Skip to content

Commit 324a0a8

Browse files
committed
Include React Bootstrap and examples; Start design tokens CLI
1 parent 2d074a7 commit 324a0a8

File tree

590 files changed

+29411
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

590 files changed

+29411
-13
lines changed

dequal/alts.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// 227B – 128k op/s
2+
export function v227(foo, bar) {
3+
var keys, ctor;
4+
return foo === bar || (
5+
foo && bar && (ctor=foo.constructor) === bar.constructor ?
6+
ctor === RegExp ? foo.toString() == bar.toString()
7+
: ctor === Date ? foo.getTime() == bar.getTime()
8+
: ctor === Array ?
9+
foo.length === bar.length && foo.every(function (val, idx) {
10+
return v227(val, bar[idx]);
11+
})
12+
: ctor === Object
13+
&& (keys=Object.keys(foo)).length === Object.keys(bar).length
14+
&& keys.every(function (k) {
15+
return k in bar && v227(foo[k], bar[k]);
16+
})
17+
: (foo !== foo && bar !== bar)
18+
);
19+
}
20+
21+
// 255B – 155k op/s
22+
export function v255(foo, bar) {
23+
var ctor, len, k;
24+
if (foo === bar) return true;
25+
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
26+
if (ctor === Date) return foo.getTime() === bar.getTime();
27+
if (ctor === RegExp) return foo.toString() === bar.toString();
28+
if (ctor === Array && (len=foo.length) === bar.length) {
29+
while (len-- > 0 && v255(foo[len], bar[len]));
30+
return len === -1;
31+
}
32+
if (ctor === Object) {
33+
if (Object.keys(foo).length !== Object.keys(bar).length) return false;
34+
for (k in foo) {
35+
if (!(k in bar) || !v255(foo[k], bar[k])) return false;
36+
}
37+
return true;
38+
}
39+
}
40+
return foo !== foo && bar !== bar;
41+
}
42+
43+
// 246B – 157k op/s
44+
export function v246(foo, bar) {
45+
var ctor, i;
46+
if (foo === bar) return true;
47+
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
48+
if (ctor === Date) return foo.getTime() === bar.getTime();
49+
if (ctor === RegExp) return foo.toString() === bar.toString();
50+
if (ctor === Array) {
51+
if (foo.length !== bar.length) return false;
52+
for (i=0; i < foo.length; i++) if (!v246(foo[i], bar[i])) return false;
53+
return true
54+
}
55+
if (ctor === Object) {
56+
if (Object.keys(foo).length !== Object.keys(bar).length) return false;
57+
for (i in foo) if (!(i in bar) || !v246(foo[i], bar[i])) return false;
58+
return true;
59+
}
60+
}
61+
return foo !== foo && bar !== bar;
62+
}
63+
64+
// 225B - 97k op/s
65+
export function v225(foo, bar) {
66+
var ctor, keys, len;
67+
if (foo === bar) return true;
68+
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
69+
if (ctor === Date) return foo.getTime() === bar.getTime();
70+
if (ctor === RegExp) return foo.toString() === bar.toString();
71+
if (typeof foo === 'object') {
72+
if (Object.keys(foo).length !== Object.keys(bar).length) return false;
73+
for (len in foo) if (!(len in bar) || !v225(foo[len], bar[len])) return false;
74+
return true;
75+
}
76+
}
77+
return foo !== foo && bar !== bar;
78+
}

