@halftone-ds/tokens 1.3.1 → 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.
@@ -106,16 +106,41 @@ export type ComponentShape = {
106
106
  h: Partial<Record<'sm' | 'md' | 'lg', number>>;
107
107
  /** Horizontal padding (px) by size. */
108
108
  x: Partial<Record<'sm' | 'md' | 'lg', number>>;
109
- /** Font role, size and line height (px), tracking (em); `style` the text style it follows. */
110
- text: { style?: string; font: 'heading' | 'body' | 'mono'; size: number; leading: number; tracking: number };
109
+ /** Font role, size and line height (px), tracking (em), the label's weight and case; `style` the text style it follows. */
110
+ text: { style?: string; font: 'heading' | 'body' | 'mono'; size: number; leading: number; tracking: number; weight: number; case: ComponentCase };
111
+ /** The border width set on the component (px), or null: as the style draws it. */
112
+ border?: number | null;
113
+ /** Chip, Badge and Input: the drawn border and bottom edge (px). Button's are per variant. */
114
+ borderWidth?: number;
115
+ edgeWidth?: number;
116
+ /** The gap between an icon and the label (px) by size; Input has none. */
117
+ gap?: Partial<Record<'sm' | 'md' | 'lg', number>>;
118
+ /** Icon size (px): ICON_DEFAULT until a system sets one. */
119
+ icon?: number;
120
+ /** Button and Input: a Foundations shadow level, or 'none' (defaultShadow until a system sets one). */
121
+ shadow?: ComponentShadow;
122
+ /** Button and Input: the focus ring's width (px) and role (null: derived). */
123
+ ring?: { width: number; role: string | null };
124
+ /** Button: the focused border (the ring's role). */
125
+ focusBorder?: ComponentColor;
126
+ /** Input: the placeholder's colour. */
127
+ placeholder?: ComponentColor;
111
128
  variants: Record<string, ComponentVariant>;
112
129
  };
130
+ export type ComponentCase = 'none' | 'uppercase';
131
+ export type ComponentShadow = 'none' | '1' | '2' | '3';
132
+ export type ComponentProp = 'border' | 'weight' | 'case' | 'icon' | 'shadow' | 'ring' | 'placeholder';
113
133
  export type ComponentShapes = Record<ComponentName, ComponentShape>;
114
134
  export type ComponentDefinition = {
115
135
  prefix: string;
116
136
  label: string;
117
137
  styles: string[];
118
- sizes: Array<'sm' | 'md' | 'lg' | 'x'>;
138
+ /** The size steps it has (heights). */
139
+ steps: Array<'sm' | 'md' | 'lg'>;
140
+ /** The size keys a system may set: the steps, padding and (not Input) the icon gap. */
141
+ sizes: Array<'sm' | 'md' | 'lg' | 'x' | 'gap'>;
142
+ /** The properties beyond style, corner, size and text it has. */
143
+ props: ComponentProp[];
119
144
  variants: Record<string, ComponentSlot[]>;
120
145
  text: string;
121
146
  };
@@ -124,6 +149,14 @@ export const COMPONENTS: Record<ComponentName, ComponentDefinition>;
124
149
  export const CORNERS: Corner[];
125
150
  export const SLOTS: ComponentSlot[];
126
151
  export const SLOT_VAR: Record<ComponentSlot | 'ring', string>;
152
+ export const WEIGHTS: number[];
153
+ export const CASES: ComponentCase[];
154
+ export const SHADOWS: ComponentShadow[];
155
+ /** The icon size (px) each component draws on the web until a system sets one. */
156
+ export const ICON_DEFAULT: Record<'button' | 'chip' | 'badge', number>;
157
+ export const RING_WIDTH: number;
158
+ /** A component's shadow until a system sets one: Button '1'; Input '1' for a boxed field (a border), else 'none'. */
159
+ export function defaultShadow(name: ComponentName, borderWidth?: number): ComponentShadow;
127
160
  /** The touch-target floor (px) the mobile kit applies on phones. */
128
161
  export const TOUCH_TARGET: number;
