Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-spring/animated

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-spring/animated - npm Package Compare versions

Comparing version 9.0.0-beta.29 to 9.0.0-beta.30

30

index.cjs.js

@@ -11,2 +11,3 @@ 'use strict';

var G = require('@react-spring/shared/globals');
var deprecations = require('@react-spring/shared/deprecations');
var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));

@@ -145,2 +146,7 @@ var invariant = _interopDefault(require('tiny-invariant'));

var interpolate = function interpolate() {
deprecations.deprecateInterpolate();
return G.createAnimatedInterpolation.apply(void 0, arguments);
};
var AnimatedInterpolation =

@@ -169,3 +175,3 @@ /*#__PURE__*/

_proto.interpolate = function interpolate() {
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -178,2 +184,7 @@ args[_key] = arguments[_key];

_proto.interpolate = function interpolate() {
deprecations.deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.getPayload = function getPayload() {

@@ -265,3 +276,3 @@ return shared.is.arr(this.source) ? this.payload || (this.payload = toPayload(this.source)) : this.source.getPayload();

_proto.interpolate = function interpolate() {
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -274,2 +285,7 @@ args[_key] = arguments[_key];

_proto.interpolate = function interpolate() {
deprecations.deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.reset = function reset(isActive) {

@@ -361,3 +377,3 @@ if (shared.is.num(this.value)) {

_proto.interpolate = function interpolate() {
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -370,2 +386,7 @@ args[_key] = arguments[_key];

_proto.interpolate = function interpolate() {
deprecations.deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.updatePayload = function updatePayload(prev, next) {

@@ -476,3 +497,3 @@ var source = [].concat(this.source);

Object.defineProperty(exports, 'interpolate', {
Object.defineProperty(exports, 'to', {
enumerable: true,

@@ -493,2 +514,3 @@ get: function () {

exports.extendAnimated = extendAnimated;
exports.interpolate = interpolate;
exports.isAnimated = isAnimated;

@@ -495,0 +517,0 @@ exports.removeChild = removeChild;

11

index.d.ts

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

import { SpringValue, Animatable, InterpolatorArgs, Indexable, Interpolatable, OneOrMore, Interpolator, ElementType } from '@react-spring/shared';
export { createAnimatedInterpolation as interpolate } from '@react-spring/shared/globals';
import { SpringValue, Animatable, InterpolatorArgs, Indexable, Interpolatable, OneOrMore, Interpolator, ElementType, SpringInterpolator } from '@react-spring/shared';
export { createAnimatedInterpolation as to } from '@react-spring/shared/globals';

@@ -17,2 +17,3 @@ /** An animated number or a native attribute value */

setValue(value: T, flush?: boolean): void;
to<Out extends Animatable>(...args: InterpolatorArgs<T, Out>): SpringValue<Out>;
interpolate<Out extends Animatable>(...args: InterpolatorArgs<T, Out>): SpringValue<Out>;

@@ -67,2 +68,3 @@ reset(isActive: boolean): void;

setValue(value: any, flush?: boolean): void;
to<Out extends Animatable>(...args: InterpolatorArgs<any[], Out>): SpringValue<Out>;
interpolate<Out extends Animatable>(...args: InterpolatorArgs<any[], Out>): SpringValue<Out>;

@@ -77,2 +79,3 @@ updatePayload(prev: Animated, next: Animated): void;

getValue(animated?: boolean): Out;
to<T extends Animatable>(...args: InterpolatorArgs<Out, T>): SpringValue<T>;
interpolate<T extends Animatable>(...args: InterpolatorArgs<Out, T>): SpringValue<T>;

@@ -114,2 +117,4 @@ getPayload(): ReadonlySet<AnimatedValue>;

export { Animated, AnimatedArray, AnimatedInterpolation, AnimatedObject, AnimatedProps, AnimatedStyle, AnimatedValue, addChild, animatedTag, extendAnimated, isAnimated, removeChild, toPayload, withAnimated };
declare const interpolate: SpringInterpolator;
export { Animated, AnimatedArray, AnimatedInterpolation, AnimatedObject, AnimatedProps, AnimatedStyle, AnimatedValue, addChild, animatedTag, extendAnimated, interpolate, isAnimated, removeChild, toPayload, withAnimated };
import { each, createInterpolator, is, toArray, Globals, useForceUpdate, useOnce } from '@react-spring/shared';
import _extends from '@babel/runtime/helpers/esm/extends';
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
import { createAnimatedTransform, createAnimatedInterpolation, now, createAnimatedStyle, applyAnimatedValues, getComponentProps } from '@react-spring/shared/globals';
export { createAnimatedInterpolation as interpolate } from '@react-spring/shared/globals';
export { createAnimatedInterpolation as to } from '@react-spring/shared/globals';
import { deprecateInterpolate } from '@react-spring/shared/deprecations';
import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
import invariant from 'tiny-invariant';

@@ -10,6 +13,10 @@ import React, { forwardRef, useRef, useEffect } from 'react';

const animatedTag = Symbol.for('isAnimated');
const isAnimated = val => !!(val && val[animatedTag]);
class Animated {
constructor() {
var animatedTag = Symbol.for('isAnimated');
var isAnimated = function isAnimated(val) {
return !!(val && val[animatedTag]);
};
var Animated =
/*#__PURE__*/
function () {
function Animated() {
this[_a] = true;

@@ -21,35 +28,47 @@ this.children = new Set();

getPayload() {
var _proto = Animated.prototype;
_proto.getPayload = function getPayload() {
return this.payload;
}
/** Returns the set of animated nodes that depend on this node. */
;
getChildren() {
_proto.getChildren = function getChildren() {
return this.children;
}
};
addChild(child) {
_proto.addChild = function addChild(child) {
this.children.size || this._attach();
this.children.add(child);
}
};
removeChild(child) {
_proto.removeChild = function removeChild(child) {
this.children.delete(child);
this.children.size || this._detach();
}
};
}
return Animated;
}();
_a = animatedTag;
class AnimatedObject extends Animated {
constructor(source) {
super();
this.source = source;
this.payload = toPayload(source);
var AnimatedObject =
/*#__PURE__*/
function (_Animated) {
_inheritsLoose(AnimatedObject, _Animated);
function AnimatedObject(source) {
var _this;
_this = _Animated.call(this) || this;
_this.source = source;
_this.payload = toPayload(source);
return _this;
}
getValue(animated) {
const obj = {};
each(this.source, (val, key) => {
var _proto = AnimatedObject.prototype;
_proto.getValue = function getValue(animated) {
var obj = {};
each(this.source, function (val, key) {
if (isAnimated(val)) {

@@ -62,8 +81,8 @@ obj[key] = val.getValue(animated);

return obj;
}
};
updatePayload(prev, next) {
const source = _extends({}, this.source);
_proto.updatePayload = function updatePayload(prev, next) {
var source = _extends({}, this.source);
each(source, (val, key) => {
each(source, function (val, key) {
if (val === prev) source[key] = next;

@@ -73,20 +92,23 @@ });

this.payload = toPayload(source);
}
};
_attach() {
_proto._attach = function _attach() {
each(this.source, addChild, this);
}
};
_detach() {
_proto._detach = function _detach() {
each(this.source, removeChild, this);
}
};
}
return AnimatedObject;
}(Animated);
/** Convert an array or object to a flat payload */
function toPayload(source) {
const payload = new Set();
each(source, val => {
var payload = new Set();
each(source, function (val) {
if (isAnimated(val)) {
each(val.getPayload(), node => payload.add(node));
each(val.getPayload(), function (node) {
return payload.add(node);
});
}

@@ -103,4 +125,8 @@ });

class AnimatedStyle extends AnimatedObject {
constructor(style) {
var AnimatedStyle =
/*#__PURE__*/
function (_AnimatedObject) {
_inheritsLoose(AnimatedStyle, _AnimatedObject);
function AnimatedStyle(style) {
if (style === void 0) {

@@ -110,22 +136,39 @@ style = {};

super(style.transform && createAnimatedTransform ? _extends({}, style, {
return _AnimatedObject.call(this, style.transform && createAnimatedTransform ? _extends({}, style, {
transform: createAnimatedTransform(style.transform)
}) : style);
}) : style) || this;
}
}
return AnimatedStyle;
}(AnimatedObject);
class AnimatedInterpolation extends Animated {
constructor(source, args) {
super();
this.source = source;
this.calc = createInterpolator(...args);
}
var interpolate = function interpolate() {
deprecateInterpolate();
return createAnimatedInterpolation.apply(void 0, arguments);
};
getValue(animated) {
const args = is.arr(this.source) ? this.source.map(node => node.getValue(animated)) : toArray(this.source.getValue(animated));
return this.calc(...args);
var AnimatedInterpolation =
/*#__PURE__*/
function (_Animated) {
_inheritsLoose(AnimatedInterpolation, _Animated);
function AnimatedInterpolation(source, args) {
var _this;
_this = _Animated.call(this) || this;
_this.source = source;
_this.calc = createInterpolator.apply(void 0, args);
return _this;
}
interpolate() {
var _proto = AnimatedInterpolation.prototype;
_proto.getValue = function getValue(animated) {
var args = is.arr(this.source) ? this.source.map(function (node) {
return node.getValue(animated);
}) : toArray(this.source.getValue(animated));
return this.calc.apply(this, args);
};
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -135,15 +178,20 @@ args[_key] = arguments[_key];

return createAnimatedInterpolation(this, ...args);
}
return createAnimatedInterpolation.apply(void 0, [this].concat(args));
};
getPayload() {
_proto.interpolate = function interpolate() {
deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.getPayload = function getPayload() {
return is.arr(this.source) ? this.payload || (this.payload = toPayload(this.source)) : this.source.getPayload();
}
};
updatePayload(prev, next) {
_proto.updatePayload = function updatePayload(prev, next) {
this.payload = void 0;
if (is.arr(this.source)) {
const source = [...this.source];
each(source, (val, index) => {
var source = [].concat(this.source);
each(source, function (val, index) {
if (val === prev) source[index] = next;

@@ -155,16 +203,19 @@ });

}
}
};
_attach() {
_proto._attach = function _attach() {
each(toArray(this.source), addChild, this);
}
};
_detach() {
_proto._detach = function _detach() {
each(toArray(this.source), removeChild, this);
}
};
}
return AnimatedInterpolation;
}(Animated);
Globals.assign({
createAnimatedStyle: style => new AnimatedStyle(style),
createAnimatedStyle: function createAnimatedStyle(style) {
return new AnimatedStyle(style);
},
createAnimatedInterpolation: function createAnimatedInterpolation(parents) {

@@ -181,21 +232,31 @@ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {

class AnimatedValue extends Animated {
constructor(value) {
super();
this.views = new Set();
this.done = false;
this.value = value;
this.payload = new Set([this]);
var AnimatedValue =
/*#__PURE__*/
function (_Animated) {
_inheritsLoose(AnimatedValue, _Animated);
function AnimatedValue(value) {
var _this;
_this = _Animated.call(this) || this;
_this.views = new Set();
_this.done = false;
_this.value = value;
_this.payload = new Set([_assertThisInitialized(_this)]);
if (is.num(value)) {
this.startPosition = value;
this.lastPosition = value;
_this.startPosition = value;
_this.lastPosition = value;
}
return _this;
}
getValue() {
var _proto = AnimatedValue.prototype;
_proto.getValue = function getValue() {
return this.value;
}
};
setValue(value, flush) {
_proto.setValue = function setValue(value, flush) {
this.value = value;

@@ -208,7 +269,9 @@

each(this.views, view => view.update());
each(this.views, function (view) {
return view.update();
});
}
}
};
interpolate() {
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -218,6 +281,11 @@ args[_key] = arguments[_key];

return createAnimatedInterpolation(this, ...args);
}
return createAnimatedInterpolation.apply(void 0, [this].concat(args));
};
reset(isActive) {
_proto.interpolate = function interpolate() {
deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.reset = function reset(isActive) {
if (is.num(this.value)) {

@@ -234,9 +302,10 @@ this.startPosition = this.value;

} // Do nothing for either of these.
;
_proto._attach = function _attach() {};
_attach() {}
_proto._detach = function _detach() {};
_detach() {}
}
return AnimatedValue;
}(Animated);
/**

@@ -267,3 +336,5 @@ * This library works by building a directed acyclic graph of dependencies

} else {
each(node.getChildren(), child => collectViews(child, views));
each(node.getChildren(), function (child) {
return collectViews(child, views);
});
}

@@ -274,24 +345,36 @@ }

class AnimatedArray extends AnimatedObject {
constructor(source) {
super(source);
}
var AnimatedArray =
/*#__PURE__*/
function (_AnimatedObject) {
_inheritsLoose(AnimatedArray, _AnimatedObject);
getValue(animated) {
return this.source.map(node => node.getValue(animated));
function AnimatedArray(source) {
return _AnimatedObject.call(this, source) || this;
}
setValue(value, flush) {
const nodes = this.payload;
var _proto = AnimatedArray.prototype;
_proto.getValue = function getValue(animated) {
return this.source.map(function (node) {
return node.getValue(animated);
});
};
_proto.setValue = function setValue(value, flush) {
var nodes = this.payload;
if (is.arr(value)) {
invariant(value.length == nodes.size);
let i = 0;
each(nodes, node => node.setValue(value[i++], flush));
var i = 0;
each(nodes, function (node) {
return node.setValue(value[i++], flush);
});
} else {
each(nodes, node => node.setValue(value, flush));
each(nodes, function (node) {
return node.setValue(value, flush);
});
}
}
};
interpolate() {
_proto.to = function to() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -301,8 +384,13 @@ args[_key] = arguments[_key];

return createAnimatedInterpolation(this, ...args);
}
return createAnimatedInterpolation.apply(void 0, [this].concat(args));
};
updatePayload(prev, next) {
const source = [...this.source];
each(source, (val, index) => {
_proto.interpolate = function interpolate() {
deprecateInterpolate();
return this.to.apply(this, arguments);
};
_proto.updatePayload = function updatePayload(prev, next) {
var source = [].concat(this.source);
each(source, function (val, index) {
if (val === prev) source[index] = next;

@@ -312,52 +400,69 @@ });

this.payload = toPayload(source);
}
};
}
return AnimatedArray;
}(AnimatedObject);
class AnimatedProps extends AnimatedObject {
constructor(props, update) {
super(props.style && createAnimatedStyle ? _extends({}, props, {
var AnimatedProps =
/*#__PURE__*/
function (_AnimatedObject) {
_inheritsLoose(AnimatedProps, _AnimatedObject);
function AnimatedProps(props, update) {
var _this;
_this = _AnimatedObject.call(this, props.style && createAnimatedStyle ? _extends({}, props, {
style: createAnimatedStyle(props.style)
}) : props);
this.update = update;
}) : props) || this;
_this.update = update;
return _this;
}
}
return AnimatedProps;
}(AnimatedObject);
const cacheKey = Symbol.for('AnimatedComponent');
const withAnimated = Component => is.str(Component) ? createAnimatedComponent(Component) : Component[cacheKey] || (Component[cacheKey] = createAnimatedComponent(Component));
var cacheKey = Symbol.for('AnimatedComponent');
var withAnimated = function withAnimated(Component) {
return is.str(Component) ? createAnimatedComponent(Component) : Component[cacheKey] || (Component[cacheKey] = createAnimatedComponent(Component));
};
const createAnimatedComponent = Component => forwardRef((rawProps, ref) => {
const node = useRef(null);
const props = useRef(null);
const forceUpdate = useForceUpdate();
const nextProps = new AnimatedProps(rawProps, () => {
const didUpdate = !!node.current && applyAnimatedValues(node.current, nextProps.getValue(true)); // Re-render the component when native updates fail.
var createAnimatedComponent = function createAnimatedComponent(Component) {
return forwardRef(function (rawProps, ref) {
var node = useRef(null);
var props = useRef(null);
var forceUpdate = useForceUpdate();
var nextProps = new AnimatedProps(rawProps, function () {
var didUpdate = !!node.current && applyAnimatedValues(node.current, nextProps.getValue(true)); // Re-render the component when native updates fail.
if (didUpdate === false) {
forceUpdate();
}
});
useEffect(() => {
const prevProps = props.current;
props.current = nextProps; // To avoid causing a cascade of detachment, we must detach
// the old props only *after* the new props are attached.
if (didUpdate === false) {
forceUpdate();
}
});
useEffect(function () {
var prevProps = props.current;
props.current = nextProps; // To avoid causing a cascade of detachment, we must detach
// the old props only *after* the new props are attached.
nextProps._attach();
nextProps._attach();
if (prevProps) {
prevProps._detach();
}
}); // Ensure the latest props are detached on unmount.
if (prevProps) {
prevProps._detach();
}
}); // Ensure the latest props are detached on unmount.
useOnce(() => () => {
props.current._detach();
}); // Functions cannot have refs (see #569)
useOnce(function () {
return function () {
props.current._detach();
};
}); // Functions cannot have refs (see #569)
const refFn = !is.fun(Component) || Component.prototype.isReactComponent ? value => node.current = updateRef(ref, value) : void 0;
rawProps = getComponentProps(nextProps.getValue());
return React.createElement(Component, Object.assign({}, rawProps, {
ref: refFn
}));
});
var refFn = !is.fun(Component) || Component.prototype.isReactComponent ? function (value) {
return node.current = updateRef(ref, value);
} : void 0;
rawProps = getComponentProps(nextProps.getValue());
return React.createElement(Component, Object.assign({}, rawProps, {
ref: refFn
}));
});
};

@@ -377,5 +482,5 @@ function updateRef(ref, value) {

const extendAnimated = (withAnimated, components, lowercase) => {
components.forEach(Component => {
let key = getDisplayName(Component);
var extendAnimated = function extendAnimated(withAnimated, components, lowercase) {
components.forEach(function (Component) {
var key = getDisplayName(Component);

@@ -391,5 +496,7 @@ if (lowercase) {

const getDisplayName = arg => is.str(arg) ? arg : arg && is.str(arg.displayName) ? arg.displayName : is.fun(arg) && arg.name || null;
var getDisplayName = function getDisplayName(arg) {
return is.str(arg) ? arg : arg && is.str(arg.displayName) ? arg.displayName : is.fun(arg) && arg.name || null;
};
export { Animated, AnimatedArray, AnimatedInterpolation, AnimatedObject, AnimatedProps, AnimatedStyle, AnimatedValue, addChild, animatedTag, extendAnimated, isAnimated, removeChild, toPayload, withAnimated };
export { Animated, AnimatedArray, AnimatedInterpolation, AnimatedObject, AnimatedProps, AnimatedStyle, AnimatedValue, addChild, animatedTag, extendAnimated, interpolate, isAnimated, removeChild, toPayload, withAnimated };
//# sourceMappingURL=index.js.map
{
"name": "@react-spring/animated",
"version": "9.0.0-beta.29",
"version": "9.0.0-beta.30",
"description": "Animated component props for React",

@@ -31,3 +31,3 @@ "keywords": [

"@babel/runtime": "^7.3.1",
"@react-spring/shared": "^9.0.0-beta.29"
"@react-spring/shared": "^9.0.0-beta.30"
},

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

import { AnimatedValue } from './AnimatedValue'
export const animatedTag = Symbol.for('isAnimated')

@@ -4,0 +3,0 @@

import { is, Animatable, SpringValue, InterpolatorArgs, each } from '@react-spring/shared'
import { deprecateInterpolate } from '@react-spring/shared/deprecations'
import { Animated } from './Animated'
import { AnimatedObject, toPayload } from './AnimatedObject'
import { interpolate } from './interpolate'
import { to } from './interpolate'
import invariant from 'tiny-invariant'

@@ -30,6 +31,13 @@

to<Out extends Animatable>(
...args: InterpolatorArgs<any[], Out>
): SpringValue<Out> {
return (to as any)(this, ...args)
}
interpolate<Out extends Animatable>(
...args: InterpolatorArgs<any[], Out>
): SpringValue<Out> {
return (interpolate as any)(this, ...args)
deprecateInterpolate()
return this.to(...args)
}

@@ -36,0 +44,0 @@

@@ -13,4 +13,5 @@ import {

} from '@react-spring/shared'
import { deprecateInterpolate } from '@react-spring/shared/deprecations'
import { Animated } from './Animated'
import { interpolate } from './interpolate'
import { to } from './interpolate'
import { toPayload, addChild, removeChild } from './AnimatedObject'

@@ -38,6 +39,11 @@

to<T extends Animatable>(...args: InterpolatorArgs<Out, T>): SpringValue<T> {
return (to as any)(this, ...args)
}
interpolate<T extends Animatable>(
...args: InterpolatorArgs<Out, T>
): SpringValue<T> {
return (interpolate as any)(this, ...args)
deprecateInterpolate()
return this.to(...args)
}

@@ -44,0 +50,0 @@

import { Animatable, SpringValue, InterpolatorArgs, is, each } from '@react-spring/shared'
import { AnimatedProps } from './AnimatedProps'
import { interpolate } from './interpolate'
import { to } from './interpolate'
import { Animated } from './Animated'
import { deprecateInterpolate } from '@react-spring/shared/deprecations'
import * as G from '@react-spring/shared/globals'

@@ -44,6 +45,13 @@

to<Out extends Animatable>(
...args: InterpolatorArgs<T, Out>
): SpringValue<Out> {
return (to as any)(this, ...args)
}
interpolate<Out extends Animatable>(
...args: InterpolatorArgs<T, Out>
): SpringValue<Out> {
return (interpolate as any)(this, ...args)
deprecateInterpolate()
return this.to(...args)
}

@@ -50,0 +58,0 @@

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

export { createAnimatedInterpolation as interpolate } from '@react-spring/shared/globals'
import { SpringInterpolator } from '@react-spring/shared'
import { createAnimatedInterpolation as to } from '@react-spring/shared/globals'
import { deprecateInterpolate } from '@react-spring/shared/deprecations'
const interpolate: SpringInterpolator = (...args: [any, any]) => {
deprecateInterpolate()
return to(...args)
}
export { to, interpolate }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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