code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
get(target, property) { const value = target[property]; if (property === proxyTargetSymbol) return target; if (property === 'setAttribute') { return (...args) => { if (args[0] === 'draw') { const value = args[1]; const values = value.split(' '); const v1 = +values[0]; const v2 = +values[1]; // TOTO: Benchmark if performing two slices is more performant than one split // const spaceIndex = value.indexOf(' '); // const v1 = round(+value.slice(0, spaceIndex), precision); // const v2 = round(+value.slice(spaceIndex + 1), precision); const scaleFactor = getScaleFactor($scalled); const os = v1 * -pathLength * scaleFactor; const d1 = (v2 * pathLength * scaleFactor) + os; const d2 = (pathLength * scaleFactor + ((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1); if (strokeLineCap !== 'butt') { const newCap = v1 === v2 ? 'butt' : strokeLineCap; if (currentCap !== newCap) { target.style.strokeLinecap = `${newCap}`; currentCap = newCap; } } target.setAttribute('stroke-dashoffset', `${os}`); target.setAttribute('stroke-dasharray', `${d1} ${d2}`); } return Reflect.apply(value, target, args); }; } if (isFnc(value)) { return (...args) => Reflect.apply(value, target, args); } else { return value; } }
Creates a proxy that wraps an SVGGeometryElement and adds drawing functionality. @param {SVGGeometryElement} $el - The SVG element to transform into a drawable @param {number} start - Starting position (0-1) @param {number} end - Ending position (0-1) @return {DrawableSVGGeometry} - Returns a proxy that preserves the original element's type with additional 'draw' attribute functionality
get
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
createDrawable = (selector, start = 0, end = 0) => { const els = parseTargets(selector); return els.map($el => createDrawableProxy( /** @type {SVGGeometryElement} */($el), start, end )); }
Creates drawable proxies for multiple SVG elements. @param {TargetsParam} selector - CSS selector, SVG element, or array of elements and selectors @param {number} [start=0] - Starting position (0-1) @param {number} [end=0] - Ending position (0-1) @return {Array<DrawableSVGGeometry>} - Array of proxied elements with drawing functionality
createDrawable
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
createDrawable = (selector, start = 0, end = 0) => { const els = parseTargets(selector); return els.map($el => createDrawableProxy( /** @type {SVGGeometryElement} */($el), start, end )); }
Creates drawable proxies for multiple SVG elements. @param {TargetsParam} selector - CSS selector, SVG element, or array of elements and selectors @param {number} [start=0] - Starting position (0-1) @param {number} [end=0] - Ending position (0-1) @return {Array<DrawableSVGGeometry>} - Array of proxied elements with drawing functionality
createDrawable
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
getPathPoint = ($path, progress, lookup = 0) => { return $path.getPointAtLength(progress + lookup >= 1 ? progress + lookup : 0); }
@param {SVGGeometryElement} $path @param {Number} progress @param {Number}lookup @return {DOMPoint}
getPathPoint
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
getPathPoint = ($path, progress, lookup = 0) => { return $path.getPointAtLength(progress + lookup >= 1 ? progress + lookup : 0); }
@param {SVGGeometryElement} $path @param {Number} progress @param {Number}lookup @return {DOMPoint}
getPathPoint
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
getPathProgess = ($path, pathProperty) => { return $el => { const totalLength = +($path.getTotalLength()); const inSvg = $el[isSvgSymbol]; const ctm = $path.getCTM(); /** @type {TweenObjectValue} */ return { from: 0, to: totalLength, /** @type {TweenModifier} */ modifier: progress => { if (pathProperty === 'a') { const p0 = getPathPoint($path, progress, -1); const p1 = getPathPoint($path, progress, +1); return atan2(p1.y - p0.y, p1.x - p0.x) * 180 / PI; } else { const p = getPathPoint($path, progress, 0); return pathProperty === 'x' ? inSvg || !ctm ? p.x : p.x * ctm.a + p.y * ctm.c + ctm.e : inSvg || !ctm ? p.y : p.x * ctm.b + p.y * ctm.d + ctm.f } } } } }
@param {SVGGeometryElement} $path @param {String} pathProperty @return {FunctionValue}
getPathProgess
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
getPathProgess = ($path, pathProperty) => { return $el => { const totalLength = +($path.getTotalLength()); const inSvg = $el[isSvgSymbol]; const ctm = $path.getCTM(); /** @type {TweenObjectValue} */ return { from: 0, to: totalLength, /** @type {TweenModifier} */ modifier: progress => { if (pathProperty === 'a') { const p0 = getPathPoint($path, progress, -1); const p1 = getPathPoint($path, progress, +1); return atan2(p1.y - p0.y, p1.x - p0.x) * 180 / PI; } else { const p = getPathPoint($path, progress, 0); return pathProperty === 'x' ? inSvg || !ctm ? p.x : p.x * ctm.a + p.y * ctm.c + ctm.e : inSvg || !ctm ? p.y : p.x * ctm.b + p.y * ctm.d + ctm.f } } } } }
@param {SVGGeometryElement} $path @param {String} pathProperty @return {FunctionValue}
getPathProgess
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
isValidSVGAttribute = (el, propertyName) => { // Return early and use CSS opacity animation instead (already better default values (opacity: 1 instead of 0)) and rotate should be considered a transform if (cssReservedProperties.includes(propertyName)) return false; if (el.getAttribute(propertyName) || propertyName in el) { if (propertyName === 'scale') { // Scale const elParentNode = /** @type {SVGGeometryElement} */(/** @type {DOMTarget} */(el).parentNode); // Only consider scale as a valid SVG attribute on filter element return elParentNode && elParentNode.tagName === 'filter'; } return true; } }
@param {Target} el @param {String} propertyName @return {Boolean}
isValidSVGAttribute
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
isValidSVGAttribute = (el, propertyName) => { // Return early and use CSS opacity animation instead (already better default values (opacity: 1 instead of 0)) and rotate should be considered a transform if (cssReservedProperties.includes(propertyName)) return false; if (el.getAttribute(propertyName) || propertyName in el) { if (propertyName === 'scale') { // Scale const elParentNode = /** @type {SVGGeometryElement} */(/** @type {DOMTarget} */(el).parentNode); // Only consider scale as a valid SVG attribute on filter element return elParentNode && elParentNode.tagName === 'filter'; } return true; } }
@param {Target} el @param {String} propertyName @return {Boolean}
isValidSVGAttribute
javascript
juliangarnier/anime
src/svg.js
https://github.com/juliangarnier/anime/blob/master/src/svg.js
MIT
function getNodeList(v) { const n = isStr(v) ? globals.root.querySelectorAll(v) : v; if (n instanceof NodeList || n instanceof HTMLCollection) return n; }
@param {DOMTargetsParam|TargetsParam} v @return {NodeList|HTMLCollection}
getNodeList
javascript
juliangarnier/anime
src/targets.js
https://github.com/juliangarnier/anime/blob/master/src/targets.js
MIT
function parseTargets(targets) { if (isNil(targets)) return /** @type {TargetsArray} */([]); if (isArr(targets)) { const flattened = targets.flat(Infinity); /** @type {TargetsArray} */ const parsed = []; for (let i = 0, l = flattened.length; i < l; i++) { const item = flattened[i]; if (!isNil(item)) { const nodeList = getNodeList(item); if (nodeList) { for (let j = 0, jl = nodeList.length; j < jl; j++) { const subItem = nodeList[j]; if (!isNil(subItem)) { let isDuplicate = false; for (let k = 0, kl = parsed.length; k < kl; k++) { if (parsed[k] === subItem) { isDuplicate = true; break; } } if (!isDuplicate) { parsed.push(subItem); } } } } else { let isDuplicate = false; for (let j = 0, jl = parsed.length; j < jl; j++) { if (parsed[j] === item) { isDuplicate = true; break; } } if (!isDuplicate) { parsed.push(item); } } } } return parsed; } if (!isBrowser) return /** @type {JSTargetsArray} */([targets]); const nodeList = getNodeList(targets); if (nodeList) return /** @type {DOMTargetsArray} */(Array.from(nodeList)); return /** @type {TargetsArray} */([targets]); }
@overload @param {DOMTargetsParam} targets @return {DOMTargetsArray} @overload @param {JSTargetsParam} targets @return {JSTargetsArray} @overload @param {TargetsParam} targets @return {TargetsArray} @param {DOMTargetsParam|JSTargetsParam|TargetsParam} targets
parseTargets
javascript
juliangarnier/anime
src/targets.js
https://github.com/juliangarnier/anime/blob/master/src/targets.js
MIT
function registerTargets(targets) { const parsedTargetsArray = parseTargets(targets); const parsedTargetsLength = parsedTargetsArray.length; if (parsedTargetsLength) { for (let i = 0; i < parsedTargetsLength; i++) { const target = parsedTargetsArray[i]; if (!target[isRegisteredTargetSymbol]) { target[isRegisteredTargetSymbol] = true; const isSvgType = isSvg(target); const isDom = /** @type {DOMTarget} */(target).nodeType || isSvgType; if (isDom) { target[isDomSymbol] = true; target[isSvgSymbol] = isSvgType; target[transformsSymbol] = {}; } } } } return parsedTargetsArray; }
@overload @param {DOMTargetsParam} targets @return {DOMTargetsArray} @overload @param {JSTargetsParam} targets @return {JSTargetsArray} @overload @param {TargetsParam} targets @return {TargetsArray} @param {DOMTargetsParam|JSTargetsParam|TargetsParam} targets
registerTargets
javascript
juliangarnier/anime
src/targets.js
https://github.com/juliangarnier/anime/blob/master/src/targets.js
MIT
getPrevChildOffset = (timeline, timePosition) => { if (stringStartsWith(timePosition, '<')) { const goToPrevAnimationOffset = timePosition[1] === '<'; const prevAnimation = /** @type {Tickable} */(timeline._tail); const prevOffset = prevAnimation ? prevAnimation._offset + prevAnimation._delay : 0; return goToPrevAnimationOffset ? prevOffset : prevOffset + prevAnimation.duration; } }
Timeline's children offsets positions parser @param {Timeline} timeline @param {String} timePosition @return {Number}
getPrevChildOffset
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
getPrevChildOffset = (timeline, timePosition) => { if (stringStartsWith(timePosition, '<')) { const goToPrevAnimationOffset = timePosition[1] === '<'; const prevAnimation = /** @type {Tickable} */(timeline._tail); const prevOffset = prevAnimation ? prevAnimation._offset + prevAnimation._delay : 0; return goToPrevAnimationOffset ? prevOffset : prevOffset + prevAnimation.duration; } }
Timeline's children offsets positions parser @param {Timeline} timeline @param {String} timePosition @return {Number}
getPrevChildOffset
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
parseTimelinePosition = (timeline, timePosition) => { let tlDuration = timeline.iterationDuration; if (tlDuration === minValue) tlDuration = 0; if (isUnd(timePosition)) return tlDuration; if (isNum(+timePosition)) return +timePosition; const timePosStr = /** @type {String} */(timePosition); const tlLabels = timeline ? timeline.labels : null; const hasLabels = !isNil(tlLabels); const prevOffset = getPrevChildOffset(timeline, timePosStr); const hasSibling = !isUnd(prevOffset); const matchedRelativeOperator = relativeValuesExecRgx.exec(timePosStr); if (matchedRelativeOperator) { const fullOperator = matchedRelativeOperator[0]; const split = timePosStr.split(fullOperator); const labelOffset = hasLabels && split[0] ? tlLabels[split[0]] : tlDuration; const parsedOffset = hasSibling ? prevOffset : hasLabels ? labelOffset : tlDuration; const parsedNumericalOffset = +split[1]; return getRelativeValue(parsedOffset, parsedNumericalOffset, fullOperator[0]); } else { return hasSibling ? prevOffset : hasLabels ? !isUnd(tlLabels[timePosStr]) ? tlLabels[timePosStr] : tlDuration : tlDuration; } }
@param {Timeline} timeline @param {TimePosition} [timePosition] @return {Number}
parseTimelinePosition
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
parseTimelinePosition = (timeline, timePosition) => { let tlDuration = timeline.iterationDuration; if (tlDuration === minValue) tlDuration = 0; if (isUnd(timePosition)) return tlDuration; if (isNum(+timePosition)) return +timePosition; const timePosStr = /** @type {String} */(timePosition); const tlLabels = timeline ? timeline.labels : null; const hasLabels = !isNil(tlLabels); const prevOffset = getPrevChildOffset(timeline, timePosStr); const hasSibling = !isUnd(prevOffset); const matchedRelativeOperator = relativeValuesExecRgx.exec(timePosStr); if (matchedRelativeOperator) { const fullOperator = matchedRelativeOperator[0]; const split = timePosStr.split(fullOperator); const labelOffset = hasLabels && split[0] ? tlLabels[split[0]] : tlDuration; const parsedOffset = hasSibling ? prevOffset : hasLabels ? labelOffset : tlDuration; const parsedNumericalOffset = +split[1]; return getRelativeValue(parsedOffset, parsedNumericalOffset, fullOperator[0]); } else { return hasSibling ? prevOffset : hasLabels ? !isUnd(tlLabels[timePosStr]) ? tlLabels[timePosStr] : tlDuration : tlDuration; } }
@param {Timeline} timeline @param {TimePosition} [timePosition] @return {Number}
parseTimelinePosition
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
function addTlChild(childParams, tl, timePosition, targets, index, length) { const isSetter = isNum(childParams.duration) && /** @type {Number} */(childParams.duration) <= minValue; // Offset the tl position with -minValue for 0 duration animations or .set() calls in order to align their end value with the defined position const adjustedPosition = isSetter ? timePosition - minValue : timePosition; tick(tl, adjustedPosition, 1, 1, tickModes.AUTO); const tlChild = targets ? new JSAnimation(targets,/** @type {AnimationParams} */(childParams), tl, adjustedPosition, false, index, length) : new Timer(/** @type {TimerParams} */(childParams), tl, adjustedPosition); tlChild.init(1); // TODO: Might be better to insert at a position relative to startTime? addChild(tl, tlChild); forEachChildren(tl, (/** @type {Renderable} */child) => { const childTLOffset = child._offset + child._delay; const childDur = childTLOffset + child.duration; if (childDur > tl.iterationDuration) tl.iterationDuration = childDur; }); tl.duration = getTimelineTotalDuration(tl); return tl; }
@overload @param {TimerParams} childParams @param {Timeline} tl @param {Number} timePosition @return {Timeline} @overload @param {AnimationParams} childParams @param {Timeline} tl @param {Number} timePosition @param {TargetsParam} targets @param {Number} [index] @param {Number} [length] @return {Timeline} @param {TimerParams|AnimationParams} childParams @param {Timeline} tl @param {Number} timePosition @param {TargetsParam} [targets] @param {Number} [index] @param {Number} [length]
addTlChild
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
add(a1, a2, a3) { const isAnim = isObj(a2); const isTimer = isObj(a1); if (isAnim || isTimer) { this._hasChildren = true; if (isAnim) { const childParams = /** @type {AnimationParams} */(a2); // Check for function for children stagger positions if (isFnc(a3)) { const staggeredPosition = /** @type {Function} */(a3); const parsedTargetsArray = parseTargets(/** @type {TargetsParam} */(a1)); // Store initial duration before adding new children that will change the duration const tlDuration = this.duration; // Store initial _iterationDuration before adding new children that will change the duration const tlIterationDuration = this.iterationDuration; // Store the original id in order to add specific indexes to the new animations ids const id = childParams.id; let i = 0; const parsedLength = parsedTargetsArray.length; parsedTargetsArray.forEach((/** @type {Target} */target) => { // Create a new parameter object for each staggered children const staggeredChildParams = { ...childParams }; // Reset the duration of the timeline iteration before each stagger to prevent wrong start value calculation this.duration = tlDuration; this.iterationDuration = tlIterationDuration; if (!isUnd(id)) staggeredChildParams.id = id + '-' + i; addTlChild( staggeredChildParams, this, staggeredPosition(target, i, parsedLength, this), target, i, parsedLength ); i++; }); } else { addTlChild( childParams, this, parseTimelinePosition(this, a3), /** @type {TargetsParam} */(a1), ); } } else { // It's a Timer addTlChild( /** @type TimerParams */(a1), this, parseTimelinePosition(this,/** @type TimePosition */(a2)), ); } return this.init(1); // 1 = internalRender } }
@overload @param {TargetsParam} a1 @param {AnimationParams} a2 @param {TimePosition} [a3] @return {this} @overload @param {TimerParams} a1 @param {TimePosition} [a2] @return {this} @param {TargetsParam|TimerParams} a1 @param {AnimationParams|TimePosition} a2 @param {TimePosition} [a3]
add
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
sync(synced, position) { if (isUnd(synced) || synced && isUnd(synced.pause)) return this; synced.pause(); const duration = +(/** @type {globalThis.Animation} */(synced).effect ? /** @type {globalThis.Animation} */(synced).effect.getTiming().duration : /** @type {Tickable} */(synced).duration); return this.add(synced, { currentTime: [0, duration], duration, ease: 'linear' }, position); }
@overload @param {Tickable} [synced] @param {TimePosition} [position] @return {this} @overload @param {globalThis.Animation} [synced] @param {TimePosition} [position] @return {this} @overload @param {WAAPIAnimation} [synced] @param {TimePosition} [position] @return {this} @param {Tickable|WAAPIAnimation|globalThis.Animation} [synced] @param {TimePosition} [position]
sync
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
set(targets, parameters, position) { if (isUnd(parameters)) return this; parameters.duration = minValue; parameters.composition = compositionTypes.replace; return this.add(targets, parameters, position); }
@param {TargetsParam} targets @param {AnimationParams} parameters @param {TimePosition} [position] @return {this}
set
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
call(callback, position) { if (isUnd(callback) || callback && !isFnc(callback)) return this; return this.add({ duration: 0, onComplete: () => callback(this) }, position); }
@param {Callback<Timer>} callback @param {TimePosition} [position] @return {this}
call
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
label(labelName, position) { if (isUnd(labelName) || labelName && !isStr(labelName)) return this; this.labels[labelName] = parseTimelinePosition(this,/** @type TimePosition */(position)); return this; }
@param {String} labelName @param {TimePosition} [position] @return {this}
label
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
remove(targets, propertyName) { remove(targets, this, propertyName); return this; }
@param {TargetsParam} targets @param {String} [propertyName] @return {this}
remove
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
then(callback) { return super.then(callback); }
@param {Callback<this>} [callback] @return {Promise}
then
javascript
juliangarnier/anime
src/timeline.js
https://github.com/juliangarnier/anime/blob/master/src/timeline.js
MIT
constructor(parameters = {}, parent = null, parentPosition = 0) { super(0); const { id, delay, duration, reversed, alternate, loop, loopDelay, autoplay, frameRate, playbackRate, onComplete, onLoop, onPause, onBegin, onBeforeUpdate, onUpdate, } = parameters; if (globals.scope) globals.scope.revertibles.push(this); const timerInitTime = parent ? 0 : engine._elapsedTime; const timerDefaults = parent ? parent.defaults : globals.defaults; const timerDelay = /** @type {Number} */(isFnc(delay) || isUnd(delay) ? timerDefaults.delay : +delay); const timerDuration = isFnc(duration) || isUnd(duration) ? Infinity : +duration; const timerLoop = setValue(loop, timerDefaults.loop); const timerLoopDelay = setValue(loopDelay, timerDefaults.loopDelay); const timerIterationCount = timerLoop === true || timerLoop === Infinity || /** @type {Number} */(timerLoop) < 0 ? Infinity : /** @type {Number} */(timerLoop) + 1; let offsetPosition = 0; if (parent) { offsetPosition = parentPosition; } else { let startTime = now(); // Make sure to tick the engine once if suspended to avoid big gaps with the following offsetPosition calculation if (engine.paused) { engine.requestTick(startTime); startTime = engine._elapsedTime; } offsetPosition = startTime - engine._startTime; } // Timer's parameters this.id = !isUnd(id) ? id : ++timerId; /** @type {Timeline} */ this.parent = parent; // Total duration of the timer this.duration = clampInfinity(((timerDuration + timerLoopDelay) * timerIterationCount) - timerLoopDelay) || minValue; /** @type {Boolean} */ this.backwards = false; /** @type {Boolean} */ this.paused = true; /** @type {Boolean} */ this.began = false; /** @type {Boolean} */ this.completed = false; /** @type {Callback<this>} */ this.onBegin = onBegin || timerDefaults.onBegin; /** @type {Callback<this>} */ this.onBeforeUpdate = onBeforeUpdate || timerDefaults.onBeforeUpdate; /** @type {Callback<this>} */ this.onUpdate = onUpdate || timerDefaults.onUpdate; /** @type {Callback<this>} */ this.onLoop = onLoop || timerDefaults.onLoop; /** @type {Callback<this>} */ this.onPause = onPause || timerDefaults.onPause; /** @type {Callback<this>} */ this.onComplete = onComplete || timerDefaults.onComplete; /** @type {Number} */ this.iterationDuration = timerDuration; // Duration of one loop /** @type {Number} */ this.iterationCount = timerIterationCount; // Number of loops /** @type {Boolean|ScrollObserver} */ this._autoplay = parent ? false : setValue(autoplay, timerDefaults.autoplay); /** @type {Number} */ this._offset = offsetPosition; /** @type {Number} */ this._delay = timerDelay; /** @type {Number} */ this._loopDelay = timerLoopDelay; /** @type {Number} */ this._iterationTime = 0; /** @type {Number} */ this._currentIteration = 0; // Current loop index /** @type {Function} */ this._resolve = noop; // Used by .then() /** @type {Boolean} */ this._running = false; /** @type {Number} */ this._reversed = +setValue(reversed, timerDefaults.reversed); /** @type {Number} */ this._reverse = this._reversed; /** @type {Number} */ this._cancelled = 0; /** @type {Boolean} */ this._alternate = setValue(alternate, timerDefaults.alternate); /** @type {Renderable} */ this._prev = null; /** @type {Renderable} */ this._next = null; // Clock's parameters /** @type {Number} */ this._elapsedTime = timerInitTime; /** @type {Number} */ this._startTime = timerInitTime; /** @type {Number} */ this._lastTime = timerInitTime; /** @type {Number} */ this._fps = setValue(frameRate, timerDefaults.frameRate); /** @type {Number} */ this._speed = setValue(playbackRate, timerDefaults.playbackRate); }
@param {TimerParams} [parameters] @param {Timeline} [parent] @param {Number} [parentPosition]
constructor
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
seek(time, muteCallbacks = 0, internalRender = 0) { // Recompose the tween siblings in case the timer has been cancelled reviveTimer(this); // If you seek a completed animation, otherwise the next play will starts at 0 this.completed = false; const isPaused = this.paused; this.paused = true; // timer, time, muteCallbacks, internalRender, tickMode tick(this, time + this._delay, ~~muteCallbacks, ~~internalRender, tickModes.AUTO); return isPaused ? this : this.resume(); }
@param {Number} time @param {Boolean|Number} [muteCallbacks] @param {Boolean|Number} [internalRender] @return {this}
seek
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
revert() { tick(this, 0, 1, 0, tickModes.AUTO); const ap = /** @type {ScrollObserver} */(this._autoplay); if (ap && ap.linked && ap.linked === this) ap.revert(); return this.cancel(); }
Cancels the timer by seeking it back to 0 and reverting the attached scroller if necessary @return {this}
revert
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
complete() { return this.seek(this.duration).cancel(); }
Imediatly completes the timer, cancels it and triggers the onComplete callback @return {this}
complete
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
then(callback = noop) { const then = this.then; const onResolve = () => { // this.then = null prevents infinite recursion if returned by an async function // https://github.com/juliangarnierorg/anime-beta/issues/26 this.then = null; callback(this); this.then = then; this._resolve = noop; } return new Promise(r => { this._resolve = () => r(onResolve()); // Make sure to resolve imediatly if the timer has already completed if (this.completed) this._resolve(); return this; }); }
@param {Callback<this>} [callback] @return {Promise}
then
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
onResolve = () => { // this.then = null prevents infinite recursion if returned by an async function // https://github.com/juliangarnierorg/anime-beta/issues/26 this.then = null; callback(this); this.then = then; this._resolve = noop; }
@param {Callback<this>} [callback] @return {Promise}
onResolve
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
onResolve = () => { // this.then = null prevents infinite recursion if returned by an async function // https://github.com/juliangarnierorg/anime-beta/issues/26 this.then = null; callback(this); this.then = then; this._resolve = noop; }
@param {Callback<this>} [callback] @return {Promise}
onResolve
javascript
juliangarnier/anime
src/timer.js
https://github.com/juliangarnier/anime/blob/master/src/timer.js
MIT
parseInlineTransforms = (target, propName, animationInlineStyles) => { const inlineTransforms = target.style.transform; let inlinedStylesPropertyValue; if (inlineTransforms) { const cachedTransforms = target[transformsSymbol]; let t; while (t = transformsExecRgx.exec(inlineTransforms)) { const inlinePropertyName = t[1]; // const inlinePropertyValue = t[2]; const inlinePropertyValue = t[2].slice(1, -1); cachedTransforms[inlinePropertyName] = inlinePropertyValue; if (inlinePropertyName === propName) { inlinedStylesPropertyValue = inlinePropertyValue; // Store the new parsed inline styles if animationInlineStyles is provided if (animationInlineStyles) { animationInlineStyles[propName] = inlinePropertyValue; } } } } return inlineTransforms && !isUnd(inlinedStylesPropertyValue) ? inlinedStylesPropertyValue : stringStartsWith(propName, 'scale') ? '1' : stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew') ? '0deg' : '0px'; }
@param {DOMTarget} target @param {String} propName @param {Object} animationInlineStyles @return {String}
parseInlineTransforms
javascript
juliangarnier/anime
src/transforms.js
https://github.com/juliangarnier/anime/blob/master/src/transforms.js
MIT
parseInlineTransforms = (target, propName, animationInlineStyles) => { const inlineTransforms = target.style.transform; let inlinedStylesPropertyValue; if (inlineTransforms) { const cachedTransforms = target[transformsSymbol]; let t; while (t = transformsExecRgx.exec(inlineTransforms)) { const inlinePropertyName = t[1]; // const inlinePropertyValue = t[2]; const inlinePropertyValue = t[2].slice(1, -1); cachedTransforms[inlinePropertyName] = inlinePropertyValue; if (inlinePropertyName === propName) { inlinedStylesPropertyValue = inlinePropertyValue; // Store the new parsed inline styles if animationInlineStyles is provided if (animationInlineStyles) { animationInlineStyles[propName] = inlinePropertyValue; } } } } return inlineTransforms && !isUnd(inlinedStylesPropertyValue) ? inlinedStylesPropertyValue : stringStartsWith(propName, 'scale') ? '1' : stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew') ? '0deg' : '0px'; }
@param {DOMTarget} target @param {String} propName @param {Object} animationInlineStyles @return {String}
parseInlineTransforms
javascript
juliangarnier/anime
src/transforms.js
https://github.com/juliangarnier/anime/blob/master/src/transforms.js
MIT
convertValueUnit = (el, decomposedValue, unit, force = false) => { const currentUnit = decomposedValue.u; const currentNumber = decomposedValue.n; if (decomposedValue.t === valueTypes.UNIT && currentUnit === unit) { // TODO: Check if checking against the same unit string is necessary return decomposedValue; } const cachedKey = currentNumber + currentUnit + unit; const cached = convertedValuesCache[cachedKey]; if (!isUnd(cached) && !force) { decomposedValue.n = cached; } else { let convertedValue; if (currentUnit in angleUnitsMap) { convertedValue = currentNumber * angleUnitsMap[currentUnit] / angleUnitsMap[unit]; } else { const baseline = 100; const tempEl = /** @type {DOMTarget} */(el.cloneNode()); const parentNode = el.parentNode; const parentEl = (parentNode && (parentNode !== doc)) ? parentNode : doc.body; parentEl.appendChild(tempEl); const elStyle = tempEl.style; elStyle.width = baseline + currentUnit; const currentUnitWidth = /** @type {HTMLElement} */(tempEl).offsetWidth || baseline; elStyle.width = baseline + unit; const newUnitWidth = /** @type {HTMLElement} */(tempEl).offsetWidth || baseline; const factor = currentUnitWidth / newUnitWidth; parentEl.removeChild(tempEl); convertedValue = factor * currentNumber; } decomposedValue.n = convertedValue; convertedValuesCache[cachedKey] = convertedValue; } decomposedValue.t === valueTypes.UNIT; decomposedValue.u = unit; return decomposedValue; }
@param {DOMTarget} el @param {TweenDecomposedValue} decomposedValue @param {String} unit @param {Boolean} [force] @return {TweenDecomposedValue}
convertValueUnit
javascript
juliangarnier/anime
src/units.js
https://github.com/juliangarnier/anime/blob/master/src/units.js
MIT
convertValueUnit = (el, decomposedValue, unit, force = false) => { const currentUnit = decomposedValue.u; const currentNumber = decomposedValue.n; if (decomposedValue.t === valueTypes.UNIT && currentUnit === unit) { // TODO: Check if checking against the same unit string is necessary return decomposedValue; } const cachedKey = currentNumber + currentUnit + unit; const cached = convertedValuesCache[cachedKey]; if (!isUnd(cached) && !force) { decomposedValue.n = cached; } else { let convertedValue; if (currentUnit in angleUnitsMap) { convertedValue = currentNumber * angleUnitsMap[currentUnit] / angleUnitsMap[unit]; } else { const baseline = 100; const tempEl = /** @type {DOMTarget} */(el.cloneNode()); const parentNode = el.parentNode; const parentEl = (parentNode && (parentNode !== doc)) ? parentNode : doc.body; parentEl.appendChild(tempEl); const elStyle = tempEl.style; elStyle.width = baseline + currentUnit; const currentUnitWidth = /** @type {HTMLElement} */(tempEl).offsetWidth || baseline; elStyle.width = baseline + unit; const newUnitWidth = /** @type {HTMLElement} */(tempEl).offsetWidth || baseline; const factor = currentUnitWidth / newUnitWidth; parentEl.removeChild(tempEl); convertedValue = factor * currentNumber; } decomposedValue.n = convertedValue; convertedValuesCache[cachedKey] = convertedValue; } decomposedValue.t === valueTypes.UNIT; decomposedValue.u = unit; return decomposedValue; }
@param {DOMTarget} el @param {TweenDecomposedValue} decomposedValue @param {String} unit @param {Boolean} [force] @return {TweenDecomposedValue}
convertValueUnit
javascript
juliangarnier/anime
src/units.js
https://github.com/juliangarnier/anime/blob/master/src/units.js
MIT
sync = (callback = noop) => { return new Timer({ duration: 1 * globals.timeScale, onComplete: callback }, null, 0).resume(); }
@param {Callback<Timer>} [callback] @return {Timer}
sync
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
sync = (callback = noop) => { return new Timer({ duration: 1 * globals.timeScale, onComplete: callback }, null, 0).resume(); }
@param {Callback<Timer>} [callback] @return {Timer}
sync
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
function getTargetValue(targetSelector, propName, unit) { const targets = registerTargets(targetSelector); if (!targets.length) return; const [ target ] = targets; const tweenType = getTweenType(target, propName); const normalizePropName = sanitizePropertyName(propName, target, tweenType); let originalValue = getOriginalAnimatableValue(target, normalizePropName); if (isUnd(unit)) { return originalValue; } else { decomposeRawValue(originalValue, decomposedOriginalValue); if (decomposedOriginalValue.t === valueTypes.NUMBER || decomposedOriginalValue.t === valueTypes.UNIT) { if (unit === false) { return decomposedOriginalValue.n; } else { const convertedValue = convertValueUnit(/** @type {DOMTarget} */(target), decomposedOriginalValue, /** @type {String} */(unit), false); return `${round(convertedValue.n, globals.precision)}${convertedValue.u}`; } } } }
@overload @param {DOMTargetSelector} targetSelector @param {String} propName @return {String} @overload @param {JSTargetsParam} targetSelector @param {String} propName @return {Number|String} @overload @param {DOMTargetsParam} targetSelector @param {String} propName @param {String} unit @return {String} @overload @param {TargetsParam} targetSelector @param {String} propName @param {Boolean} unit @return {Number} @param {TargetsParam} targetSelector @param {String} propName @param {String|Boolean} [unit]
getTargetValue
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
setTargetValues = (targets, parameters) => { if (isUnd(parameters)) return; parameters.duration = minValue; // Do not overrides currently active tweens by default parameters.composition = setValue(parameters.composition, compositionTypes.none); // Skip init() and force rendering by playing the animation return new JSAnimation(targets, parameters, null, 0, true).resume(); }
@param {TargetsParam} targets @param {AnimationParams} parameters @return {JSAnimation}
setTargetValues
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
setTargetValues = (targets, parameters) => { if (isUnd(parameters)) return; parameters.duration = minValue; // Do not overrides currently active tweens by default parameters.composition = setValue(parameters.composition, compositionTypes.none); // Skip init() and force rendering by playing the animation return new JSAnimation(targets, parameters, null, 0, true).resume(); }
@param {TargetsParam} targets @param {AnimationParams} parameters @return {JSAnimation}
setTargetValues
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
removeTargetsFromAnimation = (targetsArray, animation, propertyName) => { let tweensMatchesTargets = false; forEachChildren(animation, (/**@type {Tween} */tween) => { const tweenTarget = tween.target; if (targetsArray.includes(tweenTarget)) { const tweenName = tween.property; const tweenType = tween._tweenType; const normalizePropName = sanitizePropertyName(propertyName, tweenTarget, tweenType); if (!normalizePropName || normalizePropName && normalizePropName === tweenName) { // Make sure to flag the previous CSS transform tween to renderTransform if (tween.parent._tail === tween && tween._tweenType === tweenTypes.TRANSFORM && tween._prev && tween._prev._tweenType === tweenTypes.TRANSFORM ) { tween._prev._renderTransforms = 1; } // Removes the tween from the selected animation removeChild(animation, tween); // Detach the tween from its siblings to make sure blended tweens are correctlly removed removeTweenSliblings(tween); tweensMatchesTargets = true; } } }, true); return tweensMatchesTargets; }
@param {TargetsArray} targetsArray @param {JSAnimation} animation @param {String} [propertyName] @return {Boolean}
removeTargetsFromAnimation
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
removeTargetsFromAnimation = (targetsArray, animation, propertyName) => { let tweensMatchesTargets = false; forEachChildren(animation, (/**@type {Tween} */tween) => { const tweenTarget = tween.target; if (targetsArray.includes(tweenTarget)) { const tweenName = tween.property; const tweenType = tween._tweenType; const normalizePropName = sanitizePropertyName(propertyName, tweenTarget, tweenType); if (!normalizePropName || normalizePropName && normalizePropName === tweenName) { // Make sure to flag the previous CSS transform tween to renderTransform if (tween.parent._tail === tween && tween._tweenType === tweenTypes.TRANSFORM && tween._prev && tween._prev._tweenType === tweenTypes.TRANSFORM ) { tween._prev._renderTransforms = 1; } // Removes the tween from the selected animation removeChild(animation, tween); // Detach the tween from its siblings to make sure blended tweens are correctlly removed removeTweenSliblings(tween); tweensMatchesTargets = true; } } }, true); return tweensMatchesTargets; }
@param {TargetsArray} targetsArray @param {JSAnimation} animation @param {String} [propertyName] @return {Boolean}
removeTargetsFromAnimation
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
remove = (targets, renderable, propertyName) => { const targetsArray = parseTargets(targets); const parent = /** @type {Renderable|typeof engine} **/(renderable ? renderable : engine); const waapiAnimation = renderable && /** @type {WAAPIAnimation} */(renderable).controlAnimation && /** @type {WAAPIAnimation} */(renderable); for (let i = 0, l = targetsArray.length; i < l; i++) { const $el = /** @type {DOMTarget} */(targetsArray[i]); removeWAAPIAnimation($el, propertyName, waapiAnimation); } let removeMatches; if (parent._hasChildren) { let iterationDuration = 0; forEachChildren(parent, (/** @type {Renderable} */child) => { if (!child._hasChildren) { removeMatches = removeTargetsFromAnimation(targetsArray, /** @type {JSAnimation} */(child), propertyName); // Remove the child from its parent if no tweens and no children left after the removal if (removeMatches && !child._head) { child.cancel(); removeChild(parent, child); } else { // Calculate the new iterationDuration value to handle onComplete with last child in render() const childTLOffset = child._offset + child._delay; const childDur = childTLOffset + child.duration; if (childDur > iterationDuration) { iterationDuration = childDur; } } } // Make sure to also remove engine's children targets // NOTE: Avoid recursion? if (child._head) { remove(targets, child, propertyName); } else { child._hasChildren = false; } }, true); // Update iterationDuration value to handle onComplete with last child in render() if (!isUnd(/** @type {Renderable} */(parent).iterationDuration)) { /** @type {Renderable} */(parent).iterationDuration = iterationDuration; } } else { removeMatches = removeTargetsFromAnimation( targetsArray, /** @type {JSAnimation} */(parent), propertyName ); } if (removeMatches && !parent._head) { parent._hasChildren = false; // Cancel the parent if there are no tweens and no children left after the removal // We have to check if the .cancel() method exist to handle cases where the parent is the engine itself if (/** @type {Renderable} */(parent).cancel) /** @type {Renderable} */(parent).cancel(); } return targetsArray; }
@param {TargetsParam} targets @param {Renderable|WAAPIAnimation} [renderable] @param {String} [propertyName] @return {TargetsArray}
remove
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
remove = (targets, renderable, propertyName) => { const targetsArray = parseTargets(targets); const parent = /** @type {Renderable|typeof engine} **/(renderable ? renderable : engine); const waapiAnimation = renderable && /** @type {WAAPIAnimation} */(renderable).controlAnimation && /** @type {WAAPIAnimation} */(renderable); for (let i = 0, l = targetsArray.length; i < l; i++) { const $el = /** @type {DOMTarget} */(targetsArray[i]); removeWAAPIAnimation($el, propertyName, waapiAnimation); } let removeMatches; if (parent._hasChildren) { let iterationDuration = 0; forEachChildren(parent, (/** @type {Renderable} */child) => { if (!child._hasChildren) { removeMatches = removeTargetsFromAnimation(targetsArray, /** @type {JSAnimation} */(child), propertyName); // Remove the child from its parent if no tweens and no children left after the removal if (removeMatches && !child._head) { child.cancel(); removeChild(parent, child); } else { // Calculate the new iterationDuration value to handle onComplete with last child in render() const childTLOffset = child._offset + child._delay; const childDur = childTLOffset + child.duration; if (childDur > iterationDuration) { iterationDuration = childDur; } } } // Make sure to also remove engine's children targets // NOTE: Avoid recursion? if (child._head) { remove(targets, child, propertyName); } else { child._hasChildren = false; } }, true); // Update iterationDuration value to handle onComplete with last child in render() if (!isUnd(/** @type {Renderable} */(parent).iterationDuration)) { /** @type {Renderable} */(parent).iterationDuration = iterationDuration; } } else { removeMatches = removeTargetsFromAnimation( targetsArray, /** @type {JSAnimation} */(parent), propertyName ); } if (removeMatches && !parent._head) { parent._hasChildren = false; // Cancel the parent if there are no tweens and no children left after the removal // We have to check if the .cancel() method exist to handle cases where the parent is the engine itself if (/** @type {Renderable} */(parent).cancel) /** @type {Renderable} */(parent).cancel(); } return targetsArray; }
@param {TargetsParam} targets @param {Renderable|WAAPIAnimation} [renderable] @param {String} [propertyName] @return {TargetsArray}
remove
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
shuffle = items => { let m = items.length, t, i; while (m) { i = random(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; } return items; }
Adapted from https://bost.ocks.org/mike/shuffle/ @param {Array} items @return {Array}
shuffle
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
shuffle = items => { let m = items.length, t, i; while (m) { i = random(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; } return items; }
Adapted from https://bost.ocks.org/mike/shuffle/ @param {Array} items @return {Array}
shuffle
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
lerp = (start, end, amount, renderable) => { let dt = K / globals.defaults.frameRate; if (renderable !== false) { const ticker = /** @type Renderable */ (renderable) || (engine._hasChildren && engine); if (ticker && ticker.deltaTime) { dt = ticker.deltaTime; } } const t = 1 - Math.exp(-amount * dt * .1); return !amount ? start : amount === 1 ? end : (1 - t) * start + t * end; }
https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ @param {Number} start @param {Number} end @param {Number} amount @param {Renderable|Boolean} [renderable] @return {Number}
lerp
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
lerp = (start, end, amount, renderable) => { let dt = K / globals.defaults.frameRate; if (renderable !== false) { const ticker = /** @type Renderable */ (renderable) || (engine._hasChildren && engine); if (ticker && ticker.deltaTime) { dt = ticker.deltaTime; } } const t = 1 - Math.exp(-amount * dt * .1); return !amount ? start : amount === 1 ? end : (1 - t) * start + t * end; }
https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ @param {Number} start @param {Number} end @param {Number} amount @param {Renderable|Boolean} [renderable] @return {Number}
lerp
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
chain = fn => { return (...args) => { const result = fn(...args); return new Proxy(noop, { apply: (_, __, [v]) => result(v), get: (_, prop) => chain(/**@param {...Number|String} nextArgs */(...nextArgs) => { const nextResult = utils[prop](...nextArgs); return (/**@type {Number|String} */v) => nextResult(result(v)); }) }); } }
@param {Function} fn @return {function(...(Number|String))}
chain
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
chain = fn => { return (...args) => { const result = fn(...args); return new Proxy(noop, { apply: (_, __, [v]) => result(v), get: (_, prop) => chain(/**@param {...Number|String} nextArgs */(...nextArgs) => { const nextResult = utils[prop](...nextArgs); return (/**@type {Number|String} */v) => nextResult(result(v)); }) }); } }
@param {Function} fn @return {function(...(Number|String))}
chain
javascript
juliangarnier/anime
src/utils.js
https://github.com/juliangarnier/anime/blob/master/src/utils.js
MIT
setValue = (targetValue, defaultValue) => { return isUnd(targetValue) ? defaultValue : targetValue; }
@template T, D @param {T|undefined} targetValue @param {D} defaultValue @return {T|D}
setValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
setValue = (targetValue, defaultValue) => { return isUnd(targetValue) ? defaultValue : targetValue; }
@template T, D @param {T|undefined} targetValue @param {D} defaultValue @return {T|D}
setValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getFunctionValue = (value, target, index, total, store) => { if (isFnc(value)) { const func = () => { const computed = /** @type {Function} */(value)(target, index, total); // Fallback to 0 if the function returns undefined / NaN / null / false / 0 return !isNaN(+computed) ? +computed : computed || 0; } if (store) { store.func = func; } return func(); } else { return value; } }
@param {TweenPropValue} value @param {Target} target @param {Number} index @param {Number} total @param {Object} [store] @return {any}
getFunctionValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getFunctionValue = (value, target, index, total, store) => { if (isFnc(value)) { const func = () => { const computed = /** @type {Function} */(value)(target, index, total); // Fallback to 0 if the function returns undefined / NaN / null / false / 0 return !isNaN(+computed) ? +computed : computed || 0; } if (store) { store.func = func; } return func(); } else { return value; } }
@param {TweenPropValue} value @param {Target} target @param {Number} index @param {Number} total @param {Object} [store] @return {any}
getFunctionValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
func = () => { const computed = /** @type {Function} */(value)(target, index, total); // Fallback to 0 if the function returns undefined / NaN / null / false / 0 return !isNaN(+computed) ? +computed : computed || 0; }
@param {TweenPropValue} value @param {Target} target @param {Number} index @param {Number} total @param {Object} [store] @return {any}
func
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
func = () => { const computed = /** @type {Function} */(value)(target, index, total); // Fallback to 0 if the function returns undefined / NaN / null / false / 0 return !isNaN(+computed) ? +computed : computed || 0; }
@param {TweenPropValue} value @param {Target} target @param {Number} index @param {Number} total @param {Object} [store] @return {any}
func
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getTweenType = (target, prop) => { return !target[isDomSymbol] ? tweenTypes.OBJECT : // Handle SVG attributes target[isSvgSymbol] && isValidSVGAttribute(target, prop) ? tweenTypes.ATTRIBUTE : // Handle CSS Transform properties differently than CSS to allow individual animations validTransforms.includes(prop) || shortTransforms.get(prop) ? tweenTypes.TRANSFORM : // CSS variables stringStartsWith(prop, '--') ? tweenTypes.CSS_VAR : // All other CSS properties prop in /** @type {DOMTarget} */(target).style ? tweenTypes.CSS : // Handle other DOM Attributes prop in target ? tweenTypes.OBJECT : tweenTypes.ATTRIBUTE; }
@param {Target} target @param {String} prop @return {tweenTypes}
getTweenType
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getTweenType = (target, prop) => { return !target[isDomSymbol] ? tweenTypes.OBJECT : // Handle SVG attributes target[isSvgSymbol] && isValidSVGAttribute(target, prop) ? tweenTypes.ATTRIBUTE : // Handle CSS Transform properties differently than CSS to allow individual animations validTransforms.includes(prop) || shortTransforms.get(prop) ? tweenTypes.TRANSFORM : // CSS variables stringStartsWith(prop, '--') ? tweenTypes.CSS_VAR : // All other CSS properties prop in /** @type {DOMTarget} */(target).style ? tweenTypes.CSS : // Handle other DOM Attributes prop in target ? tweenTypes.OBJECT : tweenTypes.ATTRIBUTE; }
@param {Target} target @param {String} prop @return {tweenTypes}
getTweenType
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getCSSValue = (target, propName, animationInlineStyles) => { const inlineStyles = target.style[propName]; if (inlineStyles && animationInlineStyles) { animationInlineStyles[propName] = inlineStyles; } const value = inlineStyles || getComputedStyle(target[proxyTargetSymbol] || target).getPropertyValue(propName); return value === 'auto' ? '0' : value; }
@param {DOMTarget} target @param {String} propName @param {Object} animationInlineStyles @return {String}
getCSSValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getCSSValue = (target, propName, animationInlineStyles) => { const inlineStyles = target.style[propName]; if (inlineStyles && animationInlineStyles) { animationInlineStyles[propName] = inlineStyles; } const value = inlineStyles || getComputedStyle(target[proxyTargetSymbol] || target).getPropertyValue(propName); return value === 'auto' ? '0' : value; }
@param {DOMTarget} target @param {String} propName @param {Object} animationInlineStyles @return {String}
getCSSValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getOriginalAnimatableValue = (target, propName, tweenType, animationInlineStyles) => { const type = !isUnd(tweenType) ? tweenType : getTweenType(target, propName); return type === tweenTypes.OBJECT ? target[propName] || 0 : type === tweenTypes.ATTRIBUTE ? /** @type {DOMTarget} */(target).getAttribute(propName) : type === tweenTypes.TRANSFORM ? parseInlineTransforms(/** @type {DOMTarget} */(target), propName, animationInlineStyles) : type === tweenTypes.CSS_VAR ? getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles).trimStart() : getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles); }
@param {Target} target @param {String} propName @param {tweenTypes} [tweenType] @param {Object|void} [animationInlineStyles] @return {String|Number}
getOriginalAnimatableValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getOriginalAnimatableValue = (target, propName, tweenType, animationInlineStyles) => { const type = !isUnd(tweenType) ? tweenType : getTweenType(target, propName); return type === tweenTypes.OBJECT ? target[propName] || 0 : type === tweenTypes.ATTRIBUTE ? /** @type {DOMTarget} */(target).getAttribute(propName) : type === tweenTypes.TRANSFORM ? parseInlineTransforms(/** @type {DOMTarget} */(target), propName, animationInlineStyles) : type === tweenTypes.CSS_VAR ? getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles).trimStart() : getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles); }
@param {Target} target @param {String} propName @param {tweenTypes} [tweenType] @param {Object|void} [animationInlineStyles] @return {String|Number}
getOriginalAnimatableValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getRelativeValue = (x, y, operator) => { return operator === '-' ? x - y : operator === '+' ? x + y : x * y; }
@param {Number} x @param {Number} y @param {String} operator @return {Number}
getRelativeValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
getRelativeValue = (x, y, operator) => { return operator === '-' ? x - y : operator === '+' ? x + y : x * y; }
@param {Number} x @param {Number} y @param {String} operator @return {Number}
getRelativeValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
decomposeRawValue = (rawValue, targetObject) => { /** @type {valueTypes} */ targetObject.t = valueTypes.NUMBER; targetObject.n = 0; targetObject.u = null; targetObject.o = null; targetObject.d = null; targetObject.s = null; if (!rawValue) return targetObject; const num = +rawValue; if (!isNaN(num)) { // It's a number targetObject.n = num; return targetObject; } else { // let str = /** @type {String} */(rawValue).trim(); let str = /** @type {String} */(rawValue); // Parsing operators (+=, -=, *=) manually is much faster than using regex here if (str[1] === '=') { targetObject.o = str[0]; str = str.slice(2); } // Skip exec regex if the value type is complex or color to avoid long regex backtracking const unitMatch = str.includes(' ') ? false : unitsExecRgx.exec(str); if (unitMatch) { // Has a number and a unit targetObject.t = valueTypes.UNIT; targetObject.n = +unitMatch[1]; targetObject.u = unitMatch[2]; return targetObject; } else if (targetObject.o) { // Has an operator (+=, -=, *=) targetObject.n = +str; return targetObject; } else if (isCol(str)) { // Is a color targetObject.t = valueTypes.COLOR; targetObject.d = convertColorStringValuesToRgbaArray(str); return targetObject; } else { // Is a more complex string (generally svg coords, calc() or filters CSS values) const matchedNumbers = str.match(digitWithExponentRgx); targetObject.t = valueTypes.COMPLEX; targetObject.d = matchedNumbers ? matchedNumbers.map(Number) : []; targetObject.s = str.split(digitWithExponentRgx) || []; return targetObject; } } }
@param {String|Number} rawValue @param {TweenDecomposedValue} targetObject @return {TweenDecomposedValue}
decomposeRawValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
decomposeRawValue = (rawValue, targetObject) => { /** @type {valueTypes} */ targetObject.t = valueTypes.NUMBER; targetObject.n = 0; targetObject.u = null; targetObject.o = null; targetObject.d = null; targetObject.s = null; if (!rawValue) return targetObject; const num = +rawValue; if (!isNaN(num)) { // It's a number targetObject.n = num; return targetObject; } else { // let str = /** @type {String} */(rawValue).trim(); let str = /** @type {String} */(rawValue); // Parsing operators (+=, -=, *=) manually is much faster than using regex here if (str[1] === '=') { targetObject.o = str[0]; str = str.slice(2); } // Skip exec regex if the value type is complex or color to avoid long regex backtracking const unitMatch = str.includes(' ') ? false : unitsExecRgx.exec(str); if (unitMatch) { // Has a number and a unit targetObject.t = valueTypes.UNIT; targetObject.n = +unitMatch[1]; targetObject.u = unitMatch[2]; return targetObject; } else if (targetObject.o) { // Has an operator (+=, -=, *=) targetObject.n = +str; return targetObject; } else if (isCol(str)) { // Is a color targetObject.t = valueTypes.COLOR; targetObject.d = convertColorStringValuesToRgbaArray(str); return targetObject; } else { // Is a more complex string (generally svg coords, calc() or filters CSS values) const matchedNumbers = str.match(digitWithExponentRgx); targetObject.t = valueTypes.COMPLEX; targetObject.d = matchedNumbers ? matchedNumbers.map(Number) : []; targetObject.s = str.split(digitWithExponentRgx) || []; return targetObject; } } }
@param {String|Number} rawValue @param {TweenDecomposedValue} targetObject @return {TweenDecomposedValue}
decomposeRawValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
decomposeTweenValue = (tween, targetObject) => { targetObject.t = tween._valueType; targetObject.n = tween._toNumber; targetObject.u = tween._unit; targetObject.o = null; targetObject.d = cloneArray(tween._toNumbers); targetObject.s = cloneArray(tween._strings); return targetObject; }
@param {Tween} tween @param {TweenDecomposedValue} targetObject @return {TweenDecomposedValue}
decomposeTweenValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
decomposeTweenValue = (tween, targetObject) => { targetObject.t = tween._valueType; targetObject.n = tween._toNumber; targetObject.u = tween._unit; targetObject.o = null; targetObject.d = cloneArray(tween._toNumbers); targetObject.s = cloneArray(tween._strings); return targetObject; }
@param {Tween} tween @param {TweenDecomposedValue} targetObject @return {TweenDecomposedValue}
decomposeTweenValue
javascript
juliangarnier/anime
src/values.js
https://github.com/juliangarnier/anime/blob/master/src/values.js
MIT
easingToLinear = (fn, samples = 100) => { const points = []; for (let i = 0; i <= samples; i++) points.push(fn(i / samples)); return `linear(${points.join(', ')})`; }
Converts an easing function into a valid CSS linear() timing function string @param {EasingFunction} fn @param {number} [samples=100] @returns {string} CSS linear() timing function
easingToLinear
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
easingToLinear = (fn, samples = 100) => { const points = []; for (let i = 0; i <= samples; i++) points.push(fn(i / samples)); return `linear(${points.join(', ')})`; }
Converts an easing function into a valid CSS linear() timing function string @param {EasingFunction} fn @param {number} [samples=100] @returns {string} CSS linear() timing function
easingToLinear
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
registerTransformsProperties = () => { if (transformsPropertiesRegistered) return; validTransforms.forEach(t => { const isSkew = stringStartsWith(t, 'skew'); const isScale = stringStartsWith(t, 'scale'); const isRotate = stringStartsWith(t, 'rotate'); const isTranslate = stringStartsWith(t, 'translate'); const isAngle = isRotate || isSkew; const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*"; try { CSS.registerProperty({ name: '--' + t, syntax, inherits: false, initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0', }); } catch {}; }); transformsPropertiesRegistered = true; }
@typedef {Record<String, WAAPIKeyframeValue | WAAPIAnimationOptions | Boolean | ScrollObserver | WAAPICallback | EasingParam | WAAPITweenOptions> & WAAPIAnimationOptions} WAAPIAnimationParams
registerTransformsProperties
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
registerTransformsProperties = () => { if (transformsPropertiesRegistered) return; validTransforms.forEach(t => { const isSkew = stringStartsWith(t, 'skew'); const isScale = stringStartsWith(t, 'scale'); const isRotate = stringStartsWith(t, 'rotate'); const isTranslate = stringStartsWith(t, 'translate'); const isAngle = isRotate || isSkew; const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*"; try { CSS.registerProperty({ name: '--' + t, syntax, inherits: false, initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0', }); } catch {}; }); transformsPropertiesRegistered = true; }
@typedef {Record<String, WAAPIKeyframeValue | WAAPIAnimationOptions | Boolean | ScrollObserver | WAAPICallback | EasingParam | WAAPITweenOptions> & WAAPIAnimationOptions} WAAPIAnimationParams
registerTransformsProperties
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
removeWAAPIAnimation = ($el, property, parent) => { let nextLookup = WAAPIAnimationsLookups._head; while (nextLookup) { const next = nextLookup._next; const matchTarget = nextLookup.$el === $el; const matchProperty = !property || nextLookup.property === property; const matchParent = !parent || nextLookup.parent === parent; if (matchTarget && matchProperty && matchParent) { const anim = nextLookup.animation; try { anim.commitStyles(); } catch {}; anim.cancel(); removeChild(WAAPIAnimationsLookups, nextLookup); const lookupParent = nextLookup.parent; if (lookupParent) { lookupParent._completed++; if (lookupParent.animations.length === lookupParent._completed) { lookupParent.completed = true; if (!lookupParent.muteCallbacks) { lookupParent.paused = true; lookupParent.onComplete(lookupParent); lookupParent._resolve(lookupParent); } } } } nextLookup = next; } }
@param {DOMTarget} $el @param {String} [property] @param {WAAPIAnimation} [parent]
removeWAAPIAnimation
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
removeWAAPIAnimation = ($el, property, parent) => { let nextLookup = WAAPIAnimationsLookups._head; while (nextLookup) { const next = nextLookup._next; const matchTarget = nextLookup.$el === $el; const matchProperty = !property || nextLookup.property === property; const matchParent = !parent || nextLookup.parent === parent; if (matchTarget && matchProperty && matchParent) { const anim = nextLookup.animation; try { anim.commitStyles(); } catch {}; anim.cancel(); removeChild(WAAPIAnimationsLookups, nextLookup); const lookupParent = nextLookup.parent; if (lookupParent) { lookupParent._completed++; if (lookupParent.animations.length === lookupParent._completed) { lookupParent.completed = true; if (!lookupParent.muteCallbacks) { lookupParent.paused = true; lookupParent.onComplete(lookupParent); lookupParent._resolve(lookupParent); } } } } nextLookup = next; } }
@param {DOMTarget} $el @param {String} [property] @param {WAAPIAnimation} [parent]
removeWAAPIAnimation
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
addWAAPIAnimation = (parent, $el, property, keyframes, params) => { const animation = $el.animate(keyframes, params); const animTotalDuration = params.delay + (+params.duration * params.iterations); animation.playbackRate = parent._speed; if (parent.paused) animation.pause(); if (parent.duration < animTotalDuration) { parent.duration = animTotalDuration; parent.controlAnimation = animation; } parent.animations.push(animation); removeWAAPIAnimation($el, property); addChild(WAAPIAnimationsLookups, { parent, animation, $el, property, _next: null, _prev: null }); const handleRemove = () => { removeWAAPIAnimation($el, property, parent); }; animation.onremove = handleRemove; animation.onfinish = handleRemove; return animation; }
@param {WAAPIAnimation} parent @param {DOMTarget} $el @param {String} property @param {PropertyIndexedKeyframes} keyframes @param {KeyframeAnimationOptions} params @retun {Animation}
addWAAPIAnimation
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
addWAAPIAnimation = (parent, $el, property, keyframes, params) => { const animation = $el.animate(keyframes, params); const animTotalDuration = params.delay + (+params.duration * params.iterations); animation.playbackRate = parent._speed; if (parent.paused) animation.pause(); if (parent.duration < animTotalDuration) { parent.duration = animTotalDuration; parent.controlAnimation = animation; } parent.animations.push(animation); removeWAAPIAnimation($el, property); addChild(WAAPIAnimationsLookups, { parent, animation, $el, property, _next: null, _prev: null }); const handleRemove = () => { removeWAAPIAnimation($el, property, parent); }; animation.onremove = handleRemove; animation.onfinish = handleRemove; return animation; }
@param {WAAPIAnimation} parent @param {DOMTarget} $el @param {String} property @param {PropertyIndexedKeyframes} keyframes @param {KeyframeAnimationOptions} params @retun {Animation}
addWAAPIAnimation
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
normalizeTweenValue = (propName, value, $el, i, targetsLength) => { let v = getFunctionValue(/** @type {any} */(value), $el, i, targetsLength); if (!isNum(v)) return v; if (commonDefaultPXProperties.includes(propName) || stringStartsWith(propName, 'translate')) return `${v}px`; if (stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew')) return `${v}deg`; return `${v}`; }
@param {String} propName @param {WAAPIKeyframeValue} value @param {DOMTarget} $el @param {Number} i @param {Number} targetsLength @return {String}
normalizeTweenValue
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
normalizeTweenValue = (propName, value, $el, i, targetsLength) => { let v = getFunctionValue(/** @type {any} */(value), $el, i, targetsLength); if (!isNum(v)) return v; if (commonDefaultPXProperties.includes(propName) || stringStartsWith(propName, 'translate')) return `${v}px`; if (stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew')) return `${v}deg`; return `${v}`; }
@param {String} propName @param {WAAPIKeyframeValue} value @param {DOMTarget} $el @param {Number} i @param {Number} targetsLength @return {String}
normalizeTweenValue
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
parseIndividualTweenValue = ($el, propName, from, to, i, targetsLength) => { /** @type {WAAPITweenValue} */ let tweenValue = '0'; const computedTo = !isUnd(to) ? normalizeTweenValue(propName, to, $el, i, targetsLength) : getComputedStyle($el)[propName]; if (!isUnd(from)) { const computedFrom = normalizeTweenValue(propName, from, $el, i, targetsLength); tweenValue = [computedFrom, computedTo]; } else { tweenValue = isArr(to) ? to.map((/** @type {any} */v) => normalizeTweenValue(propName, v, $el, i, targetsLength)) : computedTo; } return tweenValue; }
@param {DOMTarget} $el @param {String} propName @param {WAAPIKeyframeValue} from @param {WAAPIKeyframeValue} to @param {Number} i @param {Number} targetsLength @return {WAAPITweenValue}
parseIndividualTweenValue
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
parseIndividualTweenValue = ($el, propName, from, to, i, targetsLength) => { /** @type {WAAPITweenValue} */ let tweenValue = '0'; const computedTo = !isUnd(to) ? normalizeTweenValue(propName, to, $el, i, targetsLength) : getComputedStyle($el)[propName]; if (!isUnd(from)) { const computedFrom = normalizeTweenValue(propName, from, $el, i, targetsLength); tweenValue = [computedFrom, computedTo]; } else { tweenValue = isArr(to) ? to.map((/** @type {any} */v) => normalizeTweenValue(propName, v, $el, i, targetsLength)) : computedTo; } return tweenValue; }
@param {DOMTarget} $el @param {String} propName @param {WAAPIKeyframeValue} from @param {WAAPIKeyframeValue} to @param {Number} i @param {Number} targetsLength @return {WAAPITweenValue}
parseIndividualTweenValue
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
constructor(targets, params) { if (globals.scope) globals.scope.revertibles.push(this); registerTransformsProperties(); const parsedTargets = registerTargets(targets); const targetsLength = parsedTargets.length; if (!targetsLength) { console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`); } const ease = setValue(params.ease, parseWAAPIEasing(globals.defaults.ease)); const spring = /** @type {Spring} */(ease).ease && ease; const autoplay = setValue(params.autoplay, globals.defaults.autoplay); const scroll = autoplay && /** @type {ScrollObserver} */(autoplay).link ? autoplay : false; const alternate = params.alternate && /** @type {Boolean} */(params.alternate) === true; const reversed = params.reversed && /** @type {Boolean} */(params.reversed) === true; const loop = setValue(params.loop, globals.defaults.loop); const iterations = /** @type {Number} */((loop === true || loop === Infinity) ? Infinity : isNum(loop) ? loop + 1 : 1); /** @type {PlaybackDirection} */ const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal'; /** @type {FillMode} */ const fill = 'forwards'; /** @type {String} */ const easing = parseWAAPIEasing(ease); const timeScale = (globals.timeScale === 1 ? 1 : K); /** @type {DOMTargetsArray}] */ this.targets = parsedTargets; /** @type {Array<globalThis.Animation>}] */ this.animations = []; /** @type {globalThis.Animation}] */ this.controlAnimation = null; /** @type {Callback<this>} */ this.onComplete = params.onComplete || noop; /** @type {Number} */ this.duration = 0; /** @type {Boolean} */ this.muteCallbacks = false; /** @type {Boolean} */ this.completed = false; /** @type {Boolean} */ this.paused = !autoplay || scroll !== false; /** @type {Boolean} */ this.reversed = reversed; /** @type {Boolean|ScrollObserver} */ this.autoplay = autoplay; /** @type {Number} */ this._speed = setValue(params.playbackRate, globals.defaults.playbackRate); /** @type {Function} */ this._resolve = noop; // Used by .then() /** @type {Number} */ this._completed = 0; /** @type {Array<Object>}] */ this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style')); parsedTargets.forEach(($el, i) => { const cachedTransforms = $el[transformsSymbol]; const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t)); /** @type {Number} */ const duration = (spring ? /** @type {Spring} */(spring).duration : getFunctionValue(setValue(params.duration, globals.defaults.duration), $el, i, targetsLength)) * timeScale; /** @type {Number} */ const delay = getFunctionValue(setValue(params.delay, globals.defaults.delay), $el, i, targetsLength) * timeScale; /** @type {CompositeOperation} */ const composite = /** @type {CompositeOperation} */(setValue(params.composition, 'replace')); for (let name in params) { if (!isKey(name)) continue; /** @type {PropertyIndexedKeyframes} */ const keyframes = {}; /** @type {KeyframeAnimationOptions} */ const tweenParams = { iterations, direction, fill, easing, duration, delay, composite }; const propertyValue = params[name]; const individualTransformProperty = hasIndividualTransforms ? validTransforms.includes(name) ? name : shortTransforms.get(name) : false; let parsedPropertyValue; if (isObj(propertyValue)) { const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue); const tweenOptionsEase = setValue(tweenOptions.ease, ease); const tweenOptionsSpring = /** @type {Spring} */(tweenOptionsEase).ease && tweenOptionsEase; const to = /** @type {WAAPITweenOptions} */(tweenOptions).to; const from = /** @type {WAAPITweenOptions} */(tweenOptions).from; /** @type {Number} */ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : getFunctionValue(setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale; /** @type {Number} */ tweenParams.delay = getFunctionValue(setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale; /** @type {CompositeOperation} */ tweenParams.composite = /** @type {CompositeOperation} */(setValue(tweenOptions.composition, composite)); /** @type {String} */ tweenParams.easing = parseWAAPIEasing(tweenOptionsEase); parsedPropertyValue = parseIndividualTweenValue($el, name, from, to, i, targetsLength); if (individualTransformProperty) { keyframes[`--${individualTransformProperty}`] = parsedPropertyValue; cachedTransforms[individualTransformProperty] = parsedPropertyValue; } else { keyframes[name] = parseIndividualTweenValue($el, name, from, to, i, targetsLength); } addWAAPIAnimation(this, $el, name, keyframes, tweenParams); if (!isUnd(from)) { if (!individualTransformProperty) { $el.style[name] = keyframes[name][0]; } else { const key = `--${individualTransformProperty}`; $el.style.setProperty(key, keyframes[key][0]); } } } else { parsedPropertyValue = isArr(propertyValue) ? propertyValue.map((/** @type {any} */v) => normalizeTweenValue(name, v, $el, i, targetsLength)) : normalizeTweenValue(name, /** @type {any} */(propertyValue), $el, i, targetsLength); if (individualTransformProperty) { keyframes[`--${individualTransformProperty}`] = parsedPropertyValue; cachedTransforms[individualTransformProperty] = parsedPropertyValue; } else { keyframes[name] = parsedPropertyValue; } addWAAPIAnimation(this, $el, name, keyframes, tweenParams); } } if (hasIndividualTransforms) { let transforms = emptyString; for (let t in cachedTransforms) { transforms += `${transformsFragmentStrings[t]}var(--${t})) `; } $el.style.transform = transforms; } }); if (scroll) { /** @type {ScrollObserver} */(this.autoplay).link(this); } }
@param {DOMTargetsParam} targets @param {WAAPIAnimationParams} params
constructor
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
forEach(callback) { const cb = isStr(callback) ? a => a[callback]() : callback; this.animations.forEach(cb); return this; }
@param {forEachCallback|String} callback @return {this}
forEach
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
get speed() { return this._speed; }
@param {forEachCallback|String} callback @return {this}
speed
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
seek(time, muteCallbacks = false) { if (muteCallbacks) this.muteCallbacks = true; if (time < this.duration) this.completed = false; this.currentTime = time; this.muteCallbacks = false; if (this.paused) this.pause(); return this; }
@param {Number} time @param {Boolean} muteCallbacks
seek
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
restart() { this.completed = false; return this.seek(0, true).resume(); }
@param {Number} time @param {Boolean} muteCallbacks
restart
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
commitStyles() { return this.forEach('commitStyles'); }
@param {Number} time @param {Boolean} muteCallbacks
commitStyles
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
complete() { return this.seek(this.duration); }
@param {Number} time @param {Boolean} muteCallbacks
complete
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
cancel() { this.forEach('cancel'); return this.pause(); }
@param {Number} time @param {Boolean} muteCallbacks
cancel
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
revert() { this.cancel(); this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) ); return this; }
@param {Number} time @param {Boolean} muteCallbacks
revert
javascript
juliangarnier/anime
src/waapi.js
https://github.com/juliangarnier/anime/blob/master/src/waapi.js
MIT
parseNumber = str => isStr(str) ? parseFloat(/** @type {String} */(str)) : /** @type {Number} */(str)
@param {Number|String} str @return {Number}
parseNumber
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
parseNumber = str => isStr(str) ? parseFloat(/** @type {String} */(str)) : /** @type {Number} */(str)
@param {Number|String} str @return {Number}
parseNumber
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
round = (v, decimalLength) => { if (decimalLength < 0) return v; const m = 10 ** decimalLength; return _round(v * m) / m; }
@param {Number} v @param {Number} decimalLength @return {Number}
round
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
round = (v, decimalLength) => { if (decimalLength < 0) return v; const m = 10 ** decimalLength; return _round(v * m) / m; }
@param {Number} v @param {Number} decimalLength @return {Number}
round
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
forEachChildren = (parent, callback, reverse, prevProp = '_prev', nextProp = '_next') => { let next = parent._head; let adjustedNextProp = nextProp; if (reverse) { next = parent._tail; adjustedNextProp = prevProp; } while (next) { const currentNext = next[adjustedNextProp]; callback(next); next = currentNext; } }
@param {Object} parent @param {Function} callback @param {Boolean} [reverse] @param {String} [prevProp] @param {String} [nextProp] @return {void}
forEachChildren
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
forEachChildren = (parent, callback, reverse, prevProp = '_prev', nextProp = '_next') => { let next = parent._head; let adjustedNextProp = nextProp; if (reverse) { next = parent._tail; adjustedNextProp = prevProp; } while (next) { const currentNext = next[adjustedNextProp]; callback(next); next = currentNext; } }
@param {Object} parent @param {Function} callback @param {Boolean} [reverse] @param {String} [prevProp] @param {String} [nextProp] @return {void}
forEachChildren
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
removeChild = (parent, child, prevProp = '_prev', nextProp = '_next') => { const prev = child[prevProp]; const next = child[nextProp]; prev ? prev[nextProp] = next : parent._head = next; next ? next[prevProp] = prev : parent._tail = prev; child[prevProp] = null; child[nextProp] = null; }
@param {Object} parent @param {Object} child @param {String} [prevProp] @param {String} [nextProp] @return {void}
removeChild
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
removeChild = (parent, child, prevProp = '_prev', nextProp = '_next') => { const prev = child[prevProp]; const next = child[nextProp]; prev ? prev[nextProp] = next : parent._head = next; next ? next[prevProp] = prev : parent._tail = prev; child[prevProp] = null; child[nextProp] = null; }
@param {Object} parent @param {Object} child @param {String} [prevProp] @param {String} [nextProp] @return {void}
removeChild
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
addChild = (parent, child, sortMethod, prevProp = '_prev', nextProp = '_next') => { let prev = parent._tail; while (prev && sortMethod && sortMethod(prev, child)) prev = prev[prevProp]; const next = prev ? prev[nextProp] : parent._head; prev ? prev[nextProp] = child : parent._head = child; next ? next[prevProp] = child : parent._tail = child; child[prevProp] = prev; child[nextProp] = next; }
@param {Object} parent @param {Object} child @param {Function} [sortMethod] @param {String} prevProp @param {String} nextProp @return {void}
addChild
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
addChild = (parent, child, sortMethod, prevProp = '_prev', nextProp = '_next') => { let prev = parent._tail; while (prev && sortMethod && sortMethod(prev, child)) prev = prev[prevProp]; const next = prev ? prev[nextProp] : parent._head; prev ? prev[nextProp] = child : parent._head = child; next ? next[prevProp] = child : parent._tail = child; child[prevProp] = prev; child[nextProp] = next; }
@param {Object} parent @param {Object} child @param {Function} [sortMethod] @param {String} prevProp @param {String} nextProp @return {void}
addChild
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT
constructor() { /** @type {Number} */ this.currentTime = 0; /** @type {Number} */ this.deltaTime = 0; /** @type {Number} */ this._elapsedTime = 0; /** @type {Number} */ this._startTime = 0; /** @type {Number} */ this._lastTime = 0; /** @type {Number} */ this._scheduledTime = 0; /** @type {Number} */ this._frameDuration = K / maxFps; /** @type {Number} */ this._fps = maxFps; /** @type {Number} */ this._speed = 1; /** @type {Boolean} */ this._hasChildren = false; }
@param {Object} parent @param {Object} child @param {Function} [sortMethod] @param {String} prevProp @param {String} nextProp @return {void}
constructor
javascript
juliangarnier/anime
tests/playground/assets/js/anime.esm.js
https://github.com/juliangarnier/anime/blob/master/tests/playground/assets/js/anime.esm.js
MIT