motion-dom 12.9.4 → 12.10.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 +727 -623
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +1 -1
- package/dist/es/effects/MotionValueState.mjs +41 -0
- package/dist/es/effects/style/index.mjs +51 -0
- package/dist/es/effects/style/transform.mjs +38 -0
- package/dist/es/gestures/press/index.mjs +4 -2
- package/dist/es/index.mjs +1 -1
- package/dist/es/value/index.mjs +20 -0
- package/dist/index.d.ts +8 -0
- package/dist/motion-dom.dev.js +727 -623
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -0
- package/dist/size-rollup-style-effect.js +1 -0
- package/package.json +14 -3
- package/dist/es/effects/style-effect.mjs +0 -36
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { frame, cancelFrame } from '../frameloop/frame.mjs';
|
|
2
|
+
import { numberValueTypes } from '../value/types/maps/number.mjs';
|
|
3
|
+
import { getValueAsType } from '../value/types/utils/get-as-type.mjs';
|
|
4
|
+
|
|
5
|
+
class MotionValueState {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.latest = {};
|
|
8
|
+
this.values = new Map();
|
|
9
|
+
}
|
|
10
|
+
set(name, value, render, computed) {
|
|
11
|
+
const existingValue = this.values.get(name);
|
|
12
|
+
if (existingValue) {
|
|
13
|
+
existingValue.onRemove();
|
|
14
|
+
}
|
|
15
|
+
const onChange = () => {
|
|
16
|
+
this.latest[name] = getValueAsType(value.get(), numberValueTypes[name]);
|
|
17
|
+
render && frame.render(render);
|
|
18
|
+
};
|
|
19
|
+
onChange();
|
|
20
|
+
const cancelOnChange = value.on("change", onChange);
|
|
21
|
+
computed && value.addDependent(computed);
|
|
22
|
+
const remove = () => {
|
|
23
|
+
cancelOnChange();
|
|
24
|
+
render && cancelFrame(render);
|
|
25
|
+
this.values.delete(name);
|
|
26
|
+
computed && value.removeDependent(computed);
|
|
27
|
+
};
|
|
28
|
+
this.values.set(name, { value, onRemove: remove });
|
|
29
|
+
return remove;
|
|
30
|
+
}
|
|
31
|
+
get(name) {
|
|
32
|
+
return this.values.get(name)?.value;
|
|
33
|
+
}
|
|
34
|
+
destroy() {
|
|
35
|
+
for (const value of this.values.values()) {
|
|
36
|
+
value.onRemove();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { MotionValueState };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isCSSVar } from '../../render/dom/is-css-var.mjs';
|
|
2
|
+
import { transformProps } from '../../render/utils/keys-transform.mjs';
|
|
3
|
+
import { resolveElements } from '../../utils/resolve-elements.mjs';
|
|
4
|
+
import { MotionValue } from '../../value/index.mjs';
|
|
5
|
+
import { MotionValueState } from '../MotionValueState.mjs';
|
|
6
|
+
import { buildTransform } from './transform.mjs';
|
|
7
|
+
|
|
8
|
+
const stateMap = new WeakMap();
|
|
9
|
+
function styleEffect(subject, values) {
|
|
10
|
+
const elements = resolveElements(subject);
|
|
11
|
+
const subscriptions = [];
|
|
12
|
+
for (let i = 0; i < elements.length; i++) {
|
|
13
|
+
const element = elements[i];
|
|
14
|
+
const state = stateMap.get(element) ?? new MotionValueState();
|
|
15
|
+
stateMap.set(element, state);
|
|
16
|
+
for (const key in values) {
|
|
17
|
+
const value = values[key];
|
|
18
|
+
const remove = addValue(element, state, key, value);
|
|
19
|
+
subscriptions.push(remove);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
for (const cancel of subscriptions)
|
|
24
|
+
cancel();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function addValue(element, state, key, value) {
|
|
28
|
+
let render = undefined;
|
|
29
|
+
let computed = undefined;
|
|
30
|
+
if (transformProps.has(key)) {
|
|
31
|
+
if (!state.get("transform")) {
|
|
32
|
+
state.set("transform", new MotionValue("none"), () => {
|
|
33
|
+
element.style.transform = buildTransform(state);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
computed = state.get("transform");
|
|
37
|
+
}
|
|
38
|
+
else if (isCSSVar(key)) {
|
|
39
|
+
render = () => {
|
|
40
|
+
element.style.setProperty(key, state.latest[key]);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
render = () => {
|
|
45
|
+
element.style[key] = state.latest[key];
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return state.set(key, value, render, computed);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { styleEffect };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { transformPropOrder } from '../../render/utils/keys-transform.mjs';
|
|
2
|
+
|
|
3
|
+
const translateAlias = {
|
|
4
|
+
x: "translateX",
|
|
5
|
+
y: "translateY",
|
|
6
|
+
z: "translateZ",
|
|
7
|
+
transformPerspective: "perspective",
|
|
8
|
+
};
|
|
9
|
+
function buildTransform(state) {
|
|
10
|
+
let transform = "";
|
|
11
|
+
let transformIsDefault = true;
|
|
12
|
+
/**
|
|
13
|
+
* Loop over all possible transforms in order, adding the ones that
|
|
14
|
+
* are present to the transform string.
|
|
15
|
+
*/
|
|
16
|
+
for (let i = 0; i < transformPropOrder.length; i++) {
|
|
17
|
+
const key = transformPropOrder[i];
|
|
18
|
+
const value = state.latest[key];
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
let valueIsDefault = true;
|
|
22
|
+
if (typeof value === "number") {
|
|
23
|
+
valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
valueIsDefault = parseFloat(value) === 0;
|
|
27
|
+
}
|
|
28
|
+
if (!valueIsDefault) {
|
|
29
|
+
transformIsDefault = false;
|
|
30
|
+
const transformName = translateAlias[key] || key;
|
|
31
|
+
const valueToRender = state.latest[key];
|
|
32
|
+
transform += `${transformName}(${valueToRender}) `;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return transformIsDefault ? "none" : transform.trim();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { buildTransform };
|
|
@@ -43,10 +43,12 @@ function press(targetOrSelector, onPressStart, options = {}) {
|
|
|
43
43
|
const onPointerEnd = (endEvent, success) => {
|
|
44
44
|
window.removeEventListener("pointerup", onPointerUp);
|
|
45
45
|
window.removeEventListener("pointercancel", onPointerCancel);
|
|
46
|
-
if (
|
|
46
|
+
if (isPressing.has(target)) {
|
|
47
|
+
isPressing.delete(target);
|
|
48
|
+
}
|
|
49
|
+
if (!isValidPressEvent(endEvent)) {
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
|
-
isPressing.delete(target);
|
|
50
52
|
if (typeof onPressEnd === "function") {
|
|
51
53
|
onPressEnd(endEvent, { success });
|
|
52
54
|
}
|
package/dist/es/index.mjs
CHANGED
|
@@ -31,7 +31,7 @@ export { supportsPartialKeyframes } from './animation/waapi/supports/partial-key
|
|
|
31
31
|
export { supportsBrowserAnimation } from './animation/waapi/supports/waapi.mjs';
|
|
32
32
|
export { acceleratedValues } from './animation/waapi/utils/accelerated-values.mjs';
|
|
33
33
|
export { generateLinearEasing } from './animation/waapi/utils/linear.mjs';
|
|
34
|
-
export { styleEffect } from './effects/style
|
|
34
|
+
export { styleEffect } from './effects/style/index.mjs';
|
|
35
35
|
export { createRenderBatcher } from './frameloop/batcher.mjs';
|
|
36
36
|
export { cancelMicrotask, microtask } from './frameloop/microtask.mjs';
|
|
37
37
|
export { time } from './frameloop/sync-time.mjs';
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -58,6 +58,11 @@ class MotionValue {
|
|
|
58
58
|
// Update update subscribers
|
|
59
59
|
if (this.current !== this.prev) {
|
|
60
60
|
this.events.change?.notify(this.current);
|
|
61
|
+
if (this.dependents) {
|
|
62
|
+
for (const dependent of this.dependents) {
|
|
63
|
+
dependent.dirty();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
// Update render subscribers
|
|
63
68
|
if (render) {
|
|
@@ -199,6 +204,20 @@ class MotionValue {
|
|
|
199
204
|
if (this.stopPassiveEffect)
|
|
200
205
|
this.stopPassiveEffect();
|
|
201
206
|
}
|
|
207
|
+
dirty() {
|
|
208
|
+
this.events.change?.notify(this.current);
|
|
209
|
+
}
|
|
210
|
+
addDependent(dependent) {
|
|
211
|
+
if (!this.dependents) {
|
|
212
|
+
this.dependents = new Set();
|
|
213
|
+
}
|
|
214
|
+
this.dependents.add(dependent);
|
|
215
|
+
}
|
|
216
|
+
removeDependent(dependent) {
|
|
217
|
+
if (this.dependents) {
|
|
218
|
+
this.dependents.delete(dependent);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
202
221
|
/**
|
|
203
222
|
* Returns the latest state of `MotionValue`
|
|
204
223
|
*
|
|
@@ -297,6 +316,7 @@ class MotionValue {
|
|
|
297
316
|
* @public
|
|
298
317
|
*/
|
|
299
318
|
destroy() {
|
|
319
|
+
this.dependents?.clear();
|
|
300
320
|
this.events.destroy?.notify();
|
|
301
321
|
this.clearListeners();
|
|
302
322
|
this.stop();
|
package/dist/index.d.ts
CHANGED
|
@@ -580,6 +580,11 @@ declare class MotionValue<V = any> {
|
|
|
580
580
|
* A reference to the currently-controlling animation.
|
|
581
581
|
*/
|
|
582
582
|
animation?: AnimationPlaybackControlsWithThen;
|
|
583
|
+
/**
|
|
584
|
+
* A list of MotionValues whose values are computed from this one.
|
|
585
|
+
* This is a rough start to a proper signal-like dirtying system.
|
|
586
|
+
*/
|
|
587
|
+
private dependents;
|
|
583
588
|
/**
|
|
584
589
|
* Tracks whether this value should be removed
|
|
585
590
|
*/
|
|
@@ -666,6 +671,9 @@ declare class MotionValue<V = any> {
|
|
|
666
671
|
* effects, and resets velocity to `0`.
|
|
667
672
|
*/
|
|
668
673
|
jump(v: V, endAnimation?: boolean): void;
|
|
674
|
+
dirty(): void;
|
|
675
|
+
addDependent(dependent: MotionValue): void;
|
|
676
|
+
removeDependent(dependent: MotionValue): void;
|
|
669
677
|
updateAndNotify: (v: V, render?: boolean) => void;
|
|
670
678
|
/**
|
|
671
679
|
* Returns the latest state of `MotionValue`
|