glacia-native 0.3.5 → 0.4.0
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/module/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Form.js +51 -12
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/internal/GlassView.js +17 -19
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +408 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Glass.d.ts +9 -0
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/internal/GlassView.d.ts +11 -3
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/package.json +2 -2
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Dialog.tsx +99 -64
- package/src/Form.tsx +90 -25
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/internal/GlassView.tsx +31 -21
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +477 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
// React Native component resolution.
|
|
2
|
+
//
|
|
3
|
+
// The package never imports `react-native` or `react-native-svg` statically:
|
|
4
|
+
// both ship Flow-typed sources that a plain JS bundler (and the jsdom test
|
|
5
|
+
// environment) cannot parse. Resolving them at runtime keeps the package
|
|
6
|
+
// importable everywhere, matching how GlassView locates the native liquid
|
|
7
|
+
// glass module.
|
|
8
|
+
//
|
|
9
|
+
// Every component in the package builds its structure from these primitives.
|
|
10
|
+
// On a device the resolver returns React Native's own View/Text/Pressable/…
|
|
11
|
+
// and react-native-svg's elements. The DOM stand-ins further down exist only
|
|
12
|
+
// for the case where React Native is genuinely absent: a jsdom test run or a
|
|
13
|
+
// web preview. They are the single place in the package allowed to emit DOM
|
|
14
|
+
// host elements, and their whole job is translating React Native props into
|
|
15
|
+
// DOM ones.
|
|
16
|
+
|
|
17
|
+
declare const require: any;
|
|
18
|
+
|
|
19
|
+
/** Minimal shapes of the React Native primitives the package uses. */
|
|
20
|
+
export interface RNPrimitives {
|
|
21
|
+
View: any;
|
|
22
|
+
Text: any;
|
|
23
|
+
Pressable: any;
|
|
24
|
+
Svg: any;
|
|
25
|
+
G: any;
|
|
26
|
+
Line: any;
|
|
27
|
+
Path: any;
|
|
28
|
+
Circle: any;
|
|
29
|
+
Rect: any;
|
|
30
|
+
Polygon: any;
|
|
31
|
+
SvgText: any;
|
|
32
|
+
TextInput: any;
|
|
33
|
+
Modal: any;
|
|
34
|
+
Image: any;
|
|
35
|
+
/** React Native's Animated API, or a no-op animation shim off-device. */
|
|
36
|
+
Animated: any;
|
|
37
|
+
/** React Native's Easing curves, used with Animated.spring. */
|
|
38
|
+
Easing: any;
|
|
39
|
+
/** React Native's ScrollView, or null when it is unavailable. */
|
|
40
|
+
getScrollView: () => any;
|
|
41
|
+
/** React Native's BackHandler, or null outside a native runtime. */
|
|
42
|
+
getBackHandler: () => any;
|
|
43
|
+
/** True when the returned primitives are React Native's own. */
|
|
44
|
+
isNative: boolean;
|
|
45
|
+
/** React Native's PanResponder, or a DOM stand-in off-device. */
|
|
46
|
+
PanResponder: any;
|
|
47
|
+
/** React Native's useColorScheme, or null outside a native runtime. */
|
|
48
|
+
useColorScheme: (() => "light" | "dark" | null | undefined) | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolves the primitives, falling back to pass-through DOM elements so the
|
|
53
|
+
* package can be rendered in a non-native environment (tests, web preview)
|
|
54
|
+
* without throwing.
|
|
55
|
+
*/
|
|
56
|
+
function resolve(): RNPrimitives {
|
|
57
|
+
let rn: any = null;
|
|
58
|
+
let svg: any = null;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
rn = require("react-native");
|
|
62
|
+
} catch {
|
|
63
|
+
// Non-native environment: the DOM stand-ins below take over.
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
svg = require("react-native-svg");
|
|
68
|
+
} catch {
|
|
69
|
+
svg = null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// On a device the SVG elements are required: the DOM <svg> stand-ins would
|
|
73
|
+
// crash in a real app ("View config not found"), so say so loudly instead of
|
|
74
|
+
// silently degrading to something that cannot run.
|
|
75
|
+
if (rn && !svg) {
|
|
76
|
+
console.error(
|
|
77
|
+
"[glacia-native] react-native-svg is required by the Glacia charts but could not be " +
|
|
78
|
+
"resolved. Install it as a dependency of your app (npx expo install react-native-svg). " +
|
|
79
|
+
"Charts will not render until it is available.",
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Adapts React Native props to the DOM preview used when RN is absent.
|
|
85
|
+
* Without this, `accessibilityRole` and `onPress` reach the DOM untranslated
|
|
86
|
+
* and the element is neither reachable nor clickable in tests.
|
|
87
|
+
*/
|
|
88
|
+
const fallback = (tag: string) =>
|
|
89
|
+
function Primitive(props: any) {
|
|
90
|
+
const {
|
|
91
|
+
children,
|
|
92
|
+
style,
|
|
93
|
+
accessibilityRole,
|
|
94
|
+
accessibilityLabel,
|
|
95
|
+
accessible,
|
|
96
|
+
accessibilityState,
|
|
97
|
+
accessibilityValue,
|
|
98
|
+
onPress,
|
|
99
|
+
numberOfLines,
|
|
100
|
+
onChangeText,
|
|
101
|
+
value,
|
|
102
|
+
editable: editableProp,
|
|
103
|
+
nativeID,
|
|
104
|
+
disabled,
|
|
105
|
+
keyboardType: _keyboardType,
|
|
106
|
+
returnKeyType: _returnKeyType,
|
|
107
|
+
onSubmitEditing: _onSubmitEditing,
|
|
108
|
+
secureTextEntry: _secureTextEntry,
|
|
109
|
+
autoCapitalize: _autoCapitalize,
|
|
110
|
+
autoCorrect: _autoCorrect,
|
|
111
|
+
multiline,
|
|
112
|
+
onFocus: _onFocus,
|
|
113
|
+
onBlur: _onBlur,
|
|
114
|
+
testID,
|
|
115
|
+
// Gesture handlers from PanResponder.panHandlers are plain DOM events
|
|
116
|
+
// off-device; let them reach the element so a drag is exercisable.
|
|
117
|
+
onMouseDown,
|
|
118
|
+
onMouseMove,
|
|
119
|
+
onMouseUp,
|
|
120
|
+
onMouseLeave,
|
|
121
|
+
onLayout: _onLayout,
|
|
122
|
+
onAccessibilityAction,
|
|
123
|
+
accessibilityActions: _accessibilityActions,
|
|
124
|
+
...rest
|
|
125
|
+
} = props ?? {};
|
|
126
|
+
const { createElement } = require("react");
|
|
127
|
+
const editable = editableProp;
|
|
128
|
+
|
|
129
|
+
// RN accepts unitless numbers where the DOM requires "px"; convert the
|
|
130
|
+
// length properties so the preview lays out instead of throwing.
|
|
131
|
+
const domProps: any = { style: toDomStyle(style), ...rest };
|
|
132
|
+
|
|
133
|
+
// RN roles that already exist in ARIA pass straight through.
|
|
134
|
+
const ROLE_MAP: Record<string, string> = {
|
|
135
|
+
button: "button",
|
|
136
|
+
checkbox: "checkbox",
|
|
137
|
+
radio: "radio",
|
|
138
|
+
radiogroup: "radiogroup",
|
|
139
|
+
alert: "alert",
|
|
140
|
+
text: "text",
|
|
141
|
+
link: "link",
|
|
142
|
+
image: "img",
|
|
143
|
+
tab: "tab",
|
|
144
|
+
tablist: "tablist",
|
|
145
|
+
progressbar: "progressbar",
|
|
146
|
+
switch: "switch",
|
|
147
|
+
slider: "slider",
|
|
148
|
+
adjustable: "slider",
|
|
149
|
+
heading: "heading",
|
|
150
|
+
};
|
|
151
|
+
// "none" means presentational: emit no role rather than a misleading one.
|
|
152
|
+
if (accessibilityRole && accessibilityRole !== "none") {
|
|
153
|
+
domProps.role = ROLE_MAP[accessibilityRole] ?? "text";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (accessibilityLabel != null) domProps["aria-label"] = accessibilityLabel;
|
|
157
|
+
// RN's `accessible` groups children into one element; a role carries the
|
|
158
|
+
// same meaning in the DOM, so it is dropped rather than emitted raw.
|
|
159
|
+
if (accessible !== undefined && !domProps.role) domProps.role = "group";
|
|
160
|
+
if (numberOfLines != null) domProps["data-lines"] = numberOfLines;
|
|
161
|
+
if (nativeID != null) domProps.id = nativeID;
|
|
162
|
+
if (testID != null) domProps["data-testid"] = testID;
|
|
163
|
+
|
|
164
|
+
if (accessibilityState) {
|
|
165
|
+
const state = accessibilityState;
|
|
166
|
+
if (state.checked !== undefined) domProps["aria-checked"] = state.checked;
|
|
167
|
+
if (state.selected !== undefined) domProps["aria-selected"] = state.selected;
|
|
168
|
+
if (state.expanded !== undefined) domProps["aria-expanded"] = state.expanded;
|
|
169
|
+
if (state.disabled !== undefined) domProps["aria-disabled"] = state.disabled;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (accessibilityValue) {
|
|
173
|
+
const value = accessibilityValue;
|
|
174
|
+
if (value.min !== undefined) domProps["aria-valuemin"] = value.min;
|
|
175
|
+
if (value.max !== undefined) domProps["aria-valuemax"] = value.max;
|
|
176
|
+
if (value.now !== undefined) domProps["aria-valuenow"] = value.now;
|
|
177
|
+
if (value.text !== undefined) domProps["aria-valuetext"] = value.text;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Inputs: bridge the RN controlled-value contract to the DOM one.
|
|
181
|
+
if (tag === "input") {
|
|
182
|
+
// A multiline field must be a real textarea: an <input> cannot wrap.
|
|
183
|
+
if (multiline) {
|
|
184
|
+
tag = "textarea";
|
|
185
|
+
if (typeof numberOfLines === "number") domProps.rows = numberOfLines;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (tag === "input" || tag === "textarea") {
|
|
190
|
+
if (value != null) domProps.value = value;
|
|
191
|
+
if (onChangeText) {
|
|
192
|
+
domProps.onChange = (event: any) => onChangeText(event.target.value);
|
|
193
|
+
}
|
|
194
|
+
if (editable === false || disabled) domProps.disabled = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Accessibility actions are React Native's; off-device they are exposed
|
|
198
|
+
// as a handler so a test can drive them, matching the role translation.
|
|
199
|
+
if (onAccessibilityAction) domProps.onAccessibilityAction = onAccessibilityAction;
|
|
200
|
+
if (onMouseDown) domProps.onMouseDown = onMouseDown;
|
|
201
|
+
if (onMouseMove) domProps.onMouseMove = onMouseMove;
|
|
202
|
+
if (onMouseUp) domProps.onMouseUp = onMouseUp;
|
|
203
|
+
if (onMouseLeave) domProps.onMouseLeave = onMouseLeave;
|
|
204
|
+
|
|
205
|
+
if (onPress) {
|
|
206
|
+
// Any element hosting a press handler needs a DOM click to fire it.
|
|
207
|
+
domProps.onClick = onPress;
|
|
208
|
+
if (
|
|
209
|
+
domProps.role === "button" ||
|
|
210
|
+
domProps.role === "checkbox" ||
|
|
211
|
+
domProps.role === "radio" ||
|
|
212
|
+
domProps.role === "switch" ||
|
|
213
|
+
domProps.role === "tab" ||
|
|
214
|
+
domProps.role === "slider"
|
|
215
|
+
) {
|
|
216
|
+
domProps.tabIndex = 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (disabled) domProps["aria-disabled"] = true;
|
|
220
|
+
|
|
221
|
+
return createElement(tag, domProps, children);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Resolves React Native's BackHandler, or null off-device. */
|
|
225
|
+
const getBackHandler = () => rn?.BackHandler ?? null;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* A Modal that only mounts its children while visible.
|
|
229
|
+
*
|
|
230
|
+
* The generic fallback would render the content regardless of `visible`,
|
|
231
|
+
* which would surface every closed dialog in the DOM preview.
|
|
232
|
+
*/
|
|
233
|
+
const modalFallback = (tag: string) =>
|
|
234
|
+
function Primitive(props: any) {
|
|
235
|
+
const { children, visible, onRequestClose: _onRequestClose, ...rest } = props ?? {};
|
|
236
|
+
if (!visible) return null;
|
|
237
|
+
const { createElement } = require("react");
|
|
238
|
+
return createElement(tag, { style: toDomStyle(rest.style) }, children);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/** An image that reads its remote source in the DOM preview. */
|
|
242
|
+
function imageFallback(props: any) {
|
|
243
|
+
const { source, accessibilityLabel, style } = props ?? {};
|
|
244
|
+
const { createElement } = require("react");
|
|
245
|
+
return createElement("img", {
|
|
246
|
+
src: source?.uri,
|
|
247
|
+
alt: accessibilityLabel ?? "",
|
|
248
|
+
style: toDomStyle(style),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const SvgComponent = svg?.default ?? fallback("svg");
|
|
253
|
+
const SvgText = svg?.Text ?? fallback("text");
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
View: rn?.View ?? fallback("div"),
|
|
257
|
+
Text: rn?.Text ?? fallback("span"),
|
|
258
|
+
Pressable: rn?.Pressable ?? fallback("button"),
|
|
259
|
+
Svg: SvgComponent,
|
|
260
|
+
G: svg?.G ?? fallback("g"),
|
|
261
|
+
Line: svg?.Line ?? fallback("line"),
|
|
262
|
+
Path: svg?.Path ?? fallback("path"),
|
|
263
|
+
Circle: svg?.Circle ?? fallback("circle"),
|
|
264
|
+
Rect: svg?.Rect ?? fallback("rect"),
|
|
265
|
+
Polygon: svg?.Polygon ?? fallback("polygon"),
|
|
266
|
+
// TextInput is not an SVG primitive, but resolving it here keeps every
|
|
267
|
+
// component on one runtime-resolution path instead of two.
|
|
268
|
+
TextInput: rn?.TextInput ?? fallback("input"),
|
|
269
|
+
// Modal is resolved the same way so dialogs degrade to a plain overlay
|
|
270
|
+
// outside a native runtime instead of failing to mount.
|
|
271
|
+
Modal: rn?.Modal ?? modalFallback("div"),
|
|
272
|
+
Image: rn?.Image ?? imageFallback,
|
|
273
|
+
// Animated comes from the same module; off-device the shim below keeps
|
|
274
|
+
// Animated.View/Value/spring from throwing in the DOM preview.
|
|
275
|
+
Animated: rn?.Animated ?? animationShim(require("react")),
|
|
276
|
+
Easing: rn?.Easing ?? easingShim(),
|
|
277
|
+
getScrollView: () => rn?.ScrollView ?? null,
|
|
278
|
+
getBackHandler,
|
|
279
|
+
SvgText,
|
|
280
|
+
isNative: Boolean(rn?.View),
|
|
281
|
+
PanResponder: rn?.PanResponder ?? panResponderShim(),
|
|
282
|
+
useColorScheme: rn?.useColorScheme ?? null,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* A stand-in for React Native's Animated API off-device.
|
|
288
|
+
*
|
|
289
|
+
* `Animated.Value` keeps the value it was given and `spring` snaps to the
|
|
290
|
+
* target immediately, so the preview renders the settled state instead of
|
|
291
|
+
* animating against a requestAnimationFrame loop that jsdom does not drive.
|
|
292
|
+
*/
|
|
293
|
+
function animationShim(reactModule: any): any {
|
|
294
|
+
class Value {
|
|
295
|
+
private current: number;
|
|
296
|
+
constructor(initial: number) {
|
|
297
|
+
this.current = initial;
|
|
298
|
+
}
|
|
299
|
+
setValue(next: number) {
|
|
300
|
+
this.current = next;
|
|
301
|
+
}
|
|
302
|
+
interpolate(config: any) {
|
|
303
|
+
const input = config?.inputRange;
|
|
304
|
+
const output = config?.outputRange;
|
|
305
|
+
if (!input || !output || input.length !== output.length) return this.current;
|
|
306
|
+
for (let i = 0; i < input.length - 1; i += 1) {
|
|
307
|
+
if (this.current <= input[i + 1]) {
|
|
308
|
+
const span = input[i + 1] - input[i] || 1;
|
|
309
|
+
const ratio = (this.current - input[i]) / span;
|
|
310
|
+
return output[i] + (output[i + 1] - output[i]) * ratio;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return output[output.length - 1];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function AnimatedView(props: any) {
|
|
318
|
+
const { style, children, ...rest } = props ?? {};
|
|
319
|
+
return reactModule.createElement(
|
|
320
|
+
"div",
|
|
321
|
+
{ style: toDomStyle(resolveAnimatedStyle(style)), ...rest },
|
|
322
|
+
children,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
Value,
|
|
328
|
+
View: AnimatedView,
|
|
329
|
+
Text: AnimatedView,
|
|
330
|
+
spring: (value: any, config: any) => {
|
|
331
|
+
value?.setValue?.(config?.toValue ?? 0);
|
|
332
|
+
return { start: (callback?: any) => callback?.({ finished: true }), stop: () => {} };
|
|
333
|
+
},
|
|
334
|
+
timing: (value: any, config: any) => {
|
|
335
|
+
value?.setValue?.(config?.toValue ?? 0);
|
|
336
|
+
return { start: (callback?: any) => callback?.({ finished: true }), stop: () => {} };
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* A stand-in for React Native's PanResponder off-device.
|
|
343
|
+
*
|
|
344
|
+
* It runs the handler hooks on DOM pointer events so a drag written against
|
|
345
|
+
* PanResponder is still exercisable in the preview and in tests. On a device
|
|
346
|
+
* the resolver returns React Native's own implementation.
|
|
347
|
+
*/
|
|
348
|
+
function panResponderShim(): any {
|
|
349
|
+
return {
|
|
350
|
+
create: (config: any) => {
|
|
351
|
+
let granted = false;
|
|
352
|
+
const start = (event: any) => {
|
|
353
|
+
if (!config?.onStartShouldSetPanResponder?.(event, gesture(event))) return;
|
|
354
|
+
granted = true;
|
|
355
|
+
config?.onPanResponderGrant?.(event, gesture(event));
|
|
356
|
+
};
|
|
357
|
+
const move = (event: any) => {
|
|
358
|
+
if (!granted) {
|
|
359
|
+
if (!config?.onMoveShouldSetPanResponder?.(event, gesture(event))) return;
|
|
360
|
+
granted = true;
|
|
361
|
+
config?.onPanResponderGrant?.(event, gesture(event));
|
|
362
|
+
}
|
|
363
|
+
config?.onPanResponderMove?.(event, gesture(event));
|
|
364
|
+
};
|
|
365
|
+
const end = (event: any) => {
|
|
366
|
+
if (!granted) return;
|
|
367
|
+
granted = false;
|
|
368
|
+
config?.onPanResponderRelease?.(event, gesture(event));
|
|
369
|
+
};
|
|
370
|
+
return {
|
|
371
|
+
panHandlers: {
|
|
372
|
+
onMouseDown: start,
|
|
373
|
+
onMouseMove: move,
|
|
374
|
+
onMouseUp: end,
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Reads a touch position the way React Native's gesture object does. */
|
|
382
|
+
function gesture(event: any): any {
|
|
383
|
+
const target = event?.currentTarget;
|
|
384
|
+
const rect = target?.getBoundingClientRect?.();
|
|
385
|
+
const x = event?.clientX ?? 0;
|
|
386
|
+
const y = event?.clientY ?? 0;
|
|
387
|
+
const locationX = rect ? x - rect.left : x;
|
|
388
|
+
const locationY = rect ? y - rect.top : y;
|
|
389
|
+
if (event && !event.nativeEvent) {
|
|
390
|
+
event.nativeEvent = { locationX, locationY, pageX: x, pageY: y };
|
|
391
|
+
}
|
|
392
|
+
return { dx: 0, dy: 0, moveX: x, moveY: y, x0: x, y0: y, vx: 0, vy: 0 };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Stand-in for React Native's Easing curves. */
|
|
396
|
+
function easingShim(): any {
|
|
397
|
+
const identity = (t: number) => t;
|
|
398
|
+
return {
|
|
399
|
+
out: (fn: (t: number) => number) => fn,
|
|
400
|
+
inOut: (fn: (t: number) => number) => fn,
|
|
401
|
+
linear: identity,
|
|
402
|
+
ease: identity,
|
|
403
|
+
quad: identity,
|
|
404
|
+
bezier: () => identity,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Reads a style value that may be an Animated.Value after the shim resolved it. */
|
|
409
|
+
function resolveAnimatedStyle(style: any): any {
|
|
410
|
+
if (!style) return style;
|
|
411
|
+
const list = Array.isArray(style) ? style : [style];
|
|
412
|
+
const merged: Record<string, any> = {};
|
|
413
|
+
for (const entry of list) {
|
|
414
|
+
if (!entry) continue;
|
|
415
|
+
Object.assign(merged, entry);
|
|
416
|
+
}
|
|
417
|
+
return merged;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const LENGTH_PROPS = new Set([
|
|
421
|
+
"width",
|
|
422
|
+
"height",
|
|
423
|
+
"top",
|
|
424
|
+
"left",
|
|
425
|
+
"right",
|
|
426
|
+
"bottom",
|
|
427
|
+
"marginTop",
|
|
428
|
+
"marginBottom",
|
|
429
|
+
"marginLeft",
|
|
430
|
+
"marginRight",
|
|
431
|
+
"paddingTop",
|
|
432
|
+
"paddingBottom",
|
|
433
|
+
"paddingLeft",
|
|
434
|
+
"paddingRight",
|
|
435
|
+
"fontSize",
|
|
436
|
+
"borderRadius",
|
|
437
|
+
"gap",
|
|
438
|
+
]);
|
|
439
|
+
|
|
440
|
+
/** Converts an RN style object to DOM-compatible CSS. */
|
|
441
|
+
function toDomStyle(style: any): any {
|
|
442
|
+
if (!style) return style;
|
|
443
|
+
const list = Array.isArray(style) ? style : [style];
|
|
444
|
+
const merged: Record<string, any> = {};
|
|
445
|
+
|
|
446
|
+
for (const entry of list) {
|
|
447
|
+
if (!entry) continue;
|
|
448
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
449
|
+
if (value == null) continue;
|
|
450
|
+
// Animated values resolve to plain numbers off-device.
|
|
451
|
+
const resolved =
|
|
452
|
+
typeof (value as any)?.interpolate === "function" ? (value as any).__getValue?.() : value;
|
|
453
|
+
merged[key] =
|
|
454
|
+
typeof resolved === "number" && LENGTH_PROPS.has(key) ? `${resolved}px` : resolved;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return merged;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Records an element's width for gesture maths when the environment has no
|
|
462
|
+
* layout events (the DOM preview). A device never needs it: React Native
|
|
463
|
+
* reports width through `onLayout`.
|
|
464
|
+
*/
|
|
465
|
+
export function measurePreviewWidth(node: any, widthRef: { current: number }) {
|
|
466
|
+
if (!node || typeof node.getBoundingClientRect !== "function") return;
|
|
467
|
+
const width = node.getBoundingClientRect().width;
|
|
468
|
+
if (width > 0) widthRef.current = width;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
let cache: RNPrimitives | null = null;
|
|
472
|
+
|
|
473
|
+
/** The resolved primitives, computed once per process. */
|
|
474
|
+
export function primitives(): RNPrimitives {
|
|
475
|
+
if (!cache) cache = resolve();
|
|
476
|
+
return cache;
|
|
477
|
+
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// React Native component resolution.
|
|
3
|
-
//
|
|
4
|
-
// The package never imports `react-native` or `react-native-svg` statically:
|
|
5
|
-
// both ship Flow-typed sources that a plain JS bundler (and the jsdom test
|
|
6
|
-
// environment) cannot parse. Resolving them at runtime keeps the package
|
|
7
|
-
// importable everywhere, matching how GlassView already locates the native
|
|
8
|
-
// liquid glass module.
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.primitives = primitives;
|
|
11
|
-
/**
|
|
12
|
-
* Resolves the primitives, falling back to pass-through DOM elements so the
|
|
13
|
-
* package can be rendered in a non-native environment (tests, web preview)
|
|
14
|
-
* without throwing.
|
|
15
|
-
*/
|
|
16
|
-
function resolve() {
|
|
17
|
-
let View;
|
|
18
|
-
let Text;
|
|
19
|
-
let Pressable;
|
|
20
|
-
let svg = null;
|
|
21
|
-
let rn = null;
|
|
22
|
-
try {
|
|
23
|
-
rn = require("react-native");
|
|
24
|
-
View = rn.View;
|
|
25
|
-
Text = rn.Text;
|
|
26
|
-
Pressable = rn.Pressable;
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// Non-native environment: render simple elements instead.
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
svg = require("react-native-svg");
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
svg = null;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Adapts React Native props to the DOM preview used when RN is absent.
|
|
39
|
-
* Without this, `accessibilityRole` and `onPress` reach the DOM untranslated
|
|
40
|
-
* and the element is neither reachable nor clickable in tests.
|
|
41
|
-
*/
|
|
42
|
-
const fallback = (tag) => function Primitive(props) {
|
|
43
|
-
const { children, style, accessibilityRole, accessibilityLabel, accessibilityState, onPress, numberOfLines, onChangeText, value, editable, nativeID, disabled, keyboardType: _keyboardType, returnKeyType: _returnKeyType, onSubmitEditing: _onSubmitEditing, secureTextEntry: _secureTextEntry, autoCapitalize: _autoCapitalize, autoCorrect: _autoCorrect, multiline, onFocus: _onFocus, onBlur: _onBlur, editable: _editable, ...rest } = props ?? {};
|
|
44
|
-
const { createElement } = require("react");
|
|
45
|
-
// RN accepts unitless numbers where the DOM requires "px"; convert the
|
|
46
|
-
// length properties so the preview lays out instead of throwing.
|
|
47
|
-
const domProps = { style: toDomStyle(style), ...rest };
|
|
48
|
-
// RN roles that already exist in ARIA pass straight through.
|
|
49
|
-
const ROLE_MAP = {
|
|
50
|
-
button: "button",
|
|
51
|
-
checkbox: "checkbox",
|
|
52
|
-
radio: "radio",
|
|
53
|
-
radiogroup: "radiogroup",
|
|
54
|
-
alert: "alert",
|
|
55
|
-
text: "text",
|
|
56
|
-
link: "link",
|
|
57
|
-
image: "img",
|
|
58
|
-
tab: "tab",
|
|
59
|
-
progressbar: "progressbar",
|
|
60
|
-
tablist: "tablist",
|
|
61
|
-
switch: "switch",
|
|
62
|
-
slider: "slider",
|
|
63
|
-
heading: "heading",
|
|
64
|
-
};
|
|
65
|
-
// "none" means presentational: emit no role rather than a misleading one.
|
|
66
|
-
if (accessibilityRole && accessibilityRole !== "none") {
|
|
67
|
-
domProps.role = ROLE_MAP[accessibilityRole] ?? "text";
|
|
68
|
-
}
|
|
69
|
-
if (accessibilityLabel != null)
|
|
70
|
-
domProps["aria-label"] = accessibilityLabel;
|
|
71
|
-
if (numberOfLines != null)
|
|
72
|
-
domProps["data-lines"] = numberOfLines;
|
|
73
|
-
if (nativeID != null)
|
|
74
|
-
domProps.id = nativeID;
|
|
75
|
-
if (accessibilityState) {
|
|
76
|
-
const state = accessibilityState;
|
|
77
|
-
if (state.checked !== undefined)
|
|
78
|
-
domProps["aria-checked"] = state.checked;
|
|
79
|
-
if (state.selected !== undefined)
|
|
80
|
-
domProps["aria-selected"] = state.selected;
|
|
81
|
-
if (state.expanded !== undefined)
|
|
82
|
-
domProps["aria-expanded"] = state.expanded;
|
|
83
|
-
if (state.disabled !== undefined)
|
|
84
|
-
domProps["aria-disabled"] = state.disabled;
|
|
85
|
-
}
|
|
86
|
-
// Inputs: bridge the RN controlled-value contract to the DOM one.
|
|
87
|
-
if (tag === "input") {
|
|
88
|
-
// A multiline field must be a real textarea: an <input> cannot wrap.
|
|
89
|
-
if (multiline) {
|
|
90
|
-
tag = "textarea";
|
|
91
|
-
if (typeof numberOfLines === "number")
|
|
92
|
-
domProps.rows = numberOfLines;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (tag === "input" || tag === "textarea") {
|
|
96
|
-
if (value != null)
|
|
97
|
-
domProps.value = value;
|
|
98
|
-
if (onChangeText) {
|
|
99
|
-
domProps.onChange = (event) => onChangeText(event.target.value);
|
|
100
|
-
}
|
|
101
|
-
if (editable === false || disabled)
|
|
102
|
-
domProps.disabled = true;
|
|
103
|
-
}
|
|
104
|
-
if (onPress) {
|
|
105
|
-
if (tag === "button" || tag === "input")
|
|
106
|
-
domProps.onClick = onPress;
|
|
107
|
-
else {
|
|
108
|
-
// A non-button element needs to be operable from the keyboard too.
|
|
109
|
-
domProps.onClick = onPress;
|
|
110
|
-
if (domProps.role === "button" || domProps.role === "checkbox" || domProps.role === "radio") {
|
|
111
|
-
domProps.tabIndex = 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (disabled)
|
|
116
|
-
domProps["aria-disabled"] = true;
|
|
117
|
-
return createElement(tag, domProps, children);
|
|
118
|
-
};
|
|
119
|
-
/** Resolves React Native's BackHandler, or null off-device. */
|
|
120
|
-
const getBackHandler = () => rn?.BackHandler ?? null;
|
|
121
|
-
/**
|
|
122
|
-
* A Modal that only mounts its children while visible.
|
|
123
|
-
*
|
|
124
|
-
* The generic fallback would render the content regardless of `visible`,
|
|
125
|
-
* which would surface every closed dialog in the DOM preview.
|
|
126
|
-
*/
|
|
127
|
-
const modalFallback = (tag) => function Primitive(props) {
|
|
128
|
-
const { children, visible, onRequestClose, ...rest } = props ?? {};
|
|
129
|
-
if (!visible)
|
|
130
|
-
return null;
|
|
131
|
-
const { createElement } = require("react");
|
|
132
|
-
return createElement(tag, { style: toDomStyle(rest.style) }, children);
|
|
133
|
-
};
|
|
134
|
-
/** An image that reads its remote source in the DOM preview. */
|
|
135
|
-
function imageFallback(props) {
|
|
136
|
-
const { source, accessibilityLabel, style } = props ?? {};
|
|
137
|
-
const { createElement } = require("react");
|
|
138
|
-
return createElement("img", {
|
|
139
|
-
src: source?.uri,
|
|
140
|
-
alt: accessibilityLabel ?? "",
|
|
141
|
-
style: toDomStyle(style),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
const SvgComponent = svg?.default ?? fallback("svg");
|
|
145
|
-
const SvgText = svg?.Text ?? fallback("text");
|
|
146
|
-
return {
|
|
147
|
-
View: View ?? fallback("div"),
|
|
148
|
-
Text: Text ?? fallback("span"),
|
|
149
|
-
Pressable: Pressable ?? fallback("button"),
|
|
150
|
-
Svg: SvgComponent,
|
|
151
|
-
G: svg?.G ?? fallback("g"),
|
|
152
|
-
Line: svg?.Line ?? fallback("line"),
|
|
153
|
-
Path: svg?.Path ?? fallback("path"),
|
|
154
|
-
Circle: svg?.Circle ?? fallback("circle"),
|
|
155
|
-
Rect: svg?.Rect ?? fallback("rect"),
|
|
156
|
-
Polygon: svg?.Polygon ?? fallback("polygon"),
|
|
157
|
-
// TextInput is not an SVG primitive, but resolving it here keeps every
|
|
158
|
-
// component on one runtime-resolution path instead of two.
|
|
159
|
-
TextInput: rn?.TextInput ?? fallback("input"),
|
|
160
|
-
// Modal is resolved the same way so dialogs degrade to a plain overlay
|
|
161
|
-
// outside a native runtime instead of failing to mount.
|
|
162
|
-
Modal: rn?.Modal ?? modalFallback("div"),
|
|
163
|
-
Image: rn?.Image ?? imageFallback,
|
|
164
|
-
getScrollView: () => rn?.ScrollView ?? null,
|
|
165
|
-
getBackHandler,
|
|
166
|
-
SvgText,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
const LENGTH_PROPS = new Set([
|
|
170
|
-
"width",
|
|
171
|
-
"height",
|
|
172
|
-
"top",
|
|
173
|
-
"left",
|
|
174
|
-
"right",
|
|
175
|
-
"bottom",
|
|
176
|
-
"marginTop",
|
|
177
|
-
"marginBottom",
|
|
178
|
-
"marginLeft",
|
|
179
|
-
"marginRight",
|
|
180
|
-
"paddingTop",
|
|
181
|
-
"paddingBottom",
|
|
182
|
-
"paddingLeft",
|
|
183
|
-
"paddingRight",
|
|
184
|
-
"fontSize",
|
|
185
|
-
"borderRadius",
|
|
186
|
-
"gap",
|
|
187
|
-
]);
|
|
188
|
-
/** Converts an RN style object to DOM-compatible CSS. */
|
|
189
|
-
function toDomStyle(style) {
|
|
190
|
-
if (!style)
|
|
191
|
-
return style;
|
|
192
|
-
const list = Array.isArray(style) ? style : [style];
|
|
193
|
-
const merged = {};
|
|
194
|
-
for (const entry of list) {
|
|
195
|
-
if (!entry)
|
|
196
|
-
continue;
|
|
197
|
-
for (const [key, value] of Object.entries(entry)) {
|
|
198
|
-
if (value == null)
|
|
199
|
-
continue;
|
|
200
|
-
merged[key] =
|
|
201
|
-
typeof value === "number" && LENGTH_PROPS.has(key) ? `${value}px` : value;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return merged;
|
|
205
|
-
}
|
|
206
|
-
let cache = null;
|
|
207
|
-
/** The resolved primitives, computed once per process. */
|
|
208
|
-
function primitives() {
|
|
209
|
-
if (!cache)
|
|
210
|
-
cache = resolve();
|
|
211
|
-
return cache;
|
|
212
|
-
}
|