motion-dom 12.5.0 → 12.6.0
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 +59 -13
- package/dist/es/index.mjs +1 -1
- 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 -10
- package/dist/motion-dom.dev.js +59 -13
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -933,7 +933,7 @@ class MotionValue {
|
|
|
933
933
|
* This will be replaced by the build step with the latest version number.
|
|
934
934
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
935
935
|
*/
|
|
936
|
-
this.version = "12.
|
|
936
|
+
this.version = "12.6.0";
|
|
937
937
|
/**
|
|
938
938
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
939
939
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1335,7 +1335,8 @@ function hasTarget(target, targets) {
|
|
|
1335
1335
|
}
|
|
1336
1336
|
|
|
1337
1337
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
1338
|
-
function startViewAnimation(
|
|
1338
|
+
function startViewAnimation(builder) {
|
|
1339
|
+
const { update, targets, options: defaultOptions } = builder;
|
|
1339
1340
|
if (!document.startViewTransition) {
|
|
1340
1341
|
return new Promise(async (resolve) => {
|
|
1341
1342
|
await update();
|
|
@@ -1466,12 +1467,54 @@ function hasOpacity(target, key) {
|
|
|
1466
1467
|
return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
|
|
1467
1468
|
}
|
|
1468
1469
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1470
|
+
let builders = [];
|
|
1471
|
+
let current = null;
|
|
1472
|
+
function next() {
|
|
1473
|
+
current = null;
|
|
1474
|
+
const [nextBuilder] = builders;
|
|
1475
|
+
if (nextBuilder)
|
|
1476
|
+
start(nextBuilder);
|
|
1477
|
+
}
|
|
1478
|
+
function start(builder) {
|
|
1479
|
+
motionUtils.removeItem(builders, builder);
|
|
1480
|
+
current = builder;
|
|
1481
|
+
startViewAnimation(builder).then((animation) => {
|
|
1482
|
+
builder.notifyReady(animation);
|
|
1483
|
+
animation.finished.finally(next);
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
function processQueue() {
|
|
1487
|
+
var _a;
|
|
1488
|
+
/**
|
|
1489
|
+
* Iterate backwards over the builders array. We can ignore the
|
|
1490
|
+
* "wait" animations. If we have an interrupting animation in the
|
|
1491
|
+
* queue then we need to batch all preceeding animations into it.
|
|
1492
|
+
* Currently this only batches the update functions but will also
|
|
1493
|
+
* need to batch the targets.
|
|
1494
|
+
*/
|
|
1495
|
+
for (let i = builders.length - 1; i >= 0; i--) {
|
|
1496
|
+
const builder = builders[i];
|
|
1497
|
+
const { interrupt } = builder.options;
|
|
1498
|
+
if (interrupt === "immediate") {
|
|
1499
|
+
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
|
|
1500
|
+
const remaining = builders.slice(i + 1);
|
|
1501
|
+
builder.update = () => {
|
|
1502
|
+
batchedUpdates.forEach((update) => update());
|
|
1503
|
+
};
|
|
1504
|
+
// Put the current builder at the front, followed by any "wait" builders
|
|
1505
|
+
builders = [builder, ...remaining];
|
|
1506
|
+
break;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
|
|
1510
|
+
next();
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function addToQueue(builder) {
|
|
1514
|
+
builders.push(builder);
|
|
1515
|
+
microtask.render(processQueue);
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1475
1518
|
class ViewTransitionBuilder {
|
|
1476
1519
|
constructor(update, options = {}) {
|
|
1477
1520
|
this.currentTarget = "root";
|
|
@@ -1480,9 +1523,12 @@ class ViewTransitionBuilder {
|
|
|
1480
1523
|
this.readyPromise = new Promise((resolve) => {
|
|
1481
1524
|
this.notifyReady = resolve;
|
|
1482
1525
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1526
|
+
this.update = update;
|
|
1527
|
+
this.options = {
|
|
1528
|
+
interrupt: "wait",
|
|
1529
|
+
...options,
|
|
1530
|
+
};
|
|
1531
|
+
addToQueue(this);
|
|
1486
1532
|
}
|
|
1487
1533
|
get(selector) {
|
|
1488
1534
|
this.currentTarget = selector;
|
|
@@ -1525,7 +1571,7 @@ class ViewTransitionBuilder {
|
|
|
1525
1571
|
return this.readyPromise.then(resolve, reject);
|
|
1526
1572
|
}
|
|
1527
1573
|
}
|
|
1528
|
-
function
|
|
1574
|
+
function animateView(update, defaultOptions = {}) {
|
|
1529
1575
|
return new ViewTransitionBuilder(update, defaultOptions);
|
|
1530
1576
|
}
|
|
1531
1577
|
|
|
@@ -1534,6 +1580,7 @@ exports.MotionValue = MotionValue;
|
|
|
1534
1580
|
exports.NativeAnimationControls = NativeAnimationControls;
|
|
1535
1581
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
1536
1582
|
exports.activeAnimations = activeAnimations;
|
|
1583
|
+
exports.animateView = animateView;
|
|
1537
1584
|
exports.attachTimeline = attachTimeline;
|
|
1538
1585
|
exports.calcGeneratorDuration = calcGeneratorDuration;
|
|
1539
1586
|
exports.cancelFrame = cancelFrame;
|
|
@@ -1570,4 +1617,3 @@ exports.supportsFlags = supportsFlags;
|
|
|
1570
1617
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
1571
1618
|
exports.supportsScrollTimeline = supportsScrollTimeline;
|
|
1572
1619
|
exports.time = time;
|
|
1573
|
-
exports.view = view;
|
package/dist/es/index.mjs
CHANGED
|
@@ -27,4 +27,4 @@ export { supportsFlags } from './utils/supports/flags.mjs';
|
|
|
27
27
|
export { supportsLinearEasing } from './utils/supports/linear-easing.mjs';
|
|
28
28
|
export { supportsScrollTimeline } from './utils/supports/scroll-timeline.mjs';
|
|
29
29
|
export { MotionValue, collectMotionValues, motionValue } from './value/index.mjs';
|
|
30
|
-
export { ViewTransitionBuilder,
|
|
30
|
+
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.0";
|
|
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
|
@@ -1046,19 +1046,16 @@ type ViewTransitionTarget = {
|
|
|
1046
1046
|
old?: ViewTransitionAnimationDefinition;
|
|
1047
1047
|
};
|
|
1048
1048
|
interface ViewTransitionOptions extends AnimationOptions {
|
|
1049
|
+
interrupt?: "wait" | "immediate";
|
|
1049
1050
|
}
|
|
1050
1051
|
type Target = string | Element;
|
|
1051
1052
|
|
|
1052
|
-
/**
|
|
1053
|
-
* TODO:
|
|
1054
|
-
* - Create view transition on next tick
|
|
1055
|
-
* - Replace animations with Motion animations
|
|
1056
|
-
* - Return GroupAnimation on next tick
|
|
1057
|
-
*/
|
|
1058
1053
|
declare class ViewTransitionBuilder {
|
|
1059
1054
|
private currentTarget;
|
|
1060
|
-
|
|
1061
|
-
|
|
1055
|
+
targets: Map<Target, ViewTransitionTarget>;
|
|
1056
|
+
update: () => void | Promise<void>;
|
|
1057
|
+
options: ViewTransitionOptions;
|
|
1058
|
+
notifyReady: (value: BaseGroupPlaybackControls) => void;
|
|
1062
1059
|
private readyPromise;
|
|
1063
1060
|
constructor(update: () => void | Promise<void>, options?: ViewTransitionOptions);
|
|
1064
1061
|
get(selector: Target): this;
|
|
@@ -1071,6 +1068,6 @@ declare class ViewTransitionBuilder {
|
|
|
1071
1068
|
updateTarget(target: "enter" | "exit" | "layout" | "new" | "old", keyframes: DOMKeyframesDefinition, options?: AnimationOptions): void;
|
|
1072
1069
|
then(resolve: () => void, reject?: () => void): Promise<void>;
|
|
1073
1070
|
}
|
|
1074
|
-
declare function
|
|
1071
|
+
declare function animateView(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
|
|
1075
1072
|
|
|
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, capturePointer, 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
|
|
1073
|
+
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, capturePointer, 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
|
@@ -933,7 +933,7 @@
|
|
|
933
933
|
* This will be replaced by the build step with the latest version number.
|
|
934
934
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
935
935
|
*/
|
|
936
|
-
this.version = "12.
|
|
936
|
+
this.version = "12.6.0";
|
|
937
937
|
/**
|
|
938
938
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
939
939
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1335,7 +1335,8 @@
|
|
|
1335
1335
|
}
|
|
1336
1336
|
|
|
1337
1337
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
1338
|
-
function startViewAnimation(
|
|
1338
|
+
function startViewAnimation(builder) {
|
|
1339
|
+
const { update, targets, options: defaultOptions } = builder;
|
|
1339
1340
|
if (!document.startViewTransition) {
|
|
1340
1341
|
return new Promise(async (resolve) => {
|
|
1341
1342
|
await update();
|
|
@@ -1466,12 +1467,54 @@
|
|
|
1466
1467
|
return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
|
|
1467
1468
|
}
|
|
1468
1469
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1470
|
+
let builders = [];
|
|
1471
|
+
let current = null;
|
|
1472
|
+
function next() {
|
|
1473
|
+
current = null;
|
|
1474
|
+
const [nextBuilder] = builders;
|
|
1475
|
+
if (nextBuilder)
|
|
1476
|
+
start(nextBuilder);
|
|
1477
|
+
}
|
|
1478
|
+
function start(builder) {
|
|
1479
|
+
motionUtils.removeItem(builders, builder);
|
|
1480
|
+
current = builder;
|
|
1481
|
+
startViewAnimation(builder).then((animation) => {
|
|
1482
|
+
builder.notifyReady(animation);
|
|
1483
|
+
animation.finished.finally(next);
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
function processQueue() {
|
|
1487
|
+
var _a;
|
|
1488
|
+
/**
|
|
1489
|
+
* Iterate backwards over the builders array. We can ignore the
|
|
1490
|
+
* "wait" animations. If we have an interrupting animation in the
|
|
1491
|
+
* queue then we need to batch all preceeding animations into it.
|
|
1492
|
+
* Currently this only batches the update functions but will also
|
|
1493
|
+
* need to batch the targets.
|
|
1494
|
+
*/
|
|
1495
|
+
for (let i = builders.length - 1; i >= 0; i--) {
|
|
1496
|
+
const builder = builders[i];
|
|
1497
|
+
const { interrupt } = builder.options;
|
|
1498
|
+
if (interrupt === "immediate") {
|
|
1499
|
+
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
|
|
1500
|
+
const remaining = builders.slice(i + 1);
|
|
1501
|
+
builder.update = () => {
|
|
1502
|
+
batchedUpdates.forEach((update) => update());
|
|
1503
|
+
};
|
|
1504
|
+
// Put the current builder at the front, followed by any "wait" builders
|
|
1505
|
+
builders = [builder, ...remaining];
|
|
1506
|
+
break;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
|
|
1510
|
+
next();
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function addToQueue(builder) {
|
|
1514
|
+
builders.push(builder);
|
|
1515
|
+
microtask.render(processQueue);
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1475
1518
|
class ViewTransitionBuilder {
|
|
1476
1519
|
constructor(update, options = {}) {
|
|
1477
1520
|
this.currentTarget = "root";
|
|
@@ -1480,9 +1523,12 @@
|
|
|
1480
1523
|
this.readyPromise = new Promise((resolve) => {
|
|
1481
1524
|
this.notifyReady = resolve;
|
|
1482
1525
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1526
|
+
this.update = update;
|
|
1527
|
+
this.options = {
|
|
1528
|
+
interrupt: "wait",
|
|
1529
|
+
...options,
|
|
1530
|
+
};
|
|
1531
|
+
addToQueue(this);
|
|
1486
1532
|
}
|
|
1487
1533
|
get(selector) {
|
|
1488
1534
|
this.currentTarget = selector;
|
|
@@ -1525,7 +1571,7 @@
|
|
|
1525
1571
|
return this.readyPromise.then(resolve, reject);
|
|
1526
1572
|
}
|
|
1527
1573
|
}
|
|
1528
|
-
function
|
|
1574
|
+
function animateView(update, defaultOptions = {}) {
|
|
1529
1575
|
return new ViewTransitionBuilder(update, defaultOptions);
|
|
1530
1576
|
}
|
|
1531
1577
|
|
|
@@ -1534,6 +1580,7 @@
|
|
|
1534
1580
|
exports.NativeAnimationControls = NativeAnimationControls;
|
|
1535
1581
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
1536
1582
|
exports.activeAnimations = activeAnimations;
|
|
1583
|
+
exports.animateView = animateView;
|
|
1537
1584
|
exports.attachTimeline = attachTimeline;
|
|
1538
1585
|
exports.calcGeneratorDuration = calcGeneratorDuration;
|
|
1539
1586
|
exports.cancelFrame = cancelFrame;
|
|
@@ -1570,6 +1617,5 @@
|
|
|
1570
1617
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
1571
1618
|
exports.supportsScrollTimeline = supportsScrollTimeline;
|
|
1572
1619
|
exports.time = time;
|
|
1573
|
-
exports.view = view;
|
|
1574
1620
|
|
|
1575
1621
|
}));
|
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(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 l{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 u=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):u(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"],w={value:null,addProjectionMetrics:null};function T(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 l(e){o.has(e)&&(u.schedule(e),t()),c++,e(r)}const u={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(l),e&&w.value&&w.value.frameloop[e].push(c),c=0,n.clear(),a=!1,s&&(s=!1,u.process(t)))}};return u}(o,n?e:void 0),t),{}),{read:c,resolveKeyframes:l,update:u,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),l.process(s),u.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}=T("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:e.noop,!0),{schedule:x,cancel:M}=T(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 I=new WeakSet;function G(t){return e=>{"Enter"===e.key&&t(e)}}function $(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}function q(t){return O(t)&&!R()}const K={layout:0,mainThread:0,waapi:0};function U(){const{value:t}=w;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(){w.value=null,w.addProjectionMetrics=null}function Y(){const{value:t}=w;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.6.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 l{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 l=y(r,i.duration);return Array.isArray(l)?s.easing=l:o.easing=l,{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 lt(t){const{update:n,targets:s,options:o}=t;if(!document.startViewTransition)return new Promise(async t=>{await n(),t(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 r=document.startViewTransition(async()=>{await n()});return r.finished.finally(()=>{st()}),new Promise(t=>{r.ready.then(()=>{var n;const r=document.getAnimations().filter(rt),c=[];s.forEach((t,e)=>{for(const n of ct){if(!t[n])continue;const{keyframes:i,options:s}=t[n];for(let[t,r]of Object.entries(i)){if(!r)continue;const i={...a(o,t),...a(s,t)},l=tt(n);if("opacity"===t&&!Array.isArray(r)){r=["new"===l?0:1,r]}"function"==typeof i.delay&&(i.delay=i.delay(0,1));const u=new _(document.documentElement,`::view-transition-${l}(${e})`,t,r,i);c.push(u)}}});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 u=ot(r);if(!u)continue;const d=s.get(u.layer);if(d)ut(d,"enter")&&ut(d,"exit")&&i.getKeyframes().some(t=>t.mixBlendMode)?c.push(new l(t)):t.cancel();else{const s="group"===u.type?"layout":"",r={...a(o,s)};Z(r);const d=y(r.ease,r.duration);i.updateTiming({delay:e.secondsToMilliseconds(null!==(n=r.delay)&&void 0!==n?n:0),duration:r.duration,easing:d}),c.push(new l(t))}}t(new i(c))})})}function ut(t,e){var n;return null===(n=null==t?void 0:t[e])||void 0===n?void 0:n.keyframes.opacity}let dt=[],ht=null;function mt(){ht=null;const[t]=dt;var n;t&&(n=t,e.removeItem(dt,n),ht=n,lt(n).then(t=>{n.notifyReady(t),t.finished.finally(mt)}))}function pt(){var t;for(let t=dt.length-1;t>=0;t--){const e=dt[t],{interrupt:n}=e.options;if("immediate"===n){const n=dt.slice(0,t+1).map(t=>t.update),i=dt.slice(t+1);e.update=()=>{n.forEach(t=>t())},dt=[e,...i];break}}ht&&"immediate"!==(null===(t=dt[0])||void 0===t?void 0:t.options.interrupt)||mt()}class ft{constructor(t,n={}){var i;this.currentTarget="root",this.targets=new Map,this.notifyReady=e.noop,this.readyPromise=new Promise(t=>{this.notifyReady=t}),this.update=t,this.options={interrupt:"wait",...n},i=this,dt.push(i),x.render(pt)}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=l,t.ViewTransitionBuilder=ft,t.activeAnimations=K,t.animateView=function(t,e={}){return new ft(t,e)},t.attachTimeline=c,t.calcGeneratorDuration=s,t.cancelFrame=A,t.cancelMicrotask=M,t.capturePointer=D,t.collectMotionValues=J,t.createGeneratorEasing=o,t.createRenderBatcher=T,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=u,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())||u(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||!q(t)||I.has(n))return;I.add(n),D(t,"set");const i=e(n,t),s=(t,e)=>{n.removeEventListener("pointerup",o),n.removeEventListener("pointercancel",r),D(t,"release"),q(t)&&I.has(n)&&(I.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(I.has(n))return;$(n,"down");const t=G(()=>{$(n,"up")});n.addEventListener("keyup",t,e),n.addEventListener("blur",()=>$(n,"cancel"),e)});n.addEventListener("keydown",i,e),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),e)})(t,a),a)}),s},t.recordStats=function(){if(w.value)throw H(),new Error("Stats are already being measured");const t=w;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=w,t.supportedWaapiEasing=v,t.supportsFlags=d,t.supportsLinearEasing=m,t.supportsScrollTimeline=n,t.time=C}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.0",
|
|
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": "1c1f25b8fb696e07eb5807ba7ac5b03a832d0a00"
|
|
28
28
|
}
|