framer-motion 10.12.2 → 10.12.3

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var indexLegacy = require('./index-legacy-5ce04d2d.js');
5
+ var indexLegacy = require('./index-legacy-ec713eb3.js');
6
6
 
7
7
 
8
8
 
@@ -150,6 +150,7 @@ function buildTransform(transform, { enableHardwareAcceleration = true, allowTra
150
150
  const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
151
151
  const isCSSVariableName = checkStringStartsWith("--");
152
152
  const isCSSVariableToken = checkStringStartsWith("var(--");
153
+ const cssVariableRegex = /var\s*\(\s*--[\w-]+(\s*,\s*(?:(?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)+)?\s*\)/g;
153
154
 
154
155
  /**
155
156
  * Provided a value and a ValueType, returns the value as that value type.
@@ -1139,8 +1140,6 @@ const mixColor = (from, to) => {
1139
1140
  };
1140
1141
  };
1141
1142
 
1142
- const colorToken = "${c}";
1143
- const numberToken = "${n}";
1144
1143
  function test(v) {
1145
1144
  var _a, _b;
1146
1145
  return (isNaN(v) &&
@@ -1149,52 +1148,84 @@ function test(v) {
1149
1148
  (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
1150
1149
  0);
1151
1150
  }
1152
- function analyseComplexValue(v) {
1153
- if (typeof v === "number")
1154
- v = `${v}`;
1155
- const values = [];
1156
- let numColors = 0;
1157
- let numNumbers = 0;
1158
- const colors = v.match(colorRegex);
1159
- if (colors) {
1160
- numColors = colors.length;
1161
- // Strip colors from input so they're not picked up by number regex.
1162
- // There's a better way to combine these regex searches, but its beyond my regex skills
1163
- v = v.replace(colorRegex, colorToken);
1164
- values.push(...colors.map(color.parse));
1165
- }
1166
- const numbers = v.match(floatRegex);
1167
- if (numbers) {
1168
- numNumbers = numbers.length;
1169
- v = v.replace(floatRegex, numberToken);
1170
- values.push(...numbers.map(number.parse));
1171
- }
1172
- return { values, numColors, numNumbers, tokenised: v };
1173
- }
1174
- function parse(v) {
1151
+ const cssVarTokeniser = {
1152
+ regex: cssVariableRegex,
1153
+ countKey: "Vars",
1154
+ token: "${v}",
1155
+ parse: noop,
1156
+ };
1157
+ const colorTokeniser = {
1158
+ regex: colorRegex,
1159
+ countKey: "Colors",
1160
+ token: "${c}",
1161
+ parse: color.parse,
1162
+ };
1163
+ const numberTokeniser = {
1164
+ regex: floatRegex,
1165
+ countKey: "Numbers",
1166
+ token: "${n}",
1167
+ parse: number.parse,
1168
+ };
1169
+ function tokenise(info, { regex, countKey, token, parse }) {
1170
+ const matches = info.tokenised.match(regex);
1171
+ if (!matches)
1172
+ return;
1173
+ info["num" + countKey] = matches.length;
1174
+ info.tokenised = info.tokenised.replace(regex, token);
1175
+ info.values.push(...matches.map(parse));
1176
+ }
1177
+ function analyseComplexValue(value) {
1178
+ const originalValue = value.toString();
1179
+ const info = {
1180
+ value: originalValue,
1181
+ tokenised: originalValue,
1182
+ values: [],
1183
+ numVars: 0,
1184
+ numColors: 0,
1185
+ numNumbers: 0,
1186
+ };
1187
+ if (info.value.includes("var(--"))
1188
+ tokenise(info, cssVarTokeniser);
1189
+ tokenise(info, colorTokeniser);
1190
+ tokenise(info, numberTokeniser);
1191
+ return info;
1192
+ }
1193
+ function parseComplexValue(v) {
1175
1194
  return analyseComplexValue(v).values;
1176
1195
  }
1177
1196
  function createTransformer(source) {
1178
- const { values, numColors, tokenised } = analyseComplexValue(source);
1197
+ const { values, numColors, numVars, tokenised } = analyseComplexValue(source);
1179
1198
  const numValues = values.length;
1180
1199
  return (v) => {
1181
1200
  let output = tokenised;
1182
1201
  for (let i = 0; i < numValues; i++) {
1183
- output = output.replace(i < numColors ? colorToken : numberToken, i < numColors
1184
- ? color.transform(v[i])
1185
- : sanitize(v[i]));
1202
+ if (i < numVars) {
1203
+ output = output.replace(cssVarTokeniser.token, v[i]);
1204
+ }
1205
+ else if (i < numVars + numColors) {
1206
+ output = output.replace(colorTokeniser.token, color.transform(v[i]));
1207
+ }
1208
+ else {
1209
+ output = output.replace(numberTokeniser.token, sanitize(v[i]));
1210
+ }
1186
1211
  }
1187
1212
  return output;
1188
1213
  };
1189
1214
  }
1190
1215
  const convertNumbersToZero = (v) => typeof v === "number" ? 0 : v;
1191
1216
  function getAnimatableNone$1(v) {
1192
- const parsed = parse(v);
1217
+ const parsed = parseComplexValue(v);
1193
1218
  const transformer = createTransformer(v);
1194
1219
  return transformer(parsed.map(convertNumbersToZero));
1195
1220
  }
1196
- const complex = { test, parse, createTransformer, getAnimatableNone: getAnimatableNone$1 };
1221
+ const complex = {
1222
+ test,
1223
+ parse: parseComplexValue,
1224
+ createTransformer,
1225
+ getAnimatableNone: getAnimatableNone$1,
1226
+ };
1197
1227
 
1228
+ const mixImmediate = (origin, target) => (p) => `${p > 0 ? target : origin}`;
1198
1229
  function getMixer$1(origin, target) {
1199
1230
  if (typeof origin === "number") {
1200
1231
  return (v) => mix(origin, target, v);
@@ -1203,7 +1234,9 @@ function getMixer$1(origin, target) {
1203
1234
  return mixColor(origin, target);
1204
1235
  }
1205
1236
  else {
1206
- return mixComplex(origin, target);
1237
+ return origin.startsWith("var(")
1238
+ ? mixImmediate(origin, target)
1239
+ : mixComplex(origin, target);
1207
1240
  }
1208
1241
  }
1209
1242
  const mixArray = (from, to) => {
@@ -1236,14 +1269,15 @@ const mixComplex = (origin, target) => {
1236
1269
  const template = complex.createTransformer(target);
1237
1270
  const originStats = analyseComplexValue(origin);
1238
1271
  const targetStats = analyseComplexValue(target);
1239
- const canInterpolate = originStats.numColors === targetStats.numColors &&
1272
+ const canInterpolate = originStats.numVars === targetStats.numVars &&
1273
+ originStats.numColors === targetStats.numColors &&
1240
1274
  originStats.numNumbers >= targetStats.numNumbers;
1241
1275
  if (canInterpolate) {
1242
1276
  return pipe(mixArray(originStats.values, targetStats.values), template);
1243
1277
  }
1244
1278
  else {
1245
1279
  exports.warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`);
1246
- return (p) => `${p > 0 ? target : origin}`;
1280
+ return mixImmediate(origin, target);
1247
1281
  }
1248
1282
  };
1249
1283
 
@@ -1270,12 +1304,7 @@ function detectMixerFactory(v) {
1270
1304
  return mixNumber;
1271
1305
  }
1272
1306
  else if (typeof v === "string") {
1273
- if (color.test(v)) {
1274
- return mixColor;
1275
- }
1276
- else {
1277
- return mixComplex;
1278
- }
1307
+ return color.test(v) ? mixColor : mixComplex;
1279
1308
  }
1280
1309
  else if (Array.isArray(v)) {
1281
1310
  return mixArray;
@@ -2622,7 +2651,7 @@ class MotionValue {
2622
2651
  * This will be replaced by the build step with the latest version number.
2623
2652
  * When MotionValues are provided to motion components, warn if versions are mixed.
2624
2653
  */
2625
- this.version = "10.12.2";
2654
+ this.version = "10.12.3";
2626
2655
  /**
2627
2656
  * Duration, in milliseconds, since last updating frame.
2628
2657
  *
@@ -3455,9 +3484,9 @@ function isSVGElement(element) {
3455
3484
  *
3456
3485
  * @param current
3457
3486
  */
3458
- const cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
3487
+ const splitCSSVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
3459
3488
  function parseCSSVariable(current) {
3460
- const match = cssVariableRegex.exec(current);
3489
+ const match = splitCSSVariableRegex.exec(current);
3461
3490
  if (!match)
3462
3491
  return [,];
3463
3492
  const [, token, fallback] = match;
@@ -3794,7 +3823,7 @@ function updateMotionValuesFromProps(element, next, prev) {
3794
3823
  * and warn against mismatches.
3795
3824
  */
3796
3825
  if (process.env.NODE_ENV === "development") {
3797
- warnOnce(nextValue.version === "10.12.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.12.2 may not work as expected.`);
3826
+ warnOnce(nextValue.version === "10.12.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.12.3 may not work as expected.`);
3798
3827
  }
3799
3828
  }
3800
3829
  else if (isMotionValue(prevValue)) {
@@ -5395,7 +5424,6 @@ exports.convertBoxToBoundingBox = convertBoxToBoundingBox;
5395
5424
  exports.createBox = createBox;
5396
5425
  exports.createDelta = createDelta;
5397
5426
  exports.createScopedAnimate = createScopedAnimate;
5398
- exports.cssVariableRegex = cssVariableRegex;
5399
5427
  exports.cubicBezier = cubicBezier;
5400
5428
  exports.delay = delay;
5401
5429
  exports.distance = distance;
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var indexLegacy = require('./index-legacy-5ce04d2d.js');
6
+ var indexLegacy = require('./index-legacy-ec713eb3.js');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
@@ -4312,21 +4312,9 @@ const correctBorderRadius = {
4312
4312
  },
4313
4313
  };
4314
4314
 
4315
- const varToken = "_$css";
4316
4315
  const correctBoxShadow = {
4317
4316
  correct: (latest, { treeScale, projectionDelta }) => {
4318
4317
  const original = latest;
4319
- /**
4320
- * We need to first strip and store CSS variables from the string.
4321
- */
4322
- const containsCSSVariables = latest.includes("var(");
4323
- const cssVariables = [];
4324
- if (containsCSSVariables) {
4325
- latest = latest.replace(indexLegacy.cssVariableRegex, (match) => {
4326
- cssVariables.push(match);
4327
- return varToken;
4328
- });
4329
- }
4330
4318
  const shadow = indexLegacy.complex.parse(latest);
4331
4319
  // TODO: Doesn't support multiple shadows
4332
4320
  if (shadow.length > 5)
@@ -4351,16 +4339,7 @@ const correctBoxShadow = {
4351
4339
  // Spread
4352
4340
  if (typeof shadow[3 + offset] === "number")
4353
4341
  shadow[3 + offset] /= averageScale;
4354
- let output = template(shadow);
4355
- if (containsCSSVariables) {
4356
- let i = 0;
4357
- output = output.replace(varToken, () => {
4358
- const cssVariable = cssVariables[i];
4359
- i++;
4360
- return cssVariable;
4361
- });
4362
- }
4363
- return output;
4342
+ return template(shadow);
4364
4343
  },
4365
4344
  };
4366
4345
 
@@ -1,22 +1,9 @@
1
- import { cssVariableRegex } from '../../render/dom/utils/css-variables-conversion.mjs';
2
1
  import { mix } from '../../utils/mix.mjs';
3
2
  import { complex } from '../../value/types/complex/index.mjs';
4
3
 
5
- const varToken = "_$css";
6
4
  const correctBoxShadow = {
7
5
  correct: (latest, { treeScale, projectionDelta }) => {
8
6
  const original = latest;
9
- /**
10
- * We need to first strip and store CSS variables from the string.
11
- */
12
- const containsCSSVariables = latest.includes("var(");
13
- const cssVariables = [];
14
- if (containsCSSVariables) {
15
- latest = latest.replace(cssVariableRegex, (match) => {
16
- cssVariables.push(match);
17
- return varToken;
18
- });
19
- }
20
7
  const shadow = complex.parse(latest);
21
8
  // TODO: Doesn't support multiple shadows
22
9
  if (shadow.length > 5)
@@ -41,16 +28,7 @@ const correctBoxShadow = {
41
28
  // Spread
42
29
  if (typeof shadow[3 + offset] === "number")
43
30
  shadow[3 + offset] /= averageScale;
44
- let output = template(shadow);
45
- if (containsCSSVariables) {
46
- let i = 0;
47
- output = output.replace(varToken, () => {
48
- const cssVariable = cssVariables[i];
49
- i++;
50
- return cssVariable;
51
- });
52
- }
53
- return output;
31
+ return template(shadow);
54
32
  },
55
33
  };
56
34
 
@@ -10,9 +10,9 @@ import { isCSSVariableToken } from './is-css-variable.mjs';
10
10
  *
11
11
  * @param current
12
12
  */
13
- const cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
13
+ const splitCSSVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
14
14
  function parseCSSVariable(current) {
15
- const match = cssVariableRegex.exec(current);
15
+ const match = splitCSSVariableRegex.exec(current);
16
16
  if (!match)
17
17
  return [,];
18
18
  const [, token, fallback] = match;
@@ -84,4 +84,4 @@ function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
84
84
  return { target, transitionEnd };
85
85
  }
86
86
 
87
- export { cssVariableRegex, parseCSSVariable, resolveCSSVariables };
87
+ export { parseCSSVariable, resolveCSSVariables };
@@ -1,5 +1,6 @@
1
1
  const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
2
2
  const isCSSVariableName = checkStringStartsWith("--");
3
3
  const isCSSVariableToken = checkStringStartsWith("var(--");
4
+ const cssVariableRegex = /var\s*\(\s*--[\w-]+(\s*,\s*(?:(?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)+)?\s*\)/g;
4
5
 
5
- export { isCSSVariableName, isCSSVariableToken };
6
+ export { cssVariableRegex, isCSSVariableName, isCSSVariableToken };
@@ -22,7 +22,7 @@ function updateMotionValuesFromProps(element, next, prev) {
22
22
  * and warn against mismatches.
23
23
  */
24
24
  if (process.env.NODE_ENV === "development") {
25
- warnOnce(nextValue.version === "10.12.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.12.2 may not work as expected.`);
25
+ warnOnce(nextValue.version === "10.12.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.12.3 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -14,12 +14,7 @@ function detectMixerFactory(v) {
14
14
  return mixNumber;
15
15
  }
16
16
  else if (typeof v === "string") {
17
- if (color.test(v)) {
18
- return mixColor;
19
- }
20
- else {
21
- return mixComplex;
22
- }
17
+ return color.test(v) ? mixColor : mixComplex;
23
18
  }
24
19
  else if (Array.isArray(v)) {
25
20
  return mixArray;
@@ -5,6 +5,7 @@ import { warning } from './errors.mjs';
5
5
  import { color } from '../value/types/color/index.mjs';
6
6
  import { complex, analyseComplexValue } from '../value/types/complex/index.mjs';
7
7
 
8
+ const mixImmediate = (origin, target) => (p) => `${p > 0 ? target : origin}`;
8
9
  function getMixer(origin, target) {
9
10
  if (typeof origin === "number") {
10
11
  return (v) => mix(origin, target, v);
@@ -13,7 +14,9 @@ function getMixer(origin, target) {
13
14
  return mixColor(origin, target);
14
15
  }
15
16
  else {
16
- return mixComplex(origin, target);
17
+ return origin.startsWith("var(")
18
+ ? mixImmediate(origin, target)
19
+ : mixComplex(origin, target);
17
20
  }
18
21
  }
19
22
  const mixArray = (from, to) => {
@@ -46,14 +49,15 @@ const mixComplex = (origin, target) => {
46
49
  const template = complex.createTransformer(target);
47
50
  const originStats = analyseComplexValue(origin);
48
51
  const targetStats = analyseComplexValue(target);
49
- const canInterpolate = originStats.numColors === targetStats.numColors &&
52
+ const canInterpolate = originStats.numVars === targetStats.numVars &&
53
+ originStats.numColors === targetStats.numColors &&
50
54
  originStats.numNumbers >= targetStats.numNumbers;
51
55
  if (canInterpolate) {
52
56
  return pipe(mixArray(originStats.values, targetStats.values), template);
53
57
  }
54
58
  else {
55
59
  warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`);
56
- return (p) => `${p > 0 ? target : origin}`;
60
+ return mixImmediate(origin, target);
57
61
  }
58
62
  };
59
63
 
@@ -26,7 +26,7 @@ class MotionValue {
26
26
  * This will be replaced by the build step with the latest version number.
27
27
  * When MotionValues are provided to motion components, warn if versions are mixed.
28
28
  */
29
- this.version = "10.12.2";
29
+ this.version = "10.12.3";
30
30
  /**
31
31
  * Duration, in milliseconds, since last updating frame.
32
32
  *
@@ -1,9 +1,9 @@
1
+ import { cssVariableRegex } from '../../../render/dom/utils/is-css-variable.mjs';
2
+ import { noop } from '../../../utils/noop.mjs';
1
3
  import { color } from '../color/index.mjs';
2
4
  import { number } from '../numbers/index.mjs';
3
- import { isString, floatRegex, colorRegex, sanitize } from '../utils.mjs';
5
+ import { colorRegex, floatRegex, isString, sanitize } from '../utils.mjs';
4
6
 
5
- const colorToken = "${c}";
6
- const numberToken = "${n}";
7
7
  function test(v) {
8
8
  var _a, _b;
9
9
  return (isNaN(v) &&
@@ -12,50 +12,81 @@ function test(v) {
12
12
  (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
13
13
  0);
14
14
  }
15
- function analyseComplexValue(v) {
16
- if (typeof v === "number")
17
- v = `${v}`;
18
- const values = [];
19
- let numColors = 0;
20
- let numNumbers = 0;
21
- const colors = v.match(colorRegex);
22
- if (colors) {
23
- numColors = colors.length;
24
- // Strip colors from input so they're not picked up by number regex.
25
- // There's a better way to combine these regex searches, but its beyond my regex skills
26
- v = v.replace(colorRegex, colorToken);
27
- values.push(...colors.map(color.parse));
28
- }
29
- const numbers = v.match(floatRegex);
30
- if (numbers) {
31
- numNumbers = numbers.length;
32
- v = v.replace(floatRegex, numberToken);
33
- values.push(...numbers.map(number.parse));
34
- }
35
- return { values, numColors, numNumbers, tokenised: v };
15
+ const cssVarTokeniser = {
16
+ regex: cssVariableRegex,
17
+ countKey: "Vars",
18
+ token: "${v}",
19
+ parse: noop,
20
+ };
21
+ const colorTokeniser = {
22
+ regex: colorRegex,
23
+ countKey: "Colors",
24
+ token: "${c}",
25
+ parse: color.parse,
26
+ };
27
+ const numberTokeniser = {
28
+ regex: floatRegex,
29
+ countKey: "Numbers",
30
+ token: "${n}",
31
+ parse: number.parse,
32
+ };
33
+ function tokenise(info, { regex, countKey, token, parse }) {
34
+ const matches = info.tokenised.match(regex);
35
+ if (!matches)
36
+ return;
37
+ info["num" + countKey] = matches.length;
38
+ info.tokenised = info.tokenised.replace(regex, token);
39
+ info.values.push(...matches.map(parse));
36
40
  }
37
- function parse(v) {
41
+ function analyseComplexValue(value) {
42
+ const originalValue = value.toString();
43
+ const info = {
44
+ value: originalValue,
45
+ tokenised: originalValue,
46
+ values: [],
47
+ numVars: 0,
48
+ numColors: 0,
49
+ numNumbers: 0,
50
+ };
51
+ if (info.value.includes("var(--"))
52
+ tokenise(info, cssVarTokeniser);
53
+ tokenise(info, colorTokeniser);
54
+ tokenise(info, numberTokeniser);
55
+ return info;
56
+ }
57
+ function parseComplexValue(v) {
38
58
  return analyseComplexValue(v).values;
39
59
  }
40
60
  function createTransformer(source) {
41
- const { values, numColors, tokenised } = analyseComplexValue(source);
61
+ const { values, numColors, numVars, tokenised } = analyseComplexValue(source);
42
62
  const numValues = values.length;
43
63
  return (v) => {
44
64
  let output = tokenised;
45
65
  for (let i = 0; i < numValues; i++) {
46
- output = output.replace(i < numColors ? colorToken : numberToken, i < numColors
47
- ? color.transform(v[i])
48
- : sanitize(v[i]));
66
+ if (i < numVars) {
67
+ output = output.replace(cssVarTokeniser.token, v[i]);
68
+ }
69
+ else if (i < numVars + numColors) {
70
+ output = output.replace(colorTokeniser.token, color.transform(v[i]));
71
+ }
72
+ else {
73
+ output = output.replace(numberTokeniser.token, sanitize(v[i]));
74
+ }
49
75
  }
50
76
  return output;
51
77
  };
52
78
  }
53
79
  const convertNumbersToZero = (v) => typeof v === "number" ? 0 : v;
54
80
  function getAnimatableNone(v) {
55
- const parsed = parse(v);
81
+ const parsed = parseComplexValue(v);
56
82
  const transformer = createTransformer(v);
57
83
  return transformer(parsed.map(convertNumbersToZero));
58
84
  }
59
- const complex = { test, parse, createTransformer, getAnimatableNone };
85
+ const complex = {
86
+ test,
87
+ parse: parseComplexValue,
88
+ createTransformer,
89
+ getAnimatableNone,
90
+ };
60
91
 
61
92
  export { analyseComplexValue, complex };