rnwind 0.0.1 → 0.0.3
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/lib/cjs/core/parser/animation.cjs +427 -0
- package/lib/cjs/core/parser/animation.cjs.map +1 -0
- package/lib/cjs/core/parser/animation.d.ts +126 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs +180 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/cjs/core/parser/case-convert.cjs +15 -0
- package/lib/cjs/core/parser/case-convert.cjs.map +1 -0
- package/lib/cjs/core/parser/case-convert.d.ts +6 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs +84 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/cjs/core/parser/color.cjs +193 -0
- package/lib/cjs/core/parser/color.cjs.map +1 -0
- package/lib/cjs/core/parser/color.d.ts +12 -0
- package/lib/cjs/core/parser/constants.cjs +21 -0
- package/lib/cjs/core/parser/constants.cjs.map +1 -0
- package/lib/cjs/core/parser/constants.d.ts +8 -0
- package/lib/cjs/core/parser/declaration.cjs +347 -0
- package/lib/cjs/core/parser/declaration.cjs.map +1 -0
- package/lib/cjs/core/parser/declaration.d.ts +15 -0
- package/lib/cjs/core/parser/gradient.cjs +132 -0
- package/lib/cjs/core/parser/gradient.cjs.map +1 -0
- package/lib/cjs/core/parser/gradient.d.ts +59 -0
- package/lib/cjs/core/parser/haptics.cjs +73 -0
- package/lib/cjs/core/parser/haptics.cjs.map +1 -0
- package/lib/cjs/core/parser/haptics.d.ts +47 -0
- package/lib/cjs/core/parser/index.d.ts +8 -0
- package/lib/cjs/core/parser/keyframes.cjs +95 -0
- package/lib/cjs/core/parser/keyframes.cjs.map +1 -0
- package/lib/cjs/core/parser/keyframes.d.ts +26 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs +120 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/cjs/core/parser/length.cjs +110 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +51 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs +77 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/property.cjs +22 -0
- package/lib/cjs/core/parser/property.cjs.map +1 -0
- package/lib/cjs/core/parser/property.d.ts +8 -0
- package/lib/cjs/core/parser/safe-area.cjs +404 -0
- package/lib/cjs/core/parser/safe-area.cjs.map +1 -0
- package/lib/cjs/core/parser/safe-area.d.ts +39 -0
- package/lib/cjs/core/parser/selector.cjs +22 -0
- package/lib/cjs/core/parser/selector.cjs.map +1 -0
- package/lib/cjs/core/parser/selector.d.ts +11 -0
- package/lib/cjs/core/parser/shorthand.cjs +188 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +67 -0
- package/lib/cjs/core/parser/text-truncate.cjs +78 -0
- package/lib/cjs/core/parser/text-truncate.cjs.map +1 -0
- package/lib/cjs/core/parser/text-truncate.d.ts +44 -0
- package/lib/cjs/core/parser/theme-vars.cjs +467 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +82 -0
- package/lib/cjs/core/parser/tokens.cjs +486 -0
- package/lib/cjs/core/parser/tokens.cjs.map +1 -0
- package/lib/cjs/core/parser/tokens.d.ts +45 -0
- package/lib/cjs/core/parser/transform.cjs +198 -0
- package/lib/cjs/core/parser/transform.cjs.map +1 -0
- package/lib/cjs/core/parser/transform.d.ts +36 -0
- package/lib/cjs/core/parser/tw-parser.cjs +1680 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +210 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +108 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/typography.cjs +97 -0
- package/lib/cjs/core/parser/typography.cjs.map +1 -0
- package/lib/cjs/core/parser/typography.d.ts +43 -0
- package/lib/cjs/core/style-builder/build-style.cjs +444 -0
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -0
- package/lib/cjs/core/style-builder/build-style.d.ts +54 -0
- package/lib/cjs/core/style-builder/index.d.ts +3 -0
- package/lib/cjs/core/style-builder/union-builder.cjs +326 -0
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -0
- package/lib/cjs/core/style-builder/union-builder.d.ts +128 -0
- package/lib/cjs/core/types.d.ts +14 -0
- package/lib/cjs/metro/dts.cjs +127 -0
- package/lib/cjs/metro/dts.cjs.map +1 -0
- package/lib/cjs/metro/dts.d.ts +16 -0
- package/lib/cjs/metro/index.cjs +19 -0
- package/lib/cjs/metro/index.cjs.map +1 -0
- package/lib/cjs/metro/index.d.ts +9 -0
- package/lib/cjs/metro/resolver.cjs +47 -0
- package/lib/cjs/metro/resolver.cjs.map +1 -0
- package/lib/cjs/metro/resolver.d.ts +22 -0
- package/lib/cjs/metro/state.cjs +301 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +88 -0
- package/lib/cjs/metro/transform-ast.cjs +1472 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +88 -0
- package/lib/cjs/metro/transformer.cjs +372 -0
- package/lib/cjs/metro/transformer.cjs.map +1 -0
- package/lib/cjs/metro/transformer.d.ts +47 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs +86 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs.map +1 -0
- package/lib/cjs/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/cjs/metro/with-config.cjs +196 -0
- package/lib/cjs/metro/with-config.cjs.map +1 -0
- package/lib/cjs/metro/with-config.d.ts +79 -0
- package/lib/cjs/runtime/chain-handlers.cjs +37 -0
- package/lib/cjs/runtime/chain-handlers.cjs.map +1 -0
- package/lib/cjs/runtime/chain-handlers.d.ts +33 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs +98 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -0
- package/lib/cjs/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/cjs/runtime/gradient-types.d.ts +58 -0
- package/lib/cjs/runtime/haptics.cjs +113 -0
- package/lib/cjs/runtime/haptics.cjs.map +1 -0
- package/lib/cjs/runtime/haptics.d.ts +48 -0
- package/lib/cjs/runtime/hooks/use-css.cjs +21 -0
- package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-css.d.ts +11 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs +46 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs +68 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/cjs/runtime/index.cjs +45 -0
- package/lib/cjs/runtime/index.cjs.map +1 -0
- package/lib/cjs/runtime/index.d.ts +27 -0
- package/lib/cjs/runtime/interactive-box.cjs +35 -0
- package/lib/cjs/runtime/interactive-box.cjs.map +1 -0
- package/lib/cjs/runtime/interactive-box.d.ts +40 -0
- package/lib/cjs/runtime/lookup-css.cjs +542 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -0
- package/lib/cjs/runtime/lookup-css.d.ts +164 -0
- package/lib/cjs/runtime/types.d.ts +29 -0
- package/lib/cjs/testing/index.cjs +367 -0
- package/lib/cjs/testing/index.cjs.map +1 -0
- package/lib/cjs/testing/index.d.ts +145 -0
- package/lib/esm/core/parser/animation.d.ts +126 -0
- package/lib/esm/core/parser/animation.mjs +408 -0
- package/lib/esm/core/parser/animation.mjs.map +1 -0
- package/lib/esm/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/esm/core/parser/border-dispatcher.mjs +178 -0
- package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/case-convert.d.ts +6 -0
- package/lib/esm/core/parser/case-convert.mjs +13 -0
- package/lib/esm/core/parser/case-convert.mjs.map +1 -0
- package/lib/esm/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs +82 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/color.d.ts +12 -0
- package/lib/esm/core/parser/color.mjs +191 -0
- package/lib/esm/core/parser/color.mjs.map +1 -0
- package/lib/esm/core/parser/constants.d.ts +8 -0
- package/lib/esm/core/parser/constants.mjs +13 -0
- package/lib/esm/core/parser/constants.mjs.map +1 -0
- package/lib/esm/core/parser/declaration.d.ts +15 -0
- package/lib/esm/core/parser/declaration.mjs +345 -0
- package/lib/esm/core/parser/declaration.mjs.map +1 -0
- package/lib/esm/core/parser/gradient.d.ts +59 -0
- package/lib/esm/core/parser/gradient.mjs +130 -0
- package/lib/esm/core/parser/gradient.mjs.map +1 -0
- package/lib/esm/core/parser/haptics.d.ts +47 -0
- package/lib/esm/core/parser/haptics.mjs +71 -0
- package/lib/esm/core/parser/haptics.mjs.map +1 -0
- package/lib/esm/core/parser/index.d.ts +8 -0
- package/lib/esm/core/parser/keyframes.d.ts +26 -0
- package/lib/esm/core/parser/keyframes.mjs +91 -0
- package/lib/esm/core/parser/keyframes.mjs.map +1 -0
- package/lib/esm/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs +118 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +51 -0
- package/lib/esm/core/parser/length.mjs +104 -0
- package/lib/esm/core/parser/length.mjs.map +1 -0
- package/lib/esm/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs +75 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/property.d.ts +8 -0
- package/lib/esm/core/parser/property.mjs +20 -0
- package/lib/esm/core/parser/property.mjs.map +1 -0
- package/lib/esm/core/parser/safe-area.d.ts +39 -0
- package/lib/esm/core/parser/safe-area.mjs +402 -0
- package/lib/esm/core/parser/safe-area.mjs.map +1 -0
- package/lib/esm/core/parser/selector.d.ts +11 -0
- package/lib/esm/core/parser/selector.mjs +20 -0
- package/lib/esm/core/parser/selector.mjs.map +1 -0
- package/lib/esm/core/parser/shorthand.d.ts +67 -0
- package/lib/esm/core/parser/shorthand.mjs +180 -0
- package/lib/esm/core/parser/shorthand.mjs.map +1 -0
- package/lib/esm/core/parser/text-truncate.d.ts +44 -0
- package/lib/esm/core/parser/text-truncate.mjs +75 -0
- package/lib/esm/core/parser/text-truncate.mjs.map +1 -0
- package/lib/esm/core/parser/theme-vars.d.ts +82 -0
- package/lib/esm/core/parser/theme-vars.mjs +461 -0
- package/lib/esm/core/parser/theme-vars.mjs.map +1 -0
- package/lib/esm/core/parser/tokens.d.ts +45 -0
- package/lib/esm/core/parser/tokens.mjs +480 -0
- package/lib/esm/core/parser/tokens.mjs.map +1 -0
- package/lib/esm/core/parser/transform.d.ts +36 -0
- package/lib/esm/core/parser/transform.mjs +193 -0
- package/lib/esm/core/parser/transform.mjs.map +1 -0
- package/lib/esm/core/parser/tw-parser.d.ts +210 -0
- package/lib/esm/core/parser/tw-parser.mjs +1678 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -0
- package/lib/esm/core/parser/types.d.ts +37 -0
- package/lib/esm/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs +106 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/typography.d.ts +43 -0
- package/lib/esm/core/parser/typography.mjs +91 -0
- package/lib/esm/core/parser/typography.mjs.map +1 -0
- package/lib/esm/core/style-builder/build-style.d.ts +54 -0
- package/lib/esm/core/style-builder/build-style.mjs +442 -0
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -0
- package/lib/esm/core/style-builder/index.d.ts +3 -0
- package/lib/esm/core/style-builder/union-builder.d.ts +128 -0
- package/lib/esm/core/style-builder/union-builder.mjs +324 -0
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -0
- package/lib/esm/core/types.d.ts +14 -0
- package/lib/esm/metro/dts.d.ts +16 -0
- package/lib/esm/metro/dts.mjs +125 -0
- package/lib/esm/metro/dts.mjs.map +1 -0
- package/lib/esm/metro/index.d.ts +9 -0
- package/lib/esm/metro/index.mjs +6 -0
- package/lib/esm/metro/index.mjs.map +1 -0
- package/lib/esm/metro/resolver.d.ts +22 -0
- package/lib/esm/metro/resolver.mjs +43 -0
- package/lib/esm/metro/resolver.mjs.map +1 -0
- package/lib/esm/metro/state.d.ts +88 -0
- package/lib/esm/metro/state.mjs +291 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +88 -0
- package/lib/esm/metro/transform-ast.mjs +1451 -0
- package/lib/esm/metro/transform-ast.mjs.map +1 -0
- package/lib/esm/metro/transformer.d.ts +47 -0
- package/lib/esm/metro/transformer.mjs +349 -0
- package/lib/esm/metro/transformer.mjs.map +1 -0
- package/lib/esm/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/esm/metro/warn-unknown-classes.mjs +84 -0
- package/lib/esm/metro/warn-unknown-classes.mjs.map +1 -0
- package/lib/esm/metro/with-config.d.ts +79 -0
- package/lib/esm/metro/with-config.mjs +194 -0
- package/lib/esm/metro/with-config.mjs.map +1 -0
- package/lib/esm/runtime/chain-handlers.d.ts +33 -0
- package/lib/esm/runtime/chain-handlers.mjs +34 -0
- package/lib/esm/runtime/chain-handlers.mjs.map +1 -0
- package/lib/esm/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs +94 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -0
- package/lib/esm/runtime/gradient-types.d.ts +58 -0
- package/lib/esm/runtime/haptics.d.ts +48 -0
- package/lib/esm/runtime/haptics.mjs +110 -0
- package/lib/esm/runtime/haptics.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-css.d.ts +11 -0
- package/lib/esm/runtime/hooks/use-css.mjs +19 -0
- package/lib/esm/runtime/hooks/use-css.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/esm/runtime/hooks/use-interact.mjs +44 -0
- package/lib/esm/runtime/hooks/use-interact.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs +63 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -0
- package/lib/esm/runtime/index.d.ts +27 -0
- package/lib/esm/runtime/index.mjs +18 -0
- package/lib/esm/runtime/index.mjs.map +1 -0
- package/lib/esm/runtime/interactive-box.d.ts +40 -0
- package/lib/esm/runtime/interactive-box.mjs +33 -0
- package/lib/esm/runtime/interactive-box.mjs.map +1 -0
- package/lib/esm/runtime/lookup-css.d.ts +164 -0
- package/lib/esm/runtime/lookup-css.mjs +531 -0
- package/lib/esm/runtime/lookup-css.mjs.map +1 -0
- package/lib/esm/runtime/types.d.ts +29 -0
- package/lib/esm/testing/index.d.ts +145 -0
- package/lib/esm/testing/index.mjs +344 -0
- package/lib/esm/testing/index.mjs.map +1 -0
- package/package.json +80 -13
- package/preset.css +1171 -0
- package/src/core/parser/animation.ts +404 -0
- package/src/core/parser/border-dispatcher.ts +176 -0
- package/src/core/parser/case-convert.ts +10 -0
- package/src/core/parser/color-properties-dispatcher.ts +78 -0
- package/src/core/parser/color.ts +191 -0
- package/src/core/parser/constants.ts +11 -0
- package/src/core/parser/declaration.ts +340 -0
- package/src/core/parser/gradient.ts +148 -0
- package/src/core/parser/haptics.ts +88 -0
- package/src/core/parser/index.ts +8 -0
- package/src/core/parser/keyframes.ts +84 -0
- package/src/core/parser/layout-dispatcher.ts +111 -0
- package/src/core/parser/length.ts +114 -0
- package/src/core/parser/motion-dispatcher.ts +89 -0
- package/src/core/parser/property.ts +15 -0
- package/src/core/parser/safe-area.ts +404 -0
- package/src/core/parser/selector.ts +17 -0
- package/src/core/parser/shorthand.ts +182 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +465 -0
- package/src/core/parser/tokens.ts +456 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1828 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +97 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +500 -0
- package/src/core/style-builder/index.ts +3 -0
- package/src/core/style-builder/union-builder.ts +328 -0
- package/src/core/types.ts +15 -0
- package/src/metro/dts.ts +128 -0
- package/src/metro/index.ts +9 -0
- package/src/metro/resolver.ts +42 -0
- package/src/metro/state.ts +305 -0
- package/src/metro/transform-ast.ts +1729 -0
- package/src/metro/transformer.ts +372 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +251 -0
- package/src/runtime/chain-handlers.ts +47 -0
- package/src/runtime/components/rnwind-provider.tsx +144 -0
- package/src/runtime/gradient-types.ts +60 -0
- package/src/runtime/haptics.ts +120 -0
- package/src/runtime/hooks/use-css.ts +16 -0
- package/src/runtime/hooks/use-interact.ts +65 -0
- package/src/runtime/hooks/use-scheme.ts +63 -0
- package/src/runtime/index.ts +54 -0
- package/src/runtime/interactive-box.tsx +57 -0
- package/src/runtime/lookup-css.ts +628 -0
- package/src/runtime/types.ts +32 -0
- package/src/testing/index.ts +507 -0
- package/src/types/tailwindcss-node.d.ts +33 -0
- package/src/index.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-style.cjs","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,QAAgB,EAAA;AACtC,IAAA,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;AACrC;AAEA;;;;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AAM,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,54 @@
|
|
|
1
|
+
import type { KeyframeBlock, SchemedStyle } from '../parser';
|
|
2
|
+
/** Output of one build pass — one source per scheme plus the manifest. */
|
|
3
|
+
export interface BuildSchemeSourcesOutput {
|
|
4
|
+
/** `<schemeName>.style.js` source per scheme. Always contains `common`. */
|
|
5
|
+
readonly schemeSources: Readonly<Record<string, string>>;
|
|
6
|
+
/** Manifest module source (`schemes.js`). */
|
|
7
|
+
readonly manifestSource: string;
|
|
8
|
+
/** Variant scheme names this build covers (sorted; excludes `common`). */
|
|
9
|
+
readonly variants: readonly string[];
|
|
10
|
+
/** Number of `prepareAtomValue` / JSON.stringify passes (cache MISSES) this call did — test telemetry. */
|
|
11
|
+
readonly serializedMisses: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Per-atom cached serialized value. Canonical (common) string plus a
|
|
15
|
+
* map of variant → own-serialized-string. `styleRef` is an identity
|
|
16
|
+
* guard against the resolved SchemedStyle — when callers replace an
|
|
17
|
+
* atom's value the ref diverges and the cache rebuilds that entry.
|
|
18
|
+
*/
|
|
19
|
+
export interface AtomSerializedEntry {
|
|
20
|
+
styleRef: SchemedStyle;
|
|
21
|
+
canonical: string;
|
|
22
|
+
variants: Map<string, string>;
|
|
23
|
+
}
|
|
24
|
+
/** Cache UnionBuilder owns across repeated writeSchemes calls. */
|
|
25
|
+
export type AtomSerializedCache = Map<string, AtomSerializedEntry>;
|
|
26
|
+
/**
|
|
27
|
+
* Build the per-scheme style files + manifest source.
|
|
28
|
+
*
|
|
29
|
+
* Dedup rule (the thing that shrinks scheme files to their diff):
|
|
30
|
+
* - Every atom's canonical value goes into `common.style.js`.
|
|
31
|
+
* - Each variant's file emits an entry for an atom ONLY when the
|
|
32
|
+
* variant's own resolved value differs from canonical. When the
|
|
33
|
+
* variant inherits (parser emits an empty `{}` for that scheme) or
|
|
34
|
+
* the variant's resolved value serializes identically to canonical,
|
|
35
|
+
* the atom is omitted — at runtime the lookup falls through via
|
|
36
|
+
* `cache.atoms[scheme]?.[atom] ?? cache.atoms.common[atom]`.
|
|
37
|
+
*
|
|
38
|
+
* Keyframes are inlined directly into atom values via `animationName`
|
|
39
|
+
* ({@link inlineAnimationName}). Safe-area markers get pre-enveloped
|
|
40
|
+
* via {@link envelopeSafeMarkers}. Hairline utilities stay bound to
|
|
41
|
+
* `StyleSheet.hairlineWidth` at runtime.
|
|
42
|
+
* @param atomNames All atom names (sorted).
|
|
43
|
+
* @param resolved Per-atom schemed styles from the parser.
|
|
44
|
+
* @param keyframes Keyframe blocks referenced by any atom.
|
|
45
|
+
* @param cache Optional shared serialized-value cache.
|
|
46
|
+
* @param breakpoints Responsive breakpoint name → px-threshold map. The
|
|
47
|
+
* manifest emits `registerBreakpoints({...})` so the runtime can gate
|
|
48
|
+
* `md:*` / `lg:*` atoms on `windowWidth`. Optional — empty when the
|
|
49
|
+
* theme declares no breakpoints (legacy/test callers).
|
|
50
|
+
* @returns Per-scheme sources, manifest source, variant list.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildSchemeSources(atomNames: readonly string[], resolved: ReadonlyMap<string, SchemedStyle>, keyframes: ReadonlyMap<string, KeyframeBlock>, cache?: AtomSerializedCache, breakpoints?: ReadonlyMap<string, number>): BuildSchemeSourcesOutput;
|
|
53
|
+
/** Registry key the runtime uses for the always-loaded fallback. */
|
|
54
|
+
export declare const COMMON_SCHEME_NAME: string;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_crypto = require('node:crypto');
|
|
4
|
+
var node_fs = require('node:fs');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var buildStyle = require('./build-style.cjs');
|
|
7
|
+
|
|
8
|
+
/** Manifest module basename — the file SchemeProvider imports via the resolver. */
|
|
9
|
+
const MANIFEST_BASENAME = 'schemes.js';
|
|
10
|
+
/**
|
|
11
|
+
* Atomic file write — stage to a `.tmp.<pid>.<nonce>` sibling, then
|
|
12
|
+
* `rename()` into place. Skips the write entirely when the existing
|
|
13
|
+
* content matches.
|
|
14
|
+
* @param target Final destination path.
|
|
15
|
+
* @param content Bytes to write.
|
|
16
|
+
* @returns Whether the file was actually rewritten.
|
|
17
|
+
*/
|
|
18
|
+
function writeIfChanged(target, content) {
|
|
19
|
+
if (node_fs.existsSync(target)) {
|
|
20
|
+
try {
|
|
21
|
+
if (node_fs.readFileSync(target, 'utf8') === content)
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Unreadable — fall through to rewrite.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
node_fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
29
|
+
const temporary = `${target}.${process.pid}.${node_crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
30
|
+
try {
|
|
31
|
+
node_fs.writeFileSync(temporary, content, 'utf8');
|
|
32
|
+
node_fs.renameSync(temporary, target);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
node_fs.rmSync(temporary, { force: true });
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* SHA-256 prefix of a string — cheap signature used to detect whether a
|
|
42
|
+
* per-scheme file's source has changed since the last write.
|
|
43
|
+
* @param text Input text.
|
|
44
|
+
* @returns 16-char hex digest.
|
|
45
|
+
*/
|
|
46
|
+
function signatureOf(text) {
|
|
47
|
+
return node_crypto.createHash('sha256').update(text).digest('hex').slice(0, 16);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compare two `Set<string>`s for equality — same size + every element
|
|
51
|
+
* of `a` present in `b`.
|
|
52
|
+
* @param a First set.
|
|
53
|
+
* @param b Second set.
|
|
54
|
+
* @returns Whether the two sets contain identical values.
|
|
55
|
+
*/
|
|
56
|
+
function setsEqual(a, b) {
|
|
57
|
+
if (a.size !== b.size)
|
|
58
|
+
return false;
|
|
59
|
+
for (const v of a)
|
|
60
|
+
if (!b.has(v))
|
|
61
|
+
return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Compute the absolute path of a per-scheme style file under the cache dir.
|
|
66
|
+
* @param cacheDir Absolute cache directory.
|
|
67
|
+
* @param scheme Registry key (`'common'` or a variant name).
|
|
68
|
+
* @returns Absolute path, e.g. `<cacheDir>/dark.style.js`.
|
|
69
|
+
*/
|
|
70
|
+
function schemeFilePath(cacheDir, scheme) {
|
|
71
|
+
return path.join(cacheDir, `${scheme}.style.js`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* In-memory atom union + per-scheme style-file emitter.
|
|
75
|
+
*
|
|
76
|
+
* Correctness under multi-worker Metro relies on `ensureProjectScanned`:
|
|
77
|
+
* the FIRST `recordFile` / `writeSchemes` call in every worker drives
|
|
78
|
+
* the oxide Scanner across ALL project sources and hydrates the union
|
|
79
|
+
* with the complete set of candidates. Subsequent per-file
|
|
80
|
+
* `recordFile` calls only layer in atoms the scan already knew about,
|
|
81
|
+
* so writes are idempotent — different workers can't clobber each
|
|
82
|
+
* other's scheme files with partial views.
|
|
83
|
+
*
|
|
84
|
+
* Per-file deltas (atom set unchanged → early return) skip
|
|
85
|
+
* serialization entirely. On a theme-CSS change, `getRnwindState`
|
|
86
|
+
* builds a fresh parser + builder; the next call re-runs
|
|
87
|
+
* `ensureProjectScanned` against the new parser, producing scheme
|
|
88
|
+
* files with the new theme values.
|
|
89
|
+
*/
|
|
90
|
+
class UnionBuilder {
|
|
91
|
+
cacheDir;
|
|
92
|
+
parser;
|
|
93
|
+
unionAtoms = new Map();
|
|
94
|
+
unionKeyframes = new Map();
|
|
95
|
+
/**
|
|
96
|
+
* Responsive breakpoints captured from the parser. Refreshed on every
|
|
97
|
+
* `recordFile` / `ensureProjectScanned` so user-defined
|
|
98
|
+
* `--breakpoint-*` overrides land in the manifest the next time it's
|
|
99
|
+
* written. Identical for every parser call within one parser instance
|
|
100
|
+
* (theme is fixed for the parser's lifetime), so storing the latest
|
|
101
|
+
* snapshot is sufficient.
|
|
102
|
+
*/
|
|
103
|
+
breakpoints = new Map();
|
|
104
|
+
/** file → set of atom names this file currently contributes. */
|
|
105
|
+
fileAtomSets = new Map();
|
|
106
|
+
/** atom name → how many files currently contribute it (refcount). */
|
|
107
|
+
atomRefCount = new Map();
|
|
108
|
+
/** scheme → last-written source SHA. Skips re-writing unchanged schemes. */
|
|
109
|
+
schemeSignatures = new Map();
|
|
110
|
+
/**
|
|
111
|
+
* Per-atom serialized-value cache — identity-keyed on each atom's
|
|
112
|
+
* SchemedStyle reference. Carried across `writeSchemes` calls so the
|
|
113
|
+
* typical "user added one className" FR case re-stringifies ONE atom
|
|
114
|
+
* instead of all 175+. Cleared on `ensureProjectScanned` (full
|
|
115
|
+
* rescan replaces every reference) and individually invalidated for
|
|
116
|
+
* any atom `applyDiff` mutates.
|
|
117
|
+
*/
|
|
118
|
+
serializedCache = new Map();
|
|
119
|
+
/** Running count of stringify passes (cache misses). Test telemetry. */
|
|
120
|
+
serializedMissesCount = 0;
|
|
121
|
+
/** Set after `ensureProjectScanned` completes. */
|
|
122
|
+
projectScanned = false;
|
|
123
|
+
/** Promise guard so concurrent first-calls await ONE scan. */
|
|
124
|
+
pendingScan = null;
|
|
125
|
+
constructor(cacheDir, parser) {
|
|
126
|
+
this.cacheDir = cacheDir;
|
|
127
|
+
this.parser = parser;
|
|
128
|
+
node_fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
129
|
+
}
|
|
130
|
+
/** Absolute path of the manifest module (`rnwind/__generated/schemes`). */
|
|
131
|
+
get manifestPath() {
|
|
132
|
+
return path.join(this.cacheDir, MANIFEST_BASENAME);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Snapshot of every source file the builder has recorded atoms for
|
|
136
|
+
* this worker session. Used by `withRnwindConfig`'s CSS watcher to
|
|
137
|
+
* touch `mtime` on each and nudge Metro into re-transforming them
|
|
138
|
+
* with the new theme values.
|
|
139
|
+
* @returns Absolute source paths.
|
|
140
|
+
*/
|
|
141
|
+
recordedFiles() {
|
|
142
|
+
return [...this.fileAtomSets.keys()];
|
|
143
|
+
}
|
|
144
|
+
/** Cumulative cache-miss count — exposed for tests to assert cache behaviour. */
|
|
145
|
+
get serializedMisses() {
|
|
146
|
+
return this.serializedMissesCount;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Absolute path of one scheme's style file.
|
|
150
|
+
* @param scheme Registry key.
|
|
151
|
+
* @returns Absolute path.
|
|
152
|
+
*/
|
|
153
|
+
schemePath(scheme) {
|
|
154
|
+
return schemeFilePath(this.cacheDir, scheme);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* One-shot oxide scan + compile across every source the parser was
|
|
158
|
+
* configured with. Idempotent — safe to call from any entry point.
|
|
159
|
+
* Concurrent callers share the same in-flight promise.
|
|
160
|
+
*/
|
|
161
|
+
async ensureProjectScanned() {
|
|
162
|
+
if (this.projectScanned)
|
|
163
|
+
return;
|
|
164
|
+
if (this.pendingScan)
|
|
165
|
+
return this.pendingScan;
|
|
166
|
+
this.pendingScan = (async () => {
|
|
167
|
+
const parsed = await this.parser.parseProject();
|
|
168
|
+
for (const [name, style] of parsed.atoms)
|
|
169
|
+
this.unionAtoms.set(name, style);
|
|
170
|
+
for (const [name, kf] of parsed.keyframes)
|
|
171
|
+
this.unionKeyframes.set(name, kf);
|
|
172
|
+
this.breakpoints = parsed.breakpoints;
|
|
173
|
+
this.projectScanned = true;
|
|
174
|
+
})();
|
|
175
|
+
try {
|
|
176
|
+
await this.pendingScan;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
this.pendingScan = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Record one source file's resolved atoms + keyframes. Short-circuits
|
|
184
|
+
* when the file's atom name set hasn't changed — the common case on
|
|
185
|
+
* every Fast Refresh save of a file whose className literals are
|
|
186
|
+
* unchanged.
|
|
187
|
+
* @param file Absolute source file path.
|
|
188
|
+
* @param atoms Per-atom resolved schemed styles from this transform.
|
|
189
|
+
* @param keyframes Keyframe blocks referenced by this file's atoms.
|
|
190
|
+
* @returns `{ changed: true }` when the union shifted (new atom name,
|
|
191
|
+
* removed atom name, or new keyframe) — the transformer uses this
|
|
192
|
+
* to skip the serializer + `writeSchemes` when nothing changed.
|
|
193
|
+
*/
|
|
194
|
+
async recordFile(file, atoms, keyframes) {
|
|
195
|
+
await this.ensureProjectScanned();
|
|
196
|
+
const newAtomNames = new Set(atoms.keys());
|
|
197
|
+
const previous = this.fileAtomSets.get(file);
|
|
198
|
+
if (previous && setsEqual(previous, newAtomNames)) {
|
|
199
|
+
// Atom set unchanged — skip the unionAtoms update entirely. The
|
|
200
|
+
// project scan already populated them, and re-setting a fresh
|
|
201
|
+
// object ref here would invalidate the per-atom serialization
|
|
202
|
+
// cache on every FR save for no gain (values are identical).
|
|
203
|
+
// Theme edits go through `getRnwindState` → new builder → fresh
|
|
204
|
+
// scan, so stale cache is impossible.
|
|
205
|
+
let keyframeAdded = false;
|
|
206
|
+
for (const [name, kf] of keyframes) {
|
|
207
|
+
if (!this.unionKeyframes.has(name))
|
|
208
|
+
keyframeAdded = true;
|
|
209
|
+
this.unionKeyframes.set(name, kf);
|
|
210
|
+
}
|
|
211
|
+
return { changed: keyframeAdded };
|
|
212
|
+
}
|
|
213
|
+
this.applyDiff(file, newAtomNames, atoms, keyframes);
|
|
214
|
+
return { changed: true };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Forget one source file's contribution. Idempotent — repeated calls
|
|
218
|
+
* for a file that's already dropped are no-ops. Does NOT remove the
|
|
219
|
+
* atom from the union when another file (or the project scan) still
|
|
220
|
+
* references it.
|
|
221
|
+
* @param file Absolute source file path.
|
|
222
|
+
*/
|
|
223
|
+
dropFile(file) {
|
|
224
|
+
const previous = this.fileAtomSets.get(file);
|
|
225
|
+
if (!previous)
|
|
226
|
+
return;
|
|
227
|
+
for (const name of previous) {
|
|
228
|
+
const count = (this.atomRefCount.get(name) ?? 0) - 1;
|
|
229
|
+
if (count <= 0)
|
|
230
|
+
this.atomRefCount.delete(name);
|
|
231
|
+
else
|
|
232
|
+
this.atomRefCount.set(name, count);
|
|
233
|
+
}
|
|
234
|
+
this.fileAtomSets.delete(file);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Serialize the union into per-scheme files + manifest, writing only
|
|
238
|
+
* files whose source bytes changed. Called after every `recordFile`
|
|
239
|
+
* from the transformer — and once at Metro startup via
|
|
240
|
+
* `ensureFilesExist` to seed disk from the project scan alone.
|
|
241
|
+
* @returns List of scheme keys whose files were rewritten (empty
|
|
242
|
+
* when the union is byte-identical to the last flush).
|
|
243
|
+
*/
|
|
244
|
+
async writeSchemes() {
|
|
245
|
+
await this.ensureProjectScanned();
|
|
246
|
+
const sortedAtomNames = [...this.unionAtoms.keys()].toSorted((a, b) => a.localeCompare(b));
|
|
247
|
+
const result = buildStyle.buildSchemeSources(sortedAtomNames, this.unionAtoms, this.unionKeyframes, this.serializedCache, this.breakpoints);
|
|
248
|
+
this.serializedMissesCount += result.serializedMisses;
|
|
249
|
+
const { schemeSources, manifestSource } = result;
|
|
250
|
+
const changed = [];
|
|
251
|
+
for (const [scheme, source] of Object.entries(schemeSources)) {
|
|
252
|
+
const signature = signatureOf(source);
|
|
253
|
+
const target = schemeFilePath(this.cacheDir, scheme);
|
|
254
|
+
if (this.schemeSignatures.get(scheme) === signature && node_fs.existsSync(target))
|
|
255
|
+
continue;
|
|
256
|
+
if (writeIfChanged(target, source))
|
|
257
|
+
changed.push(scheme);
|
|
258
|
+
this.schemeSignatures.set(scheme, signature);
|
|
259
|
+
}
|
|
260
|
+
const manifestSignature = signatureOf(manifestSource);
|
|
261
|
+
const manifestTarget = path.join(this.cacheDir, MANIFEST_BASENAME);
|
|
262
|
+
if (this.schemeSignatures.get('__manifest') !== manifestSignature || !node_fs.existsSync(manifestTarget)) {
|
|
263
|
+
if (writeIfChanged(manifestTarget, manifestSource))
|
|
264
|
+
changed.push('__manifest');
|
|
265
|
+
this.schemeSignatures.set('__manifest', manifestSignature);
|
|
266
|
+
}
|
|
267
|
+
return { changedSchemes: changed };
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Ensure the manifest + common scheme files exist on disk so Metro's
|
|
271
|
+
* resolver can SHA1 them at boot before the first transform runs.
|
|
272
|
+
*/
|
|
273
|
+
async ensureFilesExist() {
|
|
274
|
+
if (node_fs.existsSync(this.manifestPath) && node_fs.existsSync(schemeFilePath(this.cacheDir, 'common'))) {
|
|
275
|
+
// Still trigger the scan so the in-memory union is complete; file
|
|
276
|
+
// bytes may already be authoritative from a prior Metro run.
|
|
277
|
+
await this.ensureProjectScanned();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
await this.writeSchemes();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Apply one file's atom-name diff to the in-memory refcount + union.
|
|
284
|
+
* @param file Source file path.
|
|
285
|
+
* @param newAtoms New atom-name set for the file.
|
|
286
|
+
* @param resolvedAtoms Fresh parser output — carries the resolved
|
|
287
|
+
* styles for every entry in `newAtoms`.
|
|
288
|
+
* @param newKeyframes Keyframes this file's atoms reference.
|
|
289
|
+
*/
|
|
290
|
+
applyDiff(file, newAtoms, resolvedAtoms, newKeyframes) {
|
|
291
|
+
const previous = this.fileAtomSets.get(file) ?? new Set();
|
|
292
|
+
for (const name of previous) {
|
|
293
|
+
if (newAtoms.has(name))
|
|
294
|
+
continue;
|
|
295
|
+
const count = (this.atomRefCount.get(name) ?? 0) - 1;
|
|
296
|
+
if (count <= 0)
|
|
297
|
+
this.atomRefCount.delete(name);
|
|
298
|
+
else
|
|
299
|
+
this.atomRefCount.set(name, count);
|
|
300
|
+
// Do NOT remove `name` from `unionAtoms` — the project scan still
|
|
301
|
+
// references it (orphaned atoms get reaped on the next Metro
|
|
302
|
+
// cold start when the scanner re-walks disk).
|
|
303
|
+
}
|
|
304
|
+
for (const name of newAtoms) {
|
|
305
|
+
if (!previous.has(name))
|
|
306
|
+
this.atomRefCount.set(name, (this.atomRefCount.get(name) ?? 0) + 1);
|
|
307
|
+
// Only install the resolved style when the atom is new to the
|
|
308
|
+
// union. Replacing an existing entry with a fresh parser-
|
|
309
|
+
// produced object would swap the identity guard the per-atom
|
|
310
|
+
// serialization cache uses and force a re-stringify for every
|
|
311
|
+
// atom on every FR save. CSS edits rebuild the whole builder
|
|
312
|
+
// (via `getRnwindState`) so stale values aren't possible.
|
|
313
|
+
if (!this.unionAtoms.has(name)) {
|
|
314
|
+
const style = resolvedAtoms.get(name);
|
|
315
|
+
if (style)
|
|
316
|
+
this.unionAtoms.set(name, style);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this.fileAtomSets.set(file, new Set(newAtoms));
|
|
320
|
+
for (const [name, kf] of newKeyframes)
|
|
321
|
+
this.unionKeyframes.set(name, kf);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
exports.UnionBuilder = UnionBuilder;
|
|
326
|
+
//# sourceMappingURL=union-builder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union-builder.cjs","sources":["../../../../../src/core/style-builder/union-builder.ts"],"sourcesContent":["import { createHash, randomBytes } from 'node:crypto'\nimport { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'\nimport path from 'node:path'\nimport type { KeyframeBlock, SchemedStyle, TailwindParser } from '../parser'\nimport { buildSchemeSources, type AtomSerializedCache } from './build-style'\n\n/** Manifest module basename — the file SchemeProvider imports via the resolver. */\nconst MANIFEST_BASENAME = 'schemes.js'\n\n/**\n * Atomic file write — stage to a `.tmp.<pid>.<nonce>` sibling, then\n * `rename()` into place. Skips the write entirely when the existing\n * content matches.\n * @param target Final destination path.\n * @param content Bytes to write.\n * @returns Whether the file was actually rewritten.\n */\nfunction writeIfChanged(target: string, content: string): boolean {\n if (existsSync(target)) {\n try {\n if (readFileSync(target, 'utf8') === content) return false\n } catch {\n // Unreadable — fall through to rewrite.\n }\n }\n mkdirSync(path.dirname(target), { recursive: true })\n const temporary = `${target}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`\n try {\n writeFileSync(temporary, content, 'utf8')\n renameSync(temporary, target)\n return true\n } catch (error) {\n rmSync(temporary, { force: true })\n throw error\n }\n}\n\n/**\n * SHA-256 prefix of a string — cheap signature used to detect whether a\n * per-scheme file's source has changed since the last write.\n * @param text Input text.\n * @returns 16-char hex digest.\n */\nfunction signatureOf(text: string): string {\n return createHash('sha256').update(text).digest('hex').slice(0, 16)\n}\n\n/**\n * Compare two `Set<string>`s for equality — same size + every element\n * of `a` present in `b`.\n * @param a First set.\n * @param b Second set.\n * @returns Whether the two sets contain identical values.\n */\nfunction setsEqual(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {\n if (a.size !== b.size) return false\n for (const v of a) if (!b.has(v)) return false\n return true\n}\n\n/**\n * Compute the absolute path of a per-scheme style file under the cache dir.\n * @param cacheDir Absolute cache directory.\n * @param scheme Registry key (`'common'` or a variant name).\n * @returns Absolute path, e.g. `<cacheDir>/dark.style.js`.\n */\nfunction schemeFilePath(cacheDir: string, scheme: string): string {\n return path.join(cacheDir, `${scheme}.style.js`)\n}\n\n/**\n * In-memory atom union + per-scheme style-file emitter.\n *\n * Correctness under multi-worker Metro relies on `ensureProjectScanned`:\n * the FIRST `recordFile` / `writeSchemes` call in every worker drives\n * the oxide Scanner across ALL project sources and hydrates the union\n * with the complete set of candidates. Subsequent per-file\n * `recordFile` calls only layer in atoms the scan already knew about,\n * so writes are idempotent — different workers can't clobber each\n * other's scheme files with partial views.\n *\n * Per-file deltas (atom set unchanged → early return) skip\n * serialization entirely. On a theme-CSS change, `getRnwindState`\n * builds a fresh parser + builder; the next call re-runs\n * `ensureProjectScanned` against the new parser, producing scheme\n * files with the new theme values.\n */\nclass UnionBuilder {\n private readonly cacheDir: string\n private readonly parser: TailwindParser\n private readonly unionAtoms = new Map<string, SchemedStyle>()\n private readonly unionKeyframes = new Map<string, KeyframeBlock>()\n /**\n * Responsive breakpoints captured from the parser. Refreshed on every\n * `recordFile` / `ensureProjectScanned` so user-defined\n * `--breakpoint-*` overrides land in the manifest the next time it's\n * written. Identical for every parser call within one parser instance\n * (theme is fixed for the parser's lifetime), so storing the latest\n * snapshot is sufficient.\n */\n private breakpoints: ReadonlyMap<string, number> = new Map()\n /** file → set of atom names this file currently contributes. */\n private readonly fileAtomSets = new Map<string, Set<string>>()\n /** atom name → how many files currently contribute it (refcount). */\n private readonly atomRefCount = new Map<string, number>()\n /** scheme → last-written source SHA. Skips re-writing unchanged schemes. */\n private readonly schemeSignatures = new Map<string, string>()\n /**\n * Per-atom serialized-value cache — identity-keyed on each atom's\n * SchemedStyle reference. Carried across `writeSchemes` calls so the\n * typical \"user added one className\" FR case re-stringifies ONE atom\n * instead of all 175+. Cleared on `ensureProjectScanned` (full\n * rescan replaces every reference) and individually invalidated for\n * any atom `applyDiff` mutates.\n */\n private readonly serializedCache: AtomSerializedCache = new Map()\n /** Running count of stringify passes (cache misses). Test telemetry. */\n private serializedMissesCount = 0\n /** Set after `ensureProjectScanned` completes. */\n private projectScanned = false\n /** Promise guard so concurrent first-calls await ONE scan. */\n private pendingScan: Promise<void> | null = null\n\n constructor(cacheDir: string, parser: TailwindParser) {\n this.cacheDir = cacheDir\n this.parser = parser\n mkdirSync(this.cacheDir, { recursive: true })\n }\n\n /** Absolute path of the manifest module (`rnwind/__generated/schemes`). */\n public get manifestPath(): string {\n return path.join(this.cacheDir, MANIFEST_BASENAME)\n }\n\n /**\n * Snapshot of every source file the builder has recorded atoms for\n * this worker session. Used by `withRnwindConfig`'s CSS watcher to\n * touch `mtime` on each and nudge Metro into re-transforming them\n * with the new theme values.\n * @returns Absolute source paths.\n */\n public recordedFiles(): readonly string[] {\n return [...this.fileAtomSets.keys()]\n }\n\n /** Cumulative cache-miss count — exposed for tests to assert cache behaviour. */\n public get serializedMisses(): number {\n return this.serializedMissesCount\n }\n\n /**\n * Absolute path of one scheme's style file.\n * @param scheme Registry key.\n * @returns Absolute path.\n */\n public schemePath(scheme: string): string {\n return schemeFilePath(this.cacheDir, scheme)\n }\n\n /**\n * One-shot oxide scan + compile across every source the parser was\n * configured with. Idempotent — safe to call from any entry point.\n * Concurrent callers share the same in-flight promise.\n */\n public async ensureProjectScanned(): Promise<void> {\n if (this.projectScanned) return\n if (this.pendingScan) return this.pendingScan\n this.pendingScan = (async () => {\n const parsed = await this.parser.parseProject()\n for (const [name, style] of parsed.atoms) this.unionAtoms.set(name, style)\n for (const [name, kf] of parsed.keyframes) this.unionKeyframes.set(name, kf)\n this.breakpoints = parsed.breakpoints\n this.projectScanned = true\n })()\n try {\n await this.pendingScan\n } finally {\n this.pendingScan = null\n }\n }\n\n /**\n * Record one source file's resolved atoms + keyframes. Short-circuits\n * when the file's atom name set hasn't changed — the common case on\n * every Fast Refresh save of a file whose className literals are\n * unchanged.\n * @param file Absolute source file path.\n * @param atoms Per-atom resolved schemed styles from this transform.\n * @param keyframes Keyframe blocks referenced by this file's atoms.\n * @returns `{ changed: true }` when the union shifted (new atom name,\n * removed atom name, or new keyframe) — the transformer uses this\n * to skip the serializer + `writeSchemes` when nothing changed.\n */\n public async recordFile(\n file: string,\n atoms: ReadonlyMap<string, SchemedStyle>,\n keyframes: ReadonlyMap<string, KeyframeBlock>,\n ): Promise<{ changed: boolean }> {\n await this.ensureProjectScanned()\n const newAtomNames = new Set(atoms.keys())\n const previous = this.fileAtomSets.get(file)\n if (previous && setsEqual(previous, newAtomNames)) {\n // Atom set unchanged — skip the unionAtoms update entirely. The\n // project scan already populated them, and re-setting a fresh\n // object ref here would invalidate the per-atom serialization\n // cache on every FR save for no gain (values are identical).\n // Theme edits go through `getRnwindState` → new builder → fresh\n // scan, so stale cache is impossible.\n let keyframeAdded = false\n for (const [name, kf] of keyframes) {\n if (!this.unionKeyframes.has(name)) keyframeAdded = true\n this.unionKeyframes.set(name, kf)\n }\n return { changed: keyframeAdded }\n }\n this.applyDiff(file, newAtomNames, atoms, keyframes)\n return { changed: true }\n }\n\n /**\n * Forget one source file's contribution. Idempotent — repeated calls\n * for a file that's already dropped are no-ops. Does NOT remove the\n * atom from the union when another file (or the project scan) still\n * references it.\n * @param file Absolute source file path.\n */\n public dropFile(file: string): void {\n const previous = this.fileAtomSets.get(file)\n if (!previous) return\n for (const name of previous) {\n const count = (this.atomRefCount.get(name) ?? 0) - 1\n if (count <= 0) this.atomRefCount.delete(name)\n else this.atomRefCount.set(name, count)\n }\n this.fileAtomSets.delete(file)\n }\n\n /**\n * Serialize the union into per-scheme files + manifest, writing only\n * files whose source bytes changed. Called after every `recordFile`\n * from the transformer — and once at Metro startup via\n * `ensureFilesExist` to seed disk from the project scan alone.\n * @returns List of scheme keys whose files were rewritten (empty\n * when the union is byte-identical to the last flush).\n */\n public async writeSchemes(): Promise<{ changedSchemes: readonly string[] }> {\n await this.ensureProjectScanned()\n const sortedAtomNames = [...this.unionAtoms.keys()].toSorted((a, b) => a.localeCompare(b))\n const result = buildSchemeSources(sortedAtomNames, this.unionAtoms, this.unionKeyframes, this.serializedCache, this.breakpoints)\n this.serializedMissesCount += result.serializedMisses\n const { schemeSources, manifestSource } = result\n\n const changed: string[] = []\n for (const [scheme, source] of Object.entries(schemeSources)) {\n const signature = signatureOf(source)\n const target = schemeFilePath(this.cacheDir, scheme)\n if (this.schemeSignatures.get(scheme) === signature && existsSync(target)) continue\n if (writeIfChanged(target, source)) changed.push(scheme)\n this.schemeSignatures.set(scheme, signature)\n }\n\n const manifestSignature = signatureOf(manifestSource)\n const manifestTarget = path.join(this.cacheDir, MANIFEST_BASENAME)\n if (this.schemeSignatures.get('__manifest') !== manifestSignature || !existsSync(manifestTarget)) {\n if (writeIfChanged(manifestTarget, manifestSource)) changed.push('__manifest')\n this.schemeSignatures.set('__manifest', manifestSignature)\n }\n\n return { changedSchemes: changed }\n }\n\n /**\n * Ensure the manifest + common scheme files exist on disk so Metro's\n * resolver can SHA1 them at boot before the first transform runs.\n */\n public async ensureFilesExist(): Promise<void> {\n if (existsSync(this.manifestPath) && existsSync(schemeFilePath(this.cacheDir, 'common'))) {\n // Still trigger the scan so the in-memory union is complete; file\n // bytes may already be authoritative from a prior Metro run.\n await this.ensureProjectScanned()\n return\n }\n await this.writeSchemes()\n }\n\n /**\n * Apply one file's atom-name diff to the in-memory refcount + union.\n * @param file Source file path.\n * @param newAtoms New atom-name set for the file.\n * @param resolvedAtoms Fresh parser output — carries the resolved\n * styles for every entry in `newAtoms`.\n * @param newKeyframes Keyframes this file's atoms reference.\n */\n private applyDiff(\n file: string,\n newAtoms: ReadonlySet<string>,\n resolvedAtoms: ReadonlyMap<string, SchemedStyle>,\n newKeyframes: ReadonlyMap<string, KeyframeBlock>,\n ): void {\n const previous = this.fileAtomSets.get(file) ?? new Set<string>()\n for (const name of previous) {\n if (newAtoms.has(name)) continue\n const count = (this.atomRefCount.get(name) ?? 0) - 1\n if (count <= 0) this.atomRefCount.delete(name)\n else this.atomRefCount.set(name, count)\n // Do NOT remove `name` from `unionAtoms` — the project scan still\n // references it (orphaned atoms get reaped on the next Metro\n // cold start when the scanner re-walks disk).\n }\n for (const name of newAtoms) {\n if (!previous.has(name)) this.atomRefCount.set(name, (this.atomRefCount.get(name) ?? 0) + 1)\n // Only install the resolved style when the atom is new to the\n // union. Replacing an existing entry with a fresh parser-\n // produced object would swap the identity guard the per-atom\n // serialization cache uses and force a re-stringify for every\n // atom on every FR save. CSS edits rebuild the whole builder\n // (via `getRnwindState`) so stale values aren't possible.\n if (!this.unionAtoms.has(name)) {\n const style = resolvedAtoms.get(name)\n if (style) this.unionAtoms.set(name, style)\n }\n }\n this.fileAtomSets.set(file, new Set(newAtoms))\n for (const [name, kf] of newKeyframes) this.unionKeyframes.set(name, kf)\n }\n}\n\nexport { UnionBuilder }\n"],"names":["existsSync","readFileSync","mkdirSync","randomBytes","writeFileSync","renameSync","rmSync","createHash","buildSchemeSources"],"mappings":";;;;;;;AAMA;AACA,MAAM,iBAAiB,GAAG,YAAY;AAEtC;;;;;;;AAOG;AACH,SAAS,cAAc,CAAC,MAAc,EAAE,OAAe,EAAA;AACrD,IAAA,IAAIA,kBAAU,CAAC,MAAM,CAAC,EAAE;AACtB,QAAA,IAAI;AACF,YAA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5F,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBAC9B,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC;AACrC,gBAAA,IAAI,KAAK;oBAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;YAC7C;QACF;AACA,QAAA,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9C,QAAA,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,YAAY;YAAE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAC1E;AACD;;;;"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { KeyframeBlock, SchemedStyle, TailwindParser } from '../parser';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory atom union + per-scheme style-file emitter.
|
|
4
|
+
*
|
|
5
|
+
* Correctness under multi-worker Metro relies on `ensureProjectScanned`:
|
|
6
|
+
* the FIRST `recordFile` / `writeSchemes` call in every worker drives
|
|
7
|
+
* the oxide Scanner across ALL project sources and hydrates the union
|
|
8
|
+
* with the complete set of candidates. Subsequent per-file
|
|
9
|
+
* `recordFile` calls only layer in atoms the scan already knew about,
|
|
10
|
+
* so writes are idempotent — different workers can't clobber each
|
|
11
|
+
* other's scheme files with partial views.
|
|
12
|
+
*
|
|
13
|
+
* Per-file deltas (atom set unchanged → early return) skip
|
|
14
|
+
* serialization entirely. On a theme-CSS change, `getRnwindState`
|
|
15
|
+
* builds a fresh parser + builder; the next call re-runs
|
|
16
|
+
* `ensureProjectScanned` against the new parser, producing scheme
|
|
17
|
+
* files with the new theme values.
|
|
18
|
+
*/
|
|
19
|
+
declare class UnionBuilder {
|
|
20
|
+
private readonly cacheDir;
|
|
21
|
+
private readonly parser;
|
|
22
|
+
private readonly unionAtoms;
|
|
23
|
+
private readonly unionKeyframes;
|
|
24
|
+
/**
|
|
25
|
+
* Responsive breakpoints captured from the parser. Refreshed on every
|
|
26
|
+
* `recordFile` / `ensureProjectScanned` so user-defined
|
|
27
|
+
* `--breakpoint-*` overrides land in the manifest the next time it's
|
|
28
|
+
* written. Identical for every parser call within one parser instance
|
|
29
|
+
* (theme is fixed for the parser's lifetime), so storing the latest
|
|
30
|
+
* snapshot is sufficient.
|
|
31
|
+
*/
|
|
32
|
+
private breakpoints;
|
|
33
|
+
/** file → set of atom names this file currently contributes. */
|
|
34
|
+
private readonly fileAtomSets;
|
|
35
|
+
/** atom name → how many files currently contribute it (refcount). */
|
|
36
|
+
private readonly atomRefCount;
|
|
37
|
+
/** scheme → last-written source SHA. Skips re-writing unchanged schemes. */
|
|
38
|
+
private readonly schemeSignatures;
|
|
39
|
+
/**
|
|
40
|
+
* Per-atom serialized-value cache — identity-keyed on each atom's
|
|
41
|
+
* SchemedStyle reference. Carried across `writeSchemes` calls so the
|
|
42
|
+
* typical "user added one className" FR case re-stringifies ONE atom
|
|
43
|
+
* instead of all 175+. Cleared on `ensureProjectScanned` (full
|
|
44
|
+
* rescan replaces every reference) and individually invalidated for
|
|
45
|
+
* any atom `applyDiff` mutates.
|
|
46
|
+
*/
|
|
47
|
+
private readonly serializedCache;
|
|
48
|
+
/** Running count of stringify passes (cache misses). Test telemetry. */
|
|
49
|
+
private serializedMissesCount;
|
|
50
|
+
/** Set after `ensureProjectScanned` completes. */
|
|
51
|
+
private projectScanned;
|
|
52
|
+
/** Promise guard so concurrent first-calls await ONE scan. */
|
|
53
|
+
private pendingScan;
|
|
54
|
+
constructor(cacheDir: string, parser: TailwindParser);
|
|
55
|
+
/** Absolute path of the manifest module (`rnwind/__generated/schemes`). */
|
|
56
|
+
get manifestPath(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Snapshot of every source file the builder has recorded atoms for
|
|
59
|
+
* this worker session. Used by `withRnwindConfig`'s CSS watcher to
|
|
60
|
+
* touch `mtime` on each and nudge Metro into re-transforming them
|
|
61
|
+
* with the new theme values.
|
|
62
|
+
* @returns Absolute source paths.
|
|
63
|
+
*/
|
|
64
|
+
recordedFiles(): readonly string[];
|
|
65
|
+
/** Cumulative cache-miss count — exposed for tests to assert cache behaviour. */
|
|
66
|
+
get serializedMisses(): number;
|
|
67
|
+
/**
|
|
68
|
+
* Absolute path of one scheme's style file.
|
|
69
|
+
* @param scheme Registry key.
|
|
70
|
+
* @returns Absolute path.
|
|
71
|
+
*/
|
|
72
|
+
schemePath(scheme: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* One-shot oxide scan + compile across every source the parser was
|
|
75
|
+
* configured with. Idempotent — safe to call from any entry point.
|
|
76
|
+
* Concurrent callers share the same in-flight promise.
|
|
77
|
+
*/
|
|
78
|
+
ensureProjectScanned(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Record one source file's resolved atoms + keyframes. Short-circuits
|
|
81
|
+
* when the file's atom name set hasn't changed — the common case on
|
|
82
|
+
* every Fast Refresh save of a file whose className literals are
|
|
83
|
+
* unchanged.
|
|
84
|
+
* @param file Absolute source file path.
|
|
85
|
+
* @param atoms Per-atom resolved schemed styles from this transform.
|
|
86
|
+
* @param keyframes Keyframe blocks referenced by this file's atoms.
|
|
87
|
+
* @returns `{ changed: true }` when the union shifted (new atom name,
|
|
88
|
+
* removed atom name, or new keyframe) — the transformer uses this
|
|
89
|
+
* to skip the serializer + `writeSchemes` when nothing changed.
|
|
90
|
+
*/
|
|
91
|
+
recordFile(file: string, atoms: ReadonlyMap<string, SchemedStyle>, keyframes: ReadonlyMap<string, KeyframeBlock>): Promise<{
|
|
92
|
+
changed: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Forget one source file's contribution. Idempotent — repeated calls
|
|
96
|
+
* for a file that's already dropped are no-ops. Does NOT remove the
|
|
97
|
+
* atom from the union when another file (or the project scan) still
|
|
98
|
+
* references it.
|
|
99
|
+
* @param file Absolute source file path.
|
|
100
|
+
*/
|
|
101
|
+
dropFile(file: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Serialize the union into per-scheme files + manifest, writing only
|
|
104
|
+
* files whose source bytes changed. Called after every `recordFile`
|
|
105
|
+
* from the transformer — and once at Metro startup via
|
|
106
|
+
* `ensureFilesExist` to seed disk from the project scan alone.
|
|
107
|
+
* @returns List of scheme keys whose files were rewritten (empty
|
|
108
|
+
* when the union is byte-identical to the last flush).
|
|
109
|
+
*/
|
|
110
|
+
writeSchemes(): Promise<{
|
|
111
|
+
changedSchemes: readonly string[];
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Ensure the manifest + common scheme files exist on disk so Metro's
|
|
115
|
+
* resolver can SHA1 them at boot before the first transform runs.
|
|
116
|
+
*/
|
|
117
|
+
ensureFilesExist(): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Apply one file's atom-name diff to the in-memory refcount + union.
|
|
120
|
+
* @param file Source file path.
|
|
121
|
+
* @param newAtoms New atom-name set for the file.
|
|
122
|
+
* @param resolvedAtoms Fresh parser output — carries the resolved
|
|
123
|
+
* styles for every entry in `newAtoms`.
|
|
124
|
+
* @param newKeyframes Keyframes this file's atoms reference.
|
|
125
|
+
*/
|
|
126
|
+
private applyDiff;
|
|
127
|
+
}
|
|
128
|
+
export { UnionBuilder };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolved values for every CSS custom property in one theme scheme.
|
|
3
|
+
* Keys are the raw custom-property names (e.g. `--color-primary`) as they
|
|
4
|
+
* appear in the theme CSS. Values are the string / number primitives the
|
|
5
|
+
* parser emits after Tailwind compile + lightningcss walk.
|
|
6
|
+
*/
|
|
7
|
+
export type ThemeTable = Record<string, string | number>;
|
|
8
|
+
/**
|
|
9
|
+
* Map from scheme name to its resolved {@link ThemeTable}. The scheme name
|
|
10
|
+
* matches the identifier the user declared in `@variant <name> { ... }` —
|
|
11
|
+
* `'light'`, `'dark'`, `'brand'`, etc. A synthetic `'base'` key carries
|
|
12
|
+
* tokens declared outside any variant block.
|
|
13
|
+
*/
|
|
14
|
+
export type ThemeTables = Record<string, ThemeTable>;
|