vanilla-breeze 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +23012 -11383
- package/dist/cdn/components/accordion-wc.js +1 -1
- package/dist/cdn/components/activity-feed.js +1 -1
- package/dist/cdn/components/ai-chat.js +9 -6
- package/dist/cdn/components/ai-summary.js +4 -2
- package/dist/cdn/components/analytics-panel.js +19 -21
- package/dist/cdn/components/audio-player.js +17 -7
- package/dist/cdn/components/audio-visualizer.js +3 -3
- package/dist/cdn/components/author-index.js +2 -2
- package/dist/cdn/components/brand-mark.js +1 -1
- package/dist/cdn/components/bread-crumb.js +1 -1
- package/dist/cdn/components/calendar-wc.js +2 -2
- package/dist/cdn/components/card-list.js +1 -1
- package/dist/cdn/components/carousel-wc.js +1 -1
- package/dist/cdn/components/change-set.js +1 -11
- package/dist/cdn/components/chart-wc.js +32 -32
- package/dist/cdn/components/chat-input.js +1 -1
- package/dist/cdn/components/chat-window.js +1 -1
- package/dist/cdn/components/color-picker.js +1 -1
- package/dist/cdn/components/combo-box.js +1 -1
- package/dist/cdn/components/command-palette.js +1 -1
- package/dist/cdn/components/comment-box.js +50 -49
- package/dist/cdn/components/comment-thread.js +50 -49
- package/dist/cdn/components/comment-wc.js +1 -1
- package/dist/cdn/components/compare-surface.js +1 -1
- package/dist/cdn/components/consent-banner.js +1 -1
- package/dist/cdn/components/content-lens.js +1 -1
- package/dist/cdn/components/content-swap.js +1 -1
- package/dist/cdn/components/context-menu.js +1 -1
- package/dist/cdn/components/data-table.js +1 -1
- package/dist/cdn/components/date-picker.js +1 -1
- package/dist/cdn/components/day-view.js +1 -1
- package/dist/cdn/components/diagram-wc.js +2 -2
- package/dist/cdn/components/drag-surface.js +1 -1
- package/dist/cdn/components/drop-down.js +1 -1
- package/dist/cdn/components/emoji-picker.js +1 -1
- package/dist/cdn/components/flow-diagram.js +1 -1
- package/dist/cdn/components/foot-notes.js +1 -1
- package/dist/cdn/components/form-field.js +1 -1
- package/dist/cdn/components/geo-map.js +170 -54
- package/dist/cdn/components/glossary-index.js +1 -1
- package/dist/cdn/components/glossary-wc.js +1 -1
- package/dist/cdn/components/heading-links.js +1 -1
- package/dist/cdn/components/highlight-wc.js +6 -2
- package/dist/cdn/components/icon-wc.js +11 -10
- package/dist/cdn/components/image-gallery.js +1 -1
- package/dist/cdn/components/image-map.js +1 -1
- package/dist/cdn/components/include-file.js +1 -1
- package/dist/cdn/components/manifest.json +101 -101
- package/dist/cdn/components/markdown-editor.js +60 -1
- package/dist/cdn/components/markdown-viewer.js +50 -49
- package/dist/cdn/components/nav-bar.js +1 -1
- package/dist/cdn/components/note-wc.js +6 -2
- package/dist/cdn/components/notification-wc.js +33 -32
- package/dist/cdn/components/page-info.js +6 -72
- package/dist/cdn/components/page-stats.js +1 -1
- package/dist/cdn/components/page-toc.js +1 -1
- package/dist/cdn/components/page-tools.js +1 -1
- package/dist/cdn/components/page-tour.js +1 -38
- package/dist/cdn/components/pager-wc.js +1 -1
- package/dist/cdn/components/poll-wc.js +1 -1
- package/dist/cdn/components/pop-over.js +1 -1
- package/dist/cdn/components/popularity-index.js +1 -8
- package/dist/cdn/components/print-page.js +1 -1
- package/dist/cdn/components/progress-tracker.js +1 -1
- package/dist/cdn/components/qr-code.js +1 -1
- package/dist/cdn/components/reaction-bar.js +1 -1
- package/dist/cdn/components/reader-view.js +25 -25
- package/dist/cdn/components/reading-progress.js +1 -1
- package/dist/cdn/components/recently-visited.js +1 -26
- package/dist/cdn/components/score-card.js +21 -5
- package/dist/cdn/components/selection-menu.js +1 -1
- package/dist/cdn/components/settings-panel.js +88 -142
- package/dist/cdn/components/share-wc.js +2 -2
- package/dist/cdn/components/short-cuts.js +1 -1
- package/dist/cdn/components/site-index.js +1 -10
- package/dist/cdn/components/site-map.js +1 -1
- package/dist/cdn/components/site-search.js +1 -51
- package/dist/cdn/components/slide-accept.js +1 -1
- package/dist/cdn/components/social-embed.js +1 -1
- package/dist/cdn/components/split-surface.js +1 -1
- package/dist/cdn/components/star-rating.js +1 -1
- package/dist/cdn/components/status-wc.js +1 -1
- package/dist/cdn/components/stepper-wc.js +1 -1
- package/dist/cdn/components/tab-set.js +1 -1
- package/dist/cdn/components/text-reader.js +2 -2
- package/dist/cdn/components/theme-picker.js +84 -81
- package/dist/cdn/components/time-index.js +1 -11
- package/dist/cdn/components/time-picker.js +1 -1
- package/dist/cdn/components/toast-msg.js +6 -6
- package/dist/cdn/components/tool-tip.js +1 -1
- package/dist/cdn/components/topic-map.js +6 -3
- package/dist/cdn/components/trust-filter.js +1 -3
- package/dist/cdn/components/version-switcher.js +5 -15
- package/dist/cdn/components/video-player.js +67 -9
- package/dist/cdn/components/watch-wc.js +6 -2
- package/dist/cdn/components/week-view.js +1 -1
- package/dist/cdn/components/youtube-player.js +1 -1
- package/dist/cdn/emoji-extended.js +2 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-OFL.txt +93 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-400-italic.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-400-normal.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-700-italic.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-700-normal.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-ext-400-italic.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-ext-700-italic.woff2 +0 -0
- package/dist/cdn/fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2 +0 -0
- package/dist/cdn/fonts/latinmodern-math-GUST-LICENSE.txt +30 -0
- package/dist/cdn/fonts/latinmodern-math.woff2 +0 -0
- package/dist/cdn/fonts/math-fonts.css +14 -0
- package/dist/cdn/packs/effects.full.css +1 -1
- package/dist/cdn/packs/effects.full.js +1 -1
- package/dist/cdn/packs/fonts-display.full.css +1 -1
- package/dist/cdn/packs/fonts-display.theme.css +1 -1
- package/dist/cdn/packs/icons.bundle.js +1 -1
- package/dist/cdn/packs/icons.full.css +1 -1
- package/dist/cdn/packs/icons.theme.css +1 -1
- package/dist/cdn/packs/journal.effects.css +1 -1
- package/dist/cdn/packs/journal.full.css +1 -1
- package/dist/cdn/packs/kawaii.effects.css +1 -1
- package/dist/cdn/packs/kawaii.full.css +2 -2
- package/dist/cdn/packs/kawaii.full.js +6 -6
- package/dist/cdn/packs/kawaii.theme.css +1 -1
- package/dist/cdn/packs/manifest.json +17 -17
- package/dist/cdn/packs/memphis.full.css +1 -1
- package/dist/cdn/packs/memphis.theme.css +1 -1
- package/dist/cdn/packs/ui.full.css +1 -1
- package/dist/cdn/packs/ui.full.js +88 -85
- package/dist/cdn/themes/8bit.css +1 -1
- package/dist/cdn/themes/8bit.tokens.json +1 -1
- package/dist/cdn/themes/alpha1999-dark.tokens.json +1 -1
- package/dist/cdn/themes/alpha1999.css +1 -1
- package/dist/cdn/themes/alpha1999.tokens.json +1 -1
- package/dist/cdn/themes/art-deco-dark.tokens.json +33 -1
- package/dist/cdn/themes/art-deco.css +1 -1
- package/dist/cdn/themes/art-deco.tokens.json +23 -1
- package/dist/cdn/themes/bauhaus-dark.tokens.json +23 -1
- package/dist/cdn/themes/bauhaus.css +1 -1
- package/dist/cdn/themes/bauhaus.tokens.json +1 -1
- package/dist/cdn/themes/brutalist-dark.tokens.json +33 -1
- package/dist/cdn/themes/brutalist.css +1 -1
- package/dist/cdn/themes/brutalist.tokens.json +23 -1
- package/dist/cdn/themes/catppuccin-frappe.css +1 -1
- package/dist/cdn/themes/catppuccin-frappe.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-latte-dark.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-latte.css +1 -1
- package/dist/cdn/themes/catppuccin-latte.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-macchiato.css +1 -1
- package/dist/cdn/themes/catppuccin-macchiato.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-mocha.css +1 -1
- package/dist/cdn/themes/catppuccin-mocha.tokens.json +1 -1
- package/dist/cdn/themes/classic-dark.tokens.json +1 -1
- package/dist/cdn/themes/classic.css +1 -1
- package/dist/cdn/themes/classic.tokens.json +1 -1
- package/dist/cdn/themes/claymorphism-dark.tokens.json +33 -1
- package/dist/cdn/themes/claymorphism.css +1 -1
- package/dist/cdn/themes/claymorphism.tokens.json +24 -1
- package/dist/cdn/themes/clinical-dark.tokens.json +1 -1
- package/dist/cdn/themes/clinical.css +1 -1
- package/dist/cdn/themes/clinical.tokens.json +1 -1
- package/dist/cdn/themes/cottagecore-dark.tokens.json +1 -1
- package/dist/cdn/themes/cottagecore.css +1 -1
- package/dist/cdn/themes/cottagecore.tokens.json +1 -1
- package/dist/cdn/themes/cyber.css +1 -1
- package/dist/cdn/themes/cyber.tokens.json +1 -1
- package/dist/cdn/themes/dawn-dark.tokens.json +33 -1
- package/dist/cdn/themes/dawn.css +1 -1
- package/dist/cdn/themes/dawn.tokens.json +23 -1
- package/dist/cdn/themes/dracula.css +1 -1
- package/dist/cdn/themes/dracula.tokens.json +1 -1
- package/dist/cdn/themes/dusk.css +1 -1
- package/dist/cdn/themes/dusk.tokens.json +1 -1
- package/dist/cdn/themes/editorial-dark.tokens.json +1 -1
- package/dist/cdn/themes/editorial.css +1 -1
- package/dist/cdn/themes/editorial.tokens.json +1 -1
- package/dist/cdn/themes/financial-dark.tokens.json +1 -1
- package/dist/cdn/themes/financial.css +1 -1
- package/dist/cdn/themes/financial.tokens.json +1 -1
- package/dist/cdn/themes/genai.css +1 -1
- package/dist/cdn/themes/genai.tokens.json +1 -1
- package/dist/cdn/themes/glassmorphism-dark.tokens.json +1 -1
- package/dist/cdn/themes/glassmorphism.css +1 -1
- package/dist/cdn/themes/glassmorphism.tokens.json +1 -1
- package/dist/cdn/themes/government-dark.tokens.json +1 -1
- package/dist/cdn/themes/government.css +1 -1
- package/dist/cdn/themes/government.tokens.json +1 -1
- package/dist/cdn/themes/gruvbox-dark.tokens.json +1 -1
- package/dist/cdn/themes/gruvbox.css +1 -1
- package/dist/cdn/themes/gruvbox.tokens.json +1 -1
- package/dist/cdn/themes/high-noon-dark.tokens.json +23 -1
- package/dist/cdn/themes/high-noon.css +1 -1
- package/dist/cdn/themes/high-noon.tokens.json +1 -1
- package/dist/cdn/themes/journal-dark.tokens.json +36 -2
- package/dist/cdn/themes/journal.css +1 -1
- package/dist/cdn/themes/journal.tokens.json +26 -2
- package/dist/cdn/themes/kawaii-dark.tokens.json +1 -1
- package/dist/cdn/themes/kawaii.css +1 -1
- package/dist/cdn/themes/kawaii.tokens.json +1 -1
- package/dist/cdn/themes/magna-dark.tokens.json +1 -1
- package/dist/cdn/themes/magna.css +1 -1
- package/dist/cdn/themes/magna.tokens.json +1 -1
- package/dist/cdn/themes/manifest.json +44 -68
- package/dist/cdn/themes/midnight.css +1 -1
- package/dist/cdn/themes/midnight.tokens.json +1 -1
- package/dist/cdn/themes/minimal-dark.tokens.json +1 -1
- package/dist/cdn/themes/minimal.css +1 -1
- package/dist/cdn/themes/minimal.tokens.json +1 -1
- package/dist/cdn/themes/modern-dark.tokens.json +1 -1
- package/dist/cdn/themes/modern.css +1 -1
- package/dist/cdn/themes/modern.tokens.json +1 -1
- package/dist/cdn/themes/nes-dark.tokens.json +7 -2
- package/dist/cdn/themes/nes.css +1 -1
- package/dist/cdn/themes/nes.tokens.json +1 -1
- package/dist/cdn/themes/neumorphism-dark.tokens.json +1 -1
- package/dist/cdn/themes/neumorphism.css +1 -1
- package/dist/cdn/themes/neumorphism.tokens.json +1 -1
- package/dist/cdn/themes/nord-dark.tokens.json +33 -1
- package/dist/cdn/themes/nord.css +1 -1
- package/dist/cdn/themes/nord.tokens.json +23 -1
- package/dist/cdn/themes/organic-dark.tokens.json +1 -1
- package/dist/cdn/themes/organic.css +1 -1
- package/dist/cdn/themes/organic.tokens.json +1 -1
- package/dist/cdn/themes/rose-pine-dark.tokens.json +1 -1
- package/dist/cdn/themes/rose-pine.css +1 -1
- package/dist/cdn/themes/rose-pine.tokens.json +1 -1
- package/dist/cdn/themes/rough-dark.tokens.json +1 -1
- package/dist/cdn/themes/rough.css +1 -1
- package/dist/cdn/themes/rough.tokens.json +1 -1
- package/dist/cdn/themes/solarized-dark.tokens.json +23 -1
- package/dist/cdn/themes/solarized.css +1 -1
- package/dist/cdn/themes/solarized.tokens.json +23 -1
- package/dist/cdn/themes/startup-dark.tokens.json +1 -1
- package/dist/cdn/themes/startup.css +1 -1
- package/dist/cdn/themes/startup.tokens.json +1 -1
- package/dist/cdn/themes/super2026-dark.tokens.json +33 -1
- package/dist/cdn/themes/super2026.css +1 -1
- package/dist/cdn/themes/super2026.tokens.json +23 -1
- package/dist/cdn/themes/swiss-dark.tokens.json +1 -1
- package/dist/cdn/themes/swiss.css +1 -1
- package/dist/cdn/themes/swiss.tokens.json +1 -1
- package/dist/cdn/themes/terminal.css +1 -1
- package/dist/cdn/themes/terminal.tokens.json +1 -1
- package/dist/cdn/themes/tokyo-night-dark.tokens.json +33 -1
- package/dist/cdn/themes/tokyo-night.css +1 -1
- package/dist/cdn/themes/tokyo-night.tokens.json +23 -1
- package/dist/cdn/themes/vaporwave-dark.tokens.json +33 -1
- package/dist/cdn/themes/vaporwave.css +1 -1
- package/dist/cdn/themes/vaporwave.tokens.json +23 -1
- package/dist/cdn/themes/win9x-dark.tokens.json +20 -5
- package/dist/cdn/themes/win9x.css +1 -1
- package/dist/cdn/themes/win9x.tokens.json +3 -1
- package/dist/cdn/vanilla-breeze-autoload.js +553 -0
- package/dist/cdn/vanilla-breeze-charts.css +1 -1
- package/dist/cdn/vanilla-breeze-charts.js +32 -32
- package/dist/cdn/vanilla-breeze-core.css +1 -1
- package/dist/cdn/vanilla-breeze-core.js +183 -281
- package/dist/cdn/vanilla-breeze-dev.css +1 -1
- package/dist/cdn/vanilla-breeze-dev.js +1 -1
- package/dist/cdn/vanilla-breeze-extras.js +286 -134
- package/dist/cdn/vanilla-breeze.css +1 -1
- package/dist/cdn/vanilla-breeze.js +574 -656
- package/dist/cdn/view-transitions.css +2 -0
- package/package.json +17 -9
- package/dist/cdn/themes/amber.css +0 -2
- package/dist/cdn/themes/anthropic.css +0 -2
- package/dist/cdn/themes/anthropic.tokens.json +0 -564
- package/dist/cdn/themes/coral.css +0 -2
- package/dist/cdn/themes/emerald.css +0 -2
- package/dist/cdn/themes/forest.css +0 -2
- package/dist/cdn/themes/ibm.css +0 -2
- package/dist/cdn/themes/ibm.tokens.json +0 -568
- package/dist/cdn/themes/indigo.css +0 -2
- package/dist/cdn/themes/lavender.css +0 -2
- package/dist/cdn/themes/mcdonalds.css +0 -2
- package/dist/cdn/themes/mcdonalds.tokens.json +0 -533
- package/dist/cdn/themes/ocean.css +0 -2
- package/dist/cdn/themes/rose.css +0 -2
- package/dist/cdn/themes/slate.css +0 -2
- package/dist/cdn/themes/starbucks.css +0 -2
- package/dist/cdn/themes/starbucks.tokens.json +0 -593
- package/dist/cdn/themes/sunset.css +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function b(o){if(!o||typeof o!="string")return"";let t=document.createElement("template");return t.innerHTML=o,t.content.querySelectorAll("script, iframe, object, embed, form, base, link, meta, noscript").forEach(n=>n.remove()),t.content.querySelectorAll("*").forEach(n=>{for(let i of[...n.attributes]){if(i.name.startsWith("on")){n.removeAttribute(i.name);continue}if(["href","src","action","formaction","xlink:href"].includes(i.name)){let r=i.value.trim().toLowerCase();(r.startsWith("javascript:")||r.startsWith("data:text/html"))&&n.removeAttribute(i.name);continue}(i.name==="srcdoc"||i.name==="data"&&n.tagName==="OBJECT")&&n.removeAttribute(i.name)}}),t.innerHTML}var C=window.matchMedia("(prefers-reduced-motion: reduce)");var E=new Map;function A(o,t,e={}){let s=e.priority??10,n={impl:t,bundle:e.bundle,contract:e.contract,priority:s},i=E.get(o);if(customElements.get(o)){if(!i||i.priority>=s){i&&i.priority===s&&i.impl!==t&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${i.bundle}" (priority ${i.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${o}> defined by "${i.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(i&&i.priority>=s){i.priority===s&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${i.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}E.set(o,n),customElements.define(o,t)}var m=class extends HTMLElement{#t=[];#e;connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#t)t();this.#t=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,s,n){t.addEventListener(e,s,n),this.#t.push(()=>t.removeEventListener(e,s,n))}setup(){}teardown(){}setState(t,e){this.#e||(this.#e=this.attachInternals());let s=this.#e.states;try{e?s.add(t):s.delete(t)}catch{let n=`--${t}`;e?s.add(n):s.delete(n)}}_adoptInternals(t){this.#e||(this.#e=t)}};function v({newItems:o,nodes:t,keyOf:e,renderItem:s,containerFor:n}){let i=[],r=[],l=[],y=new Set;for(let a of o)y.add(e(a));for(let[a,d]of[...t])y.has(a)||(d.remove(),t.delete(a),l.push(a));let f=new Map;for(let a of o){let d=e(a),c=t.get(d)||null,h=n(a,c);f.has(h)||f.set(h,[]),f.get(h)?.push({item:a,key:d,existing:c})}for(let[a,d]of f)for(let c=0;c<d.length;c++){let{item:h,key:p,existing:M}=d[c],u=M;u?(u.parentElement!==a||a.children[c]!==u)&&r.push(p):(u=s(h),t.set(p,u),i.push(p));let w=a.children[c];w!==u&&a.insertBefore(u,w||null)}return{added:i,moved:r,removed:l}}var g=class extends m{#t=null;#e=null;#s=null;#n=new Map;#i=null;#u=new Map;setup(){this.#h(),this.#f(),this.#p(),this.#l(),this.#o(),this.#m()}teardown(){}#h(){this.#t=this.querySelector(":scope > chat-thread"),this.#e=this.querySelector(":scope > chat-input"),this.#s=this.querySelector(":scope > header select[data-model-select]")}#f(){let t=this.querySelector(":scope > script[data-participants]");if(t)try{let e=JSON.parse(t.textContent);this.#n=new Map(Object.entries(e))}catch{console.warn("[chat-window] Invalid participant JSON")}}#l(){if(this.#t)for(let t of this.#t.querySelectorAll("chat-message[data-from]"))this.#a(t)}#a(t){let e=t.getAttribute("data-from");if(!e)return;let s=this.#n.get(e);s?.name?t.setAttribute("data-from-label",s.name):t.hasAttribute("data-from-label")||t.setAttribute("data-from-label",e)}#p(){if(!this.#s)return;let t=this.getAttribute("model");t?this.#s.value=t:this.#s.value&&this.setAttribute("model",this.#s.value)}#m(){this.listen(this,"chat-input:send",this.#b),this.#s&&this.listen(this.#s,"change",this.#g)}#b=async t=>{t.stopPropagation();let{message:e}=t.detail;if(!e||!this.#t)return;let s=this.#c("user",e,"user");this.#t.appendChild(s),this.#r(),this.#o();let n=this.#w(),i=this.#y(n);this.#t.appendChild(i),this.#r(),this.#e&&(this.#e.disabled=!0);let r=this.getAttribute("endpoint");if(r)try{let l=await this.#E(r,e);this.#d(i,l)}catch(l){this.#d(i,"<p>Sorry, something went wrong.</p>"),i.setAttribute("data-status","error"),this.dispatchEvent(new CustomEvent("chat-window:error",{bubbles:!0,detail:{error:l.message,status:l.status??0}}))}else this.dispatchEvent(new CustomEvent("chat-window:send",{bubbles:!0,detail:{message:e,typingElement:i}}));this.#e&&(this.#e.disabled=!1,this.#e.focus()),this.#r()};#g=()=>{let t=this.#s.value;this.setAttribute("model",t),this.dispatchEvent(new CustomEvent("chat-window:model-change",{bubbles:!0,detail:{model:t}}))};#c(t,e,s){let n=document.createElement("chat-message");n.setAttribute("data-role",t),s&&(n.setAttribute("data-from",s),this.#a(n));let i=document.createElement("chat-bubble");if(e.includes("<"))i.innerHTML=b(e);else{let r=document.createElement("p");r.textContent=e,i.appendChild(r)}return n.appendChild(i),n}#y(t){let e=document.createElement("chat-message");if(e.setAttribute("data-role","agent"),e.setAttribute("data-status","typing"),t){e.setAttribute("data-from",t),this.#a(e);let r=this.#n.get(t)?.name??t;e.setAttribute("aria-label",`${r} is typing`)}else e.setAttribute("aria-label","Agent is typing");let s=this.getAttribute("model");s&&e.setAttribute("data-model",s);let n=document.createElement("chat-bubble");return e.appendChild(n),e}#d(t,e){let s=t.querySelector("chat-bubble");s&&(s.innerHTML=b(e)),t.removeAttribute("data-status"),t.removeAttribute("aria-label")}#w(){for(let[t,e]of this.#n)if(e.role==="agent")return t;return null}#o(){if(!this.#t)return;this.#t.querySelector("chat-message")!==null?(this.#i&&(this.#i.remove(),this.#i=null),this.#t.hidden=!1):(this.#t.hidden=!0,this.#i||(this.#i=document.createElement("p"),this.#i.setAttribute("data-chat-empty",""),this.#i.textContent=this.getAttribute("empty-message")||"Send a message to start.",this.#t.insertAdjacentElement("afterend",this.#i)))}#r(){this.#t&&requestAnimationFrame(()=>{this.#t.scrollTop=this.#t.scrollHeight})}scrollToBottom(){this.#r()}async#E(t,e){let s={message:e,model:this.getAttribute("model")||void 0},n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!n.ok){let r=new Error(`Chat request failed: ${n.status}`);throw r.status=n.status,r}let i=await n.json();return i.html??i.message??i.content??""}get model(){return this.getAttribute("model")??""}set model(t){this.setAttribute("model",t),this.#s&&(this.#s.value=t)}get participants(){return this.#n}set participants(t){this.#n=t instanceof Map?t:new Map(Object.entries(t)),this.#l()}clearThread(){if(this.#t){for(;this.#t.firstChild;)this.#t.removeChild(this.#t.firstChild);this.#o()}}appendMessage(t,e,s){if(!this.#t)return;let n=this.#c(t,e,s);this.#t.appendChild(n),this.#r(),this.#o()}get messages(){return this.#t?[...this.#t.querySelectorAll(':scope > chat-message:not([data-status="typing"])')].map(t=>({id:t.id||t.getAttribute("data-id")||void 0,role:t.getAttribute("data-role")||"user",content:t.querySelector("chat-bubble")?.innerHTML||"",from:t.getAttribute("data-from")||void 0})):[]}set messages(t){if(!this.#t)return;let e=Array.isArray(t)?t:[];v({newItems:e,nodes:this.#u,keyOf:s=>s.id??s.role+":"+s.content,renderItem:s=>{let n=this.#c(s.role||"user",s.content||"",s.from);return s.id&&(n.id=s.id),n},containerFor:()=>this.#t}),this.#o(),this.#r(),this.dispatchEvent(new CustomEvent("chat-window:messages-changed",{detail:{messages:e,source:"property"},bubbles:!0}))}};A("chat-window",g);export{g as ChatWindow};
|
|
1
|
+
var $="http://www.w3.org/1999/xhtml",g="http://www.w3.org/2000/svg",R="http://www.w3.org/1998/Math/MathML",_=new Set([$,g,R]),y="user-content-",I=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","form","base","link","meta","noscript","foreignobject","style","xmp","noembed","noframes","plaintext","mglyph","malignmark","annotation-xml"]),S=new Set(["title","desc"]),O=new Set(["animate","set","animatemotion","animatetransform"]),q=new Set(["href","xlink:href","action","formaction","data","codebase","cite","background","longdesc","manifest","to","from","values","by"]),B=new Set(["src","poster","srcset"]),D=new Set(["srcdoc","form","formaction","formmethod","formtarget","formenctype","formnovalidate","action","method","ping"]),j=new Set(["popovertarget","popovertargetaction","commandfor","command","interestfor","autofocus"]),F=new Set(["for","headers","list","aria-labelledby","aria-describedby","aria-controls","aria-owns","aria-flowto","aria-details","aria-errormessage","aria-activedescendant"]),U={"include-file":["trusted","allow-scripts","allow-cross-origin"],"markdown-viewer":["src","sanitize","ping","allow-cross-origin"]},V=new Set(["social-embed","youtube-player","geo-map"]),H=["src","src-dark","data-src","url","endpoint","tile-url","data-versions"],z=new Set(["audio-player","video-player","image-map","brand-mark"]);function P(i){return String(i).replace(/[\u0000- \u007f-\u009f]/g,"").toLowerCase()}function A(i,t=!1){let e=P(i);return t?/(^|,)(javascript|vbscript|livescript):/.test(e)?!0:/(^|,)data:/.test(e)?e.split(/(?=data:)/).filter(n=>n.startsWith("data:")).some(n=>!/^data:(image|audio|video|font)\//.test(n)):!1:/^(javascript|vbscript|livescript|data):/.test(e)}function E(i){let t=String(i).replace(/\/\*[\s\S]*?\*\//g,"").replace(/\\/g,"").replace(/\s+/g,"").toLowerCase();return/expression\(|javascript:|vbscript:|-moz-binding|behavior:|@import|position:fixed/.test(t)}var W=i=>String(i.localName||i.tagName||"").toLowerCase(),G=i=>i.startsWith(y)?i:y+i;function K(i,t){if(I.has(t))return!0;let e=i.namespaceURI;return!!(e&&!_.has(e)||t==="title"&&e!==g||S.has(t)&&e===g&&i.children?.length||O.has(t)&&(i.getAttribute("attributeName")||i.getAttribute("attributename")||"").toLowerCase().includes("href"))}function J(i,t){for(let e of[...i.attributes]){let s=e.name.toLowerCase();if(s.startsWith("on")||D.has(s)||!t.keepIds&&j.has(s)){i.removeAttribute(e.name);continue}if(s==="style"){(!t.keepStyle||E(e.value))&&i.removeAttribute(e.name);continue}if((s==="id"||s==="name")&&!t.keepIds){let n=G(e.value);s==="id"?t.ids.set(e.value,n):t.ids.set(`name:${e.value}`,n),i.setAttribute(e.name,n);continue}if(q.has(s)||s.endsWith(":href")){A(e.value,!1)&&i.removeAttribute(e.name);continue}B.has(s)&&A(e.value,!0)&&i.removeAttribute(e.name)}}function X(i,t){let e=(i.getAttribute("type")||"").toLowerCase();t==="button"&&e!=="button"&&i.setAttribute("type","button"),t==="input"&&/^(submit|reset|image)$/.test(e)&&i.setAttribute("type","button")}function Y(i,t){for(let e of i)for(let s of[...e.attributes]){let n=s.name.toLowerCase(),r=s.value;if((n==="href"||n.endsWith(":href"))&&r.startsWith("#")){let o=Q(r.slice(1));t.has(o)&&e.setAttribute(s.name,`#${t.get(o)}`)}else if(n==="usemap"&&r.startsWith("#")){let o=t.get(`name:${r.slice(1)}`);o?e.setAttribute(s.name,`#${o}`):e.removeAttribute(s.name)}else if(F.has(n)){let o=r.split(/\s+/).filter(Boolean).map(a=>t.get(a)||(a.startsWith(y)?a:null)).filter(Boolean);o.length?e.setAttribute(s.name,o.join(" ")):e.removeAttribute(s.name)}else r.includes("url(#")&&e.setAttribute(s.name,r.replace(/url\(#([^)]+)\)/g,(o,a)=>t.has(a)?`url(#${t.get(a)})`:o))}}function Q(i){try{return decodeURIComponent(i)}catch{return i}}function T(i){let t=i.childNodes;if(t)for(let e of[...t])e.nodeType===8?e.remove():(e.nodeType===1||e.nodeType===11)&&T(e)}function M(i,t){T(i);let e=[...i.querySelectorAll("*")];t.includeRoot&&e.unshift(i);let s=new Map,n=[],r={...t,ids:s};for(let o of e){if(!tt(o,i))continue;let a=W(o);if(t.svgOnly&&(S.has(a)||a==="style")){if(a==="style"&&E(o.textContent||"")){o.remove();continue}}else if(K(o,a)){o.remove();continue}if(!t.keepIds&&!t.svgOnly&&V.has(a)){Z(o);continue}if(a==="template"){let l=o.content;l&&M(l,{...t,includeRoot:!1})}J(o,r),t.keepIds||X(o,a);let u=U[a];if(u)for(let l of u)o.removeAttribute(l);if(a==="include-file"&&!t.allowIncludeFile&&o.removeAttribute("src"),!t.keepIds&&!t.svgOnly&&a.includes("-")&&a!=="include-file"&&!z.has(a))for(let l of H)o.removeAttribute(l);n.push(o)}!t.keepIds&&s.size&&Y(n,s)}function Z(i){let t=i.parentNode;if(t){for(let e of[...i.childNodes])t.insertBefore(e,i);i.remove()}}function tt(i,t){let e=i;for(;e;){if(e===t)return!0;e=e.parentNode??e.parent??null}return!1}function C(i,t={}){let e=document.createElement("template");return i&&typeof i=="string"&&(e.innerHTML=i,M(e.content,{allowIncludeFile:!!t.allowIncludeFile,keepIds:!!t.keepIds,keepStyle:!!t.keepStyle})),e.content}var nt=window.matchMedia("(prefers-reduced-motion: reduce)");var N=new Map;function k(i,t,e={}){let s=e.priority??10,n={impl:t,bundle:e.bundle,contract:e.contract,priority:s},r=N.get(i);if(customElements.get(i)){if(!r||r.priority>=s){r&&r.priority===s&&r.impl!==t&&console.warn(`[VB Bundle] Tag <${i}> already registered by "${r.bundle}" (priority ${r.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${i}> defined by "${r.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(r&&r.priority>=s){r.priority===s&&console.warn(`[VB Bundle] Tag <${i}> already registered by "${r.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}N.set(i,n),customElements.define(i,t)}var b=class extends HTMLElement{#t=[];#n;constructor(){super(),this.hasAttribute("data-upgraded")&&this.removeAttribute("data-upgraded")}connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#t)t();this.#t=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,s,n){t.addEventListener(e,s,n),this.#t.push(()=>t.removeEventListener(e,s,n))}_reinit(){for(let t of this.#t)t();this.#t=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(t,e){this.#n||(this.#n=this.attachInternals());let s=this.#n.states;try{e?s.add(t):s.delete(t)}catch{let n=`--${t}`;e?s.add(n):s.delete(n)}}_adoptInternals(t){this.#n||(this.#n=t)}#e(){return this.constructor.formAssociated&&this.#n?this.#n:null}get validity(){return this.#e()?.validity}get validationMessage(){return this.#e()?.validationMessage??""}get willValidate(){return this.#e()?.willValidate??!1}get form(){return this.#e()?.form??null}checkValidity(){return this.#e()?.checkValidity()??!0}reportValidity(){return this.#e()?.reportValidity()??!0}};function x({newItems:i,nodes:t,keyOf:e,renderItem:s,containerFor:n}){let r=[],o=[],a=[],u=new Set;for(let c of i)u.add(e(c));for(let[c,f]of[...t])u.has(c)||(f.remove(),t.delete(c),a.push(c));let l=new Map;for(let c of i){let f=e(c),d=t.get(f)||null,m=n(c,d);l.has(m)||l.set(m,[]),l.get(m)?.push({item:c,key:f,existing:d})}for(let[c,f]of l)for(let d=0;d<f.length;d++){let{item:m,key:p,existing:L}=f[d],h=L;h?(h.parentElement!==c||c.children[d]!==h)&&o.push(p):(h=s(m),t.set(p,h),r.push(p));let v=c.children[d];v!==h&&c.insertBefore(h,v||null)}return{added:r,moved:o,removed:a}}var w=class extends b{#t=null;#n=null;#e=null;#r=new Map;#s=null;#o=new Map;#c=new Set;setup(){this.#h(),this.#m(),this.#p(),this.#d(),this.#a(),this.#b()}teardown(){for(let t of this.#c)t.abort();this.#c.clear()}#h(){this.#t=this.querySelector(":scope > chat-thread"),this.#n=this.querySelector(":scope > chat-input"),this.#e=this.querySelector(":scope > header select[data-model-select]")}#m(){let t=this.querySelector(":scope > script[data-participants]");if(t)try{let e=JSON.parse(t.textContent);this.#r=new Map(Object.entries(e))}catch{console.warn("[chat-window] Invalid participant JSON")}}#d(){if(this.#t)for(let t of this.#t.querySelectorAll("chat-message[data-from]"))this.#l(t)}#l(t){let e=t.getAttribute("data-from");if(!e)return;let s=this.#r.get(e);s?.name?t.setAttribute("data-from-label",s.name):t.hasAttribute("data-from-label")||t.setAttribute("data-from-label",e)}#p(){if(!this.#e)return;let t=this.getAttribute("model");t?this.#e.value=t:this.#e.value&&this.setAttribute("model",this.#e.value)}#b(){this.listen(this,"chat-input:send",this.#g),this.#e&&this.listen(this.#e,"change",this.#y)}#g=async t=>{t.stopPropagation();let{message:e}=t.detail;if(!e||!this.#t)return;let s=this.#u("user",e,"user");this.#t.appendChild(s),this.#i(),this.#a();let n=this.#v(),r=this.#w(n);this.#t.appendChild(r),this.#i(),this.#n&&(this.#n.disabled=!0);let o=this.getAttribute("endpoint");if(o){let a=new AbortController;this.#c.add(a);try{let u=await this.#A(o,e,a.signal);this.resolveTyping(r,u)}catch(u){a.signal.aborted?r.remove():(this.resolveTyping(r,"<p>Sorry, something went wrong.</p>",{error:!0}),this.dispatchEvent(new CustomEvent("chat-window:error",{bubbles:!0,detail:{error:u.message,status:u.status??0}})))}finally{this.#c.delete(a)}}else this.dispatchEvent(new CustomEvent("chat-window:send",{bubbles:!0,detail:{message:e,typingElement:r}}));this.#n&&(this.#n.disabled=!1,this.isConnected&&this.#n.focus()),this.#i(),this.#a()};#y=()=>{let t=this.#e.value;this.setAttribute("model",t),this.dispatchEvent(new CustomEvent("chat-window:model-change",{bubbles:!0,detail:{model:t}}))};#u(t,e,s){let n=document.createElement("chat-message");n.setAttribute("data-role",t),s&&(n.setAttribute("data-from",s),this.#l(n));let r=document.createElement("chat-bubble");return this.#f(r,e,{asText:t==="user"}),n.appendChild(r),n}#f(t,e,{asText:s=!1}={}){let n=e==null?"":String(e);if(s||!n.includes("<")){let r=document.createElement("p");r.textContent=n,t.replaceChildren(r)}else t.replaceChildren(C(n))}#w(t){let e=document.createElement("chat-message");e.setAttribute("data-role","agent"),e.setAttribute("data-status","typing");let s="Agent";t&&(e.setAttribute("data-from",t),this.#l(e),s=this.#r.get(t)?.name??t);let n=this.getAttribute("model");n&&e.setAttribute("data-model",n);let r=document.createElement("chat-bubble"),o=document.createElement("span");return o.className="visually-hidden",o.setAttribute("data-chat-typing",""),o.textContent=`${s} is typing`,r.appendChild(o),e.appendChild(r),e}#v(){for(let[t,e]of this.#r)if(e.role==="agent")return t;return null}#a(){if(!this.#t)return;if(this.#t.querySelector(":scope > chat-message")!==null){this.#s?.remove(),this.#s=null;return}this.#s||(this.#s=this.#t.querySelector(":scope > [data-chat-empty]")),this.#s||(this.#s=document.createElement("p"),this.#s.setAttribute("data-chat-empty",""),this.#s.textContent=this.getAttribute("empty-message")||"Send a message to start."),this.#s.parentNode!==this.#t&&this.#t.prepend(this.#s)}#i(){this.#t&&requestAnimationFrame(()=>{this.#t.scrollTop=this.#t.scrollHeight})}scrollToBottom(){this.#i()}async#A(t,e,s){let n={message:e,model:this.getAttribute("model")||void 0},r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n),signal:s});if(!r.ok){let a=new Error(`Chat request failed: ${r.status}`);throw a.status=r.status,a}let o=await r.json();return o.html??o.message??o.content??""}get model(){return this.getAttribute("model")??""}set model(t){this.setAttribute("model",t),this.#e&&(this.#e.value=t)}get participants(){return this.#r}set participants(t){this.#r=t instanceof Map?t:new Map(Object.entries(t)),this.#d()}clearThread(){if(this.#t){for(;this.#t.firstChild;)this.#t.removeChild(this.#t.firstChild);this.#a()}}appendMessage(t,e,s){if(!this.#t)return;let n=this.#u(t,e,s);return this.#t.appendChild(n),this.#i(),this.#a(),n}resolveTyping(t,e,{error:s=!1}={}){if(!t)return;let n=t.querySelector(":scope > chat-bubble");n||(n=document.createElement("chat-bubble"),t.appendChild(n)),this.#f(n,e),t.removeAttribute("aria-label"),s?t.setAttribute("data-status","error"):t.removeAttribute("data-status"),this.#i()}get messages(){return this.#t?[...this.#t.querySelectorAll(':scope > chat-message:not([data-status="typing"])')].map(t=>{let e=t.getAttribute("data-role")||"user",s=t.querySelector("chat-bubble");return{id:t.id||t.getAttribute("data-id")||void 0,role:e,content:(e==="user"?s?.textContent?.trim():s?.innerHTML)||"",from:t.getAttribute("data-from")||void 0}}):[]}set messages(t){if(!this.#t)return;let e=Array.isArray(t)?t:[];for(let[n,r]of this.#o)r.parentNode!==this.#t&&this.#o.delete(n);let s=new Set(this.#o.values());for(let n of[...this.#t.children])if(!s.has(n)){if(n.localName==="chat-message"&&n.id&&!n.matches('[data-status="typing"]')&&!this.#o.has(n.id)){this.#o.set(n.id,n);continue}n===this.#s&&(this.#s=null),n.remove()}x({newItems:e,nodes:this.#o,keyOf:n=>n.id??n.role+":"+n.content,renderItem:n=>{let r=this.#u(n.role||"user",n.content||"",n.from);return n.id&&(r.id=n.id),r},containerFor:()=>this.#t}),this.#a(),this.#i(),this.dispatchEvent(new CustomEvent("chat-window:messages-changed",{detail:{messages:e,source:"property"},bubbles:!0}))}};k("chat-window",w);export{w as ChatWindow};
|
|
2
2
|
//# sourceMappingURL=chat-window.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var tt=window.matchMedia("(prefers-reduced-motion: reduce)");var $=new Map;function D(i,t,e={}){let s=e.priority??10,n={impl:t,bundle:e.bundle,contract:e.contract,priority:s},o=$.get(i);if(customElements.get(i)){if(!o||o.priority>=s){o&&o.priority===s&&o.impl!==t&&console.warn(`[VB Bundle] Tag <${i}> already registered by "${o.bundle}" (priority ${o.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${i}> defined by "${o.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(o&&o.priority>=s){o.priority===s&&console.warn(`[VB Bundle] Tag <${i}> already registered by "${o.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}$.set(i,n),customElements.define(i,t)}var y=class extends HTMLElement{#d=[];#r;connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#d)t();this.#d=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,s,n){t.addEventListener(e,s,n),this.#d.push(()=>t.removeEventListener(e,s,n))}setup(){}teardown(){}setState(t,e){this.#r||(this.#r=this.attachInternals());let s=this.#r.states;try{e?s.add(t):s.delete(t)}catch{let n=`--${t}`;e?s.add(n):s.delete(n)}}_adoptInternals(t){this.#r||(this.#r=t)}};var F="popover"in HTMLElement.prototype;var A="[data-copy], [data-copy-target], [data-paste-target]",_="Copied to clipboard",B="Pasted from clipboard",C=new WeakMap;async function T(i,t={}){if(i==null||i==="")return!1;let{button:e,announceMessage:s=_,duration:n=1500}=t;try{await navigator.clipboard.writeText(i)}catch{return!1}return P({button:e,duration:n,announceMessage:s,eventDetail:{text:i}}),!0}function P({button:i,duration:t,announceMessage:e,eventDetail:s,state:n="copied",eventName:o="copy"}){if(i){i.dataset.state=n;let a=C.get(i);a&&clearTimeout(a),C.set(i,setTimeout(()=>{delete i.dataset.state,C.delete(i)},t)),i.dispatchEvent(new CustomEvent(o,{bubbles:!0,detail:s}))}V(e,i??document.body)}async function U(i,t={}){let{button:e,announceMessage:s=B,duration:n=1500}=t,o;try{o=await navigator.clipboard.readText()}catch{return null}return i&&("value"in i&&(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)?i.value=o:i.textContent=o,i.dispatchEvent(new Event("input",{bubbles:!0}))),P({button:e,duration:n,announceMessage:s,eventDetail:{text:o},state:"pasted",eventName:"paste"}),o}function O(i=document){i.querySelectorAll(A).forEach(k)}function k(i){i.hasAttribute("data-copy-init")||(i.setAttribute("data-copy-init",""),i.addEventListener("click",()=>{if(i.dataset.pasteTarget){let e=document.querySelector(i.dataset.pasteTarget);if(!e)return;U(e,{button:i});return}let t=q(i);t&&T(t,{button:i})}))}function q(i){if(i.dataset.copy)return i.dataset.copy;if(i.dataset.copyTarget){let t=document.querySelector(i.dataset.copyTarget);if(!t)return"";let e=i.dataset.copyAttr;return e?t.getAttribute(e)??"":t.textContent??""}return""}function V(i,t){let e=document.createElement("div");e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.className="visually-hidden",e.textContent=i,t.appendChild(e),setTimeout(()=>e.remove(),1e3)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>O()):O();var j=new MutationObserver(i=>{for(let t of i)for(let e of t.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;let s=e;s.matches(A)&&k(s),s.querySelectorAll(A).forEach(n=>k(n))}});j.observe(document.documentElement,{childList:!0,subtree:!0});function b(i,t,e){t/=100,e/=100;let s=a=>(a+i/30)%12,n=t*Math.min(e,1-e),o=a=>e-n*Math.max(-1,Math.min(s(a)-3,9-s(a),1));return{r:Math.round(o(0)*255),g:Math.round(o(8)*255),b:Math.round(o(4)*255)}}function E(i,t,e){i/=255,t/=255,e/=255;let s=Math.max(i,t,e),n=Math.min(i,t,e),o=(s+n)/2,a=0,h=0;if(s!==n){let r=s-n;switch(h=o>.5?r/(2-s-n):r/(s+n),s){case i:a=((t-e)/r+(t<e?6:0))/6;break;case t:a=((e-i)/r+2)/6;break;case e:a=((i-t)/r+4)/6;break}}return{h:Math.round(a*360),s:Math.round(h*100),l:Math.round(o*100)}}function G(i){i=i.replace(/^#/,""),i.length===3&&(i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]);let t=parseInt(i,16);return{r:t>>16&255,g:t>>8&255,b:t&255}}function K(i,t,e){return"#"+[i,t,e].map(s=>Math.max(0,Math.min(255,Math.round(s))).toString(16).padStart(2,"0")).join("")}function u(i){let{r:t,g:e,b:s}=G(i);return E(t,e,s)}function d(i,t,e){let{r:s,g:n,b:o}=b(i,t,e);return K(s,n,o)}function c(i,t,e){return Math.max(t,Math.min(e,i))}function M(i){return i/=255,i<=.04045?i/12.92:Math.pow((i+.055)/1.055,2.4)}function N(i){let t=i<=.0031308?i*12.92:1.055*Math.pow(i,.4166666666666667)-.055;return Math.round(c(t,0,1)*255)}function z(i,t,e){let s=M(i),n=M(t),o=M(e),a=.4122214708*s+.5363325363*n+.0514459929*o,h=.2119034982*s+.6806995451*n+.1073969566*o,r=.0883024619*s+.2817188376*n+.6299787005*o,l=Math.cbrt(a),p=Math.cbrt(h),m=Math.cbrt(r),w=.2104542553*l+.793617785*p-.0040720468*m,v=1.9779984951*l-2.428592205*p+.4505937099*m,g=.0259040371*l+.7827717662*p-.808675766*m,H=Math.sqrt(v*v+g*g),x=Math.atan2(g,v)*180/Math.PI;return x<0&&(x+=360),H<1e-4&&(x=0),{L:w,C:H,H:x}}function W(i,t,e){let s=e*Math.PI/180,n=t*Math.cos(s),o=t*Math.sin(s),a=i+.3963377774*n+.2158037573*o,h=i-.1055613458*n-.0638541728*o,r=i-.0894841775*n-1.291485548*o,l=a**3,p=h**3,m=r**3,w=4.0767416621*l-3.3077115913*p+.2309699292*m,v=-1.2684380046*l+2.6097574011*p-.3413193965*m,g=-.0041960863*l-.7034186147*p+1.707614701*m;return{r:N(w),g:N(v),b:N(g)}}function L(i,t,e){let s=b(i,t,e);return z(s.r,s.g,s.b)}function I(i,t,e){let{r:s,g:n,b:o}=W(i,t,e);return E(s,n,o)}function X(i,t,e){return d(i,t,e)}function Y(i,t,e){let{r:s,g:n,b:o}=b(i,t,e);return`rgb(${s} ${n} ${o})`}function J(i,t,e){return`hsl(${i}deg ${t}% ${e}%)`}function Q(i,t,e){let{L:s,C:n,H:o}=L(i,t,e);return`oklch(${(s*100).toFixed(1)}% ${n.toFixed(3)} ${o.toFixed(1)}deg)`}function R(i,t,e,s){switch(i){case"rgb":return Y(t,e,s);case"hsl":return J(t,e,s);case"oklch":return Q(t,e,s);default:return X(t,e,s)}}var f=["hex","rgb","hsl","oklch"],Z="hex",S=class extends y{static formAssociated=!0;#d;#r;#a;#w;#C;#o;#n;#v;#i;#A;#p;#u={};#g=Z;#m;#b;#l;#f=!1;#y=!1;#t=0;#e=100;#s=50;#M;constructor(){super(),this.#d=this.attachInternals(),this._adoptInternals(this.#d)}setup(){if(this.#r=this.querySelector(':scope > input[type="color"]'),!this.#r)return!1;let t=this.getAttribute("format");t&&f.includes(t)&&(this.#g=t);let e=this.#r.value||"#000000";this.#M=e;let s=u(e);return this.#t=s.h,this.#e=s.s,this.#s=s.l,this.#r.setAttribute("tabindex","-1"),this.#r.setAttribute("aria-hidden","true"),this.#r.style.cssText="position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;overflow:hidden;",this.#D(),this.#F(),this.#E(),this.#T(),this.#y=F,this.#y&&this.#o.setAttribute("popover","manual"),this.listen(document,"click",this.#W),(this.#r.disabled||this.hasAttribute("disabled"))&&this.setAttribute("data-disabled",""),!0}teardown(){window.removeEventListener("scroll",this.#x,{capture:!0}),window.removeEventListener("resize",this.#x)}#D(){this.#a=document.createElement("button"),this.#a.type="button",this.#a.className="color-trigger",this.#a.setAttribute("aria-haspopup","dialog"),this.#a.setAttribute("aria-expanded","false"),this.#w=document.createElement("span"),this.#w.className="color-swatch",this.#C=document.createElement("span"),this.#C.className="color-hex",this.#a.appendChild(this.#w),this.#a.appendChild(this.#C),this.appendChild(this.#a),this.listen(this.#a,"click",()=>{this.#f?this.#H():this.#z()})}#F(){this.#o=document.createElement("div"),this.#o.className="color-panel",this.#o.setAttribute("role","dialog"),this.#o.setAttribute("aria-label","Color picker"),this.#n=document.createElement("div"),this.#n.className="color-area",this.#n.setAttribute("role","slider"),this.#n.setAttribute("aria-label","Saturation and lightness"),this.#n.setAttribute("tabindex","0"),this.#v=document.createElement("div"),this.#v.className="color-area-thumb",this.#n.appendChild(this.#v),this.#o.appendChild(this.#n);let t=document.createElement("div");t.className="color-hue-wrap",this.#i=document.createElement("div"),this.#i.className="color-hue",this.#i.setAttribute("role","slider"),this.#i.setAttribute("aria-label","Hue"),this.#i.setAttribute("aria-valuemin","0"),this.#i.setAttribute("aria-valuemax","360"),this.#i.setAttribute("tabindex","0"),this.#A=document.createElement("div"),this.#A.className="color-hue-thumb",this.#i.appendChild(this.#A),t.appendChild(this.#i),this.#o.appendChild(t);let e=document.createElement("div");e.className="color-format-row";let s=document.createElement("label");s.className="color-format-label";let n=document.createElement("span");n.textContent="Format",this.#p=document.createElement("select"),this.#p.className="color-format-select";for(let h of f){let r=document.createElement("option");r.value=h,r.textContent=h.toUpperCase(),this.#p.appendChild(r)}this.#p.value=this.#g,s.appendChild(n),s.appendChild(this.#p),e.appendChild(s),this.#o.appendChild(e),this.listen(this.#p,"change",this.#O),this.#u.hex=this.#k("hex",[{label:"Hex",channel:"hex",kind:"text",maxLength:7}]),this.#u.rgb=this.#k("rgb",[{label:"R",channel:"r",kind:"number",min:0,max:255,step:1},{label:"G",channel:"g",kind:"number",min:0,max:255,step:1},{label:"B",channel:"b",kind:"number",min:0,max:255,step:1}]),this.#u.hsl=this.#k("hsl",[{label:"H",channel:"h",kind:"number",min:0,max:360,step:1},{label:"S",channel:"s",kind:"number",min:0,max:100,step:1},{label:"L",channel:"l",kind:"number",min:0,max:100,step:1}]),this.#u.oklch=this.#k("oklch",[{label:"L%",channel:"oL",kind:"number",min:0,max:100,step:.1},{label:"C",channel:"oC",kind:"number",min:0,max:.4,step:.001},{label:"H\xB0",channel:"oH",kind:"number",min:0,max:360,step:.1}]);for(let h of f)this.#o.appendChild(this.#u[h].wrapper);this.#N();let o=this.querySelector(":scope > datalist");if(o){this.#m=document.createElement("div"),this.#m.className="color-swatches",this.#m.setAttribute("role","listbox"),this.#m.setAttribute("aria-label","Preset colors");for(let h of o.querySelectorAll("option[value]")){let r=document.createElement("button");r.type="button",r.setAttribute("role","option"),r.style.background=h.value,r.setAttribute("aria-label",h.textContent||h.value),r.setAttribute("data-color",h.value),this.#m.appendChild(r)}this.#o.appendChild(this.#m),this.listen(this.#m,"click",this.#j)}let a=document.createElement("div");a.className="color-actions","EyeDropper"in window&&(this.#b=document.createElement("button"),this.#b.type="button",this.#b.className="color-eyedropper",this.#b.setAttribute("aria-label","Pick color from screen"),this.#b.textContent="\u{1F4A7}",a.appendChild(this.#b),this.listen(this.#b,"click",this.#G)),this.#l=document.createElement("button"),this.#l.type="button",this.#l.className="color-copy",this.#l.setAttribute("aria-label","Copy hex value"),this.#l.textContent="Copy",a.appendChild(this.#l),this.listen(this.#l,"click",this.#K),this.#o.appendChild(a),this.appendChild(this.#o),this.listen(this.#n,"pointerdown",this.#P),this.listen(this.#n,"keydown",this.#I),this.listen(this.#i,"pointerdown",this.#R),this.listen(this.#i,"keydown",this.#_);for(let h of f){let r=h==="hex"?this.#B:h==="rgb"?this.#U:h==="hsl"?this.#q:this.#V;for(let{el:l}of this.#u[h].inputs)this.listen(l,"change",r)}}#k(t,e){let s=document.createElement("div");s.className=`color-inputs color-inputs-${t}`,s.setAttribute("data-format",t);let n=[];for(let o of e){let a=document.createElement("label");a.className="color-input-label";let h=document.createElement("span");h.textContent=o.label;let r=document.createElement("input");r.type=o.kind,r.setAttribute("data-channel",o.channel),r.setAttribute("autocomplete","off"),r.setAttribute("spellcheck","false"),o.kind==="text"&&o.maxLength&&r.setAttribute("maxlength",String(o.maxLength)),o.kind==="number"&&(r.min=String(o.min),r.max=String(o.max),o.step!=null&&(r.step=String(o.step))),a.appendChild(h),a.appendChild(r),s.appendChild(a),n.push({el:r,channel:o.channel})}return{wrapper:s,inputs:n}}#N(){for(let t of f)this.#u[t].wrapper.hidden=t!==this.#g;this.#l&&this.#l.setAttribute("aria-label",`Copy ${this.#g.toUpperCase()} value`)}#O=()=>{let t=this.#p.value;f.includes(t)&&(this.#g=t,this.#N(),this.#E())};#P=t=>{t.preventDefault(),this.#n.setPointerCapture(t.pointerId),this.#L(t);let e=n=>this.#L(n),s=n=>{this.#n.releasePointerCapture(n.pointerId),this.#n.removeEventListener("pointermove",e),this.#n.removeEventListener("pointerup",s)};this.#n.addEventListener("pointermove",e),this.#n.addEventListener("pointerup",s)};#L(t){let e=this.#n.getBoundingClientRect(),s=c((t.clientX-e.left)/e.width,0,1),n=c((t.clientY-e.top)/e.height,0,1);this.#e=Math.round(s*100),this.#s=Math.round((1-n)*100),this.#c()}#I=t=>{let e=t.shiftKey?10:1;switch(t.key){case"ArrowRight":t.preventDefault(),this.#e=c(this.#e+e,0,100);break;case"ArrowLeft":t.preventDefault(),this.#e=c(this.#e-e,0,100);break;case"ArrowUp":t.preventDefault(),this.#s=c(this.#s+e,0,100);break;case"ArrowDown":t.preventDefault(),this.#s=c(this.#s-e,0,100);break;default:return}this.#c()};#R=t=>{t.preventDefault(),this.#i.setPointerCapture(t.pointerId),this.#S(t);let e=n=>this.#S(n),s=n=>{this.#i.releasePointerCapture(n.pointerId),this.#i.removeEventListener("pointermove",e),this.#i.removeEventListener("pointerup",s)};this.#i.addEventListener("pointermove",e),this.#i.addEventListener("pointerup",s)};#S(t){let e=this.#i.getBoundingClientRect(),s=c((t.clientX-e.left)/e.width,0,1);this.#t=Math.round(s*360),this.#c()}#_=t=>{let e=t.shiftKey?10:1;switch(t.key){case"ArrowRight":case"ArrowUp":t.preventDefault(),this.#t=(this.#t+e)%361;break;case"ArrowLeft":case"ArrowDown":t.preventDefault(),this.#t=(this.#t-e+361)%361;break;default:return}this.#c()};#h(t,e){return this.#u[t].inputs.find(s=>s.channel===e)?.el}#B=()=>{let t=this.#h("hex","hex");if(!t)return;let e=t.value.trim();if(e.startsWith("#")||(e="#"+e),/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(e)){let s=u(e);this.#t=s.h,this.#e=s.s,this.#s=s.l,this.#c()}};#U=()=>{let t=c(Number(this.#h("rgb","r").value)||0,0,255),e=c(Number(this.#h("rgb","g").value)||0,0,255),s=c(Number(this.#h("rgb","b").value)||0,0,255),n=E(t,e,s);this.#t=n.h,this.#e=n.s,this.#s=n.l,this.#c()};#q=()=>{let t=c(Number(this.#h("hsl","h").value)||0,0,360)%361,e=c(Number(this.#h("hsl","s").value)||0,0,100),s=c(Number(this.#h("hsl","l").value)||0,0,100);this.#t=t,this.#e=e,this.#s=s,this.#c()};#V=()=>{let t=c(Number(this.#h("oklch","oL").value)||0,0,100)/100,e=c(Number(this.#h("oklch","oC").value)||0,0,.4),s=c(Number(this.#h("oklch","oH").value)||0,0,360),n=I(t,e,s);this.#t=n.h,this.#e=n.s,this.#s=n.l,this.#c()};#j=t=>{let e=t.target.closest("button[data-color]");if(!e)return;let s=e.getAttribute("data-color"),n=u(s);this.#t=n.h,this.#e=n.s,this.#s=n.l,this.#c()};#G=async()=>{try{let e=await new window.EyeDropper().open(),s=u(e.sRGBHex);this.#t=s.h,this.#e=s.s,this.#s=s.l,this.#c()}catch{}};#K=()=>{let t=R(this.#g,this.#t,this.#e,this.#s);T(t,{button:this.#l,announceMessage:"Color copied"})};#c(t="internal"){this.#E(),this.#T();let e=d(this.#t,this.#e,this.#s),s=b(this.#t,this.#e,this.#s);this.dispatchEvent(new CustomEvent("color-picker:change",{bubbles:!0,detail:{hex:e,rgb:{r:s.r,g:s.g,b:s.b},hsl:{h:this.#t,s:this.#e,l:this.#s},source:t}}))}#E(){let t=d(this.#t,this.#e,this.#s),e=b(this.#t,this.#e,this.#s),s=d(this.#t,100,50);this.#w.style.background=t,this.#C.textContent=t,this.#n.style.setProperty("--area-hue",s),this.#v.style.insetInlineStart=`${this.#e}%`,this.#v.style.insetBlockStart=`${100-this.#s}%`,this.#v.style.background=t,this.#n.setAttribute("aria-valuetext",`Saturation ${this.#e}%, Lightness ${this.#s}%`),this.#A.style.insetInlineStart=`${this.#t/360*100}%`,this.#i.setAttribute("aria-valuenow",String(this.#t)),this.#i.setAttribute("aria-valuetext",`Hue ${this.#t}\xB0`);let n=(a,h,r)=>{let l=this.#h(a,h);l&&(l.value=String(r))};n("hex","hex",t),n("rgb","r",e.r),n("rgb","g",e.g),n("rgb","b",e.b),n("hsl","h",this.#t),n("hsl","s",this.#e),n("hsl","l",this.#s);let o=L(this.#t,this.#e,this.#s);n("oklch","oL",(o.L*100).toFixed(1)),n("oklch","oC",o.C.toFixed(3)),n("oklch","oH",o.H.toFixed(1))}#z(){if(!this.#f){if(this.#f=!0,this.setAttribute("open",""),this.#a.setAttribute("aria-expanded","true"),this.#y){this.#$();try{this.#o.showPopover()}catch{}window.addEventListener("scroll",this.#x,{capture:!0,passive:!0}),window.addEventListener("resize",this.#x,{passive:!0})}requestAnimationFrame(()=>this.#n.focus()),this.dispatchEvent(new CustomEvent("color-picker:open",{bubbles:!0}))}}#H(){if(this.#f){if(this.#f=!1,this.removeAttribute("open"),this.#a.setAttribute("aria-expanded","false"),this.#y){try{this.#o.hidePopover()}catch{}window.removeEventListener("scroll",this.#x,{capture:!0}),window.removeEventListener("resize",this.#x)}this.dispatchEvent(new CustomEvent("color-picker:close",{bubbles:!0}))}}#$(){if(!this.#y)return;let t=this.#a.getBoundingClientRect();this.#o.style.setProperty("--panel-top",`${t.bottom+4}px`),this.#o.style.setProperty("--panel-left",`${t.left}px`)}#x=()=>{this.#f&&this.#$()};#W=t=>{this.#f&&!this.contains(t.target)&&this.#H()};#T(){let t=d(this.#t,this.#e,this.#s);this.#d.setFormValue(t),this.#r.value=t,this.#r.dispatchEvent(new Event("input",{bubbles:!0}))}formResetCallback(){let t=u(this.#M);this.#t=t.h,this.#e=t.s,this.#s=t.l,this.#E(),this.#T()}formStateRestoreCallback(t){if(!t)return;let e=u(t);this.#t=e.h,this.#e=e.s,this.#s=e.l,this.#E(),this.#T()}get value(){return d(this.#t,this.#e,this.#s)}set value(t){if(!/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(t))return;let e=d(this.#t,this.#e,this.#s).toLowerCase(),s=t.toLowerCase();if(e===s||e===s.toLowerCase())return;let n=u(t);this.#t=n.h,this.#e=n.s,this.#s=n.l,this.#c("api")}};D("color-picker",S);export{S as ColorPicker};
|
|
1
|
+
var lt=window.matchMedia("(prefers-reduced-motion: reduce)");var F=new Map;function P(s,t,e={}){let i=e.priority??10,n={impl:t,bundle:e.bundle,contract:e.contract,priority:i},r=F.get(s);if(customElements.get(s)){if(!r||r.priority>=i){r&&r.priority===i&&r.impl!==t&&console.warn(`[VB Bundle] Tag <${s}> already registered by "${r.bundle}" (priority ${r.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${s}> defined by "${r.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(r&&r.priority>=i){r.priority===i&&console.warn(`[VB Bundle] Tag <${s}> already registered by "${r.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}F.set(s,n),customElements.define(s,t)}var E=class extends HTMLElement{#d=[];#n;constructor(){super(),this.hasAttribute("data-upgraded")&&this.removeAttribute("data-upgraded")}connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#d)t();this.#d=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,i,n){t.addEventListener(e,i,n),this.#d.push(()=>t.removeEventListener(e,i,n))}_reinit(){for(let t of this.#d)t();this.#d=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(t,e){this.#n||(this.#n=this.attachInternals());let i=this.#n.states;try{e?i.add(t):i.delete(t)}catch{let n=`--${t}`;e?i.add(n):i.delete(n)}}_adoptInternals(t){this.#n||(this.#n=t)}#t(){return this.constructor.formAssociated&&this.#n?this.#n:null}get validity(){return this.#t()?.validity}get validationMessage(){return this.#t()?.validationMessage??""}get willValidate(){return this.#t()?.willValidate??!1}get form(){return this.#t()?.form??null}checkValidity(){return this.#t()?.checkValidity()??!0}reportValidity(){return this.#t()?.reportValidity()??!0}};var R="popover"in HTMLElement.prototype;var W=["position:absolute","inline-size:1px","block-size:1px","padding:0","margin:-1px","overflow:hidden","clip-path:inset(50%)","white-space:nowrap","border:0"].join(";"),I=new WeakMap;function j(s,t){let e=I.get(t);e||I.set(t,e=new Map);let i=e.get(s);if(!i||!i.region.isConnected){let r=(t.ownerDocument||document).createElement("span");r.setAttribute("data-vb-announcer",s),r.setAttribute("role",s==="assertive"?"alert":"status"),r.setAttribute("aria-live",s),r.setAttribute("aria-atomic","true"),r.style.cssText=W,t.appendChild(r),i={region:r},e.set(s,i)}return i}function _(s,{politeness:t="polite",root:e}={}){let i=String(s??"").trim();if(!i||typeof document>"u")return null;let n=e||document.body;if(!n)return null;let a=j(t==="assertive"?"assertive":"polite",n);return clearTimeout(a.write),clearTimeout(a.clear),a.region.textContent="",a.write=setTimeout(()=>{a.region.textContent=i,a.clear=setTimeout(()=>{a.region.textContent=""},7e3)},50),a.region}function w(s,t,e,i){let n=`data-label-${t}`,a=s?.closest?.(`[${n}]`)?.getAttribute(n)||e;return i?a.replace(/\{(\w+)\}/g,(o,l)=>l in i?String(i[l]):o):a}var B=1500,U="[data-copy], [data-copy-target], [data-paste-target]",A={copied:"Copied to clipboard",pasted:"Pasted from clipboard","copy-failed":"Copy failed","copy-failed-selected":"Copy failed. Text selected, press Ctrl+C to copy","paste-failed":"Paste failed"},T=new WeakMap;function z(s){if(typeof document.execCommand!="function"||!document.body)return!1;let t=document.activeElement,e=document.createElement("textarea");e.value=s,e.setAttribute("readonly",""),e.setAttribute("aria-hidden","true"),e.style.cssText="position:fixed;inset-block-start:0;inset-inline-start:0;opacity:0;pointer-events:none",document.body.appendChild(e),e.select();let i=!1;try{i=document.execCommand("copy")}catch{i=!1}return e.remove(),t?.focus?.({preventScroll:!0}),i}function G(s){if(!s)return!1;if(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement)return s.focus(),s.select(),!0;let t=window.getSelection?.();if(!t)return!1;let e=document.createRange();return e.selectNodeContents(s),t.removeAllRanges(),t.addRange(e),!t.isCollapsed}async function L(s,t={}){if(s==null||s==="")return!1;let{button:e,duration:i=B}=t,n=!1,r=null;try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(s),n=!0}catch(o){r=o,n=z(s)}if(n)return k({button:e,duration:i,state:"copied",eventName:"copy:done",eventDetail:{text:s},message:t.announceMessage??w(e,"copied",A.copied)}),!0;let a=G(t.source);return k({button:e,duration:i,state:"failed",eventName:"copy:error",eventDetail:{text:s,error:r},message:t.failureMessage??w(e,"copy-failed",a?A["copy-failed-selected"]:A["copy-failed"])}),!1}function k({button:s,duration:t,message:e,eventDetail:i,state:n,eventName:r}){if(s){s.dataset.state=n;let a=T.get(s);a&&clearTimeout(a),T.set(s,setTimeout(()=>{s.dataset.state===n&&delete s.dataset.state,T.delete(s)},t)),s.dispatchEvent(new CustomEvent(r,{bubbles:!0,detail:i}))}_(e,{politeness:n==="failed"?"assertive":"polite"})}async function K(s,t={}){let{button:e,duration:i=B}=t,n;try{if(!navigator.clipboard?.readText)throw new Error("Clipboard API unavailable");n=await navigator.clipboard.readText()}catch(r){return k({button:e,duration:i,state:"failed",eventName:"paste:error",eventDetail:{target:s,error:r},message:t.failureMessage??w(e,"paste-failed",A["paste-failed"])}),null}return s&&(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement?s.value=n:s.textContent=n,s.dispatchEvent(new Event("input",{bubbles:!0}))),k({button:e,duration:i,state:"pasted",eventName:"paste:done",eventDetail:{text:n,target:s},message:t.announceMessage??w(e,"pasted",A.pasted)}),n}function O(s){let t=s.dataset.copyTarget;if(!t)return null;try{return document.querySelector(t)}catch{return null}}function Y(s){if(s.dataset.copy)return s.dataset.copy;let t=O(s);if(!t)return"";let e=s.dataset.copyAttr;return e?t.getAttribute(e)??"":t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?t.value:t.textContent??""}function X(s){let t=s.target?.closest?.(U);if(!t||t.matches(':disabled, [aria-disabled="true"]'))return;if(t.dataset.pasteTarget){let i=null;try{i=document.querySelector(t.dataset.pasteTarget)}catch{}if(!i)return;K(i,{button:t});return}let e=Y(t);e&&L(e,{button:t,source:O(t)??void 0})}typeof document<"u"&&!document.__vbCopyDelegated&&(document.__vbCopyDelegated=!0,document.addEventListener("click",X));function b(s,t,e){t/=100,e/=100;let i=a=>(a+s/30)%12,n=t*Math.min(e,1-e),r=a=>e-n*Math.max(-1,Math.min(i(a)-3,9-i(a),1));return{r:Math.round(r(0)*255),g:Math.round(r(8)*255),b:Math.round(r(4)*255)}}function M(s,t,e,i=!1){s/=255,t/=255,e/=255;let n=Math.max(s,t,e),r=Math.min(s,t,e),a=(n+r)/2,o=0,l=0;if(n!==r){let h=n-r;switch(l=a>.5?h/(2-n-r):h/(n+r),n){case s:o=((t-e)/h+(t<e?6:0))/6;break;case t:o=((e-s)/h+2)/6;break;case e:o=((s-t)/h+4)/6;break}}return i?{h:o*360,s:l*100,l:a*100}:{h:Math.round(o*360),s:Math.round(l*100),l:Math.round(a*100)}}function J(s){s=s.replace(/^#/,""),s.length===3&&(s=s[0]+s[0]+s[1]+s[1]+s[2]+s[2]);let t=parseInt(s,16);return{r:t>>16&255,g:t>>8&255,b:t&255}}function Q(s,t,e){return"#"+[s,t,e].map(i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0")).join("")}function p(s,t=!1){let{r:e,g:i,b:n}=J(s);return M(e,i,n,t)}function f(s,t,e){let{r:i,g:n,b:r}=b(s,t,e);return Q(i,n,r)}function c(s,t,e){return Math.max(t,Math.min(e,s))}function S(s){return s/=255,s<=.04045?s/12.92:Math.pow((s+.055)/1.055,2.4)}function H(s){let t=s<=.0031308?s*12.92:1.055*Math.pow(s,.4166666666666667)-.055;return Math.round(c(t,0,1)*255)}function Z(s,t,e){let i=S(s),n=S(t),r=S(e),a=.4122214708*i+.5363325363*n+.0514459929*r,o=.2119034982*i+.6806995451*n+.1073969566*r,l=.0883024619*i+.2817188376*n+.6299787005*r,h=Math.cbrt(a),u=Math.cbrt(o),d=Math.cbrt(l),m=.2104542553*h+.793617785*u-.0040720468*d,y=1.9779984951*h-2.428592205*u+.4505937099*d,x=.0259040371*h+.7827717662*u-.808675766*d,D=Math.sqrt(y*y+x*x),C=Math.atan2(x,y)*180/Math.PI;return C<0&&(C+=360),D<1e-4&&(C=0),{L:m,C:D,H:C}}function tt(s,t,e){let i=e*Math.PI/180,n=t*Math.cos(i),r=t*Math.sin(i),a=s+.3963377774*n+.2158037573*r,o=s-.1055613458*n-.0638541728*r,l=s-.0894841775*n-1.291485548*r,h=a**3,u=o**3,d=l**3,m=4.0767416621*h-3.3077115913*u+.2309699292*d,y=-1.2684380046*h+2.6097574011*u-.3413193965*d,x=-.0041960863*h-.7034186147*u+1.707614701*d;return{r:H(m),g:H(y),b:H(x)}}function N(s,t,e){let i=b(s,t,e);return Z(i.r,i.g,i.b)}function q(s,t,e,i=!1){let{r:n,g:r,b:a}=tt(s,t,e);return M(n,r,a,i)}function et(s,t,e){return f(s,t,e)}function it(s,t,e){let{r:i,g:n,b:r}=b(s,t,e);return`rgb(${i} ${n} ${r})`}function st(s,t,e){return`hsl(${Math.round(s)}deg ${Math.round(t)}% ${Math.round(e)}%)`}function nt(s,t,e){let{L:i,C:n,H:r}=N(s,t,e);return`oklch(${(i*100).toFixed(1)}% ${n.toFixed(3)} ${r.toFixed(1)}deg)`}function V(s,t,e,i){switch(s){case"rgb":return it(t,e,i);case"hsl":return st(t,e,i);case"oklch":return nt(t,e,i);default:return et(t,e,i)}}var g=["hex","rgb","hsl","oklch"],rt="hex",ot=/^#[0-9a-fA-F]{6}$/,v=8,at=0,$=class extends E{static formAssociated=!0;#d;#n;#t;#E;#g;#v;#a;#r;#y;#o;#k;#b;#f={};#x=rt;#c;#m;#u;#p=!1;#A=!1;#$=!1;#H=`cp${++at}`;#e=0;#i=100;#s=50;#M;static get observedAttributes(){return["disabled"]}constructor(){super(),this.#d=this.attachInternals(),this._adoptInternals(this.#d)}setup(){if(this.#n=this.querySelector(':scope > input[type="color"]'),!this.#n)return!1;if(!this.#$){let i=this.getAttribute("format");i&&g.includes(i)&&(this.#x=i),this.#$=!0}if(this.#M===void 0){let i=this.#n.defaultValue;this.#M=ot.test(i)?i.toLowerCase():this.#n.value||"#000000"}let t=p(this.#n.value||this.#M,!0);this.#e=t.h,this.#i=t.s,this.#s=t.l;let e=this.#n.getAttribute("name");return e&&(this.hasAttribute("name")||this.setAttribute("name",e),this.#n.removeAttribute("name")),this.#n.hasAttribute("disabled")&&(this.#n.removeAttribute("disabled"),this.hasAttribute("disabled")||this.setAttribute("disabled","")),this.#n.setAttribute("tabindex","-1"),this.#n.setAttribute("aria-hidden","true"),this.#n.style.cssText="position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;overflow:hidden;",this.listen(this.#n,"click",this.#I),this.#B(),this.#O(),this.#C(),this.#S(),this.#A=R,this.#A&&this.#a.setAttribute("popover","manual"),this.listen(document,"click",this.#tt),this.listen(this,"keydown",this.#_),this.#N(this.matches(":disabled")),!0}teardown(){this.#p=!1,this.removeAttribute("open"),window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w),this.#t?.remove(),this.#a?.remove()}attributeChangedCallback(t){t==="disabled"&&this.#t&&this.#N(this.matches(":disabled"))}formDisabledCallback(t){this.#t&&this.#N(t)}#N(t){this.#t.disabled=t,t&&this.#L()}#I=t=>{t.preventDefault(),this.#t.disabled||this.#t.focus()};#_=t=>{t.key!=="Escape"||!this.#p||(t.preventDefault(),t.stopPropagation(),this.#L(),this.#t.focus())};#B(){this.#t=document.createElement("button"),this.#t.type="button",this.#t.className="color-trigger",this.#t.setAttribute("aria-haspopup","dialog"),this.#t.setAttribute("aria-expanded","false"),this.#E=document.createElement("span"),this.#E.className="color-swatch",this.#g=document.createElement("span"),this.#g.className="color-hex",this.#g.id=`${this.#H}-value`,this.#t.appendChild(this.#E),this.#t.appendChild(this.#g);let t=[];for(let e of Array.from(this.#n.labels||[]))e.id||(e.id=`${this.#H}-label-${t.length}`),t.push(e.id);t.length===0&&(this.#v=document.createElement("span"),this.#v.className="visually-hidden",this.#v.id=`${this.#H}-name`,this.#v.textContent=this.#n.getAttribute("aria-label")||this.getAttribute("aria-label")||"Color",this.#t.prepend(this.#v),t.push(this.#v.id)),this.#t.setAttribute("aria-labelledby",[...t,this.#g.id].join(" ")),this.appendChild(this.#t),this.listen(this.#t,"click",()=>{this.#p?this.#L():this.#Z()})}#O(){this.#c=void 0,this.#m=void 0,this.#a=document.createElement("div"),this.#a.className="color-panel",this.#a.setAttribute("role","dialog"),this.#a.setAttribute("aria-label","Color picker"),this.#r=document.createElement("div"),this.#r.className="color-area",this.#r.setAttribute("role","slider"),this.#r.setAttribute("aria-label","Saturation and lightness"),this.#r.setAttribute("aria-valuemin","0"),this.#r.setAttribute("aria-valuemax","100"),this.#r.setAttribute("tabindex","0"),this.#y=document.createElement("div"),this.#y.className="color-area-thumb",this.#r.appendChild(this.#y),this.#a.appendChild(this.#r);let t=document.createElement("div");t.className="color-hue-wrap",this.#o=document.createElement("div"),this.#o.className="color-hue",this.#o.setAttribute("role","slider"),this.#o.setAttribute("aria-label","Hue"),this.#o.setAttribute("aria-valuemin","0"),this.#o.setAttribute("aria-valuemax","360"),this.#o.setAttribute("tabindex","0"),this.#k=document.createElement("div"),this.#k.className="color-hue-thumb",this.#o.appendChild(this.#k),t.appendChild(this.#o),this.#a.appendChild(t);let e=document.createElement("div");e.className="color-format-row";let i=document.createElement("label");i.className="color-format-label";let n=document.createElement("span");n.textContent="Format",this.#b=document.createElement("select"),this.#b.className="color-format-select";for(let o of g){let l=document.createElement("option");l.value=o,l.textContent=o.toUpperCase(),this.#b.appendChild(l)}this.#b.value=this.#x,i.appendChild(n),i.appendChild(this.#b),e.appendChild(i),this.#a.appendChild(e),this.listen(this.#b,"change",this.#q),this.#f.hex=this.#T("hex",[{label:"Hex",channel:"hex",kind:"text",maxLength:7}]),this.#f.rgb=this.#T("rgb",[{label:"R",channel:"r",kind:"number",min:0,max:255,step:1},{label:"G",channel:"g",kind:"number",min:0,max:255,step:1},{label:"B",channel:"b",kind:"number",min:0,max:255,step:1}]),this.#f.hsl=this.#T("hsl",[{label:"H",channel:"h",kind:"number",min:0,max:360,step:1},{label:"S",channel:"s",kind:"number",min:0,max:100,step:1},{label:"L",channel:"l",kind:"number",min:0,max:100,step:1}]),this.#f.oklch=this.#T("oklch",[{label:"L%",channel:"oL",kind:"number",min:0,max:100,step:.1},{label:"C",channel:"oC",kind:"number",min:0,max:.4,step:.001},{label:"H\xB0",channel:"oH",kind:"number",min:0,max:360,step:.1}]);for(let o of g)this.#a.appendChild(this.#f[o].wrapper);this.#D();let r=this.querySelector(":scope > datalist");if(r){this.#c=document.createElement("div"),this.#c.className="color-swatches",this.#c.setAttribute("role","group"),this.#c.setAttribute("aria-label","Preset colors");for(let o of r.querySelectorAll("option[value]")){let l=document.createElement("button");l.type="button",l.setAttribute("aria-pressed","false"),l.style.background=o.value,l.setAttribute("aria-label",o.textContent||o.value),l.setAttribute("data-color",o.value),this.#c.appendChild(l)}this.#a.appendChild(this.#c),this.listen(this.#c,"click",this.#X)}let a=document.createElement("div");a.className="color-actions","EyeDropper"in window&&(this.#m=document.createElement("button"),this.#m.type="button",this.#m.className="color-eyedropper",this.#m.setAttribute("aria-label","Pick color from screen"),this.#m.textContent="\u{1F4A7}",a.appendChild(this.#m),this.listen(this.#m,"click",this.#J)),this.#u=document.createElement("button"),this.#u.type="button",this.#u.className="color-copy",this.#u.setAttribute("aria-label","Copy hex value"),this.#u.textContent="Copy",a.appendChild(this.#u),this.listen(this.#u,"click",this.#Q),this.#a.appendChild(a),this.appendChild(this.#a),this.listen(this.#r,"pointerdown",this.#V),this.listen(this.#r,"keydown",this.#W),this.listen(this.#o,"pointerdown",this.#j),this.listen(this.#o,"keydown",this.#U);for(let o of g){let l=o==="hex"?this.#z:o==="rgb"?this.#G:o==="hsl"?this.#K:this.#Y;for(let{el:h}of this.#f[o].inputs)this.listen(h,"change",l)}}#T(t,e){let i=document.createElement("div");i.className=`color-inputs color-inputs-${t}`,i.setAttribute("data-format",t);let n=[];for(let r of e){let a=document.createElement("label");a.className="color-input-label";let o=document.createElement("span");o.textContent=r.label;let l=document.createElement("input");l.type=r.kind,l.setAttribute("data-channel",r.channel),l.setAttribute("autocomplete","off"),l.setAttribute("spellcheck","false"),r.kind==="text"&&r.maxLength&&l.setAttribute("maxlength",String(r.maxLength)),r.kind==="number"&&(l.min=String(r.min),l.max=String(r.max),r.step!=null&&(l.step=String(r.step))),a.appendChild(o),a.appendChild(l),i.appendChild(a),n.push({el:l,channel:r.channel})}return{wrapper:i,inputs:n}}#D(){for(let t of g)this.#f[t].wrapper.hidden=t!==this.#x;this.#u&&this.#u.setAttribute("aria-label",`Copy ${this.#x.toUpperCase()} value`)}#q=()=>{let t=this.#b.value;g.includes(t)&&(this.#x=t,this.#D(),this.#C())};#V=t=>{t.preventDefault(),this.#r.setPointerCapture(t.pointerId),this.#F(t);let e=n=>this.#F(n),i=n=>{this.#r.releasePointerCapture(n.pointerId),this.#r.removeEventListener("pointermove",e),this.#r.removeEventListener("pointerup",i)};this.#r.addEventListener("pointermove",e),this.#r.addEventListener("pointerup",i)};#F(t){let e=this.#r.getBoundingClientRect(),i=c((t.clientX-e.left)/e.width,0,1),n=c((t.clientY-e.top)/e.height,0,1);this.#i=Math.round(i*100),this.#s=Math.round((1-n)*100),this.#h("pointer")}#W=t=>{let e=t.shiftKey?10:1;switch(this.#i=Math.round(this.#i),this.#s=Math.round(this.#s),t.key){case"ArrowRight":t.preventDefault(),this.#i=c(this.#i+e,0,100);break;case"ArrowLeft":t.preventDefault(),this.#i=c(this.#i-e,0,100);break;case"ArrowUp":t.preventDefault(),this.#s=c(this.#s+e,0,100);break;case"ArrowDown":t.preventDefault(),this.#s=c(this.#s-e,0,100);break;default:return}this.#h("keyboard")};#j=t=>{t.preventDefault(),this.#o.setPointerCapture(t.pointerId),this.#P(t);let e=n=>this.#P(n),i=n=>{this.#o.releasePointerCapture(n.pointerId),this.#o.removeEventListener("pointermove",e),this.#o.removeEventListener("pointerup",i)};this.#o.addEventListener("pointermove",e),this.#o.addEventListener("pointerup",i)};#P(t){let e=this.#o.getBoundingClientRect(),i=c((t.clientX-e.left)/e.width,0,1);this.#e=Math.round(i*360),this.#h("pointer")}#U=t=>{let e=t.shiftKey?10:1;switch(this.#e=Math.round(this.#e),t.key){case"ArrowRight":case"ArrowUp":t.preventDefault(),this.#e=(this.#e+e)%361;break;case"ArrowLeft":case"ArrowDown":t.preventDefault(),this.#e=(this.#e-e+361)%361;break;default:return}this.#h("keyboard")};#l(t,e){return this.#f[t].inputs.find(i=>i.channel===e)?.el}#z=()=>{let t=this.#l("hex","hex");if(!t)return;let e=t.value.trim();if(e.startsWith("#")||(e="#"+e),/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(e)){let i=p(e,!0);this.#e=i.h,this.#i=i.s,this.#s=i.l,this.#h()}};#G=()=>{let t=c(Number(this.#l("rgb","r").value)||0,0,255),e=c(Number(this.#l("rgb","g").value)||0,0,255),i=c(Number(this.#l("rgb","b").value)||0,0,255),n=M(t,e,i,!0);this.#e=n.h,this.#i=n.s,this.#s=n.l,this.#h()};#K=()=>{let t=c(Number(this.#l("hsl","h").value)||0,0,360)%361,e=c(Number(this.#l("hsl","s").value)||0,0,100),i=c(Number(this.#l("hsl","l").value)||0,0,100);this.#e=t,this.#i=e,this.#s=i,this.#h()};#Y=()=>{let t=c(Number(this.#l("oklch","oL").value)||0,0,100)/100,e=c(Number(this.#l("oklch","oC").value)||0,0,.4),i=c(Number(this.#l("oklch","oH").value)||0,0,360),n=q(t,e,i,!0);this.#e=n.h,this.#i=n.s,this.#s=n.l,this.#h()};#X=t=>{let e=t.target.closest("button[data-color]");if(!e)return;let i=e.getAttribute("data-color"),n=p(i,!0);this.#e=n.h,this.#i=n.s,this.#s=n.l,this.#h()};#J=async()=>{try{let e=await new window.EyeDropper().open(),i=p(e.sRGBHex,!0);this.#e=i.h,this.#i=i.s,this.#s=i.l,this.#h()}catch{}};#Q=()=>{let t=V(this.#x,this.#e,this.#i,this.#s);L(t,{button:this.#u,announceMessage:"Color copied"})};#h(t="internal"){this.#C(),this.#S();let e=f(this.#e,this.#i,this.#s),i=b(this.#e,this.#i,this.#s);this.dispatchEvent(new CustomEvent("color-picker:change",{bubbles:!0,detail:{hex:e,rgb:{r:i.r,g:i.g,b:i.b},hsl:{h:Math.round(this.#e),s:Math.round(this.#i),l:Math.round(this.#s)},source:t}}))}#C(){let t=f(this.#e,this.#i,this.#s),e=b(this.#e,this.#i,this.#s),i=f(this.#e,100,50);this.#E.style.background=t,this.#g.textContent=t,this.#r.style.setProperty("--area-hue",i),this.#y.style.left=`${this.#i}%`,this.#y.style.top=`${100-this.#s}%`,this.#y.style.background=t;let n=Math.round(this.#e),r=Math.round(this.#i),a=Math.round(this.#s);this.#r.setAttribute("aria-valuenow",String(r)),this.#r.setAttribute("aria-valuetext",`Saturation ${r}%, lightness ${a}%`),this.#k.style.left=`${this.#e/360*100}%`,this.#o.setAttribute("aria-valuenow",String(n)),this.#o.setAttribute("aria-valuetext",`Hue ${n}\xB0`);let o=(h,u,d)=>{let m=this.#l(h,u);m&&(m.value=String(d))};o("hex","hex",t),o("rgb","r",e.r),o("rgb","g",e.g),o("rgb","b",e.b),o("hsl","h",n),o("hsl","s",r),o("hsl","l",a);let l=N(this.#e,this.#i,this.#s);if(o("oklch","oL",(l.L*100).toFixed(1)),o("oklch","oC",l.C.toFixed(3)),o("oklch","oH",l.H.toFixed(1)),this.#c)for(let h of this.#c.querySelectorAll("button[data-color]")){let u=(h.getAttribute("data-color")||"").toLowerCase()===t.toLowerCase();h.setAttribute("aria-pressed",String(u))}}#Z(){if(!(this.#p||this.#t.disabled)){if(this.#p=!0,this.setAttribute("open",""),this.#t.setAttribute("aria-expanded","true"),this.#A){try{this.#a.showPopover()}catch{}this.#R(),window.addEventListener("scroll",this.#w,{capture:!0,passive:!0}),window.addEventListener("resize",this.#w,{passive:!0})}requestAnimationFrame(()=>this.#r.focus()),this.dispatchEvent(new CustomEvent("color-picker:open",{bubbles:!0}))}}#L(){if(this.#p){if(this.#p=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#A){try{this.#a.hidePopover()}catch{}window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w)}this.dispatchEvent(new CustomEvent("color-picker:close",{bubbles:!0}))}}#R(){if(!this.#A)return;let t=this.#t.getBoundingClientRect(),e=this.#a.offsetWidth,i=this.#a.offsetHeight,n=document.documentElement.clientWidth,r=document.documentElement.clientHeight,o=getComputedStyle(this).direction==="rtl"?t.right-e:t.left;o=Math.min(o,n-e-v),o=Math.max(o,v);let l=t.bottom+4;l+i>r-v&&t.top-i-4>=v&&(l=t.top-i-4),l=Math.max(v,Math.min(l,r-i-v)),this.#a.style.setProperty("--panel-top",`${Math.round(l)}px`),this.#a.style.setProperty("--panel-left",`${Math.round(o)}px`)}#w=()=>{this.#p&&this.#R()};#tt=t=>{this.#p&&!this.contains(t.target)&&this.#L()};#S(){let t=f(this.#e,this.#i,this.#s);this.#d.setFormValue(t),this.#n.value=t,this.#n.dispatchEvent(new Event("input",{bubbles:!0}))}formResetCallback(){if(!this.#t)return;let t=p(this.#M,!0);this.#e=t.h,this.#i=t.s,this.#s=t.l,this.#C(),this.#S()}formStateRestoreCallback(t){if(!t||!this.#t)return;let e=p(t,!0);this.#e=e.h,this.#i=e.s,this.#s=e.l,this.#C(),this.#S()}get value(){return f(this.#e,this.#i,this.#s)}set value(t){if(!/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(t))return;let e=f(this.#e,this.#i,this.#s).toLowerCase(),i=t.toLowerCase();if(e===i||e===i.toLowerCase())return;let n=p(t,!0);this.#e=n.h,this.#i=n.s,this.#s=n.l,this.#h("api")}};P("color-picker",$);export{$ as ColorPicker};
|
|
2
2
|
//# sourceMappingURL=color-picker.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var y=window.matchMedia("(prefers-reduced-motion: reduce)");var p=new Map;function c(h,t,e={}){let s=e.priority??10,o={impl:t,bundle:e.bundle,contract:e.contract,priority:s},i=p.get(h);if(customElements.get(h)){if(!i||i.priority>=s){i&&i.priority===s&&i.impl!==t&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${i.bundle}" (priority ${i.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${h}> defined by "${i.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(i&&i.priority>=s){i.priority===s&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${i.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}p.set(h,o),customElements.define(h,t)}var l=class extends HTMLElement{#e=[];#t;connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#e)t();this.#e=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,s,o){t.addEventListener(e,s,o),this.#e.push(()=>t.removeEventListener(e,s,o))}setup(){}teardown(){}setState(t,e){this.#t||(this.#t=this.attachInternals());let s=this.#t.states;try{e?s.add(t):s.delete(t)}catch{let o=`--${t}`;e?s.add(o):s.delete(o)}}_adoptInternals(t){this.#t||(this.#t=t)}};function b(h,t,e){"role"in ElementInternals.prototype?t.role=e:h.setAttribute("role",e)}var u=CSS.supports("anchor-name","--x"),v=CSS.supports("position-area","bottom"),g=0,d=class extends l{#e=null;#t=null;#i=null;#s=null;setup(){this.id||(this.id=`pop-over-${++g}`);let t=this.dataset.mode||"auto";this.hasAttribute("popover")||this.setAttribute("popover",t),this.#c(),this.#a(),this.#i=e=>{let s=e.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${s}`,{detail:{state:e.newState},bubbles:!0,composed:!0})),!u&&e.newState==="open"&&this.#e&&this.#o()},this.listen(this,"beforetoggle",this.#i),u||(this.#s=()=>{this.matches(":popover-open")&&this.#e&&this.#o()},this.listen(window,"resize",this.#s),this.listen(window,"scroll",this.#s,{capture:!0,passive:!0}))}show(){this.matches(":popover-open")||this.showPopover()}hide(){this.matches(":popover-open")&&this.hidePopover()}toggle(){this.matches(":popover-open")?this.hide():this.show()}get open(){return this.matches(":popover-open")}#c(){let t=this.dataset.anchor;t?this.#e=document.getElementById(t)||document.querySelector(t):this.#e=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#a(){if(!(!this.#e||!u)&&(this.#t=`--pop-over-anchor-${this.id}`,this.#e.style.setProperty("anchor-name",this.#t),this.style.setProperty("position-anchor",this.#t),this.setAttribute("data-anchor-name",this.#t||""),!v)){let t=this.dataset.position||"bottom";this.#l(t)}}#l(t){let e="var(--_pop-over-offset, var(--size-xs))",s={top:{bottom:`calc(anchor(top) + ${e})`,left:"anchor(left)"},bottom:{top:`calc(anchor(bottom) + ${e})`,left:"anchor(left)"},left:{right:`calc(anchor(left) + ${e})`,top:"anchor(top)"},right:{left:`calc(anchor(right) + ${e})`,top:"anchor(top)"}},o=t.split("-")[0],i=s[o]||s.bottom;Object.entries(i).forEach(([n,r])=>this.style.setProperty(n,r))}#o(){if(!this.#e)return;let t=this.#e.getBoundingClientRect(),e=this.dataset.position||"bottom",s=this.#n(),o,i;switch(e.split("-")[0]){case"top":o=t.top-this.offsetHeight-s,i=t.left;break;case"left":o=t.top,i=t.left-this.offsetWidth-s;break;case"right":o=t.top,i=t.right+s;break;default:o=t.bottom+s,i=t.left;break}e.endsWith("-end")&&(e.startsWith("top")||e.startsWith("bottom")?i=t.right-this.offsetWidth:o=t.bottom-this.offsetHeight),this.style.position="fixed",this.style.top=`${Math.round(o)}px`,this.style.left=`${Math.round(i)}px`,this.style.margin="0"}#n(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset]??t.xs}};c("pop-over",d);var A=0,f=class extends l{static formAssociated=!0;#e;#t;#i;#s;#c=[];#a=[];#l=-1;#o=!1;#n="";#f="";#w="";#p;#A;#r=[];constructor(){super(),this.#e=this.attachInternals(),this._adoptInternals(this.#e)}get#h(){return this.hasAttribute("multiple")}setup(){let t=this.querySelector(":scope > input")||this.querySelector(":scope > .tags-input-area > input");if(!t)return!1;this.#t=t;let e=this.querySelector("ul, ol");if(!e)return!1;if(this.#i=e,this.#h){let r=this.querySelector(":scope > .tags-input-area");if(!r){r=document.createElement("div"),r.className="tags-input-area";let m=this.querySelector(":scope > pop-over[data-combobox-host]")||this.#i;this.insertBefore(r,m)}this.#p=r,this.#t.parentNode!==this.#p&&this.#p.appendChild(this.#t);let a=this.querySelector(":scope > [data-combobox-live]");a||(a=document.createElement("div"),a.setAttribute("aria-live","polite"),a.setAttribute("aria-atomic","true"),a.setAttribute("data-combobox-live",""),a.className="visually-hidden",this.appendChild(a)),this.#A=a}let s=this.getAttribute("placeholder");s&&!this.#t.getAttribute("placeholder")&&this.#t.setAttribute("placeholder",s);let o=`cb${++A}`;this.#i.id||(this.#i.id=`combobox-listbox-${o}`),b(this.#t,this.#e,"combobox"),this.#t.setAttribute("aria-expanded","false"),this.#t.setAttribute("aria-autocomplete","list"),this.#t.setAttribute("aria-controls",this.#i.id),this.#t.setAttribute("autocomplete","off"),this.#i.setAttribute("role","listbox"),this.#h&&this.#i.setAttribute("aria-multiselectable","true");let i=this.#h?this.#p:this.#t;i.id||(i.id=`combobox-anchor-${o}`);let n=this.querySelector(":scope > pop-over[data-combobox-host]");if(n?this.#s=n:(this.#s=document.createElement("pop-over"),this.#s.setAttribute("data-combobox-host",""),this.#s.id=`combobox-pop-${o}`,this.#s.dataset.mode="manual",this.#s.dataset.position="bottom-start",this.#s.dataset.anchor=i.id,this.#s.appendChild(this.#i),this.appendChild(this.#s)),this.#s.dataset.anchor=i.id,this.#i.parentElement!==this.#s&&this.#s.appendChild(this.#i),this.#M(),!this.#h){let r=this.getAttribute("value");r&&this.#g(r,!1),this.#w=this.#n}return this.listen(this.#t,"input",this.#V),this.listen(this.#t,"keydown",this.#D),this.listen(this.#t,"focus",this.#P),this.listen(this.#t,"click",this.#B),this.listen(this.#i,"click",this.#T),this.listen(this.#i,"pointerdown",this.#F),this.listen(document,"click",this.#I),this.listen(this.#s,"pop-over:hide",this.#N),this.#u(),this.#d(),this.#b(),!0}teardown(){}#M(){this.#c=Array.from(this.#i.querySelectorAll(":scope > li[data-value]")),this.#c.forEach((t,e)=>{t.setAttribute("role","option"),t.setAttribute("aria-selected","false"),t.id||(t.id=`${this.#i.id}-option-${e}`)}),this.#a=[...this.#c]}#y(t,e){if(this.#r.some(r=>r.value===t))return;let s=this.#$();if(s&&this.#r.length>=s)return;this.#r.push({value:t,label:e});let o=document.createElement("span");o.className="tag",o.dataset.value=t,o.textContent=e+" ";let i=document.createElement("button");i.type="button",i.setAttribute("aria-label",`Remove ${e}`),i.innerHTML="×",i.addEventListener("click",r=>{r.stopPropagation(),this.#k(t)}),o.appendChild(i),this.#p.insertBefore(o,this.#t);let n=this.#c.find(r=>r.getAttribute("data-value")===t);n&&n.setAttribute("aria-selected","true"),this.#S(`${e} added`),this.#t.value="",this.#m(""),this.#u(),this.#d(),this.#q(),s&&this.#r.length>=s&&(this.#t.disabled=!0,this.#b())}#k(t){let e=this.#r.findIndex(r=>r.value===t);if(e===-1)return;let s=this.#r.splice(e,1)[0],o=this.#p.querySelector(`.tag[data-value="${CSS.escape(t)}"]`);o&&o.remove();let i=this.#c.find(r=>r.getAttribute("data-value")===t);i&&i.setAttribute("aria-selected","false"),this.#S(`${s.label} removed`),this.#$()&&this.#t.disabled&&(this.#t.disabled=!1),this.#m(this.#t.value.trim()),this.#u(),this.#d(),this.#q(),this.#t.focus()}#$(){let t=this.getAttribute("max");return t?parseInt(t,10):0}#S(t){this.#A&&(this.#A.textContent="",requestAnimationFrame(()=>{this.#A.textContent=t}))}#V=()=>{let t=this.#t.value.trim();if(!this.#h&&this.#n){let e=this.#i.querySelector('[aria-selected="true"]');e&&e.setAttribute("aria-selected","false"),this.#n="",this.#f="",this.removeAttribute("value"),this.#u(),this.#d()}this.#m(t),this.#v()};#D=t=>{switch(t.key){case"ArrowDown":t.preventDefault(),this.#o||this.#v(),this.#E(this.#l+1);break;case"ArrowUp":t.preventDefault(),this.#o||this.#v(),this.#E(this.#l-1);break;case"Home":this.#o&&(t.preventDefault(),this.#E(0));break;case"End":this.#o&&(t.preventDefault(),this.#E(this.#a.length-1));break;case"Enter":if(t.preventDefault(),this.#o&&this.#l>=0&&this.#a[this.#l]){let e=this.#a[this.#l];this.#h?this.#y(e.getAttribute("data-value"),e.textContent.trim()):this.#C(e)}else if(this.#h&&this.hasAttribute("custom")&&this.#t.value.trim()){let e=this.#t.value.trim();this.#y(e,e)}break;case"Backspace":if(this.#h&&!this.#t.value&&this.#r.length>0){let e=this.#r[this.#r.length-1];this.#k(e.value)}break;case",":if(this.#h&&this.hasAttribute("custom")&&this.#t.value.trim()){t.preventDefault();let e=this.#t.value.trim();this.#y(e,e)}break;case"Escape":this.#o&&(t.preventDefault(),t.stopPropagation(),this.#b(),this.#t.focus());break;case"Tab":this.#o&&this.#b();break}};#P=()=>{this.#h?(this.#m(this.#t.value.trim()),this.#v()):(this.#t.value||!this.#n)&&(this.#m(this.#t.value.trim()),this.#v())};#B=()=>{this.#o||(this.#m(this.#t.value.trim()),this.#v())};#T=t=>{let e=t.target.closest("li[data-value]");e&&this.#a.includes(e)&&(this.#h?this.#y(e.getAttribute("data-value"),e.textContent.trim()):this.#C(e))};#F=t=>{t.preventDefault()};#I=t=>{this.#o&&!this.contains(t.target)&&this.#b()};#m(t){let e=this.getAttribute("filter")||"contains",s=t.toLowerCase(),o=this.#h?new Set(this.#r.map(i=>i.value)):null;this.#a=[],this.#c.forEach(i=>{let n=i.getAttribute("data-value"),r=i.textContent.trim().toLowerCase();if(o&&o.has(n)){i.hidden=!0;return}let a;t?e==="startsWith"?a=r.startsWith(s):a=r.includes(s):a=!0,i.hidden=!a,a&&this.#a.push(i)}),this.#l=-1,this.#x(),this.setState("no-matches",this.#a.length===0)}#E(t){if(this.#a.length===0)return;t<0&&(t=this.#a.length-1),t>=this.#a.length&&(t=0),this.#l>=0&&this.#a[this.#l]&&this.#a[this.#l].removeAttribute("data-active"),this.#l=t;let e=this.#a[t];e.setAttribute("data-active",""),e.scrollIntoView({block:"nearest"}),this.#t.setAttribute("aria-activedescendant",e.id)}#x(){this.#c.forEach(t=>t.removeAttribute("data-active")),this.#t.removeAttribute("aria-activedescendant")}#C(t,e="internal"){let s=t.getAttribute("data-value")||"",o=t.textContent.trim();this.#n!==s&&(this.#c.forEach(i=>i.setAttribute("aria-selected","false")),t.setAttribute("aria-selected","true"),this.#n=s,this.#f=o,this.#t.value=o,this.setAttribute("value",s),this.#u(),this.#d(),this.#b(),this.#t.focus(),this.dispatchEvent(new CustomEvent("combo-box:change",{bubbles:!0,detail:{value:s,label:o,source:e}})))}#g(t,e=!0,s="api"){let o=this.#c.find(i=>i.getAttribute("data-value")===t);o&&(e?this.#C(o,s):(o.setAttribute("aria-selected","true"),this.#n=t,this.#f=o.textContent.trim(),this.#t.value=this.#f,this.setAttribute("value",t)))}#v(){this.#o||(this.#o=!0,this.setAttribute("open",""),this.#t.setAttribute("aria-expanded","true"),this.#s?.show(),this.dispatchEvent(new CustomEvent("combo-box:open",{bubbles:!0})))}#b(){this.#o&&(this.#o=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#l=-1,this.#x(),this.#s?.hide(),this.dispatchEvent(new CustomEvent("combo-box:close",{bubbles:!0})))}#N=()=>{this.#o&&(this.#o=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#l=-1,this.#x(),this.dispatchEvent(new CustomEvent("combo-box:close",{bubbles:!0})))};#u(){if(this.#h)if(this.#r.length>0){let t=new FormData,e=this.getAttribute("name")||"";for(let s of this.#r)t.append(e,s.value);this.#e.setFormValue(t)}else this.#e.setFormValue(null);else this.#n?this.#e.setFormValue(this.#n,this.#f):this.#e.setFormValue(null)}#d(){this.hasAttribute("required")?this.#h?this.#r.length===0?this.#e.setValidity({valueMissing:!0},"Please select at least one option",this.#t):this.#e.setValidity({}):this.#n?this.#e.setValidity({}):this.#e.setValidity({valueMissing:!0},"Please select an option",this.#t):this.#e.setValidity({})}#q(){this.dispatchEvent(new CustomEvent("combo-box:change",{bubbles:!0,detail:{values:this.#r.map(t=>t.value),labels:this.#r.map(t=>t.label)}}))}formResetCallback(){this.#h?(this.#p.querySelectorAll(".tag").forEach(t=>t.remove()),this.#r=[],this.#t.value="",this.#t.disabled=!1):(this.#n="",this.#f="",this.#t.value="",this.removeAttribute("value")),this.#c.forEach(t=>{t.setAttribute("aria-selected","false"),t.hidden=!1}),this.#a=[...this.#c],this.#l=-1,this.#x(),this.#b(),!this.#h&&this.#w&&this.#g(this.#w,!1),this.#u(),this.#d()}formStateRestoreCallback(t){t&&(this.#h||(this.#g(t,!1),this.#u(),this.#d()))}get value(){return this.#n}set value(t){t?this.#g(t):(this.#c.forEach(e=>e.setAttribute("aria-selected","false")),this.#n="",this.#f="",this.#t.value="",this.removeAttribute("value"),this.#u(),this.#d())}get label(){return this.#f}get values(){return this.#r.map(t=>t.value)}get labels(){return this.#r.map(t=>t.label)}static get observedAttributes(){return["value"]}attributeChangedCallback(t,e,s){t==="value"&&this.#t&&s!==this.#n&&s&&(this.#g(s,!1),this.#u(),this.#d())}};c("combo-box",f);export{f as ComboBox};
|
|
1
|
+
var N=window.matchMedia("(prefers-reduced-motion: reduce)");var E=new Map;function p(h,t,e={}){let i=e.priority??10,o={impl:t,bundle:e.bundle,contract:e.contract,priority:i},s=E.get(h);if(customElements.get(h)){if(!s||s.priority>=i){s&&s.priority===i&&s.impl!==t&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${s.bundle}" (priority ${s.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${h}> defined by "${s.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(s&&s.priority>=i){s.priority===i&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${s.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}E.set(h,o),customElements.define(h,t)}var d=class extends HTMLElement{#e=[];#t;constructor(){super(),this.hasAttribute("data-upgraded")&&this.removeAttribute("data-upgraded")}connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#e)t();this.#e=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,i,o){t.addEventListener(e,i,o),this.#e.push(()=>t.removeEventListener(e,i,o))}_reinit(){for(let t of this.#e)t();this.#e=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(t,e){this.#t||(this.#t=this.attachInternals());let i=this.#t.states;try{e?i.add(t):i.delete(t)}catch{let o=`--${t}`;e?i.add(o):i.delete(o)}}_adoptInternals(t){this.#t||(this.#t=t)}#i(){return this.constructor.formAssociated&&this.#t?this.#t:null}get validity(){return this.#i()?.validity}get validationMessage(){return this.#i()?.validationMessage??""}get willValidate(){return this.#i()?.willValidate??!1}get form(){return this.#i()?.form??null}checkValidity(){return this.#i()?.checkValidity()??!0}reportValidity(){return this.#i()?.reportValidity()??!0}};var b=CSS.supports("anchor-name","--x"),S=CSS.supports("position-area","bottom"),$=(()=>{let h=document.createElement("span");return h.setAttribute("popover","hint"),h.popover==="hint"})(),V=["auto","manual","hint"];function M(h){let t=V.includes(h||"")?h:"auto";return t==="hint"&&!$?"auto":t}var P=["top","bottom","left","right","inset-inline-start","inset-inline-end"],q=["position","top","left","right","bottom","margin"],x=8,D=0,O=0;function w(h){return!h||h==="none"?[]:h.split(",").map(t=>t.trim()).filter(Boolean)}var v=class extends d{static get observedAttributes(){return["data-mode","data-anchor","data-position"]}#e=null;#t=null;#i=`--pop-over-anchor-${++O}`;#s=!1;#h=!1;#o=!1;setup(){if(this.id||(this.id=`pop-over-${++D}`),(!this.hasAttribute("popover")||this.#s)&&this.#l(),this.#n(),this.#c(),this.listen(this,"beforetoggle",t=>{let e=t.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${e}`,{detail:{state:t.newState},bubbles:!0,composed:!0})),!b&&t.newState==="open"&&this.#e&&queueMicrotask(()=>{this.matches(":popover-open")&&this.#f()})}),!b){let t=()=>{this.matches(":popover-open")&&this.#e&&this.#f()};this.listen(window,"resize",t),this.listen(window,"scroll",t,{capture:!0,passive:!0})}}teardown(){this.#d(),this.#h&&(P.forEach(t=>this.style.removeProperty(t)),this.#h=!1),this.#o&&(q.forEach(t=>this.style.removeProperty(t)),this.#o=!1),this.#e=null}attributeChangedCallback(t,e,i){if(e!==i){if(!this.hasAttribute("data-upgraded")){t==="data-mode"&&this.hasAttribute("popover")&&!this.isConnected&&(this.#s=!0);return}if(t==="data-mode"){this.#l();return}this._reinit()}}#l(){let t=M(this.dataset.mode);this.getAttribute("popover")!==t&&this.setAttribute("popover",t),this.#s=!0}show(){this.matches(":popover-open")||(this.showPopover(),!b&&this.#e&&this.matches(":popover-open")&&this.#f())}hide(){this.matches(":popover-open")&&this.hidePopover()}toggle(){this.matches(":popover-open")?this.hide():this.show()}get open(){return this.matches(":popover-open")}#n(){let t=this.dataset.anchor;if(t){let e=document.getElementById(t);if(!e)try{e=document.querySelector(t)}catch{e=null}this.#e=e}else this.#e=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#c(){if(!this.#e||!b)return;let t=this.#e,e=t.style.getPropertyValue("anchor-name"),i=w(e||getComputedStyle(t).getPropertyValue("anchor-name"));i.includes(this.#i)||i.push(this.#i),t.style.setProperty("anchor-name",i.join(", ")),this.#t=this.#i,this.style.setProperty("position-anchor",this.#i),this.setAttribute("data-anchor-name",this.#i),S||this.#v(this.dataset.position||"bottom")}#d(){if(this.#e&&this.#t){let t=w(this.#e.style.getPropertyValue("anchor-name")).filter(e=>e!==this.#t);t.length?this.#e.style.setProperty("anchor-name",t.join(", ")):this.#e.style.removeProperty("anchor-name")}this.#t=null,this.style.getPropertyValue("position-anchor")&&this.style.removeProperty("position-anchor"),this.hasAttribute("data-anchor-name")&&this.removeAttribute("data-anchor-name")}#v(t){let e="var(--_pop-over-offset, var(--size-xs))",i=t.endsWith("-end")?{"inset-inline-end":"anchor(end)"}:{"inset-inline-start":"anchor(start)"},o={top:{bottom:`calc(anchor(top) + ${e})`,...i},bottom:{top:`calc(anchor(bottom) + ${e})`,...i},left:{right:`calc(anchor(left) + ${e})`,top:"anchor(top)"},right:{left:`calc(anchor(right) + ${e})`,top:"anchor(top)"}},s=t.split("-")[0],n=o[s]||o.bottom;Object.entries(n).forEach(([a,r])=>this.style.setProperty(a,r)),this.#h=!0}#f(){if(!this.#e)return;let t=this.#e.getBoundingClientRect(),e=this.dataset.position||"bottom",i=this.#u(),o=document.documentElement.clientWidth,s=document.documentElement.clientHeight;this.style.position="fixed",this.style.margin="0",this.style.right="auto",this.style.bottom="auto",this.#o=!0;let n=this.offsetWidth,a=this.offsetHeight,r=e.split("-")[0];["top","bottom","left","right"].includes(r)||(r="bottom");let l={top:t.top-i,bottom:s-t.bottom-i,left:t.left-i,right:o-t.right-i},f={top:"bottom",bottom:"top",left:"right",right:"left"},C=r==="top"||r==="bottom"?a:n;l[r]<C&&l[f[r]]>l[r]&&(r=f[r]);let c,u;switch(r){case"top":c=t.top-a-i,u=t.left;break;case"left":c=t.top,u=t.left-n-i;break;case"right":c=t.top,u=t.right+i;break;default:c=t.bottom+i,u=t.left;break}if(r==="top"||r==="bottom"){let m=getComputedStyle(this).direction==="rtl";u=e.endsWith("-end")!==m?t.right-n:t.left}else e.endsWith("-end")&&(c=t.bottom-a);let A=(m,y,k)=>Math.max(x,Math.min(m,k-y-x));u=A(u,n,o),c=A(c,a,s),this.style.top=`${Math.round(c)}px`,this.style.left=`${Math.round(u)}px`}#u(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset||""]??t.xs}};p("pop-over",v);var I=0,g=class extends d{static formAssociated=!0;#e;#t;#i;#s;#h=[];#o=[];#l=-1;#n=!1;#c="";#d="";#v;#f=!1;#u;#E;#r=[];constructor(){super(),this.#e=this.attachInternals(),this._adoptInternals(this.#e)}get#a(){return this.hasAttribute("multiple")}setup(){let t=this.querySelector(":scope > input")||this.querySelector(":scope > .tags-input-area > input");if(!t)return!1;this.#t=t;let e=this.#t.getAttribute("name");e&&(this.hasAttribute("name")||this.setAttribute("name",e),this.#t.removeAttribute("name"));let i=this.querySelector("ul, ol");if(!i)return!1;if(this.#i=i,this.#a){let r=this.querySelector(":scope > .tags-input-area");if(!r){r=document.createElement("div"),r.className="tags-input-area";let f=this.querySelector(":scope > pop-over[data-combobox-host]")||this.#i;this.insertBefore(r,f)}this.#u=r,this.#t.parentNode!==this.#u&&this.#u.appendChild(this.#t);let l=this.querySelector(":scope > [data-combobox-live]");l||(l=document.createElement("div"),l.setAttribute("aria-live","polite"),l.setAttribute("aria-atomic","true"),l.setAttribute("data-combobox-live",""),l.className="visually-hidden",this.appendChild(l)),this.#E=l}let o=this.getAttribute("placeholder");o&&!this.#t.getAttribute("placeholder")&&this.#t.setAttribute("placeholder",o);let s=`cb${++I}`;this.#i.id||(this.#i.id=`combobox-listbox-${s}`),this.#t.setAttribute("role","combobox"),this.#t.setAttribute("aria-expanded","false"),this.#t.setAttribute("aria-autocomplete","list"),this.#t.setAttribute("aria-controls",this.#i.id),this.#t.setAttribute("autocomplete","off"),this.#i.setAttribute("role","listbox"),this.#a&&this.#i.setAttribute("aria-multiselectable","true");let n=this.#a?this.#u:this.#t;n.id||(n.id=`combobox-anchor-${s}`);let a=this.querySelector(":scope > pop-over[data-combobox-host]");if(a?this.#s=a:(this.#s=document.createElement("pop-over"),this.#s.setAttribute("data-combobox-host",""),this.#s.id=`combobox-pop-${s}`,this.#s.dataset.mode="manual",this.#s.dataset.position="bottom-start",this.#s.dataset.anchor=n.id,this.#s.appendChild(this.#i),this.appendChild(this.#s)),this.#s.dataset.anchor=n.id,this.#i.parentElement!==this.#s&&this.#s.appendChild(this.#i),this.#O(),!this.#a){let r=this.getAttribute("value");r&&this.#y(r,!1),this.#v===void 0&&(this.#v=this.#c)}return this.listen(this.#t,"input",this.#I),this.listen(this.#t,"keydown",this.#N),this.listen(this.#t,"focus",this.#T),this.listen(this.#t,"click",this.#B),this.listen(this.#i,"click",this.#F),this.listen(this.#i,"pointerdown",this.#L),this.listen(document,"click",this.#R),this.listen(this.#s,"pop-over:hide",this.#_),this.listen(this,"invalid",this.#D),this.#b(),this.#m(),this.#p(),this.#k(this.matches(":disabled")),!0}teardown(){}#D=()=>{this.#t.setAttribute("aria-invalid","true")};formDisabledCallback(t){this.#t&&this.#k(t)}#k(t){this.#f=t,t&&this.#p();let e=this.#S(),i=this.#a&&e>0&&this.#r.length>=e;if(this.#t.disabled=t||i,this.#u)for(let o of this.#u.querySelectorAll(".tag button"))o.disabled=t}#O(){this.#h=Array.from(this.#i.querySelectorAll(":scope > li[data-value]")),this.#h.forEach((t,e)=>{t.setAttribute("role","option"),t.setAttribute("aria-selected","false"),t.id||(t.id=`${this.#i.id}-option-${e}`)}),this.#o=[...this.#h]}#x(t,e){if(this.#r.some(a=>a.value===t))return;let i=this.#S();if(i&&this.#r.length>=i)return;this.#r.push({value:t,label:e});let o=document.createElement("span");o.className="tag",o.dataset.value=t,o.textContent=e+" ";let s=document.createElement("button");s.type="button",s.setAttribute("aria-label",`Remove ${e}`),s.innerHTML="×",s.disabled=this.#f,s.addEventListener("click",a=>{a.stopPropagation(),this.#V(t)}),o.appendChild(s),this.#u.insertBefore(o,this.#t);let n=this.#h.find(a=>a.getAttribute("data-value")===t);n&&n.setAttribute("aria-selected","true"),this.#M(`${e} added`),this.#t.value="",this.#g(""),this.#b(),this.#m(),this.#P(),i&&this.#r.length>=i&&(this.#t.disabled=!0,this.#p())}#V(t){let e=this.#r.findIndex(a=>a.value===t);if(e===-1)return;let i=this.#r.splice(e,1)[0],o=this.#u.querySelector(`.tag[data-value="${CSS.escape(t)}"]`);o&&o.remove();let s=this.#h.find(a=>a.getAttribute("data-value")===t);s&&s.setAttribute("aria-selected","false"),this.#M(`${i.label} removed`),this.#S()&&this.#t.disabled&&(this.#t.disabled=this.#f),this.#g(this.#t.value.trim()),this.#b(),this.#m(),this.#P(),this.#t.focus()}#S(){let t=this.getAttribute("max");return t?parseInt(t,10):0}#M(t){this.#E&&(this.#E.textContent="",requestAnimationFrame(()=>{this.#E.textContent=t}))}#I=()=>{let t=this.#t.value.trim();if(!this.#a&&this.#c){let e=this.#i.querySelector('[aria-selected="true"]');e&&e.setAttribute("aria-selected","false"),this.#c="",this.#d="",this.removeAttribute("value"),this.#b(),this.#m()}this.#g(t),this.#A()};#N=t=>{switch(t.key){case"ArrowDown":t.preventDefault(),this.#n||this.#A(),this.#w(this.#l+1);break;case"ArrowUp":t.preventDefault(),this.#n||this.#A(),this.#w(this.#l-1);break;case"Home":this.#n&&(t.preventDefault(),this.#w(0));break;case"End":this.#n&&(t.preventDefault(),this.#w(this.#o.length-1));break;case"Enter":if(t.preventDefault(),this.#n&&this.#l>=0&&this.#o[this.#l]){let e=this.#o[this.#l];this.#a?this.#x(e.getAttribute("data-value"),e.textContent.trim()):this.#$(e)}else if(this.#a&&this.hasAttribute("custom")&&this.#t.value.trim()){let e=this.#t.value.trim();this.#x(e,e)}break;case"Backspace":if(this.#a&&!this.#t.value&&this.#r.length>0){let e=this.#r[this.#r.length-1];this.#V(e.value)}break;case",":if(this.#a&&this.hasAttribute("custom")&&this.#t.value.trim()){t.preventDefault();let e=this.#t.value.trim();this.#x(e,e)}break;case"Escape":this.#n&&(t.preventDefault(),t.stopPropagation(),this.#p(),this.#t.focus());break;case"Tab":this.#n&&this.#p();break}};#T=()=>{this.#a?(this.#g(this.#t.value.trim()),this.#A()):(this.#t.value||!this.#c)&&(this.#g(this.#t.value.trim()),this.#A())};#B=()=>{this.#n||(this.#g(this.#t.value.trim()),this.#A())};#F=t=>{let e=t.target.closest("li[data-value]");e&&this.#o.includes(e)&&(this.#a?this.#x(e.getAttribute("data-value"),e.textContent.trim()):this.#$(e))};#L=t=>{t.preventDefault()};#R=t=>{this.#n&&!this.contains(t.target)&&this.#p()};#g(t){let e=this.getAttribute("filter")||"contains",i=t.toLowerCase(),o=this.#a?new Set(this.#r.map(s=>s.value)):null;this.#o=[],this.#h.forEach(s=>{let n=s.getAttribute("data-value"),a=s.textContent.trim().toLowerCase();if(o&&o.has(n)){s.hidden=!0;return}let r;t?e==="startsWith"?r=a.startsWith(i):r=a.includes(i):r=!0,s.hidden=!r,r&&this.#o.push(s)}),this.#l=-1,this.#C(),this.setState("no-matches",this.#o.length===0)}#w(t){if(this.#o.length===0)return;t<0&&(t=this.#o.length-1),t>=this.#o.length&&(t=0),this.#l>=0&&this.#o[this.#l]&&this.#o[this.#l].removeAttribute("data-active"),this.#l=t;let e=this.#o[t];e.setAttribute("data-active",""),e.scrollIntoView({block:"nearest"}),this.#t.setAttribute("aria-activedescendant",e.id)}#C(){this.#h.forEach(t=>t.removeAttribute("data-active")),this.#t.removeAttribute("aria-activedescendant")}#$(t,e="internal"){let i=t.getAttribute("data-value")||"",o=t.textContent.trim();if(this.#c===i){this.#t.value=o,this.#p(),this.#t.focus();return}this.#h.forEach(s=>s.setAttribute("aria-selected","false")),t.setAttribute("aria-selected","true"),this.#c=i,this.#d=o,this.#t.value=o,this.setAttribute("value",i),this.#b(),this.#m(),this.#p(),this.#t.focus(),this.dispatchEvent(new CustomEvent("combo-box:change",{bubbles:!0,detail:{value:i,label:o,source:e}}))}#y(t,e=!0,i="api"){let o=this.#h.find(s=>s.getAttribute("data-value")===t);o&&(e?this.#$(o,i):(this.#h.forEach(s=>s.setAttribute("aria-selected","false")),o.setAttribute("aria-selected","true"),this.#c=t,this.#d=o.textContent.trim(),this.#t.value=this.#d,this.setAttribute("value",t)))}#A(){this.#n||this.#f||(this.#n=!0,this.setAttribute("open",""),this.#t.setAttribute("aria-expanded","true"),this.#s?.show(),this.dispatchEvent(new CustomEvent("combo-box:open",{bubbles:!0})))}#p(){this.#n&&(this.#n=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#l=-1,this.#C(),this.#s?.hide(),this.dispatchEvent(new CustomEvent("combo-box:close",{bubbles:!0})))}#_=()=>{this.#n&&(this.#n=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#l=-1,this.#C(),this.dispatchEvent(new CustomEvent("combo-box:close",{bubbles:!0})))};#b(){if(this.#a)if(this.#r.length>0){let t=new FormData,e=this.getAttribute("name")||"";for(let i of this.#r)t.append(e,i.value);this.#e.setFormValue(t)}else this.#e.setFormValue(null);else this.#c?this.#e.setFormValue(this.#c,this.#d):this.#e.setFormValue(null)}#m(){this.hasAttribute("required")?this.#a?this.#r.length===0?this.#e.setValidity({valueMissing:!0},"Please select at least one option",this.#t):this.#e.setValidity({}):this.#c?this.#e.setValidity({}):this.#e.setValidity({valueMissing:!0},"Please select an option",this.#t):this.#e.setValidity({}),this.#e.validity.valid&&this.#t.removeAttribute("aria-invalid")}#P(){this.dispatchEvent(new CustomEvent("combo-box:change",{bubbles:!0,detail:{values:this.#r.map(t=>t.value),labels:this.#r.map(t=>t.label),source:"internal"}}))}formResetCallback(){this.#a?(this.#u.querySelectorAll(".tag").forEach(t=>t.remove()),this.#r=[],this.#t.value="",this.#t.disabled=this.#f):(this.#c="",this.#d="",this.#t.value="",this.removeAttribute("value")),this.#h.forEach(t=>{t.setAttribute("aria-selected","false"),t.hidden=!1}),this.#o=[...this.#h],this.#l=-1,this.#C(),this.#p(),this.#t.removeAttribute("aria-invalid"),!this.#a&&this.#v&&this.#y(this.#v,!1),this.#b(),this.#m()}formStateRestoreCallback(t){t&&(this.#a||(this.#y(t,!1),this.#b(),this.#m()))}get value(){return this.#c}set value(t){t?this.#y(t):this.#q()}#q(){this.#h.forEach(t=>t.setAttribute("aria-selected","false")),this.#c="",this.#d="",this.#t&&(this.#t.value=""),this.removeAttribute("value"),this.#b(),this.#m()}get label(){return this.#d}get values(){return this.#r.map(t=>t.value)}get labels(){return this.#r.map(t=>t.label)}static get observedAttributes(){return["value","disabled"]}attributeChangedCallback(t,e,i){if(!this.#t)return;if(t==="disabled"){this.#k(this.matches(":disabled"));return}let o=i??"";t==="value"&&o!==this.#c&&(o?(this.#y(o,!1),this.#b(),this.#m()):this.#q())}};p("combo-box",g);export{g as ComboBox};
|
|
2
2
|
//# sourceMappingURL=combo-box.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var f=/Mac|iPhone|iPad|iPod/.test(navigator.platform??""),v={mac:{meta:"\u2318",cmd:"\u2318",alt:"\u2325",shift:"\u21E7",ctrl:"\u2303"},other:{meta:"Ctrl",cmd:"Ctrl",alt:"Alt",shift:"Shift",ctrl:"Ctrl"}};function b(r){let e=f?v.mac:v.other;return r.split("+").map(t=>{let n=t.trim().toLowerCase();return e[n]??n.toUpperCase()}).join(f?"":"+")}function k(r){let e=r.toLowerCase().split("+").map(n=>n.trim());return{key:e.pop()??"",meta:e.includes("meta")||e.includes("cmd"),ctrl:e.includes("ctrl"),shift:e.includes("shift"),alt:e.includes("alt")}}function C(r,e){if(r.key.toLowerCase()!==e.key)return!1;let t,n;return f?(t=e.meta,n=e.ctrl):(t=!1,n=e.meta||e.ctrl),!(t!==r.metaKey||n!==r.ctrlKey||e.shift!==r.shiftKey||e.alt!==r.altKey)}var x=new Set(["INPUT","TEXTAREA","SELECT"]),h=[],A=!1;function L(r){let e=x.has(r.target.tagName)||r.target.isContentEditable;for(let t of h)if(!(e&&!t.global)&&C(r,t.descriptor)){r.preventDefault(),t.callback(r);return}}function M(){A||(document.addEventListener("keydown",L),A=!0)}function w(r,e,t={}){M();let n=k(r),s={combo:r,descriptor:n,callback:e,global:t.global===!0};return h.find(a=>a.combo===r)&&console.warn(`[hotkey-bind] Shortcut "${r}" already bound. Last-connected-wins.`),h.unshift(s),function(){let o=h.indexOf(s);o!==-1&&h.splice(o,1)}}var H=window.matchMedia("(prefers-reduced-motion: reduce)");var N=new Map;function m(r,e,t={}){let n=t.priority??10,s={impl:e,bundle:t.bundle,contract:t.contract,priority:n},i=N.get(r);if(customElements.get(r)){if(!i||i.priority>=n){i&&i.priority===n&&i.impl!==e&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${i.bundle}" (priority ${i.priority}). Skipping "${t.bundle}".`);return}console.warn(`[VB Bundle] Tag <${r}> defined by "${i.bundle}" cannot be replaced (customElements.define is permanent). "${t.bundle}" has higher priority but arrived late.`);return}if(i&&i.priority>=n){i.priority===n&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${i.bundle}". Skipping "${t.bundle}" (first wins at equal priority).`);return}N.set(r,s),customElements.define(r,e)}var p=class extends HTMLElement{#e=[];#t;connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let e of this.#e)e();this.#e=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(e,t,n,s){e.addEventListener(t,n,s),this.#e.push(()=>e.removeEventListener(t,n,s))}setup(){}teardown(){}setState(e,t){this.#t||(this.#t=this.attachInternals());let n=this.#t.states;try{t?n.add(e):n.delete(e)}catch{let s=`--${e}`;t?n.add(s):n.delete(s)}}_adoptInternals(e){this.#t||(this.#t=e)}};var y=class extends p{#e;#t;#n;#s=[];#o=-1;#r=[];#l=null;#i=[];setup(){this.#m(),this.#p(),this.hasAttribute("discover")&&this.#y()}teardown(){this.#l?.()}get commands(){let e=[];for(let t of this.#r){let n=t.getAttribute("label")||"";for(let s of t.querySelectorAll("command-item"))e.push({value:s.getAttribute("value")||"",label:s.textContent.trim(),hotkey:s.getAttribute("data-hotkey")||void 0,group:n||void 0})}return e}set commands(e){let t=Array.isArray(e)?e:[],n=new Map;for(let s of t){let i=s.group||"";n.has(i)||n.set(i,[]),n.get(i).push(s)}for(let s of[...this.children])(s.tagName==="COMMAND-GROUP"||s.tagName==="COMMAND-ITEM")&&s.remove();for(let[s,i]of n){let a=document.createElement("command-group");s&&a.setAttribute("label",s);for(let o of i){let c=document.createElement("command-item");if(o.value&&c.setAttribute("value",o.value),o.hotkey&&c.setAttribute("data-hotkey",o.hotkey),o.icon){let l=document.createElement("span");l.setAttribute("slot","icon"),l.innerHTML=o.icon,c.appendChild(l)}c.appendChild(document.createTextNode(o.label||o.value||"")),a.appendChild(c)}this.appendChild(a)}this.teardown(),this.removeAttribute("data-upgraded"),this.setup(),this.dispatchEvent(new CustomEvent("command-palette:commands-changed",{detail:{commands:t,source:"property"},bubbles:!0}))}#m(){this.#e=document.createElement("dialog"),this.#e.className="command-dialog",this.#e.addEventListener("click",n=>{n.target===this.#e&&this.close()});let e=document.createElement("div");e.className="command-search",this.#t=document.createElement("input"),this.#t.type="search",this.#t.placeholder=this.getAttribute("placeholder")||"Type a command...",this.#t.setAttribute("aria-label","Search commands"),this.#t.autocomplete="off",this.#t.addEventListener("input",this.#a),this.#t.addEventListener("keydown",this.#f),e.appendChild(this.#t),this.#n=document.createElement("div"),this.#n.className="command-list",this.#n.setAttribute("role","listbox"),this.#r=Array.from(this.querySelectorAll("command-group")),this.#r.forEach(n=>{let s=document.createElement("div");s.className="command-group-header",s.textContent=n.getAttribute("label")||"",s.setAttribute("role","presentation");let i=Array.from(n.querySelectorAll("command-item"));this.#n.appendChild(s),i.forEach(a=>{let o=document.createElement("button");o.className="command-option",o.setAttribute("role","option"),o.dataset.value=a.getAttribute("value")||"",o.dataset.searchText=a.textContent.toLowerCase().trim();let c=a.querySelector('[slot="icon"]');if(c){let d=document.createElement("span");d.className="command-icon",d.appendChild(c.cloneNode(!0)),o.appendChild(d)}let l=document.createElement("span");l.className="command-label",l.textContent=a.textContent.trim(),o.appendChild(l);let u=a.getAttribute("data-hotkey");if(u){let d=document.createElement("kbd");d.className="command-kbd",d.textContent=b(u),o.appendChild(d)}o.addEventListener("click",()=>{this.#b(o.dataset.value)}),this.#n.appendChild(o),this.#s.push({btn:o,header:s,group:n})})});let t=document.createElement("div");t.className="command-empty",t.textContent="No results found.",t.hidden=!0,this.#n.appendChild(t),this.#e.appendChild(e),this.#e.appendChild(this.#n),this.appendChild(this.#e)}#p(){let e=this.getAttribute("hotkey")||"meta+k";this.#l=w(e,()=>{this.#e.open?this.close():this.open()},{global:!0})}#a=()=>{let e=this.#t.value.toLowerCase().trim(),t=0,n=new Set;this.#s.forEach(({btn:i,header:a})=>{let o=!e||i.dataset.searchText.includes(e);i.hidden=!o,o&&(t++,n.add(a))}),this.#n.querySelectorAll(".command-group-header").forEach(i=>{i.hidden=!n.has(i)});let s=this.#n.querySelector(".command-empty");s&&(s.hidden=t>0),this.#o=-1,t>0&&this.#c(0)};#f=e=>{let t=this.#d();switch(e.key){case"ArrowDown":e.preventDefault(),this.#c(this.#o+1);break;case"ArrowUp":e.preventDefault(),this.#c(this.#o-1);break;case"Enter":e.preventDefault(),this.#o>=0&&t[this.#o]&&t[this.#o].btn.click();break;case"Escape":e.preventDefault(),this.close();break}};#d(){return this.#s.filter(({btn:e})=>!e.hidden)}#c(e){let t=this.#d();if(t.length===0)return;t.forEach(({btn:s})=>s.removeAttribute("data-active")),e<0&&(e=t.length-1),e>=t.length&&(e=0),this.#o=e;let{btn:n}=t[e];n.setAttribute("data-active",""),n.scrollIntoView({block:"nearest"})}#b(e){this.close(),this.dispatchEvent(new CustomEvent("command-palette:select",{bubbles:!0,detail:{value:e}}))}#y(){this.listen(document,"vb:command-registry-change",this.#g)}#g=()=>{this.#e?.open&&(this.#u(),this.#a())};#u(){if(!this.hasAttribute("discover"))return;let{getRegisteredCommands:e,scanAutoDiscoverable:t}=window.__commandRegistry||{};if(!e)return;this.#s=this.#s.filter(i=>!i.discovered),this.#i.forEach(i=>i.remove()),this.#i=[];let n=this.#n.querySelector(".command-empty"),s=e();for(let[i,a]of s){let o=document.createElement("div");o.className="command-group-header",o.textContent=i,o.setAttribute("role","presentation"),this.#n.insertBefore(o,n),this.#i.push(o);for(let c of a){if(this.contains(c.element))continue;let l=this.#h(c.label,c.icon,c.shortcut);l.dataset.value=`__discovered:${c.label}`,l.addEventListener("click",()=>{this.close(),c.element.click()}),this.#n.insertBefore(l,n),this.#s.push({btn:l,header:o,group:null,discovered:!0})}}if(this.getAttribute("discover")==="auto"&&t){let i=t(),a=new Map;for(let o of i){let c=a.get(o.group)||[];c.push(o),a.set(o.group,c)}for(let[o,c]of a){let l=document.createElement("div");l.className="command-group-header",l.textContent=o,l.setAttribute("role","presentation"),this.#n.insertBefore(l,n),this.#i.push(l);for(let u of c){if(this.contains(u.element))continue;let d=this.#h(u.label,u.icon,u.shortcut);d.dataset.value=`__auto:${u.label}`,d.dataset.auto="",d.addEventListener("click",()=>{this.close(),u.action?u.action():u.element.click()}),this.#n.insertBefore(d,n),this.#s.push({btn:d,header:l,group:null,discovered:!0})}}}}#h(e,t,n){let s=document.createElement("button");if(s.className="command-option",s.setAttribute("role","option"),s.dataset.searchText=e.toLowerCase(),t){let a=document.createElement("span");a.className="command-icon";let o=document.createElement("icon-wc");o.setAttribute("name",t),a.appendChild(o),s.appendChild(a)}let i=document.createElement("span");if(i.className="command-label",i.textContent=e,s.appendChild(i),n){let a=document.createElement("kbd");a.className="command-kbd",a.textContent=b(n),s.appendChild(a)}return s}open(){this.#e.open||(this.#u(),this.#e.showModal(),this.#t.value="",this.#a(),this.#t.focus(),this.dispatchEvent(new CustomEvent("command-palette:open",{bubbles:!0})))}close(){this.#e.open&&(this.#e.close(),this.dispatchEvent(new CustomEvent("command-palette:close",{bubbles:!0})))}get isOpen(){return this.#e?.open??!1}},g=class extends HTMLElement{},E=class extends HTMLElement{};m("command-palette",y);m("command-group",g);m("command-item",E);export{y as CommandPalette};
|
|
1
|
+
var d=/Mac|iPhone|iPad|iPod/.test(navigator.platform??""),v={mac:{meta:"\u2318",cmd:"\u2318",alt:"\u2325",option:"\u2325",shift:"\u21E7",ctrl:"\u2303",control:"\u2303"},other:{meta:"Ctrl",cmd:"Ctrl",alt:"Alt",option:"Alt",shift:"Shift",ctrl:"Ctrl",control:"Ctrl"}},C={mac:{meta:"Command",cmd:"Command",alt:"Option",option:"Option",shift:"Shift",ctrl:"Control",control:"Control"},other:{meta:"Control",cmd:"Control",alt:"Alt",option:"Alt",shift:"Shift",ctrl:"Control",control:"Control"}},H={escape:{label:"Esc",spoken:"Escape"},esc:{label:"Esc",spoken:"Escape"},enter:{label:"Enter",spoken:"Enter"},return:{label:"Enter",spoken:"Enter"},tab:{label:"Tab",spoken:"Tab"},space:{label:"Space",spoken:"Space"},backspace:{label:"Backspace",spoken:"Backspace"},delete:{label:"Del",spoken:"Delete"},del:{label:"Del",spoken:"Delete"},insert:{label:"Ins",spoken:"Insert"},home:{label:"Home",spoken:"Home"},end:{label:"End",spoken:"End"},pageup:{label:"PgUp",spoken:"Page up"},pagedown:{label:"PgDn",spoken:"Page down"},arrowup:{label:"\u2191",spoken:"Up arrow"},up:{label:"\u2191",spoken:"Up arrow"},arrowdown:{label:"\u2193",spoken:"Down arrow"},down:{label:"\u2193",spoken:"Down arrow"},arrowleft:{label:"\u2190",spoken:"Left arrow"},left:{label:"\u2190",spoken:"Left arrow"},arrowright:{label:"\u2192",spoken:"Right arrow"},right:{label:"\u2192",spoken:"Right arrow"},"+":{label:"+",spoken:"Plus"},plus:{label:"+",spoken:"Plus"}};function S(o){return[...String(o??"").trim().toLowerCase().matchAll(/([^+]+|\+)(?:\+|$)/g)].map(e=>e[1].trim()).filter(Boolean).map(e=>e==="plus"?"+":e)}function I(o,t=d){let e=t?v.mac:v.other;if(o in e)return{label:e[o],spoken:(t?C.mac:C.other)[o],modifier:!0};let n=H[o];if(n)return{...n,modifier:!1};let s=o.toUpperCase();return{label:s,spoken:s,modifier:!1}}function L(o){return S(o).map(t=>I(t).label).join(d?"":"+")}var O={esc:"escape",return:"enter",del:"delete",ins:"insert",up:"arrowup",down:"arrowdown",left:"arrowleft",right:"arrowright",space:" ",spacebar:" ",plus:"+",pgup:"pageup",pgdn:"pagedown"};function _(o){let t=String(o??"").toLowerCase();return O[t]??t}function p(o){let t=S(o);return{key:_(t.pop()??""),meta:t.includes("meta")||t.includes("cmd"),ctrl:t.includes("ctrl")||t.includes("control"),shift:t.includes("shift"),alt:t.includes("alt")||t.includes("option")}}function M(o){return o.length===1&&!/[a-z0-9 ]/.test(o)}function x(o,t){let n=(o.key==="Spacebar"?" ":String(o.key??"").toLowerCase())===t.key;if(!n&&(o.altKey||o.shiftKey)&&/^[a-z0-9]$/.test(t.key)){let a=/\d/.test(t.key)?`Digit${t.key}`:`Key${t.key.toUpperCase()}`;n=o.code===a}if(!n)return!1;let s,r;return d?(s=t.meta,r=t.ctrl):(s=!1,r=t.meta||t.ctrl),!(s!==o.metaKey||r!==o.ctrlKey||!M(t.key)&&t.shift!==o.shiftKey||t.alt!==o.altKey)}function N(o){let t=typeof o=="string"?p(o):o;return!t.meta&&!t.ctrl&&!t.alt&&t.key.length===1}function T(o,t){let e=p(o),n=p(t),s=d?e.ctrl:e.ctrl||e.meta,r=d?n.ctrl:n.ctrl||n.meta,a=d&&e.meta,i=d&&n.meta,c=!M(e.key);return e.key===n.key&&s===r&&a===i&&e.alt===n.alt&&(!c||e.shift===n.shift)}var g="data-char-shortcuts";var q="vb:settings:extensions";function y(){return typeof document>"u"?!0:document.documentElement.getAttribute(g)!=="off"}function P(){try{let o=globalThis.localStorage?.getItem(q);if(!o)return null;let t=JSON.parse(o)?.data?.charShortcuts;return typeof t=="boolean"?t:null}catch{return null}}var B=!0;if(typeof document<"u"){let o=P();o===null&&(B=y()),o===!1?document.documentElement.setAttribute(g,"off"):o===!0&&document.documentElement.removeAttribute(g)}var K=new Set(["INPUT","TEXTAREA","SELECT"]),m=[],$=!1;function R(o){let t=o;return!t||!t.tagName?!1:K.has(t.tagName)||t.isContentEditable}function U(o){if(o.repeat||o.isComposing||o.defaultPrevented)return;let t=R(o.target),e=!y(),n=document.activeElement;for(let s of m)if(!(t&&!s.global)&&!(s.scope&&!(s.scope.isConnected&&s.scope.contains(n)))&&!(e&&s.character&&!s.scope)&&!(s.enabled&&!s.enabled())&&x(o,s.descriptor)){o.preventDefault(),s.callback(o);return}}function V(){$||(document.addEventListener("keydown",U),$=!0)}function k(o,t,e={}){V();let n=p(o),s={combo:o,descriptor:n,callback:t,global:e.global===!0,scope:e.scope??null,enabled:typeof e.enabled=="function"?e.enabled:null,character:N(n)},r=m.find(a=>!a.scope&&!s.scope&&T(a.combo,o));return r&&console.warn(`[hotkey-bind] Shortcut "${o}" is already bound as "${r.combo}". Last-bound wins.`),m.unshift(s),function(){let i=m.indexOf(s);i!==-1&&m.splice(i,1)}}var X=window.matchMedia("(prefers-reduced-motion: reduce)");var D=new Map;function f(o,t,e={}){let n=e.priority??10,s={impl:t,bundle:e.bundle,contract:e.contract,priority:n},r=D.get(o);if(customElements.get(o)){if(!r||r.priority>=n){r&&r.priority===n&&r.impl!==t&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${r.bundle}" (priority ${r.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${o}> defined by "${r.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(r&&r.priority>=n){r.priority===n&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${r.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}D.set(o,s),customElements.define(o,t)}var b=class extends HTMLElement{#e=[];#t;constructor(){super(),this.hasAttribute("data-upgraded")&&this.removeAttribute("data-upgraded")}connectedCallback(){this.hasAttribute("data-upgraded")||this.setup()!==!1&&(this.setAttribute("data-upgraded",""),queueMicrotask(()=>{this.dispatchEvent(new CustomEvent(`${this.localName}:upgraded`,{bubbles:!0}))}))}disconnectedCallback(){for(let t of this.#e)t();this.#e=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,n,s){t.addEventListener(e,n,s),this.#e.push(()=>t.removeEventListener(e,n,s))}_reinit(){for(let t of this.#e)t();this.#e=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(t,e){this.#t||(this.#t=this.attachInternals());let n=this.#t.states;try{e?n.add(t):n.delete(t)}catch{let s=`--${t}`;e?n.add(s):n.delete(s)}}_adoptInternals(t){this.#t||(this.#t=t)}#s(){return this.constructor.formAssociated&&this.#t?this.#t:null}get validity(){return this.#s()?.validity}get validationMessage(){return this.#s()?.validationMessage??""}get willValidate(){return this.#s()?.willValidate??!1}get form(){return this.#s()?.form??null}checkValidity(){return this.#s()?.checkValidity()??!0}reportValidity(){return this.#s()?.reportValidity()??!0}};var F=0,E=class extends b{#e=null;#t;#s;#n=[];#o=-1;#c=[];#i=[];#r=[];#a="";#l=0;setup(){this.#a=`cmdp-${++F}`,this.#l=0,this.#g(),this.#y(),this.hasAttribute("discover")&&this.#E()}teardown(){this.#i.forEach(t=>t()),this.#i=[],this.#e?.remove(),this.#e=null,this.#n=[],this.#c=[],this.#r=[],this.#o=-1}get commands(){let t=[];for(let e of this.querySelectorAll("command-group")){let n=e.getAttribute("label")||"";for(let s of e.querySelectorAll("command-item"))t.push({value:s.getAttribute("value")||"",label:s.textContent.trim(),hotkey:s.getAttribute("data-hotkey")||void 0,group:n||void 0})}return t}set commands(t){let e=Array.isArray(t)?t:[],n=new Map;for(let s of e){let r=s.group||"";n.has(r)||n.set(r,[]),n.get(r).push(s)}for(let s of[...this.children])(s.tagName==="COMMAND-GROUP"||s.tagName==="COMMAND-ITEM")&&s.remove();for(let[s,r]of n){let a=document.createElement("command-group");s&&a.setAttribute("label",s);for(let i of r){let c=document.createElement("command-item");if(i.value&&c.setAttribute("value",i.value),i.hotkey&&c.setAttribute("data-hotkey",i.hotkey),i.icon){let l=document.createElement("span");l.setAttribute("slot","icon"),l.innerHTML=i.icon,c.appendChild(l)}c.appendChild(document.createTextNode(i.label||i.value||"")),a.appendChild(c)}this.appendChild(a)}this._reinit(),this.dispatchEvent(new CustomEvent("command-palette:commands-changed",{detail:{commands:e,source:"property"},bubbles:!0}))}#g(){this.#e=document.createElement("dialog"),this.#e.className="command-dialog",this.#e.setAttribute("aria-label",this.getAttribute("label")||"Command palette"),this.#e.addEventListener("click",n=>{n.target===this.#e&&this.close()}),this.#e.addEventListener("close",()=>{this.#t?.setAttribute("aria-expanded","false"),this.#t?.removeAttribute("aria-activedescendant"),this.dispatchEvent(new CustomEvent("command-palette:close",{bubbles:!0}))});let t=document.createElement("div");t.className="command-search",this.#s=document.createElement("div"),this.#s.className="command-list",this.#s.id=`${this.#a}-list`,this.#s.setAttribute("role","listbox"),this.#s.setAttribute("aria-label","Commands"),this.#t=document.createElement("input"),this.#t.type="search",this.#t.placeholder=this.getAttribute("placeholder")||"Type a command...",this.#t.setAttribute("aria-label","Search commands"),this.#t.autocomplete="off",this.#t.setAttribute("role","combobox"),this.#t.setAttribute("aria-autocomplete","list"),this.#t.setAttribute("aria-controls",this.#s.id),this.#t.setAttribute("aria-expanded","false"),this.#t.addEventListener("input",this.#d),this.#t.addEventListener("keydown",this.#k),t.appendChild(this.#t),this.#c=Array.from(this.querySelectorAll("command-group")),this.#c.forEach(n=>{let s=this.#u(n.getAttribute("label")||"");this.#s.appendChild(s),n.querySelectorAll("command-item").forEach(r=>{let a=r.querySelector('[slot="icon"]'),i=this.#p(r.textContent.trim(),a?a.cloneNode(!0):null,r.getAttribute("data-hotkey"));i.dataset.value=r.getAttribute("value")||"",i.addEventListener("click",()=>{this.#f(i.dataset.value)}),s.appendChild(i),this.#n.push({btn:i,group:s,source:r})})});let e=document.createElement("div");e.className="command-empty",e.textContent="No results found.",e.hidden=!0,this.#s.appendChild(e),this.#e.appendChild(t),this.#e.appendChild(this.#s),this.appendChild(this.#e)}#u(t){let e=document.createElement("div");e.className="command-group",e.setAttribute("role","group");let n=document.createElement("div");return n.className="command-group-header",n.id=`${this.#a}-g${++this.#l}`,n.setAttribute("aria-hidden","true"),n.textContent=t,t?e.setAttribute("aria-labelledby",n.id):n.hidden=!0,e.appendChild(n),e}#y(){let t=this.getAttribute("hotkey")||"meta+k";this.#i.push(k(t,()=>{this.#e?.open?this.close():this.open()},{global:!0}));for(let{btn:e,source:n}of this.#n){let s=n?.getAttribute("data-hotkey");if(!s||s.toLowerCase()===t.toLowerCase())continue;let r=e.dataset.value;this.#i.push(k(s,()=>this.#f(r)))}}#d=()=>{let t=this.#t.value.toLowerCase().trim(),e=0,n=new Set;this.#n.forEach(({btn:r,group:a})=>{let i=!t||(r.dataset.searchText??"").includes(t);r.hidden=!i,i&&(e++,n.add(a))}),this.#s.querySelectorAll(":scope > .command-group").forEach(r=>{r.hidden=!n.has(r)});let s=this.#s.querySelector(".command-empty");s&&(s.hidden=e>0),this.#o=-1,this.#n.forEach(({btn:r})=>{r.removeAttribute("data-active"),r.setAttribute("aria-selected","false")}),this.#t.removeAttribute("aria-activedescendant"),e>0&&this.#h(0)};#k=t=>{let e=this.#m();switch(t.key){case"ArrowDown":t.preventDefault(),this.#h(this.#o+1);break;case"ArrowUp":t.preventDefault(),this.#h(this.#o-1);break;case"Enter":t.preventDefault(),this.#o>=0&&e[this.#o]&&e[this.#o].btn.click();break;case"Escape":t.preventDefault(),this.close();break}};#m(){return this.#n.filter(({btn:t})=>!t.hidden)}#h(t){let e=this.#m();if(e.length===0)return;e.forEach(({btn:s})=>{s.removeAttribute("data-active"),s.setAttribute("aria-selected","false")}),t<0&&(t=e.length-1),t>=e.length&&(t=0),this.#o=t;let{btn:n}=e[t];n.setAttribute("data-active",""),n.setAttribute("aria-selected","true"),this.#t.setAttribute("aria-activedescendant",n.id),n.scrollIntoView({block:"nearest"})}#f(t){this.close(),this.dispatchEvent(new CustomEvent("command-palette:select",{bubbles:!0,detail:{value:t}}))}#E(){this.listen(document,"vb:command-registry-change",this.#A)}#A=()=>{this.#e?.open&&(this.#b(),this.#d())};#b(){if(!this.hasAttribute("discover"))return;let{getRegisteredCommands:t,scanAutoDiscoverable:e}=window.__commandRegistry||{};if(!t)return;this.#n=this.#n.filter(r=>!r.discovered),this.#r.forEach(r=>r.remove()),this.#r=[];let n=this.#s.querySelector(".command-empty"),s=t();for(let[r,a]of s){let i=this.#u(r);this.#s.insertBefore(i,n),this.#r.push(i);for(let c of a){if(this.contains(c.element))continue;let l=this.#p(c.label,c.icon,c.shortcut);l.dataset.value=`__discovered:${c.label}`,l.addEventListener("click",()=>{this.close(),c.element.click()}),i.appendChild(l),this.#n.push({btn:l,group:i,source:null,discovered:!0})}}if(this.getAttribute("discover")==="auto"&&e){let r=e(),a=new Map;for(let i of r){let c=a.get(i.group)||[];c.push(i),a.set(i.group,c)}for(let[i,c]of a){let l=this.#u(i);this.#s.insertBefore(l,n),this.#r.push(l);for(let u of c){if(this.contains(u.element))continue;let h=this.#p(u.label,u.icon,u.shortcut);h.dataset.value=`__auto:${u.label}`,h.dataset.auto="",h.addEventListener("click",()=>{this.close(),u.action?u.action():u.element.click()}),l.appendChild(h),this.#n.push({btn:h,group:l,source:null,discovered:!0})}}}}#p(t,e,n){let s=document.createElement("button");if(s.type="button",s.className="command-option",s.id=`${this.#a}-opt-${++this.#l}`,s.setAttribute("role","option"),s.setAttribute("aria-selected","false"),s.tabIndex=-1,s.dataset.searchText=t.toLowerCase(),e){let a=document.createElement("span");if(a.className="command-icon",typeof e=="string"){let i=document.createElement("icon-wc");i.setAttribute("name",e),a.appendChild(i)}else a.appendChild(e);s.appendChild(a)}let r=document.createElement("span");if(r.className="command-label",r.textContent=t,s.appendChild(r),n){let a=document.createElement("kbd");a.className="command-kbd",a.setAttribute("aria-hidden","true"),a.textContent=L(n),s.appendChild(a),s.setAttribute("aria-keyshortcuts",n)}return s}open(){!this.#e||this.#e.open||(this.#b(),this.#e.showModal(),this.#t.setAttribute("aria-expanded","true"),this.#t.value="",this.#d(),this.#t.focus(),this.dispatchEvent(new CustomEvent("command-palette:open",{bubbles:!0})))}close(){this.#e?.open&&this.#e.close()}get isOpen(){return this.#e?.open??!1}},A=class extends HTMLElement{},w=class extends HTMLElement{};f("command-palette",E);f("command-group",A);f("command-item",w);export{E as CommandPalette};
|
|
2
2
|
//# sourceMappingURL=command-palette.js.map
|