@animini/core
Advanced tools
Comparing version 0.2.2 to 0.2.3
# @animini/core | ||
## 0.2.3 | ||
### Patch Changes | ||
- fd31840: Remove cached values | ||
## 0.2.2 | ||
@@ -4,0 +10,0 @@ |
@@ -294,6 +294,3 @@ 'use strict'; | ||
function buildAnimate({ | ||
target, | ||
syncCachedValues = false | ||
}) { | ||
function buildAnimate(target) { | ||
return function animate(element, masterConfig) { | ||
@@ -306,3 +303,2 @@ const loop = target.loop || GlobalLoop; | ||
const animations = new Map(); | ||
let cachedValues; | ||
let resolveRef; | ||
@@ -325,3 +321,3 @@ let rejectRef; | ||
currentValues[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, cachedValues); | ||
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); | ||
idle && (idle = animated.idle); | ||
@@ -351,4 +347,4 @@ }); | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, cachedValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, cachedValues) : _value; | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current) : _value; | ||
animated = new Animated(value, loop); | ||
@@ -365,3 +361,3 @@ adapter = _adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, cachedValues) : to[key]; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current) : to[key]; | ||
@@ -390,9 +386,2 @@ animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
const setCachedValues = () => { | ||
var _target$getCurrentVal; | ||
cachedValues = (_target$getCurrentVal = target.getCurrentValues) === null || _target$getCurrentVal === void 0 ? void 0 : _target$getCurrentVal.call(target, el.current); | ||
}; | ||
if (syncCachedValues) setCachedValues(); | ||
const api = { | ||
@@ -402,4 +391,3 @@ get, | ||
stop, | ||
clean, | ||
setCachedValues | ||
clean | ||
}; | ||
@@ -406,0 +394,0 @@ return api; |
@@ -294,6 +294,3 @@ 'use strict'; | ||
function buildAnimate({ | ||
target, | ||
syncCachedValues = false | ||
}) { | ||
function buildAnimate(target) { | ||
return function animate(element, masterConfig) { | ||
@@ -306,3 +303,2 @@ const loop = target.loop || GlobalLoop; | ||
const animations = new Map(); | ||
let cachedValues; | ||
let resolveRef; | ||
@@ -325,3 +321,3 @@ let rejectRef; | ||
currentValues[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, cachedValues); | ||
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); | ||
idle && (idle = animated.idle); | ||
@@ -351,4 +347,4 @@ }); | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, cachedValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, cachedValues) : _value; | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current) : _value; | ||
animated = new Animated(value, loop); | ||
@@ -365,3 +361,3 @@ adapter = _adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, cachedValues) : to[key]; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current) : to[key]; | ||
@@ -390,9 +386,2 @@ animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
const setCachedValues = () => { | ||
var _target$getCurrentVal; | ||
cachedValues = (_target$getCurrentVal = target.getCurrentValues) === null || _target$getCurrentVal === void 0 ? void 0 : _target$getCurrentVal.call(target, el.current); | ||
}; | ||
if (syncCachedValues) setCachedValues(); | ||
const api = { | ||
@@ -402,4 +391,3 @@ get, | ||
stop, | ||
clean, | ||
setCachedValues | ||
clean | ||
}; | ||
@@ -406,0 +394,0 @@ return api; |
@@ -291,6 +291,3 @@ import { c as clamp, l as lerp } from './lerp-839ad04d.esm.js'; | ||
function buildAnimate({ | ||
target, | ||
syncCachedValues = false | ||
}) { | ||
function buildAnimate(target) { | ||
return function animate(element, masterConfig) { | ||
@@ -303,3 +300,2 @@ const loop = target.loop || GlobalLoop; | ||
const animations = new Map(); | ||
let cachedValues; | ||
let resolveRef; | ||
@@ -322,3 +318,3 @@ let rejectRef; | ||
currentValues[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, cachedValues); | ||
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); | ||
idle && (idle = animated.idle); | ||
@@ -348,4 +344,4 @@ }); | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, cachedValues); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current, cachedValues) : _value; | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key); | ||
const value = _adapter !== null && _adapter !== void 0 && _adapter.parseInitial ? _adapter === null || _adapter === void 0 ? void 0 : _adapter.parseInitial(_value, key, el.current) : _value; | ||
animated = new Animated(value, loop); | ||
@@ -362,3 +358,3 @@ adapter = _adapter; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current, cachedValues) : to[key]; | ||
const _to = (_adapter2 = adapter) !== null && _adapter2 !== void 0 && _adapter2.parse ? adapter.parse(to[key], key, el.current) : to[key]; | ||
@@ -387,9 +383,2 @@ animated.start(_to, typeof config === 'function' ? config(key) : config); | ||
const setCachedValues = () => { | ||
var _target$getCurrentVal; | ||
cachedValues = (_target$getCurrentVal = target.getCurrentValues) === null || _target$getCurrentVal === void 0 ? void 0 : _target$getCurrentVal.call(target, el.current); | ||
}; | ||
if (syncCachedValues) setCachedValues(); | ||
const api = { | ||
@@ -399,4 +388,3 @@ get, | ||
stop, | ||
clean, | ||
setCachedValues | ||
clean | ||
}; | ||
@@ -403,0 +391,0 @@ return api; |
import { Config, Payload, Target } from './types'; | ||
declare type Args<ElementType, ValueType extends Payload> = { | ||
target: Target<ElementType, ValueType>; | ||
syncCachedValues?: boolean; | ||
}; | ||
export declare function buildAnimate<ElementType, ValueType extends Payload>({ target, syncCachedValues }: Args<ElementType, ValueType>): (element: ElementType | { | ||
export declare function buildAnimate<ElementType, ValueType extends Payload>(target: Target<ElementType, ValueType>): (element: ElementType | { | ||
current: ElementType; | ||
@@ -13,4 +9,2 @@ }, masterConfig?: Config) => { | ||
clean: () => void; | ||
setCachedValues: () => void; | ||
}; | ||
export {}; |
import { AnimatedValue } from './animated/AnimatedValue'; | ||
import { FrameLoop } from './FrameLoop'; | ||
export declare type ParsedValue = number | number[] | Record<string, number>; | ||
export declare type AdapterFn<ElementType, R> = (value: any, key: string | number | symbol, target: ElementType | undefined | null, cachedValues: any) => R; | ||
export declare type AdapterFn<ElementType, R> = (value: any, key: string | number | symbol, target: ElementType | undefined | null) => R; | ||
export declare type Adapter<ElementType, ValueType extends Payload> = { | ||
@@ -22,5 +22,4 @@ parse?: AdapterFn<ElementType, ParsedValue>; | ||
loop?: FrameLoop; | ||
getCurrentValues?(element: ElementType): Record<string, any>; | ||
setValues?(rawValues: ValueType, element: ElementType): void; | ||
getInitialValueAndAdapter<K extends keyof ValueType>(element: ElementType, key: K, cachedValues?: any): [ValueType[K], Adapter<ElementType, ValueType> | undefined]; | ||
getInitialValueAndAdapter<K extends keyof ValueType>(element: ElementType, key: K): [ValueType[K], Adapter<ElementType, ValueType> | undefined]; | ||
}; | ||
@@ -27,0 +26,0 @@ export declare type ConfigValue = { |
{ | ||
"name": "@animini/core", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Core of animini", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -15,11 +15,3 @@ import { Animated } from './animated/Animated' | ||
type Args<ElementType, ValueType extends Payload> = { | ||
target: Target<ElementType, ValueType> | ||
syncCachedValues?: boolean | ||
} | ||
export function buildAnimate<ElementType, ValueType extends Payload>({ | ||
target, | ||
syncCachedValues = false | ||
}: Args<ElementType, ValueType>) { | ||
export function buildAnimate<ElementType, ValueType extends Payload>(target: Target<ElementType, ValueType>) { | ||
return function animate(element: ElementType | { current: ElementType }, masterConfig?: Config) { | ||
@@ -30,3 +22,2 @@ const loop = target.loop || GlobalLoop | ||
const animations = new Map<keyof ValueType, Animation<ElementType, ValueType>>() | ||
let cachedValues: any | ||
let resolveRef: (value?: unknown) => void | ||
@@ -44,3 +35,3 @@ let rejectRef: (value?: unknown) => void | ||
currentValues[key] = value | ||
adapter?.onChange?.(value, key, el.current, cachedValues) | ||
adapter?.onChange?.(value, key, el.current) | ||
idle &&= animated.idle | ||
@@ -67,6 +58,4 @@ }) | ||
if (!animation) { | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key, cachedValues) | ||
const value = _adapter?.parseInitial | ||
? _adapter?.parseInitial(_value, key, el.current, cachedValues) | ||
: _value | ||
const [_value, _adapter] = target.getInitialValueAndAdapter(el.current, key) | ||
const value = _adapter?.parseInitial ? _adapter?.parseInitial(_value, key, el.current) : _value | ||
animated = new Animated(value, loop) | ||
@@ -80,3 +69,3 @@ adapter = _adapter | ||
const _to = adapter?.parse ? adapter.parse(to[key], key, el.current, cachedValues) : (to[key] as ParsedValue) | ||
const _to = adapter?.parse ? adapter.parse(to[key], key, el.current) : (to[key] as ParsedValue) | ||
animated.start(_to, typeof config === 'function' ? config(key) : config) | ||
@@ -103,11 +92,5 @@ idle &&= animated.idle | ||
const setCachedValues = () => { | ||
cachedValues = target.getCurrentValues?.(el.current) | ||
} | ||
if (syncCachedValues) setCachedValues() | ||
const api = { get, start, stop, clean, setCachedValues } | ||
const api = { get, start, stop, clean } | ||
return api | ||
} | ||
} |
@@ -9,4 +9,3 @@ import { AnimatedValue } from './animated/AnimatedValue' | ||
key: string | number | symbol, | ||
target: ElementType | undefined | null, | ||
cachedValues: any | ||
target: ElementType | undefined | null | ||
) => R | ||
@@ -35,8 +34,6 @@ | ||
loop?: FrameLoop | ||
getCurrentValues?(element: ElementType): Record<string, any> | ||
setValues?(rawValues: ValueType, element: ElementType): void | ||
getInitialValueAndAdapter<K extends keyof ValueType>( | ||
element: ElementType, | ||
key: K, | ||
cachedValues?: any | ||
key: K | ||
): [ValueType[K], Adapter<ElementType, ValueType> | undefined] | ||
@@ -43,0 +40,0 @@ } |
72030
2210