1
1
/**
2
2
* anime.js - ESM
3
- * @version v4.1.1
3
+ * @version v4.1.2
4
4
* @author Julian Garnier
5
5
* @license MIT
6
6
* @copyright (c) 2025 Julian Garnier
470
470
// TODO: Do we need to check if we're running inside a worker ?
471
471
const isBrowser = typeof window !== 'undefined' ;
472
472
473
- /** @type {Object|Null } */
474
- const win = isBrowser ? window : null ;
473
+ /** @type {Window & {AnimeJS: Array}|null } */
474
+ const win = isBrowser ? /** @type { Window & {AnimeJS: Array} } */ ( /** @type { unknown } */ ( window ) ) : null ;
475
475
476
- /** @type {Document } */
476
+ /** @type {Document|null } */
477
477
const doc = isBrowser ? document : null ;
478
478
479
479
// Enums
@@ -625,7 +625,7 @@ const globals = {
625
625
tickThreshold : 200 ,
626
626
} ;
627
627
628
- const globalVersions = { version : '4.1.1 ' , engine : null } ;
628
+ const globalVersions = { version : '4.1.2 ' , engine : null } ;
629
629
630
630
if ( isBrowser ) {
631
631
if ( ! win . AnimeJS ) win . AnimeJS = [ ] ;
@@ -1316,7 +1316,7 @@ const tick = (tickable, time, muteCallbacks, internalRender, tickMode) => {
1316
1316
if ( ! muteCallbacks && tlChildrenHasRendered ) tl . onRender ( /** @type {CallbackArgument } */ ( tl ) ) ;
1317
1317
1318
1318
// Triggers the timeline onComplete() once all chindren all completed and the current time has reached the end
1319
- if ( tlChildrenHaveCompleted && tl . _currentTime >= tl . duration ) {
1319
+ if ( ( tlChildrenHaveCompleted || tlIsRunningBackwards ) && tl . _currentTime >= tl . duration ) {
1320
1320
// Make sure the paused flag is false in case it has been skipped in the render function
1321
1321
tl . paused = true ;
1322
1322
if ( ! tl . completed ) {
@@ -3909,7 +3909,8 @@ class JSAnimation extends Timer {
3909
3909
tween . _fromNumber = decomposedOriginalValue . n ;
3910
3910
tween . _toNumbers = cloneArray ( toTargetObject . d ) ;
3911
3911
tween . _strings = cloneArray ( toTargetObject . s ) ;
3912
- tween . _toNumber = toTargetObject . n ;
3912
+ // Make sure to apply relative operators https://github.com/juliangarnier/anime/issues/1025
3913
+ tween . _toNumber = toTargetObject . o ? getRelativeValue ( decomposedOriginalValue . n , toTargetObject . n , toTargetObject . o ) : toTargetObject . n ;
3913
3914
}
3914
3915
} ) ;
3915
3916
return this ;
@@ -5741,7 +5742,8 @@ class Draggable {
5741
5742
this . deltaY = dy ;
5742
5743
this . coords [ 2 ] = x ;
5743
5744
this . coords [ 3 ] = y ;
5744
- if ( hasUpdated ) {
5745
+ // Check if dx or dy are not 0 to check if the draggable has actually moved https://github.com/juliangarnier/anime/issues/1032
5746
+ if ( hasUpdated && ( dx || dy ) ) {
5745
5747
this . onUpdate ( this ) ;
5746
5748
}
5747
5749
if ( ! hasReleased ) {
@@ -6526,7 +6528,6 @@ class Draggable {
6526
6528
this . targetStyles . revert ( ) ;
6527
6529
this . targetStyles = null ;
6528
6530
}
6529
- this . stop ( ) ;
6530
6531
this . $target . classList . add ( 'is-disabled' ) ;
6531
6532
this . $trigger . removeEventListener ( 'touchstart' , this ) ;
6532
6533
this . $trigger . removeEventListener ( 'mousedown' , this ) ;
@@ -6549,6 +6550,7 @@ class Draggable {
6549
6550
this . overshootYTicker . revert ( ) ;
6550
6551
this . resizeTicker . revert ( ) ;
6551
6552
this . animate . revert ( ) ;
6553
+ this . resizeObserver . disconnect ( ) ;
6552
6554
return this ;
6553
6555
}
6554
6556
@@ -6826,7 +6828,7 @@ const createScope = params => new Scope(params);
6826
6828
* @return {Number }
6827
6829
*/
6828
6830
const getMaxViewHeight = ( ) => {
6829
- const $el = document . createElement ( 'div' ) ;
6831
+ const $el = doc . createElement ( 'div' ) ;
6830
6832
doc . body . appendChild ( $el ) ;
6831
6833
$el . style . height = '100lvh' ;
6832
6834
const height = $el . offsetHeight ;
@@ -7025,7 +7027,7 @@ class ScrollContainer {
7025
7027
this . dataTimer . cancel ( ) ;
7026
7028
this . resizeTicker . cancel ( ) ;
7027
7029
this . wakeTicker . cancel ( ) ;
7028
- this . resizeObserver . unobserve ( this . element ) ;
7030
+ this . resizeObserver . disconnect ( ) ;
7029
7031
( this . useWin ? win : this . element ) . removeEventListener ( 'scroll' , this ) ;
7030
7032
scrollContainers . delete ( this . element ) ;
7031
7033
}
@@ -7254,8 +7256,8 @@ class ScrollObserver {
7254
7256
this . forceEnter = false ;
7255
7257
/** @type {Boolean } */
7256
7258
this . hasEntered = false ;
7257
- /** @type {Array.<Number> } */
7258
- this . offsets = [ ] ;
7259
+ // / ** @type {Array.<Number> } */
7260
+ // this.offsets = [];
7259
7261
/** @type {Number } */
7260
7262
this . offset = 0 ;
7261
7263
/** @type {Number } */
@@ -7499,33 +7501,46 @@ class ScrollObserver {
7499
7501
const linked = this . linked ;
7500
7502
let linkedTime ;
7501
7503
let $el = $target ;
7502
- let offsetX = 0 ;
7503
- let offsetY = 0 ;
7504
+ // let offsetX = 0;
7505
+ // let offsetY = 0;
7506
+ // let $offsetParent = $el;
7504
7507
/** @type {Element } */
7505
- let $offsetParent = $el ;
7506
7508
if ( linked ) {
7507
7509
linkedTime = linked . currentTime ;
7508
7510
linked . seek ( 0 , true ) ;
7509
7511
}
7510
- const isContainerStatic = getTargetValue ( container . element , 'position' ) === 'static' ? setTargetValues ( container . element , { position : 'relative ' } ) : false ;
7512
+ /* Old implementation to get offset and targetSize before fixing https://github.com/juliangarnier/anime/issues/1021
7513
+ // const isContainerStatic = getTargetValue(container.element, 'position') === 'static' ? setTargetValues(container.element, { position: 'relative '}) : false;
7514
+ // while ($el && $el !== container.element && $el !== doc.body) {
7515
+ // const isSticky = getTargetValue($el, 'position') === 'sticky' ?
7516
+ // setTargetValues($el, { position: 'static' }) :
7517
+ // false;
7518
+ // if ($el === $offsetParent) {
7519
+ // offsetX += $el.offsetLeft || 0;
7520
+ // offsetY += $el.offsetTop || 0;
7521
+ // $offsetParent = $el.offsetParent;
7522
+ // }
7523
+ // $el = /** @type {HTMLElement } */ ( $el . parentElement ) ;
7524
+ // if (isSticky) {
7525
+ // if (!stickys) stickys = [];
7526
+ // stickys.push(isSticky);
7527
+ // }
7528
+ // }
7529
+ // if (isContainerStatic) isContainerStatic.revert();
7530
+ // const offset = isHori ? offsetX : offsetY;
7531
+ // const targetSize = isHori ? $target.offsetWidth : $target.offsetHeight;
7532
+
7511
7533
while ( $el && $el !== container . element && $el !== doc . body ) {
7512
- const isSticky = getTargetValue ( $el , 'position' ) === 'sticky' ?
7513
- setTargetValues ( $el , { position : 'static' } ) :
7514
- false ;
7515
- if ( $el === $offsetParent ) {
7516
- offsetX += $el . offsetLeft || 0 ;
7517
- offsetY += $el . offsetTop || 0 ;
7518
- $offsetParent = $el . offsetParent ;
7519
- }
7520
- $el = /** @type {HTMLElement } */ ( $el . parentElement ) ;
7534
+ const isSticky = getTargetValue ( $el , 'position' ) === 'sticky' ? setTargetValues ( $el , { position : 'static' } ) : false ;
7535
+ $el = $el . parentElement ;
7521
7536
if ( isSticky ) {
7522
7537
if ( ! stickys ) stickys = [ ] ;
7523
7538
stickys . push ( isSticky ) ;
7524
7539
}
7525
7540
}
7526
- if ( isContainerStatic ) isContainerStatic . revert ( ) ;
7527
- const offset = isHori ? offsetX : offsetY ;
7528
- const targetSize = isHori ? $target . offsetWidth : $target . offsetHeight ;
7541
+ const rect = $target . getBoundingClientRect ( ) ;
7542
+ const offset = isHori ? rect . left + container . scrollX - container . left : rect . top + container . scrollY - container . top ;
7543
+ const targetSize = isHori ? rect . width : rect . height ;
7529
7544
const containerSize = isHori ? container . width : container . height ;
7530
7545
const scrollSize = isHori ? container . scrollWidth : container . scrollHeight ;
7531
7546
const maxScroll = scrollSize - containerSize ;
@@ -7574,8 +7589,8 @@ class ScrollObserver {
7574
7589
const offsetStart = parsedEnterTarget + offset - parsedEnterContainer ;
7575
7590
const offsetEnd = parsedLeaveTarget + offset - parsedLeaveContainer ;
7576
7591
const scrollDelta = offsetEnd - offsetStart ;
7577
- this . offsets [ 0 ] = offsetX ;
7578
- this . offsets [ 1 ] = offsetY ;
7592
+ // this.offsets[0] = offsetX;
7593
+ // this.offsets[1] = offsetY;
7579
7594
this . offset = offset ;
7580
7595
this . offsetStart = offsetStart ;
7581
7596
this . offsetEnd = offsetEnd ;
0 commit comments