framer-motion 7.7.0 → 7.7.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.
Files changed (65) hide show
  1. package/dist/cjs/index.js +549 -174
  2. package/dist/es/animation/legacy-popmotion/index.mjs +5 -3
  3. package/dist/es/animation/legacy-popmotion/inertia.mjs +2 -2
  4. package/dist/es/animation/utils/is-animatable.mjs +1 -1
  5. package/dist/es/animation/utils/transitions.mjs +5 -2
  6. package/dist/es/frameloop/create-render-step.mjs +88 -0
  7. package/dist/es/frameloop/data.mjs +6 -0
  8. package/dist/es/frameloop/index.mjs +59 -0
  9. package/dist/es/frameloop/on-next-frame.mjs +12 -0
  10. package/dist/es/gestures/PanSession.mjs +4 -3
  11. package/dist/es/gestures/drag/VisualElementDragControls.mjs +4 -5
  12. package/dist/es/gestures/drag/utils/constraints.mjs +1 -2
  13. package/dist/es/motion/features/layout/MeasureLayout.mjs +1 -1
  14. package/dist/es/projection/animation/mix-values.mjs +7 -8
  15. package/dist/es/projection/geometry/delta-remove.mjs +1 -1
  16. package/dist/es/projection/node/create-projection-node.mjs +1 -1
  17. package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
  18. package/dist/es/projection/styles/scale-box-shadow.mjs +1 -1
  19. package/dist/es/render/VisualElement.mjs +1 -1
  20. package/dist/es/render/dom/utils/unit-conversion.mjs +2 -1
  21. package/dist/es/render/dom/value-types/animatable-none.mjs +2 -1
  22. package/dist/es/render/dom/value-types/defaults.mjs +2 -1
  23. package/dist/es/render/dom/value-types/dimensions.mjs +2 -1
  24. package/dist/es/render/dom/value-types/find.mjs +2 -1
  25. package/dist/es/render/dom/value-types/number.mjs +2 -1
  26. package/dist/es/render/dom/value-types/type-int.mjs +1 -1
  27. package/dist/es/render/svg/utils/path.mjs +1 -1
  28. package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
  29. package/dist/es/render/utils/animation-state.mjs +1 -2
  30. package/dist/es/render/utils/motion-values.mjs +1 -1
  31. package/dist/es/render/utils/setters.mjs +1 -1
  32. package/dist/es/utils/delay.mjs +1 -1
  33. package/dist/es/utils/interpolate.mjs +1 -1
  34. package/dist/es/utils/mix-color.mjs +4 -1
  35. package/dist/es/utils/mix-complex.mjs +5 -24
  36. package/dist/es/utils/use-animation-frame.mjs +1 -1
  37. package/dist/es/utils/use-force-update.mjs +1 -1
  38. package/dist/es/utils/use-instant-transition.mjs +1 -1
  39. package/dist/es/value/index.mjs +4 -3
  40. package/dist/es/value/types/color/hex.mjs +40 -0
  41. package/dist/es/value/types/color/hsla.mjs +22 -0
  42. package/dist/es/value/types/color/index.mjs +28 -0
  43. package/dist/es/value/types/color/rgba.mjs +25 -0
  44. package/dist/es/value/types/color/utils.mjs +23 -0
  45. package/dist/es/value/types/complex/filter.mjs +30 -0
  46. package/dist/es/value/types/complex/index.mjs +61 -0
  47. package/dist/es/value/types/numbers/index.mjs +17 -0
  48. package/dist/es/value/types/numbers/units.mjs +19 -0
  49. package/dist/es/value/types/utils.mjs +15 -0
  50. package/dist/es/value/use-combine-values.mjs +1 -1
  51. package/dist/framer-motion.dev.js +304 -249
  52. package/dist/framer-motion.js +1 -1
  53. package/dist/index.d.ts +7 -2
  54. package/dist/projection.dev.js +5455 -5397
  55. package/dist/size-rollup-dom-animation-assets.js +1 -1
  56. package/dist/size-rollup-dom-animation.js +1 -1
  57. package/dist/size-rollup-dom-max-assets.js +1 -1
  58. package/dist/size-rollup-dom-max.js +1 -1
  59. package/dist/size-rollup-m.js +1 -1
  60. package/dist/size-rollup-motion.js +1 -1
  61. package/dist/size-webpack-dom-animation.js +1 -1
  62. package/dist/size-webpack-dom-max.js +1 -1
  63. package/dist/size-webpack-m.js +1 -1
  64. package/dist/three-entry.d.ts +7 -2
  65. package/package.json +9 -11
