coonlink-luxy 26.1.6 → 26.1.8

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.
@@ -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;AAyOD,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;AA6LD,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD;AAED,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAEjF"}
package/dist/index.js CHANGED
@@ -18,7 +18,6 @@ const defaults = {
18
18
  respectReducedMotion: true,
19
19
  respectOpenModalOverlay: true,
20
20
  };
21
- const SETTLE_EPS = 0.12;
22
21
  function hasOpenModalOverlay() {
23
22
  return !!document.querySelector('[data-slot="dialog-overlay"][data-state="open"],' +
24
23
  '[data-slot="alert-dialog-overlay"][data-state="open"],' +
@@ -29,7 +28,7 @@ function extend(base, over) {
29
28
  }
30
29
  function getScrollTop() {
31
30
  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);
31
+ 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;
33
32
  }
34
33
  function readSpeedY(el) {
35
34
  var _a;
@@ -42,85 +41,16 @@ class Engine {
42
41
  this.targets = [];
43
42
  this.wrapperOffset = 0;
44
43
  this.scrollTop = 0;
45
- this.scrollRaf = 0;
46
- this.resizeObserver = null;
44
+ this.rafId = 0;
47
45
  this.pauseForOverlay = false;
48
46
  this.overlayObserver = null;
49
- this.onScrollResume = () => {
50
- if (Math.abs(getScrollTop() - this.wrapperOffset) > 0.5)
51
- this.ensureTicking();
52
- };
53
- this.onResize = () => {
54
- if (!this.wrapper)
55
- return;
56
- const h = Math.max(this.wrapper.scrollHeight, this.wrapper.clientHeight);
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
- }
70
- this.ensureTicking();
47
+ this.onWindowResize = () => {
48
+ cancelAnimationFrame(this.rafId);
49
+ this.rafId = 0;
50
+ setTimeout(() => { if (this.wrapper)
51
+ this.startLoop(); }, 200);
71
52
  };
72
53
  }
73
- isSettled() {
74
- if (Math.abs(this.scrollTop - this.wrapperOffset) > SETTLE_EPS)
75
- return false;
76
- const ts = this.settings.targetSpeed;
77
- const st = this.scrollTop;
78
- for (let i = 0; i < this.targets.length; i++) {
79
- const t = this.targets[i];
80
- const idealY = st * Number(ts) * Number(t.speedY);
81
- if (Math.abs(idealY - t.top) > SETTLE_EPS)
82
- return false;
83
- if (t.horizontal) {
84
- const idealX = st * Number(ts) * Number(t.speedX);
85
- if (Math.abs(idealX - t.left) > SETTLE_EPS)
86
- return false;
87
- }
88
- }
89
- return true;
90
- }
91
- stopScrollLoop() {
92
- window.removeEventListener('scroll', this.onScrollResume);
93
- if (this.scrollRaf) {
94
- window.cancelAnimationFrame(this.scrollRaf);
95
- this.scrollRaf = 0;
96
- }
97
- }
98
- ensureTicking() {
99
- if (this.pauseForOverlay || !this.wrapper)
100
- return;
101
- window.removeEventListener('scroll', this.onScrollResume);
102
- if (this.scrollRaf !== 0)
103
- return;
104
- const tick = () => {
105
- if (this.pauseForOverlay || !this.wrapper) {
106
- this.scrollRaf = 0;
107
- return;
108
- }
109
- this.scrollTop = getScrollTop();
110
- this.wrapperUpdate();
111
- for (let i = 0; i < this.targets.length; i++)
112
- this.targetsUpdate(this.targets[i]);
113
- if (this.isSettled()) {
114
- this.wrapperOffset = Math.round(this.scrollTop);
115
- this.wrapperUpdate();
116
- this.scrollRaf = 0;
117
- window.addEventListener('scroll', this.onScrollResume, { passive: true });
118
- return;
119
- }
120
- this.scrollRaf = window.requestAnimationFrame(tick);
121
- };
122
- this.scrollRaf = window.requestAnimationFrame(tick);
123
- }
124
54
  syncOverlayPause() {
125
55
  if (!this.settings.respectOpenModalOverlay) {
126
56
  this.pauseForOverlay = false;
@@ -130,12 +60,6 @@ class Engine {
130
60
  if (blocked === this.pauseForOverlay)
131
61
  return;
132
62
  this.pauseForOverlay = blocked;
133
- if (blocked) {
134
- this.stopScrollLoop();
135
- }
136
- else {
137
- this.onResize();
138
- }
139
63
  }
140
64
  attachOverlayWatcher() {
141
65
  this.detachOverlayWatcher();
@@ -153,6 +77,60 @@ class Engine {
153
77
  this.overlayObserver = null;
154
78
  this.pauseForOverlay = false;
155
79
  }
80
+ startLoop() {
81
+ if (this.rafId !== 0 || !this.wrapper)
82
+ return;
83
+ const loop = () => {
84
+ if (!this.wrapper) {
85
+ this.rafId = 0;
86
+ return;
87
+ }
88
+ // Keep body height in sync with wrapper content height
89
+ const h = Math.max(this.wrapper.scrollHeight, this.wrapper.clientHeight);
90
+ if (parseInt(document.body.style.height) !== h) {
91
+ document.body.style.height = `${h}px`;
92
+ }
93
+ if (!this.pauseForOverlay) {
94
+ this.scrollTop = Math.round(getScrollTop());
95
+ this.wrapperUpdate(h);
96
+ for (let i = 0; i < this.targets.length; i++)
97
+ this.targetsUpdate(this.targets[i]);
98
+ }
99
+ this.rafId = window.requestAnimationFrame(loop);
100
+ };
101
+ this.rafId = window.requestAnimationFrame(loop);
102
+ }
103
+ wrapperUpdate(contentHeight) {
104
+ if (!this.wrapper)
105
+ return;
106
+ const maxOffset = Math.max(0, contentHeight - window.innerHeight);
107
+ const target = Math.max(0, Math.min(this.scrollTop, maxOffset));
108
+ const delta = target - this.wrapperOffset;
109
+ if (Math.abs(delta) < 0.1) {
110
+ if (this.wrapperOffset !== target) {
111
+ this.wrapperOffset = target;
112
+ this.wrapper.style.transform = `translate3d(0, ${-Math.round(this.wrapperOffset)}px, 0)`;
113
+ }
114
+ return;
115
+ }
116
+ this.wrapperOffset += delta * this.settings.wrapperSpeed;
117
+ const y = Math.round(-this.wrapperOffset * 100) / 100;
118
+ this.wrapper.style.transform = `translate3d(0, ${y}px, 0)`;
119
+ }
120
+ targetsUpdate(target) {
121
+ const ts = this.settings.targetSpeed;
122
+ const tp = this.settings.targetPercentage;
123
+ target.top += (this.scrollTop * Number(ts) * Number(target.speedY) - target.top) * tp;
124
+ target.left += (this.scrollTop * Number(ts) * Number(target.speedX) - target.left) * tp;
125
+ const targetOffsetTop = parseInt(String(target.percentage), 10) - target.top - parseInt(String(target.offset), 10);
126
+ let offsetY = Math.round(targetOffsetTop * -100) / 100;
127
+ let offsetX = 0;
128
+ if (target.horizontal) {
129
+ const targetOffsetLeft = parseInt(String(target.percentage), 10) - target.left - parseInt(String(target.offset), 10);
130
+ offsetX = Math.round(targetOffsetLeft * -100) / 100;
131
+ }
132
+ target.elm.style.transform = `translate3d(${offsetX}px, ${offsetY}px, 0)`;
133
+ }
156
134
  init(options) {
157
135
  var _a;
158
136
  this.destroy();
@@ -191,44 +169,16 @@ class Engine {
191
169
  percentage: percentage ? parseInt(percentage, 10) || 0 : 0,
192
170
  });
193
171
  }
194
- this.resizeObserver = new ResizeObserver(this.onResize);
195
- this.resizeObserver.observe(this.wrapper);
196
- window.addEventListener('resize', this.onResize);
172
+ window.addEventListener('resize', this.onWindowResize);
197
173
  this.attachOverlayWatcher();
198
- if (!this.pauseForOverlay)
199
- this.ensureTicking();
174
+ this.startLoop();
200
175
  return true;
201
176
  }
202
- wrapperUpdate() {
203
- if (!this.wrapper)
204
- return;
205
- this.wrapperOffset += (this.scrollTop - this.wrapperOffset) * this.settings.wrapperSpeed;
206
- const maxOffset = Math.max(0, document.body.scrollHeight - window.innerHeight);
207
- this.wrapperOffset = Math.max(0, Math.min(this.wrapperOffset, maxOffset));
208
- const y = Math.round(-this.wrapperOffset * 100) / 100;
209
- this.wrapper.style.transform = `translate3d(0, ${y}px, 0)`;
210
- }
211
- targetsUpdate(target) {
212
- const ts = this.settings.targetSpeed;
213
- const tp = this.settings.targetPercentage;
214
- target.top += (this.scrollTop * Number(ts) * Number(target.speedY) - target.top) * tp;
215
- target.left += (this.scrollTop * Number(ts) * Number(target.speedX) - target.left) * tp;
216
- const targetOffsetTop = parseInt(String(target.percentage), 10) - target.top - parseInt(String(target.offset), 10);
217
- let offsetY = Math.round(targetOffsetTop * -100) / 100;
218
- let offsetX = 0;
219
- if (target.horizontal) {
220
- const targetOffsetLeft = parseInt(String(target.percentage), 10) - target.left - parseInt(String(target.offset), 10);
221
- offsetX = Math.round(targetOffsetLeft * -100) / 100;
222
- }
223
- target.elm.style.transform = `translate3d(${offsetX}px, ${offsetY}px, 0)`;
224
- }
225
177
  destroy() {
226
- var _a;
227
178
  this.detachOverlayWatcher();
228
- this.stopScrollLoop();
229
- window.removeEventListener('resize', this.onResize);
230
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
231
- this.resizeObserver = null;
179
+ cancelAnimationFrame(this.rafId);
180
+ this.rafId = 0;
181
+ window.removeEventListener('resize', this.onWindowResize);
232
182
  document.body.style.height = '';
233
183
  if (this.wrapper) {
234
184
  this.wrapper.removeAttribute('style');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coonlink-luxy",
3
- "version": "26.1.6",
3
+ "version": "26.1.8",
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": [