coonlink-luxy 26.1.2 → 26.1.3

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/dist/index.d.ts CHANGED
@@ -11,8 +11,6 @@ export interface CoonlinkLuxyInstance {
11
11
  init(options?: CoonlinkLuxyOptions): boolean;
12
12
  destroy(): void;
13
13
  }
14
- declare const defaults: Required<CoonlinkLuxyOptions>;
15
14
  export declare function createCoonlinkLuxy(): CoonlinkLuxyInstance;
16
- export declare function getCoonlinkLuxyDefaults(): Readonly<typeof defaults>;
17
- export {};
15
+ export declare function getCoonlinkLuxyDefaults(): Readonly<Required<CoonlinkLuxyOptions>>;
18
16
  //# sourceMappingURL=index.d.ts.map
@@ -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;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"}
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"}
package/dist/index.js CHANGED
@@ -1,3 +1,14 @@
1
+ /*
2
+ ✨ CoonDev • https://dev.coonlink.com/
3
+
4
+ ▄█▄ ████▄ ████▄ ▄ ██▄ ▄███▄ ▄
5
+ █▀ ▀▄ █ █ █ █ █ █ █ █▀ ▀ █
6
+ █ ▀ █ █ █ █ ██ █ █ █ ██▄▄ █ █
7
+ █▄ ▄▀ ▀████ ▀████ █ █ █ █ █ █▄ ▄▀ █ █
8
+ ▀███▀ █ █ █ ███▀ ▀███▀ █ █
9
+ █ ██ █▐
10
+
11
+ */
1
12
  const defaults = {
2
13
  wrapper: '#luxy',
3
14
  targets: '.luxy-el',
@@ -14,16 +25,15 @@ function hasOpenModalOverlay() {
14
25
  '[data-slot="sheet-overlay"][data-state="open"]');
15
26
  }
16
27
  function extend(base, over) {
17
- return { ...base, ...(over ?? {}) };
28
+ return { ...base, ...(over !== null && over !== void 0 ? over : {}) };
18
29
  }
19
30
  function getScrollTop() {
20
- return (window.scrollY ??
21
- document.documentElement.scrollTop ??
22
- document.body.scrollTop ??
23
- 0);
31
+ var _a, _b, _c;
32
+ return ((_c = (_b = (_a = window.scrollY) !== null && _a !== void 0 ? _a : document.documentElement.scrollTop) !== null && _b !== void 0 ? _b : document.body.scrollTop) !== null && _c !== void 0 ? _c : 0);
24
33
  }
25
34
  function readSpeedY(el) {
26
- return el.getAttribute('data-speed-y') ?? el.getAttribute('data-speed-Y');
35
+ var _a;
36
+ return (_a = el.getAttribute('data-speed-y')) !== null && _a !== void 0 ? _a : el.getAttribute('data-speed-Y');
27
37
  }