dequal/index.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
var has = Object.prototype.hasOwnProperty;
2+
3+
function find(iter, tar, key) {
4+
for (key of iter.keys()) {
5+
if (dequal(key, tar)) return key;
6+
}
7+
}
8+
9+
export function dequal(foo, bar) {
10+
var ctor, len, tmp;
11+
if (foo === bar) return true;
12+
13+
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
14+
if (ctor === Date) return foo.getTime() === bar.getTime();
15+
if (ctor === RegExp) return foo.toString() === bar.toString();
16+
17+
if (ctor === Array) {
18+
if ((len=foo.length) === bar.length) {
19+
while (len-- && dequal(foo[len], bar[len]));
20+
}
21+
return len === -1;
22+
}
23+
24+
if (ctor === Set) {
25+
if (foo.size !== bar.size) {
26+
return false;
27+
}
28+
for (len of foo) {
29+
tmp = len;
30+
if (tmp && typeof tmp === 'object') {
31+
tmp = find(bar, tmp);
32+
if (!tmp) return false;
33+
}
34+
if (!bar.has(tmp)) return false;
35+
}
36+
return true;
37+
}
38+
39+
if (ctor === Map) {
40+
if (foo.size !== bar.size) {
41+
return false;
42+
}
43+
for (len of foo) {
44+
tmp = len[0];
45+
if (tmp && typeof tmp === 'object') {
46+
tmp = find(bar, tmp);
47+
if (!tmp) return false;
48+
}
49+
if (!dequal(len[1], bar.get(tmp))) {
50+
return false;
51+
}
52+
}
53+
return true;
54+
}
55+
56+
if (ctor === ArrayBuffer) {
57+
foo = new Uint8Array(foo);
58+
bar = new Uint8Array(bar);
59+
} else if (ctor === DataView) {
60+
if ((len=foo.byteLength) === bar.byteLength) {
61+
while (len-- && foo.getInt8(len) === bar.getInt8(len));
62+
}
63+
return len === -1;
64+
}
65+
66+
if (ArrayBuffer.isView(foo)) {
67+
if ((len=foo.byteLength) === bar.byteLength) {
68+
while (len-- && foo[len] === bar[len]);
69+
}
70+
return len === -1;
71+
}
72+
73+
if (!ctor || typeof foo === 'object') {
74+
len = 0;
75+
for (ctor in foo) {
76+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
77+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
78+
}
79+
return Object.keys(bar).length === len;
80+
}
81+
}
82+
83+
return foo !== foo && bar !== bar;
84+
}

dequal/lite.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var has = Object.prototype.hasOwnProperty;
2+
3+
export function dequal(foo, bar) {
4+
var ctor, len;
5+
if (foo === bar) return true;
6+
7+
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
8+
if (ctor === Date) return foo.getTime() === bar.getTime();
9+
if (ctor === RegExp) return foo.toString() === bar.toString();
10+
11+
if (ctor === Array) {
12+
if ((len=foo.length) === bar.length) {
13+
while (len-- && dequal(foo[len], bar[len]));
14+
}
15+
return len === -1;
16+
}
17+
18+
if (!ctor || typeof foo === 'object') {
19+
len = 0;
20+
for (ctor in foo) {
21+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
22+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
23+
}
24+
return Object.keys(bar).length === len;
25+
}
26+
}
27+
28+
return foo !== foo && bar !== bar;
29+
}

