@kashi-ui/elements 2.24.0 → 2.25.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.
Files changed (75) hide show
  1. package/README.md +3 -3
  2. package/dist/base.d.ts +110 -0
  3. package/dist/capture.d.ts +75 -0
  4. package/dist/capture.js +456 -0
  5. package/dist/cdn/{appointment-DOXBUwIU.js → appointment-BaEWfjSX.js} +1 -1
  6. package/dist/cdn/base-BqFAMlwG.js +1 -0
  7. package/dist/cdn/{basic-DuY4RslZ.js → basic-BBvsRt91.js} +1 -1
  8. package/dist/cdn/{buttons-BaK6bx3w.js → buttons-BmP5wikN.js} +1 -1
  9. package/dist/cdn/{calendar-BulPeVAJ.js → calendar-CwKogl-G.js} +1 -1
  10. package/dist/cdn/capture-B48H5hmR.js +24 -0
  11. package/dist/cdn/{card-BKiwJF34.js → card-C0nariT-.js} +1 -1
  12. package/dist/cdn/{cards-DKarXHsC.js → cards-D9-wNDK8.js} +1 -1
  13. package/dist/cdn/{charts-ETYOAJyB.js → charts-Cct32znI.js} +1 -1
  14. package/dist/cdn/{chat-D5ZIMnNp.js → chat-Dg5CEN6Y.js} +1 -1
  15. package/dist/cdn/{choice-DBvC2Puo.js → choice-cDqbHUTC.js} +1 -1
  16. package/dist/cdn/combobox-Drm8K9Zk.js +1 -0
  17. package/dist/cdn/commerce-JkDctt2h.js +1 -0
  18. package/dist/cdn/{content-BgfBfy8j.js → content-CqUXcDCi.js} +1 -1
  19. package/dist/cdn/{controls--OMZkJYe.js → controls-CquzGwtr.js} +1 -1
  20. package/dist/cdn/{display-BfYWAjNu.js → display-DW5JEQXT.js} +1 -1
  21. package/dist/cdn/{fields-B-jTUQiI.js → fields-C-ytjZil.js} +1 -1
  22. package/dist/cdn/forms-CurTYl2V.js +1 -0
  23. package/dist/cdn/gantt-QfHFG7O8.js +14 -0
  24. package/dist/cdn/{holidays-Cu6IfbTL.js → holidays-DgmHlqJX.js} +1 -1
  25. package/dist/cdn/{hours-CeiVqPKD.js → hours-CmICISQO.js} +1 -1
  26. package/dist/cdn/inputs-DWLKbi57.js +1 -0
  27. package/dist/cdn/invoice-BUMyjBVi.js +10 -0
  28. package/dist/cdn/kashi-elements.js +1 -1
  29. package/dist/cdn/{legal-id-Mt8FX0fV.js → legal-id-B_0kbcQT.js} +1 -1
  30. package/dist/cdn/lists-D0dao20N.js +1 -0
  31. package/dist/cdn/{map-TfSt3CjL.js → map-BxlzfCbM.js} +1 -1
  32. package/dist/cdn/{media-BRBINvzU.js → media-QVgCYQSu.js} +1 -1
  33. package/dist/cdn/{menu-DTNVFXrb.js → menu-DcFyTTHv.js} +1 -1
  34. package/dist/cdn/{money-CjGI2VIQ.js → money-BFEbgLJn.js} +1 -1
  35. package/dist/cdn/{nav-CT5RVOzy.js → nav-Cm8mAT09.js} +1 -1
  36. package/dist/cdn/{overlay-CS8piW6X.js → overlay-C1nbLv6h.js} +1 -1
  37. package/dist/cdn/pickers-DQgK1WAX.js +1 -0
  38. package/dist/cdn/{relative-OC1fV3Xh.js → relative-BoBZPiB7.js} +1 -1
  39. package/dist/cdn/{rich-text-CS6xEim6.js → rich-text-9IAZ_T8A.js} +1 -1
  40. package/dist/cdn/search-BvShDz2X.js +1 -0
  41. package/dist/cdn/{sheets-eVMx4d-5.js → sheets-CNF5lSVn.js} +1 -1
  42. package/dist/cdn/table-D1xiHZCM.js +2 -0
  43. package/dist/cdn/{text-C6fzEBBh.js → text-DFyW6cuq.js} +1 -1
  44. package/dist/cdn/{time-CkqqUKJv.js → time-CYZzyy_3.js} +1 -1
  45. package/dist/cdn/{time-CwOYrtK-.js → time-oyKIQ2bk.js} +1 -1
  46. package/dist/cdn/{validate-Dr2f6i6s.js → validate-CRU7rfNs.js} +1 -1
  47. package/dist/cdn/{work-DoNAKgVU.js → work-DS2MbtGM.js} +1 -1
  48. package/dist/cdn.js +5 -1
  49. package/dist/combobox.js +4 -4
  50. package/dist/commerce.js +2 -2
  51. package/dist/content.js +2 -1
  52. package/dist/gantt.d.ts +41 -0
  53. package/dist/gantt.js +179 -0
  54. package/dist/index.d.ts +18 -3
  55. package/dist/index.js +8 -3
  56. package/dist/inputs.d.ts +16 -0
  57. package/dist/inputs.js +62 -2
  58. package/dist/invoice.d.ts +52 -0
  59. package/dist/invoice.js +75 -0
  60. package/dist/lists.d.ts +57 -0
  61. package/dist/lists.js +306 -0
  62. package/dist/manifest.json +168 -3
  63. package/dist/pickers.d.ts +4 -0
  64. package/dist/pickers.js +34 -6
  65. package/dist/sheets.js +1 -1
  66. package/dist/table.d.ts +15 -1
  67. package/dist/table.js +184 -5
  68. package/package.json +4 -4
  69. package/dist/cdn/base-D4tCOysh.js +0 -1
  70. package/dist/cdn/combobox-BGuPAAt3.js +0 -1
  71. package/dist/cdn/commerce-SzWdpWJG.js +0 -1
  72. package/dist/cdn/forms-DgRiYmdV.js +0 -1
  73. package/dist/cdn/inputs-BkJ70Xkc.js +0 -1
  74. package/dist/cdn/pickers-BwDRsDRo.js +0 -1
  75. package/dist/cdn/table-tgB4iwcM.js +0 -1
