framer-motion 12.7.5-alpha.2 → 12.8.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.
@@ -1348,7 +1348,7 @@
1348
1348
  function mixNumber(a, b) {
1349
1349
  return (p) => mixNumber$1(a, b, p);
1350
1350
  }
1351
- function getMixer$1(a) {
1351
+ function getMixer(a) {
1352
1352
  if (typeof a === "number") {
1353
1353
  return mixNumber;
1354
1354
  }
@@ -1370,7 +1370,7 @@
1370
1370
  function mixArray(a, b) {
1371
1371
  const output = [...a];
1372
1372
  const numValues = output.length;
1373
- const blendValue = a.map((v, i) => getMixer$1(v)(v, b[i]));
1373
+ const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
1374
1374
  return (p) => {
1375
1375
  for (let i = 0; i < numValues; i++) {
1376
1376
  output[i] = blendValue[i](p);
@@ -1383,7 +1383,7 @@
1383
1383
  const blendValue = {};
1384
1384
  for (const key in output) {
1385
1385
  if (a[key] !== undefined && b[key] !== undefined) {
1386
- blendValue[key] = getMixer$1(a[key])(a[key], b[key]);
1386
+ blendValue[key] = getMixer(a[key])(a[key], b[key]);
1387
1387
  }
1388
1388
  }
1389
1389
  return (v) => {
@@ -1433,7 +1433,7 @@
1433
1433
  typeof p === "number") {
1434
1434
  return mixNumber$1(from, to, p);
1435
1435
  }
1436
- const mixer = getMixer$1(from);
1436
+ const mixer = getMixer(from);
1437
1437
  return mixer(from, to);
1438
1438
  }
1439
1439
 
@@ -3541,7 +3541,6 @@
3541
3541
  backgroundPositionY: px,
3542
3542
  ...transformValueTypes,
3543
3543
  zIndex: int,
3544
- size: px,
3545
3544
  // SVG
3546
3545
  fillOpacity: alpha,
3547
3546
  strokeOpacity: alpha,
@@ -3577,7 +3576,7 @@
3577
3576
  let defaultValueType = getDefaultValueType(key);
3578
3577
  if (defaultValueType !== filter)
3579
3578
  defaultValueType = complex;
3580
- // If value is not recognised as animatable, ie "one", create an animatable version origin based on the target
3579
+ // If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
3581
3580
  return defaultValueType.getAnimatableNone
3582
3581
  ? defaultValueType.getAnimatableNone(value)
3583
3582
  : undefined;
@@ -4195,6 +4194,17 @@
4195
4194
  return reportStats;
4196
4195
  }
4197
4196
 
4197
+ function transform(...args) {
4198
+ const useImmediate = !Array.isArray(args[0]);
4199
+ const argOffset = useImmediate ? 0 : -1;
4200
+ const inputValue = args[0 + argOffset];
4201
+ const inputRange = args[1 + argOffset];
4202
+ const outputRange = args[2 + argOffset];
4203
+ const options = args[3 + argOffset];
4204
+ const interpolator = interpolate(inputRange, outputRange, options);
4205
+ return useImmediate ? interpolator(inputValue) : interpolator;
4206
+ }
4207
+
4198
4208
  /**
4199
4209
  * Maximum time between the value of two frames, beyond which we
4200
4210
  * assume the velocity has since been 0.
@@ -4223,7 +4233,7 @@
4223
4233
  * This will be replaced by the build step with the latest version number.
4224
4234
  * When MotionValues are provided to motion components, warn if versions are mixed.
4225
4235
  */
4226
- this.version = "12.7.5-alpha.2";
4236
+ this.version = "12.8.0";
4227
4237
  /**
4228
4238
  * Tracks whether this value can output a velocity. Currently this is only true
4229
4239
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4492,6 +4502,7 @@
4492
4502
  * @public
4493
4503
  */
4494
4504
  destroy() {
4505
+ this.events.destroy?.notify();
4495
4506
  this.clearListeners();
4496
4507
  this.stop();
4497
4508
  if (this.stopPassiveEffect) {
@@ -4503,6 +4514,89 @@
4503
4514
  return new MotionValue(init, options);
4504
4515
  }
4505
4516
 
4517
+ function subscribeValue(inputValues, outputValue, getLatest) {
4518
+ const update = () => outputValue.set(getLatest());
4519
+ const scheduleUpdate = () => frame.preRender(update, false, true);
4520
+ const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
4521
+ outputValue.on("destroy", () => {
4522
+ subscriptions.forEach((unsubscribe) => unsubscribe());
4523
+ cancelFrame(update);
4524
+ });
4525
+ }
4526
+
4527
+ /**
4528
+ * Create a `MotionValue` that transforms the output of other `MotionValue`s by
4529
+ * passing their latest values through a transform function.
4530
+ *
4531
+ * Whenever a `MotionValue` referred to in the provided function is updated,
4532
+ * it will be re-evaluated.
4533
+ *
4534
+ * ```jsx
4535
+ * const x = motionValue(0)
4536
+ * const y = transformValue(() => x.get() * 2) // double x
4537
+ * ```
4538
+ *
4539
+ * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
4540
+ * @returns `MotionValue`
4541
+ *
4542
+ * @public
4543
+ */
4544
+ function transformValue(transform) {
4545
+ const collectedValues = [];
4546
+ /**
4547
+ * Open session of collectMotionValues. Any MotionValue that calls get()
4548
+ * inside transform will be saved into this array.
4549
+ */
4550
+ collectMotionValues.current = collectedValues;
4551
+ const initialValue = transform();
4552
+ collectMotionValues.current = undefined;
4553
+ const value = motionValue(initialValue);
4554
+ subscribeValue(collectedValues, value, transform);
4555
+ return value;
4556
+ }
4557
+
4558
+ /**
4559
+ * Create a `MotionValue` that maps the output of another `MotionValue` by
4560
+ * mapping it from one range of values into another.
4561
+ *
4562
+ * @remarks
4563
+ *
4564
+ * Given an input range of `[-200, -100, 100, 200]` and an output range of
4565
+ * `[0, 1, 1, 0]`, the returned `MotionValue` will:
4566
+ *
4567
+ * - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
4568
+ * - When provided a value between `-100` and `100`, will return `1`.
4569
+ * - When provided a value between `100` and `200`, will return a value between `1` and `0`
4570
+ *
4571
+ * The input range must be a linear series of numbers. The output range
4572
+ * can be any value type supported by Motion: numbers, colors, shadows, etc.
4573
+ *
4574
+ * Every value in the output range must be of the same type and in the same format.
4575
+ *
4576
+ * ```jsx
4577
+ * const x = motionValue(0)
4578
+ * const xRange = [-200, -100, 100, 200]
4579
+ * const opacityRange = [0, 1, 1, 0]
4580
+ * const opacity = mapValue(x, xRange, opacityRange)
4581
+ * ```
4582
+ *
4583
+ * @param inputValue - `MotionValue`
4584
+ * @param inputRange - A linear series of numbers (either all increasing or decreasing)
4585
+ * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
4586
+ * @param options -
4587
+ *
4588
+ * - clamp: boolean. Clamp values to within the given range. Defaults to `true`
4589
+ * - ease: EasingFunction[]. Easing functions to use on the interpolations between each value in the input and output ranges. If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition between each.
4590
+ *
4591
+ * @returns `MotionValue`
4592
+ *
4593
+ * @public
4594
+ */
4595
+ function mapValue(inputValue, inputRange, outputRange, options) {
4596
+ const map = transform(inputRange, outputRange, options);
4597
+ return transformValue(() => map(inputValue.get()));
4598
+ }
4599
+
4506
4600
  /**
4507
4601
  * A list of all ValueTypes
4508
4602
  */
@@ -5128,28 +5222,13 @@
5128
5222
  return () => cancelFrame(checkElapsed);
5129
5223
  }
5130
5224
 
5131
- const isKeyframesTarget = (v) => {
5132
- return Array.isArray(v);
5133
- };
5134
-
5135
- const isCustomValue = (v) => {
5136
- return Boolean(v && typeof v === "object" && v.mix && v.toValue);
5137
- };
5138
- const resolveFinalValueInKeyframes = (v) => {
5139
- // TODO maybe throw if v.length - 1 is placeholder token?
5140
- return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
5141
- };
5142
-
5143
5225
  /**
5144
5226
  * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
5145
5227
  *
5146
5228
  * TODO: Remove and move to library
5147
5229
  */
5148
5230
  function resolveMotionValue(value) {
5149
- const unwrappedValue = isMotionValue(value) ? value.get() : value;
5150
- return isCustomValue(unwrappedValue)
5151
- ? unwrappedValue.toValue()
5152
- : unwrappedValue;
5231
+ return isMotionValue(value) ? value.get() : value;
5153
5232
  }
5154
5233
 
5155
5234
  const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
@@ -7499,7 +7578,7 @@
7499
7578
  * and warn against mismatches.
7500
7579
  */
7501
7580
  {
7502
- warnOnce(nextValue.version === "12.7.5-alpha.2", `Attempting to mix Motion versions ${nextValue.version} with 12.7.5-alpha.2 may not work as expected.`);
7581
+ warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
7503
7582
  }
7504
7583
  }
7505
7584
  else if (isMotionValue(prevValue)) {
@@ -8559,6 +8638,10 @@
8559
8638
  return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
8560
8639
  }
8561
8640
 
8641
+ const isKeyframesTarget = (v) => {
8642
+ return Array.isArray(v);
8643
+ };
8644
+
8562
8645
  /**
8563
8646
  * Set VisualElement's MotionValue, creating a new MotionValue for it if
8564
8647
  * it doesn't exist.
@@ -8571,6 +8654,10 @@
8571
8654
  visualElement.addValue(key, motionValue(value));
8572
8655
  }
8573
8656
  }
8657
+ function resolveFinalValueInKeyframes(v) {
8658
+ // TODO maybe throw if v.length - 1 is placeholder token?
8659
+ return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
8660
+ }
8574
8661
  function setTarget(visualElement, definition) {
8575
8662
  const resolved = resolveVariant(visualElement, definition);
8576
8663
  let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
@@ -11280,24 +11367,6 @@
11280
11367
  return value;
11281
11368
  }
11282
11369
 
11283
- const isCustomValueType = (v) => {
11284
- return v && typeof v === "object" && v.mix;
11285
- };
11286
- const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
11287
- function transform(...args) {
11288
- const useImmediate = !Array.isArray(args[0]);
11289
- const argOffset = useImmediate ? 0 : -1;
11290
- const inputValue = args[0 + argOffset];
11291
- const inputRange = args[1 + argOffset];
11292
- const outputRange = args[2 + argOffset];
11293
- const options = args[3 + argOffset];
11294
- const interpolator = interpolate(inputRange, outputRange, {
11295
- mixer: getMixer(outputRange[0]),
11296
- ...options,
11297
- });
11298
- return useImmediate ? interpolator(inputValue) : interpolator;
11299
- }
11300
-
11301
11370
  function useCombineMotionValues(values, combineValues) {
11302
11371
  /**
11303
11372
  * Initialise the returned motion value. This remains the same between renders.
@@ -13708,7 +13777,7 @@
13708
13777
  exports.getComputedStyle = getComputedStyle$2;
13709
13778
  exports.getDefaultValueType = getDefaultValueType;
13710
13779
  exports.getEasingForSegment = getEasingForSegment;
13711
- exports.getMixer = getMixer$1;
13780
+ exports.getMixer = getMixer;
13712
13781
  exports.getValueAsType = getValueAsType;
13713
13782
  exports.getValueTransition = getValueTransition$1;
13714
13783
  exports.getVariableValue = getVariableValue;
@@ -13741,6 +13810,7 @@
13741
13810
  exports.m = m;
13742
13811
  exports.makeUseVisualState = makeUseVisualState;
13743
13812
  exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
13813
+ exports.mapValue = mapValue;
13744
13814
  exports.maxGeneratorDuration = maxGeneratorDuration;
13745
13815
  exports.memo = memo;
13746
13816
  exports.microtask = microtask;
@@ -13804,6 +13874,7 @@
13804
13874
  exports.transform = transform;
13805
13875
  exports.transformPropOrder = transformPropOrder;
13806
13876
  exports.transformProps = transformProps;
13877
+ exports.transformValue = transformValue;
13807
13878
  exports.transformValueTypes = transformValueTypes;
13808
13879
  exports.unwrapMotionComponent = unwrapMotionComponent;
13809
13880
  exports.useAnimate = useAnimate;