design-tokens-cli/chooseTransform.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { toCustomProps } from './transformers/toCustomProps.js';
2+
import { toScssVars } from './transformers/toScssVars.js';
3+
import { toESM } from './transformers/toESM.js';
4+
import { toJSON } from './transformers/toJSON.js';
5+
6+
/**
7+
* Convert an object of design token name/value pairs into Scss (Sass) variables
8+
* @param {Object} pairs The flattened token key/value pairs
9+
* @param {String} as What the tokens should be transformed into
10+
* @returns {String}
11+
*/
12+
const chooseTransform = (pairs, as, groupName, config) => {
13+
switch (as) {
14+
case 'css':
15+
return toCustomProps(pairs, config);
16+
case 'scss':
17+
return toScssVars(pairs, config);
18+
case 'mjs' || 'js':
19+
return toESM(pairs, groupName, config);
20+
case 'json':
21+
return toJSON(pairs, config);
22+
default:
23+
throw new Error(`The 'as' value ${as} is not recognized.`);
24+
}
25+
}
26+
27+
export { chooseTransform }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"inset": {
3+
"a": {
4+
"$value": {
5+
"left": "0",
6+
"top": "0",
7+
"bottom": "0",
8+
"right": "0"
9+
}
10+
},
11+
"b": {
12+
"$value": {
13+
"left": "50%",
14+
"top": "50%",
15+
"bottom": "50%",
16+
"right": "50%"
17+
}
18+
}
19+
}
20+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"sizing": {
3+
"relative": {
4+
"0": {
5+
"$value": "0",
6+
"comment": "no spacing, zero."
7+
},
8+
"25": {
9+
"$value": ".0625",
10+
"comment": ".0625rem, 1px"
11+
},
12+
"50": {
13+
"$value": ".125rem",
14+
"comment": ".125rem, 2px"
15+
},
16+
"100": {
17+
"$value": ".25rem",
18+
"comment": ".25rem, 4px."
19+
},
20+
"200": {
21+
"$value": ".5rem",
22+
"comment": ".5rem, 8px."
23+
},
24+
"400": {
25+
"$value": "1rem",
26+
"comment": "1rem, 16px."
27+
},
28+
"600": {
29+
"$value": "1.5rem",
30+
"comment": "1.5rem, 24px."
31+
},
32+
"800": {
33+
"$value": "2rem",
34+
"comment": "2rem, 32px."
35+
},
36+
"1200": {
37+
"$value": "3rem",
38+
"comment": "3rem, 48px."
39+
},
40+
"1600": {
41+
"$value": "4rem",
42+
"comment": "4rem, 64px."
43+
}
44+
},
45+
"absolute": {
46+
"0": {
47+
"$value": "0",
48+
"comment": "no spacing, zero."
49+
},
50+
"25": {
51+
"$value": "1px",
52+
"comment": ".0625rem, 1px"
53+
},
54+
"50": {
55+
"$value": "2px",
56+
"comment": ".125rem, 2px"
57+
},
58+
"100": {
59+
"$value": "4px",
60+
"comment": ".25rem, 4px."
61+
},
62+
"200": {
63+
"$value": "8px",
64+
"comment": ".5rem, 8px."
65+
},
66+
"400": {
67+
"$value": "16px",
68+
"comment": "1rem, 16px."
69+
},
70+
"600": {
71+
"$value": "24px",
72+
"comment": "1.5rem, 24px."
73+
},
74+
"800": {
75+
"$value": "32px",
76+
"comment": "2rem, 32px."
77+
},
78+
"1200": {
79+
"$value": "48px",
80+
"comment": "3rem, 48px."
81+
},
82+
"1600": {
83+
"$value": "64px",
84+
"comment": "4rem, 64px."
85+
}
86+
}
87+
}
88+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"color": {
3+
"white": {
4+
"name": "white",
5+
"$value": "#ffffff"
6+
},
7+
"blanche": {
8+
"name": "white",
9+
"$value": "{color.white}"
10+
},
11+
"weiss": {
12+
"name": "white",
13+
"$value": "{color.blanche}"
14+
},
15+
"black": {
16+
"name": "black",
17+
"$value": "#000000"
18+
},
19+
"grayscale": {
20+
"200": {
21+
"name": "grayscale-200",
22+
"$value": "#f8f8f8"
23+
},
24+
"300": {
25+
"name": "grayscale-300",
26+
"$value": "#f3f3f3"
27+
},
28+
"400": {
29+
"name": "grayscale-400",
30+
"$value": "#dadada"
31+
},
32+
"500": {
33+
"name": "grayscale-500",
34+
"$value": "#999999"
35+
},
36+
"600": {
37+
"name": "grayscale-600",
38+
"$value": "#666666"
39+
},
40+
"700": {
41+
"name": "grayscale-700",
42+
"$value": "#555555"
43+
},
44+
"800": {
45+
"name": "grayscale-800",
46+
"$value": "#222222"
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)