@react-spring/animated
Advanced tools
Comparing version 0.0.1-alpha.2 to 0.0.1-alpha.3
@@ -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"),globals=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 s=this.payload[a];e&&!isAnimated(s)||(t[a]=isAnimated(s)?s[e?"getAnimatedValue":"getValue"]():s)}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 globals.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=globals.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 globals.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 globals.createAnimatedInterpolation(this,...e)}}class AnimatedProps extends AnimatedObject{constructor(e,t){super(e.style&&globals.createAnimatedStyle?Object.assign({},e,{style:globals.createAnimatedStyle(e.style)}):e),this.update=t,this.attach()}}class AnimatedStyle extends AnimatedObject{constructor(e={}){super(e.transform&&globals.createAnimatedTransform?Object.assign({},e,{transform:globals.createAnimatedTransform(e.transform)}):e)}}const createAnimatedComponent=e=>React.forwardRef((t,a)=>{const s=React.useRef(null),r=React.useRef(!0),i=React.useRef(null),n=shared.useForceUpdate(),l=React.useCallback(e=>{const t=i.current;return i.current=new AnimatedProps(e,()=>{s.current&&!1===globals.applyAnimatedValues(s.current,i.current.getAnimatedValue())&&n()}),t&&t.detach(),i.current.getValue()},[]);shared.useOnce(()=>()=>{r.current=!1,i.current&&i.current.detach()}),React.useImperativeHandle(a,()=>globals.createAnimatedRef(s,r,n));const d=l(t),o=tslib_1.__rest(d,["scrollTop","scrollLeft"]);return React__default.createElement(e,Object.assign({},o,{ref:e=>s.current=handleRef(e,a)}))});function withExtend(e,t={}){const a=e,s=(r,i)=>{if(shared.is.arr(r))return r.forEach(e=>s(e));if(shared.is.obj(r)){for(const e in r)s(r[e],e);return}let n=shared.is.str(i)?i:shared.is.str(r)?r:r&&shared.is.str(r.displayName)?r.displayName:shared.is.fun(r)?r.name:"";t.lowercase&&(n=n[0].toLowerCase()+n.slice(1)),a[n]=e(r)};return a.extend=(...e)=>(e.forEach(e=>s(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 globals.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))}}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; | ||
//# sourceMappingURL=index.cjs.js.map |
import { SpringValue, Animatable, InterpolatorArgs, OneOrMore, Interpolatable, Interpolator } from '@react-spring/shared'; | ||
import { ElementType } from 'react'; | ||
export { createAnimatedInterpolation as interpolate } from '@react-spring/shared/globals'; | ||
@@ -4,0 +5,0 @@ declare function isAnimated(val: unknown): val is Animated; |
{ | ||
"name": "@react-spring/animated", | ||
"version": "0.0.1-alpha.2", | ||
"version": "0.0.1-alpha.3", | ||
"description": "Animated component props for React", | ||
@@ -28,5 +28,6 @@ "keywords": [ | ||
"module": "index.js", | ||
"types": "src/index.ts", | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.1", | ||
"@react-spring/shared": "^0.0.1-alpha.2", | ||
"@react-spring/shared": "^0.0.1-alpha.3", | ||
"tslib": "^1.9.3" | ||
@@ -33,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
141
51136