@rootnative/inertia 0.0.0-alpha.2 → 0.0.0-alpha.4
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/CHANGELOG.md +15 -1
- package/dist/chunk-5I3G43XA.js +8 -0
- package/dist/chunk-6EP3S2PN.js +113 -0
- package/dist/chunk-6FENLMCA.mjs +257 -0
- package/dist/chunk-6UQ4KA6V.js +1011 -0
- package/dist/chunk-I76OC6RX.mjs +1003 -0
- package/dist/chunk-IJNVUM5U.mjs +6 -0
- package/dist/chunk-K4KR5BIS.mjs +6 -0
- package/dist/chunk-L2EVRKSC.mjs +104 -0
- package/dist/chunk-NDKVHL3N.js +8 -0
- package/dist/chunk-OBE7KTMK.mjs +6 -0
- package/dist/chunk-OM5FXU4I.js +8 -0
- package/dist/chunk-Q6ZTMLTI.js +54 -0
- package/dist/chunk-QQJSBIXV.mjs +6 -0
- package/dist/chunk-SCTX5Z7I.js +8 -0
- package/dist/chunk-SFRNO6AW.js +267 -0
- package/dist/chunk-WPPLZNM4.mjs +6 -0
- package/dist/chunk-WZGMAXKC.js +8 -0
- package/dist/chunk-ZQUCQRZT.mjs +52 -0
- package/dist/gestureLayer/index.js +10 -272
- package/dist/gestureLayer/index.mjs +5 -267
- package/dist/index.js +122 -1457
- package/dist/index.mjs +19 -1400
- package/dist/motion/Image.js +8 -1173
- package/dist/motion/Image.mjs +4 -1172
- package/dist/motion/Pressable.js +8 -1173
- package/dist/motion/Pressable.mjs +4 -1172
- package/dist/motion/ScrollView.js +8 -1173
- package/dist/motion/ScrollView.mjs +4 -1172
- package/dist/motion/Text.js +8 -1173
- package/dist/motion/Text.mjs +4 -1172
- package/dist/motion/View.js +8 -1173
- package/dist/motion/View.mjs +4 -1172
- package/dist/touch/index.js +3 -45
- package/dist/touch/index.mjs +2 -44
- package/package.json +1 -1
- package/src/gestures/focusVisibility.ts +15 -4
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk6EP3S2PN_js = require('./chunk-6EP3S2PN.js');
|
|
4
|
+
var chunkSFRNO6AW_js = require('./chunk-SFRNO6AW.js');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var Animated = require('react-native-reanimated');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var Animated__default = /*#__PURE__*/_interopDefault(Animated);
|
|
12
|
+
|
|
13
|
+
var PresenceContext = react.createContext(null);
|
|
14
|
+
function usePresence() {
|
|
15
|
+
return react.useContext(PresenceContext);
|
|
16
|
+
}
|
|
17
|
+
function Presence({ children }) {
|
|
18
|
+
const incoming = react.useMemo(() => {
|
|
19
|
+
const out = [];
|
|
20
|
+
react.Children.forEach(children, (child) => {
|
|
21
|
+
if (!react.isValidElement(child)) return;
|
|
22
|
+
if (child.key === null) {
|
|
23
|
+
if (__DEV__) {
|
|
24
|
+
console.warn(
|
|
25
|
+
"[inertia] <Presence> children must have a `key`. Skipping a keyless child."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
out.push(child);
|
|
31
|
+
});
|
|
32
|
+
return out;
|
|
33
|
+
}, [children]);
|
|
34
|
+
const [exiting, setExiting] = react.useState(
|
|
35
|
+
() => /* @__PURE__ */ new Map()
|
|
36
|
+
);
|
|
37
|
+
const prevIncomingRef = react.useRef(incoming);
|
|
38
|
+
if (prevIncomingRef.current !== incoming) {
|
|
39
|
+
const prev = prevIncomingRef.current;
|
|
40
|
+
prevIncomingRef.current = incoming;
|
|
41
|
+
const incomingKeys = new Set(incoming.map((el) => el.key));
|
|
42
|
+
let next = null;
|
|
43
|
+
const ensureMutable = () => {
|
|
44
|
+
if (!next) next = new Map(exiting);
|
|
45
|
+
return next;
|
|
46
|
+
};
|
|
47
|
+
for (const oldEl of prev) {
|
|
48
|
+
const key = oldEl.key;
|
|
49
|
+
if (!incomingKeys.has(key) && !exiting.has(key)) {
|
|
50
|
+
ensureMutable().set(key, oldEl);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const el of incoming) {
|
|
54
|
+
const key = el.key;
|
|
55
|
+
if (exiting.has(key)) {
|
|
56
|
+
ensureMutable().delete(key);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (next) setExiting(next);
|
|
60
|
+
}
|
|
61
|
+
const handleRemove = react.useCallback((key) => {
|
|
62
|
+
setExiting((prev) => {
|
|
63
|
+
if (!prev.has(key)) return prev;
|
|
64
|
+
const next = new Map(prev);
|
|
65
|
+
next.delete(key);
|
|
66
|
+
return next;
|
|
67
|
+
});
|
|
68
|
+
}, []);
|
|
69
|
+
const renderList = [];
|
|
70
|
+
for (const el of incoming) {
|
|
71
|
+
renderList.push({
|
|
72
|
+
key: el.key,
|
|
73
|
+
element: el,
|
|
74
|
+
isPresent: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
for (const [key, el] of exiting) {
|
|
78
|
+
if (!renderList.some((entry) => entry.key === key)) {
|
|
79
|
+
renderList.push({ key, element: el, isPresent: false });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderList.map(({ key, element, isPresent }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
83
|
+
PresenceItem,
|
|
84
|
+
{
|
|
85
|
+
itemKey: key,
|
|
86
|
+
isPresent,
|
|
87
|
+
onRemove: handleRemove,
|
|
88
|
+
children: element
|
|
89
|
+
},
|
|
90
|
+
key
|
|
91
|
+
)) });
|
|
92
|
+
}
|
|
93
|
+
function PresenceItem({
|
|
94
|
+
itemKey,
|
|
95
|
+
isPresent,
|
|
96
|
+
onRemove,
|
|
97
|
+
children
|
|
98
|
+
}) {
|
|
99
|
+
const value = react.useMemo(
|
|
100
|
+
() => ({
|
|
101
|
+
isPresent,
|
|
102
|
+
safeToRemove: () => onRemove(itemKey)
|
|
103
|
+
}),
|
|
104
|
+
[isPresent, itemKey, onRemove]
|
|
105
|
+
);
|
|
106
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PresenceContext.Provider, { value, children });
|
|
107
|
+
}
|
|
108
|
+
function resolveLayoutTransition(layout) {
|
|
109
|
+
if (!layout) return void 0;
|
|
110
|
+
const cfg = layout === true ? { type: "spring" } : layout;
|
|
111
|
+
if (cfg.type === "no-animation") return void 0;
|
|
112
|
+
if (cfg.type === "timing") {
|
|
113
|
+
let builder2 = Animated.LinearTransition.duration(cfg.duration ?? 300);
|
|
114
|
+
const easing = chunkSFRNO6AW_js.ensureWorkletEasing(cfg.easing);
|
|
115
|
+
if (easing) builder2 = builder2.easing(easing);
|
|
116
|
+
if (cfg.delay) builder2 = builder2.delay(cfg.delay);
|
|
117
|
+
return builder2;
|
|
118
|
+
}
|
|
119
|
+
const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
|
|
120
|
+
const { stiffness, damping, mass } = chunkSFRNO6AW_js.springToReanimated({
|
|
121
|
+
...chunkSFRNO6AW_js.DEFAULT_SPRING,
|
|
122
|
+
...spring
|
|
123
|
+
});
|
|
124
|
+
let builder = Animated.LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
|
|
125
|
+
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
126
|
+
return builder;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/layout/sharedRegistry.ts
|
|
130
|
+
var REGISTRY = /* @__PURE__ */ new Map();
|
|
131
|
+
var SHARED_LAYOUT_TTL_MS = 1e3;
|
|
132
|
+
var now = () => Date.now();
|
|
133
|
+
function registerLayout(id, rect) {
|
|
134
|
+
REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
|
|
135
|
+
}
|
|
136
|
+
function releaseLayout(id, rect) {
|
|
137
|
+
REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
|
|
138
|
+
}
|
|
139
|
+
function consumeLayout(id) {
|
|
140
|
+
const entry = REGISTRY.get(id);
|
|
141
|
+
if (!entry) return void 0;
|
|
142
|
+
REGISTRY.delete(id);
|
|
143
|
+
if (entry.expiresAt < now()) return void 0;
|
|
144
|
+
return entry.rect;
|
|
145
|
+
}
|
|
146
|
+
function useSharedLayout(options) {
|
|
147
|
+
const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
|
|
148
|
+
const dx = Animated.useSharedValue(0);
|
|
149
|
+
const dy = Animated.useSharedValue(0);
|
|
150
|
+
const sx = Animated.useSharedValue(1);
|
|
151
|
+
const sy = Animated.useSharedValue(1);
|
|
152
|
+
const lastRectRef = react.useRef(null);
|
|
153
|
+
const consumedRef = react.useRef(false);
|
|
154
|
+
const transitionRef = react.useRef(transition);
|
|
155
|
+
transitionRef.current = transition;
|
|
156
|
+
const reducedMotionRef = react.useRef(shouldReduceMotion);
|
|
157
|
+
reducedMotionRef.current = shouldReduceMotion;
|
|
158
|
+
const setRef = react.useCallback(
|
|
159
|
+
(node) => {
|
|
160
|
+
if (typeof userRef === "function") userRef(node);
|
|
161
|
+
else if (userRef) userRef.current = node;
|
|
162
|
+
},
|
|
163
|
+
[userRef]
|
|
164
|
+
);
|
|
165
|
+
const onLayout = react.useCallback(
|
|
166
|
+
(event) => {
|
|
167
|
+
userOnLayout?.(event);
|
|
168
|
+
if (!layoutId) return;
|
|
169
|
+
const { x, y, width, height } = event.nativeEvent.layout;
|
|
170
|
+
const rect = { x, y, width, height };
|
|
171
|
+
lastRectRef.current = rect;
|
|
172
|
+
let source;
|
|
173
|
+
if (!consumedRef.current) {
|
|
174
|
+
consumedRef.current = true;
|
|
175
|
+
source = consumeLayout(layoutId);
|
|
176
|
+
}
|
|
177
|
+
registerLayout(layoutId, rect);
|
|
178
|
+
if (source) {
|
|
179
|
+
applyFlip({
|
|
180
|
+
source,
|
|
181
|
+
target: rect,
|
|
182
|
+
dx,
|
|
183
|
+
dy,
|
|
184
|
+
sx,
|
|
185
|
+
sy,
|
|
186
|
+
transition: transitionRef.current,
|
|
187
|
+
shouldReduceMotion: reducedMotionRef.current
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
// dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
|
|
192
|
+
// exhaustive-deps would flag them — including them is harmless and
|
|
193
|
+
// silences the warning.
|
|
194
|
+
[layoutId, userOnLayout, dx, dy, sx, sy]
|
|
195
|
+
);
|
|
196
|
+
react.useEffect(() => {
|
|
197
|
+
consumedRef.current = false;
|
|
198
|
+
}, [layoutId]);
|
|
199
|
+
react.useEffect(() => {
|
|
200
|
+
return () => {
|
|
201
|
+
if (!layoutId) return;
|
|
202
|
+
const rect = lastRectRef.current;
|
|
203
|
+
if (!rect) return;
|
|
204
|
+
releaseLayout(layoutId, rect);
|
|
205
|
+
};
|
|
206
|
+
}, [layoutId]);
|
|
207
|
+
return react.useMemo(
|
|
208
|
+
() => ({
|
|
209
|
+
flip: { dx, dy, sx, sy },
|
|
210
|
+
setRef,
|
|
211
|
+
onLayout
|
|
212
|
+
}),
|
|
213
|
+
[dx, dy, sx, sy, setRef, onLayout]
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function applyFlip(args) {
|
|
217
|
+
const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
|
|
218
|
+
const sourceCenterX = source.x + source.width / 2;
|
|
219
|
+
const sourceCenterY = source.y + source.height / 2;
|
|
220
|
+
const targetCenterX = target.x + target.width / 2;
|
|
221
|
+
const targetCenterY = target.y + target.height / 2;
|
|
222
|
+
const deltaX = sourceCenterX - targetCenterX;
|
|
223
|
+
const deltaY = sourceCenterY - targetCenterY;
|
|
224
|
+
const scaleX = target.width > 0 ? source.width / target.width : 1;
|
|
225
|
+
const scaleY = target.height > 0 ? source.height / target.height : 1;
|
|
226
|
+
if (shouldReduceMotion) {
|
|
227
|
+
dx.value = 0;
|
|
228
|
+
dy.value = 0;
|
|
229
|
+
sx.value = 1;
|
|
230
|
+
sy.value = 1;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (transition?.type === "no-animation") {
|
|
234
|
+
dx.value = 0;
|
|
235
|
+
dy.value = 0;
|
|
236
|
+
sx.value = 1;
|
|
237
|
+
sy.value = 1;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (transition?.type === "timing") {
|
|
241
|
+
const duration = transition.duration ?? 300;
|
|
242
|
+
dx.value = Animated.withSequence(
|
|
243
|
+
Animated.withTiming(deltaX, { duration: 0 }),
|
|
244
|
+
Animated.withTiming(0, { duration })
|
|
245
|
+
);
|
|
246
|
+
dy.value = Animated.withSequence(
|
|
247
|
+
Animated.withTiming(deltaY, { duration: 0 }),
|
|
248
|
+
Animated.withTiming(0, { duration })
|
|
249
|
+
);
|
|
250
|
+
sx.value = Animated.withSequence(
|
|
251
|
+
Animated.withTiming(scaleX, { duration: 0 }),
|
|
252
|
+
Animated.withTiming(1, { duration })
|
|
253
|
+
);
|
|
254
|
+
sy.value = Animated.withSequence(
|
|
255
|
+
Animated.withTiming(scaleY, { duration: 0 }),
|
|
256
|
+
Animated.withTiming(1, { duration })
|
|
257
|
+
);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const springCfg = transition?.type === "spring" ? { ...chunkSFRNO6AW_js.DEFAULT_SPRING, ...transition } : { type: "spring", ...chunkSFRNO6AW_js.DEFAULT_SPRING };
|
|
261
|
+
const springParams = chunkSFRNO6AW_js.springToReanimated(springCfg);
|
|
262
|
+
dx.value = Animated.withSequence(
|
|
263
|
+
Animated.withTiming(deltaX, { duration: 0 }),
|
|
264
|
+
Animated.withSpring(0, springParams)
|
|
265
|
+
);
|
|
266
|
+
dy.value = Animated.withSequence(
|
|
267
|
+
Animated.withTiming(deltaY, { duration: 0 }),
|
|
268
|
+
Animated.withSpring(0, springParams)
|
|
269
|
+
);
|
|
270
|
+
sx.value = Animated.withSequence(
|
|
271
|
+
Animated.withTiming(scaleX, { duration: 0 }),
|
|
272
|
+
Animated.withSpring(1, springParams)
|
|
273
|
+
);
|
|
274
|
+
sy.value = Animated.withSequence(
|
|
275
|
+
Animated.withTiming(scaleY, { duration: 0 }),
|
|
276
|
+
Animated.withSpring(1, springParams)
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
var alreadyChecked = false;
|
|
280
|
+
function ensureReanimatedInstalled() {
|
|
281
|
+
if (!__DEV__ || alreadyChecked) return;
|
|
282
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
alreadyChecked = true;
|
|
286
|
+
const version = Animated.reanimatedVersion;
|
|
287
|
+
if (version) {
|
|
288
|
+
const major = parseInt(version.split(".")[0] ?? "0", 10);
|
|
289
|
+
if (major < 4) {
|
|
290
|
+
console.error(
|
|
291
|
+
`[inertia] react-native-reanimated v${version} is installed, but @rootnative/inertia requires v4.0.0 or later. Upgrade with \`pnpm add react-native-reanimated@^4\` (or your package manager's equivalent).`
|
|
292
|
+
);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const probe = function probe2() {
|
|
297
|
+
"worklet";
|
|
298
|
+
return 0;
|
|
299
|
+
};
|
|
300
|
+
if (typeof probe.__workletHash !== "number") {
|
|
301
|
+
console.error(
|
|
302
|
+
`[inertia] The Reanimated worklets babel plugin is not configured. Add \`'react-native-worklets/plugin'\` as the LAST entry in the \`plugins\` array of your \`babel.config.js\`, then restart Metro with a fresh cache: \`npx expo start -c\` or \`npx react-native start --reset-cache\`.`
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
var TRANSFORM_KEYS = [
|
|
307
|
+
"translateX",
|
|
308
|
+
"translateY",
|
|
309
|
+
"scale",
|
|
310
|
+
"scaleX",
|
|
311
|
+
"scaleY",
|
|
312
|
+
"rotate",
|
|
313
|
+
"rotateX",
|
|
314
|
+
"rotateY"
|
|
315
|
+
];
|
|
316
|
+
var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
|
|
317
|
+
var NUMERIC_TOP_LEVEL_KEYS = [
|
|
318
|
+
"opacity",
|
|
319
|
+
"width",
|
|
320
|
+
"height",
|
|
321
|
+
"borderRadius",
|
|
322
|
+
"shadowOpacity",
|
|
323
|
+
"shadowRadius",
|
|
324
|
+
"elevation"
|
|
325
|
+
];
|
|
326
|
+
var COLOR_KEYS = [
|
|
327
|
+
"backgroundColor",
|
|
328
|
+
"borderColor",
|
|
329
|
+
"color",
|
|
330
|
+
"tintColor",
|
|
331
|
+
"shadowColor"
|
|
332
|
+
];
|
|
333
|
+
var SHADOW_OFFSET_KEYS = ["shadowOffsetWidth", "shadowOffsetHeight"];
|
|
334
|
+
var ALL_KEYS = [
|
|
335
|
+
...TRANSFORM_KEYS,
|
|
336
|
+
...NUMERIC_TOP_LEVEL_KEYS,
|
|
337
|
+
...COLOR_KEYS,
|
|
338
|
+
...SHADOW_OFFSET_KEYS
|
|
339
|
+
];
|
|
340
|
+
var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
|
|
341
|
+
var COLOR_KEY_SET = new Set(COLOR_KEYS);
|
|
342
|
+
var SHADOW_OFFSET_KEY_SET = new Set(SHADOW_OFFSET_KEYS);
|
|
343
|
+
var GESTURE_LAYER_NAMES = [
|
|
344
|
+
"hovered",
|
|
345
|
+
"focused",
|
|
346
|
+
"focusVisible",
|
|
347
|
+
"pressed"
|
|
348
|
+
];
|
|
349
|
+
var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
|
|
350
|
+
var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
|
|
351
|
+
var DEFAULT_RESTING = {
|
|
352
|
+
translateX: 0,
|
|
353
|
+
translateY: 0,
|
|
354
|
+
scale: 1,
|
|
355
|
+
scaleX: 1,
|
|
356
|
+
scaleY: 1,
|
|
357
|
+
rotate: 0,
|
|
358
|
+
rotateX: 0,
|
|
359
|
+
rotateY: 0,
|
|
360
|
+
opacity: 1,
|
|
361
|
+
width: 0,
|
|
362
|
+
height: 0,
|
|
363
|
+
borderRadius: 0,
|
|
364
|
+
shadowOpacity: 0,
|
|
365
|
+
shadowRadius: 0,
|
|
366
|
+
elevation: 0,
|
|
367
|
+
// 'transparent' is the only safe universal default for colors: it works as
|
|
368
|
+
// an initial seed for any color animation (no jarring opaque flash on mount
|
|
369
|
+
// when `initial` is omitted) and rgba(0,0,0,0) interpolates cleanly into
|
|
370
|
+
// any opaque target via Reanimated's color util.
|
|
371
|
+
backgroundColor: "transparent",
|
|
372
|
+
borderColor: "transparent",
|
|
373
|
+
color: "transparent",
|
|
374
|
+
tintColor: "transparent",
|
|
375
|
+
shadowColor: "transparent",
|
|
376
|
+
shadowOffsetWidth: 0,
|
|
377
|
+
shadowOffsetHeight: 0
|
|
378
|
+
};
|
|
379
|
+
function transitionFor(prop, transition) {
|
|
380
|
+
if (!transition) return void 0;
|
|
381
|
+
if (typeof transition === "string") return void 0;
|
|
382
|
+
if (chunkSFRNO6AW_js.isTopLevelTransition(transition)) return transition;
|
|
383
|
+
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
384
|
+
return transition[prop];
|
|
385
|
+
}
|
|
386
|
+
function gestureLayerTransitionFor(layer, transition) {
|
|
387
|
+
if (!transition) return void 0;
|
|
388
|
+
if (typeof transition === "string") return void 0;
|
|
389
|
+
if (chunkSFRNO6AW_js.isTopLevelTransition(transition)) return transition;
|
|
390
|
+
return transition[layer];
|
|
391
|
+
}
|
|
392
|
+
function createMotionComponent(Component) {
|
|
393
|
+
ensureReanimatedInstalled();
|
|
394
|
+
const AnimatedComponent = Animated__default.default.createAnimatedComponent(
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
396
|
+
Component
|
|
397
|
+
);
|
|
398
|
+
const Motion = react.forwardRef(function Motion2(props, ref) {
|
|
399
|
+
const {
|
|
400
|
+
initial,
|
|
401
|
+
animate,
|
|
402
|
+
exit,
|
|
403
|
+
transition: transitionProp,
|
|
404
|
+
variants,
|
|
405
|
+
controller,
|
|
406
|
+
gesture,
|
|
407
|
+
layout: layoutProp,
|
|
408
|
+
layoutId,
|
|
409
|
+
onAnimationEnd,
|
|
410
|
+
style,
|
|
411
|
+
onLayout: userOnLayout,
|
|
412
|
+
...rest
|
|
413
|
+
} = props;
|
|
414
|
+
const namedTransitions = chunk6EP3S2PN_js.useNamedTransitions();
|
|
415
|
+
const transition = chunk6EP3S2PN_js.resolveNamedTransitionProp(
|
|
416
|
+
transitionProp,
|
|
417
|
+
namedTransitions
|
|
418
|
+
);
|
|
419
|
+
const layout = typeof layoutProp === "string" ? chunk6EP3S2PN_js.lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
|
|
420
|
+
if (__DEV__ && typeof style === "function") {
|
|
421
|
+
throw new Error(
|
|
422
|
+
"[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
const presence = usePresence();
|
|
426
|
+
const isExiting = presence !== null && presence.isPresent === false;
|
|
427
|
+
const shouldReduceMotion = chunk6EP3S2PN_js.useShouldReduceMotion();
|
|
428
|
+
const onAnimationEndRef = react.useRef(onAnimationEnd);
|
|
429
|
+
onAnimationEndRef.current = onAnimationEnd;
|
|
430
|
+
const variantKey = useControllerKey(controller);
|
|
431
|
+
const resolvedAnimate = resolveAnimateInput(
|
|
432
|
+
animate,
|
|
433
|
+
variants,
|
|
434
|
+
variantKey
|
|
435
|
+
);
|
|
436
|
+
const animateRecord = resolvedAnimate ?? {};
|
|
437
|
+
const initialRecord = initial && initial !== false ? initial : void 0;
|
|
438
|
+
const exitRecord = exit ? exit : void 0;
|
|
439
|
+
const [pressed, setPressed] = react.useState(false);
|
|
440
|
+
const [focused, setFocused] = react.useState(false);
|
|
441
|
+
const [focusVisible, setFocusVisible] = react.useState(false);
|
|
442
|
+
const [hovered, setHovered] = react.useState(false);
|
|
443
|
+
const touched = /* @__PURE__ */ new Set();
|
|
444
|
+
collectTouchedKeys(touched, animateRecord);
|
|
445
|
+
if (initialRecord) collectTouchedKeys(touched, initialRecord);
|
|
446
|
+
if (variants) {
|
|
447
|
+
for (const variant of Object.values(variants)) {
|
|
448
|
+
if (!variant) continue;
|
|
449
|
+
collectTouchedKeys(touched, variant);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (gesture) {
|
|
453
|
+
for (const subState of [
|
|
454
|
+
gesture.pressed,
|
|
455
|
+
gesture.focused,
|
|
456
|
+
gesture.focusVisible,
|
|
457
|
+
gesture.hovered
|
|
458
|
+
]) {
|
|
459
|
+
if (!subState) continue;
|
|
460
|
+
collectTouchedKeys(touched, subState);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (exitRecord) collectTouchedKeys(touched, exitRecord);
|
|
464
|
+
const activeKeysRef = react.useRef(null);
|
|
465
|
+
const hasTransformRef = react.useRef(false);
|
|
466
|
+
const hasShadowOffsetRef = react.useRef(false);
|
|
467
|
+
const prevActive = activeKeysRef.current;
|
|
468
|
+
let grew = prevActive === null;
|
|
469
|
+
if (!grew && prevActive) {
|
|
470
|
+
for (const k of touched) {
|
|
471
|
+
if (!prevActive.includes(k)) {
|
|
472
|
+
grew = true;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (grew) {
|
|
478
|
+
const merged = new Set(prevActive ?? []);
|
|
479
|
+
for (const k of touched) merged.add(k);
|
|
480
|
+
activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
|
|
481
|
+
hasTransformRef.current = activeKeysRef.current.some(
|
|
482
|
+
(k) => TRANSFORM_KEY_SET.has(k)
|
|
483
|
+
);
|
|
484
|
+
hasShadowOffsetRef.current = activeKeysRef.current.some(
|
|
485
|
+
(k) => SHADOW_OFFSET_KEY_SET.has(k)
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
const sharedValues = useAnimatableSharedValues((key) => {
|
|
489
|
+
if (SHADOW_OFFSET_KEY_SET.has(key)) {
|
|
490
|
+
const axis = shadowOffsetAxisFor(key);
|
|
491
|
+
if (initial === false) {
|
|
492
|
+
return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
|
|
493
|
+
}
|
|
494
|
+
return shadowOffsetAxisValue(
|
|
495
|
+
initialRecord?.shadowOffset,
|
|
496
|
+
axis
|
|
497
|
+
) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
|
|
498
|
+
}
|
|
499
|
+
if (initial === false) {
|
|
500
|
+
const a = animateRecord[key];
|
|
501
|
+
return restValue(a) ?? DEFAULT_RESTING[key];
|
|
502
|
+
}
|
|
503
|
+
return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
|
|
504
|
+
});
|
|
505
|
+
const pressedProgress = Animated.useSharedValue(0);
|
|
506
|
+
const focusedProgress = Animated.useSharedValue(0);
|
|
507
|
+
const focusVisibleProgress = Animated.useSharedValue(0);
|
|
508
|
+
const hoveredProgress = Animated.useSharedValue(0);
|
|
509
|
+
const gestureSV = Animated.useSharedValue(
|
|
510
|
+
resolveGestureLayers(gesture)
|
|
511
|
+
);
|
|
512
|
+
const gestureTargetsSig = chunkSFRNO6AW_js.stableSig(gesture);
|
|
513
|
+
react.useEffect(() => {
|
|
514
|
+
gestureSV.value = resolveGestureLayers(gesture);
|
|
515
|
+
}, [gestureTargetsSig]);
|
|
516
|
+
const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
|
|
517
|
+
const baseSig = chunkSFRNO6AW_js.stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
|
|
518
|
+
const transitionSig = chunkSFRNO6AW_js.stableSig(transition);
|
|
519
|
+
const safeToRemoveRef = react.useRef(void 0);
|
|
520
|
+
safeToRemoveRef.current = presence?.safeToRemove;
|
|
521
|
+
react.useEffect(() => {
|
|
522
|
+
if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
|
|
523
|
+
safeToRemoveRef.current?.();
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
let pending = 0;
|
|
527
|
+
let done = false;
|
|
528
|
+
const onSettle = () => {
|
|
529
|
+
if (done) return;
|
|
530
|
+
pending--;
|
|
531
|
+
if (pending <= 0) {
|
|
532
|
+
done = true;
|
|
533
|
+
if (isExiting) safeToRemoveRef.current?.();
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
let transformPending = 0;
|
|
537
|
+
for (const k of ALL_KEYS) {
|
|
538
|
+
if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
|
|
539
|
+
transformPending++;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
|
|
543
|
+
for (const key of ALL_KEYS) {
|
|
544
|
+
const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
|
|
545
|
+
baseRecord.shadowOffset,
|
|
546
|
+
shadowOffsetAxisFor(key)
|
|
547
|
+
) : baseRecord[key];
|
|
548
|
+
if (target === void 0) continue;
|
|
549
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
|
|
550
|
+
SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
|
|
551
|
+
transition
|
|
552
|
+
);
|
|
553
|
+
if (isExiting) pending++;
|
|
554
|
+
const factory = makeKeyCallbackFactory(
|
|
555
|
+
key,
|
|
556
|
+
sharedValues[key],
|
|
557
|
+
targetEndValue(target),
|
|
558
|
+
onAnimationEndRef,
|
|
559
|
+
{
|
|
560
|
+
stepCount: stepCountOf(target),
|
|
561
|
+
totalIterations: totalIterationsOf(cfg)
|
|
562
|
+
},
|
|
563
|
+
isExiting ? onSettle : void 0,
|
|
564
|
+
TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
|
|
565
|
+
);
|
|
566
|
+
sharedValues[key].value = chunkSFRNO6AW_js.resolveAnimatableValue(
|
|
567
|
+
target,
|
|
568
|
+
cfg,
|
|
569
|
+
factory
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
if (isExiting && pending === 0) {
|
|
573
|
+
safeToRemoveRef.current?.();
|
|
574
|
+
}
|
|
575
|
+
}, [baseSig, transitionSig]);
|
|
576
|
+
useGestureLayerProgress(
|
|
577
|
+
pressedProgress,
|
|
578
|
+
pressed,
|
|
579
|
+
gesture?.pressed != null,
|
|
580
|
+
"pressed",
|
|
581
|
+
transition,
|
|
582
|
+
isExiting,
|
|
583
|
+
shouldReduceMotion
|
|
584
|
+
);
|
|
585
|
+
useGestureLayerProgress(
|
|
586
|
+
focusedProgress,
|
|
587
|
+
focused,
|
|
588
|
+
gesture?.focused != null,
|
|
589
|
+
"focused",
|
|
590
|
+
transition,
|
|
591
|
+
isExiting,
|
|
592
|
+
shouldReduceMotion
|
|
593
|
+
);
|
|
594
|
+
useGestureLayerProgress(
|
|
595
|
+
focusVisibleProgress,
|
|
596
|
+
focusVisible,
|
|
597
|
+
gesture?.focusVisible != null,
|
|
598
|
+
"focusVisible",
|
|
599
|
+
transition,
|
|
600
|
+
isExiting,
|
|
601
|
+
shouldReduceMotion
|
|
602
|
+
);
|
|
603
|
+
useGestureLayerProgress(
|
|
604
|
+
hoveredProgress,
|
|
605
|
+
hovered,
|
|
606
|
+
gesture?.hovered != null,
|
|
607
|
+
"hovered",
|
|
608
|
+
transition,
|
|
609
|
+
isExiting,
|
|
610
|
+
shouldReduceMotion
|
|
611
|
+
);
|
|
612
|
+
const sharedLayout = useSharedLayout({
|
|
613
|
+
layoutId,
|
|
614
|
+
userRef: ref,
|
|
615
|
+
transition: chunkSFRNO6AW_js.isTopLevelTransition(transition) ? transition : void 0,
|
|
616
|
+
shouldReduceMotion,
|
|
617
|
+
userOnLayout
|
|
618
|
+
});
|
|
619
|
+
const flip = sharedLayout.flip;
|
|
620
|
+
const hasLayoutId = layoutId !== void 0;
|
|
621
|
+
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
622
|
+
const activeKeys = activeKeysRef.current;
|
|
623
|
+
const hasTransform = hasTransformRef.current;
|
|
624
|
+
const hasShadowOffset = hasShadowOffsetRef.current;
|
|
625
|
+
const out = {};
|
|
626
|
+
const transform = [];
|
|
627
|
+
let shadowOffsetW = 0;
|
|
628
|
+
let shadowOffsetH = 0;
|
|
629
|
+
const ph = hoveredProgress.value;
|
|
630
|
+
const pf = focusedProgress.value;
|
|
631
|
+
const pfv = focusVisibleProgress.value;
|
|
632
|
+
const pp = pressedProgress.value;
|
|
633
|
+
const layers = gestureSV.value;
|
|
634
|
+
const hoveredLayer = layers ? layers.hovered : null;
|
|
635
|
+
const focusedLayer = layers ? layers.focused : null;
|
|
636
|
+
const focusVisibleLayer = layers ? layers.focusVisible : null;
|
|
637
|
+
const pressedLayer = layers ? layers.pressed : null;
|
|
638
|
+
for (const key of activeKeys) {
|
|
639
|
+
let v = sharedValues[key].value;
|
|
640
|
+
const isColor = COLOR_KEY_SET.has(key);
|
|
641
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
|
|
642
|
+
const t = hoveredLayer[key];
|
|
643
|
+
v = isColor ? Animated.interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
|
|
644
|
+
}
|
|
645
|
+
if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
|
|
646
|
+
const t = focusedLayer[key];
|
|
647
|
+
v = isColor ? Animated.interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
|
|
648
|
+
}
|
|
649
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
|
|
650
|
+
const t = focusVisibleLayer[key];
|
|
651
|
+
v = isColor ? Animated.interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
|
|
652
|
+
}
|
|
653
|
+
if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
|
|
654
|
+
const t = pressedLayer[key];
|
|
655
|
+
v = isColor ? Animated.interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
|
|
656
|
+
}
|
|
657
|
+
if (TRANSFORM_KEY_SET.has(key)) {
|
|
658
|
+
transform.push(
|
|
659
|
+
ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
|
|
660
|
+
);
|
|
661
|
+
} else if (key === "shadowOffsetWidth") {
|
|
662
|
+
shadowOffsetW = v;
|
|
663
|
+
} else if (key === "shadowOffsetHeight") {
|
|
664
|
+
shadowOffsetH = v;
|
|
665
|
+
} else {
|
|
666
|
+
out[key] = v;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (hasLayoutId) {
|
|
670
|
+
transform.push({ translateX: flip.dx.value });
|
|
671
|
+
transform.push({ translateY: flip.dy.value });
|
|
672
|
+
transform.push({ scaleX: flip.sx.value });
|
|
673
|
+
transform.push({ scaleY: flip.sy.value });
|
|
674
|
+
}
|
|
675
|
+
if (hasTransform || hasLayoutId) out.transform = transform;
|
|
676
|
+
if (hasShadowOffset) {
|
|
677
|
+
out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
|
|
678
|
+
}
|
|
679
|
+
return out;
|
|
680
|
+
});
|
|
681
|
+
const mergedStyle = react.useMemo(
|
|
682
|
+
() => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
|
|
683
|
+
[style, animatedStyle, isExiting]
|
|
684
|
+
);
|
|
685
|
+
const gestureHandlers = useGestureHandlers(
|
|
686
|
+
gesture,
|
|
687
|
+
rest,
|
|
688
|
+
setPressed,
|
|
689
|
+
setFocused,
|
|
690
|
+
setFocusVisible,
|
|
691
|
+
setHovered
|
|
692
|
+
);
|
|
693
|
+
const layoutSig = chunkSFRNO6AW_js.stableSig(layout);
|
|
694
|
+
const layoutTransition = react.useMemo(
|
|
695
|
+
() => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
|
|
696
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
697
|
+
[layoutSig, shouldReduceMotion]
|
|
698
|
+
);
|
|
699
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
700
|
+
AnimatedComponent,
|
|
701
|
+
{
|
|
702
|
+
ref: sharedLayout.setRef,
|
|
703
|
+
...rest,
|
|
704
|
+
...gestureHandlers,
|
|
705
|
+
onLayout: sharedLayout.onLayout,
|
|
706
|
+
layout: layoutTransition,
|
|
707
|
+
style: mergedStyle
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
});
|
|
711
|
+
Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
712
|
+
return Motion;
|
|
713
|
+
}
|
|
714
|
+
function useAnimatableSharedValues(init) {
|
|
715
|
+
const translateX = Animated.useSharedValue(init("translateX"));
|
|
716
|
+
const translateY = Animated.useSharedValue(init("translateY"));
|
|
717
|
+
const scale = Animated.useSharedValue(init("scale"));
|
|
718
|
+
const scaleX = Animated.useSharedValue(init("scaleX"));
|
|
719
|
+
const scaleY = Animated.useSharedValue(init("scaleY"));
|
|
720
|
+
const rotate = Animated.useSharedValue(init("rotate"));
|
|
721
|
+
const rotateX = Animated.useSharedValue(init("rotateX"));
|
|
722
|
+
const rotateY = Animated.useSharedValue(init("rotateY"));
|
|
723
|
+
const opacity = Animated.useSharedValue(init("opacity"));
|
|
724
|
+
const width = Animated.useSharedValue(init("width"));
|
|
725
|
+
const height = Animated.useSharedValue(init("height"));
|
|
726
|
+
const borderRadius = Animated.useSharedValue(init("borderRadius"));
|
|
727
|
+
const shadowOpacity = Animated.useSharedValue(init("shadowOpacity"));
|
|
728
|
+
const shadowRadius = Animated.useSharedValue(init("shadowRadius"));
|
|
729
|
+
const elevation = Animated.useSharedValue(init("elevation"));
|
|
730
|
+
const backgroundColor = Animated.useSharedValue(
|
|
731
|
+
init("backgroundColor")
|
|
732
|
+
);
|
|
733
|
+
const borderColor = Animated.useSharedValue(init("borderColor"));
|
|
734
|
+
const color = Animated.useSharedValue(init("color"));
|
|
735
|
+
const tintColor = Animated.useSharedValue(init("tintColor"));
|
|
736
|
+
const shadowColor = Animated.useSharedValue(init("shadowColor"));
|
|
737
|
+
const shadowOffsetWidth = Animated.useSharedValue(
|
|
738
|
+
init("shadowOffsetWidth")
|
|
739
|
+
);
|
|
740
|
+
const shadowOffsetHeight = Animated.useSharedValue(
|
|
741
|
+
init("shadowOffsetHeight")
|
|
742
|
+
);
|
|
743
|
+
const ref = react.useRef(null);
|
|
744
|
+
if (ref.current === null) {
|
|
745
|
+
ref.current = {
|
|
746
|
+
translateX,
|
|
747
|
+
translateY,
|
|
748
|
+
scale,
|
|
749
|
+
scaleX,
|
|
750
|
+
scaleY,
|
|
751
|
+
rotate,
|
|
752
|
+
rotateX,
|
|
753
|
+
rotateY,
|
|
754
|
+
opacity,
|
|
755
|
+
width,
|
|
756
|
+
height,
|
|
757
|
+
borderRadius,
|
|
758
|
+
shadowOpacity,
|
|
759
|
+
shadowRadius,
|
|
760
|
+
elevation,
|
|
761
|
+
backgroundColor,
|
|
762
|
+
borderColor,
|
|
763
|
+
color,
|
|
764
|
+
tintColor,
|
|
765
|
+
shadowColor,
|
|
766
|
+
shadowOffsetWidth,
|
|
767
|
+
shadowOffsetHeight
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
return ref.current;
|
|
771
|
+
}
|
|
772
|
+
function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, meta, onSettle, transformGroup) {
|
|
773
|
+
if (!onAnimationEndRef.current && !onSettle) return void 0;
|
|
774
|
+
const state = { iteration: 0 };
|
|
775
|
+
const isTransformKey = TRANSFORM_KEY_SET.has(key);
|
|
776
|
+
const dispatch = (rawPhase, step, finished, value) => {
|
|
777
|
+
const isLastIteration = state.iteration >= meta.totalIterations - 1;
|
|
778
|
+
let phase;
|
|
779
|
+
let isTerminal = false;
|
|
780
|
+
if (rawPhase === "step") {
|
|
781
|
+
const isLastInPass = step !== void 0 && step === meta.stepCount - 1;
|
|
782
|
+
if (!isLastInPass) {
|
|
783
|
+
phase = "step";
|
|
784
|
+
} else if (isLastIteration) {
|
|
785
|
+
phase = "animation";
|
|
786
|
+
isTerminal = true;
|
|
787
|
+
} else {
|
|
788
|
+
phase = "sequence";
|
|
789
|
+
}
|
|
790
|
+
} else if (isLastIteration) {
|
|
791
|
+
phase = "animation";
|
|
792
|
+
isTerminal = true;
|
|
793
|
+
} else {
|
|
794
|
+
phase = "repeat";
|
|
795
|
+
}
|
|
796
|
+
const reportedIteration = state.iteration;
|
|
797
|
+
if (phase === "sequence" || phase === "repeat") state.iteration++;
|
|
798
|
+
const fn = onAnimationEndRef.current;
|
|
799
|
+
if (fn) {
|
|
800
|
+
if (isTransformKey && transformGroup && phase === "animation") {
|
|
801
|
+
transformGroup.remaining--;
|
|
802
|
+
if (transformGroup.remaining <= 0) {
|
|
803
|
+
fn({
|
|
804
|
+
key: "transform",
|
|
805
|
+
finished,
|
|
806
|
+
value,
|
|
807
|
+
target,
|
|
808
|
+
phase,
|
|
809
|
+
step,
|
|
810
|
+
iteration: reportedIteration
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
} else {
|
|
814
|
+
fn({
|
|
815
|
+
key,
|
|
816
|
+
finished,
|
|
817
|
+
value,
|
|
818
|
+
target,
|
|
819
|
+
phase,
|
|
820
|
+
step,
|
|
821
|
+
iteration: reportedIteration
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (onSettle && isTerminal) onSettle();
|
|
826
|
+
};
|
|
827
|
+
return (rawPhase, step) => {
|
|
828
|
+
const cb = (finished) => {
|
|
829
|
+
"worklet";
|
|
830
|
+
Animated.runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
831
|
+
};
|
|
832
|
+
return cb;
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function shadowOffsetAxisFor(key) {
|
|
836
|
+
return key === "shadowOffsetWidth" ? "width" : "height";
|
|
837
|
+
}
|
|
838
|
+
function shadowOffsetAxisValue(source, axis) {
|
|
839
|
+
return source?.[axis];
|
|
840
|
+
}
|
|
841
|
+
function collectTouchedKeys(touched, record) {
|
|
842
|
+
for (const k of ALL_KEYS) {
|
|
843
|
+
if (k in record) touched.add(k);
|
|
844
|
+
}
|
|
845
|
+
if ("shadowOffset" in record && record.shadowOffset) {
|
|
846
|
+
const so = record.shadowOffset;
|
|
847
|
+
if (so.width !== void 0) touched.add("shadowOffsetWidth");
|
|
848
|
+
if (so.height !== void 0) touched.add("shadowOffsetHeight");
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function stepCountOf(v) {
|
|
852
|
+
if (Array.isArray(v)) return v.length;
|
|
853
|
+
return 1;
|
|
854
|
+
}
|
|
855
|
+
function totalIterationsOf(cfg) {
|
|
856
|
+
if (!cfg || cfg.type === "no-animation" || cfg.type === "decay") return 1;
|
|
857
|
+
const r = cfg.repeat;
|
|
858
|
+
if (r === void 0) return 1;
|
|
859
|
+
if (r === "infinite") return Number.POSITIVE_INFINITY;
|
|
860
|
+
if (typeof r === "number") return r;
|
|
861
|
+
if (r.count === "infinite") return Number.POSITIVE_INFINITY;
|
|
862
|
+
return r.count;
|
|
863
|
+
}
|
|
864
|
+
function targetEndValue(v) {
|
|
865
|
+
if (v === void 0) return void 0;
|
|
866
|
+
if (typeof v === "number" || typeof v === "string") return v;
|
|
867
|
+
if (Array.isArray(v)) {
|
|
868
|
+
return v.length > 0 ? targetEndValue(v[v.length - 1]) : void 0;
|
|
869
|
+
}
|
|
870
|
+
if (typeof v === "object" && v !== null && "to" in v) {
|
|
871
|
+
const to = v.to;
|
|
872
|
+
return typeof to === "number" || typeof to === "string" ? to : void 0;
|
|
873
|
+
}
|
|
874
|
+
return void 0;
|
|
875
|
+
}
|
|
876
|
+
function useControllerKey(controller) {
|
|
877
|
+
const [, setTick] = react.useState(0);
|
|
878
|
+
react.useEffect(() => {
|
|
879
|
+
if (!controller) return;
|
|
880
|
+
const unsub = controller.subscribe(() => setTick((n) => n + 1));
|
|
881
|
+
return unsub;
|
|
882
|
+
}, [controller]);
|
|
883
|
+
return controller?.current;
|
|
884
|
+
}
|
|
885
|
+
function resolveAnimateInput(animate, variants, controllerKey) {
|
|
886
|
+
if (controllerKey !== void 0 && variants && controllerKey in variants) {
|
|
887
|
+
return variants[controllerKey];
|
|
888
|
+
}
|
|
889
|
+
if (typeof animate === "string") {
|
|
890
|
+
if (variants && animate in variants) return variants[animate];
|
|
891
|
+
if (__DEV__) {
|
|
892
|
+
console.warn(
|
|
893
|
+
`[inertia] animate="${animate}" but no matching variant. Did you forget to pass \`variants\`?`
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return void 0;
|
|
897
|
+
}
|
|
898
|
+
return animate;
|
|
899
|
+
}
|
|
900
|
+
function restValue(v) {
|
|
901
|
+
if (v === void 0) return void 0;
|
|
902
|
+
if (typeof v === "number" || typeof v === "string") return v;
|
|
903
|
+
if (Array.isArray(v)) {
|
|
904
|
+
return v.length > 0 ? restValue(v[0]) : void 0;
|
|
905
|
+
}
|
|
906
|
+
if (typeof v === "object" && v !== null && "to" in v) {
|
|
907
|
+
const to = v.to;
|
|
908
|
+
return typeof to === "number" || typeof to === "string" ? to : void 0;
|
|
909
|
+
}
|
|
910
|
+
return void 0;
|
|
911
|
+
}
|
|
912
|
+
function resolveGestureLayers(gesture) {
|
|
913
|
+
if (!gesture) return null;
|
|
914
|
+
const out = {};
|
|
915
|
+
for (const layer of GESTURE_LAYER_NAMES) {
|
|
916
|
+
const subState = gesture[layer];
|
|
917
|
+
if (!subState) continue;
|
|
918
|
+
const resolved = {};
|
|
919
|
+
for (const key of ALL_KEYS) {
|
|
920
|
+
if (SHADOW_OFFSET_KEY_SET.has(key)) {
|
|
921
|
+
const axis = shadowOffsetAxisFor(key);
|
|
922
|
+
const so = subState.shadowOffset;
|
|
923
|
+
const v = shadowOffsetAxisValue(so, axis);
|
|
924
|
+
if (v !== void 0) resolved[key] = v;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
const raw = subState[key];
|
|
928
|
+
if (raw === void 0) continue;
|
|
929
|
+
const t = targetEndValue(raw);
|
|
930
|
+
if (t !== void 0) resolved[key] = t;
|
|
931
|
+
}
|
|
932
|
+
out[layer] = resolved;
|
|
933
|
+
}
|
|
934
|
+
return out;
|
|
935
|
+
}
|
|
936
|
+
function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
|
|
937
|
+
const layerCfgSig = chunkSFRNO6AW_js.stableSig(gestureLayerTransitionFor(layer, transition));
|
|
938
|
+
react.useEffect(() => {
|
|
939
|
+
if (!declared) return;
|
|
940
|
+
if (isExiting) {
|
|
941
|
+
progress.value = 0;
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
const target = active ? 1 : 0;
|
|
945
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
|
|
946
|
+
progress.value = chunkSFRNO6AW_js.resolveTransition(cfg, target);
|
|
947
|
+
}, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
|
|
948
|
+
}
|
|
949
|
+
function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
|
|
950
|
+
const hasPressed = gesture?.pressed ? 1 : 0;
|
|
951
|
+
const hasFocused = gesture?.focused ? 1 : 0;
|
|
952
|
+
const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
|
|
953
|
+
const hasHovered = gesture?.hovered ? 1 : 0;
|
|
954
|
+
return react.useMemo(() => {
|
|
955
|
+
if (!gesture) return {};
|
|
956
|
+
const handlers = {};
|
|
957
|
+
if (gesture.pressed) {
|
|
958
|
+
handlers.onTouchStart = compose(rest.onTouchStart, () => setPressed(true));
|
|
959
|
+
handlers.onTouchEnd = compose(rest.onTouchEnd, () => setPressed(false));
|
|
960
|
+
handlers.onTouchCancel = compose(
|
|
961
|
+
rest.onTouchCancel,
|
|
962
|
+
() => setPressed(false)
|
|
963
|
+
);
|
|
964
|
+
handlers.onPressIn = compose(rest.onPressIn, () => setPressed(true));
|
|
965
|
+
handlers.onPressOut = compose(rest.onPressOut, () => setPressed(false));
|
|
966
|
+
}
|
|
967
|
+
if (gesture.focused || gesture.focusVisible) {
|
|
968
|
+
handlers.onFocus = compose(rest.onFocus, () => {
|
|
969
|
+
if (gesture.focused) setFocused(true);
|
|
970
|
+
if (gesture.focusVisible && chunk6EP3S2PN_js.isFocusVisible()) setFocusVisible(true);
|
|
971
|
+
});
|
|
972
|
+
handlers.onBlur = compose(rest.onBlur, () => {
|
|
973
|
+
if (gesture.focused) setFocused(false);
|
|
974
|
+
if (gesture.focusVisible) setFocusVisible(false);
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
if (gesture.hovered) {
|
|
978
|
+
handlers.onMouseEnter = compose(rest.onMouseEnter, () => setHovered(true));
|
|
979
|
+
handlers.onMouseLeave = compose(
|
|
980
|
+
rest.onMouseLeave,
|
|
981
|
+
() => setHovered(false)
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
return handlers;
|
|
985
|
+
}, [
|
|
986
|
+
hasPressed,
|
|
987
|
+
hasFocused,
|
|
988
|
+
hasFocusVisible,
|
|
989
|
+
hasHovered,
|
|
990
|
+
rest.onTouchStart,
|
|
991
|
+
rest.onTouchEnd,
|
|
992
|
+
rest.onTouchCancel,
|
|
993
|
+
rest.onPressIn,
|
|
994
|
+
rest.onPressOut,
|
|
995
|
+
rest.onFocus,
|
|
996
|
+
rest.onBlur,
|
|
997
|
+
rest.onMouseEnter,
|
|
998
|
+
rest.onMouseLeave
|
|
999
|
+
]);
|
|
1000
|
+
}
|
|
1001
|
+
function compose(user, ours) {
|
|
1002
|
+
if (typeof user !== "function") return ours;
|
|
1003
|
+
return (event) => {
|
|
1004
|
+
user(event);
|
|
1005
|
+
ours(event);
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
exports.Presence = Presence;
|
|
1010
|
+
exports.createMotionComponent = createMotionComponent;
|
|
1011
|
+
exports.usePresence = usePresence;
|