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/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
|
|
|
@@ -1045,6 +1199,7 @@
|
|
|
1045
1199
|
const nativeClose = drawer.close.bind(drawer);
|
|
1046
1200
|
let pointerStartedOnBackdrop = false;
|
|
1047
1201
|
let closeTimer = null;
|
|
1202
|
+
let closeReturnValue = '';
|
|
1048
1203
|
|
|
1049
1204
|
const finishClose = (returnValue) => {
|
|
1050
1205
|
window.clearTimeout(closeTimer);
|
|
@@ -1065,6 +1220,7 @@
|
|
|
1065
1220
|
return;
|
|
1066
1221
|
}
|
|
1067
1222
|
|
|
1223
|
+
closeReturnValue = returnValue;
|
|
1068
1224
|
drawer.dataset.closing = 'true';
|
|
1069
1225
|
closeTimer = window.setTimeout(() => finishClose(returnValue), duration + 50);
|
|
1070
1226
|
};
|
|
@@ -1090,7 +1246,9 @@
|
|
|
1090
1246
|
drawer.addEventListener('pointerup', handlePointerUp);
|
|
1091
1247
|
|
|
1092
1248
|
drawer._destroy = () => {
|
|
1093
|
-
|
|
1249
|
+
// Finish an in-flight close before reinitialization cancels its animation.
|
|
1250
|
+
if (closeTimer !== null) finishClose(closeReturnValue);
|
|
1251
|
+
drawer.removeAttribute('data-closing');
|
|
1094
1252
|
drawer.removeEventListener('cancel', handleCancel);
|
|
1095
1253
|
drawer.removeEventListener('pointerdown', handlePointerDown);
|
|
1096
1254
|
drawer.removeEventListener('pointerup', handlePointerUp);
|
|
@@ -1103,7 +1261,7 @@
|
|
|
1103
1261
|
};
|
|
1104
1262
|
|
|
1105
1263
|
if (window.basecoat) {
|
|
1106
|
-
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);
|
|
1107
1265
|
}
|
|
1108
1266
|
})();
|
|
1109
1267
|
|
|
@@ -1315,6 +1473,83 @@
|
|
|
1315
1473
|
}
|
|
1316
1474
|
})();
|
|
1317
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
|
+
|
|
1318
1553
|
(() => {
|
|
1319
1554
|
const initPopover = (popoverComponent) => {
|
|
1320
1555
|
if (popoverComponent.dataset.popoverInitialized) return;
|
|
@@ -1962,61 +2197,38 @@
|
|
|
1962
2197
|
})();
|
|
1963
2198
|
|
|
1964
2199
|
(() => {
|
|
1965
|
-
const states = new WeakMap();
|
|
1966
|
-
|
|
1967
2200
|
const isDisabled = (tab) => tab.disabled || tab.getAttribute('aria-disabled') === 'true';
|
|
1968
2201
|
|
|
1969
|
-
const getElements = (root) => {
|
|
1970
|
-
const tablist = root.querySelector('[role="tablist"]');
|
|
1971
|
-
const tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
|
|
1972
|
-
const panels = tabs.map(tab => document.getElementById(tab.getAttribute('aria-controls'))).filter(Boolean);
|
|
1973
|
-
return { tablist, tabs, panels };
|
|
1974
|
-
};
|
|
1975
|
-
|
|
1976
|
-
const refreshTabs = (root) => {
|
|
1977
|
-
const state = states.get(root);
|
|
1978
|
-
if (!state) return;
|
|
1979
|
-
|
|
1980
|
-
Object.assign(state, getElements(root));
|
|
1981
|
-
if (!state.tablist) return;
|
|
1982
|
-
|
|
1983
|
-
const selected = state.tabs.find(tab => tab.getAttribute('aria-selected') === 'true' && !isDisabled(tab))
|
|
1984
|
-
|| state.tabs.find(tab => !isDisabled(tab));
|
|
1985
|
-
if (selected) root.select(selected, false);
|
|
1986
|
-
};
|
|
1987
|
-
|
|
1988
2202
|
const initTabs = (root) => {
|
|
1989
2203
|
if (root.dataset.tabsInitialized) return;
|
|
1990
2204
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
root.refresh = () => refreshTabs(root);
|
|
1994
|
-
|
|
2205
|
+
let tablist;
|
|
2206
|
+
let tabs = [];
|
|
1995
2207
|
const selectTab = (tabToSelect, focus = false) => {
|
|
1996
|
-
if (!tabToSelect || isDisabled(tabToSelect)) return;
|
|
2208
|
+
if (!tabs.includes(tabToSelect) || isDisabled(tabToSelect)) return;
|
|
1997
2209
|
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
tab
|
|
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;
|
|
2001
2215
|
const panel = document.getElementById(tab.getAttribute('aria-controls'));
|
|
2002
|
-
if (panel) panel.hidden =
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
tabToSelect.setAttribute('aria-selected', 'true');
|
|
2006
|
-
tabToSelect.setAttribute('tabindex', '0');
|
|
2007
|
-
const activePanel = document.getElementById(tabToSelect.getAttribute('aria-controls'));
|
|
2008
|
-
if (activePanel) activePanel.hidden = false;
|
|
2216
|
+
if (panel) panel.hidden = panel.id !== activePanelId;
|
|
2217
|
+
}
|
|
2009
2218
|
if (focus) tabToSelect.focus();
|
|
2010
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
|
+
};
|
|
2011
2227
|
|
|
2228
|
+
refresh();
|
|
2229
|
+
if (!tablist) return;
|
|
2012
2230
|
root.select = selectTab;
|
|
2013
|
-
|
|
2014
|
-
if (!state.tablist) {
|
|
2015
|
-
states.delete(root);
|
|
2016
|
-
delete root.refresh;
|
|
2017
|
-
delete root.select;
|
|
2018
|
-
return;
|
|
2019
|
-
}
|
|
2231
|
+
root.refresh = refresh;
|
|
2020
2232
|
|
|
2021
2233
|
const handleClick = (event) => {
|
|
2022
2234
|
const clickedTab = event.target.closest('[role="tab"]');
|
|
@@ -2025,16 +2237,17 @@
|
|
|
2025
2237
|
|
|
2026
2238
|
const handleKeydown = (event) => {
|
|
2027
2239
|
const currentTab = event.target;
|
|
2028
|
-
if (!
|
|
2240
|
+
if (!tabs.includes(currentTab)) return;
|
|
2029
2241
|
|
|
2030
|
-
const enabledTabs =
|
|
2242
|
+
const enabledTabs = tabs.filter(tab => !isDisabled(tab));
|
|
2031
2243
|
const currentIndex = enabledTabs.indexOf(currentTab);
|
|
2032
|
-
const orientation =
|
|
2244
|
+
const orientation = tablist.getAttribute('aria-orientation') || 'horizontal';
|
|
2033
2245
|
if (currentIndex === -1) return;
|
|
2034
2246
|
|
|
2247
|
+
const forward = getComputedStyle(tablist).direction === 'rtl' ? -1 : 1;
|
|
2035
2248
|
let nextTab;
|
|
2036
|
-
if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex +
|
|
2037
|
-
if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex -
|
|
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];
|
|
2038
2251
|
if (event.key === 'ArrowDown' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
|
|
2039
2252
|
if (event.key === 'ArrowUp' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
|
|
2040
2253
|
if (event.key === 'Home') nextTab = enabledTabs[0];
|
|
@@ -2045,13 +2258,12 @@
|
|
|
2045
2258
|
root.select(nextTab, true);
|
|
2046
2259
|
};
|
|
2047
2260
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2261
|
+
root.addEventListener('click', handleClick);
|
|
2262
|
+
root.addEventListener('keydown', handleKeydown);
|
|
2050
2263
|
|
|
2051
2264
|
root._destroy = () => {
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
states.delete(root);
|
|
2265
|
+
root.removeEventListener('click', handleClick);
|
|
2266
|
+
root.removeEventListener('keydown', handleKeydown);
|
|
2055
2267
|
delete root.refresh;
|
|
2056
2268
|
delete root.select;
|
|
2057
2269
|
};
|
|
@@ -2061,111 +2273,245 @@
|
|
|
2061
2273
|
};
|
|
2062
2274
|
|
|
2063
2275
|
if (window.basecoat) {
|
|
2064
|
-
window.basecoat.register('tabs',
|
|
2065
|
-
selector: '.tabs:not([data-tabs-initialized])',
|
|
2066
|
-
init: initTabs,
|
|
2067
|
-
refresh: refreshTabs,
|
|
2068
|
-
});
|
|
2276
|
+
window.basecoat.register('tabs', '.tabs:not([data-tabs-initialized])', initTabs);
|
|
2069
2277
|
}
|
|
2070
2278
|
})();
|
|
2071
2279
|
|
|
2072
2280
|
(() => {
|
|
2073
2281
|
let toaster;
|
|
2282
|
+
let resizeObserver;
|
|
2074
2283
|
const toasts = new WeakMap();
|
|
2075
2284
|
let isPaused = false;
|
|
2285
|
+
let focusBeforeToasts;
|
|
2286
|
+
const STACK_GAP = 12;
|
|
2287
|
+
const STACK_VISIBLE = 3;
|
|
2076
2288
|
const ICONS = {
|
|
2077
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>',
|
|
2078
|
-
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"><
|
|
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>',
|
|
2079
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>',
|
|
2080
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>'
|
|
2081
2294
|
};
|
|
2082
2295
|
|
|
2083
2296
|
function initToaster(toasterElement) {
|
|
2084
2297
|
if (toasterElement.dataset.toasterInitialized) return;
|
|
2085
2298
|
toaster = toasterElement;
|
|
2299
|
+
isPaused = toaster.matches(':hover, :focus-within');
|
|
2300
|
+
let swipe;
|
|
2086
2301
|
|
|
2087
2302
|
const handleClick = (event) => {
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
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;
|
|
2092
2309
|
}
|
|
2310
|
+
syncPause();
|
|
2093
2311
|
};
|
|
2312
|
+
const syncPause = () => swipe || toaster.matches(':hover, :focus-within')
|
|
2313
|
+
? pauseAllTimeouts()
|
|
2314
|
+
: resumeAllTimeouts();
|
|
2094
2315
|
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
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 });
|
|
2098
2374
|
|
|
2099
2375
|
toasterElement.toast = (config = {}) => {
|
|
2100
2376
|
const toastElement = createToast(config);
|
|
2101
2377
|
toasterElement.appendChild(toastElement);
|
|
2102
|
-
initToast(toastElement);
|
|
2378
|
+
initToast(toastElement, config);
|
|
2103
2379
|
return toastElement;
|
|
2104
2380
|
};
|
|
2105
2381
|
toasterElement.closeAll = () => {
|
|
2106
2382
|
toasterElement.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(closeToast);
|
|
2107
2383
|
};
|
|
2108
2384
|
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
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
|
+
}
|
|
2118
2401
|
};
|
|
2119
2402
|
toaster.dataset.toasterInitialized = 'true';
|
|
2403
|
+
updateStack();
|
|
2120
2404
|
toaster.dispatchEvent(new CustomEvent('basecoat:initialized'));
|
|
2121
2405
|
}
|
|
2122
2406
|
|
|
2123
|
-
function
|
|
2124
|
-
if (
|
|
2407
|
+
function updateStack() {
|
|
2408
|
+
if (!toaster) return;
|
|
2125
2409
|
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
? duration || (element.dataset.category === 'error' ? 5000 : 3000)
|
|
2129
|
-
: -1;
|
|
2410
|
+
const elements = Array.from(toaster.querySelectorAll('.toast:not([aria-hidden="true"])')).reverse();
|
|
2411
|
+
let offset = 0;
|
|
2130
2412
|
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
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
|
+
});
|
|
2136
2419
|
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
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 });
|
|
2143
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);
|
|
2144
2448
|
}
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
function initToast(element, config) {
|
|
2452
|
+
if (element.dataset.toastInitialized) return;
|
|
2453
|
+
const state = { remainingTime: -1, timeoutId: null, startTime: null };
|
|
2145
2454
|
toasts.set(element, state);
|
|
2455
|
+
resetTimeout(element, state);
|
|
2146
2456
|
|
|
2457
|
+
const content = element.querySelector('.toast-content') || element;
|
|
2458
|
+
resizeObserver?.observe(content);
|
|
2147
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
|
+
}
|
|
2148
2486
|
element._destroy = () => {
|
|
2149
2487
|
clearTimeout(state.timeoutId);
|
|
2488
|
+
resizeObserver?.unobserve(content);
|
|
2150
2489
|
toasts.delete(element);
|
|
2151
2490
|
delete element.close;
|
|
2491
|
+
delete element.dataset.toastInitialized;
|
|
2492
|
+
// Keep update callable for pending promises and forced reinitialization.
|
|
2493
|
+
if (!element.isConnected) updateStack();
|
|
2152
2494
|
};
|
|
2495
|
+
updateStack();
|
|
2496
|
+
// Flush the initial offscreen position before transitioning to the stack.
|
|
2497
|
+
element.getBoundingClientRect();
|
|
2153
2498
|
element.dataset.toastInitialized = 'true';
|
|
2499
|
+
element.dataset.basecoatComponent = 'toast';
|
|
2154
2500
|
}
|
|
2155
2501
|
|
|
2156
2502
|
function pauseAllTimeouts() {
|
|
2157
2503
|
if (isPaused || !toaster) return;
|
|
2158
2504
|
|
|
2159
2505
|
isPaused = true;
|
|
2506
|
+
updateStack();
|
|
2160
2507
|
|
|
2161
2508
|
toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
|
|
2162
|
-
if (!toasts.has(element)) return;
|
|
2163
|
-
|
|
2164
2509
|
const state = toasts.get(element);
|
|
2510
|
+
if (!state) return;
|
|
2165
2511
|
if (state.timeoutId) {
|
|
2166
2512
|
clearTimeout(state.timeoutId);
|
|
2167
2513
|
state.timeoutId = null;
|
|
2168
|
-
state.remainingTime
|
|
2514
|
+
state.remainingTime = Math.max(0, state.remainingTime - (Date.now() - state.startTime));
|
|
2169
2515
|
}
|
|
2170
2516
|
});
|
|
2171
2517
|
}
|
|
@@ -2174,11 +2520,11 @@
|
|
|
2174
2520
|
if (!isPaused || !toaster) return;
|
|
2175
2521
|
|
|
2176
2522
|
isPaused = false;
|
|
2523
|
+
updateStack();
|
|
2177
2524
|
|
|
2178
2525
|
toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
|
|
2179
|
-
if (!toasts.has(element)) return;
|
|
2180
|
-
|
|
2181
2526
|
const state = toasts.get(element);
|
|
2527
|
+
if (!state) return;
|
|
2182
2528
|
if (state.remainingTime !== -1 && !state.timeoutId) {
|
|
2183
2529
|
if (state.remainingTime > 0) {
|
|
2184
2530
|
state.startTime = Date.now();
|
|
@@ -2193,13 +2539,41 @@
|
|
|
2193
2539
|
function closeToast(element) {
|
|
2194
2540
|
if (!element || !toasts.has(element)) return;
|
|
2195
2541
|
|
|
2542
|
+
const host = toaster?.contains(element) ? toaster : null;
|
|
2196
2543
|
const state = toasts.get(element);
|
|
2197
2544
|
clearTimeout(state.timeoutId);
|
|
2545
|
+
resizeObserver?.unobserve(element.querySelector('.toast-content') || element);
|
|
2198
2546
|
toasts.delete(element);
|
|
2199
2547
|
|
|
2200
|
-
if (element.contains(document.activeElement))
|
|
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 = '';
|
|
2201
2563
|
element.setAttribute('aria-hidden', 'true');
|
|
2202
|
-
element.
|
|
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
|
+
});
|
|
2203
2577
|
}
|
|
2204
2578
|
|
|
2205
2579
|
const escapeHtml = (value) => String(value)
|
|
@@ -2218,6 +2592,7 @@
|
|
|
2218
2592
|
cancel,
|
|
2219
2593
|
duration,
|
|
2220
2594
|
icon,
|
|
2595
|
+
closeButton = true,
|
|
2221
2596
|
html: allowHtml = false,
|
|
2222
2597
|
} = config;
|
|
2223
2598
|
|
|
@@ -2228,25 +2603,26 @@
|
|
|
2228
2603
|
const titleHtml = title ? `<h2>${text(title)}</h2>` : '';
|
|
2229
2604
|
const descriptionHtml = description ? `<p>${text(description)}</p>` : '';
|
|
2230
2605
|
const actionHtml = action?.href
|
|
2231
|
-
? `<a href="${escapeHtml(action.href)}" class="btn" data-toast-action>${text(action.label)}</a>`
|
|
2232
|
-
: action
|
|
2233
|
-
? `<button type="button" class="btn" data-toast-action onclick="${escapeHtml(action.onclick)}">${text(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>`
|
|
2234
2609
|
: '';
|
|
2235
2610
|
const cancelHtml = cancel
|
|
2236
|
-
? `<button type="button" class="btn
|
|
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>`
|
|
2237
2612
|
: '';
|
|
2238
2613
|
|
|
2239
|
-
const
|
|
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>` : '';
|
|
2240
2618
|
|
|
2241
2619
|
const html = `
|
|
2242
|
-
<
|
|
2620
|
+
<li
|
|
2243
2621
|
class="toast"
|
|
2244
|
-
role="${category === 'error' ? 'alert' : 'status'}"
|
|
2245
|
-
aria-atomic="true"
|
|
2246
2622
|
${category ? `data-category="${escapeHtml(category)}"` : ''}
|
|
2247
2623
|
${duration !== undefined ? `data-duration="${escapeHtml(duration)}"` : ''}
|
|
2248
2624
|
>
|
|
2249
|
-
<div class="toast-content">
|
|
2625
|
+
<div class="toast-content" role="${category === 'error' ? 'alert' : 'status'}" aria-atomic="true">
|
|
2250
2626
|
${iconHtml}
|
|
2251
2627
|
<section>
|
|
2252
2628
|
${titleHtml}
|
|
@@ -2254,7 +2630,7 @@
|
|
|
2254
2630
|
</section>
|
|
2255
2631
|
${footerHtml}
|
|
2256
2632
|
</div>
|
|
2257
|
-
</
|
|
2633
|
+
</li>
|
|
2258
2634
|
`;
|
|
2259
2635
|
const template = document.createElement('template');
|
|
2260
2636
|
template.innerHTML = html.trim();
|