basecoat-css 0.1.2 → 0.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.
@@ -0,0 +1 @@
1
+ (()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]"),n=a.querySelector('[role="menu"]');if(!t||!n||!a)return void console.error("Dropdown menu component is missing a trigger, a menu, or a popover content element.",e);let r=[],i=-1;const o=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),a.setAttribute("aria-hidden","true"),t.focus(),i=-1)},d=()=>{t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false"),r=Array.from(n.querySelectorAll('[role^="menuitem"]:not([disabled])')),r.length>0&&s(0)},s=e=>{if(i>-1&&r[i]&&r[i].classList.remove("active"),i=e,i>-1&&r[i]){const e=r[i];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?o():d()})),e.addEventListener("keydown",(e=>{const a="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(a&&o());if(!a)return void(["ArrowDown","ArrowUp","Enter"," "].includes(e.key)&&(e.preventDefault(),d()));if(0===r.length)return;let n=i;switch(e.key){case"ArrowDown":e.preventDefault(),n=i<r.length-1?i+1:0;break;case"ArrowUp":e.preventDefault(),n=i>0?i-1:r.length-1;break;case"Home":e.preventDefault(),n=0;break;case"End":e.preventDefault(),n=r.length-1;break;case"Enter":case" ":return e.preventDefault(),r[i]?.click(),void o()}n!==i&&s(n)})),n.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&o()})),document.addEventListener("click",(t=>{e.contains(t.target)||o()})),e.dataset.dropdownMenuInitialized=!0};document.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".dropdown-menu:not([data-dropdown-menu-initialized])")&&e(t),t.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]");if(!t||!a)return void console.error("Popover component is missing a trigger button or a content element.",e);const n=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),a.setAttribute("aria-hidden","true"),t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?n():(()=>{const e=a.querySelector("[autofocus]");e&&a.addEventListener("transitionend",(()=>{e.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&n()})),document.addEventListener("click",(t=>{e.contains(t.target)||n()})),e.dataset.popoverInitialized=!0};document.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".popover:not([data-popover-initialized])")&&e(t),t.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=t.querySelector(":scope > span"),n=e.querySelector(":scope > [data-popover]"),r=n.querySelector('[role="listbox"]'),i=e.querySelector(':scope > input[type="hidden"]'),o=e.querySelector('header input[type="text"]');if(!(t&&n&&r&&i))return;const d=Array.from(r.querySelectorAll('[role="option"]'));let s=[...d],c=-1;const l=e=>{e&&(a.innerHTML=e.dataset.label||e.innerHTML,i.value=e.dataset.value,r.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},u=()=>{n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),o&&(o.value="",s=[...d],d.forEach((e=>e.setAttribute("aria-hidden","false")))),t.removeAttribute("aria-activedescendant"),c>-1&&d[c]?.classList.remove("active"),c=-1},h=e=>{e&&(e.dataset.value&&l(e),u())};if(o){const e=()=>{const e=o.value.trim().toLowerCase();c>-1&&(d[c].classList.remove("active"),t.removeAttribute("aria-activedescendant"),c=-1),s=[],d.forEach((t=>{const a=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!a)),a&&s.push(t)}))};o.addEventListener("input",e)}let v=d.find((e=>i.value&&e.dataset.value===i.value));!v&&d.length>0&&(v=d[0]),l(v);const p=e=>{const a="false"===n.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!a)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void u();if("Enter"===e.key)return void(c>-1&&h(s[c]));if(0===s.length)return;const r=c>-1?s.indexOf(d[c]):-1;let i=r;switch(e.key){case"ArrowDown":r<s.length-1&&(i=r+1);break;case"ArrowUp":r>0?i=r-1:-1===r&&(i=0);break;case"Home":i=0;break;case"End":i=s.length-1}if(i!==r){r>-1&&s[r].classList.remove("active");const e=s[i];e.classList.add("active"),c=d.indexOf(e),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};t.addEventListener("keydown",p),o&&o.addEventListener("keydown",p),t.addEventListener("click",(()=>{if("true"===t.getAttribute("aria-expanded"))u();else{n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true"),o&&o.focus();const e=r.querySelector('[role="option"][aria-selected="true"]');e&&(c>-1&&d[c]?.classList.remove("active"),c=d.indexOf(e),e.classList.add("active"),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest"}))}})),r.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&h(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||u()})),n.setAttribute("aria-hidden","true"),e.dataset.selectInitialized=!0};document.querySelectorAll("div.select:not([data-select-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("div.select:not([data-select-initialized])")&&e(t),t.querySelectorAll("div.select:not([data-select-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,a="true"===e.dataset.initialMobileOpen,n=parseInt(e.dataset.breakpoint)||768;let r=n>0?window.innerWidth>=n?t:a:t;const i=()=>{const t=window.location.pathname.replace(/\/$/,"");e.querySelectorAll("a").forEach((e=>{if(e.hasAttribute("data-ignore-current"))return;new URL(e.href).pathname.replace(/\/$/,"")===t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}))},o=()=>{e.setAttribute("aria-hidden",!r),r?e.removeAttribute("inert"):e.setAttribute("inert","")},d=e=>{r=e,o()},s=e.id;window.addEventListener("sidebar:open",(e=>{e.detail?.id&&e.detail.id!==s||d(!0)})),window.addEventListener("sidebar:close",(e=>{e.detail?.id&&e.detail.id!==s||d(!1)})),window.addEventListener("sidebar:toggle",(e=>{e.detail?.id&&e.detail.id!==s||d(!r)})),e.addEventListener("click",(t=>{const a=t.target,r=e.querySelector("nav");if(window.innerWidth<n&&a.closest("a, button")&&!a.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void d(!1);(a===e||r&&!r.contains(a))&&(document.activeElement&&document.activeElement.blur(),d(!1))})),window.addEventListener("popstate",i),window.addEventListener("basecoat:locationchange",i),o(),i(),e.dataset.sidebarInitialized=!0};document.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".sidebar:not([data-sidebar-initialized])")&&e(t),t.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const a=Array.from(t.querySelectorAll('[role="tab"]')),n=a.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),r=e=>{a.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),n[t]&&(n[t].hidden=!0)})),e.setAttribute("aria-selected","true"),e.setAttribute("tabindex","0");const t=document.getElementById(e.getAttribute("aria-controls"));t&&(t.hidden=!1)};t.addEventListener("click",(e=>{const t=e.target.closest('[role="tab"]');t&&r(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!a.includes(t))return;let n;const i=a.indexOf(t);switch(e.key){case"ArrowRight":n=a[(i+1)%a.length];break;case"ArrowLeft":n=a[(i-1+a.length)%a.length];break;case"Home":n=a[0];break;case"End":n=a[a.length-1];break;default:return}e.preventDefault(),r(n),n.focus()})),e.dataset.tabsInitialized=!0};document.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".tabs:not([data-tabs-initialized])")&&e(t),t.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{let e;const t=new WeakMap;let a=!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 r(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",d),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),a=e.target.closest(".toast footer button");(t||a)&&s(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(i),e.dataset.toasterInitialized="true")}function i(e){if(e.dataset.toastInitialized)return;const n=parseInt(e.dataset.duration),r=-1!==n?n||("error"===e.dataset.category?5e3:3e3):-1,i={remainingTime:r,timeoutId:null,startTime:null};-1!==r&&(a?i.timeoutId=null:(i.startTime=Date.now(),i.timeoutId=setTimeout((()=>s(e)),r))),t.set(e,i),e.dataset.toastInitialized="true"}function o(){a||(a=!0,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);a.timeoutId&&(clearTimeout(a.timeoutId),a.timeoutId=null,a.remainingTime-=Date.now()-a.startTime)})))}function d(){a&&(a=!1,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);-1===a.remainingTime||a.timeoutId||(a.remainingTime>0?(a.startTime=Date.now(),a.timeoutId=setTimeout((()=>s(e)),a.remainingTime)):s(e))})))}function s(e){if(!t.has(e))return;const a=t.get(e);clearTimeout(a.timeoutId),t.delete(e),document.activeElement&&document.activeElement.blur(),e.setAttribute("aria-hidden","true"),e.addEventListener("transitionend",(()=>e.remove()),{once:!0})}const c=document.getElementById("toaster");c&&r(c),window.addEventListener("basecoat:toast",(t=>{if(!e)return void console.error("Cannot create toast: toaster container not found on page.");const a=function(e){const{category:t="info",title:a,description:r,action:i,cancel:o,duration:d,icon:s}=e,c=s||t&&n[t]||"",l=a?`<h2>${a}</h2>`:"",u=r?`<p>${r}</p>`:"",h=i?.href?`<a href="${i.href}" class="btn" data-toast-action>${i.label}</a>`:i?.onclick?`<button type="button" class="btn" data-toast-action onclick="${i.onclick}">${i.label}</button>`:"",v=o?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${o?.onclick}">${o.label}</button>`:"",p=`\n <div\n class="toast"\n role="${"error"===t?"alert":"status"}"\n aria-atomic="true"\n ${t?`data-category="${t}"`:""}\n ${void 0!==d?`data-duration="${d}"`:""}\n >\n <div class="toast-content">\n ${c}\n <section>\n ${l}\n ${u}\n </section>\n ${h||v?`<footer>${h}${v}</footer>`:""}\n </div>\n </div>\n </div>\n `,b=document.createElement("template");return b.innerHTML=p.trim(),b.content.firstChild}(t.detail?.config||{});e.appendChild(a)}));new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("#toaster")&&r(t),e&&t.matches(".toast:not([data-toast-initialized])")&&i(t))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
@@ -0,0 +1,10 @@
1
+ (() => {
2
+ document.body.addEventListener('click', (event) => {
3
+ const toggleButton = event.target.closest('[data-action="toggle-dark-mode"]');
4
+
5
+ if (!toggleButton) return;
6
+
7
+ const isDark = document.documentElement.classList.toggle('dark');
8
+ localStorage.setItem('darkMode', isDark ? 'dark' : 'light');
9
+ });
10
+ })();
@@ -0,0 +1 @@
1
+ document.body.addEventListener("click",(t=>{if(!t.target.closest('[data-action="toggle-dark-mode"]'))return;const e=document.documentElement.classList.toggle("dark");localStorage.setItem("darkMode",e?"dark":"light")}));
@@ -0,0 +1,136 @@
1
+ (() => {
2
+ const initDropdownMenu = (dropdownMenuComponent) => {
3
+ const trigger = dropdownMenuComponent.querySelector(':scope > button');
4
+ const popover = dropdownMenuComponent.querySelector(':scope > [data-popover]');
5
+ const menu = popover.querySelector('[role="menu"]');
6
+
7
+ if (!trigger || !menu || !popover) {
8
+ console.error('Dropdown menu component is missing a trigger, a menu, or a popover content element.', dropdownMenuComponent);
9
+ return;
10
+ }
11
+
12
+ let menuItems = [];
13
+ let activeIndex = -1;
14
+
15
+ const closeMenu = () => {
16
+ if (trigger.getAttribute('aria-expanded') === 'false') return;
17
+ trigger.setAttribute('aria-expanded', 'false');
18
+ trigger.removeAttribute('aria-activedescendant');
19
+ popover.setAttribute('aria-hidden', 'true');
20
+ trigger.focus();
21
+ activeIndex = -1;
22
+ };
23
+
24
+ const openMenu = () => {
25
+ trigger.setAttribute('aria-expanded', 'true');
26
+ popover.setAttribute('aria-hidden', 'false');
27
+ menuItems = Array.from(menu.querySelectorAll('[role^="menuitem"]:not([disabled])'));
28
+ if (menuItems.length > 0) {
29
+ setActiveItem(0);
30
+ }
31
+ };
32
+
33
+ const setActiveItem = (index) => {
34
+ if (activeIndex > -1 && menuItems[activeIndex]) {
35
+ menuItems[activeIndex].classList.remove('active');
36
+ }
37
+ activeIndex = index;
38
+ if (activeIndex > -1 && menuItems[activeIndex]) {
39
+ const activeItem = menuItems[activeIndex];
40
+ activeItem.classList.add('active');
41
+ trigger.setAttribute('aria-activedescendant', activeItem.id);
42
+ } else {
43
+ trigger.removeAttribute('aria-activedescendant');
44
+ }
45
+ };
46
+
47
+ trigger.addEventListener('click', () => {
48
+ const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
49
+ if (isExpanded) {
50
+ closeMenu();
51
+ } else {
52
+ openMenu();
53
+ }
54
+ });
55
+
56
+ dropdownMenuComponent.addEventListener('keydown', (e) => {
57
+ const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
58
+
59
+ if (e.key === 'Escape') {
60
+ if (isExpanded) closeMenu();
61
+ return;
62
+ }
63
+
64
+ if (!isExpanded) {
65
+ if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(e.key)) {
66
+ e.preventDefault();
67
+ openMenu();
68
+ }
69
+ return;
70
+ }
71
+
72
+ if (menuItems.length === 0) return;
73
+
74
+ let nextIndex = activeIndex;
75
+
76
+ switch (e.key) {
77
+ case 'ArrowDown':
78
+ e.preventDefault();
79
+ nextIndex = activeIndex < menuItems.length - 1 ? activeIndex + 1 : 0;
80
+ break;
81
+ case 'ArrowUp':
82
+ e.preventDefault();
83
+ nextIndex = activeIndex > 0 ? activeIndex - 1 : menuItems.length - 1;
84
+ break;
85
+ case 'Home':
86
+ e.preventDefault();
87
+ nextIndex = 0;
88
+ break;
89
+ case 'End':
90
+ e.preventDefault();
91
+ nextIndex = menuItems.length - 1;
92
+ break;
93
+ case 'Enter':
94
+ case ' ':
95
+ e.preventDefault();
96
+ menuItems[activeIndex]?.click();
97
+ closeMenu();
98
+ return;
99
+ }
100
+
101
+ if (nextIndex !== activeIndex) {
102
+ setActiveItem(nextIndex);
103
+ }
104
+ });
105
+
106
+ menu.addEventListener('click', (e) => {
107
+ if (e.target.closest('[role^="menuitem"]')) {
108
+ closeMenu();
109
+ }
110
+ });
111
+
112
+ document.addEventListener('click', (e) => {
113
+ if (!dropdownMenuComponent.contains(e.target)) {
114
+ closeMenu();
115
+ }
116
+ });
117
+
118
+ dropdownMenuComponent.dataset.dropdownMenuInitialized = true;
119
+ };
120
+
121
+ document.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
122
+
123
+ const observer = new MutationObserver((mutations) => {
124
+ mutations.forEach((mutation) => {
125
+ mutation.addedNodes.forEach((node) => {
126
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
127
+ if (node.matches('.dropdown-menu:not([data-dropdown-menu-initialized])')) {
128
+ initDropdownMenu(node);
129
+ }
130
+ node.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
131
+ });
132
+ });
133
+ });
134
+
135
+ observer.observe(document.body, { childList: true, subtree: true });
136
+ })();
@@ -0,0 +1 @@
1
+ (()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=e.querySelector(":scope > [data-popover]"),n=r.querySelector('[role="menu"]');if(!t||!n||!r)return void console.error("Dropdown menu component is missing a trigger, a menu, or a popover content element.",e);let a=[],o=-1;const d=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),r.setAttribute("aria-hidden","true"),t.focus(),o=-1)},i=()=>{t.setAttribute("aria-expanded","true"),r.setAttribute("aria-hidden","false"),a=Array.from(n.querySelectorAll('[role^="menuitem"]:not([disabled])')),a.length>0&&c(0)},c=e=>{if(o>-1&&a[o]&&a[o].classList.remove("active"),o=e,o>-1&&a[o]){const e=a[o];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?d():i()})),e.addEventListener("keydown",(e=>{const r="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(r&&d());if(!r)return void(["ArrowDown","ArrowUp","Enter"," "].includes(e.key)&&(e.preventDefault(),i()));if(0===a.length)return;let n=o;switch(e.key){case"ArrowDown":e.preventDefault(),n=o<a.length-1?o+1:0;break;case"ArrowUp":e.preventDefault(),n=o>0?o-1:a.length-1;break;case"Home":e.preventDefault(),n=0;break;case"End":e.preventDefault(),n=a.length-1;break;case"Enter":case" ":return e.preventDefault(),a[o]?.click(),void d()}n!==o&&c(n)})),n.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&d()})),document.addEventListener("click",(t=>{e.contains(t.target)||d()})),e.dataset.dropdownMenuInitialized=!0};document.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".dropdown-menu:not([data-dropdown-menu-initialized])")&&e(t),t.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
@@ -0,0 +1,69 @@
1
+ (() => {
2
+ const initPopover = (popoverComponent) => {
3
+ const trigger = popoverComponent.querySelector(':scope > button');
4
+ const content = popoverComponent.querySelector(':scope > [data-popover]');
5
+
6
+ if (!trigger || !content) {
7
+ console.error('Popover component is missing a trigger button or a content element.', popoverComponent);
8
+ return;
9
+ }
10
+
11
+ const closePopover = () => {
12
+ if (trigger.getAttribute('aria-expanded') === 'false') return;
13
+ trigger.setAttribute('aria-expanded', 'false');
14
+ content.setAttribute('aria-hidden', 'true');
15
+ trigger.focus();
16
+ };
17
+
18
+ const openPopover = () => {
19
+ const elementToFocus = content.querySelector('[autofocus]');
20
+ if (elementToFocus) {
21
+ content.addEventListener('transitionend', () => {
22
+ elementToFocus.focus();
23
+ }, { once: true });
24
+ }
25
+
26
+ trigger.setAttribute('aria-expanded', 'true');
27
+ content.setAttribute('aria-hidden', 'false');
28
+ };
29
+
30
+ trigger.addEventListener('click', () => {
31
+ const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
32
+ if (isExpanded) {
33
+ closePopover();
34
+ } else {
35
+ openPopover();
36
+ }
37
+ });
38
+
39
+ popoverComponent.addEventListener('keydown', (e) => {
40
+ if (e.key === 'Escape') {
41
+ closePopover();
42
+ }
43
+ });
44
+
45
+ document.addEventListener('click', (e) => {
46
+ if (!popoverComponent.contains(e.target)) {
47
+ closePopover();
48
+ }
49
+ });
50
+
51
+ popoverComponent.dataset.popoverInitialized = true;
52
+ };
53
+
54
+ document.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
55
+
56
+ const observer = new MutationObserver((mutations) => {
57
+ mutations.forEach((mutation) => {
58
+ mutation.addedNodes.forEach((node) => {
59
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
60
+ if (node.matches('.popover:not([data-popover-initialized])')) {
61
+ initPopover(node);
62
+ }
63
+ node.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
64
+ });
65
+ });
66
+ });
67
+
68
+ observer.observe(document.body, { childList: true, subtree: true });
69
+ })();
@@ -0,0 +1 @@
1
+ (()=>{const e=e=>{const t=e.querySelector(":scope > button"),o=e.querySelector(":scope > [data-popover]");if(!t||!o)return void console.error("Popover component is missing a trigger button or a content element.",e);const r=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),o.setAttribute("aria-hidden","true"),t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?r():(()=>{const e=o.querySelector("[autofocus]");e&&o.addEventListener("transitionend",(()=>{e.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),o.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&r()})),document.addEventListener("click",(t=>{e.contains(t.target)||r()})),e.dataset.popoverInitialized=!0};document.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".popover:not([data-popover-initialized])")&&e(t),t.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
@@ -0,0 +1,209 @@
1
+ (() => {
2
+ const initSelect = (selectComponent) => {
3
+ const trigger = selectComponent.querySelector(':scope > button');
4
+ const selectedValue = trigger.querySelector(':scope > span');
5
+ const popover = selectComponent.querySelector(':scope > [data-popover]');
6
+ const listbox = popover.querySelector('[role="listbox"]');
7
+ const input = selectComponent.querySelector(':scope > input[type="hidden"]');
8
+ const filter = selectComponent.querySelector('header input[type="text"]');
9
+ if (!trigger || !popover || !listbox || !input) return;
10
+
11
+ const options = Array.from(listbox.querySelectorAll('[role="option"]'));
12
+ let visibleOptions = [...options];
13
+ let activeIndex = -1;
14
+
15
+ const updateValue = (option) => {
16
+ if (option) {
17
+ selectedValue.innerHTML = option.dataset.label || option.innerHTML;
18
+ input.value = option.dataset.value;
19
+ listbox.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute('aria-selected');
20
+ option.setAttribute('aria-selected', 'true');
21
+ }
22
+ };
23
+
24
+ const closePopover = () => {
25
+ popover.setAttribute('aria-hidden', 'true');
26
+ trigger.setAttribute('aria-expanded', 'false');
27
+ if (filter) {
28
+ filter.value = '';
29
+ visibleOptions = [...options];
30
+ options.forEach(opt => opt.setAttribute('aria-hidden', 'false'));
31
+ }
32
+ trigger.removeAttribute('aria-activedescendant');
33
+ if (activeIndex > -1) options[activeIndex]?.classList.remove('active');
34
+ activeIndex = -1;
35
+ }
36
+
37
+ const selectOption = (option) => {
38
+ if (!option) return;
39
+
40
+ if (option.dataset.value) {
41
+ updateValue(option);
42
+ }
43
+ closePopover();
44
+ };
45
+
46
+ if (filter) {
47
+ const filterOptions = () => {
48
+ const searchTerm = filter.value.trim().toLowerCase();
49
+
50
+ if (activeIndex > -1) {
51
+ options[activeIndex].classList.remove('active');
52
+ trigger.removeAttribute('aria-activedescendant');
53
+ activeIndex = -1;
54
+ }
55
+
56
+ visibleOptions = [];
57
+ options.forEach(option => {
58
+ const optionText = (option.dataset.label || option.textContent).trim().toLowerCase();
59
+ const matches = optionText.includes(searchTerm);
60
+ option.setAttribute('aria-hidden', String(!matches));
61
+ if (matches) {
62
+ visibleOptions.push(option);
63
+ }
64
+ });
65
+ };
66
+
67
+ filter.addEventListener('input', filterOptions);
68
+ }
69
+
70
+ let initialOption = options.find(opt => input.value && opt.dataset.value === input.value);
71
+ if (!initialOption && options.length > 0) initialOption = options[0];
72
+
73
+ updateValue(initialOption);
74
+
75
+ const handleKeyNavigation = (e) => {
76
+ const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
77
+
78
+ if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End', 'Escape'].includes(e.key)) {
79
+ return;
80
+ }
81
+
82
+ if (!isPopoverOpen) {
83
+ if (e.key !== 'Enter' && e.key !== 'Escape') {
84
+ e.preventDefault();
85
+ trigger.click();
86
+ }
87
+ return;
88
+ }
89
+
90
+ e.preventDefault();
91
+
92
+ if (e.key === 'Escape') {
93
+ closePopover();
94
+ return;
95
+ }
96
+
97
+ if (e.key === 'Enter') {
98
+ if (activeIndex > -1) {
99
+ selectOption(visibleOptions[activeIndex]);
100
+ }
101
+ return;
102
+ }
103
+
104
+ if (visibleOptions.length === 0) return;
105
+
106
+ const currentVisibleIndex = activeIndex > -1 ? visibleOptions.indexOf(options[activeIndex]) : -1;
107
+ let nextVisibleIndex = currentVisibleIndex;
108
+
109
+ switch (e.key) {
110
+ case 'ArrowDown':
111
+ if (currentVisibleIndex < visibleOptions.length - 1) {
112
+ nextVisibleIndex = currentVisibleIndex + 1;
113
+ }
114
+ break;
115
+ case 'ArrowUp':
116
+ if (currentVisibleIndex > 0) {
117
+ nextVisibleIndex = currentVisibleIndex - 1;
118
+ } else if (currentVisibleIndex === -1) {
119
+ nextVisibleIndex = 0; // Start from top if nothing is active
120
+ }
121
+ break;
122
+ case 'Home':
123
+ nextVisibleIndex = 0;
124
+ break;
125
+ case 'End':
126
+ nextVisibleIndex = visibleOptions.length - 1;
127
+ break;
128
+ }
129
+
130
+ if (nextVisibleIndex !== currentVisibleIndex) {
131
+ if (currentVisibleIndex > -1) {
132
+ visibleOptions[currentVisibleIndex].classList.remove('active');
133
+ }
134
+
135
+ const newActiveOption = visibleOptions[nextVisibleIndex];
136
+ newActiveOption.classList.add('active');
137
+ activeIndex = options.indexOf(newActiveOption);
138
+
139
+ if (newActiveOption.id) {
140
+ trigger.setAttribute('aria-activedescendant', newActiveOption.id);
141
+ }
142
+ newActiveOption.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
143
+ }
144
+ };
145
+
146
+ trigger.addEventListener('keydown', handleKeyNavigation);
147
+ if (filter) {
148
+ filter.addEventListener('keydown', handleKeyNavigation);
149
+ }
150
+
151
+ trigger.addEventListener('click', () => {
152
+ const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
153
+
154
+ if (isExpanded) {
155
+ closePopover();
156
+ } else {
157
+ popover.setAttribute('aria-hidden', 'false');
158
+ trigger.setAttribute('aria-expanded', 'true');
159
+ if (filter) filter.focus();
160
+
161
+ const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
162
+ if (selectedOption) {
163
+ if (activeIndex > -1) {
164
+ options[activeIndex]?.classList.remove('active');
165
+ }
166
+ activeIndex = options.indexOf(selectedOption);
167
+ selectedOption.classList.add('active');
168
+ if (selectedOption.id) {
169
+ trigger.setAttribute('aria-activedescendant', selectedOption.id);
170
+ }
171
+ selectedOption.scrollIntoView({ block: 'nearest' });
172
+ }
173
+ }
174
+ });
175
+
176
+ listbox.addEventListener('click', (e) => {
177
+ const clickedOption = e.target.closest('[role="option"]');
178
+ if (clickedOption) {
179
+ selectOption(clickedOption);
180
+ }
181
+ });
182
+
183
+ document.addEventListener('click', (e) => {
184
+ if (!selectComponent.contains(e.target)) {
185
+ closePopover();
186
+ }
187
+ });
188
+
189
+ popover.setAttribute('aria-hidden', 'true');
190
+ selectComponent.dataset.selectInitialized = true;
191
+ };
192
+
193
+ document.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
194
+
195
+ const observer = new MutationObserver((mutations) => {
196
+ mutations.forEach((mutation) => {
197
+ mutation.addedNodes.forEach((node) => {
198
+ if (node.nodeType === Node.ELEMENT_NODE) {
199
+ if (node.matches('div.select:not([data-select-initialized])')) {
200
+ initSelect(node);
201
+ }
202
+ node.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
203
+ }
204
+ });
205
+ });
206
+ });
207
+
208
+ observer.observe(document.body, { childList: true, subtree: true });
209
+ })();
@@ -0,0 +1 @@
1
+ (()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=t.querySelector(":scope > span"),a=e.querySelector(":scope > [data-popover]"),i=a.querySelector('[role="listbox"]'),s=e.querySelector(':scope > input[type="hidden"]'),n=e.querySelector('header input[type="text"]');if(!(t&&a&&i&&s))return;const o=Array.from(i.querySelectorAll('[role="option"]'));let c=[...o],d=-1;const l=e=>{e&&(r.innerHTML=e.dataset.label||e.innerHTML,s.value=e.dataset.value,i.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},u=()=>{a.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),n&&(n.value="",c=[...o],o.forEach((e=>e.setAttribute("aria-hidden","false")))),t.removeAttribute("aria-activedescendant"),d>-1&&o[d]?.classList.remove("active"),d=-1},v=e=>{e&&(e.dataset.value&&l(e),u())};if(n){const e=()=>{const e=n.value.trim().toLowerCase();d>-1&&(o[d].classList.remove("active"),t.removeAttribute("aria-activedescendant"),d=-1),c=[],o.forEach((t=>{const r=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!r)),r&&c.push(t)}))};n.addEventListener("input",e)}let b=o.find((e=>s.value&&e.dataset.value===s.value));!b&&o.length>0&&(b=o[0]),l(b);const p=e=>{const r="false"===a.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 u();if("Enter"===e.key)return void(d>-1&&v(c[d]));if(0===c.length)return;const i=d>-1?c.indexOf(o[d]):-1;let s=i;switch(e.key){case"ArrowDown":i<c.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=c.length-1}if(s!==i){i>-1&&c[i].classList.remove("active");const e=c[s];e.classList.add("active"),d=o.indexOf(e),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};t.addEventListener("keydown",p),n&&n.addEventListener("keydown",p),t.addEventListener("click",(()=>{if("true"===t.getAttribute("aria-expanded"))u();else{a.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true"),n&&n.focus();const e=i.querySelector('[role="option"][aria-selected="true"]');e&&(d>-1&&o[d]?.classList.remove("active"),d=o.indexOf(e),e.classList.add("active"),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest"}))}})),i.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&v(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||u()})),a.setAttribute("aria-hidden","true"),e.dataset.selectInitialized=!0};document.querySelectorAll("div.select:not([data-select-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("div.select:not([data-select-initialized])")&&e(t),t.querySelectorAll("div.select:not([data-select-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
@@ -0,0 +1,110 @@
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
+ const initSidebar = (sidebarComponent) => {
20
+ const initialOpen = sidebarComponent.dataset.initialOpen !== 'false';
21
+ const initialMobileOpen = sidebarComponent.dataset.initialMobileOpen === 'true';
22
+ const breakpoint = parseInt(sidebarComponent.dataset.breakpoint) || 768;
23
+
24
+ let open = breakpoint > 0
25
+ ? (window.innerWidth >= breakpoint ? initialOpen : initialMobileOpen)
26
+ : 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
+
42
+ const updateState = () => {
43
+ sidebarComponent.setAttribute('aria-hidden', !open);
44
+ if (open) {
45
+ sidebarComponent.removeAttribute('inert');
46
+ } else {
47
+ sidebarComponent.setAttribute('inert', '');
48
+ }
49
+ };
50
+
51
+ const setState = (state) => {
52
+ open = state;
53
+ updateState();
54
+ };
55
+
56
+ const sidebarId = sidebarComponent.id;
57
+
58
+ window.addEventListener('sidebar:open', (e) => {
59
+ if (!e.detail?.id || e.detail.id === sidebarId) setState(true);
60
+ });
61
+ window.addEventListener('sidebar:close', (e) => {
62
+ if (!e.detail?.id || e.detail.id === sidebarId) setState(false);
63
+ });
64
+ window.addEventListener('sidebar:toggle', (e) => {
65
+ if (!e.detail?.id || e.detail.id === sidebarId) setState(!open);
66
+ });
67
+
68
+ sidebarComponent.addEventListener('click', (e) => {
69
+ const target = e.target;
70
+ const nav = sidebarComponent.querySelector('nav');
71
+
72
+ const isMobile = window.innerWidth < breakpoint;
73
+
74
+ if (isMobile && (target.closest('a, button') && !target.closest('[data-keep-mobile-sidebar-open]'))) {
75
+ if (document.activeElement) document.activeElement.blur();
76
+ setState(false);
77
+ return;
78
+ }
79
+
80
+ if (target === sidebarComponent || (nav && !nav.contains(target))) {
81
+ if (document.activeElement) document.activeElement.blur();
82
+ setState(false);
83
+ }
84
+ });
85
+
86
+ window.addEventListener('popstate', updateCurrentPageLinks);
87
+ window.addEventListener('basecoat:locationchange', updateCurrentPageLinks);
88
+
89
+ updateState();
90
+ updateCurrentPageLinks();
91
+ sidebarComponent.dataset.sidebarInitialized = true;
92
+ };
93
+
94
+ document.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
95
+
96
+ const observer = new MutationObserver((mutations) => {
97
+ mutations.forEach((mutation) => {
98
+ mutation.addedNodes.forEach((node) => {
99
+ if (node.nodeType === Node.ELEMENT_NODE) {
100
+ if (node.matches('.sidebar:not([data-sidebar-initialized])')) {
101
+ initSidebar(node);
102
+ }
103
+ node.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
104
+ }
105
+ });
106
+ });
107
+ });
108
+
109
+ observer.observe(document.body, { childList: true, subtree: true });
110
+ })();
@@ -0,0 +1 @@
1
+ (()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,i="true"===e.dataset.initialMobileOpen,a=parseInt(e.dataset.breakpoint)||768;let n=a>0?window.innerWidth>=a?t:i:t;const d=()=>{const t=window.location.pathname.replace(/\/$/,"");e.querySelectorAll("a").forEach((e=>{if(e.hasAttribute("data-ignore-current"))return;new URL(e.href).pathname.replace(/\/$/,"")===t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}))},o=()=>{e.setAttribute("aria-hidden",!n),n?e.removeAttribute("inert"):e.setAttribute("inert","")},r=e=>{n=e,o()},s=e.id;window.addEventListener("sidebar:open",(e=>{e.detail?.id&&e.detail.id!==s||r(!0)})),window.addEventListener("sidebar:close",(e=>{e.detail?.id&&e.detail.id!==s||r(!1)})),window.addEventListener("sidebar:toggle",(e=>{e.detail?.id&&e.detail.id!==s||r(!n)})),e.addEventListener("click",(t=>{const i=t.target,n=e.querySelector("nav");if(window.innerWidth<a&&i.closest("a, button")&&!i.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void r(!1);(i===e||n&&!n.contains(i))&&(document.activeElement&&document.activeElement.blur(),r(!1))})),window.addEventListener("popstate",d),window.addEventListener("basecoat:locationchange",d),o(),d(),e.dataset.sidebarInitialized=!0};document.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".sidebar:not([data-sidebar-initialized])")&&e(t),t.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();