motion-dom 12.5.0 → 12.6.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.
- package/dist/cjs/index.js +72 -65
- package/dist/es/gestures/press/index.mjs +13 -40
- package/dist/es/index.mjs +1 -2
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/view/index.mjs +9 -12
- package/dist/es/view/queue.mjs +53 -0
- package/dist/es/view/start.mjs +2 -1
- package/dist/index.d.ts +7 -12
- package/dist/motion-dom.dev.js +72 -65
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
- package/dist/es/gestures/utils/capture-pointer.mjs +0 -13
package/dist/cjs/index.js
CHANGED
|
@@ -597,18 +597,6 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
|
597
597
|
return cancel;
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
-
function capturePointer(event, action) {
|
|
601
|
-
const actionName = `${action}PointerCapture`;
|
|
602
|
-
if (event.target instanceof Element &&
|
|
603
|
-
actionName in event.target &&
|
|
604
|
-
event.pointerId !== undefined) {
|
|
605
|
-
try {
|
|
606
|
-
event.target[actionName](event.pointerId);
|
|
607
|
-
}
|
|
608
|
-
catch (e) { }
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
600
|
/**
|
|
613
601
|
* Recursively traverse up the tree to check whether the provided child node
|
|
614
602
|
* is the parent or a descendant of it.
|
|
@@ -724,15 +712,13 @@ function press(targetOrSelector, onPressStart, options = {}) {
|
|
|
724
712
|
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
725
713
|
const startPress = (startEvent) => {
|
|
726
714
|
const target = startEvent.currentTarget;
|
|
727
|
-
if (!
|
|
715
|
+
if (!isValidPressEvent(startEvent) || isPressing.has(target))
|
|
728
716
|
return;
|
|
729
717
|
isPressing.add(target);
|
|
730
|
-
capturePointer(startEvent, "set");
|
|
731
718
|
const onPressEnd = onPressStart(target, startEvent);
|
|
732
719
|
const onPointerEnd = (endEvent, success) => {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
capturePointer(endEvent, "release");
|
|
720
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
721
|
+
window.removeEventListener("pointercancel", onPointerCancel);
|
|
736
722
|
if (!isValidPressEvent(endEvent) || !isPressing.has(target)) {
|
|
737
723
|
return;
|
|
738
724
|
}
|
|
@@ -742,54 +728,30 @@ function press(targetOrSelector, onPressStart, options = {}) {
|
|
|
742
728
|
}
|
|
743
729
|
};
|
|
744
730
|
const onPointerUp = (upEvent) => {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
: {
|
|
750
|
-
left: 0,
|
|
751
|
-
top: 0,
|
|
752
|
-
right: window.innerWidth,
|
|
753
|
-
bottom: window.innerHeight,
|
|
754
|
-
});
|
|
755
|
-
if (isOutside) {
|
|
756
|
-
onPointerEnd(upEvent, false);
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
onPointerEnd(upEvent, !(target instanceof Element) ||
|
|
760
|
-
isNodeOrChild(target, upEvent.target));
|
|
761
|
-
}
|
|
731
|
+
onPointerEnd(upEvent, target === window ||
|
|
732
|
+
target === document ||
|
|
733
|
+
options.useGlobalTarget ||
|
|
734
|
+
isNodeOrChild(target, upEvent.target));
|
|
762
735
|
};
|
|
763
736
|
const onPointerCancel = (cancelEvent) => {
|
|
764
737
|
onPointerEnd(cancelEvent, false);
|
|
765
738
|
};
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
739
|
+
window.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
740
|
+
window.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
769
741
|
};
|
|
770
742
|
targets.forEach((target) => {
|
|
771
|
-
|
|
772
|
-
|
|
743
|
+
const pointerDownTarget = options.useGlobalTarget ? window : target;
|
|
744
|
+
pointerDownTarget.addEventListener("pointerdown", startPress, eventOptions);
|
|
773
745
|
if (target instanceof HTMLElement) {
|
|
774
|
-
|
|
746
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
|
|
775
747
|
if (!isElementKeyboardAccessible(target) &&
|
|
776
|
-
target.
|
|
748
|
+
target.tabIndex === null) {
|
|
777
749
|
target.tabIndex = 0;
|
|
778
750
|
}
|
|
779
751
|
}
|
|
780
|
-
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
781
|
-
if (canAddKeyboardAccessibility) {
|
|
782
|
-
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
783
|
-
}
|
|
784
752
|
});
|
|
785
753
|
return cancelEvents;
|
|
786
754
|
}
|
|
787
|
-
function checkOutside(event, rect) {
|
|
788
|
-
return (event.clientX < rect.left ||
|
|
789
|
-
event.clientX > rect.right ||
|
|
790
|
-
event.clientY < rect.top ||
|
|
791
|
-
event.clientY > rect.bottom);
|
|
792
|
-
}
|
|
793
755
|
|
|
794
756
|
const activeAnimations = {
|
|
795
757
|
layout: 0,
|
|
@@ -933,7 +895,7 @@ class MotionValue {
|
|
|
933
895
|
* This will be replaced by the build step with the latest version number.
|
|
934
896
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
935
897
|
*/
|
|
936
|
-
this.version = "12.
|
|
898
|
+
this.version = "12.6.1";
|
|
937
899
|
/**
|
|
938
900
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
939
901
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1335,7 +1297,8 @@ function hasTarget(target, targets) {
|
|
|
1335
1297
|
}
|
|
1336
1298
|
|
|
1337
1299
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
1338
|
-
function startViewAnimation(
|
|
1300
|
+
function startViewAnimation(builder) {
|
|
1301
|
+
const { update, targets, options: defaultOptions } = builder;
|
|
1339
1302
|
if (!document.startViewTransition) {
|
|
1340
1303
|
return new Promise(async (resolve) => {
|
|
1341
1304
|
await update();
|
|
@@ -1466,12 +1429,54 @@ function hasOpacity(target, key) {
|
|
|
1466
1429
|
return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
|
|
1467
1430
|
}
|
|
1468
1431
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1432
|
+
let builders = [];
|
|
1433
|
+
let current = null;
|
|
1434
|
+
function next() {
|
|
1435
|
+
current = null;
|
|
1436
|
+
const [nextBuilder] = builders;
|
|
1437
|
+
if (nextBuilder)
|
|
1438
|
+
start(nextBuilder);
|
|
1439
|
+
}
|
|
1440
|
+
function start(builder) {
|
|
1441
|
+
motionUtils.removeItem(builders, builder);
|
|
1442
|
+
current = builder;
|
|
1443
|
+
startViewAnimation(builder).then((animation) => {
|
|
1444
|
+
builder.notifyReady(animation);
|
|
1445
|
+
animation.finished.finally(next);
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function processQueue() {
|
|
1449
|
+
var _a;
|
|
1450
|
+
/**
|
|
1451
|
+
* Iterate backwards over the builders array. We can ignore the
|
|
1452
|
+
* "wait" animations. If we have an interrupting animation in the
|
|
1453
|
+
* queue then we need to batch all preceeding animations into it.
|
|
1454
|
+
* Currently this only batches the update functions but will also
|
|
1455
|
+
* need to batch the targets.
|
|
1456
|
+
*/
|
|
1457
|
+
for (let i = builders.length - 1; i >= 0; i--) {
|
|
1458
|
+
const builder = builders[i];
|
|
1459
|
+
const { interrupt } = builder.options;
|
|
1460
|
+
if (interrupt === "immediate") {
|
|
1461
|
+
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
|
|
1462
|
+
const remaining = builders.slice(i + 1);
|
|
1463
|
+
builder.update = () => {
|
|
1464
|
+
batchedUpdates.forEach((update) => update());
|
|
1465
|
+
};
|
|
1466
|
+
// Put the current builder at the front, followed by any "wait" builders
|
|
1467
|
+
builders = [builder, ...remaining];
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
|
|
1472
|
+
next();
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
function addToQueue(builder) {
|
|
1476
|
+
builders.push(builder);
|
|
1477
|
+
microtask.render(processQueue);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1475
1480
|
class ViewTransitionBuilder {
|
|
1476
1481
|
constructor(update, options = {}) {
|
|
1477
1482
|
this.currentTarget = "root";
|
|
@@ -1480,9 +1485,12 @@ class ViewTransitionBuilder {
|
|
|
1480
1485
|
this.readyPromise = new Promise((resolve) => {
|
|
1481
1486
|
this.notifyReady = resolve;
|
|
1482
1487
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1488
|
+
this.update = update;
|
|
1489
|
+
this.options = {
|
|
1490
|
+
interrupt: "wait",
|
|
1491
|
+
...options,
|
|
1492
|
+
};
|
|
1493
|
+
addToQueue(this);
|
|
1486
1494
|
}
|
|
1487
1495
|
get(selector) {
|
|
1488
1496
|
this.currentTarget = selector;
|
|
@@ -1525,7 +1533,7 @@ class ViewTransitionBuilder {
|
|
|
1525
1533
|
return this.readyPromise.then(resolve, reject);
|
|
1526
1534
|
}
|
|
1527
1535
|
}
|
|
1528
|
-
function
|
|
1536
|
+
function animateView(update, defaultOptions = {}) {
|
|
1529
1537
|
return new ViewTransitionBuilder(update, defaultOptions);
|
|
1530
1538
|
}
|
|
1531
1539
|
|
|
@@ -1534,11 +1542,11 @@ exports.MotionValue = MotionValue;
|
|
|
1534
1542
|
exports.NativeAnimationControls = NativeAnimationControls;
|
|
1535
1543
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
1536
1544
|
exports.activeAnimations = activeAnimations;
|
|
1545
|
+
exports.animateView = animateView;
|
|
1537
1546
|
exports.attachTimeline = attachTimeline;
|
|
1538
1547
|
exports.calcGeneratorDuration = calcGeneratorDuration;
|
|
1539
1548
|
exports.cancelFrame = cancelFrame;
|
|
1540
1549
|
exports.cancelMicrotask = cancelMicrotask;
|
|
1541
|
-
exports.capturePointer = capturePointer;
|
|
1542
1550
|
exports.collectMotionValues = collectMotionValues;
|
|
1543
1551
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
1544
1552
|
exports.createRenderBatcher = createRenderBatcher;
|
|
@@ -1570,4 +1578,3 @@ exports.supportsFlags = supportsFlags;
|
|
|
1570
1578
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
1571
1579
|
exports.supportsScrollTimeline = supportsScrollTimeline;
|
|
1572
1580
|
exports.time = time;
|
|
1573
|
-
exports.view = view;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isDragActive } from '../drag/state/is-active.mjs';
|
|
2
|
-
import { capturePointer } from '../utils/capture-pointer.mjs';
|
|
3
2
|
import { isNodeOrChild } from '../utils/is-node-or-child.mjs';
|
|
4
3
|
import { isPrimaryPointer } from '../utils/is-primary-pointer.mjs';
|
|
5
4
|
import { setupGesture } from '../utils/setup.mjs';
|
|
@@ -37,15 +36,13 @@ function press(targetOrSelector, onPressStart, options = {}) {
|
|
|
37
36
|
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
38
37
|
const startPress = (startEvent) => {
|
|
39
38
|
const target = startEvent.currentTarget;
|
|
40
|
-
if (!
|
|
39
|
+
if (!isValidPressEvent(startEvent) || isPressing.has(target))
|
|
41
40
|
return;
|
|
42
41
|
isPressing.add(target);
|
|
43
|
-
capturePointer(startEvent, "set");
|
|
44
42
|
const onPressEnd = onPressStart(target, startEvent);
|
|
45
43
|
const onPointerEnd = (endEvent, success) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
capturePointer(endEvent, "release");
|
|
44
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
45
|
+
window.removeEventListener("pointercancel", onPointerCancel);
|
|
49
46
|
if (!isValidPressEvent(endEvent) || !isPressing.has(target)) {
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
@@ -55,53 +52,29 @@ function press(targetOrSelector, onPressStart, options = {}) {
|
|
|
55
52
|
}
|
|
56
53
|
};
|
|
57
54
|
const onPointerUp = (upEvent) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
: {
|
|
63
|
-
left: 0,
|
|
64
|
-
top: 0,
|
|
65
|
-
right: window.innerWidth,
|
|
66
|
-
bottom: window.innerHeight,
|
|
67
|
-
});
|
|
68
|
-
if (isOutside) {
|
|
69
|
-
onPointerEnd(upEvent, false);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
onPointerEnd(upEvent, !(target instanceof Element) ||
|
|
73
|
-
isNodeOrChild(target, upEvent.target));
|
|
74
|
-
}
|
|
55
|
+
onPointerEnd(upEvent, target === window ||
|
|
56
|
+
target === document ||
|
|
57
|
+
options.useGlobalTarget ||
|
|
58
|
+
isNodeOrChild(target, upEvent.target));
|
|
75
59
|
};
|
|
76
60
|
const onPointerCancel = (cancelEvent) => {
|
|
77
61
|
onPointerEnd(cancelEvent, false);
|
|
78
62
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
63
|
+
window.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
64
|
+
window.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
82
65
|
};
|
|
83
66
|
targets.forEach((target) => {
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
const pointerDownTarget = options.useGlobalTarget ? window : target;
|
|
68
|
+
pointerDownTarget.addEventListener("pointerdown", startPress, eventOptions);
|
|
86
69
|
if (target instanceof HTMLElement) {
|
|
87
|
-
|
|
70
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
|
|
88
71
|
if (!isElementKeyboardAccessible(target) &&
|
|
89
|
-
target.
|
|
72
|
+
target.tabIndex === null) {
|
|
90
73
|
target.tabIndex = 0;
|
|
91
74
|
}
|
|
92
75
|
}
|
|
93
|
-
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
94
|
-
if (canAddKeyboardAccessibility) {
|
|
95
|
-
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
96
|
-
}
|
|
97
76
|
});
|
|
98
77
|
return cancelEvents;
|
|
99
78
|
}
|
|
100
|
-
function checkOutside(event, rect) {
|
|
101
|
-
return (event.clientX < rect.left ||
|
|
102
|
-
event.clientX > rect.right ||
|
|
103
|
-
event.clientY < rect.top ||
|
|
104
|
-
event.clientY > rect.bottom);
|
|
105
|
-
}
|
|
106
79
|
|
|
107
80
|
export { press };
|
package/dist/es/index.mjs
CHANGED
|
@@ -15,7 +15,6 @@ export { isDragActive, isDragging } from './gestures/drag/state/is-active.mjs';
|
|
|
15
15
|
export { setDragLock } from './gestures/drag/state/set-active.mjs';
|
|
16
16
|
export { hover } from './gestures/hover.mjs';
|
|
17
17
|
export { press } from './gestures/press/index.mjs';
|
|
18
|
-
export { capturePointer } from './gestures/utils/capture-pointer.mjs';
|
|
19
18
|
export { isNodeOrChild } from './gestures/utils/is-node-or-child.mjs';
|
|
20
19
|
export { isPrimaryPointer } from './gestures/utils/is-primary-pointer.mjs';
|
|
21
20
|
export { recordStats } from './stats/index.mjs';
|
|
@@ -27,4 +26,4 @@ export { supportsFlags } from './utils/supports/flags.mjs';
|
|
|
27
26
|
export { supportsLinearEasing } from './utils/supports/linear-easing.mjs';
|
|
28
27
|
export { supportsScrollTimeline } from './utils/supports/scroll-timeline.mjs';
|
|
29
28
|
export { MotionValue, collectMotionValues, motionValue } from './value/index.mjs';
|
|
30
|
-
export { ViewTransitionBuilder,
|
|
29
|
+
export { ViewTransitionBuilder, animateView } from './view/index.mjs';
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ class MotionValue {
|
|
|
30
30
|
* This will be replaced by the build step with the latest version number.
|
|
31
31
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
32
32
|
*/
|
|
33
|
-
this.version = "12.
|
|
33
|
+
this.version = "12.6.1";
|
|
34
34
|
/**
|
|
35
35
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
36
36
|
* if the value is numerical, but we might be able to widen the scope here and support
|
package/dist/es/view/index.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { noop } from 'motion-utils';
|
|
2
|
-
import {
|
|
2
|
+
import { addToQueue } from './queue.mjs';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* TODO:
|
|
6
|
-
* - Create view transition on next tick
|
|
7
|
-
* - Replace animations with Motion animations
|
|
8
|
-
* - Return GroupAnimation on next tick
|
|
9
|
-
*/
|
|
10
4
|
class ViewTransitionBuilder {
|
|
11
5
|
constructor(update, options = {}) {
|
|
12
6
|
this.currentTarget = "root";
|
|
@@ -15,9 +9,12 @@ class ViewTransitionBuilder {
|
|
|
15
9
|
this.readyPromise = new Promise((resolve) => {
|
|
16
10
|
this.notifyReady = resolve;
|
|
17
11
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
this.update = update;
|
|
13
|
+
this.options = {
|
|
14
|
+
interrupt: "wait",
|
|
15
|
+
...options,
|
|
16
|
+
};
|
|
17
|
+
addToQueue(this);
|
|
21
18
|
}
|
|
22
19
|
get(selector) {
|
|
23
20
|
this.currentTarget = selector;
|
|
@@ -60,8 +57,8 @@ class ViewTransitionBuilder {
|
|
|
60
57
|
return this.readyPromise.then(resolve, reject);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
function
|
|
60
|
+
function animateView(update, defaultOptions = {}) {
|
|
64
61
|
return new ViewTransitionBuilder(update, defaultOptions);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
export { ViewTransitionBuilder,
|
|
64
|
+
export { ViewTransitionBuilder, animateView };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { removeItem } from 'motion-utils';
|
|
2
|
+
import { microtask } from '../frameloop/microtask.mjs';
|
|
3
|
+
import { startViewAnimation } from './start.mjs';
|
|
4
|
+
|
|
5
|
+
let builders = [];
|
|
6
|
+
let current = null;
|
|
7
|
+
function next() {
|
|
8
|
+
current = null;
|
|
9
|
+
const [nextBuilder] = builders;
|
|
10
|
+
if (nextBuilder)
|
|
11
|
+
start(nextBuilder);
|
|
12
|
+
}
|
|
13
|
+
function start(builder) {
|
|
14
|
+
removeItem(builders, builder);
|
|
15
|
+
current = builder;
|
|
16
|
+
startViewAnimation(builder).then((animation) => {
|
|
17
|
+
builder.notifyReady(animation);
|
|
18
|
+
animation.finished.finally(next);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function processQueue() {
|
|
22
|
+
var _a;
|
|
23
|
+
/**
|
|
24
|
+
* Iterate backwards over the builders array. We can ignore the
|
|
25
|
+
* "wait" animations. If we have an interrupting animation in the
|
|
26
|
+
* queue then we need to batch all preceeding animations into it.
|
|
27
|
+
* Currently this only batches the update functions but will also
|
|
28
|
+
* need to batch the targets.
|
|
29
|
+
*/
|
|
30
|
+
for (let i = builders.length - 1; i >= 0; i--) {
|
|
31
|
+
const builder = builders[i];
|
|
32
|
+
const { interrupt } = builder.options;
|
|
33
|
+
if (interrupt === "immediate") {
|
|
34
|
+
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
|
|
35
|
+
const remaining = builders.slice(i + 1);
|
|
36
|
+
builder.update = () => {
|
|
37
|
+
batchedUpdates.forEach((update) => update());
|
|
38
|
+
};
|
|
39
|
+
// Put the current builder at the front, followed by any "wait" builders
|
|
40
|
+
builders = [builder, ...remaining];
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
|
|
45
|
+
next();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function addToQueue(builder) {
|
|
49
|
+
builders.push(builder);
|
|
50
|
+
microtask.render(processQueue);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { addToQueue };
|
package/dist/es/view/start.mjs
CHANGED
|
@@ -12,7 +12,8 @@ import { getViewAnimations } from './utils/get-view-animations.mjs';
|
|
|
12
12
|
import { hasTarget } from './utils/has-target.mjs';
|
|
13
13
|
|
|
14
14
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
15
|
-
function startViewAnimation(
|
|
15
|
+
function startViewAnimation(builder) {
|
|
16
|
+
const { update, targets, options: defaultOptions } = builder;
|
|
16
17
|
if (!document.startViewTransition) {
|
|
17
18
|
return new Promise(async (resolve) => {
|
|
18
19
|
await update();
|
package/dist/index.d.ts
CHANGED
|
@@ -726,8 +726,6 @@ interface PointerEventOptions extends EventOptions {
|
|
|
726
726
|
*/
|
|
727
727
|
declare function press(targetOrSelector: ElementOrSelector, onPressStart: OnPressStartEvent, options?: PointerEventOptions): VoidFunction;
|
|
728
728
|
|
|
729
|
-
declare function capturePointer(event: PointerEvent, action: "set" | "release"): void;
|
|
730
|
-
|
|
731
729
|
/**
|
|
732
730
|
* Recursively traverse up the tree to check whether the provided child node
|
|
733
731
|
* is the parent or a descendant of it.
|
|
@@ -1046,19 +1044,16 @@ type ViewTransitionTarget = {
|
|
|
1046
1044
|
old?: ViewTransitionAnimationDefinition;
|
|
1047
1045
|
};
|
|
1048
1046
|
interface ViewTransitionOptions extends AnimationOptions {
|
|
1047
|
+
interrupt?: "wait" | "immediate";
|
|
1049
1048
|
}
|
|
1050
1049
|
type Target = string | Element;
|
|
1051
1050
|
|
|
1052
|
-
/**
|
|
1053
|
-
* TODO:
|
|
1054
|
-
* - Create view transition on next tick
|
|
1055
|
-
* - Replace animations with Motion animations
|
|
1056
|
-
* - Return GroupAnimation on next tick
|
|
1057
|
-
*/
|
|
1058
1051
|
declare class ViewTransitionBuilder {
|
|
1059
1052
|
private currentTarget;
|
|
1060
|
-
|
|
1061
|
-
|
|
1053
|
+
targets: Map<Target, ViewTransitionTarget>;
|
|
1054
|
+
update: () => void | Promise<void>;
|
|
1055
|
+
options: ViewTransitionOptions;
|
|
1056
|
+
notifyReady: (value: BaseGroupPlaybackControls) => void;
|
|
1062
1057
|
private readyPromise;
|
|
1063
1058
|
constructor(update: () => void | Promise<void>, options?: ViewTransitionOptions);
|
|
1064
1059
|
get(selector: Target): this;
|
|
@@ -1071,6 +1066,6 @@ declare class ViewTransitionBuilder {
|
|
|
1071
1066
|
updateTarget(target: "enter" | "exit" | "layout" | "new" | "old", keyframes: DOMKeyframesDefinition, options?: AnimationOptions): void;
|
|
1072
1067
|
then(resolve: () => void, reject?: () => void): Promise<void>;
|
|
1073
1068
|
}
|
|
1074
|
-
declare function
|
|
1069
|
+
declare function animateView(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
|
|
1075
1070
|
|
|
1076
|
-
export { type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, GroupPlaybackControls, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask,
|
|
1071
|
+
export { type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, GroupPlaybackControls, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, animateView, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask, collectMotionValues, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, frame, frameData, frameSteps, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, microtask, motionValue, press, recordStats, resolveElements, setDragLock, statsBuffer, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, time };
|
package/dist/motion-dom.dev.js
CHANGED
|
@@ -597,18 +597,6 @@
|
|
|
597
597
|
return cancel;
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
-
function capturePointer(event, action) {
|
|
601
|
-
const actionName = `${action}PointerCapture`;
|
|
602
|
-
if (event.target instanceof Element &&
|
|
603
|
-
actionName in event.target &&
|
|
604
|
-
event.pointerId !== undefined) {
|
|
605
|
-
try {
|
|
606
|
-
event.target[actionName](event.pointerId);
|
|
607
|
-
}
|
|
608
|
-
catch (e) { }
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
600
|
/**
|
|
613
601
|
* Recursively traverse up the tree to check whether the provided child node
|
|
614
602
|
* is the parent or a descendant of it.
|
|
@@ -724,15 +712,13 @@
|
|
|
724
712
|
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
725
713
|
const startPress = (startEvent) => {
|
|
726
714
|
const target = startEvent.currentTarget;
|
|
727
|
-
if (!
|
|
715
|
+
if (!isValidPressEvent(startEvent) || isPressing.has(target))
|
|
728
716
|
return;
|
|
729
717
|
isPressing.add(target);
|
|
730
|
-
capturePointer(startEvent, "set");
|
|
731
718
|
const onPressEnd = onPressStart(target, startEvent);
|
|
732
719
|
const onPointerEnd = (endEvent, success) => {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
capturePointer(endEvent, "release");
|
|
720
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
721
|
+
window.removeEventListener("pointercancel", onPointerCancel);
|
|
736
722
|
if (!isValidPressEvent(endEvent) || !isPressing.has(target)) {
|
|
737
723
|
return;
|
|
738
724
|
}
|
|
@@ -742,54 +728,30 @@
|
|
|
742
728
|
}
|
|
743
729
|
};
|
|
744
730
|
const onPointerUp = (upEvent) => {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
: {
|
|
750
|
-
left: 0,
|
|
751
|
-
top: 0,
|
|
752
|
-
right: window.innerWidth,
|
|
753
|
-
bottom: window.innerHeight,
|
|
754
|
-
});
|
|
755
|
-
if (isOutside) {
|
|
756
|
-
onPointerEnd(upEvent, false);
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
onPointerEnd(upEvent, !(target instanceof Element) ||
|
|
760
|
-
isNodeOrChild(target, upEvent.target));
|
|
761
|
-
}
|
|
731
|
+
onPointerEnd(upEvent, target === window ||
|
|
732
|
+
target === document ||
|
|
733
|
+
options.useGlobalTarget ||
|
|
734
|
+
isNodeOrChild(target, upEvent.target));
|
|
762
735
|
};
|
|
763
736
|
const onPointerCancel = (cancelEvent) => {
|
|
764
737
|
onPointerEnd(cancelEvent, false);
|
|
765
738
|
};
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
739
|
+
window.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
740
|
+
window.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
769
741
|
};
|
|
770
742
|
targets.forEach((target) => {
|
|
771
|
-
|
|
772
|
-
|
|
743
|
+
const pointerDownTarget = options.useGlobalTarget ? window : target;
|
|
744
|
+
pointerDownTarget.addEventListener("pointerdown", startPress, eventOptions);
|
|
773
745
|
if (target instanceof HTMLElement) {
|
|
774
|
-
|
|
746
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
|
|
775
747
|
if (!isElementKeyboardAccessible(target) &&
|
|
776
|
-
target.
|
|
748
|
+
target.tabIndex === null) {
|
|
777
749
|
target.tabIndex = 0;
|
|
778
750
|
}
|
|
779
751
|
}
|
|
780
|
-
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
781
|
-
if (canAddKeyboardAccessibility) {
|
|
782
|
-
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
783
|
-
}
|
|
784
752
|
});
|
|
785
753
|
return cancelEvents;
|
|
786
754
|
}
|
|
787
|
-
function checkOutside(event, rect) {
|
|
788
|
-
return (event.clientX < rect.left ||
|
|
789
|
-
event.clientX > rect.right ||
|
|
790
|
-
event.clientY < rect.top ||
|
|
791
|
-
event.clientY > rect.bottom);
|
|
792
|
-
}
|
|
793
755
|
|
|
794
756
|
const activeAnimations = {
|
|
795
757
|
layout: 0,
|
|
@@ -933,7 +895,7 @@
|
|
|
933
895
|
* This will be replaced by the build step with the latest version number.
|
|
934
896
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
935
897
|
*/
|
|
936
|
-
this.version = "12.
|
|
898
|
+
this.version = "12.6.1";
|
|
937
899
|
/**
|
|
938
900
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
939
901
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1335,7 +1297,8 @@
|
|
|
1335
1297
|
}
|
|
1336
1298
|
|
|
1337
1299
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
1338
|
-
function startViewAnimation(
|
|
1300
|
+
function startViewAnimation(builder) {
|
|
1301
|
+
const { update, targets, options: defaultOptions } = builder;
|
|
1339
1302
|
if (!document.startViewTransition) {
|
|
1340
1303
|
return new Promise(async (resolve) => {
|
|
1341
1304
|
await update();
|
|
@@ -1466,12 +1429,54 @@
|
|
|
1466
1429
|
return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
|
|
1467
1430
|
}
|
|
1468
1431
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1432
|
+
let builders = [];
|
|
1433
|
+
let current = null;
|
|
1434
|
+
function next() {
|
|
1435
|
+
current = null;
|
|
1436
|
+
const [nextBuilder] = builders;
|
|
1437
|
+
if (nextBuilder)
|
|
1438
|
+
start(nextBuilder);
|
|
1439
|
+
}
|
|
1440
|
+
function start(builder) {
|
|
1441
|
+
motionUtils.removeItem(builders, builder);
|
|
1442
|
+
current = builder;
|
|
1443
|
+
startViewAnimation(builder).then((animation) => {
|
|
1444
|
+
builder.notifyReady(animation);
|
|
1445
|
+
animation.finished.finally(next);
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function processQueue() {
|
|
1449
|
+
var _a;
|
|
1450
|
+
/**
|
|
1451
|
+
* Iterate backwards over the builders array. We can ignore the
|
|
1452
|
+
* "wait" animations. If we have an interrupting animation in the
|
|
1453
|
+
* queue then we need to batch all preceeding animations into it.
|
|
1454
|
+
* Currently this only batches the update functions but will also
|
|
1455
|
+
* need to batch the targets.
|
|
1456
|
+
*/
|
|
1457
|
+
for (let i = builders.length - 1; i >= 0; i--) {
|
|
1458
|
+
const builder = builders[i];
|
|
1459
|
+
const { interrupt } = builder.options;
|
|
1460
|
+
if (interrupt === "immediate") {
|
|
1461
|
+
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
|
|
1462
|
+
const remaining = builders.slice(i + 1);
|
|
1463
|
+
builder.update = () => {
|
|
1464
|
+
batchedUpdates.forEach((update) => update());
|
|
1465
|
+
};
|
|
1466
|
+
// Put the current builder at the front, followed by any "wait" builders
|
|
1467
|
+
builders = [builder, ...remaining];
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
|
|
1472
|
+
next();
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
function addToQueue(builder) {
|
|
1476
|
+
builders.push(builder);
|
|
1477
|
+
microtask.render(processQueue);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1475
1480
|
class ViewTransitionBuilder {
|
|
1476
1481
|
constructor(update, options = {}) {
|
|
1477
1482
|
this.currentTarget = "root";
|
|
@@ -1480,9 +1485,12 @@
|
|
|
1480
1485
|
this.readyPromise = new Promise((resolve) => {
|
|
1481
1486
|
this.notifyReady = resolve;
|
|
1482
1487
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1488
|
+
this.update = update;
|
|
1489
|
+
this.options = {
|
|
1490
|
+
interrupt: "wait",
|
|
1491
|
+
...options,
|
|
1492
|
+
};
|
|
1493
|
+
addToQueue(this);
|
|
1486
1494
|
}
|
|
1487
1495
|
get(selector) {
|
|
1488
1496
|
this.currentTarget = selector;
|
|
@@ -1525,7 +1533,7 @@
|
|
|
1525
1533
|
return this.readyPromise.then(resolve, reject);
|
|
1526
1534
|
}
|
|
1527
1535
|
}
|
|
1528
|
-
function
|
|
1536
|
+
function animateView(update, defaultOptions = {}) {
|
|
1529
1537
|
return new ViewTransitionBuilder(update, defaultOptions);
|
|
1530
1538
|
}
|
|
1531
1539
|
|
|
@@ -1534,11 +1542,11 @@
|
|
|
1534
1542
|
exports.NativeAnimationControls = NativeAnimationControls;
|
|
1535
1543
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
1536
1544
|
exports.activeAnimations = activeAnimations;
|
|
1545
|
+
exports.animateView = animateView;
|
|
1537
1546
|
exports.attachTimeline = attachTimeline;
|
|
1538
1547
|
exports.calcGeneratorDuration = calcGeneratorDuration;
|
|
1539
1548
|
exports.cancelFrame = cancelFrame;
|
|
1540
1549
|
exports.cancelMicrotask = cancelMicrotask;
|
|
1541
|
-
exports.capturePointer = capturePointer;
|
|
1542
1550
|
exports.collectMotionValues = collectMotionValues;
|
|
1543
1551
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
1544
1552
|
exports.createRenderBatcher = createRenderBatcher;
|
|
@@ -1570,6 +1578,5 @@
|
|
|
1570
1578
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
1571
1579
|
exports.supportsScrollTimeline = supportsScrollTimeline;
|
|
1572
1580
|
exports.time = time;
|
|
1573
|
-
exports.view = view;
|
|
1574
1581
|
|
|
1575
1582
|
}));
|
package/dist/motion-dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("motion-utils")):"function"==typeof define&&define.amd?define(["exports","motion-utils"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MotionDom={},t.MotionUtils)}(this,(function(t,e){"use strict";const n=e.memo(()=>void 0!==window.ScrollTimeline);class i{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>"finished"in t?t.finished:t))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const i=this.animations.map(i=>n()&&i.attachTimeline?i.attachTimeline(t):"function"==typeof e?e(i):void 0);return()=>{i.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function a(t,e){return t?t[e]||t.default||t:void 0}function s(t){let e=0;let n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}function o(t,n=100,i){const a=i({...t,keyframes:[0,n]}),o=Math.min(s(a),2e4);return{type:"keyframes",ease:t=>a.next(o*t).value/n,duration:e.millisecondsToSeconds(o)}}function r(t){return"function"==typeof t}function c(t,e){t.timeline=e,t.onfinish=null}class u{constructor(t){this.animation=t}get duration(){var t,n,i;const a=(null===(n=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===n?void 0:n.getComputedTiming().duration)||(null===(i=this.options)||void 0===i?void 0:i.duration)||300;return e.millisecondsToSeconds(Number(a))}get time(){var t;return this.animation?e.millisecondsToSeconds((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=e.secondsToMilliseconds(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var t,e;this.animation&&(null===(t=this.options)||void 0===t?void 0:t.allowFlatten)&&(null===(e=this.animation.effect)||void 0===e||e.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&c(this.animation,t),e.noop}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}const l=t=>Array.isArray(t)&&"number"==typeof t[0],d={linearEasing:void 0};function h(t,n){const i=e.memo(t);return()=>{var t;return null!==(t=d[n])&&void 0!==t?t:i()}}const m=h(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),p=(t,n,i=10)=>{let a="";const s=Math.max(Math.round(n/i),2);for(let n=0;n<s;n++)a+=t(e.progress(0,s-1,n))+", ";return`linear(${a.substring(0,a.length-2)})`};const f=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,v={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:f([0,.65,.55,1]),circOut:f([.55,0,1,.45]),backIn:f([.31,.01,.66,-.59]),backOut:f([.33,1.53,.69,.99])};function y(t,e){return t?"function"==typeof t&&m()?p(t,e):l(t)?f(t):Array.isArray(t)?t.map(t=>y(t,e)||v.easeOut):v[t]:void 0}const g=["read","resolveKeyframes","update","preRender","render","postRender"],T={value:null,addProjectionMetrics:null};function w(t,n){let i=!1,a=!0;const s={delta:0,timestamp:0,isProcessing:!1},o=()=>i=!0,r=g.reduce((t,e)=>(t[e]=function(t,e){let n=new Set,i=new Set,a=!1,s=!1;const o=new WeakSet;let r={delta:0,timestamp:0,isProcessing:!1},c=0;function u(e){o.has(e)&&(l.schedule(e),t()),c++,e(r)}const l={schedule:(t,e=!1,s=!1)=>{const r=s&&a?n:i;return e&&o.add(t),r.has(t)||r.add(t),t},cancel:t=>{i.delete(t),o.delete(t)},process:t=>{r=t,a?s=!0:(a=!0,[n,i]=[i,n],n.forEach(u),e&&T.value&&T.value.frameloop[e].push(c),c=0,n.clear(),a=!1,s&&(s=!1,l.process(t)))}};return l}(o,n?e:void 0),t),{}),{read:c,resolveKeyframes:u,update:l,preRender:d,render:h,postRender:m}=r,p=()=>{const o=e.MotionGlobalConfig.useManualTiming?s.timestamp:performance.now();i=!1,e.MotionGlobalConfig.useManualTiming||(s.delta=a?1e3/60:Math.max(Math.min(o-s.timestamp,40),1)),s.timestamp=o,s.isProcessing=!0,c.process(s),u.process(s),l.process(s),d.process(s),h.process(s),m.process(s),s.isProcessing=!1,i&&n&&(a=!1,t(p))};return{schedule:g.reduce((e,n)=>{const o=r[n];return e[n]=(e,n=!1,r=!1)=>(i||(i=!0,a=!0,s.isProcessing||t(p)),o.schedule(e,n,r)),e},{}),cancel:t=>{for(let e=0;e<g.length;e++)r[g[e]].cancel(t)},state:s,steps:r}}const{schedule:E,cancel:A,state:P,steps:b}=w("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:e.noop,!0),{schedule:x,cancel:M}=w(queueMicrotask,!1);let k;function S(){k=void 0}const C={now:()=>(void 0===k&&C.set(P.isProcessing||e.MotionGlobalConfig.useManualTiming?P.timestamp:performance.now()),k),set:t=>{k=t,queueMicrotask(S)}},L={x:!1,y:!1};function R(){return L.x||L.y}function V(t,e,n){var i;if(t instanceof EventTarget)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const s=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function j(t,e){const n=V(t),i=new AbortController;return[n,{passive:!0,...e,signal:i.signal},()=>i.abort()]}function F(t){return!("touch"===t.pointerType||R())}function D(t,e){const n=e+"PointerCapture";if(t.target instanceof Element&&n in t.target&&void 0!==t.pointerId)try{t.target[n](t.pointerId)}catch(t){}}const N=(t,e)=>!!e&&(t===e||N(t,e.parentElement)),O=t=>"mouse"===t.pointerType?"number"!=typeof t.button||t.button<=0:!1!==t.isPrimary,B=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const q=new WeakSet;function G(t){return e=>{"Enter"===e.key&&t(e)}}function I(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}function $(t){return O(t)&&!R()}const K={layout:0,mainThread:0,waapi:0};function U(){const{value:t}=T;null!==t?(t.frameloop.rate.push(P.delta),t.animations.mainThread.push(K.mainThread),t.animations.waapi.push(K.waapi),t.animations.layout.push(K.layout)):A(U)}function W(t){return t.reduce((t,e)=>t+e,0)/t.length}function z(t,e=W){return 0===t.length?{min:0,max:0,avg:0}:{min:Math.min(...t),max:Math.max(...t),avg:e(t)}}const X=t=>Math.round(1e3/t);function H(){T.value=null,T.addProjectionMetrics=null}function Y(){const{value:t}=T;if(!t)throw new Error("Stats are not being measured");H(),A(U);const e={frameloop:{rate:z(t.frameloop.rate),read:z(t.frameloop.read),resolveKeyframes:z(t.frameloop.resolveKeyframes),update:z(t.frameloop.update),preRender:z(t.frameloop.preRender),render:z(t.frameloop.render),postRender:z(t.frameloop.postRender)},animations:{mainThread:z(t.animations.mainThread),waapi:z(t.animations.waapi),layout:z(t.animations.layout)},layoutProjection:{nodes:z(t.layoutProjection.nodes),calculatedTargetDeltas:z(t.layoutProjection.calculatedTargetDeltas),calculatedProjections:z(t.layoutProjection.calculatedProjections)}},{rate:n}=e.frameloop;return n.min=X(n.min),n.max=X(n.max),n.avg=X(n.avg),[n.min,n.max]=[n.max,n.min],e}const J={current:void 0};class Q{constructor(t,e={}){this.version="12.5.0",this.canTrackVelocity=null,this.events={},this.updateAndNotify=(t,e=!0)=>{const n=C.now();this.updatedAt!==n&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(t),this.current!==this.prev&&this.events.change&&this.events.change.notify(this.current),e&&this.events.renderRequest&&this.events.renderRequest.notify(this.current)},this.hasAnimated=!1,this.setCurrent(t),this.owner=e.owner}setCurrent(t){var e;this.current=t,this.updatedAt=C.now(),null===this.canTrackVelocity&&void 0!==t&&(this.canTrackVelocity=(e=this.current,!isNaN(parseFloat(e))))}setPrevFrameValue(t=this.current){this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt}onChange(t){return this.on("change",t)}on(t,n){this.events[t]||(this.events[t]=new e.SubscriptionManager);const i=this.events[t].add(n);return"change"===t?()=>{i(),E.read(()=>{this.events.change.getSize()||this.stop()})}:i}clearListeners(){for(const t in this.events)this.events[t].clear()}attach(t,e){this.passiveEffect=t,this.stopPassiveEffect=e}set(t,e=!0){e&&this.passiveEffect?this.passiveEffect(t,this.updateAndNotify):this.updateAndNotify(t,e)}setWithVelocity(t,e,n){this.set(e),this.prev=void 0,this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt-n}jump(t,e=!0){this.updateAndNotify(t),this.prev=t,this.prevUpdatedAt=this.prevFrameValue=void 0,e&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}get(){return J.current&&J.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const t=C.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||t-this.updatedAt>30)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,30);return e.velocityPerSecond(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(t){return this.stop(),new Promise(e=>{this.hasAnimated=!0,this.animation=t(e),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function Z(t){var n;if(r(t.type)){const n=o(t,100,t.type);t.ease=m()?n.ease:"easeOut",t.duration=e.secondsToMilliseconds(n.duration),t.type="keyframes"}else t.duration=e.secondsToMilliseconds(null!==(n=t.duration)&&void 0!==n?n:.3),t.ease=t.ease||"easeOut"}class _ extends u{constructor(t,n,i,a,s){const o=function(t,n,i){var a;const s={},o={fill:"both",easing:"linear",composite:"replace"};o.delay=e.secondsToMilliseconds(null!==(a=i.delay)&&void 0!==a?a:0),Z(i),o.duration=i.duration;const{ease:r,times:c}=i;c&&(s.offset=c),s[t]=n;const u=y(r,i.duration);return Array.isArray(u)?s.easing=u:o.easing=u,{keyframes:s,options:o}}(i,a,s);super(t.animate(o.keyframes,{pseudoElement:n,...o.options}))}}function tt(t){return"layout"===t?"group":"enter"===t||"new"===t?"new":"exit"===t||"old"===t?"old":"group"}let et={},nt=null;const it=(t,e)=>{et[t]=e},at=()=>{nt||(nt=document.createElement("style"),nt.id="motion-view");let t="";for(const e in et){const n=et[e];t+=e+" {\n";for(const[e,i]of Object.entries(n))t+=` ${e}: ${i};\n`;t+="}\n"}nt.textContent=t,document.head.appendChild(nt),et={}},st=()=>{nt&&nt.parentElement&&nt.parentElement.removeChild(nt)};function ot(t){const e=t.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return e?{layer:e[2],type:e[1]}:null}function rt(t){var e;const{effect:n}=t;return!!n&&(n.target===document.documentElement&&(null===(e=n.pseudoElement)||void 0===e?void 0:e.startsWith("::view-transition")))}const ct=["layout","enter","exit","new","old"];function ut(t,n,s){if(!document.startViewTransition)return new Promise(async e=>{await t(),e(new i([]))});(function(t,e){return e.has(t)&&Object.keys(e.get(t)).length>0})("root",s)||it(":root",{"view-transition-name":"none"}),it("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),at();const o=document.startViewTransition(async()=>{await t()});return o.finished.finally(()=>{st()}),new Promise(t=>{o.ready.then(()=>{var o;const r=document.getAnimations().filter(rt),c=[];s.forEach((t,e)=>{for(const i of ct){if(!t[i])continue;const{keyframes:s,options:o}=t[i];for(let[t,r]of Object.entries(s)){if(!r)continue;const s={...a(n,t),...a(o,t)},u=tt(i);if("opacity"===t&&!Array.isArray(r)){r=["new"===u?0:1,r]}"function"==typeof s.delay&&(s.delay=s.delay(0,1));const l=new _(document.documentElement,`::view-transition-${u}(${e})`,t,r,s);c.push(l)}}});for(const t of r){if("finished"===t.playState)continue;const{effect:i}=t;if(!(i&&i instanceof KeyframeEffect))continue;const{pseudoElement:r}=i;if(!r)continue;const l=ot(r);if(!l)continue;const d=s.get(l.layer);if(d)lt(d,"enter")&<(d,"exit")&&i.getKeyframes().some(t=>t.mixBlendMode)?c.push(new u(t)):t.cancel();else{const s="group"===l.type?"layout":"",r={...a(n,s)};Z(r);const d=y(r.ease,r.duration);i.updateTiming({delay:e.secondsToMilliseconds(null!==(o=r.delay)&&void 0!==o?o:0),duration:r.duration,easing:d}),c.push(new u(t))}}t(new i(c))})})}function lt(t,e){var n;return null===(n=null==t?void 0:t[e])||void 0===n?void 0:n.keyframes.opacity}class dt{constructor(t,n={}){this.currentTarget="root",this.targets=new Map,this.notifyReady=e.noop,this.readyPromise=new Promise(t=>{this.notifyReady=t}),queueMicrotask(()=>{ut(t,n,this.targets).then(t=>this.notifyReady(t))})}get(t){return this.currentTarget=t,this}layout(t,e){return this.updateTarget("layout",t,e),this}new(t,e){return this.updateTarget("new",t,e),this}old(t,e){return this.updateTarget("old",t,e),this}enter(t,e){return this.updateTarget("enter",t,e),this}exit(t,e){return this.updateTarget("exit",t,e),this}crossfade(t){return this.updateTarget("enter",{opacity:1},t),this.updateTarget("exit",{opacity:0},t),this}updateTarget(t,e,n={}){const{currentTarget:i,targets:a}=this;a.has(i)||a.set(i,{});a.get(i)[t]={keyframes:e,options:n}}then(t,e){return this.readyPromise.then(t,e)}}t.GroupPlaybackControls=class extends i{then(t,e){return Promise.all(this.animations).then(t).catch(e)}},t.MotionValue=Q,t.NativeAnimationControls=u,t.ViewTransitionBuilder=dt,t.activeAnimations=K,t.attachTimeline=c,t.calcGeneratorDuration=s,t.cancelFrame=A,t.cancelMicrotask=M,t.capturePointer=D,t.collectMotionValues=J,t.createGeneratorEasing=o,t.createRenderBatcher=w,t.cubicBezierAsString=f,t.frame=E,t.frameData=P,t.frameSteps=b,t.generateLinearEasing=p,t.getValueTransition=a,t.hover=function(t,e,n={}){const[i,a,s]=j(t,n),o=t=>{if(!F(t))return;const{target:n}=t,i=e(n,t);if("function"!=typeof i||!n)return;const s=t=>{F(t)&&(i(t),n.removeEventListener("pointerleave",s))};n.addEventListener("pointerleave",s,a)};return i.forEach(t=>{t.addEventListener("pointerenter",o,a)}),s},t.isBezierDefinition=l,t.isDragActive=R,t.isDragging=L,t.isGenerator=r,t.isNodeOrChild=N,t.isPrimaryPointer=O,t.isWaapiSupportedEasing=function t(e){return Boolean("function"==typeof e&&m()||!e||"string"==typeof e&&(e in v||m())||l(e)||Array.isArray(e)&&e.every(t))},t.mapEasingToNativeEasing=y,t.maxGeneratorDuration=2e4,t.microtask=x,t.motionValue=function(t,e){return new Q(t,e)},t.press=function(t,e,n={}){const[i,a,s]=j(t,n),o=t=>{const n=t.currentTarget;if(!n||!$(t)||q.has(n))return;q.add(n),D(t,"set");const i=e(n,t),s=(t,e)=>{n.removeEventListener("pointerup",o),n.removeEventListener("pointercancel",r),D(t,"release"),$(t)&&q.has(n)&&(q.delete(n),"function"==typeof i&&i(t,{success:e}))},o=t=>{const e=!!t.isTrusted&&(i=t,a=n instanceof Element?n.getBoundingClientRect():{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},i.clientX<a.left||i.clientX>a.right||i.clientY<a.top||i.clientY>a.bottom);var i,a;s(t,!e&&(!(n instanceof Element)||N(n,t.target)))},r=t=>{s(t,!1)};n.addEventListener("pointerup",o,a),n.addEventListener("pointercancel",r,a),n.addEventListener("lostpointercapture",r,a)};return i.forEach(t=>{let e=!1;var i;(t=n.useGlobalTarget?window:t)instanceof HTMLElement&&(e=!0,i=t,B.has(i.tagName)||-1!==i.tabIndex||null!==t.getAttribute("tabindex")||(t.tabIndex=0)),t.addEventListener("pointerdown",o,a),e&&t.addEventListener("focus",t=>((t,e)=>{const n=t.currentTarget;if(!n)return;const i=G(()=>{if(q.has(n))return;I(n,"down");const t=G(()=>{I(n,"up")});n.addEventListener("keyup",t,e),n.addEventListener("blur",()=>I(n,"cancel"),e)});n.addEventListener("keydown",i,e),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),e)})(t,a),a)}),s},t.recordStats=function(){if(T.value)throw H(),new Error("Stats are already being measured");const t=T;return t.value={frameloop:{rate:[],read:[],resolveKeyframes:[],update:[],preRender:[],render:[],postRender:[]},animations:{mainThread:[],waapi:[],layout:[]},layoutProjection:{nodes:[],calculatedTargetDeltas:[],calculatedProjections:[]}},t.addProjectionMetrics=e=>{const{layoutProjection:n}=t.value;n.nodes.push(e.nodes),n.calculatedTargetDeltas.push(e.calculatedTargetDeltas),n.calculatedProjections.push(e.calculatedProjections)},E.postRender(U,!0),Y},t.resolveElements=V,t.setDragLock=function(t){return"x"===t||"y"===t?L[t]?null:(L[t]=!0,()=>{L[t]=!1}):L.x||L.y?null:(L.x=L.y=!0,()=>{L.x=L.y=!1})},t.statsBuffer=T,t.supportedWaapiEasing=v,t.supportsFlags=d,t.supportsLinearEasing=m,t.supportsScrollTimeline=n,t.time=C,t.view=function(t,e={}){return new dt(t,e)}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("motion-utils")):"function"==typeof define&&define.amd?define(["exports","motion-utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MotionDom={},e.MotionUtils)}(this,(function(e,t){"use strict";const n=t.memo(()=>void 0!==window.ScrollTimeline);class i{constructor(e){this.stop=()=>this.runAll("stop"),this.animations=e.filter(Boolean)}get finished(){return Promise.all(this.animations.map(e=>"finished"in e?e.finished:e))}getAll(e){return this.animations[0][e]}setAll(e,t){for(let n=0;n<this.animations.length;n++)this.animations[n][e]=t}attachTimeline(e,t){const i=this.animations.map(i=>n()&&i.attachTimeline?i.attachTimeline(e):"function"==typeof t?t(i):void 0);return()=>{i.forEach((e,t)=>{e&&e(),this.animations[t].stop()})}}get time(){return this.getAll("time")}set time(e){this.setAll("time",e)}get speed(){return this.getAll("speed")}set speed(e){this.setAll("speed",e)}get startTime(){return this.getAll("startTime")}get duration(){let e=0;for(let t=0;t<this.animations.length;t++)e=Math.max(e,this.animations[t].duration);return e}runAll(e){this.animations.forEach(t=>t[e]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function a(e,t){return e?e[t]||e.default||e:void 0}function s(e){let t=0;let n=e.next(t);for(;!n.done&&t<2e4;)t+=50,n=e.next(t);return t>=2e4?1/0:t}function o(e,n=100,i){const a=i({...e,keyframes:[0,n]}),o=Math.min(s(a),2e4);return{type:"keyframes",ease:e=>a.next(o*e).value/n,duration:t.millisecondsToSeconds(o)}}function r(e){return"function"==typeof e}function c(e,t){e.timeline=t,e.onfinish=null}class u{constructor(e){this.animation=e}get duration(){var e,n,i;const a=(null===(n=null===(e=this.animation)||void 0===e?void 0:e.effect)||void 0===n?void 0:n.getComputedTiming().duration)||(null===(i=this.options)||void 0===i?void 0:i.duration)||300;return t.millisecondsToSeconds(Number(a))}get time(){var e;return this.animation?t.millisecondsToSeconds((null===(e=this.animation)||void 0===e?void 0:e.currentTime)||0):0}set time(e){this.animation&&(this.animation.currentTime=t.secondsToMilliseconds(e))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(e){this.animation&&(this.animation.playbackRate=e)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var e,t;this.animation&&(null===(e=this.options)||void 0===e?void 0:e.allowFlatten)&&(null===(t=this.animation.effect)||void 0===t||t.updateTiming({easing:"linear"}))}attachTimeline(e){return this.animation&&c(this.animation,e),t.noop}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(e){}}}const l=e=>Array.isArray(e)&&"number"==typeof e[0],d={linearEasing:void 0};function m(e,n){const i=t.memo(e);return()=>{var e;return null!==(e=d[n])&&void 0!==e?e:i()}}const h=m(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(e){return!1}return!0},"linearEasing"),p=(e,n,i=10)=>{let a="";const s=Math.max(Math.round(n/i),2);for(let n=0;n<s;n++)a+=e(t.progress(0,s-1,n))+", ";return`linear(${a.substring(0,a.length-2)})`};const f=([e,t,n,i])=>`cubic-bezier(${e}, ${t}, ${n}, ${i})`,v={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:f([0,.65,.55,1]),circOut:f([.55,0,1,.45]),backIn:f([.31,.01,.66,-.59]),backOut:f([.33,1.53,.69,.99])};function y(e,t){return e?"function"==typeof e&&h()?p(e,t):l(e)?f(e):Array.isArray(e)?e.map(e=>y(e,t)||v.easeOut):v[e]:void 0}const g=["read","resolveKeyframes","update","preRender","render","postRender"],w={value:null,addProjectionMetrics:null};function T(e,n){let i=!1,a=!0;const s={delta:0,timestamp:0,isProcessing:!1},o=()=>i=!0,r=g.reduce((e,t)=>(e[t]=function(e,t){let n=new Set,i=new Set,a=!1,s=!1;const o=new WeakSet;let r={delta:0,timestamp:0,isProcessing:!1},c=0;function u(t){o.has(t)&&(l.schedule(t),e()),c++,t(r)}const l={schedule:(e,t=!1,s=!1)=>{const r=s&&a?n:i;return t&&o.add(e),r.has(e)||r.add(e),e},cancel:e=>{i.delete(e),o.delete(e)},process:e=>{r=e,a?s=!0:(a=!0,[n,i]=[i,n],n.forEach(u),t&&w.value&&w.value.frameloop[t].push(c),c=0,n.clear(),a=!1,s&&(s=!1,l.process(e)))}};return l}(o,n?t:void 0),e),{}),{read:c,resolveKeyframes:u,update:l,preRender:d,render:m,postRender:h}=r,p=()=>{const o=t.MotionGlobalConfig.useManualTiming?s.timestamp:performance.now();i=!1,t.MotionGlobalConfig.useManualTiming||(s.delta=a?1e3/60:Math.max(Math.min(o-s.timestamp,40),1)),s.timestamp=o,s.isProcessing=!0,c.process(s),u.process(s),l.process(s),d.process(s),m.process(s),h.process(s),s.isProcessing=!1,i&&n&&(a=!1,e(p))};return{schedule:g.reduce((t,n)=>{const o=r[n];return t[n]=(t,n=!1,r=!1)=>(i||(i=!0,a=!0,s.isProcessing||e(p)),o.schedule(t,n,r)),t},{}),cancel:e=>{for(let t=0;t<g.length;t++)r[g[t]].cancel(e)},state:s,steps:r}}const{schedule:E,cancel:A,state:P,steps:b}=T("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:t.noop,!0),{schedule:x,cancel:M}=T(queueMicrotask,!1);let k;function S(){k=void 0}const L={now:()=>(void 0===k&&L.set(P.isProcessing||t.MotionGlobalConfig.useManualTiming?P.timestamp:performance.now()),k),set:e=>{k=e,queueMicrotask(S)}},V={x:!1,y:!1};function C(){return V.x||V.y}function R(e,t,n){var i;if(e instanceof EventTarget)return[e];if("string"==typeof e){let a=document;t&&(a=t.current);const s=null!==(i=null==n?void 0:n[e])&&void 0!==i?i:a.querySelectorAll(e);return s?Array.from(s):[]}return Array.from(e)}function j(e,t){const n=R(e),i=new AbortController;return[n,{passive:!0,...t,signal:i.signal},()=>i.abort()]}function F(e){return!("touch"===e.pointerType||C())}const D=(e,t)=>!!t&&(e===t||D(e,t.parentElement)),N=e=>"mouse"===e.pointerType?"number"!=typeof e.button||e.button<=0:!1!==e.isPrimary,O=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const G=new WeakSet;function B(e){return t=>{"Enter"===t.key&&e(t)}}function I(e,t){e.dispatchEvent(new PointerEvent("pointer"+t,{isPrimary:!0,bubbles:!0}))}function $(e){return N(e)&&!C()}const q={layout:0,mainThread:0,waapi:0};function K(){const{value:e}=w;null!==e?(e.frameloop.rate.push(P.delta),e.animations.mainThread.push(q.mainThread),e.animations.waapi.push(q.waapi),e.animations.layout.push(q.layout)):A(K)}function U(e){return e.reduce((e,t)=>e+t,0)/e.length}function W(e,t=U){return 0===e.length?{min:0,max:0,avg:0}:{min:Math.min(...e),max:Math.max(...e),avg:t(e)}}const z=e=>Math.round(1e3/e);function H(){w.value=null,w.addProjectionMetrics=null}function X(){const{value:e}=w;if(!e)throw new Error("Stats are not being measured");H(),A(K);const t={frameloop:{rate:W(e.frameloop.rate),read:W(e.frameloop.read),resolveKeyframes:W(e.frameloop.resolveKeyframes),update:W(e.frameloop.update),preRender:W(e.frameloop.preRender),render:W(e.frameloop.render),postRender:W(e.frameloop.postRender)},animations:{mainThread:W(e.animations.mainThread),waapi:W(e.animations.waapi),layout:W(e.animations.layout)},layoutProjection:{nodes:W(e.layoutProjection.nodes),calculatedTargetDeltas:W(e.layoutProjection.calculatedTargetDeltas),calculatedProjections:W(e.layoutProjection.calculatedProjections)}},{rate:n}=t.frameloop;return n.min=z(n.min),n.max=z(n.max),n.avg=z(n.avg),[n.min,n.max]=[n.max,n.min],t}const J={current:void 0};class Q{constructor(e,t={}){this.version="12.6.1",this.canTrackVelocity=null,this.events={},this.updateAndNotify=(e,t=!0)=>{const n=L.now();this.updatedAt!==n&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(e),this.current!==this.prev&&this.events.change&&this.events.change.notify(this.current),t&&this.events.renderRequest&&this.events.renderRequest.notify(this.current)},this.hasAnimated=!1,this.setCurrent(e),this.owner=t.owner}setCurrent(e){var t;this.current=e,this.updatedAt=L.now(),null===this.canTrackVelocity&&void 0!==e&&(this.canTrackVelocity=(t=this.current,!isNaN(parseFloat(t))))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on("change",e)}on(e,n){this.events[e]||(this.events[e]=new t.SubscriptionManager);const i=this.events[e].add(n);return"change"===e?()=>{i(),E.read(()=>{this.events.change.getSize()||this.stop()})}:i}clearListeners(){for(const e in this.events)this.events[e].clear()}attach(e,t){this.passiveEffect=e,this.stopPassiveEffect=t}set(e,t=!0){t&&this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e,t)}setWithVelocity(e,t,n){this.set(t),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-n}jump(e,t=!0){this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,t&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}get(){return J.current&&J.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const e=L.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||e-this.updatedAt>30)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,30);return t.velocityPerSecond(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(e){return this.stop(),new Promise(t=>{this.hasAnimated=!0,this.animation=e(t),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function Y(e){var n;if(r(e.type)){const n=o(e,100,e.type);e.ease=h()?n.ease:"easeOut",e.duration=t.secondsToMilliseconds(n.duration),e.type="keyframes"}else e.duration=t.secondsToMilliseconds(null!==(n=e.duration)&&void 0!==n?n:.3),e.ease=e.ease||"easeOut"}class Z extends u{constructor(e,n,i,a,s){const o=function(e,n,i){var a;const s={},o={fill:"both",easing:"linear",composite:"replace"};o.delay=t.secondsToMilliseconds(null!==(a=i.delay)&&void 0!==a?a:0),Y(i),o.duration=i.duration;const{ease:r,times:c}=i;c&&(s.offset=c),s[e]=n;const u=y(r,i.duration);return Array.isArray(u)?s.easing=u:o.easing=u,{keyframes:s,options:o}}(i,a,s);super(e.animate(o.keyframes,{pseudoElement:n,...o.options}))}}function _(e){return"layout"===e?"group":"enter"===e||"new"===e?"new":"exit"===e||"old"===e?"old":"group"}let ee={},te=null;const ne=(e,t)=>{ee[e]=t},ie=()=>{te||(te=document.createElement("style"),te.id="motion-view");let e="";for(const t in ee){const n=ee[t];e+=t+" {\n";for(const[t,i]of Object.entries(n))e+=` ${t}: ${i};\n`;e+="}\n"}te.textContent=e,document.head.appendChild(te),ee={}},ae=()=>{te&&te.parentElement&&te.parentElement.removeChild(te)};function se(e){const t=e.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return t?{layer:t[2],type:t[1]}:null}function oe(e){var t;const{effect:n}=e;return!!n&&(n.target===document.documentElement&&(null===(t=n.pseudoElement)||void 0===t?void 0:t.startsWith("::view-transition")))}const re=["layout","enter","exit","new","old"];function ce(e){const{update:n,targets:s,options:o}=e;if(!document.startViewTransition)return new Promise(async e=>{await n(),e(new i([]))});(function(e,t){return t.has(e)&&Object.keys(t.get(e)).length>0})("root",s)||ne(":root",{"view-transition-name":"none"}),ne("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),ie();const r=document.startViewTransition(async()=>{await n()});return r.finished.finally(()=>{ae()}),new Promise(e=>{r.ready.then(()=>{var n;const r=document.getAnimations().filter(oe),c=[];s.forEach((e,t)=>{for(const n of re){if(!e[n])continue;const{keyframes:i,options:s}=e[n];for(let[e,r]of Object.entries(i)){if(!r)continue;const i={...a(o,e),...a(s,e)},u=_(n);if("opacity"===e&&!Array.isArray(r)){r=["new"===u?0:1,r]}"function"==typeof i.delay&&(i.delay=i.delay(0,1));const l=new Z(document.documentElement,`::view-transition-${u}(${t})`,e,r,i);c.push(l)}}});for(const e of r){if("finished"===e.playState)continue;const{effect:i}=e;if(!(i&&i instanceof KeyframeEffect))continue;const{pseudoElement:r}=i;if(!r)continue;const l=se(r);if(!l)continue;const d=s.get(l.layer);if(d)ue(d,"enter")&&ue(d,"exit")&&i.getKeyframes().some(e=>e.mixBlendMode)?c.push(new u(e)):e.cancel();else{const s="group"===l.type?"layout":"",r={...a(o,s)};Y(r);const d=y(r.ease,r.duration);i.updateTiming({delay:t.secondsToMilliseconds(null!==(n=r.delay)&&void 0!==n?n:0),duration:r.duration,easing:d}),c.push(new u(e))}}e(new i(c))})})}function ue(e,t){var n;return null===(n=null==e?void 0:e[t])||void 0===n?void 0:n.keyframes.opacity}let le=[],de=null;function me(){de=null;const[e]=le;var n;e&&(n=e,t.removeItem(le,n),de=n,ce(n).then(e=>{n.notifyReady(e),e.finished.finally(me)}))}function he(){var e;for(let e=le.length-1;e>=0;e--){const t=le[e],{interrupt:n}=t.options;if("immediate"===n){const n=le.slice(0,e+1).map(e=>e.update),i=le.slice(e+1);t.update=()=>{n.forEach(e=>e())},le=[t,...i];break}}de&&"immediate"!==(null===(e=le[0])||void 0===e?void 0:e.options.interrupt)||me()}class pe{constructor(e,n={}){var i;this.currentTarget="root",this.targets=new Map,this.notifyReady=t.noop,this.readyPromise=new Promise(e=>{this.notifyReady=e}),this.update=e,this.options={interrupt:"wait",...n},i=this,le.push(i),x.render(he)}get(e){return this.currentTarget=e,this}layout(e,t){return this.updateTarget("layout",e,t),this}new(e,t){return this.updateTarget("new",e,t),this}old(e,t){return this.updateTarget("old",e,t),this}enter(e,t){return this.updateTarget("enter",e,t),this}exit(e,t){return this.updateTarget("exit",e,t),this}crossfade(e){return this.updateTarget("enter",{opacity:1},e),this.updateTarget("exit",{opacity:0},e),this}updateTarget(e,t,n={}){const{currentTarget:i,targets:a}=this;a.has(i)||a.set(i,{});a.get(i)[e]={keyframes:t,options:n}}then(e,t){return this.readyPromise.then(e,t)}}e.GroupPlaybackControls=class extends i{then(e,t){return Promise.all(this.animations).then(e).catch(t)}},e.MotionValue=Q,e.NativeAnimationControls=u,e.ViewTransitionBuilder=pe,e.activeAnimations=q,e.animateView=function(e,t={}){return new pe(e,t)},e.attachTimeline=c,e.calcGeneratorDuration=s,e.cancelFrame=A,e.cancelMicrotask=M,e.collectMotionValues=J,e.createGeneratorEasing=o,e.createRenderBatcher=T,e.cubicBezierAsString=f,e.frame=E,e.frameData=P,e.frameSteps=b,e.generateLinearEasing=p,e.getValueTransition=a,e.hover=function(e,t,n={}){const[i,a,s]=j(e,n),o=e=>{if(!F(e))return;const{target:n}=e,i=t(n,e);if("function"!=typeof i||!n)return;const s=e=>{F(e)&&(i(e),n.removeEventListener("pointerleave",s))};n.addEventListener("pointerleave",s,a)};return i.forEach(e=>{e.addEventListener("pointerenter",o,a)}),s},e.isBezierDefinition=l,e.isDragActive=C,e.isDragging=V,e.isGenerator=r,e.isNodeOrChild=D,e.isPrimaryPointer=N,e.isWaapiSupportedEasing=function e(t){return Boolean("function"==typeof t&&h()||!t||"string"==typeof t&&(t in v||h())||l(t)||Array.isArray(t)&&t.every(e))},e.mapEasingToNativeEasing=y,e.maxGeneratorDuration=2e4,e.microtask=x,e.motionValue=function(e,t){return new Q(e,t)},e.press=function(e,t,n={}){const[i,a,s]=j(e,n),o=e=>{const i=e.currentTarget;if(!$(e)||G.has(i))return;G.add(i);const s=t(i,e),o=(e,t)=>{window.removeEventListener("pointerup",r),window.removeEventListener("pointercancel",c),$(e)&&G.has(i)&&(G.delete(i),"function"==typeof s&&s(e,{success:t}))},r=e=>{o(e,i===window||i===document||n.useGlobalTarget||D(i,e.target))},c=e=>{o(e,!1)};window.addEventListener("pointerup",r,a),window.addEventListener("pointercancel",c,a)};return i.forEach(e=>{var t;(n.useGlobalTarget?window:e).addEventListener("pointerdown",o,a),e instanceof HTMLElement&&(e.addEventListener("focus",e=>((e,t)=>{const n=e.currentTarget;if(!n)return;const i=B(()=>{if(G.has(n))return;I(n,"down");const e=B(()=>{I(n,"up")});n.addEventListener("keyup",e,t),n.addEventListener("blur",()=>I(n,"cancel"),t)});n.addEventListener("keydown",i,t),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),t)})(e,a)),t=e,O.has(t.tagName)||-1!==t.tabIndex||null!==e.tabIndex||(e.tabIndex=0))}),s},e.recordStats=function(){if(w.value)throw H(),new Error("Stats are already being measured");const e=w;return e.value={frameloop:{rate:[],read:[],resolveKeyframes:[],update:[],preRender:[],render:[],postRender:[]},animations:{mainThread:[],waapi:[],layout:[]},layoutProjection:{nodes:[],calculatedTargetDeltas:[],calculatedProjections:[]}},e.addProjectionMetrics=t=>{const{layoutProjection:n}=e.value;n.nodes.push(t.nodes),n.calculatedTargetDeltas.push(t.calculatedTargetDeltas),n.calculatedProjections.push(t.calculatedProjections)},E.postRender(K,!0),X},e.resolveElements=R,e.setDragLock=function(e){return"x"===e||"y"===e?V[e]?null:(V[e]=!0,()=>{V[e]=!1}):V.x||V.y?null:(V.x=V.y=!0,()=>{V.x=V.y=!1})},e.statsBuffer=w,e.supportedWaapiEasing=v,e.supportsFlags=d,e.supportsLinearEasing=h,e.supportsScrollTimeline=n,e.time=L}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.1",
|
|
4
4
|
"author": "Matt Perry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/motiondivision/motion",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\"",
|
|
25
25
|
"test": "jest --config jest.config.json --max-workers=2 motion-value.test"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "304abfe2c73decd53468dd6c4018f6b6969d230c"
|
|
28
28
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
function capturePointer(event, action) {
|
|
2
|
-
const actionName = `${action}PointerCapture`;
|
|
3
|
-
if (event.target instanceof Element &&
|
|
4
|
-
actionName in event.target &&
|
|
5
|
-
event.pointerId !== undefined) {
|
|
6
|
-
try {
|
|
7
|
-
event.target[actionName](event.pointerId);
|
|
8
|
-
}
|
|
9
|
-
catch (e) { }
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { capturePointer };
|