@cloudlet/toast 1.3.0 → 1.4.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +27 -1
  3. package/dist/agent.d.ts +334 -0
  4. package/dist/agent.d.ts.map +1 -0
  5. package/dist/agent.js +494 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/contracts/events.d.ts +14 -0
  8. package/dist/contracts/events.d.ts.map +1 -1
  9. package/dist/contracts/internal.d.ts +16 -2
  10. package/dist/contracts/internal.d.ts.map +1 -1
  11. package/dist/contracts/notifications.d.ts +16 -0
  12. package/dist/contracts/notifications.d.ts.map +1 -1
  13. package/dist/contracts/snapshots.d.ts +8 -0
  14. package/dist/contracts/snapshots.d.ts.map +1 -1
  15. package/dist/core/actions.d.ts +69 -0
  16. package/dist/core/actions.d.ts.map +1 -0
  17. package/dist/core/actions.js +160 -0
  18. package/dist/core/actions.js.map +1 -0
  19. package/dist/core/agent-port.d.ts +116 -0
  20. package/dist/core/agent-port.d.ts.map +1 -0
  21. package/dist/core/agent-port.js +138 -0
  22. package/dist/core/agent-port.js.map +1 -0
  23. package/dist/core/bridge.d.ts.map +1 -1
  24. package/dist/core/bridge.js +120 -231
  25. package/dist/core/bridge.js.map +1 -1
  26. package/dist/core/controller.d.ts +44 -9
  27. package/dist/core/controller.d.ts.map +1 -1
  28. package/dist/core/controller.js +367 -292
  29. package/dist/core/controller.js.map +1 -1
  30. package/dist/core/validation.d.ts.map +1 -1
  31. package/dist/core/validation.js +103 -94
  32. package/dist/core/validation.js.map +1 -1
  33. package/dist/react/card.d.ts.map +1 -1
  34. package/dist/react/card.js +3 -3
  35. package/dist/react/card.js.map +1 -1
  36. package/dist/react/host.d.ts.map +1 -1
  37. package/dist/react/host.js +257 -246
  38. package/dist/react/host.js.map +1 -1
  39. package/dist/react.d.ts +7 -0
  40. package/dist/react.d.ts.map +1 -1
  41. package/package.json +2 -1
  42. package/src/agent.ts +879 -0
  43. package/src/contracts/events.ts +15 -0
  44. package/src/contracts/internal.ts +14 -1
  45. package/src/contracts/notifications.ts +16 -0
  46. package/src/contracts/snapshots.ts +8 -0
  47. package/src/core/actions.ts +149 -0
  48. package/src/core/agent-port.ts +237 -0
  49. package/src/core/bridge.ts +19 -105
  50. package/src/core/controller.ts +183 -56
  51. package/src/core/validation.ts +6 -3
  52. package/src/react/card.tsx +4 -3
  53. package/src/react/host.tsx +26 -3
  54. package/src/react.ts +7 -0
