@rootnative/inertia 0.0.0-alpha.2 → 0.0.0-alpha.3
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-5RCMIJGZ.js +8 -0
- package/dist/chunk-6FENLMCA.mjs +257 -0
- package/dist/chunk-E4MDU4YV.mjs +6 -0
- package/dist/chunk-FSPQVLBF.mjs +6 -0
- package/dist/chunk-GJD4VVAS.mjs +103 -0
- package/dist/chunk-JWHKMNYA.js +112 -0
- package/dist/chunk-K7ICHCTZ.js +54 -0
- package/dist/chunk-KARV7QKF.mjs +6 -0
- package/dist/chunk-KVSJWO5X.js +1011 -0
- package/dist/chunk-NJYRN3WG.js +8 -0
- package/dist/chunk-R3ODWDTI.js +8 -0
- package/dist/chunk-RJNR7CFN.mjs +6 -0
- package/dist/chunk-S4AEU72O.js +8 -0
- package/dist/chunk-SFRNO6AW.js +267 -0
- package/dist/chunk-UM3WVSKQ.mjs +6 -0
- package/dist/chunk-UMFBAFZP.js +8 -0
- package/dist/chunk-UXK4YCT6.mjs +1003 -0
- package/dist/chunk-W6IS4HAK.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
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNativeWorklets = require('react-native-worklets');
|
|
4
|
+
var reactNativeReanimated = require('react-native-reanimated');
|
|
5
|
+
|
|
6
|
+
// src/transitions/easing.ts
|
|
7
|
+
function ensureWorkletEasing(easing) {
|
|
8
|
+
if (!easing) return void 0;
|
|
9
|
+
const fn = isEasingFactory(easing) ? easing.factory() : easing;
|
|
10
|
+
if (reactNativeWorklets.isWorkletFunction(fn)) return fn;
|
|
11
|
+
const wrapped = (t) => {
|
|
12
|
+
"worklet";
|
|
13
|
+
return fn(t);
|
|
14
|
+
};
|
|
15
|
+
return wrapped;
|
|
16
|
+
}
|
|
17
|
+
function isEasingFactory(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/transitions/spring.ts
|
|
22
|
+
var DEFAULT_SPRING = {
|
|
23
|
+
tension: 170,
|
|
24
|
+
friction: 26,
|
|
25
|
+
mass: 1
|
|
26
|
+
};
|
|
27
|
+
function springToReanimated(t) {
|
|
28
|
+
"worklet";
|
|
29
|
+
return {
|
|
30
|
+
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
31
|
+
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
32
|
+
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
33
|
+
velocity: t.velocity,
|
|
34
|
+
restSpeedThreshold: t.restSpeedThreshold,
|
|
35
|
+
restDisplacementThreshold: t.restDisplacementThreshold
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/transitions/resolve.ts
|
|
40
|
+
var DEFAULT_TIMING_DURATION = 250;
|
|
41
|
+
function buildSpring(cfg, toValue, cb) {
|
|
42
|
+
return reactNativeReanimated.withSpring(toValue, springToReanimated(cfg), cb);
|
|
43
|
+
}
|
|
44
|
+
function buildTiming(cfg, toValue, cb) {
|
|
45
|
+
return reactNativeReanimated.withTiming(
|
|
46
|
+
toValue,
|
|
47
|
+
{
|
|
48
|
+
duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
|
|
49
|
+
easing: ensureWorkletEasing(cfg.easing) ?? reactNativeReanimated.Easing.inOut(reactNativeReanimated.Easing.ease)
|
|
50
|
+
},
|
|
51
|
+
cb
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function buildDecay(cfg, cb) {
|
|
55
|
+
return reactNativeReanimated.withDecay(
|
|
56
|
+
{
|
|
57
|
+
velocity: cfg.velocity ?? 0,
|
|
58
|
+
deceleration: cfg.deceleration,
|
|
59
|
+
clamp: cfg.clamp
|
|
60
|
+
},
|
|
61
|
+
cb
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function buildOne(cfg, toValue, cb) {
|
|
65
|
+
if (cfg.type === "no-animation") {
|
|
66
|
+
if (cb) cb(true, toValue);
|
|
67
|
+
return toValue;
|
|
68
|
+
}
|
|
69
|
+
if (cfg.type === "decay") return buildDecay(cfg, cb);
|
|
70
|
+
if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
|
|
71
|
+
return buildSpring(cfg, toValue, cb);
|
|
72
|
+
}
|
|
73
|
+
function applyRepeat(animation, repeat) {
|
|
74
|
+
if (repeat === void 0) return animation;
|
|
75
|
+
if (repeat === "infinite") {
|
|
76
|
+
return reactNativeReanimated.withRepeat(animation, -1, true);
|
|
77
|
+
}
|
|
78
|
+
if (typeof repeat === "number") {
|
|
79
|
+
return reactNativeReanimated.withRepeat(animation, repeat, true);
|
|
80
|
+
}
|
|
81
|
+
const count = repeat.count === "infinite" ? -1 : repeat.count;
|
|
82
|
+
const alternate = repeat.alternate ?? true;
|
|
83
|
+
return reactNativeReanimated.withRepeat(animation, count, alternate);
|
|
84
|
+
}
|
|
85
|
+
function applyDelay(animation, delay) {
|
|
86
|
+
if (!delay || delay <= 0) return animation;
|
|
87
|
+
return reactNativeReanimated.withDelay(delay, animation);
|
|
88
|
+
}
|
|
89
|
+
function resolveTransition(config, toValue, callback) {
|
|
90
|
+
const cfg = config ?? { type: "spring" };
|
|
91
|
+
const base = buildOne(cfg, toValue, callback);
|
|
92
|
+
const repeated = applyRepeat(base, repeatOf(cfg));
|
|
93
|
+
return applyDelay(repeated, delayOf(cfg));
|
|
94
|
+
}
|
|
95
|
+
function repeatOf(cfg) {
|
|
96
|
+
if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
|
|
97
|
+
return cfg.repeat;
|
|
98
|
+
}
|
|
99
|
+
function stripRepeat(cfg) {
|
|
100
|
+
if (!cfg) return cfg;
|
|
101
|
+
if (cfg.type === "no-animation" || cfg.type === "decay") return cfg;
|
|
102
|
+
if (cfg.repeat === void 0) return cfg;
|
|
103
|
+
const next = { ...cfg };
|
|
104
|
+
delete next.repeat;
|
|
105
|
+
return next;
|
|
106
|
+
}
|
|
107
|
+
function delayOf(cfg) {
|
|
108
|
+
if (cfg.type === "no-animation") return void 0;
|
|
109
|
+
return cfg.delay;
|
|
110
|
+
}
|
|
111
|
+
function isStepObject(v) {
|
|
112
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "to" in v;
|
|
113
|
+
}
|
|
114
|
+
function resolveAnimatableValue(value, base, factory) {
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
const steps = value;
|
|
117
|
+
const stepBase = stripRepeat(base);
|
|
118
|
+
const animations = steps.map(
|
|
119
|
+
(step2, i) => resolveStep(step2, stepBase, factory?.("step", i))
|
|
120
|
+
);
|
|
121
|
+
const seq = reactNativeReanimated.withSequence(...animations);
|
|
122
|
+
return applyRepeat(seq, base ? repeatOf(base) : void 0);
|
|
123
|
+
}
|
|
124
|
+
const step = value;
|
|
125
|
+
const cb = factory?.("animation", void 0);
|
|
126
|
+
if (isStepObject(step)) {
|
|
127
|
+
return resolveStep(step, base, cb);
|
|
128
|
+
}
|
|
129
|
+
return resolveTransition(base, step, cb);
|
|
130
|
+
}
|
|
131
|
+
function resolveStep(step, base, cb) {
|
|
132
|
+
if (isStepObject(step)) {
|
|
133
|
+
const { to, ...override } = step;
|
|
134
|
+
const merged = mergeTransition(base, override);
|
|
135
|
+
return resolveTransition(merged, to, cb);
|
|
136
|
+
}
|
|
137
|
+
return resolveTransition(base, step, cb);
|
|
138
|
+
}
|
|
139
|
+
function mergeTransition(base, override) {
|
|
140
|
+
if (override.type && base && override.type !== base.type) {
|
|
141
|
+
return override;
|
|
142
|
+
}
|
|
143
|
+
return { ...base ?? { type: "spring" }, ...override };
|
|
144
|
+
}
|
|
145
|
+
var CSS_KEYWORDS = {
|
|
146
|
+
ease: [0.25, 0.1, 0.25, 1],
|
|
147
|
+
"ease-in": [0.42, 0, 1, 1],
|
|
148
|
+
"ease-out": [0, 0, 0.58, 1],
|
|
149
|
+
"ease-in-out": [0.42, 0, 0.58, 1]
|
|
150
|
+
};
|
|
151
|
+
var CSS_FUNCTION = /^cubic-bezier\((.*)\)$/;
|
|
152
|
+
function cubicBezier(first, y1, x2, y2) {
|
|
153
|
+
if (typeof first === "string") return fromCss(first);
|
|
154
|
+
return bezier(first, y1, x2, y2, void 0);
|
|
155
|
+
}
|
|
156
|
+
function fromCss(input) {
|
|
157
|
+
const token = input.trim().toLowerCase();
|
|
158
|
+
if (token === "linear") return reactNativeReanimated.Easing.linear;
|
|
159
|
+
const keyword = CSS_KEYWORDS[token];
|
|
160
|
+
if (keyword) return bezier(...keyword, input);
|
|
161
|
+
const match = CSS_FUNCTION.exec(token);
|
|
162
|
+
if (!match) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`[inertia] cubicBezier: unsupported easing token ${JSON.stringify(input)}. Expected four numbers, a 'cubic-bezier(x1, y1, x2, y2)' string, or one of the CSS keywords 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const parts = match[1].split(",").map((p) => Number(p.trim()));
|
|
168
|
+
if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n))) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`[inertia] cubicBezier: could not parse ${JSON.stringify(input)} \u2014 expected exactly four finite numbers inside cubic-bezier(...).`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return bezier(parts[0], parts[1], parts[2], parts[3], input);
|
|
174
|
+
}
|
|
175
|
+
function bezier(x1, y1, x2, y2, source) {
|
|
176
|
+
const describe = () => source !== void 0 ? JSON.stringify(source) : `cubicBezier(${x1}, ${y1}, ${x2}, ${y2})`;
|
|
177
|
+
for (const n of [x1, y1, x2, y2]) {
|
|
178
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`[inertia] cubicBezier: ${describe()} \u2014 every control point must be a finite number.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`[inertia] cubicBezier: ${describe()} \u2014 x1 and x2 must be within [0, 1] (got x1=${x1}, x2=${x2}).`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return reactNativeReanimated.Easing.bezier(x1, y1, x2, y2);
|
|
190
|
+
}
|
|
191
|
+
var DEFAULT_TIMING_DURATION2 = 250;
|
|
192
|
+
function buildReleaseAnimation(transition, toValue) {
|
|
193
|
+
"worklet";
|
|
194
|
+
if (transition.type === "no-animation") return toValue;
|
|
195
|
+
if (transition.type === "decay") {
|
|
196
|
+
const cfg = { velocity: transition.velocity ?? 0 };
|
|
197
|
+
if (transition.deceleration !== void 0) {
|
|
198
|
+
cfg.deceleration = transition.deceleration;
|
|
199
|
+
}
|
|
200
|
+
if (transition.clamp !== void 0) cfg.clamp = transition.clamp;
|
|
201
|
+
return reactNativeReanimated.withDecay(cfg);
|
|
202
|
+
}
|
|
203
|
+
if (transition.type === "timing") {
|
|
204
|
+
const e = transition.easing;
|
|
205
|
+
const easingFn = e && typeof e === "object" && "factory" in e ? e.factory() : e ?? reactNativeReanimated.Easing.inOut(reactNativeReanimated.Easing.ease);
|
|
206
|
+
return reactNativeReanimated.withTiming(toValue, {
|
|
207
|
+
duration: transition.duration ?? DEFAULT_TIMING_DURATION2,
|
|
208
|
+
easing: easingFn
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return reactNativeReanimated.withSpring(toValue, springToReanimated(transition));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/transitions/keys.ts
|
|
215
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
216
|
+
"type",
|
|
217
|
+
"tension",
|
|
218
|
+
"friction",
|
|
219
|
+
"mass",
|
|
220
|
+
"velocity",
|
|
221
|
+
"restSpeedThreshold",
|
|
222
|
+
"restDisplacementThreshold",
|
|
223
|
+
"duration",
|
|
224
|
+
"easing",
|
|
225
|
+
"delay",
|
|
226
|
+
"repeat",
|
|
227
|
+
"deceleration",
|
|
228
|
+
"clamp"
|
|
229
|
+
]);
|
|
230
|
+
function isTopLevelTransition(t) {
|
|
231
|
+
if (t === null || typeof t !== "object") return false;
|
|
232
|
+
const keys = Object.keys(t);
|
|
233
|
+
if (keys.length === 0) return false;
|
|
234
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/transitions/sig.ts
|
|
238
|
+
function stableSig(value) {
|
|
239
|
+
if (value === void 0) return "";
|
|
240
|
+
try {
|
|
241
|
+
return stableStringify(value);
|
|
242
|
+
} catch {
|
|
243
|
+
return String(value);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function stableStringify(v) {
|
|
247
|
+
if (v === null || typeof v !== "object") {
|
|
248
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
249
|
+
return JSON.stringify(v);
|
|
250
|
+
}
|
|
251
|
+
if (Array.isArray(v)) {
|
|
252
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
253
|
+
}
|
|
254
|
+
const obj = v;
|
|
255
|
+
const keys = Object.keys(obj).sort();
|
|
256
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
exports.DEFAULT_SPRING = DEFAULT_SPRING;
|
|
260
|
+
exports.buildReleaseAnimation = buildReleaseAnimation;
|
|
261
|
+
exports.cubicBezier = cubicBezier;
|
|
262
|
+
exports.ensureWorkletEasing = ensureWorkletEasing;
|
|
263
|
+
exports.isTopLevelTransition = isTopLevelTransition;
|
|
264
|
+
exports.resolveAnimatableValue = resolveAnimatableValue;
|
|
265
|
+
exports.resolveTransition = resolveTransition;
|
|
266
|
+
exports.springToReanimated = springToReanimated;
|
|
267
|
+
exports.stableSig = stableSig;
|