@stealthscale/component-feedback 0.2.1 → 0.2.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.
Files changed (37) hide show
  1. package/dist/cyclonedx/bom.json +1 -1
  2. package/dist/index.js +1 -1825
  3. package/dist/pages/alert/alert.js +223 -0
  4. package/dist/pages/alert/alert.props.js +3 -0
  5. package/dist/pages/empty-state/empty-state.js +96 -0
  6. package/dist/pages/empty-state/empty-state.props.js +3 -0
  7. package/dist/pages/loader/loader.js +359 -0
  8. package/dist/pages/loader/loader.props.js +3 -0
  9. package/dist/pages/meter/meter.js +785 -0
  10. package/dist/pages/meter/meter.props.js +3 -0
  11. package/dist/pages/pages.json +115 -0
  12. package/dist/pages/progress/progress.js +550 -0
  13. package/dist/pages/progress/progress.props.js +3 -0
  14. package/dist/pages/progress-circle/progress-circle.js +329 -0
  15. package/dist/pages/progress-circle/progress-circle.props.js +3 -0
  16. package/dist/pages/skeleton/skeleton.js +94 -0
  17. package/dist/pages/skeleton/skeleton.props.js +3 -0
  18. package/dist/pages/skeleton-text/skeleton-text.js +81 -0
  19. package/dist/pages/skeleton-text/skeleton-text.props.js +3 -0
  20. package/dist/pages/spinner/spinner.js +186 -0
  21. package/dist/pages/spinner/spinner.props.js +3 -0
  22. package/dist/pages/toast/toast.js +427 -0
  23. package/dist/pages/toast/toast.props.js +3 -0
  24. package/dist/shared-Xc-n0bn7.js +1826 -0
  25. package/dist/theme.js +27 -13
  26. package/locales/en/specimen/alert.json +37 -0
  27. package/locales/en/specimen/empty-state.json +10 -0
  28. package/locales/en/specimen/loader.json +30 -0
  29. package/locales/en/specimen/meter.json +81 -0
  30. package/locales/en/specimen/progress-circle.json +41 -0
  31. package/locales/en/specimen/progress.json +66 -0
  32. package/locales/en/specimen/skeleton-text.json +12 -0
  33. package/locales/en/specimen/skeleton.json +18 -0
  34. package/locales/en/specimen/spinner.json +33 -0
  35. package/locales/en/specimen/toast.json +79 -0
  36. package/package.json +8 -7
  37. /package/dist/{recipe-CX1gSsN7.js → recipes-CX1gSsN7.js} +0 -0
