basecoat-css 1.1.0 → 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.
- package/README.md +1 -1
- package/dist/base/base.css +1 -0
- package/dist/base/scroll-fade.css +41 -0
- package/dist/base/transition-details.css +12 -0
- package/dist/basecoat-base.bundle.css +767 -119
- package/dist/basecoat-base.cdn.css +1924 -673
- package/dist/basecoat-base.cdn.min.css +1 -1
- package/dist/basecoat-compat.cdn.css +250 -75
- package/dist/basecoat-compat.cdn.min.css +1 -1
- package/dist/basecoat-components.css +10 -0
- package/dist/basecoat-luma.bundle.css +1115 -125
- package/dist/basecoat-luma.cdn.css +4649 -2558
- package/dist/basecoat-luma.cdn.min.css +1 -1
- package/dist/basecoat-lyra.bundle.css +1110 -125
- package/dist/basecoat-lyra.cdn.css +5118 -3079
- package/dist/basecoat-lyra.cdn.min.css +1 -1
- package/dist/basecoat-maia.bundle.css +1113 -125
- package/dist/basecoat-maia.cdn.css +5244 -3202
- package/dist/basecoat-maia.cdn.min.css +1 -1
- package/dist/basecoat-mira.bundle.css +1113 -125
- package/dist/basecoat-mira.cdn.css +3623 -1583
- package/dist/basecoat-mira.cdn.min.css +1 -1
- package/dist/basecoat-nova.bundle.css +1115 -129
- package/dist/basecoat-nova.cdn.css +5271 -3229
- package/dist/basecoat-nova.cdn.min.css +1 -1
- package/dist/basecoat-rhea.bundle.css +1117 -127
- package/dist/basecoat-rhea.cdn.css +5286 -3192
- package/dist/basecoat-rhea.cdn.min.css +1 -1
- package/dist/basecoat-sera.bundle.css +1111 -128
- package/dist/basecoat-sera.cdn.css +3280 -1254
- package/dist/basecoat-sera.cdn.min.css +1 -1
- package/dist/basecoat-vega.bundle.css +1113 -125
- package/dist/basecoat-vega.cdn.css +5225 -3180
- package/dist/basecoat-vega.cdn.min.css +1 -1
- package/dist/basecoat.bundle.css +1113 -125
- package/dist/basecoat.cdn.css +5225 -3180
- package/dist/basecoat.cdn.min.css +1 -1
- package/dist/compat/legacy.css +3 -18
- package/dist/components/accordion.css +15 -1
- package/dist/components/alert.css +4 -0
- package/dist/components/attachment.css +66 -0
- package/dist/components/bubble.css +28 -0
- package/dist/components/button-group.css +2 -1
- package/dist/components/button.css +23 -0
- package/dist/components/carousel.css +30 -0
- package/dist/components/checkbox.css +5 -1
- package/dist/components/code-block.css +80 -0
- package/dist/components/collapsible.css +0 -9
- package/dist/components/command.css +13 -0
- package/dist/components/dialog.css +2 -4
- package/dist/components/drawer.css +48 -14
- package/dist/components/input-otp.css +49 -0
- package/dist/components/item.css +6 -0
- package/dist/components/marker.css +20 -0
- package/dist/components/message.css +24 -0
- package/dist/components/range.css +7 -0
- package/dist/components/scrollbar.css +20 -42
- package/dist/components/sheet.css +123 -0
- package/dist/components/shimmer.css +49 -0
- package/dist/components/sidebar.css +9 -1
- package/dist/components/toast.css +59 -44
- package/dist/components/trace.css +34 -0
- package/dist/js/all.js +488 -112
- package/dist/js/all.min.js +1 -1
- package/dist/js/carousel.js +105 -0
- package/dist/js/carousel.min.js +1 -0
- package/dist/js/code-block.js +47 -0
- package/dist/js/code-block.min.js +1 -0
- package/dist/js/drawer.js +6 -2
- package/dist/js/drawer.min.js +1 -1
- package/dist/js/input-otp.js +76 -0
- package/dist/js/input-otp.min.js +1 -0
- package/dist/js/tabs.js +31 -58
- package/dist/js/tabs.min.js +1 -1
- package/dist/js/toast.js +221 -53
- package/dist/js/toast.min.js +1 -1
- package/dist/styles/luma.css +348 -6
- package/dist/styles/lyra.css +343 -6
- package/dist/styles/maia.css +346 -6
- package/dist/styles/mira.css +346 -6
- package/dist/styles/nova.css +348 -10
- package/dist/styles/rhea.css +350 -8
- package/dist/styles/sera.css +344 -9
- package/dist/styles/vega.css +346 -6
- package/dist/typeset.cdn.css +381 -0
- package/dist/typeset.cdn.min.css +1 -0
- package/dist/typeset.css +435 -0
- package/package.json +16 -7
- package/templates/jinja/tabs.html.jinja +0 -1
- package/templates/jinja/toast.html.jinja +29 -26
- package/templates/nunjucks/tabs.njk +1 -1
- package/templates/nunjucks/toast.njk +30 -27
package/dist/js/tabs.js
CHANGED
|
@@ -1,59 +1,36 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const states = new WeakMap();
|
|
3
|
-
|
|
4
2
|
const isDisabled = (tab) => tab.disabled || tab.getAttribute('aria-disabled') === 'true';
|
|
5
3
|
|
|
6
|
-
const getElements = (root) => {
|
|
7
|
-
const tablist = root.querySelector('[role="tablist"]');
|
|
8
|
-
const tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
|
|
9
|
-
const panels = tabs.map(tab => document.getElementById(tab.getAttribute('aria-controls'))).filter(Boolean);
|
|
10
|
-
return { tablist, tabs, panels };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const refreshTabs = (root) => {
|
|
14
|
-
const state = states.get(root);
|
|
15
|
-
if (!state) return;
|
|
16
|
-
|
|
17
|
-
Object.assign(state, getElements(root));
|
|
18
|
-
if (!state.tablist) return;
|
|
19
|
-
|
|
20
|
-
const selected = state.tabs.find(tab => tab.getAttribute('aria-selected') === 'true' && !isDisabled(tab))
|
|
21
|
-
|| state.tabs.find(tab => !isDisabled(tab));
|
|
22
|
-
if (selected) root.select(selected, false);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
4
|
const initTabs = (root) => {
|
|
26
5
|
if (root.dataset.tabsInitialized) return;
|
|
27
6
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
root.refresh = () => refreshTabs(root);
|
|
31
|
-
|
|
7
|
+
let tablist;
|
|
8
|
+
let tabs = [];
|
|
32
9
|
const selectTab = (tabToSelect, focus = false) => {
|
|
33
|
-
if (!tabToSelect || isDisabled(tabToSelect)) return;
|
|
10
|
+
if (!tabs.includes(tabToSelect) || isDisabled(tabToSelect)) return;
|
|
34
11
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
tab
|
|
12
|
+
const activePanelId = tabToSelect.getAttribute('aria-controls');
|
|
13
|
+
for (const tab of tabs) {
|
|
14
|
+
const selected = tab === tabToSelect;
|
|
15
|
+
tab.setAttribute('aria-selected', String(selected));
|
|
16
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
38
17
|
const panel = document.getElementById(tab.getAttribute('aria-controls'));
|
|
39
|
-
if (panel) panel.hidden =
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
tabToSelect.setAttribute('aria-selected', 'true');
|
|
43
|
-
tabToSelect.setAttribute('tabindex', '0');
|
|
44
|
-
const activePanel = document.getElementById(tabToSelect.getAttribute('aria-controls'));
|
|
45
|
-
if (activePanel) activePanel.hidden = false;
|
|
18
|
+
if (panel) panel.hidden = panel.id !== activePanelId;
|
|
19
|
+
}
|
|
46
20
|
if (focus) tabToSelect.focus();
|
|
47
21
|
};
|
|
22
|
+
const refresh = () => {
|
|
23
|
+
tablist = Array.from(root.querySelectorAll('[role="tablist"]')).find(list => list.closest('.tabs') === root);
|
|
24
|
+
tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
|
|
25
|
+
const selected = tabs.find(tab => tab.getAttribute('aria-selected') === 'true' && !isDisabled(tab))
|
|
26
|
+
|| tabs.find(tab => !isDisabled(tab));
|
|
27
|
+
if (selected) selectTab(selected);
|
|
28
|
+
};
|
|
48
29
|
|
|
30
|
+
refresh();
|
|
31
|
+
if (!tablist) return;
|
|
49
32
|
root.select = selectTab;
|
|
50
|
-
|
|
51
|
-
if (!state.tablist) {
|
|
52
|
-
states.delete(root);
|
|
53
|
-
delete root.refresh;
|
|
54
|
-
delete root.select;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
33
|
+
root.refresh = refresh;
|
|
57
34
|
|
|
58
35
|
const handleClick = (event) => {
|
|
59
36
|
const clickedTab = event.target.closest('[role="tab"]');
|
|
@@ -62,16 +39,17 @@
|
|
|
62
39
|
|
|
63
40
|
const handleKeydown = (event) => {
|
|
64
41
|
const currentTab = event.target;
|
|
65
|
-
if (!
|
|
42
|
+
if (!tabs.includes(currentTab)) return;
|
|
66
43
|
|
|
67
|
-
const enabledTabs =
|
|
44
|
+
const enabledTabs = tabs.filter(tab => !isDisabled(tab));
|
|
68
45
|
const currentIndex = enabledTabs.indexOf(currentTab);
|
|
69
|
-
const orientation =
|
|
46
|
+
const orientation = tablist.getAttribute('aria-orientation') || 'horizontal';
|
|
70
47
|
if (currentIndex === -1) return;
|
|
71
48
|
|
|
49
|
+
const forward = getComputedStyle(tablist).direction === 'rtl' ? -1 : 1;
|
|
72
50
|
let nextTab;
|
|
73
|
-
if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex +
|
|
74
|
-
if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex -
|
|
51
|
+
if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex + forward + enabledTabs.length) % enabledTabs.length];
|
|
52
|
+
if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex - forward + enabledTabs.length) % enabledTabs.length];
|
|
75
53
|
if (event.key === 'ArrowDown' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
|
|
76
54
|
if (event.key === 'ArrowUp' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
|
|
77
55
|
if (event.key === 'Home') nextTab = enabledTabs[0];
|
|
@@ -82,13 +60,12 @@
|
|
|
82
60
|
root.select(nextTab, true);
|
|
83
61
|
};
|
|
84
62
|
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
root.addEventListener('click', handleClick);
|
|
64
|
+
root.addEventListener('keydown', handleKeydown);
|
|
87
65
|
|
|
88
66
|
root._destroy = () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
states.delete(root);
|
|
67
|
+
root.removeEventListener('click', handleClick);
|
|
68
|
+
root.removeEventListener('keydown', handleKeydown);
|
|
92
69
|
delete root.refresh;
|
|
93
70
|
delete root.select;
|
|
94
71
|
};
|
|
@@ -98,10 +75,6 @@
|
|
|
98
75
|
};
|
|
99
76
|
|
|
100
77
|
if (window.basecoat) {
|
|
101
|
-
window.basecoat.register('tabs',
|
|
102
|
-
selector: '.tabs:not([data-tabs-initialized])',
|
|
103
|
-
init: initTabs,
|
|
104
|
-
refresh: refreshTabs,
|
|
105
|
-
});
|
|
78
|
+
window.basecoat.register('tabs', '.tabs:not([data-tabs-initialized])', initTabs);
|
|
106
79
|
}
|
|
107
80
|
})();
|
package/dist/js/tabs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const t=
|
|
1
|
+
(()=>{const t=t=>t.disabled||"true"===t.getAttribute("aria-disabled"),e=e=>{if(e.dataset.tabsInitialized)return;let r,n=[];const i=(e,r=!1)=>{if(!n.includes(e)||t(e))return;const i=e.getAttribute("aria-controls");for(const t of n){const r=t===e;t.setAttribute("aria-selected",String(r)),t.tabIndex=r?0:-1;const n=document.getElementById(t.getAttribute("aria-controls"));n&&(n.hidden=n.id!==i)}r&&e.focus()},o=()=>{r=Array.from(e.querySelectorAll('[role="tablist"]')).find(t=>t.closest(".tabs")===e),n=r?Array.from(r.querySelectorAll('[role="tab"]')):[];const o=n.find(e=>"true"===e.getAttribute("aria-selected")&&!t(e))||n.find(e=>!t(e));o&&i(o)};if(o(),!r)return;e.select=i,e.refresh=o;const a=t=>{const r=t.target.closest('[role="tab"]');r&&e.select(r)},l=i=>{const o=i.target;if(!n.includes(o))return;const a=n.filter(e=>!t(e)),l=a.indexOf(o),s=r.getAttribute("aria-orientation")||"horizontal";if(-1===l)return;const d="rtl"===getComputedStyle(r).direction?-1:1;let c;"ArrowRight"===i.key&&"horizontal"===s&&(c=a[(l+d+a.length)%a.length]),"ArrowLeft"===i.key&&"horizontal"===s&&(c=a[(l-d+a.length)%a.length]),"ArrowDown"===i.key&&"vertical"===s&&(c=a[(l+1)%a.length]),"ArrowUp"===i.key&&"vertical"===s&&(c=a[(l-1+a.length)%a.length]),"Home"===i.key&&(c=a[0]),"End"===i.key&&(c=a[a.length-1]),c&&(i.preventDefault(),e.select(c,!0))};e.addEventListener("click",a),e.addEventListener("keydown",l),e._destroy=()=>{e.removeEventListener("click",a),e.removeEventListener("keydown",l),delete e.refresh,delete e.select},e.dataset.tabsInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("tabs",".tabs:not([data-tabs-initialized])",e)})();
|
package/dist/js/toast.js
CHANGED
|
@@ -1,100 +1,238 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
let toaster;
|
|
3
|
+
let resizeObserver;
|
|
3
4
|
const toasts = new WeakMap();
|
|
4
5
|
let isPaused = false;
|
|
6
|
+
let focusBeforeToasts;
|
|
7
|
+
const STACK_GAP = 12;
|
|
8
|
+
const STACK_VISIBLE = 3;
|
|
5
9
|
const ICONS = {
|
|
6
10
|
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>',
|
|
7
|
-
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"><
|
|
11
|
+
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>',
|
|
8
12
|
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>',
|
|
13
|
+
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>',
|
|
9
14
|
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>'
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
function initToaster(toasterElement) {
|
|
13
18
|
if (toasterElement.dataset.toasterInitialized) return;
|
|
14
19
|
toaster = toasterElement;
|
|
20
|
+
isPaused = toaster.matches(':hover, :focus-within');
|
|
21
|
+
let swipe;
|
|
15
22
|
|
|
16
23
|
const handleClick = (event) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const control = event.target.closest('.toast footer a, .toast footer button');
|
|
25
|
+
if (control) closeToast(control.closest('.toast'));
|
|
26
|
+
};
|
|
27
|
+
const handleFocusIn = (event) => {
|
|
28
|
+
if (event.relatedTarget instanceof HTMLElement && event.relatedTarget !== document.body && !toaster.contains(event.relatedTarget)) {
|
|
29
|
+
focusBeforeToasts = event.relatedTarget;
|
|
30
|
+
}
|
|
31
|
+
syncPause();
|
|
32
|
+
};
|
|
33
|
+
const syncPause = () => swipe || toaster.matches(':hover, :focus-within')
|
|
34
|
+
? pauseAllTimeouts()
|
|
35
|
+
: resumeAllTimeouts();
|
|
36
|
+
|
|
37
|
+
const handlePointerDown = (event) => {
|
|
38
|
+
if (!event.isPrimary || event.button !== 0 || event.target.closest('a, button, input, textarea, select, [contenteditable]')) return;
|
|
39
|
+
const element = event.target.closest('.toast:not([aria-hidden="true"])');
|
|
40
|
+
if (!element) return;
|
|
41
|
+
const rtl = getComputedStyle(toaster).direction === 'rtl';
|
|
42
|
+
const sign = (rtl ? -1 : 1) * (toaster.dataset.align === 'start' ? -1 : 1);
|
|
43
|
+
swipe = { element, id: event.pointerId, x: event.clientX, y: event.clientY, time: event.timeStamp, distance: 0, sign };
|
|
44
|
+
element.setPointerCapture(event.pointerId);
|
|
45
|
+
syncPause();
|
|
46
|
+
};
|
|
47
|
+
const handlePointerMove = (event) => {
|
|
48
|
+
if (!swipe || event.pointerId !== swipe.id) return;
|
|
49
|
+
const x = (event.clientX - swipe.x) * swipe.sign;
|
|
50
|
+
const y = event.clientY - swipe.y;
|
|
51
|
+
if (!swipe.axis) {
|
|
52
|
+
if (Math.max(x, y) < 8) return;
|
|
53
|
+
swipe.axis = x > y ? 'x' : 'y';
|
|
54
|
+
swipe.element.dataset.toastSwiping = '';
|
|
55
|
+
updateStack();
|
|
21
56
|
}
|
|
57
|
+
swipe.distance = Math.max(0, swipe.axis === 'x' ? x : y);
|
|
58
|
+
swipe.element.style.setProperty(`--toast-swipe-${swipe.axis}`, `${swipe.distance * (swipe.axis === 'x' ? swipe.sign : 1)}px`);
|
|
59
|
+
};
|
|
60
|
+
const handlePointerEnd = (event) => {
|
|
61
|
+
if (!swipe || event.pointerId !== swipe.id) return;
|
|
62
|
+
const { element, axis, distance, sign, time } = swipe;
|
|
63
|
+
const dismiss = event.type !== 'pointercancel' && (distance > 40 || (distance > 10 && distance / Math.max(1, event.timeStamp - time) > 0.5));
|
|
64
|
+
delete element.dataset.toastSwiping;
|
|
65
|
+
if (dismiss) {
|
|
66
|
+
element.dataset.toastSwipe = axis;
|
|
67
|
+
element.style.setProperty('--toast-swipe-end', `${sign * 150}%`);
|
|
68
|
+
closeToast(element);
|
|
69
|
+
} else {
|
|
70
|
+
element.style.removeProperty('--toast-swipe-x');
|
|
71
|
+
element.style.removeProperty('--toast-swipe-y');
|
|
72
|
+
}
|
|
73
|
+
if (element.hasPointerCapture(event.pointerId)) element.releasePointerCapture(event.pointerId);
|
|
74
|
+
swipe = null;
|
|
75
|
+
syncPause();
|
|
76
|
+
updateStack();
|
|
22
77
|
};
|
|
23
78
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
79
|
+
const handleFocusOut = (event) => {
|
|
80
|
+
if (!toasterElement.contains(event.relatedTarget)) syncPause();
|
|
81
|
+
};
|
|
82
|
+
const listeners = new AbortController();
|
|
83
|
+
const { signal } = listeners;
|
|
84
|
+
toaster.addEventListener('mouseenter', syncPause, { signal });
|
|
85
|
+
toaster.addEventListener('mouseleave', syncPause, { signal });
|
|
86
|
+
toaster.addEventListener('focusin', handleFocusIn, { signal });
|
|
87
|
+
toaster.addEventListener('focusout', handleFocusOut, { signal });
|
|
88
|
+
toaster.addEventListener('click', handleClick, { signal });
|
|
89
|
+
toaster.addEventListener('pointerdown', handlePointerDown, { signal });
|
|
90
|
+
toaster.addEventListener('pointermove', handlePointerMove, { signal });
|
|
91
|
+
toaster.addEventListener('pointerup', handlePointerEnd, { signal });
|
|
92
|
+
toaster.addEventListener('pointercancel', handlePointerEnd, { signal });
|
|
93
|
+
window.addEventListener('pointerup', handlePointerEnd, { signal });
|
|
94
|
+
window.addEventListener('pointercancel', handlePointerEnd, { signal });
|
|
27
95
|
|
|
28
96
|
toasterElement.toast = (config = {}) => {
|
|
29
97
|
const toastElement = createToast(config);
|
|
30
98
|
toasterElement.appendChild(toastElement);
|
|
31
|
-
initToast(toastElement);
|
|
99
|
+
initToast(toastElement, config);
|
|
32
100
|
return toastElement;
|
|
33
101
|
};
|
|
34
102
|
toasterElement.closeAll = () => {
|
|
35
103
|
toasterElement.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(closeToast);
|
|
36
104
|
};
|
|
37
105
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
106
|
+
const observer = new ResizeObserver(updateStack);
|
|
107
|
+
resizeObserver = observer;
|
|
108
|
+
toaster.querySelectorAll('.toast:not([data-toast-initialized])').forEach(element => initToast(element));
|
|
109
|
+
toasterElement._destroy = () => {
|
|
110
|
+
listeners.abort();
|
|
111
|
+
swipe = null;
|
|
112
|
+
toasterElement.querySelectorAll('.toast[data-toast-initialized]').forEach(toast => toast._destroy?.());
|
|
113
|
+
observer.disconnect();
|
|
114
|
+
delete toasterElement.toast;
|
|
115
|
+
delete toasterElement.closeAll;
|
|
116
|
+
if (toaster === toasterElement) {
|
|
117
|
+
resizeObserver = null;
|
|
118
|
+
isPaused = false;
|
|
119
|
+
focusBeforeToasts = null;
|
|
120
|
+
toaster = null;
|
|
121
|
+
}
|
|
47
122
|
};
|
|
48
123
|
toaster.dataset.toasterInitialized = 'true';
|
|
124
|
+
updateStack();
|
|
49
125
|
toaster.dispatchEvent(new CustomEvent('basecoat:initialized'));
|
|
50
126
|
}
|
|
51
127
|
|
|
52
|
-
function
|
|
53
|
-
if (
|
|
128
|
+
function updateStack() {
|
|
129
|
+
if (!toaster) return;
|
|
54
130
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
? duration || (element.dataset.category === 'error' ? 5000 : 3000)
|
|
58
|
-
: -1;
|
|
59
|
-
|
|
60
|
-
const state = {
|
|
61
|
-
remainingTime: timeoutDuration,
|
|
62
|
-
timeoutId: null,
|
|
63
|
-
startTime: null,
|
|
64
|
-
};
|
|
131
|
+
const elements = Array.from(toaster.querySelectorAll('.toast:not([aria-hidden="true"])')).reverse();
|
|
132
|
+
let offset = 0;
|
|
65
133
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
134
|
+
const expanded = toaster.matches(':hover, :focus-within, :has([data-toast-swiping])');
|
|
135
|
+
const entries = elements.map(element => {
|
|
136
|
+
const content = element.querySelector('.toast-content') || element;
|
|
137
|
+
const styles = getComputedStyle(element);
|
|
138
|
+
return { element, content, height: content.offsetHeight + parseFloat(styles.borderTopWidth) + parseFloat(styles.borderBottomWidth) };
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
entries.forEach(({ element, content, height }, index) => {
|
|
142
|
+
element.style.setProperty('--toast-offset', `${offset}px`);
|
|
143
|
+
element.style.setProperty('--toast-index', index);
|
|
144
|
+
element.style.setProperty('--toast-height', `${height}px`);
|
|
145
|
+
element.style.setProperty('--toast-front-height', `${entries[0].height}px`);
|
|
146
|
+
element.toggleAttribute('data-toast-stack-overflow', index >= STACK_VISIBLE);
|
|
147
|
+
// Keep hidden content out of the tab order; hovering/focusing expands the stack.
|
|
148
|
+
const hidden = index >= STACK_VISIBLE || (!expanded && index > 0);
|
|
149
|
+
if (hidden && content.contains(document.activeElement)) {
|
|
150
|
+
const target = entries[0].content.querySelector('button:not(:disabled), a[href]') || (focusBeforeToasts?.isConnected ? focusBeforeToasts : toaster);
|
|
151
|
+
if (target === toaster && !toaster.hasAttribute('tabindex')) toaster.tabIndex = -1;
|
|
152
|
+
target.focus({ preventScroll: true });
|
|
72
153
|
}
|
|
154
|
+
content.inert = hidden;
|
|
155
|
+
offset += height + STACK_GAP;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function resetTimeout(element, state) {
|
|
160
|
+
clearTimeout(state.timeoutId);
|
|
161
|
+
const duration = parseInt(element.dataset.duration);
|
|
162
|
+
state.remainingTime = Number.isNaN(duration) || duration === 0
|
|
163
|
+
? element.dataset.category === 'loading' ? -1 : element.dataset.category === 'error' ? 5000 : 3000
|
|
164
|
+
: duration;
|
|
165
|
+
state.timeoutId = null;
|
|
166
|
+
if (state.remainingTime !== -1 && (!isPaused || !toaster?.contains(element))) {
|
|
167
|
+
state.startTime = Date.now();
|
|
168
|
+
state.timeoutId = setTimeout(() => closeToast(element), state.remainingTime);
|
|
73
169
|
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function initToast(element, config) {
|
|
173
|
+
if (element.dataset.toastInitialized) return;
|
|
174
|
+
const state = { remainingTime: -1, timeoutId: null, startTime: null };
|
|
74
175
|
toasts.set(element, state);
|
|
176
|
+
resetTimeout(element, state);
|
|
75
177
|
|
|
178
|
+
const content = element.querySelector('.toast-content') || element;
|
|
179
|
+
resizeObserver?.observe(content);
|
|
76
180
|
element.close = () => closeToast(element);
|
|
181
|
+
if (config !== undefined) {
|
|
182
|
+
let currentConfig = { ...config };
|
|
183
|
+
element.update = (changes = {}) => {
|
|
184
|
+
// An async result must not resurrect a dismissed toast.
|
|
185
|
+
if (!toasts.has(element) || !element.isConnected) return;
|
|
186
|
+
currentConfig = { ...currentConfig, ...changes };
|
|
187
|
+
const replacement = createToast(currentConfig);
|
|
188
|
+
const controls = [...element.querySelectorAll('footer a, footer button')];
|
|
189
|
+
const focusedIndex = controls.indexOf(document.activeElement);
|
|
190
|
+
content.replaceChildren(...replacement.firstElementChild.childNodes);
|
|
191
|
+
content.setAttribute('role', replacement.firstElementChild.getAttribute('role'));
|
|
192
|
+
for (const attribute of ['data-category', 'data-duration']) {
|
|
193
|
+
if (replacement.hasAttribute(attribute)) element.setAttribute(attribute, replacement.getAttribute(attribute));
|
|
194
|
+
else element.removeAttribute(attribute);
|
|
195
|
+
}
|
|
196
|
+
if (focusedIndex >= 0) {
|
|
197
|
+
const nextControls = element.querySelectorAll('footer a, footer button');
|
|
198
|
+
const target = nextControls[focusedIndex] || nextControls[0] || toaster;
|
|
199
|
+
if (target && target === toaster && !target.hasAttribute('tabindex')) target.tabIndex = -1;
|
|
200
|
+
target?.focus({ preventScroll: true });
|
|
201
|
+
}
|
|
202
|
+
resetTimeout(element, toasts.get(element));
|
|
203
|
+
updateStack();
|
|
204
|
+
return element;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
77
207
|
element._destroy = () => {
|
|
78
208
|
clearTimeout(state.timeoutId);
|
|
209
|
+
resizeObserver?.unobserve(content);
|
|
79
210
|
toasts.delete(element);
|
|
80
211
|
delete element.close;
|
|
212
|
+
delete element.dataset.toastInitialized;
|
|
213
|
+
// Keep update callable for pending promises and forced reinitialization.
|
|
214
|
+
if (!element.isConnected) updateStack();
|
|
81
215
|
};
|
|
216
|
+
updateStack();
|
|
217
|
+
// Flush the initial offscreen position before transitioning to the stack.
|
|
218
|
+
element.getBoundingClientRect();
|
|
82
219
|
element.dataset.toastInitialized = 'true';
|
|
220
|
+
element.dataset.basecoatComponent = 'toast';
|
|
83
221
|
}
|
|
84
222
|
|
|
85
223
|
function pauseAllTimeouts() {
|
|
86
224
|
if (isPaused || !toaster) return;
|
|
87
225
|
|
|
88
226
|
isPaused = true;
|
|
227
|
+
updateStack();
|
|
89
228
|
|
|
90
229
|
toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
|
|
91
|
-
if (!toasts.has(element)) return;
|
|
92
|
-
|
|
93
230
|
const state = toasts.get(element);
|
|
231
|
+
if (!state) return;
|
|
94
232
|
if (state.timeoutId) {
|
|
95
233
|
clearTimeout(state.timeoutId);
|
|
96
234
|
state.timeoutId = null;
|
|
97
|
-
state.remainingTime
|
|
235
|
+
state.remainingTime = Math.max(0, state.remainingTime - (Date.now() - state.startTime));
|
|
98
236
|
}
|
|
99
237
|
});
|
|
100
238
|
}
|
|
@@ -103,11 +241,11 @@
|
|
|
103
241
|
if (!isPaused || !toaster) return;
|
|
104
242
|
|
|
105
243
|
isPaused = false;
|
|
244
|
+
updateStack();
|
|
106
245
|
|
|
107
246
|
toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
|
|
108
|
-
if (!toasts.has(element)) return;
|
|
109
|
-
|
|
110
247
|
const state = toasts.get(element);
|
|
248
|
+
if (!state) return;
|
|
111
249
|
if (state.remainingTime !== -1 && !state.timeoutId) {
|
|
112
250
|
if (state.remainingTime > 0) {
|
|
113
251
|
state.startTime = Date.now();
|
|
@@ -122,13 +260,41 @@
|
|
|
122
260
|
function closeToast(element) {
|
|
123
261
|
if (!element || !toasts.has(element)) return;
|
|
124
262
|
|
|
263
|
+
const host = toaster?.contains(element) ? toaster : null;
|
|
125
264
|
const state = toasts.get(element);
|
|
126
265
|
clearTimeout(state.timeoutId);
|
|
266
|
+
resizeObserver?.unobserve(element.querySelector('.toast-content') || element);
|
|
127
267
|
toasts.delete(element);
|
|
128
268
|
|
|
129
|
-
if (element.contains(document.activeElement))
|
|
269
|
+
if (element.contains(document.activeElement)) {
|
|
270
|
+
const remaining = [...(host?.querySelectorAll('.toast:not([aria-hidden="true"])') || [])].filter(toast => toast !== element);
|
|
271
|
+
const nextControl = remaining.at(-1)?.querySelector('button:not(:disabled), a[href]');
|
|
272
|
+
const keyboard = document.activeElement.matches(':focus-visible');
|
|
273
|
+
const focusTarget = (keyboard && nextControl) || (host && focusBeforeToasts?.isConnected ? focusBeforeToasts : null);
|
|
274
|
+
if (!focusTarget) document.activeElement.blur();
|
|
275
|
+
else {
|
|
276
|
+
focusTarget.focus({ preventScroll: true });
|
|
277
|
+
if (element.contains(document.activeElement)) {
|
|
278
|
+
host.tabIndex = -1;
|
|
279
|
+
host.focus({ preventScroll: true });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (host?.matches(':hover, :focus-within, :has([data-toast-swiping])')) element.dataset.toastExpanded = '';
|
|
130
284
|
element.setAttribute('aria-hidden', 'true');
|
|
131
|
-
element.
|
|
285
|
+
element.inert = true;
|
|
286
|
+
updateStack();
|
|
287
|
+
|
|
288
|
+
const remove = () => {
|
|
289
|
+
if (!element.isConnected) return;
|
|
290
|
+
element.remove();
|
|
291
|
+
updateStack();
|
|
292
|
+
};
|
|
293
|
+
requestAnimationFrame(() => {
|
|
294
|
+
const animations = element.getAnimations();
|
|
295
|
+
if (!animations.length) return remove();
|
|
296
|
+
Promise.allSettled(animations.map(animation => animation.finished)).then(remove);
|
|
297
|
+
});
|
|
132
298
|
}
|
|
133
299
|
|
|
134
300
|
const escapeHtml = (value) => String(value)
|
|
@@ -147,6 +313,7 @@
|
|
|
147
313
|
cancel,
|
|
148
314
|
duration,
|
|
149
315
|
icon,
|
|
316
|
+
closeButton = true,
|
|
150
317
|
html: allowHtml = false,
|
|
151
318
|
} = config;
|
|
152
319
|
|
|
@@ -157,25 +324,26 @@
|
|
|
157
324
|
const titleHtml = title ? `<h2>${text(title)}</h2>` : '';
|
|
158
325
|
const descriptionHtml = description ? `<p>${text(description)}</p>` : '';
|
|
159
326
|
const actionHtml = action?.href
|
|
160
|
-
? `<a href="${escapeHtml(action.href)}" class="btn" data-toast-action>${text(action.label)}</a>`
|
|
161
|
-
: action
|
|
162
|
-
? `<button type="button" class="btn" data-toast-action onclick="${escapeHtml(action.onclick)}">${text(action.label)}</button>`
|
|
327
|
+
? `<a href="${escapeHtml(action.href)}" class="btn" data-variant="outline" data-size="sm" data-toast-action>${text(action.label)}</a>`
|
|
328
|
+
: action
|
|
329
|
+
? `<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-action ${action.onclick ? `onclick="${escapeHtml(action.onclick)}"` : ''}>${text(action.label)}</button>`
|
|
163
330
|
: '';
|
|
164
331
|
const cancelHtml = cancel
|
|
165
|
-
? `<button type="button" class="btn
|
|
332
|
+
? `<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-cancel ${cancel.onclick ? `onclick="${escapeHtml(cancel.onclick)}"` : ''}>${text(cancel.label)}</button>`
|
|
166
333
|
: '';
|
|
167
334
|
|
|
168
|
-
const
|
|
335
|
+
const closeHtml = closeButton
|
|
336
|
+
? '<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>'
|
|
337
|
+
: '';
|
|
338
|
+
const footerHtml = actionHtml || cancelHtml || closeHtml ? `<footer>${actionHtml}${cancelHtml}${closeHtml}</footer>` : '';
|
|
169
339
|
|
|
170
340
|
const html = `
|
|
171
|
-
<
|
|
341
|
+
<li
|
|
172
342
|
class="toast"
|
|
173
|
-
role="${category === 'error' ? 'alert' : 'status'}"
|
|
174
|
-
aria-atomic="true"
|
|
175
343
|
${category ? `data-category="${escapeHtml(category)}"` : ''}
|
|
176
344
|
${duration !== undefined ? `data-duration="${escapeHtml(duration)}"` : ''}
|
|
177
345
|
>
|
|
178
|
-
<div class="toast-content">
|
|
346
|
+
<div class="toast-content" role="${category === 'error' ? 'alert' : 'status'}" aria-atomic="true">
|
|
179
347
|
${iconHtml}
|
|
180
348
|
<section>
|
|
181
349
|
${titleHtml}
|
|
@@ -183,7 +351,7 @@
|
|
|
183
351
|
</section>
|
|
184
352
|
${footerHtml}
|
|
185
353
|
</div>
|
|
186
|
-
</
|
|
354
|
+
</li>
|
|
187
355
|
`;
|
|
188
356
|
const template = document.createElement('template');
|
|
189
357
|
template.innerHTML = html.trim();
|
package/dist/js/toast.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{let t;const
|
|
1
|
+
(()=>{let t,e;const n=new WeakMap;let o,a=!1;const i={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>',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>',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>',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>',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>'};function r(){if(!t)return;const e=Array.from(t.querySelectorAll('.toast:not([aria-hidden="true"])')).reverse();let n=0;const a=t.matches(":hover, :focus-within, :has([data-toast-swiping])"),i=e.map(t=>{const e=t.querySelector(".toast-content")||t,n=getComputedStyle(t);return{element:t,content:e,height:e.offsetHeight+parseFloat(n.borderTopWidth)+parseFloat(n.borderBottomWidth)}});i.forEach(({element:e,content:r,height:s},l)=>{e.style.setProperty("--toast-offset",`${n}px`),e.style.setProperty("--toast-index",l),e.style.setProperty("--toast-height",`${s}px`),e.style.setProperty("--toast-front-height",`${i[0].height}px`),e.toggleAttribute("data-toast-stack-overflow",l>=3);const d=l>=3||!a&&l>0;if(d&&r.contains(document.activeElement)){const e=i[0].content.querySelector("button:not(:disabled), a[href]")||(o?.isConnected?o:t);e!==t||t.hasAttribute("tabindex")||(t.tabIndex=-1),e.focus({preventScroll:!0})}r.inert=d,n+=s+12})}function s(e,n){clearTimeout(n.timeoutId);const o=parseInt(e.dataset.duration);n.remainingTime=Number.isNaN(o)||0===o?"loading"===e.dataset.category?-1:"error"===e.dataset.category?5e3:3e3:o,n.timeoutId=null,-1===n.remainingTime||a&&t?.contains(e)||(n.startTime=Date.now(),n.timeoutId=setTimeout(()=>d(e),n.remainingTime))}function l(o,a){if(o.dataset.toastInitialized)return;const i={remainingTime:-1,timeoutId:null,startTime:null};n.set(o,i),s(o,i);const l=o.querySelector(".toast-content")||o;if(e?.observe(l),o.close=()=>d(o),void 0!==a){let e={...a};o.update=(a={})=>{if(!n.has(o)||!o.isConnected)return;e={...e,...a};const i=u(e),d=[...o.querySelectorAll("footer a, footer button")].indexOf(document.activeElement);l.replaceChildren(...i.firstElementChild.childNodes),l.setAttribute("role",i.firstElementChild.getAttribute("role"));for(const t of["data-category","data-duration"])i.hasAttribute(t)?o.setAttribute(t,i.getAttribute(t)):o.removeAttribute(t);if(d>=0){const e=o.querySelectorAll("footer a, footer button"),n=e[d]||e[0]||t;n&&n===t&&!n.hasAttribute("tabindex")&&(n.tabIndex=-1),n?.focus({preventScroll:!0})}return s(o,n.get(o)),r(),o}}o._destroy=()=>{clearTimeout(i.timeoutId),e?.unobserve(l),n.delete(o),delete o.close,delete o.dataset.toastInitialized,o.isConnected||r()},r(),o.getBoundingClientRect(),o.dataset.toastInitialized="true",o.dataset.basecoatComponent="toast"}function d(a){if(!a||!n.has(a))return;const i=t?.contains(a)?t:null,s=n.get(a);if(clearTimeout(s.timeoutId),e?.unobserve(a.querySelector(".toast-content")||a),n.delete(a),a.contains(document.activeElement)){const t=[...i?.querySelectorAll('.toast:not([aria-hidden="true"])')||[]].filter(t=>t!==a),e=t.at(-1)?.querySelector("button:not(:disabled), a[href]"),n=document.activeElement.matches(":focus-visible")&&e||(i&&o?.isConnected?o:null);n?(n.focus({preventScroll:!0}),a.contains(document.activeElement)&&(i.tabIndex=-1,i.focus({preventScroll:!0}))):document.activeElement.blur()}i?.matches(":hover, :focus-within, :has([data-toast-swiping])")&&(a.dataset.toastExpanded=""),a.setAttribute("aria-hidden","true"),a.inert=!0,r();const l=()=>{a.isConnected&&(a.remove(),r())};requestAnimationFrame(()=>{const t=a.getAnimations();if(!t.length)return l();Promise.allSettled(t.map(t=>t.finished)).then(l)})}const c=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");function u(t){const{category:e="info",title:n,description:o,action:a,cancel:r,duration:s,icon:l,closeButton:d=!0,html:u=!1}=t,h=t=>u?String(t):c(t),m=l||e&&i[e]||"",g=n?`<h2>${h(n)}</h2>`:"",p=o?`<p>${h(o)}</p>`:"",v=a?.href?`<a href="${c(a.href)}" class="btn" data-variant="outline" data-size="sm" data-toast-action>${h(a.label)}</a>`:a?`<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-action ${a.onclick?`onclick="${c(a.onclick)}"`:""}>${h(a.label)}</button>`:"",f=r?`<button type="button" class="btn" data-variant="outline" data-size="sm" data-toast-cancel ${r.onclick?`onclick="${c(r.onclick)}"`:""}>${h(r.label)}</button>`:"",w=d?'<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>':"",b=v||f||w?`<footer>${v}${f}${w}</footer>`:"",y=`\n <li\n class="toast"\n ${e?`data-category="${c(e)}"`:""}\n ${void 0!==s?`data-duration="${c(s)}"`:""}\n >\n <div class="toast-content" role="${"error"===e?"alert":"status"}" aria-atomic="true">\n ${m}\n <section>\n ${g}\n ${p}\n </section>\n ${b}\n </div>\n </li>\n `,x=document.createElement("template");return x.innerHTML=y.trim(),x.content.firstChild}window.basecoat&&(window.basecoat.register("toaster","#toaster:not([data-toaster-initialized])",function(i){if(i.dataset.toasterInitialized)return;let s;t=i,a=t.matches(":hover, :focus-within");const c=()=>s||t.matches(":hover, :focus-within")?void(!a&&t&&(a=!0,r(),t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(t=>{const e=n.get(t);e&&e.timeoutId&&(clearTimeout(e.timeoutId),e.timeoutId=null,e.remainingTime=Math.max(0,e.remainingTime-(Date.now()-e.startTime)))}))):void(a&&t&&(a=!1,r(),t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(t=>{const e=n.get(t);e&&(-1===e.remainingTime||e.timeoutId||(e.remainingTime>0?(e.startTime=Date.now(),e.timeoutId=setTimeout(()=>d(t),e.remainingTime)):d(t)))}))),h=t=>{if(!s||t.pointerId!==s.id)return;const{element:e,axis:n,distance:o,sign:a,time:i}=s,l="pointercancel"!==t.type&&(o>40||o>10&&o/Math.max(1,t.timeStamp-i)>.5);delete e.dataset.toastSwiping,l?(e.dataset.toastSwipe=n,e.style.setProperty("--toast-swipe-end",150*a+"%"),d(e)):(e.style.removeProperty("--toast-swipe-x"),e.style.removeProperty("--toast-swipe-y")),e.hasPointerCapture(t.pointerId)&&e.releasePointerCapture(t.pointerId),s=null,c(),r()},m=new AbortController,{signal:g}=m;t.addEventListener("mouseenter",c,{signal:g}),t.addEventListener("mouseleave",c,{signal:g}),t.addEventListener("focusin",e=>{e.relatedTarget instanceof HTMLElement&&e.relatedTarget!==document.body&&!t.contains(e.relatedTarget)&&(o=e.relatedTarget),c()},{signal:g}),t.addEventListener("focusout",t=>{i.contains(t.relatedTarget)||c()},{signal:g}),t.addEventListener("click",t=>{const e=t.target.closest(".toast footer a, .toast footer button");e&&d(e.closest(".toast"))},{signal:g}),t.addEventListener("pointerdown",e=>{if(!e.isPrimary||0!==e.button||e.target.closest("a, button, input, textarea, select, [contenteditable]"))return;const n=e.target.closest('.toast:not([aria-hidden="true"])');if(!n)return;const o=("rtl"===getComputedStyle(t).direction?-1:1)*("start"===t.dataset.align?-1:1);s={element:n,id:e.pointerId,x:e.clientX,y:e.clientY,time:e.timeStamp,distance:0,sign:o},n.setPointerCapture(e.pointerId),c()},{signal:g}),t.addEventListener("pointermove",t=>{if(!s||t.pointerId!==s.id)return;const e=(t.clientX-s.x)*s.sign,n=t.clientY-s.y;if(!s.axis){if(Math.max(e,n)<8)return;s.axis=e>n?"x":"y",s.element.dataset.toastSwiping="",r()}s.distance=Math.max(0,"x"===s.axis?e:n),s.element.style.setProperty(`--toast-swipe-${s.axis}`,s.distance*("x"===s.axis?s.sign:1)+"px")},{signal:g}),t.addEventListener("pointerup",h,{signal:g}),t.addEventListener("pointercancel",h,{signal:g}),window.addEventListener("pointerup",h,{signal:g}),window.addEventListener("pointercancel",h,{signal:g}),i.toast=(t={})=>{const e=u(t);return i.appendChild(e),l(e,t),e},i.closeAll=()=>{i.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(d)};const p=new ResizeObserver(r);e=p,t.querySelectorAll(".toast:not([data-toast-initialized])").forEach(t=>l(t)),i._destroy=()=>{m.abort(),s=null,i.querySelectorAll(".toast[data-toast-initialized]").forEach(t=>t._destroy?.()),p.disconnect(),delete i.toast,delete i.closeAll,t===i&&(e=null,a=!1,o=null,t=null)},t.dataset.toasterInitialized="true",r(),t.dispatchEvent(new CustomEvent("basecoat:initialized"))}),window.basecoat.register("toast",".toast:not([data-toast-initialized])",l))})();
|