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 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.cjs","sources":["../../../../src/runtime/resolve.ts"],"sourcesContent":["import { getStyleVersion, lookupCss, type InteractState } from './lookup-css'\nimport type { RnwindState } from './components/rnwind-provider'\nimport { normalizeClassName } from '../core/normalize-classname'\nimport type { GradientAtomInfo, GradientDirection } from '../core/parser/gradient'\nimport type { HapticRequest, HapticTrigger } from '../core/parser/haptics'\n\n/**\n * Rich className resolver — the runtime heart of the wrap / `useCss`.\n *\n * Resolution order, per className string:\n * 1. **Molecule** — a build-time PRE-MERGED single style object for the\n * whole literal className (per scheme). One map lookup returns it by\n * reference: no array, no merge, no per-atom loop. The common case.\n * 2. **Atom fallback** — for a className the scanner never saw (a\n * runtime-built string like `` `${className} px-2` ``) OR one that\n * carries context-dependent atoms (`pt-safe`, `text-base`, `md:*`),\n * fall back to per-atom resolution via `lookupCss`, which folds in\n * insets / fontScale / breakpoint / scheme.\n *\n * Results are cached by `(normalized className, scheme, insets, fontScale,\n * breakpoint)` so repeated renders return the SAME reference until the\n * reactive context changes. Atoms / molecules / features all live in\n * build-time registries the generated `.rnwind/*.js` modules populate.\n */\n\n/** Always-loaded fallback scheme key. */\nconst COMMON_SCHEME = 'common'\n\n/** Empty style sentinel. */\nconst EMPTY: readonly unknown[] = []\n\n/** scheme → normalized className → pre-merged style object. */\nlet molecules: Record<string, Record<string, unknown>> = Object.create(null)\n/** atom name → gradient role + resolved colour. */\nlet gradients: Record<string, GradientAtomInfo> = Object.create(null)\n/** atom name (incl. `active:`/`focus:` prefix) → haptic request. */\nlet haptics: Record<string, HapticRequest> = Object.create(null)\n/** Bumps on any molecule/gradient/haptic registration. */\nlet registryVersion = 0\n\n/** Per-(className·state) resolved cache — strong references between context changes. */\nconst resolvedCache = new Map<string, ResolvedCss>()\n/** Version the cache was last valid for (`getStyleVersion()` + {@link registryVersion}). */\nlet cachedFor = -1\n\n/** A unit-square gradient endpoint. */\ninterface GradientPoint {\n readonly x: number\n readonly y: number\n}\n\n/** Rich resolution: the RN `style` plus any className-derived props. */\nexport interface ResolvedCss {\n /** RN `style` value — a single molecule object (by ref) or an atom array. */\n readonly style: unknown\n /** Gradient stop colours (when the className is a complete gradient). */\n readonly colors?: readonly string[]\n /** Gradient start point. */\n readonly start?: GradientPoint\n /** Gradient end point. */\n readonly end?: GradientPoint\n /** Text truncation line count. */\n readonly numberOfLines?: number\n /** Text ellipsize mode. */\n readonly ellipsizeMode?: 'tail' | 'clip'\n /** Haptic requests present on the className, for the wrap to dispatch. */\n readonly haptics?: readonly { readonly request: HapticRequest; readonly trigger: HapticTrigger }[]\n}\n\n/** `GradientDirection` → expo-linear-gradient start/end points. */\nconst DIRECTION_POINTS: Record<GradientDirection, { start: GradientPoint; end: GradientPoint }> = {\n 'to-t': { start: { x: 0.5, y: 1 }, end: { x: 0.5, y: 0 } },\n 'to-b': { start: { x: 0.5, y: 0 }, end: { x: 0.5, y: 1 } },\n 'to-l': { start: { x: 1, y: 0.5 }, end: { x: 0, y: 0.5 } },\n 'to-r': { start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 } },\n 'to-tl': { start: { x: 1, y: 1 }, end: { x: 0, y: 0 } },\n 'to-tr': { start: { x: 0, y: 1 }, end: { x: 1, y: 0 } },\n 'to-bl': { start: { x: 1, y: 0 }, end: { x: 0, y: 1 } },\n 'to-br': { start: { x: 0, y: 0 }, end: { x: 1, y: 1 } },\n unknown: { start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 } },\n}\n\n/**\n * Register one scheme's pre-merged molecules (atom-merged literal\n * classNames). Merges onto any existing entries for the scheme.\n * @param scheme Scheme name (or `'common'`).\n * @param entries Normalized className → merged style object.\n */\nexport function registerMolecules(scheme: string, entries: Record<string, unknown>): void {\n molecules[scheme] = { ...molecules[scheme], ...entries }\n registryVersion += 1\n}\n\n/**\n * Register the gradient atom map (atom name → role + resolved colour).\n * @param map Atom name → gradient info.\n */\nexport function registerGradients(map: Record<string, GradientAtomInfo>): void {\n gradients = map\n registryVersion += 1\n}\n\n/**\n * Register the haptic atom map (atom name → request).\n * @param map Atom name → haptic request.\n */\nexport function registerHaptics(map: Record<string, HapticRequest>): void {\n haptics = map\n registryVersion += 1\n}\n\n\n\n/**\n * Per-state-object signature memo. `RnwindState` is created fresh (via the\n * provider's `useMemo`) whenever any field changes, so its identity is a\n * sound key — a new object means a new signature. Keyed weakly so states\n * GC with their provider.\n */\nconst stateSignatureCache = new WeakMap<RnwindState, string>()\n\n/**\n * Cache key dimension for the reactive context — everything that can\n * change a resolved style.\n * @param state Rnwind context.\n * @returns Compact signature string.\n */\nfunction stateSignature(state: RnwindState): string {\n const { insets } = state\n return `${state.scheme}|${insets.top},${insets.right},${insets.bottom},${insets.left}|${state.fontScale}|${state.windowWidth}`\n}\n\n/**\n * Memoised {@link stateSignature} — one `WeakMap.get` on the hot path\n * instead of rebuilding the template string every resolve.\n * @param state Rnwind context.\n * @returns Cached compact signature.\n */\nfunction stateSignatureCached(state: RnwindState): string {\n let signature = stateSignatureCache.get(state)\n if (signature === undefined) {\n signature = stateSignature(state)\n stateSignatureCache.set(state, signature)\n }\n return signature\n}\n\n/**\n * Compact signature of the live interactive state for the cache key.\n * @param interactState Active/focus flags, or undefined for the plain path.\n * @returns Two-bit signature (`''` when no interactive state).\n */\nfunction interactSignature(interactState?: InteractState): string {\n if (!interactState) return ''\n const active = interactState.active ? 1 : 0\n const focus = interactState.focus ? 1 : 0\n return `${active}${focus}`\n}\n\n/**\n * Whether a token is a feature-ONLY utility (gradient stop/direction,\n * haptic request, or text-truncate) that contributes NO RN `style`. These\n * are folded in via {@link attachFeatures}, so they must be kept OUT of\n * the `lookupCss` input — otherwise the atom resolver treats them as\n * unknown style atoms and emits a spurious \"unknown class\" dev warning\n * (e.g. for `active:haptic-rigid`).\n * @param token Atom name.\n * @returns True when the token carries no style.\n */\nfunction isFeatureOnlyToken(token: string): boolean {\n return Boolean(gradients[token]) || Boolean(haptics[token]) || truncateForToken(token) !== null\n}\n\n/**\n * Lifecycle trigger for a haptic atom from its variant prefix.\n * @param token Atom name (maybe `active:`/`focus:`/`hover:` prefixed).\n * @returns The trigger.\n */\nfunction hapticTriggerForToken(token: string): HapticTrigger {\n const colon = token.indexOf(':')\n if (colon === -1) return 'mount'\n const prefix = token.slice(0, colon)\n if (prefix === 'active') return 'pressIn'\n if (prefix === 'focus') return 'focus'\n if (prefix === 'hover') return 'hover'\n return 'mount'\n}\n\n/**\n * Syntactic text-truncate directive for one atom.\n * @param token Atom name.\n * @returns Partial truncate props, or null.\n */\nfunction truncateForToken(token: string): { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } | null {\n if (token === 'truncate') return { numberOfLines: 1, ellipsizeMode: 'tail' }\n if (token === 'text-ellipsis') return { ellipsizeMode: 'tail' }\n if (token === 'text-clip') return { ellipsizeMode: 'clip' }\n if (token === 'line-clamp-none') return { numberOfLines: 0 }\n if (token.startsWith('line-clamp-')) {\n const count = Number(token.slice('line-clamp-'.length))\n if (Number.isInteger(count) && count >= 0) return { numberOfLines: count }\n }\n return null\n}\n\n/**\n * Assemble gradient props from gradient roles present in the atom list.\n * @param tokens Atom names.\n * @returns `{colors, start, end}` or null when not a complete gradient.\n */\nfunction assembleGradient(tokens: readonly string[]): { colors: string[]; start: GradientPoint; end: GradientPoint } | null {\n let from: string | undefined\n let via: string | undefined\n let to: string | undefined\n let dir: GradientDirection | undefined\n for (const token of tokens) {\n const info = gradients[token]\n if (!info) continue\n switch (info.role) {\n case 'from': {\n from = info.color\n break\n }\n case 'via': {\n via = info.color\n break\n }\n case 'to': {\n to = info.color\n break\n }\n default: {\n ;({ dir } = info)\n }\n }\n }\n if (dir === undefined) return null\n const colors = [from, via, to].filter((color): color is string => color !== undefined)\n if (colors.length < 2) return null\n const points = DIRECTION_POINTS[dir]\n return { colors, start: points.start, end: points.end }\n}\n\n/**\n * Fold every truncate directive across the atom list into one result —\n * last token wins per prop (matches Tailwind last-wins).\n * @param tokens Atom names.\n * @returns Merged truncate props (empty when none apply).\n */\nfunction collectTruncate(tokens: readonly string[]): { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } {\n const out: { numberOfLines?: number; ellipsizeMode?: 'tail' | 'clip' } = {}\n for (const token of tokens) {\n const truncate = truncateForToken(token)\n if (!truncate) continue\n if (truncate.numberOfLines !== undefined) out.numberOfLines = truncate.numberOfLines\n if (truncate.ellipsizeMode !== undefined) out.ellipsizeMode = truncate.ellipsizeMode\n }\n return out\n}\n\n/**\n * Collect every haptic request present in the atom list, tagged with the\n * lifecycle trigger its variant prefix implies.\n * @param tokens Atom names.\n * @returns Haptic request list, or undefined when none apply.\n */\nfunction collectHaptics(tokens: readonly string[]): { request: HapticRequest; trigger: HapticTrigger }[] | undefined {\n let collected: { request: HapticRequest; trigger: HapticTrigger }[] | undefined\n for (const token of tokens) {\n const request = haptics[token]\n if (!request) continue\n collected ??= []\n collected.push({ request, trigger: hapticTriggerForToken(token) })\n }\n return collected\n}\n\n/**\n * Scan tokens for the className-derived feature props (gradient,\n * truncate, haptics) and fold them onto the base result.\n * @param base Result carrying the resolved `style`.\n * @param tokens Atom names.\n * @returns The result with any feature props attached.\n */\nfunction attachFeatures(base: ResolvedCss, tokens: readonly string[]): ResolvedCss {\n const { numberOfLines, ellipsizeMode } = collectTruncate(tokens)\n const collected = collectHaptics(tokens)\n const gradient = assembleGradient(tokens)\n const result: Mutable<ResolvedCss> = { style: base.style }\n if (gradient) {\n result.colors = gradient.colors\n result.start = gradient.start\n result.end = gradient.end\n }\n // `numberOfLines: 0` is kept (RN reads it as \"unlimited\"): `line-clamp-none`\n // must be able to explicitly reset an earlier `line-clamp-N` on the same\n // element — dropping the 0 would silently leave the prior limit in place.\n if (numberOfLines !== undefined) {\n result.numberOfLines = numberOfLines\n if (ellipsizeMode !== undefined) result.ellipsizeMode = ellipsizeMode\n }\n if (collected) result.haptics = collected\n return result\n}\n\n/**\n * Compose a resolved style with a caller-supplied inline style (user wins).\n * @param style\n * @param userStyle\n */\nfunction withUserStyle(style: unknown, userStyle: unknown): unknown {\n return Array.isArray(style) ? [...style, userStyle] : [style, userStyle]\n}\n\n/**\n * Resolve a className against the reactive context into a style plus any\n * className-derived props. Molecule-first (one lookup, by reference),\n * atom-fallback for unseen / context-dependent strings, cached per\n * `(className, state)`.\n * @param className Raw className string.\n * @param state Rnwind context from `useRnwind()`.\n * @param userStyle Optional inline style appended last (wins).\n * @param interactState Live active/focus flags (for `active:`/`focus:` atoms).\n * @returns The resolved style + feature props.\n */\nexport function resolve(\n className: string | null | undefined,\n state: RnwindState,\n userStyle?: unknown,\n interactState?: InteractState,\n): ResolvedCss {\n const version = getStyleVersion() + registryVersion\n if (version !== cachedFor) {\n resolvedCache.clear()\n cachedFor = version\n }\n if (className == null) {\n return { style: userStyle === undefined || userStyle === null ? EMPTY : [userStyle] }\n }\n // Key on the RAW className so the hot (cache-hit) path skips normalize\n // entirely — normalization only runs on a miss. The state signature is\n // memoised per state object, so the hit path is one WeakMap.get + one\n // string concat + one Map.get.\n const key = `${className}@${stateSignatureCached(state)}@${interactSignature(interactState)}`\n const cached = resolvedCache.get(key)\n if (cached !== undefined) {\n return userStyle === undefined || userStyle === null ? cached : { ...cached, style: withUserStyle(cached.style, userStyle) }\n }\n const normalized = normalizeClassName(className)\n if (normalized.length === 0) {\n const empty: ResolvedCss = { style: EMPTY }\n resolvedCache.set(key, empty)\n return userStyle === undefined || userStyle === null ? empty : { style: [userStyle] }\n }\n // Molecules are static pre-merges; anything carrying `active:`/`focus:`\n // is never registered as one, so the atom path handles interactive state.\n const tokens = normalized.split(' ')\n const molecule = interactState ? undefined : molecules[state.scheme]?.[normalized] ?? molecules[COMMON_SCHEME]?.[normalized]\n // Feature-only tokens (gradient / haptic / truncate) carry no style — keep\n // them out of the atom lookup so they don't warn as \"unknown class\".\n const style =\n molecule === undefined ? lookupCss(tokens.filter((token) => !isFeatureOnlyToken(token)).join(' '), state, undefined, interactState) : molecule\n const base = attachFeatures({ style }, tokens)\n resolvedCache.set(key, base)\n return userStyle === undefined || userStyle === null ? base : { ...base, style: withUserStyle(base.style, userStyle) }\n}\n\n/** Local mutable view for building the frozen-shaped result. */\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] }\n\n/** Test-only — clear the molecule / gradient / haptic registries + cache. */\nexport function __resetResolveState(): void {\n molecules = Object.create(null)\n gradients = Object.create(null)\n haptics = Object.create(null)\n resolvedCache.clear()\n registryVersion += 1\n cachedFor = -1\n}\n\nexport {normalizeClassName} from '../core/normalize-classname'"],"names":["getStyleVersion","normalizeClassName","lookupCss"],"mappings":";;;;;AAMA;;;;;;;;;;;;;;;;;AAiBG;AAEH;AACA,MAAM,aAAa,GAAG,QAAQ;AAE9B;AACA,MAAM,KAAK,GAAuB,EAAE;AAEpC;AACA,IAAI,SAAS,GAA4C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AAC5E;AACA,IAAI,SAAS,GAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AACrE;AACA,IAAI,OAAO,GAAkC,MAAM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GA,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC;AACpC,IAAA,MAAM,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC;;;AAG5H,IAAA,MAAM,KAAK,GACT,QAAQ,KAAK,SAAS,GAAGC,mBAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,GAAG,QAAQ;IAChJ,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC;AAC9C,IAAA,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC;AAC5B,IAAA,OAAO,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;AACxH;AAKA;SACgB,mBAAmB,GAAA;AACjC,IAAA,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AAC/B,IAAA,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AAC/B,IAAA,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAC7B,aAAa,CAAC,KAAK,EAAE;IACrB,eAAe,IAAI,CAAC;IACpB,SAAS,GAAG,EAAE;AAChB;;;;;;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type InteractState } from './lookup-css';
|
|
2
|
+
import type { RnwindState } from './components/rnwind-provider';
|
|
3
|
+
import type { GradientAtomInfo } from '../core/parser/gradient';
|
|
4
|
+
import type { HapticRequest, HapticTrigger } from '../core/parser/haptics';
|
|
5
|
+
/** A unit-square gradient endpoint. */
|
|
6
|
+
interface GradientPoint {
|
|
7
|
+
readonly x: number;
|
|
8
|
+
readonly y: number;
|
|
9
|
+
}
|
|
10
|
+
/** Rich resolution: the RN `style` plus any className-derived props. */
|
|
11
|
+
export interface ResolvedCss {
|
|
12
|
+
/** RN `style` value — a single molecule object (by ref) or an atom array. */
|
|
13
|
+
readonly style: unknown;
|
|
14
|
+
/** Gradient stop colours (when the className is a complete gradient). */
|
|
15
|
+
readonly colors?: readonly string[];
|
|
16
|
+
/** Gradient start point. */
|
|
17
|
+
readonly start?: GradientPoint;
|
|
18
|
+
/** Gradient end point. */
|
|
19
|
+
readonly end?: GradientPoint;
|
|
20
|
+
/** Text truncation line count. */
|
|
21
|
+
readonly numberOfLines?: number;
|
|
22
|
+
/** Text ellipsize mode. */
|
|
23
|
+
readonly ellipsizeMode?: 'tail' | 'clip';
|
|
24
|
+
/** Haptic requests present on the className, for the wrap to dispatch. */
|
|
25
|
+
readonly haptics?: readonly {
|
|
26
|
+
readonly request: HapticRequest;
|
|
27
|
+
readonly trigger: HapticTrigger;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register one scheme's pre-merged molecules (atom-merged literal
|
|
32
|
+
* classNames). Merges onto any existing entries for the scheme.
|
|
33
|
+
* @param scheme Scheme name (or `'common'`).
|
|
34
|
+
* @param entries Normalized className → merged style object.
|
|
35
|
+
*/
|
|
36
|
+
export declare function registerMolecules(scheme: string, entries: Record<string, unknown>): void;
|
|
37
|
+
/**
|
|
38
|
+
* Register the gradient atom map (atom name → role + resolved colour).
|
|
39
|
+
* @param map Atom name → gradient info.
|
|
40
|
+
*/
|
|
41
|
+
export declare function registerGradients(map: Record<string, GradientAtomInfo>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Register the haptic atom map (atom name → request).
|
|
44
|
+
* @param map Atom name → haptic request.
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerHaptics(map: Record<string, HapticRequest>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a className against the reactive context into a style plus any
|
|
49
|
+
* className-derived props. Molecule-first (one lookup, by reference),
|
|
50
|
+
* atom-fallback for unseen / context-dependent strings, cached per
|
|
51
|
+
* `(className, state)`.
|
|
52
|
+
* @param className Raw className string.
|
|
53
|
+
* @param state Rnwind context from `useRnwind()`.
|
|
54
|
+
* @param userStyle Optional inline style appended last (wins).
|
|
55
|
+
* @param interactState Live active/focus flags (for `active:`/`focus:` atoms).
|
|
56
|
+
* @returns The resolved style + feature props.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolve(className: string | null | undefined, state: RnwindState, userStyle?: unknown, interactState?: InteractState): ResolvedCss;
|
|
59
|
+
/** Test-only — clear the molecule / gradient / haptic registries + cache. */
|
|
60
|
+
export declare function __resetResolveState(): void;
|
|
61
|
+
export { normalizeClassName } from '../core/normalize-classname';
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var chainHandlers = require('./chain-handlers.cjs');
|
|
5
|
+
var useInteract = require('./hooks/use-interact.cjs');
|
|
6
|
+
var rnwindProvider = require('./components/rnwind-provider.cjs');
|
|
7
|
+
var resolve = require('./resolve.cjs');
|
|
8
|
+
|
|
9
|
+
/** Matches a leading `active:` / `focus:` variant token (`\b` excludes `inactive:`). */
|
|
10
|
+
const INTERACTIVE_VARIANT = /\b(?:active|focus):/;
|
|
11
|
+
/** One-shot guard so the missing-`onHaptics` warning logs once per session. */
|
|
12
|
+
let warnedMissingOnHaptics = false;
|
|
13
|
+
/**
|
|
14
|
+
* Dev-only warning when a className carries a haptic utility but no
|
|
15
|
+
* `onHaptics` dispatcher is wired on the nearest `<RnwindProvider>` — the
|
|
16
|
+
* haptic would silently drop otherwise. Fires once per session.
|
|
17
|
+
* @param onHaptics The dispatcher from context (or undefined).
|
|
18
|
+
* @param haptics The resolved haptic requests (or undefined).
|
|
19
|
+
*/
|
|
20
|
+
function warnIfHapticsUnwired(onHaptics, haptics) {
|
|
21
|
+
if (onHaptics || !haptics || haptics.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
const isDevelopment = typeof __DEV__ === 'undefined' || __DEV__;
|
|
24
|
+
if (!isDevelopment || warnedMissingOnHaptics)
|
|
25
|
+
return;
|
|
26
|
+
warnedMissingOnHaptics = true;
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.warn('rnwind: a `haptic-*` utility resolved but no `onHaptics` callback is wired on <RnwindProvider>. ' +
|
|
29
|
+
'Pass `onHaptics` on the provider to forward the request to expo-haptics (or any library).');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether a className needs press/focus state tracking.
|
|
33
|
+
* @param className Raw className string.
|
|
34
|
+
* @returns True when an `active:` / `focus:` variant is present.
|
|
35
|
+
*/
|
|
36
|
+
function hasInteractiveVariant(className) {
|
|
37
|
+
return INTERACTIVE_VARIANT.test(className);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Best-effort display name for the wrapped component.
|
|
41
|
+
* @param component Component being wrapped.
|
|
42
|
+
* @returns Its `displayName`, `name`, or `'Component'`.
|
|
43
|
+
*/
|
|
44
|
+
function displayNameOf(component) {
|
|
45
|
+
const named = component;
|
|
46
|
+
return named.displayName ?? named.name ?? 'Component';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Fire the `mount`-trigger haptics once, after the element mounts. Snaps
|
|
50
|
+
* the resolved requests + dispatcher at mount via a `useRef` initializer
|
|
51
|
+
* (evaluated only on the first render), so an unstable inline `onHaptics`
|
|
52
|
+
* doesn't re-fire them and no ref is written during render.
|
|
53
|
+
* @param resolved The resolved className (carries any haptic requests).
|
|
54
|
+
* @param onHaptics The dispatcher from context (or undefined).
|
|
55
|
+
*/
|
|
56
|
+
function useMountHaptics(resolved, onHaptics) {
|
|
57
|
+
const mount = React.useRef({ resolved, onHaptics });
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
const { resolved: current, onHaptics: dispatch } = mount.current;
|
|
60
|
+
if (!dispatch || !current.haptics)
|
|
61
|
+
return;
|
|
62
|
+
for (const entry of current.haptics)
|
|
63
|
+
if (entry.trigger === 'mount')
|
|
64
|
+
dispatch(entry.request, 'mount');
|
|
65
|
+
}, []);
|
|
66
|
+
}
|
|
67
|
+
/** Suffix marking a secondary class-prop (`contentContainerClassName`, …). */
|
|
68
|
+
const CLASSNAME_SUFFIX = 'ClassName';
|
|
69
|
+
/**
|
|
70
|
+
* Resolve every secondary `<prefix>ClassName` prop (e.g.
|
|
71
|
+
* `contentContainerClassName` on a ScrollView / FlatList) into its
|
|
72
|
+
* matching `<prefix>Style`, in place. Any existing `<prefix>Style` is
|
|
73
|
+
* appended last (caller wins). The original `*ClassName` prop is deleted
|
|
74
|
+
* so RN never sees an unknown attribute. The primary `className` is
|
|
75
|
+
* handled separately by the leaf and never reaches here.
|
|
76
|
+
* @param props Mutable prop object being assembled for the host.
|
|
77
|
+
* @param state Rnwind context for resolution.
|
|
78
|
+
*/
|
|
79
|
+
function applyContainerClassNames(props, state) {
|
|
80
|
+
for (const key of Object.keys(props)) {
|
|
81
|
+
if (!key.endsWith(CLASSNAME_SUFFIX))
|
|
82
|
+
continue;
|
|
83
|
+
const value = props[key];
|
|
84
|
+
if (typeof value !== 'string')
|
|
85
|
+
continue;
|
|
86
|
+
const styleKey = `${key.slice(0, -CLASSNAME_SUFFIX.length)}Style`;
|
|
87
|
+
props[styleKey] = resolve.resolve(value, state, props[styleKey]).style;
|
|
88
|
+
delete props[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build the props for the wrapped host: resolved `style`, gradient
|
|
93
|
+
* (`colors`/`start`/`end`), truncate (`numberOfLines`/`ellipsizeMode`),
|
|
94
|
+
* secondary `<prefix>ClassName` → `<prefix>Style`, and a chained
|
|
95
|
+
* `onPressIn` that fires press-trigger haptics. Unknown props on a host
|
|
96
|
+
* are simply ignored by RN, so this stays generic.
|
|
97
|
+
* @param rest Forwarded props (incl. `ref`).
|
|
98
|
+
* @param resolved Resolved className result.
|
|
99
|
+
* @param state Rnwind context — used to resolve secondary class props.
|
|
100
|
+
* @param onHaptics Dispatcher from context.
|
|
101
|
+
* @param userOnPressIn Caller-supplied onPressIn to chain after the haptic.
|
|
102
|
+
* @returns The merged prop object for `createElement`.
|
|
103
|
+
*/
|
|
104
|
+
function buildProps(rest, resolved, state, onHaptics, userOnPressIn) {
|
|
105
|
+
warnIfHapticsUnwired(onHaptics, resolved.haptics);
|
|
106
|
+
const props = { ...rest, style: resolved.style };
|
|
107
|
+
applyContainerClassNames(props, state);
|
|
108
|
+
if (resolved.colors) {
|
|
109
|
+
props.colors = resolved.colors;
|
|
110
|
+
props.start = resolved.start;
|
|
111
|
+
props.end = resolved.end;
|
|
112
|
+
}
|
|
113
|
+
if (resolved.numberOfLines !== undefined) {
|
|
114
|
+
props.numberOfLines = resolved.numberOfLines;
|
|
115
|
+
if (resolved.ellipsizeMode !== undefined)
|
|
116
|
+
props.ellipsizeMode = resolved.ellipsizeMode;
|
|
117
|
+
}
|
|
118
|
+
const pressHaptics = onHaptics && resolved.haptics?.filter((entry) => entry.trigger === 'pressIn');
|
|
119
|
+
if (pressHaptics && pressHaptics.length > 0) {
|
|
120
|
+
const previous = userOnPressIn;
|
|
121
|
+
props.onPressIn = (event) => {
|
|
122
|
+
for (const entry of pressHaptics)
|
|
123
|
+
onHaptics(entry.request, 'pressIn');
|
|
124
|
+
previous?.(event);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else if (userOnPressIn !== undefined) {
|
|
128
|
+
props.onPressIn = userOnPressIn;
|
|
129
|
+
}
|
|
130
|
+
return props;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Non-interactive leaf: resolve className → style (+ features) and
|
|
134
|
+
* forward. One context read, one molecule/atom resolve.
|
|
135
|
+
* @param props Leaf props.
|
|
136
|
+
* @param props.as
|
|
137
|
+
* @param props.className
|
|
138
|
+
* @param props.style
|
|
139
|
+
* @param props.onPressIn
|
|
140
|
+
* @returns The rendered `as` element.
|
|
141
|
+
*/
|
|
142
|
+
function PlainLeaf({ as: As, className, style, onPressIn, ...rest }) {
|
|
143
|
+
const state = rnwindProvider.useRnwind();
|
|
144
|
+
const resolved = resolve.resolve(className, state, style);
|
|
145
|
+
useMountHaptics(resolved, state.onHaptics);
|
|
146
|
+
return React.createElement(As, buildProps(rest, resolved, state, state.onHaptics, onPressIn));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Interactive leaf: tracks press/focus via `useInteract()`, feeds it into
|
|
150
|
+
* `resolve` so `active:`/`focus:` atoms apply, and chains the
|
|
151
|
+
* press/focus handlers.
|
|
152
|
+
* @param props Leaf props.
|
|
153
|
+
* @param props.as
|
|
154
|
+
* @param props.className
|
|
155
|
+
* @param props.style
|
|
156
|
+
* @param props.onPressIn
|
|
157
|
+
* @param props.onPressOut
|
|
158
|
+
* @param props.onFocus
|
|
159
|
+
* @param props.onBlur
|
|
160
|
+
* @returns The rendered `as` element with interactive wiring.
|
|
161
|
+
*/
|
|
162
|
+
function InteractiveLeaf({ as: As, className, style, onPressIn, onPressOut, onFocus, onBlur, ...rest }) {
|
|
163
|
+
const state = rnwindProvider.useRnwind();
|
|
164
|
+
const interact = useInteract.useInteract();
|
|
165
|
+
const resolved = resolve.resolve(className, state, style, interact.state);
|
|
166
|
+
useMountHaptics(resolved, state.onHaptics);
|
|
167
|
+
const props = buildProps(rest, resolved, state, state.onHaptics, onPressIn);
|
|
168
|
+
props.onPressIn = chainHandlers.chainPress(props.onPressIn, interact.onPressIn);
|
|
169
|
+
props.onPressOut = chainHandlers.chainPress(onPressOut, interact.onPressOut);
|
|
170
|
+
props.onFocus = chainHandlers.chainFocus(onFocus, interact.onFocus);
|
|
171
|
+
props.onBlur = chainHandlers.chainFocus(onBlur, interact.onBlur);
|
|
172
|
+
return React.createElement(As, props);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Wrap a component so its `className` prop resolves to RN `style` (plus
|
|
176
|
+
* gradient / truncate props and haptic dispatch) at render — no matter
|
|
177
|
+
* how className arrived: written directly, spread through `{...rest}`, or
|
|
178
|
+
* forwarded down custom wrappers. The returned component is hook-free; it
|
|
179
|
+
* dispatches to a plain or interactive leaf so non-interactive elements
|
|
180
|
+
* never pay for press/focus state. `ref` (a normal prop in React 19) and
|
|
181
|
+
* all other props forward untouched.
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* const Pressable = wrap(RNPressable)
|
|
185
|
+
* <Pressable className="active:bg-sky-700 px-4 haptic-light" onPress={fn} />
|
|
186
|
+
* ```
|
|
187
|
+
* @param Component Any component accepting a `style` prop.
|
|
188
|
+
* @returns A component accepting `className`.
|
|
189
|
+
*/
|
|
190
|
+
function wrap(Component) {
|
|
191
|
+
const as = Component;
|
|
192
|
+
/**
|
|
193
|
+
* The wrapped component — hook-free dispatcher to a leaf.
|
|
194
|
+
* @param props Forwarded props with `className` intercepted.
|
|
195
|
+
* @param props.className
|
|
196
|
+
* @returns The rendered leaf.
|
|
197
|
+
*/
|
|
198
|
+
function RnwindWrapped({ className, ...rest }) {
|
|
199
|
+
if (className !== undefined && hasInteractiveVariant(className)) {
|
|
200
|
+
return React.createElement(InteractiveLeaf, { as, className, ...rest });
|
|
201
|
+
}
|
|
202
|
+
return React.createElement(PlainLeaf, { as, className, ...rest });
|
|
203
|
+
}
|
|
204
|
+
RnwindWrapped.displayName = `wrap(${displayNameOf(Component)})`;
|
|
205
|
+
return RnwindWrapped;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Whether a namespace member name denotes a component to wrap —
|
|
209
|
+
* PascalCase and not a React context (`*Context`). Lowercase utilities /
|
|
210
|
+
* hooks (`createAnimatedComponent`, `spring`) pass through untouched.
|
|
211
|
+
* @param name Member key.
|
|
212
|
+
* @returns True when the member should be `wrap()`-ed.
|
|
213
|
+
*/
|
|
214
|
+
function isComponentMember(name) {
|
|
215
|
+
return /^[A-Z]/.test(name) && !name.endsWith('Context');
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Wrap a component NAMESPACE (a default/namespace import like reanimated's
|
|
219
|
+
* `Animated`) so member access — `Animated.View`, `Animated.ScrollView` —
|
|
220
|
+
* returns a `wrap()`-ed component whose `className` resolves at render.
|
|
221
|
+
* Returns a Proxy: component members are wrapped lazily and memoised so
|
|
222
|
+
* each access yields the SAME wrapped component (stable identity — React
|
|
223
|
+
* would remount otherwise). Non-component members (`createAnimatedComponent`,
|
|
224
|
+
* config objects) pass straight through.
|
|
225
|
+
* @example
|
|
226
|
+
* ```tsx
|
|
227
|
+
* const Animated = wrapNamespace(RNReanimated)
|
|
228
|
+
* <Animated.View className="enter-fade" />
|
|
229
|
+
* ```
|
|
230
|
+
* @param namespace The imported namespace object.
|
|
231
|
+
* @returns A Proxy that wraps component members on access.
|
|
232
|
+
*/
|
|
233
|
+
function wrapNamespace(namespace) {
|
|
234
|
+
const cache = new Map();
|
|
235
|
+
return new Proxy(namespace, {
|
|
236
|
+
get(target, key, receiver) {
|
|
237
|
+
const value = Reflect.get(target, key, receiver);
|
|
238
|
+
if (typeof key !== 'string' || !isComponentMember(key))
|
|
239
|
+
return value;
|
|
240
|
+
if (!value || (typeof value !== 'function' && typeof value !== 'object'))
|
|
241
|
+
return value;
|
|
242
|
+
let wrapped = cache.get(key);
|
|
243
|
+
if (wrapped === undefined) {
|
|
244
|
+
wrapped = wrap(value);
|
|
245
|
+
cache.set(key, wrapped);
|
|
246
|
+
}
|
|
247
|
+
return wrapped;
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
exports.wrap = wrap;
|
|
253
|
+
exports.wrapNamespace = wrapNamespace;
|
|
254
|
+
//# sourceMappingURL=wrap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.cjs","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":["useRef","useEffect","resolve","useRnwind","createElement","useInteract","chainPress","chainFocus"],"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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CAAA,CAAA,CAAG;AAC/D,IAAA,OAAO,aAAqE;AAC9E;AAEA;;;;;;AAMG;AACH,SAAS,iBAAiB,CAAC,IAAY,EAAA;AACrC,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;AACzD;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;;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Wrap a component so its `className` prop resolves to RN `style` (plus
|
|
4
|
+
* gradient / truncate props and haptic dispatch) at render — no matter
|
|
5
|
+
* how className arrived: written directly, spread through `{...rest}`, or
|
|
6
|
+
* forwarded down custom wrappers. The returned component is hook-free; it
|
|
7
|
+
* dispatches to a plain or interactive leaf so non-interactive elements
|
|
8
|
+
* never pay for press/focus state. `ref` (a normal prop in React 19) and
|
|
9
|
+
* all other props forward untouched.
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const Pressable = wrap(RNPressable)
|
|
13
|
+
* <Pressable className="active:bg-sky-700 px-4 haptic-light" onPress={fn} />
|
|
14
|
+
* ```
|
|
15
|
+
* @param Component Any component accepting a `style` prop.
|
|
16
|
+
* @returns A component accepting `className`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function wrap<P>(Component: ComponentType<P>): ComponentType<P & {
|
|
19
|
+
className?: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap a component NAMESPACE (a default/namespace import like reanimated's
|
|
23
|
+
* `Animated`) so member access — `Animated.View`, `Animated.ScrollView` —
|
|
24
|
+
* returns a `wrap()`-ed component whose `className` resolves at render.
|
|
25
|
+
* Returns a Proxy: component members are wrapped lazily and memoised so
|
|
26
|
+
* each access yields the SAME wrapped component (stable identity — React
|
|
27
|
+
* would remount otherwise). Non-component members (`createAnimatedComponent`,
|
|
28
|
+
* config objects) pass straight through.
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const Animated = wrapNamespace(RNReanimated)
|
|
32
|
+
* <Animated.View className="enter-fade" />
|
|
33
|
+
* ```
|
|
34
|
+
* @param namespace The imported namespace object.
|
|
35
|
+
* @returns A Proxy that wraps component members on access.
|
|
36
|
+
*/
|
|
37
|
+
export declare function wrapNamespace<T extends object>(namespace: T): T;
|
|
@@ -8,8 +8,9 @@ var node_os = require('node:os');
|
|
|
8
8
|
var path = require('node:path');
|
|
9
9
|
var React = require('react');
|
|
10
10
|
var lookupCss = require('../runtime/lookup-css.cjs');
|
|
11
|
+
var resolve = require('../runtime/resolve.cjs');
|
|
12
|
+
var runtime_index = require('../runtime/index.cjs');
|
|
11
13
|
var rnwindProvider = require('../runtime/components/rnwind-provider.cjs');
|
|
12
|
-
var haptics = require('../runtime/haptics.cjs');
|
|
13
14
|
var state = require('../metro/state.cjs');
|
|
14
15
|
var metro_transformer = require('../metro/transformer.cjs');
|
|
15
16
|
|
|
@@ -50,26 +51,6 @@ const DEFAULT_THEME_CSS = `@import 'tailwindcss';
|
|
|
50
51
|
`;
|
|
51
52
|
/** `StyleSheet.create` stub the evaluated bundle calls — identity at test time. */
|
|
52
53
|
const BUNDLE_STYLE_SHEET = { create: (styles) => styles, hairlineWidth: 1 };
|
|
53
|
-
/** Stubbed interactive-state hook return matching `useInteract()`. */
|
|
54
|
-
const NOOP_INTERACT = {
|
|
55
|
-
state: undefined,
|
|
56
|
-
onPressIn: () => undefined,
|
|
57
|
-
onPressOut: () => undefined,
|
|
58
|
-
onFocus: () => undefined,
|
|
59
|
-
onBlur: () => undefined,
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Identity chain helper matching `chainPress` / `chainFocus`. Returns a
|
|
63
|
-
* single callback that invokes every supplied handler in turn.
|
|
64
|
-
* @param handlers Handlers to chain.
|
|
65
|
-
* @returns Combined callback.
|
|
66
|
-
*/
|
|
67
|
-
const NOOP_CHAIN = (...handlers) => (...args) => {
|
|
68
|
-
for (const handler of handlers) {
|
|
69
|
-
if (typeof handler === 'function')
|
|
70
|
-
handler(...args);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
54
|
// Synthesize a require rooted at the consumer's cwd so optional peer
|
|
74
55
|
// lookups (`@testing-library/react-native`, `esbuild`) resolve from THEIR
|
|
75
56
|
// node_modules, not rnwind's. A workspace-local rnwind install resolves
|
|
@@ -127,28 +108,87 @@ function compileToJs(source) {
|
|
|
127
108
|
}
|
|
128
109
|
}
|
|
129
110
|
/**
|
|
130
|
-
* Evaluate
|
|
131
|
-
* so its `registerAtoms`
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
111
|
+
* Evaluate one generated registry file (`common.style.js`,
|
|
112
|
+
* `<variant>.style.js`, or `schemes.js`) so its `registerAtoms` /
|
|
113
|
+
* `registerBreakpoints` / `registerGradients` / `registerHaptics` /
|
|
114
|
+
* `registerSchemeLoader` calls land in the process-global registries the
|
|
115
|
+
* runtime resolver reads. Imports (`'rnwind'`, `'react-native'`, relative
|
|
116
|
+
* `./common.style`), `require(...)` loaders, and `export {...}` are
|
|
117
|
+
* stripped — every scheme file is evaluated directly, so lazy loaders are
|
|
118
|
+
* inert.
|
|
119
|
+
* @param filePath Absolute path to the generated file.
|
|
135
120
|
*/
|
|
136
|
-
function
|
|
137
|
-
const filePath = path.join(cacheDir, 'style.js');
|
|
121
|
+
function evaluateGeneratedFile(filePath) {
|
|
138
122
|
if (!node_fs.existsSync(filePath))
|
|
139
123
|
return;
|
|
140
124
|
const body = node_fs.readFileSync(filePath, 'utf8')
|
|
141
|
-
.replaceAll(/import
|
|
142
|
-
.replaceAll(/import
|
|
143
|
-
|
|
125
|
+
.replaceAll(/import\s+\{[^}]*\}\s+from\s+['"][^'"]+['"];?\s*\n?/g, '')
|
|
126
|
+
.replaceAll(/import\s+['"][^'"]+['"];?\s*\n?/g, '')
|
|
127
|
+
.replaceAll(/export\s+\{[^}]*\}\s*;?\s*\n?/g, '');
|
|
128
|
+
// Generated body is produced by rnwind itself — not user-controlled.
|
|
129
|
+
// `require` is neutralised: each variant file is evaluated directly,
|
|
130
|
+
// so the manifest's lazy `require('./x.style')` loaders are no-ops.
|
|
144
131
|
// eslint-disable-next-line sonarjs/code-eval
|
|
145
|
-
new Function('StyleSheet', 'registerAtoms', body)(BUNDLE_STYLE_SHEET, lookupCss.registerAtoms);
|
|
132
|
+
new Function('StyleSheet', 'registerAtoms', 'registerMolecules', 'registerBreakpoints', 'registerGradients', 'registerHaptics', 'registerSchemeLoader', 'require', body)(BUNDLE_STYLE_SHEET, lookupCss.registerAtoms, resolve.registerMolecules, lookupCss.registerBreakpoints, resolve.registerGradients, resolve.registerHaptics, lookupCss.registerSchemeLoader, () => { });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Sort comparator that floats `common.style.js` to the front, rest alpha.
|
|
136
|
+
* @param a
|
|
137
|
+
* @param b
|
|
138
|
+
*/
|
|
139
|
+
function commonFirst(a, b) {
|
|
140
|
+
if (a === 'common.style.js')
|
|
141
|
+
return -1;
|
|
142
|
+
if (b === 'common.style.js')
|
|
143
|
+
return 1;
|
|
144
|
+
return a.localeCompare(b);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Evaluate every generated registry the transform wrote (`common` +
|
|
148
|
+
* every variant scheme + the manifest) so the runtime resolver sees the
|
|
149
|
+
* full atom / molecule / gradient / haptic registries — same state a
|
|
150
|
+
* production bundle would hold once all scheme files load.
|
|
151
|
+
* @param cacheDir The rnwind cache dir holding the generated files.
|
|
152
|
+
*/
|
|
153
|
+
function evaluateGeneratedRegistries(cacheDir) {
|
|
154
|
+
if (!node_fs.existsSync(cacheDir))
|
|
155
|
+
return;
|
|
156
|
+
const files = node_fs.readdirSync(cacheDir).filter((name) => name.endsWith('.style.js'));
|
|
157
|
+
// common first so variants layer their diffs on top of it.
|
|
158
|
+
for (const name of files.toSorted(commonFirst)) {
|
|
159
|
+
evaluateGeneratedFile(path.join(cacheDir, name));
|
|
160
|
+
}
|
|
161
|
+
evaluateGeneratedFile(path.join(cacheDir, 'schemes.js'));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Move every `const {…} = __rnwind;` / `const {…} = __reactNative;`
|
|
165
|
+
* binding line to the top of the source, preserving order, so they
|
|
166
|
+
* initialise before the transformer's `const View = _rnwWrap(_rnw0)`
|
|
167
|
+
* wrap declarations reference them. Mirrors ESM import hoisting.
|
|
168
|
+
* @param source Source with imports already converted to const-destructures.
|
|
169
|
+
* @returns Source with binding consts hoisted to the front.
|
|
170
|
+
*/
|
|
171
|
+
function hoistBindingConsts(source) {
|
|
172
|
+
const hoisted = [];
|
|
173
|
+
const rest = [];
|
|
174
|
+
for (const line of source.split('\n')) {
|
|
175
|
+
if (/=\s*__(?:rnwind|reactNative);\s*$/.test(line))
|
|
176
|
+
hoisted.push(line);
|
|
177
|
+
else
|
|
178
|
+
rest.push(line);
|
|
179
|
+
}
|
|
180
|
+
return [...hoisted, ...rest].join('\n');
|
|
146
181
|
}
|
|
147
182
|
/**
|
|
148
183
|
* Evaluate the transformer's rewritten source as a standalone module:
|
|
149
|
-
* strip synthetic imports, forward `import ... from 'rnwind'`
|
|
150
|
-
* `'react-native'` to local
|
|
151
|
-
* capture the default export.
|
|
184
|
+
* strip synthetic generated imports, forward `import ... from 'rnwind'`
|
|
185
|
+
* (incl. the injected `wrap as _rnwWrap`) and `'react-native'` to local
|
|
186
|
+
* bindings, compile JSX via the compiler, and capture the default export.
|
|
187
|
+
* Aliased named imports (`{ View as _rnw0 }`) are converted to valid
|
|
188
|
+
* destructuring (`{ View: _rnw0 }`). The import-derived `const`s are then
|
|
189
|
+
* hoisted above the body: the transformer injects `const View =
|
|
190
|
+
* _rnwWrap(_rnw0)` ahead of the (real-ESM-hoisted) `import … as _rnw0`,
|
|
191
|
+
* so without re-hoisting the binding the eval would hit a TDZ on `_rnw0`.
|
|
152
192
|
* @param transformedSource Post-transformer source.
|
|
153
193
|
* @param reactNative `react-native` namespace bindings to forward.
|
|
154
194
|
* @returns The default-exported component.
|
|
@@ -156,24 +196,14 @@ function evaluateStyleBundle(cacheDir) {
|
|
|
156
196
|
function evaluateRewrittenModule(transformedSource, reactNative) {
|
|
157
197
|
const prepared = transformedSource
|
|
158
198
|
.replaceAll(/import\s+["']rnwind\/__generated\/[^"']+["'];?\s*\n?/g, '')
|
|
159
|
-
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']rnwind["'];?/g,
|
|
160
|
-
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']react-native["'];?/g,
|
|
199
|
+
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']rnwind["'];?/g, (_m, spec) => `const {${spec.replaceAll(/\bas\b/g, ':')}} = __rnwind;`)
|
|
200
|
+
.replaceAll(/import\s+\{([^}]+)\}\s+from\s+["']react-native["'];?/g, (_m, spec) => `const {${spec.replaceAll(/\bas\b/g, ':')}} = __reactNative;`)
|
|
161
201
|
.replace(/export\s+default\s+/, 'module.exports.default = ');
|
|
162
|
-
const compiled = compileToJs(prepared);
|
|
163
|
-
const rnwindEnv = {
|
|
164
|
-
lookupCss: lookupCss.lookupCss,
|
|
165
|
-
useRnwind: rnwindProvider.useRnwind,
|
|
166
|
-
useR_: rnwindProvider.useR_,
|
|
167
|
-
useMountHaptic: haptics.useMountHaptic,
|
|
168
|
-
triggerHaptic: haptics.triggerHaptic,
|
|
169
|
-
useInteract: () => NOOP_INTERACT,
|
|
170
|
-
chainPress: NOOP_CHAIN,
|
|
171
|
-
chainFocus: NOOP_CHAIN,
|
|
172
|
-
};
|
|
202
|
+
const compiled = compileToJs(hoistBindingConsts(prepared));
|
|
173
203
|
const moduleObject = { exports: {} };
|
|
174
204
|
// Compiled source originates from rnwind's own transformer + the JSX compiler.
|
|
175
205
|
// eslint-disable-next-line sonarjs/code-eval
|
|
176
|
-
new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React__namespace,
|
|
206
|
+
new Function('React', '__rnwind', '__reactNative', 'module', compiled)(React__namespace, runtime_index, reactNative, moduleObject);
|
|
177
207
|
if (!moduleObject.exports.default) {
|
|
178
208
|
throw new Error('rnwind/testing: evaluated module did not export a default component.');
|
|
179
209
|
}
|
|
@@ -249,10 +279,11 @@ async function bootstrapRnwindRuntime(options) {
|
|
|
249
279
|
const ast = parser.parse(options.source, { sourceType: 'module', plugins: ['typescript', 'jsx'] });
|
|
250
280
|
const result = await metro_transformer.transform({ filename, src: options.source, options: { projectRoot }, ast });
|
|
251
281
|
transformedSource = generate(result.ast).code;
|
|
252
|
-
|
|
282
|
+
evaluateGeneratedRegistries(cacheDir);
|
|
253
283
|
}
|
|
254
284
|
const cleanup = () => {
|
|
255
285
|
lookupCss.__resetLookupCssState();
|
|
286
|
+
resolve.__resetResolveState();
|
|
256
287
|
state.resetRnwindState();
|
|
257
288
|
if (node_fs.existsSync(projectRoot))
|
|
258
289
|
node_fs.rmSync(projectRoot, { recursive: true, force: true });
|