diff --git a/src/components/SplitText.svelte b/src/components/SplitText.svelte
new file mode 100644
index 0000000..df37634
--- /dev/null
+++ b/src/components/SplitText.svelte
@@ -0,0 +1,38 @@
+
+
+{#if clone}
+ {#if mode && mode === 'words'}
+
+ {#each Array(2) as _, index}
+
+ {#each split as word, i}
+ {word}{#if word.includes('\n')}
{/if}
+
+ {#if i < split.length - 1}{/if}
+ {/each}
+
+ {/each}
+
+ {:else}
+
+ {#each Array(2) as _, index}
+
+ {text}
+
+ {/each}
+
+ {/if}
+{/if}
\ No newline at end of file
diff --git a/src/style/_base.scss b/src/style/_base.scss
index ac63b7e..edf6b5c 100644
--- a/src/style/_base.scss
+++ b/src/style/_base.scss
@@ -78,10 +78,8 @@ button {
transform-style: preserve-3d;
will-change: transform;
}
-.words-3d {
- perspective: 800px;
-
- span {
- transform-origin: 0 85%;
+.text-split {
+ span, &__line {
+ transition: opacity 0.7s var(--ease-quart), transform 0.7s var(--ease-quart);
}
}
\ No newline at end of file
diff --git a/src/utils/functions.ts b/src/utils/functions.ts
index 0ca3d07..a4f9312 100644
--- a/src/utils/functions.ts
+++ b/src/utils/functions.ts
@@ -24,6 +24,30 @@ export const debounce = (func: Function, timeout: number) => {
}
+/**
+ * Split text
+ * @description Split a string into words or characters
+ * @returns string[]
+ */
+ export const splitText = (text: string, mode: string = 'words'): string[] => {
+ // Split by words
+ if (mode === 'words') {
+ const words = text
+ .replace(/\\n/g, '\n')
+ .replace(/\s+/g, m => m.includes('\n') ? '\n ' : ' ')
+ .trim()
+ .split(' ')
+
+ return words
+ }
+ // Split by chars
+ else if (mode === 'chars') {
+ const chars = Array.from(text).map(char => char === ' ' ? '\xa0' : char)
+ return chars
+ }
+}
+
+
/**
* Linear Interpolation
*/