basecoat-css 0.3.10 → 1.0.0-beta.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 (99) hide show
  1. package/README.md +8 -1
  2. package/dist/base/base.css +150 -0
  3. package/dist/basecoat-base.cdn.css +2942 -0
  4. package/dist/basecoat-base.cdn.min.css +2 -0
  5. package/dist/basecoat-base.css +2 -0
  6. package/dist/basecoat-components.css +32 -0
  7. package/dist/basecoat-luma.cdn.css +6073 -0
  8. package/dist/basecoat-luma.cdn.min.css +2 -0
  9. package/dist/basecoat-luma.css +2 -0
  10. package/dist/basecoat-lyra.cdn.css +6004 -0
  11. package/dist/basecoat-lyra.cdn.min.css +2 -0
  12. package/dist/basecoat-lyra.css +2 -0
  13. package/dist/basecoat-maia.cdn.css +6012 -0
  14. package/dist/basecoat-maia.cdn.min.css +2 -0
  15. package/dist/basecoat-maia.css +2 -0
  16. package/dist/basecoat-mira.cdn.css +6063 -0
  17. package/dist/basecoat-mira.cdn.min.css +2 -0
  18. package/dist/basecoat-mira.css +2 -0
  19. package/dist/basecoat-nova.cdn.css +6067 -0
  20. package/dist/basecoat-nova.cdn.min.css +2 -0
  21. package/dist/basecoat-nova.css +2 -0
  22. package/dist/basecoat-rhea.cdn.css +6092 -0
  23. package/dist/basecoat-rhea.cdn.min.css +2 -0
  24. package/dist/basecoat-rhea.css +2 -0
  25. package/dist/basecoat-sera.cdn.css +5840 -0
  26. package/dist/basecoat-sera.cdn.min.css +2 -0
  27. package/dist/basecoat-sera.css +2 -0
  28. package/dist/basecoat-vega.cdn.css +6023 -0
  29. package/dist/basecoat-vega.cdn.min.css +2 -0
  30. package/dist/basecoat-vega.css +2 -0
  31. package/dist/basecoat.all.css +1 -0
  32. package/dist/basecoat.cdn.css +5084 -2646
  33. package/dist/basecoat.cdn.min.css +1 -1
  34. package/dist/basecoat.css +1 -1311
  35. package/dist/components/alert.css +21 -0
  36. package/dist/components/badge.css +12 -0
  37. package/dist/components/button-group.css +54 -0
  38. package/dist/components/button.css +61 -0
  39. package/dist/components/card.css +22 -0
  40. package/dist/components/checkbox.css +12 -0
  41. package/dist/components/collapsible.css +21 -0
  42. package/dist/components/combobox.css +78 -0
  43. package/dist/components/command.css +133 -0
  44. package/dist/components/dialog.css +52 -0
  45. package/dist/components/dropdown-menu.css +48 -0
  46. package/dist/components/empty.css +26 -0
  47. package/dist/components/field.css +86 -0
  48. package/dist/components/form.css +9 -0
  49. package/dist/components/input-group.css +50 -0
  50. package/dist/components/input.css +32 -0
  51. package/dist/components/item.css +50 -0
  52. package/dist/components/kbd.css +10 -0
  53. package/dist/components/label.css +12 -0
  54. package/dist/components/native-select.css +12 -0
  55. package/dist/components/popover.css +81 -0
  56. package/dist/components/radio.css +11 -0
  57. package/dist/components/range.css +50 -0
  58. package/dist/components/select.css +64 -0
  59. package/dist/components/sidebar.css +101 -0
  60. package/dist/components/skeleton.css +6 -0
  61. package/dist/components/switch.css +8 -0
  62. package/dist/components/table.css +34 -0
  63. package/dist/components/tabs.css +31 -0
  64. package/dist/components/textarea.css +7 -0
  65. package/dist/components/toast.css +57 -0
  66. package/dist/components/tooltip.css +82 -0
  67. package/dist/js/all.js +1435 -789
  68. package/dist/js/all.min.js +1 -1
  69. package/dist/js/basecoat.js +95 -40
  70. package/dist/js/basecoat.min.js +1 -1
  71. package/dist/js/combobox.js +483 -0
  72. package/dist/js/combobox.min.js +1 -0
  73. package/dist/js/command.js +165 -126
  74. package/dist/js/command.min.js +1 -1
  75. package/dist/js/dropdown-menu.js +158 -133
  76. package/dist/js/dropdown-menu.min.js +1 -1
  77. package/dist/js/popover.js +22 -8
  78. package/dist/js/popover.min.js +1 -1
  79. package/dist/js/range.js +25 -0
  80. package/dist/js/range.min.js +1 -0
  81. package/dist/js/select.js +347 -359
  82. package/dist/js/select.min.js +1 -1
  83. package/dist/js/sidebar.js +27 -66
  84. package/dist/js/sidebar.min.js +1 -1
  85. package/dist/js/tabs.js +82 -38
  86. package/dist/js/tabs.min.js +1 -1
  87. package/dist/js/toast.js +42 -37
  88. package/dist/js/toast.min.js +1 -1
  89. package/dist/styles/luma.css +1308 -0
  90. package/dist/styles/lyra.css +1289 -0
  91. package/dist/styles/maia.css +1296 -0
  92. package/dist/styles/mira.css +1297 -0
  93. package/dist/styles/nova.css +1293 -0
  94. package/dist/styles/rhea.css +1305 -0
  95. package/dist/styles/sera.css +1316 -0
  96. package/dist/styles/vega.css +1293 -0
  97. package/package.json +47 -3
  98. package/dist/js/carousel.js +0 -192
  99. package/dist/js/carousel.min.js +0 -1
