templates/miniprogram/miniprogram_npm/@react-spring/animated/index.js

834 lines
21 KiB
JavaScript

module.exports = (function() {
var __MODS__ = {};
var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
__DEFINE__(1656641689784, function(require, module, exports) {
if (process.env.NODE_ENV === "production") {
module.exports = require("./react-spring-animated.cjs.prod.js");
} else {
module.exports = require("./react-spring-animated.cjs.dev.js");
}
}, function(modId) {var map = {"./react-spring-animated.cjs.prod.js":1656641689785,"./react-spring-animated.cjs.dev.js":1656641689786}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1656641689785, function(require, module, exports) {
Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@react-spring/shared');
var React = require('react');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
const $node = Symbol.for('Animated:node');
const isAnimated = value => !!value && value[$node] === value;
const getAnimated = owner => owner && owner[$node];
const setAnimated = (owner, node) => shared.defineHidden(owner, $node, node);
const getPayload = owner => owner && owner[$node] && owner[$node].getPayload();
class Animated {
constructor() {
this.payload = void 0;
setAnimated(this, this);
}
getPayload() {
return this.payload || [];
}
}
class AnimatedValue extends Animated {
constructor(_value) {
super();
this.done = true;
this.elapsedTime = void 0;
this.lastPosition = void 0;
this.lastVelocity = void 0;
this.v0 = void 0;
this.durationProgress = 0;
this._value = _value;
if (shared.is.num(this._value)) {
this.lastPosition = this._value;
}
}
static create(value) {
return new AnimatedValue(value);
}
getPayload() {
return [this];
}
getValue() {
return this._value;
}
setValue(value, step) {
if (shared.is.num(value)) {
this.lastPosition = value;
if (step) {
value = Math.round(value / step) * step;
if (this.done) {
this.lastPosition = value;
}
}
}
if (this._value === value) {
return false;
}
this._value = value;
return true;
}
reset() {
const {
done
} = this;
this.done = false;
if (shared.is.num(this._value)) {
this.elapsedTime = 0;
this.durationProgress = 0;
this.lastPosition = this._value;
if (done) this.lastVelocity = null;
this.v0 = null;
}
}
}
class AnimatedString extends AnimatedValue {
constructor(value) {
super(0);
this._string = null;
this._toString = void 0;
this._toString = shared.createInterpolator({
output: [value, value]
});
}
static create(value) {
return new AnimatedString(value);
}
getValue() {
let value = this._string;
return value == null ? this._string = this._toString(this._value) : value;
}
setValue(value) {
if (shared.is.str(value)) {
if (value == this._string) {
return false;
}
this._string = value;
this._value = 1;
} else if (super.setValue(value)) {
this._string = null;
} else {
return false;
}
return true;
}
reset(goal) {
if (goal) {
this._toString = shared.createInterpolator({
output: [this.getValue(), goal]
});
}
this._value = 0;
super.reset();
}
}
const TreeContext = {
dependencies: null
};
class AnimatedObject extends Animated {
constructor(source) {
super();
this.source = source;
this.setValue(source);
}
getValue(animated) {
const values = {};
shared.eachProp(this.source, (source, key) => {
if (isAnimated(source)) {
values[key] = source.getValue(animated);
} else if (shared.hasFluidValue(source)) {
values[key] = shared.getFluidValue(source);
} else if (!animated) {
values[key] = source;
}
});
return values;
}
setValue(source) {
this.source = source;
this.payload = this._makePayload(source);
}
reset() {
if (this.payload) {
shared.each(this.payload, node => node.reset());
}
}
_makePayload(source) {
if (source) {
const payload = new Set();
shared.eachProp(source, this._addToPayload, payload);
return Array.from(payload);
}
}
_addToPayload(source) {
if (TreeContext.dependencies && shared.hasFluidValue(source)) {
TreeContext.dependencies.add(source);
}
const payload = getPayload(source);
if (payload) {
shared.each(payload, node => this.add(node));
}
}
}
class AnimatedArray extends AnimatedObject {
constructor(source) {
super(source);
}
static create(source) {
return new AnimatedArray(source);
}
getValue() {
return this.source.map(node => node.getValue());
}
setValue(source) {
const payload = this.getPayload();
if (source.length == payload.length) {
return payload.map((node, i) => node.setValue(source[i])).some(Boolean);
}
super.setValue(source.map(makeAnimated));
return true;
}
}
function makeAnimated(value) {
const nodeType = shared.isAnimatedString(value) ? AnimatedString : AnimatedValue;
return nodeType.create(value);
}
function getAnimatedType(value) {
const parentNode = getAnimated(value);
return parentNode ? parentNode.constructor : shared.is.arr(value) ? AnimatedArray : shared.isAnimatedString(value) ? AnimatedString : AnimatedValue;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
const withAnimated = (Component, host) => {
const hasInstance = !shared.is.fun(Component) || Component.prototype && Component.prototype.isReactComponent;
return React.forwardRef((givenProps, givenRef) => {
const instanceRef = React.useRef(null);
const ref = hasInstance && React.useCallback(value => {
instanceRef.current = updateRef(givenRef, value);
}, [givenRef]);
const [props, deps] = getAnimatedState(givenProps, host);
const forceUpdate = shared.useForceUpdate();
const callback = () => {
const instance = instanceRef.current;
if (hasInstance && !instance) {
return;
}
const didUpdate = instance ? host.applyAnimatedValues(instance, props.getValue(true)) : false;
if (didUpdate === false) {
forceUpdate();
}
};
const observer = new PropsObserver(callback, deps);
const observerRef = React.useRef();
shared.useLayoutEffect(() => {
observerRef.current = observer;
shared.each(deps, dep => shared.addFluidObserver(dep, observer));
return () => {
if (observerRef.current) {
shared.each(observerRef.current.deps, dep => shared.removeFluidObserver(dep, observerRef.current));
shared.raf.cancel(observerRef.current.update);
}
};
});
React.useEffect(callback, []);
shared.useOnce(() => () => {
const observer = observerRef.current;
shared.each(observer.deps, dep => shared.removeFluidObserver(dep, observer));
});
const usedProps = host.getComponentProps(props.getValue());
return React__namespace.createElement(Component, _extends({}, usedProps, {
ref: ref
}));
});
};
class PropsObserver {
constructor(update, deps) {
this.update = update;
this.deps = deps;
}
eventObserved(event) {
if (event.type == 'change') {
shared.raf.write(this.update);
}
}
}
function getAnimatedState(props, host) {
const dependencies = new Set();
TreeContext.dependencies = dependencies;
if (props.style) props = _extends({}, props, {
style: host.createAnimatedStyle(props.style)
});
props = new AnimatedObject(props);
TreeContext.dependencies = null;
return [props, dependencies];
}
function updateRef(ref, value) {
if (ref) {
if (shared.is.fun(ref)) ref(value);else ref.current = value;
}
return value;
}
const cacheKey = Symbol.for('AnimatedComponent');
const createHost = (components, {
applyAnimatedValues: _applyAnimatedValues = () => false,
createAnimatedStyle: _createAnimatedStyle = style => new AnimatedObject(style),
getComponentProps: _getComponentProps = props => props
} = {}) => {
const hostConfig = {
applyAnimatedValues: _applyAnimatedValues,
createAnimatedStyle: _createAnimatedStyle,
getComponentProps: _getComponentProps
};
const animated = Component => {
const displayName = getDisplayName(Component) || 'Anonymous';
if (shared.is.str(Component)) {
Component = animated[Component] || (animated[Component] = withAnimated(Component, hostConfig));
} else {
Component = Component[cacheKey] || (Component[cacheKey] = withAnimated(Component, hostConfig));
}
Component.displayName = `Animated(${displayName})`;
return Component;
};
shared.eachProp(components, (Component, key) => {
if (shared.is.arr(components)) {
key = getDisplayName(Component);
}
animated[key] = animated(Component);
});
return {
animated
};
};
const getDisplayName = arg => shared.is.str(arg) ? arg : arg && shared.is.str(arg.displayName) ? arg.displayName : shared.is.fun(arg) && arg.name || null;
exports.Animated = Animated;
exports.AnimatedArray = AnimatedArray;
exports.AnimatedObject = AnimatedObject;
exports.AnimatedString = AnimatedString;
exports.AnimatedValue = AnimatedValue;
exports.createHost = createHost;
exports.getAnimated = getAnimated;
exports.getAnimatedType = getAnimatedType;
exports.getPayload = getPayload;
exports.isAnimated = isAnimated;
exports.setAnimated = setAnimated;
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1656641689786, function(require, module, exports) {
Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@react-spring/shared');
var React = require('react');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
const $node = Symbol.for('Animated:node');
const isAnimated = value => !!value && value[$node] === value;
const getAnimated = owner => owner && owner[$node];
const setAnimated = (owner, node) => shared.defineHidden(owner, $node, node);
const getPayload = owner => owner && owner[$node] && owner[$node].getPayload();
class Animated {
constructor() {
this.payload = void 0;
setAnimated(this, this);
}
getPayload() {
return this.payload || [];
}
}
class AnimatedValue extends Animated {
constructor(_value) {
super();
this.done = true;
this.elapsedTime = void 0;
this.lastPosition = void 0;
this.lastVelocity = void 0;
this.v0 = void 0;
this.durationProgress = 0;
this._value = _value;
if (shared.is.num(this._value)) {
this.lastPosition = this._value;
}
}
static create(value) {
return new AnimatedValue(value);
}
getPayload() {
return [this];
}
getValue() {
return this._value;
}
setValue(value, step) {
if (shared.is.num(value)) {
this.lastPosition = value;
if (step) {
value = Math.round(value / step) * step;
if (this.done) {
this.lastPosition = value;
}
}
}
if (this._value === value) {
return false;
}
this._value = value;
return true;
}
reset() {
const {
done
} = this;
this.done = false;
if (shared.is.num(this._value)) {
this.elapsedTime = 0;
this.durationProgress = 0;
this.lastPosition = this._value;
if (done) this.lastVelocity = null;
this.v0 = null;
}
}
}
class AnimatedString extends AnimatedValue {
constructor(value) {
super(0);
this._string = null;
this._toString = void 0;
this._toString = shared.createInterpolator({
output: [value, value]
});
}
static create(value) {
return new AnimatedString(value);
}
getValue() {
let value = this._string;
return value == null ? this._string = this._toString(this._value) : value;
}
setValue(value) {
if (shared.is.str(value)) {
if (value == this._string) {
return false;
}
this._string = value;
this._value = 1;
} else if (super.setValue(value)) {
this._string = null;
} else {
return false;
}
return true;
}
reset(goal) {
if (goal) {
this._toString = shared.createInterpolator({
output: [this.getValue(), goal]
});
}
this._value = 0;
super.reset();
}
}
const TreeContext = {
dependencies: null
};
class AnimatedObject extends Animated {
constructor(source) {
super();
this.source = source;
this.setValue(source);
}
getValue(animated) {
const values = {};
shared.eachProp(this.source, (source, key) => {
if (isAnimated(source)) {
values[key] = source.getValue(animated);
} else if (shared.hasFluidValue(source)) {
values[key] = shared.getFluidValue(source);
} else if (!animated) {
values[key] = source;
}
});
return values;
}
setValue(source) {
this.source = source;
this.payload = this._makePayload(source);
}
reset() {
if (this.payload) {
shared.each(this.payload, node => node.reset());
}
}
_makePayload(source) {
if (source) {
const payload = new Set();
shared.eachProp(source, this._addToPayload, payload);
return Array.from(payload);
}
}
_addToPayload(source) {
if (TreeContext.dependencies && shared.hasFluidValue(source)) {
TreeContext.dependencies.add(source);
}
const payload = getPayload(source);
if (payload) {
shared.each(payload, node => this.add(node));
}
}
}
class AnimatedArray extends AnimatedObject {
constructor(source) {
super(source);
}
static create(source) {
return new AnimatedArray(source);
}
getValue() {
return this.source.map(node => node.getValue());
}
setValue(source) {
const payload = this.getPayload();
if (source.length == payload.length) {
return payload.map((node, i) => node.setValue(source[i])).some(Boolean);
}
super.setValue(source.map(makeAnimated));
return true;
}
}
function makeAnimated(value) {
const nodeType = shared.isAnimatedString(value) ? AnimatedString : AnimatedValue;
return nodeType.create(value);
}
function getAnimatedType(value) {
const parentNode = getAnimated(value);
return parentNode ? parentNode.constructor : shared.is.arr(value) ? AnimatedArray : shared.isAnimatedString(value) ? AnimatedString : AnimatedValue;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
const withAnimated = (Component, host) => {
const hasInstance = !shared.is.fun(Component) || Component.prototype && Component.prototype.isReactComponent;
return React.forwardRef((givenProps, givenRef) => {
const instanceRef = React.useRef(null);
const ref = hasInstance && React.useCallback(value => {
instanceRef.current = updateRef(givenRef, value);
}, [givenRef]);
const [props, deps] = getAnimatedState(givenProps, host);
const forceUpdate = shared.useForceUpdate();
const callback = () => {
const instance = instanceRef.current;
if (hasInstance && !instance) {
return;
}
const didUpdate = instance ? host.applyAnimatedValues(instance, props.getValue(true)) : false;
if (didUpdate === false) {
forceUpdate();
}
};
const observer = new PropsObserver(callback, deps);
const observerRef = React.useRef();
shared.useLayoutEffect(() => {
observerRef.current = observer;
shared.each(deps, dep => shared.addFluidObserver(dep, observer));
return () => {
if (observerRef.current) {
shared.each(observerRef.current.deps, dep => shared.removeFluidObserver(dep, observerRef.current));
shared.raf.cancel(observerRef.current.update);
}
};
});
React.useEffect(callback, []);
shared.useOnce(() => () => {
const observer = observerRef.current;
shared.each(observer.deps, dep => shared.removeFluidObserver(dep, observer));
});
const usedProps = host.getComponentProps(props.getValue());
return React__namespace.createElement(Component, _extends({}, usedProps, {
ref: ref
}));
});
};
class PropsObserver {
constructor(update, deps) {
this.update = update;
this.deps = deps;
}
eventObserved(event) {
if (event.type == 'change') {
shared.raf.write(this.update);
}
}
}
function getAnimatedState(props, host) {
const dependencies = new Set();
TreeContext.dependencies = dependencies;
if (props.style) props = _extends({}, props, {
style: host.createAnimatedStyle(props.style)
});
props = new AnimatedObject(props);
TreeContext.dependencies = null;
return [props, dependencies];
}
function updateRef(ref, value) {
if (ref) {
if (shared.is.fun(ref)) ref(value);else ref.current = value;
}
return value;
}
const cacheKey = Symbol.for('AnimatedComponent');
const createHost = (components, {
applyAnimatedValues: _applyAnimatedValues = () => false,
createAnimatedStyle: _createAnimatedStyle = style => new AnimatedObject(style),
getComponentProps: _getComponentProps = props => props
} = {}) => {
const hostConfig = {
applyAnimatedValues: _applyAnimatedValues,
createAnimatedStyle: _createAnimatedStyle,
getComponentProps: _getComponentProps
};
const animated = Component => {
const displayName = getDisplayName(Component) || 'Anonymous';
if (shared.is.str(Component)) {
Component = animated[Component] || (animated[Component] = withAnimated(Component, hostConfig));
} else {
Component = Component[cacheKey] || (Component[cacheKey] = withAnimated(Component, hostConfig));
}
Component.displayName = `Animated(${displayName})`;
return Component;
};
shared.eachProp(components, (Component, key) => {
if (shared.is.arr(components)) {
key = getDisplayName(Component);
}
animated[key] = animated(Component);
});
return {
animated
};
};
const getDisplayName = arg => shared.is.str(arg) ? arg : arg && shared.is.str(arg.displayName) ? arg.displayName : shared.is.fun(arg) && arg.name || null;
exports.Animated = Animated;
exports.AnimatedArray = AnimatedArray;
exports.AnimatedObject = AnimatedObject;
exports.AnimatedString = AnimatedString;
exports.AnimatedValue = AnimatedValue;
exports.createHost = createHost;
exports.getAnimated = getAnimated;
exports.getAnimatedType = getAnimatedType;
exports.getPayload = getPayload;
exports.isAnimated = isAnimated;
exports.setAnimated = setAnimated;
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
return __REQUIRE__(1656641689784);
})()
//miniprogram-npm-outsideDeps=["@react-spring/shared","react"]
//# sourceMappingURL=index.js.map