@@ -1 +1 @@
1
- import{c as e,i as t,l as n,o as r,p as i,r as a,t as o,y as s}from"./base-D4tCOysh.js";import{i as c}from"./parts-5fVaWtRe.js";const l=[`name`,`value`,`form`,`target`,`rel`,`download`,`aria-controls`,`aria-expanded`,`aria-haspopup`,`aria-pressed`,`aria-describedby`,`title`];var u=class extends o{constructor(){super(...arguments),this.el=null}connectedCallback(){a(()=>{this.isConnected&&(this.ensure(),this.update())})}attributeChangedCallback(e,t,n){this.el&&t!==n&&(this.ensure(),this.update())}get control(){return this.el}focus(e){this.el?.focus(e)}click(){this.el?.click()}ensure(){let e=this.hasAttribute(`href`)?`A`:`BUTTON`;if(this.el?.tagName===e)return;let t=document.createElement(e);t.append(...this.el?this.el.childNodes:this.childNodes),this.el?.remove(),this.el=t,this.append(t),t.addEventListener(`click`,e=>{t.getAttribute(`aria-disabled`)===`true`&&(e.preventDefault(),e.stopImmediatePropagation())})}update(){let e=this.el,r=this.getAttribute(`variant`)??`secondary`,a=this.getAttribute(`size`)??`md`,o=this.getAttribute(`shape`)??`default`,s=t(this,`loading`),u=t(this,`disabled`),d=e.tagName===`BUTTON`,f=s||!d&&u;if(e.className=c(`k-btn`,`k-btn--${r}`,a!==`md`&&`k-btn--${a}`,o!=="default"&&`k-btn--${o}`,t(this,`block`)&&`k-btn--block`,t(this,`icon-only`)&&`k-btn--icon`),e.dataset.variant=r,e.dataset.size=a,d){let t=e;t.type=this.getAttribute(`type`)??`button`,t.disabled=u}else{let t=this.getAttribute(`href`);t&&!f?e.setAttribute(`href`,t):e.removeAttribute(`href`)}for(let t of l){let n=this.getAttribute(t);n===null?e.removeAttribute(t):e.setAttribute(t,n)}let p=this.getAttribute(`label`);p?e.setAttribute(`aria-label`,p):e.removeAttribute(`aria-label`),f?e.setAttribute(`aria-disabled`,`true`):e.removeAttribute(`aria-disabled`),s?e.setAttribute(`aria-busy`,`true`):e.removeAttribute(`aria-busy`);let m=e.querySelector(`:scope > [data-kashi-loading]`);s&&!m?e.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" role="status" data-kashi-loading>${n(this.getAttribute(`loading-label`)??i().common.loading)}</span>`):s||m?.remove()}};u.observedAttributes=[`variant`,`size`,`shape`,`loading`,`loading-label`,`block`,`icon-only`,`disabled`,`type`,`href`,`label`,...l];var d=class extends o{constructor(){super(...arguments),this.box=null}connectedCallback(){a(()=>{this.isConnected&&(this.box||(this.box=document.createElement(`div`),this.box.setAttribute(`role`,`group`),this.box.className=`k-btn-group`,this.box.append(...this.childNodes),this.append(this.box),this.box.addEventListener(`click`,e=>this.onClick(e))),this.update())})}attributeChangedCallback(){this.box&&this.update()}get buttons(){return[...this.box.querySelectorAll(`:scope > .k-btn`)]}get value(){let e=this.box?this.buttons.filter(e=>e.getAttribute(`aria-pressed`)===`true`).map(e=>e.dataset.value??e.textContent?.trim()??``):[];return this.getAttribute(`toggle`)===`multiple`?e:e[0]??``}set value(e){let t=Array.isArray(e)?e:[e];a(()=>this.box&&this.buttons.forEach(e=>e.setAttribute(`aria-pressed`,String(t.includes(e.dataset.value??``)))))}update(){let e=this.getAttribute(`label`);if(e?this.box.setAttribute(`aria-label`,e):this.box.removeAttribute(`aria-label`),this.getAttribute(`toggle`))for(let e of this.buttons)e.hasAttribute(`aria-pressed`)||e.setAttribute(`aria-pressed`,`false`)}onClick(t){let n=this.getAttribute(`toggle`),r=t.target.closest(`.k-btn`);if(!n||!r||r.parentElement!==this.box||r.disabled)return;let i=r.getAttribute(`aria-pressed`)===`true`;if(n===`single`)for(let e of this.buttons)e.setAttribute(`aria-pressed`,`false`);r.setAttribute(`aria-pressed`,String(!i)),e(this,`kashi-change`,{value:this.value})}};d.observedAttributes=[`label`,`toggle`];var f=class extends o{constructor(){super(...arguments),this.box=null,this.current=``,this.ro=null,this.key=s(`kashi-seg`)}connectedCallback(){a(()=>{this.isConnected&&(this.box||this.build(),this.update(),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.box)))})}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?this.select(n??``,!1):this.update())}get value(){return this.current}set value(e){this.box?this.select(String(e??``),!1):this.setAttribute(`value`,String(e??``))}build(){let e=[...this.querySelectorAll(`:scope > option`)],n=document.createElement(`div`);n.setAttribute(`role`,`radiogroup`),n.innerHTML=`<span class="k-segmented__indicator" aria-hidden="true"></span>`;for(let t of e){let e=document.createElement(`label`);e.className=`k-segmented__item`;let r=document.createElement(`input`);r.type=`radio`,r.className=`k-sr-only`,r.value=t.value,r.disabled=t.disabled,t.disabled&&r.setAttribute(`data-off`,``);let i=t.getAttribute(`aria-label`);i&&r.setAttribute(`aria-label`,i),e.append(r),t.dataset.icon&&e.insertAdjacentHTML(`beforeend`,t.dataset.icon),t.textContent?.trim()&&e.append(t.textContent.trim()),n.append(e)}for(let t of e)t.remove();this.current=this.getAttribute(`value`)??e.find(e=>e.selected&&e.hasAttribute(`selected`))?.value??e.find(e=>!e.disabled)?.value??``,n.addEventListener(`change`,e=>{let n=e.target;t(this,`readonly`)?this.paint():this.select(n.value,!0)}),n.addEventListener(`click`,e=>{t(this,`readonly`)&&e.target.closest(`input`)&&e.preventDefault()}),this.append(n),this.box=n}select(t,n){if(t===this.current&&!n)return this.paint();this.current=t,this.paint(),n&&e(this,`kashi-change`,{value:t})}update(){let e=this.box;e.className=c(`k-segmented`,this.getAttribute(`size`)===`sm`&&`k-segmented--sm`,t(this,`block`)&&`k-segmented--block`);let n=this.getAttribute(`label`)??this.getAttribute(`aria-label`);n?e.setAttribute(`aria-label`,n):e.removeAttribute(`aria-label`);let r=t(this,`readonly`);e.toggleAttribute(`data-readonly`,r),r?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`);let i=this.getAttribute(`name`)??this.key,a=t(this,`disabled`);for(let t of e.querySelectorAll(`input`))t.name=i,a?t.disabled=!0:t.hasAttribute(`data-off`)||(t.disabled=!1);this.paint()}paint(){for(let e of this.box.querySelectorAll(`input`))e.checked=e.value===this.current;this.measure()}measure(){let e=this.box;if(!e)return;let t=[...e.querySelectorAll(`.k-segmented__item`)].find(e=>e.querySelector(`input`).checked);!t||!t.offsetWidth?e.removeAttribute(`data-indicator`):(e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.setAttribute(`data-indicator`,``))}};f.observedAttributes=[`value`,`name`,`size`,`block`,`disabled`,`readonly`,`label`,`aria-label`];var p=class extends o{constructor(){super(...arguments),this.nav=null,this.items=[],this.expanded=!1}connectedCallback(){a(()=>{this.isConnected&&(this.nav||this.build(),this.update())})}attributeChangedCallback(){this.nav&&this.update()}build(){this.items=[...this.children].filter(e=>e instanceof HTMLElement);for(let e of this.items){let t=e.hasAttribute(`data-icon-only`);e.classList.add(`k-breadcrumb__link`),t&&e.classList.add(`k-breadcrumb__link--icon`);let n=[...e.childNodes].filter(e=>e.nodeType===3&&e.textContent?.trim()),r=n.map(e=>e.textContent.trim()).join(` `);if(n.length){let i=document.createElement(`span`);i.className=t?`k-sr-only`:`k-breadcrumb__text`,i.textContent=r,n[0].replaceWith(i);for(let e of n.slice(1))e.remove();!t&&!e.title&&(e.title=r)}}this.nav=document.createElement(`nav`),this.nav.innerHTML=`<ol></ol>`,this.replaceChildren(this.nav),this.nav.addEventListener(`click`,e=>{e.target.closest(`[data-expand]`)&&(this.expanded=!0,this.update(),this.nav.querySelectorAll(`.k-breadcrumb__link`)[1]?.focus())})}update(){let e=this.nav;e.className=c(`k-breadcrumb`,this.getAttribute(`separator`)===`slash`&&`k-breadcrumb--slash`),e.setAttribute(`aria-label`,this.getAttribute(`label`)??i().breadcrumb.label);let t=Number(this.getAttribute(`max-items`))||0,r=this.items,a=!this.expanded&&t>=2&&r.length>t?[r[0],`…`,...r.slice(r.length-(t-1))]:r;r.forEach((e,t)=>{t===r.length-1?e.setAttribute(`aria-current`,`page`):e.getAttribute(`aria-current`)===`page`&&e.removeAttribute(`aria-current`)}),e.querySelector(`ol`).replaceChildren(...a.map(e=>{let t=document.createElement(`li`);return e===`…`?t.innerHTML=`<button type="button" class="k-breadcrumb__link" data-expand aria-label="${n(this.getAttribute(`expand-label`)??i().breadcrumb.expand)}">…</button>`:t.append(e),t}))}};p.observedAttributes=[`max-items`,`separator`,`label`,`expand-label`];var m=class extends o{constructor(){super(...arguments),this.box=null,this.key=s(`k-acc`)}connectedCallback(){a(()=>{this.isConnected&&(this.box||this.build(),this.update())})}attributeChangedCallback(){this.box&&this.update()}get details(){return[...this.box.querySelectorAll(`:scope > details`)]}build(){let t=document.createElement(`div`);for(let e of[...this.children]){let n;if(e.tagName===`DETAILS`)n=e;else if(e.hasAttribute(`data-title`)){n=document.createElement(`details`),n.innerHTML=`<summary></summary>`;let t=n.querySelector(`summary`),r=e.getAttribute(`data-description`);r?(t.innerHTML=`<span class="k-accordion__head"><span class="k-accordion__titles"><span class="k-accordion__title"></span><span class="k-accordion__description"></span></span></span>`,t.querySelector(`.k-accordion__title`).textContent=e.getAttribute(`data-title`),t.querySelector(`.k-accordion__description`).textContent=r):t.textContent=e.getAttribute(`data-title`),n.open=e.hasAttribute(`data-open`),e.hasAttribute(`data-disabled`)&&n.setAttribute(`data-disabled`,``),e.hasAttribute(`data-value`)&&(n.dataset.value=e.getAttribute(`data-value`));let i=document.createElement(`div`);i.append(...e.childNodes),n.append(i)}else continue;n.classList.add(`k-accordion__item`);let r=n.querySelector(`:scope > summary`);r?.classList.add(`k-accordion__trigger`),n.hasAttribute(`data-disabled`)&&r&&(n.classList.add(`k-accordion__item--disabled`),r.setAttribute(`aria-disabled`,`true`),r.tabIndex=-1,r.addEventListener(`click`,e=>e.preventDefault()));let i=[...n.childNodes].filter(e=>e!==r);if(!(i.length===1&&i[0]instanceof HTMLElement&&i[0].classList.contains(`k-accordion__content`)&&i[0])){let e=document.createElement(`div`);e.className=`k-accordion__content`,e.append(...i),n.append(e)}t.append(n)}this.replaceChildren(t),this.box=t,t.addEventListener(`toggle`,n=>{let r=n.target;if(r.parentElement===t){if(r.open&&this.getAttribute(`type`)===`single`)for(let e of this.details)e!==r&&e.open&&(e.open=!1);e(this,`kashi-toggle`,{index:this.details.indexOf(r),value:r.dataset.value,open:r.open})}},!0)}update(){this.box.className=c(`k-accordion`,t(this,`flush`)&&`k-accordion--flush`,this.getAttribute(`size`)===`sm`&&`k-accordion--sm`);let e=this.getAttribute(`type`)===`single`;for(let t of this.details)e?t.setAttribute(`name`,this.key):t.removeAttribute(`name`)}};m.observedAttributes=[`type`,`flush`,`size`],r(`kashi-button`,u),r(`kashi-button-group`,d),r(`kashi-segmented-control`,f),r(`kashi-breadcrumb`,p,`block`),r(`kashi-accordion`,m,`block`);export{m as KashiAccordion,p as KashiBreadcrumb,u as KashiButton,d as KashiButtonGroup,f as KashiSegmentedControl};
1
+ import{c as e,i as t,l as n,o as r,p as i,r as a,t as o,y as s}from"./base-BqFAMlwG.js";import{i as c}from"./parts-5fVaWtRe.js";const l=[`name`,`value`,`form`,`target`,`rel`,`download`,`aria-controls`,`aria-expanded`,`aria-haspopup`,`aria-pressed`,`aria-describedby`,`title`];var u=class extends o{constructor(){super(...arguments),this.el=null}connectedCallback(){a(()=>{this.isConnected&&(this.ensure(),this.update())})}attributeChangedCallback(e,t,n){this.el&&t!==n&&(this.ensure(),this.update())}get control(){return this.el}focus(e){this.el?.focus(e)}click(){this.el?.click()}ensure(){let e=this.hasAttribute(`href`)?`A`:`BUTTON`;if(this.el?.tagName===e)return;let t=document.createElement(e);t.append(...this.el?this.el.childNodes:this.childNodes),this.el?.remove(),this.el=t,this.append(t),t.addEventListener(`click`,e=>{t.getAttribute(`aria-disabled`)===`true`&&(e.preventDefault(),e.stopImmediatePropagation())})}update(){let e=this.el,r=this.getAttribute(`variant`)??`secondary`,a=this.getAttribute(`size`)??`md`,o=this.getAttribute(`shape`)??`default`,s=t(this,`loading`),u=t(this,`disabled`),d=e.tagName===`BUTTON`,f=s||!d&&u;if(e.className=c(`k-btn`,`k-btn--${r}`,a!==`md`&&`k-btn--${a}`,o!=="default"&&`k-btn--${o}`,t(this,`block`)&&`k-btn--block`,t(this,`icon-only`)&&`k-btn--icon`),e.dataset.variant=r,e.dataset.size=a,d){let t=e;t.type=this.getAttribute(`type`)??`button`,t.disabled=u}else{let t=this.getAttribute(`href`);t&&!f?e.setAttribute(`href`,t):e.removeAttribute(`href`)}for(let t of l){let n=this.getAttribute(t);n===null?e.removeAttribute(t):e.setAttribute(t,n)}let p=this.getAttribute(`label`);p?e.setAttribute(`aria-label`,p):e.removeAttribute(`aria-label`),f?e.setAttribute(`aria-disabled`,`true`):e.removeAttribute(`aria-disabled`),s?e.setAttribute(`aria-busy`,`true`):e.removeAttribute(`aria-busy`);let m=e.querySelector(`:scope > [data-kashi-loading]`);s&&!m?e.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" role="status" data-kashi-loading>${n(this.getAttribute(`loading-label`)??i().common.loading)}</span>`):s||m?.remove()}};u.observedAttributes=[`variant`,`size`,`shape`,`loading`,`loading-label`,`block`,`icon-only`,`disabled`,`type`,`href`,`label`,...l];var d=class extends o{constructor(){super(...arguments),this.box=null}connectedCallback(){a(()=>{this.isConnected&&(this.box||(this.box=document.createElement(`div`),this.box.setAttribute(`role`,`group`),this.box.className=`k-btn-group`,this.box.append(...this.childNodes),this.append(this.box),this.box.addEventListener(`click`,e=>this.onClick(e))),this.update())})}attributeChangedCallback(){this.box&&this.update()}get buttons(){return[...this.box.querySelectorAll(`:scope > .k-btn`)]}get value(){let e=this.box?this.buttons.filter(e=>e.getAttribute(`aria-pressed`)===`true`).map(e=>e.dataset.value??e.textContent?.trim()??``):[];return this.getAttribute(`toggle`)===`multiple`?e:e[0]??``}set value(e){let t=Array.isArray(e)?e:[e];a(()=>this.box&&this.buttons.forEach(e=>e.setAttribute(`aria-pressed`,String(t.includes(e.dataset.value??``)))))}update(){let e=this.getAttribute(`label`);if(e?this.box.setAttribute(`aria-label`,e):this.box.removeAttribute(`aria-label`),this.getAttribute(`toggle`))for(let e of this.buttons)e.hasAttribute(`aria-pressed`)||e.setAttribute(`aria-pressed`,`false`)}onClick(t){let n=this.getAttribute(`toggle`),r=t.target.closest(`.k-btn`);if(!n||!r||r.parentElement!==this.box||r.disabled)return;let i=r.getAttribute(`aria-pressed`)===`true`;if(n===`single`)for(let e of this.buttons)e.setAttribute(`aria-pressed`,`false`);r.setAttribute(`aria-pressed`,String(!i)),e(this,`kashi-change`,{value:this.value})}};d.observedAttributes=[`label`,`toggle`];var f=class extends o{constructor(){super(...arguments),this.box=null,this.current=``,this.ro=null,this.key=s(`kashi-seg`)}connectedCallback(){a(()=>{this.isConnected&&(this.box||this.build(),this.update(),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.box)))})}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?this.select(n??``,!1):this.update())}get value(){return this.current}set value(e){this.box?this.select(String(e??``),!1):this.setAttribute(`value`,String(e??``))}build(){let e=[...this.querySelectorAll(`:scope > option`)],n=document.createElement(`div`);n.setAttribute(`role`,`radiogroup`),n.innerHTML=`<span class="k-segmented__indicator" aria-hidden="true"></span>`;for(let t of e){let e=document.createElement(`label`);e.className=`k-segmented__item`;let r=document.createElement(`input`);r.type=`radio`,r.className=`k-sr-only`,r.value=t.value,r.disabled=t.disabled,t.disabled&&r.setAttribute(`data-off`,``);let i=t.getAttribute(`aria-label`);i&&r.setAttribute(`aria-label`,i),e.append(r),t.dataset.icon&&e.insertAdjacentHTML(`beforeend`,t.dataset.icon),t.textContent?.trim()&&e.append(t.textContent.trim()),n.append(e)}for(let t of e)t.remove();this.current=this.getAttribute(`value`)??e.find(e=>e.selected&&e.hasAttribute(`selected`))?.value??e.find(e=>!e.disabled)?.value??``,n.addEventListener(`change`,e=>{let n=e.target;t(this,`readonly`)?this.paint():this.select(n.value,!0)}),n.addEventListener(`click`,e=>{t(this,`readonly`)&&e.target.closest(`input`)&&e.preventDefault()}),this.append(n),this.box=n}select(t,n){if(t===this.current&&!n)return this.paint();this.current=t,this.paint(),n&&e(this,`kashi-change`,{value:t})}update(){let e=this.box;e.className=c(`k-segmented`,this.getAttribute(`size`)===`sm`&&`k-segmented--sm`,t(this,`block`)&&`k-segmented--block`);let n=this.getAttribute(`label`)??this.getAttribute(`aria-label`);n?e.setAttribute(`aria-label`,n):e.removeAttribute(`aria-label`);let r=t(this,`readonly`);e.toggleAttribute(`data-readonly`,r),r?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`);let i=this.getAttribute(`name`)??this.key,a=t(this,`disabled`);for(let t of e.querySelectorAll(`input`))t.name=i,a?t.disabled=!0:t.hasAttribute(`data-off`)||(t.disabled=!1);this.paint()}paint(){for(let e of this.box.querySelectorAll(`input`))e.checked=e.value===this.current;this.measure()}measure(){let e=this.box;if(!e)return;let t=[...e.querySelectorAll(`.k-segmented__item`)].find(e=>e.querySelector(`input`).checked);!t||!t.offsetWidth?e.removeAttribute(`data-indicator`):(e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.setAttribute(`data-indicator`,``))}};f.observedAttributes=[`value`,`name`,`size`,`block`,`disabled`,`readonly`,`label`,`aria-label`];var p=class extends o{constructor(){super(...arguments),this.nav=null,this.items=[],this.expanded=!1}connectedCallback(){a(()=>{this.isConnected&&(this.nav||this.build(),this.update())})}attributeChangedCallback(){this.nav&&this.update()}build(){this.items=[...this.children].filter(e=>e instanceof HTMLElement);for(let e of this.items){let t=e.hasAttribute(`data-icon-only`);e.classList.add(`k-breadcrumb__link`),t&&e.classList.add(`k-breadcrumb__link--icon`);let n=[...e.childNodes].filter(e=>e.nodeType===3&&e.textContent?.trim()),r=n.map(e=>e.textContent.trim()).join(` `);if(n.length){let i=document.createElement(`span`);i.className=t?`k-sr-only`:`k-breadcrumb__text`,i.textContent=r,n[0].replaceWith(i);for(let e of n.slice(1))e.remove();!t&&!e.title&&(e.title=r)}}this.nav=document.createElement(`nav`),this.nav.innerHTML=`<ol></ol>`,this.replaceChildren(this.nav),this.nav.addEventListener(`click`,e=>{e.target.closest(`[data-expand]`)&&(this.expanded=!0,this.update(),this.nav.querySelectorAll(`.k-breadcrumb__link`)[1]?.focus())})}update(){let e=this.nav;e.className=c(`k-breadcrumb`,this.getAttribute(`separator`)===`slash`&&`k-breadcrumb--slash`),e.setAttribute(`aria-label`,this.getAttribute(`label`)??i().breadcrumb.label);let t=Number(this.getAttribute(`max-items`))||0,r=this.items,a=!this.expanded&&t>=2&&r.length>t?[r[0],`…`,...r.slice(r.length-(t-1))]:r;r.forEach((e,t)=>{t===r.length-1?e.setAttribute(`aria-current`,`page`):e.getAttribute(`aria-current`)===`page`&&e.removeAttribute(`aria-current`)}),e.querySelector(`ol`).replaceChildren(...a.map(e=>{let t=document.createElement(`li`);return e===`…`?t.innerHTML=`<button type="button" class="k-breadcrumb__link" data-expand aria-label="${n(this.getAttribute(`expand-label`)??i().breadcrumb.expand)}">…</button>`:t.append(e),t}))}};p.observedAttributes=[`max-items`,`separator`,`label`,`expand-label`];var m=class extends o{constructor(){super(...arguments),this.box=null,this.key=s(`k-acc`)}connectedCallback(){a(()=>{this.isConnected&&(this.box||this.build(),this.update())})}attributeChangedCallback(){this.box&&this.update()}get details(){return[...this.box.querySelectorAll(`:scope > details`)]}build(){let t=document.createElement(`div`);for(let e of[...this.children]){let n;if(e.tagName===`DETAILS`)n=e;else if(e.hasAttribute(`data-title`)){n=document.createElement(`details`),n.innerHTML=`<summary></summary>`;let t=n.querySelector(`summary`),r=e.getAttribute(`data-description`);r?(t.innerHTML=`<span class="k-accordion__head"><span class="k-accordion__titles"><span class="k-accordion__title"></span><span class="k-accordion__description"></span></span></span>`,t.querySelector(`.k-accordion__title`).textContent=e.getAttribute(`data-title`),t.querySelector(`.k-accordion__description`).textContent=r):t.textContent=e.getAttribute(`data-title`),n.open=e.hasAttribute(`data-open`),e.hasAttribute(`data-disabled`)&&n.setAttribute(`data-disabled`,``),e.hasAttribute(`data-value`)&&(n.dataset.value=e.getAttribute(`data-value`));let i=document.createElement(`div`);i.append(...e.childNodes),n.append(i)}else continue;n.classList.add(`k-accordion__item`);let r=n.querySelector(`:scope > summary`);r?.classList.add(`k-accordion__trigger`),n.hasAttribute(`data-disabled`)&&r&&(n.classList.add(`k-accordion__item--disabled`),r.setAttribute(`aria-disabled`,`true`),r.tabIndex=-1,r.addEventListener(`click`,e=>e.preventDefault()));let i=[...n.childNodes].filter(e=>e!==r);if(!(i.length===1&&i[0]instanceof HTMLElement&&i[0].classList.contains(`k-accordion__content`)&&i[0])){let e=document.createElement(`div`);e.className=`k-accordion__content`,e.append(...i),n.append(e)}t.append(n)}this.replaceChildren(t),this.box=t,t.addEventListener(`toggle`,n=>{let r=n.target;if(r.parentElement===t){if(r.open&&this.getAttribute(`type`)===`single`)for(let e of this.details)e!==r&&e.open&&(e.open=!1);e(this,`kashi-toggle`,{index:this.details.indexOf(r),value:r.dataset.value,open:r.open})}},!0)}update(){this.box.className=c(`k-accordion`,t(this,`flush`)&&`k-accordion--flush`,this.getAttribute(`size`)===`sm`&&`k-accordion--sm`);let e=this.getAttribute(`type`)===`single`;for(let t of this.details)e?t.setAttribute(`name`,this.key):t.removeAttribute(`name`)}};m.observedAttributes=[`type`,`flush`,`size`],r(`kashi-button`,u),r(`kashi-button-group`,d),r(`kashi-segmented-control`,f),r(`kashi-breadcrumb`,p,`block`),r(`kashi-accordion`,m,`block`);export{m as KashiAccordion,p as KashiBreadcrumb,u as KashiButton,d as KashiButtonGroup,f as KashiSegmentedControl};
@@ -1,4 +1,4 @@
1
- import{A as e,C as t,D as n,E as r,O as i,P as a,T as o,_ as s,a as c,c as l,d as u,i as d,k as f,l as p,n as m,o as h,p as g,s as _,t as v,u as y,v as b,w as x,y as S}from"./base-D4tCOysh.js";import{t as C}from"./holidays-Cu6IfbTL.js";const w=(e,t)=>!!e&&!!t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),T=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),E=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),D=e=>`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}`;function O(t,n){let{jy:r,jm:a,jd:s}=e(t),c=r*12+(a-1)+n,l=Math.floor(c/12),u=c-l*12+1;return i(l,u,Math.min(s,o(l,u)))}const k=e=>e?x(e.trim())??n(e):null;var A=class extends v{constructor(){super(...arguments),this.rangeValue=null,this.hover=null,this.selected=null,this.valueSet=!1,this.focused=T(/* @__PURE__ */ new Date),this.refocus=!1,this.rendered=!1,this.key=S(`kashi-cal`),this.onClick=e=>{let t=e.target.closest(`button`);if(!t||!this.contains(t))return;let n=t.dataset.nav;if(n)this.go(O(this.focused,n===`prev`?-1:1),!1);else if(t.dataset.today!==void 0){let e=/* @__PURE__ */ new Date;this.pick(new Date(e.getFullYear(),e.getMonth(),e.getDate()))}else if(t.dataset.day){let[e,n,r]=t.dataset.day.split(`-`).map(Number);this.pick(new Date(e,n-1,r))}},this.onSelect=t=>{let n=t.target;if(!n.matches?.(`.k-calendar__select`))return;t.stopPropagation();let{jy:r,jm:a,jd:s}=e(this.focused),c=n.dataset.part===`year`?Number(n.value):r,l=n.dataset.part===`month`?Number(n.value):a;this.go(i(c,l,Math.min(s,o(c,l))),!1),this.querySelector(`.k-calendar__select[data-part="${n.dataset.part}"]`)?.focus()},this.onKey=e=>{if(!e.target.classList?.contains(`k-calendar__day`))return;let t=getComputedStyle(this).direction===`rtl`,n=this.focused,i=r(n),a={ArrowLeft:()=>E(n,t?1:-1),ArrowRight:()=>E(n,t?-1:1),ArrowUp:()=>E(n,-7),ArrowDown:()=>E(n,7),Home:()=>E(n,-i),End:()=>E(n,6-i),PageUp:()=>O(n,e.shiftKey?-12:-1),PageDown:()=>O(n,e.shiftKey?12:1)};a[e.key]&&(e.preventDefault(),this.go(a[e.key]()))}}get range(){return this.rangeValue}set range(e){this.rangeValue=e,e?.start&&(this.focused=this.clamp(T(e.start))),this.rendered&&this.render()}connectedCallback(){if(!this.rendered){this.valueSet||(this.selected=k(this.getAttribute(`value`))),this.focused=this.clamp(T(this.selected??/* @__PURE__ */ new Date)),this.addEventListener(`click`,this.onClick),this.addEventListener(`keydown`,this.onKey),this.addEventListener(`change`,this.onSelect);let e=e=>{let t=e.target.closest?.(`.k-calendar__day`)?.dataset.day;if(!this.rangeValue?.start||this.rangeValue.end||!t)return;let[n,r,i]=t.split(`-`).map(Number);this.hover=new Date(n,r-1,i),this.paintRange()};this.addEventListener(`pointerover`,e),this.addEventListener(`focusin`,e)}this.rendered=!0,this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`&&(this.selected=k(n),this.selected&&(this.focused=T(this.selected))),this.render())}get value(){return this.selected?f(this.selected):``}set value(e){this.valueSet=!0,this.selected=k(e??``),this.selected&&(this.focused=T(this.selected)),this.rendered&&this.render()}get date(){return this.selected}set date(e){this.value=e?f(e):``}focus(){this.querySelector(`.k-calendar__day[tabindex="0"]`)?.focus()}get min(){return k(this.getAttribute(`min`))}get max(){return k(this.getAttribute(`max`))}clamp(e){let t=this.min,n=this.max;return t&&e<t?T(t):n&&e>n?T(n):e}disabled(e){let t=this.min,n=this.max;return!!t&&e<t||!!n&&e>n||!!this.isDateDisabled?.(e)}holiday(e){return this.holidayOf?this.holidayOf(e)||null:d(this,`holidays`)?C(e,{locale:u()}):null}go(e,t=!0){this.focused=this.clamp(e),this.refocus=t,this.render()}pick(e){this.disabled(e)||(this.selected=e,this.focused=e,this.refocus=!0,this.render(),b(this,this.getAttribute(`name`),this.value),l(this,`kashi-change`,{value:this.value,date:e}))}paintRange(){let e=this.rangeValue;if(!e)return;let t=e.start?T(e.start):null,n=e.end?T(e.end):null,r=t&&!n&&this.hover?this.hover:null,[i,a]=t&&(n||r)?[t,n??r].sort((e,t)=>+e-t):[t,t];this.querySelectorAll(`td[data-date]`).forEach(e=>{let[t,r,o]=e.dataset.date.split(`-`).map(Number),s=new Date(t,r-1,o),c=!!i&&!!a&&s>=i&&s<=a;e.setAttribute(`aria-selected`,String(c)),e.toggleAttribute(`data-in-range`,c&&!!n),e.toggleAttribute(`data-preview`,c&&!n),e.toggleAttribute(`data-range-start`,!!i&&w(s,i)),e.toggleAttribute(`data-range-end`,!!a&&w(s,a))})}render(){let n=_(this),s=e=>n===`fa`?a(e):String(e),l=g(),d=l.calendar,{months:f,weekdays:h,weekdaysShort:v,friday:y}=c(),x=T(/* @__PURE__ */ new Date),{jy:S,jm:C}=e(this.focused),O=i(S,C,1),k=o(S,C),A=[...Array(r(O)).fill(null),...Array.from({length:k},(e,t)=>E(O,t))];for(;A.length%7;)A.push(null);let j=this.min,M=this.max,N=j?e(j).jy:e(x).jy-100,P=M?e(M).jy:e(x).jy+20,F=Array.from({length:Math.max(0,P-N+1)},(e,t)=>N+t);F.includes(S)||F.push(S),F.sort((e,t)=>e-t);let I=!!j&&O<=T(j),L=!!M&&i(S,C,k)>=T(M),R=[];for(let r=0;r<A.length;r+=7)R.push(`<tr>${A.slice(r,r+7).map(r=>{if(!r)return`<td role="gridcell"></td>`;let i=this.holiday(r),a=t(r,{style:`full`,digits:n,locale:u()})+(i?`${l.common.list}${d.holiday}${i===y?``:`: ${i}`}`:``);return`<td role="gridcell" data-date="${D(r)}" aria-selected="${w(r,this.selected)}"><button type="button" class="k-calendar__day" data-day="${D(r)}" tabindex="${w(r,this.focused)?0:-1}" aria-label="${p(a)}"${i&&i!==y?` title="${p(i)}"`:``}${i?` data-holiday=""`:``}${w(r,x)?` aria-current="date"`:``}${this.disabled(r)?` aria-disabled="true"`:``}>${s(e(r).jd)}</button></td>`}).join(``)}</tr>`);let z=this.getAttribute(`today-label`);this.innerHTML=`<div class="k-calendar" role="group" aria-label="${p(this.getAttribute(`label`)??d.label)}">
1
+ import{A as e,C as t,D as n,E as r,O as i,P as a,T as o,_ as s,a as c,c as l,d as u,i as d,k as f,l as p,n as m,o as h,p as g,s as _,t as v,u as y,v as b,w as x,y as S}from"./base-BqFAMlwG.js";import{t as C}from"./holidays-DgmHlqJX.js";const w=(e,t)=>!!e&&!!t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),T=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),E=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),D=e=>`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}`;function O(t,n){let{jy:r,jm:a,jd:s}=e(t),c=r*12+(a-1)+n,l=Math.floor(c/12),u=c-l*12+1;return i(l,u,Math.min(s,o(l,u)))}const k=e=>e?x(e.trim())??n(e):null;var A=class extends v{constructor(){super(...arguments),this.rangeValue=null,this.hover=null,this.selected=null,this.valueSet=!1,this.focused=T(/* @__PURE__ */ new Date),this.refocus=!1,this.rendered=!1,this.key=S(`kashi-cal`),this.onClick=e=>{let t=e.target.closest(`button`);if(!t||!this.contains(t))return;let n=t.dataset.nav;if(n)this.go(O(this.focused,n===`prev`?-1:1),!1);else if(t.dataset.today!==void 0){let e=/* @__PURE__ */ new Date;this.pick(new Date(e.getFullYear(),e.getMonth(),e.getDate()))}else if(t.dataset.day){let[e,n,r]=t.dataset.day.split(`-`).map(Number);this.pick(new Date(e,n-1,r))}},this.onSelect=t=>{let n=t.target;if(!n.matches?.(`.k-calendar__select`))return;t.stopPropagation();let{jy:r,jm:a,jd:s}=e(this.focused),c=n.dataset.part===`year`?Number(n.value):r,l=n.dataset.part===`month`?Number(n.value):a;this.go(i(c,l,Math.min(s,o(c,l))),!1),this.querySelector(`.k-calendar__select[data-part="${n.dataset.part}"]`)?.focus()},this.onKey=e=>{if(!e.target.classList?.contains(`k-calendar__day`))return;let t=getComputedStyle(this).direction===`rtl`,n=this.focused,i=r(n),a={ArrowLeft:()=>E(n,t?1:-1),ArrowRight:()=>E(n,t?-1:1),ArrowUp:()=>E(n,-7),ArrowDown:()=>E(n,7),Home:()=>E(n,-i),End:()=>E(n,6-i),PageUp:()=>O(n,e.shiftKey?-12:-1),PageDown:()=>O(n,e.shiftKey?12:1)};a[e.key]&&(e.preventDefault(),this.go(a[e.key]()))}}get range(){return this.rangeValue}set range(e){this.rangeValue=e,e?.start&&(this.focused=this.clamp(T(e.start))),this.rendered&&this.render()}connectedCallback(){if(!this.rendered){this.valueSet||(this.selected=k(this.getAttribute(`value`))),this.focused=this.clamp(T(this.selected??/* @__PURE__ */ new Date)),this.addEventListener(`click`,this.onClick),this.addEventListener(`keydown`,this.onKey),this.addEventListener(`change`,this.onSelect);let e=e=>{let t=e.target.closest?.(`.k-calendar__day`)?.dataset.day;if(!this.rangeValue?.start||this.rangeValue.end||!t)return;let[n,r,i]=t.split(`-`).map(Number);this.hover=new Date(n,r-1,i),this.paintRange()};this.addEventListener(`pointerover`,e),this.addEventListener(`focusin`,e)}this.rendered=!0,this.render()}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`&&(this.selected=k(n),this.selected&&(this.focused=T(this.selected))),this.render())}get value(){return this.selected?f(this.selected):``}set value(e){this.valueSet=!0,this.selected=k(e??``),this.selected&&(this.focused=T(this.selected)),this.rendered&&this.render()}get date(){return this.selected}set date(e){this.value=e?f(e):``}focus(){this.querySelector(`.k-calendar__day[tabindex="0"]`)?.focus()}get min(){return k(this.getAttribute(`min`))}get max(){return k(this.getAttribute(`max`))}clamp(e){let t=this.min,n=this.max;return t&&e<t?T(t):n&&e>n?T(n):e}disabled(e){let t=this.min,n=this.max;return!!t&&e<t||!!n&&e>n||!!this.isDateDisabled?.(e)}holiday(e){return this.holidayOf?this.holidayOf(e)||null:d(this,`holidays`)?C(e,{locale:u()}):null}go(e,t=!0){this.focused=this.clamp(e),this.refocus=t,this.render()}pick(e){this.disabled(e)||(this.selected=e,this.focused=e,this.refocus=!0,this.render(),b(this,this.getAttribute(`name`),this.value),l(this,`kashi-change`,{value:this.value,date:e}))}paintRange(){let e=this.rangeValue;if(!e)return;let t=e.start?T(e.start):null,n=e.end?T(e.end):null,r=t&&!n&&this.hover?this.hover:null,[i,a]=t&&(n||r)?[t,n??r].sort((e,t)=>+e-t):[t,t];this.querySelectorAll(`td[data-date]`).forEach(e=>{let[t,r,o]=e.dataset.date.split(`-`).map(Number),s=new Date(t,r-1,o),c=!!i&&!!a&&s>=i&&s<=a;e.setAttribute(`aria-selected`,String(c)),e.toggleAttribute(`data-in-range`,c&&!!n),e.toggleAttribute(`data-preview`,c&&!n),e.toggleAttribute(`data-range-start`,!!i&&w(s,i)),e.toggleAttribute(`data-range-end`,!!a&&w(s,a))})}render(){let n=_(this),s=e=>n===`fa`?a(e):String(e),l=g(),d=l.calendar,{months:f,weekdays:h,weekdaysShort:v,friday:y}=c(),x=T(/* @__PURE__ */ new Date),{jy:S,jm:C}=e(this.focused),O=i(S,C,1),k=o(S,C),A=[...Array(r(O)).fill(null),...Array.from({length:k},(e,t)=>E(O,t))];for(;A.length%7;)A.push(null);let j=this.min,M=this.max,N=j?e(j).jy:e(x).jy-100,P=M?e(M).jy:e(x).jy+20,F=Array.from({length:Math.max(0,P-N+1)},(e,t)=>N+t);F.includes(S)||F.push(S),F.sort((e,t)=>e-t);let I=!!j&&O<=T(j),L=!!M&&i(S,C,k)>=T(M),R=[];for(let r=0;r<A.length;r+=7)R.push(`<tr>${A.slice(r,r+7).map(r=>{if(!r)return`<td role="gridcell"></td>`;let i=this.holiday(r),a=t(r,{style:`full`,digits:n,locale:u()})+(i?`${l.common.list}${d.holiday}${i===y?``:`: ${i}`}`:``);return`<td role="gridcell" data-date="${D(r)}" aria-selected="${w(r,this.selected)}"><button type="button" class="k-calendar__day" data-day="${D(r)}" tabindex="${w(r,this.focused)?0:-1}" aria-label="${p(a)}"${i&&i!==y?` title="${p(i)}"`:``}${i?` data-holiday=""`:``}${w(r,x)?` aria-current="date"`:``}${this.disabled(r)?` aria-disabled="true"`:``}>${s(e(r).jd)}</button></td>`}).join(``)}</tr>`);let z=this.getAttribute(`today-label`);this.innerHTML=`<div class="k-calendar" role="group" aria-label="${p(this.getAttribute(`label`)??d.label)}">
2
2
  <div class="k-calendar__header">
3
3
  <button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm" data-nav="prev" aria-label="${p(d.prevMonth)}"${I?` disabled`:``}>${m.prev}</button>
4
4
  <div class="k-calendar__selects">
@@ -0,0 +1,24 @@
1
+ import{c as e,i as t,l as n,m as r,o as i,p as a,t as o,v as s,y as c}from"./base-BqFAMlwG.js";import{u as l}from"./parts-5fVaWtRe.js";var u=class extends o{constructor(){super(...arguments),this.strokes=[],this.current=null,this.mode=`draw`,this.typed=``,this.key=c(`kashi-sign`),this.canvas=null,this.ro=null,this.built=!1}connectedCallback(){this.built||this.build()}disconnectedCallback(){this.ro?.disconnect()}attributeChangedCallback(e,t,n){this.built&&t!==n&&this.build()}get locked(){return this.hasAttribute(`disabled`)||this.hasAttribute(`readonly`)}get penWidth(){return l(this,`pen-width`,2.5)}build(){let e=a().signature,r=this.getAttribute(`label`),i=this.getAttribute(`error`),o=this.getAttribute(`hint`)??(this.locked?null:e.hint),s=t(this,`allow-typed`,!0)&&!this.locked;this.innerHTML=`<div class="k-field k-signature"${this.hasAttribute(`disabled`)?` data-disabled`:``}${i?` data-invalid`:``}>
2
+ ${r?`<span class="k-label">${n(r)}${this.hasAttribute(`required`)?`<span class="k-label__required" aria-hidden="true">*</span>`:``}</span>`:``}
3
+ ${s?`<div class="k-signature__modes" role="radiogroup" aria-label="${n(r??e.label)}">${[`draw`,`type`].map(t=>`<button type="button" role="radio" class="k-signature__mode" data-mode="${t}" aria-checked="${this.mode===t}">${n(e[t])}</button>`).join(``)}</div>`:``}
4
+ <div class="k-signature__pad">
5
+ ${this.mode===`draw`?`<canvas class="k-signature__canvas" role="img" aria-describedby="${this.key}-hint"></canvas>`:`<label class="k-signature__typed"><span class="k-sr-only">${n(e.typedLabel)}</span><input class="k-signature__typed-input" placeholder="${n(e.typedLabel)}" autocomplete="name" value="${n(this.typed)}"></label>`}
6
+ <span class="k-signature__line" aria-hidden="true">×</span>
7
+ ${this.locked?``:`<div class="k-signature__tools">${this.mode===`draw`?`<button type="button" class="k-signature__tool" data-undo aria-label="${n(e.undo)}" title="${n(e.undo)}"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M7.5 5 4 8.5 7.5 12M4.5 8.5h7a4 4 0 0 1 0 8H9" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button>`:``}<button type="button" class="k-signature__tool" data-clear>${n(e.clear)}</button></div>`}
8
+ </div>
9
+ ${i?`<p class="k-hint k-hint--error" role="alert">${n(i)}</p>`:o?`<p class="k-hint" id="${this.key}-hint">${n(o)}</p>`:``}
10
+ <span class="k-sr-only" aria-live="polite"></span>
11
+ </div>`,this.built=!0;let c=this.firstElementChild;c.querySelectorAll(`[data-mode]`).forEach(e=>e.addEventListener(`click`,()=>{this.mode=e.dataset.mode,this.build(),this.querySelector(`.k-signature__typed-input`)?.focus(),this.commit()})),c.querySelector(`[data-undo]`)?.addEventListener(`click`,()=>this.undo()),c.querySelector(`[data-clear]`)?.addEventListener(`click`,()=>this.clear());let l=c.querySelector(`.k-signature__typed-input`);l?.addEventListener(`input`,()=>{this.typed=l.value,this.commit()}),this.canvas=c.querySelector(`canvas`),this.canvas&&this.wireCanvas(this.canvas),this.ro?.disconnect(),this.canvas&&typeof ResizeObserver<`u`&&(this.ro=new ResizeObserver(()=>this.redraw()),this.ro.observe(this.canvas)),this.redraw(),this.paintState()}wireCanvas(e){let t=t=>{let n=e.getBoundingClientRect();return[(t.clientX-n.left)/n.width,(t.clientY-n.top)/n.height,t.pointerType===`pen`&&t.pressure>0?t.pressure:.5]};e.addEventListener(`pointerdown`,n=>{this.locked||n.pointerType===`mouse`&&n.button!==0||(e.setPointerCapture(n.pointerId),this.current=[t(n)],this.redraw())}),e.addEventListener(`pointermove`,n=>{let r=this.current;if(!r)return;let i=e.getBoundingClientRect(),a=n.getCoalescedEvents?.();for(let e of a&&a.length?a:[n]){let n=t(e),a=r[r.length-1],o=Math.hypot(n[0]-a[0],n[1]-a[1])*i.width;o<1.2||(e.pointerType!==`pen`&&(n[2]=Math.max(.15,Math.min(.75,.75-o/60))),r.push(n))}this.redraw()}),e.addEventListener(`pointerup`,()=>{this.current&&(this.strokes.push(this.current),this.current=null,this.commit(this.strokes.length===1?a().signature.signed:void 0))}),e.addEventListener(`pointercancel`,()=>{this.current=null,this.redraw()})}paint(e,t,n,r,i,a){e.clearRect(0,0,t,n),e.strokeStyle=e.fillStyle=i,e.lineCap=e.lineJoin=`round`;let o=this.penWidth;for(let i of r)if(i.length===1)e.beginPath(),e.arc(i[0][0]*t,i[0][1]*n,o*a*(.6+i[0][2])/2,0,Math.PI*2),e.fill();else for(let r=1;r<i.length;r++){let s=i[r-1],c=i[r],l=r>1?[(i[r-2][0]+s[0])/2,(i[r-2][1]+s[1])/2]:s,u=[(s[0]+c[0])/2,(s[1]+c[1])/2];e.lineWidth=o*a*(.6+(s[2]+c[2])/2),e.beginPath(),e.moveTo(l[0]*t,l[1]*n),e.quadraticCurveTo(s[0]*t,s[1]*n,u[0]*t,u[1]*n),r===i.length-1&&e.lineTo(c[0]*t,c[1]*n),e.stroke()}}redraw(){let e=this.canvas;if(!e)return;let t=e.getBoundingClientRect(),n=typeof devicePixelRatio==`number`&&devicePixelRatio||1;e.width=Math.max(1,Math.round(t.width*n)),e.height=Math.max(1,Math.round(t.height*n));let r=e.getContext(`2d`);r&&this.paint(r,e.width,e.height,this.current?[...this.strokes,this.current]:this.strokes,getComputedStyle(e).color,n)}isEmpty(){return this.mode===`type`?!this.typed.trim():this.strokes.length===0}toDataURL(e=`image/png`){if(this.isEmpty())return null;let t=this.canvas,n=t?.width||600,r=t?.height||200,i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return null;let o=this.getAttribute(`export-color`)??`#0b0c0f`;return this.mode===`type`?(a.fillStyle=o,a.textAlign=`center`,a.textBaseline=`middle`,a.direction=`rtl`,a.font=`700 ${Math.round(r*.34)}px ${getComputedStyle(this).getPropertyValue(`--k-font-display`)||`sans-serif`}`,a.fillText(this.typed.trim(),n/2,r/2,n*.9)):this.paint(a,n,r,this.strokes,o,n/(t?.getBoundingClientRect().width||n)),i.toDataURL(e)}undo(){this.strokes.pop(),this.redraw(),this.commit()}clear(){this.strokes=[],this.typed=``;let e=this.querySelector(`.k-signature__typed-input`);e&&(e.value=``),this.redraw(),this.commit(a().signature.cleared)}paintState(){let e=this.firstElementChild;if(!e)return;let t=this.isEmpty();e.toggleAttribute(`data-empty`,t);let n=a().signature;this.canvas?.setAttribute(`aria-label`,`${n.area}${t?`${a().common.comma}${n.empty}`:``}`);let r=e.querySelector(`[data-undo]`);r&&(r.disabled=this.strokes.length===0);let i=e.querySelector(`[data-clear]`);i&&(i.disabled=t)}commit(t){let n=this.toDataURL();this.paintState(),s(this,this.getAttribute(`name`),n??``),t&&(this.querySelector(`.k-signature [aria-live]`).textContent=t),e(this,`kashi-change`,{value:n})}};u.observedAttributes=[`label`,`hint`,`error`,`disabled`,`readonly`,`allow-typed`];var d=class extends o{constructor(){super(...arguments),this.s={x:0,y:0,zoom:1,rotation:0},this.nat=null,this.stage=null,this.img=null,this.ro=null,this.pointers=/* @__PURE__ */ new Map,this.drag=null,this.pinch=null}connectedCallback(){this.stage||this.build()}disconnectedCallback(){this.ro?.disconnect()}attributeChangedCallback(e,t,n){this.stage&&t!==n&&(e===`src`?(this.nat=null,this.s={x:0,y:0,zoom:1,rotation:0},this.img.src=n??``):e===`shape`||e===`aspect`?(this.querySelector(`.k-cropper`).setAttribute(`data-shape`,this.getAttribute(`shape`)??`rect`),this.layout()):this.build())}get aspect(){let e=this.getAttribute(`aspect`);if(!e)return 1;let[t,n]=e.split(`/`).map(Number);return n?t/n:t||1}get maxZoom(){return l(this,`max-zoom`,4)}build(){let e=a().cropper,i=this.getAttribute(`label`),o=(e,t,r)=>`<button type="button" class="k-cropper__btn" ${e} aria-label="${n(t)}"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="${r}" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button>`;this.innerHTML=`<div class="k-cropper" data-shape="${n(this.getAttribute(`shape`)??`rect`)}">
12
+ ${i?`<span class="k-label">${n(i)}</span>`:``}
13
+ <div class="k-cropper__stage" dir="ltr" tabindex="0" role="application" aria-roledescription="${n(e.label)}" aria-label="${n(e.area)}">
14
+ <img class="k-cropper__img" alt="${n(this.getAttribute(`alt`)??``)}" draggable="false" style="opacity:0">
15
+ <div class="k-cropper__frame" aria-hidden="true"><span class="k-cropper__grid"></span></div>
16
+ </div>
17
+ <div class="k-cropper__controls">
18
+ ${o(`data-zoom="out"`,`${e.zoom} −`,`M5 10h10`)}
19
+ <input type="range" class="k-slider k-cropper__zoom" min="1" max="${this.maxZoom}" step="0.01" value="1" aria-label="${n(e.zoom)}">
20
+ ${o(`data-zoom="in"`,`${e.zoom} +`,`M5 10h10M10 5v10`)}
21
+ ${t(this,`rotatable`,!0)?o(`data-rotate`,e.rotate,`M15.5 9A5.5 5.5 0 1 0 14 13.3M15.5 4.5V9H11`):``}
22
+ </div>
23
+ <span class="k-sr-only" aria-live="polite"></span>
24
+ </div>`,this.stage=this.querySelector(`.k-cropper__stage`),this.img=this.querySelector(`.k-cropper__img`),this.img.addEventListener(`load`,()=>{this.nat={w:this.img.naturalWidth,h:this.img.naturalHeight},this.move(this.s)}),this.img.src=this.getAttribute(`src`)??``;let s=this.stage;s.addEventListener(`pointerdown`,e=>{if(s.setPointerCapture(e.pointerId),this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.pointers.size===2){let[e,t]=[...this.pointers.values()];this.pinch={d:Math.hypot(e.x-t.x,e.y-t.y),zoom:this.s.zoom},this.drag=null}else this.drag={id:e.pointerId,x:e.clientX,y:e.clientY,sx:this.s.x,sy:this.s.y}}),s.addEventListener(`pointermove`,e=>{if(!this.pointers.has(e.pointerId))return;this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});let t=this.geom();if(this.pinch&&this.pointers.size===2){let[e,t]=[...this.pointers.values()];this.move({...this.s,zoom:this.pinch.zoom*Math.hypot(e.x-t.x,e.y-t.y)/this.pinch.d})}else this.drag?.id===e.pointerId&&this.move({...this.s,x:this.drag.sx+(e.clientX-this.drag.x)/t.fw,y:this.drag.sy+(e.clientY-this.drag.y)/t.fh})});let c=e=>{this.pointers.delete(e.pointerId),this.pointers.size<2&&(this.pinch=null),this.drag?.id===e.pointerId&&(this.drag=null)};s.addEventListener(`pointerup`,c),s.addEventListener(`pointercancel`,c),s.addEventListener(`wheel`,e=>{!e.ctrlKey&&Math.abs(e.deltaY)<1||(e.preventDefault(),this.move({...this.s,zoom:this.s.zoom*Math.exp(-e.deltaY/400)}))},{passive:!1}),s.addEventListener(`keydown`,t=>{let n=t.shiftKey?.1:.02,i={ArrowLeft:[n,0],ArrowRight:[-n,0],ArrowUp:[0,n],ArrowDown:[0,-n]};i[t.key]?(t.preventDefault(),this.move({...this.s,x:this.s.x+i[t.key][0],y:this.s.y+i[t.key][1]}),this.say(e.moved(r(this,Math.round((.5-this.s.x)*100)),r(this,Math.round((.5-this.s.y)*100))))):t.key===`+`||t.key===`=`?(t.preventDefault(),this.zoomBy(1.1)):t.key===`-`||t.key===`_`?(t.preventDefault(),this.zoomBy(1/1.1)):t.key===`0`&&(t.preventDefault(),this.move({x:0,y:0,zoom:1,rotation:0}),this.say(e.reset))});let l=this.querySelector(`.k-cropper__zoom`);l.addEventListener(`input`,()=>this.move({...this.s,zoom:Number(l.value)})),this.querySelector(`[data-zoom="in"]`).addEventListener(`click`,()=>this.zoomBy(1.2)),this.querySelector(`[data-zoom="out"]`).addEventListener(`click`,()=>this.zoomBy(1/1.2)),this.querySelector(`[data-rotate]`)?.addEventListener(`click`,()=>this.move({...this.s,x:0,y:0,rotation:(this.s.rotation+90)%360})),this.ro?.disconnect(),typeof ResizeObserver<`u`&&(this.ro=new ResizeObserver(()=>this.move(this.s,!1)),this.ro.observe(s)),this.layout()}say(e){this.querySelector(`.k-cropper [aria-live]`).textContent=e}zoomBy(e){this.move({...this.s,zoom:this.s.zoom*e}),this.say(a().cropper.zoomed(r(this,Math.round(this.s.zoom*100))))}geom(){let e=this.stage,t=e.clientWidth,n=e.clientHeight,r=this.aspect,i=Math.max(1,Math.min(t-32,(n-32)*r)),a=i/r,o=this.s.rotation%180!=0,s=this.nat?o?this.nat.h:this.nat.w:1,c=this.nat?o?this.nat.w:this.nat.h:1;return{W:t,H:n,fw:i,fh:a,iw:s,ih:c,side:o,base:Math.max(i/s,a/c)}}get area(){let e=this.geom(),t=e.base*this.s.zoom;return{x:Math.max(0,e.iw*t/2-this.s.x*e.fw-e.fw/2)/t,y:Math.max(0,e.ih*t/2-this.s.y*e.fh-e.fh/2)/t,width:e.fw/t,height:e.fh/t}}move(t,n=!0){let r=Math.min(this.maxZoom,Math.max(1,t.zoom));this.s={...t,zoom:r};let i=this.geom(),a=i.base*r,o=Math.max(0,(i.iw*a-i.fw)/2)/i.fw,s=Math.max(0,(i.ih*a-i.fh)/2)/i.fh;this.s.x=Math.min(o,Math.max(-o,this.s.x)),this.s.y=Math.min(s,Math.max(-s,this.s.y)),this.layout(),n&&this.nat&&e(this,`kashi-change`,{area:this.area,zoom:this.s.zoom,rotation:this.s.rotation})}layout(){if(!this.stage||!this.img)return;let e=this.geom(),t=this.querySelector(`.k-cropper__frame`);t.style.inlineSize=`${e.fw}px`,t.style.blockSize=`${e.fh}px`;let n=this.querySelector(`.k-cropper__zoom`);if(n.value=String(this.s.zoom),n.setAttribute(`aria-valuetext`,a().common.percent(r(this,Math.round(this.s.zoom*100)))),this.querySelector(`[data-zoom="out"]`).disabled=this.s.zoom<=1,this.querySelector(`[data-zoom="in"]`).disabled=this.s.zoom>=this.maxZoom,!this.nat)return;let i=e.base*this.s.zoom,o=(e.side?e.ih:e.iw)*i,s=(e.side?e.iw:e.ih)*i,c=e.W/2+this.s.x*e.fw-e.iw*i/2+(e.side?(e.iw*i-e.ih*i)/2:0),l=e.H/2+this.s.y*e.fh-e.ih*i/2+(e.side?(e.ih*i-e.iw*i)/2:0);Object.assign(this.img.style,{opacity:`1`,inlineSize:`${o}px`,blockSize:`${s}px`,transform:`translate(${c}px, ${l}px) rotate(${this.s.rotation}deg)`})}async crop({width:e,type:t=`image/webp`,quality:n=.92}={}){let r=new Image;r.crossOrigin=`anonymous`,r.src=this.getAttribute(`src`)??``,await r.decode();let i=this.area,a=this.s.rotation,o=a%180!=0,s=o?r.naturalHeight:r.naturalWidth,c=o?r.naturalWidth:r.naturalHeight,l=Math.round(e??i.width),u=Math.round(l*i.height/i.width),d=document.createElement(`canvas`);d.width=l,d.height=u;let f=d.getContext(`2d`);if(!f)return null;this.getAttribute(`shape`)===`circle`&&(f.beginPath(),f.ellipse(l/2,u/2,l/2,u/2,0,0,Math.PI*2),f.clip());let p=l/i.width;return f.scale(p,p),f.translate(-i.x+s/2,-i.y+c/2),f.rotate(a*Math.PI/180),f.drawImage(r,-r.naturalWidth/2,-r.naturalHeight/2),new Promise(e=>d.toBlob(t=>e(t),t,n))}};d.observedAttributes=[`src`,`alt`,`aspect`,`shape`,`max-zoom`,`rotatable`,`label`],i(`kashi-signature-pad`,u,`block`),i(`kashi-image-cropper`,d,`block`);export{d as KashiImageCropper,u as KashiSignaturePad};
@@ -1 +1 @@
1
- import{M as e}from"./base-D4tCOysh.js";const t={melli:`Bank Melli`,sepah:`Bank Sepah`,edbi:`Export Development Bank`,bim:`Bank of Industry and Mine`,keshavarzi:`Bank Keshavarzi`,maskan:`Bank Maskan`,postbank:`Post Bank`,"tosee-taavon":`Tose'e Ta'avon Bank`,"eghtesad-novin":`EN Bank`,parsian:`Parsian Bank`,pasargad:`Bank Pasargad`,karafarin:`Karafarin Bank`,saman:`Saman Bank`,sina:`Sina Bank`,sarmayeh:`Sarmayeh Bank`,ayandeh:`Ayandeh Bank`,shahr:`Shahr Bank`,dey:`Dey Bank`,saderat:`Bank Saderat`,mellat:`Bank Mellat`,tejarat:`Tejarat Bank`,refah:`Refah Bank`,"iran-zamin":`Iran Zamin Bank`,"mehr-iran":`Mehr Iran Bank`,gardeshgari:`Tourism Bank`,markazi:`Central Bank of Iran`,khavarmianeh:`Middle East Bank`,noor:`Noor Credit Institution`,melal:`Melal Credit Institution`,tosee:`Tose'e Credit Institution`,resalat:`Resalat Bank`,ansar:`Ansar Bank`,ghavamin:`Ghavamin Bank`,hekmat:`Hekmat Iranian Bank`,kosar:`Kosar Credit Institution`,"mehr-eghtesad":`Mehr Eghtesad Bank`};function n(e,n=`fa`){return n===`en`?t[e.slug]??e.name:e.name}const r={603799:{name:`بانک ملی`,slug:`melli`},589210:{name:`بانک سپه`,slug:`sepah`},627648:{name:`بانک توسعه صادرات`,slug:`edbi`},627961:{name:`بانک صنعت و معدن`,slug:`bim`},603770:{name:`بانک کشاورزی`,slug:`keshavarzi`},639217:{name:`بانک کشاورزی`,slug:`keshavarzi`},628023:{name:`بانک مسکن`,slug:`maskan`},627760:{name:`پست بانک`,slug:`postbank`},502908:{name:`بانک توسعه تعاون`,slug:`tosee-taavon`},627412:{name:`بانک اقتصاد نوین`,slug:`eghtesad-novin`},622106:{name:`بانک پارسیان`,slug:`parsian`},639194:{name:`بانک پارسیان`,slug:`parsian`},627884:{name:`بانک پارسیان`,slug:`parsian`},502229:{name:`بانک پاسارگاد`,slug:`pasargad`},639347:{name:`بانک پاسارگاد`,slug:`pasargad`},627488:{name:`بانک کارآفرین`,slug:`karafarin`},502910:{name:`بانک کارآفرین`,slug:`karafarin`},621986:{name:`بانک سامان`,slug:`saman`},639346:{name:`بانک سینا`,slug:`sina`},639607:{name:`بانک سرمایه`,slug:`sarmayeh`},636214:{name:`بانک آینده`,slug:`ayandeh`},502806:{name:`بانک شهر`,slug:`shahr`},504706:{name:`بانک شهر`,slug:`shahr`},502938:{name:`بانک دی`,slug:`dey`},603769:{name:`بانک صادرات`,slug:`saderat`},610433:{name:`بانک ملت`,slug:`mellat`},991975:{name:`بانک ملت`,slug:`mellat`},627353:{name:`بانک تجارت`,slug:`tejarat`},585983:{name:`بانک تجارت`,slug:`tejarat`},589463:{name:`بانک رفاه`,slug:`refah`},505785:{name:`بانک ایران زمین`,slug:`iran-zamin`},606373:{name:`بانک قرض‌الحسنه مهر ایران`,slug:`mehr-iran`},505416:{name:`بانک گردشگری`,slug:`gardeshgari`},636795:{name:`بانک مرکزی`,slug:`markazi`},585947:{name:`بانک خاورمیانه`,slug:`khavarmianeh`},505809:{name:`بانک خاورمیانه`,slug:`khavarmianeh`},507677:{name:`موسسه اعتباری نور`,slug:`noor`},606256:{name:`موسسه اعتباری ملل`,slug:`melal`},628157:{name:`موسسه اعتباری توسعه`,slug:`tosee`},504172:{name:`بانک قرض‌الحسنه رسالت`,slug:`resalat`},627381:{name:`بانک انصار`,slug:`ansar`},639599:{name:`بانک قوامین`,slug:`ghavamin`},636949:{name:`بانک حکمت ایرانیان`,slug:`hekmat`},505801:{name:`موسسه اعتباری کوثر`,slug:`kosar`},639370:{name:`بانک مهر اقتصاد`,slug:`mehr-eghtesad`}};function i(e){let t=0;for(let n=0;n<e.length;n++){let r=Number(e[e.length-1-n]);n%2==1&&(r*=2,r>9&&(r-=9)),t+=r}return t%10==0}function a(t){let n=e(t);return/^\d{16}$/.test(n)&&i(n)}function o(t){let n=e(t);return n.length>=6?r[n.slice(0,6)]??null:null}function s(t){return e(t).slice(0,16).replace(/(\d{4})(?=\d)/g,`$1 `)}export{a as i,s as n,o as r,n as t};
1
+ import{M as e}from"./base-BqFAMlwG.js";const t={melli:`Bank Melli`,sepah:`Bank Sepah`,edbi:`Export Development Bank`,bim:`Bank of Industry and Mine`,keshavarzi:`Bank Keshavarzi`,maskan:`Bank Maskan`,postbank:`Post Bank`,"tosee-taavon":`Tose'e Ta'avon Bank`,"eghtesad-novin":`EN Bank`,parsian:`Parsian Bank`,pasargad:`Bank Pasargad`,karafarin:`Karafarin Bank`,saman:`Saman Bank`,sina:`Sina Bank`,sarmayeh:`Sarmayeh Bank`,ayandeh:`Ayandeh Bank`,shahr:`Shahr Bank`,dey:`Dey Bank`,saderat:`Bank Saderat`,mellat:`Bank Mellat`,tejarat:`Tejarat Bank`,refah:`Refah Bank`,"iran-zamin":`Iran Zamin Bank`,"mehr-iran":`Mehr Iran Bank`,gardeshgari:`Tourism Bank`,markazi:`Central Bank of Iran`,khavarmianeh:`Middle East Bank`,noor:`Noor Credit Institution`,melal:`Melal Credit Institution`,tosee:`Tose'e Credit Institution`,resalat:`Resalat Bank`,ansar:`Ansar Bank`,ghavamin:`Ghavamin Bank`,hekmat:`Hekmat Iranian Bank`,kosar:`Kosar Credit Institution`,"mehr-eghtesad":`Mehr Eghtesad Bank`};function n(e,n=`fa`){return n===`en`?t[e.slug]??e.name:e.name}const r={603799:{name:`بانک ملی`,slug:`melli`},589210:{name:`بانک سپه`,slug:`sepah`},627648:{name:`بانک توسعه صادرات`,slug:`edbi`},627961:{name:`بانک صنعت و معدن`,slug:`bim`},603770:{name:`بانک کشاورزی`,slug:`keshavarzi`},639217:{name:`بانک کشاورزی`,slug:`keshavarzi`},628023:{name:`بانک مسکن`,slug:`maskan`},627760:{name:`پست بانک`,slug:`postbank`},502908:{name:`بانک توسعه تعاون`,slug:`tosee-taavon`},627412:{name:`بانک اقتصاد نوین`,slug:`eghtesad-novin`},622106:{name:`بانک پارسیان`,slug:`parsian`},639194:{name:`بانک پارسیان`,slug:`parsian`},627884:{name:`بانک پارسیان`,slug:`parsian`},502229:{name:`بانک پاسارگاد`,slug:`pasargad`},639347:{name:`بانک پاسارگاد`,slug:`pasargad`},627488:{name:`بانک کارآفرین`,slug:`karafarin`},502910:{name:`بانک کارآفرین`,slug:`karafarin`},621986:{name:`بانک سامان`,slug:`saman`},639346:{name:`بانک سینا`,slug:`sina`},639607:{name:`بانک سرمایه`,slug:`sarmayeh`},636214:{name:`بانک آینده`,slug:`ayandeh`},502806:{name:`بانک شهر`,slug:`shahr`},504706:{name:`بانک شهر`,slug:`shahr`},502938:{name:`بانک دی`,slug:`dey`},603769:{name:`بانک صادرات`,slug:`saderat`},610433:{name:`بانک ملت`,slug:`mellat`},991975:{name:`بانک ملت`,slug:`mellat`},627353:{name:`بانک تجارت`,slug:`tejarat`},585983:{name:`بانک تجارت`,slug:`tejarat`},589463:{name:`بانک رفاه`,slug:`refah`},505785:{name:`بانک ایران زمین`,slug:`iran-zamin`},606373:{name:`بانک قرض‌الحسنه مهر ایران`,slug:`mehr-iran`},505416:{name:`بانک گردشگری`,slug:`gardeshgari`},636795:{name:`بانک مرکزی`,slug:`markazi`},585947:{name:`بانک خاورمیانه`,slug:`khavarmianeh`},505809:{name:`بانک خاورمیانه`,slug:`khavarmianeh`},507677:{name:`موسسه اعتباری نور`,slug:`noor`},606256:{name:`موسسه اعتباری ملل`,slug:`melal`},628157:{name:`موسسه اعتباری توسعه`,slug:`tosee`},504172:{name:`بانک قرض‌الحسنه رسالت`,slug:`resalat`},627381:{name:`بانک انصار`,slug:`ansar`},639599:{name:`بانک قوامین`,slug:`ghavamin`},636949:{name:`بانک حکمت ایرانیان`,slug:`hekmat`},505801:{name:`موسسه اعتباری کوثر`,slug:`kosar`},639370:{name:`بانک مهر اقتصاد`,slug:`mehr-eghtesad`}};function i(e){let t=0;for(let n=0;n<e.length;n++){let r=Number(e[e.length-1-n]);n%2==1&&(r*=2,r>9&&(r-=9)),t+=r}return t%10==0}function a(t){let n=e(t);return/^\d{16}$/.test(n)&&i(n)}function o(t){let n=e(t);return n.length>=6?r[n.slice(0,6)]??null:null}function s(t){return e(t).slice(0,16).replace(/(\d{4})(?=\d)/g,`$1 `)}export{a as i,s as n,o as r,n as t};
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"./card-BKiwJF34.js";import{A as r,C as i,E as a,M as o,a as s,c,d as l,i as u,k as d,l as f,m as p,n as m,o as h,p as g,r as _,s as v,t as y,y as b}from"./base-D4tCOysh.js";import{t as x}from"./money-CjGI2VIQ.js";import{t as S}from"./time-CwOYrtK-.js";import{t as C}from"./holidays-Cu6IfbTL.js";import{t as w}from"./words-BdADG_9U.js";import{i as T,l as E,m as D,o as O,p as k,r as A,s as j}from"./parts-5fVaWtRe.js";function M(e,t){e&&import(`./dist-D670Gw0K.js`).then(n=>{let r=n.bankLogoDataUri(e.slug);r&&t(r)}).catch(()=>{})}const N={mellat:`#b5172b`,melli:`#0b3f7d`,saderat:`#203b8c`,tejarat:`#173c7a`,sepah:`#0d56a0`,pasargad:`#2a2418`,saman:`#0a78b8`,parsian:`#7f1c3c`,keshavarzi:`#0d6b3a`,maskan:`#d4600a`,refah:`#0a5a94`,"eghtesad-novin":`#5d2a86`,ayandeh:`#5a3a26`,shahr:`#b3232a`,resalat:`#23853a`,postbank:`#0a703a`,dey:`#00676d`,sina:`#1d4a92`,karafarin:`#00877c`,"mehr-iran":`#178e42`,tosee:`#3b3f8f`,gardeshgari:`#8a1f4c`,"iran-zamin":`#6a1f7a`,sarmayeh:`#2b2b6e`};var P=class extends y{connectedCallback(){this.render()}attributeChangedCallback(e,t,n){this.isConnected&&t!==n&&this.render()}render(){let r=g(),i=l(),a=o(this.getAttribute(`number`)??``).slice(0,16),s=t(a),c=u(this,`masked`),d=c&&a.length===16?`${a.slice(0,6)}******${a.slice(12)}`:a,m=e=>p(this,e),h=this.getAttribute(`expiry`),_=this.getAttribute(`holder`),v=c?r.bankCard.endingIn(m(a.slice(-4))):m(e(a)),y=s?N[s.slug]:void 0,b=s?n(s,i):r.bankCard.card;this.innerHTML=`<figure class="k-bankcard"${y?` style="--k-bankcard-color: ${y}"`:``} aria-label="${f(`${s?r.bankCard.cardOf(b):r.bankCard.card}${r.common.list}${v}`)}"><div class="k-bankcard__top"><span class="k-bankcard__bank">${f(b)}</span><svg class="k-bankcard__chip" viewBox="0 0 40 30" aria-hidden="true"><rect x="0.5" y="0.5" width="39" height="29" rx="5"/><path d="M14 1v28M26 1v28M1 10h13M26 10h13M1 20h13M26 20h13"/></svg></div><div class="k-bankcard__number" dir="ltr" aria-hidden="true">${f(m(d.replace(/(.{4})(?=.)/g,`$1 `)))}</div><div class="k-bankcard__bottom"${_||h?``:` aria-hidden="true"`}>${_?`<span class="k-bankcard__holder">${f(_)}</span>`:``}${h?`<span class="k-bankcard__exp"><small>${f(r.bankCard.expiry)}</small><span dir="ltr">${f(m(h))}</span></span>`:``}</div></figure>`,this.getAttribute(`logo`)!==`false`&&M(s,e=>{let n=this.querySelector(`.k-bankcard__bank`);n&&!n.querySelector(`img`)&&t(o(this.getAttribute(`number`)??``))?.slug===s?.slug&&n.insertAdjacentHTML(`afterbegin`,`<img class="k-bankcard__logo" src="${e}" alt="" width="28" height="28">`)})}};P.observedAttributes=[`number`,`holder`,`expiry`,`masked`,`logo`,`digits`];const F={success:m.success,failed:m.error,pending:m.warning},I=j(`<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/>`),L=j(`<path d="m5 10.5 3.2 3L15 7"/>`,2);var R=class extends y{constructor(){super(...arguments),this.actions=[],this.root=null,this.key=b(`kashi-receipt`)}connectedCallback(){_(()=>{this.isConnected&&(this.root||(this.actions=D(this),this.root=document.createElement(`section`),this.replaceChildren(this.root),this.root.addEventListener(`click`,async e=>{let t=e.target.closest(`[data-copy]`);t&&await A(this.getAttribute(`tracking-code`)??``)&&(t.innerHTML=L,t.setAttribute(`aria-label`,g().copy.copied),clearTimeout(this.timer),this.timer=setTimeout(()=>{t.innerHTML=I,t.setAttribute(`aria-label`,g().receipt.copyTracking)},2e3),c(this,`kashi-copy`,{value:this.getAttribute(`tracking-code`)}))})),this.render())})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){this.root&&t!==n&&this.render()}render(){let e=g(),r=e.receipt,a=l(),s=v(this),c=[`success`,`failed`,`pending`].includes(this.getAttribute(`status`)??``)?this.getAttribute(`status`):`success`,u=Number(this.getAttribute(`amount`)??0)||0,d=this.getAttribute(`unit`)===`rial`?`rial`:`toman`,m=d===`toman`?e.money.toman:e.money.rial,h=o(this.getAttribute(`card-number`)??``),_=h?t(h):null,y=this.getAttribute(`tracking-code`),b=this.getAttribute(`reference-id`),C=k(this.getAttribute(`date`)),T=e=>p(this,e),D=[],A=this.getAttribute(`merchant`);A&&D.push([f(r.merchant),f(A)]),y&&D.push([f(r.tracking),`<span class="k-receipt__code"><span dir="ltr">${f(T(y))}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--xs" data-copy aria-label="${f(r.copyTracking)}">${I}</button></span>`]),b&&D.push([f(r.reference),`<span dir="ltr">${f(T(b))}</span>`]),h&&D.push([f(r.card),`<span class="k-receipt__card"><span dir="ltr" aria-label="${f(`${_?n(_,a):r.card} ${e.bankCard.endingIn(T(h.slice(-4)))}`)}">${f(T(`${h.slice(0,4)}-${h.slice(4,6)}**-****-${h.slice(-4)}`))}</span></span>`]),C&&D.push([f(r.date),f(`${i(C,{style:`long`,digits:s,locale:a})}${e.common.list}${r.at(T(S({hours:C.getHours(),minutes:C.getMinutes()})))}`)]);for(let[e,t]of E(this,`rows`,[]))D.push([f(e),f(t)]);let j=this.root;j.className=`k-receipt`,j.dataset.status=c,j.setAttribute(`aria-labelledby`,`${this.key}-t`);let N=this.getAttribute(`description`);if(j.innerHTML=`<div class="k-receipt__head"><span class="k-receipt__icon">${F[c]}</span><h2 class="k-receipt__title" id="${this.key}-t">${f(this.getAttribute(`heading`)??r[c])}</h2>${N?`<p class="k-receipt__desc">${f(N)}</p>`:``}<data value="${u}" class="k-money k-money--xl k-receipt__amount"><span class="k-money__amount">${f(x(u,{unit:d,from:d,digits:s,locale:a,showUnit:!1}))}</span><span class="k-money__unit">${f(m)}</span></data><p class="k-receipt__words">${f(`${w(Math.round(u),{locale:a})} ${m}`)}</p></div>${D.length?`<dl class="k-receipt__rows">${D.map(([e,t])=>`<div class="k-receipt__row"><dt>${e}</dt><dd>${t}</dd></div>`).join(``)}</dl>`:``}`,O(this.actions)){let e=document.createElement(`div`);e.className=`k-receipt__actions`,e.append(...this.actions),j.append(e)}M(_,e=>{let t=j.querySelector(`.k-receipt__card`);t&&!t.querySelector(`img`)&&t.insertAdjacentHTML(`afterbegin`,`<img src="${e}" alt="" width="20" height="20">`)})}};R.observedAttributes=[`status`,`amount`,`unit`,`heading`,`description`,`merchant`,`tracking-code`,`reference-id`,`card-number`,`date`,`rows`,`digits`];const z=new Intl.DateTimeFormat(`fa-IR-u-ca-gregory-nu-arabext`,{day:`numeric`,month:`long`,year:`numeric`}),B=new Intl.DateTimeFormat(`en-US`,{day:`numeric`,month:`long`,year:`numeric`}),V=e=>{let t=e?.match(/^(\d{4})-(\d{2})-(\d{2})$/);return t?new Date(+t[1],t[2]-1,+t[3]):k(e)};var H=class extends y{connectedCallback(){this.render()}attributeChangedCallback(e,t,n){this.isConnected&&t!==n&&this.render()}render(){let e=V(this.getAttribute(`date`))??/* @__PURE__ */ new Date,{jy:t,jm:n,jd:i}=r(e),{months:o,weekdays:c,friday:u}=s(),m=l(),h=this.getAttribute(`holidays`)===`false`?null:C(e,{locale:m}),g=h&&h!==u?h:null,_=this.getAttribute(`size`)??`md`,y=this.getAttribute(`gregorian`)!==`false`,b=(m===`en`?B:z).format(e);m!==`en`&&v(this)===`latin`&&(b=b.replace(/[۰-۹]/g,e=>String(e.charCodeAt(0)-1776))),this.innerHTML=`<time datetime="${d(e)}" class="${T(`k-datetile`,`k-datetile--${_}`)}"${h?` data-holiday`:``}><span class="k-datetile__head">${f(o[n-1])} ${p(this,t)}</span><span class="k-datetile__day">${p(this,i)}</span><span class="k-datetile__weekday">${f(c[a(e)])}</span>${g?`<span class="k-datetile__occasion">${f(g)}</span>`:``}${y?`<span class="k-datetile__greg">${f(b)}</span>`:``}</time>`}};H.observedAttributes=[`date`,`holidays`,`gregorian`,`size`,`digits`],h(`kashi-bank-card`,P,`block`),h(`kashi-receipt`,R,`block`),h(`kashi-date-tile`,H);export{P as KashiBankCard,H as KashiDateTile,R as KashiReceipt};
1
+ import{n as e,r as t,t as n}from"./card-C0nariT-.js";import{A as r,C as i,E as a,M as o,a as s,c,d as l,i as u,k as d,l as f,m as p,n as m,o as h,p as g,r as _,s as v,t as y,y as b}from"./base-BqFAMlwG.js";import{t as x}from"./money-BFEbgLJn.js";import{t as S}from"./time-oyKIQ2bk.js";import{t as C}from"./holidays-DgmHlqJX.js";import{t as w}from"./words-BdADG_9U.js";import{i as T,l as E,m as D,o as O,p as k,r as A,s as j}from"./parts-5fVaWtRe.js";function M(e,t){e&&import(`./dist-D670Gw0K.js`).then(n=>{let r=n.bankLogoDataUri(e.slug);r&&t(r)}).catch(()=>{})}const N={mellat:`#b5172b`,melli:`#0b3f7d`,saderat:`#203b8c`,tejarat:`#173c7a`,sepah:`#0d56a0`,pasargad:`#2a2418`,saman:`#0a78b8`,parsian:`#7f1c3c`,keshavarzi:`#0d6b3a`,maskan:`#d4600a`,refah:`#0a5a94`,"eghtesad-novin":`#5d2a86`,ayandeh:`#5a3a26`,shahr:`#b3232a`,resalat:`#23853a`,postbank:`#0a703a`,dey:`#00676d`,sina:`#1d4a92`,karafarin:`#00877c`,"mehr-iran":`#178e42`,tosee:`#3b3f8f`,gardeshgari:`#8a1f4c`,"iran-zamin":`#6a1f7a`,sarmayeh:`#2b2b6e`};var P=class extends y{connectedCallback(){this.render()}attributeChangedCallback(e,t,n){this.isConnected&&t!==n&&this.render()}render(){let r=g(),i=l(),a=o(this.getAttribute(`number`)??``).slice(0,16),s=t(a),c=u(this,`masked`),d=c&&a.length===16?`${a.slice(0,6)}******${a.slice(12)}`:a,m=e=>p(this,e),h=this.getAttribute(`expiry`),_=this.getAttribute(`holder`),v=c?r.bankCard.endingIn(m(a.slice(-4))):m(e(a)),y=s?N[s.slug]:void 0,b=s?n(s,i):r.bankCard.card;this.innerHTML=`<figure class="k-bankcard"${y?` style="--k-bankcard-color: ${y}"`:``} aria-label="${f(`${s?r.bankCard.cardOf(b):r.bankCard.card}${r.common.list}${v}`)}"><div class="k-bankcard__top"><span class="k-bankcard__bank">${f(b)}</span><svg class="k-bankcard__chip" viewBox="0 0 40 30" aria-hidden="true"><rect x="0.5" y="0.5" width="39" height="29" rx="5"/><path d="M14 1v28M26 1v28M1 10h13M26 10h13M1 20h13M26 20h13"/></svg></div><div class="k-bankcard__number" dir="ltr" aria-hidden="true">${f(m(d.replace(/(.{4})(?=.)/g,`$1 `)))}</div><div class="k-bankcard__bottom"${_||h?``:` aria-hidden="true"`}>${_?`<span class="k-bankcard__holder">${f(_)}</span>`:``}${h?`<span class="k-bankcard__exp"><small>${f(r.bankCard.expiry)}</small><span dir="ltr">${f(m(h))}</span></span>`:``}</div></figure>`,this.getAttribute(`logo`)!==`false`&&M(s,e=>{let n=this.querySelector(`.k-bankcard__bank`);n&&!n.querySelector(`img`)&&t(o(this.getAttribute(`number`)??``))?.slug===s?.slug&&n.insertAdjacentHTML(`afterbegin`,`<img class="k-bankcard__logo" src="${e}" alt="" width="28" height="28">`)})}};P.observedAttributes=[`number`,`holder`,`expiry`,`masked`,`logo`,`digits`];const F={success:m.success,failed:m.error,pending:m.warning},I=j(`<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/>`),L=j(`<path d="m5 10.5 3.2 3L15 7"/>`,2);var R=class extends y{constructor(){super(...arguments),this.actions=[],this.root=null,this.key=b(`kashi-receipt`)}connectedCallback(){_(()=>{this.isConnected&&(this.root||(this.actions=D(this),this.root=document.createElement(`section`),this.replaceChildren(this.root),this.root.addEventListener(`click`,async e=>{let t=e.target.closest(`[data-copy]`);t&&await A(this.getAttribute(`tracking-code`)??``)&&(t.innerHTML=L,t.setAttribute(`aria-label`,g().copy.copied),clearTimeout(this.timer),this.timer=setTimeout(()=>{t.innerHTML=I,t.setAttribute(`aria-label`,g().receipt.copyTracking)},2e3),c(this,`kashi-copy`,{value:this.getAttribute(`tracking-code`)}))})),this.render())})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){this.root&&t!==n&&this.render()}render(){let e=g(),r=e.receipt,a=l(),s=v(this),c=[`success`,`failed`,`pending`].includes(this.getAttribute(`status`)??``)?this.getAttribute(`status`):`success`,u=Number(this.getAttribute(`amount`)??0)||0,d=this.getAttribute(`unit`)===`rial`?`rial`:`toman`,m=d===`toman`?e.money.toman:e.money.rial,h=o(this.getAttribute(`card-number`)??``),_=h?t(h):null,y=this.getAttribute(`tracking-code`),b=this.getAttribute(`reference-id`),C=k(this.getAttribute(`date`)),T=e=>p(this,e),D=[],A=this.getAttribute(`merchant`);A&&D.push([f(r.merchant),f(A)]),y&&D.push([f(r.tracking),`<span class="k-receipt__code"><span dir="ltr">${f(T(y))}</span><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--xs" data-copy aria-label="${f(r.copyTracking)}">${I}</button></span>`]),b&&D.push([f(r.reference),`<span dir="ltr">${f(T(b))}</span>`]),h&&D.push([f(r.card),`<span class="k-receipt__card"><span dir="ltr" aria-label="${f(`${_?n(_,a):r.card} ${e.bankCard.endingIn(T(h.slice(-4)))}`)}">${f(T(`${h.slice(0,4)}-${h.slice(4,6)}**-****-${h.slice(-4)}`))}</span></span>`]),C&&D.push([f(r.date),f(`${i(C,{style:`long`,digits:s,locale:a})}${e.common.list}${r.at(T(S({hours:C.getHours(),minutes:C.getMinutes()})))}`)]);for(let[e,t]of E(this,`rows`,[]))D.push([f(e),f(t)]);let j=this.root;j.className=`k-receipt`,j.dataset.status=c,j.setAttribute(`aria-labelledby`,`${this.key}-t`);let N=this.getAttribute(`description`);if(j.innerHTML=`<div class="k-receipt__head"><span class="k-receipt__icon">${F[c]}</span><h2 class="k-receipt__title" id="${this.key}-t">${f(this.getAttribute(`heading`)??r[c])}</h2>${N?`<p class="k-receipt__desc">${f(N)}</p>`:``}<data value="${u}" class="k-money k-money--xl k-receipt__amount"><span class="k-money__amount">${f(x(u,{unit:d,from:d,digits:s,locale:a,showUnit:!1}))}</span><span class="k-money__unit">${f(m)}</span></data><p class="k-receipt__words">${f(`${w(Math.round(u),{locale:a})} ${m}`)}</p></div>${D.length?`<dl class="k-receipt__rows">${D.map(([e,t])=>`<div class="k-receipt__row"><dt>${e}</dt><dd>${t}</dd></div>`).join(``)}</dl>`:``}`,O(this.actions)){let e=document.createElement(`div`);e.className=`k-receipt__actions`,e.append(...this.actions),j.append(e)}M(_,e=>{let t=j.querySelector(`.k-receipt__card`);t&&!t.querySelector(`img`)&&t.insertAdjacentHTML(`afterbegin`,`<img src="${e}" alt="" width="20" height="20">`)})}};R.observedAttributes=[`status`,`amount`,`unit`,`heading`,`description`,`merchant`,`tracking-code`,`reference-id`,`card-number`,`date`,`rows`,`digits`];const z=new Intl.DateTimeFormat(`fa-IR-u-ca-gregory-nu-arabext`,{day:`numeric`,month:`long`,year:`numeric`}),B=new Intl.DateTimeFormat(`en-US`,{day:`numeric`,month:`long`,year:`numeric`}),V=e=>{let t=e?.match(/^(\d{4})-(\d{2})-(\d{2})$/);return t?new Date(+t[1],t[2]-1,+t[3]):k(e)};var H=class extends y{connectedCallback(){this.render()}attributeChangedCallback(e,t,n){this.isConnected&&t!==n&&this.render()}render(){let e=V(this.getAttribute(`date`))??/* @__PURE__ */ new Date,{jy:t,jm:n,jd:i}=r(e),{months:o,weekdays:c,friday:u}=s(),m=l(),h=this.getAttribute(`holidays`)===`false`?null:C(e,{locale:m}),g=h&&h!==u?h:null,_=this.getAttribute(`size`)??`md`,y=this.getAttribute(`gregorian`)!==`false`,b=(m===`en`?B:z).format(e);m!==`en`&&v(this)===`latin`&&(b=b.replace(/[۰-۹]/g,e=>String(e.charCodeAt(0)-1776))),this.innerHTML=`<time datetime="${d(e)}" class="${T(`k-datetile`,`k-datetile--${_}`)}"${h?` data-holiday`:``}><span class="k-datetile__head">${f(o[n-1])} ${p(this,t)}</span><span class="k-datetile__day">${p(this,i)}</span><span class="k-datetile__weekday">${f(c[a(e)])}</span>${g?`<span class="k-datetile__occasion">${f(g)}</span>`:``}${y?`<span class="k-datetile__greg">${f(b)}</span>`:``}</time>`}};H.observedAttributes=[`date`,`holidays`,`gregorian`,`size`,`digits`],h(`kashi-bank-card`,P,`block`),h(`kashi-receipt`,R,`block`),h(`kashi-date-tile`,H);export{P as KashiBankCard,H as KashiDateTile,R as KashiReceipt};
@@ -1 +1 @@
1
- import{A as e,C as t,O as n,T as r,a as i,d as a,f as o,j as s,k as c,l,o as u,p as d,t as f,y as p}from"./base-D4tCOysh.js";const m=e=>s(e,{digits:o()}),h=e=>m(Math.round(e*10)/10).replace(`.`,d().common.decimal),g=e=>{let t=Math.abs(e),n=d().chart;return t>=1e9?h(e/1e9)+n.billion:t>=1e6?h(e/1e6)+n.million:t>=1e3?h(e/1e3)+n.thousand:m(e)};function _(e,t=4){if(e<=0)return[0];let n=e/t,r=10**Math.floor(Math.log10(n)),i=[1,2,2.5,5,10].map(e=>e*r).find(e=>e>=n);return Array.from({length:Math.ceil(e/i)+1},(e,t)=>t*i)}const v=(e,t)=>d().common.percent(h(e/(t||1)*100)),y=e=>e<8?`var(--k-chart-${e+1})`:`var(--k-text-quaternary)`,b=(e,t)=>{if(!e)return t;try{return JSON.parse(e)}catch{return t}};var x=class extends f{constructor(){super(...arguments),this.key=p(`kashi-chart`),this.props={}}connectedCallback(){this.draw()}attributeChangedCallback(){this.isConnected&&this.draw()}get format(){let e=this.getAttribute(`unit`);return this.fmt??(t=>`${m(Math.round(t))}${e?` ${e}`:``}`)}set format(e){this.fmt=e,this.isConnected&&this.draw()}read(e,t){return this.props[e]??b(this.getAttribute(e),t)}write(e,t){this.props[e]=t,this.isConnected&&this.draw()}get heading(){return this.getAttribute(`label`)??``}tip(e,t,n=0,r,i=[]){let a=e.querySelector(`:scope > .k-chart__tip`);if(t===null){a?.remove();return}a||(a=document.createElement(`div`),a.className=`k-chart__tip`,a.setAttribute(`aria-hidden`,`true`),e.append(a));let o=e.clientWidth;a.style.left=`${o?Math.min(Math.max(t,80),o-80):t}px`,a.style.top=`${n}px`,a.innerHTML=`${r?`<span class="k-chart__tip-title">${l(r)}</span>`:``}${i.map(e=>`<span class="k-chart__tip-row"${e.color?` style="--_c: ${e.color}"`:``}>${e.name===void 0?``:`<span>${e.color?`<i></i>`:``}${l(e.name)}</span>`}<strong>${l(e.value)}</strong></span>`).join(``)}`}at(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return{x:r.left+r.width/2-n.left,y:r.top-n.top}}},S=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}draw(){let e=this.format,t=this.series.length?this.series.slice(0,4):null,n=this.data,r=t?this.labels:n.map(e=>e.label),i=r.map((e,r)=>t?t.reduce((e,t)=>e+(t.values[r]??0),0):n[r].value),a=Math.max(0,...i),o=_(a),s=o.at(-1)||1,c=i.indexOf(a),u=this.getAttribute(`label-max`)!==`false`,f=n=>t?`${r[n]}: ${t.map(t=>`${t.name} ${e(t.values[n]??0)}`).join(d().common.list)}${d().common.list}${d().common.total} ${e(i[n])}`:`${r[n]}: ${e(i[n])}`,p=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart k-chart--bar" aria-labelledby="${this.key}-t" style="margin: 0${p?`; --k-chart-height: ${l(p)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p>${t&&t.length>1?`<ul class="k-chart__legend" aria-hidden="true">${t.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key k-chart__key--box"></span>${l(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot"><div class="k-bars__grid" aria-hidden="true">${o.map(e=>`<span data-v="${l(g(e))}"></span>`).join(``)}</div><div class="k-bars" role="list" aria-label="${l(this.heading)}">${r.map((n,r)=>`<div class="k-bars__col" role="listitem" tabindex="0" data-i="${r}" aria-label="${l(f(r))}" style="--_d: ${r*40}ms">${u&&r===c?`<span class="k-bars__value" aria-hidden="true">${l(e(i[r]))}</span>`:``}${t?`<span class="k-bars__stack" style="block-size: ${i[r]/s*100}%" aria-hidden="true">${t.map((e,t)=>`<span class="k-bars__seg" style="--_c: ${y(t)}; flex-grow: ${e.values[r]??0}"></span>`).join(``)}</span>`:`<span class="k-bars__bar" style="block-size: ${i[r]/s*100}%" aria-hidden="true"></span>`}<span class="k-bars__label" aria-hidden="true">${l(n)}</span></div>`).join(``)}</div></div></figure>`;let m=this.querySelector(`.k-chart__plot`),h=n=>{let a=Number(n.dataset.i);m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-bars__bar, .k-bars__stack`)??n,m);this.tip(m,o.x,o.y,r[a],t?[...t.map((t,n)=>({name:t.name,value:e(t.values[a]??0),color:y(n)})),{name:d().common.total,value:e(i[a])}]:[{value:e(i[a])}])},v=()=>{m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),this.tip(m,null)};m.querySelectorAll(`.k-bars__col`).forEach(e=>{e.addEventListener(`pointerenter`,()=>h(e)),e.addEventListener(`focus`,()=>h(e)),e.addEventListener(`pointerleave`,v),e.addEventListener(`blur`,v)})}};S.observedAttributes=[`label`,`data`,`labels`,`series`,`unit`,`label-max`,`height`];var C=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data,n=Math.max(1,...t.map(e=>e.value)),r=t.reduce((e,t)=>e+t.value,0);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><ol class="k-barlist" style="position: relative">${t.map((t,i)=>`<li class="k-barlist__row" data-i="${i}" style="--_d: ${i*60}ms"><span class="k-barlist__track"><span class="k-barlist__fill" style="inline-size: ${t.value/n*100}%" aria-hidden="true"></span>${t.href?`<a class="k-barlist__label" href="${l(t.href)}">${l(t.label)}</a>`:`<span class="k-barlist__label">${l(t.label)}</span>`}</span><span class="k-barlist__value">${l(e(t.value))} <span class="k-barlist__share">${v(t.value,r)}</span></span></li>`).join(``)}</ol></figure>`;let i=this.querySelector(`.k-barlist`);i.querySelectorAll(`.k-barlist__row`).forEach(n=>{n.addEventListener(`pointerenter`,()=>{let a=t[Number(n.dataset.i)];n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-barlist__fill`),i);this.tip(i,o.x,o.y,a.label,[{name:d().chart.value,value:e(a.value)},{name:d().chart.share,value:v(a.value,r)}])}),n.addEventListener(`pointerleave`,()=>{n.removeAttribute(`data-active`),this.tip(i,null)})})}};C.observedAttributes=[`label`,`data`,`unit`];var w=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data.slice(0,4),n=t.reduce((e,t)=>e+t.value,0),r=this.getAttribute(`percent`)!==`false`;this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><div class="k-proportion__wrap"><div class="k-proportion" aria-hidden="true">${t.map((e,t)=>`<span class="k-proportion__seg" data-i="${t}" style="--_c: ${y(t)}; flex-grow: ${e.value}"></span>`).join(``)}</div></div><ul class="k-proportion__legend">${t.map((t,i)=>`<li data-i="${i}" style="--_c: ${y(i)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span>${l(t.label)}</span><strong>${l(r?v(t.value,n):e(t.value))}</strong>${r?`<span class="k-proportion__abs">${l(e(t.value))}</span>`:``}</li>`).join(``)}</ul></figure>`;let i=this.querySelector(`.k-proportion__wrap`),a=e=>this.querySelectorAll(`[data-i]`).forEach(t=>t.toggleAttribute(`data-active`,Number(t.dataset.i)===e));i.querySelectorAll(`.k-proportion__seg`).forEach(r=>{r.addEventListener(`pointerenter`,()=>{let o=Number(r.dataset.i);a(o);let s=this.at(r,i);this.tip(i,s.x,s.y,void 0,[{name:t[o].label,value:v(t[o].value,n),color:y(o)},{name:d().chart.count,value:e(t[o].value)}])}),r.addEventListener(`pointerleave`,()=>{a(null),this.tip(i,null)})})}};w.observedAttributes=[`label`,`data`,`unit`,`percent`];var T=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=[...this.data].sort((e,t)=>t.value-e.value),n=t.length>5?[...t.slice(0,4),{label:d().common.other,value:t.slice(4).reduce((e,t)=>e+t.value,0)}]:t,r=n.reduce((e,t)=>e+t.value,0)||1,i=e=>e<4?y(e):`var(--k-text-quaternary)`,a=this.getAttribute(`variant`)!==`pie`,o=Number(this.getAttribute(`size`))||176,s=this.getAttribute(`total-label`)??d().common.total,c=a?40:25,u=a?16:50,f=2*Math.PI*c,p=n.length>1?a?1.6:.8:0,m=0,h=n.map(e=>{let t=e.value/r*f,n={start:m,len:t};return m+=t,n});this.innerHTML=`<figure class="k-chart k-pie" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><div class="k-pie__body"><div class="k-pie__plot" style="inline-size: ${o}px; block-size: ${o}px"><svg viewBox="0 0 100 100" class="k-pie__svg" aria-hidden="true">${a?`<circle cx="50" cy="50" r="${c}" fill="none" stroke="var(--k-bg-tertiary)" stroke-width="${u}"></circle>`:``}${n.map((e,t)=>`<circle class="k-pie__slice" data-i="${t}" cx="50" cy="50" r="${c}" fill="none" stroke="${i(t)}" stroke-width="${u}" stroke-dasharray="${Math.max(0,h[t].len-p)} ${f}" stroke-dashoffset="${-h[t].start}" transform="rotate(-90 50 50)" style="--_d: ${t*80}ms"></circle>`).join(``)}</svg>${a?`<div class="k-pie__center" aria-hidden="true"><strong>${l(e(r))}</strong><span>${l(s)}</span></div>`:``}</div><ul class="k-pie__legend">${n.map((t,n)=>`<li data-i="${n}" style="--_c: ${i(n)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span class="k-pie__name">${l(t.label)}</span><strong>${v(t.value,r)}</strong><span class="k-pie__abs">${l(e(t.value))}</span></li>`).join(``)}</ul></div></figure>`;let g=this.querySelector(`.k-pie__plot`),_=this.querySelector(`.k-pie__center`),b=e=>{let t=(h[e].start+h[e].len/2)/f*2*Math.PI-Math.PI/2,n=a?c:c*1.3;return{x:(50+n*Math.cos(t))/100*o,y:(50+n*Math.sin(t))/100*o-8}},x=t=>{this.querySelectorAll(`[data-i]`).forEach(e=>e.toggleAttribute(`data-active`,Number(e.dataset.i)===t)),_&&(_.innerHTML=t===null?`<strong>${l(e(r))}</strong><span>${l(s)}</span>`:`<strong>${v(n[t].value,r)}</strong><span>${l(n[t].label)}</span>`),a||(t===null?this.tip(g,null):this.tip(g,b(t).x,b(t).y,void 0,[{name:n[t].label,value:v(n[t].value,r),color:i(t)},{name:d().chart.count,value:e(n[t].value)}]))};this.querySelectorAll(`.k-pie__slice, .k-pie__legend li`).forEach(e=>e.addEventListener(`pointerenter`,()=>x(Number(e.dataset.i)))),g.addEventListener(`pointerleave`,()=>x(null)),this.querySelector(`.k-pie__legend`).addEventListener(`pointerleave`,()=>x(null))}};T.observedAttributes=[`label`,`data`,`unit`,`variant`,`total-label`,`size`];var E=class extends x{get values(){return this.props.values??(this.getAttribute(`values`)??``).split(/[,،\s]+/).filter(Boolean).map(Number).filter(e=>!Number.isNaN(e))}set values(e){this.write(`values`,e)}draw(){let e=this.values;if(!e.length){this.innerHTML=``;return}let t=Math.max(...e),n=Math.min(...e),r=Math.max(t-n,Math.abs(t)*.25)||1,i=(t+n)/2-r/2,a=e.map((t,n)=>`${n?`L`:`M`}${n/Math.max(1,e.length-1)*100},${28-(t-i)/r*24}`).join(` `),o=this.getAttribute(`tone`)??`brand`,s=o===`neutral`?`var(--k-text-tertiary)`:o===`brand`?`var(--k-text-brand)`:`var(--k-text-${o})`,c=this.getAttribute(`label`);this.innerHTML=`<svg class="k-sparkline" viewBox="0 0 100 30" preserveAspectRatio="none"${c?` role="img" aria-label="${l(c)}"`:` aria-hidden="true"`} style="color: ${s}">${this.getAttribute(`area`)===`false`?``:`<path d="${a} L100,30 L0,30 Z" fill="currentColor" opacity="0.1"></path>`}<path d="${a}" fill="none" stroke="currentColor" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round" stroke-linecap="round"></path></svg>`}};E.observedAttributes=[`values`,`tone`,`area`,`label`];var D=class extends x{constructor(){super(...arguments),this.ro=null,this.active=null}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}connectedCallback(){if(super.connectedCallback(),typeof ResizeObserver<`u`&&!this.ro){let e=0;this.ro=new ResizeObserver(()=>{let t=this.clientWidth;t&&t!==e&&(e=t,this.paintSvg())}),this.ro.observe(this)}}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}draw(){let e=this.series.slice(0,4),t=this.format,n=this.labels,r=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0${r?`; --k-chart-height: ${l(r)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p>${e.length>1?`<ul class="k-chart__legend" aria-hidden="true">${e.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key"></span>${l(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot" tabindex="0" role="img" aria-label="${l(d().chart.keyboard(this.heading))}" aria-describedby="${this.key}-live"><svg class="k-chart__svg" aria-hidden="true" direction="ltr"></svg></div><span class="k-sr-only" aria-live="polite" id="${this.key}-live"></span><table class="k-sr-only"><caption>${l(this.heading)}</caption><thead><tr><th scope="col">${l(d().chart.period)}</th>${e.map(e=>`<th scope="col">${l(e.name)}</th>`).join(``)}</tr></thead><tbody>${n.map((n,r)=>`<tr><th scope="row">${l(n)}</th>${e.map(e=>`<td>${l(t(e.values[r]))}</td>`).join(``)}</tr>`).join(``)}</tbody></table></figure>`;let i=this.querySelector(`.k-chart__plot`);i.addEventListener(`pointermove`,e=>this.pick(e.clientX)),i.addEventListener(`pointerleave`,()=>this.setActive(null)),i.addEventListener(`blur`,()=>this.setActive(null)),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,r=n.length,a={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];a?(e.preventDefault(),this.setActive(Math.min(r-1,Math.max(0,(this.active??(a>0?-1:r))+a)))):e.key===`Home`?this.setActive(0):e.key===`End`?this.setActive(r-1):e.key===`Escape`&&this.setActive(null)}),this.active=null,this.paintSvg()}geometry(){let e=this.querySelector(`.k-chart__plot`),t=this.series.slice(0,4),n=this.labels,r=e.clientWidth||600,i=e.clientHeight||220,a=getComputedStyle(e).direction===`rtl`,o={top:12,bottom:24,start:52,end:t.length>1?64:16},s=_(Math.max(0,...t.flatMap(e=>e.values))),c=s.at(-1)||1,l=Math.max(1,r-o.start-o.end),u=Math.max(1,i-o.top-o.bottom);return{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:u,x:e=>{let t=n.length>1?e/(n.length-1):.5;return a?r-o.start-t*l:o.start+t*l},y:e=>o.top+u-e/c*u}}paintSvg(){if(!this.querySelector(`.k-chart__plot`))return;let{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:c,innerH:u,x:f,y:p}=this.geometry(),m=e.querySelector(`svg`),h=a?r-o.start+8:o.start-8,_=a?`start`:`end`,v=n.length-1,b=t.map((e,t)=>({i:t,y:p(e.values[v])})).sort((e,t)=>e.y-t.y);for(let e=1;e<b.length;e++)b[e].y-b[e-1].y<14&&(b[e].y=b[e-1].y+14);let x=Object.fromEntries(b.map(e=>[e.i,e.y])),S=Math.max(1,Math.ceil(n.length/Math.max(2,Math.floor(c/64)))),C=`${this.key}-fade`,w=this.active;m.innerHTML=`<g class="k-chart__grid">${s.map(e=>`<line x1="${o.start}" x2="${r-o.end}" y1="${p(e)}" y2="${p(e)}"${a?` transform="translate(${o.end-o.start} 0)"`:``}></line>`).join(``)}</g>${s.map(e=>`<text class="k-chart__tick" x="${h}" y="${p(e)+4}" text-anchor="${_}">${l(g(e))}</text>`).join(``)}${n.map((e,t)=>t%S===0||t===v?`<text class="k-chart__tick" x="${f(t)}" y="${i-6}" text-anchor="middle">${l(e)}</text>`:``).join(``)}<defs><linearGradient id="${C}" x1="0" y1="0" x2="0" y2="1"><stop offset="0" style="stop-color: var(--k-chart-1); stop-opacity: 0.28"></stop><stop offset="1" style="stop-color: var(--k-chart-1); stop-opacity: 0"></stop></linearGradient></defs>${t.length===1&&this.getAttribute(`area`)!==`false`?`<path class="k-chart__area" fill="url(#${C})" d="M${f(0)},${p(0)} ${t[0].values.map((e,t)=>`L${f(t)},${p(e)}`).join(` `)} L${f(v)},${p(0)} Z"></path>`:``}${w===null?``:`<line class="k-chart__cross" x1="${f(w)}" x2="${f(w)}" y1="${o.top}" y2="${o.top+u}"></line>`}${t.map((e,n)=>`<g style="--_c: ${y(n)}"><path class="k-chart__line" pathLength="1" d="${e.values.map((e,t)=>`${t?`L`:`M`}${f(t)},${p(e)}`).join(` `)}"></path><circle class="k-chart__dot" cx="${f(e.values.length-1)}" cy="${p(e.values.at(-1)??0)}" r="4"></circle>${t.length>1?`<text class="k-chart__end" x="${f(v)+(a?-8:8)}" y="${x[n]+4}" text-anchor="${a?`end`:`start`}">${l(e.name)}</text>`:``}${w===null?``:`<circle class="k-chart__dot" cx="${f(w)}" cy="${p(e.values[w])}" r="4.5"></circle>`}</g>`).join(``)}`;let T=this.format;w===null?this.tip(e,null):this.tip(e,f(w),Math.min(...t.map(e=>p(e.values[w])))-6,n[w],t.map((e,t)=>({name:e.name,value:T(e.values[w]),color:y(t)}))),this.querySelector(`#${this.key}-live`).textContent=w===null?``:`${n[w]}: ${t.map(e=>`${e.name} ${T(e.values[w])}`).join(d().common.list)}`}pick(e){let{plot:t,labels:n,x:r}=this.geometry(),i=e-t.getBoundingClientRect().left,a=0;n.forEach((e,t)=>{Math.abs(r(t)-i)<Math.abs(r(a)-i)&&(a=t)}),a!==this.active&&this.setActive(a)}setActive(e){this.active=e,this.paintSvg()}};D.observedAttributes=[`label`,`labels`,`series`,`unit`,`area`,`height`];var O=class extends x{get data(){return this.read(`data`,{})}set data(e){this.write(`data`,e)}draw(){let s=this.data,u=Number(this.getAttribute(`year`))||e(/* @__PURE__ */ new Date).jy,f=d().heatmap,p=this.getAttribute(`unit`)??f.unit,h=[];for(let e=1;e<=12;e++)for(let t=1;t<=r(u,e);t++){let r=n(u,e,t);h.push({date:r,value:s[c(r)]??0})}let g=Math.max(0,...h.map(e=>e.value)),_=e=>e<=0||g===0?0:Math.max(1,Math.ceil(e/g*4)),v=(h[0].date.getDay()+1)%7,y=e=>Math.floor((e+v)/7),b=i().months.map((t,n)=>({name:t,col:y(h.findIndex(t=>e(t.date).jm===n+1))})),x=h.reduce((e,t)=>e+t.value,0),S=i().months.map((t,n)=>({name:t,sum:h.filter(t=>e(t.date).jm===n+1).reduce((e,t)=>e+t.value,0)})),C=m(u).replace(/[٬,]/g,``),w=this.getAttribute(`label`)??f.inYear(p,C);this.innerHTML=`<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll" tabindex="0" role="region" aria-label="${l(w)}"><div role="img" aria-label="${l(`${w}: ${m(x)} ${p}`)}"><div class="k-heatmap__months" aria-hidden="true">${b.map(e=>`<span style="grid-column: ${e.col+1}">${e.name}</span>`).join(``)}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${f.weekdays.map(e=>`<span>${e}</span>`).join(``)}</div><div class="k-heatmap__grid">${`<span class="k-heatmap__cell" data-empty=""></span>`.repeat(v)}${h.map((e,t)=>`<span class="k-heatmap__cell" data-l="${_(e.value)}" data-i="${t}"></span>`).join(``)}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${l(f.total(m(x),p,C))}</span><span class="k-heatmap__scale" aria-hidden="true">${l(f.less)} ${[0,1,2,3,4].map(e=>`<span class="k-heatmap__cell" data-l="${e}"></span>`).join(``)} ${l(f.more)}</span></figcaption><table class="k-sr-only"><caption>${l(f.byMonth(w))}</caption><tbody>${S.map(e=>`<tr><th scope="row">${e.name}</th><td>${m(e.sum)}</td></tr>`).join(``)}</tbody></table></figure>`;let T=this.querySelector(`figure`);this.querySelector(`.k-heatmap__grid`).addEventListener(`pointerover`,e=>{let n=e.target.closest(`[data-i]`);if(T.querySelector(`.k-heatmap__cell[data-active]`)?.removeAttribute(`data-active`),!n)return this.tip(T,null);n.setAttribute(`data-active`,``);let r=this.at(n,T),i=h[Number(n.dataset.i)];this.tip(T,r.x,r.y-2,t(i.date,{style:`full`,digits:o(),locale:a()}),[{value:`${m(i.value)} ${p}`}])}),T.addEventListener(`pointerleave`,()=>this.tip(T,null))}};O.observedAttributes=[`data`,`year`,`unit`,`label`],u(`kashi-bar-chart`,S,`block`),u(`kashi-line-chart`,D,`block`),u(`kashi-pie-chart`,T,`block`),u(`kashi-bar-list`,C,`block`),u(`kashi-proportion-bar`,w,`block`),u(`kashi-sparkline`,E),u(`kashi-activity-heatmap`,O,`block`);export{O as KashiActivityHeatmap,S as KashiBarChart,C as KashiBarList,D as KashiLineChart,T as KashiPieChart,w as KashiProportionBar,E as KashiSparkline};
1
+ import{A as e,C as t,O as n,T as r,a as i,d as a,f as o,j as s,k as c,l,o as u,p as d,t as f,y as p}from"./base-BqFAMlwG.js";const m=e=>s(e,{digits:o()}),h=e=>m(Math.round(e*10)/10).replace(`.`,d().common.decimal),g=e=>{let t=Math.abs(e),n=d().chart;return t>=1e9?h(e/1e9)+n.billion:t>=1e6?h(e/1e6)+n.million:t>=1e3?h(e/1e3)+n.thousand:m(e)};function _(e,t=4){if(e<=0)return[0];let n=e/t,r=10**Math.floor(Math.log10(n)),i=[1,2,2.5,5,10].map(e=>e*r).find(e=>e>=n);return Array.from({length:Math.ceil(e/i)+1},(e,t)=>t*i)}const v=(e,t)=>d().common.percent(h(e/(t||1)*100)),y=e=>e<8?`var(--k-chart-${e+1})`:`var(--k-text-quaternary)`,b=(e,t)=>{if(!e)return t;try{return JSON.parse(e)}catch{return t}};var x=class extends f{constructor(){super(...arguments),this.key=p(`kashi-chart`),this.props={}}connectedCallback(){this.draw()}attributeChangedCallback(){this.isConnected&&this.draw()}get format(){let e=this.getAttribute(`unit`);return this.fmt??(t=>`${m(Math.round(t))}${e?` ${e}`:``}`)}set format(e){this.fmt=e,this.isConnected&&this.draw()}read(e,t){return this.props[e]??b(this.getAttribute(e),t)}write(e,t){this.props[e]=t,this.isConnected&&this.draw()}get heading(){return this.getAttribute(`label`)??``}tip(e,t,n=0,r,i=[]){let a=e.querySelector(`:scope > .k-chart__tip`);if(t===null){a?.remove();return}a||(a=document.createElement(`div`),a.className=`k-chart__tip`,a.setAttribute(`aria-hidden`,`true`),e.append(a));let o=e.clientWidth;a.style.left=`${o?Math.min(Math.max(t,80),o-80):t}px`,a.style.top=`${n}px`,a.innerHTML=`${r?`<span class="k-chart__tip-title">${l(r)}</span>`:``}${i.map(e=>`<span class="k-chart__tip-row"${e.color?` style="--_c: ${e.color}"`:``}>${e.name===void 0?``:`<span>${e.color?`<i></i>`:``}${l(e.name)}</span>`}<strong>${l(e.value)}</strong></span>`).join(``)}`}at(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return{x:r.left+r.width/2-n.left,y:r.top-n.top}}},S=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}draw(){let e=this.format,t=this.series.length?this.series.slice(0,4):null,n=this.data,r=t?this.labels:n.map(e=>e.label),i=r.map((e,r)=>t?t.reduce((e,t)=>e+(t.values[r]??0),0):n[r].value),a=Math.max(0,...i),o=_(a),s=o.at(-1)||1,c=i.indexOf(a),u=this.getAttribute(`label-max`)!==`false`,f=n=>t?`${r[n]}: ${t.map(t=>`${t.name} ${e(t.values[n]??0)}`).join(d().common.list)}${d().common.list}${d().common.total} ${e(i[n])}`:`${r[n]}: ${e(i[n])}`,p=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart k-chart--bar" aria-labelledby="${this.key}-t" style="margin: 0${p?`; --k-chart-height: ${l(p)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p>${t&&t.length>1?`<ul class="k-chart__legend" aria-hidden="true">${t.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key k-chart__key--box"></span>${l(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot"><div class="k-bars__grid" aria-hidden="true">${o.map(e=>`<span data-v="${l(g(e))}"></span>`).join(``)}</div><div class="k-bars" role="list" aria-label="${l(this.heading)}">${r.map((n,r)=>`<div class="k-bars__col" role="listitem" tabindex="0" data-i="${r}" aria-label="${l(f(r))}" style="--_d: ${r*40}ms">${u&&r===c?`<span class="k-bars__value" aria-hidden="true">${l(e(i[r]))}</span>`:``}${t?`<span class="k-bars__stack" style="block-size: ${i[r]/s*100}%" aria-hidden="true">${t.map((e,t)=>`<span class="k-bars__seg" style="--_c: ${y(t)}; flex-grow: ${e.values[r]??0}"></span>`).join(``)}</span>`:`<span class="k-bars__bar" style="block-size: ${i[r]/s*100}%" aria-hidden="true"></span>`}<span class="k-bars__label" aria-hidden="true">${l(n)}</span></div>`).join(``)}</div></div></figure>`;let m=this.querySelector(`.k-chart__plot`),h=n=>{let a=Number(n.dataset.i);m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-bars__bar, .k-bars__stack`)??n,m);this.tip(m,o.x,o.y,r[a],t?[...t.map((t,n)=>({name:t.name,value:e(t.values[a]??0),color:y(n)})),{name:d().common.total,value:e(i[a])}]:[{value:e(i[a])}])},v=()=>{m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),this.tip(m,null)};m.querySelectorAll(`.k-bars__col`).forEach(e=>{e.addEventListener(`pointerenter`,()=>h(e)),e.addEventListener(`focus`,()=>h(e)),e.addEventListener(`pointerleave`,v),e.addEventListener(`blur`,v)})}};S.observedAttributes=[`label`,`data`,`labels`,`series`,`unit`,`label-max`,`height`];var C=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data,n=Math.max(1,...t.map(e=>e.value)),r=t.reduce((e,t)=>e+t.value,0);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><ol class="k-barlist" style="position: relative">${t.map((t,i)=>`<li class="k-barlist__row" data-i="${i}" style="--_d: ${i*60}ms"><span class="k-barlist__track"><span class="k-barlist__fill" style="inline-size: ${t.value/n*100}%" aria-hidden="true"></span>${t.href?`<a class="k-barlist__label" href="${l(t.href)}">${l(t.label)}</a>`:`<span class="k-barlist__label">${l(t.label)}</span>`}</span><span class="k-barlist__value">${l(e(t.value))} <span class="k-barlist__share">${v(t.value,r)}</span></span></li>`).join(``)}</ol></figure>`;let i=this.querySelector(`.k-barlist`);i.querySelectorAll(`.k-barlist__row`).forEach(n=>{n.addEventListener(`pointerenter`,()=>{let a=t[Number(n.dataset.i)];n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-barlist__fill`),i);this.tip(i,o.x,o.y,a.label,[{name:d().chart.value,value:e(a.value)},{name:d().chart.share,value:v(a.value,r)}])}),n.addEventListener(`pointerleave`,()=>{n.removeAttribute(`data-active`),this.tip(i,null)})})}};C.observedAttributes=[`label`,`data`,`unit`];var w=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data.slice(0,4),n=t.reduce((e,t)=>e+t.value,0),r=this.getAttribute(`percent`)!==`false`;this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><div class="k-proportion__wrap"><div class="k-proportion" aria-hidden="true">${t.map((e,t)=>`<span class="k-proportion__seg" data-i="${t}" style="--_c: ${y(t)}; flex-grow: ${e.value}"></span>`).join(``)}</div></div><ul class="k-proportion__legend">${t.map((t,i)=>`<li data-i="${i}" style="--_c: ${y(i)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span>${l(t.label)}</span><strong>${l(r?v(t.value,n):e(t.value))}</strong>${r?`<span class="k-proportion__abs">${l(e(t.value))}</span>`:``}</li>`).join(``)}</ul></figure>`;let i=this.querySelector(`.k-proportion__wrap`),a=e=>this.querySelectorAll(`[data-i]`).forEach(t=>t.toggleAttribute(`data-active`,Number(t.dataset.i)===e));i.querySelectorAll(`.k-proportion__seg`).forEach(r=>{r.addEventListener(`pointerenter`,()=>{let o=Number(r.dataset.i);a(o);let s=this.at(r,i);this.tip(i,s.x,s.y,void 0,[{name:t[o].label,value:v(t[o].value,n),color:y(o)},{name:d().chart.count,value:e(t[o].value)}])}),r.addEventListener(`pointerleave`,()=>{a(null),this.tip(i,null)})})}};w.observedAttributes=[`label`,`data`,`unit`,`percent`];var T=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=[...this.data].sort((e,t)=>t.value-e.value),n=t.length>5?[...t.slice(0,4),{label:d().common.other,value:t.slice(4).reduce((e,t)=>e+t.value,0)}]:t,r=n.reduce((e,t)=>e+t.value,0)||1,i=e=>e<4?y(e):`var(--k-text-quaternary)`,a=this.getAttribute(`variant`)!==`pie`,o=Number(this.getAttribute(`size`))||176,s=this.getAttribute(`total-label`)??d().common.total,c=a?40:25,u=a?16:50,f=2*Math.PI*c,p=n.length>1?a?1.6:.8:0,m=0,h=n.map(e=>{let t=e.value/r*f,n={start:m,len:t};return m+=t,n});this.innerHTML=`<figure class="k-chart k-pie" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p></figcaption><div class="k-pie__body"><div class="k-pie__plot" style="inline-size: ${o}px; block-size: ${o}px"><svg viewBox="0 0 100 100" class="k-pie__svg" aria-hidden="true">${a?`<circle cx="50" cy="50" r="${c}" fill="none" stroke="var(--k-bg-tertiary)" stroke-width="${u}"></circle>`:``}${n.map((e,t)=>`<circle class="k-pie__slice" data-i="${t}" cx="50" cy="50" r="${c}" fill="none" stroke="${i(t)}" stroke-width="${u}" stroke-dasharray="${Math.max(0,h[t].len-p)} ${f}" stroke-dashoffset="${-h[t].start}" transform="rotate(-90 50 50)" style="--_d: ${t*80}ms"></circle>`).join(``)}</svg>${a?`<div class="k-pie__center" aria-hidden="true"><strong>${l(e(r))}</strong><span>${l(s)}</span></div>`:``}</div><ul class="k-pie__legend">${n.map((t,n)=>`<li data-i="${n}" style="--_c: ${i(n)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span class="k-pie__name">${l(t.label)}</span><strong>${v(t.value,r)}</strong><span class="k-pie__abs">${l(e(t.value))}</span></li>`).join(``)}</ul></div></figure>`;let g=this.querySelector(`.k-pie__plot`),_=this.querySelector(`.k-pie__center`),b=e=>{let t=(h[e].start+h[e].len/2)/f*2*Math.PI-Math.PI/2,n=a?c:c*1.3;return{x:(50+n*Math.cos(t))/100*o,y:(50+n*Math.sin(t))/100*o-8}},x=t=>{this.querySelectorAll(`[data-i]`).forEach(e=>e.toggleAttribute(`data-active`,Number(e.dataset.i)===t)),_&&(_.innerHTML=t===null?`<strong>${l(e(r))}</strong><span>${l(s)}</span>`:`<strong>${v(n[t].value,r)}</strong><span>${l(n[t].label)}</span>`),a||(t===null?this.tip(g,null):this.tip(g,b(t).x,b(t).y,void 0,[{name:n[t].label,value:v(n[t].value,r),color:i(t)},{name:d().chart.count,value:e(n[t].value)}]))};this.querySelectorAll(`.k-pie__slice, .k-pie__legend li`).forEach(e=>e.addEventListener(`pointerenter`,()=>x(Number(e.dataset.i)))),g.addEventListener(`pointerleave`,()=>x(null)),this.querySelector(`.k-pie__legend`).addEventListener(`pointerleave`,()=>x(null))}};T.observedAttributes=[`label`,`data`,`unit`,`variant`,`total-label`,`size`];var E=class extends x{get values(){return this.props.values??(this.getAttribute(`values`)??``).split(/[,،\s]+/).filter(Boolean).map(Number).filter(e=>!Number.isNaN(e))}set values(e){this.write(`values`,e)}draw(){let e=this.values;if(!e.length){this.innerHTML=``;return}let t=Math.max(...e),n=Math.min(...e),r=Math.max(t-n,Math.abs(t)*.25)||1,i=(t+n)/2-r/2,a=e.map((t,n)=>`${n?`L`:`M`}${n/Math.max(1,e.length-1)*100},${28-(t-i)/r*24}`).join(` `),o=this.getAttribute(`tone`)??`brand`,s=o===`neutral`?`var(--k-text-tertiary)`:o===`brand`?`var(--k-text-brand)`:`var(--k-text-${o})`,c=this.getAttribute(`label`);this.innerHTML=`<svg class="k-sparkline" viewBox="0 0 100 30" preserveAspectRatio="none"${c?` role="img" aria-label="${l(c)}"`:` aria-hidden="true"`} style="color: ${s}">${this.getAttribute(`area`)===`false`?``:`<path d="${a} L100,30 L0,30 Z" fill="currentColor" opacity="0.1"></path>`}<path d="${a}" fill="none" stroke="currentColor" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round" stroke-linecap="round"></path></svg>`}};E.observedAttributes=[`values`,`tone`,`area`,`label`];var D=class extends x{constructor(){super(...arguments),this.ro=null,this.active=null}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}connectedCallback(){if(super.connectedCallback(),typeof ResizeObserver<`u`&&!this.ro){let e=0;this.ro=new ResizeObserver(()=>{let t=this.clientWidth;t&&t!==e&&(e=t,this.paintSvg())}),this.ro.observe(this)}}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}draw(){let e=this.series.slice(0,4),t=this.format,n=this.labels,r=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0${r?`; --k-chart-height: ${l(r)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${l(this.heading)}</p>${e.length>1?`<ul class="k-chart__legend" aria-hidden="true">${e.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key"></span>${l(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot" tabindex="0" role="img" aria-label="${l(d().chart.keyboard(this.heading))}" aria-describedby="${this.key}-live"><svg class="k-chart__svg" aria-hidden="true" direction="ltr"></svg></div><span class="k-sr-only" aria-live="polite" id="${this.key}-live"></span><table class="k-sr-only"><caption>${l(this.heading)}</caption><thead><tr><th scope="col">${l(d().chart.period)}</th>${e.map(e=>`<th scope="col">${l(e.name)}</th>`).join(``)}</tr></thead><tbody>${n.map((n,r)=>`<tr><th scope="row">${l(n)}</th>${e.map(e=>`<td>${l(t(e.values[r]))}</td>`).join(``)}</tr>`).join(``)}</tbody></table></figure>`;let i=this.querySelector(`.k-chart__plot`);i.addEventListener(`pointermove`,e=>this.pick(e.clientX)),i.addEventListener(`pointerleave`,()=>this.setActive(null)),i.addEventListener(`blur`,()=>this.setActive(null)),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,r=n.length,a={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];a?(e.preventDefault(),this.setActive(Math.min(r-1,Math.max(0,(this.active??(a>0?-1:r))+a)))):e.key===`Home`?this.setActive(0):e.key===`End`?this.setActive(r-1):e.key===`Escape`&&this.setActive(null)}),this.active=null,this.paintSvg()}geometry(){let e=this.querySelector(`.k-chart__plot`),t=this.series.slice(0,4),n=this.labels,r=e.clientWidth||600,i=e.clientHeight||220,a=getComputedStyle(e).direction===`rtl`,o={top:12,bottom:24,start:52,end:t.length>1?64:16},s=_(Math.max(0,...t.flatMap(e=>e.values))),c=s.at(-1)||1,l=Math.max(1,r-o.start-o.end),u=Math.max(1,i-o.top-o.bottom);return{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:u,x:e=>{let t=n.length>1?e/(n.length-1):.5;return a?r-o.start-t*l:o.start+t*l},y:e=>o.top+u-e/c*u}}paintSvg(){if(!this.querySelector(`.k-chart__plot`))return;let{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:c,innerH:u,x:f,y:p}=this.geometry(),m=e.querySelector(`svg`),h=a?r-o.start+8:o.start-8,_=a?`start`:`end`,v=n.length-1,b=t.map((e,t)=>({i:t,y:p(e.values[v])})).sort((e,t)=>e.y-t.y);for(let e=1;e<b.length;e++)b[e].y-b[e-1].y<14&&(b[e].y=b[e-1].y+14);let x=Object.fromEntries(b.map(e=>[e.i,e.y])),S=Math.max(1,Math.ceil(n.length/Math.max(2,Math.floor(c/64)))),C=`${this.key}-fade`,w=this.active;m.innerHTML=`<g class="k-chart__grid">${s.map(e=>`<line x1="${o.start}" x2="${r-o.end}" y1="${p(e)}" y2="${p(e)}"${a?` transform="translate(${o.end-o.start} 0)"`:``}></line>`).join(``)}</g>${s.map(e=>`<text class="k-chart__tick" x="${h}" y="${p(e)+4}" text-anchor="${_}">${l(g(e))}</text>`).join(``)}${n.map((e,t)=>t%S===0||t===v?`<text class="k-chart__tick" x="${f(t)}" y="${i-6}" text-anchor="middle">${l(e)}</text>`:``).join(``)}<defs><linearGradient id="${C}" x1="0" y1="0" x2="0" y2="1"><stop offset="0" style="stop-color: var(--k-chart-1); stop-opacity: 0.28"></stop><stop offset="1" style="stop-color: var(--k-chart-1); stop-opacity: 0"></stop></linearGradient></defs>${t.length===1&&this.getAttribute(`area`)!==`false`?`<path class="k-chart__area" fill="url(#${C})" d="M${f(0)},${p(0)} ${t[0].values.map((e,t)=>`L${f(t)},${p(e)}`).join(` `)} L${f(v)},${p(0)} Z"></path>`:``}${w===null?``:`<line class="k-chart__cross" x1="${f(w)}" x2="${f(w)}" y1="${o.top}" y2="${o.top+u}"></line>`}${t.map((e,n)=>`<g style="--_c: ${y(n)}"><path class="k-chart__line" pathLength="1" d="${e.values.map((e,t)=>`${t?`L`:`M`}${f(t)},${p(e)}`).join(` `)}"></path><circle class="k-chart__dot" cx="${f(e.values.length-1)}" cy="${p(e.values.at(-1)??0)}" r="4"></circle>${t.length>1?`<text class="k-chart__end" x="${f(v)+(a?-8:8)}" y="${x[n]+4}" text-anchor="${a?`end`:`start`}">${l(e.name)}</text>`:``}${w===null?``:`<circle class="k-chart__dot" cx="${f(w)}" cy="${p(e.values[w])}" r="4.5"></circle>`}</g>`).join(``)}`;let T=this.format;w===null?this.tip(e,null):this.tip(e,f(w),Math.min(...t.map(e=>p(e.values[w])))-6,n[w],t.map((e,t)=>({name:e.name,value:T(e.values[w]),color:y(t)}))),this.querySelector(`#${this.key}-live`).textContent=w===null?``:`${n[w]}: ${t.map(e=>`${e.name} ${T(e.values[w])}`).join(d().common.list)}`}pick(e){let{plot:t,labels:n,x:r}=this.geometry(),i=e-t.getBoundingClientRect().left,a=0;n.forEach((e,t)=>{Math.abs(r(t)-i)<Math.abs(r(a)-i)&&(a=t)}),a!==this.active&&this.setActive(a)}setActive(e){this.active=e,this.paintSvg()}};D.observedAttributes=[`label`,`labels`,`series`,`unit`,`area`,`height`];var O=class extends x{get data(){return this.read(`data`,{})}set data(e){this.write(`data`,e)}draw(){let s=this.data,u=Number(this.getAttribute(`year`))||e(/* @__PURE__ */ new Date).jy,f=d().heatmap,p=this.getAttribute(`unit`)??f.unit,h=[];for(let e=1;e<=12;e++)for(let t=1;t<=r(u,e);t++){let r=n(u,e,t);h.push({date:r,value:s[c(r)]??0})}let g=Math.max(0,...h.map(e=>e.value)),_=e=>e<=0||g===0?0:Math.max(1,Math.ceil(e/g*4)),v=(h[0].date.getDay()+1)%7,y=e=>Math.floor((e+v)/7),b=i().months.map((t,n)=>({name:t,col:y(h.findIndex(t=>e(t.date).jm===n+1))})),x=h.reduce((e,t)=>e+t.value,0),S=i().months.map((t,n)=>({name:t,sum:h.filter(t=>e(t.date).jm===n+1).reduce((e,t)=>e+t.value,0)})),C=m(u).replace(/[٬,]/g,``),w=this.getAttribute(`label`)??f.inYear(p,C);this.innerHTML=`<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll" tabindex="0" role="region" aria-label="${l(w)}"><div role="img" aria-label="${l(`${w}: ${m(x)} ${p}`)}"><div class="k-heatmap__months" aria-hidden="true">${b.map(e=>`<span style="grid-column: ${e.col+1}">${e.name}</span>`).join(``)}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${f.weekdays.map(e=>`<span>${e}</span>`).join(``)}</div><div class="k-heatmap__grid">${`<span class="k-heatmap__cell" data-empty=""></span>`.repeat(v)}${h.map((e,t)=>`<span class="k-heatmap__cell" data-l="${_(e.value)}" data-i="${t}"></span>`).join(``)}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${l(f.total(m(x),p,C))}</span><span class="k-heatmap__scale" aria-hidden="true">${l(f.less)} ${[0,1,2,3,4].map(e=>`<span class="k-heatmap__cell" data-l="${e}"></span>`).join(``)} ${l(f.more)}</span></figcaption><table class="k-sr-only"><caption>${l(f.byMonth(w))}</caption><tbody>${S.map(e=>`<tr><th scope="row">${e.name}</th><td>${m(e.sum)}</td></tr>`).join(``)}</tbody></table></figure>`;let T=this.querySelector(`figure`);this.querySelector(`.k-heatmap__grid`).addEventListener(`pointerover`,e=>{let n=e.target.closest(`[data-i]`);if(T.querySelector(`.k-heatmap__cell[data-active]`)?.removeAttribute(`data-active`),!n)return this.tip(T,null);n.setAttribute(`data-active`,``);let r=this.at(n,T),i=h[Number(n.dataset.i)];this.tip(T,r.x,r.y-2,t(i.date,{style:`full`,digits:o(),locale:a()}),[{value:`${m(i.value)} ${p}`}])}),T.addEventListener(`pointerleave`,()=>this.tip(T,null))}};O.observedAttributes=[`data`,`year`,`unit`,`label`],u(`kashi-bar-chart`,S,`block`),u(`kashi-line-chart`,D,`block`),u(`kashi-pie-chart`,T,`block`),u(`kashi-bar-list`,C,`block`),u(`kashi-proportion-bar`,w,`block`),u(`kashi-sparkline`,E),u(`kashi-activity-heatmap`,O,`block`);export{O as KashiActivityHeatmap,S as KashiBarChart,C as KashiBarList,D as KashiLineChart,T as KashiPieChart,w as KashiProportionBar,E as KashiSparkline};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./relative-OC1fV3Xh.js";import{c as t,d as n,f as r,i,l as a,m as o,o as s,p as c,r as l,s as u,t as d,y as f}from"./base-D4tCOysh.js";import{d as p,f as m,m as h,p as g,r as _,s as v,u as y}from"./parts-5fVaWtRe.js";const b=v(`<path d="M10 4v12m0 0-4.5-4.5M10 16l4.5-4.5"/>`,1.9);var x=class extends d{constructor(){super(...arguments),this.scroller=null,this.stick=!0,this.mo=null,this.ro=null}connectedCallback(){l(()=>{this.isConnected&&(this.scroller||this.build(),this.update(),this.observe(),this.toEnd())})}disconnectedCallback(){this.mo?.disconnect(),this.ro?.disconnect(),this.mo=this.ro=null}attributeChangedCallback(){this.scroller&&this.update()}get thread(){return this.scroller}scrollToEnd(e=!0){this.stick=!0,this.scroller?.scrollTo({top:this.scroller.scrollHeight,behavior:e?`smooth`:`auto`})}build(){let e=document.createElement(`div`);e.className=`k-chat`,e.innerHTML=`<div class="k-chat__scroll" role="log" aria-live="polite" tabindex="0"></div><button type="button" class="k-chat__jump" tabindex="-1" aria-hidden="true">${b}</button>`,this.scroller=e.querySelector(`.k-chat__scroll`),this.jump=e.querySelector(`.k-chat__jump`),this.scroller.append(...this.childNodes),this.append(e),this.scroller.addEventListener(`scroll`,()=>{let e=this.scroller,t=e.scrollHeight-e.scrollTop-e.clientHeight<48;this.stick=t,this.jump.toggleAttribute(`data-show`,!t),this.jump.tabIndex=t?-1:0,this.jump.setAttribute(`aria-hidden`,String(t))}),this.jump.addEventListener(`click`,()=>this.scrollToEnd())}observe(){this.mo||typeof MutationObserver>`u`||(this.mo=new MutationObserver(()=>{let e=[...this.childNodes].filter(e=>e!==this.scroller?.parentElement);e.length&&this.scroller.append(...e),this.toEnd()}),this.mo.observe(this,{childList:!0,subtree:!0,characterData:!0}),typeof ResizeObserver<`u`&&(this.ro=new ResizeObserver(()=>this.toEnd()),this.ro.observe(this.scroller)))}toEnd(){i(this,`auto-scroll`,!0)&&this.stick&&this.scroller&&(this.scroller.scrollTop=this.scroller.scrollHeight)}update(){let e=c();this.scroller.setAttribute(`aria-label`,this.getAttribute(`label`)??e.chat.thread),this.jump.setAttribute(`aria-label`,e.chat.scrollDown)}};x.observedAttributes=[`label`,`auto-scroll`];const S=(e,t=1.7)=>v(e,t),C={sending:S(`<circle cx="10" cy="10" r="6.5"/><path d="M10 6.5V10l2 1.5"/>`),failed:S(`<circle cx="10" cy="10" r="7"/><path d="M10 6.5v4M10 13.5h.01"/>`),sent:S(`<path d="m4.5 10.5 3 3 6-7"/>`,1.9),delivered:S(`<path d="m2.5 10.5 3 3 6-7"/><path d="m9 13.2.3.3 6-7"/>`,1.9),read:S(`<path d="m2.5 10.5 3 3 6-7"/><path d="m9 13.2.3.3 6-7"/>`,1.9)},w=S(`<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/>`),T=S(`<path d="m5 10.5 3.2 3L15 7"/>`,2),E=S(`<path d="M4 10a6 6 0 1 0 1.8-4.3"/><path d="M4 3.5V7h3.5"/>`),D=S(`<path d="M6.5 9 9.5 3.5a1.6 1.6 0 0 1 2.9 1.2L11.5 8h3.8a1.5 1.5 0 0 1 1.5 1.8l-1.2 5.5a1.5 1.5 0 0 1-1.5 1.2H6.5M6.5 9v7.5M6.5 9H4v7.5h2.5"/>`),O=S(`<path d="M13.5 11 10.5 16.5a1.6 1.6 0 0 1-2.9-1.2L8.5 12H4.7a1.5 1.5 0 0 1-1.5-1.8l1.2-5.5A1.5 1.5 0 0 1 5.9 3.5h7.6M13.5 11V3.5m0 7.5H16V3.5h-2.5"/>`),k=/^\d{4}-\d{2}-\d{2}T/;var A=class extends d{constructor(){super(...arguments),this.box=null,this.avatar=[],this.extra=[]}connectedCallback(){l(()=>{this.isConnected&&(this.box||this.build(),this.update())})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){this.box&&t!==n&&this.update()}build(){this.avatar=m(this,`avatar`),this.extra=m(this,`actions`),this.box=document.createElement(`div`),this.bubble=document.createElement(`div`),this.bubble.className=`k-msg__bubble`,this.bubble.dir=`auto`,this.bubble.append(...h(this)),this.replaceChildren(this.box),this.box.addEventListener(`click`,e=>this.onClick(e))}async onClick(e){let n=e.target.closest(`[data-act]`);if(!n)return;let r=n.dataset.act;if(r===`copy`){if(!await _(this.getAttribute(`copy-text`)??this.bubble.innerText??this.bubble.textContent??``))return;let e=c().chat;n.setAttribute(`data-done`,``),n.innerHTML=T,n.setAttribute(`aria-label`,e.copied),this.box.querySelector(`.k-msg__actions > .k-sr-only`).textContent=e.copied,clearTimeout(this.timer),this.timer=setTimeout(()=>this.update(),2e3),t(this,`kashi-copy`,{})}else if(r===`retry`)t(this,`kashi-retry`,{});else if(r===`up`||r===`down`){let e=this.getAttribute(`rated`)===r?null:r;e?this.setAttribute(`rated`,e):this.removeAttribute(`rated`),t(this,`kashi-feedback`,{value:e})}}update(){let t=c().chat,r=this.box,o=this.getAttribute(`from`)??`assistant`;if(o===`system`){r.className=`k-chat__system`,r.removeAttribute(`data-from`),r.replaceChildren(...this.bubble.childNodes.length?[...this.bubble.childNodes]:[]);return}r.className===`k-chat__system`&&this.bubble.append(...r.childNodes),r.className=`k-msg`,r.dataset.from=o;let s=this.getAttribute(`status`);s?r.dataset.status=s:delete r.dataset.status;let l=this.getAttribute(`name`),d=l??(o===`user`?t.you:t.assistant),f=this.getAttribute(`time`),p=f&&k.test(f)?g(f):null,m=p?e(p,{locale:n(),digits:u(this)}):f,h=i(this,`edited`),_=this.getAttribute(`rated`),v=i(this,`copyable`)||this.hasAttribute(`copy-text`),y=v||i(this,`retry`)||i(this,`feedback`)||this.extra.length,b=document.createElement(`div`);if(b.className=`k-msg__main`,b.innerHTML=`${l?`<div class="k-msg__name">${a(l)}</div>`:`<span class="k-sr-only">${a(d)}: </span>`}`,b.append(this.bubble),(m||s||h)&&b.insertAdjacentHTML(`beforeend`,`<div class="k-msg__meta">${h?`<span>${a(t.edited)}</span>`:``}${m?`<time${p?` datetime="${p.toISOString()}"`:``}>${a(m)}</time>`:``}${s?`<span class="k-msg__status" data-status="${a(s)}" role="img" aria-label="${a(t[s]??s)}">${C[s]??``}</span>`:``}</div>`),y){let e=document.createElement(`div`);e.className=`k-msg__actions`,e.setAttribute(`role`,`group`),e.setAttribute(`aria-label`,t.actions),e.innerHTML=`${v?`<button type="button" class="k-msg__action" data-act="copy" aria-label="${a(t.copy)}">${w}</button>`:``}${i(this,`retry`)?`<button type="button" class="k-msg__action" data-act="retry" aria-label="${a(t.retry)}">${E}</button>`:``}${i(this,`feedback`)?`<button type="button" class="k-msg__action" data-act="up" aria-label="${a(t.like)}" aria-pressed="${_===`up`}">${D}</button><button type="button" class="k-msg__action" data-act="down" aria-label="${a(t.dislike)}" aria-pressed="${_===`down`}">${O}</button>`:``}`,e.append(...this.extra),e.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" aria-live="polite"></span>`),b.append(e)}let x=r.contains(document.activeElement)?document.activeElement.dataset.act:void 0;if(r.replaceChildren(),this.avatar.length){let e=document.createElement(`div`);e.className=`k-msg__avatar`,e.append(...this.avatar),r.append(e)}r.append(b),x&&r.querySelector(`[data-act="${x}"]`)?.focus()}};A.observedAttributes=[`from`,`name`,`time`,`status`,`edited`,`copyable`,`copy-text`,`retry`,`feedback`,`rated`];var j=class extends d{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=this.getAttribute(`name`),t=e?c().chat.typing(e):c().chat.typingShort;this.innerHTML=`<div class="k-typing" role="status"><span class="k-typing__dots" aria-hidden="true"><i></i><i></i><i></i></span>${i(this,`show-label`)?`<span class="k-typing__label">${a(t)}…</span>`:`<span class="k-sr-only">${a(t)}</span>`}</div>`}};j.observedAttributes=[`name`,`show-label`];const M=v(`<path d="m15.5 9.5-5.6 5.6a3.5 3.5 0 0 1-5-5l6-6a2.3 2.3 0 0 1 3.3 3.3l-6 6a1.2 1.2 0 0 1-1.7-1.7l5.5-5.5"/>`,1.8),N=v(`<path d="M10 16V4m0 0L5 9m5-5 5 5"/>`,1.8),P=v(`<path d="M6 6l8 8M14 6l-8 8"/>`,1.8),F=v(`<path d="M11.5 3H6a1.5 1.5 0 0 0-1.5 1.5v11A1.5 1.5 0 0 0 6 17h8a1.5 1.5 0 0 0 1.5-1.5V7z"/><path d="M11.5 3v4h4"/>`,1.8);function I(e){let t=c().fileUpload.units,n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;let a=i===0?String(n):n.toFixed(+(n<10)).replace(/\.0$/,``);return`${r()===`fa`?a.replace(/\d/g,e=>`۰۱۲۳۴۵۶۷۸۹`[+e]).replace(`.`,`٫`):a} ${t[i]}`}var L=class extends d{constructor(){super(...arguments),this.box=null,this.files=[],this.urls=[],this.error=``,this.key=f(`kashi-composer`),this.initial=null}connectedCallback(){l(()=>{this.isConnected&&(this.box||this.build(),this.update())})}disconnectedCallback(){for(let e of this.urls)e&&URL.revokeObjectURL(e)}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?this.value=n??``:this.update())}get value(){return this.box?this.area.value:this.initial??this.getAttribute(`value`)??``}set value(e){this.initial=String(e??``),this.box&&(this.area.value=this.initial,this.paint())}get attachments(){return[...this.files]}focus(e){this.area?.focus(e)}build(){let e=m(this,`tools`),n=document.createElement(`div`);n.innerHTML=`<ul class="k-composer__files" hidden></ul><textarea class="k-composer__input" rows="1" dir="auto"></textarea><div class="k-composer__bar"><button type="button" class="k-composer__tool" data-act="attach">${M}</button><input type="file" hidden><span class="k-composer__count" hidden></span><button type="button" class="k-composer__send" data-act="send"></button></div><p class="k-hint k-hint--error k-composer__error" id="${this.key}-err" role="alert" hidden></p><p class="k-composer__hint" id="${this.key}-hint" hidden></p>`,this.area=n.querySelector(`textarea`),this.picker=n.querySelector(`input[type=file]`),this.area.value=this.initial??this.getAttribute(`value`)??``,n.querySelector(`.k-composer__count`).before(...e),this.replaceChildren(n),this.box=n,this.area.addEventListener(`input`,()=>{this.paint(),t(this,`kashi-change`,{value:this.area.value})}),this.area.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&e.keyCode!==229&&(e.preventDefault(),this.send())}),this.area.addEventListener(`paste`,e=>{if(!this.hasAttribute(`attach`))return;let t=[...e.clipboardData?.files??[]];t.length&&(e.preventDefault(),this.add(t))}),this.picker.addEventListener(`change`,()=>{this.add([...this.picker.files??[]]),this.picker.value=``}),n.addEventListener(`click`,e=>{let n=e.target.closest(`button`);if(n){if(n.dataset.act===`attach`)this.picker.click();else if(n.dataset.act===`send`)this.send();else if(n.dataset.act===`stop`)t(this,`kashi-stop`,{});else if(n.dataset.remove!==void 0){let e=Number(n.dataset.remove);this.files.splice(e,1),this.renderFiles(),this.area.focus()}}})}add(e){let t=c().composer,n=y(this,`max-size`),r=y(this,`max-files`,5);this.error=``;let i=[];for(let r of e)n&&r.size>n?this.error=t.tooLarge(r.name,I(n)):i.push(r);let a=[...this.files,...i];a.length>r&&(this.error=t.tooMany(o(this,r))),this.files=a.slice(0,r),this.renderFiles()}renderFiles(){let e=c().composer;for(let e of this.urls)e&&URL.revokeObjectURL(e);this.urls=this.files.map(e=>e.type.startsWith(`image/`)&&typeof URL.createObjectURL==`function`?URL.createObjectURL(e):``);let t=this.box.querySelector(`.k-composer__files`);t.hidden=!this.files.length,t.setAttribute(`aria-label`,e.attachments),t.innerHTML=this.files.map((t,n)=>`<li class="k-composer__file">${this.urls[n]?`<img src="${a(this.urls[n])}" alt="" class="k-composer__thumb">`:`<span class="k-composer__thumb">${F}</span>`}<span class="k-composer__file-text"><span class="k-composer__file-name" dir="auto">${a(t.name)}</span><span class="k-composer__file-size">${a(I(t.size))}</span></span><button type="button" class="k-composer__remove" data-remove="${n}" aria-label="${a(e.removeAttachment(t.name))}">${P}</button></li>`).join(``),this.paint()}canSend(){let e=this.area.value,t=y(this,`max-length`);return!i(this,`disabled`)&&!i(this,`streaming`)&&(e.trim().length>0||this.files.length>0)&&(!t||e.length<=t)}send(){this.canSend()&&(t(this,`kashi-send`,{text:this.area.value.trim(),files:[...this.files]}),this.area.value=``,this.files=[],this.error=``,this.renderFiles(),t(this,`kashi-change`,{value:``}),this.area.focus())}update(){let e=c().composer,t=this.box,n=i(this,`disabled`);t.className=`k-composer`,t.toggleAttribute(`data-disabled`,n),this.area.disabled=n,this.area.placeholder=this.getAttribute(`placeholder`)??e.placeholder,this.area.setAttribute(`aria-label`,this.getAttribute(`label`)??e.label);let r=this.getAttribute(`attach`),a=t.querySelector(`[data-act=attach]`);a.hidden=r===null||r===`false`,a.setAttribute(`aria-label`,e.attach),this.picker.multiple=y(this,`max-files`,5)>1,r&&r!==`true`&&r!==`false`?this.picker.accept=r:this.picker.removeAttribute(`accept`);let o=t.querySelector(`.k-composer__hint`);o.textContent=e.hint,o.hidden=!i(this,`show-hint`),this.paint()}paint(){let e=c().composer,t=this.box,n=this.area;n.style.blockSize=`auto`;let r=parseFloat(getComputedStyle(n).lineHeight)||24;n.scrollHeight&&(n.style.blockSize=`${Math.min(n.scrollHeight,r*y(this,`max-rows`,8)+2)}px`);let a=y(this,`max-length`),s=n.value.length,l=t.querySelector(`.k-composer__count`);l.hidden=!(a&&s>a*.8),l.textContent=a?`${o(this,s)}/${o(this,a)}`:``,l.toggleAttribute(`data-over`,!!a&&s>a),a&&s>a?n.setAttribute(`aria-invalid`,`true`):n.removeAttribute(`aria-invalid`);let u=t.querySelector(`.k-composer__error`);u.textContent=this.error,u.hidden=!this.error,t.toggleAttribute(`data-invalid`,!!this.error);let d=[i(this,`show-hint`)?`${this.key}-hint`:``,this.error?`${this.key}-err`:``].filter(Boolean).join(` `);d?n.setAttribute(`aria-describedby`,d):n.removeAttribute(`aria-describedby`),t.querySelector(`[data-act=attach]`).disabled=i(this,`disabled`)||this.files.length>=y(this,`max-files`,5);let f=t.querySelector(`.k-composer__send`),p=i(this,`streaming`),m=document.activeElement===f;f.dataset.act=p?`stop`:`send`,f.toggleAttribute(`data-stop`,p),f.setAttribute(`aria-label`,p?e.stop:e.send),f.innerHTML=p?`<svg viewBox="0 0 20 20" aria-hidden="true"><rect x="6" y="6" width="8" height="8" rx="1.5" fill="currentColor"/></svg>`:N,f.disabled=!p&&!this.canSend(),m&&!f.disabled&&f.focus()}};L.observedAttributes=[`placeholder`,`label`,`streaming`,`attach`,`max-files`,`max-size`,`max-length`,`max-rows`,`show-hint`,`disabled`,`value`];const R=e=>e.match(/\S+\s*|\s+/g)??[];var z=class extends d{constructor(){super(...arguments),this.full=``,this.shown=0,this.seen=0,this.root=null,this.typing=!1,this.textSet=!1}connectedCallback(){l(()=>{if(this.isConnected){if(!this.root){this.textSet||(this.full=this.getAttribute(`text`)??this.textContent?.trim()??``),this.root=document.createElement(`p`),this.root.className=`k-stream`,this.root.dir=`auto`,this.replaceChildren(this.root);let e=R(this.full).length;this.shown=this.animated?0:e,this.seen=this.shown}this.tick()}})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){t!==n&&(e===`text`&&(this.full=n??``,this.textSet=!0),this.root&&this.tick())}get text(){return this.full}set text(e){this.full=String(e??``),this.textSet=!0,this.root&&this.tick()}appendText(e){this.text=this.full+e}get animated(){return y(this,`speed`,0)>0&&!p()}tick(){clearTimeout(this.timer);let e=R(this.full);this.animated?this.shown<e.length&&(this.timer=setTimeout(()=>{this.shown++,this.tick()},1e3/y(this,`speed`,1))):this.shown=e.length,this.paint(e)}paint(e){let n=this.root,r=Math.min(this.shown,e.length),a=i(this,`streaming`)||this.animated&&r<e.length,o=Math.min(this.seen,r);n.textContent=e.slice(0,o).join(``);for(let t of e.slice(o,r)){let e=document.createElement(`span`);e.className=`k-stream__word`,e.textContent=t,n.append(e)}this.seen=r,i(this,`cursor`,!0)&&a&&n.insertAdjacentHTML(`beforeend`,`<span class="k-stream__cursor" aria-hidden="true"></span>`),n.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" aria-live="polite"></span>`),a?n.setAttribute(`aria-busy`,`true`):n.removeAttribute(`aria-busy`),n.toggleAttribute(`data-streaming`,a),this.typing&&!a&&(n.querySelector(`.k-sr-only`).textContent=c().streaming.done,t(this,`kashi-done`,{})),this.typing=a}};z.observedAttributes=[`text`,`streaming`,`speed`,`cursor`];const B=new Set(`import export from default const let var function return if else for while do switch case break continue new class extends async await try catch finally throw typeof instanceof in of interface type enum implements public private protected static readonly def lambda pass elif with as yield None True False self print fn pub use mod impl struct match mut package func go defer select true false null undefined void this super echo SELECT FROM WHERE INSERT INTO VALUES UPDATE SET DELETE JOIN ON AND OR NOT ORDER BY GROUP LIMIT`.split(` `)),V=/(\/\/[^\n]*|#(?![{\[])[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)|("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|(\b\d[\d_.]*(?:e[+-]?\d+)?\b)|([A-Za-z_$][\w$]*)/g;function H(e,t=``){let n=[],r=/^(py|python|sh|bash|shell|zsh|yaml|yml|toml|rb|ruby|r)$/i.test(t),i=0;for(let t of e.matchAll(V)){let[a,o,s,c,l]=t,u=t.index??0;o&&o.startsWith(`#`)&&!r||(u>i&&n.push([``,e.slice(i,u)]),n.push([o?`comment`:s?`string`:c?`number`:l&&B.has(l)?`keyword`:l&&e[u+a.length]===`(`?`fn`:``,a]),i=u+a.length)}return i<e.length&&n.push([``,e.slice(i)]),n}const U=e=>{let t=/* @__PURE__ */ new Set;for(let n of(e??``).split(/[\s,]+/)){let[e,r]=n.split(`-`).map(Number);if(e)for(let n=e;n<=(r||e);n++)t.add(n)}return t},W=v(`<path d="M3 5h14M3 10h11a3 3 0 0 1 0 6h-3m0 0 2-2m-2 2 2 2M3 15h4"/>`);var G=class extends d{constructor(){super(...arguments),this.source=null,this.fig=null,this.wrapped=!1}connectedCallback(){l(()=>{if(this.isConnected){if(!this.fig){if(this.source===null&&!this.hasAttribute(`code`)){let e=this.querySelector(`template`);this.source=(e?e.innerHTML:this.querySelector(`pre, code`)?.textContent??this.textContent??``).replace(/^\n/,``);let t=this.source.split(`
1
+ import{t as e}from"./relative-BoBZPiB7.js";import{c as t,d as n,f as r,i,l as a,m as o,o as s,p as c,r as l,s as u,t as d,y as f}from"./base-BqFAMlwG.js";import{d as p,f as m,m as h,p as g,r as _,s as v,u as y}from"./parts-5fVaWtRe.js";const b=v(`<path d="M10 4v12m0 0-4.5-4.5M10 16l4.5-4.5"/>`,1.9);var x=class extends d{constructor(){super(...arguments),this.scroller=null,this.stick=!0,this.mo=null,this.ro=null}connectedCallback(){l(()=>{this.isConnected&&(this.scroller||this.build(),this.update(),this.observe(),this.toEnd())})}disconnectedCallback(){this.mo?.disconnect(),this.ro?.disconnect(),this.mo=this.ro=null}attributeChangedCallback(){this.scroller&&this.update()}get thread(){return this.scroller}scrollToEnd(e=!0){this.stick=!0,this.scroller?.scrollTo({top:this.scroller.scrollHeight,behavior:e?`smooth`:`auto`})}build(){let e=document.createElement(`div`);e.className=`k-chat`,e.innerHTML=`<div class="k-chat__scroll" role="log" aria-live="polite" tabindex="0"></div><button type="button" class="k-chat__jump" tabindex="-1" aria-hidden="true">${b}</button>`,this.scroller=e.querySelector(`.k-chat__scroll`),this.jump=e.querySelector(`.k-chat__jump`),this.scroller.append(...this.childNodes),this.append(e),this.scroller.addEventListener(`scroll`,()=>{let e=this.scroller,t=e.scrollHeight-e.scrollTop-e.clientHeight<48;this.stick=t,this.jump.toggleAttribute(`data-show`,!t),this.jump.tabIndex=t?-1:0,this.jump.setAttribute(`aria-hidden`,String(t))}),this.jump.addEventListener(`click`,()=>this.scrollToEnd())}observe(){this.mo||typeof MutationObserver>`u`||(this.mo=new MutationObserver(()=>{let e=[...this.childNodes].filter(e=>e!==this.scroller?.parentElement);e.length&&this.scroller.append(...e),this.toEnd()}),this.mo.observe(this,{childList:!0,subtree:!0,characterData:!0}),typeof ResizeObserver<`u`&&(this.ro=new ResizeObserver(()=>this.toEnd()),this.ro.observe(this.scroller)))}toEnd(){i(this,`auto-scroll`,!0)&&this.stick&&this.scroller&&(this.scroller.scrollTop=this.scroller.scrollHeight)}update(){let e=c();this.scroller.setAttribute(`aria-label`,this.getAttribute(`label`)??e.chat.thread),this.jump.setAttribute(`aria-label`,e.chat.scrollDown)}};x.observedAttributes=[`label`,`auto-scroll`];const S=(e,t=1.7)=>v(e,t),C={sending:S(`<circle cx="10" cy="10" r="6.5"/><path d="M10 6.5V10l2 1.5"/>`),failed:S(`<circle cx="10" cy="10" r="7"/><path d="M10 6.5v4M10 13.5h.01"/>`),sent:S(`<path d="m4.5 10.5 3 3 6-7"/>`,1.9),delivered:S(`<path d="m2.5 10.5 3 3 6-7"/><path d="m9 13.2.3.3 6-7"/>`,1.9),read:S(`<path d="m2.5 10.5 3 3 6-7"/><path d="m9 13.2.3.3 6-7"/>`,1.9)},w=S(`<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/>`),T=S(`<path d="m5 10.5 3.2 3L15 7"/>`,2),E=S(`<path d="M4 10a6 6 0 1 0 1.8-4.3"/><path d="M4 3.5V7h3.5"/>`),D=S(`<path d="M6.5 9 9.5 3.5a1.6 1.6 0 0 1 2.9 1.2L11.5 8h3.8a1.5 1.5 0 0 1 1.5 1.8l-1.2 5.5a1.5 1.5 0 0 1-1.5 1.2H6.5M6.5 9v7.5M6.5 9H4v7.5h2.5"/>`),O=S(`<path d="M13.5 11 10.5 16.5a1.6 1.6 0 0 1-2.9-1.2L8.5 12H4.7a1.5 1.5 0 0 1-1.5-1.8l1.2-5.5A1.5 1.5 0 0 1 5.9 3.5h7.6M13.5 11V3.5m0 7.5H16V3.5h-2.5"/>`),k=/^\d{4}-\d{2}-\d{2}T/;var A=class extends d{constructor(){super(...arguments),this.box=null,this.avatar=[],this.extra=[]}connectedCallback(){l(()=>{this.isConnected&&(this.box||this.build(),this.update())})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){this.box&&t!==n&&this.update()}build(){this.avatar=m(this,`avatar`),this.extra=m(this,`actions`),this.box=document.createElement(`div`),this.bubble=document.createElement(`div`),this.bubble.className=`k-msg__bubble`,this.bubble.dir=`auto`,this.bubble.append(...h(this)),this.replaceChildren(this.box),this.box.addEventListener(`click`,e=>this.onClick(e))}async onClick(e){let n=e.target.closest(`[data-act]`);if(!n)return;let r=n.dataset.act;if(r===`copy`){if(!await _(this.getAttribute(`copy-text`)??this.bubble.innerText??this.bubble.textContent??``))return;let e=c().chat;n.setAttribute(`data-done`,``),n.innerHTML=T,n.setAttribute(`aria-label`,e.copied),this.box.querySelector(`.k-msg__actions > .k-sr-only`).textContent=e.copied,clearTimeout(this.timer),this.timer=setTimeout(()=>this.update(),2e3),t(this,`kashi-copy`,{})}else if(r===`retry`)t(this,`kashi-retry`,{});else if(r===`up`||r===`down`){let e=this.getAttribute(`rated`)===r?null:r;e?this.setAttribute(`rated`,e):this.removeAttribute(`rated`),t(this,`kashi-feedback`,{value:e})}}update(){let t=c().chat,r=this.box,o=this.getAttribute(`from`)??`assistant`;if(o===`system`){r.className=`k-chat__system`,r.removeAttribute(`data-from`),r.replaceChildren(...this.bubble.childNodes.length?[...this.bubble.childNodes]:[]);return}r.className===`k-chat__system`&&this.bubble.append(...r.childNodes),r.className=`k-msg`,r.dataset.from=o;let s=this.getAttribute(`status`);s?r.dataset.status=s:delete r.dataset.status;let l=this.getAttribute(`name`),d=l??(o===`user`?t.you:t.assistant),f=this.getAttribute(`time`),p=f&&k.test(f)?g(f):null,m=p?e(p,{locale:n(),digits:u(this)}):f,h=i(this,`edited`),_=this.getAttribute(`rated`),v=i(this,`copyable`)||this.hasAttribute(`copy-text`),y=v||i(this,`retry`)||i(this,`feedback`)||this.extra.length,b=document.createElement(`div`);if(b.className=`k-msg__main`,b.innerHTML=`${l?`<div class="k-msg__name">${a(l)}</div>`:`<span class="k-sr-only">${a(d)}: </span>`}`,b.append(this.bubble),(m||s||h)&&b.insertAdjacentHTML(`beforeend`,`<div class="k-msg__meta">${h?`<span>${a(t.edited)}</span>`:``}${m?`<time${p?` datetime="${p.toISOString()}"`:``}>${a(m)}</time>`:``}${s?`<span class="k-msg__status" data-status="${a(s)}" role="img" aria-label="${a(t[s]??s)}">${C[s]??``}</span>`:``}</div>`),y){let e=document.createElement(`div`);e.className=`k-msg__actions`,e.setAttribute(`role`,`group`),e.setAttribute(`aria-label`,t.actions),e.innerHTML=`${v?`<button type="button" class="k-msg__action" data-act="copy" aria-label="${a(t.copy)}">${w}</button>`:``}${i(this,`retry`)?`<button type="button" class="k-msg__action" data-act="retry" aria-label="${a(t.retry)}">${E}</button>`:``}${i(this,`feedback`)?`<button type="button" class="k-msg__action" data-act="up" aria-label="${a(t.like)}" aria-pressed="${_===`up`}">${D}</button><button type="button" class="k-msg__action" data-act="down" aria-label="${a(t.dislike)}" aria-pressed="${_===`down`}">${O}</button>`:``}`,e.append(...this.extra),e.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" aria-live="polite"></span>`),b.append(e)}let x=r.contains(document.activeElement)?document.activeElement.dataset.act:void 0;if(r.replaceChildren(),this.avatar.length){let e=document.createElement(`div`);e.className=`k-msg__avatar`,e.append(...this.avatar),r.append(e)}r.append(b),x&&r.querySelector(`[data-act="${x}"]`)?.focus()}};A.observedAttributes=[`from`,`name`,`time`,`status`,`edited`,`copyable`,`copy-text`,`retry`,`feedback`,`rated`];var j=class extends d{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=this.getAttribute(`name`),t=e?c().chat.typing(e):c().chat.typingShort;this.innerHTML=`<div class="k-typing" role="status"><span class="k-typing__dots" aria-hidden="true"><i></i><i></i><i></i></span>${i(this,`show-label`)?`<span class="k-typing__label">${a(t)}…</span>`:`<span class="k-sr-only">${a(t)}</span>`}</div>`}};j.observedAttributes=[`name`,`show-label`];const M=v(`<path d="m15.5 9.5-5.6 5.6a3.5 3.5 0 0 1-5-5l6-6a2.3 2.3 0 0 1 3.3 3.3l-6 6a1.2 1.2 0 0 1-1.7-1.7l5.5-5.5"/>`,1.8),N=v(`<path d="M10 16V4m0 0L5 9m5-5 5 5"/>`,1.8),P=v(`<path d="M6 6l8 8M14 6l-8 8"/>`,1.8),F=v(`<path d="M11.5 3H6a1.5 1.5 0 0 0-1.5 1.5v11A1.5 1.5 0 0 0 6 17h8a1.5 1.5 0 0 0 1.5-1.5V7z"/><path d="M11.5 3v4h4"/>`,1.8);function I(e){let t=c().fileUpload.units,n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;let a=i===0?String(n):n.toFixed(+(n<10)).replace(/\.0$/,``);return`${r()===`fa`?a.replace(/\d/g,e=>`۰۱۲۳۴۵۶۷۸۹`[+e]).replace(`.`,`٫`):a} ${t[i]}`}var L=class extends d{constructor(){super(...arguments),this.box=null,this.files=[],this.urls=[],this.error=``,this.key=f(`kashi-composer`),this.initial=null}connectedCallback(){l(()=>{this.isConnected&&(this.box||this.build(),this.update())})}disconnectedCallback(){for(let e of this.urls)e&&URL.revokeObjectURL(e)}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?this.value=n??``:this.update())}get value(){return this.box?this.area.value:this.initial??this.getAttribute(`value`)??``}set value(e){this.initial=String(e??``),this.box&&(this.area.value=this.initial,this.paint())}get attachments(){return[...this.files]}focus(e){this.area?.focus(e)}build(){let e=m(this,`tools`),n=document.createElement(`div`);n.innerHTML=`<ul class="k-composer__files" hidden></ul><textarea class="k-composer__input" rows="1" dir="auto"></textarea><div class="k-composer__bar"><button type="button" class="k-composer__tool" data-act="attach">${M}</button><input type="file" hidden><span class="k-composer__count" hidden></span><button type="button" class="k-composer__send" data-act="send"></button></div><p class="k-hint k-hint--error k-composer__error" id="${this.key}-err" role="alert" hidden></p><p class="k-composer__hint" id="${this.key}-hint" hidden></p>`,this.area=n.querySelector(`textarea`),this.picker=n.querySelector(`input[type=file]`),this.area.value=this.initial??this.getAttribute(`value`)??``,n.querySelector(`.k-composer__count`).before(...e),this.replaceChildren(n),this.box=n,this.area.addEventListener(`input`,()=>{this.paint(),t(this,`kashi-change`,{value:this.area.value})}),this.area.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&e.keyCode!==229&&(e.preventDefault(),this.send())}),this.area.addEventListener(`paste`,e=>{if(!this.hasAttribute(`attach`))return;let t=[...e.clipboardData?.files??[]];t.length&&(e.preventDefault(),this.add(t))}),this.picker.addEventListener(`change`,()=>{this.add([...this.picker.files??[]]),this.picker.value=``}),n.addEventListener(`click`,e=>{let n=e.target.closest(`button`);if(n){if(n.dataset.act===`attach`)this.picker.click();else if(n.dataset.act===`send`)this.send();else if(n.dataset.act===`stop`)t(this,`kashi-stop`,{});else if(n.dataset.remove!==void 0){let e=Number(n.dataset.remove);this.files.splice(e,1),this.renderFiles(),this.area.focus()}}})}add(e){let t=c().composer,n=y(this,`max-size`),r=y(this,`max-files`,5);this.error=``;let i=[];for(let r of e)n&&r.size>n?this.error=t.tooLarge(r.name,I(n)):i.push(r);let a=[...this.files,...i];a.length>r&&(this.error=t.tooMany(o(this,r))),this.files=a.slice(0,r),this.renderFiles()}renderFiles(){let e=c().composer;for(let e of this.urls)e&&URL.revokeObjectURL(e);this.urls=this.files.map(e=>e.type.startsWith(`image/`)&&typeof URL.createObjectURL==`function`?URL.createObjectURL(e):``);let t=this.box.querySelector(`.k-composer__files`);t.hidden=!this.files.length,t.setAttribute(`aria-label`,e.attachments),t.innerHTML=this.files.map((t,n)=>`<li class="k-composer__file">${this.urls[n]?`<img src="${a(this.urls[n])}" alt="" class="k-composer__thumb">`:`<span class="k-composer__thumb">${F}</span>`}<span class="k-composer__file-text"><span class="k-composer__file-name" dir="auto">${a(t.name)}</span><span class="k-composer__file-size">${a(I(t.size))}</span></span><button type="button" class="k-composer__remove" data-remove="${n}" aria-label="${a(e.removeAttachment(t.name))}">${P}</button></li>`).join(``),this.paint()}canSend(){let e=this.area.value,t=y(this,`max-length`);return!i(this,`disabled`)&&!i(this,`streaming`)&&(e.trim().length>0||this.files.length>0)&&(!t||e.length<=t)}send(){this.canSend()&&(t(this,`kashi-send`,{text:this.area.value.trim(),files:[...this.files]}),this.area.value=``,this.files=[],this.error=``,this.renderFiles(),t(this,`kashi-change`,{value:``}),this.area.focus())}update(){let e=c().composer,t=this.box,n=i(this,`disabled`);t.className=`k-composer`,t.toggleAttribute(`data-disabled`,n),this.area.disabled=n,this.area.placeholder=this.getAttribute(`placeholder`)??e.placeholder,this.area.setAttribute(`aria-label`,this.getAttribute(`label`)??e.label);let r=this.getAttribute(`attach`),a=t.querySelector(`[data-act=attach]`);a.hidden=r===null||r===`false`,a.setAttribute(`aria-label`,e.attach),this.picker.multiple=y(this,`max-files`,5)>1,r&&r!==`true`&&r!==`false`?this.picker.accept=r:this.picker.removeAttribute(`accept`);let o=t.querySelector(`.k-composer__hint`);o.textContent=e.hint,o.hidden=!i(this,`show-hint`),this.paint()}paint(){let e=c().composer,t=this.box,n=this.area;n.style.blockSize=`auto`;let r=parseFloat(getComputedStyle(n).lineHeight)||24;n.scrollHeight&&(n.style.blockSize=`${Math.min(n.scrollHeight,r*y(this,`max-rows`,8)+2)}px`);let a=y(this,`max-length`),s=n.value.length,l=t.querySelector(`.k-composer__count`);l.hidden=!(a&&s>a*.8),l.textContent=a?`${o(this,s)}/${o(this,a)}`:``,l.toggleAttribute(`data-over`,!!a&&s>a),a&&s>a?n.setAttribute(`aria-invalid`,`true`):n.removeAttribute(`aria-invalid`);let u=t.querySelector(`.k-composer__error`);u.textContent=this.error,u.hidden=!this.error,t.toggleAttribute(`data-invalid`,!!this.error);let d=[i(this,`show-hint`)?`${this.key}-hint`:``,this.error?`${this.key}-err`:``].filter(Boolean).join(` `);d?n.setAttribute(`aria-describedby`,d):n.removeAttribute(`aria-describedby`),t.querySelector(`[data-act=attach]`).disabled=i(this,`disabled`)||this.files.length>=y(this,`max-files`,5);let f=t.querySelector(`.k-composer__send`),p=i(this,`streaming`),m=document.activeElement===f;f.dataset.act=p?`stop`:`send`,f.toggleAttribute(`data-stop`,p),f.setAttribute(`aria-label`,p?e.stop:e.send),f.innerHTML=p?`<svg viewBox="0 0 20 20" aria-hidden="true"><rect x="6" y="6" width="8" height="8" rx="1.5" fill="currentColor"/></svg>`:N,f.disabled=!p&&!this.canSend(),m&&!f.disabled&&f.focus()}};L.observedAttributes=[`placeholder`,`label`,`streaming`,`attach`,`max-files`,`max-size`,`max-length`,`max-rows`,`show-hint`,`disabled`,`value`];const R=e=>e.match(/\S+\s*|\s+/g)??[];var z=class extends d{constructor(){super(...arguments),this.full=``,this.shown=0,this.seen=0,this.root=null,this.typing=!1,this.textSet=!1}connectedCallback(){l(()=>{if(this.isConnected){if(!this.root){this.textSet||(this.full=this.getAttribute(`text`)??this.textContent?.trim()??``),this.root=document.createElement(`p`),this.root.className=`k-stream`,this.root.dir=`auto`,this.replaceChildren(this.root);let e=R(this.full).length;this.shown=this.animated?0:e,this.seen=this.shown}this.tick()}})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){t!==n&&(e===`text`&&(this.full=n??``,this.textSet=!0),this.root&&this.tick())}get text(){return this.full}set text(e){this.full=String(e??``),this.textSet=!0,this.root&&this.tick()}appendText(e){this.text=this.full+e}get animated(){return y(this,`speed`,0)>0&&!p()}tick(){clearTimeout(this.timer);let e=R(this.full);this.animated?this.shown<e.length&&(this.timer=setTimeout(()=>{this.shown++,this.tick()},1e3/y(this,`speed`,1))):this.shown=e.length,this.paint(e)}paint(e){let n=this.root,r=Math.min(this.shown,e.length),a=i(this,`streaming`)||this.animated&&r<e.length,o=Math.min(this.seen,r);n.textContent=e.slice(0,o).join(``);for(let t of e.slice(o,r)){let e=document.createElement(`span`);e.className=`k-stream__word`,e.textContent=t,n.append(e)}this.seen=r,i(this,`cursor`,!0)&&a&&n.insertAdjacentHTML(`beforeend`,`<span class="k-stream__cursor" aria-hidden="true"></span>`),n.insertAdjacentHTML(`beforeend`,`<span class="k-sr-only" aria-live="polite"></span>`),a?n.setAttribute(`aria-busy`,`true`):n.removeAttribute(`aria-busy`),n.toggleAttribute(`data-streaming`,a),this.typing&&!a&&(n.querySelector(`.k-sr-only`).textContent=c().streaming.done,t(this,`kashi-done`,{})),this.typing=a}};z.observedAttributes=[`text`,`streaming`,`speed`,`cursor`];const B=new Set(`import export from default const let var function return if else for while do switch case break continue new class extends async await try catch finally throw typeof instanceof in of interface type enum implements public private protected static readonly def lambda pass elif with as yield None True False self print fn pub use mod impl struct match mut package func go defer select true false null undefined void this super echo SELECT FROM WHERE INSERT INTO VALUES UPDATE SET DELETE JOIN ON AND OR NOT ORDER BY GROUP LIMIT`.split(` `)),V=/(\/\/[^\n]*|#(?![{\[])[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)|("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|(\b\d[\d_.]*(?:e[+-]?\d+)?\b)|([A-Za-z_$][\w$]*)/g;function H(e,t=``){let n=[],r=/^(py|python|sh|bash|shell|zsh|yaml|yml|toml|rb|ruby|r)$/i.test(t),i=0;for(let t of e.matchAll(V)){let[a,o,s,c,l]=t,u=t.index??0;o&&o.startsWith(`#`)&&!r||(u>i&&n.push([``,e.slice(i,u)]),n.push([o?`comment`:s?`string`:c?`number`:l&&B.has(l)?`keyword`:l&&e[u+a.length]===`(`?`fn`:``,a]),i=u+a.length)}return i<e.length&&n.push([``,e.slice(i)]),n}const U=e=>{let t=/* @__PURE__ */ new Set;for(let n of(e??``).split(/[\s,]+/)){let[e,r]=n.split(`-`).map(Number);if(e)for(let n=e;n<=(r||e);n++)t.add(n)}return t},W=v(`<path d="M3 5h14M3 10h11a3 3 0 0 1 0 6h-3m0 0 2-2m-2 2 2 2M3 15h4"/>`);var G=class extends d{constructor(){super(...arguments),this.source=null,this.fig=null,this.wrapped=!1}connectedCallback(){l(()=>{if(this.isConnected){if(!this.fig){if(this.source===null&&!this.hasAttribute(`code`)){let e=this.querySelector(`template`);this.source=(e?e.innerHTML:this.querySelector(`pre, code`)?.textContent??this.textContent??``).replace(/^\n/,``);let t=this.source.split(`
2
2
  `),n=Math.min(...t.filter(e=>e.trim()).map(e=>e.match(/^\s*/)[0].length));n>0&&Number.isFinite(n)&&(this.source=t.map(e=>e.slice(n)).join(`
3
3
  `)),e&&(this.source=this.source.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&amp;/g,`&`))}this.wrapped=i(this,`wrap`),this.fig=document.createElement(`figure`),this.replaceChildren(this.fig),this.fig.addEventListener(`click`,e=>this.onClick(e))}this.render()}})}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(e,t,n){t!==n&&(e===`wrap`&&(this.wrapped=n!==null&&n!==`false`),this.fig&&this.render())}get code(){return(this.getAttribute(`code`)??this.source??``).replace(/\n$/,``)}set code(e){this.source=String(e??``),this.removeAttribute(`code`),this.fig&&this.render()}async onClick(e){let n=e.target.closest(`button`);if(!n)return;let r=c().codeBlock;n.dataset.act===`wrap`?(this.wrapped=!this.wrapped,this.fig.toggleAttribute(`data-wrap`,this.wrapped),n.setAttribute(`aria-pressed`,String(this.wrapped))):n.dataset.act===`copy`&&await _(this.code)&&(n.setAttribute(`data-done`,``),n.innerHTML=`${T}<span>${a(r.copied)}</span>`,this.fig.querySelector(`.k-code__tools > .k-sr-only`).textContent=r.copied,clearTimeout(this.timer),this.timer=setTimeout(()=>{n.removeAttribute(`data-done`),n.innerHTML=`${w}<span>${a(r.copy)}</span>`,this.fig.querySelector(`.k-code__tools > .k-sr-only`).textContent=``},2e3),t(this,`kashi-copy`,{value:this.code}))}render(){let e=c().codeBlock,t=this.code,n=this.getAttribute(`language`)??``,r=this.getAttribute(`filename`)??n,s=i(this,`line-numbers`),l=U(this.getAttribute(`highlight-lines`)),u=this.getAttribute(`highlight`)===`false`?[[``,t]]:H(t,n),d=[``];for(let[e,t]of u)t.split(`
4
4
  `).forEach((t,n)=>{n&&d.push(``),t&&(d[d.length-1]+=e?`<span class="k-code__t-${e}">${a(t)}</span>`:a(t))});let f=this.getAttribute(`max-height`),p=this.fig;p.className=`k-code`,p.toggleAttribute(`data-wrap`,this.wrapped),p.innerHTML=`<figcaption class="k-code__head"><span class="k-code__lang" dir="ltr">${a(r||e.lines(o(this,d.length)))}</span><span class="k-code__tools"><button type="button" class="k-code__btn" data-act="wrap" aria-label="${a(e.wrap)}" aria-pressed="${this.wrapped}">${W}</button><button type="button" class="k-code__btn" data-act="copy">${w}<span>${a(e.copy)}</span></button><span class="k-sr-only" aria-live="polite"></span></span></figcaption><pre class="k-code__pre" dir="ltr" tabindex="0"${n?` aria-label="${a(e.code(n))}"`:``}${f?` style="max-block-size: ${a(f)}"`:``}><code>${d.map((e,t)=>`<span class="k-code__line"${l.has(t+1)?` data-marked`:``}>${s?`<span class="k-code__num" aria-hidden="true">${t+1}</span>`:``}<span class="k-code__text">${e||` `}</span></span>`).join(``)}</code></pre>`}};G.observedAttributes=[`code`,`language`,`filename`,`line-numbers`,`highlight-lines`,`wrap`,`highlight`,`max-height`],s(`kashi-chat`,x,`block`),s(`kashi-chat-message`,A,`contents`),s(`kashi-typing-indicator`,j,`contents`),s(`kashi-chat-composer`,L,`block`),s(`kashi-streaming-text`,z,`block`),s(`kashi-code-block`,G,`block`);export{x as KashiChat,L as KashiChatComposer,A as KashiChatMessage,G as KashiCodeBlock,z as KashiStreamingText,j as KashiTypingIndicator,I as formatBytes};
@@ -1 +1 @@
1
- import{n as e}from"./text-C6fzEBBh.js";import{_ as t,c as n,i as r,l as i,o as a,p as o,r as s,t as c,u as l,y as u}from"./base-D4tCOysh.js";import{i as d}from"./parts-5fVaWtRe.js";const f=[`name`,`value`,`form`,`aria-label`,`aria-describedby`];var p=class extends c{constructor(){super(...arguments),this.input=null,this.wrap=null,this.initial=null,this.key=u(`kashi-check`)}connectedCallback(){this.input||this.build(),this.update()}attributeChangedCallback(e,t,n){this.input&&t!==n&&(e===`checked`?this.input.checked=n!==null&&n!==`false`:this.update())}get checked(){return this.input?this.input.checked:this.initial??r(this,`checked`)}set checked(e){this.initial=!!e,this.input&&(this.input.checked=!!e)}focus(e){this.input?.focus(e)}build(){let e=document.createElement(`input`);e.type=`checkbox`,e.id=this.key,this.kind===`switch`&&e.setAttribute(`role`,`switch`),e.checked=this.initial??r(this,`checked`),e.addEventListener(`click`,e=>{r(this,`readonly`)&&e.preventDefault()}),e.addEventListener(`change`,()=>{this.removeAttribute(`data-indeterminate`),n(this,`kashi-change`,{checked:e.checked,value:e.value})}),this.input=e,this.extra()}extra(){}update(){let e=this.input,t=this.getAttribute(`label`),n=this.getAttribute(`description`),i=this.getAttribute(`size`)??`md`;e.className=this.kind===`switch`?d(`k-switch`,i!==`md`&&`k-switch--${i}`):d(`k-checkbox`,i===`lg`&&`k-checkbox--lg`),e.disabled=r(this,`disabled`),e.required=r(this,`required`);for(let t of f){let n=this.getAttribute(t);n===null?e.removeAttribute(t):e.setAttribute(t,n)}if(r(this,`invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`),r(this,`readonly`)?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`),n&&e.setAttribute(`aria-describedby`,`${this.key}-desc`),!t&&!n){this.wrap?.remove(),this.wrap=null,e.parentElement!==this&&this.prepend(e);return}this.wrap||(this.wrap=document.createElement(`label`),this.wrap.htmlFor=this.key,this.wrap.innerHTML=`<span class="k-check__text"><span class="k-check__label"></span><span class="k-check__description"></span></span>`,this.wrap.prepend(e),this.prepend(this.wrap));let a=this.wrap;a.className=d(`k-check`,this.getAttribute(`label-position`)===`start`&&`k-check--start`),a.toggleAttribute(`data-readonly`,r(this,`readonly`));let o=a.querySelector(`.k-check__label`);o.textContent=t??``,o.hidden=!t;let s=a.querySelector(`.k-check__description`);s.id=`${this.key}-desc`,s.textContent=n??``,s.hidden=!n}};p.observedAttributes=[`label`,`description`,`checked`,`disabled`,`required`,`readonly`,`invalid`,`size`,`label-position`,...f];var m=class extends p{constructor(){super(...arguments),this.kind=`checkbox`}attributeChangedCallback(e,t,n){super.attributeChangedCallback(e,t,n),e===`indeterminate`&&this.input&&(this.input.indeterminate=n!==null&&n!==`false`)}extra(){this.input.indeterminate=r(this,`indeterminate`)}get indeterminate(){return this.input?.indeterminate??r(this,`indeterminate`)}set indeterminate(e){this.toggleAttribute(`indeterminate`,!!e)}};m.observedAttributes=[...p.observedAttributes,`indeterminate`];var h=class extends p{constructor(){super(...arguments),this.kind=`switch`}},g=class extends c{constructor(){super(...arguments),this.box=null,this.current=null,this.key=u(`kashi-radio`)}connectedCallback(){s(()=>{this.isConnected&&(this.box||this.build(),this.update())})}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?(this.current=n,this.paint()):this.update())}get value(){return this.current??``}set value(e){this.current=e,this.box&&this.paint()}focus(e){(this.box?.querySelector(`input:checked`)??this.box?.querySelector(`input:not(:disabled)`))?.focus(e)}build(){let e=[...this.querySelectorAll(`:scope > option`)];this.current===null&&(this.current=this.getAttribute(`value`)??e.find(e=>e.hasAttribute(`selected`))?.value??null);let t=document.createElement(`fieldset`);t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-labelledby`,`${this.key}-legend`),t.innerHTML=`<legend class="k-label" id="${this.key}-legend"></legend>`,e.forEach((e,n)=>{let r=`${this.key}-${n}`,a=e.dataset.description,o=e.dataset.badge,s=e.dataset.meta,c=i(e.textContent?.trim()??e.value);t.insertAdjacentHTML(`beforeend`,`<label class="k-check" for="${r}"><input type="radio" class="k-radio" id="${r}" value="${i(e.value)}"${e.disabled?` disabled data-off`:``}${a?` aria-describedby="${r}-desc"`:``}><span class="k-check__text">${o?`<span class="k-check__head"><span class="k-check__label">${c}</span><span class="k-badge k-badge--brand k-badge--sm">${i(o)}</span></span>`:`<span class="k-check__label">${c}</span>`}${a?`<span class="k-check__description" id="${r}-desc">${i(a)}</span>`:``}</span>${s?`<span class="k-check__meta">${i(s)}</span>`:``}</label>`)});for(let t of e)t.remove();t.addEventListener(`click`,e=>{r(this,`readonly`)&&e.target.closest(`input`)&&e.preventDefault()}),t.addEventListener(`change`,e=>{let t=e.target;if(r(this,`readonly`))return this.paint();this.current=t.value,n(this,`kashi-change`,{value:t.value})}),this.prepend(t),this.box=t}update(){let e=this.box,t=this.getAttribute(`variant`)??`list`,n=this.getAttribute(`error`),a=this.getAttribute(`hint`),o=r(this,`readonly`);e.className=d(`k-radio-group`,t!==`list`&&`k-radio-group--${t}`),e.disabled=r(this,`disabled`),e.toggleAttribute(`data-readonly`,o);for(let[t,i]of[[`aria-readonly`,o],[`aria-required`,r(this,`required`)],[`aria-invalid`,!!n]])i?e.setAttribute(t,`true`):e.removeAttribute(t);let s=e.querySelector(`legend`);s.innerHTML=`${i(this.getAttribute(`label`)??``)}${r(this,`required`)?`<span class="k-label__required" aria-hidden="true">*</span>`:``}`,e.querySelectorAll(`:scope > .k-hint`).forEach(e=>e.remove()),n&&e.insertAdjacentHTML(`beforeend`,`<p class="k-hint k-hint--error" id="${this.key}-error">${i(n)}</p>`),a&&e.insertAdjacentHTML(`beforeend`,`<p class="k-hint" id="${this.key}-hint">${i(a)}</p>`);let c=[n&&`${this.key}-error`,a&&`${this.key}-hint`].filter(Boolean).join(` `);c?e.setAttribute(`aria-describedby`,c):e.removeAttribute(`aria-describedby`);let l=this.getAttribute(`name`)??this.key;[...e.querySelectorAll(`input`)].forEach((e,t)=>{e.name=l,e.required=r(this,`required`)&&t===0,o?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`),n?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`)}),this.paint()}paint(){for(let e of this.box.querySelectorAll(`input`))e.checked=e.value===this.current}};g.observedAttributes=[`label`,`name`,`value`,`variant`,`hint`,`error`,`required`,`disabled`,`readonly`];const _=t=>e(t,{digits:`latin`}).replace(/‌/g,` `).toLowerCase();var v=class extends c{constructor(){super(...arguments),this.list=null,this.current=null,this.rendered=!1,this.key=u(`kashi-select`),this.isOpen=!1,this.active=-1,this.typed={text:``,at:0},this.trigger=null,this.listbox=null,this.place=()=>{let e=this.trigger,t=this.listbox;if(!e||!t)return;let n=e.getBoundingClientRect(),r=Math.min(288,t.scrollHeight+8),i=innerHeight-n.bottom,a=i<r&&n.top>i;t.classList.toggle(`k-select__list--up`,a),Object.assign(t.style,{position:`fixed`,insetBlock:`auto`,right:`auto`,left:`${n.left}px`,width:`${n.width}px`,top:a?`auto`:`${n.bottom+6}px`,bottom:a?`${innerHeight-n.top+6}px`:`auto`})},this.onOutside=e=>{let t=e.target;!this.listbox?.contains(t)&&!this.trigger?.contains(t)&&this.close(!1)}}connectedCallback(){s(()=>{this.isConnected&&(this.rendered||(this.list===null&&(this.list=this.readOptions()),this.current===null&&(this.current=this.getAttribute(`value`)??(this.hasAttribute(`placeholder`)?``:this.enabled()[0]?.value??``))),this.render())})}disconnectedCallback(){this.close(!1)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:e===`error`||e===`hint`||e===`placeholder`?this.sync():this.render())}get options(){return this.list??[]}set options(e){this.list=[...e??[]],this.rendered&&this.render()}get value(){return this.current??``}set value(e){this.current=String(e??``),this.rendered&&this.sync()}focus(e){(this.trigger??this.nativeEl)?.focus(e)}readOptions(){let e=[];for(let t of this.querySelectorAll(`:scope > option, :scope > optgroup > option`)){if(t.value===``&&!t.textContent?.trim())continue;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,disabled:t.disabled,group:n})}for(let e of[...this.querySelectorAll(`:scope > option, :scope > optgroup`)])e.remove();return e}enabled(){return this.options.filter(e=>!e.disabled)}render(){this.close(!1);let e=this.key,t=this.getAttribute(`label`),a=this.getAttribute(`aria-label`),o=this.getAttribute(`size`)??`md`,s=r(this,`required`),c=r(this,`disabled`),u=r(this,`readonly`),f=r(this,`native`),p=this.getAttribute(`placeholder`),m=this.options,h,g=m.map(e=>{let t=e.group===h?``:`${h===void 0?``:`</optgroup>`}${e.group===void 0?``:`<optgroup label="${i(e.group)}">`}`;return h=e.group,`${t}<option value="${i(e.value)}"${e.disabled?` disabled`:``}>${i(e.label)}</option>`}).join(``)+(h===void 0?``:`</optgroup>`),_=this.getAttribute(`name`)?` name="${i(this.getAttribute(`name`))}"`:``,v;if(f)v=`<div class="${d(`k-select`,o!==`md`&&`k-select--${o}`)}"><select id="${e}" class="k-select__control"${_}${s?` required`:``}${c?` disabled`:``}${!t&&a?` aria-label="${i(a)}"`:``}>${p===null?``:`<option value="" disabled>${i(p)}</option>`}${g}</select></div>`;else{let n=`${e}-list`;v=`<div class="${d(`k-select`,`k-select--custom`,o!==`md`&&`k-select--${o}`)}"${u?` data-readonly`:``}${r(this,`loading`)?` aria-busy="true"`:``}><button id="${e}" type="button" role="combobox" class="k-select__control" aria-haspopup="listbox" aria-expanded="false" aria-controls="${n}"${s?` aria-required="true"`:``}${u?` aria-readonly="true"`:``}${c?` disabled`:``}${!t&&a?` aria-label="${i(a)}"`:``}><span class="k-select__value"></span><svg class="k-select__chevron" viewBox="0 0 20 20" width="18" height="18" 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><ul id="${n}" role="listbox" aria-labelledby="${e}" class="k-listbox k-select__list" hidden tabindex="-1" popover="manual"></ul><select class="k-select__native" tabindex="-1" aria-hidden="true"${_}${s?` required`:``}${c?` disabled`:``}><option value=""></option>${m.map(e=>`<option value="${i(e.value)}"${e.disabled?` disabled`:``}>${i(e.label)}</option>`).join(``)}</select></div>`}if(this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,l({id:e,label:t,required:s,control:v})),this.nativeEl=this.querySelector(f?`select.k-select__control`:`select.k-select__native`),this.trigger=f?null:this.querySelector(`button.k-select__control`),this.listbox=f?null:this.querySelector(`.k-select__list`),this.nativeEl.addEventListener(`change`,()=>{this.current=this.nativeEl.value,this.sync(),n(this,`kashi-change`,{value:this.current})}),this.trigger){let e=this.trigger;this.nativeEl.addEventListener(`focus`,()=>e.focus()),this.nativeEl.addEventListener(`invalid`,()=>e.focus()),e.addEventListener(`click`,()=>this.isOpen?this.close():this.open()),e.addEventListener(`keydown`,e=>this.onKey(e)),e.addEventListener(`blur`,e=>{this.listbox?.contains(e.relatedTarget)||this.close(!1)});let t=this.listbox;t.addEventListener(`mousedown`,e=>e.preventDefault()),t.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&(this.choose(this.options[Number(t.dataset.index)].value),this.close())}),t.addEventListener(`pointermove`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&this.setActive(Number(t.dataset.index))})}this.rendered=!0,this.sync()}sync(){let e=this.options.find(e=>e.value===this.current);if(this.nativeEl.value=e?e.value:``,this.trigger){let t=this.trigger.querySelector(`.k-select__value`);t.textContent=e?e.label:this.getAttribute(`placeholder`)??` `,t.className=d(`k-select__value`,!e&&`k-select__value--placeholder`)}let n=this.trigger??this.nativeEl;t(this.querySelector(`:scope > .k-field`),n,this.key,this.getAttribute(`error`),this.getAttribute(`hint`)),this.isOpen&&this.renderList()}choose(e){e!==this.current&&(this.current=e,this.sync(),n(this,`kashi-change`,{value:e}))}renderList(){let e=this.listbox,t=this.options,n=`${this.key}-list`,a,s=t.map((e,t)=>{let r=e.group&&e.group!==a?`<li role="presentation" class="k-listbox__group">${i(e.group)}</li>`:``;a=e.group;let o=e.value===this.current;return`${r}<li id="${n}-${t}" data-index="${t}" role="option" class="k-option" aria-selected="${o}"${e.disabled?` aria-disabled="true"`:``}><span class="k-option__label">${i(e.label)}</span>${o?`<svg class="k-option__check" viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4.5 10.5 3.5 3.5 7.5-8"/></svg>`:``}</li>`});t.length||s.push(r(this,`loading`)?`<li class="k-listbox__loading" role="presentation"></li>`.repeat(3):`<li class="k-listbox__empty" role="presentation">${i(this.getAttribute(`empty-message`)??o().common.noOptions)}</li>`),e.innerHTML=s.join(``),this.setActive(this.active)}setActive(e){this.active=e;let t=this.listbox;t.querySelector(`[data-active]`)?.removeAttribute(`data-active`);let n=e>=0?t.querySelector(`[data-index="${e}"]`):null;n?(n.setAttribute(`data-active`,``),n.scrollIntoView?.({block:`nearest`}),this.isOpen&&this.trigger.setAttribute(`aria-activedescendant`,n.id)):this.trigger.removeAttribute(`aria-activedescendant`)}open(e){if(r(this,`disabled`)||r(this,`readonly`)||!this.trigger)return;this.isOpen=!0;let t=this.listbox;t.hidden=!1,this.trigger.setAttribute(`aria-expanded`,`true`),this.querySelector(`.k-select`).setAttribute(`data-open`,``);let n=this.options.findIndex(e=>e.value===this.current);this.active=e??(n>=0?n:this.step(-1,1)),this.renderList();try{let e=t;e.showPopover&&!t.matches(`:popover-open`)&&e.showPopover()}catch{}this.place(),addEventListener(`resize`,this.place),addEventListener(`scroll`,this.place,!0),document.addEventListener(`pointerdown`,this.onOutside)}close(e=!0){if(!this.isOpen||!this.listbox)return;this.isOpen=!1;let t=this.listbox;try{let e=t;e.hidePopover&&t.matches(`:popover-open`)&&e.hidePopover()}catch{}t.hidden=!0,this.trigger.setAttribute(`aria-expanded`,`false`),this.trigger.removeAttribute(`aria-activedescendant`),this.querySelector(`.k-select`)?.removeAttribute(`data-open`),removeEventListener(`resize`,this.place),removeEventListener(`scroll`,this.place,!0),document.removeEventListener(`pointerdown`,this.onOutside),e&&this.trigger.focus()}step(e,t){let n=this.options;for(let r=e+t;r>=0&&r<n.length;r+=t)if(!n[r].disabled)return r;return e}typeahead(e){let t=this.options;if(!t.length)return;let n=Date.now();this.typed.text=n-this.typed.at>700?e:this.typed.text+e,this.typed.at=n;let r=_(this.typed.text),i=this.isOpen?this.active:t.findIndex(e=>e.value===this.current),a=[...t.keys()].map(e=>(e+i+1+t.length)%t.length).find(e=>!t[e].disabled&&_(t[e].label).startsWith(r));a!==void 0&&(this.isOpen?this.setActive(a):this.choose(t[a].value))}onKey(e){if(r(this,`disabled`)||r(this,`readonly`))return;let t=e.key,n=this.options,i=t.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey;if(!this.isOpen)[`ArrowDown`,`ArrowUp`,`Enter`,` `].includes(t)?(e.preventDefault(),this.open()):t===`Home`||t===`End`?(e.preventDefault(),this.open(t===`Home`?this.step(-1,1):this.step(n.length,-1))):i&&this.typeahead(t);else if(t===`ArrowDown`||t===`ArrowUp`)e.preventDefault(),this.setActive(this.step(this.active,t===`ArrowDown`?1:-1));else if(t===`Home`||t===`PageUp`)e.preventDefault(),this.setActive(this.step(-1,1));else if(t===`End`||t===`PageDown`)e.preventDefault(),this.setActive(this.step(n.length,-1));else if(t===`Enter`||t===` `){e.preventDefault();let t=n[this.active];t&&!t.disabled&&this.choose(t.value),this.close()}else t===`Escape`?(e.preventDefault(),this.close()):t===`Tab`?this.close(!1):i&&this.typeahead(t)}};v.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`size`,`required`,`disabled`,`readonly`,`loading`,`empty-message`,`name`,`value`,`native`,`aria-label`],a(`kashi-checkbox`,m),a(`kashi-switch`,h),a(`kashi-radio-group`,g,`block`),a(`kashi-select`,v,`block`);export{m as KashiCheckbox,g as KashiRadioGroup,v as KashiSelect,h as KashiSwitch};
1
+ import{n as e}from"./text-DFyW6cuq.js";import{_ as t,c as n,i as r,l as i,o as a,p as o,r as s,t as c,u as l,y as u}from"./base-BqFAMlwG.js";import{i as d}from"./parts-5fVaWtRe.js";const f=[`name`,`value`,`form`,`aria-label`,`aria-describedby`];var p=class extends c{constructor(){super(...arguments),this.input=null,this.wrap=null,this.initial=null,this.key=u(`kashi-check`)}connectedCallback(){this.input||this.build(),this.update()}attributeChangedCallback(e,t,n){this.input&&t!==n&&(e===`checked`?this.input.checked=n!==null&&n!==`false`:this.update())}get checked(){return this.input?this.input.checked:this.initial??r(this,`checked`)}set checked(e){this.initial=!!e,this.input&&(this.input.checked=!!e)}focus(e){this.input?.focus(e)}build(){let e=document.createElement(`input`);e.type=`checkbox`,e.id=this.key,this.kind===`switch`&&e.setAttribute(`role`,`switch`),e.checked=this.initial??r(this,`checked`),e.addEventListener(`click`,e=>{r(this,`readonly`)&&e.preventDefault()}),e.addEventListener(`change`,()=>{this.removeAttribute(`data-indeterminate`),n(this,`kashi-change`,{checked:e.checked,value:e.value})}),this.input=e,this.extra()}extra(){}update(){let e=this.input,t=this.getAttribute(`label`),n=this.getAttribute(`description`),i=this.getAttribute(`size`)??`md`;e.className=this.kind===`switch`?d(`k-switch`,i!==`md`&&`k-switch--${i}`):d(`k-checkbox`,i===`lg`&&`k-checkbox--lg`),e.disabled=r(this,`disabled`),e.required=r(this,`required`);for(let t of f){let n=this.getAttribute(t);n===null?e.removeAttribute(t):e.setAttribute(t,n)}if(r(this,`invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`),r(this,`readonly`)?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`),n&&e.setAttribute(`aria-describedby`,`${this.key}-desc`),!t&&!n){this.wrap?.remove(),this.wrap=null,e.parentElement!==this&&this.prepend(e);return}this.wrap||(this.wrap=document.createElement(`label`),this.wrap.htmlFor=this.key,this.wrap.innerHTML=`<span class="k-check__text"><span class="k-check__label"></span><span class="k-check__description"></span></span>`,this.wrap.prepend(e),this.prepend(this.wrap));let a=this.wrap;a.className=d(`k-check`,this.getAttribute(`label-position`)===`start`&&`k-check--start`),a.toggleAttribute(`data-readonly`,r(this,`readonly`));let o=a.querySelector(`.k-check__label`);o.textContent=t??``,o.hidden=!t;let s=a.querySelector(`.k-check__description`);s.id=`${this.key}-desc`,s.textContent=n??``,s.hidden=!n}};p.observedAttributes=[`label`,`description`,`checked`,`disabled`,`required`,`readonly`,`invalid`,`size`,`label-position`,...f];var m=class extends p{constructor(){super(...arguments),this.kind=`checkbox`}attributeChangedCallback(e,t,n){super.attributeChangedCallback(e,t,n),e===`indeterminate`&&this.input&&(this.input.indeterminate=n!==null&&n!==`false`)}extra(){this.input.indeterminate=r(this,`indeterminate`)}get indeterminate(){return this.input?.indeterminate??r(this,`indeterminate`)}set indeterminate(e){this.toggleAttribute(`indeterminate`,!!e)}};m.observedAttributes=[...p.observedAttributes,`indeterminate`];var h=class extends p{constructor(){super(...arguments),this.kind=`switch`}},g=class extends c{constructor(){super(...arguments),this.box=null,this.current=null,this.key=u(`kashi-radio`)}connectedCallback(){s(()=>{this.isConnected&&(this.box||this.build(),this.update())})}attributeChangedCallback(e,t,n){this.box&&t!==n&&(e===`value`?(this.current=n,this.paint()):this.update())}get value(){return this.current??``}set value(e){this.current=e,this.box&&this.paint()}focus(e){(this.box?.querySelector(`input:checked`)??this.box?.querySelector(`input:not(:disabled)`))?.focus(e)}build(){let e=[...this.querySelectorAll(`:scope > option`)];this.current===null&&(this.current=this.getAttribute(`value`)??e.find(e=>e.hasAttribute(`selected`))?.value??null);let t=document.createElement(`fieldset`);t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-labelledby`,`${this.key}-legend`),t.innerHTML=`<legend class="k-label" id="${this.key}-legend"></legend>`,e.forEach((e,n)=>{let r=`${this.key}-${n}`,a=e.dataset.description,o=e.dataset.badge,s=e.dataset.meta,c=i(e.textContent?.trim()??e.value);t.insertAdjacentHTML(`beforeend`,`<label class="k-check" for="${r}"><input type="radio" class="k-radio" id="${r}" value="${i(e.value)}"${e.disabled?` disabled data-off`:``}${a?` aria-describedby="${r}-desc"`:``}><span class="k-check__text">${o?`<span class="k-check__head"><span class="k-check__label">${c}</span><span class="k-badge k-badge--brand k-badge--sm">${i(o)}</span></span>`:`<span class="k-check__label">${c}</span>`}${a?`<span class="k-check__description" id="${r}-desc">${i(a)}</span>`:``}</span>${s?`<span class="k-check__meta">${i(s)}</span>`:``}</label>`)});for(let t of e)t.remove();t.addEventListener(`click`,e=>{r(this,`readonly`)&&e.target.closest(`input`)&&e.preventDefault()}),t.addEventListener(`change`,e=>{let t=e.target;if(r(this,`readonly`))return this.paint();this.current=t.value,n(this,`kashi-change`,{value:t.value})}),this.prepend(t),this.box=t}update(){let e=this.box,t=this.getAttribute(`variant`)??`list`,n=this.getAttribute(`error`),a=this.getAttribute(`hint`),o=r(this,`readonly`);e.className=d(`k-radio-group`,t!==`list`&&`k-radio-group--${t}`),e.disabled=r(this,`disabled`),e.toggleAttribute(`data-readonly`,o);for(let[t,i]of[[`aria-readonly`,o],[`aria-required`,r(this,`required`)],[`aria-invalid`,!!n]])i?e.setAttribute(t,`true`):e.removeAttribute(t);let s=e.querySelector(`legend`);s.innerHTML=`${i(this.getAttribute(`label`)??``)}${r(this,`required`)?`<span class="k-label__required" aria-hidden="true">*</span>`:``}`,e.querySelectorAll(`:scope > .k-hint`).forEach(e=>e.remove()),n&&e.insertAdjacentHTML(`beforeend`,`<p class="k-hint k-hint--error" id="${this.key}-error">${i(n)}</p>`),a&&e.insertAdjacentHTML(`beforeend`,`<p class="k-hint" id="${this.key}-hint">${i(a)}</p>`);let c=[n&&`${this.key}-error`,a&&`${this.key}-hint`].filter(Boolean).join(` `);c?e.setAttribute(`aria-describedby`,c):e.removeAttribute(`aria-describedby`);let l=this.getAttribute(`name`)??this.key;[...e.querySelectorAll(`input`)].forEach((e,t)=>{e.name=l,e.required=r(this,`required`)&&t===0,o?e.setAttribute(`aria-readonly`,`true`):e.removeAttribute(`aria-readonly`),n?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`)}),this.paint()}paint(){for(let e of this.box.querySelectorAll(`input`))e.checked=e.value===this.current}};g.observedAttributes=[`label`,`name`,`value`,`variant`,`hint`,`error`,`required`,`disabled`,`readonly`];const _=t=>e(t,{digits:`latin`}).replace(/‌/g,` `).toLowerCase();var v=class extends c{constructor(){super(...arguments),this.list=null,this.current=null,this.rendered=!1,this.key=u(`kashi-select`),this.isOpen=!1,this.active=-1,this.typed={text:``,at:0},this.trigger=null,this.listbox=null,this.place=()=>{let e=this.trigger,t=this.listbox;if(!e||!t)return;let n=e.getBoundingClientRect(),r=Math.min(288,t.scrollHeight+8),i=innerHeight-n.bottom,a=i<r&&n.top>i;t.classList.toggle(`k-select__list--up`,a),Object.assign(t.style,{position:`fixed`,insetBlock:`auto`,right:`auto`,left:`${n.left}px`,width:`${n.width}px`,top:a?`auto`:`${n.bottom+6}px`,bottom:a?`${innerHeight-n.top+6}px`:`auto`})},this.onOutside=e=>{let t=e.target;!this.listbox?.contains(t)&&!this.trigger?.contains(t)&&this.close(!1)}}connectedCallback(){s(()=>{this.isConnected&&(this.rendered||(this.list===null&&(this.list=this.readOptions()),this.current===null&&(this.current=this.getAttribute(`value`)??(this.hasAttribute(`placeholder`)?``:this.enabled()[0]?.value??``))),this.render())})}disconnectedCallback(){this.close(!1)}attributeChangedCallback(e,t,n){this.rendered&&t!==n&&(e===`value`?this.value=n??``:e===`error`||e===`hint`||e===`placeholder`?this.sync():this.render())}get options(){return this.list??[]}set options(e){this.list=[...e??[]],this.rendered&&this.render()}get value(){return this.current??``}set value(e){this.current=String(e??``),this.rendered&&this.sync()}focus(e){(this.trigger??this.nativeEl)?.focus(e)}readOptions(){let e=[];for(let t of this.querySelectorAll(`:scope > option, :scope > optgroup > option`)){if(t.value===``&&!t.textContent?.trim())continue;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,disabled:t.disabled,group:n})}for(let e of[...this.querySelectorAll(`:scope > option, :scope > optgroup`)])e.remove();return e}enabled(){return this.options.filter(e=>!e.disabled)}render(){this.close(!1);let e=this.key,t=this.getAttribute(`label`),a=this.getAttribute(`aria-label`),o=this.getAttribute(`size`)??`md`,s=r(this,`required`),c=r(this,`disabled`),u=r(this,`readonly`),f=r(this,`native`),p=this.getAttribute(`placeholder`),m=this.options,h,g=m.map(e=>{let t=e.group===h?``:`${h===void 0?``:`</optgroup>`}${e.group===void 0?``:`<optgroup label="${i(e.group)}">`}`;return h=e.group,`${t}<option value="${i(e.value)}"${e.disabled?` disabled`:``}>${i(e.label)}</option>`}).join(``)+(h===void 0?``:`</optgroup>`),_=this.getAttribute(`name`)?` name="${i(this.getAttribute(`name`))}"`:``,v;if(f)v=`<div class="${d(`k-select`,o!==`md`&&`k-select--${o}`)}"><select id="${e}" class="k-select__control"${_}${s?` required`:``}${c?` disabled`:``}${!t&&a?` aria-label="${i(a)}"`:``}>${p===null?``:`<option value="" disabled>${i(p)}</option>`}${g}</select></div>`;else{let n=`${e}-list`;v=`<div class="${d(`k-select`,`k-select--custom`,o!==`md`&&`k-select--${o}`)}"${u?` data-readonly`:``}${r(this,`loading`)?` aria-busy="true"`:``}><button id="${e}" type="button" role="combobox" class="k-select__control" aria-haspopup="listbox" aria-expanded="false" aria-controls="${n}"${s?` aria-required="true"`:``}${u?` aria-readonly="true"`:``}${c?` disabled`:``}${!t&&a?` aria-label="${i(a)}"`:``}><span class="k-select__value"></span><svg class="k-select__chevron" viewBox="0 0 20 20" width="18" height="18" 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><ul id="${n}" role="listbox" aria-labelledby="${e}" class="k-listbox k-select__list" hidden tabindex="-1" popover="manual"></ul><select class="k-select__native" tabindex="-1" aria-hidden="true"${_}${s?` required`:``}${c?` disabled`:``}><option value=""></option>${m.map(e=>`<option value="${i(e.value)}"${e.disabled?` disabled`:``}>${i(e.label)}</option>`).join(``)}</select></div>`}if(this.querySelector(`:scope > .k-field`)?.remove(),this.insertAdjacentHTML(`afterbegin`,l({id:e,label:t,required:s,control:v})),this.nativeEl=this.querySelector(f?`select.k-select__control`:`select.k-select__native`),this.trigger=f?null:this.querySelector(`button.k-select__control`),this.listbox=f?null:this.querySelector(`.k-select__list`),this.nativeEl.addEventListener(`change`,()=>{this.current=this.nativeEl.value,this.sync(),n(this,`kashi-change`,{value:this.current})}),this.trigger){let e=this.trigger;this.nativeEl.addEventListener(`focus`,()=>e.focus()),this.nativeEl.addEventListener(`invalid`,()=>e.focus()),e.addEventListener(`click`,()=>this.isOpen?this.close():this.open()),e.addEventListener(`keydown`,e=>this.onKey(e)),e.addEventListener(`blur`,e=>{this.listbox?.contains(e.relatedTarget)||this.close(!1)});let t=this.listbox;t.addEventListener(`mousedown`,e=>e.preventDefault()),t.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&(this.choose(this.options[Number(t.dataset.index)].value),this.close())}),t.addEventListener(`pointermove`,e=>{let t=e.target.closest(`[role="option"]`);t&&t.getAttribute(`aria-disabled`)!==`true`&&this.setActive(Number(t.dataset.index))})}this.rendered=!0,this.sync()}sync(){let e=this.options.find(e=>e.value===this.current);if(this.nativeEl.value=e?e.value:``,this.trigger){let t=this.trigger.querySelector(`.k-select__value`);t.textContent=e?e.label:this.getAttribute(`placeholder`)??` `,t.className=d(`k-select__value`,!e&&`k-select__value--placeholder`)}let n=this.trigger??this.nativeEl;t(this.querySelector(`:scope > .k-field`),n,this.key,this.getAttribute(`error`),this.getAttribute(`hint`)),this.isOpen&&this.renderList()}choose(e){e!==this.current&&(this.current=e,this.sync(),n(this,`kashi-change`,{value:e}))}renderList(){let e=this.listbox,t=this.options,n=`${this.key}-list`,a,s=t.map((e,t)=>{let r=e.group&&e.group!==a?`<li role="presentation" class="k-listbox__group">${i(e.group)}</li>`:``;a=e.group;let o=e.value===this.current;return`${r}<li id="${n}-${t}" data-index="${t}" role="option" class="k-option" aria-selected="${o}"${e.disabled?` aria-disabled="true"`:``}><span class="k-option__label">${i(e.label)}</span>${o?`<svg class="k-option__check" viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4.5 10.5 3.5 3.5 7.5-8"/></svg>`:``}</li>`});t.length||s.push(r(this,`loading`)?`<li class="k-listbox__loading" role="presentation"></li>`.repeat(3):`<li class="k-listbox__empty" role="presentation">${i(this.getAttribute(`empty-message`)??o().common.noOptions)}</li>`),e.innerHTML=s.join(``),this.setActive(this.active)}setActive(e){this.active=e;let t=this.listbox;t.querySelector(`[data-active]`)?.removeAttribute(`data-active`);let n=e>=0?t.querySelector(`[data-index="${e}"]`):null;n?(n.setAttribute(`data-active`,``),n.scrollIntoView?.({block:`nearest`}),this.isOpen&&this.trigger.setAttribute(`aria-activedescendant`,n.id)):this.trigger.removeAttribute(`aria-activedescendant`)}open(e){if(r(this,`disabled`)||r(this,`readonly`)||!this.trigger)return;this.isOpen=!0;let t=this.listbox;t.hidden=!1,this.trigger.setAttribute(`aria-expanded`,`true`),this.querySelector(`.k-select`).setAttribute(`data-open`,``);let n=this.options.findIndex(e=>e.value===this.current);this.active=e??(n>=0?n:this.step(-1,1)),this.renderList();try{let e=t;e.showPopover&&!t.matches(`:popover-open`)&&e.showPopover()}catch{}this.place(),addEventListener(`resize`,this.place),addEventListener(`scroll`,this.place,!0),document.addEventListener(`pointerdown`,this.onOutside)}close(e=!0){if(!this.isOpen||!this.listbox)return;this.isOpen=!1;let t=this.listbox;try{let e=t;e.hidePopover&&t.matches(`:popover-open`)&&e.hidePopover()}catch{}t.hidden=!0,this.trigger.setAttribute(`aria-expanded`,`false`),this.trigger.removeAttribute(`aria-activedescendant`),this.querySelector(`.k-select`)?.removeAttribute(`data-open`),removeEventListener(`resize`,this.place),removeEventListener(`scroll`,this.place,!0),document.removeEventListener(`pointerdown`,this.onOutside),e&&this.trigger.focus()}step(e,t){let n=this.options;for(let r=e+t;r>=0&&r<n.length;r+=t)if(!n[r].disabled)return r;return e}typeahead(e){let t=this.options;if(!t.length)return;let n=Date.now();this.typed.text=n-this.typed.at>700?e:this.typed.text+e,this.typed.at=n;let r=_(this.typed.text),i=this.isOpen?this.active:t.findIndex(e=>e.value===this.current),a=[...t.keys()].map(e=>(e+i+1+t.length)%t.length).find(e=>!t[e].disabled&&_(t[e].label).startsWith(r));a!==void 0&&(this.isOpen?this.setActive(a):this.choose(t[a].value))}onKey(e){if(r(this,`disabled`)||r(this,`readonly`))return;let t=e.key,n=this.options,i=t.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey;if(!this.isOpen)[`ArrowDown`,`ArrowUp`,`Enter`,` `].includes(t)?(e.preventDefault(),this.open()):t===`Home`||t===`End`?(e.preventDefault(),this.open(t===`Home`?this.step(-1,1):this.step(n.length,-1))):i&&this.typeahead(t);else if(t===`ArrowDown`||t===`ArrowUp`)e.preventDefault(),this.setActive(this.step(this.active,t===`ArrowDown`?1:-1));else if(t===`Home`||t===`PageUp`)e.preventDefault(),this.setActive(this.step(-1,1));else if(t===`End`||t===`PageDown`)e.preventDefault(),this.setActive(this.step(n.length,-1));else if(t===`Enter`||t===` `){e.preventDefault();let t=n[this.active];t&&!t.disabled&&this.choose(t.value),this.close()}else t===`Escape`?(e.preventDefault(),this.close()):t===`Tab`?this.close(!1):i&&this.typeahead(t)}};v.observedAttributes=[`label`,`hint`,`error`,`placeholder`,`size`,`required`,`disabled`,`readonly`,`loading`,`empty-message`,`name`,`value`,`native`,`aria-label`],a(`kashi-checkbox`,m),a(`kashi-switch`,h),a(`kashi-radio-group`,g,`block`),a(`kashi-select`,v,`block`);export{m as KashiCheckbox,g as KashiRadioGroup,v as KashiSelect,h as KashiSwitch};