@ssgoi/core 6.6.9 → 6.6.11

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.
@@ -0,0 +1,439 @@
1
+ var S = Object.defineProperty;
2
+ var F = (a, i, t) => i in a ? S(a, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[i] = t;
3
+ var r = (a, i, t) => F(a, typeof i != "symbol" ? i + "" : i, t);
4
+ class f {
5
+ constructor() {
6
+ /** Current playback rate (1 = realtime, 0 = paused, negative = backwards) */
7
+ r(this, "_playbackRate", 1);
8
+ /** Fired every frame with the most recent value. Optional. */
9
+ r(this, "onUpdate");
10
+ /** Fired once when the animation settles. */
11
+ r(this, "onComplete");
12
+ }
13
+ get playbackRate() {
14
+ return this._playbackRate;
15
+ }
16
+ set playbackRate(i) {
17
+ this._playbackRate = i;
18
+ }
19
+ }
20
+ const O = 0.01, V = 0.01, b = 0.05;
21
+ function R(a) {
22
+ return new Promise((i) => {
23
+ requestAnimationFrame(() => {
24
+ requestAnimationFrame(() => {
25
+ i();
26
+ });
27
+ });
28
+ });
29
+ }
30
+ const T = 1e3 / 60, g = 1e3 / 30, k = g + 1;
31
+ class w {
32
+ constructor() {
33
+ r(this, "drivers", /* @__PURE__ */ new Set());
34
+ r(this, "observers", /* @__PURE__ */ new Set());
35
+ r(this, "frameRequest", null);
36
+ r(this, "previousTimestamp", null);
37
+ r(this, "tick", (i) => {
38
+ this.frameRequest = null;
39
+ const t = this.previousTimestamp === null ? T : Math.max(0, i - this.previousTimestamp);
40
+ this.previousTimestamp = i;
41
+ const e = {
42
+ delta: Math.min(t, g),
43
+ rawDelta: t
44
+ };
45
+ this.runPhase(this.drivers, e), this.runPhase(this.observers, e), this.hasCallbacks() ? this.requestFrame() : this.previousTimestamp = null;
46
+ });
47
+ }
48
+ subscribe(i, t = "drive") {
49
+ const e = t === "drive" ? this.drivers : this.observers;
50
+ return e.add(i), this.requestFrame(), () => {
51
+ e.delete(i), this.stopIfIdle();
52
+ };
53
+ }
54
+ requestFrame() {
55
+ this.frameRequest !== null || !this.hasCallbacks() || (this.frameRequest = requestAnimationFrame(this.tick));
56
+ }
57
+ runPhase(i, t) {
58
+ for (const e of [...i])
59
+ i.has(e) && e(t);
60
+ }
61
+ hasCallbacks() {
62
+ return this.drivers.size > 0 || this.observers.size > 0;
63
+ }
64
+ stopIfIdle() {
65
+ this.hasCallbacks() || (this.frameRequest !== null && typeof cancelAnimationFrame < "u" && cancelAnimationFrame(this.frameRequest), this.frameRequest = null, this.previousTimestamp = null);
66
+ }
67
+ }
68
+ const y = new w(), p = 1e3 / 60, C = 2;
69
+ class _ extends f {
70
+ constructor(t) {
71
+ super();
72
+ r(this, "element");
73
+ r(this, "integrator");
74
+ r(this, "styleFn");
75
+ r(this, "lowerBound");
76
+ r(this, "upperBound");
77
+ r(this, "currentValue");
78
+ r(this, "currentVelocity", 0);
79
+ r(this, "frames", []);
80
+ r(this, "waapi", null);
81
+ r(this, "runId", 0);
82
+ r(this, "waitingForStart", !1);
83
+ r(this, "startReady", !1);
84
+ r(this, "pendingFirstFrame");
85
+ r(this, "stopStartupClock", null);
86
+ r(this, "startupStableFrames", 0);
87
+ r(this, "running", !1);
88
+ r(this, "paused", !1);
89
+ r(this, "settled", !1);
90
+ r(this, "reversing", !1);
91
+ this.element = t.element, this.integrator = t.integrator, this.styleFn = t.style, this.lowerBound = t.lowerBound ?? 0, this.upperBound = t.upperBound ?? 1, this.currentValue = this.lowerBound, this.onUpdate = t.onUpdate, this.onComplete = t.onComplete;
92
+ }
93
+ play() {
94
+ if (this.reversing = !1, this.paused && this.waapi) {
95
+ if (this.paused = !1, this.running = !0, this.waitingForStart) {
96
+ this.startReady && this.startFramePacedPlayback(this.waapi);
97
+ return;
98
+ }
99
+ this.waapi.play();
100
+ return;
101
+ }
102
+ this.runToward(this.upperBound);
103
+ }
104
+ reverse() {
105
+ this.reversing = !0, this.runToward(this.lowerBound);
106
+ }
107
+ pause() {
108
+ var t, e;
109
+ this.running && (this.captureLiveState(), (t = this.waapi) == null || t.pause(), (e = this.stopStartupClock) == null || e.call(this), this.stopStartupClock = null, this.running = !1, this.paused = !0);
110
+ }
111
+ complete() {
112
+ var t;
113
+ this.clearWaapi(), this.running = !1, this.paused = !1, this.currentValue = this.upperBound, this.currentVelocity = 0, this.applyStyleAt(this.currentValue), this.settled = !0, (t = this.onComplete) == null || t.call(this);
114
+ }
115
+ /**
116
+ * Drop the WAAPI forwards-fill after the run has settled, letting inline
117
+ * styles govern the resting visual. Call only from `onComplete` (the run is
118
+ * already finished) — otherwise it cancels mid-flight. Unlike `complete()`,
119
+ * it writes no final frame, so a caller can reset the element to its natural
120
+ * state without the lingering fill clobbering it.
121
+ */
122
+ releaseFill() {
123
+ this.clearWaapi();
124
+ }
125
+ get isAnimating() {
126
+ return this.running;
127
+ }
128
+ get isPaused() {
129
+ return this.paused;
130
+ }
131
+ get isComplete() {
132
+ return this.settled;
133
+ }
134
+ get isReversing() {
135
+ return this.reversing;
136
+ }
137
+ get progress() {
138
+ this.running && this.captureLiveState();
139
+ const t = this.upperBound - this.lowerBound;
140
+ if (t === 0) return 0;
141
+ const e = (this.currentValue - this.lowerBound) / t;
142
+ return e < 0 ? 0 : e > 1 ? 1 : e;
143
+ }
144
+ findTimeForProgress(t) {
145
+ if (this.frames.length < 2) return null;
146
+ const e = this.upperBound - this.lowerBound;
147
+ if (e === 0) return 0;
148
+ for (const s of this.frames)
149
+ if ((s.position - this.lowerBound) / e >= t) return s.time;
150
+ return this.frames[this.frames.length - 1].time;
151
+ }
152
+ get playbackRate() {
153
+ return super.playbackRate;
154
+ }
155
+ set playbackRate(t) {
156
+ super.playbackRate = t, this.waapi && (this.waapi.playbackRate = t);
157
+ }
158
+ getPose() {
159
+ return this.running && this.captureLiveState(), [
160
+ {
161
+ element: this.element,
162
+ value: this.currentValue,
163
+ velocity: this.currentVelocity
164
+ }
165
+ ];
166
+ }
167
+ getTimeline() {
168
+ const t = this.frames.map((e) => {
169
+ const s = e.position, n = this.lowerBound + this.upperBound - s;
170
+ return {
171
+ time: e.time,
172
+ value: e.position,
173
+ velocity: e.velocity,
174
+ style: this.styleFn(s, n)
175
+ };
176
+ });
177
+ return [{ element: this.element, frames: t }];
178
+ }
179
+ matchInto(t) {
180
+ const e = t.find((s) => s.element === this.element);
181
+ e && (this.currentValue = e.value, this.currentVelocity = e.velocity);
182
+ }
183
+ /* ───────────────────────────────────────────────────────── private */
184
+ runToward(t) {
185
+ var o;
186
+ if (this.running && this.captureLiveState(), this.clearWaapi(), this.running = !1, this.paused = !1, this.settled = !1, this.frames = A(
187
+ this.integrator,
188
+ this.currentValue,
189
+ t,
190
+ this.currentVelocity
191
+ ), this.frames.length === 0) {
192
+ this.currentValue = t, this.currentVelocity = 0, this.applyStyleAt(t), this.settled = !0, (o = this.onComplete) == null || o.call(this);
193
+ return;
194
+ }
195
+ const e = this.frames.map((c) => {
196
+ const d = c.position, v = this.lowerBound + this.upperBound - d;
197
+ return this.styleFn(d, v);
198
+ }), s = e[0], n = this.frames[this.frames.length - 1], h = n.time, u = ++this.runId, l = this.element.animate(e, {
199
+ duration: h,
200
+ fill: "both",
201
+ easing: "linear",
202
+ composite: "replace"
203
+ });
204
+ l.playbackRate = this.playbackRate, l.currentTime = 0, l.pause(), this.waapi = l, this.waitingForStart = !0, this.startReady = !1, this.pendingFirstFrame = s, this.running = !0, l.onfinish = () => {
205
+ var c;
206
+ !this.running || this.waapi !== l || (this.running = !1, this.settled = !0, this.currentValue = n.position, this.currentVelocity = 0, (c = this.onComplete) == null || c.call(this));
207
+ }, this.startWhenReady(l, u);
208
+ }
209
+ clearWaapi() {
210
+ var t, e;
211
+ this.runId++, (t = this.waapi) == null || t.cancel(), this.waapi = null, this.waitingForStart = !1, this.startReady = !1, this.pendingFirstFrame = void 0, (e = this.stopStartupClock) == null || e.call(this), this.stopStartupClock = null, this.startupStableFrames = 0;
212
+ }
213
+ captureLiveState() {
214
+ if (this.frames.length === 0) return;
215
+ const t = m(this.waapi);
216
+ if (t === null) return;
217
+ const { position: e, velocity: s } = P(this.frames, t);
218
+ this.currentValue = e, this.currentVelocity = s;
219
+ }
220
+ async startWhenReady(t, e) {
221
+ try {
222
+ await t.ready, typeof requestAnimationFrame < "u" && await R(this.element);
223
+ } catch {
224
+ return;
225
+ }
226
+ this.runId !== e || this.waapi !== t || (this.startReady = !0, !(!this.running || this.paused) && this.startFramePacedPlayback(t));
227
+ }
228
+ startFramePacedPlayback(t) {
229
+ if (!(this.waapi !== t || !this.waitingForStart || !this.startReady || this.stopStartupClock)) {
230
+ if (this.pendingFirstFrame)
231
+ for (const e of Object.keys(this.pendingFirstFrame))
232
+ this.element.style[e] = "";
233
+ if (this.pendingFirstFrame = void 0, typeof requestAnimationFrame > "u" || this.playbackRate < 0) {
234
+ this.handOffToWaapi(t);
235
+ return;
236
+ }
237
+ this.startupStableFrames = 0, this.stopStartupClock = y.subscribe((e) => {
238
+ this.advanceFramePacedStartup(t, e);
239
+ });
240
+ }
241
+ }
242
+ advanceFramePacedStartup(t, e) {
243
+ if (this.waapi !== t || !this.running || this.paused || !this.waitingForStart)
244
+ return;
245
+ const s = this.frames[this.frames.length - 1];
246
+ if (!s) return;
247
+ const n = m(t) ?? 0, h = Math.min(
248
+ s.time,
249
+ n + e.delta * Math.max(0, this.playbackRate)
250
+ );
251
+ if (t.currentTime = h, this.captureLiveState(), h >= s.time) {
252
+ this.finishFramePacedRun(t, s);
253
+ return;
254
+ }
255
+ e.rawDelta <= k ? this.startupStableFrames++ : this.startupStableFrames = 0, !(this.startupStableFrames < C) && this.handOffToWaapi(t);
256
+ }
257
+ handOffToWaapi(t) {
258
+ var e;
259
+ this.waapi !== t || !this.running || this.paused || ((e = this.stopStartupClock) == null || e.call(this), this.stopStartupClock = null, this.waitingForStart = !1, this.startReady = !1, this.startupStableFrames = 0, t.play());
260
+ }
261
+ finishFramePacedRun(t, e) {
262
+ var s, n;
263
+ this.waapi !== t || !this.running || ((s = this.stopStartupClock) == null || s.call(this), this.stopStartupClock = null, this.waitingForStart = !1, this.startReady = !1, this.startupStableFrames = 0, this.running = !1, this.settled = !0, this.currentValue = e.position, this.currentVelocity = 0, (n = this.onComplete) == null || n.call(this));
264
+ }
265
+ applyStyleAt(t) {
266
+ const e = this.lowerBound + this.upperBound - t, s = this.styleFn(t, e);
267
+ for (const [n, h] of Object.entries(s))
268
+ this.element.style[n] = typeof h == "number" ? String(h) : h;
269
+ }
270
+ }
271
+ function A(a, i, t, e) {
272
+ if (i === t && e === 0) return [];
273
+ const s = 600;
274
+ let n = { position: i, velocity: e }, h = 0;
275
+ const u = [];
276
+ for (let l = 0; l < s; l++) {
277
+ const o = l * p;
278
+ if (u.push({ time: o, position: n.position, velocity: n.velocity }), n = a.step(n, t, p / 1e3), a.isSettled(n, t)) {
279
+ if (h += p / 1e3, h >= b) {
280
+ u.push({
281
+ time: (l + 1) * p,
282
+ position: t,
283
+ velocity: 0
284
+ });
285
+ break;
286
+ }
287
+ } else
288
+ h = 0;
289
+ }
290
+ return u;
291
+ }
292
+ function P(a, i) {
293
+ if (a.length === 0) return { position: 0, velocity: 0 };
294
+ const t = a[0], e = a[a.length - 1];
295
+ if (i <= 0)
296
+ return { position: t.position, velocity: t.velocity };
297
+ if (i >= e.time)
298
+ return { position: e.position, velocity: e.velocity };
299
+ let s = 0, n = a.length - 1;
300
+ for (; s < n - 1; ) {
301
+ const o = s + n >> 1;
302
+ a[o].time <= i ? s = o : n = o;
303
+ }
304
+ const h = a[s], u = a[n], l = (i - h.time) / (u.time - h.time);
305
+ return {
306
+ position: h.position + (u.position - h.position) * l,
307
+ velocity: h.velocity + (u.velocity - h.velocity) * l
308
+ };
309
+ }
310
+ function m(a) {
311
+ const i = a == null ? void 0 : a.currentTime;
312
+ return typeof i == "number" ? i : null;
313
+ }
314
+ class M extends f {
315
+ constructor(t, e = {}) {
316
+ super();
317
+ r(this, "children");
318
+ r(this, "startAt");
319
+ r(this, "pendingComplete", 0);
320
+ r(this, "running", !1);
321
+ r(this, "pendingStartObservers", []);
322
+ this.children = t, (e.mode ?? "parallel") === "sequence" ? this.startAt = t.map((s, n) => n === 0 ? 0 : 1) : this.startAt = e.startAt ?? [];
323
+ }
324
+ play() {
325
+ this.startRun("play");
326
+ }
327
+ reverse() {
328
+ this.startRun("reverse");
329
+ }
330
+ pause() {
331
+ this.running = !1, this.clearPendingStartObservers();
332
+ for (const t of this.children) t.pause();
333
+ }
334
+ complete() {
335
+ var t;
336
+ this.running = !1, this.clearPendingStartObservers();
337
+ for (const e of this.children) e.complete();
338
+ (t = this.onComplete) == null || t.call(this);
339
+ }
340
+ get progress() {
341
+ if (this.children.length === 0) return 0;
342
+ let t = 0;
343
+ for (const e of this.children) t += e.progress;
344
+ return t / this.children.length;
345
+ }
346
+ getPose() {
347
+ return this.children.flatMap((t) => t.getPose());
348
+ }
349
+ getTimeline() {
350
+ return this.children.flatMap((t) => t.getTimeline());
351
+ }
352
+ matchInto(t) {
353
+ }
354
+ get isAnimating() {
355
+ return this.children.some((t) => t.isAnimating);
356
+ }
357
+ get isPaused() {
358
+ return this.children.some((t) => t.isPaused) && this.children.every((t) => t.isPaused || t.isComplete);
359
+ }
360
+ get isComplete() {
361
+ return this.children.every((t) => t.isComplete);
362
+ }
363
+ get isReversing() {
364
+ return this.children.some((t) => t.isReversing);
365
+ }
366
+ get playbackRate() {
367
+ return super.playbackRate;
368
+ }
369
+ set playbackRate(t) {
370
+ super.playbackRate = t;
371
+ for (const e of this.children) e.playbackRate = t;
372
+ }
373
+ /* ───────────────────────────────────────────────────────── private */
374
+ startRun(t) {
375
+ if (this.running && this.pause(), this.running = !0, this.pendingComplete = this.children.length, this.pendingComplete === 0) {
376
+ this.handleFinished();
377
+ return;
378
+ }
379
+ for (const e of this.children) {
380
+ const s = e.onComplete;
381
+ e.onComplete = () => {
382
+ s == null || s(), this.handleChildComplete();
383
+ };
384
+ }
385
+ this.scheduleStart(0, t);
386
+ }
387
+ // Chained start: play child `index`, then observe its actual progress before
388
+ // starting the next one. A wall-clock timeout starts counting before WAAPI's
389
+ // asynchronous startup has completed, so mount/layout delays can otherwise
390
+ // make a sequence or stagger run early. The shared frame scheduler evaluates
391
+ // observers after frame-paced drivers, matching the pose painted this frame.
392
+ scheduleStart(t, e) {
393
+ if (!this.running || t >= this.children.length) return;
394
+ this.children[t][e]();
395
+ const s = t + 1;
396
+ if (s >= this.children.length) return;
397
+ const n = this.startAt[s];
398
+ if (n === void 0 || n <= 0) {
399
+ this.scheduleStart(s, e);
400
+ return;
401
+ }
402
+ const h = this.children[t];
403
+ if (this.hasReachedThreshold(h, n, e)) {
404
+ this.scheduleStart(s, e);
405
+ return;
406
+ }
407
+ const u = y.subscribe(() => {
408
+ this.running && this.hasReachedThreshold(h, n, e) && (u(), this.pendingStartObservers = this.pendingStartObservers.filter(
409
+ (l) => l !== u
410
+ ), this.scheduleStart(s, e));
411
+ }, "observe");
412
+ this.pendingStartObservers.push(u);
413
+ }
414
+ hasReachedThreshold(t, e, s) {
415
+ return t.isComplete ? !0 : (s === "play" ? t.progress : 1 - t.progress) >= e;
416
+ }
417
+ clearPendingStartObservers() {
418
+ for (const t of this.pendingStartObservers) t();
419
+ this.pendingStartObservers = [];
420
+ }
421
+ handleChildComplete() {
422
+ this.pendingComplete--, this.pendingComplete <= 0 && this.handleFinished();
423
+ }
424
+ handleFinished() {
425
+ var t;
426
+ this.running = !1, this.clearPendingStartObservers(), (t = this.onComplete) == null || t.call(this);
427
+ }
428
+ findTimeForProgress(t) {
429
+ return null;
430
+ }
431
+ }
432
+ export {
433
+ f as A,
434
+ M,
435
+ O as P,
436
+ b as S,
437
+ V,
438
+ _ as W
439
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"crossfade.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/drill/provider/crossfade.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,aAAa,EACd,MAAM,UAAU,CAAC;AAsClB,wBAAgB,uBAAuB,IAAI,aAAa,CAKvD"}
1
+ {"version":3,"file":"crossfade.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/drill/provider/crossfade.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,aAAa,EACd,MAAM,UAAU,CAAC;AA0ClB,wBAAgB,uBAAuB,IAAI,aAAa,CAKvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"parallax.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/drill/provider/parallax.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,aAAa,EACd,MAAM,UAAU,CAAC;AAyClB,wBAAgB,sBAAsB,IAAI,aAAa,CAKtD"}
1
+ {"version":3,"file":"parallax.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/drill/provider/parallax.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,aAAa,EACd,MAAM,UAAU,CAAC;AAqClB,wBAAgB,sBAAsB,IAAI,aAAa,CAKtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/sheet/provider/static.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAY9C,wBAAgB,oBAAoB,IAAI,aAAa,CAUpD"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/lib/transitions/sheet/provider/static.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAkB9C,wBAAgB,oBAAoB,IAAI,aAAa,CAUpD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssgoi/core",
3
- "version": "6.6.9",
3
+ "version": "6.6.11",
4
4
  "description": "Core animation engine for SSGOI - Native app-like page transitions with spring physics",
5
5
  "private": false,
6
6
  "type": "module",