129
162
  export function defaultCorner(name: ComponentName, options?: { controls?: string; style?: string }): Corner;
@@ -27,6 +27,7 @@ export { CVD_TYPES, cvdWarnings, describeCvdWarnings, DISTINCT_PAIRS, MIN_DELTA_
27
27
 
28
28
  export { AA, AA_NON_TEXT, componentContrast, contrastPairs, contrastReport } from '../contrast.mjs';
29
29
  export {
30
+ CASES,
30
31
  COMPONENT_NAMES,
31
32
  COMPONENTS,
32
33
  componentColors,
@@ -35,10 +36,15 @@ export {
35
36
  componentVars,
36
37
  CORNERS,
37
38
  defaultCorner,
39
+ defaultShadow,
38
40
  defaultStyle,
39
41
  fittedLeading,
42
+ ICON_DEFAULT,
43
+ RING_WIDTH,
44
+ SHADOWS,
40
45
  SLOT_VAR,
41
46
  SLOTS,
42
47
  TOUCH_TARGET,
48
+ WEIGHTS,
43
49
  } from './components.mjs';
44
50
  export { apcaContrast } from '../apca.mjs';
@@ -20,6 +20,29 @@ export const darkStep = (anchor) => DARK_STEP[anchor] ?? anchor;
20
20
  const STATUS_STEPS = { danger: [0, -1], success: [1, -1], warning: [1, -2], info: [1, -1] };
21
21
  const status = (ramp, anchor = '600') => ({ light: p(ramp, shift(anchor, STATUS_STEPS[ramp][0])), dark: p(ramp, shift(anchor, STATUS_STEPS[ramp][1])) });
22
22
 
23
+ /**
24
+ * The tints: colours come from the ramps, not from opacity (a colour at partial opacity takes on whatever is
25
+ * behind it, so its contrast changes with the surface). `<tone>-subtle` is a tinted surface (an Alert, an
26
+ * IconCircle, a selected card), `<tone>-border` its edge: a light step on a light page, a dark one on a dark page.
27
+ * Text on a tint is `foreground`; the tone itself is an icon or a dot on it (contrast.mjs checks both).
28
+ */
29
+ const TINT_TONES = { primary: 'brand', success: 'success', warning: 'warning', destructive: 'danger', info: 'info' };
30
+ export const TINT_ROLES = Object.keys(TINT_TONES).flatMap((tone) => [`${tone}-subtle`, `${tone}-border`]);
31
+ const tints = () =>
32
+ Object.fromEntries(
33
+ Object.entries(TINT_TONES).flatMap(([tone, ramp]) => [
34
+ [`${tone}-subtle`, { light: p(ramp, '100'), dark: p(ramp, '950') }],
35
+ [`${tone}-border`, { light: p(ramp, '300'), dark: p(ramp, '900') }],
36
+ ])
37
+ );
38
+
39
+ /**
40
+ * Roles a theme derives from others rather than picking: the tints, `muted-subtle` (a surface a step off the
41
+ * page) and the pressed fills (the next step of the fill's ramp, away from the page). The fixer moves one of these,
42
+ * not the ink on it, when a pairing on it fails (fix.mjs).
43
+ */
44
+ export const isDerived = (name) => /-(subtle|pressed)$/.test(name);
45
+
23
46
  /**
24
47
  * { name: { light: ref, dark: ref } } in the order the kit's tokens.json lists them. `anchors` holds the step
25
48
  * each status seed sits on (`{ danger: '500' }`); a status without one uses its 600, the curated ramps' seed.
@@ -66,6 +89,10 @@ export function semanticColors(anchor = '600', anchors = {}) {
66
89
  'chart-3': { light: p('warning', 500), dark: p('warning', 400) },
67
90
  'chart-4': { light: p('danger', 500), dark: p('danger', 400) },
68
91
  'chart-5': { light: p('info', 500), dark: p('info', 400) },
92
+ 'muted-subtle': { light: n(50), dark: n(900) },
93
+ ...tints(),
94
+ 'primary-pressed': { light: b(shift(anchor, 1)), dark: b(shift(darkStep(anchor), -1)) },
95
+ 'secondary-pressed': { light: n(200), dark: n(700) },
69
96
  };
70
97
  }
71
98
 
@@ -54,8 +54,8 @@ export function textStyleVars(styles, format, font = (role) => `var(--kit-font-$
54
54
  /**
55
55
  * The button and field styles' variables (both formats), from a theme's or a token file's { button, field }
56
56
  * (generate.mjs, resolve.mjs). Widths are numbers on the light block; the field's fill opacity is per mode. A
57
- * field's corners and padding are the component layer's (componentVars: --field-radius, --field-radius-b,
58
- * --field-x).
57
+ * field's corners, padding and shadow are the component layer's (componentVars: --field-radius, --field-radius-b,
58
+ * --field-x, --field-shadow; a field is flat until a system gives it a shadow).
59
59
  */
60
60
  export function styleVars({ button, field }, format) {
61
61
  return {
@@ -66,8 +66,6 @@ export function styleVars({ button, field }, format) {
66
66
  '--field-alpha': String(field.alpha.light),
67
67
  '--field-border-w': `${field.border}px`,
68
68
  '--field-edge-w': `${field.edge}px`,
69
- // Web: a boxed field keeps shadcn's shadow-xs; a filled or underline field has none.
70
- ...(format === 'hsl' ? {} : { '--field-shadow': field.border ? 'var(--shadow-1)' : '0 0 #0000' }),
71
69
  },
72
70
  dark: { '--field-alpha': String(field.alpha.dark) },
73
71
  };
package/lib/usage.mjs CHANGED
@@ -94,7 +94,7 @@ export function usageIn(code, colours, roles = {}) {
94
94
  if (colour && colours.has(colour[1])) keys.add(`color.${colour[1]}`);
95
95
  if (colour && roles[colour[1]]) for (const role of roles[colour[1]]) keys.add(`color.${role}`);
96
96
  const component = COMPONENT_CLASS.exec(cls);
97
- if (component && (roles[colour?.[1]] || /^(rounded|h|w|size|px|type|text-type|leading-type|tracking-type|border(-b)?)-/.test(cls))) keys.add(`component.${PREFIX[component[1]]}`);
97
+ if (component && (roles[colour?.[1]] || /^(rounded|h|min-h|w|size|px|gap|type|text-type|leading-type|tracking-type|border(-b)?)-/.test(cls))) keys.add(`component.${PREFIX[component[1]]}`);
98
98
  const radius = RADIUS.exec(cls);
99
99
  if (radius) keys.add(`radius.${radius[1]}`);
100
100
  if (SHADOW[cls]) keys.add(`shadow.${SHADOW[cls]}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halftone-ds/tokens",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Design tokens (W3C DTCG) to NativeWind, Tailwind 4 / shadcn, TypeScript, DESIGN.md and Figma, with a WCAG AA contrast gate. The token build behind Halftone.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -41,6 +41,7 @@
41
41
  "push-figma.mjs",
42
42
  "lib/",
43
43
  "targets/",
44
+ "templates/",
44
45
  "README.md",
45
46
  "LICENSE"
46
47
  ],
@@ -5,7 +5,7 @@
5
5
  * The detailed rules stay in DESIGN_SYSTEM.md; this file points there instead of repeating them.
6
6
  * options: { out: 'DESIGN.md', name?: string, description?: string, platform?: 'mobile' | 'web' }
7
7
  */
8
- import { describeTintLimits, textOnTintLimits } from '../lib/contrast.mjs';
8
+ import { subtleLine, textOnSubtle } from '../lib/contrast.mjs';
9
9
  import { describeComponents } from '../lib/theme/components.mjs';
10
10
  import { describeExtras } from '../lib/theme/extras.mjs';
11
11
  import { themeFonts } from './fonts.mjs';
@@ -176,17 +176,18 @@ hex literal or a Tailwind palette colour in UI code. Keys ending in \`-dark\` ar
176
176
  - **Background (${hex.background}) and Card (${hex.card}):** the page canvas and raised surfaces.
177
177
  - **Muted foreground (${hex['muted-foreground']}):** helper text, captions, placeholders.
178
178
  - **Destructive, Success, Warning, Info:** status only, each with its own \`-foreground\`.
179
+ - **Tints:** \`primary-subtle\`, \`success-subtle\`, \`warning-subtle\`, \`destructive-subtle\`, \`info-subtle\` (a tinted
180
+ surface: an alert, an icon well, a selected card), each with a \`-border\` (\`border-warning-border\`), and
181
+ \`muted-subtle\`, a surface a step off the page. Pressed fills: \`primary-pressed\`, \`secondary-pressed\`.
179
182
  - **Chart 1–5:** data series.
180
183
 
181
184
  ${contrastLine(ctx)}
182
185
 
183
- A tone's text on that tone's own tint (\`text-success\` on \`bg-success/15\`) is a weaker pairing. With
184
- this palette it clears AA only for:
185
-
186
- ${describeTintLimits(textOnTintLimits(ctx.colors))}.
187
-
188
- On a stronger tint, the text stays \`text-foreground\` and the tint, an icon or a dot carries the
189
- colour. \`halftone-tokens check\` flags class strings that break this.
186
+ Colours come from the ramps, not from opacity: a colour at partial opacity (\`bg-primary/15\`) takes on whatever
187
+ is behind it, so its contrast changes with the surface. Tints are the roles above; transparency is for overlays
188
+ only (the scrim behind a sheet, a frosted bar, a focus ring's halo). Text on a tint is \`text-foreground\` or
189
+ \`text-muted-foreground\`; the tone itself goes on the icon or a dot. ${subtleLine(textOnSubtle(ctx.colors))}
190
+ \`halftone-tokens check\` flags class strings that break this.
190
191
  ${extrasSection}
191
192
  ## Typography
192
193
 
package/targets/fonts.mjs CHANGED
@@ -4,6 +4,9 @@
4
4
  * the family name expo-font registers for each role and weight (FONT_FAMILY)
5
5
  * options: { platform: 'next', out: 'app/fonts.ts' } next/font/google, exposing --kit-font-heading,
6
6
  * --kit-font-body and --kit-font-mono (app/tokens.css maps them to font-heading / font-sans / font-mono)
7
+ * options: { platform: 'web', out: 'src/fonts.css' } any other web app: a Google Fonts @import and the same
8
+ * --kit-font-* variables. Import it FIRST in the app's stylesheet (before tailwindcss): a CSS @import of
9
+ * a URL only works at the very top, and the build hoists it there from the first imported file.
7
10
  * An empty family (heading, body) or Menlo (mono) is the platform's own font: nothing to load.
8
11
  *
9
12
  * A curated font (lib/theme/fonts.mjs) loads the weights it lists; any other Google Fonts family (a system's
@@ -84,8 +87,32 @@ export const fontVariables = [${roles.map(([role]) => `${role}.variable`).join('
84
87
  `;
85
88
  }
86
89
 
90
+ const FALLBACK = { serif: 'serif', mono: 'monospace' };
91
+
92
+ function web(ctx, fonts) {
93
+ const roles = [];
94
+ if (fonts.body) roles.push(['body', fonts.body]);
95
+ if (fonts.heading && fonts.heading.id !== fonts.body?.id) roles.push(['heading', fonts.heading]);
96
+ if (fonts.mono) roles.push(['mono', fonts.mono]);
97
+ if (!roles.length) return `/* ${ctx.header} */\n/* The theme uses the system fonts: nothing to load (tokens.css falls back to the system stacks). */\n`;
98
+ const families = [...new Map(roles.map(([, f]) => [f.id, f])).values()].map((f) => `family=${f.family.replace(/ /g, '+')}:wght@${f.weights.join(';')}`);
99
+ const stack = (role, f) => `'${f.family}', ${FALLBACK[role === 'mono' ? 'mono' : f.category] ?? 'sans-serif'}`;
100
+ return `/* ${ctx.header} */
101
+ /* Import this file first in the app's stylesheet, before tailwindcss: a URL @import only works at the top. */
102
+ @import url('https://fonts.googleapis.com/css2?${families.join('&')}&display=swap');
103
+
104
+ :root {
105
+ ${roles.map(([role, f]) => ` --kit-font-${role}: ${stack(role, f)};`).join('\n')}
106
+ }
107
+ `;
108
+ }
109
+
110
+ const PLATFORMS = { expo, next, web };
111
+
87
112
  export default function fontsTarget(ctx, options) {
88
113
  const fonts = themeFonts(ctx);
89
- const contents = options.platform === 'next' ? next(ctx, fonts) : expo(ctx, fonts);
114
+ const platform = PLATFORMS[options.platform ?? 'expo'];
115
+ if (!platform) throw new Error(`fonts: unknown platform "${options.platform}" (expo, next or web)`);
116
+ const contents = platform(ctx, fonts);
90
117
  return [{ path: options.out, contents }];
91
118
  }
package/targets/llms.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  * options: { out: 'tokens/generated/llms-tokens.md', platform?: 'mobile' | 'web' }
5
5
  */
6
6
  import { group } from '../lib/resolve.mjs';
7
- import { AA, describeTintLimits, textOnTintLimits } from '../lib/contrast.mjs';
7
+ import { AA, subtleLine, textOnSubtle } from '../lib/contrast.mjs';
8
8
  import { themeStatus } from '../lib/theme/index.mjs';
9
9
  import { themeFonts } from './fonts.mjs';
10
10
  import { describeComponents } from '../lib/theme/components.mjs';
@@ -23,11 +23,11 @@ export default function llms(ctx, options) {
23
23
  ## Tokens
24
24
 
25
25
  Colours are semantic names only, used as Tailwind classes (\`bg-primary\`, \`text-muted-foreground\`,
26
- \`border-border\`, \`bg-success/15\`). Never hex, never Tailwind palette colours. Both themes are
26
+ \`border-border\`, \`bg-success-subtle\`). Never hex, never Tailwind palette colours, never a colour at an
27
+ opacity (\`bg-primary/15\`): tints are the \`-subtle\` roles (with \`-border\`), \`muted-subtle\` and the
28
+ \`-pressed\` fills; only overlays (the \`bg-black/50\` scrim, a frosted bar, focus halos) are see-through. Both themes are
27
29
  required; ${ctx.contrastFailures?.length ? `${ctx.contrastFailures.length} pairing(s) in this palette fall below WCAG AA (${AA}:1): fix them (\`npm run tokens:build\` names them).` : `every fill/foreground pairing clears WCAG AA (${AA}:1); \`npm run tokens:build\` names any that falls short (\`--strict\` fails on it).`}
28
- A tone's own text on its own tint (\`text-success\` on \`bg-success/15\`) clears AA only for these
29
- tints; on a stronger one, put \`text-foreground\` on the tint:
30
- ${describeTintLimits(textOnTintLimits(ctx.colors))}.
30
+ Text on a tint is \`text-foreground\`; the tone goes on the icon or a dot. ${subtleLine(textOnSubtle(ctx.colors))}
31
31
 
32
32
  | Name | Light | Dark |
33
33
  |---|---|---|
@@ -1,7 +1,13 @@
1
1
  /**
2
- * NativeWind 4 / Tailwind 3 (shadcn v3 shape): bare HSL triplets in `:root` and `.dark:root`, plus the
3
- * colour + radius maps tailwind.config.js spreads in.
4
- * options: { css: 'global.css', tailwind: 'tokens/generated/tailwind.theme.js' }
2
+ * NativeWind 4 / Tailwind 3 (shadcn v3 shape): bare HSL triplets in `:root` and `.dark:root`, plus the theme
3
+ * extension Tailwind needs (colours, radius, sizes, type, shadows…).
4
+ * options: { css: 'global.css', tailwind: 'tokens/generated/tailwind.theme.js' } the whole stylesheet, and the
5
+ * extension as a map tailwind.config.js spreads in, key by key
6
+ * options: { css: 'tokens/generated/tokens.css', partial: true, preset: 'tokens/generated/tailwind.preset.js' }
7
+ * only the variables, for the app's own global.css to import first (`@import './tokens/generated/tokens.css';`
8
+ * before `@tailwind base;`: Tailwind's build inlines it, so it reaches native too), and the extension as a
9
+ * Tailwind preset the app's tailwind.config.js lists once (`presets: [require('nativewind/preset'),
10
+ * require('./tokens/generated/tailwind.preset')]`). `tailwind` and `preset` can both be written.
5
11
  */
6
12
  import { hexToHslTriplet } from '../lib/color.mjs';
7
13
  import { cssName, group, isColor, radiusCss } from '../lib/resolve.mjs';
@@ -49,11 +55,11 @@ function cssBlock(selector, tokens, shape, mode, colors) {
49
55
  }
50
56
 
51
57
  export default function nativewind3(ctx, options) {
58
+ const directives = options.partial
59
+ ? '/* Import this file first in global.css, before `@tailwind base;`. */\n'
60
+ : '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n';
52
61
  const css = `/* ${ctx.header} */
53
- @tailwind base;
54
- @tailwind components;
55
- @tailwind utilities;
56
-
62
+ ${directives}
57
63
  @layer base {
58
64
  ${cssBlock(':root', ctx.semLight, { ...ctx.shape, styleShape: ctx.shape, textStyles: ctx.textStyles, extras: ctx.extras, components: ctx.components }, 'light', ctx.colors)}
59
65
 
@@ -98,7 +104,8 @@ ${cssBlock('.dark:root', ctx.semDark, { styleShape: ctx.shape, extras: ctx.extra
98
104
  const letterSpacing = Object.fromEntries(Object.keys(ctx.textStyles).map((name) => [`type-${name}`, `var(--type-${name}-tracking)`]));
99
105
  const fontWeight = Object.fromEntries(Object.keys(ctx.textStyles).map((name) => [`type-${name}`, `var(--type-${name}-weight)`]));
100
106
  // The component layer: bg-button-primary-bg, rounded-button, h-button-md, px-button-x, text-type-button,
101
- // border-button-primary-w… Each colour carries its opacity (--button-primary-bg-a).
107
+ // border-button-primary-w, gap-button-gap, border-chip… Each colour carries its opacity (--button-primary-bg-a).
108
+ // Weight, case and shadow are picked in JS from TOKENS.components (a custom font is one family per weight).
102
109
  Object.assign(colors, componentColors(ctx.components, (key, alpha) => (alpha ? `hsl(var(--${key}) / var(--${key}-a))` : `hsl(var(--${key}))`)));
103
110
  for (const name of COMPONENT_NAMES) {
104
111
  const c = ctx.components[name];
@@ -111,6 +118,10 @@ ${cssBlock('.dark:root', ctx.semDark, { styleShape: ctx.shape, extras: ctx.extra
111
118
  letterSpacing[`type-${p}`] = `var(--${p}-text-tracking)`;
112
119
  }
113
120
  Object.assign(spacing, { 'button-x-sm': 'var(--button-x-sm)', 'button-x-lg': 'var(--button-x-lg)' });
121
+ // Gaps (gap-button-gap, gap-button-gap-sm, gap-chip-gap, gap-badge-gap) and Chip and Badge borders (border-chip).
122
+ for (const name of ['button', 'chip', 'badge']) spacing[`${name}-gap`] = `var(--${name}-gap)`;
123
+ spacing['button-gap-sm'] = 'var(--button-gap-sm)';
124
+ for (const name of ['chip', 'badge']) borderWidth[name] = `var(--${name}-border-w)`;
114
125
  for (const variant of Object.keys(ctx.components.button.variants)) {
115
126
  borderWidth[`button-${variant}-w`] = `var(--button-${variant}-border-w)`;
116
127
  borderWidth[`button-${variant}-edge-w`] = `var(--button-${variant}-edge-w)`;
@@ -127,9 +138,25 @@ ${cssBlock('.dark:root', ctx.semDark, { styleShape: ctx.shape, extras: ctx.extra
127
138
  letterSpacing[`type-${name}`] = `var(--type-${name}-tracking)`;
128
139
  fontWeight[`type-${name}`] = `var(--type-${name}-weight)`;
129
140
  }
130
- const tailwind = `// ${ctx.header}\nmodule.exports = ${JSON.stringify({ colors, borderRadius, borderWidth, boxShadow, height, minHeight: height, width: height, spacing, fontSize, lineHeight, letterSpacing, fontWeight, maxWidth }, null, 2)};\n`;
131
- return [
132
- { path: options.css, contents: css },
133
- { path: options.tailwind, contents: tailwind },
134
- ];
141
+ const extend = { colors, borderRadius, borderWidth, boxShadow, height, minHeight: height, width: height, spacing, fontSize, lineHeight, letterSpacing, fontWeight, maxWidth };
142
+ const files = [{ path: options.css, contents: css }];
143
+ if (options.tailwind) files.push({ path: options.tailwind, contents: `// ${ctx.header}\nmodule.exports = ${JSON.stringify(extend, null, 2)};\n` });
144
+ if (options.preset) {
145
+ // A preset merges into the app's config: its `extend` adds to the app's own, with the hairline border NativeWind
146
+ // computes per device.
147
+ files.push({
148
+ path: options.preset,
149
+ contents: `// ${ctx.header}
150
+ // A Tailwind preset: list it in tailwind.config.js after nativewind/preset.
151
+ const { hairlineWidth } = require('nativewind/theme');
152
+
153
+ const extend = ${JSON.stringify(extend, null, 2)};
154
+ extend.borderWidth.hairline = hairlineWidth();
155
+
156
+ /** @type {import('tailwindcss').Config} */
157
+ module.exports = { darkMode: 'class', theme: { extend } };
158
+ `,
159
+ });
160
+ }
161
+ return files;
135
162
  }
@@ -95,12 +95,13 @@ function componentsCss(ctx) {
95
95
  ...COMPONENT_NAMES.filter((n) => n !== 'input').map((n) => ` --radius-${n}: var(--${n}-radius);`),
96
96
  ...Object.entries(colors).map(([key, css]) => ` --color-${key}: ${css};`),
97
97
  ];
98
- const utilities = COMPONENT_NAMES.map((n) => COMPONENTS[n].prefix).map(
99
- (p) => `@utility type-${p} {
98
+ // A label's weight and case are the component's (Button, Chip, Badge); a font-* or case class still wins.
99
+ const utilities = COMPONENT_NAMES.map((n) => [n, COMPONENTS[n].prefix]).map(
100
+ ([n, p]) => `@utility type-${p} {
100
101
  font-family: var(--${p}-text-font);
101
102
  font-size: var(--${p}-text-size);
102
103
  line-height: var(--tw-leading, var(--${p}-text-leading));
103
- letter-spacing: var(--tw-tracking, var(--${p}-text-tracking));
104
+ letter-spacing: var(--tw-tracking, var(--${p}-text-tracking));${COMPONENTS[n].props.includes('weight') ? `\n font-weight: var(--tw-font-weight, var(--${p}-text-weight));` : ''}${COMPONENTS[n].props.includes('case') ? `\n text-transform: var(--${p}-text-case);` : ''}
104
105
  }`
105
106
  );
106
107
  return {
@@ -23,16 +23,26 @@ const round = (n) => Number(n.toFixed(4));
23
23
  function componentsObject(components) {
24
24
  return COMPONENT_NAMES.map((name) => {
25
25
  const c = components[name];
26
- const text = { font: c.text.font, size: round(c.text.size), lineHeight: round(c.text.leading), tracking: c.text.tracking };
27
- // The font role is typed as a role, so code can branch on it (the object is `as const`).
28
- const json = JSON.stringify({ height: c.h, x: c.x, radius: c.radius, text }).replace(/"font":("\w+")/, `"font":$1 as 'heading' | 'body' | 'mono'`);
26
+ const text = { font: c.text.font, size: round(c.text.size), lineHeight: round(c.text.leading), tracking: c.text.tracking, weight: c.text.weight ?? (name === 'input' ? 400 : 500), case: c.text.case ?? 'none' };
27
+ // The icon size and the shadow ('none', '1'…'3'): native picks them in JS.
28
+ const own = { ...(c.gap ? { gap: c.gap } : {}), ...('icon' in c ? { icon: c.icon } : {}), ...('shadow' in c ? { shadow: c.shadow } : {}) };
29
+ // The font role is typed as a role, so code can branch on it (the object is `as const`), and tracking as a
30
+ // number: a kit compares it with 0, which wouldn't typecheck against a system's literal 0.01.
31
+ const json = JSON.stringify({ height: c.h, x: c.x, radius: c.radius, text, ...own })
32
+ .replace(/"font":("\w+")/, `"font":$1 as 'heading' | 'body' | 'mono'`)
33
+ .replace(/"tracking":(-?[\d.e-]+)/, '"tracking":$1 as number')
34
+ .replace(/"weight":(\d+)/, '"weight":$1 as number')
35
+ .replace(/"case":("\w+")/, `"case":$1 as 'none' | 'uppercase'`)
36
+ .replace(/"icon":([\d.]+)/, '"icon":$1 as number')
37
+ .replace(/"shadow":("\w+")/, `"shadow":$1 as 'none' | '1' | '2' | '3'`);
29
38
  return ` ${name}: ${json},`;
30
39
  }).join('\n');
31
40
  }
32
41
 
33
42
  function textStylesObject(styles) {
34
43
  return Object.entries(styles)
35
- .map(([name, s]) => ` ${name}: ${JSON.stringify({ font: s.font, weight: s.weight, size: round(s.size), lineHeight: round(s.lineHeight), tracking: s.tracking })},`)
44
+ // Tracking as a number, as the components' (a kit compares it with 0).
45
+ .map(([name, s]) => ` ${name}: ${JSON.stringify({ font: s.font, weight: s.weight, size: round(s.size), lineHeight: round(s.lineHeight), tracking: s.tracking }).replace(/"tracking":(-?[\d.e-]+)/, '"tracking":$1 as number')},`)
36
46
  .join('\n');
37
47
  }
38
48
 
@@ -91,6 +101,9 @@ ${primitiveGroup(ctx.prim, ['radius'])}
91
101
  },
92
102
  /** Lucide stroke width for icons (the Icon component's default; an explicit strokeWidth is relative to 2). */
93
103
  iconStroke: ${ctx.shape.stroke},
104
+ /** The Foundations shadows as CSS, per mode (shadow-sm / md / lg): native draws a component's shadow with them
105
+ * (React Native's boxShadow), so a see-through field shows one too. */
106
+ shadows: ${JSON.stringify(ctx.shape.shadows)},
94
107
  /** Width of \`border\` in px. */
95
108
  borderWidth: ${ctx.shape.borderWidth},
96
109
  /** The theme's styles (button: solid · soft · outline · raised; field: outline · filled · underline) and their
@@ -98,9 +111,10 @@ ${primitiveGroup(ctx.prim, ['radius'])}
98
111
  styles: ${JSON.stringify(ctx.styles)},
99
112
  button: ${JSON.stringify(ctx.shape.button)},
100
113
  field: ${JSON.stringify(ctx.shape.field)},
101
- /** The component layer (Button, Chip, Badge, Input) as numbers: heights and padding (px), corner, and the text's
102
- * font role and tracking. The classes (h-button-md, rounded-button, text-type-button…) already follow them; this is
103
- * for the touch-target floor (phones raise a height under ${TOUCH_TARGET} with hitSlop) and the font. */
114
+ /** The component layer (Button, Chip, Badge, Input) as numbers: heights, padding and gaps (px), corner, the text's
115
+ * font role, tracking, weight and case, the icon size and shadow level. The classes (h-button-md,
116
+ * rounded-button, text-type-button…) already follow the sizes; this is for the touch-target floor (phones raise a
117
+ * height under ${TOUCH_TARGET} with hitSlop) and what native picks in JS: the font, weight, case, icon and shadow. */
104
118
  components: {
105
119
  ${componentsObject(ctx.components)}
106
120
  },