basecoat-css 1.0.2 → 1.2.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 (107) hide show
  1. package/README.md +1 -1
  2. package/dist/base/base.css +11 -1
  3. package/dist/base/scroll-fade.css +41 -0
  4. package/dist/base/transition-details.css +12 -0
  5. package/dist/basecoat-base.bundle.css +2532 -0
  6. package/dist/basecoat-base.cdn.css +1948 -677
  7. package/dist/basecoat-base.cdn.min.css +1 -2
  8. package/dist/basecoat-compat.cdn.css +251 -76
  9. package/dist/basecoat-compat.cdn.min.css +1 -2
  10. package/dist/basecoat-components.css +10 -0
  11. package/dist/basecoat-luma.bundle.css +4309 -0
  12. package/dist/basecoat-luma.cdn.css +5309 -3216
  13. package/dist/basecoat-luma.cdn.min.css +1 -2
  14. package/dist/basecoat-lyra.bundle.css +4287 -0
  15. package/dist/basecoat-lyra.cdn.css +5130 -3099
  16. package/dist/basecoat-lyra.cdn.min.css +1 -2
  17. package/dist/basecoat-maia.bundle.css +4275 -0
  18. package/dist/basecoat-maia.cdn.css +5220 -3158
  19. package/dist/basecoat-maia.cdn.min.css +1 -2
  20. package/dist/basecoat-mira.bundle.css +4284 -0
  21. package/dist/basecoat-mira.cdn.css +3530 -1494
  22. package/dist/basecoat-mira.cdn.min.css +1 -2
  23. package/dist/basecoat-nova.bundle.css +4300 -0
  24. package/dist/basecoat-nova.cdn.css +3685 -1623
  25. package/dist/basecoat-nova.cdn.min.css +1 -2
  26. package/dist/basecoat-rhea.bundle.css +4314 -0
  27. package/dist/basecoat-rhea.cdn.css +5315 -3219
  28. package/dist/basecoat-rhea.cdn.min.css +1 -2
  29. package/dist/basecoat-sera.bundle.css +4295 -0
  30. package/dist/basecoat-sera.cdn.css +3219 -1191
  31. package/dist/basecoat-sera.cdn.min.css +1 -2
  32. package/dist/basecoat-vega.bundle.css +4289 -0
  33. package/dist/basecoat-vega.cdn.css +3681 -1616
  34. package/dist/basecoat-vega.cdn.min.css +1 -2
  35. package/dist/basecoat.bundle.css +4289 -0
  36. package/dist/basecoat.cdn.css +3681 -1616
  37. package/dist/basecoat.cdn.min.css +1 -2
  38. package/dist/compat/legacy.css +3 -18
  39. package/dist/components/accordion.css +15 -1
  40. package/dist/components/alert.css +4 -0
  41. package/dist/components/attachment.css +66 -0
  42. package/dist/components/bubble.css +28 -0
  43. package/dist/components/button-group.css +2 -1
  44. package/dist/components/button.css +23 -0
  45. package/dist/components/carousel.css +30 -0
  46. package/dist/components/checkbox.css +5 -1
  47. package/dist/components/code-block.css +80 -0
  48. package/dist/components/collapsible.css +0 -9
  49. package/dist/components/command.css +13 -0
  50. package/dist/components/dialog.css +13 -1
  51. package/dist/components/drawer.css +48 -14
  52. package/dist/components/input-otp.css +49 -0
  53. package/dist/components/item.css +6 -0
  54. package/dist/components/marker.css +20 -0
  55. package/dist/components/message.css +24 -0
  56. package/dist/components/range.css +7 -0
  57. package/dist/components/scrollbar.css +20 -42
  58. package/dist/components/sheet.css +123 -0
  59. package/dist/components/shimmer.css +49 -0
  60. package/dist/components/sidebar.css +19 -8
  61. package/dist/components/toast.css +59 -44
  62. package/dist/components/tooltip.css +1 -1
  63. package/dist/components/trace.css +34 -0
  64. package/dist/js/all.js +513 -122
  65. package/dist/js/all.min.js +1 -1
  66. package/dist/js/carousel.js +105 -0
  67. package/dist/js/carousel.min.js +1 -0
  68. package/dist/js/code-block.js +47 -0
  69. package/dist/js/code-block.min.js +1 -0
  70. package/dist/js/combobox.js +6 -2
  71. package/dist/js/combobox.min.js +1 -1
  72. package/dist/js/drawer.js +6 -2
  73. package/dist/js/drawer.min.js +1 -1
  74. package/dist/js/dropdown-menu.js +1 -1
  75. package/dist/js/dropdown-menu.min.js +1 -1
  76. package/dist/js/input-otp.js +76 -0
  77. package/dist/js/input-otp.min.js +1 -0
  78. package/dist/js/popover.js +1 -1
  79. package/dist/js/popover.min.js +1 -1
  80. package/dist/js/select.js +1 -1
  81. package/dist/js/select.min.js +1 -1
  82. package/dist/js/sidebar.js +1 -1
  83. package/dist/js/sidebar.min.js +1 -1
  84. package/dist/js/tabs.js +31 -58
  85. package/dist/js/tabs.min.js +1 -1
  86. package/dist/js/toast.js +236 -57
  87. package/dist/js/toast.min.js +1 -1
  88. package/dist/styles/luma.css +451 -50
  89. package/dist/styles/lyra.css +418 -42
  90. package/dist/styles/maia.css +427 -48
  91. package/dist/styles/mira.css +422 -43
  92. package/dist/styles/nova.css +432 -51
  93. package/dist/styles/rhea.css +453 -52
  94. package/dist/styles/sera.css +416 -50
  95. package/dist/styles/vega.css +418 -47
  96. package/dist/typeset.cdn.css +381 -0
  97. package/dist/typeset.cdn.min.css +1 -0
  98. package/dist/typeset.css +435 -0
  99. package/package.json +18 -6
  100. package/templates/jinja/command.html.jinja +1 -1
  101. package/templates/jinja/dialog.html.jinja +1 -1
  102. package/templates/jinja/tabs.html.jinja +0 -1
  103. package/templates/jinja/toast.html.jinja +29 -26
  104. package/templates/nunjucks/command.njk +1 -1
  105. package/templates/nunjucks/dialog.njk +1 -1
  106. package/templates/nunjucks/tabs.njk +1 -1
  107. package/templates/nunjucks/toast.njk +30 -27
