New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rive-react

Package Overview
Dependencies
Maintainers
4
Versions
209
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rive-react - npm Package Compare versions

Comparing version 0.2.0-alpha.5 to 1.0.0

2

dist/index.js

@@ -1,1 +0,1 @@

Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@rive-app/webgl");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}function u(e){var t=e.setContainerRef,n=e.setCanvasRef,u=a(e,["setContainerRef","setCanvasRef"]);return r.default.createElement("div",i({ref:t,style:"className"in u?void 0:{width:"100%",height:"100%"}},u),r.default.createElement("canvas",{ref:n,style:{verticalAlign:"top"}}))}var o={useDevicePixelRatio:!0,fitCanvasToArtboardHeight:!1};function c(n,a){void 0===a&&(a={});var c=e.useRef(null),s=e.useRef(null),f=e.useState(null),l=f[0],d=f[1],h=e.useState({height:0,width:0}),v=h[0],p=h[1],w=function(){var t=e.useState({width:0,height:0}),n=t[0],r=t[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){r({width:window.innerWidth,height:window.innerHeight})};return window.addEventListener("resize",e),e(),function(){return window.removeEventListener("resize",e)}}},[]),n}(),g=Boolean(n),b=function(e){return Object.assign({},o,e)}(a);function y(){if(s.current){var e=function(){var e,t,n=null!==(t=null===(e=s.current)||void 0===e?void 0:e.getBoundingClientRect())&&void 0!==t?t:new DOMRect(0,0,0,0),r=n.width,i=n.height;if(l&&b.fitCanvasToArtboardHeight){var a=l.bounds;return{width:r,height:r*(a.maxY/a.maxX)}}return{width:r,height:i}}(),t=e.width,n=e.height,r=t!==v.width||n!==v.height;if(c.current&&l&&r){if(b.fitCanvasToArtboardHeight&&(s.current.style.height=n+"px"),b.useDevicePixelRatio){var i=window.devicePixelRatio||1;c.current.width=i*t,c.current.height=i*n,c.current.style.width=t+"px",c.current.style.height=n+"px"}else c.current.width=t,c.current.height=n;p({width:t,height:n}),l.startRendering()}l&&l.resizeToCanvas()}}e.useEffect(function(){l&&y()},[l,w]);var R=e.useCallback(function(e){if(e&&n){var r=new t.Rive(i(i({},n),{canvas:e}));r.on(t.EventType.Load,function(){return d(r)})}else null===e&&c.current&&(c.current.height=0,c.current.width=0);c.current=e},[g]),O=e.useCallback(function(e){s.current=e},[]);e.useEffect(function(){var e=new IntersectionObserver(function(e){e[0].isIntersecting?l&&l.startRendering():l&&l.stopRendering()});return c.current&&e.observe(c.current),function(){e.disconnect()}},[l]),e.useEffect(function(){return function(){l&&(l.stop(),d(null))}},[l]);var m=e.useCallback(function(e){return r.default.createElement(u,i({setContainerRef:O,setCanvasRef:R},e))},[]);return{canvas:c.current,setCanvasRef:R,setContainerRef:O,rive:l,RiveComponent:m}}exports.default=function(e){var t=e.src,n=e.artboard,u=e.animations,o=e.layout,s=a(e,["src","artboard","animations","layout"]),f=c({src:t,artboard:n,animations:u,layout:o,autoplay:!0}).RiveComponent;return r.default.createElement(f,i({},s))},exports.useRive=c,exports.useStateMachineInput=function(t,n,r){var i=e.useState(null),a=i[0],u=i[1];return e.useEffect(function(){if(t&&n&&r||u(null),t&&n&&r){var e=t.stateMachineInputs(n);if(e){var i=e.find(function(e){return e.name===r});u(i||null)}}else u(null)},[t]),a},Object.keys(t).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})});
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@rive-app/webgl");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 u(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}function a(e){var t=e.setContainerRef,n=e.setCanvasRef,a=u(e,["setContainerRef","setCanvasRef"]);return r.default.createElement("div",i({ref:t,style:"className"in a?void 0:{width:"100%",height:"100%"}},a),r.default.createElement("canvas",{ref:n,style:{verticalAlign:"top"}}))}var o={useDevicePixelRatio:!0,fitCanvasToArtboardHeight:!1,useOffscreenRenderer:!0};function s(n,u){void 0===u&&(u={});var s=e.useRef(null),c=e.useRef(null),f=e.useState(null),l=f[0],d=f[1],v=e.useState({height:0,width:0}),h=v[0],p=v[1],w=function(){var t=e.useState({width:0,height:0}),n=t[0],r=t[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){r({width:window.innerWidth,height:window.innerHeight})};return window.addEventListener("resize",e),e(),function(){return window.removeEventListener("resize",e)}}},[]),n}(),g=Boolean(n),b=function(e){return Object.assign({},o,e)}(u);function y(){if(c.current){var e=function(){var e,t,n=null!==(t=null===(e=c.current)||void 0===e?void 0:e.getBoundingClientRect())&&void 0!==t?t:new DOMRect(0,0,0,0),r=n.width,i=n.height;if(l&&b.fitCanvasToArtboardHeight){var u=l.bounds;return{width:r,height:r*(u.maxY/u.maxX)}}return{width:r,height:i}}(),t=e.width,n=e.height,r=t!==h.width||n!==h.height;if(s.current&&l&&r){if(b.fitCanvasToArtboardHeight&&(c.current.style.height=n+"px"),b.useDevicePixelRatio){var i=window.devicePixelRatio||1;s.current.width=i*t,s.current.height=i*n,s.current.style.width=t+"px",s.current.style.height=n+"px"}else s.current.width=t,s.current.height=n;p({width:t,height:n}),l.startRendering()}l&&l.resizeToCanvas()}}e.useEffect(function(){l&&y()},[l,w]);var R=e.useCallback(function(e){if(e&&n){var r=b.useOffscreenRenderer,u=new t.Rive(i(i({useOffscreenRenderer:r},n),{canvas:e}));u.on(t.EventType.Load,function(){return d(u)})}else null===e&&s.current&&(s.current.height=0,s.current.width=0);s.current=e},[g]),O=e.useCallback(function(e){c.current=e},[]);e.useEffect(function(){var e=new IntersectionObserver(function(e){e[0].isIntersecting?l&&l.startRendering():l&&l.stopRendering()});return s.current&&e.observe(s.current),function(){e.disconnect()}},[l]),e.useEffect(function(){return function(){l&&(l.stop(),d(null))}},[l]);var m=e.useCallback(function(e){return r.default.createElement(a,i({setContainerRef:O,setCanvasRef:R},e))},[]);return{canvas:s.current,setCanvasRef:R,setContainerRef:O,rive:l,RiveComponent:m}}exports.default=function(e){var t=e.src,n=e.artboard,a=e.animations,o=e.layout,c=e.useOffscreenRenderer,f=void 0===c||c,l=u(e,["src","artboard","animations","layout","useOffscreenRenderer"]),d=s({src:t,artboard:n,animations:a,layout:o,autoplay:!0},{useOffscreenRenderer:f}).RiveComponent;return r.default.createElement(d,i({},l))},exports.useRive=s,exports.useStateMachineInput=function(t,n,r){var i=e.useState(null),u=i[0],a=i[1];return e.useEffect(function(){if(t&&n&&r||a(null),t&&n&&r){var e=t.stateMachineInputs(n);if(e){var i=e.find(function(e){return e.name===r});a(i||null)}}else a(null)},[t]),u},Object.keys(t).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})});

