rnwind 0.0.2 → 0.0.4

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.
Files changed (87) hide show
  1. package/lib/cjs/core/parser/color.cjs +53 -24
  2. package/lib/cjs/core/parser/color.cjs.map +1 -1
  3. package/lib/cjs/core/parser/layout-dispatcher.cjs +20 -0
  4. package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -1
  5. package/lib/cjs/core/parser/length.cjs +20 -6
  6. package/lib/cjs/core/parser/length.cjs.map +1 -1
  7. package/lib/cjs/core/parser/length.d.ts +6 -3
  8. package/lib/cjs/core/parser/shorthand.cjs +37 -5
  9. package/lib/cjs/core/parser/shorthand.cjs.map +1 -1
  10. package/lib/cjs/core/parser/shorthand.d.ts +11 -5
  11. package/lib/cjs/core/parser/theme-vars.cjs +53 -0
  12. package/lib/cjs/core/parser/theme-vars.cjs.map +1 -1
  13. package/lib/cjs/core/parser/theme-vars.d.ts +21 -0
  14. package/lib/cjs/core/parser/tokens.cjs +183 -1
  15. package/lib/cjs/core/parser/tokens.cjs.map +1 -1
  16. package/lib/cjs/core/parser/tw-parser.cjs +140 -27
  17. package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
  18. package/lib/cjs/core/parser/tw-parser.d.ts +21 -5
  19. package/lib/cjs/core/parser/typography-dispatcher.cjs +16 -1
  20. package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -1
  21. package/lib/cjs/core/style-builder/build-style.cjs +73 -26
  22. package/lib/cjs/core/style-builder/build-style.cjs.map +1 -1
  23. package/lib/cjs/metro/css-imports.cjs +81 -0
  24. package/lib/cjs/metro/css-imports.cjs.map +1 -0
  25. package/lib/cjs/metro/css-imports.d.ts +8 -0
  26. package/lib/cjs/metro/state.cjs +60 -10
  27. package/lib/cjs/metro/state.cjs.map +1 -1
  28. package/lib/cjs/metro/state.d.ts +17 -1
  29. package/lib/cjs/metro/transform-ast.cjs +238 -21
  30. package/lib/cjs/metro/transform-ast.cjs.map +1 -1
  31. package/lib/cjs/metro/transform-ast.d.ts +15 -0
  32. package/lib/cjs/metro/transformer.cjs +29 -2
  33. package/lib/cjs/metro/transformer.cjs.map +1 -1
  34. package/lib/cjs/metro/with-config.cjs +1 -1
  35. package/lib/cjs/metro/with-config.cjs.map +1 -1
  36. package/lib/cjs/metro/with-config.d.ts +22 -0
  37. package/lib/esm/core/parser/color.mjs +53 -24
  38. package/lib/esm/core/parser/color.mjs.map +1 -1
  39. package/lib/esm/core/parser/layout-dispatcher.mjs +20 -0
  40. package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -1
  41. package/lib/esm/core/parser/length.d.ts +6 -3
  42. package/lib/esm/core/parser/length.mjs +20 -6
  43. package/lib/esm/core/parser/length.mjs.map +1 -1
  44. package/lib/esm/core/parser/shorthand.d.ts +11 -5
  45. package/lib/esm/core/parser/shorthand.mjs +37 -5
  46. package/lib/esm/core/parser/shorthand.mjs.map +1 -1
  47. package/lib/esm/core/parser/theme-vars.d.ts +21 -0
  48. package/lib/esm/core/parser/theme-vars.mjs +53 -1
  49. package/lib/esm/core/parser/theme-vars.mjs.map +1 -1
  50. package/lib/esm/core/parser/tokens.mjs +183 -1
  51. package/lib/esm/core/parser/tokens.mjs.map +1 -1
  52. package/lib/esm/core/parser/tw-parser.d.ts +21 -5
  53. package/lib/esm/core/parser/tw-parser.mjs +141 -28
  54. package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
  55. package/lib/esm/core/parser/typography-dispatcher.mjs +16 -1
  56. package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -1
  57. package/lib/esm/core/style-builder/build-style.mjs +73 -26
  58. package/lib/esm/core/style-builder/build-style.mjs.map +1 -1
  59. package/lib/esm/metro/css-imports.d.ts +8 -0
  60. package/lib/esm/metro/css-imports.mjs +79 -0
  61. package/lib/esm/metro/css-imports.mjs.map +1 -0
  62. package/lib/esm/metro/state.d.ts +17 -1
  63. package/lib/esm/metro/state.mjs +60 -12
  64. package/lib/esm/metro/state.mjs.map +1 -1
  65. package/lib/esm/metro/transform-ast.d.ts +15 -0
  66. package/lib/esm/metro/transform-ast.mjs +238 -21
  67. package/lib/esm/metro/transform-ast.mjs.map +1 -1
  68. package/lib/esm/metro/transformer.mjs +30 -3
  69. package/lib/esm/metro/transformer.mjs.map +1 -1
  70. package/lib/esm/metro/with-config.d.ts +22 -0
  71. package/lib/esm/metro/with-config.mjs +1 -1
  72. package/lib/esm/metro/with-config.mjs.map +1 -1
  73. package/package.json +2 -1
  74. package/src/core/parser/color.ts +52 -18
  75. package/src/core/parser/layout-dispatcher.ts +19 -0
  76. package/src/core/parser/length.ts +20 -6
  77. package/src/core/parser/shorthand.ts +35 -5
  78. package/src/core/parser/theme-vars.ts +53 -0
  79. package/src/core/parser/tokens.ts +171 -1
  80. package/src/core/parser/tw-parser.ts +147 -28
  81. package/src/core/parser/typography-dispatcher.ts +15 -1
  82. package/src/core/style-builder/build-style.ts +84 -26
  83. package/src/metro/css-imports.ts +75 -0
  84. package/src/metro/state.ts +58 -10
  85. package/src/metro/transform-ast.ts +249 -18
  86. package/src/metro/transformer.ts +28 -3
  87. package/src/metro/with-config.ts +23 -1
@@ -276,25 +276,75 @@ function renderManifest(variants, breakpoints) {
276
276
  return lines.join('\n');
277
277
  }
