motion-dom 14.2.0 → 14.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 +73 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/render/dom/parse-transform.mjs +4 -2
- package/dist/es/render/dom/parse-transform.mjs.map +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +7 -2
- package/dist/es/render/svg/utils/scrape-motion-values.mjs.map +1 -1
- package/dist/es/render/utils/keys-transform.mjs +1 -0
- package/dist/es/render/utils/keys-transform.mjs.map +1 -1
- package/dist/es/utils/stagger.mjs +39 -6
- package/dist/es/utils/stagger.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs +3 -2
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/es/value/utils/follow.mjs +19 -2
- package/dist/es/value/utils/follow.mjs.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/motion-dom.dev.js +73 -14
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -249,8 +249,9 @@ const COLOR_TOKEN = "color";
|
|
|
249
249
|
const VAR_TOKEN = "var";
|
|
250
250
|
const VAR_FUNCTION_TOKEN = "var(";
|
|
251
251
|
const SPLIT_TOKEN = "${}";
|
|
252
|
-
// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex
|
|
253
|
-
|
|
252
|
+
// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`.
|
|
253
|
+
// The lookahead skips digits in function names, like the 3 in matrix3d(.
|
|
254
|
+
const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)(?![a-z]*\()/giu;
|
|
254
255
|
/**
|
|
255
256
|
* Whether analyseComplexValue(value) would find any values, without
|
|
256
257
|
* tokenising the string. CSS variables are resolved before this is
|
|
@@ -2193,6 +2194,7 @@ const matrix2dParsers = {
|
|
|
2193
2194
|
translateY: 5,
|
|
2194
2195
|
scaleX: 0,
|
|
2195
2196
|
scaleY: 3,
|
|
2197
|
+
scaleZ: () => 1,
|
|
2196
2198
|
scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
|
|
2197
2199
|
rotate,
|
|
2198
2200
|
rotateZ: rotate,
|
|
@@ -2207,8 +2209,8 @@ const rebaseAngle = (angle) => {
|
|
|
2207
2209
|
return angle;
|
|
2208
2210
|
};
|
|
2209
2211
|
const rotateZ = rotate;
|
|
2210
|
-
const scaleX = (v) => Math.
|
|
2211
|
-
const scaleY = (v) => Math.
|
|
2212
|
+
const scaleX = (v) => Math.hypot(v[0], v[1]);
|
|
2213
|
+
const scaleY = (v) => Math.hypot(v[4], v[5]);
|
|
2212
2214
|
const matrix3dParsers = {
|
|
2213
2215
|
x: 12,
|
|
2214
2216
|
y: 13,
|
|
@@ -2218,6 +2220,7 @@ const matrix3dParsers = {
|
|
|
2218
2220
|
translateZ: 14,
|
|
2219
2221
|
scaleX,
|
|
2220
2222
|
scaleY,
|
|
2223
|
+
scaleZ: (v) => Math.hypot(v[8], v[9], v[10]),
|
|
2221
2224
|
scale: (v) => (scaleX(v) + scaleY(v)) / 2,
|
|
2222
2225
|
rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
|
|
2223
2226
|
rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
|
|
@@ -2277,6 +2280,7 @@ const transformPropOrder = [
|
|
|
2277
2280
|
"scale",
|
|
2278
2281
|
"scaleX",
|
|
2279
2282
|
"scaleY",
|
|
2283
|
+
"scaleZ",
|
|
2280
2284
|
"rotate",
|
|
2281
2285
|
"rotateX",
|
|
2282
2286
|
"rotateY",
|
|
@@ -7061,13 +7065,46 @@ function getOriginIndex(from, total) {
|
|
|
7061
7065
|
return from === "last" ? lastIndex : lastIndex / 2;
|
|
7062
7066
|
}
|
|
7063
7067
|
}
|
|
7064
|
-
function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
|
|
7068
|
+
function stagger(duration = 0.1, { startDelay = 0, from = 0, ease, grid } = {}) {
|
|
7069
|
+
/**
|
|
7070
|
+
* Distances from the origin for each element count. The final entry
|
|
7071
|
+
* holds the distance used to normalise easing.
|
|
7072
|
+
*/
|
|
7073
|
+
const cache = {};
|
|
7065
7074
|
return (i, total) => {
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
const
|
|
7075
|
+
let distances = cache[total];
|
|
7076
|
+
if (!distances) {
|
|
7077
|
+
const [columns, rows] = grid || [Infinity, 1];
|
|
7078
|
+
const lastX = Math.min(columns, total) - 1;
|
|
7079
|
+
const lastY = Math.max(rows, Math.ceil(total / columns)) - 1;
|
|
7080
|
+
const isIndex = typeof from === "number";
|
|
7081
|
+
const scale = from === "first" ? 0 : from === "last" ? 1 : 0.5;
|
|
7082
|
+
const originX = isIndex ? from % columns : lastX * scale;
|
|
7083
|
+
const originY = isIndex ? Math.floor(from / columns) : lastY * scale;
|
|
7084
|
+
distances = cache[total] = [];
|
|
7085
|
+
for (let j = 0; j < total; j++) {
|
|
7086
|
+
const x = j % columns;
|
|
7087
|
+
const y = Math.floor(j / columns);
|
|
7088
|
+
const edgeX = Math.min(x, lastX - x);
|
|
7089
|
+
const edgeY = Math.min(y, lastY - y);
|
|
7090
|
+
if (from === "random") {
|
|
7091
|
+
// Inside-out shuffle, so each element gets a distinct step
|
|
7092
|
+
const k = (Math.random() * (j + 1)) | 0;
|
|
7093
|
+
distances[j] = distances[k];
|
|
7094
|
+
distances[k] = j;
|
|
7095
|
+
}
|
|
7096
|
+
else {
|
|
7097
|
+
distances[j] =
|
|
7098
|
+
from === "edges"
|
|
7099
|
+
? Math.min(lastX ? edgeX : edgeY, lastY ? edgeY : edgeX)
|
|
7100
|
+
: Math.hypot(x - originX, y - originY);
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
distances.push(grid ? Math.max(...distances) : total);
|
|
7104
|
+
}
|
|
7105
|
+
let delay = duration * distances[i];
|
|
7106
|
+
const maxDelay = duration * distances[total];
|
|
7107
|
+
if (ease && maxDelay) {
|
|
7071
7108
|
const easingFunction = motionUtils.easingDefinitionToFunction(ease);
|
|
7072
7109
|
delay = easingFunction(delay / maxDelay) * maxDelay;
|
|
7073
7110
|
}
|
|
@@ -7301,7 +7338,7 @@ function follow(value, source, options) {
|
|
|
7301
7338
|
}, stopAnimation);
|
|
7302
7339
|
if (isMotionValue(source)) {
|
|
7303
7340
|
let skipNextAnimation = options.skipInitialAnimation === true;
|
|
7304
|
-
const
|
|
7341
|
+
const onSourceChange = (v) => {
|
|
7305
7342
|
if (skipNextAnimation) {
|
|
7306
7343
|
skipNextAnimation = false;
|
|
7307
7344
|
value.jump(parseValue(v, unit), false);
|
|
@@ -7309,11 +7346,28 @@ function follow(value, source, options) {
|
|
|
7309
7346
|
else {
|
|
7310
7347
|
value.set(parseValue(v, unit));
|
|
7311
7348
|
}
|
|
7312
|
-
}
|
|
7349
|
+
};
|
|
7350
|
+
const removeSourceOnChange = source.on("change", onSourceChange);
|
|
7351
|
+
/**
|
|
7352
|
+
* Catch up on a change made before we subscribed, for instance
|
|
7353
|
+
* between a React render reading the source and the effect
|
|
7354
|
+
* attaching to it. Subtracting is falsy for equal or non-numeric
|
|
7355
|
+
* (NaN) values.
|
|
7356
|
+
*/
|
|
7357
|
+
const latest = source.get();
|
|
7358
|
+
if (asNumber(latest) - asNumber(value.get()))
|
|
7359
|
+
onSourceChange(latest);
|
|
7313
7360
|
const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
|
|
7361
|
+
/**
|
|
7362
|
+
* Stop our animation on detach, otherwise a re-attach (new
|
|
7363
|
+
* options, Strict Mode) starts a second animation that fights
|
|
7364
|
+
* this orphaned one. The catch-up above resumes from the
|
|
7365
|
+
* current value and velocity.
|
|
7366
|
+
*/
|
|
7314
7367
|
return () => {
|
|
7315
7368
|
removeSourceOnChange();
|
|
7316
7369
|
removeValueOnDestroy();
|
|
7370
|
+
stopAnimation();
|
|
7317
7371
|
};
|
|
7318
7372
|
}
|
|
7319
7373
|
return stopAnimation;
|
|
@@ -9476,8 +9530,13 @@ function renderSVG(element, renderState, _styleProp, projection) {
|
|
|
9476
9530
|
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
9477
9531
|
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
9478
9532
|
for (const key in props) {
|
|
9479
|
-
|
|
9480
|
-
|
|
9533
|
+
/**
|
|
9534
|
+
* A MotionValue child is rendered as text content by
|
|
9535
|
+
* DOMVisualElement, so it mustn't also be written as an attribute.
|
|
9536
|
+
*/
|
|
9537
|
+
if (key !== "children" &&
|
|
9538
|
+
(isMotionValue(props[key]) ||
|
|
9539
|
+
isMotionValue(prevProps[key]))) {
|
|
9481
9540
|
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
9482
9541
|
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
9483
9542
|
: key;
|