@@ -1,4 +1,5 @@
1
- import sync, { getFrameData } from 'framesync';
1
+ import { sync } from '../frameloop/index.mjs';
2
+ import { frameData } from '../frameloop/data.mjs';
2
3
  import { SubscriptionManager } from '../utils/subscription-manager.mjs';
3
4
  import { velocityPerSecond } from '../utils/velocity-per-second.mjs';
4
5
 
@@ -24,7 +25,7 @@ class MotionValue {
24
25
  * This will be replaced by the build step with the latest version number.
25
26
  * When MotionValues are provided to motion components, warn if versions are mixed.
26
27
  */
27
- this.version = "7.7.0";
28
+ this.version = "7.7.2";
28
29
  /**
29
30
  * Duration, in milliseconds, since last updating frame.
30
31
  *
@@ -67,7 +68,7 @@ class MotionValue {
67
68
  this.prev = this.current;
68
69
  this.current = v;
69
70
  // Update timestamp
70
- const { delta, timestamp } = getFrameData();
71
+ const { delta, timestamp } = frameData;
71
72
  if (this.lastUpdated !== timestamp) {
72
73
  this.timeDelta = delta;
73
74
  this.lastUpdated = timestamp;
@@ -0,0 +1,40 @@
1
+ import { rgba } from './rgba.mjs';
2
+ import { isColorString } from './utils.mjs';
3
+
4
+ function parseHex(v) {
5
+ let r = "";
6
+ let g = "";
7
+ let b = "";
8
+ let a = "";
9
+ // If we have 6 characters, ie #FF0000
10
+ if (v.length > 5) {
11
+ r = v.substring(1, 3);
12
+ g = v.substring(3, 5);
13
+ b = v.substring(5, 7);
14
+ a = v.substring(7, 9);
15
+ // Or we have 3 characters, ie #F00
16
+ }
17
+ else {
18
+ r = v.substring(1, 2);
19
+ g = v.substring(2, 3);
20
+ b = v.substring(3, 4);
21
+ a = v.substring(4, 5);
22
+ r += r;
23
+ g += g;
24
+ b += b;
25
+ a += a;
26
+ }
27
+ return {
28
+ red: parseInt(r, 16),
29
+ green: parseInt(g, 16),
30
+ blue: parseInt(b, 16),
31
+ alpha: a ? parseInt(a, 16) / 255 : 1,
32
+ };
33
+ }
34
+ const hex = {
35
+ test: isColorString("#"),
36
+ parse: parseHex,
37
+ transform: rgba.transform,
38
+ };
39
+
40
+ export { hex };
@@ -0,0 +1,22 @@
1
+ import { alpha } from '../numbers/index.mjs';
2
+ import { percent } from '../numbers/units.mjs';
3
+ import { sanitize } from '../utils.mjs';
4
+ import { isColorString, splitColor } from './utils.mjs';
5
+
6
+ const hsla = {
7
+ test: isColorString("hsl", "hue"),
8
+ parse: splitColor("hue", "saturation", "lightness"),
9
+ transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
10
+ return ("hsla(" +
11
+ Math.round(hue) +
12
+ ", " +
13
+ percent.transform(sanitize(saturation)) +
14
+ ", " +
15
+ percent.transform(sanitize(lightness)) +
16
+ ", " +
17
+ sanitize(alpha.transform(alpha$1)) +
18
+ ")");
19
+ },
20
+ };
21
+
22
+ export { hsla };
@@ -0,0 +1,28 @@
1
+ import { isString } from '../utils.mjs';
2
+ import { hex } from './hex.mjs';
3
+ import { hsla } from './hsla.mjs';
4
+ import { rgba } from './rgba.mjs';
5
+
6
+ const color = {
7
+ test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
8
+ parse: (v) => {
9
+ if (rgba.test(v)) {
10
+ return rgba.parse(v);
11
+ }
12
+ else if (hsla.test(v)) {
13
+ return hsla.parse(v);
14
+ }
15
+ else {
16
+ return hex.parse(v);
17
+ }
18
+ },
19
+ transform: (v) => {
20
+ return isString(v)
21
+ ? v
22
+ : v.hasOwnProperty("red")
23
+ ? rgba.transform(v)
24
+ : hsla.transform(v);
25
+ },
26
+ };
27
+
28
+ export { color };
@@ -0,0 +1,25 @@
1
+ import { clamp } from '../../../utils/clamp.mjs';
2
+ import { number, alpha } from '../numbers/index.mjs';
3
+ import { sanitize } from '../utils.mjs';
4
+ import { isColorString, splitColor } from './utils.mjs';
5
+
6
+ const clampRgbUnit = (v) => clamp(0, 255, v);
7
+ const rgbUnit = {
8
+ ...number,
9
+ transform: (v) => Math.round(clampRgbUnit(v)),
10
+ };
11
+ const rgba = {
12
+ test: isColorString("rgb", "red"),
13
+ parse: splitColor("red", "green", "blue"),
14
+ transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => "rgba(" +
15
+ rgbUnit.transform(red) +
16
+ ", " +
17
+ rgbUnit.transform(green) +
18
+ ", " +
19
+ rgbUnit.transform(blue) +
20
+ ", " +
21
+ sanitize(alpha.transform(alpha$1)) +
22
+ ")",
23
+ };
24
+
25
+ export { rgbUnit, rgba };
@@ -0,0 +1,23 @@
1
+ import { isString, singleColorRegex, floatRegex } from '../utils.mjs';
2
+
3
+ /**
4
+ * Returns true if the provided string is a color, ie rgba(0,0,0,0) or #000,
5
+ * but false if a number or multiple colors
6
+ */
7
+ const isColorString = (type, testProp) => (v) => {
8
+ return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
9
+ (testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
10
+ };
11
+ const splitColor = (aName, bName, cName) => (v) => {
12
+ if (!isString(v))
13
+ return v;
14
+ const [a, b, c, alpha] = v.match(floatRegex);
15
+ return {
16
+ [aName]: parseFloat(a),
17
+ [bName]: parseFloat(b),
18
+ [cName]: parseFloat(c),
19
+ alpha: alpha !== undefined ? parseFloat(alpha) : 1,
20
+ };
21
+ };
22
+
23
+ export { isColorString, splitColor };
@@ -0,0 +1,30 @@
1
+ import { complex } from './index.mjs';
2
+ import { floatRegex } from '../utils.mjs';
3
+
4
+ /**
5
+ * Properties that should default to 1 or 100%
6
+ */
7
+ const maxDefaults = new Set(["brightness", "contrast", "saturate", "opacity"]);
8
+ function applyDefaultFilter(v) {
9
+ const [name, value] = v.slice(0, -1).split("(");
10
+ if (name === "drop-shadow")
11
+ return v;
12
+ const [number] = value.match(floatRegex) || [];
13
+ if (!number)
14
+ return v;
15
+ const unit = value.replace(number, "");
16
+ let defaultValue = maxDefaults.has(name) ? 1 : 0;
17
+ if (number !== value)
18
+ defaultValue *= 100;
19
+ return name + "(" + defaultValue + unit + ")";
20
+ }
21
+ const functionRegex = /([a-z-]*)\(.*?\)/g;
22
+ const filter = {
23
+ ...complex,
24
+ getAnimatableNone: (v) => {
25
+ const functions = v.match(functionRegex);
26
+ return functions ? functions.map(applyDefaultFilter).join(" ") : v;
27
+ },
28
+ };
29
+
30
+ export { filter };
@@ -0,0 +1,61 @@
1
+ import { color } from '../color/index.mjs';
2
+ import { number } from '../numbers/index.mjs';
3
+ import { isString, floatRegex, colorRegex, sanitize } from '../utils.mjs';
4
+
5
+ const colorToken = "${c}";
6
+ const numberToken = "${n}";
7
+ function test(v) {
8
+ var _a, _b;
9
+ return (isNaN(v) &&
10
+ isString(v) &&
11
+ (((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
12
+ (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
13
+ 0);
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 };
36
+ }
37
+ function parse(v) {
38
+ return analyseComplexValue(v).values;
39
+ }
40
+ function createTransformer(source) {
41
+ const { values, numColors, tokenised } = analyseComplexValue(source);
42
+ const numValues = values.length;
43
+ return (v) => {
44
+ let output = tokenised;
45
+ 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]));
49
+ }
50
+ return output;
51
+ };
52
+ }
53
+ const convertNumbersToZero = (v) => typeof v === "number" ? 0 : v;
54
+ function getAnimatableNone(v) {
55
+ const parsed = parse(v);
56
+ const transformer = createTransformer(v);
57
+ return transformer(parsed.map(convertNumbersToZero));
58
+ }
59
+ const complex = { test, parse, createTransformer, getAnimatableNone };
60
+
61
+ export { analyseComplexValue, complex };
@@ -0,0 +1,17 @@
1
+ import { clamp } from '../../../utils/clamp.mjs';
2
+
3
+ const number = {
4
+ test: (v) => typeof v === "number",
5
+ parse: parseFloat,
6
+ transform: (v) => v,
7
+ };
8
+ const alpha = {
9
+ ...number,
10
+ transform: (v) => clamp(0, 1, v),
11
+ };
12
+ const scale = {
13
+ ...number,
14
+ default: 1,
15
+ };
16
+
17
+ export { alpha, number, scale };
@@ -0,0 +1,19 @@
1
+ import { isString } from '../utils.mjs';
2
+
3
+ const createUnitType = (unit) => ({
4
+ test: (v) => isString(v) && v.endsWith(unit) && v.split(" ").length === 1,
5
+ parse: parseFloat,
6
+ transform: (v) => `${v}${unit}`,
7
+ });
8
+ const degrees = createUnitType("deg");
9
+ const percent = createUnitType("%");
10
+ const px = createUnitType("px");
11
+ const vh = createUnitType("vh");
12
+ const vw = createUnitType("vw");
13
+ const progressPercentage = {
14
+ ...percent,
15
+ parse: (v) => percent.parse(v) / 100,
16
+ transform: (v) => percent.transform(v * 100),
17
+ };
18
+
19
+ export { degrees, percent, progressPercentage, px, vh, vw };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * TODO: When we move from string as a source of truth to data models
3
+ * everything in this folder should probably be referred to as models vs types
4
+ */
5
+ // If this number is a decimal, make it just five decimal places
6
+ // to avoid exponents
7
+ const sanitize = (v) => Math.round(v * 100000) / 100000;
8
+ const floatRegex = /(-)?([\d]*\.?[\d])+/g;
9
+ const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))/gi;
10
+ const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))$/i;
11
+ function isString(v) {
12
+ return typeof v === "string";
13
+ }
14
+
15
+ export { colorRegex, floatRegex, isString, sanitize, singleColorRegex };
@@ -1,6 +1,6 @@
1
1
  import { useMotionValue } from './use-motion-value.mjs';
2
2
  import { useMultiOnChange } from './use-on-change.mjs';
3
- import sync, { cancelSync } from 'framesync';
3
+ import { cancelSync, sync } from '../frameloop/index.mjs';
4
4
 
5
5
  function useCombineMotionValues(values, combineValues) {
6
6
  /**