@halftone-ds/tokens 1.4.0 → 1.6.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 +54 -6
- package/cli.mjs +21 -12
- package/lib/doctor.mjs +360 -0
- package/lib/generate.mjs +28 -0
- package/lib/import-cli.mjs +87 -0
- package/lib/init.mjs +18 -3
- package/lib/resolve.mjs +18 -1
- package/lib/system/generate.mjs +5 -1
- package/lib/system/import.mjs +552 -0
- package/lib/system/index.d.mts +20 -1
- package/lib/system/index.mjs +2 -0
- package/lib/system/schema.mjs +67 -1
- package/lib/theme/apply.mjs +17 -2
- package/lib/theme/codec.mjs +13 -7
- package/lib/theme/generate.mjs +3 -0
- package/lib/theme/index.d.mts +36 -0
- package/lib/theme/index.mjs +3 -2
- package/lib/theme/motion.mjs +99 -0
- package/lib/theme/recipe.mjs +11 -1
- package/lib/theme/vars.mjs +18 -0
- package/package.json +1 -1
- package/targets/design-md.mjs +8 -3
- package/targets/figma.mjs +3 -0
- package/targets/llms.mjs +1 -1
- package/targets/nativewind3.mjs +4 -1
- package/targets/shadcn-web.mjs +32 -2
- package/targets/ts-theme.mjs +28 -1
- package/templates/tokens.json +37 -0
package/targets/shadcn-web.mjs
CHANGED
|
@@ -6,13 +6,17 @@
|
|
|
6
6
|
* options: { out: 'tokens/generated/web.css' }
|
|
7
7
|
* density: false leave the spacing scale alone (the docs site)
|
|
8
8
|
* typeset: false leave the text sizes alone (the docs site keeps its reading sizes)
|
|
9
|
+
* Motion: --duration-*, --ease-* and --spring-* in :root, with duration-fast|base|slow, ease-standard|emphasized|exit and
|
|
10
|
+
* spring-snappy|gentle classes (a spring class sets the easing and its duration together). A transition or an enter/exit
|
|
11
|
+
* animation without a duration class takes the theme's fast duration and standard easing, so the theme's Speed reaches
|
|
12
|
+
* every component, the overlays tw-animate-css draws included (it reads --tw-duration).
|
|
9
13
|
*/
|
|
10
14
|
import { hexToOklch } from '../lib/color.mjs';
|
|
11
15
|
import { group, radiusCss } from '../lib/resolve.mjs';
|
|
12
16
|
import { TEXT_LINE_HEIGHT } from '../lib/theme/recipe.mjs';
|
|
13
17
|
import { COMPONENT_NAMES, COMPONENTS, componentColors, componentVars } from '../lib/theme/components.mjs';
|
|
14
18
|
import { hasExtras } from '../lib/theme/extras.mjs';
|
|
15
|
-
import { extraVars, styleVars, textStyleVars, typeVars } from '../lib/theme/vars.mjs';
|
|
19
|
+
import { extraVars, motionVars, styleVars, textStyleVars, typeVars } from '../lib/theme/vars.mjs';
|
|
16
20
|
|
|
17
21
|
const rem = (px) => (px >= 9999 ? '9999px' : `${px / 16}rem`);
|
|
18
22
|
const SYSTEM_SANS = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
|
|
@@ -112,6 +116,20 @@ function componentsCss(ctx) {
|
|
|
112
116
|
};
|
|
113
117
|
}
|
|
114
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The motion classes: durations and springs (an easing class is Tailwind's own, from --ease-* in @theme). Like Tailwind's
|
|
121
|
+
* duration-200, they set --tw-duration (and a spring --tw-ease) too, which tw-animate-css's animate-in/out read.
|
|
122
|
+
*/
|
|
123
|
+
function motionUtilities(motion) {
|
|
124
|
+
return [
|
|
125
|
+
...Object.keys(motion.durations).map((n) => `@utility duration-${n} {\n --tw-duration: var(--duration-${n});\n transition-duration: var(--duration-${n});\n}`),
|
|
126
|
+
...Object.keys(motion.springs).map(
|
|
127
|
+
(n) =>
|
|
128
|
+
`@utility spring-${n} {\n --tw-ease: var(--spring-${n});\n --tw-duration: var(--spring-${n}-duration);\n transition-timing-function: var(--spring-${n});\n transition-duration: var(--spring-${n}-duration);\n}`
|
|
129
|
+
),
|
|
130
|
+
].join('\n');
|
|
131
|
+
}
|
|
132
|
+
|
|
115
133
|
export default function shadcnWeb(ctx, options) {
|
|
116
134
|
const extras = extrasCss(ctx);
|
|
117
135
|
const components = componentsCss(ctx);
|
|
@@ -133,6 +151,8 @@ export default function shadcnWeb(ctx, options) {
|
|
|
133
151
|
}
|
|
134
152
|
${styles('light')}
|
|
135
153
|
${shadows('light')}
|
|
154
|
+
/* Motion: durations, easings and springs (a spring is a linear() easing and the time it takes to settle). */
|
|
155
|
+
${Object.entries(motionVars(ctx.motion)).map(([k, v]) => ` ${k}: ${v};`).join('\n')}
|
|
136
156
|
/* The text styles (type-h1…type-blockquote), literal at the typeset: an edited style is one variable. */
|
|
137
157
|
${Object.entries(textStyleVars(ctx.textStyles, 'oklch', (role) => FONT_ROLE[role])).map(([k, v]) => ` ${k}: ${v};`).join('\n')}
|
|
138
158
|
${vars('light')}${components.light}${extras.light}
|
|
@@ -161,18 +181,28 @@ ${ctx.radius.steps.map((s) => ` --radius-${s.name}: ${radiusCss(s)};`).join('\n
|
|
|
161
181
|
--shadow-2xl: var(--shadow-3);
|
|
162
182
|
--font-sans: var(--kit-font-body, ${SYSTEM_SANS});
|
|
163
183
|
--font-heading: var(--kit-font-heading, var(--kit-font-body, ${SYSTEM_SANS}));
|
|
164
|
-
--font-mono: var(--kit-font-mono, ${SYSTEM_MONO})
|
|
184
|
+
--font-mono: var(--kit-font-mono, ${SYSTEM_MONO});
|
|
185
|
+
${Object.keys(ctx.motion.easings).map((n) => ` --ease-${n}: var(--ease-${n});`).join('\n')}
|
|
186
|
+
/* A transition without a duration or easing class takes the theme's (Tailwind's default is 150ms, its own curve). */
|
|
187
|
+
--default-transition-duration: var(--duration-fast);
|
|
188
|
+
--default-transition-timing-function: var(--ease-standard);${
|
|
165
189
|
options.typeset === false ? '' : `\n /* The theme's typeset scales every text size and its line height (text-sm, text-base…). */\n${textScale(ctx)}`
|
|
166
190
|
}
|
|
167
191
|
${ctx.colors.map((c) => ` --color-${c.name}: ${color(c.name)};`).join('\n')}${components.theme}${extras.theme}
|
|
168
192
|
}
|
|
169
193
|
|
|
170
194
|
${textStyleUtilities(Object.keys(ctx.textStyles))}
|
|
195
|
+
${motionUtilities(ctx.motion)}
|
|
171
196
|
${components.utilities}${extras.utilities}
|
|
172
197
|
@layer base {
|
|
173
198
|
* {
|
|
174
199
|
@apply border-border outline-ring/50;
|
|
175
200
|
}
|
|
201
|
+
/* An enter or exit animation without a duration class (popovers, menus, tooltips) takes the theme's fast duration:
|
|
202
|
+
tw-animate-css reads --tw-duration, and its own fallback is a fixed 150ms. A duration-* class still wins. */
|
|
203
|
+
*, ::before, ::after {
|
|
204
|
+
--tw-duration: var(--duration-fast);
|
|
205
|
+
}
|
|
176
206
|
body {
|
|
177
207
|
@apply bg-background text-foreground;
|
|
178
208
|
}
|
package/targets/ts-theme.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* lib/theme.ts — semantic colours as hex per scheme, non-colour primitives, and (for Expo Router apps)
|
|
3
|
-
* the React Navigation theme.
|
|
3
|
+
* the React Navigation theme, and MOTION (durations, easings and springs, typed, for Motion and Reanimated).
|
|
4
4
|
* options: { out: 'lib/theme.ts', navTheme?: 'expo-router/react-navigation' | false }
|
|
5
5
|
*/
|
|
6
6
|
import { camel, group } from '../lib/resolve.mjs';
|
|
@@ -144,6 +144,32 @@ ${primitiveGroup(ctx.prim, ['easing'])}
|
|
|
144
144
|
},
|
|
145
145
|
} as const;
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* The theme's motion, at its speed: durations (ms), easings (cubic-bezier) and springs (stiffness, damping, mass).
|
|
149
|
+
* Reanimated: \`withTiming(v, { duration: MOTION.duration.base, easing: Easing.bezier(...MOTION.easing.standard) })\`,
|
|
150
|
+
* \`withSpring(v, MOTION.spring.snappy)\`. Motion: \`transition={{ type: 'spring', ...MOTION.spring.snappy }}\`, or
|
|
151
|
+
* \`{ duration: MOTION.duration.base / 1000, ease: MOTION.easing.standard }\`. Respect reduced motion either way.
|
|
152
|
+
*/
|
|
153
|
+
export const MOTION: Motion = ${JSON.stringify(
|
|
154
|
+
{
|
|
155
|
+
duration: ctx.motion.durations,
|
|
156
|
+
easing: ctx.motion.easings,
|
|
157
|
+
spring: ctx.motion.springs,
|
|
158
|
+
},
|
|
159
|
+
null,
|
|
160
|
+
2
|
|
161
|
+
)};
|
|
162
|
+
|
|
163
|
+
export type Spring = { stiffness: number; damping: number; mass: number };
|
|
164
|
+
export type Motion = {
|
|
165
|
+
/** ms: fast for hover and small feedback, base for most transitions, slow for sheets. */
|
|
166
|
+
duration: { fast: number; base: number; slow: number };
|
|
167
|
+
/** cubic-bezier [x1, y1, x2, y2]: standard for most movement, emphasized for entering, exit for leaving. */
|
|
168
|
+
easing: { standard: readonly [number, number, number, number]; emphasized: readonly [number, number, number, number]; exit: readonly [number, number, number, number] };
|
|
169
|
+
/** snappy for presses and toggles, gentle for sheets and cards settling in. */
|
|
170
|
+
spring: { snappy: Spring; gentle: Spring };
|
|
171
|
+
};
|
|
172
|
+
|
|
147
173
|
/** The component layer's CSS variables (what an embedded kit accepts from the docs site's live theme). */
|
|
148
174
|
export const COMPONENT_VARS = ${JSON.stringify(componentVarNames())} as const;
|
|
149
175
|
|
|
@@ -174,6 +200,7 @@ export type ThemeInfo = {
|
|
|
174
200
|
measure: string;
|
|
175
201
|
button?: string;
|
|
176
202
|
field?: string;
|
|
203
|
+
speed?: string;
|
|
177
204
|
preset?: string;
|
|
178
205
|
};
|
|
179
206
|
};
|
package/templates/tokens.json
CHANGED
|
@@ -460,6 +460,42 @@
|
|
|
460
460
|
1
|
|
461
461
|
]
|
|
462
462
|
}
|
|
463
|
+
},
|
|
464
|
+
"spring": {
|
|
465
|
+
"snappy": {
|
|
466
|
+
"stiffness": {
|
|
467
|
+
"$type": "number",
|
|
468
|
+
"$description": "Spring snappy (presses, toggles, small moves): stiffness (how hard it pulls toward rest). DTCG has no spring type, so it is three numbers.",
|
|
469
|
+
"$value": 400
|
|
470
|
+
},
|
|
471
|
+
"damping": {
|
|
472
|
+
"$type": "number",
|
|
473
|
+
"$description": "Spring snappy (presses, toggles, small moves): damping (how quickly the bounce dies). DTCG has no spring type, so it is three numbers.",
|
|
474
|
+
"$value": 36
|
|
475
|
+
},
|
|
476
|
+
"mass": {
|
|
477
|
+
"$type": "number",
|
|
478
|
+
"$description": "Spring snappy (presses, toggles, small moves): mass. DTCG has no spring type, so it is three numbers.",
|
|
479
|
+
"$value": 1
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
"gentle": {
|
|
483
|
+
"stiffness": {
|
|
484
|
+
"$type": "number",
|
|
485
|
+
"$description": "Spring gentle (sheets, cards settling in): stiffness (how hard it pulls toward rest). DTCG has no spring type, so it is three numbers.",
|
|
486
|
+
"$value": 120
|
|
487
|
+
},
|
|
488
|
+
"damping": {
|
|
489
|
+
"$type": "number",
|
|
490
|
+
"$description": "Spring gentle (sheets, cards settling in): damping (how quickly the bounce dies). DTCG has no spring type, so it is three numbers.",
|
|
491
|
+
"$value": 18
|
|
492
|
+
},
|
|
493
|
+
"mass": {
|
|
494
|
+
"$type": "number",
|
|
495
|
+
"$description": "Spring gentle (sheets, cards settling in): mass. DTCG has no spring type, so it is three numbers.",
|
|
496
|
+
"$value": 1
|
|
497
|
+
}
|
|
498
|
+
}
|
|
463
499
|
}
|
|
464
500
|
},
|
|
465
501
|
"semantic": {
|
|
@@ -2318,6 +2354,7 @@
|
|
|
2318
2354
|
"measure": "70",
|
|
2319
2355
|
"button": "solid",
|
|
2320
2356
|
"field": "outline",
|
|
2357
|
+
"speed": "normal",
|
|
2321
2358
|
"preset": "default"
|
|
2322
2359
|
},
|
|
2323
2360
|
"adjustments": [
|