@animini/core
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -5,4 +5,37 @@ 'use strict'; | ||
var lerp = require('../../dist/lerp-d42f3733.cjs.dev.js'); | ||
var lerp = require('../../dist/lerp-6bec8f39.cjs.dev.js'); | ||
function spring({ | ||
tension: k = 170, | ||
friction: c = 26, | ||
mass: m = 1, | ||
velocity | ||
} = {}) { | ||
const zeta = c / (2 * Math.sqrt(k * m)); | ||
const w0 = Math.sqrt(k / m) * 0.001; | ||
const w1 = w0 * Math.sqrt(1.0 - zeta * zeta); | ||
return { | ||
update(a) { | ||
const t = a.time.elapsed; | ||
const v0 = velocity !== null && velocity !== void 0 ? velocity : a.startVelocity; | ||
const { | ||
to, | ||
distance: x0 | ||
} = a; | ||
let value; | ||
if (zeta < 1) { | ||
const envelope = Math.exp(-zeta * w0 * t); | ||
value = to - envelope * ((-v0 + zeta * w0 * x0) / w1 * Math.sin(w1 * t) + x0 * Math.cos(w1 * t)); | ||
} else { | ||
const envelope = Math.exp(-w0 * t); | ||
value = to - envelope * (x0 + (-v0 + w0 * x0) * t); | ||
} | ||
return value; | ||
} | ||
}; | ||
} | ||
const NEWTON_ITERATIONS = 4; | ||
@@ -132,3 +165,3 @@ const NEWTON_MIN_SLOPE = 0.001; | ||
} = {}) { | ||
const springEase = lerp.spring(); | ||
const springEase = spring(); | ||
return { | ||
@@ -158,4 +191,4 @@ wanders: true, | ||
exports.lerp = lerp.lerp; | ||
exports.spring = lerp.spring; | ||
exports.ease = ease; | ||
exports.inertia = inertia; | ||
exports.spring = spring; |
@@ -5,4 +5,37 @@ 'use strict'; | ||
var lerp = require('../../dist/lerp-65d16c52.cjs.prod.js'); | ||
var lerp = require('../../dist/lerp-de136b1e.cjs.prod.js'); | ||
function spring({ | ||
tension: k = 170, | ||
friction: c = 26, | ||
mass: m = 1, | ||
velocity | ||
} = {}) { | ||
const zeta = c / (2 * Math.sqrt(k * m)); | ||
const w0 = Math.sqrt(k / m) * 0.001; | ||
const w1 = w0 * Math.sqrt(1.0 - zeta * zeta); | ||
return { | ||
update(a) { | ||
const t = a.time.elapsed; | ||
const v0 = velocity !== null && velocity !== void 0 ? velocity : a.startVelocity; | ||
const { | ||
to, | ||
distance: x0 | ||
} = a; | ||
let value; | ||
if (zeta < 1) { | ||
const envelope = Math.exp(-zeta * w0 * t); | ||
value = to - envelope * ((-v0 + zeta * w0 * x0) / w1 * Math.sin(w1 * t) + x0 * Math.cos(w1 * t)); | ||
} else { | ||
const envelope = Math.exp(-w0 * t); | ||
value = to - envelope * (x0 + (-v0 + w0 * x0) * t); | ||
} | ||
return value; | ||
} | ||
}; | ||
} | ||
const NEWTON_ITERATIONS = 4; | ||
@@ -132,3 +165,3 @@ const NEWTON_MIN_SLOPE = 0.001; | ||
} = {}) { | ||
const springEase = lerp.spring(); | ||
const springEase = spring(); | ||
return { | ||
@@ -158,4 +191,4 @@ wanders: true, | ||
exports.lerp = lerp.lerp; | ||
exports.spring = lerp.spring; | ||
exports.ease = ease; | ||
exports.inertia = inertia; | ||
exports.spring = spring; |
@@ -1,4 +0,37 @@ | ||
import { a as lerp, r as rubberbandIfOutOfBounds, s as spring } from '../../dist/lerp-cd1f0aee.esm.js'; | ||
export { l as lerp, s as spring } from '../../dist/lerp-cd1f0aee.esm.js'; | ||
import { a as lerp, r as rubberbandIfOutOfBounds } from '../../dist/lerp-839ad04d.esm.js'; | ||
export { l as lerp } from '../../dist/lerp-839ad04d.esm.js'; | ||
function spring({ | ||
tension: k = 170, | ||
friction: c = 26, | ||
mass: m = 1, | ||
velocity | ||
} = {}) { | ||
const zeta = c / (2 * Math.sqrt(k * m)); | ||
const w0 = Math.sqrt(k / m) * 0.001; | ||
const w1 = w0 * Math.sqrt(1.0 - zeta * zeta); | ||
return { | ||
update(a) { | ||
const t = a.time.elapsed; | ||
const v0 = velocity !== null && velocity !== void 0 ? velocity : a.startVelocity; | ||
const { | ||
to, | ||
distance: x0 | ||
} = a; | ||
let value; | ||
if (zeta < 1) { | ||
const envelope = Math.exp(-zeta * w0 * t); | ||
value = to - envelope * ((-v0 + zeta * w0 * x0) / w1 * Math.sin(w1 * t) + x0 * Math.cos(w1 * t)); | ||
} else { | ||
const envelope = Math.exp(-w0 * t); | ||
value = to - envelope * (x0 + (-v0 + w0 * x0) * t); | ||
} | ||
return value; | ||
} | ||
}; | ||
} | ||
const NEWTON_ITERATIONS = 4; | ||
@@ -152,2 +185,2 @@ const NEWTON_MIN_SLOPE = 0.001; | ||
export { ease, inertia }; | ||
export { ease, inertia, spring }; |
# @animini/core | ||
## 0.2.0 | ||
### Minor Changes | ||
- 10ba638: Refactor package | ||
## 0.1.4 | ||
@@ -4,0 +10,0 @@ |
@@ -5,4 +5,3 @@ 'use strict'; | ||
var react = require('react'); | ||
var lerp = require('./lerp-d42f3733.cjs.dev.js'); | ||
var lerp = require('./lerp-6bec8f39.cjs.dev.js'); | ||
@@ -296,94 +295,97 @@ function _defineProperty(obj, key, value) { | ||
function useAniminiCore(target, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = react.useRef(null); | ||
const rawValues = react.useRef({}); | ||
const animations = react.useMemo(() => new Map(), []); | ||
const resolveRef = react.useRef(); | ||
const rejectRef = react.useRef(); | ||
const configRef = react.useRef(masterConfig); | ||
configRef.current = masterConfig; | ||
const update = react.useCallback(() => { | ||
var _target$setValues; | ||
function buildAnimate(target) { | ||
return function animate(element, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = typeof element === 'object' && 'current' in element ? element : { | ||
current: element | ||
}; | ||
const values = {}; | ||
const animations = new Map(); | ||
let resolveRef; | ||
let rejectRef; | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
const update = () => { | ||
var _target$setValues; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
rawValues.current[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, rawValues.current, el.current, currentValues); | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
if (idle) { | ||
var _resolveRef$current; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
values[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, values, el.current, currentValues); | ||
loop.stop(update); | ||
(_resolveRef$current = resolveRef.current) === null || _resolveRef$current === void 0 ? void 0 : _resolveRef$current.call(resolveRef); | ||
} | ||
}, [target, animations]); | ||
const start = react.useCallback((to, config = configRef.current) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef.current = resolve; | ||
rejectRef.current = reject; | ||
let idle = true; | ||
if (idle) { | ||
loop.stop(update); | ||
resolveRef(); | ||
} | ||
}; | ||
for (let key in to) { | ||
var _adapter2; | ||
const start = (to, config = masterConfig) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef = resolve; | ||
rejectRef = reject; | ||
let idle = true; | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
for (let key in to) { | ||
var _adapter2; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!idle) loop.start(update);else resolveRef.current(); | ||
}); | ||
}, [update, animations]); | ||
const stop = react.useCallback(() => { | ||
var _rejectRef$current; | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
loop.stop(update); | ||
(_rejectRef$current = rejectRef.current) === null || _rejectRef$current === void 0 ? void 0 : _rejectRef$current.call(rejectRef); | ||
}, [update]); | ||
react.useEffect(() => { | ||
return () => { | ||
var _resolveRef$current2; | ||
if (!idle) loop.start(update);else resolveRef(); | ||
}); | ||
}; | ||
const stop = () => { | ||
loop.stop(update); | ||
(_resolveRef$current2 = resolveRef.current) === null || _resolveRef$current2 === void 0 ? void 0 : _resolveRef$current2.call(resolveRef); | ||
rejectRef(); | ||
}; | ||
}, [update]); | ||
const get = react.useCallback(key => rawValues.current[key], []); | ||
const api = { | ||
get, | ||
start, | ||
stop | ||
const clean = () => { | ||
var _resolveRef; | ||
loop.stop(update); | ||
(_resolveRef = resolveRef) === null || _resolveRef === void 0 ? void 0 : _resolveRef(); | ||
}; | ||
const get = key => values[key]; | ||
const api = { | ||
get, | ||
start, | ||
stop, | ||
clean | ||
}; | ||
return api; | ||
}; | ||
return [el, api]; | ||
} | ||
@@ -394,5 +396,5 @@ | ||
exports.rubberbandIfOutOfBounds = lerp.rubberbandIfOutOfBounds; | ||
exports.spring = lerp.spring; | ||
exports.FrameLoop = FrameLoop; | ||
exports.GlobalLoop = GlobalLoop; | ||
exports.buildAnimate = buildAnimate; | ||
exports.each = each; | ||
@@ -404,2 +406,1 @@ exports.equal = equal; | ||
exports.substringMatch = substringMatch; | ||
exports.useAniminiCore = useAniminiCore; |
@@ -5,4 +5,3 @@ 'use strict'; | ||
var react = require('react'); | ||
var lerp = require('./lerp-65d16c52.cjs.prod.js'); | ||
var lerp = require('./lerp-de136b1e.cjs.prod.js'); | ||
@@ -296,94 +295,97 @@ function _defineProperty(obj, key, value) { | ||
function useAniminiCore(target, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = react.useRef(null); | ||
const rawValues = react.useRef({}); | ||
const animations = react.useMemo(() => new Map(), []); | ||
const resolveRef = react.useRef(); | ||
const rejectRef = react.useRef(); | ||
const configRef = react.useRef(masterConfig); | ||
configRef.current = masterConfig; | ||
const update = react.useCallback(() => { | ||
var _target$setValues; | ||
function buildAnimate(target) { | ||
return function animate(element, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = typeof element === 'object' && 'current' in element ? element : { | ||
current: element | ||
}; | ||
const values = {}; | ||
const animations = new Map(); | ||
let resolveRef; | ||
let rejectRef; | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
const update = () => { | ||
var _target$setValues; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
rawValues.current[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, rawValues.current, el.current, currentValues); | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
if (idle) { | ||
var _resolveRef$current; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
values[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, values, el.current, currentValues); | ||
loop.stop(update); | ||
(_resolveRef$current = resolveRef.current) === null || _resolveRef$current === void 0 ? void 0 : _resolveRef$current.call(resolveRef); | ||
} | ||
}, [target, animations]); | ||
const start = react.useCallback((to, config = configRef.current) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef.current = resolve; | ||
rejectRef.current = reject; | ||
let idle = true; | ||
if (idle) { | ||
loop.stop(update); | ||
resolveRef(); | ||
} | ||
}; | ||
for (let key in to) { | ||
var _adapter2; | ||
const start = (to, config = masterConfig) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef = resolve; | ||
rejectRef = reject; | ||
let idle = true; | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
for (let key in to) { | ||
var _adapter2; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!idle) loop.start(update);else resolveRef.current(); | ||
}); | ||
}, [update, animations]); | ||
const stop = react.useCallback(() => { | ||
var _rejectRef$current; | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
loop.stop(update); | ||
(_rejectRef$current = rejectRef.current) === null || _rejectRef$current === void 0 ? void 0 : _rejectRef$current.call(rejectRef); | ||
}, [update]); | ||
react.useEffect(() => { | ||
return () => { | ||
var _resolveRef$current2; | ||
if (!idle) loop.start(update);else resolveRef(); | ||
}); | ||
}; | ||
const stop = () => { | ||
loop.stop(update); | ||
(_resolveRef$current2 = resolveRef.current) === null || _resolveRef$current2 === void 0 ? void 0 : _resolveRef$current2.call(resolveRef); | ||
rejectRef(); | ||
}; | ||
}, [update]); | ||
const get = react.useCallback(key => rawValues.current[key], []); | ||
const api = { | ||
get, | ||
start, | ||
stop | ||
const clean = () => { | ||
var _resolveRef; | ||
loop.stop(update); | ||
(_resolveRef = resolveRef) === null || _resolveRef === void 0 ? void 0 : _resolveRef(); | ||
}; | ||
const get = key => values[key]; | ||
const api = { | ||
get, | ||
start, | ||
stop, | ||
clean | ||
}; | ||
return api; | ||
}; | ||
return [el, api]; | ||
} | ||
@@ -394,5 +396,5 @@ | ||
exports.rubberbandIfOutOfBounds = lerp.rubberbandIfOutOfBounds; | ||
exports.spring = lerp.spring; | ||
exports.FrameLoop = FrameLoop; | ||
exports.GlobalLoop = GlobalLoop; | ||
exports.buildAnimate = buildAnimate; | ||
exports.each = each; | ||
@@ -404,2 +406,1 @@ exports.equal = equal; | ||
exports.substringMatch = substringMatch; | ||
exports.useAniminiCore = useAniminiCore; |
@@ -1,4 +0,3 @@ | ||
import { useRef, useMemo, useCallback, useEffect } from 'react'; | ||
import { c as clamp, l as lerp } from './lerp-cd1f0aee.esm.js'; | ||
export { c as clamp, a as lerp, r as rubberbandIfOutOfBounds, s as spring } from './lerp-cd1f0aee.esm.js'; | ||
import { c as clamp, l as lerp } from './lerp-839ad04d.esm.js'; | ||
export { c as clamp, a as lerp, r as rubberbandIfOutOfBounds } from './lerp-839ad04d.esm.js'; | ||
@@ -292,96 +291,99 @@ function _defineProperty(obj, key, value) { | ||
function useAniminiCore(target, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = useRef(null); | ||
const rawValues = useRef({}); | ||
const animations = useMemo(() => new Map(), []); | ||
const resolveRef = useRef(); | ||
const rejectRef = useRef(); | ||
const configRef = useRef(masterConfig); | ||
configRef.current = masterConfig; | ||
const update = useCallback(() => { | ||
var _target$setValues; | ||
function buildAnimate(target) { | ||
return function animate(element, currentValues, masterConfig) { | ||
const loop = target.loop || GlobalLoop; | ||
const el = typeof element === 'object' && 'current' in element ? element : { | ||
current: element | ||
}; | ||
const values = {}; | ||
const animations = new Map(); | ||
let resolveRef; | ||
let rejectRef; | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
const update = () => { | ||
var _target$setValues; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
rawValues.current[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, rawValues.current, el.current, currentValues); | ||
if (!el.current) return; | ||
let idle = true; | ||
animations.forEach(({ | ||
animated, | ||
adapter | ||
}, key) => { | ||
var _adapter$onChange; | ||
if (idle) { | ||
var _resolveRef$current; | ||
animated.update(); | ||
const value = adapter !== null && adapter !== void 0 && adapter.format ? adapter.format(animated.value) : animated.value; | ||
values[key] = value; | ||
adapter === null || adapter === void 0 ? void 0 : (_adapter$onChange = adapter.onChange) === null || _adapter$onChange === void 0 ? void 0 : _adapter$onChange.call(adapter, value, key, el.current, currentValues); | ||
idle && (idle = animated.idle); | ||
}); | ||
(_target$setValues = target.setValues) === null || _target$setValues === void 0 ? void 0 : _target$setValues.call(target, values, el.current, currentValues); | ||
loop.stop(update); | ||
(_resolveRef$current = resolveRef.current) === null || _resolveRef$current === void 0 ? void 0 : _resolveRef$current.call(resolveRef); | ||
} | ||
}, [target, animations]); | ||
const start = useCallback((to, config = configRef.current) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef.current = resolve; | ||
rejectRef.current = reject; | ||
let idle = true; | ||
if (idle) { | ||
loop.stop(update); | ||
resolveRef(); | ||
} | ||
}; | ||
for (let key in to) { | ||
var _adapter2; | ||
const start = (to, config = masterConfig) => { | ||
return new Promise((resolve, reject) => { | ||
resolveRef = resolve; | ||
rejectRef = reject; | ||
let idle = true; | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
for (let key in to) { | ||
var _adapter2; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
const animation = animations.get(key); | ||
let animated; | ||
let adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, currentValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, currentValues) : _value; | ||
animated = new Animated(value, loop); | ||
adapter = _adapter; | ||
animations.set(key, { | ||
animated, | ||
adapter | ||
}); | ||
} else { | ||
animated = animation.animated; | ||
adapter = animation.adapter; | ||
} | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, currentValues) : to[key]; | ||
if (!idle) loop.start(update);else resolveRef.current(); | ||
}); | ||
}, [update, animations]); | ||
const stop = useCallback(() => { | ||
var _rejectRef$current; | ||
animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
idle && (idle = animated.idle); | ||
} | ||
loop.stop(update); | ||
(_rejectRef$current = rejectRef.current) === null || _rejectRef$current === void 0 ? void 0 : _rejectRef$current.call(rejectRef); | ||
}, [update]); | ||
useEffect(() => { | ||
return () => { | ||
var _resolveRef$current2; | ||
if (!idle) loop.start(update);else resolveRef(); | ||
}); | ||
}; | ||
const stop = () => { | ||
loop.stop(update); | ||
(_resolveRef$current2 = resolveRef.current) === null || _resolveRef$current2 === void 0 ? void 0 : _resolveRef$current2.call(resolveRef); | ||
rejectRef(); | ||
}; | ||
}, [update]); | ||
const get = useCallback(key => rawValues.current[key], []); | ||
const api = { | ||
get, | ||
start, | ||
stop | ||
const clean = () => { | ||
var _resolveRef; | ||
loop.stop(update); | ||
(_resolveRef = resolveRef) === null || _resolveRef === void 0 ? void 0 : _resolveRef(); | ||
}; | ||
const get = key => values[key]; | ||
const api = { | ||
get, | ||
start, | ||
stop, | ||
clean | ||
}; | ||
return api; | ||
}; | ||
return [el, api]; | ||
} | ||
export { FrameLoop, GlobalLoop, each, equal, map, parseColor, parseUnitValue, substringMatch, useAniminiCore }; | ||
export { FrameLoop, GlobalLoop, buildAnimate, each, equal, map, parseColor, parseUnitValue, substringMatch }; |
@@ -1,5 +0,4 @@ | ||
export { useAniminiCore } from './useAniminiCore'; | ||
export { spring } from './algorithms/spring'; | ||
export { buildAnimate } from './buildAnimate'; | ||
export * from './utils'; | ||
export * from './FrameLoop'; | ||
export * from './types'; |
{ | ||
"name": "@animini/core", | ||
"version": "0.1.4", | ||
"description": "small animation lib", | ||
"version": "0.2.0", | ||
"description": "Core of animini", | ||
"keywords": [], | ||
@@ -20,6 +20,3 @@ "main": "dist/animini-core.cjs.js", | ||
}, | ||
"bugs": "https://github.com/dbismut/animini/issues", | ||
"peerDependencies": { | ||
"react": ">=16.8.0" | ||
} | ||
"bugs": "https://github.com/dbismut/animini/issues" | ||
} |
@@ -1,5 +0,4 @@ | ||
export { useAniminiCore } from './useAniminiCore' | ||
export { spring } from './algorithms/spring' | ||
export { buildAnimate } from './buildAnimate' | ||
export * from './utils' | ||
export * from './FrameLoop' | ||
export * from './types' |
0
72268
2214