@linear_non/stellar-libs 1.0.43 → 1.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linear_non/stellar-libs",
3
- "version": "1.0.43",
3
+ "version": "1.1.0",
4
4
  "description": "Reusable JavaScript libraries for Non-Linear Studio projects.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "author": "Non-Linear Studio",
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@linear_non/stellar-kit": "^2.1.17"
28
+ "@linear_non/stellar-kit": "^2.1.21"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@linear_non/prettier-config": "^1.0.6",
@@ -17,28 +17,6 @@ export default class Scrollbar {
17
17
  this.init()
18
18
  }
19
19
 
20
- init() {
21
- this.create()
22
- this.setBounds()
23
- this.on()
24
- }
25
-
26
- on() {
27
- emitter.on(EVENTS.APP_TICK, this.tick)
28
- emitter.on(EVENTS.APP_RESIZE, this.resize)
29
- this.handle.addEventListener("mousedown", this.mouseDown)
30
- window.addEventListener("mouseup", this.mouseUp)
31
- window.addEventListener("mousemove", this.mouseMove)
32
- }
33
-
34
- off() {
35
- emitter.off(EVENTS.APP_TICK, this.tick)
36
- emitter.off(EVENTS.APP_RESIZE, this.resize)
37
- this.handle.removeEventListener("mousedown", this.mouseDown)
38
- window.removeEventListener("mouseup", this.mouseUp)
39
- window.removeEventListener("mousemove", this.mouseMove)
40
- }
41
-
42
20
  mouseDown = () => {
43
21
  this.touching = true
44
22
  document.body.style.userSelect = "none"
@@ -121,4 +99,26 @@ export default class Scrollbar {
121
99
  destroy() {
122
100
  this.off()
123
101
  }
102
+
103
+ on() {
104
+ emitter.on(EVENTS.APP_TICK, this.tick)
105
+ emitter.on(EVENTS.APP_RESIZE, this.resize)
106
+ this.handle.addEventListener("mousedown", this.mouseDown)
107
+ window.addEventListener("mouseup", this.mouseUp)
108
+ window.addEventListener("mousemove", this.mouseMove)
109
+ }
110
+
111
+ off() {
112
+ emitter.off(EVENTS.APP_TICK, this.tick)
113
+ emitter.off(EVENTS.APP_RESIZE, this.resize)
114
+ this.handle.removeEventListener("mousedown", this.mouseDown)
115
+ window.removeEventListener("mouseup", this.mouseUp)
116
+ window.removeEventListener("mousemove", this.mouseMove)
117
+ }
118
+
119
+ init() {
120
+ this.create()
121
+ this.setBounds()
122
+ this.on()
123
+ }
124
124
  }
@@ -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 = el.dataset.speed || 1
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
- let parent = el.parentNode.closest("[data-smooth]")
34
+ cursor = bottom
43
35
 
44
- if (parent) {
45
- this.sections.some(obj => {
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.update(this.elems)
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) {
@@ -17,7 +13,7 @@ function normalizeTargets(splitTargets) {
17
13
  export default class SplitonScroll {
18
14
  constructor({
19
15
  el,
20
- splitText,
16
+ splitTargets,
21
17
  isReady,
22
18
  reverse,
23
19
  resize,
@@ -27,7 +23,7 @@ export default class SplitonScroll {
27
23
  once = true,
28
24
  }) {
29
25
  this.element = el
30
- this.targets = normalizeTargets(splitText)
26
+ this.targets = normalizeTargets(splitTargets)
31
27
 
32
28
  this.splits = null
33
29
  this.groups = null