@linear_non/stellar-kit 1.0.9 → 1.0.10
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/events/Emitter.js +1 -1
- package/package.json +1 -1
- package/utils/splitText.js +22 -19
package/events/Emitter.js
CHANGED
package/package.json
CHANGED
package/utils/splitText.js
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
// splitText.js
|
|
2
|
-
import {
|
|
2
|
+
import { Emitter, EVENTS } from "../events"
|
|
3
3
|
import { SplitText } from "../libraries/gsap"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export const splitText = data => {
|
|
6
|
+
const emitter = new Emitter()
|
|
7
7
|
const splits = []
|
|
8
8
|
let splitted = 0
|
|
9
|
-
const totalSplits =
|
|
9
|
+
const totalSplits = data.length
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
data.forEach(el => {
|
|
12
12
|
const dataset = el.dataset.split
|
|
13
|
-
const
|
|
13
|
+
const data = dataset.split(",")
|
|
14
|
+
const split = {}
|
|
14
15
|
const classes = {}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
split.el = el
|
|
18
|
+
splitted++
|
|
19
|
+
|
|
20
|
+
data.forEach((type, i) => {
|
|
21
|
+
const filter = type.trim()
|
|
22
|
+
if (filter == "lines") classes.linesClass = `line-${i}`
|
|
23
|
+
if (filter == "words") classes.wordsClass = `word-${i}`
|
|
24
|
+
if (filter == "chars") classes.charsClass = `char-${i} chr-++`
|
|
21
25
|
})
|
|
22
26
|
|
|
23
|
-
const
|
|
27
|
+
const splitText = new SplitText(el, {
|
|
24
28
|
type: dataset.toString(),
|
|
25
29
|
...classes,
|
|
26
30
|
})
|
|
27
31
|
|
|
28
|
-
splits.push(
|
|
29
|
-
splitted++
|
|
32
|
+
splits.push(splitText)
|
|
30
33
|
|
|
31
|
-
if (splitted
|
|
34
|
+
if (splitted == totalSplits) {
|
|
32
35
|
setTimeout(() => {
|
|
33
36
|
emitter.emit(EVENTS.APP_SPLITTEXT_READY, splits)
|
|
34
|
-
}, 0)
|
|
37
|
+
}, 0) // Use a small delay to ensure the event listener is set up
|
|
35
38
|
}
|
|
36
39
|
})
|
|
37
40
|
|
|
38
|
-
return
|
|
41
|
+
return emitter
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
export const reverseSplit =
|
|
42
|
-
|
|
44
|
+
export const reverseSplit = data => {
|
|
45
|
+
data.forEach(split => {
|
|
43
46
|
split.revert()
|
|
44
47
|
})
|
|
45
48
|
}
|