@linear_non/stellar-libs 1.0.43 → 1.0.44
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 +1 -1
- package/src/Smooth/index.js +26 -30
- package/src/SplitOnScroll/index.js +0 -4
package/package.json
CHANGED
package/src/Smooth/index.js
CHANGED
|
@@ -12,16 +12,9 @@ export default class Smooth {
|
|
|
12
12
|
this.sections = null
|
|
13
13
|
this.scrollbar = null
|
|
14
14
|
this.dpr = Math.max(1, Math.round(window.devicePixelRatio || 1))
|
|
15
|
-
|
|
16
15
|
this.init()
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
/**
|
|
20
|
-
* - top / bottom: virtual layout positions
|
|
21
|
-
* - offset: parallax centering adjustment
|
|
22
|
-
* - speed: dataset speed multiplier
|
|
23
|
-
* - parent: optional reference to another section for nested offsets
|
|
24
|
-
*/
|
|
25
18
|
getSections() {
|
|
26
19
|
const { isSmooth } = kitStore.flags
|
|
27
20
|
if (!this.elems || !isSmooth) return
|
|
@@ -31,21 +24,17 @@ export default class Smooth {
|
|
|
31
24
|
|
|
32
25
|
this.elems.forEach(el => {
|
|
33
26
|
el.style.transform = "translate3d(0, 0, 0)"
|
|
34
|
-
|
|
35
|
-
const speed =
|
|
27
|
+
const raw = el.dataset.speed != null ? parseFloat(el.dataset.speed) : 1
|
|
28
|
+
const speed = Number.isFinite(raw) ? raw : 1
|
|
36
29
|
const { height, offset } = this.getVars(el, speed)
|
|
37
30
|
|
|
38
31
|
const top = cursor
|
|
39
32
|
const bottom = top + height
|
|
40
|
-
cursor = bottom
|
|
41
33
|
|
|
42
|
-
|
|
34
|
+
cursor = bottom
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (obj.el === parent) parent = obj
|
|
47
|
-
})
|
|
48
|
-
}
|
|
36
|
+
const parentEl = el.parentElement?.closest?.("[data-smooth]")
|
|
37
|
+
const parent = parentEl ? this.sections.find(s => s.el === parentEl) || null : null
|
|
49
38
|
|
|
50
39
|
this.sections.push({
|
|
51
40
|
el,
|
|
@@ -56,11 +45,14 @@ export default class Smooth {
|
|
|
56
45
|
speed,
|
|
57
46
|
out: true,
|
|
58
47
|
transform: 0,
|
|
48
|
+
_roundedY: 0,
|
|
59
49
|
})
|
|
60
50
|
})
|
|
61
51
|
}
|
|
62
52
|
|
|
63
53
|
tick = ({ current }) => {
|
|
54
|
+
const { isSmooth, isResizing } = kitStore.flags
|
|
55
|
+
if (!isSmooth || isResizing) return
|
|
64
56
|
this.current = current
|
|
65
57
|
this.transformSections()
|
|
66
58
|
}
|
|
@@ -71,11 +63,14 @@ export default class Smooth {
|
|
|
71
63
|
|
|
72
64
|
this.sections.forEach(section => {
|
|
73
65
|
const { isVisible, transform } = this.isVisible(section)
|
|
74
|
-
|
|
75
66
|
if (isVisible || isResizing || !section.out) {
|
|
67
|
+
const { y, css } = this.getTransform(transform)
|
|
68
|
+
if (y !== section._roundedY) {
|
|
69
|
+
section.el.style.transform = css
|
|
70
|
+
section._roundedY = y
|
|
71
|
+
}
|
|
76
72
|
section.out = !isVisible
|
|
77
73
|
section.transform = transform
|
|
78
|
-
section.el.style.transform = this.getTransform(transform)
|
|
79
74
|
}
|
|
80
75
|
})
|
|
81
76
|
}
|
|
@@ -83,15 +78,11 @@ export default class Smooth {
|
|
|
83
78
|
isVisible(section) {
|
|
84
79
|
const { vh } = kitStore.sizes
|
|
85
80
|
const { top, bottom, offset, speed, parent } = section
|
|
86
|
-
|
|
87
81
|
const extra = (parent && parent.transform) || 0
|
|
88
|
-
|
|
89
82
|
const translate = this.current * speed
|
|
90
83
|
const transform = translate - offset - extra
|
|
91
|
-
|
|
92
84
|
const start = top - translate
|
|
93
85
|
const end = bottom - translate
|
|
94
|
-
|
|
95
86
|
const isVisible = end > 0 && start < vh
|
|
96
87
|
|
|
97
88
|
return { isVisible, transform }
|
|
@@ -100,8 +91,7 @@ export default class Smooth {
|
|
|
100
91
|
getTransform(transform) {
|
|
101
92
|
let y = -transform
|
|
102
93
|
y = Math.round(y * this.dpr) / this.dpr
|
|
103
|
-
|
|
104
|
-
return `translate3d(0, ${y}px, 0)`
|
|
94
|
+
return { y, css: `translate3d(0, ${y}px, 0)` }
|
|
105
95
|
}
|
|
106
96
|
|
|
107
97
|
getVars(el, speed) {
|
|
@@ -119,26 +109,32 @@ export default class Smooth {
|
|
|
119
109
|
|
|
120
110
|
resize = () => {
|
|
121
111
|
const { isSmooth } = kitStore.flags
|
|
112
|
+
|
|
122
113
|
if (!isSmooth) return
|
|
123
114
|
|
|
124
|
-
this.
|
|
115
|
+
this.scroll?.setScrollBounds()
|
|
116
|
+
|
|
117
|
+
const { fh } = kitStore.sizes
|
|
118
|
+
this.current = Math.min(Math.max(this.current, 0), fh || 0)
|
|
119
|
+
|
|
120
|
+
this.getSections()
|
|
125
121
|
emitter.emit(EVENTS.APP_SMOOTH_RESIZE)
|
|
122
|
+
this.transformSections()
|
|
123
|
+
this.scrollbar?.update()
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
update(elems) {
|
|
129
127
|
kitStore.flags.isResizing = true
|
|
130
|
-
|
|
131
128
|
this.scroll.setScrollBounds()
|
|
132
129
|
this.elems = elems || qsa("[data-smooth]")
|
|
133
130
|
this.scrollbar?.update()
|
|
134
|
-
|
|
135
131
|
this.getSections()
|
|
136
132
|
this.transformSections()
|
|
137
|
-
|
|
138
133
|
kitStore.flags.isResizing = false
|
|
139
134
|
}
|
|
140
135
|
|
|
141
136
|
clean() {
|
|
137
|
+
if (this.sections) this.sections.forEach(s => (s.el.style.transform = ""))
|
|
142
138
|
this.elems = this.sections = null
|
|
143
139
|
}
|
|
144
140
|
|
|
@@ -154,15 +150,15 @@ export default class Smooth {
|
|
|
154
150
|
|
|
155
151
|
destroy() {
|
|
156
152
|
this.off()
|
|
153
|
+
this.scrollbar?.destroy()
|
|
157
154
|
this.clean()
|
|
158
155
|
}
|
|
159
156
|
|
|
160
157
|
init(elems) {
|
|
161
158
|
this.elems = elems || qsa("[data-smooth]")
|
|
162
159
|
|
|
163
|
-
const container = kitStore.currentPage
|
|
164
160
|
this.scrollbar = new Scrollbar({
|
|
165
|
-
container,
|
|
161
|
+
container: kitStore.currentPage,
|
|
166
162
|
})
|
|
167
163
|
|
|
168
164
|
this.on()
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { EVENTS } from "@linear_non/stellar-kit/events"
|
|
2
2
|
import { Observer, reverseSplit, splitText } from "@linear_non/stellar-kit/plugins"
|
|
3
3
|
|
|
4
|
-
import { EVENTS } from "../events"
|
|
5
|
-
import Observer from "./_Observer"
|
|
6
|
-
import { reverseSplit, splitText } from "./_SplitText"
|
|
7
|
-
|
|
8
4
|
const NOOP = () => {}
|
|
9
5
|
|
|
10
6
|
function normalizeTargets(splitTargets) {
|