rnwind 0.0.4 → 0.0.5
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/normalize-classname.cjs +25 -0
- package/lib/cjs/core/normalize-classname.cjs.map +1 -0
- package/lib/cjs/core/normalize-classname.d.ts +10 -0
- package/lib/cjs/core/style-builder/build-style.cjs +258 -58
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -1
- package/lib/cjs/core/style-builder/build-style.d.ts +6 -1
- package/lib/cjs/core/style-builder/union-builder.cjs +37 -3
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
- package/lib/cjs/core/style-builder/union-builder.d.ts +21 -1
- package/lib/cjs/metro/dts.cjs +7 -16
- package/lib/cjs/metro/dts.cjs.map +1 -1
- package/lib/cjs/metro/dts.d.ts +2 -4
- package/lib/cjs/metro/state.cjs +30 -78
- package/lib/cjs/metro/state.cjs.map +1 -1
- package/lib/cjs/metro/state.d.ts +8 -25
- package/lib/cjs/metro/transformer.cjs +193 -34
- package/lib/cjs/metro/transformer.cjs.map +1 -1
- package/lib/cjs/metro/with-config.cjs +2 -2
- package/lib/cjs/metro/with-config.cjs.map +1 -1
- package/lib/cjs/metro/with-config.d.ts +11 -26
- package/lib/cjs/metro/wrap-imports.cjs +273 -0
- package/lib/cjs/metro/wrap-imports.cjs.map +1 -0
- package/lib/cjs/metro/wrap-imports.d.ts +26 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs +0 -17
- package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -1
- package/lib/cjs/runtime/components/rnwind-provider.d.ts +0 -14
- package/lib/cjs/runtime/hooks/use-css.cjs +16 -10
- package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -1
- package/lib/cjs/runtime/hooks/use-css.d.ts +15 -9
- package/lib/cjs/runtime/index.cjs +11 -13
- package/lib/cjs/runtime/index.cjs.map +1 -1
- package/lib/cjs/runtime/index.d.ts +4 -9
- package/lib/cjs/runtime/lookup-css.cjs +10 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -1
- package/lib/cjs/runtime/lookup-css.d.ts +7 -0
- package/lib/cjs/runtime/resolve.cjs +348 -0
- package/lib/cjs/runtime/resolve.cjs.map +1 -0
- package/lib/cjs/runtime/resolve.d.ts +61 -0
- package/lib/cjs/runtime/wrap.cjs +254 -0
- package/lib/cjs/runtime/wrap.cjs.map +1 -0
- package/lib/cjs/runtime/wrap.d.ts +37 -0
- package/lib/cjs/testing/index.cjs +81 -50
- package/lib/cjs/testing/index.cjs.map +1 -1
- package/lib/esm/core/normalize-classname.d.ts +10 -0
- package/lib/esm/core/normalize-classname.mjs +23 -0
- package/lib/esm/core/normalize-classname.mjs.map +1 -0
- package/lib/esm/core/style-builder/build-style.d.ts +6 -1
- package/lib/esm/core/style-builder/build-style.mjs +258 -58
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -1
- package/lib/esm/core/style-builder/union-builder.d.ts +21 -1
- package/lib/esm/core/style-builder/union-builder.mjs +37 -3
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
- package/lib/esm/metro/dts.d.ts +2 -4
- package/lib/esm/metro/dts.mjs +7 -16
- package/lib/esm/metro/dts.mjs.map +1 -1
- package/lib/esm/metro/state.d.ts +8 -25
- package/lib/esm/metro/state.mjs +30 -76
- package/lib/esm/metro/state.mjs.map +1 -1
- package/lib/esm/metro/transformer.mjs +194 -35
- package/lib/esm/metro/transformer.mjs.map +1 -1
- package/lib/esm/metro/with-config.d.ts +11 -26
- package/lib/esm/metro/with-config.mjs +2 -2
- package/lib/esm/metro/with-config.mjs.map +1 -1
- package/lib/esm/metro/wrap-imports.d.ts +26 -0
- package/lib/esm/metro/wrap-imports.mjs +250 -0
- package/lib/esm/metro/wrap-imports.mjs.map +1 -0
- package/lib/esm/runtime/components/rnwind-provider.d.ts +0 -14
- package/lib/esm/runtime/components/rnwind-provider.mjs +1 -17
- package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -1
- package/lib/esm/runtime/hooks/use-css.d.ts +15 -9
- package/lib/esm/runtime/hooks/use-css.mjs +16 -10
- package/lib/esm/runtime/hooks/use-css.mjs.map +1 -1
- package/lib/esm/runtime/index.d.ts +4 -9
- package/lib/esm/runtime/index.mjs +4 -4
- package/lib/esm/runtime/index.mjs.map +1 -1
- package/lib/esm/runtime/lookup-css.d.ts +7 -0
- package/lib/esm/runtime/lookup-css.mjs +10 -1
- package/lib/esm/runtime/lookup-css.mjs.map +1 -1
- package/lib/esm/runtime/resolve.d.ts +61 -0
- package/lib/esm/runtime/resolve.mjs +341 -0
- package/lib/esm/runtime/resolve.mjs.map +1 -0
- package/lib/esm/runtime/wrap.d.ts +37 -0
- package/lib/esm/runtime/wrap.mjs +251 -0
- package/lib/esm/runtime/wrap.mjs.map +1 -0
- package/lib/esm/testing/index.mjs +84 -53
- package/lib/esm/testing/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/core/normalize-classname.ts +19 -0
- package/src/core/style-builder/build-style.ts +286 -55
- package/src/core/style-builder/union-builder.ts +36 -3
- package/src/metro/dts.ts +7 -19
- package/src/metro/state.ts +29 -74
- package/src/metro/transformer.ts +190 -34
- package/src/metro/with-config.ts +13 -28
- package/src/metro/wrap-imports.ts +260 -0
- package/src/runtime/components/rnwind-provider.tsx +0 -17
- package/src/runtime/hooks/use-css.ts +17 -11
- package/src/runtime/index.ts +3 -26
- package/src/runtime/lookup-css.ts +10 -0
- package/src/runtime/resolve.ts +381 -0
- package/src/runtime/wrap.tsx +267 -0
- package/src/testing/index.ts +106 -56
- package/lib/cjs/core/parser/text-truncate.cjs +0 -78
- package/lib/cjs/core/parser/text-truncate.cjs.map +0 -1
- package/lib/cjs/metro/transform-ast.cjs +0 -1472
- package/lib/cjs/metro/transform-ast.cjs.map +0 -1
- package/lib/cjs/metro/transform-ast.d.ts +0 -88
- package/lib/cjs/runtime/haptics.cjs +0 -113
- package/lib/cjs/runtime/haptics.cjs.map +0 -1
- package/lib/cjs/runtime/haptics.d.ts +0 -48
- package/lib/cjs/runtime/interactive-box.cjs +0 -35
- package/lib/cjs/runtime/interactive-box.cjs.map +0 -1
- package/lib/cjs/runtime/interactive-box.d.ts +0 -40
- package/lib/esm/core/parser/text-truncate.mjs +0 -75
- package/lib/esm/core/parser/text-truncate.mjs.map +0 -1
- package/lib/esm/metro/transform-ast.d.ts +0 -88
- package/lib/esm/metro/transform-ast.mjs +0 -1451
- package/lib/esm/metro/transform-ast.mjs.map +0 -1
- package/lib/esm/runtime/haptics.d.ts +0 -48
- package/lib/esm/runtime/haptics.mjs +0 -110
- package/lib/esm/runtime/haptics.mjs.map +0 -1
- package/lib/esm/runtime/interactive-box.d.ts +0 -40
- package/lib/esm/runtime/interactive-box.mjs +0 -33
- package/lib/esm/runtime/interactive-box.mjs.map +0 -1
- package/src/metro/transform-ast.ts +0 -1729
- package/src/runtime/haptics.ts +0 -120
- package/src/runtime/interactive-box.tsx +0 -57
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { createElement, useRef, useEffect } from 'react';
|
|
2
|
+
import { chainPress, chainFocus } from './chain-handlers.mjs';
|
|
3
|
+
import { useInteract } from './hooks/use-interact.mjs';
|
|
4
|
+
import { useRnwind } from './components/rnwind-provider.mjs';
|
|
5
|
+
import { resolve } from './resolve.mjs';
|
|
6
|
+
|
|
7
|
+
/** Matches a leading `active:` / `focus:` variant token (`\b` excludes `inactive:`). */
|
|
8
|
+
const INTERACTIVE_VARIANT = /\b(?:active|focus):/;
|
|
9
|
+
/** One-shot guard so the missing-`onHaptics` warning logs once per session. */
|
|
10
|
+
let warnedMissingOnHaptics = false;
|
|
11
|
+
/**
|
|
12
|
+
* Dev-only warning when a className carries a haptic utility but no
|
|
13
|
+
* `onHaptics` dispatcher is wired on the nearest `<RnwindProvider>` — the
|
|
14
|
+
* haptic would silently drop otherwise. Fires once per session.
|
|
15
|
+
* @param onHaptics The dispatcher from context (or undefined).
|
|
16
|
+
* @param haptics The resolved haptic requests (or undefined).
|
|
17
|
+
*/
|
|
18
|
+
function warnIfHapticsUnwired(onHaptics, haptics) {
|
|
19
|
+
if (onHaptics || !haptics || haptics.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
const isDevelopment = typeof __DEV__ === 'undefined' || __DEV__;
|
|
22
|
+
if (!isDevelopment || warnedMissingOnHaptics)
|
|
23
|
+
return;
|
|
24
|
+
warnedMissingOnHaptics = true;
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.warn('rnwind: a `haptic-*` utility resolved but no `onHaptics` callback is wired on <RnwindProvider>. ' +
|
|
27
|
+
'Pass `onHaptics` on the provider to forward the request to expo-haptics (or any library).');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a className needs press/focus state tracking.
|
|
31
|
+
* @param className Raw className string.
|
|
32
|
+
* @returns True when an `active:` / `focus:` variant is present.
|
|
33
|
+
*/
|
|
34
|
+
function hasInteractiveVariant(className) {
|
|
35
|
+
return INTERACTIVE_VARIANT.test(className);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Best-effort display name for the wrapped component.
|
|
39
|
+
* @param component Component being wrapped.
|
|
40
|
+
* @returns Its `displayName`, `name`, or `'Component'`.
|
|
41
|
+
*/
|
|
42
|
+
function displayNameOf(component) {
|
|
43
|
+
const named = component;
|
|
44
|
+
return named.displayName ?? named.name ?? 'Component';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fire the `mount`-trigger haptics once, after the element mounts. Snaps
|
|
48
|
+
* the resolved requests + dispatcher at mount via a `useRef` initializer
|
|
49
|
+
* (evaluated only on the first render), so an unstable inline `onHaptics`
|
|
50
|
+
* doesn't re-fire them and no ref is written during render.
|
|
51
|
+
* @param resolved The resolved className (carries any haptic requests).
|
|
52
|
+
* @param onHaptics The dispatcher from context (or undefined).
|
|
53
|
+
*/
|
|
54
|
+
function useMountHaptics(resolved, onHaptics) {
|
|
55
|
+
const mount = useRef({ resolved, onHaptics });
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const { resolved: current, onHaptics: dispatch } = mount.current;
|
|
58
|
+
if (!dispatch || !current.haptics)
|
|
59
|
+
return;
|
|
60
|
+
for (const entry of current.haptics)
|
|
61
|
+
if (entry.trigger === 'mount')
|
|
62
|
+
dispatch(entry.request, 'mount');
|
|
63
|
+
}, []);
|
|
64
|
+
}
|
|
65
|
+
/** Suffix marking a secondary class-prop (`contentContainerClassName`, …). */
|
|
66
|
+
const CLASSNAME_SUFFIX = 'ClassName';
|
|
67
|
+
/**
|
|
68
|
+
* Resolve every secondary `<prefix>ClassName` prop (e.g.
|
|
69
|
+
* `contentContainerClassName` on a ScrollView / FlatList) into its
|
|
70
|
+
* matching `<prefix>Style`, in place. Any existing `<prefix>Style` is
|
|
71
|
+
* appended last (caller wins). The original `*ClassName` prop is deleted
|
|
72
|
+
* so RN never sees an unknown attribute. The primary `className` is
|
|
73
|
+
* handled separately by the leaf and never reaches here.
|
|
74
|
+
* @param props Mutable prop object being assembled for the host.
|
|
75
|
+
* @param state Rnwind context for resolution.
|
|
76
|
+
*/
|
|
77
|
+
function applyContainerClassNames(props, state) {
|
|
78
|
+
for (const key of Object.keys(props)) {
|
|
79
|
+
if (!key.endsWith(CLASSNAME_SUFFIX))
|
|
80
|
+
continue;
|
|
81
|
+
const value = props[key];
|
|
82
|
+
if (typeof value !== 'string')
|
|
83
|
+
continue;
|
|
84
|
+
const styleKey = `${key.slice(0, -CLASSNAME_SUFFIX.length)}Style`;
|
|
85
|
+
props[styleKey] = resolve(value, state, props[styleKey]).style;
|
|
86
|
+
delete props[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build the props for the wrapped host: resolved `style`, gradient
|
|
91
|
+
* (`colors`/`start`/`end`), truncate (`numberOfLines`/`ellipsizeMode`),
|
|
92
|
+
* secondary `<prefix>ClassName` → `<prefix>Style`, and a chained
|
|
93
|
+
* `onPressIn` that fires press-trigger haptics. Unknown props on a host
|
|
94
|
+
* are simply ignored by RN, so this stays generic.
|
|
95
|
+
* @param rest Forwarded props (incl. `ref`).
|
|
96
|
+
* @param resolved Resolved className result.
|
|
97
|
+
* @param state Rnwind context — used to resolve secondary class props.
|
|
98
|
+
* @param onHaptics Dispatcher from context.
|
|
99
|
+
* @param userOnPressIn Caller-supplied onPressIn to chain after the haptic.
|
|
100
|
+
* @returns The merged prop object for `createElement`.
|
|
101
|
+
*/
|
|
102
|
+
function buildProps(rest, resolved, state, onHaptics, userOnPressIn) {
|
|
103
|
+
warnIfHapticsUnwired(onHaptics, resolved.haptics);
|
|
104
|
+
const props = { ...rest, style: resolved.style };
|
|
105
|
+
applyContainerClassNames(props, state);
|
|
106
|
+
if (resolved.colors) {
|
|
107
|
+
props.colors = resolved.colors;
|
|
108
|
+
props.start = resolved.start;
|
|
109
|
+
props.end = resolved.end;
|
|
110
|
+
}
|
|
111
|
+
if (resolved.numberOfLines !== undefined) {
|
|
112
|
+
props.numberOfLines = resolved.numberOfLines;
|
|
113
|
+
if (resolved.ellipsizeMode !== undefined)
|
|
114
|
+
props.ellipsizeMode = resolved.ellipsizeMode;
|
|
115
|
+
}
|
|
116
|
+
const pressHaptics = onHaptics && resolved.haptics?.filter((entry) => entry.trigger === 'pressIn');
|
|
117
|
+
if (pressHaptics && pressHaptics.length > 0) {
|
|
118
|
+
const previous = userOnPressIn;
|
|
119
|
+
props.onPressIn = (event) => {
|
|
120
|
+
for (const entry of pressHaptics)
|
|
121
|
+
onHaptics(entry.request, 'pressIn');
|
|
122
|
+
previous?.(event);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else if (userOnPressIn !== undefined) {
|
|
126
|
+
props.onPressIn = userOnPressIn;
|
|
127
|
+
}
|
|
128
|
+
return props;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Non-interactive leaf: resolve className → style (+ features) and
|
|
132
|
+
* forward. One context read, one molecule/atom resolve.
|
|
133
|
+
* @param props Leaf props.
|
|
134
|
+
* @param props.as
|
|
135
|
+
* @param props.className
|
|
136
|
+
* @param props.style
|
|
137
|
+
* @param props.onPressIn
|
|
138
|
+
* @returns The rendered `as` element.
|
|
139
|
+
*/
|
|
140
|
+
function PlainLeaf({ as: As, className, style, onPressIn, ...rest }) {
|
|
141
|
+
const state = useRnwind();
|
|
142
|
+
const resolved = resolve(className, state, style);
|
|
143
|
+
useMountHaptics(resolved, state.onHaptics);
|
|
144
|
+
return createElement(As, buildProps(rest, resolved, state, state.onHaptics, onPressIn));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Interactive leaf: tracks press/focus via `useInteract()`, feeds it into
|
|
148
|
+
* `resolve` so `active:`/`focus:` atoms apply, and chains the
|
|
149
|
+
* press/focus handlers.
|
|
150
|
+
* @param props Leaf props.
|
|
151
|
+
* @param props.as
|
|
152
|
+
* @param props.className
|
|
153
|
+
* @param props.style
|
|
154
|
+
* @param props.onPressIn
|
|
155
|
+
* @param props.onPressOut
|
|
156
|
+
* @param props.onFocus
|
|
157
|
+
* @param props.onBlur
|
|
158
|
+
* @returns The rendered `as` element with interactive wiring.
|
|
159
|
+
*/
|
|
160
|
+
function InteractiveLeaf({ as: As, className, style, onPressIn, onPressOut, onFocus, onBlur, ...rest }) {
|
|
161
|
+
const state = useRnwind();
|
|
162
|
+
const interact = useInteract();
|
|
163
|
+
const resolved = resolve(className, state, style, interact.state);
|
|
164
|
+
useMountHaptics(resolved, state.onHaptics);
|
|
165
|
+
const props = buildProps(rest, resolved, state, state.onHaptics, onPressIn);
|
|
166
|
+
props.onPressIn = chainPress(props.onPressIn, interact.onPressIn);
|
|
167
|
+
props.onPressOut = chainPress(onPressOut, interact.onPressOut);
|
|
168
|
+
props.onFocus = chainFocus(onFocus, interact.onFocus);
|
|
169
|
+
props.onBlur = chainFocus(onBlur, interact.onBlur);
|
|
170
|
+
return createElement(As, props);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Wrap a component so its `className` prop resolves to RN `style` (plus
|
|
174
|
+
* gradient / truncate props and haptic dispatch) at render — no matter
|
|
175
|
+
* how className arrived: written directly, spread through `{...rest}`, or
|
|
176
|
+
* forwarded down custom wrappers. The returned component is hook-free; it
|
|
177
|
+
* dispatches to a plain or interactive leaf so non-interactive elements
|
|
178
|
+
* never pay for press/focus state. `ref` (a normal prop in React 19) and
|
|
179
|
+
* all other props forward untouched.
|
|
180
|
+
* @example
|
|
181
|
+
* ```tsx
|
|
182
|
+
* const Pressable = wrap(RNPressable)
|
|
183
|
+
* <Pressable className="active:bg-sky-700 px-4 haptic-light" onPress={fn} />
|
|
184
|
+
* ```
|
|
185
|
+
* @param Component Any component accepting a `style` prop.
|
|
186
|
+
* @returns A component accepting `className`.
|
|
187
|
+
*/
|
|
188
|
+
function wrap(Component) {
|
|
189
|
+
const as = Component;
|
|
190
|
+
/**
|
|
191
|
+
* The wrapped component — hook-free dispatcher to a leaf.
|
|
192
|
+
* @param props Forwarded props with `className` intercepted.
|
|
193
|
+
* @param props.className
|
|
194
|
+
* @returns The rendered leaf.
|
|
195
|
+
*/
|
|
196
|
+
function RnwindWrapped({ className, ...rest }) {
|
|
197
|
+
if (className !== undefined && hasInteractiveVariant(className)) {
|
|
198
|
+
return createElement(InteractiveLeaf, { as, className, ...rest });
|
|
199
|
+
}
|
|
200
|
+
return createElement(PlainLeaf, { as, className, ...rest });
|
|
201
|
+
}
|
|
202
|
+
RnwindWrapped.displayName = `wrap(${displayNameOf(Component)})`;
|
|
203
|
+
return RnwindWrapped;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Whether a namespace member name denotes a component to wrap —
|
|
207
|
+
* PascalCase and not a React context (`*Context`). Lowercase utilities /
|
|
208
|
+
* hooks (`createAnimatedComponent`, `spring`) pass through untouched.
|
|
209
|
+
* @param name Member key.
|
|
210
|
+
* @returns True when the member should be `wrap()`-ed.
|
|
211
|
+
*/
|
|
212
|
+
function isComponentMember(name) {
|
|
213
|
+
return /^[A-Z]/.test(name) && !name.endsWith('Context');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Wrap a component NAMESPACE (a default/namespace import like reanimated's
|
|
217
|
+
* `Animated`) so member access — `Animated.View`, `Animated.ScrollView` —
|
|
218
|
+
* returns a `wrap()`-ed component whose `className` resolves at render.
|
|
219
|
+
* Returns a Proxy: component members are wrapped lazily and memoised so
|
|
220
|
+
* each access yields the SAME wrapped component (stable identity — React
|
|
221
|
+
* would remount otherwise). Non-component members (`createAnimatedComponent`,
|
|
222
|
+
* config objects) pass straight through.
|
|
223
|
+
* @example
|
|
224
|
+
* ```tsx
|
|
225
|
+
* const Animated = wrapNamespace(RNReanimated)
|
|
226
|
+
* <Animated.View className="enter-fade" />
|
|
227
|
+
* ```
|
|
228
|
+
* @param namespace The imported namespace object.
|
|
229
|
+
* @returns A Proxy that wraps component members on access.
|
|
230
|
+
*/
|
|
231
|
+
function wrapNamespace(namespace) {
|
|
232
|
+
const cache = new Map();
|
|
233
|
+
return new Proxy(namespace, {
|
|
234
|
+
get(target, key, receiver) {
|
|
235
|
+
const value = Reflect.get(target, key, receiver);
|
|
236
|
+
if (typeof key !== 'string' || !isComponentMember(key))
|
|
237
|
+
return value;
|
|
238
|
+
if (!value || (typeof value !== 'function' && typeof value !== 'object'))
|
|
239
|
+
return value;
|
|
240
|
+
let wrapped = cache.get(key);
|
|
241
|
+
if (wrapped === undefined) {
|
|
242
|
+
wrapped = wrap(value);
|
|
243
|
+
cache.set(key, wrapped);
|
|
244
|
+
}
|
|
245
|
+
return wrapped;
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { wrap, wrapNamespace };
|
|
251
|
+
//# sourceMappingURL=wrap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.mjs","sources":["../../../../src/runtime/wrap.tsx"],"sourcesContent":["import { createElement, useEffect, useRef, type ComponentType, type ReactElement } from 'react'\nimport { chainFocus, chainPress } from './chain-handlers'\nimport { useInteract } from './hooks/use-interact'\nimport { useRnwind } from './components/rnwind-provider'\nimport type { RnwindState } from './components/rnwind-provider'\nimport { resolve, type ResolvedCss } from './resolve'\nimport type { OnHaptics } from '../core/parser/haptics'\n\n/** Matches a leading `active:` / `focus:` variant token (`\\b` excludes `inactive:`). */\nconst INTERACTIVE_VARIANT = /\\b(?:active|focus):/\n\n/** One-shot guard so the missing-`onHaptics` warning logs once per session. */\nlet warnedMissingOnHaptics = false\n\n/**\n * Dev-only warning when a className carries a haptic utility but no\n * `onHaptics` dispatcher is wired on the nearest `<RnwindProvider>` — the\n * haptic would silently drop otherwise. Fires once per session.\n * @param onHaptics The dispatcher from context (or undefined).\n * @param haptics The resolved haptic requests (or undefined).\n */\nfunction warnIfHapticsUnwired(onHaptics: OnHaptics | undefined, haptics: ResolvedCss['haptics']): void {\n if (onHaptics || !haptics || haptics.length === 0) return\n const isDevelopment = typeof __DEV__ === 'undefined' || __DEV__\n if (!isDevelopment || warnedMissingOnHaptics) return\n warnedMissingOnHaptics = true\n // eslint-disable-next-line no-console\n console.warn(\n 'rnwind: a `haptic-*` utility resolved but no `onHaptics` callback is wired on <RnwindProvider>. ' +\n 'Pass `onHaptics` on the provider to forward the request to expo-haptics (or any library).',\n )\n}\n\n/**\n * Whether a className needs press/focus state tracking.\n * @param className Raw className string.\n * @returns True when an `active:` / `focus:` variant is present.\n */\nfunction hasInteractiveVariant(className: string): boolean {\n return INTERACTIVE_VARIANT.test(className)\n}\n\n/**\n * Best-effort display name for the wrapped component.\n * @param component Component being wrapped.\n * @returns Its `displayName`, `name`, or `'Component'`.\n */\nfunction displayNameOf(component: unknown): string {\n const named = component as { displayName?: string; name?: string }\n return named.displayName ?? named.name ?? 'Component'\n}\n\n/**\n * Fire the `mount`-trigger haptics once, after the element mounts. Snaps\n * the resolved requests + dispatcher at mount via a `useRef` initializer\n * (evaluated only on the first render), so an unstable inline `onHaptics`\n * doesn't re-fire them and no ref is written during render.\n * @param resolved The resolved className (carries any haptic requests).\n * @param onHaptics The dispatcher from context (or undefined).\n */\nfunction useMountHaptics(resolved: ResolvedCss, onHaptics: OnHaptics | undefined): void {\n const mount = useRef({ resolved, onHaptics })\n useEffect(() => {\n const { resolved: current, onHaptics: dispatch } = mount.current\n if (!dispatch || !current.haptics) return\n for (const entry of current.haptics) if (entry.trigger === 'mount') dispatch(entry.request, 'mount')\n }, [])\n}\n\n/** Suffix marking a secondary class-prop (`contentContainerClassName`, …). */\nconst CLASSNAME_SUFFIX = 'ClassName'\n\n/**\n * Resolve every secondary `<prefix>ClassName` prop (e.g.\n * `contentContainerClassName` on a ScrollView / FlatList) into its\n * matching `<prefix>Style`, in place. Any existing `<prefix>Style` is\n * appended last (caller wins). The original `*ClassName` prop is deleted\n * so RN never sees an unknown attribute. The primary `className` is\n * handled separately by the leaf and never reaches here.\n * @param props Mutable prop object being assembled for the host.\n * @param state Rnwind context for resolution.\n */\nfunction applyContainerClassNames(props: Record<string, unknown>, state: RnwindState): void {\n for (const key of Object.keys(props)) {\n if (!key.endsWith(CLASSNAME_SUFFIX)) continue\n const value = props[key]\n if (typeof value !== 'string') continue\n const styleKey = `${key.slice(0, -CLASSNAME_SUFFIX.length)}Style`\n props[styleKey] = resolve(value, state, props[styleKey]).style\n delete props[key]\n }\n}\n\n/**\n * Build the props for the wrapped host: resolved `style`, gradient\n * (`colors`/`start`/`end`), truncate (`numberOfLines`/`ellipsizeMode`),\n * secondary `<prefix>ClassName` → `<prefix>Style`, and a chained\n * `onPressIn` that fires press-trigger haptics. Unknown props on a host\n * are simply ignored by RN, so this stays generic.\n * @param rest Forwarded props (incl. `ref`).\n * @param resolved Resolved className result.\n * @param state Rnwind context — used to resolve secondary class props.\n * @param onHaptics Dispatcher from context.\n * @param userOnPressIn Caller-supplied onPressIn to chain after the haptic.\n * @returns The merged prop object for `createElement`.\n */\nfunction buildProps(\n rest: Record<string, unknown>,\n resolved: ResolvedCss,\n state: RnwindState,\n onHaptics: OnHaptics | undefined,\n userOnPressIn?: unknown,\n): Record<string, unknown> {\n warnIfHapticsUnwired(onHaptics, resolved.haptics)\n const props: Record<string, unknown> = { ...rest, style: resolved.style }\n applyContainerClassNames(props, state)\n if (resolved.colors) {\n props.colors = resolved.colors\n props.start = resolved.start\n props.end = resolved.end\n }\n if (resolved.numberOfLines !== undefined) {\n props.numberOfLines = resolved.numberOfLines\n if (resolved.ellipsizeMode !== undefined) props.ellipsizeMode = resolved.ellipsizeMode\n }\n const pressHaptics = onHaptics && resolved.haptics?.filter((entry) => entry.trigger === 'pressIn')\n if (pressHaptics && pressHaptics.length > 0) {\n const previous = userOnPressIn as ((event: unknown) => void) | undefined\n props.onPressIn = (event: unknown): void => {\n for (const entry of pressHaptics) onHaptics(entry.request, 'pressIn')\n previous?.(event)\n }\n } else if (userOnPressIn !== undefined) {\n props.onPressIn = userOnPressIn\n }\n return props\n}\n\n/** Props a leaf receives — the wrapped `as` tag plus forwarded props. */\ninterface LeafProps {\n readonly as: ComponentType<Record<string, unknown>>\n readonly className?: string\n readonly style?: unknown\n readonly [key: string]: unknown\n}\n\n/**\n * Non-interactive leaf: resolve className → style (+ features) and\n * forward. One context read, one molecule/atom resolve.\n * @param props Leaf props.\n * @param props.as\n * @param props.className\n * @param props.style\n * @param props.onPressIn\n * @returns The rendered `as` element.\n */\nfunction PlainLeaf({ as: As, className, style, onPressIn, ...rest }: LeafProps): ReactElement {\n const state = useRnwind()\n const resolved = resolve(className, state, style)\n useMountHaptics(resolved, state.onHaptics)\n return createElement(As, buildProps(rest, resolved, state, state.onHaptics, onPressIn))\n}\n\n/**\n * Interactive leaf: tracks press/focus via `useInteract()`, feeds it into\n * `resolve` so `active:`/`focus:` atoms apply, and chains the\n * press/focus handlers.\n * @param props Leaf props.\n * @param props.as\n * @param props.className\n * @param props.style\n * @param props.onPressIn\n * @param props.onPressOut\n * @param props.onFocus\n * @param props.onBlur\n * @returns The rendered `as` element with interactive wiring.\n */\nfunction InteractiveLeaf({ as: As, className, style, onPressIn, onPressOut, onFocus, onBlur, ...rest }: LeafProps): ReactElement {\n const state = useRnwind()\n const interact = useInteract()\n const resolved = resolve(className, state, style, interact.state)\n useMountHaptics(resolved, state.onHaptics)\n const props = buildProps(rest, resolved, state, state.onHaptics, onPressIn)\n props.onPressIn = chainPress(props.onPressIn as Parameters<typeof chainPress>[0], interact.onPressIn)\n props.onPressOut = chainPress(onPressOut as Parameters<typeof chainPress>[0], interact.onPressOut)\n props.onFocus = chainFocus(onFocus as Parameters<typeof chainFocus>[0], interact.onFocus)\n props.onBlur = chainFocus(onBlur as Parameters<typeof chainFocus>[0], interact.onBlur)\n return createElement(As, props)\n}\n\n/**\n * Wrap a component so its `className` prop resolves to RN `style` (plus\n * gradient / truncate props and haptic dispatch) at render — no matter\n * how className arrived: written directly, spread through `{...rest}`, or\n * forwarded down custom wrappers. The returned component is hook-free; it\n * dispatches to a plain or interactive leaf so non-interactive elements\n * never pay for press/focus state. `ref` (a normal prop in React 19) and\n * all other props forward untouched.\n * @example\n * ```tsx\n * const Pressable = wrap(RNPressable)\n * <Pressable className=\"active:bg-sky-700 px-4 haptic-light\" onPress={fn} />\n * ```\n * @param Component Any component accepting a `style` prop.\n * @returns A component accepting `className`.\n */\nexport function wrap<P>(Component: ComponentType<P>): ComponentType<P & { className?: string }> {\n const as = Component as unknown as ComponentType<Record<string, unknown>>\n /**\n * The wrapped component — hook-free dispatcher to a leaf.\n * @param props Forwarded props with `className` intercepted.\n * @param props.className\n * @returns The rendered leaf.\n */\n function RnwindWrapped({ className, ...rest }: { className?: string; [key: string]: unknown }): ReactElement {\n if (className !== undefined && hasInteractiveVariant(className)) {\n return createElement(InteractiveLeaf, { as, className, ...rest })\n }\n return createElement(PlainLeaf, { as, className, ...rest })\n }\n RnwindWrapped.displayName = `wrap(${displayNameOf(Component)})`\n return RnwindWrapped as unknown as ComponentType<P & { className?: string }>\n}\n\n/**\n * Whether a namespace member name denotes a component to wrap —\n * PascalCase and not a React context (`*Context`). Lowercase utilities /\n * hooks (`createAnimatedComponent`, `spring`) pass through untouched.\n * @param name Member key.\n * @returns True when the member should be `wrap()`-ed.\n */\nfunction isComponentMember(name: string): boolean {\n return /^[A-Z]/.test(name) && !name.endsWith('Context')\n}\n\n/**\n * Wrap a component NAMESPACE (a default/namespace import like reanimated's\n * `Animated`) so member access — `Animated.View`, `Animated.ScrollView` —\n * returns a `wrap()`-ed component whose `className` resolves at render.\n * Returns a Proxy: component members are wrapped lazily and memoised so\n * each access yields the SAME wrapped component (stable identity — React\n * would remount otherwise). Non-component members (`createAnimatedComponent`,\n * config objects) pass straight through.\n * @example\n * ```tsx\n * const Animated = wrapNamespace(RNReanimated)\n * <Animated.View className=\"enter-fade\" />\n * ```\n * @param namespace The imported namespace object.\n * @returns A Proxy that wraps component members on access.\n */\nexport function wrapNamespace<T extends object>(namespace: T): T {\n const cache = new Map<string, unknown>()\n return new Proxy(namespace, {\n get(target, key, receiver): unknown {\n const value = Reflect.get(target, key, receiver)\n if (typeof key !== 'string' || !isComponentMember(key)) return value\n if (!value || (typeof value !== 'function' && typeof value !== 'object')) return value\n let wrapped = cache.get(key)\n if (wrapped === undefined) {\n wrapped = wrap(value as ComponentType<unknown>)\n cache.set(key, wrapped)\n }\n return wrapped\n },\n })\n}\n"],"names":[],"mappings":";;;;;;AAQA;AACA,MAAM,mBAAmB,GAAG,qBAAqB;AAEjD;AACA,IAAI,sBAAsB,GAAG,KAAK;AAElC;;;;;;AAMG;AACH,SAAS,oBAAoB,CAAC,SAAgC,EAAE,OAA+B,EAAA;IAC7F,IAAI,SAAS,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE;IACnD,MAAM,aAAa,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO;IAC/D,IAAI,CAAC,aAAa,IAAI,sBAAsB;QAAE;IAC9C,sBAAsB,GAAG,IAAI;;IAE7B,OAAO,CAAC,IAAI,CACV,kGAAkG;AAChG,QAAA,2FAA2F,C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;AAEA;;;;;;;;;;;;;;;AAeG;AACG,SAAU,aAAa,CAAmB,SAAY,EAAA;AAC1D,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB;AACxC,IAAA,OAAO,IAAI,KAAK,CAAC,SAAS,EAAE;AAC1B,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACvB,YAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;YAChD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;AAAE,gBAAA,OAAO,KAAK;AACpE,YAAA,IAAI,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAAE,gBAAA,OAAO,KAAK;YACtF,IAAI,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;AAC5B,YAAA,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,gBAAA,OAAO,GAAG,IAAI,CAAC,KAA+B,CAAC;AAC/C,gBAAA,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC;YACzB;AACA,YAAA,OAAO,OAAO;QAChB,CAAC;AACF,KAAA,CAAC;AACJ;;;;"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { parse } from '@babel/parser';
|
|
2
2
|
import generate$1 from '@babel/generator';
|
|
3
|
-
import { mkdtempSync, writeFileSync, existsSync,
|
|
3
|
+
import { mkdtempSync, writeFileSync, existsSync, readdirSync, rmSync, readFileSync } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { tmpdir } from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
8
|
+
import { __resetLookupCssState, registerAtoms, registerBreakpoints, registerSchemeLoader } from '../runtime/lookup-css.mjs';
|
|
9
|
+
import { __resetResolveState, registerMolecules, registerGradients, registerHaptics } from '../runtime/resolve.mjs';
|
|
10
|
+
import * as runtime_index from '../runtime/index.mjs';
|
|
11
|
+
import { RnwindProvider } from '../runtime/components/rnwind-provider.mjs';
|
|
11
12
|
import { configureRnwindState, resetRnwindState } from '../metro/state.mjs';
|
|
12
13
|
import { transform } from '../metro/transformer.mjs';
|
|
13
14
|
|
|
@@ -29,26 +30,6 @@ const DEFAULT_THEME_CSS = `@import 'tailwindcss';
|
|
|
29
30
|
`;
|
|
30
31
|
/** `StyleSheet.create` stub the evaluated bundle calls — identity at test time. */
|
|
31
32
|
const BUNDLE_STYLE_SHEET = { create: (styles) => styles, hairlineWidth: 1 };
|
|
32
|
-
/** Stubbed interactive-state hook return matching `useInteract()`. */
|
|
33
|
-
const NOOP_INTERACT = {
|
|
34
|
-
state: undefined,
|
|
35
|
-
onPressIn: () => undefined,
|
|
36
|
-
onPressOut: () => undefined,
|
|
37
|
-
onFocus: () => undefined,
|
|
38
|
-
onBlur: () => undefined,
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Identity chain helper matching `chainPress` / `chainFocus`. Returns a
|
|
42
|
-
* single callback that invokes every supplied handler in turn.
|
|
43
|
-
* @param handlers Handlers to chain.
|
|
44
|
-
* @returns Combined callback.
|
|
45
|
-
*/
|
|
46
|
-
const NOOP_CHAIN = (...handlers) => (...args) => {
|
|
47
|
-
for (const handler of handlers) {
|
|
48
|
-
if (typeof handler === 'function')
|
|
49
|
-
handler(...args);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
33
|
// Synthesize a require rooted at the consumer's cwd so optional peer
|
|
53
34
|
// lookups (`@testing-library/react-native`, `esbuild`) resolve from THEIR
|
|
54
35
|
// node_modules, not rnwind's. A workspace-local rnwind install resolves
|
|
@@ -106,28 +87,87 @@ function compileToJs(source) {
|
|
|
106
87
|
}
|
|
107
88
|
}
|
|
108
89
|
/**
|
|
109
|
-
* Evaluate
|
|
110
|
-
* so its `registerAtoms`
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
90
|
+
* Evaluate one generated registry file (`common.style.js`,
|
|
91
|
+
* `<variant>.style.js`, or `schemes.js`) so its `registerAtoms` /
|
|
92
|
+
* `registerBreakpoints` / `registerGradients` / `registerHaptics` /
|
|
93
|
+
* `registerSchemeLoader` calls land in the process-global registries the
|
|
94
|
+
* runtime resolver reads. Imports (`'rnwind'`, `'react-native'`, relative
|
|
95
|
+
* `./common.style`), `require(...)` loaders, and `export {...}` are
|
|
96
|
+
* stripped — every scheme file is evaluated directly, so lazy loaders are
|
|
97
|
+
* inert.
|
|
98
|
+
* @param filePath Absolute path to the generated file.
|
|
114
99
|
*/
|
|
115
|
-
function
|
|
116
|
-
const filePath = path.join(cacheDir, 'style.js');
|
|
100
|
+
function evaluateGeneratedFile(filePath) {
|
|
117
101
|
if (!existsSync(filePath))
|
|
118
102
|
return;
|
|
119
103
|
const body = readFileSync(filePath, 'utf8')
|
|
120
|
-
.replaceAll(/import
|
|
121
|
-
.replaceAll(/import
|
|
122
|
-
|
|
104
|
+
.replaceAll(/import\s+\{[^}]*\}\s+from\s+['"][^'"]+['"];?\s*\n?/g, '')
|
|
105
|
+
.replaceAll(/import\s+['"][^'"]+['"];?\s*\n?/g, '')
|
|
106
|
+
.replaceAll(/export\s+\{[^}]*\}\s*;?\s*\n?/g, '');
|
|
107
|
+
// Generated body is produced by rnwind itself — not user-controlled.
|
|
108
|
+
// `require` is neutralised: each variant file is evaluated directly,
|
|
109
|
+
// so the manifest's lazy `require('./x.style')` loaders are no-ops.
|
|
123
110
|
// eslint-disable-next-line sonarjs/code-eval
|
|
124
|
-
new Function('StyleSheet', 'registerAtoms', body)(BUNDLE_STYLE_SHEET, registerAtoms);
|
|
111
|
+
new Function('StyleSheet', 'registerAtoms', 'registerMolecules', 'registerBreakpoints', 'registerGradients', 'registerHaptics', 'registerSchemeLoader', 'require', body)(BUNDLE_STYLE_SHEET, registerAtoms, registerMolecules, registerBreakpoints, registerGradients, registerHaptics, registerSchemeLoader, () => { });
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Sort comparator that floats `common.style.js` to the front, rest alpha.
|
|
115
|
+
* @param a
|
|
116
|
+
* @param b
|
|
117
|
+
*/
|
|
118
|
+
function commonFirst(a, b) {
|
|
119
|
+
if (a === 'common.style.js')
|
|
120
|
+
return -1;
|
|
121
|
+
if (b === 'common.style.js')
|
|
122
|
+
return 1;
|
|
123
|
+
return a.localeCompare(b);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Evaluate every generated registry the transform wrote (`common` +
|
|
127
|
+
* every variant scheme + the manifest) so the runtime resolver sees the
|
|
128
|
+
* full atom / molecule / gradient / haptic registries — same state a
|
|
129
|
+
* production bundle would hold once all scheme files load.
|
|
130
|
+
* @param cacheDir The rnwind cache dir holding the generated files.
|
|
131
|
+
*/
|
|
132
|
+
function evaluateGeneratedRegistries(cacheDir) {
|
|
133
|
+
if (!existsSync(cacheDir))
|
|
134
|
+
return;
|
|
135
|
+
const files = readdirSync(cacheDir).filter((name) => name.endsWith('.style.js'));
|
|
136
|
+
// common first so variants layer their diffs on top of it.
|
|
137
|
+
for (const name of files.toSorted(commonFirst)) {
|
|
138
|
+
evaluateGeneratedFile(path.join(cacheDir, name));
|
|
139
|
+
}
|
|
140
|
+
evaluateGeneratedFile(path.join(cacheDir, 'schemes.js'));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Move every `const {…} = __rnwind;` / `const {…} = __reactNative;`
|
|
144
|
+
* binding line to the top of the source, preserving order, so they
|
|
145
|
+
* initialise before the transformer's `const View = _rnwWrap(_rnw0)`
|
|
146
|
+
* wrap declarations reference them. Mirrors ESM import hoisting.
|
|
147
|
+
* @param source Source with imports already converted to const-destructures.
|
|
148
|
+
* @returns Source with binding consts hoisted to the front.
|
|
149
|
+
*/
|
|
150
|
+
function hoistBindingConsts(source) {
|
|
151
|
+
const hoisted = [];
|
|
152
|
+
const rest = [];
|
|
153
|
+
for (const line of source.split('\n')) {
|
|
154
|
+
if (/=\s*__(?:rnwind|reactNative);\s*$/.test(line))
|
|
155
|
+
hoisted.push(line);
|
|
156
|
+
else
|
|
157
|
+
rest.push(line);
|
|
158
|
+
}
|
|
159
|
+
return [...hoisted, ...rest].join('\n');
|
|
125
160
|
}
|
|
126
161
|
/**
|
|
127
162
|
* Evaluate the transformer's rewritten source as a standalone module:
|
|
128
|
-
* strip synthetic imports, forward `import ... from 'rnwind'`
|
|
129
|
-
* `'react-native'` to local
|
|
130
|
-
* capture the default export.
|
|
163
|
+
* strip synthetic generated imports, forward `import ... from 'rnwind'`
|
|
164
|
+
* (incl. the injected `wrap as _rnwWrap`) and `'react-native'` to local
|
|
165
|
+
* bindings, compile JSX via the compiler, and capture the default export.
|
|
166
|
+
* Aliased named imports (`{ View as _rnw0 }`) are converted to valid
|
|
167
|
+
* destructuring (`{ View: _rnw0 }`). The import-derived `const`s are then
|
|
168
|
+
* hoisted above the body: the transformer injects `const View =
|
|
169
|
+
* _rnwWrap(_rnw0)` ahead of the (real-ESM-hoisted) `import … as _rnw0`,
|
|
170
|
+
* so without re-hoisting the binding the eval would hit a TDZ on `_rnw0`.
|
|
131
171
|
* @param transformedSource Post-transformer source.
|
|
132
172
|
* @param reactNative `react-native` namespace bindings to forward.
|
|
133
173
|
* @returns The default-exported component.
|
|
@@ -135,24 +175,14 @@ function evaluateStyleBundle(cacheDir) {
|
|
|
135
175
|
function evaluateRewrittenModule(transformedSource, reactNative) {
|
|
136
176
|
const prepared = transformedSource
|
|
137
177
|
.replaceAll(/import\s+["']rnwind\/__generated\/[^"']+["'];?\s*\n?/g, '')
|
|
138
|
-
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']rnwind["'];?/g,
|
|
139
|
-
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']react-native["'];?/g,
|
|
178
|
+
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']rnwind["'];?/g, (_m, spec) => `const {${spec.replaceAll(/\bas\b/g, ':')}} = __rnwind;`)
|
|
179
|
+
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']react-native["'];?/g, (_m, spec) => `const {${spec.replaceAll(/\bas\b/g, ':')}} = __reactNative;`)
|
|
140
180
|
.replace(/export\s+default\s+/, 'module.exports.default = ');
|
|
141
|
-
const compiled = compileToJs(prepared);
|
|
142
|
-
const rnwindEnv = {
|
|
143
|
-
lookupCss,
|
|
144
|
-
useRnwind,
|
|
145
|
-
useR_,
|
|
146
|
-
useMountHaptic,
|
|
147
|
-
triggerHaptic,
|
|
148
|
-
useInteract: () => NOOP_INTERACT,
|
|
149
|
-
chainPress: NOOP_CHAIN,
|
|
150
|
-
chainFocus: NOOP_CHAIN,
|
|
151
|
-
};
|
|
181
|
+
const compiled = compileToJs(hoistBindingConsts(prepared));
|
|
152
182
|
const moduleObject = { exports: {} };
|
|
153
183
|
// Compiled source originates from rnwind's own transformer + the JSX compiler.
|
|
154
184
|
// eslint-disable-next-line sonarjs/code-eval
|
|
155
|
-
new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React,
|
|
185
|
+
new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React, runtime_index, reactNative, moduleObject);
|
|
156
186
|
if (!moduleObject.exports.default) {
|
|
157
187
|
throw new Error('rnwind/testing: evaluated module did not export a default component.');
|
|
158
188
|
}
|
|
@@ -228,10 +258,11 @@ async function bootstrapRnwindRuntime(options) {
|
|
|
228
258
|
const ast = parse(options.source, { sourceType: 'module', plugins: ['typescript', 'jsx'] });
|
|
229
259
|
const result = await transform({ filename, src: options.source, options: { projectRoot }, ast });
|
|
230
260
|
transformedSource = generate(result.ast).code;
|
|
231
|
-
|
|
261
|
+
evaluateGeneratedRegistries(cacheDir);
|
|
232
262
|
}
|
|
233
263
|
const cleanup = () => {
|
|
234
264
|
__resetLookupCssState();
|
|
265
|
+
__resetResolveState();
|
|
235
266
|
resetRnwindState();
|
|
236
267
|
if (existsSync(projectRoot))
|
|
237
268
|
rmSync(projectRoot, { recursive: true, force: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/testing/index.ts"],"sourcesContent":["/* eslint-disable sonarjs/no-unused-vars */\nimport type { File as BabelFile } from '@babel/types'\nimport { parse } from '@babel/parser'\nimport generateImport from '@babel/generator'\nimport { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport path from 'node:path'\nimport * as React from 'react'\nimport type {\n render as testingLibraryRender,\n renderHook as testingLibraryRenderHook,\n RenderHookOptions,\n} from '@testing-library/react-native'\nimport { configureRnwindState, resetRnwindState, transform as metroTransform } from '../metro'\nimport { __resetLookupCssState, lookupCss, registerAtoms } from '../runtime/lookup-css'\nimport type { Insets } from '../runtime/components/rnwind-provider'\nimport { RnwindProvider, useRnwind, useR_ } from '../runtime/components/rnwind-provider'\nimport { triggerHaptic, useMountHaptic } from '../runtime/haptics'\nimport type { OnHaptics } from '../core/parser/haptics'\nimport type { Scheme } from '../runtime/types'\n\n// ────────────────────────────────────────────────────────────────────────\n// Private constants\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Minimal theme every `renderWithCss` call defaults to. Ships the two\n * conventional schemes so atoms carrying `dark:` / `light:` prefixes\n * resolve without the caller having to craft a theme CSS string.\n */\nconst DEFAULT_THEME_CSS = `@import 'tailwindcss';\n@layer theme {\n :root {\n @variant light { --color-bg: #ffffff; --color-fg: #0a0a0a; }\n @variant dark { --color-bg: #0a0a0a; --color-fg: #ffffff; }\n }\n}\n`\n\n/** `StyleSheet.create` stub the evaluated bundle calls — identity at test time. */\nconst BUNDLE_STYLE_SHEET = { create: <T>(styles: T): T => styles, hairlineWidth: 1 }\n\n/** Stubbed interactive-state hook return matching `useInteract()`. */\nconst NOOP_INTERACT = {\n state: undefined,\n onPressIn: (): void => undefined,\n onPressOut: (): void => undefined,\n onFocus: (): void => undefined,\n onBlur: (): void => undefined,\n}\n\n/**\n * Identity chain helper matching `chainPress` / `chainFocus`. Returns a\n * single callback that invokes every supplied handler in turn.\n * @param handlers Handlers to chain.\n * @returns Combined callback.\n */\nconst NOOP_CHAIN =\n (...handlers: ReadonlyArray<((...args: unknown[]) => unknown) | undefined>) =>\n (...args: unknown[]): void => {\n for (const handler of handlers) {\n if (typeof handler === 'function') handler(...args)\n }\n }\n\n// Synthesize a require rooted at the consumer's cwd so optional peer\n// lookups (`@testing-library/react-native`, `esbuild`) resolve from THEIR\n// node_modules, not rnwind's. A workspace-local rnwind install resolves\n// through a different node_modules chain than the test cwd — we want the\n// test's chain.\nconst localRequire: NodeRequire = createRequire(path.join(process.cwd(), 'package.json'))\n\nconst generate: typeof generateImport = (generateImport as { default?: typeof generateImport }).default ?? generateImport\n\n/**\n * Pre-loaded `@testing-library/react-native`. Resolved once at module\n * init (not lazily per-call) because the testing library registers\n * `beforeAll`/`afterEach` cleanup hooks on import — and Bun's test\n * runner refuses to register lifecycle hooks from inside a running\n * test body, which is where the first `renderWithCss` call lands.\n */\nconst TESTING_LIBRARY: {\n render: typeof testingLibraryRender\n renderHook: typeof testingLibraryRenderHook\n} = (() => {\n try {\n return localRequire('@testing-library/react-native') as {\n render: typeof testingLibraryRender\n renderHook: typeof testingLibraryRenderHook\n }\n } catch (error) {\n throw new Error(\n 'rnwind/testing: cannot load `@testing-library/react-native`. Add it to your dev dependencies. Underlying error: ' +\n (error instanceof Error ? error.message : String(error)),\n )\n }\n})()\n\n// ────────────────────────────────────────────────────────────────────────\n// Private helpers\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Scheme string typed to match what `<RnwindProvider>` accepts. Users\n * who declare their own scheme names via `rnwind-types.d.ts` get them\n * through `Scheme`; everyone else gets `'light' | 'dark' | string`.\n */\ntype SchemeName = Scheme\n\n/**\n * Default lookup for the test process's `react-native` module. Users\n * who run with a mocked `react-native` (via Bun's `mock.module` or\n * Jest's `jest.mock`) get the mock here automatically.\n * @returns React Native namespace bindings.\n */\nfunction resolveReactNative(): Record<string, unknown> {\n return localRequire('react-native') as Record<string, unknown>\n}\n\n/**\n * Compile JSX + TypeScript source to plain JS. Prefers Bun's built-in\n * transpiler (fast, zero-dep); falls back to `esbuild` if running under\n * Node (Jest users). Throws with an install hint if neither is available.\n * @param source Source text to compile.\n * @returns JavaScript suitable for `new Function(...)` evaluation.\n */\nfunction compileToJs(source: string): string {\n const globalBun = (\n globalThis as { Bun?: { Transpiler: new (options: unknown) => { transformSync: (text: string) => string } } }\n ).Bun\n if (globalBun?.Transpiler) {\n return new globalBun.Transpiler({\n loader: 'tsx',\n tsconfig: JSON.stringify({ compilerOptions: { jsx: 'react', target: 'esnext' } }),\n }).transformSync(source)\n }\n try {\n const esbuild = localRequire('esbuild') as {\n transformSync: (text: string, options: { loader: string; jsx: string; target?: string }) => { code: string }\n }\n return esbuild.transformSync(source, { loader: 'tsx', jsx: 'transform', target: 'esnext' }).code\n } catch {\n throw new Error(\n 'rnwind/testing: cannot compile JSX. Run tests under Bun (which has a built-in transpiler) ' +\n 'or install `esbuild` as a dev dependency for Node / Jest setups.',\n )\n }\n}\n\n/**\n * Evaluate the union `style.js` the ledger wrote during the transform\n * so its `registerAtoms` call lands in the process-global registry.\n * Strips the `react-native` + `rnwind` imports from the source and\n * forwards local bindings into the evaluated closure.\n * @param cacheDir The rnwind cache dir where the ledger writes bundles.\n */\nfunction evaluateStyleBundle(cacheDir: string): void {\n const filePath = path.join(cacheDir, 'style.js')\n if (!existsSync(filePath)) return\n const body = readFileSync(filePath, 'utf8')\n .replaceAll(/import \\{ StyleSheet \\} from 'react-native'\\s*\\n/g, '')\n .replaceAll(/import \\{[^}]+\\} from 'rnwind'\\s*\\n/g, '')\n // Bundle body is generated by rnwind itself — not user-controlled.\n // eslint-disable-next-line sonarjs/code-eval\n new Function('StyleSheet', 'registerAtoms', body)(BUNDLE_STYLE_SHEET, registerAtoms)\n}\n\n/**\n * Evaluate the transformer's rewritten source as a standalone module:\n * strip synthetic imports, forward `import ... from 'rnwind'` +\n * `'react-native'` to local bindings, compile JSX via the compiler, and\n * capture the default export.\n * @param transformedSource Post-transformer source.\n * @param reactNative `react-native` namespace bindings to forward.\n * @returns The default-exported component.\n */\nfunction evaluateRewrittenModule(\n transformedSource: string,\n reactNative: Record<string, unknown>,\n): React.ComponentType<Record<string, unknown>> {\n const prepared = transformedSource\n .replaceAll(/import\\s+[\"']rnwind\\/__generated\\/[^\"']+[\"'];?\\s*\\n?/g, '')\n .replaceAll(/import\\s+\\{([^}]+)\\}\\s+from\\s+[\"']rnwind[\"'];?/g, 'const {$1} = __rnwind;')\n .replaceAll(/import\\s+\\{([^}]+)\\}\\s+from\\s+[\"']react-native[\"'];?/g, 'const {$1} = __reactNative;')\n .replace(/export\\s+default\\s+/, 'module.exports.default = ')\n\n const compiled = compileToJs(prepared)\n const rnwindEnv = {\n lookupCss,\n useRnwind,\n useR_,\n useMountHaptic,\n triggerHaptic,\n useInteract: () => NOOP_INTERACT,\n chainPress: NOOP_CHAIN,\n chainFocus: NOOP_CHAIN,\n }\n const moduleObject: { exports: { default?: React.ComponentType<Record<string, unknown>> } } = { exports: {} }\n // Compiled source originates from rnwind's own transformer + the JSX compiler.\n // eslint-disable-next-line sonarjs/code-eval\n new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React, rnwindEnv, reactNative, moduleObject)\n if (!moduleObject.exports.default) {\n throw new Error('rnwind/testing: evaluated module did not export a default component.')\n }\n return moduleObject.exports.default\n}\n\n/**\n * Build the root element `@testing-library/react-native`'s `render`\n * receives. When a scheme is specified, wrap the component in a live\n * `<RnwindProvider>` so hooks like `useScheme()` and `useCss()` return\n * the requested scheme. Otherwise render bare (context falls back to the\n * default `'light'`).\n * @param Component Component to render.\n * @param scheme Optional active scheme override.\n * @param insets\n * @param onHaptics\n * @returns The React element to hand to `render`.\n */\nfunction buildRootElement(\n Component: React.ComponentType<Record<string, unknown>>,\n scheme: string | undefined,\n insets: Partial<Insets> | undefined,\n onHaptics: OnHaptics | undefined,\n): React.ReactElement {\n const child = React.createElement(Component)\n if (scheme === undefined && !insets && !onHaptics) return child\n const providerProps: { scheme: SchemeName; insets?: Partial<Insets>; onHaptics?: OnHaptics } = {\n scheme: (scheme ?? 'light') as SchemeName,\n }\n if (insets) providerProps.insets = insets\n if (onHaptics) providerProps.onHaptics = onHaptics\n return React.createElement(RnwindProvider, providerProps, child)\n}\n\n/**\n * Compose the `wrapper` option `renderHook` accepts. When a scheme is\n * set, wrap the hook's execution context in `<RnwindProvider>` so hooks\n * that read `useScheme()` see the requested scheme. If the user also\n * supplies their own wrapper, nest it inside the provider so both apply.\n * @param scheme Optional active scheme override.\n * @param userWrapper Optional user-supplied wrapper component.\n * @returns A wrapper component suitable for `renderHook`'s `wrapper` option.\n */\nfunction composeHookWrapper(\n scheme: string | undefined,\n userWrapper: React.ComponentType<{ children?: React.ReactNode }> | undefined,\n): React.ComponentType<{ children?: React.ReactNode }> | undefined {\n if (scheme === undefined && !userWrapper) return undefined\n return function RnwindTestWrapper({ children }: { children?: React.ReactNode }): React.ReactElement {\n const inner = userWrapper ? React.createElement(userWrapper, null, children) : (children as React.ReactElement)\n if (scheme === undefined) return inner\n return React.createElement(RnwindProvider, { scheme: scheme as SchemeName }, inner)\n }\n}\n\n/**\n * Spin up an ephemeral rnwind project and register the atoms produced\n * by `source` (when provided) into the runtime. Returns the project\n * state and the post-transform source so callers can render the\n * rewritten module or just rely on the registered atoms.\n *\n * Shared between `renderWithCss` (needs the rewritten component) and\n * `renderHookWithCss` (only needs the atoms in the registry).\n * @param options Options controlling the theme and pre-registered source.\n * @param options.themeCss Theme CSS override.\n * @param options.source Source whose Tailwind candidates should be registered.\n * @returns Paths plus the transformed source and a `cleanup` closure.\n */\nasync function bootstrapRnwindRuntime(options: { themeCss?: string; source?: string }): Promise<{\n projectRoot: string\n cacheDir: string\n transformedSource: string\n cleanup: () => void\n}> {\n const projectRoot = mkdtempSync(path.join(tmpdir(), 'rnwind-test-'))\n const cacheDir = path.join(projectRoot, '.rnwind-cache')\n const cssPath = path.join(projectRoot, 'theme.css')\n writeFileSync(cssPath, options.themeCss ?? DEFAULT_THEME_CSS)\n configureRnwindState(cssPath, cacheDir)\n\n let transformedSource = ''\n if (options.source !== undefined) {\n const filename = path.join(projectRoot, 'App.tsx')\n writeFileSync(filename, options.source)\n const ast: BabelFile = parse(options.source, { sourceType: 'module', plugins: ['typescript', 'jsx'] })\n const result = await metroTransform({ filename, src: options.source, options: { projectRoot }, ast })\n transformedSource = generate(result.ast).code\n evaluateStyleBundle(cacheDir)\n }\n\n const cleanup = (): void => {\n __resetLookupCssState()\n resetRnwindState()\n if (existsSync(projectRoot)) rmSync(projectRoot, { recursive: true, force: true })\n }\n\n return { projectRoot, cacheDir, transformedSource, cleanup }\n}\n\n/**\n * Synthesize a throwaway source file that mentions each className in a\n * JSX `className=\"...\"` attribute so the Metro transformer's scanner\n * picks them up and records their resolved styles into the union\n * `style.js`. Used by `renderHookWithCss` to pre-register atoms the\n * hook under test will look up.\n * @param classNames Class names to include.\n * @returns Source string suitable for `bootstrapRnwindRuntime`.\n */\nfunction sourceFromClassNames(classNames: readonly string[]): string {\n const joined = classNames.join(' ').replaceAll('\"', String.raw`\\\"`)\n return `const V: any = () => null\\nexport default () => <V className=\"${joined}\" />\\n`\n}\n\n// ────────────────────────────────────────────────────────────────────────\n// Public exports — types\n// ────────────────────────────────────────────────────────────────────────\n\n/** Exact signature of `@testing-library/react-native`'s `render`. */\nexport type Render = typeof testingLibraryRender\n\n/** Exact signature of `@testing-library/react-native`'s `renderHook`. */\nexport type RenderHook = typeof testingLibraryRenderHook\n\n/**\n * Exact return type of `@testing-library/react-native`'s `render` — we\n * re-export the upstream type so tests get every query (`getByTestId`,\n * `queryByText`, `rerender`, `unmount`, `debug`, `UNSAFE_root`, …) with\n * its real signature.\n */\nexport type TestingLibraryRenderAPI = ReturnType<typeof testingLibraryRender>\n\n/** Options accepted by {@link renderWithCss}. */\nexport interface RenderWithCssOptions {\n /** Theme CSS fed to rnwind's parser. Defaults to {@link DEFAULT_THEME_CSS}. */\n themeCss?: string\n /**\n * Active scheme the runtime resolver uses. Defaults to `'light'`.\n * Flip to `'dark'` / `'brand'` / ... to exercise scheme-variant atoms.\n */\n scheme?: string\n /**\n * Safe-area insets to inject. When provided, the component tree is\n * rendered under a `<RnwindProvider insets={...}>` so `*-safe` atoms\n * resolve to real numbers instead of the `0` fallback. Partial is\n * accepted — missing sides default to zero.\n */\n insets?: Partial<Insets>\n /**\n * Haptic dispatcher forwarded onto the implicit `<RnwindProvider>`.\n * Tests pass a spy callback to assert which haptic atoms fired.\n */\n onHaptics?: OnHaptics\n /**\n * `react-native` namespace bindings forwarded into the rewritten\n * module. Defaults to importing the test process's `react-native`\n * (typically a mocked stub). Override to inject custom host elements.\n */\n reactNative?: Record<string, unknown>\n}\n\n/**\n * Result of a {@link renderWithCss} call. Every key from\n * `@testing-library/react-native`'s `render` return value is spread onto\n * this object — `getByTestId`, `queryByText`, `rerender`, `unmount`,\n * `debug`, etc. — so tests use the testing-library API directly.\n *\n * Two rnwind-specific handles are added:\n * - `transformedSource` — the exact code the rnwind Metro transformer\n * emitted for your input. Log it to confirm the rewrite.\n * - `cleanup` — tears down the ephemeral rnwind state + chunk cache dir.\n * Call from `afterEach` so successive tests don't share atoms.\n */\nexport type RenderWithCssResult = TestingLibraryRenderAPI & {\n /** The post-transformer source text. Same code Metro would ship. */\n transformedSource: string\n /** Tear down the ephemeral rnwind state + cache dir. */\n cleanup: () => void\n}\n\n/** Options accepted by {@link renderHookWithCss}. */\nexport interface RenderHookWithCssOptions<Props> extends RenderHookOptions<Props> {\n /** Theme CSS fed to rnwind's parser. Defaults to the built-in minimal theme. */\n themeCss?: string\n /**\n * Active scheme the runtime resolver uses. Defaults to `'light'`. When\n * set, the hook is wrapped in `<RnwindProvider scheme={scheme}>` so\n * `useScheme()` / `useCss()` observe the override.\n */\n scheme?: string\n /**\n * Class names to pre-register into the runtime atom registry before\n * the hook runs. rnwind synthesizes a throwaway source file mentioning\n * these classes, feeds it through the real Metro transformer, and\n * evaluates the generated `style.js` bundle — so the hook sees\n * exactly the atoms the production bundle would register.\n */\n classNames?: readonly string[]\n}\n\n/**\n * Result of a {@link renderHookWithCss} call. Mirrors\n * `@testing-library/react-native`'s `renderHook` return type — `result`,\n * `rerender`, `unmount` — and adds a `cleanup` that tears down the\n * ephemeral rnwind state.\n */\nexport type RenderHookWithCssResult<Result, Props> = ReturnType<typeof testingLibraryRenderHook<Result, Props>> & {\n /** Tear down the ephemeral rnwind state + cache dir. */\n cleanup: () => void\n}\n\n// ────────────────────────────────────────────────────────────────────────\n// Public exports — functions\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Feed a source string through rnwind's Metro transformer, evaluate\n * the generated `style.js` bundle, evaluate the rewritten module, and\n * render the default-exported component with\n * `@testing-library/react-native`.\n *\n * The rendered RN element's `style` prop is the EXACT array your\n * production bundle would attach — same transformer, same runtime\n * resolver, same atoms. Assert on `flatten(node.props.style)` to verify\n * the resolved values.\n * @example\n * ```tsx\n * const handle = await renderWithCss(\n * `import { View } from 'react-native'\n * export default () => <View className=\"bg-primary p-4\" testID=\"box\" />`,\n * { themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }` },\n * )\n * const flat = flatten(handle.getByTestId('box').props.style)\n * expect(flat.backgroundColor).toBe('#6366f1')\n * ```\n * @param source User source (one file) to transform + render.\n * @param options Optional theme override, scheme, and `react-native` bindings.\n * @returns Render queries + diagnostic handles.\n */\nexport async function renderWithCss(source: string, options: RenderWithCssOptions = {}): Promise<RenderWithCssResult> {\n const reactNative = options.reactNative ?? resolveReactNative()\n const {\n projectRoot: _projectRoot,\n transformedSource,\n cleanup,\n } = await bootstrapRnwindRuntime({\n themeCss: options.themeCss,\n source,\n })\n const Component = evaluateRewrittenModule(transformedSource, reactNative)\n const rendered = TESTING_LIBRARY.render(buildRootElement(Component, options.scheme, options.insets, options.onHaptics))\n return Object.assign({}, rendered, { transformedSource, cleanup })\n}\n\n/**\n * Render-side counterpart to {@link renderWithCss} for testing hooks in\n * isolation. Pre-registers atoms for the supplied `classNames`, wraps\n * the hook in an optional `<RnwindProvider>`, and forwards to\n * `@testing-library/react-native`'s `renderHook`.\n * @example\n * ```ts\n * const { result, cleanup } = await renderHookWithCss(\n * () => useCss('bg-primary'),\n * {\n * themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }`,\n * classNames: ['bg-primary'],\n * },\n * )\n * expect(flatten(result.current).backgroundColor).toBe('#6366f1')\n * cleanup()\n * ```\n * @param callback Hook body — same shape as `renderHook(callback)`.\n * @param options Theme, scheme, classNames to pre-register, plus\n * everything `renderHook` itself accepts (`initialProps`, `wrapper`).\n * @returns `renderHook`'s return value plus a `cleanup` function.\n */\nexport async function renderHookWithCss<Result, Props = unknown>(\n callback: (props: Props) => Result,\n options: RenderHookWithCssOptions<Props> = {},\n): Promise<RenderHookWithCssResult<Result, Props>> {\n const { cleanup } = await bootstrapRnwindRuntime({\n themeCss: options.themeCss,\n source: options.classNames && options.classNames.length > 0 ? sourceFromClassNames(options.classNames) : undefined,\n })\n const wrapper = composeHookWrapper(options.scheme, options.wrapper as RenderHookWithCssOptions<Props>['wrapper'])\n const { themeCss: _themeCss, scheme: _scheme, classNames: _classNames, ...hookOptions } = options\n const rendered = TESTING_LIBRARY.renderHook<Result, Props>(callback, {\n ...(hookOptions as RenderHookOptions<Props>),\n wrapper,\n })\n return Object.assign({}, rendered, { cleanup })\n}\n\n/**\n * Flatten a React Native style array (or single style object) into one\n * merged record. RN flattens left-to-right (later wins), so the returned\n * record is what the native view manager actually applies.\n * @param styles Style array, single object, or null/undefined.\n * @returns Flat style record.\n */\nexport function flatten(styles: unknown): Record<string, unknown> {\n if (styles == null) return {}\n if (Array.isArray(styles)) return Object.assign({}, ...styles.map((entry) => flatten(entry)))\n if (typeof styles === 'object') return styles as Record<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,EAAE;AACnE,QAAA,GAAI,WAAwC;QAC5C,OAAO;AACR,KAAA,CAAC;AACF,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC;AACjD;AAEA;;;;;;AAMG;AACG,SAAU,OAAO,CAAC,MAAe,EAAA;IACrC,IAAI,MAAM,IAAI,IAAI;AAAE,QAAA,OAAO,EAAE;AAC7B,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7F,IAAI,OAAO,MAAM,KAAK,QAAQ;AAAE,QAAA,OAAO,MAAiC;AACxE,IAAA,OAAO,EAAE;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/testing/index.ts"],"sourcesContent":["/* eslint-disable sonarjs/no-unused-vars */\nimport type { File as BabelFile } from '@babel/types'\nimport { parse } from '@babel/parser'\nimport generateImport from '@babel/generator'\nimport { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport path from 'node:path'\nimport * as React from 'react'\nimport type {\n render as testingLibraryRender,\n renderHook as testingLibraryRenderHook,\n RenderHookOptions,\n} from '@testing-library/react-native'\nimport { configureRnwindState, resetRnwindState, transform as metroTransform } from '../metro'\nimport {\n __resetLookupCssState,\n registerAtoms,\n registerBreakpoints,\n registerSchemeLoader,\n} from '../runtime/lookup-css'\nimport { __resetResolveState, registerGradients, registerHaptics, registerMolecules } from '../runtime/resolve'\nimport * as rnwindRuntime from '../runtime'\nimport type { Insets } from '../runtime/components/rnwind-provider'\nimport { RnwindProvider } from '../runtime/components/rnwind-provider'\nimport type { OnHaptics } from '../core/parser/haptics'\nimport type { Scheme } from '../runtime/types'\n\n// ────────────────────────────────────────────────────────────────────────\n// Private constants\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Minimal theme every `renderWithCss` call defaults to. Ships the two\n * conventional schemes so atoms carrying `dark:` / `light:` prefixes\n * resolve without the caller having to craft a theme CSS string.\n */\nconst DEFAULT_THEME_CSS = `@import 'tailwindcss';\n@layer theme {\n :root {\n @variant light { --color-bg: #ffffff; --color-fg: #0a0a0a; }\n @variant dark { --color-bg: #0a0a0a; --color-fg: #ffffff; }\n }\n}\n`\n\n/** `StyleSheet.create` stub the evaluated bundle calls — identity at test time. */\nconst BUNDLE_STYLE_SHEET = { create: <T>(styles: T): T => styles, hairlineWidth: 1 }\n\n// Synthesize a require rooted at the consumer's cwd so optional peer\n// lookups (`@testing-library/react-native`, `esbuild`) resolve from THEIR\n// node_modules, not rnwind's. A workspace-local rnwind install resolves\n// through a different node_modules chain than the test cwd — we want the\n// test's chain.\nconst localRequire: NodeRequire = createRequire(path.join(process.cwd(), 'package.json'))\n\nconst generate: typeof generateImport = (generateImport as { default?: typeof generateImport }).default ?? generateImport\n\n/**\n * Pre-loaded `@testing-library/react-native`. Resolved once at module\n * init (not lazily per-call) because the testing library registers\n * `beforeAll`/`afterEach` cleanup hooks on import — and Bun's test\n * runner refuses to register lifecycle hooks from inside a running\n * test body, which is where the first `renderWithCss` call lands.\n */\nconst TESTING_LIBRARY: {\n render: typeof testingLibraryRender\n renderHook: typeof testingLibraryRenderHook\n} = (() => {\n try {\n return localRequire('@testing-library/react-native') as {\n render: typeof testingLibraryRender\n renderHook: typeof testingLibraryRenderHook\n }\n } catch (error) {\n throw new Error(\n 'rnwind/testing: cannot load `@testing-library/react-native`. Add it to your dev dependencies. Underlying error: ' +\n (error instanceof Error ? error.message : String(error)),\n )\n }\n})()\n\n// ────────────────────────────────────────────────────────────────────────\n// Private helpers\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Scheme string typed to match what `<RnwindProvider>` accepts. Users\n * who declare their own scheme names via `rnwind-types.d.ts` get them\n * through `Scheme`; everyone else gets `'light' | 'dark' | string`.\n */\ntype SchemeName = Scheme\n\n/**\n * Default lookup for the test process's `react-native` module. Users\n * who run with a mocked `react-native` (via Bun's `mock.module` or\n * Jest's `jest.mock`) get the mock here automatically.\n * @returns React Native namespace bindings.\n */\nfunction resolveReactNative(): Record<string, unknown> {\n return localRequire('react-native') as Record<string, unknown>\n}\n\n/**\n * Compile JSX + TypeScript source to plain JS. Prefers Bun's built-in\n * transpiler (fast, zero-dep); falls back to `esbuild` if running under\n * Node (Jest users). Throws with an install hint if neither is available.\n * @param source Source text to compile.\n * @returns JavaScript suitable for `new Function(...)` evaluation.\n */\nfunction compileToJs(source: string): string {\n const globalBun = (\n globalThis as { Bun?: { Transpiler: new (options: unknown) => { transformSync: (text: string) => string } } }\n ).Bun\n if (globalBun?.Transpiler) {\n return new globalBun.Transpiler({\n loader: 'tsx',\n tsconfig: JSON.stringify({ compilerOptions: { jsx: 'react', target: 'esnext' } }),\n }).transformSync(source)\n }\n try {\n const esbuild = localRequire('esbuild') as {\n transformSync: (text: string, options: { loader: string; jsx: string; target?: string }) => { code: string }\n }\n return esbuild.transformSync(source, { loader: 'tsx', jsx: 'transform', target: 'esnext' }).code\n } catch {\n throw new Error(\n 'rnwind/testing: cannot compile JSX. Run tests under Bun (which has a built-in transpiler) ' +\n 'or install `esbuild` as a dev dependency for Node / Jest setups.',\n )\n }\n}\n\n/**\n * Evaluate one generated registry file (`common.style.js`,\n * `<variant>.style.js`, or `schemes.js`) so its `registerAtoms` /\n * `registerBreakpoints` / `registerGradients` / `registerHaptics` /\n * `registerSchemeLoader` calls land in the process-global registries the\n * runtime resolver reads. Imports (`'rnwind'`, `'react-native'`, relative\n * `./common.style`), `require(...)` loaders, and `export {...}` are\n * stripped — every scheme file is evaluated directly, so lazy loaders are\n * inert.\n * @param filePath Absolute path to the generated file.\n */\nfunction evaluateGeneratedFile(filePath: string): void {\n if (!existsSync(filePath)) return\n const body = readFileSync(filePath, 'utf8')\n .replaceAll(/import\\s+\\{[^}]*\\}\\s+from\\s+['\"][^'\"]+['\"];?\\s*\\n?/g, '')\n .replaceAll(/import\\s+['\"][^'\"]+['\"];?\\s*\\n?/g, '')\n .replaceAll(/export\\s+\\{[^}]*\\}\\s*;?\\s*\\n?/g, '')\n // Generated body is produced by rnwind itself — not user-controlled.\n // `require` is neutralised: each variant file is evaluated directly,\n // so the manifest's lazy `require('./x.style')` loaders are no-ops.\n // eslint-disable-next-line sonarjs/code-eval\n new Function(\n 'StyleSheet',\n 'registerAtoms',\n 'registerMolecules',\n 'registerBreakpoints',\n 'registerGradients',\n 'registerHaptics',\n 'registerSchemeLoader',\n 'require',\n body,\n )(\n BUNDLE_STYLE_SHEET,\n registerAtoms,\n registerMolecules,\n registerBreakpoints,\n registerGradients,\n registerHaptics,\n registerSchemeLoader,\n () => {},\n )\n}\n\n/**\n * Sort comparator that floats `common.style.js` to the front, rest alpha.\n * @param a\n * @param b\n */\nfunction commonFirst(a: string, b: string): number {\n if (a === 'common.style.js') return -1\n if (b === 'common.style.js') return 1\n return a.localeCompare(b)\n}\n\n/**\n * Evaluate every generated registry the transform wrote (`common` +\n * every variant scheme + the manifest) so the runtime resolver sees the\n * full atom / molecule / gradient / haptic registries — same state a\n * production bundle would hold once all scheme files load.\n * @param cacheDir The rnwind cache dir holding the generated files.\n */\nfunction evaluateGeneratedRegistries(cacheDir: string): void {\n if (!existsSync(cacheDir)) return\n const files = readdirSync(cacheDir).filter((name) => name.endsWith('.style.js'))\n // common first so variants layer their diffs on top of it.\n for (const name of files.toSorted(commonFirst)) {\n evaluateGeneratedFile(path.join(cacheDir, name))\n }\n evaluateGeneratedFile(path.join(cacheDir, 'schemes.js'))\n}\n\n/**\n * Move every `const {…} = __rnwind;` / `const {…} = __reactNative;`\n * binding line to the top of the source, preserving order, so they\n * initialise before the transformer's `const View = _rnwWrap(_rnw0)`\n * wrap declarations reference them. Mirrors ESM import hoisting.\n * @param source Source with imports already converted to const-destructures.\n * @returns Source with binding consts hoisted to the front.\n */\nfunction hoistBindingConsts(source: string): string {\n const hoisted: string[] = []\n const rest: string[] = []\n for (const line of source.split('\\n')) {\n if (/=\\s*__(?:rnwind|reactNative);\\s*$/.test(line)) hoisted.push(line)\n else rest.push(line)\n }\n return [...hoisted, ...rest].join('\\n')\n}\n\n/**\n * Evaluate the transformer's rewritten source as a standalone module:\n * strip synthetic generated imports, forward `import ... from 'rnwind'`\n * (incl. the injected `wrap as _rnwWrap`) and `'react-native'` to local\n * bindings, compile JSX via the compiler, and capture the default export.\n * Aliased named imports (`{ View as _rnw0 }`) are converted to valid\n * destructuring (`{ View: _rnw0 }`). The import-derived `const`s are then\n * hoisted above the body: the transformer injects `const View =\n * _rnwWrap(_rnw0)` ahead of the (real-ESM-hoisted) `import … as _rnw0`,\n * so without re-hoisting the binding the eval would hit a TDZ on `_rnw0`.\n * @param transformedSource Post-transformer source.\n * @param reactNative `react-native` namespace bindings to forward.\n * @returns The default-exported component.\n */\nfunction evaluateRewrittenModule(\n transformedSource: string,\n reactNative: Record<string, unknown>,\n): React.ComponentType<Record<string, unknown>> {\n const prepared = transformedSource\n .replaceAll(/import\\s+[\"']rnwind\\/__generated\\/[^\"']+[\"'];?\\s*\\n?/g, '')\n .replaceAll(/import\\s+\\{([^}]+)\\}\\s+from\\s+[\"']rnwind[\"'];?/g, (_m, spec: string) => `const {${spec.replaceAll(/\\bas\\b/g, ':')}} = __rnwind;`)\n .replaceAll(/import\\s+\\{([^}]+)\\}\\s+from\\s+[\"']react-native[\"'];?/g, (_m, spec: string) => `const {${spec.replaceAll(/\\bas\\b/g, ':')}} = __reactNative;`)\n .replace(/export\\s+default\\s+/, 'module.exports.default = ')\n\n const compiled = compileToJs(hoistBindingConsts(prepared))\n const moduleObject: { exports: { default?: React.ComponentType<Record<string, unknown>> } } = { exports: {} }\n // Compiled source originates from rnwind's own transformer + the JSX compiler.\n // eslint-disable-next-line sonarjs/code-eval\n new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React, rnwindRuntime, reactNative, moduleObject)\n if (!moduleObject.exports.default) {\n throw new Error('rnwind/testing: evaluated module did not export a default component.')\n }\n return moduleObject.exports.default\n}\n\n/**\n * Build the root element `@testing-library/react-native`'s `render`\n * receives. When a scheme is specified, wrap the component in a live\n * `<RnwindProvider>` so hooks like `useScheme()` and `useCss()` return\n * the requested scheme. Otherwise render bare (context falls back to the\n * default `'light'`).\n * @param Component Component to render.\n * @param scheme Optional active scheme override.\n * @param insets\n * @param onHaptics\n * @returns The React element to hand to `render`.\n */\nfunction buildRootElement(\n Component: React.ComponentType<Record<string, unknown>>,\n scheme: string | undefined,\n insets: Partial<Insets> | undefined,\n onHaptics: OnHaptics | undefined,\n): React.ReactElement {\n const child = React.createElement(Component)\n if (scheme === undefined && !insets && !onHaptics) return child\n const providerProps: { scheme: SchemeName; insets?: Partial<Insets>; onHaptics?: OnHaptics } = {\n scheme: (scheme ?? 'light') as SchemeName,\n }\n if (insets) providerProps.insets = insets\n if (onHaptics) providerProps.onHaptics = onHaptics\n return React.createElement(RnwindProvider, providerProps, child)\n}\n\n/**\n * Compose the `wrapper` option `renderHook` accepts. When a scheme is\n * set, wrap the hook's execution context in `<RnwindProvider>` so hooks\n * that read `useScheme()` see the requested scheme. If the user also\n * supplies their own wrapper, nest it inside the provider so both apply.\n * @param scheme Optional active scheme override.\n * @param userWrapper Optional user-supplied wrapper component.\n * @returns A wrapper component suitable for `renderHook`'s `wrapper` option.\n */\nfunction composeHookWrapper(\n scheme: string | undefined,\n userWrapper: React.ComponentType<{ children?: React.ReactNode }> | undefined,\n): React.ComponentType<{ children?: React.ReactNode }> | undefined {\n if (scheme === undefined && !userWrapper) return undefined\n return function RnwindTestWrapper({ children }: { children?: React.ReactNode }): React.ReactElement {\n const inner = userWrapper ? React.createElement(userWrapper, null, children) : (children as React.ReactElement)\n if (scheme === undefined) return inner\n return React.createElement(RnwindProvider, { scheme: scheme as SchemeName }, inner)\n }\n}\n\n/**\n * Spin up an ephemeral rnwind project and register the atoms produced\n * by `source` (when provided) into the runtime. Returns the project\n * state and the post-transform source so callers can render the\n * rewritten module or just rely on the registered atoms.\n *\n * Shared between `renderWithCss` (needs the rewritten component) and\n * `renderHookWithCss` (only needs the atoms in the registry).\n * @param options Options controlling the theme and pre-registered source.\n * @param options.themeCss Theme CSS override.\n * @param options.source Source whose Tailwind candidates should be registered.\n * @returns Paths plus the transformed source and a `cleanup` closure.\n */\nasync function bootstrapRnwindRuntime(options: { themeCss?: string; source?: string }): Promise<{\n projectRoot: string\n cacheDir: string\n transformedSource: string\n cleanup: () => void\n}> {\n const projectRoot = mkdtempSync(path.join(tmpdir(), 'rnwind-test-'))\n const cacheDir = path.join(projectRoot, '.rnwind-cache')\n const cssPath = path.join(projectRoot, 'theme.css')\n writeFileSync(cssPath, options.themeCss ?? DEFAULT_THEME_CSS)\n configureRnwindState(cssPath, cacheDir)\n\n let transformedSource = ''\n if (options.source !== undefined) {\n const filename = path.join(projectRoot, 'App.tsx')\n writeFileSync(filename, options.source)\n const ast: BabelFile = parse(options.source, { sourceType: 'module', plugins: ['typescript', 'jsx'] })\n const result = await metroTransform({ filename, src: options.source, options: { projectRoot }, ast })\n transformedSource = generate(result.ast).code\n evaluateGeneratedRegistries(cacheDir)\n }\n\n const cleanup = (): void => {\n __resetLookupCssState()\n __resetResolveState()\n resetRnwindState()\n if (existsSync(projectRoot)) rmSync(projectRoot, { recursive: true, force: true })\n }\n\n return { projectRoot, cacheDir, transformedSource, cleanup }\n}\n\n/**\n * Synthesize a throwaway source file that mentions each className in a\n * JSX `className=\"...\"` attribute so the Metro transformer's scanner\n * picks them up and records their resolved styles into the union\n * `style.js`. Used by `renderHookWithCss` to pre-register atoms the\n * hook under test will look up.\n * @param classNames Class names to include.\n * @returns Source string suitable for `bootstrapRnwindRuntime`.\n */\nfunction sourceFromClassNames(classNames: readonly string[]): string {\n const joined = classNames.join(' ').replaceAll('\"', String.raw`\\\"`)\n return `const V: any = () => null\\nexport default () => <V className=\"${joined}\" />\\n`\n}\n\n// ────────────────────────────────────────────────────────────────────────\n// Public exports — types\n// ────────────────────────────────────────────────────────────────────────\n\n/** Exact signature of `@testing-library/react-native`'s `render`. */\nexport type Render = typeof testingLibraryRender\n\n/** Exact signature of `@testing-library/react-native`'s `renderHook`. */\nexport type RenderHook = typeof testingLibraryRenderHook\n\n/**\n * Exact return type of `@testing-library/react-native`'s `render` — we\n * re-export the upstream type so tests get every query (`getByTestId`,\n * `queryByText`, `rerender`, `unmount`, `debug`, `UNSAFE_root`, …) with\n * its real signature.\n */\nexport type TestingLibraryRenderAPI = ReturnType<typeof testingLibraryRender>\n\n/** Options accepted by {@link renderWithCss}. */\nexport interface RenderWithCssOptions {\n /** Theme CSS fed to rnwind's parser. Defaults to {@link DEFAULT_THEME_CSS}. */\n themeCss?: string\n /**\n * Active scheme the runtime resolver uses. Defaults to `'light'`.\n * Flip to `'dark'` / `'brand'` / ... to exercise scheme-variant atoms.\n */\n scheme?: string\n /**\n * Safe-area insets to inject. When provided, the component tree is\n * rendered under a `<RnwindProvider insets={...}>` so `*-safe` atoms\n * resolve to real numbers instead of the `0` fallback. Partial is\n * accepted — missing sides default to zero.\n */\n insets?: Partial<Insets>\n /**\n * Haptic dispatcher forwarded onto the implicit `<RnwindProvider>`.\n * Tests pass a spy callback to assert which haptic atoms fired.\n */\n onHaptics?: OnHaptics\n /**\n * `react-native` namespace bindings forwarded into the rewritten\n * module. Defaults to importing the test process's `react-native`\n * (typically a mocked stub). Override to inject custom host elements.\n */\n reactNative?: Record<string, unknown>\n}\n\n/**\n * Result of a {@link renderWithCss} call. Every key from\n * `@testing-library/react-native`'s `render` return value is spread onto\n * this object — `getByTestId`, `queryByText`, `rerender`, `unmount`,\n * `debug`, etc. — so tests use the testing-library API directly.\n *\n * Two rnwind-specific handles are added:\n * - `transformedSource` — the exact code the rnwind Metro transformer\n * emitted for your input. Log it to confirm the rewrite.\n * - `cleanup` — tears down the ephemeral rnwind state + chunk cache dir.\n * Call from `afterEach` so successive tests don't share atoms.\n */\nexport type RenderWithCssResult = TestingLibraryRenderAPI & {\n /** The post-transformer source text. Same code Metro would ship. */\n transformedSource: string\n /** Tear down the ephemeral rnwind state + cache dir. */\n cleanup: () => void\n}\n\n/** Options accepted by {@link renderHookWithCss}. */\nexport interface RenderHookWithCssOptions<Props> extends RenderHookOptions<Props> {\n /** Theme CSS fed to rnwind's parser. Defaults to the built-in minimal theme. */\n themeCss?: string\n /**\n * Active scheme the runtime resolver uses. Defaults to `'light'`. When\n * set, the hook is wrapped in `<RnwindProvider scheme={scheme}>` so\n * `useScheme()` / `useCss()` observe the override.\n */\n scheme?: string\n /**\n * Class names to pre-register into the runtime atom registry before\n * the hook runs. rnwind synthesizes a throwaway source file mentioning\n * these classes, feeds it through the real Metro transformer, and\n * evaluates the generated `style.js` bundle — so the hook sees\n * exactly the atoms the production bundle would register.\n */\n classNames?: readonly string[]\n}\n\n/**\n * Result of a {@link renderHookWithCss} call. Mirrors\n * `@testing-library/react-native`'s `renderHook` return type — `result`,\n * `rerender`, `unmount` — and adds a `cleanup` that tears down the\n * ephemeral rnwind state.\n */\nexport type RenderHookWithCssResult<Result, Props> = ReturnType<typeof testingLibraryRenderHook<Result, Props>> & {\n /** Tear down the ephemeral rnwind state + cache dir. */\n cleanup: () => void\n}\n\n// ────────────────────────────────────────────────────────────────────────\n// Public exports — functions\n// ────────────────────────────────────────────────────────────────────────\n\n/**\n * Feed a source string through rnwind's Metro transformer, evaluate\n * the generated `style.js` bundle, evaluate the rewritten module, and\n * render the default-exported component with\n * `@testing-library/react-native`.\n *\n * The rendered RN element's `style` prop is the EXACT array your\n * production bundle would attach — same transformer, same runtime\n * resolver, same atoms. Assert on `flatten(node.props.style)` to verify\n * the resolved values.\n * @example\n * ```tsx\n * const handle = await renderWithCss(\n * `import { View } from 'react-native'\n * export default () => <View className=\"bg-primary p-4\" testID=\"box\" />`,\n * { themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }` },\n * )\n * const flat = flatten(handle.getByTestId('box').props.style)\n * expect(flat.backgroundColor).toBe('#6366f1')\n * ```\n * @param source User source (one file) to transform + render.\n * @param options Optional theme override, scheme, and `react-native` bindings.\n * @returns Render queries + diagnostic handles.\n */\nexport async function renderWithCss(source: string, options: RenderWithCssOptions = {}): Promise<RenderWithCssResult> {\n const reactNative = options.reactNative ?? resolveReactNative()\n const {\n projectRoot: _projectRoot,\n transformedSource,\n cleanup,\n } = await bootstrapRnwindRuntime({\n themeCss: options.themeCss,\n source,\n })\n const Component = evaluateRewrittenModule(transformedSource, reactNative)\n const rendered = TESTING_LIBRARY.render(buildRootElement(Component, options.scheme, options.insets, options.onHaptics))\n return Object.assign({}, rendered, { transformedSource, cleanup })\n}\n\n/**\n * Render-side counterpart to {@link renderWithCss} for testing hooks in\n * isolation. Pre-registers atoms for the supplied `classNames`, wraps\n * the hook in an optional `<RnwindProvider>`, and forwards to\n * `@testing-library/react-native`'s `renderHook`.\n * @example\n * ```ts\n * const { result, cleanup } = await renderHookWithCss(\n * () => useCss('bg-primary'),\n * {\n * themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }`,\n * classNames: ['bg-primary'],\n * },\n * )\n * expect(flatten(result.current).backgroundColor).toBe('#6366f1')\n * cleanup()\n * ```\n * @param callback Hook body — same shape as `renderHook(callback)`.\n * @param options Theme, scheme, classNames to pre-register, plus\n * everything `renderHook` itself accepts (`initialProps`, `wrapper`).\n * @returns `renderHook`'s return value plus a `cleanup` function.\n */\nexport async function renderHookWithCss<Result, Props = unknown>(\n callback: (props: Props) => Result,\n options: RenderHookWithCssOptions<Props> = {},\n): Promise<RenderHookWithCssResult<Result, Props>> {\n const { cleanup } = await bootstrapRnwindRuntime({\n themeCss: options.themeCss,\n source: options.classNames && options.classNames.length > 0 ? sourceFromClassNames(options.classNames) : undefined,\n })\n const wrapper = composeHookWrapper(options.scheme, options.wrapper as RenderHookWithCssOptions<Props>['wrapper'])\n const { themeCss: _themeCss, scheme: _scheme, classNames: _classNames, ...hookOptions } = options\n const rendered = TESTING_LIBRARY.renderHook<Result, Props>(callback, {\n ...(hookOptions as RenderHookOptions<Props>),\n wrapper,\n })\n return Object.assign({}, rendered, { cleanup })\n}\n\n/**\n * Flatten a React Native style array (or single style object) into one\n * merged record. RN flattens left-to-right (later wins), so the returned\n * record is what the native view manager actually applies.\n * @param styles Style array, single object, or null/undefined.\n * @returns Flat style record.\n */\nexport function flatten(styles: unknown): Record<string, unknown> {\n if (styles == null) return {}\n if (Array.isArray(styles)) return Object.assign({}, ...styles.map((entry) => flatten(entry)))\n if (typeof styles === 'object') return styles as Record<string, unknown>\n return {}\n}\n"],"names":["generateImport","rnwindRuntime","metroTransform"],"mappings":";;;;;;;;;;;;;;AA4BA;AACA;AACA;AAEA;;;;AAIG;AACH,MAAM,iBAAiB,GAAG,CAAA;;;;;;;CAOzB;AAED;AACA,MAAM,kBAAkB,GAAG,EAAE,MAAM,EAAE,CAAI,MAAS,KAAQ,MAAM,EAAE,aAAa,EAAE,CAAC,EAAE;AAEpF;AACA;AACA;AACA;AACA;AACA,MAAM,YAAY,GAAgB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAEzF,MAAM,QAAQ,GAA2BA,UAAsD,CAAC,OAAO,IAAIA,UAAc;AAEzH;;;;;;AAMG;AACH,MAAM,eAAe,GAGjB,CAAC,MAAK;AACR,IAAA,IAAI;AACF,QAAA,OAAO,YAAY,CAAC,+BAA+B,CAGlD;IACH;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CACb,kHAAkH;AAChH,aAAC,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAC3D;IACH;AACF,CAAC,GAAG;AAaJ;;;;;AAKG;AACH,SAAS,kBAAkB,GAAA;AACzB,IAAA,OAAO,YAAY,CAAC,cAAc,CAA4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