motion 12.8.0 → 12.9.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 +92 -89
- package/dist/cjs/mini.js +6 -1
- package/dist/cjs/react-client.js +106 -184
- package/dist/cjs/react-m.js +17 -141
- package/dist/cjs/react-mini.js +6 -1
- package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +11 -0
- package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +1 -10
- package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +1 -3
- package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +0 -12
- package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +0 -45
- package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.mjs +16 -11
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/motion/lib/index.mjs +1 -0
- package/dist/es/motion/lib/react.mjs +1 -0
- package/dist/es/motion-dom/dist/es/animation/AsyncMotionValueAnimation.mjs +2 -7
- package/dist/es/motion-dom/dist/es/animation/JSAnimation.mjs +1 -1
- package/dist/es/motion-dom/dist/es/animation/NativeAnimation.mjs +6 -1
- package/dist/es/motion-dom/dist/es/effects/style-effect.mjs +36 -0
- package/dist/es/motion-dom/dist/es/value/index.mjs +5 -7
- package/dist/motion.dev.js +92 -89
- package/dist/motion.js +1 -1
- package/package.json +3 -3
- package/dist/es/framer-motion/dist/es/render/svg/utils/measure.mjs +0 -19
- package/dist/es/framer-motion/dist/es/render/svg/utils/transform-origin.mjs +0 -18
package/dist/motion.dev.js
CHANGED
|
@@ -1866,7 +1866,6 @@
|
|
|
1866
1866
|
this.holdTime = null;
|
|
1867
1867
|
}
|
|
1868
1868
|
finish() {
|
|
1869
|
-
this.notifyFinished();
|
|
1870
1869
|
this.teardown();
|
|
1871
1870
|
this.state = "finished";
|
|
1872
1871
|
const { onComplete } = this.options;
|
|
@@ -1879,6 +1878,7 @@
|
|
|
1879
1878
|
this.teardown();
|
|
1880
1879
|
}
|
|
1881
1880
|
teardown() {
|
|
1881
|
+
this.notifyFinished();
|
|
1882
1882
|
this.state = "idle";
|
|
1883
1883
|
this.stopDriver();
|
|
1884
1884
|
this.startTime = this.holdTime = null;
|
|
@@ -2331,7 +2331,7 @@
|
|
|
2331
2331
|
this.isStopped = false;
|
|
2332
2332
|
if (!options)
|
|
2333
2333
|
return;
|
|
2334
|
-
const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, } = options;
|
|
2334
|
+
const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, onComplete, } = options;
|
|
2335
2335
|
this.isPseudoElement = Boolean(pseudoElement);
|
|
2336
2336
|
this.allowFlatten = allowFlatten;
|
|
2337
2337
|
this.options = options;
|
|
@@ -2357,8 +2357,13 @@
|
|
|
2357
2357
|
}
|
|
2358
2358
|
this.animation.cancel();
|
|
2359
2359
|
}
|
|
2360
|
+
onComplete?.();
|
|
2360
2361
|
this.notifyFinished();
|
|
2361
2362
|
};
|
|
2363
|
+
/**
|
|
2364
|
+
* TODO: In a breaking change, we should replace this with `.notifyCancel()`
|
|
2365
|
+
*/
|
|
2366
|
+
this.animation.oncancel = () => this.notifyFinished();
|
|
2362
2367
|
}
|
|
2363
2368
|
play() {
|
|
2364
2369
|
if (this.isStopped)
|
|
@@ -2683,7 +2688,7 @@
|
|
|
2683
2688
|
}
|
|
2684
2689
|
onKeyframesResolved(keyframes, finalKeyframe, options, sync) {
|
|
2685
2690
|
this.keyframeResolver = undefined;
|
|
2686
|
-
const { name, type, velocity, delay, isHandoff, onUpdate
|
|
2691
|
+
const { name, type, velocity, delay, isHandoff, onUpdate } = options;
|
|
2687
2692
|
this.resolvedAt = time.now();
|
|
2688
2693
|
/**
|
|
2689
2694
|
* If we can't animate this value with the resolved keyframes
|
|
@@ -2733,12 +2738,7 @@
|
|
|
2733
2738
|
element: resolvedOptions.motionValue.owner.current,
|
|
2734
2739
|
})
|
|
2735
2740
|
: new JSAnimation(resolvedOptions);
|
|
2736
|
-
animation.finished
|
|
2737
|
-
.then(() => {
|
|
2738
|
-
onComplete?.();
|
|
2739
|
-
this.notifyFinished();
|
|
2740
|
-
})
|
|
2741
|
-
.catch(noop);
|
|
2741
|
+
animation.finished.then(() => this.notifyFinished()).catch(noop);
|
|
2742
2742
|
if (this.pendingTimeline) {
|
|
2743
2743
|
this.stopTimeline = animation.attachTimeline(this.pendingTimeline);
|
|
2744
2744
|
this.pendingTimeline = undefined;
|
|
@@ -3351,6 +3351,54 @@
|
|
|
3351
3351
|
// "background-color"
|
|
3352
3352
|
]);
|
|
3353
3353
|
|
|
3354
|
+
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
3355
|
+
if (elementOrSelector instanceof EventTarget) {
|
|
3356
|
+
return [elementOrSelector];
|
|
3357
|
+
}
|
|
3358
|
+
else if (typeof elementOrSelector === "string") {
|
|
3359
|
+
let root = document;
|
|
3360
|
+
if (scope) {
|
|
3361
|
+
root = scope.current;
|
|
3362
|
+
}
|
|
3363
|
+
const elements = selectorCache?.[elementOrSelector] ??
|
|
3364
|
+
root.querySelectorAll(elementOrSelector);
|
|
3365
|
+
return elements ? Array.from(elements) : [];
|
|
3366
|
+
}
|
|
3367
|
+
return Array.from(elementOrSelector);
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
function styleEffect(subject, values) {
|
|
3371
|
+
const elements = resolveElements(subject);
|
|
3372
|
+
const subscriptions = [];
|
|
3373
|
+
for (let i = 0; i < elements.length; i++) {
|
|
3374
|
+
const element = elements[i];
|
|
3375
|
+
for (const key in values) {
|
|
3376
|
+
const value = values[key];
|
|
3377
|
+
/**
|
|
3378
|
+
* TODO: Get specific setters for combined props (like x)
|
|
3379
|
+
* or values with default types (like color)
|
|
3380
|
+
*
|
|
3381
|
+
* TODO: CSS variable support
|
|
3382
|
+
*/
|
|
3383
|
+
const updateStyle = () => {
|
|
3384
|
+
element.style[key] = value.get();
|
|
3385
|
+
};
|
|
3386
|
+
const scheduleUpdate = () => frame.render(updateStyle);
|
|
3387
|
+
const cancel = value.on("change", scheduleUpdate);
|
|
3388
|
+
scheduleUpdate();
|
|
3389
|
+
subscriptions.push(() => {
|
|
3390
|
+
cancel();
|
|
3391
|
+
cancelFrame(updateStyle);
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
return () => {
|
|
3396
|
+
for (const cancel of subscriptions) {
|
|
3397
|
+
cancel();
|
|
3398
|
+
}
|
|
3399
|
+
};
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3354
3402
|
const { schedule: microtask, cancel: cancelMicrotask } =
|
|
3355
3403
|
/* @__PURE__ */ createRenderBatcher(queueMicrotask, false);
|
|
3356
3404
|
|
|
@@ -3387,22 +3435,6 @@
|
|
|
3387
3435
|
}
|
|
3388
3436
|
}
|
|
3389
3437
|
|
|
3390
|
-
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
3391
|
-
if (elementOrSelector instanceof EventTarget) {
|
|
3392
|
-
return [elementOrSelector];
|
|
3393
|
-
}
|
|
3394
|
-
else if (typeof elementOrSelector === "string") {
|
|
3395
|
-
let root = document;
|
|
3396
|
-
if (scope) {
|
|
3397
|
-
root = scope.current;
|
|
3398
|
-
}
|
|
3399
|
-
const elements = selectorCache?.[elementOrSelector] ??
|
|
3400
|
-
root.querySelectorAll(elementOrSelector);
|
|
3401
|
-
return elements ? Array.from(elements) : [];
|
|
3402
|
-
}
|
|
3403
|
-
return Array.from(elementOrSelector);
|
|
3404
|
-
}
|
|
3405
|
-
|
|
3406
3438
|
function setupGesture(elementOrSelector, options) {
|
|
3407
3439
|
const elements = resolveElements(elementOrSelector);
|
|
3408
3440
|
const gestureAbortController = new AbortController();
|
|
@@ -3777,7 +3809,7 @@
|
|
|
3777
3809
|
* This will be replaced by the build step with the latest version number.
|
|
3778
3810
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3779
3811
|
*/
|
|
3780
|
-
this.version = "12.
|
|
3812
|
+
this.version = "12.9.0";
|
|
3781
3813
|
/**
|
|
3782
3814
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
3783
3815
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -3803,12 +3835,12 @@
|
|
|
3803
3835
|
this.prev = this.current;
|
|
3804
3836
|
this.setCurrent(v);
|
|
3805
3837
|
// Update update subscribers
|
|
3806
|
-
if (this.current !== this.prev
|
|
3807
|
-
this.events.change
|
|
3838
|
+
if (this.current !== this.prev) {
|
|
3839
|
+
this.events.change?.notify(this.current);
|
|
3808
3840
|
}
|
|
3809
3841
|
// Update render subscribers
|
|
3810
|
-
if (render
|
|
3811
|
-
this.events.renderRequest
|
|
3842
|
+
if (render) {
|
|
3843
|
+
this.events.renderRequest?.notify(this.current);
|
|
3812
3844
|
}
|
|
3813
3845
|
};
|
|
3814
3846
|
this.hasAnimated = false;
|
|
@@ -3921,8 +3953,6 @@
|
|
|
3921
3953
|
* @public
|
|
3922
3954
|
*/
|
|
3923
3955
|
set(v, render = true) {
|
|
3924
|
-
if (v === "none")
|
|
3925
|
-
console.trace();
|
|
3926
3956
|
if (!render || !this.passiveEffect) {
|
|
3927
3957
|
this.updateAndNotify(v, render);
|
|
3928
3958
|
}
|
|
@@ -5101,6 +5131,17 @@
|
|
|
5101
5131
|
delay,
|
|
5102
5132
|
...getValueTransition$1(transition || {}, key),
|
|
5103
5133
|
};
|
|
5134
|
+
/**
|
|
5135
|
+
* If the value is already at the defined target, skip the animation.
|
|
5136
|
+
*/
|
|
5137
|
+
const currentValue = value.get();
|
|
5138
|
+
if (currentValue !== undefined &&
|
|
5139
|
+
!value.isAnimating &&
|
|
5140
|
+
!Array.isArray(valueTarget) &&
|
|
5141
|
+
valueTarget === currentValue &&
|
|
5142
|
+
!valueTransition.velocity) {
|
|
5143
|
+
continue;
|
|
5144
|
+
}
|
|
5104
5145
|
/**
|
|
5105
5146
|
* If this is the first time a value is being animated, check
|
|
5106
5147
|
* to see if we're handling off from an existing animation.
|
|
@@ -5240,7 +5281,7 @@
|
|
|
5240
5281
|
* and warn against mismatches.
|
|
5241
5282
|
*/
|
|
5242
5283
|
{
|
|
5243
|
-
warnOnce(nextValue.version === "12.
|
|
5284
|
+
warnOnce(nextValue.version === "12.9.0", `Attempting to mix Motion versions ${nextValue.version} with 12.9.0 may not work as expected.`);
|
|
5244
5285
|
}
|
|
5245
5286
|
}
|
|
5246
5287
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5373,8 +5414,7 @@
|
|
|
5373
5414
|
frame.render(this.render, false, true);
|
|
5374
5415
|
}
|
|
5375
5416
|
};
|
|
5376
|
-
const { latestValues, renderState
|
|
5377
|
-
this.onUpdate = onUpdate;
|
|
5417
|
+
const { latestValues, renderState } = visualState;
|
|
5378
5418
|
this.latestValues = latestValues;
|
|
5379
5419
|
this.baseTarget = { ...latestValues };
|
|
5380
5420
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -5576,7 +5616,6 @@
|
|
|
5576
5616
|
if (this.handleChildMotionValue) {
|
|
5577
5617
|
this.handleChildMotionValue();
|
|
5578
5618
|
}
|
|
5579
|
-
this.onUpdate && this.onUpdate(this);
|
|
5580
5619
|
}
|
|
5581
5620
|
getProps() {
|
|
5582
5621
|
return this.props;
|
|
@@ -5918,25 +5957,10 @@
|
|
|
5918
5957
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
5919
5958
|
}
|
|
5920
5959
|
|
|
5921
|
-
function calcOrigin(origin, offset, size) {
|
|
5922
|
-
return typeof origin === "string"
|
|
5923
|
-
? origin
|
|
5924
|
-
: px.transform(offset + size * origin);
|
|
5925
|
-
}
|
|
5926
|
-
/**
|
|
5927
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5928
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5929
|
-
*/
|
|
5930
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5931
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
5932
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
5933
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
5934
|
-
}
|
|
5935
|
-
|
|
5936
5960
|
/**
|
|
5937
5961
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
5938
5962
|
*/
|
|
5939
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
5963
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
5940
5964
|
// This is object creation, which we try to avoid per-frame.
|
|
5941
5965
|
...latest }, isSVGTag, transformTemplate) {
|
|
5942
5966
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -5952,20 +5976,26 @@
|
|
|
5952
5976
|
}
|
|
5953
5977
|
state.attrs = state.style;
|
|
5954
5978
|
state.style = {};
|
|
5955
|
-
const { attrs, style
|
|
5979
|
+
const { attrs, style } = state;
|
|
5956
5980
|
/**
|
|
5957
|
-
* However, we apply transforms as CSS transforms.
|
|
5958
|
-
* and copy it into style.
|
|
5981
|
+
* However, we apply transforms as CSS transforms.
|
|
5982
|
+
* So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
|
|
5959
5983
|
*/
|
|
5960
5984
|
if (attrs.transform) {
|
|
5961
|
-
|
|
5962
|
-
style.transform = attrs.transform;
|
|
5985
|
+
style.transform = attrs.transform;
|
|
5963
5986
|
delete attrs.transform;
|
|
5964
5987
|
}
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5988
|
+
if (style.transform || attrs.transformOrigin) {
|
|
5989
|
+
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
5990
|
+
delete attrs.transformOrigin;
|
|
5991
|
+
}
|
|
5992
|
+
if (style.transform) {
|
|
5993
|
+
/**
|
|
5994
|
+
* SVG's element transform-origin uses its own median as a reference.
|
|
5995
|
+
* Therefore, transformBox becomes a fill-box
|
|
5996
|
+
*/
|
|
5997
|
+
style.transformBox = "fill-box";
|
|
5998
|
+
delete attrs.transformBox;
|
|
5969
5999
|
}
|
|
5970
6000
|
// Render attrX/attrY/attrScale as attributes
|
|
5971
6001
|
if (attrX !== undefined)
|
|
@@ -6011,24 +6041,6 @@
|
|
|
6011
6041
|
|
|
6012
6042
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
6013
6043
|
|
|
6014
|
-
function updateSVGDimensions(instance, renderState) {
|
|
6015
|
-
try {
|
|
6016
|
-
renderState.dimensions =
|
|
6017
|
-
typeof instance.getBBox === "function"
|
|
6018
|
-
? instance.getBBox()
|
|
6019
|
-
: instance.getBoundingClientRect();
|
|
6020
|
-
}
|
|
6021
|
-
catch (e) {
|
|
6022
|
-
// Most likely trying to measure an unrendered element under Firefox
|
|
6023
|
-
renderState.dimensions = {
|
|
6024
|
-
x: 0,
|
|
6025
|
-
y: 0,
|
|
6026
|
-
width: 0,
|
|
6027
|
-
height: 0,
|
|
6028
|
-
};
|
|
6029
|
-
}
|
|
6030
|
-
}
|
|
6031
|
-
|
|
6032
6044
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
6033
6045
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
6034
6046
|
// Loop over any CSS variables and assign those.
|
|
@@ -6088,11 +6100,6 @@
|
|
|
6088
6100
|
this.type = "svg";
|
|
6089
6101
|
this.isSVGTag = false;
|
|
6090
6102
|
this.measureInstanceViewportBox = createBox;
|
|
6091
|
-
this.updateDimensions = () => {
|
|
6092
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6093
|
-
updateSVGDimensions(this.current, this.renderState);
|
|
6094
|
-
}
|
|
6095
|
-
};
|
|
6096
6103
|
}
|
|
6097
6104
|
getBaseTargetFromProps(props, key) {
|
|
6098
6105
|
return props[key];
|
|
@@ -6108,11 +6115,6 @@
|
|
|
6108
6115
|
scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6109
6116
|
return scrapeMotionValuesFromProps(props, prevProps, visualElement);
|
|
6110
6117
|
}
|
|
6111
|
-
onBindTransform() {
|
|
6112
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6113
|
-
frame.postRender(this.updateDimensions);
|
|
6114
|
-
}
|
|
6115
|
-
}
|
|
6116
6118
|
build(renderState, latestValues, props) {
|
|
6117
6119
|
buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
|
|
6118
6120
|
}
|
|
@@ -7215,6 +7217,7 @@
|
|
|
7215
7217
|
exports.startWaapiAnimation = startWaapiAnimation;
|
|
7216
7218
|
exports.statsBuffer = statsBuffer;
|
|
7217
7219
|
exports.steps = steps;
|
|
7220
|
+
exports.styleEffect = styleEffect;
|
|
7218
7221
|
exports.supportedWaapiEasing = supportedWaapiEasing;
|
|
7219
7222
|
exports.supportsBrowserAnimation = supportsBrowserAnimation;
|
|
7220
7223
|
exports.supportsFlags = supportsFlags;
|