@linear_non/stellar-libs 1.1.9 → 1.2.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.
- package/package.json +1 -1
- package/src/Smooth/index.js +43 -8
package/package.json
CHANGED
package/src/Smooth/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Scrollbar from "../ScrollBar"
|
|
2
2
|
import { kitStore } from "@linear_non/stellar-kit"
|
|
3
3
|
import { emitter, EVENTS } from "@linear_non/stellar-kit/events"
|
|
4
|
-
import { qs, qsa, bounds
|
|
4
|
+
import { qs, qsa, bounds } from "@linear_non/stellar-kit/utils"
|
|
5
5
|
|
|
6
6
|
export default class Smooth {
|
|
7
7
|
constructor(obj) {
|
|
@@ -12,6 +12,7 @@ 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
|
+
this.resizeRAF = null
|
|
15
16
|
|
|
16
17
|
this.init()
|
|
17
18
|
}
|
|
@@ -109,20 +110,49 @@ export default class Smooth {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
resetTransforms() {
|
|
114
|
+
if (!this.elems) return
|
|
115
|
+
this.elems.forEach(el => {
|
|
116
|
+
el.style.transform = ""
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
112
120
|
resize = () => {
|
|
113
121
|
const { isSmooth } = kitStore.flags
|
|
114
122
|
|
|
115
123
|
if (!isSmooth) return
|
|
116
124
|
|
|
117
|
-
|
|
125
|
+
// Cancel any pending resize RAF
|
|
126
|
+
if (this.resizeRAF) {
|
|
127
|
+
cancelAnimationFrame(this.resizeRAF)
|
|
128
|
+
this.resizeRAF = null
|
|
129
|
+
}
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
this.
|
|
131
|
+
// Clear transforms to get accurate measurements
|
|
132
|
+
this.resetTransforms()
|
|
121
133
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
// Force reflow
|
|
135
|
+
if (this.el) {
|
|
136
|
+
void this.el.offsetHeight
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Double RAF to ensure DOM has fully reflowed
|
|
140
|
+
this.resizeRAF = requestAnimationFrame(() => {
|
|
141
|
+
this.resizeRAF = requestAnimationFrame(() => {
|
|
142
|
+
this.resizeRAF = null
|
|
143
|
+
|
|
144
|
+
this.scroll?.setScrollBounds()
|
|
145
|
+
|
|
146
|
+
const { fh } = kitStore.sizes
|
|
147
|
+
this.current = Math.min(Math.max(this.current, 0), fh || 0)
|
|
148
|
+
|
|
149
|
+
this.getSections()
|
|
150
|
+
|
|
151
|
+
emitter.emit(EVENTS.APP_SMOOTH_RESIZE)
|
|
152
|
+
this.transformSections()
|
|
153
|
+
this.scrollbar?.update()
|
|
154
|
+
})
|
|
155
|
+
})
|
|
126
156
|
}
|
|
127
157
|
|
|
128
158
|
update(elems) {
|
|
@@ -152,6 +182,11 @@ export default class Smooth {
|
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
destroy() {
|
|
185
|
+
if (this.resizeRAF) {
|
|
186
|
+
cancelAnimationFrame(this.resizeRAF)
|
|
187
|
+
this.resizeRAF = null
|
|
188
|
+
}
|
|
189
|
+
|
|
155
190
|
this.off()
|
|
156
191
|
this.scrollbar?.destroy()
|
|
157
192
|
this.clean()
|