@hex-core/tokens 1.3.8 → 1.5.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 CHANGED
@@ -21,6 +21,15 @@ Or, more commonly, copy the CSS block from the [Theming guide](https://hex-core.
21
21
  - Radii (`--radius-sm/md/lg`)
22
22
  - Shadows (`--shadow-glow`)
23
23
  - Container widths
24
+ - React Native output: `generateGlobalsCssNative(theme)` and `themeToNativeTheme(theme)`
25
+
26
+ ## React Native
27
+
28
+ `generateGlobalsCssNative(theme)` emits the NativeWind stylesheet (`@tailwind` directives plus a `:root` / `.dark:root` pair), and `themeToNativeTheme(theme)` returns the resolved light and dark palettes.
29
+
30
+ Both resolve palette references to literal `H S% L%` triplets rather than emitting `var()` chains. React Native has no cascade for a `var()` to resolve through, so a stylesheet carrying them yields no colour at all — silently, which is worse than failing. `hex doctor` fails a native project whose `global.css` contains one.
31
+
32
+ NativeWind 4 is built on Tailwind **3.4.x**, so the emitted config is the v3 shape.
24
33
 
25
34
  ## CSS variable namespaces
26
35
 
package/dist/index.d.ts CHANGED
@@ -99,8 +99,29 @@ interface GenerateGlobalsCssOptions {
99
99
  * that maps the raw `--<key>` CSS variables to color/radius utilities.
100
100
  * - `"v4"`: emits `@import "tailwindcss"` + `@theme { --color-<key>: hsl(...) }` so
101
101
  * utilities like `bg-background` resolve directly. No `tailwind.config.ts` needed.
102
+ * - `"native"`: the NativeWind shape — `@tailwind` directives plus `:root` /
103
+ * `.dark:root` blocks with every palette reference resolved to its literal
104
+ * triplet, and no `*` / `body` rules (React Native has neither). Pair with
105
+ * `themeToTailwindConfig()` in a Tailwind v3 `tailwind.config.js` using the
106
+ * NativeWind preset. See {@link generateGlobalsCssNative}.
102
107
  */
103
- target?: "v3" | "v4";
108
+ target?: "v3" | "v4" | "native";
109
+ /**
110
+ * Explicit content globs for Tailwind v4 to scan, relative to the CSS file.
111
+ *
112
+ * When set, the import becomes `@import "tailwindcss" source(none)` followed
113
+ * by one `@source` rule per glob — automatic detection is turned off.
114
+ *
115
+ * Pass this for an app generated *inside* an existing repository. Tailwind's
116
+ * automatic scan walks up past the app to the enclosing git root and reads
117
+ * whatever it finds — including binary files, whose bytes become class
118
+ * candidates and emit unparseable utilities. Scoping the scan to the app's
119
+ * own directories is the fix. Omit it for an app at the root of its own
120
+ * repository, where automatic detection is correct.
121
+ *
122
+ * Ignored when `target` is `"v3"`, which has no `@source` rule.
123
+ */
124
+ sources?: readonly string[];
104
125
  }
105
126
  /**
106
127
  * Generates a complete globals.css content with theme tokens and Tailwind directives.
@@ -110,6 +131,68 @@ interface GenerateGlobalsCssOptions {
110
131
  * @returns A full globals.css string ready to drop into `app/globals.css`.
111
132
  */
112
133
  declare function generateGlobalsCss(theme: Theme, options?: GenerateGlobalsCssOptions): string;
134
+ /**
135
+ * A theme flattened for React Native: one resolved-literal map per colour
136
+ * mode, keyed by CSS custom-property name.
137
+ *
138
+ * This is the shape NativeWind's runtime `vars()` helper takes, so a
139
+ * consumer can switch themes without regenerating `global.css`:
140
+ *
141
+ * ```tsx
142
+ * import { vars } from "nativewind";
143
+ * const { light, dark } = themeToNativeTheme(theme);
144
+ * <View style={vars(scheme === "dark" ? dark : light)}>…</View>
145
+ * ```
146
+ */
147
+ interface NativeTheme {
148
+ /** Light-mode tokens, e.g. `{ "--background": "0 0% 100%" }`. */
149
+ light: Record<string, string>;
150
+ /** Dark-mode tokens in the same shape. */
151
+ dark: Record<string, string>;
152
+ }
153
+ /**
154
+ * Transform a theme into the two flat token maps a React Native app needs.
155
+ *
156
+ * Same values as {@link themeToFlatJson} for each mode, returned together
157
+ * because a native theme provider always holds both and flips between them
158
+ * on `useColorScheme()`.
159
+ * @param theme - The theme to flatten
160
+ * @returns Light and dark maps keyed by `--<token>`
161
+ */
162
+ declare function themeToNativeTheme(theme: Theme): NativeTheme;
163
+ /**
164
+ * Generate the `global.css` a NativeWind (v4 line, Tailwind v3) project imports.
165
+ *
166
+ * Differences from the web v3 output, each forced by the renderer:
167
+ *
168
+ * - Palette references are resolved to literal `H S% L%` triplets and the
169
+ * ramp tier is omitted. NativeWind supports CSS variables but the
170
+ * `var(--slate-900)` indirection is not worth the runtime cost on a
171
+ * platform with no cascade to exploit.
172
+ * - Dark mode is `.dark:root`, the selector NativeWind's `darkMode: "class"`
173
+ * toggles through `colorScheme.set()`.
174
+ * - No `* { border-color }` or `body { … }` rules: React Native has no
175
+ * universal selector and no body. Components read `border-border` and
176
+ * `bg-background` themselves.
177
+ * @param theme - The theme to emit
178
+ * @returns The full `global.css` contents
179
+ */
180
+ declare function generateGlobalsCssNative(theme: Theme): string;
181
+ /**
182
+ * Emit only the token layer — the raw ramp, the semantic tokens, and the
183
+ * Tailwind `--color-*` bridge.
184
+ *
185
+ * Split out of {@link generateGlobalsCss} so a consumer that already owns
186
+ * its `@import`s, custom variants and non-colour `@theme` block can
187
+ * generate just the colours. The docs site does exactly that: its
188
+ * `globals.css` used to hand-copy this output four times over and carried
189
+ * a "KEEP IN SYNC" comment to prove it.
190
+ *
191
+ * @param theme - The theme to emit
192
+ * @returns The `:root` / `.dark` / `@theme inline` blocks, plus the base
193
+ * `body` and border rules
194
+ */
195
+ declare function generateThemeCssV4(theme: Theme): string;
113
196
 
114
197
  declare const defaultTheme: Theme;
115
198
 
@@ -419,4 +502,4 @@ declare function listThemes(): Array<{
419
502
  description: string;
420
503
  }>;
421
504
 
422
- export { COLOR_MODE_BANDS, type ColorMode, type DeriveDarkOptions, type DeriveForegroundOptions, type DeriveSecondaryOptions, RADIUS_PRESETS, type RadiusPreset, type ScopedRuntimeCssOptions, type TokenSetSeeds, buildTokenSet, colorInputToTokenValue, contrastRatio, defaultSemanticTokens, defaultTheme, deriveDarkFromLight, deriveForegroundFor, deriveSecondaryFromPrimary, emberTheme, generateGlobalsCss, getTheme, listThemes, midnightTheme, resolveSemanticToken, sharedTokens, themeToCss, themeToFlatJson, themeToScopedRuntimeCss, themeToTailwindConfig, themes, tokenLuminance };
505
+ export { COLOR_MODE_BANDS, type ColorMode, type DeriveDarkOptions, type DeriveForegroundOptions, type DeriveSecondaryOptions, type NativeTheme, RADIUS_PRESETS, type RadiusPreset, type ScopedRuntimeCssOptions, type TokenSetSeeds, buildTokenSet, colorInputToTokenValue, contrastRatio, defaultSemanticTokens, defaultTheme, deriveDarkFromLight, deriveForegroundFor, deriveSecondaryFromPrimary, emberTheme, generateGlobalsCss, generateGlobalsCssNative, generateThemeCssV4, getTheme, listThemes, midnightTheme, resolveSemanticToken, sharedTokens, themeToCss, themeToFlatJson, themeToNativeTheme, themeToScopedRuntimeCss, themeToTailwindConfig, themes, tokenLuminance };