motion-dom 13.5.0 → 14.0.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 +260 -442
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +2 -4
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-variant.mjs +29 -49
- package/dist/es/animation/interfaces/visual-element-variant.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element.mjs +5 -14
- package/dist/es/animation/interfaces/visual-element.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +6 -1
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +1 -1
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/svg/index.mjs +18 -7
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/render/VisualElement.mjs +17 -57
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +144 -267
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +7 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs.map +1 -1
- package/dist/es/render/utils/resolve-variants.mjs +8 -19
- package/dist/es/render/utils/resolve-variants.mjs.map +1 -1
- package/dist/index.d.ts +16 -24
- package/dist/motion-dom.dev.js +260 -442
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +3 -3
|
@@ -15,7 +15,7 @@ const isBrowser = typeof window !== "undefined";
|
|
|
15
15
|
* had been set to true in the meantime.
|
|
16
16
|
*/
|
|
17
17
|
function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
|
|
18
|
-
const shouldBlock =
|
|
18
|
+
const shouldBlock = key in protectedKeys && !needsAnimating[key];
|
|
19
19
|
needsAnimating[key] = false;
|
|
20
20
|
return shouldBlock;
|
|
21
21
|
}
|
|
@@ -30,9 +30,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
30
30
|
if (transitionOverride)
|
|
31
31
|
transition = transitionOverride;
|
|
32
32
|
const animations = [];
|
|
33
|
-
const animationTypeState = type &&
|
|
34
|
-
visualElement.animationState &&
|
|
35
|
-
visualElement.animationState.getState()[type];
|
|
33
|
+
const animationTypeState = type && visualElement.animationState?.getState()[type];
|
|
36
34
|
const path = transition?.path;
|
|
37
35
|
if (path) {
|
|
38
36
|
// path mutates `target` to claim x/y; loop below skips them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock
|
|
1
|
+
{"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock = key in protectedKeys && !needsAnimating[key]\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition,\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const defaultTransition = visualElement.getDefaultTransition()\n transition = transition\n ? resolveTransition(transition, defaultTransition)\n : defaultTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n const skipAnimations = transition?.skipAnimations\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type && visualElement.animationState?.getState()[type]\n\n const path = (transition as { path?: MotionPath } | undefined)?.path\n if (path) {\n // path mutates `target` to claim x/y; loop below skips them.\n path.animateVisualElement(\n visualElement,\n target,\n transition,\n delay,\n animations\n )\n }\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(transition || {}, key),\n }\n\n if (skipAnimations) valueTransition.skipAnimations = true\n\n /**\n * If the value is already at the defined target, skip the animation.\n * We still re-assert the value via frame.update to take precedence\n * over any stale transitionEnd callbacks from previous animations.\n */\n const currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n frame.update(() => value.set(valueTarget as any))\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (isBrowser && window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.start(\n animateMotionValue(\n key,\n value,\n valueTarget,\n shouldReduceMotion && positionalKeys.has(key)\n ? { type: false }\n : valueTransition,\n visualElement,\n isHandoff\n )\n )\n\n const animation = value.animation as\n | AnimationPlaybackControlsWithThen\n | undefined\n\n if (animation) {\n animations.push(animation)\n }\n }\n\n if (transitionEnd) {\n const applyTransitionEnd = () =>\n frame.update(() => {\n transitionEnd && setTarget(visualElement, transitionEnd)\n })\n\n if (animations.length) {\n Promise.all(animations).then(applyTransitionEnd)\n } else {\n applyTransitionEnd()\n }\n }\n\n return animations\n}\n"],"names":[],"mappings":";;;;;;;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MAAM,kBAAkB,GACpB,YAAY,IAAI,aAAa,CAAC,kBAAkB;AAEpD,QAAA,KAAK,CAAC,KAAK,CACP,kBAAkB,CACd,GAAG,EACH,KAAK,EACL,WAAW,EACX,kBAAkB,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG;AACxC,cAAE,EAAE,IAAI,EAAE,KAAK;cACb,eAAe,EACrB,aAAa,EACb,SAAS,CACZ,CACJ;AAED,QAAA,MAAM,SAAS,GAAG,KAAK,CAAC,SAET;QAEf,IAAI,SAAS,EAAE;AACX,YAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QAC9B;IACJ;IAEA,IAAI,aAAa,EAAE;QACf,MAAM,kBAAkB,GAAG,MACvB,KAAK,CAAC,MAAM,CAAC,MAAK;AACd,YAAA,aAAa,IAAI,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;AAC5D,QAAA,CAAC,CAAC;AAEN,QAAA,IAAI,UAAU,CAAC,MAAM,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACpD;aAAO;AACH,YAAA,kBAAkB,EAAE;QACxB;IACJ;AAEA,IAAA,OAAO,UAAU;AACrB;;;;"}
|
|
@@ -1,59 +1,39 @@
|
|
|
1
|
-
import { resolveVariant } from '../../render/utils/resolve-dynamic-variants.mjs';
|
|
1
|
+
import { resolveVariant, getTypeCustom } from '../../render/utils/resolve-dynamic-variants.mjs';
|
|
2
2
|
import { calcChildStagger } from '../utils/calc-child-stagger.mjs';
|
|
3
3
|
import { animateTarget } from './visual-element-target.mjs';
|
|
4
4
|
|
|
5
5
|
function animateVariant(visualElement, variant, options = {}) {
|
|
6
|
-
const resolved = resolveVariant(visualElement, variant, options.type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const resolved = resolveVariant(visualElement, variant, getTypeCustom(visualElement, options.type));
|
|
7
|
+
const transition = options.transitionOverride ||
|
|
8
|
+
(resolved?.transition ?? (visualElement.getDefaultTransition() || {}));
|
|
9
|
+
const getAnimation = () => Promise.all(resolved ? animateTarget(visualElement, resolved, options) : []);
|
|
10
|
+
const getChildAnimations = (delay = 0) => {
|
|
11
|
+
const { variantChildren } = visualElement;
|
|
12
|
+
const { delayChildren = 0, staggerChildren, staggerDirection, } = transition;
|
|
13
|
+
const animations = [];
|
|
14
|
+
variantChildren?.forEach((child) => {
|
|
15
|
+
child.notify("AnimationStart", variant);
|
|
16
|
+
animations.push(animateVariant(child, variant, {
|
|
17
|
+
...options,
|
|
18
|
+
delay: delay +
|
|
19
|
+
(typeof delayChildren === "function"
|
|
20
|
+
? 0
|
|
21
|
+
: delayChildren) +
|
|
22
|
+
calcChildStagger(variantChildren, child, delayChildren, staggerChildren, staggerDirection),
|
|
23
|
+
}).then(() => child.notify("AnimationComplete", variant)));
|
|
24
|
+
});
|
|
25
|
+
return Promise.all(animations);
|
|
26
|
+
};
|
|
13
27
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
const getAnimation = resolved
|
|
18
|
-
? () => Promise.all(animateTarget(visualElement, resolved, options))
|
|
19
|
-
: () => Promise.resolve();
|
|
20
|
-
/**
|
|
21
|
-
* If we have children, create a callback that runs all their animations.
|
|
22
|
-
* Otherwise, we resolve a Promise immediately for a composable no-op.
|
|
23
|
-
*/
|
|
24
|
-
const getChildAnimations = visualElement.variantChildren && visualElement.variantChildren.size
|
|
25
|
-
? (forwardDelay = 0) => {
|
|
26
|
-
const { delayChildren = 0, staggerChildren, staggerDirection, } = transition;
|
|
27
|
-
return animateChildren(visualElement, variant, forwardDelay, delayChildren, staggerChildren, staggerDirection, options);
|
|
28
|
-
}
|
|
29
|
-
: () => Promise.resolve();
|
|
30
|
-
/**
|
|
31
|
-
* If the transition explicitly defines a "when" option, we need to resolve either
|
|
32
|
-
* this animation or all children animations before playing the other.
|
|
28
|
+
* when: "beforeChildren" | "afterChildren" runs this element's animation
|
|
29
|
+
* and its children's in sequence.
|
|
33
30
|
*/
|
|
34
31
|
const { when } = transition;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
?
|
|
38
|
-
:
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return Promise.all([getAnimation(), getChildAnimations(options.delay)]);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function animateChildren(visualElement, variant, delay = 0, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
|
|
46
|
-
const animations = [];
|
|
47
|
-
for (const child of visualElement.variantChildren) {
|
|
48
|
-
child.notify("AnimationStart", variant);
|
|
49
|
-
animations.push(animateVariant(child, variant, {
|
|
50
|
-
...options,
|
|
51
|
-
delay: delay +
|
|
52
|
-
(typeof delayChildren === "function" ? 0 : delayChildren) +
|
|
53
|
-
calcChildStagger(visualElement.variantChildren, child, delayChildren, staggerChildren, staggerDirection),
|
|
54
|
-
}).then(() => child.notify("AnimationComplete", variant)));
|
|
55
|
-
}
|
|
56
|
-
return Promise.all(animations);
|
|
32
|
+
return when
|
|
33
|
+
? when === "beforeChildren"
|
|
34
|
+
? getAnimation().then(() => getChildAnimations())
|
|
35
|
+
: getChildAnimations().then(getAnimation)
|
|
36
|
+
: Promise.all([getAnimation(), getChildAnimations(options.delay)]);
|
|
57
37
|
}
|
|
58
38
|
|
|
59
39
|
export { animateVariant };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-element-variant.mjs","sources":["../../../../src/animation/interfaces/visual-element-variant.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"visual-element-variant.mjs","sources":["../../../../src/animation/interfaces/visual-element-variant.ts"],"sourcesContent":["import {\n getTypeCustom,\n resolveVariant,\n} from \"../../render/utils/resolve-dynamic-variants\"\nimport { calcChildStagger } from \"../utils/calc-child-stagger\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport { animateTarget } from \"./visual-element-target\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nexport function animateVariant(\n visualElement: VisualElement,\n variant: string,\n options: VisualElementAnimationOptions = {}\n): Promise<any> {\n const resolved = resolveVariant(\n visualElement,\n variant,\n getTypeCustom(visualElement, options.type)\n )\n\n const transition =\n options.transitionOverride ||\n (resolved?.transition ?? (visualElement.getDefaultTransition() || {}))\n\n const getAnimation = () =>\n Promise.all(\n resolved ? animateTarget(visualElement, resolved, options) : []\n )\n\n const getChildAnimations = (delay = 0) => {\n const { variantChildren } = visualElement\n const {\n delayChildren = 0,\n staggerChildren,\n staggerDirection,\n } = transition\n const animations: Promise<any>[] = []\n\n variantChildren?.forEach((child) => {\n child.notify(\"AnimationStart\", variant)\n animations.push(\n animateVariant(child, variant, {\n ...options,\n delay:\n delay +\n (typeof delayChildren === \"function\"\n ? 0\n : delayChildren) +\n calcChildStagger(\n variantChildren,\n child,\n delayChildren,\n staggerChildren,\n staggerDirection\n ),\n }).then(() => child.notify(\"AnimationComplete\", variant))\n )\n })\n\n return Promise.all(animations)\n }\n\n /**\n * when: \"beforeChildren\" | \"afterChildren\" runs this element's animation\n * and its children's in sequence.\n */\n const { when } = transition\n\n return when\n ? when === \"beforeChildren\"\n ? getAnimation().then(() => getChildAnimations())\n : getChildAnimations().then(getAnimation)\n : Promise.all([getAnimation(), getChildAnimations(options.delay)])\n}\n"],"names":[],"mappings":";;;;AASM,SAAU,cAAc,CAC1B,aAA4B,EAC5B,OAAe,EACf,UAAyC,EAAE,EAAA;AAE3C,IAAA,MAAM,QAAQ,GAAG,cAAc,CAC3B,aAAa,EACb,OAAO,EACP,aAAa,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,CAC7C;AAED,IAAA,MAAM,UAAU,GACZ,OAAO,CAAC,kBAAkB;AAC1B,SAAC,QAAQ,EAAE,UAAU,KAAK,aAAa,CAAC,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;IAE1E,MAAM,YAAY,GAAG,MACjB,OAAO,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 +4,11 @@ import { animateVariant } from './visual-element-variant.mjs';
|
|
|
4
4
|
|
|
5
5
|
function animateVisualElement(visualElement, definition, options = {}) {
|
|
6
6
|
visualElement.notify("AnimationStart", definition);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
else if (typeof definition === "string") {
|
|
13
|
-
animation = animateVariant(visualElement, definition, options);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const resolvedDefinition = typeof definition === "function"
|
|
17
|
-
? resolveVariant(visualElement, definition, options.custom)
|
|
18
|
-
: definition;
|
|
19
|
-
animation = Promise.all(animateTarget(visualElement, resolvedDefinition, options));
|
|
20
|
-
}
|
|
7
|
+
const animation = Array.isArray(definition)
|
|
8
|
+
? Promise.all(definition.map((variant) => animateVariant(visualElement, variant, options)))
|
|
9
|
+
: typeof definition === "string"
|
|
10
|
+
? animateVariant(visualElement, definition, options)
|
|
11
|
+
: Promise.all(animateTarget(visualElement, resolveVariant(visualElement, definition, options.custom), options));
|
|
21
12
|
return animation.then(() => {
|
|
22
13
|
visualElement.notify("AnimationComplete", definition);
|
|
23
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-element.mjs","sources":["../../../../src/animation/interfaces/visual-element.ts"],"sourcesContent":["import { resolveVariant } from \"../../render/utils/resolve-dynamic-variants\"\nimport type { AnimationDefinition } from \"../../node/types\"\nimport type { VisualElement } from \"../../render/VisualElement\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport { animateTarget } from \"./visual-element-target\"\nimport { animateVariant } from \"./visual-element-variant\"\n\nexport function animateVisualElement(\n visualElement: VisualElement,\n definition: AnimationDefinition,\n options: VisualElementAnimationOptions = {}\n) {\n visualElement.notify(\"AnimationStart\", definition)\n
|
|
1
|
+
{"version":3,"file":"visual-element.mjs","sources":["../../../../src/animation/interfaces/visual-element.ts"],"sourcesContent":["import { resolveVariant } from \"../../render/utils/resolve-dynamic-variants\"\nimport type { AnimationDefinition } from \"../../node/types\"\nimport type { VisualElement } from \"../../render/VisualElement\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport { animateTarget } from \"./visual-element-target\"\nimport { animateVariant } from \"./visual-element-variant\"\n\nexport function animateVisualElement(\n visualElement: VisualElement,\n definition: AnimationDefinition,\n options: VisualElementAnimationOptions = {}\n) {\n visualElement.notify(\"AnimationStart\", definition)\n\n const animation = Array.isArray(definition)\n ? Promise.all(\n definition.map((variant) =>\n animateVariant(visualElement, variant, options)\n )\n )\n : typeof definition === \"string\"\n ? animateVariant(visualElement, definition, options)\n : Promise.all(\n animateTarget(\n visualElement,\n resolveVariant(visualElement, definition, options.custom),\n options\n )\n )\n\n return animation.then(() => {\n visualElement.notify(\"AnimationComplete\", definition)\n })\n}\n"],"names":[],"mappings":";;;;AAOM,SAAU,oBAAoB,CAChC,aAA4B,EAC5B,UAA+B,EAC/B,UAAyC,EAAE,EAAA;AAE3C,IAAA,aAAa,CAAC,MAAM,CAAC,gBAAgB,EAAE,UAAU,CAAC;AAElD,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU;UACpC,OAAO,CAAC,GAAG,CACP,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,KACnB,cAAc,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAClD;AAEP,UAAE,OAAO,UAAU,KAAK;cACtB,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO;cACjD,OAAO,CAAC,GAAG,CACP,aAAa,CACT,aAAa,EACb,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,EACzD,OAAO,CACV,CACJ;AAEP,IAAA,OAAO,SAAS,CAAC,IAAI,CAAC,MAAK;AACvB,QAAA,aAAa,CAAC,MAAM,CAAC,mBAAmB,EAAE,UAAU,CAAC;AACzD,IAAA,CAAC,CAAC;AACN;;;;"}
|
|
@@ -56,7 +56,12 @@ class MotionValueState {
|
|
|
56
56
|
const onRemove = () => {
|
|
57
57
|
cancelOnChange();
|
|
58
58
|
render && !computed && this.cancel(render);
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A later set() of the same name has already removed this
|
|
61
|
+
* entry, so leave the one that replaced it.
|
|
62
|
+
*/
|
|
63
|
+
this.values.get(name)?.onRemove === onRemove &&
|
|
64
|
+
this.values.delete(name);
|
|
60
65
|
};
|
|
61
66
|
this.values.set(name, {
|
|
62
67
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { frame } from \"../frameloop/frame\"\nimport { Schedule } from \"../frameloop/types\"\nimport { MotionValue } from \"../value\"\n\ninterface Entry {\n value: MotionValue\n render?: VoidFunction\n onRemove: VoidFunction\n}\n\nexport class MotionValueState {\n /**\n * Transform keys bound to this state, in `transformPropOrder`, and\n * the value bound to each. Lets the transform builder visit only\n * bound transforms, reading each value directly.\n */\n transformKeys?: string[]\n transformValues?: Record<string, MotionValue>\n\n private values = new Map<string, Entry>()\n\n /**\n * Renders scheduled for the next flush, usually one or two (values\n * bound to the same computed render, e.g. `x` and `y` to `transform`,\n * share an entry). Tracked with a count rather than truncating the\n * array so no backing store is reallocated every frame. Kept per\n * state so pending writes can be flushed synchronously before the\n * subject is measured.\n */\n private pending: VoidFunction[] = []\n private numPending = 0\n\n /**\n * @param step - The frameloop step renders are scheduled in. Defaults\n * to `frame.render`. Effects that feed a render loop running in\n * `frame.render` (GPU scenes) should write in `frame.preRender`.\n */\n constructor(private step: Schedule = frame.render) {}\n\n /**\n * @param render - Writes the value to the subject. Renders read the\n * motion value directly rather than a cached copy, so there is one\n * place a value lives.\n * @param computed - A value already in this state (e.g. `transform`)\n * whose render should run whenever `value` changes.\n */\n set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue\n ): VoidFunction {\n this.values.get(name)?.onRemove()\n\n if (computed) {\n for (const entry of this.values.values()) {\n if (entry.value === computed) render = entry.render\n }\n }\n\n const onChange = () => render && this.schedule(render)\n\n /**\n * Values created ahead of a DOM read start out undefined and\n * have nothing to render until they're set.\n */\n value.get() !== undefined && onChange()\n\n const cancelOnChange = value.on(\"change\", onChange)\n\n const onRemove = () => {\n cancelOnChange()\n render && !computed && this.cancel(render)\n this.values.delete(name)\n }\n\n this.values.set(name, {\n value,\n render: computed ? undefined : render,\n onRemove,\n })\n\n return onRemove\n }\n\n get(name: string): MotionValue | undefined {\n return this.values.get(name)?.value\n }\n\n /**\n * Detach every value from this state and return them, so another\n * renderer can take them over. The state stays cached by its effect,\n * so the bound transforms are reset too rather than leaking into\n * values bound later.\n */\n release() {\n const values = new Map<string, MotionValue>()\n this.values.forEach((entry, name) => {\n values.set(name, entry.value)\n entry.onRemove()\n })\n this.transformKeys = this.transformValues = undefined\n return values\n }\n\n private schedule(render: VoidFunction) {\n const { pending, numPending } = this\n\n for (let i = 0; i < numPending; i++) {\n if (pending[i] === render) return\n }\n\n numPending || this.step(this.flush)\n\n pending[this.numPending++] = render\n }\n\n private cancel(render: VoidFunction) {\n const { pending } = this\n\n for (let i = 0; i < this.numPending; i++) {\n if (pending[i] === render) {\n pending[i] = pending[--this.numPending]\n return\n }\n }\n }\n\n /**\n * Run the pending renders. Resetting the count first means a render\n * scheduled while flushing lands in the next frame, as with the\n * frameloop itself.\n */\n flush = () => {\n const { pending, numPending } = this\n this.numPending = 0\n for (let i = 0; i < numPending; i++) pending[i]()\n }\n}\n"],"names":[],"mappings":";;MAUa,gBAAgB,CAAA;AAsBzB;;;;AAIG;IACH,WAAA,CAAoB,IAAA,GAAiB,KAAK,CAAC,MAAM,EAAA;QAA7B,IAAA,CAAA,IAAI,GAAJ,IAAI;AAlBhB,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,GAAG,EAAiB;AAEzC;;;;;;;AAOG;QACK,IAAA,CAAA,OAAO,GAAmB,EAAE;QAC5B,IAAA,CAAA,UAAU,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { frame } from \"../frameloop/frame\"\nimport { Schedule } from \"../frameloop/types\"\nimport { MotionValue } from \"../value\"\n\ninterface Entry {\n value: MotionValue\n render?: VoidFunction\n onRemove: VoidFunction\n}\n\nexport class MotionValueState {\n /**\n * Transform keys bound to this state, in `transformPropOrder`, and\n * the value bound to each. Lets the transform builder visit only\n * bound transforms, reading each value directly.\n */\n transformKeys?: string[]\n transformValues?: Record<string, MotionValue>\n\n private values = new Map<string, Entry>()\n\n /**\n * Renders scheduled for the next flush, usually one or two (values\n * bound to the same computed render, e.g. `x` and `y` to `transform`,\n * share an entry). Tracked with a count rather than truncating the\n * array so no backing store is reallocated every frame. Kept per\n * state so pending writes can be flushed synchronously before the\n * subject is measured.\n */\n private pending: VoidFunction[] = []\n private numPending = 0\n\n /**\n * @param step - The frameloop step renders are scheduled in. Defaults\n * to `frame.render`. Effects that feed a render loop running in\n * `frame.render` (GPU scenes) should write in `frame.preRender`.\n */\n constructor(private step: Schedule = frame.render) {}\n\n /**\n * @param render - Writes the value to the subject. Renders read the\n * motion value directly rather than a cached copy, so there is one\n * place a value lives.\n * @param computed - A value already in this state (e.g. `transform`)\n * whose render should run whenever `value` changes.\n */\n set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue\n ): VoidFunction {\n this.values.get(name)?.onRemove()\n\n if (computed) {\n for (const entry of this.values.values()) {\n if (entry.value === computed) render = entry.render\n }\n }\n\n const onChange = () => render && this.schedule(render)\n\n /**\n * Values created ahead of a DOM read start out undefined and\n * have nothing to render until they're set.\n */\n value.get() !== undefined && onChange()\n\n const cancelOnChange = value.on(\"change\", onChange)\n\n const onRemove = () => {\n cancelOnChange()\n render && !computed && this.cancel(render)\n /**\n * A later set() of the same name has already removed this\n * entry, so leave the one that replaced it.\n */\n this.values.get(name)?.onRemove === onRemove &&\n this.values.delete(name)\n }\n\n this.values.set(name, {\n value,\n render: computed ? undefined : render,\n onRemove,\n })\n\n return onRemove\n }\n\n get(name: string): MotionValue | undefined {\n return this.values.get(name)?.value\n }\n\n /**\n * Detach every value from this state and return them, so another\n * renderer can take them over. The state stays cached by its effect,\n * so the bound transforms are reset too rather than leaking into\n * values bound later.\n */\n release() {\n const values = new Map<string, MotionValue>()\n this.values.forEach((entry, name) => {\n values.set(name, entry.value)\n entry.onRemove()\n })\n this.transformKeys = this.transformValues = undefined\n return values\n }\n\n private schedule(render: VoidFunction) {\n const { pending, numPending } = this\n\n for (let i = 0; i < numPending; i++) {\n if (pending[i] === render) return\n }\n\n numPending || this.step(this.flush)\n\n pending[this.numPending++] = render\n }\n\n private cancel(render: VoidFunction) {\n const { pending } = this\n\n for (let i = 0; i < this.numPending; i++) {\n if (pending[i] === render) {\n pending[i] = pending[--this.numPending]\n return\n }\n }\n }\n\n /**\n * Run the pending renders. Resetting the count first means a render\n * scheduled while flushing lands in the next frame, as with the\n * frameloop itself.\n */\n flush = () => {\n const { pending, numPending } = this\n this.numPending = 0\n for (let i = 0; i < numPending; i++) pending[i]()\n }\n}\n"],"names":[],"mappings":";;MAUa,gBAAgB,CAAA;AAsBzB;;;;AAIG;IACH,WAAA,CAAoB,IAAA,GAAiB,KAAK,CAAC,MAAM,EAAA;QAA7B,IAAA,CAAA,IAAI,GAAJ,IAAI;AAlBhB,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,GAAG,EAAiB;AAEzC;;;;;;;AAOG;QACK,IAAA,CAAA,OAAO,GAAmB,EAAE;QAC5B,IAAA,CAAA,UAAU,GAAG,CAAC;AAuGtB;;;;AAIG;QACH,IAAA,CAAA,KAAK,GAAG,MAAK;AACT,YAAA,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI;AACpC,YAAA,IAAI,CAAC,UAAU,GAAG,CAAC;YACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,E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ffect(addStyleValue, {
|
|
|
92
92
|
});
|
|
93
93
|
const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
|
|
94
94
|
|
|
95
|
-
export { addStyleValue, readStyleValue, styleEffect, styleSubjectEffect };
|
|
95
|
+
export { addStyleValue, originProps, readStyleValue, styleEffect, styleSubjectEffect };
|
|
96
96
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { readTransformValue } from \"../../render/dom/parse-transform\"\nimport {\n transformPropOrder,\n transformProps,\n} from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { readTransformValue } from \"../../render/dom/parse-transform\"\nimport {\n transformPropOrder,\n transformProps,\n} from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\nexport const originProps = new Set([\"originX\", \"originY\", \"originZ\"])\n\n/**\n * A bound value in its default unit, e.g. `originX: 50` -> `\"50%\"`.\n */\nconst styleValue = (state: MotionValueState, key: string) =>\n getValueAsType(state.get(key)?.get(), numberValueTypes[key])\n\nexport const addStyleValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n let render: VoidFunction | undefined = undefined\n let computed: MotionValue | undefined = undefined\n\n if (transformProps.has(key)) {\n if (key !== \"pathRotation\") {\n const keys = (state.transformKeys ??= [])\n ;(state.transformValues ??= {})[key] = value\n\n if (!keys.includes(key)) {\n keys.push(key)\n keys.sort(\n (a, b) =>\n transformPropOrder.indexOf(a) -\n transformPropOrder.indexOf(b)\n )\n }\n }\n\n if (!state.get(\"transform\")) {\n // If this is an HTML element, we need to set the transform-box to fill-box\n // to normalise the transform relative to the element's bounding box\n if (!isHTMLElement(element) && !state.get(\"transformBox\")) {\n addStyleValue(\n element,\n state,\n \"transformBox\",\n new MotionValue(\"fill-box\")\n )\n }\n\n state.set(\"transform\", new MotionValue(\"none\"), () => {\n element.style.transform = buildTransform(state)\n })\n }\n\n computed = state.get(\"transform\")\n } else if (originProps.has(key)) {\n if (!state.get(\"transformOrigin\")) {\n state.set(\"transformOrigin\", new MotionValue(\"\"), () => {\n const originX = styleValue(state, \"originX\") ?? \"50%\"\n const originY = styleValue(state, \"originY\") ?? \"50%\"\n const originZ = styleValue(state, \"originZ\") ?? 0\n element.style.transformOrigin = `${originX} ${originY} ${originZ}`\n })\n }\n\n computed = state.get(\"transformOrigin\")\n } else if (isCSSVar(key)) {\n render = () => {\n element.style.setProperty(key, value.get() as string)\n }\n } else {\n render = () => {\n element.style[key as any] = getValueAsType(\n value.get(),\n numberValueTypes[key]\n ) as string\n }\n }\n\n return state.set(key, value, render, computed)\n}\n\nexport type StyleSubject = HTMLElement | SVGElement\n\nconst isStyleSubject = (subject: unknown): subject is StyleSubject =>\n isHTMLElement(subject) || isSVGElement(subject)\n\n/**\n * Reads the current value of a style from the element, as the initial\n * keyframe when `animate()` targets an element via this effect. Transforms\n * are parsed out of the computed matrix; everything else is the computed\n * style. Units aren't converted to match the target keyframes. A style\n * the browser can't report is 0, as a VisualElement reports it.\n */\nexport const readStyleValue = (element: StyleSubject, key: string) => {\n if (transformProps.has(key)) {\n return readTransformValue(element as HTMLElement, key)\n }\n\n const computedStyle = getComputedStyle(element)\n const value = isCSSVar(key)\n ? computedStyle.getPropertyValue(key)\n : computedStyle[key as any]\n\n return (typeof value === \"string\" && value.trim()) || 0\n}\n\n/**\n * The per-element effect `animate()` binds through, so HTML values share\n * state with a direct `styleEffect()` call. The exported `styleEffect`\n * is this wrapped to also accept selectors.\n */\nexport const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {\n test: isStyleSubject,\n read: readStyleValue,\n})\n\nexport const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect)\n"],"names":[],"mappings":";;;;;;;;;;;;AAgBO,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;AAEpE;;AAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAuB,EAAE,GAAW,KACpD,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAEzD,MAAM,aAAa,GAAG,CACzB,OAAiC,EACjC,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,IAAI,MAAM,GAA6B,SAAS;IAChD,IAAI,QAAQ,GAA4B,SAAS;AAEjD,IAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,QAAA,IAAI,GAAG,KAAK,cAAc,EAAE;AACxB,YAAA,MAAM,IAAI,IAAI,KAAK,CAAC,aAAa,KAAnB,KAAK,CAAC,aAAa,GAAK,EAAE,EAAC;AACxC,YAAA,CAAC,KAAK,CAAC,eAAe,KAArB,KAAK,CAAC,eAAe,GA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AAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;AAC3D;AAEA;;;;AAIG;MACU,kBAAkB,iBAAiB,YAAY,CAAC,aAAa,EAAE;AACxE,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,IAAI,EAAE,cAAc;AACvB,CAAA;AAEM,MAAM,WAAW,iBAAiB,oBAAoB,CAAC,kBAAkB;;;;"}
|
|
@@ -6,7 +6,7 @@ import { isSVGElement } from '../../utils/is-svg-element.mjs';
|
|
|
6
6
|
import { MotionValue } from '../../value/index.mjs';
|
|
7
7
|
import { numberValueTypes } from '../../value/types/maps/number.mjs';
|
|
8
8
|
import { addAttrValue } from '../attr/index.mjs';
|
|
9
|
-
import { addStyleValue, readStyleValue } from '../style/index.mjs';
|
|
9
|
+
import { originProps, addStyleValue, readStyleValue } from '../style/index.mjs';
|
|
10
10
|
import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
|
|
11
11
|
import { createEffect } from '../utils/create-effect.mjs';
|
|
12
12
|
import { frame } from '../../frameloop/frame.mjs';
|
|
@@ -39,24 +39,35 @@ const addSVGValue = (element, state, key, value) => {
|
|
|
39
39
|
else if (key.startsWith("attr")) {
|
|
40
40
|
return addAttrValue(element, state, key, value, convertAttrKey(key));
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Transforms and origins aren't CSS properties (bar `x`/`y` in some
|
|
44
|
+
* browsers), so check them by name rather than `key in element.style`.
|
|
45
|
+
*/
|
|
46
|
+
const handler = transformProps.has(key) ||
|
|
47
|
+
originProps.has(key) ||
|
|
48
|
+
isCSSVar(key) ||
|
|
49
|
+
key in element.style
|
|
50
|
+
? addStyleValue
|
|
51
|
+
: addAttrValue;
|
|
43
52
|
return handler(element, state, key, value);
|
|
44
53
|
};
|
|
45
54
|
/**
|
|
46
55
|
* Reads the current value of `key` from an SVG element as the origin of
|
|
47
56
|
* an animation, as the SVG VisualElement does: transforms start from
|
|
48
57
|
* their defaults, CSS variables and the few CSS-only properties come from
|
|
49
|
-
* computed style
|
|
50
|
-
* and everything else is read from the
|
|
51
|
-
* (`strokeWidth` -> `stroke-width`) or, failing
|
|
52
|
-
* (`baseFrequency`).
|
|
58
|
+
* computed style, falling back to the attribute when that's empty (e.g.
|
|
59
|
+
* the element isn't rendered), and everything else is read from the
|
|
60
|
+
* attribute, dash-cased (`strokeWidth` -> `stroke-width`) or, failing
|
|
61
|
+
* that, as written (`baseFrequency`).
|
|
53
62
|
*/
|
|
54
63
|
const readSVGValue = (element, key) => {
|
|
55
64
|
if (transformProps.has(key)) {
|
|
56
65
|
return numberValueTypes[key]?.default || 0;
|
|
57
66
|
}
|
|
58
67
|
if (isCSSVar(key) || cssStyleProperties.includes(key)) {
|
|
59
|
-
return readStyleValue(element, key)
|
|
68
|
+
return (readStyleValue(element, key) ||
|
|
69
|
+
element.getAttribute(camelToDash(key)) ||
|
|
70
|
+
0);
|
|
60
71
|
}
|
|
61
72
|
key = convertAttrKey(key);
|
|
62
73
|
return (element.getAttribute(camelToDash(key)) ??
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/svg/index.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { cssStyleProperties } from \"../../render/svg/utils/build-attrs\"\nimport { transformProps } from \"../../render/utils/keys-transform\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { addAttrValue } from \"../attr\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { addStyleValue, readStyleValue } from \"../style\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction addSVGPathValue(\n element: SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) {\n frame.render(() => element.setAttribute(\"pathLength\", \"1\"))\n\n if (key === \"pathOffset\") {\n return state.set(key, value, () => {\n // Use unitless value to avoid Safari zoom bug\n const offset = value.get()\n element.setAttribute(\"stroke-dashoffset\", `${-offset}`)\n })\n } else {\n if (!state.get(\"stroke-dasharray\")) {\n state.set(\"stroke-dasharray\", new MotionValue(\"1 1\"), () => {\n const pathLength = state.get(\"pathLength\")?.get() ?? 1\n const pathSpacing = state.get(\"pathSpacing\")?.get()\n\n // Use unitless values to avoid Safari zoom bug\n element.setAttribute(\n \"stroke-dasharray\",\n `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`\n )\n })\n }\n\n return state.set(key, value, undefined, state.get(\"stroke-dasharray\"))\n }\n}\n\nexport const addSVGValue = (\n element: SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n if (key.startsWith(\"path\")) {\n return addSVGPathValue(element, state, key, value)\n } else if (key.startsWith(\"attr\")) {\n return addAttrValue(element, state, key, value, convertAttrKey(key))\n }\n\n const handler =\n
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/svg/index.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { cssStyleProperties } from \"../../render/svg/utils/build-attrs\"\nimport { transformProps } from \"../../render/utils/keys-transform\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { addAttrValue } from \"../attr\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { addStyleValue, originProps, readStyleValue } from \"../style\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction addSVGPathValue(\n element: SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) {\n frame.render(() => element.setAttribute(\"pathLength\", \"1\"))\n\n if (key === \"pathOffset\") {\n return state.set(key, value, () => {\n // Use unitless value to avoid Safari zoom bug\n const offset = value.get()\n element.setAttribute(\"stroke-dashoffset\", `${-offset}`)\n })\n } else {\n if (!state.get(\"stroke-dasharray\")) {\n state.set(\"stroke-dasharray\", new MotionValue(\"1 1\"), () => {\n const pathLength = state.get(\"pathLength\")?.get() ?? 1\n const pathSpacing = state.get(\"pathSpacing\")?.get()\n\n // Use unitless values to avoid Safari zoom bug\n element.setAttribute(\n \"stroke-dasharray\",\n `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`\n )\n })\n }\n\n return state.set(key, value, undefined, state.get(\"stroke-dasharray\"))\n }\n}\n\nexport const addSVGValue = (\n element: SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n if (key.startsWith(\"path\")) {\n return addSVGPathValue(element, state, key, value)\n } else if (key.startsWith(\"attr\")) {\n return addAttrValue(element, state, key, value, convertAttrKey(key))\n }\n\n /**\n * Transforms and origins aren't CSS properties (bar `x`/`y` in some\n * browsers), so check them by name rather than `key in element.style`.\n */\n const handler =\n transformProps.has(key) ||\n originProps.has(key) ||\n isCSSVar(key) ||\n key in element.style\n ? addStyleValue\n : addAttrValue\n return handler(element, state, key, value)\n}\n\n/**\n * Reads the current value of `key` from an SVG element as the origin of\n * an animation, as the SVG VisualElement does: transforms start from\n * their defaults, CSS variables and the few CSS-only properties come from\n * computed style, falling back to the attribute when that's empty (e.g.\n * the element isn't rendered), and everything else is read from the\n * attribute, dash-cased (`strokeWidth` -> `stroke-width`) or, failing\n * that, as written (`baseFrequency`).\n */\nexport const readSVGValue = (element: SVGElement, key: string) => {\n if (transformProps.has(key)) {\n return numberValueTypes[key]?.default || 0\n }\n\n if (isCSSVar(key) || cssStyleProperties.includes(key)) {\n return (\n readStyleValue(element, key) ||\n element.getAttribute(camelToDash(key)) ||\n 0\n )\n }\n\n key = convertAttrKey(key)\n\n return (\n element.getAttribute(camelToDash(key)) ??\n element.getAttribute(key) ??\n undefined\n )\n}\n\n/**\n * The per-element effect `animate()` binds through, so SVG values share\n * state with a direct `svgEffect()` call.\n */\nexport const svgSubjectEffect = /*@__PURE__*/ createEffect(addSVGValue, {\n test: isSVGElement,\n read: readSVGValue,\n})\n\nexport const svgEffect = /*@__PURE__*/ createSelectorEffect(svgSubjectEffect)\n\nfunction convertAttrKey(key: string) {\n return key.replace(/^attr([A-Z])/, (_, firstChar) =>\n firstChar.toLowerCase()\n )\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAcA,SAAS,eAAe,CACpB,OAAmB,EACnB,KAAuB,EACvB,GAAW,EACX,KAAkB,EAAA;AAElB,IAAA,KAAK,CAAC,MAAM,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AAE3D,IAAA,IAAI,GAAG,KAAK,YAAY,EAAE;QACtB,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAK;;AAE9B,YAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE;YAC1B,OAAO,CAAC,YAAY,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAA,CAAE,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;SAAO;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE;AAChC,YAAA,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,MAAK;AACvD,gBAAA,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC;gBACtD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE;;AAGnD,gBAAA,OAAO,CAAC,YAAY,CAChB,kBAAkB,EAClB,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,WAAW,IAAI,CAAC,GAAG,MAAM,CAAC,U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AA,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AACtC,YAAA,CAAC;IAET;AAEA,IAAA,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC;IAEzB,QACI,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AACtC,QAAA,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC;AACzB,QAAA,SAAS;AAEjB;AAEA;;;AAGG;MACU,gBAAgB,iBAAiB,YAAY,CAAC,WAAW,EAAE;AACpE,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,IAAI,EAAE,YAAY;AACrB,CAAA;AAEM,MAAM,SAAS,iBAAiB,oBAAoB,CAAC,gBAAgB;AAE5E,SAAS,cAAc,CAAC,GAAW,EAAA;AAC/B,IAAA,OAAO,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,SAAS,KAC5C,SAAS,CAAC,WAAW,EAAE,CAC1B;AACL;;;;"}
|
package/dist/es/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ export { animateElement, handOffElementState } from './animation/animate/element
|
|
|
50
50
|
export { addAttrValue, attrEffect } from './effects/attr/index.mjs';
|
|
51
51
|
export { MotionValueState } from './effects/MotionValueState.mjs';
|
|
52
52
|
export { propEffect } from './effects/prop/index.mjs';
|
|
53
|
-
export { addStyleValue, readStyleValue, styleEffect, styleSubjectEffect } from './effects/style/index.mjs';
|
|
53
|
+
export { addStyleValue, originProps, readStyleValue, styleEffect, styleSubjectEffect } from './effects/style/index.mjs';
|
|
54
54
|
export { addSVGValue, readSVGValue, svgEffect, svgSubjectEffect } from './effects/svg/index.mjs';
|
|
55
55
|
export { createEffect } from './effects/utils/create-effect.mjs';
|
|
56
56
|
export { createRenderBatcher } from './frameloop/batcher.mjs';
|
|
@@ -14,7 +14,6 @@ import { isControllingVariants, isVariantNode } from './utils/is-controlling-var
|
|
|
14
14
|
import { transformProps } from './utils/keys-transform.mjs';
|
|
15
15
|
import { updateMotionValuesFromProps } from './utils/motion-values.mjs';
|
|
16
16
|
import { initPrefersReducedMotion } from './utils/reduced-motion/index.mjs';
|
|
17
|
-
import { resolveVariantFromProps } from './utils/resolve-variants.mjs';
|
|
18
17
|
import { hasReducedMotionListener, prefersReducedMotion } from './utils/reduced-motion/state.mjs';
|
|
19
18
|
import { frame, cancelFrame } from '../frameloop/frame.mjs';
|
|
20
19
|
|
|
@@ -193,8 +192,20 @@ class VisualElement {
|
|
|
193
192
|
if (this.projection && !this.projection.instance) {
|
|
194
193
|
this.projection.mount(instance);
|
|
195
194
|
}
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Join the closest variant node above, so its variant changes
|
|
197
|
+
* propagate here, unless inherit={false} cuts the chain.
|
|
198
|
+
*/
|
|
199
|
+
if (this.isVariantNode && !this.isControllingVariants) {
|
|
200
|
+
let node = this;
|
|
201
|
+
do
|
|
202
|
+
node = node.props.inherit !== false && node.parent;
|
|
203
|
+
while (node && !node.isVariantNode);
|
|
204
|
+
if (node) {
|
|
205
|
+
const { variantChildren } = node;
|
|
206
|
+
variantChildren.add(this);
|
|
207
|
+
this.removeFromVariantTree = () => variantChildren.delete(this);
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
210
|
this.values.forEach((value, key) => this.bindToMotionValue(key, value));
|
|
200
211
|
/**
|
|
@@ -304,9 +315,11 @@ class VisualElement {
|
|
|
304
315
|
}
|
|
305
316
|
sortNodePosition(other) {
|
|
306
317
|
/**
|
|
307
|
-
* If
|
|
318
|
+
* If either node isn't mounted, or they aren't even of the same type,
|
|
319
|
+
* we can't compare their document order.
|
|
308
320
|
*/
|
|
309
321
|
if (!this.current ||
|
|
322
|
+
!other.current ||
|
|
310
323
|
!this.sortInstanceNodePosition ||
|
|
311
324
|
this.type !== other.type) {
|
|
312
325
|
return 0;
|
|
@@ -412,24 +425,6 @@ class VisualElement {
|
|
|
412
425
|
getTransformPagePoint() {
|
|
413
426
|
return this.props.transformPagePoint;
|
|
414
427
|
}
|
|
415
|
-
getClosestVariantNode() {
|
|
416
|
-
return this.isVariantNode
|
|
417
|
-
? this
|
|
418
|
-
: this.parent
|
|
419
|
-
? this.parent.getClosestVariantNode()
|
|
420
|
-
: undefined;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Add a child visual element to our set of children.
|
|
424
|
-
*/
|
|
425
|
-
addVariantChild(child) {
|
|
426
|
-
const closestVariantNode = this.getClosestVariantNode();
|
|
427
|
-
if (closestVariantNode) {
|
|
428
|
-
closestVariantNode.variantChildren &&
|
|
429
|
-
closestVariantNode.variantChildren.add(child);
|
|
430
|
-
return () => closestVariantNode.variantChildren.delete(child);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
428
|
/**
|
|
434
429
|
* Add a motion value and bind it to this visual element.
|
|
435
430
|
*/
|
|
@@ -524,41 +519,6 @@ class VisualElement {
|
|
|
524
519
|
setBaseTarget(key, value) {
|
|
525
520
|
this.baseTarget[key] = value;
|
|
526
521
|
}
|
|
527
|
-
/**
|
|
528
|
-
* Find the base target for a value thats been removed from all animation
|
|
529
|
-
* props.
|
|
530
|
-
*/
|
|
531
|
-
getBaseTarget(key) {
|
|
532
|
-
const { initial } = this.props;
|
|
533
|
-
let valueFromInitial;
|
|
534
|
-
if (typeof initial === "string" || typeof initial === "object") {
|
|
535
|
-
const variant = resolveVariantFromProps(this.props, initial, this.presenceContext?.custom);
|
|
536
|
-
if (variant) {
|
|
537
|
-
valueFromInitial = variant[key];
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* If this value still exists in the current initial variant, read that.
|
|
542
|
-
*/
|
|
543
|
-
if (initial && valueFromInitial !== undefined) {
|
|
544
|
-
return valueFromInitial;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Alternatively, if this VisualElement config has defined a getBaseTarget
|
|
548
|
-
* so we can read the value from an alternative source, try that.
|
|
549
|
-
*/
|
|
550
|
-
const target = this.getBaseTargetFromProps(this.props, key);
|
|
551
|
-
if (target !== undefined && !isMotionValue(target))
|
|
552
|
-
return target;
|
|
553
|
-
/**
|
|
554
|
-
* If the value was initially defined on initial, but it doesn't any more,
|
|
555
|
-
* return undefined. Otherwise return the value as initially read from the DOM.
|
|
556
|
-
*/
|
|
557
|
-
return this.initialValues[key] !== undefined &&
|
|
558
|
-
valueFromInitial === undefined
|
|
559
|
-
? undefined
|
|
560
|
-
: this.baseTarget[key];
|
|
561
|
-
}
|
|
562
522
|
on(eventName, callback) {
|
|
563
523
|
if (!this.events[eventName]) {
|
|
564
524
|
this.events[eventName] = new SubscriptionManager();
|