@baukit/ui-tokens 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/color-literals.d.ts +16 -0
- package/dist/color-literals.d.ts.map +1 -0
- package/dist/color-literals.js +186 -0
- package/dist/color-literals.js.map +1 -0
- package/dist/compiler.d.ts +6 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +84 -0
- package/dist/compiler.js.map +1 -0
- package/dist/contrast.d.ts +16 -0
- package/dist/contrast.d.ts.map +1 -0
- package/dist/contrast.js +59 -0
- package/dist/contrast.js.map +1 -0
- package/dist/eslint.d.ts +50 -0
- package/dist/eslint.d.ts.map +1 -0
- package/dist/eslint.js +233 -0
- package/dist/eslint.js.map +1 -0
- package/dist/example.d.ts +70 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +31 -0
- package/dist/example.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +26 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +28 -0
- package/dist/layout.js.map +1 -0
- package/dist/schema.d.ts +40 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -0
- package/dist/validation.d.ts +14 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +183 -0
- package/dist/validation.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Koss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# `@baukit/ui-tokens`
|
|
2
|
+
|
|
3
|
+
A dependency-free design-token schema, validator, accessibility checker, and deterministic compiler for web and React Native.
|
|
4
|
+
|
|
5
|
+
This package shares semantic values such as `color.background.primary`; it is deliberately not a design system or cross-platform component library. DOM/React Native components, interaction behavior, raw brand-palette decisions, and product-specific themes remain outside the package.
|
|
6
|
+
|
|
7
|
+
## Define and validate tokens
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { checkContrast, parseTokens, type DesignTokens } from '@baukit/ui-tokens';
|
|
11
|
+
|
|
12
|
+
const tokens = parseTokens(untrustedJson);
|
|
13
|
+
const violations = checkContrast(tokens);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Colors are opaque `#RGB` or `#RRGGBB` sRGB values with light and dark variants. Color leaves require at least a semantic group and name. Typography, space, radius, motion, and elevation are named scales. `contrastPairs` declares foreground/background semantic paths; normal text must reach 4.5:1 and entries marked `largeText` must reach 3:1 in both themes. Validation errors include paths such as `$.color.text.primary.light`, while contrast failures include the calculated ratio.
|
|
17
|
+
|
|
18
|
+
Validation is handwritten rather than Zod-based: the schema is small, this keeps production dependencies at zero, and it enables diagnostics tailored to semantic token paths.
|
|
19
|
+
|
|
20
|
+
## Compile
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { toCssVariables, toReactNative } from '@baukit/ui-tokens';
|
|
24
|
+
|
|
25
|
+
const css = toCssVariables(tokens);
|
|
26
|
+
const nativeModule = toReactNative(tokens);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`toCssVariables` emits sorted `--bk-*` declarations in `:root`, then dark color overrides under `[data-theme="dark"]`. `toReactNative` emits a sorted nested `tokens` constant with an inferred `Tokens` type. Accessibility declarations are build metadata and are omitted from generated runtime constants. `exampleTokens` is available as a test fixture demonstrating every group; it is intentionally not a Baukit visual language.
|
|
30
|
+
|
|
31
|
+
## Enforce tokens with `no-raw-color`
|
|
32
|
+
|
|
33
|
+
The design-token schema is only worth having if colors stay out of components.
|
|
34
|
+
`@baukit/ui-tokens/eslint` ships an ESLint flat-config plugin that reports CSS
|
|
35
|
+
colors written directly in application code.
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import uiTokens from '@baukit/ui-tokens/eslint';
|
|
39
|
+
|
|
40
|
+
export default [
|
|
41
|
+
{
|
|
42
|
+
plugins: { '@baukit/ui-tokens': uiTokens },
|
|
43
|
+
rules: {
|
|
44
|
+
'@baukit/ui-tokens/no-raw-color': [
|
|
45
|
+
'error',
|
|
46
|
+
{ allowedFiles: ['src/theme/tokens.ts', 'src/theme/**'] },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`configs.recommended` turns the rule on with defaults when a product needs no
|
|
54
|
+
options:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { configs } from '@baukit/ui-tokens/eslint';
|
|
58
|
+
|
|
59
|
+
export default [configs.recommended];
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The rule reports `#rgb`, `#rrggbb`, and `#rrggbbaa` hex values plus
|
|
63
|
+
`rgb()`, `rgba()`, `hsl()`, and `hsla()` anywhere they appear, in string and
|
|
64
|
+
template literals alike. CSS color keywords such as `crimson` are reported only
|
|
65
|
+
in a style-like position: a color-named property, a `StyleSheet.create` call, a
|
|
66
|
+
`style`, `color`, or `fill` JSX attribute, a `css` tagged template, or a
|
|
67
|
+
variable whose name ends in `style`, `theme`, `palette`, or `colors`. That
|
|
68
|
+
restriction keeps route names, test ids, and ordinary prose off the report.
|
|
69
|
+
|
|
70
|
+
Options:
|
|
71
|
+
|
|
72
|
+
| Option | Default | Meaning |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| `allowedFiles` | `[]` | Glob-like paths that may declare raw colors. `*` matches inside a path segment, `**` across segments. Put the token definition here. |
|
|
75
|
+
| `allowedValues` | `transparent`, `currentColor`, `inherit`, `none` | Literals allowed everywhere. Entries add to the defaults. |
|
|
76
|
+
| `additionalStyleProperties` | `[]` | Extra property or attribute names treated as style-like. |
|
|
77
|
+
| `reportKeywords` | `true` | Set to `false` to report only hex and functional notations. |
|
|
78
|
+
|
|
79
|
+
eslint is an optional peer dependency. Importing `@baukit/ui-tokens` itself
|
|
80
|
+
never loads it.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Kind of raw color found in a literal, used to pick the report message. */
|
|
2
|
+
export type RawColorKind = 'hex' | 'function' | 'keyword';
|
|
3
|
+
/** A raw color match with the exact text that triggered it. */
|
|
4
|
+
export interface RawColorMatch {
|
|
5
|
+
readonly kind: RawColorKind;
|
|
6
|
+
readonly text: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Finds the first raw CSS color in a string. Hex and functional notations are
|
|
10
|
+
* unambiguous anywhere; keyword matches are only meaningful in a style-like
|
|
11
|
+
* context, which the caller decides.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findRawColor(value: string, includeKeywords: boolean): RawColorMatch | undefined;
|
|
14
|
+
/** True when the value is a CSS color keyword on its own. */
|
|
15
|
+
export declare function isCssColorKeyword(value: string): boolean;
|
|
16
|
+
//# sourceMappingURL=color-literals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-literals.d.ts","sourceRoot":"","sources":["../src/color-literals.ts"],"names":[],"mappings":"AA+JA,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAE1D,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AASD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAU/F;AAED,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS color keywords recognized as raw colors. Keywords that double as ordinary
|
|
3
|
+
* English words in prop values are handled by requiring a style-like context.
|
|
4
|
+
*/
|
|
5
|
+
const CSS_COLOR_KEYWORDS = new Set([
|
|
6
|
+
'aliceblue',
|
|
7
|
+
'antiquewhite',
|
|
8
|
+
'aqua',
|
|
9
|
+
'aquamarine',
|
|
10
|
+
'azure',
|
|
11
|
+
'beige',
|
|
12
|
+
'bisque',
|
|
13
|
+
'black',
|
|
14
|
+
'blanchedalmond',
|
|
15
|
+
'blue',
|
|
16
|
+
'blueviolet',
|
|
17
|
+
'brown',
|
|
18
|
+
'burlywood',
|
|
19
|
+
'cadetblue',
|
|
20
|
+
'chartreuse',
|
|
21
|
+
'chocolate',
|
|
22
|
+
'coral',
|
|
23
|
+
'cornflowerblue',
|
|
24
|
+
'cornsilk',
|
|
25
|
+
'crimson',
|
|
26
|
+
'cyan',
|
|
27
|
+
'darkblue',
|
|
28
|
+
'darkcyan',
|
|
29
|
+
'darkgoldenrod',
|
|
30
|
+
'darkgray',
|
|
31
|
+
'darkgreen',
|
|
32
|
+
'darkgrey',
|
|
33
|
+
'darkkhaki',
|
|
34
|
+
'darkmagenta',
|
|
35
|
+
'darkolivegreen',
|
|
36
|
+
'darkorange',
|
|
37
|
+
'darkorchid',
|
|
38
|
+
'darkred',
|
|
39
|
+
'darksalmon',
|
|
40
|
+
'darkseagreen',
|
|
41
|
+
'darkslateblue',
|
|
42
|
+
'darkslategray',
|
|
43
|
+
'darkslategrey',
|
|
44
|
+
'darkturquoise',
|
|
45
|
+
'darkviolet',
|
|
46
|
+
'deeppink',
|
|
47
|
+
'deepskyblue',
|
|
48
|
+
'dimgray',
|
|
49
|
+
'dimgrey',
|
|
50
|
+
'dodgerblue',
|
|
51
|
+
'firebrick',
|
|
52
|
+
'floralwhite',
|
|
53
|
+
'forestgreen',
|
|
54
|
+
'fuchsia',
|
|
55
|
+
'gainsboro',
|
|
56
|
+
'ghostwhite',
|
|
57
|
+
'gold',
|
|
58
|
+
'goldenrod',
|
|
59
|
+
'gray',
|
|
60
|
+
'green',
|
|
61
|
+
'greenyellow',
|
|
62
|
+
'grey',
|
|
63
|
+
'honeydew',
|
|
64
|
+
'hotpink',
|
|
65
|
+
'indianred',
|
|
66
|
+
'indigo',
|
|
67
|
+
'ivory',
|
|
68
|
+
'khaki',
|
|
69
|
+
'lavender',
|
|
70
|
+
'lavenderblush',
|
|
71
|
+
'lawngreen',
|
|
72
|
+
'lemonchiffon',
|
|
73
|
+
'lightblue',
|
|
74
|
+
'lightcoral',
|
|
75
|
+
'lightcyan',
|
|
76
|
+
'lightgoldenrodyellow',
|
|
77
|
+
'lightgray',
|
|
78
|
+
'lightgreen',
|
|
79
|
+
'lightgrey',
|
|
80
|
+
'lightpink',
|
|
81
|
+
'lightsalmon',
|
|
82
|
+
'lightseagreen',
|
|
83
|
+
'lightskyblue',
|
|
84
|
+
'lightslategray',
|
|
85
|
+
'lightslategrey',
|
|
86
|
+
'lightsteelblue',
|
|
87
|
+
'lightyellow',
|
|
88
|
+
'lime',
|
|
89
|
+
'limegreen',
|
|
90
|
+
'linen',
|
|
91
|
+
'magenta',
|
|
92
|
+
'maroon',
|
|
93
|
+
'mediumaquamarine',
|
|
94
|
+
'mediumblue',
|
|
95
|
+
'mediumorchid',
|
|
96
|
+
'mediumpurple',
|
|
97
|
+
'mediumseagreen',
|
|
98
|
+
'mediumslateblue',
|
|
99
|
+
'mediumspringgreen',
|
|
100
|
+
'mediumturquoise',
|
|
101
|
+
'mediumvioletred',
|
|
102
|
+
'midnightblue',
|
|
103
|
+
'mintcream',
|
|
104
|
+
'mistyrose',
|
|
105
|
+
'moccasin',
|
|
106
|
+
'navajowhite',
|
|
107
|
+
'navy',
|
|
108
|
+
'oldlace',
|
|
109
|
+
'olive',
|
|
110
|
+
'olivedrab',
|
|
111
|
+
'orange',
|
|
112
|
+
'orangered',
|
|
113
|
+
'orchid',
|
|
114
|
+
'palegoldenrod',
|
|
115
|
+
'palegreen',
|
|
116
|
+
'paleturquoise',
|
|
117
|
+
'palevioletred',
|
|
118
|
+
'papayawhip',
|
|
119
|
+
'peachpuff',
|
|
120
|
+
'peru',
|
|
121
|
+
'pink',
|
|
122
|
+
'plum',
|
|
123
|
+
'powderblue',
|
|
124
|
+
'purple',
|
|
125
|
+
'rebeccapurple',
|
|
126
|
+
'red',
|
|
127
|
+
'rosybrown',
|
|
128
|
+
'royalblue',
|
|
129
|
+
'saddlebrown',
|
|
130
|
+
'salmon',
|
|
131
|
+
'sandybrown',
|
|
132
|
+
'seagreen',
|
|
133
|
+
'seashell',
|
|
134
|
+
'sienna',
|
|
135
|
+
'silver',
|
|
136
|
+
'skyblue',
|
|
137
|
+
'slateblue',
|
|
138
|
+
'slategray',
|
|
139
|
+
'slategrey',
|
|
140
|
+
'snow',
|
|
141
|
+
'springgreen',
|
|
142
|
+
'steelblue',
|
|
143
|
+
'tan',
|
|
144
|
+
'teal',
|
|
145
|
+
'thistle',
|
|
146
|
+
'tomato',
|
|
147
|
+
'turquoise',
|
|
148
|
+
'violet',
|
|
149
|
+
'wheat',
|
|
150
|
+
'white',
|
|
151
|
+
'whitesmoke',
|
|
152
|
+
'yellow',
|
|
153
|
+
'yellowgreen',
|
|
154
|
+
]);
|
|
155
|
+
const HEX_PATTERN = /#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\b/i;
|
|
156
|
+
const FUNCTIONAL_PATTERN = /\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\s*\(/i;
|
|
157
|
+
const KEYWORD_SPLIT_PATTERN = /[^a-z]+/i;
|
|
158
|
+
function findKeyword(value) {
|
|
159
|
+
for (const word of value.split(KEYWORD_SPLIT_PATTERN)) {
|
|
160
|
+
if (word !== '' && CSS_COLOR_KEYWORDS.has(word.toLowerCase()))
|
|
161
|
+
return word;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Finds the first raw CSS color in a string. Hex and functional notations are
|
|
167
|
+
* unambiguous anywhere; keyword matches are only meaningful in a style-like
|
|
168
|
+
* context, which the caller decides.
|
|
169
|
+
*/
|
|
170
|
+
export function findRawColor(value, includeKeywords) {
|
|
171
|
+
const hex = HEX_PATTERN.exec(value);
|
|
172
|
+
if (hex)
|
|
173
|
+
return { kind: 'hex', text: hex[0] };
|
|
174
|
+
const functional = FUNCTIONAL_PATTERN.exec(value);
|
|
175
|
+
if (functional)
|
|
176
|
+
return { kind: 'function', text: functional[0].replace(/\s*\($/, '') };
|
|
177
|
+
if (!includeKeywords)
|
|
178
|
+
return undefined;
|
|
179
|
+
const keyword = findKeyword(value);
|
|
180
|
+
return keyword === undefined ? undefined : { kind: 'keyword', text: keyword };
|
|
181
|
+
}
|
|
182
|
+
/** True when the value is a CSS color keyword on its own. */
|
|
183
|
+
export function isCssColorKeyword(value) {
|
|
184
|
+
return CSS_COLOR_KEYWORDS.has(value.trim().toLowerCase());
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=color-literals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-literals.js","sourceRoot":"","sources":["../src/color-literals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,WAAW;IACX,cAAc;IACd,MAAM;IACN,YAAY;IACZ,OAAO;IACP,OAAO;IACP,QAAQ;IACR,OAAO;IACP,gBAAgB;IAChB,MAAM;IACN,YAAY;IACZ,OAAO;IACP,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,OAAO;IACP,gBAAgB;IAChB,UAAU;IACV,SAAS;IACT,MAAM;IACN,UAAU;IACV,UAAU;IACV,eAAe;IACf,UAAU;IACV,WAAW;IACX,UAAU;IACV,WAAW;IACX,aAAa;IACb,gBAAgB;IAChB,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,cAAc;IACd,eAAe;IACf,eAAe;IACf,eAAe;IACf,eAAe;IACf,YAAY;IACZ,UAAU;IACV,aAAa;IACb,SAAS;IACT,SAAS;IACT,YAAY;IACZ,WAAW;IACX,aAAa;IACb,aAAa;IACb,SAAS;IACT,WAAW;IACX,YAAY;IACZ,MAAM;IACN,WAAW;IACX,MAAM;IACN,OAAO;IACP,aAAa;IACb,MAAM;IACN,UAAU;IACV,SAAS;IACT,WAAW;IACX,QAAQ;IACR,OAAO;IACP,OAAO;IACP,UAAU;IACV,eAAe;IACf,WAAW;IACX,cAAc;IACd,WAAW;IACX,YAAY;IACZ,WAAW;IACX,sBAAsB;IACtB,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,aAAa;IACb,eAA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;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,eAAwB;IAClE,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9C,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,UAAU;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC;IAEvF,IAAI,CAAC,eAAe;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAChF,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DesignTokens } from './schema.js';
|
|
2
|
+
/** Compiles a deterministic light root and dark-theme override block. */
|
|
3
|
+
export declare function toCssVariables(tokens: DesignTokens): string;
|
|
4
|
+
/** Compiles deterministic, nested TypeScript constants for React Native. */
|
|
5
|
+
export declare function toReactNative(tokens: DesignTokens): string;
|
|
6
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAwD5D,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAqB3D;AAgBD,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAW1D"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function isThemeColor(value) {
|
|
5
|
+
return isRecord(value) && typeof value['light'] === 'string' && typeof value['dark'] === 'string';
|
|
6
|
+
}
|
|
7
|
+
function flattenColors(value, path, theme, output) {
|
|
8
|
+
if (isThemeColor(value)) {
|
|
9
|
+
output.push({ path: path.join('-'), value: value[theme] });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (isRecord(value)) {
|
|
13
|
+
for (const key of Object.keys(value).sort()) {
|
|
14
|
+
flattenColors(value[key], [...path, key], theme, output);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function flattenScalars(value, path, output) {
|
|
19
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
20
|
+
output.push({ path: path.join('-'), value });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (isRecord(value)) {
|
|
24
|
+
for (const key of Object.keys(value).sort()) {
|
|
25
|
+
flattenScalars(value[key], [...path, key], output);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function kebabCase(path) {
|
|
30
|
+
return path.replaceAll(/([a-z\d])([A-Z])/gu, '$1-$2').toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
function declaration(token) {
|
|
33
|
+
return ` --bk-${kebabCase(token.path)}: ${String(token.value)};`;
|
|
34
|
+
}
|
|
35
|
+
function comparePaths(left, right) {
|
|
36
|
+
return left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
/** Compiles a deterministic light root and dark-theme override block. */
|
|
39
|
+
export function toCssVariables(tokens) {
|
|
40
|
+
const light = [];
|
|
41
|
+
const dark = [];
|
|
42
|
+
flattenColors(tokens.color, ['color'], 'light', light);
|
|
43
|
+
flattenColors(tokens.color, ['color'], 'dark', dark);
|
|
44
|
+
for (const group of ['typography', 'space', 'radius', 'motion', 'elevation']) {
|
|
45
|
+
flattenScalars(tokens[group], [group], light);
|
|
46
|
+
}
|
|
47
|
+
light.sort(comparePaths);
|
|
48
|
+
dark.sort(comparePaths);
|
|
49
|
+
return [
|
|
50
|
+
':root {',
|
|
51
|
+
...light.map(declaration),
|
|
52
|
+
'}',
|
|
53
|
+
'',
|
|
54
|
+
'[data-theme="dark"] {',
|
|
55
|
+
...dark.map(declaration),
|
|
56
|
+
'}',
|
|
57
|
+
'',
|
|
58
|
+
].join('\n');
|
|
59
|
+
}
|
|
60
|
+
function sortDeep(value) {
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
return value.map((item) => sortDeep(item));
|
|
63
|
+
}
|
|
64
|
+
if (isRecord(value)) {
|
|
65
|
+
return Object.fromEntries(Object.keys(value)
|
|
66
|
+
.sort()
|
|
67
|
+
.map((key) => [key, sortDeep(value[key])]));
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
/** Compiles deterministic, nested TypeScript constants for React Native. */
|
|
72
|
+
export function toReactNative(tokens) {
|
|
73
|
+
const runtimeTokens = {
|
|
74
|
+
color: tokens.color,
|
|
75
|
+
typography: tokens.typography,
|
|
76
|
+
space: tokens.space,
|
|
77
|
+
radius: tokens.radius,
|
|
78
|
+
motion: tokens.motion,
|
|
79
|
+
elevation: tokens.elevation,
|
|
80
|
+
};
|
|
81
|
+
const json = JSON.stringify(sortDeep(runtimeTokens), undefined, 2);
|
|
82
|
+
return `// Generated by @baukit/ui-tokens. Do not edit.\nexport const tokens = ${json} as const;\n\nexport type Tokens = typeof tokens;\n`;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAOA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC;AACpG,CAAC;AAED,SAAS,aAAa,CACpB,KAAc,EACd,IAAuB,EACvB,KAAuB,EACvB,MAAmB;IAEnB,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3D,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5C,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,IAAuB,EAAE,MAAmB;IAClF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,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MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACnE,OAAO,0EAA0E,IAAI,qDAAqD,CAAC;AAC7I,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DesignTokens } from './schema.js';
|
|
2
|
+
export type ThemeName = 'light' | 'dark';
|
|
3
|
+
export interface ContrastViolation {
|
|
4
|
+
readonly foreground: string;
|
|
5
|
+
readonly background: string;
|
|
6
|
+
readonly theme: ThemeName;
|
|
7
|
+
readonly ratio: number;
|
|
8
|
+
readonly requiredRatio: 3 | 4.5;
|
|
9
|
+
}
|
|
10
|
+
/** WCAG 2.x relative luminance for an opaque hexadecimal sRGB color. */
|
|
11
|
+
export declare function relativeLuminance(color: string): number;
|
|
12
|
+
/** WCAG contrast ratio, always between 1 and 21 inclusive. */
|
|
13
|
+
export declare function contrastRatio(foreground: string, background: string): number;
|
|
14
|
+
/** Checks every declared pair in both themes and returns only failures. */
|
|
15
|
+
export declare function checkContrast(tokens: DesignTokens): ContrastViolation[];
|
|
16
|
+
//# sourceMappingURL=contrast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contrast.d.ts","sourceRoot":"","sources":["../src/contrast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,GAAG,CAAC;CACjC;AAkBD,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM5E;AAYD,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,iBAAiB,EAAE,CAoBvE"}
|
package/dist/contrast.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function expandHex(color) {
|
|
2
|
+
const match = /^#([\dA-Fa-f]{3}|[\dA-Fa-f]{6})$/u.exec(color);
|
|
3
|
+
if (match?.[1] === undefined) {
|
|
4
|
+
throw new TypeError(`Unsupported color ${color}; expected #RGB or #RRGGBB.`);
|
|
5
|
+
}
|
|
6
|
+
const digits = match[1];
|
|
7
|
+
return digits.length === 3
|
|
8
|
+
? `${digits.charAt(0)}${digits.charAt(0)}${digits.charAt(1)}${digits.charAt(1)}${digits.charAt(2)}${digits.charAt(2)}`
|
|
9
|
+
: digits;
|
|
10
|
+
}
|
|
11
|
+
function channel(hex, offset) {
|
|
12
|
+
const value = Number.parseInt(hex.slice(offset, offset + 2), 16) / 255;
|
|
13
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
14
|
+
}
|
|
15
|
+
/** WCAG 2.x relative luminance for an opaque hexadecimal sRGB color. */
|
|
16
|
+
export function relativeLuminance(color) {
|
|
17
|
+
const hex = expandHex(color);
|
|
18
|
+
return 0.2126 * channel(hex, 0) + 0.7152 * channel(hex, 2) + 0.0722 * channel(hex, 4);
|
|
19
|
+
}
|
|
20
|
+
/** WCAG contrast ratio, always between 1 and 21 inclusive. */
|
|
21
|
+
export function contrastRatio(foreground, background) {
|
|
22
|
+
const foregroundLuminance = relativeLuminance(foreground);
|
|
23
|
+
const backgroundLuminance = relativeLuminance(background);
|
|
24
|
+
const lighter = Math.max(foregroundLuminance, backgroundLuminance);
|
|
25
|
+
const darker = Math.min(foregroundLuminance, backgroundLuminance);
|
|
26
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
27
|
+
}
|
|
28
|
+
function colorAt(tokens, path) {
|
|
29
|
+
const segments = path.split('.');
|
|
30
|
+
segments.shift();
|
|
31
|
+
let current = tokens.color;
|
|
32
|
+
for (const segment of segments) {
|
|
33
|
+
current = current[segment];
|
|
34
|
+
}
|
|
35
|
+
return current;
|
|
36
|
+
}
|
|
37
|
+
/** Checks every declared pair in both themes and returns only failures. */
|
|
38
|
+
export function checkContrast(tokens) {
|
|
39
|
+
const violations = [];
|
|
40
|
+
for (const pair of tokens.contrastPairs) {
|
|
41
|
+
const foreground = colorAt(tokens, pair.foreground);
|
|
42
|
+
const background = colorAt(tokens, pair.background);
|
|
43
|
+
const requiredRatio = pair.largeText === true ? 3 : 4.5;
|
|
44
|
+
for (const theme of ['light', 'dark']) {
|
|
45
|
+
const ratio = contrastRatio(foreground[theme], background[theme]);
|
|
46
|
+
if (ratio < requiredRatio) {
|
|
47
|
+
violations.push({
|
|
48
|
+
foreground: pair.foreground,
|
|
49
|
+
background: pair.background,
|
|
50
|
+
theme,
|
|
51
|
+
ratio,
|
|
52
|
+
requiredRatio,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return violations;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=contrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contrast.js","sourceRoot":"","sources":["../src/contrast.ts"],"names":[],"mappings":"AAYA,SAAS,SAAS,CAAC,KAAa;IAC9B,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,CAAC,GAAG,CAAC;QACxD,KAAK,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,CAAU,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAClE,IAAI,KAAK,GAAG,aAAa,EAAE,CAAC;gBAC1B,UAAU,CAAC,IAAI,CAAC;oBACd,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,KAAK;oBACL,KAAK;oBACL,aAAa;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/eslint.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/** Options accepted by the `no-raw-color` rule. */
|
|
3
|
+
export interface NoRawColorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Glob-like file patterns whose contents may declare raw colors. A token
|
|
6
|
+
* definition file belongs here. `*` matches within a path segment, `**`
|
|
7
|
+
* across segments.
|
|
8
|
+
*/
|
|
9
|
+
readonly allowedFiles?: readonly string[];
|
|
10
|
+
/** Exact literal values that stay allowed everywhere, such as `transparent`. */
|
|
11
|
+
readonly allowedValues?: readonly string[];
|
|
12
|
+
/** Extra property or attribute names treated as style-like. */
|
|
13
|
+
readonly additionalStyleProperties?: readonly string[];
|
|
14
|
+
/** Report CSS color keywords such as `red`. Defaults to `true`. */
|
|
15
|
+
readonly reportKeywords?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reports CSS colors written directly in application code. Colors belong in the
|
|
19
|
+
* token definition, which the `allowedFiles` option exempts.
|
|
20
|
+
*/
|
|
21
|
+
export declare const noRawColor: Rule.RuleModule;
|
|
22
|
+
/** Rules exported by this plugin, keyed by rule name. */
|
|
23
|
+
export declare const rules: {
|
|
24
|
+
'no-raw-color': Rule.RuleModule;
|
|
25
|
+
};
|
|
26
|
+
declare const plugin: {
|
|
27
|
+
rules: {
|
|
28
|
+
'no-raw-color': Rule.RuleModule;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Ready-made flat config. Spread it into a product's `eslint.config.js` and pass
|
|
33
|
+
* `allowedFiles` so the token definition may keep its color literals.
|
|
34
|
+
*/
|
|
35
|
+
export declare const configs: {
|
|
36
|
+
readonly recommended: {
|
|
37
|
+
readonly plugins: {
|
|
38
|
+
readonly '@baukit/ui-tokens': {
|
|
39
|
+
rules: {
|
|
40
|
+
'no-raw-color': Rule.RuleModule;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
readonly rules: {
|
|
45
|
+
readonly '@baukit/ui-tokens/no-raw-color': "error";
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export default plugin;
|
|
50
|
+
//# sourceMappingURL=eslint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.d.ts","sourceRoot":"","sources":["../src/eslint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAKnC,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,gFAAgF;IAChF,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,+DAA+D;IAC/D,QAAQ,CAAC,yBAAyB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvD,mEAAmE;IACnE,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACnC;AA8KD;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,IAAI,CAAC,UAmE7B,CAAC;AAEF,yDAAyD;AACzD,eAAO,MAAM,KAAK;;CAAiC,CAAC;AAEpD,QAAA,MAAM,MAAM;;;;CAAY,CAAC;AAEzB;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;CAKV,CAAC;AAEX,eAAe,MAAM,CAAC"}
|