@rxxuzi/gumi
Version:
Clean & minimal design system with delightful interactions
10 lines (9 loc) • 45.5 kB
JavaScript
/*!
* Gumi.js v1.0.0
* Clean & minimal design system with delightful interactions 🍬
* https://github.com/rxxuzi/gumi
* (c) 2025 rxxuzi
* Released under the MIT License
*/
function t(t){return"string"==typeof t?document.querySelector(t):t}function e(t){return document.querySelectorAll(t)}function i(t){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()}function s(t,e={}){const i=document.createElement(t);return e.className&&(i.className=e.className),e.id&&(i.id=e.id),e.text&&(i.textContent=e.text),e.html&&(i.innerHTML=e.html),e.attributes&&Object.entries(e.attributes).forEach((([t,e])=>{i.setAttribute(t,e)})),e.style&&Object.assign(i.style,e.style),e.events&&Object.entries(e.events).forEach((([t,e])=>{i.addEventListener(t,e)})),e.children&&e.children.forEach((t=>{"string"==typeof t?i.appendChild(document.createTextNode(t)):i.appendChild(t)})),i}function n(e,i,s,n){const r=e instanceof Document||e instanceof Window?e:t(e);r&&("function"==typeof s?r.addEventListener(i,s):r.addEventListener(i,(t=>{const e=t.target.closest(s);e&&n&&n.call(e,t)})))}function r(e,i,s){const n=e instanceof Document||e instanceof Window?e:t(e);n&&n.removeEventListener(i,s)}function o(e,i,s){const n=t(e);if(!n)return;const r=new CustomEvent(i,{bubbles:!0,cancelable:!0,detail:s});n.dispatchEvent(r)}function a(e,i){const s=t(e);return!!s&&s.classList.contains(i)}function l(e,...i){const s=t(e);s&&s.classList.add(...i)}function c(e,...i){const s=t(e);s&&s.classList.remove(...i)}function h(e){const i=t(e);if(!i)return;"none"===i.style.display&&(i.style.display=""),"none"===window.getComputedStyle(i).display&&(i.style.display="block")}function d(e){const i=t(e);i&&(i.style.display="none")}function u(e){const i=t(e);i&&("none"===window.getComputedStyle(i).display?h(i):d(i))}function p(e,i,s={}){const n=t(e);if(!n)return Promise.resolve();const r={duration:s.duration||300,easing:s.easing||"cubic-bezier(0.4, 0, 0.2, 1)",fill:s.fill||"forwards",delay:s.delay||0,iterations:s.iterations||1,direction:s.direction||"normal"},o=n.animate(i,r);return new Promise((t=>{o.onfinish=()=>t(),o.oncancel=()=>t()}))}function m(e,i={}){const s=t(e);return s?(s.style.opacity="0",s.style.visibility="visible",p(s,[{opacity:0},{opacity:1}],{duration:i.duration||600,...i})):Promise.resolve()}function g(e,i={}){const s=t(e);return s?p(s,[{opacity:1},{opacity:0}],{duration:i.duration||300,...i}).then((()=>{"none"!==i.fill&&(s.style.visibility="hidden")})):Promise.resolve()}function y(e,i={}){const s=t(e);if(!s)return Promise.resolve();const n=s.offsetHeight;return s.style.overflow="hidden",p(s,[{height:`${n}px`,opacity:1},{height:"0px",opacity:0}],{duration:i.duration||300,...i}).then((()=>{s.style.display="none",s.style.height="",s.style.overflow=""}))}function v(e,i={}){const s=t(e);if(!s)return Promise.resolve();s.style.display="block",s.style.height="auto";const n=s.offsetHeight;return s.style.height="0px",s.style.overflow="hidden",p(s,[{height:"0px",opacity:0},{height:`${n}px`,opacity:1}],{duration:i.duration||300,...i}).then((()=>{s.style.height="",s.style.overflow=""}))}function b(e,i={}){const s=t(e);return s?(s.style.visibility="visible",p(s,[{transform:"scale(0.9)",opacity:0},{transform:"scale(1)",opacity:1}],{duration:i.duration||300,...i})):Promise.resolve()}function f(e,i={}){const s=t(e);return s?p(s,[{transform:"scale(1)",opacity:1},{transform:"scale(0.9)",opacity:0}],{duration:i.duration||300,...i}):Promise.resolve()}function w(e,i="left",s={}){const n=t(e);if(!n)return Promise.resolve();return n.style.visibility="visible",p(n,[{transform:{left:"translateX(-100%)",right:"translateX(100%)",top:"translateY(-100%)",bottom:"translateY(100%)"}[i],opacity:0},{transform:"translate(0)",opacity:1}],{duration:s.duration||300,...s})}function x(e,i={}){const s=t(e);return s?p(s,[{transform:"translateY(0)"},{transform:"translateY(-20px)"},{transform:"translateY(0)"}],{duration:i.duration||1e3,...i}):Promise.resolve()}function k(e,i={}){const s=t(e);return s?p(s,[{transform:"translateX(0)"},{transform:"translateX(-10px)"},{transform:"translateX(10px)"},{transform:"translateX(-10px)"},{transform:"translateX(10px)"},{transform:"translateX(0)"}],{duration:i.duration||500,...i}):Promise.resolve()}function A(e,i={}){const s=t(e);return s?p(s,[{transform:"scale(1)",opacity:1},{transform:"scale(1.05)",opacity:.8},{transform:"scale(1)",opacity:1}],{duration:i.duration||2e3,...i}):Promise.resolve()}class E{constructor(){this.currentTheme="light",this.storageKey="apple-theme",this.init()}init(){const t=localStorage.getItem(this.storageKey),e=window.matchMedia("(prefers-color-scheme: dark)").matches;t?this.setTheme(t):e&&this.setTheme("dark"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(t=>{localStorage.getItem(this.storageKey)||this.setTheme(t.matches?"dark":"light")}))}getTheme(){return this.currentTheme}setTheme(t){if("auto"===t){t=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}this.currentTheme=t,document.documentElement.setAttribute("data-theme",t),localStorage.setItem(this.storageKey,t),o(document.documentElement,"apple-theme-change",{theme:t})}toggleTheme(){const t="light"===this.currentTheme?"dark":"light";this.setTheme(t)}clearPreference(){localStorage.removeItem(this.storageKey),this.init()}createToggleButton(t={}){const e=document.createElement("button");e.className=t.className||"btn-icon btn-ghost",e.setAttribute("aria-label","Toggle theme");const i=()=>{const i="dark"===this.currentTheme;e.innerHTML=i?t.darkIcon||'<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>':t.lightIcon||'<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>'};return i(),e.addEventListener("click",(()=>{this.toggleTheme(),i()})),window.addEventListener("apple-theme-change",i),e}}function C(t,e){let i=null;return function(...s){i&&clearTimeout(i),i=setTimeout((()=>{i=null,t(...s)}),e)}}function T(t,e){let i=!1;return function(...s){i||(t(...s),i=!0,setTimeout((()=>{i=!1}),e))}}function O(t="apple"){return`${t}-${Math.random().toString(36).substr(2,9)}`}function S(t,e,i){return Math.max(e,Math.min(i,t))}async function L(t){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(t),!0;{const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-999999px",e.style.top="-999999px",document.body.appendChild(e),e.focus(),e.select();const i=document.execCommand("copy");return e.remove(),i}}catch(t){return console.error("Failed to copy text:",t),!1}}class M{constructor(e,i={}){this.backdrop=null,this.isOpen=!1,this.escapeHandler=null,this.keydownListener=null;const s=t(e);if(!s)throw new Error("Modal element not found");this.element=s,this.options={backdrop:!0,keyboard:!0,focus:!0,...i},this.init()}init(){this.element.style.display="none",this.element.setAttribute("role","dialog"),this.element.setAttribute("aria-modal","true"),this.element.id||(this.element.id=O("modal"))}open(){this.isOpen||(this.isOpen=!0,this.options.backdrop&&this.createBackdrop(),Object.assign(this.element.style,{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%) scale(0.9)",zIndex:"1050",opacity:"0",maxWidth:"90vw",maxHeight:"90vh",overflow:"auto",display:"block"}),document.body.style.overflow="hidden",this.backdrop&&p(this.backdrop,[{opacity:0},{opacity:1}],{duration:200}),p(this.element,[{opacity:0,transform:"translate(-50%, -50%) scale(0.9)"},{opacity:1,transform:"translate(-50%, -50%) scale(1)"}],{duration:300}),this.options.focus&&this.element.focus(),this.options.keyboard&&(this.escapeHandler=t=>{"Escape"===t.key&&this.close()},this.keydownListener=t=>{this.escapeHandler&&this.escapeHandler(t)},n(document,"keydown",this.keydownListener)),o(this.element,"modal-open",{modal:this.element}))}close(){if(!this.isOpen)return;this.isOpen=!1,this.keydownListener&&(r(document,"keydown",this.keydownListener),this.keydownListener=null,this.escapeHandler=null);const t=[p(this.element,[{opacity:1,transform:"translate(-50%, -50%) scale(1)"},{opacity:0,transform:"translate(-50%, -50%) scale(0.9)"}],{duration:200})];this.backdrop&&t.push(p(this.backdrop,[{opacity:1},{opacity:0}],{duration:200})),Promise.all(t).then((()=>{this.element.style.display="none",document.body.style.overflow="",this.backdrop&&(this.backdrop.remove(),this.backdrop=null),o(this.element,"modal-close",{modal:this.element})}))}toggle(){this.isOpen?this.close():this.open()}createBackdrop(){const e=t(".gumi-modal-backdrop");e&&e.remove(),this.backdrop=document.createElement("div"),this.backdrop.className="gumi-modal-backdrop",Object.assign(this.backdrop.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(4px)",zIndex:"1040",opacity:"0"}),n(this.backdrop,"click",(()=>this.close())),document.body.appendChild(this.backdrop)}destroy(){this.close(),this.element.removeAttribute("role"),this.element.removeAttribute("aria-modal")}static initFromTriggers(i="[data-modal]"){const s=e(i),r=[];return s.forEach((e=>{const i=e.getAttribute("data-modal");if(!i)return;const s=t(i);if(!s)return;const o=new M(s);r.push(o),n(e,"click",(t=>{t.preventDefault(),o.open()}))})),r}}class F{static show(t,e={}){const i={type:"info",duration:4e3,position:"top-right",...e},r=`toast-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;this.createContainer(i.position);const a=s("div",{className:`gumi-toast ${i.type} entering`,html:`\n ${this.getIcon(i.type)}\n <span>${t}</span>\n `});return this.toasts.set(r,a),this.container.appendChild(a),setTimeout((()=>{this.remove(r)}),i.duration),n(a,"click",(()=>{this.remove(r)})),o(document.body,"gumi-toast-show",{id:r,message:t,type:i.type}),r}static remove(t){const e=this.toasts.get(t);e&&(c(e,"entering"),l(e,"exiting"),setTimeout((()=>{e.parentNode&&e.parentNode.removeChild(e),this.toasts.delete(t)}),200),o(document.body,"gumi-toast-hide",{id:t}))}static removeAll(){Array.from(this.toasts.keys()).forEach((t=>this.remove(t)))}static createContainer(t){this.container||(this.container=s("div",{className:`gumi-toast-container ${t}`}),document.body.appendChild(this.container))}static getIcon(t){const e={success:'<svg class="toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M9 12l2 2 4-4"></path>\n <circle cx="12" cy="12" r="9"></circle>\n </svg>',error:'<svg class="toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <circle cx="12" cy="12" r="9"></circle>\n <line x1="15" y1="9" x2="9" y2="15"></line>\n <line x1="9" y1="9" x2="15" y2="15"></line>\n </svg>',warning:'<svg class="toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>\n <line x1="12" y1="9" x2="12" y2="13"></line>\n <line x1="12" y1="17" x2="12.01" y2="17"></line>\n </svg>',info:'<svg class="toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <circle cx="12" cy="12" r="9"></circle>\n <line x1="12" y1="8" x2="12" y2="12"></line>\n <line x1="12" y1="16" x2="12.01" y2="16"></line>\n </svg>'};return e[t]||e.info}static success(t,e={}){return this.show(t,{...e,type:"success"})}static error(t,e={}){return this.show(t,{...e,type:"error"})}static warning(t,e={}){return this.show(t,{...e,type:"warning"})}static info(t,e={}){return this.show(t,{...e,type:"info"})}}F.container=null,F.toasts=new Map;class I{constructor(e,i={}){this.tabs=[],this.panels=[],this.activeIndex=0;const s=t(e);if(!s)throw new Error("Tabs container not found");this.container=s,this.options={activeIndex:0,...i},this.init()}init(){const e=this.container.querySelector(".tab-list");if(this.tabs=e?Array.from(e.querySelectorAll(".tab-button")):Array.from(this.container.querySelectorAll(".tab")),this.tabs.forEach(((e,i)=>{const s=e.getAttribute("data-tab");if(s){const n=t(s);n&&(this.panels[i]=n,n.setAttribute("role","tabpanel"),n.setAttribute("aria-labelledby",e.id||`tab-${i}`),n.style.transition="opacity 0.2s ease, transform 0.2s ease")}e.setAttribute("role","tab"),e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),e.id||(e.id=`tab-${i}`),n(e,"click",(()=>this.selectTab(i)))})),e?e.setAttribute("role","tablist"):this.container.setAttribute("role","tablist"),void 0!==this.options.activeIndex)this.selectTab(this.options.activeIndex);else if(this.tabs.length>0){const t=this.tabs.findIndex((t=>t.classList.contains("active")));this.selectTab(t>=0?t:0)}}async selectTab(t){if(t<0||t>=this.tabs.length||t===this.activeIndex)return;const e=this.panels[this.activeIndex],i=this.tabs[t],s=this.panels[t];this.tabs.forEach(((t,e)=>{c(t,"active"),t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1")})),l(i,"active"),i.setAttribute("aria-selected","true"),i.setAttribute("tabindex","0"),e&&s&&e!==s?(l(e,"tab-panel-exit"),l(s,"tab-panel-enter"),s.style.display="block",s.style.opacity="0",s.style.transform="translateX(10px)",e.style.opacity="0",e.style.transform="translateX(-10px)",await new Promise((t=>setTimeout(t,150))),e.style.display="none",e.style.opacity="",e.style.transform="",c(e,"tab-panel-exit"),s.style.opacity="1",s.style.transform="translateX(0)",setTimeout((()=>{c(s,"tab-panel-enter"),s.style.opacity="",s.style.transform=""}),200)):s&&this.panels.forEach(((e,i)=>{e&&(e.style.display=i===t?"block":"none")})),this.activeIndex=t,this.options.onChange&&this.options.onChange(t),o(this.container,"tab-change",{index:t})}getActiveIndex(){return this.activeIndex}next(){const t=(this.activeIndex+1)%this.tabs.length;this.selectTab(t)}previous(){const t=0===this.activeIndex?this.tabs.length-1:this.activeIndex-1;this.selectTab(t)}enableKeyboardNavigation(){n(this.container,"keydown",(t=>{const e=t;switch(e.key){case"ArrowLeft":e.preventDefault(),this.previous(),this.tabs[this.activeIndex].focus();break;case"ArrowRight":e.preventDefault(),this.next(),this.tabs[this.activeIndex].focus();break;case"Home":e.preventDefault(),this.selectTab(0),this.tabs[0].focus();break;case"End":e.preventDefault(),this.selectTab(this.tabs.length-1),this.tabs[this.tabs.length-1].focus()}}))}destroy(){this.container.removeAttribute("role"),this.tabs.forEach((t=>{t.removeAttribute("role"),t.removeAttribute("aria-selected")})),this.panels.forEach((t=>{t.removeAttribute("role"),t.removeAttribute("aria-labelledby")}))}static initAll(t=".tabs"){const i=e(t);return Array.from(i).map((t=>new I(t)))}}const B={check:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>',x:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" 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"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>',warning:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>',error:'<svg xmlns="http://www.w3.org/2000/svg" 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"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg>',success:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>',chevronDown:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>',chevronUp:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"></polyline></svg>',chevronLeft:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>',chevronRight:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>',moon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>',sun:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>',loader:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>',menu:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>',search:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><path d="m21 21-4.35-4.35"></path></svg>',plus:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>',minus:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"></line></svg>',copy:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>',heart:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path></svg>',star:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>'};class H{constructor(e,i={}){this.items=[];const s=t(e);if(!s)throw new Error("Accordion container not found");this.container=s,this.options={multiple:!1,collapsed:!0,...i},this.init()}init(){this.options.multiple&&this.container.setAttribute("data-multiple","true"),this.items=Array.from(this.container.querySelectorAll(".accordion-item")),this.items.forEach(((t,e)=>{const i=t.querySelector(".accordion-header"),s=t.querySelector(".accordion-content");if(i&&s){if(i.setAttribute("role","button"),i.setAttribute("aria-expanded","false"),i.id||(i.id=`accordion-header-${e}`),s.setAttribute("role","region"),s.setAttribute("aria-labelledby",i.id),!i.querySelector(".accordion-icon")){const t=document.createElement("span");t.className="accordion-icon",t.innerHTML=B.chevronDown,i.appendChild(t)}this.options.collapsed&&!a(t,"active")?(c(t,"active"),i.setAttribute("aria-expanded","false")):a(t,"active")&&i.setAttribute("aria-expanded","true"),n(i,"click",(()=>this.toggle(e)))}}))}toggle(t){const e=this.items[t];if(!e)return;a(e,"active")?this.close(t):this.open(t)}open(t){const e=this.items[t];if(!e)return;const i=e.querySelector(".accordion-header"),s=e.querySelector(".accordion-content");i&&s&&(this.options.multiple||this.items.forEach(((e,i)=>{i!==t&&a(e,"active")&&this.close(i)})),l(e,"active"),l(i,"active"),i.setAttribute("aria-expanded","true"),o(e,"accordion-toggle",{item:e,open:!0}))}close(t){const e=this.items[t];if(!e)return;const i=e.querySelector(".accordion-header"),s=e.querySelector(".accordion-content");i&&s&&(c(e,"active"),c(i,"active"),i.setAttribute("aria-expanded","false"),o(e,"accordion-toggle",{item:e,open:!1}))}openAll(){this.items.forEach(((t,e)=>this.open(e)))}closeAll(){this.items.forEach(((t,e)=>this.close(e)))}getActiveItems(){return this.items.map(((t,e)=>a(t,"active")?e:-1)).filter((t=>-1!==t))}enableKeyboardNavigation(){this.items.forEach(((t,e)=>{const i=t.querySelector(".accordion-header");i&&(i.setAttribute("tabindex","0"),n(i,"keydown",(t=>{const i=t;switch(i.key){case"Enter":case" ":i.preventDefault(),this.toggle(e);break;case"ArrowDown":i.preventDefault();const t=(e+1)%this.items.length,s=this.items[t].querySelector(".accordion-header");null==s||s.focus();break;case"ArrowUp":i.preventDefault();const n=0===e?this.items.length-1:e-1,r=this.items[n].querySelector(".accordion-header");null==r||r.focus()}})))}))}destroy(){this.items.forEach((t=>{const e=t.querySelector(".accordion-header"),i=t.querySelector(".accordion-content");e&&(e.removeAttribute("role"),e.removeAttribute("aria-expanded"),e.removeAttribute("tabindex")),i&&(i.removeAttribute("role"),i.removeAttribute("aria-labelledby"))}))}static initAll(t=".accordion"){const i=e(t);return Array.from(i).map((t=>new H(t)))}}class ${constructor(e,i,s){this.isOpen=!1;const n=t(e);if(!n)throw new Error("Dropdown trigger not found");if(this.trigger=n,i&&"object"==typeof i&&!("nodeType"in i))this.options={...this.getDefaultOptions(),...i},this.menu=this.findMenu();else{const e=t(i);if(!e)throw new Error("Dropdown menu not found");this.menu=e,this.options={...this.getDefaultOptions(),...s}}this.init()}getDefaultOptions(){return{trigger:"hover",closeOnClick:!0,keyboard:!0}}findMenu(){const e=this.trigger.getAttribute("data-dropdown");if(e){const i=t(e);if(i)return i}let i=this.trigger.nextElementSibling;if(i&&a(i,"dropdown-menu"))return i;const s=this.trigger.closest(".dropdown");if(s&&(i=s.querySelector(".dropdown-menu"),i))return i;throw new Error("Dropdown menu not found")}init(){var t;const e=this.trigger.parentElement;if(e&&a(e,"dropdown"))"click"===this.options.trigger&&l(e,"dropdown-click");else{const e=document.createElement("div");e.className="dropdown","click"===this.options.trigger&&(e.className+=" dropdown-click"),null===(t=this.trigger.parentNode)||void 0===t||t.insertBefore(e,this.trigger),e.appendChild(this.trigger),e.appendChild(this.menu)}"click"===this.options.trigger&&this.bindClickEvents(),this.options.keyboard&&this.bindKeyboardEvents(),this.trigger.setAttribute("role","button"),this.trigger.setAttribute("aria-haspopup","true"),this.trigger.setAttribute("aria-expanded","false"),this.menu.setAttribute("role","menu")}bindClickEvents(){this.clickHandler=t=>{t.preventDefault(),t.stopPropagation(),this.toggle()},n(this.trigger,"click",this.clickHandler),this.documentClickHandler=t=>{const e=t.target,i=this.trigger.closest(".dropdown");i&&!i.contains(e)&&this.hide()},this.options.closeOnClick&&n(this.menu,"click",(t=>{t.target.closest(".dropdown-item")&&this.hide()}))}bindKeyboardEvents(){n(this.trigger,"keydown",(t=>{const e=t;"Enter"===e.key||" "===e.key?(t.preventDefault(),this.toggle()):"Escape"===e.key&&this.isOpen&&(t.preventDefault(),this.hide(),this.trigger.focus())}))}show(){if(this.isOpen||"click"!==this.options.trigger)return;const t=this.trigger.closest(".dropdown");t&&(this.isOpen=!0,l(t,"active"),this.trigger.setAttribute("aria-expanded","true"),this.documentClickHandler&&setTimeout((()=>{n(document,"click",this.documentClickHandler)}),0),o(this.trigger,"gumi:dropdown:show",{dropdown:this}))}hide(){if(!this.isOpen||"click"!==this.options.trigger)return;const t=this.trigger.closest(".dropdown");t&&(this.isOpen=!1,c(t,"active"),this.trigger.setAttribute("aria-expanded","false"),this.documentClickHandler&&r(document,"click",this.documentClickHandler),o(this.trigger,"gumi:dropdown:hide",{dropdown:this}))}toggle(){this.isOpen?this.hide():this.show()}destroy(){this.isOpen&&this.hide(),this.clickHandler&&r(this.trigger,"click",this.clickHandler),this.documentClickHandler&&r(document,"click",this.documentClickHandler),this.trigger.removeAttribute("role"),this.trigger.removeAttribute("aria-haspopup"),this.trigger.removeAttribute("aria-expanded"),this.menu.removeAttribute("role")}static initAll(t="[data-dropdown]"){const i=e(t);return Array.from(i).map((t=>new $(t)))}static initFromAttributes(t="[data-dropdown]"){const i=e(t);return Array.from(i).map((t=>{const e={},i=t.getAttribute("data-trigger");i&&(e.trigger=i);const s=t.getAttribute("data-close-on-click");s&&(e.closeOnClick="false"!==s);const n=t.getAttribute("data-keyboard");return n&&(e.keyboard="false"!==n),new $(t,e)}))}}class q{constructor(e,i){var s;this.value=0;const n=t(e);if(!n)throw new Error("Progress element not found");n.classList.contains("progress")?(this.container=n,this.bar=n.querySelector(".progress-bar"),this.bar||(this.bar=document.createElement("div"),this.bar.className="progress-bar",this.container.appendChild(this.bar))):(n.classList.contains("progress-bar"),this.bar=n,this.container=n.parentElement),this.options={animated:!1,striped:!1,...i,value:null!==(s=i.value)&&void 0!==s?s:0},this.init()}init(){this.bar.setAttribute("role","progressbar"),this.bar.setAttribute("aria-valuemin","0"),this.bar.setAttribute("aria-valuemax","100"),this.options.striped&&l(this.container,"progress-striped"),this.options.animated&&l(this.container,"progress-animated"),this.setValue(this.options.value)}setValue(t){this.value=S(t,0,100),this.bar.style.width=`${this.value}%`,this.bar.setAttribute("aria-valuenow",String(this.value)),this.updateColor()}getValue(){return this.value}updateColor(){let t;t=this.value<25?"var(--gumi-error)":this.value<50?"var(--gumi-warning)":this.value<75?"var(--gumi-secondary)":"var(--gumi-success)",this.bar.style.backgroundColor=t}increment(t=1){this.setValue(this.value+t)}decrement(t=1){this.setValue(this.value-t)}setIndeterminate(t=!0){t?(this.bar.style.width="100%",l(this.container,"progress-indeterminate"),this.bar.removeAttribute("aria-valuenow")):(c(this.container,"progress-indeterminate"),this.setValue(this.value))}setStriped(t=!0){t?l(this.container,"progress-striped"):c(this.container,"progress-striped")}setAnimated(t=!0){t?(l(this.container,"progress-animated"),this.setStriped(!0)):c(this.container,"progress-animated")}animateTo(t,e=1e3){return new Promise((i=>{const s=this.value,n=performance.now(),r=o=>{const a=o-n,l=Math.min(a/e,1),c=l<.5?2*l*l:1-Math.pow(-2*l+2,2)/2,h=s+(t-s)*c;this.setValue(h),l<1?requestAnimationFrame(r):i()};requestAnimationFrame(r)}))}reset(){this.setValue(0)}complete(){this.setValue(100)}static create(t={value:0}){const e=t.container||document.body,i=document.createElement("div");i.className="progress "+(t.className||"");const s=document.createElement("div");return s.className="progress-bar",i.appendChild(s),e.appendChild(i),new q(i,t)}static setProgress(e,i){const s=t(e);if(!s)return;const n=s.classList.contains("progress-bar")?s:s.querySelector(".progress-bar");if(!n)return;const r=S(i,0,100);let o;n.style.width=`${r}%`,n.setAttribute("aria-valuenow",String(r)),o=r<25?"var(--gumi-error)":r<50?"var(--gumi-warning)":r<75?"var(--gumi-secondary)":"var(--gumi-success)",n.style.backgroundColor=o}}class D{constructor(e,i={}){this.errors=new Map;const s=t(e);if(!(s&&s instanceof HTMLFormElement))throw new Error("Form element not found");this.form=s,this.options={showErrors:!0,validateOnChange:!0,...i},this.init()}init(){if(this.form.noValidate=!0,n(this.form,"submit",(t=>{if(t.preventDefault(),this.validate()){const t=new CustomEvent("valid-submit",{detail:{form:this.form},cancelable:!0});this.form.dispatchEvent(t)&&(this.options.rules||this.form.submit())}})),this.options.validateOnChange){this.getInputs().forEach((t=>{n(t,"blur",(()=>this.validateField(t))),n(t,"input",(()=>{this.errors.has(t.name)&&this.validateField(t)}))}))}}getInputs(){return Array.from(this.form.querySelectorAll("input, textarea, select"))}validate(){this.clearErrors();const t=this.getInputs();let e=!0;return t.forEach((t=>{this.validateField(t)||(e=!1)})),e}validateField(t){const e=t.name,i=t.value.trim(),s=t.type;if(this.clearFieldError(t),t.hasAttribute("required")&&!i)return this.setFieldError(t,"This field is required"),!1;if(t.hasAttribute("minlength")){const e=parseInt(t.getAttribute("minlength")||"0");if(i.length<e)return this.setFieldError(t,`Minimum length is ${e} characters`),!1}if(t.hasAttribute("maxlength")){const e=parseInt(t.getAttribute("maxlength")||"0");if(i.length>e)return this.setFieldError(t,`Maximum length is ${e} characters`),!1}if(t.hasAttribute("min")&&"number"===s){const e=parseFloat(t.getAttribute("min")||"0");if(parseFloat(i)<e)return this.setFieldError(t,`Minimum value is ${e}`),!1}if(t.hasAttribute("max")&&"number"===s){const e=parseFloat(t.getAttribute("max")||"0");if(parseFloat(i)>e)return this.setFieldError(t,`Maximum value is ${e}`),!1}if("email"===s&&i){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i))return this.setFieldError(t,"Please enter a valid email address"),!1}if("url"===s&&i)try{new URL(i)}catch(e){return this.setFieldError(t,"Please enter a valid URL"),!1}if(this.options.rules&&e&&this.options.rules[e]){const n=this.options.rules[e];if(n.required&&!i)return this.setFieldError(t,n.message||"This field is required"),!1;if(void 0!==n.min){if(("number"===s?parseFloat(i):i.length)<n.min)return this.setFieldError(t,n.message||`Minimum ${"number"===s?"value":"length"} is ${n.min}`),!1}if(void 0!==n.max){if(("number"===s?parseFloat(i):i.length)>n.max)return this.setFieldError(t,n.message||`Maximum ${"number"===s?"value":"length"} is ${n.max}`),!1}if(n.pattern&&i&&!n.pattern.test(i))return this.setFieldError(t,n.message||"Invalid format"),!1;if(n.custom&&!n.custom(i))return this.setFieldError(t,n.message||"Invalid value"),!1}return!0}setFieldError(t,e){var i,n;if(this.errors.set(t.name,e),l(t,"error"),this.options.showErrors){const r=null===(i=t.parentElement)||void 0===i?void 0:i.querySelector(".error-message");r&&r.remove();const o=s("span",{className:"error-message",text:e,style:{color:"var(--apple-error)",fontSize:"var(--apple-text-sm)",marginTop:"var(--apple-space-1)",display:"block"}});null===(n=t.parentElement)||void 0===n||n.appendChild(o)}}clearFieldError(t){var e;this.errors.delete(t.name),c(t,"error");const i=null===(e=t.parentElement)||void 0===e?void 0:e.querySelector(".error-message");i&&i.remove()}clearErrors(){this.errors.clear();this.getInputs().forEach((t=>{var e;c(t,"error");const i=null===(e=t.parentElement)||void 0===e?void 0:e.querySelector(".error-message");i&&i.remove()}))}getErrors(){return new Map(this.errors)}setRules(t){this.options.rules=t}addValidator(t,e){this.options.rules||(this.options.rules={}),this.options.rules[t]=e}static validateForm(e){const i=t(e);if(!(i&&i instanceof HTMLFormElement))return!1;const s=i.querySelectorAll("input[required], textarea[required], select[required]");let n=!0;return s.forEach((t=>{const e=t;if(!e.value.trim()){n=!1,l(e,"error");const t=()=>{c(e,"error")};e.addEventListener("input",t,{once:!0})}})),n}}class P{constructor(e,i={}){if(this.overlay=null,this.hamburger=null,this.isOpen=!1,this.element=t(e),!this.element)throw new Error("Sidebar element not found");this.options={overlay:!0,closeOnOutsideClick:!0,closeOnEscape:!0,push:!1,pushTarget:"body",...i},this.boundKeyHandler=this.handleKeyPress.bind(this),this.boundOutsideClickHandler=this.handleOutsideClick.bind(this),this.init()}init(){this.options.overlay&&this.createOverlay(),this.setupHamburger(),this.bindEvents()}createOverlay(){this.overlay=s("div",{className:"sidebar-overlay"}),document.body.appendChild(this.overlay),n(this.overlay,"click",(()=>{this.options.closeOnOutsideClick&&this.close()}))}setupHamburger(){const e=`[data-sidebar="#${this.element.id}"], [data-sidebar="${this.element.id}"]`;this.hamburger=t(e),this.hamburger&&n(this.hamburger,"click",(t=>{t.preventDefault(),this.toggle()}))}bindEvents(){this.options.closeOnEscape&&n(document,"keydown",this.boundKeyHandler),this.options.closeOnOutsideClick&&n(document,"click",this.boundOutsideClickHandler)}handleKeyPress(t){"Escape"===t.key&&this.isOpen&&this.close()}handleOutsideClick(t){if(!this.isOpen)return;const e=t.target;this.element.contains(e)||this.hamburger&&this.hamburger.contains(e)||this.close()}open(){if(this.isOpen)return;if(this.isOpen=!0,l(this.element,"active"),this.overlay&&l(this.overlay,"active"),this.hamburger&&l(this.hamburger,"active"),this.options.push&&this.options.pushTarget){const e=t(this.options.pushTarget);if(e){l(e,"sidebar-push",this.element.classList.contains("sidebar-right")?"pushed-right":"pushed")}}const e=new CustomEvent("gumi-sidebar-open",{detail:{sidebar:this}});this.element.dispatchEvent(e)}close(){if(!this.isOpen)return;if(this.isOpen=!1,c(this.element,"active"),this.overlay&&c(this.overlay,"active"),this.hamburger&&c(this.hamburger,"active"),this.options.push&&this.options.pushTarget){const e=t(this.options.pushTarget);e&&c(e,"sidebar-push","pushed","pushed-right")}const e=new CustomEvent("gumi-sidebar-close",{detail:{sidebar:this}});this.element.dispatchEvent(e)}toggle(){this.isOpen?this.close():this.open()}isOpened(){return this.isOpen}destroy(){if(r(document,"keydown",this.boundKeyHandler),r(document,"click",this.boundOutsideClickHandler),this.overlay&&this.overlay.remove(),c(this.element,"active"),this.hamburger&&c(this.hamburger,"active"),this.options.push&&this.options.pushTarget){const e=t(this.options.pushTarget);e&&c(e,"sidebar-push","pushed","pushed-right")}}static initFromAttributes(i="[data-sidebar]"){const s=e(i),n=[];return s.forEach((e=>{const i=e.getAttribute("data-sidebar");if(!i)return;const s=t(i);if(!s)return;if(s.__gumi_sidebar)return;const r={overlay:"false"!==e.getAttribute("data-overlay"),closeOnOutsideClick:"false"!==e.getAttribute("data-close-outside"),closeOnEscape:"false"!==e.getAttribute("data-close-escape"),push:"true"===e.getAttribute("data-push"),pushTarget:e.getAttribute("data-push-target")||"body"},o=new P(s,r);s.__gumi_sidebar=o,n.push(o)})),n}static init(e){const i=t(e);return i?new P(i):null}}class j{constructor(e,i={}){if(this.isVisible=!1,this.element=t(e),!this.element)throw new Error("Code element not found");this.options={copyText:"Copy",successText:"Copied!",errorText:"Failed to copy",showToast:!0,buttonClass:"code-copy-btn",iconClass:"copy-icon",...i},this.init()}init(){"static"===window.getComputedStyle(this.element).position&&(this.element.style.position="relative"),this.createButton(),this.bindEvents()}createButton(){this.button=s("button",{className:this.options.buttonClass,attributes:{title:this.options.copyText,"aria-label":this.options.copyText},html:`\n <svg class="${this.options.iconClass}" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>\n <path d="m5 15-1-1V6a2 2 0 0 1 2-2h8"></path>\n </svg>\n `}),this.element.appendChild(this.button),this.button.style.opacity="0",this.button.style.visibility="hidden"}bindEvents(){n(this.element,"mouseenter",(()=>{this.showButton()})),n(this.element,"mouseleave",(()=>{this.hideButton()})),n(this.button,"click",(t=>{t.preventDefault(),t.stopPropagation(),this.copyCode()}))}showButton(){this.isVisible||(this.isVisible=!0,this.button.style.visibility="visible",this.button.style.opacity="1")}hideButton(){this.isVisible&&(this.isVisible=!1,this.button.style.opacity="0",setTimeout((()=>{this.isVisible||(this.button.style.visibility="hidden")}),200))}async copyCode(){try{const t=this.getCodeText();navigator.clipboard&&window.isSecureContext?await navigator.clipboard.writeText(t):this.fallbackCopy(t),this.showSuccess()}catch(t){this.showError()}}getCodeText(){const t=this.element.cloneNode(!0),e=t.querySelector(`.${this.options.buttonClass}`);return e&&e.remove(),t.textContent||t.innerText||""}fallbackCopy(t){const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-999999px",e.style.top="-999999px",document.body.appendChild(e),e.focus(),e.select();try{document.execCommand("copy")}finally{document.body.removeChild(e)}}showSuccess(){l(this.button,"success"),this.options.showToast&&F.show(this.options.successText,{type:"success",duration:2e3}),setTimeout((()=>{c(this.button,"success")}),2e3)}showError(){l(this.button,"error"),this.options.showToast&&F.show(this.options.errorText,{type:"error",duration:2e3}),setTimeout((()=>{c(this.button,"error")}),2e3)}destroy(){this.button&&this.button.remove()}static initAll(t="pre, code, .code-block"){const i=e(t),s=[];return i.forEach((t=>{var e;if(t.__gumi_code_copy)return;if("code"===t.tagName.toLowerCase()&&"pre"!==(null===(e=t.parentElement)||void 0===e?void 0:e.tagName.toLowerCase()))return;const i=new j(t);t.__gumi_code_copy=i,s.push(i)})),s}}const N=new class{constructor(){this.version="1.0.0",this.modals=new Map,this.dropdowns=new Map,this.tabs=new Map,this.accordions=new Map,this.sidebars=new Map,this.$=t,this.$$=e,this.ready=i,this.on=n,this.off=r,this.trigger=o,this.createElement=s,this.animate=p,this.fadeIn=m,this.fadeOut=g,this.slideUp=y,this.slideDown=v,this.scaleIn=b,this.scaleOut=f,this.slideIn=w,this.bounce=x,this.shake=k,this.pulse=A,this.show=h,this.hide=d,this.toggle=u,this.debounce=C,this.throttle=T,this.copyToClipboard=L,this.icons=B,this.theme=new E,this.init()}init(){i((()=>{this.setupSmoothScroll(),this.setupFocusRings(),this.setupPreloadedAnimations(),this.initializeComponents(),console.log(`🍬 Gumi.js v${this.version} initialized`)}))}setupSmoothScroll(){n(document,"click",'a[href^="#"]',(e=>{e.preventDefault();const i=e.target.closest('a[href^="#"]');if(!i)return;const s=i.getAttribute("href");if(!s)return;const n=t(s);n&&n.scrollIntoView({behavior:"smooth",block:"start"})}))}setupFocusRings(){let t=!1;n(document,"keydown",(()=>{t=!0})),n(document,"mousedown",(()=>{t=!1})),n(document,"focusin",(e=>{t&&l(e.target,"gumi-focus-visible")})),n(document,"focusout",(t=>{c(t.target,"gumi-focus-visible")}))}setupPreloadedAnimations(){const t=new IntersectionObserver((e=>{e.forEach((e=>{if(e.isIntersecting){const i=e.target;i.classList.contains("gumi-fade-in")&&m(i),i.classList.contains("gumi-slide-up")&&(i.style.transform="translateY(30px)",i.style.opacity="0",p(i,[{transform:"translateY(30px)",opacity:0},{transform:"translateY(0)",opacity:1}],{duration:600})),i.classList.contains("gumi-slide-down")&&v(i),i.classList.contains("gumi-scale-in")&&b(i),t.unobserve(i)}}))}),{threshold:.1});e(".gumi-fade-in, .gumi-slide-up, .gumi-slide-down, .gumi-scale-in").forEach((e=>t.observe(e)))}initializeComponents(){M.initFromTriggers("[data-modal]").forEach((t=>{const e=t.element.id;e&&this.modals.set(e,t)})),$.initFromAttributes("[data-dropdown]").forEach((t=>{const e=O("dropdown");this.dropdowns.set(e,t)})),I.initAll(".tabs").forEach((t=>{const e=O("tabs");this.tabs.set(e,t)})),H.initAll(".accordion").forEach((t=>{const e=O("accordion");this.accordions.set(e,t)})),P.initFromAttributes("[data-sidebar]").forEach((t=>{const e=O("sidebar");this.sidebars.set(e,t)})),j.initAll("pre, .code-block"),this.setupSwitches()}setupSwitches(){e(".switch input").forEach((t=>{n(t,"change",(()=>{const e=new CustomEvent("gumi-switch-change",{detail:{checked:t.checked}});t.dispatchEvent(e)}))}))}setTheme(t){this.theme.setTheme(t)}toggleTheme(){this.theme.toggleTheme()}getTheme(){return this.theme.getTheme()}modal(i,s){const r=t(i);if(!r)return;const o=new M(r,s);this.modals.set(r.id||O("modal"),o);e(`[data-modal="${i}"]`).forEach((t=>{n(t,"click",(t=>{t.preventDefault(),o.open()}))}))}openModal(e){const i=t(e);if(!i)return;let s=Array.from(this.modals.values()).find((t=>t.element===i));s||(s=new M(i),this.modals.set(i.id||O("modal"),s)),s.open()}closeModal(e){const i=t(e);if(!i)return;const s=Array.from(this.modals.values()).find((t=>t.element===i));s&&s.close()}toast(t,e){return F.show(t,e)}setProgress(e,i){q.setProgress(e,i);const s=t(e);s&&s.setAttribute("data-progress",Math.round(i).toString())}validateForm(t){return D.validateForm(t)}dropdown(e,i,s){const n=t(e);if(!n)return;const r=i||n.getAttribute("data-dropdown");if(!r)return;const o=t(r);if(!o)return;const a=new $(n,o,s);this.dropdowns.set(O("dropdown"),a)}lazyLoad(t="img[data-src]"){const i=e(t),s=new IntersectionObserver((t=>{t.forEach((t=>{if(t.isIntersecting){const e=t.target,i=e.getAttribute("data-src");i&&(e.src=i,e.removeAttribute("data-src"),l(e,"gumi-loaded")),s.unobserve(e)}}))}));i.forEach((t=>s.observe(t)))}parallax(t,i={}){const s=e(t),r=i.speed||.5,o=()=>{const t=window.pageYOffset;s.forEach((e=>{const i=e.getBoundingClientRect(),s=i.top+t,n=window.innerHeight;if(i.bottom>=0&&i.top<=n){const i=(t-s)*r;e.style.transform=`translateY(${i}px)`}}))};n(window,"scroll",C(o,10)),o()}ripple(i){e(i).forEach((e=>{n(e,"click",(i=>{!function(e,i){const s=i?t(i):e.currentTarget;if(!s)return;const n=document.createElement("span"),r=s.getBoundingClientRect(),o=Math.max(r.width,r.height),a=e.clientX-r.left-o/2,l=e.clientY-r.top-o/2;n.style.cssText=`\n position: absolute;\n width: ${o}px;\n height: ${o}px;\n background: rgba(255, 255, 255, 0.5);\n border-radius: 50%;\n top: ${l}px;\n left: ${a}px;\n pointer-events: none;\n transform: scale(0);\n `,s.style.position="relative",s.style.overflow="hidden",s.appendChild(n),p(n,[{transform:"scale(0)",opacity:1},{transform:"scale(4)",opacity:0}],{duration:600}).then((()=>{n.remove()}))}(i,e)}))}))}loading(e,i=!0){const s=t(e);if(s)if(i){s.disabled=!0,s.setAttribute("data-loading","true");const t=s.innerHTML;s.setAttribute("data-original-content",t),s.innerHTML='<span class="spinner"></span> Loading...'}else{s.disabled=!1,s.removeAttribute("data-loading");const t=s.getAttribute("data-original-content");t&&(s.innerHTML=t,s.removeAttribute("data-original-content"))}}sidebar(t){return P.init(t)}openSidebar(e){const i=Array.from(this.sidebars.values()).find((i=>i.element===t(e)));i&&i.open()}closeSidebar(e){const i=Array.from(this.sidebars.values()).find((i=>i.element===t(e)));i&&i.close()}toggleSidebar(e){const i=Array.from(this.sidebars.values()).find((i=>i.element===t(e)));i&&i.toggle()}};"undefined"!=typeof window&&(window.gumi=N);export{H as Accordion,j as CodeCopy,$ as Dropdown,D as FormValidator,M as Modal,q as Progress,P as Sidebar,I as Tabs,E as ThemeManager,F as Toast,N as default};
//# sourceMappingURL=gumi.esm.min.js.map