package/dist/js/all.js CHANGED
@@ -243,6 +243,160 @@
243
243
  }
244
244
  })();
245
245
 
246
+ (() => {
247
+ function initCarousel(root) {
248
+ if (root.dataset.carouselInitialized) return;
249
+ const track = root.querySelector(':scope > ul');
250
+ const previous = root.querySelector(':scope > button:first-of-type');
251
+ const next = root.querySelector(':scope > button:last-of-type');
252
+ if (!track || !previous || !next || previous === next) return;
253
+
254
+ let target = null;
255
+ let settleTimer;
256
+ const vertical = () => root.dataset.orientation === 'vertical';
257
+ const rtl = () => getComputedStyle(track).direction === 'rtl';
258
+ const position = () => vertical() ? track.scrollTop : Math.abs(track.scrollLeft);
259
+ const maximum = () => Math.max(0, vertical()
260
+ ? track.scrollHeight - track.clientHeight
261
+ : track.scrollWidth - track.clientWidth);
262
+ const update = () => {
263
+ const active = document.activeElement;
264
+ previous.disabled = position() <= 1;
265
+ next.disabled = position() >= maximum() - 1;
266
+ // Keep keyboard focus inside the carousel when the active control disables.
267
+ if ((active === previous || active === next) && active.disabled) {
268
+ const other = active === previous ? next : previous;
269
+ (other.disabled ? track : other).focus({ preventScroll: true });
270
+ }
271
+ };
272
+ const move = (direction) => {
273
+ const bounds = track.getBoundingClientRect();
274
+ const current = position();
275
+ const limit = maximum();
276
+ const points = [...track.children].map(item => {
277
+ const rect = item.getBoundingClientRect();
278
+ const offset = vertical() ? rect.top - bounds.top
279
+ : rtl() ? bounds.right - rect.right : rect.left - bounds.left;
280
+ return Math.max(0, Math.min(limit, current + offset));
281
+ });
282
+ const from = Math.min(limit, target ?? current);
283
+ target = direction > 0
284
+ ? (points.find(point => point > from + 1) ?? limit)
285
+ : (points.findLast(point => point < from - 1) ?? 0);
286
+ track.scrollTo(vertical() ? { top: target } : { left: rtl() ? -target : target });
287
+ };
288
+ const releaseTarget = () => { target = null; };
289
+ const onScroll = () => {
290
+ update();
291
+ clearTimeout(settleTimer);
292
+ settleTimer = setTimeout(releaseTarget, 180);
293
+ };
294
+ const onKeydown = (event) => {
295
+ // Do not intercept keys from links, inputs, or other controls in a slide.
296
+ if (![track, previous, next].includes(event.target) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
297
+ let direction = 0;
298
+ if (vertical()) {
299
+ if (event.key === 'ArrowUp') direction = -1;
300
+ if (event.key === 'ArrowDown') direction = 1;
301
+ } else {
302
+ if (event.key === 'ArrowLeft') direction = rtl() ? 1 : -1;
303
+ if (event.key === 'ArrowRight') direction = rtl() ? -1 : 1;
304
+ }
305
+ if (!direction) return;
306
+ event.preventDefault();
307
+ move(direction);
308
+ };
309
+ const prevClick = () => move(-1);
310
+ const nextClick = () => move(1);
311
+ const resizeObserver = new ResizeObserver(() => { releaseTarget(); update(); });
312
+ const refresh = () => {
313
+ resizeObserver.disconnect();
314
+ resizeObserver.observe(track);
315
+ [...track.children].forEach(item => resizeObserver.observe(item));
316
+ releaseTarget();
317
+ update();
318
+ };
319
+ const mutationObserver = new MutationObserver(refresh);
320
+ mutationObserver.observe(track, { childList: true });
321
+ previous.addEventListener('click', prevClick);
322
+ next.addEventListener('click', nextClick);
323
+ track.addEventListener('scroll', onScroll, { passive: true });
324
+ track.addEventListener('wheel', releaseTarget, { passive: true });
325
+ track.addEventListener('pointerdown', releaseTarget);
326
+ root.addEventListener('keydown', onKeydown);
327
+ previous.hidden = false;
328
+ next.hidden = false;
329
+ root.dataset.carouselInitialized = 'true';
330
+ refresh();
331
+ root.dispatchEvent(new CustomEvent('basecoat:initialized'));
332
+ root._destroy = () => {
333
+ clearTimeout(settleTimer);
334
+ resizeObserver.disconnect();
335
+ mutationObserver.disconnect();
336
+ track.removeEventListener('scroll', onScroll);
337
+ track.removeEventListener('wheel', releaseTarget);
338
+ track.removeEventListener('pointerdown', releaseTarget);
339
+ root.removeEventListener('keydown', onKeydown);
340
+ previous.removeEventListener('click', prevClick);
341
+ next.removeEventListener('click', nextClick);
342
+ previous.hidden = true;
343
+ next.hidden = true;
344
+ };
345
+ }
346
+
347
+ if (window.basecoat) {
348
+ window.basecoat.register('carousel', '.carousel:not([data-carousel-initialized])', initCarousel);
349
+ }
350
+ })();
351
+
352
+ (() => {
353
+ function initCodeBlock(root) {
354
+ if (root.dataset.codeBlockInitialized) return;
355
+ const code = root.querySelector(':scope > pre > code');
356
+ if (!code || !root.querySelector('button[data-copy]')) return;
357
+
358
+ const existingStatus = root.querySelector(':scope > output');
359
+ const status = existingStatus || document.createElement('output');
360
+ if (!existingStatus) root.append(status);
361
+ let timer;
362
+ let active = true;
363
+ const reset = () => {
364
+ root.querySelectorAll('button[data-copy]').forEach(button => delete button.dataset.copied);
365
+ status.textContent = '';
366
+ };
367
+ const onClick = async (event) => {
368
+ const button = event.target.closest('button[data-copy]');
369
+ if (!button || button.closest('.code-block') !== root || button.disabled) return;
370
+ clearTimeout(timer);
371
+ reset();
372
+ try {
373
+ await navigator.clipboard.writeText(code.textContent);
374
+ if (!active || !root.isConnected) return;
375
+ button.dataset.copied = 'true';
376
+ status.textContent = 'Copied to clipboard.';
377
+ timer = setTimeout(reset, 2000);
378
+ } catch (_) {
379
+ if (active) status.textContent = 'Could not copy. Select the code and copy it manually.';
380
+ }
381
+ };
382
+ reset();
383
+ root.addEventListener('click', onClick);
384
+ root.dataset.codeBlockInitialized = 'true';
385
+ root._destroy = () => {
386
+ active = false;
387
+ clearTimeout(timer);
388
+ root.removeEventListener('click', onClick);
389
+ reset();
390
+ if (!existingStatus) status.remove();
391
+ };
392
+ root.dispatchEvent(new CustomEvent('basecoat:initialized'));
393
+ }
394
+
395
+ if (window.basecoat) {
396
+ window.basecoat.register('code-block', '.code-block:not([data-code-block-initialized])', initCodeBlock);
397
+ }
398
+ })();
399
+
246
400
  (() => {
247
401
  const states = new WeakMap();
248
402
 
@@ -837,7 +991,11 @@
837
991
  }
838
992
 
839
993
  if (event.key === 'Escape') {
840
- root.close(true);
994
+ if (isOpen) {
995
+ event.preventDefault();
996
+ event.stopPropagation();
997
+ root.close(true);
998
+ }
841
999
  return;
842
1000
  }
843
1001
 
@@ -950,7 +1108,7 @@
950
1108
  if (!root.contains(event.target)) root.close(false);
951
1109
  };
952
1110
  const handleDocumentPopover = (event) => {
953
- if (event.detail.source !== root) root.close(false);
1111
+ if (!root.contains(event.detail.source)) root.close(false);
954
1112
  };
955
1113
 
956
1114
  state.input.addEventListener('focus', handleInputFocus);
@@ -1041,6 +1199,7 @@
1041
1199
  const nativeClose = drawer.close.bind(drawer);
1042
1200
  let pointerStartedOnBackdrop = false;
1043
1201
  let closeTimer = null;
1202
+ let closeReturnValue = '';
1044
1203
 
1045
1204
  const finishClose = (returnValue) => {
1046
1205
  window.clearTimeout(closeTimer);
@@ -1061,6 +1220,7 @@
1061
1220
  return;
1062
1221
  }
1063
1222
 
1223
+ closeReturnValue = returnValue;
1064
1224
  drawer.dataset.closing = 'true';
1065
1225
  closeTimer = window.setTimeout(() => finishClose(returnValue), duration + 50);
1066
1226
  };
