framer-motion 6.4.3 → 7.0.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.
@@ -27,7 +27,7 @@
27
27
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
28
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
29
29
 
30
- /*! *****************************************************************************
30
+ /******************************************************************************
31
31
  Copyright (c) Microsoft Corporation.
32
32
 
33
33
  Permission to use, copy, modify, and/or distribute this software for any
@@ -887,43 +887,43 @@
887
887
  : value;
888
888
  };
889
889
 
890
- const clamp$1 = (min, max) => (v) => Math.max(Math.min(v, max), min);
891
- const sanitize = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
892
- const floatRegex = /(-)?([\d]*\.?[\d])+/g;
893
- const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
894
- const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
895
- function isString(v) {
890
+ const clamp$3 = (min, max) => (v) => Math.max(Math.min(v, max), min);
891
+ const sanitize$1 = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
892
+ const floatRegex$1 = /(-)?([\d]*\.?[\d])+/g;
893
+ const colorRegex$1 = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
894
+ const singleColorRegex$1 = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
895
+ function isString$2(v) {
896
896
  return typeof v === 'string';
897
897
  }
898
898
 
899
- const number = {
899
+ const number$1 = {
900
900
  test: (v) => typeof v === 'number',
901
901
  parse: parseFloat,
902
902
  transform: (v) => v,
903
903
  };
904
- const alpha = Object.assign(Object.assign({}, number), { transform: clamp$1(0, 1) });
905
- const scale = Object.assign(Object.assign({}, number), { default: 1 });
904
+ const alpha$1 = Object.assign(Object.assign({}, number$1), { transform: clamp$3(0, 1) });
905
+ const scale = Object.assign(Object.assign({}, number$1), { default: 1 });
906
906
 
907
- const createUnitType = (unit) => ({
908
- test: (v) => isString(v) && v.endsWith(unit) && v.split(' ').length === 1,
907
+ const createUnitType$1 = (unit) => ({
908
+ test: (v) => isString$2(v) && v.endsWith(unit) && v.split(' ').length === 1,
909
909
  parse: parseFloat,
910
910
  transform: (v) => `${v}${unit}`,
911
911
  });
912
- const degrees = createUnitType('deg');
913
- const percent = createUnitType('%');
914
- const px = createUnitType('px');
915
- const vh = createUnitType('vh');
916
- const vw = createUnitType('vw');
917
- const progressPercentage = Object.assign(Object.assign({}, percent), { parse: (v) => percent.parse(v) / 100, transform: (v) => percent.transform(v * 100) });
918
-
919
- const isColorString = (type, testProp) => (v) => {
920
- return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
912
+ const degrees = createUnitType$1('deg');
913
+ const percent$1 = createUnitType$1('%');
914
+ const px = createUnitType$1('px');
915
+ const vh = createUnitType$1('vh');
916
+ const vw = createUnitType$1('vw');
917
+ const progressPercentage = Object.assign(Object.assign({}, percent$1), { parse: (v) => percent$1.parse(v) / 100, transform: (v) => percent$1.transform(v * 100) });
918
+
919
+ const isColorString$1 = (type, testProp) => (v) => {
920
+ return Boolean((isString$2(v) && singleColorRegex$1.test(v) && v.startsWith(type)) ||
921
921
  (testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
922
922
  };
923
- const splitColor = (aName, bName, cName) => (v) => {
924
- if (!isString(v))
923
+ const splitColor$1 = (aName, bName, cName) => (v) => {
924
+ if (!isString$2(v))
925
925
  return v;
926
- const [a, b, c, alpha] = v.match(floatRegex);
926
+ const [a, b, c, alpha] = v.match(floatRegex$1);
927
927
  return {
928
928
  [aName]: parseFloat(a),
929
929
  [bName]: parseFloat(b),
@@ -932,39 +932,39 @@
932
932
  };
933
933
  };
934
934
 
935
- const hsla = {
936
- test: isColorString('hsl', 'hue'),
937
- parse: splitColor('hue', 'saturation', 'lightness'),
938
- transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
935
+ const hsla$1 = {
936
+ test: isColorString$1('hsl', 'hue'),
937
+ parse: splitColor$1('hue', 'saturation', 'lightness'),
938
+ transform: ({ hue, saturation, lightness, alpha: alpha$1$1 = 1 }) => {
939
939
  return ('hsla(' +
940
940
  Math.round(hue) +
941
941
  ', ' +
942
- percent.transform(sanitize(saturation)) +
942
+ percent$1.transform(sanitize$1(saturation)) +
943
943
  ', ' +
944
- percent.transform(sanitize(lightness)) +
944
+ percent$1.transform(sanitize$1(lightness)) +
945
945
  ', ' +
946
- sanitize(alpha.transform(alpha$1)) +
946
+ sanitize$1(alpha$1.transform(alpha$1$1)) +
947
947
  ')');
948
948
  },
949
949
  };
950
950
 
951
- const clampRgbUnit = clamp$1(0, 255);
952
- const rgbUnit = Object.assign(Object.assign({}, number), { transform: (v) => Math.round(clampRgbUnit(v)) });
953
- const rgba = {
954
- test: isColorString('rgb', 'red'),
955
- parse: splitColor('red', 'green', 'blue'),
956
- transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => 'rgba(' +
957
- rgbUnit.transform(red) +
951
+ const clampRgbUnit$1 = clamp$3(0, 255);
952
+ const rgbUnit$1 = Object.assign(Object.assign({}, number$1), { transform: (v) => Math.round(clampRgbUnit$1(v)) });
953
+ const rgba$1 = {
954
+ test: isColorString$1('rgb', 'red'),
955
+ parse: splitColor$1('red', 'green', 'blue'),
956
+ transform: ({ red, green, blue, alpha: alpha$1$1 = 1 }) => 'rgba(' +
957
+ rgbUnit$1.transform(red) +
958
958
  ', ' +
959
- rgbUnit.transform(green) +
959
+ rgbUnit$1.transform(green) +
960
960
  ', ' +
961
- rgbUnit.transform(blue) +
961
+ rgbUnit$1.transform(blue) +
962
962
  ', ' +
963
- sanitize(alpha.transform(alpha$1)) +
963
+ sanitize$1(alpha$1.transform(alpha$1$1)) +
964
964
  ')',
965
965
  };
966
966
 
967
- function parseHex(v) {
967
+ function parseHex$1(v) {
968
968
  let r = '';
969
969
  let g = '';
970
970
  let b = '';
@@ -992,88 +992,88 @@
992
992
  alpha: a ? parseInt(a, 16) / 255 : 1,
993
993
  };
994
994
  }
995
- const hex = {
996
- test: isColorString('#'),
997
- parse: parseHex,
998
- transform: rgba.transform,
995
+ const hex$1 = {
996
+ test: isColorString$1('#'),
997
+ parse: parseHex$1,
998
+ transform: rgba$1.transform,
999
999
  };
1000
1000
 
1001
- const color = {
1002
- test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
1001
+ const color$1 = {
1002
+ test: (v) => rgba$1.test(v) || hex$1.test(v) || hsla$1.test(v),
1003
1003
  parse: (v) => {
1004
- if (rgba.test(v)) {
1005
- return rgba.parse(v);
1004
+ if (rgba$1.test(v)) {
1005
+ return rgba$1.parse(v);
1006
1006
  }
1007
- else if (hsla.test(v)) {
1008
- return hsla.parse(v);
1007
+ else if (hsla$1.test(v)) {
1008
+ return hsla$1.parse(v);
1009
1009
  }
1010
1010
  else {
1011
- return hex.parse(v);
1011
+ return hex$1.parse(v);
1012
1012
  }
1013
1013
  },
1014
1014
  transform: (v) => {
1015
- return isString(v)
1015
+ return isString$2(v)
1016
1016
  ? v
1017
1017
  : v.hasOwnProperty('red')
1018
- ? rgba.transform(v)
1019
- : hsla.transform(v);
1018
+ ? rgba$1.transform(v)
1019
+ : hsla$1.transform(v);
1020
1020
  },
1021
1021
  };
1022
1022
 
1023
- const colorToken = '${c}';
1024
- const numberToken = '${n}';
1025
- function test(v) {
1023
+ const colorToken$1 = '${c}';
1024
+ const numberToken$1 = '${n}';
1025
+ function test$1(v) {
1026
1026
  var _a, _b, _c, _d;
1027
1027
  return (isNaN(v) &&
1028
- isString(v) &&
1029
- ((_b = (_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = v.match(colorRegex)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0);
1028
+ isString$2(v) &&
1029
+ ((_b = (_a = v.match(floatRegex$1)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = v.match(colorRegex$1)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0);
1030
1030
  }
1031
- function analyse$1(v) {
1031
+ function analyse$2(v) {
1032
1032
  if (typeof v === 'number')
1033
1033
  v = `${v}`;
1034
1034
  const values = [];
1035
1035
  let numColors = 0;
1036
- const colors = v.match(colorRegex);
1036
+ const colors = v.match(colorRegex$1);
1037
1037
  if (colors) {
1038
1038
  numColors = colors.length;
1039
- v = v.replace(colorRegex, colorToken);
1040
- values.push(...colors.map(color.parse));
1039
+ v = v.replace(colorRegex$1, colorToken$1);
1040
+ values.push(...colors.map(color$1.parse));
1041
1041
  }
1042
- const numbers = v.match(floatRegex);
1042
+ const numbers = v.match(floatRegex$1);
1043
1043
  if (numbers) {
1044
- v = v.replace(floatRegex, numberToken);
1045
- values.push(...numbers.map(number.parse));
1044
+ v = v.replace(floatRegex$1, numberToken$1);
1045
+ values.push(...numbers.map(number$1.parse));
1046
1046
  }
1047
1047
  return { values, numColors, tokenised: v };
1048
1048
  }
1049
- function parse(v) {
1050
- return analyse$1(v).values;
1049
+ function parse$1(v) {
1050
+ return analyse$2(v).values;
1051
1051
  }
1052
- function createTransformer(v) {
1053
- const { values, numColors, tokenised } = analyse$1(v);
1052
+ function createTransformer$1(v) {
1053
+ const { values, numColors, tokenised } = analyse$2(v);
1054
1054
  const numValues = values.length;
1055
1055
  return (v) => {
1056
1056
  let output = tokenised;
1057
1057
  for (let i = 0; i < numValues; i++) {
1058
- output = output.replace(i < numColors ? colorToken : numberToken, i < numColors ? color.transform(v[i]) : sanitize(v[i]));
1058
+ output = output.replace(i < numColors ? colorToken$1 : numberToken$1, i < numColors ? color$1.transform(v[i]) : sanitize$1(v[i]));
1059
1059
  }
1060
1060
  return output;
1061
1061
  };
1062
1062
  }
1063
- const convertNumbersToZero = (v) => typeof v === 'number' ? 0 : v;
1064
- function getAnimatableNone$1(v) {
1065
- const parsed = parse(v);
1066
- const transformer = createTransformer(v);
1067
- return transformer(parsed.map(convertNumbersToZero));
1063
+ const convertNumbersToZero$1 = (v) => typeof v === 'number' ? 0 : v;
1064
+ function getAnimatableNone$2(v) {
1065
+ const parsed = parse$1(v);
1066
+ const transformer = createTransformer$1(v);
1067
+ return transformer(parsed.map(convertNumbersToZero$1));
1068
1068
  }
1069
- const complex = { test, parse, createTransformer, getAnimatableNone: getAnimatableNone$1 };
1069
+ const complex$1 = { test: test$1, parse: parse$1, createTransformer: createTransformer$1, getAnimatableNone: getAnimatableNone$2 };
1070
1070
 
1071
1071
  const maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
1072
1072
  function applyDefaultFilter(v) {
1073
1073
  let [name, value] = v.slice(0, -1).split('(');
1074
1074
  if (name === 'drop-shadow')
1075
1075
  return v;
1076
- const [number] = value.match(floatRegex) || [];
1076
+ const [number] = value.match(floatRegex$1) || [];
1077
1077
  if (!number)
1078
1078
  return v;
1079
1079
  const unit = value.replace(number, '');
@@ -1083,12 +1083,12 @@
1083
1083
  return name + '(' + defaultValue + unit + ')';
1084
1084
  }
1085
1085
  const functionRegex = /([a-z-]*)\(.*?\)/g;
1086
- const filter = Object.assign(Object.assign({}, complex), { getAnimatableNone: (v) => {
1086
+ const filter = Object.assign(Object.assign({}, complex$1), { getAnimatableNone: (v) => {
1087
1087
  const functions = v.match(functionRegex);
1088
1088
  return functions ? functions.map(applyDefaultFilter).join(' ') : v;
1089
1089
  } });
1090
1090
 
1091
- var int = __assign(__assign({}, number), { transform: Math.round });
1091
+ var int = __assign(__assign({}, number$1), { transform: Math.round });
1092
1092
 
1093
1093
  var numberValueTypes = {
1094
1094
  // Border props
@@ -1145,15 +1145,15 @@
1145
1145
  z: px,
1146
1146
  perspective: px,
1147
1147
  transformPerspective: px,
1148
- opacity: alpha,
1148
+ opacity: alpha$1,
1149
1149
  originX: progressPercentage,
1150
1150
  originY: progressPercentage,
1151
1151
  originZ: px,
1152
1152
  // Misc
1153
1153
  zIndex: int,
1154
1154
  // SVG
1155
- fillOpacity: alpha,
1156
- strokeOpacity: alpha,
1155
+ fillOpacity: alpha$1,
1156
+ strokeOpacity: alpha$1,
1157
1157
  numOctaves: int,
1158
1158
  };
1159
1159
 
@@ -2008,7 +2008,7 @@
2008
2008
  return React.useEffect(function () { return function () { return callback(); }; }, []);
2009
2009
  }
2010
2010
 
2011
- const clamp = (min, max, v) => Math.min(Math.max(v, min), max);
2011
+ const clamp$2 = (min, max, v) => Math.min(Math.max(v, min), max);
2012
2012
 
2013
2013
  const safeMin = 0.001;
2014
2014
  const minDuration = 0.01;
@@ -2020,8 +2020,8 @@
2020
2020
  let derivative;
2021
2021
  warning(duration <= maxDuration * 1000, "Spring duration must be 10 seconds or less");
2022
2022
  let dampingRatio = 1 - bounce;
2023
- dampingRatio = clamp(minDamping, maxDamping, dampingRatio);
2024
- duration = clamp(minDuration, maxDuration, duration / 1000);
2023
+ dampingRatio = clamp$2(minDamping, maxDamping, dampingRatio);
2024
+ duration = clamp$2(minDuration, maxDuration, duration / 1000);
2025
2025
  if (dampingRatio < 1) {
2026
2026
  envelope = (undampedFreq) => {
2027
2027
  const exponentialDecay = undampedFreq * dampingRatio;
@@ -2200,12 +2200,189 @@
2200
2200
  spring.needsInterpolation = (a, b) => typeof a === "string" || typeof b === "string";
2201
2201
  const zero = (_t) => 0;
2202
2202
 
2203
- const progress = (from, to, value) => {
2203
+ const progress$1 = (from, to, value) => {
2204
2204
  const toFromDifference = to - from;
2205
2205
  return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
2206
2206
  };
2207
2207
 
2208
- const mix = (from, to, progress) => -progress * from + progress * to + from;
2208
+ const mix$1 = (from, to, progress) => -progress * from + progress * to + from;
2209
+
2210
+ const clamp$1 = (min, max) => (v) => Math.max(Math.min(v, max), min);
2211
+ const sanitize = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
2212
+ const floatRegex = /(-)?([\d]*\.?[\d])+/g;
2213
+ const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
2214
+ const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
2215
+ function isString$1(v) {
2216
+ return typeof v === 'string';
2217
+ }
2218
+
2219
+ const number = {
2220
+ test: (v) => typeof v === 'number',
2221
+ parse: parseFloat,
2222
+ transform: (v) => v,
2223
+ };
2224
+ const alpha = Object.assign(Object.assign({}, number), { transform: clamp$1(0, 1) });
2225
+ Object.assign(Object.assign({}, number), { default: 1 });
2226
+
2227
+ const createUnitType = (unit) => ({
2228
+ test: (v) => isString$1(v) && v.endsWith(unit) && v.split(' ').length === 1,
2229
+ parse: parseFloat,
2230
+ transform: (v) => `${v}${unit}`,
2231
+ });
2232
+ const percent = createUnitType('%');
2233
+ Object.assign(Object.assign({}, percent), { parse: (v) => percent.parse(v) / 100, transform: (v) => percent.transform(v * 100) });
2234
+
2235
+ const isColorString = (type, testProp) => (v) => {
2236
+ return Boolean((isString$1(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
2237
+ (testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
2238
+ };
2239
+ const splitColor = (aName, bName, cName) => (v) => {
2240
+ if (!isString$1(v))
2241
+ return v;
2242
+ const [a, b, c, alpha] = v.match(floatRegex);
2243
+ return {
2244
+ [aName]: parseFloat(a),
2245
+ [bName]: parseFloat(b),
2246
+ [cName]: parseFloat(c),
2247
+ alpha: alpha !== undefined ? parseFloat(alpha) : 1,
2248
+ };
2249
+ };
2250
+
2251
+ const hsla = {
2252
+ test: isColorString('hsl', 'hue'),
2253
+ parse: splitColor('hue', 'saturation', 'lightness'),
2254
+ transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
2255
+ return ('hsla(' +
2256
+ Math.round(hue) +
2257
+ ', ' +
2258
+ percent.transform(sanitize(saturation)) +
2259
+ ', ' +
2260
+ percent.transform(sanitize(lightness)) +
2261
+ ', ' +
2262
+ sanitize(alpha.transform(alpha$1)) +
2263
+ ')');
2264
+ },
2265
+ };
2266
+
2267
+ const clampRgbUnit = clamp$1(0, 255);
2268
+ const rgbUnit = Object.assign(Object.assign({}, number), { transform: (v) => Math.round(clampRgbUnit(v)) });
2269
+ const rgba = {
2270
+ test: isColorString('rgb', 'red'),
2271
+ parse: splitColor('red', 'green', 'blue'),
2272
+ transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => 'rgba(' +
2273
+ rgbUnit.transform(red) +
2274
+ ', ' +
2275
+ rgbUnit.transform(green) +
2276
+ ', ' +
2277
+ rgbUnit.transform(blue) +
2278
+ ', ' +
2279
+ sanitize(alpha.transform(alpha$1)) +
2280
+ ')',
2281
+ };
2282
+
2283
+ function parseHex(v) {
2284
+ let r = '';
2285
+ let g = '';
2286
+ let b = '';
2287
+ let a = '';
2288
+ if (v.length > 5) {
2289
+ r = v.substr(1, 2);
2290
+ g = v.substr(3, 2);
2291
+ b = v.substr(5, 2);
2292
+ a = v.substr(7, 2);
2293
+ }
2294
+ else {
2295
+ r = v.substr(1, 1);
2296
+ g = v.substr(2, 1);
2297
+ b = v.substr(3, 1);
2298
+ a = v.substr(4, 1);
2299
+ r += r;
2300
+ g += g;
2301
+ b += b;
2302
+ a += a;
2303
+ }
2304
+ return {
2305
+ red: parseInt(r, 16),
2306
+ green: parseInt(g, 16),
2307
+ blue: parseInt(b, 16),
2308
+ alpha: a ? parseInt(a, 16) / 255 : 1,
2309
+ };
2310
+ }
2311
+ const hex = {
2312
+ test: isColorString('#'),
2313
+ parse: parseHex,
2314
+ transform: rgba.transform,
2315
+ };
2316
+
2317
+ const color = {
2318
+ test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
2319
+ parse: (v) => {
2320
+ if (rgba.test(v)) {
2321
+ return rgba.parse(v);
2322
+ }
2323
+ else if (hsla.test(v)) {
2324
+ return hsla.parse(v);
2325
+ }
2326
+ else {
2327
+ return hex.parse(v);
2328
+ }
2329
+ },
2330
+ transform: (v) => {
2331
+ return isString$1(v)
2332
+ ? v
2333
+ : v.hasOwnProperty('red')
2334
+ ? rgba.transform(v)
2335
+ : hsla.transform(v);
2336
+ },
2337
+ };
2338
+
2339
+ const colorToken = '${c}';
2340
+ const numberToken = '${n}';
2341
+ function test(v) {
2342
+ var _a, _b, _c, _d;
2343
+ return (isNaN(v) &&
2344
+ isString$1(v) &&
2345
+ ((_b = (_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = v.match(colorRegex)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0);
2346
+ }
2347
+ function analyse$1(v) {
2348
+ if (typeof v === 'number')
2349
+ v = `${v}`;
2350
+ const values = [];
2351
+ let numColors = 0;
2352
+ const colors = v.match(colorRegex);
2353
+ if (colors) {
2354
+ numColors = colors.length;
2355
+ v = v.replace(colorRegex, colorToken);
2356
+ values.push(...colors.map(color.parse));
2357
+ }
2358
+ const numbers = v.match(floatRegex);
2359
+ if (numbers) {
2360
+ v = v.replace(floatRegex, numberToken);
2361
+ values.push(...numbers.map(number.parse));
2362
+ }
2363
+ return { values, numColors, tokenised: v };
2364
+ }
2365
+ function parse(v) {
2366
+ return analyse$1(v).values;
2367
+ }
2368
+ function createTransformer(v) {
2369
+ const { values, numColors, tokenised } = analyse$1(v);
2370
+ const numValues = values.length;
2371
+ return (v) => {
2372
+ let output = tokenised;
2373
+ for (let i = 0; i < numValues; i++) {
2374
+ output = output.replace(i < numColors ? colorToken : numberToken, i < numColors ? color.transform(v[i]) : sanitize(v[i]));
2375
+ }
2376
+ return output;
2377
+ };
2378
+ }
2379
+ const convertNumbersToZero = (v) => typeof v === 'number' ? 0 : v;
2380
+ function getAnimatableNone$1(v) {
2381
+ const parsed = parse(v);
2382
+ const transformer = createTransformer(v);
2383
+ return transformer(parsed.map(convertNumbersToZero));
2384
+ }
2385
+ const complex = { test, parse, createTransformer, getAnimatableNone: getAnimatableNone$1 };
2209
2386
 
2210
2387
  function hueToRgb(p, q, t) {
2211
2388
  if (t < 0)
@@ -2277,7 +2454,7 @@
2277
2454
  blended[key] = mixLinearColor(fromColor[key], toColor[key], v);
2278
2455
  }
2279
2456
  }
2280
- blended.alpha = mix(fromColor.alpha, toColor.alpha, v);
2457
+ blended.alpha = mix$1(fromColor.alpha, toColor.alpha, v);
2281
2458
  return fromColorType.transform(blended);
2282
2459
  };
2283
2460
  };
@@ -2289,7 +2466,7 @@
2289
2466
 
2290
2467
  function getMixer$1(origin, target) {
2291
2468
  if (isNum(origin)) {
2292
- return (v) => mix(origin, target, v);
2469
+ return (v) => mix$1(origin, target, v);
2293
2470
  }
2294
2471
  else if (color.test(origin)) {
2295
2472
  return mixColor(origin, target);
@@ -2361,7 +2538,7 @@
2361
2538
  }
2362
2539
  };
2363
2540
 
2364
- const mixNumber = (from, to) => (p) => mix(from, to, p);
2541
+ const mixNumber = (from, to) => (p) => mix$1(from, to, p);
2365
2542
  function detectMixerFactory(v) {
2366
2543
  if (typeof v === 'number') {
2367
2544
  return mixNumber;
@@ -2396,7 +2573,7 @@
2396
2573
  return mixers;
2397
2574
  }
2398
2575
  function fastInterpolate([from, to], [mixer]) {
2399
- return (v) => mixer(progress(from, to, v));
2576
+ return (v) => mixer(progress$1(from, to, v));
2400
2577
  }
2401
2578
  function slowInterpolate(input, mixers) {
2402
2579
  const inputLength = input.length;
@@ -2420,11 +2597,11 @@
2420
2597
  }
2421
2598
  mixerIndex = i - 1;
2422
2599
  }
2423
- const progressInRange = progress(input[mixerIndex], input[mixerIndex + 1], v);
2600
+ const progressInRange = progress$1(input[mixerIndex], input[mixerIndex + 1], v);
2424
2601
  return mixers[mixerIndex](progressInRange);
2425
2602
  };
2426
2603
  }
2427
- function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
2604
+ function interpolate$1(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
2428
2605
  const inputLength = input.length;
2429
2606
  invariant(inputLength === output.length, 'Both input and output ranges must be the same length');
2430
2607
  invariant(!ease || !Array.isArray(ease) || ease.length === inputLength - 1, 'Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values.');
@@ -2439,7 +2616,7 @@
2439
2616
  ? fastInterpolate(input, mixers)
2440
2617
  : slowInterpolate(input, mixers);
2441
2618
  return isClamp
2442
- ? (v) => interpolator(clamp(input[0], input[inputLength - 1], v))
2619
+ ? (v) => interpolator(clamp$2(input[0], input[inputLength - 1], v))
2443
2620
  : interpolator;
2444
2621
  }
2445
2622
 
@@ -2492,7 +2669,7 @@
2492
2669
  function defaultEasing(values, easing) {
2493
2670
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
2494
2671
  }
2495
- function defaultOffset(values) {
2672
+ function defaultOffset$2(values) {
2496
2673
  const numValues = values.length;
2497
2674
  return values.map((_value, i) => i !== 0 ? i / (numValues - 1) : 0);
2498
2675
  }
@@ -2504,9 +2681,9 @@
2504
2681
  const values = Array.isArray(to) ? to : [from, to];
2505
2682
  const times = convertOffsetToTimes(offset && offset.length === values.length
2506
2683
  ? offset
2507
- : defaultOffset(values), duration);
2684
+ : defaultOffset$2(values), duration);
2508
2685
  function createInterpolator() {
2509
- return interpolate(times, values, {
2686
+ return interpolate$1(times, values, {
2510
2687
  ease: Array.isArray(ease) ? ease : defaultEasing(values, ease),
2511
2688
  });
2512
2689
  }
@@ -2567,12 +2744,12 @@
2567
2744
  }
2568
2745
 
2569
2746
  const defaultTimestep = (1 / 60) * 1000;
2570
- const getCurrentTime$1 = typeof performance !== "undefined"
2747
+ const getCurrentTime = typeof performance !== "undefined"
2571
2748
  ? () => performance.now()
2572
2749
  : () => Date.now();
2573
2750
  const onNextFrame = typeof window !== "undefined"
2574
2751
  ? (callback) => window.requestAnimationFrame(callback)
2575
- : (callback) => setTimeout(() => callback(getCurrentTime$1()), defaultTimestep);
2752
+ : (callback) => setTimeout(() => callback(getCurrentTime()), defaultTimestep);
2576
2753
 
2577
2754
  function createRenderStep(runNextFrame) {
2578
2755
  let toRun = [];
@@ -2629,7 +2806,7 @@
2629
2806
  return step;
2630
2807
  }
2631
2808
 
2632
- const maxElapsed = 40;
2809
+ const maxElapsed$1 = 40;
2633
2810
  let useDefaultElapsed = true;
2634
2811
  let runNextFrame = false;
2635
2812
  let isProcessing = false;
@@ -2670,7 +2847,7 @@
2670
2847
  runNextFrame = false;
2671
2848
  frame.delta = useDefaultElapsed
2672
2849
  ? defaultTimestep
2673
- : Math.max(Math.min(timestamp - frame.timestamp, maxElapsed), 1);
2850
+ : Math.max(Math.min(timestamp - frame.timestamp, maxElapsed$1), 1);
2674
2851
  frame.timestamp = timestamp;
2675
2852
  isProcessing = true;
2676
2853
  stepsOrder.forEach(processStep);
@@ -2720,7 +2897,7 @@
2720
2897
  let interpolateFromNumber;
2721
2898
  const animator = detectAnimationFromOptions(options);
2722
2899
  if ((_c = (_b = animator).needsInterpolation) === null || _c === void 0 ? void 0 : _c.call(_b, from, to)) {
2723
- interpolateFromNumber = interpolate([0, 100], [from, to], {
2900
+ interpolateFromNumber = interpolate$1([0, 100], [from, to], {
2724
2901
  clamp: false,
2725
2902
  });
2726
2903
  from = 0;
@@ -2782,7 +2959,7 @@
2782
2959
  };
2783
2960
  }
2784
2961
 
2785
- function velocityPerSecond(velocity, frameDuration) {
2962
+ function velocityPerSecond$1(velocity, frameDuration) {
2786
2963
  return frameDuration ? velocity * (1000 / frameDuration) : 0;
2787
2964
  }
2788
2965
 
@@ -2824,7 +3001,7 @@
2824
3001
  const checkBoundary = (v) => {
2825
3002
  prev = current;
2826
3003
  current = v;
2827
- velocity = velocityPerSecond(v - prev, getFrameData().delta);
3004
+ velocity = velocityPerSecond$1(v - prev, getFrameData().delta);
2828
3005
  if ((heading === 1 && v > boundary) ||
2829
3006
  (heading === -1 && v < boundary)) {
2830
3007
  startSpring({ from: v, to: boundary, velocity });
@@ -2863,7 +3040,7 @@
2863
3040
  }
2864
3041
  }
2865
3042
 
2866
- const wrap = (min, max, v) => {
3043
+ const wrap$1 = (min, max, v) => {
2867
3044
  const rangeSize = max - min;
2868
3045
  return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
2869
3046
  };
@@ -3311,7 +3488,7 @@
3311
3488
  if (typeof value === "number" || Array.isArray(value))
3312
3489
  return true;
3313
3490
  if (typeof value === "string" && // It's animatable if we have a string
3314
- complex.test(value) && // And it contains numbers and/or colors
3491
+ complex$1.test(value) && // And it contains numbers and/or colors
3315
3492
  !value.startsWith("url(") // Unless it starts with "url("
3316
3493
  ) {
3317
3494
  return true;
@@ -3374,9 +3551,9 @@
3374
3551
  */
