@linear_non/stellar-libs 1.0.19 → 1.0.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linear_non/stellar-libs",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "Reusable JavaScript libraries for Non-Linear Studio projects.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -14,8 +14,21 @@ export default class SplitonScroll {
14
14
  once = true,
15
15
  }) {
16
16
  this.element = el
17
- this.splitText = splitText
18
- this.splits = []
17
+
18
+ if (!splitText) {
19
+ this.targets = []
20
+ } else if (splitText instanceof Element) {
21
+ this.targets = [splitText]
22
+ } else if (Array.isArray(splitText)) {
23
+ this.targets = splitText
24
+ } else {
25
+ this.targets = Array.from(splitText)
26
+ }
27
+
28
+ if (!this.targets.length) return
29
+
30
+ this.splits = null
31
+
19
32
  this.animateCallback = animate || (() => {})
20
33
  this.reverseCallback = reverse || (() => {})
21
34
  this.start = start
@@ -23,10 +36,7 @@ export default class SplitonScroll {
23
36
  this.scrub = scrub
24
37
  this.once = once
25
38
 
26
- if (!this.splitText[0]) return
27
-
28
39
  // this.initScrollTrigger()
29
-
30
40
  this.addObserver()
31
41
  }
32
42
 
@@ -49,23 +59,34 @@ export default class SplitonScroll {
49
59
  end: this.end,
50
60
  scrub: this.scrub,
51
61
  })
62
+
52
63
  this.observer.on("enter", () => this.handleEnter())
53
64
  this.observer.on("leave", () => this.handleLeave())
54
65
  }
55
66
 
56
67
  handleEnter() {
57
- console.log("jojo")
58
- const split = splitText(this.splitText)
68
+ console.log(this.targets)
69
+
70
+ const split = splitText(this.targets)
71
+
59
72
  split.on(EVENTS.APP_SPLITTEXT_READY, splits => {
60
- this.splits = [...splits]
61
- this.animateCallback([...splits])
73
+ this.splits = splits
74
+ this.hasSplit = true
75
+
76
+ this.animateCallback(this.splits)
62
77
  })
63
78
  }
64
79
 
65
80
  handleLeave() {
66
- reverseSplit(this.splits)
81
+ if (this.splits) {
82
+ reverseSplit(this.splits)
83
+ }
84
+
67
85
  this.reverseCallback()
68
- this.destroy()
86
+
87
+ if (this.once) {
88
+ this.destroy()
89
+ }
69
90
  }
70
91
 
71
92
  update() {
@@ -74,5 +95,9 @@ export default class SplitonScroll {
74
95
 
75
96
  destroy() {
76
97
  this.observer?.kill()
98
+
99
+ this.splits = null
100
+ this.targets = null
101
+ this.element = null
77
102
  }
78
103
  }