framer-motion 6.4.2 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/index.mjs CHANGED
@@ -15,6 +15,7 @@ export { resolveMotionValue } from './value/utils/resolve-motion-value.mjs';
15
15
  export { useTransform } from './value/use-transform.mjs';
16
16
  export { useSpring } from './value/use-spring.mjs';
17
17
  export { useVelocity } from './value/use-velocity.mjs';
18
+ export { useScroll } from './value/use-scroll.mjs';
18
19
  export { useElementScroll } from './value/scroll/use-element-scroll.mjs';
19
20
  export { useViewportScroll } from './value/scroll/use-viewport-scroll.mjs';
20
21
  export { useTime } from './value/use-time.mjs';
@@ -4,7 +4,7 @@ import React__default, { useContext } from 'react';
4
4
  import { usePresence } from '../../../components/AnimatePresence/use-presence.mjs';
5
5
  import { LayoutGroupContext } from '../../../context/LayoutGroupContext.mjs';
6
6
  import { SwitchLayoutGroupContext } from '../../../context/SwitchLayoutGroupContext.mjs';
7
- import { globalProjectionState } from '../../../projection/node/create-projection-node.mjs';
7
+ import { globalProjectionState } from '../../../projection/node/state.mjs';
8
8
  import { correctBorderRadius } from '../../../projection/styles/scale-border-radius.mjs';
9
9
  import { correctBoxShadow } from '../../../projection/styles/scale-box-shadow.mjs';
10
10
  import { addScaleCorrector } from '../../../projection/styles/scale-correction.mjs';
@@ -19,29 +19,13 @@ import { hasTransform, hasScale } from '../utils/has-transform.mjs';
19
19
  import { transformAxes } from '../../render/html/utils/transform.mjs';
20
20
  import { FlatTree } from '../../render/utils/flat-tree.mjs';
21
21
  import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
22
+ import { globalProjectionState } from './state.mjs';
22
23
 
23
24
  /**
24
25
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
25
26
  * which has a noticeable difference in spring animations
26
27
  */
27
28
  var animationTarget = 1000;