3375
3552
  var defaultValueTypes = __assign(__assign({}, numberValueTypes), {
3376
3553
  // Color props
3377
- color: color, backgroundColor: color, outlineColor: color, fill: color, stroke: color,
3554
+ color: color$1, backgroundColor: color$1, outlineColor: color$1, fill: color$1, stroke: color$1,
3378
3555
  // Border props
3379
- borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter: filter, WebkitFilter: filter });
3556
+ borderColor: color$1, borderTopColor: color$1, borderRightColor: color$1, borderBottomColor: color$1, borderLeftColor: color$1, filter: filter, WebkitFilter: filter });
3380
3557
  /**
3381
3558
  * Gets the default ValueType for the provided value key
3382
3559
  */
@@ -3386,7 +3563,7 @@
3386
3563
  var _a;
3387
3564
  var defaultValueType = getDefaultValueType(key);
3388
3565
  if (defaultValueType !== filter)
3389
- defaultValueType = complex;
3566
+ defaultValueType = complex$1;
3390
3567
  // If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
3391
3568
  return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
3392
3569
  }
@@ -3682,7 +3859,7 @@
3682
3859
  * This will be replaced by the build step with the latest version number.
3683
3860
  * When MotionValues are provided to motion components, warn if versions are mixed.
3684
3861
  */
