@linear_non/stellar-libs 1.2.2 → 1.2.4

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.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Reusable JavaScript libraries for Non-Linear Studio projects.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,16 +1,17 @@
1
1
  // Sticky.js
2
2
  import { bounds } from "@linear_non/stellar-kit/utils"
3
3
  import { gsap, ScrollTrigger } from "@linear_non/stellar-kit/gsap"
4
- import { kitStore } from "@linear_non/stellar-kit/kitStore"
4
+ import { kitStore } from "@linear_non/stellar-kit"
5
5
 
6
6
  export default class Sticky {
7
7
  constructor(obj) {
8
- const { el, sticky, isSmooth, onUpdateCallback } = obj
8
+ const { el, sticky, container, isSmooth, onUpdateCallback } = obj
9
9
 
10
10
  this.el = el
11
11
  this.sticky = sticky
12
12
  this.isSticky = false
13
13
  this.isSmooth = isSmooth
14
+ this.container = container
14
15
  this.progress = 0
15
16
  this.total = 0
16
17
  this.positionX = 0
@@ -18,6 +19,9 @@ export default class Sticky {
18
19
  this.scrollTrigger = null
19
20
  this.onUpdateCallback = typeof onUpdateCallback === "function" ? onUpdateCallback : null
20
21
 
22
+ this.dpr = Math.max(1, Math.round(window.devicePixelRatio || 1))
23
+ this.snap = v => Math.round(v * this.dpr) / this.dpr
24
+
21
25
  this.config = {
22
26
  width: 0,
23
27
  height: 0,
@@ -66,8 +70,8 @@ export default class Sticky {
66
70
  onUpdate(self) {
67
71
  const { totalWidth, totalHeight } = this.config
68
72
  const newProgress = self.progress
69
- const newY = newProgress * totalHeight
70
- const newX = -newProgress * totalWidth
73
+ const newY = this.snap(newProgress * totalHeight)
74
+ const newX = this.snap(-newProgress * totalWidth)
71
75
 
72
76
  // Only update if values change to prevent unnecessary calls
73
77
  if (this.progress !== newProgress || this.positionY !== newY || this.positionX !== newX) {
@@ -76,7 +80,7 @@ export default class Sticky {
76
80
  this.positionX = newX
77
81
 
78
82
  if (this.isSmooth) {
79
- gsap.set(this.sticky, { y: this.positionY })
83
+ gsap.set(this.sticky, { y: this.positionY, force3D: true })
80
84
  }
81
85
 
82
86
  // Call the callback function if provided
@@ -96,10 +100,9 @@ export default class Sticky {
96
100
  // Get the viewport height dynamically instead of using store
97
101
  const vh = window.innerHeight
98
102
  let stickyRect = bounds(this.el)
99
-
100
- Object.assign(this.config, {
101
- totalHeight: stickyRect.height - vh,
102
- })
103
+ let containerRect = this.container ? bounds(this.container) : null
104
+ this.config.totalWidth = containerRect ? this.snap(containerRect.width - vh) : 0
105
+ this.config.totalHeight = this.snap(stickyRect.height - vh)
103
106
  }
104
107
 
105
108
  destroy() {