coonlink-luxy 26.1.3 → 26.1.6

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 ADDED
@@ -0,0 +1,38 @@
1
+ # coonlink-luxy
2
+
3
+ Inertia scroll and parallax (same idea as [luxy.js](https://github.com/min30327/luxy.js)), with fixes for modern browsers, `data-speed-y`, and clean `destroy()` for React/Next.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i coonlink-luxy
9
+ ```
10
+
11
+ ## Markup
12
+
13
+ ```html
14
+ <div id="luxy">
15
+ <div class="luxy-el" data-speed-y="5" data-offset="-50">…</div>
16
+ </div>
17
+ ```
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
+
21
+ ## Usage
22
+
23
+ ```ts
24
+ import { createCoonlinkLuxy } from 'coonlink-luxy'
25
+
26
+ const luxy = createCoonlinkLuxy()
27
+ luxy.init({
28
+ wrapper: '#luxy',
29
+ targets: '.luxy-el',
30
+ wrapperSpeed: 0.08,
31
+ targetSpeed: 0.02,
32
+ targetPercentage: 0.1,
33
+ respectReducedMotion: true,
34
+ })
35
+
36
+ // SPA / React unmount:
37
+ luxy.destroy()
38
+ ```
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC;IAC7C,OAAO,IAAI,IAAI,CAAC;CACjB;AA4ND,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD;AAED,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAEjF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC;IAC7C,OAAO,IAAI,IAAI,CAAC;CACjB;AAyOD,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD;AAED,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAEjF"}
package/dist/index.js CHANGED
@@ -46,12 +46,27 @@ class Engine {
46
46
  this.resizeObserver = null;
47
47
  this.pauseForOverlay = false;
48
48
  this.overlayObserver = null;
49
- this.onScrollResume = () => { this.ensureTicking(); };
49
+ this.onScrollResume = () => {
50
+ if (Math.abs(getScrollTop() - this.wrapperOffset) > 0.5)
51
+ this.ensureTicking();
52
+ };
50
53
  this.onResize = () => {
51
54
  if (!this.wrapper)
52
55
  return;
53
56
  const h = Math.max(this.wrapper.scrollHeight, this.wrapper.clientHeight);
54
57
  document.body.style.height = `${h}px`;
58
+ if (this.scrollRaf === 0) {
59
+ const newST = getScrollTop();
60
+ const diff = Math.abs(newST - this.wrapperOffset);
61
+ if (diff > 0 && diff < 5) {
62
+ const maxOff = Math.max(0, h - window.innerHeight);
63
+ this.wrapperOffset = Math.max(0, Math.min(Math.round(newST), maxOff));
64
+ this.scrollTop = newST;
65
+ const y = Math.round(-this.wrapperOffset * 100) / 100;
66
+ this.wrapper.style.transform = `translate3d(0, ${y}px, 0)`;
67
+ return;
68
+ }
69
+ }
55
70
  this.ensureTicking();
56
71
  };
57
72
  }
@@ -96,6 +111,8 @@ class Engine {
96
111
  for (let i = 0; i < this.targets.length; i++)
97
112
  this.targetsUpdate(this.targets[i]);
98
113
  if (this.isSettled()) {
114
+ this.wrapperOffset = Math.round(this.scrollTop);
115
+ this.wrapperUpdate();
99
116
  this.scrollRaf = 0;
100
117
  window.addEventListener('scroll', this.onScrollResume, { passive: true });
101
118
  return;
@@ -125,11 +142,7 @@ class Engine {
125
142
  if (!this.settings.respectOpenModalOverlay)
126
143
  return;
127
144
  this.pauseForOverlay = hasOpenModalOverlay();
128
- this.overlayObserver = new MutationObserver(() => {
129
- this.syncOverlayPause();
130
- if (!this.pauseForOverlay)
131
- this.ensureTicking();
132
- });
145
+ this.overlayObserver = new MutationObserver(() => this.syncOverlayPause());
133
146
  this.overlayObserver.observe(document.body, {
134
147
  childList: true, subtree: true, attributes: true, attributeFilter: ['data-state'],
135
148
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coonlink-luxy",
3
- "version": "26.1.3",
3
+ "version": "26.1.6",
4
4
  "description": "Inertia scroll and parallax (luxy-style) with fixes for modern browsers, React/Next, and prefers-reduced-motion.",
5
5
  "homepage": "https://dev.coonlink.com",
6
6
  "keywords": [