@kashi-ui/elements 2.16.0 → 2.17.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/dist/cdn/{appointment-Bib3SMh-.js → appointment-D_pJVXZI.js} +1 -1
- package/dist/cdn/{base-BlPZs-0l.js → base-w2Oo_bN6.js} +1 -1
- package/dist/cdn/{basic-oiYiznp8.js → basic-BgjuD9oA.js} +1 -1
- package/dist/cdn/{calendar-DftXi3uh.js → calendar-C8oLBqU9.js} +1 -1
- package/dist/cdn/{charts-CsNTZKBb.js → charts-BwxbZ9wY.js} +1 -1
- package/dist/cdn/combobox-DbO22e05.js +1 -0
- package/dist/cdn/{commerce-DN3dNoSR.js → commerce-BE8XqH5T.js} +1 -1
- package/dist/cdn/{controls-C2wsO-Gb.js → controls-B6MNzFzT.js} +1 -1
- package/dist/cdn/display-BF8oy2Qf.js +1 -0
- package/dist/cdn/{fields-Btdg5Zgk.js → fields-BqqCV2-_.js} +1 -1
- package/dist/cdn/{forms-BF079sWA.js → forms-CdqDEqNa.js} +1 -1
- package/dist/cdn/{holidays-BYSO2Byu.js → holidays-_P97spUk.js} +1 -1
- package/dist/cdn/{inputs-BclVyEHc.js → inputs-DJWF8jhq.js} +1 -1
- package/dist/cdn/kashi-elements.js +1 -1
- package/dist/cdn/{map-YrESQG5R.js → map-CfW_We7C.js} +10 -10
- package/dist/cdn/{menu-DgUM6m6b.js → menu-DPDpTJN9.js} +1 -1
- package/dist/cdn/{nav-DK0pd2O-.js → nav-CSjD84u9.js} +1 -1
- package/dist/cdn/{overlay-okwu-XyC.js → overlay-BL7eQXAc.js} +1 -1
- package/dist/cdn/{pickers-DB_1HqNt.js → pickers-C2I7_Fkl.js} +1 -1
- package/dist/cdn/{table-r5MhfzoO.js → table-CvSlz5Ml.js} +1 -1
- package/dist/cdn/{text-BX7yfRY7.js → text-3BuPhESu.js} +1 -1
- package/dist/cdn/{time-BhYgzIGh.js → time-7kcoDwZ_.js} +1 -1
- package/package.json +4 -4
- package/dist/cdn/combobox-B0G6DzSq.js +0 -1
- package/dist/cdn/display-B8uz0cQh.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,i as t,l as n,m as r,o as i,p as a,r as o,t as s,y as c}from"./base-BlPZs-0l.js";import{n as l}from"./text-BX7yfRY7.js";const u=e=>l(e,{digits:`latin`}).toLowerCase(),d=e=>[...e.querySelectorAll(`[role^="menuitem"]:not([aria-disabled="true"])`)];var f=class extends s{constructor(){super(...arguments),this.list=null,this.dialog=null,this.query=``,this.active=0,this.opener=null,this.key=c(`kashi-cmd`),this.onShortcut=e=>{this.getAttribute(`shortcut`)!==`false`&&(e.ctrlKey||e.metaKey)&&(e.key===`k`||e.key===`K`||e.code===`KeyK`)&&(e.preventDefault(),this.dialog?.open?this.close():this.show())}}connectedCallback(){o(()=>{this.isConnected&&(this.list===null&&(this.list=this.readItems()),this.dialog||this.build(),document.addEventListener(`keydown`,this.onShortcut))})}disconnectedCallback(){document.removeEventListener(`keydown`,this.onShortcut)}get items(){return this.list??[]}set items(e){this.list=[...e],this.dialog?.open&&this.paint()}readItems(){let e=[...this.querySelectorAll(`:scope > a, :scope > button`)].map((e,t)=>({id:e.dataset.value??`${t}`,label:e.textContent?.trim()??``,group:e.dataset.group,description:e.dataset.description,shortcut:e.dataset.shortcut,keywords:e.dataset.keywords?.split(/[,،]\s*/),href:e instanceof HTMLAnchorElement?e.getAttribute(`href`)??void 0:void 0}));return this.querySelectorAll(`:scope > a, :scope > button`).forEach(e=>e.remove()),e}build(){let e=document.createElement(`dialog`);e.className=`k-dialog k-command`;let t=a(),r=this.getAttribute(`label`)??t.command.title;e.setAttribute(`aria-label`,r),e.innerHTML=`<div class="k-input"><span class="k-input__addon"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="9" r="5.5"/><path d="m13.5 13.5 3 3"/></svg></span><input class="k-input__control" type="text" role="combobox" aria-expanded="true" aria-controls="${this.key}-list" aria-autocomplete="list" aria-label="${n(r)}" placeholder="${n(this.getAttribute(`placeholder`)??t.command.placeholder)}" autocomplete="off"></div><ul id="${this.key}-list" role="listbox" aria-label="${n(r)}" class="k-listbox k-listbox--inline k-command__list"></ul><div class="k-command__footer" aria-hidden="true"><span><kbd class="k-kbd">↑</kbd><kbd class="k-kbd">↓</kbd>${n(t.command.navigate)}</span><span><kbd class="k-kbd">Enter</kbd>${n(t.command.select)}</span><span><kbd class="k-kbd">Esc</kbd>${n(t.common.close)}</span></div><span class="k-sr-only" aria-live="polite"></span>`,this.append(e),this.dialog=e;let i=e.querySelector(`input`);i.addEventListener(`input`,()=>{this.query=i.value,this.active=0,this.paint()}),i.addEventListener(`keydown`,e=>{let t=this.filtered().length;if(t){if(e.key===`ArrowDown`)this.active=(this.active+1)%t;else if(e.key===`ArrowUp`)this.active=(this.active-1+t)%t;else if(e.key===`Home`)this.active=0;else if(e.key===`End`)this.active=t-1;else if(e.key===`Enter`)return this.run(this.filtered()[this.active]);else return;e.preventDefault(),this.paint()}});let o=e.querySelector(`ul`);o.addEventListener(`pointerdown`,e=>e.preventDefault()),o.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&this.run(this.filtered()[Number(t.dataset.i)])}),e.addEventListener(`click`,t=>t.target===e&&this.close()),e.addEventListener(`close`,()=>this.opener?.focus?.())}filtered(){let e=u(this.query.trim());return this.items.filter(t=>!e||[t.label,t.description??``,...t.keywords??[]].some(t=>u(t).includes(e)))}show(){this.dialog&&(this.opener=document.activeElement,this.query=``,this.active=0,this.dialog.querySelector(`input`).value=``,this.dialog.showModal?.(),this.paint(),this.dialog.querySelector(`input`).focus())}close(){this.dialog?.open&&this.dialog.close()}run(t){t&&(this.close(),t.href?location.href=t.href:e(this,`kashi-select`,{value:t.id,item:t}))}paint(){let e=this.dialog,t=this.filtered(),i=u(this.query.trim()),o=e=>{let t=i?u(e).indexOf(i):-1;return t<0?n(e):`${n(e.slice(0,t))}<mark>${n(e.slice(t,t+i.length))}</mark>${n(e.slice(t+i.length))}`},s;e.querySelector(`ul`).innerHTML=t.length?t.map((e,t)=>{let r=e.group&&e.group!==s?`<li role="presentation" class="k-listbox__group">${n(e.group)}</li>`:``;return s=e.group,`${r}<li id="${this.key}-list-${t}" data-i="${t}" role="option" aria-selected="${t===this.active}"${t===this.active?` data-active`:``} class="k-option"><span class="k-option__body"><span>${o(e.label)}</span>${e.description?`<span class="k-option__desc">${n(e.description)}</span>`:``}</span>${e.shortcut?`<span class="k-menu__shortcut" aria-hidden="true">${n(e.shortcut)}</span>`:``}</li>`}).join(``):`<li role="presentation" class="k-listbox__empty">${n(a().command.empty)}</li>`;let c=e.querySelector(`input`);t.length?c.setAttribute(`aria-activedescendant`,`${this.key}-list-${this.active}`):c.removeAttribute(`aria-activedescendant`),e.querySelector(`#${this.key}-list-${this.active}`)?.scrollIntoView?.({block:`nearest`}),e.querySelector(`:scope > .k-sr-only`).textContent=this.query?a().common.results(r(this,t.length)):``}};f.observedAttributes=[`placeholder`,`label`,`shortcut`];var p=class extends s{constructor(){super(...arguments),this.menu=null,this.returnTo=null,this.key=c(`kashi-ctx`),this.onOutside=e=>{this.menu?.contains(e.target)||this.close(!1)},this.onScroll=()=>this.close(!1)}connectedCallback(){o(()=>this.isConnected&&!this.menu&&this.build())}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}build(){let t=this.querySelector(`:scope > [data-menu]`);this.classList.add(`k-context-area`),this.setAttribute(`aria-haspopup`,`menu`),this.setAttribute(`aria-describedby`,`${this.key}-hint`);let r=document.createElement(`ul`);r.setAttribute(`role`,`menu`),r.setAttribute(`aria-label`,this.getAttribute(`label`)??a().contextMenu.label),r.className=`k-menu k-menu--context`,r.hidden=!0;for(let e of[...t?.children??[]]){let t=document.createElement(`li`);e.tagName===`HR`?(t.setAttribute(`role`,`separator`),t.className=`k-menu__separator`):e.hasAttribute(`data-label`)?(t.setAttribute(`role`,`presentation`),t.className=`k-menu__label`,t.textContent=e.textContent):(t.setAttribute(`role`,`none`),e.setAttribute(`role`,`menuitem`),e.tabIndex=-1,e.classList.add(`k-menu__item`),e.dataset.tone===`danger`&&e.classList.add(`k-menu__item--danger`),e instanceof HTMLButtonElement&&(e.type=`button`),e.innerHTML=`<span>${e.innerHTML}</span>${e.dataset.shortcut?`<span class="k-menu__shortcut" aria-hidden="true">${n(e.dataset.shortcut)}</span>`:``}`,t.append(e)),r.append(t)}t?.remove(),this.insertAdjacentHTML(`beforeend`,`<span id="${this.key}-hint" class="k-sr-only">${n(a().contextMenu.hint)}</span>`),this.append(r),this.menu=r,this.addEventListener(`contextmenu`,e=>{r.contains(e.target)||(e.preventDefault(),this.openAt(e.clientX,e.clientY))});let i=null,o=()=>{i&&clearTimeout(i.t),i=null};this.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||r.contains(e.target))return;o();let{clientX:t,clientY:n}=e;i={x:t,y:n,t:setTimeout(()=>{i=null,this.openAt(t,n)},500)}}),this.addEventListener(`pointermove`,e=>{i&&Math.hypot(e.clientX-i.x,e.clientY-i.y)>10&&o()}),this.addEventListener(`pointerup`,o),this.addEventListener(`pointercancel`,o),this.addEventListener(`keydown`,e=>{if(r.contains(e.target))return this.onMenuKey(e);if(e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`){e.preventDefault();let t=document.activeElement.getBoundingClientRect();this.openAt(t.left+t.width/2,t.top+t.height/2)}}),r.addEventListener(`click`,t=>{let n=t.target.closest(`[role="menuitem"]`);n&&(e(this,`kashi-select`,{value:n.dataset.value??n.textContent?.trim()??``}),this.close(n.tagName!==`A`))})}openAt(e,t){let n=this.menu;this.returnTo=document.activeElement??this,n.hidden=!1;let r=n;r.showPopover&&(n.hasAttribute(`popover`)||n.setAttribute(`popover`,`manual`),n.matches(`:popover-open`)||r.showPopover());let i=n.getBoundingClientRect(),a=getComputedStyle(this).direction===`rtl`,o=a?e-i.width:e;o<8&&(o=a?e:8),o=Math.max(8,Math.min(o,innerWidth-i.width-8));let s=Math.max(8,Math.min(t+i.height>innerHeight-8?t-i.height:t,innerHeight-i.height-8));n.style.setProperty(`--_x`,`${o}px`),n.style.setProperty(`--_y`,`${s}px`),d(n)[0]?.focus({preventScroll:!0}),document.addEventListener(`pointerdown`,this.onOutside),setTimeout(()=>addEventListener(`scroll`,this.onScroll,{passive:!0,once:!0}),150)}close(e=!0){let t=this.menu;if(!t||t.hidden)return;let n=t;t.matches?.(`:popover-open`)&&n.hidePopover?.(),t.hidden=!0,document.removeEventListener(`pointerdown`,this.onOutside),removeEventListener(`scroll`,this.onScroll),e&&this.returnTo?.focus()}onMenuKey(e){let t=d(this.menu),n=t.indexOf(document.activeElement),r=e=>t[(e+t.length)%t.length]?.focus();if(e.key===`ArrowDown`)r(n+1);else if(e.key===`ArrowUp`)r(n-1);else if(e.key===`Home`)r(0);else if(e.key===`End`)r(t.length-1);else if(e.key===`Escape`)this.close();else if(e.key===`Tab`)return this.close(!1);else return;e.preventDefault()}};p.observedAttributes=[`label`];const m=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-k-mirror=""><path d="${e?`m8 5 5 5-5 5`:`m12 5-5 5 5 5`}"/></svg>`,h=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e?`<path d="M7.5 5v10M12.5 5v10"/>`:`<path d="M7 4.8v10.4a.6.6 0 0 0 .9.5l8-5.2a.6.6 0 0 0 0-1L7.9 4.3a.6.6 0 0 0-.9.5Z"/>`}</svg>`,g=e=>getComputedStyle(e).direction===`rtl`;function _(e,t){let n=null;e.addEventListener(`pointerdown`,e=>{e.pointerType!==`mouse`&&(n={x:e.clientX,y:e.clientY})}),e.addEventListener(`pointercancel`,()=>n=null),e.addEventListener(`pointerup`,r=>{let i=n;if(n=null,!i)return;let a=r.clientX-i.x,o=r.clientY-i.y;Math.abs(a)<40||Math.abs(a)<Math.abs(o)*1.2||t(a<0===g(e)?-1:1)})}var v=class extends s{constructor(){super(...arguments),this.track=null,this.section=null,this.index=0,this.io=null,this.key=c(`kashi-carousel`),this.left=0,this.startedAt=0,this.playing=!1,this.holds=/* @__PURE__ */ new Set,this.box=null,this.boxIndex=0,this.onVisibility=()=>this.hold(`hidden`,document.hidden)}connectedCallback(){o(()=>this.isConnected&&!this.track&&this.build())}disconnectedCallback(){this.io?.disconnect(),clearTimeout(this.timer),document.removeEventListener(`visibilitychange`,this.onVisibility)}get fade(){return this.getAttribute(`effect`)===`fade`}get perView(){return this.fade?1:Math.max(1,Number(this.getAttribute(`per-view`))||1)}get interval(){if(!this.hasAttribute(`autoplay`))return 0;let e=Number(this.getAttribute(`autoplay`));return e>0?e:5e3}get slides(){return[...this.track?.children??[]]}get pages(){return Math.max(1,this.slides.length-this.perView+1)}build(){let e=a(),t=this.getAttribute(`label`)??e.carousel.slider,i=[...this.children],o=this.hasAttribute(`lightbox`),s=document.createElement(`section`);s.className=`k-carousel${this.fade?` k-carousel--fade`:``}`,s.setAttribute(`aria-roledescription`,e.carousel.slider),s.setAttribute(`aria-label`,t),o&&s.setAttribute(`data-lightbox`,``),s.style.setProperty(`--k-carousel-per-view`,String(this.perView));let c=document.createElement(`div`);c.className=`k-carousel__track`,c.tabIndex=0,c.setAttribute(`aria-live`,`polite`);let l=[];i.forEach((t,n)=>{let a=document.createElement(`div`);a.className=`k-carousel__slide`,a.setAttribute(`role`,`group`),a.setAttribute(`aria-roledescription`,e.carousel.slide),a.setAttribute(`aria-label`,e.carousel.slideOf(r(this,n+1),r(this,i.length))),a.id=`${this.key}-s${n}`;let o=t.getAttribute(`data-thumb`)??(t.tagName===`IMG`?t.getAttribute(`src`):null);o&&(l[n]=o),a.append(t),c.append(a)}),s.append(c),this.replaceChildren(s),this.track=c,this.section=s;let u=this.interval;if(u&&this.pages>1&&s.insertAdjacentHTML(`beforeend`,`<span class="k-carousel__progress" aria-hidden="true"><span class="k-carousel__progress-bar" style="--_d: ${u}ms"></span></span>`),i.some(e=>e.hasAttribute(`data-thumb`))&&s.insertAdjacentHTML(`beforeend`,`<div class="k-carousel__thumbs" role="group" aria-label="${n(e.carousel.thumbnails(t))}">${i.map((t,a)=>`<button type="button" class="k-carousel__thumb" data-go="${a}" aria-label="${n(e.carousel.slideOf(r(this,a+1),r(this,i.length)))}" aria-controls="${this.key}-s${a}">${l[a]?`<img src="${n(l[a])}" alt="" loading="lazy">`:``}</button>`).join(``)}</div>`),this.pages>1||o){let i=this.getAttribute(`dots`)!==`false`&&this.pages>1,a=`${u&&this.pages>1?`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-act="play"></button>`:``}${o?`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-act="expand" aria-haspopup="dialog" aria-label="${n(e.carousel.expand)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3.5h4.5V8M8 16.5H3.5V12M16.5 3.5 11.5 8.5M3.5 16.5l5-5"/></svg></button>`:``}${this.pages>1?`<button type="button" class="k-btn k-btn--secondary k-btn--icon k-btn--sm" data-step="-1" aria-label="${n(e.common.prev)}">${m(!1)}</button><button type="button" class="k-btn k-btn--secondary k-btn--icon k-btn--sm" data-step="1" aria-label="${n(e.common.next)}">${m(!0)}</button>`:``}`;s.insertAdjacentHTML(`beforeend`,`<div class="k-carousel__bar">${i?`<ul class="k-carousel__dots" aria-label="${n(e.carousel.slides(t))}">${Array.from({length:this.pages},(t,i)=>`<li><button type="button" class="k-carousel__dot" data-go="${i}" aria-label="${n(e.carousel.slideOf(r(this,i+1),r(this,this.pages)))}" aria-controls="${this.key}-s${i}"></button></li>`).join(``)}</ul>`:`<span></span>`}<div class="k-carousel__nav">${a}</div></div>`)}s.addEventListener(`click`,e=>{let t=e.target.closest(`button`);if(t&&!this.box?.contains(t))return t.dataset.act===`play`?this.setPlaying(!this.playing):t.dataset.act===`expand`?this.openBox(this.index):t.dataset.go===void 0?t.dataset.step?this.go(this.index+Number(t.dataset.step)):void 0:this.go(Number(t.dataset.go));let n=e.target.closest(`.k-carousel__slide`);o&&n&&c.contains(n)&&!e.target.closest(`a, input, select, textarea, [tabindex]:not(.k-carousel__track)`)&&this.openBox(this.slides.indexOf(n))}),c.addEventListener(`keydown`,e=>{let t=g(c),n={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];n?(e.preventDefault(),this.go(this.index+n)):e.key===`Home`?this.go(0):e.key===`End`?this.go(this.pages-1):o&&e.key===`Enter`&&e.target===c&&this.openBox(this.index)}),this.fade?_(c,e=>this.go(this.index+e)):typeof IntersectionObserver<`u`&&(this.io=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting&&e.intersectionRatio>.6).map(e=>this.slides.indexOf(e.target));t.length&&this.setIndex(Math.min(...t))},{root:c,threshold:[.6,1]}),this.slides.forEach(e=>this.io.observe(e))),s.addEventListener(`mouseenter`,()=>this.hold(`hover`,!0)),s.addEventListener(`mouseleave`,()=>this.hold(`hover`,!1)),s.addEventListener(`focusin`,()=>this.hold(`focus`,!0)),s.addEventListener(`focusout`,e=>!s.contains(e.relatedTarget)&&this.hold(`focus`,!1)),document.addEventListener(`visibilitychange`,this.onVisibility),this.index=-1,this.setIndex(0),this.left=u,this.setPlaying(u>0&&!matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)}hold(e,t){t?this.holds.add(e):this.holds.delete(e),this.schedule()}setPlaying(e){this.playing=e;let t=this.querySelector(`[data-act="play"]`);t&&(t.innerHTML=h(e),t.setAttribute(`aria-label`,e?a().carousel.pause:a().carousel.play),t.setAttribute(`aria-pressed`,String(!e))),this.schedule()}schedule(){let e=this.interval>0&&this.pages>1&&this.playing&&this.holds.size===0;this.timer!==void 0&&(clearTimeout(this.timer),this.timer=void 0,this.left=Math.max(0,this.left-(Date.now()-this.startedAt))),this.track?.setAttribute(`aria-live`,e?`off`:`polite`),this.querySelector(`.k-carousel__progress-bar`)?.toggleAttribute(`data-paused`,!e),e&&(this.startedAt=Date.now(),this.timer=setTimeout(()=>{this.timer=void 0,this.go((this.index+1)%this.pages)},this.left))}go(e){let t=Math.max(0,Math.min(this.pages-1,e)),n=this.slides[t],r=this.track;if(n&&r){if(!this.fade){let e=g(r)?-(r.getBoundingClientRect().right-n.getBoundingClientRect().right)+r.scrollLeft:n.getBoundingClientRect().left-r.getBoundingClientRect().left+r.scrollLeft;r.scrollTo?.({left:e})}this.setIndex(t)}}setIndex(t){let n=t!==this.index;this.index=t,this.querySelectorAll(`.k-carousel__dot`).forEach((e,n)=>e.setAttribute(`aria-current`,String(n===t)));let r=this.querySelectorAll(`.k-carousel__thumb`);r.forEach((e,n)=>e.setAttribute(`aria-current`,String(n===t)));let i=this.querySelector(`.k-carousel__thumbs`),a=r[t];if(i&&a){let e=i.getBoundingClientRect(),t=a.getBoundingClientRect();(t.left<e.left||t.right>e.right)&&i.scrollTo?.({left:i.scrollLeft+(t.left+t.width/2)-(e.left+e.width/2)})}this.fade&&this.slides.forEach((e,n)=>{e.toggleAttribute(`data-active`,n===t),e.toggleAttribute(`inert`,n!==t),n===t?e.removeAttribute(`aria-hidden`):e.setAttribute(`aria-hidden`,`true`)});let[o,s]=this.querySelectorAll(`.k-carousel__bar [data-step]`);if(o&&(o.disabled=t===0),s&&(s.disabled=t>=this.pages-1),!n)return;let c=this.querySelector(`.k-carousel__progress-bar`);c&&c.replaceWith(c.cloneNode(!0)),this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.left=this.interval,this.section&&this.schedule(),e(this,`kashi-change`,{index:t})}openBox(e){let t=a();if(!this.box){let e=document.createElement(`dialog`);e.className=`k-carousel__lightbox`,e.setAttribute(`aria-label`,t.carousel.lightbox(this.getAttribute(`label`)??t.carousel.slider)),e.innerHTML=`<div class="k-carousel__lightbox-head"><span class="k-carousel__lightbox-count" aria-live="polite"></span><button type="button" class="k-btn k-btn--tertiary k-btn--icon" data-box="close" aria-label="${n(t.common.close)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="m5.5 5.5 9 9m0-9-9 9"/></svg></button></div><div class="k-carousel__lightbox-stage">${this.slides.map(e=>`<div class="k-carousel__lightbox-slide">${e.innerHTML}</div>`).join(``)}</div>${this.slides.length>1?`<div class="k-carousel__lightbox-nav"><button type="button" class="k-btn k-btn--secondary k-btn--icon" data-box="-1" aria-label="${n(t.common.prev)}">${m(!1)}</button><button type="button" class="k-btn k-btn--secondary k-btn--icon" data-box="1" aria-label="${n(t.common.next)}">${m(!0)}</button></div>`:``}`,e.querySelectorAll(`[id]`).forEach(e=>e.removeAttribute(`id`)),e.addEventListener(`click`,t=>{let n=t.target.closest(`[data-box]`);n?.dataset.box===`close`||t.target===e?e.close():n&&this.boxGo(this.boxIndex+Number(n.dataset.box))}),e.addEventListener(`keydown`,t=>{let n=g(e),r={ArrowLeft:n?1:-1,ArrowRight:n?-1:1}[t.key];r&&(t.preventDefault(),this.boxGo(this.boxIndex+r))}),e.addEventListener(`close`,()=>{this.hold(`box`,!1),this.go(Math.min(this.boxIndex,this.pages-1))}),_(e.querySelector(`.k-carousel__lightbox-stage`),e=>this.boxGo(this.boxIndex+e)),this.section.append(e),this.box=e}this.hold(`box`,!0),this.boxGo(e),this.box.showModal?.(),this.box.querySelector(`[data-box="close"]`)?.focus()}boxGo(e){let t=this.slides.length;this.boxIndex=(e+t)%t,this.box.querySelectorAll(`.k-carousel__lightbox-slide`).forEach((e,t)=>{e.toggleAttribute(`data-active`,t===this.boxIndex),e.toggleAttribute(`inert`,t!==this.boxIndex),t===this.boxIndex?e.removeAttribute(`aria-hidden`):e.setAttribute(`aria-hidden`,`true`)}),this.box.querySelector(`.k-carousel__lightbox-count`).textContent=a().carousel.slideOf(r(this,this.boxIndex+1),r(this,t))}};v.observedAttributes=[`label`,`per-view`,`dots`,`effect`,`autoplay`,`lightbox`];var y=class extends s{constructor(){super(...arguments),this.nodes=null,this.open=/* @__PURE__ */ new Set,this.sel=null,this.focusId=null,this.built=!1}connectedCallback(){o(()=>{if(this.isConnected){if(this.nodes===null){let e=this.querySelector(`:scope > ul`);this.nodes=e?this.parse(e):[]}if(!this.built){this.sel=this.getAttribute(`selected`);for(let e of(this.getAttribute(`expanded`)??``).split(/[,،]/).map(e=>e.trim()).filter(Boolean))this.open.add(e);this.built=!0}this.render()}})}attributeChangedCallback(e,t,n){this.built&&t!==n&&(e===`selected`&&(this.sel=n),this.render())}get items(){return this.nodes??[]}set items(e){this.nodes=e,this.built&&this.render()}get value(){return this.sel??``}parse(e){return[...e.children].filter(e=>e.tagName===`LI`).map((e,t)=>{let n=e.querySelector(`:scope > ul`),r=[...e.childNodes].filter(e=>e!==n).map(e=>e.textContent).join(``).trim(),i=e;return{id:i.dataset.id??`${r}-${t}`,label:r,meta:i.dataset.meta,disabled:i.hasAttribute(`data-disabled`),children:n?this.parse(n):void 0}})}visible(){let e=[],t=(n,r)=>{for(let i of n)e.push({node:i,parent:r}),i.children?.length&&this.open.has(i.id)&&t(i.children,i.id)};return t(this.items,null),e}render(e=!1){let t=this.visible(),r=this.focusId&&t.some(e=>e.node.id===this.focusId)?this.focusId:this.sel&&t.some(e=>e.node.id===this.sel)?this.sel:t[0]?.node.id,i=(e,t)=>e.map(e=>{let a=!!e.children?.length,o=this.open.has(e.id);return`<li role="treeitem" data-id="${n(e.id)}" class="k-tree__item" aria-level="${t}"${a?` aria-expanded="${o}"`:``} aria-selected="${this.sel===e.id}"${e.disabled?` aria-disabled="true"`:``} tabindex="${r===e.id?0:-1}"><div class="k-tree__row">${a?`<span class="k-tree__toggle" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 5 5 5-5 5"/></svg></span>`:`<span class="k-tree__spacer"></span>`}<span class="k-tree__label">${n(e.label)}</span>${e.meta?`<span class="k-tree__meta">${n(e.meta)}</span>`:``}</div>${a&&o?`<ul role="group">${i(e.children,t+1)}</ul>`:``}</li>`}).join(``);this.innerHTML=`<ul role="tree" class="k-tree"${this.getAttribute(`label`)?` aria-label="${n(this.getAttribute(`label`))}"`:``}>${i(this.items,1)}</ul>`;let a=this.querySelector(`ul`);a.addEventListener(`click`,e=>{let t=e.target.closest(`[role="treeitem"]`);if(!t||!e.target.closest(`.k-tree__row`))return;let n=this.find(t.dataset.id);n&&(n.children?.length&&this.toggle(n.id),this.focusId=n.id,this.choose(n))}),a.addEventListener(`keydown`,e=>this.onKey(e)),e&&r&&[...this.querySelectorAll(`[data-id]`)].find(e=>e.dataset.id===r)?.focus()}find(e,t=this.items){for(let n of t){if(n.id===e)return n;let t=n.children&&this.find(e,n.children);if(t)return t}return null}toggle(t,n=!this.open.has(t)){n?this.open.add(t):this.open.delete(t),e(this,`kashi-expand`,{expanded:[...this.open]})}choose(t){t.disabled||(this.sel=t.id,e(this,`kashi-change`,{value:t.id,node:t})),this.render(!0)}onKey(e){let t=this.visible(),n=document.activeElement?.dataset?.id,r=t.findIndex(e=>e.node.id===n),i=t[r];if(!i)return;let a=getComputedStyle(this).direction===`rtl`,o=!!i.node.children?.length,s=this.open.has(i.node.id),c=e=>{this.focusId=e,this.render(!0)};if(e.key===`ArrowDown`)t[r+1]&&c(t[r+1].node.id);else if(e.key===`ArrowUp`)t[r-1]&&c(t[r-1].node.id);else if(e.key===`Home`)c(t[0].node.id);else if(e.key===`End`)c(t[t.length-1].node.id);else if(e.key===(a?`ArrowLeft`:`ArrowRight`))o&&!s?(this.toggle(i.node.id,!0),c(i.node.id)):o&&c(i.node.children[0].id);else if(e.key===(a?`ArrowRight`:`ArrowLeft`))o&&s?(this.toggle(i.node.id,!1),c(i.node.id)):i.parent&&c(i.parent);else if(e.key===`Enter`||e.key===` `)this.focusId=i.node.id,this.choose(i.node);else return;e.preventDefault()}};y.observedAttributes=[`label`,`selected`,`expanded`];var b=class extends s{constructor(){super(...arguments),this.list=null,this.i=0,this.spot=null,this.card=null,this.returnTo=null,this.key=c(`kashi-tour`),this.place=()=>{let e=this.card;if(!e)return;let t=document.querySelector(this.steps[this.i].target)?.getBoundingClientRect()??null;t?(this.spot||(this.spot=document.createElement(`div`),this.spot.className=`k-tour__spot`,this.spot.setAttribute(`aria-hidden`,`true`),document.body.append(this.spot)),Object.assign(this.spot.style,{top:`${t.top-6}px`,left:`${t.left-6}px`,inlineSize:`${t.width+12}px`,blockSize:`${t.height+12}px`})):(this.spot?.remove(),this.spot=null);let n=e.getBoundingClientRect();if(!t){Object.assign(e.style,{top:`${innerHeight/2-n.height/2}px`,left:`${innerWidth/2-n.width/2}px`});return}let r=t.bottom+12+n.height<innerHeight?t.bottom+12:Math.max(12,t.top-12-n.height),i=Math.min(innerWidth-n.width-12,Math.max(12,t.left+t.width/2-n.width/2));Object.assign(e.style,{top:`${r}px`,left:`${i}px`})}}connectedCallback(){o(()=>{this.isConnected&&this.list===null&&(this.list=[...this.querySelectorAll(`:scope > [data-target]`)].map(e=>({target:e.dataset.target,title:e.dataset.title??``,content:e.textContent?.trim()??``})),this.replaceChildren())})}disconnectedCallback(){this.stop(!1)}get steps(){return this.list??[]}set steps(e){this.list=[...e]}start(){this.steps.length&&(this.returnTo=document.activeElement,this.i=0,addEventListener(`scroll`,this.place,{passive:!0}),addEventListener(`resize`,this.place),this.show())}stop(e=!0){this.spot?.remove(),this.card?.remove(),this.spot=this.card=null,removeEventListener(`scroll`,this.place),removeEventListener(`resize`,this.place),e&&this.returnTo?.focus?.()}show(){let t=this.steps[this.i],i=this.steps.length,o=this.i===i-1;this.card||(this.card=document.createElement(`div`),this.card.className=`k-tour__card`,this.card.setAttribute(`role`,`dialog`),this.card.setAttribute(`aria-modal`,`false`),this.card.setAttribute(`aria-labelledby`,`${this.key}-t`),this.card.setAttribute(`aria-describedby`,`${this.key}-b`),this.card.tabIndex=-1,this.card.addEventListener(`click`,t=>{let n=t.target.closest(`[data-act]`);if(!n)return;let r=n.dataset.act;r===`skip`?this.stop():r===`prev`?this.step(-1):r===`next`?this.step(1):r===`done`&&(this.stop(),e(this,`kashi-finish`,{}))}),this.card.addEventListener(`keydown`,e=>{let t=getComputedStyle(this.card).direction===`rtl`;e.key===`Escape`?this.stop():e.key===(t?`ArrowLeft`:`ArrowRight`)&&this.i<this.steps.length-1?this.step(1):e.key===(t?`ArrowRight`:`ArrowLeft`)&&this.i>0&&this.step(-1)}),document.body.append(this.card)),this.card.innerHTML=`<span class="k-tour__step">${n(a().tour.step(r(this,this.i+1),r(this,i)))}</span><p class="k-tour__title" id="${this.key}-t">${n(t.title)}</p><p class="k-tour__body" id="${this.key}-b">${n(t.content)}</p><div class="k-tour__actions"><button type="button" class="k-btn k-btn--link k-tour__skip" data-act="skip">${n(a().tour.skip)}</button><span class="k-tour__progress" aria-hidden="true">${this.steps.map((e,t)=>`<span${t<=this.i?` data-on=""`:``}></span>`).join(``)}</span>${this.i>0?'<button type="button" class="k-btn k-btn--secondary k-btn--sm" data-act="prev">${esc(msg().common.prev)}</button>':``}<button type="button" class="k-btn k-btn--primary k-btn--sm" data-act="${o?`done`:`next`}">${n(o?a().tour.done:a().common.next)}</button></div>`;let s=document.querySelector(t.target),c=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches;s?.scrollIntoView?.({block:`center`,behavior:c?`auto`:`smooth`}),this.place(),setTimeout(this.place,400),this.card.focus({preventScroll:!0})}step(e){this.i=Math.max(0,Math.min(this.steps.length-1,this.i+e)),this.show()}},x=class extends s{constructor(){super(...arguments),this.current=40,this.built=!1,this.dragging=!1}connectedCallback(){o(()=>{this.isConnected&&!this.built&&(this.current=this.num(`size`,40),this.build())})}attributeChangedCallback(e,t,n){this.built&&t!==n&&(e===`size`?this.set(Number(n)||40,!1):this.decorate())}get value(){return this.current}set value(e){this.set(e,!1)}num(e,t){let n=Number(this.getAttribute(e));return Number.isFinite(n)&&this.getAttribute(e)!==null?n:t}get vertical(){return this.getAttribute(`orientation`)===`vertical`}build(){let[e,t]=[...this.children],n=document.createElement(`div`),r=document.createElement(`div`);r.className=`k-splitter__pane`,e&&r.append(e);let i=document.createElement(`div`);i.className=`k-splitter__handle`,i.setAttribute(`role`,`separator`),i.tabIndex=0;let a=document.createElement(`div`);a.className=`k-splitter__pane`,t&&a.append(t),n.append(r,i,a),this.replaceChildren(n),this.built=!0,i.addEventListener(`pointerdown`,e=>{i.setPointerCapture?.(e.pointerId),this.dragging=!0,n.toggleAttribute(`data-dragging`,!0),i.toggleAttribute(`data-dragging`,!0)}),i.addEventListener(`pointermove`,e=>{if(!this.dragging)return;let t=n.getBoundingClientRect();if(this.vertical)return this.set((e.clientY-t.top)/t.height*100);let r=getComputedStyle(n).direction===`rtl`;this.set((r?t.right-e.clientX:e.clientX-t.left)/t.width*100)});let o=()=>{this.dragging=!1,n.removeAttribute(`data-dragging`),i.removeAttribute(`data-dragging`)};i.addEventListener(`pointerup`,o),i.addEventListener(`pointercancel`,o),i.addEventListener(`dblclick`,()=>this.set(this.num(`size`,40))),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,n=this.vertical?{ArrowUp:-5,ArrowDown:5}:{ArrowLeft:t?5:-5,ArrowRight:t?-5:5};if(e.key in n)this.set(this.current+n[e.key]);else if(e.key===`Home`)this.set(this.num(`min`,15));else if(e.key===`End`)this.set(this.num(`max`,85));else return;e.preventDefault()}),this.decorate()}decorate(){let e=this.firstElementChild;e.className=`k-splitter${this.vertical?` k-splitter--vertical`:``}`;let t=this.getAttribute(`height`);e.style.blockSize=t??``;let n=e.querySelector(`.k-splitter__handle`);n.setAttribute(`aria-orientation`,this.vertical?`horizontal`:`vertical`),n.setAttribute(`aria-valuemin`,String(this.num(`min`,15))),n.setAttribute(`aria-valuemax`,String(this.num(`max`,85))),n.setAttribute(`aria-label`,this.getAttribute(`label`)??a().splitter.label),this.paint()}set(t,n=!0){let r=Math.round(Math.min(this.num(`max`,85),Math.max(this.num(`min`,15),t))*10)/10,i=r!==this.current;this.current=r,this.built&&this.paint(),n&&i&&e(this,`kashi-change`,{value:r})}paint(){let e=this.firstElementChild,t=e.querySelector(`.k-splitter__pane`);t.style.inlineSize=this.vertical?``:`${this.current}%`,t.style.blockSize=this.vertical?`${this.current}%`:``;let n=e.querySelector(`.k-splitter__handle`);n.setAttribute(`aria-valuenow`,String(this.current)),n.setAttribute(`aria-valuetext`,a().common.percent(r(this,Math.round(this.current))))}};x.observedAttributes=[`size`,`min`,`max`,`orientation`,`label`,`height`];var S=class extends s{constructor(){super(...arguments),this.built=!1}connectedCallback(){o(()=>{this.isConnected&&!this.built&&(this.built=!0,this.addEventListener(`click`,t=>{let n=t.target.closest(`button[aria-controls][aria-expanded]`);if(!n||!this.contains(n))return;let r=document.getElementById(n.getAttribute(`aria-controls`)),i=n.getAttribute(`aria-expanded`)!==`true`;n.setAttribute(`aria-expanded`,String(i)),r&&(r.hidden=!i),e(this,`kashi-toggle`,{id:r?.id??``,open:i})}),this.decorate())})}attributeChangedCallback(){this.built&&this.decorate()}decorate(){let e=this.querySelector(`.k-sidenav`),n=t(this,`collapsed`);e?.classList.toggle(`k-sidenav--collapsed`,n),this.querySelectorAll(`.k-sidenav__item`).forEach(e=>{let t=e.querySelector(`.k-sidenav__text`)?.textContent?.trim();t&&(n?(e.setAttribute(`aria-label`,t),e.setAttribute(`title`,t)):(e.removeAttribute(`aria-label`),e.removeAttribute(`title`)))})}};S.observedAttributes=[`collapsed`],typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target,n=t?.closest?.(`[data-kashi-tour]`),r=n?document.getElementById(n.getAttribute(`data-kashi-tour`)):null;r?.start&&r.start();let i=t?.closest?.(`[data-kashi-command]`),a=i?document.getElementById(i.getAttribute(`data-kashi-command`)):null;a?.show&&a.show()}),i(`kashi-command-palette`,f,`contents`),i(`kashi-context-menu`,p,`block`),i(`kashi-carousel`,v,`block`),i(`kashi-tree-view`,y,`block`),i(`kashi-tour`,b,`contents`),i(`kashi-splitter`,x,`block`),i(`kashi-side-nav`,S,`block`);export{v as KashiCarousel,f as KashiCommandPalette,p as KashiContextMenu,S as KashiSideNav,x as KashiSplitter,b as KashiTour,y as KashiTreeView};
|
|
1
|
+
import{n as e}from"./text-3BuPhESu.js";import{c as t,i as n,l as r,m as i,o as a,p as o,r as s,t as c,y as l}from"./base-w2Oo_bN6.js";const u=t=>e(t,{digits:`latin`}).toLowerCase(),d=e=>[...e.querySelectorAll(`[role^="menuitem"]:not([aria-disabled="true"])`)];var f=class extends c{constructor(){super(...arguments),this.list=null,this.dialog=null,this.query=``,this.active=0,this.opener=null,this.key=l(`kashi-cmd`),this.onShortcut=e=>{this.getAttribute(`shortcut`)!==`false`&&(e.ctrlKey||e.metaKey)&&(e.key===`k`||e.key===`K`||e.code===`KeyK`)&&(e.preventDefault(),this.dialog?.open?this.close():this.show())}}connectedCallback(){s(()=>{this.isConnected&&(this.list===null&&(this.list=this.readItems()),this.dialog||this.build(),document.addEventListener(`keydown`,this.onShortcut))})}disconnectedCallback(){document.removeEventListener(`keydown`,this.onShortcut)}get items(){return this.list??[]}set items(e){this.list=[...e],this.dialog?.open&&this.paint()}readItems(){let e=[...this.querySelectorAll(`:scope > a, :scope > button`)].map((e,t)=>({id:e.dataset.value??`${t}`,label:e.textContent?.trim()??``,group:e.dataset.group,description:e.dataset.description,shortcut:e.dataset.shortcut,keywords:e.dataset.keywords?.split(/[,،]\s*/),href:e instanceof HTMLAnchorElement?e.getAttribute(`href`)??void 0:void 0}));return this.querySelectorAll(`:scope > a, :scope > button`).forEach(e=>e.remove()),e}build(){let e=document.createElement(`dialog`);e.className=`k-dialog k-command`;let t=o(),n=this.getAttribute(`label`)??t.command.title;e.setAttribute(`aria-label`,n),e.innerHTML=`<div class="k-input"><span class="k-input__addon"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="9" r="5.5"/><path d="m13.5 13.5 3 3"/></svg></span><input class="k-input__control" type="text" role="combobox" aria-expanded="true" aria-controls="${this.key}-list" aria-autocomplete="list" aria-label="${r(n)}" placeholder="${r(this.getAttribute(`placeholder`)??t.command.placeholder)}" autocomplete="off"></div><ul id="${this.key}-list" role="listbox" aria-label="${r(n)}" class="k-listbox k-listbox--inline k-command__list"></ul><div class="k-command__footer" aria-hidden="true"><span><kbd class="k-kbd">↑</kbd><kbd class="k-kbd">↓</kbd>${r(t.command.navigate)}</span><span><kbd class="k-kbd">Enter</kbd>${r(t.command.select)}</span><span><kbd class="k-kbd">Esc</kbd>${r(t.common.close)}</span></div><span class="k-sr-only" aria-live="polite"></span>`,this.append(e),this.dialog=e;let i=e.querySelector(`input`);i.addEventListener(`input`,()=>{this.query=i.value,this.active=0,this.paint()}),i.addEventListener(`keydown`,e=>{let t=this.filtered().length;if(t){if(e.key===`ArrowDown`)this.active=(this.active+1)%t;else if(e.key===`ArrowUp`)this.active=(this.active-1+t)%t;else if(e.key===`Home`)this.active=0;else if(e.key===`End`)this.active=t-1;else if(e.key===`Enter`)return this.run(this.filtered()[this.active]);else return;e.preventDefault(),this.paint()}});let a=e.querySelector(`ul`);a.addEventListener(`pointerdown`,e=>e.preventDefault()),a.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&this.run(this.filtered()[Number(t.dataset.i)])}),e.addEventListener(`click`,t=>t.target===e&&this.close()),e.addEventListener(`close`,()=>this.opener?.focus?.())}filtered(){let e=u(this.query.trim());return this.items.filter(t=>!e||[t.label,t.description??``,...t.keywords??[]].some(t=>u(t).includes(e)))}show(){this.dialog&&(this.opener=document.activeElement,this.query=``,this.active=0,this.dialog.querySelector(`input`).value=``,this.dialog.showModal?.(),this.paint(),this.dialog.querySelector(`input`).focus())}close(){this.dialog?.open&&this.dialog.close()}run(e){e&&(this.close(),e.href?location.href=e.href:t(this,`kashi-select`,{value:e.id,item:e}))}paint(){let e=this.dialog,t=this.filtered(),n=u(this.query.trim()),a=e=>{let t=n?u(e).indexOf(n):-1;return t<0?r(e):`${r(e.slice(0,t))}<mark>${r(e.slice(t,t+n.length))}</mark>${r(e.slice(t+n.length))}`},s;e.querySelector(`ul`).innerHTML=t.length?t.map((e,t)=>{let n=e.group&&e.group!==s?`<li role="presentation" class="k-listbox__group">${r(e.group)}</li>`:``;return s=e.group,`${n}<li id="${this.key}-list-${t}" data-i="${t}" role="option" aria-selected="${t===this.active}"${t===this.active?` data-active`:``} class="k-option"><span class="k-option__body"><span>${a(e.label)}</span>${e.description?`<span class="k-option__desc">${r(e.description)}</span>`:``}</span>${e.shortcut?`<span class="k-menu__shortcut" aria-hidden="true">${r(e.shortcut)}</span>`:``}</li>`}).join(``):`<li role="presentation" class="k-listbox__empty">${r(o().command.empty)}</li>`;let c=e.querySelector(`input`);t.length?c.setAttribute(`aria-activedescendant`,`${this.key}-list-${this.active}`):c.removeAttribute(`aria-activedescendant`),e.querySelector(`#${this.key}-list-${this.active}`)?.scrollIntoView?.({block:`nearest`}),e.querySelector(`:scope > .k-sr-only`).textContent=this.query?o().common.results(i(this,t.length)):``}};f.observedAttributes=[`placeholder`,`label`,`shortcut`];var p=class extends c{constructor(){super(...arguments),this.menu=null,this.returnTo=null,this.key=l(`kashi-ctx`),this.onOutside=e=>{this.menu?.contains(e.target)||this.close(!1)},this.onScroll=()=>this.close(!1)}connectedCallback(){s(()=>this.isConnected&&!this.menu&&this.build())}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}build(){let e=this.querySelector(`:scope > [data-menu]`);this.classList.add(`k-context-area`),this.setAttribute(`aria-haspopup`,`menu`),this.setAttribute(`aria-describedby`,`${this.key}-hint`);let n=document.createElement(`ul`);n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,this.getAttribute(`label`)??o().contextMenu.label),n.className=`k-menu k-menu--context`,n.hidden=!0;for(let t of[...e?.children??[]]){let e=document.createElement(`li`);t.tagName===`HR`?(e.setAttribute(`role`,`separator`),e.className=`k-menu__separator`):t.hasAttribute(`data-label`)?(e.setAttribute(`role`,`presentation`),e.className=`k-menu__label`,e.textContent=t.textContent):(e.setAttribute(`role`,`none`),t.setAttribute(`role`,`menuitem`),t.tabIndex=-1,t.classList.add(`k-menu__item`),t.dataset.tone===`danger`&&t.classList.add(`k-menu__item--danger`),t instanceof HTMLButtonElement&&(t.type=`button`),t.innerHTML=`<span>${t.innerHTML}</span>${t.dataset.shortcut?`<span class="k-menu__shortcut" aria-hidden="true">${r(t.dataset.shortcut)}</span>`:``}`,e.append(t)),n.append(e)}e?.remove(),this.insertAdjacentHTML(`beforeend`,`<span id="${this.key}-hint" class="k-sr-only">${r(o().contextMenu.hint)}</span>`),this.append(n),this.menu=n,this.addEventListener(`contextmenu`,e=>{n.contains(e.target)||(e.preventDefault(),this.openAt(e.clientX,e.clientY))});let i=null,a=()=>{i&&clearTimeout(i.t),i=null};this.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||n.contains(e.target))return;a();let{clientX:t,clientY:r}=e;i={x:t,y:r,t:setTimeout(()=>{i=null,this.openAt(t,r)},500)}}),this.addEventListener(`pointermove`,e=>{i&&Math.hypot(e.clientX-i.x,e.clientY-i.y)>10&&a()}),this.addEventListener(`pointerup`,a),this.addEventListener(`pointercancel`,a),this.addEventListener(`keydown`,e=>{if(n.contains(e.target))return this.onMenuKey(e);if(e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`){e.preventDefault();let t=document.activeElement.getBoundingClientRect();this.openAt(t.left+t.width/2,t.top+t.height/2)}}),n.addEventListener(`click`,e=>{let n=e.target.closest(`[role="menuitem"]`);n&&(t(this,`kashi-select`,{value:n.dataset.value??n.textContent?.trim()??``}),this.close(n.tagName!==`A`))})}openAt(e,t){let n=this.menu;this.returnTo=document.activeElement??this,n.hidden=!1;let r=n;r.showPopover&&(n.hasAttribute(`popover`)||n.setAttribute(`popover`,`manual`),n.matches(`:popover-open`)||r.showPopover());let i=n.getBoundingClientRect(),a=getComputedStyle(this).direction===`rtl`,o=a?e-i.width:e;o<8&&(o=a?e:8),o=Math.max(8,Math.min(o,innerWidth-i.width-8));let s=Math.max(8,Math.min(t+i.height>innerHeight-8?t-i.height:t,innerHeight-i.height-8));n.style.setProperty(`--_x`,`${o}px`),n.style.setProperty(`--_y`,`${s}px`),d(n)[0]?.focus({preventScroll:!0}),document.addEventListener(`pointerdown`,this.onOutside),setTimeout(()=>addEventListener(`scroll`,this.onScroll,{passive:!0,once:!0}),150)}close(e=!0){let t=this.menu;if(!t||t.hidden)return;let n=t;t.matches?.(`:popover-open`)&&n.hidePopover?.(),t.hidden=!0,document.removeEventListener(`pointerdown`,this.onOutside),removeEventListener(`scroll`,this.onScroll),e&&this.returnTo?.focus()}onMenuKey(e){let t=d(this.menu),n=t.indexOf(document.activeElement),r=e=>t[(e+t.length)%t.length]?.focus();if(e.key===`ArrowDown`)r(n+1);else if(e.key===`ArrowUp`)r(n-1);else if(e.key===`Home`)r(0);else if(e.key===`End`)r(t.length-1);else if(e.key===`Escape`)this.close();else if(e.key===`Tab`)return this.close(!1);else return;e.preventDefault()}};p.observedAttributes=[`label`];const m=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-k-mirror=""><path d="${e?`m8 5 5 5-5 5`:`m12 5-5 5 5 5`}"/></svg>`,h=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e?`<path d="M7.5 5v10M12.5 5v10"/>`:`<path d="M7 4.8v10.4a.6.6 0 0 0 .9.5l8-5.2a.6.6 0 0 0 0-1L7.9 4.3a.6.6 0 0 0-.9.5Z"/>`}</svg>`,g=e=>getComputedStyle(e).direction===`rtl`;function _(e,t){let n=null;e.addEventListener(`pointerdown`,e=>{e.pointerType!==`mouse`&&(n={x:e.clientX,y:e.clientY})}),e.addEventListener(`pointercancel`,()=>n=null),e.addEventListener(`pointerup`,r=>{let i=n;if(n=null,!i)return;let a=r.clientX-i.x,o=r.clientY-i.y;Math.abs(a)<40||Math.abs(a)<Math.abs(o)*1.2||t(a<0===g(e)?-1:1)})}var v=class extends c{constructor(){super(...arguments),this.track=null,this.section=null,this.index=0,this.io=null,this.key=l(`kashi-carousel`),this.left=0,this.startedAt=0,this.playing=!1,this.holds=/* @__PURE__ */ new Set,this.box=null,this.boxIndex=0,this.onVisibility=()=>this.hold(`hidden`,document.hidden)}connectedCallback(){s(()=>this.isConnected&&!this.track&&this.build())}disconnectedCallback(){this.io?.disconnect(),clearTimeout(this.timer),document.removeEventListener(`visibilitychange`,this.onVisibility)}get fade(){return this.getAttribute(`effect`)===`fade`}get perView(){return this.fade?1:Math.max(1,Number(this.getAttribute(`per-view`))||1)}get interval(){if(!this.hasAttribute(`autoplay`))return 0;let e=Number(this.getAttribute(`autoplay`));return e>0?e:5e3}get slides(){return[...this.track?.children??[]]}get pages(){return Math.max(1,this.slides.length-this.perView+1)}build(){let e=o(),t=this.getAttribute(`label`)??e.carousel.slider,n=[...this.children],a=this.hasAttribute(`lightbox`),s=document.createElement(`section`);s.className=`k-carousel${this.fade?` k-carousel--fade`:``}`,s.setAttribute(`aria-roledescription`,e.carousel.slider),s.setAttribute(`aria-label`,t),a&&s.setAttribute(`data-lightbox`,``),s.style.setProperty(`--k-carousel-per-view`,String(this.perView));let c=document.createElement(`div`);c.className=`k-carousel__track`,c.tabIndex=0,c.setAttribute(`aria-live`,`polite`);let l=[];n.forEach((t,r)=>{let a=document.createElement(`div`);a.className=`k-carousel__slide`,a.setAttribute(`role`,`group`),a.setAttribute(`aria-roledescription`,e.carousel.slide),a.setAttribute(`aria-label`,e.carousel.slideOf(i(this,r+1),i(this,n.length))),a.id=`${this.key}-s${r}`;let o=t.getAttribute(`data-thumb`)??(t.tagName===`IMG`?t.getAttribute(`src`):null);o&&(l[r]=o),a.append(t),c.append(a)}),s.append(c),this.replaceChildren(s),this.track=c,this.section=s;let u=this.interval;if(u&&this.pages>1&&s.insertAdjacentHTML(`beforeend`,`<span class="k-carousel__progress" aria-hidden="true"><span class="k-carousel__progress-bar" style="--_d: ${u}ms"></span></span>`),n.some(e=>e.hasAttribute(`data-thumb`))&&s.insertAdjacentHTML(`beforeend`,`<div class="k-carousel__thumbs" role="group" aria-label="${r(e.carousel.thumbnails(t))}">${n.map((t,a)=>`<button type="button" class="k-carousel__thumb" data-go="${a}" aria-label="${r(e.carousel.slideOf(i(this,a+1),i(this,n.length)))}" aria-controls="${this.key}-s${a}">${l[a]?`<img src="${r(l[a])}" alt="" loading="lazy">`:``}</button>`).join(``)}</div>`),this.pages>1||a){let n=this.getAttribute(`dots`)!==`false`&&this.pages>1,o=`${u&&this.pages>1?`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-act="play"></button>`:``}${a?`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-act="expand" aria-haspopup="dialog" aria-label="${r(e.carousel.expand)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3.5h4.5V8M8 16.5H3.5V12M16.5 3.5 11.5 8.5M3.5 16.5l5-5"/></svg></button>`:``}${this.pages>1?`<button type="button" class="k-btn k-btn--secondary k-btn--icon k-btn--sm" data-step="-1" aria-label="${r(e.common.prev)}">${m(!1)}</button><button type="button" class="k-btn k-btn--secondary k-btn--icon k-btn--sm" data-step="1" aria-label="${r(e.common.next)}">${m(!0)}</button>`:``}`;s.insertAdjacentHTML(`beforeend`,`<div class="k-carousel__bar">${n?`<ul class="k-carousel__dots" aria-label="${r(e.carousel.slides(t))}">${Array.from({length:this.pages},(t,n)=>`<li><button type="button" class="k-carousel__dot" data-go="${n}" aria-label="${r(e.carousel.slideOf(i(this,n+1),i(this,this.pages)))}" aria-controls="${this.key}-s${n}"></button></li>`).join(``)}</ul>`:`<span></span>`}<div class="k-carousel__nav">${o}</div></div>`)}s.addEventListener(`click`,e=>{let t=e.target.closest(`button`);if(t&&!this.box?.contains(t))return t.dataset.act===`play`?this.setPlaying(!this.playing):t.dataset.act===`expand`?this.openBox(this.index):t.dataset.go===void 0?t.dataset.step?this.go(this.index+Number(t.dataset.step)):void 0:this.go(Number(t.dataset.go));let n=e.target.closest(`.k-carousel__slide`);a&&n&&c.contains(n)&&!e.target.closest(`a, input, select, textarea, [tabindex]:not(.k-carousel__track)`)&&this.openBox(this.slides.indexOf(n))}),c.addEventListener(`keydown`,e=>{let t=g(c),n={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];n?(e.preventDefault(),this.go(this.index+n)):e.key===`Home`?this.go(0):e.key===`End`?this.go(this.pages-1):a&&e.key===`Enter`&&e.target===c&&this.openBox(this.index)}),this.fade?_(c,e=>this.go(this.index+e)):typeof IntersectionObserver<`u`&&(this.io=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting&&e.intersectionRatio>.6).map(e=>this.slides.indexOf(e.target));t.length&&this.setIndex(Math.min(...t))},{root:c,threshold:[.6,1]}),this.slides.forEach(e=>this.io.observe(e))),s.addEventListener(`mouseenter`,()=>this.hold(`hover`,!0)),s.addEventListener(`mouseleave`,()=>this.hold(`hover`,!1)),s.addEventListener(`focusin`,()=>this.hold(`focus`,!0)),s.addEventListener(`focusout`,e=>!s.contains(e.relatedTarget)&&this.hold(`focus`,!1)),document.addEventListener(`visibilitychange`,this.onVisibility),this.index=-1,this.setIndex(0),this.left=u,this.setPlaying(u>0&&!matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)}hold(e,t){t?this.holds.add(e):this.holds.delete(e),this.schedule()}setPlaying(e){this.playing=e;let t=this.querySelector(`[data-act="play"]`);t&&(t.innerHTML=h(e),t.setAttribute(`aria-label`,e?o().carousel.pause:o().carousel.play),t.setAttribute(`aria-pressed`,String(!e))),this.schedule()}schedule(){let e=this.interval>0&&this.pages>1&&this.playing&&this.holds.size===0;this.timer!==void 0&&(clearTimeout(this.timer),this.timer=void 0,this.left=Math.max(0,this.left-(Date.now()-this.startedAt))),this.track?.setAttribute(`aria-live`,e?`off`:`polite`),this.querySelector(`.k-carousel__progress-bar`)?.toggleAttribute(`data-paused`,!e),e&&(this.startedAt=Date.now(),this.timer=setTimeout(()=>{this.timer=void 0,this.go((this.index+1)%this.pages)},this.left))}go(e){let t=Math.max(0,Math.min(this.pages-1,e)),n=this.slides[t],r=this.track;if(n&&r){if(!this.fade){let e=g(r)?-(r.getBoundingClientRect().right-n.getBoundingClientRect().right)+r.scrollLeft:n.getBoundingClientRect().left-r.getBoundingClientRect().left+r.scrollLeft;r.scrollTo?.({left:e})}this.setIndex(t)}}setIndex(e){let n=e!==this.index;this.index=e,this.querySelectorAll(`.k-carousel__dot`).forEach((t,n)=>t.setAttribute(`aria-current`,String(n===e)));let r=this.querySelectorAll(`.k-carousel__thumb`);r.forEach((t,n)=>t.setAttribute(`aria-current`,String(n===e)));let i=this.querySelector(`.k-carousel__thumbs`),a=r[e];if(i&&a){let e=i.getBoundingClientRect(),t=a.getBoundingClientRect();(t.left<e.left||t.right>e.right)&&i.scrollTo?.({left:i.scrollLeft+(t.left+t.width/2)-(e.left+e.width/2)})}this.fade&&this.slides.forEach((t,n)=>{t.toggleAttribute(`data-active`,n===e),t.toggleAttribute(`inert`,n!==e),n===e?t.removeAttribute(`aria-hidden`):t.setAttribute(`aria-hidden`,`true`)});let[o,s]=this.querySelectorAll(`.k-carousel__bar [data-step]`);if(o&&(o.disabled=e===0),s&&(s.disabled=e>=this.pages-1),!n)return;let c=this.querySelector(`.k-carousel__progress-bar`);c&&c.replaceWith(c.cloneNode(!0)),this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.left=this.interval,this.section&&this.schedule(),t(this,`kashi-change`,{index:e})}openBox(e){let t=o();if(!this.box){let e=document.createElement(`dialog`);e.className=`k-carousel__lightbox`,e.setAttribute(`aria-label`,t.carousel.lightbox(this.getAttribute(`label`)??t.carousel.slider)),e.innerHTML=`<div class="k-carousel__lightbox-head"><span class="k-carousel__lightbox-count" aria-live="polite"></span><button type="button" class="k-btn k-btn--tertiary k-btn--icon" data-box="close" aria-label="${r(t.common.close)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="m5.5 5.5 9 9m0-9-9 9"/></svg></button></div><div class="k-carousel__lightbox-stage">${this.slides.map(e=>`<div class="k-carousel__lightbox-slide">${e.innerHTML}</div>`).join(``)}</div>${this.slides.length>1?`<div class="k-carousel__lightbox-nav"><button type="button" class="k-btn k-btn--secondary k-btn--icon" data-box="-1" aria-label="${r(t.common.prev)}">${m(!1)}</button><button type="button" class="k-btn k-btn--secondary k-btn--icon" data-box="1" aria-label="${r(t.common.next)}">${m(!0)}</button></div>`:``}`,e.querySelectorAll(`[id]`).forEach(e=>e.removeAttribute(`id`)),e.addEventListener(`click`,t=>{let n=t.target.closest(`[data-box]`);n?.dataset.box===`close`||t.target===e?e.close():n&&this.boxGo(this.boxIndex+Number(n.dataset.box))}),e.addEventListener(`keydown`,t=>{let n=g(e),r={ArrowLeft:n?1:-1,ArrowRight:n?-1:1}[t.key];r&&(t.preventDefault(),this.boxGo(this.boxIndex+r))}),e.addEventListener(`close`,()=>{this.hold(`box`,!1),this.go(Math.min(this.boxIndex,this.pages-1))}),_(e.querySelector(`.k-carousel__lightbox-stage`),e=>this.boxGo(this.boxIndex+e)),this.section.append(e),this.box=e}this.hold(`box`,!0),this.boxGo(e),this.box.showModal?.(),this.box.querySelector(`[data-box="close"]`)?.focus()}boxGo(e){let t=this.slides.length;this.boxIndex=(e+t)%t,this.box.querySelectorAll(`.k-carousel__lightbox-slide`).forEach((e,t)=>{e.toggleAttribute(`data-active`,t===this.boxIndex),e.toggleAttribute(`inert`,t!==this.boxIndex),t===this.boxIndex?e.removeAttribute(`aria-hidden`):e.setAttribute(`aria-hidden`,`true`)}),this.box.querySelector(`.k-carousel__lightbox-count`).textContent=o().carousel.slideOf(i(this,this.boxIndex+1),i(this,t))}};v.observedAttributes=[`label`,`per-view`,`dots`,`effect`,`autoplay`,`lightbox`];var y=class extends c{constructor(){super(...arguments),this.nodes=null,this.open=/* @__PURE__ */ new Set,this.sel=null,this.focusId=null,this.built=!1}connectedCallback(){s(()=>{if(this.isConnected){if(this.nodes===null){let e=this.querySelector(`:scope > ul`);this.nodes=e?this.parse(e):[]}if(!this.built){this.sel=this.getAttribute(`selected`);for(let e of(this.getAttribute(`expanded`)??``).split(/[,،]/).map(e=>e.trim()).filter(Boolean))this.open.add(e);this.built=!0}this.render()}})}attributeChangedCallback(e,t,n){this.built&&t!==n&&(e===`selected`&&(this.sel=n),this.render())}get items(){return this.nodes??[]}set items(e){this.nodes=e,this.built&&this.render()}get value(){return this.sel??``}parse(e){return[...e.children].filter(e=>e.tagName===`LI`).map((e,t)=>{let n=e.querySelector(`:scope > ul`),r=[...e.childNodes].filter(e=>e!==n).map(e=>e.textContent).join(``).trim(),i=e;return{id:i.dataset.id??`${r}-${t}`,label:r,meta:i.dataset.meta,disabled:i.hasAttribute(`data-disabled`),children:n?this.parse(n):void 0}})}visible(){let e=[],t=(n,r)=>{for(let i of n)e.push({node:i,parent:r}),i.children?.length&&this.open.has(i.id)&&t(i.children,i.id)};return t(this.items,null),e}render(e=!1){let t=this.visible(),n=this.focusId&&t.some(e=>e.node.id===this.focusId)?this.focusId:this.sel&&t.some(e=>e.node.id===this.sel)?this.sel:t[0]?.node.id,i=(e,t)=>e.map(e=>{let a=!!e.children?.length,o=this.open.has(e.id);return`<li role="treeitem" data-id="${r(e.id)}" class="k-tree__item" aria-level="${t}"${a?` aria-expanded="${o}"`:``} aria-selected="${this.sel===e.id}"${e.disabled?` aria-disabled="true"`:``} tabindex="${n===e.id?0:-1}"><div class="k-tree__row">${a?`<span class="k-tree__toggle" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 5 5 5-5 5"/></svg></span>`:`<span class="k-tree__spacer"></span>`}<span class="k-tree__label">${r(e.label)}</span>${e.meta?`<span class="k-tree__meta">${r(e.meta)}</span>`:``}</div>${a&&o?`<ul role="group">${i(e.children,t+1)}</ul>`:``}</li>`}).join(``);this.innerHTML=`<ul role="tree" class="k-tree"${this.getAttribute(`label`)?` aria-label="${r(this.getAttribute(`label`))}"`:``}>${i(this.items,1)}</ul>`;let a=this.querySelector(`ul`);a.addEventListener(`click`,e=>{let t=e.target.closest(`[role="treeitem"]`);if(!t||!e.target.closest(`.k-tree__row`))return;let n=this.find(t.dataset.id);n&&(n.children?.length&&this.toggle(n.id),this.focusId=n.id,this.choose(n))}),a.addEventListener(`keydown`,e=>this.onKey(e)),e&&n&&[...this.querySelectorAll(`[data-id]`)].find(e=>e.dataset.id===n)?.focus()}find(e,t=this.items){for(let n of t){if(n.id===e)return n;let t=n.children&&this.find(e,n.children);if(t)return t}return null}toggle(e,n=!this.open.has(e)){n?this.open.add(e):this.open.delete(e),t(this,`kashi-expand`,{expanded:[...this.open]})}choose(e){e.disabled||(this.sel=e.id,t(this,`kashi-change`,{value:e.id,node:e})),this.render(!0)}onKey(e){let t=this.visible(),n=document.activeElement?.dataset?.id,r=t.findIndex(e=>e.node.id===n),i=t[r];if(!i)return;let a=getComputedStyle(this).direction===`rtl`,o=!!i.node.children?.length,s=this.open.has(i.node.id),c=e=>{this.focusId=e,this.render(!0)};if(e.key===`ArrowDown`)t[r+1]&&c(t[r+1].node.id);else if(e.key===`ArrowUp`)t[r-1]&&c(t[r-1].node.id);else if(e.key===`Home`)c(t[0].node.id);else if(e.key===`End`)c(t[t.length-1].node.id);else if(e.key===(a?`ArrowLeft`:`ArrowRight`))o&&!s?(this.toggle(i.node.id,!0),c(i.node.id)):o&&c(i.node.children[0].id);else if(e.key===(a?`ArrowRight`:`ArrowLeft`))o&&s?(this.toggle(i.node.id,!1),c(i.node.id)):i.parent&&c(i.parent);else if(e.key===`Enter`||e.key===` `)this.focusId=i.node.id,this.choose(i.node);else return;e.preventDefault()}};y.observedAttributes=[`label`,`selected`,`expanded`];var b=class extends c{constructor(){super(...arguments),this.list=null,this.i=0,this.spot=null,this.card=null,this.returnTo=null,this.key=l(`kashi-tour`),this.place=()=>{let e=this.card;if(!e)return;let t=document.querySelector(this.steps[this.i].target)?.getBoundingClientRect()??null;t?(this.spot||(this.spot=document.createElement(`div`),this.spot.className=`k-tour__spot`,this.spot.setAttribute(`aria-hidden`,`true`),document.body.append(this.spot)),Object.assign(this.spot.style,{top:`${t.top-6}px`,left:`${t.left-6}px`,inlineSize:`${t.width+12}px`,blockSize:`${t.height+12}px`})):(this.spot?.remove(),this.spot=null);let n=e.getBoundingClientRect();if(!t){Object.assign(e.style,{top:`${innerHeight/2-n.height/2}px`,left:`${innerWidth/2-n.width/2}px`});return}let r=t.bottom+12+n.height<innerHeight?t.bottom+12:Math.max(12,t.top-12-n.height),i=Math.min(innerWidth-n.width-12,Math.max(12,t.left+t.width/2-n.width/2));Object.assign(e.style,{top:`${r}px`,left:`${i}px`})}}connectedCallback(){s(()=>{this.isConnected&&this.list===null&&(this.list=[...this.querySelectorAll(`:scope > [data-target]`)].map(e=>({target:e.dataset.target,title:e.dataset.title??``,content:e.textContent?.trim()??``})),this.replaceChildren())})}disconnectedCallback(){this.stop(!1)}get steps(){return this.list??[]}set steps(e){this.list=[...e]}start(){this.steps.length&&(this.returnTo=document.activeElement,this.i=0,addEventListener(`scroll`,this.place,{passive:!0}),addEventListener(`resize`,this.place),this.show())}stop(e=!0){this.spot?.remove(),this.card?.remove(),this.spot=this.card=null,removeEventListener(`scroll`,this.place),removeEventListener(`resize`,this.place),e&&this.returnTo?.focus?.()}show(){let e=this.steps[this.i],n=this.steps.length,a=this.i===n-1;this.card||(this.card=document.createElement(`div`),this.card.className=`k-tour__card`,this.card.setAttribute(`role`,`dialog`),this.card.setAttribute(`aria-modal`,`false`),this.card.setAttribute(`aria-labelledby`,`${this.key}-t`),this.card.setAttribute(`aria-describedby`,`${this.key}-b`),this.card.tabIndex=-1,this.card.addEventListener(`click`,e=>{let n=e.target.closest(`[data-act]`);if(!n)return;let r=n.dataset.act;r===`skip`?this.stop():r===`prev`?this.step(-1):r===`next`?this.step(1):r===`done`&&(this.stop(),t(this,`kashi-finish`,{}))}),this.card.addEventListener(`keydown`,e=>{let t=getComputedStyle(this.card).direction===`rtl`;e.key===`Escape`?this.stop():e.key===(t?`ArrowLeft`:`ArrowRight`)&&this.i<this.steps.length-1?this.step(1):e.key===(t?`ArrowRight`:`ArrowLeft`)&&this.i>0&&this.step(-1)}),document.body.append(this.card)),this.card.innerHTML=`<span class="k-tour__step">${r(o().tour.step(i(this,this.i+1),i(this,n)))}</span><p class="k-tour__title" id="${this.key}-t">${r(e.title)}</p><p class="k-tour__body" id="${this.key}-b">${r(e.content)}</p><div class="k-tour__actions"><button type="button" class="k-btn k-btn--link k-tour__skip" data-act="skip">${r(o().tour.skip)}</button><span class="k-tour__progress" aria-hidden="true">${this.steps.map((e,t)=>`<span${t<=this.i?` data-on=""`:``}></span>`).join(``)}</span>${this.i>0?'<button type="button" class="k-btn k-btn--secondary k-btn--sm" data-act="prev">${esc(msg().common.prev)}</button>':``}<button type="button" class="k-btn k-btn--primary k-btn--sm" data-act="${a?`done`:`next`}">${r(a?o().tour.done:o().common.next)}</button></div>`;let s=document.querySelector(e.target),c=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches;s?.scrollIntoView?.({block:`center`,behavior:c?`auto`:`smooth`}),this.place(),setTimeout(this.place,400),this.card.focus({preventScroll:!0})}step(e){this.i=Math.max(0,Math.min(this.steps.length-1,this.i+e)),this.show()}},x=class extends c{constructor(){super(...arguments),this.current=40,this.built=!1,this.dragging=!1}connectedCallback(){s(()=>{this.isConnected&&!this.built&&(this.current=this.num(`size`,40),this.build())})}attributeChangedCallback(e,t,n){this.built&&t!==n&&(e===`size`?this.set(Number(n)||40,!1):this.decorate())}get value(){return this.current}set value(e){this.set(e,!1)}num(e,t){let n=Number(this.getAttribute(e));return Number.isFinite(n)&&this.getAttribute(e)!==null?n:t}get vertical(){return this.getAttribute(`orientation`)===`vertical`}build(){let[e,t]=[...this.children],n=document.createElement(`div`),r=document.createElement(`div`);r.className=`k-splitter__pane`,e&&r.append(e);let i=document.createElement(`div`);i.className=`k-splitter__handle`,i.setAttribute(`role`,`separator`),i.tabIndex=0;let a=document.createElement(`div`);a.className=`k-splitter__pane`,t&&a.append(t),n.append(r,i,a),this.replaceChildren(n),this.built=!0,i.addEventListener(`pointerdown`,e=>{i.setPointerCapture?.(e.pointerId),this.dragging=!0,n.toggleAttribute(`data-dragging`,!0),i.toggleAttribute(`data-dragging`,!0)}),i.addEventListener(`pointermove`,e=>{if(!this.dragging)return;let t=n.getBoundingClientRect();if(this.vertical)return this.set((e.clientY-t.top)/t.height*100);let r=getComputedStyle(n).direction===`rtl`;this.set((r?t.right-e.clientX:e.clientX-t.left)/t.width*100)});let o=()=>{this.dragging=!1,n.removeAttribute(`data-dragging`),i.removeAttribute(`data-dragging`)};i.addEventListener(`pointerup`,o),i.addEventListener(`pointercancel`,o),i.addEventListener(`dblclick`,()=>this.set(this.num(`size`,40))),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,n=this.vertical?{ArrowUp:-5,ArrowDown:5}:{ArrowLeft:t?5:-5,ArrowRight:t?-5:5};if(e.key in n)this.set(this.current+n[e.key]);else if(e.key===`Home`)this.set(this.num(`min`,15));else if(e.key===`End`)this.set(this.num(`max`,85));else return;e.preventDefault()}),this.decorate()}decorate(){let e=this.firstElementChild;e.className=`k-splitter${this.vertical?` k-splitter--vertical`:``}`;let t=this.getAttribute(`height`);e.style.blockSize=t??``;let n=e.querySelector(`.k-splitter__handle`);n.setAttribute(`aria-orientation`,this.vertical?`horizontal`:`vertical`),n.setAttribute(`aria-valuemin`,String(this.num(`min`,15))),n.setAttribute(`aria-valuemax`,String(this.num(`max`,85))),n.setAttribute(`aria-label`,this.getAttribute(`label`)??o().splitter.label),this.paint()}set(e,n=!0){let r=Math.round(Math.min(this.num(`max`,85),Math.max(this.num(`min`,15),e))*10)/10,i=r!==this.current;this.current=r,this.built&&this.paint(),n&&i&&t(this,`kashi-change`,{value:r})}paint(){let e=this.firstElementChild,t=e.querySelector(`.k-splitter__pane`);t.style.inlineSize=this.vertical?``:`${this.current}%`,t.style.blockSize=this.vertical?`${this.current}%`:``;let n=e.querySelector(`.k-splitter__handle`);n.setAttribute(`aria-valuenow`,String(this.current)),n.setAttribute(`aria-valuetext`,o().common.percent(i(this,Math.round(this.current))))}};x.observedAttributes=[`size`,`min`,`max`,`orientation`,`label`,`height`];var S=class extends c{constructor(){super(...arguments),this.built=!1}connectedCallback(){s(()=>{this.isConnected&&!this.built&&(this.built=!0,this.addEventListener(`click`,e=>{let n=e.target.closest(`button[aria-controls][aria-expanded]`);if(!n||!this.contains(n))return;let r=document.getElementById(n.getAttribute(`aria-controls`)),i=n.getAttribute(`aria-expanded`)!==`true`;n.setAttribute(`aria-expanded`,String(i)),r&&(r.hidden=!i),t(this,`kashi-toggle`,{id:r?.id??``,open:i})}),this.decorate())})}attributeChangedCallback(){this.built&&this.decorate()}decorate(){let e=this.querySelector(`.k-sidenav`),t=n(this,`collapsed`);e?.classList.toggle(`k-sidenav--collapsed`,t),this.querySelectorAll(`.k-sidenav__item`).forEach(e=>{let n=e.querySelector(`.k-sidenav__text`)?.textContent?.trim();n&&(t?(e.setAttribute(`aria-label`,n),e.setAttribute(`title`,n)):(e.removeAttribute(`aria-label`),e.removeAttribute(`title`)))})}};S.observedAttributes=[`collapsed`],typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target,n=t?.closest?.(`[data-kashi-tour]`),r=n?document.getElementById(n.getAttribute(`data-kashi-tour`)):null;r?.start&&r.start();let i=t?.closest?.(`[data-kashi-command]`),a=i?document.getElementById(i.getAttribute(`data-kashi-command`)):null;a?.show&&a.show()}),a(`kashi-command-palette`,f,`contents`),a(`kashi-context-menu`,p,`block`),a(`kashi-carousel`,v,`block`),a(`kashi-tree-view`,y,`block`),a(`kashi-tour`,b,`contents`),a(`kashi-splitter`,x,`block`),a(`kashi-side-nav`,S,`block`);export{v as KashiCarousel,f as KashiCommandPalette,p as KashiContextMenu,S as KashiSideNav,x as KashiSplitter,b as KashiTour,y as KashiTreeView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,c as t,h as n,i as r,l as i,n as a,o,p as s,r as c,t as l,y as u}from"./base-BlPZs-0l.js";var d=class extends l{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=u(`kashi-dialog`)}connectedCallback(){c(()=>{this.isConnected&&(this.dialog||this.build(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.dialog?.open?this.dialog.close(e):this.open=!1}build(){let e=[...this.children].filter(e=>e.getAttribute(`slot`)===`footer`),n=[...this.childNodes].filter(t=>!e.includes(t)),i=document.createElement(`dialog`);if(i.setAttribute(`aria-labelledby`,`${this.key}-title`),i.innerHTML=`<div class="k-dialog__header"><div class="k-dialog__heading"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${a.close}</button></div>`,n.some(e=>e.nodeType===1||e.textContent?.trim())){let e=document.createElement(`div`);e.className=`k-dialog__body`,e.append(...n),i.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-dialog__footer`;for(let n of e)n.removeAttribute(`slot`),t.append(n);i.append(t)}this.replaceChildren(i),this.dialog=i,i.querySelector(`.k-dialog__close`).addEventListener(`click`,()=>this.close()),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close]`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:i.returnValue})}),this.decorate()}decorate(){let e=this.dialog,t=this.getAttribute(`size`)??`md`,n=this.getAttribute(`placement`)??`center`;e.className=[`k-dialog`,t!==`md`&&`k-dialog--${t}`,n!==`center`&&`k-dialog--${n}`,this.getAttribute(`tone`)===`danger`&&`k-dialog--danger`].filter(Boolean).join(` `),e.dataset.placement=n,e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let r=e.querySelector(`.k-dialog__description`),i=this.getAttribute(`description`);r.textContent=i??``,r.hidden=!i,i?e.setAttribute(`aria-describedby`,r.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`).setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().common.close)}sync(){let e=this.dialog;e&&this.isConnected&&(this.open&&!e.open?(this.opener=document.activeElement,e.showModal?.(),t(this,`kashi-open`,{})):!this.open&&e.open&&e.close())}};d.observedAttributes=[`open`,`heading`,`description`,`tone`,`size`,`placement`,`close-label`];var f=class extends l{constructor(){super(...arguments),this.list=null,this.key=u(`kashi-tabs`),this.ro=null}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){this.list||this.build(),this.decorate(),this.select(this.getAttribute(`value`)??this.panels[0]?.dataset.value??``,!1),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.list))}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`value`?this.select(n??``,!1):this.decorate())}get value(){return this.getAttribute(`value`)??``}set value(e){this.setAttribute(`value`,e)}get panels(){return[...this.children].filter(e=>e instanceof HTMLElement&&e.hasAttribute(`data-tab`))}build(){let e=document.createElement(`div`);e.setAttribute(`role`,`tablist`),e.className=`k-tabs__list`,this.panels.forEach((t,n)=>{let r=t.dataset.value||String(n+1);t.dataset.value=r;let i=document.createElement(`button`);i.type=`button`,i.setAttribute(`role`,`tab`),i.className=`k-tabs__tab`,i.id=`${this.key}-tab-${n}`,i.dataset.value=r,i.textContent=t.dataset.tab??``,t.hasAttribute(`data-disabled`)&&(i.disabled=!0),t.id||=`${this.key}-panel-${n}`,i.setAttribute(`aria-controls`,t.id),t.setAttribute(`role`,`tabpanel`),t.setAttribute(`aria-labelledby`,i.id),t.tabIndex=0,t.classList.add(`k-tabs__panel`),e.append(i)});let t=document.createElement(`span`);t.className=`k-tabs__indicator`,t.setAttribute(`aria-hidden`,`true`),e.append(t),e.addEventListener(`click`,e=>{let t=e.target.closest(`[role="tab"]`);t&&!t.disabled&&this.select(t.dataset.value,!0)}),e.addEventListener(`keydown`,e=>this.onKey(e)),this.prepend(e),this.list=e}decorate(){let e=this.getAttribute(`variant`)??`line`,t=this.getAttribute(`orientation`)===`vertical`;for(let e of[...this.classList])e.startsWith(`k-tabs`)&&this.classList.remove(e);this.classList.add(`k-tabs`,`k-tabs--${e}`),r(this,`block`)&&this.classList.add(`k-tabs--block`),t&&this.classList.add(`k-tabs--vertical`),this.getAttribute(`size`)===`sm`&&this.classList.add(`k-tabs--sm`),this.dataset.orientation=t?`vertical`:`horizontal`,this.list.setAttribute(`aria-orientation`,t?`vertical`:`horizontal`);let n=this.getAttribute(`label`);n&&this.list.setAttribute(`aria-label`,n),this.measure()}select(e,n){let r=[...this.list.querySelectorAll(`[role="tab"]`)];r.some(t=>t.dataset.value===e)||(e=r[0]?.dataset.value??``);for(let t of r){let n=t.dataset.value===e;t.setAttribute(`aria-selected`,String(n)),t.tabIndex=n?0:-1}for(let t of this.panels)t.hidden=t.dataset.value!==e;this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e),this.measure(),n&&t(this,`kashi-change`,{value:e})}measure(){let e=this.list,t=e?.querySelector(`[role="tab"][aria-selected="true"]`);!e||!t||!t.offsetWidth?e?.removeAttribute(`data-indicator`):(e.setAttribute(`data-indicator`,``),e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iy`,`${t.offsetTop}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.style.setProperty(`--_ih`,`${t.offsetHeight}px`))}onKey(e){let t=[...this.list.querySelectorAll(`[role="tab"]:not(:disabled)`)],n=t.indexOf(document.activeElement);if(n<0)return;let r=getComputedStyle(this.list).direction===`rtl`,i=this.getAttribute(`orientation`)===`vertical`?{ArrowDown:n+1,ArrowUp:n-1,Home:0,End:t.length-1}:{ArrowLeft:r?n+1:n-1,ArrowRight:r?n-1:n+1,Home:0,End:t.length-1};if(!(e.key in i))return;e.preventDefault();let a=t[(i[e.key]+t.length)%t.length];a.focus(),this.select(a.dataset.value,!0)}};f.observedAttributes=[`value`,`variant`,`block`,`orientation`,`size`,`label`];var p=class extends l{constructor(){super(...arguments),this.tip=null,this.key=u(`kashi-tip`),this.place=()=>n(this,this.tip,this.getAttribute(`placement`)||`top`),this.onKey=e=>{e.key===`Escape`&&(clearTimeout(this.timer),this.close())}}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){if(!this.tip){this.classList.add(`k-tooltip-anchor`);let e=document.createElement(`span`);e.setAttribute(`role`,`tooltip`),e.id=this.key,e.hidden=!0,e.setAttribute(`popover`,`manual`),this.append(e),this.tip=e;let t=this.firstElementChild===e?null:this.firstElementChild;t&&t.setAttribute(`aria-describedby`,[t.getAttribute(`aria-describedby`),this.key].filter(Boolean).join(` `)),this.addEventListener(`mouseenter`,()=>this.show(Number(this.getAttribute(`delay`)??300))),this.addEventListener(`mouseleave`,()=>this.hide()),this.addEventListener(`focusin`,()=>this.show(0)),this.addEventListener(`focusout`,()=>this.hide())}this.decorate()}disconnectedCallback(){clearTimeout(this.timer),this.close()}attributeChangedCallback(){this.tip&&this.decorate(),this.tip&&!this.tip.hidden&&this.place()}open(){let e=this.tip;e.hidden&&(e.hidden=!1,this.place(),document.addEventListener(`keydown`,this.onKey),addEventListener(`scroll`,this.place,{capture:!0,passive:!0}),addEventListener(`resize`,this.place))}close(){this.tip&&(this.tip.hidden=!0,e(this.tip),document.removeEventListener(`keydown`,this.onKey),removeEventListener(`scroll`,this.place,{capture:!0}),removeEventListener(`resize`,this.place))}decorate(){let e=this.getAttribute(`placement`);this.tip.className=`k-tooltip${e&&e!==`top`?` k-tooltip--${e}`:``}`,this.tip.textContent=this.getAttribute(`content`)??``}show(e){clearTimeout(this.timer),this.timer=setTimeout(()=>this.open(),e)}hide(){clearTimeout(this.timer),this.timer=setTimeout(()=>this.close(),100)}};p.observedAttributes=[`content`,`placement`];var m=class extends l{constructor(){super(...arguments),this.state=`idle`,this.built=!1}connectedCallback(){this.built||(this.built=!0,this.addEventListener(`click`,e=>{e.target.closest(`button`)&&this.copy()})),this.render()}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(){this.built&&this.render()}get text(){let e=this.getAttribute(`value`);if(e!==null)return e;let t=this.getAttribute(`target`),n=t?document.querySelector(t):null;return n?typeof n.value==`string`?n.value:(n.textContent??``).trim():``}async copy(){try{await navigator.clipboard.writeText(this.text),this.state=`copied`,t(this,`kashi-copy`,{value:this.text})}catch{this.state=`failed`}this.render(),clearTimeout(this.timer),this.timer=setTimeout(()=>{this.state=`idle`,this.render()},Number(this.getAttribute(`timeout`))||2e3)}render(){let e=this.getAttribute(`label`)??s().copy.copy,t=this.getAttribute(`copied-label`)??s().copy.copied,n=this.state===`copied`?t:this.state===`failed`?s().copy.failed:e,o=r(this,`icon-only`),c=this.state===`copied`?a.check:a.copy,l=this.getAttribute(`variant`)??`secondary`,u=this.getAttribute(`size`)??`sm`,d=this.contains(document.activeElement);this.innerHTML=`<button type="button" class="k-btn k-btn--${i(l)}${u===`md`?``:` k-btn--${i(u)}`}${o?` k-btn--icon`:``}" data-variant="${i(l)}" data-size="${i(u)}"${o?` aria-label="${i(n)}"`:``}${this.state===`copied`?` data-copied=""`:``}>${c}${o?``:i(n)}</button><span class="k-sr-only" aria-live="polite">${this.state===`idle`?``:i(n)}</span>`,d&&this.querySelector(`button`).focus()}};m.observedAttributes=[`value`,`target`,`label`,`copied-label`,`icon-only`,`variant`,`size`],o(`kashi-dialog`,d,`contents`),o(`kashi-tabs`,f,`block`),o(`kashi-tooltip`,p),o(`kashi-copy-button`,m),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(t){let n=document.getElementById(t.getAttribute(`data-kashi-open`));n?.show&&(e.preventDefault(),n.show())}});export{m as KashiCopyButton,d as KashiDialog,f as KashiTabs,p as KashiTooltip};
|
|
1
|
+
import{b as e,c as t,h as n,i as r,l as i,n as a,o,p as s,r as c,t as l,y as u}from"./base-w2Oo_bN6.js";var d=class extends l{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=u(`kashi-dialog`)}connectedCallback(){c(()=>{this.isConnected&&(this.dialog||this.build(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.dialog?.open?this.dialog.close(e):this.open=!1}build(){let e=[...this.children].filter(e=>e.getAttribute(`slot`)===`footer`),n=[...this.childNodes].filter(t=>!e.includes(t)),i=document.createElement(`dialog`);if(i.setAttribute(`aria-labelledby`,`${this.key}-title`),i.innerHTML=`<div class="k-dialog__header"><div class="k-dialog__heading"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${a.close}</button></div>`,n.some(e=>e.nodeType===1||e.textContent?.trim())){let e=document.createElement(`div`);e.className=`k-dialog__body`,e.append(...n),i.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-dialog__footer`;for(let n of e)n.removeAttribute(`slot`),t.append(n);i.append(t)}this.replaceChildren(i),this.dialog=i,i.querySelector(`.k-dialog__close`).addEventListener(`click`,()=>this.close()),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close]`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:i.returnValue})}),this.decorate()}decorate(){let e=this.dialog,t=this.getAttribute(`size`)??`md`,n=this.getAttribute(`placement`)??`center`;e.className=[`k-dialog`,t!==`md`&&`k-dialog--${t}`,n!==`center`&&`k-dialog--${n}`,this.getAttribute(`tone`)===`danger`&&`k-dialog--danger`].filter(Boolean).join(` `),e.dataset.placement=n,e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let r=e.querySelector(`.k-dialog__description`),i=this.getAttribute(`description`);r.textContent=i??``,r.hidden=!i,i?e.setAttribute(`aria-describedby`,r.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`).setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().common.close)}sync(){let e=this.dialog;e&&this.isConnected&&(this.open&&!e.open?(this.opener=document.activeElement,e.showModal?.(),t(this,`kashi-open`,{})):!this.open&&e.open&&e.close())}};d.observedAttributes=[`open`,`heading`,`description`,`tone`,`size`,`placement`,`close-label`];var f=class extends l{constructor(){super(...arguments),this.list=null,this.key=u(`kashi-tabs`),this.ro=null}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){this.list||this.build(),this.decorate(),this.select(this.getAttribute(`value`)??this.panels[0]?.dataset.value??``,!1),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.list))}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`value`?this.select(n??``,!1):this.decorate())}get value(){return this.getAttribute(`value`)??``}set value(e){this.setAttribute(`value`,e)}get panels(){return[...this.children].filter(e=>e instanceof HTMLElement&&e.hasAttribute(`data-tab`))}build(){let e=document.createElement(`div`);e.setAttribute(`role`,`tablist`),e.className=`k-tabs__list`,this.panels.forEach((t,n)=>{let r=t.dataset.value||String(n+1);t.dataset.value=r;let i=document.createElement(`button`);i.type=`button`,i.setAttribute(`role`,`tab`),i.className=`k-tabs__tab`,i.id=`${this.key}-tab-${n}`,i.dataset.value=r,i.textContent=t.dataset.tab??``,t.hasAttribute(`data-disabled`)&&(i.disabled=!0),t.id||=`${this.key}-panel-${n}`,i.setAttribute(`aria-controls`,t.id),t.setAttribute(`role`,`tabpanel`),t.setAttribute(`aria-labelledby`,i.id),t.tabIndex=0,t.classList.add(`k-tabs__panel`),e.append(i)});let t=document.createElement(`span`);t.className=`k-tabs__indicator`,t.setAttribute(`aria-hidden`,`true`),e.append(t),e.addEventListener(`click`,e=>{let t=e.target.closest(`[role="tab"]`);t&&!t.disabled&&this.select(t.dataset.value,!0)}),e.addEventListener(`keydown`,e=>this.onKey(e)),this.prepend(e),this.list=e}decorate(){let e=this.getAttribute(`variant`)??`line`,t=this.getAttribute(`orientation`)===`vertical`;for(let e of[...this.classList])e.startsWith(`k-tabs`)&&this.classList.remove(e);this.classList.add(`k-tabs`,`k-tabs--${e}`),r(this,`block`)&&this.classList.add(`k-tabs--block`),t&&this.classList.add(`k-tabs--vertical`),this.getAttribute(`size`)===`sm`&&this.classList.add(`k-tabs--sm`),this.dataset.orientation=t?`vertical`:`horizontal`,this.list.setAttribute(`aria-orientation`,t?`vertical`:`horizontal`);let n=this.getAttribute(`label`);n&&this.list.setAttribute(`aria-label`,n),this.measure()}select(e,n){let r=[...this.list.querySelectorAll(`[role="tab"]`)];r.some(t=>t.dataset.value===e)||(e=r[0]?.dataset.value??``);for(let t of r){let n=t.dataset.value===e;t.setAttribute(`aria-selected`,String(n)),t.tabIndex=n?0:-1}for(let t of this.panels)t.hidden=t.dataset.value!==e;this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e),this.measure(),n&&t(this,`kashi-change`,{value:e})}measure(){let e=this.list,t=e?.querySelector(`[role="tab"][aria-selected="true"]`);!e||!t||!t.offsetWidth?e?.removeAttribute(`data-indicator`):(e.setAttribute(`data-indicator`,``),e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iy`,`${t.offsetTop}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.style.setProperty(`--_ih`,`${t.offsetHeight}px`))}onKey(e){let t=[...this.list.querySelectorAll(`[role="tab"]:not(:disabled)`)],n=t.indexOf(document.activeElement);if(n<0)return;let r=getComputedStyle(this.list).direction===`rtl`,i=this.getAttribute(`orientation`)===`vertical`?{ArrowDown:n+1,ArrowUp:n-1,Home:0,End:t.length-1}:{ArrowLeft:r?n+1:n-1,ArrowRight:r?n-1:n+1,Home:0,End:t.length-1};if(!(e.key in i))return;e.preventDefault();let a=t[(i[e.key]+t.length)%t.length];a.focus(),this.select(a.dataset.value,!0)}};f.observedAttributes=[`value`,`variant`,`block`,`orientation`,`size`,`label`];var p=class extends l{constructor(){super(...arguments),this.tip=null,this.key=u(`kashi-tip`),this.place=()=>n(this,this.tip,this.getAttribute(`placement`)||`top`),this.onKey=e=>{e.key===`Escape`&&(clearTimeout(this.timer),this.close())}}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){if(!this.tip){this.classList.add(`k-tooltip-anchor`);let e=document.createElement(`span`);e.setAttribute(`role`,`tooltip`),e.id=this.key,e.hidden=!0,e.setAttribute(`popover`,`manual`),this.append(e),this.tip=e;let t=this.firstElementChild===e?null:this.firstElementChild;t&&t.setAttribute(`aria-describedby`,[t.getAttribute(`aria-describedby`),this.key].filter(Boolean).join(` `)),this.addEventListener(`mouseenter`,()=>this.show(Number(this.getAttribute(`delay`)??300))),this.addEventListener(`mouseleave`,()=>this.hide()),this.addEventListener(`focusin`,()=>this.show(0)),this.addEventListener(`focusout`,()=>this.hide())}this.decorate()}disconnectedCallback(){clearTimeout(this.timer),this.close()}attributeChangedCallback(){this.tip&&this.decorate(),this.tip&&!this.tip.hidden&&this.place()}open(){let e=this.tip;e.hidden&&(e.hidden=!1,this.place(),document.addEventListener(`keydown`,this.onKey),addEventListener(`scroll`,this.place,{capture:!0,passive:!0}),addEventListener(`resize`,this.place))}close(){this.tip&&(this.tip.hidden=!0,e(this.tip),document.removeEventListener(`keydown`,this.onKey),removeEventListener(`scroll`,this.place,{capture:!0}),removeEventListener(`resize`,this.place))}decorate(){let e=this.getAttribute(`placement`);this.tip.className=`k-tooltip${e&&e!==`top`?` k-tooltip--${e}`:``}`,this.tip.textContent=this.getAttribute(`content`)??``}show(e){clearTimeout(this.timer),this.timer=setTimeout(()=>this.open(),e)}hide(){clearTimeout(this.timer),this.timer=setTimeout(()=>this.close(),100)}};p.observedAttributes=[`content`,`placement`];var m=class extends l{constructor(){super(...arguments),this.state=`idle`,this.built=!1}connectedCallback(){this.built||(this.built=!0,this.addEventListener(`click`,e=>{e.target.closest(`button`)&&this.copy()})),this.render()}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(){this.built&&this.render()}get text(){let e=this.getAttribute(`value`);if(e!==null)return e;let t=this.getAttribute(`target`),n=t?document.querySelector(t):null;return n?typeof n.value==`string`?n.value:(n.textContent??``).trim():``}async copy(){try{await navigator.clipboard.writeText(this.text),this.state=`copied`,t(this,`kashi-copy`,{value:this.text})}catch{this.state=`failed`}this.render(),clearTimeout(this.timer),this.timer=setTimeout(()=>{this.state=`idle`,this.render()},Number(this.getAttribute(`timeout`))||2e3)}render(){let e=this.getAttribute(`label`)??s().copy.copy,t=this.getAttribute(`copied-label`)??s().copy.copied,n=this.state===`copied`?t:this.state===`failed`?s().copy.failed:e,o=r(this,`icon-only`),c=this.state===`copied`?a.check:a.copy,l=this.getAttribute(`variant`)??`secondary`,u=this.getAttribute(`size`)??`sm`,d=this.contains(document.activeElement);this.innerHTML=`<button type="button" class="k-btn k-btn--${i(l)}${u===`md`?``:` k-btn--${i(u)}`}${o?` k-btn--icon`:``}" data-variant="${i(l)}" data-size="${i(u)}"${o?` aria-label="${i(n)}"`:``}${this.state===`copied`?` data-copied=""`:``}>${c}${o?``:i(n)}</button><span class="k-sr-only" aria-live="polite">${this.state===`idle`?``:i(n)}</span>`,d&&this.querySelector(`button`).focus()}};m.observedAttributes=[`value`,`target`,`label`,`copied-label`,`icon-only`,`variant`,`size`],o(`kashi-dialog`,d,`contents`),o(`kashi-tabs`,f,`block`),o(`kashi-tooltip`,p),o(`kashi-copy-button`,m),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(t){let n=document.getElementById(t.getAttribute(`data-kashi-open`));n?.show&&(e.preventDefault(),n.show())}});export{m as KashiCopyButton,d as KashiDialog,f as KashiTabs,p as KashiTooltip};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,E as t,M as n,O as r,S as i,T as a,_ as o,a as s,c,d as l,f as u,i as d,l as f,m as p,n as m,o as h,p as g,s as _,t as v,u as y,x as b,y as x}from"./base-BlPZs-0l.js";import"./calendar-DftXi3uh.js";const S=e=>e?i(e.trim())??a(e):null,C=(e,t=0)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),w=(e,t)=>!e&&!t||!!e&&!!t&&e.getTime()===t.getTime(),T=[[(e,t)=>e.last7(t(7)),e=>({start:C(e,-6),end:e})],[(e,t)=>e.last30(t(30)),e=>({start:C(e,-29),end:e})],[e=>e.thisMonth,e=>{let{jy:n,jm:i}=r(e);return{start:t(n,i,1),end:e}}],[e=>e.lastMonth,e=>{let{jy:n,jm:i}=r(e),[a,o]=i===1?[n-1,12]:[n,i-1];return{start:t(a,o,1),end:C(t(n,i,1),-1)}}]];var E=class extends v{constructor(){super(...arguments),this.current={start:null,end:null},this.draft={start:null,end:null},this.valueSet=!1,this.rendered=!1,this.key=x(`kashi-range`),this.pop=null,this.onOutside=e=>{this.contains(e.target)||this.close(!1)}}connectedCallback(){!this.rendered&&!this.valueSet&&(this.current={start:S(this.getAttribute(`start`)),end:S(this.getAttribute(`end`))}),this.render()}disconnectedCallback(){this.close(!1)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&((e===`start`||e===`end`)&&(this.current={...this.current,[e]:S(n)}),this.render())}get value(){return{...this.current}}set value(e){this.valueSet=!0,this.current={start:e?.start??null,end:e?.end??null},this.rendered&&this.render()}fmt(e){return b(e,{digits:_(this),locale:l()})}text(e){return e.start&&e.end?`${this.fmt(e.start)}${g().common.range}${this.fmt(e.end)}`:null}render(){this.close(!1);let t=this.key,n=this.getAttribute(`label`)??g().dateRange.label,r=this.text(this.current),i=`<div class="k-datepicker k-daterange"><div class="k-select"><button id="${t}" type="button" class="k-select__control k-daterange__trigger" aria-haspopup="dialog" aria-expanded="false"${r?``:` data-placeholder=""`}${this.hasAttribute(`disabled`)?` disabled`:``}>${m.calendar}<span>${f(r??this.getAttribute(`placeholder`)??g().dateRange.placeholder)}</span></button></div></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,y({id:t,label:n,control:i})),this.trigger=this.querySelector(`.k-daterange__trigger`),this.trigger.addEventListener(`click`,()=>this.pop?this.close():this.open()),this.rendered=!0,o(this.querySelector(`:scope > .k-field`),this.trigger,t,this.getAttribute(`error`),this.getAttribute(`hint`));let a=this.getAttribute(`name`);if(this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),a)for(let[t,n]of[[`start`,this.current.start],[`end`,this.current.end]])this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(`${a}_${t}`)}" value="${n?e(n):``}">`)}open(){if(this.pop||this.hasAttribute(`disabled`))return;this.draft={...this.current};let t=this.querySelector(`.k-daterange`),n=document.createElement(`div`);n.id=`${this.key}-popover`,n.className=`k-datepicker__popover k-daterange__popover`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-label`,this.getAttribute(`label`)??g().dateRange.placeholder);let r=this.getAttribute(`presets`)===`false`?[]:T;n.innerHTML=`${r.length?`<ul class="k-daterange__presets" role="list" aria-label="${f(g().dateRange.presets)}">${r.map(([e],t)=>`<li><button type="button" class="k-daterange__preset" data-preset="${t}" aria-pressed="false">${f(e(g().dateRange,e=>p(this,e)))}</button></li>`).join(``)}</ul>`:``}<div class="k-daterange__main"><div class="k-daterange__footer"><span class="k-daterange__summary" aria-live="polite"></span><button type="button" class="k-btn k-btn--secondary k-btn--sm" data-cancel>${f(g().common.cancel)}</button><button type="button" class="k-btn k-btn--primary k-btn--sm" data-apply>${f(g().common.confirm)}</button></div></div>`;let i=document.createElement(`kashi-calendar`);for(let e of[`min`,`max`,`digits`,`holidays`]){let t=this.getAttribute(e);t!==null&&i.setAttribute(e,t)}i.range=this.draft,n.querySelector(`.k-daterange__main`).prepend(i),i.addEventListener(`kashi-change`,e=>{e.stopPropagation();let t=e.detail.date,n=this.draft;this.draft=!n.start||n.end?{start:t,end:null}:t<n.start?{start:t,end:n.start}:{start:n.start,end:t},i.range=this.draft,this.paintDraft()}),n.addEventListener(`click`,t=>{let n=t.target,a=n.closest(`[data-preset]`);if(a)this.draft=r[Number(a.dataset.preset)][1](C(/* @__PURE__ */ new Date)),i.range=this.draft,this.paintDraft();else if(n.closest(`[data-cancel]`))this.close();else if(n.closest(`[data-apply]`)&&this.draft.start&&this.draft.end){let t=!w(this.draft.start,this.current.start)||!w(this.draft.end,this.current.end);this.current={...this.draft},this.close(),this.render(),this.trigger.focus(),t&&c(this,`kashi-change`,{start:this.current.start,end:this.current.end,value:{start:e(this.current.start),end:e(this.current.end)}})}}),n.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.close())}),t.append(n),this.pop=n,this.trigger.setAttribute(`aria-expanded`,`true`),this.trigger.setAttribute(`aria-controls`,n.id),document.addEventListener(`pointerdown`,this.onOutside),this.paintDraft(),i.focus()}paintDraft(){let e=this.pop,t=this.draft;e.querySelector(`.k-daterange__summary`).textContent=this.text(t)??(t.start?g().dateRange.pickEnd:``),e.querySelector(`[data-apply]`).disabled=!t.start||!t.end;let n=C(/* @__PURE__ */ new Date);e.querySelectorAll(`[data-preset]`).forEach((e,r)=>{let i=T[r][1](n);e.setAttribute(`aria-pressed`,String(w(t.start,i.start)&&w(t.end,i.end)))})}close(e=!0){this.pop&&(this.pop.remove(),this.pop=null,document.removeEventListener(`pointerdown`,this.onOutside),this.trigger.setAttribute(`aria-expanded`,`false`),this.trigger.removeAttribute(`aria-controls`),e&&this.trigger.focus())}};E.observedAttributes=[`label`,`hint`,`error`,`start`,`end`,`min`,`max`,`holidays`,`digits`,`name`,`disabled`,`presets`,`placeholder`];const D=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-k-mirror=""><path d="${e?`m8 5 5 5-5 5`:`m12 5-5 5 5 5`}"/></svg>`;var O=class extends v{constructor(){super(...arguments),this.selected=null,this.year=r(/* @__PURE__ */ new Date).jy,this.focusMonth=1,this.valueSet=!1,this.rendered=!1}connectedCallback(){if(!this.rendered){this.valueSet||(this.selected=this.parse(this.getAttribute(`value`)));let e=r(/* @__PURE__ */ new Date);this.year=this.selected?.year??e.jy,this.focusMonth=this.selected?.month??(this.year===e.jy?e.jm:1)}this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}parse(e){let t=(e??``).trim().match(/^(\d{4})[-/](\d{1,2})$/);return t?{year:Number(t[1]),month:Number(t[2])}:null}get value(){return this.selected?`${this.selected.year}-${String(this.selected.month).padStart(2,`0`)}`:``}set value(e){this.valueSet=!0,this.selected=this.parse(e),this.selected&&([this.year,this.focusMonth]=[this.selected.year,this.selected.month]),this.rendered&&this.render()}out(e,t){let n=e*12+t,r=this.parse(this.getAttribute(`min`)),i=this.parse(this.getAttribute(`max`));return!!r&&n<r.year*12+r.month||!!i&&n>i.year*12+i.month}render(e=!1){let t=e=>_(this)===`latin`?String(e):n(String(e)),i=r(/* @__PURE__ */ new Date),a=this.parse(this.getAttribute(`min`)),o=this.parse(this.getAttribute(`max`)),l=this.year;this.innerHTML=`<div class="k-monthpicker" role="group" aria-label="${f(this.getAttribute(`label`)??g().monthPicker.label)}"><div class="k-monthpicker__header"><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-year="-1" aria-label="${f(g().monthPicker.prevYear)}"${a&&l<=a.year?` disabled`:``}>${D(!1)}</button><span class="k-monthpicker__year" aria-live="polite">${t(l)}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-year="1" aria-label="${f(g().monthPicker.nextYear)}"${o&&l>=o.year?` disabled`:``}>${D(!0)}</button></div><div class="k-monthpicker__grid">${s().months.map((e,n)=>`<button type="button" data-month="${n+1}" class="k-monthpicker__month" tabindex="${this.focusMonth===n+1?0:-1}" aria-pressed="${this.selected?.year===l&&this.selected.month===n+1}" aria-label="${e} ${t(l)}"${i.jy===l&&i.jm===n+1?` aria-current="date"`:``}${this.out(l,n+1)?` disabled`:``}>${e}</button>`).join(``)}</div></div>`;let u=this.getAttribute(`name`);u&&this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(u)}" value="${this.value}">`),this.rendered=!0,this.querySelectorAll(`[data-year]`).forEach(e=>e.addEventListener(`click`,()=>{this.year+=Number(e.dataset.year),this.render()}));let d=this.querySelector(`.k-monthpicker__grid`);d.addEventListener(`click`,e=>{let t=e.target.closest(`[data-month]`);t&&!t.disabled&&(this.selected={year:this.year,month:Number(t.dataset.month)},this.focusMonth=this.selected.month,this.render(!0),c(this,`kashi-change`,{value:this.value,year:this.selected.year,month:this.selected.month}))}),d.addEventListener(`keydown`,e=>{let t=getComputedStyle(d).direction===`rtl`,n={ArrowRight:t?-1:1,ArrowLeft:t?1:-1,ArrowDown:3,ArrowUp:-3,PageUp:-12,PageDown:12},r=this.year*12+this.focusMonth-1;if(e.key in n)r+=n[e.key];else if(e.key===`Home`)r=this.year*12;else if(e.key===`End`)r=this.year*12+11;else return;e.preventDefault(),this.year=Math.floor(r/12),this.focusMonth=r%12+1,this.render(!0)}),e&&this.querySelector(`[data-month="${this.focusMonth}"]`)?.focus()}};O.observedAttributes=[`value`,`min`,`max`,`digits`,`label`,`name`];function k(e){let t=g().fileUpload.units,r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i++;let a=i===0?String(r):r.toFixed(+(r<10)).replace(/\.0$/,``);return`${u()===`fa`?n(a).replace(`.`,`٫`):a} ${t[i]}`}async function A(e,{maxDimension:t,quality:n=.85,type:r}){if(!/^image\/(jpeg|png|webp)$/.test(e.type)||typeof createImageBitmap!=`function`)return null;let i;try{i=await createImageBitmap(e,{imageOrientation:`from-image`})}catch{return null}let a=Math.min(1,t/Math.max(i.width,i.height));if(a>=1)return i.close?.(),null;let o=Math.round(i.width*a),s=Math.round(i.height*a),c=r??e.type,l=null;try{if(typeof OffscreenCanvas<`u`){let e=new OffscreenCanvas(o,s),t=e.getContext(`2d`);t.imageSmoothingQuality=`high`,t.drawImage(i,0,0,o,s),l=await e.convertToBlob({type:c,quality:n})}else{let e=document.createElement(`canvas`);e.width=o,e.height=s;let t=e.getContext(`2d`);t.imageSmoothingQuality=`high`,t.drawImage(i,0,0,o,s),l=await new Promise(t=>e.toBlob(t,c,n))}}finally{i.close?.()}if(!l||l.size>=e.size)return null;let u=c===e.type?e.name:`${e.name.replace(/\.[^.]+$/,``)}.${c===`image/jpeg`?`jpg`:c.split(`/`)[1]}`;return{file:new File([l],u,{type:c,lastModified:e.lastModified}),width:o,height:s}}var j=class extends v{constructor(){super(...arguments),this.items=[],this.rendered=!1,this.key=x(`kashi-upload`)}connectedCallback(){this.rendered||this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&this.render()}get files(){return this.items.filter(e=>e.status!==`error`).map(e=>e.file)}get multiple(){return d(this,`multiple`,!0)}render(){let e=this.key,t=this.getAttribute(`hint`),n=this.hasAttribute(`disabled`),r=this.getAttribute(`name`),i=this.getAttribute(`accept`);this.innerHTML=`<div class="k-dropzone"${n?` data-disabled=""`:``}><span class="k-dropzone__icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13V3.5m-4 4 4-4 4 4M4 13v2.5A1.5 1.5 0 0 0 5.5 17h9a1.5 1.5 0 0 0 1.5-1.5V13"/></svg></span><p class="k-dropzone__title" style="margin: 0"><button type="button" class="k-dropzone__browse"${n?` disabled`:``}${t?` aria-describedby="${e}-hint"`:``}>${f(this.getAttribute(`label`)??g().fileUpload.browse)}</button> <span>${f(g().fileUpload.drop)}</span></p>${t?`<p class="k-dropzone__hint" id="${e}-hint" style="margin: 0">${f(t)}</p>`:``}<input type="file" tabindex="-1" aria-hidden="true"${i?` accept="${f(i)}"`:``}${this.multiple?` multiple`:``}${r?` name="${f(r)}"`:``}${this.hasAttribute(`required`)?` required`:``}></div><ul class="k-file-list" role="list" hidden></ul><span class="k-sr-only" aria-live="polite"></span>`,this.rendered=!0,this.input=this.querySelector(`input[type=file]`);let a=this.querySelector(`.k-dropzone`);this.querySelector(`.k-dropzone__browse`).addEventListener(`click`,()=>this.input.click()),this.input.addEventListener(`change`,()=>{this.input.files?.length&&this.add([...this.input.files])}),this.input.addEventListener(`invalid`,()=>a.setAttribute(`data-invalid`,``)),a.addEventListener(`dragover`,e=>{e.preventDefault(),n||a.setAttribute(`data-dragging`,``)}),a.addEventListener(`dragleave`,e=>{a.contains(e.relatedTarget)||a.removeAttribute(`data-dragging`)}),a.addEventListener(`drop`,e=>{e.preventDefault(),a.removeAttribute(`data-dragging`),!n&&e.dataTransfer?.files.length&&this.add([...e.dataTransfer.files])}),this.querySelector(`.k-file-list`).addEventListener(`click`,e=>{let t=e.target.closest(`[data-remove]`);if(!t)return;let n=this.items.find(e=>e.id===t.dataset.remove);n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),this.items=this.items.filter(e=>e.id!==t.dataset.remove),this.announce(g().common.removed(n?.file.name??``)),this.changed()}),this.paint()}accepts(e){let t=this.getAttribute(`accept`);return!t||t.split(`,`).map(e=>e.trim().toLowerCase()).some(t=>t.startsWith(`.`)?e.name.toLowerCase().endsWith(t):t.endsWith(`/*`)?e.type.startsWith(t.slice(0,-1)):e.type===t)}add(e){let t=Number(this.getAttribute(`max-dimension`))||0,n=this.multiple?e:e.slice(0,1);if(!t)return this.accept(n,/* @__PURE__ */ new Map);let r=Number(this.getAttribute(`quality`))||void 0,i=/* @__PURE__ */ new Map;Promise.all(n.map(async e=>{let n=this.accepts(e)?await A(e,{maxDimension:t,quality:r}):null;return n?(i.set(n.file,g().fileUpload.resized(p(this,n.width),p(this,n.height))),n.file):e})).then(e=>this.accept(e,i))}accept(e,t){let n=this.getAttribute(`preview`)!==`false`;this.multiple||this.items.forEach(e=>e.previewUrl&&URL.revokeObjectURL(e.previewUrl));let r=Number(this.getAttribute(`max-size`))||0,i=Number(this.getAttribute(`max-files`))||0,a=this.multiple?this.items.filter(e=>e.status!==`error`).length:0,o=e.map((e,o)=>{let s;this.accepts(e)?r&&e.size>r?s=g().fileUpload.tooBig(k(r)):i&&a+o>=i&&(s=g().fileUpload.tooMany(p(this,i))):s=g().fileUpload.wrongType;let c=!s&&!!this.uploader,l=n&&!s&&e.type.startsWith(`image/`)&&typeof URL.createObjectURL==`function`?URL.createObjectURL(e):void 0;return{id:x(`f`),file:e,status:s?`error`:c?`uploading`:`done`,progress:s||c?0:100,error:s,previewUrl:l,note:t.get(e)}});this.items=this.multiple?[...this.items,...o]:o,this.announce(o.map(e=>`${e.file.name}: ${e.error??(this.uploader?g().fileUpload.uploading:g().fileUpload.done)}`).join(g().common.list)),this.changed();for(let e of o)e.status===`uploading`&&this.uploader&&this.uploader(e.file,t=>{e.progress=t,this.paint()}).then(()=>{e.status=`done`,e.progress=100,this.announce(`${e.file.name}: ${g().fileUpload.done}`),this.changed()},t=>{e.status=`error`,e.error=t instanceof Error?t.message:g().fileUpload.error,this.announce(`${e.file.name}: ${e.error}`),this.changed()})}announce(e){this.querySelector(`:scope > .k-sr-only`).textContent=e}changed(){try{let e=new DataTransfer;for(let t of this.files)e.items.add(t);this.input.files=e.files,e.files.length&&this.querySelector(`.k-dropzone`)?.removeAttribute(`data-invalid`)}catch{}this.paint(),c(this,`kashi-change`,{files:this.files})}paint(){let e=this.querySelector(`.k-file-list`);e.hidden=!this.items.length;let t=e=>(e.split(`.`).pop()??``).slice(0,4).toUpperCase();e.innerHTML=this.items.map(e=>`<li class="k-file" data-status="${e.status}">${e.previewUrl?`<img class="k-file__thumb" src="${f(e.previewUrl)}" alt="">`:`<span class="k-file__icon" aria-hidden="true">${f(t(e.file.name))}</span>`}<span class="k-file__name" title="${f(e.file.name)}">${f(e.file.name)}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-file__remove" data-remove="${e.id}" aria-label="${f(g().common.remove(e.file.name))}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 5.5h13M8 5.5V4h4v1.5M5 5.5l.8 10.2a1.5 1.5 0 0 0 1.5 1.3h5.4a1.5 1.5 0 0 0 1.5-1.3L15 5.5"/></svg></button><span class="k-file__meta">${f(e.error??`${k(e.file.size)}${e.status===`uploading`?` · ${g().common.percent(p(this,Math.round(e.progress)))}`:e.status===`done`?` · ${g().fileUpload.done}`:``}${e.note?` · ${e.note}`:``}`)}</span>${e.status===`uploading`?`<div role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${Math.round(e.progress)}" aria-label="${f(g().fileUpload.uploadingFile(e.file.name))}" class="k-progress k-progress--sm"><div class="k-progress__bar" style="--k-value: ${e.progress}%"></div></div>`:``}</li>`).join(``)}};j.observedAttributes=[`accept`,`multiple`,`max-size`,`max-files`,`hint`,`name`,`disabled`,`label`,`required`,`preview`,`max-dimension`,`quality`];const M=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i,N=e=>{let t=e.trim().match(M);return t?`#${(t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1]).toLowerCase()}`:null},P=e=>[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)),F=(e,t,n)=>`#${[e,t,n].map(e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`)).join(``)}`,I=e=>{let[t,n,r]=P(e).map(e=>e/255).map(e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4);return .2126*t+.7152*n+.0722*r},L=(e,t)=>{let[n,r]=[I(N(e)??e),I(N(t)??t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)};function R(e){let[t,n,r]=P(e).map(e=>e/255),i=Math.max(t,n,r),a=i-Math.min(t,n,r),o=0;return a&&(o=i===t?(n-r)/a%6:i===n?(r-t)/a+2:(t-n)/a+4),{h:(o*60+360)%360,s:i?a/i:0,v:i}}function z({h:e,s:t,v:n}){let r=r=>{let i=(r+e/60)%6;return(n-n*t*Math.max(0,Math.min(i,4-i,1)))*255};return F(r(5),r(3),r(1))}const B=[[`firoozeh`,`#0b8077`],[`lajvard`,`#2740ed`],[`violet`,`#7c3aed`],[`anar`,`#e51d2a`],[`zafaran`,`#dd5e02`],[`peste`,`#518b25`],[`shab`,`#2a2f3d`]],V=()=>B.map(([e,t])=>[g().colorPicker.names[e],t]);var H=class extends v{constructor(){super(...arguments),this.current=`#0b8077`,this.hsv=R(`#0b8077`),this.valueSet=!1,this.rendered=!1,this.key=x(`kashi-color`),this.panel=null,this.onOutside=e=>{this.querySelector(`.k-color__anchor`)?.contains(e.target)||this.closePanel(!1)}}connectedCallback(){!this.rendered&&!this.valueSet&&this.setColor(N(this.getAttribute(`value`)??``)??`#0b8077`,!1),this.render()}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}get value(){return this.current}set value(e){this.valueSet=!0;let t=N(e??``);t&&this.setColor(t,!1),this.rendered&&this.paint()}setColor(e,t){if(this.current=e,!t){let t=R(e);this.hsv=t.s===0?{...t,h:this.hsv.h}:t}}swatches(){let e=this.getAttribute(`swatches`);return e===null?V():e.split(`,`).map(e=>e.trim().split(/\s+/)).filter(([e])=>N(e)).map(([e,...t])=>[t.join(` `)||e,N(e)])}render(){let e=this.key,t=this.swatches(),n=`<div class="k-color">${t.length?`<div class="k-color__swatches" role="radiogroup" aria-label="${f(g().colorPicker.swatches)}">${t.map(([t,n])=>`<label class="k-color__swatch" style="--_sw: ${n}; --_ink: ${L(n,`#ffffff`)>=3?`#fff`:`#000`}" title="${f(t)}"><input type="radio" class="k-sr-only" name="${e}-sw" value="${n}" aria-label="${f(t)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 10.5 3.2 3L15 7"/></svg></label>`).join(``)}</div>`:``}<div class="k-color__row"><span class="k-color__anchor"><button type="button" class="k-color__preview" aria-label="${f(g().colorPicker.custom)}" aria-haspopup="dialog" aria-expanded="false"></button></span><div class="k-input"><input id="${e}-hex" class="k-input__control" dir="ltr" spellcheck="false" autocomplete="off"></div></div>${this.getAttribute(`show-contrast`)===`false`?``:'<p class="k-color__contrast" aria-live="polite"><span class="k-color__sample">${esc(msg().colorPicker.sample)}</span><span></span></p>'}</div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,y({id:`${e}-hex`,label:this.getAttribute(`label`)??g().colorPicker.label,control:n})),this.rendered=!0,this.querySelector(`.k-color__swatches`)?.addEventListener(`change`,e=>this.pick(e.target.value));let r=this.querySelector(`#${e}-hex`);r.addEventListener(`input`,()=>{let e=N(r.value);this.paintMessages(!e),e&&this.pick(e,!1)}),r.addEventListener(`blur`,()=>{N(r.value)&&(r.value=this.current)}),this.querySelector(`.k-color__preview`).addEventListener(`click`,()=>this.panel?this.closePanel():this.openPanel()),this.paint()}pick(e,t=!0,n=!1){let r=e!==this.current;this.setColor(e,n),this.paint(t),r&&c(this,`kashi-change`,{value:e})}paint(e=!0){let t=this.current,n=L(t,`#ffffff`),r=L(t,`#000000`),i=n>=r?`#ffffff`:`#000000`,a=this.querySelector(`.k-color`);a.style.setProperty(`--_sw`,t),a.style.setProperty(`--_ink`,i),this.querySelectorAll(`.k-color__swatch input`).forEach(e=>e.checked=e.value===t);let o=this.querySelector(`#${this.key}-hex`);e&&(o.value=t);let s=Math.max(n,r),c=this.querySelector(`.k-color__contrast span:last-child`);c&&(c.textContent=g().colorPicker.contrast(i===`#ffffff`?`white`:`black`,p(this,(Math.round(s*10)/10).toFixed(1)).replace(`.`,g().common.decimal),s>=4.5));let l=this.getAttribute(`name`);this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),l&&this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(l)}" value="${t}">`),this.panel&&this.paintPanel(),this.paintMessages(!1)}paintMessages(e){let t=this.querySelector(`#${this.key}-hex`);o(this.querySelector(`:scope > .k-field`),t,`${this.key}-hex`,e?g().colorPicker.invalid:null,this.getAttribute(`hint`))}openPanel(){let e=this.querySelector(`.k-color__anchor`),t=document.createElement(`div`);t.className=`k-color__panel`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,g().colorPicker.custom),t.innerHTML=`<div class="k-color__area" role="slider" tabindex="0" aria-label="${f(g().colorPicker.area)}"><span class="k-color__thumb"></span></div><div class="k-color__tools"><span class="k-color__current" aria-hidden="true"></span><input type="range" class="k-color__hue" min="0" max="359" aria-label="${f(g().colorPicker.hue)}"></div><div class="k-color__codes" dir="ltr">${[`R`,`G`,`B`].map((e,t)=>`<label class="k-color__code"><input class="k-color__num" inputmode="numeric" data-ch="${t}" aria-label="${f([g().colorPicker.red,g().colorPicker.green,g().colorPicker.blue][t])}"><span aria-hidden="true">${e}</span></label>`).join(``)}</div>`,e.append(t),this.panel=t;let n=t.querySelector(`.k-color__area`),r=e=>{this.hsv=e,this.pick(z(e),!0,!0)},i=e=>{let t=n.getBoundingClientRect();r({...this.hsv,s:Math.min(1,Math.max(0,(e.clientX-t.left)/t.width)),v:1-Math.min(1,Math.max(0,(e.clientY-t.top)/t.height))})};n.addEventListener(`pointerdown`,e=>{n.setPointerCapture?.(e.pointerId),i(e)}),n.addEventListener(`pointermove`,e=>e.buttons===1&&i(e)),n.addEventListener(`keydown`,e=>{let t=e.shiftKey?.1:.01,n=this.hsv,i={ArrowLeft:{s:Math.max(0,n.s-t)},ArrowRight:{s:Math.min(1,n.s+t)},ArrowUp:{v:Math.min(1,n.v+t)},ArrowDown:{v:Math.max(0,n.v-t)}};i[e.key]&&(e.preventDefault(),r({...n,...i[e.key]}))}),t.querySelector(`.k-color__hue`).addEventListener(`input`,e=>r({...this.hsv,h:Number(e.target.value)})),t.querySelectorAll(`.k-color__num`).forEach(e=>e.addEventListener(`input`,()=>{let t=P(this.current);t[Number(e.dataset.ch)]=Math.min(255,Math.max(0,Number(e.value.replace(/\D/g,``))||0)),this.pick(F(...t))})),t.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.closePanel())}),this.querySelector(`.k-color__preview`).setAttribute(`aria-expanded`,`true`),document.addEventListener(`pointerdown`,this.onOutside),this.paintPanel(),n.focus({preventScroll:!0})}paintPanel(){let e=this.panel,{h:t,s:n,v:r}=this.hsv,i=e=>g().common.percent(p(this,Math.round(e*100))),a=e.querySelector(`.k-color__area`);a.style.setProperty(`--_hue`,`hsl(${t} 100% 50%)`),a.setAttribute(`aria-valuenow`,String(Math.round(n*100))),a.setAttribute(`aria-valuetext`,g().colorPicker.areaValue(i(n),i(r)));let o=e.querySelector(`.k-color__thumb`);o.style.left=`${n*100}%`,o.style.top=`${(1-r)*100}%`;let s=e.querySelector(`.k-color__hue`);s.value=String(Math.round(t)),s.setAttribute(`aria-valuetext`,g().colorPicker.degrees(p(this,Math.round(t))));let c=P(this.current);e.querySelectorAll(`.k-color__num`).forEach((e,t)=>{document.activeElement!==e&&(e.value=String(c[t]))})}closePanel(e=!0){if(!this.panel)return;this.panel.remove(),this.panel=null,document.removeEventListener(`pointerdown`,this.onOutside);let t=this.querySelector(`.k-color__preview`);t.setAttribute(`aria-expanded`,`false`),e&&t.focus()}};H.observedAttributes=[`label`,`hint`,`value`,`name`,`swatches`,`show-contrast`],h(`kashi-date-range-picker`,E,`block`),h(`kashi-month-picker`,O,`block`),h(`kashi-file-upload`,j,`block`),h(`kashi-color-picker`,H,`block`);export{H as KashiColorPicker,E as KashiDateRangePicker,j as KashiFileUpload,O as KashiMonthPicker,L as contrastRatio,k as formatBytes,A as shrinkImage};
|
|
1
|
+
import{D as e,E as t,M as n,O as r,S as i,T as a,_ as o,a as s,c,d as l,f as u,i as d,l as f,m as p,n as m,o as h,p as g,s as _,t as v,u as y,x as b,y as x}from"./base-w2Oo_bN6.js";import"./calendar-C8oLBqU9.js";const S=e=>e?i(e.trim())??a(e):null,C=(e,t=0)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),w=(e,t)=>!e&&!t||!!e&&!!t&&e.getTime()===t.getTime(),T=[[(e,t)=>e.last7(t(7)),e=>({start:C(e,-6),end:e})],[(e,t)=>e.last30(t(30)),e=>({start:C(e,-29),end:e})],[e=>e.thisMonth,e=>{let{jy:n,jm:i}=r(e);return{start:t(n,i,1),end:e}}],[e=>e.lastMonth,e=>{let{jy:n,jm:i}=r(e),[a,o]=i===1?[n-1,12]:[n,i-1];return{start:t(a,o,1),end:C(t(n,i,1),-1)}}]];var E=class extends v{constructor(){super(...arguments),this.current={start:null,end:null},this.draft={start:null,end:null},this.valueSet=!1,this.rendered=!1,this.key=x(`kashi-range`),this.pop=null,this.onOutside=e=>{this.contains(e.target)||this.close(!1)}}connectedCallback(){!this.rendered&&!this.valueSet&&(this.current={start:S(this.getAttribute(`start`)),end:S(this.getAttribute(`end`))}),this.render()}disconnectedCallback(){this.close(!1)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&((e===`start`||e===`end`)&&(this.current={...this.current,[e]:S(n)}),this.render())}get value(){return{...this.current}}set value(e){this.valueSet=!0,this.current={start:e?.start??null,end:e?.end??null},this.rendered&&this.render()}fmt(e){return b(e,{digits:_(this),locale:l()})}text(e){return e.start&&e.end?`${this.fmt(e.start)}${g().common.range}${this.fmt(e.end)}`:null}render(){this.close(!1);let t=this.key,n=this.getAttribute(`label`)??g().dateRange.label,r=this.text(this.current),i=`<div class="k-datepicker k-daterange"><div class="k-select"><button id="${t}" type="button" class="k-select__control k-daterange__trigger" aria-haspopup="dialog" aria-expanded="false"${r?``:` data-placeholder=""`}${this.hasAttribute(`disabled`)?` disabled`:``}>${m.calendar}<span>${f(r??this.getAttribute(`placeholder`)??g().dateRange.placeholder)}</span></button></div></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,y({id:t,label:n,control:i})),this.trigger=this.querySelector(`.k-daterange__trigger`),this.trigger.addEventListener(`click`,()=>this.pop?this.close():this.open()),this.rendered=!0,o(this.querySelector(`:scope > .k-field`),this.trigger,t,this.getAttribute(`error`),this.getAttribute(`hint`));let a=this.getAttribute(`name`);if(this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),a)for(let[t,n]of[[`start`,this.current.start],[`end`,this.current.end]])this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(`${a}_${t}`)}" value="${n?e(n):``}">`)}open(){if(this.pop||this.hasAttribute(`disabled`))return;this.draft={...this.current};let t=this.querySelector(`.k-daterange`),n=document.createElement(`div`);n.id=`${this.key}-popover`,n.className=`k-datepicker__popover k-daterange__popover`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-label`,this.getAttribute(`label`)??g().dateRange.placeholder);let r=this.getAttribute(`presets`)===`false`?[]:T;n.innerHTML=`${r.length?`<ul class="k-daterange__presets" role="list" aria-label="${f(g().dateRange.presets)}">${r.map(([e],t)=>`<li><button type="button" class="k-daterange__preset" data-preset="${t}" aria-pressed="false">${f(e(g().dateRange,e=>p(this,e)))}</button></li>`).join(``)}</ul>`:``}<div class="k-daterange__main"><div class="k-daterange__footer"><span class="k-daterange__summary" aria-live="polite"></span><button type="button" class="k-btn k-btn--secondary k-btn--sm" data-cancel>${f(g().common.cancel)}</button><button type="button" class="k-btn k-btn--primary k-btn--sm" data-apply>${f(g().common.confirm)}</button></div></div>`;let i=document.createElement(`kashi-calendar`);for(let e of[`min`,`max`,`digits`,`holidays`]){let t=this.getAttribute(e);t!==null&&i.setAttribute(e,t)}i.range=this.draft,n.querySelector(`.k-daterange__main`).prepend(i),i.addEventListener(`kashi-change`,e=>{e.stopPropagation();let t=e.detail.date,n=this.draft;this.draft=!n.start||n.end?{start:t,end:null}:t<n.start?{start:t,end:n.start}:{start:n.start,end:t},i.range=this.draft,this.paintDraft()}),n.addEventListener(`click`,t=>{let n=t.target,a=n.closest(`[data-preset]`);if(a)this.draft=r[Number(a.dataset.preset)][1](C(/* @__PURE__ */ new Date)),i.range=this.draft,this.paintDraft();else if(n.closest(`[data-cancel]`))this.close();else if(n.closest(`[data-apply]`)&&this.draft.start&&this.draft.end){let t=!w(this.draft.start,this.current.start)||!w(this.draft.end,this.current.end);this.current={...this.draft},this.close(),this.render(),this.trigger.focus(),t&&c(this,`kashi-change`,{start:this.current.start,end:this.current.end,value:{start:e(this.current.start),end:e(this.current.end)}})}}),n.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.close())}),t.append(n),this.pop=n,this.trigger.setAttribute(`aria-expanded`,`true`),this.trigger.setAttribute(`aria-controls`,n.id),document.addEventListener(`pointerdown`,this.onOutside),this.paintDraft(),i.focus()}paintDraft(){let e=this.pop,t=this.draft;e.querySelector(`.k-daterange__summary`).textContent=this.text(t)??(t.start?g().dateRange.pickEnd:``),e.querySelector(`[data-apply]`).disabled=!t.start||!t.end;let n=C(/* @__PURE__ */ new Date);e.querySelectorAll(`[data-preset]`).forEach((e,r)=>{let i=T[r][1](n);e.setAttribute(`aria-pressed`,String(w(t.start,i.start)&&w(t.end,i.end)))})}close(e=!0){this.pop&&(this.pop.remove(),this.pop=null,document.removeEventListener(`pointerdown`,this.onOutside),this.trigger.setAttribute(`aria-expanded`,`false`),this.trigger.removeAttribute(`aria-controls`),e&&this.trigger.focus())}};E.observedAttributes=[`label`,`hint`,`error`,`start`,`end`,`min`,`max`,`holidays`,`digits`,`name`,`disabled`,`presets`,`placeholder`];const D=e=>`<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-k-mirror=""><path d="${e?`m8 5 5 5-5 5`:`m12 5-5 5 5 5`}"/></svg>`;var O=class extends v{constructor(){super(...arguments),this.selected=null,this.year=r(/* @__PURE__ */ new Date).jy,this.focusMonth=1,this.valueSet=!1,this.rendered=!1}connectedCallback(){if(!this.rendered){this.valueSet||(this.selected=this.parse(this.getAttribute(`value`)));let e=r(/* @__PURE__ */ new Date);this.year=this.selected?.year??e.jy,this.focusMonth=this.selected?.month??(this.year===e.jy?e.jm:1)}this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}parse(e){let t=(e??``).trim().match(/^(\d{4})[-/](\d{1,2})$/);return t?{year:Number(t[1]),month:Number(t[2])}:null}get value(){return this.selected?`${this.selected.year}-${String(this.selected.month).padStart(2,`0`)}`:``}set value(e){this.valueSet=!0,this.selected=this.parse(e),this.selected&&([this.year,this.focusMonth]=[this.selected.year,this.selected.month]),this.rendered&&this.render()}out(e,t){let n=e*12+t,r=this.parse(this.getAttribute(`min`)),i=this.parse(this.getAttribute(`max`));return!!r&&n<r.year*12+r.month||!!i&&n>i.year*12+i.month}render(e=!1){let t=e=>_(this)===`latin`?String(e):n(String(e)),i=r(/* @__PURE__ */ new Date),a=this.parse(this.getAttribute(`min`)),o=this.parse(this.getAttribute(`max`)),l=this.year;this.innerHTML=`<div class="k-monthpicker" role="group" aria-label="${f(this.getAttribute(`label`)??g().monthPicker.label)}"><div class="k-monthpicker__header"><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-year="-1" aria-label="${f(g().monthPicker.prevYear)}"${a&&l<=a.year?` disabled`:``}>${D(!1)}</button><span class="k-monthpicker__year" aria-live="polite">${t(l)}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-year="1" aria-label="${f(g().monthPicker.nextYear)}"${o&&l>=o.year?` disabled`:``}>${D(!0)}</button></div><div class="k-monthpicker__grid">${s().months.map((e,n)=>`<button type="button" data-month="${n+1}" class="k-monthpicker__month" tabindex="${this.focusMonth===n+1?0:-1}" aria-pressed="${this.selected?.year===l&&this.selected.month===n+1}" aria-label="${e} ${t(l)}"${i.jy===l&&i.jm===n+1?` aria-current="date"`:``}${this.out(l,n+1)?` disabled`:``}>${e}</button>`).join(``)}</div></div>`;let u=this.getAttribute(`name`);u&&this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(u)}" value="${this.value}">`),this.rendered=!0,this.querySelectorAll(`[data-year]`).forEach(e=>e.addEventListener(`click`,()=>{this.year+=Number(e.dataset.year),this.render()}));let d=this.querySelector(`.k-monthpicker__grid`);d.addEventListener(`click`,e=>{let t=e.target.closest(`[data-month]`);t&&!t.disabled&&(this.selected={year:this.year,month:Number(t.dataset.month)},this.focusMonth=this.selected.month,this.render(!0),c(this,`kashi-change`,{value:this.value,year:this.selected.year,month:this.selected.month}))}),d.addEventListener(`keydown`,e=>{let t=getComputedStyle(d).direction===`rtl`,n={ArrowRight:t?-1:1,ArrowLeft:t?1:-1,ArrowDown:3,ArrowUp:-3,PageUp:-12,PageDown:12},r=this.year*12+this.focusMonth-1;if(e.key in n)r+=n[e.key];else if(e.key===`Home`)r=this.year*12;else if(e.key===`End`)r=this.year*12+11;else return;e.preventDefault(),this.year=Math.floor(r/12),this.focusMonth=r%12+1,this.render(!0)}),e&&this.querySelector(`[data-month="${this.focusMonth}"]`)?.focus()}};O.observedAttributes=[`value`,`min`,`max`,`digits`,`label`,`name`];function k(e){let t=g().fileUpload.units,r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i++;let a=i===0?String(r):r.toFixed(+(r<10)).replace(/\.0$/,``);return`${u()===`fa`?n(a).replace(`.`,`٫`):a} ${t[i]}`}async function A(e,{maxDimension:t,quality:n=.85,type:r}){if(!/^image\/(jpeg|png|webp)$/.test(e.type)||typeof createImageBitmap!=`function`)return null;let i;try{i=await createImageBitmap(e,{imageOrientation:`from-image`})}catch{return null}let a=Math.min(1,t/Math.max(i.width,i.height));if(a>=1)return i.close?.(),null;let o=Math.round(i.width*a),s=Math.round(i.height*a),c=r??e.type,l=null;try{if(typeof OffscreenCanvas<`u`){let e=new OffscreenCanvas(o,s),t=e.getContext(`2d`);t.imageSmoothingQuality=`high`,t.drawImage(i,0,0,o,s),l=await e.convertToBlob({type:c,quality:n})}else{let e=document.createElement(`canvas`);e.width=o,e.height=s;let t=e.getContext(`2d`);t.imageSmoothingQuality=`high`,t.drawImage(i,0,0,o,s),l=await new Promise(t=>e.toBlob(t,c,n))}}finally{i.close?.()}if(!l||l.size>=e.size)return null;let u=c===e.type?e.name:`${e.name.replace(/\.[^.]+$/,``)}.${c===`image/jpeg`?`jpg`:c.split(`/`)[1]}`;return{file:new File([l],u,{type:c,lastModified:e.lastModified}),width:o,height:s}}var j=class extends v{constructor(){super(...arguments),this.items=[],this.rendered=!1,this.key=x(`kashi-upload`)}connectedCallback(){this.rendered||this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&this.render()}get files(){return this.items.filter(e=>e.status!==`error`).map(e=>e.file)}get multiple(){return d(this,`multiple`,!0)}render(){let e=this.key,t=this.getAttribute(`hint`),n=this.hasAttribute(`disabled`),r=this.getAttribute(`name`),i=this.getAttribute(`accept`);this.innerHTML=`<div class="k-dropzone"${n?` data-disabled=""`:``}><span class="k-dropzone__icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13V3.5m-4 4 4-4 4 4M4 13v2.5A1.5 1.5 0 0 0 5.5 17h9a1.5 1.5 0 0 0 1.5-1.5V13"/></svg></span><p class="k-dropzone__title" style="margin: 0"><button type="button" class="k-dropzone__browse"${n?` disabled`:``}${t?` aria-describedby="${e}-hint"`:``}>${f(this.getAttribute(`label`)??g().fileUpload.browse)}</button> <span>${f(g().fileUpload.drop)}</span></p>${t?`<p class="k-dropzone__hint" id="${e}-hint" style="margin: 0">${f(t)}</p>`:``}<input type="file" tabindex="-1" aria-hidden="true"${i?` accept="${f(i)}"`:``}${this.multiple?` multiple`:``}${r?` name="${f(r)}"`:``}${this.hasAttribute(`required`)?` required`:``}></div><ul class="k-file-list" role="list" hidden></ul><span class="k-sr-only" aria-live="polite"></span>`,this.rendered=!0,this.input=this.querySelector(`input[type=file]`);let a=this.querySelector(`.k-dropzone`);this.querySelector(`.k-dropzone__browse`).addEventListener(`click`,()=>this.input.click()),this.input.addEventListener(`change`,()=>{this.input.files?.length&&this.add([...this.input.files])}),this.input.addEventListener(`invalid`,()=>a.setAttribute(`data-invalid`,``)),a.addEventListener(`dragover`,e=>{e.preventDefault(),n||a.setAttribute(`data-dragging`,``)}),a.addEventListener(`dragleave`,e=>{a.contains(e.relatedTarget)||a.removeAttribute(`data-dragging`)}),a.addEventListener(`drop`,e=>{e.preventDefault(),a.removeAttribute(`data-dragging`),!n&&e.dataTransfer?.files.length&&this.add([...e.dataTransfer.files])}),this.querySelector(`.k-file-list`).addEventListener(`click`,e=>{let t=e.target.closest(`[data-remove]`);if(!t)return;let n=this.items.find(e=>e.id===t.dataset.remove);n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),this.items=this.items.filter(e=>e.id!==t.dataset.remove),this.announce(g().common.removed(n?.file.name??``)),this.changed()}),this.paint()}accepts(e){let t=this.getAttribute(`accept`);return!t||t.split(`,`).map(e=>e.trim().toLowerCase()).some(t=>t.startsWith(`.`)?e.name.toLowerCase().endsWith(t):t.endsWith(`/*`)?e.type.startsWith(t.slice(0,-1)):e.type===t)}add(e){let t=Number(this.getAttribute(`max-dimension`))||0,n=this.multiple?e:e.slice(0,1);if(!t)return this.accept(n,/* @__PURE__ */ new Map);let r=Number(this.getAttribute(`quality`))||void 0,i=/* @__PURE__ */ new Map;Promise.all(n.map(async e=>{let n=this.accepts(e)?await A(e,{maxDimension:t,quality:r}):null;return n?(i.set(n.file,g().fileUpload.resized(p(this,n.width),p(this,n.height))),n.file):e})).then(e=>this.accept(e,i))}accept(e,t){let n=this.getAttribute(`preview`)!==`false`;this.multiple||this.items.forEach(e=>e.previewUrl&&URL.revokeObjectURL(e.previewUrl));let r=Number(this.getAttribute(`max-size`))||0,i=Number(this.getAttribute(`max-files`))||0,a=this.multiple?this.items.filter(e=>e.status!==`error`).length:0,o=e.map((e,o)=>{let s;this.accepts(e)?r&&e.size>r?s=g().fileUpload.tooBig(k(r)):i&&a+o>=i&&(s=g().fileUpload.tooMany(p(this,i))):s=g().fileUpload.wrongType;let c=!s&&!!this.uploader,l=n&&!s&&e.type.startsWith(`image/`)&&typeof URL.createObjectURL==`function`?URL.createObjectURL(e):void 0;return{id:x(`f`),file:e,status:s?`error`:c?`uploading`:`done`,progress:s||c?0:100,error:s,previewUrl:l,note:t.get(e)}});this.items=this.multiple?[...this.items,...o]:o,this.announce(o.map(e=>`${e.file.name}: ${e.error??(this.uploader?g().fileUpload.uploading:g().fileUpload.done)}`).join(g().common.list)),this.changed();for(let e of o)e.status===`uploading`&&this.uploader&&this.uploader(e.file,t=>{e.progress=t,this.paint()}).then(()=>{e.status=`done`,e.progress=100,this.announce(`${e.file.name}: ${g().fileUpload.done}`),this.changed()},t=>{e.status=`error`,e.error=t instanceof Error?t.message:g().fileUpload.error,this.announce(`${e.file.name}: ${e.error}`),this.changed()})}announce(e){this.querySelector(`:scope > .k-sr-only`).textContent=e}changed(){try{let e=new DataTransfer;for(let t of this.files)e.items.add(t);this.input.files=e.files,e.files.length&&this.querySelector(`.k-dropzone`)?.removeAttribute(`data-invalid`)}catch{}this.paint(),c(this,`kashi-change`,{files:this.files})}paint(){let e=this.querySelector(`.k-file-list`);e.hidden=!this.items.length;let t=e=>(e.split(`.`).pop()??``).slice(0,4).toUpperCase();e.innerHTML=this.items.map(e=>`<li class="k-file" data-status="${e.status}">${e.previewUrl?`<img class="k-file__thumb" src="${f(e.previewUrl)}" alt="">`:`<span class="k-file__icon" aria-hidden="true">${f(t(e.file.name))}</span>`}<span class="k-file__name" title="${f(e.file.name)}">${f(e.file.name)}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-file__remove" data-remove="${e.id}" aria-label="${f(g().common.remove(e.file.name))}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 5.5h13M8 5.5V4h4v1.5M5 5.5l.8 10.2a1.5 1.5 0 0 0 1.5 1.3h5.4a1.5 1.5 0 0 0 1.5-1.3L15 5.5"/></svg></button><span class="k-file__meta">${f(e.error??`${k(e.file.size)}${e.status===`uploading`?` · ${g().common.percent(p(this,Math.round(e.progress)))}`:e.status===`done`?` · ${g().fileUpload.done}`:``}${e.note?` · ${e.note}`:``}`)}</span>${e.status===`uploading`?`<div role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${Math.round(e.progress)}" aria-label="${f(g().fileUpload.uploadingFile(e.file.name))}" class="k-progress k-progress--sm"><div class="k-progress__bar" style="--k-value: ${e.progress}%"></div></div>`:``}</li>`).join(``)}};j.observedAttributes=[`accept`,`multiple`,`max-size`,`max-files`,`hint`,`name`,`disabled`,`label`,`required`,`preview`,`max-dimension`,`quality`];const M=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i,N=e=>{let t=e.trim().match(M);return t?`#${(t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1]).toLowerCase()}`:null},P=e=>[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)),F=(e,t,n)=>`#${[e,t,n].map(e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`)).join(``)}`,I=e=>{let[t,n,r]=P(e).map(e=>e/255).map(e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4);return .2126*t+.7152*n+.0722*r},L=(e,t)=>{let[n,r]=[I(N(e)??e),I(N(t)??t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)};function R(e){let[t,n,r]=P(e).map(e=>e/255),i=Math.max(t,n,r),a=i-Math.min(t,n,r),o=0;return a&&(o=i===t?(n-r)/a%6:i===n?(r-t)/a+2:(t-n)/a+4),{h:(o*60+360)%360,s:i?a/i:0,v:i}}function z({h:e,s:t,v:n}){let r=r=>{let i=(r+e/60)%6;return(n-n*t*Math.max(0,Math.min(i,4-i,1)))*255};return F(r(5),r(3),r(1))}const B=[[`firoozeh`,`#0b8077`],[`lajvard`,`#2740ed`],[`violet`,`#7c3aed`],[`anar`,`#e51d2a`],[`zafaran`,`#dd5e02`],[`peste`,`#518b25`],[`shab`,`#2a2f3d`]],V=()=>B.map(([e,t])=>[g().colorPicker.names[e],t]);var H=class extends v{constructor(){super(...arguments),this.current=`#0b8077`,this.hsv=R(`#0b8077`),this.valueSet=!1,this.rendered=!1,this.key=x(`kashi-color`),this.panel=null,this.onOutside=e=>{this.querySelector(`.k-color__anchor`)?.contains(e.target)||this.closePanel(!1)}}connectedCallback(){!this.rendered&&!this.valueSet&&this.setColor(N(this.getAttribute(`value`)??``)??`#0b8077`,!1),this.render()}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}get value(){return this.current}set value(e){this.valueSet=!0;let t=N(e??``);t&&this.setColor(t,!1),this.rendered&&this.paint()}setColor(e,t){if(this.current=e,!t){let t=R(e);this.hsv=t.s===0?{...t,h:this.hsv.h}:t}}swatches(){let e=this.getAttribute(`swatches`);return e===null?V():e.split(`,`).map(e=>e.trim().split(/\s+/)).filter(([e])=>N(e)).map(([e,...t])=>[t.join(` `)||e,N(e)])}render(){let e=this.key,t=this.swatches(),n=`<div class="k-color">${t.length?`<div class="k-color__swatches" role="radiogroup" aria-label="${f(g().colorPicker.swatches)}">${t.map(([t,n])=>`<label class="k-color__swatch" style="--_sw: ${n}; --_ink: ${L(n,`#ffffff`)>=3?`#fff`:`#000`}" title="${f(t)}"><input type="radio" class="k-sr-only" name="${e}-sw" value="${n}" aria-label="${f(t)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 10.5 3.2 3L15 7"/></svg></label>`).join(``)}</div>`:``}<div class="k-color__row"><span class="k-color__anchor"><button type="button" class="k-color__preview" aria-label="${f(g().colorPicker.custom)}" aria-haspopup="dialog" aria-expanded="false"></button></span><div class="k-input"><input id="${e}-hex" class="k-input__control" dir="ltr" spellcheck="false" autocomplete="off"></div></div>${this.getAttribute(`show-contrast`)===`false`?``:'<p class="k-color__contrast" aria-live="polite"><span class="k-color__sample">${esc(msg().colorPicker.sample)}</span><span></span></p>'}</div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,y({id:`${e}-hex`,label:this.getAttribute(`label`)??g().colorPicker.label,control:n})),this.rendered=!0,this.querySelector(`.k-color__swatches`)?.addEventListener(`change`,e=>this.pick(e.target.value));let r=this.querySelector(`#${e}-hex`);r.addEventListener(`input`,()=>{let e=N(r.value);this.paintMessages(!e),e&&this.pick(e,!1)}),r.addEventListener(`blur`,()=>{N(r.value)&&(r.value=this.current)}),this.querySelector(`.k-color__preview`).addEventListener(`click`,()=>this.panel?this.closePanel():this.openPanel()),this.paint()}pick(e,t=!0,n=!1){let r=e!==this.current;this.setColor(e,n),this.paint(t),r&&c(this,`kashi-change`,{value:e})}paint(e=!0){let t=this.current,n=L(t,`#ffffff`),r=L(t,`#000000`),i=n>=r?`#ffffff`:`#000000`,a=this.querySelector(`.k-color`);a.style.setProperty(`--_sw`,t),a.style.setProperty(`--_ink`,i),this.querySelectorAll(`.k-color__swatch input`).forEach(e=>e.checked=e.value===t);let o=this.querySelector(`#${this.key}-hex`);e&&(o.value=t);let s=Math.max(n,r),c=this.querySelector(`.k-color__contrast span:last-child`);c&&(c.textContent=g().colorPicker.contrast(i===`#ffffff`?`white`:`black`,p(this,(Math.round(s*10)/10).toFixed(1)).replace(`.`,g().common.decimal),s>=4.5));let l=this.getAttribute(`name`);this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),l&&this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${f(l)}" value="${t}">`),this.panel&&this.paintPanel(),this.paintMessages(!1)}paintMessages(e){let t=this.querySelector(`#${this.key}-hex`);o(this.querySelector(`:scope > .k-field`),t,`${this.key}-hex`,e?g().colorPicker.invalid:null,this.getAttribute(`hint`))}openPanel(){let e=this.querySelector(`.k-color__anchor`),t=document.createElement(`div`);t.className=`k-color__panel`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,g().colorPicker.custom),t.innerHTML=`<div class="k-color__area" role="slider" tabindex="0" aria-label="${f(g().colorPicker.area)}"><span class="k-color__thumb"></span></div><div class="k-color__tools"><span class="k-color__current" aria-hidden="true"></span><input type="range" class="k-color__hue" min="0" max="359" aria-label="${f(g().colorPicker.hue)}"></div><div class="k-color__codes" dir="ltr">${[`R`,`G`,`B`].map((e,t)=>`<label class="k-color__code"><input class="k-color__num" inputmode="numeric" data-ch="${t}" aria-label="${f([g().colorPicker.red,g().colorPicker.green,g().colorPicker.blue][t])}"><span aria-hidden="true">${e}</span></label>`).join(``)}</div>`,e.append(t),this.panel=t;let n=t.querySelector(`.k-color__area`),r=e=>{this.hsv=e,this.pick(z(e),!0,!0)},i=e=>{let t=n.getBoundingClientRect();r({...this.hsv,s:Math.min(1,Math.max(0,(e.clientX-t.left)/t.width)),v:1-Math.min(1,Math.max(0,(e.clientY-t.top)/t.height))})};n.addEventListener(`pointerdown`,e=>{n.setPointerCapture?.(e.pointerId),i(e)}),n.addEventListener(`pointermove`,e=>e.buttons===1&&i(e)),n.addEventListener(`keydown`,e=>{let t=e.shiftKey?.1:.01,n=this.hsv,i={ArrowLeft:{s:Math.max(0,n.s-t)},ArrowRight:{s:Math.min(1,n.s+t)},ArrowUp:{v:Math.min(1,n.v+t)},ArrowDown:{v:Math.max(0,n.v-t)}};i[e.key]&&(e.preventDefault(),r({...n,...i[e.key]}))}),t.querySelector(`.k-color__hue`).addEventListener(`input`,e=>r({...this.hsv,h:Number(e.target.value)})),t.querySelectorAll(`.k-color__num`).forEach(e=>e.addEventListener(`input`,()=>{let t=P(this.current);t[Number(e.dataset.ch)]=Math.min(255,Math.max(0,Number(e.value.replace(/\D/g,``))||0)),this.pick(F(...t))})),t.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.closePanel())}),this.querySelector(`.k-color__preview`).setAttribute(`aria-expanded`,`true`),document.addEventListener(`pointerdown`,this.onOutside),this.paintPanel(),n.focus({preventScroll:!0})}paintPanel(){let e=this.panel,{h:t,s:n,v:r}=this.hsv,i=e=>g().common.percent(p(this,Math.round(e*100))),a=e.querySelector(`.k-color__area`);a.style.setProperty(`--_hue`,`hsl(${t} 100% 50%)`),a.setAttribute(`aria-valuenow`,String(Math.round(n*100))),a.setAttribute(`aria-valuetext`,g().colorPicker.areaValue(i(n),i(r)));let o=e.querySelector(`.k-color__thumb`);o.style.left=`${n*100}%`,o.style.top=`${(1-r)*100}%`;let s=e.querySelector(`.k-color__hue`);s.value=String(Math.round(t)),s.setAttribute(`aria-valuetext`,g().colorPicker.degrees(p(this,Math.round(t))));let c=P(this.current);e.querySelectorAll(`.k-color__num`).forEach((e,t)=>{document.activeElement!==e&&(e.value=String(c[t]))})}closePanel(e=!0){if(!this.panel)return;this.panel.remove(),this.panel=null,document.removeEventListener(`pointerdown`,this.onOutside);let t=this.querySelector(`.k-color__preview`);t.setAttribute(`aria-expanded`,`false`),e&&t.focus()}};H.observedAttributes=[`label`,`hint`,`value`,`name`,`swatches`,`show-contrast`],h(`kashi-date-range-picker`,E,`block`),h(`kashi-month-picker`,O,`block`),h(`kashi-file-upload`,j,`block`),h(`kashi-color-picker`,H,`block`);export{H as KashiColorPicker,E as KashiDateRangePicker,j as KashiFileUpload,O as KashiMonthPicker,L as contrastRatio,k as formatBytes,A as shrinkImage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e}from"./text-3BuPhESu.js";import{c as t,i as n,l as r,m as i,o as a,p as o,r as s,t as c,y as l}from"./base-w2Oo_bN6.js";import{cellNumber as u}from"./controls-B6MNzFzT.js";const d=t=>e(t,{digits:`latin`}).toLowerCase();var f=class extends c{constructor(){super(...arguments),this.cols=null,this.data=null,this.table=null,this.sort=null,this.query=``,this.key=l(`kashi-table`),this.getRowId=e=>String(e.id??``)}connectedCallback(){s(()=>this.isConnected&&this.setup())}attributeChangedCallback(e,t,n){this.table&&t!==n&&this.setup()}get columns(){return this.cols??[]}set columns(e){this.cols=e,this.isConnected&&this.data&&this.setup()}get rows(){return this.data??[]}set rows(e){this.data=e,this.isConnected&&this.cols&&this.setup()}get selected(){return[...this.querySelectorAll(`tbody tr[aria-selected="true"]`)].map(e=>e.dataset.id??``)}setup(){this.cols&&this.data&&this.buildFromData();let e=this.querySelector(`:scope table`);if(!e)return;let t=e.closest(`.k-table-wrap`)??this.wrap(e);t.className=`k-table-wrap${n(this,`sticky-header`)?` k-table-wrap--sticky`:``}`,e.classList.add(`k-table`),e.classList.toggle(`k-table--compact`,n(this,`compact`)),e.classList.toggle(`k-table--striped`,n(this,`striped`));let r=e.querySelector(`caption`);r&&(r.id||=`${this.key}-caption`,t.setAttribute(`aria-labelledby`,r.id)),this.table=e,this.decorateHeader(),this.decorateRows(),this.searchBox(),this.apply()}wrap(e){let t=document.createElement(`div`);return t.setAttribute(`role`,`region`),t.tabIndex=0,e.before(t),t.append(e),t}buildFromData(){let e=this.cols,t=this.getAttribute(`caption`)??``,n=(e,t)=>e.format?e.format(t[e.key],t):String(t[e.key]??``),i=`<table>${t?`<caption><span class="k-table__caption-title">${r(t)}</span></caption>`:``}<thead><tr>${e.map(e=>`<th scope="col"${e.sortable?` data-sort`:``}${e.numeric?` data-numeric`:``}>${r(e.header)}</th>`).join(``)}</tr></thead><tbody>${this.data.map(t=>`<tr data-id="${r(this.getRowId(t))}">${e.map(e=>`<td>${r(n(e,t))}</td>`).join(``)}</tr>`).join(``)}</tbody></table>`;this.querySelector(`:scope > .k-table-wrap, :scope > table`)?.remove(),this.insertAdjacentHTML(`beforeend`,i)}decorateHeader(){this.table;let e=this.headCells();e.forEach((e,n)=>{if(e.classList.contains(`k-table__check`)||(e.scope||=`col`,e.hasAttribute(`data-numeric`)&&e.classList.add(`k-table__num`),!e.hasAttribute(`data-sort`)||e.querySelector(`.k-table__sort`)))return;e.setAttribute(`aria-sort`,`none`);let r=document.createElement(`button`);r.type=`button`,r.className=`k-table__sort`,r.append(...e.childNodes),e.append(r);let i=this.dataIndex(n);r.addEventListener(`click`,()=>{this.sort=this.sort?.index===i&&this.sort.dir===`ascending`?{index:i,dir:`descending`}:{index:i,dir:`ascending`},this.apply(),t(this,`kashi-sort`,{column:i,direction:this.sort.dir})})});let r=e.map(e=>e.hasAttribute(`data-numeric`));for(let e of this.bodyRows())[...e.children].forEach((e,t)=>r[t]&&e.classList.add(`k-table__num`));let i=n(this,`selectable`),a=this.headRow(),o=a?.querySelector(`.k-table__check`);if(i&&a&&!o){let e=document.createElement(`th`);e.scope=`col`,e.className=`k-table__check`,e.innerHTML='<input type="checkbox" class="k-checkbox" aria-label="${esc(msg().table.selectAll)}">',a.prepend(e),e.querySelector(`input`).addEventListener(`change`,e=>{let t=e.target.checked;this.visibleRows().forEach(e=>this.setRow(e,t)),this.selectionChanged()})}else!i&&o&&o.remove()}headRow(){return this.table.querySelector(`:scope > thead > tr`)}headCells(){return[...this.headRow()?.children??[]]}bodyRows(){return[...this.table.querySelectorAll(`:scope > tbody > tr`)]}dataIndex(e){return this.headRow()?.querySelector(`.k-table__check`)?e-1:e}offset(){return+!!this.headRow()?.querySelector(`.k-table__check`)}decorateRows(){let e=n(this,`selectable`);this.bodyRows().forEach((t,n)=>{var i,a;(i=t.dataset).id||(i.id=String(n+1)),(a=t.dataset).order||(a.order=String(n));let s=t.querySelector(`.k-table__check`);if(e&&!s){let e=document.createElement(`td`);e.className=`k-table__check`;let n=t.children[0]?.textContent?.trim();e.innerHTML=`<input type="checkbox" class="k-checkbox" aria-label="${r(n?o().table.selectNamed(n):o().table.selectRow)}">`,t.prepend(e),t.setAttribute(`aria-selected`,`false`),e.querySelector(`input`).addEventListener(`change`,e=>{this.setRow(t,e.target.checked),this.selectionChanged()})}else!e&&s&&(s.remove(),t.removeAttribute(`aria-selected`))}),this.selectionChanged(!1)}setRow(e,t){e.setAttribute(`aria-selected`,String(t));let n=e.querySelector(`.k-table__check input`);n&&(n.checked=t)}selectionChanged(e=!0){let n=this.headRow()?.querySelector(`.k-table__check input`),i=this.visibleRows(),a=i.filter(e=>e.getAttribute(`aria-selected`)===`true`).length;n&&(n.checked=i.length>0&&a===i.length,n.indeterminate=a>0&&a<i.length);let o=this.getAttribute(`name`);if(this.querySelectorAll(`:scope > input[type=hidden]`).forEach(e=>e.remove()),o)for(let e of this.selected)this.insertAdjacentHTML(`beforeend`,`<input type="hidden" name="${r(o)}" value="${r(e)}">`);e&&t(this,`kashi-change`,{selected:this.selected})}visibleRows(){return this.bodyRows().filter(e=>!e.hidden&&!e.classList.contains(`k-table__empty`))}searchBox(){let e=this.querySelector(`:scope > .k-table-search`);if(!n(this,`searchable`))return e?.remove();if(e)return;let t=`${this.key}-search`,a=document.createElement(`div`);a.className=`k-table-search k-field`,a.style.marginBlockEnd=`var(--k-space-3)`,a.innerHTML=`<div class="k-input k-input--sm"><input id="${t}" class="k-input__control" type="search" placeholder="${r(o().table.search)}" aria-label="${r(o().table.search)}"></div><span class="k-sr-only" aria-live="polite"></span>`,this.prepend(a);let s=a.querySelector(`input`);s.addEventListener(`input`,()=>{this.query=s.value,this.apply(),a.querySelector(`.k-sr-only`).textContent=o().table.rows(i(this,this.visibleRows().length))})}apply(){let e=this.table.querySelector(`:scope > tbody`);if(!e)return;let t=this.offset(),n=this.bodyRows().filter(e=>!e.classList.contains(`k-table__empty`)),i=this.headCells();i.forEach((e,n)=>{e.hasAttribute(`aria-sort`)&&e.setAttribute(`aria-sort`,this.sort&&this.sort.index===n-t?this.sort.dir:`none`)});let a=n.sort((e,t)=>Number(e.dataset.order)-Number(t.dataset.order));if(this.sort){let{index:e,dir:n}=this.sort,r=i[e+t]?.hasAttribute(`data-numeric`),o=n=>{let i=n.children[e+t],a=i?.dataset.value??i?.textContent?.trim()??``;return r?u(a):a},s=n===`ascending`?1:-1;a=[...a].sort((e,t)=>{let n=o(e),r=o(t);return(typeof n==`number`&&typeof r==`number`?n-r:String(n).localeCompare(String(r),`fa`))*s})}let s=d(this.query.trim());for(let t of a)t.hidden=!!s&&!d(t.textContent??``).includes(s),e.append(t);if(e.querySelector(`.k-table__empty`)?.remove(),s&&!this.visibleRows().length){let t=i.length;e.insertAdjacentHTML(`beforeend`,`<tr class="k-table__empty"><td colspan="${t}"><p style="padding: 2rem; margin: 0; text-align: center">${r(o().common.noResults)}</p></td></tr>`)}this.selectionChanged(!1)}};f.observedAttributes=[`selectable`,`searchable`,`compact`,`striped`,`sticky-header`,`caption`,`name`],a(`kashi-data-table`,f,`block`);export{f as KashiDataTable};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{M as e,j as t}from"./base-
|
|
1
|
+
import{M as e,j as t}from"./base-w2Oo_bN6.js";function n(n,{digits:r}={}){let i=n.replace(/[يى]/g,`ی`).replace(/ك/g,`ک`).replace(/ة/g,`ه`).replace(/[ً-ٰٟ]/g,``).replace(/ـ/g,``).replace(/{2,}/g,``).replace(/ * */g,``).replace(/[ \t]{2,}/g,` `).trim();return r===`fa`&&(i=e(t(i))),r===`latin`&&(i=t(i)),i}function r(t,{digits:n=!0}={}){let r={arabic:0,zwnj:0,punctuation:0,digits:0,spacing:0},i=(e,t,n,i)=>e.replace(t,(...e)=>(r[i]++,typeof n==`string`?n.replace(/\$(\d)/g,(t,n)=>e[Number(n)]??``):n(...e))),a=`[\\u0621-\\u063A\\u0641-\\u064A\\u067E\\u0686\\u0698\\u06A9\\u06AF\\u06CC]`,o=t;o=i(o,/[يى]/g,`ی`,`arabic`),o=i(o,/ك/g,`ک`,`arabic`),o=i(o,RegExp(`(^|[\\s(«])(ن?می) (?=${a})`,`g`),`$1$2`,`zwnj`),o=i(o,RegExp(`(${a}) (ها|های|هایی|هایم|هایت|هایش|تر|ترین)(?=$|[\\s.،؛؟!»)])`,`g`),`$1$2`,`zwnj`),o=i(o,RegExp(`(${a}\\s*),(?=\\s)`,`g`),`$1،`,`punctuation`),o=i(o,RegExp(`(${a}\\s*)\\?`,`g`),`$1؟`,`punctuation`),o=i(o,RegExp(`(${a}\\s*);`,`g`),`$1؛`,`punctuation`),o=i(o,/ +([،؛؟!.:])(?=\s|$)/g,`$1`,`spacing`),o=i(o,/ {2,}/g,` `,`spacing`),n&&(o=i(o,RegExp(`(${a}[\\s\\u200c]*)(\\d+)|(\\d+)(?=[\\s\\u200c]*${a})`,`g`),(t,n,r,i)=>n?n+e(r):e(i),`digits`));let s=Object.values(r).reduce((e,t)=>e+t,0);return{text:o,fixes:r,count:s}}export{n,r as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e}from"./base-
|
|
1
|
+
import{A as e}from"./base-w2Oo_bN6.js";function t(t){let n=t.trim();if(!n)return null;let r=n.split(/[:٫.،,\s]/).map(e).filter(Boolean),i,a;if(r.length>=2)[i,a]=[Number(r[0]),Number(r[1])];else{let t=e(n);t.length<=2?[i,a]=[Number(t),0]:[i,a]=[Number(t.slice(0,-2)),Number(t.slice(-2))]}return i>=0&&i<24&&a>=0&&a<60?{hours:i,minutes:a}:null}function n({hours:e,minutes:t}){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}export{t as n,n as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/elements",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "وب کامپوننتهای کاشی: فیلدهای فارسی، تقویم شمسی و کامپوننتهای تعاملی بدون React؛ برای HTML، Vue، Svelte، Angular و وردپرس",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"test": "node --test test/*.test.mjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@kashi-ui/bank-logos": "^2.
|
|
31
|
-
"@kashi-ui/persian": "^2.
|
|
30
|
+
"@kashi-ui/bank-logos": "^2.17.0",
|
|
31
|
+
"@kashi-ui/persian": "^2.17.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@kashi-ui/css": "^2.
|
|
34
|
+
"@kashi-ui/css": "^2.17.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"happy-dom": "^21.0.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,c as t,l as n,m as r,o as i,p as a,r as o,t as s,u as c,v as l,y as u}from"./base-BlPZs-0l.js";import{n as d}from"./text-BX7yfRY7.js";const f=[{name:`آذربایجان شرقی`,capital:`تبریز`,areaCode:`41`},{name:`آذربایجان غربی`,capital:`ارومیه`,areaCode:`44`},{name:`اردبیل`,capital:`اردبیل`,areaCode:`45`},{name:`اصفهان`,capital:`اصفهان`,areaCode:`31`},{name:`البرز`,capital:`کرج`,areaCode:`26`},{name:`ایلام`,capital:`ایلام`,areaCode:`84`},{name:`بوشهر`,capital:`بوشهر`,areaCode:`77`},{name:`تهران`,capital:`تهران`,areaCode:`21`},{name:`چهارمحال و بختیاری`,capital:`شهرکرد`,areaCode:`38`},{name:`خراسان جنوبی`,capital:`بیرجند`,areaCode:`56`},{name:`خراسان رضوی`,capital:`مشهد`,areaCode:`51`},{name:`خراسان شمالی`,capital:`بجنورد`,areaCode:`58`},{name:`خوزستان`,capital:`اهواز`,areaCode:`61`},{name:`زنجان`,capital:`زنجان`,areaCode:`24`},{name:`سمنان`,capital:`سمنان`,areaCode:`23`},{name:`سیستان و بلوچستان`,capital:`زاهدان`,areaCode:`54`},{name:`فارس`,capital:`شیراز`,areaCode:`71`},{name:`قزوین`,capital:`قزوین`,areaCode:`28`},{name:`قم`,capital:`قم`,areaCode:`25`},{name:`کردستان`,capital:`سنندج`,areaCode:`87`},{name:`کرمان`,capital:`کرمان`,areaCode:`34`},{name:`کرمانشاه`,capital:`کرمانشاه`,areaCode:`83`},{name:`کهگیلویه و بویراحمد`,capital:`یاسوج`,areaCode:`74`},{name:`گلستان`,capital:`گرگان`,areaCode:`17`},{name:`گیلان`,capital:`رشت`,areaCode:`13`},{name:`لرستان`,capital:`خرمآباد`,areaCode:`66`},{name:`مازندران`,capital:`ساری`,areaCode:`11`},{name:`مرکزی`,capital:`اراک`,areaCode:`86`},{name:`هرمزگان`,capital:`بندرعباس`,areaCode:`76`},{name:`همدان`,capital:`همدان`,areaCode:`81`},{name:`یزد`,capital:`یزد`,areaCode:`35`}],p={"آذربایجان شرقی":/* @__PURE__ */ `آبشاحمد.آچاچی.آذرشهر.آقکند.اسکو.اهر.ایلخچی.باسمنج.بخشایش.بستانآباد.بناب.بناب مرند.تبریز.ترک.ترکمانچای.تسوج.تیکمهداش.تیمورلو.جلفا.جوانقلعه.خاروانا.خامنه.خداجو.خسروشاه.خمارلو.خواجه.دریان.دوزدوزان.زرنق.زنوز.سراب.سردرود.سهند.سیس.سیهرود.شبستر.شربیان.شرفخانه.شندآباد.شهریار.صوفیان.عجبشیر.قرهآغاج.کشکسرای.کلوانق.کلیبر.کوزهکنان.گوگان.لیلان.مبارک آباد.مراغه.مرند.ملکان.ملککیان.ممقان.مهربان.میانه.نظرکهریزی.وایقان.ورزقان.هادیشهر.هریس.هشترود.هوراند.یامچی`.split(`.`),"آذربایجان غربی":/* @__PURE__ */ `آواجیق.ارومیه.اشنویه.ایواوغلی.باروق.بازرگان.بوکان.پلدشت.پیرانشهر.تازهشهر.تکاب.چهاربرج.خلیفان.خوی.دیزج دیز.ربط.زرآباد.سردشت.سرو.سلماس.سیلوانه.سیمینه.سیهچشمه.شاهیندژ.شوط.فیرورق.قرهضیاءالدین.قطور.قوشچی.کشاورز.گردکشانه.ماکو.محمدیار.محمودآباد.مرگنلر.مهاباد.میاندوآب.میرآباد.نازک علیا.نالوس.نقده.نوشینشهر`.split(`.`),اردبیل:[`آبیبیگلو`,`اردبیل`,`اسلامآباد قدیم`,`اصلاندوز`,`انگوت`,`بیلهسوار`,`پارسآباد`,`جعفرآباد`,`خلخال`,`رضی`,`سرعین`,`عنبران`,`قصابه`,`کلور`,`کوراییم`,`گرمی`,`گیوی`,`لاهرود`,`مرادلو`,`مشگینشهر`,`نمین`,`نیر`,`هشجین`,`هیر`],اصفهان:/* @__PURE__ */ `آران و بیدگل.ابریشم.ابوزیدآباد.اردستان.اژیه.اشترجان.اصغرآباد.اصفهان.افوس.انارک.بادرود.باغ بهادران.باغشاد.بافران.برزک.برفانبار.بوئین و میاندشت.بهارانشهر.بهارستان.پیربکران.تودشک.تیران.جندق.جوزدان.جوشقان قالی.جوشقان و کامو.چادگان.چرمهین.چمگردان.حبیب آباد برخوار.حسنآباد.حنا.خالدآباد.خمینیشهر.خوانسار.خور.خوراسگان.خورزوق.داران.دامنه.درچهپیاز.دستگرد.دولتآباد.دهاقان.دهق.دیزیچه.رزوه.رضوانشهر.زازران.زایندهرود.زرینشهر.زواره.زیار.زیباشهر.سده لنجان.سفیدشهر.سگزی.سمیرم.سین.شاپورآباد.شاهینشهر.شهر جدید مجلسی.شهرضا.طالخونچه.طرق.عسگران.علویجه.فرخی.فریدونشهر.فلاورجان.فولادشهر.قمصر.قهجاورستان.قهدریجان.کاشان.کرکوند.کلیشاد و سودرجان.کمشجه.کمه.کوشک.کوهپایه.کهریزسنگ.گرگاب.گز.گلپایگان.گلدشت.گلشن.گلشهر.گوگد.لای بید.مبارکه.محمدآباد.مشکات.منظریه.مهاباد.میمه.نائین.نجفآباد.نصرآباد.نطنز.نوشآباد.نیاسر.نیکآباد.ورزنه.ورنامخواست.وزوان.ونک.هرند.یزدانشهر نجف آباد`.split(`.`),البرز:[`آسارا`,`اشتهارد`,`تنکمان`,`چهارباغ`,`طالقان`,`فردیس`,`کرج`,`کمالشهر`,`کوهسار`,`گرمدره`,`گلسار`,`ماهدشت`,`محمدشهر`,`مشکیندشت`,`مهستان`,`نظرآباد`],ایلام:/* @__PURE__ */ `آبدانان.آسمانآباد.ارکواز.ایلام.ایوان.بدره.بلاوه تره سفلی.پهله.توحید.جعفرآباد.چشمه شیرین.چوار.درهشهر.دلگشا.دهلران.زرنه.سرابباغ.سرابله.شباب.صالحآباد.لومار.ماژین.مورموری.موسیان.مهر.مهران.میمه`.split(`.`),بوشهر:/* @__PURE__ */ `آباد.آبپخش.آبدان.امام حسن.انارستان.اهرم.بادوله.برازجان.بردخون.بردستان.بندر دیر.بندر دیلم.بندر ریگ.بندر سیراف.بندر کنگان.بندر گناوه.بندو.بنک.بوشکان.بوشهر.تنگ ارم.جم.چغادک.خارگ.خورموج.دالکی.دلوار.دوراهک.ریز.سعدآباد.شبانکاره.شنبه.عالیشهر.عسلویه.کاکی.کلمه.نخل تقی.وحدتیه`.split(`.`),تهران:/* @__PURE__ */ `آبسرد.آبعلی.احمدآباد مستوفی.ارجمند.اسلامشهر.اندیشه.باغستان.باقرشهر.بومهن.پاکدشت.پردیس.پرند.پیشوا.تهران.جلیلآباد.جوادآباد.چهاردانگه.حسنآباد.خاورشهر.دماوند.رباطکریم.رودهن.شاهدشهر.شریفآباد.شمشک.شهر ری.شهریار.صالحیه.صباشهر.صفادشت.فردوسیه.فرونآباد.فشم.فیروزکوه.قدس.قرچک.کرشته.کهریزک.کیلان.گلستان.لواسان.ملارد.نسیمشهر.نصیرشهر.وحیدیه.ورامین`.split(`.`),"چهارمحال و بختیاری":/* @__PURE__ */ `آلونی.اردل.باباحیدر.بروجن.بلداجی.بن.پردنجان.تلورد.جونقان.چالشتر.چلگرد.چلیچه.دستنا.دشتک.سامان.سرخون.سردشت.سفیددشت.سودجان.سورشجان.شلمزار.شهرکرد.صمصامی.طاقانک.فارسان.فرادنبه.فرخشهر.کاج.کیان.گندمان.گوجان.گهرو.لردگان.مالخلیفه.منج نسا.ناغان.نافچ.وردنجان.هارونی.هرچگان.هفشجان.یانچشمه`.split(`.`),"خراسان جنوبی":/* @__PURE__ */ `آرینشهر.آیسک.ارسک.اسدیه.اسفدن.اسلامیه.باغستان علیا.بشرویه.بیرجند.حاجیآباد.خضری دشتبیاض.خوسف.درح.دیهوک.زهان.سرایان.سربیشه.سهقلعه.شوسف.طبس.طبس مسینا.عشقآباد.فردوس.قائن.قهستان.گزیک.محمدشهر.مود.نهبندان.نیمبلوک`.split(`.`),"خراسان رضوی":/* @__PURE__ */ `احمدآباد.انابد.باجگیران.باخرز.بار.بایگ.بجستان.بردسکن.بیدخت.بینالود.تایباد.تربت جام.تربت حیدریه.جغتای.جنگل.چاپشلو.چکنه.چناران.خرو.خلیلآباد.خواف.داورزن.دررود.درگز.دولتآباد.رادکان.رباط سنگ.رشتخوار.رضویه.رودآب.ریوش.سبزوار.سرخس.سفیدسنگ.سلامی.سلطانآباد.سنگان.سیدآباد.شادمهر.شاندیز.ششتمد.شهرآباد.شهرزو.شهرکهنه.صالحآباد.طرقبه.عشقآباد.فرگ قلعه.فرهادگرد.فریمان.فیروزه.فیضآباد.قاسمآباد.قدمگاه.قلندرآباد.قوچان.کاخک.کاریز.کاشمر.کدکن.کلات.کندر.گلبهار.گلمکان.گناباد.لطفآباد.مزداوند.مشهد.مشهد ریزه.ملکآباد.نسر.نشتیفان.نصرآباد.نقاب.نوخندان.نیشابور.نیلشهر.همتآباد.یونسی`.split(`.`),"خراسان شمالی":[`آشخانه`,`آوا`,`اسفراین`,`ایور`,`بجنورد`,`پیشقلعه`,`تیتکانلو`,`جاجرم`,`چنارانشهر`,`حصار گرمخان`,`درق`,`راز`,`زیارت`,`سنخواست`,`شوقان`,`شیروان`,`صفیآباد`,`فاروج`,`فیروزه`,`قاضی`,`گرمه`,`لوجلی`],خوزستان:/* @__PURE__ */ `آبادان.آبژدان.آغاجاری.ابوحمیظه.اروندکنار.الوان.الهایی.امیدیه.اندیمشک.اهواز.ایذه.باغملک.بستان.بندر امام خمینی.بندر ماهشهر.بهبهان.بیدروبهمرکزی.ترکالکی.تشان.جایزان.جنتمکان.چغامیش.چم گلک.چمران.چویبده.حر ریاحی.حسینیه.حمیدیه.خرمشهر.دارخوین.دزآب.دزفول.دهدز.رامشیر.رامهرمز.رفیع.زهره.سالند.سردشت.سماله.سوسنگرد.سیاهمنصور.شادگان.شمسآباد.شوش.شوشتر.شهرک حمزه.شیبان.صالح شهر.صفیآباد.صیدون.فتحالمبین.قلعه خواجه.قلعهتل.کوت سیدنعیم طالقانی.کوت عبدالله.گتوند.گوریه.لالی.مسجدسلیمان.مشراگه.مقاومت.ملاثانی.منصوریه.میانرود.میانکوه.میداود.مینوشهر.ویس.هفتکل.هندیجان.هویزه`.split(`.`),زنجان:[`آببر`,`ابهر`,`ارمغانخانه`,`چورزق`,`حلب`,`خرمدره`,`دندی`,`زرینآباد`,`زرینرود`,`زنجان`,`سجاس`,`سلطانیه`,`سهرورد`,`صایینقلعه`,`قیدار`,`کرسف`,`گرماب`,`ماهنشان`,`نیکپی`,`هیدج`],سمنان:[`آرادان`,`امیریه`,`ایوانکی`,`بسطام`,`بیارجمند`,`دامغان`,`درجزین`,`دیباج`,`رودیان`,`سرخه`,`سمنان`,`شاهرود`,`شهمیرزاد`,`کلاته خیج`,`کلاته رودبار`,`کهنآباد`,`گرمسار`,`مجن`,`مهدیشهر`,`میامی`],"سیستان و بلوچستان":/* @__PURE__ */ `آسپیچ محمدی.ادیمی.اسپکه.ایرانشهر.بریس.بزمان.بمپور.بنت.بنجار.پیشین.جالق.چابهار.خاش.دوستمحمد.راسک.رامشار.زابل.زاهدان.زرآباد.زهک.سراوان.سرباز.سوران.سیب.سیرکان.شهرک علیاکبر.فنوج.قصرقند.کنارک.گشت.گلمورتی.محمدآباد.مهرستان.میرجاوه.نصرتآباد.نگور.نوکآباد.نیکشهر.هیدوچ`.split(`.`),فارس:/* @__PURE__ */ `آباده.آباده طشک.ارد.اردکان.ارسنجان.استهبان.اسیر.اشکنان.افزر.اقلید.اوز.اهل.ایج.ایزدخواست.باب انار.بابامنیر.بایگان.بنارویه.بوانات.بهمن.بیرم.بیضا.جنتشهر.جویم.جهرم.حاجیآباد.حسامی.حسنآباد.خانه زنیان.خانیمن.خاوران.خرامه.خشت.خنج.خور.خوزی.خومهزار.داراب.داریان.دبیران.دژکرد.دوبرجی.دوزه.دهرم.رامجرد.رونیز.زاهدشهر.زرقان.سده.سروستان.سعادتشهر.سلطانشهر.سورمق.سیدان.ششده.شهر جدید صدرا.شهرپیر.شهرک امام.شیراز.صغاد.صفاشهر.علامرودشت.عمادشهر.فاروق.فتح آباد.فدامی.فراشبند.فسا.فیروزآباد.فیشور.قائمیه.قادرآباد.قرهبلاغ.قطبآباد.قطرویه.قیر.کازرون.کامفیروز.کرهای.کنارتخته.کوار.کوپن.کوهنجان.گراش.گلهدار.گویم.لار.لامرد.لپوئی.لطیفی.مادرسلیمان.مرودشت.مزایجان.مشکان.مصیری.مهر.میانشهر.میمند.نوبندگان.نوجین.نودان.نورآباد.نیریز.والاشهر.وراوی.هماشهر`.split(`.`),قزوین:[`آبگرم`,`آبیک`,`آوج`,`ارداق`,`اسفرورین`,`اقبالیه`,`الوند`,`بوئینزهرا`,`بیدستان`,`تاکستان`,`خاکعلی`,`خرمدشت`,`دانسفهان`,`رازمیان`,`سگزآباد`,`سیردان`,`شال`,`ضیاءآباد`,`قزوین`,`کوهین`,`محمدیه`,`محمودآباد نمونه`,`معلمکلایه`,`نرجه`],قم:[`جعفریه`,`دستجرد`,`سلفچگان`,`قاهان`,`قم`,`قنوات`,`کهک`],کردستان:/* @__PURE__ */ `آرمرده.اورامان.بابارشانی.بانه.برده رشه.بلبانآباد.بویین سفلی.بیجار.پیرتاج.توپآغاج.چناره.حسنآباد یاسوکند.دزج.دلبران.دهگلان.دیواندره.زرینه.سروآباد.سریشآباد.سقز.سنندج.شویشه.صاحب.قروه.کامیاران.کانیدینار.کانیسور.مریوان.موچش`.split(`.`),کرمان:/* @__PURE__ */ `اختیارآباد.ارزوئیه.امینشهر.انار.اندوهجرد.باغین.بافت.بردسیر.بروات.بزنجان.بلورد.بلوک.بم.بهرمان.پاریز.جبالبارز.جوپار.جوزم.جیرفت.چترود.خاتونآباد.خانوک.خرسند.خواجو شهر.درب بهشت.دشتکار.دوساری.دهج.دهستان بزنجان.رابر.راور.راین.رفسنجان.ریحانشهر.زرند.زنگیآباد.زهکلوت.زیدآباد.سیرجان.سیریز.شهداد.شهربابک.صفائیه.عنبرآباد.فاریاب.فهرج.قلعهگنج.کاظمآباد.کرمان.کشکوئیه.کوهبنان.کهنوج.کیانشهر.گلباف.گلزار.لاله زار.ماهان.محمدآباد.محمدآباد گنبکی.محیآباد.مردهک.مس سرچشمه.منوجان.نجفشهر.نرماشیر.نظامشهر.نگار.نودژ.هجدک.هماشهر.هنزا.یزدانشهر`.split(`.`),کرمانشاه:/* @__PURE__ */ `ازگله.اسلامآباد غرب.بانهوره.باینگان.بیستون.پاوه.تازهآباد.جوانرود.حمیل.روانسر.ریژاو.سرپل ذهاب.سرمست.سطر.سنقر.سومار.شروینه.صحنه.قصر شیرین.قلعه.کرمانشاه.کرند غرب.کنگاور.کوزران.گودین.گهواره.گیلانغرب.ماهیدشت.میانراهان.نودشه.نوسود.هرسین.هلشی`.split(`.`),"کهگیلویه و بویراحمد":[`باشت`,`پاتاوه`,`چرام`,`چیتاب`,`دوگنبدان`,`دهدشت`,`دیشموک`,`سوق`,`سیسخت`,`قلعه رئیسی`,`گراب سفلی`,`لنده`,`لیکک`,`مادوان علیا`,`مارگون`,`محله چینیها`,`یاسوج`],گلستان:/* @__PURE__ */ `آزادشهر.آققلا.انبارآلوم.اینچهبرون.بندر ترکمن.بندر گز.تاتار علیا.خانببین.دلند.رامیان.سرخنکلاته.سنگدوین.سیمینشهر.علیآباد کتول.فاضلآباد.فراغی.قرق.کردکوی.کلاله.گالیکش.گرگان.گمیشان.گنبد کاووس.مراوهتپه.مزرعه.مینودشت.نگینشهر.نوده خاندوز.نوکنده`.split(`.`),گیلان:/* @__PURE__ */ `آستارا.آستانه اشرفیه.احمدسرگوراب.اسالم.اطاقور.املش.بازارجمعه.برهسر.بندر انزلی.بندر کیاشهر.پرهسر.توتکابن.جیرنده.چابکسر.چاف و چمخاله.چوبر.حویق.خشکبیجار.خمام.دیلمان.رانکوه.رحیمآباد.رستمآباد.رشت.رضوانشهر.رودبار.رودبنه.رودسر.سنگر.سیاهکل.شفت.شلمان.صومعهسرا.فومن.کلاچای.کوچصفهان.کومله.گوراب زرمیخ.لاهیجان.لشت نشا.لنگرود.لوشان.لولمان.لوندویل.لیسار.ماسال.ماسوله.ماکلوان.مرجغل.منجیل.واجارگاه.هشتپر`.split(`.`),لرستان:[`ازنا`,`اشترینان`,`الشتر`,`الیگودرز`,`بروجرد`,`بیرانشهر`,`پل دختر`,`چالانچولان`,`چقابل`,`خرمآباد`,`درب گنبد`,`دورود`,`زاغه`,`سپیددشت`,`سرابدوره`,`شولآباد`,`فیروزآباد`,`کونانی`,`کوهدشت`,`گراب لکستان`,`معمولان`,`مومنآباد`,`نورآباد`,`ویسیان`,`هفتچشمه`],مازندران:/* @__PURE__ */ `آلاشت.آمل.ارطه.اکند.امامزاده عبدالله.امیرکلا.ایزدشهر.بابل.بابلسر.بلده.بهشهر.بهنمیر.پایین هولار.پل سفید.پول.تنکابن.جویبار.چالوس.چمستان.خرمآباد.خلیلشهر.خوشرودپی.دابودشت.رامسر.رستمکلا.رویان.رینه.زرگرمحله.زیرآب.ساری.سرخرود.سلمانشهر.سورک.شیرگاه.شیرود.طبقده.عباسآباد.فرحآباد.فریدونکنار.فریم.قائمشهر.کتالم و ساداتشهر.کجور.کلارآباد.کلاردشت.کلهبست.کوهیخیل.کیاسر.کیاکلا.گتاب.گزنک.گلوگاه.محمودآباد.مرزنآباد.مرزیکلا.نشتارود.نکا.نمکآبرود.نور.نوشهر.هچیرود`.split(`.`),مرکزی:/* @__PURE__ */ `آستانه.آشتیان.آوه.اراک.پرندک.تفرش.توره.جاورسیان.خشکرود.خمین.خنجین.خنداب.داوودآباد.دلیجان.رازقان.زاویه.ساروق.ساوه.سنجان.شازند.شهباز.شهر جدید امیرکبیر.غرقآباد.فرمهین.قورچیباشی.کارچان.کرهرود.کمیجان.مأمونیه.محلات.مهاجران.میلاجرد.نراق.نوبران.نیمور.هندودر`.split(`.`),هرمزگان:/* @__PURE__ */ `ابوموسی.بستک.بندر چارک.بندر خمیر.بندر کنگ.بندر لافت.بندر لنگه.بندرعباس.بیکا.پارسیان.تازیان پایین.تخت.تنب بزرگ.تیرور.جاسک.جناح.حاجیآباد.درگهان.دشتی.دهبارز.رویدر.زیارتعلی.سردشت.سرگز احمدی.سندرک.سوزا.سیریک.طبل.فارغان.فین.قشم.قلعه قاضی.کوخردهرنگ.کوهستک.کوهیج.کیش.گروک.گوهران.لمزان.میناب.هرمز.هشتبندی`.split(`.`),همدان:/* @__PURE__ */ `آجین.ازندریان.اسدآباد.برزول.بهار.تویسرکان.جورقان.جوکار.داقداقآباد.دمق.دهستان سلگی.رزن.زنگنه.سامن.سرکان.شیرینسو.صالحآباد.فامنین.فرسفج.فیروزان.قروه درجزین.قهاوند.کبودرآهنگ.گلتپه.گیان.لالجین.مریانج.ملایر.مهاجران.نهاوند.همدان`.split(`.`),یزد:[`ابرکوه`,`احمدآباد`,`اردکان`,`اشکذر`,`بافق`,`بخ`,`بفروییه`,`بهاباد`,`تفت`,`حمیدیا`,`خضرآباد`,`رضوانشهر`,`زارچ`,`شاهدیه`,`عقدا`,`مروست`,`مهردشت`,`مهریز`,`میبد`,`ندوشن`,`نیر`,`هرات`,`یزد`]};function m(e){return e&&p[e]||[]}const h={province:null,city:null,street:``,plaque:``,unit:``,postalCode:``},g=e=>d(e,{digits:`latin`}).toLowerCase();var _=class extends s{constructor(){super(...arguments),this.selected=null,this.query=``,this.list=null,this.filtered=[],this.typing=!1,this.isOpen=!1,this.active=-1,this.rendered=!1,this.valueSet=!1,this.key=u(`kashi-combo`),this.onOutside=e=>{this.contains(e.target)||this.close()}}get defaultLabel(){return null}get defaultPlaceholder(){return``}connectedCallback(){o(()=>{if(this.isConnected){if(!this.rendered){if(this.list===null&&(this.list=this.readOptions()),Object.prototype.hasOwnProperty.call(this,`value`)){let e=this.value;delete this.value,this.value=e??``}else if(!this.valueSet){let e=this.getAttribute(`value`);this.selected=e?this.find(e):null,this.query=this.selected?.label??``}}this.render()}})}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:this.render())}get options(){return this.list??[]}set options(e){this.list=[...e],this.selected&&=this.find(this.selected.value),this.rendered&&this.sync()}get value(){return this.selected?.value??``}set value(e){this.valueSet=!0,this.selected=e?this.find(e):null,this.query=this.selected?.label??``,this.typing=!1,this.rendered&&this.sync()}get selectedOption(){return this.selected}focus(e){this.input?.focus(e)}readOptions(){let e=[];for(let t of[...this.querySelectorAll(`:scope > option, :scope > optgroup > option`)]){let n=t.parentElement?.tagName===`OPTGROUP`?t.parentElement.getAttribute(`label`)??void 0:void 0;e.push({value:t.value,label:t.textContent?.trim()??t.value,description:t.dataset.description,keywords:t.dataset.keywords?.split(/[,،]\s*/),disabled:t.disabled,group:n})}for(let e of[...this.querySelectorAll(`:scope > option, :scope > optgroup`)])e.remove();return e}source(e){return this.options}accepts(e,t){let n=g(t.trim());return!n||[e.label,e.description??``,...e.keywords??[]].some(e=>g(e).includes(n))}find(e){return this.source(``).find(t=>t.value===e)??null}detail(){return{value:this.value,option:this.selected}}render(){let e=this.key,r=this.getAttribute(`aria-label`),i=this.hasAttribute(`label`)?this.getAttribute(`label`):r?null:this.defaultLabel,o=this.hasAttribute(`required`),s=this.hasAttribute(`disabled`),l=`${e}-list`,u=`<div class="k-combobox"><div class="k-input"${s?` data-state="disabled"`:``}><input id="${e}" class="k-input__control" type="text" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="${l}" autocomplete="off" placeholder="${n(this.getAttribute(`placeholder`)??this.defaultPlaceholder)}"${o?` required`:``}${s?` disabled`:``}${!i&&r?` aria-label="${n(r)}"`:``}><button type="button" tabindex="-1" class="k-input__action k-combobox__toggle" aria-label="${n(a().combobox.toggle)}"${s?` disabled`:``}><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 8 4 4 4-4"/></svg></button></div><ul id="${l}" role="listbox" class="k-listbox" hidden style="inset-block-start: calc(100% + 6px)"${i?` aria-label="${n(i)}"`:` aria-labelledby="${e}"`}></ul><span class="k-sr-only" aria-live="polite"></span></div>`;this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,c({id:e,label:i,required:o,control:u})),this.input=this.querySelector(`input.k-input__control`),this.listbox=this.querySelector(`.k-listbox`),this.live=this.querySelector(`.k-combobox > .k-sr-only`),this.isOpen=!1,this.input.addEventListener(`input`,()=>{this.query=this.input.value,this.typing=!0,this.active=-1,this.open(!1),t(this,`kashi-input`,{query:this.query})}),this.input.addEventListener(`keydown`,e=>this.onKey(e)),this.input.addEventListener(`click`,()=>!this.isOpen&&this.open()),this.input.addEventListener(`blur`,e=>{this.contains(e.relatedTarget)||this.close()}),this.querySelector(`.k-combobox__toggle`).addEventListener(`click`,()=>{this.isOpen?this.close():(this.typing=!1,this.open(),this.input.focus())}),this.listbox.addEventListener(`pointerdown`,e=>e.preventDefault()),this.listbox.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&this.commit(this.filtered[Number(t.dataset.i)])}),this.listbox.addEventListener(`pointermove`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&Number(t.dataset.i)!==this.active&&this.setActive(Number(t.dataset.i))}),this.rendered=!0,this.sync()}sync(){!this.typing&&this.input.value!==this.query&&(this.input.value=this.query),e(this.querySelector(`:scope > .k-field`),this.input,this.key,this.getAttribute(`error`),this.getAttribute(`hint`)),this.syncHidden(),this.isOpen&&this.renderList()}syncHidden(){l(this,this.getAttribute(`name`),this.value)}enabled(){return this.filtered.map((e,t)=>e.disabled?-1:t).filter(e=>e>=0)}open(e=!0,t=`selected`){if(!this.hasAttribute(`disabled`)){if(this.isOpen=!0,this.input.setAttribute(`aria-expanded`,`true`),this.listbox.hidden=!1,this.toggleAttribute(`data-open`,!0),this.querySelector(`.k-combobox`).setAttribute(`data-open`,``),this.filter(),e){let e=this.enabled(),n=this.filtered.findIndex(e=>e.value===this.selected?.value);this.active=t===`last`?e.at(-1)??-1:t===`first`||n<0?e[0]??-1:n}this.renderList(),document.addEventListener(`pointerdown`,this.onOutside)}}close(){this.rendered&&(this.isOpen=!1,this.input.setAttribute(`aria-expanded`,`false`),this.input.removeAttribute(`aria-activedescendant`),this.listbox.hidden=!0,this.querySelector(`.k-combobox`).removeAttribute(`data-open`),this.live.textContent=``,document.removeEventListener(`pointerdown`,this.onOutside),this.typing&&(this.typing=!1,this.query=this.selected?.label??``,this.input.value=this.query))}filter(){let e=this.source(this.typing?this.query:``);this.filtered=this.typing?e.filter(e=>this.accepts(e,this.query)):e}renderList(){let e=this.typing?g(this.query.trim()):``,t=t=>{let r=e?g(t).indexOf(e):-1;return r<0?n(t):`${n(t.slice(0,r))}<mark>${n(t.slice(r,r+e.length))}</mark>${n(t.slice(r+e.length))}`},i=`${this.key}-list`,o,s=this.filtered.slice(0,300).map((e,r)=>{let a=e.group&&e.group!==o?`<li role="presentation" class="k-listbox__group">${n(e.group)}</li>`:``;o=e.group;let s=e.value===this.selected?.value;return`${a}<li id="${i}-${r}" data-i="${r}" role="option" aria-selected="${s}"${e.disabled?` aria-disabled="true"`:``}${r===this.active?` data-active`:``} class="k-option"><span class="k-option__body"><span>${t(e.label)}</span>${e.description?`<span class="k-option__desc">${n(e.description)}</span>`:``}</span>${s?`<span class="k-option__check"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 10.5 3.2 3L15 7"/></svg></span>`:``}</li>`});this.filtered.length||s.push(`<li class="k-listbox__empty" role="presentation">${n(this.getAttribute(`empty-message`)??a().common.noResults)}</li>`),this.filtered.length>300&&s.push(`<li class="k-listbox__empty" role="presentation">${n(a().combobox.more(r(this,this.filtered.length-300)))}</li>`),this.listbox.innerHTML=s.join(``),this.live.textContent=this.typing?a().common.results(r(this,this.filtered.length)):``,this.setActive(this.active)}setActive(e){this.active=e,this.listbox.querySelector(`[data-active]`)?.removeAttribute(`data-active`);let t=e>=0?this.listbox.querySelector(`[data-i="${e}"]`):null;t?(t.setAttribute(`data-active`,``),t.scrollIntoView?.({block:`nearest`}),this.input.setAttribute(`aria-activedescendant`,t.id)):this.input.removeAttribute(`aria-activedescendant`)}move(e){let t=this.enabled().filter(e=>e<300);if(!t.length)return;let n=t.indexOf(this.active);this.setActive(t[(n+e+t.length)%t.length])}onKey(e){if(e.key===`ArrowDown`)e.preventDefault(),this.isOpen?this.move(1):this.open(!0,e.altKey?`selected`:`first`);else if(e.key===`ArrowUp`)e.preventDefault(),this.isOpen?this.move(-1):this.open(!0,`last`);else if(e.key===`Enter`&&this.isOpen&&this.active>=0)e.preventDefault(),this.commit(this.filtered[this.active]);else if(e.key===`Escape`)this.isOpen?(e.preventDefault(),this.close()):this.input.value&&(e.preventDefault(),this.commit(null));else if((e.key===`Home`||e.key===`End`)&&this.isOpen){e.preventDefault();let t=this.enabled();this.setActive((e.key===`Home`?t[0]:t.at(-1))??-1)}}commit(e){let n=(e?.value??null)!==(this.selected?.value??null);this.selected=e,this.query=e?.label??``,this.typing=!1,this.input.value=this.query,this.close(),this.sync(),n&&t(this,`kashi-change`,this.detail())}};_.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`required`,`disabled`,`name`,`value`,`empty-message`,`aria-label`];var v=class extends _{get defaultLabel(){return a().province.label}get defaultPlaceholder(){return a().province.search}source(){let e=this.getAttribute(`show-capital`)!==`false`;return f.map(t=>({value:t.name,label:t.name,description:e?a().province.capital(t.capital):void 0,keywords:[t.capital]}))}detail(){return{value:this.value,province:f.find(e=>e.name===this.value)??null}}};v.observedAttributes=[..._.observedAttributes,`show-capital`];const y=e=>g(e).replace(/[\s]/g,``);var b=class extends _{constructor(){super(...arguments),this.custom=null}get defaultLabel(){return a().city.label}get defaultPlaceholder(){return this.placeholderText()}get province(){return this.getAttribute(`province`)||null}set province(e){e?this.setAttribute(`province`,e):this.removeAttribute(`province`)}get value(){return this.selected?this.selected.value.split(`|`)[1]:``}set value(e){this.valueSet=!0,this.custom=null;let t=this.source(``),n=this.province,r=e?t.find(t=>t.label===e&&(!n||t.value.startsWith(`${n}|`)))??null:null;e&&!r&&(this.custom=e,r={value:`custom|${e}`,label:e,description:a().city.outside}),this.selected=r,this.query=r?.label??``,this.isConnected&&this.querySelector(`.k-combobox`)&&this.sync()}find(e){return this.value=e,this.selected}attributeChangedCallback(e,t,n){if(e!==`province`)return super.attributeChangedCallback(e,t,n);if(t!==n){if(this.selected){let e=this.value;!n||!m(n).includes(e)?(this.selected=null,this.query=``,this.custom=null):this.selected={value:`${n}|${e}`,label:e}}this.querySelector(`.k-combobox`)&&(this.input.placeholder=this.getAttribute(`placeholder`)??this.placeholderText(),this.input.value=this.query,this.sync())}}connectedCallback(){super.connectedCallback()}placeholderText(){return this.province?a().city.search:a().city.hint}source(e){let t=this.province,n=t?m(t).map(e=>({value:`${t}|${e}`,label:e})):Object.entries(p).flatMap(([e,t])=>t.map(t=>({value:`${e}|${t}`,label:t,description:e})));this.custom&&n.unshift({value:`custom|${this.custom}`,label:this.custom,description:a().city.outside});let r=e.trim();return this.getAttribute(`allow-custom`)!==`false`&&r&&r!==this.custom&&!n.some(e=>y(e.label)===y(r))&&n.push({value:`custom|${r}`,label:r,description:a().city.custom}),n}accepts(e,t){return e.value.startsWith(`custom|`)||[e.label,e.description??``].some(e=>y(e).includes(y(t)))}commit(e){this.custom=e?.value.startsWith(`custom|`)?e.label:null,super.commit(e)}detail(){let[e]=this.selected?this.selected.value.split(`|`):[null];return{value:this.value,province:e===`custom`?null:e}}};b.observedAttributes=[..._.observedAttributes,`province`,`allow-custom`],i(`kashi-combobox`,_,`block`),i(`kashi-province-select`,v,`block`),i(`kashi-city-select`,b,`block`);export{b as KashiCitySelect,_ as KashiCombobox,v as KashiProvinceSelect,m as n,f as r,g as searchText,h as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e,S as t,c as n,d as r,k as i,l as a,o,p as s,s as c,t as l,x as u}from"./base-BlPZs-0l.js";import{t as d}from"./words-BdADG_9U.js";const f={دقیقه:`minute`,ساعت:`hour`,روز:`day`,هفته:`week`,ماه:`month`,سال:`year`},p=6e4,m=60*p,h=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();function g(t,{now:n=/* @__PURE__ */ new Date,locale:r=`fa`,digits:i=r===`en`?`latin`:`fa`}={}){let a=r===`en`,o=t.getTime()-n.getTime(),s=o<0,c=Math.abs(o),l=t=>i===`fa`?e(t):String(t),u=(e,t)=>{if(!a)return`${l(e)} ${t} ${s?`پیش`:`دیگر`}`;let n=`${f[t]}${e===1?``:`s`}`;return s?`${l(e)} ${n} ago`:`in ${l(e)} ${n}`};if(c<45e3)return a?`just now`:`همین الان`;if(c<m)return u(Math.max(1,Math.round(c/p)),`دقیقه`);let d=Math.round((h(t)-h(n))/864e5);if(c<6*m||d===0)return u(Math.round(c/m),`ساعت`);if(d===-1)return a?`yesterday`:`دیروز`;if(d===1)return a?`tomorrow`:`فردا`;let g=Math.abs(d);return g<7?u(g,`روز`):g<30?u(Math.round(g/7),`هفته`):g<365?u(Math.max(1,Math.round(g/30.44)),`ماه`):u(Math.round(g/365.25),`سال`)}const _={همت:`trillion`,میلیارد:`billion`,میلیون:`million`,هزار:`thousand`},v=[[0xe8d4a51000,`همت`],[1e9,`میلیارد`],[1e6,`میلیون`],[1e3,`هزار`]],y=e=>Math.round(e/10),b=e=>e*10;function x(t,{unit:n=`toman`,from:r=`toman`,compact:a=!1,showUnit:o=!0,locale:s=`fa`,digits:c=s===`en`?`latin`:`fa`}={}){let l=s===`en`,u=r===n?t:r===`rial`?y(t):b(t),d=u<0?`−`:``;u=Math.abs(u);let f=i(Math.round(u),{digits:c}),p=l?n===`toman`?`Toman`:`Rial`:n===`toman`?`تومان`:`ریال`;if(a){let t=v.find(([e,t])=>u>=e&&(t!==`همت`||n===`toman`&&!l));if(t){let n=Math.round(u/t[0]*100)/100,r=String(n).replace(`.`,c===`fa`?`٫`:`.`);f=`${c===`fa`?e(r):r} ${l?_[t[1]]:t[1]}`,t[1]===`همت`&&(p=``)}}return`${d}${f}${o&&p?` ${p}`:``}`}const S=e=>{if(!e)return null;let n=t(e.trim())??new Date(e);return Number.isNaN(n.getTime())?null:n};var C=class extends l{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}},w=class extends C{render(){let e=Number(this.getAttribute(`value`)??0),t=this.getAttribute(`unit`)===`rial`?`rial`:`toman`,n=this.getAttribute(`from`)===`rial`?`rial`:this.getAttribute(`from`)===`toman`?`toman`:t,i=this.hasAttribute(`compact`),o=c(this),l=this.hasAttribute(`signed`),u=this.getAttribute(`size`)??`md`,f=n===t?e:n===`rial`?y(e):b(e),p=r(),m=s(),h=x(f,{unit:t,compact:i,digits:o,locale:p,showUnit:!1}),g=x(f,{unit:t,compact:i,locale:p}),_=t===`toman`?m.money.toman:m.money.rial,v=g.endsWith(`همت`)?null:_,S=this.getAttribute(`words`)!==`false`&&Number.isSafeInteger(Math.round(f))?`${d(Math.round(f),{locale:p})} ${_}`:null,C=l?f>0?`positive`:f<0?`negative`:null:null,w=S?` aria-hidden="true"`:``;this.innerHTML=`<data value="${f}" class="k-money k-money--${a(u)}"${C?` data-tone="${C}"`:``}${S?` title="${a(S)}"`:``}><span class="k-money__amount"${w}>${l&&f>0?`+`:``}${a(h)}</span>${v?`<span class="k-money__unit"${w}>${v}</span>`:``}${S?`<span class="k-sr-only">${f<0?``:l&&f>0?m.money.positive:``}${a(S)}</span>`:``}</data>`}};w.observedAttributes=[`value`,`unit`,`from`,`compact`,`digits`,`signed`,`words`,`size`];var T=class extends C{render(){let e=S(this.getAttribute(`datetime`));if(!e){this.textContent=``;return}let t=this.getAttribute(`format`),n=t===`numeric`||t===`full`?t:`long`,i=c(this);this.innerHTML=`<time datetime="${a(this.getAttribute(`datetime`))}">${a(u(e,{style:n,digits:i,locale:r()}))}</time>`}};T.observedAttributes=[`datetime`,`format`,`digits`];var E=class extends C{connectedCallback(){super.connectedCallback(),clearInterval(this.timer),this.timer=setInterval(()=>this.render(),Number(this.getAttribute(`refresh`))||6e4)}disconnectedCallback(){clearInterval(this.timer)}render(){let e=S(this.getAttribute(`datetime`));if(!e){this.textContent=``;return}let t=c(this);this.innerHTML=`<time datetime="${e.toISOString()}" title="${a(u(e,{style:`full`,digits:t,locale:r()}))}">${a(g(e,{digits:t,locale:r()}))}</time>`}};E.observedAttributes=[`datetime`,`digits`,`refresh`];const D=e=>String(e).padStart(2,`0`);var O=class extends l{constructor(){super(...arguments),this.end=0,this.done=!1}connectedCallback(){this.restart()}disconnectedCallback(){clearInterval(this.timer)}attributeChangedCallback(e,t,n){this.isConnected&&t!==n&&(e===`to`||e===`seconds`?this.restart():this.render())}restart(){let e=S(this.getAttribute(`to`));this.end=e?e.getTime():Date.now()+(Number(this.getAttribute(`seconds`))||0)*1e3,this.done=!1,clearInterval(this.timer),this.render(),this.timer=setInterval(()=>this.render(),1e3)}get remaining(){return Math.max(0,Math.ceil((this.end-Date.now())/1e3))}render(){let t=this.remaining,r=Math.floor(t/86400),i=Math.floor(t%86400/3600),o=Math.floor(t%3600/60),l=t%60,u=c(this)===`fa`,d=t=>u?e(String(t)):String(t),f=s().countdown,p=[r&&`${d(r)} ${f.days}`,i&&`${d(i)} ${f.hours}`,o&&`${d(o)} ${f.minutes}`,`${d(l)} ${f.seconds}`].filter(Boolean).join(s().common.and),m=this.getAttribute(`label`),h=a(m?`${m}: ${p}`:p),g=t===0?` data-done=""`:``;if(this.getAttribute(`variant`)===`blocks`){let e=[...r?[[r,f.days]]:[],[i,f.hours],[o,f.minutes],[l,f.seconds]];this.innerHTML=`<div role="timer" aria-label="${h}" class="k-countdown k-countdown--blocks"${g}>${e.map(([e,t])=>`<span class="k-countdown__unit" aria-hidden="true"><span class="k-countdown__num">${d(D(e))}</span><span class="k-countdown__name">${t}</span></span>`).join(``)}</div>`}else{let e=(r?`${r}:`:``)+(i||r?`${D(i)}:`:``)+`${D(o)}:${D(l)}`;this.innerHTML=`<span role="timer" aria-label="${h}" class="k-countdown"${g} dir="ltr"><span aria-hidden="true">${d(e)}</span></span>`}t===0&&(clearInterval(this.timer),this.done||(this.done=!0,n(this,`kashi-complete`,{})))}};O.observedAttributes=[`to`,`seconds`,`variant`,`digits`,`label`],o(`kashi-money`,w),o(`kashi-date`,T),o(`kashi-relative-time`,E),o(`kashi-countdown`,O);export{O as KashiCountdown,T as KashiDate,w as KashiMoney,E as KashiRelativeTime};
|