package/dist/index.js CHANGED
@@ -1,1826 +1,2 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { a as recipe$4, c as TINT, d as recipe$1, f as recipe, i as recipe$5, l as recipe$3, n as recipe$7, o as MARKER, r as recipe$6, s as SHARE, t as recipe$8, u as recipe$2 } from "./recipe-CX1gSsN7.js";
3
- import { createRecipeContext, createSlotRecipeContext } from "@stealthscale/theme";
4
- import { c } from "react/compiler-runtime";
5
- import { jsx, jsxs } from "react/jsx-runtime";
6
- import { createContext, use, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
7
- import * as progress from "@zag-js/progress";
8
- import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
9
- import { clampValue, createSplitProps, getValuePercent } from "@zag-js/utils";
10
- import { createRequiredContext, omitUndefined, splitEnumerable, useSafeLayoutEffect } from "@stealthscale/hooks";
11
- import * as toast from "@zag-js/toast";
12
- import { createStore as createToaster } from "@zag-js/toast";
13
- //#region src/alert/context.ts
14
- /**
15
- * Binds the alert slot recipe to React.
16
- *
17
- * @remarks
18
- * The binding is a separate module from the recipe, because an application's compiler imports the
19
- * recipe at build time and the binding needs the React runtime.
20
- */
21
- /**
22
- * Factories for the parts. The root resolves the variants once and the other parts read them.
23
- */
24
- const { withContext: withContext$8, withProvider: withProvider$5 } = createSlotRecipeContext(recipe);
25
- //#endregion
26
- //#region src/alert/aside.ts
27
- /**
28
- * Renders a flex div at the inline end, sized to its content.
29
- */
30
- const Aside = withContext$8("div", "aside");
31
- //#endregion
32
- //#region src/alert/close-trigger.tsx
33
- /**
34
- * Button with the close trigger slot classes and `type="button"`.
35
- */
36
- const Styled = withContext$8("button", "closeTrigger", { defaultProps: { type: "button" } });
37
- /**
38
- * Renders a square button in the alert's ink, named by `label`.
39
- */
40
- function CloseTrigger$1(t0) {
41
- const $ = c(6);
42
- let rest;
43
- let t1;
44
- if ($[0] !== t0) {
45
- ({label: t1, ...rest} = t0);
46
- $[0] = t0;
47
- $[1] = rest;
48
- $[2] = t1;
49
- } else {
50
- rest = $[1];
51
- t1 = $[2];
52
- }
53
- const label = t1 === void 0 ? "Dismiss" : t1;
54
- let t2;
55
- if ($[3] !== label || $[4] !== rest) {
56
- t2 = /* @__PURE__ */ jsx(Styled, {
57
- "aria-label": label,
58
- ...rest
59
- });
60
- $[3] = label;
61
- $[4] = rest;
62
- $[5] = t2;
63
- } else t2 = $[5];
64
- return t2;
65
- }
66
- //#endregion
67
- //#region src/alert/content.ts
68
- /**
69
- * Renders the flex container of the title and the description.
70
- */
71
- const Content$3 = withContext$8("div", "content");
72
- //#endregion
73
- //#region src/alert/description.ts
74
- /**
75
- * Renders a span in the root's ink.
76
- */
77
- const Description$2 = withContext$8("span", "description");
78
- //#endregion
79
- //#region src/alert/indicator.ts
80
- /**
81
- * Renders a div on the icon scale, hidden from the accessibility tree by default.
82
- */
83
- const Indicator$3 = withContext$8("div", "indicator", { defaultProps: { "aria-hidden": true } });
84
- //#endregion
85
- //#region src/alert/live.ts
86
- /**
87
- * Every announcement level, quietest first.
88
- */
89
- const LIVES = [
90
- "off",
91
- "polite",
92
- "assertive"
93
- ];
94
- /**
95
- * Maps each announcement level to the attributes the root sets.
96
- *
97
- * @remarks
98
- * `role="alert"` implies `aria-live="assertive"` and `role="status"` implies
99
- * `aria-live="polite"`, so the map sets the role only. `off` sets no attribute, because a live
100
- * region announces its content on mount, and a page of static notices would read them all.
101
- */
102
- const ROLES = {
103
- assertive: { role: "alert" },
104
- off: {},
105
- polite: { role: "status" }
106
- };
107
- //#endregion
108
- //#region src/alert/root.tsx
109
- /**
110
- * Div with the root slot classes that provides the variants.
111
- */
112
- const Framed$1 = withProvider$5("div", "root");
113
- /**
114
- * Renders a div with the role of its announcement level.
115
- *
116
- * @remarks
117
- * The role comes before the caller's props, so a `role` prop overrides it.
118
- */
119
- function Root$6(t0) {
120
- const $ = c(6);
121
- let rest;
122
- let t1;
123
- if ($[0] !== t0) {
124
- ({live: t1, ...rest} = t0);
125
- $[0] = t0;
126
- $[1] = rest;
127
- $[2] = t1;
128
- } else {
129
- rest = $[1];
130
- t1 = $[2];
131
- }
132
- const t2 = ROLES[t1 === void 0 ? "polite" : t1];
133
- let t3;
134
- if ($[3] !== rest || $[4] !== t2) {
135
- t3 = /* @__PURE__ */ jsx(Framed$1, {
136
- ...t2,
137
- ...rest
138
- });
139
- $[3] = rest;
140
- $[4] = t2;
141
- $[5] = t3;
142
- } else t3 = $[5];
143
- return t3;
144
- }
145
- //#endregion
146
- //#region src/alert/title.ts
147
- /**
148
- * Renders a span at medium weight.
149
- */
150
- const Title$2 = withContext$8("span", "title");
151
- //#endregion
152
- //#region src/alert/index.ts
153
- var alert_exports = /* @__PURE__ */ __exportAll({
154
- Aside: () => Aside,
155
- CloseTrigger: () => CloseTrigger$1,
156
- Content: () => Content$3,
157
- Description: () => Description$2,
158
- Indicator: () => Indicator$3,
159
- LIVES: () => LIVES,
160
- Root: () => Root$6,
161
- Title: () => Title$2
162
- });
163
- //#endregion
164
- //#region src/empty-state/context.ts
165
- /**
166
- * Binds the empty state slot recipe to React.
167
- *
168
- * @remarks
169
- * The binding is a separate module from the recipe, because an application's compiler imports the
170
- * recipe at build time and the binding needs the React runtime.
171
- */
172
- /**
173
- * Factories for the parts. The root resolves the size once and the other parts read it.
174
- */
175
- const { withContext: withContext$7, withProvider: withProvider$4 } = createSlotRecipeContext(recipe$1);
176
- //#endregion
177
- //#region src/empty-state/content.ts
178
- /**
179
- * Renders a centred flex column with the gap of the root's size.
180
- */
181
- const Content$2 = withContext$7("div", "content");
182
- //#endregion
183
- //#region src/empty-state/description.ts
184
- /**
185
- * Renders a paragraph in the muted ink at `body.sm`, at every size of the root.
186
- */
187
- const Description$1 = withContext$7("p", "description");
188
- //#endregion
189
- //#region src/empty-state/indicator.ts
190
- /**
191
- * Renders a div in the muted ink, hidden from the accessibility tree by default.
192
- */
193
- const Indicator$2 = withContext$7("div", "indicator", { defaultProps: { "aria-hidden": true } });
194
- //#endregion
195
- //#region src/empty-state/root.ts
196
- /**
197
- * Renders a div and provides the size to the parts inside it.
198
- */
199
- const Root$5 = withProvider$4("div", "root");
200
- //#endregion
201
- //#region src/empty-state/title.ts
202
- /**
203
- * Renders a semibold heading at the text style of the root's size.
204
- */
205
- const Title$1 = withContext$7("h2", "title");
206
- //#endregion
207
- //#region src/empty-state/index.ts
208
- var empty_state_exports = /* @__PURE__ */ __exportAll({
209
- Content: () => Content$2,
210
- Description: () => Description$1,
211
- Indicator: () => Indicator$2,
212
- Root: () => Root$5,
213
- Title: () => Title$1
214
- });
215
- //#endregion
216
- //#region src/loader/context.ts
217
- /**
218
- * Binds the loader recipe to the elements that render it.
219
- *
220
- * @remarks
221
- * The binding is kept out of `recipe.ts` because an application's style compiler imports the
222
- * recipe at build time, and a binding there would pull the React runtime into that import.
223
- */
224
- /**
225
- * Supplies the element factories the loader and its overlay are built from.
226
- */
227
- const { withContext: withContext$6, withProvider: withProvider$3 } = createSlotRecipeContext(recipe$2);
228
- //#endregion
229
- //#region src/spinner/context.ts
230
- /**
231
- * Binds the spinner recipe to the element that renders it.
232
- *
233
- * @remarks
234
- * The binding is kept out of `recipe.ts` because an application's style compiler imports the
235
- * recipe at build time, and a binding there would pull the React runtime into that import.
236
- */
237
- /**
238
- * Supplies the element factory the spinner is built from.
239
- */
240
- const { withContext: withContext$5 } = createRecipeContext(recipe$3);
241
- //#endregion
242
- //#region src/spinner/spinner.ts
243
- /**
244
- * Renders a `span` styled by the spinner recipe.
245
- */
246
- const Spinner = withContext$5("span");
247
- //#endregion
248
- //#region src/loader/loader.tsx
249
- /**
250
- * Renders the loader's root: an inline row with words, an inline grid over content.
251
- */
252
- const Root$4 = withProvider$3("span", "root");
253
- /**
254
- * Renders the element that contains the spinner.
255
- */
256
- const Indicator$1 = withContext$6("span", "indicator");
257
- /**
258
- * Renders the hidden content the spinner is centred over.
259
- */
260
- const Content$1 = withContext$6("span", "content");
261
- /**
262
- * Renders the text screen readers read in place of the hidden content.
263
- */
264
- const Label$2 = withContext$6("span", "label");
265
- /**
266
- * The default indicator: a spinner as tall as the surrounding text, in its ink.
267
- */
268
- const SPINNER = /* @__PURE__ */ jsx(Spinner, { size: "inherit" });
269
- /**
270
- * Renders the spinner beside `text`, or over the hidden children, while `loading` is true.
271
- */
272
- function Loader(t0) {
273
- const $ = c(24);
274
- let children;
275
- let rest;
276
- let t1;
277
- let t2;
278
- let t3;
279
- let t4;
280
- let text;
281
- if ($[0] !== t0) {
282
- ({children, label: t1, loading: t2, placement: t3, spinner: t4, text, ...rest} = t0);
283
- $[0] = t0;
284
- $[1] = children;
285
- $[2] = rest;
286
- $[3] = t1;
287
- $[4] = t2;
288
- $[5] = t3;
289
- $[6] = t4;
290
- $[7] = text;
291
- } else {
292
- children = $[1];
293
- rest = $[2];
294
- t1 = $[3];
295
- t2 = $[4];
296
- t3 = $[5];
297
- t4 = $[6];
298
- text = $[7];
299
- }
300
- const label = t1 === void 0 ? "Loading" : t1;
301
- const loading = t2 === void 0 ? true : t2;
302
- const placement = t3 === void 0 ? "start" : t3;
303
- const spinner = t4 === void 0 ? SPINNER : t4;
304
- if (!loading) return children;
305
- let t5;
306
- if ($[8] !== spinner) {
307
- t5 = /* @__PURE__ */ jsx(Indicator$1, { children: spinner });
308
- $[8] = spinner;
309
- $[9] = t5;
310
- } else t5 = $[9];
311
- const indicator = t5;
312
- if (text !== void 0) {
313
- const t6 = placement === "start" ? indicator : null;
314
- const t7 = placement === "end" ? indicator : null;
315
- let t8;
316
- if ($[10] !== rest || $[11] !== t6 || $[12] !== t7 || $[13] !== text) {
317
- t8 = /* @__PURE__ */ jsxs(Root$4, {
318
- ...rest,
319
- children: [
320
- t6,
321
- text,
322
- t7
323
- ]
324
- });
325
- $[10] = rest;
326
- $[11] = t6;
327
- $[12] = t7;
328
- $[13] = text;
329
- $[14] = t8;
330
- } else t8 = $[14];
331
- return t8;
332
- }
333
- let t6;
334
- if ($[15] !== children) {
335
- t6 = /* @__PURE__ */ jsx(Content$1, { children });
336
- $[15] = children;
337
- $[16] = t6;
338
- } else t6 = $[16];
339
- let t7;
340
- if ($[17] !== label) {
341
- t7 = /* @__PURE__ */ jsx(Label$2, { children: label });
342
- $[17] = label;
343
- $[18] = t7;
344
- } else t7 = $[18];
345
- let t8;
346
- if ($[19] !== indicator || $[20] !== rest || $[21] !== t6 || $[22] !== t7) {
347
- t8 = /* @__PURE__ */ jsxs(Root$4, {
348
- ...rest,
349
- children: [
350
- t6,
351
- indicator,
352
- t7
353
- ]
354
- });
355
- $[19] = indicator;
356
- $[20] = rest;
357
- $[21] = t6;
358
- $[22] = t7;
359
- $[23] = t8;
360
- } else t8 = $[23];
361
- return t8;
362
- }
363
- /**
364
- * Renders the overlay `div`, veiled by default.
365
- */
366
- const LoaderOverlay = withProvider$3("div", "overlay");
367
- //#endregion
368
- //#region src/progress/role.ts
369
- /**
370
- * Provides the role the track takes: the progress bar's, or the meter's inside `Meter.Root`.
371
- *
372
- * @remarks
373
- * A progress bar reports work under way and a meter reports a measurement, and a screen reader
374
- * names the two apart. They share every part, so the root states the role and the track reads it.
375
- */
376
- /**
377
- * Context with the track's role: `meter` inside `Meter.Root`, and `progressbar` elsewhere.
378
- */
379
- const RoleContext = createContext("progressbar");
380
- //#endregion
381
- //#region src/progress/context.ts
382
- /**
383
- * Binds the progress recipe to the elements that render it.
384
- *
385
- * @remarks
386
- * The binding is kept out of `recipe.ts` because an application's style compiler imports the
387
- * recipe at build time, and a binding there would pull the React runtime into that import.
388
- */
389
- /**
390
- * Supplies the element factories the progress parts are built from.
391
- */
392
- const { withContext: withContext$4, withProvider: withProvider$2 } = createSlotRecipeContext(recipe$4);
393
- //#endregion
394
- //#region src/progress/machine.ts
395
- /**
396
- * Connects the Zag progress machine and provides its API to the parts.
397
- *
398
- * @remarks
399
- * A `null` value is a value the machine does not know. The track then leaves out `aria-valuenow`,
400
- * and the range sets `data-state="indeterminate"`. The machine formats the value with
401
- * `Intl.NumberFormat` in `locale`, as a percentage unless `formatOptions` states otherwise.
402
- */
403
- /**
404
- * Context through which the root provides the connected API to its parts.
405
- *
406
- * @remarks
407
- * `useProgress` throws when no `Progress.Root` is mounted above the calling part.
408
- */
409
- const [ApiProvider$1, useProgress] = createRequiredContext("Progress");
410
- /**
411
- * Starts the progress machine and returns its connected API and the label's ID.
412
- *
413
- * @remarks
414
- * The label's ID is fixed here and passed to the machine in `ids`, so the track can name the
415
- * element the machine writes the ID on. A caller's `ids.label` replaces the generated ID.
416
- * @param options - Machine settings split from the root's props. A generated ID is used when `id`
417
- * is absent.
418
- */
419
- function useProgressMachine(options) {
420
- const $ = c(14);
421
- const generated = useId();
422
- const id = options.id ?? generated;
423
- const labelId = options.ids?.label ?? `progress-${id}-label`;
424
- let t0;
425
- if ($[0] !== options) {
426
- t0 = omitUndefined(options);
427
- $[0] = options;
428
- $[1] = t0;
429
- } else t0 = $[1];
430
- let t1;
431
- if ($[2] !== labelId || $[3] !== options.ids) {
432
- t1 = {
433
- ...options.ids,
434
- label: labelId
435
- };
436
- $[2] = labelId;
437
- $[3] = options.ids;
438
- $[4] = t1;
439
- } else t1 = $[4];
440
- let t2;
441
- if ($[5] !== id || $[6] !== t0 || $[7] !== t1) {
442
- t2 = {
443
- ...t0,
444
- id,
445
- ids: t1
446
- };
447
- $[5] = id;
448
- $[6] = t0;
449
- $[7] = t1;
450
- $[8] = t2;
451
- } else t2 = $[8];
452
- const service = useMachine(progress.machine, t2);
453
- let t3;
454
- if ($[9] !== service) {
455
- t3 = progress.connect(service, normalizeProps);
456
- $[9] = service;
457
- $[10] = t3;
458
- } else t3 = $[10];
459
- let t4;
460
- if ($[11] !== labelId || $[12] !== t3) {
461
- t4 = {
462
- api: t3,
463
- labelId
464
- };
465
- $[11] = labelId;
466
- $[12] = t3;
467
- $[13] = t4;
468
- } else t4 = $[13];
469
- return t4;
470
- }
471
- /**
472
- * Splits the root's props into machine settings and element props.
473
- *
474
- * @remarks
475
- * The key list is `progress.props` without `orientation` and `translations`, so it follows the
476
- * installed machine version. The machine's own splitter types `id` as required, and the root
477
- * generates the ID after splitting, so the splitter is rebuilt over `ProgressOptions`.
478
- */
479
- const splitProgressProps = splitEnumerable(createSplitProps(progress.props.filter((key) => key !== "orientation" && key !== "translations")));
480
- //#endregion
481
- //#region src/progress/state.ts
482
- /**
483
- * Provides whether a label renders in the bar, so the track is named by it only while it exists.
484
- *
485
- * @remarks
486
- * The machine gives the track the value as its `aria-label` and writes no `aria-labelledby`. A
487
- * reference to a label that is not rendered is an invalid ID reference, so the label reports
488
- * itself when it mounts and the track points at it from then on.
489
- */
490
- /**
491
- * Context through which the root provides the label's state to the label and the track.
492
- *
493
- * @remarks
494
- * `useLabelling` throws when no `Progress.Root` is mounted above the calling part.
495
- */
496
- const [LabellingProvider, useLabelling] = createRequiredContext("Progress");
497
- //#endregion
498
- //#region src/progress/root.tsx
499
- /**
500
- * Renders the bar's grid and runs the machine that tracks its value.
501
- *
502
- * @remarks
503
- * The root is a `div` without a role. The track inside it is the progress bar. `value` sets the
504
- * value between `min` and `max`, 0 and 100 by default, and `null` renders a bar whose value is
505
- * not known. Without `value` or `defaultValue` the machine starts halfway.
506
- */
507
- /**
508
- * Renders the root `div` and provides the variants to the parts.
509
- */
510
- const Gridded$1 = withProvider$2("div", "root");
511
- /**
512
- * Renders the bar and provides the machine's API and the label's state to its parts.
513
- *
514
- * @param props - The machine settings, the recipe's variants and the `div` props.
515
- * @returns The `div` element.
516
- */
517
- function Root$3(props) {
518
- const $ = c(16);
519
- let t0;
520
- if ($[0] !== props) {
521
- t0 = splitProgressProps(props);
522
- $[0] = props;
523
- $[1] = t0;
524
- } else t0 = $[1];
525
- const [options, rest] = t0;
526
- const { api, labelId } = useProgressMachine(options);
527
- const [labelled, setLabelled] = useState(false);
528
- let t1;
529
- if ($[2] !== labelId || $[3] !== labelled) {
530
- t1 = {
531
- id: labelId,
532
- labelled,
533
- setLabelled
534
- };
535
- $[2] = labelId;
536
- $[3] = labelled;
537
- $[4] = t1;
538
- } else t1 = $[4];
539
- let t2;
540
- if ($[5] !== api) {
541
- t2 = api.getRootProps();
542
- $[5] = api;
543
- $[6] = t2;
544
- } else t2 = $[6];
545
- let t3;
546
- if ($[7] !== rest || $[8] !== t2) {
547
- t3 = /* @__PURE__ */ jsx(Gridded$1, {
548
- ...rest,
549
- ...t2
550
- });
551
- $[7] = rest;
552
- $[8] = t2;
553
- $[9] = t3;
554
- } else t3 = $[9];
555
- let t4;
556
- if ($[10] !== t1 || $[11] !== t3) {
557
- t4 = /* @__PURE__ */ jsx(LabellingProvider, {
558
- value: t1,
559
- children: t3
560
- });
561
- $[10] = t1;
562
- $[11] = t3;
563
- $[12] = t4;
564
- } else t4 = $[12];
565
- let t5;
566
- if ($[13] !== api || $[14] !== t4) {
567
- t5 = /* @__PURE__ */ jsx(ApiProvider$1, {
568
- value: api,
569
- children: t4
570
- });
571
- $[13] = api;
572
- $[14] = t4;
573
- $[15] = t5;
574
- } else t5 = $[15];
575
- return t5;
576
- }
577
- //#endregion
578
- //#region src/meter/root.tsx
579
- /**
580
- * Renders the progress bar's root inside the meter's role.
581
- *
582
- * @param props - The value, its range and format, the recipe's variants and the props of a `div`.
583
- * @returns The root `div` inside the role's provider.
584
- */
585
- function Root$2(props) {
586
- const $ = c(2);
587
- let t0;
588
- if ($[0] !== props) {
589
- t0 = /* @__PURE__ */ jsx(RoleContext, {
590
- value: "meter",
591
- children: /* @__PURE__ */ jsx(Root$3, { ...props })
592
- });
593
- $[0] = props;
594
- $[1] = t0;
595
- } else t0 = $[1];
596
- return t0;
597
- }
598
- //#endregion
599
- //#region src/progress/label.tsx
600
- /**
601
- * Renders the label `span`.
602
- */
603
- const Named$1 = withContext$4("span", "label");
604
- /**
605
- * Renders the label with the machine's ID.
606
- *
607
- * @param props - The `span` element's props.
608
- * @returns The `span` element.
609
- */
610
- function Label$1(props) {
611
- const $ = c(8);
612
- const api = useProgress();
613
- const { setLabelled } = useLabelling();
614
- let t0;
615
- let t1;
616
- if ($[0] !== setLabelled) {
617
- t0 = () => {
618
- setLabelled(true);
619
- return () => {
620
- setLabelled(false);
621
- };
622
- };
623
- t1 = [setLabelled];
624
- $[0] = setLabelled;
625
- $[1] = t0;
626
- $[2] = t1;
627
- } else {
628
- t0 = $[1];
629
- t1 = $[2];
630
- }
631
- useSafeLayoutEffect(t0, t1);
632
- let t2;
633
- if ($[3] !== api || $[4] !== props) {
634
- t2 = mergeProps(api.getLabelProps(), props);
635
- $[3] = api;
636
- $[4] = props;
637
- $[5] = t2;
638
- } else t2 = $[5];
639
- let t3;
640
- if ($[6] !== t2) {
641
- t3 = /* @__PURE__ */ jsx(Named$1, { ...t2 });
642
- $[6] = t2;
643
- $[7] = t3;
644
- } else t3 = $[7];
645
- return t3;
646
- }
647
- //#endregion
648
- //#region src/progress/marker.tsx
649
- /**
650
- * Renders the marker `div`.
651
- */
652
- const Marked = withContext$4("div", "marker");
653
- /**
654
- * Renders the marker at its value's share of the range.
655
- *
656
- * @param props - The value and the props of a `div`.
657
- * @returns The `div` element.
658
- */
659
- function Marker(t0) {
660
- const $ = c(16);
661
- let props;
662
- let style;
663
- let value;
664
- if ($[0] !== t0) {
665
- ({style, value, ...props} = t0);
666
- $[0] = t0;
667
- $[1] = props;
668
- $[2] = style;
669
- $[3] = value;
670
- } else {
671
- props = $[1];
672
- style = $[2];
673
- value = $[3];
674
- }
675
- const { max, min } = useProgress();
676
- let t1;
677
- if ($[4] !== max || $[5] !== min || $[6] !== value) {
678
- t1 = getValuePercent(clampValue(value, min, max), min, max);
679
- $[4] = max;
680
- $[5] = min;
681
- $[6] = value;
682
- $[7] = t1;
683
- } else t1 = $[7];
684
- const share = t1 * 100;
685
- const t2 = `${String(share)}%`;
686
- let t3;
687
- if ($[8] !== t2) {
688
- t3 = { [MARKER]: t2 };
689
- $[8] = t2;
690
- $[9] = t3;
691
- } else t3 = $[9];
692
- const placed = t3;
693
- let t4;
694
- if ($[10] !== placed || $[11] !== style) {
695
- t4 = {
696
- ...placed,
697
- ...style
698
- };
699
- $[10] = placed;
700
- $[11] = style;
701
- $[12] = t4;
702
- } else t4 = $[12];
703
- let t5;
704
- if ($[13] !== props || $[14] !== t4) {
705
- t5 = /* @__PURE__ */ jsx(Marked, {
706
- "aria-hidden": true,
707
- ...props,
708
- style: t4
709
- });
710
- $[13] = props;
711
- $[14] = t4;
712
- $[15] = t5;
713
- } else t5 = $[15];
714
- return t5;
715
- }
716
- //#endregion
717
- //#region src/progress/range.tsx
718
- /**
719
- * Renders the range `div`.
720
- */
721
- const Filled$1 = withContext$4("div", "range");
722
- /**
723
- * Renders the range with the machine's width and state.
724
- *
725
- * @param props - The `div` element's props.
726
- * @returns The `div` element.
727
- */
728
- function Range$1(props) {
729
- const $ = c(5);
730
- const api = useProgress();
731
- let t0;
732
- if ($[0] !== api || $[1] !== props) {
733
- t0 = mergeProps(api.getRangeProps(), props);
734
- $[0] = api;
735
- $[1] = props;
736
- $[2] = t0;
737
- } else t0 = $[2];
738
- let t1;
739
- if ($[3] !== t0) {
740
- t1 = /* @__PURE__ */ jsx(Filled$1, { ...t0 });
741
- $[3] = t0;
742
- $[4] = t1;
743
- } else t1 = $[4];
744
- return t1;
745
- }
746
- //#endregion
747
- //#region src/progress/segment.tsx
748
- /**
749
- * Renders the segment `span`.
750
- */
751
- const Filled = withContext$4("span", "segment");
752
- /**
753
- * Renders the segment at its value's share of the range, in its color.
754
- *
755
- * @param props - The value, the color and the props of a `span`.
756
- * @returns The `span` element.
757
- */
758
- function Segment(t0) {
759
- const $ = c(16);
760
- let color;
761
- let props;
762
- let style;
763
- let value;
764
- if ($[0] !== t0) {
765
- ({color, style, value, ...props} = t0);
766
- $[0] = t0;
767
- $[1] = color;
768
- $[2] = props;
769
- $[3] = style;
770
- $[4] = value;
771
- } else {
772
- color = $[1];
773
- props = $[2];
774
- style = $[3];
775
- value = $[4];
776
- }
777
- const { max, min } = useProgress();
778
- const share = clampValue(value, 0, max - min) / (max - min) * 100;
779
- const t1 = `${String(share)}%`;
780
- let t2;
781
- if ($[5] !== t1) {
782
- t2 = { [SHARE]: t1 };
783
- $[5] = t1;
784
- $[6] = t2;
785
- } else t2 = $[6];
786
- const sized = t2;
787
- let t3;
788
- if ($[7] !== color) {
789
- t3 = { [TINT]: color };
790
- $[7] = color;
791
- $[8] = t3;
792
- } else t3 = $[8];
793
- let t4;
794
- if ($[9] !== sized || $[10] !== style) {
795
- t4 = {
796
- ...sized,
797
- ...style
798
- };
799
- $[9] = sized;
800
- $[10] = style;
801
- $[11] = t4;
802
- } else t4 = $[11];
803
- let t5;
804
- if ($[12] !== props || $[13] !== t3 || $[14] !== t4) {
805
- t5 = /* @__PURE__ */ jsx(Filled, {
806
- ...props,
807
- ...t3,
808
- style: t4
809
- });
810
- $[12] = props;
811
- $[13] = t3;
812
- $[14] = t4;
813
- $[15] = t5;
814
- } else t5 = $[15];
815
- return t5;
816
- }
817
- //#endregion
818
- //#region src/progress/track.tsx
819
- /**
820
- * Renders the track, which is the progress bar or the meter a screen reader reports.
821
- *
822
- * @remarks
823
- * The machine writes the value range on the track and the `progressbar` role, which the track
824
- * replaces with `meter` inside `Meter.Root`. A rendered label names the track through
825
- * `aria-labelledby`. Without one, pass `aria-label`. The track states the formatted value as
826
- * `aria-valuetext` while the value is known, so a screen reader reads `62%` or a count in the
827
- * caller's units rather than the raw number. A caller replaces it with words through
828
- * `aria-valuetext`, such as a password's strength or a target.
829
- */
830
- /**
831
- * Renders the track `div`.
832
- */
833
- const Tracked = withContext$4("div", "track");
834
- /**
835
- * Renders the track in its root's role, named by the label once it renders.
836
- *
837
- * @param props - The `div` element's props.
838
- * @returns The `div` element.
839
- */
840
- function Track$1(props) {
841
- const $ = c(8);
842
- const api = useProgress();
843
- const role = use(RoleContext);
844
- const { id, labelled } = useLabelling();
845
- let t0;
846
- if ($[0] !== api || $[1] !== id || $[2] !== labelled || $[3] !== props || $[4] !== role) {
847
- t0 = mergeProps(api.getTrackProps(), {
848
- "aria-labelledby": labelled ? id : void 0,
849
- "aria-valuetext": api.indeterminate ? void 0 : api.valueAsString,
850
- role
851
- }, props);
852
- $[0] = api;
853
- $[1] = id;
854
- $[2] = labelled;
855
- $[3] = props;
856
- $[4] = role;
857
- $[5] = t0;
858
- } else t0 = $[5];
859
- let t1;
860
- if ($[6] !== t0) {
861
- t1 = /* @__PURE__ */ jsx(Tracked, { ...t0 });
862
- $[6] = t0;
863
- $[7] = t1;
864
- } else t1 = $[7];
865
- return t1;
866
- }
867
- //#endregion
868
- //#region src/progress/value-text.tsx
869
- /**
870
- * Renders the value `span`.
871
- */
872
- const Valued$1 = withContext$4("span", "valueText");
873
- /**
874
- * Renders the children, or the formatted value.
875
- *
876
- * @param props - The `span` element's props.
877
- * @returns The `span` element.
878
- */
879
- function ValueText$1(t0) {
880
- const $ = c(4);
881
- const { children, ...rest } = t0;
882
- const api = useProgress();
883
- const T0 = Valued$1;
884
- const t1 = mergeProps(api.getValueTextProps(), { "aria-live": "off" }, rest);
885
- const t2 = children ?? (api.indeterminate ? null : api.valueAsString);
886
- let t3;
887
- if ($[0] !== T0 || $[1] !== t1 || $[2] !== t2) {
888
- t3 = /* @__PURE__ */ jsx(T0, {
889
- ...t1,
890
- children: t2
891
- });
892
- $[0] = T0;
893
- $[1] = t1;
894
- $[2] = t2;
895
- $[3] = t3;
896
- } else t3 = $[3];
897
- return t3;
898
- }
899
- //#endregion
900
- //#region src/meter/index.ts
901
- var meter_exports = /* @__PURE__ */ __exportAll({
902
- Label: () => Label$1,
903
- Marker: () => Marker,
904
- Range: () => Range$1,
905
- Root: () => Root$2,
906
- Segment: () => Segment,
907
- Track: () => Track$1,
908
- ValueText: () => ValueText$1
909
- });
910
- //#endregion
911
- //#region src/progress-circle/context.ts
912
- /**
913
- * Binds the progress circle recipe to React.
914
- *
915
- * @remarks
916
- * The binding is a separate module because an application's compiler reads `recipe.ts` at build
917
- * time and the binding needs the runtime. The behaviour is the progress bar's `machine.ts`.
918
- */
919
- /**
920
- * Binds the recipe once. The root receives the variants and every other part reads them.
921
- */
922
- const { withContext: withContext$3, withProvider: withProvider$1 } = createSlotRecipeContext(recipe$5);
923
- //#endregion
924
- //#region src/progress-circle/circle.tsx
925
- /**
926
- * Renders the ring `svg`.
927
- */
928
- const Ring = withContext$3("svg", "circle");
929
- /**
930
- * Renders the ring with the machine's progress bar props, named by the label once it renders.
931
- *
932
- * @param props - The `svg` element's props and its circles.
933
- * @returns The `svg` element.
934
- */
935
- function Circle(props) {
936
- const $ = c(7);
937
- const api = useProgress();
938
- const { id, labelled } = useLabelling();
939
- let t0;
940
- if ($[0] !== api || $[1] !== id || $[2] !== labelled || $[3] !== props) {
941
- t0 = mergeProps(api.getCircleProps(), {
942
- "aria-labelledby": labelled ? id : void 0,
943
- "aria-valuetext": api.indeterminate ? void 0 : api.valueAsString
944
- }, props);
945
- $[0] = api;
946
- $[1] = id;
947
- $[2] = labelled;
948
- $[3] = props;
949
- $[4] = t0;
950
- } else t0 = $[4];
951
- let t1;
952
- if ($[5] !== t0) {
953
- t1 = /* @__PURE__ */ jsx(Ring, { ...t0 });
954
- $[5] = t0;
955
- $[6] = t1;
956
- } else t1 = $[6];
957
- return t1;
958
- }
959
- //#endregion
960
- //#region src/progress-circle/label.tsx
961
- /**
962
- * Renders the label `span`.
963
- */
964
- const Named = withContext$3("span", "label");
965
- /**
966
- * Renders the label with the machine's ID.
967
- *
968
- * @param props - The `span` element's props.
969
- * @returns The `span` element.
970
- */
971
- function Label(props) {
972
- const $ = c(8);
973
- const api = useProgress();
974
- const { setLabelled } = useLabelling();
975
- let t0;
976
- let t1;
977
- if ($[0] !== setLabelled) {
978
- t0 = () => {
979
- setLabelled(true);
980
- return () => {
981
- setLabelled(false);
982
- };
983
- };
984
- t1 = [setLabelled];
985
- $[0] = setLabelled;
986
- $[1] = t0;
987
- $[2] = t1;
988
- } else {
989
- t0 = $[1];
990
- t1 = $[2];
991
- }
992
- useSafeLayoutEffect(t0, t1);
993
- let t2;
994
- if ($[3] !== api || $[4] !== props) {
995
- t2 = mergeProps(api.getLabelProps(), props);
996
- $[3] = api;
997
- $[4] = props;
998
- $[5] = t2;
999
- } else t2 = $[5];
1000
- let t3;
1001
- if ($[6] !== t2) {
1002
- t3 = /* @__PURE__ */ jsx(Named, { ...t2 });
1003
- $[6] = t2;
1004
- $[7] = t3;
1005
- } else t3 = $[7];
1006
- return t3;
1007
- }
1008
- //#endregion
1009
- //#region src/progress-circle/range.tsx
1010
- /**
1011
- * Renders the range `circle`.
1012
- */
1013
- const Arc = withContext$3("circle", "range");
1014
- /**
1015
- * Renders the range with the machine's geometry and state.
1016
- *
1017
- * @param props - The `circle` element's props.
1018
- * @returns The `circle` element.
1019
- */
1020
- function Range(props) {
1021
- const $ = c(5);
1022
- const t0 = useProgress();
1023
- let t1;
1024
- if ($[0] !== props || $[1] !== t0) {
1025
- t1 = mergeProps(t0.getCircleRangeProps(), props);
1026
- $[0] = props;
1027
- $[1] = t0;
1028
- $[2] = t1;
1029
- } else t1 = $[2];
1030
- let t2;
1031
- if ($[3] !== t1) {
1032
- t2 = /* @__PURE__ */ jsx(Arc, { ...t1 });
1033
- $[3] = t1;
1034
- $[4] = t2;
1035
- } else t2 = $[4];
1036
- return t2;
1037
- }
1038
- //#endregion
1039
- //#region src/progress-circle/root.tsx
1040
- /**
1041
- * Renders the ring's grid and runs the machine that tracks its value.
1042
- *
1043
- * @remarks
1044
- * The root is a `div` without a role. The `svg` inside it is the progress bar. `value` sets the
1045
- * value between `min` and `max`, 0 and 100 by default, and `null` renders a ring whose value is
1046
- * not known. Without `value` or `defaultValue` the machine starts halfway. The ring runs the
1047
- * progress bar's machine and names itself the same way.
1048
- */
1049
- /**
1050
- * Renders the root `div` and provides the variants to the parts.
1051
- */
1052
- const Gridded = withProvider$1("div", "root");
1053
- /**
1054
- * Renders the ring's grid and provides the machine's API and the label's state to its parts.
1055
- *
1056
- * @param props - The machine settings, the recipe's variants and the `div` props.
1057
- * @returns The `div` element.
1058
- */
1059
- function Root$1(props) {
1060
- const $ = c(16);
1061
- let t0;
1062
- if ($[0] !== props) {
1063
- t0 = splitProgressProps(props);
1064
- $[0] = props;
1065
- $[1] = t0;
1066
- } else t0 = $[1];
1067
- const [options, rest] = t0;
1068
- const { api, labelId } = useProgressMachine(options);
1069
- const [labelled, setLabelled] = useState(false);
1070
- let t1;
1071
- if ($[2] !== labelId || $[3] !== labelled) {
1072
- t1 = {
1073
- id: labelId,
1074
- labelled,
1075
- setLabelled
1076
- };
1077
- $[2] = labelId;
1078
- $[3] = labelled;
1079
- $[4] = t1;
1080
- } else t1 = $[4];
1081
- let t2;
1082
- if ($[5] !== api) {
1083
- t2 = api.getRootProps();
1084
- $[5] = api;
1085
- $[6] = t2;
1086
- } else t2 = $[6];
1087
- let t3;
1088
- if ($[7] !== rest || $[8] !== t2) {
1089
- t3 = /* @__PURE__ */ jsx(Gridded, {
1090
- ...rest,
1091
- ...t2
1092
- });
1093
- $[7] = rest;
1094
- $[8] = t2;
1095
- $[9] = t3;
1096
- } else t3 = $[9];
1097
- let t4;
1098
- if ($[10] !== t1 || $[11] !== t3) {
1099
- t4 = /* @__PURE__ */ jsx(LabellingProvider, {
1100
- value: t1,
1101
- children: t3
1102
- });
1103
- $[10] = t1;
1104
- $[11] = t3;
1105
- $[12] = t4;
1106
- } else t4 = $[12];
1107
- let t5;
1108
- if ($[13] !== api || $[14] !== t4) {
1109
- t5 = /* @__PURE__ */ jsx(ApiProvider$1, {
1110
- value: api,
1111
- children: t4
1112
- });
1113
- $[13] = api;
1114
- $[14] = t4;
1115
- $[15] = t5;
1116
- } else t5 = $[15];
1117
- return t5;
1118
- }
1119
- //#endregion
1120
- //#region src/progress-circle/track.tsx
1121
- /**
1122
- * Renders the track `circle`.
1123
- */
1124
- const Whole = withContext$3("circle", "track");
1125
- /**
1126
- * Renders the track with the machine's geometry.
1127
- *
1128
- * @param props - The `circle` element's props.
1129
- * @returns The `circle` element.
1130
- */
1131
- function Track(props) {
1132
- const $ = c(5);
1133
- const t0 = useProgress();
1134
- let t1;
1135
- if ($[0] !== props || $[1] !== t0) {
1136
- t1 = mergeProps(t0.getCircleTrackProps(), props);
1137
- $[0] = props;
1138
- $[1] = t0;
1139
- $[2] = t1;
1140
- } else t1 = $[2];
1141
- let t2;
1142
- if ($[3] !== t1) {
1143
- t2 = /* @__PURE__ */ jsx(Whole, { ...t1 });
1144
- $[3] = t1;
1145
- $[4] = t2;
1146
- } else t2 = $[4];
1147
- return t2;
1148
- }
1149
- //#endregion
1150
- //#region src/progress-circle/value-text.tsx
1151
- /**
1152
- * Renders the value `span`.
1153
- */
1154
- const Valued = withContext$3("span", "valueText");
1155
- /**
1156
- * Renders the children, or the formatted value.
1157
- *
1158
- * @param props - The `span` element's props.
1159
- * @returns The `span` element.
1160
- */
1161
- function ValueText(t0) {
1162
- const $ = c(4);
1163
- const { children, ...rest } = t0;
1164
- const api = useProgress();
1165
- const T0 = Valued;
1166
- const t1 = mergeProps(api.getValueTextProps(), { "aria-live": "off" }, rest);
1167
- const t2 = children ?? (api.indeterminate ? null : api.valueAsString);
1168
- let t3;
1169
- if ($[0] !== T0 || $[1] !== t1 || $[2] !== t2) {
1170
- t3 = /* @__PURE__ */ jsx(T0, {
1171
- ...t1,
1172
- children: t2
1173
- });
1174
- $[0] = T0;
1175
- $[1] = t1;
1176
- $[2] = t2;
1177
- $[3] = t3;
1178
- } else t3 = $[3];
1179
- return t3;
1180
- }
1181
- //#endregion
1182
- //#region src/progress-circle/index.ts
1183
- var progress_circle_exports = /* @__PURE__ */ __exportAll({
1184
- Circle: () => Circle,
1185
- Label: () => Label,
1186
- Range: () => Range,
1187
- Root: () => Root$1,
1188
- Track: () => Track,
1189
- ValueText: () => ValueText
1190
- });
1191
- //#endregion
1192
- //#region src/progress/index.ts
1193
- var progress_exports = /* @__PURE__ */ __exportAll({
1194
- Label: () => Label$1,
1195
- Marker: () => Marker,
1196
- Range: () => Range$1,
1197
- Root: () => Root$3,
1198
- Segment: () => Segment,
1199
- Track: () => Track$1,
1200
- ValueText: () => ValueText$1
1201
- });
1202
- //#endregion
1203
- //#region src/skeleton-text/context.ts
1204
- /**
1205
- * Binds the skeleton text recipe to React.
1206
- *
1207
- * @remarks
1208
- * The binding is a separate module from the recipe, because an application's compiler imports the
1209
- * recipe at build time and the binding needs the React runtime.
1210
- */
1211
- /**
1212
- * Factory for the column and the provider that sets its props for descendants.
1213
- */
1214
- const { PropsProvider: PropsProvider$1, withContext: withContext$2 } = createRecipeContext(recipe$6);
1215
- //#endregion
1216
- //#region src/skeleton/context.ts
1217
- /**
1218
- * Binds the skeleton recipe to React.
1219
- *
1220
- * @remarks
1221
- * The binding is a separate module from the recipe, because an application's compiler imports the
1222
- * recipe at build time and the binding needs the React runtime.
1223
- */
1224
- /**
1225
- * Factory for the skeleton and the skeleton text bars, and the provider that sets their variants
1226
- * for descendants.
1227
- */
1228
- const { PropsProvider, withContext: withContext$1 } = createRecipeContext(recipe$7);
1229
- //#endregion
1230
- //#region src/skeleton/skeleton.ts
1231
- /**
1232
- * Renders a div that takes the box of the content it wraps.
1233
- */
1234
- const Skeleton = withContext$1("div");
1235
- //#endregion
1236
- //#region src/skeleton-text/skeleton-text.tsx
1237
- /**
1238
- * Div with the skeleton text classes.
1239
- */
1240
- const Column = withContext$2("div");
1241
- /**
1242
- * Renders a column of `Skeleton` bars, one per line.
1243
- *
1244
- * @remarks
1245
- * `motion` and `radius` are left out of the bar props when undefined, because an explicit
1246
- * `undefined` overrides the value an enclosing `SkeletonPropsProvider` sets.
1247
- */
1248
- function SkeletonText(t0) {
1249
- const $ = c(20);
1250
- let motion;
1251
- let radius;
1252
- let rest;
1253
- let t1;
1254
- if ($[0] !== t0) {
1255
- ({lines: t1, motion, radius, ...rest} = t0);
1256
- $[0] = t0;
1257
- $[1] = motion;
1258
- $[2] = radius;
1259
- $[3] = rest;
1260
- $[4] = t1;
1261
- } else {
1262
- motion = $[1];
1263
- radius = $[2];
1264
- rest = $[3];
1265
- t1 = $[4];
1266
- }
1267
- const lines = t1 === void 0 ? 3 : t1;
1268
- let t2;
1269
- if ($[5] !== motion) {
1270
- t2 = motion === void 0 ? {} : { motion };
1271
- $[5] = motion;
1272
- $[6] = t2;
1273
- } else t2 = $[6];
1274
- let t3;
1275
- if ($[7] !== radius) {
1276
- t3 = radius === void 0 ? {} : { radius };
1277
- $[7] = radius;
1278
- $[8] = t3;
1279
- } else t3 = $[8];
1280
- let t4;
1281
- if ($[9] !== t2 || $[10] !== t3) {
1282
- t4 = {
1283
- ...t2,
1284
- ...t3
1285
- };
1286
- $[9] = t2;
1287
- $[10] = t3;
1288
- $[11] = t4;
1289
- } else t4 = $[11];
1290
- const drawn = t4;
1291
- let t5;
1292
- if ($[12] !== drawn || $[13] !== lines) {
1293
- let t6;
1294
- if ($[15] !== drawn) {
1295
- t6 = (_, at) => /* @__PURE__ */ jsx(Skeleton, { ...drawn }, at);
1296
- $[15] = drawn;
1297
- $[16] = t6;
1298
- } else t6 = $[16];
1299
- t5 = Array.from({ length: Math.max(lines, 1) }, t6);
1300
- $[12] = drawn;
1301
- $[13] = lines;
1302
- $[14] = t5;
1303
- } else t5 = $[14];
1304
- let t6;
1305
- if ($[17] !== rest || $[18] !== t5) {
1306
- t6 = /* @__PURE__ */ jsx(Column, {
1307
- ...rest,
1308
- children: t5
1309
- });
1310
- $[17] = rest;
1311
- $[18] = t5;
1312
- $[19] = t6;
1313
- } else t6 = $[19];
1314
- return t6;
1315
- }
1316
- //#endregion
1317
- //#region src/toast/context.ts
1318
- /**
1319
- * Binds the toast's recipe to its parts.
1320
- *
1321
- * @remarks
1322
- * The binding is apart from the recipe, because a compiler reads the recipe at build time and the
1323
- * binding imports the runtime. It is apart from the machine, because the recipe styles a part and
1324
- * the machine sets its behaviour.
1325
- */
1326
- /**
1327
- * Binds the recipe once. The region provides the variants and every other part reads them.
1328
- */
1329
- const { withContext, withProvider } = createSlotRecipeContext(recipe$8);
1330
- //#endregion
1331
- //#region src/toast/machine.ts
1332
- /**
1333
- * Connects the toast machines and provides a toast's api to its parts.
1334
- *
1335
- * @remarks
1336
- * A toaster is the store an application raises toasts into. `Toast.Region` runs the group machine
1337
- * for one toaster, and each toast in the region runs a machine of its own, whose api the toast's
1338
- * parts read from context. The group machine derives the region's id from the toaster's
1339
- * placement, so a page renders one region per placement.
1340
- */
1341
- /**
1342
- * Creates the context through which each toast provides its api to its parts.
1343
- *
1344
- * @remarks
1345
- * `useToast` throws when no toast of a `Toast.Region` is rendering the calling part.
1346
- */
1347
- const [ApiProvider, useToast] = createRequiredContext("Toast");
1348
- /**
1349
- * Starts the group machine for one toaster and returns its api and service.
1350
- *
1351
- * @param toaster - The store the region renders the toasts of.
1352
- * @param dir - The text direction, which mirrors the start and end placements.
1353
- */
1354
- function useRegionMachine(toaster, dir) {
1355
- const $ = c(11);
1356
- let t0;
1357
- if ($[0] !== dir) {
1358
- t0 = omitUndefined({ dir });
1359
- $[0] = dir;
1360
- $[1] = t0;
1361
- } else t0 = $[1];
1362
- const t1 = useId();
1363
- let t2;
1364
- if ($[2] !== t0 || $[3] !== t1 || $[4] !== toaster) {
1365
- t2 = {
1366
- ...t0,
1367
- id: t1,
1368
- store: toaster
1369
- };
1370
- $[2] = t0;
1371
- $[3] = t1;
1372
- $[4] = toaster;
1373
- $[5] = t2;
1374
- } else t2 = $[5];
1375
- const service = useMachine(toast.group.machine, t2);
1376
- let t3;
1377
- if ($[6] !== service) {
1378
- t3 = toast.group.connect(service, normalizeProps);
1379
- $[6] = service;
1380
- $[7] = t3;
1381
- } else t3 = $[7];
1382
- let t4;
1383
- if ($[8] !== service || $[9] !== t3) {
1384
- t4 = {
1385
- api: t3,
1386
- service
1387
- };
1388
- $[8] = service;
1389
- $[9] = t3;
1390
- $[10] = t4;
1391
- } else t4 = $[10];
1392
- return t4;
1393
- }
1394
- /**
1395
- * Starts the machine of one toast and returns its connected api.
1396
- *
1397
- * @param options - The toast as the toaster holds it.
1398
- * @param parent - The group machine's service.
1399
- * @param index - The toast's place in the region, the newest first.
1400
- */
1401
- function useToastMachine(options, parent, index) {
1402
- const $ = c(8);
1403
- let t0;
1404
- if ($[0] !== options) {
1405
- t0 = omitUndefined(options);
1406
- $[0] = options;
1407
- $[1] = t0;
1408
- } else t0 = $[1];
1409
- let t1;
1410
- if ($[2] !== index || $[3] !== parent || $[4] !== t0) {
1411
- t1 = {
1412
- ...t0,
1413
- index,
1414
- parent
1415
- };
1416
- $[2] = index;
1417
- $[3] = parent;
1418
- $[4] = t0;
1419
- $[5] = t1;
1420
- } else t1 = $[5];
1421
- const service = useMachine(toast.machine, t1);
1422
- let t2;
1423
- if ($[6] !== service) {
1424
- t2 = toast.connect(service, normalizeProps);
1425
- $[6] = service;
1426
- $[7] = t2;
1427
- } else t2 = $[7];
1428
- return t2;
1429
- }
1430
- //#endregion
1431
- //#region src/toast/action-trigger.tsx
1432
- /**
1433
- * Renders the `button` with the toast's action trigger class.
1434
- */
1435
- const Drawn$4 = withContext("button", "actionTrigger");
1436
- /**
1437
- * Renders the action trigger with the machine's props merged over the caller's.
1438
- *
1439
- * @param props - The props of a `button`.
1440
- * @returns The `button` element.
1441
- */
1442
- function ActionTrigger(props) {
1443
- const $ = c(5);
1444
- const api = useToast();
1445
- let t0;
1446
- if ($[0] !== api || $[1] !== props) {
1447
- t0 = mergeProps(api.getActionTriggerProps(), props);
1448
- $[0] = api;
1449
- $[1] = props;
1450
- $[2] = t0;
1451
- } else t0 = $[2];
1452
- let t1;
1453
- if ($[3] !== t0) {
1454
- t1 = /* @__PURE__ */ jsx(Drawn$4, { ...t0 });
1455
- $[3] = t0;
1456
- $[4] = t1;
1457
- } else t1 = $[4];
1458
- return t1;
1459
- }
1460
- //#endregion
1461
- //#region src/toast/close-trigger.tsx
1462
- /**
1463
- * Renders the `button` with the toast's close trigger class.
1464
- */
1465
- const Drawn$3 = withContext("button", "closeTrigger");
1466
- /**
1467
- * Renders the close trigger with the machine's props merged over the caller's.
1468
- *
1469
- * @param props - The props of a `button`.
1470
- * @returns The `button` element.
1471
- */
1472
- function CloseTrigger(props) {
1473
- const $ = c(5);
1474
- const api = useToast();
1475
- let t0;
1476
- if ($[0] !== api || $[1] !== props) {
1477
- t0 = mergeProps(api.getCloseTriggerProps(), props);
1478
- $[0] = api;
1479
- $[1] = props;
1480
- $[2] = t0;
1481
- } else t0 = $[2];
1482
- let t1;
1483
- if ($[3] !== t0) {
1484
- t1 = /* @__PURE__ */ jsx(Drawn$3, { ...t0 });
1485
- $[3] = t0;
1486
- $[4] = t1;
1487
- } else t1 = $[4];
1488
- return t1;
1489
- }
1490
- //#endregion
1491
- //#region src/toast/content.ts
1492
- /**
1493
- * Renders the column of the title and the description.
1494
- */
1495
- const Content = withContext("div", "content");
1496
- //#endregion
1497
- //#region src/toast/description.tsx
1498
- /**
1499
- * Renders the `div` with the toast's description class.
1500
- */
1501
- const Drawn$2 = withContext("div", "description");
1502
- /**
1503
- * Renders the description with the machine's description props merged over the caller's.
1504
- *
1505
- * @param props - The props of a `div`.
1506
- * @returns The `div` element.
1507
- */
1508
- function Description(props) {
1509
- const $ = c(5);
1510
- const api = useToast();
1511
- let t0;
1512
- if ($[0] !== api || $[1] !== props) {
1513
- t0 = mergeProps(api.getDescriptionProps(), props);
1514
- $[0] = api;
1515
- $[1] = props;
1516
- $[2] = t0;
1517
- } else t0 = $[2];
1518
- let t1;
1519
- if ($[3] !== t0) {
1520
- t1 = /* @__PURE__ */ jsx(Drawn$2, { ...t0 });
1521
- $[3] = t0;
1522
- $[4] = t1;
1523
- } else t1 = $[4];
1524
- return t1;
1525
- }
1526
- //#endregion
1527
- //#region src/toast/indicator.ts
1528
- /**
1529
- * Renders a `span` hidden from the accessibility tree by default.
1530
- */
1531
- const Indicator = withContext("span", "indicator", { defaultProps: { "aria-hidden": true } });
1532
- //#endregion
1533
- //#region src/toast/actor.tsx
1534
- /**
1535
- * Runs the toast's machine and renders what the render function returns for the toast.
1536
- *
1537
- * @param props - The toast, its place, the region's service and the render function.
1538
- * @returns The rendered toast inside the api's provider.
1539
- */
1540
- function Actor(t0) {
1541
- const $ = c(6);
1542
- const { index, parent, render, value } = t0;
1543
- const api = useToastMachine(value, parent, index);
1544
- let t1;
1545
- if ($[0] !== render || $[1] !== value) {
1546
- t1 = render(value);
1547
- $[0] = render;
1548
- $[1] = value;
1549
- $[2] = t1;
1550
- } else t1 = $[2];
1551
- let t2;
1552
- if ($[3] !== api || $[4] !== t1) {
1553
- t2 = /* @__PURE__ */ jsx(ApiProvider, {
1554
- value: api,
1555
- children: t1
1556
- });
1557
- $[3] = api;
1558
- $[4] = t1;
1559
- $[5] = t2;
1560
- } else t2 = $[5];
1561
- return t2;
1562
- }
1563
- //#endregion
1564
- //#region src/toast/region.tsx
1565
- /**
1566
- * Renders the region a toaster raises its toasts into, and each toast through a render function.
1567
- *
1568
- * @remarks
1569
- * The machine makes the element a `region` landmark named `<label>, <placement> (alt+T)`, fixes
1570
- * it to the placement's edge of the window, and announces each new toast through
1571
- * `aria-live="polite"`. Alt+T moves focus to the newest toast, and when the toast that has focus
1572
- * leaves, focus returns to the element it entered the region from. A pointer resting on the
1573
- * region, or focus inside it, pauses every toast. The machine derives the region's id from the
1574
- * placement, so a page renders one region per placement. While the toaster's `pauseOnPageIdle` is
1575
- * true, the region pauses every toast when the page is hidden and resumes them when it shows
1576
- * again, because the machine sends that pause to no handler.
1577
- */
1578
- /**
1579
- * Renders the `div` that provides the recipe's variants.
1580
- */
1581
- const Framed = withProvider("div", "region");
1582
- /**
1583
- * Selects the root of a toast by the class the binding writes.
1584
- */
1585
- const ROOT = `.${recipe$8.className}__root`;
1586
- /**
1587
- * Pauses every toast of a toaster while the page is hidden.
1588
- *
1589
- * @param toaster - The store whose toasts pause.
1590
- */
1591
- function useIdlePause(toaster) {
1592
- const $ = c(3);
1593
- let t0;
1594
- let t1;
1595
- if ($[0] !== toaster) {
1596
- t0 = () => {
1597
- const changed = function changed() {
1598
- if (document.visibilityState === "hidden") toaster.pause();
1599
- else toaster.resume();
1600
- };
1601
- if (toaster.attrs.pauseOnPageIdle) document.addEventListener("visibilitychange", changed);
1602
- return () => {
1603
- document.removeEventListener("visibilitychange", changed);
1604
- };
1605
- };
1606
- t1 = [toaster];
1607
- $[0] = toaster;
1608
- $[1] = t0;
1609
- $[2] = t1;
1610
- } else {
1611
- t0 = $[1];
1612
- t1 = $[2];
1613
- }
1614
- useEffect(t0, t1);
1615
- }
1616
- /**
1617
- * Returns focus to the element it entered the region from when the toast that has it leaves.
1618
- *
1619
- * @remarks
1620
- * The machine returns focus only when focus leaves the region while no pointer rests on it. A
1621
- * toast that leaves while it has focus takes focus with it, and the browser moves focus to the
1622
- * document's body, so the region moves it back after the render that removed the toast. The
1623
- * check runs after every render of the region, because the region renders again whenever a
1624
- * toast enters or leaves.
1625
- */
1626
- function useFocusReturn() {
1627
- const $ = c(2);
1628
- const came = useRef(null);
1629
- const within = useRef(false);
1630
- let t0;
1631
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1632
- t0 = () => {
1633
- if (!within.current || document.activeElement !== document.body) return;
1634
- within.current = false;
1635
- came.current?.focus();
1636
- };
1637
- $[0] = t0;
1638
- } else t0 = $[0];
1639
- useLayoutEffect(t0);
1640
- let t1;
1641
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
1642
- t1 = {
1643
- onBlur: (event) => {
1644
- if (!event.currentTarget.contains(event.relatedTarget)) within.current = false;
1645
- },
1646
- onFocus: (event_0) => {
1647
- if (within.current) return;
1648
- within.current = true;
1649
- came.current = event_0.relatedTarget instanceof HTMLElement ? event_0.relatedTarget : null;
1650
- }
1651
- };
1652
- $[1] = t1;
1653
- } else t1 = $[1];
1654
- return t1;
1655
- }
1656
- /**
1657
- * Moves focus from the region itself to the newest toast, or back to the element it came from
1658
- * while the region has no toast.
1659
- *
1660
- * @remarks
1661
- * Alt+T focuses the region, an element of no size at the window's edge, so a person sees no focus
1662
- * indicator on it. The newest toast is the first in the region. It shows the focus ring and
1663
- * takes Escape. The region merges this handler after the machine's, so the machine records the
1664
- * element that focus came from before focus moves on.
1665
- */
1666
- function forwarded(event) {
1667
- if (event.target !== event.currentTarget) return;
1668
- const came = event.relatedTarget instanceof HTMLElement ? event.relatedTarget : null;
1669
- (event.currentTarget.querySelector(ROOT) ?? came)?.focus();
1670
- }
1671
- /**
1672
- * Renders the region with the group machine's props merged over the caller's, and each toast.
1673
- *
1674
- * @param props - The toaster, the name, the direction, the render function and the props of a
1675
- * `div`.
1676
- * @returns The `div` element.
1677
- */
1678
- function Region(t0) {
1679
- const $ = c(11);
1680
- const { children, dir, label: t1, toaster, ...props } = t0;
1681
- const label = t1 === void 0 ? "Notifications" : t1;
1682
- const { api, service } = useRegionMachine(toaster, dir);
1683
- const focusReturn = useFocusReturn();
1684
- useIdlePause(toaster);
1685
- const T0 = Framed;
1686
- const t2 = mergeProps({ onFocus: forwarded }, api.getGroupProps({ label }), focusReturn, props);
1687
- let t3;
1688
- if ($[0] !== api || $[1] !== children || $[2] !== service) {
1689
- let t4;
1690
- if ($[4] !== children || $[5] !== service) {
1691
- t4 = (value, index) => /* @__PURE__ */ jsx(Actor, {
1692
- index,
1693
- parent: service,
1694
- render: children,
1695
- value
1696
- }, value.id);
1697
- $[4] = children;
1698
- $[5] = service;
1699
- $[6] = t4;
1700
- } else t4 = $[6];
1701
- t3 = api.getToasts().map(t4);
1702
- $[0] = api;
1703
- $[1] = children;
1704
- $[2] = service;
1705
- $[3] = t3;
1706
- } else t3 = $[3];
1707
- let t4;
1708
- if ($[7] !== T0 || $[8] !== t2 || $[9] !== t3) {
1709
- t4 = /* @__PURE__ */ jsx(T0, {
1710
- ...t2,
1711
- children: t3
1712
- });
1713
- $[7] = T0;
1714
- $[8] = t2;
1715
- $[9] = t3;
1716
- $[10] = t4;
1717
- } else t4 = $[10];
1718
- return t4;
1719
- }
1720
- //#endregion
1721
- //#region src/toast/root.tsx
1722
- /**
1723
- * Renders the `div` with the toast's root class.
1724
- */
1725
- const Drawn$1 = withContext("div", "root");
1726
- /**
1727
- * Renders the toast with the machine's root props merged over the caller's, between the machine's
1728
- * two empty elements.
1729
- *
1730
- * @param props - The props of a `div`.
1731
- * @returns The `div` element.
1732
- */
1733
- function Root(t0) {
1734
- const $ = c(14);
1735
- const { children, ...props } = t0;
1736
- const api = useToast();
1737
- const T0 = Drawn$1;
1738
- const t1 = mergeProps(api.getRootProps(), props);
1739
- let t2;
1740
- if ($[0] !== api) {
1741
- t2 = api.getGhostBeforeProps();
1742
- $[0] = api;
1743
- $[1] = t2;
1744
- } else t2 = $[1];
1745
- let t3;
1746
- if ($[2] !== t2) {
1747
- t3 = /* @__PURE__ */ jsx("div", { ...t2 });
1748
- $[2] = t2;
1749
- $[3] = t3;
1750
- } else t3 = $[3];
1751
- let t4;
1752
- if ($[4] !== api) {
1753
- t4 = api.getGhostAfterProps();
1754
- $[4] = api;
1755
- $[5] = t4;
1756
- } else t4 = $[5];
1757
- let t5;
1758
- if ($[6] !== t4) {
1759
- t5 = /* @__PURE__ */ jsx("div", { ...t4 });
1760
- $[6] = t4;
1761
- $[7] = t5;
1762
- } else t5 = $[7];
1763
- let t6;
1764
- if ($[8] !== T0 || $[9] !== children || $[10] !== t1 || $[11] !== t3 || $[12] !== t5) {
1765
- t6 = /* @__PURE__ */ jsxs(T0, {
1766
- ...t1,
1767
- children: [
1768
- t3,
1769
- children,
1770
- t5
1771
- ]
1772
- });
1773
- $[8] = T0;
1774
- $[9] = children;
1775
- $[10] = t1;
1776
- $[11] = t3;
1777
- $[12] = t5;
1778
- $[13] = t6;
1779
- } else t6 = $[13];
1780
- return t6;
1781
- }
1782
- //#endregion
1783
- //#region src/toast/title.tsx
1784
- /**
1785
- * Renders the `div` with the toast's title class.
1786
- */
1787
- const Drawn = withContext("div", "title");
1788
- /**
1789
- * Renders the title with the machine's title props merged over the caller's.
1790
- *
1791
- * @param props - The props of a `div`.
1792
- * @returns The `div` element.
1793
- */
1794
- function Title(props) {
1795
- const $ = c(5);
1796
- const api = useToast();
1797
- let t0;
1798
- if ($[0] !== api || $[1] !== props) {
1799
- t0 = mergeProps(api.getTitleProps(), props);
1800
- $[0] = api;
1801
- $[1] = props;
1802
- $[2] = t0;
1803
- } else t0 = $[2];
1804
- let t1;
1805
- if ($[3] !== t0) {
1806
- t1 = /* @__PURE__ */ jsx(Drawn, { ...t0 });
1807
- $[3] = t0;
1808
- $[4] = t1;
1809
- } else t1 = $[4];
1810
- return t1;
1811
- }
1812
- //#endregion
1813
- //#region src/toast/index.ts
1814
- var toast_exports = /* @__PURE__ */ __exportAll({
1815
- ActionTrigger: () => ActionTrigger,
1816
- CloseTrigger: () => CloseTrigger,
1817
- Content: () => Content,
1818
- Description: () => Description,
1819
- Indicator: () => Indicator,
1820
- Region: () => Region,
1821
- Root: () => Root,
1822
- Title: () => Title,
1823
- createToaster: () => createToaster
1824
- });
1825
- //#endregion
1
+ import { C as meter_exports, F as empty_state_exports, M as LoaderOverlay, N as Loader, P as Spinner, V as alert_exports, d as SkeletonText, f as Skeleton, g as progress_circle_exports, h as progress_exports, m as PropsProvider$1, n as toast_exports, p as PropsProvider } from "./shared-Xc-n0bn7.js";
1826
2
  export { alert_exports as Alert, empty_state_exports as EmptyState, Loader, LoaderOverlay, meter_exports as Meter, progress_exports as Progress, progress_circle_exports as ProgressCircle, Skeleton, PropsProvider as SkeletonPropsProvider, SkeletonText, PropsProvider$1 as SkeletonTextPropsProvider, Spinner, toast_exports as Toast };