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
@@ -0,0 +1,438 @@
1
+ import { getStyleVersion, lookupCss, type InteractState } from './lookup-css'
2
+ import type { RnwindState } from './components/rnwind-provider'
3
+ import { normalizeClassName } from '../core/normalize-classname'
4
+ import type { GradientAtomInfo, GradientDirection } from '../core/parser/gradient'
5
+ import type { HapticRequest, HapticTrigger } from '../core/parser/haptics'
6
+
7
+ /**
8
+ * Rich className resolver — the runtime heart of the wrap / `useCss`.
9
+ *
10
+ * Resolution order, per className string:
11
+ * 1. **Molecule** — a build-time PRE-MERGED single style object for the
12
+ * whole literal className (per scheme). One map lookup returns it by
13
+ * reference: no array, no merge, no per-atom loop. The common case.
14
+ * 2. **Atom fallback** — for a className the scanner never saw (a
15
+ * runtime-built string like `` `${className} px-2` ``) OR one that
16
+ * carries context-dependent atoms (`pt-safe`, `text-base`, `md:*`),
17
+ * fall back to per-atom resolution via `lookupCss`, which folds in
18
+ * insets / fontScale / breakpoint / scheme.
19
+ *
20
+ * Results are cached by `(normalized className, scheme, insets, fontScale,
21
+ * breakpoint)` so repeated renders return the SAME reference until the
22
+ * reactive context changes. Atoms / molecules / features all live in
23
+ * build-time registries the generated `.rnwind/*.js` modules populate.
24
+ */
25
+
26
+ /** Always-loaded fallback scheme key. */
27
+ const COMMON_SCHEME = 'common'
28
+
29
+ /** Empty style sentinel. */
30
+ const EMPTY: readonly unknown[] = []
31
+
32
+ /** scheme → normalized className → pre-merged style object. */
33
+ let molecules: Record<string, Record<string, unknown>> = Object.create(null)
34
+ /** atom name → gradient role + resolved colour. */
35
+ let gradients: Record<string, GradientAtomInfo> = Object.create(null)
36
+ /** atom name (incl. `active:`/`focus:` prefix) → haptic request. */
37
+ let haptics: Record<string, HapticRequest> = Object.create(null)
38
+ /** Bumps on any molecule/gradient/haptic registration. */
39
+ let registryVersion = 0
40
+
41
+ /** Per-(className·state) resolved cache — strong references between context changes. */
42
+ const resolvedCache = new Map<string, ResolvedCss>()
43
+ /** Version the cache was last valid for (`getStyleVersion()` + {@link registryVersion}). */
44
+ let cachedFor = -1
45
+
46
+ /**
47
+ * Hard ceiling on the resolved cache. The cache is pure memoisation, so
48
+ * eviction only costs a re-resolve (sub-µs) — never correctness. Build
49
+ * molecules are NOT in here; they live permanently in `molecules`.
50
+ */
51
+ const MAX_RESOLVED_CACHE = 2048
52
+
53
+ /**
54
+ * Store a resolved result, bulk-evicting the OLDEST half when the cache
55
+ * hits {@link MAX_RESOLVED_CACHE}. `Map` preserves insertion order, so the
56
+ * first keys are the oldest. Bulk eviction keeps the hot (cache-hit) path
57
+ * free of per-access LRU bookkeeping at the cost of an occasional small
58
+ * recompute burst under sustained pressure (web / long sessions).
59
+ * @param key Cache key.
60
+ * @param value Resolved result to store.
61
+ */
62
+ function cacheResolved(key: string, value: ResolvedCss): void {
63
+ if (resolvedCache.size >= MAX_RESOLVED_CACHE) {
64
+ let drop = resolvedCache.size >> 1
65
+ for (const oldKey of resolvedCache.keys()) {
66
+ resolvedCache.delete(oldKey)
67
+ if (--drop <= 0) break
68
+ }
69
+ }
70
+ resolvedCache.set(key, value)
71
+ }
72
+
73
+ /** A unit-square gradient endpoint. */
74
+ interface GradientPoint {
75
+ readonly x: number
76
+ readonly y: number
77
+ }
78
+
79
+ /** Rich resolution: the RN `style` plus any className-derived props. */
80
+ export interface ResolvedCss {
81
+ /** RN `style` value — a single molecule object (by ref) or an atom array. */
82
+ readonly style: unknown
83
+ /** Gradient stop colours (when the className is a complete gradient). */
84
+ readonly colors?: readonly string[]
85
+ /** Gradient start point. */
86
+ readonly start?: GradientPoint
87
+ /** Gradient end point. */
88
+ readonly end?: GradientPoint
89
+ /** Text truncation line count. */
90
+ readonly numberOfLines?: number
91
+ /** Text ellipsize mode. */
92
+ readonly ellipsizeMode?: 'tail' | 'clip'
93
+ /** Haptic requests present on the className, for the wrap to dispatch. */
94
+ readonly haptics?: readonly { readonly request: HapticRequest; readonly trigger: HapticTrigger }[]
95
+ }
96
+
97
+ /** `GradientDirection` → expo-linear-gradient start/end points. */
98
+ const DIRECTION_POINTS: Record<GradientDirection, { start: GradientPoint; end: GradientPoint }> = {
99
+ 'to-t': { start: { x: 0.5, y: 1 }, end: { x: 0.5, y: 0 } },
100
+ 'to-b': { start: { x: 0.5, y: 0 }, end: { x: 0.5, y: 1 } },
101
+ 'to-l': { start: { x: 1, y: 0.5 }, end: { x: 0, y: 0.5 } },
102
+ 'to-r': { start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 } },
103
+ 'to-tl': { start: { x: 1, y: 1 }, end: { x: 0, y: 0 } },
104
+ 'to-tr': { start: { x: 0, y: 1 }, end: { x: 1, y: 0 } },
105
+ 'to-bl': { start: { x: 1, y: 0 }, end: { x: 0, y: 1 } },
106
+ 'to-br': { start: { x: 0, y: 0 }, end: { x: 1, y: 1 } },
107
+ unknown: { start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 } },
108
+ }
109
+
110
+ /**
111
+ * Register one scheme's pre-merged molecules (atom-merged literal
112
+ * classNames). Merges onto any existing entries for the scheme.
113
+ * @param scheme Scheme name (or `'common'`).
114
+ * @param entries Normalized className → merged style object.
115
+ */
116
+ export function registerMolecules(scheme: string, entries: Record<string, unknown>): void {
117
+ molecules[scheme] = { ...molecules[scheme], ...entries }
118
+ registryVersion += 1
119
+ }
120
+
121
+ /**
122
+ * Register the gradient atom map (atom name → role + resolved colour).
123
+ * @param map Atom name → gradient info.
124
+ */
125
+ export function registerGradients(map: Record<string, GradientAtomInfo>): void {
126
+ gradients = map
127
+ registryVersion += 1
128
+ }
129
+
130
+ /**
131
+ * Register the haptic atom map (atom name → request).
132
+ * @param map Atom name → haptic request.
133
+ */
134
+ export function registerHaptics(map: Record<string, HapticRequest>): void {
135
+ haptics = map
136
+ registryVersion += 1
137
+ }
138
+
139
+
140
+
141
+ /**
142
+ * Per-state-object signature memo. `RnwindState` is created fresh (via the
143
+ * provider's `useMemo`) whenever any field changes, so its identity is a
144
+ * sound key — a new object means a new signature. Keyed weakly so states
145
+ * GC with their provider.
146
+ */
147
+ const stateSignatureCache = new WeakMap<RnwindState, string>()
148
+
149
+ /**
150
+ * Cache key dimension for the reactive context — everything that can
151
+ * change a resolved style. Uses the breakpoint TIER (`activeBreakpoint`),
152
+ * NOT the raw `windowWidth`: two widths in the same tier gate `md:*` atoms
153
+ * identically, so they resolve the same. This collapses the window axis
154
+ * from "every pixel" to ~6 values, bounding the cache on resizable
155
+ * surfaces (web / desktop) without changing any result.
156
+ * @param state Rnwind context.
157
+ * @returns Compact signature string.
158
+ */
159
+ function stateSignature(state: RnwindState): string {
160
+ const { insets } = state
161
+ return `${state.scheme}|${insets.top},${insets.right},${insets.bottom},${insets.left}|${state.fontScale}|${state.activeBreakpoint}`
162
+ }
163
+
164
+ /**
165
+ * Memoised {@link stateSignature} — one `WeakMap.get` on the hot path
166
+ * instead of rebuilding the template string every resolve.
167
+ * @param state Rnwind context.
168
+ * @returns Cached compact signature.
169
+ */
170
+ function stateSignatureCached(state: RnwindState): string {
171
+ let signature = stateSignatureCache.get(state)
172
+ if (signature === undefined) {
173
+ signature = stateSignature(state)
174
+ stateSignatureCache.set(state, signature)
175
+ }
176
+ return signature
177
+ }
178
+
179
+ /**
180
+ * Compact signature of the live interactive state for the cache key.
181
+ * @param interactState Active/focus flags, or undefined for the plain path.
182
+ * @returns Two-bit signature (`''` when no interactive state).
183
+ */
184
+ function interactSignature(interactState?: InteractState): string {
185
+ if (!interactState) return ''
186
+ const active = interactState.active ? 1 : 0
187
+ const focus = interactState.focus ? 1 : 0
188
+ return `${active}${focus}`
189
+ }
190
+
191
+ /**
192
+ * Whether a token is a feature-ONLY utility (gradient stop/direction,
193
+ * haptic request, or text-truncate) that contributes NO RN `style`. These
194
+ * are folded in via {@link attachFeatures}, so they must be kept OUT of
195
+ * the `lookupCss` input — otherwise the atom resolver treats them as
196
+ * unknown style atoms and emits a spurious "unknown class" dev warning
197
+ * (e.g. for `active:haptic-rigid`).
198
+ * @param token Atom name.
199
+ * @returns True when the token carries no style.
200
+ */
201
+ function isFeatureOnlyToken(token: string): boolean {
202
+ return Boolean(gradients[token]) || Boolean(haptics[token]) || truncateForToken(token) !== null
203
+ }
204
+
205
+ /**
206
+ * Lifecycle trigger for a haptic atom from its variant prefix.
207
+ * @param token Atom name (maybe `active:`/`focus:`/`hover:` prefixed).
208
+ * @returns The trigger.
209
+ */
210
+ function hapticTriggerForToken(token: string): HapticTrigger {
211
+ const colon = token.indexOf(':')
212
+ if (colon === -1) return 'mount'
213
+ const prefix = token.slice(0, colon)
214
+ if (prefix === 'active') return 'pressIn'
215
+ if (prefix === 'focus') return 'focus'
216
+ if (prefix === 'hover') return 'hover'
217
+ return 'mount'
218
+ }
219
+
220
+ /**
221
+ * Syntactic text-truncate directive for one atom.
222
+ * @param token Atom name.
223
+ * @returns Partial truncate props, or null.
224
+ */
225
+ function truncateForToken(token: string): { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } | null {
226
+ if (token === 'truncate') return { numberOfLines: 1, ellipsizeMode: 'tail' }
227
+ if (token === 'text-ellipsis') return { ellipsizeMode: 'tail' }
228
+ if (token === 'text-clip') return { ellipsizeMode: 'clip' }
229
+ if (token === 'line-clamp-none') return { numberOfLines: 0 }
230
+ if (token.startsWith('line-clamp-')) {
231
+ const count = Number(token.slice('line-clamp-'.length))
232
+ if (Number.isInteger(count) && count >= 0) return { numberOfLines: count }
233
+ }
234
+ return null
235
+ }
236
+
237
+ /**
238
+ * Assemble gradient props from gradient roles present in the atom list.
239
+ * @param tokens Atom names.
240
+ * @returns `{colors, start, end}` or null when not a complete gradient.
241
+ */
242
+ function assembleGradient(tokens: readonly string[]): { colors: string[]; start: GradientPoint; end: GradientPoint } | null {
243
+ let from: string | undefined
244
+ let via: string | undefined
245
+ let to: string | undefined
246
+ let dir: GradientDirection | undefined
247
+ for (const token of tokens) {
248
+ const info = gradients[token]
249
+ if (!info) continue
250
+ switch (info.role) {
251
+ case 'from': {
252
+ from = info.color
253
+ break
254
+ }
255
+ case 'via': {
256
+ via = info.color
257
+ break
258
+ }
259
+ case 'to': {
260
+ to = info.color
261
+ break
262
+ }
263
+ default: {
264
+ ;({ dir } = info)
265
+ }
266
+ }
267
+ }
268
+ if (dir === undefined) return null
269
+ const colors = [from, via, to].filter((color): color is string => color !== undefined)
270
+ if (colors.length < 2) return null
271
+ const points = DIRECTION_POINTS[dir]
272
+ return { colors, start: points.start, end: points.end }
273
+ }
274
+
275
+ /**
276
+ * Fold every truncate directive across the atom list into one result —
277
+ * last token wins per prop (matches Tailwind last-wins).
278
+ * @param tokens Atom names.
279
+ * @returns Merged truncate props (empty when none apply).
280
+ */
281
+ function collectTruncate(tokens: readonly string[]): { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } {
282
+ const out: { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } = {}
283
+ for (const token of tokens) {
284
+ const truncate = truncateForToken(token)
285
+ if (!truncate) continue
286
+ if (truncate.numberOfLines !== undefined) out.numberOfLines = truncate.numberOfLines
287
+ if (truncate.ellipsizeMode !== undefined) out.ellipsizeMode = truncate.ellipsizeMode
288
+ }
289
+ return out
290
+ }
291
+
292
+ /**
293
+ * Collect every haptic request present in the atom list, tagged with the
294
+ * lifecycle trigger its variant prefix implies.
295
+ * @param tokens Atom names.
296
+ * @returns Haptic request list, or undefined when none apply.
297
+ */
298
+ function collectHaptics(tokens: readonly string[]): { request: HapticRequest; trigger: HapticTrigger }[] | undefined {
299
+ let collected: { request: HapticRequest; trigger: HapticTrigger }[] | undefined
300
+ for (const token of tokens) {
301
+ const request = haptics[token]
302
+ if (!request) continue
303
+ collected ??= []
304
+ collected.push({ request, trigger: hapticTriggerForToken(token) })
305
+ }
306
+ return collected
307
+ }
308
+
309
+ /**
310
+ * Scan tokens for the className-derived feature props (gradient,
311
+ * truncate, haptics) and fold them onto the base result.
312
+ * @param base Result carrying the resolved `style`.
313
+ * @param tokens Atom names.
314
+ * @returns The result with any feature props attached.
315
+ */
316
+ function attachFeatures(base: ResolvedCss, tokens: readonly string[]): ResolvedCss {
317
+ const { numberOfLines, ellipsizeMode } = collectTruncate(tokens)
318
+ const collected = collectHaptics(tokens)
319
+ const gradient = assembleGradient(tokens)
320
+ const result: Mutable<ResolvedCss> = { style: base.style }
321
+ if (gradient) {
322
+ result.colors = gradient.colors
323
+ result.start = gradient.start
324
+ result.end = gradient.end
325
+ }
326
+ // `numberOfLines: 0` is kept (RN reads it as "unlimited"): `line-clamp-none`
327
+ // must be able to explicitly reset an earlier `line-clamp-N` on the same
328
+ // element — dropping the 0 would silently leave the prior limit in place.
329
+ if (numberOfLines !== undefined) {
330
+ result.numberOfLines = numberOfLines
331
+ if (ellipsizeMode !== undefined) result.ellipsizeMode = ellipsizeMode
332
+ }
333
+ if (collected) result.haptics = collected
334
+ return result
335
+ }
336
+
337
+ /**
338
+ * Flatten the per-atom style array into ONE object — a *runtime molecule*.
339
+ * RN flattens a style array left-to-right (later wins), which is exactly
340
+ * `Object.assign` semantics, so the merged object renders identically
341
+ * while giving dynamic (cva / clsx) classNames the same single-object
342
+ * shape a build-time molecule has. The caller caches the result per
343
+ * `(className · state)`, so the merge runs once per unique context.
344
+ * @param array Per-atom style array from `lookupCss`.
345
+ * @returns Single merged style object.
346
+ */
347
+ function mergeStyleArray(array: readonly unknown[]): Record<string, unknown> {
348
+ const out: Record<string, unknown> = {}
349
+ for (const entry of array) if (entry && typeof entry === 'object') Object.assign(out, entry)
350
+ return out
351
+ }
352
+
353
+ /**
354
+ * Compose a resolved style with a caller-supplied inline style (user wins).
355
+ * @param style
356
+ * @param userStyle
357
+ */
358
+ function withUserStyle(style: unknown, userStyle: unknown): unknown {
359
+ return Array.isArray(style) ? [...style, userStyle] : [style, userStyle]
360
+ }
361
+
362
+ /**
363
+ * Resolve a className against the reactive context into a style plus any
364
+ * className-derived props. Molecule-first (one lookup, by reference),
365
+ * atom-fallback for unseen / context-dependent strings, cached per
366
+ * `(className, state)`.
367
+ * @param className Raw className string.
368
+ * @param state Rnwind context from `useRnwind()`.
369
+ * @param userStyle Optional inline style appended last (wins).
370
+ * @param interactState Live active/focus flags (for `active:`/`focus:` atoms).
371
+ * @returns The resolved style + feature props.
372
+ */
373
+ export function resolve(
374
+ className: string | null | undefined,
375
+ state: RnwindState,
376
+ userStyle?: unknown,
377
+ interactState?: InteractState,
378
+ ): ResolvedCss {
379
+ const version = getStyleVersion() + registryVersion
380
+ if (version !== cachedFor) {
381
+ resolvedCache.clear()
382
+ cachedFor = version
383
+ }
384
+ if (className == null) {
385
+ return { style: userStyle === undefined || userStyle === null ? EMPTY : [userStyle] }
386
+ }
387
+ // Key on the RAW className so the hot (cache-hit) path skips normalize
388
+ // entirely — normalization only runs on a miss. The state signature is
389
+ // memoised per state object, so the hit path is one WeakMap.get + one
390
+ // string concat + one Map.get.
391
+ const key = `${className}@${stateSignatureCached(state)}@${interactSignature(interactState)}`
392
+ const cached = resolvedCache.get(key)
393
+ if (cached !== undefined) {
394
+ return userStyle === undefined || userStyle === null ? cached : { ...cached, style: withUserStyle(cached.style, userStyle) }
395
+ }
396
+ const normalized = normalizeClassName(className)
397
+ if (normalized.length === 0) {
398
+ const empty: ResolvedCss = { style: EMPTY }
399
+ cacheResolved(key, empty)
400
+ return userStyle === undefined || userStyle === null ? empty : { style: [userStyle] }
401
+ }
402
+ // Molecules are static pre-merges; anything carrying `active:`/`focus:`
403
+ // is never registered as one, so the atom path handles interactive state.
404
+ const tokens = normalized.split(' ')
405
+ const molecule = interactState ? undefined : molecules[state.scheme]?.[normalized] ?? molecules[COMMON_SCHEME]?.[normalized]
406
+ // Feature-only tokens (gradient / haptic / truncate) carry no style — keep
407
+ // them out of the atom lookup so they don't warn as "unknown class". The
408
+ // atom array is merged into ONE object (a runtime molecule) so dynamic
409
+ // (cva / clsx) classNames get the same single-object shape as a build
410
+ // molecule; the cache below pins the context, so the merge is correct.
411
+ const style =
412
+ molecule === undefined
413
+ ? mergeStyleArray(lookupCss(tokens.filter((token) => !isFeatureOnlyToken(token)).join(' '), state, undefined, interactState))
414
+ : molecule
415
+ const base = attachFeatures({ style }, tokens)
416
+ cacheResolved(key, base)
417
+ return userStyle === undefined || userStyle === null ? base : { ...base, style: withUserStyle(base.style, userStyle) }
418
+ }
419
+
420
+ /** Local mutable view for building the frozen-shaped result. */
421
+ type Mutable<T> = { -readonly [K in keyof T]: T[K] }
422
+
423
+ /** Test-only — clear the molecule / gradient / haptic registries + cache. */
424
+ export function __resetResolveState(): void {
425
+ molecules = Object.create(null)
426
+ gradients = Object.create(null)
427
+ haptics = Object.create(null)
428
+ resolvedCache.clear()
429
+ registryVersion += 1
430
+ cachedFor = -1
431
+ }
432
+
433
+ /** Test-only — current resolved-cache entry count + its hard ceiling. */
434
+ export function __resolveCacheStats(): { size: number; max: number } {
435
+ return { size: resolvedCache.size, max: MAX_RESOLVED_CACHE }
436
+ }
437
+
438
+ export {normalizeClassName} from '../core/normalize-classname'