vevet 2.1.0 → 2.4.0

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 (47) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/app/events/Viewport.js +17 -6
  3. package/build/cjs/components/text/SplitText.js +2 -2
  4. package/build/cjs/index.js +2 -0
  5. package/build/cjs/utils/scroll/getScrollValues.js +20 -0
  6. package/build/cjs/utils/scroll/index.js +12 -0
  7. package/build/cjs/utils/scroll/scrollTo.js +41 -0
  8. package/build/cjs/utils/scroll/scrollToElement.js +39 -0
  9. package/build/cjs/utils/scroll/to.js +41 -0
  10. package/build/es/app/events/Viewport.js +16 -6
  11. package/build/es/components/text/SplitText.js +2 -2
  12. package/build/es/index.js +2 -0
  13. package/build/es/utils/scroll/getScrollValues.js +16 -0
  14. package/build/es/utils/scroll/index.js +4 -0
  15. package/build/es/utils/scroll/scrollTo.js +34 -0
  16. package/build/es/utils/scroll/scrollToElement.js +32 -0
  17. package/build/es/utils/scroll/to.js +34 -0
  18. package/build/types/app/events/Viewport.d.ts +9 -1
  19. package/build/types/app/events/Viewport.d.ts.map +1 -1
  20. package/build/types/components/scroll/types.d.ts +2 -5
  21. package/build/types/components/scroll/types.d.ts.map +1 -1
  22. package/build/types/components/text/SplitText.d.ts +5 -0
  23. package/build/types/components/text/SplitText.d.ts.map +1 -1
  24. package/build/types/index.d.ts +2 -0
  25. package/build/types/index.d.ts.map +1 -1
  26. package/build/types/utils/scroll/getScrollValues.d.ts +9 -0
  27. package/build/types/utils/scroll/getScrollValues.d.ts.map +1 -0
  28. package/build/types/utils/scroll/index.d.ts +5 -0
  29. package/build/types/utils/scroll/index.d.ts.map +1 -0
  30. package/build/types/utils/scroll/scrollTo.d.ts +28 -0
  31. package/build/types/utils/scroll/scrollTo.d.ts.map +1 -0
  32. package/build/types/utils/scroll/scrollToElement.d.ts +32 -0
  33. package/build/types/utils/scroll/scrollToElement.d.ts.map +1 -0
  34. package/build/types/utils/scroll/to.d.ts +28 -0
  35. package/build/types/utils/scroll/to.d.ts.map +1 -0
  36. package/build/types/utils/types/general.d.ts +6 -0
  37. package/build/types/utils/types/general.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/ts/app/events/Viewport.ts +18 -6
  40. package/src/ts/components/scroll/types.ts +3 -5
  41. package/src/ts/components/text/SplitText.ts +7 -1
  42. package/src/ts/index.ts +2 -0
  43. package/src/ts/utils/scroll/getScrollValues.ts +20 -0
  44. package/src/ts/utils/scroll/index.ts +9 -0
  45. package/src/ts/utils/scroll/scrollTo.ts +65 -0
  46. package/src/ts/utils/scroll/scrollToElement.ts +74 -0
  47. package/src/ts/utils/types/general.ts +7 -0
@@ -0,0 +1,32 @@
1
+ import { ScrollLike } from '../types/general';
2
+ interface Props {
3
+ /**
4
+ * @default window
5
+ */
6
+ container?: Window | Element | ScrollLike;
7
+ /**
8
+ * The target element
9
+ */
10
+ el: Element | string;
11
+ /**
12
+ * top padding
13
+ * @default 0
14
+ */
15
+ top?: number;
16
+ /**
17
+ * left padding
18
+ * @default 0
19
+ */
20
+ left?: number;
21
+ /**
22
+ * scroll duration
23
+ * @default 250
24
+ */
25
+ duration?: number;
26
+ }
27
+ /**
28
+ * Scroll to element
29
+ */
30
+ export default function scrollToElement({ container, el, top, left, duration, }: Props): Promise<void>;
31
+ export {};
32
+ //# sourceMappingURL=scrollToElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollToElement.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/scrollToElement.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,UAAU,KAAK;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1C;;OAEG;IACH,EAAE,EAAE,OAAO,GAAG,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAE,EACrC,SAAkB,EAClB,EAAE,EACF,GAAO,EACP,IAAQ,EACR,QAAc,GACjB,EAAE,KAAK,iBAgCP"}
@@ -0,0 +1,28 @@
1
+ import { ScrollLike } from '../types/general';
2
+ interface Props {
3
+ /**
4
+ * @default window
5
+ */
6
+ container?: Window | Element | ScrollLike;
7
+ /**
8
+ * top padding
9
+ * @default 0
10
+ */
11
+ top?: number;
12
+ /**
13
+ * left padding
14
+ * @default 0
15
+ */
16
+ left?: number;
17
+ /**
18
+ * scroll duration
19
+ * @default 250
20
+ */
21
+ duration?: number;
22
+ }
23
+ /**
24
+ * Scroll to coordinates
25
+ */
26
+ export default function scrollTo({ container, top, left, duration, }: Props): Promise<void>;
27
+ export {};
28
+ //# sourceMappingURL=to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,UAAU,KAAK;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1C;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAE,EAC9B,SAAkB,EAClB,GAAO,EACP,IAAQ,EACR,QAAc,GACjB,EAAE,KAAK,iBA8BP"}
@@ -4,4 +4,10 @@ export interface IRemovable {
4
4
  export interface IDestroyable {
5
5
  destroy: () => void;
6
6
  }
7
+ export interface ScrollLike {
8
+ scrollTop: number;
9
+ scrollLeft: number;
10
+ scrollTo(options: ScrollToOptions): void;
11
+ scrollTo(x: number, y: number): void;
12
+ }
7
13
  //# sourceMappingURL=general.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/types/general.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB"}
1
+ {"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/types/general.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vevet",
3
- "version": "2.1.0",
3
+ "version": "2.4.0",
4
4
  "description": "VEVET - A JavaScript library",
5
5
  "browserslist": [
6
6
  "since 2015"
@@ -323,7 +323,12 @@ export class Viewport extends Callbacks<
323
323
  /**
324
324
  * Launch callbacks on resize.
325
325
  */
326
- protected _onResize () {
326
+ protected _onResize (
327
+ /**
328
+ * force all callbacks
329
+ */
330
+ force = false,
331
+ ) {
327
332
  // copy previous values
328
333
  const prevWidth = this._prevSize.w;
329
334
  const prevHeight = this._prevSize.h;
@@ -342,29 +347,36 @@ export class Viewport extends Callbacks<
342
347
  };
343
348
 
344
349
  // only when width is changed
345
- if (width !== prevWidth && height === prevHeight) {
350
+ if (force || (width !== prevWidth && height === prevHeight)) {
346
351
  this.tbt('w_', changes);
347
352
  }
348
353
  // only when height is changed
349
- if (height !== prevHeight && width === prevWidth) {
354
+ if (force || (height !== prevHeight && width === prevWidth)) {
350
355
  this.tbt('h_', changes);
351
356
  }
352
357
  // when height & width are changed
353
- if (width !== prevWidth && height !== prevHeight) {
358
+ if (force || (width !== prevWidth && height !== prevHeight)) {
354
359
  this.tbt('wh', changes);
355
360
  this.tbt('hw', changes);
356
361
  }
357
362
  // when width is changed
358
- if (width !== prevWidth) {
363
+ if (force || width !== prevWidth) {
359
364
  this.tbt('w', changes);
360
365
  }
361
366
  // when height changed
362
- if (height !== prevHeight) {
367
+ if (force || height !== prevHeight) {
363
368
  this.tbt('h', changes);
364
369
  }
365
370
 
366
371
  // on any change
367
372
  this.tbt('', changes);
368
373
  }
374
+
375
+ /**
376
+ * Force launching all callbacks
377
+ */
378
+ public forceResize () {
379
+ this._onResize(true);
380
+ }
369
381
  }
370
382
 
@@ -1,8 +1,6 @@
1
- export interface ScrollableElement {
2
- scrollTop: number;
3
- scrollTo(options: ScrollToOptions): void;
4
- scrollTo(x: number, y: number): void;
5
- scrollLeft: number;
1
+ import { ScrollLike } from '../../utils/types/general';
2
+
3
+ export interface ScrollableElement extends ScrollLike {
6
4
  scrollWidth: number;
7
5
  scrollHeight: number;
8
6
  clientWidth: number;
@@ -16,6 +16,11 @@ export namespace NSplitText {
16
16
  * @default '#v-split-text'
17
17
  */
18
18
  container?: string | Element;
19
+ /**
20
+ * Text content
21
+ * @default 'innerText'
22
+ */
23
+ textSource?: 'textContent' | 'innerText' | 'innerHTML';
19
24
  /**
20
25
  * If need to split text into letters.
21
26
  * @default true
@@ -92,6 +97,7 @@ export class SplitText <
92
97
  return {
93
98
  ...super._getDefaultProp(),
94
99
  container: `#${this.prefix}`,
100
+ textSource: 'innerText',
95
101
  appendLetters: true,
96
102
  appendLines: false,
97
103
  viewportTarget: '',
@@ -168,7 +174,7 @@ export class SplitText <
168
174
 
169
175
  // get initial text
170
176
  this._initHTML = this._container.innerHTML;
171
- const innerText = this._container.innerText.trim() || this._container.innerHTML.trim();
177
+ const innerText = this._container[this.prop.textSource]!.trim();
172
178
  this._initText = innerText || 'no rendered text';
173
179
  this._initText = this._initText.replace(/\s+\n/gm, '\n');
174
180
  this._initText = this._initText.replace(/<br>/gm, String.fromCharCode(10));
package/src/ts/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as common from './utils/common';
2
2
  import * as listeners from './utils/listeners';
3
3
  import * as math from './utils/math';
4
+ import * as scroll from './utils/scroll';
4
5
 
5
6
  import * as GeneralTypes from './utils/types/general';
6
7
 
@@ -48,6 +49,7 @@ const utils = {
48
49
  common,
49
50
  listeners,
50
51
  math,
52
+ scroll,
51
53
  };
52
54
 
53
55
 
@@ -0,0 +1,20 @@
1
+ import { ScrollLike } from '../types/general';
2
+
3
+ /**
4
+ * Get scroll values of a certain element
5
+ */
6
+ export default function getScrollValues (
7
+ selector: (Window | Element | ScrollLike | undefined) = window,
8
+ ) {
9
+ if (selector) {
10
+ const scrollTop = selector instanceof Window
11
+ ? selector.pageYOffset : selector.scrollTop;
12
+ const scrollLeft = selector instanceof Window
13
+ ? selector.pageXOffset : selector.scrollLeft;
14
+ return {
15
+ scrollTop,
16
+ scrollLeft,
17
+ };
18
+ }
19
+ return undefined;
20
+ }
@@ -0,0 +1,9 @@
1
+ import getValues from './getScrollValues';
2
+ import scrollTo from './scrollTo';
3
+ import scrollToElement from './scrollToElement';
4
+
5
+ export {
6
+ getValues,
7
+ scrollTo as to,
8
+ scrollToElement as toElement,
9
+ };
@@ -0,0 +1,65 @@
1
+ import { Timeline } from '../../components/timeline/Timeline';
2
+ import { ScrollLike } from '../types/general';
3
+ import getScrollValues from './getScrollValues';
4
+
5
+ interface Props {
6
+ /**
7
+ * @default window
8
+ */
9
+ container?: Window | Element | ScrollLike;
10
+ /**
11
+ * top padding
12
+ * @default 0
13
+ */
14
+ top?: number;
15
+ /**
16
+ * left padding
17
+ * @default 0
18
+ */
19
+ left?: number;
20
+ /**
21
+ * scroll duration
22
+ * @default 250
23
+ */
24
+ duration?: number;
25
+ }
26
+
27
+ /**
28
+ * Scroll to coordinates
29
+ */
30
+ export default function scrollTo ({
31
+ container = window,
32
+ top = 0,
33
+ left = 0,
34
+ duration = 250,
35
+ }: Props) {
36
+ return new Promise<void>((
37
+ resolve, reject,
38
+ ) => {
39
+ // save start values
40
+ const startValues = getScrollValues(container);
41
+ if (startValues) {
42
+ // create animation
43
+ const timeline = new Timeline({
44
+ duration,
45
+ });
46
+ timeline.addCallback('progress', (data) => {
47
+ if (container) {
48
+ container.scrollTo({
49
+ top: startValues.scrollTop
50
+ + (top - startValues.scrollTop) * data.easing,
51
+ left: startValues.scrollLeft
52
+ + (left - startValues.scrollLeft) * data.easing,
53
+ behavior: 'auto',
54
+ });
55
+ }
56
+ });
57
+ timeline.addCallback('end', () => {
58
+ resolve();
59
+ });
60
+ timeline.play();
61
+ return;
62
+ }
63
+ reject();
64
+ });
65
+ }
@@ -0,0 +1,74 @@
1
+ import { selectOne } from 'vevet-dom';
2
+ import { ScrollLike } from '../types/general';
3
+ import getScrollValues from './getScrollValues';
4
+ import clamp from '../math/clamp';
5
+ import scrollTo from './scrollTo';
6
+
7
+ interface Props {
8
+ /**
9
+ * @default window
10
+ */
11
+ container?: Window | Element | ScrollLike;
12
+ /**
13
+ * The target element
14
+ */
15
+ el: Element | string;
16
+ /**
17
+ * top padding
18
+ * @default 0
19
+ */
20
+ top?: number;
21
+ /**
22
+ * left padding
23
+ * @default 0
24
+ */
25
+ left?: number;
26
+ /**
27
+ * scroll duration
28
+ * @default 250
29
+ */
30
+ duration?: number;
31
+ }
32
+
33
+ /**
34
+ * Scroll to element
35
+ */
36
+ export default function scrollToElement ({
37
+ container = window,
38
+ el,
39
+ top = 0,
40
+ left = 0,
41
+ duration = 250,
42
+ }: Props) {
43
+ return new Promise<void>((
44
+ resolve, reject,
45
+ ) => {
46
+ const startValues = getScrollValues(container);
47
+ if (startValues) {
48
+ const element = selectOne(el);
49
+ if (element) {
50
+ const bounding = element.getBoundingClientRect();
51
+ const toTop = clamp(
52
+ bounding.top + startValues.scrollTop - top,
53
+ [0, Infinity],
54
+ );
55
+ const toLeft = clamp(
56
+ bounding.left + startValues.scrollLeft - left,
57
+ [0, Infinity],
58
+ );
59
+ scrollTo({
60
+ container,
61
+ top: toTop,
62
+ left: toLeft,
63
+ duration,
64
+ }).then(() => {
65
+ resolve();
66
+ }).catch(() => {
67
+ reject();
68
+ });
69
+ }
70
+ return;
71
+ }
72
+ reject();
73
+ });
74
+ }
@@ -5,3 +5,10 @@ export interface IRemovable {
5
5
  export interface IDestroyable {
6
6
  destroy: () => void;
7
7
  }
8
+
9
+ export interface ScrollLike {
10
+ scrollTop: number;
11
+ scrollLeft: number;
12
+ scrollTo(options: ScrollToOptions): void;
13
+ scrollTo(x: number, y: number): void;
14
+ }