@@ -1 +1 @@
1
- (()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=t.querySelector(":scope > span"),n=e.querySelector(":scope > [data-popover]"),i=n?n.querySelector('[role="listbox"]'):null,a=e.querySelector(':scope > input[type="hidden"]'),s=e.querySelector('header input[type="text"]');if(!(t&&n&&i&&a)){const r=[];return t||r.push("trigger"),n||r.push("popover"),i||r.push("listbox"),a||r.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${r.join(", ")}`,e)}const o=Array.from(i.querySelectorAll('[role="option"]')),c=o.filter((e=>"true"!==e.getAttribute("aria-disabled")));let l=[...c],d=-1;const u="true"===i.getAttribute("aria-multiselectable"),f=u?new Set:null,p=u?e.dataset.placeholder||"":null,v="true"===e.dataset.closeOnSelect,h=e=>e.dataset.value??e.textContent.trim(),b=e=>{if(d>-1&&c[d]&&c[d].classList.remove("active"),d=e,d>-1){const e=c[d];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},m=()=>{const e=getComputedStyle(n);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},y=(t,n=!0)=>{let i;if(u){const e=Array.isArray(t)?t:[];f.clear(),e.forEach((e=>f.add(e)));const n=c.filter((e=>f.has(e)));0===n.length?(r.textContent=p,r.classList.add("text-muted-foreground")):(r.textContent=n.map((e=>e.dataset.label||e.textContent.trim())).join(", "),r.classList.remove("text-muted-foreground")),i=n.map(h),a.value=JSON.stringify(i)}else{const e=t;if(!e)return;r.innerHTML=e.innerHTML,i=h(e),a.value=i}c.forEach((e=>{(u?f.has(e):e===t)?e.setAttribute("aria-selected","true"):e.removeAttribute("aria-selected")})),n&&e.dispatchEvent(new CustomEvent("change",{detail:{value:i},bubbles:!0}))},A=(e=!0)=>{if("true"!==n.getAttribute("aria-hidden")){if(s){const e=()=>{s.value="",l=[...c],o.forEach((e=>e.setAttribute("aria-hidden","false")))};m()?n.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),b(-1)}},E=e=>{f.has(e)?f.delete(e):f.add(e),y(c.filter((e=>f.has(e))))},g=e=>{if(u){const t=c.find((t=>h(t)===e&&!f.has(t)));if(!t)return;f.add(t),y(c.filter((e=>f.has(e))))}else{const t=c.find((t=>h(t)===e));if(!t)return;a.value!==e&&y(t),A()}},w=e=>{if(!u)return;const t=c.find((t=>h(t)===e&&f.has(t)));t&&(f.delete(t),y(c.filter((e=>f.has(e)))))},L=e=>{if(!u)return;const t=c.find((t=>h(t)===e));t&&E(t)};if(s){const e=()=>{const e=s.value.trim().toLowerCase();b(-1),l=[],o.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(c.includes(t)&&l.push(t));const r=(t.dataset.filter||t.textContent).trim().toLowerCase(),n=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),i=r.includes(e)||n;t.setAttribute("aria-hidden",String(!i)),i&&c.includes(t)&&l.push(t)}))};s.addEventListener("input",e)}if(u){const e=c.filter((e=>"true"===e.getAttribute("aria-selected")));try{const t=JSON.parse(a.value||"[]"),r=new Set(c.map(h)),n=Array.isArray(t)?t.filter((e=>r.has(e))):[],i=[];n.length>0?n.forEach((e=>{const t=c.find((t=>h(t)===e&&!i.includes(t)));t&&i.push(t)})):i.push(...e),y(i,!1)}catch(t){y(e,!1)}}else{const e=c.find((e=>h(e)===a.value))||c[0];e&&y(e,!1)}const x=e=>{const r="false"===n.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!r)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void A();if("Enter"===e.key){if(d>-1){const e=c[d];u?(E(e),v&&A()):(a.value!==h(e)&&y(e),A())}return}if(0===l.length)return;const i=d>-1?l.indexOf(c[d]):-1;let s=i;switch(e.key){case"ArrowDown":i<l.length-1&&(s=i+1);break;case"ArrowUp":i>0?s=i-1:-1===i&&(s=0);break;case"Home":s=0;break;case"End":s=l.length-1}if(s!==i){const e=l[s];b(c.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&l.includes(t)){const e=c.indexOf(t);e!==d&&b(e)}})),i.addEventListener("mouseleave",(()=>{const e=i.querySelector('[role="option"][aria-selected="true"]');b(e?c.indexOf(e):-1)})),t.addEventListener("keydown",x),s&&s.addEventListener("keydown",x);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?A():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),s&&(m()?n.addEventListener("transitionend",(()=>{s.focus()}),{once:!0}):s.focus()),n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const r=i.querySelector('[role="option"][aria-selected="true"]');r&&(b(c.indexOf(r)),r.scrollIntoView({block:"nearest"}))})()})),i.addEventListener("click",(e=>{const r=e.target.closest('[role="option"]');if(!r)return;const n=c.find((e=>e===r));n&&(u?(E(n),v?A():(b(c.indexOf(n)),s?s.focus():t.focus())):(a.value!==h(n)&&y(n),A()))})),document.addEventListener("click",(t=>{e.contains(t.target)||A(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&A(!1)})),n.setAttribute("aria-hidden","true"),Object.defineProperty(e,"value",{get:()=>u?c.filter((e=>f.has(e))).map(h):a.value,set:e=>{if(u){const t=Array.isArray(e)?e:null!=e?[e]:[],r=[];t.forEach((e=>{const t=c.find((t=>h(t)===e&&!r.includes(t)));t&&r.push(t)})),y(r)}else{const t=c.find((t=>h(t)===e));t&&(y(t),A())}}}),e.select=g,e.selectByValue=g,u&&(e.deselect=w,e.toggle=L,e.selectAll=()=>y(c),e.selectNone=()=>y([])),e.dataset.selectInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("select","div.select:not([data-select-initialized])",e)})();
1
+ (()=>{const e=new WeakMap,t=e=>e.dataset.value??e.textContent.trim(),o=e=>e.dataset.label||e.textContent.trim(),i=e=>({value:t(e),label:o(e)}),s=(e,{isMultiple:t,format:o})=>{if(t)try{const t=JSON.parse(e||"[]");return Array.isArray(t)?t.map((e=>"object"===o&&e&&"object"==typeof e?e.value:e)).filter((e=>null!=e)).map(String):[]}catch(e){return[]}if("object"===o)try{const t=JSON.parse(e||"null");return t&&"object"==typeof t&&null!=t.value?String(t.value):""}catch(e){return""}return e||""},n=(e,t)=>{if("object"===e.format)return JSON.stringify(e.isMultiple?t:t[0]||null);const o=t.map((e=>e.value));return e.isMultiple?JSON.stringify(o):o[0]||""},l=(e,t)=>{const o=t.getBoundingClientRect(),i=e.listbox.getBoundingClientRect();o.top<i.top?e.listbox.scrollTop-=i.top-o.top:o.bottom>i.bottom&&(e.listbox.scrollTop+=o.bottom-i.bottom)},r=(e,t)=>{if(e.activeIndex>-1&&e.options[e.activeIndex]&&e.options[e.activeIndex].classList.remove("active"),e.activeIndex=t,e.activeIndex>-1){const t=e.options[e.activeIndex];t.classList.add("active"),t.id?e.trigger.setAttribute("aria-activedescendant",t.id):e.trigger.removeAttribute("aria-activedescendant")}else e.trigger.removeAttribute("aria-activedescendant")},a=(t,o,s=!0)=>{const l=e.get(t);let r,a;if(l.isMultiple){const e=Array.isArray(o)?o:[];l.selectedOptions.clear(),e.forEach((e=>l.selectedOptions.add(e)));const t=l.options.filter((e=>l.selectedOptions.has(e)));a=t.map(i),0===t.length?(l.selectedLabel.textContent=l.placeholder,l.selectedLabel.classList.add("text-muted-foreground")):(l.selectedLabel.textContent=a.map((e=>e.label)).join(", "),l.selectedLabel.classList.remove("text-muted-foreground")),r=a.map((e=>e.value)),l.input.value=n(l,a)}else{const e=o;if(!e)return;l.selectedLabel.innerHTML=e.innerHTML,a=i(e),r=a.value,l.input.value=n(l,[a])}l.options.forEach((e=>{(l.isMultiple?l.selectedOptions.has(e):e===o)?e.setAttribute("aria-selected","true"):e.removeAttribute("aria-selected")})),s&&t.dispatchEvent(new CustomEvent("change",{detail:{value:r,selected:a},bubbles:!0}))},c=(e,t=!0)=>{"true"!==e.popover.getAttribute("aria-hidden")&&(t&&e.trigger.focus(),e.popover.setAttribute("aria-hidden","true"),e.trigger.setAttribute("aria-expanded","false"),r(e,-1))},d=o=>{const i=e.get(o);if(!i)return;const n=(e=>{const t=e.querySelector(":scope > button"),o=t?.querySelector(":scope > span")||null,i=e.querySelector(":scope > [data-popover]"),s=i?i.querySelector('[role="listbox"]'):null;return{trigger:t,selectedLabel:o,popover:i,listbox:s,input:e.querySelector(':scope > input[type="hidden"]')}})(o);if(!(n.trigger&&n.selectedLabel&&n.popover&&n.listbox&&n.input)){const e=[];return n.trigger||e.push("trigger"),n.selectedLabel||e.push("selected label"),n.popover||e.push("popover"),n.listbox||e.push("listbox"),n.input||e.push("input"),void console.error(`Select component refresh failed. Missing element(s): ${e.join(", ")}`,o)}const l=n.input.value;if(Object.assign(i,n,(e=>{const t=Array.from(e.querySelectorAll('[role="option"]'));return{allOptions:t,options:t.filter((e=>!(e=>"true"===e.getAttribute("aria-disabled"))(e)))}})(n.listbox)),i.visibleOptions=[...i.options],i.isMultiple="true"===i.listbox.getAttribute("aria-multiselectable"),i.format=(e=>"object"===e.dataset.format?"object":"value")(o),i.placeholder=i.isMultiple?o.dataset.placeholder||"":null,i.closeOnSelect="true"===o.dataset.closeOnSelect,i.isMultiple){i.selectedOptions||(i.selectedOptions=new Set);const e=s(l,i),n=e.length?e.map((e=>i.options.find((o=>t(o)===e)))).filter(Boolean):i.options.filter((e=>"true"===e.getAttribute("aria-selected")));a(o,n,!1)}else{const e=s(l,i),n=i.options.find((o=>t(o)===e))||i.options.find((e=>"true"===e.getAttribute("aria-selected")));i.options.forEach((e=>e.removeAttribute("aria-selected"))),n&&a(o,n,!1)}const c=i.listbox.querySelector('[role="option"][aria-selected="true"]');r(i,c?i.options.indexOf(c):-1)},p=(t,o)=>{const i=e.get(t);i.selectedOptions.has(o)?i.selectedOptions.delete(o):i.selectedOptions.add(o),a(t,i.options.filter((e=>i.selectedOptions.has(e))))},u=o=>{if(o.dataset.selectInitialized)return;const n={activeIndex:-1,selectedOptions:null,options:[],allOptions:[],visibleOptions:[],format:"value"};if(e.set(o,n),o.refresh=()=>d(o),d(o),!(n.trigger&&n.selectedLabel&&n.popover&&n.listbox&&n.input))return e.delete(o),void delete o.refresh;o.open=()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:o}})),o.refresh(),n.popover.setAttribute("aria-hidden","false"),n.trigger.setAttribute("aria-expanded","true");const e=n.listbox.querySelector('[role="option"][aria-selected="true"]');e&&(r(n,n.options.indexOf(e)),l(n,e))},o.close=(e=!0)=>c(n,e),o.togglePopover=()=>"true"===n.trigger.getAttribute("aria-expanded")?o.close():o.open();const u=i=>((o,i)=>{const s=e.get(i),n="false"===s.popover.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(o.key))return;if(!n)return void("Enter"!==o.key&&"Escape"!==o.key&&(o.preventDefault(),i.open()));if(o.preventDefault(),"Escape"===o.key)return void i.close();if("Enter"===o.key){if(s.activeIndex>-1){const e=s.options[s.activeIndex];s.isMultiple?(p(i,e),s.closeOnSelect&&i.close()):(i.value!==t(e)&&a(i,e),i.close())}return}if(0===s.visibleOptions.length)return;const c=s.activeIndex>-1?s.visibleOptions.indexOf(s.options[s.activeIndex]):-1;let d=c;if("ArrowDown"===o.key&&c<s.visibleOptions.length-1&&(d=c+1),"ArrowUp"===o.key&&(d=c>0?c-1:0),"Home"===o.key&&(d=0),"End"===o.key&&(d=s.visibleOptions.length-1),d!==c){const e=s.visibleOptions[d];r(s,s.options.indexOf(e)),l(s,e)}})(i,o),v=o.togglePopover,f=e=>{const t=e.target.closest('[role="option"]');if(t&&n.visibleOptions.includes(t)){const e=n.options.indexOf(t);e!==n.activeIndex&&r(n,e)}},b=()=>{const e=n.listbox.querySelector('[role="option"][aria-selected="true"]');r(n,e?n.options.indexOf(e):-1)},g=e=>{const i=e.target.closest('[role="option"]');if(!i)return;const s=n.options.find((e=>e===i));s&&(n.isMultiple?(p(o,s),n.closeOnSelect?o.close():(r(n,n.options.indexOf(s)),n.trigger.focus())):(o.value!==t(s)&&a(o,s),o.close()))},m=e=>{o.contains(e.target)||o.close(!1)},x=e=>{e.detail.source!==o&&o.close(!1)};n.trigger.addEventListener("keydown",u),n.trigger.addEventListener("click",v),n.listbox.addEventListener("mousemove",f),n.listbox.addEventListener("mouseleave",b),n.listbox.addEventListener("click",g),document.addEventListener("click",m),document.addEventListener("basecoat:popover",x),o._destroy=()=>{n.trigger.removeEventListener("keydown",u),n.trigger.removeEventListener("click",v),n.listbox.removeEventListener("mousemove",f),n.listbox.removeEventListener("mouseleave",b),n.listbox.removeEventListener("click",g),document.removeEventListener("click",m),document.removeEventListener("basecoat:popover",x),e.delete(o),delete o.refresh,delete o.open,delete o.close,delete o.togglePopover,delete o.select,delete o.selectByValue,delete o.deselect,delete o.toggle,delete o.selectAll,delete o.selectNone},Object.defineProperty(o,"value",{configurable:!0,get:()=>n.isMultiple?n.options.filter((e=>n.selectedOptions.has(e))).map(t):s(n.input.value,n),set:e=>{if(n.isMultiple){const i=Array.isArray(e)?e:null!=e?[e]:[];a(o,i.map((e=>n.options.find((o=>t(o)===e)))).filter(Boolean))}else{const i=n.options.find((o=>t(o)===e));i&&(a(o,i),o.close())}}}),Object.defineProperty(o,"selected",{configurable:!0,get:()=>{if(n.isMultiple)return n.options.filter((e=>n.selectedOptions.has(e))).map(i);const e=o.value,s=n.options.find((o=>t(o)===e));return s?i(s):null}}),o.select=i=>((o,i)=>{const s=e.get(o);if(s.isMultiple){const e=s.options.find((e=>t(e)===i&&!s.selectedOptions.has(e)));if(!e)return;s.selectedOptions.add(e),a(o,s.options.filter((e=>s.selectedOptions.has(e))))}else{const e=s.options.find((e=>t(e)===i));if(!e)return;o.value!==i&&a(o,e),c(s)}})(o,i),o.selectByValue=o.select,n.isMultiple&&(o.deselect=i=>((o,i)=>{const s=e.get(o);if(!s.isMultiple)return;const n=s.options.find((e=>t(e)===i&&s.selectedOptions.has(e)));n&&(s.selectedOptions.delete(n),a(o,s.options.filter((e=>s.selectedOptions.has(e)))))})(o,i),o.toggle=e=>{const i=n.options.find((o=>t(o)===e));i&&p(o,i)},o.selectAll=()=>a(o,n.options),o.selectNone=()=>a(o,[])),n.popover.setAttribute("aria-hidden","true"),n.trigger.setAttribute("aria-expanded","false"),o.dataset.selectInitialized="true",o.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("select",{selector:"div.select:not([data-select-initialized])",init:u,refresh:d})})();
@@ -1,46 +1,17 @@
1
1
  (() => {
2
- // Monkey patching the history API to detect client-side navigation
3
- if (!window.history.__basecoatPatched) {
4
- const originalPushState = window.history.pushState;
5
- window.history.pushState = function(...args) {
6
- originalPushState.apply(this, args);
7
- window.dispatchEvent(new Event('basecoat:locationchange'));
8
- };
9
-
10
- const originalReplaceState = window.history.replaceState;
11
- window.history.replaceState = function(...args) {
12
- originalReplaceState.apply(this, args);
13
- window.dispatchEvent(new Event('basecoat:locationchange'));
14
- };
15
-
16
- window.history.__basecoatPatched = true;
17
- }
18
-
19
2
  const initSidebar = (sidebarComponent) => {
3
+ if (sidebarComponent.dataset.sidebarInitialized) return;
4
+
20
5
  const initialOpen = sidebarComponent.dataset.initialOpen !== 'false';
21
6
  const initialMobileOpen = sidebarComponent.dataset.initialMobileOpen === 'true';
22
7
  const breakpoint = parseInt(sidebarComponent.dataset.breakpoint) || 768;
23
-
24
- let open = breakpoint > 0
8
+
9
+ let open = breakpoint > 0
25
10
  ? (window.innerWidth >= breakpoint ? initialOpen : initialMobileOpen)
26
11
  : initialOpen;
27
-
28
- const updateCurrentPageLinks = () => {
29
- const currentPath = window.location.pathname.replace(/\/$/, '');
30
- sidebarComponent.querySelectorAll('a').forEach(link => {
31
- if (link.hasAttribute('data-ignore-current')) return;
32
-
33
- const linkPath = new URL(link.href).pathname.replace(/\/$/, '');
34
- if (linkPath === currentPath) {
35
- link.setAttribute('aria-current', 'page');
36
- } else {
37
- link.removeAttribute('aria-current');
38
- }
39
- });
40
- };
41
-
12
+
42
13
  const updateState = () => {
43
- sidebarComponent.setAttribute('aria-hidden', !open);
14
+ sidebarComponent.setAttribute('aria-hidden', String(!open));
44
15
  if (open) {
45
16
  sidebarComponent.removeAttribute('inert');
46
17
  } else {
@@ -49,56 +20,46 @@
49
20
  };
50
21
 
51
22
  const setState = (state) => {
52
- open = state;
23
+ open = Boolean(state);
53
24
  updateState();
54
25
  };
55
26
 
56
- const sidebarId = sidebarComponent.id;
57
-
58
- document.addEventListener('basecoat:sidebar', (event) => {
59
- if (event.detail?.id && event.detail.id !== sidebarId) return;
27
+ sidebarComponent.open = () => setState(true);
28
+ sidebarComponent.close = () => setState(false);
29
+ sidebarComponent.toggle = () => setState(!open);
60
30
 
61
- switch (event.detail?.action) {
62
- case 'open':
63
- setState(true);
64
- break;
65
- case 'close':
66
- setState(false);
67
- break;
68
- default:
69
- setState(!open);
70
- break;
71
- }
72
- });
73
-
74
- sidebarComponent.addEventListener('click', (event) => {
31
+ const handleClick = (event) => {
75
32
  const target = event.target;
76
33
  const nav = sidebarComponent.querySelector('nav');
77
-
78
34
  const isMobile = window.innerWidth < breakpoint;
79
-
80
- if (isMobile && (target.closest('a, button') && !target.closest('[data-keep-mobile-sidebar-open]'))) {
35
+
36
+ if (isMobile && target.closest('a, button') && !target.closest('[data-keep-mobile-sidebar-open]')) {
81
37
  if (document.activeElement) document.activeElement.blur();
82
- setState(false);
38
+ sidebarComponent.close();
83
39
  return;
84
40
  }
85
-
41
+
86
42
  if (target === sidebarComponent || (nav && !nav.contains(target))) {
87
43
  if (document.activeElement) document.activeElement.blur();
88
- setState(false);
44
+ sidebarComponent.close();
89
45
  }
90
- });
46
+ };
91
47
 
92
- window.addEventListener('popstate', updateCurrentPageLinks);
93
- window.addEventListener('basecoat:locationchange', updateCurrentPageLinks);
48
+ sidebarComponent.addEventListener('click', handleClick);
49
+
50
+ sidebarComponent._destroy = () => {
51
+ sidebarComponent.removeEventListener('click', handleClick);
52
+ delete sidebarComponent.open;
53
+ delete sidebarComponent.close;
54
+ delete sidebarComponent.toggle;
55
+ };
94
56
 
95
57
  updateState();
96
- updateCurrentPageLinks();
97
- sidebarComponent.dataset.sidebarInitialized = true;
58
+ sidebarComponent.dataset.sidebarInitialized = 'true';
98
59
  sidebarComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
99
60
  };
100
61
 
101
62
  if (window.basecoat) {
102
63
  window.basecoat.register('sidebar', '.sidebar:not([data-sidebar-initialized])', initSidebar);
103
64
  }
104
- })();
65
+ })();
@@ -1 +1 @@
1
- (()=>{if(!window.history.__basecoatPatched){const t=window.history.pushState;window.history.pushState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))};const e=window.history.replaceState;window.history.replaceState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const t=t=>{const e="false"!==t.dataset.initialOpen,a="true"===t.dataset.initialMobileOpen,i=parseInt(t.dataset.breakpoint)||768;let n=i>0?window.innerWidth>=i?e:a:e;const o=()=>{const e=window.location.pathname.replace(/\/$/,"");t.querySelectorAll("a").forEach((t=>{if(t.hasAttribute("data-ignore-current"))return;new URL(t.href).pathname.replace(/\/$/,"")===e?t.setAttribute("aria-current","page"):t.removeAttribute("aria-current")}))},r=()=>{t.setAttribute("aria-hidden",!n),n?t.removeAttribute("inert"):t.setAttribute("inert","")},d=t=>{n=t,r()},s=t.id;document.addEventListener("basecoat:sidebar",(t=>{if(!t.detail?.id||t.detail.id===s)switch(t.detail?.action){case"open":d(!0);break;case"close":d(!1);break;default:d(!n)}})),t.addEventListener("click",(e=>{const a=e.target,n=t.querySelector("nav");if(window.innerWidth<i&&a.closest("a, button")&&!a.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void d(!1);(a===t||n&&!n.contains(a))&&(document.activeElement&&document.activeElement.blur(),d(!1))})),window.addEventListener("popstate",o),window.addEventListener("basecoat:locationchange",o),r(),o(),t.dataset.sidebarInitialized=!0,t.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("sidebar",".sidebar:not([data-sidebar-initialized])",t)})();
1
+ (()=>{const e=e=>{if(e.dataset.sidebarInitialized)return;const t="false"!==e.dataset.initialOpen,i="true"===e.dataset.initialMobileOpen,n=parseInt(e.dataset.breakpoint)||768;let a=n>0?window.innerWidth>=n?t:i:t;const o=()=>{e.setAttribute("aria-hidden",String(!a)),a?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{a=Boolean(e),o()};e.open=()=>s(!0),e.close=()=>s(!1),e.toggle=()=>s(!a);const d=t=>{const i=t.target,a=e.querySelector("nav");if(window.innerWidth<n&&i.closest("a, button")&&!i.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void e.close();(i===e||a&&!a.contains(i))&&(document.activeElement&&document.activeElement.blur(),e.close())};e.addEventListener("click",d),e._destroy=()=>{e.removeEventListener("click",d),delete e.open,delete e.close,delete e.toggle},o(),e.dataset.sidebarInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("sidebar",".sidebar:not([data-sidebar-initialized])",e)})();
package/dist/js/tabs.js CHANGED
@@ -1,63 +1,107 @@
1
1
  (() => {
2
- const initTabs = (tabsComponent) => {
3
- const tablist = tabsComponent.querySelector('[role="tablist"]');
4
- if (!tablist) return;
2
+ const states = new WeakMap();
5
3
 
6
- const tabs = Array.from(tablist.querySelectorAll('[role="tab"]'));
4
+ const isDisabled = (tab) => tab.disabled || tab.getAttribute('aria-disabled') === 'true';
5
+
6
+ const getElements = (root) => {
7
+ const tablist = root.querySelector('[role="tablist"]');
8
+ const tabs = tablist ? Array.from(tablist.querySelectorAll('[role="tab"]')) : [];
7
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
+ const initTabs = (root) => {
26
+ if (root.dataset.tabsInitialized) return;
27
+
28
+ const state = {};
29
+ states.set(root, state);
30
+ root.refresh = () => refreshTabs(root);
8
31
 
9
- const selectTab = (tabToSelect) => {
10
- tabs.forEach((tab, index) => {
32
+ const selectTab = (tabToSelect, focus = false) => {
33
+ if (!tabToSelect || isDisabled(tabToSelect)) return;
34
+
35
+ state.tabs.forEach((tab) => {
11
36
  tab.setAttribute('aria-selected', 'false');
12
37
  tab.setAttribute('tabindex', '-1');
13
- if (panels[index]) panels[index].hidden = true;
38
+ const panel = document.getElementById(tab.getAttribute('aria-controls'));
39
+ if (panel) panel.hidden = true;
14
40
  });
15
41
 
16
42
  tabToSelect.setAttribute('aria-selected', 'true');
17
43
  tabToSelect.setAttribute('tabindex', '0');
18
44
  const activePanel = document.getElementById(tabToSelect.getAttribute('aria-controls'));
19
45
  if (activePanel) activePanel.hidden = false;
46
+ if (focus) tabToSelect.focus();
20
47
  };
21
48
 
22
- tablist.addEventListener('click', (event) => {
49
+ root.select = selectTab;
50
+ refreshTabs(root);
51
+ if (!state.tablist) {
52
+ states.delete(root);
53
+ delete root.refresh;
54
+ delete root.select;
55
+ return;
56
+ }
57
+
58
+ const handleClick = (event) => {
23
59
  const clickedTab = event.target.closest('[role="tab"]');
24
- if (clickedTab) selectTab(clickedTab);
25
- });
60
+ if (clickedTab) root.select(clickedTab);
61
+ };
26
62
 
27
- tablist.addEventListener('keydown', (event) => {
63
+ const handleKeydown = (event) => {
28
64
  const currentTab = event.target;
29
- if (!tabs.includes(currentTab)) return;
65
+ if (!state.tabs.includes(currentTab)) return;
66
+
67
+ const enabledTabs = state.tabs.filter(tab => !isDisabled(tab));
68
+ const currentIndex = enabledTabs.indexOf(currentTab);
69
+ const orientation = state.tablist.getAttribute('aria-orientation') || 'horizontal';
70
+ if (currentIndex === -1) return;
30
71
 
31
72
  let nextTab;
32
- const currentIndex = tabs.indexOf(currentTab);
33
-
34
- switch (event.key) {
35
- case 'ArrowRight':
36
- nextTab = tabs[(currentIndex + 1) % tabs.length];
37
- break;
38
- case 'ArrowLeft':
39
- nextTab = tabs[(currentIndex - 1 + tabs.length) % tabs.length];
40
- break;
41
- case 'Home':
42
- nextTab = tabs[0];
43
- break;
44
- case 'End':
45
- nextTab = tabs[tabs.length - 1];
46
- break;
47
- default:
48
- return;
49
- }
73
+ if (event.key === 'ArrowRight' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
74
+ if (event.key === 'ArrowLeft' && orientation === 'horizontal') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
75
+ if (event.key === 'ArrowDown' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex + 1) % enabledTabs.length];
76
+ if (event.key === 'ArrowUp' && orientation === 'vertical') nextTab = enabledTabs[(currentIndex - 1 + enabledTabs.length) % enabledTabs.length];
77
+ if (event.key === 'Home') nextTab = enabledTabs[0];
78
+ if (event.key === 'End') nextTab = enabledTabs[enabledTabs.length - 1];
79
+ if (!nextTab) return;
50
80
 
51
81
  event.preventDefault();
52
- selectTab(nextTab);
53
- nextTab.focus();
54
- });
55
-
56
- tabsComponent.dataset.tabsInitialized = true;
57
- tabsComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
82
+ root.select(nextTab, true);
83
+ };
84
+
85
+ state.tablist.addEventListener('click', handleClick);
86
+ state.tablist.addEventListener('keydown', handleKeydown);
87
+
88
+ root._destroy = () => {
89
+ state.tablist.removeEventListener('click', handleClick);
90
+ state.tablist.removeEventListener('keydown', handleKeydown);
91
+ states.delete(root);
92
+ delete root.refresh;
93
+ delete root.select;
94
+ };
95
+
96
+ root.dataset.tabsInitialized = 'true';
97
+ root.dispatchEvent(new CustomEvent('basecoat:initialized'));
58
98
  };
59
99
 
60
100
  if (window.basecoat) {
61
- window.basecoat.register('tabs', '.tabs:not([data-tabs-initialized])', initTabs);
101
+ window.basecoat.register('tabs', {
102
+ selector: '.tabs:not([data-tabs-initialized])',
103
+ init: initTabs,
104
+ refresh: refreshTabs,
105
+ });
62
106
  }
63
- })();
107
+ })();
@@ -1 +1 @@
1
- (()=>{const t=t=>{const e=t.querySelector('[role="tablist"]');if(!e)return;const a=Array.from(e.querySelectorAll('[role="tab"]')),r=a.map((t=>document.getElementById(t.getAttribute("aria-controls")))).filter(Boolean),n=t=>{a.forEach(((t,e)=>{t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1"),r[e]&&(r[e].hidden=!0)})),t.setAttribute("aria-selected","true"),t.setAttribute("tabindex","0");const e=document.getElementById(t.getAttribute("aria-controls"));e&&(e.hidden=!1)};e.addEventListener("click",(t=>{const e=t.target.closest('[role="tab"]');e&&n(e)})),e.addEventListener("keydown",(t=>{const e=t.target;if(!a.includes(e))return;let r;const i=a.indexOf(e);switch(t.key){case"ArrowRight":r=a[(i+1)%a.length];break;case"ArrowLeft":r=a[(i-1+a.length)%a.length];break;case"Home":r=a[0];break;case"End":r=a[a.length-1];break;default:return}t.preventDefault(),n(r),r.focus()})),t.dataset.tabsInitialized=!0,t.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("tabs",".tabs:not([data-tabs-initialized])",t)})();
1
+ (()=>{const t=new WeakMap,e=t=>t.disabled||"true"===t.getAttribute("aria-disabled"),r=r=>{const i=t.get(r);if(!i)return;if(Object.assign(i,(t=>{const e=t.querySelector('[role="tablist"]'),r=e?Array.from(e.querySelectorAll('[role="tab"]')):[],i=r.map((t=>document.getElementById(t.getAttribute("aria-controls")))).filter(Boolean);return{tablist:e,tabs:r,panels:i}})(r)),!i.tablist)return;const a=i.tabs.find((t=>"true"===t.getAttribute("aria-selected")&&!e(t)))||i.tabs.find((t=>!e(t)));a&&r.select(a,!1)},i=i=>{if(i.dataset.tabsInitialized)return;const a={};t.set(i,a),i.refresh=()=>r(i);if(i.select=(t,r=!1)=>{if(!t||e(t))return;a.tabs.forEach((t=>{t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1");const e=document.getElementById(t.getAttribute("aria-controls"));e&&(e.hidden=!0)})),t.setAttribute("aria-selected","true"),t.setAttribute("tabindex","0");const i=document.getElementById(t.getAttribute("aria-controls"));i&&(i.hidden=!1),r&&t.focus()},r(i),!a.tablist)return t.delete(i),delete i.refresh,void delete i.select;const n=t=>{const e=t.target.closest('[role="tab"]');e&&i.select(e)},s=t=>{const r=t.target;if(!a.tabs.includes(r))return;const n=a.tabs.filter((t=>!e(t))),s=n.indexOf(r),l=a.tablist.getAttribute("aria-orientation")||"horizontal";if(-1===s)return;let o;"ArrowRight"===t.key&&"horizontal"===l&&(o=n[(s+1)%n.length]),"ArrowLeft"===t.key&&"horizontal"===l&&(o=n[(s-1+n.length)%n.length]),"ArrowDown"===t.key&&"vertical"===l&&(o=n[(s+1)%n.length]),"ArrowUp"===t.key&&"vertical"===l&&(o=n[(s-1+n.length)%n.length]),"Home"===t.key&&(o=n[0]),"End"===t.key&&(o=n[n.length-1]),o&&(t.preventDefault(),i.select(o,!0))};a.tablist.addEventListener("click",n),a.tablist.addEventListener("keydown",s),i._destroy=()=>{a.tablist.removeEventListener("click",n),a.tablist.removeEventListener("keydown",s),t.delete(i),delete i.refresh,delete i.select},i.dataset.tabsInitialized="true",i.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("tabs",{selector:".tabs:not([data-tabs-initialized])",init:i,refresh:r})})();
package/dist/js/toast.js CHANGED
@@ -13,17 +13,38 @@
13
13
  if (toasterElement.dataset.toasterInitialized) return;
14
14
  toaster = toasterElement;
15
15
 
16
- toaster.addEventListener('mouseenter', pauseAllTimeouts);
17
- toaster.addEventListener('mouseleave', resumeAllTimeouts);
18
- toaster.addEventListener('click', (event) => {
16
+ const handleClick = (event) => {
19
17
  const actionLink = event.target.closest('.toast footer a');
20
18
  const actionButton = event.target.closest('.toast footer button');
21
19
  if (actionLink || actionButton) {
22
20
  closeToast(event.target.closest('.toast'));
23
21
  }
24
- });
22
+ };
23
+
24
+ toaster.addEventListener('mouseenter', pauseAllTimeouts);
25
+ toaster.addEventListener('mouseleave', resumeAllTimeouts);
26
+ toaster.addEventListener('click', handleClick);
27
+
28
+ toasterElement.toast = (config = {}) => {
29
+ const toastElement = createToast(config);
30
+ toasterElement.appendChild(toastElement);
31
+ initToast(toastElement);
32
+ return toastElement;
33
+ };
34
+ toasterElement.closeAll = () => {
35
+ toasterElement.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(closeToast);
36
+ };
25
37
 
26
38
  toaster.querySelectorAll('.toast:not([data-toast-initialized])').forEach(initToast);
39
+ toaster._destroy = () => {
40
+ toaster.removeEventListener('mouseenter', pauseAllTimeouts);
41
+ toaster.removeEventListener('mouseleave', resumeAllTimeouts);
42
+ toaster.removeEventListener('click', handleClick);
43
+ toaster.querySelectorAll('.toast[data-toast-initialized]').forEach(toast => toast._destroy?.());
44
+ delete toaster.toast;
45
+ delete toaster.closeAll;
46
+ if (toaster === toasterElement) toaster = null;
47
+ };
27
48
  toaster.dataset.toasterInitialized = 'true';
28
49
  toaster.dispatchEvent(new CustomEvent('basecoat:initialized'));
29
50
  }
@@ -35,13 +56,13 @@
35
56
  const timeoutDuration = duration !== -1
36
57
  ? duration || (element.dataset.category === 'error' ? 5000 : 3000)
37
58
  : -1;
38
-
59
+
39
60
  const state = {
40
61
  remainingTime: timeoutDuration,
41
62
  timeoutId: null,
42
63
  startTime: null,
43
64
  };
44
-
65
+
45
66
  if (timeoutDuration !== -1) {
46
67
  if (isPaused) {
47
68
  state.timeoutId = null;
@@ -51,18 +72,24 @@
51
72
  }
52
73
  }
53
74
  toasts.set(element, state);
54
-
75
+
76
+ element.close = () => closeToast(element);
77
+ element._destroy = () => {
78
+ clearTimeout(state.timeoutId);
79
+ toasts.delete(element);
80
+ delete element.close;
81
+ };
55
82
  element.dataset.toastInitialized = 'true';
56
83
  }
57
84
 
58
85
  function pauseAllTimeouts() {
59
- if (isPaused) return;
86
+ if (isPaused || !toaster) return;
60
87
 
61
88
  isPaused = true;
62
-
89
+
63
90
  toaster.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(element => {
64
91
  if (!toasts.has(element)) return;
65
-
92
+
66
93
  const state = toasts.get(element);
67
94
  if (state.timeoutId) {
68
95
  clearTimeout(state.timeoutId);
@@ -73,7 +100,7 @@
73
100
  }
74
101
 
75
102
  function resumeAllTimeouts() {
76
- if (!isPaused) return;
103
+ if (!isPaused || !toaster) return;
77
104
 
78
105
  isPaused = false;
79
106
 
@@ -93,28 +120,17 @@
93
120
  }
94
121
 
95
122
  function closeToast(element) {
96
- if (!toasts.has(element)) return;
123
+ if (!element || !toasts.has(element)) return;
97
124
 
98
125
  const state = toasts.get(element);
99
126
  clearTimeout(state.timeoutId);
100
127
  toasts.delete(element);
101
-
128
+
102
129
  if (element.contains(document.activeElement)) document.activeElement.blur();
103
130
  element.setAttribute('aria-hidden', 'true');
104
131
  element.addEventListener('transitionend', () => element.remove(), { once: true });
105
132
  }
106
133
 
107
- function executeAction(button, toast) {
108
- const actionString = button.dataset.toastAction;
109
- if (!actionString) return;
110
- try {
111
- const func = new Function('close', actionString);
112
- func(() => closeToast(toast));
113
- } catch (event) {
114
- console.error('Error executing toast action:', event);
115
- }
116
- }
117
-
118
134
  function createToast(config) {
119
135
  const {
120
136
  category = 'info',
@@ -135,7 +151,7 @@
135
151
  ? `<button type="button" class="btn" data-toast-action onclick="${action.onclick}">${action.label}</button>`
136
152
  : '';
137
153
  const cancelHtml = cancel
138
- ? `<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${cancel?.onclick}">${cancel.label}</button>`
154
+ ? `<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${cancel?.onclick || ''}">${cancel.label}</button>`
139
155
  : '';
140
156
 
141
157
  const footerHtml = actionHtml || cancelHtml ? `<footer>${actionHtml}${cancelHtml}</footer>` : '';
@@ -155,7 +171,6 @@
155
171
  ${descriptionHtml}
156
172
  </section>
157
173
  ${footerHtml}
158
- </div>
159
174
  </div>
160
175
  </div>
161
176
  `;
@@ -164,18 +179,8 @@
164
179
  return template.content.firstChild;
165
180
  }
166
181
 
167
- document.addEventListener('basecoat:toast', (event) => {
168
- if (!toaster) {
169
- console.error('Cannot create toast: toaster container not found on page.');
170
- return;
171
- }
172
- const config = event.detail?.config || {};
173
- const toastElement = createToast(config);
174
- toaster.appendChild(toastElement);
175
- });
176
-
177
182
  if (window.basecoat) {
178
183
  window.basecoat.register('toaster', '#toaster:not([data-toaster-initialized])', initToaster);
179
184
  window.basecoat.register('toast', '.toast:not([data-toast-initialized])', initToast);
180
185
  }
181
- })();
186
+ })();
@@ -1 +1 @@
1
- (()=>{let t;const e=new WeakMap;let n=!1;const o={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"><circle cx="12" cy="12" r="10"/><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>',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 i(t){if(t.dataset.toastInitialized)return;const o=parseInt(t.dataset.duration),i=-1!==o?o||("error"===t.dataset.category?5e3:3e3):-1,a={remainingTime:i,timeoutId:null,startTime:null};-1!==i&&(n?a.timeoutId=null:(a.startTime=Date.now(),a.timeoutId=setTimeout((()=>s(t)),i))),e.set(t,a),t.dataset.toastInitialized="true"}function a(){n||(n=!0,t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((t=>{if(!e.has(t))return;const n=e.get(t);n.timeoutId&&(clearTimeout(n.timeoutId),n.timeoutId=null,n.remainingTime-=Date.now()-n.startTime)})))}function r(){n&&(n=!1,t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((t=>{if(!e.has(t))return;const n=e.get(t);-1===n.remainingTime||n.timeoutId||(n.remainingTime>0?(n.startTime=Date.now(),n.timeoutId=setTimeout((()=>s(t)),n.remainingTime)):s(t))})))}function s(t){if(!e.has(t))return;const n=e.get(t);clearTimeout(n.timeoutId),e.delete(t),t.contains(document.activeElement)&&document.activeElement.blur(),t.setAttribute("aria-hidden","true"),t.addEventListener("transitionend",(()=>t.remove()),{once:!0})}document.addEventListener("basecoat:toast",(e=>{if(!t)return void console.error("Cannot create toast: toaster container not found on page.");const n=function(t){const{category:e="info",title:n,description:i,action:a,cancel:r,duration:s,icon:d}=t,c=d||e&&o[e]||"",l=n?`<h2>${n}</h2>`:"",u=i?`<p>${i}</p>`:"",h=a?.href?`<a href="${a.href}" class="btn" data-toast-action>${a.label}</a>`:a?.onclick?`<button type="button" class="btn" data-toast-action onclick="${a.onclick}">${a.label}</button>`:"",m=r?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${r?.onclick}">${r.label}</button>`:"",w=`\n <div\n class="toast"\n role="${"error"===e?"alert":"status"}"\n aria-atomic="true"\n ${e?`data-category="${e}"`:""}\n ${void 0!==s?`data-duration="${s}"`:""}\n >\n <div class="toast-content">\n ${c}\n <section>\n ${l}\n ${u}\n </section>\n ${h||m?`<footer>${h}${m}</footer>`:""}\n </div>\n </div>\n </div>\n `,g=document.createElement("template");return g.innerHTML=w.trim(),g.content.firstChild}(e.detail?.config||{});t.appendChild(n)})),window.basecoat&&(window.basecoat.register("toaster","#toaster:not([data-toaster-initialized])",(function(e){e.dataset.toasterInitialized||(t=e,t.addEventListener("mouseenter",a),t.addEventListener("mouseleave",r),t.addEventListener("click",(t=>{const e=t.target.closest(".toast footer a"),n=t.target.closest(".toast footer button");(e||n)&&s(t.target.closest(".toast"))})),t.querySelectorAll(".toast:not([data-toast-initialized])").forEach(i),t.dataset.toasterInitialized="true",t.dispatchEvent(new CustomEvent("basecoat:initialized")))})),window.basecoat.register("toast",".toast:not([data-toast-initialized])",i))})();
1
+ (()=>{let t;const e=new WeakMap;let o=!1;const n={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"><circle cx="12" cy="12" r="10"/><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>',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 i(t){if(t.dataset.toastInitialized)return;const n=parseInt(t.dataset.duration),i=-1!==n?n||("error"===t.dataset.category?5e3:3e3):-1,a={remainingTime:i,timeoutId:null,startTime:null};-1!==i&&(o?a.timeoutId=null:(a.startTime=Date.now(),a.timeoutId=setTimeout((()=>s(t)),i))),e.set(t,a),t.close=()=>s(t),t._destroy=()=>{clearTimeout(a.timeoutId),e.delete(t),delete t.close},t.dataset.toastInitialized="true"}function a(){!o&&t&&(o=!0,t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((t=>{if(!e.has(t))return;const o=e.get(t);o.timeoutId&&(clearTimeout(o.timeoutId),o.timeoutId=null,o.remainingTime-=Date.now()-o.startTime)})))}function r(){o&&t&&(o=!1,t.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((t=>{if(!e.has(t))return;const o=e.get(t);-1===o.remainingTime||o.timeoutId||(o.remainingTime>0?(o.startTime=Date.now(),o.timeoutId=setTimeout((()=>s(t)),o.remainingTime)):s(t))})))}function s(t){if(!t||!e.has(t))return;const o=e.get(t);clearTimeout(o.timeoutId),e.delete(t),t.contains(document.activeElement)&&document.activeElement.blur(),t.setAttribute("aria-hidden","true"),t.addEventListener("transitionend",(()=>t.remove()),{once:!0})}window.basecoat&&(window.basecoat.register("toaster","#toaster:not([data-toaster-initialized])",(function(e){if(e.dataset.toasterInitialized)return;t=e;const o=t=>{const e=t.target.closest(".toast footer a"),o=t.target.closest(".toast footer button");(e||o)&&s(t.target.closest(".toast"))};t.addEventListener("mouseenter",a),t.addEventListener("mouseleave",r),t.addEventListener("click",o),e.toast=(t={})=>{const o=function(t){const{category:e="info",title:o,description:i,action:a,cancel:r,duration:s,icon:l}=t,d=l||e&&n[e]||"",c=o?`<h2>${o}</h2>`:"",u=i?`<p>${i}</p>`:"",h=a?.href?`<a href="${a.href}" class="btn" data-toast-action>${a.label}</a>`:a?.onclick?`<button type="button" class="btn" data-toast-action onclick="${a.onclick}">${a.label}</button>`:"",m=r?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${r?.onclick||""}">${r.label}</button>`:"",v=`\n <div\n class="toast"\n role="${"error"===e?"alert":"status"}"\n aria-atomic="true"\n ${e?`data-category="${e}"`:""}\n ${void 0!==s?`data-duration="${s}"`:""}\n >\n <div class="toast-content">\n ${d}\n <section>\n ${c}\n ${u}\n </section>\n ${h||m?`<footer>${h}${m}</footer>`:""}\n </div>\n </div>\n `,w=document.createElement("template");return w.innerHTML=v.trim(),w.content.firstChild}(t);return e.appendChild(o),i(o),o},e.closeAll=()=>{e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach(s)},t.querySelectorAll(".toast:not([data-toast-initialized])").forEach(i),t._destroy=()=>{t.removeEventListener("mouseenter",a),t.removeEventListener("mouseleave",r),t.removeEventListener("click",o),t.querySelectorAll(".toast[data-toast-initialized]").forEach((t=>t._destroy?.())),delete t.toast,delete t.closeAll,t===e&&(t=null)},t.dataset.toasterInitialized="true",t.dispatchEvent(new CustomEvent("basecoat:initialized"))})),window.basecoat.register("toast",".toast:not([data-toast-initialized])",i))})();