@tamagui/animations-reanimated 2.7.7 → 3.0.0-beta.643.1

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.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,36 +6,27 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var createAnimations_exports = {};
35
- __export(createAnimations_exports, {
36
- createAnimations: () => createAnimations
37
- });
29
+ __export(createAnimations_exports, { createAnimations: () => createAnimations });
38
30
  module.exports = __toCommonJS(createAnimations_exports);
39
31
  var import_animation_helpers = require("@tamagui/animation-helpers");
40
32
  var import_core = require("@tamagui/core");
@@ -43,917 +35,968 @@ var import_normalize_colors = __toESM(require("@react-native/normalize-colors"),
43
35
  var import_react = __toESM(require("react"), 1);
44
36
  var import_react_native_reanimated = __toESM(require("react-native-reanimated"), 1);
45
37
  var import_jsx_runtime = require("react/jsx-runtime");
46
- const getDefaultExport = module2 => {
47
- const mod = module2;
48
- if (mod.__esModule || mod[Symbol.toStringTag] === "Module") {
49
- return mod.default || mod;
50
- }
51
- return mod;
38
+ const getDefaultExport = (module2) => {
39
+ const mod = module2;
40
+ if (mod.__esModule || mod[Symbol.toStringTag] === "Module") {
41
+ return mod.default || mod;
42
+ }
43
+ return mod;
52
44
  };
53
45
  const Animated = getDefaultExport(import_react_native_reanimated.default);
54
- const silenceAnimatedComponentDevCheck = style => {
55
- if (process.env.NODE_ENV !== "development" || import_core.isWeb || !style || typeof style !== "object") {
56
- return;
57
- }
58
- Object.defineProperty(style, "_requiresAnimatedComponent", {
59
- configurable: true,
60
- enumerable: false,
61
- value: true
62
- });
46
+ const silenceAnimatedComponentDevCheck = (style) => {
47
+ if (process.env.NODE_ENV !== "development" || import_core.isWeb || !style || typeof style !== "object") {
48
+ return;
49
+ }
50
+ Object.defineProperty(style, "_requiresAnimatedComponent", {
51
+ configurable: true,
52
+ enumerable: false,
53
+ value: true
54
+ });
63
55
  };
64
56
  const resolveDynamicValue = (value, isDark) => {
65
- if (value !== null && typeof value === "object" && "dynamic" in value && typeof value.dynamic === "object") {
66
- const dynamic = value.dynamic;
67
- return isDark ? dynamic.dark : dynamic.light;
68
- }
69
- return value;
57
+ if (value !== null && typeof value === "object" && "dynamic" in value && typeof value.dynamic === "object") {
58
+ const dynamic = value.dynamic;
59
+ return isDark ? dynamic.dark : dynamic.light;
60
+ }
61
+ return value;
70
62
  };
71
63
  const updateMapperState = import_core.isWeb ? (state, emitted) => {
72
- state.value.emitted = emitted;
64
+ state.value.emitted = emitted;
73
65
  } : (state, emitted) => {
74
- "worklet";
75
-
76
- if (!globalThis._WORKLET) return;
77
- state.modify(current => {
78
- current.emitted = emitted;
79
- return current;
80
- }, false);
66
+ "worklet";
67
+ if (!globalThis._WORKLET) return;
68
+ state.modify((current) => {
69
+ current.emitted = emitted;
70
+ return current;
71
+ }, false);
81
72
  };
82
- const cloneAnimationValue = value => {
83
- if (Array.isArray(value)) {
84
- return value.map(cloneAnimationValue);
85
- }
86
- if (value && typeof value === "object") {
87
- const next = {};
88
- for (const key in value) {
89
- next[key] = cloneAnimationValue(value[key]);
90
- }
91
- return next;
92
- }
93
- return value;
73
+ const cloneAnimationValue = (value) => {
74
+ if (Array.isArray(value)) {
75
+ return value.map(cloneAnimationValue);
76
+ }
77
+ if (value && typeof value === "object") {
78
+ const next = {};
79
+ for (const key in value) {
80
+ next[key] = cloneAnimationValue(value[key]);
81
+ }
82
+ return next;
83
+ }
84
+ return value;
94
85
  };
95
- const cloneStyleRecord = style => {
96
- const next = {};
97
- for (const key in style) {
98
- next[key] = cloneAnimationValue(style[key]);
99
- }
100
- return next;
86
+ const cloneStyleRecord = (style) => {
87
+ const next = {};
88
+ for (const key in style) {
89
+ next[key] = cloneAnimationValue(style[key]);
90
+ }
91
+ return next;
101
92
  };
102
- const cloneTransitionConfig = config => {
103
- return cloneAnimationValue(config);
93
+ const cloneTransitionConfig = (config) => {
94
+ return cloneAnimationValue(config);
104
95
  };
105
- const getAnimatedTransforms = value => {
106
- if (!Array.isArray(value)) return [];
107
- return value.filter(item => item !== null && typeof item === "object" && !Array.isArray(item));
96
+ const getAnimatedTransforms = (value) => {
97
+ if (!Array.isArray(value)) return [];
98
+ return value.filter((item) => item !== null && typeof item === "object" && !Array.isArray(item));
108
99
  };
109
100
  const getRemovedAnimatedKeys = (current, previous) => {
110
- const removedKeys = {};
111
- for (const key of previous) {
112
- if (!current.has(key)) removedKeys[key] = true;
113
- }
114
- return removedKeys;
101
+ const removedKeys = {};
102
+ for (const key of previous) {
103
+ if (!current.has(key)) removedKeys[key] = true;
104
+ }
105
+ return removedKeys;
115
106
  };
116
107
  const getImplicitDefault = (key, targetValue) => {
117
- "worklet";
118
-
119
- const value = key === "opacity" || key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
120
- if (typeof targetValue !== "string") return value;
121
- let suffixIndex = 0;
122
- while (suffixIndex < targetValue.length) {
123
- const character = targetValue[suffixIndex];
124
- const code = character.charCodeAt(0);
125
- if (code >= 48 && code <= 57 || character === "." || character === "-" || character === "+") {
126
- suffixIndex++;
127
- } else {
128
- break;
129
- }
130
- }
131
- return suffixIndex > 0 ? `${value}${targetValue.slice(suffixIndex)}` : value;
108
+ "worklet";
109
+ const value = key === "opacity" || key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
110
+ if (typeof targetValue !== "string") return value;
111
+ let suffixIndex = 0;
112
+ while (suffixIndex < targetValue.length) {
113
+ const character = targetValue[suffixIndex];
114
+ const code = character.charCodeAt(0);
115
+ if (code >= 48 && code <= 57 || character === "." || character === "-" || character === "+") {
116
+ suffixIndex++;
117
+ } else {
118
+ break;
119
+ }
120
+ }
121
+ return suffixIndex > 0 ? `${value}${targetValue.slice(suffixIndex)}` : value;
132
122
  };
133
123
  const COLOR_STYLE_KEYS = {
134
- backgroundColor: true,
135
- borderColor: true,
136
- borderLeftColor: true,
137
- borderRightColor: true,
138
- borderTopColor: true,
139
- borderBottomColor: true,
140
- color: true
124
+ backgroundColor: true,
125
+ borderColor: true,
126
+ borderLeftColor: true,
127
+ borderRightColor: true,
128
+ borderTopColor: true,
129
+ borderBottomColor: true,
130
+ color: true
141
131
  };
142
- const toReanimatedColor = value => {
143
- "worklet";
144
-
145
- if (typeof value === "number") {
146
- const color = value >>> 0;
147
- const alpha = (color >>> 24 & 255) / 255;
148
- const red = color >>> 16 & 255;
149
- const green = color >>> 8 & 255;
150
- const blue = color & 255;
151
- return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
152
- }
153
- if (typeof value !== "string") return value;
154
- const trimmed = value.trim();
155
- if (trimmed === "transparent") return "rgba(0, 0, 0, 0)";
156
- return trimmed;
132
+ const toReanimatedColor = (value) => {
133
+ "worklet";
134
+ if (typeof value === "number") {
135
+ const color = value >>> 0;
136
+ const alpha = (color >>> 24 & 255) / 255;
137
+ const red = color >>> 16 & 255;
138
+ const green = color >>> 8 & 255;
139
+ const blue = color & 255;
140
+ return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
141
+ }
142
+ if (typeof value !== "string") return value;
143
+ const trimmed = value.trim();
144
+ if (trimmed === "transparent") return "rgba(0, 0, 0, 0)";
145
+ return trimmed;
157
146
  };
158
- const isReanimatedColorHistory = value => {
159
- "worklet";
160
-
161
- const normalized = toReanimatedColor(value);
162
- return typeof normalized === "string" && normalized.startsWith("rgba(");
147
+ const isReanimatedColorHistory = (value) => {
148
+ "worklet";
149
+ const normalized = toReanimatedColor(value);
150
+ return typeof normalized === "string" && normalized.startsWith("rgba(");
163
151
  };
164
- const normalizeAnimationColor = value => {
165
- if (typeof value === "number") {
166
- return toReanimatedColor(value);
167
- }
168
- if (typeof value !== "string") return;
169
- const color = (0, import_normalize_colors.default)(value);
170
- if (color == null) return;
171
- const red = Math.round((color & 4278190080) >>> 24);
172
- const green = Math.round((color & 16711680) >>> 16);
173
- const blue = Math.round((color & 65280) >>> 8);
174
- const alpha = (color & 255) / 255;
175
- return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
152
+ const normalizeAnimationColor = (value) => {
153
+ if (typeof value === "number") {
154
+ return toReanimatedColor(value);
155
+ }
156
+ if (typeof value !== "string") return;
157
+ const color = (0, import_normalize_colors.default)(value);
158
+ if (color == null) return;
159
+ const red = Math.round((color & 4278190080) >>> 24);
160
+ const green = Math.round((color & 16711680) >>> 16);
161
+ const blue = Math.round((color & 65280) >>> 8);
162
+ const alpha = (color & 255) / 255;
163
+ return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
176
164
  };
177
165
  const buildSnapshot = (animated, statics, transforms, previousKeys, lastPainted) => {
178
- const snapshotAnimated = {};
179
- const snapshotStatics = cloneStyleRecord(statics);
180
- for (const key in snapshotStatics) {
181
- if (!COLOR_STYLE_KEYS[key]) continue;
182
- const normalized = normalizeAnimationColor(snapshotStatics[key]);
183
- if (normalized !== void 0) snapshotStatics[key] = normalized;
184
- }
185
- for (const key in animated) {
186
- if (key === "transform") continue;
187
- const value = animated[key];
188
- if (COLOR_STYLE_KEYS[key]) {
189
- const normalized = normalizeAnimationColor(value);
190
- if (normalized === void 0) {
191
- snapshotStatics[key] = cloneAnimationValue(value);
192
- continue;
193
- }
194
- snapshotAnimated[key] = normalized;
195
- } else {
196
- snapshotAnimated[key] = cloneAnimationValue(value);
197
- }
198
- }
199
- const snapshotTransforms = transforms.map(cloneStyleRecord);
200
- const keys = new Set(Object.keys(snapshotAnimated));
201
- for (const transform of snapshotTransforms) {
202
- const key = Object.keys(transform)[0];
203
- const value = key ? transform[key] : void 0;
204
- if (key && (typeof value === "number" || typeof value === "string")) {
205
- keys.add(`transform:${key}`);
206
- }
207
- }
208
- const seeds = {};
209
- for (const key of keys) {
210
- let value = lastPainted[key];
211
- if (typeof value !== "number" && typeof value !== "string") continue;
212
- if (value === "auto" || typeof value === "string" && value.startsWith("calc")) {
213
- continue;
214
- }
215
- if (COLOR_STYLE_KEYS[key]) value = normalizeAnimationColor(value);
216
- if (value !== void 0) seeds[key] = value;
217
- }
218
- const gatedKeys = {};
219
- for (const key of keys) gatedKeys[key] = true;
220
- const removedKeys = getRemovedAnimatedKeys(keys, previousKeys);
221
- const painted = {
222
- ...snapshotStatics,
223
- ...snapshotAnimated
224
- };
225
- const staticTransforms = getAnimatedTransforms(snapshotStatics.transform);
226
- delete painted.transform;
227
- for (const transform of staticTransforms) {
228
- const key = Object.keys(transform)[0];
229
- if (key) painted[`transform:${key}`] = transform[key];
230
- }
231
- for (const transform of snapshotTransforms) {
232
- const key = Object.keys(transform)[0];
233
- if (key) painted[`transform:${key}`] = transform[key];
234
- }
235
- return {
236
- value: {
237
- animated: snapshotAnimated,
238
- statics: snapshotStatics,
239
- transforms: snapshotTransforms,
240
- gatedKeys,
241
- seeds,
242
- removedKeys,
243
- removeTransform: Object.keys(removedKeys).some(key => key.startsWith("transform:")),
244
- clearValue: import_core.isWeb ? "" : null
245
- },
246
- painted,
247
- keys
248
- };
166
+ const snapshotAnimated = {};
167
+ const snapshotStatics = cloneStyleRecord(statics);
168
+ for (const key in snapshotStatics) {
169
+ if (!COLOR_STYLE_KEYS[key]) continue;
170
+ const normalized = normalizeAnimationColor(snapshotStatics[key]);
171
+ if (normalized !== void 0) snapshotStatics[key] = normalized;
172
+ }
173
+ for (const key in animated) {
174
+ if (key === "transform") continue;
175
+ const value = animated[key];
176
+ if (COLOR_STYLE_KEYS[key]) {
177
+ const normalized = normalizeAnimationColor(value);
178
+ if (normalized === void 0) {
179
+ snapshotStatics[key] = cloneAnimationValue(value);
180
+ continue;
181
+ }
182
+ snapshotAnimated[key] = normalized;
183
+ } else {
184
+ snapshotAnimated[key] = cloneAnimationValue(value);
185
+ }
186
+ }
187
+ const snapshotTransforms = transforms.map(cloneStyleRecord);
188
+ const keys = new Set(Object.keys(snapshotAnimated));
189
+ for (const transform of snapshotTransforms) {
190
+ const key = Object.keys(transform)[0];
191
+ const value = key ? transform[key] : void 0;
192
+ if (key && (typeof value === "number" || typeof value === "string")) {
193
+ keys.add(`transform:${key}`);
194
+ }
195
+ }
196
+ const seeds = {};
197
+ for (const key of keys) {
198
+ let value = lastPainted[key];
199
+ if (typeof value !== "number" && typeof value !== "string") continue;
200
+ if (value === "auto" || typeof value === "string" && value.startsWith("calc")) {
201
+ continue;
202
+ }
203
+ if (COLOR_STYLE_KEYS[key]) value = normalizeAnimationColor(value);
204
+ if (value !== void 0) seeds[key] = value;
205
+ }
206
+ const gatedKeys = {};
207
+ for (const key of keys) gatedKeys[key] = true;
208
+ const removedKeys = getRemovedAnimatedKeys(keys, previousKeys);
209
+ const painted = {
210
+ ...snapshotStatics,
211
+ ...snapshotAnimated
212
+ };
213
+ const staticTransforms = getAnimatedTransforms(snapshotStatics.transform);
214
+ delete painted.transform;
215
+ for (const transform of staticTransforms) {
216
+ const key = Object.keys(transform)[0];
217
+ if (key) painted[`transform:${key}`] = transform[key];
218
+ }
219
+ for (const transform of snapshotTransforms) {
220
+ const key = Object.keys(transform)[0];
221
+ if (key) painted[`transform:${key}`] = transform[key];
222
+ }
223
+ return {
224
+ value: {
225
+ animated: snapshotAnimated,
226
+ statics: snapshotStatics,
227
+ transforms: snapshotTransforms,
228
+ gatedKeys,
229
+ seeds,
230
+ removedKeys,
231
+ removeTransform: Object.keys(removedKeys).some((key) => key.startsWith("transform:")),
232
+ clearValue: import_core.isWeb ? "" : null
233
+ },
234
+ painted,
235
+ keys
236
+ };
249
237
  };
250
- const getGatedKeys = snapshot => Object.keys(snapshot.gatedKeys);
251
- const createReanimatedConfig = config => {
252
- "worklet";
253
-
254
- const next = {};
255
- const source = config;
256
- for (const key in source) {
257
- if (key === "type" || key === "delay") continue;
258
- const value = source[key];
259
- if (value !== void 0) {
260
- next[key] = value;
261
- }
262
- }
263
- return next;
238
+ const getGatedKeys = (snapshot) => Object.keys(snapshot.gatedKeys);
239
+ const createReanimatedConfig = (config) => {
240
+ "worklet";
241
+ const next = {};
242
+ const source = config;
243
+ for (const key in source) {
244
+ if (key === "type" || key === "delay") continue;
245
+ const value = source[key];
246
+ if (value !== void 0) {
247
+ next[key] = value;
248
+ }
249
+ }
250
+ return next;
264
251
  };
265
252
  const applyAnimation = (targetValue, config, callback, seedValue, validateStartAsColor = false) => {
266
- "worklet";
267
-
268
- const delay = config.delay;
269
- const reanimatedConfig = createReanimatedConfig(config);
270
- let animatedValue;
271
- if (config.type === "timing") {
272
- animatedValue = (0, import_react_native_reanimated.withTiming)(targetValue, reanimatedConfig, callback);
273
- } else {
274
- animatedValue = (0, import_react_native_reanimated.withSpring)(targetValue, reanimatedConfig, callback);
275
- }
276
- if (seedValue !== void 0 || validateStartAsColor) {
277
- const innerOnStart = animatedValue.onStart;
278
- animatedValue.onStart = (animation, value, timestamp, previousAnimation) => {
279
- "worklet";
280
-
281
- const startValue = validateStartAsColor ? isReanimatedColorHistory(value) ? toReanimatedColor(value) : seedValue ?? targetValue : seedValue;
282
- innerOnStart(animation, startValue, timestamp, previousAnimation);
283
- };
284
- }
285
- if (delay && delay > 0) {
286
- animatedValue = (0, import_react_native_reanimated.withDelay)(delay, animatedValue);
287
- }
288
- return animatedValue;
253
+ "worklet";
254
+ const delay = config.delay;
255
+ const reanimatedConfig = createReanimatedConfig(config);
256
+ let animatedValue;
257
+ if (config.type === "timing") {
258
+ animatedValue = (0, import_react_native_reanimated.withTiming)(targetValue, reanimatedConfig, callback);
259
+ } else {
260
+ animatedValue = (0, import_react_native_reanimated.withSpring)(targetValue, reanimatedConfig, callback);
261
+ const innerOnFrame = animatedValue.onFrame;
262
+ animatedValue.onFrame = (animation, now) => {
263
+ "worklet";
264
+ return innerOnFrame(animation, now < animation.lastTimestamp ? animation.lastTimestamp : now);
265
+ };
266
+ }
267
+ if (seedValue !== void 0 || validateStartAsColor) {
268
+ const innerOnStart = animatedValue.onStart;
269
+ animatedValue.onStart = (animation, value, timestamp, previousAnimation) => {
270
+ "worklet";
271
+ const startValue = validateStartAsColor ? isReanimatedColorHistory(value) ? toReanimatedColor(value) : seedValue ?? targetValue : seedValue;
272
+ innerOnStart(animation, startValue, timestamp, previousAnimation);
273
+ };
274
+ }
275
+ if (delay && delay > 0) {
276
+ animatedValue = (0, import_react_native_reanimated.withDelay)(delay, animatedValue);
277
+ }
278
+ return animatedValue;
289
279
  };
290
- const animateSnapshotValue = (key, implicitKey, targetValue, config, previouslyEmitted, seedValue, gated, currentlyExiting, exitCycleId, currentlyCompletingAnimation, didAnimateCycleId, markExitKeyDone, markDidAnimateKeyDone, validateStartAsColor = false) => {
291
- "worklet";
292
-
293
- const cycleGated = gated && (currentlyExiting || currentlyCompletingAnimation);
294
- if (!previouslyEmitted && seedValue === void 0 && !cycleGated) {
295
- return targetValue;
296
- }
297
- let callback;
298
- if (gated && currentlyExiting) {
299
- callback = finished => {
300
- "worklet";
301
-
302
- (0, import_react_native_reanimated.runOnJS)(markExitKeyDone)(key, exitCycleId, finished ?? false);
303
- };
304
- } else if (gated && currentlyCompletingAnimation) {
305
- callback = finished => {
306
- "worklet";
307
-
308
- (0, import_react_native_reanimated.runOnJS)(markDidAnimateKeyDone)(key, didAnimateCycleId, finished ?? false);
309
- };
310
- }
311
- return applyAnimation(targetValue, config, callback, previouslyEmitted ? void 0 : seedValue ?? getImplicitDefault(implicitKey, targetValue), validateStartAsColor);
280
+ const animateSnapshotValue = (key, implicitKey, targetValue, config, previouslyEmitted, seedValue, gated, currentlyExiting, exitCycleId, currentlyCompletingEnter, enterCycleId, currentlyCompletingUpdate, updateCycleId, markExitKeyDone, markEnterKeyDone, markUpdateKeyDone, validateStartAsColor = false) => {
281
+ "worklet";
282
+ const cycleGated = gated && (currentlyExiting || currentlyCompletingEnter || currentlyCompletingUpdate);
283
+ if (!previouslyEmitted && seedValue === void 0 && !cycleGated) {
284
+ return targetValue;
285
+ }
286
+ let callback;
287
+ if (gated && currentlyExiting) {
288
+ callback = (finished) => {
289
+ "worklet";
290
+ (0, import_react_native_reanimated.runOnJS)(markExitKeyDone)(key, exitCycleId, finished ?? false);
291
+ };
292
+ } else if (gated && currentlyCompletingEnter) {
293
+ callback = () => {
294
+ "worklet";
295
+ (0, import_react_native_reanimated.runOnJS)(markEnterKeyDone)(key, enterCycleId);
296
+ };
297
+ } else if (gated && currentlyCompletingUpdate) {
298
+ callback = (finished) => {
299
+ "worklet";
300
+ (0, import_react_native_reanimated.runOnJS)(markUpdateKeyDone)(key, updateCycleId, finished ?? false);
301
+ };
302
+ }
303
+ return applyAnimation(targetValue, config, callback, previouslyEmitted ? void 0 : seedValue ?? getImplicitDefault(implicitKey, targetValue), validateStartAsColor);
312
304
  };
313
305
  const ANIMATABLE_PROPERTIES = {
314
- // Transform
315
- transform: true,
316
- // Opacity
317
- opacity: true,
318
- // Dimensions
319
- height: true,
320
- width: true,
321
- minWidth: true,
322
- minHeight: true,
323
- maxWidth: true,
324
- maxHeight: true,
325
- // Background
326
- backgroundColor: true,
327
- // Border colors
328
- borderColor: true,
329
- borderLeftColor: true,
330
- borderRightColor: true,
331
- borderTopColor: true,
332
- borderBottomColor: true,
333
- // Border radius
334
- borderRadius: true,
335
- borderTopLeftRadius: true,
336
- borderTopRightRadius: true,
337
- borderBottomLeftRadius: true,
338
- borderBottomRightRadius: true,
339
- // Border width
340
- borderWidth: true,
341
- borderLeftWidth: true,
342
- borderRightWidth: true,
343
- borderTopWidth: true,
344
- borderBottomWidth: true,
345
- // Text
346
- color: true,
347
- fontSize: true,
348
- fontWeight: true,
349
- lineHeight: true,
350
- letterSpacing: true,
351
- // Position
352
- left: true,
353
- right: true,
354
- top: true,
355
- bottom: true,
356
- // Margin
357
- margin: true,
358
- marginTop: true,
359
- marginBottom: true,
360
- marginLeft: true,
361
- marginRight: true,
362
- marginHorizontal: true,
363
- marginVertical: true,
364
- // Padding
365
- padding: true,
366
- paddingTop: true,
367
- paddingBottom: true,
368
- paddingLeft: true,
369
- paddingRight: true,
370
- paddingHorizontal: true,
371
- paddingVertical: true,
372
- // Flex/Gap
373
- gap: true,
374
- rowGap: true,
375
- columnGap: true,
376
- flex: true,
377
- flexGrow: true,
378
- flexShrink: true
306
+ transform: true,
307
+ opacity: true,
308
+ height: true,
309
+ width: true,
310
+ minWidth: true,
311
+ minHeight: true,
312
+ maxWidth: true,
313
+ maxHeight: true,
314
+ backgroundColor: true,
315
+ borderColor: true,
316
+ borderLeftColor: true,
317
+ borderRightColor: true,
318
+ borderTopColor: true,
319
+ borderBottomColor: true,
320
+ borderRadius: true,
321
+ borderTopLeftRadius: true,
322
+ borderTopRightRadius: true,
323
+ borderBottomLeftRadius: true,
324
+ borderBottomRightRadius: true,
325
+ borderWidth: true,
326
+ borderLeftWidth: true,
327
+ borderRightWidth: true,
328
+ borderTopWidth: true,
329
+ borderBottomWidth: true,
330
+ color: true,
331
+ fontSize: true,
332
+ fontWeight: true,
333
+ lineHeight: true,
334
+ letterSpacing: true,
335
+ left: true,
336
+ right: true,
337
+ top: true,
338
+ bottom: true,
339
+ margin: true,
340
+ marginTop: true,
341
+ marginBottom: true,
342
+ marginLeft: true,
343
+ marginRight: true,
344
+ marginHorizontal: true,
345
+ marginVertical: true,
346
+ padding: true,
347
+ paddingTop: true,
348
+ paddingBottom: true,
349
+ paddingLeft: true,
350
+ paddingRight: true,
351
+ paddingHorizontal: true,
352
+ paddingVertical: true,
353
+ gap: true,
354
+ rowGap: true,
355
+ columnGap: true,
356
+ flex: true,
357
+ flexGrow: true,
358
+ flexShrink: true
379
359
  };
380
360
  const canAnimateProperty = (key, value, animateOnly) => {
381
- if (!ANIMATABLE_PROPERTIES[key]) return false;
382
- if (value === "auto") return false;
383
- if (typeof value === "string" && value.startsWith("calc")) return false;
384
- if (animateOnly && !animateOnly.includes(key)) return false;
385
- return true;
361
+ if (!ANIMATABLE_PROPERTIES[key]) return false;
362
+ if (value === "auto") return false;
363
+ if (typeof value === "string" && value.startsWith("calc")) return false;
364
+ if (animateOnly && !animateOnly.includes(key)) return false;
365
+ return true;
386
366
  };
387
367
  const splitAnimationStyles = (style, isDark, disableAnimation, animateOnly) => {
388
- const animated = {};
389
- const statics = {};
390
- for (const key in style) {
391
- const value = resolveDynamicValue(style[key], isDark);
392
- if (value === void 0) continue;
393
- if (!disableAnimation && canAnimateProperty(key, value, animateOnly)) {
394
- animated[key] = cloneAnimationValue(value);
395
- } else {
396
- statics[key] = cloneAnimationValue(value);
397
- }
398
- }
399
- return {
400
- animated,
401
- statics
402
- };
368
+ const animated = {};
369
+ const statics = {};
370
+ for (const key in style) {
371
+ const value = resolveDynamicValue(style[key], isDark);
372
+ if (value === void 0) continue;
373
+ if (!disableAnimation && canAnimateProperty(key, value, animateOnly)) {
374
+ animated[key] = cloneAnimationValue(value);
375
+ } else {
376
+ statics[key] = cloneAnimationValue(value);
377
+ }
378
+ }
379
+ return {
380
+ animated,
381
+ statics
382
+ };
403
383
  };
404
384
  function createWebAnimatedComponent(defaultTag) {
405
- const isText = defaultTag === "span";
406
- const Component = Animated.createAnimatedComponent((0, import_react.forwardRef)((propsIn, ref) => {
407
- const {
408
- forwardedRef,
409
- render = defaultTag,
410
- ...rest
411
- } = propsIn;
412
- const hostRef = (0, import_react.useRef)(null);
413
- const composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef);
414
- const stateRef = (0, import_react.useRef)({
415
- get host() {
416
- return hostRef.current;
417
- }
418
- });
419
- const [, themeState] = (0, import_core.useThemeWithState)({});
420
- const result = (0, import_core.getSplitStyles)(rest, isText ? import_core.Text.staticConfig : import_core.View.staticConfig, themeState?.theme ?? {}, themeState?.name ?? "", {
421
- unmounted: false
422
- }, {
423
- isAnimated: false,
424
- noClass: true
425
- });
426
- const viewProps = result?.viewProps ?? {};
427
- const Element = render;
428
- const transformedProps = import_core.hooks.usePropsTransform?.(render, viewProps, stateRef, false);
429
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
430
- ...transformedProps,
431
- ref: composedRefs
432
- });
433
- }));
434
- Component.acceptRenderProp = true;
435
- return Component;
385
+ const isText = defaultTag === "span";
386
+ const Component = Animated.createAnimatedComponent((0, import_core.createRefComponent)((propsIn, ref) => {
387
+ const { forwardedRef, render = defaultTag, ...rest } = propsIn;
388
+ const hostRef = (0, import_react.useRef)(null);
389
+ const composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef);
390
+ const stateRef = (0, import_react.useRef)({ get host() {
391
+ return hostRef.current;
392
+ } });
393
+ const [, themeState] = (0, import_core.useThemeWithState)({});
394
+ const result = (0, import_core.getSplitStyles)(rest, isText ? import_core.Text.staticConfig : import_core.View.staticConfig, themeState?.theme ?? {}, themeState?.name ?? "", { unmounted: false }, {
395
+ isAnimated: false,
396
+ noClass: true
397
+ });
398
+ const viewProps = result?.viewProps ?? {};
399
+ const Element = render;
400
+ const transformedProps = import_core.hooks.usePropsTransform?.(render, viewProps, stateRef, false);
401
+ const { nativeID, ...webProps } = transformedProps ?? viewProps;
402
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Element, {
403
+ ...webProps,
404
+ ref: composedRefs
405
+ });
406
+ }));
407
+ Component.acceptRenderProp = true;
408
+ return Component;
436
409
  }
437
410
  const AnimatedView = createWebAnimatedComponent("div");
438
411
  const AnimatedText = createWebAnimatedComponent("span");
439
412
  function buildTransitionConfig(transition, animations, animationState, styleKeys) {
440
- const normalized = (0, import_animation_helpers.normalizeTransition)(transition);
441
- const effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
442
- let base = cloneTransitionConfig(effectiveKey ? animations[effectiveKey] ?? {
443
- type: "spring"
444
- } : {
445
- type: "spring"
446
- });
447
- if (normalized.delay) {
448
- base = cloneTransitionConfig({
449
- ...base,
450
- delay: normalized.delay
451
- });
452
- }
453
- if (normalized.config) {
454
- base = cloneTransitionConfig({
455
- ...base,
456
- ...normalized.config
457
- });
458
- if (base.type !== "timing" && normalized.config.duration !== void 0 && normalized.config.damping === void 0 && normalized.config.stiffness === void 0 && normalized.config.mass === void 0) {
459
- base = cloneTransitionConfig({
460
- ...base,
461
- type: "timing"
462
- });
463
- }
464
- }
465
- const propertyConfigs = {};
466
- for (const key of styleKeys) {
467
- const propAnimation = normalized.properties[key];
468
- if (typeof propAnimation === "string") {
469
- propertyConfigs[key] = cloneTransitionConfig(animations[propAnimation] ?? base);
470
- } else if (propAnimation && typeof propAnimation === "object") {
471
- const configType = propAnimation.type;
472
- const baseForProp = configType ? animations[configType] ?? base : base;
473
- propertyConfigs[key] = cloneTransitionConfig({
474
- ...baseForProp,
475
- ...propAnimation
476
- });
477
- } else {
478
- propertyConfigs[key] = cloneTransitionConfig(base);
479
- }
480
- }
481
- return {
482
- baseConfig: base,
483
- propertyConfigs
484
- };
413
+ const normalized = (0, import_animation_helpers.normalizeTransition)(transition);
414
+ const effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
415
+ let base = cloneTransitionConfig(effectiveKey ? animations[effectiveKey] ?? { type: "spring" } : { type: "spring" });
416
+ if (normalized.delay) {
417
+ base = cloneTransitionConfig({
418
+ ...base,
419
+ delay: normalized.delay
420
+ });
421
+ }
422
+ if (normalized.config) {
423
+ base = cloneTransitionConfig({
424
+ ...base,
425
+ ...normalized.config
426
+ });
427
+ if (base.type !== "timing" && normalized.config.duration !== void 0 && normalized.config.damping === void 0 && normalized.config.stiffness === void 0 && normalized.config.mass === void 0) {
428
+ base = cloneTransitionConfig({
429
+ ...base,
430
+ type: "timing"
431
+ });
432
+ }
433
+ }
434
+ const propertyConfigs = {};
435
+ for (const key of styleKeys) {
436
+ const propAnimation = normalized.properties[key];
437
+ if (typeof propAnimation === "string") {
438
+ propertyConfigs[key] = cloneTransitionConfig(animations[propAnimation] ?? base);
439
+ } else if (propAnimation && typeof propAnimation === "object") {
440
+ const configType = propAnimation.type;
441
+ const baseForProp = configType ? animations[configType] ?? base : base;
442
+ propertyConfigs[key] = cloneTransitionConfig({
443
+ ...baseForProp,
444
+ ...propAnimation
445
+ });
446
+ } else {
447
+ propertyConfigs[key] = cloneTransitionConfig(base);
448
+ }
449
+ }
450
+ return {
451
+ baseConfig: base,
452
+ propertyConfigs
453
+ };
485
454
  }
486
455
  function getStyleKeys(style) {
487
- const keys = new Set(Object.keys(style));
488
- if (style.transform && Array.isArray(style.transform)) {
489
- for (const t of style.transform) {
490
- if (t && typeof t === "object") {
491
- keys.add(Object.keys(t)[0]);
492
- }
493
- }
494
- }
495
- return keys;
456
+ const keys = new Set(Object.keys(style));
457
+ if (style.transform && Array.isArray(style.transform)) {
458
+ for (const t of style.transform) {
459
+ if (t && typeof t === "object") {
460
+ keys.add(Object.keys(t)[0]);
461
+ }
462
+ }
463
+ }
464
+ return keys;
496
465
  }
497
466
  function createAnimations(animationsConfig) {
498
- const animations = {};
499
- for (const key in animationsConfig) {
500
- animations[key] = cloneTransitionConfig({
501
- type: "spring",
502
- ...animationsConfig[key]
503
- });
504
- }
505
- return {
506
- needsCustomComponent: true,
507
- View: import_core.isWeb ? AnimatedView : Animated.View,
508
- Text: import_core.isWeb ? AnimatedText : Animated.Text,
509
- isReactNative: true,
510
- inputStyle: "value",
511
- outputStyle: "inline",
512
- avoidReRenders: true,
513
- animations,
514
- usePresence: import_use_presence.usePresence,
515
- ResetPresence: import_use_presence.ResetPresence,
516
- // =========================================================================
517
- // useAnimatedNumber - For imperative animated values
518
- // =========================================================================
519
- useAnimatedNumber(initial) {
520
- const sharedValue = (0, import_react_native_reanimated.useSharedValue)(initial);
521
- return (0, import_react.useMemo)(() => ({
522
- getInstance() {
523
- "worklet";
524
-
525
- return sharedValue;
526
- },
527
- getValue() {
528
- "worklet";
529
-
530
- return sharedValue.value;
531
- },
532
- setValue(next, config = {
533
- type: "spring"
534
- }, onFinish) {
535
- if (config.type === "direct") {
536
- sharedValue.value = next;
537
- onFinish?.();
538
- } else {
539
- const cb = onFinish ? finished => {
540
- "worklet";
541
-
542
- if (finished !== false) {
543
- (0, import_react_native_reanimated.runOnJS)(onFinish)();
544
- }
545
- } : void 0;
546
- const animationConfig = cloneTransitionConfig(config);
547
- if (import_core.isWeb) {
548
- sharedValue.value = applyAnimation(next, animationConfig, cb);
549
- } else {
550
- (0, import_react_native_reanimated.runOnUI)((targetValue, animationConfig2) => {
551
- "worklet";
552
-
553
- sharedValue.value = applyAnimation(targetValue, animationConfig2, cb);
554
- })(next, animationConfig);
555
- }
556
- }
557
- },
558
- stop() {
559
- (0, import_react_native_reanimated.cancelAnimation)(sharedValue);
560
- }
561
- }), [sharedValue]);
562
- },
563
- // =========================================================================
564
- // useAnimatedNumberReaction - React to animated value changes
565
- // =========================================================================
566
- useAnimatedNumberReaction({
567
- value
568
- }, onValue) {
569
- const instance = value.getInstance();
570
- return (0, import_react_native_reanimated.useAnimatedReaction)(() => instance.value, (next, prev) => {
571
- if (prev !== next) {
572
- (0, import_react_native_reanimated.runOnJS)(onValue)(next);
573
- }
574
- }, [onValue, instance]);
575
- },
576
- // =========================================================================
577
- // useAnimatedNumberStyle - Create animated styles from values
578
- // =========================================================================
579
- useAnimatedNumberStyle(val, getStyle) {
580
- const instance = val.getInstance();
581
- if (import_core.isWeb) {
582
- return (0, import_react_native_reanimated.useAnimatedStyle)(() => {
583
- "worklet";
584
-
585
- return getStyle(instance.value);
586
- }, [instance, getStyle]);
587
- }
588
- const styleVal = (0, import_react_native_reanimated.useDerivedValue)(() => {
589
- "worklet";
590
-
591
- return getStyle(instance.value);
592
- });
593
- const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
594
- "worklet";
595
-
596
- return styleVal.value;
597
- });
598
- silenceAnimatedComponentDevCheck(animatedStyle);
599
- return animatedStyle;
600
- },
601
- useAnimatedNumbersStyle(vals, getStyle) {
602
- const instances = vals.map(v => v.getInstance());
603
- const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
604
- "worklet";
605
-
606
- const currentValues = instances.map(inst => inst.value);
607
- return getStyle(...currentValues);
608
- }, import_core.isWeb ? [getStyle, ...instances] : void 0);
609
- silenceAnimatedComponentDevCheck(animatedStyle);
610
- return animatedStyle;
611
- },
612
- // =========================================================================
613
- // useAnimations - Main animation hook for components
614
- // =========================================================================
615
- useAnimations(animationProps) {
616
- const {
617
- props,
618
- presence,
619
- style,
620
- componentState,
621
- useStyleEmitter,
622
- themeName,
623
- stateRef,
624
- styleState,
625
- onDidAnimate
626
- } = animationProps;
627
- const isHydrating = componentState.unmounted === true;
628
- const isMounting = componentState.unmounted === "should-enter";
629
- const isEntering = !!componentState.unmounted;
630
- const isExiting = presence?.[0] === false;
631
- const wasEnteringRef = (0, import_react.useRef)(isEntering);
632
- const justFinishedEntering = wasEnteringRef.current && !isEntering;
633
- import_react.default.useEffect(() => {
634
- wasEnteringRef.current = isEntering;
635
- });
636
- const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
637
- const normalized = (0, import_animation_helpers.normalizeTransition)(effectiveTransition);
638
- const animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
639
- const animationKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
640
- const disableAnimation = isHydrating || !animationKey;
641
- const isDark = themeName?.startsWith("dark") || false;
642
- const sendExitComplete = presence?.[1];
643
- const onDidAnimateRef = (0, import_react.useRef)(onDidAnimate);
644
- (0, import_core.useIsomorphicLayoutEffect)(() => {
645
- onDidAnimateRef.current = onDidAnimate;
646
- }, [onDidAnimate]);
647
- const didAnimateCycleIdRef = (0, import_react.useRef)(0);
648
- const pendingDidAnimateKeysRef = (0, import_react.useRef)(/* @__PURE__ */new Set());
649
- const didAnimateCompletedRef = (0, import_react.useRef)(false);
650
- const isCompletingAnimationRef = (0, import_react_native_reanimated.useSharedValue)(false);
651
- const didAnimateCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(0);
652
- const markDidAnimateKeyDone = (0, import_core.useEvent)((key, cycleId, finished) => {
653
- if (!finished || cycleId !== didAnimateCycleIdRef.current) return;
654
- if (didAnimateCompletedRef.current) return;
655
- pendingDidAnimateKeysRef.current.delete(key);
656
- if (pendingDidAnimateKeysRef.current.size === 0) {
657
- didAnimateCompletedRef.current = true;
658
- isCompletingAnimationRef.value = false;
659
- onDidAnimateRef.current?.();
660
- }
661
- });
662
- const exitCycleIdRef = (0, import_react.useRef)(0);
663
- const pendingExitKeysRef = (0, import_react.useRef)(/* @__PURE__ */new Set());
664
- const exitCompletedRef = (0, import_react.useRef)(false);
665
- const wasExitingRef = (0, import_react.useRef)(false);
666
- const justStartedExiting = isExiting && !wasExitingRef.current;
667
- const justStoppedExiting = !isExiting && wasExitingRef.current;
668
- const markExitKeyDone = (0, import_core.useEvent)((key, cycleId, finished) => {
669
- if (cycleId !== exitCycleIdRef.current) return;
670
- if (exitCompletedRef.current) return;
671
- pendingExitKeysRef.current.delete(key);
672
- if (pendingExitKeysRef.current.size === 0) {
673
- exitCompletedRef.current = true;
674
- sendExitComplete?.();
675
- }
676
- });
677
- const isExitingRef = (0, import_react_native_reanimated.useSharedValue)(isExiting);
678
- const exitCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(exitCycleIdRef.current);
679
- if (justStartedExiting) {
680
- exitCycleIdRef.current++;
681
- exitCompletedRef.current = false;
682
- pendingExitKeysRef.current.clear();
683
- didAnimateCycleIdRef.current++;
684
- pendingDidAnimateKeysRef.current.clear();
685
- didAnimateCompletedRef.current = true;
686
- }
687
- if (justStoppedExiting) {
688
- exitCycleIdRef.current++;
689
- pendingExitKeysRef.current.clear();
690
- }
691
- (0, import_core.useIsomorphicLayoutEffect)(() => {
692
- isExitingRef.value = isExiting;
693
- exitCycleIdShared.value = exitCycleIdRef.current;
694
- if (justStartedExiting) {
695
- isCompletingAnimationRef.value = false;
696
- didAnimateCycleIdShared.value = didAnimateCycleIdRef.current;
697
- }
698
- }, [isExiting, exitCycleIdRef.current, justStartedExiting]);
699
- import_react.default.useEffect(() => {
700
- wasExitingRef.current = isExiting;
701
- });
702
- const committedRenderKeysRef = (0, import_react.useRef)(/* @__PURE__ */new Set());
703
- const lastPaintedRef = (0, import_react.useRef)({});
704
- const carryRef = (0, import_react.useRef)({});
705
- const {
706
- animatedStyles,
707
- staticStyles,
708
- nextCarry
709
- } = (0, import_react.useMemo)(() => {
710
- const animateOnly = props.animateOnly;
711
- const {
712
- animated,
713
- statics
714
- } = splitAnimationStyles(style, isDark, disableAnimation, animateOnly);
715
- const nextCarry2 = cloneStyleRecord(carryRef.current);
716
- for (const key in nextCarry2) {
717
- if (!(key in animated)) delete nextCarry2[key];
718
- }
719
- for (const key in animated) {
720
- if (!(key in nextCarry2)) {
721
- nextCarry2[key] = cloneAnimationValue(animated[key]);
722
- }
723
- statics[key] = nextCarry2[key];
724
- }
725
- return {
726
- animatedStyles: animated,
727
- staticStyles: statics,
728
- nextCarry: nextCarry2
729
- };
730
- }, [disableAnimation, style, isDark, props.animateOnly]);
731
- const renderSnapshot = (0, import_react.useMemo)(() => buildSnapshot(animatedStyles, staticStyles, getAnimatedTransforms(animatedStyles.transform), committedRenderKeysRef.current, lastPaintedRef.current), [animatedStyles, staticStyles]);
732
- const renderSnapshotRef = (0, import_react_native_reanimated.useSharedValue)({
733
- animated: {},
734
- statics: {},
735
- transforms: [],
736
- gatedKeys: {},
737
- seeds: {},
738
- removedKeys: {},
739
- removeTransform: false,
740
- clearValue: import_core.isWeb ? "" : null
741
- });
742
- const emitterSnapshotRef = (0, import_react_native_reanimated.useSharedValue)(null);
743
- const emitterKeysRef = (0, import_react.useRef)(null);
744
- (0, import_core.useIsomorphicLayoutEffect)(() => {
745
- carryRef.current = nextCarry;
746
- committedRenderKeysRef.current = renderSnapshot.keys;
747
- lastPaintedRef.current = renderSnapshot.painted;
748
- }, [nextCarry, renderSnapshot]);
749
- const pseudoActiveRef = (0, import_react.useRef)(false);
750
- const isExitingJSRef = (0, import_react.useRef)(false);
751
- isExitingJSRef.current = isExiting;
752
- const publishedSnapshotRef = (0, import_react.useRef)(null);
753
- (0, import_core.useIsomorphicLayoutEffect)(() => {
754
- const droppingLatch = (isExiting || !pseudoActiveRef.current) && emitterSnapshotRef.value !== null;
755
- const emitterKeys = droppingLatch ? emitterKeysRef.current : null;
756
- if (droppingLatch || publishedSnapshotRef.current !== renderSnapshot.value) {
757
- const removedKeys = emitterKeys ? {
758
- ...renderSnapshot.value.removedKeys,
759
- ...getRemovedAnimatedKeys(renderSnapshot.keys, emitterKeys)
760
- } : renderSnapshot.value.removedKeys;
761
- renderSnapshotRef.value = {
762
- ...renderSnapshot.value,
763
- removedKeys,
764
- removeTransform: Object.keys(removedKeys).some(key => key.startsWith("transform:"))
765
- };
766
- publishedSnapshotRef.current = renderSnapshot.value;
767
- }
768
- if (droppingLatch) {
769
- emitterSnapshotRef.value = null;
770
- emitterKeysRef.current = null;
771
- }
772
- });
773
- const {
774
- baseConfig,
775
- propertyConfigs
776
- } = (0, import_react.useMemo)(() => {
777
- if (isHydrating) {
778
- return {
779
- baseConfig: {
780
- type: "timing",
781
- duration: 0
782
- },
783
- propertyConfigs: {}
784
- };
785
- }
786
- return buildTransitionConfig(effectiveTransition, animations, animationState, getStyleKeys(animatedStyles));
787
- }, [isHydrating, effectiveTransition, animatedStyles, animationState]);
788
- const configRef = (0, import_react_native_reanimated.useSharedValue)({
789
- baseConfig,
790
- propertyConfigs,
791
- disableAnimation,
792
- isHydrating
793
- });
794
- (0, import_core.useIsomorphicLayoutEffect)(() => {
795
- configRef.value = {
796
- baseConfig,
797
- propertyConfigs,
798
- disableAnimation,
799
- isHydrating
800
- };
801
- }, [baseConfig, propertyConfigs, disableAnimation, isHydrating]);
802
- useStyleEmitter?.((nextStyle, effectiveTransition2, pseudoActive) => {
803
- if (isExitingJSRef.current) return;
804
- pseudoActiveRef.current = pseudoActive === true;
805
- const animateOnly = props.animateOnly;
806
- const transitionToUse = effectiveTransition2 ?? props.transition;
807
- const {
808
- baseConfig: newBase,
809
- propertyConfigs: newPropertyConfigs
810
- } = buildTransitionConfig(transitionToUse, animations, animationState, getStyleKeys(nextStyle));
811
- configRef.value = {
812
- baseConfig: newBase,
813
- propertyConfigs: newPropertyConfigs,
814
- disableAnimation: configRef.value.disableAnimation,
815
- isHydrating: configRef.value.isHydrating
816
- };
817
- const previousKeys = emitterKeysRef.current ?? committedRenderKeysRef.current;
818
- const {
819
- animated,
820
- statics
821
- } = splitAnimationStyles(nextStyle, isDark, configRef.value.disableAnimation, animateOnly);
822
- const snapshot = buildSnapshot(animated, statics, getAnimatedTransforms(animated.transform), previousKeys, lastPaintedRef.current);
823
- emitterSnapshotRef.value = snapshot.value;
824
- emitterKeysRef.current = snapshot.keys;
825
- lastPaintedRef.current = snapshot.painted;
826
- if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
827
- console.info("[animations-reanimated] useStyleEmitter update", {
828
- animated,
829
- statics,
830
- transforms: snapshot.value.transforms
831
- });
832
- }
833
- });
834
- const exitKeysRegistered = (0, import_react.useRef)(false);
835
- if (justStartedExiting && sendExitComplete) {
836
- const exitKeys = getGatedKeys(renderSnapshot.value);
837
- pendingExitKeysRef.current = new Set(exitKeys);
838
- exitKeysRegistered.current = exitKeys.length > 0;
839
- }
840
- const previousDidAnimateStyleRef = (0, import_react.useRef)(null);
841
- const didAnimateStyle = onDidAnimate ? JSON.stringify(style) : null;
842
- const previousDidAnimateStyle = previousDidAnimateStyleRef.current;
843
- const shouldRegisterDidAnimate = didAnimateStyle !== null && previousDidAnimateStyle !== null && previousDidAnimateStyle !== didAnimateStyle && !isExiting && !isEntering && !justFinishedEntering;
844
- const didAnimateKeys = shouldRegisterDidAnimate ? getGatedKeys(renderSnapshot.value) : [];
845
- (0, import_core.useIsomorphicLayoutEffect)(() => {
846
- if (didAnimateStyle === null) {
847
- previousDidAnimateStyleRef.current = null;
848
- isCompletingAnimationRef.value = false;
849
- return;
850
- }
851
- const previousStyleStillCurrent = previousDidAnimateStyleRef.current === previousDidAnimateStyle;
852
- previousDidAnimateStyleRef.current = didAnimateStyle;
853
- if (!shouldRegisterDidAnimate || !previousStyleStillCurrent) return;
854
- const cycleId = ++didAnimateCycleIdRef.current;
855
- pendingDidAnimateKeysRef.current = new Set(didAnimateKeys);
856
- didAnimateCompletedRef.current = didAnimateKeys.length === 0;
857
- isCompletingAnimationRef.value = didAnimateKeys.length > 0;
858
- didAnimateCycleIdShared.value = cycleId;
859
- if (didAnimateKeys.length === 0) {
860
- onDidAnimateRef.current?.();
861
- }
862
- }, [didAnimateStyle, shouldRegisterDidAnimate]);
863
- import_react.default.useEffect(() => {
864
- if (!justStartedExiting || !sendExitComplete) return;
865
- if (!exitKeysRegistered.current && pendingExitKeysRef.current.size === 0) {
866
- if (!exitCompletedRef.current) {
867
- exitCompletedRef.current = true;
868
- sendExitComplete();
869
- }
870
- }
871
- }, [justStartedExiting, sendExitComplete]);
872
- const mapperStateRef = (0, import_react_native_reanimated.useSharedValue)({
873
- emitted: {}
874
- });
875
- const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
876
- "worklet";
877
-
878
- const mapperState = mapperStateRef.value;
879
- const config = configRef.value;
880
- if (config.disableAnimation || config.isHydrating) {
881
- updateMapperState(mapperStateRef, {});
882
- return {};
883
- }
884
- const previouslyEmitted = mapperState.emitted;
885
- const emitted = {};
886
- const result = {};
887
- const emitterSnapshot = emitterSnapshotRef.value;
888
- const snapshot = emitterSnapshot ?? renderSnapshotRef.value;
889
- const animatedValues = snapshot.animated;
890
- const staticValues = snapshot.statics;
891
- const currentlyExiting = isExitingRef.value;
892
- const currentCycleId = exitCycleIdShared.value;
893
- const currentlyCompletingAnimation = isCompletingAnimationRef.value;
894
- const currentDidAnimateCycleId = didAnimateCycleIdShared.value;
895
- for (const key in staticValues) {
896
- result[key] = staticValues[key];
897
- }
898
- for (const key in snapshot.removedKeys) {
899
- if (!key.startsWith("transform:") && !(key in staticValues)) {
900
- result[key] = snapshot.clearValue;
901
- }
902
- }
903
- for (const key in animatedValues) {
904
- if (key === "transform") continue;
905
- const targetValue = animatedValues[key];
906
- emitted[key] = true;
907
- if (typeof targetValue !== "number" && typeof targetValue !== "string") {
908
- result[key] = targetValue;
909
- continue;
910
- }
911
- result[key] = animateSnapshotValue(key, key, targetValue, config.propertyConfigs[key] ?? config.baseConfig, !!previouslyEmitted[key], snapshot.seeds[key], !!snapshot.gatedKeys[key], currentlyExiting, currentCycleId, currentlyCompletingAnimation, currentDidAnimateCycleId, markExitKeyDone, markDidAnimateKeyDone, !!COLOR_STYLE_KEYS[key]);
912
- }
913
- const transforms = snapshot.transforms;
914
- if (transforms.length > 0 || snapshot.removeTransform) {
915
- const validTransforms = [];
916
- for (const t of transforms) {
917
- if (!t) continue;
918
- const keys = Object.keys(t);
919
- if (keys.length === 0) continue;
920
- const transformKey = keys[0];
921
- const value = t[transformKey];
922
- if (typeof value === "number" || typeof value === "string") {
923
- const propConfig = config.propertyConfigs[transformKey] ?? config.baseConfig;
924
- const subKey = `transform:${transformKey}`;
925
- emitted[subKey] = true;
926
- validTransforms.push({
927
- [transformKey]: animateSnapshotValue(subKey, transformKey, value, propConfig, !!previouslyEmitted[subKey], snapshot.seeds[subKey], !!snapshot.gatedKeys[subKey], currentlyExiting, currentCycleId, currentlyCompletingAnimation, currentDidAnimateCycleId, markExitKeyDone, markDidAnimateKeyDone)
928
- });
929
- } else {
930
- validTransforms.push(t);
931
- }
932
- }
933
- if (validTransforms.length > 0 || !("transform" in staticValues)) {
934
- result.transform = validTransforms;
935
- }
936
- }
937
- updateMapperState(mapperStateRef, emitted);
938
- return result;
939
- }, import_core.isWeb ? [
940
- // pass SharedValues so the stable mapper watches them on web (no babel plugin)
941
- renderSnapshotRef, emitterSnapshotRef, configRef, isExitingRef, exitCycleIdShared, markExitKeyDone, isCompletingAnimationRef, didAnimateCycleIdShared, markDidAnimateKeyDone] : void 0);
942
- silenceAnimatedComponentDevCheck(animatedStyle);
943
- if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
944
- console.info("[animations-reanimated] useAnimations", {
945
- animationKey,
946
- componentState,
947
- isExiting,
948
- animatedStyles,
949
- staticStyles,
950
- baseConfig,
951
- propertyConfigs
952
- });
953
- }
954
- return {
955
- style: [staticStyles, animatedStyle]
956
- };
957
- }
958
- };
959
- }
467
+ const animations = {};
468
+ for (const key in animationsConfig) {
469
+ animations[key] = cloneTransitionConfig({
470
+ type: "spring",
471
+ ...animationsConfig[key]
472
+ });
473
+ }
474
+ return {
475
+ needsCustomComponent: true,
476
+ View: import_core.isWeb ? AnimatedView : Animated.View,
477
+ Text: import_core.isWeb ? AnimatedText : Animated.Text,
478
+ isReactNative: true,
479
+ inputStyle: "value",
480
+ outputStyle: "inline",
481
+ avoidReRenders: true,
482
+ animations,
483
+ usePresence: import_use_presence.usePresence,
484
+ ResetPresence: import_use_presence.ResetPresence,
485
+ useAnimatedNumber(initial) {
486
+ const sharedValue = (0, import_react_native_reanimated.useSharedValue)(initial);
487
+ return (0, import_react.useMemo)(() => ({
488
+ getInstance() {
489
+ "worklet";
490
+ return sharedValue;
491
+ },
492
+ getValue() {
493
+ "worklet";
494
+ return sharedValue.value;
495
+ },
496
+ setValue(next, config = { type: "spring" }, onFinish) {
497
+ if (config.type === "direct") {
498
+ sharedValue.value = next;
499
+ onFinish?.();
500
+ } else {
501
+ const cb = onFinish ? (finished) => {
502
+ "worklet";
503
+ if (finished !== false) {
504
+ (0, import_react_native_reanimated.runOnJS)(onFinish)();
505
+ }
506
+ } : void 0;
507
+ const animationConfig = cloneTransitionConfig(config);
508
+ if (import_core.isWeb) {
509
+ sharedValue.value = applyAnimation(next, animationConfig, cb);
510
+ } else {
511
+ (0, import_react_native_reanimated.runOnUI)((targetValue, animationConfig2) => {
512
+ "worklet";
513
+ sharedValue.value = applyAnimation(targetValue, animationConfig2, cb);
514
+ })(next, animationConfig);
515
+ }
516
+ }
517
+ },
518
+ stop() {
519
+ (0, import_react_native_reanimated.cancelAnimation)(sharedValue);
520
+ }
521
+ }), [sharedValue]);
522
+ },
523
+ useAnimatedNumberReaction({ value }, onValue) {
524
+ const instance = value.getInstance();
525
+ return (0, import_react_native_reanimated.useAnimatedReaction)(() => instance.value, (next, prev) => {
526
+ if (prev !== next) {
527
+ (0, import_react_native_reanimated.runOnJS)(onValue)(next);
528
+ }
529
+ }, [onValue, instance]);
530
+ },
531
+ useAnimatedNumberStyle(val, getStyle) {
532
+ const instance = val.getInstance();
533
+ if (import_core.isWeb) {
534
+ return (0, import_react_native_reanimated.useAnimatedStyle)(() => {
535
+ "worklet";
536
+ return getStyle(instance.value);
537
+ }, [instance, getStyle]);
538
+ }
539
+ const styleVal = (0, import_react_native_reanimated.useDerivedValue)(() => {
540
+ "worklet";
541
+ return getStyle(instance.value);
542
+ });
543
+ const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
544
+ "worklet";
545
+ return styleVal.value;
546
+ });
547
+ silenceAnimatedComponentDevCheck(animatedStyle);
548
+ return animatedStyle;
549
+ },
550
+ useAnimatedNumbersStyle(vals, getStyle) {
551
+ const instances = vals.map((v) => v.getInstance());
552
+ const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
553
+ "worklet";
554
+ const currentValues = instances.map((inst) => inst.value);
555
+ return getStyle(...currentValues);
556
+ }, import_core.isWeb ? [getStyle, ...instances] : void 0);
557
+ silenceAnimatedComponentDevCheck(animatedStyle);
558
+ return animatedStyle;
559
+ },
560
+ useAnimations(animationProps) {
561
+ const { props, presence, style, componentState, useStyleEmitter, themeName, stateRef, styleState, onTransition } = animationProps;
562
+ const isHydrating = componentState.unmounted === true;
563
+ const isMounting = componentState.unmounted === "should-enter";
564
+ const isEntering = !!componentState.unmounted;
565
+ const isExiting = presence?.[0] === false;
566
+ const wasEnteringRef = (0, import_react.useRef)(isEntering);
567
+ const justFinishedEntering = wasEnteringRef.current && !isEntering;
568
+ import_react.default.useEffect(() => {
569
+ wasEnteringRef.current = isEntering;
570
+ });
571
+ const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
572
+ const normalized = (0, import_animation_helpers.normalizeTransition)(effectiveTransition);
573
+ const animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
574
+ const animationKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
575
+ const disableAnimation = isHydrating || !animationKey;
576
+ const isDark = themeName?.startsWith("dark") || false;
577
+ const sendExitComplete = presence?.[1];
578
+ const onTransitionRef = (0, import_react.useRef)(onTransition);
579
+ onTransitionRef.current = onTransition;
580
+ const emit = (phase, cause, finished) => {
581
+ onTransitionRef.current?.(phase === "end" ? {
582
+ phase,
583
+ cause,
584
+ finished
585
+ } : {
586
+ phase,
587
+ cause
588
+ });
589
+ };
590
+ const enterStartedRef = (0, import_react.useRef)(false);
591
+ const exitStartedRef = (0, import_react.useRef)(false);
592
+ const updateStartedRef = (0, import_react.useRef)(false);
593
+ const isExitingJSRef = (0, import_react.useRef)(false);
594
+ isExitingJSRef.current = isExiting;
595
+ const updateCycleIdRef = (0, import_react.useRef)(0);
596
+ const pendingUpdateKeysRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
597
+ const updateCompletedRef = (0, import_react.useRef)(false);
598
+ const isCompletingUpdateRef = (0, import_react_native_reanimated.useSharedValue)(false);
599
+ const updateCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(0);
600
+ const markUpdateKeyDone = (0, import_core.useEvent)((key, cycleId, finished) => {
601
+ if (!finished || cycleId !== updateCycleIdRef.current) return;
602
+ if (updateCompletedRef.current) return;
603
+ pendingUpdateKeysRef.current.delete(key);
604
+ if (pendingUpdateKeysRef.current.size === 0) {
605
+ updateCompletedRef.current = true;
606
+ isCompletingUpdateRef.value = false;
607
+ if (updateStartedRef.current) {
608
+ updateStartedRef.current = false;
609
+ emit("end", "update", true);
610
+ }
611
+ }
612
+ });
613
+ const exitCycleIdRef = (0, import_react.useRef)(0);
614
+ const pendingExitKeysRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
615
+ const exitCompletedRef = (0, import_react.useRef)(false);
616
+ const wasExitingRef = (0, import_react.useRef)(false);
617
+ const justStartedExiting = isExiting && !wasExitingRef.current;
618
+ const justStoppedExiting = !isExiting && wasExitingRef.current;
619
+ const markExitKeyDone = (0, import_core.useEvent)((key, cycleId, finished) => {
620
+ if (cycleId !== exitCycleIdRef.current) return;
621
+ if (exitCompletedRef.current) return;
622
+ pendingExitKeysRef.current.delete(key);
623
+ if (pendingExitKeysRef.current.size === 0) {
624
+ exitCompletedRef.current = true;
625
+ if (exitStartedRef.current) {
626
+ exitStartedRef.current = false;
627
+ emit("end", "exit", true);
628
+ }
629
+ sendExitComplete?.();
630
+ }
631
+ });
632
+ const enterCycleIdRef = (0, import_react.useRef)(0);
633
+ const pendingEnterKeysRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
634
+ const enterCompletedRef = (0, import_react.useRef)(false);
635
+ const markEnterKeyDone = (0, import_core.useEvent)((key, cycleId) => {
636
+ if (cycleId !== enterCycleIdRef.current) return;
637
+ if (enterCompletedRef.current) return;
638
+ if (isExitingJSRef.current) return;
639
+ pendingEnterKeysRef.current.delete(key);
640
+ if (pendingEnterKeysRef.current.size === 0) {
641
+ enterCompletedRef.current = true;
642
+ if (enterStartedRef.current) {
643
+ enterStartedRef.current = false;
644
+ emit("end", "enter", true);
645
+ }
646
+ }
647
+ });
648
+ const isExitingRef = (0, import_react_native_reanimated.useSharedValue)(isExiting);
649
+ const exitCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(exitCycleIdRef.current);
650
+ const isCompletingEnterRef = (0, import_react_native_reanimated.useSharedValue)(false);
651
+ const enterCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(enterCycleIdRef.current);
652
+ if (justStartedExiting) {
653
+ exitCycleIdRef.current++;
654
+ exitCompletedRef.current = false;
655
+ pendingExitKeysRef.current.clear();
656
+ enterCycleIdRef.current++;
657
+ pendingEnterKeysRef.current.clear();
658
+ updateCycleIdRef.current++;
659
+ pendingUpdateKeysRef.current.clear();
660
+ updateCompletedRef.current = true;
661
+ }
662
+ if (justStoppedExiting) {
663
+ exitCycleIdRef.current++;
664
+ pendingExitKeysRef.current.clear();
665
+ }
666
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
667
+ isExitingRef.value = isExiting;
668
+ exitCycleIdShared.value = exitCycleIdRef.current;
669
+ isCompletingEnterRef.value = !isExiting && justFinishedEntering && Boolean(onTransitionRef.current);
670
+ enterCycleIdShared.value = enterCycleIdRef.current;
671
+ if (justStartedExiting) {
672
+ isCompletingUpdateRef.value = false;
673
+ updateCycleIdShared.value = updateCycleIdRef.current;
674
+ }
675
+ }, [
676
+ isExiting,
677
+ justFinishedEntering,
678
+ exitCycleIdRef.current,
679
+ enterCycleIdRef.current,
680
+ justStartedExiting
681
+ ]);
682
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
683
+ if (justStoppedExiting && exitStartedRef.current && !exitCompletedRef.current) {
684
+ exitStartedRef.current = false;
685
+ emit("end", "exit", false);
686
+ }
687
+ }, [justStoppedExiting]);
688
+ import_react.default.useEffect(() => {
689
+ wasExitingRef.current = isExiting;
690
+ });
691
+ const committedRenderKeysRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
692
+ const lastPaintedRef = (0, import_react.useRef)({});
693
+ const carryRef = (0, import_react.useRef)({});
694
+ const { animatedStyles, staticStyles, nextCarry } = (0, import_react.useMemo)(() => {
695
+ const animateOnly = props.animateOnly;
696
+ const { animated, statics } = splitAnimationStyles(style, isDark, disableAnimation, animateOnly);
697
+ const nextCarry2 = cloneStyleRecord(carryRef.current);
698
+ for (const key in nextCarry2) {
699
+ if (!(key in animated)) delete nextCarry2[key];
700
+ }
701
+ for (const key in animated) {
702
+ if (!(key in nextCarry2)) {
703
+ nextCarry2[key] = cloneAnimationValue(animated[key]);
704
+ }
705
+ statics[key] = nextCarry2[key];
706
+ }
707
+ return {
708
+ animatedStyles: animated,
709
+ staticStyles: statics,
710
+ nextCarry: nextCarry2
711
+ };
712
+ }, [
713
+ disableAnimation,
714
+ style,
715
+ isDark,
716
+ props.animateOnly
717
+ ]);
718
+ const renderSnapshot = (0, import_react.useMemo)(() => buildSnapshot(animatedStyles, staticStyles, getAnimatedTransforms(animatedStyles.transform), committedRenderKeysRef.current, lastPaintedRef.current), [animatedStyles, staticStyles]);
719
+ const renderSnapshotRef = (0, import_react_native_reanimated.useSharedValue)({
720
+ animated: {},
721
+ statics: {},
722
+ transforms: [],
723
+ gatedKeys: {},
724
+ seeds: {},
725
+ removedKeys: {},
726
+ removeTransform: false,
727
+ clearValue: import_core.isWeb ? "" : null
728
+ });
729
+ const emitterSnapshotRef = (0, import_react_native_reanimated.useSharedValue)(null);
730
+ const emitterKeysRef = (0, import_react.useRef)(null);
731
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
732
+ carryRef.current = nextCarry;
733
+ committedRenderKeysRef.current = renderSnapshot.keys;
734
+ lastPaintedRef.current = renderSnapshot.painted;
735
+ }, [nextCarry, renderSnapshot]);
736
+ const pseudoActiveRef = (0, import_react.useRef)(false);
737
+ const publishedSnapshotRef = (0, import_react.useRef)(null);
738
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
739
+ const renderChanged = publishedSnapshotRef.current !== renderSnapshot.value;
740
+ const droppingLatch = (isExiting || !pseudoActiveRef.current && publishedSnapshotRef.current !== null && renderChanged) && emitterSnapshotRef.value !== null;
741
+ const emitterKeys = droppingLatch ? emitterKeysRef.current : null;
742
+ if (droppingLatch || renderChanged) {
743
+ const removedKeys = emitterKeys ? {
744
+ ...renderSnapshot.value.removedKeys,
745
+ ...getRemovedAnimatedKeys(renderSnapshot.keys, emitterKeys)
746
+ } : renderSnapshot.value.removedKeys;
747
+ renderSnapshotRef.value = {
748
+ ...renderSnapshot.value,
749
+ removedKeys,
750
+ removeTransform: Object.keys(removedKeys).some((key) => key.startsWith("transform:"))
751
+ };
752
+ publishedSnapshotRef.current = renderSnapshot.value;
753
+ }
754
+ if (droppingLatch) {
755
+ emitterSnapshotRef.value = null;
756
+ emitterKeysRef.current = null;
757
+ }
758
+ });
759
+ const { baseConfig, propertyConfigs } = (0, import_react.useMemo)(() => {
760
+ if (isHydrating) {
761
+ return {
762
+ baseConfig: {
763
+ type: "timing",
764
+ duration: 0
765
+ },
766
+ propertyConfigs: {}
767
+ };
768
+ }
769
+ return buildTransitionConfig(effectiveTransition, animations, animationState, getStyleKeys(animatedStyles));
770
+ }, [
771
+ isHydrating,
772
+ effectiveTransition,
773
+ animatedStyles,
774
+ animationState
775
+ ]);
776
+ const configRef = (0, import_react_native_reanimated.useSharedValue)({
777
+ baseConfig,
778
+ propertyConfigs,
779
+ disableAnimation,
780
+ isHydrating
781
+ });
782
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
783
+ configRef.value = {
784
+ baseConfig,
785
+ propertyConfigs,
786
+ disableAnimation,
787
+ isHydrating
788
+ };
789
+ }, [
790
+ baseConfig,
791
+ propertyConfigs,
792
+ disableAnimation,
793
+ isHydrating
794
+ ]);
795
+ useStyleEmitter?.((nextStyle, effectiveTransition2, pseudoActive) => {
796
+ if (isExitingJSRef.current) return;
797
+ pseudoActiveRef.current = pseudoActive === true;
798
+ const animateOnly = props.animateOnly;
799
+ const transitionToUse = effectiveTransition2 ?? props.transition;
800
+ const { baseConfig: newBase, propertyConfigs: newPropertyConfigs } = buildTransitionConfig(transitionToUse, animations, animationState, getStyleKeys(nextStyle));
801
+ configRef.value = {
802
+ baseConfig: newBase,
803
+ propertyConfigs: newPropertyConfigs,
804
+ disableAnimation: configRef.value.disableAnimation,
805
+ isHydrating: configRef.value.isHydrating
806
+ };
807
+ const previousKeys = emitterKeysRef.current ?? committedRenderKeysRef.current;
808
+ const { animated, statics } = splitAnimationStyles(nextStyle, isDark, configRef.value.disableAnimation, animateOnly);
809
+ const snapshot = buildSnapshot(animated, statics, getAnimatedTransforms(animated.transform), previousKeys, lastPaintedRef.current);
810
+ emitterSnapshotRef.value = snapshot.value;
811
+ emitterKeysRef.current = snapshot.keys;
812
+ lastPaintedRef.current = snapshot.painted;
813
+ if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
814
+ console.info("[animations-reanimated] useStyleEmitter update", {
815
+ animated,
816
+ statics,
817
+ transforms: snapshot.value.transforms
818
+ });
819
+ }
820
+ });
821
+ const exitKeysRegistered = (0, import_react.useRef)(false);
822
+ const enterKeysRegistered = (0, import_react.useRef)(false);
823
+ if (!isExiting && justFinishedEntering && onTransition) {
824
+ const enterKeys = getGatedKeys(renderSnapshot.value);
825
+ enterCycleIdRef.current++;
826
+ enterCompletedRef.current = false;
827
+ pendingEnterKeysRef.current = new Set(enterKeys);
828
+ enterKeysRegistered.current = enterKeys.length > 0;
829
+ }
830
+ if (justStartedExiting && sendExitComplete) {
831
+ const exitKeys = getGatedKeys(renderSnapshot.value);
832
+ pendingExitKeysRef.current = new Set(exitKeys);
833
+ exitKeysRegistered.current = exitKeys.length > 0;
834
+ }
835
+ const previousUpdateStyleRef = (0, import_react.useRef)(null);
836
+ const updateStyle = onTransition ? JSON.stringify(style) : null;
837
+ const previousUpdateStyle = previousUpdateStyleRef.current;
838
+ const shouldRegisterUpdate = updateStyle !== null && previousUpdateStyle !== null && previousUpdateStyle !== updateStyle && !isExiting && !isEntering && !justFinishedEntering;
839
+ const updateKeys = shouldRegisterUpdate ? getGatedKeys(renderSnapshot.value) : [];
840
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
841
+ if (updateStyle === null) {
842
+ previousUpdateStyleRef.current = null;
843
+ isCompletingUpdateRef.value = false;
844
+ return;
845
+ }
846
+ const previousStyleStillCurrent = previousUpdateStyleRef.current === previousUpdateStyle;
847
+ previousUpdateStyleRef.current = updateStyle;
848
+ if (!shouldRegisterUpdate || !previousStyleStillCurrent) return;
849
+ const cycleId = ++updateCycleIdRef.current;
850
+ pendingUpdateKeysRef.current = new Set(updateKeys);
851
+ updateCompletedRef.current = updateKeys.length === 0;
852
+ isCompletingUpdateRef.value = updateKeys.length > 0;
853
+ updateCycleIdShared.value = cycleId;
854
+ if (updateStartedRef.current) {
855
+ emit("end", "update", false);
856
+ }
857
+ updateStartedRef.current = true;
858
+ emit("start", "update");
859
+ if (updateKeys.length === 0) {
860
+ updateStartedRef.current = false;
861
+ emit("end", "update", true);
862
+ }
863
+ }, [updateStyle, shouldRegisterUpdate]);
864
+ import_react.default.useEffect(() => {
865
+ if (!justStartedExiting || !sendExitComplete) return;
866
+ if (enterStartedRef.current) {
867
+ enterStartedRef.current = false;
868
+ emit("end", "enter", false);
869
+ }
870
+ if (updateStartedRef.current) {
871
+ updateStartedRef.current = false;
872
+ emit("end", "update", false);
873
+ }
874
+ if (onTransitionRef.current && !exitStartedRef.current) {
875
+ exitStartedRef.current = true;
876
+ emit("start", "exit");
877
+ }
878
+ if (!exitKeysRegistered.current && pendingExitKeysRef.current.size === 0) {
879
+ if (!exitCompletedRef.current) {
880
+ exitCompletedRef.current = true;
881
+ if (exitStartedRef.current) {
882
+ exitStartedRef.current = false;
883
+ emit("end", "exit", true);
884
+ }
885
+ sendExitComplete();
886
+ }
887
+ }
888
+ }, [justStartedExiting, sendExitComplete]);
889
+ import_react.default.useEffect(() => {
890
+ if (isExiting || !justFinishedEntering || !onTransition) return;
891
+ if (!enterStartedRef.current) {
892
+ enterStartedRef.current = true;
893
+ emit("start", "enter");
894
+ }
895
+ if (!enterKeysRegistered.current && pendingEnterKeysRef.current.size === 0) {
896
+ if (!enterCompletedRef.current) {
897
+ enterCompletedRef.current = true;
898
+ if (enterStartedRef.current) {
899
+ enterStartedRef.current = false;
900
+ emit("end", "enter", true);
901
+ }
902
+ }
903
+ }
904
+ }, [
905
+ isExiting,
906
+ justFinishedEntering,
907
+ onTransition
908
+ ]);
909
+ const mapperStateRef = (0, import_react_native_reanimated.useSharedValue)({ emitted: {} });
910
+ const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
911
+ "worklet";
912
+ const mapperState = mapperStateRef.value;
913
+ const config = configRef.value;
914
+ if (config.disableAnimation || config.isHydrating) {
915
+ updateMapperState(mapperStateRef, {});
916
+ return {};
917
+ }
918
+ const previouslyEmitted = mapperState.emitted;
919
+ const emitted = {};
920
+ const result = {};
921
+ const emitterSnapshot = emitterSnapshotRef.value;
922
+ const snapshot = emitterSnapshot ?? renderSnapshotRef.value;
923
+ const animatedValues = snapshot.animated;
924
+ const staticValues = snapshot.statics;
925
+ const currentlyExiting = isExitingRef.value;
926
+ const currentCycleId = exitCycleIdShared.value;
927
+ const currentlyCompletingEnter = isCompletingEnterRef.value;
928
+ const currentEnterCycleId = enterCycleIdShared.value;
929
+ const currentlyCompletingUpdate = isCompletingUpdateRef.value;
930
+ const currentUpdateCycleId = updateCycleIdShared.value;
931
+ for (const key in staticValues) {
932
+ result[key] = staticValues[key];
933
+ }
934
+ for (const key in snapshot.removedKeys) {
935
+ if (!key.startsWith("transform:") && !(key in staticValues)) {
936
+ result[key] = snapshot.clearValue;
937
+ }
938
+ }
939
+ for (const key in animatedValues) {
940
+ if (key === "transform") continue;
941
+ const targetValue = animatedValues[key];
942
+ emitted[key] = true;
943
+ if (typeof targetValue !== "number" && typeof targetValue !== "string") {
944
+ result[key] = targetValue;
945
+ continue;
946
+ }
947
+ result[key] = animateSnapshotValue(key, key, targetValue, config.propertyConfigs[key] ?? config.baseConfig, !!previouslyEmitted[key], snapshot.seeds[key], !!snapshot.gatedKeys[key], currentlyExiting, currentCycleId, currentlyCompletingEnter, currentEnterCycleId, currentlyCompletingUpdate, currentUpdateCycleId, markExitKeyDone, markEnterKeyDone, markUpdateKeyDone, !!COLOR_STYLE_KEYS[key]);
948
+ }
949
+ const transforms = snapshot.transforms;
950
+ if (transforms.length > 0 || snapshot.removeTransform) {
951
+ const validTransforms = [];
952
+ for (const t of transforms) {
953
+ if (!t) continue;
954
+ const keys = Object.keys(t);
955
+ if (keys.length === 0) continue;
956
+ const transformKey = keys[0];
957
+ const value = t[transformKey];
958
+ if (typeof value === "number" || typeof value === "string") {
959
+ const propConfig = config.propertyConfigs[transformKey] ?? config.baseConfig;
960
+ const subKey = `transform:${transformKey}`;
961
+ emitted[subKey] = true;
962
+ validTransforms.push({ [transformKey]: animateSnapshotValue(subKey, transformKey, value, propConfig, !!previouslyEmitted[subKey], snapshot.seeds[subKey], !!snapshot.gatedKeys[subKey], currentlyExiting, currentCycleId, currentlyCompletingEnter, currentEnterCycleId, currentlyCompletingUpdate, currentUpdateCycleId, markExitKeyDone, markEnterKeyDone, markUpdateKeyDone) });
963
+ } else {
964
+ validTransforms.push(t);
965
+ }
966
+ }
967
+ if (validTransforms.length > 0 || !("transform" in staticValues)) {
968
+ result.transform = validTransforms;
969
+ }
970
+ }
971
+ updateMapperState(mapperStateRef, emitted);
972
+ return result;
973
+ }, import_core.isWeb ? [
974
+ renderSnapshotRef,
975
+ emitterSnapshotRef,
976
+ configRef,
977
+ isExitingRef,
978
+ exitCycleIdShared,
979
+ markExitKeyDone,
980
+ isCompletingEnterRef,
981
+ enterCycleIdShared,
982
+ markEnterKeyDone,
983
+ isCompletingUpdateRef,
984
+ updateCycleIdShared,
985
+ markUpdateKeyDone
986
+ ] : void 0);
987
+ silenceAnimatedComponentDevCheck(animatedStyle);
988
+ if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
989
+ console.info("[animations-reanimated] useAnimations", {
990
+ animationKey,
991
+ componentState,
992
+ isExiting,
993
+ animatedStyles,
994
+ staticStyles,
995
+ baseConfig,
996
+ propertyConfigs
997
+ });
998
+ }
999
+ return { style: [staticStyles, animatedStyle] };
1000
+ }
1001
+ };
1002
+ }