@@ -1086,7 +1246,9 @@
1086
1246
  drawer.addEventListener('pointerup', handlePointerUp);
1087
1247
 
1088
1248
  drawer._destroy = () => {
1089
- window.clearTimeout(closeTimer);
1249
+ // Finish an in-flight close before reinitialization cancels its animation.
1250
+ if (closeTimer !== null) finishClose(closeReturnValue);
1251
+ drawer.removeAttribute('data-closing');
1090
1252
  drawer.removeEventListener('cancel', handleCancel);
1091
1253
  drawer.removeEventListener('pointerdown', handlePointerDown);
1092
1254
  drawer.removeEventListener('pointerup', handlePointerUp);
@@ -1099,7 +1261,7 @@
1099
1261
  };
1100
1262
 
1101
1263
  if (window.basecoat) {
1102
- window.basecoat.register('drawer', '.drawer:not([data-drawer-initialized])', initDrawer);
1264
+ window.basecoat.register('drawer', '.drawer:not([data-drawer-initialized]), .sheet:not([data-drawer-initialized])', initDrawer);
1103
1265
  }
1104
1266
  })();
1105
1267
 
@@ -1270,7 +1432,7 @@
1270
1432
  };
1271
1433
 
1272
1434
  const handleDocumentPopover = (event) => {
1273
- if (event.detail.source !== root) root.close(false);
1435
+ if (!root.contains(event.detail.source)) root.close(false);
1274
1436
  };
1275
1437
 
1276
1438
  state.trigger.addEventListener('click', handleTriggerClick);
@@ -1311,6 +1473,83 @@
1311
1473
  }
1312
1474
  })();
1313
1475
 
