Skip to content

Commit 4b0d147

Browse files
authored
Merge pull request #3 from n-langle/evol
Evol
2 parents 564d9e0 + f1697bc commit 4b0d147

File tree

8 files changed

+155
-139
lines changed

8 files changed

+155
-139
lines changed

build/OneLoop.js

Lines changed: 93 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright 2022 OneLoop.js
44
* Author: Nicolas Langle
55
* Repository: https://github.com/n-langle/OneLoop.js
6-
* Version: 5.1.4
6+
* Version: 5.2.0
77
* SPDX-License-Identifier: MIT
88
*
99
* Credit for easing functions goes to : https://github.com/ai/easings.net/blob/master/src/easings/easingsFunctions.ts
@@ -245,18 +245,18 @@ class MainLoopEntry {
245245
needsUpdate() {
246246
return true
247247
}
248-
249-
// ----
250-
// statics
251-
// ----
252-
static defaults = {
253-
onStart: noop,
254-
onUpdate: noop,
255-
onStop: noop,
256-
onComplete: noop,
257-
}
258248
}
259249

250+
// ----
251+
// statics
252+
// ----
253+
MainLoopEntry.defaults = {
254+
onStart: noop,
255+
onUpdate: noop,
256+
onStop: noop,
257+
onComplete: noop,
258+
};
259+
260260
class Tween extends MainLoopEntry {
261261
constructor(options) {
262262
super(assign({}, Tween.defaults, options));
@@ -352,20 +352,20 @@ class Tween extends MainLoopEntry {
352352
needsUpdate(timestamp) {
353353
return timestamp - (this._startTime + this._pauseDuration) < this.duration * this._range
354354
}
355-
356-
// ----
357-
// statics
358-
// ----
359-
static defaults = {
360-
delay: 0,
361-
duration: 1000,
362-
easing: 'linear',
363-
loop: 0,
364-
reverse: false,
365-
autoStart: true
366-
}
367355
}
368356

357+
// ----
358+
// statics
359+
// ----
360+
Tween.defaults = {
361+
delay: 0,
362+
duration: 1000,
363+
easing: 'linear',
364+
loop: 0,
365+
reverse: false,
366+
autoStart: true
367+
};
368+
369369
// ----
370370
// utils
371371
// ----
@@ -381,7 +381,7 @@ var getElements = (element, context) => typeof element === 'string' ?
381381
:
382382
element.length >= 0 ? element : [element];
383383

384-
const instances$2 = [];
384+
const instances = [];
385385

386386
class ThrottledEvent extends MainLoopEntry {
387387
constructor(target, eventType, name) {
@@ -418,10 +418,10 @@ class ThrottledEvent extends MainLoopEntry {
418418
}
419419

420420
destroy() {
421-
const index = instances$2.indexOf(this);
421+
const index = instances.indexOf(this);
422422

423423
if (index > -1) {
424-
instances$2.splice(index, 1);
424+
instances.splice(index, 1);
425425
}
426426

427427
this._target.removeEventListener(this._eventType, this._onEvent);
@@ -477,25 +477,25 @@ class ThrottledEvent extends MainLoopEntry {
477477

478478
name = name || '';
479479

480-
for (let i = 0; i < instances$2.length; i++) {
481-
let instance = instances$2[i];
480+
for (let i = 0; i < instances.length; i++) {
481+
let instance = instances[i];
482482
if (instance._eventType === eventType && instance._target === target && instance._name === name) {
483-
found = instances$2[i];
483+
found = instances[i];
484484
break
485485
}
486486
}
487487

488488
if (!found) {
489489
found = new ThrottledEvent(target, eventType, name);
490-
instances$2.push(found);
490+
instances.push(found);
491491
}
492492

493493
return found
494494
}
495495

496496
static destroy() {
497-
while (instances$2[0]) {
498-
instances$2[0].destroy();
497+
while (instances[0]) {
498+
instances[0].destroy();
499499
}
500500
}
501501
}
@@ -671,7 +671,11 @@ class ScrollObserverEntry {
671671
p1 = scroll.clone().subtract(this.startRTW).divide(this.distanceRTW),
672672
p2 = scroll.clone().subtract(this.startRTE).divide(this.distanceRTE);
673673

674-
if (p1.x >= 0 && p1.x <= 1 && p1.y >= 0 && p1.y <= 1) {
674+
// prevent NaN error
675+
// if scrollX or scrollY is equal to window width or height
676+
p2.set(p2.x || 0, p2.y || 0);
677+
678+
if ((this.disableCheckOnAxis === 'x' || p1.x >= 0 && p1.x <= 1) && (!this.disableCheckOnAxis === 'y' || p1.y >= 0 && p1.y <= 1)) {
675679
if (!this._isVisible) {
676680
this._isVisible = true;
677681
this.onVisibilityStart.call(this, scrollInfos, getMinOrMax(p1), getMinOrMax(p2));
@@ -691,19 +695,20 @@ class ScrollObserverEntry {
691695

692696
return this
693697
}
694-
695-
// ----
696-
// statics
697-
// ----
698-
static defaults = {
699-
children: '',
700-
onVisible: noop,
701-
onVisibilityStart: noop,
702-
onVisibilityEnd: noop,
703-
onAlways: noop
704-
}
705698
}
706699

700+
// ----
701+
// statics
702+
// ----
703+
ScrollObserverEntry.defaults = {
704+
children: '',
705+
disableCheckOnAxis: '',
706+
onVisible: noop,
707+
onVisibilityStart: noop,
708+
onVisibilityEnd: noop,
709+
onAlways: noop
710+
};
711+
707712
// ----
708713
// utils
709714
// ----
@@ -717,7 +722,7 @@ function getMinOrMax(v) {
717722
const
718723
instances$1 = [];
719724
let autoRefreshTimer = null,
720-
resize$1 = null,
725+
resize = null,
721726
scroll = null;
722727

723728
class ScrollObserver extends MainLoopEntry {
@@ -732,10 +737,10 @@ class ScrollObserver extends MainLoopEntry {
732737
this._needsUpdate = true;
733738
this._lastSize = getDocumentScrollSize();
734739

735-
resize$1 = resize$1 || new ThrottledEvent(window, 'resize');
740+
resize = resize || new ThrottledEvent(window, 'resize');
736741
scroll = scroll || new ThrottledEvent(window, 'scroll');
737742

738-
resize$1.add('resize', this._onResize);
743+
resize.add('resize', this._onResize);
739744
scroll.add('scrollstart', this._onScroll);
740745

741746
instances$1.push(this);
@@ -752,11 +757,11 @@ class ScrollObserver extends MainLoopEntry {
752757

753758
if (instances$1.length === 0) {
754759
ScrollObserver.stopAutoRefresh();
755-
resize$1.destroy();
760+
resize.destroy();
756761
scroll.destroy();
757-
resize$1 = scroll = null;
762+
resize = scroll = null;
758763
} else {
759-
resize$1.remove('resize', this._onResize);
764+
resize.remove('resize', this._onResize);
760765
scroll.remove('scrollstart', this._onScroll);
761766
}
762767
}
@@ -854,13 +859,6 @@ class ScrollObserver extends MainLoopEntry {
854859
// ----
855860
// statics
856861
// ----
857-
static defaults = {
858-
scrollDivider: 1,
859-
onRefresh: noop
860-
}
861-
862-
static autoRefreshDelay = 1000
863-
864862
static startAutoRefresh() {
865863
let lastSize = getDocumentScrollSize();
866864

@@ -893,13 +891,23 @@ class ScrollObserver extends MainLoopEntry {
893891
}
894892
}
895893

894+
// ----
895+
// statics
896+
// ----
897+
ScrollObserver.defaults = {
898+
scrollDivider: 1,
899+
onRefresh: noop
900+
};
901+
902+
ScrollObserver.autoRefreshDelay = 1000;
903+
896904
/* eslint-disable no-empty-character-class */
897905

898906
const
899-
instances = [],
907+
instances$2 = [],
900908
specialCharRegExp = /(((?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c[\ude32-\ude3a]|[\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])((\u200D(\u2640|\u2642)\uFE0F)|[]))|&([a-zA-Z]{2,6}|#[0-9]{2,5});|<|>)/g,
901909
whiteCharRegExp = /(\s)/;
902-
let resize = null;
910+
let resize$1 = null;
903911

904912
class SplittedText {
905913
constructor(element, options) {
@@ -909,35 +917,35 @@ class SplittedText {
909917
this._element = element;
910918
this._onResize = this.split.bind(this);
911919

912-
if (!resize) {
913-
resize = new ThrottledEvent(window, 'resize');
920+
if (!resize$1) {
921+
resize$1 = new ThrottledEvent(window, 'resize');
914922
}
915923

916924
if (this.autoSplit) {
917925
this.split();
918926
}
919927

920-
instances.push(this);
928+
instances$2.push(this);
921929
}
922930

923931
destroy() {
924-
const index = instances.indexOf(this);
932+
const index = instances$2.indexOf(this);
925933

926934
if (index > -1) {
927935
this.restore();
928936

929-
instances.splice(index, 1);
937+
instances$2.splice(index, 1);
930938

931-
if (!instances.length) {
932-
resize.destroy();
933-
resize = null;
939+
if (!instances$2.length) {
940+
resize$1.destroy();
941+
resize$1 = null;
934942
}
935943
}
936944
}
937945

938946
restore() {
939947
this._element.innerHTML = this._originalInnerHTML;
940-
resize.remove('resize', this._onResize);
948+
resize$1.remove('resize', this._onResize);
941949

942950
return this
943951
}
@@ -965,7 +973,7 @@ class SplittedText {
965973
html = '',
966974
lastOffsetTop = children[0].offsetTop;
967975

968-
resize.add('resize', this._onResize);
976+
resize$1.add('resize', this._onResize);
969977

970978
for (let i = 0; i < children.length; i++) {
971979
const
@@ -1007,22 +1015,22 @@ class SplittedText {
10071015

10081016
return this
10091017
}
1010-
1011-
// ----
1012-
// statics
1013-
// ----
1014-
static defaults = {
1015-
autoSplit: true,
1016-
byLine: false,
1017-
byWord: false,
1018-
byChar: false,
1019-
preserve: 'st-char',
1020-
lineWrapper: getStringWrapper('st-line'),
1021-
wordWrapper: getStringWrapper('st-word'),
1022-
charWrapper: getStringWrapper('st-char'),
1023-
}
10241018
}
10251019

1020+
// ----
1021+
// statics
1022+
// ----
1023+
SplittedText.defaults = {
1024+
autoSplit: true,
1025+
byLine: false,
1026+
byWord: false,
1027+
byChar: false,
1028+
preserve: 'st-char',
1029+
lineWrapper: getStringWrapper('st-line'),
1030+
wordWrapper: getStringWrapper('st-word'),
1031+
charWrapper: getStringWrapper('st-char'),
1032+
};
1033+
10261034
// ----
10271035
// utils
10281036
// ----
@@ -1109,8 +1117,8 @@ function wrapByWord(element, wrapper) {
11091117
// static
11101118
// ----
11111119
SplittedText.destroy = function() {
1112-
while (instances[0]) {
1113-
instances[0].destroy();
1120+
while (instances$2[0]) {
1121+
instances$2[0].destroy();
11141122
}
11151123
};
11161124

0 commit comments

Comments
 (0)