@cloudlet/toast 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +236 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/THIRD_PARTY_NOTICES.md +149 -0
- package/dist/contracts/controller.d.ts +71 -0
- package/dist/contracts/controller.d.ts.map +1 -0
- package/dist/contracts/events.d.ts +72 -0
- package/dist/contracts/events.d.ts.map +1 -0
- package/dist/contracts/identity.d.ts +32 -0
- package/dist/contracts/identity.d.ts.map +1 -0
- package/dist/contracts/internal.d.ts +188 -0
- package/dist/contracts/internal.d.ts.map +1 -0
- package/dist/contracts/notifications.d.ts +101 -0
- package/dist/contracts/notifications.d.ts.map +1 -0
- package/dist/contracts/operations.d.ts +76 -0
- package/dist/contracts/operations.d.ts.map +1 -0
- package/dist/contracts/snapshots.d.ts +48 -0
- package/dist/contracts/snapshots.d.ts.map +1 -0
- package/dist/core/controller.d.ts +7 -0
- package/dist/core/controller.d.ts.map +1 -0
- package/dist/core/controller.js +954 -0
- package/dist/core/controller.js.map +1 -0
- package/dist/core/validation.d.ts +17 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +298 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/create-cloudlet.d.ts +5 -0
- package/dist/create-cloudlet.d.ts.map +1 -0
- package/dist/create-cloudlet.js +34 -0
- package/dist/create-cloudlet.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/react/announcer.d.ts +15 -0
- package/dist/react/announcer.d.ts.map +1 -0
- package/dist/react/announcer.js +134 -0
- package/dist/react/announcer.js.map +1 -0
- package/dist/react/bindings.d.ts +8 -0
- package/dist/react/bindings.d.ts.map +1 -0
- package/dist/react/bindings.js +84 -0
- package/dist/react/bindings.js.map +1 -0
- package/dist/react/card.d.ts +58 -0
- package/dist/react/card.d.ts.map +1 -0
- package/dist/react/card.js +300 -0
- package/dist/react/card.js.map +1 -0
- package/dist/react/generators.d.ts +46 -0
- package/dist/react/generators.d.ts.map +1 -0
- package/dist/react/generators.js +115 -0
- package/dist/react/generators.js.map +1 -0
- package/dist/react/gestures.d.ts +50 -0
- package/dist/react/gestures.d.ts.map +1 -0
- package/dist/react/gestures.js +239 -0
- package/dist/react/gestures.js.map +1 -0
- package/dist/react/host.d.ts +37 -0
- package/dist/react/host.d.ts.map +1 -0
- package/dist/react/host.js +816 -0
- package/dist/react/host.js.map +1 -0
- package/dist/react/motion.d.ts +206 -0
- package/dist/react/motion.d.ts.map +1 -0
- package/dist/react/motion.js +414 -0
- package/dist/react/motion.js.map +1 -0
- package/dist/react/plan.d.ts +45 -0
- package/dist/react/plan.d.ts.map +1 -0
- package/dist/react/plan.js +58 -0
- package/dist/react/plan.js.map +1 -0
- package/dist/react/shape.d.ts +7 -0
- package/dist/react/shape.d.ts.map +1 -0
- package/dist/react/shape.js +21 -0
- package/dist/react/shape.js.map +1 -0
- package/dist/react/viewport.d.ts +15 -0
- package/dist/react/viewport.d.ts.map +1 -0
- package/dist/react/viewport.js +16 -0
- package/dist/react/viewport.js.map +1 -0
- package/dist/react.d.ts +176 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +2 -0
- package/dist/styles.css +1 -0
- package/package.json +17 -4
- package/src/contracts/controller.ts +61 -0
- package/src/contracts/events.ts +47 -0
- package/src/contracts/identity.ts +27 -0
- package/src/contracts/internal.ts +150 -0
- package/src/contracts/notifications.ts +104 -0
- package/src/contracts/operations.ts +71 -0
- package/src/contracts/snapshots.ts +59 -0
- package/src/core/controller.ts +1038 -0
- package/src/core/validation.ts +290 -0
- package/src/create-cloudlet.ts +43 -0
- package/src/index.ts +34 -0
- package/src/react/announcer.ts +189 -0
- package/src/react/bindings.tsx +100 -0
- package/src/react/card.tsx +222 -0
- package/src/react/generators.ts +274 -0
- package/src/react/gestures.ts +296 -0
- package/src/react/host.tsx +947 -0
- package/src/react/motion.ts +484 -0
- package/src/react/plan.ts +101 -0
- package/src/react/shape.ts +33 -0
- package/src/react/viewport.ts +10 -0
- package/src/react.ts +190 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createCloudletCore as e } from "./core/controller.js";
|
|
2
|
+
//#region src/create-cloudlet.ts
|
|
3
|
+
function t() {
|
|
4
|
+
return {
|
|
5
|
+
now: () => globalThis.performance.now(),
|
|
6
|
+
schedule(e, t) {
|
|
7
|
+
let n = !1, r, i = () => {
|
|
8
|
+
let a = Math.max(0, e - globalThis.performance.now());
|
|
9
|
+
r = globalThis.setTimeout(() => {
|
|
10
|
+
n || (globalThis.performance.now() < e ? i() : t());
|
|
11
|
+
}, Math.min(a, 2147483647));
|
|
12
|
+
};
|
|
13
|
+
return i(), () => {
|
|
14
|
+
n || (n = !0, globalThis.clearTimeout(r));
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function n(n) {
|
|
20
|
+
return e(n, {
|
|
21
|
+
clock: t(),
|
|
22
|
+
createCancellation: () => {
|
|
23
|
+
let e = new AbortController();
|
|
24
|
+
return {
|
|
25
|
+
signal: e.signal,
|
|
26
|
+
abort: (t) => e.abort(t)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { n as createCloudlet };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=create-cloudlet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-cloudlet.js","names":["createWebClock","cancelled","timer","schedule","delay","deadline","callback","createCloudlet","createCloudletCore","options","controller","reason"],"sources":["../src/create-cloudlet.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { ControllerOptions } from './contracts/controller.js';\nimport type { MonotonicClock } from './contracts/internal.js';\nimport type { ReactCloudletController } from './react.js';\nimport { createCloudletCore } from './core/controller.js';\n\n/** A lazy web adapter: constructing a controller allocates no timers or listeners. */\nfunction createWebClock(): MonotonicClock {\n return {\n now: () => globalThis.performance.now(),\n schedule(deadline, callback) {\n let cancelled = false;\n let timer: ReturnType<typeof globalThis.setTimeout>;\n const schedule = () => {\n const delay = Math.max(0, deadline - globalThis.performance.now());\n // Browsers clamp longer delays to a signed 32-bit timeout. Re-arm only\n // at that boundary so long explicit durations cannot expire early.\n timer = globalThis.setTimeout(() => {\n if (cancelled) return;\n if (globalThis.performance.now() < deadline) schedule();\n else callback();\n }, Math.min(delay, 2_147_483_647));\n };\n schedule();\n return () => {\n if (cancelled) return;\n cancelled = true;\n globalThis.clearTimeout(timer);\n };\n },\n };\n}\n\n/** DOM-free state with lazy native clock and per-attempt cancellation adapters. */\nexport function createCloudlet(options?: ControllerOptions): ReactCloudletController {\n return createCloudletCore<ReactNode, AbortSignal>(options, {\n clock: createWebClock(),\n createCancellation: () => {\n const controller = new AbortController();\n return { signal: controller.signal, abort: (reason) => controller.abort(reason) };\n },\n });\n}\n"],"mappings":";;AAOA,SAASA,IAAiC;CACxC,OAAO;EACL,WAAW,WAAW,YAAY,IAAI;EACtC,SAAS,GAAU,GAAU;GAC3B,IAAIC,IAAY,IACZC,GACEC,UAAiB;IACrB,IAAMC,IAAQ,KAAK,IAAI,GAAGC,IAAW,WAAW,YAAY,IAAI,CAAC;IAGjE,IAAQ,WAAW,iBAAiB;KAClC,AAAIJ,MACA,WAAW,YAAY,IAAI,IAAII,IAAUF,EAAS,IACjDG,EAAS;IAChB,GAAG,KAAK,IAAIF,GAAO,UAAa,CAAC;GACnC;GAEA,OADAD,EAAS,SACI;IACX,AAAIF,MACJ,IAAY,IACZ,WAAW,aAAaC,CAAK;GAC/B;EACF;CACF;AACF;AAGA,SAAgBK,EAAe,GAAsD;CACnF,OAAOC,EAA2CC,GAAS;EACzD,OAAOT,EAAe;EACtB,0BAA0B;GACxB,IAAMU,IAAa,IAAI,gBAAgB;GACvC,OAAO;IAAE,QAAQA,EAAW;IAAQ,QAAQ,MAAWA,EAAW,MAAMC,CAAM;GAAE;EAClF;CACF,CAAC;AACH"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createCloudlet } from './create-cloudlet.js';
|
|
2
|
+
export { CloudletProvider, useCloudlet, useOptionalCloudlet, Toaster } from './react.js';
|
|
3
|
+
export type * from './contracts/identity.js';
|
|
4
|
+
export type * from './contracts/notifications.js';
|
|
5
|
+
export type * from './contracts/operations.js';
|
|
6
|
+
export type * from './contracts/snapshots.js';
|
|
7
|
+
export type * from './contracts/events.js';
|
|
8
|
+
export type * from './contracts/controller.js';
|
|
9
|
+
export type { ReactNotificationSpec, ReactNotificationPatch, ReactCloudletController, ReactOperationContext, ReactOperationFactory, ReactTrackOptions, CreateCloudlet, CloudletProviderProps, EdgeInsets, ToasterOffsets, ToasterAttention, ToasterMotion, CloudletSpring, CloudletTimedSpring, CloudletMotionConstants, CloudletMotionOverrides, CloudletPart, CloudletLabels, AnnouncementFormatters, ToasterProps, CloudletProviderComponent, UseCloudlet, UseOptionalCloudlet, ToasterComponent, } from './react.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACzF,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,2BAA2B,CAAC;AAC/C,mBAAmB,0BAA0B,CAAC;AAC9C,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,2BAA2B,CAAC;AAC/C,YAAY,EACV,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createCloudlet as e } from "./create-cloudlet.js";
|
|
2
|
+
import { CloudletProvider as t, Toaster as n, useCloudlet as r, useOptionalCloudlet as i } from "./react.js";
|
|
3
|
+
export { t as CloudletProvider, n as Toaster, e as createCloudlet, r as useCloudlet, i as useOptionalCloudlet };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { HostLease, RendererBridge } from '../contracts/internal.js';
|
|
3
|
+
import type { AnnouncementFormatters } from '../react.js';
|
|
4
|
+
/** One attachment, two existing live hosts, one fixed batch window. No event history. */
|
|
5
|
+
export declare function createAnnouncer(bridge: RendererBridge<ReactNode>, lease: HostLease, doc: Document, options: () => Partial<AnnouncementFormatters> | undefined): {
|
|
6
|
+
/**
|
|
7
|
+
* The announcer owns its live regions: created here, next to the host (React owns the host's
|
|
8
|
+
* children), and inserted twice. VoiceOver in Safari ignored assertive changes made while focus
|
|
9
|
+
* was in the open Island in regions inserted only once (0 of 6 runs), and spoke them after one
|
|
10
|
+
* re-insertion on the next frame (6 of 6, rc.2 gate); a zero timeout was not enough (3 of 5).
|
|
11
|
+
*/
|
|
12
|
+
mount(host: HTMLElement): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=announcer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announcer.d.ts","sourceRoot":"","sources":["../../src/react/announcer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAA+B,SAAS,EAA8B,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAGnI,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAkB1D,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAChG,OAAO,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,GAAG,SAAS;IAyHxD;;;;;OAKG;IACH,KAAK,OAAO,WAAW;IA4BvB,OAAO;EASV"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
//#region src/react/announcer.ts
|
|
2
|
+
var e = ({ content: e }) => [e.title, e.description?.kind === "rich" ? e.description.announcement : e.description?.text].filter(Boolean).join(". "), t = {
|
|
3
|
+
notification: e,
|
|
4
|
+
queued: (e) => `${e} notifications queued`,
|
|
5
|
+
occurrences: (e) => `${e.content.title}. ${e.occurrences} occurrences`,
|
|
6
|
+
overflow: (e) => `${e} missed notifications`,
|
|
7
|
+
operation: e,
|
|
8
|
+
actionError: (e, t) => `${e.content.title}. ${t}`,
|
|
9
|
+
actionPending: (e) => `${e.content.title}. ${e.content.action?.label}. In progress`,
|
|
10
|
+
resumed: (e) => `${e} current notifications`
|
|
11
|
+
};
|
|
12
|
+
function n(e, n, r, i) {
|
|
13
|
+
let a = null, o = null, s, c, l = !1, u = !1, d = null, f = null, p, m = r.defaultView, h = () => {
|
|
14
|
+
m?.clearTimeout(s), s = void 0;
|
|
15
|
+
}, g = () => {
|
|
16
|
+
if (!l) return;
|
|
17
|
+
let t = e.getSnapshot();
|
|
18
|
+
!t.notifications.length && !t.overflow.pending ? (h(), u = !1) : s === void 0 && r.visibilityState !== "hidden" && (s = m?.setTimeout(v, 300));
|
|
19
|
+
};
|
|
20
|
+
function _(r, ...a) {
|
|
21
|
+
try {
|
|
22
|
+
let e = (i()?.[r] ?? t[r])(...a);
|
|
23
|
+
if (typeof e != "string" || !e.trim()) throw TypeError("Announcement must be a nonempty string");
|
|
24
|
+
return e;
|
|
25
|
+
} catch (i) {
|
|
26
|
+
return e.reportDiagnostic(n, {
|
|
27
|
+
code: "formatter-error",
|
|
28
|
+
source: `Toaster.announcements.${r}`,
|
|
29
|
+
message: "Announcement formatter failed",
|
|
30
|
+
error: i
|
|
31
|
+
}), t[r](...a);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function v() {
|
|
35
|
+
if (s = void 0, !l || r.visibilityState === "hidden" || !a || !o) return;
|
|
36
|
+
let t = e.getSnapshot(), i = [], c = {
|
|
37
|
+
polite: [],
|
|
38
|
+
assertive: []
|
|
39
|
+
}, d = {
|
|
40
|
+
polite: 0,
|
|
41
|
+
assertive: 0
|
|
42
|
+
};
|
|
43
|
+
for (let e of t.notifications) {
|
|
44
|
+
let n = t.announcements.notifications.find((t) => t.handle === e.handle), r = e.handle, a = e.content.announcementPriority ?? "polite", o = t.presentation?.handle === r && t.presentation.readable, s = (e) => {
|
|
45
|
+
a !== "off" && !u && c[a].push(e());
|
|
46
|
+
};
|
|
47
|
+
if (e.location === "stack") {
|
|
48
|
+
if (n.queued || (i.push({
|
|
49
|
+
kind: "queued",
|
|
50
|
+
handle: r
|
|
51
|
+
}), a !== "off" && !n.firstPresentation && !u && d[a]++), !u) continue;
|
|
52
|
+
} else if (!o && !u) continue;
|
|
53
|
+
let l = e.location === "current" && o && !n.firstPresentation;
|
|
54
|
+
l && i.push({
|
|
55
|
+
kind: "first-presentation",
|
|
56
|
+
handle: r
|
|
57
|
+
});
|
|
58
|
+
let p = e.operation, m = !1;
|
|
59
|
+
if (p) {
|
|
60
|
+
let t = p.status === "pending" ? p.cancelRequested ? "cancel-requested" : "started" : p.status, a = n.operation?.token === p.token ? n.operation.phases : [];
|
|
61
|
+
for (let e of /* @__PURE__ */ new Set([
|
|
62
|
+
"started",
|
|
63
|
+
...p.cancelRequested ? ["cancel-requested"] : [],
|
|
64
|
+
t
|
|
65
|
+
])) a.includes(e) || i.push({
|
|
66
|
+
kind: "operation",
|
|
67
|
+
handle: r,
|
|
68
|
+
token: p.token,
|
|
69
|
+
phase: e
|
|
70
|
+
});
|
|
71
|
+
a.includes(t) || (s(() => _("operation", e, t)), m = !0);
|
|
72
|
+
}
|
|
73
|
+
l && !m ? s(() => _("notification", e)) : f === r && e.location === "current" && !m && a !== "off" && !u && c.polite.push(_("notification", e)), e.occurrences > n.occurrences && (i.push({
|
|
74
|
+
kind: "occurrences",
|
|
75
|
+
handle: r,
|
|
76
|
+
count: e.occurrences
|
|
77
|
+
}), !l && e.occurrences > 1 && s(() => _("occurrences", e)));
|
|
78
|
+
let h = e.action;
|
|
79
|
+
h.status !== "idle" && (n.action?.token !== h.token || n.action.status !== h.status) && (i.push({
|
|
80
|
+
kind: "action",
|
|
81
|
+
handle: r,
|
|
82
|
+
token: h.token,
|
|
83
|
+
status: h.status
|
|
84
|
+
}), s(() => h.status === "failed" ? _("actionError", e, h.message) : _("actionPending", e)));
|
|
85
|
+
}
|
|
86
|
+
for (let e of ["polite", "assertive"]) d[e] && c[e].push(_("queued", d[e]));
|
|
87
|
+
if (t.overflow.count > t.announcements.overflowCount && (i.push({
|
|
88
|
+
kind: "overflow",
|
|
89
|
+
count: t.overflow.count
|
|
90
|
+
}), u || c.polite.push(_("overflow", t.overflow.count))), u) {
|
|
91
|
+
for (let e of ["polite", "assertive"]) {
|
|
92
|
+
let n = t.notifications.filter((t) => (t.content.announcementPriority ?? "polite") === e).length;
|
|
93
|
+
n && c[e].push(_("resumed", n));
|
|
94
|
+
}
|
|
95
|
+
t.overflow.pending && c.polite.push(_("overflow", t.overflow.count));
|
|
96
|
+
}
|
|
97
|
+
if (l) {
|
|
98
|
+
if (e.getSnapshot() !== t) g();
|
|
99
|
+
else {
|
|
100
|
+
u = !1, f = null;
|
|
101
|
+
for (let [e, t] of [[a, c.polite], [o, c.assertive]]) {
|
|
102
|
+
if (!t.length) continue;
|
|
103
|
+
let n = t.join(". ");
|
|
104
|
+
e.textContent === n && (n += "\xA0"), e.replaceChildren(r.createTextNode(n));
|
|
105
|
+
}
|
|
106
|
+
e.acknowledgeAnnouncements(n, i);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function y() {
|
|
111
|
+
h(), r.visibilityState === "hidden" ? (a?.replaceChildren(), o?.replaceChildren()) : (u = !0, g());
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
mount(t) {
|
|
115
|
+
l = !0;
|
|
116
|
+
let n = (e) => {
|
|
117
|
+
let t = r.createElement("div");
|
|
118
|
+
return t.className = "cloudlet-announcer", t.dataset.cloudletAnnouncer = e, t.setAttribute("aria-live", e), t.setAttribute("aria-atomic", "true"), t;
|
|
119
|
+
};
|
|
120
|
+
a = n("polite"), o = n("assertive"), t.after(a, o), p = m?.requestAnimationFrame?.(() => {
|
|
121
|
+
p = void 0, a && o && t.after(a, o);
|
|
122
|
+
}), c = e.onEvent((t) => {
|
|
123
|
+
t.type === "presented" && (!t.firstPresentation && d !== null && t.handle !== d && e.getSnapshot().island.open && (f = t.handle), d = t.handle), t.type !== "updated" && t.type !== "diagnostic" && g();
|
|
124
|
+
}), r.addEventListener("visibilitychange", y), g();
|
|
125
|
+
},
|
|
126
|
+
dispose() {
|
|
127
|
+
l = !1, h(), c?.(), r.removeEventListener("visibilitychange", y), p !== void 0 && m?.cancelAnimationFrame(p), a?.remove(), o?.remove(), a = o = null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { n as createAnnouncer };
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=announcer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announcer.js","names":["content","value","defaults","count","item","message","createAnnouncer","polite","assertive","timer","unsubscribe","mounted","resumed","shown","revisit","reinsert","view","doc","cancel","schedule","snapshot","bridge","flush","format","args","options","key","error","lease","acks","messages","queued","ledger","handle","priority","readable","say","text","first","operation","operationText","phase","phases","current","action","host","lines","visibility","region","element","event"],"sources":["../../src/react/announcer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { AnnouncementAcknowledgement, HostLease, OperationAnnouncementPhase, RendererBridge } from '../contracts/internal.js';\nimport type { NotificationHandle } from '../contracts/identity.js';\nimport type { NotificationSnapshot } from '../contracts/snapshots.js';\nimport type { AnnouncementFormatters } from '../react.js';\n\ntype Notification = NotificationSnapshot<ReactNode>;\nconst content = ({ content: value }: Notification) => [value.title,\n value.description?.kind === 'rich' ? value.description.announcement : value.description?.text,\n].filter(Boolean).join('. ');\n\nconst defaults: Required<AnnouncementFormatters> = {\n notification: content,\n queued: count => `${count} notifications queued`,\n occurrences: item => `${item.content.title}. ${item.occurrences} occurrences`,\n overflow: count => `${count} missed notifications`,\n operation: content,\n actionError: (item, message) => `${item.content.title}. ${message}`,\n actionPending: item => `${item.content.title}. ${item.content.action?.label}. In progress`,\n resumed: count => `${count} current notifications`,\n};\n\n/** One attachment, two existing live hosts, one fixed batch window. No event history. */\nexport function createAnnouncer(bridge: RendererBridge<ReactNode>, lease: HostLease, doc: Document,\n options: () => Partial<AnnouncementFormatters> | undefined) {\n let polite: Element | null = null;\n let assertive: Element | null = null;\n let timer: number | undefined;\n let unsubscribe: (() => void) | undefined;\n let mounted = false;\n let resumed = false;\n /** The record last presented, and one shown again inside the open Island (a slide back, or the next after a close). */\n let shown: NotificationHandle | null = null;\n let revisit: NotificationHandle | null = null;\n let reinsert: number | undefined;\n const view = doc.defaultView;\n const cancel = () => { view?.clearTimeout(timer); timer = undefined; };\n const schedule = () => {\n if (!mounted) return;\n const snapshot = bridge.getSnapshot();\n if (!snapshot.notifications.length && !snapshot.overflow.pending) { cancel(); resumed = false; return; }\n if (timer === undefined && doc.visibilityState !== 'hidden') timer = view?.setTimeout(flush, 300);\n };\n function format<K extends keyof AnnouncementFormatters>(key: K,\n ...args: Parameters<Required<AnnouncementFormatters>[K]>): string {\n // The correlated tuple is preserved at all callers; the cast is local to dispatch.\n type Formatter = (...values: typeof args) => string;\n try {\n const text = (options()?.[key] ?? defaults[key]) as Formatter;\n const value = text(...args);\n if (typeof value !== 'string' || !value.trim()) throw new TypeError('Announcement must be a nonempty string');\n return value;\n } catch (error) {\n bridge.reportDiagnostic(lease, { code: 'formatter-error', source: `Toaster.announcements.${key}`,\n message: 'Announcement formatter failed', error });\n return (defaults[key] as Formatter)(...args);\n }\n }\n function flush() {\n timer = undefined;\n if (!mounted || doc.visibilityState === 'hidden' || !polite || !assertive) return;\n const snapshot = bridge.getSnapshot();\n const acks: AnnouncementAcknowledgement[] = [];\n const messages = { polite: [] as string[], assertive: [] as string[] };\n const queued = { polite: 0, assertive: 0 };\n for (const item of snapshot.notifications) {\n const ledger = snapshot.announcements.notifications.find(value => value.handle === item.handle)!;\n const handle = item.handle;\n const priority = item.content.announcementPriority ?? 'polite';\n const readable = snapshot.presentation?.handle === handle && snapshot.presentation.readable;\n const say = (text: () => string) => { if (priority !== 'off' && !resumed) messages[priority].push(text()); };\n // Stack records behind the presented one speak only as an aggregate, like a queue.\n if (item.location === 'stack') {\n if (!ledger.queued) {\n acks.push({ kind: 'queued', handle });\n if (priority !== 'off' && !ledger.firstPresentation && !resumed) queued[priority]++;\n }\n // Queued payloads/progress never speak; first presentation reads the latest state.\n if (!resumed) continue;\n } else if (!readable && !resumed) continue;\n\n const first = item.location === 'current' && readable && !ledger.firstPresentation;\n if (first) acks.push({ kind: 'first-presentation', handle });\n const operation = item.operation;\n let operationText = false;\n if (operation) {\n const phase = operation.status === 'pending' ? operation.cancelRequested ? 'cancel-requested' : 'started' : operation.status;\n const phases = ledger.operation?.token === operation.token ? ledger.operation.phases : [];\n for (const current of new Set<OperationAnnouncementPhase>(['started', ...(operation.cancelRequested ? ['cancel-requested' as const] : []), phase])) {\n if (!phases.includes(current)) acks.push({ kind: 'operation', handle, token: operation.token, phase: current });\n }\n if (!phases.includes(phase)) { say(() => format('operation', item, phase)); operationText = true; }\n }\n if (first && !operationText) say(() => format('notification', item));\n // The title node is shared by every slide, so focus never moves when a slide comes back:\n // speak the record once more so a screen reader hears where the user landed.\n else if (revisit === handle && item.location === 'current' && !operationText && priority !== 'off' && !resumed) {\n messages.polite.push(format('notification', item));\n }\n if (item.occurrences > ledger.occurrences) {\n acks.push({ kind: 'occurrences', handle, count: item.occurrences });\n if (!first && item.occurrences > 1) say(() => format('occurrences', item));\n }\n const action = item.action;\n if (action.status !== 'idle' && (ledger.action?.token !== action.token || ledger.action.status !== action.status)) {\n acks.push({ kind: 'action', handle, token: action.token, status: action.status });\n say(() => action.status === 'failed' ? format('actionError', item, action.message) : format('actionPending', item));\n }\n }\n for (const priority of ['polite', 'assertive'] as const) {\n if (queued[priority]) messages[priority].push(format('queued', queued[priority]));\n }\n if (snapshot.overflow.count > snapshot.announcements.overflowCount) {\n acks.push({ kind: 'overflow', count: snapshot.overflow.count });\n if (!resumed) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n if (resumed) {\n for (const priority of ['polite', 'assertive'] as const) {\n const count = snapshot.notifications.filter(item => (item.content.announcementPriority ?? 'polite') === priority).length;\n if (count) messages[priority].push(format('resumed', count));\n }\n if (snapshot.overflow.pending) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n // A user formatter/diagnostic can reenter the controller. Never deliver its stale batch.\n if (!mounted) return;\n if (bridge.getSnapshot() !== snapshot) { schedule(); return; }\n resumed = false;\n revisit = null;\n for (const [host, lines] of [[polite, messages.polite], [assertive, messages.assertive]] as const) {\n if (!lines.length) continue;\n let text = lines.join('. ');\n // The same message again (a second failed attempt) would leave the region unchanged and silent;\n // a trailing no-break space makes it a change without changing what is spoken.\n if (host.textContent === text) text += '\\u00a0';\n host.replaceChildren(doc.createTextNode(text));\n }\n bridge.acknowledgeAnnouncements(lease, acks);\n }\n function visibility() {\n cancel();\n if (doc.visibilityState === 'hidden') {\n polite?.replaceChildren(); assertive?.replaceChildren();\n } else { resumed = true; schedule(); }\n }\n return {\n /**\n * The announcer owns its live regions: created here, next to the host (React owns the host's\n * children), and inserted twice. VoiceOver in Safari ignored assertive changes made while focus\n * was in the open Island in regions inserted only once (0 of 6 runs), and spoke them after one\n * re-insertion on the next frame (6 of 6, rc.2 gate); a zero timeout was not enough (3 of 5).\n */\n mount(host: HTMLElement) {\n mounted = true;\n const region = (priority: 'polite' | 'assertive') => {\n const element = doc.createElement('div');\n element.className = 'cloudlet-announcer';\n element.dataset.cloudletAnnouncer = priority;\n element.setAttribute('aria-live', priority);\n element.setAttribute('aria-atomic', 'true');\n return element;\n };\n polite = region('polite');\n assertive = region('assertive');\n host.after(polite, assertive);\n reinsert = view?.requestAnimationFrame?.(() => {\n reinsert = undefined;\n if (polite && assertive) host.after(polite, assertive);\n });\n unsubscribe = bridge.onEvent(event => {\n if (event.type === 'presented') {\n if (!event.firstPresentation && shown !== null && event.handle !== shown && bridge.getSnapshot().island.open) revisit = event.handle;\n shown = event.handle;\n }\n // Updated includes progress, reflow and ordinary text edits, not a new semantic phase.\n if (event.type !== 'updated' && event.type !== 'diagnostic') schedule();\n });\n doc.addEventListener('visibilitychange', visibility);\n schedule();\n },\n dispose() {\n mounted = false;\n cancel(); unsubscribe?.();\n doc.removeEventListener('visibilitychange', visibility);\n if (reinsert !== undefined) view?.cancelAnimationFrame(reinsert);\n polite?.remove(); assertive?.remove();\n polite = assertive = null;\n },\n };\n}\n"],"mappings":";AAOA,IAAMA,KAAW,EAAE,SAASC,QAA0B,CAACA,EAAM,OAC3DA,EAAM,aAAa,SAAS,SAASA,EAAM,YAAY,eAAeA,EAAM,aAAa,IAC3F,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,GAErBC,IAA6C;CACjD,cAAcF;CACd,SAAQ,MAAS,GAAGG,EAAM;CAC1B,cAAa,MAAQ,GAAGC,EAAK,QAAQ,MA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AM,8BAA8B;IAE7C,AADA,IAAW,KAAA,GACPT,KAAUC,KAAWqC,EAAK,MAAMtC,GAAQC,CAAS;GACvD,CAAC,GACD,IAAca,EAAO,SAAQ,MAAS;IAMpC,AALI6B,EAAM,SAAS,gBACb,CAACA,EAAM,qBAAqBrC,MAAU,QAAQqC,EAAM,WAAWrC,KAASQ,EAAO,YAAY,CAAC,CAAC,OAAO,SAAM,IAAU6B,EAAM,SAC9H,IAAQA,EAAM,SAGZA,EAAM,SAAS,aAAaA,EAAM,SAAS,gBAAc/B,EAAS;GACxE,CAAC,GACDF,EAAI,iBAAiB,oBAAoB8B,CAAU,GACnD5B,EAAS;EACX;EACA,UAAU;GAMR,AALA,IAAU,IACVD,EAAO,GAAGR,IAAc,GACxBO,EAAI,oBAAoB,oBAAoB8B,CAAU,GAClDhC,MAAa,KAAA,KAAWC,GAAM,qBAAqBD,CAAQ,GAC/DR,GAAQ,OAAO,GAAGC,GAAW,OAAO,GACpC,IAAS,IAAY;EACvB;CACF;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { CloudletProviderProps, ReactCloudletController, ToasterProps } from '../react.js';
|
|
3
|
+
export declare function CloudletProvider({ controller, children }: CloudletProviderProps): ReactElement;
|
|
4
|
+
export declare function useCloudlet(): ReactCloudletController;
|
|
5
|
+
/** The controller, or null outside a provider and while the provider's controller is null. */
|
|
6
|
+
export declare function useOptionalCloudlet(): ReactCloudletController | null;
|
|
7
|
+
export declare function Toaster(options: ToasterProps): ReactElement | null;
|
|
8
|
+
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/react/bindings.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAShG,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAE9F;AAED,wBAAgB,WAAW,IAAI,uBAAuB,CAIrD;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,IAAI,uBAAuB,GAAG,IAAI,CAEpE;AASD,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAKlE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getRendererBridge as e } from "../core/controller.js";
|
|
2
|
+
import { Host as t } from "./host.js";
|
|
3
|
+
import { createContext as n, useContext as r, useEffect as i, useRef as a, useState as o, useSyncExternalStore as s } from "react";
|
|
4
|
+
import { createPortal as c } from "react-dom";
|
|
5
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
6
|
+
//#region src/react/bindings.tsx
|
|
7
|
+
var f = n(void 0), p = () => () => {}, m = () => !0, h = () => !1;
|
|
8
|
+
function g({ controller: e, children: t }) {
|
|
9
|
+
return /* @__PURE__ */ u(f.Provider, {
|
|
10
|
+
value: e,
|
|
11
|
+
children: t
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function _() {
|
|
15
|
+
let e = r(f);
|
|
16
|
+
if (!e) throw Error("useCloudlet must be used within a CloudletProvider that has a controller");
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
function v() {
|
|
20
|
+
return r(f) ?? null;
|
|
21
|
+
}
|
|
22
|
+
function y(e) {
|
|
23
|
+
let t = r(f);
|
|
24
|
+
if (t === void 0) throw Error("Toaster must be used within a CloudletProvider");
|
|
25
|
+
return t ? /* @__PURE__ */ u(b, {
|
|
26
|
+
controller: t,
|
|
27
|
+
options: e
|
|
28
|
+
}) : null;
|
|
29
|
+
}
|
|
30
|
+
function b({ controller: n, options: r }) {
|
|
31
|
+
let f = s(p, m, h), g = e(n), _ = s(g.subscribe, g.getSnapshot, g.getServerSnapshot), v = a(null), [y, b] = o(null);
|
|
32
|
+
i(() => {
|
|
33
|
+
if (!f || !v.current) return;
|
|
34
|
+
let e = v.current.ownerDocument, t;
|
|
35
|
+
try {
|
|
36
|
+
let n = (typeof r.container == "function" ? r.container() : r.container) ?? e.body;
|
|
37
|
+
if (!n || n.nodeType !== 1 || n.ownerDocument !== e || n.namespaceURI !== "http://www.w3.org/1999/xhtml" || !n.isConnected || n.getRootNode().nodeType === 11) {
|
|
38
|
+
g.reportInvalidContainer("Toaster container must be a connected HTML Element in the mounting document, outside Shadow DOM");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
t = n;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
g.reportInvalidContainer("Toaster container resolver failed", e);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let i = r.attention?.delay, a = g.attach(i === void 0 ? void 0 : { attentionDelay: i }), o = a.status === "rejected" && a.reason === "invalid-input";
|
|
47
|
+
if (o && (a = g.attach()), a.status !== "attached") return;
|
|
48
|
+
o && g.reportDiagnostic(a.lease, {
|
|
49
|
+
code: "invalid-input",
|
|
50
|
+
source: "Toaster.attention",
|
|
51
|
+
message: "attention.delay must be a finite nonnegative number of milliseconds"
|
|
52
|
+
});
|
|
53
|
+
let s = {
|
|
54
|
+
controller: n,
|
|
55
|
+
lease: a.lease,
|
|
56
|
+
container: t,
|
|
57
|
+
document: e
|
|
58
|
+
};
|
|
59
|
+
return x(s.lease, !1), b(s), () => {
|
|
60
|
+
g.detach(s.lease);
|
|
61
|
+
};
|
|
62
|
+
}, [n, f]);
|
|
63
|
+
function x(e, t) {
|
|
64
|
+
let n = r.autoDismiss, i = n === void 0 || typeof n == "boolean";
|
|
65
|
+
g.setAutoDismiss(e, i ? n : void 0), !i && t && g.reportDiagnostic(e, {
|
|
66
|
+
code: "invalid-input",
|
|
67
|
+
source: "Toaster.autoDismiss",
|
|
68
|
+
message: "autoDismiss must be a boolean"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return i(() => {
|
|
72
|
+
y && x(y.lease, !0);
|
|
73
|
+
}, [y, r.autoDismiss]), f ? /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("template", { ref: v }), y?.controller === n && !_.disposed ? c(/* @__PURE__ */ u(t, {
|
|
74
|
+
bridge: g,
|
|
75
|
+
lease: y.lease,
|
|
76
|
+
snapshot: _,
|
|
77
|
+
options: r,
|
|
78
|
+
document: y.document
|
|
79
|
+
}, y.lease), y.container) : null] }) : null;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { g as CloudletProvider, y as Toaster, _ as useCloudlet, v as useOptionalCloudlet };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.js","names":["_Fragment","CloudletContext","createContext","subscribeMount","clientMounted","serverMounted","CloudletProvider","controller","useCloudlet","useContext","useOptionalCloudlet","Toaster","AttachedToaster","mounted","useSyncExternalStore","bridge","getRendererBridge","snapshot","marker","useRef","attachment","setAttachment","useState","ownerDocument","container","candidate","options","error","delay","attached","invalidDelay","current","applyAutoDismiss","value","valid","lease","report","useEffect","Fragment","createPortal","Host"],"sources":["../../src/react/bindings.tsx"],"sourcesContent":["import { createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from 'react';\nimport type { ReactElement } from 'react';\nimport { createPortal } from 'react-dom';\nimport { getRendererBridge } from '../core/controller.js';\nimport type { HostLease } from '../contracts/internal.js';\nimport type { CloudletProviderProps, ReactCloudletController, ToasterProps } from '../react.js';\nimport { Host } from './host.js';\n\n/** Undefined outside a provider; null inside one whose controller does not exist yet. */\nconst CloudletContext = createContext<ReactCloudletController | null | undefined>(undefined);\nconst subscribeMount = () => () => {};\nconst clientMounted = () => true;\nconst serverMounted = () => false;\n\nexport function CloudletProvider({ controller, children }: CloudletProviderProps): ReactElement {\n return <CloudletContext.Provider value={controller}>{children}</CloudletContext.Provider>;\n}\n\nexport function useCloudlet(): ReactCloudletController {\n const controller = useContext(CloudletContext);\n if (!controller) throw new Error('useCloudlet must be used within a CloudletProvider that has a controller');\n return controller;\n}\n\n/** The controller, or null outside a provider and while the provider's controller is null. */\nexport function useOptionalCloudlet(): ReactCloudletController | null {\n return useContext(CloudletContext) ?? null;\n}\n\ninterface Attachment {\n readonly controller: ReactCloudletController;\n readonly lease: HostLease;\n readonly container: Element;\n readonly document: Document;\n}\n\nexport function Toaster(options: ToasterProps): ReactElement | null {\n const controller = useContext(CloudletContext);\n if (controller === undefined) throw new Error('Toaster must be used within a CloudletProvider');\n // A provider without a controller yet (server, first client render) renders nothing.\n return controller ? <AttachedToaster controller={controller} options={options} /> : null;\n}\n\nfunction AttachedToaster({ controller, options }: { controller: ReactCloudletController; options: ToasterProps }): ReactElement | null {\n // React supplies the server value during hydration, then the client value.\n // The inert marker can therefore identify the owner document without a store\n // or effect whose only purpose is an extra mounting render.\n const mounted = useSyncExternalStore(subscribeMount, clientMounted, serverMounted);\n const bridge = getRendererBridge(controller);\n const snapshot = useSyncExternalStore(bridge.subscribe, bridge.getSnapshot, bridge.getServerSnapshot);\n const marker = useRef<HTMLTemplateElement>(null);\n const [attachment, setAttachment] = useState<Attachment | null>(null);\n useEffect(() => {\n if (!mounted || !marker.current) return;\n const ownerDocument = marker.current.ownerDocument;\n let container: Element;\n try {\n const requested = typeof options.container === 'function' ? options.container() : options.container;\n const candidate = requested ?? ownerDocument.body;\n // nodeType/ownerDocument also work when the mounting React root is in another realm.\n if (!candidate || candidate.nodeType !== 1 || candidate.ownerDocument !== ownerDocument\n || candidate.namespaceURI !== 'http://www.w3.org/1999/xhtml' || !candidate.isConnected\n || candidate.getRootNode().nodeType === 11) {\n bridge.reportInvalidContainer('Toaster container must be a connected HTML Element in the mounting document, outside Shadow DOM');\n return;\n }\n container = candidate;\n } catch (error) {\n bridge.reportInvalidContainer('Toaster container resolver failed', error);\n return;\n }\n const delay = options.attention?.delay;\n let attached = bridge.attach(delay === undefined ? undefined : { attentionDelay: delay });\n // An invalid delay must not suppress the host: fall back to the controller default and report it.\n const invalidDelay = attached.status === 'rejected' && attached.reason === 'invalid-input';\n if (invalidDelay) attached = bridge.attach();\n if (attached.status !== 'attached') return;\n if (invalidDelay) bridge.reportDiagnostic(attached.lease, { code: 'invalid-input', source: 'Toaster.attention',\n message: 'attention.delay must be a finite nonnegative number of milliseconds' });\n const current = { controller, lease: attached.lease, container, document: ownerDocument };\n applyAutoDismiss(current.lease, false);\n setAttachment(current);\n return () => { bridge.detach(current.lease); };\n // Container and attention delay are fixed for this attachment; changing them requires remount.\n }, [controller, mounted]);\n // Applied before the first presentation, then whenever the prop changes (which reports an invalid value once).\n function applyAutoDismiss(lease: HostLease, report: boolean) {\n const value = options.autoDismiss;\n const valid = value === undefined || typeof value === 'boolean';\n bridge.setAutoDismiss(lease, valid ? value : undefined);\n if (!valid && report) bridge.reportDiagnostic(lease, { code: 'invalid-input', source: 'Toaster.autoDismiss',\n message: 'autoDismiss must be a boolean' });\n }\n useEffect(() => { if (attachment) applyAutoDismiss(attachment.lease, true); }, [attachment, options.autoDismiss]);\n\n if (!mounted) return null;\n return <><template ref={marker} />{attachment?.controller === controller && !snapshot.disposed\n ? createPortal(<Host key={attachment.lease} bridge={bridge} lease={attachment.lease} snapshot={snapshot}\n options={options} document={attachment.document} />, attachment.container) : null}</>;\n}\n"],"mappings":";;;;;;AASA,IAAMC,IAAkBC,EAA0D,KAAA,CAAS,GACrFC,gBAA6B,CAAC,GAC9BC,UAAsB,IACtBC,UAAsB;AAE5B,SAAgBC,EAAiB,EAAE,eAAY,eAAiD;CAC9F,OAAO,kBAACL,EAAgB,UAAjB;EAA0B,OAAOM;EAAa;CAAmC,CAAA;AAC1F;AAEA,SAAgBC,IAAuC;CACrD,IAAMD,IAAaE,EAAWR,CAAe;CAC7C,IAAI,CAACM,GAAY,MAAU,MAAM,0EAA0E;CAC3G,OAAOA;AACT;AAGA,SAAg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AAM;GAAiB,QAAQ;GACzF,SAAS;EAAsE,CAAC;EAClF,IAAME,IAAU;GAAE;GAAY,OAAOF,EAAS;GAAO;GAAW,UAAUN;EAAc;EAGxF,OAFAS,EAAiBD,EAAQ,OAAO,EAAK,GACrCV,EAAcU,CAAO,SACR;GAAE,EAAO,OAAOA,EAAQ,KAAK;EAAG;CAE/C,GAAG,CAACxB,GAAYM,CAAO,CAAC;CAExB,SAASmB,EAAiB,GAAkB,GAAiB;EAC3D,IAAMC,IAAQP,EAAQ,aAChBQ,IAAQD,MAAU,KAAA,KAAa,OAAOA,KAAU;EAEtD,AADAlB,EAAO,eAAeoB,GAAOD,IAAQD,IAAQ,KAAA,CAAS,GAClD,CAACC,KAASE,KAAQrB,EAAO,iBAAiBoB,GAAO;GAAE,MAAM;GAAiB,QAAQ;GACpF,SAAS;EAAgC,CAAC;CAC9C;CAIA,OAHAE,QAAgB;EAAE,AAAIjB,KAAYY,EAAiBZ,EAAW,OAAO,EAAI;CAAG,GAAG,CAACA,GAAYM,EAAQ,WAAW,CAAC,GAE3Gb,IACE,kBAAAb,GAAA,EAAA,UAAA,CAAE,kBAAC,YAAD,EAAU,KAAKkB,EAAS,CAAA,GAAEE,GAAY,eAAeb,KAAc,CAACU,EAAS,WAClFsB,EAAa,kBAACC,GAAD;EAAqC;EAAQ,OAAOpB,EAAW;EAAiB;EACpF;EAAS,UAAUA,EAAW;CAAW,GAD1BA,EAAW,KACe,GAAGA,EAAW,SAAS,IAAI,IAAO,EAAA,CAAA,IAHnE;AAIvB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { HostLease, RendererBridge } from '../contracts/internal.js';
|
|
3
|
+
import type { NotificationHandle } from '../contracts/identity.js';
|
|
4
|
+
import type { NotificationSnapshot } from '../contracts/snapshots.js';
|
|
5
|
+
import type { CloudletLabels, CloudletPart, ToasterProps } from '../react.js';
|
|
6
|
+
export declare const defaultLabels: CloudletLabels;
|
|
7
|
+
/** Adds the application's `classNames` part to an own `cloudlet-*` class, never replacing it. */
|
|
8
|
+
export type PartClass = (part: CloudletPart, own: string) => string;
|
|
9
|
+
export declare function partClasses(classNames: ToasterProps['classNames']): PartClass;
|
|
10
|
+
/**
|
|
11
|
+
* The status icon: a 24 px tinted circle with a glyph, the loading spinner or the
|
|
12
|
+
* notification's own icon, and the 2 px progress ring around it (pill and Island
|
|
13
|
+
* share these nodes). With progress the icon is the accessible progressbar. The
|
|
14
|
+
* determinate arc is owned by the host sampler (one RAF per host, 240 ms tween);
|
|
15
|
+
* `preview` draws the value statically for the inert swipe neighbour.
|
|
16
|
+
*/
|
|
17
|
+
export declare function StatusIcon({ notification, slot, part, preview }: {
|
|
18
|
+
notification: NotificationSnapshot<ReactNode>;
|
|
19
|
+
slot: (value: ReactNode) => ReactNode;
|
|
20
|
+
part: PartClass;
|
|
21
|
+
preview?: boolean;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
export declare function slotRenderer(bridge: RendererBridge<ReactNode>, lease: HostLease, handle: NotificationHandle, rejectSlotFocus: (previous: EventTarget | null) => void): (value: ReactNode) => import("react").JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* Status icon and title: the same DOM nodes in the pill and in the Island header,
|
|
26
|
+
* so opening never re-creates them and the title can receive focus in place.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Heading({ notification, slot, part, titleId }: {
|
|
29
|
+
notification: NotificationSnapshot<ReactNode>;
|
|
30
|
+
slot: (value: ReactNode) => ReactNode;
|
|
31
|
+
part: PartClass;
|
|
32
|
+
/** Omitted for the inert neighbour preview: no id, focus target, data hook or live progress. */
|
|
33
|
+
titleId?: string;
|
|
34
|
+
}): import("react").JSX.Element;
|
|
35
|
+
/** Rich content of the inert neighbour preview: rendered as is, never checked or reported twice. */
|
|
36
|
+
export declare const previewSlot: (value: ReactNode) => import("react").JSX.Element;
|
|
37
|
+
/**
|
|
38
|
+
* The neighbour shown only while a finger drags the Island content (DESIGN §3, §9):
|
|
39
|
+
* the same layout as a live slide, but every control is a lookalike without
|
|
40
|
+
* handlers, ids, links or tab stops. The caller puts it in an `inert` container.
|
|
41
|
+
*/
|
|
42
|
+
export declare function SlidePreview({ notification, labels, part }: {
|
|
43
|
+
notification: NotificationSnapshot<ReactNode>;
|
|
44
|
+
labels: CloudletLabels;
|
|
45
|
+
part: PartClass;
|
|
46
|
+
}): import("react").JSX.Element;
|
|
47
|
+
/** Island slide body: description, progress, actions and the action error. */
|
|
48
|
+
export declare function Body({ notification, bridge, lease, labels, navigate, slot, part }: {
|
|
49
|
+
notification: NotificationSnapshot<ReactNode>;
|
|
50
|
+
bridge: RendererBridge<ReactNode>;
|
|
51
|
+
lease: HostLease;
|
|
52
|
+
labels: CloudletLabels;
|
|
53
|
+
navigate: (handle: NotificationHandle) => void;
|
|
54
|
+
slot: (value: ReactNode) => ReactNode;
|
|
55
|
+
part: PartClass;
|
|
56
|
+
}): import("react").JSX.Element;
|
|
57
|
+
export declare function closeButton(labels: CloudletLabels, part: PartClass, onClick: () => void): import("react").JSX.Element;
|
|
58
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/react/card.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9E,eAAO,MAAM,aAAa,EAAE,cAS3B,CAAC;AA4DF,iGAAiG;AACjG,MAAM,MAAM,SAAS,GAAG,CAAC,IAA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