@fragiola/primitives 0.0.0-stage → 0.1.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/CHANGELOG.md +63 -0
- 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,62 @@
|
|
|
1
|
+
// src/hover/delay-group.ts
|
|
2
|
+
/**
|
|
3
|
+
* The coordination of a tooltip delay group (spec/tooltip.md, "Delay group"): at most one member
|
|
4
|
+
* open, and the instant hand-off. It knows the open member's close callback and the time of the
|
|
5
|
+
* last close, never a member's open state: each member keeps its own and reports here.
|
|
6
|
+
*
|
|
7
|
+
* `timeout` may be a getter, read at each check: a provider whose timeout changes keeps one group
|
|
8
|
+
* (and its open member) instead of making a new one.
|
|
9
|
+
*/
|
|
10
|
+
function createDelayGroup(options) {
|
|
11
|
+
const timeout = () => typeof options.timeout === "function" ? options.timeout() : options.timeout;
|
|
12
|
+
let current = null;
|
|
13
|
+
let lastClosed = Number.NEGATIVE_INFINITY;
|
|
14
|
+
return {
|
|
15
|
+
isInstant(now = Date.now()) {
|
|
16
|
+
return current !== null || now - lastClosed <= timeout();
|
|
17
|
+
},
|
|
18
|
+
opened(close) {
|
|
19
|
+
const previous = current;
|
|
20
|
+
current = close;
|
|
21
|
+
if (previous !== null && previous !== close) previous();
|
|
22
|
+
},
|
|
23
|
+
closed(close, now = Date.now()) {
|
|
24
|
+
if (current === close) current = null;
|
|
25
|
+
lastClosed = now;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// src/hover/hover-intent.ts
|
|
30
|
+
/**
|
|
31
|
+
* The timers of hover intent (spec/tooltip.md, "Pointer"): an open after a delay that a leave
|
|
32
|
+
* cancels, and a close after a delay that a return cancels. It holds no open state: `open` and
|
|
33
|
+
* `close` report to the framework, which decides.
|
|
34
|
+
*/
|
|
35
|
+
function createHoverIntent(callbacks) {
|
|
36
|
+
let timer;
|
|
37
|
+
const cancel = () => {
|
|
38
|
+
if (timer !== void 0) {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
timer = void 0;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const after = (delay, run) => {
|
|
44
|
+
cancel();
|
|
45
|
+
if (delay <= 0) {
|
|
46
|
+
run();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
timer = void 0;
|
|
51
|
+
run();
|
|
52
|
+
}, delay);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
enter: (delay) => after(delay, callbacks.open),
|
|
56
|
+
leave: (delay) => after(delay, callbacks.close),
|
|
57
|
+
cancel
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { createDelayGroup as n, createHoverIntent as t };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=hover-BakyPYnC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-BakyPYnC.js","names":[],"sources":["../src/hover/delay-group.ts","../src/hover/hover-intent.ts"],"sourcesContent":["export interface DelayGroup {\n /** Whether a member opening now skips its delay: one is open, or one closed within `timeout`. */\n isInstant(now?: number): boolean;\n /** A member opened; the previously open one is asked to close (`close` is how). */\n opened(close: () => void): void;\n /** A member closed (`close` is the callback it registered). */\n closed(close: () => void, now?: number): void;\n}\n\n/**\n * The coordination of a tooltip delay group (spec/tooltip.md, \"Delay group\"): at most one member\n * open, and the instant hand-off. It knows the open member's close callback and the time of the\n * last close, never a member's open state: each member keeps its own and reports here.\n *\n * `timeout` may be a getter, read at each check: a provider whose timeout changes keeps one group\n * (and its open member) instead of making a new one.\n */\nexport function createDelayGroup(options: {\n timeout: number | (() => number);\n}): DelayGroup {\n const timeout = () =>\n typeof options.timeout === \"function\"\n ? options.timeout()\n : options.timeout;\n let current: (() => void) | null = null;\n let lastClosed = Number.NEGATIVE_INFINITY;\n return {\n isInstant(now = Date.now()) {\n return current !== null || now - lastClosed <= timeout();\n },\n opened(close) {\n const previous = current;\n current = close;\n if (previous !== null && previous !== close) {\n previous();\n }\n },\n closed(close, now = Date.now()) {\n if (current === close) {\n current = null;\n }\n lastClosed = now;\n },\n };\n}\n","export interface HoverIntent {\n /** Calls `open` after `delay` ms (at once for 0), cancelling a pending close. */\n enter(delay: number): void;\n /** Calls `close` after `delay` ms (at once for 0), cancelling a pending open. */\n leave(delay: number): void;\n /** Cancels whatever is pending. */\n cancel(): void;\n}\n\n/**\n * The timers of hover intent (spec/tooltip.md, \"Pointer\"): an open after a delay that a leave\n * cancels, and a close after a delay that a return cancels. It holds no open state: `open` and\n * `close` report to the framework, which decides.\n */\nexport function createHoverIntent(callbacks: {\n open: () => void;\n close: () => void;\n}): HoverIntent {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const cancel = () => {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n }\n };\n const after = (delay: number, run: () => void) => {\n cancel();\n if (delay <= 0) {\n run();\n return;\n }\n timer = setTimeout(() => {\n timer = undefined;\n run();\n }, delay);\n };\n return {\n enter: (delay) => after(delay, callbacks.open),\n leave: (delay) => after(delay, callbacks.close),\n cancel,\n };\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,iBAAiB,SAElB;CACX,MAAM,gBACF,OAAO,QAAQ,YAAY,aACrB,QAAQ,QAAQ,IAChB,QAAQ;CAClB,IAAI,UAA+B;CACnC,IAAI,aAAa,OAAO;CACxB,OAAO;EACH,UAAU,MAAM,KAAK,IAAI,GAAG;GACxB,OAAO,YAAY,QAAQ,MAAM,cAAc,QAAQ;EAC3D;EACA,OAAO,OAAO;GACV,MAAM,WAAW;GACjB,UAAU;GACV,IAAI,aAAa,QAAQ,aAAa,OAClC,SAAS;EAEjB;EACA,OAAO,OAAO,MAAM,KAAK,IAAI,GAAG;GAC5B,IAAI,YAAY,OACZ,UAAU;GAEd,aAAa;EACjB;CACJ;AACJ;;;;;;;AC9BA,SAAgB,kBAAkB,WAGlB;CACZ,IAAI;CACJ,MAAM,eAAe;EACjB,IAAI,UAAU,KAAA,GAAW;GACrB,aAAa,KAAK;GAClB,QAAQ,KAAA;EACZ;CACJ;CACA,MAAM,SAAS,OAAe,QAAoB;EAC9C,OAAO;EACP,IAAI,SAAS,GAAG;GACZ,IAAI;GACJ;EACJ;EACA,QAAQ,iBAAiB;GACrB,QAAQ,KAAA;GACR,IAAI;EACR,GAAG,KAAK;CACZ;CACA,OAAO;EACH,QAAQ,UAAU,MAAM,OAAO,UAAU,IAAI;EAC7C,QAAQ,UAAU,MAAM,OAAO,UAAU,KAAK;EAC9C;CACJ;AACJ"}
|
package/dist/hover.d.ts
ADDED
package/dist/hover.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as createDelayGroup, t as createHoverIntent } from "./hover-BakyPYnC.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/id/create-id.ts
|
|
2
|
+
let counter = 0;
|
|
3
|
+
/**
|
|
4
|
+
* A document-unique id for frameworks without one of their own (React, Vue and Angular have
|
|
5
|
+
* theirs: `useId`, `useId`, the injector). Ids look like `primitives-dialog-3`.
|
|
6
|
+
*/
|
|
7
|
+
function createId(prefix = "primitives") {
|
|
8
|
+
counter += 1;
|
|
9
|
+
return `${prefix}-${counter}`;
|
|
10
|
+
}
|
|
11
|
+
export { createId as t };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=id-B0Y8iZrc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-B0Y8iZrc.js","names":[],"sources":["../src/id/create-id.ts"],"sourcesContent":["let counter = 0;\n\n/**\n * A document-unique id for frameworks without one of their own (React, Vue and Angular have\n * theirs: `useId`, `useId`, the injector). Ids look like `primitives-dialog-3`.\n */\nexport function createId(prefix = \"primitives\"): string {\n counter += 1;\n return `${prefix}-${counter}`;\n}\n"],"mappings":";AAAA,IAAI,UAAU;;;;;AAMd,SAAgB,SAAS,SAAS,cAAsB;CACpD,WAAW;CACX,OAAO,GAAG,OAAO,GAAG;AACxB"}
|
package/dist/id.d.ts
ADDED
package/dist/id.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as createId } from "./id-B0Y8iZrc.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/image/watch-image-status.ts
|
|
2
|
+
/**
|
|
3
|
+
* Loads an image outside the document, through the element's window (`new Image()` of its
|
|
4
|
+
* `ownerDocument.defaultView`), and reports its status (spec/avatar.md, "The loading status"):
|
|
5
|
+
* `loading`, then `loaded` or `error`. No `src` and no `srcSet` is an `error`. An image the
|
|
6
|
+
* browser already holds (a cached one) is complete as soon as its source is set: it reports
|
|
7
|
+
* `loaded` (or `error`, when it has no size) at once, synchronously and with no `loading`.
|
|
8
|
+
* Returns the cleanup, after which no status is reported.
|
|
9
|
+
*/
|
|
10
|
+
function watchImageStatus(element, src, options, onStatus) {
|
|
11
|
+
const view = element.ownerDocument.defaultView;
|
|
12
|
+
if (view === null || (src === void 0 || src === "") && (options.srcSet === void 0 || options.srcSet === "")) {
|
|
13
|
+
onStatus("error");
|
|
14
|
+
return () => {};
|
|
15
|
+
}
|
|
16
|
+
let active = true;
|
|
17
|
+
let last = "idle";
|
|
18
|
+
const report = (status) => {
|
|
19
|
+
if (active && status !== last) {
|
|
20
|
+
last = status;
|
|
21
|
+
onStatus(status);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const image = new view.Image();
|
|
25
|
+
const loaded = () => report(image.naturalWidth > 0 ? "loaded" : "error");
|
|
26
|
+
const failed = () => report("error");
|
|
27
|
+
image.addEventListener("load", loaded);
|
|
28
|
+
image.addEventListener("error", failed);
|
|
29
|
+
if (options.crossOrigin !== void 0) image.crossOrigin = options.crossOrigin;
|
|
30
|
+
if (options.referrerPolicy !== void 0) image.referrerPolicy = options.referrerPolicy;
|
|
31
|
+
if (options.sizes !== void 0) image.sizes = options.sizes;
|
|
32
|
+
if (options.srcSet !== void 0) image.srcset = options.srcSet;
|
|
33
|
+
if (src !== void 0) image.src = src;
|
|
34
|
+
if (image.complete) loaded();
|
|
35
|
+
else report("loading");
|
|
36
|
+
return () => {
|
|
37
|
+
active = false;
|
|
38
|
+
image.removeEventListener("load", loaded);
|
|
39
|
+
image.removeEventListener("error", failed);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { watchImageStatus as t };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=image-D4X_yRYw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-D4X_yRYw.js","names":[],"sources":["../src/image/watch-image-status.ts"],"sourcesContent":["/** An image's loading status (spec/avatar.md): `idle` until a load starts. */\nexport type ImageLoadingStatus = \"idle\" | \"loading\" | \"loaded\" | \"error\";\n\nexport interface ImageSourceOptions {\n srcSet?: string;\n sizes?: string;\n /** The load's CORS mode (`anonymous`, `use-credentials`), as the `img` would make it. */\n crossOrigin?: string | null;\n /** The load's referrer policy, as the `img` would make it. */\n referrerPolicy?: string;\n}\n\n/**\n * Loads an image outside the document, through the element's window (`new Image()` of its\n * `ownerDocument.defaultView`), and reports its status (spec/avatar.md, \"The loading status\"):\n * `loading`, then `loaded` or `error`. No `src` and no `srcSet` is an `error`. An image the\n * browser already holds (a cached one) is complete as soon as its source is set: it reports\n * `loaded` (or `error`, when it has no size) at once, synchronously and with no `loading`.\n * Returns the cleanup, after which no status is reported.\n */\nexport function watchImageStatus(\n element: Element,\n src: string | undefined,\n options: ImageSourceOptions,\n onStatus: (status: Exclude<ImageLoadingStatus, \"idle\">) => void,\n): () => void {\n const view = element.ownerDocument.defaultView;\n if (\n view === null ||\n ((src === undefined || src === \"\") &&\n (options.srcSet === undefined || options.srcSet === \"\"))\n ) {\n onStatus(\"error\");\n return () => {};\n }\n let active = true;\n let last: ImageLoadingStatus = \"idle\";\n const report = (status: Exclude<ImageLoadingStatus, \"idle\">) => {\n if (active && status !== last) {\n last = status;\n onStatus(status);\n }\n };\n const image = new view.Image();\n const loaded = () => report(image.naturalWidth > 0 ? \"loaded\" : \"error\");\n const failed = () => report(\"error\");\n image.addEventListener(\"load\", loaded);\n image.addEventListener(\"error\", failed);\n if (options.crossOrigin !== undefined) {\n image.crossOrigin = options.crossOrigin;\n }\n if (options.referrerPolicy !== undefined) {\n image.referrerPolicy = options.referrerPolicy;\n }\n if (options.sizes !== undefined) {\n image.sizes = options.sizes;\n }\n if (options.srcSet !== undefined) {\n image.srcset = options.srcSet;\n }\n if (src !== undefined) {\n image.src = src;\n }\n if (image.complete) {\n loaded();\n } else {\n report(\"loading\");\n }\n return () => {\n active = false;\n image.removeEventListener(\"load\", loaded);\n image.removeEventListener(\"error\", failed);\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,iBACZ,SACA,KACA,SACA,UACU;CACV,MAAM,OAAO,QAAQ,cAAc;CACnC,IACI,SAAS,SACP,QAAQ,KAAA,KAAa,QAAQ,QAC1B,QAAQ,WAAW,KAAA,KAAa,QAAQ,WAAW,KAC1D;EACE,SAAS,OAAO;EAChB,aAAa,CAAC;CAClB;CACA,IAAI,SAAS;CACb,IAAI,OAA2B;CAC/B,MAAM,UAAU,WAAgD;EAC5D,IAAI,UAAU,WAAW,MAAM;GAC3B,OAAO;GACP,SAAS,MAAM;EACnB;CACJ;CACA,MAAM,QAAQ,IAAI,KAAK,MAAM;CAC7B,MAAM,eAAe,OAAO,MAAM,eAAe,IAAI,WAAW,OAAO;CACvE,MAAM,eAAe,OAAO,OAAO;CACnC,MAAM,iBAAiB,QAAQ,MAAM;CACrC,MAAM,iBAAiB,SAAS,MAAM;CACtC,IAAI,QAAQ,gBAAgB,KAAA,GACxB,MAAM,cAAc,QAAQ;CAEhC,IAAI,QAAQ,mBAAmB,KAAA,GAC3B,MAAM,iBAAiB,QAAQ;CAEnC,IAAI,QAAQ,UAAU,KAAA,GAClB,MAAM,QAAQ,QAAQ;CAE1B,IAAI,QAAQ,WAAW,KAAA,GACnB,MAAM,SAAS,QAAQ;CAE3B,IAAI,QAAQ,KAAA,GACR,MAAM,MAAM;CAEhB,IAAI,MAAM,UACN,OAAO;MAEP,OAAO,SAAS;CAEpB,aAAa;EACT,SAAS;EACT,MAAM,oBAAoB,QAAQ,MAAM;EACxC,MAAM,oBAAoB,SAAS,MAAM;CAC7C;AACJ"}
|
package/dist/image.d.ts
ADDED
package/dist/image.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as watchImageStatus } from "./image-D4X_yRYw.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { n as PlainDate } from "./plain-date-idQH1P6X.js";
|
|
2
|
+
declare function daysInMonth(year: number, month: number): number;
|
|
3
|
+
declare function addDays(date: PlainDate, days: number): PlainDate;
|
|
4
|
+
/** The same day `months` later, clamped to the target month's last day (Jan 31 + 1 = Feb 28). */
|
|
5
|
+
declare function addMonths(date: PlainDate, months: number): PlainDate;
|
|
6
|
+
declare function addYears(date: PlainDate, years: number): PlainDate;
|
|
7
|
+
declare function startOfMonth(date: PlainDate): PlainDate;
|
|
8
|
+
declare function endOfMonth(date: PlainDate): PlainDate;
|
|
9
|
+
/** 0 = Sunday … 6 = Saturday. */
|
|
10
|
+
declare function dayOfWeek(date: PlainDate): number;
|
|
11
|
+
/** The first day of the date's week, given the locale's first day (0 = Sunday). */
|
|
12
|
+
declare function startOfWeek(date: PlainDate, firstDayOfWeek: number): PlainDate;
|
|
13
|
+
declare function endOfWeek(date: PlainDate, firstDayOfWeek: number): PlainDate;
|
|
14
|
+
/** Whether `date` is inside `[min, max]` (each bound optional). */
|
|
15
|
+
declare function isWithinBounds(date: PlainDate, min?: PlainDate | null, max?: PlainDate | null): boolean;
|
|
16
|
+
/** `date` moved into `[min, max]`. */
|
|
17
|
+
declare function clampDate(date: PlainDate, min?: PlainDate | null, max?: PlainDate | null): PlainDate;
|
|
18
|
+
/** Whether `date` is in `[a, b]`, whatever the order of `a` and `b`. */
|
|
19
|
+
declare function isBetween(date: PlainDate, a: PlainDate, b: PlainDate): boolean;
|
|
20
|
+
/** The difference in whole months from `a`'s month to `b`'s month. */
|
|
21
|
+
declare function monthsBetween(a: PlainDate, b: PlainDate): number;
|
|
22
|
+
interface Weekday {
|
|
23
|
+
/** 0 = Sunday … 6 = Saturday. */
|
|
24
|
+
readonly index: number;
|
|
25
|
+
/** `Intl` `weekday: "short"`. */
|
|
26
|
+
readonly short: string;
|
|
27
|
+
/** `Intl` `weekday: "long"`. */
|
|
28
|
+
readonly long: string;
|
|
29
|
+
}
|
|
30
|
+
/** The locale's first day of the week, 0 = Sunday (spec/calendar.md, `firstDayOfWeek`). */
|
|
31
|
+
declare function firstDayOfWeek(locale: string): number;
|
|
32
|
+
/** The seven weekdays in the locale's order. */
|
|
33
|
+
declare function weekdays(locale: string, firstDay: number): Weekday[];
|
|
34
|
+
/** "November 2026" (`Intl` `month: "long", year: "numeric"`). */
|
|
35
|
+
declare function formatMonthYear(locale: string, date: PlainDate): string;
|
|
36
|
+
/** "Friday, November 20, 2026" (`Intl` `dateStyle: "full"`). */
|
|
37
|
+
declare function formatFullDate(locale: string, date: PlainDate): string;
|
|
38
|
+
/** "20" (`Intl` `day: "numeric"`). */
|
|
39
|
+
declare function formatDayNumber(locale: string, date: PlainDate): string;
|
|
40
|
+
/**
|
|
41
|
+
* The 6 weeks shown for a month (spec/calendar.md: always 6 rows, so the grid never changes
|
|
42
|
+
* height), starting on the locale's first day of the week.
|
|
43
|
+
*/
|
|
44
|
+
declare function monthGrid(year: number, month: number, firstDayOfWeek: number): PlainDate[][];
|
|
45
|
+
/**
|
|
46
|
+
* Calls `onChange` when the `lang` of `doc`'s document element changes (spec/calendar.md, "API":
|
|
47
|
+
* a calendar with no `locale` follows the document's language after mount, Epic #49). Returns the
|
|
48
|
+
* cleanup.
|
|
49
|
+
*/
|
|
50
|
+
declare function watchDocumentLanguage(doc: Document, onChange: () => void): () => void;
|
|
51
|
+
export { isBetween as _, formatDayNumber as a, startOfMonth as b, weekdays as c, addYears as d, clampDate as f, endOfWeek as g, endOfMonth as h, firstDayOfWeek as i, addDays as l, daysInMonth as m, monthGrid as n, formatFullDate as o, dayOfWeek as p, Weekday as r, formatMonthYear as s, watchDocumentLanguage as t, addMonths as u, isWithinBounds as v, startOfWeek as x, monthsBetween as y };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** A file's name and type, all an `accept` pattern reads. */
|
|
2
|
+
interface FileLike {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly type: string;
|
|
5
|
+
}
|
|
6
|
+
/** The `accept` of a file input: a comma-separated string, or its patterns (spec/drop-zone.md). */
|
|
7
|
+
type FileAccept = string | readonly string[];
|
|
8
|
+
/** `accept` as a file input's attribute (`undefined` for none). */
|
|
9
|
+
declare function acceptAttribute(accept: FileAccept | undefined): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Whether `file` matches `accept`, as a file input's `accept` reads it (spec/drop-zone.md, "API"):
|
|
12
|
+
* an extension (`.pdf`, case insensitive), a MIME type (`image/png`) or a wildcard (`image/*`).
|
|
13
|
+
* No `accept` (or an empty one) takes every file.
|
|
14
|
+
*/
|
|
15
|
+
declare function acceptsFile(file: FileLike, accept: FileAccept | undefined): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A DropZone's split of the files it was given (spec/drop-zone.md): the ones `accept` takes, and
|
|
18
|
+
* the others. When `multiple` is `false`, more than one file rejects them all.
|
|
19
|
+
*/
|
|
20
|
+
declare function acceptFiles<File extends FileLike>(files: readonly File[], accept: FileAccept | undefined, multiple: boolean): {
|
|
21
|
+
accepted: File[];
|
|
22
|
+
rejected: File[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Puts `files` into a file input (spec/file-upload.md, "Forms"): a `DataTransfer` of the input's
|
|
26
|
+
* window, built with them, gives its `files` list to `input.files`, so the native form submits
|
|
27
|
+
* them, `required` validates them and a `FormData` holds them. Verified in Chromium; Firefox
|
|
28
|
+
* (57+) and Safari (14.1+) accept the same assignment. Returns `false` where the window has no
|
|
29
|
+
* `DataTransfer` constructor (the input keeps its files).
|
|
30
|
+
*/
|
|
31
|
+
declare function assignFiles(input: HTMLInputElement, files: readonly File[]): boolean;
|
|
32
|
+
/** A file as the checks read it: its name, type and size in bytes. */
|
|
33
|
+
interface CheckedFile {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly type: string;
|
|
36
|
+
readonly size: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Why a file was rejected (spec/file-upload.md, "Purpose"): its type (`accept`), its size, the
|
|
40
|
+
* count (`maxFiles`), or a reason of the app's own `validate`.
|
|
41
|
+
*/
|
|
42
|
+
type FileRejectionReason = "invalid-type" | "too-large" | "too-small" | "too-many" | (string & Record<never, never>);
|
|
43
|
+
/** A rejected file and every reason it failed. */
|
|
44
|
+
interface FileRejection<File extends CheckedFile = CheckedFile> {
|
|
45
|
+
file: File;
|
|
46
|
+
reasons: readonly FileRejectionReason[];
|
|
47
|
+
}
|
|
48
|
+
/** A FileUpload's rules (spec/file-upload.md, "API"). */
|
|
49
|
+
interface FileRules<File extends CheckedFile = CheckedFile> {
|
|
50
|
+
accept?: FileAccept | undefined;
|
|
51
|
+
/** At most this many accepted files (default `1`, which replaces the file on a new pick). */
|
|
52
|
+
maxFiles?: number | undefined;
|
|
53
|
+
/** Bytes, inclusive (default `0`). */
|
|
54
|
+
minFileSize?: number | undefined;
|
|
55
|
+
/** Bytes, inclusive (default `Infinity`). */
|
|
56
|
+
maxFileSize?: number | undefined;
|
|
57
|
+
/** The app's own reasons for a file (`null` or `[]` for none), given the files accepted so far. */
|
|
58
|
+
validate?: ((file: File, value: readonly File[]) => readonly string[] | null | undefined) | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** What a pick does to a FileUpload's files. */
|
|
61
|
+
interface FileCheck<File extends CheckedFile = CheckedFile> {
|
|
62
|
+
/** The accepted files after the pick: the value. */
|
|
63
|
+
value: File[];
|
|
64
|
+
/** The files of the pick that were accepted. */
|
|
65
|
+
accepted: File[];
|
|
66
|
+
/** The files of the pick that were rejected, with their reasons. */
|
|
67
|
+
rejected: FileRejection<File>[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks the files of a pick against `rules`, given the accepted files `value` (spec/file-upload.md):
|
|
71
|
+
* each file in order, every failing check a reason (`invalid-type`, `too-large`, `too-small`, the
|
|
72
|
+
* app's own, then `too-many` for a file over `maxFiles`). With `maxFiles` `1`, a single good file
|
|
73
|
+
* replaces the value and a pick of several rejects them all (`too-many`), as a native single file
|
|
74
|
+
* input does.
|
|
75
|
+
*/
|
|
76
|
+
declare function checkFiles<File extends CheckedFile>(value: readonly File[], files: readonly File[], rules: FileRules<File>): FileCheck<File>;
|
|
77
|
+
/**
|
|
78
|
+
* A copy of `files` that a Field can compare (spec/file-upload.md, "Forms"): a Field detects a
|
|
79
|
+
* change of its control's value by its JSON text, and a `File` writes `{}`; the copy writes each
|
|
80
|
+
* file as `name:size:type:lastModified` (a non-enumerable `toJSON`), so a replaced file is a
|
|
81
|
+
* change. It is still the files, for the Field's `validate`.
|
|
82
|
+
*/
|
|
83
|
+
declare function fieldFiles(files: readonly File[]): File[];
|
|
84
|
+
/**
|
|
85
|
+
* A file size in the locale's bytes (spec/file-upload.md, "State attributes and ARIA"):
|
|
86
|
+
* `Intl.NumberFormat`'s `unit` style, short, in decimal units (`Intl`'s are SI: 1 kB = 1000
|
|
87
|
+
* bytes), with one fraction digit above bytes: `en-US` writes `512 byte`, `1.5 kB`, `2 MB`.
|
|
88
|
+
* Locale data, not text of the library's own; `undefined` is the runtime's locale.
|
|
89
|
+
*/
|
|
90
|
+
declare function formatFileSize(bytes: number, locale?: string | readonly string[]): string;
|
|
91
|
+
interface FileDialogOptions {
|
|
92
|
+
accept?: FileAccept | undefined;
|
|
93
|
+
multiple?: boolean | undefined;
|
|
94
|
+
/** The camera a phone opens (`user`, `environment`), as a file input's `capture`. */
|
|
95
|
+
capture?: "user" | "environment" | undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Opens the browser's file dialog for `element`'s document (spec/drop-zone.md, "Purpose"): a file
|
|
99
|
+
* `input` created for this press, never put in the document, clicked in the press's user
|
|
100
|
+
* activation. `onFiles` receives the files picked, and is not called when the dialog closes with
|
|
101
|
+
* none.
|
|
102
|
+
*/
|
|
103
|
+
declare function openFileDialog(element: Element, options: FileDialogOptions, onFiles: (files: File[], event: Event) => void): void;
|
|
104
|
+
/** Why files arrived on a drop target (spec/drop-zone.md). */
|
|
105
|
+
type FileDropReason = "drop" | "paste";
|
|
106
|
+
interface FileDropOptions {
|
|
107
|
+
/** Read on every event: a disabled target takes nothing. */
|
|
108
|
+
disabled: () => boolean;
|
|
109
|
+
/** A drag of files entered the target (`true`), or left it, dropped or ended (`false`). */
|
|
110
|
+
onDropTargetChange: (active: boolean, event: Event) => void;
|
|
111
|
+
/** Files were dropped or pasted (never called with none). */
|
|
112
|
+
onFiles: (files: File[], reason: FileDropReason, event: Event) => void;
|
|
113
|
+
/** A press: a click, Enter or Space (the file dialog's opening). */
|
|
114
|
+
onActivate?: ((event: Event) => void) | undefined;
|
|
115
|
+
}
|
|
116
|
+
/** Whether a drag carries files (`dataTransfer.types` holds `"Files"`). */
|
|
117
|
+
declare function dragHasFiles(event: DragEvent): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Makes `element` a target for files (spec/drop-zone.md, "Pointer", "Keyboard"): a drag of files
|
|
120
|
+
* over it (counted across its children's enters and leaves) is reported and shows the `copy`
|
|
121
|
+
* effect, its drop hands over the files, and a paste on it hands over the clipboard's files; a
|
|
122
|
+
* drag of anything else is left alone. While `disabled()`, a drag of files shows the `none` effect
|
|
123
|
+
* and its drop is canceled, so the browser does not open the file. A click, Enter (keydown) or Space (keyup)
|
|
124
|
+
* is a press (`onActivate`; neither scrolls the page, Enter does not repeat). Native listeners, so
|
|
125
|
+
* every framework sees the same events. Returns the cleanup.
|
|
126
|
+
*/
|
|
127
|
+
declare function watchFileDrop(element: HTMLElement, options: FileDropOptions): () => void;
|
|
128
|
+
export { FileLike as _, FileDialogOptions as a, acceptsFile as b, fieldFiles as c, FileRejection as d, FileRejectionReason as f, FileAccept as g, assignFiles as h, watchFileDrop as i, CheckedFile as l, checkFiles as m, FileDropReason as n, openFileDialog as o, FileRules as p, dragHasFiles as r, formatFileSize as s, FileDropOptions as t, FileCheck as u, acceptAttribute as v, acceptFiles as y };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** An image's loading status (spec/avatar.md): `idle` until a load starts. */
|
|
2
|
+
type ImageLoadingStatus = "idle" | "loading" | "loaded" | "error";
|
|
3
|
+
interface ImageSourceOptions {
|
|
4
|
+
srcSet?: string;
|
|
5
|
+
sizes?: string;
|
|
6
|
+
/** The load's CORS mode (`anonymous`, `use-credentials`), as the `img` would make it. */
|
|
7
|
+
crossOrigin?: string | null;
|
|
8
|
+
/** The load's referrer policy, as the `img` would make it. */
|
|
9
|
+
referrerPolicy?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Loads an image outside the document, through the element's window (`new Image()` of its
|
|
13
|
+
* `ownerDocument.defaultView`), and reports its status (spec/avatar.md, "The loading status"):
|
|
14
|
+
* `loading`, then `loaded` or `error`. No `src` and no `srcSet` is an `error`. An image the
|
|
15
|
+
* browser already holds (a cached one) is complete as soon as its source is set: it reports
|
|
16
|
+
* `loaded` (or `error`, when it has no size) at once, synchronously and with no `loading`.
|
|
17
|
+
* Returns the cleanup, after which no status is reported.
|
|
18
|
+
*/
|
|
19
|
+
declare function watchImageStatus(element: Element, src: string | undefined, options: ImageSourceOptions, onStatus: (status: Exclude<ImageLoadingStatus, "idle">) => void): () => void;
|
|
20
|
+
export { ImageSourceOptions as n, watchImageStatus as r, ImageLoadingStatus as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blocks the pointer outside a modal overlay (spec/menu.md, "Modal"): the body stops taking
|
|
3
|
+
* pointer events (`pointer-events: none`), so a press outside reaches no element of the page and
|
|
4
|
+
* only dismisses the overlay; the overlay's own elements opt back in with `pointer-events: auto`.
|
|
5
|
+
* Nested blocks are counted. Returns the restore.
|
|
6
|
+
*/
|
|
7
|
+
declare function blockOutsidePointer(doc: Document): () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Makes everything outside `keep` inert (spec/dialog.md, "Focus"): each sibling of each ancestor
|
|
10
|
+
* of the kept elements, up to `body`. Elements added later (a child layer's portal) are not
|
|
11
|
+
* touched, nor a hidden overlay part (`hidden` and `data-primitives-part`: a kept-mounted
|
|
12
|
+
* overlay's portal content, closed): it takes no interaction while hidden, and an overlay opened
|
|
13
|
+
* from the kept elements later shows it again, which an inert would leave unusable. Returns the
|
|
14
|
+
* restore.
|
|
15
|
+
*/
|
|
16
|
+
declare function inertOutside(keep: readonly Element[]): () => void;
|
|
17
|
+
export { blockOutsidePointer as n, inertOutside as t };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A month with no day, no time and no time zone (spec/month-calendar.md, "Values"), Temporal's
|
|
3
|
+
* `PlainYearMonth` shape. `month` is 1–12.
|
|
4
|
+
*/
|
|
5
|
+
interface PlainYearMonth {
|
|
6
|
+
readonly year: number;
|
|
7
|
+
readonly month: number;
|
|
8
|
+
}
|
|
9
|
+
/** A year with no month (an object, so a calendar system can extend it). */
|
|
10
|
+
interface PlainYear {
|
|
11
|
+
readonly year: number;
|
|
12
|
+
}
|
|
13
|
+
/** A range of months, `start <= end`. */
|
|
14
|
+
interface YearMonthRange {
|
|
15
|
+
readonly start: PlainYearMonth;
|
|
16
|
+
readonly end: PlainYearMonth;
|
|
17
|
+
}
|
|
18
|
+
/** A range of years, `start <= end`. */
|
|
19
|
+
interface YearRange {
|
|
20
|
+
readonly start: PlainYear;
|
|
21
|
+
readonly end: PlainYear;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A month as one number (`year * 12 + month - 1`), so the month grid moves by adding: the next
|
|
25
|
+
* month is `+ 1`, the same month of the next year `+ 12`. A year's index is the year itself.
|
|
26
|
+
*/
|
|
27
|
+
declare function monthIndex(month: PlainYearMonth): number;
|
|
28
|
+
/** The month of a {@link monthIndex}. */
|
|
29
|
+
declare function fromMonthIndex(index: number): PlainYearMonth;
|
|
30
|
+
/** The local month of `now` (the clock the page sees). */
|
|
31
|
+
declare function currentYearMonth(now?: Date): PlainYearMonth;
|
|
32
|
+
/** `2026-11` (ISO 8601, as `<input type="month">`). */
|
|
33
|
+
declare function toIsoYearMonth(month: PlainYearMonth): string;
|
|
34
|
+
/** `2026` (ISO 8601's year: 4 digits). */
|
|
35
|
+
declare function toIsoYear(year: PlainYear): string;
|
|
36
|
+
/** "Nov" (`Intl` `month: "short"`), or "November" with `"long"`. */
|
|
37
|
+
declare function formatMonthName(locale: string, month: PlainYearMonth, width?: "short" | "long"): string;
|
|
38
|
+
/** "November 2026" (`Intl` `month: "long", year: "numeric"`). */
|
|
39
|
+
declare function formatYearMonth(locale: string, month: PlainYearMonth): string;
|
|
40
|
+
/** "2026" (`Intl` `year: "numeric"`). */
|
|
41
|
+
declare function formatYear(locale: string, year: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* "2016 – 2027" (`Intl.DateTimeFormat#formatRange` of two years), every space written as U+0020:
|
|
44
|
+
* engines differ on the spaces around the dash (Node's ICU and Chromium's), and a server's text
|
|
45
|
+
* must be the hydrating browser's (the date fields' literals, Epic #73).
|
|
46
|
+
*/
|
|
47
|
+
declare function formatYearSpan(locale: string, first: number, last: number): string;
|
|
48
|
+
export { PlainYear as a, YearRange as c, monthIndex as d, toIsoYear as f, formatYearSpan as i, currentYearMonth as l, formatYear as n, PlainYearMonth as o, toIsoYearMonth as p, formatYearMonth as r, YearMonthRange as s, formatMonthName as t, fromMonthIndex as u };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** A rendered row of a virtual list: its index, where it starts, its size and the room before it. */
|
|
2
|
+
interface VirtualRow {
|
|
3
|
+
index: number;
|
|
4
|
+
/** Its offset from the list's first row (the sizes and gaps of every row before it). */
|
|
5
|
+
start: number;
|
|
6
|
+
size: number;
|
|
7
|
+
/**
|
|
8
|
+
* The room between the previous rendered row (or the list's start) and this row that no
|
|
9
|
+
* rendered row fills: the unrendered rows and their gaps. The framework gives it to the row as
|
|
10
|
+
* its `margin-block-start`; the layout's own gap between two rendered rows is not part of it.
|
|
11
|
+
*/
|
|
12
|
+
spaceBefore: number;
|
|
13
|
+
/** The group label that sticks to the top of the scroll container (`position: sticky`). */
|
|
14
|
+
sticky: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** What a virtual list renders: its rows, in order, and the room after the last one. */
|
|
17
|
+
interface VirtualRange {
|
|
18
|
+
rows: readonly VirtualRow[];
|
|
19
|
+
/** The room after the last rendered row: its `margin-block-end`. */
|
|
20
|
+
spaceAfter: number;
|
|
21
|
+
/** The size of every row and gap: the list's full extent. */
|
|
22
|
+
totalSize: number;
|
|
23
|
+
/** The first row in view (the overscan excluded), `-1` when the list is empty. */
|
|
24
|
+
visibleStart: number;
|
|
25
|
+
/** The last row in view (the overscan excluded), `-1` when the list is empty. */
|
|
26
|
+
visibleEnd: number;
|
|
27
|
+
}
|
|
28
|
+
interface VirtualLayoutOptions {
|
|
29
|
+
count: number;
|
|
30
|
+
/** A row's size: measured, else estimated. */
|
|
31
|
+
size: (index: number) => number;
|
|
32
|
+
/** The layout's gap between two rows (a flex or grid `row-gap`). */
|
|
33
|
+
gap?: number;
|
|
34
|
+
/** How far the list is scrolled, from its first row. */
|
|
35
|
+
offset: number;
|
|
36
|
+
/** The scroll container's visible size. */
|
|
37
|
+
viewport: number;
|
|
38
|
+
/** The rows rendered beyond each end of the view (default 4). */
|
|
39
|
+
overscan?: number;
|
|
40
|
+
/** Rows always rendered: the focused or highlighted one, the selected one, the ends. */
|
|
41
|
+
pinned?: readonly number[];
|
|
42
|
+
/** The rows that stick while their group is in view (group labels), in order. */
|
|
43
|
+
sticky?: readonly number[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Where every row starts: `starts[i]` is row `i`'s offset, `starts[count]` the list's extent. A
|
|
47
|
+
* gap separates two rows (none after the last).
|
|
48
|
+
*/
|
|
49
|
+
declare function rowStarts(count: number, size: (index: number) => number, gap?: number): Float64Array;
|
|
50
|
+
/** The row at `offset`: the last one starting at or before it (clamped to the list). */
|
|
51
|
+
declare function rowAt(starts: Float64Array, offset: number): number;
|
|
52
|
+
/** The sticky row of the group in view: the last sticky row at or before `first`. */
|
|
53
|
+
declare function activeSticky(sticky: readonly number[], first: number): number | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The rows a virtual list renders for a scroll position (spec/README.md, "Virtual lists"): the
|
|
56
|
+
* rows in view, `overscan` rows beyond each end, the pinned rows and the sticky row of the group
|
|
57
|
+
* in view, each with the room before it. Pure: the framework renders the rows, the virtualizer
|
|
58
|
+
* reads the DOM.
|
|
59
|
+
*/
|
|
60
|
+
declare function virtualLayout(options: VirtualLayoutOptions, starts?: Float64Array): VirtualRange;
|
|
61
|
+
/**
|
|
62
|
+
* The row a page away from `from` (PageDown `1`, PageUp `-1`): the farthest row whose far edge is
|
|
63
|
+
* within `viewport` of `from`'s near edge; the last (first) row when the whole list fits. As
|
|
64
|
+
* `/selection`'s `pageTarget`, computed on the sizes instead of the elements, so it reaches rows
|
|
65
|
+
* that are not rendered.
|
|
66
|
+
*/
|
|
67
|
+
declare function pageIndex(starts: Float64Array, size: (index: number) => number, from: number, delta: 1 | -1, viewport: number): number;
|
|
68
|
+
/** Where `scrollToIndex` puts the row: `auto` scrolls the least to bring it into view. */
|
|
69
|
+
type VirtualAlign = "auto" | "start" | "center" | "end";
|
|
70
|
+
interface VirtualizerOptions {
|
|
71
|
+
/** How many rows the list has. */
|
|
72
|
+
count: number;
|
|
73
|
+
/**
|
|
74
|
+
* A row's size before it is measured, or every row's size when the rows are not measured
|
|
75
|
+
* (fixed sizes): a number, or a function of the index (default 36).
|
|
76
|
+
*/
|
|
77
|
+
estimateSize?: number | ((index: number) => number);
|
|
78
|
+
/** The rows rendered beyond each end of the view (default 4). */
|
|
79
|
+
overscan?: number;
|
|
80
|
+
/** Rows always rendered (the focused, highlighted or selected one; the ends). */
|
|
81
|
+
pinned?: readonly number[];
|
|
82
|
+
/** The rows that stick while their group is in view (group labels), in order. */
|
|
83
|
+
sticky?: readonly number[];
|
|
84
|
+
/**
|
|
85
|
+
* The visible size assumed before the scroll container is attached (a server render, the
|
|
86
|
+
* first client render): default 0, so only the overscan rows render until then.
|
|
87
|
+
*/
|
|
88
|
+
initialViewport?: number;
|
|
89
|
+
/** The rendered rows changed: render the list again and read `range()`. */
|
|
90
|
+
onChange?: () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A virtual list's mechanism (spec/README.md, "Virtual lists"): the rows to render for the
|
|
94
|
+
* scroll position, their measured sizes and the scrolling to a row. It holds no component state
|
|
95
|
+
* (rule 2): the framework keeps the items, the focus and the highlight, renders the rows of
|
|
96
|
+
* `range()` and gives each its `spaceBefore` as `margin-block-start` (the last one
|
|
97
|
+
* `spaceAfter` as `margin-block-end`), `flex-shrink: 0` and `overflow-anchor: none` (the
|
|
98
|
+
* virtualizer keeps the view still itself), so the list keeps its flow layout (sticky labels,
|
|
99
|
+
* flex gaps) with no extra element.
|
|
100
|
+
*/
|
|
101
|
+
interface Virtualizer {
|
|
102
|
+
/** New options (the count, the pinned rows, ...); the next `range()` follows them. */
|
|
103
|
+
update(options: Partial<VirtualizerOptions>): void;
|
|
104
|
+
/** The rows to render now. */
|
|
105
|
+
range(): VirtualRange;
|
|
106
|
+
/**
|
|
107
|
+
* Watches the list's scroll container (`scroller`, default the list or its nearest
|
|
108
|
+
* scrollable ancestor) and its size; returns the cleanup.
|
|
109
|
+
*/
|
|
110
|
+
attach(list: HTMLElement, scroller?: HTMLElement | null): () => void;
|
|
111
|
+
/** Measures a rendered row now and whenever its size changes; returns the cleanup. */
|
|
112
|
+
measure(index: number, element: HTMLElement): () => void;
|
|
113
|
+
/** Scrolls the container so the row is in view, and updates the range at once. */
|
|
114
|
+
scrollToIndex(index: number, align?: VirtualAlign): void;
|
|
115
|
+
/** The row a page away (PageDown `1`, PageUp `-1`), by the sizes and the visible size. */
|
|
116
|
+
pageIndex(from: number, delta: 1 | -1): number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The scroll container of a list: the list itself when it scrolls, else its nearest ancestor
|
|
120
|
+
* whose `overflow-y` scrolls; the list when none does.
|
|
121
|
+
*/
|
|
122
|
+
declare function scrollContainer(list: HTMLElement): HTMLElement;
|
|
123
|
+
/** Creates a virtualizer (`Virtualizer`); it reads the DOM only once attached. */
|
|
124
|
+
declare function createVirtualizer(initial: VirtualizerOptions): Virtualizer;
|
|
125
|
+
export { scrollContainer as a, VirtualRow as c, rowAt as d, rowStarts as f, createVirtualizer as i, activeSticky as l, Virtualizer as n, VirtualLayoutOptions as o, virtualLayout as p, VirtualizerOptions as r, VirtualRange as s, VirtualAlign as t, pageIndex as u };
|