@react-three/drei 9.56.5 → 9.56.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/drei",
3
- "version": "9.56.5",
3
+ "version": "9.56.7",
4
4
  "private": false,
5
5
  "description": "useful add-ons for react-three-fiber",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.11.2",
43
43
  "@react-spring/three": "^9.3.1",
44
- "@use-gesture/react": "^10.2.0",
44
+ "@use-gesture/react": "^10.2.24",
45
45
  "camera-controls": "^2.0.0",
46
46
  "detect-gpu": "^5.0.8",
47
47
  "glsl-noise": "^0.0.0",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),o=require("@react-three/fiber"),n=require("@react-spring/three"),a=require("@use-gesture/react");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=i(e),l=s(t);exports.PresentationControls=function({enabled:e=!0,snap:t,global:i,cursor:s=!0,children:c,speed:f=1,rotation:m=[0,0,0],zoom:d=1,polar:g=[0,Math.PI/2],azimuth:b=[-1/0,1/0],config:p={mass:1,tension:170,friction:26}}){const{size:h,gl:M}=o.useThree(),y=l.useMemo((()=>[m[0]+g[0],m[0]+g[1]]),[m[0],g[0],g[1]]),E=l.useMemo((()=>[m[1]+b[0],m[1]+b[1]]),[m[1],b[0],b[1]]),v=l.useMemo((()=>[r.MathUtils.clamp(m[0],...y),r.MathUtils.clamp(m[1],...E),m[2]]),[m[0],m[1],m[2],y,E]),[j,O]=n.useSpring((()=>({scale:1,rotation:v,config:p})));l.useEffect((()=>{O.start({scale:1,rotation:v,config:p})}),[v]),l.useEffect((()=>(i&&s&&e&&(M.domElement.style.cursor="grab"),()=>{M.domElement.style.cursor="default"})),[i,s,M.domElement,e]);const P=a.useGesture({onHover:({last:t})=>{s&&!i&&e&&(M.domElement.style.cursor=t?"auto":"grab")},onDrag:({down:o,delta:[n,a],memo:[i,u]=j.rotation.animation.to||v})=>{if(!e)return[a,n];s&&(M.domElement.style.cursor=o?"grabbing":"grab"),n=r.MathUtils.clamp(u+n/h.width*Math.PI*f,...E),a=r.MathUtils.clamp(i+a/h.height*Math.PI*f,...y);const l=t&&!o&&"boolean"!=typeof t?t:p;return O.start({scale:o&&a>y[1]/2?d:1,rotation:t&&!o?v:[a,n,0],config:e=>"scale"===e?{...l,friction:3*l.friction}:l}),[a,n]}},{target:i?M.domElement:void 0});return l.createElement(n.a.group,u.default({},null==P?void 0:P(),j),c)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),o=require("@react-three/fiber"),n=require("@react-spring/three"),a=require("@use-gesture/react");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=s(e),c=u(t);exports.PresentationControls=function({enabled:e=!0,snap:t,global:s,domElement:u,cursor:l=!0,children:f,speed:d=1,rotation:m=[0,0,0],zoom:g=1,polar:h=[0,Math.PI/2],azimuth:b=[-1/0,1/0],config:p={mass:1,tension:170,friction:26}}){const y=o.useThree((e=>e.events)),M=o.useThree((e=>e.gl)),v=u||y.connected||M.domElement,{size:E}=o.useThree(),j=c.useMemo((()=>[m[0]+h[0],m[0]+h[1]]),[m[0],h[0],h[1]]),O=c.useMemo((()=>[m[1]+b[0],m[1]+b[1]]),[m[1],b[0],b[1]]),P=c.useMemo((()=>[r.MathUtils.clamp(m[0],...j),r.MathUtils.clamp(m[1],...O),m[2]]),[m[0],m[1],m[2],j,O]),[q,z]=n.useSpring((()=>({scale:1,rotation:P,config:p})));c.useEffect((()=>{z.start({scale:1,rotation:P,config:p})}),[P]),c.useEffect((()=>(s&&l&&e&&(v.style.cursor="grab",M.domElement.style.cursor=""),()=>{v.style.cursor="default",M.domElement.style.cursor="default"})),[s,l,v,e]);const U=a.useGesture({onHover:({last:t})=>{l&&!s&&e&&(v.style.cursor=t?"auto":"grab")},onDrag:({down:o,delta:[n,a],memo:[s,u]=q.rotation.animation.to||P})=>{if(!e)return[a,n];l&&(v.style.cursor=o?"grabbing":"grab"),n=r.MathUtils.clamp(u+n/E.width*Math.PI*d,...O),a=r.MathUtils.clamp(s+a/E.height*Math.PI*d,...j);const i=t&&!o&&"boolean"!=typeof t?t:p;return z.start({scale:o&&a>j[1]/2?g:1,rotation:t&&!o?P:[a,n,0],config:e=>"scale"===e?{...i,friction:3*i.friction}:i}),[a,n]}},{target:s?v:void 0});return c.createElement(n.a.group,i.default({},null==U?void 0:U(),q),f)};
