framer-motion 5.5.2 → 5.5.6-beta.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.
- package/dist/cjs/index.js +33 -27
- package/dist/cjs/{three-entry.js → three.js} +46 -28
- package/dist/cjs/{use-motion-value-28b1fded.js → use-motion-value-3615b5bb.js} +22 -1
- package/dist/es/components/LayoutSVG.mjs +33 -0
- package/dist/es/components/three/MotionCanvas.mjs +23 -9
- package/dist/es/components/three/use-layout-camera.mjs +26 -20
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/index.mjs +1 -1
- package/dist/es/render/svg/utils/render.mjs +2 -2
- package/dist/es/{three-entry.mjs → three.mjs} +0 -0
- package/dist/framer-motion.dev.js +60 -35
- package/dist/framer-motion.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/package.json +8 -8
- package/types/components/LayoutSVG.d.ts +12 -0
- package/types/components/three/MotionCanvasContext.d.ts +3 -2
- package/types/index.d.ts +1 -0
- package/types/render/svg/types.d.ts +1 -1
- package/types/render/svg/utils/render.d.ts +3 -1
- /package/types/{three-entry.d.ts → three.d.ts} +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
-
var useMotionValue = require('./use-motion-value-
|
|
6
|
+
var useMotionValue = require('./use-motion-value-3615b5bb.js');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var styleValueTypes = require('style-value-types');
|
|
9
9
|
var popmotion = require('popmotion');
|
|
@@ -499,8 +499,8 @@ var camelCaseAttributes = new Set([
|
|
|
499
499
|
"pathLength",
|
|
500
500
|
]);
|
|
501
501
|
|
|
502
|
-
function renderSVG(element, renderState) {
|
|
503
|
-
renderHTML(element, renderState);
|
|
502
|
+
function renderSVG(element, renderState, styleProp, projection) {
|
|
503
|
+
renderHTML(element, renderState, styleProp, projection);
|
|
504
504
|
for (var key in renderState.attrs) {
|
|
505
505
|
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
506
506
|
}
|
|
@@ -633,10 +633,6 @@ var isNodeOrChild = function (parent, child) {
|
|
|
633
633
|
}
|
|
634
634
|
};
|
|
635
635
|
|
|
636
|
-
function useUnmountEffect(callback) {
|
|
637
|
-
return React.useEffect(function () { return function () { return callback(); }; }, []);
|
|
638
|
-
}
|
|
639
|
-
|
|
640
636
|
/**
|
|
641
637
|
* @param handlers -
|
|
642
638
|
* @internal
|
|
@@ -688,7 +684,7 @@ function useTapGesture(_a) {
|
|
|
688
684
|
onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
|
|
689
685
|
}
|
|
690
686
|
useMotionValue.usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
|
|
691
|
-
useUnmountEffect(removePointerEndListener);
|
|
687
|
+
useMotionValue.useUnmountEffect(removePointerEndListener);
|
|
692
688
|
}
|
|
693
689
|
|
|
694
690
|
var warned = new Set();
|
|
@@ -1641,7 +1637,7 @@ function usePanGesture(_a) {
|
|
|
1641
1637
|
});
|
|
1642
1638
|
}
|
|
1643
1639
|
useMotionValue.usePointerEvent(visualElement, "pointerdown", hasPanEvents && onPointerDown);
|
|
1644
|
-
useUnmountEffect(function () { return panSession.current && panSession.current.end(); });
|
|
1640
|
+
useMotionValue.useUnmountEffect(function () { return panSession.current && panSession.current.end(); });
|
|
1645
1641
|
}
|
|
1646
1642
|
|
|
1647
1643
|
var drag = {
|
|
@@ -2393,21 +2389,6 @@ function createDomMotionComponent(key) {
|
|
|
2393
2389
|
*/
|
|
2394
2390
|
var m = createMotionProxy(createDomMotionConfig);
|
|
2395
2391
|
|
|
2396
|
-
function useForceUpdate() {
|
|
2397
|
-
var isUnmountingRef = React.useRef(false);
|
|
2398
|
-
var _a = tslib.__read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
|
|
2399
|
-
useUnmountEffect(function () { return (isUnmountingRef.current = true); });
|
|
2400
|
-
var forceRender = React.useCallback(function () {
|
|
2401
|
-
!isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
|
|
2402
|
-
}, [forcedRenderCount]);
|
|
2403
|
-
/**
|
|
2404
|
-
* Defer this to the end of the next animation frame in case there are multiple
|
|
2405
|
-
* synchronous calls.
|
|
2406
|
-
*/
|
|
2407
|
-
var deferredForceRender = React.useCallback(function () { return sync__default["default"].postRender(forceRender); }, [forceRender]);
|
|
2408
|
-
return [deferredForceRender, forcedRenderCount];
|
|
2409
|
-
}
|
|
2410
|
-
|
|
2411
2392
|
var presenceId = 0;
|
|
2412
2393
|
function getPresenceId() {
|
|
2413
2394
|
var id = presenceId;
|
|
@@ -2531,7 +2512,7 @@ var AnimatePresence = function (_a) {
|
|
|
2531
2512
|
var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c;
|
|
2532
2513
|
// We want to force a re-render once all exiting animations have finished. We
|
|
2533
2514
|
// either use a local forceRender function, or one from a parent context if it exists.
|
|
2534
|
-
var _d = tslib.__read(useForceUpdate(), 1), forceRender = _d[0];
|
|
2515
|
+
var _d = tslib.__read(useMotionValue.useForceUpdate(), 1), forceRender = _d[0];
|
|
2535
2516
|
var forceRenderLayoutGroup = React.useContext(useMotionValue.LayoutGroupContext).forceRender;
|
|
2536
2517
|
if (forceRenderLayoutGroup)
|
|
2537
2518
|
forceRender = forceRenderLayoutGroup;
|
|
@@ -2658,7 +2639,7 @@ var LayoutGroup = function (_a) {
|
|
|
2658
2639
|
var children = _a.children, id = _a.id, _d = _a.inheritId, inheritId = _d === void 0 ? true : _d;
|
|
2659
2640
|
var layoutGroupContext = React.useContext(useMotionValue.LayoutGroupContext);
|
|
2660
2641
|
var deprecatedLayoutGroupContext = React.useContext(DeprecatedLayoutGroupContext);
|
|
2661
|
-
var _e = tslib.__read(useForceUpdate(), 2), forceRender = _e[0], key = _e[1];
|
|
2642
|
+
var _e = tslib.__read(useMotionValue.useForceUpdate(), 2), forceRender = _e[0], key = _e[1];
|
|
2662
2643
|
var context = React.useRef(null);
|
|
2663
2644
|
var upstreamId = (_b = layoutGroupContext.id) !== null && _b !== void 0 ? _b : deprecatedLayoutGroupContext;
|
|
2664
2645
|
if (context.current === null) {
|
|
@@ -2787,6 +2768,30 @@ function isLazyBundle(features) {
|
|
|
2787
2768
|
return typeof features === "function";
|
|
2788
2769
|
}
|
|
2789
2770
|
|
|
2771
|
+
function LayoutSVGComponent(_a, ref) {
|
|
2772
|
+
var children = _a.children, props = tslib.__rest(_a, ["children"]);
|
|
2773
|
+
var viewBox = useMotionValue.useMotionValue(props.viewBox);
|
|
2774
|
+
return (React__namespace.createElement(motion.svg, tslib.__assign({ ref: ref }, props, { viewBox: viewBox, layout: true, preserveAspectRatio: "none" }),
|
|
2775
|
+
React__namespace.createElement(ProjectViewBox, { viewBox: viewBox }),
|
|
2776
|
+
children));
|
|
2777
|
+
}
|
|
2778
|
+
function ProjectViewBox(_a) {
|
|
2779
|
+
var viewBox = _a.viewBox;
|
|
2780
|
+
var svgVisualElement = useMotionValue.useVisualElementContext();
|
|
2781
|
+
React.useEffect(function () {
|
|
2782
|
+
var _a;
|
|
2783
|
+
return (_a = svgVisualElement === null || svgVisualElement === void 0 ? void 0 : svgVisualElement.projection) === null || _a === void 0 ? void 0 : _a.addEventListener("projectionUpdate", function (_a) {
|
|
2784
|
+
var x = _a.x, y = _a.y;
|
|
2785
|
+
// TODO: A reveal option could be added where 0 0 is
|
|
2786
|
+
// x.min, y.min
|
|
2787
|
+
// viewBox.set(`0 0 ${calcLength(x)} ${calcLength(y)}`)
|
|
2788
|
+
viewBox.set("".concat(x.min, " ").concat(y.min, " ").concat(useMotionValue.calcLength(x), " ").concat(useMotionValue.calcLength(y)));
|
|
2789
|
+
});
|
|
2790
|
+
}, [svgVisualElement]);
|
|
2791
|
+
return null;
|
|
2792
|
+
}
|
|
2793
|
+
var LayoutSVG = React__namespace.forwardRef(LayoutSVGComponent);
|
|
2794
|
+
|
|
2790
2795
|
var ReorderContext = React.createContext(null);
|
|
2791
2796
|
|
|
2792
2797
|
function checkReorder(order, value, offset, velocity) {
|
|
@@ -3543,7 +3548,7 @@ function startTransition(cb) {
|
|
|
3543
3548
|
}
|
|
3544
3549
|
|
|
3545
3550
|
function useInstantTransition() {
|
|
3546
|
-
var _a = tslib.__read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
|
|
3551
|
+
var _a = tslib.__read(useMotionValue.useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
|
|
3547
3552
|
var startInstantLayoutTransition = useInstantLayoutTransition();
|
|
3548
3553
|
React.useEffect(function () {
|
|
3549
3554
|
/**
|
|
@@ -3693,6 +3698,7 @@ exports.AnimateSharedLayout = AnimateSharedLayout;
|
|
|
3693
3698
|
exports.DeprecatedLayoutGroupContext = DeprecatedLayoutGroupContext;
|
|
3694
3699
|
exports.DragControls = DragControls;
|
|
3695
3700
|
exports.LayoutGroup = LayoutGroup;
|
|
3701
|
+
exports.LayoutSVG = LayoutSVG;
|
|
3696
3702
|
exports.LazyMotion = LazyMotion;
|
|
3697
3703
|
exports.MotionConfig = MotionConfig;
|
|
3698
3704
|
exports.Reorder = Reorder;
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
-
var useMotionValue = require('./use-motion-value-
|
|
6
|
+
var useMotionValue = require('./use-motion-value-3615b5bb.js');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var popmotion = require('popmotion');
|
|
9
9
|
var three = require('three');
|
|
10
10
|
var mergeRefs = require('react-merge-refs');
|
|
11
11
|
var fiber = require('@react-three/fiber');
|
|
12
12
|
var heyListen = require('hey-listen');
|
|
13
|
-
|
|
13
|
+
require('framesync');
|
|
14
14
|
require('style-value-types');
|
|
15
15
|
|
|
16
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -295,6 +295,12 @@ var motion = new Proxy(custom, {
|
|
|
295
295
|
|
|
296
296
|
var MotionCanvasContext = React.createContext(undefined);
|
|
297
297
|
|
|
298
|
+
var devicePixelRatio = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
299
|
+
var calculateDpr = function (dpr) {
|
|
300
|
+
return Array.isArray(dpr)
|
|
301
|
+
? popmotion.clamp(dpr[0], dpr[1], devicePixelRatio)
|
|
302
|
+
: dpr || devicePixelRatio;
|
|
303
|
+
};
|
|
298
304
|
/**
|
|
299
305
|
* This file contains a version of R3F's Canvas component that uses our projection
|
|
300
306
|
* system for layout measurements instead of use-react-measure so we can keep the
|
|
@@ -336,26 +342,28 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
336
342
|
*/
|
|
337
343
|
var motionContext = React.useContext(useMotionValue.MotionContext);
|
|
338
344
|
var configContext = React.useContext(useMotionValue.MotionConfigContext);
|
|
345
|
+
var _b = tslib.__read(useMotionValue.useForceUpdate(), 1), forceRender = _b[0];
|
|
339
346
|
var layoutCamera = React.useRef(null);
|
|
340
|
-
var
|
|
347
|
+
var dimensions = React.useRef({
|
|
341
348
|
size: { width: 0, height: 0 },
|
|
342
|
-
})
|
|
343
|
-
var
|
|
349
|
+
});
|
|
350
|
+
var _c = dimensions.current, size = _c.size, dpr = _c.dpr;
|
|
344
351
|
var containerRef = React.useRef(null);
|
|
345
352
|
var handleResize = function () {
|
|
346
353
|
var container = containerRef.current;
|
|
347
|
-
|
|
354
|
+
dimensions.current = {
|
|
348
355
|
size: {
|
|
349
356
|
width: container.offsetWidth,
|
|
350
357
|
height: container.offsetHeight,
|
|
351
358
|
},
|
|
352
|
-
}
|
|
359
|
+
};
|
|
360
|
+
forceRender();
|
|
353
361
|
};
|
|
354
362
|
// Set canvas size on mount
|
|
355
363
|
React.useLayoutEffect(handleResize, []);
|
|
356
364
|
var canvasRef = React__namespace.useRef(null);
|
|
357
|
-
var
|
|
358
|
-
var
|
|
365
|
+
var _d = tslib.__read(React__namespace.useState(false), 2), block = _d[0], setBlock = _d[1];
|
|
366
|
+
var _e = tslib.__read(React__namespace.useState(false), 2), error = _e[0], setError = _e[1];
|
|
359
367
|
// Suspend this component if block is a promise (2nd run)
|
|
360
368
|
if (block)
|
|
361
369
|
throw block;
|
|
@@ -366,7 +374,11 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
366
374
|
if (size.width > 0 && size.height > 0) {
|
|
367
375
|
fiber.render(React__namespace.createElement(ErrorBoundary, { set: setError },
|
|
368
376
|
React__namespace.createElement(React__namespace.Suspense, { fallback: React__namespace.createElement(Block, { set: setBlock }) },
|
|
369
|
-
React__namespace.createElement(MotionCanvasContext.Provider, { value: {
|
|
377
|
+
React__namespace.createElement(MotionCanvasContext.Provider, { value: {
|
|
378
|
+
dimensions: dimensions,
|
|
379
|
+
layoutCamera: layoutCamera,
|
|
380
|
+
requestedDpr: calculateDpr(props.dpr),
|
|
381
|
+
} },
|
|
370
382
|
React__namespace.createElement(useMotionValue.MotionConfigContext.Provider, { value: configContext },
|
|
371
383
|
React__namespace.createElement(useMotionValue.MotionContext.Provider, { value: motionContext }, children))))), canvasRef.current, tslib.__assign(tslib.__assign({}, props), { dpr: dpr || props.dpr, size: size, events: events || fiber.events }));
|
|
372
384
|
}
|
|
@@ -390,15 +402,18 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
390
402
|
var _b = _a.makeDefault, makeDefault = _b === void 0 ? true : _b;
|
|
391
403
|
var context = React.useContext(MotionCanvasContext);
|
|
392
404
|
heyListen.invariant(Boolean(context), "No MotionCanvas detected. Replace Canvas from @react-three/fiber with MotionCanvas from framer-motion.");
|
|
393
|
-
var _c = context,
|
|
405
|
+
var _c = context, dimensions = _c.dimensions, layoutCamera = _c.layoutCamera, requestedDpr = _c.requestedDpr;
|
|
394
406
|
var advance = fiber.useThree(function (three) { return three.advance; });
|
|
395
407
|
var set = fiber.useThree(function (three) { return three.set; });
|
|
396
408
|
var camera = fiber.useThree(function (three) { return three.camera; });
|
|
397
409
|
var size = fiber.useThree(function (three) { return three.size; });
|
|
398
410
|
var gl = fiber.useThree(function (three) { return three.gl; });
|
|
399
411
|
var parentVisualElement = useMotionValue.useVisualElementContext();
|
|
412
|
+
var measuredLayoutSize = React.useRef();
|
|
400
413
|
React.useLayoutEffect(function () {
|
|
414
|
+
measuredLayoutSize.current = size;
|
|
401
415
|
updateCamera(size);
|
|
416
|
+
advance(performance.now());
|
|
402
417
|
var projection = parentVisualElement === null || parentVisualElement === void 0 ? void 0 : parentVisualElement.projection;
|
|
403
418
|
if (!projection)
|
|
404
419
|
return;
|
|
@@ -406,26 +421,25 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
406
421
|
* When the projection of an element changes we want to update the camera
|
|
407
422
|
* with the projected dimensions.
|
|
408
423
|
*/
|
|
409
|
-
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) {
|
|
410
|
-
updateCamera(calcBoxSize(newProjection));
|
|
411
|
-
advance(sync.getFrameData().timestamp);
|
|
412
|
-
});
|
|
424
|
+
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) { return updateCamera(calcBoxSize(newProjection)); });
|
|
413
425
|
/**
|
|
414
426
|
* When the layout of an element changes we want to update the renderer
|
|
415
427
|
* output to match the layout dimensions.
|
|
416
428
|
*/
|
|
417
429
|
var removeLayoutMeasureListener = projection.addEventListener("measure", function (newLayout) {
|
|
418
430
|
var newSize = calcBoxSize(newLayout);
|
|
431
|
+
var dpr = requestedDpr;
|
|
432
|
+
var _a = dimensions.current.size, width = _a.width, height = _a.height;
|
|
433
|
+
var xScale = width / newSize.width;
|
|
434
|
+
var yScale = height / newSize.height;
|
|
435
|
+
var maxScale = Math.max(xScale, yScale);
|
|
436
|
+
dpr = popmotion.clamp(0.75, 4, maxScale);
|
|
437
|
+
dimensions.current = {
|
|
438
|
+
size: { width: newSize.width, height: newSize.height },
|
|
439
|
+
dpr: dpr,
|
|
440
|
+
};
|
|
419
441
|
gl.setSize(newSize.width, newSize.height);
|
|
420
|
-
|
|
421
|
-
if (newSize.width < size.width ||
|
|
422
|
-
newSize.height < size.height) {
|
|
423
|
-
var xScale = size.width / newSize.width;
|
|
424
|
-
var yScale = size.height / newSize.height;
|
|
425
|
-
var maxScale = Math.max(xScale, yScale);
|
|
426
|
-
dpr = Math.min(maxScale, 8);
|
|
427
|
-
}
|
|
428
|
-
setDimensions({ size: newSize, dpr: dpr });
|
|
442
|
+
gl.setPixelRatio(dpr);
|
|
429
443
|
});
|
|
430
444
|
/**
|
|
431
445
|
* When a projection animation completes we want to update the camera to
|
|
@@ -434,9 +448,13 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
434
448
|
var removeAnimationCompleteListener = projection.addEventListener("animationComplete", function () {
|
|
435
449
|
var actual = (projection.layout || {}).actual;
|
|
436
450
|
if (actual) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
451
|
+
setTimeout(function () {
|
|
452
|
+
var newSize = calcBoxSize(actual);
|
|
453
|
+
updateCamera(newSize);
|
|
454
|
+
dimensions.current = { size: newSize };
|
|
455
|
+
gl.setSize(newSize.width, newSize.height);
|
|
456
|
+
gl.setPixelRatio(requestedDpr);
|
|
457
|
+
}, 50);
|
|
440
458
|
}
|
|
441
459
|
});
|
|
442
460
|
return function () {
|
|
@@ -444,7 +462,7 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
444
462
|
removeLayoutMeasureListener();
|
|
445
463
|
removeAnimationCompleteListener();
|
|
446
464
|
};
|
|
447
|
-
}, [
|
|
465
|
+
}, []);
|
|
448
466
|
React.useLayoutEffect(function () {
|
|
449
467
|
var cam = layoutCamera.current;
|
|
450
468
|
if (makeDefault && cam) {
|
|
@@ -2983,7 +2983,7 @@ function createMotionComponent(_a) {
|
|
|
2983
2983
|
* shared element transitions however. Perhaps for those we could revert to a root node
|
|
2984
2984
|
* that gets forceRendered and layout animations are triggered on its layout effect.
|
|
2985
2985
|
*/
|
|
2986
|
-
var projectionId = useProjectionId();
|
|
2986
|
+
var projectionId = config.isStatic ? undefined : useProjectionId();
|
|
2987
2987
|
/**
|
|
2988
2988
|
*
|
|
2989
2989
|
*/
|
|
@@ -3422,6 +3422,10 @@ function isDragActive() {
|
|
|
3422
3422
|
return false;
|
|
3423
3423
|
}
|
|
3424
3424
|
|
|
3425
|
+
function useUnmountEffect(callback) {
|
|
3426
|
+
return React.useEffect(function () { return function () { return callback(); }; }, []);
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3425
3429
|
var makeRenderlessComponent = function (hook) { return function (props) {
|
|
3426
3430
|
hook(props);
|
|
3427
3431
|
return null;
|
|
@@ -4621,6 +4625,21 @@ var visualElement = function (_a) {
|
|
|
4621
4625
|
var variantProps = tslib.__spreadArray(["initial"], tslib.__read(variantPriorityOrder), false);
|
|
4622
4626
|
var numVariantProps = variantProps.length;
|
|
4623
4627
|
|
|
4628
|
+
function useForceUpdate() {
|
|
4629
|
+
var isUnmountingRef = React.useRef(false);
|
|
4630
|
+
var _a = tslib.__read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
|
|
4631
|
+
useUnmountEffect(function () { return (isUnmountingRef.current = true); });
|
|
4632
|
+
var forceRender = React.useCallback(function () {
|
|
4633
|
+
!isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
|
|
4634
|
+
}, [forcedRenderCount]);
|
|
4635
|
+
/**
|
|
4636
|
+
* Defer this to the end of the next animation frame in case there are multiple
|
|
4637
|
+
* synchronous calls.
|
|
4638
|
+
*/
|
|
4639
|
+
var deferredForceRender = React.useCallback(function () { return sync__default["default"].postRender(forceRender); }, [forceRender]);
|
|
4640
|
+
return [deferredForceRender, forcedRenderCount];
|
|
4641
|
+
}
|
|
4642
|
+
|
|
4624
4643
|
/**
|
|
4625
4644
|
* Creates a `MotionValue` to track the state and velocity of a value.
|
|
4626
4645
|
*
|
|
@@ -4707,11 +4726,13 @@ exports.transformProps = transformProps;
|
|
|
4707
4726
|
exports.translateAxis = translateAxis;
|
|
4708
4727
|
exports.useConstant = useConstant;
|
|
4709
4728
|
exports.useDomEvent = useDomEvent;
|
|
4729
|
+
exports.useForceUpdate = useForceUpdate;
|
|
4710
4730
|
exports.useIsPresent = useIsPresent;
|
|
4711
4731
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
4712
4732
|
exports.useMotionValue = useMotionValue;
|
|
4713
4733
|
exports.usePointerEvent = usePointerEvent;
|
|
4714
4734
|
exports.usePresence = usePresence;
|
|
4735
|
+
exports.useUnmountEffect = useUnmountEffect;
|
|
4715
4736
|
exports.useVisualElementContext = useVisualElementContext;
|
|
4716
4737
|
exports.visualElement = visualElement;
|
|
4717
4738
|
exports.wrapHandler = wrapHandler;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { motion } from '../render/dom/motion.mjs';
|
|
5
|
+
import { useMotionValue } from '../value/use-motion-value.mjs';
|
|
6
|
+
import { useVisualElementContext } from '../context/MotionContext/index.mjs';
|
|
7
|
+
import { calcLength } from '../projection/geometry/delta-calc.mjs';
|
|
8
|
+
|
|
9
|
+
function LayoutSVGComponent(_a, ref) {
|
|
10
|
+
var children = _a.children, props = __rest(_a, ["children"]);
|
|
11
|
+
var viewBox = useMotionValue(props.viewBox);
|
|
12
|
+
return (React.createElement(motion.svg, __assign({ ref: ref }, props, { viewBox: viewBox, layout: true, preserveAspectRatio: "none" }),
|
|
13
|
+
React.createElement(ProjectViewBox, { viewBox: viewBox }),
|
|
14
|
+
children));
|
|
15
|
+
}
|
|
16
|
+
function ProjectViewBox(_a) {
|
|
17
|
+
var viewBox = _a.viewBox;
|
|
18
|
+
var svgVisualElement = useVisualElementContext();
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = svgVisualElement === null || svgVisualElement === void 0 ? void 0 : svgVisualElement.projection) === null || _a === void 0 ? void 0 : _a.addEventListener("projectionUpdate", function (_a) {
|
|
22
|
+
var x = _a.x, y = _a.y;
|
|
23
|
+
// TODO: A reveal option could be added where 0 0 is
|
|
24
|
+
// x.min, y.min
|
|
25
|
+
// viewBox.set(`0 0 ${calcLength(x)} ${calcLength(y)}`)
|
|
26
|
+
viewBox.set("".concat(x.min, " ").concat(y.min, " ").concat(calcLength(x), " ").concat(calcLength(y)));
|
|
27
|
+
});
|
|
28
|
+
}, [svgVisualElement]);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var LayoutSVG = React.forwardRef(LayoutSVGComponent);
|
|
32
|
+
|
|
33
|
+
export { LayoutSVG, LayoutSVGComponent };
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { __extends, __rest, __read, __assign } from 'tslib';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { forwardRef, useContext, useRef,
|
|
3
|
+
import { forwardRef, useContext, useRef, useLayoutEffect } from 'react';
|
|
4
4
|
import { MotionContext } from '../../context/MotionContext/index.mjs';
|
|
5
5
|
import mergeRefs from 'react-merge-refs';
|
|
6
6
|
import { render, events, unmountComponentAtNode } from '@react-three/fiber';
|
|
7
7
|
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
8
8
|
import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
|
|
9
9
|
import { MotionCanvasContext } from './MotionCanvasContext.mjs';
|
|
10
|
+
import { useForceUpdate } from '../../utils/use-force-update.mjs';
|
|
11
|
+
import { clamp } from 'popmotion';
|
|
10
12
|
|
|
13
|
+
var devicePixelRatio = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
14
|
+
var calculateDpr = function (dpr) {
|
|
15
|
+
return Array.isArray(dpr)
|
|
16
|
+
? clamp(dpr[0], dpr[1], devicePixelRatio)
|
|
17
|
+
: dpr || devicePixelRatio;
|
|
18
|
+
};
|
|
11
19
|
/**
|
|
12
20
|
* This file contains a version of R3F's Canvas component that uses our projection
|
|
13
21
|
* system for layout measurements instead of use-react-measure so we can keep the
|
|
@@ -49,26 +57,28 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
49
57
|
*/
|
|
50
58
|
var motionContext = useContext(MotionContext);
|
|
51
59
|
var configContext = useContext(MotionConfigContext);
|
|
60
|
+
var _b = __read(useForceUpdate(), 1), forceRender = _b[0];
|
|
52
61
|
var layoutCamera = useRef(null);
|
|
53
|
-
var
|
|
62
|
+
var dimensions = useRef({
|
|
54
63
|
size: { width: 0, height: 0 },
|
|
55
|
-
})
|
|
56
|
-
var
|
|
64
|
+
});
|
|
65
|
+
var _c = dimensions.current, size = _c.size, dpr = _c.dpr;
|
|
57
66
|
var containerRef = useRef(null);
|
|
58
67
|
var handleResize = function () {
|
|
59
68
|
var container = containerRef.current;
|
|
60
|
-
|
|
69
|
+
dimensions.current = {
|
|
61
70
|
size: {
|
|
62
71
|
width: container.offsetWidth,
|
|
63
72
|
height: container.offsetHeight,
|
|
64
73
|
},
|
|
65
|
-
}
|
|
74
|
+
};
|
|
75
|
+
forceRender();
|
|
66
76
|
};
|
|
67
77
|
// Set canvas size on mount
|
|
68
78
|
useLayoutEffect(handleResize, []);
|
|
69
79
|
var canvasRef = React.useRef(null);
|
|
70
|
-
var
|
|
71
|
-
var
|
|
80
|
+
var _d = __read(React.useState(false), 2), block = _d[0], setBlock = _d[1];
|
|
81
|
+
var _e = __read(React.useState(false), 2), error = _e[0], setError = _e[1];
|
|
72
82
|
// Suspend this component if block is a promise (2nd run)
|
|
73
83
|
if (block)
|
|
74
84
|
throw block;
|
|
@@ -79,7 +89,11 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
79
89
|
if (size.width > 0 && size.height > 0) {
|
|
80
90
|
render(React.createElement(ErrorBoundary, { set: setError },
|
|
81
91
|
React.createElement(React.Suspense, { fallback: React.createElement(Block, { set: setBlock }) },
|
|
82
|
-
React.createElement(MotionCanvasContext.Provider, { value: {
|
|
92
|
+
React.createElement(MotionCanvasContext.Provider, { value: {
|
|
93
|
+
dimensions: dimensions,
|
|
94
|
+
layoutCamera: layoutCamera,
|
|
95
|
+
requestedDpr: calculateDpr(props.dpr),
|
|
96
|
+
} },
|
|
83
97
|
React.createElement(MotionConfigContext.Provider, { value: configContext },
|
|
84
98
|
React.createElement(MotionContext.Provider, { value: motionContext }, children))))), canvasRef.current, __assign(__assign({}, props), { dpr: dpr || props.dpr, size: size, events: events$1 || events }));
|
|
85
99
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useContext, useLayoutEffect } from 'react';
|
|
1
|
+
import { useContext, useRef, useLayoutEffect } from 'react';
|
|
2
2
|
import { useThree } from '@react-three/fiber';
|
|
3
3
|
import { useVisualElementContext } from '../../context/MotionContext/index.mjs';
|
|
4
4
|
import { MotionCanvasContext } from './MotionCanvasContext.mjs';
|
|
5
5
|
import { invariant } from 'hey-listen';
|
|
6
6
|
import { calcLength } from '../../projection/geometry/delta-calc.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { clamp } from 'popmotion';
|
|
8
8
|
|
|
9
9
|
var calcBoxSize = function (_a) {
|
|
10
10
|
var x = _a.x, y = _a.y;
|
|
@@ -17,15 +17,18 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
17
17
|
var _b = _a.makeDefault, makeDefault = _b === void 0 ? true : _b;
|
|
18
18
|
var context = useContext(MotionCanvasContext);
|
|
19
19
|
invariant(Boolean(context), "No MotionCanvas detected. Replace Canvas from @react-three/fiber with MotionCanvas from framer-motion.");
|
|
20
|
-
var _c = context,
|
|
20
|
+
var _c = context, dimensions = _c.dimensions, layoutCamera = _c.layoutCamera, requestedDpr = _c.requestedDpr;
|
|
21
21
|
var advance = useThree(function (three) { return three.advance; });
|
|
22
22
|
var set = useThree(function (three) { return three.set; });
|
|
23
23
|
var camera = useThree(function (three) { return three.camera; });
|
|
24
24
|
var size = useThree(function (three) { return three.size; });
|
|
25
25
|
var gl = useThree(function (three) { return three.gl; });
|
|
26
26
|
var parentVisualElement = useVisualElementContext();
|
|
27
|
+
var measuredLayoutSize = useRef();
|
|
27
28
|
useLayoutEffect(function () {
|
|
29
|
+
measuredLayoutSize.current = size;
|
|
28
30
|
updateCamera(size);
|
|
31
|
+
advance(performance.now());
|
|
29
32
|
var projection = parentVisualElement === null || parentVisualElement === void 0 ? void 0 : parentVisualElement.projection;
|
|
30
33
|
if (!projection)
|
|
31
34
|
return;
|
|
@@ -33,26 +36,25 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
33
36
|
* When the projection of an element changes we want to update the camera
|
|
34
37
|
* with the projected dimensions.
|
|
35
38
|
*/
|
|
36
|
-
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) {
|
|
37
|
-
updateCamera(calcBoxSize(newProjection));
|
|
38
|
-
advance(getFrameData().timestamp);
|
|
39
|
-
});
|
|
39
|
+
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) { return updateCamera(calcBoxSize(newProjection)); });
|
|
40
40
|
/**
|
|
41
41
|
* When the layout of an element changes we want to update the renderer
|
|
42
42
|
* output to match the layout dimensions.
|
|
43
43
|
*/
|
|
44
44
|
var removeLayoutMeasureListener = projection.addEventListener("measure", function (newLayout) {
|
|
45
45
|
var newSize = calcBoxSize(newLayout);
|
|
46
|
+
var dpr = requestedDpr;
|
|
47
|
+
var _a = dimensions.current.size, width = _a.width, height = _a.height;
|
|
48
|
+
var xScale = width / newSize.width;
|
|
49
|
+
var yScale = height / newSize.height;
|
|
50
|
+
var maxScale = Math.max(xScale, yScale);
|
|
51
|
+
dpr = clamp(0.75, 4, maxScale);
|
|
52
|
+
dimensions.current = {
|
|
53
|
+
size: { width: newSize.width, height: newSize.height },
|
|
54
|
+
dpr: dpr,
|
|
55
|
+
};
|
|
46
56
|
gl.setSize(newSize.width, newSize.height);
|
|
47
|
-
|
|
48
|
-
if (newSize.width < size.width ||
|
|
49
|
-
newSize.height < size.height) {
|
|
50
|
-
var xScale = size.width / newSize.width;
|
|
51
|
-
var yScale = size.height / newSize.height;
|
|
52
|
-
var maxScale = Math.max(xScale, yScale);
|
|
53
|
-
dpr = Math.min(maxScale, 8);
|
|
54
|
-
}
|
|
55
|
-
setDimensions({ size: newSize, dpr: dpr });
|
|
57
|
+
gl.setPixelRatio(dpr);
|
|
56
58
|
});
|
|
57
59
|
/**
|
|
58
60
|
* When a projection animation completes we want to update the camera to
|
|
@@ -61,9 +63,13 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
61
63
|
var removeAnimationCompleteListener = projection.addEventListener("animationComplete", function () {
|
|
62
64
|
var actual = (projection.layout || {}).actual;
|
|
63
65
|
if (actual) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
setTimeout(function () {
|
|
67
|
+
var newSize = calcBoxSize(actual);
|
|
68
|
+
updateCamera(newSize);
|
|
69
|
+
dimensions.current = { size: newSize };
|
|
70
|
+
gl.setSize(newSize.width, newSize.height);
|
|
71
|
+
gl.setPixelRatio(requestedDpr);
|
|
72
|
+
}, 50);
|
|
67
73
|
}
|
|
68
74
|
});
|
|
69
75
|
return function () {
|
|
@@ -71,7 +77,7 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
71
77
|
removeLayoutMeasureListener();
|
|
72
78
|
removeAnimationCompleteListener();
|
|
73
79
|
};
|
|
74
|
-
}, [
|
|
80
|
+
}, []);
|
|
75
81
|
useLayoutEffect(function () {
|
|
76
82
|
var cam = layoutCamera.current;
|
|
77
83
|
if (makeDefault && cam) {
|
package/dist/es/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export { AnimateSharedLayout } from './components/AnimateSharedLayout.mjs';
|
|
|
5
5
|
export { MotionConfig } from './components/MotionConfig/index.mjs';
|
|
6
6
|
export { LazyMotion } from './components/LazyMotion/index.mjs';
|
|
7
7
|
export { LayoutGroup } from './components/LayoutGroup/index.mjs';
|
|
8
|
+
export { LayoutSVG } from './components/LayoutSVG.mjs';
|
|
8
9
|
export { Reorder } from './components/Reorder/index.mjs';
|
|
9
10
|
export { domAnimation } from './render/dom/features-animation.mjs';
|
|
10
11
|
export { domMax } from './render/dom/features-max.mjs';
|
package/dist/es/motion/index.mjs
CHANGED
|
@@ -51,7 +51,7 @@ function createMotionComponent(_a) {
|
|
|
51
51
|
* shared element transitions however. Perhaps for those we could revert to a root node
|
|
52
52
|
* that gets forceRendered and layout animations are triggered on its layout effect.
|
|
53
53
|
*/
|
|
54
|
-
var projectionId = useProjectionId();
|
|
54
|
+
var projectionId = config.isStatic ? undefined : useProjectionId();
|
|
55
55
|
/**
|
|
56
56
|
*
|
|
57
57
|
*/
|
|
@@ -2,8 +2,8 @@ import { camelToDash } from '../../dom/utils/camel-to-dash.mjs';
|
|
|
2
2
|
import { renderHTML } from '../../html/utils/render.mjs';
|
|
3
3
|
import { camelCaseAttributes } from './camel-case-attrs.mjs';
|
|
4
4
|
|
|
5
|
-
function renderSVG(element, renderState) {
|
|
6
|
-
renderHTML(element, renderState);
|
|
5
|
+
function renderSVG(element, renderState, styleProp, projection) {
|
|
6
|
+
renderHTML(element, renderState, styleProp, projection);
|
|
7
7
|
for (var key in renderState.attrs) {
|
|
8
8
|
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
9
9
|
}
|
|
File without changes
|