rnwind 0.0.3 → 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/css-imports.cjs +81 -0
- package/lib/cjs/metro/css-imports.cjs.map +1 -0
- package/lib/cjs/metro/css-imports.d.ts +8 -0
- 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 +38 -86
- 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/css-imports.d.ts +8 -0
- package/lib/esm/metro/css-imports.mjs +79 -0
- package/lib/esm/metro/css-imports.mjs.map +1 -0
- 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 +39 -85
- 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/css-imports.ts +75 -0
- package/src/metro/dts.ts +7 -19
- package/src/metro/state.ts +38 -83
- 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
package/src/runtime/haptics.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime helpers the transformer injects for haptic utilities.
|
|
3
|
-
*
|
|
4
|
-
* Two entry points:
|
|
5
|
-
*
|
|
6
|
-
* useMountHaptic(requests) — fires each request on mount via
|
|
7
|
-
* `useEffect(() => { ... }, [])`. Used by the transformer for bare
|
|
8
|
-
* `haptic-*` atoms (no variant prefix).
|
|
9
|
-
*
|
|
10
|
-
* triggerHaptic(onHaptics, request, trigger) — thin forwarding
|
|
11
|
-
* helper for event-driven variants (`active:haptic-*`, `focus:...`,
|
|
12
|
-
* `hover:...`). The transformer emits an inline arrow that calls
|
|
13
|
-
* this from `onPressIn` / `onFocus` / etc.
|
|
14
|
-
*
|
|
15
|
-
* Both emit a one-shot dev-mode warning when `onHaptics` is missing —
|
|
16
|
-
* so developers get a clear "you forgot to wire <SchemeProvider
|
|
17
|
-
* onHaptics=...>" signal instead of silently dropping the haptic.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { useEffect } from 'react'
|
|
21
|
-
import type { HapticRequest, HapticTrigger, OnHaptics } from '../core/parser/haptics'
|
|
22
|
-
import { useRnwind } from './components/rnwind-provider'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Module-scope set tracking haptic trigger strings we've already
|
|
26
|
-
* warned about. Prevents the "missing onHaptics" warning from
|
|
27
|
-
* spamming the console when the same class appears on many elements.
|
|
28
|
-
*/
|
|
29
|
-
const WARNED_MISSING_HAPTICS = new Set<string>()
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Render a `HapticRequest` as a short descriptive tag for log lines.
|
|
33
|
-
* @param request Haptic request.
|
|
34
|
-
* @returns `impact/Light`, `notification/Success`, or `selection`.
|
|
35
|
-
*/
|
|
36
|
-
function hapticTag(request: HapticRequest): string {
|
|
37
|
-
if (request.kind === 'impact') return `impact/${request.style}`
|
|
38
|
-
if (request.kind === 'notification') return `notification/${request.type}`
|
|
39
|
-
return 'selection'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Warn once per haptic trigger kind when a `haptic-*` atom tries to
|
|
44
|
-
* dispatch without an `onHaptics` provider. Dev-mode only — `__DEV__`
|
|
45
|
-
* is a Metro / Expo / RN global that compiles to `false` in release
|
|
46
|
-
* bundles, so no warn code ships to production.
|
|
47
|
-
* @param request The haptic request that had no provider.
|
|
48
|
-
* @param trigger The lifecycle trigger that tried to fire.
|
|
49
|
-
*/
|
|
50
|
-
function warnMissingOnHaptics(request: HapticRequest, trigger: HapticTrigger): void {
|
|
51
|
-
// `__DEV__` is a RN / Metro global — `false` in release, strips the
|
|
52
|
-
// branch entirely. Guarded in case we're evaluated outside of Metro
|
|
53
|
-
// (tests, node scripts) where the global isn't defined.
|
|
54
|
-
const isDevelopment = typeof __DEV__ === 'undefined' || __DEV__
|
|
55
|
-
if (!isDevelopment) return
|
|
56
|
-
const tag = hapticTag(request)
|
|
57
|
-
const key = `${tag}@${trigger}`
|
|
58
|
-
if (WARNED_MISSING_HAPTICS.has(key)) return
|
|
59
|
-
WARNED_MISSING_HAPTICS.add(key)
|
|
60
|
-
// eslint-disable-next-line no-console
|
|
61
|
-
console.warn(
|
|
62
|
-
`rnwind: a haptic utility fired (${tag}, trigger=${trigger}) but no onHaptics callback is wired on <SchemeProvider>. ` +
|
|
63
|
-
`Pass \`onHaptics\` on the provider to forward this to expo-haptics (or any library of your choice).`,
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Test-only hook — clears the warned-haptics set so successive test
|
|
69
|
-
* runs don't silently swallow their own warnings.
|
|
70
|
-
*/
|
|
71
|
-
function __resetHapticWarnings(): void {
|
|
72
|
-
WARNED_MISSING_HAPTICS.clear()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Invoke every request in `requests` on mount (once per component
|
|
77
|
-
* mount), using the `onHaptics` dispatcher from the nearest
|
|
78
|
-
* `<SchemeProvider>`. Missing-provider dev warnings fire via
|
|
79
|
-
* {@link warnMissingOnHaptics}.
|
|
80
|
-
*
|
|
81
|
-
* Uses `useEffect(..., [])` — the requests array is identity-stable
|
|
82
|
-
* (hoisted at module scope by the transformer), so re-firing on
|
|
83
|
-
* re-renders isn't a concern.
|
|
84
|
-
* @param requests Hoisted request list for this component.
|
|
85
|
-
*/
|
|
86
|
-
function useMountHaptic(requests: readonly HapticRequest[]): void {
|
|
87
|
-
const { onHaptics } = useRnwind()
|
|
88
|
-
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
for (const request of requests) {
|
|
91
|
-
if (onHaptics) onHaptics(request, 'mount')
|
|
92
|
-
else warnMissingOnHaptics(request, 'mount')
|
|
93
|
-
}
|
|
94
|
-
// requests is a hoisted stable reference — depending on onHaptics
|
|
95
|
-
// identity keeps the effect fresh if the provider remounts with a
|
|
96
|
-
// different dispatcher, while the hoisted const prevents a remount
|
|
97
|
-
// from an inline `onHaptics={(r) => ...}`.
|
|
98
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
99
|
-
}, [onHaptics])
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Fire one haptic request through the provider dispatcher. Emits the
|
|
104
|
-
* missing-provider dev warning when no dispatcher is wired. Designed
|
|
105
|
-
* for the inline arrows the transformer synthesises:
|
|
106
|
-
*
|
|
107
|
-
* onPressIn={(e) => { triggerHaptic(_h, _HR_xxx, 'pressIn'); user?.(e) }}
|
|
108
|
-
* @param onHaptics Provider dispatcher (may be undefined).
|
|
109
|
-
* @param request Pre-hoisted request object.
|
|
110
|
-
* @param trigger Lifecycle trigger.
|
|
111
|
-
*/
|
|
112
|
-
function triggerHaptic(onHaptics: OnHaptics | undefined, request: HapticRequest, trigger: HapticTrigger): void {
|
|
113
|
-
if (onHaptics) {
|
|
114
|
-
onHaptics(request, trigger)
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
warnMissingOnHaptics(request, trigger)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { useMountHaptic, triggerHaptic, __resetHapticWarnings }
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createElement, type ComponentType, type ElementType, type ReactElement } from 'react'
|
|
2
|
-
import { chainFocus, chainPress } from './chain-handlers'
|
|
3
|
-
import { useInteract } from './hooks/use-interact'
|
|
4
|
-
import { lookupCss, type HoistedClassName } from './lookup-css'
|
|
5
|
-
import type { RnwindState } from './components/rnwind-provider'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Per-element "interactive" spec the transformer packs into the `_rw`
|
|
9
|
-
* prop on every JSX site it rewrites for active/focus support. Carrying
|
|
10
|
-
* it as one object prop (rather than four sibling props) keeps the
|
|
11
|
-
* rewritten JSX legible and avoids colliding with any host component's
|
|
12
|
-
* own naming.
|
|
13
|
-
*/
|
|
14
|
-
export interface InteractiveSpec {
|
|
15
|
-
/** The original JSX tag (`Pressable`, `TextInput`, `Animated.View`, …). */
|
|
16
|
-
readonly as: ElementType
|
|
17
|
-
/** Hoisted atom-name array (or a dynamic classname string). */
|
|
18
|
-
readonly cn: HoistedClassName | string | null | undefined
|
|
19
|
-
/** Full rnwind context — `_t = useRnwind___()` from the call site. */
|
|
20
|
-
readonly t: RnwindState
|
|
21
|
-
/** Optional caller-supplied style forwarded as `lookupCss`'s 3rd arg. */
|
|
22
|
-
readonly us?: unknown
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Props InteractiveBox accepts — `_rw` plus anything to forward. */
|
|
26
|
-
export interface InteractiveBoxProps {
|
|
27
|
-
/** Compile-time spec packed by the transformer. */
|
|
28
|
-
readonly _rw: InteractiveSpec
|
|
29
|
-
/** Every other prop passes through to the inner component. */
|
|
30
|
-
readonly [key: string]: unknown
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Per-instance wrapper that drives `active:` / `focus:` variants. One
|
|
35
|
-
* `useInteract()` hook per mounted `InteractiveBox` means each element
|
|
36
|
-
* owns its own state — siblings never share `active` / `focus` flags.
|
|
37
|
-
*
|
|
38
|
-
* The transformer replaces
|
|
39
|
-
* `<Pressable className="active:bg-sky-700" onPress={x} />`
|
|
40
|
-
* with
|
|
41
|
-
* `<InteractiveBox _rw={{as: Pressable, cn: _c0, t: _t}} onPress={x} />`.
|
|
42
|
-
* @param props `_rw` spec + any props to forward to the inner component.
|
|
43
|
-
* @returns Rendered element of the inner component with interact wiring.
|
|
44
|
-
*/
|
|
45
|
-
export function InteractiveBox(props: InteractiveBoxProps): ReactElement {
|
|
46
|
-
const { _rw, onPressIn, onPressOut, onFocus, onBlur, ...rest } = props
|
|
47
|
-
const interact = useInteract()
|
|
48
|
-
const merged: Record<string, unknown> = {
|
|
49
|
-
...rest,
|
|
50
|
-
style: lookupCss(_rw.cn, _rw.t, _rw.us, interact.state),
|
|
51
|
-
onPressIn: chainPress(onPressIn as Parameters<typeof chainPress>[0], interact.onPressIn),
|
|
52
|
-
onPressOut: chainPress(onPressOut as Parameters<typeof chainPress>[0], interact.onPressOut),
|
|
53
|
-
onFocus: chainFocus(onFocus as Parameters<typeof chainFocus>[0], interact.onFocus),
|
|
54
|
-
onBlur: chainFocus(onBlur as Parameters<typeof chainFocus>[0], interact.onBlur),
|
|
55
|
-
}
|
|
56
|
-
return createElement(_rw.as as ComponentType<Record<string, unknown>>, merged)
|
|
57
|
-
}
|