@rive-app/react-canvas 3.0.28 → 3.0.30
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/index.js +1 -1
- package/dist/package.json +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@rive-app/canvas");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}var
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@rive-app/canvas");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}var u=function(){function e(){}return e.prototype.observe=function(){},e.prototype.unobserve=function(){},e.prototype.disconnect=function(){},e}();var o=globalThis.ResizeObserver||u,c=void 0!==globalThis.ResizeObserver,s=!c;function f(t){var n=e.useState({width:0,height:0}),r=n[0],i=n[1];e.useEffect(function(){if("undefined"!=typeof window){var e=function(){i({width:window.innerWidth,height:window.innerHeight})};return s&&(e(),window.addEventListener("resize",e)),function(){return window.removeEventListener("resize",e)}}},[]);var a,u,f,l=e.useRef(new o((a=function(e){c&&i({width:e[e.length-1].contentRect.width,height:e[e.length-1].contentRect.height})},u=0,f=0,function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];clearTimeout(f),f=window.setTimeout(function(){return a.apply(e,t)},u)})));return e.useEffect(function(){var e=l.current;return t.current&&c&&e.observe(t.current),function(){e.disconnect(),t.current&&c&&e.unobserve(t.current)}},[t,l]),r}function l(){var e="undefined"!=typeof window&&"number"==typeof window.devicePixelRatio?window.devicePixelRatio:1;return Math.min(Math.max(1,e),3)}function d(e){var t=e.setContainerRef,n=e.setCanvasRef,u=e.className,o=void 0===u?"":u,c=e.style,s=a(e,["setContainerRef","setCanvasRef","className","style"]),f=i({width:"100%",height:"100%"},c);return r.default.createElement("div",i({ref:t,className:o},!o&&{style:f}),r.default.createElement("canvas",i({ref:n,style:{verticalAlign:"top",width:0,height:0}},s)))}var h={useDevicePixelRatio:!0,fitCanvasToArtboardHeight:!1,useOffscreenRenderer:!0};function v(n,a){void 0===a&&(a={});var u=e.useRef(null),o=e.useRef(null),c=e.useState(null),s=c[0],v=c[1],p=e.useState({height:0,width:0}),w=p[0],g=p[1],y=e.useState({height:0,width:0}),b=y[0],m=y[1],R=f(o),O=function(){var t=l(),n=e.useState(t),r=n[0],i=n[1];return e.useEffect(function(){if("undefined"!=typeof window&&"matchMedia"in window){var e=function(){var e=l();i(e)},t=window.matchMedia("screen and (resolution: ".concat(r,"dppx)"));return t.addEventListener("change",e),function(){t.removeEventListener("change",e)}}},[r]),r}(),E=Boolean(n),x=function(e){return Object.assign({},h,e)}(a);function C(){if(o.current){var e=function(){var e,t,n,r,i=null!==(t=null===(e=o.current)||void 0===e?void 0:e.clientWidth)&&void 0!==t?t:0,a=null!==(r=null===(n=o.current)||void 0===n?void 0:n.clientHeight)&&void 0!==r?r:0;if(s&&x.fitCanvasToArtboardHeight){var u=s.bounds;return{width:i,height:i*(u.maxY/u.maxX)}}return{width:i,height:a}}(),t=e.width,n=e.height;if(u.current&&s){var r=t!==w.width||n!==w.height;if(x.fitCanvasToArtboardHeight&&r&&(o.current.style.height=n+"px"),x.useDevicePixelRatio){var i=t*O!==b.width||n*O!==b.height;if(r||i){var a=O*t,c=O*n;u.current.width=a,u.current.height=c,u.current.style.width=t+"px",u.current.style.height=n+"px",m({width:a,height:c})}}else r&&(u.current.width=t,u.current.height=n,m({width:t,height:n}));g({width:t,height:n}),s.startRendering()}s&&s.resizeToCanvas()}}e.useEffect(function(){s&&C()},[s,R,O]);var P=e.useCallback(function(e){if(e&&n&&E){var r=x.useOffscreenRenderer,a=new t.Rive(i(i({useOffscreenRenderer:r},n),{canvas:e}));a.on(t.EventType.Load,function(){u.current?v(a):a.cleanup()})}else null===e&&u.current&&(u.current.height=0,u.current.width=0);u.current=e},[E]),j=e.useCallback(function(e){o.current=e},[]);e.useEffect(function(){var e=new IntersectionObserver(function(e){e[0].isIntersecting?s&&s.startRendering():s&&s.stopRendering()});return u.current&&e.observe(u.current),function(){e.disconnect()}},[s]),e.useEffect(function(){return function(){s&&(s.cleanup(),v(null))}},[s]);var M=null==n?void 0:n.animations;e.useEffect(function(){s&&M&&(s.isPlaying?(s.stop(s.animationNames),s.play(M)):s.isPaused&&(s.stop(s.animationNames),s.pause(M)))},[M,s]);var T=e.useCallback(function(e){return r.default.createElement(d,i({setContainerRef:j,setCanvasRef:P},e))},[]);return{canvas:u.current,setCanvasRef:P,setContainerRef:j,rive:s,RiveComponent:T}}exports.default=function(e){var t=e.src,n=e.artboard,u=e.animations,o=e.stateMachines,c=e.layout,s=e.useOffscreenRenderer,f=void 0===s||s,l=a(e,["src","artboard","animations","stateMachines","layout","useOffscreenRenderer"]),d=v({src:t,artboard:n,animations:u,layout:c,stateMachines:o,autoplay:!0},{useOffscreenRenderer:f}).RiveComponent;return r.default.createElement(d,i({},l))},exports.useRive=v,exports.useStateMachineInput=function(n,r,i,a){var u=e.useState(null),o=u[0],c=u[1];return e.useEffect(function(){function e(){if(n&&r&&i||c(null),n&&r&&i){var e=n.stateMachineInputs(r);if(e){var t=e.find(function(e){return e.name===i});void 0!==a&&t&&(t.value=a),c(t||null)}}else c(null)}e(),n&&n.on(t.EventType.Play,function(){e()})},[n]),o},Object.keys(t).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})});
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rive-app/react-canvas",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.30",
|
|
4
4
|
"description": "React wrapper around the @rive-app/canvas library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/types/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/rive-app/rive-react#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rive-app/canvas": "1.0.
|
|
21
|
+
"@rive-app/canvas": "1.0.91"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rive-app/react-canvas",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.30",
|
|
4
4
|
"description": "React wrapper around the @rive-app/canvas library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/types/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/rive-app/rive-react#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rive-app/canvas": "1.0.
|
|
21
|
+
"@rive-app/canvas": "1.0.91"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|