vevet 2.0.1-dev.26 → 2.0.1-dev.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cdn/index.js +1 -1
- package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
- package/build/cjs/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/cjs/components/scroll/scrollbar/Bar.js +4 -4
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +5 -5
- package/build/cjs/components/timeline/StaticTimeline.js +3 -3
- package/build/cjs/components/timeline/Timeline.js +2 -2
- package/build/cjs/utils/math/clamp.js +16 -0
- package/build/cjs/utils/math/clampScope.js +16 -0
- package/build/cjs/utils/math/inScope.js +10 -0
- package/build/cjs/utils/math/index.js +11 -7
- package/build/cjs/utils/math/scoped.js +18 -0
- package/build/cjs/utils/math/spreadScope.js +18 -0
- package/build/es/components/animation-frame/AnimationFrame.js +2 -2
- package/build/es/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/es/components/scroll/scrollbar/Bar.js +4 -4
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +5 -5
- package/build/es/components/timeline/StaticTimeline.js +3 -3
- package/build/es/components/timeline/Timeline.js +2 -2
- package/build/es/utils/math/clamp.js +12 -0
- package/build/es/utils/math/clampScope.js +8 -0
- package/build/es/utils/math/inScope.js +6 -0
- package/build/es/utils/math/index.js +6 -4
- package/build/es/utils/math/scoped.js +14 -0
- package/build/es/utils/math/spreadScope.js +15 -0
- package/build/types/utils/math/clamp.d.ts +5 -0
- package/build/types/utils/math/clamp.d.ts.map +1 -0
- package/build/types/utils/math/clampScope.d.ts +5 -0
- package/build/types/utils/math/clampScope.d.ts.map +1 -0
- package/build/types/utils/math/inScope.d.ts +5 -0
- package/build/types/utils/math/inScope.d.ts.map +1 -0
- package/build/types/utils/math/index.d.ts +6 -4
- package/build/types/utils/math/index.d.ts.map +1 -1
- package/build/types/utils/math/scoped.d.ts +12 -0
- package/build/types/utils/math/scoped.d.ts.map +1 -0
- package/build/types/utils/math/spreadScope.d.ts +5 -0
- package/build/types/utils/math/spreadScope.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
- package/src/ts/components/scroll/scrollable/ScrollView.ts +2 -2
- package/src/ts/components/scroll/scrollbar/Bar.ts +4 -4
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +5 -5
- package/src/ts/components/timeline/StaticTimeline.ts +4 -4
- package/src/ts/components/timeline/Timeline.ts +2 -2
- package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
- package/src/ts/utils/math/clampScope.ts +16 -0
- package/src/ts/utils/math/inScope.ts +9 -0
- package/src/ts/utils/math/index.ts +10 -6
- package/src/ts/utils/math/scoped.ts +17 -0
- package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
- package/src/ts/utils/math/scopeProgress.ts +0 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { addEventListener, createElement, IAddEventListener } from 'vevet-dom';
|
|
2
2
|
import { IRemovable } from '../../../utils/types/general';
|
|
3
3
|
import onScroll from '../../../utils/listeners/onScroll';
|
|
4
|
-
import
|
|
4
|
+
import clamp from '../../../utils/math/clamp';
|
|
5
5
|
import { DraggerMove, NDraggerMove } from '../../dragger/DraggerMove';
|
|
6
6
|
import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
|
|
7
7
|
|
|
@@ -293,7 +293,7 @@ export default class Bar {
|
|
|
293
293
|
*/
|
|
294
294
|
protected _renderThumb () {
|
|
295
295
|
// calculate progress
|
|
296
|
-
const progress =
|
|
296
|
+
const progress = clamp(
|
|
297
297
|
this._scrollVal / this.scrollLine,
|
|
298
298
|
[0, 1],
|
|
299
299
|
);
|
|
@@ -321,7 +321,7 @@ export default class Bar {
|
|
|
321
321
|
// calculate thumb sizes
|
|
322
322
|
if (this.prop.autoSize) {
|
|
323
323
|
if (this.isX) {
|
|
324
|
-
const barSize =
|
|
324
|
+
const barSize = clamp(
|
|
325
325
|
this._outerWidth / (this.scrollWidth / (
|
|
326
326
|
this.scrollWidth - scrollLine
|
|
327
327
|
)),
|
|
@@ -329,7 +329,7 @@ export default class Bar {
|
|
|
329
329
|
);
|
|
330
330
|
thumb.style.width = `${barSize}px`;
|
|
331
331
|
} else {
|
|
332
|
-
const barSize =
|
|
332
|
+
const barSize = clamp(
|
|
333
333
|
this._outerHeight / (this.scrollHeight / (
|
|
334
334
|
this.scrollHeight - scrollLine
|
|
335
335
|
)),
|
|
@@ -6,7 +6,7 @@ import { Component, NComponent } from '../../../base/Component';
|
|
|
6
6
|
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
7
7
|
import { AnimationFrame } from '../../animation-frame/AnimationFrame';
|
|
8
8
|
import { ScrollableElement } from '../types';
|
|
9
|
-
import
|
|
9
|
+
import clamp from '../../../utils/math/clamp';
|
|
10
10
|
import { NCallbacks } from '../../../base/Callbacks';
|
|
11
11
|
import { lerp } from '../../../utils/math';
|
|
12
12
|
|
|
@@ -215,7 +215,7 @@ export class SmoothScroll <
|
|
|
215
215
|
? -this.prop.overscroll.max : 0;
|
|
216
216
|
const max = this.maxScrollableWidth
|
|
217
217
|
+ (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
218
|
-
this._targetLeft =
|
|
218
|
+
this._targetLeft = clamp(
|
|
219
219
|
val,
|
|
220
220
|
[min, max],
|
|
221
221
|
);
|
|
@@ -247,7 +247,7 @@ export class SmoothScroll <
|
|
|
247
247
|
? -this.prop.overscroll.max : 0;
|
|
248
248
|
const max = this.maxScrollableHeight
|
|
249
249
|
+ (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
250
|
-
this._targetTop =
|
|
250
|
+
this._targetTop = clamp(
|
|
251
251
|
val,
|
|
252
252
|
[min, max],
|
|
253
253
|
);
|
|
@@ -492,8 +492,8 @@ export class SmoothScroll <
|
|
|
492
492
|
// get sizes
|
|
493
493
|
this._clientWidth = outer.clientWidth;
|
|
494
494
|
this._clientHeight = outer.clientHeight;
|
|
495
|
-
this._scrollWidth =
|
|
496
|
-
this._scrollHeight =
|
|
495
|
+
this._scrollWidth = clamp(container.clientWidth, [this.clientWidth, Infinity]);
|
|
496
|
+
this._scrollHeight = clamp(container.clientHeight, [this.clientHeight, Infinity]);
|
|
497
497
|
|
|
498
498
|
// force instant change
|
|
499
499
|
// it means that after resizing, scrolling will be instantaneous for a while
|
|
@@ -2,8 +2,8 @@ import easingProgress from 'easing-progress';
|
|
|
2
2
|
import { NApplication } from '../../app/Application';
|
|
3
3
|
import { Component, NComponent } from '../../base/Component';
|
|
4
4
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import scoped from '../../utils/math/scoped';
|
|
6
|
+
import clamp from '../../utils/math/clamp';
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -174,8 +174,8 @@ export class StaticTimeline <
|
|
|
174
174
|
for (let index = 0, l = length; index < l; index += 1) {
|
|
175
175
|
const tm = this._nestedTimelines[index];
|
|
176
176
|
// calculate progress of this very timeline
|
|
177
|
-
const tmProgress =
|
|
178
|
-
|
|
177
|
+
const tmProgress = clamp(
|
|
178
|
+
scoped(progressForNested, tm.prop.nestedScope),
|
|
179
179
|
[0, 1],
|
|
180
180
|
);
|
|
181
181
|
tm.progress = tmProgress;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StaticTimeline, NStaticTimeline } from './StaticTimeline';
|
|
2
2
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
3
|
-
import
|
|
3
|
+
import clamp from '../../utils/math/clamp';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -205,7 +205,7 @@ export class Timeline <
|
|
|
205
205
|
|
|
206
206
|
// calculate current progress
|
|
207
207
|
const progressIterator = frameDiff / this.prop.duration / (isReversed ? -1 : 1);
|
|
208
|
-
const progressTarget =
|
|
208
|
+
const progressTarget = clamp(
|
|
209
209
|
this.progress + progressIterator,
|
|
210
210
|
[0, 1],
|
|
211
211
|
);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Clamp the value between two points
|
|
3
3
|
*/
|
|
4
|
-
export default function
|
|
4
|
+
export default function clamp (
|
|
5
5
|
val: number,
|
|
6
|
-
scope
|
|
6
|
+
scope = [0, 1],
|
|
7
7
|
) {
|
|
8
8
|
if (val < scope[0]) {
|
|
9
9
|
return scope[0];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import scoped from './scoped';
|
|
2
|
+
import clamp from './clamp';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get progress relatively to the scope and clamp it within two points
|
|
6
|
+
*/
|
|
7
|
+
export default function clampScoped (
|
|
8
|
+
val: number,
|
|
9
|
+
scope = [0, 1],
|
|
10
|
+
clampScope = [0, 1],
|
|
11
|
+
) {
|
|
12
|
+
return clamp(
|
|
13
|
+
scoped(val, scope),
|
|
14
|
+
clampScope,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import clamp from './clamp';
|
|
2
2
|
import lerp from './lerp';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import scoped from './scoped';
|
|
4
|
+
import spreadScope from './spreadScope';
|
|
5
|
+
import inScope from './inScope';
|
|
6
|
+
import clampScope from './clampScope';
|
|
5
7
|
import wrap from './wrap';
|
|
6
8
|
|
|
7
9
|
export {
|
|
8
|
-
|
|
10
|
+
clamp,
|
|
9
11
|
lerp,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
scoped,
|
|
13
|
+
spreadScope,
|
|
14
|
+
inScope,
|
|
15
|
+
clampScope,
|
|
12
16
|
wrap,
|
|
13
17
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get progress relatively to the scope.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* scope(.35, [0, 1]);
|
|
7
|
+
* // => .5
|
|
8
|
+
* scope(.35, [.25, 1]);
|
|
9
|
+
* // => .133
|
|
10
|
+
*/
|
|
11
|
+
export default function scoped (
|
|
12
|
+
val: number,
|
|
13
|
+
scopeValue = [0, 1],
|
|
14
|
+
) {
|
|
15
|
+
const result = (val - scopeValue[0]) / (scopeValue[1] - scopeValue[0]);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Distribute scope progress among a certain quantity of timelines.
|
|
3
3
|
*/
|
|
4
|
-
export default function
|
|
4
|
+
export default function spreadScope (
|
|
5
5
|
quantity: number,
|
|
6
6
|
shift: number,
|
|
7
7
|
) {
|
|
8
|
-
const timelines: [
|
|
8
|
+
const timelines: number[][] = [];
|
|
9
9
|
// duration for each element
|
|
10
10
|
const duration = 1 / (quantity - shift * (quantity - 1));
|
|
11
11
|
// calculate timelines
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get progress relatively to the scope.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
*
|
|
6
|
-
* scopeProgress(.35, [0, 1]);
|
|
7
|
-
* // => .5
|
|
8
|
-
* scopeProgress(.35, [.25, 1]);
|
|
9
|
-
* // => .133
|
|
10
|
-
*/
|
|
11
|
-
export default function scopeProgress (
|
|
12
|
-
/**
|
|
13
|
-
* Current progress
|
|
14
|
-
*/
|
|
15
|
-
progress: number,
|
|
16
|
-
/**
|
|
17
|
-
* Progress scope
|
|
18
|
-
*/
|
|
19
|
-
scope: [number, number],
|
|
20
|
-
) {
|
|
21
|
-
const result = (progress - scope[0]) / (scope[1] - scope[0]);
|
|
22
|
-
return result;
|
|
23
|
-
}
|