framer-motion 5.5.2 → 5.5.3
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 +6 -25
- package/dist/cjs/three-entry.js +36 -26
- package/dist/cjs/{use-motion-value-28b1fded.js → use-motion-value-3bddc610.js} +21 -0
- package/dist/es/components/three/MotionCanvas.mjs +12 -9
- package/dist/es/components/three/use-layout-camera.mjs +25 -18
- package/package.json +1 -1
- package/types/components/three/MotionCanvasContext.d.ts +2 -2
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-3bddc610.js');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var styleValueTypes = require('style-value-types');
|
|
9
9
|
var popmotion = require('popmotion');
|
|
@@ -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) {
|
|
@@ -3543,7 +3524,7 @@ function startTransition(cb) {
|
|
|
3543
3524
|
}
|
|
3544
3525
|
|
|
3545
3526
|
function useInstantTransition() {
|
|
3546
|
-
var _a = tslib.__read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
|
|
3527
|
+
var _a = tslib.__read(useMotionValue.useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
|
|
3547
3528
|
var startInstantLayoutTransition = useInstantLayoutTransition();
|
|
3548
3529
|
React.useEffect(function () {
|
|
3549
3530
|
/**
|
package/dist/cjs/three-entry.js
CHANGED
|
@@ -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-3bddc610.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 }; }
|
|
@@ -336,26 +336,28 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
336
336
|
*/
|
|
337
337
|
var motionContext = React.useContext(useMotionValue.MotionContext);
|
|
338
338
|
var configContext = React.useContext(useMotionValue.MotionConfigContext);
|
|
339
|
+
var _b = tslib.__read(useMotionValue.useForceUpdate(), 1), forceRender = _b[0];
|
|
339
340
|
var layoutCamera = React.useRef(null);
|
|
340
|
-
var
|
|
341
|
+
var dimensions = React.useRef({
|
|
341
342
|
size: { width: 0, height: 0 },
|
|
342
|
-
})
|
|
343
|
-
var
|
|
343
|
+
});
|
|
344
|
+
var _c = dimensions.current, size = _c.size, dpr = _c.dpr;
|
|
344
345
|
var containerRef = React.useRef(null);
|
|
345
346
|
var handleResize = function () {
|
|
346
347
|
var container = containerRef.current;
|
|
347
|
-
|
|
348
|
+
dimensions.current = {
|
|
348
349
|
size: {
|
|
349
350
|
width: container.offsetWidth,
|
|
350
351
|
height: container.offsetHeight,
|
|
351
352
|
},
|
|
352
|
-
}
|
|
353
|
+
};
|
|
354
|
+
forceRender();
|
|
353
355
|
};
|
|
354
356
|
// Set canvas size on mount
|
|
355
357
|
React.useLayoutEffect(handleResize, []);
|
|
356
358
|
var canvasRef = React__namespace.useRef(null);
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
+
var _d = tslib.__read(React__namespace.useState(false), 2), block = _d[0], setBlock = _d[1];
|
|
360
|
+
var _e = tslib.__read(React__namespace.useState(false), 2), error = _e[0], setError = _e[1];
|
|
359
361
|
// Suspend this component if block is a promise (2nd run)
|
|
360
362
|
if (block)
|
|
361
363
|
throw block;
|
|
@@ -366,7 +368,7 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
366
368
|
if (size.width > 0 && size.height > 0) {
|
|
367
369
|
fiber.render(React__namespace.createElement(ErrorBoundary, { set: setError },
|
|
368
370
|
React__namespace.createElement(React__namespace.Suspense, { fallback: React__namespace.createElement(Block, { set: setBlock }) },
|
|
369
|
-
React__namespace.createElement(MotionCanvasContext.Provider, { value: {
|
|
371
|
+
React__namespace.createElement(MotionCanvasContext.Provider, { value: { dimensions: dimensions, layoutCamera: layoutCamera } },
|
|
370
372
|
React__namespace.createElement(useMotionValue.MotionConfigContext.Provider, { value: configContext },
|
|
371
373
|
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
374
|
}
|
|
@@ -390,15 +392,18 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
390
392
|
var _b = _a.makeDefault, makeDefault = _b === void 0 ? true : _b;
|
|
391
393
|
var context = React.useContext(MotionCanvasContext);
|
|
392
394
|
heyListen.invariant(Boolean(context), "No MotionCanvas detected. Replace Canvas from @react-three/fiber with MotionCanvas from framer-motion.");
|
|
393
|
-
var _c = context,
|
|
395
|
+
var _c = context, dimensions = _c.dimensions, layoutCamera = _c.layoutCamera;
|
|
394
396
|
var advance = fiber.useThree(function (three) { return three.advance; });
|
|
395
397
|
var set = fiber.useThree(function (three) { return three.set; });
|
|
396
398
|
var camera = fiber.useThree(function (three) { return three.camera; });
|
|
397
399
|
var size = fiber.useThree(function (three) { return three.size; });
|
|
398
400
|
var gl = fiber.useThree(function (three) { return three.gl; });
|
|
399
401
|
var parentVisualElement = useMotionValue.useVisualElementContext();
|
|
402
|
+
var measuredLayoutSize = React.useRef();
|
|
400
403
|
React.useLayoutEffect(function () {
|
|
404
|
+
measuredLayoutSize.current = size;
|
|
401
405
|
updateCamera(size);
|
|
406
|
+
advance(performance.now());
|
|
402
407
|
var projection = parentVisualElement === null || parentVisualElement === void 0 ? void 0 : parentVisualElement.projection;
|
|
403
408
|
if (!projection)
|
|
404
409
|
return;
|
|
@@ -406,26 +411,27 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
406
411
|
* When the projection of an element changes we want to update the camera
|
|
407
412
|
* with the projected dimensions.
|
|
408
413
|
*/
|
|
409
|
-
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) {
|
|
410
|
-
updateCamera(calcBoxSize(newProjection));
|
|
411
|
-
advance(sync.getFrameData().timestamp);
|
|
412
|
-
});
|
|
414
|
+
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) { return updateCamera(calcBoxSize(newProjection)); });
|
|
413
415
|
/**
|
|
414
416
|
* When the layout of an element changes we want to update the renderer
|
|
415
417
|
* output to match the layout dimensions.
|
|
416
418
|
*/
|
|
417
419
|
var removeLayoutMeasureListener = projection.addEventListener("measure", function (newLayout) {
|
|
418
420
|
var newSize = calcBoxSize(newLayout);
|
|
419
|
-
|
|
420
|
-
var
|
|
421
|
-
if (newSize.width <
|
|
422
|
-
|
|
423
|
-
var
|
|
424
|
-
var yScale = size.height / newSize.height;
|
|
421
|
+
var dpr = window.devicePixelRatio;
|
|
422
|
+
var _a = dimensions.current.size, width = _a.width, height = _a.height;
|
|
423
|
+
if (newSize.width < width || newSize.height < height) {
|
|
424
|
+
var xScale = width / newSize.width;
|
|
425
|
+
var yScale = height / newSize.height;
|
|
425
426
|
var maxScale = Math.max(xScale, yScale);
|
|
426
427
|
dpr = Math.min(maxScale, 8);
|
|
427
428
|
}
|
|
428
|
-
|
|
429
|
+
dimensions.current = {
|
|
430
|
+
size: { width: newSize.width, height: newSize.height },
|
|
431
|
+
dpr: dpr,
|
|
432
|
+
};
|
|
433
|
+
gl.setSize(newSize.width, newSize.height);
|
|
434
|
+
gl.setPixelRatio(dpr);
|
|
429
435
|
});
|
|
430
436
|
/**
|
|
431
437
|
* When a projection animation completes we want to update the camera to
|
|
@@ -434,9 +440,13 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
434
440
|
var removeAnimationCompleteListener = projection.addEventListener("animationComplete", function () {
|
|
435
441
|
var actual = (projection.layout || {}).actual;
|
|
436
442
|
if (actual) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
443
|
+
setTimeout(function () {
|
|
444
|
+
var newSize = calcBoxSize(actual);
|
|
445
|
+
updateCamera(newSize);
|
|
446
|
+
dimensions.current = { size: newSize };
|
|
447
|
+
gl.setSize(newSize.width, newSize.height);
|
|
448
|
+
gl.setPixelRatio(window.devicePixelRatio);
|
|
449
|
+
}, 50);
|
|
440
450
|
}
|
|
441
451
|
});
|
|
442
452
|
return function () {
|
|
@@ -444,7 +454,7 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
444
454
|
removeLayoutMeasureListener();
|
|
445
455
|
removeAnimationCompleteListener();
|
|
446
456
|
};
|
|
447
|
-
}, [
|
|
457
|
+
}, []);
|
|
448
458
|
React.useLayoutEffect(function () {
|
|
449
459
|
var cam = layoutCamera.current;
|
|
450
460
|
if (makeDefault && cam) {
|
|
@@ -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;
|
|
@@ -1,12 +1,13 @@
|
|
|
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';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* This file contains a version of R3F's Canvas component that uses our projection
|
|
@@ -49,26 +50,28 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
49
50
|
*/
|
|
50
51
|
var motionContext = useContext(MotionContext);
|
|
51
52
|
var configContext = useContext(MotionConfigContext);
|
|
53
|
+
var _b = __read(useForceUpdate(), 1), forceRender = _b[0];
|
|
52
54
|
var layoutCamera = useRef(null);
|
|
53
|
-
var
|
|
55
|
+
var dimensions = useRef({
|
|
54
56
|
size: { width: 0, height: 0 },
|
|
55
|
-
})
|
|
56
|
-
var
|
|
57
|
+
});
|
|
58
|
+
var _c = dimensions.current, size = _c.size, dpr = _c.dpr;
|
|
57
59
|
var containerRef = useRef(null);
|
|
58
60
|
var handleResize = function () {
|
|
59
61
|
var container = containerRef.current;
|
|
60
|
-
|
|
62
|
+
dimensions.current = {
|
|
61
63
|
size: {
|
|
62
64
|
width: container.offsetWidth,
|
|
63
65
|
height: container.offsetHeight,
|
|
64
66
|
},
|
|
65
|
-
}
|
|
67
|
+
};
|
|
68
|
+
forceRender();
|
|
66
69
|
};
|
|
67
70
|
// Set canvas size on mount
|
|
68
71
|
useLayoutEffect(handleResize, []);
|
|
69
72
|
var canvasRef = React.useRef(null);
|
|
70
|
-
var
|
|
71
|
-
var
|
|
73
|
+
var _d = __read(React.useState(false), 2), block = _d[0], setBlock = _d[1];
|
|
74
|
+
var _e = __read(React.useState(false), 2), error = _e[0], setError = _e[1];
|
|
72
75
|
// Suspend this component if block is a promise (2nd run)
|
|
73
76
|
if (block)
|
|
74
77
|
throw block;
|
|
@@ -79,7 +82,7 @@ function CanvasComponent(_a, forwardedRef) {
|
|
|
79
82
|
if (size.width > 0 && size.height > 0) {
|
|
80
83
|
render(React.createElement(ErrorBoundary, { set: setError },
|
|
81
84
|
React.createElement(React.Suspense, { fallback: React.createElement(Block, { set: setBlock }) },
|
|
82
|
-
React.createElement(MotionCanvasContext.Provider, { value: {
|
|
85
|
+
React.createElement(MotionCanvasContext.Provider, { value: { dimensions: dimensions, layoutCamera: layoutCamera } },
|
|
83
86
|
React.createElement(MotionConfigContext.Provider, { value: configContext },
|
|
84
87
|
React.createElement(MotionContext.Provider, { value: motionContext }, children))))), canvasRef.current, __assign(__assign({}, props), { dpr: dpr || props.dpr, size: size, events: events$1 || events }));
|
|
85
88
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
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 { getFrameData } from 'framesync';
|
|
8
7
|
|
|
9
8
|
var calcBoxSize = function (_a) {
|
|
10
9
|
var x = _a.x, y = _a.y;
|
|
@@ -17,15 +16,18 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
17
16
|
var _b = _a.makeDefault, makeDefault = _b === void 0 ? true : _b;
|
|
18
17
|
var context = useContext(MotionCanvasContext);
|
|
19
18
|
invariant(Boolean(context), "No MotionCanvas detected. Replace Canvas from @react-three/fiber with MotionCanvas from framer-motion.");
|
|
20
|
-
var _c = context,
|
|
19
|
+
var _c = context, dimensions = _c.dimensions, layoutCamera = _c.layoutCamera;
|
|
21
20
|
var advance = useThree(function (three) { return three.advance; });
|
|
22
21
|
var set = useThree(function (three) { return three.set; });
|
|
23
22
|
var camera = useThree(function (three) { return three.camera; });
|
|
24
23
|
var size = useThree(function (three) { return three.size; });
|
|
25
24
|
var gl = useThree(function (three) { return three.gl; });
|
|
26
25
|
var parentVisualElement = useVisualElementContext();
|
|
26
|
+
var measuredLayoutSize = useRef();
|
|
27
27
|
useLayoutEffect(function () {
|
|
28
|
+
measuredLayoutSize.current = size;
|
|
28
29
|
updateCamera(size);
|
|
30
|
+
advance(performance.now());
|
|
29
31
|
var projection = parentVisualElement === null || parentVisualElement === void 0 ? void 0 : parentVisualElement.projection;
|
|
30
32
|
if (!projection)
|
|
31
33
|
return;
|
|
@@ -33,26 +35,27 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
33
35
|
* When the projection of an element changes we want to update the camera
|
|
34
36
|
* with the projected dimensions.
|
|
35
37
|
*/
|
|
36
|
-
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) {
|
|
37
|
-
updateCamera(calcBoxSize(newProjection));
|
|
38
|
-
advance(getFrameData().timestamp);
|
|
39
|
-
});
|
|
38
|
+
var removeProjectionUpdateListener = projection.addEventListener("projectionUpdate", function (newProjection) { return updateCamera(calcBoxSize(newProjection)); });
|
|
40
39
|
/**
|
|
41
40
|
* When the layout of an element changes we want to update the renderer
|
|
42
41
|
* output to match the layout dimensions.
|
|
43
42
|
*/
|
|
44
43
|
var removeLayoutMeasureListener = projection.addEventListener("measure", function (newLayout) {
|
|
45
44
|
var newSize = calcBoxSize(newLayout);
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
if (newSize.width <
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
var yScale = size.height / newSize.height;
|
|
45
|
+
var dpr = window.devicePixelRatio;
|
|
46
|
+
var _a = dimensions.current.size, width = _a.width, height = _a.height;
|
|
47
|
+
if (newSize.width < width || newSize.height < height) {
|
|
48
|
+
var xScale = width / newSize.width;
|
|
49
|
+
var yScale = height / newSize.height;
|
|
52
50
|
var maxScale = Math.max(xScale, yScale);
|
|
53
51
|
dpr = Math.min(maxScale, 8);
|
|
54
52
|
}
|
|
55
|
-
|
|
53
|
+
dimensions.current = {
|
|
54
|
+
size: { width: newSize.width, height: newSize.height },
|
|
55
|
+
dpr: dpr,
|
|
56
|
+
};
|
|
57
|
+
gl.setSize(newSize.width, newSize.height);
|
|
58
|
+
gl.setPixelRatio(dpr);
|
|
56
59
|
});
|
|
57
60
|
/**
|
|
58
61
|
* When a projection animation completes we want to update the camera to
|
|
@@ -61,9 +64,13 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
61
64
|
var removeAnimationCompleteListener = projection.addEventListener("animationComplete", function () {
|
|
62
65
|
var actual = (projection.layout || {}).actual;
|
|
63
66
|
if (actual) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
setTimeout(function () {
|
|
68
|
+
var newSize = calcBoxSize(actual);
|
|
69
|
+
updateCamera(newSize);
|
|
70
|
+
dimensions.current = { size: newSize };
|
|
71
|
+
gl.setSize(newSize.width, newSize.height);
|
|
72
|
+
gl.setPixelRatio(window.devicePixelRatio);
|
|
73
|
+
}, 50);
|
|
67
74
|
}
|
|
68
75
|
});
|
|
69
76
|
return function () {
|
|
@@ -71,7 +78,7 @@ function useLayoutCamera(_a, updateCamera) {
|
|
|
71
78
|
removeLayoutMeasureListener();
|
|
72
79
|
removeAnimationCompleteListener();
|
|
73
80
|
};
|
|
74
|
-
}, [
|
|
81
|
+
}, []);
|
|
75
82
|
useLayoutEffect(function () {
|
|
76
83
|
var cam = layoutCamera.current;
|
|
77
84
|
if (makeDefault && cam) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Size } from "@react-three/fiber";
|
|
2
|
-
import { RefObject, Ref } from "react";
|
|
2
|
+
import { MutableRefObject, RefObject, Ref } from "react";
|
|
3
3
|
export declare type DimensionsState = {
|
|
4
4
|
size: Size;
|
|
5
5
|
dpr?: number;
|
|
@@ -8,6 +8,6 @@ export declare type SetLayoutCamera = (ref: Ref<any>) => void;
|
|
|
8
8
|
export declare type SetDimensions = (state: DimensionsState) => void;
|
|
9
9
|
export interface MotionCanvasContextProps {
|
|
10
10
|
layoutCamera: RefObject<any>;
|
|
11
|
-
|
|
11
|
+
dimensions: MutableRefObject<DimensionsState>;
|
|
12
12
|
}
|
|
13
13
|
export declare const MotionCanvasContext: import("react").Context<MotionCanvasContextProps | undefined>;
|