rnwind 0.0.1 → 0.0.2
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 +164 -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 +100 -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 +96 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +48 -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 +156 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +61 -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 +414 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +61 -0
- package/lib/cjs/core/parser/tokens.cjs +304 -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 +1567 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +194 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +93 -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 +397 -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 +251 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +72 -0
- package/lib/cjs/metro/transform-ast.cjs +1255 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +73 -0
- package/lib/cjs/metro/transformer.cjs +345 -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 +57 -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 +162 -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 +98 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +48 -0
- package/lib/esm/core/parser/length.mjs +90 -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 +61 -0
- package/lib/esm/core/parser/shorthand.mjs +148 -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 +61 -0
- package/lib/esm/core/parser/theme-vars.mjs +409 -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 +298 -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 +194 -0
- package/lib/esm/core/parser/tw-parser.mjs +1565 -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 +91 -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 +395 -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 +72 -0
- package/lib/esm/metro/state.mjs +243 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +73 -0
- package/lib/esm/metro/transform-ast.mjs +1234 -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 +322 -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 +57 -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 +79 -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 +157 -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 +92 -0
- package/src/core/parser/length.ts +100 -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 +152 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +412 -0
- package/src/core/parser/tokens.ts +286 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1709 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +83 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +442 -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 +257 -0
- package/src/metro/transform-ast.ts +1498 -0
- package/src/metro/transformer.ts +347 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +229 -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,72 @@
|
|
|
1
|
+
import { UnionBuilder } from '../core/style-builder';
|
|
2
|
+
import { TailwindParser } from '../core/parser';
|
|
3
|
+
/**
|
|
4
|
+
* Worker-local state. Lazy-initialised on first access so files that
|
|
5
|
+
* bypass the transform don't pay for construction.
|
|
6
|
+
*/
|
|
7
|
+
export interface RnwindState {
|
|
8
|
+
parser: TailwindParser;
|
|
9
|
+
builder: UnionBuilder;
|
|
10
|
+
themeCss: string;
|
|
11
|
+
themeHash: string;
|
|
12
|
+
projectRoot: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Publish the theme CSS path + cache dir to the environment so worker
|
|
16
|
+
* subprocesses (spawned by Metro once `babelTransformerPath` is set)
|
|
17
|
+
* can rebuild the same state without re-reading the Metro config.
|
|
18
|
+
* @param cssEntryFile Absolute path to the user's theme CSS.
|
|
19
|
+
* @param cacheDir Absolute path to the cache dir (`.rnwind`).
|
|
20
|
+
* @param watchFolders
|
|
21
|
+
* @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
|
|
22
|
+
*/
|
|
23
|
+
export declare function configureRnwindState(cssEntryFile: string, cacheDir: string, watchFolders?: readonly string[], classNamePrefixes?: readonly string[]): void;
|
|
24
|
+
/**
|
|
25
|
+
* Read the caller-configured extra className prefixes out of the
|
|
26
|
+
* worker environment. Returns an empty array when unset — the
|
|
27
|
+
* transformer applies the built-in `contentContainer` default on top
|
|
28
|
+
* either way.
|
|
29
|
+
* @returns User-supplied extra prefixes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getClassNamePrefixes(): readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* Fetch (or build) the worker-local rnwind state. Re-reads the theme
|
|
34
|
+
* CSS hash on every call: if the user edited `global.css` while Metro
|
|
35
|
+
* is running, the cached state is dropped and a fresh parser + ledger
|
|
36
|
+
* is built. Combined with the `getCacheKey()` export on the
|
|
37
|
+
* transformer (which folds the same hash into Metro's per-file cache
|
|
38
|
+
* key) every CSS edit produces a full, correct re-bundle.
|
|
39
|
+
* @param projectRoot
|
|
40
|
+
* @returns The live rnwind state.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getRnwindState(projectRoot: string): RnwindState;
|
|
43
|
+
/**
|
|
44
|
+
* Compute the rnwind cache-key suffix Metro mixes into every per-file
|
|
45
|
+
* transform cache entry via the transformer's `getCacheKey()` export.
|
|
46
|
+
* Includes the CSS path + its current content hash + the rnwind
|
|
47
|
+
* library fingerprint, so any edit to `global.css` OR a library
|
|
48
|
+
* upgrade flips the cache key and forces Metro to re-run the
|
|
49
|
+
* transformer.
|
|
50
|
+
* @returns Deterministic string suitable for appending to Metro's cache key.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getRnwindCacheKey(): string;
|
|
53
|
+
/** Drop the cached state — call after editing the theme CSS. */
|
|
54
|
+
export declare function resetRnwindState(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Drop cached state, rebuild parser/builder with the fresh CSS, rescan
|
|
57
|
+
* the project, and rewrite every scheme file on disk. This is what
|
|
58
|
+
* `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
|
|
59
|
+
* propagate to the app via Metro's HMR — without this, the CSS-as-JS
|
|
60
|
+
* module would re-emit `export {}` whose bytes never change, so Metro
|
|
61
|
+
* would never invalidate downstream modules.
|
|
62
|
+
* @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
|
|
63
|
+
*/
|
|
64
|
+
export declare function onThemeChange(projectRoot: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve the on-disk path of the scheme manifest module for the
|
|
67
|
+
* resolver. The manifest eager-imports `common.style.js` and
|
|
68
|
+
* lazy-requires each variant scheme; SchemeProvider calls its
|
|
69
|
+
* `ensureSchemeLoaded` export to trigger per-scheme requires.
|
|
70
|
+
* @returns Absolute path to `<cacheDir>/schemes.js`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function manifestPathFor(): string;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { UnionBuilder } from '../core/style-builder/union-builder.mjs';
|
|
5
|
+
import { TailwindParser } from '../core/parser/tw-parser.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default oxide Scanner globs — walk every JS/TS source under the
|
|
9
|
+
* project root AND every monorepo watch folder, excluding
|
|
10
|
+
* `node_modules` and rnwind's own cache dir so we don't rescan
|
|
11
|
+
* generated scheme files.
|
|
12
|
+
*
|
|
13
|
+
* Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface
|
|
14
|
+
* sibling package roots as `metroConfig.watchFolders`. Every folder
|
|
15
|
+
* Metro watches must also be scanned so atoms declared in shared UI
|
|
16
|
+
* packages make it into the union — without this, only the app's
|
|
17
|
+
* own files would be scanned and every UI-package atom would resolve
|
|
18
|
+
* to `undefined` at runtime.
|
|
19
|
+
* @param projectRoot Absolute project root.
|
|
20
|
+
* @param cacheDir Absolute rnwind cache dir (to exclude).
|
|
21
|
+
* @param watchFolders Extra monorepo roots Metro is watching.
|
|
22
|
+
* @returns Scanner sources suitable for `parser.parseProject()`.
|
|
23
|
+
*/
|
|
24
|
+
function defaultSources(projectRoot, cacheDir, watchFolders) {
|
|
25
|
+
const cacheBaseName = path.basename(cacheDir);
|
|
26
|
+
const roots = new Set([projectRoot, ...watchFolders]);
|
|
27
|
+
const sources = [];
|
|
28
|
+
for (const root of roots) {
|
|
29
|
+
sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true });
|
|
30
|
+
}
|
|
31
|
+
return sources;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read monorepo watch-folder paths out of the worker environment.
|
|
35
|
+
* Empty array when the host isn't a monorepo.
|
|
36
|
+
* @returns Absolute paths Metro also watches (sibling packages).
|
|
37
|
+
*/
|
|
38
|
+
function readWatchFolders() {
|
|
39
|
+
const raw = process.env[WATCH_FOLDERS_ENV];
|
|
40
|
+
if (!raw || raw.length === 0)
|
|
41
|
+
return [];
|
|
42
|
+
return raw.split('\0').filter((entry) => entry.length > 0);
|
|
43
|
+
}
|
|
44
|
+
/** Env var Metro workers read to locate the theme CSS on disk. */
|
|
45
|
+
const CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE';
|
|
46
|
+
/** Env var Metro workers read to locate the cache directory (`.rnwind`). */
|
|
47
|
+
const CACHE_DIR_ENV = 'RNWIND_CACHE_DIR';
|
|
48
|
+
/** Env var carrying `watchFolders` from Metro config (NUL-separated). */
|
|
49
|
+
const WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS';
|
|
50
|
+
/** Env var carrying extra className prefixes the Metro config supplied. */
|
|
51
|
+
const CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES';
|
|
52
|
+
/** Memoised library fingerprint — read once per worker process. */
|
|
53
|
+
let libraryFingerprint;
|
|
54
|
+
/** Live state shared across one Metro transform worker. */
|
|
55
|
+
let cached = null;
|
|
56
|
+
/**
|
|
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.
|
|
61
|
+
* @param cssPath Absolute CSS path.
|
|
62
|
+
* @returns 16-char hex content hash.
|
|
63
|
+
*/
|
|
64
|
+
function readThemeHashFor(cssPath) {
|
|
65
|
+
if (!existsSync(cssPath))
|
|
66
|
+
return 'missing';
|
|
67
|
+
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);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return 'missing';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Hash a small set of rnwind library files whose changes affect the
|
|
78
|
+
* generated transform output. When the library is rebuilt (workspace
|
|
79
|
+
* dev OR npm install of a new version) the file bytes change, the
|
|
80
|
+
* fingerprint rotates, and Metro's transform cache invalidates.
|
|
81
|
+
*
|
|
82
|
+
* Includes the JSX rewriter (`transform-ast`) alongside the parser /
|
|
83
|
+
* style-builder so a change to the transformer — e.g. renaming the
|
|
84
|
+
* injected context hook — invalidates every stale per-file cache entry
|
|
85
|
+
* on the next dev run. Without this, a user upgrading rnwind in-place
|
|
86
|
+
* would keep loading the old transformed bytes; React-refresh would
|
|
87
|
+
* then preserve fiber state across the version bump and the rendered
|
|
88
|
+
* hook list could shift, surfacing as "change in the order of Hooks"
|
|
89
|
+
* runtime errors.
|
|
90
|
+
* Memoised — read once per worker process.
|
|
91
|
+
* @returns 16-char hex fingerprint.
|
|
92
|
+
*/
|
|
93
|
+
function getLibraryFingerprint() {
|
|
94
|
+
if (libraryFingerprint !== undefined)
|
|
95
|
+
return libraryFingerprint;
|
|
96
|
+
const here = path.dirname(__filename);
|
|
97
|
+
const candidates = [
|
|
98
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),
|
|
99
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),
|
|
100
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),
|
|
101
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),
|
|
102
|
+
path.resolve(here, 'transform-ast.mjs'),
|
|
103
|
+
path.resolve(here, 'transform-ast.cjs'),
|
|
104
|
+
path.resolve(here, 'transformer.mjs'),
|
|
105
|
+
path.resolve(here, 'transformer.cjs'),
|
|
106
|
+
// Source-tree fallback for tests + workspace dev (no built lib yet).
|
|
107
|
+
path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),
|
|
108
|
+
path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),
|
|
109
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),
|
|
110
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),
|
|
111
|
+
];
|
|
112
|
+
const hash = createHash('sha256');
|
|
113
|
+
let included = 0;
|
|
114
|
+
for (const file of candidates) {
|
|
115
|
+
if (!existsSync(file))
|
|
116
|
+
continue;
|
|
117
|
+
try {
|
|
118
|
+
hash.update(readFileSync(file));
|
|
119
|
+
included += 1;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Unreadable file — skip; fingerprint still derives from whatever WE could read.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16);
|
|
126
|
+
return libraryFingerprint;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Publish the theme CSS path + cache dir to the environment so worker
|
|
130
|
+
* subprocesses (spawned by Metro once `babelTransformerPath` is set)
|
|
131
|
+
* can rebuild the same state without re-reading the Metro config.
|
|
132
|
+
* @param cssEntryFile Absolute path to the user's theme CSS.
|
|
133
|
+
* @param cacheDir Absolute path to the cache dir (`.rnwind`).
|
|
134
|
+
* @param watchFolders
|
|
135
|
+
* @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
|
|
136
|
+
*/
|
|
137
|
+
function configureRnwindState(cssEntryFile, cacheDir, watchFolders = [], classNamePrefixes) {
|
|
138
|
+
process.env[CSS_ENTRY_ENV] = cssEntryFile;
|
|
139
|
+
process.env[CACHE_DIR_ENV] = cacheDir;
|
|
140
|
+
if (watchFolders.length === 0) {
|
|
141
|
+
delete process.env[WATCH_FOLDERS_ENV];
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\0');
|
|
145
|
+
}
|
|
146
|
+
if (!classNamePrefixes || classNamePrefixes.length === 0) {
|
|
147
|
+
delete process.env[CLASSNAME_PREFIXES_ENV];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',');
|
|
151
|
+
}
|
|
152
|
+
cached = null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Read the caller-configured extra className prefixes out of the
|
|
156
|
+
* worker environment. Returns an empty array when unset — the
|
|
157
|
+
* transformer applies the built-in `contentContainer` default on top
|
|
158
|
+
* either way.
|
|
159
|
+
* @returns User-supplied extra prefixes.
|
|
160
|
+
*/
|
|
161
|
+
function getClassNamePrefixes() {
|
|
162
|
+
const raw = process.env[CLASSNAME_PREFIXES_ENV];
|
|
163
|
+
if (!raw || raw.length === 0)
|
|
164
|
+
return [];
|
|
165
|
+
return raw.split(',').filter((entry) => entry.length > 0);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Fetch (or build) the worker-local rnwind state. Re-reads the theme
|
|
169
|
+
* CSS hash on every call: if the user edited `global.css` while Metro
|
|
170
|
+
* is running, the cached state is dropped and a fresh parser + ledger
|
|
171
|
+
* is built. Combined with the `getCacheKey()` export on the
|
|
172
|
+
* transformer (which folds the same hash into Metro's per-file cache
|
|
173
|
+
* key) every CSS edit produces a full, correct re-bundle.
|
|
174
|
+
* @param projectRoot
|
|
175
|
+
* @returns The live rnwind state.
|
|
176
|
+
*/
|
|
177
|
+
function getRnwindState(projectRoot) {
|
|
178
|
+
const cssEntry = process.env[CSS_ENTRY_ENV];
|
|
179
|
+
const cacheDir = process.env[CACHE_DIR_ENV];
|
|
180
|
+
if (!cssEntry)
|
|
181
|
+
throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?');
|
|
182
|
+
if (!cacheDir)
|
|
183
|
+
throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?');
|
|
184
|
+
const currentHash = readThemeHashFor(cssEntry);
|
|
185
|
+
if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot)
|
|
186
|
+
return cached;
|
|
187
|
+
const themeCss = readFileSync(cssEntry, 'utf8');
|
|
188
|
+
const parser = new TailwindParser({
|
|
189
|
+
themeCss,
|
|
190
|
+
sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
|
|
191
|
+
});
|
|
192
|
+
const builder = new UnionBuilder(cacheDir, parser);
|
|
193
|
+
cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot };
|
|
194
|
+
return cached;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Compute the rnwind cache-key suffix Metro mixes into every per-file
|
|
198
|
+
* transform cache entry via the transformer's `getCacheKey()` export.
|
|
199
|
+
* Includes the CSS path + its current content hash + the rnwind
|
|
200
|
+
* library fingerprint, so any edit to `global.css` OR a library
|
|
201
|
+
* upgrade flips the cache key and forces Metro to re-run the
|
|
202
|
+
* transformer.
|
|
203
|
+
* @returns Deterministic string suitable for appending to Metro's cache key.
|
|
204
|
+
*/
|
|
205
|
+
function getRnwindCacheKey() {
|
|
206
|
+
const cssEntry = process.env[CSS_ENTRY_ENV] ?? '';
|
|
207
|
+
const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? '';
|
|
208
|
+
return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}`;
|
|
209
|
+
}
|
|
210
|
+
/** Drop the cached state — call after editing the theme CSS. */
|
|
211
|
+
function resetRnwindState() {
|
|
212
|
+
cached = null;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Drop cached state, rebuild parser/builder with the fresh CSS, rescan
|
|
216
|
+
* the project, and rewrite every scheme file on disk. This is what
|
|
217
|
+
* `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
|
|
218
|
+
* propagate to the app via Metro's HMR — without this, the CSS-as-JS
|
|
219
|
+
* module would re-emit `export {}` whose bytes never change, so Metro
|
|
220
|
+
* would never invalidate downstream modules.
|
|
221
|
+
* @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
|
|
222
|
+
*/
|
|
223
|
+
async function onThemeChange(projectRoot) {
|
|
224
|
+
resetRnwindState();
|
|
225
|
+
const state = getRnwindState(projectRoot);
|
|
226
|
+
await state.builder.writeSchemes();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Resolve the on-disk path of the scheme manifest module for the
|
|
230
|
+
* resolver. The manifest eager-imports `common.style.js` and
|
|
231
|
+
* lazy-requires each variant scheme; SchemeProvider calls its
|
|
232
|
+
* `ensureSchemeLoaded` export to trigger per-scheme requires.
|
|
233
|
+
* @returns Absolute path to `<cacheDir>/schemes.js`.
|
|
234
|
+
*/
|
|
235
|
+
function manifestPathFor() {
|
|
236
|
+
const cacheDir = process.env[CACHE_DIR_ENV];
|
|
237
|
+
if (!cacheDir)
|
|
238
|
+
throw new Error('rnwind: RNWIND_CACHE_DIR is not set');
|
|
239
|
+
return path.join(cacheDir, 'schemes.js');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { configureRnwindState, getClassNamePrefixes, getRnwindCacheKey, getRnwindState, manifestPathFor, onThemeChange, resetRnwindState };
|
|
243
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the\n * file's mtime nanoseconds (so identical content with different mtime\n * — atomic rewrites — still picks up the change). Returns `'missing'`\n * when the file can't be read so the cache key is still deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n const bytes = readFileSync(cssPath)\n const mtime = statSync(cssPath).mtimeMs.toString()\n return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = readFileSync(cssEntry, 'utf8')\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":[],"mappings":";;;;;;AAMA;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,cAAc,CAAC,WAAmB,EAAE,QAAgB,EAAE,YAA+B,EAAA;IAC5F,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC7C,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAkB,EAAE;AACjC,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA,GAAA,EAAM,aAAa,CAA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E;AAC3E,IAAA,OAAO,MAAM;AACf;AAEA;;;;;;;;AAQG;SACa,iBAAiB,GAAA;IAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE;IACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE;AAC1D,IAAA,OAAO,CAAA,OAAA,EAAU,QAAQ,CAAA,CAAA,EAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAA,KAAA,EAAQ,qBAAqB,EAAE,CAAA,KAAA,EAAQ,QAAQ,EAAE;AAC1G;AAEA;SACgB,gBAAgB,GAAA;IAC9B,MAAM,GAAG,IAAI;AACf;AAEA;;;;;;;;AAQG;AACI,eAAe,aAAa,CAAC,WAAmB,EAAA;AACrD,IAAA,gBAAgB,EAAE;AAClB,IAAA,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC;AACzC,IAAA,MAAM,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE;AACpC;AAEA;;;;;;AAMG;SACa,eAAe,GAAA;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC3C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC1C;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { File } from '@babel/types';
|
|
2
|
+
import type { GradientAtomInfo, HapticRequest } from '../core/parser';
|
|
3
|
+
/** Name of the runtime atom-registration entry point imported by the union style file. */
|
|
4
|
+
export declare const REGISTER_ATOMS = "registerAtoms";
|
|
5
|
+
/** Per-file state returned by the transformer, for the caller to integrate with the atom ledger. */
|
|
6
|
+
export interface TransformAstResult {
|
|
7
|
+
/** `true` when the AST was mutated (any `className=` rewrite landed). */
|
|
8
|
+
touched: boolean;
|
|
9
|
+
/** Atom-name arrays the transformer hoisted — one entry per unique atom set. */
|
|
10
|
+
hoistedArrays: ReadonlyMap<string, readonly string[]>;
|
|
11
|
+
/** Candidate literal texts collected from every rewritten `className`. */
|
|
12
|
+
literals: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** Inputs to {@link transformAst}. */
|
|
15
|
+
export interface TransformAstOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Module specifiers the transformer side-effect-imports at the top
|
|
18
|
+
* of each rewritten file. Today: the union `style.js` and
|
|
19
|
+
* `keyframes.js` (always two entries — see `STYLE_SPECIFIERS` in
|
|
20
|
+
* resolver.ts). Empty when the file has no atoms to register.
|
|
21
|
+
*/
|
|
22
|
+
styleSpecifiers: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Parser-surfaced gradient metadata per atom. The transformer reads
|
|
25
|
+
* this map when rewriting literal `className="..."` sites so it can
|
|
26
|
+
* strip gradient atoms out of the atom array fed to `lookupCss` and
|
|
27
|
+
* emit `colors={...} start={...} end={...}` JSX attributes consumed
|
|
28
|
+
* by `<LinearGradient>` (or any component with the expo prop shape).
|
|
29
|
+
*/
|
|
30
|
+
gradientAtoms?: ReadonlyMap<string, GradientAtomInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* Parser-surfaced haptic metadata per atom. Keys are the full class
|
|
33
|
+
* name (including any variant prefix — `haptic-light`,
|
|
34
|
+
* `active:haptic-medium`). Values are the structured
|
|
35
|
+
* {@link HapticRequest}. The transformer strips matched atoms from
|
|
36
|
+
* the className, aggregates mount requests per enclosing component,
|
|
37
|
+
* and wires press-in chains directly on the element.
|
|
38
|
+
*/
|
|
39
|
+
hapticAtoms?: ReadonlyMap<string, HapticRequest>;
|
|
40
|
+
/**
|
|
41
|
+
* Extra prop-name prefixes that turn `<prefix>ClassName="…"` into
|
|
42
|
+
* `<prefix>Style={lookupCss(…)}` with the same plumbing as the plain
|
|
43
|
+
* `className` path. The built-in `'contentContainer'` prefix is always
|
|
44
|
+
* enabled (covers ScrollView / FlatList / SectionList) — entries here
|
|
45
|
+
* are additive, not a replacement. A user-supplied `['myFunny']` yields
|
|
46
|
+
* the effective set `['contentContainer', 'myFunny']`.
|
|
47
|
+
*
|
|
48
|
+
* Prefixed rewrites never go through `<InteractiveBox>`: the targeted
|
|
49
|
+
* sub-surfaces (scroll content containers, column wrappers, etc.)
|
|
50
|
+
* can't fire press / focus events, so we always emit the inline
|
|
51
|
+
* `lookupCss(…)` call regardless of whether the expression is static
|
|
52
|
+
* or dynamic.
|
|
53
|
+
*/
|
|
54
|
+
classNamePrefixes?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Mutate an already-parsed Babel AST in place:
|
|
58
|
+
* - Rewrite every JSX `className="…"` / `className={expr}` attribute to
|
|
59
|
+
* `style={lookupCss(<ref|expr>, _s, <existingStyle>)}`. Static string
|
|
60
|
+
* literals get a module-scope `const _c_<hash> = Object.freeze(['a',
|
|
61
|
+
* 'b'])` hoist so React sees an identity-stable array across renders.
|
|
62
|
+
* - Preserve any adjacent `style={…}` prop — it becomes the third
|
|
63
|
+
* argument so user inline styles keep working (and trump atoms).
|
|
64
|
+
* - Inject `const _s = useScheme()` at the top of the enclosing
|
|
65
|
+
* function component (idempotent — one injection per component).
|
|
66
|
+
* - Prepend `import { lookupCss, useScheme } from 'rnwind'`.
|
|
67
|
+
* - Prepend a side-effect `import 'rnwind/__generated/style'` so the
|
|
68
|
+
* union registry is loaded before any hoist runs.
|
|
69
|
+
* @param ast Babel File AST (usually handed to us by Metro).
|
|
70
|
+
* @param options Extra inputs — side-effect import specifiers + parser metadata.
|
|
71
|
+
* @returns Transform outcome flags + the hoist table.
|
|
72
|
+
*/
|
|
73
|
+
export declare function transformAst(ast: File, options: TransformAstOptions): TransformAstResult;
|