motion-dom 13.1.1-alpha.0 → 13.2.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 +152 -150
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/animate/effects.mjs +48 -0
- package/dist/es/animation/animate/effects.mjs.map +1 -0
- package/dist/es/animation/generators/inertia.mjs +8 -6
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +43 -58
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/animation/generators/utils/calc-duration.mjs +5 -4
- package/dist/es/animation/generators/utils/calc-duration.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +2 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/waapi/supports/waapi.mjs +3 -6
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs +1 -12
- package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +8 -2
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +4 -11
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +0 -5
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs +6 -3
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/index.mjs +4 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +8 -13
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +1 -3
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/projection/utils/has-transform.mjs +1 -7
- package/dist/es/projection/utils/has-transform.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +2 -5
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/html/utils/build-styles.mjs +12 -10
- package/dist/es/render/html/utils/build-styles.mjs.map +1 -1
- package/dist/es/render/html/utils/build-transform.mjs +0 -5
- package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/index.d.ts +72 -9
- package/dist/motion-dom.dev.js +152 -150
- 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 +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../animation/types\"\nimport { cancelFrame, frame } from \"../frameloop/frame\"\nimport { MotionValue } from \"../value\"\nimport { numberValueTypes } from \"../value/types/maps/number\"\nimport { getValueAsType } from \"../value/types/utils/get-as-type\"\n\nexport class MotionValueState {\n latest: { [name: string]: AnyResolvedKeyframe } = {}\n\n private values = new Map<\n string,\n { value: MotionValue; onRemove: VoidFunction }\n >()\n\n set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue,\n useDefaultValueType = true\n ) {\n const existingValue = this.values.get(name)\n\n if (existingValue) {\n existingValue.onRemove()\n }\n\n const onChange = () => {\n const v = value.get()\n\n if (useDefaultValueType) {\n this.latest[name] = getValueAsType(v, numberValueTypes[name])\n } else {\n this.latest[name] = v\n }\n\n render &&
|
|
1
|
+
{"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../animation/types\"\nimport { cancelFrame, frame } from \"../frameloop/frame\"\nimport { Schedule } from \"../frameloop/types\"\nimport { MotionValue } from \"../value\"\nimport { numberValueTypes } from \"../value/types/maps/number\"\nimport { getValueAsType } from \"../value/types/utils/get-as-type\"\n\nexport class MotionValueState {\n latest: { [name: string]: AnyResolvedKeyframe } = {}\n\n private values = new Map<\n string,\n { value: MotionValue; onRemove: VoidFunction }\n >()\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 set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue,\n useDefaultValueType = true\n ): VoidFunction {\n const existingValue = this.values.get(name)\n\n if (existingValue) {\n existingValue.onRemove()\n }\n\n const onChange = () => {\n const v = value.get()\n\n if (useDefaultValueType) {\n this.latest[name] = getValueAsType(v, numberValueTypes[name])\n } else {\n this.latest[name] = v\n }\n\n render && this.step(render)\n }\n\n onChange()\n\n const cancelOnChange = value.on(\"change\", onChange)\n\n computed && value.addDependent(computed)\n\n const remove = () => {\n cancelOnChange()\n render && cancelFrame(render)\n this.values.delete(name)\n computed && value.removeDependent(computed)\n }\n\n this.values.set(name, { value, onRemove: remove })\n\n return remove\n }\n\n get(name: string): MotionValue | undefined {\n return this.values.get(name)?.value\n }\n}\n"],"names":[],"mappings":";;;;MAOa,gBAAgB,CAAA;AAQzB;;;;AAIG;IACH,WAAA,CAAoB,IAAA,GAAiB,KAAK,CAAC,MAAM,EAAA;QAA7B,IAAA,CAAA,IAAI,GAAJ,IAAI;QAZxB,IAAA,CAAA,MAAM,GAA4C,EAAE;AAE5C,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,GAAG,EAGrB;IAOiD;IAEpD,GAAG,CACC,IAAY,EACZ,KAAkB,EAClB,MAAqB,EACrB,QAAsB,EACtB,mBAAmB,GAAG,IAAI,EAAA;QAE1B,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;QAE3C,IAAI,aAAa,EAAE;YACf,aAAa,CAAC,QAAQ,EAAE;QAC5B;QAEA,MAAM,QAAQ,GAAG,MAAK;AAClB,YAAA,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE;YAErB,IAAI,mBAAmB,EAAE;AACrB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACjE;iBAAO;AACH,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;YACzB;AAEA,YAAA,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AAC/B,QAAA,CAAC;AAED,QAAA,QAAQ,EAAE;QAEV,MAAM,cAAc,GAAG,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;AAEnD,QAAA,QAAQ,IAAI,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC;QAExC,MAAM,MAAM,GAAG,MAAK;AAChB,YAAA,cAAc,EAAE;AAChB,YAAA,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC;AAC7B,YAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AACxB,YAAA,QAAQ,IAAI,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC;AAC/C,QAAA,CAAC;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAElD,QAAA,OAAO,MAAM;IACjB;AAEA,IAAA,GAAG,CAAC,IAAY,EAAA;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK;IACvC;AACH;;;;"}
|
|
@@ -7,28 +7,21 @@ import { createEffect } from '../utils/create-effect.mjs';
|
|
|
7
7
|
import { buildTransform } from './transform.mjs';
|
|
8
8
|
|
|
9
9
|
const originProps = new Set(["originX", "originY", "originZ"]);
|
|
10
|
-
/**
|
|
11
|
-
* Internal key for the computed transform channel. The user "transform"
|
|
12
|
-
* value now composes into this channel, so it can't share the "transform"
|
|
13
|
-
* key. Prefixed with $ so it can never collide with a real style key
|
|
14
|
-
* (like "transformStyle", which is the transform-style CSS property).
|
|
15
|
-
*/
|
|
16
|
-
const computedTransform = "$transform";
|
|
17
10
|
const addStyleValue = (element, state, key, value) => {
|
|
18
11
|
let render = undefined;
|
|
19
12
|
let computed = undefined;
|
|
20
|
-
if (transformProps.has(key)
|
|
21
|
-
if (!state.get(
|
|
13
|
+
if (transformProps.has(key)) {
|
|
14
|
+
if (!state.get("transform")) {
|
|
22
15
|
// If this is an HTML element, we need to set the transform-box to fill-box
|
|
23
16
|
// to normalise the transform relative to the element's bounding box
|
|
24
17
|
if (!isHTMLElement(element) && !state.get("transformBox")) {
|
|
25
18
|
addStyleValue(element, state, "transformBox", new MotionValue("fill-box"));
|
|
26
19
|
}
|
|
27
|
-
state.set(
|
|
20
|
+
state.set("transform", new MotionValue("none"), () => {
|
|
28
21
|
element.style.transform = buildTransform(state);
|
|
29
22
|
});
|
|
30
23
|
}
|
|
31
|
-
computed = state.get(
|
|
24
|
+
computed = state.get("transform");
|
|
32
25
|
}
|
|
33
26
|
else if (originProps.has(key)) {
|
|
34
27
|
if (!state.get("transformOrigin")) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { transformProps } from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\nconst originProps = new Set([\"originX\", \"originY\", \"originZ\"])\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { transformProps } from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\nconst originProps = new Set([\"originX\", \"originY\", \"originZ\"])\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 (!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 = state.latest.originX ?? \"50%\"\n const originY = state.latest.originY ?? \"50%\"\n const originZ = state.latest.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, state.latest[key] as string)\n }\n } else {\n render = () => {\n element.style[key as any] = state.latest[key] as string\n }\n }\n\n return state.set(key, value, render, computed)\n}\n\nexport const styleEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addStyleValue)\n)\n"],"names":[],"mappings":";;;;;;;;AASA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEvD,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;QACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;;;AAGzB,YAAA,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;AACvD,gBAAA,aAAa,CACT,OAAO,EACP,KAAK,EACL,cAAc,EACd,IAAI,WAAW,CAAC,UAAU,CAAC,CAC9B;YACL;AAEA,YAAA,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,MAAK;gBACjD,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC;AACnD,YAAA,CAAC,CAAC;QACN;AAEA,QAAA,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;IACrC;AAAO,SAAA,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAC7B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;AAC/B,YAAA,KAAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,WAAW,CAAC,EAAE,CAAC,EAAE,MAAK;gBACnD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK;gBAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK;gBAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC;AACzC,gBAAA,OAAO,CAAC,KAAK,CAAC,eAAe,GAAG,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE;AACtE,YAAA,CAAC,CAAC;QACN;AAEA,QAAA,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAC3C;AAAO,SAAA,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,GAAG,MAAK;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAW,CAAC;AAC/D,QAAA,CAAC;IACL;SAAO;QACH,MAAM,GAAG,MAAK;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,GAAU,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAW;AAC3D,QAAA,CAAC;IACL;AAEA,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC;AAClD;AAEO,MAAM,WAAW,iBAAiB,oBAAoB;AACzD,cAAc,YAAY,CAAC,aAAa,CAAC;;;;"}
|
|
@@ -41,11 +41,6 @@ function buildTransform(state) {
|
|
|
41
41
|
? `${pathRotation}deg`
|
|
42
42
|
: pathRotation}) `;
|
|
43
43
|
}
|
|
44
|
-
const userTransform = state.latest.transform;
|
|
45
|
-
if (userTransform && userTransform !== "none") {
|
|
46
|
-
transformIsDefault = false;
|
|
47
|
-
transform += userTransform;
|
|
48
|
-
}
|
|
49
44
|
return transformIsDefault ? "none" : transform.trim();
|
|
50
45
|
}
|
|
51
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../../render/utils/keys-transform\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < transformPropOrder.length; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = state.latest[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n const parsed = parseFloat(value)\n valueIsDefault = key.startsWith(\"scale\") ? parsed === 1 : parsed === 0\n }\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n transform += `${transformName}(${value}) `\n }\n }\n\n // See build-transform.ts: additive `rotate()` so user `rotate` isn't\n // clobbered. Not a `transformPropOrder` slot.\n const pathRotation = state.latest.pathRotation\n if (pathRotation) {\n transformIsDefault = false\n transform += `rotate(${\n typeof pathRotation === \"number\"\n ? `${pathRotation}deg`\n : pathRotation\n }) `\n }\n\n
|
|
1
|
+
{"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../../render/utils/keys-transform\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < transformPropOrder.length; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = state.latest[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n const parsed = parseFloat(value)\n valueIsDefault = key.startsWith(\"scale\") ? parsed === 1 : parsed === 0\n }\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n transform += `${transformName}(${value}) `\n }\n }\n\n // See build-transform.ts: additive `rotate()` so user `rotate` isn't\n // clobbered. Not a `transformPropOrder` slot.\n const pathRotation = state.latest.pathRotation\n if (pathRotation) {\n transformIsDefault = false\n transform += `rotate(${\n typeof pathRotation === \"number\"\n ? `${pathRotation}deg`\n : pathRotation\n }) `\n }\n\n return transformIsDefault ? \"none\" : transform.trim()\n}\n"],"names":[],"mappings":";;AAGA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC;AAEK,SAAU,cAAc,CAAC,KAAuB,EAAA;IAClD,IAAI,SAAS,GAAG,EAAE;IAClB,IAAI,kBAAkB,GAAG,IAAI;AAE7B;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAgC;QAChE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE;QAEzB,IAAI,cAAc,GAAG,IAAI;AACzB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,cAAc,GAAG,KAAK,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChE;aAAO;AACH,YAAA,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;AAChC,YAAA,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC;QAC1E;QAEA,IAAI,CAAC,cAAc,EAAE;YACjB,kBAAkB,GAAG,KAAK;YAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG;AAChD,YAAA,SAAS,IAAI,CAAA,EAAG,aAAa,CAAA,CAAA,EAAI,KAAK,IAAI;QAC9C;IACJ;;;AAIA,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY;IAC9C,IAAI,YAAY,EAAE;QACd,kBAAkB,GAAG,KAAK;AAC1B,QAAA,SAAS,IAAI,CAAA,OAAA,EACT,OAAO,YAAY,KAAK;cAClB,CAAA,EAAG,YAAY,CAAA,GAAA;cACf,YACV,CAAA,EAAA,CAAI;IACR;AAEA,IAAA,OAAO,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE;AACzD;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MotionValueState } from '../MotionValueState.mjs';
|
|
2
2
|
|
|
3
|
-
function createEffect(addValue) {
|
|
3
|
+
function createEffect(addValue, { step, ...options } = {}) {
|
|
4
4
|
const stateCache = new WeakMap();
|
|
5
|
-
|
|
6
|
-
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
5
|
+
const effect = (subject, values) => {
|
|
6
|
+
const state = stateCache.get(subject) ?? new MotionValueState(step);
|
|
7
7
|
stateCache.set(subject, state);
|
|
8
8
|
const subscriptions = [];
|
|
9
9
|
for (const key in values) {
|
|
@@ -16,6 +16,9 @@ function createEffect(addValue) {
|
|
|
16
16
|
cancel();
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
+
return Object.assign(effect, options, {
|
|
20
|
+
get: (subject, key) => stateCache.get(subject)?.get(key),
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export { createEffect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-effect.mjs","sources":["../../../../src/effects/utils/create-effect.ts"],"sourcesContent":["import { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nexport
|
|
1
|
+
{"version":3,"file":"create-effect.mjs","sources":["../../../../src/effects/utils/create-effect.ts"],"sourcesContent":["import {\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n} from \"../../animation/types\"\nimport { Schedule } from \"../../frameloop/types\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\n\n/**\n * Returns true if the effect knows how to write to `subject`.\n */\nexport type EffectTest<Subject extends object> = (\n subject: unknown\n) => subject is Subject\n\n/**\n * Reads the current value of `key` from `subject`, used as the initial\n * keyframe when `animate()` creates a motion value for the subject.\n * Returns `undefined` when the value can't be read.\n *\n * `keyframes` is the target being animated to, so effects can match\n * the format of the initial value (for instance color vs numeric).\n */\nexport type EffectRead<Subject extends object> = (\n subject: Subject,\n key: string,\n keyframes?: UnresolvedValueKeyframe | UnresolvedValueKeyframe[]\n) => AnyResolvedKeyframe | undefined\n\nexport interface EffectOptions<Subject extends object> {\n test?: EffectTest<Subject>\n read?: EffectRead<Subject>\n\n /**\n * Frameloop step writes are scheduled in. Defaults to `frame.render`.\n */\n step?: Schedule\n}\n\nexport interface Effect<Subject extends object = object>\n extends EffectOptions<Subject> {\n (subject: Subject, values: Record<string, MotionValue>): VoidFunction\n\n /**\n * Returns the motion value currently bound to `key` on `subject`, if any.\n */\n get(subject: Subject, key: string): MotionValue | undefined\n}\n\n/**\n * An effect that can be registered with `animate.addEffect()`.\n */\nexport interface AnimateEffect<Subject extends object = object>\n extends Effect<Subject> {\n test: EffectTest<Subject>\n read: EffectRead<Subject>\n}\n\nexport type AddEffectValue<Subject extends object> = (\n subject: Subject,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => VoidFunction\n\nexport function createEffect<Subject extends object>(\n addValue: AddEffectValue<Subject>,\n options: EffectOptions<Subject> & {\n test: EffectTest<Subject>\n read: EffectRead<Subject>\n }\n): AnimateEffect<Subject>\nexport function createEffect<Subject extends object>(\n addValue: AddEffectValue<Subject>,\n options?: EffectOptions<Subject>\n): Effect<Subject>\nexport function createEffect<Subject extends object>(\n addValue: AddEffectValue<Subject>,\n { step, ...options }: EffectOptions<Subject> = {}\n): Effect<Subject> {\n const stateCache = new WeakMap<Subject, MotionValueState>()\n\n const effect = (\n subject: Subject,\n values: Record<string, MotionValue>\n ): VoidFunction => {\n const state = stateCache.get(subject) ?? new MotionValueState(step)\n\n stateCache.set(subject, state)\n\n const subscriptions: VoidFunction[] = []\n\n for (const key in values) {\n const value = values[key]\n const remove = addValue(subject, state, key, value)\n subscriptions.push(remove)\n }\n\n return () => {\n for (const cancel of subscriptions) cancel()\n }\n }\n\n return Object.assign(effect, options, {\n get: (subject: Subject, key: string) =>\n stateCache.get(subject)?.get(key),\n })\n}\n"],"names":[],"mappings":";;AA4EM,SAAU,YAAY,CACxB,QAAiC,EACjC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAA,GAA6B,EAAE,EAAA;AAEjD,IAAA,MAAM,UAAU,GAAG,IAAI,OAAO,EAA6B;AAE3D,IAAA,MAAM,MAAM,GAAG,CACX,OAAgB,EAChB,MAAmC,KACrB;AACd,QAAA,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC;AAEnE,QAAA,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;QAE9B,MAAM,aAAa,GAAmB,EAAE;AAExC,QAAA,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;AACtB,YAAA,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC;AACzB,YAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC;AACnD,YAAA,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9B;AAEA,QAAA,OAAO,MAAK;YACR,KAAK,MAAM,MAAM,IAAI,aAAa;AAAE,gBAAA,MAAM,EAAE;AAChD,QAAA,CAAC;AACL,IAAA,CAAC;AAED,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE;AAClC,QAAA,GAAG,EAAE,CAAC,OAAgB,EAAE,GAAW,KAC/B,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;AACxC,KAAA,CAAC;AACN;;;;"}
|
package/dist/es/index.mjs
CHANGED
|
@@ -42,13 +42,16 @@ export { supportedWaapiEasing } from './animation/waapi/easing/supported.mjs';
|
|
|
42
42
|
export { startWaapiAnimation } from './animation/waapi/start-waapi-animation.mjs';
|
|
43
43
|
export { supportsPartialKeyframes } from './animation/waapi/supports/partial-keyframes.mjs';
|
|
44
44
|
export { supportsBrowserAnimation } from './animation/waapi/supports/waapi.mjs';
|
|
45
|
-
export { acceleratedValues
|
|
45
|
+
export { acceleratedValues } from './animation/waapi/utils/accelerated-values.mjs';
|
|
46
46
|
export { applyGeneratorOptions } from './animation/waapi/utils/apply-generator.mjs';
|
|
47
47
|
export { generateLinearEasing } from './animation/waapi/utils/linear.mjs';
|
|
48
|
+
export { addEffect, animateEffectSubject, findEffect, removeEffect } from './animation/animate/effects.mjs';
|
|
48
49
|
export { addAttrValue, attrEffect } from './effects/attr/index.mjs';
|
|
50
|
+
export { MotionValueState } from './effects/MotionValueState.mjs';
|
|
49
51
|
export { propEffect } from './effects/prop/index.mjs';
|
|
50
52
|
export { addStyleValue, styleEffect } from './effects/style/index.mjs';
|
|
51
53
|
export { svgEffect } from './effects/svg/index.mjs';
|
|
54
|
+
export { createEffect } from './effects/utils/create-effect.mjs';
|
|
52
55
|
export { createRenderBatcher } from './frameloop/batcher.mjs';
|
|
53
56
|
export { cancelMicrotask, microtask } from './frameloop/microtask.mjs';
|
|
54
57
|
export { time } from './frameloop/sync-time.mjs';
|
package/dist/es/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -23,7 +23,7 @@ import { NodeStack } from '../shared/stack.mjs';
|
|
|
23
23
|
import { buildProjectionTransform } from '../styles/transform.mjs';
|
|
24
24
|
import { eachAxis } from '../utils/each-axis.mjs';
|
|
25
25
|
import { FlatTree } from '../utils/flat-tree.mjs';
|
|
26
|
-
import {
|
|
26
|
+
import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
|
|
27
27
|
import { globalProjectionState } from './state.mjs';
|
|
28
28
|
import { frame, cancelFrame, frameData, frameSteps } from '../../frameloop/frame.mjs';
|
|
29
29
|
|
|
@@ -39,14 +39,14 @@ const transformAxes = ["", "X", "Y", "Z"];
|
|
|
39
39
|
*/
|
|
40
40
|
const animationTarget = 1000;
|
|
41
41
|
let id = 0;
|
|
42
|
-
function resetDistortingTransform(key, visualElement, values, sharedAnimationValues
|
|
42
|
+
function resetDistortingTransform(key, visualElement, values, sharedAnimationValues) {
|
|
43
43
|
const { latestValues } = visualElement;
|
|
44
|
-
// Record the distorting transform and then temporarily
|
|
44
|
+
// Record the distorting transform and then temporarily set it to 0
|
|
45
45
|
if (latestValues[key]) {
|
|
46
46
|
values[key] = latestValues[key];
|
|
47
|
-
visualElement.setStaticValue(key,
|
|
47
|
+
visualElement.setStaticValue(key, 0);
|
|
48
48
|
if (sharedAnimationValues) {
|
|
49
|
-
sharedAnimationValues[key] =
|
|
49
|
+
sharedAnimationValues[key] = 0;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -625,7 +625,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
625
625
|
if (isResetRequested &&
|
|
626
626
|
this.instance &&
|
|
627
627
|
(hasProjection ||
|
|
628
|
-
|
|
628
|
+
hasTransform(this.latestValues) ||
|
|
629
629
|
transformTemplateHasChanged)) {
|
|
630
630
|
resetTransform(this.instance, transformTemplateValue);
|
|
631
631
|
this.shouldResetTransform = false;
|
|
@@ -1293,8 +1293,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
1293
1293
|
latestValues.rotateY ||
|
|
1294
1294
|
latestValues.rotateZ ||
|
|
1295
1295
|
latestValues.skewX ||
|
|
1296
|
-
latestValues.skewY
|
|
1297
|
-
(latestValues.transform && latestValues.transform !== "none")) {
|
|
1296
|
+
latestValues.skewY) {
|
|
1298
1297
|
hasDistortingTransform = true;
|
|
1299
1298
|
}
|
|
1300
1299
|
// If there's no distorting values, we don't need to do any more.
|
|
@@ -1304,9 +1303,6 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
1304
1303
|
if (latestValues.z) {
|
|
1305
1304
|
resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
|
|
1306
1305
|
}
|
|
1307
|
-
if (latestValues.transform && latestValues.transform !== "none") {
|
|
1308
|
-
resetDistortingTransform("transform", visualElement, resetValues, this.animationValues, "none");
|
|
1309
|
-
}
|
|
1310
1306
|
// Check the skew and rotate value of all axes and reset to 0
|
|
1311
1307
|
for (let i = 0; i < transformAxes.length; i++) {
|
|
1312
1308
|
resetDistortingTransform(`rotate${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
|
|
@@ -1356,8 +1352,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
1356
1352
|
targetStyle.pointerEvents =
|
|
1357
1353
|
resolveMotionValue(styleProp?.pointerEvents) || "";
|
|
1358
1354
|
}
|
|
1359
|
-
if (this.hasProjected &&
|
|
1360
|
-
!hasVisualTransform(this.latestValues)) {
|
|
1355
|
+
if (this.hasProjected && !hasTransform(this.latestValues)) {
|
|
1361
1356
|
targetStyle.transform = transformTemplate
|
|
1362
1357
|
? transformTemplate({}, "")
|
|
1363
1358
|
: "none";
|