rnwind 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/lib/cjs/core/normalize-classname.cjs +25 -0
  2. package/lib/cjs/core/normalize-classname.cjs.map +1 -0
  3. package/lib/cjs/core/normalize-classname.d.ts +10 -0
  4. package/lib/cjs/core/style-builder/build-style.cjs +258 -58
  5. package/lib/cjs/core/style-builder/build-style.cjs.map +1 -1
  6. package/lib/cjs/core/style-builder/build-style.d.ts +6 -1
  7. package/lib/cjs/core/style-builder/union-builder.cjs +37 -3
  8. package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
  9. package/lib/cjs/core/style-builder/union-builder.d.ts +21 -1
  10. package/lib/cjs/metro/dts.cjs +7 -16
  11. package/lib/cjs/metro/dts.cjs.map +1 -1
  12. package/lib/cjs/metro/dts.d.ts +2 -4
  13. package/lib/cjs/metro/state.cjs +30 -78
  14. package/lib/cjs/metro/state.cjs.map +1 -1
  15. package/lib/cjs/metro/state.d.ts +8 -25
  16. package/lib/cjs/metro/transformer.cjs +193 -34
  17. package/lib/cjs/metro/transformer.cjs.map +1 -1
  18. package/lib/cjs/metro/with-config.cjs +2 -2
  19. package/lib/cjs/metro/with-config.cjs.map +1 -1
  20. package/lib/cjs/metro/with-config.d.ts +11 -26
  21. package/lib/cjs/metro/wrap-imports.cjs +273 -0
  22. package/lib/cjs/metro/wrap-imports.cjs.map +1 -0
  23. package/lib/cjs/metro/wrap-imports.d.ts +26 -0
  24. package/lib/cjs/runtime/components/rnwind-provider.cjs +0 -17
  25. package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -1
  26. package/lib/cjs/runtime/components/rnwind-provider.d.ts +0 -14
  27. package/lib/cjs/runtime/hooks/use-css.cjs +16 -10
  28. package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -1
  29. package/lib/cjs/runtime/hooks/use-css.d.ts +15 -9
  30. package/lib/cjs/runtime/index.cjs +11 -13
  31. package/lib/cjs/runtime/index.cjs.map +1 -1
  32. package/lib/cjs/runtime/index.d.ts +4 -9
  33. package/lib/cjs/runtime/lookup-css.cjs +10 -0
  34. package/lib/cjs/runtime/lookup-css.cjs.map +1 -1
  35. package/lib/cjs/runtime/lookup-css.d.ts +7 -0
  36. package/lib/cjs/runtime/resolve.cjs +400 -0
  37. package/lib/cjs/runtime/resolve.cjs.map +1 -0
  38. package/lib/cjs/runtime/resolve.d.ts +66 -0
  39. package/lib/cjs/runtime/wrap.cjs +254 -0
  40. package/lib/cjs/runtime/wrap.cjs.map +1 -0
  41. package/lib/cjs/runtime/wrap.d.ts +37 -0
  42. package/lib/cjs/testing/index.cjs +81 -50
  43. package/lib/cjs/testing/index.cjs.map +1 -1
  44. package/lib/esm/core/normalize-classname.d.ts +10 -0
  45. package/lib/esm/core/normalize-classname.mjs +23 -0
  46. package/lib/esm/core/normalize-classname.mjs.map +1 -0
  47. package/lib/esm/core/style-builder/build-style.d.ts +6 -1
  48. package/lib/esm/core/style-builder/build-style.mjs +258 -58
  49. package/lib/esm/core/style-builder/build-style.mjs.map +1 -1
  50. package/lib/esm/core/style-builder/union-builder.d.ts +21 -1
  51. package/lib/esm/core/style-builder/union-builder.mjs +37 -3
  52. package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
  53. package/lib/esm/metro/dts.d.ts +2 -4
  54. package/lib/esm/metro/dts.mjs +7 -16
  55. package/lib/esm/metro/dts.mjs.map +1 -1
  56. package/lib/esm/metro/state.d.ts +8 -25
  57. package/lib/esm/metro/state.mjs +30 -76
  58. package/lib/esm/metro/state.mjs.map +1 -1
  59. package/lib/esm/metro/transformer.mjs +194 -35
  60. package/lib/esm/metro/transformer.mjs.map +1 -1
  61. package/lib/esm/metro/with-config.d.ts +11 -26
  62. package/lib/esm/metro/with-config.mjs +2 -2
  63. package/lib/esm/metro/with-config.mjs.map +1 -1
  64. package/lib/esm/metro/wrap-imports.d.ts +26 -0
  65. package/lib/esm/metro/wrap-imports.mjs +250 -0
  66. package/lib/esm/metro/wrap-imports.mjs.map +1 -0
  67. package/lib/esm/runtime/components/rnwind-provider.d.ts +0 -14
  68. package/lib/esm/runtime/components/rnwind-provider.mjs +1 -17
  69. package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -1
  70. package/lib/esm/runtime/hooks/use-css.d.ts +15 -9
  71. package/lib/esm/runtime/hooks/use-css.mjs +16 -10
  72. package/lib/esm/runtime/hooks/use-css.mjs.map +1 -1
  73. package/lib/esm/runtime/index.d.ts +4 -9
  74. package/lib/esm/runtime/index.mjs +4 -4
  75. package/lib/esm/runtime/index.mjs.map +1 -1
  76. package/lib/esm/runtime/lookup-css.d.ts +7 -0
  77. package/lib/esm/runtime/lookup-css.mjs +10 -1
  78. package/lib/esm/runtime/lookup-css.mjs.map +1 -1
  79. package/lib/esm/runtime/resolve.d.ts +66 -0
  80. package/lib/esm/runtime/resolve.mjs +393 -0
  81. package/lib/esm/runtime/resolve.mjs.map +1 -0
  82. package/lib/esm/runtime/wrap.d.ts +37 -0
  83. package/lib/esm/runtime/wrap.mjs +251 -0
  84. package/lib/esm/runtime/wrap.mjs.map +1 -0
  85. package/lib/esm/testing/index.mjs +84 -53
  86. package/lib/esm/testing/index.mjs.map +1 -1
  87. package/package.json +2 -1
  88. package/src/core/normalize-classname.ts +19 -0
  89. package/src/core/style-builder/build-style.ts +286 -55
  90. package/src/core/style-builder/union-builder.ts +36 -3
  91. package/src/metro/dts.ts +7 -19
  92. package/src/metro/state.ts +29 -74
  93. package/src/metro/transformer.ts +190 -34
  94. package/src/metro/with-config.ts +13 -28
  95. package/src/metro/wrap-imports.ts +260 -0
  96. package/src/runtime/components/rnwind-provider.tsx +0 -17
  97. package/src/runtime/hooks/use-css.ts +17 -11
  98. package/src/runtime/index.ts +3 -26
  99. package/src/runtime/lookup-css.ts +10 -0
  100. package/src/runtime/resolve.ts +438 -0
  101. package/src/runtime/wrap.tsx +267 -0
  102. package/src/testing/index.ts +106 -56
  103. package/lib/cjs/core/parser/text-truncate.cjs +0 -78
  104. package/lib/cjs/core/parser/text-truncate.cjs.map +0 -1
  105. package/lib/cjs/metro/transform-ast.cjs +0 -1472
  106. package/lib/cjs/metro/transform-ast.cjs.map +0 -1
  107. package/lib/cjs/metro/transform-ast.d.ts +0 -88
  108. package/lib/cjs/runtime/haptics.cjs +0 -113
  109. package/lib/cjs/runtime/haptics.cjs.map +0 -1
  110. package/lib/cjs/runtime/haptics.d.ts +0 -48
  111. package/lib/cjs/runtime/interactive-box.cjs +0 -35
  112. package/lib/cjs/runtime/interactive-box.cjs.map +0 -1
  113. package/lib/cjs/runtime/interactive-box.d.ts +0 -40
  114. package/lib/esm/core/parser/text-truncate.mjs +0 -75
  115. package/lib/esm/core/parser/text-truncate.mjs.map +0 -1
  116. package/lib/esm/metro/transform-ast.d.ts +0 -88
  117. package/lib/esm/metro/transform-ast.mjs +0 -1451
  118. package/lib/esm/metro/transform-ast.mjs.map +0 -1
  119. package/lib/esm/runtime/haptics.d.ts +0 -48
  120. package/lib/esm/runtime/haptics.mjs +0 -110
  121. package/lib/esm/runtime/haptics.mjs.map +0 -1
  122. package/lib/esm/runtime/interactive-box.d.ts +0 -40
  123. package/lib/esm/runtime/interactive-box.mjs +0 -33
  124. package/lib/esm/runtime/interactive-box.mjs.map +0 -1
  125. package/src/metro/transform-ast.ts +0 -1729
  126. package/src/runtime/haptics.ts +0 -120
  127. package/src/runtime/interactive-box.tsx +0 -57