@@ -2,7 +2,8 @@ import { copyContent as e, patchContent as t, validateContent as n, validateOpti
2
2
  var s = Object.freeze, c = /* @__PURE__ */ new WeakSet(), l = /* @__PURE__ */ new WeakMap(), u = 0, d = s([]), f = s({
3
3
  open: !1,
4
4
  reason: null,
5
- current: null
5
+ current: null,
6
+ source: null
6
7
  }), p = s({
7
8
  controller: null,
8
9
  revision: 0,
@@ -40,54 +41,56 @@ function x(d, m) {
40
41
  if (!m?.clock || typeof m.clock.now != "function" || typeof m.clock.schedule != "function") throw TypeError("Cloudlet requires a monotonic clock");
41
42
  let x = m.clock;
42
43
  if (typeof m.createCancellation != "function") throw TypeError("Cloudlet requires a cancellation source factory");
43
- let S = `cloudlet-${++u}`, C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Set(), O = [], k = null, A = null, j = null, M = null, N = 0, ee = 0, P = 0, te = 0, F = null, I = null, L, R, z = null, B = null, ne = 0, V = 0, H = 0, U = !1, re = !1, ie = null, ae = 0, oe, se, W = () => `${S}:${++N}`, ce = () => [...C.values()].reverse(), le = () => ce()[0] ?? null, ue = (e) => {
44
+ let S = `cloudlet-${++u}`, C = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set(), D = [], O = null, k = null, A = null, j = null, te = 0, ne = 0, M = 0, re = 0, N = null, P = null, F = null, I = null, L, R, z = null, B = null, ie = 0, V = null, H = null, ae = 0, U = 0, W = 0, G = !1, oe = !1, se = null, ce = 0, le, ue, K = () => `${S}:${++te}`, de = () => [...C.values()].reverse(), fe = () => de()[0] ?? null, pe = (e) => {
44
45
  let t = e.operation?.getSnapshot();
45
46
  return !!t?.canRetry && t.status !== "fulfilled";
46
- }, de = (e) => !!e.content.action || ue(e) || e.content.attention === "open", fe = (e) => {
47
+ }, me = (e) => !!e.content.action || pe(e) || e.content.attention === "open", he = (e) => {
47
48
  let t = e.content.attention ?? "auto";
48
- return t === "open" || t === "auto" && (de(e) || !!e.content.description);
49
- }, pe = (e) => {
49
+ return t === "open" || t === "auto" && (me(e) || !!e.content.description);
50
+ }, ge = (e) => {
50
51
  let t = e.content.action;
51
52
  return t?.kind === "form" ? (e.form?.action !== t && (e.form = {
52
53
  action: t,
53
54
  errors: g,
54
- values: s(Object.fromEntries(t.fields.map((e) => [e.name, e.defaultValue ?? ""])))
55
+ values: s(Object.fromEntries(t.fields.map((e) => [e.name, e.defaultValue ?? ""]))),
56
+ authors: s(Object.fromEntries(t.fields.flatMap((e) => e.defaultValue ? [[e.name, "app"]] : [])))
55
57
  }), e.form) : e.form = null;
56
- }, me = (e) => {
57
- let t = pe(e);
58
- return !!t && t.action.fields.some((e) => t.values[e.name] !== (e.defaultValue ?? ""));
59
- }, he = () => D.has("hover") || D.has("focus") || [...C.values()].some((e) => e.pauses.has("gesture")) || !!F && me(F.current), ge = (e) => {
58
+ }, _e = (e) => {
59
+ let t = ge(e);
60
+ return !!t && t.action.fields.some((e) => (Object.hasOwn(t.values, e.name) ? t.values[e.name] : "") !== (e.defaultValue ?? ""));
61
+ }, q = () => E.has("hover") || E.has("focus") || [...C.values()].some((e) => e.pauses.has("gesture")) || !!N && _e(N.current), ve = (e) => {
60
62
  let t = e === I;
61
63
  return [
62
64
  ...t ? [] : ["inactive"],
63
- ...j === null ? ["no-host"] : [],
65
+ ...A === null ? ["no-host"] : [],
64
66
  ...t && !e.readable ? ["presentation-pending"] : [],
65
- ...t && F && (F.reason === "user" || de(e)) ? ["island"] : [],
67
+ ...t && N && (N.reason === "user" || me(e)) ? ["island"] : [],
66
68
  ...e.action.status === "pending" ? ["action-pending"] : [],
67
- ...me(e) ? ["draft"] : [],
68
- ...D,
69
+ ..._e(e) ? ["draft"] : [],
70
+ ...E,
69
71
  ...e.pauses
70
72
  ];
71
- }, _e = (e) => {
72
- if (U) return "disposed";
73
+ }, ye = (e) => {
74
+ if (G) return "disposed";
73
75
  if (typeof e != "object" || !e || !c.has(e)) return "invalid-handle";
74
76
  if (e.controller !== S) return "foreign-controller";
75
77
  if (C.get(e.id)?.handle !== e) return "stale-handle";
76
78
  };
77
- function ve(e) {
79
+ function be(e) {
78
80
  return (t, ...n) => {
79
- let r = _e(t);
81
+ let r = ye(t);
80
82
  return r ? y(r) : e(C.get(t.id), ...n);
81
83
  };
82
84
  }
83
- function G(e) {
84
- q([{
85
+ function J(e) {
86
+ Se([{
85
87
  type: "diagnostic",
88
+ source: "system",
86
89
  diagnostic: s({ ...e })
87
90
  }]);
88
91
  }
89
- function K(e, t, n, r) {
90
- G({
92
+ function Y(e, t, n, r) {
93
+ J({
91
94
  code: e,
92
95
  source: t,
93
96
  message: `${t} failed`,
@@ -95,80 +98,88 @@ function x(d, m) {
95
98
  ...r ? { handle: r } : {}
96
99
  });
97
100
  }
98
- function ye(e, t) {
101
+ function xe(e, t) {
99
102
  for (let n of [...e]) if (e.has(n)) try {
100
103
  n();
101
104
  } catch (e) {
102
- K("listener-error", t, e);
105
+ Y("listener-error", t, e);
103
106
  }
104
107
  }
105
- function q(e, t = !1, n = x.now(), r = !1, i = !1) {
106
- if (O.push(() => {
107
- t && ye(w, "subscribe");
108
+ function Se(e, t = !1, n = x.now(), r = !1, i = !1) {
109
+ let a = t ? {
110
+ deliveries: e,
111
+ snapshot: ue,
112
+ closedBy: P
113
+ } : null;
114
+ if (D.push(() => {
115
+ a && (F = a, xe(ee, "subscribe"), F = null);
108
116
  for (let t of e) {
109
117
  if ("callback" in t) {
110
118
  try {
111
119
  t.callback();
112
120
  } catch (e) {
113
- K("callback-error", t.source, e, t.handle);
121
+ Y("callback-error", t.source, e, t.handle);
114
122
  }
115
123
  continue;
116
124
  }
117
125
  let e = s({
118
126
  ...t,
119
127
  controller: S,
120
- sequence: ++te,
128
+ sequence: ++re,
121
129
  at: i ? x.now() : n
122
130
  });
123
- for (let t of [...T]) if (T.has(t)) try {
131
+ for (let t of [...w]) if (w.has(t)) try {
124
132
  t(e);
125
133
  } catch (t) {
126
- e.type !== "diagnostic" && K("listener-error", "onEvent", t);
134
+ e.type !== "diagnostic" && Y("listener-error", "onEvent", t);
127
135
  }
128
136
  if (e.type === "diagnostic") try {
129
137
  b.onDiagnostic?.(e.diagnostic);
130
138
  } catch {}
131
139
  }
132
- if (r && q([{ type: "disposed" }], !1, n, !1, !0), i) {
133
- w.clear(), T.clear();
134
- for (let e of E.keys()) e.clear();
135
- E.clear();
140
+ if (r && Se([{
141
+ type: "disposed",
142
+ source: "system"
143
+ }], !1, n, !1, !0), i) {
144
+ ee.clear(), w.clear();
145
+ for (let e of T.keys()) e.clear();
146
+ T.clear();
136
147
  }
137
- }), !re) {
138
- re = !0;
148
+ }), !oe) {
149
+ oe = !0;
139
150
  try {
140
151
  let e;
141
- for (; e = O.shift();) e();
152
+ for (; e = D.shift();) e();
142
153
  } finally {
143
- re = !1;
154
+ oe = !1;
144
155
  }
145
156
  }
146
157
  }
147
- function J() {
158
+ function X() {
148
159
  let e = x.now();
149
160
  for (let t of C.values()) t.activeSince !== null && t.remaining !== null && (t.remaining = Math.max(0, t.remaining - Math.max(0, e - t.activeSince)), t.activeSince = e);
150
161
  return e;
151
162
  }
152
- function be() {
153
- ++ae, ie?.(), ie = null;
163
+ function Ce() {
164
+ ++ce, se?.(), se = null;
154
165
  }
155
- function xe(e) {
156
- be();
166
+ function we(e) {
167
+ Ce();
157
168
  let t = Infinity;
158
169
  for (let n of C.values()) {
159
- let r = n.remaining !== null && ge(n).length === 0 && !U;
170
+ let r = n.remaining !== null && ve(n).length === 0 && !G;
160
171
  n.activeSince = r ? e : null, r && (t = Math.min(t, e + n.remaining));
161
172
  }
162
173
  if (!Number.isFinite(t)) return;
163
- let n = ae;
164
- ie = x.schedule(t, () => {
165
- if (U || n !== ae) return;
166
- let e = J(), t = [...C.values()].filter((e) => e.activeSince !== null && e.remaining === 0), r = [];
167
- for (let e of t) $(e, "timeout", r);
168
- t.length ? Y(r, e) : xe(e);
174
+ let n = ce;
175
+ se = x.schedule(t, () => {
176
+ if (G || n !== ce) return;
177
+ let e = X(), t = [...C.values()].filter((e) => e.activeSince !== null && e.remaining === 0), r = [];
178
+ for (let e of t) ze(e, "timeout", r, "system");
179
+ t.length ? Z(r, e) : we(e);
169
180
  });
170
181
  }
171
- function Se() {
182
+ function Te() {
172
183
  let e = [...C.values()], t = s(e.map((e) => s({
173
184
  handle: e.handle,
174
185
  kind: e.kind,
@@ -177,44 +188,46 @@ function x(d, m) {
177
188
  occurrences: e.occurrences,
178
189
  location: e === I ? "current" : "stack",
179
190
  remainingMs: e.remaining,
180
- pauseReasons: s(ge(e)),
191
+ pauseReasons: s(ve(e)),
181
192
  operation: e.operation?.getSnapshot() ?? null,
182
193
  action: e.action,
183
- draft: me(e)
194
+ draft: _e(e)
184
195
  })));
185
- oe = s({
196
+ le = s({
186
197
  controller: S,
187
- revision: P,
188
- disposed: U,
198
+ revision: M,
199
+ disposed: G,
189
200
  notifications: t,
190
- stack: s(ce().map((e) => e.handle)),
191
- island: F ? s({
201
+ stack: s(de().map((e) => e.handle)),
202
+ island: N ? s({
192
203
  open: !0,
193
- reason: F.reason,
194
- current: F.current.handle
204
+ reason: N.reason,
205
+ current: N.current.handle,
206
+ source: N.source
195
207
  }) : f,
196
208
  overflow: s({
197
- count: V,
198
- pending: V > 0
209
+ count: U,
210
+ pending: U > 0
199
211
  })
200
- }), se = s({
201
- ...oe,
212
+ }), ue = s({
213
+ ...le,
202
214
  presentation: I ? s({
203
215
  handle: I.handle,
204
216
  token: I.presentation,
205
217
  readable: I.readable
206
218
  }) : null,
207
- focusRequest: A,
219
+ focusRequest: k,
208
220
  forms: s(e.flatMap((e) => {
209
- let t = pe(e);
221
+ let t = ge(e);
210
222
  return t ? [s({
211
223
  handle: e.handle,
212
224
  values: t.values,
213
- errors: t.errors
225
+ errors: t.errors,
226
+ authors: t.authors
214
227
  })] : [];
215
228
  })),
216
229
  announcements: s({
217
- overflowCount: H,
230
+ overflowCount: W,
218
231
  notifications: s(e.map((e) => s({
219
232
  handle: e.handle,
220
233
  queued: e.queuedAnnounced,
@@ -229,143 +242,189 @@ function x(d, m) {
229
242
  })
230
243
  });
231
244
  }
232
- function Y(e = [], t = x.now(), n = !1) {
233
- Te(), xe(t), Oe(t), ++P, Se(), q(e, !0, t, n);
245
+ function Z(e = [], t = x.now(), n = !1) {
246
+ Oe(), we(t), Ie(t), je(t), ++M, Te(), Se(e, !0, t, n);
234
247
  }
235
- function X(e, t = !1) {
236
- let n = J(), r = [];
237
- return e(r), Y(r, n, t), _;
248
+ function Q(e, t = !1) {
249
+ let n = X(), r = [];
250
+ return e(r), Z(r, n, t), _;
238
251
  }
239
- function Ce(e) {
240
- e.readable = !1, e.presentation = j === null ? null : W();
252
+ function Ee(e) {
253
+ e.readable = !1, e.presentation = A === null ? null : K();
241
254
  }
242
- function we(e) {
243
- e.presentation = null, e.readable = !1, e.pauses.clear(), k === e.handle && (k = null), A?.target.kind === "notification" && A.target.handle === e.handle && (A = null);
255
+ function De(e) {
256
+ e.presentation = null, e.readable = !1, e.pauses.clear(), O === e.handle && (O = null), k?.target.kind === "notification" && k.target.handle === e.handle && (k = null);
244
257
  }
245
- function Te() {
246
- let e = F ? F.current : le();
247
- e !== I && (I && we(I), I = e, e && Ce(e));
258
+ function Oe() {
259
+ let e = N ? N.current : fe();
260
+ e !== I && (I && De(I), I = e, e && Ee(e));
248
261
  }
249
- function Ee() {
250
- ++ne, B?.(), B = null;
262
+ function ke() {
263
+ ++ie, B?.(), B = null;
251
264
  }
252
- function De(e, t) {
253
- fe(e) && (z = {
265
+ function Ae(e, t) {
266
+ he(e) && (z = {
254
267
  record: e,
255
268
  due: t + (L ?? b.attentionDelay ?? 600),
256
269
  waiting: !1
257
270
  });
258
271
  }
259
- function Oe(e) {
260
- Ee();
272
+ function je(e) {
273
+ ke();
261
274
  let t = z;
262
- if (!t || U) return;
263
- if (j === null) {
275
+ if (!t || G) return;
276
+ if (A === null) {
264
277
  t.waiting = !0;
265
278
  return;
266
279
  }
267
280
  if (t.waiting) {
268
- if (he()) return;
281
+ if (q()) return;
269
282
  t.waiting = !1, t.due = e + (L ?? b.attentionDelay ?? 600);
270
283
  }
271
- let n = ne;
284
+ let n = ie;
272
285
  B = x.schedule(t.due, () => {
273
- if (U || n !== ne || z !== t) return;
286
+ if (G || n !== ie || z !== t) return;
274
287
  let e = x.now();
275
288
  if (e < t.due) {
276
- Oe(e);
289
+ je(e);
277
290
  return;
278
291
  }
279
- if (B = null, he()) {
292
+ if (B = null, q() || V) {
280
293
  t.waiting = !0;
281
294
  return;
282
295
  }
283
296
  z = null;
284
297
  let r = t.record;
285
- fe(r) && F?.current !== r && X(() => {
286
- F ? F.current = r : F = {
298
+ he(r) && N?.current !== r && Q(() => {
299
+ N ? (N.current = r, N.source = "system") : N = {
287
300
  reason: "attention",
288
- current: r
301
+ current: r,
302
+ source: "system"
289
303
  };
290
304
  });
291
305
  });
292
306
  }
293
- let Z = (e) => (e ?? b.autoDismiss) !== !1;
294
- function ke(e) {
295
- let t = Z(e) !== Z(R);
296
- if (R = e, t) for (let e of C.values()) e.remaining = Q(e);
307
+ let Me = () => L ?? b.attentionDelay ?? 600;
308
+ function Ne(e, t) {
309
+ N ? (N.current = e, N.source = t) : N = {
310
+ reason: "attention",
311
+ current: e,
312
+ source: t
313
+ }, z?.record === e ? z = null : z && (z.waiting = !1, z.due = x.now() + Me());
314
+ }
315
+ function Pe() {
316
+ ++ae, H?.(), H = null;
317
+ }
318
+ function Fe(e) {
319
+ let t = V !== null;
320
+ return V = null, Pe(), N?.current === e ? (t && je(x.now()), "unchanged") : q() ? (V = {
321
+ record: e,
322
+ due: 0,
323
+ waiting: !0
324
+ }, "waiting") : (Q(() => Ne(e, "agent")), "shown");
325
+ }
326
+ function Ie(e) {
327
+ Pe();
328
+ let t = V;
329
+ if (!t) return;
330
+ if (G || A === null) {
331
+ V = null;
332
+ return;
333
+ }
334
+ if (t.waiting) {
335
+ if (q()) return;
336
+ t.waiting = !1, t.due = e + Me();
337
+ }
338
+ let n = ae;
339
+ H = x.schedule(t.due, () => {
340
+ if (G || n !== ae || V !== t) return;
341
+ let e = x.now();
342
+ e < t.due ? Ie(e) : (H = null, q() ? t.waiting = !0 : (V = null, N?.current === t.record ? je(e) : Q(() => Ne(t.record, "agent"))));
343
+ });
344
+ }
345
+ let Le = (e) => (e ?? b.autoDismiss) !== !1;
346
+ function Re(e) {
347
+ let t = Le(e) !== Le(R);
348
+ if (R = e, t) for (let e of C.values()) e.remaining = $(e);
297
349
  }
298
- function Q(e) {
299
- return Z(R) ? e.content.duration === void 0 ? (e.kind === "info" || e.kind === "success") && !e.content.action ? 6e3 : null : e.content.duration : null;
350
+ function $(e) {
351
+ return Le(R) ? e.content.duration === void 0 ? (e.kind === "info" || e.kind === "success") && !e.content.action ? 6e3 : null : e.content.duration : null;
300
352
  }
301
- function $(e, t, n) {
302
- if (F?.current === e) {
303
- let t = ce(), n = t.indexOf(e), r = t[n + 1] ?? t[n - 1];
304
- r ? F.current = r : F = null;
353
+ function ze(e, t, n, r) {
354
+ if (N?.current === e) {
355
+ let t = de(), n = t.indexOf(e), i = t[n + 1] ?? t[n - 1];
356
+ i ? (N.current = i, N.source = r) : Be(r);
305
357
  }
306
- if (z?.record === e && (z = null), C.delete(e.handle.id), e.operation && n.push(e.operation.detach()), n.push({
358
+ if (z?.record === e && (z = null), V?.record === e && (V = null), C.delete(e.handle.id), e.operation && n.push(e.operation.detach()), n.push({
307
359
  type: "closed",
360
+ source: r,
308
361
  handle: e.handle,
309
362
  reason: t
310
363
  }), e.onClose) {
311
- let r = e.onClose, i = s({
364
+ let i = e.onClose, a = s({
312
365
  handle: e.handle,
313
- reason: t
366
+ reason: t,
367
+ source: r
314
368
  });
315
369
  n.push({
316
- callback: () => r(i),
370
+ callback: () => i(a),
317
371
  source: "onClose",
318
372
  handle: e.handle
319
373
  });
320
374
  }
321
375
  }
322
- let Ae = ve((e, t) => X((n) => $(e, t, n)));
323
- function je(e) {
376
+ function Be(e) {
377
+ N = null, P = e;
378
+ }
379
+ let Ve = be((e, t, n) => Q((r) => ze(e, t, r, n)));
380
+ function He(e, t) {
324
381
  e.push({
325
382
  type: "overflow-acknowledged",
326
- count: V
327
- }), V = H = 0, A?.target.kind === "overflow" && (A = null);
328
- }
329
- function Me() {
330
- return U ? y("disposed") : V ? X(je) : v;
331
- }
332
- function Ne(e) {
333
- if (U) return y("disposed");
334
- let t = C.size, n = e === "clear-button" && V > 0;
335
- return (t || n) && X((t) => {
336
- for (let n of C.values()) $(n, e, t);
337
- n && je(t);
383
+ source: t,
384
+ count: U
385
+ }), U = W = 0, k?.target.kind === "overflow" && (k = null);
386
+ }
387
+ function Ue(e) {
388
+ return G ? y("disposed") : U ? Q((t) => He(t, e)) : v;
389
+ }
390
+ function We(e, t) {
391
+ if (G) return y("disposed");
392
+ let n = C.size, r = e === "clear-button" && U > 0;
393
+ return (n || r) && Q((n) => {
394
+ for (let r of C.values()) ze(r, e, n, t);
395
+ r && He(n, t);
338
396
  }), {
339
397
  status: "cleared",
340
- count: t
398
+ count: n
341
399
  };
342
400
  }
343
- function Pe(e, t) {
401
+ function Ge(e, t) {
344
402
  if (typeof t != "function") throw TypeError("Listener must be a function");
345
- return U ? () => {} : (e.add(t), () => {
403
+ return G ? () => {} : (e.add(t), () => {
346
404
  e.delete(t);
347
405
  });
348
406
  }
349
- function Fe(e) {
350
- if (U) return y("disposed");
407
+ function Ke(e) {
408
+ if (G) return y("disposed");
351
409
  let t = a(e);
352
- return t.length ? (G({
410
+ return t.length ? (J({
353
411
  code: "invalid-input",
354
412
  source: "show",
355
413
  message: "Invalid notification specification"
356
414
  }), {
357
415
  ...y("invalid-input"),
358
416
  issues: t
359
- }) : Ie(e);
417
+ }) : qe(e);
360
418
  }
361
- function Ie(t, n) {
419
+ function qe(t, n) {
362
420
  if (t.id !== void 0 && C.has(t.id)) return y("id-conflict");
363
421
  let r = t.dedupeKey === void 0 ? void 0 : [...C.values()].find((e) => e.dedupeKey === t.dedupeKey);
364
422
  if (r) {
365
423
  let e = r.occurrences;
366
- return X((t) => {
424
+ return Q((t) => {
367
425
  e = r.occurrences = Math.min(2 ** 53 - 1, e + 1), t.push({
368
426
  type: "deduplicated",
427
+ source: "app",
369
428
  handle: r.handle,
370
429
  occurrences: e
371
430
  });
@@ -375,28 +434,29 @@ function x(d, m) {
375
434
  occurrences: e
376
435
  };
377
436
  }
378
- if (C.size >= 100) return X((e) => {
379
- V = Math.min(2 ** 53 - 1, V + 1);
437
+ if (C.size >= 100) return Q((e) => {
438
+ U = Math.min(2 ** 53 - 1, U + 1);
380
439
  let t = s({
381
- count: V,
440
+ count: U,
382
441
  pending: !0
383
442
  });
384
443
  e.push({
385
444
  type: "overflow",
386
- count: V
445
+ source: "app",
446
+ count: U
387
447
  }), b.onOverflow && e.push({
388
448
  callback: () => b.onOverflow(t),
389
449
  source: "onOverflow"
390
450
  });
391
451
  }), y("capacity");
392
- let i = J(), a = t.id;
452
+ let i = X(), a = t.id;
393
453
  if (a === void 0) do
394
- a = `${S}:notification-${++ee}`;
454
+ a = `${S}:notification-${++ne}`;
395
455
  while (C.has(a));
396
456
  let o = s({
397
457
  id: a,
398
458
  controller: S,
399
- generation: W()
459
+ generation: K()
400
460
  });
401
461
  c.add(o);
402
462
  let l = {
@@ -421,32 +481,34 @@ function x(d, m) {
421
481
  action: h,
422
482
  form: null
423
483
  };
424
- l.remaining = Q(l), C.set(a, l), n?.(l), De(l, i);
484
+ l.remaining = $(l), C.set(a, l), n?.(l), Ae(l, i);
425
485
  let u = [{
426
486
  type: "admitted",
487
+ source: "app",
427
488
  handle: o
428
489
  }];
429
490
  if (l.operation) {
430
491
  let e = l.operation.getSnapshot();
431
492
  u.push({
432
493
  type: "operation-started",
494
+ source: "app",
433
495
  handle: o,
434
496
  token: e.token,
435
497
  attempt: e.attempt
436
498
  });
437
499
  }
438
- return Y(u, i), {
500
+ return Z(u, i), {
439
501
  status: "created",
440
502
  handle: o
441
503
  };
442
504
  }
443
- function Le(e) {
444
- U || q(e);
505
+ function Je(e) {
506
+ G || Se(e);
445
507
  }
446
- function Re(e, t, n) {
447
- e.content = t, e.kind = n, e.remaining = n === "loading" ? null : Q(e), e.action = h, e === I && Ce(e), De(e, x.now()), A?.target.kind === "notification" && A.target.handle === e.handle && A.target.control === "action" && !t.action && (A = null);
508
+ function Ye(e, t, n) {
509
+ e.content = t, e.kind = n, e.remaining = n === "loading" ? null : $(e), e.action = h, e === I && Ee(e), Ae(e, x.now()), k?.target.kind === "notification" && k.target.handle === e.handle && k.target.control === "action" && !t.action && (k = null);
448
510
  }
449
- function ze(r, i) {
511
+ function Xe(r, i) {
450
512
  let a = typeof r == "function" ? r : null, c;
451
513
  if (!a && (typeof r != "object" || !r || typeof (c = r.then) != "function")) throw TypeError("Operation source must be a factory or thenable");
452
514
  let l = o(i, a !== null), u = (e) => i && typeof i == "object" ? Object.getOwnPropertyDescriptor(i, e)?.value : void 0, d = u("cancel"), f = !a && typeof d == "function" ? d : null, p = u("isCancellation"), h = typeof p == "function" ? p : null, g = l.length ? null : s({
@@ -455,12 +517,12 @@ function x(d, m) {
455
517
  success: typeof i.success == "function" ? i.success : e(i.success),
456
518
  error: typeof i.error == "function" ? i.error : e(i.error),
457
519
  ...i.cancelled === void 0 ? {} : { cancelled: typeof i.cancelled == "function" ? i.cancelled : e(i.cancelled) }
458
- }), _ = /* @__PURE__ */ new Set(), v = null, x = !1, S, w = 0;
459
- function T() {
520
+ }), _ = /* @__PURE__ */ new Set(), v = null, x = !1, S, ee = 0;
521
+ function w() {
460
522
  let e = m.createCancellation(), t = s({
461
523
  signal: e.signal,
462
- token: W(),
463
- attempt: ++w
524
+ token: K(),
525
+ attempt: ++ee
464
526
  }), n, r, i = new Promise((e, t) => {
465
527
  n = e, r = t;
466
528
  }), a = {
@@ -476,53 +538,53 @@ function x(d, m) {
476
538
  status: "pending",
477
539
  cancelRequested: !1
478
540
  };
479
- return i.then((e) => ee(a, "fulfilled", e), (e) => ee(a, "rejected", e)).catch((e) => {
480
- U || K("callback-error", "operation-settlement", e);
541
+ return i.then((e) => ne(a, "fulfilled", e), (e) => ne(a, "rejected", e)).catch((e) => {
542
+ G || Y("callback-error", "operation-settlement", e);
481
543
  }), a;
482
544
  }
483
- let D = T(), O = D;
484
- function k() {
545
+ let E = w(), D = E;
546
+ function O() {
485
547
  let e = {
486
- token: O.context.token,
487
- attempt: O.context.attempt,
488
- status: O.status,
489
- cancelRequested: O.cancelRequested,
490
- canCancel: !U && O.status === "pending" && !O.cancelRequested && (!!a || !!f),
491
- canRetry: !U && !!a && O.status !== "pending",
492
- notification: x && !U ? v : null
548
+ token: D.context.token,
549
+ attempt: D.context.attempt,
550
+ status: D.status,
551
+ cancelRequested: D.cancelRequested,
552
+ canCancel: !G && D.status === "pending" && !D.cancelRequested && (!!a || !!f),
553
+ canRetry: !G && !!a && D.status !== "pending",
554
+ notification: x && !G ? v : null
493
555
  };
494
556
  return (!S || Object.keys(e).some((t) => e[t] !== S[t])) && (S = s(e)), S;
495
557
  }
496
- let A = {
558
+ let k = {
497
559
  source: "operation.subscribe",
498
- callback: () => ye(_, "operation.subscribe")
560
+ callback: () => xe(_, "operation.subscribe")
499
561
  };
500
- function j(e) {
501
- if (U || O !== e || !x || !v) return;
562
+ function A(e) {
563
+ if (G || D !== e || !x || !v) return;
502
564
  let t = C.get(v.id);
503
- return t?.handle === v && t.operation === L ? t : void 0;
565
+ return t?.handle === v && t.operation === F ? t : void 0;
504
566
  }
505
- function M(e) {
567
+ function j(e) {
506
568
  try {
507
569
  e.resolve(a ? a(e.context) : { then: c.bind(r) });
508
570
  } catch (t) {
509
571
  e.reject(t);
510
572
  }
511
573
  }
512
- function N(e, t) {
574
+ function te(e, t) {
513
575
  if (t) {
514
- let n = J();
515
- t(), Y(e, n);
516
- } else Le(e);
576
+ let n = X();
577
+ t(), Z(e, n);
578
+ } else Je(e);
517
579
  }
518
- function ee(t, r, i) {
580
+ function ne(t, r, i) {
519
581
  if (t.status = r, r === "rejected") try {
520
582
  (h ? h(i, t.context) === !0 : t.cancelRequested && typeof i == "object" && i && "name" in i && i.name === "AbortError") && (t.status = "cancelled");
521
583
  } catch (e) {
522
- U || K("cancellation-error", "isCancellation", e);
584
+ G || Y("cancellation-error", "isCancellation", e);
523
585
  }
524
586
  let a;
525
- if (j(t) && g) {
587
+ if (A(t) && g) {
526
588
  let r = t.status, o = r === "fulfilled" ? b.messages?.operationSuccess ?? "Completed" : r === "cancelled" ? b.messages?.operationCancelled ?? "Cancelled" : b.messages?.operationError ?? "Something went wrong";
527
589
  try {
528
590
  let t = r === "fulfilled" ? g.success : r === "cancelled" ? g.cancelled : g.error, s = typeof t == "function" ? t(i) : t ?? { title: o };
@@ -532,118 +594,122 @@ function x(d, m) {
532
594
  a = s({
533
595
  title: o,
534
596
  announcementPriority: "polite"
535
- }), U || K("mapper-error", `track.${r}`, e, v ?? void 0);
597
+ }), G || Y("mapper-error", `track.${r}`, e, v ?? void 0);
536
598
  }
537
599
  }
538
- let o = j(t), c = !!o && !!a;
539
- N([...O === t ? [A] : [], {
600
+ let o = A(t), c = !!o && !!a;
601
+ te([...D === t ? [k] : [], {
540
602
  type: "operation-settled",
603
+ source: "system",
541
604
  handle: v,
542
605
  token: t.context.token,
543
606
  status: t.status,
544
607
  uiApplied: c
545
- }], o && a ? () => Re(o, a, t.status === "fulfilled" ? "success" : t.status === "cancelled" ? "warning" : "error") : void 0);
608
+ }], o && a ? () => Ye(o, a, t.status === "fulfilled" ? "success" : t.status === "cancelled" ? "warning" : "error") : void 0);
546
609
  }
547
- function P(e, n) {
610
+ function M(e, n, r) {
548
611
  e.cancelRequested = !0;
549
- let r = j(e);
550
- N([A, {
612
+ let i = A(e);
613
+ te([k, {
551
614
  type: "cancellation-requested",
615
+ source: r,
552
616
  handle: v,
553
617
  token: e.context.token
554
- }], r ? () => {
555
- r.content = t(r.content, { title: b.messages?.cancellationRequested ?? "Cancellation requested" });
618
+ }], i ? () => {
619
+ i.content = t(i.content, { title: b.messages?.cancellationRequested ?? "Cancellation requested" });
556
620
  } : void 0);
557
621
  try {
558
622
  e.abort(n), f?.(n);
559
623
  } catch (e) {
560
- U || K("cancellation-error", "cancel", e, v ?? void 0);
624
+ G || Y("cancellation-error", "cancel", e, v ?? void 0);
561
625
  }
562
626
  }
563
- function te() {
627
+ function re() {
564
628
  let e = /* @__PURE__ */ Error("Cancellation requested");
565
629
  return e.name = "AbortError", e;
566
630
  }
567
- function F(e = te()) {
568
- return U ? y("disposed") : O.status === "pending" ? !a && !f ? y("not-cancellable") : O.cancelRequested ? {
631
+ function N(e = re(), t) {
632
+ return G ? y("disposed") : D.status === "pending" ? !a && !f ? y("not-cancellable") : D.cancelRequested ? {
569
633
  status: "unchanged",
570
634
  reason: "already-requested"
571
- } : (P(O, e), { status: "requested" }) : {
635
+ } : (M(D, e, t), { status: "requested" }) : {
572
636
  status: "unchanged",
573
637
  reason: "settled"
574
638
  };
575
639
  }
576
- function I(e) {
577
- if (U) return y("disposed");
640
+ function P(e, t) {
641
+ if (G) return y("disposed");
578
642
  if (!a) return y("not-retryable");
579
- if (O.status === "pending" && !e) return y("already-pending");
580
- let t = O, n = T();
581
- O = n;
582
- let r = j(n);
583
- return N([A, {
643
+ if (D.status === "pending" && !e) return y("already-pending");
644
+ let n = D, r = w();
645
+ D = r;
646
+ let i = A(r);
647
+ return te([k, {
584
648
  type: "operation-started",
649
+ source: t,
585
650
  handle: v,
586
- token: n.context.token,
587
- attempt: n.context.attempt
588
- }], r && g ? () => {
589
- r.operationAnnounced.clear(), Re(r, g.pending, "loading");
590
- } : void 0), t.status === "pending" && !t.cancelRequested && P(t, te()), M(n), {
651
+ token: r.context.token,
652
+ attempt: r.context.attempt
653
+ }], i && g ? () => {
654
+ i.operationAnnounced.clear(), Ye(i, g.pending, "loading");
655
+ } : void 0), n.status === "pending" && !n.cancelRequested && M(n, re(), t), j(r), {
591
656
  status: "started",
592
- attempt: n.public
657
+ attempt: r.public
593
658
  };
594
659
  }
595
- let L = {
596
- getSnapshot: k,
597
- retry: () => I(!1),
598
- cancel: F,
599
- detach: () => (x = !1, A)
600
- }, R;
601
- if (U) R = y("disposed");
602
- else if (!g) R = {
660
+ let F = {
661
+ getSnapshot: O,
662
+ retry: (e) => P(!1, e),
663
+ cancel: N,
664
+ detach: () => (x = !1, k)
665
+ }, I;
666
+ if (G) I = y("disposed");
667
+ else if (!g) I = {
603
668
  ...y("invalid-input"),
604
669
  issues: l
605
- }, G({
670
+ }, J({
606
671
  code: "invalid-input",
607
672
  source: "track",
608
673
  message: "Invalid operation options"
609
674
  });
610
675
  else {
611
- let e = Ie({
676
+ let e = qe({
612
677
  ...g.pending,
613
678
  ...g,
614
679
  kind: "loading"
615
680
  }, (e) => {
616
- v = e.handle, x = !0, e.operation = L;
681
+ v = e.handle, x = !0, e.operation = F;
617
682
  });
618
683
  if (e.status === "deduplicated") throw Error("Tracked operation cannot be deduplicated");
619
- R = e;
684
+ I = e;
620
685
  }
621
- return R.status === "rejected" && Le([{
686
+ return I.status === "rejected" && Je([{
622
687
  type: "operation-started",
688
+ source: "app",
623
689
  handle: null,
624
- token: D.context.token,
690
+ token: E.context.token,
625
691
  attempt: 1
626
- }]), M(D), s({
627
- ...D.public,
628
- admission: s(R),
629
- getSnapshot: k,
692
+ }]), j(E), s({
693
+ ...E.public,
694
+ admission: s(I),
695
+ getSnapshot: O,
630
696
  subscribe(e) {
631
- let t = Pe(_, e);
632
- return _.size && E.set(_, A), () => {
633
- t(), _.size || E.delete(_);
697
+ let t = Ge(_, e);
698
+ return _.size && T.set(_, k), () => {
699
+ t(), _.size || T.delete(_);
634
700
  };
635
701
  },
636
- cancel: F,
637
- retry: () => I(!1),
638
- restart: () => I(!0)
702
+ cancel: (e) => N(e, "app"),
703
+ retry: () => P(!1, "app"),
704
+ restart: () => P(!0, "app")
639
705
  });
640
706
  }
641
- let Be = s({
642
- show: (e) => Fe(e),
643
- track: ze,
644
- update: ve((e, n) => {
707
+ let Ze = s({
708
+ show: (e) => Ke(e),
709
+ track: Xe,
710
+ update: be((e, n) => {
645
711
  let r = e.handle, a = i(n);
646
- if (a.length) return G({
712
+ if (a.length) return J({
647
713
  code: "invalid-input",
648
714
  source: "update",
649
715
  message: "Invalid notification patch",
@@ -655,26 +721,27 @@ function x(d, m) {
655
721
  if (e.action.status === "pending" && Object.prototype.hasOwnProperty.call(n, "action")) return y("action-pending");
656
722
  if (e.operation && (Object.prototype.hasOwnProperty.call(n, "kind") || e.operation.getSnapshot().status === "pending" && Object.prototype.hasOwnProperty.call(n, "duration"))) return y("operation-owned");
657
723
  let o = t(e.content, n), s = n.kind ?? e.kind, c = n.priority ?? e.priority, l = Object.prototype.hasOwnProperty.call(n, "duration");
658
- return o === e.content && s === e.kind && c === e.priority && !l && !(Object.prototype.hasOwnProperty.call(n, "action") && e.action.status === "failed") ? v : X((t) => {
659
- let i = Q(e);
724
+ return o === e.content && s === e.kind && c === e.priority && !l && !(Object.prototype.hasOwnProperty.call(n, "action") && e.action.status === "failed") ? v : Q((t) => {
725
+ let i = $(e);
660
726
  e.content = o, Object.prototype.hasOwnProperty.call(n, "action") && (e.action = h), e.kind = s, e.priority = c;
661
- let a = Q(e);
662
- (l || i !== a) && (e.remaining = a), A?.target.kind === "notification" && A.target.handle === r && A.target.control === "action" && !o.action && (A = null), z?.record === e && !fe(e) && (z = null), t.push({
727
+ let a = $(e);
728
+ (l || i !== a) && (e.remaining = a), k?.target.kind === "notification" && k.target.handle === r && k.target.control === "action" && !o.action && (k = null), z?.record === e && !he(e) && (z = null), t.push({
663
729
  type: "updated",
730
+ source: "app",
664
731
  handle: r
665
732
  });
666
733
  });
667
734
  }),
668
- getHandle: (e) => !U && typeof e == "string" ? C.get(e)?.handle : void 0,
669
- dismiss: (e) => Ae(e, "programmatic"),
670
- clear: () => Ne("clear"),
735
+ getHandle: (e) => !G && typeof e == "string" ? C.get(e)?.handle : void 0,
736
+ dismiss: (e) => Ve(e, "programmatic", "app"),
737
+ clear: () => We("clear", "app"),
671
738
  requestFocus(e = { kind: "anchor" }) {
672
- if (U) return y("disposed");
739
+ if (G) return y("disposed");
673
740
  if (e?.kind === "notification") {
674
- let t = _e(e.handle);
741
+ let t = ye(e.handle);
675
742
  if (t) return y(t);
676
743
  }
677
- if (!j) return y("no-host");
744
+ if (!A) return y("no-host");
678
745
  if (!e || ![
679
746
  "anchor",
680
747
  "notification",
@@ -684,64 +751,64 @@ function x(d, m) {
684
751
  let t = C.get(e.handle.id);
685
752
  if (t !== I) return y("not-visible");
686
753
  if (e.control !== void 0 && !["action", "close"].includes(e.control) || e.control === "action" && !t.content.action) return y("unavailable");
687
- if (e.control !== void 0 && !F) return y("not-visible");
754
+ if (e.control !== void 0 && !N) return y("not-visible");
688
755
  }
689
- return e.kind === "overflow" && !V ? y("unavailable") : (X(() => {
756
+ return e.kind === "overflow" && !U ? y("unavailable") : (Q(() => {
690
757
  let t = e.kind === "notification" ? s({
691
758
  kind: e.kind,
692
759
  handle: e.handle,
693
760
  ...e.control ? { control: e.control } : {}
694
761
  }) : s({ kind: e.kind });
695
- A = s({
696
- token: W(),
762
+ k = s({
763
+ token: K(),
697
764
  target: t
698
765
  });
699
766
  }), { status: "requested" });
700
767
  },
701
- acknowledgeOverflow: Me,
702
- getSnapshot: () => oe,
768
+ acknowledgeOverflow: () => Ue("app"),
769
+ getSnapshot: () => le,
703
770
  getServerSnapshot: () => p,
704
- subscribe: (e) => Pe(w, e),
705
- onEvent: (e) => Pe(T, e),
771
+ subscribe: (e) => Ge(ee, e),
772
+ onEvent: (e) => Ge(w, e),
706
773
  dispose() {
707
- U || X((e) => {
708
- U = !0;
709
- for (let t of C.values()) $(t, "dispose", e);
710
- for (let t of E.values()) e.includes(t) || e.push(t);
711
- j = M = null, F = null, z = null, Ee(), A = null, D.clear(), V = H = 0;
774
+ G || Q((e) => {
775
+ G = !0;
776
+ for (let t of C.values()) ze(t, "dispose", e, "system");
777
+ for (let t of T.values()) e.includes(t) || e.push(t);
778
+ A = j = null, N && Be("system"), z = null, ke(), V = null, Pe(), k = null, E.clear(), U = W = 0;
712
779
  }, !0);
713
780
  }
714
781
  });
715
- return Se(), l.set(Be, s({
782
+ return Te(), l.set(Ze, s({
716
783
  options: b,
717
784
  clock: x,
718
785
  records: C,
719
- globalPauses: D,
720
- subscribe: Be.subscribe,
721
- onEvent: Be.onEvent,
786
+ globalPauses: E,
787
+ subscribe: Ze.subscribe,
788
+ onEvent: Ze.onEvent,
722
789
  get disposed() {
723
- return U;
790
+ return G;
724
791
  },
725
792
  get presented() {
726
793
  return I;
727
794
  },
728
795
  get rendererSnapshot() {
729
- return se;
796
+ return ue;
730
797
  },
731
798
  get overflow() {
732
- return V;
799
+ return U;
733
800
  },
734
801
  get lease() {
735
- return j;
802
+ return A;
736
803
  },
737
804
  set lease(e) {
738
- j = e;
805
+ A = e;
739
806
  },
740
807
  get lastLease() {
741
- return M;
808
+ return j;
742
809
  },
743
810
  set lastLease(e) {
744
- M = e;
811
+ j = e;
745
812
  },
746
813
  get hostDelay() {
747
814
  return L;
@@ -756,11 +823,15 @@ function x(d, m) {
756
823
  R = e;
757
824
  },
758
825
  get island() {
759
- return F;
826
+ return N;
760
827
  },
761
828
  set island(e) {
762
- F = e;
829
+ N = e;
763
830
  },
831
+ get announced() {
832
+ return F;
833
+ },
834
+ collapse: Be,
764
835
  get attention() {
765
836
  return z;
766
837
  },
@@ -768,48 +839,52 @@ function x(d, m) {
768
839
  z = e;
769
840
  },
770
841
  get focusRequest() {
771
- return A;
842
+ return k;
772
843
  },
773
844
  set focusRequest(e) {
774
- A = e;
845
+ k = e;
775
846
  },
776
847
  get focused() {
777
- return k;
848
+ return O;
778
849
  },
779
850
  set focused(e) {
780
- k = e;
851
+ O = e;
781
852
  },
782
853
  get overflowAnnounced() {
783
- return H;
854
+ return W;
784
855
  },
785
856
  set overflowAnnounced(e) {
786
- H = e;
857
+ W = e;
787
858
  },
788
- token: W,
789
- diagnostic: G,
790
- failure: K,
791
- mutate: X,
792
- commit: Y,
793
- settle: J,
794
- assign: Ce,
795
- newest: le,
796
- formOf: pe,
797
- handleError: _e,
798
- withRecord: ve,
799
- autoDismissing: Z,
800
- setHostAutoDismiss: ke,
801
- dismiss: Ae,
802
- acknowledgeOverflow: Me,
803
- clear: Ne,
859
+ interacting: q,
860
+ dirty: _e,
861
+ reach: Ne,
862
+ summon: Fe,
863
+ token: K,
864
+ diagnostic: J,
865
+ failure: Y,
866
+ mutate: Q,
867
+ commit: Z,
868
+ settle: X,
869
+ assign: Ee,
870
+ newest: fe,
871
+ formOf: ge,
872
+ handleError: ye,
873
+ withRecord: be,
874
+ autoDismissing: Le,
875
+ setHostAutoDismiss: Re,
876
+ dismiss: Ve,
877
+ acknowledgeOverflow: Ue,
878
+ clear: We,
804
879
  reportRendererLoadError(e) {
805
- U || G({
880
+ G || J({
806
881
  code: "renderer-load-error",
807
882
  source: "Toaster",
808
883
  message: "Toaster renderer failed to load",
809
884
  error: e
810
885
  });
811
886
  }
812
- })), Be;
887
+ })), Ze;
813
888
  }
814
889
  //#endregion
815
890
  export { _ as APPLIED, g as NO_FORM_ERRORS, m as RENDERER_SERVER, v as UNCHANGED, x as createCloudletCore, b as getControllerKernel, y as reject };