3685
- this.version = "6.4.3";
3862
+ this.version = "7.0.0";
3686
3863
  /**
3687
3864
  * Duration, in milliseconds, since last updating frame.
3688
3865
  *
@@ -3900,7 +4077,7 @@
3900
4077
  // This could be isFloat(this.prev) && isFloat(this.current), but that would be wasteful
3901
4078
  return this.canTrackVelocity
3902
4079
  ? // These casts could be avoided if parseFloat would be typed better
3903
- velocityPerSecond(parseFloat(this.current) -
4080
+ velocityPerSecond$1(parseFloat(this.current) -
3904
4081
  parseFloat(this.prev), this.timeDelta)
3905
4082
  : 0;
3906
4083
  };
@@ -3981,7 +4158,7 @@
3981
4158
  /**
3982
4159
  * A list of value types commonly used for dimensions
3983
4160
  */
3984
- var dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
4161
+ var dimensionValueTypes = [number$1, px, percent$1, degrees, vw, vh, auto];
3985
4162
  /**
3986
4163
  * Tests a dimensional value against the list of dimension ValueTypes
3987
4164
  */
@@ -3992,7 +4169,7 @@
3992
4169
  /**
3993
4170
  * A list of all ValueTypes
3994
4171
  */
3995
- var valueTypes = __spreadArray(__spreadArray([], __read(dimensionValueTypes), false), [color, complex], false);
4172
+ var valueTypes = __spreadArray(__spreadArray([], __read(dimensionValueTypes), false), [color$1, complex$1], false);
3996
4173
  /**
3997
4174
  * Tests a value against the list of ValueTypes
3998
4175
  */