1476
+ (() => {
1477
+ function initInputOtp(root) {
1478
+ if (root.dataset.inputOtpInitialized) return;
1479
+ const input = root.querySelector(':scope > input[type="text"]');
1480
+ const slots = [...root.querySelectorAll(':scope > div > div > span')];
1481
+ if (!input || !slots.length || input.maxLength !== slots.length) return;
1482
+
1483
+ let value = input.value;
1484
+ let start = input.selectionStart;
1485
+ let end = input.selectionEnd;
1486
+ const refresh = () => {
1487
+ const focused = document.activeElement === input;
1488
+ const caret = input.selectionStart;
1489
+ // A caret on existing text selects one slot. At the end of a partial code it can append.
1490
+ if (focused && caret === input.selectionEnd && (caret < input.value.length || caret === input.maxLength)) {
1491
+ const backward = caret === input.maxLength || (caret > 0 && start !== end && caret < end);
1492
+ const index = backward ? caret - 1 : caret;
1493
+ input.setSelectionRange(index, index + 1, backward ? 'backward' : 'forward');
1494
+ }
1495
+ value = input.value;
1496
+ start = input.selectionStart;
1497
+ end = input.selectionEnd;
1498
+ slots.forEach((slot, index) => {
1499
+ slot.textContent = value[index] || '';
1500
+ const active = focused && (start === end ? index === start : index >= start && index < end);
1501
+ slot.toggleAttribute('data-active', active);
1502
+ slot.toggleAttribute('data-caret', active && !slot.textContent);
1503
+ });
1504
+ };
1505
+ const onFocus = () => {
1506
+ input.setSelectionRange(Math.min(input.value.length, input.maxLength - 1), input.value.length);
1507
+ refresh();
1508
+ };
1509
+ const onInput = (event) => {
1510
+ if (input.hasAttribute('data-filter') && input.validity.patternMismatch) {
1511
+ input.value = value;
1512
+ input.setSelectionRange(start, end);
1513
+ event.stopImmediatePropagation();
1514
+ }
1515
+ refresh();
1516
+ };
1517
+ const onPasteIOS = (event) => {
1518
+ if (event.defaultPrevented || !event.clipboardData || input.readOnly || input.disabled) return;
1519
+ event.preventDefault();
1520
+ const text = event.clipboardData.getData('text/plain');
1521
+ const next = input.value.slice(0, input.selectionStart) + text + input.value.slice(input.selectionEnd);
1522
+ input.value = next.slice(0, input.maxLength);
1523
+ input.setSelectionRange(Math.min(input.value.length, input.maxLength - 1), input.value.length);
1524
+ input.dispatchEvent(new InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: text }));
1525
+ };
1526
+ let frame;
1527
+ const onReset = () => { cancelAnimationFrame(frame); frame = requestAnimationFrame(refresh); };
1528
+ const controller = new AbortController();
1529
+ const options = { signal: controller.signal };
1530
+ input.addEventListener('focus', onFocus, options);
1531
+ input.addEventListener('blur', refresh, options);
1532
+ input.addEventListener('selectionchange', refresh, options);
1533
+ input.addEventListener('input', onInput, { ...options, capture: true });
1534
+ if (CSS.supports('-webkit-touch-callout', 'none')) input.addEventListener('paste', onPasteIOS, options);
1535
+ input.form?.addEventListener('reset', onReset, options);
1536
+ root.refresh = refresh;
1537
+ root.dataset.inputOtpInitialized = 'true';
1538
+ refresh();
1539
+ root._destroy = () => {
1540
+ cancelAnimationFrame(frame);
1541
+ controller.abort();
1542
+ slots.forEach(slot => { slot.textContent = ''; delete slot.dataset.active; delete slot.dataset.caret; });
1543
+ delete root.refresh;
1544
+ };
1545
+ root.dispatchEvent(new CustomEvent('basecoat:initialized'));
1546
+ }
1547
+
1548
+ if (window.basecoat) {
1549
+ window.basecoat.register('input-otp', '.input-otp:not([data-input-otp-initialized])', initInputOtp);
1550
+ }
1551
+ })();
1552
+
1314
1553
  (() => {
1315
1554
  const initPopover = (popoverComponent) => {
1316
1555
  if (popoverComponent.dataset.popoverInitialized) return;
@@ -1373,7 +1612,7 @@
1373
1612
  };
1374
1613
 
1375
1614
  const handleDocumentPopover = (event) => {
1376
- if (event.detail.source !== popoverComponent) {
1615
+ if (!popoverComponent.contains(event.detail.source)) {
1377
1616
  closePopover(false);
1378
1617
  }
1379
1618
  };
@@ -1800,7 +2039,7 @@
1800
2039
  if (!root.contains(event.target)) root.close(false);
1801
2040
  };
1802
2041
  const handleDocumentPopover = (event) => {
1803
- if (event.detail.source !== root) root.close(false);
2042
+ if (!root.contains(event.detail.source)) root.close(false);
1804
2043
  };
1805
2044
 
1806
2045
  state.trigger.addEventListener('keydown', handleTriggerKeydown);
@@ -1923,7 +2162,7 @@
1923
2162
 
1924
2163
  const handleClick = (event) => {
1925
2164
  const target = event.target;
1926
- const nav = sidebarComponent.querySelector('nav');
2165
+ const nav = sidebarComponent.querySelector(':scope > nav');
1927
2166
  const isMobile = window.innerWidth < breakpoint;
1928
2167
 
1929
2168
  if (isMobile && target.closest('a, button') && !target.closest('[data-keep-mobile-sidebar-open]')) {
@@ -1958,61 +2197,38 @@
1958
2197
  })();
1959
2198
 
1960
2199
  (() => {
1961
- const states = new WeakMap();
1962
-
1963
2200
  const isDisabled = (tab) => tab.disabled || tab.getAttribute('aria-disabled') === 'true';
1964
2201
 
1965
- const getElements = (root) => {
1966
- const tablist = root.querySelector('[role="tablist"]');
1967
- const tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
1968
- const panels = tabs.map(tab => document.getElementById(tab.getAttribute('aria-controls'))).filter(Boolean);
1969
- return { tablist, tabs, panels };
1970
- };
1971
-
1972
- const refreshTabs = (root) => {
1973
- const state = states.get(root);
1974
- if (!state) return;
1975
-
1976
- Object.assign(state, getElements(root));
1977
- if (!state.tablist) return;
1978
-
1979
- const selected = state.tabs.find(tab => tab.getAttribute('aria-selected') === 'true' && !isDisabled(tab))
1980
- || state.tabs.find(tab => !isDisabled(tab));
1981
- if (selected) root.select(selected, false);
1982
- };
1983
-
1984
2202
  const initTabs = (root) => {
1985
2203
  if (root.dataset.tabsInitialized) return;
1986
2204
 
1987
- const state = {};
1988
- states.set(root, state);
1989
- root.refresh = () => refreshTabs(root);
1990
-
2205
+ let tablist;
2206
+ let tabs = [];
1991
2207
  const selectTab = (tabToSelect, focus = false) => {
1992
- if (!tabToSelect || isDisabled(tabToSelect)) return;
2208
+ if (!tabs.includes(tabToSelect) || isDisabled(tabToSelect)) return;
1993
2209
 
1994
- state.tabs.forEach((tab) => {
1995
- tab.setAttribute('aria-selected', 'false');
1996
- tab.setAttribute('tabindex', '-1');
2210
+ const activePanelId = tabToSelect.getAttribute('aria-controls');
2211
+ for (const tab of tabs) {
2212
+ const selected = tab === tabToSelect;
2213
+ tab.setAttribute('aria-selected', String(selected));
2214
+ tab.tabIndex = selected ? 0 : -1;
1997
2215
  const panel = document.getElementById(tab.getAttribute('aria-controls'));
1998
- if (panel) panel.hidden = true;
1999
- });
2000
-
2001
- tabToSelect.setAttribute('aria-selected', 'true');
2002
- tabToSelect.setAttribute('tabindex', '0');
2003
- const activePanel = document.getElementById(tabToSelect.getAttribute('aria-controls'));
2004
- if (activePanel) activePanel.hidden = false;
2216
+ if (panel) panel.hidden = panel.id !== activePanelId;
2217
+ }
2005
2218
  if (focus) tabToSelect.focus();
2006
2219
  };
2220
+ const refresh = () => {
2221
+ tablist = Array.from(root.querySelectorAll('[role="tablist"]')).find(list => list.closest('.tabs') === root);
2222
+ tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
2223
+ const selected = tabs.find(tab => tab.getAttribute('aria-selected') === 'true' && !isDisabled(tab))
2224
+ || tabs.find(tab => !isDisabled(tab));
2225
+ if (selected) selectTab(selected);
2226
+ };
2007
2227
 
2228
+ refresh();
2229
+ if (!tablist) return;
2008
2230
  root.select = selectTab;
2009
- refreshTabs(root);
2010
- if (!state.tablist) {
2011
- states.delete(root);
2012
- delete root.refresh;
2013
- delete root.select;
2014
- return;
2015
- }
2231
+ root.refresh = refresh;
2016
2232
 
2017
2233
  const handleClick = (event) => {
2018
2234
  const clickedTab = event.target.closest('[role="tab"]');
@@ -2021,16 +2237,17 @@
2021
2237
 
2022
2238
  const handleKeydown = (event) => {
2023
2239
  const currentTab = event.target;
2024
- if (!state.tabs.includes(currentTab)) return;
2240
+ if (!tabs.includes(currentTab)) return;
2025
2241
 
2026
- const enabledTabs = state.tabs.filter(tab => !isDisabled(tab));
2242
+ const enabledTabs = tabs.filter(tab => !isDisabled(tab));
2027
2243
  const currentIndex = enabledTabs.indexOf(currentTab);
2028
- const orientation = state.tablist.getAttribute('aria-orientation') || 'horizontal';
2244
+ const orientation = tablist.getAttribute('aria-orientation') || 'horizontal';
2029
2245
  if (currentIndex === -1) return;
2030
2246
 
2247
+ const forward = getComputedStyle(tablist).direction === 'rtl' ? -1 : 1;
2031
2248
  let nextTab;
2032
- if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
2033
- if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
2249
+ if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex + forward + enabledTabs.length) % enabledTabs.length];
2250
+ if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex - forward + enabledTabs.length) % enabledTabs.length];
2034
2251
  if (event.key === 'ArrowDown' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
2035
2252
  if (event.key === 'ArrowUp' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
2036
2253
  if (event.key === 'Home') nextTab = enabledTabs[0];
@@ -2041,13 +2258,12 @@
2041
2258
  root.select(nextTab, true);
2042
2259
  };
2043
2260
 
2044
- state.tablist.addEventListener('click', handleClick);
2045
- state.tablist.addEventListener('keydown', handleKeydown);
2261
+ root.addEventListener('click', handleClick);
2262
+ root.addEventListener('keydown', handleKeydown);
2046
2263
 
2047
2264
  root._destroy = () => {
2048
- state.tablist.removeEventListener('click', handleClick);
2049
- state.tablist.removeEventListener('keydown', handleKeydown);
2050
- states.delete(root);
2265
+ root.removeEventListener('click', handleClick);
2266
+ root.removeEventListener('keydown', handleKeydown);
2051
2267
  delete root.refresh;
2052
2268
  delete root.select;
2053
2269
  };
@@ -2057,111 +2273,245 @@
2057
2273
  };
2058
2274
 
2059
2275
  if (window.basecoat) {
2060
- window.basecoat.register('tabs', {
2061
- selector: '.tabs:not([data-tabs-initialized])',
2062
- init: initTabs,
2063
- refresh: refreshTabs,
2064
- });
2276
+ window.basecoat.register('tabs', '.tabs:not([data-tabs-initialized])', initTabs);
2065
2277
  }
2066
2278
  })();
2067
2279
 
2068
2280
  (() => {
2069
2281
  let toaster;
2282
+ let resizeObserver;
2070
2283
  const toasts = new WeakMap();
2071
2284
  let isPaused = false;
2285
+ let focusBeforeToasts;
2286
+ const STACK_GAP = 12;
2287
+ const STACK_VISIBLE = 3;
2072
2288
  const ICONS = {
2073
2289
  success: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',
2074
- error: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',
2290
+ error: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',
2075
2291
  info: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',
2292
+ loading: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
2076
2293
  warning: '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>'
2077
2294
  };
2078
2295
 
2079
2296
  function initToaster(toasterElement) {
2080
2297
  if (toasterElement.dataset.toasterInitialized) return;
2081
2298
  toaster = toasterElement;
2299
+ isPaused = toaster.matches(':hover, :focus-within');
2300
+ let swipe;
2082
2301
 
2083
2302
  const handleClick = (event) => {
2084
- const actionLink = event.target.closest('.toast footer a');
2085
- const actionButton = event.target.closest('.toast footer button');
2086
- if (actionLink || actionButton) {
2087
- closeToast(event.target.closest('.toast'));
2303
+ const control = event.target.closest('.toast footer a, .toast footer button');
2304
+ if (control) closeToast(control.closest('.toast'));
2305
+ };
2306
+ const handleFocusIn = (event) => {
2307
+ if (event.relatedTarget instanceof HTMLElement && event.relatedTarget !== document.body && !toaster.contains(event.relatedTarget)) {
2308
+ focusBeforeToasts = event.relatedTarget;
2088
2309
  }
2310
+ syncPause();
2089
2311
  };
2312
+ const syncPause = () => swipe || toaster.matches(':hover, :focus-within')
2313
+ ? pauseAllTimeouts()
2314
+ : resumeAllTimeouts();
2090
2315
 
2091
- toaster.addEventListener('mouseenter', pauseAllTimeouts);
2092
- toaster.addEventListener('mouseleave', resumeAllTimeouts);
2093
- toaster.addEventListener('click', handleClick);
2316
+ const handlePointerDown = (event) => {
2317
+ if (!event.isPrimary || event.button !== 0 || event.target.closest('a, button, input, textarea, select, [contenteditable]')) return;
2318
+ const element = event.target.closest('.toast:not([aria-hidden="true"])');
2319
+ if (!element) return;
2320
+ const rtl = getComputedStyle(toaster).direction === 'rtl';
2321
+ const sign = (rtl ? -1 : 1) * (toaster.dataset.align === 'start' ? -1 : 1);
2322
+ swipe = { element, id: event.pointerId, x: event.clientX, y: event.clientY, time: event.timeStamp, distance: 0, sign };
2323
+ element.setPointerCapture(event.pointerId);
2324
+ syncPause();
2325
+ };
2326
+ const handlePointerMove = (event) => {
2327
+ if (!swipe || event.pointerId !== swipe.id) return;
2328
+ const x = (event.clientX - swipe.x) * swipe.sign;
2329
+ const y = event.clientY - swipe.y;
2330
+ if (!swipe.axis) {
2331
+ if (Math.max(x, y) < 8) return;
2332
+ swipe.axis = x > y ? 'x' : 'y';
2333
+ swipe.element.dataset.toastSwiping = '';
2334
+ updateStack();
2335
+ }
2336
+ swipe.distance = Math.max(0, swipe.axis === 'x' ? x : y);
2337
+ swipe.element.style.setProperty(`--toast-swipe-${swipe.axis}`, `${swipe.distance * (swipe.axis === 'x' ? swipe.sign : 1)}px`);
2338
+ };
2339
+ const handlePointerEnd = (event) => {
2340
+ if (!swipe || event.pointerId !== swipe.id) return;
2341
+ const { element, axis, distance, sign, time } = swipe;
2342
+ const dismiss = event.type !== 'pointercancel' && (distance > 40 || (distance > 10 && distance / Math.max(1, event.timeStamp - time) > 0.5));
2343
+ delete element.dataset.toastSwiping;
2344
+ if (dismiss) {
2345
+ element.dataset.toastSwipe = axis;
2346
+ element.style.setProperty('--toast-swipe-end', `${sign * 150}%`);
2347
+ closeToast(element);
2348
+ } else {
2349
+ element.style.removeProperty('--toast-swipe-x');
2350
+ element.style.removeProperty('--toast-swipe-y');
2351
+ }
2352
+ if (element.hasPointerCapture(event.pointerId)) element.releasePointerCapture(event.pointerId);
2353
+ swipe = null;
2354
+ syncPause();
2355
+ updateStack();
2356
+ };
2357
+
2358
+ const handleFocusOut = (event) => {
2359
+ if (!toasterElement.contains(event.relatedTarget)) syncPause();
2360
+ };
2361
+ const listeners = new AbortController();
2362
+ const { signal } = listeners;
2363
+ toaster.addEventListener('mouseenter', syncPause, { signal });
2364
+ toaster.addEventListener('mouseleave', syncPause, { signal });
2365
+ toaster.addEventListener('focusin', handleFocusIn, { signal });
2366
+ toaster.addEventListener('focusout', handleFocusOut, { signal });
2367
+ toaster.addEventListener('click', handleClick, { signal });
2368
+ toaster.addEventListener('pointerdown', handlePointerDown, { signal });
2369
+ toaster.addEventListener('pointermove', handlePointerMove, { signal });
2370
+ toaster.addEventListener('pointerup', handlePointerEnd, { signal });
2371
+ toaster.addEventListener('pointercancel', handlePointerEnd, { signal });
2372
+ window.addEventListener('pointerup', handlePointerEnd, { signal });
2373
+ window.addEventListener('pointercancel', handlePointerEnd, { signal });
2094
2374
 
2095
2375
  toasterElement.toast = (config = {}) => {
2096
2376
  const toastElement = createToast(config);
2097
2377
  toasterElement.appendChild(toastElement);
2098
- initToast(toastElement);
2378
+ initToast(toastElement, config);
2099
2379
  return toastElement;
2100
2380
  };
2101
2381
  toasterElement.closeAll = () => {
2102
2382
  toasterElement.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(closeToast);
2103
2383
  };
2104
2384
 
2105
- toaster.querySelectorAll('.toast:not([data-toast-initialized])').forEach(initToast);
2106
- toaster._destroy = () => {
2107
- toaster.removeEventListener('mouseenter', pauseAllTimeouts);
2108
- toaster.removeEventListener('mouseleave', resumeAllTimeouts);
2109
- toaster.removeEventListener('click', handleClick);
2110
- toaster.querySelectorAll('.toast[data-toast-initialized]').forEach(toast => toast._destroy?.());
2111
- delete toaster.toast;
2112
- delete toaster.closeAll;
2113
- if (toaster === toasterElement) toaster = null;
2385
+ const observer = new ResizeObserver(updateStack);
2386
+ resizeObserver = observer;
2387
+ toaster.querySelectorAll('.toast:not([data-toast-initialized])').forEach(element => initToast(element));
2388
+ toasterElement._destroy = () => {
2389
+ listeners.abort();
2390
+ swipe = null;
2391
+ toasterElement.querySelectorAll('.toast[data-toast-initialized]').forEach(toast => toast._destroy?.());
2392
+ observer.disconnect();
2393
+ delete toasterElement.toast;
2394
+ delete toasterElement.closeAll;
2395
+ if (toaster === toasterElement) {
2396
+ resizeObserver = null;
2397
+ isPaused = false;
2398
+ focusBeforeToasts = null;
2399
+ toaster = null;
2400
+ }
2114
2401
  };
2115
2402
  toaster.dataset.toasterInitialized = 'true';
2403
+ updateStack();
2116
2404
  toaster.dispatchEvent(new CustomEvent('basecoat:initialized'));
2117
2405
  }
2118
2406
 
2119
- function initToast(element) {
2120
- if (element.dataset.toastInitialized) return;
2407
+ function updateStack() {
2408
+ if (!toaster) return;
2121
2409
 
2122
- const duration = parseInt(element.dataset.duration);
2123
- const timeoutDuration = duration !== -1
2124
- ? duration || (element.dataset.category === 'error' ? 5000 : 3000)
2125
- : -1;
2410
+ const elements = Array.from(toaster.querySelectorAll('.toast:not([aria-hidden="true"])')).reverse();
2411
+ let offset = 0;
2126
2412
 
2127
- const state = {
2128
- remainingTime: timeoutDuration,
2129
- timeoutId: null,
2130
- startTime: null,
2131
- };
2413
+ const expanded = toaster.matches(':hover, :focus-within, :has([data-toast-swiping])');
2414
+ const entries = elements.map(element => {
2415
+ const content = element.querySelector('.toast-content') || element;
2416
+ const styles = getComputedStyle(element);
2417
+ return { element, content, height: content.offsetHeight + parseFloat(styles.borderTopWidth) + parseFloat(styles.borderBottomWidth) };
2418
+ });
2132
2419
 
2133
- if (timeoutDuration !== -1) {
2134
- if (isPaused) {
2135
- state.timeoutId = null;
2136
- } else {
2137
- state.startTime = Date.now();
2138
- state.timeoutId = setTimeout(() => closeToast(element), timeoutDuration);
2420
+ entries.forEach(({ element, content, height }, index) => {
2421
+ element.style.setProperty('--toast-offset', `${offset}px`);
2422
+ element.style.setProperty('--toast-index', index);
2423
+ element.style.setProperty('--toast-height', `${height}px`);
2424
+ element.style.setProperty('--toast-front-height', `${entries[0].height}px`);
2425
+ element.toggleAttribute('data-toast-stack-overflow', index >= STACK_VISIBLE);
2426
+ // Keep hidden content out of the tab order; hovering/focusing expands the stack.
2427
+ const hidden = index >= STACK_VISIBLE || (!expanded && index > 0);
2428
+ if (hidden && content.contains(document.activeElement)) {
2429
+ const target = entries[0].content.querySelector('button:not(:disabled), a[href]') || (focusBeforeToasts?.isConnected ? focusBeforeToasts : toaster);
2430
+ if (target === toaster && !toaster.hasAttribute('tabindex')) toaster.tabIndex = -1;
2431
+ target.focus({ preventScroll: true });
2139
2432
  }
2433
+ content.inert = hidden;
2434
+ offset += height + STACK_GAP;
2435
+ });
2436
+ }
2437
+
2438
+ function resetTimeout(element, state) {
2439
+ clearTimeout(state.timeoutId);
2440
+ const duration = parseInt(element.dataset.duration);
2441
+ state.remainingTime = Number.isNaN(duration) || duration === 0
2442
+ ? element.dataset.category === 'loading' ? -1 : element.dataset.category === 'error' ? 5000 : 3000
2443
+ : duration;
2444
+ state.timeoutId = null;
2445
+ if (state.remainingTime !== -1 && (!isPaused || !toaster?.contains(element))) {
2446
+ state.startTime = Date.now();
2447
+ state.timeoutId = setTimeout(() => closeToast(element), state.remainingTime);
2140
2448
  }
2449
+ }
2450
+
2451
+ function initToast(element, config) {
2452
+ if (element.dataset.toastInitialized) return;
2453
+ const state = { remainingTime: -1, timeoutId: null, startTime: null };
2141
2454
  toasts.set(element, state);
2455
+ resetTimeout(element, state);
2142
2456
 
2457
+ const content = element.querySelector('.toast-content') || element;
2458
+ resizeObserver?.observe(content);
2143
2459
  element.close = () => closeToast(element);
2460
+ if (config !== undefined) {
2461
+ let currentConfig = { ...config };
2462
+ element.update = (changes = {}) => {
2463
+ // An async result must not resurrect a dismissed toast.
2464
+ if (!toasts.has(element) || !element.isConnected) return;
2465
+ currentConfig = { ...currentConfig, ...changes };
2466
+ const replacement = createToast(currentConfig);
2467
+ const controls = [...element.querySelectorAll('footer a, footer button')];
2468
+ const focusedIndex = controls.indexOf(document.activeElement);
2469
+ content.replaceChildren(...replacement.firstElementChild.childNodes);
2470
+ content.setAttribute('role', replacement.firstElementChild.getAttribute('role'));
2471
+ for (const attribute of ['data-category', 'data-duration']) {
2472
+ if (replacement.hasAttribute(attribute)) element.setAttribute(attribute, replacement.getAttribute(attribute));
2473
+ else element.removeAttribute(attribute);
2474
+ }
2475
+ if (focusedIndex >= 0) {
2476
+ const nextControls = element.querySelectorAll('footer a, footer button');
2477
+ const target = nextControls[focusedIndex] || nextControls[0] || toaster;
2478
+ if (target && target === toaster && !target.hasAttribute('tabindex')) target.tabIndex = -1;
2479
+ target?.focus({ preventScroll: true });
2480
+ }
2481
+ resetTimeout(element, toasts.get(element));
2482
+ updateStack();
2483
+ return element;
2484
+ };
2485
+ }
2144
2486
  element._destroy = () => {
2145
2487
  clearTimeout(state.timeoutId);
2488
+ resizeObserver?.unobserve(content);
2146
2489
  toasts.delete(element);
2147
2490
  delete element.close;
2491
+ delete element.dataset.toastInitialized;
2492
+ // Keep update callable for pending promises and forced reinitialization.
2493
+ if (!element.isConnected) updateStack();
2148
2494
  };
2495
+ updateStack();
2496
+ // Flush the initial offscreen position before transitioning to the stack.
2497
+ element.getBoundingClientRect();
2149
2498
  element.dataset.toastInitialized = 'true';
2499
+ element.dataset.basecoatComponent = 'toast';
2150
2500
  }
2151
2501
 
2152
2502
  function pauseAllTimeouts() {
2153
2503
  if (isPaused || !toaster) return;
2154
2504
 
2155
2505
  isPaused = true;
2506
+ updateStack();
2156
2507
 
2157
2508
  toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
2158
- if (!toasts.has(element)) return;
2159
-
2160
2509
  const state = toasts.get(element);
2510
+ if (!state) return;
2161
2511
  if (state.timeoutId) {
2162
2512
  clearTimeout(state.timeoutId);
2163
2513
  state.timeoutId = null;
2164
- state.remainingTime -= Date.now() - state.startTime;
2514
+ state.remainingTime = Math.max(0, state.remainingTime - (Date.now() - state.startTime));
2165
2515
  }
2166
2516
  });
2167
2517
  }
@@ -2170,11 +2520,11 @@
2170
2520
  if (!isPaused || !toaster) return;
2171
2521
 
2172
2522
  isPaused = false;
2523
+ updateStack();
2173
2524
 
2174
2525
  toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
2175
- if (!toasts.has(element)) return;
2176
-
2177
2526
  const state = toasts.get(element);
2527
+ if (!state) return;
2178
2528
  if (state.remainingTime !== -1 && !state.timeoutId) {
2179
2529
  if (state.remainingTime > 0) {
2180
2530
  state.startTime = Date.now();
@@ -2189,15 +2539,50 @@
2189
2539
  function closeToast(element) {
2190
2540
  if (!element || !toasts.has(element)) return;
2191
2541
 
2542
+ const host = toaster?.contains(element) ? toaster : null;
2192
2543
  const state = toasts.get(element);
2193
2544
  clearTimeout(state.timeoutId);
2545
+ resizeObserver?.unobserve(element.querySelector('.toast-content') || element);
2194
2546
  toasts.delete(element);
2195
2547
 
2196
- if (element.contains(document.activeElement)) document.activeElement.blur();
2548
+ if (element.contains(document.activeElement)) {
2549
+ const remaining = [...(host?.querySelectorAll('.toast:not([aria-hidden="true"])') || [])].filter(toast => toast !== element);
2550
+ const nextControl = remaining.at(-1)?.querySelector('button:not(:disabled), a[href]');
2551
+ const keyboard = document.activeElement.matches(':focus-visible');
2552
+ const focusTarget = (keyboard && nextControl) || (host && focusBeforeToasts?.isConnected ? focusBeforeToasts : null);
2553
+ if (!focusTarget) document.activeElement.blur();
2554
+ else {
2555
+ focusTarget.focus({ preventScroll: true });
2556
+ if (element.contains(document.activeElement)) {
2557
+ host.tabIndex = -1;
2558
+ host.focus({ preventScroll: true });
2559
+ }
2560
+ }
2561
+ }
2562
+ if (host?.matches(':hover, :focus-within, :has([data-toast-swiping])')) element.dataset.toastExpanded = '';
2197
2563
  element.setAttribute('aria-hidden', 'true');
2198
- element.addEventListener('transitionend', () => element.remove(), { once: true });
2564
+ element.inert = true;
2565
+ updateStack();
2566
+
2567
+ const remove = () => {
2568
+ if (!element.isConnected) return;
2569
+ element.remove();
2570
+ updateStack();
2571
+ };
2572
+ requestAnimationFrame(() => {
2573
+ const animations = element.getAnimations();
2574
+ if (!animations.length) return remove();
2575
+ Promise.allSettled(animations.map(animation => animation.finished)).then(remove);
2576
+ });
2199
2577
  }
2200
2578
 
2579
+ const escapeHtml = (value) => String(value)
2580
+ .replace(/&/g, '&amp;')
2581
+ .replace(/</g, '&lt;')
2582
+ .replace(/>/g, '&gt;')
2583
+ .replace(/"/g, '&quot;')
2584
+ .replace(/'/g, '&#39;');
2585
+
2201
2586
  function createToast(config) {
2202
2587
  const {
2203
2588
  category = 'info',
@@ -2207,31 +2592,37 @@
2207
2592
  cancel,
2208
2593
  duration,
2209
2594
  icon,
2595
+ closeButton = true,
2596
+ html: allowHtml = false,
2210
2597
  } = config;
2211
2598
 
2599
+ // Text is escaped unless `html: true`. `icon` is always raw markup (SVG).
2600
+ const text = (value) => (allowHtml ? String(value) : escapeHtml(value));
2601
+
2212
2602
  const iconHtml = icon || (category && ICONS[category]) || '';
2213
- const titleHtml = title ? `<h2>${title}</h2>` : '';
2214
- const descriptionHtml = description ? `<p>${description}</p>` : '';
2603
+ const titleHtml = title ? `<h2>${text(title)}</h2>` : '';
2604
+ const descriptionHtml = description ? `<p>${text(description)}</p>` : '';
2215
2605
  const actionHtml = action?.href
2216
- ? `<a href="${action.href}" class="btn" data-toast-action>${action.label}</a>`
2217
- : action?.onclick
2218
- ? `<button type="button" class="btn" data-toast-action onclick="${action.onclick}">${action.label}</button>`
2606
+ ? `<a href="${escapeHtml(action.href)}" class="btn" data-variant="outline" data-size="sm" data-toast-action>${text(action.label)}</a>`
2607
+ : action
2608
+ ? `<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-action ${action.onclick ? `onclick="${escapeHtml(action.onclick)}"` : ''}>${text(action.label)}</button>`
2219
2609
  : '';
2220
2610
  const cancelHtml = cancel
2221
- ? `<button type="button" class="btn h-6 text-xs px-2.5 rounded-sm" data-variant="outline" data-toast-cancel onclick="${cancel?.onclick || ''}">${cancel.label}</button>`
2611
+ ? `<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-cancel ${cancel.onclick ? `onclick="${escapeHtml(cancel.onclick)}"` : ''}>${text(cancel.label)}</button>`
2222
2612
  : '';
2223
2613
 
2224
- const footerHtml = actionHtml || cancelHtml ? `<footer>${actionHtml}${cancelHtml}</footer>` : '';
2614
+ const closeHtml = closeButton
2615
+ ? '<button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Close toast"><svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>'
2616
+ : '';
2617
+ const footerHtml = actionHtml || cancelHtml || closeHtml ? `<footer>${actionHtml}${cancelHtml}${closeHtml}</footer>` : '';
2225
2618
 
2226
2619
  const html = `
2227
- <div
2620
+ <li
2228
2621
  class="toast"
2229
- role="${category === 'error' ? 'alert' : 'status'}"
2230
- aria-atomic="true"
2231
- ${category ? `data-category="${category}"` : ''}
2232
- ${duration !== undefined ? `data-duration="${duration}"` : ''}
2622
+ ${category ? `data-category="${escapeHtml(category)}"` : ''}
2623
+ ${duration !== undefined ? `data-duration="${escapeHtml(duration)}"` : ''}
2233
2624
  >
2234
- <div class="toast-content">
2625
+ <div class="toast-content" role="${category === 'error' ? 'alert' : 'status'}" aria-atomic="true">
2235
2626
  ${iconHtml}
2236
2627
  <section>
2237
2628
  ${titleHtml}
@@ -2239,7 +2630,7 @@
2239
2630
  </section>
2240
2631
  ${footerHtml}
2241
2632
  </div>
2242
- </div>
2633
+ </li>
2243
2634
  `;
2244
2635
  const template = document.createElement('template');
2245
2636
  template.innerHTML = html.trim();