@halftone-ds/tokens 1.3.2 → 1.4.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/README.md +38 -8
- package/cli.mjs +39 -6
- package/lib/contrast.mjs +50 -6
- package/lib/init.mjs +249 -0
- package/lib/resolve.mjs +13 -1
- package/lib/scan.mjs +15 -11
- package/lib/system/index.d.mts +13 -1
- package/lib/system/schema.mjs +36 -8
- package/lib/theme/apply.mjs +13 -3
- package/lib/theme/components.mjs +276 -52
- package/lib/theme/fix.mjs +26 -3
- package/lib/theme/generate.mjs +11 -1
- package/lib/theme/index.d.mts +36 -3
- package/lib/theme/index.mjs +6 -0
- package/lib/theme/semantic.mjs +27 -0
- package/lib/theme/vars.mjs +2 -4
- package/lib/usage.mjs +1 -1
- package/package.json +2 -1
- package/targets/design-md.mjs +9 -8
- package/targets/fonts.mjs +28 -1
- package/targets/llms.mjs +5 -5
- package/targets/nativewind3.mjs +40 -13
- package/targets/shadcn-web.mjs +4 -3
- package/targets/ts-theme.mjs +16 -6
- package/templates/tokens.json +2363 -0
package/lib/system/schema.mjs
CHANGED
|
@@ -27,13 +27,22 @@
|
|
|
27
27
|
* extras { color: [], text: [], radius: [], shadow: [], border: [] } named tokens of your own,
|
|
28
28
|
* exported (tokens.json `extra.*`) and never drawn by the kits
|
|
29
29
|
* brand { name, iconBackground, logo?, logoDark?, mark?, markDark? } (the Studio's BrandState)
|
|
30
|
-
* components { button|chip|badge|input: { style?, radius?, size?, text?,
|
|
31
|
-
* edits (lib/theme/components.mjs),
|
|
30
|
+
* components { button|chip|badge|input: { style?, radius?, border?, size?, text?, weight?, case?, icon?,
|
|
31
|
+
* shadow?, ring?, placeholder?, variants? } } component-level edits (lib/theme/components.mjs),
|
|
32
|
+
* overrides only, each where the component has it (COMPONENTS[name].props):
|
|
32
33
|
* style the component's look. Button and Input fold into recipe.button / recipe.field;
|
|
33
34
|
* Chip outline|soft|solid, Badge pill|square|soft
|
|
34
35
|
* radius a Foundations corner (sm…2xl, full) or px
|
|
35
|
-
*
|
|
36
|
-
*
|
|
36
|
+
* border border width, px (Input: its field style's lines)
|
|
37
|
+
* size { sm?, md?, lg?, x?, gap? } heights per step, then the horizontal padding and
|
|
38
|
+
* the icon gap every step shares, px (the keys it has: Badge S/M, Input no gap)
|
|
39
|
+
* text a text style (h1…blockquote): its font, size and tracking
|
|
40
|
+
* weight 400 | 500 | 600 | 700 (the label's; Button, Chip, Badge)
|
|
41
|
+
* case 'none' | 'uppercase' (Button, Badge)
|
|
42
|
+
* icon icon size, px (Button, Chip, Badge)
|
|
43
|
+
* shadow 'none' | '1' | '2' | '3', a Foundations shadow (Button, Input)
|
|
44
|
+
* ring { width?: px, role?: a role } the focus ring (Button, Input)
|
|
45
|
+
* placeholder a role (Input)
|
|
37
46
|
* variants { <variant>: { fill?, label?, border?, pressed? } } roles (ROLE_NAMES), or
|
|
38
47
|
* 'none' for a fill or border. Variants are fixed (Input: its states)
|
|
39
48
|
*
|
|
@@ -43,7 +52,7 @@
|
|
|
43
52
|
import { FONTS } from '../theme/fonts.mjs';
|
|
44
53
|
import { STEPS } from '../theme/palettes.mjs';
|
|
45
54
|
import { anchorStep, neutralAnchorStep } from '../theme/ramp.mjs';
|
|
46
|
-
import { COMPONENT_NAMES, COMPONENTS, CORNERS } from '../theme/components.mjs';
|
|
55
|
+
import { CASES, COMPONENT_NAMES, COMPONENTS, CORNERS, SHADOWS, WEIGHTS } from '../theme/components.mjs';
|
|
47
56
|
import { normalizeRecipe, OPTIONS, TEXT_DEFAULTS, TEXT_STYLES } from '../theme/recipe.mjs';
|
|
48
57
|
import { semanticColors } from '../theme/semantic.mjs';
|
|
49
58
|
|
|
@@ -346,7 +355,7 @@ function components(r, input, recipe) {
|
|
|
346
355
|
const path = `components.${name}`;
|
|
347
356
|
const def = COMPONENTS[name];
|
|
348
357
|
const v = r.object(path, value);
|
|
349
|
-
r.keys(path, v, ['style', 'radius', 'size', 'text', 'variants']);
|
|
358
|
+
r.keys(path, v, ['style', 'radius', 'size', 'text', 'variants', ...def.props]);
|
|
350
359
|
const entry = {};
|
|
351
360
|
if (v.style !== undefined) {
|
|
352
361
|
const style = r.oneOf(`${path}.style`, v.style, def.styles);
|
|
@@ -358,10 +367,28 @@ function components(r, input, recipe) {
|
|
|
358
367
|
if (v.radius !== undefined) entry.radius = typeof v.radius === 'number' ? r.num(`${path}.radius`, v.radius, 0, 9999) : r.oneOf(`${path}.radius`, v.radius, CORNERS);
|
|
359
368
|
if (v.size !== undefined) {
|
|
360
369
|
const size = {};
|
|
361
|
-
for (const [key, px] of r.keys(`${path}.size`, r.object(`${path}.size`, v.size), def.sizes))
|
|
370
|
+
for (const [key, px] of r.keys(`${path}.size`, r.object(`${path}.size`, v.size), def.sizes)) {
|
|
371
|
+
size[key] = key === 'x' ? r.num(`${path}.size.x`, px, 0, 64) : key === 'gap' ? r.num(`${path}.size.gap`, px, 0, 24) : r.num(`${path}.size.${key}`, px, 12, 120);
|
|
372
|
+
}
|
|
362
373
|
if (Object.keys(size).length) entry.size = size;
|
|
363
374
|
}
|
|
364
375
|
if (v.text !== undefined) entry.text = r.oneOf(`${path}.text`, v.text, TEXT_STYLES);
|
|
376
|
+
if (v.border !== undefined) entry.border = r.num(`${path}.border`, v.border, 0, 8);
|
|
377
|
+
if (v.weight !== undefined) entry.weight = r.oneOf(`${path}.weight`, v.weight, WEIGHTS);
|
|
378
|
+
if (v.case !== undefined) entry.case = r.oneOf(`${path}.case`, v.case, CASES);
|
|
379
|
+
if (v.icon !== undefined) entry.icon = r.num(`${path}.icon`, v.icon, 8, 40);
|
|
380
|
+
if (v.shadow !== undefined) entry.shadow = r.oneOf(`${path}.shadow`, String(v.shadow), SHADOWS);
|
|
381
|
+
if (v.placeholder !== undefined) entry.placeholder = r.oneOf(`${path}.placeholder`, v.placeholder, ROLE_NAMES);
|
|
382
|
+
if (v.ring !== undefined) {
|
|
383
|
+
const ring = {};
|
|
384
|
+
const at = `${path}.ring`;
|
|
385
|
+
const value = r.object(at, v.ring);
|
|
386
|
+
r.keys(at, value, ['width', 'role']);
|
|
387
|
+
if (value.width !== undefined) ring.width = r.num(`${at}.width`, value.width, 0, 8);
|
|
388
|
+
if (value.role !== undefined) ring.role = r.oneOf(`${at}.role`, value.role, ROLE_NAMES);
|
|
389
|
+
for (const key of Object.keys(ring)) if (ring[key] === undefined) delete ring[key];
|
|
390
|
+
if (Object.keys(ring).length) entry.ring = ring;
|
|
391
|
+
}
|
|
365
392
|
if (v.variants !== undefined) {
|
|
366
393
|
const variants = {};
|
|
367
394
|
for (const [variant, slots] of r.keys(`${path}.variants`, r.object(`${path}.variants`, v.variants), Object.keys(def.variants))) {
|
|
@@ -495,7 +522,8 @@ export function systemOverrides(input) {
|
|
|
495
522
|
for (const section of ['fonts', 'radius', 'shadow', 'border']) for (const key of Object.keys(doc[section])) paths.push(`${section}.${key}`);
|
|
496
523
|
for (const kind of EXTRA_KINDS) for (const item of doc.extras[kind]) paths.push(`extras.${kind}.${item.name}`);
|
|
497
524
|
for (const [name, entry] of Object.entries(doc.components)) {
|
|
498
|
-
for (const key of ['style', 'radius', 'text']) if (entry[key] !== undefined) paths.push(`components.${name}.${key}`);
|
|
525
|
+
for (const key of ['style', 'radius', 'text', 'border', 'weight', 'case', 'icon', 'shadow', 'placeholder']) if (entry[key] !== undefined) paths.push(`components.${name}.${key}`);
|
|
526
|
+
for (const key of Object.keys(entry.ring ?? {})) paths.push(`components.${name}.ring.${key}`);
|
|
499
527
|
for (const key of Object.keys(entry.size ?? {})) paths.push(`components.${name}.size.${key}`);
|
|
500
528
|
for (const [variant, slots] of Object.entries(entry.variants ?? {})) for (const slot of Object.keys(slots)) paths.push(`components.${name}.variants.${variant}.${slot}`);
|
|
501
529
|
}
|
package/lib/theme/apply.mjs
CHANGED
|
@@ -96,11 +96,11 @@ function typeOf(path) {
|
|
|
96
96
|
const parts = path.split('.');
|
|
97
97
|
if (parts[0] === 'semantic' && parts[1] === 'type' && parts.length === 4) return { font: 'fontFamily', weight: 'fontWeight' }[parts[3]] ?? 'number';
|
|
98
98
|
if (path === 'semantic.border.style') return 'strokeStyle';
|
|
99
|
-
if (parts[1] === 'component') return COLOR_SLOTS.has(parts.at(-1)) ? 'color' :
|
|
99
|
+
if (parts[1] === 'component') return COLOR_SLOTS.has(parts.at(-1)) ? 'color' : { font: 'fontFamily', weight: 'fontWeight' }[parts.at(-1)] ?? 'number';
|
|
100
100
|
return TYPES[parts[1]] ?? 'color';
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const COLOR_SLOTS = new Set(['fill', 'label', 'border', 'pressed', 'ring']);
|
|
103
|
+
const COLOR_SLOTS = new Set(['fill', 'label', 'border', 'pressed', 'ring', 'focus-border', 'placeholder']);
|
|
104
104
|
/** What a component token is, for its $description (semantic.component.<name>.…). */
|
|
105
105
|
const COMPONENT_DESCRIPTION = {
|
|
106
106
|
radius: 'corner radius (px; 9999 = a pill)',
|
|
@@ -115,6 +115,16 @@ const COMPONENT_DESCRIPTION = {
|
|
|
115
115
|
'text.leading': 'line height (px), fitted to the control',
|
|
116
116
|
'text.tracking': 'letter spacing (em)',
|
|
117
117
|
'text.font': "the text style's font",
|
|
118
|
+
'text.weight': "the label's font weight",
|
|
119
|
+
'text.uppercase': '1 = uppercase labels',
|
|
120
|
+
'gap.sm': 'small gap between an icon and the label (px)',
|
|
121
|
+
'gap.md': 'gap between an icon and the label (px)',
|
|
122
|
+
'gap.lg': 'large gap between an icon and the label (px)',
|
|
123
|
+
icon: 'icon size (px)',
|
|
124
|
+
shadow: 'shadow level (0 = none)',
|
|
125
|
+
'ring-width': 'focus ring width (px)',
|
|
126
|
+
'focus-border': 'border colour when focused (the focus ring role)',
|
|
127
|
+
placeholder: 'placeholder text colour (a role)',
|
|
118
128
|
fill: 'fill colour (a role)',
|
|
119
129
|
'fill-alpha': 'fill opacity',
|
|
120
130
|
label: 'label colour (a role)',
|
|
@@ -124,7 +134,7 @@ const COMPONENT_DESCRIPTION = {
|
|
|
124
134
|
'edge-width': 'bottom edge width (px)',
|
|
125
135
|
pressed: 'pressed and hover fill (derived from the fill unless set)',
|
|
126
136
|
'pressed-alpha': 'pressed and hover opacity',
|
|
127
|
-
ring: 'focus ring colour (the border, faded)',
|
|
137
|
+
ring: 'focus ring colour (a role or the border, faded)',
|
|
128
138
|
'ring-alpha': 'focus ring opacity',
|
|
129
139
|
alpha: "the style's fill opacity",
|
|
130
140
|
round: '1 = rounded top corners, 0 = square',
|