coonlink-luxy 26.1.1 → 26.1.2
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/README.md +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ npm i coonlink-luxy
|
|
|
16
16
|
</div>
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
`#luxy` gets a CSS `transform` while scrolling. Any child with `position: fixed` would be positioned against that transformed box, not the browser viewport — so pin overlays (modals, toasts, QR widgets) with a **React portal to `document.body`** (or keep them outside `#luxy`).
|
|
20
|
+
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
23
|
```ts
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAA;IAC5C,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,QAAA,MAAM,QAAQ,EAAE,QAAQ,CAAC,mBAAmB,CAQ3C,CAAA;AAuQD,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD;AAED,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,OAAO,QAAQ,CAAC,CAEnE"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,14 @@ const defaults = {
|
|
|
5
5
|
targetSpeed: 0.02,
|
|
6
6
|
targetPercentage: 0.1,
|
|
7
7
|
respectReducedMotion: true,
|
|
8
|
+
respectOpenModalOverlay: true,
|
|
8
9
|
};
|
|
10
|
+
const SETTLE_EPS = 0.12;
|
|
11
|
+
function hasOpenModalOverlay() {
|
|
12
|
+
return !!document.querySelector('[data-slot="dialog-overlay"][data-state="open"],' +
|
|
13
|
+
'[data-slot="alert-dialog-overlay"][data-state="open"],' +
|
|
14
|
+
'[data-slot="sheet-overlay"][data-state="open"]');
|
|
15
|
+
}
|
|
9
16
|
function extend(base, over) {
|
|
10
17
|
return { ...base, ...(over ?? {}) };
|
|
11
18
|
}
|
|
@@ -27,13 +34,110 @@ class Engine {
|
|
|
27
34
|
this.scrollTop = 0;
|
|
28
35
|
this.scrollRaf = 0;
|
|
29
36
|
this.resizeObserver = null;
|
|
37
|
+
this.pauseForOverlay = false;
|
|
38
|
+
this.overlayObserver = null;
|
|
39
|
+
this.onScrollResume = () => {
|
|
40
|
+
this.ensureTicking();
|
|
41
|
+
};
|
|
30
42
|
this.onResize = () => {
|
|
31
43
|
if (!this.wrapper)
|
|
32
44
|
return;
|
|
33
45
|
const h = Math.max(this.wrapper.scrollHeight, this.wrapper.clientHeight);
|
|
34
46
|
document.body.style.height = `${h}px`;
|
|
47
|
+
this.ensureTicking();
|
|
35
48
|
};
|
|
36
49
|
}
|
|
50
|
+
isSettled() {
|
|
51
|
+
if (Math.abs(this.scrollTop - this.wrapperOffset) > SETTLE_EPS) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const ts = this.settings.targetSpeed;
|
|
55
|
+
const st = this.scrollTop;
|
|
56
|
+
for (let i = 0; i < this.targets.length; i++) {
|
|
57
|
+
const t = this.targets[i];
|
|
58
|
+
const idealY = st * Number(ts) * Number(t.speedY);
|
|
59
|
+
if (Math.abs(idealY - t.top) > SETTLE_EPS)
|
|
60
|
+
return false;
|
|
61
|
+
if (t.horizontal) {
|
|
62
|
+
const idealX = st * Number(ts) * Number(t.speedX);
|
|
63
|
+
if (Math.abs(idealX - t.left) > SETTLE_EPS)
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
stopScrollLoop() {
|
|
70
|
+
window.removeEventListener('scroll', this.onScrollResume);
|
|
71
|
+
if (this.scrollRaf) {
|
|
72
|
+
window.cancelAnimationFrame(this.scrollRaf);
|
|
73
|
+
this.scrollRaf = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ensureTicking() {
|
|
77
|
+
if (this.pauseForOverlay || !this.wrapper)
|
|
78
|
+
return;
|
|
79
|
+
window.removeEventListener('scroll', this.onScrollResume);
|
|
80
|
+
if (this.scrollRaf !== 0)
|
|
81
|
+
return;
|
|
82
|
+
const tick = () => {
|
|
83
|
+
if (this.pauseForOverlay || !this.wrapper) {
|
|
84
|
+
this.scrollRaf = 0;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.scrollTop = getScrollTop();
|
|
88
|
+
this.wrapperUpdate();
|
|
89
|
+
for (let i = 0; i < this.targets.length; i++) {
|
|
90
|
+
this.targetsUpdate(this.targets[i]);
|
|
91
|
+
}
|
|
92
|
+
if (this.isSettled()) {
|
|
93
|
+
this.scrollRaf = 0;
|
|
94
|
+
window.addEventListener('scroll', this.onScrollResume, {
|
|
95
|
+
passive: true,
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.scrollRaf = window.requestAnimationFrame(tick);
|
|
100
|
+
};
|
|
101
|
+
this.scrollRaf = window.requestAnimationFrame(tick);
|
|
102
|
+
}
|
|
103
|
+
syncOverlayPause() {
|
|
104
|
+
if (!this.settings.respectOpenModalOverlay) {
|
|
105
|
+
this.pauseForOverlay = false;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const blocked = hasOpenModalOverlay();
|
|
109
|
+
if (blocked === this.pauseForOverlay)
|
|
110
|
+
return;
|
|
111
|
+
this.pauseForOverlay = blocked;
|
|
112
|
+
if (blocked) {
|
|
113
|
+
this.stopScrollLoop();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.onResize();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
attachOverlayWatcher() {
|
|
120
|
+
this.detachOverlayWatcher();
|
|
121
|
+
if (!this.settings.respectOpenModalOverlay)
|
|
122
|
+
return;
|
|
123
|
+
this.pauseForOverlay = hasOpenModalOverlay();
|
|
124
|
+
this.overlayObserver = new MutationObserver(() => {
|
|
125
|
+
this.syncOverlayPause();
|
|
126
|
+
if (!this.pauseForOverlay)
|
|
127
|
+
this.ensureTicking();
|
|
128
|
+
});
|
|
129
|
+
this.overlayObserver.observe(document.body, {
|
|
130
|
+
childList: true,
|
|
131
|
+
subtree: true,
|
|
132
|
+
attributes: true,
|
|
133
|
+
attributeFilter: ['data-state'],
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
detachOverlayWatcher() {
|
|
137
|
+
this.overlayObserver?.disconnect();
|
|
138
|
+
this.overlayObserver = null;
|
|
139
|
+
this.pauseForOverlay = false;
|
|
140
|
+
}
|
|
37
141
|
init(options) {
|
|
38
142
|
this.destroy();
|
|
39
143
|
this.settings = extend(defaults, options);
|
|
@@ -76,15 +180,10 @@ class Engine {
|
|
|
76
180
|
this.resizeObserver = new ResizeObserver(this.onResize);
|
|
77
181
|
this.resizeObserver.observe(this.wrapper);
|
|
78
182
|
window.addEventListener('resize', this.onResize);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
this.targetsUpdate(this.targets[i]);
|
|
84
|
-
}
|
|
85
|
-
this.scrollRaf = window.requestAnimationFrame(tickScroll);
|
|
86
|
-
};
|
|
87
|
-
this.scrollRaf = window.requestAnimationFrame(tickScroll);
|
|
183
|
+
this.attachOverlayWatcher();
|
|
184
|
+
if (!this.pauseForOverlay) {
|
|
185
|
+
this.ensureTicking();
|
|
186
|
+
}
|
|
88
187
|
return true;
|
|
89
188
|
}
|
|
90
189
|
wrapperUpdate() {
|
|
@@ -116,13 +215,11 @@ class Engine {
|
|
|
116
215
|
target.elm.style.transform = `translate3d(${offsetX}px, ${offsetY}px, 0)`;
|
|
117
216
|
}
|
|
118
217
|
destroy() {
|
|
218
|
+
this.detachOverlayWatcher();
|
|
219
|
+
this.stopScrollLoop();
|
|
119
220
|
window.removeEventListener('resize', this.onResize);
|
|
120
221
|
this.resizeObserver?.disconnect();
|
|
121
222
|
this.resizeObserver = null;
|
|
122
|
-
if (this.scrollRaf) {
|
|
123
|
-
window.cancelAnimationFrame(this.scrollRaf);
|
|
124
|
-
this.scrollRaf = 0;
|
|
125
|
-
}
|
|
126
223
|
document.body.style.height = '';
|
|
127
224
|
if (this.wrapper) {
|
|
128
225
|
this.wrapper.removeAttribute('style');
|
package/package.json
CHANGED