28
- /**
29
- * This should only ever be modified on the client otherwise it'll
30
- * persist through server requests. If we need instanced states we
31
- * could lazy-init via root.
32
- */
33
- var globalProjectionState = {
34
- /**
35
- * Global flag as to whether the tree has animated since the last time
36
- * we resized the window
37
- */
38
- hasAnimatedSinceResize: true,
39
- /**
40
- * We set this to true once, on the first update. Any nodes added to the tree beyond that
41
- * update will be given a `data-projection-id` attribute.
42
- */
43
- hasEverUpdated: false,
44
- };
45
29
  function createProjectionNode(_a) {
46
30
  var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, checkIsScrollRoot = _a.checkIsScrollRoot, resetTransform = _a.resetTransform;
47
31
  return /** @class */ (function () {
@@ -1220,4 +1204,4 @@ function roundBox(box) {
1220
1204
  roundAxis(box.y);
1221
1205
  }
1222
1206
 
1223
- export { createProjectionNode, globalProjectionState, mixAxis, mixAxisDelta, mixBox };
1207
+ export { createProjectionNode, mixAxis, mixAxisDelta, mixBox };
@@ -1,5 +1,5 @@
1
1
  import { useConstant } from '../../utils/use-constant.mjs';
2
- import { globalProjectionState } from './create-projection-node.mjs';
2
+ import { globalProjectionState } from './state.mjs';
3
3
 
4
4
  var id = 1;
5
5
  function useProjectionId() {
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This should only ever be modified on the client otherwise it'll
3
+ * persist through server requests. If we need instanced states we
4
+ * could lazy-init via root.
5
+ */
6
+ var globalProjectionState = {
7
+ /**
8
+ * Global flag as to whether the tree has animated since the last time
9
+ * we resized the window
10
+ */
11
+ hasAnimatedSinceResize: true,
12
+ /**
13
+ * We set this to true once, on the first update. Any nodes added to the tree beyond that
14
+ * update will be given a `data-projection-id` attribute.
15
+ */
16
+ hasEverUpdated: false,
17
+ };
18
+
19
+ export { globalProjectionState };
@@ -18,7 +18,7 @@ function updateMotionValuesFromProps(element, next, prev) {
18
18
  * and warn against mismatches.
19
19
  */
20
20
  if (process.env.NODE_ENV === "development") {
21
- warnOnce(nextValue.version === "6.4.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.2 may not work as expected."));
21
+ warnOnce(nextValue.version === "6.5.1", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.5.1 may not work as expected."));
22
22
  }
23
23
  }
24
24
  else if (isMotionValue(prevValue)) {
@@ -25,7 +25,7 @@ var MotionValue = /** @class */ (function () {
25
25
  * This will be replaced by the build step with the latest version number.
26
26
  * When MotionValues are provided to motion components, warn if versions are mixed.
27
27
  */
28
- this.version = "6.4.2";
28
+ this.version = "6.5.1";
29
29
  /**
30
30
  * Duration, in milliseconds, since last updating frame.
31
31
  *
@@ -1,58 +1,9 @@
1
- import { useConstant } from '../../utils/use-constant.mjs';
2
- import { createScrollUpdater, createScrollMotionValues } from './utils.mjs';
3
- import { addDomEvent } from '../../events/use-dom-event.mjs';
4
- import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
5
- import { invariant } from 'hey-listen';
1
+ import { warnOnce } from '../../utils/warn-once.mjs';
2
+ import { useScroll } from '../use-scroll.mjs';
6
3
 
7
- var getElementScrollOffsets = function (element) { return function () {
8
- return {
9
- xOffset: element.scrollLeft,
10
- yOffset: element.scrollTop,
11
- xMaxOffset: element.scrollWidth - element.offsetWidth,
12
- yMaxOffset: element.scrollHeight - element.offsetHeight,
13
- };
14
- }; };
15
- /**
16
- * Returns MotionValues that update when the provided element scrolls:
17
- *
18
- * - `scrollX` — Horizontal scroll distance in pixels.
19
- * - `scrollY` — Vertical scroll distance in pixels.
20
- * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
21
- * - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
22
- *
23
- * This element must be set to `overflow: scroll` on either or both axes to report scroll offset.
24
- *
25
- * ```jsx
26
- * export const MyComponent = () => {
27
- * const ref = useRef()
28
- * const { scrollYProgress } = useElementScroll(ref)
29
- *
30
- * return (
31
- * <div ref={ref}>
32
- * <motion.div style={{ scaleX: scrollYProgress }} />
33
- * </div>
34
- * )
35
- * }
36
- * ```
37
- *
38
- * @public
39
- */
40
4
  function useElementScroll(ref) {
41
- var values = useConstant(createScrollMotionValues);
42
- useIsomorphicLayoutEffect(function () {
43
- var element = ref.current;
44
- invariant(!!element, "ref provided to useScroll must be passed into a HTML element.");
45
- if (!element)
46
- return;
47
- var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
48
- var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
49
- var resizeListener = addDomEvent(element, "resize", updateScrollValues);
50
- return function () {
51
- scrollListener && scrollListener();
52
- resizeListener && resizeListener();
53
- };
54
- }, []);
55
- return values;
5
+ warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
6
+ return useScroll({ container: ref });
56
7
  }
57
8
 
58
9
  export { useElementScroll };
@@ -1,54 +1,9 @@
1
- import { createScrollMotionValues, createScrollUpdater } from './utils.mjs';
2
- import { addDomEvent } from '../../events/use-dom-event.mjs';
3
- import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
1
+ import { warnOnce } from '../../utils/warn-once.mjs';
2
+ import { useScroll } from '../use-scroll.mjs';
4
3
 
5
- var viewportScrollValues;
6
- function getViewportScrollOffsets() {
7
- return {
8
- xOffset: window.pageXOffset,
9
- yOffset: window.pageYOffset,
10
- xMaxOffset: document.body.clientWidth - window.innerWidth,
11
- yMaxOffset: document.body.clientHeight - window.innerHeight,
12
- };
13
- }
14
- var hasListeners = false;
15
- function addEventListeners() {
16
- hasListeners = true;
17
- var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
18
- addDomEvent(window, "scroll", updateScrollValues);
19
- addDomEvent(window, "resize", updateScrollValues);
20
- }
21
- /**
22
- * Returns MotionValues that update when the viewport scrolls:
23
- *
24
- * - `scrollX` — Horizontal scroll distance in pixels.
25
- * - `scrollY` — Vertical scroll distance in pixels.
26
- * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
27
- * - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
28
- *
29
- * **Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress`
30
- * values as this breaks the browser's capability to accurately measure the page length.
31
- *
32
- * ```jsx
33
- * export const MyComponent = () => {
34
- * const { scrollYProgress } = useViewportScroll()
35
- * return <motion.div style={{ scaleX: scrollYProgress }} />
36
- * }
37
- * ```
38
- *
39
- * @public
40
- */
41
4
  function useViewportScroll() {
42
- /**
43
- * Lazy-initialise the viewport scroll values
44
- */
45
- if (!viewportScrollValues) {
46
- viewportScrollValues = createScrollMotionValues();
47
- }
48
- useIsomorphicLayoutEffect(function () {
49
- !hasListeners && addEventListeners();
50
- }, []);
51
- return viewportScrollValues;
5
+ warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
6
+ return useScroll();
52
7
  }
53
8
 
54
9
  export { useViewportScroll };
@@ -1,14 +1,14 @@
1
- import { useEffect } from 'react';
2
1
  import { isMotionValue } from './utils/is-motion-value.mjs';
2
+ import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
3
3
 
4
4
  function useOnChange(value, callback) {
5
- useEffect(function () {
5
+ useIsomorphicLayoutEffect(function () {
6
6
  if (isMotionValue(value))
7
7
  return value.onChange(callback);
8
8
  }, [callback]);
9
9
  }
10
10
  function useMultiOnChange(values, handler) {
11
- useEffect(function () {
11
+ useIsomorphicLayoutEffect(function () {
12
12
  var subscriptions = values.map(function (value) { return value.onChange(handler); });
13
13
  return function () { return subscriptions.forEach(function (unsubscribe) { return unsubscribe(); }); };
14
14
  });
@@ -0,0 +1,29 @@
1
+ import { __rest, __assign } from 'tslib';
2
+ import { scroll } from '@motionone/dom';
3
+ import { motionValue } from './index.mjs';
4
+ import { useConstant } from '../utils/use-constant.mjs';
5
+ import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
6
+
7
+ var createScrollMotionValues = function () { return ({
8
+ scrollX: motionValue(0),
9
+ scrollY: motionValue(0),
10
+ scrollXProgress: motionValue(0),
11
+ scrollYProgress: motionValue(0),
12
+ }); };
13
+ function useScroll(_a) {
14
+ if (_a === void 0) { _a = {}; }
15
+ var container = _a.container, target = _a.target, options = __rest(_a, ["container", "target"]);
16
+ var values = useConstant(createScrollMotionValues);
17
+ useIsomorphicLayoutEffect(function () {
18
+ return scroll(function (_a) {
19
+ var x = _a.x, y = _a.y;
20
+ values.scrollX.set(x.current);
21
+ values.scrollXProgress.set(x.progress);
22
+ values.scrollY.set(y.current);
23
+ values.scrollYProgress.set(y.progress);
24
+ }, __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 }));
25
+ }, []);
26
+ return values;
27
+ }
28
+
29
+ export { useScroll };