framer-motion 11.18.0 → 11.18.2
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/client.js +35 -29
- package/dist/cjs/dom-mini.js +4 -1
- package/dist/cjs/dom.js +33 -26
- package/dist/cjs/index.js +39 -30
- package/dist/cjs/m.js +21 -19
- package/dist/cjs/mini.js +4 -1
- package/dist/client.d.ts +5 -4
- package/dist/dom-mini.d.ts +2 -1
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +2 -1
- package/dist/dom.js +1 -1
- package/dist/es/animation/animators/AcceleratedAnimation.mjs +9 -6
- package/dist/es/animation/animators/BaseAnimation.mjs +3 -2
- package/dist/es/animation/animators/waapi/NativeAnimation.mjs +4 -1
- package/dist/es/render/svg/config-motion.mjs +6 -4
- package/dist/es/render/svg/utils/build-attrs.mjs +1 -1
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/framer-motion.dev.js +44 -30
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/m.d.ts +5 -4
- package/dist/mini.js +1 -1
- package/dist/three.d.ts +2 -1
- package/package.json +4 -4
package/dist/cjs/client.js
CHANGED
|
@@ -409,7 +409,7 @@ class MotionValue {
|
|
|
409
409
|
* This will be replaced by the build step with the latest version number.
|
|
410
410
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
411
411
|
*/
|
|
412
|
-
this.version = "11.18.
|
|
412
|
+
this.version = "11.18.2";
|
|
413
413
|
/**
|
|
414
414
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
415
415
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1797,8 +1797,9 @@ class BaseAnimation {
|
|
|
1797
1797
|
if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
|
|
1798
1798
|
// Finish immediately
|
|
1799
1799
|
if (!delay) {
|
|
1800
|
-
onUpdate
|
|
1801
|
-
|
|
1800
|
+
onUpdate &&
|
|
1801
|
+
onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
|
|
1802
|
+
onComplete && onComplete();
|
|
1802
1803
|
this.resolveFinishedPromise();
|
|
1803
1804
|
return;
|
|
1804
1805
|
}
|
|
@@ -3071,13 +3072,12 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3071
3072
|
this.resolver.scheduleResolve();
|
|
3072
3073
|
}
|
|
3073
3074
|
initPlayback(keyframes, finalKeyframe) {
|
|
3074
|
-
var _a;
|
|
3075
3075
|
let { duration = 300, times, ease, type, motionValue, name, startTime, } = this.options;
|
|
3076
3076
|
/**
|
|
3077
3077
|
* If element has since been unmounted, return false to indicate
|
|
3078
3078
|
* the animation failed to initialised.
|
|
3079
3079
|
*/
|
|
3080
|
-
if (!
|
|
3080
|
+
if (!motionValue.owner || !motionValue.owner.current) {
|
|
3081
3081
|
return false;
|
|
3082
3082
|
}
|
|
3083
3083
|
/**
|
|
@@ -3284,17 +3284,21 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3284
3284
|
}
|
|
3285
3285
|
static supports(options) {
|
|
3286
3286
|
const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
|
|
3287
|
+
if (!motionValue ||
|
|
3288
|
+
!motionValue.owner ||
|
|
3289
|
+
!(motionValue.owner.current instanceof HTMLElement)) {
|
|
3290
|
+
return false;
|
|
3291
|
+
}
|
|
3292
|
+
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
3287
3293
|
return (supportsWaapi() &&
|
|
3288
3294
|
name &&
|
|
3289
3295
|
acceleratedValues.has(name) &&
|
|
3290
|
-
motionValue &&
|
|
3291
|
-
motionValue.owner &&
|
|
3292
|
-
motionValue.owner.current instanceof HTMLElement &&
|
|
3293
3296
|
/**
|
|
3294
3297
|
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
3295
3298
|
* no way to read the value from WAAPI every frame.
|
|
3296
3299
|
*/
|
|
3297
|
-
!
|
|
3300
|
+
!onUpdate &&
|
|
3301
|
+
!transformTemplate &&
|
|
3298
3302
|
!repeatDelay &&
|
|
3299
3303
|
repeatType !== "mirror" &&
|
|
3300
3304
|
damping !== 0 &&
|
|
@@ -5201,7 +5205,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5201
5205
|
* and warn against mismatches.
|
|
5202
5206
|
*/
|
|
5203
5207
|
if (process.env.NODE_ENV === "development") {
|
|
5204
|
-
warnOnce(nextValue.version === "11.18.
|
|
5208
|
+
warnOnce(nextValue.version === "11.18.2", `Attempting to mix Motion versions ${nextValue.version} with 11.18.2 may not work as expected.`);
|
|
5205
5209
|
}
|
|
5206
5210
|
}
|
|
5207
5211
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5858,21 +5862,6 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
5858
5862
|
}
|
|
5859
5863
|
}
|
|
5860
5864
|
|
|
5861
|
-
function calcOrigin(origin, offset, size) {
|
|
5862
|
-
return typeof origin === "string"
|
|
5863
|
-
? origin
|
|
5864
|
-
: px.transform(offset + size * origin);
|
|
5865
|
-
}
|
|
5866
|
-
/**
|
|
5867
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5868
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5869
|
-
*/
|
|
5870
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5871
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
5872
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
5873
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
5874
|
-
}
|
|
5875
|
-
|
|
5876
5865
|
const dashKeys = {
|
|
5877
5866
|
offset: "stroke-dashoffset",
|
|
5878
5867
|
array: "stroke-dasharray",
|
|
@@ -5902,6 +5891,21 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
5902
5891
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
5903
5892
|
}
|
|
5904
5893
|
|
|
5894
|
+
function calcOrigin(origin, offset, size) {
|
|
5895
|
+
return typeof origin === "string"
|
|
5896
|
+
? origin
|
|
5897
|
+
: px.transform(offset + size * origin);
|
|
5898
|
+
}
|
|
5899
|
+
/**
|
|
5900
|
+
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5901
|
+
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5902
|
+
*/
|
|
5903
|
+
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5904
|
+
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
5905
|
+
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
5906
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
5907
|
+
}
|
|
5908
|
+
|
|
5905
5909
|
/**
|
|
5906
5910
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
5907
5911
|
*/
|
|
@@ -9086,10 +9090,12 @@ const svgMotionConfig = {
|
|
|
9086
9090
|
}
|
|
9087
9091
|
if (!needsMeasure)
|
|
9088
9092
|
return;
|
|
9089
|
-
frame.read(() =>
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
+
frame.read(() => {
|
|
9094
|
+
updateSVGDimensions(current, renderState);
|
|
9095
|
+
frame.render(() => {
|
|
9096
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
9097
|
+
renderSVG(current, renderState);
|
|
9098
|
+
});
|
|
9093
9099
|
});
|
|
9094
9100
|
},
|
|
9095
9101
|
}),
|
package/dist/cjs/dom-mini.js
CHANGED
|
@@ -550,7 +550,10 @@ class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
|
550
550
|
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
551
551
|
this.options = options;
|
|
552
552
|
this.updateFinishedPromise();
|
|
553
|
-
this.removeAnimation = () => {
|
|
553
|
+
this.removeAnimation = () => {
|
|
554
|
+
const elementState = state.get(element);
|
|
555
|
+
elementState && elementState.delete(valueName);
|
|
556
|
+
};
|
|
554
557
|
};
|
|
555
558
|
if (!supportsWaapi()) {
|
|
556
559
|
super();
|
package/dist/cjs/dom.js
CHANGED
|
@@ -994,7 +994,7 @@ class MotionValue {
|
|
|
994
994
|
* This will be replaced by the build step with the latest version number.
|
|
995
995
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
996
996
|
*/
|
|
997
|
-
this.version = "11.18.
|
|
997
|
+
this.version = "11.18.2";
|
|
998
998
|
/**
|
|
999
999
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
1000
1000
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -2412,8 +2412,9 @@ class BaseAnimation {
|
|
|
2412
2412
|
if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
|
|
2413
2413
|
// Finish immediately
|
|
2414
2414
|
if (!delay) {
|
|
2415
|
-
onUpdate
|
|
2416
|
-
|
|
2415
|
+
onUpdate &&
|
|
2416
|
+
onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
|
|
2417
|
+
onComplete && onComplete();
|
|
2417
2418
|
this.resolveFinishedPromise();
|
|
2418
2419
|
return;
|
|
2419
2420
|
}
|
|
@@ -3373,13 +3374,12 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3373
3374
|
this.resolver.scheduleResolve();
|
|
3374
3375
|
}
|
|
3375
3376
|
initPlayback(keyframes, finalKeyframe) {
|
|
3376
|
-
var _a;
|
|
3377
3377
|
let { duration = 300, times, ease, type, motionValue, name, startTime, } = this.options;
|
|
3378
3378
|
/**
|
|
3379
3379
|
* If element has since been unmounted, return false to indicate
|
|
3380
3380
|
* the animation failed to initialised.
|
|
3381
3381
|
*/
|
|
3382
|
-
if (!
|
|
3382
|
+
if (!motionValue.owner || !motionValue.owner.current) {
|
|
3383
3383
|
return false;
|
|
3384
3384
|
}
|
|
3385
3385
|
/**
|
|
@@ -3586,17 +3586,21 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3586
3586
|
}
|
|
3587
3587
|
static supports(options) {
|
|
3588
3588
|
const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
|
|
3589
|
+
if (!motionValue ||
|
|
3590
|
+
!motionValue.owner ||
|
|
3591
|
+
!(motionValue.owner.current instanceof HTMLElement)) {
|
|
3592
|
+
return false;
|
|
3593
|
+
}
|
|
3594
|
+
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
3589
3595
|
return (supportsWaapi() &&
|
|
3590
3596
|
name &&
|
|
3591
3597
|
acceleratedValues.has(name) &&
|
|
3592
|
-
motionValue &&
|
|
3593
|
-
motionValue.owner &&
|
|
3594
|
-
motionValue.owner.current instanceof HTMLElement &&
|
|
3595
3598
|
/**
|
|
3596
3599
|
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
3597
3600
|
* no way to read the value from WAAPI every frame.
|
|
3598
3601
|
*/
|
|
3599
|
-
!
|
|
3602
|
+
!onUpdate &&
|
|
3603
|
+
!transformTemplate &&
|
|
3600
3604
|
!repeatDelay &&
|
|
3601
3605
|
repeatType !== "mirror" &&
|
|
3602
3606
|
damping !== 0 &&
|
|
@@ -3924,7 +3928,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3924
3928
|
* and warn against mismatches.
|
|
3925
3929
|
*/
|
|
3926
3930
|
if (process.env.NODE_ENV === "development") {
|
|
3927
|
-
warnOnce(nextValue.version === "11.18.
|
|
3931
|
+
warnOnce(nextValue.version === "11.18.2", `Attempting to mix Motion versions ${nextValue.version} with 11.18.2 may not work as expected.`);
|
|
3928
3932
|
}
|
|
3929
3933
|
}
|
|
3930
3934
|
else if (isMotionValue(prevValue)) {
|
|
@@ -4581,21 +4585,6 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
4581
4585
|
}
|
|
4582
4586
|
}
|
|
4583
4587
|
|
|
4584
|
-
function calcOrigin(origin, offset, size) {
|
|
4585
|
-
return typeof origin === "string"
|
|
4586
|
-
? origin
|
|
4587
|
-
: px.transform(offset + size * origin);
|
|
4588
|
-
}
|
|
4589
|
-
/**
|
|
4590
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
4591
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
4592
|
-
*/
|
|
4593
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
4594
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
4595
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
4596
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
4597
|
-
}
|
|
4598
|
-
|
|
4599
4588
|
const dashKeys = {
|
|
4600
4589
|
offset: "stroke-dashoffset",
|
|
4601
4590
|
array: "stroke-dasharray",
|
|
@@ -4625,6 +4614,21 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
4625
4614
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
4626
4615
|
}
|
|
4627
4616
|
|
|
4617
|
+
function calcOrigin(origin, offset, size) {
|
|
4618
|
+
return typeof origin === "string"
|
|
4619
|
+
? origin
|
|
4620
|
+
: px.transform(offset + size * origin);
|
|
4621
|
+
}
|
|
4622
|
+
/**
|
|
4623
|
+
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
4624
|
+
* so we use the measured dimensions of the SVG to reconcile these.
|
|
4625
|
+
*/
|
|
4626
|
+
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
4627
|
+
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
4628
|
+
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
4629
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4628
4632
|
/**
|
|
4629
4633
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
4630
4634
|
*/
|
|
@@ -5090,7 +5094,10 @@ class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
|
5090
5094
|
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
5091
5095
|
this.options = options;
|
|
5092
5096
|
this.updateFinishedPromise();
|
|
5093
|
-
this.removeAnimation = () => {
|
|
5097
|
+
this.removeAnimation = () => {
|
|
5098
|
+
const elementState = state.get(element);
|
|
5099
|
+
elementState && elementState.delete(valueName);
|
|
5100
|
+
};
|
|
5094
5101
|
};
|
|
5095
5102
|
if (!supportsWaapi()) {
|
|
5096
5103
|
super();
|
package/dist/cjs/index.js
CHANGED
|
@@ -445,7 +445,7 @@ class MotionValue {
|
|
|
445
445
|
* This will be replaced by the build step with the latest version number.
|
|
446
446
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
447
447
|
*/
|
|
448
|
-
this.version = "11.18.
|
|
448
|
+
this.version = "11.18.2";
|
|
449
449
|
/**
|
|
450
450
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
451
451
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1840,8 +1840,9 @@ class BaseAnimation {
|
|
|
1840
1840
|
if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
|
|
1841
1841
|
// Finish immediately
|
|
1842
1842
|
if (instantAnimationState.current || !delay) {
|
|
1843
|
-
onUpdate
|
|
1844
|
-
|
|
1843
|
+
onUpdate &&
|
|
1844
|
+
onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
|
|
1845
|
+
onComplete && onComplete();
|
|
1845
1846
|
this.resolveFinishedPromise();
|
|
1846
1847
|
return;
|
|
1847
1848
|
}
|
|
@@ -3118,13 +3119,12 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3118
3119
|
this.resolver.scheduleResolve();
|
|
3119
3120
|
}
|
|
3120
3121
|
initPlayback(keyframes, finalKeyframe) {
|
|
3121
|
-
var _a;
|
|
3122
3122
|
let { duration = 300, times, ease, type, motionValue, name, startTime, } = this.options;
|
|
3123
3123
|
/**
|
|
3124
3124
|
* If element has since been unmounted, return false to indicate
|
|
3125
3125
|
* the animation failed to initialised.
|
|
3126
3126
|
*/
|
|
3127
|
-
if (!
|
|
3127
|
+
if (!motionValue.owner || !motionValue.owner.current) {
|
|
3128
3128
|
return false;
|
|
3129
3129
|
}
|
|
3130
3130
|
/**
|
|
@@ -3331,17 +3331,21 @@ class AcceleratedAnimation extends BaseAnimation {
|
|
|
3331
3331
|
}
|
|
3332
3332
|
static supports(options) {
|
|
3333
3333
|
const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
|
|
3334
|
+
if (!motionValue ||
|
|
3335
|
+
!motionValue.owner ||
|
|
3336
|
+
!(motionValue.owner.current instanceof HTMLElement)) {
|
|
3337
|
+
return false;
|
|
3338
|
+
}
|
|
3339
|
+
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
3334
3340
|
return (supportsWaapi() &&
|
|
3335
3341
|
name &&
|
|
3336
3342
|
acceleratedValues.has(name) &&
|
|
3337
|
-
motionValue &&
|
|
3338
|
-
motionValue.owner &&
|
|
3339
|
-
motionValue.owner.current instanceof HTMLElement &&
|
|
3340
3343
|
/**
|
|
3341
3344
|
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
3342
3345
|
* no way to read the value from WAAPI every frame.
|
|
3343
3346
|
*/
|
|
3344
|
-
!
|
|
3347
|
+
!onUpdate &&
|
|
3348
|
+
!transformTemplate &&
|
|
3345
3349
|
!repeatDelay &&
|
|
3346
3350
|
repeatType !== "mirror" &&
|
|
3347
3351
|
damping !== 0 &&
|
|
@@ -5215,7 +5219,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5215
5219
|
* and warn against mismatches.
|
|
5216
5220
|
*/
|
|
5217
5221
|
if (process.env.NODE_ENV === "development") {
|
|
5218
|
-
warnOnce(nextValue.version === "11.18.
|
|
5222
|
+
warnOnce(nextValue.version === "11.18.2", `Attempting to mix Motion versions ${nextValue.version} with 11.18.2 may not work as expected.`);
|
|
5219
5223
|
}
|
|
5220
5224
|
}
|
|
5221
5225
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5872,21 +5876,6 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
5872
5876
|
}
|
|
5873
5877
|
}
|
|
5874
5878
|
|
|
5875
|
-
function calcOrigin$1(origin, offset, size) {
|
|
5876
|
-
return typeof origin === "string"
|
|
5877
|
-
? origin
|
|
5878
|
-
: px.transform(offset + size * origin);
|
|
5879
|
-
}
|
|
5880
|
-
/**
|
|
5881
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5882
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5883
|
-
*/
|
|
5884
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5885
|
-
const pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
|
|
5886
|
-
const pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
|
|
5887
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
5888
|
-
}
|
|
5889
|
-
|
|
5890
5879
|
const dashKeys = {
|
|
5891
5880
|
offset: "stroke-dashoffset",
|
|
5892
5881
|
array: "stroke-dasharray",
|
|
@@ -5916,6 +5905,21 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
5916
5905
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
5917
5906
|
}
|
|
5918
5907
|
|
|
5908
|
+
function calcOrigin$1(origin, offset, size) {
|
|
5909
|
+
return typeof origin === "string"
|
|
5910
|
+
? origin
|
|
5911
|
+
: px.transform(offset + size * origin);
|
|
5912
|
+
}
|
|
5913
|
+
/**
|
|
5914
|
+
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5915
|
+
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5916
|
+
*/
|
|
5917
|
+
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5918
|
+
const pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
|
|
5919
|
+
const pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
|
|
5920
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5919
5923
|
/**
|
|
5920
5924
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
5921
5925
|
*/
|
|
@@ -6530,7 +6534,10 @@ class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
|
6530
6534
|
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
6531
6535
|
this.options = options;
|
|
6532
6536
|
this.updateFinishedPromise();
|
|
6533
|
-
this.removeAnimation = () => {
|
|
6537
|
+
this.removeAnimation = () => {
|
|
6538
|
+
const elementState = state.get(element);
|
|
6539
|
+
elementState && elementState.delete(valueName);
|
|
6540
|
+
};
|
|
6534
6541
|
};
|
|
6535
6542
|
if (!supportsWaapi()) {
|
|
6536
6543
|
super();
|
|
@@ -11095,10 +11102,12 @@ const svgMotionConfig = {
|
|
|
11095
11102
|
}
|
|
11096
11103
|
if (!needsMeasure)
|
|
11097
11104
|
return;
|
|
11098
|
-
frame.read(() =>
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11105
|
+
frame.read(() => {
|
|
11106
|
+
updateSVGDimensions(current, renderState);
|
|
11107
|
+
frame.render(() => {
|
|
11108
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
11109
|
+
renderSVG(current, renderState);
|
|
11110
|
+
});
|
|
11102
11111
|
});
|
|
11103
11112
|
},
|
|
11104
11113
|
}),
|
package/dist/cjs/m.js
CHANGED
|
@@ -1010,21 +1010,6 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
1013
|
-
function calcOrigin(origin, offset, size) {
|
|
1014
|
-
return typeof origin === "string"
|
|
1015
|
-
? origin
|
|
1016
|
-
: px.transform(offset + size * origin);
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1020
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1021
|
-
*/
|
|
1022
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1023
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1024
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1025
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
1013
|
const dashKeys = {
|
|
1029
1014
|
offset: "stroke-dashoffset",
|
|
1030
1015
|
array: "stroke-dasharray",
|
|
@@ -1054,6 +1039,21 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1054
1039
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
1055
1040
|
}
|
|
1056
1041
|
|
|
1042
|
+
function calcOrigin(origin, offset, size) {
|
|
1043
|
+
return typeof origin === "string"
|
|
1044
|
+
? origin
|
|
1045
|
+
: px.transform(offset + size * origin);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1049
|
+
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1050
|
+
*/
|
|
1051
|
+
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1052
|
+
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1053
|
+
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1054
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
1057
|
/**
|
|
1058
1058
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1059
1059
|
*/
|
|
@@ -1250,10 +1250,12 @@ const svgMotionConfig = {
|
|
|
1250
1250
|
}
|
|
1251
1251
|
if (!needsMeasure)
|
|
1252
1252
|
return;
|
|
1253
|
-
frame.read(() =>
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1253
|
+
frame.read(() => {
|
|
1254
|
+
updateSVGDimensions(current, renderState);
|
|
1255
|
+
frame.render(() => {
|
|
1256
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
1257
|
+
renderSVG(current, renderState);
|
|
1258
|
+
});
|
|
1257
1259
|
});
|
|
1258
1260
|
},
|
|
1259
1261
|
}),
|
package/dist/cjs/mini.js
CHANGED
|
@@ -177,7 +177,10 @@ class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
|
177
177
|
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
178
178
|
this.options = options;
|
|
179
179
|
this.updateFinishedPromise();
|
|
180
|
-
this.removeAnimation = () => {
|
|
180
|
+
this.removeAnimation = () => {
|
|
181
|
+
const elementState = state.get(element);
|
|
182
|
+
elementState && elementState.delete(valueName);
|
|
183
|
+
};
|
|
181
184
|
};
|
|
182
185
|
if (!supportsWaapi()) {
|
|
183
186
|
super();
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import * as
|
|
2
|
+
import * as react from 'react';
|
|
3
3
|
import { SVGAttributes, CSSProperties, PropsWithoutRef, RefAttributes, JSX } from 'react';
|
|
4
4
|
import { AnimationPlaybackControls, TransformProperties, SVGPathProperties, VariableKeyframesDefinition, Easing, Transition as Transition$1, ProgressTimeline } from 'motion-dom';
|
|
5
5
|
|
|
@@ -21,6 +21,7 @@ interface Owner {
|
|
|
21
21
|
current: HTMLElement | unknown;
|
|
22
22
|
getProps: () => {
|
|
23
23
|
onUpdate?: (latest: ResolvedValues$1) => void;
|
|
24
|
+
transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -1232,7 +1233,7 @@ declare class DragControls {
|
|
|
1232
1233
|
*
|
|
1233
1234
|
* @public
|
|
1234
1235
|
*/
|
|
1235
|
-
start(event:
|
|
1236
|
+
start(event: react.PointerEvent | PointerEvent, options?: DragControlOptions): void;
|
|
1236
1237
|
}
|
|
1237
1238
|
|
|
1238
1239
|
type DragElastic = boolean | number | Partial<BoundingBox>;
|
|
@@ -2375,9 +2376,9 @@ declare global {
|
|
|
2375
2376
|
|
|
2376
2377
|
type DOMMotionComponents = HTMLMotionComponents & SVGMotionComponents;
|
|
2377
2378
|
|
|
2378
|
-
declare const createMotionComponent: <Props, TagName extends string = "div">(Component: string | TagName |
|
|
2379
|
+
declare const createMotionComponent: <Props, TagName extends string = "div">(Component: string | TagName | react.ComponentType<Props>, { forwardMotionProps }?: {
|
|
2379
2380
|
forwardMotionProps: boolean;
|
|
2380
|
-
}) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "stop" | "path" | "image" | "circle" | "switch" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] :
|
|
2381
|
+
}) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "stop" | "path" | "image" | "circle" | "switch" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] : react.ComponentType<MotionComponentProps<react.PropsWithChildren<Props>>>;
|
|
2381
2382
|
|
|
2382
2383
|
/**
|
|
2383
2384
|
* HTML components
|
package/dist/dom-mini.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnimationPlaybackControls, AnimationPlaybackOptions, Transition, UnresolvedValueKeyframe, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, GroupPlaybackControls } from 'motion-dom';
|
|
1
|
+
import { AnimationPlaybackControls, TransformProperties, AnimationPlaybackOptions, Transition, UnresolvedValueKeyframe, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, GroupPlaybackControls } from 'motion-dom';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
@@ -18,6 +18,7 @@ interface Owner {
|
|
|
18
18
|
current: HTMLElement | unknown;
|
|
19
19
|
getProps: () => {
|
|
20
20
|
onUpdate?: (latest: ResolvedValues) => void;
|
|
21
|
+
transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
/**
|
package/dist/dom-mini.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";const e=t=>t;let n=e;function i(t){let e;return()=>(void 0===e&&(e=t()),e)}const a=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},r=t=>1e3*t,o=t=>t/1e3,s=i(()=>void 0!==window.ScrollTimeline);class u extends class{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>"finished"in t?t.finished:t))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const n=this.animations.map(n=>s()&&n.attachTimeline?n.attachTimeline(t):"function"==typeof e?e(n):void 0);return()=>{n.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}{then(t,e){return Promise.all(this.animations).then(t).catch(e)}}function l(t,e=100,n){const i=n({...t,keyframes:[0,e]}),a=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}(i),2e4);return{type:"keyframes",ease:t=>i.next(a*t).value/e,duration:o(a)}}function c(t){return"function"==typeof t}const h={linearEasing:void 0};function f(t,e){const n=i(t);return()=>{var t;return null!==(t=h[e])&&void 0!==t?t:n()}}const m=f(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),d=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,p={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:d([0,.65,.55,1]),circOut:d([.55,0,1,.45]),backIn:d([.31,.01,.66,-.59]),backOut:d([.33,1.53,.69,.99])};function y(t,e){return t?"function"==typeof t&&m()?((t,e,n=10)=>{let i="";const r=Math.max(Math.round(e/n),2);for(let e=0;e<r;e++)i+=t(a(0,r-1,e))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?d(t):Array.isArray(t)?t.map(t=>y(t,e)||p.easeOut):p[t]:void 0}function g(t,e,n){var i;if(t instanceof Element)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const r=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return r?Array.from(r):[]}return Array.from(t)}function v(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const A=(t,e,n)=>t+(e-t)*n;function b(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const r=a(0,e,i);t.push(A(n,1,r))}}function T(t){const e=[0];return b(e,t.length-1),e}function x(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?g(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function P(t,e,n){return t*(e+1)}function w(t,e,n,i){var a;return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(a=i.get(e))&&void 0!==a?a:t}function k(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function M(t,e,n,i,a,r){!function(t,e,n){for(let i=0;i<t.length;i++){const a=t[i];a.at>e&&a.at<n&&(k(t,a),i--)}}(t,a,r);for(let o=0;o<e.length;o++)t.push({value:e[o],at:A(a,r,i[o]),easing:v(n,o)})}function O(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function R(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function W(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function E(t,e){return e[t]||(e[t]=[]),e[t]}function F(t){return Array.isArray(t)?t:[t]}function B(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const S=t=>"number"==typeof t,$=t=>t.every(S);const I=(t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}))("px"),L={borderWidth:I,borderTopWidth:I,borderRightWidth:I,borderBottomWidth:I,borderLeftWidth:I,borderRadius:I,radius:I,borderTopLeftRadius:I,borderTopRightRadius:I,borderBottomRightRadius:I,borderBottomLeftRadius:I,width:I,maxWidth:I,height:I,maxHeight:I,top:I,right:I,bottom:I,left:I,padding:I,paddingTop:I,paddingRight:I,paddingBottom:I,paddingLeft:I,margin:I,marginTop:I,marginRight:I,marginBottom:I,marginLeft:I,backgroundPositionX:I,backgroundPositionY:I},V=t=>null!==t;function j(t,e,n){t.style.setProperty("--"+e,n)}function q(t,e,n){t.style[e]=n}const C=i(()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0}),N=i(()=>Object.hasOwnProperty.call(Element.prototype,"animate")),z=new WeakMap;function D(t){const e=z.get(t)||new Map;return z.set(t,e),z.get(t)}class H extends class{constructor(t){this.animation=t}get duration(){var t,e,n;const i=(null===(e=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===e?void 0:e.getComputedTiming().duration)||(null===(n=this.options)||void 0===n?void 0:n.duration)||300;return o(Number(i))}get time(){var t;return this.animation?o((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=r(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var t;this.animation&&(null===(t=this.animation.effect)||void 0===t||t.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&function(t,e){t.timeline=e,t.onfinish=null}(this.animation,t),e}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}{constructor(t,e,i,a){const o=e.startsWith("--");n("string"!=typeof a.type);const s=D(t).get(e);s&&s.stop();if(Array.isArray(i)||(i=[i]),function(t,e,n){for(let i=0;i<e.length;i++)null===e[i]&&(e[i]=0===i?n():e[i-1]),"number"==typeof e[i]&&L[t]&&(e[i]=L[t].transform(e[i]));!C()&&e.length<2&&e.unshift(n())}(e,i,()=>e.startsWith("--")?t.style.getPropertyValue(e):window.getComputedStyle(t)[e]),c(a.type)){const t=l(a,100,a.type);a.ease=m()?t.ease:"easeOut",a.duration=r(t.duration),a.type="keyframes"}else a.ease=a.ease||"easeOut";const u=()=>{this.setValue(t,e,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(V),r=e&&"loop"!==n&&e%2==1?0:a.length-1;return r&&void 0!==i?i:a[r]}(i,a)),this.cancel(),this.resolveFinishedPromise()},h=()=>{this.setValue=o?j:q,this.options=a,this.updateFinishedPromise(),this.removeAnimation=()=>{var n;return null===(n=z.get(t))||void 0===n?void 0:n.delete(e)}};N()?(super(function(t,e,n,{delay:i=0,duration:a=300,repeat:r=0,repeatType:o="loop",ease:s="easeInOut",times:u}={}){const l={[e]:n};u&&(l.offset=u);const c=y(s,a);return Array.isArray(c)&&(l.easing=c),t.animate(l,{delay:i,duration:a,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:r+1,direction:"reverse"===o?"alternate":"normal"})}(t,e,i,a)),h(),!1===a.autoplay&&this.animation.pause(),this.animation.onfinish=u,D(t).set(e,this)):(super(),h(),u())}then(t,e){return this.currentFinishedPromise.then(t,e)}updateFinishedPromise(){this.currentFinishedPromise=new Promise(t=>{this.resolveFinishedPromise=t})}play(){"finished"===this.state&&this.updateFinishedPromise(),super.play()}cancel(){this.removeAnimation(),super.cancel()}}function X(t,e,n,i){const a=g(t,i),o=a.length,s=[];for(let t=0;t<o;t++){const i=a[t],c={...n};"function"==typeof c.delay&&(c.delay=c.delay(t,o));for(const t in e){const n=e[t],a={...(u=c,l=t,u?u[l]||u.default||u:void 0)};a.duration=a.duration?r(a.duration):a.duration,a.delay=r(a.delay||0),s.push(new H(i,t,n,a))}}var u,l;return s}const Y=(t=>function(e,n,i){return new u(X(e,n,i,t))})();t.animate=Y,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,o){const s=e.duration||.3,u=new Map,h=new Map,f={},m=new Map;let d=0,p=0,y=0;for(let n=0;n<t.length;n++){const a=t[n];if("string"==typeof a){m.set(a,p);continue}if(!Array.isArray(a)){m.set(a.name,w(p,a.at,d,m));continue}let[u,A,k={}]=a;void 0!==k.at&&(p=w(p,k.at,d,m));let R=0;const S=(t,n,i,a=0,u=0)=>{const h=F(t),{delay:f=0,times:m=T(h),type:d="keyframes",repeat:g,repeatType:A,repeatDelay:x=0,...w}=n;let{ease:k=e.ease||"easeOut",duration:W}=n;const E="function"==typeof f?f(a,u):f,B=h.length,S=c(d)?d:null==o?void 0:o[d];if(B<=2&&S){let t=100;if(2===B&&$(h)){const e=h[1]-h[0];t=Math.abs(e)}const e={...w};void 0!==W&&(e.duration=r(W));const n=l(e,t,S);k=n.ease,W=n.duration}null!=W||(W=s);const I=p+E;1===m.length&&0===m[0]&&(m[1]=1);const L=m.length-h.length;if(L>0&&b(m,L),1===h.length&&h.unshift(null),g){W=P(W,g);const t=[...h],e=[...m];k=Array.isArray(k)?[...k]:[k];const n=[...k];for(let i=0;i<g;i++){h.push(...t);for(let a=0;a<t.length;a++)m.push(e[a]+(i+1)),k.push(0===a?"linear":v(n,a-1))}O(m,g)}const V=I+W;M(i,h,k,m,I,V),R=Math.max(E+W,R),y=Math.max(V,y)};if(g=u,Boolean(g&&g.getVelocity)){S(A,k,E("default",W(u,h)))}else{const t=x(u,A,i,f),e=t.length;for(let n=0;n<e;n++){A=A,k=k;const i=W(t[n],h);for(const t in A)S(A[t],B(k,t),E(t,i),n,e)}}d=p,p+=R}var g;return h.forEach((t,i)=>{for(const r in t){const o=t[r];o.sort(R);const s=[],l=[],c=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:i}=o[t];s.push(n),l.push(a(0,y,e)),c.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),s.unshift(s[0]),c.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),s.push(null)),u.has(i)||u.set(i,{keyframes:{},transition:{}});const h=u.get(i);h.keyframes[r]=s,h.transition[r]={...e,duration:y,ease:c,times:l,...n}}}),u}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...X(i,t,e))}),new u(n)}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";const e=t=>t;let n=e;function i(t){let e;return()=>(void 0===e&&(e=t()),e)}const a=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},s=t=>1e3*t,o=t=>t/1e3,r=i(()=>void 0!==window.ScrollTimeline);class u extends class{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>"finished"in t?t.finished:t))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const n=this.animations.map(n=>r()&&n.attachTimeline?n.attachTimeline(t):"function"==typeof e?e(n):void 0);return()=>{n.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}{then(t,e){return Promise.all(this.animations).then(t).catch(e)}}function l(t,e=100,n){const i=n({...t,keyframes:[0,e]}),a=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}(i),2e4);return{type:"keyframes",ease:t=>i.next(a*t).value/e,duration:o(a)}}function c(t){return"function"==typeof t}const h={linearEasing:void 0};function f(t,e){const n=i(t);return()=>{var t;return null!==(t=h[e])&&void 0!==t?t:n()}}const m=f(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),d=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,p={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:d([0,.65,.55,1]),circOut:d([.55,0,1,.45]),backIn:d([.31,.01,.66,-.59]),backOut:d([.33,1.53,.69,.99])};function y(t,e){return t?"function"==typeof t&&m()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;e<s;e++)i+=t(a(0,s-1,e))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?d(t):Array.isArray(t)?t.map(t=>y(t,e)||p.easeOut):p[t]:void 0}function g(t,e,n){var i;if(t instanceof Element)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const s=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function v(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const A=(t,e,n)=>t+(e-t)*n;function b(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const s=a(0,e,i);t.push(A(n,1,s))}}function T(t){const e=[0];return b(e,t.length-1),e}function x(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?g(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function P(t,e,n){return t*(e+1)}function w(t,e,n,i){var a;return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(a=i.get(e))&&void 0!==a?a:t}function k(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function M(t,e,n,i,a,s){!function(t,e,n){for(let i=0;i<t.length;i++){const a=t[i];a.at>e&&a.at<n&&(k(t,a),i--)}}(t,a,s);for(let o=0;o<e.length;o++)t.push({value:e[o],at:A(a,s,i[o]),easing:v(n,o)})}function O(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function R(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function W(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function E(t,e){return e[t]||(e[t]=[]),e[t]}function F(t){return Array.isArray(t)?t:[t]}function B(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const S=t=>"number"==typeof t,$=t=>t.every(S);const I=(t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}))("px"),L={borderWidth:I,borderTopWidth:I,borderRightWidth:I,borderBottomWidth:I,borderLeftWidth:I,borderRadius:I,radius:I,borderTopLeftRadius:I,borderTopRightRadius:I,borderBottomRightRadius:I,borderBottomLeftRadius:I,width:I,maxWidth:I,height:I,maxHeight:I,top:I,right:I,bottom:I,left:I,padding:I,paddingTop:I,paddingRight:I,paddingBottom:I,paddingLeft:I,margin:I,marginTop:I,marginRight:I,marginBottom:I,marginLeft:I,backgroundPositionX:I,backgroundPositionY:I},V=t=>null!==t;function j(t,e,n){t.style.setProperty("--"+e,n)}function q(t,e,n){t.style[e]=n}const C=i(()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0}),N=i(()=>Object.hasOwnProperty.call(Element.prototype,"animate")),z=new WeakMap;function D(t){const e=z.get(t)||new Map;return z.set(t,e),z.get(t)}class H extends class{constructor(t){this.animation=t}get duration(){var t,e,n;const i=(null===(e=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===e?void 0:e.getComputedTiming().duration)||(null===(n=this.options)||void 0===n?void 0:n.duration)||300;return o(Number(i))}get time(){var t;return this.animation?o((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=s(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var t;this.animation&&(null===(t=this.animation.effect)||void 0===t||t.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&function(t,e){t.timeline=e,t.onfinish=null}(this.animation,t),e}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}{constructor(t,e,i,a){const o=e.startsWith("--");n("string"!=typeof a.type);const r=D(t).get(e);r&&r.stop();if(Array.isArray(i)||(i=[i]),function(t,e,n){for(let i=0;i<e.length;i++)null===e[i]&&(e[i]=0===i?n():e[i-1]),"number"==typeof e[i]&&L[t]&&(e[i]=L[t].transform(e[i]));!C()&&e.length<2&&e.unshift(n())}(e,i,()=>e.startsWith("--")?t.style.getPropertyValue(e):window.getComputedStyle(t)[e]),c(a.type)){const t=l(a,100,a.type);a.ease=m()?t.ease:"easeOut",a.duration=s(t.duration),a.type="keyframes"}else a.ease=a.ease||"easeOut";const u=()=>{this.setValue(t,e,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(V),s=e&&"loop"!==n&&e%2==1?0:a.length-1;return s&&void 0!==i?i:a[s]}(i,a)),this.cancel(),this.resolveFinishedPromise()},h=()=>{this.setValue=o?j:q,this.options=a,this.updateFinishedPromise(),this.removeAnimation=()=>{const n=z.get(t);n&&n.delete(e)}};N()?(super(function(t,e,n,{delay:i=0,duration:a=300,repeat:s=0,repeatType:o="loop",ease:r="easeInOut",times:u}={}){const l={[e]:n};u&&(l.offset=u);const c=y(r,a);return Array.isArray(c)&&(l.easing=c),t.animate(l,{delay:i,duration:a,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:s+1,direction:"reverse"===o?"alternate":"normal"})}(t,e,i,a)),h(),!1===a.autoplay&&this.animation.pause(),this.animation.onfinish=u,D(t).set(e,this)):(super(),h(),u())}then(t,e){return this.currentFinishedPromise.then(t,e)}updateFinishedPromise(){this.currentFinishedPromise=new Promise(t=>{this.resolveFinishedPromise=t})}play(){"finished"===this.state&&this.updateFinishedPromise(),super.play()}cancel(){this.removeAnimation(),super.cancel()}}function X(t,e,n,i){const a=g(t,i),o=a.length,r=[];for(let t=0;t<o;t++){const i=a[t],c={...n};"function"==typeof c.delay&&(c.delay=c.delay(t,o));for(const t in e){const n=e[t],a={...(u=c,l=t,u?u[l]||u.default||u:void 0)};a.duration=a.duration?s(a.duration):a.duration,a.delay=s(a.delay||0),r.push(new H(i,t,n,a))}}var u,l;return r}const Y=(t=>function(e,n,i){return new u(X(e,n,i,t))})();t.animate=Y,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,o){const r=e.duration||.3,u=new Map,h=new Map,f={},m=new Map;let d=0,p=0,y=0;for(let n=0;n<t.length;n++){const a=t[n];if("string"==typeof a){m.set(a,p);continue}if(!Array.isArray(a)){m.set(a.name,w(p,a.at,d,m));continue}let[u,A,k={}]=a;void 0!==k.at&&(p=w(p,k.at,d,m));let R=0;const S=(t,n,i,a=0,u=0)=>{const h=F(t),{delay:f=0,times:m=T(h),type:d="keyframes",repeat:g,repeatType:A,repeatDelay:x=0,...w}=n;let{ease:k=e.ease||"easeOut",duration:W}=n;const E="function"==typeof f?f(a,u):f,B=h.length,S=c(d)?d:null==o?void 0:o[d];if(B<=2&&S){let t=100;if(2===B&&$(h)){const e=h[1]-h[0];t=Math.abs(e)}const e={...w};void 0!==W&&(e.duration=s(W));const n=l(e,t,S);k=n.ease,W=n.duration}null!=W||(W=r);const I=p+E;1===m.length&&0===m[0]&&(m[1]=1);const L=m.length-h.length;if(L>0&&b(m,L),1===h.length&&h.unshift(null),g){W=P(W,g);const t=[...h],e=[...m];k=Array.isArray(k)?[...k]:[k];const n=[...k];for(let i=0;i<g;i++){h.push(...t);for(let a=0;a<t.length;a++)m.push(e[a]+(i+1)),k.push(0===a?"linear":v(n,a-1))}O(m,g)}const V=I+W;M(i,h,k,m,I,V),R=Math.max(E+W,R),y=Math.max(V,y)};if(g=u,Boolean(g&&g.getVelocity)){S(A,k,E("default",W(u,h)))}else{const t=x(u,A,i,f),e=t.length;for(let n=0;n<e;n++){A=A,k=k;const i=W(t[n],h);for(const t in A)S(A[t],B(k,t),E(t,i),n,e)}}d=p,p+=R}var g;return h.forEach((t,i)=>{for(const s in t){const o=t[s];o.sort(R);const r=[],l=[],c=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:i}=o[t];r.push(n),l.push(a(0,y,e)),c.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),r.unshift(r[0]),c.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),r.push(null)),u.has(i)||u.set(i,{keyframes:{},transition:{}});const h=u.get(i);h.keyframes[s]=r,h.transition[s]={...e,duration:y,ease:c,times:l,...n}}}),u}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...X(i,t,e))}),new u(n)}}));
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as motion_dom from 'motion-dom';
|
|
2
|
-
import { AnimationPlaybackControls, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, Easing, AnimationScope, ValueAnimationTransition, EasingFunction, ProgressTimeline, EasingModifier, ValueAnimationOptions, KeyframeGenerator, DynamicOption } from 'motion-dom';
|
|
2
|
+
import { AnimationPlaybackControls, TransformProperties, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, Easing, AnimationScope, ValueAnimationTransition, EasingFunction, ProgressTimeline, EasingModifier, ValueAnimationOptions, KeyframeGenerator, DynamicOption } from 'motion-dom';
|
|
3
3
|
export * from 'motion-dom';
|
|
4
4
|
export { BezierDefinition, Easing, EasingDefinition, EasingFunction, EasingModifier, isDragActive } from 'motion-dom';
|
|
5
5
|
export { invariant, noop, progress } from 'motion-utils';
|
|
@@ -26,6 +26,7 @@ interface Owner {
|
|
|
26
26
|
current: HTMLElement | unknown;
|
|
27
27
|
getProps: () => {
|
|
28
28
|
onUpdate?: (latest: ResolvedValues) => void;
|
|
29
|
+
transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
interface MotionValueOptions {
|