motion-v 1.0.0-alpha.0 → 1.0.0-alpha.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
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const vue = require("vue");
|
|
4
|
-
const core = require("@vueuse/core");
|
|
5
|
-
const motionDom = require("motion-dom");
|
|
6
4
|
const heyListen = require("hey-listen");
|
|
5
|
+
const motionDom = require("motion-dom");
|
|
6
|
+
const core = require("@vueuse/core");
|
|
7
7
|
function addUniqueItem(arr, item) {
|
|
8
8
|
if (arr.indexOf(item) === -1)
|
|
9
9
|
arr.push(item);
|
|
@@ -5861,9 +5861,13 @@ function convertSvgStyleToAttributes(keyframes2) {
|
|
|
5861
5861
|
style: styleProps
|
|
5862
5862
|
};
|
|
5863
5863
|
}
|
|
5864
|
+
function createVisualElement(Component, options) {
|
|
5865
|
+
return isSVGElement(Component) ? new SVGVisualElement(options) : new HTMLVisualElement(options);
|
|
5866
|
+
}
|
|
5864
5867
|
const STATE_TYPES = ["initial", "animate", "whileInView", "whileHover", "whilePress", "whileDrag", "whileFocus", "exit"];
|
|
5865
5868
|
class AnimationFeature extends Feature {
|
|
5866
5869
|
constructor(state2) {
|
|
5870
|
+
var _a;
|
|
5867
5871
|
super(state2);
|
|
5868
5872
|
this.animateUpdates = ({
|
|
5869
5873
|
controlActiveState,
|
|
@@ -5893,7 +5897,30 @@ class AnimationFeature extends Feature {
|
|
|
5893
5897
|
isExit
|
|
5894
5898
|
});
|
|
5895
5899
|
};
|
|
5900
|
+
this.state.visualElement = createVisualElement(this.state.options.as, {
|
|
5901
|
+
presenceContext: null,
|
|
5902
|
+
parent: (_a = this.state.parent) == null ? void 0 : _a.visualElement,
|
|
5903
|
+
props: {
|
|
5904
|
+
...this.state.options,
|
|
5905
|
+
whileTap: this.state.options.whilePress
|
|
5906
|
+
},
|
|
5907
|
+
visualState: {
|
|
5908
|
+
renderState: {
|
|
5909
|
+
transform: {},
|
|
5910
|
+
transformOrigin: {},
|
|
5911
|
+
style: {},
|
|
5912
|
+
vars: {},
|
|
5913
|
+
attrs: {}
|
|
5914
|
+
},
|
|
5915
|
+
latestValues: {
|
|
5916
|
+
...this.state.baseTarget
|
|
5917
|
+
}
|
|
5918
|
+
},
|
|
5919
|
+
reducedMotionConfig: this.state.options.motionConfig.reduceMotion
|
|
5920
|
+
});
|
|
5896
5921
|
this.state.animateUpdates = this.animateUpdates;
|
|
5922
|
+
if (this.state.isMounted())
|
|
5923
|
+
this.state.startAnimation();
|
|
5897
5924
|
}
|
|
5898
5925
|
updateAnimationControlsSubscription() {
|
|
5899
5926
|
const { animate: animate2 } = this.state.options;
|
|
@@ -6014,6 +6041,13 @@ class AnimationFeature extends Feature {
|
|
|
6014
6041
|
* Subscribe any provided AnimationControls to the component's VisualElement
|
|
6015
6042
|
*/
|
|
6016
6043
|
mount() {
|
|
6044
|
+
const { element } = this.state;
|
|
6045
|
+
mountedStates.set(element, this.state);
|
|
6046
|
+
if (!visualElementStore.get(element)) {
|
|
6047
|
+
this.state.visualElement.mount(element);
|
|
6048
|
+
visualElementStore.set(element, this.state.visualElement);
|
|
6049
|
+
}
|
|
6050
|
+
this.state.visualElement.state = this.state;
|
|
6017
6051
|
this.updateAnimationControlsSubscription();
|
|
6018
6052
|
}
|
|
6019
6053
|
update() {
|
|
@@ -7548,9 +7582,6 @@ const domAnimation = [
|
|
|
7548
7582
|
// LayoutFeature,
|
|
7549
7583
|
// PanGesture,
|
|
7550
7584
|
];
|
|
7551
|
-
function createVisualElement(Component, options) {
|
|
7552
|
-
return isSVGElement(Component) ? new SVGVisualElement(options) : new HTMLVisualElement(options);
|
|
7553
|
-
}
|
|
7554
7585
|
function isVariantLabels(value) {
|
|
7555
7586
|
return typeof value === "string" || value === false || Array.isArray(value);
|
|
7556
7587
|
}
|
|
@@ -7578,28 +7609,8 @@ class MotionState {
|
|
|
7578
7609
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
7579
7610
|
const initialVariantSource = this.context.initial === false ? ["initial", "animate"] : ["initial"];
|
|
7580
7611
|
this.initTarget(initialVariantSource);
|
|
7581
|
-
this.visualElement = createVisualElement(this.options.as, {
|
|
7582
|
-
presenceContext: null,
|
|
7583
|
-
parent: parent == null ? void 0 : parent.visualElement,
|
|
7584
|
-
props: {
|
|
7585
|
-
...this.options,
|
|
7586
|
-
whileTap: this.options.whilePress
|
|
7587
|
-
},
|
|
7588
|
-
visualState: {
|
|
7589
|
-
renderState: {
|
|
7590
|
-
transform: {},
|
|
7591
|
-
transformOrigin: {},
|
|
7592
|
-
style: {},
|
|
7593
|
-
vars: {},
|
|
7594
|
-
attrs: {}
|
|
7595
|
-
},
|
|
7596
|
-
latestValues: {
|
|
7597
|
-
...this.baseTarget
|
|
7598
|
-
}
|
|
7599
|
-
},
|
|
7600
|
-
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
7601
|
-
});
|
|
7602
7612
|
this.featureManager = new FeatureManager(this);
|
|
7613
|
+
this.type = isSVGElement(this.options.as) ? "svg" : "html";
|
|
7603
7614
|
}
|
|
7604
7615
|
// Get animation context, falling back to parent context for inheritance
|
|
7605
7616
|
get context() {
|
|
@@ -7626,7 +7637,8 @@ class MotionState {
|
|
|
7626
7637
|
}
|
|
7627
7638
|
// Update visual element with new options
|
|
7628
7639
|
updateOptions() {
|
|
7629
|
-
|
|
7640
|
+
var _a;
|
|
7641
|
+
(_a = this.visualElement) == null ? void 0 : _a.update({
|
|
7630
7642
|
...this.options,
|
|
7631
7643
|
whileTap: this.options.whilePress,
|
|
7632
7644
|
reducedMotionConfig: this.options.motionConfig.reduceMotion
|
|
@@ -7647,16 +7659,10 @@ class MotionState {
|
|
|
7647
7659
|
);
|
|
7648
7660
|
this.element = element;
|
|
7649
7661
|
this.options = options;
|
|
7650
|
-
mountedStates.set(element, this);
|
|
7651
|
-
if (!visualElementStore.get(element)) {
|
|
7652
|
-
this.visualElement.mount(element);
|
|
7653
|
-
visualElementStore.set(element, this.visualElement);
|
|
7654
|
-
}
|
|
7655
|
-
this.visualElement.state = this;
|
|
7656
7662
|
this.updateOptions();
|
|
7657
7663
|
this.featureManager.mount();
|
|
7658
7664
|
if (!notAnimate && this.options.animate) {
|
|
7659
|
-
if (this.
|
|
7665
|
+
if (this.type === "svg") {
|
|
7660
7666
|
this.visualElement.updateDimensions();
|
|
7661
7667
|
}
|
|
7662
7668
|
(_a = this.startAnimation) == null ? void 0 : _a.call(this);
|
|
@@ -7669,10 +7675,10 @@ class MotionState {
|
|
|
7669
7675
|
}
|
|
7670
7676
|
}
|
|
7671
7677
|
clearAnimation() {
|
|
7672
|
-
var _a;
|
|
7678
|
+
var _a, _b;
|
|
7673
7679
|
this.currentProcess && motionDom.cancelFrame(this.currentProcess);
|
|
7674
7680
|
this.currentProcess = null;
|
|
7675
|
-
(_a = this.visualElement.variantChildren) == null ? void 0 :
|
|
7681
|
+
(_b = (_a = this.visualElement) == null ? void 0 : _a.variantChildren) == null ? void 0 : _b.forEach((child) => {
|
|
7676
7682
|
child.state.clearAnimation();
|
|
7677
7683
|
});
|
|
7678
7684
|
}
|
|
@@ -7800,7 +7806,8 @@ function useMotionState(props) {
|
|
|
7800
7806
|
);
|
|
7801
7807
|
provideMotion(state2);
|
|
7802
7808
|
function getAttrs() {
|
|
7803
|
-
|
|
7809
|
+
var _a2;
|
|
7810
|
+
const isSVG = state2.type === "svg";
|
|
7804
7811
|
const attrsProps = { ...attrs };
|
|
7805
7812
|
Object.keys(attrs).forEach((key) => {
|
|
7806
7813
|
if (isMotionValue(attrs[key]))
|
|
@@ -7808,7 +7815,7 @@ function useMotionState(props) {
|
|
|
7808
7815
|
});
|
|
7809
7816
|
let styleProps = {
|
|
7810
7817
|
...props.style,
|
|
7811
|
-
...isSVG ? {} : state2.visualElement.latestValues
|
|
7818
|
+
...isSVG ? {} : ((_a2 = state2.visualElement) == null ? void 0 : _a2.latestValues) || state2.baseTarget
|
|
7812
7819
|
};
|
|
7813
7820
|
if (isSVG) {
|
|
7814
7821
|
const { attributes, style: style2 } = convertSvgStyleToAttributes({
|
|
@@ -54,7 +54,8 @@ function useMotionState(props) {
|
|
|
54
54
|
);
|
|
55
55
|
provideMotion(state);
|
|
56
56
|
function getAttrs() {
|
|
57
|
-
|
|
57
|
+
var _a2;
|
|
58
|
+
const isSVG = state.type === "svg";
|
|
58
59
|
const attrsProps = { ...attrs };
|
|
59
60
|
Object.keys(attrs).forEach((key) => {
|
|
60
61
|
if (isMotionValue(attrs[key]))
|
|
@@ -62,7 +63,7 @@ function useMotionState(props) {
|
|
|
62
63
|
});
|
|
63
64
|
let styleProps = {
|
|
64
65
|
...props.style,
|
|
65
|
-
...isSVG ? {} : state.visualElement.latestValues
|
|
66
|
+
...isSVG ? {} : ((_a2 = state.visualElement) == null ? void 0 : _a2.latestValues) || state.baseTarget
|
|
66
67
|
};
|
|
67
68
|
if (isSVG) {
|
|
68
69
|
const { attributes, style } = convertSvgStyleToAttributes({
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { isAnimationControls } from "../../animation/utils.mjs";
|
|
2
2
|
import { Feature } from "../feature.mjs";
|
|
3
|
+
import { mountedStates } from "../../state/motion-state.mjs";
|
|
4
|
+
import { visualElementStore } from "../../external/.pnpm/framer-motion@12.5.0/external/framer-motion/dist/es/render/store.mjs";
|
|
3
5
|
import { motionEvent } from "../../state/event.mjs";
|
|
4
6
|
import { style } from "../../state/style.mjs";
|
|
5
7
|
import { transformResetValue } from "../../state/transform.mjs";
|
|
6
8
|
import { hasChanged, resolveVariant } from "../../state/utils.mjs";
|
|
7
9
|
import { isDef } from "@vueuse/core";
|
|
10
|
+
import { createVisualElement } from "../../state/create-visual-element.mjs";
|
|
8
11
|
import { animate } from "../../external/.pnpm/framer-motion@12.5.0/external/framer-motion/dist/es/animation/animate/index.mjs";
|
|
9
12
|
import { noop } from "../../external/.pnpm/motion-utils@12.5.0/external/motion-utils/dist/es/noop.mjs";
|
|
10
13
|
import "../../external/.pnpm/motion-utils@12.5.0/external/motion-utils/dist/es/errors.mjs";
|
|
11
14
|
const STATE_TYPES = ["initial", "animate", "whileInView", "whileHover", "whilePress", "whileDrag", "whileFocus", "exit"];
|
|
12
15
|
class AnimationFeature extends Feature {
|
|
13
16
|
constructor(state) {
|
|
17
|
+
var _a;
|
|
14
18
|
super(state);
|
|
15
19
|
this.animateUpdates = ({
|
|
16
20
|
controlActiveState,
|
|
@@ -40,7 +44,30 @@ class AnimationFeature extends Feature {
|
|
|
40
44
|
isExit
|
|
41
45
|
});
|
|
42
46
|
};
|
|
47
|
+
this.state.visualElement = createVisualElement(this.state.options.as, {
|
|
48
|
+
presenceContext: null,
|
|
49
|
+
parent: (_a = this.state.parent) == null ? void 0 : _a.visualElement,
|
|
50
|
+
props: {
|
|
51
|
+
...this.state.options,
|
|
52
|
+
whileTap: this.state.options.whilePress
|
|
53
|
+
},
|
|
54
|
+
visualState: {
|
|
55
|
+
renderState: {
|
|
56
|
+
transform: {},
|
|
57
|
+
transformOrigin: {},
|
|
58
|
+
style: {},
|
|
59
|
+
vars: {},
|
|
60
|
+
attrs: {}
|
|
61
|
+
},
|
|
62
|
+
latestValues: {
|
|
63
|
+
...this.state.baseTarget
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
reducedMotionConfig: this.state.options.motionConfig.reduceMotion
|
|
67
|
+
});
|
|
43
68
|
this.state.animateUpdates = this.animateUpdates;
|
|
69
|
+
if (this.state.isMounted())
|
|
70
|
+
this.state.startAnimation();
|
|
44
71
|
}
|
|
45
72
|
updateAnimationControlsSubscription() {
|
|
46
73
|
const { animate: animate2 } = this.state.options;
|
|
@@ -161,6 +188,13 @@ class AnimationFeature extends Feature {
|
|
|
161
188
|
* Subscribe any provided AnimationControls to the component's VisualElement
|
|
162
189
|
*/
|
|
163
190
|
mount() {
|
|
191
|
+
const { element } = this.state;
|
|
192
|
+
mountedStates.set(element, this.state);
|
|
193
|
+
if (!visualElementStore.get(element)) {
|
|
194
|
+
this.state.visualElement.mount(element);
|
|
195
|
+
visualElementStore.set(element, this.state.visualElement);
|
|
196
|
+
}
|
|
197
|
+
this.state.visualElement.state = this.state;
|
|
164
198
|
this.updateAnimationControlsSubscription();
|
|
165
199
|
}
|
|
166
200
|
update() {
|
|
@@ -12,8 +12,9 @@ export declare const mountedStates: WeakMap<Element, MotionState>;
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class MotionState {
|
|
14
14
|
readonly id: string;
|
|
15
|
+
type: 'html' | 'svg';
|
|
15
16
|
element: HTMLElement | null;
|
|
16
|
-
|
|
17
|
+
parent?: MotionState;
|
|
17
18
|
options: Options & {
|
|
18
19
|
animatePresenceContext?: PresenceContext;
|
|
19
20
|
features?: Feature[];
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { invariant } from "hey-listen";
|
|
2
|
-
import {
|
|
3
|
-
import { resolveVariant, isAnimateChanged } from "./utils.mjs";
|
|
2
|
+
import { isSVGElement, resolveVariant, isAnimateChanged } from "./utils.mjs";
|
|
4
3
|
import { FeatureManager } from "../features/feature-manager.mjs";
|
|
5
|
-
import { createVisualElement } from "./create-visual-element.mjs";
|
|
6
4
|
import { doneCallbacks } from "../components/presence.mjs";
|
|
7
5
|
import { isVariantLabels } from "./utils/is-variant-labels.mjs";
|
|
8
6
|
import { noop } from "../external/.pnpm/motion-utils@12.5.0/external/motion-utils/dist/es/noop.mjs";
|
|
@@ -32,28 +30,8 @@ class MotionState {
|
|
|
32
30
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
33
31
|
const initialVariantSource = this.context.initial === false ? ["initial", "animate"] : ["initial"];
|
|
34
32
|
this.initTarget(initialVariantSource);
|
|
35
|
-
this.visualElement = createVisualElement(this.options.as, {
|
|
36
|
-
presenceContext: null,
|
|
37
|
-
parent: parent == null ? void 0 : parent.visualElement,
|
|
38
|
-
props: {
|
|
39
|
-
...this.options,
|
|
40
|
-
whileTap: this.options.whilePress
|
|
41
|
-
},
|
|
42
|
-
visualState: {
|
|
43
|
-
renderState: {
|
|
44
|
-
transform: {},
|
|
45
|
-
transformOrigin: {},
|
|
46
|
-
style: {},
|
|
47
|
-
vars: {},
|
|
48
|
-
attrs: {}
|
|
49
|
-
},
|
|
50
|
-
latestValues: {
|
|
51
|
-
...this.baseTarget
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
55
|
-
});
|
|
56
33
|
this.featureManager = new FeatureManager(this);
|
|
34
|
+
this.type = isSVGElement(this.options.as) ? "svg" : "html";
|
|
57
35
|
}
|
|
58
36
|
// Get animation context, falling back to parent context for inheritance
|
|
59
37
|
get context() {
|
|
@@ -80,7 +58,8 @@ class MotionState {
|
|
|
80
58
|
}
|
|
81
59
|
// Update visual element with new options
|
|
82
60
|
updateOptions() {
|
|
83
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = this.visualElement) == null ? void 0 : _a.update({
|
|
84
63
|
...this.options,
|
|
85
64
|
whileTap: this.options.whilePress,
|
|
86
65
|
reducedMotionConfig: this.options.motionConfig.reduceMotion
|
|
@@ -101,16 +80,10 @@ class MotionState {
|
|
|
101
80
|
);
|
|
102
81
|
this.element = element;
|
|
103
82
|
this.options = options;
|
|
104
|
-
mountedStates.set(element, this);
|
|
105
|
-
if (!visualElementStore.get(element)) {
|
|
106
|
-
this.visualElement.mount(element);
|
|
107
|
-
visualElementStore.set(element, this.visualElement);
|
|
108
|
-
}
|
|
109
|
-
this.visualElement.state = this;
|
|
110
83
|
this.updateOptions();
|
|
111
84
|
this.featureManager.mount();
|
|
112
85
|
if (!notAnimate && this.options.animate) {
|
|
113
|
-
if (this.
|
|
86
|
+
if (this.type === "svg") {
|
|
114
87
|
this.visualElement.updateDimensions();
|
|
115
88
|
}
|
|
116
89
|
(_a = this.startAnimation) == null ? void 0 : _a.call(this);
|
|
@@ -123,10 +96,10 @@ class MotionState {
|
|
|
123
96
|
}
|
|
124
97
|
}
|
|
125
98
|
clearAnimation() {
|
|
126
|
-
var _a;
|
|
99
|
+
var _a, _b;
|
|
127
100
|
this.currentProcess && cancelFrame(this.currentProcess);
|
|
128
101
|
this.currentProcess = null;
|
|
129
|
-
(_a = this.visualElement.variantChildren) == null ? void 0 :
|
|
102
|
+
(_b = (_a = this.visualElement) == null ? void 0 : _a.variantChildren) == null ? void 0 : _b.forEach((child) => {
|
|
130
103
|
child.state.clearAnimation();
|
|
131
104
|
});
|
|
132
105
|
}
|