@fragiola/primitives 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/async-list-Bv6ff5Oj.js +81 -0
- package/dist/async-list-Bv6ff5Oj.js.map +1 -0
- package/dist/async-list.d.ts +2 -0
- package/dist/async-list.js +1 -0
- package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
- package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
- package/dist/calendar-systems-Daa6Q_ca.js +659 -0
- package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
- package/dist/calendar-systems.d.ts +3 -0
- package/dist/calendar-systems.js +1 -0
- package/dist/carousel-LRbWqbAx.js +375 -0
- package/dist/carousel-LRbWqbAx.js.map +1 -0
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +1 -0
- package/dist/cascade-B155Xvvv.js +64 -0
- package/dist/cascade-B155Xvvv.js.map +1 -0
- package/dist/cascade.d.ts +2 -0
- package/dist/cascade.js +1 -0
- package/dist/clipboard-Cy2cbGEW.js +33 -0
- package/dist/clipboard-Cy2cbGEW.js.map +1 -0
- package/dist/clipboard.d.ts +2 -0
- package/dist/clipboard.js +1 -0
- package/dist/collection-Dbk-PB5S.js +609 -0
- package/dist/collection-Dbk-PB5S.js.map +1 -0
- package/dist/collection.d.ts +2 -0
- package/dist/collection.js +3 -0
- package/dist/color-sURV5Irg.js +699 -0
- package/dist/color-sURV5Irg.js.map +1 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +1 -0
- package/dist/command-DueCXi65.js +104 -0
- package/dist/command-DueCXi65.js.map +1 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +1 -0
- package/dist/date-CrbFSJKQ.js +215 -0
- package/dist/date-CrbFSJKQ.js.map +1 -0
- package/dist/date.d.ts +4 -0
- package/dist/date.js +1 -0
- package/dist/direction-CTnVLpmd.d.ts +8 -0
- package/dist/direction-DJDPvnxJ.js +13 -0
- package/dist/direction-DJDPvnxJ.js.map +1 -0
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +1 -0
- package/dist/drag-session-CSr06B5v.js +41 -0
- package/dist/drag-session-CSr06B5v.js.map +1 -0
- package/dist/file-DSLtfzbi.js +263 -0
- package/dist/file-DSLtfzbi.js.map +1 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +1 -0
- package/dist/focus-BI-VvM0f.js +75 -0
- package/dist/focus-BI-VvM0f.js.map +1 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +3 -0
- package/dist/form-DovwKtqz.js +501 -0
- package/dist/form-DovwKtqz.js.map +1 -0
- package/dist/form.d.ts +2 -0
- package/dist/form.js +1 -0
- package/dist/hover-BakyPYnC.js +62 -0
- package/dist/hover-BakyPYnC.js.map +1 -0
- package/dist/hover.d.ts +2 -0
- package/dist/hover.js +1 -0
- package/dist/id-B0Y8iZrc.js +13 -0
- package/dist/id-B0Y8iZrc.js.map +1 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +1 -0
- package/dist/image-D4X_yRYw.js +44 -0
- package/dist/image-D4X_yRYw.js.map +1 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +1 -0
- package/dist/index-B0rwIZw9.d.ts +51 -0
- package/dist/index-B4wF1isn.d.ts +128 -0
- package/dist/index-BHiBRE01.d.ts +20 -0
- package/dist/index-BNlMm-0u.d.ts +17 -0
- package/dist/index-BapNrjY9.d.ts +48 -0
- package/dist/index-Bd-tVb7C.d.ts +6 -0
- package/dist/index-BjE8nDiX.d.ts +125 -0
- package/dist/index-BpbT-FsX.d.ts +117 -0
- package/dist/index-CBgGcTeX.d.ts +37 -0
- package/dist/index-CGThV_Md.d.ts +100 -0
- package/dist/index-CMig3TXL.d.ts +28 -0
- package/dist/index-CWFRduRd.d.ts +212 -0
- package/dist/index-CkrHWyU_.d.ts +33 -0
- package/dist/index-Cwu6f7y1.d.ts +18 -0
- package/dist/index-D10LDdR6.d.ts +139 -0
- package/dist/index-D146vm21.d.ts +104 -0
- package/dist/index-DGKhEvNr.d.ts +107 -0
- package/dist/index-DbAu4s16.d.ts +48 -0
- package/dist/index-DdaCj6IO.d.ts +54 -0
- package/dist/index-DeHcNdjC.d.ts +68 -0
- package/dist/index-DeR4ncrW.d.ts +93 -0
- package/dist/index-HIksgK0e.d.ts +70 -0
- package/dist/index-IZB0mlZl.d.ts +71 -0
- package/dist/index-IfDZj87U.d.ts +28 -0
- package/dist/index-SrTuVBms.d.ts +75 -0
- package/dist/index-T9UcYvkf.d.ts +339 -0
- package/dist/index-fRTojAoR.d.ts +31 -0
- package/dist/index-fuLUke9n.d.ts +6 -0
- package/dist/index-l63esAck.d.ts +104 -0
- package/dist/index-raSUg9U7.d.ts +38 -0
- package/dist/index-twgzPKvZ.d.ts +278 -0
- package/dist/index-wBpjRykh.d.ts +125 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +42 -0
- package/dist/inert-DlGToy3q.js +80 -0
- package/dist/inert-DlGToy3q.js.map +1 -0
- package/dist/inert.d.ts +2 -0
- package/dist/inert.js +1 -0
- package/dist/layer-stack-BEtzaFC1.js +118 -0
- package/dist/layer-stack-BEtzaFC1.js.map +1 -0
- package/dist/layers-C-N4rrZX.js +24 -0
- package/dist/layers-C-N4rrZX.js.map +1 -0
- package/dist/layers.d.ts +2 -0
- package/dist/layers.js +3 -0
- package/dist/list-navigation-CbWv4DK5.js +40 -0
- package/dist/list-navigation-CbWv4DK5.js.map +1 -0
- package/dist/month-year-BG5imFUq.js +108 -0
- package/dist/month-year-BG5imFUq.js.map +1 -0
- package/dist/month-year.d.ts +3 -0
- package/dist/month-year.js +1 -0
- package/dist/number-BFUio97d.js +316 -0
- package/dist/number-BFUio97d.js.map +1 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +1 -0
- package/dist/overlay-BwPyiM3T.js +78 -0
- package/dist/overlay-BwPyiM3T.js.map +1 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +1 -0
- package/dist/pagination-BkVzaIGP.js +51 -0
- package/dist/pagination-BkVzaIGP.js.map +1 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +1 -0
- package/dist/plain-date-idQH1P6X.d.ts +29 -0
- package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
- package/dist/pointer-CuDtD9XA.js +189 -0
- package/dist/pointer-CuDtD9XA.js.map +1 -0
- package/dist/pointer.d.ts +2 -0
- package/dist/pointer.js +3 -0
- package/dist/positioning-DDUQ75mB.js +148 -0
- package/dist/positioning-DDUQ75mB.js.map +1 -0
- package/dist/positioning.d.ts +2 -0
- package/dist/positioning.js +1 -0
- package/dist/presence-BhKDOmII.js +86 -0
- package/dist/presence-BhKDOmII.js.map +1 -0
- package/dist/presence.d.ts +2 -0
- package/dist/presence.js +1 -0
- package/dist/range-o0_GBhyY.js +158 -0
- package/dist/range-o0_GBhyY.js.map +1 -0
- package/dist/range.d.ts +2 -0
- package/dist/range.js +1 -0
- package/dist/scroll-area-BYNhv36t.js +447 -0
- package/dist/scroll-area-BYNhv36t.js.map +1 -0
- package/dist/scroll-area.d.ts +2 -0
- package/dist/scroll-area.js +1 -0
- package/dist/scroll-lock-JzRNOA1O.js +42 -0
- package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
- package/dist/scroll-lock.d.ts +2 -0
- package/dist/scroll-lock.js +1 -0
- package/dist/segments-eRu5G_Bd.js +587 -0
- package/dist/segments-eRu5G_Bd.js.map +1 -0
- package/dist/segments.d.ts +3 -0
- package/dist/segments.js +1 -0
- package/dist/selection-Cor67w_V.js +287 -0
- package/dist/selection-Cor67w_V.js.map +1 -0
- package/dist/selection.d.ts +2 -0
- package/dist/selection.js +1 -0
- package/dist/swipe.d.ts +2 -0
- package/dist/swipe.js +1 -0
- package/dist/tabbable-BPiLssIv.js +35 -0
- package/dist/tabbable-BPiLssIv.js.map +1 -0
- package/dist/time-Ct6oq9kt.js +208 -0
- package/dist/time-Ct6oq9kt.js.map +1 -0
- package/dist/time-zone-DegkzwST.js +305 -0
- package/dist/time-zone-DegkzwST.js.map +1 -0
- package/dist/time-zone.d.ts +2 -0
- package/dist/time-zone.js +1 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +1 -0
- package/dist/toast-BjRpJalM.js +400 -0
- package/dist/toast-BjRpJalM.js.map +1 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +1 -0
- package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
- package/dist/virtual-BlX1RuHD.js +306 -0
- package/dist/virtual-BlX1RuHD.js.map +1 -0
- package/dist/virtual.d.ts +2 -0
- package/dist/virtual.js +1 -0
- package/dist/watch-swipe-BIucfr9O.js +301 -0
- package/dist/watch-swipe-BIucfr9O.js.map +1 -0
- package/package.json +234 -3
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// src/virtual/virtual-layout.ts
|
|
2
|
+
/**
|
|
3
|
+
* Where every row starts: `starts[i]` is row `i`'s offset, `starts[count]` the list's extent. A
|
|
4
|
+
* gap separates two rows (none after the last).
|
|
5
|
+
*/
|
|
6
|
+
function rowStarts(count, size, gap = 0) {
|
|
7
|
+
const starts = new Float64Array(count + 1);
|
|
8
|
+
for (let index = 0; index < count; index += 1) starts[index + 1] = starts[index] + size(index) + (index < count - 1 ? gap : 0);
|
|
9
|
+
return starts;
|
|
10
|
+
}
|
|
11
|
+
/** The row at `offset`: the last one starting at or before it (clamped to the list). */
|
|
12
|
+
function rowAt(starts, offset) {
|
|
13
|
+
const count = starts.length - 1;
|
|
14
|
+
if (count <= 0) return -1;
|
|
15
|
+
let low = 0;
|
|
16
|
+
let high = count - 1;
|
|
17
|
+
while (low < high) {
|
|
18
|
+
const middle = low + high + 1 >> 1;
|
|
19
|
+
if (starts[middle] <= offset) low = middle;
|
|
20
|
+
else high = middle - 1;
|
|
21
|
+
}
|
|
22
|
+
return low;
|
|
23
|
+
}
|
|
24
|
+
/** The sticky row of the group in view: the last sticky row at or before `first`. */
|
|
25
|
+
function activeSticky(sticky, first) {
|
|
26
|
+
let active;
|
|
27
|
+
for (const index of sticky) {
|
|
28
|
+
if (index > first) break;
|
|
29
|
+
active = index;
|
|
30
|
+
}
|
|
31
|
+
return active;
|
|
32
|
+
}
|
|
33
|
+
const EMPTY = {
|
|
34
|
+
rows: [],
|
|
35
|
+
spaceAfter: 0,
|
|
36
|
+
totalSize: 0,
|
|
37
|
+
visibleStart: -1,
|
|
38
|
+
visibleEnd: -1
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The rows a virtual list renders for a scroll position (spec/README.md, "Virtual lists"): the
|
|
42
|
+
* rows in view, `overscan` rows beyond each end, the pinned rows and the sticky row of the group
|
|
43
|
+
* in view, each with the room before it. Pure: the framework renders the rows, the virtualizer
|
|
44
|
+
* reads the DOM.
|
|
45
|
+
*/
|
|
46
|
+
function virtualLayout(options, starts = rowStarts(options.count, options.size, options.gap ?? 0)) {
|
|
47
|
+
const { count, size, gap = 0, overscan = 4, pinned = [], sticky = [] } = options;
|
|
48
|
+
if (count <= 0) return EMPTY;
|
|
49
|
+
const totalSize = starts[count];
|
|
50
|
+
const top = Math.min(Math.max(options.offset, 0), totalSize);
|
|
51
|
+
const bottom = top + Math.max(options.viewport, 0);
|
|
52
|
+
const visibleStart = rowAt(starts, top);
|
|
53
|
+
let visibleEnd = rowAt(starts, bottom);
|
|
54
|
+
if (visibleEnd > visibleStart && starts[visibleEnd] >= bottom) visibleEnd -= 1;
|
|
55
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
56
|
+
const from = Math.max(0, visibleStart - overscan);
|
|
57
|
+
const to = Math.min(count - 1, visibleEnd + overscan);
|
|
58
|
+
for (let index = from; index <= to; index += 1) indexes.add(index);
|
|
59
|
+
for (const index of pinned) if (Number.isInteger(index) && index >= 0 && index < count) indexes.add(index);
|
|
60
|
+
const stuck = activeSticky(sticky, visibleStart);
|
|
61
|
+
if (stuck !== void 0) indexes.add(stuck);
|
|
62
|
+
const rows = [];
|
|
63
|
+
let end;
|
|
64
|
+
for (const index of [...indexes].sort((a, b) => a - b)) {
|
|
65
|
+
const start = starts[index];
|
|
66
|
+
const rowSize = size(index);
|
|
67
|
+
rows.push({
|
|
68
|
+
index,
|
|
69
|
+
start,
|
|
70
|
+
size: rowSize,
|
|
71
|
+
spaceBefore: Math.max(0, end === void 0 ? start : start - end - gap),
|
|
72
|
+
sticky: index === stuck
|
|
73
|
+
});
|
|
74
|
+
end = start + rowSize;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
rows,
|
|
78
|
+
spaceAfter: Math.max(0, totalSize - (end ?? 0)),
|
|
79
|
+
totalSize,
|
|
80
|
+
visibleStart,
|
|
81
|
+
visibleEnd
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The row a page away from `from` (PageDown `1`, PageUp `-1`): the farthest row whose far edge is
|
|
86
|
+
* within `viewport` of `from`'s near edge; the last (first) row when the whole list fits. As
|
|
87
|
+
* `/selection`'s `pageTarget`, computed on the sizes instead of the elements, so it reaches rows
|
|
88
|
+
* that are not rendered.
|
|
89
|
+
*/
|
|
90
|
+
function pageIndex(starts, size, from, delta, viewport) {
|
|
91
|
+
const count = starts.length - 1;
|
|
92
|
+
const last = count - 1;
|
|
93
|
+
if (count <= 0) return -1;
|
|
94
|
+
const edge = delta === 1 ? last : 0;
|
|
95
|
+
if (starts[count] <= viewport || viewport <= 0) return edge;
|
|
96
|
+
const current = Math.min(Math.max(from, 0), last);
|
|
97
|
+
const origin = delta === 1 ? starts[current] : starts[current] + size(current);
|
|
98
|
+
let target = current;
|
|
99
|
+
for (let index = current + delta; index >= 0 && index <= last; index += delta) {
|
|
100
|
+
const far = delta === 1 ? starts[index] + size(index) : starts[index];
|
|
101
|
+
if (Math.abs(far - origin) > viewport) break;
|
|
102
|
+
target = index;
|
|
103
|
+
}
|
|
104
|
+
return target === current ? Math.min(Math.max(current + delta, 0), last) : target;
|
|
105
|
+
}
|
|
106
|
+
// src/virtual/virtualizer.ts
|
|
107
|
+
/**
|
|
108
|
+
* The scroll container of a list: the list itself when it scrolls, else its nearest ancestor
|
|
109
|
+
* whose `overflow-y` scrolls; the list when none does.
|
|
110
|
+
*/
|
|
111
|
+
function scrollContainer(list) {
|
|
112
|
+
const view = list.ownerDocument.defaultView;
|
|
113
|
+
for (let element = list; element !== null; element = element.parentElement) {
|
|
114
|
+
const overflow = view?.getComputedStyle(element).overflowY ?? "";
|
|
115
|
+
if (overflow === "auto" || overflow === "scroll" || overflow === "overlay") return element;
|
|
116
|
+
}
|
|
117
|
+
return list;
|
|
118
|
+
}
|
|
119
|
+
function pixels(value) {
|
|
120
|
+
const number = Number.parseFloat(value);
|
|
121
|
+
return Number.isFinite(number) ? number : 0;
|
|
122
|
+
}
|
|
123
|
+
/** Same rows and same room: nothing to render again. */
|
|
124
|
+
function sameRange(a, b) {
|
|
125
|
+
if (a === null || a.rows.length !== b.rows.length || Math.round(a.spaceAfter) !== Math.round(b.spaceAfter)) return false;
|
|
126
|
+
return a.rows.every((row, index) => {
|
|
127
|
+
const other = b.rows[index];
|
|
128
|
+
return other !== void 0 && row.index === other.index && row.sticky === other.sticky && Math.round(row.spaceBefore) === Math.round(other.spaceBefore);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/** Creates a virtualizer (`Virtualizer`); it reads the DOM only once attached. */
|
|
132
|
+
function createVirtualizer(initial) {
|
|
133
|
+
let options = { ...initial };
|
|
134
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
135
|
+
let starts = null;
|
|
136
|
+
let list = null;
|
|
137
|
+
let scroller = null;
|
|
138
|
+
let offset = 0;
|
|
139
|
+
let viewport = null;
|
|
140
|
+
let gap = 0;
|
|
141
|
+
let current = null;
|
|
142
|
+
let emitted = null;
|
|
143
|
+
let observer = null;
|
|
144
|
+
const observed = /* @__PURE__ */ new Map();
|
|
145
|
+
const estimate = (index) => {
|
|
146
|
+
const { estimateSize = 36 } = options;
|
|
147
|
+
return typeof estimateSize === "number" ? estimateSize : estimateSize(index);
|
|
148
|
+
};
|
|
149
|
+
const size = (index) => sizes.get(index) ?? estimate(index);
|
|
150
|
+
const startsOf = () => {
|
|
151
|
+
if (starts === null || starts.length !== options.count + 1) starts = rowStarts(options.count, size, gap);
|
|
152
|
+
return starts;
|
|
153
|
+
};
|
|
154
|
+
const visible = () => viewport ?? options.initialViewport ?? 0;
|
|
155
|
+
const range = () => {
|
|
156
|
+
if (current === null) current = virtualLayout({
|
|
157
|
+
count: options.count,
|
|
158
|
+
size,
|
|
159
|
+
gap,
|
|
160
|
+
offset,
|
|
161
|
+
viewport: visible(),
|
|
162
|
+
overscan: options.overscan,
|
|
163
|
+
pinned: options.pinned,
|
|
164
|
+
sticky: options.sticky
|
|
165
|
+
}, startsOf());
|
|
166
|
+
return current;
|
|
167
|
+
};
|
|
168
|
+
/** The range changed: tell the framework, once per change. */
|
|
169
|
+
const notify = () => {
|
|
170
|
+
current = null;
|
|
171
|
+
const next = range();
|
|
172
|
+
if (sameRange(emitted, next)) return;
|
|
173
|
+
emitted = next;
|
|
174
|
+
options.onChange?.();
|
|
175
|
+
};
|
|
176
|
+
/** Where the list's first row sits in the scroll container's content. */
|
|
177
|
+
const listTop = () => {
|
|
178
|
+
if (list === null || scroller === null) return 0;
|
|
179
|
+
const style = list.ownerDocument.defaultView?.getComputedStyle(list);
|
|
180
|
+
const padding = pixels(style?.paddingTop ?? "");
|
|
181
|
+
if (list === scroller) return padding;
|
|
182
|
+
const box = list.getBoundingClientRect();
|
|
183
|
+
const container = scroller.getBoundingClientRect();
|
|
184
|
+
return box.top - container.top - scroller.clientTop + scroller.scrollTop + list.clientTop + padding;
|
|
185
|
+
};
|
|
186
|
+
/** Reads the scroll position, the visible size and the gap. */
|
|
187
|
+
const read = () => {
|
|
188
|
+
if (list === null || scroller === null) return;
|
|
189
|
+
offset = scroller.scrollTop - listTop();
|
|
190
|
+
viewport = scroller.clientHeight;
|
|
191
|
+
const style = list.ownerDocument.defaultView?.getComputedStyle(list);
|
|
192
|
+
const nextGap = pixels(style?.rowGap ?? "");
|
|
193
|
+
if (nextGap !== gap) {
|
|
194
|
+
gap = nextGap;
|
|
195
|
+
starts = null;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* A row's measured size. A row above the view that changes size moves the scroll position by
|
|
200
|
+
* the change, so the rows in view stay still (the scroll anchoring the rows opt out of: the
|
|
201
|
+
* browser's would also follow the rows the virtualizer adds and removes).
|
|
202
|
+
*/
|
|
203
|
+
const setSize = (index, next) => {
|
|
204
|
+
const previous = size(index);
|
|
205
|
+
if (next <= 0 || sizes.get(index) === next) return false;
|
|
206
|
+
const above = scroller !== null && startsOf()[index] + previous <= offset;
|
|
207
|
+
sizes.set(index, next);
|
|
208
|
+
starts = null;
|
|
209
|
+
if (above && scroller !== null && next !== previous) {
|
|
210
|
+
scroller.scrollTop += next - previous;
|
|
211
|
+
offset += next - previous;
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
update(next) {
|
|
217
|
+
const countChanged = next.count !== void 0 && next.count !== options.count || "estimateSize" in next && next.estimateSize !== options.estimateSize;
|
|
218
|
+
options = {
|
|
219
|
+
...options,
|
|
220
|
+
...next
|
|
221
|
+
};
|
|
222
|
+
if (countChanged) starts = null;
|
|
223
|
+
current = null;
|
|
224
|
+
emitted = range();
|
|
225
|
+
},
|
|
226
|
+
range,
|
|
227
|
+
attach(element, container) {
|
|
228
|
+
list = element;
|
|
229
|
+
scroller = container ?? scrollContainer(element);
|
|
230
|
+
const view = element.ownerDocument.defaultView;
|
|
231
|
+
const onScroll = () => {
|
|
232
|
+
read();
|
|
233
|
+
notify();
|
|
234
|
+
};
|
|
235
|
+
scroller.addEventListener("scroll", onScroll, { passive: true });
|
|
236
|
+
const Observer = view?.ResizeObserver;
|
|
237
|
+
observer = Observer === void 0 ? null : new Observer((entries) => {
|
|
238
|
+
let changed = false;
|
|
239
|
+
for (const entry of entries) {
|
|
240
|
+
const index = observed.get(entry.target);
|
|
241
|
+
if (index === void 0) continue;
|
|
242
|
+
const box = entry.borderBoxSize?.[0];
|
|
243
|
+
changed = setSize(index, box === void 0 ? entry.target.offsetHeight : box.blockSize) || changed;
|
|
244
|
+
}
|
|
245
|
+
read();
|
|
246
|
+
if (changed || entries.length > 0) notify();
|
|
247
|
+
});
|
|
248
|
+
observer?.observe(scroller);
|
|
249
|
+
if (element !== scroller) observer?.observe(element);
|
|
250
|
+
for (const target of observed.keys()) observer?.observe(target);
|
|
251
|
+
read();
|
|
252
|
+
notify();
|
|
253
|
+
const attached = scroller;
|
|
254
|
+
return () => {
|
|
255
|
+
attached.removeEventListener("scroll", onScroll);
|
|
256
|
+
observer?.disconnect();
|
|
257
|
+
observer = null;
|
|
258
|
+
list = null;
|
|
259
|
+
scroller = null;
|
|
260
|
+
viewport = null;
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
measure(index, element) {
|
|
264
|
+
observed.set(element, index);
|
|
265
|
+
observer?.observe(element);
|
|
266
|
+
if (list !== null && !sizes.has(index)) {
|
|
267
|
+
if (setSize(index, element.offsetHeight)) notify();
|
|
268
|
+
}
|
|
269
|
+
return () => {
|
|
270
|
+
if (observed.get(element) === index) {
|
|
271
|
+
observed.delete(element);
|
|
272
|
+
observer?.unobserve(element);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
scrollToIndex(index, align = "auto") {
|
|
277
|
+
if (index < 0 || index >= options.count) return;
|
|
278
|
+
if (scroller === null) {
|
|
279
|
+
offset = startsOf()[index];
|
|
280
|
+
notify();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
read();
|
|
284
|
+
const rowStart = startsOf()[index];
|
|
285
|
+
const rowEnd = rowStart + size(index);
|
|
286
|
+
const top = listTop();
|
|
287
|
+
const height = scroller.clientHeight;
|
|
288
|
+
let target;
|
|
289
|
+
if (align === "start") target = rowStart;
|
|
290
|
+
else if (align === "end") target = rowEnd - height;
|
|
291
|
+
else if (align === "center") target = (rowStart + rowEnd - height) / 2;
|
|
292
|
+
else if (rowStart < offset) target = rowStart;
|
|
293
|
+
else if (rowEnd > offset + height) target = rowEnd - height;
|
|
294
|
+
if (target !== void 0) scroller.scrollTop = Math.max(0, target + top);
|
|
295
|
+
read();
|
|
296
|
+
if (target !== void 0 && target > 0 && scroller.scrollTop === 0) offset = target;
|
|
297
|
+
notify();
|
|
298
|
+
},
|
|
299
|
+
pageIndex(from, delta) {
|
|
300
|
+
return pageIndex(startsOf(), size, from, delta, visible());
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
export { rowAt as a, pageIndex as i, scrollContainer as n, rowStarts as o, activeSticky as r, virtualLayout as s, createVirtualizer as t };
|
|
305
|
+
|
|
306
|
+
//# sourceMappingURL=virtual-BlX1RuHD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-BlX1RuHD.js","names":[],"sources":["../src/virtual/virtual-layout.ts","../src/virtual/virtualizer.ts"],"sourcesContent":["/** A rendered row of a virtual list: its index, where it starts, its size and the room before it. */\nexport interface VirtualRow {\n index: number;\n /** Its offset from the list's first row (the sizes and gaps of every row before it). */\n start: number;\n size: number;\n /**\n * The room between the previous rendered row (or the list's start) and this row that no\n * rendered row fills: the unrendered rows and their gaps. The framework gives it to the row as\n * its `margin-block-start`; the layout's own gap between two rendered rows is not part of it.\n */\n spaceBefore: number;\n /** The group label that sticks to the top of the scroll container (`position: sticky`). */\n sticky: boolean;\n}\n\n/** What a virtual list renders: its rows, in order, and the room after the last one. */\nexport interface VirtualRange {\n rows: readonly VirtualRow[];\n /** The room after the last rendered row: its `margin-block-end`. */\n spaceAfter: number;\n /** The size of every row and gap: the list's full extent. */\n totalSize: number;\n /** The first row in view (the overscan excluded), `-1` when the list is empty. */\n visibleStart: number;\n /** The last row in view (the overscan excluded), `-1` when the list is empty. */\n visibleEnd: number;\n}\n\nexport interface VirtualLayoutOptions {\n count: number;\n /** A row's size: measured, else estimated. */\n size: (index: number) => number;\n /** The layout's gap between two rows (a flex or grid `row-gap`). */\n gap?: number;\n /** How far the list is scrolled, from its first row. */\n offset: number;\n /** The scroll container's visible size. */\n viewport: number;\n /** The rows rendered beyond each end of the view (default 4). */\n overscan?: number;\n /** Rows always rendered: the focused or highlighted one, the selected one, the ends. */\n pinned?: readonly number[];\n /** The rows that stick while their group is in view (group labels), in order. */\n sticky?: readonly number[];\n}\n\n/**\n * Where every row starts: `starts[i]` is row `i`'s offset, `starts[count]` the list's extent. A\n * gap separates two rows (none after the last).\n */\nexport function rowStarts(\n count: number,\n size: (index: number) => number,\n gap = 0,\n): Float64Array {\n const starts = new Float64Array(count + 1);\n for (let index = 0; index < count; index += 1) {\n starts[index + 1] =\n (starts[index] as number) +\n size(index) +\n (index < count - 1 ? gap : 0);\n }\n return starts;\n}\n\n/** The row at `offset`: the last one starting at or before it (clamped to the list). */\nexport function rowAt(starts: Float64Array, offset: number): number {\n const count = starts.length - 1;\n if (count <= 0) {\n return -1;\n }\n let low = 0;\n let high = count - 1;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if ((starts[middle] as number) <= offset) {\n low = middle;\n } else {\n high = middle - 1;\n }\n }\n return low;\n}\n\n/** The sticky row of the group in view: the last sticky row at or before `first`. */\nexport function activeSticky(\n sticky: readonly number[],\n first: number,\n): number | undefined {\n let active: number | undefined;\n for (const index of sticky) {\n if (index > first) {\n break;\n }\n active = index;\n }\n return active;\n}\n\nconst EMPTY: VirtualRange = {\n rows: [],\n spaceAfter: 0,\n totalSize: 0,\n visibleStart: -1,\n visibleEnd: -1,\n};\n\n/**\n * The rows a virtual list renders for a scroll position (spec/README.md, \"Virtual lists\"): the\n * rows in view, `overscan` rows beyond each end, the pinned rows and the sticky row of the group\n * in view, each with the room before it. Pure: the framework renders the rows, the virtualizer\n * reads the DOM.\n */\nexport function virtualLayout(\n options: VirtualLayoutOptions,\n starts: Float64Array = rowStarts(\n options.count,\n options.size,\n options.gap ?? 0,\n ),\n): VirtualRange {\n const {\n count,\n size,\n gap = 0,\n overscan = 4,\n pinned = [],\n sticky = [],\n } = options;\n if (count <= 0) {\n return EMPTY;\n }\n const totalSize = starts[count] as number;\n const top = Math.min(Math.max(options.offset, 0), totalSize);\n const bottom = top + Math.max(options.viewport, 0);\n const visibleStart = rowAt(starts, top);\n // the last row that starts before the view's far edge\n let visibleEnd = rowAt(starts, bottom);\n if (visibleEnd > visibleStart && (starts[visibleEnd] as number) >= bottom) {\n visibleEnd -= 1;\n }\n const indexes = new Set<number>();\n const from = Math.max(0, visibleStart - overscan);\n const to = Math.min(count - 1, visibleEnd + overscan);\n for (let index = from; index <= to; index += 1) {\n indexes.add(index);\n }\n for (const index of pinned) {\n if (Number.isInteger(index) && index >= 0 && index < count) {\n indexes.add(index);\n }\n }\n const stuck = activeSticky(sticky, visibleStart);\n if (stuck !== undefined) {\n indexes.add(stuck);\n }\n const rows: VirtualRow[] = [];\n let end: number | undefined;\n for (const index of [...indexes].sort((a, b) => a - b)) {\n const start = starts[index] as number;\n const rowSize = size(index);\n rows.push({\n index,\n start,\n size: rowSize,\n spaceBefore: Math.max(\n 0,\n end === undefined ? start : start - end - gap,\n ),\n sticky: index === stuck,\n });\n end = start + rowSize;\n }\n return {\n rows,\n spaceAfter: Math.max(0, totalSize - (end ?? 0)),\n totalSize,\n visibleStart,\n visibleEnd,\n };\n}\n\n/**\n * The row a page away from `from` (PageDown `1`, PageUp `-1`): the farthest row whose far edge is\n * within `viewport` of `from`'s near edge; the last (first) row when the whole list fits. As\n * `/selection`'s `pageTarget`, computed on the sizes instead of the elements, so it reaches rows\n * that are not rendered.\n */\nexport function pageIndex(\n starts: Float64Array,\n size: (index: number) => number,\n from: number,\n delta: 1 | -1,\n viewport: number,\n): number {\n const count = starts.length - 1;\n const last = count - 1;\n if (count <= 0) {\n return -1;\n }\n const edge = delta === 1 ? last : 0;\n if ((starts[count] as number) <= viewport || viewport <= 0) {\n return edge;\n }\n const current = Math.min(Math.max(from, 0), last);\n const origin =\n delta === 1\n ? (starts[current] as number)\n : (starts[current] as number) + size(current);\n let target = current;\n for (\n let index = current + delta;\n index >= 0 && index <= last;\n index += delta\n ) {\n const far =\n delta === 1\n ? (starts[index] as number) + size(index)\n : (starts[index] as number);\n if (Math.abs(far - origin) > viewport) {\n break;\n }\n target = index;\n }\n return target === current\n ? Math.min(Math.max(current + delta, 0), last)\n : target;\n}\n","import {\n pageIndex,\n rowStarts,\n type VirtualRange,\n virtualLayout,\n} from \"./virtual-layout.ts\";\n\n/** Where `scrollToIndex` puts the row: `auto` scrolls the least to bring it into view. */\nexport type VirtualAlign = \"auto\" | \"start\" | \"center\" | \"end\";\n\nexport interface VirtualizerOptions {\n /** How many rows the list has. */\n count: number;\n /**\n * A row's size before it is measured, or every row's size when the rows are not measured\n * (fixed sizes): a number, or a function of the index (default 36).\n */\n estimateSize?: number | ((index: number) => number);\n /** The rows rendered beyond each end of the view (default 4). */\n overscan?: number;\n /** Rows always rendered (the focused, highlighted or selected one; the ends). */\n pinned?: readonly number[];\n /** The rows that stick while their group is in view (group labels), in order. */\n sticky?: readonly number[];\n /**\n * The visible size assumed before the scroll container is attached (a server render, the\n * first client render): default 0, so only the overscan rows render until then.\n */\n initialViewport?: number;\n /** The rendered rows changed: render the list again and read `range()`. */\n onChange?: () => void;\n}\n\n/**\n * A virtual list's mechanism (spec/README.md, \"Virtual lists\"): the rows to render for the\n * scroll position, their measured sizes and the scrolling to a row. It holds no component state\n * (rule 2): the framework keeps the items, the focus and the highlight, renders the rows of\n * `range()` and gives each its `spaceBefore` as `margin-block-start` (the last one\n * `spaceAfter` as `margin-block-end`), `flex-shrink: 0` and `overflow-anchor: none` (the\n * virtualizer keeps the view still itself), so the list keeps its flow layout (sticky labels,\n * flex gaps) with no extra element.\n */\nexport interface Virtualizer {\n /** New options (the count, the pinned rows, ...); the next `range()` follows them. */\n update(options: Partial<VirtualizerOptions>): void;\n /** The rows to render now. */\n range(): VirtualRange;\n /**\n * Watches the list's scroll container (`scroller`, default the list or its nearest\n * scrollable ancestor) and its size; returns the cleanup.\n */\n attach(list: HTMLElement, scroller?: HTMLElement | null): () => void;\n /** Measures a rendered row now and whenever its size changes; returns the cleanup. */\n measure(index: number, element: HTMLElement): () => void;\n /** Scrolls the container so the row is in view, and updates the range at once. */\n scrollToIndex(index: number, align?: VirtualAlign): void;\n /** The row a page away (PageDown `1`, PageUp `-1`), by the sizes and the visible size. */\n pageIndex(from: number, delta: 1 | -1): number;\n}\n\n/**\n * The scroll container of a list: the list itself when it scrolls, else its nearest ancestor\n * whose `overflow-y` scrolls; the list when none does.\n */\nexport function scrollContainer(list: HTMLElement): HTMLElement {\n const view = list.ownerDocument.defaultView;\n for (\n let element: HTMLElement | null = list;\n element !== null;\n element = element.parentElement\n ) {\n const overflow = view?.getComputedStyle(element).overflowY ?? \"\";\n if (\n overflow === \"auto\" ||\n overflow === \"scroll\" ||\n overflow === \"overlay\"\n ) {\n return element;\n }\n }\n return list;\n}\n\nfunction pixels(value: string): number {\n const number = Number.parseFloat(value);\n return Number.isFinite(number) ? number : 0;\n}\n\n/** Same rows and same room: nothing to render again. */\nfunction sameRange(a: VirtualRange | null, b: VirtualRange): boolean {\n if (\n a === null ||\n a.rows.length !== b.rows.length ||\n Math.round(a.spaceAfter) !== Math.round(b.spaceAfter)\n ) {\n return false;\n }\n return a.rows.every((row, index) => {\n const other = b.rows[index];\n return (\n other !== undefined &&\n row.index === other.index &&\n row.sticky === other.sticky &&\n Math.round(row.spaceBefore) === Math.round(other.spaceBefore)\n );\n });\n}\n\n/** Creates a virtualizer (`Virtualizer`); it reads the DOM only once attached. */\nexport function createVirtualizer(initial: VirtualizerOptions): Virtualizer {\n let options: VirtualizerOptions = { ...initial };\n const sizes = new Map<number, number>();\n let starts: Float64Array | null = null;\n let list: HTMLElement | null = null;\n let scroller: HTMLElement | null = null;\n let offset = 0;\n let viewport: number | null = null;\n let gap = 0;\n let current: VirtualRange | null = null;\n let emitted: VirtualRange | null = null;\n let observer: ResizeObserver | null = null;\n const observed = new Map<Element, number>();\n\n const estimate = (index: number): number => {\n const { estimateSize = 36 } = options;\n return typeof estimateSize === \"number\"\n ? estimateSize\n : estimateSize(index);\n };\n const size = (index: number): number => sizes.get(index) ?? estimate(index);\n const startsOf = (): Float64Array => {\n if (starts === null || starts.length !== options.count + 1) {\n starts = rowStarts(options.count, size, gap);\n }\n return starts;\n };\n const visible = () => viewport ?? options.initialViewport ?? 0;\n\n const range = (): VirtualRange => {\n if (current === null) {\n current = virtualLayout(\n {\n count: options.count,\n size,\n gap,\n offset,\n viewport: visible(),\n overscan: options.overscan,\n pinned: options.pinned,\n sticky: options.sticky,\n },\n startsOf(),\n );\n }\n return current;\n };\n /** The range changed: tell the framework, once per change. */\n const notify = () => {\n current = null;\n const next = range();\n if (sameRange(emitted, next)) {\n return;\n }\n emitted = next;\n options.onChange?.();\n };\n\n /** Where the list's first row sits in the scroll container's content. */\n const listTop = (): number => {\n if (list === null || scroller === null) {\n return 0;\n }\n const style = list.ownerDocument.defaultView?.getComputedStyle(list);\n const padding = pixels(style?.paddingTop ?? \"\");\n if (list === scroller) {\n return padding;\n }\n const box = list.getBoundingClientRect();\n const container = scroller.getBoundingClientRect();\n return (\n box.top -\n container.top -\n scroller.clientTop +\n scroller.scrollTop +\n list.clientTop +\n padding\n );\n };\n /** Reads the scroll position, the visible size and the gap. */\n const read = () => {\n if (list === null || scroller === null) {\n return;\n }\n offset = scroller.scrollTop - listTop();\n viewport = scroller.clientHeight;\n const style = list.ownerDocument.defaultView?.getComputedStyle(list);\n const nextGap = pixels(style?.rowGap ?? \"\");\n if (nextGap !== gap) {\n gap = nextGap;\n starts = null;\n }\n };\n /**\n * A row's measured size. A row above the view that changes size moves the scroll position by\n * the change, so the rows in view stay still (the scroll anchoring the rows opt out of: the\n * browser's would also follow the rows the virtualizer adds and removes).\n */\n const setSize = (index: number, next: number): boolean => {\n const previous = size(index);\n if (next <= 0 || sizes.get(index) === next) {\n return false;\n }\n const above =\n scroller !== null &&\n (startsOf()[index] as number) + previous <= offset;\n sizes.set(index, next);\n starts = null;\n if (above && scroller !== null && next !== previous) {\n scroller.scrollTop += next - previous;\n offset += next - previous;\n }\n return true;\n };\n\n return {\n update(next) {\n const countChanged =\n (next.count !== undefined && next.count !== options.count) ||\n (\"estimateSize\" in next &&\n next.estimateSize !== options.estimateSize);\n options = { ...options, ...next };\n if (countChanged) {\n starts = null;\n }\n current = null;\n // the framework renders after an update: what it renders is what was emitted\n emitted = range();\n },\n range,\n attach(element, container) {\n list = element;\n scroller = container ?? scrollContainer(element);\n const view = element.ownerDocument.defaultView;\n const onScroll = () => {\n read();\n notify();\n };\n scroller.addEventListener(\"scroll\", onScroll, { passive: true });\n const Observer = view?.ResizeObserver;\n observer =\n Observer === undefined\n ? null\n : new Observer((entries) => {\n let changed = false;\n for (const entry of entries) {\n const index = observed.get(entry.target);\n if (index === undefined) {\n continue;\n }\n const box = entry.borderBoxSize?.[0];\n changed =\n setSize(\n index,\n box === undefined\n ? (entry.target as HTMLElement)\n .offsetHeight\n : box.blockSize,\n ) || changed;\n }\n read();\n if (changed || entries.length > 0) {\n notify();\n }\n });\n observer?.observe(scroller);\n if (element !== scroller) {\n observer?.observe(element);\n }\n for (const target of observed.keys()) {\n observer?.observe(target);\n }\n read();\n notify();\n const attached = scroller;\n return () => {\n attached.removeEventListener(\"scroll\", onScroll);\n observer?.disconnect();\n observer = null;\n list = null;\n scroller = null;\n viewport = null;\n };\n },\n measure(index, element) {\n observed.set(element, index);\n observer?.observe(element);\n if (list !== null && !sizes.has(index)) {\n // a row measured as it renders: the list renders again with its real size, its\n // layout size (a popup's opening scale transforms its box, never its size)\n if (setSize(index, element.offsetHeight)) {\n notify();\n }\n }\n return () => {\n if (observed.get(element) === index) {\n observed.delete(element);\n observer?.unobserve(element);\n }\n };\n },\n scrollToIndex(index, align = \"auto\") {\n if (index < 0 || index >= options.count) {\n return;\n }\n if (scroller === null) {\n // before attach: the range starts at the row\n offset = startsOf()[index] as number;\n notify();\n return;\n }\n read();\n const rowStart = startsOf()[index] as number;\n const rowEnd = rowStart + size(index);\n const top = listTop();\n const height = scroller.clientHeight;\n let target: number | undefined;\n if (align === \"start\") {\n target = rowStart;\n } else if (align === \"end\") {\n target = rowEnd - height;\n } else if (align === \"center\") {\n target = (rowStart + rowEnd - height) / 2;\n } else if (rowStart < offset) {\n target = rowStart;\n } else if (rowEnd > offset + height) {\n target = rowEnd - height;\n }\n if (target !== undefined) {\n scroller.scrollTop = Math.max(0, target + top);\n }\n read();\n // the row is in the range at once, before the scroll event (a key that moves the\n // focus renders the row within the event); a container that cannot scroll (no layout)\n // keeps the asked offset\n if (\n target !== undefined &&\n target > 0 &&\n scroller.scrollTop === 0\n ) {\n offset = target;\n }\n notify();\n },\n pageIndex(from, delta) {\n return pageIndex(startsOf(), size, from, delta, visible());\n },\n };\n}\n"],"mappings":";;;;;AAmDA,SAAgB,UACZ,OACA,MACA,MAAM,GACM;CACZ,MAAM,SAAS,IAAI,aAAa,QAAQ,CAAC;CACzC,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,SAAS,GACxC,OAAO,QAAQ,KACV,OAAO,SACR,KAAK,KAAK,KACT,QAAQ,QAAQ,IAAI,MAAM;CAEnC,OAAO;AACX;;AAGA,SAAgB,MAAM,QAAsB,QAAwB;CAChE,MAAM,QAAQ,OAAO,SAAS;CAC9B,IAAI,SAAS,GACT,OAAO;CAEX,IAAI,MAAM;CACV,IAAI,OAAO,QAAQ;CACnB,OAAO,MAAM,MAAM;EACf,MAAM,SAAU,MAAM,OAAO,KAAM;EACnC,IAAK,OAAO,WAAsB,QAC9B,MAAM;OAEN,OAAO,SAAS;CAExB;CACA,OAAO;AACX;;AAGA,SAAgB,aACZ,QACA,OACkB;CAClB,IAAI;CACJ,KAAK,MAAM,SAAS,QAAQ;EACxB,IAAI,QAAQ,OACR;EAEJ,SAAS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IAC/B;GACJ;EACJ;EACA,cAAc,OAAO,QAAQ,QAAQ;GACjC,IAAI,QAAQ,KAAK,SAAS,QAAQ,OAC9B;GAEJ,IAAI,aAAa,MAAM;IAEnB,SAAS,SAAS,CAAC,CAAC;IACpB,OAAO;IACP;GACJ;GACA,KAAK;GACL,MAAM,WAAW,SAAS,CAAC,CAAC;GAC5B,MAAM,SAAS,WAAW,KAAK,KAAK;GACpC,MAAM,MAAM,QAAQ;GACpB,MAAM,SAAS,SAAS;GACxB,IAAI;GACJ,IAAI,UAAU,SACV,SAAS;QACN,IAAI,UAAU,OACjB,SAAS,SAAS;QACf,IAAI,UAAU,UACjB,UAAU,WAAW,SAAS,UAAU;QACrC,IAAI,WAAW,QAClB,SAAS;QACN,IAAI,SAAS,SAAS,QACzB,SAAS,SAAS;GAEtB,IAAI,WAAW,KAAA,GACX,SAAS,YAAY,KAAK,IAAI,GAAG,SAAS,GAAG;GAEjD,KAAK;GAIL,IACI,WAAW,KAAA,KACX,SAAS,KACT,SAAS,cAAc,GAEvB,SAAS;GAEb,OAAO;EACX;EACA,UAAU,MAAM,OAAO;GACnB,OAAO,UAAU,SAAS,GAAG,MAAM,MAAM,OAAO,QAAQ,CAAC;EAC7D;CACJ;AACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as scrollContainer, c as VirtualRow, d as rowAt, f as rowStarts, i as createVirtualizer, l as activeSticky, n as Virtualizer, o as VirtualLayoutOptions, p as virtualLayout, r as VirtualizerOptions, s as VirtualRange, t as VirtualAlign, u as pageIndex } from "./index-BjE8nDiX.js";
|
|
2
|
+
export { type VirtualAlign, type VirtualLayoutOptions, type VirtualRange, type VirtualRow, type Virtualizer, type VirtualizerOptions, activeSticky, createVirtualizer, pageIndex, rowAt, rowStarts, scrollContainer, virtualLayout };
|
package/dist/virtual.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { r as activeSticky, t as createVirtualizer, i as pageIndex, a as rowAt, o as rowStarts, n as scrollContainer, s as virtualLayout } from "./virtual-BlX1RuHD.js";
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
const SWIPE_FLICK_VELOCITY = .5;
|
|
2
|
+
/** A release at this velocity or faster moves the snap target by velocity × this (px). */
|
|
3
|
+
const SNAP_VELOCITY_PROJECTION = 300;
|
|
4
|
+
const SNAP_MAX_VELOCITY = 4;
|
|
5
|
+
function clamp(value, min, max) {
|
|
6
|
+
return Math.min(max, Math.max(min, value));
|
|
7
|
+
}
|
|
8
|
+
/** The px height of a snap point in a viewport of `viewportHeight`, or `null` when invalid. */
|
|
9
|
+
function snapPointHeight(point, viewportHeight, rootFontSize) {
|
|
10
|
+
if (typeof point === "number") {
|
|
11
|
+
if (!Number.isFinite(point) || point < 0) return null;
|
|
12
|
+
return point <= 1 ? point * viewportHeight : point;
|
|
13
|
+
}
|
|
14
|
+
const text = point.trim();
|
|
15
|
+
const value = Number.parseFloat(text);
|
|
16
|
+
if (!Number.isFinite(value)) return null;
|
|
17
|
+
if (text.endsWith("rem")) return value * rootFontSize;
|
|
18
|
+
return text.endsWith("px") ? value : null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Measures `points` for a popup of `popupHeight` in a viewport of `viewportHeight` (spec/drawer.md,
|
|
22
|
+
* "Snap points"): each one's height (clamped to the popup and the viewport) and offset. Invalid
|
|
23
|
+
* points are left out; two points within 1 px of each other count once (the earlier one).
|
|
24
|
+
*/
|
|
25
|
+
function resolveSnapPoints(points, sizes) {
|
|
26
|
+
const { popupHeight, viewportHeight, rootFontSize = 16 } = sizes;
|
|
27
|
+
if (popupHeight <= 0 || viewportHeight <= 0) return [];
|
|
28
|
+
const max = Math.min(popupHeight, viewportHeight);
|
|
29
|
+
const resolved = [];
|
|
30
|
+
for (const value of points) {
|
|
31
|
+
const height = snapPointHeight(value, viewportHeight, rootFontSize);
|
|
32
|
+
if (height === null) continue;
|
|
33
|
+
const clamped = clamp(height, 0, max);
|
|
34
|
+
if (resolved.some((point) => Math.abs(point.height - clamped) <= 1)) continue;
|
|
35
|
+
resolved.push({
|
|
36
|
+
value,
|
|
37
|
+
height: clamped,
|
|
38
|
+
offset: Math.max(0, popupHeight - clamped)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return resolved;
|
|
42
|
+
}
|
|
43
|
+
/** The movement of a swipe along `direction`: positive towards the edge it dismisses to. */
|
|
44
|
+
function swipeDisplacement(direction, movement) {
|
|
45
|
+
switch (direction) {
|
|
46
|
+
case "down": return movement.deltaY;
|
|
47
|
+
case "up": return -movement.deltaY;
|
|
48
|
+
case "right": return movement.deltaX;
|
|
49
|
+
case "left": return -movement.deltaX;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The movement to show while a swipe runs (spec/drawer.md, "Swipe"): along `direction` only, as
|
|
54
|
+
* far as the pointer went towards the edge, and damped (the square root) past the fully open
|
|
55
|
+
* position, where `baseOffset` (a snap point's offset) is `0`. Returns the x and y movement in px.
|
|
56
|
+
*/
|
|
57
|
+
function swipeMovement(direction, movement, baseOffset = 0) {
|
|
58
|
+
const along = swipeDisplacement(direction, movement);
|
|
59
|
+
const next = baseOffset + along;
|
|
60
|
+
const value = (next >= 0 ? along : -Math.sqrt(-next) - baseOffset) * (direction === "down" || direction === "right" ? 1 : -1);
|
|
61
|
+
return direction === "up" || direction === "down" ? {
|
|
62
|
+
x: 0,
|
|
63
|
+
y: value
|
|
64
|
+
} : {
|
|
65
|
+
x: value,
|
|
66
|
+
y: 0
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What a released swipe does (spec/drawer.md, "Swipe" and "Snap points"). Without snap points, it
|
|
71
|
+
* dismisses when it moved more than half the popup's `size` along `direction`, or at least 10 px
|
|
72
|
+
* at a flick's velocity (0.5 px per ms) towards the edge; otherwise it settles back. With snap
|
|
73
|
+
* points (the popup's `currentOffset` the active one's), the release's target is where it was let
|
|
74
|
+
* go plus, at a flick's velocity or faster, a projection of that velocity (velocity × 300 px, the
|
|
75
|
+
* velocity capped at 4); the closest of the snap points and the closed position (`size`) wins.
|
|
76
|
+
*/
|
|
77
|
+
function swipeRelease(direction, end, size, snap) {
|
|
78
|
+
const displacement = swipeDisplacement(direction, end);
|
|
79
|
+
const velocity = swipeDisplacement(direction, {
|
|
80
|
+
deltaX: end.velocityX,
|
|
81
|
+
deltaY: end.velocityY
|
|
82
|
+
});
|
|
83
|
+
if (snap === void 0 || snap.points.length === 0) {
|
|
84
|
+
if (displacement <= 0) return {
|
|
85
|
+
dismiss: false,
|
|
86
|
+
snapPoint: null
|
|
87
|
+
};
|
|
88
|
+
return velocity >= .5 && displacement >= 10 || displacement > Math.max(size * .5, 10) ? { dismiss: true } : {
|
|
89
|
+
dismiss: false,
|
|
90
|
+
snapPoint: null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const projection = Math.abs(velocity) >= .5 ? clamp(velocity, -4, SNAP_MAX_VELOCITY) * SNAP_VELOCITY_PROJECTION : 0;
|
|
94
|
+
const target = clamp(snap.currentOffset + displacement + projection, 0, size);
|
|
95
|
+
let closest = 0;
|
|
96
|
+
snap.points.forEach((point, index) => {
|
|
97
|
+
const best = snap.points[closest];
|
|
98
|
+
if (Math.abs(point.offset - target) < Math.abs(best.offset - target)) closest = index;
|
|
99
|
+
});
|
|
100
|
+
const best = snap.points[closest];
|
|
101
|
+
if (Math.abs(size - target) < Math.abs(best.offset - target)) return { dismiss: true };
|
|
102
|
+
return {
|
|
103
|
+
dismiss: false,
|
|
104
|
+
snapPoint: closest
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* How far a running swipe has moved the popup towards its closed position, from `0` (where it
|
|
109
|
+
* was, or fully open) to `1` (closed), for a recipe's `--drawer-swipe-progress` (spec/drawer.md).
|
|
110
|
+
*/
|
|
111
|
+
function swipeProgress(direction, movement, size, baseOffset = 0) {
|
|
112
|
+
if (size <= 0) return 0;
|
|
113
|
+
return clamp((baseOffset + swipeDisplacement(direction, movement)) / size, 0, 1);
|
|
114
|
+
}
|
|
115
|
+
// src/swipe/watch-swipe.ts
|
|
116
|
+
/** The distance a pointer moves before a swipe locks on an axis (or lets it go), in px. */
|
|
117
|
+
const SWIPE_LOCK_DISTANCE = 6;
|
|
118
|
+
/** How far a touch moves along the swipe's axis before its page scroll is held back, in px. */
|
|
119
|
+
const TOUCH_CLAIM_DISTANCE = 2;
|
|
120
|
+
/** How far back the release velocity looks, in ms. */
|
|
121
|
+
const VELOCITY_WINDOW = 100;
|
|
122
|
+
/** A release this long after the last move is a release at rest (velocity 0), in ms. */
|
|
123
|
+
const RELEASE_REST = 80;
|
|
124
|
+
const TEXT_CONTROLS = "input:not([type=\"button\"],[type=\"checkbox\"],[type=\"radio\"],[type=\"submit\"],[type=\"reset\"]),textarea,select,[contenteditable]:not([contenteditable=\"false\"])";
|
|
125
|
+
const INTERACTIVE = "button,a[href],label,[role=\"button\"],summary";
|
|
126
|
+
function axisOf(directions) {
|
|
127
|
+
return directions.some((direction) => direction === "up" || direction === "down") ? "y" : "x";
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Whether an element between `target` and `root` would scroll for a pointer moving by `delta`
|
|
131
|
+
* along `axis`: a pointer moving down scrolls its content up (towards its start), so a scroller
|
|
132
|
+
* that is not at its start takes it; moving up, one not at its end (scroll containment: a drawer's
|
|
133
|
+
* content scrolls before the drawer moves).
|
|
134
|
+
*/
|
|
135
|
+
function scrollsFirst(target, root, axis, delta) {
|
|
136
|
+
const view = root.ownerDocument.defaultView;
|
|
137
|
+
for (let node = target; node !== null && node !== root.parentElement; node = node.parentElement) {
|
|
138
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
139
|
+
const overflow = view?.getComputedStyle(node)[axis === "y" ? "overflowY" : "overflowX"];
|
|
140
|
+
if (overflow !== "auto" && overflow !== "scroll") continue;
|
|
141
|
+
const position = axis === "y" ? node.scrollTop : Math.abs(node.scrollLeft);
|
|
142
|
+
const max = axis === "y" ? node.scrollHeight - node.clientHeight : node.scrollWidth - node.clientWidth;
|
|
143
|
+
if (max <= 0) continue;
|
|
144
|
+
if (delta > 0 ? position > 0 : position < max - 1) return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Watches `element` for swipes (spec/drawer.md, "Swipe"): a primary pointer goes down on it, and
|
|
150
|
+
* once it moved `SWIPE_LOCK_DISTANCE` px, the gesture locks on the swipe's axis (it becomes a
|
|
151
|
+
* swipe, with pointer capture) or is let go (the other axis, or a scroller under the pointer that
|
|
152
|
+
* takes the move: scroll containment). A touch's moves are kept from scrolling the page while they
|
|
153
|
+
* may be a swipe (a non-passive `touchmove`), so the browser does not cancel the pointer. It holds
|
|
154
|
+
* no state of the component: it reports the movement and the release velocity, and the framework
|
|
155
|
+
* decides what they mean (`swipeRelease`). Text selection is cleared and kept off while a swipe
|
|
156
|
+
* runs. Returns the cleanup, which cancels a running swipe.
|
|
157
|
+
*/
|
|
158
|
+
function watchSwipe(element, options) {
|
|
159
|
+
const doc = element.ownerDocument;
|
|
160
|
+
const view = doc.defaultView;
|
|
161
|
+
const axis = axisOf(options.directions);
|
|
162
|
+
let gesture = null;
|
|
163
|
+
const movement = (event) => ({
|
|
164
|
+
deltaX: gesture ? event.clientX - gesture.x : 0,
|
|
165
|
+
deltaY: gesture ? event.clientY - gesture.y : 0
|
|
166
|
+
});
|
|
167
|
+
const stopListening = () => {
|
|
168
|
+
view?.removeEventListener("pointermove", onMove);
|
|
169
|
+
view?.removeEventListener("pointerup", onUp);
|
|
170
|
+
view?.removeEventListener("pointercancel", onCancel);
|
|
171
|
+
element.removeEventListener("lostpointercapture", onLost);
|
|
172
|
+
};
|
|
173
|
+
const finish = (end, event) => {
|
|
174
|
+
const current = gesture;
|
|
175
|
+
gesture = null;
|
|
176
|
+
stopListening();
|
|
177
|
+
if (current === null || !current.started) return;
|
|
178
|
+
current.restoreSelect?.();
|
|
179
|
+
try {
|
|
180
|
+
if (element.hasPointerCapture(current.pointerId)) element.releasePointerCapture(current.pointerId);
|
|
181
|
+
} catch {}
|
|
182
|
+
options.onEnd(end, event);
|
|
183
|
+
};
|
|
184
|
+
const velocity = (samples, now) => {
|
|
185
|
+
const last = samples.at(-1);
|
|
186
|
+
if (last === void 0 || now - last.time > RELEASE_REST) return {
|
|
187
|
+
velocityX: 0,
|
|
188
|
+
velocityY: 0
|
|
189
|
+
};
|
|
190
|
+
const first = samples.find((sample) => last.time - sample.time <= VELOCITY_WINDOW) ?? last;
|
|
191
|
+
const elapsed = last.time - first.time;
|
|
192
|
+
if (elapsed <= 0) return {
|
|
193
|
+
velocityX: 0,
|
|
194
|
+
velocityY: 0
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
velocityX: (last.x - first.x) / elapsed,
|
|
198
|
+
velocityY: (last.y - first.y) / elapsed
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const onMove = (event) => {
|
|
202
|
+
if (gesture === null || event.pointerId !== gesture.pointerId) return;
|
|
203
|
+
const { deltaX, deltaY } = movement(event);
|
|
204
|
+
gesture.samples.push({
|
|
205
|
+
time: event.timeStamp,
|
|
206
|
+
x: event.clientX,
|
|
207
|
+
y: event.clientY
|
|
208
|
+
});
|
|
209
|
+
if (gesture.samples.length > 32) gesture.samples.shift();
|
|
210
|
+
if (!gesture.started) {
|
|
211
|
+
const along = axis === "y" ? deltaY : deltaX;
|
|
212
|
+
const across = axis === "y" ? deltaX : deltaY;
|
|
213
|
+
if (Math.max(Math.abs(along), Math.abs(across)) < 6) return;
|
|
214
|
+
if (Math.abs(across) > Math.abs(along) || scrollsFirst(gesture.target, element, axis, along)) {
|
|
215
|
+
gesture = null;
|
|
216
|
+
stopListening();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
gesture.started = true;
|
|
220
|
+
try {
|
|
221
|
+
element.setPointerCapture(event.pointerId);
|
|
222
|
+
} catch {}
|
|
223
|
+
doc.getSelection()?.removeAllRanges();
|
|
224
|
+
const style = doc.documentElement.style;
|
|
225
|
+
const previous = style.userSelect;
|
|
226
|
+
style.userSelect = "none";
|
|
227
|
+
gesture.restoreSelect = () => {
|
|
228
|
+
style.userSelect = previous;
|
|
229
|
+
};
|
|
230
|
+
options.onStart(event);
|
|
231
|
+
}
|
|
232
|
+
options.onMove({
|
|
233
|
+
deltaX,
|
|
234
|
+
deltaY
|
|
235
|
+
}, event);
|
|
236
|
+
};
|
|
237
|
+
const onUp = (event) => {
|
|
238
|
+
if (gesture === null || event.pointerId !== gesture.pointerId) return;
|
|
239
|
+
const end = {
|
|
240
|
+
...movement(event),
|
|
241
|
+
...velocity(gesture.samples, event.timeStamp)
|
|
242
|
+
};
|
|
243
|
+
finish(end, event);
|
|
244
|
+
};
|
|
245
|
+
const onCancel = (event) => {
|
|
246
|
+
if (gesture !== null && event.pointerId === gesture.pointerId) finish(null, event);
|
|
247
|
+
};
|
|
248
|
+
const onLost = (event) => {
|
|
249
|
+
if (event.target === element && gesture?.started) view?.setTimeout(() => {
|
|
250
|
+
if (gesture?.started) finish(null, event);
|
|
251
|
+
}, 0);
|
|
252
|
+
};
|
|
253
|
+
const onDown = (event) => {
|
|
254
|
+
if (gesture !== null || !event.isPrimary) return;
|
|
255
|
+
const target = event.target;
|
|
256
|
+
if (!(target instanceof Element) || !element.contains(target)) return;
|
|
257
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
258
|
+
if (target.closest("[data-swipe-ignore]") !== null || target.closest(TEXT_CONTROLS) !== null || target.closest("input[type=\"range\"]") !== null || event.pointerType === "mouse" && target.closest(INTERACTIVE) !== null) return;
|
|
259
|
+
if (options.canStart && !options.canStart(target, event)) return;
|
|
260
|
+
gesture = {
|
|
261
|
+
pointerId: event.pointerId,
|
|
262
|
+
pointerType: event.pointerType,
|
|
263
|
+
target,
|
|
264
|
+
x: event.clientX,
|
|
265
|
+
y: event.clientY,
|
|
266
|
+
started: false,
|
|
267
|
+
samples: [{
|
|
268
|
+
time: event.timeStamp,
|
|
269
|
+
x: event.clientX,
|
|
270
|
+
y: event.clientY
|
|
271
|
+
}],
|
|
272
|
+
restoreSelect: null
|
|
273
|
+
};
|
|
274
|
+
view?.addEventListener("pointermove", onMove);
|
|
275
|
+
view?.addEventListener("pointerup", onUp);
|
|
276
|
+
view?.addEventListener("pointercancel", onCancel);
|
|
277
|
+
element.addEventListener("lostpointercapture", onLost);
|
|
278
|
+
};
|
|
279
|
+
const onTouchMove = (event) => {
|
|
280
|
+
if (gesture === null || gesture.pointerType !== "touch" || !event.cancelable) return;
|
|
281
|
+
if (gesture.started) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const touch = event.touches[0];
|
|
286
|
+
if (touch === void 0) return;
|
|
287
|
+
const along = axis === "y" ? touch.clientY - gesture.y : touch.clientX - gesture.x;
|
|
288
|
+
const across = axis === "y" ? touch.clientX - gesture.x : touch.clientY - gesture.y;
|
|
289
|
+
if (Math.abs(along) >= TOUCH_CLAIM_DISTANCE && Math.abs(along) > Math.abs(across) && !scrollsFirst(gesture.target, element, axis, along)) event.preventDefault();
|
|
290
|
+
};
|
|
291
|
+
element.addEventListener("pointerdown", onDown);
|
|
292
|
+
element.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
293
|
+
return () => {
|
|
294
|
+
element.removeEventListener("pointerdown", onDown);
|
|
295
|
+
element.removeEventListener("touchmove", onTouchMove);
|
|
296
|
+
finish(null, null);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
export { swipeDisplacement as a, swipeRelease as c, resolveSnapPoints as i, watchSwipe as n, swipeMovement as o, SWIPE_FLICK_VELOCITY as r, swipeProgress as s, SWIPE_LOCK_DISTANCE as t };
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=watch-swipe-BIucfr9O.js.map
|