278
278
  /**
279
- * Serialize one atom's canonical + variant-diff entries, honouring
280
- * the per-atom cache. Returns the number of cache MISSES this atom
281
- * incurred (0 when canonical was cached AND every needed variant was
282
- * cached; 1 when anything had to be re-stringified). Split out of
283
- * `buildSchemeSources` to keep that function under the repo's cognitive
284
- * complexity budget.
279
+ * Pre-serialize every non-empty variant value, reusing the per-atom
280
+ * cache where present. Result drives both the scheme-uniform check
281
+ * AND the per-variant emission loop downstream.
282
+ * @param atom Atom name.
283
+ * @param schemed Parser-produced schemed bucket.
284
+ * @param variants Variant scheme names in deterministic order.
285
+ * @param keyframes Keyframes available to inline.
286
+ * @param cached Cached entry for this atom (when ref-stable).
287
+ * @returns variantName → serialized text.
288
+ */
289
+ function buildVariantTexts(atom, schemed, variants, keyframes, cached) {
290
+ const out = new Map();
291
+ for (const variant of variants) {
292
+ const own = schemed[variant];
293
+ if (!isNonEmptyStyle(own))
294
+ continue;
295
+ const text = cached?.variants.get(variant) ?? prepareAtomValue(atom, own, keyframes);
296
+ out.set(variant, text);
297
+ }
298
+ return out;
299
+ }
300
+ /**
301
+ * Decide whether a (no-base) atom should be promoted to common because
302
+ * every declared variant resolves to the same value. This is the
303
+ * scheme-uniform case: `flex`, `p-4`, `absolute` all carry no theme
304
+ * variables, so Phase-1 fills every variant bucket identically and
305
+ * leaves `base` empty — without this collapse they'd be duplicated
306
+ * across every scheme file.
285
307
  *
286
- * Two paths gated on whether the parser produced a non-empty `base`
287
- * bucket:
308
+ * The variant-prefix check is what keeps a real scheme-gated atom
309
+ * (`dark:bg-indigo-800`) out of common in a single-variant project
310
+ * (where its 1 bucket would otherwise look "uniform" by definition).
311
+ * @param atom Atom name (checked for `<variant>:` prefix).
312
+ * @param variants Declared variant scheme names.
313
+ * @param variantTexts Serialized variant values.
314
+ * @param canonicalText Serialized canonical (common) value.
315
+ * @returns Whether the atom is uniform across every declared variant.
316
+ */
317
+ function isSchemeUniform(atom, variants, variantTexts, canonicalText) {
318
+ if (variants.length === 0 || variantTexts.size !== variants.length)
319
+ return false;
320
+ if (variants.some((variant) => atom.startsWith(`${variant}:`)))
321
+ return false;
322
+ for (const text of variantTexts.values()) {
323
+ if (text !== canonicalText)
324
+ return false;
325
+ }
326
+ return true;
327
+ }
328
+ /**
329
+ * Serialize one atom's canonical + variant-diff entries, honouring the
330
+ * per-atom cache. Returns the number of cache MISSES this atom incurred
331
+ * (0 when canonical was cached AND every needed variant was cached;
332
+ * 1 when anything had to be re-stringified).
333
+ *
334
+ * Three paths gated on whether the parser produced a non-empty `base`
335
+ * bucket and whether the variants converge:
288
336
  * - **Themed atom (base present)**: canonical goes to `common`, each
289
337
  * variant whose own value diverges from canonical writes the diff
290
- * into its own scheme file. `lookupAtom` then finds the variant's
338
+ * into its own scheme file. `lookupAtom` finds the variant's
291
339
  * override or falls through to common.
292
- * - **Scheme-gated atom (base empty)**: the atom only matches when a
293
- * specific scheme is active (Tailwind `light:` / `dark:` / `brand:`
294
- * selectors). Skipping `common` here is essential registering it
295
- * would let the lookup fall through under non-matching schemes and
296
- * leak the variant style into every scheme. Each populated variant
297
- * bucket writes the value into its own scheme file directly.
340
+ * - **Scheme-uniform atom (base empty, every variant identical)**:
341
+ * promoted to `common` once the parser's Phase-1 fills every
342
+ * variant bucket with the same value for utilities like `flex` /
343
+ * `p-4` / `absolute` that don't reference theme variables.
344
+ * - **Scheme-gated atom (base empty, prefixed name like `dark:foo`,
345
+ * or variants diverge)**: each populated variant writes the value
346
+ * into its own scheme file directly; common stays empty so the
347
+ * runtime fallback can't leak the variant style into other schemes.
298
348
  * @param atom Atom name.
299
349
  * @param schemed Parser-produced schemed bucket for the atom.
300
350
  * @param canonical Canonical RN style for `common`.
@@ -309,25 +359,22 @@ function collectAtomEntries(atom, schemed, canonical, variants, keyframes, commo
309
359
  const cached = cache?.get(atom);
310
360
  const hit = cached?.styleRef === schemed;
311
361
  const baseEntry = schemed[BASE_SCHEME];
312
- const isSchemeGated = !isNonEmptyStyle(baseEntry);
362
+ const hasBase = isNonEmptyStyle(baseEntry);
313
363
  const canonicalText = hit ? cached.canonical : prepareAtomValue(atom, canonical, keyframes);
314
- if (!isSchemeGated)
364
+ const variantTexts = buildVariantTexts(atom, schemed, variants, keyframes, hit ? cached : undefined);
365
+ const goesToCommon = hasBase || isSchemeUniform(atom, variants, variantTexts, canonicalText);
366
+ if (goesToCommon)
315
367
  commonEntries.push([atom, canonicalText]);
316
368
  const entry = hit
317
369
  ? cached
318
- : { styleRef: schemed, canonical: canonicalText, variants: new Map() };
370
+ : { styleRef: schemed, canonical: canonicalText, variants: new Map(variantTexts) };
319
371
  if (!hit)
320
372
  cache?.set(atom, entry);
321
373
  for (const variant of variants) {
322
- const own = schemed[variant];
323
- if (!isNonEmptyStyle(own))
374
+ const ownText = variantTexts.get(variant);
375
+ if (ownText === undefined)
324
376
  continue;
325
- let ownText = entry.variants.get(variant);
326
- if (ownText === undefined) {
327
- ownText = prepareAtomValue(atom, own, keyframes);
328
- entry.variants.set(variant, ownText);
329
- }
330
- if (!isSchemeGated && ownText === canonicalText)
377
+ if (goesToCommon && ownText === canonicalText)
331
378
  continue;
332
379
  variantEntries[variant].push([atom, ownText]);
333
380
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build-style.mjs","sources":["../../../../../src/core/style-builder/build-style.ts"],"sourcesContent":["import type { KeyframeBlock, RNStyle, SchemedStyle } from '../parser'\n\n/** Match atom names like `border-hairline`, `h-hairline`, `border-t-hairline`, etc. */\nconst HAIRLINE_ATOM = /-hairline$/\n\n/** Parser's synthetic \"no variant\" scheme — provides the canonical fallback. */\nconst BASE_SCHEME = 'base'\n\n/** Runtime registry key for the always-loaded fallback scheme. */\nconst COMMON_SCHEME = 'common'\n\n/** Sentinel key the parser sets on interactive (`active:`/`focus:`) atoms. */\nconst STATE_KEY = '__state'\n\n/**\n * Whether an atom is a `*-hairline` utility — its numeric value must be\n * rewritten as `StyleSheet.hairlineWidth` at runtime.\n * @param atomName Class name.\n * @returns True when the atom is a hairline utility.\n */\nfunction isHairlineAtom(atomName: string): boolean {\n return HAIRLINE_ATOM.test(atomName)\n}\n\n/**\n * Whether an RN style object carries any own key. The parser emits\n * empty `{}` for schemes an atom doesn't apply to; we treat those as\n * \"inherit canonical\" and don't emit an entry for that scheme.\n * @param style RN style object.\n * @returns Whether the style has content.\n */\nfunction isNonEmptyStyle(style: RNStyle | undefined): style is RNStyle {\n if (!style) return false\n return Object.keys(style).length > 0\n}\n\n/**\n * Iterate per-scheme entries from a parser-produced schemed bucket,\n * skipping the reserved `__state` metadata key.\n * @param schemed Parser output for one atom.\n * @yields `[scheme, style]` pairs in object-key order.\n */\nfunction* iterScheme(schemed: SchemedStyle): IterableIterator<[string, RNStyle]> {\n const raw = schemed as Readonly<Record<string, RNStyle | string>>\n for (const key in raw) {\n if (key === STATE_KEY) continue\n yield [key, raw[key] as RNStyle]\n }\n}\n\n/**\n * Pick the canonical style for an atom — the value that goes into\n * `common.style.js`. Prefers the parser's `base` entry (the \"default\n * when no variant matches\"); falls back to the first non-empty per-\n * scheme entry when the atom has no explicit base.\n * @param schemed Parser-produced per-scheme bucket.\n * @returns Canonical style, or undefined when every scheme is empty.\n */\nfunction canonicalValue(schemed: SchemedStyle): RNStyle | undefined {\n const baseEntry = (schemed as Readonly<Record<string, RNStyle>>)[BASE_SCHEME]\n if (isNonEmptyStyle(baseEntry)) return baseEntry\n for (const [, style] of iterScheme(schemed)) {\n if (isNonEmptyStyle(style)) return style\n }\n return undefined\n}\n\n/**\n * Collect every variant scheme name across the project's atoms. The\n * synthetic `base` scheme is excluded — it's folded into the `common`\n * output. Returns variants in sorted order for deterministic output.\n * @param resolved Parser-produced atom map.\n * @returns Variant scheme names (no `base`, no `common`).\n */\nfunction collectVariantSchemes(resolved: ReadonlyMap<string, SchemedStyle>): readonly string[] {\n const set = new Set<string>()\n for (const schemed of resolved.values()) {\n for (const [scheme] of iterScheme(schemed)) {\n if (scheme !== BASE_SCHEME) set.add(scheme)\n }\n }\n return [...set].toSorted((a, b) => a.localeCompare(b))\n}\n\n/**\n * Normalize a CSS keyframe selector to the percentage form Reanimated\n * v4 keyframes objects use.\n * @param offset Selector text (`'from'`, `'to'`, `'50%'`).\n * @returns Percentage string.\n */\nfunction offsetToPercent(offset: string): string {\n if (offset === 'from') return '0%'\n if (offset === 'to') return '100%'\n return offset\n}\n\n/**\n * Replace a string `animationName` with the inline keyframes object\n * Reanimated v4's CSS engine expects. Atoms whose `animationName`\n * doesn't match any registered keyframe keep the original string.\n * @param style RN style object (possibly carrying `animationName`).\n * @param keyframes Keyframes available to this build.\n * @returns Style with `animationName` inlined when matched.\n */\nfunction inlineAnimationName(style: RNStyle, keyframes: ReadonlyMap<string, KeyframeBlock>): RNStyle {\n const name = style.animationName\n if (typeof name !== 'string') return style\n const block = keyframes.get(name)\n if (!block) return style\n const out: RNStyle = { ...style }\n const inline: Record<string, Record<string, string | number>> = {}\n for (const step of block.steps) inline[offsetToPercent(step.offset)] = step.style as Record<string, string | number>\n out.animationName = inline as unknown as RNStyle[string]\n return out\n}\n\n/**\n * Convert any safe-area markers in the style into a precomputed spec\n * envelope. Atoms with `__safe` markers become\n * `{__safeStyle: [[cssKey, sideTag, or, offset], ...]}` — the runtime\n * resolver reads `value.__safeStyle` as a single property access and\n * resolves against live insets without walking the value's keys.\n * @param style RN style as resolved by the parser.\n * @returns Original style OR the safe-style envelope.\n */\nfunction envelopeSafeMarkers(\n style: RNStyle,\n): RNStyle | { __safeStyle: readonly (readonly [string, string, number | undefined, number | undefined])[] } {\n let specs: [string, string, number | undefined, number | undefined][] | null = null\n for (const key of Object.keys(style)) {\n const value = style[key]\n if (typeof value !== 'object' || !value) continue\n const marker = value as { __safe?: string; or?: number; offset?: number }\n if (typeof marker.__safe !== 'string') continue\n if (!specs) specs = []\n specs.push([key, marker.__safe, marker.or, marker.offset])\n }\n if (!specs) return style\n return { __safeStyle: specs }\n}\n\n/**\n * Serialise a single atom's RN style to a JS object literal. Honors\n * the `*-hairline` sentinel: numeric values get rewritten to\n * `StyleSheet.hairlineWidth` so device-density differences land in the\n * rendered border.\n * @param atomName The atom's class name (used to detect hairline).\n * @param style The atom's RN style object.\n * @returns JS object-literal source.\n */\nfunction serializeStyle(atomName: string, style: RNStyle): string {\n const json = JSON.stringify(style)\n if (!isHairlineAtom(atomName)) return json\n return json.replaceAll(/:(-?\\d+(?:\\.\\d+)?)/g, ': StyleSheet.hairlineWidth')\n}\n\n/**\n * Serialise an atom's resolved value — bare RN style object or an\n * already-enveloped safe-style value.\n * @param atomName Atom name (controls hairline rewrite).\n * @param value Atom value (bare style or `{__safeStyle: spec[]}`).\n * @returns JS source for the value.\n */\nfunction serializeAtomValue(atomName: string, value: unknown): string {\n if (typeof value === 'object' && value !== null && '__safeStyle' in value) return JSON.stringify(value)\n return serializeStyle(atomName, value as RNStyle)\n}\n\n/**\n * Resolve + envelope + serialize an atom's value under one scheme.\n * @param atomName Atom name.\n * @param style Raw RN style for this scheme.\n * @param keyframes Keyframes available to this build.\n * @returns Serialized text ready to emit.\n */\nfunction prepareAtomValue(atomName: string, style: RNStyle, keyframes: ReadonlyMap<string, KeyframeBlock>): string {\n const enveloped = envelopeSafeMarkers(inlineAnimationName(style, keyframes))\n return serializeAtomValue(atomName, enveloped)\n}\n\n/**\n * Per-file value deduplicator — interns each unique serialized atom\n * value once and emits `const _s<N> = <value>` at module scope. Scheme\n * entries reference the const instead of inlining the literal.\n *\n * Wins: (1) smaller bundle bytes for themes with many atoms sharing a\n * style shape; (2) stable `===` inside one scheme so two atoms\n * resolving to the same value yield the same object reference.\n */\nclass ValueDeduper {\n private readonly byText = new Map<string, string>()\n private readonly decls: string[] = []\n\n intern(serialized: string): string {\n const existing = this.byText.get(serialized)\n if (existing) return existing\n const name = `_s${this.decls.length}`\n this.decls.push(`const ${name} = ${serialized}`)\n this.byText.set(serialized, name)\n return name\n }\n\n get declarations(): readonly string[] {\n return this.decls\n }\n}\n\n/**\n * Render one scheme file's source. `entries` is the list of atoms this\n * scheme contributes — for `common` every atom's canonical value; for\n * a variant only atoms whose value differs from canonical. Hairline\n * atoms in this file trigger the `StyleSheet` import.\n * @param schemeName Registry key (`'common'` or the variant name).\n * @param entries `[atomName, serializedValue]` pairs to emit.\n * @returns JS source text.\n */\nfunction renderSchemeFile(schemeName: string, entries: readonly (readonly [string, string])[]): string {\n const needsStyleSheet = entries.some(([atom]) => isHairlineAtom(atom))\n const deduper = new ValueDeduper()\n const recordLines: string[] = []\n for (const [atom, value] of entries) {\n const ref = deduper.intern(value)\n recordLines.push(` ${JSON.stringify(atom)}: ${ref},`)\n }\n\n const lines: string[] = []\n if (needsStyleSheet) lines.push(`import { StyleSheet } from 'react-native'`)\n lines.push(`import { registerAtoms } from 'rnwind'`, ``)\n if (deduper.declarations.length > 0) {\n for (const decl of deduper.declarations) lines.push(decl)\n lines.push(``)\n }\n lines.push(`registerAtoms(${JSON.stringify(schemeName)}, {`, ...recordLines, `})`, ``)\n return lines.join('\\n')\n}\n\n/**\n * Render the JS-object literal for the responsive-breakpoint table the\n * runtime registers at manifest-load time. Sorted by ascending px\n * threshold so the runtime can build a deterministic \"tier index\" for\n * its style cache.\n * @param breakpoints Breakpoint name → px-threshold map.\n * @returns Object-literal source (`{}` when empty).\n */\nfunction serializeBreakpoints(breakpoints: ReadonlyMap<string, number>): string {\n if (breakpoints.size === 0) return '{}'\n const entries = [...breakpoints].toSorted((a, b) => a[1] - b[1] || a[0].localeCompare(b[0]))\n const inner = entries.map(([name, px]) => `${JSON.stringify(name)}: ${px}`).join(', ')\n return `{ ${inner} }`\n}\n\n/**\n * Render the manifest module. Eager-imports `common.style.js` (every\n * rewritten source file pulls this via a transitive side-effect\n * import), registers the responsive-breakpoint table once, and lazy-\n * requires every variant scheme's file through an inline require —\n * first call in `ensureSchemeLoaded(name)` triggers the scheme\n * module's evaluation; Metro's module cache makes subsequent calls\n * no-ops.\n * @param variants Variant scheme names (no `base`, no `common`).\n * @param breakpoints Responsive breakpoint name → px-threshold map.\n * @returns JS source text.\n */\nfunction renderManifest(variants: readonly string[], breakpoints: ReadonlyMap<string, number>): string {\n const lines: string[] = [\n `import { registerSchemeLoader, registerBreakpoints } from 'rnwind'`,\n `import './common.style'`,\n ``,\n `registerBreakpoints(${serializeBreakpoints(breakpoints)})`,\n ``,\n ]\n if (variants.length === 0) {\n lines.push(`function ensureSchemeLoaded(_name) {}`, ``, `registerSchemeLoader(ensureSchemeLoaded)`, ``, `export { ensureSchemeLoaded }`, ``)\n return lines.join('\\n')\n }\n lines.push(`const LOADERS = {`)\n for (const variant of variants) {\n lines.push(` ${JSON.stringify(variant)}: () => require(${JSON.stringify(`./${variant}.style`)}),`)\n }\n lines.push(`}`, ``, `function ensureSchemeLoaded(name) {`, ` const loader = LOADERS[name]`, ` if (loader) loader()`, `}`, ``, `registerSchemeLoader(ensureSchemeLoaded)`, ``, `export { ensureSchemeLoaded }`, ``)\n return lines.join('\\n')\n}\n\n/** Output of one build pass — one source per scheme plus the manifest. */\nexport interface BuildSchemeSourcesOutput {\n /** `<schemeName>.style.js` source per scheme. Always contains `common`. */\n readonly schemeSources: Readonly<Record<string, string>>\n /** Manifest module source (`schemes.js`). */\n readonly manifestSource: string\n /** Variant scheme names this build covers (sorted; excludes `common`). */\n readonly variants: readonly string[]\n /** Number of `prepareAtomValue` / JSON.stringify passes (cache MISSES) this call did — test telemetry. */\n readonly serializedMisses: number\n}\n\n/**\n * Per-atom cached serialized value. Canonical (common) string plus a\n * map of variant → own-serialized-string. `styleRef` is an identity\n * guard against the resolved SchemedStyle — when callers replace an\n * atom's value the ref diverges and the cache rebuilds that entry.\n */\nexport interface AtomSerializedEntry {\n styleRef: SchemedStyle\n canonical: string\n variants: Map<string, string>\n}\n\n/** Cache UnionBuilder owns across repeated writeSchemes calls. */\nexport type AtomSerializedCache = Map<string, AtomSerializedEntry>\n\n/**\n * Serialize one atom's canonical + variant-diff entries, honouring\n * the per-atom cache. Returns the number of cache MISSES this atom\n * incurred (0 when canonical was cached AND every needed variant was\n * cached; 1 when anything had to be re-stringified). Split out of\n * `buildSchemeSources` to keep that function under the repo's cognitive\n * complexity budget.\n *\n * Two paths gated on whether the parser produced a non-empty `base`\n * bucket:\n * - **Themed atom (base present)**: canonical goes to `common`, each\n * variant whose own value diverges from canonical writes the diff\n * into its own scheme file. `lookupAtom` then finds the variant's\n * override or falls through to common.\n * - **Scheme-gated atom (base empty)**: the atom only matches when a\n * specific scheme is active (Tailwind `light:` / `dark:` / `brand:`\n * selectors). Skipping `common` here is essential — registering it\n * would let the lookup fall through under non-matching schemes and\n * leak the variant style into every scheme. Each populated variant\n * bucket writes the value into its own scheme file directly.\n * @param atom Atom name.\n * @param schemed Parser-produced schemed bucket for the atom.\n * @param canonical Canonical RN style for `common`.\n * @param variants Variant scheme names in deterministic order.\n * @param keyframes Keyframes available to inline.\n * @param commonEntries Mutable collector for `common`'s `[atom, text]` pairs.\n * @param variantEntries Mutable collector keyed by variant name.\n * @param cache Optional shared serialized-value cache.\n * @returns Number of JSON.stringify passes triggered for this atom.\n */\nfunction collectAtomEntries(\n atom: string,\n schemed: SchemedStyle,\n canonical: RNStyle,\n variants: readonly string[],\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n commonEntries: (readonly [string, string])[],\n variantEntries: Record<string, (readonly [string, string])[]>,\n cache?: AtomSerializedCache,\n): number {\n const cached = cache?.get(atom)\n const hit = cached?.styleRef === schemed\n const baseEntry = (schemed as Readonly<Record<string, RNStyle>>)[BASE_SCHEME]\n const isSchemeGated = !isNonEmptyStyle(baseEntry)\n const canonicalText = hit ? cached.canonical : prepareAtomValue(atom, canonical, keyframes)\n if (!isSchemeGated) commonEntries.push([atom, canonicalText])\n const entry: AtomSerializedEntry = hit\n ? cached\n : { styleRef: schemed, canonical: canonicalText, variants: new Map<string, string>() }\n if (!hit) cache?.set(atom, entry)\n\n for (const variant of variants) {\n const own = (schemed as Readonly<Record<string, RNStyle>>)[variant]\n if (!isNonEmptyStyle(own)) continue\n let ownText = entry.variants.get(variant)\n if (ownText === undefined) {\n ownText = prepareAtomValue(atom, own, keyframes)\n entry.variants.set(variant, ownText)\n }\n if (!isSchemeGated && ownText === canonicalText) continue\n variantEntries[variant].push([atom, ownText])\n }\n return hit ? 0 : 1\n}\n\n/** Empty fallback when the caller didn't supply breakpoints (legacy callers, tests). */\nconst EMPTY_BREAKPOINTS: ReadonlyMap<string, number> = new Map()\n\n/**\n * Build the per-scheme style files + manifest source.\n *\n * Dedup rule (the thing that shrinks scheme files to their diff):\n * - Every atom's canonical value goes into `common.style.js`.\n * - Each variant's file emits an entry for an atom ONLY when the\n * variant's own resolved value differs from canonical. When the\n * variant inherits (parser emits an empty `{}` for that scheme) or\n * the variant's resolved value serializes identically to canonical,\n * the atom is omitted — at runtime the lookup falls through via\n * `cache.atoms[scheme]?.[atom] ?? cache.atoms.common[atom]`.\n *\n * Keyframes are inlined directly into atom values via `animationName`\n * ({@link inlineAnimationName}). Safe-area markers get pre-enveloped\n * via {@link envelopeSafeMarkers}. Hairline utilities stay bound to\n * `StyleSheet.hairlineWidth` at runtime.\n * @param atomNames All atom names (sorted).\n * @param resolved Per-atom schemed styles from the parser.\n * @param keyframes Keyframe blocks referenced by any atom.\n * @param cache Optional shared serialized-value cache.\n * @param breakpoints Responsive breakpoint name → px-threshold map. The\n * manifest emits `registerBreakpoints({...})` so the runtime can gate\n * `md:*` / `lg:*` atoms on `windowWidth`. Optional — empty when the\n * theme declares no breakpoints (legacy/test callers).\n * @returns Per-scheme sources, manifest source, variant list.\n */\nexport function buildSchemeSources(\n atomNames: readonly string[],\n resolved: ReadonlyMap<string, SchemedStyle>,\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n cache?: AtomSerializedCache,\n breakpoints: ReadonlyMap<string, number> = EMPTY_BREAKPOINTS,\n): BuildSchemeSourcesOutput {\n const variants = collectVariantSchemes(resolved)\n const commonEntries: (readonly [string, string])[] = []\n const variantEntries: Record<string, (readonly [string, string])[]> = {}\n for (const variant of variants) variantEntries[variant] = []\n let misses = 0\n\n for (const atom of atomNames) {\n const schemed = resolved.get(atom)\n if (!schemed) continue\n const canonical = canonicalValue(schemed)\n if (!canonical) continue\n misses += collectAtomEntries(atom, schemed, canonical, variants, keyframes, commonEntries, variantEntries, cache)\n }\n\n const schemeSources: Record<string, string> = {\n [COMMON_SCHEME]: renderSchemeFile(COMMON_SCHEME, commonEntries),\n }\n for (const variant of variants) {\n schemeSources[variant] = renderSchemeFile(variant, variantEntries[variant])\n }\n\n return {\n schemeSources,\n manifestSource: renderManifest(variants, breakpoints),\n variants,\n serializedMisses: misses,\n }\n}\n\n/** Registry key the runtime uses for the always-loaded fallback. */\nexport const COMMON_SCHEME_NAME: string = COMMON_SCHEME\n"],"names":[],"mappings":"AAEA;AACA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AC,GAAG,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7E;IAEA,OAAO;QACL,aAAa;AACb,QAAA,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC;QACrD,QAAQ;AACR,QAAA,gBAAgB,EAAE,MAAM;KACzB;AACH;;;;"}
1
+ {"version":3,"file":"build-style.mjs","sources":["../../../../../src/core/style-builder/build-style.ts"],"sourcesContent":["import type { KeyframeBlock, RNStyle, SchemedStyle } from '../parser'\n\n/** Match atom names like `border-hairline`, `h-hairline`, `border-t-hairline`, etc. */\nconst HAIRLINE_ATOM = /-hairline$/\n\n/** Parser's synthetic \"no variant\" scheme — provides the canonical fallback. */\nconst BASE_SCHEME = 'base'\n\n/** Runtime registry key for the always-loaded fallback scheme. */\nconst COMMON_SCHEME = 'common'\n\n/** Sentinel key the parser sets on interactive (`active:`/`focus:`) atoms. */\nconst STATE_KEY = '__state'\n\n/**\n * Whether an atom is a `*-hairline` utility — its numeric value must be\n * rewritten as `StyleSheet.hairlineWidth` at runtime.\n * @param atomName Class name.\n * @returns True when the atom is a hairline utility.\n */\nfunction isHairlineAtom(atomName: string): boolean {\n return HAIRLINE_ATOM.test(atomName)\n}\n\n/**\n * Whether an RN style object carries any own key. The parser emits\n * empty `{}` for schemes an atom doesn't apply to; we treat those as\n * \"inherit canonical\" and don't emit an entry for that scheme.\n * @param style RN style object.\n * @returns Whether the style has content.\n */\nfunction isNonEmptyStyle(style: RNStyle | undefined): style is RNStyle {\n if (!style) return false\n return Object.keys(style).length > 0\n}\n\n/**\n * Iterate per-scheme entries from a parser-produced schemed bucket,\n * skipping the reserved `__state` metadata key.\n * @param schemed Parser output for one atom.\n * @yields `[scheme, style]` pairs in object-key order.\n */\nfunction* iterScheme(schemed: SchemedStyle): IterableIterator<[string, RNStyle]> {\n const raw = schemed as Readonly<Record<string, RNStyle | string>>\n for (const key in raw) {\n if (key === STATE_KEY) continue\n yield [key, raw[key] as RNStyle]\n }\n}\n\n/**\n * Pick the canonical style for an atom — the value that goes into\n * `common.style.js`. Prefers the parser's `base` entry (the \"default\n * when no variant matches\"); falls back to the first non-empty per-\n * scheme entry when the atom has no explicit base.\n * @param schemed Parser-produced per-scheme bucket.\n * @returns Canonical style, or undefined when every scheme is empty.\n */\nfunction canonicalValue(schemed: SchemedStyle): RNStyle | undefined {\n const baseEntry = (schemed as Readonly<Record<string, RNStyle>>)[BASE_SCHEME]\n if (isNonEmptyStyle(baseEntry)) return baseEntry\n for (const [, style] of iterScheme(schemed)) {\n if (isNonEmptyStyle(style)) return style\n }\n return undefined\n}\n\n/**\n * Collect every variant scheme name across the project's atoms. The\n * synthetic `base` scheme is excluded — it's folded into the `common`\n * output. Returns variants in sorted order for deterministic output.\n * @param resolved Parser-produced atom map.\n * @returns Variant scheme names (no `base`, no `common`).\n */\nfunction collectVariantSchemes(resolved: ReadonlyMap<string, SchemedStyle>): readonly string[] {\n const set = new Set<string>()\n for (const schemed of resolved.values()) {\n for (const [scheme] of iterScheme(schemed)) {\n if (scheme !== BASE_SCHEME) set.add(scheme)\n }\n }\n return [...set].toSorted((a, b) => a.localeCompare(b))\n}\n\n/**\n * Normalize a CSS keyframe selector to the percentage form Reanimated\n * v4 keyframes objects use.\n * @param offset Selector text (`'from'`, `'to'`, `'50%'`).\n * @returns Percentage string.\n */\nfunction offsetToPercent(offset: string): string {\n if (offset === 'from') return '0%'\n if (offset === 'to') return '100%'\n return offset\n}\n\n/**\n * Replace a string `animationName` with the inline keyframes object\n * Reanimated v4's CSS engine expects. Atoms whose `animationName`\n * doesn't match any registered keyframe keep the original string.\n * @param style RN style object (possibly carrying `animationName`).\n * @param keyframes Keyframes available to this build.\n * @returns Style with `animationName` inlined when matched.\n */\nfunction inlineAnimationName(style: RNStyle, keyframes: ReadonlyMap<string, KeyframeBlock>): RNStyle {\n const name = style.animationName\n if (typeof name !== 'string') return style\n const block = keyframes.get(name)\n if (!block) return style\n const out: RNStyle = { ...style }\n const inline: Record<string, Record<string, string | number>> = {}\n for (const step of block.steps) inline[offsetToPercent(step.offset)] = step.style as Record<string, string | number>\n out.animationName = inline as unknown as RNStyle[string]\n return out\n}\n\n/**\n * Convert any safe-area markers in the style into a precomputed spec\n * envelope. Atoms with `__safe` markers become\n * `{__safeStyle: [[cssKey, sideTag, or, offset], ...]}` — the runtime\n * resolver reads `value.__safeStyle` as a single property access and\n * resolves against live insets without walking the value's keys.\n * @param style RN style as resolved by the parser.\n * @returns Original style OR the safe-style envelope.\n */\nfunction envelopeSafeMarkers(\n style: RNStyle,\n): RNStyle | { __safeStyle: readonly (readonly [string, string, number | undefined, number | undefined])[] } {\n let specs: [string, string, number | undefined, number | undefined][] | null = null\n for (const key of Object.keys(style)) {\n const value = style[key]\n if (typeof value !== 'object' || !value) continue\n const marker = value as { __safe?: string; or?: number; offset?: number }\n if (typeof marker.__safe !== 'string') continue\n if (!specs) specs = []\n specs.push([key, marker.__safe, marker.or, marker.offset])\n }\n if (!specs) return style\n return { __safeStyle: specs }\n}\n\n/**\n * Serialise a single atom's RN style to a JS object literal. Honors\n * the `*-hairline` sentinel: numeric values get rewritten to\n * `StyleSheet.hairlineWidth` so device-density differences land in the\n * rendered border.\n * @param atomName The atom's class name (used to detect hairline).\n * @param style The atom's RN style object.\n * @returns JS object-literal source.\n */\nfunction serializeStyle(atomName: string, style: RNStyle): string {\n const json = JSON.stringify(style)\n if (!isHairlineAtom(atomName)) return json\n return json.replaceAll(/:(-?\\d+(?:\\.\\d+)?)/g, ': StyleSheet.hairlineWidth')\n}\n\n/**\n * Serialise an atom's resolved value — bare RN style object or an\n * already-enveloped safe-style value.\n * @param atomName Atom name (controls hairline rewrite).\n * @param value Atom value (bare style or `{__safeStyle: spec[]}`).\n * @returns JS source for the value.\n */\nfunction serializeAtomValue(atomName: string, value: unknown): string {\n if (typeof value === 'object' && value !== null && '__safeStyle' in value) return JSON.stringify(value)\n return serializeStyle(atomName, value as RNStyle)\n}\n\n/**\n * Resolve + envelope + serialize an atom's value under one scheme.\n * @param atomName Atom name.\n * @param style Raw RN style for this scheme.\n * @param keyframes Keyframes available to this build.\n * @returns Serialized text ready to emit.\n */\nfunction prepareAtomValue(atomName: string, style: RNStyle, keyframes: ReadonlyMap<string, KeyframeBlock>): string {\n const enveloped = envelopeSafeMarkers(inlineAnimationName(style, keyframes))\n return serializeAtomValue(atomName, enveloped)\n}\n\n/**\n * Per-file value deduplicator — interns each unique serialized atom\n * value once and emits `const _s<N> = <value>` at module scope. Scheme\n * entries reference the const instead of inlining the literal.\n *\n * Wins: (1) smaller bundle bytes for themes with many atoms sharing a\n * style shape; (2) stable `===` inside one scheme so two atoms\n * resolving to the same value yield the same object reference.\n */\nclass ValueDeduper {\n private readonly byText = new Map<string, string>()\n private readonly decls: string[] = []\n\n intern(serialized: string): string {\n const existing = this.byText.get(serialized)\n if (existing) return existing\n const name = `_s${this.decls.length}`\n this.decls.push(`const ${name} = ${serialized}`)\n this.byText.set(serialized, name)\n return name\n }\n\n get declarations(): readonly string[] {\n return this.decls\n }\n}\n\n/**\n * Render one scheme file's source. `entries` is the list of atoms this\n * scheme contributes — for `common` every atom's canonical value; for\n * a variant only atoms whose value differs from canonical. Hairline\n * atoms in this file trigger the `StyleSheet` import.\n * @param schemeName Registry key (`'common'` or the variant name).\n * @param entries `[atomName, serializedValue]` pairs to emit.\n * @returns JS source text.\n */\nfunction renderSchemeFile(schemeName: string, entries: readonly (readonly [string, string])[]): string {\n const needsStyleSheet = entries.some(([atom]) => isHairlineAtom(atom))\n const deduper = new ValueDeduper()\n const recordLines: string[] = []\n for (const [atom, value] of entries) {\n const ref = deduper.intern(value)\n recordLines.push(` ${JSON.stringify(atom)}: ${ref},`)\n }\n\n const lines: string[] = []\n if (needsStyleSheet) lines.push(`import { StyleSheet } from 'react-native'`)\n lines.push(`import { registerAtoms } from 'rnwind'`, ``)\n if (deduper.declarations.length > 0) {\n for (const decl of deduper.declarations) lines.push(decl)\n lines.push(``)\n }\n lines.push(`registerAtoms(${JSON.stringify(schemeName)}, {`, ...recordLines, `})`, ``)\n return lines.join('\\n')\n}\n\n/**\n * Render the JS-object literal for the responsive-breakpoint table the\n * runtime registers at manifest-load time. Sorted by ascending px\n * threshold so the runtime can build a deterministic \"tier index\" for\n * its style cache.\n * @param breakpoints Breakpoint name → px-threshold map.\n * @returns Object-literal source (`{}` when empty).\n */\nfunction serializeBreakpoints(breakpoints: ReadonlyMap<string, number>): string {\n if (breakpoints.size === 0) return '{}'\n const entries = [...breakpoints].toSorted((a, b) => a[1] - b[1] || a[0].localeCompare(b[0]))\n const inner = entries.map(([name, px]) => `${JSON.stringify(name)}: ${px}`).join(', ')\n return `{ ${inner} }`\n}\n\n/**\n * Render the manifest module. Eager-imports `common.style.js` (every\n * rewritten source file pulls this via a transitive side-effect\n * import), registers the responsive-breakpoint table once, and lazy-\n * requires every variant scheme's file through an inline require —\n * first call in `ensureSchemeLoaded(name)` triggers the scheme\n * module's evaluation; Metro's module cache makes subsequent calls\n * no-ops.\n * @param variants Variant scheme names (no `base`, no `common`).\n * @param breakpoints Responsive breakpoint name → px-threshold map.\n * @returns JS source text.\n */\nfunction renderManifest(variants: readonly string[], breakpoints: ReadonlyMap<string, number>): string {\n const lines: string[] = [\n `import { registerSchemeLoader, registerBreakpoints } from 'rnwind'`,\n `import './common.style'`,\n ``,\n `registerBreakpoints(${serializeBreakpoints(breakpoints)})`,\n ``,\n ]\n if (variants.length === 0) {\n lines.push(`function ensureSchemeLoaded(_name) {}`, ``, `registerSchemeLoader(ensureSchemeLoaded)`, ``, `export { ensureSchemeLoaded }`, ``)\n return lines.join('\\n')\n }\n lines.push(`const LOADERS = {`)\n for (const variant of variants) {\n lines.push(` ${JSON.stringify(variant)}: () => require(${JSON.stringify(`./${variant}.style`)}),`)\n }\n lines.push(`}`, ``, `function ensureSchemeLoaded(name) {`, ` const loader = LOADERS[name]`, ` if (loader) loader()`, `}`, ``, `registerSchemeLoader(ensureSchemeLoaded)`, ``, `export { ensureSchemeLoaded }`, ``)\n return lines.join('\\n')\n}\n\n/** Output of one build pass — one source per scheme plus the manifest. */\nexport interface BuildSchemeSourcesOutput {\n /** `<schemeName>.style.js` source per scheme. Always contains `common`. */\n readonly schemeSources: Readonly<Record<string, string>>\n /** Manifest module source (`schemes.js`). */\n readonly manifestSource: string\n /** Variant scheme names this build covers (sorted; excludes `common`). */\n readonly variants: readonly string[]\n /** Number of `prepareAtomValue` / JSON.stringify passes (cache MISSES) this call did — test telemetry. */\n readonly serializedMisses: number\n}\n\n/**\n * Per-atom cached serialized value. Canonical (common) string plus a\n * map of variant → own-serialized-string. `styleRef` is an identity\n * guard against the resolved SchemedStyle — when callers replace an\n * atom's value the ref diverges and the cache rebuilds that entry.\n */\nexport interface AtomSerializedEntry {\n styleRef: SchemedStyle\n canonical: string\n variants: Map<string, string>\n}\n\n/** Cache UnionBuilder owns across repeated writeSchemes calls. */\nexport type AtomSerializedCache = Map<string, AtomSerializedEntry>\n\n/**\n * Pre-serialize every non-empty variant value, reusing the per-atom\n * cache where present. Result drives both the scheme-uniform check\n * AND the per-variant emission loop downstream.\n * @param atom Atom name.\n * @param schemed Parser-produced schemed bucket.\n * @param variants Variant scheme names in deterministic order.\n * @param keyframes Keyframes available to inline.\n * @param cached Cached entry for this atom (when ref-stable).\n * @returns variantName → serialized text.\n */\nfunction buildVariantTexts(\n atom: string,\n schemed: SchemedStyle,\n variants: readonly string[],\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n cached: AtomSerializedEntry | undefined,\n): Map<string, string> {\n const out = new Map<string, string>()\n for (const variant of variants) {\n const own = (schemed as Readonly<Record<string, RNStyle>>)[variant]\n if (!isNonEmptyStyle(own)) continue\n const text = cached?.variants.get(variant) ?? prepareAtomValue(atom, own, keyframes)\n out.set(variant, text)\n }\n return out\n}\n\n/**\n * Decide whether a (no-base) atom should be promoted to common because\n * every declared variant resolves to the same value. This is the\n * scheme-uniform case: `flex`, `p-4`, `absolute` all carry no theme\n * variables, so Phase-1 fills every variant bucket identically and\n * leaves `base` empty — without this collapse they'd be duplicated\n * across every scheme file.\n *\n * The variant-prefix check is what keeps a real scheme-gated atom\n * (`dark:bg-indigo-800`) out of common in a single-variant project\n * (where its 1 bucket would otherwise look \"uniform\" by definition).\n * @param atom Atom name (checked for `<variant>:` prefix).\n * @param variants Declared variant scheme names.\n * @param variantTexts Serialized variant values.\n * @param canonicalText Serialized canonical (common) value.\n * @returns Whether the atom is uniform across every declared variant.\n */\nfunction isSchemeUniform(\n atom: string,\n variants: readonly string[],\n variantTexts: ReadonlyMap<string, string>,\n canonicalText: string,\n): boolean {\n if (variants.length === 0 || variantTexts.size !== variants.length) return false\n if (variants.some((variant) => atom.startsWith(`${variant}:`))) return false\n for (const text of variantTexts.values()) {\n if (text !== canonicalText) return false\n }\n return true\n}\n\n/**\n * Serialize one atom's canonical + variant-diff entries, honouring the\n * per-atom cache. Returns the number of cache MISSES this atom incurred\n * (0 when canonical was cached AND every needed variant was cached;\n * 1 when anything had to be re-stringified).\n *\n * Three paths gated on whether the parser produced a non-empty `base`\n * bucket and whether the variants converge:\n * - **Themed atom (base present)**: canonical goes to `common`, each\n * variant whose own value diverges from canonical writes the diff\n * into its own scheme file. `lookupAtom` finds the variant's\n * override or falls through to common.\n * - **Scheme-uniform atom (base empty, every variant identical)**:\n * promoted to `common` once — the parser's Phase-1 fills every\n * variant bucket with the same value for utilities like `flex` /\n * `p-4` / `absolute` that don't reference theme variables.\n * - **Scheme-gated atom (base empty, prefixed name like `dark:foo`,\n * or variants diverge)**: each populated variant writes the value\n * into its own scheme file directly; common stays empty so the\n * runtime fallback can't leak the variant style into other schemes.\n * @param atom Atom name.\n * @param schemed Parser-produced schemed bucket for the atom.\n * @param canonical Canonical RN style for `common`.\n * @param variants Variant scheme names in deterministic order.\n * @param keyframes Keyframes available to inline.\n * @param commonEntries Mutable collector for `common`'s `[atom, text]` pairs.\n * @param variantEntries Mutable collector keyed by variant name.\n * @param cache Optional shared serialized-value cache.\n * @returns Number of JSON.stringify passes triggered for this atom.\n */\nfunction collectAtomEntries(\n atom: string,\n schemed: SchemedStyle,\n canonical: RNStyle,\n variants: readonly string[],\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n commonEntries: (readonly [string, string])[],\n variantEntries: Record<string, (readonly [string, string])[]>,\n cache?: AtomSerializedCache,\n): number {\n const cached = cache?.get(atom)\n const hit = cached?.styleRef === schemed\n const baseEntry = (schemed as Readonly<Record<string, RNStyle>>)[BASE_SCHEME]\n const hasBase = isNonEmptyStyle(baseEntry)\n const canonicalText = hit ? cached.canonical : prepareAtomValue(atom, canonical, keyframes)\n const variantTexts = buildVariantTexts(atom, schemed, variants, keyframes, hit ? cached : undefined)\n const goesToCommon = hasBase || isSchemeUniform(atom, variants, variantTexts, canonicalText)\n\n if (goesToCommon) commonEntries.push([atom, canonicalText])\n\n const entry: AtomSerializedEntry = hit\n ? cached\n : { styleRef: schemed, canonical: canonicalText, variants: new Map(variantTexts) }\n if (!hit) cache?.set(atom, entry)\n\n for (const variant of variants) {\n const ownText = variantTexts.get(variant)\n if (ownText === undefined) continue\n if (goesToCommon && ownText === canonicalText) continue\n variantEntries[variant].push([atom, ownText])\n }\n return hit ? 0 : 1\n}\n\n/** Empty fallback when the caller didn't supply breakpoints (legacy callers, tests). */\nconst EMPTY_BREAKPOINTS: ReadonlyMap<string, number> = new Map()\n\n/**\n * Build the per-scheme style files + manifest source.\n *\n * Dedup rule (the thing that shrinks scheme files to their diff):\n * - Every atom's canonical value goes into `common.style.js`.\n * - Each variant's file emits an entry for an atom ONLY when the\n * variant's own resolved value differs from canonical. When the\n * variant inherits (parser emits an empty `{}` for that scheme) or\n * the variant's resolved value serializes identically to canonical,\n * the atom is omitted — at runtime the lookup falls through via\n * `cache.atoms[scheme]?.[atom] ?? cache.atoms.common[atom]`.\n *\n * Keyframes are inlined directly into atom values via `animationName`\n * ({@link inlineAnimationName}). Safe-area markers get pre-enveloped\n * via {@link envelopeSafeMarkers}. Hairline utilities stay bound to\n * `StyleSheet.hairlineWidth` at runtime.\n * @param atomNames All atom names (sorted).\n * @param resolved Per-atom schemed styles from the parser.\n * @param keyframes Keyframe blocks referenced by any atom.\n * @param cache Optional shared serialized-value cache.\n * @param breakpoints Responsive breakpoint name → px-threshold map. The\n * manifest emits `registerBreakpoints({...})` so the runtime can gate\n * `md:*` / `lg:*` atoms on `windowWidth`. Optional — empty when the\n * theme declares no breakpoints (legacy/test callers).\n * @returns Per-scheme sources, manifest source, variant list.\n */\nexport function buildSchemeSources(\n atomNames: readonly string[],\n resolved: ReadonlyMap<string, SchemedStyle>,\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n cache?: AtomSerializedCache,\n breakpoints: ReadonlyMap<string, number> = EMPTY_BREAKPOINTS,\n): BuildSchemeSourcesOutput {\n const variants = collectVariantSchemes(resolved)\n const commonEntries: (readonly [string, string])[] = []\n const variantEntries: Record<string, (readonly [string, string])[]> = {}\n for (const variant of variants) variantEntries[variant] = []\n let misses = 0\n\n for (const atom of atomNames) {\n const schemed = resolved.get(atom)\n if (!schemed) continue\n const canonical = canonicalValue(schemed)\n if (!canonical) continue\n misses += collectAtomEntries(atom, schemed, canonical, variants, keyframes, commonEntries, variantEntries, cache)\n }\n\n const schemeSources: Record<string, string> = {\n [COMMON_SCHEME]: renderSchemeFile(COMMON_SCHEME, commonEntries),\n }\n for (const variant of variants) {\n schemeSources[variant] = renderSchemeFile(variant, variantEntries[variant])\n }\n\n return {\n schemeSources,\n manifestSource: renderManifest(variants, breakpoints),\n variants,\n serializedMisses: misses,\n }\n}\n\n/** Registry key the runtime uses for the always-loaded fallback. */\nexport const COMMON_SCHEME_NAME: string = COMMON_SCHEME\n"],"names":[],"mappings":"AAEA;AACA,MAAM,aAAa,GAAG,YAAY;AAElC;AACA,MAAM,WAAW,GAAG,MAAM;AAE1B;AACA,MAAM,aAAa,GAAG,QAAQ;AAE9B;AACA,MAAM,SAAS,GAAG,SAAS;AAE3B;;;;;AAKG;AACH,SAAS,cAAc,CAAC,QAA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C,EAC3C,SAA6C,EAC7C,KAA2B,EAC3B,WAAA,GAA2C,iBAAiB,EAAA;AAE5D,IAAA,MAAM,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC;IAChD,MAAM,aAAa,GAAkC,EAAE;IACvD,MAAM,cAAc,GAAkD,EAAE;IACxE,KAAK,MAAM,OAAO,IAAI,QAAQ;AAAE,QAAA,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE;IAC5D,IAAI,MAAM,GAAG,CAAC;AAEd,IAAA,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE;QAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;AAClC,QAAA,IAAI,CAAC,OAAO;YAAE;AACd,QAAA,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC;AACzC,QAAA,IAAI,CAAC,SAAS;YAAE;AAChB,QAAA,MAAM,IAAI,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,CAAC;IACnH;AAEA,IAAA,MAAM,aAAa,GAA2B;QAC5C,CAAC,aAAa,GAAG,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;KAChE;AACD,IAAA,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;AAC9B,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7E;IAEA,OAAO;QACL,aAAa;AACb,QAAA,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC;QACrD,QAAQ;AACR,QAAA,gBAAgB,EAAE,MAAM;KACzB;AACH;;;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
3
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
4
+ * declarations even when the entry only re-exports them via `@import`.
5
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
6
+ * @returns Inlined CSS, or `''` when the entry can't be read.
7
+ */
8
+ export declare function resolveThemeCss(entryFilePath: string): string;
@@ -0,0 +1,79 @@
1
+ import { createRequire } from 'node:module';
2
+ import { readFileSync, existsSync } from 'node:fs';
3
+
4
+ /**
5
+ * Inline `@import` resolution for the theme entry CSS.
6
+ *
7
+ * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,
8
+ * `extractCustomVariantSchemes`) are plain text passes over the entry
9
+ * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow
10
+ * imports, so utilities still compile, but a user who keeps their theme
11
+ * in a separate file and points the entry at it:
12
+ *
13
+ * ```css
14
+ * @import "@acme/ui/theme.css"; // global.css — the cssEntryFile
15
+ * ```
16
+ *
17
+ * would hand the extractors a file with no `@theme` / `@variant` /
18
+ * `@custom-variant` in sight → every scheme collapses to base and theme
19
+ * switching dies. This module flattens those user imports first so the
20
+ * extractors (and the compiler) see the real declarations.
21
+ */
22
+ /** Matches a bare `@import "spec";` / `@import 'spec';` (no media/layer suffix). */
23
+ const CSS_IMPORT = /@import\s+(["'])([^"']+)\1\s*;/g;
24
+ /**
25
+ * Specs left untouched for the Tailwind compiler to resolve itself.
26
+ * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the
27
+ * framework preset — both are the compiler's job, not user theme files.
28
+ */
29
+ const FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind']);
30
+ /**
31
+ * Read `filePath` and replace each user `@import "<spec>";` whose spec
32
+ * resolves (Node resolution, honouring `exports` maps and workspace
33
+ * symlinks) to a readable `.css` file with that file's inlined +
34
+ * recursively-resolved contents. Unresolvable specs, non-CSS targets,
35
+ * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.
36
+ * @param filePath Absolute path of the CSS file being inlined.
37
+ * @param seen Visited set guarding against import cycles.
38
+ * @returns CSS text with user imports flattened in place.
39
+ */
40
+ function inlineImports(filePath, seen) {
41
+ if (seen.has(filePath))
42
+ return '';
43
+ seen.add(filePath);
44
+ let css;
45
+ try {
46
+ css = readFileSync(filePath, 'utf8');
47
+ }
48
+ catch {
49
+ return '';
50
+ }
51
+ const request = createRequire(filePath);
52
+ return css.replaceAll(CSS_IMPORT, (full, _quote, spec) => {
53
+ if (FRAMEWORK_SPECS.has(spec))
54
+ return full;
55
+ let resolved;
56
+ try {
57
+ resolved = request.resolve(spec);
58
+ }
59
+ catch {
60
+ return full;
61
+ }
62
+ if (!resolved.endsWith('.css') || !existsSync(resolved))
63
+ return full;
64
+ return inlineImports(resolved, seen);
65
+ });
66
+ }
67
+ /**
68
+ * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based
69
+ * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`
70
+ * declarations even when the entry only re-exports them via `@import`.
71
+ * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).
72
+ * @returns Inlined CSS, or `''` when the entry can't be read.
73
+ */
74
+ function resolveThemeCss(entryFilePath) {
75
+ return inlineImports(entryFilePath, new Set());
76
+ }
77
+
78
+ export { resolveThemeCss };
79
+ //# sourceMappingURL=css-imports.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-imports.mjs","sources":["../../../../src/metro/css-imports.ts"],"sourcesContent":["import { createRequire } from 'node:module'\nimport { existsSync, readFileSync } from 'node:fs'\n\n/**\n * Inline `@import` resolution for the theme entry CSS.\n *\n * rnwind's scheme extractors (`extractThemeVars`, `extractSchemeAliases`,\n * `extractCustomVariantSchemes`) are plain text passes over the entry\n * CSS — they don't follow `@import`. Tailwind's own compiler DOES follow\n * imports, so utilities still compile, but a user who keeps their theme\n * in a separate file and points the entry at it:\n *\n * ```css\n * @import \"@acme/ui/theme.css\"; // global.css — the cssEntryFile\n * ```\n *\n * would hand the extractors a file with no `@theme` / `@variant` /\n * `@custom-variant` in sight → every scheme collapses to base and theme\n * switching dies. This module flattens those user imports first so the\n * extractors (and the compiler) see the real declarations.\n */\n\n/** Matches a bare `@import \"spec\";` / `@import 'spec';` (no media/layer suffix). */\nconst CSS_IMPORT = /@import\\s+([\"'])([^\"']+)\\1\\s*;/g\n\n/**\n * Specs left untouched for the Tailwind compiler to resolve itself.\n * `tailwindcss` resolves to JS (not inlinable) and `rnwind/css` is the\n * framework preset — both are the compiler's job, not user theme files.\n */\nconst FRAMEWORK_SPECS = new Set(['tailwindcss', 'rnwind/css', 'rnwind'])\n\n/**\n * Read `filePath` and replace each user `@import \"<spec>\";` whose spec\n * resolves (Node resolution, honouring `exports` maps and workspace\n * symlinks) to a readable `.css` file with that file's inlined +\n * recursively-resolved contents. Unresolvable specs, non-CSS targets,\n * and {@link FRAMEWORK_SPECS} are left as-is for the compiler.\n * @param filePath Absolute path of the CSS file being inlined.\n * @param seen Visited set guarding against import cycles.\n * @returns CSS text with user imports flattened in place.\n */\nfunction inlineImports(filePath: string, seen: Set<string>): string {\n if (seen.has(filePath)) return ''\n seen.add(filePath)\n let css: string\n try {\n css = readFileSync(filePath, 'utf8')\n } catch {\n return ''\n }\n const request = createRequire(filePath)\n return css.replaceAll(CSS_IMPORT, (full: string, _quote: string, spec: string): string => {\n if (FRAMEWORK_SPECS.has(spec)) return full\n let resolved: string\n try {\n resolved = request.resolve(spec)\n } catch {\n return full\n }\n if (!resolved.endsWith('.css') || !existsSync(resolved)) return full\n return inlineImports(resolved, seen)\n })\n}\n\n/**\n * Flatten user `@import`s in a theme entry CSS file so rnwind's text-based\n * scheme extractors see the real `@theme` / `@variant` / `@custom-variant`\n * declarations even when the entry only re-exports them via `@import`.\n * @param entryFilePath Absolute path to the theme entry CSS (the cssEntryFile).\n * @returns Inlined CSS, or `''` when the entry can't be read.\n */\nexport function resolveThemeCss(entryFilePath: string): string {\n return inlineImports(entryFilePath, new Set<string>())\n}\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;AAiBG;AAEH;AACA,MAAM,UAAU,GAAG,iCAAiC;AAEpD;;;;AAIG;AACH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
20
  * @param watchFolders
21
21
  * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
22
+ * @param hostSources
23
+ * @param hostComponents
22
24
  */
23
- export declare function configureRnwindState(cssEntryFile: string, cacheDir: string, watchFolders?: readonly string[], classNamePrefixes?: readonly string[]): void;
25
+ export declare function configureRnwindState(cssEntryFile: string, cacheDir: string, watchFolders?: readonly string[], classNamePrefixes?: readonly string[], hostSources?: readonly string[], hostComponents?: readonly string[]): void;
24
26
  /**
25
27
  * Read the caller-configured extra className prefixes out of the
26
28
  * worker environment. Returns an empty array when unset — the
@@ -29,6 +31,20 @@ export declare function configureRnwindState(cssEntryFile: string, cacheDir: str
29
31
  * @returns User-supplied extra prefixes.
30
32
  */
31
33
  export declare function getClassNamePrefixes(): readonly string[];
34
+ /**
35
+ * Read the caller-configured extra host module sources out of the
36
+ * worker environment. Empty array when unset — the transformer applies
37
+ * its built-in default list on top either way.
38
+ * @returns User-supplied extra host sources.
39
+ */
40
+ export declare function getHostSources(): readonly string[];
41
+ /**
42
+ * Read the caller-configured extra host JSX tag names out of the worker
43
+ * environment. Verbatim names — may include `.` for member expressions
44
+ * like `'Animated.View'`.
45
+ * @returns User-supplied extra host component names.
46
+ */
47
+ export declare function getHostComponents(): readonly string[];
32
48
  /**
33
49
  * Fetch (or build) the worker-local rnwind state. Re-reads the theme
34
50
  * CSS hash on every call: if the user edited `global.css` while Metro
@@ -1,8 +1,9 @@
1
- import { readFileSync, existsSync, statSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createHash } from 'node:crypto';
4
4
  import { UnionBuilder } from '../core/style-builder/union-builder.mjs';
5
5
  import { TailwindParser } from '../core/parser/tw-parser.mjs';
6
+ import { resolveThemeCss } from './css-imports.mjs';
6
7
 
7
8
  /**
8
9
  * Default oxide Scanner globs — walk every JS/TS source under the
@@ -49,15 +50,20 @@ const CACHE_DIR_ENV = 'RNWIND_CACHE_DIR';
49
50
  const WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS';
50
51
  /** Env var carrying extra className prefixes the Metro config supplied. */
51
52
  const CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES';
53
+ /** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */
54
+ const HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES';
55
+ /** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */
56
+ const HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS';
52
57
  /** Memoised library fingerprint — read once per worker process. */
53
58
  let libraryFingerprint;
54
59
  /** Live state shared across one Metro transform worker. */
55
60
  let cached = null;
56
61
  /**
57
- * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
58
- * file's mtime nanoseconds (so identical content with different mtime
59
- * atomic rewrites still picks up the change). Returns `'missing'`
60
- * when the file can't be read so the cache key is still deterministic.
62
+ * Cheap content-hash readout. SHA-256 prefix of the FULLY-RESOLVED theme
63
+ * CSS — `@import`s flattened so an edit to a theme file the entry only
64
+ * re-exports (`@import "@acme/ui/theme.css"`) still rotates the hash and
65
+ * invalidates Metro's cache. Returns `'missing'` when the entry can't be
66
+ * read so the cache key stays deterministic.
61
67
  * @param cssPath Absolute CSS path.
62
68
  * @returns 16-char hex content hash.
63
69
  */
@@ -65,9 +71,7 @@ function readThemeHashFor(cssPath) {
65
71
  if (!existsSync(cssPath))
66
72
  return 'missing';
67
73
  try {
68
- const bytes = readFileSync(cssPath);
69
- const mtime = statSync(cssPath).mtimeMs.toString();
70
- return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16);
74
+ return createHash('sha256').update(resolveThemeCss(cssPath)).digest('hex').slice(0, 16);
71
75
  }
72
76
  catch {
73
77
  return 'missing';
@@ -133,8 +137,10 @@ function getLibraryFingerprint() {
133
137
  * @param cacheDir Absolute path to the cache dir (`.rnwind`).
134
138
  * @param watchFolders
135
139
  * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
140
+ * @param hostSources
141
+ * @param hostComponents
136
142
  */
137
- function configureRnwindState(cssEntryFile, cacheDir, watchFolders = [], classNamePrefixes) {
143
+ function configureRnwindState(cssEntryFile, cacheDir, watchFolders = [], classNamePrefixes, hostSources, hostComponents) {
138
144
  process.env[CSS_ENTRY_ENV] = cssEntryFile;
139
145
  process.env[CACHE_DIR_ENV] = cacheDir;
140
146
  if (watchFolders.length === 0) {
@@ -149,6 +155,18 @@ function configureRnwindState(cssEntryFile, cacheDir, watchFolders = [], classNa
149
155
  else {
150
156
  process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',');
151
157
  }
158
+ if (!hostSources || hostSources.length === 0) {
159
+ delete process.env[HOST_SOURCES_ENV];
160
+ }
161
+ else {
162
+ process.env[HOST_SOURCES_ENV] = hostSources.join(',');
163
+ }
164
+ if (!hostComponents || hostComponents.length === 0) {
165
+ delete process.env[HOST_COMPONENTS_ENV];
166
+ }
167
+ else {
168
+ process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',');
169
+ }
152
170
  cached = null;
153
171
  }
154
172
  /**
@@ -164,6 +182,30 @@ function getClassNamePrefixes() {
164
182
  return [];
165
183
  return raw.split(',').filter((entry) => entry.length > 0);
166
184
  }
185
+ /**
186
+ * Read the caller-configured extra host module sources out of the
187
+ * worker environment. Empty array when unset — the transformer applies
188
+ * its built-in default list on top either way.
189
+ * @returns User-supplied extra host sources.
190
+ */
191
+ function getHostSources() {
192
+ const raw = process.env[HOST_SOURCES_ENV];
193
+ if (!raw || raw.length === 0)
194
+ return [];
195
+ return raw.split(',').filter((entry) => entry.length > 0);
196
+ }
197
+ /**
198
+ * Read the caller-configured extra host JSX tag names out of the worker
199
+ * environment. Verbatim names — may include `.` for member expressions
200
+ * like `'Animated.View'`.
201
+ * @returns User-supplied extra host component names.
202
+ */
203
+ function getHostComponents() {
204
+ const raw = process.env[HOST_COMPONENTS_ENV];
205
+ if (!raw || raw.length === 0)
206
+ return [];
207
+ return raw.split(',').filter((entry) => entry.length > 0);
208
+ }
167
209
  /**
168
210
  * Fetch (or build) the worker-local rnwind state. Re-reads the theme
169
211
  * CSS hash on every call: if the user edited `global.css` while Metro
@@ -184,7 +226,7 @@ function getRnwindState(projectRoot) {
184
226
  const currentHash = readThemeHashFor(cssEntry);
185
227
  if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot)
186
228
  return cached;
187
- const themeCss = readFileSync(cssEntry, 'utf8');
229
+ const themeCss = resolveThemeCss(cssEntry);
188
230
  const parser = new TailwindParser({
189
231
  themeCss,
190
232
  sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
@@ -205,7 +247,13 @@ function getRnwindState(projectRoot) {
205
247
  function getRnwindCacheKey() {
206
248
  const cssEntry = process.env[CSS_ENTRY_ENV] ?? '';
207
249
  const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? '';
208
- return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}`;
250
+ // Host source / component config changes which JSX tags get rewritten,
251
+ // so it MUST flip the cache key — otherwise Metro replays stale
252
+ // transforms (a newly-opted-in host keeps its raw className, a removed
253
+ // one keeps the rewrite).
254
+ const hostSources = process.env[HOST_SOURCES_ENV] ?? '';
255
+ const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? '';
256
+ return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`;
209
257
  }
210
258
  /** Drop the cached state — call after editing the theme CSS. */
211
259
  function resetRnwindState() {
@@ -239,5 +287,5 @@ function manifestPathFor() {
239
287
  return path.join(cacheDir, 'schemes.js');
240
288
  }
241
289
 
242
- export { configureRnwindState, getClassNamePrefixes, getRnwindCacheKey, getRnwindState, manifestPathFor, onThemeChange, resetRnwindState };
290
+ export { configureRnwindState, getClassNamePrefixes, getHostComponents, getHostSources, getRnwindCacheKey, getRnwindState, manifestPathFor, onThemeChange, resetRnwindState };
243
291
  //# sourceMappingURL=state.mjs.map