@@ -4078,7 +4255,7 @@
4078
4255
  // If this is a number read as a string, ie "0" or "200", convert it to a number
4079
4256
  value = parseFloat(value);
4080
4257
  }
4081
- else if (!findValueType(value) && complex.test(targetValue)) {
4258
+ else if (!findValueType(value) && complex$1.test(targetValue)) {
4082
4259
  value = getAnimatableNone(key, targetValue);
4083
4260
  }
4084
4261
  visualElement.addValue(key, motionValue(value));
@@ -4608,8 +4785,8 @@
4608
4785
  */
4609
4786
  var PanSession = /** @class */ (function () {
4610
4787
  function PanSession(event, handlers, _a) {
4611
- var _this = this;
4612
4788
  var _b = _a === void 0 ? {} : _a, transformPagePoint = _b.transformPagePoint;
4789
+ var _this = this;
4613
4790
  /**
4614
4791
  * @internal
4615
4792
  */
@@ -4758,12 +4935,12 @@
4758
4935
  function calcAxisDelta(delta, source, target, origin) {
4759
4936
  if (origin === void 0) { origin = 0.5; }
4760
4937
  delta.origin = origin;
4761
- delta.originPoint = mix(source.min, source.max, delta.origin);
4938
+ delta.originPoint = mix$1(source.min, source.max, delta.origin);
4762
4939
  delta.scale = calcLength(target) / calcLength(source);
4763
4940
  if (isNear(delta.scale, 1, 0.0001) || isNaN(delta.scale))
4764
4941
  delta.scale = 1;
4765
4942
  delta.translate =
4766
- mix(target.min, target.max, delta.origin) - delta.originPoint;
4943
+ mix$1(target.min, target.max, delta.origin) - delta.originPoint;
4767
4944
  if (isNear(delta.translate) || isNaN(delta.translate))
4768
4945
  delta.translate = 0;
4769
4946
  }
@@ -4797,11 +4974,11 @@
4797
4974
  var min = _a.min, max = _a.max;
4798
4975
  if (min !== undefined && point < min) {
4799
4976
  // If we have a min point defined, and this is outside of that, constrain
4800
- point = elastic ? mix(min, point, elastic.min) : Math.max(point, min);
4977
+ point = elastic ? mix$1(min, point, elastic.min) : Math.max(point, min);
4801
4978
  }
4802
4979
  else if (max !== undefined && point > max) {
4803
4980
  // If we have a max point defined, and this is outside of that, constrain
4804
- point = elastic ? mix(max, point, elastic.max) : Math.min(point, max);
4981
+ point = elastic ? mix$1(max, point, elastic.max) : Math.min(point, max);
4805
4982
  }
4806
4983
  return point;
4807
4984
  }
@@ -4862,12 +5039,12 @@
4862
5039
  var sourceLength = calcLength(source);
4863
5040
  var targetLength = calcLength(target);
4864
5041
  if (targetLength > sourceLength) {
4865
- origin = progress(target.min, target.max - sourceLength, source.min);
5042
+ origin = progress$1(target.min, target.max - sourceLength, source.min);
4866
5043
  }
4867
5044
  else if (sourceLength > targetLength) {
4868
- origin = progress(source.min, source.max - targetLength, target.min);
5045
+ origin = progress$1(source.min, source.max - targetLength, target.min);
4869
5046
  }
4870
- return clamp(0, 1, origin);
5047
+ return clamp$2(0, 1, origin);
4871
5048
  }
4872
5049
  /**
4873
5050
  * Rebase the calculated viewport constraints relative to the layout.min point.
@@ -5073,7 +5250,7 @@
5073
5250
  function transformAxis(axis, transforms, _a) {
5074
5251
  var _b = __read(_a, 3), key = _b[0], scaleKey = _b[1], originKey = _b[2];
5075
5252
  var axisOrigin = transforms[originKey] !== undefined ? transforms[originKey] : 0.5;
5076
- var originPoint = mix(axis.min, axis.max, axisOrigin);
5253
+ var originPoint = mix$1(axis.min, axis.max, axisOrigin);
5077
5254
  // Apply the axis delta to the final axis
5078
5255
  applyAxisDelta(axis, transforms[key], transforms[scaleKey], originPoint, transforms.scale);
5079
5256
  }
@@ -5172,7 +5349,7 @@
5172
5349
  /**
5173
5350
  * If the MotionValue is a percentage value convert to px
5174
5351
  */
5175
- if (percent.test(current)) {
5352
+ if (percent$1.test(current)) {
5176
5353
  var measuredAxis = (_b = (_a = _this.visualElement.projection) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.actual[axis];
5177
5354
  if (measuredAxis) {
5178
5355
  var length_1 = calcLength(measuredAxis);
@@ -5386,7 +5563,7 @@
5386
5563
  var axisValue = _this.getAxisMotionValue(axis);
5387
5564
  if (projection && projection.layout) {
5388
5565
  var _a = projection.layout.actual[axis], min = _a.min, max = _a.max;
5389
- axisValue.set(point[axis] - mix(min, max, 0.5));
5566
+ axisValue.set(point[axis] - mix$1(min, max, 0.5));
5390
5567
  }
5391
5568
  });
5392
5569
  };
@@ -5441,7 +5618,7 @@
5441
5618
  */
5442
5619
  var axisValue = _this.getAxisMotionValue(axis);
5443
5620
  var _a = _this.constraints[axis], min = _a.min, max = _a.max;
5444
- axisValue.set(mix(min, max, boxProgress[axis]));
5621
+ axisValue.set(mix$1(min, max, boxProgress[axis]));
5445
5622
  });
5446
5623
  };