28
38
  class Engine {
29
39
  constructor() {
@@ -36,9 +46,7 @@ class Engine {
36
46
  this.resizeObserver = null;
37
47
  this.pauseForOverlay = false;
38
48
  this.overlayObserver = null;
39
- this.onScrollResume = () => {
40
- this.ensureTicking();
41
- };
49
+ this.onScrollResume = () => { this.ensureTicking(); };
42
50
  this.onResize = () => {
43
51
  if (!this.wrapper)
44
52
  return;
@@ -48,9 +56,8 @@ class Engine {
48
56
  };
49
57
  }
50
58
  isSettled() {
51
- if (Math.abs(this.scrollTop - this.wrapperOffset) > SETTLE_EPS) {
59
+ if (Math.abs(this.scrollTop - this.wrapperOffset) > SETTLE_EPS)
52
60
  return false;
53
- }
54
61
  const ts = this.settings.targetSpeed;
55
62
  const st = this.scrollTop;
56
63
  for (let i = 0; i < this.targets.length; i++) {
@@ -86,14 +93,11 @@ class Engine {
86
93
  }
87
94
  this.scrollTop = getScrollTop();
88
95
  this.wrapperUpdate();
89
- for (let i = 0; i < this.targets.length; i++) {
96
+ for (let i = 0; i < this.targets.length; i++)
90
97
  this.targetsUpdate(this.targets[i]);
91
- }
92
98
  if (this.isSettled()) {
93
99
  this.scrollRaf = 0;
94
- window.addEventListener('scroll', this.onScrollResume, {
95
- passive: true,
96
- });
100
+ window.addEventListener('scroll', this.onScrollResume, { passive: true });
97
101
  return;
98
102
  }
99
103
  this.scrollRaf = window.requestAnimationFrame(tick);
@@ -127,29 +131,27 @@ class Engine {
127
131
  this.ensureTicking();
128
132
  });
129
133
  this.overlayObserver.observe(document.body, {
130
- childList: true,
131
- subtree: true,
132
- attributes: true,
133
- attributeFilter: ['data-state'],
134
+ childList: true, subtree: true, attributes: true, attributeFilter: ['data-state'],
134
135
  });
135
136
  }
136
137
  detachOverlayWatcher() {
137
- this.overlayObserver?.disconnect();
138
+ var _a;
139
+ (_a = this.overlayObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
138
140
  this.overlayObserver = null;
139
141
  this.pauseForOverlay = false;
140
142
  }
141
143
  init(options) {
144
+ var _a;
142
145
  this.destroy();
143
146
  this.settings = extend(defaults, options);
144
147
  if (this.settings.respectReducedMotion) {
145
- const mq = window.matchMedia?.('(prefers-reduced-motion: reduce)');
146
- if (mq?.matches)
148
+ const mq = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-reduced-motion: reduce)');
149
+ if (mq === null || mq === void 0 ? void 0 : mq.matches)
147
150
  return false;
148
151
  }
149
152
  const el = document.querySelector(this.settings.wrapper);
150
- if (!el || !(el instanceof HTMLElement)) {
153
+ if (!el || !(el instanceof HTMLElement))
151
154
  return false;
152
- }
153
155
  this.wrapper = el;
154
156
  const nodeList = document.querySelectorAll(this.settings.targets);
155
157
  const scrollHeight = Math.max(this.wrapper.scrollHeight, this.wrapper.clientHeight);
@@ -170,8 +172,7 @@ class Engine {
170
172
  elm: node,
171
173
  offset: offset ? parseInt(offset, 10) || 0 : 0,
172
174
  horizontal: horizontal ? 1 : 0,
173
- top: 0,
174
- left: 0,
175
+ top: 0, left: 0,
175
176
  speedX: speedX ? Number(speedX) || 1 : 1,
176
177
  speedY: speedY ? Number(speedY) || 1 : 1,
177
178
  percentage: percentage ? parseInt(percentage, 10) || 0 : 0,
@@ -181,53 +182,47 @@ class Engine {
181
182
  this.resizeObserver.observe(this.wrapper);
182
183
  window.addEventListener('resize', this.onResize);
183
184
  this.attachOverlayWatcher();
184
- if (!this.pauseForOverlay) {
185
+ if (!this.pauseForOverlay)
185
186
  this.ensureTicking();
186
- }
187
187
  return true;
188
188
  }
189
189
  wrapperUpdate() {
190
190
  if (!this.wrapper)
191
191
  return;
192
- this.wrapperOffset +=
193
- (this.scrollTop - this.wrapperOffset) * this.settings.wrapperSpeed;
192
+ this.wrapperOffset += (this.scrollTop - this.wrapperOffset) * this.settings.wrapperSpeed;
193
+ const maxOffset = Math.max(0, document.body.scrollHeight - window.innerHeight);
194
+ this.wrapperOffset = Math.max(0, Math.min(this.wrapperOffset, maxOffset));
194
195
  const y = Math.round(-this.wrapperOffset * 100) / 100;
195
196
  this.wrapper.style.transform = `translate3d(0, ${y}px, 0)`;
196
197
  }
197
198
  targetsUpdate(target) {
198
199
  const ts = this.settings.targetSpeed;
199
200
  const tp = this.settings.targetPercentage;
200
- target.top +=
201
- (this.scrollTop * Number(ts) * Number(target.speedY) - target.top) * tp;
202
- target.left +=
203
- (this.scrollTop * Number(ts) * Number(target.speedX) - target.left) * tp;
204
- const targetOffsetTop = parseInt(String(target.percentage), 10) -
205
- target.top -
206
- parseInt(String(target.offset), 10);
201
+ target.top += (this.scrollTop * Number(ts) * Number(target.speedY) - target.top) * tp;
202
+ target.left += (this.scrollTop * Number(ts) * Number(target.speedX) - target.left) * tp;
203
+ const targetOffsetTop = parseInt(String(target.percentage), 10) - target.top - parseInt(String(target.offset), 10);
207
204
  let offsetY = Math.round(targetOffsetTop * -100) / 100;
208
205
  let offsetX = 0;
209
206
  if (target.horizontal) {
210
- const targetOffsetLeft = parseInt(String(target.percentage), 10) -
211
- target.left -
212
- parseInt(String(target.offset), 10);
207
+ const targetOffsetLeft = parseInt(String(target.percentage), 10) - target.left - parseInt(String(target.offset), 10);
213
208
  offsetX = Math.round(targetOffsetLeft * -100) / 100;
214
209
  }
215
210
  target.elm.style.transform = `translate3d(${offsetX}px, ${offsetY}px, 0)`;
216
211
  }
217
212
  destroy() {
213
+ var _a;
218
214
  this.detachOverlayWatcher();
219
215
  this.stopScrollLoop();
220
216
  window.removeEventListener('resize', this.onResize);
221
- this.resizeObserver?.disconnect();
217
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
222
218
  this.resizeObserver = null;
223
219
  document.body.style.height = '';
224
220
  if (this.wrapper) {
225
221
  this.wrapper.removeAttribute('style');
226
222
  this.wrapper = null;
227
223
  }
228
- for (let i = 0; i < this.targets.length; i++) {
224
+ for (let i = 0; i < this.targets.length; i++)
229
225
  this.targets[i].elm.removeAttribute('style');
230
- }
231
226
  this.targets = [];
232
227
  this.wrapperOffset = 0;
233
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coonlink-luxy",
3
- "version": "26.1.2",
3
+ "version": "26.1.3",
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": [
package/README.md DELETED
@@ -1,38 +0,0 @@
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
- ```