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.
Files changed (51) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
  3. package/build/cjs/components/scroll/scrollable/ScrollView.js +2 -2
  4. package/build/cjs/components/scroll/scrollbar/Bar.js +4 -4
  5. package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +5 -5
  6. package/build/cjs/components/timeline/StaticTimeline.js +3 -3
  7. package/build/cjs/components/timeline/Timeline.js +2 -2
  8. package/build/cjs/utils/math/clamp.js +16 -0
  9. package/build/cjs/utils/math/clampScope.js +16 -0
  10. package/build/cjs/utils/math/inScope.js +10 -0
  11. package/build/cjs/utils/math/index.js +11 -7
  12. package/build/cjs/utils/math/scoped.js +18 -0
  13. package/build/cjs/utils/math/spreadScope.js +18 -0
  14. package/build/es/components/animation-frame/AnimationFrame.js +2 -2
  15. package/build/es/components/scroll/scrollable/ScrollView.js +2 -2
  16. package/build/es/components/scroll/scrollbar/Bar.js +4 -4
  17. package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +5 -5
  18. package/build/es/components/timeline/StaticTimeline.js +3 -3
  19. package/build/es/components/timeline/Timeline.js +2 -2
  20. package/build/es/utils/math/clamp.js +12 -0
  21. package/build/es/utils/math/clampScope.js +8 -0
  22. package/build/es/utils/math/inScope.js +6 -0
  23. package/build/es/utils/math/index.js +6 -4
  24. package/build/es/utils/math/scoped.js +14 -0
  25. package/build/es/utils/math/spreadScope.js +15 -0
  26. package/build/types/utils/math/clamp.d.ts +5 -0
  27. package/build/types/utils/math/clamp.d.ts.map +1 -0
  28. package/build/types/utils/math/clampScope.d.ts +5 -0
  29. package/build/types/utils/math/clampScope.d.ts.map +1 -0
  30. package/build/types/utils/math/inScope.d.ts +5 -0
  31. package/build/types/utils/math/inScope.d.ts.map +1 -0
  32. package/build/types/utils/math/index.d.ts +6 -4
  33. package/build/types/utils/math/index.d.ts.map +1 -1
  34. package/build/types/utils/math/scoped.d.ts +12 -0
  35. package/build/types/utils/math/scoped.d.ts.map +1 -0
  36. package/build/types/utils/math/spreadScope.d.ts +5 -0
  37. package/build/types/utils/math/spreadScope.d.ts.map +1 -0
  38. package/package.json +1 -1
  39. package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
  40. package/src/ts/components/scroll/scrollable/ScrollView.ts +2 -2
  41. package/src/ts/components/scroll/scrollbar/Bar.ts +4 -4
  42. package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +5 -5
  43. package/src/ts/components/timeline/StaticTimeline.ts +4 -4
  44. package/src/ts/components/timeline/Timeline.ts +2 -2
  45. package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
  46. package/src/ts/utils/math/clampScope.ts +16 -0
  47. package/src/ts/utils/math/inScope.ts +9 -0
  48. package/src/ts/utils/math/index.ts +10 -6
  49. package/src/ts/utils/math/scoped.ts +17 -0
  50. package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
  51. 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 boundVal from '../../../utils/math/boundVal';
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 = boundVal(
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 = boundVal(
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 = boundVal(
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 boundVal from '../../../utils/math/boundVal';
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 = boundVal(
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 = boundVal(
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 = boundVal(container.clientWidth, [this.clientWidth, Infinity]);
496
- this._scrollHeight = boundVal(container.clientHeight, [this.clientHeight, Infinity]);
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 scopeProgress from '../../utils/math/scopeProgress';
6
- import boundVal from '../../utils/math/boundVal';
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 = boundVal(
178
- scopeProgress(progressForNested, tm.prop.nestedScope),
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 boundVal from '../../utils/math/boundVal';
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 = boundVal(
208
+ const progressTarget = clamp(
209
209
  this.progress + progressIterator,
210
210
  [0, 1],
211
211
  );
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Bound a value between two points
2
+ * Clamp the value between two points
3
3
  */
4
- export default function boundVal (
4
+ export default function clamp (
5
5
  val: number,
6
- scope: [number, number] = [0, 1],
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
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Check if the value is within the scope
3
+ */
4
+ export default function inScope (
5
+ val: number,
6
+ scopeValue = [0, 1],
7
+ ) {
8
+ return val >= scopeValue[0] && val <= scopeValue[1];
9
+ }
@@ -1,13 +1,17 @@
1
- import boundVal from './boundVal';
1
+ import clamp from './clamp';
2
2
  import lerp from './lerp';
3
- import scopeProgress from './scopeProgress';
4
- import spreadScopeProgress from './spreadScopeProgress';
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
- boundVal,
10
+ clamp,
9
11
  lerp,
10
- scopeProgress,
11
- spreadScopeProgress,
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 spreadScopeProgress (
4
+ export default function spreadScope (
5
5
  quantity: number,
6
6
  shift: number,
7
7
  ) {
8
- const timelines: [number, number][] = [];
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
- }