@linear_non/stellar-libs 1.0.22 → 1.0.25

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.22",
3
+ "version": "1.0.25",
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.2"
28
+ "@linear_non/stellar-kit": "^2.1.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@linear_non/prettier-config": "^1.0.6",
@@ -13,6 +13,7 @@ export default class Smooth {
13
13
  this.sections = null
14
14
  this.scrollbar = null
15
15
  this.dpr = Math.max(1, Math.round(window.devicePixelRatio || 1))
16
+ this.init()
16
17
  }
17
18
 
18
19
  getSections() {
@@ -99,7 +100,6 @@ export default class Smooth {
99
100
  const { vh } = kitStore.sizes
100
101
  const rect = bounds(el)
101
102
  const height = rect.height
102
-
103
103
  const centering = vh / 2 - height / 2
104
104
  const offset = rect.top < vh ? 0 : (rect.top - centering) * speed - (rect.top - centering)
105
105
 
@@ -136,7 +136,7 @@ export default class Smooth {
136
136
  kitStore.flags.isResizing = true
137
137
  this.scroll.setScrollBounds()
138
138
  this.elems = elems || qsa("[data-smooth]")
139
- this.scrollbar.update()
139
+ this.scrollbar?.update()
140
140
  this.getSections()
141
141
  this.transformSections()
142
142
  kitStore.flags.isResizing = false
@@ -6,7 +6,7 @@ export default class SplitonScroll {
6
6
  constructor({
7
7
  el,
8
8
  splitText,
9
- animate,
9
+ isReady,
10
10
  reverse,
11
11
  start = "top bottom", // "top top+=100%",
12
12
  end = "bottom top", // "bottom bottom-=100%",
@@ -28,40 +28,22 @@ export default class SplitonScroll {
28
28
  if (!this.targets.length) return
29
29
 
30
30
  this.splits = null
31
-
32
- this.animateCallback = animate || (() => {})
31
+ this.isReadyCallback = isReady || (() => {})
33
32
  this.reverseCallback = reverse || (() => {})
34
33
  this.start = start
35
34
  this.end = end
36
35
  this.scrub = scrub
37
36
  this.once = once
38
37
 
39
- <<<<<<< HEAD
40
- // this.initScrollTrigger()
41
- =======
42
- if (!this.splitText[0]) return
43
-
44
- >>>>>>> origin
45
38
  this.addObserver()
46
39
  }
47
40
 
48
- initScrollTrigger() {
49
- this.myScrollTrigger = ScrollTrigger.create({
50
- trigger: this.element,
51
- start: this.start,
52
- end: this.end,
53
- scrub: this.scrub,
54
- once: this.once,
55
- onEnter: () => this.handleEnter(),
56
- onLeave: () => this.handleLeave(),
57
- })
58
- }
59
-
60
41
  addObserver() {
61
42
  this.observer = new Observer({
62
43
  trigger: this.element,
63
44
  start: this.start,
64
45
  end: this.end,
46
+ once: this.once,
65
47
  scrub: this.scrub,
66
48
  })
67
49
 
@@ -69,19 +51,20 @@ export default class SplitonScroll {
69
51
  this.observer.on("leave", () => this.handleLeave())
70
52
  }
71
53
 
72
- handleEnter() {
73
- <<<<<<< HEAD
74
- const split = splitText(this.targets)
75
-
76
- =======
77
- const split = splitText(this.splitText)
78
- >>>>>>> origin
79
- split.on(EVENTS.APP_SPLITTEXT_READY, splits => {
80
- this.splits = splits
81
- this.hasSplit = true
54
+ async handleEnter() {
55
+ if (this.splits) {
56
+ this.isReadyCallback(this.splits)
57
+ return
58
+ }
82
59
 
83
- this.animateCallback(this.splits)
60
+ const split = splitText(this.targets)
61
+ const splits = await new Promise(resolve => {
62
+ split.on(EVENTS.APP_SPLITTEXT_READY, readySplits => {
63
+ resolve(readySplits)
64
+ })
84
65
  })
66
+ this.splits = splits
67
+ this.isReadyCallback(splits)
85
68
  }
86
69
 
87
70
  handleLeave() {
@@ -102,7 +85,6 @@ export default class SplitonScroll {
102
85
 
103
86
  destroy() {
104
87
  this.observer?.kill()
105
-
106
88
  this.splits = null
107
89
  this.targets = null
108
90
  this.element = null
@@ -5,13 +5,11 @@ import { gsap, ScrollTrigger } from "@linear_non/stellar-kit/gsap"
5
5
  export default class Sticky {
6
6
  constructor(obj) {
7
7
  const { el, sticky, isSmooth, onUpdateCallback } = obj
8
-
9
8
  this.el = el
10
9
  this.sticky = sticky
11
10
  this.isSticky = false
12
11
  this.isSmooth = isSmooth
13
12
  this.progress = 0
14
- this.total = 0
15
13
  this.positionX = 0
16
14
  this.positionY = 0
17
15
  this.scrollTrigger = null
@@ -24,23 +22,26 @@ export default class Sticky {
24
22
  totalHeight: 0,
25
23
  totalItems: 0,
26
24
  }
25
+
27
26
  if (!isSmooth) sticky.style.pointerEvents = "none"
28
27
  this.init()
29
28
  }
30
29
 
31
30
  observer() {
32
- if (this.scrollTrigger) this.scrollTrigger.kill() // Prevent duplicate listeners
31
+ if (this.scrollTrigger) this.scrollTrigger.kill()
33
32
 
34
33
  this.scrollTrigger = ScrollTrigger.create({
35
34
  trigger: this.el,
36
35
  start: "top top",
37
36
  end: "bottom bottom",
38
37
  scrub: true,
38
+ invalidateOnRefresh: true,
39
39
  onEnter: () => this.toggleSticky(true),
40
40
  onEnterBack: () => this.toggleSticky(true),
41
41
  onLeave: () => this.toggleSticky(false, true),
42
42
  onLeaveBack: () => this.toggleSticky(false),
43
43
  onUpdate: self => this.onUpdate(self),
44
+ onRefresh: self => this.onRefresh(self),
44
45
  })
45
46
  }
46
47
 
@@ -67,17 +68,13 @@ export default class Sticky {
67
68
  const newY = newProgress * totalHeight
68
69
  const newX = -newProgress * totalWidth
69
70
 
70
- // Only update if values change to prevent unnecessary calls
71
71
  if (this.progress !== newProgress || this.positionY !== newY || this.positionX !== newX) {
72
72
  this.progress = newProgress
73
73
  this.positionY = newY
74
74
  this.positionX = newX
75
75
 
76
- if (this.isSmooth) {
77
- gsap.set(this.sticky, { y: this.positionY })
78
- }
76
+ if (this.isSmooth) gsap.set(this.sticky, { y: this.positionY })
79
77
 
80
- // Call the callback function if provided
81
78
  if (this.onUpdateCallback) {
82
79
  this.onUpdateCallback({
83
80
  progress: this.progress,
@@ -88,18 +85,43 @@ export default class Sticky {
88
85
  }
89
86
  }
90
87
 
91
- resize() {
92
- if (!this.sticky) return
88
+ onRefresh(self) {
89
+ this.computeSizes()
93
90
 
94
- // Get the viewport height dynamically instead of using store
91
+ const { totalWidth, totalHeight } = this.config
92
+ this.progress = self?.progress || 0
93
+ this.positionY = this.progress * totalHeight
94
+ this.positionX = -this.progress * totalWidth
95
+
96
+ if (this.isSmooth) {
97
+ gsap.set(this.sticky, { y: this.positionY })
98
+ } else {
99
+ if (this.isSticky) gsap.set(this.sticky, { top: 0 })
100
+ else gsap.set(this.sticky, { top: `${this.positionY}px` })
101
+ }
102
+ }
103
+
104
+ computeSizes() {
105
+ if (!this.sticky) return
95
106
  const vh = window.innerHeight
96
- let stickyRect = bounds(this.el)
107
+ const stickyRect = bounds(this.el)
108
+ const totalHeight = Math.max(stickyRect.height - vh, 0)
97
109
 
98
110
  Object.assign(this.config, {
99
- totalHeight: stickyRect.height - vh,
111
+ totalHeight,
112
+ totalWidth: this.config.totalWidth || 0,
100
113
  })
101
114
  }
102
115
 
116
+ resize() {
117
+ this.computeSizes()
118
+ }
119
+
120
+ refresh() {
121
+ this.computeSizes()
122
+ if (this.scrollTrigger) this.scrollTrigger.refresh()
123
+ }
124
+
103
125
  destroy() {
104
126
  if (this.scrollTrigger) {
105
127
  this.scrollTrigger.kill()
@@ -110,7 +132,7 @@ export default class Sticky {
110
132
  }
111
133
 
112
134
  init() {
113
- this.resize()
135
+ this.computeSizes()
114
136
  this.observer()
115
137
  }
116
138
  }