@@ -12,5 +12,6 @@ export declare type PresentationControlProps = {
12
12
  config?: any;
13
13
  enabled?: boolean;
14
14
  children?: React.ReactNode;
15
+ domElement?: HTMLElement;
15
16
  };
16
- export declare function PresentationControls({ enabled, snap, global, cursor, children, speed, rotation, zoom, polar, azimuth, config, }: PresentationControlProps): JSX.Element;
17
+ export declare function PresentationControls({ enabled, snap, global, domElement, cursor, children, speed, rotation, zoom, polar, azimuth, config, }: PresentationControlProps): JSX.Element;
@@ -9,6 +9,7 @@ function PresentationControls({
9
9
  enabled = true,
10
10
  snap,
11
11
  global,
12
+ domElement,
12
13
  cursor = true,
13
14
  children,
14
15
  speed = 1,
@@ -22,9 +23,11 @@ function PresentationControls({
22
23
  friction: 26
23
24
  }
24
25
  }) {
26
+ const events = useThree(state => state.events);
27
+ const gl = useThree(state => state.gl);
28
+ const explDomElement = domElement || events.connected || gl.domElement;
25
29
  const {
26
- size,
27
- gl
30
+ size
28
31
  } = useThree();
29
32
  const rPolar = React.useMemo(() => [rotation[0] + polar[0], rotation[0] + polar[1]], [rotation[0], polar[0], polar[1]]);
30
33
  const rAzimuth = React.useMemo(() => [rotation[1] + azimuth[0], rotation[1] + azimuth[1]], [rotation[1], azimuth[0], azimuth[1]]);
@@ -40,14 +43,21 @@ function PresentationControls({
40
43
  config
41
44
  }), [rInitial]);
42
45
  React.useEffect(() => {
43
- if (global && cursor && enabled) gl.domElement.style.cursor = 'grab';
44
- return () => void (gl.domElement.style.cursor = 'default');
45
- }, [global, cursor, gl.domElement, enabled]);
46
+ if (global && cursor && enabled) {
47
+ explDomElement.style.cursor = 'grab';
48
+ gl.domElement.style.cursor = '';
49
+ }
50
+
51
+ return () => {
52
+ explDomElement.style.cursor = 'default';
53
+ gl.domElement.style.cursor = 'default';
54
+ };
55
+ }, [global, cursor, explDomElement, enabled]);
46
56
  const bind = useGesture({
47
57
  onHover: ({
48
58
  last
49
59
  }) => {
50
- if (cursor && !global && enabled) gl.domElement.style.cursor = last ? 'auto' : 'grab';
60
+ if (cursor && !global && enabled) explDomElement.style.cursor = last ? 'auto' : 'grab';
51
61
  },
52
62
  onDrag: ({
53
63
  down,
@@ -55,7 +65,7 @@ function PresentationControls({
55
65
  memo: [oldY, oldX] = spring.rotation.animation.to || rInitial
56
66
  }) => {
57
67
  if (!enabled) return [y, x];
58
- if (cursor) gl.domElement.style.cursor = down ? 'grabbing' : 'grab';
68
+ if (cursor) explDomElement.style.cursor = down ? 'grabbing' : 'grab';
59
69
  x = MathUtils.clamp(oldX + x / size.width * Math.PI * speed, ...rAzimuth);
60
70
  y = MathUtils.clamp(oldY + y / size.height * Math.PI * speed, ...rPolar);
61
71
  const sConfig = snap && !down && typeof snap !== 'boolean' ? snap : config;
@@ -69,7 +79,7 @@ function PresentationControls({
69
79
  return [y, x];
70
80
  }
71
81
  }, {
72
- target: global ? gl.domElement : undefined
82
+ target: global ? explDomElement : undefined
73
83
  });
74
84
  return /*#__PURE__*/React.createElement(a.group, _extends({}, bind == null ? void 0 : bind(), spring), children);
75
85
  }