@halftone-ds/tokens 1.1.0 → 1.2.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 +42 -4
- package/cli.mjs +28 -12
- package/lib/apca.mjs +55 -0
- package/lib/color.mjs +27 -7
- package/lib/contrast.mjs +23 -1
- package/lib/cvd.mjs +97 -0
- package/lib/resolve.mjs +31 -3
- package/lib/theme/apply.mjs +17 -1
- package/lib/theme/codec.mjs +38 -23
- package/lib/theme/fonts.mjs +3 -1
- package/lib/theme/generate.mjs +27 -4
- package/lib/theme/index.d.mts +75 -0
- package/lib/theme/index.mjs +15 -2
- package/lib/theme/presets.mjs +18 -6
- package/lib/theme/recipe.mjs +39 -0
- package/lib/theme/semantic.mjs +25 -0
- package/lib/theme/shadcn.mjs +265 -0
- package/lib/theme/vars.mjs +25 -0
- package/lib/theme-cli.mjs +98 -6
- package/package.json +1 -1
- package/targets/design-md.mjs +33 -3
- package/targets/llms.mjs +2 -1
- package/targets/nativewind3.mjs +22 -7
- package/targets/shadcn-web.mjs +12 -2
- package/targets/ts-theme.mjs +7 -0
package/targets/shadcn-web.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { hexToOklch } from '../lib/color.mjs';
|
|
11
11
|
import { group, radiusCalc } from '../lib/resolve.mjs';
|
|
12
12
|
import { TEXT_LINE_HEIGHT } from '../lib/theme/recipe.mjs';
|
|
13
|
-
import { typeVars } from '../lib/theme/vars.mjs';
|
|
13
|
+
import { styleVars, typeVars } from '../lib/theme/vars.mjs';
|
|
14
14
|
|
|
15
15
|
const rem = (px) => (px >= 9999 ? '9999px' : `${px / 16}rem`);
|
|
16
16
|
const SYSTEM_SANS = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
|
|
@@ -29,6 +29,10 @@ function textScale(ctx) {
|
|
|
29
29
|
|
|
30
30
|
export default function shadcnWeb(ctx, options) {
|
|
31
31
|
const vars = (mode) => ctx.colors.map((c) => ` --${c.name}: ${hexToOklch(c[mode])};`).join('\n');
|
|
32
|
+
const styles = (mode) => Object.entries(styleVars(ctx.shape, 'oklch')[mode]).map(([k, v]) => ` ${k}: ${v};`).join('\n');
|
|
33
|
+
// The styles' fills carry their own opacity (an outline button, a transparent field).
|
|
34
|
+
const color = (name) =>
|
|
35
|
+
name === 'button' || name === 'field' ? `color-mix(in oklab, var(--${name}) calc(var(--${name}-alpha) * 100%), transparent)` : `var(--${name})`;
|
|
32
36
|
const shadows = (mode) => Object.entries(ctx.shape.shadows[mode]).map(([level, css]) => ` --shadow-${level}: ${css};`).join('\n');
|
|
33
37
|
const contents = `/* ${ctx.header} */
|
|
34
38
|
@custom-variant dark (&:is(.dark *));
|
|
@@ -40,11 +44,13 @@ export default function shadcnWeb(ctx, options) {
|
|
|
40
44
|
--icon-stroke: ${ctx.shape.stroke};${options.density === false ? '' : `\n --density: ${ctx.shape.density.scale};`}${
|
|
41
45
|
options.typeset === false ? '' : '\n' + Object.entries(typeVars(ctx.type)).map(([k, v]) => ` ${k}: ${v};`).join('\n')
|
|
42
46
|
}
|
|
47
|
+
${styles('light')}
|
|
43
48
|
${shadows('light')}
|
|
44
49
|
${vars('light')}
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
.dark {
|
|
53
|
+
${styles('dark')}
|
|
48
54
|
${shadows('dark')}
|
|
49
55
|
${vars('dark')}
|
|
50
56
|
}
|
|
@@ -52,6 +58,10 @@ ${vars('dark')}
|
|
|
52
58
|
@theme inline {
|
|
53
59
|
${ctx.radius.steps.map((s) => ` --radius-${s.name}: ${radiusCalc(s.scale)};`).join('\n')}
|
|
54
60
|
--radius-control: var(--radius-control);
|
|
61
|
+
/* The field style: rounded-field, rounded-b-field-b, px-field-x. Widths are border-(length:--field-border-w) etc. */
|
|
62
|
+
--radius-field: var(--field-radius);
|
|
63
|
+
--radius-field-b: var(--field-radius-b);
|
|
64
|
+
--spacing-field-x: var(--field-x);
|
|
55
65
|
--default-border-width: var(--border-width);${options.density === false ? '' : `\n /* The theme's density scales the whole spacing scale (p-4, gap-2, h-9…). */\n --spacing: calc(0.25rem * var(--density));`}
|
|
56
66
|
--shadow-2xs: var(--shadow-1);
|
|
57
67
|
--shadow-xs: var(--shadow-1);
|
|
@@ -65,7 +75,7 @@ ${ctx.radius.steps.map((s) => ` --radius-${s.name}: ${radiusCalc(s.scale)};`).j
|
|
|
65
75
|
--font-mono: var(--kit-font-mono, ${SYSTEM_MONO});${
|
|
66
76
|
options.typeset === false ? '' : `\n /* The theme's typeset scales every text size and its line height (text-sm, text-base…). */\n${textScale(ctx)}`
|
|
67
77
|
}
|
|
68
|
-
${ctx.colors.map((c) => ` --color-${c.name}:
|
|
78
|
+
${ctx.colors.map((c) => ` --color-${c.name}: ${color(c.name)};`).join('\n')}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
@layer base {
|
package/targets/ts-theme.mjs
CHANGED
|
@@ -72,6 +72,11 @@ ${primitiveGroup(ctx.prim, ['radius'])}
|
|
|
72
72
|
iconStroke: ${ctx.shape.stroke},
|
|
73
73
|
/** Width of \`border\` in px. */
|
|
74
74
|
borderWidth: ${ctx.shape.borderWidth},
|
|
75
|
+
/** The theme's styles (button: solid · soft · outline · raised; field: outline · filled · underline) and their
|
|
76
|
+
* numbers (px): bg-button / bg-field, border-button-w, rounded-field… already follow them. */
|
|
77
|
+
styles: ${JSON.stringify(ctx.styles)},
|
|
78
|
+
button: ${JSON.stringify(ctx.shape.button)},
|
|
79
|
+
field: ${JSON.stringify(ctx.shape.field)},
|
|
75
80
|
/** Control heights and padding (px) for the theme's density: h-control-sm, h-control, h-control-lg, px-control-x. */
|
|
76
81
|
density: ${JSON.stringify({ sm: ctx.shape.density.sm, md: ctx.shape.density.md, lg: ctx.shape.density.lg, x: ctx.shape.density.x })},
|
|
77
82
|
/** The type scale at 16px; the theme's typeset multiplies it (text-* classes are already scaled). */
|
|
@@ -115,6 +120,8 @@ export type ThemeInfo = {
|
|
|
115
120
|
leading: string;
|
|
116
121
|
flow: string;
|
|
117
122
|
measure: string;
|
|
123
|
+
button?: string;
|
|
124
|
+
field?: string;
|
|
118
125
|
preset?: string;
|
|
119
126
|
};
|
|
120
127
|
};
|