motion-dom 13.2.0 → 13.3.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 +3961 -3188
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +41 -38
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/FollowAnimation.mjs +152 -0
- package/dist/es/animation/FollowAnimation.mjs.map +1 -0
- package/dist/es/animation/JSAnimation.mjs +7 -11
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +2 -0
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationWrapper.mjs +7 -0
- package/dist/es/animation/NativeAnimationWrapper.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +70 -13
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/animate/element.mjs +80 -0
- package/dist/es/animation/animate/element.mjs.map +1 -0
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +25 -1
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +100 -52
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/animation/generators/utils/velocity.mjs +13 -1
- package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +12 -6
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/KeyframesResolver.mjs +38 -7
- package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs +8 -2
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs +45 -19
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
- package/dist/es/animation/utils/WithPromise.mjs +12 -5
- package/dist/es/animation/utils/WithPromise.mjs.map +1 -1
- package/dist/es/animation/utils/arc.mjs +2 -1
- package/dist/es/animation/utils/arc.mjs.map +1 -1
- package/dist/es/animation/utils/can-animate.mjs +3 -1
- package/dist/es/animation/utils/can-animate.mjs.map +1 -1
- package/dist/es/animation/utils/notify-inspector.mjs +56 -0
- package/dist/es/animation/utils/notify-inspector.mjs.map +1 -0
- package/dist/es/animation/waapi/supports/waapi.mjs +8 -1
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +83 -25
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/attr/index.mjs +15 -9
- package/dist/es/effects/attr/index.mjs.map +1 -1
- package/dist/es/effects/prop/index.mjs +15 -2
- package/dist/es/effects/prop/index.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +52 -9
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +28 -25
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/svg/index.mjs +40 -7
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/effects/utils/create-dom-effect.mjs +9 -1
- package/dist/es/effects/utils/create-dom-effect.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs +2 -0
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs +5 -2
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/index.mjs +5 -4
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +9 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +4 -1
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +11 -2
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/utils/is-controlling-variants.mjs +8 -2
- package/dist/es/render/utils/is-controlling-variants.mjs.map +1 -1
- package/dist/es/utils/mix/color.mjs +3 -2
- package/dist/es/utils/mix/color.mjs.map +1 -1
- package/dist/es/utils/mix/index.mjs +28 -0
- package/dist/es/utils/mix/index.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +33 -30
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/es/value/index.mjs +73 -29
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs +17 -4
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/index.d.ts +245 -50
- package/dist/motion-dom.dev.js +3961 -3188
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
|
|
2
|
+
import { numberValueTypes } from '../../value/types/maps/number.mjs';
|
|
3
|
+
import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
|
|
2
4
|
import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
|
|
3
5
|
import { createEffect } from '../utils/create-effect.mjs';
|
|
4
6
|
|
|
@@ -10,22 +12,26 @@ function canSetAsProperty(element, name) {
|
|
|
10
12
|
// Check if it has a setter
|
|
11
13
|
return descriptor && typeof descriptor.set === "function";
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `name` is the attribute written when it differs from the key the value
|
|
17
|
+
* is stored under, e.g. `attrX` -> `x`. Numbers take the attribute's
|
|
18
|
+
* default unit (`x: 100` -> `"100px"`), as they do when key and name match.
|
|
19
|
+
*/
|
|
20
|
+
const addAttrValue = (element, state, key, value, name = key) => {
|
|
21
|
+
const isProp = canSetAsProperty(element, name);
|
|
22
|
+
if (!isProp && (name.startsWith("data") || name.startsWith("aria"))) {
|
|
23
|
+
name = camelToDash(name);
|
|
24
|
+
}
|
|
25
|
+
const type = numberValueTypes[key] || numberValueTypes[name];
|
|
20
26
|
/**
|
|
21
27
|
* Set attribute directly via property if available
|
|
22
28
|
*/
|
|
23
29
|
const render = isProp
|
|
24
30
|
? () => {
|
|
25
|
-
element[name] =
|
|
31
|
+
element[name] = getValueAsType(value.get(), numberValueTypes[key]);
|
|
26
32
|
}
|
|
27
33
|
: () => {
|
|
28
|
-
const v =
|
|
34
|
+
const v = getValueAsType(value.get(), type);
|
|
29
35
|
if (v === null || v === undefined) {
|
|
30
36
|
element.removeAttribute(name);
|
|
31
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/attr/index.ts"],"sourcesContent":["import { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction canSetAsProperty(element: HTMLElement | SVGElement, name: string) {\n if (!(name in element)) return false\n\n const descriptor =\n Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), name) ||\n Object.getOwnPropertyDescriptor(element, name)\n\n // Check if it has a setter\n return descriptor && typeof descriptor.set === \"function\"\n}\n\nexport const addAttrValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n const isProp = canSetAsProperty(element,
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/attr/index.ts"],"sourcesContent":["import { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\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\"\n\nfunction canSetAsProperty(element: HTMLElement | SVGElement, name: string) {\n if (!(name in element)) return false\n\n const descriptor =\n Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), name) ||\n Object.getOwnPropertyDescriptor(element, name)\n\n // Check if it has a setter\n return descriptor && typeof descriptor.set === \"function\"\n}\n\n/**\n * `name` is the attribute written when it differs from the key the value\n * is stored under, e.g. `attrX` -> `x`. Numbers take the attribute's\n * default unit (`x: 100` -> `\"100px\"`), as they do when key and name match.\n */\nexport const addAttrValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue,\n name: string = key\n) => {\n const isProp = canSetAsProperty(element, name)\n if (!isProp && (name.startsWith(\"data\") || name.startsWith(\"aria\"))) {\n name = camelToDash(name)\n }\n\n const type = numberValueTypes[key] || numberValueTypes[name]\n\n /**\n * Set attribute directly via property if available\n */\n const render = isProp\n ? () => {\n ;(element as any)[name] = getValueAsType(\n value.get(),\n numberValueTypes[key]\n )\n }\n : () => {\n const v = getValueAsType(value.get(), type)\n if (v === null || v === undefined) {\n element.removeAttribute(name)\n } else {\n element.setAttribute(name, String(v))\n }\n }\n\n return state.set(key, value, render)\n}\n\nexport const attrEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addAttrValue)\n)\n"],"names":[],"mappings":";;;;;;AAQA,SAAS,gBAAgB,CAAC,OAAiC,EAAE,IAAY,EAAA;AACrE,IAAA,IAAI,EAAE,IAAI,IAAI,OAAO,CAAC;AAAE,QAAA,OAAO,KAAK;AAEpC,IAAA,MAAM,UAAU,GACZ,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CA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
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
import { isObject } from 'motion-utils';
|
|
1
2
|
import { createEffect } from '../utils/create-effect.mjs';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Writes motion values to the properties of any object. This is
|
|
6
|
+
* animate()'s fallback for subjects no registered effect claims.
|
|
7
|
+
*/
|
|
3
8
|
const propEffect = /*@__PURE__*/ createEffect((subject, state, key, value) => {
|
|
4
9
|
return state.set(key, value, () => {
|
|
5
|
-
subject[key] =
|
|
6
|
-
}
|
|
10
|
+
subject[key] = value.get();
|
|
11
|
+
});
|
|
12
|
+
}, {
|
|
13
|
+
test: (subject) => isObject(subject),
|
|
14
|
+
read: (subject, key) => {
|
|
15
|
+
const value = subject[key];
|
|
16
|
+
return typeof value === "string" || typeof value === "number"
|
|
17
|
+
? value
|
|
18
|
+
: undefined;
|
|
19
|
+
},
|
|
7
20
|
});
|
|
8
21
|
|
|
9
22
|
export { propEffect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/prop/index.ts"],"sourcesContent":["import { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createEffect } from \"../utils/create-effect\"\n\nexport const propEffect = /*@__PURE__*/ createEffect(\n (\n subject:
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/prop/index.ts"],"sourcesContent":["import { isObject } from \"motion-utils\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createEffect } from \"../utils/create-effect\"\n\ninterface PropSubject {\n [key: string]: any\n}\n\n/**\n * Writes motion values to the properties of any object. This is\n * animate()'s fallback for subjects no registered effect claims.\n */\nexport const propEffect = /*@__PURE__*/ createEffect(\n (\n subject: PropSubject,\n state: MotionValueState,\n key: string,\n value: MotionValue\n ) => {\n return state.set(\n key,\n value,\n () => {\n subject[key] = value.get()\n }\n )\n },\n {\n test: (subject: unknown): subject is PropSubject => isObject(subject),\n read: (subject, key) => {\n const value = subject[key]\n return typeof value === \"string\" || typeof value === \"number\"\n ? value\n : undefined\n },\n }\n)\n"],"names":[],"mappings":";;;AASA;;;AAGG;AACI,MAAM,UAAU,iBAAiB,YAAY,CAChD,CACI,OAAoB,EACpB,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,OAAO,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,MAAK;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE;AAC9B,IAAA,CAAC,CACJ;AACL,CAAC,EACD;IACI,IAAI,EAAE,CAAC,OAAgB,KAA6B,QAAQ,CAAC,OAAO,CAAC;AACrE,IAAA,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,KAAI;AACnB,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK;AACjD,cAAE;cACA,SAAS;IACnB,CAAC;AACJ,CAAA;;;;"}
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import { isCSSVar } from '../../render/dom/is-css-var.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { readTransformValue } from '../../render/dom/parse-transform.mjs';
|
|
3
|
+
import { transformProps, transformPropOrder } from '../../render/utils/keys-transform.mjs';
|
|
3
4
|
import { isHTMLElement } from '../../utils/is-html-element.mjs';
|
|
5
|
+
import { isSVGElement } from '../../utils/is-svg-element.mjs';
|
|
4
6
|
import { MotionValue } from '../../value/index.mjs';
|
|
7
|
+
import { numberValueTypes } from '../../value/types/maps/number.mjs';
|
|
8
|
+
import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
|
|
5
9
|
import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
|
|
6
10
|
import { createEffect } from '../utils/create-effect.mjs';
|
|
7
11
|
import { buildTransform } from './transform.mjs';
|
|
8
12
|
|
|
9
13
|
const originProps = new Set(["originX", "originY", "originZ"]);
|
|
14
|
+
/**
|
|
15
|
+
* A bound value in its default unit, e.g. `originX: 50` -> `"50%"`.
|
|
16
|
+
*/
|
|
17
|
+
const styleValue = (state, key) => getValueAsType(state.get(key)?.get(), numberValueTypes[key]);
|
|
10
18
|
const addStyleValue = (element, state, key, value) => {
|
|
11
19
|
let render = undefined;
|
|
12
20
|
let computed = undefined;
|
|
13
21
|
if (transformProps.has(key)) {
|
|
22
|
+
if (key !== "pathRotation") {
|
|
23
|
+
const keys = (state.transformKeys ?? (state.transformKeys = []));
|
|
24
|
+
(state.transformValues ?? (state.transformValues = {}))[key] = value;
|
|
25
|
+
if (!keys.includes(key)) {
|
|
26
|
+
keys.push(key);
|
|
27
|
+
keys.sort((a, b) => transformPropOrder.indexOf(a) -
|
|
28
|
+
transformPropOrder.indexOf(b));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
14
31
|
if (!state.get("transform")) {
|
|
15
32
|
// If this is an HTML element, we need to set the transform-box to fill-box
|
|
16
33
|
// to normalise the transform relative to the element's bounding box
|
|
@@ -26,9 +43,9 @@ const addStyleValue = (element, state, key, value) => {
|
|
|
26
43
|
else if (originProps.has(key)) {
|
|
27
44
|
if (!state.get("transformOrigin")) {
|
|
28
45
|
state.set("transformOrigin", new MotionValue(""), () => {
|
|
29
|
-
const originX = state
|
|
30
|
-
const originY = state
|
|
31
|
-
const originZ = state
|
|
46
|
+
const originX = styleValue(state, "originX") ?? "50%";
|
|
47
|
+
const originY = styleValue(state, "originY") ?? "50%";
|
|
48
|
+
const originZ = styleValue(state, "originZ") ?? 0;
|
|
32
49
|
element.style.transformOrigin = `${originX} ${originY} ${originZ}`;
|
|
33
50
|
});
|
|
34
51
|
}
|
|
@@ -36,18 +53,44 @@ const addStyleValue = (element, state, key, value) => {
|
|
|
36
53
|
}
|
|
37
54
|
else if (isCSSVar(key)) {
|
|
38
55
|
render = () => {
|
|
39
|
-
element.style.setProperty(key,
|
|
56
|
+
element.style.setProperty(key, value.get());
|
|
40
57
|
};
|
|
41
58
|
}
|
|
42
59
|
else {
|
|
43
60
|
render = () => {
|
|
44
|
-
element.style[key] =
|
|
61
|
+
element.style[key] = getValueAsType(value.get(), numberValueTypes[key]);
|
|
45
62
|
};
|
|
46
63
|
}
|
|
47
64
|
return state.set(key, value, render, computed);
|
|
48
65
|
};
|
|
49
|
-
const
|
|
50
|
-
|
|
66
|
+
const isStyleSubject = (subject) => isHTMLElement(subject) || isSVGElement(subject);
|
|
67
|
+
/**
|
|
68
|
+
* Reads the current value of a style from the element, as the initial
|
|
69
|
+
* keyframe when `animate()` targets an element via this effect. Transforms
|
|
70
|
+
* are parsed out of the computed matrix; everything else is the computed
|
|
71
|
+
* style. Units aren't converted to match the target keyframes. A style
|
|
72
|
+
* the browser can't report is 0, as a VisualElement reports it.
|
|
73
|
+
*/
|
|
74
|
+
const readStyleValue = (element, key) => {
|
|
75
|
+
if (transformProps.has(key)) {
|
|
76
|
+
return readTransformValue(element, key);
|
|
77
|
+
}
|
|
78
|
+
const computedStyle = getComputedStyle(element);
|
|
79
|
+
const value = isCSSVar(key)
|
|
80
|
+
? computedStyle.getPropertyValue(key)
|
|
81
|
+
: computedStyle[key];
|
|
82
|
+
return (typeof value === "string" && value.trim()) || 0;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The per-element effect `animate()` binds through, so HTML values share
|
|
86
|
+
* state with a direct `styleEffect()` call. The exported `styleEffect`
|
|
87
|
+
* is this wrapped to also accept selectors.
|
|
88
|
+
*/
|
|
89
|
+
const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {
|
|
90
|
+
test: isStyleSubject,
|
|
91
|
+
read: readStyleValue,
|
|
92
|
+
});
|
|
93
|
+
const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
|
|
51
94
|
|
|
52
|
-
export { addStyleValue, styleEffect };
|
|
95
|
+
export { addStyleValue, readStyleValue, styleEffect, styleSubjectEffect };
|
|
53
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 {
|
|
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\nconst 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":";;;;;;;;;;;;AAgBA,MAAM,WAAW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gBAAgB,CAAC,GAAG,CAAC,CACd;AACf,QAAA,CAAC;IACL;AAEA,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC;AAClD;AAIA,MAAM,cAAc,GAAG,CAAC,OAAgB,KACpC,aAAa,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC;AAEnD;;;;;;AAMG;MACU,cAAc,GAAG,CAAC,OAAqB,EAAE,GAAW,KAAI;AACjE,IAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,QAAA,OAAO,kBAAkB,CAAC,OAAsB,EAAE,GAAG,CAAC;IAC1D;AAEA,IAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG;AACtB,UAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG;AACpC,UAAE,aAAa,CAAC,GAAU,CAAC;AAE/B,IAAA,OAAO,CAAC,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;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformValueTypes } from '../../value/types/maps/transform.mjs';
|
|
2
|
+
import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
|
|
2
3
|
|
|
3
4
|
const translateAlias = {
|
|
4
5
|
x: "translateX",
|
|
@@ -6,42 +7,44 @@ const translateAlias = {
|
|
|
6
7
|
z: "translateZ",
|
|
7
8
|
transformPerspective: "perspective",
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Cache of `translateX(`-style openers so each render is a few string
|
|
12
|
+
* concatenations rather than a template per transform.
|
|
13
|
+
*/
|
|
14
|
+
const openers = {};
|
|
9
15
|
function buildTransform(state) {
|
|
10
16
|
let transform = "";
|
|
11
|
-
|
|
17
|
+
const { transformKeys: keys = [], transformValues: values = {} } = state;
|
|
12
18
|
/**
|
|
13
|
-
* Loop over
|
|
14
|
-
*
|
|
19
|
+
* Loop over the bound transforms in order, adding the ones that
|
|
20
|
+
* aren't at their default value to the transform string.
|
|
15
21
|
*/
|
|
16
|
-
for (let i = 0; i <
|
|
17
|
-
const key =
|
|
18
|
-
const value =
|
|
22
|
+
for (let i = 0; i < keys.length; i++) {
|
|
23
|
+
const key = keys[i];
|
|
24
|
+
const value = values[key].get();
|
|
19
25
|
if (value === undefined)
|
|
20
26
|
continue;
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!valueIsDefault) {
|
|
30
|
-
transformIsDefault = false;
|
|
31
|
-
const transformName = translateAlias[key] || key;
|
|
32
|
-
transform += `${transformName}(${value}) `;
|
|
27
|
+
const parsed = typeof value === "number" ? value : parseFloat(value);
|
|
28
|
+
if (parsed !== (key.startsWith("scale") ? 1 : 0)) {
|
|
29
|
+
transform +=
|
|
30
|
+
(transform && " ") +
|
|
31
|
+
(openers[key] ||
|
|
32
|
+
(openers[key] = (translateAlias[key] || key) + "(")) +
|
|
33
|
+
getValueAsType(value, transformValueTypes[key]) +
|
|
34
|
+
")";
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
// See build-transform.ts: additive `rotate()` so user `rotate` isn't
|
|
36
38
|
// clobbered. Not a `transformPropOrder` slot.
|
|
37
|
-
const pathRotation = state.
|
|
39
|
+
const pathRotation = state.get("pathRotation")?.get();
|
|
38
40
|
if (pathRotation) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
transform +=
|
|
42
|
+
(transform && " ") +
|
|
43
|
+
"rotate(" +
|
|
44
|
+
getValueAsType(pathRotation, transformValueTypes.pathRotation) +
|
|
45
|
+
")";
|
|
43
46
|
}
|
|
44
|
-
return
|
|
47
|
+
return transform || "none";
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
export { buildTransform };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformValueTypes } from \"../../value/types/maps/transform\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias: Record<string, string> = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\n/**\n * Cache of `translateX(`-style openers so each render is a few string\n * concatenations rather than a template per transform.\n */\nconst openers: Record<string, string> = {}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n const { transformKeys: keys = [], transformValues: values = {} } = state\n\n /**\n * Loop over the bound transforms in order, adding the ones that\n * aren't at their default value to the transform string.\n */\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n const value = values[key].get()\n\n if (value === undefined) continue\n\n const parsed = typeof value === \"number\" ? value : parseFloat(value)\n\n if (parsed !== (key.startsWith(\"scale\") ? 1 : 0)) {\n transform +=\n (transform && \" \") +\n (openers[key] ||\n (openers[key] = (translateAlias[key] || key) + \"(\")) +\n getValueAsType(value, transformValueTypes[key]) +\n \")\"\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.get(\"pathRotation\")?.get()\n if (pathRotation) {\n transform +=\n (transform && \" \") +\n \"rotate(\" +\n getValueAsType(pathRotation, transformValueTypes.pathRotation) +\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AAc,CAAC,EAAE,GAAG,EAAE;IACrD,IAAI,YAAY,EAAE;QACd,SAAS;YACL,CAAC,SAAS,IAAI,GAAG;gBACjB,SAAS;AACT,gBAAA,cAAc,CAAC,YAAY,EAAE,mBAAmB,CAAC,YAAY,CAAC;AAC9D,gBAAA,GAAG;IACX;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
|
|
2
|
+
import { cssStyleProperties } from '../../render/svg/utils/build-attrs.mjs';
|
|
3
|
+
import { transformProps } from '../../render/utils/keys-transform.mjs';
|
|
4
|
+
import { isSVGElement } from '../../utils/is-svg-element.mjs';
|
|
1
5
|
import { MotionValue } from '../../value/index.mjs';
|
|
6
|
+
import { numberValueTypes } from '../../value/types/maps/number.mjs';
|
|
2
7
|
import { addAttrValue } from '../attr/index.mjs';
|
|
3
|
-
import { addStyleValue } from '../style/index.mjs';
|
|
8
|
+
import { addStyleValue, readStyleValue } from '../style/index.mjs';
|
|
4
9
|
import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
|
|
5
10
|
import { createEffect } from '../utils/create-effect.mjs';
|
|
6
11
|
import { frame } from '../../frameloop/frame.mjs';
|
|
@@ -10,14 +15,15 @@ function addSVGPathValue(element, state, key, value) {
|
|
|
10
15
|
if (key === "pathOffset") {
|
|
11
16
|
return state.set(key, value, () => {
|
|
12
17
|
// Use unitless value to avoid Safari zoom bug
|
|
13
|
-
const offset =
|
|
18
|
+
const offset = value.get();
|
|
14
19
|
element.setAttribute("stroke-dashoffset", `${-offset}`);
|
|
15
20
|
});
|
|
16
21
|
}
|
|
17
22
|
else {
|
|
18
23
|
if (!state.get("stroke-dasharray")) {
|
|
19
24
|
state.set("stroke-dasharray", new MotionValue("1 1"), () => {
|
|
20
|
-
const
|
|
25
|
+
const pathLength = state.get("pathLength")?.get() ?? 1;
|
|
26
|
+
const pathSpacing = state.get("pathSpacing")?.get();
|
|
21
27
|
// Use unitless values to avoid Safari zoom bug
|
|
22
28
|
element.setAttribute("stroke-dasharray", `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`);
|
|
23
29
|
});
|
|
@@ -30,16 +36,43 @@ const addSVGValue = (element, state, key, value) => {
|
|
|
30
36
|
return addSVGPathValue(element, state, key, value);
|
|
31
37
|
}
|
|
32
38
|
else if (key.startsWith("attr")) {
|
|
33
|
-
return addAttrValue(element, state,
|
|
39
|
+
return addAttrValue(element, state, key, value, convertAttrKey(key));
|
|
34
40
|
}
|
|
35
41
|
const handler = key in element.style ? addStyleValue : addAttrValue;
|
|
36
42
|
return handler(element, state, key, value);
|
|
37
43
|
};
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Reads the current value of `key` from an SVG element as the origin of
|
|
46
|
+
* an animation, as the SVG VisualElement does: transforms start from
|
|
47
|
+
* their defaults, the few CSS-only properties come from computed style
|
|
48
|
+
* and everything else is read from the attribute, dash-cased
|
|
49
|
+
* (`strokeWidth` -> `stroke-width`) or, failing that, as written
|
|
50
|
+
* (`baseFrequency`).
|
|
51
|
+
*/
|
|
52
|
+
const readSVGValue = (element, key) => {
|
|
53
|
+
if (transformProps.has(key)) {
|
|
54
|
+
return numberValueTypes[key]?.default || 0;
|
|
55
|
+
}
|
|
56
|
+
if (cssStyleProperties.includes(key)) {
|
|
57
|
+
return readStyleValue(element, key);
|
|
58
|
+
}
|
|
59
|
+
key = convertAttrKey(key);
|
|
60
|
+
return (element.getAttribute(camelToDash(key)) ??
|
|
61
|
+
element.getAttribute(key) ??
|
|
62
|
+
undefined);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The per-element effect `animate()` binds through, so SVG values share
|
|
66
|
+
* state with a direct `svgEffect()` call.
|
|
67
|
+
*/
|
|
68
|
+
const svgSubjectEffect = /*@__PURE__*/ createEffect(addSVGValue, {
|
|
69
|
+
test: isSVGElement,
|
|
70
|
+
read: readSVGValue,
|
|
71
|
+
});
|
|
72
|
+
const svgEffect = /*@__PURE__*/ createSelectorEffect(svgSubjectEffect);
|
|
40
73
|
function convertAttrKey(key) {
|
|
41
74
|
return key.replace(/^attr([A-Z])/, (_, firstChar) => firstChar.toLowerCase());
|
|
42
75
|
}
|
|
43
76
|
|
|
44
|
-
export { svgEffect };
|
|
77
|
+
export { addSVGValue, readSVGValue, svgEffect, svgSubjectEffect };
|
|
45
78
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/svg/index.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { MotionValue } from \"../../value\"\nimport { addAttrValue } from \"../attr\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { addStyleValue } 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 =
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/effects/svg/index.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\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 = key in element.style ? addStyleValue : 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, the few CSS-only properties come from computed style\n * and everything else is read from the attribute, dash-cased\n * (`strokeWidth` -> `stroke-width`) or, failing that, as written\n * (`baseFrequency`).\n */\nexport const readSVGValue = (element: SVGElement, key: string) => {\n if (transformProps.has(key)) {\n return numberValueTypes[key]?.default || 0\n }\n\n if (cssStyleProperties.includes(key)) {\n return readStyleValue(element, key)\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":";;;;;;;;;;;;AAaA,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,UAAU,CAAC,CAAA,CAAE,CAC3D;AACL,YAAA,CAAC,CAAC;QACN;AAEA,QAAA,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,CAA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AA;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;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveElements } from '../../utils/resolve-elements.mjs';
|
|
2
2
|
|
|
3
3
|
function createSelectorEffect(subjectEffect) {
|
|
4
|
-
|
|
4
|
+
const effect = (subject, values) => {
|
|
5
5
|
const elements = resolveElements(subject);
|
|
6
6
|
const subscriptions = [];
|
|
7
7
|
for (const element of elements) {
|
|
@@ -13,6 +13,14 @@ function createSelectorEffect(subjectEffect) {
|
|
|
13
13
|
remove();
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
+
const { test, read, get, flush, state } = subjectEffect;
|
|
17
|
+
return Object.assign(effect, {
|
|
18
|
+
test,
|
|
19
|
+
read,
|
|
20
|
+
get: get,
|
|
21
|
+
flush,
|
|
22
|
+
state,
|
|
23
|
+
});
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
export { createSelectorEffect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-dom-effect.mjs","sources":["../../../../src/effects/utils/create-dom-effect.ts"],"sourcesContent":["import {\n ElementOrSelector,\n resolveElements,\n} from \"../../utils/resolve-elements\"\nimport { MotionValue } from \"../../value\"\n\nexport
|
|
1
|
+
{"version":3,"file":"create-dom-effect.mjs","sources":["../../../../src/effects/utils/create-dom-effect.ts"],"sourcesContent":["import {\n ElementOrSelector,\n resolveElements,\n} from \"../../utils/resolve-elements\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport {\n AnimateEffect,\n Effect,\n EffectOptions,\n EffectRead,\n EffectTest,\n} from \"./create-effect\"\n\n/**\n * The element overloads come last so generic inference sees the subject type.\n */\nexport interface SelectorEffect<T extends object> extends EffectOptions<T> {\n (\n subject: ElementOrSelector,\n values: Record<string, MotionValue>\n ): VoidFunction\n (subject: T, values: Record<string, MotionValue>): VoidFunction\n\n get(subject: ElementOrSelector, key: string): MotionValue | undefined\n get(subject: T, key: string): MotionValue | undefined\n\n flush(subject: T): void\n state(subject: T): MotionValueState | undefined\n}\n\nexport interface SelectorAnimateEffect<T extends object>\n extends SelectorEffect<T> {\n test: EffectTest<T>\n read: EffectRead<T>\n}\n\n/**\n * Wraps a per-element effect so it also accepts selectors and element\n * lists. `test`, `read` and `get` still address a single element, so the\n * result can be registered with `animate.addEffect()`.\n */\nexport function createSelectorEffect<T extends object>(\n subjectEffect: AnimateEffect<T>\n): SelectorAnimateEffect<T>\nexport function createSelectorEffect<T extends object>(\n subjectEffect: Effect<T>\n): SelectorEffect<T>\nexport function createSelectorEffect<T extends object>(\n subjectEffect: Effect<T>\n): SelectorEffect<T> {\n const effect = (\n subject: T | ElementOrSelector,\n values: Record<string, MotionValue>\n ) => {\n const elements = resolveElements(subject as ElementOrSelector)\n const subscriptions: VoidFunction[] = []\n\n for (const element of elements) {\n const remove = subjectEffect(element as T, values)\n subscriptions.push(remove)\n }\n\n return () => {\n for (const remove of subscriptions) remove()\n }\n }\n\n const { test, read, get, flush, state } = subjectEffect\n\n return Object.assign(effect, {\n test,\n read,\n get: get as SelectorEffect<T>[\"get\"],\n flush,\n state,\n })\n}\n"],"names":[],"mappings":";;AAgDM,SAAU,oBAAoB,CAChC,aAAwB,EAAA;AAExB,IAAA,MAAM,MAAM,GAAG,CACX,OAA8B,EAC9B,MAAmC,KACnC;AACA,QAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,OAA4B,CAAC;QAC9D,MAAM,aAAa,GAAmB,EAAE;AAExC,QAAA,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,OAAY,EAAE,MAAM,CAAC;AAClD,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,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,aAAa;AAEvD,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACzB,IAAI;QACJ,IAAI;AACJ,QAAA,GAAG,EAAE,GAA+B;QACpC,KAAK;QACL,KAAK;AACR,KAAA,CAAC;AACN;;;;"}
|
|
@@ -18,6 +18,8 @@ function createEffect(addValue, { step, ...options } = {}) {
|
|
|
18
18
|
};
|
|
19
19
|
return Object.assign(effect, options, {
|
|
20
20
|
get: (subject, key) => stateCache.get(subject)?.get(key),
|
|
21
|
+
flush: (subject) => stateCache.get(subject)?.flush(),
|
|
22
|
+
state: (subject) => stateCache.get(subject),
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -1 +1 @@
|
|
|
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":";;
|
|
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 * Write `subject`'s pending values now rather than in the next frame,\n * e.g. so it can be measured with a target applied.\n */\n flush(subject: Subject): void\n\n /**\n * The state holding the motion values bound to `subject`, if any have\n * been, so they can be handed to another renderer.\n */\n state(subject: Subject): MotionValueState | 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 flush: (subject: Subject) => stateCache.get(subject)?.flush(),\n state: (subject: Subject) => stateCache.get(subject),\n })\n}\n"],"names":[],"mappings":";;AAwFM,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;AACrC,QAAA,KAAK,EAAE,CAAC,OAAgB,KAAK,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE;QAC7D,KAAK,EAAE,CAAC,OAAgB,KAAK,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;AACvD,KAAA,CAAC;AACN;;;;"}
|
|
@@ -13,8 +13,11 @@ function createRenderStep(runNextFrame) {
|
|
|
13
13
|
let flushNextFrame = false;
|
|
14
14
|
/**
|
|
15
15
|
* A set of processes which were marked keepAlive when scheduled.
|
|
16
|
+
* A keepAlive process is always also held by a frame queue until
|
|
17
|
+
* it's cancelled, so a Set has the same lifetime semantics as a
|
|
18
|
+
* WeakSet here while being considerably faster to query every frame.
|
|
16
19
|
*/
|
|
17
|
-
const toKeepAlive = new
|
|
20
|
+
const toKeepAlive = new Set();
|
|
18
21
|
let latestFrameData = {
|
|
19
22
|
delta: 0.0,
|
|
20
23
|
timestamp: 0.0,
|
|
@@ -22,7 +25,7 @@ function createRenderStep(runNextFrame) {
|
|
|
22
25
|
};
|
|
23
26
|
function triggerCallback(callback) {
|
|
24
27
|
if (toKeepAlive.has(callback)) {
|
|
25
|
-
|
|
28
|
+
nextFrame.add(callback);
|
|
26
29
|
runNextFrame();
|
|
27
30
|
}
|
|
28
31
|
callback(latestFrameData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-step.mjs","sources":["../../../src/frameloop/render-step.ts"],"sourcesContent":["import { FrameData, Process, Step } from \"./types\"\n\nexport function createRenderStep(runNextFrame: () => void): Step {\n /**\n * We create and reuse two queues, one to queue jobs for the current frame\n * and one for the next. We reuse to avoid triggering GC after x frames.\n */\n let thisFrame = new Set<Process>()\n let nextFrame = new Set<Process>()\n\n /**\n * Track whether we're currently processing jobs in this step. This way\n * we can decide whether to schedule new jobs for this frame or next.\n */\n let isProcessing = false\n\n let flushNextFrame = false\n\n /**\n * A set of processes which were marked keepAlive when scheduled.\n */\n const toKeepAlive = new
|
|
1
|
+
{"version":3,"file":"render-step.mjs","sources":["../../../src/frameloop/render-step.ts"],"sourcesContent":["import { FrameData, Process, Step } from \"./types\"\n\nexport function createRenderStep(runNextFrame: () => void): Step {\n /**\n * We create and reuse two queues, one to queue jobs for the current frame\n * and one for the next. We reuse to avoid triggering GC after x frames.\n */\n let thisFrame = new Set<Process>()\n let nextFrame = new Set<Process>()\n\n /**\n * Track whether we're currently processing jobs in this step. This way\n * we can decide whether to schedule new jobs for this frame or next.\n */\n let isProcessing = false\n\n let flushNextFrame = false\n\n /**\n * A set of processes which were marked keepAlive when scheduled.\n * A keepAlive process is always also held by a frame queue until\n * it's cancelled, so a Set has the same lifetime semantics as a\n * WeakSet here while being considerably faster to query every frame.\n */\n const toKeepAlive = new Set<Process>()\n\n let latestFrameData: FrameData = {\n delta: 0.0,\n timestamp: 0.0,\n isProcessing: false,\n }\n\n function triggerCallback(callback: Process) {\n if (toKeepAlive.has(callback)) {\n nextFrame.add(callback)\n runNextFrame()\n }\n\n callback(latestFrameData)\n }\n\n const step: Step = {\n /**\n * Schedule a process to run on the next frame.\n */\n schedule: (callback, keepAlive = false, immediate = false) => {\n const addToCurrentFrame = immediate && isProcessing\n const queue = addToCurrentFrame ? thisFrame : nextFrame\n\n if (keepAlive) toKeepAlive.add(callback)\n\n queue.add(callback)\n\n return callback\n },\n\n /**\n * Cancel the provided callback from running on the next frame.\n */\n cancel: (callback) => {\n nextFrame.delete(callback)\n toKeepAlive.delete(callback)\n },\n\n /**\n * Execute all schedule callbacks.\n */\n process: (frameData) => {\n latestFrameData = frameData\n\n /**\n * If we're already processing we've probably been triggered by a flushSync\n * inside an existing process. Instead of executing, mark flushNextFrame\n * as true and ensure we flush the following frame at the end of this one.\n */\n if (isProcessing) {\n flushNextFrame = true\n return\n }\n\n isProcessing = true\n\n // Swap this frame and the next to avoid GC\n const prevFrame = thisFrame\n thisFrame = nextFrame\n nextFrame = prevFrame\n\n // Execute this frame\n thisFrame.forEach(triggerCallback)\n\n // Clear the frame so no callbacks remain. This is to avoid\n // memory leaks should this render step not run for a while.\n thisFrame.clear()\n\n isProcessing = false\n\n if (flushNextFrame) {\n flushNextFrame = false\n step.process(frameData)\n }\n },\n }\n\n return step\n}\n"],"names":[],"mappings":"AAEM,SAAU,gBAAgB,CAAC,YAAwB,EAAA;AACrD;;;AAGG;AACH,IAAA,IAAI,SAAS,GAAG,IAAI,GAAG,EAAW;AAClC,IAAA,IAAI,SAAS,GAAG,IAAI,GAAG,EAAW;AAElC;;;AAGG;IACH,IAAI,YAAY,GAAG,KAAK;IAExB,IAAI,cAAc,GAAG,KAAK;AAE1B;;;;;AAKG;AACH,IAAA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAW;AAEtC,IAAA,IAAI,eAAe,GAAc;AAC7B,QAAA,KAAK,EAAE,GAAG;AACV,QAAA,SAAS,EAAE,GAAG;AACd,QAAA,YAAY,EAAE,KAAK;KACtB;IAED,SAAS,eAAe,CAAC,QAAiB,EAAA;AACtC,QAAA,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;AAC3B,YAAA,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;AACvB,YAAA,YAAY,EAAE;QAClB;QAEA,QAAQ,CAAC,eAAe,CAAC;IAC7B;AAEA,IAAA,MAAM,IAAI,GAAS;AACf;;AAEG;AACH,QAAA,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,KAAI;AACzD,YAAA,MAAM,iBAAiB,GAAG,SAAS,IAAI,YAAY;YACnD,MAAM,KAAK,GAAG,iBAAiB,GAAG,SAAS,GAAG,SAAS;AAEvD,YAAA,IAAI,SAAS;AAAE,gBAAA,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;AAExC,YAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;AAEnB,YAAA,OAAO,QAAQ;QACnB,CAAC;AAED;;AAEG;AACH,QAAA,MAAM,EAAE,CAAC,QAAQ,KAAI;AACjB,YAAA,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC1B,YAAA,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChC,CAAC;AAED;;AAEG;AACH,QAAA,OAAO,EAAE,CAAC,SAAS,KAAI;YACnB,eAAe,GAAG,SAAS;AAE3B;;;;AAIG;YACH,IAAI,YAAY,EAAE;gBACd,cAAc,GAAG,IAAI;gBACrB;YACJ;YAEA,YAAY,GAAG,IAAI;;YAGnB,MAAM,SAAS,GAAG,SAAS;YAC3B,SAAS,GAAG,SAAS;YACrB,SAAS,GAAG,SAAS;;AAGrB,YAAA,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC;;;YAIlC,SAAS,CAAC,KAAK,EAAE;YAEjB,YAAY,GAAG,KAAK;YAEpB,IAAI,cAAc,EAAE;gBAChB,cAAc,GAAG,KAAK;AACtB,gBAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAC3B;QACJ,CAAC;KACJ;AAED,IAAA,OAAO,IAAI;AACf;;;;"}
|
package/dist/es/index.mjs
CHANGED
|
@@ -45,12 +45,13 @@ export { supportsBrowserAnimation } from './animation/waapi/supports/waapi.mjs';
|
|
|
45
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
|
+
export { addEffect, animateEffectSubject, animateValues, findEffect, removeEffect } from './animation/animate/effects.mjs';
|
|
49
|
+
export { animateElement, handOffElementState } from './animation/animate/element.mjs';
|
|
49
50
|
export { addAttrValue, attrEffect } from './effects/attr/index.mjs';
|
|
50
51
|
export { MotionValueState } from './effects/MotionValueState.mjs';
|
|
51
52
|
export { propEffect } from './effects/prop/index.mjs';
|
|
52
|
-
export { addStyleValue, styleEffect } from './effects/style/index.mjs';
|
|
53
|
-
export { svgEffect } from './effects/svg/index.mjs';
|
|
53
|
+
export { addStyleValue, readStyleValue, styleEffect, styleSubjectEffect } from './effects/style/index.mjs';
|
|
54
|
+
export { addSVGValue, readSVGValue, svgEffect, svgSubjectEffect } from './effects/svg/index.mjs';
|
|
54
55
|
export { createEffect } from './effects/utils/create-effect.mjs';
|
|
55
56
|
export { createRenderBatcher } from './frameloop/batcher.mjs';
|
|
56
57
|
export { cancelMicrotask, microtask } from './frameloop/microtask.mjs';
|
|
@@ -98,7 +99,7 @@ export { hex } from './value/types/color/hex.mjs';
|
|
|
98
99
|
export { hsla } from './value/types/color/hsla.mjs';
|
|
99
100
|
export { hslaToRgba } from './value/types/color/hsla-to-rgba.mjs';
|
|
100
101
|
export { rgbUnit, rgba } from './value/types/color/rgba.mjs';
|
|
101
|
-
export { analyseComplexValue, complex } from './value/types/complex/index.mjs';
|
|
102
|
+
export { analyseComplexValue, complex, hasComplexValues } from './value/types/complex/index.mjs';
|
|
102
103
|
export { dimensionValueTypes, findDimensionValueType } from './value/types/dimensions.mjs';
|
|
103
104
|
export { defaultValueTypes, getDefaultValueType } from './value/types/maps/defaults.mjs';
|
|
104
105
|
export { numberValueTypes } from './value/types/maps/number.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|