@react-spring/animated
Advanced tools
Comparing version 0.0.1-alpha.3 to 9.0.0-beta.9
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var shared=require("@react-spring/shared"),G=require("@react-spring/shared/globals"),tslib_1=require("tslib"),React=require("react"),React__default=_interopDefault(React);function isAnimated(e){return e instanceof Animated}class Animated{constructor(){this.children=[]}getAnimatedValue(){return this.getValue()}getPayload(){return this.payload||this}attach(){}detach(){}getChildren(){return this.children}addChild(e){0===this.children.length&&this.attach(),this.children.push(e)}removeChild(e){const t=this.children.indexOf(e);this.children.splice(t,1),0===this.children.length&&this.detach()}}class AnimatedArray extends Animated{attach(){this.payload.forEach(e=>isAnimated(e)&&e.addChild(this))}detach(){this.payload.forEach(e=>isAnimated(e)&&e.removeChild(this))}}class AnimatedObject extends Animated{constructor(e){super(),this.payload=e}getValue(e=!1){const t={};for(const a in this.payload){const r=this.payload[a];e&&!isAnimated(r)||(t[a]=isAnimated(r)?r[e?"getAnimatedValue":"getValue"]():r)}return t}getAnimatedValue(){return this.getValue(!0)}attach(){Object.values(this.payload).forEach(e=>isAnimated(e)&&e.addChild(this))}detach(){Object.values(this.payload).forEach(e=>isAnimated(e)&&e.removeChild(this))}}function addAnimatedStyles(e,t){"update"in e?t.add(e):e.getChildren().forEach(e=>addAnimatedStyles(e,t))}class AnimatedValue extends Animated{constructor(e){super(),this.animatedStyles=new Set,this.done=!1,this.setValue=(e,t=!0)=>{this.value=e,t&&this.flush()},this.value=e,shared.is.num(e)&&(this.startPosition=e,this.lastPosition=e)}static from(e){return isAnimated(e)?e:new AnimatedValue(e)}getValue(){return this.value}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}reset(e){shared.is.num(this.value)&&(this.startPosition=this.value,this.lastPosition=this.value,this.lastVelocity=e?this.lastVelocity:void 0,this.lastTime=e?this.lastTime:void 0,this.startTime=G.now()),this.done=!1,this.animatedStyles.clear()}clearStyles(){this.animatedStyles.clear()}flush(){0===this.animatedStyles.size&&addAnimatedStyles(this,this.animatedStyles),this.animatedStyles.forEach(e=>e.update())}}class AnimatedValueArray extends AnimatedArray{constructor(e){super(),this.payload=e}getValue(){return this.payload.map(e=>e.getValue())}setValue(e,t=!0){shared.is.arr(e)?e.length===this.payload.length&&e.forEach((e,a)=>this.payload[a].setValue(e,t)):this.payload.forEach(a=>a.setValue(e,t))}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}}class AnimatedInterpolation extends AnimatedArray{constructor(e,t){super(),this.calc=shared.createInterpolator(...t),this.payload=Array.isArray(e)?e.map(AnimatedValue.from):e instanceof AnimatedValueArray?e.getPayload():[e]}getValue(){const e=this.payload.map(e=>e.getValue());return this.calc(...e)}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}}class AnimatedProps extends AnimatedObject{constructor(e,t){super(e.style&&G.createAnimatedStyle?Object.assign({},e,{style:G.createAnimatedStyle(e.style)}):e),this.update=t,this.attach()}}class AnimatedStyle extends AnimatedObject{constructor(e={}){super(e.transform&&G.createAnimatedTransform?Object.assign({},e,{transform:G.createAnimatedTransform(e.transform)}):e)}}const createAnimatedComponent=e=>React.forwardRef((t,a)=>{const r=React.useRef(null),s=React.useRef(!0),i=React.useRef(null),n=shared.useForceUpdate(),d=React.useCallback(e=>{const t=i.current;return i.current=new AnimatedProps(e,()=>{r.current&&!1===G.applyAnimatedValues(r.current,i.current.getAnimatedValue())&&n()}),t&&t.detach(),i.current.getValue()},[]);shared.useOnce(()=>()=>{s.current=!1,i.current&&i.current.detach()}),React.useImperativeHandle(a,()=>G.createAnimatedRef(r,s,n));const l=d(t),o=tslib_1.__rest(l,["scrollTop","scrollLeft"]);return React__default.createElement(e,Object.assign({},o,{ref:e=>r.current=handleRef(e,a)}))});function withExtend(e,t={}){const a=e,r=(s,i)=>{if(shared.is.arr(s))return s.forEach(e=>r(e));if(shared.is.obj(s)){for(const e in s)r(s[e],e);return}let n=shared.is.str(i)?i:shared.is.str(s)?s:s&&shared.is.str(s.displayName)?s.displayName:shared.is.fun(s)?s.name:"";t.lowercase&&(n=n[0].toLowerCase()+n.slice(1)),a[n]=e(s)};return a.extend=(...e)=>(e.forEach(e=>r(e)),a),a}function handleRef(e,t){return t&&(shared.is.fun(t)?t(e):shared.is.obj(t)&&(t.current=e)),e}Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return G.createAnimatedInterpolation}}),exports.Animated=Animated,exports.AnimatedArray=AnimatedArray,exports.AnimatedInterpolation=AnimatedInterpolation,exports.AnimatedObject=AnimatedObject,exports.AnimatedProps=AnimatedProps,exports.AnimatedStyle=AnimatedStyle,exports.AnimatedValue=AnimatedValue,exports.AnimatedValueArray=AnimatedValueArray,exports.createAnimatedComponent=createAnimatedComponent,exports.isAnimated=isAnimated,exports.withExtend=withExtend; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var shared=require("@react-spring/shared"),G=require("@react-spring/shared/globals"),tslib_1=require("tslib"),React=require("react"),React__default=_interopDefault(React);function isAnimated(e){return e instanceof Animated}class Animated{constructor(){this.children=[]}getAnimatedValue(){return this.getValue()}getPayload(){return this.payload||this}attach(){}detach(){}getChildren(){return this.children}addChild(e){0===this.children.length&&this.attach(),this.children.push(e)}removeChild(e){const t=this.children.indexOf(e);this.children.splice(t,1),0===this.children.length&&this.detach()}}class AnimatedArray extends Animated{attach(){this.payload.forEach(e=>isAnimated(e)&&e.addChild(this))}detach(){this.payload.forEach(e=>isAnimated(e)&&e.removeChild(this))}}class AnimatedObject extends Animated{constructor(e){super(),this.payload=e}getValue(e=!1){const t={};for(const a in this.payload){const r=this.payload[a];e&&!isAnimated(r)||(t[a]=isAnimated(r)?r[e?"getAnimatedValue":"getValue"]():r)}return t}getAnimatedValue(){return this.getValue(!0)}attach(){Object.values(this.payload).forEach(e=>isAnimated(e)&&e.addChild(this))}detach(){Object.values(this.payload).forEach(e=>isAnimated(e)&&e.removeChild(this))}}class AnimatedStyle extends AnimatedObject{constructor(e={}){super(e.transform&&G.createAnimatedTransform?Object.assign({},e,{transform:G.createAnimatedTransform(e.transform)}):e)}}function addAnimatedStyles(e,t){"update"in e?t.add(e):e.getChildren().forEach(e=>addAnimatedStyles(e,t))}class AnimatedValue extends Animated{constructor(e){super(),this.animatedStyles=new Set,this.done=!1,this.setValue=(e,t=!0)=>{this.value=e,t&&this.flush()},this.value=e,shared.is.num(e)&&(this.startPosition=e,this.lastPosition=e)}static from(e){return isAnimated(e)?e:new AnimatedValue(e)}getValue(){return this.value}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}reset(e){shared.is.num(this.value)&&(this.startPosition=this.value,this.lastPosition=this.value,this.lastVelocity=e?this.lastVelocity:void 0,this.lastTime=e?this.lastTime:void 0,this.startTime=G.now()),this.done=!1,this.animatedStyles.clear()}clearStyles(){this.animatedStyles.clear()}flush(){0===this.animatedStyles.size&&addAnimatedStyles(this,this.animatedStyles),this.animatedStyles.forEach(e=>e.update())}}class AnimatedValueArray extends AnimatedArray{constructor(e){super(),this.payload=e}getValue(){return this.payload.map(e=>e.getValue())}setValue(e,t=!0){shared.is.arr(e)?e.length===this.payload.length&&e.forEach((e,a)=>this.payload[a].setValue(e,t)):this.payload.forEach(a=>a.setValue(e,t))}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}}class AnimatedInterpolation extends AnimatedArray{constructor(e,t){super(),this.calc=shared.createInterpolator(...t),this.payload=Array.isArray(e)?e.map(AnimatedValue.from):e instanceof AnimatedValueArray?e.getPayload():[e]}getValue(){const e=this.payload.map(e=>e.getValue());return this.calc(...e)}interpolate(...e){return G.createAnimatedInterpolation(this,...e)}}shared.Globals.assign({createAnimatedStyle:e=>new AnimatedStyle(e),createAnimatedInterpolation:(e,...t)=>new AnimatedInterpolation(e,t)});class AnimatedProps extends AnimatedObject{constructor(e,t){super(e.style&&G.createAnimatedStyle?Object.assign({},e,{style:G.createAnimatedStyle(e.style)}):e),this.update=t,this.attach()}}const createAnimatedComponent=e=>React.forwardRef((t,a)=>{const r=React.useRef(null),s=React.useRef(!0),i=React.useRef(null),n=shared.useForceUpdate(),d=React.useCallback(e=>{const t=i.current;return i.current=new AnimatedProps(e,()=>{!1===(r.current&&G.applyAnimatedValues(r.current,i.current.getAnimatedValue()))&&n()}),t&&t.detach(),i.current.getValue()},[]);shared.useOnce(()=>()=>{s.current=!1,i.current&&i.current.detach()}),React.useImperativeHandle(a,()=>G.createAnimatedRef(r,s,n));const l=d(t),o=tslib_1.__rest(l,["scrollTop","scrollLeft"]),c=shared.is.fun(e)?void 0:e=>r.current=handleRef(e,a);return React__default.createElement(e,Object.assign({},o,{ref:c}))});function withExtend(e,t={}){const a=e,r=(s,i)=>{if(shared.is.arr(s))return s.forEach(e=>r(e));if(shared.is.obj(s)){for(const e in s)r(s[e],e);return}let n=shared.is.str(i)?i:shared.is.str(s)?s:s&&shared.is.str(s.displayName)?s.displayName:shared.is.fun(s)?s.name:"";t.lowercase&&(n=n[0].toLowerCase()+n.slice(1)),a[n]=e(s)};return a.extend=(...e)=>(e.forEach(e=>r(e)),a),a}function handleRef(e,t){return t&&(shared.is.fun(t)?t(e):shared.is.obj(t)&&(t.current=e)),e}Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return G.createAnimatedInterpolation}}),exports.Animated=Animated,exports.AnimatedArray=AnimatedArray,exports.AnimatedInterpolation=AnimatedInterpolation,exports.AnimatedObject=AnimatedObject,exports.AnimatedProps=AnimatedProps,exports.AnimatedStyle=AnimatedStyle,exports.AnimatedValue=AnimatedValue,exports.AnimatedValueArray=AnimatedValueArray,exports.createAnimatedComponent=createAnimatedComponent,exports.isAnimated=isAnimated,exports.withExtend=withExtend; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -105,3 +105,3 @@ import { SpringValue, Animatable, InterpolatorArgs, OneOrMore, Interpolatable, Interpolator } from '@react-spring/shared'; | ||
}; | ||
declare type CreateAnimated = (Component: ElementType) => any; | ||
declare type CreateAnimated = (Component: string | ElementType) => any; | ||
/** Add an `extend` method to your `animated` factory function */ | ||
@@ -108,0 +108,0 @@ declare function withExtend<T extends CreateAnimated>(animated: T, options?: { |
@@ -1,2 +0,2 @@ | ||
import{is as t,createInterpolator as e,useForceUpdate as s,useOnce as a}from"@react-spring/shared";import{createAnimatedInterpolation as r,now as i,createAnimatedStyle as n,createAnimatedTransform as l,createAnimatedRef as h,applyAnimatedValues as o}from"@react-spring/shared/globals";export{createAnimatedInterpolation as interpolate}from"@react-spring/shared/globals";import{__rest as c}from"tslib";import u,{forwardRef as d,useRef as p,useCallback as m,useImperativeHandle as f}from"react";function y(t){return t instanceof g}class g{constructor(){this.children=[]}getAnimatedValue(){return this.getValue()}getPayload(){return this.payload||this}attach(){}detach(){}getChildren(){return this.children}addChild(t){0===this.children.length&&this.attach(),this.children.push(t)}removeChild(t){const e=this.children.indexOf(t);this.children.splice(e,1),0===this.children.length&&this.detach()}}class V extends g{attach(){this.payload.forEach(t=>y(t)&&t.addChild(this))}detach(){this.payload.forEach(t=>y(t)&&t.removeChild(this))}}class v extends g{constructor(t){super(),this.payload=t}getValue(t=!1){const e={};for(const s in this.payload){const a=this.payload[s];t&&!y(a)||(e[s]=y(a)?a[t?"getAnimatedValue":"getValue"]():a)}return e}getAnimatedValue(){return this.getValue(!0)}attach(){Object.values(this.payload).forEach(t=>y(t)&&t.addChild(this))}detach(){Object.values(this.payload).forEach(t=>y(t)&&t.removeChild(this))}}class x extends g{constructor(e){super(),this.animatedStyles=new Set,this.done=!1,this.setValue=(t,e=!0)=>{this.value=t,e&&this.flush()},this.value=e,t.num(e)&&(this.startPosition=e,this.lastPosition=e)}static from(t){return y(t)?t:new x(t)}getValue(){return this.value}interpolate(...t){return r(this,...t)}reset(e){t.num(this.value)&&(this.startPosition=this.value,this.lastPosition=this.value,this.lastVelocity=e?this.lastVelocity:void 0,this.lastTime=e?this.lastTime:void 0,this.startTime=i()),this.done=!1,this.animatedStyles.clear()}clearStyles(){this.animatedStyles.clear()}flush(){0===this.animatedStyles.size&&function t(e,s){"update"in e?s.add(e):e.getChildren().forEach(e=>t(e,s))}(this,this.animatedStyles),this.animatedStyles.forEach(t=>t.update())}}class E extends V{constructor(t){super(),this.payload=t}getValue(){return this.payload.map(t=>t.getValue())}setValue(e,s=!0){t.arr(e)?e.length===this.payload.length&&e.forEach((t,e)=>this.payload[e].setValue(t,s)):this.payload.forEach(t=>t.setValue(e,s))}interpolate(...t){return r(this,...t)}}class b extends V{constructor(t,s){super(),this.calc=e(...s),this.payload=Array.isArray(t)?t.map(x.from):t instanceof E?t.getPayload():[t]}getValue(){const t=this.payload.map(t=>t.getValue());return this.calc(...t)}interpolate(...t){return r(this,...t)}}class C extends v{constructor(t,e){super(t.style&&n?Object.assign({},t,{style:n(t.style)}):t),this.update=e,this.attach()}}class S extends v{constructor(t={}){super(t.transform&&l?Object.assign({},t,{transform:l(t.transform)}):t)}}const j=e=>d((r,i)=>{const n=p(null),l=p(!0),d=p(null),y=s(),g=m(t=>{const e=d.current;return d.current=new C(t,()=>{n.current&&!1===o(n.current,d.current.getAnimatedValue())&&y()}),e&&e.detach(),d.current.getValue()},[]);a(()=>()=>{l.current=!1,d.current&&d.current.detach()}),f(i,()=>h(n,l,y));const V=g(r),v=c(V,["scrollTop","scrollLeft"]);return u.createElement(e,Object.assign({},v,{ref:e=>n.current=function(e,s){s&&(t.fun(s)?s(e):t.obj(s)&&(s.current=e));return e}(e,i)}))});function A(e,s={}){const a=e,r=(i,n)=>{if(t.arr(i))return i.forEach(t=>r(t));if(t.obj(i)){for(const t in i)r(i[t],t);return}let l=t.str(n)?n:t.str(i)?i:i&&t.str(i.displayName)?i.displayName:t.fun(i)?i.name:"";s.lowercase&&(l=l[0].toLowerCase()+l.slice(1)),a[l]=e(i)};return a.extend=(...t)=>(t.forEach(t=>r(t)),a),a}export{g as Animated,V as AnimatedArray,b as AnimatedInterpolation,v as AnimatedObject,C as AnimatedProps,S as AnimatedStyle,x as AnimatedValue,E as AnimatedValueArray,j as createAnimatedComponent,y as isAnimated,A as withExtend}; | ||
import{is as t,createInterpolator as e,Globals as s,useForceUpdate as a,useOnce as r}from"@react-spring/shared";import{createAnimatedTransform as i,createAnimatedInterpolation as n,now as l,createAnimatedStyle as o,createAnimatedRef as h,applyAnimatedValues as c}from"@react-spring/shared/globals";export{createAnimatedInterpolation as interpolate}from"@react-spring/shared/globals";import{__rest as u}from"tslib";import d,{forwardRef as p,useRef as m,useCallback as f,useImperativeHandle as y}from"react";function g(t){return t instanceof V}class V{constructor(){this.children=[]}getAnimatedValue(){return this.getValue()}getPayload(){return this.payload||this}attach(){}detach(){}getChildren(){return this.children}addChild(t){0===this.children.length&&this.attach(),this.children.push(t)}removeChild(t){const e=this.children.indexOf(t);this.children.splice(e,1),0===this.children.length&&this.detach()}}class v extends V{attach(){this.payload.forEach(t=>g(t)&&t.addChild(this))}detach(){this.payload.forEach(t=>g(t)&&t.removeChild(this))}}class x extends V{constructor(t){super(),this.payload=t}getValue(t=!1){const e={};for(const s in this.payload){const a=this.payload[s];t&&!g(a)||(e[s]=g(a)?a[t?"getAnimatedValue":"getValue"]():a)}return e}getAnimatedValue(){return this.getValue(!0)}attach(){Object.values(this.payload).forEach(t=>g(t)&&t.addChild(this))}detach(){Object.values(this.payload).forEach(t=>g(t)&&t.removeChild(this))}}class E extends x{constructor(t={}){super(t.transform&&i?Object.assign({},t,{transform:i(t.transform)}):t)}}class b extends V{constructor(e){super(),this.animatedStyles=new Set,this.done=!1,this.setValue=(t,e=!0)=>{this.value=t,e&&this.flush()},this.value=e,t.num(e)&&(this.startPosition=e,this.lastPosition=e)}static from(t){return g(t)?t:new b(t)}getValue(){return this.value}interpolate(...t){return n(this,...t)}reset(e){t.num(this.value)&&(this.startPosition=this.value,this.lastPosition=this.value,this.lastVelocity=e?this.lastVelocity:void 0,this.lastTime=e?this.lastTime:void 0,this.startTime=l()),this.done=!1,this.animatedStyles.clear()}clearStyles(){this.animatedStyles.clear()}flush(){0===this.animatedStyles.size&&function t(e,s){"update"in e?s.add(e):e.getChildren().forEach(e=>t(e,s))}(this,this.animatedStyles),this.animatedStyles.forEach(t=>t.update())}}class A extends v{constructor(t){super(),this.payload=t}getValue(){return this.payload.map(t=>t.getValue())}setValue(e,s=!0){t.arr(e)?e.length===this.payload.length&&e.forEach((t,e)=>this.payload[e].setValue(t,s)):this.payload.forEach(t=>t.setValue(e,s))}interpolate(...t){return n(this,...t)}}class C extends v{constructor(t,s){super(),this.calc=e(...s),this.payload=Array.isArray(t)?t.map(b.from):t instanceof A?t.getPayload():[t]}getValue(){const t=this.payload.map(t=>t.getValue());return this.calc(...t)}interpolate(...t){return n(this,...t)}}s.assign({createAnimatedStyle:t=>new E(t),createAnimatedInterpolation:(t,...e)=>new C(t,e)});class S extends x{constructor(t,e){super(t.style&&o?Object.assign({},t,{style:o(t.style)}):t),this.update=e,this.attach()}}const j=e=>p((s,i)=>{const n=m(null),l=m(!0),o=m(null),p=a(),g=f(t=>{const e=o.current;return o.current=new S(t,()=>{!1===(n.current&&c(n.current,o.current.getAnimatedValue()))&&p()}),e&&e.detach(),o.current.getValue()},[]);r(()=>()=>{l.current=!1,o.current&&o.current.detach()}),y(i,()=>h(n,l,p));const V=g(s),v=u(V,["scrollTop","scrollLeft"]),x=t.fun(e)?void 0:e=>n.current=function(e,s){s&&(t.fun(s)?s(e):t.obj(s)&&(s.current=e));return e}(e,i);return d.createElement(e,Object.assign({},v,{ref:x}))});function w(e,s={}){const a=e,r=(i,n)=>{if(t.arr(i))return i.forEach(t=>r(t));if(t.obj(i)){for(const t in i)r(i[t],t);return}let l=t.str(n)?n:t.str(i)?i:i&&t.str(i.displayName)?i.displayName:t.fun(i)?i.name:"";s.lowercase&&(l=l[0].toLowerCase()+l.slice(1)),a[l]=e(i)};return a.extend=(...t)=>(t.forEach(t=>r(t)),a),a}export{V as Animated,v as AnimatedArray,C as AnimatedInterpolation,x as AnimatedObject,S as AnimatedProps,E as AnimatedStyle,b as AnimatedValue,A as AnimatedValueArray,j as createAnimatedComponent,g as isAnimated,w as withExtend}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@react-spring/animated", | ||
"version": "0.0.1-alpha.3", | ||
"version": "9.0.0-beta.9", | ||
"description": "Animated component props for React", | ||
@@ -28,6 +28,6 @@ "keywords": [ | ||
"module": "index.js", | ||
"types": "src/index.ts", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.1", | ||
"@react-spring/shared": "^0.0.1-alpha.3", | ||
"@react-spring/shared": "^9.0.0-beta.9", | ||
"tslib": "^1.9.3" | ||
@@ -34,0 +34,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53075
+ Added@react-spring/rafz@9.7.4(transitive)
+ Added@react-spring/shared@9.7.4(transitive)
+ Added@react-spring/types@9.7.4(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)
- Removed@react-spring/shared@0.0.1-alpha.3(transitive)
- Removedtiny-invariant@1.3.3(transitive)