@rootnative/web 0.0.0-alpha.0 → 0.0.0-stage
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/README.md +2 -68
- package/package.json +3 -65
- package/CHANGELOG.md +0 -29
- package/LICENSE +0 -21
- package/dist/StyleRegistryContext-ButsUd8D.js +0 -129
- package/dist/StyleRegistryContext-ButsUd8D.js.map +0 -1
- package/dist/dom/index.d.ts +0 -22
- package/dist/dom/index.js +0 -53
- package/dist/dom/index.js.map +0 -1
- package/dist/index.d.ts +0 -875
- package/dist/index.js +0 -3374
- package/dist/index.js.map +0 -1
- package/dist/server/index.d.ts +0 -32
- package/dist/server/index.js +0 -25
- package/dist/server/index.js.map +0 -1
- package/dist/types-BxTWbdj9.d.ts +0 -5
- package/llms.txt +0 -328
package/dist/index.js
DELETED
|
@@ -1,3374 +0,0 @@
|
|
|
1
|
-
import { c as isProductionEnv, l as isTestEnv, n as useStyleRegistry, o as getStyleRegistry, s as hasDOM, u as matchesMedia } from "./StyleRegistryContext-ButsUd8D.js";
|
|
2
|
-
import normalizeColor from "@react-native/normalize-colors";
|
|
3
|
-
import { Children, Fragment, cloneElement, createContext, createElement, isValidElement, memo, useCallback, useContext, useEffect, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
// src/apis/AccessibilityInfo/index.ts
|
|
6
|
-
const mediaQueryOf = {
|
|
7
|
-
reduceMotionChanged: "(prefers-reduced-motion: reduce)",
|
|
8
|
-
reduceTransparencyChanged: "(prefers-reduced-transparency: reduce)",
|
|
9
|
-
invertColorsChanged: "(inverted-colors: inverted)",
|
|
10
|
-
darkerSystemColorsChanged: "(prefers-contrast: more)",
|
|
11
|
-
highTextContrastChanged: "(prefers-contrast: more)"
|
|
12
|
-
};
|
|
13
|
-
const resolve = (value) => Promise.resolve(value);
|
|
14
|
-
let liveRegion = null;
|
|
15
|
-
const getLiveRegion = () => {
|
|
16
|
-
if (!hasDOM()) return null;
|
|
17
|
-
if (liveRegion !== null && liveRegion.isConnected) return liveRegion;
|
|
18
|
-
const element = document.createElement("div");
|
|
19
|
-
element.setAttribute("aria-live", "polite");
|
|
20
|
-
element.setAttribute("aria-atomic", "true");
|
|
21
|
-
element.setAttribute("data-rn-announcer", "");
|
|
22
|
-
Object.assign(element.style, {
|
|
23
|
-
position: "absolute",
|
|
24
|
-
width: "1px",
|
|
25
|
-
height: "1px",
|
|
26
|
-
margin: "-1px",
|
|
27
|
-
padding: "0",
|
|
28
|
-
overflow: "hidden",
|
|
29
|
-
clip: "rect(0 0 0 0)",
|
|
30
|
-
whiteSpace: "nowrap",
|
|
31
|
-
border: "0"
|
|
32
|
-
});
|
|
33
|
-
document.body.appendChild(element);
|
|
34
|
-
liveRegion = element;
|
|
35
|
-
return element;
|
|
36
|
-
};
|
|
37
|
-
const announcementListeners = /* @__PURE__ */ new Set();
|
|
38
|
-
const announce = (announcement, queue) => {
|
|
39
|
-
const region = getLiveRegion();
|
|
40
|
-
if (region === null) return;
|
|
41
|
-
region.setAttribute("aria-live", queue ? "polite" : "assertive");
|
|
42
|
-
region.textContent = "";
|
|
43
|
-
requestAnimationFrame(() => {
|
|
44
|
-
region.textContent = announcement;
|
|
45
|
-
for (const listener of announcementListeners) listener({
|
|
46
|
-
announcement,
|
|
47
|
-
success: true
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const AccessibilityInfo = {
|
|
52
|
-
isScreenReaderEnabled: () => resolve(false),
|
|
53
|
-
isAccessibilityServiceEnabled: () => resolve(false),
|
|
54
|
-
isBoldTextEnabled: () => resolve(false),
|
|
55
|
-
isGrayscaleEnabled: () => resolve(false),
|
|
56
|
-
isInvertColorsEnabled: () => resolve(matchesMedia("(inverted-colors: inverted)")),
|
|
57
|
-
isReduceMotionEnabled: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
|
|
58
|
-
isReduceTransparencyEnabled: () => resolve(matchesMedia("(prefers-reduced-transparency: reduce)")),
|
|
59
|
-
isHighTextContrastEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
|
|
60
|
-
isDarkerSystemColorsEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
|
|
61
|
-
prefersCrossFadeTransitions: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
|
|
62
|
-
getRecommendedTimeoutMillis: (originalTimeout) => resolve(originalTimeout),
|
|
63
|
-
addEventListener: (eventName, handler) => {
|
|
64
|
-
if (eventName === "announcementFinished") {
|
|
65
|
-
const listener = handler;
|
|
66
|
-
announcementListeners.add(listener);
|
|
67
|
-
return { remove: () => announcementListeners.delete(listener) };
|
|
68
|
-
}
|
|
69
|
-
const query = mediaQueryOf[eventName];
|
|
70
|
-
if (query === void 0 || !hasDOM() || typeof window.matchMedia !== "function") return { remove: () => {} };
|
|
71
|
-
const list = window.matchMedia(query);
|
|
72
|
-
const listener = () => handler(list.matches);
|
|
73
|
-
list.addEventListener("change", listener);
|
|
74
|
-
return { remove: () => list.removeEventListener("change", listener) };
|
|
75
|
-
},
|
|
76
|
-
announceForAccessibility: (announcement) => announce(announcement, true),
|
|
77
|
-
announceForAccessibilityWithOptions: (announcement, options) => announce(announcement, options.queue !== false),
|
|
78
|
-
setAccessibilityFocus: (target) => {
|
|
79
|
-
if (target instanceof HTMLElement) target.focus();
|
|
80
|
-
},
|
|
81
|
-
sendAccessibilityEvent: (target, eventType) => {
|
|
82
|
-
if (eventType === "focus" && target instanceof HTMLElement) target.focus();
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
// src/apis/Appearance/index.ts
|
|
86
|
-
const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
87
|
-
let override = null;
|
|
88
|
-
let last = null;
|
|
89
|
-
let mediaList = null;
|
|
90
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
91
|
-
const system = () => matchesMedia(DARK_QUERY) ? "dark" : "light";
|
|
92
|
-
const current$2 = () => override ?? system();
|
|
93
|
-
const notify = () => {
|
|
94
|
-
const next = current$2();
|
|
95
|
-
if (next === last) return;
|
|
96
|
-
last = next;
|
|
97
|
-
for (const listener of listeners) listener({ colorScheme: next });
|
|
98
|
-
};
|
|
99
|
-
const listen$1 = () => {
|
|
100
|
-
if (mediaList !== null || !hasDOM() || typeof window.matchMedia !== "function") return;
|
|
101
|
-
mediaList = window.matchMedia(DARK_QUERY);
|
|
102
|
-
mediaList.addEventListener("change", notify);
|
|
103
|
-
};
|
|
104
|
-
const Appearance = {
|
|
105
|
-
getColorScheme() {
|
|
106
|
-
return current$2();
|
|
107
|
-
},
|
|
108
|
-
setColorScheme(scheme) {
|
|
109
|
-
override = scheme === "light" || scheme === "dark" ? scheme : null;
|
|
110
|
-
if (hasDOM()) document.documentElement.style.colorScheme = override ?? "";
|
|
111
|
-
notify();
|
|
112
|
-
},
|
|
113
|
-
addChangeListener(listener) {
|
|
114
|
-
if (listeners.size === 0) last = current$2();
|
|
115
|
-
listeners.add(listener);
|
|
116
|
-
listen$1();
|
|
117
|
-
return { remove: () => listeners.delete(listener) };
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
// src/apis/BackHandler/index.ts
|
|
121
|
-
const handlers$1 = /* @__PURE__ */ new Set();
|
|
122
|
-
const BackHandler = {
|
|
123
|
-
addEventListener: (eventName, handler) => {
|
|
124
|
-
if (eventName !== "hardwareBackPress") throw new Error(`BackHandler: unknown event "${String(eventName)}"`);
|
|
125
|
-
handlers$1.add(handler);
|
|
126
|
-
return { remove: () => handlers$1.delete(handler) };
|
|
127
|
-
},
|
|
128
|
-
removeEventListener: (_eventName, handler) => {
|
|
129
|
-
handlers$1.delete(handler);
|
|
130
|
-
},
|
|
131
|
-
exitApp: () => {}
|
|
132
|
-
};
|
|
133
|
-
// src/apis/Dimensions/index.ts
|
|
134
|
-
const serverSize = Object.freeze({
|
|
135
|
-
width: 0,
|
|
136
|
-
height: 0,
|
|
137
|
-
scale: 1,
|
|
138
|
-
fontScale: 1
|
|
139
|
-
});
|
|
140
|
-
const read = () => {
|
|
141
|
-
if (!hasDOM()) return {
|
|
142
|
-
window: serverSize,
|
|
143
|
-
screen: serverSize
|
|
144
|
-
};
|
|
145
|
-
const scale = window.devicePixelRatio || 1;
|
|
146
|
-
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
147
|
-
const fontScale = Number.isFinite(rootFontSize) && rootFontSize > 0 ? rootFontSize / 16 : 1;
|
|
148
|
-
return {
|
|
149
|
-
window: {
|
|
150
|
-
width: window.innerWidth,
|
|
151
|
-
height: window.innerHeight,
|
|
152
|
-
scale,
|
|
153
|
-
fontScale
|
|
154
|
-
},
|
|
155
|
-
screen: {
|
|
156
|
-
width: window.screen.width,
|
|
157
|
-
height: window.screen.height,
|
|
158
|
-
scale,
|
|
159
|
-
fontScale
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
const sameSize = (a, b) => a.width === b.width && a.height === b.height && a.scale === b.scale && a.fontScale === b.fontScale;
|
|
164
|
-
let current$1 = null;
|
|
165
|
-
const handlers = /* @__PURE__ */ new Set();
|
|
166
|
-
let listening = false;
|
|
167
|
-
const refresh = () => {
|
|
168
|
-
const next = read();
|
|
169
|
-
if (current$1 === null || !sameSize(current$1.window, next.window) || !sameSize(current$1.screen, next.screen)) current$1 = next;
|
|
170
|
-
return current$1;
|
|
171
|
-
};
|
|
172
|
-
const update = () => {
|
|
173
|
-
const previous = current$1;
|
|
174
|
-
const value = refresh();
|
|
175
|
-
if (value === previous) return;
|
|
176
|
-
for (const handler of handlers) handler(value);
|
|
177
|
-
};
|
|
178
|
-
const listen = () => {
|
|
179
|
-
if (listening || !hasDOM()) return;
|
|
180
|
-
listening = true;
|
|
181
|
-
window.addEventListener("resize", update);
|
|
182
|
-
};
|
|
183
|
-
const Dimensions = {
|
|
184
|
-
get(dimension) {
|
|
185
|
-
return (current$1 === null || !listening ? refresh() : current$1)[dimension];
|
|
186
|
-
},
|
|
187
|
-
addEventListener(type, handler) {
|
|
188
|
-
if (type !== "change") throw new Error(`Dimensions: unknown event "${String(type)}"`);
|
|
189
|
-
refresh();
|
|
190
|
-
handlers.add(handler);
|
|
191
|
-
listen();
|
|
192
|
-
return { remove: () => handlers.delete(handler) };
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
// src/apis/I18nManager/index.ts
|
|
196
|
-
let allowed = true;
|
|
197
|
-
let forced = false;
|
|
198
|
-
let swapLeftAndRight = true;
|
|
199
|
-
const documentIsRTL = () => hasDOM() && getComputedStyle(document.documentElement).direction === "rtl";
|
|
200
|
-
const isRTL = () => forced || allowed && documentIsRTL();
|
|
201
|
-
const I18nManager = {
|
|
202
|
-
get isRTL() {
|
|
203
|
-
return isRTL();
|
|
204
|
-
},
|
|
205
|
-
get doLeftAndRightSwapInRTL() {
|
|
206
|
-
return swapLeftAndRight;
|
|
207
|
-
},
|
|
208
|
-
getConstants: () => ({
|
|
209
|
-
isRTL: isRTL(),
|
|
210
|
-
doLeftAndRightSwapInRTL: swapLeftAndRight,
|
|
211
|
-
localeIdentifier: hasDOM() ? navigator.language : void 0
|
|
212
|
-
}),
|
|
213
|
-
allowRTL: (allow) => {
|
|
214
|
-
allowed = allow;
|
|
215
|
-
},
|
|
216
|
-
forceRTL: (force) => {
|
|
217
|
-
forced = force;
|
|
218
|
-
if (hasDOM()) document.documentElement.dir = force ? "rtl" : "";
|
|
219
|
-
},
|
|
220
|
-
swapLeftAndRightInRTL: (swap) => {
|
|
221
|
-
swapLeftAndRight = swap;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
// src/apis/PanResponder/index.ts
|
|
225
|
-
let current = null;
|
|
226
|
-
let grantEvent = null;
|
|
227
|
-
let nextStateID = 1;
|
|
228
|
-
const newGestureState = () => ({
|
|
229
|
-
stateID: nextStateID++,
|
|
230
|
-
moveX: 0,
|
|
231
|
-
moveY: 0,
|
|
232
|
-
x0: 0,
|
|
233
|
-
y0: 0,
|
|
234
|
-
dx: 0,
|
|
235
|
-
dy: 0,
|
|
236
|
-
vx: 0,
|
|
237
|
-
vy: 0,
|
|
238
|
-
numberActiveTouches: 0,
|
|
239
|
-
_accountsForMovesUpTo: 0
|
|
240
|
-
});
|
|
241
|
-
const centroid = (pointers) => {
|
|
242
|
-
let x = 0;
|
|
243
|
-
let y = 0;
|
|
244
|
-
for (const pointer of pointers.values()) {
|
|
245
|
-
x += pointer.clientX + window.scrollX;
|
|
246
|
-
y += pointer.clientY + window.scrollY;
|
|
247
|
-
}
|
|
248
|
-
const count = pointers.size || 1;
|
|
249
|
-
return {
|
|
250
|
-
x: x / count,
|
|
251
|
-
y: y / count
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
const define$1 = (target, fields) => {
|
|
255
|
-
for (const key in fields) Object.defineProperty(target, key, {
|
|
256
|
-
value: fields[key],
|
|
257
|
-
configurable: true,
|
|
258
|
-
writable: true
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
const touchOf = (pointer, rect, timestamp) => ({
|
|
262
|
-
changedTouches: [],
|
|
263
|
-
identifier: pointer.id,
|
|
264
|
-
locationX: pointer.clientX - rect.left,
|
|
265
|
-
locationY: pointer.clientY - rect.top,
|
|
266
|
-
pageX: pointer.clientX + window.scrollX,
|
|
267
|
-
pageY: pointer.clientY + window.scrollY,
|
|
268
|
-
target: pointer.target,
|
|
269
|
-
timestamp,
|
|
270
|
-
touches: []
|
|
271
|
-
});
|
|
272
|
-
const toResponderEvent = (event, responder, changed) => {
|
|
273
|
-
const rect = (responder.element ?? event.currentTarget).getBoundingClientRect();
|
|
274
|
-
const touches = [...responder.pointers.values()].map((p) => touchOf(p, rect, event.timeStamp));
|
|
275
|
-
const touch = touchOf(changed, rect, event.timeStamp);
|
|
276
|
-
define$1(event.nativeEvent, {
|
|
277
|
-
...touch,
|
|
278
|
-
force: event.pressure,
|
|
279
|
-
touches,
|
|
280
|
-
changedTouches: [touch]
|
|
281
|
-
});
|
|
282
|
-
return event;
|
|
283
|
-
};
|
|
284
|
-
const pointerOf = (event) => ({
|
|
285
|
-
id: event.pointerId,
|
|
286
|
-
clientX: event.clientX,
|
|
287
|
-
clientY: event.clientY,
|
|
288
|
-
target: event.target
|
|
289
|
-
});
|
|
290
|
-
const updateMove = (responder, time) => {
|
|
291
|
-
const state = responder.gestureState;
|
|
292
|
-
const next = centroid(responder.pointers);
|
|
293
|
-
const last = responder.last;
|
|
294
|
-
if (last !== null) {
|
|
295
|
-
const dt = time - last.time;
|
|
296
|
-
state.dx += next.x - last.x;
|
|
297
|
-
state.dy += next.y - last.y;
|
|
298
|
-
state.vx = dt > 0 ? (next.x - last.x) / dt : 0;
|
|
299
|
-
state.vy = dt > 0 ? (next.y - last.y) / dt : 0;
|
|
300
|
-
}
|
|
301
|
-
state.moveX = next.x;
|
|
302
|
-
state.moveY = next.y;
|
|
303
|
-
state._accountsForMovesUpTo = time;
|
|
304
|
-
responder.last = {
|
|
305
|
-
x: next.x,
|
|
306
|
-
y: next.y,
|
|
307
|
-
time
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
const rebase = (responder, time) => {
|
|
311
|
-
const next = centroid(responder.pointers);
|
|
312
|
-
responder.last = {
|
|
313
|
-
x: next.x,
|
|
314
|
-
y: next.y,
|
|
315
|
-
time
|
|
316
|
-
};
|
|
317
|
-
responder.gestureState.numberActiveTouches = responder.pointers.size;
|
|
318
|
-
};
|
|
319
|
-
const grant = (responder, event, responderEvent) => {
|
|
320
|
-
const state = responder.gestureState;
|
|
321
|
-
const point = centroid(responder.pointers);
|
|
322
|
-
state.x0 = point.x;
|
|
323
|
-
state.y0 = point.y;
|
|
324
|
-
state.dx = 0;
|
|
325
|
-
state.dy = 0;
|
|
326
|
-
state.vx = 0;
|
|
327
|
-
state.vy = 0;
|
|
328
|
-
responder.last = {
|
|
329
|
-
x: point.x,
|
|
330
|
-
y: point.y,
|
|
331
|
-
time: event.timeStamp
|
|
332
|
-
};
|
|
333
|
-
responder.element = event.currentTarget;
|
|
334
|
-
current = responder;
|
|
335
|
-
grantEvent = event.nativeEvent;
|
|
336
|
-
for (const pointer of responder.pointers.values()) try {
|
|
337
|
-
responder.element.setPointerCapture(pointer.id);
|
|
338
|
-
} catch {}
|
|
339
|
-
responder.config.onPanResponderGrant?.(responderEvent, state);
|
|
340
|
-
responder.config.onPanResponderStart?.(responderEvent, state);
|
|
341
|
-
};
|
|
342
|
-
const releaseCapture = (responder) => {
|
|
343
|
-
const element = responder.element;
|
|
344
|
-
if (element === null) return;
|
|
345
|
-
for (const pointer of responder.pointers.values()) try {
|
|
346
|
-
if (element.hasPointerCapture(pointer.id)) element.releasePointerCapture(pointer.id);
|
|
347
|
-
} catch {}
|
|
348
|
-
};
|
|
349
|
-
const finish = (responder) => {
|
|
350
|
-
releaseCapture(responder);
|
|
351
|
-
if (current === responder) current = null;
|
|
352
|
-
responder.element = null;
|
|
353
|
-
responder.last = null;
|
|
354
|
-
};
|
|
355
|
-
const negotiate = (responder, event, responderEvent, predicate) => {
|
|
356
|
-
if (current === responder) return;
|
|
357
|
-
if (current !== null && grantEvent === event.nativeEvent) return;
|
|
358
|
-
if (predicate === void 0 || !predicate(responderEvent, responder.gestureState)) return;
|
|
359
|
-
if (current !== null) {
|
|
360
|
-
const holder = current;
|
|
361
|
-
if (holder.config.onPanResponderTerminationRequest?.(responderEvent, holder.gestureState) === false) {
|
|
362
|
-
responder.config.onPanResponderReject?.(responderEvent, responder.gestureState);
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
holder.config.onPanResponderTerminate?.(responderEvent, holder.gestureState);
|
|
366
|
-
finish(holder);
|
|
367
|
-
}
|
|
368
|
-
grant(responder, event, responderEvent);
|
|
369
|
-
};
|
|
370
|
-
const createHandlers = (responder) => {
|
|
371
|
-
const down = (event, capture) => {
|
|
372
|
-
const pointer = pointerOf(event);
|
|
373
|
-
const first = responder.pointers.size === 0;
|
|
374
|
-
if (capture) {
|
|
375
|
-
if (first) responder.gestureState = newGestureState();
|
|
376
|
-
responder.pointers.set(pointer.id, pointer);
|
|
377
|
-
rebase(responder, event.timeStamp);
|
|
378
|
-
}
|
|
379
|
-
const responderEvent = toResponderEvent(event, responder, pointer);
|
|
380
|
-
const { config } = responder;
|
|
381
|
-
if (current === responder) {
|
|
382
|
-
if (capture) config.onPanResponderStart?.(responderEvent, responder.gestureState);
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
negotiate(responder, event, responderEvent, capture ? config.onStartShouldSetPanResponderCapture : config.onStartShouldSetPanResponder);
|
|
386
|
-
};
|
|
387
|
-
const move = (event, capture) => {
|
|
388
|
-
const pointer = responder.pointers.get(event.pointerId);
|
|
389
|
-
if (pointer === void 0) return;
|
|
390
|
-
if (capture) {
|
|
391
|
-
pointer.clientX = event.clientX;
|
|
392
|
-
pointer.clientY = event.clientY;
|
|
393
|
-
updateMove(responder, event.timeStamp);
|
|
394
|
-
}
|
|
395
|
-
const responderEvent = toResponderEvent(event, responder, pointer);
|
|
396
|
-
const { config } = responder;
|
|
397
|
-
if (current === responder) {
|
|
398
|
-
if (capture) config.onPanResponderMove?.(responderEvent, responder.gestureState);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
negotiate(responder, event, responderEvent, capture ? config.onMoveShouldSetPanResponderCapture : config.onMoveShouldSetPanResponder);
|
|
402
|
-
};
|
|
403
|
-
const end = (event, cancel) => {
|
|
404
|
-
const pointer = responder.pointers.get(event.pointerId);
|
|
405
|
-
if (pointer === void 0) return;
|
|
406
|
-
const responderEvent = toResponderEvent(event, responder, pointer);
|
|
407
|
-
responder.pointers.delete(event.pointerId);
|
|
408
|
-
const { config, gestureState } = responder;
|
|
409
|
-
const responding = current === responder;
|
|
410
|
-
if (responding && cancel) {
|
|
411
|
-
config.onPanResponderTerminate?.(responderEvent, gestureState);
|
|
412
|
-
responder.pointers.clear();
|
|
413
|
-
finish(responder);
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
if (responding) config.onPanResponderEnd?.(responderEvent, gestureState);
|
|
417
|
-
if (responder.pointers.size === 0) {
|
|
418
|
-
if (responding) config.onPanResponderRelease?.(responderEvent, gestureState);
|
|
419
|
-
finish(responder);
|
|
420
|
-
} else rebase(responder, event.timeStamp);
|
|
421
|
-
};
|
|
422
|
-
return {
|
|
423
|
-
onPointerDownCapture: (event) => down(event, true),
|
|
424
|
-
onPointerDown: (event) => down(event, false),
|
|
425
|
-
onPointerMoveCapture: (event) => move(event, true),
|
|
426
|
-
onPointerMove: (event) => move(event, false),
|
|
427
|
-
onPointerUp: (event) => end(event, false),
|
|
428
|
-
onPointerCancel: (event) => end(event, true)
|
|
429
|
-
};
|
|
430
|
-
};
|
|
431
|
-
const PanResponder = { create(config) {
|
|
432
|
-
const responder = {
|
|
433
|
-
config,
|
|
434
|
-
gestureState: newGestureState(),
|
|
435
|
-
pointers: /* @__PURE__ */ new Map(),
|
|
436
|
-
element: null,
|
|
437
|
-
last: null
|
|
438
|
-
};
|
|
439
|
-
return {
|
|
440
|
-
panHandlers: createHandlers(responder),
|
|
441
|
-
getInteractionHandle: () => null
|
|
442
|
-
};
|
|
443
|
-
} };
|
|
444
|
-
// src/apis/PixelRatio/index.ts
|
|
445
|
-
const PixelRatio = {
|
|
446
|
-
get: () => Dimensions.get("window").scale,
|
|
447
|
-
getFontScale: () => Dimensions.get("window").fontScale,
|
|
448
|
-
getPixelSizeForLayoutSize: (layoutSize) => Math.round(layoutSize * PixelRatio.get()),
|
|
449
|
-
roundToNearestPixel: (layoutSize) => {
|
|
450
|
-
const ratio = PixelRatio.get();
|
|
451
|
-
return Math.round(layoutSize * ratio) / ratio;
|
|
452
|
-
},
|
|
453
|
-
startDetecting: () => {}
|
|
454
|
-
};
|
|
455
|
-
// src/reactNativeVersion.ts
|
|
456
|
-
const reactNativeVersion = {
|
|
457
|
-
major: 0,
|
|
458
|
-
minor: 88,
|
|
459
|
-
patch: 1,
|
|
460
|
-
prerelease: void 0
|
|
461
|
-
};
|
|
462
|
-
// src/apis/Platform/index.ts
|
|
463
|
-
const Platform = {
|
|
464
|
-
OS: "web",
|
|
465
|
-
get Version() {
|
|
466
|
-
return hasDOM() ? navigator.userAgent : "";
|
|
467
|
-
},
|
|
468
|
-
get constants() {
|
|
469
|
-
return { reactNativeVersion };
|
|
470
|
-
},
|
|
471
|
-
get isTV() {
|
|
472
|
-
return false;
|
|
473
|
-
},
|
|
474
|
-
get isTesting() {
|
|
475
|
-
return isTestEnv();
|
|
476
|
-
},
|
|
477
|
-
get isDisableAnimations() {
|
|
478
|
-
return matchesMedia("(prefers-reduced-motion: reduce)");
|
|
479
|
-
},
|
|
480
|
-
select(spec) {
|
|
481
|
-
if ("web" in spec) return spec.web;
|
|
482
|
-
if ("default" in spec) return spec.default;
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
// src/apis/processColor/index.ts
|
|
486
|
-
const processColor = (color) => {
|
|
487
|
-
if (color === void 0 || color === null) return color;
|
|
488
|
-
if (typeof color !== "string" && typeof color !== "number") return null;
|
|
489
|
-
const rgba = normalizeColor(color);
|
|
490
|
-
if (rgba === null || rgba === void 0) return null;
|
|
491
|
-
return (rgba << 24 | rgba >>> 8) >>> 0;
|
|
492
|
-
};
|
|
493
|
-
// src/style/color.ts
|
|
494
|
-
const toCSSColor = (value) => {
|
|
495
|
-
if (typeof value !== "string" && typeof value !== "number") return void 0;
|
|
496
|
-
const packed = normalizeColor(value);
|
|
497
|
-
if (packed === null || packed === void 0) return void 0;
|
|
498
|
-
const r = packed >>> 24 & 255;
|
|
499
|
-
const g = packed >>> 16 & 255;
|
|
500
|
-
const b = packed >>> 8 & 255;
|
|
501
|
-
const a = (packed & 255) / 255;
|
|
502
|
-
return a === 1 ? `rgb(${r},${g},${b})` : `rgba(${r},${g},${b},${round(a)})`;
|
|
503
|
-
};
|
|
504
|
-
const round = (n) => Math.round(n * 1e3) / 1e3;
|
|
505
|
-
// src/style/units.ts
|
|
506
|
-
const toUnit = (value, unit) => {
|
|
507
|
-
if (typeof value === "number") return value === 0 ? "0" : `${value}${unit}`;
|
|
508
|
-
return String(value);
|
|
509
|
-
};
|
|
510
|
-
const unitlessProperties = /* @__PURE__ */ new Set([
|
|
511
|
-
"aspectRatio",
|
|
512
|
-
"flex",
|
|
513
|
-
"flexGrow",
|
|
514
|
-
"flexShrink",
|
|
515
|
-
"fontWeight",
|
|
516
|
-
"lineClamp",
|
|
517
|
-
"WebkitLineClamp",
|
|
518
|
-
"opacity",
|
|
519
|
-
"zIndex",
|
|
520
|
-
"scale",
|
|
521
|
-
"shadowOpacity"
|
|
522
|
-
]);
|
|
523
|
-
// src/style/shadow.ts
|
|
524
|
-
const offsetOf = (value) => {
|
|
525
|
-
const o = value ?? {};
|
|
526
|
-
return {
|
|
527
|
-
x: typeof o.width === "number" ? o.width : 0,
|
|
528
|
-
y: typeof o.height === "number" ? o.height : 0
|
|
529
|
-
};
|
|
530
|
-
};
|
|
531
|
-
const legacyBoxShadow = (style) => {
|
|
532
|
-
const { x, y } = offsetOf(style["shadowOffset"]);
|
|
533
|
-
const radius = typeof style["shadowRadius"] === "number" ? style["shadowRadius"] : 0;
|
|
534
|
-
const opacity = typeof style["shadowOpacity"] === "number" ? style["shadowOpacity"] : 1;
|
|
535
|
-
const color = toCSSColor(style["shadowColor"] ?? "black");
|
|
536
|
-
if (color === void 0) return void 0;
|
|
537
|
-
return `${x}px ${y}px ${radius}px ${withOpacity(color, opacity)}`;
|
|
538
|
-
};
|
|
539
|
-
const toCSSTextShadow = (style) => {
|
|
540
|
-
const { x, y } = offsetOf(style["textShadowOffset"]);
|
|
541
|
-
const radius = typeof style["textShadowRadius"] === "number" ? style["textShadowRadius"] : 0;
|
|
542
|
-
const color = toCSSColor(style["textShadowColor"] ?? "black");
|
|
543
|
-
if (color === void 0) return void 0;
|
|
544
|
-
return `${x}px ${y}px ${radius}px ${color}`;
|
|
545
|
-
};
|
|
546
|
-
const toCSSBoxShadow = (value) => {
|
|
547
|
-
if (typeof value === "string") return value;
|
|
548
|
-
if (!Array.isArray(value)) return void 0;
|
|
549
|
-
const shadows = value.map((s) => {
|
|
550
|
-
const parts = [
|
|
551
|
-
toUnit(s.offsetX, "px"),
|
|
552
|
-
toUnit(s.offsetY, "px"),
|
|
553
|
-
toUnit(s.blurRadius ?? 0, "px"),
|
|
554
|
-
toUnit(s.spreadDistance ?? 0, "px"),
|
|
555
|
-
toCSSColor(s.color ?? "black") ?? "black"
|
|
556
|
-
];
|
|
557
|
-
if (s.inset === true) parts.push("inset");
|
|
558
|
-
return parts.join(" ");
|
|
559
|
-
});
|
|
560
|
-
return shadows.length === 0 ? "none" : shadows.join(", ");
|
|
561
|
-
};
|
|
562
|
-
const lengthFilters = /* @__PURE__ */ new Set(["blur"]);
|
|
563
|
-
const angleFilters = /* @__PURE__ */ new Set(["hueRotate"]);
|
|
564
|
-
const toCSSFilter = (value) => {
|
|
565
|
-
if (typeof value === "string") return value;
|
|
566
|
-
if (!Array.isArray(value)) return void 0;
|
|
567
|
-
const parts = [];
|
|
568
|
-
for (const entry of value) for (const [name, raw] of Object.entries(entry)) {
|
|
569
|
-
const css = toFilterFunction(name, raw);
|
|
570
|
-
if (css !== void 0) parts.push(css);
|
|
571
|
-
}
|
|
572
|
-
return parts.length === 0 ? "none" : parts.join(" ");
|
|
573
|
-
};
|
|
574
|
-
const toFilterFunction = (name, raw) => {
|
|
575
|
-
if (name === "dropShadow") {
|
|
576
|
-
const shadow = typeof raw === "string" ? raw : dropShadow(raw);
|
|
577
|
-
return shadow === void 0 ? void 0 : `drop-shadow(${shadow})`;
|
|
578
|
-
}
|
|
579
|
-
const cssName = name === "hueRotate" ? "hue-rotate" : name;
|
|
580
|
-
if (typeof raw === "number") {
|
|
581
|
-
if (lengthFilters.has(name)) return `${cssName}(${raw}px)`;
|
|
582
|
-
if (angleFilters.has(name)) return `${cssName}(${raw}deg)`;
|
|
583
|
-
return `${cssName}(${raw})`;
|
|
584
|
-
}
|
|
585
|
-
if (typeof raw === "string") return `${cssName}(${raw})`;
|
|
586
|
-
};
|
|
587
|
-
const dropShadow = (v) => {
|
|
588
|
-
const color = toCSSColor(v["color"] ?? "black");
|
|
589
|
-
if (color === void 0) return void 0;
|
|
590
|
-
return [
|
|
591
|
-
toUnit(v["offsetX"] ?? 0, "px"),
|
|
592
|
-
toUnit(v["offsetY"] ?? 0, "px"),
|
|
593
|
-
toUnit(v["standardDeviation"] ?? 0, "px"),
|
|
594
|
-
color
|
|
595
|
-
].join(" ");
|
|
596
|
-
};
|
|
597
|
-
const withOpacity = (color, opacity) => {
|
|
598
|
-
if (opacity >= 1) return color;
|
|
599
|
-
const match = /^rgba?\((\d+),(\d+),(\d+)(?:,([\d.]+))?\)$/.exec(color);
|
|
600
|
-
if (match === null) return color;
|
|
601
|
-
const alpha = match[4] === void 0 ? 1 : Number(match[4]);
|
|
602
|
-
const a = Math.round(alpha * opacity * 1e3) / 1e3;
|
|
603
|
-
return `rgba(${match[1]},${match[2]},${match[3]},${a})`;
|
|
604
|
-
};
|
|
605
|
-
// src/style/transform.ts
|
|
606
|
-
const lengthFunctions = /* @__PURE__ */ new Set([
|
|
607
|
-
"translateX",
|
|
608
|
-
"translateY",
|
|
609
|
-
"translateZ",
|
|
610
|
-
"perspective"
|
|
611
|
-
]);
|
|
612
|
-
const toCSSTransform = (value) => {
|
|
613
|
-
if (typeof value === "string") return value;
|
|
614
|
-
if (!Array.isArray(value)) return void 0;
|
|
615
|
-
const parts = [];
|
|
616
|
-
for (const entry of value) {
|
|
617
|
-
if (entry === null || typeof entry !== "object") continue;
|
|
618
|
-
for (const [name, raw] of Object.entries(entry)) {
|
|
619
|
-
const css = toTransformFunction(name, raw);
|
|
620
|
-
if (css !== void 0) parts.push(css);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
return parts.length === 0 ? "none" : parts.join(" ");
|
|
624
|
-
};
|
|
625
|
-
const toTransformFunction = (name, raw) => {
|
|
626
|
-
if (name === "matrix" && Array.isArray(raw)) return `${raw.length === 16 ? "matrix3d" : "matrix"}(${raw.join(",")})`;
|
|
627
|
-
if (name === "translate" && Array.isArray(raw)) return `translate(${raw.map((v) => toUnit(v, "px")).join(",")})`;
|
|
628
|
-
if (typeof raw === "number") return lengthFunctions.has(name) ? `${name}(${raw}px)` : `${name}(${raw})`;
|
|
629
|
-
if (typeof raw === "string") return `${name}(${raw})`;
|
|
630
|
-
};
|
|
631
|
-
const toCSSTransformOrigin = (value) => {
|
|
632
|
-
if (typeof value === "string") return value;
|
|
633
|
-
if (!Array.isArray(value)) return void 0;
|
|
634
|
-
return value.map((v) => toUnit(v, "px")).join(" ");
|
|
635
|
-
};
|
|
636
|
-
// src/style/resolveStyle.ts
|
|
637
|
-
const colorProperties = /* @__PURE__ */ new Set([
|
|
638
|
-
"backgroundColor",
|
|
639
|
-
"borderBlockColor",
|
|
640
|
-
"borderBlockEndColor",
|
|
641
|
-
"borderBlockStartColor",
|
|
642
|
-
"borderBottomColor",
|
|
643
|
-
"borderColor",
|
|
644
|
-
"borderEndColor",
|
|
645
|
-
"borderLeftColor",
|
|
646
|
-
"borderRightColor",
|
|
647
|
-
"borderStartColor",
|
|
648
|
-
"borderTopColor",
|
|
649
|
-
"color",
|
|
650
|
-
"outlineColor",
|
|
651
|
-
"textDecorationColor"
|
|
652
|
-
]);
|
|
653
|
-
const renamedProperties = {
|
|
654
|
-
borderEndColor: "borderInlineEndColor",
|
|
655
|
-
borderEndWidth: "borderInlineEndWidth",
|
|
656
|
-
borderStartColor: "borderInlineStartColor",
|
|
657
|
-
borderStartWidth: "borderInlineStartWidth",
|
|
658
|
-
borderTopStartRadius: "borderStartStartRadius",
|
|
659
|
-
borderTopEndRadius: "borderStartEndRadius",
|
|
660
|
-
borderBottomStartRadius: "borderEndStartRadius",
|
|
661
|
-
borderBottomEndRadius: "borderEndEndRadius",
|
|
662
|
-
end: "insetInlineEnd",
|
|
663
|
-
marginEnd: "marginInlineEnd",
|
|
664
|
-
marginStart: "marginInlineStart",
|
|
665
|
-
paddingEnd: "paddingInlineEnd",
|
|
666
|
-
paddingStart: "paddingInlineStart",
|
|
667
|
-
start: "insetInlineStart",
|
|
668
|
-
writingDirection: "direction"
|
|
669
|
-
};
|
|
670
|
-
const expandedProperties = {
|
|
671
|
-
marginHorizontal: ["marginLeft", "marginRight"],
|
|
672
|
-
marginVertical: ["marginTop", "marginBottom"],
|
|
673
|
-
paddingHorizontal: ["paddingLeft", "paddingRight"],
|
|
674
|
-
paddingVertical: ["paddingTop", "paddingBottom"]
|
|
675
|
-
};
|
|
676
|
-
const ignoredProperties = /* @__PURE__ */ new Set([
|
|
677
|
-
"borderCurve",
|
|
678
|
-
"elevation",
|
|
679
|
-
"includeFontPadding",
|
|
680
|
-
"overlayColor",
|
|
681
|
-
"shadowColor",
|
|
682
|
-
"shadowOffset",
|
|
683
|
-
"shadowOpacity",
|
|
684
|
-
"shadowRadius",
|
|
685
|
-
"textShadowColor",
|
|
686
|
-
"textShadowOffset",
|
|
687
|
-
"textShadowRadius",
|
|
688
|
-
"tintColor"
|
|
689
|
-
]);
|
|
690
|
-
const fontWeightNames = {
|
|
691
|
-
ultralight: "200",
|
|
692
|
-
thin: "100",
|
|
693
|
-
light: "300",
|
|
694
|
-
regular: "400",
|
|
695
|
-
medium: "500",
|
|
696
|
-
semibold: "600",
|
|
697
|
-
condensedBold: "700",
|
|
698
|
-
condensed: "400",
|
|
699
|
-
heavy: "800",
|
|
700
|
-
black: "900"
|
|
701
|
-
};
|
|
702
|
-
const resizeModeToObjectFit = {
|
|
703
|
-
contain: "contain",
|
|
704
|
-
cover: "cover",
|
|
705
|
-
stretch: "fill",
|
|
706
|
-
center: "none",
|
|
707
|
-
repeat: "none"
|
|
708
|
-
};
|
|
709
|
-
const systemFontStack = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
|
|
710
|
-
const textAlignVerticalToVerticalAlign = {
|
|
711
|
-
top: "top",
|
|
712
|
-
center: "middle",
|
|
713
|
-
bottom: "bottom"
|
|
714
|
-
};
|
|
715
|
-
const resolveStyle = (style) => {
|
|
716
|
-
const out = {};
|
|
717
|
-
for (const [name, value] of Object.entries(style)) {
|
|
718
|
-
if (value === void 0 || value === null || ignoredProperties.has(name)) continue;
|
|
719
|
-
resolveProperty(name, value, out);
|
|
720
|
-
}
|
|
721
|
-
if (out["boxShadow"] === void 0 && hasLegacyShadow(style)) {
|
|
722
|
-
const shadow = legacyBoxShadow(style);
|
|
723
|
-
if (shadow !== void 0) out["boxShadow"] = shadow;
|
|
724
|
-
}
|
|
725
|
-
if (style["textShadowColor"] !== void 0 || style["textShadowOffset"] !== void 0) {
|
|
726
|
-
const shadow = toCSSTextShadow(style);
|
|
727
|
-
if (shadow !== void 0) out["textShadow"] = shadow;
|
|
728
|
-
}
|
|
729
|
-
return out;
|
|
730
|
-
};
|
|
731
|
-
const resolveProperty = (name, value, out) => {
|
|
732
|
-
switch (name) {
|
|
733
|
-
case "flex":
|
|
734
|
-
if (typeof value === "number") out["flex"] = value > 0 ? `${value} 1 0%` : value === 0 ? "0 0 auto" : "0 1 auto";
|
|
735
|
-
else out["flex"] = String(value);
|
|
736
|
-
return;
|
|
737
|
-
case "transform": {
|
|
738
|
-
const transform = toCSSTransform(value);
|
|
739
|
-
if (transform !== void 0) out["transform"] = transform;
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
case "transformOrigin": {
|
|
743
|
-
const origin = toCSSTransformOrigin(value);
|
|
744
|
-
if (origin !== void 0) out["transformOrigin"] = origin;
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
case "boxShadow": {
|
|
748
|
-
const shadow = toCSSBoxShadow(value);
|
|
749
|
-
if (shadow !== void 0) out["boxShadow"] = shadow;
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
case "filter": {
|
|
753
|
-
const filter = toCSSFilter(value);
|
|
754
|
-
if (filter !== void 0) out["filter"] = filter;
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
case "fontWeight":
|
|
758
|
-
out["fontWeight"] = fontWeightNames[String(value)] ?? String(value);
|
|
759
|
-
return;
|
|
760
|
-
case "fontFamily":
|
|
761
|
-
out["fontFamily"] = value === "System" ? systemFontStack : String(value);
|
|
762
|
-
return;
|
|
763
|
-
case "fontVariant":
|
|
764
|
-
out["fontVariant"] = Array.isArray(value) ? value.join(" ") : String(value);
|
|
765
|
-
return;
|
|
766
|
-
case "fontVariationSettings":
|
|
767
|
-
out["fontVariationSettings"] = Array.isArray(value) ? value.map((v) => `'${v.axis}' ${v.value}`).join(", ") : String(value);
|
|
768
|
-
return;
|
|
769
|
-
case "resizeMode": {
|
|
770
|
-
const fit = resizeModeToObjectFit[String(value)];
|
|
771
|
-
if (fit !== void 0 && out["objectFit"] === void 0) out["objectFit"] = fit;
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
case "objectFit":
|
|
775
|
-
out["objectFit"] = String(value);
|
|
776
|
-
return;
|
|
777
|
-
case "textAlignVertical": {
|
|
778
|
-
const align = textAlignVerticalToVerticalAlign[String(value)];
|
|
779
|
-
if (align !== void 0 && out["verticalAlign"] === void 0) out["verticalAlign"] = align;
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
case "backgroundImage":
|
|
783
|
-
if (typeof value === "string") out["backgroundImage"] = value;
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
if (colorProperties.has(name)) {
|
|
787
|
-
const color = toCSSColor(value);
|
|
788
|
-
if (color !== void 0) out[renamedProperties[name] ?? name] = color;
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
const targets = expandedProperties[name] ?? [renamedProperties[name] ?? name];
|
|
792
|
-
const css = unitlessProperties.has(name) ? String(value) : toUnit(value, "px");
|
|
793
|
-
for (const target of targets) out[target] = css;
|
|
794
|
-
};
|
|
795
|
-
const hasLegacyShadow = (style) => style["shadowColor"] !== void 0 || style["shadowOffset"] !== void 0 || style["shadowOpacity"] !== void 0 || style["shadowRadius"] !== void 0;
|
|
796
|
-
// src/style/compile.ts
|
|
797
|
-
const flattenStyle = (style) => {
|
|
798
|
-
if (style === null || style === void 0 || style === false || style === "") return void 0;
|
|
799
|
-
if (!Array.isArray(style)) return style;
|
|
800
|
-
let result;
|
|
801
|
-
for (const entry of style) {
|
|
802
|
-
const flat = flattenStyle(entry);
|
|
803
|
-
if (flat === void 0) continue;
|
|
804
|
-
result = result === void 0 ? { ...flat } : Object.assign(result, flat);
|
|
805
|
-
}
|
|
806
|
-
return result;
|
|
807
|
-
};
|
|
808
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
809
|
-
const compileStyle = (style, registry = getStyleRegistry()) => {
|
|
810
|
-
const flat = flattenStyle(style);
|
|
811
|
-
if (flat === void 0) return "";
|
|
812
|
-
const cacheable = Object.isFrozen(flat);
|
|
813
|
-
let perRegistry = cache.get(registry);
|
|
814
|
-
if (cacheable) {
|
|
815
|
-
const cached = perRegistry?.get(flat);
|
|
816
|
-
if (cached !== void 0) return cached;
|
|
817
|
-
}
|
|
818
|
-
const classes = registry.classesFor(resolveStyle(flat));
|
|
819
|
-
if (cacheable) {
|
|
820
|
-
if (perRegistry === void 0) {
|
|
821
|
-
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
822
|
-
cache.set(registry, perRegistry);
|
|
823
|
-
}
|
|
824
|
-
perRegistry.set(flat, classes);
|
|
825
|
-
}
|
|
826
|
-
return classes;
|
|
827
|
-
};
|
|
828
|
-
// src/apis/StyleSheet/index.ts
|
|
829
|
-
const absoluteFillObject = {
|
|
830
|
-
position: "absolute",
|
|
831
|
-
left: 0,
|
|
832
|
-
right: 0,
|
|
833
|
-
top: 0,
|
|
834
|
-
bottom: 0
|
|
835
|
-
};
|
|
836
|
-
const create = (styles) => {
|
|
837
|
-
for (const key in styles) Object.freeze(styles[key]);
|
|
838
|
-
return Object.freeze(styles);
|
|
839
|
-
};
|
|
840
|
-
const flatten = (style) => flattenStyle(style);
|
|
841
|
-
const compose = (style1, style2) => {
|
|
842
|
-
if (style1 && style2) return [style1, style2];
|
|
843
|
-
return style1 || style2;
|
|
844
|
-
};
|
|
845
|
-
const StyleSheet = Object.freeze({
|
|
846
|
-
absoluteFill: Object.freeze(absoluteFillObject),
|
|
847
|
-
absoluteFillObject,
|
|
848
|
-
hairlineWidth: 1,
|
|
849
|
-
create,
|
|
850
|
-
flatten,
|
|
851
|
-
compose
|
|
852
|
-
});
|
|
853
|
-
// src/apis/useColorScheme/index.ts
|
|
854
|
-
const subscribe$1 = (onChange) => {
|
|
855
|
-
const subscription = Appearance.addChangeListener(onChange);
|
|
856
|
-
return () => subscription.remove();
|
|
857
|
-
};
|
|
858
|
-
const getSnapshot$1 = () => Appearance.getColorScheme();
|
|
859
|
-
const getServerSnapshot$1 = () => "light";
|
|
860
|
-
const useColorScheme = () => useSyncExternalStore(subscribe$1, getSnapshot$1, getServerSnapshot$1);
|
|
861
|
-
// src/apis/useWindowDimensions/index.ts
|
|
862
|
-
const serverSnapshot = Object.freeze({
|
|
863
|
-
width: 0,
|
|
864
|
-
height: 0,
|
|
865
|
-
scale: 1,
|
|
866
|
-
fontScale: 1
|
|
867
|
-
});
|
|
868
|
-
const subscribe = (onChange) => {
|
|
869
|
-
const subscription = Dimensions.addEventListener("change", onChange);
|
|
870
|
-
return () => subscription.remove();
|
|
871
|
-
};
|
|
872
|
-
const getSnapshot = () => Dimensions.get("window");
|
|
873
|
-
const getServerSnapshot = () => serverSnapshot;
|
|
874
|
-
const useWindowDimensions = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
875
|
-
// src/render/domProps.ts
|
|
876
|
-
const liveRegionToAriaLive = {
|
|
877
|
-
none: "off",
|
|
878
|
-
polite: "polite",
|
|
879
|
-
assertive: "assertive"
|
|
880
|
-
};
|
|
881
|
-
const nativeHandler = /^on(Press|Layout|TextLayout|Accessibility|Magic|Responder|.*ShouldSet)/;
|
|
882
|
-
const passThrough = /* @__PURE__ */ new Set([
|
|
883
|
-
"lang",
|
|
884
|
-
"dir",
|
|
885
|
-
"target",
|
|
886
|
-
"rel",
|
|
887
|
-
"download"
|
|
888
|
-
]);
|
|
889
|
-
const toDOMProps = (props) => {
|
|
890
|
-
const out = {};
|
|
891
|
-
for (const name in props) {
|
|
892
|
-
const value = props[name];
|
|
893
|
-
if (value === void 0) continue;
|
|
894
|
-
if (name.startsWith("aria-") || name.startsWith("data-") || passThrough.has(name)) out[name] = value;
|
|
895
|
-
else if (name.startsWith("on") && name.length > 2 && !nativeHandler.test(name)) out[name] = value;
|
|
896
|
-
}
|
|
897
|
-
const { accessibilityLabel, accessibilityLabelledBy, accessibilityHint, accessibilityState, accessibilityValue, accessibilityLiveRegion, accessibilityElementsHidden, accessibilityViewIsModal, importantForAccessibility, id, nativeID, testID, tabIndex, focusable, href } = props;
|
|
898
|
-
if (accessibilityLabel !== void 0) out["aria-label"] ??= accessibilityLabel;
|
|
899
|
-
if (accessibilityLabelledBy !== void 0) out["aria-labelledby"] ??= Array.isArray(accessibilityLabelledBy) ? accessibilityLabelledBy.join(" ") : accessibilityLabelledBy;
|
|
900
|
-
if (accessibilityHint !== void 0) out["aria-description"] ??= accessibilityHint;
|
|
901
|
-
if (accessibilityLiveRegion !== void 0) out["aria-live"] ??= liveRegionToAriaLive[accessibilityLiveRegion];
|
|
902
|
-
if (accessibilityViewIsModal !== void 0) out["aria-modal"] ??= accessibilityViewIsModal;
|
|
903
|
-
if (accessibilityElementsHidden === true || importantForAccessibility === "no-hide-descendants") out["aria-hidden"] ??= true;
|
|
904
|
-
if (accessibilityState !== void 0) {
|
|
905
|
-
const { busy, checked, disabled, expanded, selected } = accessibilityState;
|
|
906
|
-
if (busy !== void 0) out["aria-busy"] ??= busy;
|
|
907
|
-
if (checked !== void 0) out["aria-checked"] ??= checked;
|
|
908
|
-
if (disabled !== void 0) out["aria-disabled"] ??= disabled;
|
|
909
|
-
if (expanded !== void 0) out["aria-expanded"] ??= expanded;
|
|
910
|
-
if (selected !== void 0) out["aria-selected"] ??= selected;
|
|
911
|
-
}
|
|
912
|
-
if (accessibilityValue !== void 0) {
|
|
913
|
-
const { max, min, now, text } = accessibilityValue;
|
|
914
|
-
if (max !== void 0) out["aria-valuemax"] ??= max;
|
|
915
|
-
if (min !== void 0) out["aria-valuemin"] ??= min;
|
|
916
|
-
if (now !== void 0) out["aria-valuenow"] ??= now;
|
|
917
|
-
if (text !== void 0) out["aria-valuetext"] ??= text;
|
|
918
|
-
}
|
|
919
|
-
const domId = id ?? nativeID;
|
|
920
|
-
if (domId !== void 0) out["id"] = domId;
|
|
921
|
-
if (testID !== void 0) out["data-testid"] = testID;
|
|
922
|
-
if (href !== void 0) out["href"] = href;
|
|
923
|
-
if (tabIndex !== void 0) out["tabIndex"] = tabIndex;
|
|
924
|
-
else if (focusable === true) out["tabIndex"] = 0;
|
|
925
|
-
else if (focusable === false) out["tabIndex"] = -1;
|
|
926
|
-
return out;
|
|
927
|
-
};
|
|
928
|
-
// src/render/resolveTag.ts
|
|
929
|
-
const legacyRoleToRole = {
|
|
930
|
-
header: "heading",
|
|
931
|
-
image: "img",
|
|
932
|
-
imagebutton: "button",
|
|
933
|
-
summary: "region",
|
|
934
|
-
text: "none",
|
|
935
|
-
adjustable: "slider",
|
|
936
|
-
search: "searchbox",
|
|
937
|
-
keyboardkey: "none"
|
|
938
|
-
};
|
|
939
|
-
const roleToTag = {
|
|
940
|
-
article: "article",
|
|
941
|
-
banner: "header",
|
|
942
|
-
button: "button",
|
|
943
|
-
complementary: "aside",
|
|
944
|
-
contentinfo: "footer",
|
|
945
|
-
figure: "figure",
|
|
946
|
-
form: "form",
|
|
947
|
-
list: "ul",
|
|
948
|
-
listitem: "li",
|
|
949
|
-
main: "main",
|
|
950
|
-
navigation: "nav",
|
|
951
|
-
separator: "hr"
|
|
952
|
-
};
|
|
953
|
-
const headingLevel = (level) => level !== void 0 && Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2;
|
|
954
|
-
const voidTags = /* @__PURE__ */ new Set(["hr"]);
|
|
955
|
-
const resolveTag = (props, defaultTag, hasChildren = false) => {
|
|
956
|
-
const role = props.role ?? mapLegacyRole(props.accessibilityRole);
|
|
957
|
-
const resolved = tagForRole(role, props, defaultTag);
|
|
958
|
-
return hasChildren && voidTags.has(resolved.tag) ? {
|
|
959
|
-
tag: defaultTag,
|
|
960
|
-
role
|
|
961
|
-
} : resolved;
|
|
962
|
-
};
|
|
963
|
-
const tagForRole = (role, props, defaultTag) => {
|
|
964
|
-
if (role === "heading") return {
|
|
965
|
-
tag: `h${headingLevel(props["aria-level"])}`,
|
|
966
|
-
role: void 0
|
|
967
|
-
};
|
|
968
|
-
if (role === "link") return props.href === void 0 ? {
|
|
969
|
-
tag: defaultTag,
|
|
970
|
-
role: "link"
|
|
971
|
-
} : {
|
|
972
|
-
tag: "a",
|
|
973
|
-
role: void 0
|
|
974
|
-
};
|
|
975
|
-
if (role === void 0) return {
|
|
976
|
-
tag: props.href === void 0 ? defaultTag : "a",
|
|
977
|
-
role: void 0
|
|
978
|
-
};
|
|
979
|
-
const tag = roleToTag[role];
|
|
980
|
-
return tag === void 0 ? {
|
|
981
|
-
tag: defaultTag,
|
|
982
|
-
role
|
|
983
|
-
} : {
|
|
984
|
-
tag,
|
|
985
|
-
role: void 0
|
|
986
|
-
};
|
|
987
|
-
};
|
|
988
|
-
const mapLegacyRole = (legacy) => legacy === void 0 ? void 0 : legacyRoleToRole[legacy] ?? legacy;
|
|
989
|
-
// src/render/useElementLayout.ts
|
|
990
|
-
const measure = (element) => ({ nativeEvent: { layout: {
|
|
991
|
-
x: element.offsetLeft,
|
|
992
|
-
y: element.offsetTop,
|
|
993
|
-
width: element.offsetWidth,
|
|
994
|
-
height: element.offsetHeight
|
|
995
|
-
} } });
|
|
996
|
-
const useElementLayout = (ref, onLayout) => {
|
|
997
|
-
const latest = useRef(onLayout);
|
|
998
|
-
useEffect(() => {
|
|
999
|
-
latest.current = onLayout;
|
|
1000
|
-
}, [onLayout]);
|
|
1001
|
-
const enabled = onLayout !== void 0;
|
|
1002
|
-
useEffect(() => {
|
|
1003
|
-
const element = ref.current;
|
|
1004
|
-
if (element === null || !enabled) return;
|
|
1005
|
-
const observer = new ResizeObserver(() => latest.current?.(measure(element)));
|
|
1006
|
-
observer.observe(element);
|
|
1007
|
-
return () => observer.disconnect();
|
|
1008
|
-
}, [ref, enabled]);
|
|
1009
|
-
};
|
|
1010
|
-
// src/components/View/index.tsx
|
|
1011
|
-
const resetStyle$2 = Object.freeze({
|
|
1012
|
-
alignItems: "stretch",
|
|
1013
|
-
backgroundColor: "transparent",
|
|
1014
|
-
border: "0 solid black",
|
|
1015
|
-
boxSizing: "border-box",
|
|
1016
|
-
display: "flex",
|
|
1017
|
-
flexBasis: "auto",
|
|
1018
|
-
flexDirection: "column",
|
|
1019
|
-
flexShrink: 0,
|
|
1020
|
-
listStyle: "none",
|
|
1021
|
-
margin: 0,
|
|
1022
|
-
minHeight: 0,
|
|
1023
|
-
minWidth: 0,
|
|
1024
|
-
padding: 0,
|
|
1025
|
-
position: "relative",
|
|
1026
|
-
textDecoration: "none",
|
|
1027
|
-
zIndex: 0
|
|
1028
|
-
});
|
|
1029
|
-
const pointerEventsClass = (registry, value) => registry.staticClass(`rn-pe-${value}`, value === "box-none" ? [".rn-pe-box-none{pointer-events:none}", ".rn-pe-box-none>*{pointer-events:auto}"] : [".rn-pe-box-only{pointer-events:auto}", ".rn-pe-box-only>*{pointer-events:none}"]);
|
|
1030
|
-
function View(props) {
|
|
1031
|
-
return useViewElement(props);
|
|
1032
|
-
}
|
|
1033
|
-
function useViewElement(props, extraClassName) {
|
|
1034
|
-
const { children, onLayout, pointerEvents, ref, style, ...rest } = props;
|
|
1035
|
-
const element = useRef(null);
|
|
1036
|
-
useImperativeHandle(ref, () => element.current, []);
|
|
1037
|
-
useElementLayout(element, onLayout);
|
|
1038
|
-
const registry = useStyleRegistry();
|
|
1039
|
-
const { tag, role } = resolveTag(rest, "div", children != null);
|
|
1040
|
-
let className = compileStyle([
|
|
1041
|
-
resetStyle$2,
|
|
1042
|
-
style,
|
|
1043
|
-
pointerEvents === "none" || pointerEvents === "auto" ? { pointerEvents } : void 0
|
|
1044
|
-
], registry);
|
|
1045
|
-
if (pointerEvents === "box-none" || pointerEvents === "box-only") className = `${className} ${pointerEventsClass(registry, pointerEvents)}`;
|
|
1046
|
-
if (extraClassName !== void 0) className = `${className} ${extraClassName}`;
|
|
1047
|
-
const domProps = toDOMProps(rest);
|
|
1048
|
-
if (role !== void 0) domProps["role"] = role;
|
|
1049
|
-
if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
|
|
1050
|
-
if (tag === "button") domProps["type"] = "button";
|
|
1051
|
-
domProps["className"] = className;
|
|
1052
|
-
domProps["ref"] = element;
|
|
1053
|
-
return createElement(tag, domProps, children);
|
|
1054
|
-
}
|
|
1055
|
-
// src/components/ScrollView/snap.ts
|
|
1056
|
-
const nearest = (offset, candidates) => {
|
|
1057
|
-
let best;
|
|
1058
|
-
let distance = Infinity;
|
|
1059
|
-
for (const candidate of candidates) {
|
|
1060
|
-
const d = Math.abs(candidate - offset);
|
|
1061
|
-
if (d < distance) {
|
|
1062
|
-
distance = d;
|
|
1063
|
-
best = candidate;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
return best;
|
|
1067
|
-
};
|
|
1068
|
-
const snapTarget = (offset, viewport, contentSize, config) => {
|
|
1069
|
-
const max = Math.max(0, contentSize - viewport);
|
|
1070
|
-
let target;
|
|
1071
|
-
if (config.offsets !== void 0) {
|
|
1072
|
-
if (config.offsets.length === 0) return void 0;
|
|
1073
|
-
const first = Math.min(...config.offsets);
|
|
1074
|
-
const last = Math.max(...config.offsets);
|
|
1075
|
-
if (!config.snapToStart && offset < first) return void 0;
|
|
1076
|
-
if (!config.snapToEnd && offset > last) return void 0;
|
|
1077
|
-
const candidates = [...config.offsets];
|
|
1078
|
-
if (config.snapToStart) candidates.push(0);
|
|
1079
|
-
if (config.snapToEnd) candidates.push(max);
|
|
1080
|
-
target = nearest(offset, candidates);
|
|
1081
|
-
} else if (config.interval !== void 0 && config.interval > 0) {
|
|
1082
|
-
const { interval, alignment } = config;
|
|
1083
|
-
const shift = alignment === "center" ? (viewport - interval) / 2 : alignment === "end" ? viewport - interval : 0;
|
|
1084
|
-
target = Math.round((offset + shift) / interval) * interval - shift;
|
|
1085
|
-
}
|
|
1086
|
-
if (target === void 0) return void 0;
|
|
1087
|
-
target = Math.min(max, Math.max(0, target));
|
|
1088
|
-
return Math.abs(target - offset) < .5 ? void 0 : target;
|
|
1089
|
-
};
|
|
1090
|
-
// src/components/ScrollView/index.tsx
|
|
1091
|
-
const scrollerStyle = Object.freeze({
|
|
1092
|
-
flexGrow: 1,
|
|
1093
|
-
flexShrink: 1,
|
|
1094
|
-
overflowX: "hidden",
|
|
1095
|
-
overflowY: "auto",
|
|
1096
|
-
WebkitOverflowScrolling: "touch"
|
|
1097
|
-
});
|
|
1098
|
-
const horizontalScrollerStyle = Object.freeze({
|
|
1099
|
-
flexDirection: "row",
|
|
1100
|
-
overflowX: "auto",
|
|
1101
|
-
overflowY: "hidden"
|
|
1102
|
-
});
|
|
1103
|
-
const disabledScrollerStyle = Object.freeze({
|
|
1104
|
-
overflowX: "hidden",
|
|
1105
|
-
overflowY: "hidden"
|
|
1106
|
-
});
|
|
1107
|
-
const horizontalContentStyle = Object.freeze({ flexDirection: "row" });
|
|
1108
|
-
const centerContentStyle = Object.freeze({
|
|
1109
|
-
flexGrow: 1,
|
|
1110
|
-
justifyContent: "center"
|
|
1111
|
-
});
|
|
1112
|
-
const stickyStyle = Object.freeze({
|
|
1113
|
-
position: "sticky",
|
|
1114
|
-
top: 0,
|
|
1115
|
-
zIndex: 10
|
|
1116
|
-
});
|
|
1117
|
-
const invertedStickyStyle = Object.freeze({
|
|
1118
|
-
position: "sticky",
|
|
1119
|
-
bottom: 0,
|
|
1120
|
-
zIndex: 10
|
|
1121
|
-
});
|
|
1122
|
-
const hiddenScrollbarClass = (registry) => registry.staticClass("rn-scrollbar-none", [".rn-scrollbar-none{scrollbar-width:none;-ms-overflow-style:none}", ".rn-scrollbar-none::-webkit-scrollbar{display:none}"]);
|
|
1123
|
-
const supportsScrollEnd = hasDOM() && "onscrollend" in window;
|
|
1124
|
-
const SCROLL_END_DELAY = 150;
|
|
1125
|
-
const behaviorFor = (animated) => animated !== false && !Platform.isDisableAnimations ? "smooth" : "auto";
|
|
1126
|
-
const describe = (element) => ({
|
|
1127
|
-
contentInset: {
|
|
1128
|
-
top: 0,
|
|
1129
|
-
left: 0,
|
|
1130
|
-
bottom: 0,
|
|
1131
|
-
right: 0
|
|
1132
|
-
},
|
|
1133
|
-
contentOffset: {
|
|
1134
|
-
x: element.scrollLeft,
|
|
1135
|
-
y: element.scrollTop
|
|
1136
|
-
},
|
|
1137
|
-
contentSize: {
|
|
1138
|
-
width: element.scrollWidth,
|
|
1139
|
-
height: element.scrollHeight
|
|
1140
|
-
},
|
|
1141
|
-
layoutMeasurement: {
|
|
1142
|
-
width: element.clientWidth,
|
|
1143
|
-
height: element.clientHeight
|
|
1144
|
-
},
|
|
1145
|
-
zoomScale: 1
|
|
1146
|
-
});
|
|
1147
|
-
const isReactNativeScrollTo = (value) => typeof value === "object" && value !== null && ("x" in value || "y" in value || "animated" in value);
|
|
1148
|
-
const domScrollTo = (element, options) => {
|
|
1149
|
-
const init = { behavior: behaviorFor(options.animated) };
|
|
1150
|
-
if (options.x !== void 0) init.left = options.x;
|
|
1151
|
-
if (options.y !== void 0) init.top = options.y;
|
|
1152
|
-
element.scrollTo(init);
|
|
1153
|
-
};
|
|
1154
|
-
function ScrollView(props) {
|
|
1155
|
-
const { centerContent, children, contentContainerStyle, contentOffset, horizontal = false, invertStickyHeaders, keyboardDismissMode, onContentSizeChange, onMomentumScrollBegin, onMomentumScrollEnd, onPointerDown, onScroll, onScrollBeginDrag, onScrollEndDrag, pagingEnabled, ref, refreshControl, scrollEnabled = true, showsHorizontalScrollIndicator = true, showsVerticalScrollIndicator = true, snapToAlignment = "start", snapToEnd = true, snapToInterval, snapToOffsets, snapToStart = true, stickyHeaderHiddenOnScroll, stickyHeaderIndices, style, alwaysBounceHorizontal: _alwaysBounceHorizontal, alwaysBounceVertical: _alwaysBounceVertical, automaticallyAdjustContentInsets: _automaticallyAdjustContentInsets, automaticallyAdjustKeyboardInsets: _automaticallyAdjustKeyboardInsets, automaticallyAdjustsScrollIndicatorInsets: _automaticallyAdjustsScrollIndicatorInsets, bounces: _bounces, bouncesZoom: _bouncesZoom, canCancelContentTouches: _canCancelContentTouches, contentInset: _contentInset, contentInsetAdjustmentBehavior: _contentInsetAdjustmentBehavior, decelerationRate: _decelerationRate, directionalLockEnabled: _directionalLockEnabled, disableIntervalMomentum: _disableIntervalMomentum, disableScrollViewPanResponder: _disableScrollViewPanResponder, endFillColor: _endFillColor, fadingEdgeLength: _fadingEdgeLength, indicatorStyle: _indicatorStyle, keyboardShouldPersistTaps: _keyboardShouldPersistTaps, maintainVisibleContentPosition: _maintainVisibleContentPosition, maximumZoomScale: _maximumZoomScale, minimumZoomScale: _minimumZoomScale, nestedScrollEnabled: _nestedScrollEnabled, onScrollToTop: _onScrollToTop, overScrollMode: _overScrollMode, persistentScrollbar: _persistentScrollbar, pinchGestureEnabled: _pinchGestureEnabled, removeClippedSubviews: _removeClippedSubviews, scrollEventThrottle: _scrollEventThrottle, scrollIndicatorInsets: _scrollIndicatorInsets, scrollPerfTag: _scrollPerfTag, scrollToOverflowEnabled: _scrollToOverflowEnabled, scrollsToTop: _scrollsToTop, snapToIntervalMomentum: _snapToIntervalMomentum, zoomScale: _zoomScale, ...rest } = props;
|
|
1156
|
-
const registry = useStyleRegistry();
|
|
1157
|
-
const scroller = useRef(null);
|
|
1158
|
-
const content = useRef(null);
|
|
1159
|
-
const handlers = useRef({});
|
|
1160
|
-
useEffect(() => {
|
|
1161
|
-
handlers.current = {
|
|
1162
|
-
onScroll,
|
|
1163
|
-
onScrollBeginDrag,
|
|
1164
|
-
onScrollEndDrag,
|
|
1165
|
-
onMomentumScrollBegin,
|
|
1166
|
-
onMomentumScrollEnd
|
|
1167
|
-
};
|
|
1168
|
-
});
|
|
1169
|
-
const snap = useRef({
|
|
1170
|
-
horizontal,
|
|
1171
|
-
pagingEnabled: pagingEnabled === true,
|
|
1172
|
-
snapToInterval,
|
|
1173
|
-
snapToOffsets,
|
|
1174
|
-
snapToAlignment,
|
|
1175
|
-
snapToStart,
|
|
1176
|
-
snapToEnd,
|
|
1177
|
-
keyboardDismissMode,
|
|
1178
|
-
stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
|
|
1179
|
-
});
|
|
1180
|
-
useEffect(() => {
|
|
1181
|
-
snap.current = {
|
|
1182
|
-
horizontal,
|
|
1183
|
-
pagingEnabled: pagingEnabled === true,
|
|
1184
|
-
snapToInterval,
|
|
1185
|
-
snapToOffsets,
|
|
1186
|
-
snapToAlignment,
|
|
1187
|
-
snapToStart,
|
|
1188
|
-
snapToEnd,
|
|
1189
|
-
keyboardDismissMode,
|
|
1190
|
-
stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
|
|
1191
|
-
};
|
|
1192
|
-
});
|
|
1193
|
-
const sequence = useRef({
|
|
1194
|
-
phase: "idle",
|
|
1195
|
-
pointerDown: false,
|
|
1196
|
-
lastEvent: null,
|
|
1197
|
-
lastOffset: 0,
|
|
1198
|
-
timer: void 0,
|
|
1199
|
-
snapping: false
|
|
1200
|
-
});
|
|
1201
|
-
const stickyHeaders = useRef([]);
|
|
1202
|
-
const refreshEvent = useCallback(() => {
|
|
1203
|
-
const state = sequence.current;
|
|
1204
|
-
const element = scroller.current;
|
|
1205
|
-
if (state.lastEvent === null || element === null) return null;
|
|
1206
|
-
Object.assign(state.lastEvent.nativeEvent, describe(element));
|
|
1207
|
-
return state.lastEvent;
|
|
1208
|
-
}, []);
|
|
1209
|
-
const settle = useCallback(() => {
|
|
1210
|
-
const state = sequence.current;
|
|
1211
|
-
const element = scroller.current;
|
|
1212
|
-
if (element === null) return;
|
|
1213
|
-
if (state.pointerDown && state.phase === "drag") return;
|
|
1214
|
-
if (state.phase === "momentum") {
|
|
1215
|
-
const event = refreshEvent();
|
|
1216
|
-
if (event !== null) handlers.current.onMomentumScrollEnd?.(event);
|
|
1217
|
-
}
|
|
1218
|
-
state.phase = "idle";
|
|
1219
|
-
if (state.snapping) {
|
|
1220
|
-
state.snapping = false;
|
|
1221
|
-
return;
|
|
1222
|
-
}
|
|
1223
|
-
const config = snap.current;
|
|
1224
|
-
const axis = config.horizontal;
|
|
1225
|
-
const viewport = axis ? element.clientWidth : element.clientHeight;
|
|
1226
|
-
const target = snapTarget(axis ? element.scrollLeft : element.scrollTop, viewport, axis ? element.scrollWidth : element.scrollHeight, {
|
|
1227
|
-
offsets: config.snapToOffsets,
|
|
1228
|
-
interval: config.pagingEnabled ? viewport : config.snapToInterval,
|
|
1229
|
-
alignment: config.snapToAlignment,
|
|
1230
|
-
snapToStart: config.snapToStart,
|
|
1231
|
-
snapToEnd: config.snapToEnd
|
|
1232
|
-
});
|
|
1233
|
-
if (target === void 0) return;
|
|
1234
|
-
state.snapping = true;
|
|
1235
|
-
domScrollTo(element, axis ? { x: target } : { y: target });
|
|
1236
|
-
}, [refreshEvent]);
|
|
1237
|
-
const handleScroll = (event) => {
|
|
1238
|
-
const element = event.currentTarget;
|
|
1239
|
-
if (event.target !== element) return;
|
|
1240
|
-
const state = sequence.current;
|
|
1241
|
-
const scrollEvent = event;
|
|
1242
|
-
Object.assign(scrollEvent.nativeEvent, describe(element));
|
|
1243
|
-
state.lastEvent = scrollEvent;
|
|
1244
|
-
const config = snap.current;
|
|
1245
|
-
const offset = config.horizontal ? element.scrollLeft : element.scrollTop;
|
|
1246
|
-
const delta = offset - state.lastOffset;
|
|
1247
|
-
state.lastOffset = offset;
|
|
1248
|
-
if (state.phase === "idle") {
|
|
1249
|
-
if (state.pointerDown) {
|
|
1250
|
-
state.phase = "drag";
|
|
1251
|
-
handlers.current.onScrollBeginDrag?.(scrollEvent);
|
|
1252
|
-
if (config.keyboardDismissMode === "on-drag") {
|
|
1253
|
-
const active = document.activeElement;
|
|
1254
|
-
if (active instanceof HTMLElement && active !== document.body) active.blur();
|
|
1255
|
-
}
|
|
1256
|
-
} else {
|
|
1257
|
-
state.phase = "momentum";
|
|
1258
|
-
handlers.current.onMomentumScrollBegin?.(scrollEvent);
|
|
1259
|
-
}
|
|
1260
|
-
} else if (state.phase === "released") {
|
|
1261
|
-
state.phase = "momentum";
|
|
1262
|
-
handlers.current.onMomentumScrollBegin?.(scrollEvent);
|
|
1263
|
-
}
|
|
1264
|
-
if (config.stickyHeaderHiddenOnScroll && !config.horizontal && delta !== 0) {
|
|
1265
|
-
const hidden = delta > 0;
|
|
1266
|
-
for (const header of stickyHeaders.current) {
|
|
1267
|
-
header.style.transition = "transform 150ms";
|
|
1268
|
-
header.style.transform = hidden ? "translateY(-100%)" : "";
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
handlers.current.onScroll?.(scrollEvent);
|
|
1272
|
-
if (!supportsScrollEnd) {
|
|
1273
|
-
if (state.timer !== void 0) clearTimeout(state.timer);
|
|
1274
|
-
state.timer = setTimeout(settle, SCROLL_END_DELAY);
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
const handleScrollEnd = (event) => {
|
|
1278
|
-
if (event.target !== event.currentTarget) return;
|
|
1279
|
-
settle();
|
|
1280
|
-
};
|
|
1281
|
-
const handlePointerDown = (event) => {
|
|
1282
|
-
onPointerDown?.(event);
|
|
1283
|
-
const state = sequence.current;
|
|
1284
|
-
if (state.pointerDown) return;
|
|
1285
|
-
state.pointerDown = true;
|
|
1286
|
-
const release = () => {
|
|
1287
|
-
window.removeEventListener("pointerup", release);
|
|
1288
|
-
window.removeEventListener("pointercancel", release);
|
|
1289
|
-
state.pointerDown = false;
|
|
1290
|
-
if (state.phase === "drag") {
|
|
1291
|
-
state.phase = "released";
|
|
1292
|
-
const scrollEvent = refreshEvent();
|
|
1293
|
-
if (scrollEvent !== null) handlers.current.onScrollEndDrag?.(scrollEvent);
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
window.addEventListener("pointerup", release);
|
|
1297
|
-
window.addEventListener("pointercancel", release);
|
|
1298
|
-
};
|
|
1299
|
-
useEffect(() => {
|
|
1300
|
-
const state = sequence.current;
|
|
1301
|
-
return () => {
|
|
1302
|
-
if (state.timer !== void 0) clearTimeout(state.timer);
|
|
1303
|
-
};
|
|
1304
|
-
}, []);
|
|
1305
|
-
const onContentLayout = onContentSizeChange === void 0 ? void 0 : (event) => onContentSizeChange(event.nativeEvent.layout.width, event.nativeEvent.layout.height);
|
|
1306
|
-
const stickySet = stickyHeaderIndices !== void 0 && stickyHeaderIndices.length > 0 && !horizontal ? new Set(stickyHeaderIndices) : void 0;
|
|
1307
|
-
const setStickyHeader = useCallback((node) => {
|
|
1308
|
-
const list = stickyHeaders.current;
|
|
1309
|
-
if (node === null) return;
|
|
1310
|
-
if (!list.includes(node)) list.push(node);
|
|
1311
|
-
return () => {
|
|
1312
|
-
const index = list.indexOf(node);
|
|
1313
|
-
if (index !== -1) list.splice(index, 1);
|
|
1314
|
-
};
|
|
1315
|
-
}, []);
|
|
1316
|
-
let items = children;
|
|
1317
|
-
if (stickySet !== void 0) items = Children.toArray(children).map((child, index) => stickySet.has(index) ? /* @__PURE__ */ jsx(View, {
|
|
1318
|
-
ref: setStickyHeader,
|
|
1319
|
-
style: invertStickyHeaders === true ? invertedStickyStyle : stickyStyle,
|
|
1320
|
-
children: child
|
|
1321
|
-
}, isValidElement(child) && child.key !== null ? child.key : `sticky-${index}`) : child);
|
|
1322
|
-
const contentElement = /* @__PURE__ */ jsx(View, {
|
|
1323
|
-
ref: content,
|
|
1324
|
-
onLayout: onContentLayout,
|
|
1325
|
-
style: [
|
|
1326
|
-
horizontal && horizontalContentStyle,
|
|
1327
|
-
centerContent === true && centerContentStyle,
|
|
1328
|
-
contentContainerStyle
|
|
1329
|
-
],
|
|
1330
|
-
children: items
|
|
1331
|
-
});
|
|
1332
|
-
const hideScrollbar = horizontal ? !showsHorizontalScrollIndicator : !showsVerticalScrollIndicator;
|
|
1333
|
-
const scrollerElement = useViewElement({
|
|
1334
|
-
...rest,
|
|
1335
|
-
ref: scroller,
|
|
1336
|
-
style: [
|
|
1337
|
-
scrollerStyle,
|
|
1338
|
-
horizontal && horizontalScrollerStyle,
|
|
1339
|
-
!scrollEnabled && disabledScrollerStyle,
|
|
1340
|
-
style
|
|
1341
|
-
],
|
|
1342
|
-
onScroll: handleScroll,
|
|
1343
|
-
onScrollEnd: handleScrollEnd,
|
|
1344
|
-
onPointerDown: handlePointerDown,
|
|
1345
|
-
children: contentElement
|
|
1346
|
-
}, hideScrollbar ? hiddenScrollbarClass(registry) : void 0);
|
|
1347
|
-
const offsetX = contentOffset?.x;
|
|
1348
|
-
const offsetY = contentOffset?.y;
|
|
1349
|
-
useLayoutEffect(() => {
|
|
1350
|
-
const element = scroller.current;
|
|
1351
|
-
if (element === null || offsetX === void 0 && offsetY === void 0) return;
|
|
1352
|
-
if (offsetX !== void 0) element.scrollLeft = offsetX;
|
|
1353
|
-
if (offsetY !== void 0) element.scrollTop = offsetY;
|
|
1354
|
-
sequence.current.lastOffset = horizontal ? element.scrollLeft : element.scrollTop;
|
|
1355
|
-
}, [
|
|
1356
|
-
offsetX,
|
|
1357
|
-
offsetY,
|
|
1358
|
-
horizontal
|
|
1359
|
-
]);
|
|
1360
|
-
useImperativeHandle(ref, () => {
|
|
1361
|
-
const element = scroller.current;
|
|
1362
|
-
const nativeScrollTo = element.scrollTo.bind(element);
|
|
1363
|
-
const instance = element;
|
|
1364
|
-
return Object.assign(instance, {
|
|
1365
|
-
scrollTo: ((first, second) => {
|
|
1366
|
-
if (isReactNativeScrollTo(first)) domScrollTo(element, first);
|
|
1367
|
-
else if (typeof first === "number" && typeof second === "number") nativeScrollTo(first, second);
|
|
1368
|
-
else nativeScrollTo(first);
|
|
1369
|
-
}),
|
|
1370
|
-
scrollToEnd: (options) => {
|
|
1371
|
-
const animated = options?.animated;
|
|
1372
|
-
domScrollTo(element, horizontal ? {
|
|
1373
|
-
x: element.scrollWidth,
|
|
1374
|
-
animated
|
|
1375
|
-
} : {
|
|
1376
|
-
y: element.scrollHeight,
|
|
1377
|
-
animated
|
|
1378
|
-
});
|
|
1379
|
-
},
|
|
1380
|
-
flashScrollIndicators: () => {},
|
|
1381
|
-
getScrollResponder: () => instance,
|
|
1382
|
-
getScrollableNode: () => element,
|
|
1383
|
-
getInnerViewNode: () => content.current,
|
|
1384
|
-
getInnerViewRef: () => content.current,
|
|
1385
|
-
getNativeScrollRef: () => element
|
|
1386
|
-
});
|
|
1387
|
-
}, [horizontal]);
|
|
1388
|
-
return refreshControl === void 0 ? scrollerElement : cloneElement(refreshControl, void 0, scrollerElement);
|
|
1389
|
-
}
|
|
1390
|
-
// src/components/FlatList/viewability.ts
|
|
1391
|
-
const pixelsVisible = (top, bottom, viewport) => Math.max(0, Math.min(bottom, viewport) - Math.max(top, 0));
|
|
1392
|
-
const isEntirelyVisible = (top, bottom, viewport) => top >= 0 && bottom <= viewport && bottom > top;
|
|
1393
|
-
const isViewable = (viewAreaMode, threshold, top, bottom, viewport, length) => {
|
|
1394
|
-
if (isEntirelyVisible(top, bottom, viewport)) return true;
|
|
1395
|
-
const pixels = pixelsVisible(top, bottom, viewport);
|
|
1396
|
-
return 100 * (viewAreaMode ? pixels / viewport : pixels / length) >= threshold;
|
|
1397
|
-
};
|
|
1398
|
-
const computeViewableIndices = (itemCount, metricsAt, scrollOffset, viewport, config) => {
|
|
1399
|
-
const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = config;
|
|
1400
|
-
const viewAreaMode = viewAreaCoveragePercentThreshold != null;
|
|
1401
|
-
const threshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
|
|
1402
|
-
if (threshold == null || viewAreaMode === (itemVisiblePercentThreshold != null)) throw new Error("Must set exactly one of itemVisiblePercentThreshold or viewAreaCoveragePercentThreshold");
|
|
1403
|
-
const viewable = [];
|
|
1404
|
-
let firstVisible = -1;
|
|
1405
|
-
for (let index = 0; index < itemCount; index++) {
|
|
1406
|
-
const metrics = metricsAt(index);
|
|
1407
|
-
if (metrics === void 0) continue;
|
|
1408
|
-
const top = Math.floor(metrics.offset - scrollOffset);
|
|
1409
|
-
const bottom = Math.floor(top + metrics.length);
|
|
1410
|
-
if (top < viewport && bottom > 0) {
|
|
1411
|
-
firstVisible = index;
|
|
1412
|
-
if (isViewable(viewAreaMode, threshold, top, bottom, viewport, metrics.length)) viewable.push(index);
|
|
1413
|
-
} else if (firstVisible >= 0) break;
|
|
1414
|
-
}
|
|
1415
|
-
return viewable;
|
|
1416
|
-
};
|
|
1417
|
-
const sameIndices = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
|
|
1418
|
-
var ViewabilityTracker = class {
|
|
1419
|
-
constructor(config = { viewAreaCoveragePercentThreshold: 0 }) {
|
|
1420
|
-
this.interacted = false;
|
|
1421
|
-
this.timers = /* @__PURE__ */ new Set();
|
|
1422
|
-
this.viewableIndices = [];
|
|
1423
|
-
this.viewableItems = /* @__PURE__ */ new Map();
|
|
1424
|
-
this.config = config;
|
|
1425
|
-
}
|
|
1426
|
-
dispose() {
|
|
1427
|
-
for (const timer of this.timers) clearTimeout(timer);
|
|
1428
|
-
this.timers.clear();
|
|
1429
|
-
}
|
|
1430
|
-
recordInteraction() {
|
|
1431
|
-
this.interacted = true;
|
|
1432
|
-
}
|
|
1433
|
-
resetViewableIndices() {
|
|
1434
|
-
this.viewableIndices = [];
|
|
1435
|
-
}
|
|
1436
|
-
onUpdate(itemCount, metricsAt, scrollOffset, viewport, createViewToken, onViewableItemsChanged) {
|
|
1437
|
-
if (this.config.waitForInteraction === true && !this.interacted || itemCount === 0) return;
|
|
1438
|
-
if (metricsAt(0) === void 0) return;
|
|
1439
|
-
const next = computeViewableIndices(itemCount, metricsAt, scrollOffset, viewport, this.config);
|
|
1440
|
-
if (sameIndices(this.viewableIndices, next)) return;
|
|
1441
|
-
this.viewableIndices = next;
|
|
1442
|
-
const { minimumViewTime } = this.config;
|
|
1443
|
-
if (minimumViewTime !== void 0 && minimumViewTime > 0) {
|
|
1444
|
-
const timer = setTimeout(() => {
|
|
1445
|
-
this.timers.delete(timer);
|
|
1446
|
-
if (this.viewableIndices !== next) return;
|
|
1447
|
-
this.report(next, createViewToken, onViewableItemsChanged);
|
|
1448
|
-
}, minimumViewTime);
|
|
1449
|
-
this.timers.add(timer);
|
|
1450
|
-
} else this.report(next, createViewToken, onViewableItemsChanged);
|
|
1451
|
-
}
|
|
1452
|
-
report(indices, createViewToken, onViewableItemsChanged) {
|
|
1453
|
-
const previous = this.viewableItems;
|
|
1454
|
-
const next = /* @__PURE__ */ new Map();
|
|
1455
|
-
for (const index of indices) {
|
|
1456
|
-
const token = createViewToken(index, true);
|
|
1457
|
-
next.set(token.key, token);
|
|
1458
|
-
}
|
|
1459
|
-
const changed = [];
|
|
1460
|
-
for (const [key, token] of next) if (!previous.has(key)) changed.push(token);
|
|
1461
|
-
for (const [key, token] of previous) if (!next.has(key)) changed.push({
|
|
1462
|
-
...token,
|
|
1463
|
-
isViewable: false
|
|
1464
|
-
});
|
|
1465
|
-
if (changed.length === 0) return;
|
|
1466
|
-
this.viewableItems = next;
|
|
1467
|
-
onViewableItemsChanged({
|
|
1468
|
-
viewableItems: Array.from(next.values()),
|
|
1469
|
-
changed
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
};
|
|
1473
|
-
// src/components/FlatList/index.tsx
|
|
1474
|
-
const rowStyle = Object.freeze({ flexDirection: "row" });
|
|
1475
|
-
const rowReverseStyle = Object.freeze({ flexDirection: "row-reverse" });
|
|
1476
|
-
const columnReverseStyle = Object.freeze({ flexDirection: "column-reverse" });
|
|
1477
|
-
const verticallyInvertedStyle = Object.freeze({ transform: [{ scaleY: -1 }] });
|
|
1478
|
-
const horizontallyInvertedStyle = Object.freeze({ transform: [{ scaleX: -1 }] });
|
|
1479
|
-
const ON_EDGE_REACHED_EPSILON = .001;
|
|
1480
|
-
const DEFAULT_EDGE_THRESHOLD_PX = 2;
|
|
1481
|
-
const defaultKeyExtractor = (item, index) => {
|
|
1482
|
-
if (typeof item === "object" && item !== null) {
|
|
1483
|
-
const record = item;
|
|
1484
|
-
if (record.key != null) return String(record.key);
|
|
1485
|
-
if (record.id != null) return String(record.id);
|
|
1486
|
-
}
|
|
1487
|
-
return String(index);
|
|
1488
|
-
};
|
|
1489
|
-
const isArrayLike = (data) => data != null && typeof data.length === "number";
|
|
1490
|
-
const renderListComponent = (component) => {
|
|
1491
|
-
if (component == null) return null;
|
|
1492
|
-
if (isValidElement(component)) return component;
|
|
1493
|
-
return /* @__PURE__ */ jsx(component, {});
|
|
1494
|
-
};
|
|
1495
|
-
function CustomScroller({ render, ref, ...props }) {
|
|
1496
|
-
return cloneElement(render(props), { ref }, props.children);
|
|
1497
|
-
}
|
|
1498
|
-
function Cell(props) {
|
|
1499
|
-
const { cellKey, prevCellKey, index, item, style, renderCell, ItemSeparatorComponent, CellRendererComponent, separatorUpdaters, onElement } = props;
|
|
1500
|
-
const [separatorProps, setSeparatorProps] = useState({
|
|
1501
|
-
highlighted: false,
|
|
1502
|
-
leadingItem: item
|
|
1503
|
-
});
|
|
1504
|
-
const shown = separatorProps.leadingItem === item ? separatorProps : {
|
|
1505
|
-
...separatorProps,
|
|
1506
|
-
leadingItem: item
|
|
1507
|
-
};
|
|
1508
|
-
useEffect(() => {
|
|
1509
|
-
separatorUpdaters.set(cellKey, (next) => {
|
|
1510
|
-
setSeparatorProps((current) => ({
|
|
1511
|
-
...current,
|
|
1512
|
-
...next
|
|
1513
|
-
}));
|
|
1514
|
-
});
|
|
1515
|
-
return () => {
|
|
1516
|
-
separatorUpdaters.delete(cellKey);
|
|
1517
|
-
};
|
|
1518
|
-
}, [cellKey, separatorUpdaters]);
|
|
1519
|
-
const separators = useMemo(() => {
|
|
1520
|
-
const update = (keys, next) => {
|
|
1521
|
-
for (const key of keys) if (key !== void 0) separatorUpdaters.get(key)?.(next);
|
|
1522
|
-
};
|
|
1523
|
-
return {
|
|
1524
|
-
highlight: () => update([cellKey, prevCellKey], { highlighted: true }),
|
|
1525
|
-
unhighlight: () => update([cellKey, prevCellKey], { highlighted: false }),
|
|
1526
|
-
updateProps: (select, next) => update([select === "leading" ? prevCellKey : cellKey], next)
|
|
1527
|
-
};
|
|
1528
|
-
}, [
|
|
1529
|
-
cellKey,
|
|
1530
|
-
prevCellKey,
|
|
1531
|
-
separatorUpdaters
|
|
1532
|
-
]);
|
|
1533
|
-
const setElement = useCallback((node) => {
|
|
1534
|
-
if (node === null) return;
|
|
1535
|
-
onElement(index, node);
|
|
1536
|
-
return () => onElement(index, null);
|
|
1537
|
-
}, [index, onElement]);
|
|
1538
|
-
let separator = null;
|
|
1539
|
-
if (ItemSeparatorComponent != null) {
|
|
1540
|
-
if (isValidElement(ItemSeparatorComponent)) separator = ItemSeparatorComponent;
|
|
1541
|
-
else separator = /* @__PURE__ */ jsx(ItemSeparatorComponent, { ...shown });
|
|
1542
|
-
}
|
|
1543
|
-
const element = renderCell(item, index, separators);
|
|
1544
|
-
if (CellRendererComponent != null) return /* @__PURE__ */ jsx(View, {
|
|
1545
|
-
ref: setElement,
|
|
1546
|
-
children: /* @__PURE__ */ jsxs(CellRendererComponent, {
|
|
1547
|
-
cellKey,
|
|
1548
|
-
index,
|
|
1549
|
-
item,
|
|
1550
|
-
style,
|
|
1551
|
-
children: [element, separator]
|
|
1552
|
-
})
|
|
1553
|
-
});
|
|
1554
|
-
return /* @__PURE__ */ jsxs(View, {
|
|
1555
|
-
ref: setElement,
|
|
1556
|
-
style,
|
|
1557
|
-
children: [element, separator]
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
const createTrackers = (props) => {
|
|
1561
|
-
if (props.viewabilityConfigCallbackPairs !== void 0) return props.viewabilityConfigCallbackPairs.map((pair) => ({
|
|
1562
|
-
tracker: new ViewabilityTracker(pair.viewabilityConfig),
|
|
1563
|
-
callback: () => pair.onViewableItemsChanged
|
|
1564
|
-
}));
|
|
1565
|
-
if (props.onViewableItemsChanged != null) return [{
|
|
1566
|
-
tracker: new ViewabilityTracker(props.viewabilityConfig),
|
|
1567
|
-
callback: (latest) => latest.onViewableItemsChanged
|
|
1568
|
-
}];
|
|
1569
|
-
return [];
|
|
1570
|
-
};
|
|
1571
|
-
function FlatList(props) {
|
|
1572
|
-
const { data, renderItem, ListItemComponent, keyExtractor = defaultKeyExtractor, getItemLayout: _getItemLayout, numColumns = 1, columnWrapperStyle, inverted, initialScrollIndex: _initialScrollIndex, ItemSeparatorComponent, ListEmptyComponent, ListHeaderComponent, ListHeaderComponentStyle, ListFooterComponent, ListFooterComponentStyle, CellRendererComponent, renderScrollComponent, horizontal = false, style, ref, onScroll: _onScroll, onContentSizeChange: _onContentSizeChange, onLayout: _onLayout, onEndReached: _onEndReached, onEndReachedThreshold: _onEndReachedThreshold, onStartReached: _onStartReached, onStartReachedThreshold: _onStartReachedThreshold, onViewableItemsChanged: _onViewableItemsChanged, viewabilityConfig: _viewabilityConfig, viewabilityConfigCallbackPairs: _viewabilityConfigCallbackPairs, onScrollToIndexFailed: _onScrollToIndexFailed, extraData: _extraData, onRefresh: _onRefresh, refreshing: _refreshing, debug: _debug, disableVirtualization: _disableVirtualization, initialNumToRender: _initialNumToRender, maxToRenderPerBatch: _maxToRenderPerBatch, progressViewOffset: _progressViewOffset, strictMode: _strictMode, updateCellsBatchingPeriod: _updateCellsBatchingPeriod, windowSize: _windowSize, legacyImplementation: _legacyImplementation, ...scrollViewProps } = props;
|
|
1573
|
-
if (numColumns > 1 && horizontal) throw new Error("numColumns does not support horizontal.");
|
|
1574
|
-
const latest = useRef(props);
|
|
1575
|
-
useEffect(() => {
|
|
1576
|
-
latest.current = props;
|
|
1577
|
-
});
|
|
1578
|
-
const scroller = useRef(null);
|
|
1579
|
-
const [cells] = useState(() => /* @__PURE__ */ new Map());
|
|
1580
|
-
const [separatorUpdaters] = useState(() => /* @__PURE__ */ new Map());
|
|
1581
|
-
const [trackers] = useState(() => createTrackers(props));
|
|
1582
|
-
const edge = useRef({
|
|
1583
|
-
sentEndForContentLength: 0,
|
|
1584
|
-
sentStartForContentLength: 0
|
|
1585
|
-
});
|
|
1586
|
-
useEffect(() => {
|
|
1587
|
-
return () => {
|
|
1588
|
-
for (const entry of trackers) entry.tracker.dispose();
|
|
1589
|
-
};
|
|
1590
|
-
}, [trackers]);
|
|
1591
|
-
const onElement = useCallback((index, node) => {
|
|
1592
|
-
if (node === null) cells.delete(index);
|
|
1593
|
-
else cells.set(index, node);
|
|
1594
|
-
}, [cells]);
|
|
1595
|
-
const items = isArrayLike(data) ? data : [];
|
|
1596
|
-
const rowCount = numColumns > 1 ? Math.ceil(items.length / numColumns) : items.length;
|
|
1597
|
-
const rowAt = (index) => {
|
|
1598
|
-
if (numColumns === 1) return items[index];
|
|
1599
|
-
const row = [];
|
|
1600
|
-
for (let column = 0; column < numColumns; column++) {
|
|
1601
|
-
const itemIndex = index * numColumns + column;
|
|
1602
|
-
if (itemIndex < items.length) row.push(items[itemIndex]);
|
|
1603
|
-
}
|
|
1604
|
-
return row;
|
|
1605
|
-
};
|
|
1606
|
-
const rowKey = (row, index) => {
|
|
1607
|
-
if (numColumns === 1) return keyExtractor(row, index);
|
|
1608
|
-
return row.map((item, column) => keyExtractor(item, index * numColumns + column)).join(":");
|
|
1609
|
-
};
|
|
1610
|
-
const metricsAt = useCallback((index) => {
|
|
1611
|
-
const element = cells.get(index);
|
|
1612
|
-
const { horizontal: isHorizontal = false, getItemLayout, data: currentData } = latest.current;
|
|
1613
|
-
if (element !== void 0) return isHorizontal ? {
|
|
1614
|
-
offset: element.offsetLeft,
|
|
1615
|
-
length: element.offsetWidth
|
|
1616
|
-
} : {
|
|
1617
|
-
offset: element.offsetTop,
|
|
1618
|
-
length: element.offsetHeight
|
|
1619
|
-
};
|
|
1620
|
-
const layout = getItemLayout?.(currentData, index);
|
|
1621
|
-
return layout === void 0 ? void 0 : {
|
|
1622
|
-
offset: layout.offset,
|
|
1623
|
-
length: layout.length
|
|
1624
|
-
};
|
|
1625
|
-
}, [cells]);
|
|
1626
|
-
const maybeCallOnEdgeReached = useCallback(() => {
|
|
1627
|
-
const element = scroller.current;
|
|
1628
|
-
if (element === null) return;
|
|
1629
|
-
const { horizontal: isHorizontal = false, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold } = latest.current;
|
|
1630
|
-
const visibleLength = isHorizontal ? element.clientWidth : element.clientHeight;
|
|
1631
|
-
const contentLength = isHorizontal ? element.scrollWidth : element.scrollHeight;
|
|
1632
|
-
if (visibleLength === 0 || contentLength === 0) return;
|
|
1633
|
-
const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
|
|
1634
|
-
let distanceFromStart = offset;
|
|
1635
|
-
let distanceFromEnd = contentLength - visibleLength - offset;
|
|
1636
|
-
if (distanceFromStart < ON_EDGE_REACHED_EPSILON) distanceFromStart = 0;
|
|
1637
|
-
if (distanceFromEnd < ON_EDGE_REACHED_EPSILON) distanceFromEnd = 0;
|
|
1638
|
-
const startThreshold = onStartReachedThreshold != null ? onStartReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
|
|
1639
|
-
const endThreshold = onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
|
|
1640
|
-
const withinStart = distanceFromStart <= startThreshold;
|
|
1641
|
-
const withinEnd = distanceFromEnd <= endThreshold;
|
|
1642
|
-
const state = edge.current;
|
|
1643
|
-
if (onEndReached != null && withinEnd && contentLength !== state.sentEndForContentLength) {
|
|
1644
|
-
state.sentEndForContentLength = contentLength;
|
|
1645
|
-
onEndReached({ distanceFromEnd });
|
|
1646
|
-
}
|
|
1647
|
-
if (onStartReached != null && withinStart && contentLength !== state.sentStartForContentLength) {
|
|
1648
|
-
state.sentStartForContentLength = contentLength;
|
|
1649
|
-
onStartReached({ distanceFromStart });
|
|
1650
|
-
}
|
|
1651
|
-
if (!withinStart) state.sentStartForContentLength = 0;
|
|
1652
|
-
if (!withinEnd) state.sentEndForContentLength = 0;
|
|
1653
|
-
}, []);
|
|
1654
|
-
const updateViewability = useCallback(() => {
|
|
1655
|
-
const element = scroller.current;
|
|
1656
|
-
if (element === null || trackers.length === 0) return;
|
|
1657
|
-
const current = latest.current;
|
|
1658
|
-
const isHorizontal = current.horizontal === true;
|
|
1659
|
-
const columns = current.numColumns ?? 1;
|
|
1660
|
-
const extract = current.keyExtractor ?? defaultKeyExtractor;
|
|
1661
|
-
const currentItems = isArrayLike(current.data) ? current.data : [];
|
|
1662
|
-
const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
|
|
1663
|
-
const createToken = (index, isViewable) => {
|
|
1664
|
-
if (columns === 1) {
|
|
1665
|
-
const item = currentItems[index];
|
|
1666
|
-
return {
|
|
1667
|
-
item,
|
|
1668
|
-
key: extract(item, index),
|
|
1669
|
-
index,
|
|
1670
|
-
isViewable
|
|
1671
|
-
};
|
|
1672
|
-
}
|
|
1673
|
-
const row = [];
|
|
1674
|
-
for (let column = 0; column < columns; column++) {
|
|
1675
|
-
const itemIndex = index * columns + column;
|
|
1676
|
-
if (itemIndex < currentItems.length) row.push(currentItems[itemIndex]);
|
|
1677
|
-
}
|
|
1678
|
-
return {
|
|
1679
|
-
item: row,
|
|
1680
|
-
key: row.map((item, column) => extract(item, index * columns + column)).join(":"),
|
|
1681
|
-
index,
|
|
1682
|
-
isViewable
|
|
1683
|
-
};
|
|
1684
|
-
};
|
|
1685
|
-
const expand = (tokens) => {
|
|
1686
|
-
if (columns === 1) return tokens;
|
|
1687
|
-
const out = [];
|
|
1688
|
-
for (const token of tokens) token.item.forEach((item, column) => {
|
|
1689
|
-
const index = (token.index ?? 0) * columns + column;
|
|
1690
|
-
out.push({
|
|
1691
|
-
...token,
|
|
1692
|
-
item,
|
|
1693
|
-
key: extract(item, index),
|
|
1694
|
-
index
|
|
1695
|
-
});
|
|
1696
|
-
});
|
|
1697
|
-
return out;
|
|
1698
|
-
};
|
|
1699
|
-
const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
|
|
1700
|
-
const viewport = isHorizontal ? element.clientWidth : element.clientHeight;
|
|
1701
|
-
for (const entry of trackers) {
|
|
1702
|
-
const handler = entry.callback(current);
|
|
1703
|
-
if (handler == null) continue;
|
|
1704
|
-
entry.tracker.onUpdate(count, metricsAt, offset, viewport, createToken, (info) => {
|
|
1705
|
-
handler({
|
|
1706
|
-
viewableItems: expand(info.viewableItems),
|
|
1707
|
-
changed: expand(info.changed)
|
|
1708
|
-
});
|
|
1709
|
-
});
|
|
1710
|
-
}
|
|
1711
|
-
}, [metricsAt, trackers]);
|
|
1712
|
-
const handleScroll = useCallback((event) => {
|
|
1713
|
-
latest.current.onScroll?.(event);
|
|
1714
|
-
maybeCallOnEdgeReached();
|
|
1715
|
-
updateViewability();
|
|
1716
|
-
}, [maybeCallOnEdgeReached, updateViewability]);
|
|
1717
|
-
const handleContentSizeChange = useCallback((width, height) => {
|
|
1718
|
-
latest.current.onContentSizeChange?.(width, height);
|
|
1719
|
-
maybeCallOnEdgeReached();
|
|
1720
|
-
updateViewability();
|
|
1721
|
-
}, [maybeCallOnEdgeReached, updateViewability]);
|
|
1722
|
-
const handleLayout = useCallback((event) => {
|
|
1723
|
-
latest.current.onLayout?.(event);
|
|
1724
|
-
maybeCallOnEdgeReached();
|
|
1725
|
-
updateViewability();
|
|
1726
|
-
}, [maybeCallOnEdgeReached, updateViewability]);
|
|
1727
|
-
useEffect(() => {
|
|
1728
|
-
updateViewability();
|
|
1729
|
-
});
|
|
1730
|
-
const scrollToOffset = useCallback((offset, animated) => {
|
|
1731
|
-
const element = scroller.current;
|
|
1732
|
-
if (element === null) return;
|
|
1733
|
-
element.scrollTo(latest.current.horizontal === true ? {
|
|
1734
|
-
x: offset,
|
|
1735
|
-
animated
|
|
1736
|
-
} : {
|
|
1737
|
-
y: offset,
|
|
1738
|
-
animated
|
|
1739
|
-
});
|
|
1740
|
-
}, []);
|
|
1741
|
-
const scrollToIndex = useCallback((params) => {
|
|
1742
|
-
const current = latest.current;
|
|
1743
|
-
const columns = current.numColumns ?? 1;
|
|
1744
|
-
const currentItems = isArrayLike(current.data) ? current.data : [];
|
|
1745
|
-
const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
|
|
1746
|
-
const { animated, index, viewOffset, viewPosition } = params;
|
|
1747
|
-
if (index < 0) throw new Error(`scrollToIndex out of range: requested index ${index} but minimum is 0`);
|
|
1748
|
-
if (count < 1) throw new Error(`scrollToIndex out of range: item length ${count} but minimum is 1`);
|
|
1749
|
-
if (index >= count) throw new Error(`scrollToIndex out of range: requested index ${index} is out of 0 to ${count - 1}`);
|
|
1750
|
-
const frame = metricsAt(Math.floor(index));
|
|
1751
|
-
const element = scroller.current;
|
|
1752
|
-
if (frame === void 0 || element === null) {
|
|
1753
|
-
const { onScrollToIndexFailed } = current;
|
|
1754
|
-
if (onScrollToIndexFailed === void 0) throw new Error("scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed, otherwise there is no way to know the location of offscreen indices or handle failures.");
|
|
1755
|
-
onScrollToIndexFailed({
|
|
1756
|
-
index,
|
|
1757
|
-
highestMeasuredFrameIndex: -1,
|
|
1758
|
-
averageItemLength: 0
|
|
1759
|
-
});
|
|
1760
|
-
return;
|
|
1761
|
-
}
|
|
1762
|
-
const visibleLength = current.horizontal === true ? element.clientWidth : element.clientHeight;
|
|
1763
|
-
const offset = Math.max(0, frame.offset - (viewPosition ?? 0) * (visibleLength - frame.length)) - (viewOffset ?? 0);
|
|
1764
|
-
scrollToOffset(offset, animated);
|
|
1765
|
-
}, [metricsAt, scrollToOffset]);
|
|
1766
|
-
useImperativeHandle(ref, () => ({
|
|
1767
|
-
scrollToOffset: (params) => scrollToOffset(params.offset, params.animated),
|
|
1768
|
-
scrollToEnd: (params) => scroller.current?.scrollToEnd({ animated: params?.animated }),
|
|
1769
|
-
scrollToIndex,
|
|
1770
|
-
scrollToItem: ({ item, ...rest }) => {
|
|
1771
|
-
const current = latest.current;
|
|
1772
|
-
const columns = current.numColumns ?? 1;
|
|
1773
|
-
const currentItems = isArrayLike(current.data) ? current.data : [];
|
|
1774
|
-
for (let index = 0; index < currentItems.length; index++) if (currentItems[index] === item) {
|
|
1775
|
-
scrollToIndex({
|
|
1776
|
-
...rest,
|
|
1777
|
-
index: Math.floor(index / columns)
|
|
1778
|
-
});
|
|
1779
|
-
return;
|
|
1780
|
-
}
|
|
1781
|
-
},
|
|
1782
|
-
recordInteraction: () => {
|
|
1783
|
-
for (const entry of trackers) entry.tracker.recordInteraction();
|
|
1784
|
-
updateViewability();
|
|
1785
|
-
},
|
|
1786
|
-
flashScrollIndicators: () => {},
|
|
1787
|
-
getScrollResponder: () => scroller.current,
|
|
1788
|
-
getNativeScrollRef: () => scroller.current,
|
|
1789
|
-
getScrollableNode: () => scroller.current,
|
|
1790
|
-
setNativeProps: () => {}
|
|
1791
|
-
}), [
|
|
1792
|
-
scrollToIndex,
|
|
1793
|
-
scrollToOffset,
|
|
1794
|
-
trackers,
|
|
1795
|
-
updateViewability
|
|
1796
|
-
]);
|
|
1797
|
-
useLayoutEffect(() => {
|
|
1798
|
-
const index = latest.current.initialScrollIndex;
|
|
1799
|
-
const element = scroller.current;
|
|
1800
|
-
if (index == null || element === null) return;
|
|
1801
|
-
const frame = metricsAt(index);
|
|
1802
|
-
if (frame === void 0) return;
|
|
1803
|
-
if (latest.current.horizontal === true) element.scrollLeft = frame.offset;
|
|
1804
|
-
else element.scrollTop = frame.offset;
|
|
1805
|
-
}, [metricsAt]);
|
|
1806
|
-
const inversionStyle = inverted ? horizontal ? horizontallyInvertedStyle : verticallyInvertedStyle : void 0;
|
|
1807
|
-
const cellStyle = inversionStyle ? horizontal ? [rowReverseStyle, inversionStyle] : [columnReverseStyle, inversionStyle] : horizontal ? rowStyle : void 0;
|
|
1808
|
-
const renderOne = (info) => {
|
|
1809
|
-
if (ListItemComponent !== void 0) return /* @__PURE__ */ jsx(ListItemComponent, { ...info });
|
|
1810
|
-
if (renderItem != null) return renderItem(info);
|
|
1811
|
-
throw new Error("FlatList: Either ListItemComponent or renderItem props are required but none were found.");
|
|
1812
|
-
};
|
|
1813
|
-
const renderCell = (row, index, separators) => {
|
|
1814
|
-
if (numColumns === 1) return renderOne({
|
|
1815
|
-
item: row,
|
|
1816
|
-
index,
|
|
1817
|
-
separators
|
|
1818
|
-
});
|
|
1819
|
-
return /* @__PURE__ */ jsx(View, {
|
|
1820
|
-
style: [rowStyle, columnWrapperStyle],
|
|
1821
|
-
children: row.map((item, column) => {
|
|
1822
|
-
const element = renderOne({
|
|
1823
|
-
item,
|
|
1824
|
-
index: index * numColumns + column,
|
|
1825
|
-
separators
|
|
1826
|
-
});
|
|
1827
|
-
return element == null ? null : /* @__PURE__ */ jsx(Fragment, { children: element }, column);
|
|
1828
|
-
})
|
|
1829
|
-
});
|
|
1830
|
-
};
|
|
1831
|
-
const children = [];
|
|
1832
|
-
if (ListHeaderComponent != null) children.push(/* @__PURE__ */ jsx(View, {
|
|
1833
|
-
style: [inversionStyle, ListHeaderComponentStyle],
|
|
1834
|
-
children: renderListComponent(ListHeaderComponent)
|
|
1835
|
-
}, "$header"));
|
|
1836
|
-
if (rowCount === 0) {
|
|
1837
|
-
if (ListEmptyComponent != null) children.push(/* @__PURE__ */ jsx(View, {
|
|
1838
|
-
style: inversionStyle,
|
|
1839
|
-
children: renderListComponent(ListEmptyComponent)
|
|
1840
|
-
}, "$empty"));
|
|
1841
|
-
} else {
|
|
1842
|
-
let prevCellKey;
|
|
1843
|
-
for (let index = 0; index < rowCount; index++) {
|
|
1844
|
-
const row = rowAt(index);
|
|
1845
|
-
const cellKey = rowKey(row, index);
|
|
1846
|
-
children.push(/* @__PURE__ */ jsx(Cell, {
|
|
1847
|
-
cellKey,
|
|
1848
|
-
prevCellKey,
|
|
1849
|
-
index,
|
|
1850
|
-
item: row,
|
|
1851
|
-
style: cellStyle,
|
|
1852
|
-
renderCell,
|
|
1853
|
-
ItemSeparatorComponent: index < rowCount - 1 ? ItemSeparatorComponent : void 0,
|
|
1854
|
-
CellRendererComponent,
|
|
1855
|
-
separatorUpdaters,
|
|
1856
|
-
onElement
|
|
1857
|
-
}, cellKey));
|
|
1858
|
-
prevCellKey = cellKey;
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
if (ListFooterComponent != null) children.push(/* @__PURE__ */ jsx(View, {
|
|
1862
|
-
style: [inversionStyle, ListFooterComponentStyle],
|
|
1863
|
-
children: renderListComponent(ListFooterComponent)
|
|
1864
|
-
}, "$footer"));
|
|
1865
|
-
const scrollProps = {
|
|
1866
|
-
...scrollViewProps,
|
|
1867
|
-
horizontal,
|
|
1868
|
-
style: [inversionStyle, style],
|
|
1869
|
-
onScroll: handleScroll,
|
|
1870
|
-
onContentSizeChange: handleContentSizeChange,
|
|
1871
|
-
onLayout: handleLayout,
|
|
1872
|
-
children
|
|
1873
|
-
};
|
|
1874
|
-
if (renderScrollComponent !== void 0) return /* @__PURE__ */ jsx(CustomScroller, {
|
|
1875
|
-
...scrollProps,
|
|
1876
|
-
ref: scroller,
|
|
1877
|
-
render: renderScrollComponent
|
|
1878
|
-
});
|
|
1879
|
-
return /* @__PURE__ */ jsx(ScrollView, {
|
|
1880
|
-
...scrollProps,
|
|
1881
|
-
ref: scroller
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
// src/utils/warn.ts
|
|
1885
|
-
const warned = /* @__PURE__ */ new Set();
|
|
1886
|
-
const warnOnce = (key, message) => {
|
|
1887
|
-
if (isProductionEnv() || warned.has(key)) return;
|
|
1888
|
-
warned.add(key);
|
|
1889
|
-
console.warn(`[@rootnative/web] ${message}`);
|
|
1890
|
-
};
|
|
1891
|
-
// src/components/Image/source.ts
|
|
1892
|
-
const none = Object.freeze({
|
|
1893
|
-
src: void 0,
|
|
1894
|
-
srcSet: void 0,
|
|
1895
|
-
sizes: void 0,
|
|
1896
|
-
width: void 0,
|
|
1897
|
-
height: void 0,
|
|
1898
|
-
request: void 0
|
|
1899
|
-
});
|
|
1900
|
-
const ASSET_ID_WARNING = "Image: a numeric source is a Metro asset id, which has no meaning here. Import the image file and pass its URL.";
|
|
1901
|
-
const hasURI = (source) => typeof source.uri === "string" && source.uri.length > 0;
|
|
1902
|
-
const requestOf = (source) => {
|
|
1903
|
-
if (source.headers === void 0 && source.method === void 0 && source.body === void 0) return;
|
|
1904
|
-
return {
|
|
1905
|
-
method: source.method ?? "GET",
|
|
1906
|
-
headers: source.headers,
|
|
1907
|
-
body: source.body
|
|
1908
|
-
};
|
|
1909
|
-
};
|
|
1910
|
-
const single = (source) => ({
|
|
1911
|
-
src: source.uri,
|
|
1912
|
-
srcSet: void 0,
|
|
1913
|
-
sizes: void 0,
|
|
1914
|
-
width: source.width,
|
|
1915
|
-
height: source.height,
|
|
1916
|
-
request: requestOf(source)
|
|
1917
|
-
});
|
|
1918
|
-
const firstCandidate = (srcSet) => srcSet.split(",")[0]?.trim().split(/\s+/)[0];
|
|
1919
|
-
const list = (sources, layoutWidth) => {
|
|
1920
|
-
const first = sources[0];
|
|
1921
|
-
if (sources.length === 1) return single(first);
|
|
1922
|
-
if (sources.every((s) => typeof s.width === "number")) return {
|
|
1923
|
-
src: first.uri,
|
|
1924
|
-
srcSet: sources.map((s) => `${s.uri} ${s.width}w`).join(", "),
|
|
1925
|
-
sizes: layoutWidth === void 0 ? "100vw" : `${layoutWidth}px`,
|
|
1926
|
-
width: void 0,
|
|
1927
|
-
height: void 0,
|
|
1928
|
-
request: void 0
|
|
1929
|
-
};
|
|
1930
|
-
if (sources.every((s) => typeof s.scale === "number")) {
|
|
1931
|
-
const base = sources.find((s) => s.scale === 1) ?? first;
|
|
1932
|
-
return {
|
|
1933
|
-
src: base.uri,
|
|
1934
|
-
srcSet: sources.map((s) => `${s.uri} ${s.scale}x`).join(", "),
|
|
1935
|
-
sizes: void 0,
|
|
1936
|
-
width: base.width,
|
|
1937
|
-
height: base.height,
|
|
1938
|
-
request: void 0
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
return single(first);
|
|
1942
|
-
};
|
|
1943
|
-
const resolveSource = (source, src, srcSet, layoutWidth) => {
|
|
1944
|
-
if (src !== void 0 || srcSet !== void 0) return {
|
|
1945
|
-
...none,
|
|
1946
|
-
src: src ?? (srcSet === void 0 ? void 0 : firstCandidate(srcSet)),
|
|
1947
|
-
srcSet,
|
|
1948
|
-
sizes: srcSet !== void 0 && /\d+w/.test(srcSet) ? "100vw" : void 0
|
|
1949
|
-
};
|
|
1950
|
-
if (source === void 0 || source === null) return none;
|
|
1951
|
-
if (typeof source === "string") return {
|
|
1952
|
-
...none,
|
|
1953
|
-
src: source
|
|
1954
|
-
};
|
|
1955
|
-
if (typeof source === "number") {
|
|
1956
|
-
warnOnce("image-asset-id", ASSET_ID_WARNING);
|
|
1957
|
-
return none;
|
|
1958
|
-
}
|
|
1959
|
-
if (Array.isArray(source)) {
|
|
1960
|
-
const sources = source.filter(hasURI);
|
|
1961
|
-
return sources.length === 0 ? none : list(sources, layoutWidth);
|
|
1962
|
-
}
|
|
1963
|
-
return hasURI(source) ? single(source) : none;
|
|
1964
|
-
};
|
|
1965
|
-
const resolveAssetSource = (source) => {
|
|
1966
|
-
if (typeof source === "string") return {
|
|
1967
|
-
uri: source,
|
|
1968
|
-
scale: 1
|
|
1969
|
-
};
|
|
1970
|
-
if (typeof source === "number") {
|
|
1971
|
-
warnOnce("image-asset-id", ASSET_ID_WARNING);
|
|
1972
|
-
return null;
|
|
1973
|
-
}
|
|
1974
|
-
const first = Array.isArray(source) ? source[0] : source;
|
|
1975
|
-
if (first === void 0 || first === null || !hasURI(first)) return null;
|
|
1976
|
-
const { uri, width, height, scale } = first;
|
|
1977
|
-
return {
|
|
1978
|
-
uri,
|
|
1979
|
-
width,
|
|
1980
|
-
height,
|
|
1981
|
-
scale: scale ?? 1
|
|
1982
|
-
};
|
|
1983
|
-
};
|
|
1984
|
-
// src/components/Image/index.tsx
|
|
1985
|
-
const boxStyle = Object.freeze({
|
|
1986
|
-
backgroundColor: "transparent",
|
|
1987
|
-
border: "0 solid black",
|
|
1988
|
-
boxSizing: "border-box",
|
|
1989
|
-
display: "flex",
|
|
1990
|
-
flexBasis: "auto",
|
|
1991
|
-
flexDirection: "column",
|
|
1992
|
-
flexShrink: 0,
|
|
1993
|
-
margin: 0,
|
|
1994
|
-
minHeight: 0,
|
|
1995
|
-
minWidth: 0,
|
|
1996
|
-
overflow: "hidden",
|
|
1997
|
-
padding: 0,
|
|
1998
|
-
position: "relative",
|
|
1999
|
-
zIndex: 0
|
|
2000
|
-
});
|
|
2001
|
-
const fillStyle = Object.freeze({
|
|
2002
|
-
position: "absolute",
|
|
2003
|
-
left: 0,
|
|
2004
|
-
top: 0,
|
|
2005
|
-
width: "100%",
|
|
2006
|
-
height: "100%",
|
|
2007
|
-
display: "block",
|
|
2008
|
-
border: 0,
|
|
2009
|
-
margin: 0,
|
|
2010
|
-
padding: 0
|
|
2011
|
-
});
|
|
2012
|
-
const hiddenStyle = Object.freeze({ visibility: "hidden" });
|
|
2013
|
-
const objectFitOf = {
|
|
2014
|
-
cover: "cover",
|
|
2015
|
-
contain: "contain",
|
|
2016
|
-
stretch: "fill",
|
|
2017
|
-
center: "none",
|
|
2018
|
-
repeat: "none"
|
|
2019
|
-
};
|
|
2020
|
-
const resizeModeOfObjectFit = {
|
|
2021
|
-
cover: "cover",
|
|
2022
|
-
contain: "contain",
|
|
2023
|
-
fill: "stretch",
|
|
2024
|
-
"scale-down": "contain",
|
|
2025
|
-
none: "center"
|
|
2026
|
-
};
|
|
2027
|
-
const maskSizeOf = {
|
|
2028
|
-
cover: "cover",
|
|
2029
|
-
contain: "contain",
|
|
2030
|
-
stretch: "100% 100%",
|
|
2031
|
-
center: "auto",
|
|
2032
|
-
repeat: "auto"
|
|
2033
|
-
};
|
|
2034
|
-
const cssURL = (url) => `url("${url.replace(/["\\]/g, "\\$&")}")`;
|
|
2035
|
-
const loadError = (uri) => `Failed to load image: ${uri ?? ""}`;
|
|
2036
|
-
const sizeOf = (img) => ({
|
|
2037
|
-
width: img.naturalWidth,
|
|
2038
|
-
height: img.naturalHeight
|
|
2039
|
-
});
|
|
2040
|
-
const placeholderURI = (source) => {
|
|
2041
|
-
if (typeof source === "string") return source;
|
|
2042
|
-
if (typeof source === "object" && source !== null) return source.uri;
|
|
2043
|
-
};
|
|
2044
|
-
const useRequestURL = (uri, request) => {
|
|
2045
|
-
const [state, setState] = useState({
|
|
2046
|
-
uri: void 0,
|
|
2047
|
-
url: void 0,
|
|
2048
|
-
error: void 0
|
|
2049
|
-
});
|
|
2050
|
-
const requestKey = request === void 0 ? void 0 : JSON.stringify(request);
|
|
2051
|
-
useEffect(() => {
|
|
2052
|
-
if (uri === void 0 || requestKey === void 0) return;
|
|
2053
|
-
const { method, headers, body } = JSON.parse(requestKey);
|
|
2054
|
-
const controller = new AbortController();
|
|
2055
|
-
let objectURL;
|
|
2056
|
-
const init = {
|
|
2057
|
-
method,
|
|
2058
|
-
signal: controller.signal
|
|
2059
|
-
};
|
|
2060
|
-
if (headers !== void 0) init.headers = headers;
|
|
2061
|
-
if (body !== void 0) init.body = body;
|
|
2062
|
-
fetch(uri, init).then((response) => {
|
|
2063
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
2064
|
-
return response.blob();
|
|
2065
|
-
}).then((blob) => {
|
|
2066
|
-
objectURL = URL.createObjectURL(blob);
|
|
2067
|
-
setState({
|
|
2068
|
-
uri,
|
|
2069
|
-
url: objectURL,
|
|
2070
|
-
error: void 0
|
|
2071
|
-
});
|
|
2072
|
-
}).catch((error) => {
|
|
2073
|
-
if (controller.signal.aborted) return;
|
|
2074
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2075
|
-
setState({
|
|
2076
|
-
uri,
|
|
2077
|
-
url: void 0,
|
|
2078
|
-
error: `${loadError(uri)} (${message})`
|
|
2079
|
-
});
|
|
2080
|
-
});
|
|
2081
|
-
return () => {
|
|
2082
|
-
controller.abort();
|
|
2083
|
-
if (objectURL !== void 0) URL.revokeObjectURL(objectURL);
|
|
2084
|
-
};
|
|
2085
|
-
}, [uri, requestKey]);
|
|
2086
|
-
return state.uri === uri ? state : {
|
|
2087
|
-
url: void 0,
|
|
2088
|
-
error: void 0
|
|
2089
|
-
};
|
|
2090
|
-
};
|
|
2091
|
-
function ImageComponent(props) {
|
|
2092
|
-
const { alt, blurRadius, crossOrigin, decoding, defaultSource, fetchPriority, height, loading, onError, onLayout, onLoad, onLoadEnd, onLoadStart, ref, referrerPolicy, resizeMode: resizeModeProp, source, src, srcSet, style, tintColor: tintColorProp, width, fadeDuration: _fadeDuration, loadingIndicatorSource: _loadingIndicatorSource, onProgress: _onProgress, progressiveRenderingEnabled: _progressiveRenderingEnabled, resizeMethod: _resizeMethod, ...rest } = props;
|
|
2093
|
-
const element = useRef(null);
|
|
2094
|
-
const img = useRef(null);
|
|
2095
|
-
useImperativeHandle(ref, () => element.current, []);
|
|
2096
|
-
useElementLayout(element, onLayout);
|
|
2097
|
-
const registry = useStyleRegistry();
|
|
2098
|
-
const { resizeMode: styleResizeMode, objectFit, tintColor: styleTintColor, overlayColor: _overlayColor, ...userBoxStyle } = flattenStyle(style) ?? {};
|
|
2099
|
-
const resizeMode = (typeof objectFit === "string" ? resizeModeOfObjectFit[objectFit] : void 0) ?? resizeModeProp ?? styleResizeMode ?? "cover";
|
|
2100
|
-
const tintColor = tintColorProp ?? styleTintColor;
|
|
2101
|
-
const painted = resizeMode === "repeat" || tintColor !== void 0;
|
|
2102
|
-
const styleWidth = userBoxStyle["width"] ?? width;
|
|
2103
|
-
const resolved = resolveSource(source, src, srcSet, typeof styleWidth === "number" ? styleWidth : void 0);
|
|
2104
|
-
const requested = useRequestURL(resolved.src, resolved.request);
|
|
2105
|
-
const currentSrc = resolved.request === void 0 ? resolved.src : requested.url;
|
|
2106
|
-
const handlers = useRef({
|
|
2107
|
-
onLoad,
|
|
2108
|
-
onLoadStart,
|
|
2109
|
-
onLoadEnd,
|
|
2110
|
-
onError
|
|
2111
|
-
});
|
|
2112
|
-
useEffect(() => {
|
|
2113
|
-
handlers.current = {
|
|
2114
|
-
onLoad,
|
|
2115
|
-
onLoadStart,
|
|
2116
|
-
onLoadEnd,
|
|
2117
|
-
onError
|
|
2118
|
-
};
|
|
2119
|
-
});
|
|
2120
|
-
const [loadedSrc, setLoadedSrc] = useState(void 0);
|
|
2121
|
-
const firedFor = useRef(void 0);
|
|
2122
|
-
useEffect(() => {
|
|
2123
|
-
if (resolved.src === void 0) return;
|
|
2124
|
-
firedFor.current = void 0;
|
|
2125
|
-
handlers.current.onLoadStart?.();
|
|
2126
|
-
}, [resolved.src]);
|
|
2127
|
-
const fireLoad = useCallback((target) => {
|
|
2128
|
-
const uri = target.currentSrc || target.src;
|
|
2129
|
-
if (firedFor.current === uri) return;
|
|
2130
|
-
firedFor.current = uri;
|
|
2131
|
-
setLoadedSrc(target.src);
|
|
2132
|
-
const { width: naturalWidth, height: naturalHeight } = sizeOf(target);
|
|
2133
|
-
handlers.current.onLoad?.({ nativeEvent: { source: {
|
|
2134
|
-
uri,
|
|
2135
|
-
width: naturalWidth,
|
|
2136
|
-
height: naturalHeight
|
|
2137
|
-
} } });
|
|
2138
|
-
handlers.current.onLoadEnd?.();
|
|
2139
|
-
}, []);
|
|
2140
|
-
const fireError = useCallback((target) => {
|
|
2141
|
-
const uri = target.currentSrc || target.src;
|
|
2142
|
-
if (firedFor.current === uri) return;
|
|
2143
|
-
firedFor.current = uri;
|
|
2144
|
-
handlers.current.onError?.({ nativeEvent: { error: loadError(uri) } });
|
|
2145
|
-
handlers.current.onLoadEnd?.();
|
|
2146
|
-
}, []);
|
|
2147
|
-
const handleLoad = useCallback((event) => fireLoad(event.currentTarget), [fireLoad]);
|
|
2148
|
-
const handleError = useCallback((event) => fireError(event.currentTarget), [fireError]);
|
|
2149
|
-
useEffect(() => {
|
|
2150
|
-
const target = img.current;
|
|
2151
|
-
if (target === null || currentSrc === void 0 || !target.complete) return;
|
|
2152
|
-
if (target.naturalWidth > 0) fireLoad(target);
|
|
2153
|
-
else fireError(target);
|
|
2154
|
-
});
|
|
2155
|
-
const requestError = requested.error;
|
|
2156
|
-
useEffect(() => {
|
|
2157
|
-
if (requestError === void 0) return;
|
|
2158
|
-
if (firedFor.current === resolved.src) return;
|
|
2159
|
-
firedFor.current = resolved.src;
|
|
2160
|
-
handlers.current.onError?.({ nativeEvent: { error: requestError } });
|
|
2161
|
-
handlers.current.onLoadEnd?.();
|
|
2162
|
-
}, [requestError, resolved.src]);
|
|
2163
|
-
const { tag, role } = resolveTag(rest, "div", true);
|
|
2164
|
-
const sizeStyle = {
|
|
2165
|
-
width: userBoxStyle["width"] ?? width ?? resolved.width,
|
|
2166
|
-
height: userBoxStyle["height"] ?? height ?? resolved.height
|
|
2167
|
-
};
|
|
2168
|
-
const boxClassName = compileStyle([
|
|
2169
|
-
boxStyle,
|
|
2170
|
-
sizeStyle,
|
|
2171
|
-
userBoxStyle
|
|
2172
|
-
], registry);
|
|
2173
|
-
const label = alt ?? rest.accessibilityLabel ?? rest["aria-label"];
|
|
2174
|
-
const domProps = toDOMProps(rest);
|
|
2175
|
-
domProps["className"] = boxClassName;
|
|
2176
|
-
domProps["ref"] = element;
|
|
2177
|
-
if (role !== void 0) domProps["role"] = role;
|
|
2178
|
-
else if (painted && label !== void 0 && label !== "") {
|
|
2179
|
-
domProps["role"] = "img";
|
|
2180
|
-
domProps["aria-label"] = label;
|
|
2181
|
-
}
|
|
2182
|
-
const imgStyle = {
|
|
2183
|
-
objectFit: objectFitOf[resizeMode],
|
|
2184
|
-
filter: blurRadius !== void 0 && blurRadius > 0 ? `blur(${blurRadius}px)` : void 0
|
|
2185
|
-
};
|
|
2186
|
-
const placeholder = placeholderURI(defaultSource);
|
|
2187
|
-
const showPlaceholder = placeholder !== void 0 && (currentSrc === void 0 || loadedSrc !== currentSrc);
|
|
2188
|
-
let paintStyle;
|
|
2189
|
-
if (painted && currentSrc !== void 0) {
|
|
2190
|
-
const url = cssURL(currentSrc);
|
|
2191
|
-
const repeat = resizeMode === "repeat" ? "repeat" : "no-repeat";
|
|
2192
|
-
paintStyle = tintColor === void 0 ? {
|
|
2193
|
-
backgroundImage: url,
|
|
2194
|
-
backgroundRepeat: repeat,
|
|
2195
|
-
backgroundPosition: "center",
|
|
2196
|
-
backgroundSize: "auto"
|
|
2197
|
-
} : {
|
|
2198
|
-
backgroundColor: tintColor,
|
|
2199
|
-
WebkitMaskImage: url,
|
|
2200
|
-
maskImage: url,
|
|
2201
|
-
WebkitMaskRepeat: repeat,
|
|
2202
|
-
maskRepeat: repeat,
|
|
2203
|
-
WebkitMaskPosition: "center",
|
|
2204
|
-
maskPosition: "center",
|
|
2205
|
-
WebkitMaskSize: maskSizeOf[resizeMode],
|
|
2206
|
-
maskSize: maskSizeOf[resizeMode]
|
|
2207
|
-
};
|
|
2208
|
-
}
|
|
2209
|
-
const children = [/* @__PURE__ */ jsx("img", {
|
|
2210
|
-
ref: img,
|
|
2211
|
-
src: currentSrc,
|
|
2212
|
-
srcSet: resolved.srcSet,
|
|
2213
|
-
sizes: resolved.sizes,
|
|
2214
|
-
alt: painted ? "" : label ?? "",
|
|
2215
|
-
"aria-hidden": painted ? true : void 0,
|
|
2216
|
-
draggable: false,
|
|
2217
|
-
crossOrigin,
|
|
2218
|
-
referrerPolicy,
|
|
2219
|
-
loading,
|
|
2220
|
-
fetchPriority,
|
|
2221
|
-
decoding,
|
|
2222
|
-
onLoad: handleLoad,
|
|
2223
|
-
onError: handleError,
|
|
2224
|
-
className: compileStyle([
|
|
2225
|
-
fillStyle,
|
|
2226
|
-
imgStyle,
|
|
2227
|
-
painted && hiddenStyle
|
|
2228
|
-
], registry)
|
|
2229
|
-
}, "img")];
|
|
2230
|
-
if (showPlaceholder) children.unshift(/* @__PURE__ */ jsx("img", {
|
|
2231
|
-
src: placeholder,
|
|
2232
|
-
alt: "",
|
|
2233
|
-
"aria-hidden": true,
|
|
2234
|
-
draggable: false,
|
|
2235
|
-
className: compileStyle([fillStyle, imgStyle], registry)
|
|
2236
|
-
}, "placeholder"));
|
|
2237
|
-
if (paintStyle !== void 0) children.push(/* @__PURE__ */ jsx("div", {
|
|
2238
|
-
"aria-hidden": true,
|
|
2239
|
-
className: compileStyle([fillStyle, paintStyle], registry)
|
|
2240
|
-
}, "paint"));
|
|
2241
|
-
return createElement(tag, domProps, ...children);
|
|
2242
|
-
}
|
|
2243
|
-
const loadSize = (uri) => new Promise((resolve, reject) => {
|
|
2244
|
-
if (!hasDOM()) {
|
|
2245
|
-
reject(/* @__PURE__ */ new Error("Image.getSize needs a DOM"));
|
|
2246
|
-
return;
|
|
2247
|
-
}
|
|
2248
|
-
const probe = document.createElement("img");
|
|
2249
|
-
probe.addEventListener("load", () => resolve(sizeOf(probe)), { once: true });
|
|
2250
|
-
probe.addEventListener("error", () => reject(new Error(loadError(uri))), { once: true });
|
|
2251
|
-
probe.src = uri;
|
|
2252
|
-
});
|
|
2253
|
-
const fetchObjectURL = async (uri, headers) => {
|
|
2254
|
-
const response = await fetch(uri, { headers });
|
|
2255
|
-
if (!response.ok) throw new Error(`${loadError(uri)} (HTTP ${response.status})`);
|
|
2256
|
-
return URL.createObjectURL(await response.blob());
|
|
2257
|
-
};
|
|
2258
|
-
const withCallbacks = (promise, success, failure) => {
|
|
2259
|
-
if (success === void 0) return promise;
|
|
2260
|
-
promise.then((size) => success(size.width, size.height), (error) => failure?.(error));
|
|
2261
|
-
};
|
|
2262
|
-
function getSize(uri, success, failure) {
|
|
2263
|
-
return withCallbacks(loadSize(uri), success, failure);
|
|
2264
|
-
}
|
|
2265
|
-
function getSizeWithHeaders(uri, headers, success, failure) {
|
|
2266
|
-
const promise = fetchObjectURL(uri, headers).then((url) => loadSize(url).finally(() => URL.revokeObjectURL(url)));
|
|
2267
|
-
return withCallbacks(promise, success, failure);
|
|
2268
|
-
}
|
|
2269
|
-
const Image = Object.assign(ImageComponent, {
|
|
2270
|
-
getSize,
|
|
2271
|
-
getSizeWithHeaders,
|
|
2272
|
-
prefetch: (url) => loadSize(url).then(() => true),
|
|
2273
|
-
queryCache: () => Promise.resolve({}),
|
|
2274
|
-
resolveAssetSource
|
|
2275
|
-
});
|
|
2276
|
-
// src/events/responderEvent.ts
|
|
2277
|
-
const hasPoint = (event) => event.clientX !== void 0 && !(event.type === "click" && event.detail === 0);
|
|
2278
|
-
const activeTypes = /* @__PURE__ */ new Set([
|
|
2279
|
-
"pointerdown",
|
|
2280
|
-
"pointermove",
|
|
2281
|
-
"keydown"
|
|
2282
|
-
]);
|
|
2283
|
-
const define = (target, fields) => {
|
|
2284
|
-
for (const key in fields) {
|
|
2285
|
-
if (key in target) continue;
|
|
2286
|
-
Object.defineProperty(target, key, {
|
|
2287
|
-
value: fields[key],
|
|
2288
|
-
configurable: true
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
const toGestureResponderEvent = (event, element) => {
|
|
2293
|
-
const native = event.nativeEvent;
|
|
2294
|
-
if (!("locationX" in native)) {
|
|
2295
|
-
const rect = element.getBoundingClientRect();
|
|
2296
|
-
const point = hasPoint(native);
|
|
2297
|
-
const clientX = point ? native.clientX ?? 0 : rect.left + rect.width / 2;
|
|
2298
|
-
const clientY = point ? native.clientY ?? 0 : rect.top + rect.height / 2;
|
|
2299
|
-
const touch = {
|
|
2300
|
-
changedTouches: [],
|
|
2301
|
-
force: native.pressure,
|
|
2302
|
-
identifier: native.pointerId ?? 0,
|
|
2303
|
-
locationX: clientX - rect.left,
|
|
2304
|
-
locationY: clientY - rect.top,
|
|
2305
|
-
pageX: clientX + window.scrollX,
|
|
2306
|
-
pageY: clientY + window.scrollY,
|
|
2307
|
-
target: native.target,
|
|
2308
|
-
timestamp: event.timeStamp,
|
|
2309
|
-
touches: []
|
|
2310
|
-
};
|
|
2311
|
-
define(native, {
|
|
2312
|
-
...touch,
|
|
2313
|
-
changedTouches: [touch],
|
|
2314
|
-
touches: activeTypes.has(native.type) ? [touch] : []
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
return event;
|
|
2318
|
-
};
|
|
2319
|
-
const toMouseEvent = (event) => {
|
|
2320
|
-
define(event.nativeEvent, { timestamp: event.timeStamp });
|
|
2321
|
-
return event;
|
|
2322
|
-
};
|
|
2323
|
-
// src/events/press/Pressability.ts
|
|
2324
|
-
const transitions = {
|
|
2325
|
-
NOT_RESPONDER: { RESPONDER_GRANT: "RESPONDER_INACTIVE_PRESS_IN" },
|
|
2326
|
-
RESPONDER_INACTIVE_PRESS_IN: {
|
|
2327
|
-
DELAY: "RESPONDER_ACTIVE_PRESS_IN",
|
|
2328
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2329
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2330
|
-
ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
|
|
2331
|
-
LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
|
|
2332
|
-
},
|
|
2333
|
-
RESPONDER_INACTIVE_PRESS_OUT: {
|
|
2334
|
-
DELAY: "RESPONDER_ACTIVE_PRESS_OUT",
|
|
2335
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2336
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2337
|
-
ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
|
|
2338
|
-
LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
|
|
2339
|
-
},
|
|
2340
|
-
RESPONDER_ACTIVE_PRESS_IN: {
|
|
2341
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2342
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2343
|
-
ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
|
|
2344
|
-
LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT",
|
|
2345
|
-
LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
|
|
2346
|
-
},
|
|
2347
|
-
RESPONDER_ACTIVE_PRESS_OUT: {
|
|
2348
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2349
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2350
|
-
ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
|
|
2351
|
-
LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT"
|
|
2352
|
-
},
|
|
2353
|
-
RESPONDER_ACTIVE_LONG_PRESS_IN: {
|
|
2354
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2355
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2356
|
-
ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
|
|
2357
|
-
LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT",
|
|
2358
|
-
LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
|
|
2359
|
-
},
|
|
2360
|
-
RESPONDER_ACTIVE_LONG_PRESS_OUT: {
|
|
2361
|
-
RESPONDER_RELEASE: "NOT_RESPONDER",
|
|
2362
|
-
RESPONDER_TERMINATED: "NOT_RESPONDER",
|
|
2363
|
-
ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
|
|
2364
|
-
LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT"
|
|
2365
|
-
}
|
|
2366
|
-
};
|
|
2367
|
-
const isActive = (state) => state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
|
|
2368
|
-
const isActivation = (state) => state === "RESPONDER_ACTIVE_PRESS_OUT" || state === "RESPONDER_ACTIVE_PRESS_IN";
|
|
2369
|
-
const isPressIn = (state) => state === "RESPONDER_INACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
|
|
2370
|
-
const isTerminal = (signal) => signal === "RESPONDER_TERMINATED" || signal === "RESPONDER_RELEASE";
|
|
2371
|
-
const DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
2372
|
-
const DEFAULT_MIN_PRESS_DURATION = 130;
|
|
2373
|
-
const DEFAULT_PRESS_RECT_OFFSETS = {
|
|
2374
|
-
bottom: 30,
|
|
2375
|
-
left: 20,
|
|
2376
|
-
right: 20,
|
|
2377
|
-
top: 20
|
|
2378
|
-
};
|
|
2379
|
-
let longPressDeactivationDistance = 10;
|
|
2380
|
-
const normalizeDelay = (delay, min = 0, fallback = 0) => Math.max(min, delay ?? fallback);
|
|
2381
|
-
const normalizeRect = (rect) => typeof rect === "number" ? {
|
|
2382
|
-
bottom: rect,
|
|
2383
|
-
left: rect,
|
|
2384
|
-
right: rect,
|
|
2385
|
-
top: rect
|
|
2386
|
-
} : rect;
|
|
2387
|
-
const claimed = /* @__PURE__ */ new WeakSet();
|
|
2388
|
-
const isActivationKey = (key) => key === "Enter" || key === " ";
|
|
2389
|
-
const hasNativeActivation = (element) => {
|
|
2390
|
-
switch (element.tagName) {
|
|
2391
|
-
case "BUTTON":
|
|
2392
|
-
case "INPUT":
|
|
2393
|
-
case "SELECT":
|
|
2394
|
-
case "SUMMARY":
|
|
2395
|
-
case "TEXTAREA": return true;
|
|
2396
|
-
case "A":
|
|
2397
|
-
case "AREA": return element.hasAttribute("href");
|
|
2398
|
-
default: return element.isContentEditable;
|
|
2399
|
-
}
|
|
2400
|
-
};
|
|
2401
|
-
const nativeControl = "a[href],area[href],audio[controls],button,input,select,summary,textarea,video[controls],[contenteditable]:not([contenteditable=\"false\"])";
|
|
2402
|
-
const startsInNativeControl = (event) => {
|
|
2403
|
-
const { currentTarget, target } = event;
|
|
2404
|
-
if (!(target instanceof Element)) return false;
|
|
2405
|
-
const control = target.closest(nativeControl);
|
|
2406
|
-
return control !== null && control !== currentTarget && currentTarget.contains(control);
|
|
2407
|
-
};
|
|
2408
|
-
const clear = (timer) => {
|
|
2409
|
-
if (timer !== null) clearTimeout(timer);
|
|
2410
|
-
return null;
|
|
2411
|
-
};
|
|
2412
|
-
var Pressability = class {
|
|
2413
|
-
constructor(config) {
|
|
2414
|
-
this.state = "NOT_RESPONDER";
|
|
2415
|
-
this.element = null;
|
|
2416
|
-
this.region = null;
|
|
2417
|
-
this.pointerId = null;
|
|
2418
|
-
this.key = null;
|
|
2419
|
-
this.activatePosition = null;
|
|
2420
|
-
this.activateTime = null;
|
|
2421
|
-
this.hovered = false;
|
|
2422
|
-
this.pointerClickPending = false;
|
|
2423
|
-
this.cancelClick = false;
|
|
2424
|
-
this.hoverInTimer = null;
|
|
2425
|
-
this.hoverOutTimer = null;
|
|
2426
|
-
this.longPressTimer = null;
|
|
2427
|
-
this.pressDelayTimer = null;
|
|
2428
|
-
this.pressOutTimer = null;
|
|
2429
|
-
this.config = config;
|
|
2430
|
-
this.handlers = this.createEventHandlers();
|
|
2431
|
-
}
|
|
2432
|
-
configure(config) {
|
|
2433
|
-
this.config = config;
|
|
2434
|
-
}
|
|
2435
|
-
reset() {
|
|
2436
|
-
this.hoverInTimer = clear(this.hoverInTimer);
|
|
2437
|
-
this.hoverOutTimer = clear(this.hoverOutTimer);
|
|
2438
|
-
this.longPressTimer = clear(this.longPressTimer);
|
|
2439
|
-
this.pressDelayTimer = clear(this.pressDelayTimer);
|
|
2440
|
-
this.pressOutTimer = clear(this.pressOutTimer);
|
|
2441
|
-
this.config = Object.freeze({});
|
|
2442
|
-
}
|
|
2443
|
-
getEventHandlers() {
|
|
2444
|
-
return this.handlers;
|
|
2445
|
-
}
|
|
2446
|
-
static setLongPressDeactivationDistance(distance) {
|
|
2447
|
-
longPressDeactivationDistance = distance;
|
|
2448
|
-
}
|
|
2449
|
-
createEventHandlers() {
|
|
2450
|
-
return {
|
|
2451
|
-
onPointerDown: (event) => {
|
|
2452
|
-
const native = event.nativeEvent;
|
|
2453
|
-
if (event.button !== 0 || claimed.has(native) || this.config.disabled === true) return;
|
|
2454
|
-
if (startsInNativeControl(event)) return;
|
|
2455
|
-
claimed.add(native);
|
|
2456
|
-
if (this.pointerId !== null || this.key !== null) return;
|
|
2457
|
-
const element = event.currentTarget;
|
|
2458
|
-
this.pointerId = event.pointerId;
|
|
2459
|
-
this.pointerClickPending = true;
|
|
2460
|
-
try {
|
|
2461
|
-
element.setPointerCapture(event.pointerId);
|
|
2462
|
-
} catch {}
|
|
2463
|
-
this.grant(element, toGestureResponderEvent(event, element));
|
|
2464
|
-
},
|
|
2465
|
-
onPointerMove: (event) => {
|
|
2466
|
-
const element = this.element;
|
|
2467
|
-
if (event.pointerId !== this.pointerId || element === null) return;
|
|
2468
|
-
const pressEvent = toGestureResponderEvent(event, element);
|
|
2469
|
-
this.config.onPressMove?.(pressEvent);
|
|
2470
|
-
const region = this.region;
|
|
2471
|
-
if (region === null) return;
|
|
2472
|
-
const { pageX, pageY } = pressEvent.nativeEvent;
|
|
2473
|
-
const start = this.activatePosition;
|
|
2474
|
-
if (start !== null && Math.hypot(start.pageX - pageX, start.pageY - pageY) > longPressDeactivationDistance) this.longPressTimer = clear(this.longPressTimer);
|
|
2475
|
-
if (this.isWithinRegion(pageX, pageY, region)) this.receiveSignal("ENTER_PRESS_RECT", pressEvent);
|
|
2476
|
-
else {
|
|
2477
|
-
this.longPressTimer = clear(this.longPressTimer);
|
|
2478
|
-
this.receiveSignal("LEAVE_PRESS_RECT", pressEvent);
|
|
2479
|
-
}
|
|
2480
|
-
},
|
|
2481
|
-
onPointerUp: (event) => {
|
|
2482
|
-
const element = this.element;
|
|
2483
|
-
if (event.pointerId !== this.pointerId || element === null) return;
|
|
2484
|
-
this.pointerId = null;
|
|
2485
|
-
this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
|
|
2486
|
-
},
|
|
2487
|
-
onPointerCancel: (event) => {
|
|
2488
|
-
const element = this.element;
|
|
2489
|
-
if (event.pointerId !== this.pointerId || element === null) return;
|
|
2490
|
-
this.pointerId = null;
|
|
2491
|
-
this.pointerClickPending = false;
|
|
2492
|
-
this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
|
|
2493
|
-
},
|
|
2494
|
-
onClick: (event) => {
|
|
2495
|
-
const native = event.nativeEvent;
|
|
2496
|
-
if (claimed.has(native) || startsInNativeControl(event)) return;
|
|
2497
|
-
if (this.pointerClickPending && event.detail > 0) {
|
|
2498
|
-
this.pointerClickPending = false;
|
|
2499
|
-
claimed.add(native);
|
|
2500
|
-
if (this.cancelClick) event.preventDefault();
|
|
2501
|
-
return;
|
|
2502
|
-
}
|
|
2503
|
-
if (this.config.disabled === true) return;
|
|
2504
|
-
claimed.add(native);
|
|
2505
|
-
this.config.onPress?.(toGestureResponderEvent(event, event.currentTarget));
|
|
2506
|
-
},
|
|
2507
|
-
onKeyDown: (event) => {
|
|
2508
|
-
if (!isActivationKey(event.key) || event.repeat || event.nativeEvent.isComposing) return;
|
|
2509
|
-
const element = event.currentTarget;
|
|
2510
|
-
if (event.target !== element || this.config.disabled === true) return;
|
|
2511
|
-
if (hasNativeActivation(element)) return;
|
|
2512
|
-
if (event.key === " ") event.preventDefault();
|
|
2513
|
-
if (this.pointerId !== null || this.key !== null) return;
|
|
2514
|
-
this.key = event.key;
|
|
2515
|
-
this.grant(element, toGestureResponderEvent(event, element));
|
|
2516
|
-
},
|
|
2517
|
-
onKeyUp: (event) => {
|
|
2518
|
-
const element = this.element;
|
|
2519
|
-
if (event.key !== this.key || element === null) return;
|
|
2520
|
-
this.key = null;
|
|
2521
|
-
this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
|
|
2522
|
-
},
|
|
2523
|
-
onFocus: (event) => {
|
|
2524
|
-
this.config.onFocus?.(event);
|
|
2525
|
-
},
|
|
2526
|
-
onBlur: (event) => {
|
|
2527
|
-
const element = this.element;
|
|
2528
|
-
if (this.key !== null && element !== null && event.target === event.currentTarget) {
|
|
2529
|
-
this.key = null;
|
|
2530
|
-
this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
|
|
2531
|
-
}
|
|
2532
|
-
this.config.onBlur?.(event);
|
|
2533
|
-
},
|
|
2534
|
-
onPointerEnter: (event) => {
|
|
2535
|
-
if (event.pointerType === "touch") return;
|
|
2536
|
-
this.hovered = true;
|
|
2537
|
-
this.hoverOutTimer = clear(this.hoverOutTimer);
|
|
2538
|
-
this.hover(event, this.config.onHoverIn, this.config.delayHoverIn, "in");
|
|
2539
|
-
},
|
|
2540
|
-
onPointerLeave: (event) => {
|
|
2541
|
-
if (!this.hovered) return;
|
|
2542
|
-
this.hovered = false;
|
|
2543
|
-
this.hoverInTimer = clear(this.hoverInTimer);
|
|
2544
|
-
this.hover(event, this.config.onHoverOut, this.config.delayHoverOut, "out");
|
|
2545
|
-
},
|
|
2546
|
-
onContextMenu: (event) => {
|
|
2547
|
-
if (this.pointerId !== null && this.config.onLongPress != null) event.preventDefault();
|
|
2548
|
-
}
|
|
2549
|
-
};
|
|
2550
|
-
}
|
|
2551
|
-
hover(event, callback, delay, direction) {
|
|
2552
|
-
if (callback == null) return;
|
|
2553
|
-
const hoverEvent = toMouseEvent(event);
|
|
2554
|
-
const wait = normalizeDelay(delay);
|
|
2555
|
-
if (wait === 0) {
|
|
2556
|
-
callback(hoverEvent);
|
|
2557
|
-
return;
|
|
2558
|
-
}
|
|
2559
|
-
const timer = setTimeout(() => callback(hoverEvent), wait);
|
|
2560
|
-
if (direction === "in") this.hoverInTimer = timer;
|
|
2561
|
-
else this.hoverOutTimer = timer;
|
|
2562
|
-
}
|
|
2563
|
-
grant(element, event) {
|
|
2564
|
-
this.pressOutTimer = clear(this.pressOutTimer);
|
|
2565
|
-
this.element = element;
|
|
2566
|
-
this.cancelClick = false;
|
|
2567
|
-
this.state = "NOT_RESPONDER";
|
|
2568
|
-
this.receiveSignal("RESPONDER_GRANT", event);
|
|
2569
|
-
const delayPressIn = normalizeDelay(this.config.delayPressIn);
|
|
2570
|
-
if (delayPressIn > 0) this.pressDelayTimer = setTimeout(() => this.receiveSignal("DELAY", event), delayPressIn);
|
|
2571
|
-
else this.receiveSignal("DELAY", event);
|
|
2572
|
-
const delayLongPress = normalizeDelay(this.config.delayLongPress, 10, DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn);
|
|
2573
|
-
this.longPressTimer = setTimeout(() => {
|
|
2574
|
-
if (this.state === "RESPONDER_ACTIVE_PRESS_IN" || this.state === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.receiveSignal("LONG_PRESS_DETECTED", event);
|
|
2575
|
-
}, delayLongPress + delayPressIn);
|
|
2576
|
-
}
|
|
2577
|
-
receiveSignal(signal, event) {
|
|
2578
|
-
const prevState = this.state;
|
|
2579
|
-
const nextState = transitions[prevState][signal];
|
|
2580
|
-
if (nextState === void 0 || nextState === prevState) return;
|
|
2581
|
-
this.performTransitionSideEffects(prevState, nextState, signal, event);
|
|
2582
|
-
this.state = nextState;
|
|
2583
|
-
}
|
|
2584
|
-
performTransitionSideEffects(prevState, nextState, signal, event) {
|
|
2585
|
-
if (isTerminal(signal)) {
|
|
2586
|
-
this.activatePosition = null;
|
|
2587
|
-
this.longPressTimer = clear(this.longPressTimer);
|
|
2588
|
-
}
|
|
2589
|
-
const isInitialTransition = prevState === "NOT_RESPONDER" && nextState === "RESPONDER_INACTIVE_PRESS_IN";
|
|
2590
|
-
const isActivationTransition = !isActivation(prevState) && isActivation(nextState);
|
|
2591
|
-
if (isInitialTransition || isActivationTransition) this.measureRegion();
|
|
2592
|
-
if (isPressIn(prevState) && signal === "LONG_PRESS_DETECTED") this.config.onLongPress?.(event);
|
|
2593
|
-
const isPrevActive = isActive(prevState);
|
|
2594
|
-
const isNextActive = isActive(nextState);
|
|
2595
|
-
if (!isPrevActive && isNextActive) this.activate(event);
|
|
2596
|
-
else if (isPrevActive && !isNextActive) this.deactivate(event);
|
|
2597
|
-
if (isPressIn(prevState) && signal === "RESPONDER_RELEASE") {
|
|
2598
|
-
if (!isNextActive && !isPrevActive) {
|
|
2599
|
-
this.activate(event);
|
|
2600
|
-
this.deactivate(event);
|
|
2601
|
-
}
|
|
2602
|
-
const { onLongPress, onPress } = this.config;
|
|
2603
|
-
if (onLongPress != null && prevState === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.cancelClick = true;
|
|
2604
|
-
else if (onPress != null) {
|
|
2605
|
-
onPress(event);
|
|
2606
|
-
if (event.isDefaultPrevented()) this.cancelClick = true;
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
this.pressDelayTimer = clear(this.pressDelayTimer);
|
|
2610
|
-
}
|
|
2611
|
-
activate(event) {
|
|
2612
|
-
const { pageX, pageY } = event.nativeEvent;
|
|
2613
|
-
this.activatePosition = {
|
|
2614
|
-
pageX,
|
|
2615
|
-
pageY
|
|
2616
|
-
};
|
|
2617
|
-
this.activateTime = Date.now();
|
|
2618
|
-
this.config.onPressIn?.(event);
|
|
2619
|
-
}
|
|
2620
|
-
deactivate(event) {
|
|
2621
|
-
const { onPressOut } = this.config;
|
|
2622
|
-
if (onPressOut != null) {
|
|
2623
|
-
const minPressDuration = normalizeDelay(this.config.minPressDuration, 0, DEFAULT_MIN_PRESS_DURATION);
|
|
2624
|
-
const pressDuration = Date.now() - (this.activateTime ?? 0);
|
|
2625
|
-
const delayPressOut = Math.max(minPressDuration - pressDuration, normalizeDelay(this.config.delayPressOut));
|
|
2626
|
-
if (delayPressOut > 0) this.pressOutTimer = setTimeout(() => onPressOut(event), delayPressOut);
|
|
2627
|
-
else onPressOut(event);
|
|
2628
|
-
}
|
|
2629
|
-
this.activateTime = null;
|
|
2630
|
-
}
|
|
2631
|
-
measureRegion() {
|
|
2632
|
-
if (this.element === null) return;
|
|
2633
|
-
const rect = this.element.getBoundingClientRect();
|
|
2634
|
-
if (rect.width === 0 && rect.height === 0 && rect.top === 0 && rect.left === 0) return;
|
|
2635
|
-
this.region = {
|
|
2636
|
-
bottom: rect.bottom + window.scrollY,
|
|
2637
|
-
left: rect.left + window.scrollX,
|
|
2638
|
-
right: rect.right + window.scrollX,
|
|
2639
|
-
top: rect.top + window.scrollY
|
|
2640
|
-
};
|
|
2641
|
-
}
|
|
2642
|
-
isWithinRegion(pageX, pageY, region) {
|
|
2643
|
-
const hitSlop = normalizeRect(this.config.hitSlop);
|
|
2644
|
-
const offset = normalizeRect(this.config.pressRectOffset);
|
|
2645
|
-
const bottom = region.bottom + (hitSlop?.bottom ?? 0) + (offset?.bottom ?? DEFAULT_PRESS_RECT_OFFSETS.bottom);
|
|
2646
|
-
const left = region.left - (hitSlop?.left ?? 0) - (offset?.left ?? DEFAULT_PRESS_RECT_OFFSETS.left);
|
|
2647
|
-
const right = region.right + (hitSlop?.right ?? 0) + (offset?.right ?? DEFAULT_PRESS_RECT_OFFSETS.right);
|
|
2648
|
-
const top = region.top - (hitSlop?.top ?? 0) - (offset?.top ?? DEFAULT_PRESS_RECT_OFFSETS.top);
|
|
2649
|
-
return pageX > left && pageX < right && pageY > top && pageY < bottom;
|
|
2650
|
-
}
|
|
2651
|
-
};
|
|
2652
|
-
// src/events/press/usePressability.ts
|
|
2653
|
-
function usePressability(config) {
|
|
2654
|
-
const [pressability, setPressability] = useState(() => config == null ? null : new Pressability(config));
|
|
2655
|
-
if (pressability === null && config != null) setPressability(new Pressability(config));
|
|
2656
|
-
useInsertionEffect(() => {
|
|
2657
|
-
if (config != null && pressability !== null) pressability.configure(config);
|
|
2658
|
-
}, [config, pressability]);
|
|
2659
|
-
useInsertionEffect(() => {
|
|
2660
|
-
if (pressability === null) return void 0;
|
|
2661
|
-
return () => pressability.reset();
|
|
2662
|
-
}, [pressability]);
|
|
2663
|
-
return pressability === null ? null : pressability.getEventHandlers();
|
|
2664
|
-
}
|
|
2665
|
-
// src/components/Pressable/index.tsx
|
|
2666
|
-
const notCancelableStyle = Object.freeze({ touchAction: "none" });
|
|
2667
|
-
const hitSlopClass = (registry, hitSlop) => {
|
|
2668
|
-
if (hitSlop === void 0) return void 0;
|
|
2669
|
-
const { top = 0, right = 0, bottom = 0, left = 0 } = typeof hitSlop === "number" ? {
|
|
2670
|
-
top: hitSlop,
|
|
2671
|
-
right: hitSlop,
|
|
2672
|
-
bottom: hitSlop,
|
|
2673
|
-
left: hitSlop
|
|
2674
|
-
} : hitSlop;
|
|
2675
|
-
if (top === 0 && right === 0 && bottom === 0 && left === 0) return void 0;
|
|
2676
|
-
const name = `rn-hs-${[
|
|
2677
|
-
top,
|
|
2678
|
-
right,
|
|
2679
|
-
bottom,
|
|
2680
|
-
left
|
|
2681
|
-
].map((n) => String(n).replace(/[^0-9]/g, "_")).join("-")}`;
|
|
2682
|
-
return registry.staticClass(name, [`.${name}::before{content:"";position:absolute;top:${-top}px;right:${-right}px;bottom:${-bottom}px;left:${-left}px;z-index:-1}`]);
|
|
2683
|
-
};
|
|
2684
|
-
const isFocusVisible = (element) => {
|
|
2685
|
-
try {
|
|
2686
|
-
return element.matches(":focus-visible");
|
|
2687
|
-
} catch {
|
|
2688
|
-
return true;
|
|
2689
|
-
}
|
|
2690
|
-
};
|
|
2691
|
-
const sharedHandlers = [
|
|
2692
|
-
"onClick",
|
|
2693
|
-
"onContextMenu",
|
|
2694
|
-
"onKeyDown",
|
|
2695
|
-
"onKeyUp",
|
|
2696
|
-
"onPointerCancel",
|
|
2697
|
-
"onPointerDown",
|
|
2698
|
-
"onPointerEnter",
|
|
2699
|
-
"onPointerLeave",
|
|
2700
|
-
"onPointerMove",
|
|
2701
|
-
"onPointerUp"
|
|
2702
|
-
];
|
|
2703
|
-
const mergeHandlers = (app, own) => {
|
|
2704
|
-
const merged = { ...own };
|
|
2705
|
-
for (const key of sharedHandlers) {
|
|
2706
|
-
const first = app[key];
|
|
2707
|
-
if (first === void 0) continue;
|
|
2708
|
-
const second = own[key];
|
|
2709
|
-
merged[key] = (event) => {
|
|
2710
|
-
first(event);
|
|
2711
|
-
second(event);
|
|
2712
|
-
};
|
|
2713
|
-
}
|
|
2714
|
-
return merged;
|
|
2715
|
-
};
|
|
2716
|
-
const Pressable = memo(function Pressable(props) {
|
|
2717
|
-
const { android_disableSound, android_ripple: _androidRipple, blockNativeResponder, cancelable, children, delayHoverIn, delayHoverOut, delayLongPress, disabled, focusable, hitSlop, onBlur, onFocus, onHoverIn, onHoverOut, onLongPress, onPress, onPressIn, onPressMove, onPressOut, pressRetentionOffset, style, testOnly_pressed, unstable_pressDelay, ...rest } = props;
|
|
2718
|
-
const [pressed, setPressed] = useState(false);
|
|
2719
|
-
const [hovered, setHovered] = useState(false);
|
|
2720
|
-
const [focused, setFocused] = useState(false);
|
|
2721
|
-
const tracksState = typeof children === "function" || typeof style === "function";
|
|
2722
|
-
const handlers = usePressability(useMemo(() => ({
|
|
2723
|
-
cancelable,
|
|
2724
|
-
disabled,
|
|
2725
|
-
hitSlop,
|
|
2726
|
-
pressRectOffset: pressRetentionOffset,
|
|
2727
|
-
android_disableSound,
|
|
2728
|
-
delayHoverIn,
|
|
2729
|
-
delayHoverOut,
|
|
2730
|
-
delayLongPress,
|
|
2731
|
-
delayPressIn: unstable_pressDelay,
|
|
2732
|
-
blockNativeResponder,
|
|
2733
|
-
onLongPress,
|
|
2734
|
-
onPress,
|
|
2735
|
-
onPressMove,
|
|
2736
|
-
onPressIn: (event) => {
|
|
2737
|
-
if (tracksState) setPressed(true);
|
|
2738
|
-
onPressIn?.(event);
|
|
2739
|
-
},
|
|
2740
|
-
onPressOut: (event) => {
|
|
2741
|
-
if (tracksState) setPressed(false);
|
|
2742
|
-
onPressOut?.(event);
|
|
2743
|
-
},
|
|
2744
|
-
onHoverIn: (event) => {
|
|
2745
|
-
if (tracksState) setHovered(true);
|
|
2746
|
-
onHoverIn?.(event);
|
|
2747
|
-
},
|
|
2748
|
-
onHoverOut: (event) => {
|
|
2749
|
-
if (tracksState) setHovered(false);
|
|
2750
|
-
onHoverOut?.(event);
|
|
2751
|
-
},
|
|
2752
|
-
onFocus: (event) => {
|
|
2753
|
-
if (tracksState && event.target === event.currentTarget) setFocused(isFocusVisible(event.currentTarget));
|
|
2754
|
-
onFocus?.(event);
|
|
2755
|
-
},
|
|
2756
|
-
onBlur: (event) => {
|
|
2757
|
-
if (tracksState && event.target === event.currentTarget) setFocused(false);
|
|
2758
|
-
onBlur?.(event);
|
|
2759
|
-
}
|
|
2760
|
-
}), [
|
|
2761
|
-
android_disableSound,
|
|
2762
|
-
blockNativeResponder,
|
|
2763
|
-
cancelable,
|
|
2764
|
-
delayHoverIn,
|
|
2765
|
-
delayHoverOut,
|
|
2766
|
-
delayLongPress,
|
|
2767
|
-
disabled,
|
|
2768
|
-
hitSlop,
|
|
2769
|
-
onBlur,
|
|
2770
|
-
onFocus,
|
|
2771
|
-
onHoverIn,
|
|
2772
|
-
onHoverOut,
|
|
2773
|
-
onLongPress,
|
|
2774
|
-
onPress,
|
|
2775
|
-
onPressIn,
|
|
2776
|
-
onPressMove,
|
|
2777
|
-
onPressOut,
|
|
2778
|
-
pressRetentionOffset,
|
|
2779
|
-
tracksState,
|
|
2780
|
-
unstable_pressDelay
|
|
2781
|
-
]));
|
|
2782
|
-
const registry = useStyleRegistry();
|
|
2783
|
-
const state = {
|
|
2784
|
-
pressed: pressed || testOnly_pressed === true,
|
|
2785
|
-
hovered,
|
|
2786
|
-
focused
|
|
2787
|
-
};
|
|
2788
|
-
const viewProps = {
|
|
2789
|
-
...rest,
|
|
2790
|
-
...mergeHandlers(rest, handlers),
|
|
2791
|
-
focusable: disabled !== true && focusable !== false,
|
|
2792
|
-
style: [typeof style === "function" ? style(state) : style, cancelable === false && notCancelableStyle],
|
|
2793
|
-
children: typeof children === "function" ? children(state) : children
|
|
2794
|
-
};
|
|
2795
|
-
if (disabled === true) viewProps["aria-disabled"] = true;
|
|
2796
|
-
return useViewElement(viewProps, hitSlopClass(registry, hitSlop));
|
|
2797
|
-
});
|
|
2798
|
-
// src/components/StatusBar/index.tsx
|
|
2799
|
-
const stack = [];
|
|
2800
|
-
const base = {};
|
|
2801
|
-
const merged = () => {
|
|
2802
|
-
const out = { ...base };
|
|
2803
|
-
for (const entry of stack) for (const key in entry) {
|
|
2804
|
-
const value = entry[key];
|
|
2805
|
-
if (value !== void 0) out[key] = value;
|
|
2806
|
-
}
|
|
2807
|
-
return out;
|
|
2808
|
-
};
|
|
2809
|
-
const themeColorMeta = () => {
|
|
2810
|
-
if (!hasDOM()) return null;
|
|
2811
|
-
let meta = document.head.querySelector("meta[name=\"theme-color\"]:not([media])");
|
|
2812
|
-
if (meta === null) {
|
|
2813
|
-
meta = document.createElement("meta");
|
|
2814
|
-
meta.name = "theme-color";
|
|
2815
|
-
document.head.appendChild(meta);
|
|
2816
|
-
}
|
|
2817
|
-
return meta;
|
|
2818
|
-
};
|
|
2819
|
-
let originalThemeColor;
|
|
2820
|
-
const apply = () => {
|
|
2821
|
-
const meta = themeColorMeta();
|
|
2822
|
-
if (meta === null) return;
|
|
2823
|
-
if (originalThemeColor === void 0) originalThemeColor = meta.getAttribute("content");
|
|
2824
|
-
const color = toCSSColor(merged().backgroundColor);
|
|
2825
|
-
if (color !== void 0) meta.setAttribute("content", color);
|
|
2826
|
-
else if (originalThemeColor === null) meta.removeAttribute("content");
|
|
2827
|
-
else meta.setAttribute("content", originalThemeColor);
|
|
2828
|
-
};
|
|
2829
|
-
const pushStackEntry = (props) => {
|
|
2830
|
-
const entry = { ...props };
|
|
2831
|
-
stack.push(entry);
|
|
2832
|
-
apply();
|
|
2833
|
-
return entry;
|
|
2834
|
-
};
|
|
2835
|
-
const popStackEntry = (entry) => {
|
|
2836
|
-
const index = stack.indexOf(entry);
|
|
2837
|
-
if (index !== -1) stack.splice(index, 1);
|
|
2838
|
-
apply();
|
|
2839
|
-
};
|
|
2840
|
-
const replaceStackEntry = (entry, props) => {
|
|
2841
|
-
const index = stack.indexOf(entry);
|
|
2842
|
-
const next = { ...props };
|
|
2843
|
-
if (index === -1) stack.push(next);
|
|
2844
|
-
else stack[index] = next;
|
|
2845
|
-
apply();
|
|
2846
|
-
return next;
|
|
2847
|
-
};
|
|
2848
|
-
function StatusBarComponent(props) {
|
|
2849
|
-
const entry = useRef(null);
|
|
2850
|
-
const { animated, backgroundColor, barStyle, hidden, networkActivityIndicatorVisible, showHideTransition, translucent } = props;
|
|
2851
|
-
useEffect(() => {
|
|
2852
|
-
const next = {
|
|
2853
|
-
animated,
|
|
2854
|
-
backgroundColor,
|
|
2855
|
-
barStyle,
|
|
2856
|
-
hidden,
|
|
2857
|
-
networkActivityIndicatorVisible,
|
|
2858
|
-
showHideTransition,
|
|
2859
|
-
translucent
|
|
2860
|
-
};
|
|
2861
|
-
entry.current = entry.current === null ? pushStackEntry(next) : replaceStackEntry(entry.current, next);
|
|
2862
|
-
}, [
|
|
2863
|
-
animated,
|
|
2864
|
-
backgroundColor,
|
|
2865
|
-
barStyle,
|
|
2866
|
-
hidden,
|
|
2867
|
-
networkActivityIndicatorVisible,
|
|
2868
|
-
showHideTransition,
|
|
2869
|
-
translucent
|
|
2870
|
-
]);
|
|
2871
|
-
useEffect(() => {
|
|
2872
|
-
return () => {
|
|
2873
|
-
if (entry.current !== null) popStackEntry(entry.current);
|
|
2874
|
-
entry.current = null;
|
|
2875
|
-
};
|
|
2876
|
-
}, []);
|
|
2877
|
-
return null;
|
|
2878
|
-
}
|
|
2879
|
-
const StatusBar = Object.assign(StatusBarComponent, {
|
|
2880
|
-
currentHeight: null,
|
|
2881
|
-
setBarStyle: (style, _animated) => {
|
|
2882
|
-
base.barStyle = style;
|
|
2883
|
-
apply();
|
|
2884
|
-
},
|
|
2885
|
-
setBackgroundColor: (color, _animated) => {
|
|
2886
|
-
base.backgroundColor = color;
|
|
2887
|
-
apply();
|
|
2888
|
-
},
|
|
2889
|
-
setHidden: (hidden, _animation) => {
|
|
2890
|
-
base.hidden = hidden;
|
|
2891
|
-
apply();
|
|
2892
|
-
},
|
|
2893
|
-
setTranslucent: (translucent) => {
|
|
2894
|
-
base.translucent = translucent;
|
|
2895
|
-
apply();
|
|
2896
|
-
},
|
|
2897
|
-
setNetworkActivityIndicatorVisible: (visible) => {
|
|
2898
|
-
base.networkActivityIndicatorVisible = visible;
|
|
2899
|
-
apply();
|
|
2900
|
-
},
|
|
2901
|
-
pushStackEntry,
|
|
2902
|
-
popStackEntry,
|
|
2903
|
-
replaceStackEntry
|
|
2904
|
-
});
|
|
2905
|
-
// src/components/Text/TextAncestorContext.ts
|
|
2906
|
-
const TextAncestorContext = createContext(false);
|
|
2907
|
-
// src/components/Text/index.tsx
|
|
2908
|
-
const resetStyle$1 = Object.freeze({
|
|
2909
|
-
backgroundColor: "transparent",
|
|
2910
|
-
border: "0 solid black",
|
|
2911
|
-
boxSizing: "border-box",
|
|
2912
|
-
color: "black",
|
|
2913
|
-
display: "inline",
|
|
2914
|
-
fontFamily: "System",
|
|
2915
|
-
fontSize: 14,
|
|
2916
|
-
listStyle: "none",
|
|
2917
|
-
margin: 0,
|
|
2918
|
-
padding: 0,
|
|
2919
|
-
position: "relative",
|
|
2920
|
-
textAlign: "start",
|
|
2921
|
-
textDecoration: "none",
|
|
2922
|
-
whiteSpace: "pre-wrap",
|
|
2923
|
-
wordWrap: "break-word"
|
|
2924
|
-
});
|
|
2925
|
-
const nestedResetStyle = Object.freeze({
|
|
2926
|
-
color: "inherit",
|
|
2927
|
-
font: "inherit",
|
|
2928
|
-
textAlign: "inherit",
|
|
2929
|
-
textDecoration: "inherit",
|
|
2930
|
-
whiteSpace: "inherit"
|
|
2931
|
-
});
|
|
2932
|
-
const singleLineStyle = Object.freeze({
|
|
2933
|
-
overflow: "hidden",
|
|
2934
|
-
textOverflow: "ellipsis",
|
|
2935
|
-
whiteSpace: "nowrap"
|
|
2936
|
-
});
|
|
2937
|
-
const multiLineStyle = (lines) => ({
|
|
2938
|
-
display: "-webkit-box",
|
|
2939
|
-
WebkitBoxOrient: "vertical",
|
|
2940
|
-
WebkitLineClamp: lines,
|
|
2941
|
-
overflow: "hidden"
|
|
2942
|
-
});
|
|
2943
|
-
const selectionClass$1 = (registry, color) => {
|
|
2944
|
-
const css = toCSSColor(color);
|
|
2945
|
-
if (css === void 0) return void 0;
|
|
2946
|
-
const name = `rn-sel-${css.replace(/[^a-z0-9]/g, "")}`;
|
|
2947
|
-
return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
|
|
2948
|
-
};
|
|
2949
|
-
function Text(props) {
|
|
2950
|
-
const { children, disabled, ellipsizeMode, numberOfLines, onClick, onLayout, onPress, pointerEvents, ref, selectable, selectionColor, style, ...rest } = props;
|
|
2951
|
-
const nested = useContext(TextAncestorContext);
|
|
2952
|
-
const element = useRef(null);
|
|
2953
|
-
useImperativeHandle(ref, () => element.current, []);
|
|
2954
|
-
useElementLayout(element, onLayout);
|
|
2955
|
-
const registry = useStyleRegistry();
|
|
2956
|
-
const { tag, role } = resolveTag(rest, "span", children != null);
|
|
2957
|
-
const lineStyle = numberOfLines === void 0 || numberOfLines < 1 ? void 0 : numberOfLines === 1 ? singleLineStyle : multiLineStyle(numberOfLines);
|
|
2958
|
-
let className = compileStyle([
|
|
2959
|
-
nested ? nestedResetStyle : resetStyle$1,
|
|
2960
|
-
style,
|
|
2961
|
-
lineStyle,
|
|
2962
|
-
ellipsizeMode === "clip" ? { textOverflow: "clip" } : void 0,
|
|
2963
|
-
selectable === false ? { userSelect: "none" } : void 0,
|
|
2964
|
-
pointerEvents === "none" || pointerEvents === "auto" ? { pointerEvents } : void 0
|
|
2965
|
-
], registry);
|
|
2966
|
-
if (selectionColor !== void 0) {
|
|
2967
|
-
const extra = selectionClass$1(registry, selectionColor);
|
|
2968
|
-
if (extra !== void 0) className = `${className} ${extra}`;
|
|
2969
|
-
}
|
|
2970
|
-
const handleClick = useCallback((event) => {
|
|
2971
|
-
onClick?.(event);
|
|
2972
|
-
if (disabled === true || event.defaultPrevented) return;
|
|
2973
|
-
onPress?.(event);
|
|
2974
|
-
}, [
|
|
2975
|
-
disabled,
|
|
2976
|
-
onClick,
|
|
2977
|
-
onPress
|
|
2978
|
-
]);
|
|
2979
|
-
const domProps = toDOMProps(rest);
|
|
2980
|
-
if (role !== void 0) domProps["role"] = role;
|
|
2981
|
-
if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
|
|
2982
|
-
if (tag === "button") domProps["type"] = "button";
|
|
2983
|
-
if (disabled === true) domProps["aria-disabled"] = true;
|
|
2984
|
-
if (onPress !== void 0 || onClick !== void 0) domProps["onClick"] = handleClick;
|
|
2985
|
-
domProps["className"] = className;
|
|
2986
|
-
domProps["ref"] = element;
|
|
2987
|
-
const content = nested ? children : createElement(TextAncestorContext.Provider, { value: true }, children);
|
|
2988
|
-
return createElement(tag, domProps, content);
|
|
2989
|
-
}
|
|
2990
|
-
// src/components/TextInput/autocomplete.ts
|
|
2991
|
-
const reactNativeToHTML = {
|
|
2992
|
-
"address-line1": "address-line1",
|
|
2993
|
-
"address-line2": "address-line2",
|
|
2994
|
-
"birthdate-day": "bday-day",
|
|
2995
|
-
"birthdate-full": "bday",
|
|
2996
|
-
"birthdate-month": "bday-month",
|
|
2997
|
-
"birthdate-year": "bday-year",
|
|
2998
|
-
"cc-middle-name": "cc-additional-name",
|
|
2999
|
-
gender: "sex",
|
|
3000
|
-
"name-family": "family-name",
|
|
3001
|
-
"name-given": "given-name",
|
|
3002
|
-
"name-middle": "additional-name",
|
|
3003
|
-
"name-middle-initial": "additional-name",
|
|
3004
|
-
"name-prefix": "honorific-prefix",
|
|
3005
|
-
"name-suffix": "honorific-suffix",
|
|
3006
|
-
"postal-address": "street-address",
|
|
3007
|
-
"postal-address-country": "country",
|
|
3008
|
-
"postal-address-extended": "address-line2",
|
|
3009
|
-
"postal-address-extended-postal-code": "postal-code",
|
|
3010
|
-
"postal-address-locality": "address-level2",
|
|
3011
|
-
"postal-address-region": "address-level1",
|
|
3012
|
-
"sms-otp": "one-time-code",
|
|
3013
|
-
"tel-device": "tel",
|
|
3014
|
-
"username-new": "username"
|
|
3015
|
-
};
|
|
3016
|
-
const textContentTypeToHTML = {
|
|
3017
|
-
none: "off",
|
|
3018
|
-
URL: "url",
|
|
3019
|
-
addressCity: "address-level2",
|
|
3020
|
-
addressCityAndState: "address-level1",
|
|
3021
|
-
addressState: "address-level1",
|
|
3022
|
-
birthdate: "bday",
|
|
3023
|
-
birthdateDay: "bday-day",
|
|
3024
|
-
birthdateMonth: "bday-month",
|
|
3025
|
-
birthdateYear: "bday-year",
|
|
3026
|
-
countryName: "country-name",
|
|
3027
|
-
creditCardExpiration: "cc-exp",
|
|
3028
|
-
creditCardExpirationMonth: "cc-exp-month",
|
|
3029
|
-
creditCardExpirationYear: "cc-exp-year",
|
|
3030
|
-
creditCardFamilyName: "cc-family-name",
|
|
3031
|
-
creditCardGivenName: "cc-given-name",
|
|
3032
|
-
creditCardMiddleName: "cc-additional-name",
|
|
3033
|
-
creditCardName: "cc-name",
|
|
3034
|
-
creditCardNumber: "cc-number",
|
|
3035
|
-
creditCardSecurityCode: "cc-csc",
|
|
3036
|
-
creditCardType: "cc-type",
|
|
3037
|
-
emailAddress: "email",
|
|
3038
|
-
familyName: "family-name",
|
|
3039
|
-
fullStreetAddress: "street-address",
|
|
3040
|
-
givenName: "given-name",
|
|
3041
|
-
jobTitle: "organization-title",
|
|
3042
|
-
location: "street-address",
|
|
3043
|
-
middleName: "additional-name",
|
|
3044
|
-
name: "name",
|
|
3045
|
-
namePrefix: "honorific-prefix",
|
|
3046
|
-
nameSuffix: "honorific-suffix",
|
|
3047
|
-
newPassword: "new-password",
|
|
3048
|
-
nickname: "nickname",
|
|
3049
|
-
oneTimeCode: "one-time-code",
|
|
3050
|
-
organizationName: "organization",
|
|
3051
|
-
password: "current-password",
|
|
3052
|
-
postalCode: "postal-code",
|
|
3053
|
-
streetAddressLine1: "address-line1",
|
|
3054
|
-
streetAddressLine2: "address-line2",
|
|
3055
|
-
sublocality: "address-level3",
|
|
3056
|
-
telephoneNumber: "tel",
|
|
3057
|
-
username: "username"
|
|
3058
|
-
};
|
|
3059
|
-
const toHTMLAutoComplete = (autoComplete, textContentType) => {
|
|
3060
|
-
if (autoComplete !== void 0) return reactNativeToHTML[autoComplete] ?? autoComplete;
|
|
3061
|
-
if (textContentType !== void 0) return textContentTypeToHTML[textContentType];
|
|
3062
|
-
};
|
|
3063
|
-
const keyboardTypeToInputMode = {
|
|
3064
|
-
"decimal-pad": "decimal",
|
|
3065
|
-
"email-address": "email",
|
|
3066
|
-
"number-pad": "numeric",
|
|
3067
|
-
numeric: "numeric",
|
|
3068
|
-
"numbers-and-punctuation": "decimal",
|
|
3069
|
-
"phone-pad": "tel",
|
|
3070
|
-
url: "url",
|
|
3071
|
-
"web-search": "search"
|
|
3072
|
-
};
|
|
3073
|
-
const toInputMode = (inputMode, keyboardType, showSoftInputOnFocus) => {
|
|
3074
|
-
if (showSoftInputOnFocus === false) return "none";
|
|
3075
|
-
if (inputMode !== void 0) return inputMode;
|
|
3076
|
-
if (keyboardType !== void 0) return keyboardTypeToInputMode[keyboardType];
|
|
3077
|
-
};
|
|
3078
|
-
const returnKeyTypeToEnterKeyHint = {
|
|
3079
|
-
done: "done",
|
|
3080
|
-
go: "go",
|
|
3081
|
-
next: "next",
|
|
3082
|
-
search: "search",
|
|
3083
|
-
send: "send"
|
|
3084
|
-
};
|
|
3085
|
-
const toEnterKeyHint = (enterKeyHint, returnKeyType) => {
|
|
3086
|
-
if (enterKeyHint !== void 0) return enterKeyHint;
|
|
3087
|
-
if (returnKeyType !== void 0) return returnKeyTypeToEnterKeyHint[returnKeyType];
|
|
3088
|
-
};
|
|
3089
|
-
// src/components/TextInput/index.tsx
|
|
3090
|
-
const resetStyle = Object.freeze({
|
|
3091
|
-
appearance: "none",
|
|
3092
|
-
backgroundColor: "transparent",
|
|
3093
|
-
border: "0 solid black",
|
|
3094
|
-
borderRadius: 0,
|
|
3095
|
-
boxSizing: "border-box",
|
|
3096
|
-
color: "black",
|
|
3097
|
-
display: "block",
|
|
3098
|
-
fontFamily: "System",
|
|
3099
|
-
fontSize: 14,
|
|
3100
|
-
margin: 0,
|
|
3101
|
-
minWidth: 0,
|
|
3102
|
-
padding: 0,
|
|
3103
|
-
position: "relative",
|
|
3104
|
-
resize: "none",
|
|
3105
|
-
textAlign: "start",
|
|
3106
|
-
textDecoration: "none"
|
|
3107
|
-
});
|
|
3108
|
-
const textareaStyle = Object.freeze({
|
|
3109
|
-
fieldSizing: "content",
|
|
3110
|
-
overflow: "auto",
|
|
3111
|
-
whiteSpace: "pre-wrap",
|
|
3112
|
-
wordWrap: "break-word"
|
|
3113
|
-
});
|
|
3114
|
-
const supportsFieldSizing = hasDOM() && typeof CSS !== "undefined" && CSS.supports("field-sizing", "content");
|
|
3115
|
-
const hash = (value) => {
|
|
3116
|
-
let h = 5381;
|
|
3117
|
-
for (let i = 0; i < value.length; i++) h = h * 33 ^ value.charCodeAt(i);
|
|
3118
|
-
return (h >>> 0).toString(36);
|
|
3119
|
-
};
|
|
3120
|
-
const placeholderClass = (registry, color) => {
|
|
3121
|
-
const css = toCSSColor(color);
|
|
3122
|
-
if (css === void 0) return void 0;
|
|
3123
|
-
const name = `rn-ph-${hash(css)}`;
|
|
3124
|
-
return registry.staticClass(name, [`.${name}::placeholder{color:${css};opacity:1}`]);
|
|
3125
|
-
};
|
|
3126
|
-
const selectionClass = (registry, color) => {
|
|
3127
|
-
const css = toCSSColor(color);
|
|
3128
|
-
if (css === void 0) return void 0;
|
|
3129
|
-
const name = `rn-sel-${hash(css)}`;
|
|
3130
|
-
return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
|
|
3131
|
-
};
|
|
3132
|
-
const submitBehaviorOf = (submitBehavior, blurOnSubmit, multiline) => {
|
|
3133
|
-
if (submitBehavior !== void 0) return submitBehavior;
|
|
3134
|
-
if (multiline) return blurOnSubmit === true ? "blurAndSubmit" : "newline";
|
|
3135
|
-
return blurOnSubmit === false ? "submit" : "blurAndSubmit";
|
|
3136
|
-
};
|
|
3137
|
-
const selectionOf = (field) => ({
|
|
3138
|
-
start: field.selectionStart ?? 0,
|
|
3139
|
-
end: field.selectionEnd ?? 0
|
|
3140
|
-
});
|
|
3141
|
-
const sameSelection = (a, b) => a !== null && a.start === b.start && a.end === b.end;
|
|
3142
|
-
const isField = (node) => node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement;
|
|
3143
|
-
function TextInputComponent(props) {
|
|
3144
|
-
const { autoCapitalize, autoComplete, autoCorrect, autoFocus, blurOnSubmit: _blurOnSubmit, caretHidden, clearTextOnFocus: _clearTextOnFocus, contextMenuHidden: _contextMenuHidden, cursorColor, defaultValue, editable = true, enterKeyHint, inputMode, keyboardType, maxLength, multiline = false, numberOfLines, onBlur: _onBlur, onChange: _onChange, onChangeText: _onChangeText, onContentSizeChange, onContextMenu: _onContextMenu, onEndEditing: _onEndEditing, onFocus: _onFocus, onKeyDown: _onKeyDown, onKeyPress: _onKeyPress, onLayout, onScroll: _onScroll, onSelectionChange: _onSelectionChange, onSubmitEditing: _onSubmitEditing, placeholder, placeholderTextColor, readOnly, ref, returnKeyType, secureTextEntry, selectTextOnFocus: _selectTextOnFocus, selection, selectionColor, showSoftInputOnFocus, spellCheck, style, submitBehavior: _submitBehavior, textAlign, textContentType, value, allowFontScaling: _allowFontScaling, clearButtonMode: _clearButtonMode, dataDetectorTypes: _dataDetectorTypes, disableFullscreenUI: _disableFullscreenUI, enablesReturnKeyAutomatically: _enablesReturnKeyAutomatically, importantForAutofill: _importantForAutofill, inlineImageLeft: _inlineImageLeft, inlineImagePadding: _inlineImagePadding, keyboardAppearance: _keyboardAppearance, lineBreakStrategyIOS: _lineBreakStrategyIOS, maxFontSizeMultiplier: _maxFontSizeMultiplier, passwordRules: _passwordRules, rejectResponderTermination: _rejectResponderTermination, returnKeyLabel: _returnKeyLabel, scrollEnabled: _scrollEnabled, smartInsertDelete: _smartInsertDelete, textAlignVertical: _textAlignVertical, textBreakStrategy: _textBreakStrategy, underlineColorAndroid: _underlineColorAndroid, verticalAlign: _verticalAlign, ...rest } = props;
|
|
3145
|
-
const registry = useStyleRegistry();
|
|
3146
|
-
const field = useRef(null);
|
|
3147
|
-
useElementLayout(field, onLayout);
|
|
3148
|
-
const handlers = useRef(props);
|
|
3149
|
-
useEffect(() => {
|
|
3150
|
-
handlers.current = props;
|
|
3151
|
-
});
|
|
3152
|
-
const eventCount = useRef(0);
|
|
3153
|
-
const lastSelection = useRef(null);
|
|
3154
|
-
const lastContentSize = useRef(null);
|
|
3155
|
-
const reportContentSize = useCallback((element) => {
|
|
3156
|
-
const next = {
|
|
3157
|
-
width: element.scrollWidth,
|
|
3158
|
-
height: element.scrollHeight
|
|
3159
|
-
};
|
|
3160
|
-
const last = lastContentSize.current;
|
|
3161
|
-
if (last !== null && last.width === next.width && last.height === next.height) return;
|
|
3162
|
-
lastContentSize.current = next;
|
|
3163
|
-
handlers.current.onContentSizeChange?.({ nativeEvent: { contentSize: next } });
|
|
3164
|
-
}, []);
|
|
3165
|
-
const grow = useCallback((element) => {
|
|
3166
|
-
if (supportsFieldSizing || !(element instanceof HTMLTextAreaElement)) return;
|
|
3167
|
-
if (handlers.current.style !== void 0) {
|
|
3168
|
-
if (flattenStyle(handlers.current.style)?.["height"] !== void 0) return;
|
|
3169
|
-
}
|
|
3170
|
-
element.style.height = "auto";
|
|
3171
|
-
element.style.height = `${element.scrollHeight}px`;
|
|
3172
|
-
}, []);
|
|
3173
|
-
const handleChange = useCallback((event) => {
|
|
3174
|
-
const element = event.currentTarget;
|
|
3175
|
-
const text = element.value;
|
|
3176
|
-
eventCount.current += 1;
|
|
3177
|
-
Object.assign(event.nativeEvent, {
|
|
3178
|
-
text,
|
|
3179
|
-
eventCount: eventCount.current
|
|
3180
|
-
});
|
|
3181
|
-
handlers.current.onChange?.(event);
|
|
3182
|
-
handlers.current.onChangeText?.(text);
|
|
3183
|
-
grow(element);
|
|
3184
|
-
if (handlers.current.onContentSizeChange !== void 0) reportContentSize(element);
|
|
3185
|
-
}, [grow, reportContentSize]);
|
|
3186
|
-
const handleFocus = useCallback((event) => {
|
|
3187
|
-
const element = event.currentTarget;
|
|
3188
|
-
const current = handlers.current;
|
|
3189
|
-
if (current.clearTextOnFocus === true && element.value !== "") {
|
|
3190
|
-
element.value = "";
|
|
3191
|
-
eventCount.current += 1;
|
|
3192
|
-
current.onChangeText?.("");
|
|
3193
|
-
}
|
|
3194
|
-
if (current.selectTextOnFocus === true) element.select();
|
|
3195
|
-
Object.assign(event.nativeEvent, {
|
|
3196
|
-
text: element.value,
|
|
3197
|
-
eventCount: eventCount.current
|
|
3198
|
-
});
|
|
3199
|
-
current.onFocus?.(event);
|
|
3200
|
-
}, []);
|
|
3201
|
-
const handleBlur = useCallback((event) => {
|
|
3202
|
-
const element = event.currentTarget;
|
|
3203
|
-
Object.assign(event.nativeEvent, {
|
|
3204
|
-
text: element.value,
|
|
3205
|
-
eventCount: eventCount.current
|
|
3206
|
-
});
|
|
3207
|
-
handlers.current.onBlur?.(event);
|
|
3208
|
-
handlers.current.onEndEditing?.(event);
|
|
3209
|
-
}, []);
|
|
3210
|
-
const handleKeyDown = useCallback((event) => {
|
|
3211
|
-
const current = handlers.current;
|
|
3212
|
-
current.onKeyDown?.(event);
|
|
3213
|
-
current.onKeyPress?.(event);
|
|
3214
|
-
if (event.defaultPrevented || event.key !== "Enter" || event.shiftKey) return;
|
|
3215
|
-
const isMultiline = current.multiline === true;
|
|
3216
|
-
const behavior = submitBehaviorOf(current.submitBehavior, current.blurOnSubmit, isMultiline);
|
|
3217
|
-
if (behavior === "newline") return;
|
|
3218
|
-
if (isMultiline) event.preventDefault();
|
|
3219
|
-
const element = event.currentTarget;
|
|
3220
|
-
Object.assign(event.nativeEvent, { text: element.value });
|
|
3221
|
-
current.onSubmitEditing?.(event);
|
|
3222
|
-
if (behavior === "blurAndSubmit") element.blur();
|
|
3223
|
-
}, []);
|
|
3224
|
-
const handleSelect = useCallback((event) => {
|
|
3225
|
-
const next = selectionOf(event.currentTarget);
|
|
3226
|
-
if (sameSelection(lastSelection.current, next)) return;
|
|
3227
|
-
lastSelection.current = next;
|
|
3228
|
-
Object.assign(event.nativeEvent, { selection: next });
|
|
3229
|
-
handlers.current.onSelectionChange?.(event);
|
|
3230
|
-
}, []);
|
|
3231
|
-
const handleScroll = useCallback((event) => {
|
|
3232
|
-
const element = event.currentTarget;
|
|
3233
|
-
Object.assign(event.nativeEvent, {
|
|
3234
|
-
contentInset: {
|
|
3235
|
-
top: 0,
|
|
3236
|
-
left: 0,
|
|
3237
|
-
bottom: 0,
|
|
3238
|
-
right: 0
|
|
3239
|
-
},
|
|
3240
|
-
contentOffset: {
|
|
3241
|
-
x: element.scrollLeft,
|
|
3242
|
-
y: element.scrollTop
|
|
3243
|
-
},
|
|
3244
|
-
contentSize: {
|
|
3245
|
-
width: element.scrollWidth,
|
|
3246
|
-
height: element.scrollHeight
|
|
3247
|
-
},
|
|
3248
|
-
layoutMeasurement: {
|
|
3249
|
-
width: element.clientWidth,
|
|
3250
|
-
height: element.clientHeight
|
|
3251
|
-
},
|
|
3252
|
-
zoomScale: 1
|
|
3253
|
-
});
|
|
3254
|
-
handlers.current.onScroll?.(event);
|
|
3255
|
-
}, []);
|
|
3256
|
-
const handleContextMenu = useCallback((event) => {
|
|
3257
|
-
handlers.current.onContextMenu?.(event);
|
|
3258
|
-
if (handlers.current.contextMenuHidden === true) event.preventDefault();
|
|
3259
|
-
}, []);
|
|
3260
|
-
const selectionStart = selection?.start;
|
|
3261
|
-
const selectionEnd = selection?.end ?? selection?.start;
|
|
3262
|
-
useLayoutEffect(() => {
|
|
3263
|
-
const element = field.current;
|
|
3264
|
-
if (element === null || selectionStart === void 0 || selectionEnd === void 0) return;
|
|
3265
|
-
if (element.selectionStart === selectionStart && element.selectionEnd === selectionEnd) return;
|
|
3266
|
-
element.setSelectionRange(selectionStart, selectionEnd);
|
|
3267
|
-
lastSelection.current = {
|
|
3268
|
-
start: selectionStart,
|
|
3269
|
-
end: selectionEnd
|
|
3270
|
-
};
|
|
3271
|
-
}, [
|
|
3272
|
-
selectionStart,
|
|
3273
|
-
selectionEnd,
|
|
3274
|
-
value
|
|
3275
|
-
]);
|
|
3276
|
-
useLayoutEffect(() => {
|
|
3277
|
-
const element = field.current;
|
|
3278
|
-
if (element === null) return;
|
|
3279
|
-
grow(element);
|
|
3280
|
-
}, [
|
|
3281
|
-
grow,
|
|
3282
|
-
value,
|
|
3283
|
-
multiline
|
|
3284
|
-
]);
|
|
3285
|
-
const wantsContentSize = onContentSizeChange !== void 0;
|
|
3286
|
-
useEffect(() => {
|
|
3287
|
-
const element = field.current;
|
|
3288
|
-
if (element === null || !wantsContentSize) return;
|
|
3289
|
-
reportContentSize(element);
|
|
3290
|
-
const observer = new ResizeObserver(() => reportContentSize(element));
|
|
3291
|
-
observer.observe(element);
|
|
3292
|
-
return () => observer.disconnect();
|
|
3293
|
-
}, [wantsContentSize, reportContentSize]);
|
|
3294
|
-
useImperativeHandle(ref, () => {
|
|
3295
|
-
const element = field.current;
|
|
3296
|
-
return Object.assign(element, {
|
|
3297
|
-
clear: () => {
|
|
3298
|
-
element.value = "";
|
|
3299
|
-
grow(element);
|
|
3300
|
-
handlers.current.onChangeText?.("");
|
|
3301
|
-
},
|
|
3302
|
-
isFocused: () => document.activeElement === element,
|
|
3303
|
-
getNativeRef: () => element,
|
|
3304
|
-
setNativeProps: (nativeProps) => {
|
|
3305
|
-
if (nativeProps.text !== void 0) {
|
|
3306
|
-
element.value = nativeProps.text;
|
|
3307
|
-
grow(element);
|
|
3308
|
-
}
|
|
3309
|
-
}
|
|
3310
|
-
});
|
|
3311
|
-
}, [grow]);
|
|
3312
|
-
const flat = flattenStyle(style);
|
|
3313
|
-
const colorStyle = {};
|
|
3314
|
-
const caret = cursorColor ?? selectionColor;
|
|
3315
|
-
if (caretHidden === true) colorStyle["caretColor"] = "transparent";
|
|
3316
|
-
else if (caret !== void 0) colorStyle["caretColor"] = caret;
|
|
3317
|
-
if (textAlign !== void 0) colorStyle["textAlign"] = textAlign;
|
|
3318
|
-
let className = compileStyle([
|
|
3319
|
-
resetStyle,
|
|
3320
|
-
multiline && textareaStyle,
|
|
3321
|
-
flat,
|
|
3322
|
-
colorStyle
|
|
3323
|
-
], registry);
|
|
3324
|
-
const placeholderName = placeholderClass(registry, placeholderTextColor);
|
|
3325
|
-
if (placeholderName !== void 0) className = `${className} ${placeholderName}`;
|
|
3326
|
-
const selectionName = selectionClass(registry, selectionColor);
|
|
3327
|
-
if (selectionName !== void 0) className = `${className} ${selectionName}`;
|
|
3328
|
-
const domProps = toDOMProps(rest);
|
|
3329
|
-
domProps["className"] = className;
|
|
3330
|
-
domProps["value"] = value;
|
|
3331
|
-
domProps["defaultValue"] = defaultValue;
|
|
3332
|
-
domProps["placeholder"] = placeholder;
|
|
3333
|
-
domProps["readOnly"] = readOnly === true || !editable ? true : void 0;
|
|
3334
|
-
domProps["maxLength"] = maxLength;
|
|
3335
|
-
domProps["autoFocus"] = autoFocus;
|
|
3336
|
-
domProps["autoCapitalize"] = autoCapitalize;
|
|
3337
|
-
domProps["autoCorrect"] = autoCorrect === void 0 ? void 0 : autoCorrect ? "on" : "off";
|
|
3338
|
-
domProps["spellCheck"] = spellCheck;
|
|
3339
|
-
domProps["autoComplete"] = toHTMLAutoComplete(autoComplete, textContentType);
|
|
3340
|
-
domProps["inputMode"] = toInputMode(inputMode, keyboardType, showSoftInputOnFocus);
|
|
3341
|
-
domProps["enterKeyHint"] = toEnterKeyHint(enterKeyHint, returnKeyType);
|
|
3342
|
-
domProps["dir"] ??= "auto";
|
|
3343
|
-
domProps["onChange"] = handleChange;
|
|
3344
|
-
domProps["onFocus"] = handleFocus;
|
|
3345
|
-
domProps["onBlur"] = handleBlur;
|
|
3346
|
-
domProps["onKeyDown"] = handleKeyDown;
|
|
3347
|
-
domProps["onSelect"] = handleSelect;
|
|
3348
|
-
domProps["onContextMenu"] = handleContextMenu;
|
|
3349
|
-
if (multiline) {
|
|
3350
|
-
domProps["rows"] = numberOfLines ?? 1;
|
|
3351
|
-
domProps["onScroll"] = handleScroll;
|
|
3352
|
-
return /* @__PURE__ */ jsx("textarea", {
|
|
3353
|
-
...domProps,
|
|
3354
|
-
ref: field
|
|
3355
|
-
});
|
|
3356
|
-
}
|
|
3357
|
-
domProps["type"] = secureTextEntry === true ? "password" : "text";
|
|
3358
|
-
return /* @__PURE__ */ jsx("input", {
|
|
3359
|
-
...domProps,
|
|
3360
|
-
ref: field
|
|
3361
|
-
});
|
|
3362
|
-
}
|
|
3363
|
-
const TextInput = Object.assign(TextInputComponent, { State: {
|
|
3364
|
-
currentlyFocusedInput: () => {
|
|
3365
|
-
if (!hasDOM()) return null;
|
|
3366
|
-
const active = document.activeElement;
|
|
3367
|
-
return isField(active) ? active : null;
|
|
3368
|
-
},
|
|
3369
|
-
focusTextInput: (input) => input?.focus(),
|
|
3370
|
-
blurTextInput: (input) => input?.blur()
|
|
3371
|
-
} });
|
|
3372
|
-
export { AccessibilityInfo, Appearance, BackHandler, Dimensions, FlatList, I18nManager, Image, PanResponder, PixelRatio, Platform, Pressable, ScrollView, StatusBar, StyleSheet, Text, TextAncestorContext, TextInput, View, processColor, useColorScheme, usePressability, useWindowDimensions };
|
|
3373
|
-
|
|
3374
|
-
//# sourceMappingURL=index.js.map
|