@@ -8,4 +8,5 @@ import { Layout } from '@rive-app/webgl';

layout?: Layout;
useOffscreenRenderer?: boolean;
};
declare const Rive: ({ src, artboard, animations, layout, ...rest }: RiveProps & ComponentProps<'div'>) => JSX.Element;
declare const Rive: ({ src, artboard, animations, layout, useOffscreenRenderer, ...rest }: RiveProps & ComponentProps<'div'>) => JSX.Element;
export default Rive;

@@ -7,2 +7,3 @@ import { RefCallback, ComponentProps } from 'react';

fitCanvasToArtboardHeight: boolean;
useOffscreenRenderer: boolean;
};

@@ -9,0 +10,0 @@ export declare type Dimensions = {

{
"name": "rive-react",
"version": "0.2.0-alpha.5",
"version": "1.0.0",
"description": "React wrapper around the rive-js library",

@@ -17,3 +17,3 @@ "main": "dist/index.js",

"types:check": "tsc --noEmit",
"release": "release-it"
"release": "release-it -- major"
},

@@ -31,3 +31,3 @@ "repository": {

"dependencies": {
"@rive-app/webgl": "1.0.13"
"@rive-app/webgl": "1.0.27"
},

@@ -34,0 +34,0 @@ "peerDependencies": {

@@ -25,2 +25,26 @@ ![Build Status](https://github.com/rive-app/rive-react/actions/workflows/tests.yml/badge.svg)

### Migrating from v 0.0.x to 1.x.x
Starting in v 1.0.0, we've migrated from wrapping around the `@rive-app/canvas` runtime (which uses the `CanvasRendereringContext2D` renderer) to the `@rive-app/webgl` runtime (which uses the WebGL renderer). The high-level API doesn't require any change to upgrade, but there are some notes to consider about the backing renderer.
The backing `WebGL` runtime allows for best performance across all devices, as well as support for some features that are not supported in the `canvas` renderer runtime. To allow the `react` runtime to support some of the newer features in Rive, we needed to switch the `rive-react` backing runtime to `@rive-app/webgl`.
One note about this switch is that some browsers may limit the number of concurrent WebGL contexts. For example, Chrome may only support up to 16 contexts concurrently. We pass a property called `useOffscreenRenderer` set to true to the backing runtime when instantiating Rive by default, which helps to manage the lifecycle of the `canvas` with a single offscreen `WebGL` context, even if there are many Rive animations on the screen (i.e 16+). If you need a single `WebGL` context per Rive animation/instance, pass in the `useOffscreenRenderer` property set to `false` in the `useRive` options, or as a prop in the default export component from this runtime. See below for an example:
```js
const {rive, RiveComponent} = useRive({
src: 'foo.riv',
}, {
// Default (you don't need to set this)
useOffscreenRenderer: true,
// To override and use one context per Rive instance, uncomment and use the line below
// useOffscreenRenderer: false,
});
// or you can override the flag in JSX via props
return (
<Rive src="foo.riv" useOffscreenRenderer={false} />
);
```
## Usage

@@ -110,2 +134,3 @@

- `fitCanvasToArtboardHeight`: _(optional)_ If `true`, then the canvas will resize based on the height of the artboard. Defaults to `false`.
- `useOffscreenRenderer`: _(optional)_ If `true`, the Rive instance will share (or create if one does not exist) an offscreen `WebGL` context. This allows you to display multiple Rive animations on one screen to work around some browser limitations regarding multiple concurrent WebGL contexts. If `false`, each Rive instance will have its own dedicated `WebGL` context, and you may need to be cautious of the browser limitations just mentioned. Defaults to `true`.

@@ -112,0 +137,0 @@ ### useStateMachineInput Hook

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc