vevet 3.13.1 → 3.14.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 (216) hide show
  1. package/lib/cjs/Application/events/PageLoad/index.js +2 -1
  2. package/lib/cjs/Application/events/PageLoad/index.js.map +1 -1
  3. package/lib/cjs/Application/events/Viewport/index.js +16 -27
  4. package/lib/cjs/Application/events/Viewport/index.js.map +1 -1
  5. package/lib/cjs/Application/index.js +0 -18
  6. package/lib/cjs/Application/index.js.map +1 -1
  7. package/lib/cjs/base/Callbacks/index.js +0 -28
  8. package/lib/cjs/base/Callbacks/index.js.map +1 -1
  9. package/lib/cjs/base/Module/index.js +4 -22
  10. package/lib/cjs/base/Module/index.js.map +1 -1
  11. package/lib/cjs/base/MutableProps/index.js +3 -3
  12. package/lib/cjs/base/MutableProps/index.js.map +1 -1
  13. package/lib/cjs/components/BaseTimeline/index.js +15 -14
  14. package/lib/cjs/components/BaseTimeline/index.js.map +1 -1
  15. package/lib/cjs/components/Ctx2D/index.js +2 -2
  16. package/lib/cjs/components/Ctx2D/index.js.map +1 -1
  17. package/lib/cjs/components/CustomCursor/index.js +3 -2
  18. package/lib/cjs/components/CustomCursor/index.js.map +1 -1
  19. package/lib/cjs/components/DraggerBase/index.js +2 -1
  20. package/lib/cjs/components/DraggerBase/index.js.map +1 -1
  21. package/lib/cjs/components/Marquee/index.js +3 -2
  22. package/lib/cjs/components/Marquee/index.js.map +1 -1
  23. package/lib/cjs/components/Preloader/index.js +3 -31
  24. package/lib/cjs/components/Preloader/index.js.map +1 -1
  25. package/lib/cjs/components/ProgressPreloader/index.js +5 -3
  26. package/lib/cjs/components/ProgressPreloader/index.js.map +1 -1
  27. package/lib/cjs/components/ScrollBar/index.js +4 -3
  28. package/lib/cjs/components/ScrollBar/index.js.map +1 -1
  29. package/lib/cjs/components/ScrollView/index.js +3 -2
  30. package/lib/cjs/components/ScrollView/index.js.map +1 -1
  31. package/lib/cjs/components/SectionScrollProgress/index.js +3 -2
  32. package/lib/cjs/components/SectionScrollProgress/index.js.map +1 -1
  33. package/lib/cjs/components/SlideProgress/index.js +1 -1
  34. package/lib/cjs/components/SlideProgress/index.js.map +1 -1
  35. package/lib/cjs/components/SmoothScroll/index.js +2 -1
  36. package/lib/cjs/components/SmoothScroll/index.js.map +1 -1
  37. package/lib/cjs/components/SmoothScrollKeyboardPlugin/index.js +2 -1
  38. package/lib/cjs/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  39. package/lib/cjs/components/SplitText/index.js +68 -202
  40. package/lib/cjs/components/SplitText/index.js.map +1 -1
  41. package/lib/cjs/components/SplitText/utils/splitBase.js +31 -0
  42. package/lib/cjs/components/SplitText/utils/splitBase.js.map +1 -0
  43. package/lib/cjs/components/SplitText/utils/wrapLetters.js +30 -0
  44. package/lib/cjs/components/SplitText/utils/wrapLetters.js.map +1 -0
  45. package/lib/cjs/components/SplitText/utils/wrapLines.js +78 -0
  46. package/lib/cjs/components/SplitText/utils/wrapLines.js.map +1 -0
  47. package/lib/cjs/components/SplitText/utils/wrapWords.js +57 -0
  48. package/lib/cjs/components/SplitText/utils/wrapWords.js.map +1 -0
  49. package/lib/cjs/components/Timeline/index.js +7 -7
  50. package/lib/cjs/components/Timeline/index.js.map +1 -1
  51. package/lib/cjs/utils/internal/getApp.js +8 -0
  52. package/lib/cjs/utils/internal/getApp.js.map +1 -0
  53. package/lib/cjs/utils/scroll/scrollTo.js +3 -3
  54. package/lib/cjs/utils/scroll/scrollTo.js.map +1 -1
  55. package/lib/cjs/version.js +1 -1
  56. package/lib/esm/Application/events/PageLoad/index.js +2 -1
  57. package/lib/esm/Application/events/PageLoad/index.js.map +1 -1
  58. package/lib/esm/Application/events/Viewport/index.js +16 -26
  59. package/lib/esm/Application/events/Viewport/index.js.map +1 -1
  60. package/lib/esm/Application/index.js +0 -18
  61. package/lib/esm/Application/index.js.map +1 -1
  62. package/lib/esm/base/Callbacks/index.js +0 -23
  63. package/lib/esm/base/Callbacks/index.js.map +1 -1
  64. package/lib/esm/base/Module/index.js +4 -17
  65. package/lib/esm/base/Module/index.js.map +1 -1
  66. package/lib/esm/base/MutableProps/index.js +3 -3
  67. package/lib/esm/base/MutableProps/index.js.map +1 -1
  68. package/lib/esm/components/BaseTimeline/index.js +16 -15
  69. package/lib/esm/components/BaseTimeline/index.js.map +1 -1
  70. package/lib/esm/components/Ctx2D/index.js +2 -2
  71. package/lib/esm/components/Ctx2D/index.js.map +1 -1
  72. package/lib/esm/components/CustomCursor/index.js +3 -2
  73. package/lib/esm/components/CustomCursor/index.js.map +1 -1
  74. package/lib/esm/components/DraggerBase/index.js +2 -1
  75. package/lib/esm/components/DraggerBase/index.js.map +1 -1
  76. package/lib/esm/components/Marquee/index.js +3 -2
  77. package/lib/esm/components/Marquee/index.js.map +1 -1
  78. package/lib/esm/components/Preloader/index.js +3 -19
  79. package/lib/esm/components/Preloader/index.js.map +1 -1
  80. package/lib/esm/components/ProgressPreloader/index.js +4 -3
  81. package/lib/esm/components/ProgressPreloader/index.js.map +1 -1
  82. package/lib/esm/components/ScrollBar/index.js +4 -3
  83. package/lib/esm/components/ScrollBar/index.js.map +1 -1
  84. package/lib/esm/components/ScrollView/index.js +3 -2
  85. package/lib/esm/components/ScrollView/index.js.map +1 -1
  86. package/lib/esm/components/SectionScrollProgress/index.js +3 -2
  87. package/lib/esm/components/SectionScrollProgress/index.js.map +1 -1
  88. package/lib/esm/components/SlideProgress/index.js +1 -1
  89. package/lib/esm/components/SlideProgress/index.js.map +1 -1
  90. package/lib/esm/components/SmoothScroll/index.js +2 -1
  91. package/lib/esm/components/SmoothScroll/index.js.map +1 -1
  92. package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js +2 -1
  93. package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  94. package/lib/esm/components/SplitText/index.js +55 -193
  95. package/lib/esm/components/SplitText/index.js.map +1 -1
  96. package/lib/esm/components/SplitText/utils/splitBase.js +26 -0
  97. package/lib/esm/components/SplitText/utils/splitBase.js.map +1 -0
  98. package/lib/esm/components/SplitText/utils/wrapLetters.js +25 -0
  99. package/lib/esm/components/SplitText/utils/wrapLetters.js.map +1 -0
  100. package/lib/esm/components/SplitText/utils/wrapLines.js +68 -0
  101. package/lib/esm/components/SplitText/utils/wrapLines.js.map +1 -0
  102. package/lib/esm/components/SplitText/utils/wrapWords.js +43 -0
  103. package/lib/esm/components/SplitText/utils/wrapWords.js.map +1 -0
  104. package/lib/esm/components/Timeline/index.js +7 -7
  105. package/lib/esm/components/Timeline/index.js.map +1 -1
  106. package/lib/esm/utils/internal/getApp.js +4 -0
  107. package/lib/esm/utils/internal/getApp.js.map +1 -0
  108. package/lib/esm/utils/scroll/scrollTo.js +3 -3
  109. package/lib/esm/utils/scroll/scrollTo.js.map +1 -1
  110. package/lib/esm/version.js +1 -1
  111. package/lib/types/Application/events/PageLoad/index.d.ts.map +1 -1
  112. package/lib/types/Application/events/Viewport/index.d.ts +0 -4
  113. package/lib/types/Application/events/Viewport/index.d.ts.map +1 -1
  114. package/lib/types/Application/index.d.ts +0 -2
  115. package/lib/types/Application/index.d.ts.map +1 -1
  116. package/lib/types/Application/types.d.ts +2 -3
  117. package/lib/types/Application/types.d.ts.map +1 -1
  118. package/lib/types/base/Callbacks/index.d.ts +0 -16
  119. package/lib/types/base/Callbacks/index.d.ts.map +1 -1
  120. package/lib/types/base/Module/index.d.ts +1 -6
  121. package/lib/types/base/Module/index.d.ts.map +1 -1
  122. package/lib/types/base/Module/types.d.ts +2 -2
  123. package/lib/types/base/Module/types.d.ts.map +1 -1
  124. package/lib/types/base/MutableProps/index.d.ts +0 -4
  125. package/lib/types/base/MutableProps/index.d.ts.map +1 -1
  126. package/lib/types/base/Plugin/types.d.ts +2 -2
  127. package/lib/types/base/Plugin/types.d.ts.map +1 -1
  128. package/lib/types/components/AnimationFrame/index.d.ts +1 -1
  129. package/lib/types/components/BaseTimeline/index.d.ts +7 -7
  130. package/lib/types/components/BaseTimeline/index.d.ts.map +1 -1
  131. package/lib/types/components/BaseTimeline/types.d.ts +2 -2
  132. package/lib/types/components/BaseTimeline/types.d.ts.map +1 -1
  133. package/lib/types/components/Ctx2D/index.d.ts +1 -1
  134. package/lib/types/components/Ctx2D/index.d.ts.map +1 -1
  135. package/lib/types/components/Ctx2DPrerender/index.d.ts +3 -3
  136. package/lib/types/components/Ctx2DPrerender/index.d.ts.map +1 -1
  137. package/lib/types/components/CustomCursor/index.d.ts +1 -1
  138. package/lib/types/components/CustomCursor/index.d.ts.map +1 -1
  139. package/lib/types/components/DraggerBase/index.d.ts +1 -1
  140. package/lib/types/components/DraggerBase/index.d.ts.map +1 -1
  141. package/lib/types/components/DraggerDirection/index.d.ts +1 -1
  142. package/lib/types/components/DraggerMove/index.d.ts +1 -1
  143. package/lib/types/components/Marquee/index.d.ts +1 -1
  144. package/lib/types/components/Marquee/index.d.ts.map +1 -1
  145. package/lib/types/components/Preloader/index.d.ts +1 -13
  146. package/lib/types/components/Preloader/index.d.ts.map +1 -1
  147. package/lib/types/components/ProgressPreloader/index.d.ts +1 -1
  148. package/lib/types/components/ProgressPreloader/index.d.ts.map +1 -1
  149. package/lib/types/components/ScrollBar/index.d.ts +1 -1
  150. package/lib/types/components/ScrollBar/index.d.ts.map +1 -1
  151. package/lib/types/components/ScrollView/index.d.ts +1 -1
  152. package/lib/types/components/ScrollView/index.d.ts.map +1 -1
  153. package/lib/types/components/SectionScrollProgress/index.d.ts +1 -1
  154. package/lib/types/components/SectionScrollProgress/index.d.ts.map +1 -1
  155. package/lib/types/components/SlideProgress/index.d.ts +1 -1
  156. package/lib/types/components/SmoothScroll/index.d.ts +1 -1
  157. package/lib/types/components/SmoothScroll/index.d.ts.map +1 -1
  158. package/lib/types/components/SmoothScrollDragPlugin/index.d.ts +1 -1
  159. package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts +1 -1
  160. package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts.map +1 -1
  161. package/lib/types/components/SplitText/index.d.ts +15 -13
  162. package/lib/types/components/SplitText/index.d.ts.map +1 -1
  163. package/lib/types/components/SplitText/types.d.ts +17 -13
  164. package/lib/types/components/SplitText/types.d.ts.map +1 -1
  165. package/lib/types/components/SplitText/utils/splitBase.d.ts +17 -0
  166. package/lib/types/components/SplitText/utils/splitBase.d.ts.map +1 -0
  167. package/lib/types/components/SplitText/utils/wrapLetters.d.ts +12 -0
  168. package/lib/types/components/SplitText/utils/wrapLetters.d.ts.map +1 -0
  169. package/lib/types/components/SplitText/utils/wrapLines.d.ts +17 -0
  170. package/lib/types/components/SplitText/utils/wrapLines.d.ts.map +1 -0
  171. package/lib/types/components/SplitText/utils/wrapWords.d.ts +10 -0
  172. package/lib/types/components/SplitText/utils/wrapWords.d.ts.map +1 -0
  173. package/lib/types/components/Timeline/index.d.ts +2 -2
  174. package/lib/types/utils/internal/getApp.d.ts +2 -0
  175. package/lib/types/utils/internal/getApp.d.ts.map +1 -0
  176. package/lib/types/version.d.ts +1 -1
  177. package/package.json +1 -1
  178. package/src/Application/events/PageLoad/index.ts +2 -1
  179. package/src/Application/events/Viewport/index.ts +17 -29
  180. package/src/Application/index.ts +0 -22
  181. package/src/Application/types.ts +2 -3
  182. package/src/base/Callbacks/index.ts +0 -31
  183. package/src/base/Module/index.ts +4 -22
  184. package/src/base/Module/types.ts +4 -3
  185. package/src/base/MutableProps/index.ts +3 -8
  186. package/src/base/Plugin/types.ts +2 -2
  187. package/src/components/BaseTimeline/index.ts +19 -18
  188. package/src/components/BaseTimeline/stories/Basic.tsx +3 -3
  189. package/src/components/BaseTimeline/stories/Nested.tsx +3 -3
  190. package/src/components/BaseTimeline/types.ts +2 -2
  191. package/src/components/Ctx2D/index.ts +2 -2
  192. package/src/components/CustomCursor/index.ts +3 -2
  193. package/src/components/DraggerBase/index.ts +2 -1
  194. package/src/components/Marquee/index.ts +3 -2
  195. package/src/components/Preloader/index.ts +3 -28
  196. package/src/components/ProgressPreloader/index.ts +4 -3
  197. package/src/components/ScrollBar/index.ts +4 -3
  198. package/src/components/ScrollView/index.ts +3 -2
  199. package/src/components/SectionScrollProgress/index.ts +3 -2
  200. package/src/components/SlideProgress/index.ts +1 -1
  201. package/src/components/SmoothScroll/index.ts +2 -1
  202. package/src/components/SmoothScrollKeyboardPlugin/index.ts +2 -1
  203. package/src/components/SplitText/index.ts +64 -234
  204. package/src/components/SplitText/stories/index.stories.tsx +13 -4
  205. package/src/components/SplitText/stories/index.tsx +26 -8
  206. package/src/components/SplitText/types.ts +17 -14
  207. package/src/components/SplitText/utils/splitBase.ts +49 -0
  208. package/src/components/SplitText/utils/wrapLetters.ts +41 -0
  209. package/src/components/SplitText/utils/wrapLines.ts +98 -0
  210. package/src/components/SplitText/utils/wrapWords.ts +64 -0
  211. package/src/components/Timeline/index.ts +7 -7
  212. package/src/components/Timeline/stories/Basic.tsx +4 -4
  213. package/src/components/Timeline/stories/Nested.tsx +5 -5
  214. package/src/utils/internal/getApp.ts +3 -0
  215. package/src/utils/scroll/scrollTo.ts +3 -3
  216. package/src/version.ts +1 -1
@@ -1,26 +1,44 @@
1
+ /* eslint-disable react/no-danger */
1
2
  import React, { FC, useEffect, useRef } from 'react';
2
- import { SplitText, NSplitText } from '..';
3
+ import { NSplitText } from '../types';
4
+ import { SplitText } from '..';
3
5
 
4
6
  interface IProps extends Omit<NSplitText.IStaticProps, 'parent' | 'container'> {
5
7
  text: string;
6
8
  }
7
9
 
8
- export const Component: FC<IProps> = ({ text, ...props }) => {
10
+ export const Component: FC<IProps> = ({ text, hasLetters, hasLines }) => {
9
11
  const ref = useRef<HTMLHeadingElement>(null);
10
12
 
11
13
  useEffect(() => {
12
- if (!ref.current) {
14
+ const container = ref.current;
15
+ if (!container) {
13
16
  return undefined;
14
17
  }
15
18
 
16
19
  const instance = new SplitText({
17
- ...props,
18
- container: ref.current,
20
+ container,
21
+ hasLetters,
22
+ hasLines,
19
23
  });
20
24
 
21
25
  return () => instance.destroy();
22
- }, [props]);
26
+ }, [hasLetters, hasLines]);
23
27
 
24
- // eslint-disable-next-line react/no-danger
25
- return <h1 ref={ref} dangerouslySetInnerHTML={{ __html: text }} />;
28
+ const style = { fontSize: '30px', fontKerning: 'none' } as any;
29
+
30
+ return (
31
+ <>
32
+ <h1>Vevet</h1>
33
+
34
+ <div ref={ref} style={style} dangerouslySetInnerHTML={{ __html: text }} />
35
+
36
+ <br />
37
+ <br />
38
+
39
+ <h1>Reference text</h1>
40
+
41
+ <div style={style} dangerouslySetInnerHTML={{ __html: text }} />
42
+ </>
43
+ );
26
44
  };
@@ -2,18 +2,11 @@ import { NComponent } from '@/base/Component/types';
2
2
  import { TOnResizeTarget } from '@/utils/listeners/onResize';
3
3
 
4
4
  export namespace NSplitText {
5
- export type TTextSource = 'textContent' | 'innerText' | 'innerHTML';
6
-
7
5
  export interface IStaticProps extends NComponent.IStaticProps {
8
6
  /**
9
7
  * The text container. You may use a CSS selector or the element itself
10
8
  */
11
9
  container: string | Element;
12
- /**
13
- * Text content
14
- * @default 'innerText'
15
- */
16
- textSource?: TTextSource;
17
10
  /**
18
11
  * If need to split text into letters.
19
12
  * @default true
@@ -24,6 +17,21 @@ export namespace NSplitText {
24
17
  * @default false
25
18
  */
26
19
  hasLines?: boolean;
20
+ /**
21
+ * Letter tagName
22
+ * @default `span`
23
+ */
24
+ letterTag?: keyof HTMLElementTagNameMap;
25
+ /**
26
+ * Word tagName
27
+ * @default `span`
28
+ */
29
+ wordTag?: keyof HTMLElementTagNameMap;
30
+ /**
31
+ * Line tagName
32
+ * @default `span`
33
+ */
34
+ lineTag?: keyof HTMLElementTagNameMap;
27
35
  /**
28
36
  * Viewport target
29
37
  * @default 'any'
@@ -44,22 +52,17 @@ export namespace NSplitText {
44
52
 
45
53
  export interface ILine {
46
54
  element: HTMLElement;
47
- textContent: string;
48
55
  words: NSplitText.IWord[];
49
56
  }
50
57
 
51
58
  export interface IWord {
52
59
  element: HTMLElement;
53
- textContent: string;
54
- hasNewLine: boolean;
60
+ text: string;
55
61
  letters: NSplitText.ILetter[];
56
- br?: HTMLBRElement;
57
- whitespace?: Text;
58
62
  }
59
63
 
60
64
  export interface ILetter {
61
65
  element: HTMLElement;
62
- textContent: string;
63
- word: NSplitText.IWord;
66
+ text: string;
64
67
  }
65
68
  }
@@ -0,0 +1,49 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import { NSplitText } from '../types';
3
+ import { wrapLetters } from './wrapLetters';
4
+ import { wrapWords } from './wrapWords';
5
+
6
+ interface IProps {
7
+ container: HTMLElement;
8
+ letterClassName: string;
9
+ wordClassName: string;
10
+ hasLetters: boolean;
11
+ letterTag: keyof HTMLElementTagNameMap;
12
+ wordTag: keyof HTMLElementTagNameMap;
13
+ }
14
+
15
+ /** Split text into letters & words */
16
+ export function splitBase({
17
+ container,
18
+ letterClassName,
19
+ wordClassName,
20
+ hasLetters,
21
+ letterTag,
22
+ wordTag,
23
+ }: IProps) {
24
+ const helper = container.cloneNode(true) as HTMLElement;
25
+
26
+ const words = wrapWords({
27
+ container: helper,
28
+ classname: wordClassName,
29
+ tagName: wordTag,
30
+ });
31
+
32
+ const letters: NSplitText.ILetter[] = [];
33
+
34
+ if (hasLetters) {
35
+ const wrappedLetters = wrapLetters({
36
+ words,
37
+ classname: letterClassName,
38
+ tagName: letterTag,
39
+ });
40
+
41
+ letters.push(...wrappedLetters.letters);
42
+ }
43
+
44
+ return {
45
+ helper,
46
+ words,
47
+ letters,
48
+ };
49
+ }
@@ -0,0 +1,41 @@
1
+ import { NSplitText } from '../types';
2
+
3
+ interface IProps {
4
+ words: NSplitText.IWord[];
5
+ classname: string;
6
+ tagName: keyof HTMLElementTagNameMap;
7
+ }
8
+
9
+ /** Wrap each word inside the container */
10
+ export function wrapLetters({ words, classname, tagName }: IProps) {
11
+ const letters: NSplitText.ILetter[] = [];
12
+
13
+ words.forEach((word) => {
14
+ const textNode = word.element.childNodes[0];
15
+ const text = textNode.textContent;
16
+
17
+ if (!text) {
18
+ return;
19
+ }
20
+
21
+ const slitLetters = text.split('');
22
+
23
+ slitLetters.forEach((splitLetter) => {
24
+ const element = document.createElement(tagName);
25
+ element.style.display = 'inline-block';
26
+ element.classList.add(classname);
27
+ element.appendChild(document.createTextNode(splitLetter));
28
+
29
+ word.element.appendChild(element);
30
+
31
+ const letter: NSplitText.ILetter = { element, text: splitLetter };
32
+
33
+ word.letters.push(letter);
34
+ letters.push(letter);
35
+ });
36
+
37
+ textNode.remove();
38
+ });
39
+
40
+ return { letters };
41
+ }
@@ -0,0 +1,98 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import { childOf } from 'vevet-dom';
3
+ import { NSplitText } from '../types';
4
+
5
+ interface IProps {
6
+ container: HTMLElement;
7
+ words: NSplitText.IWord[];
8
+ className: string;
9
+ tagName: keyof HTMLElementTagNameMap;
10
+ }
11
+
12
+ interface ILine extends NSplitText.ILine {
13
+ nodes: Node[];
14
+ }
15
+
16
+ function getTopParent(ref: Element | null, topParent: Element): Element {
17
+ if (ref?.parentElement === topParent) {
18
+ return ref;
19
+ }
20
+
21
+ return getTopParent(ref?.parentElement ?? null, topParent);
22
+ }
23
+
24
+ /** Wrap each word inside the container */
25
+ export function wrapLines({ container, words, className, tagName }: IProps) {
26
+ const lines: ILine[] = [];
27
+ let lineIndex = -1;
28
+ let prevTop = Infinity;
29
+
30
+ // create lines
31
+ words.forEach((word) => {
32
+ const currentTop = Math.round(word.element.getBoundingClientRect().top);
33
+ const topParent = getTopParent(word.element, container);
34
+
35
+ if (currentTop !== prevTop) {
36
+ prevTop = currentTop;
37
+ lineIndex += 1;
38
+
39
+ const element = document.createElement(tagName);
40
+ element.style.display = 'block';
41
+ element.classList.add(className);
42
+
43
+ lines[lineIndex] = { element, nodes: [], words: [] };
44
+ }
45
+
46
+ const currentLine = lines[lineIndex];
47
+
48
+ const isInList = !!lines.find(({ nodes }) => nodes.includes(topParent));
49
+
50
+ if (!isInList) {
51
+ currentLine.nodes.push(topParent);
52
+
53
+ if (topParent.nextSibling?.nodeType === 3) {
54
+ currentLine.nodes.push(topParent.nextSibling);
55
+ }
56
+ }
57
+ });
58
+
59
+ // append lines
60
+ lines.forEach((line) => {
61
+ container.insertBefore(line.element, line.nodes[0]);
62
+
63
+ line.element.append(...line.nodes);
64
+ });
65
+
66
+ // hide extra br
67
+ const hiddenBr: HTMLBRElement[] = [];
68
+ lines.forEach((line) => {
69
+ const nextSibling = line.element.nextElementSibling;
70
+ if (nextSibling instanceof HTMLBRElement) {
71
+ nextSibling.style.display = 'none';
72
+ hiddenBr.push(nextSibling);
73
+ }
74
+ });
75
+
76
+ // add words
77
+ lines.forEach((line) => {
78
+ line.words.push(
79
+ ...words.filter((word) => childOf(word.element, line.element)),
80
+ );
81
+ });
82
+
83
+ const destroy = () => {
84
+ hiddenBr.forEach((br) => {
85
+ br.style.display = '';
86
+ });
87
+
88
+ lines.forEach((line) => {
89
+ line.nodes.forEach((node) => {
90
+ container.insertBefore(node, line.element);
91
+ });
92
+
93
+ line.element.remove();
94
+ });
95
+ };
96
+
97
+ return { lines, destroy };
98
+ }
@@ -0,0 +1,64 @@
1
+ import { NSplitText } from '../types';
2
+
3
+ /* eslint-disable no-param-reassign */
4
+ interface IProps {
5
+ container: ChildNode;
6
+ classname: string;
7
+ tagName: keyof HTMLElementTagNameMap;
8
+ }
9
+
10
+ /** Wrap each word inside the container */
11
+ export function wrapWords({ container, classname, tagName }: IProps) {
12
+ const whitespace = String.fromCharCode(32);
13
+
14
+ const words: NSplitText.IWord[] = [];
15
+
16
+ function recursive(node: ChildNode) {
17
+ if (node instanceof HTMLElement) {
18
+ if (node.tagName !== 'BR') {
19
+ node.style.display = 'inline-block';
20
+ }
21
+
22
+ const children = [...Array.from(node.childNodes)];
23
+ children.forEach((child) => recursive(child));
24
+
25
+ return;
26
+ }
27
+
28
+ if (node.nodeType === 3) {
29
+ const nodeParent = node.parentElement;
30
+ const text = node.nodeValue ?? '';
31
+ const splitWords = text.split(whitespace);
32
+
33
+ if (text === whitespace) {
34
+ nodeParent?.insertBefore(document.createTextNode(whitespace), node);
35
+ node.remove();
36
+
37
+ return;
38
+ }
39
+
40
+ splitWords.forEach((splitWord, index) => {
41
+ if (splitWord) {
42
+ const element = document.createElement(tagName);
43
+ element.style.display = 'inline-block';
44
+ element.classList.add(classname);
45
+ element.appendChild(document.createTextNode(splitWord));
46
+
47
+ words.push({ element, text: splitWord, letters: [] });
48
+
49
+ nodeParent?.insertBefore(element, node);
50
+ }
51
+
52
+ if (index < splitWords.length - 1) {
53
+ nodeParent?.insertBefore(document.createTextNode(whitespace), node);
54
+ }
55
+ });
56
+
57
+ node.remove();
58
+ }
59
+ }
60
+
61
+ recursive(container);
62
+
63
+ return words;
64
+ }
@@ -68,7 +68,7 @@ export class Timeline<
68
68
 
69
69
  /** Play the timeline */
70
70
  public play() {
71
- if (this.isDestroyed || this.progress === 1) {
71
+ if (this.isDestroyed || this.p === 1) {
72
72
  return;
73
73
  }
74
74
 
@@ -83,7 +83,7 @@ export class Timeline<
83
83
 
84
84
  /** Reverse timeline */
85
85
  public reverse() {
86
- if (this.isDestroyed || this.progress === 0) {
86
+ if (this.isDestroyed || this.p === 0) {
87
87
  return;
88
88
  }
89
89
 
@@ -117,7 +117,7 @@ export class Timeline<
117
117
  }
118
118
 
119
119
  this.pause();
120
- this.progress = 0;
120
+ this.p = 0;
121
121
  }
122
122
 
123
123
  /** Start animation */
@@ -135,8 +135,8 @@ export class Timeline<
135
135
 
136
136
  // calculate current progress
137
137
  const progressIterator = frameDiff / this.duration / (isReversed ? -1 : 1);
138
- const progressTarget = clamp(this.progress + progressIterator, [0, 1]);
139
- this.progress = progressTarget;
138
+ const progressTarget = clamp(this.p + progressIterator, [0, 1]);
139
+ this.p = progressTarget;
140
140
 
141
141
  // end animation
142
142
  if (
@@ -160,13 +160,13 @@ export class Timeline<
160
160
  protected _handleProgressUpdate() {
161
161
  super._handleProgressUpdate();
162
162
 
163
- if (this.progress === 0) {
163
+ if (this.p === 0) {
164
164
  this.callbacks.tbt('start', undefined);
165
165
 
166
166
  return;
167
167
  }
168
168
 
169
- if (this.progress === 1) {
169
+ if (this.p === 1) {
170
170
  this.callbacks.tbt('end', undefined);
171
171
 
172
172
  if (this.props.shouldDestroyOnEnd) {
@@ -16,13 +16,13 @@ export const Basic: FC = () => {
16
16
 
17
17
  setTimeline(instance);
18
18
 
19
- instance.addCallback('progress', ({ easing, progress }) => {
19
+ instance.addCallback('progress', ({ e, p }) => {
20
20
  if (inputRef.current) {
21
- inputRef.current.value = `${progress}`;
21
+ inputRef.current.value = `${p}`;
22
22
  }
23
23
 
24
24
  if (thumbRef.current) {
25
- thumbRef.current.style.left = `${easing * 100}%`;
25
+ thumbRef.current.style.left = `${e * 100}%`;
26
26
  }
27
27
  });
28
28
 
@@ -54,7 +54,7 @@ export const Basic: FC = () => {
54
54
  style={{ width: '100%' }}
55
55
  onChange={(event) => {
56
56
  if (timeline) {
57
- timeline.progress = parseFloat(event.currentTarget.value);
57
+ timeline.p = parseFloat(event.currentTarget.value);
58
58
  }
59
59
  }}
60
60
  />
@@ -17,9 +17,9 @@ export const Nested: FC = () => {
17
17
 
18
18
  setTimeline(instance);
19
19
 
20
- instance.addCallback('progress', ({ progress }) => {
20
+ instance.addCallback('progress', ({ p }) => {
21
21
  if (inputRef.current) {
22
- inputRef.current.value = `${progress}`;
22
+ inputRef.current.value = `${p}`;
23
23
  }
24
24
  });
25
25
 
@@ -36,9 +36,9 @@ export const Nested: FC = () => {
36
36
  easing: EaseInOutBounce,
37
37
  });
38
38
 
39
- nestedTm.addCallback('progress', ({ easing }) => {
39
+ nestedTm.addCallback('progress', ({ e }) => {
40
40
  // eslint-disable-next-line no-param-reassign
41
- child.style.transform = `scale(${easing}, 1)`;
41
+ child.style.transform = `scale(${e}, 1)`;
42
42
  });
43
43
 
44
44
  instance.addNestedTimeline(nestedTm);
@@ -73,7 +73,7 @@ export const Nested: FC = () => {
73
73
  style={{ width: '100%' }}
74
74
  onChange={(event) => {
75
75
  if (timeline) {
76
- timeline.progress = parseFloat(event.currentTarget.value);
76
+ timeline.p = parseFloat(event.currentTarget.value);
77
77
  }
78
78
  }}
79
79
  />
@@ -0,0 +1,3 @@
1
+ export function getApp() {
2
+ return window.vevetApp;
3
+ }
@@ -75,14 +75,14 @@ export function scrollTo({
75
75
  shouldDestroyOnEnd: true,
76
76
  });
77
77
 
78
- timeline.addCallback('progress', ({ easing }) => {
78
+ timeline.addCallback('progress', ({ e }) => {
79
79
  if (!container) {
80
80
  return;
81
81
  }
82
82
 
83
83
  container.scrollTo({
84
- top: startValues.scrollTop + topDiff * easing,
85
- left: startValues.scrollLeft + leftDiff * easing,
84
+ top: startValues.scrollTop + topDiff * e,
85
+ left: startValues.scrollLeft + leftDiff * e,
86
86
  behavior: 'auto',
87
87
  });
88
88
  });
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- const version = '3.13.1';
1
+ const version = '3.14.0';
2
2
  export default version;