@@ -1,75 +0,0 @@
1
- /**
2
- * Text-truncate atom detector.
3
- *
4
- * React Native's `<Text>` exposes two props that cover every case
5
- * Tailwind's text-truncation utilities express:
6
- *
7
- * numberOfLines — clamp after N lines (1 for single-line ellipsis)
8
- * ellipsizeMode — 'tail' (ellipsis) or 'clip' at the truncation point
9
- *
10
- * rnwind treats the Tailwind classes as **metadata**: the transformer
11
- * strips the truncate atoms from the JSX site's className and emits
12
- * `numberOfLines={N}` / `ellipsizeMode="tail"` props on the element.
13
- *
14
- * Covered atoms:
15
- * truncate → { numberOfLines: 1, ellipsizeMode: 'tail' }
16
- * text-ellipsis → { ellipsizeMode: 'tail' }
17
- * text-clip → { ellipsizeMode: 'clip' }
18
- * line-clamp-<N> → { numberOfLines: <N> }
19
- * line-clamp-none → { numberOfLines: 0 } (reset — overrides prior)
20
- *
21
- * Detection is pure name matching — no CSS inspection — because every
22
- * relevant piece of data lives in the class name itself.
23
- */
24
- /** Regex matching `line-clamp-<N>` with a positive-integer N. */
25
- const LINE_CLAMP_RE = /^line-clamp-(\d+)$/;
26
- /** Regex matching Tailwind v4's `line-clamp-[<value>]` arbitrary form. */
27
- const LINE_CLAMP_ARBITRARY_RE = /^line-clamp-\[([^\]]+)\]$/;
28
- /**
29
- * Inspect one class-name token and return the text-truncate metadata it
30
- * contributes, or `null` when the atom isn't a truncate utility.
31
- * @param atom Single class-name token (no variant prefix).
32
- * @returns The atom's contribution, or null.
33
- */
34
- function detectTextTruncate(atom) {
35
- if (atom === 'truncate')
36
- return { numberOfLines: 1, ellipsizeMode: 'tail' };
37
- if (atom === 'text-ellipsis')
38
- return { ellipsizeMode: 'tail' };
39
- if (atom === 'text-clip')
40
- return { ellipsizeMode: 'clip' };
41
- if (atom === 'line-clamp-none')
42
- return { numberOfLines: 0 };
43
- const numeric = LINE_CLAMP_RE.exec(atom);
44
- if (numeric)
45
- return { numberOfLines: Number(numeric[1]) };
46
- const arbitrary = LINE_CLAMP_ARBITRARY_RE.exec(atom);
47
- if (arbitrary) {
48
- const n = Number.parseInt(arbitrary[1], 10);
49
- if (Number.isFinite(n) && n >= 0)
50
- return { numberOfLines: n };
51
- }
52
- return null;
53
- }
54
- /**
55
- * Fast pre-check — returns true when ANY atom in the list could be a
56
- * truncate utility, false when none can. Lets callers skip the
57
- * allocation of the merge pass for the common "no truncate" case.
58
- * @param atoms Tokenised atom list from a literal className.
59
- * @returns Whether to run the full per-atom detection.
60
- */
61
- function mayContainTextTruncate(atoms) {
62
- for (const atom of atoms) {
63
- if (atom === 'truncate' ||
64
- atom === 'text-ellipsis' ||
65
- atom === 'text-clip' ||
66
- atom === 'line-clamp-none' ||
67
- atom.startsWith('line-clamp-')) {
68
- return true;
69
- }
70
- }
71
- return false;
72
- }
73
-
74
- export { detectTextTruncate, mayContainTextTruncate };
75
- //# sourceMappingURL=text-truncate.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-truncate.mjs","sources":["../../../../../src/core/parser/text-truncate.ts"],"sourcesContent":["/**\n * Text-truncate atom detector.\n *\n * React Native's `<Text>` exposes two props that cover every case\n * Tailwind's text-truncation utilities express:\n *\n * numberOfLines — clamp after N lines (1 for single-line ellipsis)\n * ellipsizeMode — 'tail' (ellipsis) or 'clip' at the truncation point\n *\n * rnwind treats the Tailwind classes as **metadata**: the transformer\n * strips the truncate atoms from the JSX site's className and emits\n * `numberOfLines={N}` / `ellipsizeMode=\"tail\"` props on the element.\n *\n * Covered atoms:\n * truncate → { numberOfLines: 1, ellipsizeMode: 'tail' }\n * text-ellipsis → { ellipsizeMode: 'tail' }\n * text-clip → { ellipsizeMode: 'clip' }\n * line-clamp-<N> → { numberOfLines: <N> }\n * line-clamp-none → { numberOfLines: 0 } (reset — overrides prior)\n *\n * Detection is pure name matching — no CSS inspection — because every\n * relevant piece of data lives in the class name itself.\n */\n\n/** Text-truncate metadata produced by a single atom. */\nexport interface TextTruncateInfo {\n readonly numberOfLines?: number\n readonly ellipsizeMode?: 'tail' | 'clip'\n}\n\n/** Regex matching `line-clamp-<N>` with a positive-integer N. */\nconst LINE_CLAMP_RE = /^line-clamp-(\\d+)$/\n/** Regex matching Tailwind v4's `line-clamp-[<value>]` arbitrary form. */\nconst LINE_CLAMP_ARBITRARY_RE = /^line-clamp-\\[([^\\]]+)\\]$/\n\n/**\n * Inspect one class-name token and return the text-truncate metadata it\n * contributes, or `null` when the atom isn't a truncate utility.\n * @param atom Single class-name token (no variant prefix).\n * @returns The atom's contribution, or null.\n */\nfunction detectTextTruncate(atom: string): TextTruncateInfo | null {\n if (atom === 'truncate') return { numberOfLines: 1, ellipsizeMode: 'tail' }\n if (atom === 'text-ellipsis') return { ellipsizeMode: 'tail' }\n if (atom === 'text-clip') return { ellipsizeMode: 'clip' }\n if (atom === 'line-clamp-none') return { numberOfLines: 0 }\n const numeric = LINE_CLAMP_RE.exec(atom)\n if (numeric) return { numberOfLines: Number(numeric[1]) }\n const arbitrary = LINE_CLAMP_ARBITRARY_RE.exec(atom)\n if (arbitrary) {\n const n = Number.parseInt(arbitrary[1]!, 10)\n if (Number.isFinite(n) && n >= 0) return { numberOfLines: n }\n }\n return null\n}\n\n/**\n * Fast pre-check — returns true when ANY atom in the list could be a\n * truncate utility, false when none can. Lets callers skip the\n * allocation of the merge pass for the common \"no truncate\" case.\n * @param atoms Tokenised atom list from a literal className.\n * @returns Whether to run the full per-atom detection.\n */\nfunction mayContainTextTruncate(atoms: readonly string[]): boolean {\n for (const atom of atoms) {\n if (\n atom === 'truncate' ||\n atom === 'text-ellipsis' ||\n atom === 'text-clip' ||\n atom === 'line-clamp-none' ||\n atom.startsWith('line-clamp-')\n ) {\n return true\n }\n }\n return false\n}\n\nexport { detectTextTruncate, mayContainTextTruncate }\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AAQH;AACA,MAAM,aAAa,GAAG,oBAAoB;AAC1C;AACA,MAAM,uBAAuB,GAAG,2BAA2B;AAE3D;;;;;AAKG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAA;IACtC,IAAI,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE;IAC3E,IAAI,IAAI,KAAK,eAAe;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE;IAC9D,IAAI,IAAI,KAAK,WAAW;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE;IAC1D,IAAI,IAAI,KAAK,iBAAiB;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE;IAC3D,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;AACxC,IAAA,IAAI,OAAO;QAAE,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;IACzD,MAAM,SAAS,GAAG,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;IACpD,IAAI,SAAS,EAAE;AACb,QAAA,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC;QAC5C,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE;IAC/D;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;AAMG;AACH,SAAS,sBAAsB,CAAC,KAAwB,EAAA;AACtD,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,IACE,IAAI,KAAK,UAAU;AACnB,YAAA,IAAI,KAAK,eAAe;AACxB,YAAA,IAAI,KAAK,WAAW;AACpB,YAAA,IAAI,KAAK,iBAAiB;AAC1B,YAAA,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAC9B;AACA,YAAA,OAAO,IAAI;QACb;IACF;AACA,IAAA,OAAO,KAAK;AACd;;;;"}
@@ -1,88 +0,0 @@
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
- * Extra module specifiers whose JSX exports the transformer should
57
- * treat as hosts (rewrite `className` → `style` at compile time).
58
- * Merged with the built-in {@link DEFAULT_HOST_SOURCES} list. Use
59
- * this for design-system packages whose primitives wrap RN hosts and
60
- * accept `style` directly.
61
- */
62
- hostSources?: readonly string[];
63
- /**
64
- * Extra component names (verbatim, including dotted member access
65
- * like `'Animated.View'`) the transformer should treat as hosts. Use
66
- * this for one-off escape-hatches that aren't matchable by source —
67
- * e.g. you alias `View as MyBox` and want the compile-time path.
68
- */
69
- hostComponents?: readonly string[];
70
- }
71
- /**
72
- * Mutate an already-parsed Babel AST in place:
73
- * - Rewrite every JSX `className="…"` / `className={expr}` attribute to
74
- * `style={lookupCss(<ref|expr>, _s, <existingStyle>)}`. Static string
75
- * literals get a module-scope `const _c_<hash> = Object.freeze(['a',
76
- * 'b'])` hoist so React sees an identity-stable array across renders.
77
- * - Preserve any adjacent `style={…}` prop — it becomes the third
78
- * argument so user inline styles keep working (and trump atoms).
79
- * - Inject `const _s = useScheme()` at the top of the enclosing
80
- * function component (idempotent — one injection per component).
81
- * - Prepend `import { lookupCss, useScheme } from 'rnwind'`.
82
- * - Prepend a side-effect `import 'rnwind/__generated/style'` so the
83
- * union registry is loaded before any hoist runs.
84
- * @param ast Babel File AST (usually handed to us by Metro).
85
- * @param options Extra inputs — side-effect import specifiers + parser metadata.
86
- * @returns Transform outcome flags + the hoist table.
87
- */
88
- export declare function transformAst(ast: File, options: TransformAstOptions): TransformAstResult;