5447
5624
  VisualElementDragControls.prototype.addListeners = function () {
@@ -5480,7 +5657,7 @@
5480
5657
  * If the element's layout changes, calculate the delta and apply that to
5481
5658
  * the drag gesture's origin point.
5482
5659
  */
5483
- projection.addEventListener("didUpdate", (function (_a) {
5660
+ var stopLayoutUpdateListener = projection.addEventListener("didUpdate", (function (_a) {
5484
5661
  var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged;
5485
5662
  if (_this.isDragging && hasLayoutChanged) {
5486
5663
  eachAxis(function (axis) {
@@ -5497,6 +5674,7 @@
5497
5674
  stopResizeListener();
5498
5675
  stopPointerListener();
5499
5676
  stopMeasureLayoutListener();
5677
+ stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
5500
5678
  };
5501
5679
  };
5502
5680
  VisualElementDragControls.prototype.getProps = function () {
@@ -5651,7 +5829,7 @@
5651
5829
  * and warn against mismatches.
5652
5830
  */
5653
5831
  {
5654
- warnOnce(nextValue.version === "6.4.3", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.3 may not work as expected."));
5832
+ warnOnce(nextValue.version === "7.0.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.0.0 may not work as expected."));
5655
5833
  }
5656
5834
  }
5657
5835
  else if (isMotionValue(prevValue)) {
@@ -6183,7 +6361,7 @@
6183
6361
  value.set(to);
6184
6362
  };
6185
6363
  var isNumOrPxType = function (v) {
6186
- return v === number || v === px;
6364
+ return v === number$1 || v === px;
6187
6365
  };
6188
6366
  var BoundingBoxDimension;
6189
6367
  (function (BoundingBoxDimension) {
@@ -6490,9 +6668,9 @@
6490
6668
  * can be animated by Motion.
6491
6669
  */
6492
6670
  makeTargetAnimatable: function (element, _a, _b, isMounted) {
6671
+ var transition = _a.transition, transitionEnd = _a.transitionEnd, target = __rest(_a, ["transition", "transitionEnd"]);
6493
6672
  var transformValues = _b.transformValues;
6494
6673
  if (isMounted === void 0) { isMounted = true; }
6495
- var transition = _a.transition, transitionEnd = _a.transitionEnd, target = __rest(_a, ["transition", "transitionEnd"]);
6496
6674
  var origin = getOrigin(target, transition || {}, element);
6497
6675
  /**
6498
6676
  * If Framer has provided a function to convert `Color` etc value types, convert them
@@ -6599,11 +6777,11 @@
6599
6777
  return varToken;
6600
6778
  });
6601
6779
  }
6602
- var shadow = complex.parse(latest);
6780
+ var shadow = complex$1.parse(latest);
6603
6781
  // TODO: Doesn't support multiple shadows
6604
6782
  if (shadow.length > 5)
6605
6783
  return original;
6606
- var template = complex.createTransformer(latest);
6784
+ var template = complex$1.createTransformer(latest);
6607
6785
  var offset = typeof shadow[0] !== "number" ? 1 : 0;
6608
6786
  // Calculate the overall context scale
6609
6787
  var xScale = projectionDelta.x.scale * treeScale.x;
@@ -6616,7 +6794,7 @@
6616
6794
  * We could potentially improve the outcome of this by incorporating the ratio between
6617
6795
  * the two scales.
6618
6796
  */
6619
- var averageScale = mix(xScale, yScale, 0.5);
6797
+ var averageScale = mix$1(xScale, yScale, 0.5);
6620
6798
  // Blur
6621
6799
  if (typeof shadow[2 + offset] === "number")
6622
6800
  shadow[2 + offset] /= averageScale;
@@ -6807,14 +6985,14 @@
6807
6985
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
6808
6986
  var _a, _b, _c, _d;
6809
6987
  if (shouldCrossfadeOpacity) {
6810
- target.opacity = mix(0,
6988
+ target.opacity = mix$1(0,
6811
6989
  // (follow?.opacity as number) ?? 0,
6812
6990
  // TODO Reinstate this if only child
6813
6991
  (_a = lead.opacity) !== null && _a !== void 0 ? _a : 1, easeCrossfadeIn(progress));
6814
- target.opacityExit = mix((_b = follow.opacity) !== null && _b !== void 0 ? _b : 1, 0, easeCrossfadeOut(progress));
6992
+ target.opacityExit = mix$1((_b = follow.opacity) !== null && _b !== void 0 ? _b : 1, 0, easeCrossfadeOut(progress));
6815
6993
  }
6816
6994
  else if (isOnlyMember) {
6817
- target.opacity = mix((_c = follow.opacity) !== null && _c !== void 0 ? _c : 1, (_d = lead.opacity) !== null && _d !== void 0 ? _d : 1, progress);
6995
+ target.opacity = mix$1((_c = follow.opacity) !== null && _c !== void 0 ? _c : 1, (_d = lead.opacity) !== null && _d !== void 0 ? _d : 1, progress);
6818
6996
  }
6819
6997
  /**
6820
6998
  * Mix border radius
@@ -6831,8 +7009,8 @@
6831
7009
  leadRadius === 0 ||
6832
7010
  isPx(followRadius) === isPx(leadRadius);
6833
7011
  if (canMix) {
6834
- target[borderLabel] = Math.max(mix(asNumber(followRadius), asNumber(leadRadius), progress), 0);
6835
- if (percent.test(leadRadius) || percent.test(followRadius)) {
7012
+ target[borderLabel] = Math.max(mix$1(asNumber(followRadius), asNumber(leadRadius), progress), 0);
7013
+ if (percent$1.test(leadRadius) || percent$1.test(followRadius)) {
6836
7014
  target[borderLabel] += "%";
6837
7015
  }
6838
7016
  }
@@ -6844,7 +7022,7 @@
6844
7022
  * Mix rotation
6845
7023
  */
6846
7024
  if (follow.rotate || lead.rotate) {
6847
- target.rotate = mix(follow.rotate || 0, lead.rotate || 0, progress);
7025
+ target.rotate = mix$1(follow.rotate || 0, lead.rotate || 0, progress);
6848
7026
  }
6849
7027
  }
6850
7028
  function getRadius(values, radiusName) {
@@ -6883,7 +7061,7 @@
6883
7061
  return 0;
6884
7062
  if (p > max)
6885
7063
  return 1;
6886
- return easing(progress(min, max, p));
7064
+ return easing(progress$1(min, max, p));
6887
7065
  };
6888
7066
  }
6889
7067
 
@@ -6926,14 +7104,14 @@
6926
7104
  if (origin === void 0) { origin = 0.5; }
6927
7105
  if (originAxis === void 0) { originAxis = axis; }
6928
7106
  if (sourceAxis === void 0) { sourceAxis = axis; }
6929
- if (percent.test(translate)) {
7107
+ if (percent$1.test(translate)) {
6930
7108
  translate = parseFloat(translate);
6931
- var relativeProgress = mix(sourceAxis.min, sourceAxis.max, translate / 100);
7109
+ var relativeProgress = mix$1(sourceAxis.min, sourceAxis.max, translate / 100);
6932
7110
  translate = relativeProgress - sourceAxis.min;
6933
7111
  }
6934
7112
  if (typeof translate !== "number")
6935
7113
  return;
6936
- var originPoint = mix(originAxis.min, originAxis.max, origin);
7114
+ var originPoint = mix$1(originAxis.min, originAxis.max, origin);
6937
7115
  if (axis === originAxis)
6938
7116
  originPoint -= translate;
6939
7117
  axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
@@ -7152,9 +7330,9 @@
7152
7330
  var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, checkIsScrollRoot = _a.checkIsScrollRoot, resetTransform = _a.resetTransform;
7153
7331
  return /** @class */ (function () {
7154
7332
  function ProjectionNode(id, latestValues, parent) {
7155
- var _this = this;
7156
7333
  if (latestValues === void 0) { latestValues = {}; }
7157
7334
  if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
7335
+ var _this = this;
7158
7336
  /**
7159
7337
  * A Set containing all this component's children. This is used to iterate
7160
7338
  * through the children.
@@ -8280,14 +8458,14 @@
8280
8458
  stack.removeLeadSnapshot();
8281
8459
  }
8282
8460
  function mixAxisDelta(output, delta, p) {
8283
- output.translate = mix(delta.translate, 0, p);
8284
- output.scale = mix(delta.scale, 1, p);
8461
+ output.translate = mix$1(delta.translate, 0, p);
8462
+ output.scale = mix$1(delta.scale, 1, p);
8285
8463
  output.origin = delta.origin;
8286
8464
  output.originPoint = delta.originPoint;
8287
8465
  }
8288
8466
  function mixAxis(output, from, to, p) {
8289
- output.min = mix(from.min, to.min, p);
8290
- output.max = mix(from.max, to.max, p);
8467
+ output.min = mix$1(from.min, to.min, p);
8468
+ output.max = mix$1(from.max, to.max, p);
8291
8469
  }
8292
8470
  function mixBox(output, from, to, p) {
8293
8471
  mixAxis(output.x, from.x, to.x, p);
@@ -8800,7 +8978,7 @@
8800
8978
  return order;
8801
8979
  var item = order[index];
8802
8980
  var nextLayout = nextItem.layout;
8803
- var nextItemCenter = mix(nextLayout.min, nextLayout.max, 0.5);
8981
+ var nextItemCenter = mix$1(nextLayout.min, nextLayout.max, 0.5);
8804
8982
  if ((nextOffset === 1 && item.layout.max + offset > nextItemCenter) ||
8805
8983
  (nextOffset === -1 && item.layout.min + offset < nextItemCenter)) {
8806
8984
  return moveItem(order, index, index + nextOffset);
@@ -8899,18 +9077,18 @@
8899
9077
  var inputRange = args[1 + argOffset];
8900
9078
  var outputRange = args[2 + argOffset];
8901
9079
  var options = args[3 + argOffset];
8902
- var interpolator = interpolate(inputRange, outputRange, __assign({ mixer: getMixer(outputRange[0]) }, options));
9080
+ var interpolator = interpolate$1(inputRange, outputRange, __assign({ mixer: getMixer(outputRange[0]) }, options));
8903
9081
  return useImmediate ? interpolator(inputValue) : interpolator;
8904
9082
  }
8905
9083
 
8906
9084
  function useOnChange(value, callback) {
8907
- React.useEffect(function () {
9085
+ useIsomorphicLayoutEffect(function () {
8908
9086
  if (isMotionValue(value))
8909
9087
  return value.onChange(callback);
8910
9088
  }, [callback]);
8911
9089
  }
8912
9090
  function useMultiOnChange(values, handler) {
8913
- React.useEffect(function () {
9091
+ useIsomorphicLayoutEffect(function () {
8914
9092
  var subscriptions = values.map(function (value) { return value.onChange(handler); });
8915
9093
  return function () { return subscriptions.forEach(function (unsubscribe) { return unsubscribe(); }); };
8916
9094
  });
@@ -9120,143 +9298,636 @@
9120
9298
  return velocity;
9121
9299
  }
9122
9300
 
9123
- function createScrollMotionValues() {
9124
- return {
9125
- scrollX: motionValue(0),
9126
- scrollY: motionValue(0),
9127
- scrollXProgress: motionValue(0),
9128
- scrollYProgress: motionValue(0),
9129
- };
9130
- }
9131
- function setProgress(offset, maxOffset, value) {
9132
- value.set(!offset || !maxOffset ? 0 : offset / maxOffset);
9133
- }
9134
- function createScrollUpdater(values, getOffsets) {
9135
- var update = function () {
9136
- var _a = getOffsets(), xOffset = _a.xOffset, yOffset = _a.yOffset, xMaxOffset = _a.xMaxOffset, yMaxOffset = _a.yMaxOffset;
9137
- // Set absolute positions
9138
- values.scrollX.set(xOffset);
9139
- values.scrollY.set(yOffset);
9140
- // Set 0-1 progress
9141
- setProgress(xOffset, xMaxOffset, values.scrollXProgress);
9142
- setProgress(yOffset, yMaxOffset, values.scrollYProgress);
9143
- };
9144
- update();
9145
- return update;
9146
- }
9301
+ const clamp = (min, max, v) => Math.min(Math.max(v, min), max);
9147
9302
 
9148
- var getElementScrollOffsets = function (element) { return function () {
9149
- return {
9150
- xOffset: element.scrollLeft,
9151
- yOffset: element.scrollTop,
9152
- xMaxOffset: element.scrollWidth - element.offsetWidth,
9153
- yMaxOffset: element.scrollHeight - element.offsetHeight,
9154
- };
9155
- }; };
9156
- /**
9157
- * Returns MotionValues that update when the provided element scrolls:
9158
- *
9159
- * - `scrollX` — Horizontal scroll distance in pixels.
9160
- * - `scrollY` — Vertical scroll distance in pixels.
9161
- * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
9162
- * - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
9163
- *
9164
- * This element must be set to `overflow: scroll` on either or both axes to report scroll offset.
9165
- *
9166
- * ```jsx
9167
- * export const MyComponent = () => {
9168
- * const ref = useRef()
9169
- * const { scrollYProgress } = useElementScroll(ref)
9170
- *
9171
- * return (
9172
- * <div ref={ref}>
9173
- * <motion.div style={{ scaleX: scrollYProgress }} />
9174
- * </div>
9175
- * )
9176
- * }
9177
- * ```
9178
- *
9179
- * @public
9180
- */
9181
- function useElementScroll(ref) {
9182
- var values = useConstant(createScrollMotionValues);
9183
- useIsomorphicLayoutEffect(function () {
9184
- var element = ref.current;
9185
- invariant(!!element, "ref provided to useScroll must be passed into a HTML element.");
9186
- if (!element)
9187
- return;
9188
- var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
9189
- var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
9190
- var resizeListener = addDomEvent(element, "resize", updateScrollValues);
9191
- return function () {
9192
- scrollListener && scrollListener();
9193
- resizeListener && resizeListener();
9303
+ const isNumber = (value) => typeof value === "number";
9304
+
9305
+ const isEasingList = (easing) => Array.isArray(easing) && !isNumber(easing[0]);
9306
+
9307
+ const wrap = (min, max, v) => {
9308
+ const rangeSize = max - min;
9309
+ return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
9310
+ };
9311
+
9312
+ function getEasingForSegment(easing, i) {
9313
+ return isEasingList(easing)
9314
+ ? easing[wrap(0, easing.length, i)]
9315
+ : easing;
9316
+ }
9317
+
9318
+ const mix = (min, max, progress) => -progress * min + progress * max + min;
9319
+
9320
+ const noopReturn = (v) => v;
9321
+
9322
+ const progress = (min, max, value) => max - min === 0 ? 1 : (value - min) / (max - min);
9323
+
9324
+ function fillOffset(offset, remaining) {
9325
+ const min = offset[offset.length - 1];
9326
+ for (let i = 1; i <= remaining; i++) {
9327
+ const offsetProgress = progress(0, remaining, i);
9328
+ offset.push(mix(min, 1, offsetProgress));
9329
+ }
9330
+ }
9331
+ function defaultOffset$1(length) {
9332
+ const offset = [0];
9333
+ fillOffset(offset, length - 1);
9334
+ return offset;
9335
+ }
9336
+
9337
+ function interpolate(output, input = defaultOffset$1(output.length), easing = noopReturn) {
9338
+ const length = output.length;
9339
+ /**
9340
+ * If the input length is lower than the output we
9341
+ * fill the input to match. This currently assumes the input
9342
+ * is an animation progress value so is a good candidate for
9343
+ * moving outside the function.
9344
+ */
9345
+ const remainder = length - input.length;
9346
+ remainder > 0 && fillOffset(input, remainder);
9347
+ return (t) => {
9348
+ let i = 0;
9349
+ for (; i < length - 2; i++) {
9350
+ if (t < input[i + 1])
9351
+ break;
9352
+ }
9353
+ let progressInRange = clamp(0, 1, progress(input[i], input[i + 1], t));
9354
+ const segmentEasing = getEasingForSegment(easing, i);
9355
+ progressInRange = segmentEasing(progressInRange);
9356
+ return mix(output[i], output[i + 1], progressInRange);
9357
+ };
9358
+ }
9359
+
9360
+ const isFunction = (value) => typeof value === "function";
9361
+
9362
+ const isString = (value) => typeof value === "string";
9363
+
9364
+ /*
9365
+ Convert velocity into velocity per second
9366
+
9367
+ @param [number]: Unit per frame
9368
+ @param [number]: Frame duration in ms
9369
+ */
9370
+ function velocityPerSecond(velocity, frameDuration) {
9371
+ return frameDuration ? velocity * (1000 / frameDuration) : 0;
9372
+ }
9373
+
9374
+ function resolveElements(elements, selectorCache) {
9375
+ var _a;
9376
+ if (typeof elements === "string") {
9377
+ if (selectorCache) {
9378
+ (_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
9379
+ elements = selectorCache[elements];
9380
+ }
9381
+ else {
9382
+ elements = document.querySelectorAll(elements);
9383
+ }
9384
+ }
9385
+ else if (elements instanceof Element) {
9386
+ elements = [elements];
9387
+ }
9388
+ /**
9389
+ * Return an empty array
9390
+ */
9391
+ return Array.from(elements || []);
9392
+ }
9393
+
9394
+ const thresholds = {
9395
+ any: 0,
9396
+ all: 1,
9397
+ };
9398
+ function inView(elementOrSelector, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
9399
+ /**
9400
+ * If this browser doesn't support IntersectionObserver, return a dummy stop function.
9401
+ * Default triggering of onStart is tricky - it could be used for starting/stopping
9402
+ * videos, lazy loading content etc. We could provide an option to enable a fallback, or
9403
+ * provide a fallback callback option.
9404
+ */
9405
+ if (typeof IntersectionObserver === "undefined") {
9406
+ return () => { };
9407
+ }
9408
+ const elements = resolveElements(elementOrSelector);
9409
+ const activeIntersections = new WeakMap();
9410
+ const onIntersectionChange = (entries) => {
9411
+ entries.forEach((entry) => {
9412
+ const onEnd = activeIntersections.get(entry.target);
9413
+ /**
9414
+ * If there's no change to the intersection, we don't need to
9415
+ * do anything here.
9416
+ */
9417
+ if (entry.isIntersecting === Boolean(onEnd))
9418
+ return;
9419
+ if (entry.isIntersecting) {
9420
+ const newOnEnd = onStart(entry);
9421
+ if (isFunction(newOnEnd)) {
9422
+ activeIntersections.set(entry.target, newOnEnd);
9423
+ }
9424
+ else {
9425
+ observer.unobserve(entry.target);
9426
+ }
9427
+ }
9428
+ else if (onEnd) {
9429
+ onEnd(entry);
9430
+ activeIntersections.delete(entry.target);
9431
+ }
9432
+ });
9433
+ };
9434
+ const observer = new IntersectionObserver(onIntersectionChange, {
9435
+ root,
9436
+ rootMargin,
9437
+ threshold: typeof amount === "number" ? amount : thresholds[amount],
9438
+ });
9439
+ elements.forEach((element) => observer.observe(element));
9440
+ return () => observer.disconnect();
9441
+ }
9442
+
9443
+ const resizeHandlers = new WeakMap();
9444
+ let observer;
9445
+ function getElementSize(target, borderBoxSize) {
9446
+ if (borderBoxSize) {
9447
+ const { inlineSize, blockSize } = borderBoxSize[0];
9448
+ return { width: inlineSize, height: blockSize };
9449
+ }
9450
+ else if (target instanceof SVGElement && "getBBox" in target) {
9451
+ return target.getBBox();
9452
+ }
9453
+ else {
9454
+ return {
9455
+ width: target.offsetWidth,
9456
+ height: target.offsetHeight,
9194
9457
  };
9195
- }, []);
9196
- return values;
9458
+ }
9459
+ }
9460
+ function notifyTarget({ target, contentRect, borderBoxSize, }) {
9461
+ var _a;
9462
+ (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
9463
+ handler({
9464
+ target,
9465
+ contentSize: contentRect,
9466
+ get size() {
9467
+ return getElementSize(target, borderBoxSize);
9468
+ },
9469
+ });
9470
+ });
9471
+ }
9472
+ function notifyAll(entries) {
9473
+ entries.forEach(notifyTarget);
9474
+ }
9475
+ function createResizeObserver() {
9476
+ if (typeof ResizeObserver === "undefined")
9477
+ return;
9478
+ observer = new ResizeObserver(notifyAll);
9479
+ }
9480
+ function resizeElement(target, handler) {
9481
+ if (!observer)
9482
+ createResizeObserver();
9483
+ const elements = resolveElements(target);
9484
+ elements.forEach((element) => {
9485
+ let elementHandlers = resizeHandlers.get(element);
9486
+ if (!elementHandlers) {
9487
+ elementHandlers = new Set();
9488
+ resizeHandlers.set(element, elementHandlers);
9489
+ }
9490
+ elementHandlers.add(handler);
9491
+ observer === null || observer === void 0 ? void 0 : observer.observe(element);
9492
+ });
9493
+ return () => {
9494
+ elements.forEach((element) => {
9495
+ const elementHandlers = resizeHandlers.get(element);
9496
+ elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
9497
+ if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
9498
+ observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
9499
+ }
9500
+ });
9501
+ };
9197
9502
  }
9198
9503
 
9199
- var viewportScrollValues;
9200
- function getViewportScrollOffsets() {
9201
- return {
9202
- xOffset: window.pageXOffset,
9203
- yOffset: window.pageYOffset,
9204
- xMaxOffset: document.body.clientWidth - window.innerWidth,
9205
- yMaxOffset: document.body.clientHeight - window.innerHeight,
9504
+ const windowCallbacks = new Set();
9505
+ let windowResizeHandler;
9506
+ function createWindowResizeHandler() {
9507
+ windowResizeHandler = () => {
9508
+ const size = {
9509
+ width: window.innerWidth,
9510
+ height: window.innerHeight,
9511
+ };
9512
+ const info = {
9513
+ target: window,
9514
+ size,
9515
+ contentSize: size,
9516
+ };
9517
+ windowCallbacks.forEach((callback) => callback(info));
9518
+ };
9519
+ window.addEventListener("resize", windowResizeHandler);
9520
+ }
9521
+ function resizeWindow(callback) {
9522
+ windowCallbacks.add(callback);
9523
+ if (!windowResizeHandler)
9524
+ createWindowResizeHandler();
9525
+ return () => {
9526
+ windowCallbacks.delete(callback);
9527
+ if (!windowCallbacks.size && windowResizeHandler) {
9528
+ windowResizeHandler = undefined;
9529
+ }
9206
9530
  };
9207
9531
  }
9208
- var hasListeners = false;
9209
- function addEventListeners() {
9210
- hasListeners = true;
9211
- var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
9212
- addDomEvent(window, "scroll", updateScrollValues);
9213
- addDomEvent(window, "resize", updateScrollValues);
9532
+
9533
+ function resize(a, b) {
9534
+ return isFunction(a) ? resizeWindow(a) : resizeElement(a, b);
9214
9535
  }
9536
+
9215
9537
  /**
9216
- * Returns MotionValues that update when the viewport scrolls:
9217
- *
9218
- * - `scrollX` — Horizontal scroll distance in pixels.
9219
- * - `scrollY` — Vertical scroll distance in pixels.
9220
- * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
9221
- * - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
9222
- *
9223
- * **Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress`
9224
- * values as this breaks the browser's capability to accurately measure the page length.
9225
- *
9226
- * ```jsx
9227
- * export const MyComponent = () => {
9228
- * const { scrollYProgress } = useViewportScroll()
9229
- * return <motion.div style={{ scaleX: scrollYProgress }} />
9230
- * }
9231
- * ```
9232
- *
9233
- * @public
9538
+ * A time in milliseconds, beyond which we consider the scroll velocity to be 0.
9234
9539
  */
9235
- function useViewportScroll() {
9540
+ const maxElapsed = 50;
9541
+ const createAxisInfo = () => ({
9542
+ current: 0,
9543
+ offset: [],
9544
+ progress: 0,
9545
+ scrollLength: 0,
9546
+ targetOffset: 0,
9547
+ targetLength: 0,
9548
+ containerLength: 0,
9549
+ velocity: 0,
9550
+ });
9551
+ const createScrollInfo = () => ({
9552
+ time: 0,
9553
+ x: createAxisInfo(),
9554
+ y: createAxisInfo(),
9555
+ });
9556
+ const keys = {
9557
+ x: {
9558
+ length: "Width",
9559
+ position: "Left",
9560
+ },
9561
+ y: {
9562
+ length: "Height",
9563
+ position: "Top",
9564
+ },
9565
+ };
9566
+ function updateAxisInfo(element, axisName, info, time) {
9567
+ const axis = info[axisName];
9568
+ const { length, position } = keys[axisName];
9569
+ const prev = axis.current;
9570
+ const prevTime = info.time;
9571
+ axis.current = element["scroll" + position];
9572
+ axis.scrollLength = element["scroll" + length] - element["client" + length];
9573
+ axis.offset.length = 0;
9574
+ axis.offset[0] = 0;
9575
+ axis.offset[1] = axis.scrollLength;
9576
+ axis.progress = progress(0, axis.scrollLength, axis.current);
9577
+ const elapsed = time - prevTime;
9578
+ axis.velocity =
9579
+ elapsed > maxElapsed ? 0 : velocityPerSecond(axis.current - prev, elapsed);
9580
+ }
9581
+ function updateScrollInfo(element, info, time) {
9582
+ updateAxisInfo(element, "x", info, time);
9583
+ updateAxisInfo(element, "y", info, time);
9584
+ info.time = time;
9585
+ }
9586
+
9587
+ function calcInset(element, container) {
9588
+ let inset = { x: 0, y: 0 };
9589
+ let current = element;
9590
+ while (current && current !== container) {
9591
+ if (current instanceof HTMLElement) {
9592
+ inset.x += current.offsetLeft;
9593
+ inset.y += current.offsetTop;
9594
+ current = current.offsetParent;
9595
+ }
9596
+ else if (current instanceof SVGGraphicsElement && "getBBox" in current) {
9597
+ const { top, left } = current.getBBox();
9598
+ inset.x += left;
9599
+ inset.y += top;
9600
+ /**
9601
+ * Assign the next parent element as the <svg /> tag.
9602
+ */
9603
+ while (current && current.tagName !== "svg") {
9604
+ current = current.parentNode;
9605
+ }
9606
+ }
9607
+ }
9608
+ return inset;
9609
+ }
9610
+
9611
+ const ScrollOffset = {
9612
+ Enter: [
9613
+ [0, 1],
9614
+ [1, 1],
9615
+ ],
9616
+ Exit: [
9617
+ [0, 0],
9618
+ [1, 0],
9619
+ ],
9620
+ Any: [
9621
+ [1, 0],
9622
+ [0, 1],
9623
+ ],
9624
+ All: [
9625
+ [0, 0],
9626
+ [1, 1],
9627
+ ],
9628
+ };
9629
+
9630
+ const namedEdges = {
9631
+ start: 0,
9632
+ center: 0.5,
9633
+ end: 1,
9634
+ };
9635
+ function resolveEdge(edge, length, inset = 0) {
9636
+ let delta = 0;
9637
+ /**
9638
+ * If we have this edge defined as a preset, replace the definition
9639
+ * with the numerical value.
9640
+ */
9641
+ if (namedEdges[edge] !== undefined) {
9642
+ edge = namedEdges[edge];
9643
+ }
9644
+ /**
9645
+ * Handle unit values
9646
+ */
9647
+ if (isString(edge)) {
9648
+ const asNumber = parseFloat(edge);
9649
+ if (edge.endsWith("px")) {
9650
+ delta = asNumber;
9651
+ }
9652
+ else if (edge.endsWith("%")) {
9653
+ edge = asNumber / 100;
9654
+ }
9655
+ else if (edge.endsWith("vw")) {
9656
+ delta = (asNumber / 100) * document.documentElement.clientWidth;
9657
+ }
9658
+ else if (edge.endsWith("vh")) {
9659
+ delta = (asNumber / 100) * document.documentElement.clientHeight;
9660
+ }
9661
+ else {
9662
+ edge = asNumber;
9663
+ }
9664
+ }
9665
+ /**
9666
+ * If the edge is defined as a number, handle as a progress value.
9667
+ */
9668
+ if (isNumber(edge)) {
9669
+ delta = length * edge;
9670
+ }
9671
+ return inset + delta;
9672
+ }
9673
+
9674
+ const defaultOffset = [0, 0];
9675
+ function resolveOffset(offset, containerLength, targetLength, targetInset) {
9676
+ let offsetDefinition = Array.isArray(offset) ? offset : defaultOffset;
9677
+ let targetPoint = 0;
9678
+ let containerPoint = 0;
9679
+ if (isNumber(offset)) {
9680
+ /**
9681
+ * If we're provided offset: [0, 0.5, 1] then each number x should become
9682
+ * [x, x], so we default to the behaviour of mapping 0 => 0 of both target
9683
+ * and container etc.
9684
+ */
9685
+ offsetDefinition = [offset, offset];
9686
+ }
9687
+ else if (isString(offset)) {
9688
+ offset = offset.trim();
9689
+ if (offset.includes(" ")) {
9690
+ offsetDefinition = offset.split(" ");
9691
+ }
9692
+ else {
9693
+ /**
9694
+ * If we're provided a definition like "100px" then we want to apply
9695
+ * that only to the top of the target point, leaving the container at 0.
9696
+ * Whereas a named offset like "end" should be applied to both.
9697
+ */
9698
+ offsetDefinition = [offset, namedEdges[offset] ? offset : `0`];
9699
+ }
9700
+ }
9701
+ targetPoint = resolveEdge(offsetDefinition[0], targetLength, targetInset);
9702
+ containerPoint = resolveEdge(offsetDefinition[1], containerLength);
9703
+ return targetPoint - containerPoint;
9704
+ }
9705
+
9706
+ const point = { x: 0, y: 0 };
9707
+ function resolveOffsets(container, info, options) {
9708
+ let { offset: offsetDefinition = ScrollOffset.All } = options;
9709
+ const { target = container, axis = "y" } = options;
9710
+ const lengthLabel = axis === "y" ? "height" : "width";
9711
+ const inset = target !== container ? calcInset(target, container) : point;
9712
+ /**
9713
+ * Measure the target and container. If they're the same thing then we
9714
+ * use the container's scrollWidth/Height as the target, from there
9715
+ * all other calculations can remain the same.
9716
+ */
9717
+ const targetSize = target === container
9718
+ ? { width: container.scrollWidth, height: container.scrollHeight }
9719
+ : { width: target.clientWidth, height: target.clientHeight };
9720
+ const containerSize = {
9721
+ width: container.clientWidth,
9722
+ height: container.clientHeight,
9723
+ };
9724
+ /**
9725
+ * Reset the length of the resolved offset array rather than creating a new one.
9726
+ * TODO: More reusable data structures for targetSize/containerSize would also be good.
9727
+ */
9728
+ info[axis].offset.length = 0;
9729
+ /**
9730
+ * Populate the offset array by resolving the user's offset definition into
9731
+ * a list of pixel scroll offets.
9732
+ */
9733
+ let hasChanged = !info[axis].interpolate;
9734
+ const numOffsets = offsetDefinition.length;
9735
+ for (let i = 0; i < numOffsets; i++) {
9736
+ const offset = resolveOffset(offsetDefinition[i], containerSize[lengthLabel], targetSize[lengthLabel], inset[axis]);
9737
+ if (!hasChanged && offset !== info[axis].interpolatorOffsets[i]) {
9738
+ hasChanged = true;
9739
+ }
9740
+ info[axis].offset[i] = offset;
9741
+ }
9742
+ /**
9743
+ * If the pixel scroll offsets have changed, create a new interpolator function
9744
+ * to map scroll value into a progress.
9745
+ */
9746
+ if (hasChanged) {
9747
+ info[axis].interpolate = interpolate(defaultOffset$1(numOffsets), info[axis].offset);
9748
+ info[axis].interpolatorOffsets = [...info[axis].offset];
9749
+ }
9750
+ info[axis].progress = info[axis].interpolate(info[axis].current);
9751
+ }
9752
+
9753
+ function measure(container, target = container, info) {
9754
+ /**
9755
+ * Find inset of target within scrollable container
9756
+ */
9757
+ info.x.targetOffset = 0;
9758
+ info.y.targetOffset = 0;
9759
+ if (target !== container) {
9760
+ let node = target;
9761
+ while (node && node != container) {
9762
+ info.x.targetOffset += node.offsetLeft;
9763
+ info.y.targetOffset += node.offsetTop;
9764
+ node = node.offsetParent;
9765
+ }
9766
+ }
9767
+ info.x.targetLength =
9768
+ target === container ? target.scrollWidth : target.clientWidth;
9769
+ info.y.targetLength =
9770
+ target === container ? target.scrollHeight : target.clientHeight;
9771
+ info.x.containerLength = container.clientWidth;
9772
+ info.y.containerLength = container.clientHeight;
9773
+ }
9774
+ function createOnScrollHandler(element, onScroll, info, options = {}) {
9775
+ const axis = options.axis || "y";
9776
+ return {
9777
+ measure: () => measure(element, options.target, info),
9778
+ update: (time) => {
9779
+ updateScrollInfo(element, info, time);
9780
+ if (options.offset || options.target) {
9781
+ resolveOffsets(element, info, options);
9782
+ }
9783
+ },
9784
+ notify: isFunction(onScroll)
9785
+ ? () => onScroll(info)
9786
+ : scrubAnimation(onScroll, info[axis]),
9787
+ };
9788
+ }
9789
+ function scrubAnimation(controls, axisInfo) {
9790
+ controls.pause();
9791
+ controls.forEachNative((animation, { easing }) => {
9792
+ var _a, _b;
9793
+ if (animation.updateDuration) {
9794
+ if (!easing)
9795
+ animation.easing = noopReturn;
9796
+ animation.updateDuration(1);
9797
+ }
9798
+ else {
9799
+ const timingOptions = { duration: 1000 };
9800
+ if (!easing)
9801
+ timingOptions.easing = "linear";
9802
+ (_b = (_a = animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming) === null || _b === void 0 ? void 0 : _b.call(_a, timingOptions);
9803
+ }
9804
+ });
9805
+ return () => {
9806
+ controls.currentTime = axisInfo.progress;
9807
+ };
9808
+ }
9809
+
9810
+ const scrollListeners = new WeakMap();
9811
+ const resizeListeners = new WeakMap();
9812
+ const onScrollHandlers = new WeakMap();
9813
+ const getEventTarget = (element) => element === document.documentElement ? window : element;
9814
+ function scroll(onScroll, _a = {}) {
9815
+ var { container = document.documentElement } = _a, options = __rest(_a, ["container"]);
9816
+ let containerHandlers = onScrollHandlers.get(container);
9817
+ /**
9818
+ * Get the onScroll handlers for this container.
9819
+ * If one isn't found, create a new one.
9820
+ */
9821
+ if (!containerHandlers) {
9822
+ containerHandlers = new Set();
9823
+ onScrollHandlers.set(container, containerHandlers);
9824
+ }
9236
9825
  /**
9237
- * Lazy-initialise the viewport scroll values
9826
+ * Create a new onScroll handler for the provided callback.
9238
9827
  */
9239
- if (!viewportScrollValues) {
9240
- viewportScrollValues = createScrollMotionValues();
9828
+ const info = createScrollInfo();
9829
+ const containerHandler = createOnScrollHandler(container, onScroll, info, options);
9830
+ containerHandlers.add(containerHandler);
9831
+ /**
9832
+ * Check if there's a scroll event listener for this container.
9833
+ * If not, create one.
9834
+ */
9835
+ if (!scrollListeners.has(container)) {
9836
+ const listener = () => {
9837
+ const time = performance.now();
9838
+ for (const handler of containerHandlers)
9839
+ handler.measure();
9840
+ for (const handler of containerHandlers)
9841
+ handler.update(time);
9842
+ for (const handler of containerHandlers)
9843
+ handler.notify();
9844
+ };
9845
+ scrollListeners.set(container, listener);
9846
+ const target = getEventTarget(container);
9847
+ window.addEventListener("resize", listener, { passive: true });
9848
+ if (container !== document.documentElement) {
9849
+ resizeListeners.set(container, resize(container, listener));
9850
+ }
9851
+ target.addEventListener("scroll", listener, { passive: true });
9241
9852
  }
9853
+ const listener = scrollListeners.get(container);
9854
+ const onLoadProcesss = requestAnimationFrame(listener);
9855
+ return () => {
9856
+ var _a;
9857
+ if (typeof onScroll !== "function")
9858
+ onScroll.stop();
9859
+ cancelAnimationFrame(onLoadProcesss);
9860
+ /**
9861
+ * Check if we even have any handlers for this container.
9862
+ */
9863
+ const containerHandlers = onScrollHandlers.get(container);
9864
+ if (!containerHandlers)
9865
+ return;
9866
+ containerHandlers.delete(containerHandler);
9867
+ if (containerHandlers.size)
9868
+ return;
9869
+ /**
9870
+ * If no more handlers, remove the scroll listener too.
9871
+ */
9872
+ const listener = scrollListeners.get(container);
9873
+ scrollListeners.delete(container);
9874
+ if (listener) {
9875
+ getEventTarget(container).removeEventListener("scroll", listener);
9876
+ (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
9877
+ window.removeEventListener("resize", listener);
9878
+ }
9879
+ };
9880
+ }
9881
+
9882
+ var createScrollMotionValues = function () { return ({
9883
+ scrollX: motionValue(0),
9884
+ scrollY: motionValue(0),
9885
+ scrollXProgress: motionValue(0),
9886
+ scrollYProgress: motionValue(0),
9887
+ }); };
9888
+ function useScroll(_a) {
9889
+ if (_a === void 0) { _a = {}; }
9890
+ var container = _a.container, target = _a.target, options = __rest(_a, ["container", "target"]);
9891
+ var values = useConstant(createScrollMotionValues);
9242
9892
  useIsomorphicLayoutEffect(function () {
9243
- !hasListeners && addEventListeners();
9893
+ return scroll(function (_a) {
9894
+ var x = _a.x, y = _a.y;
9895
+ values.scrollX.set(x.current);
9896
+ values.scrollXProgress.set(x.progress);
9897
+ values.scrollY.set(y.current);
9898
+ values.scrollYProgress.set(y.progress);
9899
+ }, __assign(__assign({}, options), { container: (container === null || container === void 0 ? void 0 : container.current) || undefined, target: (target === null || target === void 0 ? void 0 : target.current) || undefined }));
9244
9900
  }, []);
9245
- return viewportScrollValues;
9901
+ return values;
9902
+ }
9903
+
9904
+ /**
9905
+ * @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
9906
+ */
9907
+ function useElementScroll(ref) {
9908
+ warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
9909
+ return useScroll({ container: ref });
9910
+ }
9911
+
9912
+ /**
9913
+ * @deprecated useViewportScroll is deprecated. Convert to useScroll()
9914
+ */
9915
+ function useViewportScroll() {
9916
+ warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
9917
+ return useScroll();
9246
9918
  }
9247
9919
 
9248
- var getCurrentTime = typeof performance !== "undefined"
9249
- ? function () { return performance.now(); }
9250
- : function () { return Date.now(); };
9251
9920
  function useAnimationFrame(callback) {
9252
- var initialTimestamp = useConstant(getCurrentTime);
9921
+ var initialTimestamp = React.useRef(0);
9253
9922
  var isStatic = React.useContext(MotionConfigContext).isStatic;
9254
9923
  React.useEffect(function () {
9255
9924
  if (isStatic)
9256
9925
  return;
9257
9926
  var provideTimeSinceStart = function (_a) {
9258
9927
  var timestamp = _a.timestamp;
9259
- callback(timestamp - initialTimestamp);
9928
+ if (!initialTimestamp.current)
9929
+ initialTimestamp.current = timestamp;
9930
+ callback(timestamp - initialTimestamp.current);
9260
9931
  };
9261
9932
  sync.update(provideTimeSinceStart, true);
9262
9933
  return function () { return cancelSync.update(provideTimeSinceStart); };
@@ -9414,97 +10085,13 @@
9414
10085
  var runCycle = React.useCallback(function (next) {
9415
10086
  index.current =
9416
10087
  typeof next !== "number"
9417
- ? wrap(0, items.length, index.current + 1)
10088
+ ? wrap$1(0, items.length, index.current + 1)
9418
10089
  : next;
9419
10090
  setItem(items[index.current]);
9420
10091
  }, __spreadArray([items.length], __read(items), false));
9421
10092
  return [item, runCycle];
9422
10093
  }
9423
10094
 
9424
- const noop = () => { };
9425
-
9426
- function resolveElements(elements, selectorCache) {
9427
- var _a;
9428
- if (typeof elements === "string") {
9429
- if (selectorCache) {
9430
- (_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
9431
- elements = selectorCache[elements];
9432
- }
9433
- else {
9434
- elements = document.querySelectorAll(elements);
9435
- }
9436
- }
9437
- else if (elements instanceof Element) {
9438
- elements = [elements];
9439
- }
9440
- /**
9441
- * Return an empty array
9442
- */
9443
- return Array.from(elements || []);
9444
- }
9445
-
9446
- let supportsDocumentRoot;
9447
- function getDefaultRoot() {
9448
- if (supportsDocumentRoot === undefined) {
9449
- try {
9450
- new IntersectionObserver(noop, { root: document });
9451
- supportsDocumentRoot = true;
9452
- }
9453
- catch (e) {
9454
- supportsDocumentRoot = false;
9455
- }
9456
- }
9457
- return supportsDocumentRoot ? document : undefined;
9458
- }
9459
- const thresholds = {
9460
- any: 0,
9461
- all: 1,
9462
- };
9463
- function inView(elements, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
9464
- /**
9465
- * If this browser doesn't support IntersectionObserver, return a dummy stop function.
9466
- * Default triggering of onStart is tricky - it could be used for starting/stopping
9467
- * videos, lazy loading content etc. We could provide an option to enable a fallback, or
9468
- * provide a fallback callback option.
9469
- */
9470
- if (typeof IntersectionObserver === "undefined") {
9471
- return () => { };
9472
- }
9473
- const resolvedElements = resolveElements(elements);
9474
- const activeIntersections = new WeakMap();
9475
- const onIntersectionChange = (entries) => {
9476
- entries.forEach((entry) => {
9477
- const onEnd = activeIntersections.get(entry.target);
9478
- /**
9479
- * If there's no change to the intersection, we don't need to
9480
- * do anything here.
9481
- */
9482
- if (entry.isIntersecting === Boolean(onEnd))
9483
- return;
9484
- if (entry.isIntersecting) {
9485
- const newOnEnd = onStart(entry);
9486
- if (typeof newOnEnd === "function") {
9487
- activeIntersections.set(entry.target, newOnEnd);
9488
- }
9489
- else {
9490
- observer.unobserve(entry.target);
9491
- }
9492
- }
9493
- else if (onEnd) {
9494
- onEnd(entry);
9495
- activeIntersections.delete(entry.target);
9496
- }
9497
- });
9498
- };
9499
- const observer = new IntersectionObserver(onIntersectionChange, {
9500
- root: root || getDefaultRoot(),
9501
- rootMargin,
9502
- threshold: typeof amount === "number" ? amount : thresholds[amount],
9503
- });
9504
- resolvedElements.forEach((element) => observer.observe(element));
9505
- return () => observer.disconnect();
9506
- }
9507
-
9508
10095
  function useInView(ref, _a) {
9509
10096
  var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
9510
10097
  var _d = __read(React.useState(false), 2), isInView = _d[0], setInView = _d[1];
@@ -9811,6 +10398,7 @@
9811
10398
  exports.useReducedMotion = useReducedMotion;
9812
10399
  exports.useReducedMotionConfig = useReducedMotionConfig;
9813
10400
  exports.useResetProjection = useResetProjection;
10401
+ exports.useScroll = useScroll;
9814
10402
  exports.useSpring = useSpring;
9815
10403
  exports.useTime = useTime;
9816
10404
  exports.useTransform = useTransform;