vanilla-breeze 0.4.0 → 0.5.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 +13966 -11505
- 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 +49 -49
- package/dist/cdn/components/comment-thread.js +32 -32
- 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 +4 -4
- 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 +2 -2
- 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 +100 -100
- package/dist/cdn/components/markdown-editor.js +1 -1
- package/dist/cdn/components/markdown-viewer.js +11 -11
- package/dist/cdn/components/nav-bar.js +1 -1
- package/dist/cdn/components/note-wc.js +2 -2
- package/dist/cdn/components/notification-wc.js +4 -4
- package/dist/cdn/components/page-info.js +2 -2
- 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 +5 -5
- 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 +4 -4
- 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 +3 -3
- package/dist/cdn/components/reading-progress.js +1 -1
- package/dist/cdn/components/recently-visited.js +7 -7
- package/dist/cdn/components/score-card.js +2 -2
- package/dist/cdn/components/selection-menu.js +1 -1
- package/dist/cdn/components/settings-panel.js +4 -4
- 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 +6 -6
- package/dist/cdn/components/site-map.js +1 -1
- package/dist/cdn/components/site-search.js +3 -3
- 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 +44 -44
- package/dist/cdn/components/time-index.js +2 -2
- package/dist/cdn/components/time-picker.js +1 -1
- package/dist/cdn/components/toast-msg.js +1 -1
- package/dist/cdn/components/tool-tip.js +1 -1
- package/dist/cdn/components/topic-map.js +3 -3
- package/dist/cdn/components/trust-filter.js +3 -3
- package/dist/cdn/components/version-switcher.js +3 -13
- package/dist/cdn/components/video-player.js +1 -1
- package/dist/cdn/components/watch-wc.js +2 -2
- package/dist/cdn/components/week-view.js +1 -1
- package/dist/cdn/components/youtube-player.js +1 -1
- package/dist/cdn/packs/effects.full.js +1 -1
- package/dist/cdn/packs/kawaii.effects.css +1 -1
- package/dist/cdn/packs/kawaii.full.css +1 -1
- package/dist/cdn/packs/kawaii.full.js +4 -4
- package/dist/cdn/packs/manifest.json +7 -7
- package/dist/cdn/packs/memphis.full.css +1 -1
- package/dist/cdn/packs/memphis.theme.css +1 -1
- package/dist/cdn/packs/ui.full.js +46 -46
- 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.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.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-latte-dark.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-latte.tokens.json +1 -1
- package/dist/cdn/themes/catppuccin-macchiato.tokens.json +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.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 +23 -1
- package/dist/cdn/themes/clinical-dark.tokens.json +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.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.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.tokens.json +1 -1
- package/dist/cdn/themes/government-dark.tokens.json +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.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 +33 -1
- package/dist/cdn/themes/journal.css +1 -1
- package/dist/cdn/themes/journal.tokens.json +23 -1
- 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.tokens.json +1 -1
- package/dist/cdn/themes/manifest.json +26 -50
- package/dist/cdn/themes/midnight.tokens.json +1 -1
- package/dist/cdn/themes/minimal-dark.tokens.json +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.tokens.json +1 -1
- package/dist/cdn/themes/nes-dark.tokens.json +1 -1
- 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.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.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 +15 -4
- package/dist/cdn/themes/win9x.css +1 -1
- package/dist/cdn/themes/win9x.tokens.json +1 -1
- package/dist/cdn/vanilla-breeze-autoload.js +663 -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 +78 -80
- package/dist/cdn/vanilla-breeze-dev.css +1 -1
- package/dist/cdn/vanilla-breeze-extras.js +47 -37
- package/dist/cdn/vanilla-breeze.css +1 -1
- package/dist/cdn/vanilla-breeze.js +180 -177
- package/package.json +12 -7
- 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
|
|
1
|
+
function E(t){return document.startViewTransition?document.startViewTransition(t):t()}var x=window.matchMedia("(prefers-reduced-motion: reduce)");var v=new Map;function S(t,e,n={}){let o=n.priority??10,i={impl:e,bundle:n.bundle,contract:n.contract,priority:o},r=v.get(t);if(customElements.get(t)){if(!r||r.priority>=o){r&&r.priority===o&&r.impl!==e&&console.warn(`[VB Bundle] Tag <${t}> already registered by "${r.bundle}" (priority ${r.priority}). Skipping "${n.bundle}".`);return}console.warn(`[VB Bundle] Tag <${t}> defined by "${r.bundle}" cannot be replaced (customElements.define is permanent). "${n.bundle}" has higher priority but arrived late.`);return}if(r&&r.priority>=o){r.priority===o&&console.warn(`[VB Bundle] Tag <${t}> already registered by "${r.bundle}". Skipping "${n.bundle}" (first wins at equal priority).`);return}v.set(t,i),customElements.define(t,e)}var h=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 e of this.#t)e();this.#t=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(e,n,o,i){e.addEventListener(n,o,i),this.#t.push(()=>e.removeEventListener(n,o,i))}_reinit(){for(let e of this.#t)e();this.#t=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(e,n){this.#e||(this.#e=this.attachInternals());let o=this.#e.states;try{n?o.add(e):o.delete(e)}catch{let i=`--${e}`;n?o.add(i):o.delete(i)}}_adoptInternals(e){this.#e||(this.#e=e)}};var q=0;function w(t,e){return t.matches("content-swap")?e:`data-${e}`}function b(t){let e=t.querySelector(':scope > [data-face="front"]'),n=t.querySelector(':scope > [data-face="back"]');if(!e||!n)return;t.style.viewTransitionName||(t.style.viewTransitionName=`content-swap-${++q}`);let o=t.matches("content-swap");o||t.setAttribute("data-swap-init","");let i=[];function r(s,a,u,f){s.addEventListener(a,u,f),i.push(()=>s.removeEventListener(a,u,f))}let l=[...t.querySelectorAll("[data-swap]")].filter(s=>s.parentElement?.closest("content-swap, [data-swap]")===t),y=l.length===0,c=t.querySelector(":scope > [data-swap-toggle]");if(y){if(!c){let s=document.createElement("button");s.type="button",s.setAttribute("data-swap-toggle",""),s.textContent="Show back",t.append(s),c=s}r(c,"click",s=>{s.stopPropagation(),d(t,s.detail===0?"keyboard":"pointer")}),r(t,"click",s=>{let u=s.target.closest?.(M);u&&u!==t&&t.contains(u)||d(t,"pointer")})}else c&&!c.hasAttribute("data-swap")&&c.remove(),c=null,l.forEach(s=>{r(s,"click",a=>{a.stopPropagation(),d(t,"pointer")}),r(s,"keydown",a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),d(t,"keyboard"))})});if(t.matches('[data-gesture="flick"], [data-gesture="swipe"]')&&(r(t,"swipe-left",()=>d(t,"pointer")),r(t,"swipe-right",()=>d(t,"pointer"))),!o){let s=new MutationObserver(()=>m(t,e,n));s.observe(t,{attributes:!0,attributeFilter:["data-swapped"]}),i.push(()=>s.disconnect())}return m(t,e,n),$([e,n]),()=>{for(let s of i)s();i.length=0}}var M='a[href], button, input, select, textarea, label, summary, [contenteditable=""], [contenteditable="true"], [tabindex]';function $(t){let e=t.map(n=>n.style.transition);for(let n of t)n.style.transition="none";for(let n of t)getComputedStyle(n).transform;t.forEach((n,o)=>{n.style.transition=e[o]})}function m(t,e,n){let o=t.hasAttribute(w(t,"swapped"));e.inert=o,n.inert=!o,t.querySelector(":scope > [data-swap-toggle]")?.setAttribute("aria-pressed",String(o))}function T(t){return{front:t.querySelector(':scope > [data-face="front"]'),back:t.querySelector(':scope > [data-face="back"]')}}function p(t,e,n="api"){let{front:o,back:i}=T(t);if(!o||!i)return;let r=w(t,"swapped");if(e&&t.hasAttribute(r)||!e&&!t.hasAttribute(r))return;let l=document.activeElement,y=()=>{e?t.setAttribute(r,""):t.removeAttribute(r),m(t,o,i),C(t,n);let a=e?i:o,u=e?o:i,f=a.querySelector("[autofocus]");f?f.focus():n==="keyboard"&&u.contains(l)&&L(a)},c=a=>{let u=t;typeof u.setState=="function"&&u.setState("transition-running",a)};c(!0);let s=E(y);s&&s.finished&&typeof s.finished.finally=="function"?s.finished.finally(()=>c(!1)):c(!1)}function d(t,e="api"){p(t,!t.hasAttribute(w(t,"swapped")),e)}function C(t,e="internal"){t.dispatchEvent(new CustomEvent("content-swap:swap",{detail:{swapped:t.hasAttribute(w(t,"swapped")),source:e},bubbles:!0}))}function L(t){let e=t.querySelector("[data-swap], button, a, input, select, textarea");e&&e.focus()}var g=class extends h{static observedAttributes=["swapped"];#t=null;attributeChangedCallback(){if(!this.isConnected)return;let{front:e,back:n}=T(this);e&&n&&m(this,e,n)}setup(){this.#t=b(this)??null}teardown(){this.#t?.(),this.#t=null}flip(){p(this,!0)}unflip(){p(this,!1)}toggle(){d(this)}get flipped(){return this.hasAttribute("swapped")}set flipped(e){p(this,!!e)}get swapped(){return this.hasAttribute("swapped")}set swapped(e){p(this,!!e)}};S("content-swap",g);function k(){document.querySelectorAll("[data-swap]:not(content-swap):not([data-swap-init])").forEach(t=>{t.querySelector(":scope > [data-face]")&&b(t)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",k):k();var A=new MutationObserver(t=>{for(let e of t)for(let n of e.addedNodes){if(n.nodeType!==Node.ELEMENT_NODE)continue;let o=n;o.hasAttribute("data-swap")&&!o.matches("content-swap")&&!o.hasAttribute("data-swap-init")&&o.querySelector(":scope > [data-face]")&&b(o),o.querySelectorAll("[data-swap]:not(content-swap):not([data-swap-init])").forEach(i=>{i.querySelector(":scope > [data-face]")&&b(i)})}});document.body?A.observe(document.body,{childList:!0,subtree:!0}):document.addEventListener("DOMContentLoaded",()=>{A.observe(document.body,{childList:!0,subtree:!0})});export{g as ContentSwap};
|
|
2
2
|
//# sourceMappingURL=content-swap.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var u=/Mac|iPhone|iPad|iPod/.test(navigator.platform??""),m={mac:{meta:"\u2318",cmd:"\u2318",alt:"\u2325",shift:"\u21E7",ctrl:"\u2303"},other:{meta:"Ctrl",cmd:"Ctrl",alt:"Alt",shift:"Shift",ctrl:"Ctrl"}};function b(n){let t=u?m.mac:m.other;return n.split("+").map(s=>{let e=s.trim().toLowerCase();return t[e]??e.toUpperCase()}).join(u?"":"+")}function y(n){let t=n.toLowerCase().split("+").map(e=>e.trim());return{key:t.pop()??"",meta:t.includes("meta")||t.includes("cmd"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),alt:t.includes("alt")}}function g(n,t){if(n.key.toLowerCase()!==t.key)return!1;let s,e;return u?(s=t.meta,e=t.ctrl):(s=!1,e=t.meta||t.ctrl),!(s!==n.metaKey||e!==n.ctrlKey||t.shift!==n.shiftKey||t.alt!==n.altKey)}var k=new Set(["INPUT","TEXTAREA","SELECT"]),h=[],w=!1;function x(n){let t=k.has(n.target.tagName)||n.target.isContentEditable;for(let s of h)if(!(t&&!s.global)&&g(n,s.descriptor)){n.preventDefault(),s.callback(n);return}}function C(){w||(document.addEventListener("keydown",x),w=!0)}function E(n,t,s={}){C();let e=y(n),i={combo:n,descriptor:e,callback:t,global:s.global===!0};return h.find(r=>r.combo===n)&&console.warn(`[hotkey-bind] Shortcut "${n}" already bound. Last-connected-wins.`),h.unshift(i),function(){let a=h.indexOf(i);a!==-1&&h.splice(a,1)}}var L=window.matchMedia("(prefers-reduced-motion: reduce)");var v=new Map;function l(n,t,s={}){let e=s.priority??10,i={impl:t,bundle:s.bundle,contract:s.contract,priority:e},o=v.get(n);if(customElements.get(n)){if(!o||o.priority>=e){o&&o.priority===e&&o.impl!==t&&console.warn(`[VB Bundle] Tag <${n}> already registered by "${o.bundle}" (priority ${o.priority}). Skipping "${s.bundle}".`);return}console.warn(`[VB Bundle] Tag <${n}> defined by "${o.bundle}" cannot be replaced (customElements.define is permanent). "${s.bundle}" has higher priority but arrived late.`);return}if(o&&o.priority>=e){o.priority===e&&console.warn(`[VB Bundle] Tag <${n}> already registered by "${o.bundle}". Skipping "${s.bundle}" (first wins at equal priority).`);return}v.set(n,i),customElements.define(n,t)}var c=class extends HTMLElement{#s=[];#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.#s)t();this.#s=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,s,e,i){t.addEventListener(s,e,i),this.#s.push(()=>t.removeEventListener(s,e,i))}setup(){}teardown(){}setState(t,s){this.#t||(this.#t=this.attachInternals());let e=this.#t.states;try{s?e.add(t):e.delete(t)}catch{let i=`--${t}`;s?e.add(i):e.delete(i)}}_adoptInternals(t){this.#t||(this.#t=t)}};var d=CSS.supports("anchor-name","--x"),S=CSS.supports("position-area","bottom"),$=0,p=class extends c{#s=null;#t=null;#e=null;#i=null;setup(){this.id||(this.id=`pop-over-${++$}`);let t=this.dataset.mode||"auto";this.hasAttribute("popover")||this.setAttribute("popover",t),this.#o(),this.#n(),this.#e=s=>{let e=s.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${e}`,{detail:{state:s.newState},bubbles:!0,composed:!0})),!d&&s.newState==="open"&&this.#s&&this.#c()},this.listen(this,"beforetoggle",this.#e),d||(this.#i=()=>{this.matches(":popover-open")&&this.#s&&this.#c()},this.listen(window,"resize",this.#i),this.listen(window,"scroll",this.#i,{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")}#o(){let t=this.dataset.anchor;t?this.#s=document.getElementById(t)||document.querySelector(t):this.#s=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#n(){if(!(!this.#s||!d)&&(this.#t=`--pop-over-anchor-${this.id}`,this.#s.style.setProperty("anchor-name",this.#t),this.style.setProperty("position-anchor",this.#t),this.setAttribute("data-anchor-name",this.#t||""),!S)){let t=this.dataset.position||"bottom";this.#r(t)}}#r(t){let s="var(--_pop-over-offset, var(--size-xs))",e={top:{bottom:`calc(anchor(top) + ${s})`,left:"anchor(left)"},bottom:{top:`calc(anchor(bottom) + ${s})`,left:"anchor(left)"},left:{right:`calc(anchor(left) + ${s})`,top:"anchor(top)"},right:{left:`calc(anchor(right) + ${s})`,top:"anchor(top)"}},i=t.split("-")[0],o=e[i]||e.bottom;Object.entries(o).forEach(([r,a])=>this.style.setProperty(r,a))}#c(){if(!this.#s)return;let t=this.#s.getBoundingClientRect(),s=this.dataset.position||"bottom",e=this.#h(),i,o;switch(s.split("-")[0]){case"top":i=t.top-this.offsetHeight-e,o=t.left;break;case"left":i=t.top,o=t.left-this.offsetWidth-e;break;case"right":i=t.top,o=t.right+e;break;default:i=t.bottom+e,o=t.left;break}s.endsWith("-end")&&(s.startsWith("top")||s.startsWith("bottom")?o=t.right-this.offsetWidth:i=t.bottom-this.offsetHeight),this.style.position="fixed",this.style.top=`${Math.round(i)}px`,this.style.left=`${Math.round(o)}px`,this.style.margin="0"}#h(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset]??t.xs}};l("pop-over",p);var A=0,f=class extends c{#s;#t;#e;#i=[];#o=-1;#n=!1;#r=[];setup(){let t=this.querySelector(":scope > [data-trigger]"),s=this.querySelector('menu, ul[role="menu"]');if(!t||!s)return!1;this.#s=t,this.#t=s;let e=this.querySelector(":scope > pop-over[data-context-menu-host]");return e?this.#e=e:(this.#e=document.createElement("pop-over"),this.#e.setAttribute("data-context-menu-host",""),this.#e.id=`ctx-menu-${++A}`,this.#e.dataset.mode="auto",this.#e.appendChild(this.#t),this.appendChild(this.#e)),this.#t.parentElement!==this.#e&&this.#e.appendChild(this.#t),this.#s?.setAttribute("aria-expanded","false"),this.#t.setAttribute("role","menu"),this.#t.id||(this.#t.id=`ctx-menu-list-${++A}`),this.#t.querySelectorAll(":scope > li[data-group]").forEach(i=>{i.setAttribute("role","presentation"),i.classList.add("ctx-group-label")}),this.#i=Array.from(this.#t.querySelectorAll('button, a, [role="menuitem"]')).filter(i=>!i.disabled&&!i.hasAttribute("data-disabled")),this.#i.forEach(i=>{i.setAttribute("role","menuitem"),i.setAttribute("tabindex","-1"),this.listen(i,"click",this.#u);let o=i.getAttribute("data-shortcut");if(o){let r=document.createElement("kbd");r.className="ctx-kbd",r.textContent=b(o),i.appendChild(r);let a=E(o,()=>i.click());this.#r.push(a)}}),this.#t.querySelectorAll('li:empty:not([data-group]), [role="separator"], hr').forEach(i=>{i.setAttribute("role","separator")}),this.listen(this.#s,"contextmenu",this.#c),this.listen(this.#t,"keydown",this.#l),this.listen(window,"scroll",this.#p,{capture:!0}),this.listen(this.#e,"pop-over:hide",this.#d),!0}teardown(){this.#r.forEach(t=>t()),this.#r=[]}get items(){if(!this.#t)return[];let t=[];for(let s of this.#t.querySelectorAll(":scope > li")){if(s.hasAttribute("data-group")){t.push({group:s.textContent.trim()});continue}if(s.matches(':empty, [role="separator"]')||s.querySelector("hr")){t.push({separator:!0});continue}let e=s.querySelector('button, a, [role="menuitem"]');e&&t.push({label:e.textContent.trim().replace(/\s+/g," "),value:e.getAttribute("data-value")||void 0,href:e.tagName==="A"?e.getAttribute("href"):void 0,shortcut:e.getAttribute("data-shortcut")||void 0,disabled:e.disabled||e.hasAttribute("data-disabled")||void 0})}return t}set items(t){let s=Array.isArray(t)?t:[],e=this.querySelector('menu, ul[role="menu"]');for(e||(e=document.createElement("menu"),this.appendChild(e));e.firstChild;)e.firstChild.remove();for(let i of s){let o=document.createElement("li");if(i.separator)o.setAttribute("role","separator");else if(i.group!=null)o.setAttribute("data-group",""),o.textContent=i.group;else{let r=i.href?document.createElement("a"):document.createElement("button");i.href&&r.setAttribute("href",i.href),i.value&&r.setAttribute("data-value",i.value),i.shortcut&&r.setAttribute("data-shortcut",i.shortcut),i.disabled&&(r.tagName==="BUTTON"?r.disabled=!0:r.setAttribute("data-disabled","")),r.textContent=i.label||"",o.appendChild(r)}e.appendChild(o)}this.teardown(),this.removeAttribute("data-upgraded"),this.setup(),this.dispatchEvent(new CustomEvent("context-menu:items-changed",{detail:{items:s,source:"property"},bubbles:!0}))}#c=t=>{t.preventDefault(),t.buttons!==0?this.listen(window,"pointerup",()=>{setTimeout(()=>this.#h(t.clientX,t.clientY),0)},{once:!0,capture:!0}):this.#h(t.clientX,t.clientY)};#h(t,s){this.#n=!0,this.setAttribute("data-open",""),this.#s?.setAttribute("aria-expanded","true"),this.#e.style.top=`${s}px`,this.#e.style.left=`${t}px`,this.#e.show(),requestAnimationFrame(()=>{let e=this.#e.getBoundingClientRect(),i=t+e.width>window.innerWidth?t-e.width:t,o=s+e.height>window.innerHeight?s-e.height:s;this.#e.style.top=`${Math.max(0,o)}px`,this.#e.style.left=`${Math.max(0,i)}px`}),this.#o=-1,this.#a(0),this.dispatchEvent(new CustomEvent("context-menu:open",{bubbles:!0}))}close(){this.#n&&(this.#n=!1,this.removeAttribute("data-open"),this.#s?.setAttribute("aria-expanded","false"),this.#o=-1,this.#e?.hide(),this.dispatchEvent(new CustomEvent("context-menu:close",{bubbles:!0})))}#l=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.#a(this.#o+1);break;case"ArrowUp":case"Up":t.preventDefault(),this.#a(this.#o-1);break;case"Home":t.preventDefault(),this.#a(0);break;case"End":t.preventDefault(),this.#a(this.#i.length-1);break;case"Enter":case" ":t.preventDefault(),this.#o>=0&&this.#i[this.#o].click();break;case"Tab":this.close();break}};#u=()=>{this.close(),this.dispatchEvent(new CustomEvent("context-menu:select",{bubbles:!0,detail:{item:this.#i[this.#o]}}))};#d=()=>{this.#n&&(this.#n=!1,this.removeAttribute("data-open"),this.#s?.setAttribute("aria-expanded","false"),this.#o=-1,this.dispatchEvent(new CustomEvent("context-menu:close",{bubbles:!0})))};#p=()=>{this.#n&&this.close()};#a(t){this.#i.length!==0&&(t<0&&(t=this.#i.length-1),t>=this.#i.length&&(t=0),this.#o=t,this.#i[t].focus())}get isOpen(){return this.#n}};l("context-menu",f);export{f as ContextMenuWc};
|
|
1
|
+
var l=/Mac|iPhone|iPad|iPod/.test(navigator.platform??""),g={mac:{meta:"\u2318",cmd:"\u2318",alt:"\u2325",shift:"\u21E7",ctrl:"\u2303"},other:{meta:"Ctrl",cmd:"Ctrl",alt:"Alt",shift:"Shift",ctrl:"Ctrl"}};function A(r){let t=l?g.mac:g.other;return r.split("+").map(e=>{let i=e.trim().toLowerCase();return t[i]??i.toUpperCase()}).join(l?"":"+")}function w(r){let t=r.toLowerCase().split("+").map(i=>i.trim());return{key:t.pop()??"",meta:t.includes("meta")||t.includes("cmd"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),alt:t.includes("alt")}}function v(r,t){if(r.key.toLowerCase()!==t.key)return!1;let e,i;return l?(e=t.meta,i=t.ctrl):(e=!1,i=t.meta||t.ctrl),!(e!==r.metaKey||i!==r.ctrlKey||t.shift!==r.shiftKey||t.alt!==r.altKey)}var k=new Set(["INPUT","TEXTAREA","SELECT"]),u=[],E=!1;function S(r){let t=k.has(r.target.tagName)||r.target.isContentEditable;for(let e of u)if(!(t&&!e.global)&&v(r,e.descriptor)){r.preventDefault(),e.callback(r);return}}function $(){E||(document.addEventListener("keydown",S),E=!0)}function x(r,t,e={}){$();let i=w(r),o={combo:r,descriptor:i,callback:t,global:e.global===!0};return u.find(n=>n.combo===r)&&console.warn(`[hotkey-bind] Shortcut "${r}" already bound. Last-connected-wins.`),u.unshift(o),function(){let a=u.indexOf(o);a!==-1&&u.splice(a,1)}}var P=window.matchMedia("(prefers-reduced-motion: reduce)");var C=new Map;function d(r,t,e={}){let i=e.priority??10,o={impl:t,bundle:e.bundle,contract:e.contract,priority:i},s=C.get(r);if(customElements.get(r)){if(!s||s.priority>=i){s&&s.priority===i&&s.impl!==t&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${s.bundle}" (priority ${s.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${r}> 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 <${r}> already registered by "${s.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}C.set(r,o),customElements.define(r,t)}var c=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,i,o){t.addEventListener(e,i,o),this.#t.push(()=>t.removeEventListener(e,i,o))}_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.#e||(this.#e=this.attachInternals());let i=this.#e.states;try{e?i.add(t):i.delete(t)}catch{let o=`--${t}`;e?i.add(o):i.delete(o)}}_adoptInternals(t){this.#e||(this.#e=t)}};var f=CSS.supports("anchor-name","--x"),M=CSS.supports("position-area","bottom"),q=0,m=class extends c{#t=null;#e=null;#i=null;#s=null;setup(){this.id||(this.id=`pop-over-${++q}`);let t=this.dataset.mode||"auto";this.hasAttribute("popover")||this.setAttribute("popover",t),this.#r(),this.#o(),this.#i=e=>{let i=e.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${i}`,{detail:{state:e.newState},bubbles:!0,composed:!0})),!f&&e.newState==="open"&&this.#t&&this.#c()},this.listen(this,"beforetoggle",this.#i),f||(this.#s=()=>{this.matches(":popover-open")&&this.#t&&this.#c()},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")}#r(){let t=this.dataset.anchor;t?this.#t=document.getElementById(t)||document.querySelector(t):this.#t=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#o(){if(!(!this.#t||!f)&&(this.#e=`--pop-over-anchor-${this.id}`,this.#t.style.setProperty("anchor-name",this.#e),this.style.setProperty("position-anchor",this.#e),this.setAttribute("data-anchor-name",this.#e||""),!M)){let t=this.dataset.position||"bottom";this.#n(t)}}#n(t){let e="var(--_pop-over-offset, var(--size-xs))",i={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],s=i[o]||i.bottom;Object.entries(s).forEach(([n,a])=>this.style.setProperty(n,a))}#c(){if(!this.#t)return;let t=this.#t.getBoundingClientRect(),e=this.dataset.position||"bottom",i=this.#l(),o,s;switch(e.split("-")[0]){case"top":o=t.top-this.offsetHeight-i,s=t.left;break;case"left":o=t.top,s=t.left-this.offsetWidth-i;break;case"right":o=t.top,s=t.right+i;break;default:o=t.bottom+i,s=t.left;break}e.endsWith("-end")&&(e.startsWith("top")||e.startsWith("bottom")?s=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(s)}px`,this.style.margin="0"}#l(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset]??t.xs}};d("pop-over",m);var b=0,T='a[href], button, input, select, textarea, summary, iframe, [tabindex], [contenteditable]:not([contenteditable="false"])';function p(r){return r.hasAttribute("data-disabled")||r.getAttribute("aria-disabled")==="true"||!!r.disabled}function L(r){return r.split("+").map(t=>{let e=t.trim().toLowerCase();return e==="meta"||e==="cmd"?l?"Meta":"Control":e==="ctrl"?"Control":e==="alt"?"Alt":e==="shift"?"Shift":e.length===1?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)}).join("+")}function B(r){return r.pointerType===""||r.pointerId===-1||r.button===-1||r.clientX===0&&r.clientY===0&&r.buttons===0}var y=class extends c{#t;#e;#i;#s=[];#r=-1;#o=!1;#n=[];setup(){let t=this.querySelector(":scope > [data-trigger]"),e=this.querySelector('menu, ul[role="menu"]');if(!t||!e)return!1;this.#t=t,this.#e=e;let i=this.querySelector(":scope > pop-over[data-context-menu-host]");i?this.#i=i:(this.#i=document.createElement("pop-over"),this.#i.setAttribute("data-context-menu-host",""),this.#i.id=`ctx-menu-${++b}`,this.#i.dataset.mode="auto",this.#i.appendChild(this.#e),this.appendChild(this.#i)),this.#e.parentElement!==this.#i&&this.#i.appendChild(this.#e),this.#e.setAttribute("role","menu"),this.#e.id||(this.#e.id=`ctx-menu-list-${++b}`),this.#t.setAttribute("aria-haspopup","menu"),this.#t.setAttribute("aria-expanded","false"),this.#t.setAttribute("aria-controls",this.#e.id),this.#t.matches(T)||this.#t.setAttribute("tabindex","0"),this.#e.querySelectorAll(':scope > li:empty:not([data-group]), :scope > [role="separator"], :scope > hr').forEach(s=>{s.setAttribute("role","separator")}),this.#c();let o=Array.from(this.#e.querySelectorAll('button, a, [role="menuitem"]'));return o.forEach(s=>{s.setAttribute("role","menuitem"),s.setAttribute("tabindex","-1")}),this.#s=o.filter(s=>!s.disabled),this.#e.querySelectorAll("li").forEach(s=>{s.querySelector(':scope > :is(button, a, [role="menuitem"])')&&s.setAttribute("role","none")}),this.#s.forEach(s=>{s.hasAttribute("data-disabled")&&s.setAttribute("aria-disabled","true"),this.listen(s,"click",this.#g);let n=s.getAttribute("data-shortcut");if(n){if(!s.querySelector(":scope > .ctx-kbd")){let h=document.createElement("kbd");h.className="ctx-kbd",h.setAttribute("aria-hidden","true"),h.textContent=A(n),s.appendChild(h)}s.setAttribute("aria-keyshortcuts",L(n));let a=x(n,()=>{p(s)||s.click()});this.#n.push(a)}}),this.listen(this.#t,"contextmenu",this.#f),this.listen(this.#t,"keydown",this.#m),this.listen(this.#e,"keydown",this.#b),this.listen(this.#e,"click",this.#y,{capture:!0}),this.listen(window,"scroll",this.#w,{capture:!0}),this.listen(this.#i,"pop-over:hide",this.#A),!0}teardown(){this.#n.forEach(t=>t()),this.#n=[],this.#o&&(this.#o=!1,this.removeAttribute("data-open"),this.#i?.hide?.()),this.#r=-1,this.#s=[],this.#e?.querySelectorAll(".ctx-kbd").forEach(t=>t.remove()),this.#l()}#c(){let t=this.#e;for(let e of Array.from(t.querySelectorAll(":scope > li[data-group]"))){e.id||(e.id=`ctx-group-${++b}`),e.classList.add("ctx-group-label"),e.setAttribute("aria-hidden","true");let i=document.createElement("li");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",e.id),i.setAttribute("data-ctx-group","");let o=document.createElement("ul");o.setAttribute("role","none"),i.appendChild(o),t.insertBefore(i,e),o.appendChild(e);let s=i.nextElementSibling;for(;s&&!s.hasAttribute("data-group")&&s.getAttribute("role")!=="separator";){let n=s;s=s.nextElementSibling,o.appendChild(n)}}}#l(){let t=this.#e;if(t)for(let e of Array.from(t.querySelectorAll(":scope > li[data-ctx-group]"))){let i=e.querySelector(":scope > ul");if(i)for(let o of Array.from(i.children))t.insertBefore(o,e);e.remove()}}get items(){if(!this.#e)return[];let t=[],e=this.#e.querySelectorAll(":scope > li:not([data-ctx-group]), :scope > li[data-ctx-group] > ul > li");for(let i of e){if(i.hasAttribute("data-group")){t.push({group:i.textContent.trim()});continue}if(i.matches(':empty, [role="separator"]')||i.querySelector("hr")){t.push({separator:!0});continue}let o=i.querySelector('button, a, [role="menuitem"]');if(!o)continue;let s=Array.from(o.childNodes).filter(n=>!(n instanceof Element&&n.classList.contains("ctx-kbd"))).map(n=>n.textContent).join("");t.push({label:s.trim().replace(/\s+/g," "),value:o.getAttribute("data-value")||void 0,href:o.tagName==="A"?o.getAttribute("href"):void 0,shortcut:o.getAttribute("data-shortcut")||void 0,disabled:o.disabled||o.hasAttribute("data-disabled")||void 0})}return t}set items(t){let e=Array.isArray(t)?t:[],i=this.querySelector('menu, ul[role="menu"]');for(i||(i=document.createElement("menu"),this.appendChild(i));i.firstChild;)i.firstChild.remove();for(let o of e){let s=document.createElement("li");if(o.separator)s.setAttribute("role","separator");else if(o.group!=null)s.setAttribute("data-group",""),s.textContent=o.group;else{let n=o.href?document.createElement("a"):document.createElement("button");o.href&&n.setAttribute("href",o.href),o.value&&n.setAttribute("data-value",o.value),o.shortcut&&n.setAttribute("data-shortcut",o.shortcut),o.disabled&&n.setAttribute("data-disabled",""),n.tagName==="BUTTON"&&n.setAttribute("type","button"),n.textContent=o.label||"",s.appendChild(n)}i.appendChild(s)}this._reinit(),this.dispatchEvent(new CustomEvent("context-menu:items-changed",{detail:{items:e,source:"property"},bubbles:!0}))}#f=t=>{if(t.preventDefault(),B(t)){this.#o||this.#h();return}t.buttons!==0?this.listen(window,"pointerup",()=>{setTimeout(()=>this.#u(t.clientX,t.clientY),0)},{once:!0,capture:!0}):this.#u(t.clientX,t.clientY)};#m=t=>{t.target===this.#t&&(t.key==="ContextMenu"||t.key==="F10"&&t.shiftKey)&&(t.preventDefault(),this.#o||this.#h())};#h(){let t=this.#t.getBoundingClientRect();this.#u(t.left,t.bottom)}#u(t,e){this.#o=!0,this.setAttribute("data-open",""),this.#t?.setAttribute("aria-expanded","true"),this.#i.style.top=`${e}px`,this.#i.style.left=`${t}px`,this.#i.show(),requestAnimationFrame(()=>{let i=this.#i.getBoundingClientRect(),o=t+i.width>window.innerWidth?t-i.width:t,s=e+i.height>window.innerHeight?e-i.height:e;this.#i.style.top=`${Math.max(0,s)}px`,this.#i.style.left=`${Math.max(0,o)}px`}),this.#r=-1,this.#a(0),this.dispatchEvent(new CustomEvent("context-menu:open",{bubbles:!0}))}close(){if(!this.#o)return;let t=this.#d();this.#o=!1,this.removeAttribute("data-open"),this.#t?.setAttribute("aria-expanded","false"),this.#r=-1,this.#i?.hide(),t&&this.#p(),this.dispatchEvent(new CustomEvent("context-menu:close",{bubbles:!0}))}#d(){let t=document.activeElement;return!t||t===document.body||!!this.#i?.contains(t)}#p(){this.#t?.isConnected&&this.#t.focus({preventScroll:!0})}#b=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.#a(this.#r+1);break;case"ArrowUp":case"Up":t.preventDefault(),this.#a(this.#r-1);break;case"Home":t.preventDefault(),this.#a(0);break;case"End":t.preventDefault(),this.#a(this.#s.length-1);break;case"Enter":case" ":{t.preventDefault();let e=this.#s[this.#r];e&&!p(e)&&e.click();break}case"Tab":this.close();break}};#y=t=>{let e=t.target.closest?.('button, a, [role="menuitem"]');e&&this.#e.contains(e)&&p(e)&&(t.preventDefault(),t.stopPropagation())};#g=t=>{let e=t.currentTarget;p(e)||(this.close(),this.dispatchEvent(new CustomEvent("context-menu:select",{bubbles:!0,detail:{item:e,value:e.getAttribute("data-value")||void 0}})))};#A=()=>{this.#o&&(this.#o=!1,this.removeAttribute("data-open"),this.#t?.setAttribute("aria-expanded","false"),this.#r=-1,this.#d()&&this.#p(),this.dispatchEvent(new CustomEvent("context-menu:close",{bubbles:!0})))};#w=()=>{this.#o&&this.close()};#a(t){this.#s.length!==0&&(t<0&&(t=this.#s.length-1),t>=this.#s.length&&(t=0),this.#r=t,this.#s[t].focus())}get isOpen(){return this.#o}};d("context-menu",y);export{y as ContextMenuWc};
|
|
2
2
|
//# sourceMappingURL=context-menu.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var E=window.matchMedia("(prefers-reduced-motion: reduce)");var A=new Map;function w(h,e,t={}){let s=t.priority??10,i={impl:e,bundle:t.bundle,contract:t.contract,priority:s},n=A.get(h);if(customElements.get(h)){if(!n||n.priority>=s){n&&n.priority===s&&n.impl!==e&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${n.bundle}" (priority ${n.priority}). Skipping "${t.bundle}".`);return}console.warn(`[VB Bundle] Tag <${h}> defined by "${n.bundle}" cannot be replaced (customElements.define is permanent). "${t.bundle}" has higher priority but arrived late.`);return}if(n&&n.priority>=s){n.priority===s&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${n.bundle}". Skipping "${t.bundle}" (first wins at equal priority).`);return}A.set(h,i),customElements.define(h,e)}var m=class extends HTMLElement{#i=[];#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.#i)e();this.#i=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(e,t,s,i){e.addEventListener(t,s,i),this.#i.push(()=>e.removeEventListener(t,s,i))}setup(){}teardown(){}setState(e,t){this.#t||(this.#t=this.attachInternals());let s=this.#t.states;try{t?s.add(e):s.delete(e)}catch{let i=`--${e}`;t?s.add(i):s.delete(i)}}_adoptInternals(e){this.#t||(this.#t=e)}};function x({newItems:h,nodes:e,keyOf:t,renderItem:s,containerFor:i}){let n=[],r=[],a=[],d=new Set;for(let l of h)d.add(t(l));for(let[l,o]of[...e])d.has(l)||(o.remove(),e.delete(l),a.push(l));let c=new Map;for(let l of h){let o=t(l),u=e.get(o)||null,f=i(l,u);c.has(f)||c.set(f,[]),c.get(f)?.push({item:l,key:o,existing:u})}for(let[l,o]of c)for(let u=0;u<o.length;u++){let{item:f,key:p,existing:v}=o[u],b=v;b?(b.parentElement!==l||l.children[u]!==b)&&r.push(p):(b=s(f),e.set(p,b),n.push(p));let y=l.children[u];y!==b&&l.insertBefore(b,y||null)}return{added:n,moved:r,removed:a}}var g=class h extends m{#i;#t;#c=[];#s=[];#e=[];#o=-1;#d=null;#n=1;#r=0;#p=null;#b=null;#h=null;#l="";#a=null;#x=null;#m=[];#v=new Map;#g=[];setup(){return this.#i=this.querySelector(":scope > table"),!this.#i||(this.#t=this.#i.querySelector("tbody"),!this.#t)?!1:(this.#F(),!0)}teardown(){this.#L(),this.#c=[],this.#s=[],this.#e=[]}#F(){this.#s=[...this.#t.querySelectorAll(":scope > tr:not([data-expand-content])")],this.#e=[...this.#s],this.#g=[...this.#i.tHead?.rows[0]?.cells||[]].map(t=>({key:t.getAttribute("data-key")||t.textContent.trim().toLowerCase(),label:t.textContent.trim(),sort:t.getAttribute("data-sort")||void 0})),this.#v.clear(),this.#m=[];for(let t of this.#s){let s=t.getAttribute("data-id")||t.getAttribute("data-key");s&&(this.#v.set(s,t),this.#m.push({id:s}))}this.#B(),this.#M(),this.#R(),this.#P(),this.#i.hasAttribute("data-filterable")&&this.#K();let e=this.#i.getAttribute("data-paginate");e&&(this.#r=parseInt(e,10),this.#r>0&&this.#j()),this.#z(),this.#G(),this.#f()}get rows(){return this.#m}set rows(e){let t=e||[],s=x({newItems:t,nodes:this.#v,keyOf:i=>i.id,renderItem:i=>this._renderRow(i),containerFor:()=>this.#t});this.#m=t,this.#s=[...this.#t.querySelectorAll(":scope > tr:not([data-expand-content])")],this.#M(),this.#R(),this.#w(this.#l),this.dispatchEvent(new CustomEvent("data-table:rows-changed",{detail:{rows:t,added:s.added,moved:s.moved,removed:s.removed,source:"api"},bubbles:!0}))}get columns(){return this.#g}_renderRow(e){let t=this;if(typeof t.renderRow=="function"){let i=t.renderRow(e,this.#g);if(!(i instanceof Element))throw new Error("data-table: renderRow must return an Element");return i.hasAttribute("data-id")||i.setAttribute("data-id",String(e.id)),i}let s=document.createElement("tr");s.setAttribute("data-id",String(e.id));for(let i of this.#g){let n=document.createElement("td"),r=e[i.key];n.textContent=r==null?"":String(r),s.appendChild(n)}return s}#k=[];#u=[];#y=[];#B(){let e=[...this.#i.tHead?.rows[0]?.cells||[]];this.#k=e.map(t=>{let s=parseFloat(t.getAttribute("data-weight"));return Number.isFinite(s)?s:null}),this.#u=e.map(t=>t.getAttribute("data-rollup")||null),this.#y=e.map(t=>t.getAttribute("data-heatmap")||null)}#M(){if(this.#u.some(Boolean))for(let e=0;e<this.#u.length;e++){let t=this.#u[e];if(t)for(let s of this.#s){let i=s.children[e];if(!i)continue;let n=this.#$(s,e,t),r=h.#N(n);i.textContent=r,i.setAttribute("data-rollup-value",String(n)),i.hasAttribute("data-sort-value")||i.setAttribute("data-sort-value",String(n))}}}#$(e,t,s){let i=[...e.children],n=0,r=0,a=-1/0,d=0,c=1,l=!1;for(let o=0;o<i.length;o++){if(o===t||this.#u[o])continue;let u=i[o].getAttribute("data-sort-value")??i[o].textContent??"",f=parseFloat(u);if(!Number.isFinite(f))continue;n+=f,r++,f>a&&(a=f),c*=f,l=!0;let p=this.#k[o];p!==null&&(d+=f*p)}switch(s){case"sum":return n;case"avg":return r?n/r:0;case"max":return a===-1/0?0:a;case"weighted-sum":return d;case"product":return l?c:0;default:return n}}static#N(e){return Number.isFinite(e)?Number.isInteger(e)?String(e):(Math.round(e*100)/100).toString():""}#R(){if(this.#y.some(Boolean))for(let e=0;e<this.#y.length;e++){let t=this.#y[e];if(!t)continue;let s=this.#s.map(d=>{let c=d.children[e];if(!c)return null;let l=c.getAttribute("data-rollup-value")??c.getAttribute("data-sort-value")??c.textContent??"",o=parseFloat(l);return Number.isFinite(o)?o:null}),i=s.filter(d=>d!==null);if(!i.length)continue;let n=Math.min(...i),a=Math.max(...i)-n||1;for(let d=0;d<this.#s.length;d++){let c=this.#s[d].children[e];if(!c)continue;let l=s[d];if(l===null){c.removeAttribute("data-heat-level");continue}let o=(l-n)/a;t==="low-good"&&(o=1-o);let u=o<.34?"low":o<.67?"mid":"high";c.setAttribute("data-heat-level",u)}}}#L(){this.#h&&clearTimeout(this.#h),this.#p?.parentElement?.remove(),this.#b?.remove()}#P(){this.#i.querySelectorAll("thead th[data-sort]").forEach((t,s)=>{let i=t.getAttribute("data-sort"),n=this.#V(t);this.#c.push({th:t,sortType:i,columnIndex:n}),t.setAttribute("tabindex","0"),t.setAttribute("role","columnheader"),t.setAttribute("aria-sort","none"),t.dataset.columnIndex=n,this.listen(t,"click",this.#H),this.listen(t,"keydown",this.#D)})}#V(e){return[...e.parentElement.children].indexOf(e)}#H=e=>{let t=e.currentTarget,s=parseInt(t.dataset.columnIndex,10);this.#q(s)};#D=e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();let t=e.currentTarget,s=parseInt(t.dataset.columnIndex,10);this.#q(s)}};#O(e,t,s){let i=this.#e;if(i.length<2)return!0;let n=s==="asc"?1:-1;for(let r=1;r<i.length;r++){let a=this.#A(i[r-1].children[e],t),d=this.#A(i[r].children[e],t);if((typeof a=="string"?a.localeCompare(d)*n:(a-d)*n)>0)return!1}return!0}#q(e){let t=this.#c.find(i=>i.columnIndex===e);if(!t)return;let s;this.#o===e?s=this.#d==="asc"?"desc":"asc":this.#O(e,t.sortType,"asc")?s="desc":s="asc",this.#c.forEach(({th:i})=>{i.setAttribute("aria-sort","none")}),t.th.setAttribute("aria-sort",s==="asc"?"ascending":"descending"),this.#o=e,this.#d=s,this.#E(e,s,t.sortType),this.#n=1,this.#f(),this.dispatchEvent(new CustomEvent("data-table:sort",{detail:{column:e,direction:s,columnName:t.th.textContent.trim()},bubbles:!0}))}#E(e,t,s){let i=t==="asc"?1:-1;this.#e.sort((n,r)=>{let a=n.children[e],d=r.children[e];if(!a||!d)return 0;let c=this.#A(a,s),l=this.#A(d,s),o=0;switch(s){case"number":o=c-l;break;case"date":o=c-l;break;default:o=c.localeCompare(l,void 0,{numeric:!0,sensitivity:"base"});break}return o*i})}#A(e,t){let i=e.getAttribute("data-sort-value")??e.textContent.trim();switch(t){case"number":return parseFloat(i)||0;case"date":return new Date(i).getTime()||0;default:return i.toLowerCase()}}#K(){let e=document.createElement("div");e.setAttribute("data-table-filter","");let t=document.createElement("input");t.type="search",t.setAttribute("data-filter-input",""),t.setAttribute("placeholder","Filter table..."),t.setAttribute("aria-label","Filter table rows"),e.appendChild(t),this.insertBefore(e,this.#i),this.#p=t,this.listen(t,"input",this.#_)}#_=e=>{let t=e.target.value;this.#h&&clearTimeout(this.#h),this.#h=setTimeout(()=>{this.#w(t)},150)};#w(e){if(this.#l=e.toLowerCase().trim(),this.#l===""?this.#e=[...this.#s]:this.#e=this.#s.filter(t=>[...t.children].some(i=>(i.getAttribute("data-filter-value")??i.textContent).toLowerCase().includes(this.#l))),this.#o>=0&&this.#d){let t=this.#c.find(s=>s.columnIndex===this.#o);t&&this.#E(this.#o,this.#d,t.sortType)}this.#n=1,this.#f(),this.dispatchEvent(new CustomEvent("data-table:filter",{detail:{query:this.#l,count:this.#e.length},bubbles:!0}))}#j(){let e=document.createElement("nav");e.setAttribute("data-pagination",""),e.setAttribute("aria-label","Table pagination"),this.appendChild(e),this.#b=e}#z(){this.listen(this.#i,"click",this.#Q)}#Q=e=>{let t=e.target.closest('[data-action="toggle-expand"]');if(!t)return;let s=t.closest("tr[data-expandable]");if(!s)return;let i=s.hasAttribute("data-state-expanded"),n=s.nextElementSibling;i?(s.removeAttribute("data-state-expanded"),t.setAttribute("aria-expanded","false"),n?.hasAttribute("data-expand-content")&&(n.hidden=!0,n.setAttribute("aria-hidden","true"))):(s.setAttribute("data-state-expanded",""),t.setAttribute("aria-expanded","true"),n?.hasAttribute("data-expand-content")&&(n.hidden=!1,n.removeAttribute("aria-hidden"))),this.dispatchEvent(new CustomEvent("data-table:expand",{detail:{row:s,expanded:!i},bubbles:!0}))};#G(){this.#a=this.#i.querySelector('thead [data-action="select-all"]'),this.#a&&this.listen(this.#a,"change",this.#J),this.listen(this.#t,"change",this.#U),this.#x=this.querySelector("[data-selected-count]"),this.#T()}#J=e=>{let t=e.target.checked;this.#t.querySelectorAll("tr[data-selectable]").forEach(i=>{let n=i.querySelector('[data-action="select-row"]');t?(i.setAttribute("data-state-selected",""),n&&(n.checked=!0)):(i.removeAttribute("data-state-selected"),n&&(n.checked=!1))}),e.target.indeterminate=!1,this.#C(),this.#I()};#U=e=>{let t=e.target.closest('[data-action="select-row"]');if(!t)return;let s=t.closest("tr[data-selectable]");s&&(t.checked?s.setAttribute("data-state-selected",""):s.removeAttribute("data-state-selected"),this.#T(),this.#I())};#T(){if(!this.#a){this.#C();return}let e=this.#t.querySelectorAll("tr[data-selectable]"),t=this.#t.querySelectorAll("tr[data-selectable][data-state-selected]"),s=e.length,i=t.length;i===0?(this.#a.checked=!1,this.#a.indeterminate=!1):i===s?(this.#a.checked=!0,this.#a.indeterminate=!1):(this.#a.checked=!1,this.#a.indeterminate=!0),this.#C()}#C(){let t=this.#t.querySelectorAll("tr[data-selectable][data-state-selected]").length;this.#x&&(this.#x.textContent=t)}#I(){let e=[...this.#t.querySelectorAll("tr[data-selectable][data-state-selected]")];this.dispatchEvent(new CustomEvent("data-table:selection",{detail:{count:e.length,rows:e},bubbles:!0}))}#W(){if(!this.#b||this.#r<=0)return;let e=this.#b,t=Math.ceil(this.#e.length/this.#r);if(e.innerHTML="",t<=1)return;let s=document.createElement("button");s.type="button",s.textContent="Previous",s.setAttribute("data-pagination-prev",""),s.disabled=this.#n===1,s.addEventListener("click",()=>this.goToPage(this.#n-1)),e.appendChild(s),this.#X(t).forEach(r=>{if(r==="..."){let a=document.createElement("span");a.textContent="...",a.setAttribute("data-pagination-ellipsis",""),e.appendChild(a)}else{let a=document.createElement("button");a.type="button",a.textContent=r,a.setAttribute("data-pagination-page",""),r===this.#n&&(a.setAttribute("aria-current","page"),a.setAttribute("data-current","")),a.addEventListener("click",()=>this.goToPage(r)),e.appendChild(a)}});let n=document.createElement("button");n.type="button",n.textContent="Next",n.setAttribute("data-pagination-next",""),n.disabled=this.#n===t,n.addEventListener("click",()=>this.goToPage(this.#n+1)),e.appendChild(n)}#X(e){let t=this.#n,s=[];if(e<=7)for(let i=1;i<=e;i++)s.push(i);else{s.push(1),t>3&&s.push("...");let i=Math.max(2,t-1),n=Math.min(e-1,t+1);for(let r=i;r<=n;r++)s.push(r);t<e-2&&s.push("..."),s.push(e)}return s}#f(){this.#s.forEach(t=>{t.setAttribute("data-state-hidden","")});let e;if(this.#r>0){let t=(this.#n-1)*this.#r,s=t+this.#r;e=this.#e.slice(t,s)}else e=this.#e;e.forEach(t=>{t.removeAttribute("data-state-hidden"),this.#t.appendChild(t);let s=t.nextElementSibling?.hasAttribute?.("data-expand-content")?t.nextElementSibling:this.#S(t);s&&this.#t.appendChild(s)}),this.#e.forEach(t=>{if(t.hasAttribute("data-state-hidden")){this.#t.appendChild(t);let s=this.#S(t);s&&this.#t.appendChild(s)}}),this.#s.forEach(t=>{if(!this.#e.includes(t)){this.#t.appendChild(t);let s=this.#S(t);s&&this.#t.appendChild(s)}}),this.#W()}#S(e){if(!e.hasAttribute("data-expandable"))return null;let t=e.nextElementSibling;return t?.hasAttribute("data-expand-content")?t:null}goToPage(e){let t=Math.ceil(this.#e.length/this.#r),s=Math.max(1,Math.min(e,t));s!==this.#n&&(this.#n=s,this.#f(),this.dispatchEvent(new CustomEvent("data-table:page",{detail:{page:this.#n},bubbles:!0})))}setFilter(e){this.#p&&(this.#p.value=e),this.#w(e)}refresh(){if(this.#s=[...this.#t.querySelectorAll(":scope > tr")],this.#l?this.#w(this.#l):this.#e=[...this.#s],this.#o>=0&&this.#d){let t=this.#c.find(s=>s.columnIndex===this.#o);t&&this.#E(this.#o,this.#d,t.sortType)}let e=Math.max(1,Math.ceil(this.#e.length/this.#r));this.#n>e&&(this.#n=e),this.#f()}get currentPage(){return this.#n}get totalPages(){return this.#r<=0?1:Math.ceil(this.#e.length/this.#r)}get filteredCount(){return this.#e.length}get totalCount(){return this.#s.length}getSelectedRows(){return this.#t?[...this.#t.querySelectorAll("tr[data-selectable][data-state-selected]")]:[]}};w("data-table",g);export{g as DataTable};
|
|
1
|
+
var E=window.matchMedia("(prefers-reduced-motion: reduce)");var y=new Map;function w(h,e,t={}){let s=t.priority??10,i={impl:e,bundle:t.bundle,contract:t.contract,priority:s},n=y.get(h);if(customElements.get(h)){if(!n||n.priority>=s){n&&n.priority===s&&n.impl!==e&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${n.bundle}" (priority ${n.priority}). Skipping "${t.bundle}".`);return}console.warn(`[VB Bundle] Tag <${h}> defined by "${n.bundle}" cannot be replaced (customElements.define is permanent). "${t.bundle}" has higher priority but arrived late.`);return}if(n&&n.priority>=s){n.priority===s&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${n.bundle}". Skipping "${t.bundle}" (first wins at equal priority).`);return}y.set(h,i),customElements.define(h,e)}var m=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,s,i){e.addEventListener(t,s,i),this.#e.push(()=>e.removeEventListener(t,s,i))}_reinit(){for(let e of this.#e)e();this.#e=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(e,t){this.#t||(this.#t=this.attachInternals());let s=this.#t.states;try{t?s.add(e):s.delete(e)}catch{let i=`--${e}`;t?s.add(i):s.delete(i)}}_adoptInternals(e){this.#t||(this.#t=e)}};function x({newItems:h,nodes:e,keyOf:t,renderItem:s,containerFor:i}){let n=[],r=[],a=[],d=new Set;for(let l of h)d.add(t(l));for(let[l,o]of[...e])d.has(l)||(o.remove(),e.delete(l),a.push(l));let c=new Map;for(let l of h){let o=t(l),u=e.get(o)||null,f=i(l,u);c.has(f)||c.set(f,[]),c.get(f)?.push({item:l,key:o,existing:u})}for(let[l,o]of c)for(let u=0;u<o.length;u++){let{item:f,key:p,existing:v}=o[u],b=v;b?(b.parentElement!==l||l.children[u]!==b)&&r.push(p):(b=s(f),e.set(p,b),n.push(p));let A=l.children[u];A!==b&&l.insertBefore(b,A||null)}return{added:n,moved:r,removed:a}}var g=class h extends m{#e;#t;#c=[];#i=[];#s=[];#o=-1;#d=null;#n=1;#r=0;#p=null;#b=null;#h=null;#l="";#a=null;#x=null;#m=[];#v=new Map;#g=[];setup(){return this.#e=this.querySelector(":scope > table"),!this.#e||(this.#t=this.#e.querySelector("tbody"),!this.#t)?!1:(this.#F(),!0)}teardown(){this.#L(),this.#c=[],this.#i=[],this.#s=[]}#F(){this.#i=[...this.#t.querySelectorAll(":scope > tr:not([data-expand-content])")],this.#s=[...this.#i],this.#g=[...this.#e.tHead?.rows[0]?.cells||[]].map(t=>({key:t.getAttribute("data-key")||t.textContent.trim().toLowerCase(),label:t.textContent.trim(),sort:t.getAttribute("data-sort")||void 0})),this.#v.clear(),this.#m=[];for(let t of this.#i){let s=t.getAttribute("data-id")||t.getAttribute("data-key");s&&(this.#v.set(s,t),this.#m.push({id:s}))}this.#B(),this.#M(),this.#R(),this.#P(),this.#e.hasAttribute("data-filterable")&&this.#_();let e=this.#e.getAttribute("data-paginate");e&&(this.#r=parseInt(e,10),this.#r>0&&this.#j()),this.#z(),this.#G(),this.#f()}get rows(){return this.#m}set rows(e){let t=e||[],s=x({newItems:t,nodes:this.#v,keyOf:i=>i.id,renderItem:i=>this._renderRow(i),containerFor:()=>this.#t});this.#m=t,this.#i=[...this.#t.querySelectorAll(":scope > tr:not([data-expand-content])")],this.#M(),this.#R(),this.#w(this.#l),this.dispatchEvent(new CustomEvent("data-table:rows-changed",{detail:{rows:t,added:s.added,moved:s.moved,removed:s.removed,source:"api"},bubbles:!0}))}get columns(){return this.#g}_renderRow(e){let t=this;if(typeof t.renderRow=="function"){let i=t.renderRow(e,this.#g);if(!(i instanceof Element))throw new Error("data-table: renderRow must return an Element");return i.hasAttribute("data-id")||i.setAttribute("data-id",String(e.id)),i}let s=document.createElement("tr");s.setAttribute("data-id",String(e.id));for(let i of this.#g){let n=document.createElement("td"),r=e[i.key];n.textContent=r==null?"":String(r),s.appendChild(n)}return s}#k=[];#u=[];#A=[];#B(){let e=[...this.#e.tHead?.rows[0]?.cells||[]];this.#k=e.map(t=>{let s=parseFloat(t.getAttribute("data-weight"));return Number.isFinite(s)?s:null}),this.#u=e.map(t=>t.getAttribute("data-rollup")||null),this.#A=e.map(t=>t.getAttribute("data-heatmap")||null)}#M(){if(this.#u.some(Boolean))for(let e=0;e<this.#u.length;e++){let t=this.#u[e];if(t)for(let s of this.#i){let i=s.children[e];if(!i)continue;let n=this.#$(s,e,t),r=h.#N(n);i.textContent=r,i.setAttribute("data-rollup-value",String(n)),i.hasAttribute("data-sort-value")||i.setAttribute("data-sort-value",String(n))}}}#$(e,t,s){let i=[...e.children],n=0,r=0,a=-1/0,d=0,c=1,l=!1;for(let o=0;o<i.length;o++){if(o===t||this.#u[o])continue;let u=i[o].getAttribute("data-sort-value")??i[o].textContent??"",f=parseFloat(u);if(!Number.isFinite(f))continue;n+=f,r++,f>a&&(a=f),c*=f,l=!0;let p=this.#k[o];p!==null&&(d+=f*p)}switch(s){case"sum":return n;case"avg":return r?n/r:0;case"max":return a===-1/0?0:a;case"weighted-sum":return d;case"product":return l?c:0;default:return n}}static#N(e){return Number.isFinite(e)?Number.isInteger(e)?String(e):(Math.round(e*100)/100).toString():""}#R(){if(this.#A.some(Boolean))for(let e=0;e<this.#A.length;e++){let t=this.#A[e];if(!t)continue;let s=this.#i.map(d=>{let c=d.children[e];if(!c)return null;let l=c.getAttribute("data-rollup-value")??c.getAttribute("data-sort-value")??c.textContent??"",o=parseFloat(l);return Number.isFinite(o)?o:null}),i=s.filter(d=>d!==null);if(!i.length)continue;let n=Math.min(...i),a=Math.max(...i)-n||1;for(let d=0;d<this.#i.length;d++){let c=this.#i[d].children[e];if(!c)continue;let l=s[d];if(l===null){c.removeAttribute("data-heat-level");continue}let o=(l-n)/a;t==="low-good"&&(o=1-o);let u=o<.34?"low":o<.67?"mid":"high";c.setAttribute("data-heat-level",u)}}}#L(){this.#h&&clearTimeout(this.#h),this.#p?.parentElement?.remove(),this.#b?.remove()}#P(){this.#e.querySelectorAll("thead th[data-sort]").forEach((t,s)=>{let i=t.getAttribute("data-sort"),n=this.#V(t);this.#c.push({th:t,sortType:i,columnIndex:n}),t.setAttribute("tabindex","0"),t.setAttribute("role","columnheader"),t.setAttribute("aria-sort","none"),t.dataset.columnIndex=n,this.listen(t,"click",this.#H),this.listen(t,"keydown",this.#D)})}#V(e){return[...e.parentElement.children].indexOf(e)}#H=e=>{let t=e.currentTarget,s=parseInt(t.dataset.columnIndex,10);this.#q(s)};#D=e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();let t=e.currentTarget,s=parseInt(t.dataset.columnIndex,10);this.#q(s)}};#O(e,t,s){let i=this.#s;if(i.length<2)return!0;let n=s==="asc"?1:-1;for(let r=1;r<i.length;r++){let a=this.#y(i[r-1].children[e],t),d=this.#y(i[r].children[e],t);if((typeof a=="string"?a.localeCompare(d)*n:(a-d)*n)>0)return!1}return!0}#q(e){let t=this.#c.find(i=>i.columnIndex===e);if(!t)return;let s;this.#o===e?s=this.#d==="asc"?"desc":"asc":this.#O(e,t.sortType,"asc")?s="desc":s="asc",this.#c.forEach(({th:i})=>{i.setAttribute("aria-sort","none")}),t.th.setAttribute("aria-sort",s==="asc"?"ascending":"descending"),this.#o=e,this.#d=s,this.#E(e,s,t.sortType),this.#n=1,this.#f(),this.dispatchEvent(new CustomEvent("data-table:sort",{detail:{column:e,direction:s,columnName:t.th.textContent.trim()},bubbles:!0}))}#E(e,t,s){let i=t==="asc"?1:-1;this.#s.sort((n,r)=>{let a=n.children[e],d=r.children[e];if(!a||!d)return 0;let c=this.#y(a,s),l=this.#y(d,s),o=0;switch(s){case"number":o=c-l;break;case"date":o=c-l;break;default:o=c.localeCompare(l,void 0,{numeric:!0,sensitivity:"base"});break}return o*i})}#y(e,t){let i=e.getAttribute("data-sort-value")??e.textContent.trim();switch(t){case"number":return parseFloat(i)||0;case"date":return new Date(i).getTime()||0;default:return i.toLowerCase()}}#_(){let e=document.createElement("div");e.setAttribute("data-table-filter","");let t=document.createElement("input");t.type="search",t.setAttribute("data-filter-input",""),t.setAttribute("placeholder","Filter table..."),t.setAttribute("aria-label","Filter table rows"),e.appendChild(t),this.insertBefore(e,this.#e),this.#p=t,this.listen(t,"input",this.#K)}#K=e=>{let t=e.target.value;this.#h&&clearTimeout(this.#h),this.#h=setTimeout(()=>{this.#w(t)},150)};#w(e){if(this.#l=e.toLowerCase().trim(),this.#l===""?this.#s=[...this.#i]:this.#s=this.#i.filter(t=>[...t.children].some(i=>(i.getAttribute("data-filter-value")??i.textContent).toLowerCase().includes(this.#l))),this.#o>=0&&this.#d){let t=this.#c.find(s=>s.columnIndex===this.#o);t&&this.#E(this.#o,this.#d,t.sortType)}this.#n=1,this.#f(),this.dispatchEvent(new CustomEvent("data-table:filter",{detail:{query:this.#l,count:this.#s.length},bubbles:!0}))}#j(){let e=document.createElement("nav");e.setAttribute("data-pagination",""),e.setAttribute("aria-label","Table pagination"),this.appendChild(e),this.#b=e}#z(){this.listen(this.#e,"click",this.#Q)}#Q=e=>{let t=e.target.closest('[data-action="toggle-expand"]');if(!t)return;let s=t.closest("tr[data-expandable]");if(!s)return;let i=s.hasAttribute("data-state-expanded"),n=s.nextElementSibling;i?(s.removeAttribute("data-state-expanded"),t.setAttribute("aria-expanded","false"),n?.hasAttribute("data-expand-content")&&(n.hidden=!0,n.setAttribute("aria-hidden","true"))):(s.setAttribute("data-state-expanded",""),t.setAttribute("aria-expanded","true"),n?.hasAttribute("data-expand-content")&&(n.hidden=!1,n.removeAttribute("aria-hidden"))),this.dispatchEvent(new CustomEvent("data-table:expand",{detail:{row:s,expanded:!i},bubbles:!0}))};#G(){this.#a=this.#e.querySelector('thead [data-action="select-all"]'),this.#a&&this.listen(this.#a,"change",this.#J),this.listen(this.#t,"change",this.#U),this.#x=this.querySelector("[data-selected-count]"),this.#T()}#J=e=>{let t=e.target.checked;this.#t.querySelectorAll("tr[data-selectable]").forEach(i=>{let n=i.querySelector('[data-action="select-row"]');t?(i.setAttribute("data-state-selected",""),n&&(n.checked=!0)):(i.removeAttribute("data-state-selected"),n&&(n.checked=!1))}),e.target.indeterminate=!1,this.#C(),this.#I()};#U=e=>{let t=e.target.closest('[data-action="select-row"]');if(!t)return;let s=t.closest("tr[data-selectable]");s&&(t.checked?s.setAttribute("data-state-selected",""):s.removeAttribute("data-state-selected"),this.#T(),this.#I())};#T(){if(!this.#a){this.#C();return}let e=this.#t.querySelectorAll("tr[data-selectable]"),t=this.#t.querySelectorAll("tr[data-selectable][data-state-selected]"),s=e.length,i=t.length;i===0?(this.#a.checked=!1,this.#a.indeterminate=!1):i===s?(this.#a.checked=!0,this.#a.indeterminate=!1):(this.#a.checked=!1,this.#a.indeterminate=!0),this.#C()}#C(){let t=this.#t.querySelectorAll("tr[data-selectable][data-state-selected]").length;this.#x&&(this.#x.textContent=t)}#I(){let e=[...this.#t.querySelectorAll("tr[data-selectable][data-state-selected]")];this.dispatchEvent(new CustomEvent("data-table:selection",{detail:{count:e.length,rows:e},bubbles:!0}))}#W(){if(!this.#b||this.#r<=0)return;let e=this.#b,t=Math.ceil(this.#s.length/this.#r);if(e.innerHTML="",t<=1)return;let s=document.createElement("button");s.type="button",s.textContent="Previous",s.setAttribute("data-pagination-prev",""),s.disabled=this.#n===1,s.addEventListener("click",()=>this.goToPage(this.#n-1)),e.appendChild(s),this.#X(t).forEach(r=>{if(r==="..."){let a=document.createElement("span");a.textContent="...",a.setAttribute("data-pagination-ellipsis",""),e.appendChild(a)}else{let a=document.createElement("button");a.type="button",a.textContent=r,a.setAttribute("data-pagination-page",""),r===this.#n&&(a.setAttribute("aria-current","page"),a.setAttribute("data-current","")),a.addEventListener("click",()=>this.goToPage(r)),e.appendChild(a)}});let n=document.createElement("button");n.type="button",n.textContent="Next",n.setAttribute("data-pagination-next",""),n.disabled=this.#n===t,n.addEventListener("click",()=>this.goToPage(this.#n+1)),e.appendChild(n)}#X(e){let t=this.#n,s=[];if(e<=7)for(let i=1;i<=e;i++)s.push(i);else{s.push(1),t>3&&s.push("...");let i=Math.max(2,t-1),n=Math.min(e-1,t+1);for(let r=i;r<=n;r++)s.push(r);t<e-2&&s.push("..."),s.push(e)}return s}#f(){this.#i.forEach(t=>{t.setAttribute("data-state-hidden","")});let e;if(this.#r>0){let t=(this.#n-1)*this.#r,s=t+this.#r;e=this.#s.slice(t,s)}else e=this.#s;e.forEach(t=>{t.removeAttribute("data-state-hidden"),this.#t.appendChild(t);let s=t.nextElementSibling?.hasAttribute?.("data-expand-content")?t.nextElementSibling:this.#S(t);s&&this.#t.appendChild(s)}),this.#s.forEach(t=>{if(t.hasAttribute("data-state-hidden")){this.#t.appendChild(t);let s=this.#S(t);s&&this.#t.appendChild(s)}}),this.#i.forEach(t=>{if(!this.#s.includes(t)){this.#t.appendChild(t);let s=this.#S(t);s&&this.#t.appendChild(s)}}),this.#W()}#S(e){if(!e.hasAttribute("data-expandable"))return null;let t=e.nextElementSibling;return t?.hasAttribute("data-expand-content")?t:null}goToPage(e){let t=Math.ceil(this.#s.length/this.#r),s=Math.max(1,Math.min(e,t));s!==this.#n&&(this.#n=s,this.#f(),this.dispatchEvent(new CustomEvent("data-table:page",{detail:{page:this.#n},bubbles:!0})))}setFilter(e){this.#p&&(this.#p.value=e),this.#w(e)}refresh(){if(this.#i=[...this.#t.querySelectorAll(":scope > tr")],this.#l?this.#w(this.#l):this.#s=[...this.#i],this.#o>=0&&this.#d){let t=this.#c.find(s=>s.columnIndex===this.#o);t&&this.#E(this.#o,this.#d,t.sortType)}let e=Math.max(1,Math.ceil(this.#s.length/this.#r));this.#n>e&&(this.#n=e),this.#f()}get currentPage(){return this.#n}get totalPages(){return this.#r<=0?1:Math.ceil(this.#s.length/this.#r)}get filteredCount(){return this.#s.length}get totalCount(){return this.#i.length}getSelectedRows(){return this.#t?[...this.#t.querySelectorAll("tr[data-selectable][data-state-selected]")]:[]}};w("data-table",g);export{g as DataTable};
|
|
2
2
|
//# sourceMappingURL=data-table.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var S=window.matchMedia("(prefers-reduced-motion: reduce)");var A=new Map;function E(a,t,i={}){let e=i.priority??10,s={impl:t,bundle:i.bundle,contract:i.contract,priority:e},n=A.get(a);if(customElements.get(a)){if(!n||n.priority>=e){n&&n.priority===e&&n.impl!==t&&console.warn(`[VB Bundle] Tag <${a}> already registered by "${n.bundle}" (priority ${n.priority}). Skipping "${i.bundle}".`);return}console.warn(`[VB Bundle] Tag <${a}> defined by "${n.bundle}" cannot be replaced (customElements.define is permanent). "${i.bundle}" has higher priority but arrived late.`);return}if(n&&n.priority>=e){n.priority===e&&console.warn(`[VB Bundle] Tag <${a}> already registered by "${n.bundle}". Skipping "${i.bundle}" (first wins at equal priority).`);return}A.set(a,s),customElements.define(a,t)}var m=class extends HTMLElement{#c=[];#i;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.#c)t();this.#c=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,i,e,s){t.addEventListener(i,e,s),this.#c.push(()=>t.removeEventListener(i,e,s))}setup(){}teardown(){}setState(t,i){this.#i||(this.#i=this.attachInternals());let e=this.#i.states;try{i?e.add(t):e.delete(t)}catch{let s=`--${t}`;i?e.add(s):e.delete(s)}}_adoptInternals(t){this.#i||(this.#i=t)}};var C="popover"in HTMLElement.prototype;var x=["Su","Mo","Tu","We","Th","Fr","Sa"],k=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],D=["january","february","march","april","may","june","july","august","september","october","november","december"];function d(a){let t=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0"),e=String(a.getDate()).padStart(2,"0");return`${t}-${i}-${e}`}function p(a){if(!a)return null;let[t,i,e]=a.split("-").map(Number);return new Date(t,i-1,e)}function b(a,t){return new Date(a,t+1,0).getDate()}function F(){try{let a=new Intl.Locale(navigator.language);if(a.weekInfo)return a.weekInfo.firstDay%7}catch{}return 0}function N(a){try{return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"long",day:"numeric"}).format(a)}catch{return d(a)}}function g(a,t){return a&&t&&a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function T(){let a=new Map;D.forEach((t,i)=>{a.set(t,i),a.set(t.slice(0,3),i)});try{for(let t=0;t<12;t++){let i=new Intl.DateTimeFormat(void 0,{month:"long"}).format(new Date(2e3,t,1)).toLowerCase(),e=new Intl.DateTimeFormat(void 0,{month:"short"}).format(new Date(2e3,t,1)).toLowerCase().replace(".","");a.set(i,t),a.set(e,t)}}catch{}return a}var w=T();function y(a){let t=a.trim();if(!t)return{date:null,partial:null};if(/^\d{4}-\d{2}-\d{2}$/.test(t)){let r=p(t);return r&&!isNaN(r.getTime())?{date:r,partial:null}:{date:null,partial:null}}if(/^\d{4}\/\d{2}\/\d{2}$/.test(t)){let r=p(t.replace(/\//g,"-"));return r&&!isNaN(r.getTime())?{date:r,partial:null}:{date:null,partial:null}}let i=/^([a-z\u00C0-\u024F]+)\s+(\d{1,2}),?\s+(\d{4})$/i,e=t.match(i);if(e){let r=w.get(e[1].toLowerCase());if(r!==void 0){let h=new Date(Number(e[3]),r,Number(e[2]));if(!isNaN(h.getTime()))return{date:h,partial:null}}}let s=/^(\d{1,2})\s+([a-z\u00C0-\u024F]+)\s+(\d{4})$/i;if(e=t.match(s),e){let r=w.get(e[2].toLowerCase());if(r!==void 0){let h=new Date(Number(e[3]),r,Number(e[1]));if(!isNaN(h.getTime()))return{date:h,partial:null}}}let n=/^([a-z\u00C0-\u024F]+)\s+(\d{4})$/i;if(e=t.match(n),e){let r=w.get(e[1].toLowerCase());if(r!==void 0)return{date:null,partial:{year:Number(e[2]),month:r}}}return{date:null,partial:null}}var v=class extends m{static formAssociated=!0;#c;#i;#t;#p;#b;#a;#y;#f;#D;#u;#l=!1;#v=!1;#e=null;#n=null;#r=new Date().getFullYear();#s=new Date().getMonth();#h=null;#o=null;#x=new Map;#k=new Map;#S=null;#A=0;constructor(){super(),this.#c=this.attachInternals(),this._adoptInternals(this.#c)}setup(){if(this.#i=this.querySelector(':scope > input[type="date"]'),!this.#i)return!1;this.#h=p(this.#i.getAttribute("min")),this.#o=p(this.#i.getAttribute("max")),this.#A=F();let t=this.getAttribute("data-disabled-dates");t&&t.split(",").forEach(s=>{let[n,r]=s.trim().split(":");this.#x.set(n,r||"")});let i=this.getAttribute("data-highlight-dates");i&&i.split(",").forEach(s=>{let[n,r]=s.trim().split(":");this.#k.set(n,r||"")}),this.#e=p(this.#i.value),this.#S=this.#i.value;let e=new Date;return this.#o&&e>this.#o&&(e=this.#o),this.#h&&e<this.#h&&(e=this.#h),this.#r=this.#e?this.#e.getFullYear():e.getFullYear(),this.#s=this.#e?this.#e.getMonth():e.getMonth(),this.#n=this.#e||e,this.#i.setAttribute("tabindex","-1"),this.#i.setAttribute("aria-hidden","true"),this.#i.style.cssText="position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;overflow:hidden;",this.#P(),this.#B(),this.#g(),this.#E(),this.#C(),this.#v=C,this.#v&&this.#a.setAttribute("popover","manual"),this.listen(document,"click",this.#z),(this.#i.disabled||this.hasAttribute("disabled"))&&(this.setAttribute("data-disabled",""),this.#t.disabled=!0),!0}teardown(){window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w)}#P(){this.#b=document.createElement("div"),this.#b.className="date-trigger",this.#t=document.createElement("input"),this.#t.type="text",this.#t.className="date-input",this.#t.setAttribute("role","combobox"),this.#t.setAttribute("aria-haspopup","dialog"),this.#t.setAttribute("aria-expanded","false"),this.#t.setAttribute("autocomplete","off"),this.#t.setAttribute("placeholder","Type a date\u2026"),this.#b.appendChild(this.#t),this.#p=document.createElement("button"),this.#p.type="button",this.#p.className="date-trigger-icon",this.#p.setAttribute("aria-label","Toggle calendar"),this.#p.setAttribute("tabindex","-1");let t=document.createElement("icon-wc");t.setAttribute("name","calendar"),t.setAttribute("size","sm"),t.setAttribute("aria-hidden","true"),this.#p.appendChild(t),this.#b.appendChild(this.#p),this.appendChild(this.#b),this.listen(this.#p,"click",i=>{i.stopPropagation(),this.#l?this.#m():this.#T(),this.#t.focus()}),this.listen(this.#t,"focus",()=>this.#t.select()),this.listen(this.#t,"input",this.#O),this.listen(this.#t,"keydown",this.#q),this.listen(this.#t,"blur",this.#R)}#B(){this.#y=`dp-${Math.random().toString(36).slice(2,8)}`,this.#a=document.createElement("div"),this.#a.className="calendar",this.#a.id=this.#y,this.#a.setAttribute("role","dialog"),this.#a.setAttribute("aria-modal","false"),this.#a.setAttribute("aria-label","Choose date"),this.#a.hidden=!0,this.#t.setAttribute("aria-controls",this.#y);let t=document.createElement("div");t.className="calendar-header";let i=document.createElement("button");i.type="button",i.className="calendar-nav",i.setAttribute("aria-label","Previous month");let e=document.createElement("icon-wc");e.setAttribute("name","chevron-left"),e.setAttribute("size","sm"),e.setAttribute("aria-hidden","true"),i.appendChild(e);let s=document.createElement("span");s.className="calendar-title",s.id=`${this.#y}-title`,s.setAttribute("aria-live","polite"),this.#D=document.createElement("span"),this.#D.className="calendar-month",this.#u=document.createElement("select"),this.#u.className="calendar-year",this.#u.setAttribute("aria-label","Year"),this.#Y(),s.appendChild(this.#D),s.appendChild(this.#u);let n=document.createElement("button");n.type="button",n.className="calendar-nav",n.setAttribute("aria-label","Next month");let r=document.createElement("icon-wc");r.setAttribute("name","chevron-right"),r.setAttribute("size","sm"),r.setAttribute("aria-hidden","true"),n.appendChild(r),t.appendChild(i),t.appendChild(s),t.appendChild(n),this.#a.appendChild(t);let h=document.createElement("table");h.setAttribute("role","grid"),h.setAttribute("aria-labelledby",`${this.#y}-title`);let u=document.createElement("thead"),c=document.createElement("tr");for(let l=0;l<7;l++){let o=(this.#A+l)%7,f=document.createElement("th");f.setAttribute("abbr",k[o]),f.setAttribute("scope","col"),f.textContent=x[o],c.appendChild(f)}u.appendChild(c),h.appendChild(u),this.#f=document.createElement("tbody"),h.appendChild(this.#f),this.#a.appendChild(h),this.appendChild(this.#a),this.#d(),this.listen(i,"click",()=>this.#L(-1)),this.listen(n,"click",()=>this.#L(1)),this.listen(this.#u,"change",()=>{this.#r=Number(this.#u.value);let l=b(this.#r,this.#s),o=Math.min(this.#n?.getDate()??1,l);this.#n=new Date(this.#r,this.#s,o),this.#d()}),this.listen(this.#f,"click",this.#H),this.listen(this.#a,"keydown",this.#V)}#d(){try{this.#D.textContent=new Intl.DateTimeFormat(void 0,{month:"long"}).format(new Date(this.#r,this.#s,1))}catch{this.#D.textContent=D[this.#s].charAt(0).toUpperCase()+D[this.#s].slice(1)}this.#u.querySelector(`option[value="${this.#r}"]`)||this.#Y(),this.#u.value=String(this.#r),this.#f.innerHTML="";let t=b(this.#r,this.#s),e=(new Date(this.#r,this.#s,1).getDay()-this.#A+7)%7,s=new Date,n=document.createElement("tr");for(let h=0;h<e;h++)n.appendChild(document.createElement("td"));for(let h=1;h<=t;h++){let u=new Date(this.#r,this.#s,h),c=d(u),l=document.createElement("td"),o=document.createElement("button");o.type="button",o.setAttribute("data-date",c),o.textContent=String(h),g(u,s)&&o.setAttribute("aria-current","date"),g(u,this.#e)&&o.setAttribute("aria-selected","true");let f=this.#$(u,c);if(f.disabled&&(o.setAttribute("aria-disabled","true"),o.setAttribute("disabled",""),f.reason&&o.setAttribute("data-disabled-reason",f.reason)),this.#k.has(c)){let M=this.#k.get(c);o.setAttribute("data-highlight",M||"")}g(u,this.#n)?(o.setAttribute("tabindex","0"),g(u,this.#e)||o.setAttribute("data-focused","")):o.setAttribute("tabindex","-1"),l.appendChild(o),n.appendChild(l),(e+h)%7===0&&(this.#f.appendChild(n),n=document.createElement("tr"))}let r=(e+t)%7;if(r>0){for(let h=r;h<7;h++)n.appendChild(document.createElement("td"));this.#f.appendChild(n)}}#F(t,i){return this.#$(t,i).disabled}#$(t,i){return this.#x.has(i)?{disabled:!0,reason:this.#x.get(i)}:this.#h&&t<this.#h?{disabled:!0,reason:null}:this.#o&&t>this.#o?{disabled:!0,reason:null}:{disabled:!1,reason:null}}#Y(){this.#u.innerHTML="";let t=new Date().getFullYear(),i=this.#h?this.#h.getFullYear():t-100,e=this.#o?this.#o.getFullYear():t+10;for(let s=i;s<=e;s++){let n=document.createElement("option");n.value=String(s),n.textContent=String(s),this.#u.appendChild(n)}}#L(t){this.#s+=t,this.#s>11?(this.#s=0,this.#r++):this.#s<0&&(this.#s=11,this.#r--);let i=b(this.#r,this.#s),e=Math.min(this.#n?.getDate()??1,i);this.#n=new Date(this.#r,this.#s,e),this.#d(),this.#N(this.#n)}#M(t,i="internal"){let e=d(t);this.#F(t,e)||this.#e&&d(this.#e)===e||(this.#e=t,this.#n=t,this.#g(),this.#E(),this.#C(),this.#d(),this.#m(),this.#t.focus(),this.dispatchEvent(new CustomEvent("date-picker:change",{bubbles:!0,detail:{value:e,date:new Date(t),source:i}})))}#N(t){let i=d(t),e=this.#f.querySelector(`[data-date="${i}"]`);e&&(this.#f.querySelectorAll('button[tabindex="0"]').forEach(s=>{s.setAttribute("tabindex","-1")}),e.setAttribute("tabindex","0"),e.focus())}#g(){this.#e?this.#t.value=N(this.#e):this.#t.value=""}#T(){if(!this.#l){if(this.#l=!0,this.setAttribute("open",""),this.#t.setAttribute("aria-expanded","true"),this.#a.hidden=!1,this.#n&&(this.#r=this.#n.getFullYear(),this.#s=this.#n.getMonth()),this.#d(),this.#v){try{this.#a.showPopover()}catch{}this.#I(),window.addEventListener("scroll",this.#w,{capture:!0,passive:!0}),window.addEventListener("resize",this.#w,{passive:!0})}this.dispatchEvent(new CustomEvent("date-picker:open",{bubbles:!0}))}}#m(){if(this.#l){if(this.#l=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#a.hidden=!0,this.#v){try{this.#a.hidePopover()}catch{}window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w)}this.dispatchEvent(new CustomEvent("date-picker:close",{bubbles:!0}))}}#I(){if(!this.#v)return;let t=this.#b.getBoundingClientRect(),i=this.#a.getBoundingClientRect(),e=4,s=8,n=window.innerHeight,r=window.innerWidth,h=n-t.bottom-s,u=t.top-s,c;h<i.height&&u>h?(c=t.top-i.height-e,this.#a.dataset.placement="top"):(c=t.bottom+e,delete this.#a.dataset.placement);let l=t.left;l+i.width>r-s&&(l=r-i.width-s),l<s&&(l=s),this.#a.style.setProperty("--calendar-top",`${c}px`),this.#a.style.setProperty("--calendar-left",`${l}px`)}#w=()=>{this.#l&&this.#I()};#O=()=>{let t=this.#t.value,{date:i,partial:e}=y(t);if(i)this.#n=i,this.#r=i.getFullYear(),this.#s=i.getMonth(),this.#d();else if(e){this.#r=e.year,this.#s=e.month;let s=b(e.year,e.month),n=Math.min(this.#n?.getDate()??1,s);this.#n=new Date(e.year,e.month,n),this.#d()}!this.#l&&t.length>0&&this.#T()};#q=t=>{switch(t.key){case"Enter":{t.preventDefault(),t.stopPropagation();let{date:i}=y(this.#t.value);i&&!this.#F(i,d(i))&&this.#M(i);return}case"ArrowDown":t.preventDefault(),t.stopPropagation(),this.#l||this.#T(),requestAnimationFrame(()=>this.#N(this.#n));return;case"Escape":t.preventDefault(),t.stopPropagation(),this.#l&&this.#m(),this.#g();return;case"Tab":this.#l&&this.#m();return}};#R=t=>{if(t.relatedTarget&&this.contains(t.relatedTarget))return;let i=this.#t.value.trim();if(i){let{date:e}=y(i);e&&!this.#F(e,d(e))&&(this.#e=e,this.#n=e,this.#E(),this.#C(),this.dispatchEvent(new CustomEvent("date-picker:change",{bubbles:!0,detail:{value:d(e),date:new Date(e)}})))}this.#g(),this.#l&&this.#m(),this.#i.dispatchEvent(new Event("blur",{bubbles:!0}))};#z=t=>{this.#l&&!this.contains(t.target)&&this.#m()};#H=t=>{let e=t.target?.closest("button[data-date]");if(!e||e.hasAttribute("disabled"))return;let s=p(e.getAttribute("data-date"));s&&this.#M(s)};#V=t=>{if(t.key==="Tab"){this.#m();return}let i=this.#n;if(!i)return;let e;switch(t.key){case"ArrowRight":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+1);break;case"ArrowLeft":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-1);break;case"ArrowDown":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+7);break;case"ArrowUp":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-7);break;case"PageDown":t.shiftKey?e=new Date(i.getFullYear()+1,i.getMonth(),i.getDate()):e=new Date(i.getFullYear(),i.getMonth()+1,i.getDate());break;case"PageUp":t.shiftKey?e=new Date(i.getFullYear()-1,i.getMonth(),i.getDate()):e=new Date(i.getFullYear(),i.getMonth()-1,i.getDate());break;case"Home":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-i.getDay()+this.#A);break;case"End":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+(6-i.getDay()+this.#A));break;case"Enter":case" ":t.preventDefault(),t.stopPropagation(),this.#M(i);return;case"Escape":t.preventDefault(),t.stopPropagation(),this.#m(),this.#t.focus();return;default:return}t.preventDefault(),t.stopPropagation(),e&&(this.#h&&e<this.#h&&(e=this.#h),this.#o&&e>this.#o&&(e=this.#o),this.#n=e,(e.getMonth()!==this.#s||e.getFullYear()!==this.#r)&&(this.#s=e.getMonth(),this.#r=e.getFullYear(),this.#d()),this.#N(e))};#E(){let t=this.#e?d(this.#e):"";this.#c.setFormValue(t||null),this.#i.value=t,this.#i.dispatchEvent(new Event("input",{bubbles:!0}))}#C(){(this.hasAttribute("required")||this.#i.hasAttribute("required"))&&!this.#e?this.#c.setValidity({valueMissing:!0},"Please select a date",this.#t||this):this.#c.setValidity({})}formResetCallback(){this.#e=p(this.#S);let t=new Date;this.#n=this.#e||t,this.#r=this.#n.getFullYear(),this.#s=this.#n.getMonth(),this.#g(),this.#E(),this.#C(),this.#l&&this.#d()}formStateRestoreCallback(t){t&&(this.#e=p(t),this.#e&&(this.#n=this.#e,this.#r=this.#e.getFullYear(),this.#s=this.#e.getMonth(),this.#g(),this.#E(),this.#C()))}get value(){return this.#e?d(this.#e):""}set value(t){let i=p(t);i&&this.#M(i,"api")}get min(){return this.#h?d(this.#h):""}set min(t){this.#h=t?p(t):null,this.#i&&this.#i.setAttribute("min",t||""),this.#d()}get max(){return this.#o?d(this.#o):""}set max(t){this.#o=t?p(t):null,this.#i&&this.#i.setAttribute("max",t||""),this.#d()}};E("date-picker",v);export{v as DatePicker};
|
|
1
|
+
var S=window.matchMedia("(prefers-reduced-motion: reduce)");var A=new Map;function E(a,t,i={}){let e=i.priority??10,s={impl:t,bundle:i.bundle,contract:i.contract,priority:e},n=A.get(a);if(customElements.get(a)){if(!n||n.priority>=e){n&&n.priority===e&&n.impl!==t&&console.warn(`[VB Bundle] Tag <${a}> already registered by "${n.bundle}" (priority ${n.priority}). Skipping "${i.bundle}".`);return}console.warn(`[VB Bundle] Tag <${a}> defined by "${n.bundle}" cannot be replaced (customElements.define is permanent). "${i.bundle}" has higher priority but arrived late.`);return}if(n&&n.priority>=e){n.priority===e&&console.warn(`[VB Bundle] Tag <${a}> already registered by "${n.bundle}". Skipping "${i.bundle}" (first wins at equal priority).`);return}A.set(a,s),customElements.define(a,t)}var m=class extends HTMLElement{#d=[];#i;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,i,e,s){t.addEventListener(i,e,s),this.#d.push(()=>t.removeEventListener(i,e,s))}_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,i){this.#i||(this.#i=this.attachInternals());let e=this.#i.states;try{i?e.add(t):e.delete(t)}catch{let s=`--${t}`;i?e.add(s):e.delete(s)}}_adoptInternals(t){this.#i||(this.#i=t)}};var C="popover"in HTMLElement.prototype;var x=["Su","Mo","Tu","We","Th","Fr","Sa"],k=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],D=["january","february","march","april","may","june","july","august","september","october","november","december"];function d(a){let t=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0"),e=String(a.getDate()).padStart(2,"0");return`${t}-${i}-${e}`}function p(a){if(!a)return null;let[t,i,e]=a.split("-").map(Number);return new Date(t,i-1,e)}function b(a,t){return new Date(a,t+1,0).getDate()}function F(){try{let a=new Intl.Locale(navigator.language);if(a.weekInfo)return a.weekInfo.firstDay%7}catch{}return 0}function N(a){try{return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"long",day:"numeric"}).format(a)}catch{return d(a)}}function g(a,t){return a&&t&&a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function T(){let a=new Map;D.forEach((t,i)=>{a.set(t,i),a.set(t.slice(0,3),i)});try{for(let t=0;t<12;t++){let i=new Intl.DateTimeFormat(void 0,{month:"long"}).format(new Date(2e3,t,1)).toLowerCase(),e=new Intl.DateTimeFormat(void 0,{month:"short"}).format(new Date(2e3,t,1)).toLowerCase().replace(".","");a.set(i,t),a.set(e,t)}}catch{}return a}var w=T();function y(a){let t=a.trim();if(!t)return{date:null,partial:null};if(/^\d{4}-\d{2}-\d{2}$/.test(t)){let r=p(t);return r&&!isNaN(r.getTime())?{date:r,partial:null}:{date:null,partial:null}}if(/^\d{4}\/\d{2}\/\d{2}$/.test(t)){let r=p(t.replace(/\//g,"-"));return r&&!isNaN(r.getTime())?{date:r,partial:null}:{date:null,partial:null}}let i=/^([a-z\u00C0-\u024F]+)\s+(\d{1,2}),?\s+(\d{4})$/i,e=t.match(i);if(e){let r=w.get(e[1].toLowerCase());if(r!==void 0){let h=new Date(Number(e[3]),r,Number(e[2]));if(!isNaN(h.getTime()))return{date:h,partial:null}}}let s=/^(\d{1,2})\s+([a-z\u00C0-\u024F]+)\s+(\d{4})$/i;if(e=t.match(s),e){let r=w.get(e[2].toLowerCase());if(r!==void 0){let h=new Date(Number(e[3]),r,Number(e[1]));if(!isNaN(h.getTime()))return{date:h,partial:null}}}let n=/^([a-z\u00C0-\u024F]+)\s+(\d{4})$/i;if(e=t.match(n),e){let r=w.get(e[1].toLowerCase());if(r!==void 0)return{date:null,partial:{year:Number(e[2]),month:r}}}return{date:null,partial:null}}var v=class extends m{static formAssociated=!0;#d;#i;#t;#p;#b;#a;#y;#f;#D;#c;#l=!1;#v=!1;#e=null;#n=null;#r=new Date().getFullYear();#s=new Date().getMonth();#h=null;#o=null;#x=new Map;#k=new Map;#S=null;#A=0;constructor(){super(),this.#d=this.attachInternals(),this._adoptInternals(this.#d)}setup(){if(this.#i=this.querySelector(':scope > input[type="date"]'),!this.#i)return!1;this.#h=p(this.#i.getAttribute("min")),this.#o=p(this.#i.getAttribute("max")),this.#A=F();let t=this.getAttribute("data-disabled-dates");t&&t.split(",").forEach(s=>{let[n,r]=s.trim().split(":");this.#x.set(n,r||"")});let i=this.getAttribute("data-highlight-dates");i&&i.split(",").forEach(s=>{let[n,r]=s.trim().split(":");this.#k.set(n,r||"")}),this.#e=p(this.#i.value),this.#S=this.#i.value;let e=new Date;return this.#o&&e>this.#o&&(e=this.#o),this.#h&&e<this.#h&&(e=this.#h),this.#r=this.#e?this.#e.getFullYear():e.getFullYear(),this.#s=this.#e?this.#e.getMonth():e.getMonth(),this.#n=this.#e||e,this.#i.setAttribute("tabindex","-1"),this.#i.setAttribute("aria-hidden","true"),this.#i.style.cssText="position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;overflow:hidden;",this.#P(),this.#B(),this.#g(),this.#E(),this.#C(),this.#v=C,this.#v&&this.#a.setAttribute("popover","manual"),this.listen(document,"click",this.#z),(this.#i.disabled||this.hasAttribute("disabled"))&&(this.setAttribute("data-disabled",""),this.#t.disabled=!0),!0}teardown(){window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w)}#P(){this.#b=document.createElement("div"),this.#b.className="date-trigger",this.#t=document.createElement("input"),this.#t.type="text",this.#t.className="date-input",this.#t.setAttribute("role","combobox"),this.#t.setAttribute("aria-haspopup","dialog"),this.#t.setAttribute("aria-expanded","false"),this.#t.setAttribute("autocomplete","off"),this.#t.setAttribute("placeholder","Type a date\u2026"),this.#b.appendChild(this.#t),this.#p=document.createElement("button"),this.#p.type="button",this.#p.className="date-trigger-icon",this.#p.setAttribute("aria-label","Toggle calendar"),this.#p.setAttribute("tabindex","-1");let t=document.createElement("icon-wc");t.setAttribute("name","calendar"),t.setAttribute("size","sm"),t.setAttribute("aria-hidden","true"),this.#p.appendChild(t),this.#b.appendChild(this.#p),this.appendChild(this.#b),this.listen(this.#p,"click",i=>{i.stopPropagation(),this.#l?this.#m():this.#T(),this.#t.focus()}),this.listen(this.#t,"focus",()=>this.#t.select()),this.listen(this.#t,"input",this.#O),this.listen(this.#t,"keydown",this.#q),this.listen(this.#t,"blur",this.#R)}#B(){this.#y=`dp-${Math.random().toString(36).slice(2,8)}`,this.#a=document.createElement("div"),this.#a.className="calendar",this.#a.id=this.#y,this.#a.setAttribute("role","dialog"),this.#a.setAttribute("aria-modal","false"),this.#a.setAttribute("aria-label","Choose date"),this.#a.hidden=!0,this.#t.setAttribute("aria-controls",this.#y);let t=document.createElement("div");t.className="calendar-header";let i=document.createElement("button");i.type="button",i.className="calendar-nav",i.setAttribute("aria-label","Previous month");let e=document.createElement("icon-wc");e.setAttribute("name","chevron-left"),e.setAttribute("size","sm"),e.setAttribute("aria-hidden","true"),i.appendChild(e);let s=document.createElement("span");s.className="calendar-title",s.id=`${this.#y}-title`,s.setAttribute("aria-live","polite"),this.#D=document.createElement("span"),this.#D.className="calendar-month",this.#c=document.createElement("select"),this.#c.className="calendar-year",this.#c.setAttribute("aria-label","Year"),this.#Y(),s.appendChild(this.#D),s.appendChild(this.#c);let n=document.createElement("button");n.type="button",n.className="calendar-nav",n.setAttribute("aria-label","Next month");let r=document.createElement("icon-wc");r.setAttribute("name","chevron-right"),r.setAttribute("size","sm"),r.setAttribute("aria-hidden","true"),n.appendChild(r),t.appendChild(i),t.appendChild(s),t.appendChild(n),this.#a.appendChild(t);let h=document.createElement("table");h.setAttribute("role","grid"),h.setAttribute("aria-labelledby",`${this.#y}-title`);let u=document.createElement("thead"),c=document.createElement("tr");for(let l=0;l<7;l++){let o=(this.#A+l)%7,f=document.createElement("th");f.setAttribute("abbr",k[o]),f.setAttribute("scope","col"),f.textContent=x[o],c.appendChild(f)}u.appendChild(c),h.appendChild(u),this.#f=document.createElement("tbody"),h.appendChild(this.#f),this.#a.appendChild(h),this.appendChild(this.#a),this.#u(),this.listen(i,"click",()=>this.#L(-1)),this.listen(n,"click",()=>this.#L(1)),this.listen(this.#c,"change",()=>{this.#r=Number(this.#c.value);let l=b(this.#r,this.#s),o=Math.min(this.#n?.getDate()??1,l);this.#n=new Date(this.#r,this.#s,o),this.#u()}),this.listen(this.#f,"click",this.#H),this.listen(this.#a,"keydown",this.#V)}#u(){try{this.#D.textContent=new Intl.DateTimeFormat(void 0,{month:"long"}).format(new Date(this.#r,this.#s,1))}catch{this.#D.textContent=D[this.#s].charAt(0).toUpperCase()+D[this.#s].slice(1)}this.#c.querySelector(`option[value="${this.#r}"]`)||this.#Y(),this.#c.value=String(this.#r),this.#f.innerHTML="";let t=b(this.#r,this.#s),e=(new Date(this.#r,this.#s,1).getDay()-this.#A+7)%7,s=new Date,n=document.createElement("tr");for(let h=0;h<e;h++)n.appendChild(document.createElement("td"));for(let h=1;h<=t;h++){let u=new Date(this.#r,this.#s,h),c=d(u),l=document.createElement("td"),o=document.createElement("button");o.type="button",o.setAttribute("data-date",c),o.textContent=String(h),g(u,s)&&o.setAttribute("aria-current","date"),g(u,this.#e)&&o.setAttribute("aria-selected","true");let f=this.#$(u,c);if(f.disabled&&(o.setAttribute("aria-disabled","true"),o.setAttribute("disabled",""),f.reason&&o.setAttribute("data-disabled-reason",f.reason)),this.#k.has(c)){let M=this.#k.get(c);o.setAttribute("data-highlight",M||"")}g(u,this.#n)?(o.setAttribute("tabindex","0"),g(u,this.#e)||o.setAttribute("data-focused","")):o.setAttribute("tabindex","-1"),l.appendChild(o),n.appendChild(l),(e+h)%7===0&&(this.#f.appendChild(n),n=document.createElement("tr"))}let r=(e+t)%7;if(r>0){for(let h=r;h<7;h++)n.appendChild(document.createElement("td"));this.#f.appendChild(n)}}#F(t,i){return this.#$(t,i).disabled}#$(t,i){return this.#x.has(i)?{disabled:!0,reason:this.#x.get(i)}:this.#h&&t<this.#h?{disabled:!0,reason:null}:this.#o&&t>this.#o?{disabled:!0,reason:null}:{disabled:!1,reason:null}}#Y(){this.#c.innerHTML="";let t=new Date().getFullYear(),i=this.#h?this.#h.getFullYear():t-100,e=this.#o?this.#o.getFullYear():t+10;for(let s=i;s<=e;s++){let n=document.createElement("option");n.value=String(s),n.textContent=String(s),this.#c.appendChild(n)}}#L(t){this.#s+=t,this.#s>11?(this.#s=0,this.#r++):this.#s<0&&(this.#s=11,this.#r--);let i=b(this.#r,this.#s),e=Math.min(this.#n?.getDate()??1,i);this.#n=new Date(this.#r,this.#s,e),this.#u(),this.#N(this.#n)}#M(t,i="internal"){let e=d(t);this.#F(t,e)||this.#e&&d(this.#e)===e||(this.#e=t,this.#n=t,this.#g(),this.#E(),this.#C(),this.#u(),this.#m(),this.#t.focus(),this.dispatchEvent(new CustomEvent("date-picker:change",{bubbles:!0,detail:{value:e,date:new Date(t),source:i}})))}#N(t){let i=d(t),e=this.#f.querySelector(`[data-date="${i}"]`);e&&(this.#f.querySelectorAll('button[tabindex="0"]').forEach(s=>{s.setAttribute("tabindex","-1")}),e.setAttribute("tabindex","0"),e.focus())}#g(){this.#e?this.#t.value=N(this.#e):this.#t.value=""}#T(){if(!this.#l){if(this.#l=!0,this.setAttribute("open",""),this.#t.setAttribute("aria-expanded","true"),this.#a.hidden=!1,this.#n&&(this.#r=this.#n.getFullYear(),this.#s=this.#n.getMonth()),this.#u(),this.#v){try{this.#a.showPopover()}catch{}this.#I(),window.addEventListener("scroll",this.#w,{capture:!0,passive:!0}),window.addEventListener("resize",this.#w,{passive:!0})}this.dispatchEvent(new CustomEvent("date-picker:open",{bubbles:!0}))}}#m(){if(this.#l){if(this.#l=!1,this.removeAttribute("open"),this.#t.setAttribute("aria-expanded","false"),this.#a.hidden=!0,this.#v){try{this.#a.hidePopover()}catch{}window.removeEventListener("scroll",this.#w,{capture:!0}),window.removeEventListener("resize",this.#w)}this.dispatchEvent(new CustomEvent("date-picker:close",{bubbles:!0}))}}#I(){if(!this.#v)return;let t=this.#b.getBoundingClientRect(),i=this.#a.getBoundingClientRect(),e=4,s=8,n=window.innerHeight,r=window.innerWidth,h=n-t.bottom-s,u=t.top-s,c;h<i.height&&u>h?(c=t.top-i.height-e,this.#a.dataset.placement="top"):(c=t.bottom+e,delete this.#a.dataset.placement);let l=t.left;l+i.width>r-s&&(l=r-i.width-s),l<s&&(l=s),this.#a.style.setProperty("--calendar-top",`${c}px`),this.#a.style.setProperty("--calendar-left",`${l}px`)}#w=()=>{this.#l&&this.#I()};#O=()=>{let t=this.#t.value,{date:i,partial:e}=y(t);if(i)this.#n=i,this.#r=i.getFullYear(),this.#s=i.getMonth(),this.#u();else if(e){this.#r=e.year,this.#s=e.month;let s=b(e.year,e.month),n=Math.min(this.#n?.getDate()??1,s);this.#n=new Date(e.year,e.month,n),this.#u()}!this.#l&&t.length>0&&this.#T()};#q=t=>{switch(t.key){case"Enter":{t.preventDefault(),t.stopPropagation();let{date:i}=y(this.#t.value);i&&!this.#F(i,d(i))&&this.#M(i);return}case"ArrowDown":t.preventDefault(),t.stopPropagation(),this.#l||this.#T(),requestAnimationFrame(()=>this.#N(this.#n));return;case"Escape":t.preventDefault(),t.stopPropagation(),this.#l&&this.#m(),this.#g();return;case"Tab":this.#l&&this.#m();return}};#R=t=>{if(t.relatedTarget&&this.contains(t.relatedTarget))return;let i=this.#t.value.trim();if(i){let{date:e}=y(i);e&&!this.#F(e,d(e))&&(this.#e=e,this.#n=e,this.#E(),this.#C(),this.dispatchEvent(new CustomEvent("date-picker:change",{bubbles:!0,detail:{value:d(e),date:new Date(e)}})))}this.#g(),this.#l&&this.#m(),this.#i.dispatchEvent(new Event("blur",{bubbles:!0}))};#z=t=>{this.#l&&!this.contains(t.target)&&this.#m()};#H=t=>{let e=t.target?.closest("button[data-date]");if(!e||e.hasAttribute("disabled"))return;let s=p(e.getAttribute("data-date"));s&&this.#M(s)};#V=t=>{if(t.key==="Tab"){this.#m();return}let i=this.#n;if(!i)return;let e;switch(t.key){case"ArrowRight":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+1);break;case"ArrowLeft":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-1);break;case"ArrowDown":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+7);break;case"ArrowUp":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-7);break;case"PageDown":t.shiftKey?e=new Date(i.getFullYear()+1,i.getMonth(),i.getDate()):e=new Date(i.getFullYear(),i.getMonth()+1,i.getDate());break;case"PageUp":t.shiftKey?e=new Date(i.getFullYear()-1,i.getMonth(),i.getDate()):e=new Date(i.getFullYear(),i.getMonth()-1,i.getDate());break;case"Home":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()-i.getDay()+this.#A);break;case"End":e=new Date(i.getFullYear(),i.getMonth(),i.getDate()+(6-i.getDay()+this.#A));break;case"Enter":case" ":t.preventDefault(),t.stopPropagation(),this.#M(i);return;case"Escape":t.preventDefault(),t.stopPropagation(),this.#m(),this.#t.focus();return;default:return}t.preventDefault(),t.stopPropagation(),e&&(this.#h&&e<this.#h&&(e=this.#h),this.#o&&e>this.#o&&(e=this.#o),this.#n=e,(e.getMonth()!==this.#s||e.getFullYear()!==this.#r)&&(this.#s=e.getMonth(),this.#r=e.getFullYear(),this.#u()),this.#N(e))};#E(){let t=this.#e?d(this.#e):"";this.#d.setFormValue(t||null),this.#i.value=t,this.#i.dispatchEvent(new Event("input",{bubbles:!0}))}#C(){(this.hasAttribute("required")||this.#i.hasAttribute("required"))&&!this.#e?this.#d.setValidity({valueMissing:!0},"Please select a date",this.#t||this):this.#d.setValidity({})}formResetCallback(){this.#e=p(this.#S);let t=new Date;this.#n=this.#e||t,this.#r=this.#n.getFullYear(),this.#s=this.#n.getMonth(),this.#g(),this.#E(),this.#C(),this.#l&&this.#u()}formStateRestoreCallback(t){t&&(this.#e=p(t),this.#e&&(this.#n=this.#e,this.#r=this.#e.getFullYear(),this.#s=this.#e.getMonth(),this.#g(),this.#E(),this.#C()))}get value(){return this.#e?d(this.#e):""}set value(t){let i=p(t);i&&this.#M(i,"api")}get min(){return this.#h?d(this.#h):""}set min(t){this.#h=t?p(t):null,this.#i&&this.#i.setAttribute("min",t||""),this.#u()}get max(){return this.#o?d(this.#o):""}set max(t){this.#o=t?p(t):null,this.#i&&this.#i.setAttribute("max",t||""),this.#u()}};E("date-picker",v);export{v as DatePicker};
|
|
2
2
|
//# sourceMappingURL=date-picker.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var b=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
|
|
1
|
+
var b=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,n,e,s){t.addEventListener(n,e,s),this.#t.push(()=>t.removeEventListener(n,e,s))}_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,n){this.#e||(this.#e=this.attachInternals());let e=this.#e.states;try{n?e.add(t):e.delete(t)}catch{let s=`--${t}`;n?e.add(s):e.delete(s)}}_adoptInternals(t){this.#e||(this.#e=t)}};var q=window.matchMedia("(prefers-reduced-motion: reduce)");var w=new Map;function x(h,t,n={}){let e=n.priority??10,s={impl:t,bundle:n.bundle,contract:n.contract,priority:e},r=w.get(h);if(customElements.get(h)){if(!r||r.priority>=e){r&&r.priority===e&&r.impl!==t&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${r.bundle}" (priority ${r.priority}). Skipping "${n.bundle}".`);return}console.warn(`[VB Bundle] Tag <${h}> defined by "${r.bundle}" cannot be replaced (customElements.define is permanent). "${n.bundle}" has higher priority but arrived late.`);return}if(r&&r.priority>=e){r.priority===e&&console.warn(`[VB Bundle] Tag <${h}> already registered by "${r.bundle}". Skipping "${n.bundle}" (first wins at equal priority).`);return}w.set(h,s),customElements.define(h,t)}var v=class extends b{#t=null;setup(){if(this.#t=this.querySelector("ol"),!this.#t&&this.dataset.startHour==="auto"&&this.#e(),!this.#t)return!1;let t=this.#t;this.#n(),this.listen(t,"click",e=>{let r=e.target?.closest("calendar-event");r&&this.dispatchEvent(new CustomEvent("day-view:event-click",{bubbles:!0,detail:{time:r.querySelector("time[datetime]")?.getAttribute("datetime"),text:r.textContent?.trim()??"",element:r,category:r.dataset.category,duration:r.dataset.duration}}))}),this.listen(t,"keydown",e=>{let s=e,p=s.target?.closest("calendar-event");if(!p)return;let o=[...t.querySelectorAll("calendar-event")],a=o.indexOf(p);if(a===-1)return;let c;s.key==="ArrowDown"&&a<o.length-1&&(c=o[a+1]),s.key==="ArrowUp"&&a>0&&(c=o[a-1]),c&&(s.preventDefault(),c.setAttribute("tabindex","0"),p.setAttribute("tabindex","-1"),c.focus())});let n=t.querySelector("calendar-event");return n&&n.setAttribute("tabindex","0"),!0}#e(){let t=[...this.querySelectorAll(":scope > calendar-event")];if(t.length===0)return;let n=new Map,e=[];if(t.forEach(d=>{let i=d,l=i.querySelector("time[datetime]");if(!l){e.push(i);return}let g=l.getAttribute("datetime");if(!g){e.push(i);return}let f=g.split(":"),u=parseInt(f[0],10),m=parseInt(f[1]||"0",10);if(isNaN(u)){e.push(i);return}m>=30&&!i.dataset.start&&(i.dataset.start="30"),n.has(u)||n.set(u,[]),n.get(u).push(i)}),e.length>0){let d=document.createElement("ul");d.className="all-day-events",e.forEach(i=>{let l=document.createElement("li");l.appendChild(i),d.appendChild(l)}),this.prepend(d)}let s=[...n.keys()].sort((d,i)=>d-i);if(s.length===0)return;let r=Math.max(0,s[0]-1),p=Math.min(23,s[s.length-1]+1),o=this.closest("[lang]")?.lang||navigator.language,a=new Intl.DateTimeFormat(o,{hour:"numeric"}),c=document.createElement("ol");for(let d=r;d<=p;d++){let i=document.createElement("li"),l=document.createElement("time"),g=String(d).padStart(2,"0");l.setAttribute("datetime",`${g}:00`),l.textContent=a.format(new Date(2026,0,1,d));let f=document.createElement("hour-view"),u=n.get(d)||[];u.length>1&&(f.dataset.overlap=""),u.forEach(m=>f.appendChild(m)),i.append(l,f),c.appendChild(i)}this.appendChild(c),this.#t=c}teardown(){this.querySelectorAll("calendar-event.dv-spanning").forEach(t=>{t.style.cssText="",t.classList.remove("dv-spanning")})}refresh(){this.teardown(),this.#n()}get events(){return[...this.querySelectorAll("calendar-event")].map(t=>{let n=t;return{time:n.querySelector("time[datetime]")?.getAttribute("datetime")||void 0,text:n.textContent?.trim()??"",category:n.dataset.category||void 0,duration:n.dataset.duration||void 0,href:n.querySelector("a[href]")?.getAttribute("href")||void 0}})}set events(t){let n=Array.isArray(t)?t:[];for(;this.firstChild;)this.firstChild.remove();this.dataset.startHour="auto";for(let e of n){let s=document.createElement("calendar-event");if(e.category&&(s.dataset.category=e.category),e.duration&&(s.dataset.duration=String(e.duration)),e.time){let r=document.createElement("time");r.setAttribute("datetime",e.time),r.textContent=e.time,s.appendChild(r),s.appendChild(document.createTextNode(" "))}if(e.href){let r=document.createElement("a");r.href=e.href,r.textContent=e.text||"",s.appendChild(r)}else s.appendChild(document.createTextNode(e.text||""));this.appendChild(s)}this.teardown(),this.removeAttribute("data-upgraded"),this.setup(),this.dispatchEvent(new CustomEvent("day-view:events-changed",{detail:{events:n,source:"property"},bubbles:!0}))}#n(){let t=this.#t;if(!t)return;let n=t.querySelectorAll("calendar-event[data-duration]");n.length!==0&&requestAnimationFrame(()=>{let e=t.getBoundingClientRect(),s=new Map,r=64;t.querySelectorAll(":scope > li").forEach(o=>{let a=o.querySelector(":scope > time");if(!a)return;let c=a.getAttribute("datetime");if(!c)return;let d=parseInt(c.split(":")[0],10),i=o.getBoundingClientRect();s.set(d,{top:i.top-e.top,height:i.height}),r=a.getBoundingClientRect().width});let p=[];n.forEach(o=>{let a=o,c=a.closest("ol > li");if(!c)return;let i=c.querySelector(":scope > time")?.getAttribute("datetime");if(!i)return;let l=parseInt(i.split(":")[0],10),g=parseInt(a.dataset.start||"0",10),f=a.dataset.duration??"",u=60,m=f.match(/(\d+)h/),E=f.match(/(\d+)m/);(m||E)&&(u=(m?parseInt(m[1],10)*60:0)+(E?parseInt(E[1],10):0));let y=s.get(l);if(!y)return;let A=g/60,C=y.top+y.height*A,S=y.height*(u/60);p.push({event:a,top:C,height:S})}),p.forEach(({event:o,top:a,height:c})=>{o.style.position="absolute",o.style.top=a+"px",o.style.height=c+"px",o.style.insetInlineStart=r+4+"px",o.style.insetInlineEnd="4px",o.classList.add("dv-spanning")})})}};x("day-view",v);export{v as DayView};
|
|
2
2
|
//# sourceMappingURL=day-view.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)[0].slice(0,240);e.textContent=`Diagram syntax error: ${
|
|
1
|
+
var k=window.matchMedia("(prefers-reduced-motion: reduce)");var w=new Map;function v(o,t,e={}){let r=e.priority??10,s={impl:t,bundle:e.bundle,contract:e.contract,priority:r},i=w.get(o);if(customElements.get(o)){if(!i||i.priority>=r){i&&i.priority===r&&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>=r){i.priority===r&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${i.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}w.set(o,s),customElements.define(o,t)}var g=class extends HTMLElement{#r=[];#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.#r)t();this.#r=[],this.removeAttribute("data-upgraded"),this.teardown()}listen(t,e,r,s){t.addEventListener(e,r,s),this.#r.push(()=>t.removeEventListener(e,r,s))}_reinit(){for(let t of this.#r)t();this.#r=[],this.teardown(),this.removeAttribute("data-upgraded"),this.isConnected&&this.setup()!==!1&&this.setAttribute("data-upgraded","")}setup(){}teardown(){}setState(t,e){this.#e||(this.#e=this.attachInternals());let r=this.#e.states;try{e?r.add(t):r.delete(t)}catch{let s=`--${t}`;e?r.add(s):r.delete(s)}}_adoptInternals(t){this.#e||(this.#e=t)}};var $=0;function C(o,t,e="vb-vt"){if(!o?.isConnected||typeof document>"u"||!("startViewTransition"in document)||matchMedia("(prefers-reduced-motion: reduce)").matches)return t(),null;let r=`${e}-${++$}`;o.style.viewTransitionName=r;let s=document.startViewTransition(t);return s.finished.finally(()=>{o.style.viewTransitionName===r&&(o.style.viewTransitionName="")}),s}function n(o,t,e){return o.getPropertyValue(t).trim()||e}function l(o,t){if(!t)return t;let e=document.createElement("span");e.style.color=t,e.style.position="absolute",e.style.visibility="hidden",e.style.pointerEvents="none",(o.parentElement||document.body).appendChild(e);let r=getComputedStyle(e).color;if(e.remove(),!r)return t;let s=l,i=s._canvas||(s._canvas=document.createElement("canvas"));i.width=i.height=1;let a=s._ctx||(s._ctx=i.getContext("2d",{willReadFrequently:!0}));a.clearRect(0,0,1,1),a.fillStyle=r,a.fillRect(0,0,1,1);let[d,u,f,m]=a.getImageData(0,0,1,1).data;return m===255?`rgb(${d},${u},${f})`:`rgba(${d},${u},${f},${(m/255).toFixed(3)})`}function T(o){let t=getComputedStyle(o),e=l(o,n(t,"--color-text","#1a1a1a")),r=l(o,n(t,"--color-surface","#ffffff")),s=l(o,n(t,"--color-surface-raised",n(t,"--color-surface","#ffffff"))),i=l(o,n(t,"--color-border","#e0e0e0")),a=l(o,n(t,"--color-primary",n(t,"--color-interactive","#3b82f6"))),d=l(o,n(t,"--color-secondary",n(t,"--color-surface-raised","#f8f9fa"))),u=l(o,n(t,"--color-accent",n(t,"--color-primary","#3b82f6"))),f=l(o,n(t,"--color-text-muted",n(t,"--color-text","#1a1a1a"))),m=n(t,"--font-sans",'system-ui, -apple-system, "Segoe UI", sans-serif'),S=n(t,"--font-size-m","14px"),p=[a,u,d],h={};for(let c=0;c<12;c++)h[`cScale${c}`]=p[c%p.length],h[`cScaleLabel${c}`]=e,h[`cScalePeer${c}`]=i,h[`cScaleInv${c}`]=r;let b={};for(let c=0;c<8;c++)b[`git${c}`]=p[c%p.length],b[`gitInv${c}`]=r,b[`gitBranchLabel${c}`]=e;return{primaryColor:a,primaryBorderColor:i,primaryTextColor:e,nodeTextColor:e,secondaryColor:d,secondaryBorderColor:i,secondaryTextColor:e,tertiaryColor:u,tertiaryBorderColor:i,tertiaryTextColor:e,background:r,mainBkg:r,secondBkg:s,tertiaryBkg:s,lineColor:i,nodeBorder:i,gridColor:i,defaultLinkColor:f,clusterBkg:s,clusterBorder:i,actorBkg:r,actorBorder:i,actorTextColor:e,actorLineColor:i,signalColor:e,signalTextColor:e,labelBoxBkgColor:s,labelBoxBorderColor:i,labelTextColor:e,loopTextColor:e,noteBkgColor:s,noteBorderColor:i,noteTextColor:e,edgeLabelBackground:r,titleColor:e,fontFamily:m,fontSize:S,...h,...b}}function E(o,t={}){return{startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:t.themeBase||"base",themeVariables:T(o)}}var B="https://cdn.jsdelivr.net/npm/mermaid@11.14.0/dist/mermaid.esm.min.mjs",x=new Map;function A(o){let t=o||typeof window<"u"&&window.VB_MERMAID_URL||B,e=x.get(t);return e||(e=import(t).then(r=>r.default||r),x.set(t,e)),e}var y=class o extends g{static#r=0;#e=null;#o=null;#t=null;#i=null;#s=null;#n=!1;setup(){this.hasAttribute("type")||this.setAttribute("type","mermaid");let t=this.getAttribute("min-height");t&&(this.style.minBlockSize=t);let e=this.querySelector(":scope > pre");e&&(this.#o=document.createElement("template"),this.#o.appendChild(e.cloneNode(!0)),this.#e=this.#u(e),this.setAttribute("data-rendering",""));let r=this.querySelector(":scope > .dwc-figure");r&&(this.#t=r,this.#n=!0,this.removeAttribute("data-rendering")),this.listen(window,"vb:theme-change",()=>{this.#s&&clearTimeout(this.#s),this.#s=setTimeout(()=>{this.#n&&this.#c()},50)});let s=this.getAttribute("src");s?this.#h(s).then(()=>this.#d()):this.#e&&this.#d()}teardown(){if(this.#i&&(this.#i.disconnect(),this.#i=null),this.#s&&(clearTimeout(this.#s),this.#s=null),this.#t&&(this.#t.remove(),this.#t=null),this.#o){let t=this.#o.content.firstElementChild;t&&!this.querySelector(":scope > pre")&&this.appendChild(t.cloneNode(!0))}this.#n=!1}#d(){if(this.getAttribute("loading")!=="lazy"){this.#c();return}if(!("IntersectionObserver"in window)){this.#c();return}this.#i=new IntersectionObserver(t=>{for(let e of t)if(e.isIntersecting){this.#i?.disconnect(),this.#i=null,this.#c();break}},{rootMargin:"200px"}),this.#i.observe(this)}async#c(){if(!this.#e)return;let t=this.getAttribute("type")||"mermaid";if(t!=="mermaid"){this.#a(new Error(`Unsupported diagram type "${t}". v1 supports "mermaid" only.`));return}try{let e=await A(this.dataset.mermaidSrc),r=E(this,{themeBase:this.dataset.themeBase||"base"});e.initialize(r);let s=`diagram-wc-${++o.#r}`,{svg:i}=await e.render(s,this.#e);this.#l(i),this.#n=!0,this.removeAttribute("data-rendering"),this.removeAttribute("data-error"),this.querySelector(":scope > .dwc-error")?.remove(),this.dispatchEvent(new CustomEvent("diagram-wc:ready",{bubbles:!0,detail:{svg:i,type:t,source:this.#e}}))}catch(e){this.removeAttribute("data-rendering"),this.#n||this.setAttribute("data-error",""),this.#a(e)}}#l(t){let e=document.createElement("figure");e.className="dwc-figure",e.setAttribute("role","img");let r=this.getAttribute("caption")||`${this.getAttribute("type")||"diagram"} diagram`;e.setAttribute("aria-label",r),e.innerHTML=t;let s=this.getAttribute("caption");if(s){let d=document.createElement("figcaption");d.className="dwc-caption",d.textContent=s,e.appendChild(d)}let i=this.#t,a=()=>{i&&i.isConnected?i.replaceWith(e):this.appendChild(e),this.querySelector(":scope > pre")?.remove(),this.#t=e};i?.isConnected?C(this,a,"dwc-vt"):a()}#a(t){if(!this.#n){if(!this.querySelector(":scope > pre")&&this.#o){let s=this.#o.content.firstElementChild;s&&this.appendChild(s.cloneNode(!0))}this.#t&&(this.#t.remove(),this.#t=null)}this.querySelector(":scope > .dwc-error")?.remove();let e=document.createElement("p");e.className="dwc-error",e.setAttribute("role","status");let r=(t.message||String(t)).split(`
|
|
2
|
+
`)[0].slice(0,240);e.textContent=`Diagram syntax error: ${r}`,this.appendChild(e),this.dispatchEvent(new CustomEvent("diagram-wc:error",{bubbles:!0,detail:{error:t,source:this.#e,type:this.getAttribute("type")}}))}#u(t){let e=t.querySelector("code");return(e?e.textContent:t.textContent)||""}async#h(t){try{let e=await fetch(t);if(!e.ok)throw new Error(`HTTP ${e.status}`);this.#e=await e.text()}catch(e){this.#a(e)}}get source(){return this.#e||""}set source(t){let e=String(t||"");e!==this.#e&&(this.#e=e,this.#t&&(this.#t.remove(),this.#t=null),this.querySelector(":scope > .dwc-error")?.remove(),this.dispatchEvent(new CustomEvent("diagram-wc:source-changed",{bubbles:!0,detail:{source:e}})),this.#c())}get svg(){return this.#t?.querySelector("svg")?.outerHTML||""}};v("diagram-wc",y);export{y as DiagramWc};
|
|
3
3
|
//# sourceMappingURL=diagram-wc.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var p=window.matchMedia("(prefers-reduced-motion: reduce)");var g=new Map;function b(o,t,e={}){let r=e.priority??10,i={impl:t,bundle:e.bundle,contract:e.contract,priority:r},
|
|
1
|
+
var p=window.matchMedia("(prefers-reduced-motion: reduce)");var g=new Map;function b(o,t,e={}){let r=e.priority??10,i={impl:t,bundle:e.bundle,contract:e.contract,priority:r},s=g.get(o);if(customElements.get(o)){if(!s||s.priority>=r){s&&s.priority===r&&s.impl!==t&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${s.bundle}" (priority ${s.priority}). Skipping "${e.bundle}".`);return}console.warn(`[VB Bundle] Tag <${o}> defined by "${s.bundle}" cannot be replaced (customElements.define is permanent). "${e.bundle}" has higher priority but arrived late.`);return}if(s&&s.priority>=r){s.priority===r&&console.warn(`[VB Bundle] Tag <${o}> already registered by "${s.bundle}". Skipping "${e.bundle}" (first wins at equal priority).`);return}g.set(o,i),customElements.define(o,t)}var c=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,r,i){t.addEventListener(e,r,i),this.#t.push(()=>t.removeEventListener(e,r,i))}_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.#e||(this.#e=this.attachInternals());let r=this.#e.states;try{e?r.add(t):r.delete(t)}catch{let i=`--${t}`;e?r.add(i):r.delete(i)}}_adoptInternals(t){this.#e||(this.#e=t)}};var f=class o extends c{#t=null;#e=null;#h=!1;#l=null;setup(){this.setAttribute("role","list"),this.#h=window.matchMedia("(prefers-reduced-motion: reduce)").matches,this.#f(),this.#g(),this.#E(),this.#c()}teardown(){this.#t&&(this.#t.remove(),this.#t=null),o.#r?.source===this&&(o.#r=null)}get draggableChildren(){return[...this.querySelectorAll(':scope > [draggable="true"]')]}get group(){return this.getAttribute("group")||null}get orientation(){return this.getAttribute("orientation")||"vertical"}get sortedOrder(){return this.draggableChildren.map(t=>t.dataset.id)}#c(){for(let t of this.draggableChildren)t.getAttribute("role")||t.setAttribute("role","listitem"),t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.hasAttribute("aria-grabbed")||t.setAttribute("aria-grabbed","false")}#f(){this.#t=document.createElement("div"),this.#t.setAttribute("role","status"),this.#t.setAttribute("aria-live","polite"),this.#t.setAttribute("aria-atomic","true"),this.#t.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);",this.prepend(this.#t)}#s(t){let e=this.#t;e&&(e.textContent="",requestAnimationFrame(()=>{e.textContent=t}))}#g(){this.listen(this,"pointerdown",t=>{this.#l=t.target}),this.listen(this,"dragstart",this.#b.bind(this)),this.listen(this,"dragover",this.#p.bind(this)),this.listen(this,"dragleave",this.#m.bind(this)),this.listen(this,"drop",this.#v.bind(this)),this.listen(this,"dragend",this.#A.bind(this))}#b(t){let e=t.target.closest('[draggable="true"]');if(!e||e.parentElement!==this||this.hasAttribute("disabled"))return;let r=e.querySelector("[data-drag-handle]");if(r&&!r.contains(this.#l)){t.preventDefault();return}e.setAttribute("data-dragging",""),t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.dataset.id||""),t.dataTransfer.setData("application/x-drag-surface-group",this.group||"");let i=this.#n(e);o.#r={item:e,source:this,originalIndex:i},this.dispatchEvent(new CustomEvent("drag-surface:reorder-start",{bubbles:!0}))}#p(t){let e=o.#r;if(!e||(this.group||e.source.group)&&this.group!==e.source.group)return;t.preventDefault(),t.dataTransfer.dropEffect="move",this.setAttribute("data-drag-over","");let r=this.orientation==="horizontal"?t.clientX:t.clientY;this.#C(r)}#m(t){t.relatedTarget&&!this.contains(t.relatedTarget)&&(this.removeAttribute("data-drag-over"),this.#d())}#v(t){t.preventDefault(),this.removeAttribute("data-drag-over"),this.#d();let e=o.#r;if(!e)return;let{item:r,source:i,originalIndex:s}=e,d=this.orientation==="horizontal"?t.clientX:t.clientY,u=this.#x(d);if(i===this){this.#a(r,u),this.#i();let h=this.#n(r);this.#o(r),this.dispatchEvent(new CustomEvent("drag-surface:reorder",{bubbles:!0,detail:{item:r,itemId:r.dataset.id,oldIndex:s,newIndex:h,order:this.sortedOrder}}))}else this.#a(r,u),this.#i(),i.#i(),this.#o(r),this.dispatchEvent(new CustomEvent("drag-surface:transfer",{bubbles:!0,detail:{item:r,itemId:r.dataset.id,fromSurface:i,toSurface:this,newIndex:this.#n(r),fromOrder:i.sortedOrder,toOrder:this.sortedOrder}}))}#A(){let t=o.#r;t?.item&&t.item.removeAttribute("data-dragging"),this.removeAttribute("data-drag-over"),this.#d(),o.#r=null,this.dispatchEvent(new CustomEvent("drag-surface:reorder-end",{bubbles:!0}))}#E(){this.listen(this,"keydown",this.#w.bind(this))}#w(t){let e=t.target.closest('[draggable="true"]');if(!e||e.parentElement!==this||this.hasAttribute("disabled"))return;let r=e.getAttribute("aria-grabbed")==="true",i=this.orientation==="horizontal",s=i?"ArrowLeft":"ArrowUp",d=i?"ArrowRight":"ArrowDown";if(t.key===" "||t.key==="Enter"){if(t.preventDefault(),r){e.setAttribute("aria-grabbed","false"),this.removeAttribute("data-reorder-mode"),this.#i(),this.#o(e);let a=this.#n(e),n=this.draggableChildren;this.#s(`${this.#u(e)}, dropped at position ${a+1} of ${n.length}`),this.dispatchEvent(new CustomEvent("drag-surface:reorder",{bubbles:!0,detail:{item:e,itemId:e.dataset.id,oldIndex:this.#e,newIndex:a,order:this.sortedOrder}})),this.dispatchEvent(new CustomEvent("drag-surface:reorder-end",{bubbles:!0})),this.#e=null}else{this.#e=this.#n(e),e.setAttribute("aria-grabbed","true"),this.setAttribute("data-reorder-mode","");let a=this.draggableChildren;this.#s(`${this.#u(e)}, grabbed. Position ${this.#e+1} of ${a.length}. Use arrow keys to move, Enter to drop, Escape to cancel.`),this.dispatchEvent(new CustomEvent("drag-surface:reorder-start",{bubbles:!0}))}return}if(!r&&(t.key===s||t.key===d)){t.preventDefault();let a=this.draggableChildren,n=a.indexOf(e),l=t.key===s?Math.max(0,n-1):Math.min(a.length-1,n+1);l!==n&&a[l].focus();return}if(r&&(t.key===s||t.key===d)){t.preventDefault();let a=this.draggableChildren,n=a.indexOf(e),l=t.key===s?Math.max(0,n-1):Math.min(a.length-1,n+1);l!==n&&(this.#a(e,l),e.focus(),this.#s(`Position ${l+1} of ${a.length}`));return}let u=i?"ArrowUp":"ArrowLeft",h=i?"ArrowDown":"ArrowRight";if(r&&(t.key===u||t.key===h)){if(t.preventDefault(),!this.group)return;let a=t.key===h?1:-1,n=this.#y(a);if(!n)return;n.appendChild(e),n.#i(),this.#i(),n.#o(e),e.focus();let l=n.getAttribute("aria-label")||"next surface";n.#s(`Moved to ${l}`),n.dispatchEvent(new CustomEvent("drag-surface:transfer",{bubbles:!0,detail:{item:e,itemId:e.dataset.id,fromSurface:this,toSurface:n,newIndex:n.draggableChildren.indexOf(e),fromOrder:this.sortedOrder,toOrder:n.sortedOrder}})),this.removeAttribute("data-reorder-mode"),n.setAttribute("data-reorder-mode",""),this.#e=null;return}if(r&&t.key==="Escape"){t.preventDefault(),e.setAttribute("aria-grabbed","false"),this.removeAttribute("data-reorder-mode"),this.#e!=null&&(this.#a(e,this.#e),e.focus()),this.#s("Reorder cancelled"),this.dispatchEvent(new CustomEvent("drag-surface:reorder-end",{bubbles:!0})),this.#e=null;return}!r&&t.key==="Escape"&&(t.preventDefault(),e.blur())}#o(t){t.setAttribute("data-just-dropped",""),t.addEventListener("animationend",()=>{t.removeAttribute("data-just-dropped")},{once:!0}),setTimeout(()=>t.removeAttribute("data-just-dropped"),500)}#y(t){if(!this.group)return null;let e=[...document.querySelectorAll(`drag-surface[group="${this.group}"]`)];if(e.length<2)return null;e.sort((s,d)=>{let u=s.getBoundingClientRect(),h=d.getBoundingClientRect();return u.left-h.left||u.top-h.top});let r=e.indexOf(this);return e[r+t]||null}#u(t){return t.dataset.id||t.textContent.trim().slice(0,40)}#n(t){return this.draggableChildren.indexOf(t)}#a(t,e){let i=this.draggableChildren.filter(s=>s!==t)[e]||null;i?this.insertBefore(t,i):this.appendChild(t)}#i(){this.draggableChildren.forEach((t,e)=>{t.dataset.sortOrder=String(e+1)})}#x(t){let e=this.orientation==="horizontal",r=this.draggableChildren.filter(i=>!i.hasAttribute("data-dragging"));for(let i=0;i<r.length;i++){let s=r[i].getBoundingClientRect(),d=e?s.left+s.width/2:s.top+s.height/2;if(t<d)return i}return r.length}#C(t){this.#d();let e=this.orientation==="horizontal",r=this.draggableChildren.filter(i=>!i.hasAttribute("data-dragging"));for(let i=0;i<r.length;i++){let s=r[i].getBoundingClientRect(),d=e?s.left+s.width/2:s.top+s.height/2;if(t<d){r[i].setAttribute("data-drop-target","before");return}}r.length>0&&r[r.length-1].setAttribute("data-drop-target","after")}#d(){for(let t of this.querySelectorAll("[data-drop-target]"))t.removeAttribute("data-drop-target")}static#r=null};b("drag-surface",f);export{f as DragSurface};
|
|
2
2
|
//# sourceMappingURL=drag-surface.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=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,s,e,i){t.addEventListener(s,e,i),this.#t.push(()=>t.removeEventListener(s,e,i))}setup(){}teardown(){}setState(t,s){this.#e||(this.#e=this.attachInternals());let e=this.#e.states;try{s?e.add(t):e.delete(t)}catch{let i=`--${t}`;s?e.add(i):e.delete(i)}}_adoptInternals(t){this.#e||(this.#e=t)}};var v=window.matchMedia("(prefers-reduced-motion: reduce)");var p=new Map;function h(r,t,s={}){let e=s.priority??10,i={impl:t,bundle:s.bundle,contract:s.contract,priority:e},o=p.get(r);if(customElements.get(r)){if(!o||o.priority>=e){o&&o.priority===e&&o.impl!==t&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${o.bundle}" (priority ${o.priority}). Skipping "${s.bundle}".`);return}console.warn(`[VB Bundle] Tag <${r}> defined by "${o.bundle}" cannot be replaced (customElements.define is permanent). "${s.bundle}" has higher priority but arrived late.`);return}if(o&&o.priority>=e){o.priority===e&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${o.bundle}". Skipping "${s.bundle}" (first wins at equal priority).`);return}p.set(r,i),customElements.define(r,t)}var l=CSS.supports("anchor-name","--x"),m=CSS.supports("position-area","bottom"),b=0,c=class extends a{#t=null;#e=null;#s=null;#i=null;setup(){this.id||(this.id=`pop-over-${++b}`);let t=this.dataset.mode||"auto";this.hasAttribute("popover")||this.setAttribute("popover",t),this.#n(),this.#r(),this.#s=s=>{let e=s.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${e}`,{detail:{state:s.newState},bubbles:!0,composed:!0})),!l&&s.newState==="open"&&this.#t&&this.#o()},this.listen(this,"beforetoggle",this.#s),l||(this.#i=()=>{this.matches(":popover-open")&&this.#t&&this.#o()},this.listen(window,"resize",this.#i),this.listen(window,"scroll",this.#i,{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")}#n(){let t=this.dataset.anchor;t?this.#t=document.getElementById(t)||document.querySelector(t):this.#t=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#r(){if(!(!this.#t||!l)&&(this.#e=`--pop-over-anchor-${this.id}`,this.#t.style.setProperty("anchor-name",this.#e),this.style.setProperty("position-anchor",this.#e),this.setAttribute("data-anchor-name",this.#e||""),!m)){let t=this.dataset.position||"bottom";this.#a(t)}}#a(t){let s="var(--_pop-over-offset, var(--size-xs))",e={top:{bottom:`calc(anchor(top) + ${s})`,left:"anchor(left)"},bottom:{top:`calc(anchor(bottom) + ${s})`,left:"anchor(left)"},left:{right:`calc(anchor(left) + ${s})`,top:"anchor(top)"},right:{left:`calc(anchor(right) + ${s})`,top:"anchor(top)"}},i=t.split("-")[0],o=e[i]||e.bottom;Object.entries(o).forEach(([n,f])=>this.style.setProperty(n,f))}#o(){if(!this.#t)return;let t=this.#t.getBoundingClientRect(),s=this.dataset.position||"bottom",e=this.#l(),i,o;switch(s.split("-")[0]){case"top":i=t.top-this.offsetHeight-e,o=t.left;break;case"left":i=t.top,o=t.left-this.offsetWidth-e;break;case"right":i=t.top,o=t.right+e;break;default:i=t.bottom+e,o=t.left;break}s.endsWith("-end")&&(s.startsWith("top")||s.startsWith("bottom")?o=t.right-this.offsetWidth:i=t.bottom-this.offsetHeight),this.style.position="fixed",this.style.top=`${Math.round(i)}px`,this.style.left=`${Math.round(o)}px`,this.style.margin="0"}#l(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset]??t.xs}};h("pop-over",c);var d=0,u=class extends a{#t;#e;#s;#i=[];#n=-1;#r=!1;#a=!1;#o=null;setup(){let t=this.querySelector(":scope > [data-trigger]")||this.querySelector(":scope > button");if(!t)return!1;this.#t=t;let s=this.querySelector('menu, ul[role="menu"]');if(!s)return!1;this.#e=s,this.#a=this.hasAttribute("hover"),this.#t.id||(this.#t.id=`dropdown-trigger-${++d}`);let e=this.querySelector(":scope > pop-over[data-dropdown-host]");return e?this.#s=e:(this.#s=document.createElement("pop-over"),this.#s.setAttribute("data-dropdown-host",""),this.#s.id=`dropdown-${++d}`,this.#s.dataset.mode=this.#a?"manual":"auto",this.#s.dataset.position=this.getAttribute("position")||"bottom-start",this.#s.dataset.anchor=this.#t.id,this.#s.appendChild(this.#e),this.appendChild(this.#s)),this.#s.dataset.mode=this.#a?"manual":"auto",this.#s.dataset.position=this.getAttribute("position")||"bottom-start",this.#s.dataset.anchor=this.#t.id,this.#e.parentElement!==this.#s&&this.#s.appendChild(this.#e),this.#t.setAttribute("aria-haspopup","menu"),this.#t.setAttribute("aria-expanded","false"),this.#e.id||(this.#e.id=`dropdown-menu-${++d}`),this.#t.setAttribute("aria-controls",this.#e.id),this.#e.setAttribute("role","menu"),this.#l(),this.#a?(this.listen(this,"mouseenter",this.#d),this.listen(this,"mouseleave",this.#u),this.listen(this.#t,"focus",this.#p),this.listen(this.#t,"blur",this.#f)):this.listen(this.#t,"click",this.#c),this.listen(this.#t,"keydown",this.#m),this.listen(this.#e,"keydown",this.#b),this.listen(this.#s,"pop-over:hide",this.#w),this.listen(this.#s,"pop-over:show",this.#y),this.#a&&this.listen(document,"keydown",this.#g),!0}teardown(){this.#o&&clearTimeout(this.#o)}get items(){if(!this.#e)return[];let t=[];for(let s of this.#e.querySelectorAll(":scope > li")){if(s.matches('[role="separator"]')||s.querySelector("hr")){t.push({separator:!0});continue}let e=s.querySelector('button, a, [role="menuitem"]');e&&t.push({label:e.textContent.trim().replace(/\s+/g," "),value:e.getAttribute("data-value")||void 0,href:e.tagName==="A"?e.getAttribute("href"):void 0,disabled:e.disabled||e.hasAttribute("data-disabled")||void 0})}return t}set items(t){let s=Array.isArray(t)?t:[],e=this.querySelector('menu, ul[role="menu"]');for(e||(e=document.createElement("menu"),this.appendChild(e));e.firstChild;)e.firstChild.remove();for(let i of s){let o=document.createElement("li");if(i.separator)o.setAttribute("role","separator");else{let n=i.href?document.createElement("a"):document.createElement("button");i.href&&n.setAttribute("href",i.href),i.value&&n.setAttribute("data-value",i.value),i.disabled&&(n.tagName==="BUTTON"?n.disabled=!0:n.setAttribute("data-disabled","")),n.textContent=i.label||"",o.appendChild(n)}e.appendChild(o)}this.teardown(),this.removeAttribute("data-upgraded"),this.setup(),this.dispatchEvent(new CustomEvent("drop-down:items-changed",{detail:{items:s,source:"property"},bubbles:!0}))}#l(){this.#i=Array.from(this.#e.querySelectorAll('button, a, [role="menuitem"]')).filter(t=>!t.disabled&&!t.closest('[role="separator"]')),this.#i.forEach(t=>{t.setAttribute("role","menuitem"),t.setAttribute("tabindex","-1"),t.addEventListener("click",this.#v)}),this.#e.querySelectorAll('li:empty, [role="separator"], hr').forEach(t=>{t.setAttribute("role","separator")})}#c=t=>{t.stopPropagation(),this.toggle()};#d=()=>{this.#o&&(clearTimeout(this.#o),this.#o=null,this.setState("hover-grace-pending",!1)),this.open()};#u=()=>{this.setState("hover-grace-pending",!0),this.#o=setTimeout(()=>{this.setState("hover-grace-pending",!1),this.close()},100)};#p=()=>{this.#o&&(clearTimeout(this.#o),this.#o=null,this.setState("hover-grace-pending",!1)),this.open()};#f=t=>{this.#e?.contains(t.relatedTarget)||(this.setState("hover-grace-pending",!0),this.#o=setTimeout(()=>{this.setState("hover-grace-pending",!1),this.contains(document.activeElement)||this.close()},100))};#m=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.open(),this.#h(0);break;case"ArrowUp":case"Up":t.preventDefault(),this.open(),this.#h(this.#i.length-1);break}};#b=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.#h(this.#n+1);break;case"ArrowUp":case"Up":t.preventDefault(),this.#h(this.#n-1);break;case"Home":t.preventDefault(),this.#h(0);break;case"End":t.preventDefault(),this.#h(this.#i.length-1);break;case"Tab":this.close();break;case"Enter":case" ":t.preventDefault(),this.#n>=0&&this.#i[this.#n].click();break}};#g=t=>{t.key==="Escape"&&this.#r&&(t.preventDefault(),this.close(),this.#t?.focus())};#v=t=>{t.defaultPrevented||(this.close(),this.#t?.focus())};#y=()=>{this.#r||(this.#r=!0,this.setAttribute("open",""),this.#t?.setAttribute("aria-expanded","true"),this.#n=-1,this.dispatchEvent(new CustomEvent("drop-down:open",{bubbles:!0})))};#w=()=>{this.#r&&(this.#r=!1,this.removeAttribute("open"),this.#t?.setAttribute("aria-expanded","false"),this.#n=-1,this.dispatchEvent(new CustomEvent("drop-down:close",{bubbles:!0})))};#h(t){this.#i.length!==0&&(t<0&&(t=this.#i.length-1),t>=this.#i.length&&(t=0),this.#n=t,this.#i[t].focus())}open(){this.#r||!this.#s||this.#s.show()}close(){!this.#r||!this.#s||this.#s.hide()}toggle(){this.#r?this.close():this.open()}get isOpen(){return this.#r}};h("drop-down",u);export{u as DropDown};
|
|
1
|
+
var a=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,s,e,i){t.addEventListener(s,e,i),this.#t.push(()=>t.removeEventListener(s,e,i))}_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,s){this.#e||(this.#e=this.attachInternals());let e=this.#e.states;try{s?e.add(t):e.delete(t)}catch{let i=`--${t}`;s?e.add(i):e.delete(i)}}_adoptInternals(t){this.#e||(this.#e=t)}};var v=window.matchMedia("(prefers-reduced-motion: reduce)");var p=new Map;function h(r,t,s={}){let e=s.priority??10,i={impl:t,bundle:s.bundle,contract:s.contract,priority:e},o=p.get(r);if(customElements.get(r)){if(!o||o.priority>=e){o&&o.priority===e&&o.impl!==t&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${o.bundle}" (priority ${o.priority}). Skipping "${s.bundle}".`);return}console.warn(`[VB Bundle] Tag <${r}> defined by "${o.bundle}" cannot be replaced (customElements.define is permanent). "${s.bundle}" has higher priority but arrived late.`);return}if(o&&o.priority>=e){o.priority===e&&console.warn(`[VB Bundle] Tag <${r}> already registered by "${o.bundle}". Skipping "${s.bundle}" (first wins at equal priority).`);return}p.set(r,i),customElements.define(r,t)}var l=CSS.supports("anchor-name","--x"),m=CSS.supports("position-area","bottom"),b=0,c=class extends a{#t=null;#e=null;#s=null;#i=null;setup(){this.id||(this.id=`pop-over-${++b}`);let t=this.dataset.mode||"auto";this.hasAttribute("popover")||this.setAttribute("popover",t),this.#n(),this.#r(),this.#s=s=>{let e=s.newState==="open"?"show":"hide";this.dispatchEvent(new CustomEvent(`pop-over:${e}`,{detail:{state:s.newState},bubbles:!0,composed:!0})),!l&&s.newState==="open"&&this.#t&&this.#o()},this.listen(this,"beforetoggle",this.#s),l||(this.#i=()=>{this.matches(":popover-open")&&this.#t&&this.#o()},this.listen(window,"resize",this.#i),this.listen(window,"scroll",this.#i,{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")}#n(){let t=this.dataset.anchor;t?this.#t=document.getElementById(t)||document.querySelector(t):this.#t=document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`)}#r(){if(!(!this.#t||!l)&&(this.#e=`--pop-over-anchor-${this.id}`,this.#t.style.setProperty("anchor-name",this.#e),this.style.setProperty("position-anchor",this.#e),this.setAttribute("data-anchor-name",this.#e||""),!m)){let t=this.dataset.position||"bottom";this.#a(t)}}#a(t){let s="var(--_pop-over-offset, var(--size-xs))",e={top:{bottom:`calc(anchor(top) + ${s})`,left:"anchor(left)"},bottom:{top:`calc(anchor(bottom) + ${s})`,left:"anchor(left)"},left:{right:`calc(anchor(left) + ${s})`,top:"anchor(top)"},right:{left:`calc(anchor(right) + ${s})`,top:"anchor(top)"}},i=t.split("-")[0],o=e[i]||e.bottom;Object.entries(o).forEach(([n,f])=>this.style.setProperty(n,f))}#o(){if(!this.#t)return;let t=this.#t.getBoundingClientRect(),s=this.dataset.position||"bottom",e=this.#l(),i,o;switch(s.split("-")[0]){case"top":i=t.top-this.offsetHeight-e,o=t.left;break;case"left":i=t.top,o=t.left-this.offsetWidth-e;break;case"right":i=t.top,o=t.right+e;break;default:i=t.bottom+e,o=t.left;break}s.endsWith("-end")&&(s.startsWith("top")||s.startsWith("bottom")?o=t.right-this.offsetWidth:i=t.bottom-this.offsetHeight),this.style.position="fixed",this.style.top=`${Math.round(i)}px`,this.style.left=`${Math.round(o)}px`,this.style.margin="0"}#l(){let t={none:0,xs:4,s:8,m:16,l:24};return t[this.dataset.offset]??t.xs}};h("pop-over",c);var d=0,u=class extends a{#t;#e;#s;#i=[];#n=-1;#r=!1;#a=!1;#o=null;setup(){let t=this.querySelector(":scope > [data-trigger]")||this.querySelector(":scope > button");if(!t)return!1;this.#t=t;let s=this.querySelector('menu, ul[role="menu"]');if(!s)return!1;this.#e=s,this.#a=this.hasAttribute("hover"),this.#t.id||(this.#t.id=`dropdown-trigger-${++d}`);let e=this.querySelector(":scope > pop-over[data-dropdown-host]");return e?this.#s=e:(this.#s=document.createElement("pop-over"),this.#s.setAttribute("data-dropdown-host",""),this.#s.id=`dropdown-${++d}`,this.#s.dataset.mode=this.#a?"manual":"auto",this.#s.dataset.position=this.getAttribute("position")||"bottom-start",this.#s.dataset.anchor=this.#t.id,this.#s.appendChild(this.#e),this.appendChild(this.#s)),this.#s.dataset.mode=this.#a?"manual":"auto",this.#s.dataset.position=this.getAttribute("position")||"bottom-start",this.#s.dataset.anchor=this.#t.id,this.#e.parentElement!==this.#s&&this.#s.appendChild(this.#e),this.#t.setAttribute("aria-haspopup","menu"),this.#t.setAttribute("aria-expanded","false"),this.#e.id||(this.#e.id=`dropdown-menu-${++d}`),this.#t.setAttribute("aria-controls",this.#e.id),this.#e.setAttribute("role","menu"),this.#l(),this.#a?(this.listen(this,"mouseenter",this.#d),this.listen(this,"mouseleave",this.#u),this.listen(this.#t,"focus",this.#p),this.listen(this.#t,"blur",this.#f)):this.listen(this.#t,"click",this.#c),this.listen(this.#t,"keydown",this.#m),this.listen(this.#e,"keydown",this.#b),this.listen(this.#s,"pop-over:hide",this.#w),this.listen(this.#s,"pop-over:show",this.#y),this.#a&&this.listen(document,"keydown",this.#g),!0}teardown(){this.#o&&clearTimeout(this.#o)}get items(){if(!this.#e)return[];let t=[];for(let s of this.#e.querySelectorAll(":scope > li")){if(s.matches('[role="separator"]')||s.querySelector("hr")){t.push({separator:!0});continue}let e=s.querySelector('button, a, [role="menuitem"]');e&&t.push({label:e.textContent.trim().replace(/\s+/g," "),value:e.getAttribute("data-value")||void 0,href:e.tagName==="A"?e.getAttribute("href"):void 0,disabled:e.disabled||e.hasAttribute("data-disabled")||void 0})}return t}set items(t){let s=Array.isArray(t)?t:[],e=this.querySelector('menu, ul[role="menu"]');for(e||(e=document.createElement("menu"),this.appendChild(e));e.firstChild;)e.firstChild.remove();for(let i of s){let o=document.createElement("li");if(i.separator)o.setAttribute("role","separator");else{let n=i.href?document.createElement("a"):document.createElement("button");i.href&&n.setAttribute("href",i.href),i.value&&n.setAttribute("data-value",i.value),i.disabled&&(n.tagName==="BUTTON"?n.disabled=!0:n.setAttribute("data-disabled","")),n.textContent=i.label||"",o.appendChild(n)}e.appendChild(o)}this.teardown(),this.removeAttribute("data-upgraded"),this.setup(),this.dispatchEvent(new CustomEvent("drop-down:items-changed",{detail:{items:s,source:"property"},bubbles:!0}))}#l(){this.#i=Array.from(this.#e.querySelectorAll('button, a, [role="menuitem"]')).filter(t=>!t.disabled&&!t.closest('[role="separator"]')),this.#i.forEach(t=>{t.setAttribute("role","menuitem"),t.setAttribute("tabindex","-1"),t.addEventListener("click",this.#v)}),this.#e.querySelectorAll('li:empty, [role="separator"], hr').forEach(t=>{t.setAttribute("role","separator")})}#c=t=>{t.stopPropagation(),this.toggle()};#d=()=>{this.#o&&(clearTimeout(this.#o),this.#o=null,this.setState("hover-grace-pending",!1)),this.open()};#u=()=>{this.setState("hover-grace-pending",!0),this.#o=setTimeout(()=>{this.setState("hover-grace-pending",!1),this.close()},100)};#p=()=>{this.#o&&(clearTimeout(this.#o),this.#o=null,this.setState("hover-grace-pending",!1)),this.open()};#f=t=>{this.#e?.contains(t.relatedTarget)||(this.setState("hover-grace-pending",!0),this.#o=setTimeout(()=>{this.setState("hover-grace-pending",!1),this.contains(document.activeElement)||this.close()},100))};#m=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.open(),this.#h(0);break;case"ArrowUp":case"Up":t.preventDefault(),this.open(),this.#h(this.#i.length-1);break}};#b=t=>{switch(t.key){case"ArrowDown":case"Down":t.preventDefault(),this.#h(this.#n+1);break;case"ArrowUp":case"Up":t.preventDefault(),this.#h(this.#n-1);break;case"Home":t.preventDefault(),this.#h(0);break;case"End":t.preventDefault(),this.#h(this.#i.length-1);break;case"Tab":this.close();break;case"Enter":case" ":t.preventDefault(),this.#n>=0&&this.#i[this.#n].click();break}};#g=t=>{t.key==="Escape"&&this.#r&&(t.preventDefault(),this.close(),this.#t?.focus())};#v=t=>{t.defaultPrevented||(this.close(),this.#t?.focus())};#y=()=>{this.#r||(this.#r=!0,this.setAttribute("open",""),this.#t?.setAttribute("aria-expanded","true"),this.#n=-1,this.dispatchEvent(new CustomEvent("drop-down:open",{bubbles:!0})))};#w=()=>{this.#r&&(this.#r=!1,this.removeAttribute("open"),this.#t?.setAttribute("aria-expanded","false"),this.#n=-1,this.dispatchEvent(new CustomEvent("drop-down:close",{bubbles:!0})))};#h(t){this.#i.length!==0&&(t<0&&(t=this.#i.length-1),t>=this.#i.length&&(t=0),this.#n=t,this.#i[t].focus())}open(){this.#r||!this.#s||this.#s.show()}close(){!this.#r||!this.#s||this.#s.hide()}toggle(){this.#r?this.close():this.open()}get isOpen(){return this.#r}};h("drop-down",u);export{u as DropDown};
|
|
2
2
|
//# sourceMappingURL=drop-down.js.map
|