@oxog/scrollex 1.0.3 → 1.1.1
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/CHANGELOG.md +32 -1
- package/README.md +22 -5
- package/dist/chunk-MEEFAXSA.cjs +748 -0
- package/dist/chunk-MEEFAXSA.cjs.map +1 -0
- package/dist/chunk-VLA5K5HH.js +735 -0
- package/dist/chunk-VLA5K5HH.js.map +1 -0
- package/dist/index.cjs +154 -784
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -808
- package/dist/index.d.ts +5 -808
- package/dist/index.js +120 -764
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +33 -745
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +5 -529
- package/dist/plugins/index.d.ts +5 -529
- package/dist/plugins/index.js +11 -737
- package/dist/plugins/index.js.map +1 -1
- package/dist/scroll-controller-CBna5Yim.d.cts +830 -0
- package/dist/scroll-controller-CBna5Yim.d.ts +830 -0
- package/package.json +19 -5
package/dist/plugins/index.cjs
CHANGED
|
@@ -1,735 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkMEEFAXSA_cjs = require('../chunk-MEEFAXSA.cjs');
|
|
3
4
|
var react = require('react');
|
|
4
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
|
|
6
|
-
// src/plugins/core/list-renderer.ts
|
|
7
|
-
function listRendererPlugin(options = {}) {
|
|
8
|
-
const { getItemKey = (index) => index } = options;
|
|
9
|
-
let kernel = null;
|
|
10
|
-
let virtualItems = [];
|
|
11
|
-
let currentRange = {
|
|
12
|
-
startIndex: 0,
|
|
13
|
-
endIndex: 0,
|
|
14
|
-
overscanStartIndex: 0,
|
|
15
|
-
overscanEndIndex: 0
|
|
16
|
-
};
|
|
17
|
-
function buildVirtualItems(range) {
|
|
18
|
-
if (!kernel) return [];
|
|
19
|
-
const items = [];
|
|
20
|
-
range.startIndex;
|
|
21
|
-
range.endIndex;
|
|
22
|
-
const lastIndex = Math.min(range.overscanEndIndex, kernel.getItemCount() - 1);
|
|
23
|
-
for (let i = range.overscanStartIndex; i <= lastIndex; i++) {
|
|
24
|
-
const offset = kernel.getItemOffset(i);
|
|
25
|
-
const size = kernel.getCachedHeight(i) ?? kernel.getEstimatedHeight();
|
|
26
|
-
items.push({
|
|
27
|
-
index: i,
|
|
28
|
-
key: getItemKey(i),
|
|
29
|
-
start: offset,
|
|
30
|
-
end: offset + size,
|
|
31
|
-
size,
|
|
32
|
-
lane: 0
|
|
33
|
-
// For list, always lane 0
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return items;
|
|
37
|
-
}
|
|
38
|
-
function recalculate() {
|
|
39
|
-
if (!kernel) return;
|
|
40
|
-
currentRange = kernel.getVisibleRange();
|
|
41
|
-
virtualItems = buildVirtualItems(currentRange);
|
|
42
|
-
}
|
|
43
|
-
const api = {
|
|
44
|
-
getVirtualItems() {
|
|
45
|
-
return virtualItems;
|
|
46
|
-
},
|
|
47
|
-
getTotalHeight() {
|
|
48
|
-
return kernel?.getTotalSize() ?? 0;
|
|
49
|
-
},
|
|
50
|
-
getStartOffset() {
|
|
51
|
-
if (virtualItems.length === 0) return 0;
|
|
52
|
-
return virtualItems[0]?.start ?? 0;
|
|
53
|
-
},
|
|
54
|
-
getEndOffset() {
|
|
55
|
-
if (virtualItems.length === 0) return 0;
|
|
56
|
-
const lastItem = virtualItems[virtualItems.length - 1];
|
|
57
|
-
return lastItem?.end ?? 0;
|
|
58
|
-
},
|
|
59
|
-
isItemVisible(index) {
|
|
60
|
-
if (!kernel || index >= kernel.getItemCount()) return false;
|
|
61
|
-
return index >= currentRange.startIndex && index <= currentRange.endIndex;
|
|
62
|
-
},
|
|
63
|
-
recalculate
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
name: "list-renderer",
|
|
67
|
-
version: "1.0.0",
|
|
68
|
-
type: "core",
|
|
69
|
-
install(k) {
|
|
70
|
-
kernel = k;
|
|
71
|
-
recalculate();
|
|
72
|
-
},
|
|
73
|
-
uninstall() {
|
|
74
|
-
virtualItems = [];
|
|
75
|
-
kernel = null;
|
|
76
|
-
},
|
|
77
|
-
hooks: {
|
|
78
|
-
onScroll: () => recalculate(),
|
|
79
|
-
onResize: () => recalculate(),
|
|
80
|
-
onItemMeasured: () => recalculate(),
|
|
81
|
-
onVisibleRangeChange: (range) => {
|
|
82
|
-
currentRange = range;
|
|
83
|
-
virtualItems = buildVirtualItems(range);
|
|
84
|
-
},
|
|
85
|
-
onItemsChange: () => recalculate()
|
|
86
|
-
},
|
|
87
|
-
api
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/utils/array.ts
|
|
92
|
-
function normalizeColumnCount(columns) {
|
|
93
|
-
return Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 1;
|
|
94
|
-
}
|
|
95
|
-
function autoColumnCount(containerWidth, minColumnWidth, gap) {
|
|
96
|
-
const slot = minColumnWidth + gap;
|
|
97
|
-
return slot > 0 ? normalizeColumnCount(Math.floor((containerWidth + gap) / slot)) : 1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/plugins/core/grid-renderer.ts
|
|
101
|
-
function gridRendererPlugin(options) {
|
|
102
|
-
const {
|
|
103
|
-
columns,
|
|
104
|
-
minColumnWidth = 100,
|
|
105
|
-
rowHeight,
|
|
106
|
-
gap = 0,
|
|
107
|
-
getItemKey = (index) => index,
|
|
108
|
-
getContainerWidth
|
|
109
|
-
} = options;
|
|
110
|
-
let kernel = null;
|
|
111
|
-
let virtualItems = [];
|
|
112
|
-
let columnCount = typeof columns === "number" ? normalizeColumnCount(columns) : 1;
|
|
113
|
-
let columnWidth = 0;
|
|
114
|
-
let gapX = typeof gap === "number" ? gap : gap.x;
|
|
115
|
-
let gapY = typeof gap === "number" ? gap : gap.y;
|
|
116
|
-
function calculateColumns(containerWidth) {
|
|
117
|
-
if (typeof columns === "number") {
|
|
118
|
-
columnCount = normalizeColumnCount(columns);
|
|
119
|
-
} else {
|
|
120
|
-
columnCount = autoColumnCount(containerWidth, minColumnWidth, gapX);
|
|
121
|
-
}
|
|
122
|
-
columnWidth = (containerWidth - (columnCount - 1) * gapX) / columnCount;
|
|
123
|
-
}
|
|
124
|
-
function getRowCount() {
|
|
125
|
-
if (!kernel) return 0;
|
|
126
|
-
return Math.ceil(kernel.getItemCount() / columnCount);
|
|
127
|
-
}
|
|
128
|
-
function buildVirtualItems() {
|
|
129
|
-
if (!kernel) return [];
|
|
130
|
-
const viewport = kernel.getViewport();
|
|
131
|
-
const scrollPosition = kernel.getScrollPosition();
|
|
132
|
-
const scrollTop = scrollPosition.scrollTop;
|
|
133
|
-
const effectiveRowHeight = rowHeight + gapY;
|
|
134
|
-
const startRow = Math.max(0, Math.floor(scrollTop / effectiveRowHeight));
|
|
135
|
-
const visibleRows = Math.ceil(viewport.height / effectiveRowHeight);
|
|
136
|
-
const overscan = kernel.getOptions().overscan;
|
|
137
|
-
const endRow = Math.min(getRowCount() - 1, startRow + visibleRows + overscan);
|
|
138
|
-
const overscanStartRow = Math.max(0, startRow - overscan);
|
|
139
|
-
const items = [];
|
|
140
|
-
const itemCount = kernel.getItemCount();
|
|
141
|
-
for (let row = overscanStartRow; row <= endRow; row++) {
|
|
142
|
-
for (let col = 0; col < columnCount; col++) {
|
|
143
|
-
const index = row * columnCount + col;
|
|
144
|
-
if (index >= itemCount) break;
|
|
145
|
-
const top = row * effectiveRowHeight;
|
|
146
|
-
items.push({
|
|
147
|
-
index,
|
|
148
|
-
key: getItemKey(index),
|
|
149
|
-
start: top,
|
|
150
|
-
end: top + rowHeight,
|
|
151
|
-
size: rowHeight,
|
|
152
|
-
lane: col
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return items;
|
|
157
|
-
}
|
|
158
|
-
function recalculate() {
|
|
159
|
-
if (!kernel) return;
|
|
160
|
-
const viewport = kernel.getViewport();
|
|
161
|
-
calculateColumns(getContainerWidth?.() ?? viewport.width);
|
|
162
|
-
virtualItems = buildVirtualItems();
|
|
163
|
-
}
|
|
164
|
-
const api = {
|
|
165
|
-
getVirtualItems() {
|
|
166
|
-
return virtualItems;
|
|
167
|
-
},
|
|
168
|
-
getTotalHeight() {
|
|
169
|
-
const rowCount = getRowCount();
|
|
170
|
-
return rowCount === 0 ? 0 : rowCount * (rowHeight + gapY) - gapY;
|
|
171
|
-
},
|
|
172
|
-
getColumnCount() {
|
|
173
|
-
return columnCount;
|
|
174
|
-
},
|
|
175
|
-
getColumnWidth() {
|
|
176
|
-
return columnWidth;
|
|
177
|
-
},
|
|
178
|
-
getItemsPerRow() {
|
|
179
|
-
return columnCount;
|
|
180
|
-
},
|
|
181
|
-
getRowCount,
|
|
182
|
-
recalculate
|
|
183
|
-
};
|
|
184
|
-
return {
|
|
185
|
-
name: "grid-renderer",
|
|
186
|
-
version: "1.0.0",
|
|
187
|
-
type: "core",
|
|
188
|
-
install(k) {
|
|
189
|
-
kernel = k;
|
|
190
|
-
recalculate();
|
|
191
|
-
},
|
|
192
|
-
uninstall() {
|
|
193
|
-
virtualItems = [];
|
|
194
|
-
kernel = null;
|
|
195
|
-
},
|
|
196
|
-
hooks: {
|
|
197
|
-
onScroll: () => {
|
|
198
|
-
virtualItems = buildVirtualItems();
|
|
199
|
-
},
|
|
200
|
-
onResize: () => recalculate(),
|
|
201
|
-
onItemsChange: () => recalculate()
|
|
202
|
-
},
|
|
203
|
-
api
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// src/utils/debounce.ts
|
|
208
|
-
function debounce(fn, wait) {
|
|
209
|
-
let timeoutId = null;
|
|
210
|
-
let lastArgs = null;
|
|
211
|
-
let lastThis = null;
|
|
212
|
-
const debounced = function(...args) {
|
|
213
|
-
lastArgs = args;
|
|
214
|
-
lastThis = this;
|
|
215
|
-
if (timeoutId) {
|
|
216
|
-
clearTimeout(timeoutId);
|
|
217
|
-
}
|
|
218
|
-
timeoutId = setTimeout(() => {
|
|
219
|
-
timeoutId = null;
|
|
220
|
-
if (lastArgs) {
|
|
221
|
-
fn.apply(lastThis, lastArgs);
|
|
222
|
-
lastArgs = null;
|
|
223
|
-
lastThis = null;
|
|
224
|
-
}
|
|
225
|
-
}, wait);
|
|
226
|
-
};
|
|
227
|
-
debounced.cancel = () => {
|
|
228
|
-
if (timeoutId) {
|
|
229
|
-
clearTimeout(timeoutId);
|
|
230
|
-
timeoutId = null;
|
|
231
|
-
}
|
|
232
|
-
lastArgs = null;
|
|
233
|
-
lastThis = null;
|
|
234
|
-
};
|
|
235
|
-
debounced.flush = () => {
|
|
236
|
-
if (timeoutId) {
|
|
237
|
-
clearTimeout(timeoutId);
|
|
238
|
-
timeoutId = null;
|
|
239
|
-
if (lastArgs) {
|
|
240
|
-
fn.apply(lastThis, lastArgs);
|
|
241
|
-
lastArgs = null;
|
|
242
|
-
lastThis = null;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
return debounced;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// src/plugins/core/auto-measurer.ts
|
|
250
|
-
function autoMeasurerPlugin(options = {}) {
|
|
251
|
-
const {
|
|
252
|
-
estimatedItemHeight,
|
|
253
|
-
measureOnResize = true,
|
|
254
|
-
debounceMs = 100
|
|
255
|
-
} = options;
|
|
256
|
-
let kernel = null;
|
|
257
|
-
let resizeObserver = null;
|
|
258
|
-
const observedElements = /* @__PURE__ */ new WeakMap();
|
|
259
|
-
const elementsByIndex = /* @__PURE__ */ new Map();
|
|
260
|
-
let measureQueue = /* @__PURE__ */ new Set();
|
|
261
|
-
let flushScheduled = false;
|
|
262
|
-
function sizeAlongAxis(rect) {
|
|
263
|
-
return kernel?.getOptions().direction === "horizontal" ? rect.width : rect.height;
|
|
264
|
-
}
|
|
265
|
-
const debouncedFlush = debounce(() => {
|
|
266
|
-
flush();
|
|
267
|
-
}, debounceMs);
|
|
268
|
-
function flush() {
|
|
269
|
-
if (!kernel || measureQueue.size === 0) {
|
|
270
|
-
flushScheduled = false;
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const indicesToMeasure = Array.from(measureQueue);
|
|
274
|
-
measureQueue = /* @__PURE__ */ new Set();
|
|
275
|
-
flushScheduled = false;
|
|
276
|
-
const measurements = [];
|
|
277
|
-
for (const index of indicesToMeasure) {
|
|
278
|
-
const ref = elementsByIndex.get(index);
|
|
279
|
-
const element = ref?.deref();
|
|
280
|
-
if (element) {
|
|
281
|
-
const rect = element.getBoundingClientRect();
|
|
282
|
-
measurements.push({ index, height: sizeAlongAxis(rect) });
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
for (const { index, height } of measurements) {
|
|
286
|
-
if (height > 0) {
|
|
287
|
-
kernel.measureItem(index, height);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function scheduleFlush() {
|
|
292
|
-
if (!flushScheduled) {
|
|
293
|
-
flushScheduled = true;
|
|
294
|
-
requestAnimationFrame(() => {
|
|
295
|
-
flush();
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
function handleResize(entries) {
|
|
300
|
-
for (const entry of entries) {
|
|
301
|
-
const index = observedElements.get(entry.target);
|
|
302
|
-
if (index !== void 0) {
|
|
303
|
-
measureQueue.add(index);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (measureOnResize && measureQueue.size > 0) {
|
|
307
|
-
debouncedFlush();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
const api = {
|
|
311
|
-
measureElement(index, element) {
|
|
312
|
-
const rect = element.getBoundingClientRect();
|
|
313
|
-
const height = sizeAlongAxis(rect);
|
|
314
|
-
if (height > 0 && kernel) {
|
|
315
|
-
kernel.measureItem(index, height);
|
|
316
|
-
}
|
|
317
|
-
return height;
|
|
318
|
-
},
|
|
319
|
-
getCachedSize(index) {
|
|
320
|
-
return kernel?.getCachedHeight(index);
|
|
321
|
-
},
|
|
322
|
-
invalidate(index) {
|
|
323
|
-
kernel?.invalidateMeasurement(index);
|
|
324
|
-
},
|
|
325
|
-
invalidateAll() {
|
|
326
|
-
kernel?.invalidateAllMeasurements();
|
|
327
|
-
},
|
|
328
|
-
getMeasurementCache() {
|
|
329
|
-
const cache = /* @__PURE__ */ new Map();
|
|
330
|
-
if (!kernel) return cache;
|
|
331
|
-
const itemCount = kernel.getItemCount();
|
|
332
|
-
for (let i = 0; i < itemCount; i++) {
|
|
333
|
-
const height = kernel.getCachedHeight(i);
|
|
334
|
-
if (height !== void 0) {
|
|
335
|
-
cache.set(i, height);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return cache;
|
|
339
|
-
},
|
|
340
|
-
observe(index, element) {
|
|
341
|
-
const existingRef = elementsByIndex.get(index);
|
|
342
|
-
const existingElement = existingRef?.deref();
|
|
343
|
-
if (existingElement && existingElement !== element) {
|
|
344
|
-
resizeObserver?.unobserve(existingElement);
|
|
345
|
-
observedElements.delete(existingElement);
|
|
346
|
-
}
|
|
347
|
-
const previousIndex = observedElements.get(element);
|
|
348
|
-
if (previousIndex !== void 0 && previousIndex !== index) {
|
|
349
|
-
elementsByIndex.delete(previousIndex);
|
|
350
|
-
measureQueue.delete(previousIndex);
|
|
351
|
-
}
|
|
352
|
-
observedElements.set(element, index);
|
|
353
|
-
elementsByIndex.set(index, typeof WeakRef === "function" ? new WeakRef(element) : { deref: () => element });
|
|
354
|
-
resizeObserver?.observe(element);
|
|
355
|
-
measureQueue.add(index);
|
|
356
|
-
scheduleFlush();
|
|
357
|
-
},
|
|
358
|
-
unobserve(element) {
|
|
359
|
-
const index = observedElements.get(element);
|
|
360
|
-
if (index !== void 0) {
|
|
361
|
-
resizeObserver?.unobserve(element);
|
|
362
|
-
observedElements.delete(element);
|
|
363
|
-
elementsByIndex.delete(index);
|
|
364
|
-
measureQueue.delete(index);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
return {
|
|
369
|
-
name: "auto-measurer",
|
|
370
|
-
version: "1.0.0",
|
|
371
|
-
type: "core",
|
|
372
|
-
install(k) {
|
|
373
|
-
kernel = k;
|
|
374
|
-
if (estimatedItemHeight !== void 0) {
|
|
375
|
-
kernel.configure({ estimatedItemHeight });
|
|
376
|
-
}
|
|
377
|
-
if (measureOnResize && typeof ResizeObserver !== "undefined") {
|
|
378
|
-
resizeObserver = new ResizeObserver(handleResize);
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
uninstall() {
|
|
382
|
-
if (resizeObserver) {
|
|
383
|
-
resizeObserver.disconnect();
|
|
384
|
-
resizeObserver = null;
|
|
385
|
-
}
|
|
386
|
-
debouncedFlush.cancel();
|
|
387
|
-
measureQueue.clear();
|
|
388
|
-
elementsByIndex.clear();
|
|
389
|
-
flushScheduled = false;
|
|
390
|
-
kernel = null;
|
|
391
|
-
},
|
|
392
|
-
api
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// src/plugins/core/infinite-loader.ts
|
|
397
|
-
function initialLoaderState(direction) {
|
|
398
|
-
return { loading: false, loadGeneration: 0, hasMoreForward: true, hasMoreBackward: direction === "backward" || direction === "both" };
|
|
399
|
-
}
|
|
400
|
-
var sharedLoaderStates = /* @__PURE__ */ new WeakMap();
|
|
401
|
-
function infiniteLoaderPlugin(options) {
|
|
402
|
-
const {
|
|
403
|
-
threshold = 200,
|
|
404
|
-
thresholdItems = 5,
|
|
405
|
-
direction = "forward",
|
|
406
|
-
onLoadMore
|
|
407
|
-
} = options;
|
|
408
|
-
let kernel = null;
|
|
409
|
-
let state = initialLoaderState(direction);
|
|
410
|
-
let lastCheckTime = 0;
|
|
411
|
-
const checkDebounceMs = 100;
|
|
412
|
-
let pendingEvent = null;
|
|
413
|
-
let trailingTimer = null;
|
|
414
|
-
function checkLoadMore(event) {
|
|
415
|
-
if (state.loading || !kernel) return;
|
|
416
|
-
const now = performance.now();
|
|
417
|
-
if (now - lastCheckTime < checkDebounceMs) {
|
|
418
|
-
pendingEvent = event;
|
|
419
|
-
if (trailingTimer === null) {
|
|
420
|
-
trailingTimer = setTimeout(() => {
|
|
421
|
-
trailingTimer = null;
|
|
422
|
-
const latest = pendingEvent;
|
|
423
|
-
pendingEvent = null;
|
|
424
|
-
if (latest) runCheck(latest);
|
|
425
|
-
}, Math.max(0, checkDebounceMs - (now - lastCheckTime)));
|
|
426
|
-
}
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
runCheck(event);
|
|
430
|
-
}
|
|
431
|
-
function runCheck(event) {
|
|
432
|
-
if (state.loading || !kernel) return;
|
|
433
|
-
lastCheckTime = performance.now();
|
|
434
|
-
const viewport = kernel.getViewport();
|
|
435
|
-
const totalSize = kernel.getTotalSize();
|
|
436
|
-
const horizontal = kernel.getOptions().direction === "horizontal";
|
|
437
|
-
const scrollTop = horizontal ? event.scrollLeft : event.scrollTop;
|
|
438
|
-
const viewportSize = horizontal ? viewport.width : viewport.height;
|
|
439
|
-
if ((direction === "forward" || direction === "both") && state.hasMoreForward) {
|
|
440
|
-
const distanceFromBottom = totalSize - scrollTop - viewportSize;
|
|
441
|
-
if (distanceFromBottom < threshold) {
|
|
442
|
-
triggerLoad("forward");
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if ((direction === "backward" || direction === "both") && state.hasMoreBackward) {
|
|
447
|
-
if (scrollTop < threshold) {
|
|
448
|
-
triggerLoad("backward");
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
function checkLoadMoreByRange(range, forwardOnly = false) {
|
|
454
|
-
if (state.loading || !kernel) return;
|
|
455
|
-
const itemCount = kernel.getItemCount();
|
|
456
|
-
if ((direction === "forward" || direction === "both") && state.hasMoreForward) {
|
|
457
|
-
const itemsFromEnd = itemCount - 1 - range.endIndex;
|
|
458
|
-
if (itemsFromEnd <= thresholdItems) {
|
|
459
|
-
triggerLoad("forward");
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (!forwardOnly && (direction === "backward" || direction === "both") && state.hasMoreBackward) {
|
|
464
|
-
if (range.startIndex <= thresholdItems) {
|
|
465
|
-
triggerLoad("backward");
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
async function triggerLoad(loadDirection) {
|
|
471
|
-
if (state.loading || !kernel) return;
|
|
472
|
-
if (loadDirection === "forward" && !state.hasMoreForward) return;
|
|
473
|
-
if (loadDirection === "backward" && !state.hasMoreBackward) return;
|
|
474
|
-
state.loading = true;
|
|
475
|
-
const generation = ++state.loadGeneration;
|
|
476
|
-
kernel.emit({
|
|
477
|
-
type: "load-more",
|
|
478
|
-
direction: loadDirection
|
|
479
|
-
});
|
|
480
|
-
try {
|
|
481
|
-
await onLoadMore(loadDirection);
|
|
482
|
-
} catch (error) {
|
|
483
|
-
console.error("[Scrollex] Error in onLoadMore:", error);
|
|
484
|
-
} finally {
|
|
485
|
-
if (generation === state.loadGeneration) {
|
|
486
|
-
state.loading = false;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
const api = {
|
|
491
|
-
isLoading() {
|
|
492
|
-
return state.loading;
|
|
493
|
-
},
|
|
494
|
-
setLoading(l) {
|
|
495
|
-
state.loading = l;
|
|
496
|
-
},
|
|
497
|
-
hasMore() {
|
|
498
|
-
return state.hasMoreForward || state.hasMoreBackward;
|
|
499
|
-
},
|
|
500
|
-
setHasMore(hasMore) {
|
|
501
|
-
state.hasMoreForward = hasMore;
|
|
502
|
-
state.hasMoreBackward = hasMore;
|
|
503
|
-
},
|
|
504
|
-
hasMoreForward() {
|
|
505
|
-
return state.hasMoreForward;
|
|
506
|
-
},
|
|
507
|
-
setHasMoreForward(hasMore) {
|
|
508
|
-
state.hasMoreForward = hasMore;
|
|
509
|
-
},
|
|
510
|
-
hasMoreBackward() {
|
|
511
|
-
return state.hasMoreBackward;
|
|
512
|
-
},
|
|
513
|
-
setHasMoreBackward(hasMore) {
|
|
514
|
-
state.hasMoreBackward = hasMore;
|
|
515
|
-
},
|
|
516
|
-
reset() {
|
|
517
|
-
state.loadGeneration++;
|
|
518
|
-
state.loading = false;
|
|
519
|
-
state.hasMoreForward = true;
|
|
520
|
-
state.hasMoreBackward = direction === "backward" || direction === "both";
|
|
521
|
-
if (trailingTimer !== null) {
|
|
522
|
-
clearTimeout(trailingTimer);
|
|
523
|
-
trailingTimer = null;
|
|
524
|
-
}
|
|
525
|
-
pendingEvent = null;
|
|
526
|
-
},
|
|
527
|
-
triggerLoad(loadDirection) {
|
|
528
|
-
triggerLoad(loadDirection);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
return {
|
|
532
|
-
name: "infinite-loader",
|
|
533
|
-
version: "1.0.0",
|
|
534
|
-
type: "core",
|
|
535
|
-
install(k) {
|
|
536
|
-
kernel = k;
|
|
537
|
-
const shared = sharedLoaderStates.get(k);
|
|
538
|
-
if (shared) {
|
|
539
|
-
state = shared;
|
|
540
|
-
} else {
|
|
541
|
-
sharedLoaderStates.set(k, state);
|
|
542
|
-
checkLoadMoreByRange(k.getVisibleRange(), true);
|
|
543
|
-
}
|
|
544
|
-
},
|
|
545
|
-
uninstall() {
|
|
546
|
-
if (trailingTimer !== null) {
|
|
547
|
-
clearTimeout(trailingTimer);
|
|
548
|
-
trailingTimer = null;
|
|
549
|
-
}
|
|
550
|
-
pendingEvent = null;
|
|
551
|
-
kernel = null;
|
|
552
|
-
},
|
|
553
|
-
hooks: {
|
|
554
|
-
onScroll: checkLoadMore,
|
|
555
|
-
onVisibleRangeChange: (range) => checkLoadMoreByRange(range)
|
|
556
|
-
},
|
|
557
|
-
api
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// src/utils/raf.ts
|
|
562
|
-
function raf(callback) {
|
|
563
|
-
if (typeof requestAnimationFrame !== "undefined") {
|
|
564
|
-
return requestAnimationFrame(callback);
|
|
565
|
-
}
|
|
566
|
-
return setTimeout(() => callback(performance.now()), 16);
|
|
567
|
-
}
|
|
568
|
-
function cancelRaf(id) {
|
|
569
|
-
if (typeof cancelAnimationFrame !== "undefined") {
|
|
570
|
-
cancelAnimationFrame(id);
|
|
571
|
-
} else {
|
|
572
|
-
clearTimeout(id);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// src/plugins/core/scroll-controller.ts
|
|
577
|
-
var easings = {
|
|
578
|
-
easeInOut: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t};
|
|
579
|
-
function scrollControllerPlugin(options = {}) {
|
|
580
|
-
const {
|
|
581
|
-
defaultDuration = 300,
|
|
582
|
-
defaultEasing = easings.easeInOut
|
|
583
|
-
} = options;
|
|
584
|
-
let kernel = null;
|
|
585
|
-
let animationId = null;
|
|
586
|
-
let animating = false;
|
|
587
|
-
let animationGeneration = 0;
|
|
588
|
-
function isHorizontal(k) {
|
|
589
|
-
return k.getOptions().direction === "horizontal";
|
|
590
|
-
}
|
|
591
|
-
function getOffset(k) {
|
|
592
|
-
const position = k.getScrollPosition();
|
|
593
|
-
return isHorizontal(k) ? position.scrollLeft : position.scrollTop;
|
|
594
|
-
}
|
|
595
|
-
function setOffset(k, offset) {
|
|
596
|
-
k.setScrollPosition(isHorizontal(k) ? { scrollLeft: offset } : { scrollTop: offset });
|
|
597
|
-
}
|
|
598
|
-
function getViewportSize(k) {
|
|
599
|
-
const viewport = k.getViewport();
|
|
600
|
-
return isHorizontal(k) ? viewport.width : viewport.height;
|
|
601
|
-
}
|
|
602
|
-
function animateScroll(targetOffset, duration, easing) {
|
|
603
|
-
if (!kernel) return;
|
|
604
|
-
stopAnimation();
|
|
605
|
-
const generation = animationGeneration;
|
|
606
|
-
const startTime = performance.now();
|
|
607
|
-
const startOffset = getOffset(kernel);
|
|
608
|
-
const distance = targetOffset - startOffset;
|
|
609
|
-
if (distance === 0 || !(duration > 0)) {
|
|
610
|
-
setOffset(kernel, targetOffset);
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
animating = true;
|
|
614
|
-
function animate(currentTime) {
|
|
615
|
-
if (!kernel) {
|
|
616
|
-
animating = false;
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
if (generation !== animationGeneration) return;
|
|
620
|
-
const elapsed = currentTime - startTime;
|
|
621
|
-
const progress = Math.max(0, Math.min(elapsed / duration, 1));
|
|
622
|
-
const easedProgress = easing(progress);
|
|
623
|
-
const currentOffset = startOffset + distance * easedProgress;
|
|
624
|
-
setOffset(kernel, currentOffset);
|
|
625
|
-
if (generation !== animationGeneration) return;
|
|
626
|
-
if (progress < 1) {
|
|
627
|
-
animationId = raf(animate);
|
|
628
|
-
} else {
|
|
629
|
-
animationId = null;
|
|
630
|
-
animating = false;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
animationId = raf(animate);
|
|
634
|
-
}
|
|
635
|
-
function stopAnimation() {
|
|
636
|
-
animationGeneration++;
|
|
637
|
-
if (animationId !== null) {
|
|
638
|
-
cancelRaf(animationId);
|
|
639
|
-
animationId = null;
|
|
640
|
-
}
|
|
641
|
-
animating = false;
|
|
642
|
-
}
|
|
643
|
-
const api = {
|
|
644
|
-
scrollTo(offset, options2 = {}) {
|
|
645
|
-
if (!kernel) return;
|
|
646
|
-
const {
|
|
647
|
-
behavior = "auto",
|
|
648
|
-
duration = defaultDuration,
|
|
649
|
-
easing = defaultEasing
|
|
650
|
-
} = options2;
|
|
651
|
-
if (behavior === "auto") {
|
|
652
|
-
stopAnimation();
|
|
653
|
-
setOffset(kernel, offset);
|
|
654
|
-
} else {
|
|
655
|
-
animateScroll(offset, duration, easing);
|
|
656
|
-
}
|
|
657
|
-
},
|
|
658
|
-
scrollToIndex(index, options2 = {}) {
|
|
659
|
-
if (!kernel) return;
|
|
660
|
-
const {
|
|
661
|
-
align = "auto",
|
|
662
|
-
offset: additionalOffset = 0,
|
|
663
|
-
...scrollOptions
|
|
664
|
-
} = options2;
|
|
665
|
-
const itemOffset = kernel.getItemOffset(index);
|
|
666
|
-
const itemSize = kernel.getCachedHeight(index) ?? kernel.getEstimatedHeight();
|
|
667
|
-
const viewportSize = getViewportSize(kernel);
|
|
668
|
-
let targetOffset;
|
|
669
|
-
switch (align) {
|
|
670
|
-
case "start":
|
|
671
|
-
targetOffset = itemOffset;
|
|
672
|
-
break;
|
|
673
|
-
case "center":
|
|
674
|
-
targetOffset = itemOffset - viewportSize / 2 + itemSize / 2;
|
|
675
|
-
break;
|
|
676
|
-
case "end":
|
|
677
|
-
targetOffset = itemOffset - viewportSize + itemSize;
|
|
678
|
-
break;
|
|
679
|
-
case "auto":
|
|
680
|
-
default: {
|
|
681
|
-
const visibleStart = getOffset(kernel);
|
|
682
|
-
const visibleEnd = visibleStart + viewportSize;
|
|
683
|
-
const itemEnd = itemOffset + itemSize;
|
|
684
|
-
if (itemOffset < visibleStart) {
|
|
685
|
-
targetOffset = itemOffset;
|
|
686
|
-
} else if (itemEnd > visibleEnd) {
|
|
687
|
-
targetOffset = itemEnd - viewportSize;
|
|
688
|
-
} else {
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
break;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
const maxScroll = Math.max(0, kernel.getTotalSize() - viewportSize);
|
|
695
|
-
targetOffset = Math.max(0, Math.min(targetOffset + additionalOffset, maxScroll));
|
|
696
|
-
api.scrollTo(targetOffset, scrollOptions);
|
|
697
|
-
},
|
|
698
|
-
scrollToTop(options2 = {}) {
|
|
699
|
-
api.scrollTo(0, options2);
|
|
700
|
-
},
|
|
701
|
-
scrollToBottom(options2 = {}) {
|
|
702
|
-
if (!kernel) return;
|
|
703
|
-
const totalSize = kernel.getTotalSize();
|
|
704
|
-
const maxScroll = Math.max(0, totalSize - getViewportSize(kernel));
|
|
705
|
-
api.scrollTo(maxScroll, options2);
|
|
706
|
-
},
|
|
707
|
-
getScrollPosition() {
|
|
708
|
-
return kernel?.getScrollPosition() ?? { scrollTop: 0, scrollLeft: 0 };
|
|
709
|
-
},
|
|
710
|
-
isScrolling() {
|
|
711
|
-
return kernel?.isScrolling() ?? false;
|
|
712
|
-
},
|
|
713
|
-
isAnimating() {
|
|
714
|
-
return animating;
|
|
715
|
-
},
|
|
716
|
-
stopAnimation
|
|
717
|
-
};
|
|
718
|
-
return {
|
|
719
|
-
name: "scroll-controller",
|
|
720
|
-
version: "1.0.0",
|
|
721
|
-
type: "core",
|
|
722
|
-
install(k) {
|
|
723
|
-
kernel = k;
|
|
724
|
-
},
|
|
725
|
-
uninstall() {
|
|
726
|
-
stopAnimation();
|
|
727
|
-
kernel = null;
|
|
728
|
-
},
|
|
729
|
-
api
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
|
|
733
7
|
// src/plugins/optional/masonry-renderer.ts
|
|
734
8
|
function masonryRenderer(options) {
|
|
735
9
|
const {
|
|
@@ -741,16 +15,16 @@ function masonryRenderer(options) {
|
|
|
741
15
|
} = options;
|
|
742
16
|
let kernel = null;
|
|
743
17
|
let virtualItems = [];
|
|
744
|
-
let columnCount = typeof columns === "number" ? normalizeColumnCount(columns) : 1;
|
|
18
|
+
let columnCount = typeof columns === "number" ? chunkMEEFAXSA_cjs.normalizeColumnCount(columns) : 1;
|
|
745
19
|
let columnWidth = 0;
|
|
746
20
|
let columnHeights = [];
|
|
747
21
|
let totalHeight = 0;
|
|
748
22
|
const layoutCache = /* @__PURE__ */ new Map();
|
|
749
23
|
function calculateColumns(containerWidth) {
|
|
750
24
|
if (typeof columns === "number") {
|
|
751
|
-
columnCount = normalizeColumnCount(columns);
|
|
25
|
+
columnCount = chunkMEEFAXSA_cjs.normalizeColumnCount(columns);
|
|
752
26
|
} else {
|
|
753
|
-
columnCount = autoColumnCount(containerWidth, minColumnWidth, gap);
|
|
27
|
+
columnCount = chunkMEEFAXSA_cjs.autoColumnCount(containerWidth, minColumnWidth, gap);
|
|
754
28
|
}
|
|
755
29
|
columnWidth = (containerWidth - (columnCount - 1) * gap) / columnCount;
|
|
756
30
|
}
|
|
@@ -880,10 +154,8 @@ function masonryRenderer(options) {
|
|
|
880
154
|
// src/plugins/optional/sticky-headers.ts
|
|
881
155
|
function stickyHeaders(options) {
|
|
882
156
|
const {
|
|
883
|
-
headerHeight,
|
|
884
157
|
isHeader,
|
|
885
158
|
getGroupId,
|
|
886
|
-
zIndex = 10,
|
|
887
159
|
stickyOffset = 0
|
|
888
160
|
} = options;
|
|
889
161
|
let kernel = null;
|
|
@@ -1351,7 +623,7 @@ function scrollRestoration(options) {
|
|
|
1351
623
|
const horizontal = kernel.getOptions().direction === "horizontal";
|
|
1352
624
|
const viewport = kernel.getViewport();
|
|
1353
625
|
const target = horizontal ? state.scrollLeft : state.scrollTop;
|
|
1354
|
-
const maxScroll = kernel.getTotalSize() - (horizontal ? viewport.width : viewport.height);
|
|
626
|
+
const maxScroll = kernel.getTotalSize() + (kernel.getOptions().scrollMargin ?? 0) - (horizontal ? viewport.width : viewport.height);
|
|
1355
627
|
if (target > maxScroll + 1) {
|
|
1356
628
|
awaitingContent = true;
|
|
1357
629
|
return;
|
|
@@ -1369,6 +641,10 @@ function scrollRestoration(options) {
|
|
|
1369
641
|
}
|
|
1370
642
|
}
|
|
1371
643
|
function handleScroll(_event) {
|
|
644
|
+
if (awaitingContent && kernel) {
|
|
645
|
+
awaitingContent = false;
|
|
646
|
+
restoredKernels.set(kernel, key);
|
|
647
|
+
}
|
|
1372
648
|
if (saveOnScroll && debouncedSave) {
|
|
1373
649
|
debouncedSave();
|
|
1374
650
|
}
|
|
@@ -1391,7 +667,7 @@ function scrollRestoration(options) {
|
|
|
1391
667
|
install(k) {
|
|
1392
668
|
kernel = k;
|
|
1393
669
|
if (saveOnScroll) {
|
|
1394
|
-
debouncedSave = debounce(save, debounceMs);
|
|
670
|
+
debouncedSave = chunkMEEFAXSA_cjs.debounce(save, debounceMs);
|
|
1395
671
|
}
|
|
1396
672
|
if (restoreOnMount && restoredKernels.get(k) !== key) {
|
|
1397
673
|
restoreFrame = requestAnimationFrame(() => {
|
|
@@ -1503,8 +779,9 @@ function bidirectional(options = {}) {
|
|
|
1503
779
|
if (scrollPosition.scrollTop > stickThreshold) ;
|
|
1504
780
|
}
|
|
1505
781
|
if (isSticking && stickToBottom) {
|
|
782
|
+
const k = kernel;
|
|
1506
783
|
requestAnimationFrame(() => {
|
|
1507
|
-
|
|
784
|
+
k.scrollTo(k.getTotalSize());
|
|
1508
785
|
});
|
|
1509
786
|
}
|
|
1510
787
|
}
|
|
@@ -1549,7 +826,6 @@ function bidirectional(options = {}) {
|
|
|
1549
826
|
type: "optional",
|
|
1550
827
|
install(k) {
|
|
1551
828
|
kernel = k;
|
|
1552
|
-
k.getItemCount();
|
|
1553
829
|
previousTotalSize = k.getTotalSize();
|
|
1554
830
|
isSticking = stickToBottom && (initialPosition === "bottom" && !positionedKernels.has(k) || checkIsAtBottom());
|
|
1555
831
|
if (initialPosition === "bottom" && !positionedKernels.has(k)) {
|
|
@@ -1591,10 +867,7 @@ function dragToReorder(options) {
|
|
|
1591
867
|
const {
|
|
1592
868
|
enabled: initialEnabled = true,
|
|
1593
869
|
axis = "vertical",
|
|
1594
|
-
handle = true,
|
|
1595
870
|
autoScroll = true,
|
|
1596
|
-
autoScrollSpeed = 10,
|
|
1597
|
-
dropIndicator = "line",
|
|
1598
871
|
onDragStart,
|
|
1599
872
|
onDragEnd,
|
|
1600
873
|
onReorder,
|
|
@@ -1857,7 +1130,7 @@ function debugPanel(options = {}) {
|
|
|
1857
1130
|
const horizontal = kernel.getOptions().direction === "horizontal";
|
|
1858
1131
|
const viewport = kernel.getViewport();
|
|
1859
1132
|
const scrollOffset = horizontal ? scrollPos.scrollLeft : scrollPos.scrollTop;
|
|
1860
|
-
const maxScroll = kernel.getTotalSize() - (horizontal ? viewport.width : viewport.height);
|
|
1133
|
+
const maxScroll = kernel.getTotalSize() + (kernel.getOptions().scrollMargin ?? 0) - (horizontal ? viewport.width : viewport.height);
|
|
1861
1134
|
state.stats = {
|
|
1862
1135
|
...state.stats,
|
|
1863
1136
|
memoryUsage,
|
|
@@ -2379,17 +1652,32 @@ function EventsPanel({ eventLog, onClear }) {
|
|
|
2379
1652
|
] });
|
|
2380
1653
|
}
|
|
2381
1654
|
|
|
1655
|
+
Object.defineProperty(exports, "autoMeasurerPlugin", {
|
|
1656
|
+
enumerable: true,
|
|
1657
|
+
get: function () { return chunkMEEFAXSA_cjs.autoMeasurerPlugin; }
|
|
1658
|
+
});
|
|
1659
|
+
Object.defineProperty(exports, "gridRendererPlugin", {
|
|
1660
|
+
enumerable: true,
|
|
1661
|
+
get: function () { return chunkMEEFAXSA_cjs.gridRendererPlugin; }
|
|
1662
|
+
});
|
|
1663
|
+
Object.defineProperty(exports, "infiniteLoaderPlugin", {
|
|
1664
|
+
enumerable: true,
|
|
1665
|
+
get: function () { return chunkMEEFAXSA_cjs.infiniteLoaderPlugin; }
|
|
1666
|
+
});
|
|
1667
|
+
Object.defineProperty(exports, "listRendererPlugin", {
|
|
1668
|
+
enumerable: true,
|
|
1669
|
+
get: function () { return chunkMEEFAXSA_cjs.listRendererPlugin; }
|
|
1670
|
+
});
|
|
1671
|
+
Object.defineProperty(exports, "scrollControllerPlugin", {
|
|
1672
|
+
enumerable: true,
|
|
1673
|
+
get: function () { return chunkMEEFAXSA_cjs.scrollControllerPlugin; }
|
|
1674
|
+
});
|
|
2382
1675
|
exports.DebugPanelOverlay = DebugPanelOverlay;
|
|
2383
|
-
exports.autoMeasurerPlugin = autoMeasurerPlugin;
|
|
2384
1676
|
exports.bidirectional = bidirectional;
|
|
2385
1677
|
exports.debugPanel = debugPanel;
|
|
2386
1678
|
exports.dragToReorder = dragToReorder;
|
|
2387
|
-
exports.gridRendererPlugin = gridRendererPlugin;
|
|
2388
|
-
exports.infiniteLoaderPlugin = infiniteLoaderPlugin;
|
|
2389
1679
|
exports.keyboardNav = keyboardNav;
|
|
2390
|
-
exports.listRendererPlugin = listRendererPlugin;
|
|
2391
1680
|
exports.masonryRenderer = masonryRenderer;
|
|
2392
|
-
exports.scrollControllerPlugin = scrollControllerPlugin;
|
|
2393
1681
|
exports.scrollRestoration = scrollRestoration;
|
|
2394
1682
|
exports.stickyHeaders = stickyHeaders;
|
|
2395
1683
|
//# sourceMappingURL=index.cjs.map
|