@kashi-ui/elements 2.23.0 → 2.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buttons.js +22 -4
- package/dist/cdn/{buttons-zhSdiaXr.js → buttons-BaK6bx3w.js} +1 -1
- package/dist/cdn/{content-BgfBfy8j.js → content-DN3eXLg-.js} +1 -1
- package/dist/cdn/kashi-elements.js +1 -1
- package/dist/cdn/{overlay-DC5-I6hM.js → overlay-CS8piW6X.js} +1 -1
- package/dist/cdn/{sheets-eVMx4d-5.js → sheets-CVbD98PY.js} +1 -1
- package/dist/content.js +2 -1
- package/dist/manifest.json +8 -3
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.js +42 -11
- package/dist/sheets.js +1 -1
- package/package.json +4 -4
package/dist/buttons.js
CHANGED
|
@@ -433,8 +433,20 @@ export class KashiAccordion extends HTMLBase {
|
|
|
433
433
|
else if (child.hasAttribute("data-title")) {
|
|
434
434
|
d = document.createElement("details");
|
|
435
435
|
d.innerHTML = "<summary></summary>";
|
|
436
|
-
d.querySelector("summary")
|
|
436
|
+
const sum = d.querySelector("summary");
|
|
437
|
+
const desc = child.getAttribute("data-description");
|
|
438
|
+
if (desc) {
|
|
439
|
+
sum.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>`;
|
|
440
|
+
sum.querySelector(".k-accordion__title").textContent = child.getAttribute("data-title");
|
|
441
|
+
sum.querySelector(".k-accordion__description").textContent = desc;
|
|
442
|
+
}
|
|
443
|
+
else
|
|
444
|
+
sum.textContent = child.getAttribute("data-title");
|
|
437
445
|
d.open = child.hasAttribute("data-open");
|
|
446
|
+
if (child.hasAttribute("data-disabled"))
|
|
447
|
+
d.setAttribute("data-disabled", "");
|
|
448
|
+
if (child.hasAttribute("data-value"))
|
|
449
|
+
d.dataset.value = child.getAttribute("data-value");
|
|
438
450
|
const body = document.createElement("div");
|
|
439
451
|
body.append(...child.childNodes);
|
|
440
452
|
d.append(body);
|
|
@@ -444,6 +456,12 @@ export class KashiAccordion extends HTMLBase {
|
|
|
444
456
|
d.classList.add("k-accordion__item");
|
|
445
457
|
const summary = d.querySelector(":scope > summary");
|
|
446
458
|
summary?.classList.add("k-accordion__trigger");
|
|
459
|
+
if (d.hasAttribute("data-disabled") && summary) {
|
|
460
|
+
d.classList.add("k-accordion__item--disabled");
|
|
461
|
+
summary.setAttribute("aria-disabled", "true");
|
|
462
|
+
summary.tabIndex = -1;
|
|
463
|
+
summary.addEventListener("click", (e) => e.preventDefault());
|
|
464
|
+
}
|
|
447
465
|
const rest = [...d.childNodes].filter((n) => n !== summary);
|
|
448
466
|
const content = rest.length === 1 && rest[0] instanceof HTMLElement && rest[0].classList.contains("k-accordion__content") ? rest[0] : null;
|
|
449
467
|
if (!content) {
|
|
@@ -465,11 +483,11 @@ export class KashiAccordion extends HTMLBase {
|
|
|
465
483
|
for (const x of this.details)
|
|
466
484
|
if (x !== d && x.open)
|
|
467
485
|
x.open = false;
|
|
468
|
-
emit(this, "kashi-toggle", { index: this.details.indexOf(d), open: d.open });
|
|
486
|
+
emit(this, "kashi-toggle", { index: this.details.indexOf(d), value: d.dataset.value, open: d.open });
|
|
469
487
|
}, true);
|
|
470
488
|
}
|
|
471
489
|
update() {
|
|
472
|
-
this.box.className = cx("k-accordion", bool(this, "flush") && "k-accordion--flush");
|
|
490
|
+
this.box.className = cx("k-accordion", bool(this, "flush") && "k-accordion--flush", this.getAttribute("size") === "sm" && "k-accordion--sm");
|
|
473
491
|
const single = this.getAttribute("type") === "single";
|
|
474
492
|
for (const d of this.details) {
|
|
475
493
|
if (single)
|
|
@@ -479,7 +497,7 @@ export class KashiAccordion extends HTMLBase {
|
|
|
479
497
|
}
|
|
480
498
|
}
|
|
481
499
|
}
|
|
482
|
-
KashiAccordion.observedAttributes = ["type", "flush"];
|
|
500
|
+
KashiAccordion.observedAttributes = ["type", "flush", "size"];
|
|
483
501
|
define("kashi-button", KashiButton);
|
|
484
502
|
define("kashi-button-group", KashiButtonGroup);
|
|
485
503
|
define("kashi-segmented-control", KashiSegmentedControl);
|
|
@@ -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>`,n.querySelector(`summary`).textContent=e.getAttribute(`data-title`),n.open=e.hasAttribute(`data-open`);let t=document.createElement(`div`);t.append(...e.childNodes),n.append(t)}else continue;n.classList.add(`k-accordion__item`);let r=n.querySelector(`:scope > summary`);r?.classList.add(`k-accordion__trigger`);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),open:r.open})}},!0)}update(){this.box.className=c(`k-accordion`,t(this,`flush`)&&`k-accordion--flush`);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`],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-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 +1 @@
|
|
|
1
|
-
import{d as e,i as t,j as n,l as r,m as i,n as a,o,p as s,r as c,s as l,t as u}from"./base-D4tCOysh.js";import{t as d}from"./relative-OC1fV3Xh.js";import{f,i as p,m,o as h,p as g,s as _,u as v}from"./parts-5fVaWtRe.js";var y=class extends u{constructor(){super(...arguments),this.built=!1}connectedCallback(){c(()=>{this.isConnected&&(this.built||(this.built=!0,this.build()),this.update())})}attributeChangedCallback(e,t,n){this.built&&t!==n&&this.update()}},b=class extends y{build(){let e=f(this,`icon`)[0];if(this.box=document.createElement(`span`),e){let t=document.createElement(`span`);t.className=`k-badge__icon`,t.setAttribute(`aria-hidden`,`true`),t.append(e),this.box.append(t)}this.text=document.createElement(`span`),this.text.style.display=`contents`,this.text.append(...this.childNodes),this.box.append(this.text),this.append(this.box),this.box.addEventListener(`click`,e=>{if(!e.target.closest(`.k-badge__remove`))return;let t=new CustomEvent(`kashi-remove`,{bubbles:!0,cancelable:!0,detail:{value:this.text.textContent?.trim()??``}});this.dispatchEvent(t)&&this.remove()})}update(){let e=this.getAttribute(`tone`)??`neutral`,n=this.getAttribute(`variant`)??`soft`,i=this.getAttribute(`size`)??`md`,a=t(this,`removable`);this.box.className=p(`k-badge`,e!==`neutral`&&`k-badge--${e}`,n!==`soft`&&`k-badge--${n}`,i!==`md`&&`k-badge--${i}`,t(this,`square`)&&`k-badge--square`,a&&`k-badge--removable`),this.box.dataset.tone=e,this.box.dataset.variant=n;let o=this.box.querySelector(`:scope > .k-badge__dot`);t(this,`dot`)&&!o?this.box.insertAdjacentHTML(`afterbegin`,`<span class="k-badge__dot" aria-hidden="true"></span>`):t(this,`dot`)||o?.remove();let c=this.box.querySelector(`:scope > .k-badge__remove`);if(a){let e=this.text.textContent?.trim()??``,t=this.getAttribute(`remove-label`)??(e?s().common.remove(e):s().common.removeShort);c?c.setAttribute(`aria-label`,t):this.box.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-badge__remove" aria-label="${r(t)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="m6 6 8 8M14 6l-8 8"/></svg></button>`)}else c?.remove()}};b.observedAttributes=[`tone`,`variant`,`size`,`dot`,`square`,`removable`,`remove-label`];const x=[`brand`,`info`,`success`,`warning`,`error`],S=(e,t=2)=>e.trim().split(/\s+/).slice(0,t).map(e=>e[0]??``).join(``).toUpperCase();function C(e){let t=0;for(let n of e.trim())t=t*31+n.codePointAt(0)>>>0;return x[t%x.length]}var w=class extends u{constructor(){super(...arguments),this.failed=!1}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&(e===`src`&&(this.failed=!1),this.render())}render(){let e=this.getAttribute(`name`)??``,n=this.getAttribute(`size`)??`md`,i=this.getAttribute(`color`),a=i===`auto`?C(e):i??(t(this,`brand`)?`brand`:`neutral`),o=this.getAttribute(`status`),c=o?this.getAttribute(`status-label`)??s().avatar[o]:null,l=this.getAttribute(`src`),u=c?`${e}${s().common.list}${c}`:e,d=l&&!this.failed?`<img class="k-avatar__image" src="${r(l)}" alt="">`:`<span aria-hidden="true">${r(S(e,n===`xs`||n===`sm`?1:2))}</span>`;this.innerHTML=`<span role="img" aria-label="${r(u)}" data-tone="${a}" class="${p(`k-avatar`,n!==`md`&&`k-avatar--${n}`,t(this,`square`)&&`k-avatar--square`,a!==`neutral`&&`k-avatar--${a}`)}">${d}${o?`<span class="k-avatar__status k-avatar__status--${o}" aria-hidden="true"></span>`:``}</span>`,this.querySelector(`img`)?.addEventListener(`error`,()=>{this.failed=!0,this.render()},{once:!0})}};w.observedAttributes=[`name`,`src`,`size`,`square`,`brand`,`color`,`status`,`status-label`];var T=class extends y{build(){this.box=document.createElement(`div`),this.box.setAttribute(`role`,`group`),this.box.className=`k-avatar-group`,this.box.append(...this.childNodes),this.append(this.box)}update(){this.box.querySelector(`:scope > [data-more]`)?.remove();let e=[...this.box.children].filter(e=>e.tagName===`KASHI-AVATAR`||e.classList.contains(`k-avatar`)),t=v(this,`max`);e.forEach((e,n)=>e.hidden=!!t&&n>=t);let n=t?Math.max(0,e.length-t):0;if(!n)return;let a=this.getAttribute(`size`)??`md`,o=this.getAttribute(`more-label`)?.replace(`{n}`,i(this,n))??s().avatar.more(i(this,n));this.box.insertAdjacentHTML(`beforeend`,`<span data-more role="img" aria-label="${r(o)}" class="${p(`k-avatar`,a!==`md`&&`k-avatar--${a}`)}"><span aria-hidden="true">+${i(this,n)}</span></span>`)}};T.observedAttributes=[`max`,`size`,`more-label`];var E=class extends u{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=this.getAttribute(`label`),n=t(this,`vertical`);this.innerHTML=`<div role="separator"${n?` aria-orientation="vertical"`:``} class="${p(`k-divider`,n&&`k-divider--vertical`)}">${e?`<span>${r(e)}</span>`:``}</div>`}};E.observedAttributes=[`label`,`vertical`];const D=e=>e===null?null:/^\d+(\.\d+)?$/.test(e)?`${e}px`:e;var O=class extends u{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=D(this.getAttribute(`width`)),n=t(this,`circle`),i=D(this.getAttribute(`height`))??(n?e:null),a=[e&&`--k-skeleton-width: ${e}`,i&&`--k-skeleton-height: ${i}`].filter(Boolean).join(`; `),o=a?` style="${r(a)}"`:``,s=v(this,`lines`,0);this.innerHTML=s>0?`<span class="k-skeleton-group" aria-hidden="true"${o}>${`<span class="k-skeleton k-skeleton--text"></span>`.repeat(Math.min(50,s))}</span>`:`<span class="${p(`k-skeleton`,n&&`k-skeleton--circle`)}" aria-hidden="true"${o}></span>`}};O.observedAttributes=[`width`,`height`,`circle`,`lines`];var k=class extends y{build(){let e=f(this,`media`),t=f(this,`actions`),n=f(this,`footer`),r=m(this);this.box=document.createElement(`article`);for(let t of e)t.classList.add(`k-card__media`),t instanceof HTMLImageElement&&!t.style.aspectRatio&&(t.style.aspectRatio=`16 / 9`),this.box.append(t);if(this.header=document.createElement(`header`),this.header.innerHTML=`<div class="k-card__heading"></div>`,t.length){let e=document.createElement(`div`);e.className=`k-card__actions`,e.append(...t),this.header.append(e)}if(this.box.append(this.header),h(r)){let e=document.createElement(`div`);e.className=`k-card__body`,e.append(...r),this.box.append(e)}if(n.length){let e=document.createElement(`footer`);e.className=`k-card__footer`,e.append(...n),this.box.append(e)}this.append(this.box)}update(){let e=this.getAttribute(`variant`)??`outlined`,n=this.getAttribute(`padding`)??`md`;this.box.className=p(`k-card`,t(this,`flat`)&&`k-card--flat`,t(this,`interactive`)&&`k-card--interactive`,e!==`outlined`&&`k-card--${e}`,n!==`md`&&`k-card--pad-${n}`),this.box.dataset.variant=e;let i=this.getAttribute(`heading`),a=this.getAttribute(`description`),o=!!this.header.querySelector(`.k-card__actions`);this.header.className=p(`k-card__header`,o&&`k-card__header--actions`),this.header.hidden=!i&&!a&&!o;let s=Math.min(6,Math.max(1,v(this,`heading-level`,3))),c=this.header.querySelector(`.k-card__heading`);c.innerHTML=`${i?`<h${s} class="k-card__title">${r(i)}</h${s}>`:``}${a?`<p class="k-card__description">${r(a)}</p>`:``}`}};k.observedAttributes=[`heading`,`description`,`heading-level`,`variant`,`padding`,`flat`,`interactive`];const A=e=>_(e,1.5),j={noData:A(`<path d="M7.25 2.75h5.5c3.6 0 4.5.9 4.5 4.5v5.5c0 3.6-.9 4.5-4.5 4.5h-5.5c-3.6 0-4.5-.9-4.5-4.5v-5.5c0-3.6.9-4.5 4.5-4.5Z"/><path d="M2.75 10.75h3.1c.55 0 1 .3 1.25.75l.5.95c.25.45.7.75 1.25.75h2.3c.55 0 1-.3 1.25-.75l.5-.95c.25-.45.7-.75 1.25-.75h3.1"/>`),noResults:A(`<circle cx="9.1" cy="9.1" r="6.2"/><path d="m14.9 14.9 2.3 2.3M7.2 7.2l3.8 3.8M11 7.2l-3.8 3.8"/>`),error:A(`<path d="M8.33 3.9c.74-1.3 2.6-1.3 3.34 0l5.6 9.75c.74 1.3-.2 2.85-1.67 2.85H4.4c-1.48 0-2.41-1.56-1.67-2.85Z"/><path d="M10 7.9v3.1M10 13.6v.01"/>`),offline:A(`<path d="M2.75 7.6a10.5 10.5 0 0 1 14.5 0M5.2 10.3a7 7 0 0 1 9.6 0M7.7 12.95a3.5 3.5 0 0 1 4.6 0M10 15.75v.01"/><path d="m3 3 14 14"/>`),noAccess:A(`<path d="M7.25 8.25h5.5c2.6 0 3.25.65 3.25 3.25v2.75c0 2.6-.65 3.25-3.25 3.25h-5.5C4.65 17.5 4 16.85 4 14.25V11.5c0-2.6.65-3.25 3.25-3.25Z"/><path d="M6.9 8.3V6.4a3.1 3.1 0 0 1 6.2 0v1.9M10 11.6v2.2"/>`),done:A(`<circle cx="10" cy="10" r="7.25"/><path d="m6.75 10.1 2.2 2.2 4.3-4.5"/>`)},M=[`noData`,`noResults`,`error`,`offline`,`noAccess`,`done`],N=e=>{if(!e)return null;let t=e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());return M.includes(t)?t:null};var P=class extends y{constructor(){super(...arguments),this.customIcon=null,this.actions=null}build(){this.customIcon=f(this,`icon`)[0]??null;let e=f(this,`actions`);this.box=document.createElement(`div`),this.box.innerHTML=`<span class="k-empty__icon" aria-hidden="true"></span><p class="k-empty__title"></p><p class="k-empty__description"></p>`,this.customIcon&&this.box.firstElementChild.append(this.customIcon);let t=m(this);(e.length||h(t))&&(this.actions=document.createElement(`div`),this.actions.className=`k-empty__actions`,this.actions.append(...e,...h(t)?t:[]),this.box.append(this.actions)),this.replaceChildren(this.box)}update(){let e=N(this.getAttribute(`preset`)),n=this.getAttribute(`size`)??`md`,r=e?s().empty[e]:void 0;this.box.className=p(`k-empty`,n!==`md`&&`k-empty--${n}`,t(this,`bordered`)&&`k-empty--bordered`),e?this.box.dataset.preset=e:delete this.box.dataset.preset,e===`error`||e===`offline`?this.box.setAttribute(`role`,`status`):this.box.removeAttribute(`role`);let i=this.box.querySelector(`.k-empty__icon`);this.customIcon||(i.innerHTML=e?j[e]:``),i.hidden=!i.firstChild;let a=this.getAttribute(`heading`)??r?.[0]??``,o=this.getAttribute(`description`)??r?.[1]??``,c=this.box.querySelector(`.k-empty__title`),l=this.box.querySelector(`.k-empty__description`);c.textContent=a,c.hidden=!a,l.textContent=o,l.hidden=!o}};P.observedAttributes=[`preset`,`heading`,`description`,`size`,`bordered`];const F=e=>_(e?`<path d="M10 15V5m0 0-4 4m4-4 4 4"/>`:`<path d="M10 5v10m0 0-4-4m4 4 4-4"/>`,1.8);var I=class extends y{build(){let e=f(this,`icon`)[0],t=m(this);if(this.box=document.createElement(`div`),this.box.className=`k-stat`,this.box.innerHTML=`<div class="k-stat__head"><p class="k-stat__label"></p></div><p class="k-stat__value"><span></span><span class="k-stat__unit"></span></p><div class="k-stat__foot"></div>`,e){let t=document.createElement(`span`);t.className=`k-stat__icon`,t.setAttribute(`aria-hidden`,`true`),t.append(e),this.box.firstElementChild.prepend(t)}if(h(t)){let e=document.createElement(`div`);e.className=`k-stat__chart`,e.append(...t),this.box.append(e)}this.replaceChildren(this.box)}update(){let e=s(),n=v(this,`change`);this.box.querySelector(`.k-stat__label`).textContent=this.getAttribute(`label`)??``;let a=this.getAttribute(`value`)??``;this.box.querySelector(`.k-stat__value > span`).textContent=/^-?[\d.,]+$/.test(a)?i(this,a):a;let o=this.box.querySelector(`.k-stat__unit`);o.textContent=this.getAttribute(`unit`)??``,o.hidden=!o.textContent,t(this,`loading`)?this.box.setAttribute(`aria-busy`,`true`):this.box.removeAttribute(`aria-busy`);let c=n===void 0?null:n>0?`up`:n<0?`down`:`flat`,l=c===`flat`?`flat`:c===`up`===t(this,`invert-trend`)?`down`:`up`,u=this.getAttribute(`up-label`)??e.stat.up,d=this.getAttribute(`down-label`)??e.stat.down,f=this.getAttribute(`flat-label`)??e.stat.flat,p=n===void 0?``:e.common.percent(i(this,Math.abs(Math.round(n*10)/10)).replace(`.`,e.common.decimal)),m=this.getAttribute(`caption`),h=this.box.querySelector(`.k-stat__foot`);h.hidden=!c&&!m,h.innerHTML=`${c?`<span class="k-trend k-trend--${l}">${c===`flat`?``:F(c===`up`)}<span aria-hidden="true">${r(c===`flat`?f:p)}</span><span class="k-sr-only">${r(c===`flat`?f:`${p} ${c===`up`?u:d}`)}</span></span>`:``}${m?`<span>${r(m)}</span>`:``}`}};I.observedAttributes=[`label`,`value`,`unit`,`change`,`invert-trend`,`caption`,`loading`,`up-label`,`down-label`,`flat-label`];const L={neutral:a.info,brand:a.info,info:a.info,success:a.success,warning:a.warning,error:a.error};var R=class extends y{constructor(){super(...arguments),this.customIcon=null}build(){this.customIcon=f(this,`icon`)[0]??null;let e=f(this,`actions`),t=m(this);this.box=document.createElement(`div`),this.box.innerHTML=`<span class="k-alert__icon" aria-hidden="true"></span><div class="k-alert__content"><p class="k-alert__title"></p></div>`;let n=this.box.querySelector(`.k-alert__content`);if(h(t)){let e=document.createElement(`div`);e.className=`k-alert__description`,e.append(...t),n.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-alert__actions`,t.append(...e),n.append(t)}this.customIcon&&this.box.firstElementChild.append(this.customIcon),this.replaceChildren(this.box),this.box.addEventListener(`click`,e=>{e.target.closest(`.k-alert__close`)&&this.close()})}update(){let e=this.getAttribute(`tone`)??`neutral`;this.box.className=p(`k-alert`,e!==`neutral`&&`k-alert--${e}`,t(this,`tinted`)&&`k-alert--tinted`,this.getAttribute(`layout`)===`banner`&&`k-alert--banner`,this.getAttribute(`size`)===`sm`&&`k-alert--sm`),this.box.dataset.tone=e,this.box.setAttribute(`role`,e===`error`||e===`warning`?`alert`:`status`);let n=this.box.querySelector(`.k-alert__icon`);n.hidden=this.getAttribute(`icon`)===`false`,this.customIcon||(n.innerHTML=L[e]??a.info);let r=this.box.querySelector(`.k-alert__title`);r.textContent=this.getAttribute(`heading`)??``,r.hidden=!r.textContent;let i=this.box.querySelector(`:scope > .k-alert__close`);t(this,`dismissible`)?(i||=(this.box.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-alert__close">${a.close}</button>`),this.box.querySelector(`:scope > .k-alert__close`)),i.setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().alert.close)):i?.remove()}close(){let e=new CustomEvent(`kashi-close`,{bubbles:!0,cancelable:!0,detail:{}});this.dispatchEvent(e)&&(this.hidden=!0)}};R.observedAttributes=[`tone`,`heading`,`tinted`,`layout`,`size`,`dismissible`,`close-label`,`icon`];var z=class extends u{constructor(){super(...arguments),this.box=null}connectedCallback(){this.box||(this.box=document.createElement(`div`),this.box.className=`k-meter`,this.box.innerHTML=`<div class="k-meter__head"><span class="k-meter__label"></span><span class="k-meter__value"></span></div><div class="k-meter__track" role="meter" aria-valuemin="0"><span class="k-meter__fill"></span><span class="k-meter__mark" aria-hidden="true"></span></div><p class="k-meter__status" aria-hidden="true"></p>`,this.replaceChildren(this.box)),this.update()}attributeChangedCallback(){this.box&&this.update()}update(){let e=s(),t=v(this,`max`,100)||100,a=v(this,`warning`,t*.8),o=v(this,`critical`,t*.95),c=Math.min(t,Math.max(0,v(this,`value`,0))),u=c>=o?`critical`:c>=a?`warning`:`ok`,d=Math.round(c/t*100),f=this.getAttribute(`${u}-label`)??e.meter[u],p=this.getAttribute(`unit`),m=e=>`${n(Math.round(e*100)/100,{digits:l(this)})}${p?` ${p}`:``}`,h=this.getAttribute(`of`),g=this.getAttribute(`label`)??``,y=this.box;y.dataset.status=u,y.querySelector(`.k-meter__label`).textContent=g,y.querySelector(`.k-meter__value`).innerHTML=`${r(m(c))} <span>${r(h??`/`)} ${r(m(t))}</span>`;let b=y.querySelector(`.k-meter__track`);b.setAttribute(`aria-valuenow`,String(c)),b.setAttribute(`aria-valuemax`,String(t)),b.setAttribute(`aria-valuetext`,`${h?`${m(c)} ${h} ${m(t)}`:e.common.of(m(c),m(t))}${e.common.list}${e.common.percent(i(this,d))}${e.common.list}${f}`),g&&b.setAttribute(`aria-label`,g),y.querySelector(`.k-meter__fill`).style.inlineSize=`${d}%`,y.querySelector(`.k-meter__mark`).style.insetInlineStart=`${a/t*100}%`,y.querySelector(`.k-meter__status`).innerHTML=`${_(`<path d="${u===`ok`?`m5 10.5 3.2 3L15 7`:`M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01`}"/>`,1.8)}${r(f)} · ${r(e.common.percent(i(this,d)))}`}};z.observedAttributes=[`label`,`value`,`max`,`warning`,`critical`,`unit`,`of`,`ok-label`,`warning-label`,`critical-label`,`digits`];var B=class extends u{constructor(){super(...arguments),this.kind=``}connectedCallback(){this.update()}attributeChangedCallback(){this.isConnected&&this.update()}update(){let e=s(),n=v(this,`max`,100)||100,r=v(this,`value`),a=r===void 0?void 0:Math.max(0,Math.min(100,r/n*100)),o=a===void 0?void 0:e.common.percent(i(this,Math.round(a))),c=this.getAttribute(`label`),l=this.getAttribute(`size`)??`md`,u=this.getAttribute(`tone`)??`brand`,d=this.getAttribute(`variant`)===`circular`,f=t(this,`show-value`),m=`${d}-${!!c}`;m!==this.kind&&(this.kind=m,this.innerHTML=d?`<div role="progressbar" aria-valuemin="0"><svg viewBox="0 0 40 40" aria-hidden="true"><circle class="k-progress-ring__track" cx="20" cy="20" r="16"/><circle class="k-progress-ring__bar" cx="20" cy="20" r="16"/></svg><span class="k-progress-ring__value" aria-hidden="true"></span></div>`:`${c?`<div class="k-progress-field"><div class="k-progress-field__head" aria-hidden="true"><span class="k-progress-field__label"></span><span class="k-progress-field__value"></span></div>`:``}<div role="progressbar" aria-valuemin="0"><div class="k-progress__bar"></div></div>${c?`</div>`:``}`);let h=this.querySelector(`[role="progressbar"]`);h.setAttribute(`aria-valuemax`,String(n));for(let[e,t]of[[`aria-valuenow`,r===void 0?null:String(r)],[`aria-valuetext`,o??null],[`aria-label`,this.getAttribute(`aria-label`)??c]])t===null?h.removeAttribute(e):h.setAttribute(e,t);if(d){let e=2*Math.PI*16;h.className=p(`k-progress-ring`,l!==`md`&&`k-progress-ring--${l}`,u!==`brand`&&`k-progress--${u}`,a===void 0&&`k-progress-ring--indeterminate`);let t=h.querySelector(`.k-progress-ring__bar`);t.setAttribute(`stroke-dasharray`,String(e)),t.setAttribute(`stroke-dashoffset`,String(a===void 0?e*.7:e*(1-a/100)));let n=h.querySelector(`.k-progress-ring__value`);n.textContent=f&&o?o:``,n.hidden=!n.textContent;return}h.className=p(`k-progress`,l!==`md`&&`k-progress--${l}`,u!==`brand`&&`k-progress--${u}`);let g=h.querySelector(`.k-progress__bar`);if(a===void 0?g.style.removeProperty(`--k-value`):g.style.setProperty(`--k-value`,`${a}%`),c){this.querySelector(`.k-progress-field__label`).textContent=c;let e=this.querySelector(`.k-progress-field__value`);e.textContent=f&&o?o:``,e.hidden=!e.textContent}}};B.observedAttributes=[`value`,`max`,`label`,`show-value`,`size`,`tone`,`variant`,`aria-label`];const V=/^\d{4}-\d{2}-\d{2}([T ][\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/;var H=class extends u{constructor(){super(...arguments),this.list=null,this.data=[],this.timer=null}connectedCallback(){c(()=>{this.isConnected&&(this.list||(this.data.length||(this.data=[...this.children].filter(e=>e.hasAttribute(`data-title`)).map(e=>{let t=e;return{item:{title:t.dataset.title??``,time:t.dataset.time,tone:t.dataset.tone},nodes:[...t.childNodes]}})),this.list=document.createElement(`ol`),this.list.className=`k-timeline`,this.replaceChildren(this.list)),this.render(),this.list.querySelector(`time[data-iso]`)&&(this.timer??=setInterval(()=>this.refreshTimes(),6e4)))})}disconnectedCallback(){this.timer&&clearInterval(this.timer),this.timer=null}attributeChangedCallback(){this.list&&this.render()}get items(){return this.data.map(e=>e.item)}set items(e){this.data=(e??[]).map(e=>({item:e,nodes:[]})),this.list&&this.render()}timeText(t){if(!V.test(t))return t;let n=g(t);return n?d(n,{locale:e(),digits:l(this)}):t}refreshTimes(){this.list?.querySelectorAll(`time[data-iso]`).forEach(e=>e.textContent=this.timeText(e.dateTime))}render(){let e=this.list;e.replaceChildren();for(let{item:t,nodes:n}of this.data){let i=document.createElement(`li`);i.className=`k-timeline__item`,t.tone&&t.tone!==`neutral`&&(i.dataset.tone=t.tone);let a=t.time?V.test(t.time)?`<time class="k-timeline__time" data-iso datetime="${r(t.time)}">${r(this.timeText(t.time))}</time>`:`<span class="k-timeline__time">${r(t.time)}</span>`:``;if(i.innerHTML=`<span class="k-timeline__marker" aria-hidden="true"><svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="3" fill="currentColor"/></svg></span><div class="k-timeline__body"><p class="k-timeline__title">${r(t.title)}</p>${a}</div>`,h(n)||t.content){let e=document.createElement(`div`);e.className=`k-timeline__content`,h(n)?e.append(...n):e.textContent=t.content,i.querySelector(`.k-timeline__body`).append(e)}e.append(i)}}};H.observedAttributes=[`digits`];const U=_(`<path d="m5 10.5 3.2 3L15 7"/>`,2.2);var W=class extends u{constructor(){super(...arguments),this.list=null,this.data=[]}connectedCallback(){c(()=>{this.isConnected&&(this.list||(!this.data.length&&!this.hasAttribute(`steps`)&&(this.data=[...this.children].filter(e=>e.tagName===`LI`).map(e=>({title:e.textContent?.trim()??``,description:e.dataset.description}))),this.list=document.createElement(`ol`),this.replaceChildren(this.list)),this.render())})}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`steps`&&(this.data=[]),this.render())}get steps(){return this.data.length?this.data:this.parsed()}set steps(e){this.data=[...e??[]],this.list&&this.render()}get current(){return v(this,`current`,0)}set current(e){this.setAttribute(`current`,String(e))}parsed(){try{let e=JSON.parse(this.getAttribute(`steps`)??`[]`);return Array.isArray(e)?e.map(e=>typeof e==`string`?{title:e}:e):[]}catch{return[]}}render(){let e=s(),t=this.list,n=this.steps,a=this.current;t.className=p(`k-steps`,this.getAttribute(`orientation`)===`vertical`&&`k-steps--vertical`),t.setAttribute(`aria-label`,this.getAttribute(`label`)??e.stepper.label);let o=this.getAttribute(`complete-label`)??e.stepper.complete,c=this.getAttribute(`current-label`)??e.stepper.current;t.innerHTML=n.map((t,n)=>{let s=n<a?`complete`:n===a?`current`:`upcoming`;return`<li class="k-steps__step" data-status="${s}"${s===`current`?` aria-current="step"`:``}><span class="k-steps__marker" aria-hidden="true">${s===`complete`?U:i(this,n+1)}</span><span class="k-steps__title">${r(t.title)}${s===`upcoming`?``:`<span class="k-sr-only">${r(`${e.common.list}${s===`complete`?o:c}`)}</span>`}</span>${t.description?`<span class="k-steps__description">${r(t.description)}</span>`:``}</li>`}).join(``)}};W.observedAttributes=[`current`,`orientation`,`label`,`steps`,`complete-label`,`current-label`,`digits`],o(`kashi-badge`,b),o(`kashi-avatar`,w),o(`kashi-avatar-group`,T),o(`kashi-divider`,E,`contents`),o(`kashi-skeleton`,O),o(`kashi-card`,k,`block`),o(`kashi-empty-state`,P,`block`),o(`kashi-stat-card`,I,`block`),o(`kashi-alert`,R,`block`),o(`kashi-meter`,z,`block`),o(`kashi-progress`,B,`block`),o(`kashi-timeline`,H,`block`),o(`kashi-stepper`,W,`block`);export{R as KashiAlert,w as KashiAvatar,T as KashiAvatarGroup,b as KashiBadge,k as KashiCard,E as KashiDivider,P as KashiEmptyState,z as KashiMeter,B as KashiProgress,O as KashiSkeleton,I as KashiStatCard,W as KashiStepper,H as KashiTimeline,C as autoTone,S as initials};
|
|
1
|
+
import{d as e,i as t,j as n,l as r,m as i,n as a,o,p as s,r as c,s as l,t as u}from"./base-D4tCOysh.js";import{t as d}from"./relative-OC1fV3Xh.js";import{f,i as p,m,o as h,p as g,s as _,u as v}from"./parts-5fVaWtRe.js";var y=class extends u{constructor(){super(...arguments),this.built=!1}connectedCallback(){c(()=>{this.isConnected&&(this.built||(this.built=!0,this.build()),this.update())})}attributeChangedCallback(e,t,n){this.built&&t!==n&&this.update()}},b=class extends y{build(){let e=f(this,`icon`)[0];if(this.box=document.createElement(`span`),e){let t=document.createElement(`span`);t.className=`k-badge__icon`,t.setAttribute(`aria-hidden`,`true`),t.append(e),this.box.append(t)}this.text=document.createElement(`span`),this.text.style.display=`contents`,this.text.append(...this.childNodes),this.box.append(this.text),this.append(this.box),this.box.addEventListener(`click`,e=>{if(!e.target.closest(`.k-badge__remove`))return;let t=new CustomEvent(`kashi-remove`,{bubbles:!0,cancelable:!0,detail:{value:this.text.textContent?.trim()??``}});this.dispatchEvent(t)&&this.remove()})}update(){let e=this.getAttribute(`tone`)??`neutral`,n=this.getAttribute(`variant`)??`soft`,i=this.getAttribute(`size`)??`md`,a=t(this,`removable`);this.box.className=p(`k-badge`,e!==`neutral`&&`k-badge--${e}`,n!==`soft`&&`k-badge--${n}`,i!==`md`&&`k-badge--${i}`,t(this,`square`)&&`k-badge--square`,a&&`k-badge--removable`),this.box.dataset.tone=e,this.box.dataset.variant=n;let o=this.box.querySelector(`:scope > .k-badge__dot`);t(this,`dot`)&&!o?this.box.insertAdjacentHTML(`afterbegin`,`<span class="k-badge__dot" aria-hidden="true"></span>`):t(this,`dot`)||o?.remove();let c=this.box.querySelector(`:scope > .k-badge__remove`);if(a){let e=this.text.textContent?.trim()??``,t=this.getAttribute(`remove-label`)??(e?s().common.remove(e):s().common.removeShort);c?c.setAttribute(`aria-label`,t):this.box.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-badge__remove" aria-label="${r(t)}"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="m6 6 8 8M14 6l-8 8"/></svg></button>`)}else c?.remove()}};b.observedAttributes=[`tone`,`variant`,`size`,`dot`,`square`,`removable`,`remove-label`];const x=[`brand`,`info`,`success`,`warning`,`error`],S=(e,t=2)=>e.trim().split(/\s+/).slice(0,t).map(e=>e[0]??``).join(``).toUpperCase();function C(e){let t=0;for(let n of e.trim())t=t*31+n.codePointAt(0)>>>0;return x[t%x.length]}var w=class extends u{constructor(){super(...arguments),this.failed=!1}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&(e===`src`&&(this.failed=!1),this.render())}render(){let e=this.getAttribute(`name`)??``,n=this.getAttribute(`size`)??`md`,i=this.getAttribute(`color`),a=i===`auto`?C(e):i??(t(this,`brand`)?`brand`:`neutral`),o=this.getAttribute(`status`),c=o?this.getAttribute(`status-label`)??s().avatar[o]:null,l=this.getAttribute(`src`),u=c?`${e}${s().common.list}${c}`:e,d=l&&!this.failed?`<img class="k-avatar__image" src="${r(l)}" alt="">`:`<span aria-hidden="true">${r(S(e,n===`xs`||n===`sm`?1:2))}</span>`;this.innerHTML=`<span role="img" aria-label="${r(u)}" data-tone="${a}" class="${p(`k-avatar`,n!==`md`&&`k-avatar--${n}`,t(this,`square`)&&`k-avatar--square`,a!==`neutral`&&`k-avatar--${a}`)}">${d}${o?`<span class="k-avatar__status k-avatar__status--${o}" aria-hidden="true"></span>`:``}</span>`,this.querySelector(`img`)?.addEventListener(`error`,()=>{this.failed=!0,this.render()},{once:!0})}};w.observedAttributes=[`name`,`src`,`size`,`square`,`brand`,`color`,`status`,`status-label`];var T=class extends y{build(){this.box=document.createElement(`div`),this.box.setAttribute(`role`,`group`),this.box.className=`k-avatar-group`,this.box.append(...this.childNodes),this.append(this.box)}update(){this.box.querySelector(`:scope > [data-more]`)?.remove();let e=[...this.box.children].filter(e=>e.tagName===`KASHI-AVATAR`||e.classList.contains(`k-avatar`)),t=v(this,`max`);e.forEach((e,n)=>e.hidden=!!t&&n>=t);let n=t?Math.max(0,e.length-t):0;if(!n)return;let a=this.getAttribute(`size`)??`md`,o=this.getAttribute(`more-label`)?.replace(`{n}`,i(this,n))??s().avatar.more(i(this,n));this.box.insertAdjacentHTML(`beforeend`,`<span data-more role="img" aria-label="${r(o)}" class="${p(`k-avatar`,a!==`md`&&`k-avatar--${a}`)}"><span aria-hidden="true">+${i(this,n)}</span></span>`)}};T.observedAttributes=[`max`,`size`,`more-label`];var E=class extends u{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=this.getAttribute(`label`),n=t(this,`vertical`);this.innerHTML=`<div role="separator"${n?` aria-orientation="vertical"`:``} class="${p(`k-divider`,n&&`k-divider--vertical`)}">${e?`<span>${r(e)}</span>`:``}</div>`}};E.observedAttributes=[`label`,`vertical`];const D=e=>e===null?null:/^\d+(\.\d+)?$/.test(e)?`${e}px`:e;var O=class extends u{connectedCallback(){this.render()}attributeChangedCallback(){this.isConnected&&this.render()}render(){let e=D(this.getAttribute(`width`)),n=t(this,`circle`),i=D(this.getAttribute(`height`))??(n?e:null),a=[e&&`--k-skeleton-width: ${e}`,i&&`--k-skeleton-height: ${i}`].filter(Boolean).join(`; `),o=a?` style="${r(a)}"`:``,s=v(this,`lines`,0);this.innerHTML=s>0?`<span class="k-skeleton-group" aria-hidden="true"${o}>${`<span class="k-skeleton k-skeleton--text"></span>`.repeat(Math.min(50,s))}</span>`:`<span class="${p(`k-skeleton`,n&&`k-skeleton--circle`)}" aria-hidden="true"${o}></span>`}};O.observedAttributes=[`width`,`height`,`circle`,`lines`];var k=class extends y{build(){let e=f(this,`media`),t=f(this,`actions`),n=f(this,`footer`),r=m(this);this.box=document.createElement(`article`);for(let t of e)t.classList.add(`k-card__media`),t instanceof HTMLImageElement&&!t.style.aspectRatio&&(t.style.aspectRatio=`16 / 9`),this.box.append(t);if(this.header=document.createElement(`header`),this.header.innerHTML=`<div class="k-card__heading"></div>`,t.length){let e=document.createElement(`div`);e.className=`k-card__actions`,e.append(...t),this.header.append(e)}if(this.box.append(this.header),h(r)){let e=document.createElement(`div`);e.className=`k-card__body`,e.append(...r),this.box.append(e)}if(n.length){let e=document.createElement(`footer`);e.className=`k-card__footer`,e.append(...n),this.box.append(e)}this.append(this.box)}update(){let e=this.getAttribute(`variant`)??`outlined`,n=this.getAttribute(`padding`)??`md`;this.box.className=p(`k-card`,t(this,`flat`)&&`k-card--flat`,t(this,`interactive`)&&`k-card--interactive`,e!==`outlined`&&`k-card--${e}`,n!==`md`&&`k-card--pad-${n}`),this.box.dataset.variant=e;let i=this.getAttribute(`heading`),a=this.getAttribute(`description`),o=!!this.header.querySelector(`.k-card__actions`);this.header.className=p(`k-card__header`,o&&`k-card__header--actions`),this.header.hidden=!i&&!a&&!o;let s=Math.min(6,Math.max(1,v(this,`heading-level`,3))),c=this.header.querySelector(`.k-card__heading`);c.innerHTML=`${i?`<h${s} class="k-card__title">${r(i)}</h${s}>`:``}${a?`<p class="k-card__description">${r(a)}</p>`:``}`}};k.observedAttributes=[`heading`,`description`,`heading-level`,`variant`,`padding`,`flat`,`interactive`];const A=e=>_(e,1.5),j={noData:A(`<path d="M7.25 2.75h5.5c3.6 0 4.5.9 4.5 4.5v5.5c0 3.6-.9 4.5-4.5 4.5h-5.5c-3.6 0-4.5-.9-4.5-4.5v-5.5c0-3.6.9-4.5 4.5-4.5Z"/><path d="M2.75 10.75h3.1c.55 0 1 .3 1.25.75l.5.95c.25.45.7.75 1.25.75h2.3c.55 0 1-.3 1.25-.75l.5-.95c.25-.45.7-.75 1.25-.75h3.1"/>`),noResults:A(`<circle cx="9.1" cy="9.1" r="6.2"/><path d="m14.9 14.9 2.3 2.3M7.2 7.2l3.8 3.8M11 7.2l-3.8 3.8"/>`),error:A(`<path d="M8.33 3.9c.74-1.3 2.6-1.3 3.34 0l5.6 9.75c.74 1.3-.2 2.85-1.67 2.85H4.4c-1.48 0-2.41-1.56-1.67-2.85Z"/><path d="M10 7.9v3.1M10 13.6v.01"/>`),offline:A(`<path d="M2.75 7.6a10.5 10.5 0 0 1 14.5 0M5.2 10.3a7 7 0 0 1 9.6 0M7.7 12.95a3.5 3.5 0 0 1 4.6 0M10 15.75v.01"/><path d="m3 3 14 14"/>`),noAccess:A(`<path d="M7.25 8.25h5.5c2.6 0 3.25.65 3.25 3.25v2.75c0 2.6-.65 3.25-3.25 3.25h-5.5C4.65 17.5 4 16.85 4 14.25V11.5c0-2.6.65-3.25 3.25-3.25Z"/><path d="M6.9 8.3V6.4a3.1 3.1 0 0 1 6.2 0v1.9M10 11.6v2.2"/>`),done:A(`<circle cx="10" cy="10" r="7.25"/><path d="m6.75 10.1 2.2 2.2 4.3-4.5"/>`)},M=[`noData`,`noResults`,`error`,`offline`,`noAccess`,`done`],N=e=>{if(!e)return null;let t=e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());return M.includes(t)?t:null};var P=class extends y{constructor(){super(...arguments),this.customIcon=null,this.actions=null}build(){this.customIcon=f(this,`icon`)[0]??null;let e=f(this,`actions`);this.box=document.createElement(`div`),this.box.innerHTML=`<span class="k-empty__icon" aria-hidden="true"></span><p class="k-empty__title"></p><p class="k-empty__description"></p>`,this.customIcon&&this.box.firstElementChild.append(this.customIcon);let t=m(this);(e.length||h(t))&&(this.actions=document.createElement(`div`),this.actions.className=`k-empty__actions`,this.actions.append(...e,...h(t)?t:[]),this.box.append(this.actions)),this.replaceChildren(this.box)}update(){let e=N(this.getAttribute(`preset`)),n=this.getAttribute(`size`)??`md`,r=e?s().empty[e]:void 0;this.box.className=p(`k-empty`,n!==`md`&&`k-empty--${n}`,t(this,`bordered`)&&`k-empty--bordered`),e?this.box.dataset.preset=e:delete this.box.dataset.preset,e===`error`||e===`offline`?this.box.setAttribute(`role`,`status`):this.box.removeAttribute(`role`);let i=this.box.querySelector(`.k-empty__icon`);this.customIcon||(i.innerHTML=e?j[e]:``),i.hidden=!i.firstChild;let a=this.getAttribute(`heading`)??r?.[0]??``,o=this.getAttribute(`description`)??r?.[1]??``,c=this.box.querySelector(`.k-empty__title`),l=this.box.querySelector(`.k-empty__description`);c.textContent=a,c.hidden=!a,l.textContent=o,l.hidden=!o}};P.observedAttributes=[`preset`,`heading`,`description`,`size`,`bordered`];const F=e=>_(e?`<path d="M10 15V5m0 0-4 4m4-4 4 4"/>`:`<path d="M10 5v10m0 0-4-4m4 4 4-4"/>`,1.8);var I=class extends y{build(){let e=f(this,`icon`)[0],t=m(this);if(this.box=document.createElement(`div`),this.box.className=`k-stat`,this.box.innerHTML=`<div class="k-stat__head"><p class="k-stat__label"></p></div><p class="k-stat__value"><span></span><span class="k-stat__unit"></span></p><div class="k-stat__foot"></div>`,e){let t=document.createElement(`span`);t.className=`k-stat__icon`,t.setAttribute(`aria-hidden`,`true`),t.append(e),this.box.firstElementChild.prepend(t)}if(h(t)){let e=document.createElement(`div`);e.className=`k-stat__chart`,e.append(...t),this.box.append(e)}this.replaceChildren(this.box)}update(){let e=s(),n=v(this,`change`);this.box.querySelector(`.k-stat__label`).textContent=this.getAttribute(`label`)??``;let a=this.getAttribute(`value`)??``;this.box.querySelector(`.k-stat__value > span`).textContent=/^-?[\d.,]+$/.test(a)?i(this,a):a;let o=this.box.querySelector(`.k-stat__unit`);o.textContent=this.getAttribute(`unit`)??``,o.hidden=!o.textContent,t(this,`loading`)?this.box.setAttribute(`aria-busy`,`true`):this.box.removeAttribute(`aria-busy`);let c=n===void 0?null:n>0?`up`:n<0?`down`:`flat`,l=c===`flat`?`flat`:c===`up`===t(this,`invert-trend`)?`down`:`up`,u=this.getAttribute(`up-label`)??e.stat.up,d=this.getAttribute(`down-label`)??e.stat.down,f=this.getAttribute(`flat-label`)??e.stat.flat,p=n===void 0?``:e.common.percent(i(this,Math.abs(Math.round(n*10)/10)).replace(`.`,e.common.decimal)),m=this.getAttribute(`caption`),h=this.box.querySelector(`.k-stat__foot`);h.hidden=!c&&!m,h.innerHTML=`${c?`<span class="k-trend k-trend--${l}">${c===`flat`?``:F(c===`up`)}<span aria-hidden="true">${r(c===`flat`?f:p)}</span><span class="k-sr-only">${r(c===`flat`?f:`${p} ${c===`up`?u:d}`)}</span></span>`:``}${m?`<span>${r(m)}</span>`:``}`}};I.observedAttributes=[`label`,`value`,`unit`,`change`,`invert-trend`,`caption`,`loading`,`up-label`,`down-label`,`flat-label`];const L={neutral:a.info,brand:a.info,info:a.info,success:a.success,warning:a.warning,error:a.error};var R=class extends y{constructor(){super(...arguments),this.customIcon=null}build(){this.customIcon=f(this,`icon`)[0]??null;let e=f(this,`actions`),t=m(this);this.box=document.createElement(`div`),this.box.innerHTML=`<span class="k-alert__icon" aria-hidden="true"></span><div class="k-alert__content"><p class="k-alert__title"></p></div>`;let n=this.box.querySelector(`.k-alert__content`);if(h(t)){let e=document.createElement(`div`);e.className=`k-alert__description`,e.append(...t),n.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-alert__actions`,t.append(...e),n.append(t)}this.customIcon&&this.box.firstElementChild.append(this.customIcon),this.replaceChildren(this.box),this.box.addEventListener(`click`,e=>{e.target.closest(`.k-alert__close`)&&this.close()})}update(){let e=this.getAttribute(`tone`)??`neutral`;this.box.className=p(`k-alert`,e!==`neutral`&&`k-alert--${e}`,t(this,`tinted`)&&`k-alert--tinted`,this.getAttribute(`layout`)===`banner`&&`k-alert--banner`,this.getAttribute(`size`)===`sm`&&`k-alert--sm`),this.box.dataset.tone=e,this.box.setAttribute(`role`,e===`error`||e===`warning`?`alert`:`status`);let n=this.box.querySelector(`.k-alert__icon`);n.hidden=this.getAttribute(`icon`)===`false`,this.customIcon||(n.innerHTML=L[e]??a.info);let r=this.box.querySelector(`.k-alert__title`);r.textContent=this.getAttribute(`heading`)??``,r.hidden=!r.textContent;let i=this.box.querySelector(`:scope > .k-alert__close`);t(this,`dismissible`)?(i||=(this.box.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-alert__close">${a.close}</button>`),this.box.querySelector(`:scope > .k-alert__close`)),i.setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().alert.close)):i?.remove()}close(){let e=new CustomEvent(`kashi-close`,{bubbles:!0,cancelable:!0,detail:{}});this.dispatchEvent(e)&&(this.hidden=!0)}};R.observedAttributes=[`tone`,`heading`,`tinted`,`layout`,`size`,`dismissible`,`close-label`,`icon`];var z=class extends u{constructor(){super(...arguments),this.box=null}connectedCallback(){this.box||(this.box=document.createElement(`div`),this.box.className=`k-meter`,this.box.innerHTML=`<div class="k-meter__head"><span class="k-meter__label"></span><span class="k-meter__value"></span></div><div class="k-meter__track" role="meter" aria-valuemin="0"><span class="k-meter__fill"></span><span class="k-meter__mark" aria-hidden="true"></span></div><p class="k-meter__status" aria-hidden="true"></p>`,this.replaceChildren(this.box)),this.update()}attributeChangedCallback(){this.box&&this.update()}update(){let e=s(),t=v(this,`max`,100)||100,a=v(this,`warning`,t*.8),o=v(this,`critical`,t*.95),c=Math.min(t,Math.max(0,v(this,`value`,0))),u=c>=o?`critical`:c>=a?`warning`:`ok`,d=Math.round(c/t*100),f=this.getAttribute(`${u}-label`)??e.meter[u],p=this.getAttribute(`unit`),m=e=>`${n(Math.round(e*100)/100,{digits:l(this)})}${p?` ${p}`:``}`,h=this.getAttribute(`of`),g=this.getAttribute(`label`)??``,y=this.box;y.dataset.status=u,y.querySelector(`.k-meter__label`).textContent=g,y.querySelector(`.k-meter__value`).innerHTML=`${r(m(c))} <span>${r(h==null?s().common.of(``,m(t)).trim():`${h} ${m(t)}`)}</span>`;let b=y.querySelector(`.k-meter__track`);b.setAttribute(`aria-valuenow`,String(c)),b.setAttribute(`aria-valuemax`,String(t)),b.setAttribute(`aria-valuetext`,`${h?`${m(c)} ${h} ${m(t)}`:e.common.of(m(c),m(t))}${e.common.list}${e.common.percent(i(this,d))}${e.common.list}${f}`),g&&b.setAttribute(`aria-label`,g),y.querySelector(`.k-meter__fill`).style.inlineSize=`${d}%`,y.querySelector(`.k-meter__mark`).style.insetInlineStart=`${a/t*100}%`,y.querySelector(`.k-meter__status`).innerHTML=`${_(`<path d="${u===`ok`?`m5 10.5 3.2 3L15 7`:`M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01`}"/>`,1.8)}${r(f)} · ${r(e.common.percent(i(this,d)))}`}};z.observedAttributes=[`label`,`value`,`max`,`warning`,`critical`,`unit`,`of`,`ok-label`,`warning-label`,`critical-label`,`digits`];var B=class extends u{constructor(){super(...arguments),this.kind=``}connectedCallback(){this.update()}attributeChangedCallback(){this.isConnected&&this.update()}update(){let e=s(),n=v(this,`max`,100)||100,r=v(this,`value`),a=r===void 0?void 0:Math.max(0,Math.min(100,r/n*100)),o=a===void 0?void 0:e.common.percent(i(this,Math.round(a))),c=this.getAttribute(`label`),l=this.getAttribute(`size`)??`md`,u=this.getAttribute(`tone`)??`brand`,d=this.getAttribute(`variant`)===`circular`,f=t(this,`show-value`),m=`${d}-${!!c}`;m!==this.kind&&(this.kind=m,this.innerHTML=d?`<div role="progressbar" aria-valuemin="0"><svg viewBox="0 0 40 40" aria-hidden="true"><circle class="k-progress-ring__track" cx="20" cy="20" r="16"/><circle class="k-progress-ring__bar" cx="20" cy="20" r="16"/></svg><span class="k-progress-ring__value" aria-hidden="true"></span></div>`:`${c?`<div class="k-progress-field"><div class="k-progress-field__head" aria-hidden="true"><span class="k-progress-field__label"></span><span class="k-progress-field__value"></span></div>`:``}<div role="progressbar" aria-valuemin="0"><div class="k-progress__bar"></div></div>${c?`</div>`:``}`);let h=this.querySelector(`[role="progressbar"]`);h.setAttribute(`aria-valuemax`,String(n));for(let[e,t]of[[`aria-valuenow`,r===void 0?null:String(r)],[`aria-valuetext`,o??null],[`aria-label`,this.getAttribute(`aria-label`)??c]])t===null?h.removeAttribute(e):h.setAttribute(e,t);if(d){let e=2*Math.PI*16;h.className=p(`k-progress-ring`,l!==`md`&&`k-progress-ring--${l}`,u!==`brand`&&`k-progress--${u}`,a===void 0&&`k-progress-ring--indeterminate`);let t=h.querySelector(`.k-progress-ring__bar`);t.setAttribute(`stroke-dasharray`,String(e)),t.setAttribute(`stroke-dashoffset`,String(a===void 0?e*.7:e*(1-a/100)));let n=h.querySelector(`.k-progress-ring__value`);n.textContent=f&&o?o:``,n.hidden=!n.textContent;return}h.className=p(`k-progress`,l!==`md`&&`k-progress--${l}`,u!==`brand`&&`k-progress--${u}`);let g=h.querySelector(`.k-progress__bar`);if(a===void 0?g.style.removeProperty(`--k-value`):g.style.setProperty(`--k-value`,`${a}%`),c){this.querySelector(`.k-progress-field__label`).textContent=c;let e=this.querySelector(`.k-progress-field__value`);e.textContent=f&&o?o:``,e.hidden=!e.textContent}}};B.observedAttributes=[`value`,`max`,`label`,`show-value`,`size`,`tone`,`variant`,`aria-label`];const V=/^\d{4}-\d{2}-\d{2}([T ][\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/;var H=class extends u{constructor(){super(...arguments),this.list=null,this.data=[],this.timer=null}connectedCallback(){c(()=>{this.isConnected&&(this.list||(this.data.length||(this.data=[...this.children].filter(e=>e.hasAttribute(`data-title`)).map(e=>{let t=e;return{item:{title:t.dataset.title??``,time:t.dataset.time,tone:t.dataset.tone},nodes:[...t.childNodes]}})),this.list=document.createElement(`ol`),this.list.className=`k-timeline`,this.replaceChildren(this.list)),this.render(),this.list.querySelector(`time[data-iso]`)&&(this.timer??=setInterval(()=>this.refreshTimes(),6e4)))})}disconnectedCallback(){this.timer&&clearInterval(this.timer),this.timer=null}attributeChangedCallback(){this.list&&this.render()}get items(){return this.data.map(e=>e.item)}set items(e){this.data=(e??[]).map(e=>({item:e,nodes:[]})),this.list&&this.render()}timeText(t){if(!V.test(t))return t;let n=g(t);return n?d(n,{locale:e(),digits:l(this)}):t}refreshTimes(){this.list?.querySelectorAll(`time[data-iso]`).forEach(e=>e.textContent=this.timeText(e.dateTime))}render(){let e=this.list;e.replaceChildren();for(let{item:t,nodes:n}of this.data){let i=document.createElement(`li`);i.className=`k-timeline__item`,t.tone&&t.tone!==`neutral`&&(i.dataset.tone=t.tone);let a=t.time?V.test(t.time)?`<time class="k-timeline__time" data-iso datetime="${r(t.time)}">${r(this.timeText(t.time))}</time>`:`<span class="k-timeline__time">${r(t.time)}</span>`:``;if(i.innerHTML=`<span class="k-timeline__marker" aria-hidden="true"><svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="3" fill="currentColor"/></svg></span><div class="k-timeline__body"><p class="k-timeline__title">${r(t.title)}</p>${a}</div>`,h(n)||t.content){let e=document.createElement(`div`);e.className=`k-timeline__content`,h(n)?e.append(...n):e.textContent=t.content,i.querySelector(`.k-timeline__body`).append(e)}e.append(i)}}};H.observedAttributes=[`digits`];const U=_(`<path d="m5 10.5 3.2 3L15 7"/>`,2.2);var W=class extends u{constructor(){super(...arguments),this.list=null,this.data=[]}connectedCallback(){c(()=>{this.isConnected&&(this.list||(!this.data.length&&!this.hasAttribute(`steps`)&&(this.data=[...this.children].filter(e=>e.tagName===`LI`).map(e=>({title:e.textContent?.trim()??``,description:e.dataset.description}))),this.list=document.createElement(`ol`),this.replaceChildren(this.list)),this.render())})}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`steps`&&(this.data=[]),this.render())}get steps(){return this.data.length?this.data:this.parsed()}set steps(e){this.data=[...e??[]],this.list&&this.render()}get current(){return v(this,`current`,0)}set current(e){this.setAttribute(`current`,String(e))}parsed(){try{let e=JSON.parse(this.getAttribute(`steps`)??`[]`);return Array.isArray(e)?e.map(e=>typeof e==`string`?{title:e}:e):[]}catch{return[]}}render(){let e=s(),t=this.list,n=this.steps,a=this.current;t.className=p(`k-steps`,this.getAttribute(`orientation`)===`vertical`&&`k-steps--vertical`),t.setAttribute(`aria-label`,this.getAttribute(`label`)??e.stepper.label);let o=this.getAttribute(`complete-label`)??e.stepper.complete,c=this.getAttribute(`current-label`)??e.stepper.current;t.innerHTML=n.map((t,n)=>{let s=n<a?`complete`:n===a?`current`:`upcoming`;return`<li class="k-steps__step" data-status="${s}"${s===`current`?` aria-current="step"`:``}><span class="k-steps__marker" aria-hidden="true">${s===`complete`?U:i(this,n+1)}</span><span class="k-steps__title">${r(t.title)}${s===`upcoming`?``:`<span class="k-sr-only">${r(`${e.common.list}${s===`complete`?o:c}`)}</span>`}</span>${t.description?`<span class="k-steps__description">${r(t.description)}</span>`:``}</li>`}).join(``)}};W.observedAttributes=[`current`,`orientation`,`label`,`steps`,`complete-label`,`current-label`,`digits`],o(`kashi-badge`,b),o(`kashi-avatar`,w),o(`kashi-avatar-group`,T),o(`kashi-divider`,E,`contents`),o(`kashi-skeleton`,O),o(`kashi-card`,k,`block`),o(`kashi-empty-state`,P,`block`),o(`kashi-stat-card`,I,`block`),o(`kashi-alert`,R,`block`),o(`kashi-meter`,z,`block`),o(`kashi-progress`,B,`block`),o(`kashi-timeline`,H,`block`),o(`kashi-stepper`,W,`block`);export{R as KashiAlert,w as KashiAvatar,T as KashiAvatarGroup,b as KashiBadge,k as KashiCard,E as KashiDivider,P as KashiEmptyState,z as KashiMeter,B as KashiProgress,O as KashiSkeleton,I as KashiStatCard,W as KashiStepper,H as KashiTimeline,C as autoTone,S as initials};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e,l as t,n,o as r,p as i,t as a}from"./base-D4tCOysh.js";let o=1;function s(){let e=document.querySelectorAll(`kashi-toaster`);if(e.length)return e[e.length-1];let t=document.createElement(`kashi-toaster`);return document.body.append(t),t}function c(e){let t=e.id??o++;return s().upsert({...e,id:t}),t}function l(e){return c(typeof e==`string`?{title:e}:e)}l.success=(e,t={})=>l({...t,title:e,tone:`success`}),l.error=(e,t={})=>l({...t,title:e,tone:`error`}),l.warning=(e,t={})=>l({...t,title:e,tone:`warning`}),l.info=(e,t={})=>l({...t,title:e,tone:`info`}),l.dismiss=e=>document.querySelectorAll(`kashi-toaster`).forEach(t=>t.dismiss(e)),l.promise=(e,t)=>{let n=c({title:t.loading,tone:`info`,duration:1/0,loading:!0});return e.then(e=>c({id:n,title:typeof t.success==`function`?t.success(e):t.success,tone:`success`}),e=>c({id:n,title:typeof t.error==`function`?t.error(e):t.error,tone:`error`})),e};var u=class extends a{constructor(){super(...arguments),this.list=null}connectedCallback(){this.list||=(this.innerHTML=`<section><ol class="k-toaster" aria-live="polite"></ol></section>`,this.querySelector(`ol`)),this.decorate()}attributeChangedCallback(){this.list&&this.decorate()}decorate(){let e=this.getAttribute(`placement`)??`bottom-end`;this.list.className=`k-toaster k-toaster--${e}`,this.list.dataset.placement=e,this.querySelector(`section`).setAttribute(`aria-label`,this.getAttribute(`label`)??i().toast.region)}upsert(e){this.list||this.connectedCallback();let t=[...this.list.children].find(t=>t.toastId===e.id),n=d(e,this.getAttribute(`close-label`)??i().toast.close,()=>this.dismiss(e.id));t?(t.stop?.(),t.replaceWith(n)):this.list.append(n);let r=Number(this.getAttribute(`max`))||5;for(;this.list.children.length>r;)this.list.firstElementChild.stop?.(),this.list.firstElementChild.remove()}dismiss(e){let t=[...this.list?.children??[]].find(t=>t.toastId===e);t&&t.dataset.state!==`closing`&&(t.stop?.(),t.dataset.state=`closing`,setTimeout(()=>t.remove(),200))}};u.observedAttributes=[`placement`,`label`];function d(e,r,i){let a=e.duration??(e.action?1/0:5e3),o=e.tone??`neutral`,s=document.createElement(`li`);s.toastId=e.id,s.className=`k-toast${o===`neutral`?``:` k-toast--${o}`}`,s.dataset.state=`open`,s.setAttribute(`role`,o===`error`?`alert`:`status`),s.innerHTML=`<span class="k-toast__icon" aria-hidden="true">${e.loading?`<span class="k-spinner k-spinner--sm" style="color: inherit"></span>`:n[o===`neutral`?`info`:o]}</span><div class="k-toast__content"><p class="k-toast__title">${t(e.title)}</p>${e.description?`<p class="k-toast__description">${t(e.description)}</p>`:``}${e.action?`<button type="button" class="k-btn k-btn--link k-toast__action">${t(e.action.label)}</button>`:``}</div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-toast__close" aria-label="${t(r)}">${n.close}</button>${Number.isFinite(a)?`<span class="k-toast__progress" aria-hidden="true" style="animation-duration: ${a}ms"></span>`:``}`,s.querySelector(`.k-toast__close`).addEventListener(`click`,i),s.querySelector(`.k-toast__action`)?.addEventListener(`click`,()=>{e.action.onClick(),i()}),s.addEventListener(`keydown`,e=>e.key===`Escape`&&i());let c=a,l=0,u,d=()=>{u===void 0&&Number.isFinite(c)&&(l=Date.now(),u=setTimeout(i,c))},f=()=>{u!==void 0&&(clearTimeout(u),u=void 0,c-=Date.now()-l)};return s.addEventListener(`mouseenter`,f),s.addEventListener(`focusin`,f),s.addEventListener(`mouseleave`,d),s.addEventListener(`focusout`,d),s.stop=()=>{clearTimeout(u),c=1/0},d(),s}r(`kashi-toaster`,u),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-toast]`);t&&l({title:t.dataset.kashiToast,description:t.dataset.description,tone:t.dataset.tone??`neutral`})});const f=/* @__PURE__ */ new Set([[[`kashi-national-id`,`kashi-legal-id`,`kashi-mobile`,`kashi-landline`,`kashi-card-number`,`kashi-iban`,`kashi-postal-code`,`kashi-price`,`kashi-sayad`,`kashi-economic-code`,`kashi-tax-id`],()=>import(`./inputs-BkJ70Xkc.js`)],[[`kashi-otp`],()=>import(`./fields-B-jTUQiI.js`)],[[`kashi-combobox`,`kashi-province-select`,`kashi-city-select`],()=>import(`./combobox-BGuPAAt3.js`).then(e=>e.t)],[[`kashi-iran-map`,`kashi-address-form`],()=>import(`./map-TfSt3CjL.js`)],[[`kashi-calendar`,`kashi-date-picker`],()=>import(`./calendar-BulPeVAJ.js`)],[[`kashi-time-picker`,`kashi-time-clock`],()=>import(`./time-CkqqUKJv.js`)],[[`kashi-money`,`kashi-date`,`kashi-relative-time`,`kashi-countdown`],()=>import(`./display-BfYWAjNu.js`)],[[`kashi-dialog`,`kashi-tabs`,`kashi-tooltip`,`kashi-copy-button`],()=>import(`./overlay-
|
|
1
|
+
import{g as e,l as t,n,o as r,p as i,t as a}from"./base-D4tCOysh.js";let o=1;function s(){let e=document.querySelectorAll(`kashi-toaster`);if(e.length)return e[e.length-1];let t=document.createElement(`kashi-toaster`);return document.body.append(t),t}function c(e){let t=e.id??o++;return s().upsert({...e,id:t}),t}function l(e){return c(typeof e==`string`?{title:e}:e)}l.success=(e,t={})=>l({...t,title:e,tone:`success`}),l.error=(e,t={})=>l({...t,title:e,tone:`error`}),l.warning=(e,t={})=>l({...t,title:e,tone:`warning`}),l.info=(e,t={})=>l({...t,title:e,tone:`info`}),l.dismiss=e=>document.querySelectorAll(`kashi-toaster`).forEach(t=>t.dismiss(e)),l.promise=(e,t)=>{let n=c({title:t.loading,tone:`info`,duration:1/0,loading:!0});return e.then(e=>c({id:n,title:typeof t.success==`function`?t.success(e):t.success,tone:`success`}),e=>c({id:n,title:typeof t.error==`function`?t.error(e):t.error,tone:`error`})),e};var u=class extends a{constructor(){super(...arguments),this.list=null}connectedCallback(){this.list||=(this.innerHTML=`<section><ol class="k-toaster" aria-live="polite"></ol></section>`,this.querySelector(`ol`)),this.decorate()}attributeChangedCallback(){this.list&&this.decorate()}decorate(){let e=this.getAttribute(`placement`)??`bottom-end`;this.list.className=`k-toaster k-toaster--${e}`,this.list.dataset.placement=e,this.querySelector(`section`).setAttribute(`aria-label`,this.getAttribute(`label`)??i().toast.region)}upsert(e){this.list||this.connectedCallback();let t=[...this.list.children].find(t=>t.toastId===e.id),n=d(e,this.getAttribute(`close-label`)??i().toast.close,()=>this.dismiss(e.id));t?(t.stop?.(),t.replaceWith(n)):this.list.append(n);let r=Number(this.getAttribute(`max`))||5;for(;this.list.children.length>r;)this.list.firstElementChild.stop?.(),this.list.firstElementChild.remove()}dismiss(e){let t=[...this.list?.children??[]].find(t=>t.toastId===e);t&&t.dataset.state!==`closing`&&(t.stop?.(),t.dataset.state=`closing`,setTimeout(()=>t.remove(),200))}};u.observedAttributes=[`placement`,`label`];function d(e,r,i){let a=e.duration??(e.action?1/0:5e3),o=e.tone??`neutral`,s=document.createElement(`li`);s.toastId=e.id,s.className=`k-toast${o===`neutral`?``:` k-toast--${o}`}`,s.dataset.state=`open`,s.setAttribute(`role`,o===`error`?`alert`:`status`),s.innerHTML=`<span class="k-toast__icon" aria-hidden="true">${e.loading?`<span class="k-spinner k-spinner--sm" style="color: inherit"></span>`:n[o===`neutral`?`info`:o]}</span><div class="k-toast__content"><p class="k-toast__title">${t(e.title)}</p>${e.description?`<p class="k-toast__description">${t(e.description)}</p>`:``}${e.action?`<button type="button" class="k-btn k-btn--link k-toast__action">${t(e.action.label)}</button>`:``}</div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-toast__close" aria-label="${t(r)}">${n.close}</button>${Number.isFinite(a)?`<span class="k-toast__progress" aria-hidden="true" style="animation-duration: ${a}ms"></span>`:``}`,s.querySelector(`.k-toast__close`).addEventListener(`click`,i),s.querySelector(`.k-toast__action`)?.addEventListener(`click`,()=>{e.action.onClick(),i()}),s.addEventListener(`keydown`,e=>e.key===`Escape`&&i());let c=a,l=0,u,d=()=>{u===void 0&&Number.isFinite(c)&&(l=Date.now(),u=setTimeout(i,c))},f=()=>{u!==void 0&&(clearTimeout(u),u=void 0,c-=Date.now()-l)};return s.addEventListener(`mouseenter`,f),s.addEventListener(`focusin`,f),s.addEventListener(`mouseleave`,d),s.addEventListener(`focusout`,d),s.stop=()=>{clearTimeout(u),c=1/0},d(),s}r(`kashi-toaster`,u),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-toast]`);t&&l({title:t.dataset.kashiToast,description:t.dataset.description,tone:t.dataset.tone??`neutral`})});const f=/* @__PURE__ */ new Set([[[`kashi-national-id`,`kashi-legal-id`,`kashi-mobile`,`kashi-landline`,`kashi-card-number`,`kashi-iban`,`kashi-postal-code`,`kashi-price`,`kashi-sayad`,`kashi-economic-code`,`kashi-tax-id`],()=>import(`./inputs-BkJ70Xkc.js`)],[[`kashi-otp`],()=>import(`./fields-B-jTUQiI.js`)],[[`kashi-combobox`,`kashi-province-select`,`kashi-city-select`],()=>import(`./combobox-BGuPAAt3.js`).then(e=>e.t)],[[`kashi-iran-map`,`kashi-address-form`],()=>import(`./map-TfSt3CjL.js`)],[[`kashi-calendar`,`kashi-date-picker`],()=>import(`./calendar-BulPeVAJ.js`)],[[`kashi-time-picker`,`kashi-time-clock`],()=>import(`./time-CkqqUKJv.js`)],[[`kashi-money`,`kashi-date`,`kashi-relative-time`,`kashi-countdown`],()=>import(`./display-BfYWAjNu.js`)],[[`kashi-dialog`,`kashi-tabs`,`kashi-tooltip`,`kashi-copy-button`],()=>import(`./overlay-CS8piW6X.js`)],[[`kashi-dropdown-menu`,`kashi-popover`],()=>import(`./menu-DTNVFXrb.js`)],[[`kashi-tag-input`,`kashi-number-input`,`kashi-rating`,`kashi-pagination`],()=>import(`./controls--OMZkJYe.js`)],[[`kashi-data-table`],()=>import(`./table-tgB4iwcM.js`)],[[`kashi-multi-select`,`kashi-slider`,`kashi-chip-group`,`kashi-password-strength`,`kashi-persian-textarea`,`kashi-keyboard-fix`,`kashi-time-input`,`kashi-plate-input`,`kashi-inline-edit`],()=>import(`./forms-DgRiYmdV.js`)],[[`kashi-date-range-picker`,`kashi-month-picker`,`kashi-file-upload`,`kashi-color-picker`],()=>import(`./pickers-BwDRsDRo.js`)],[[`kashi-bar-chart`,`kashi-line-chart`,`kashi-pie-chart`,`kashi-bar-list`,`kashi-proportion-bar`,`kashi-sparkline`,`kashi-activity-heatmap`],()=>import(`./charts-ETYOAJyB.js`)],[[`kashi-input`,`kashi-textarea`,`kashi-banner`],()=>import(`./basic-DuY4RslZ.js`)],[[`kashi-appointment-picker`],()=>import(`./appointment-DOXBUwIU.js`)],[[`kashi-price-range`,`kashi-swatch-group`,`kashi-search-suggest`],()=>import(`./commerce-SzWdpWJG.js`)],[[`kashi-command-palette`,`kashi-context-menu`,`kashi-carousel`,`kashi-tree-view`,`kashi-tour`,`kashi-splitter`,`kashi-side-nav`],()=>import(`./nav-CT5RVOzy.js`)],[[`kashi-badge`,`kashi-avatar`,`kashi-avatar-group`,`kashi-divider`,`kashi-skeleton`,`kashi-card`,`kashi-empty-state`,`kashi-stat-card`,`kashi-alert`,`kashi-meter`,`kashi-progress`,`kashi-timeline`,`kashi-stepper`],()=>import(`./content-DN3eXLg-.js`)],[[`kashi-button`,`kashi-button-group`,`kashi-segmented-control`,`kashi-breadcrumb`,`kashi-accordion`],()=>import(`./buttons-BaK6bx3w.js`)],[[`kashi-checkbox`,`kashi-switch`,`kashi-radio-group`,`kashi-select`],()=>import(`./choice-DBvC2Puo.js`)],[[`kashi-drawer`,`kashi-bottom-sheet`,`kashi-navbar`,`kashi-notification-list`,`kashi-notification-center`],()=>import(`./sheets-CVbD98PY.js`)],[[`kashi-chat`,`kashi-chat-message`,`kashi-typing-indicator`,`kashi-chat-composer`,`kashi-streaming-text`,`kashi-code-block`],()=>import(`./chat-D5ZIMnNp.js`)],[[`kashi-sortable`,`kashi-kanban`,`kashi-scheduler`],()=>import(`./work-DoNAKgVU.js`)],[[`kashi-gallery`,`kashi-qr-code`],()=>import(`./media-BRBINvzU.js`)],[[`kashi-rich-text`],()=>import(`./rich-text-CS6xEim6.js`)],[[`kashi-form`],()=>import(`./validate-Dr2f6i6s.js`)],[[`kashi-bank-card`,`kashi-receipt`,`kashi-date-tile`],()=>import(`./cards-DKarXHsC.js`)],[[`kashi-business-hours`],()=>import(`./hours-CeiVqPKD.js`)]]);function p(){for(let e of f)document.querySelector(e[0].join(`,`))&&(f.delete(e),e[1]().catch(e=>console.error(`[kashi] بارگذاری نشد:`,e)));f.size||h?.disconnect()}function m(){let e=[...f].map(([,e])=>e());return f.clear(),h?.disconnect(),Promise.all(e)}let h=null;typeof document<`u`&&(p(),h=new MutationObserver(p),h.observe(document.documentElement,{childList:!0,subtree:!0}));export{m as loadAll,e as setLocale,l as toast};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,c as t,h as n,i as r,l as i,n as a,o,p as s,r as c,t as l,y as u}from"./base-D4tCOysh.js";var d=class extends l{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=u(`kashi-dialog`)}connectedCallback(){c(()=>{this.isConnected&&(this.dialog||this.build(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.dialog?.open?this.dialog.close(e):this.open=!1}build(){let e=[...this.children].filter(e=>e.getAttribute(`slot`)===`footer`),n=[...this.childNodes].filter(t=>!e.includes(t)),i=document.createElement(`dialog`);if(i.setAttribute(`aria-labelledby`,`${this.key}-title`),i.innerHTML=`<div class="k-dialog__header"><div class="k-dialog__heading"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${a.close}</button></div>`,n.some(e=>e.nodeType===1||e.textContent?.trim())){let e=document.createElement(`div`);e.className=`k-dialog__body`,e.append(...n),i.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-dialog__footer`;for(let n of e)n.removeAttribute(`slot`),t.append(n);i.append(t)}this.replaceChildren(i),this.dialog=i,i.querySelector(`.k-dialog__close`).addEventListener(`click`,()=>this.close()),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close]`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:i.returnValue})}),this.decorate()}decorate(){let e=this.dialog,t=this.getAttribute(`size`)??`md`,n=this.getAttribute(`placement`)??`center`;e.className=[`k-dialog`,t!==`md`&&`k-dialog--${t}`,n!==`center`&&`k-dialog--${n}`,this.getAttribute(`tone`)===`danger`&&`k-dialog--danger`].filter(Boolean).join(` `),e.dataset.placement=n,e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let r=e.querySelector(`.k-dialog__description`),i=this.getAttribute(`description`);r.textContent=i??``,r.hidden=!i,i?e.setAttribute(`aria-describedby`,r.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`).setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().common.close)}sync(){let e=this.dialog;e&&this.isConnected&&(this.open&&!e.open?(this.opener=document.activeElement,e.showModal?.(),t(this,`kashi-open`,{})):!this.open&&e.open&&e.close())}};d.observedAttributes=[`open`,`heading`,`description`,`tone`,`size`,`placement`,`close-label`];var f=class extends l{constructor(){super(...arguments),this.list=null,this.key=u(`kashi-tabs`),this.ro=null}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){this.list||this.build(),this.decorate(),this.select(this.getAttribute(`value`)??this.panels[0]?.dataset.value??``,!1),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.list))}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`value`?this.select(n??``,!1):this.decorate())}get value(){return this.getAttribute(`value`)??``}set value(e){this.setAttribute(`value`,e)}get panels(){return[...this.children].filter(e=>e instanceof HTMLElement&&e.hasAttribute(`data-tab`))}build(){let e=document.createElement(`div`);e.setAttribute(`role`,`tablist`),e.className=`k-tabs__list`,this.panels.forEach((t,n)=>{let r=t.dataset.value||String(n+1);t.dataset.value=r;let i=document.createElement(`button`);i.type=`button`,i.setAttribute(`role`,`tab`),i.className=`k-tabs__tab`,i.id=`${this.key}-tab-${n}`,i.dataset.value=r,i.textContent=t.dataset.tab??``,t.hasAttribute(`data-disabled`)&&(i.disabled=!0),t.id||=`${this.key}-panel-${n}`,i.setAttribute(`aria-controls`,t.id),t.setAttribute(`role`,`tabpanel`),t.setAttribute(`aria-labelledby`,i.id),t.tabIndex=0,t.classList.add(`k-tabs__panel`),e.append(i)});let t=document.createElement(`span`);t.className=`k-tabs__indicator`,t.setAttribute(`aria-hidden`,`true`),e.append(t),e.addEventListener(`click`,e=>{let t=e.target.closest(`[role="tab"]`);t&&!t.disabled&&this.select(t.dataset.value,!0)}),e.addEventListener(`keydown`,e=>this.onKey(e)),this.prepend(e),this.list=e}decorate(){let e=this.getAttribute(`variant`)??`line`,t=this.getAttribute(`orientation`)===`vertical`;for(let e of[...this.classList])e.startsWith(`k-tabs`)&&this.classList.remove(e);this.classList.add(`k-tabs`,`k-tabs--${e}`),r(this,`block`)&&this.classList.add(`k-tabs--block`),t&&this.classList.add(`k-tabs--vertical`),this.getAttribute(`size`)===`sm`&&this.classList.add(`k-tabs--sm`),this.dataset.orientation=t?`vertical`:`horizontal`,this.list.setAttribute(`aria-orientation`,t?`vertical`:`horizontal`);let n=this.getAttribute(`label`);n&&this.list.setAttribute(`aria-label`,n),this.measure()}select(e,n){let r=[...this.list.querySelectorAll(`[role="tab"]`)];r.some(t=>t.dataset.value===e)||(e=r[0]?.dataset.value??``);for(let t of r){let n=t.dataset.value===e;t.setAttribute(`aria-selected`,String(n)),t.tabIndex=n?0:-1}for(let t of this.panels)t.hidden=t.dataset.value!==e;this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e),this.measure(),n&&t(this,`kashi-change`,{value:e})}measure(){let e=this.list,t=e?.querySelector(`[role="tab"][aria-selected="true"]`);!e||!t||!t.offsetWidth?e?.removeAttribute(`data-indicator`):(e.setAttribute(`data-indicator`,``),e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iy`,`${t.offsetTop}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.style.setProperty(`--_ih`,`${t.offsetHeight}px`))}onKey(e){let t=[...this.list.querySelectorAll(`[role="tab"]:not(:disabled)`)],n=t.indexOf(document.activeElement);if(n<0)return;let r=getComputedStyle(this.list).direction===`rtl`,i=this.getAttribute(`orientation`)===`vertical`?{ArrowDown:n+1,ArrowUp:n-1,Home:0,End:t.length-1}:{ArrowLeft:r?n+1:n-1,ArrowRight:r?n-1:n+1,Home:0,End:t.length-1};if(!(e.key in i))return;e.preventDefault();let a=t[(i[e.key]+t.length)%t.length];a.focus(),this.select(a.dataset.value,!0)}};f.observedAttributes=[`value`,`variant`,`block`,`orientation`,`size`,`label`];var p=class extends l{constructor(){super(...arguments),this.tip=null,this.key=u(`kashi-tip`),this.place=()=>n(this,this.tip,this.getAttribute(`placement`)||`top`),this.onKey=e=>{e.key===`Escape`&&(clearTimeout(this.timer),this.close())}}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){if(!this.tip){this.classList.add(`k-tooltip-anchor`);let e=document.createElement(`span`);e.setAttribute(`role`,`tooltip`),e.id=this.key,e.hidden=!0,e.setAttribute(`popover`,`manual`),this.append(e),this.tip=e;let t=this.firstElementChild===e?null:this.firstElementChild;t&&t.setAttribute(`aria-describedby`,[t.getAttribute(`aria-describedby`),this.key].filter(Boolean).join(` `)),this.addEventListener(`mouseenter`,()=>this.show(Number(this.getAttribute(`delay`)??300))),this.addEventListener(`mouseleave`,()=>this.hide()),this.addEventListener(`focusin`,()=>this.show(0)),this.addEventListener(`focusout`,()=>this.hide())}this.decorate()}disconnectedCallback(){clearTimeout(this.timer),this.close()}attributeChangedCallback(){this.tip&&this.decorate(),this.tip&&!this.tip.hidden&&this.place()}open(){let e=this.tip;e.hidden&&(e.hidden=!1,this.place(),document.addEventListener(`keydown`,this.onKey),addEventListener(`scroll`,this.place,{capture:!0,passive:!0}),addEventListener(`resize`,this.place))}close(){this.tip&&(this.tip.hidden=!0,e(this.tip),document.removeEventListener(`keydown`,this.onKey),removeEventListener(`scroll`,this.place,{capture:!0}),removeEventListener(`resize`,this.place))}decorate(){let e=this.getAttribute(`placement`);this.tip.className=`k-tooltip${e&&e!==`top`?` k-tooltip--${e}`:``}`,this.tip.textContent=this.getAttribute(`content`)??``}show(e){clearTimeout(this.timer),this.timer=setTimeout(()=>this.open(),e)}hide(){clearTimeout(this.timer),this.timer=setTimeout(()=>this.close(),100)}};p.observedAttributes=[`content`,`placement`];var m=class extends l{constructor(){super(...arguments),this.state=`idle`,this.built=!1}connectedCallback(){this.built||(this.built=!0,this.addEventListener(`click`,e=>{e.target.closest(`button`)&&this.copy()})),this.render()}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(){this.built&&this.render()}get text(){let e=this.getAttribute(`value`);if(e!==null)return e;let t=this.getAttribute(`target`),n=t?document.querySelector(t):null;return n?typeof n.value==`string`?n.value:(n.textContent??``).trim():``}async copy(){try{await navigator.clipboard.writeText(this.text),this.state=`copied`,t(this,`kashi-copy`,{value:this.text})}catch{this.state=`failed`}this.render(),clearTimeout(this.timer),this.timer=setTimeout(()=>{this.state=`idle`,this.render()},Number(this.getAttribute(`timeout`))||2e3)}render(){let e=this.getAttribute(`label`)??s().copy.copy,t=this.getAttribute(`copied-label`)??s().copy.copied,n=this.state===`copied`?t:this.state===`failed`?s().copy.failed:e,o=r(this,`icon-only`),c=this.state===`copied`?a.check:a.copy,l=this.getAttribute(`variant`)??`secondary`,u=this.getAttribute(`size`)??`sm`,d=this.contains(document.activeElement);this.innerHTML=`<button type="button" class="k-btn k-btn--${i(l)}${u===`md`?``:` k-btn--${i(u)}`}${o?` k-btn--icon`:``}" data-variant="${i(l)}" data-size="${i(u)}"${o?` aria-label="${i(n)}"`:``}${this.state===`copied`?` data-copied=""`:``}>${c}${o?``:i(n)}</button><span class="k-sr-only" aria-live="polite">${this.state===`idle`?``:i(n)}</span>`,d&&this.querySelector(`button`).focus()}};m.observedAttributes=[`value`,`target`,`label`,`copied-label`,`icon-only`,`variant`,`size`],o(`kashi-dialog`,d,`contents`),o(`kashi-tabs`,f,`block`),o(`kashi-tooltip`,p),o(`kashi-copy-button`,m),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(t){let n=document.getElementById(t.getAttribute(`data-kashi-open`));n?.show&&(e.preventDefault(),n.show())}});export{m as KashiCopyButton,d as KashiDialog,f as KashiTabs,p as KashiTooltip};
|
|
1
|
+
import{b as e,c as t,h as n,i as r,l as i,n as a,o,p as s,r as c,t as l,y as u}from"./base-D4tCOysh.js";var d=class extends l{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=u(`kashi-dialog`)}connectedCallback(){c(()=>{this.isConnected&&(this.dialog||this.build(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.dialog?.open?this.dialog.close(e):this.open=!1}build(){let e=[...this.children].filter(e=>e.getAttribute(`slot`)===`footer`),n=[...this.childNodes].filter(t=>!e.includes(t)),i=document.createElement(`dialog`);if(i.setAttribute(`aria-labelledby`,`${this.key}-title`),i.innerHTML=`<div class="k-dialog__header"><div class="k-dialog__heading"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div><button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${a.close}</button></div>`,n.some(e=>e.nodeType===1||e.textContent?.trim())){let e=document.createElement(`div`);e.className=`k-dialog__body`,e.append(...n),i.append(e)}if(e.length){let t=document.createElement(`div`);t.className=`k-dialog__footer`;for(let n of e)n.removeAttribute(`slot`),t.append(n);i.append(t)}this.replaceChildren(i),this.dialog=i,i.querySelector(`.k-dialog__close`).addEventListener(`click`,()=>this.close()),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close]`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:i.returnValue})}),this.decorate()}decorate(){let e=this.dialog,t=this.getAttribute(`size`)??`md`,n=this.getAttribute(`placement`)??`center`;e.className=[`k-dialog`,t!==`md`&&`k-dialog--${t}`,n!==`center`&&`k-dialog--${n}`,this.getAttribute(`tone`)===`danger`&&`k-dialog--danger`].filter(Boolean).join(` `),e.dataset.placement=n,e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let r=e.querySelector(`.k-dialog__description`),i=this.getAttribute(`description`);r.textContent=i??``,r.hidden=!i,i?e.setAttribute(`aria-describedby`,r.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`).setAttribute(`aria-label`,this.getAttribute(`close-label`)??s().common.close)}sync(){let e=this.dialog;e&&this.isConnected&&(this.open&&!e.open?(this.opener=document.activeElement,e.showModal?.(),t(this,`kashi-open`,{})):!this.open&&e.open&&e.close())}};d.observedAttributes=[`open`,`heading`,`description`,`tone`,`size`,`placement`,`close-label`];var f=class extends l{constructor(){super(...arguments),this.list=null,this.key=u(`kashi-tabs`),this.ro=null}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){this.list||this.build(),this.decorate(),this.select(this.getAttribute(`value`)??this.panels[0]?.dataset.value??``,!1),typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.measure()),this.ro.observe(this.list))}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}attributeChangedCallback(e,t,n){this.list&&t!==n&&(e===`value`?this.select(n??``,!1):this.decorate())}get value(){return this.getAttribute(`value`)??``}set value(e){this.setAttribute(`value`,e)}get panels(){return[...this.children].filter(e=>e instanceof HTMLElement&&e.hasAttribute(`data-tab`))}build(){let e=document.createElement(`div`);e.setAttribute(`role`,`tablist`),e.className=`k-tabs__list`,this.panels.forEach((t,n)=>{let r=t.dataset.value||String(n+1);t.dataset.value=r;let i=document.createElement(`button`);i.type=`button`,i.setAttribute(`role`,`tab`),i.className=`k-tabs__tab`,i.id=`${this.key}-tab-${n}`,i.dataset.value=r,i.textContent=t.dataset.tab??``,t.hasAttribute(`data-disabled`)&&(i.disabled=!0),t.id||=`${this.key}-panel-${n}`,i.setAttribute(`aria-controls`,t.id),t.setAttribute(`role`,`tabpanel`),t.setAttribute(`aria-labelledby`,i.id),t.tabIndex=0,t.classList.add(`k-tabs__panel`),e.append(i)});let t=document.createElement(`span`);t.className=`k-tabs__indicator`,t.setAttribute(`aria-hidden`,`true`),e.append(t),e.addEventListener(`click`,e=>{let t=e.target.closest(`[role="tab"]`);t&&!t.disabled&&this.select(t.dataset.value,!0)}),e.addEventListener(`keydown`,e=>this.onKey(e)),this.prepend(e),this.list=e}decorate(){let e=this.getAttribute(`variant`)??`line`,t=this.getAttribute(`orientation`)===`vertical`;for(let e of[...this.classList])e.startsWith(`k-tabs`)&&this.classList.remove(e);this.classList.add(`k-tabs`,`k-tabs--${e}`),r(this,`block`)&&this.classList.add(`k-tabs--block`),t&&this.classList.add(`k-tabs--vertical`),this.getAttribute(`size`)===`sm`&&this.classList.add(`k-tabs--sm`),this.dataset.orientation=t?`vertical`:`horizontal`,this.list.setAttribute(`aria-orientation`,t?`vertical`:`horizontal`);let n=this.getAttribute(`label`);n&&this.list.setAttribute(`aria-label`,n),this.measure()}select(e,n){let r=[...this.list.querySelectorAll(`[role="tab"]`)];r.some(t=>t.dataset.value===e)||(e=r[0]?.dataset.value??``);for(let t of r){let n=t.dataset.value===e;t.setAttribute(`aria-selected`,String(n)),t.tabIndex=n?0:-1}for(let t of this.panels)t.hidden=t.dataset.value!==e;this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e),this.measure(),n&&t(this,`kashi-change`,{value:e})}measure(){let e=this.list,t=e?.querySelector(`[role="tab"][aria-selected="true"]`);!e||!t||!t.offsetWidth?e?.removeAttribute(`data-indicator`):(e.setAttribute(`data-indicator`,``),e.style.setProperty(`--_ix`,`${t.offsetLeft}px`),e.style.setProperty(`--_iy`,`${t.offsetTop}px`),e.style.setProperty(`--_iw`,`${t.offsetWidth}px`),e.style.setProperty(`--_ih`,`${t.offsetHeight}px`))}onKey(e){let t=[...this.list.querySelectorAll(`[role="tab"]:not(:disabled)`)],n=t.indexOf(document.activeElement);if(n<0)return;let r=getComputedStyle(this.list).direction===`rtl`,i=this.getAttribute(`orientation`)===`vertical`?{ArrowDown:n+1,ArrowUp:n-1,Home:0,End:t.length-1}:{ArrowLeft:r?n+1:n-1,ArrowRight:r?n-1:n+1,Home:0,End:t.length-1};if(!(e.key in i))return;e.preventDefault();let a=t[(i[e.key]+t.length)%t.length];a.focus(),this.select(a.dataset.value,!0)}};f.observedAttributes=[`value`,`variant`,`block`,`orientation`,`size`,`label`];var p=class extends l{constructor(){super(...arguments),this.tip=null,this.key=u(`kashi-tip`),this.trigger=null,this.place=()=>n(this,this.tip,this.getAttribute(`placement`)||`top`),this.onKey=e=>{e.key===`Escape`&&(clearTimeout(this.timer),this.close())}}connectedCallback(){c(()=>this.isConnected&&this.setup())}setup(){if(!this.tip){this.classList.add(`k-tooltip-anchor`);let e=document.createElement(`span`);e.setAttribute(`role`,`tooltip`),e.id=this.key,e.hidden=!0,e.setAttribute(`popover`,`manual`),this.append(e),this.tip=e;let t=this.firstElementChild===e?null:this.firstElementChild;this.addEventListener(`mouseenter`,()=>this.show(Number(this.getAttribute(`delay`)??300))),this.trigger=t,this.addEventListener(`mouseleave`,()=>this.hide()),this.addEventListener(`focusin`,()=>this.show(0)),this.addEventListener(`focusout`,()=>this.hide())}this.decorate(),this.hasAttribute(`open`)&&this.open()}disconnectedCallback(){clearTimeout(this.timer),this.close()}attributeChangedCallback(e){this.tip&&(this.decorate(),(e===`open`||e===`disabled`)&&(this.hasAttribute(`open`)&&!this.hasAttribute(`disabled`)?this.open():this.close()),this.tip.hidden||this.place())}open(){let e=this.tip;e.hidden&&!this.hasAttribute(`disabled`)&&(e.hidden=!1,t(this,`kashi-toggle`,{open:!0}),this.place(),document.addEventListener(`keydown`,this.onKey),addEventListener(`scroll`,this.place,{capture:!0,passive:!0}),addEventListener(`resize`,this.place))}close(){this.tip&&(this.hasAttribute(`open`)&&!this.hasAttribute(`disabled`)&&this.isConnected||(this.tip.hidden||t(this,`kashi-toggle`,{open:!1}),this.tip.hidden=!0,e(this.tip),document.removeEventListener(`keydown`,this.onKey),removeEventListener(`scroll`,this.place,{capture:!0}),removeEventListener(`resize`,this.place)))}decorate(){let e=this.tip,t=this.getAttribute(`placement`),n=this.getAttribute(`heading`),r=this.getAttribute(`shortcut`);e.className=`k-tooltip${t&&t!==`top`?` k-tooltip--${t}`:``}${n?` k-tooltip--rich`:``}`;let a=i(this.getAttribute(`content`)??``);e.innerHTML=(n?`<span class="k-tooltip__title">${i(n)}</span><span class="k-tooltip__body">${a}</span>`:a)+(r?`<kbd class="k-tooltip__kbd" dir="ltr">${i(r)}</kbd>`:``);let o=this.trigger;if(o){let e=(o.getAttribute(`aria-describedby`)??``).split(` `).filter(e=>e&&e!==this.key);this.hasAttribute(`disabled`)||e.push(this.key),e.length?o.setAttribute(`aria-describedby`,e.join(` `)):o.removeAttribute(`aria-describedby`)}}show(e){clearTimeout(this.timer),this.timer=setTimeout(()=>this.open(),e)}hide(){clearTimeout(this.timer),this.timer=setTimeout(()=>this.close(),Number(this.getAttribute(`close-delay`)??100))}};p.observedAttributes=[`content`,`placement`,`heading`,`shortcut`,`disabled`,`open`];var m=class extends l{constructor(){super(...arguments),this.state=`idle`,this.built=!1}connectedCallback(){this.built||(this.built=!0,this.addEventListener(`click`,e=>{e.target.closest(`button`)&&this.copy()})),this.render()}disconnectedCallback(){clearTimeout(this.timer)}attributeChangedCallback(){this.built&&this.render()}get text(){let e=this.getAttribute(`value`);if(e!==null)return e;let t=this.getAttribute(`target`),n=t?document.querySelector(t):null;return n?typeof n.value==`string`?n.value:(n.textContent??``).trim():``}async copy(){try{await navigator.clipboard.writeText(this.text),this.state=`copied`,t(this,`kashi-copy`,{value:this.text})}catch{this.state=`failed`}this.render(),clearTimeout(this.timer),this.timer=setTimeout(()=>{this.state=`idle`,this.render()},Number(this.getAttribute(`timeout`))||2e3)}render(){let e=this.getAttribute(`label`)??s().copy.copy,t=this.getAttribute(`copied-label`)??s().copy.copied,n=this.state===`copied`?t:this.state===`failed`?s().copy.failed:e,o=r(this,`icon-only`),c=this.state===`copied`?a.check:a.copy,l=this.getAttribute(`variant`)??`secondary`,u=this.getAttribute(`size`)??`sm`,d=this.contains(document.activeElement);this.innerHTML=`<button type="button" class="k-btn k-btn--${i(l)}${u===`md`?``:` k-btn--${i(u)}`}${o?` k-btn--icon`:``}" data-variant="${i(l)}" data-size="${i(u)}"${o?` aria-label="${i(n)}"`:``}${this.state===`copied`?` data-copied=""`:``}>${c}${o?``:i(n)}</button><span class="k-sr-only" aria-live="polite">${this.state===`idle`?``:i(n)}</span>`,d&&this.querySelector(`button`).focus()}};m.observedAttributes=[`value`,`target`,`label`,`copied-label`,`icon-only`,`variant`,`size`],o(`kashi-dialog`,d,`contents`),o(`kashi-tabs`,f,`block`),o(`kashi-tooltip`,p),o(`kashi-copy-button`,m),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(t){let n=document.getElementById(t.getAttribute(`data-kashi-open`));n?.show&&(e.preventDefault(),n.show())}});export{m as KashiCopyButton,d as KashiDialog,f as KashiTabs,p as KashiTooltip};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./relative-OC1fV3Xh.js";import{c as t,d as n,i as r,l as i,m as a,n 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{f as p,i as m,l as h,m as g,n as _,p as v,s as y}from"./parts-5fVaWtRe.js";var b=class extends d{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=f(`kashi-modal`)}connectedCallback(){l(()=>{this.isConnected&&(this.dialog||this.setup(),this.decorate(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.open=!1,e!==void 0&&(this.dataset.returnValue=e)}setup(){let e=p(this,`footer`),n=g(this),i=document.createElement(`dialog`);i.setAttribute(`aria-labelledby`,`${this.key}-title`),this.build(i,n,e),this.replaceChildren(i),this.dialog=i,i.addEventListener(`cancel`,e=>{e.preventDefault(),this.close()}),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close], .k-dialog__close`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),i.style.translate=``,this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:this.dataset.returnValue??``}),delete this.dataset.returnValue})}heading(e=``){return`<div class="k-dialog__heading${e}"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div>`}closeButton(){return`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${o.close}</button>`}texts(){let e=this.dialog;e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let t=e.querySelector(`.k-dialog__description`),n=this.getAttribute(`description`);t.textContent=n??``,t.hidden=!n,n?e.setAttribute(`aria-describedby`,t.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`)?.setAttribute(`aria-label`,this.getAttribute(`close-label`)??c().common.close)}wrap(e,t){let n=document.createElement(`div`);return n.className=e,n.append(...t),n}sync(){let e=this.dialog;e&&this.isConnected&&(this.open?(e.removeAttribute(`data-closing`),e.open||(this.opener=document.activeElement,e.showModal?.(),this.opened(),t(this,`kashi-open`,{}))):e.open&&_(e,this.dataset.returnValue))}opened(){}},x=class extends b{build(e,t,n){e.innerHTML=`<div class="k-dialog__header k-drawer__header">${this.heading()}${this.closeButton()}</div>`,e.append(this.wrap(`k-dialog__body k-drawer__body`,t)),n.length&&e.append(this.wrap(`k-dialog__footer k-drawer__footer`,n))}decorate(){let e=this.dialog,t=this.getAttribute(`side`)===`start`?`start`:`end`,n=this.getAttribute(`size`)??`md`;e.className=m(`k-dialog k-drawer`,`k-dialog--${t}`,n!==`md`&&`k-drawer--${n}`,this.dataset.drawerClass),e.dataset.placement=t,this.texts()}};x.observedAttributes=[`open`,`heading`,`description`,`side`,`size`,`close-label`];const S=.6;var C=class extends b{constructor(){super(...arguments),this.current=0,this.drag=null}get snap(){return this.current}set snap(e){this.current=Math.max(0,Math.min(e,this.points.length-1)),this.dialog&&this.paintSnap()}get points(){return(this.getAttribute(`snap-points`)??``).split(/[\s,]+/).map(Number).filter(e=>e>0&&e<=1)}build(e,t,n){e.innerHTML=`<div class="k-sheet__grab"><span class="k-sheet__handle" aria-hidden="true"></span><div class="k-dialog__header k-sheet__header">${this.heading()}</div></div>`,e.append(this.wrap(`k-dialog__body k-sheet__body`,t)),n.length&&e.append(this.wrap(`k-dialog__footer k-sheet__footer`,n));let r=e.querySelector(`.k-sheet__grab`);r.addEventListener(`pointerdown`,e=>this.down(e)),r.addEventListener(`pointermove`,e=>this.move(e)),r.addEventListener(`pointerup`,()=>this.up()),r.addEventListener(`pointercancel`,()=>this.up()),r.addEventListener(`click`,e=>{if(!e.target.closest(`button.k-sheet__handle`))return;let t=this.points;this.setSnap(this.current===t.length-1?0:this.current+1)}),r.addEventListener(`keydown`,e=>{if(!e.target.closest(`button.k-sheet__handle`))return;let t=this.points;e.key===`ArrowUp`&&this.current<t.length-1?(e.preventDefault(),this.setSnap(this.current+1)):e.key===`ArrowDown`&&this.current>0&&(e.preventDefault(),this.setSnap(this.current-1))})}decorate(){let e=this.dialog,t=this.points;e.className=m(`k-dialog k-dialog--bottom k-sheet`,t.length>0&&`k-sheet--snap`),e.dataset.placement=`bottom`;let n=r(this,`hide-title`),i=r(this,`show-close`),a=e.querySelector(`.k-sheet__header`);a.className=m(`k-dialog__header k-sheet__header`,n&&!i&&`k-sheet__header--hidden`),a.querySelector(`.k-dialog__heading`).className=m(`k-dialog__heading`,n&&`k-sr-only`);let o=a.querySelector(`.k-dialog__close`);i&&!o?a.insertAdjacentHTML(`beforeend`,this.closeButton()):i||o?.remove();let s=e.querySelector(`.k-sheet__handle`);t.length&&s.tagName!==`BUTTON`?s.outerHTML=`<button type="button" class="k-sheet__handle"></button>`:!t.length&&s.tagName===`BUTTON`&&(s.outerHTML=`<span class="k-sheet__handle" aria-hidden="true"></span>`);let c=this.getAttribute(`snap`);c!==null&&(this.current=Math.max(0,Math.min(Number(c)||0,Math.max(0,t.length-1)))),this.texts(),this.paintSnap()}opened(){let e=this.getAttribute(`snap`);this.current=e===null?0:Number(e)||0,this.paintSnap()}paintSnap(){let e=this.dialog,t=this.points;t.length?e.style.setProperty(`--k-sheet-height`,`${t[Math.min(this.current,t.length-1)]*100}dvh`):e.style.removeProperty(`--k-sheet-height`);let n=e.querySelector(`button.k-sheet__handle`);if(n){let e=this.current===t.length-1;n.setAttribute(`aria-label`,e?c().sheet.collapse:c().sheet.expand),n.setAttribute(`aria-expanded`,String(e))}}setSnap(e){this.snap=e,t(this,`kashi-snap`,{index:this.current})}down(e){if(e.button!==0||e.target.closest(`.k-dialog__close`))return;let t=this.dialog;this.drag={y:e.clientY,t:e.timeStamp,h:t.getBoundingClientRect().height,dy:0,v:0},e.currentTarget.setPointerCapture?.(e.pointerId),t.setAttribute(`data-dragging`,``)}move(e){let t=this.drag;if(!t)return;let n=e.clientY-t.y;t.v=(n-t.dy)/Math.max(1,e.timeStamp-t.t),t.dy=n,t.t=e.timeStamp;let r=this.points,i=r.length?r[r.length-1]*innerHeight-t.h:0,a=n<0?-Math.min(-n,Math.max(0,i))-Math.max(0,-n-Math.max(0,i))*.15:n;this.dialog.style.translate=`0 ${a}px`}up(){let e=this.drag,t=this.dialog;if(this.drag=null,!e)return;t.removeAttribute(`data-dragging`),t.style.translate=``;let n=this.points,i=e.h-e.dy;if(r(this,`dismissible`,!0)&&(e.dy>e.h*.3||e.v>S&&e.dy>24)&&(!n.length||this.current===0||e.v>S*1.5||i<n[0]*innerHeight*.6)){t.style.translate=`0 ${Math.max(0,e.dy)}px`,this.close();return}if(!n.length)return;let a=Math.abs(e.v)>S?Math.max(0,Math.min(n.length-1,this.current+(e.v<0?1:-1))):n.reduce((e,t,r)=>Math.abs(t*innerHeight-i)<Math.abs(n[e]*innerHeight-i)?r:e,0);a!==this.current&&this.setSnap(a)}};C.observedAttributes=[`open`,`heading`,`description`,`hide-title`,`snap-points`,`snap`,`show-close`,`close-label`];const w=y(`<path d="M3.75 5.5h12.5M3.75 10h12.5M3.75 14.5h12.5"/>`,1.5);var T=class extends d{constructor(){super(...arguments),this.header=null,this.nav=null,this.drawer=null,this.ro=null,this.onScroll=()=>{this.header?.toggleAttribute(`data-scrolled`,r(this,`sticky`,!0)&&(window.scrollY??0)>4)}}connectedCallback(){l(()=>{this.isConnected&&(this.header||this.build(),this.update(),addEventListener(`scroll`,this.onScroll,{passive:!0}),this.onScroll(),this.nav&&typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.toCurrent()),this.ro.observe(this.nav)))})}disconnectedCallback(){removeEventListener(`scroll`,this.onScroll),this.ro?.disconnect(),this.ro=null}attributeChangedCallback(){this.header&&this.update()}build(){let e=p(this,`brand`),t=p(this,`actions`),n=p(this,`menu-footer`),r=[...this.children].filter(e=>e.tagName===`A`),a=document.createElement(`header`);a.innerHTML=`<div class="k-navbar__inner"><a class="k-navbar__brand"></a><div class="k-navbar__actions"></div></div>`;let o=a.querySelector(`.k-navbar__brand`);o.append(...e);let s=(e,t)=>{e.className=t;let n=e.dataset.badge;if(!e.querySelector(`:scope > span`)){let t=document.createElement(`span`);t.append(...[...e.childNodes].filter(e=>e.nodeName.toLowerCase()!==`svg`)),e.append(t)}return e.querySelectorAll(`:scope > svg`).forEach(t=>{let n=document.createElement(`span`);n.className=`k-navbar__icon`,n.setAttribute(`aria-hidden`,`true`),t.replaceWith(n),n.append(t),e.prepend(n)}),n&&!e.querySelector(`.k-navbar__badge`)&&e.insertAdjacentHTML(`beforeend`,`<span class="k-navbar__badge">${i(n)}</span>`),e},c=a.querySelector(`.k-navbar__actions`);if(c.append(...t),r.length){let e=document.createElement(`nav`);e.className=`k-navbar__nav`,e.innerHTML=`<span class="k-navbar__pill" aria-hidden="true"></span>`;let t=document.createElement(`nav`);t.className=`k-navbar__mobile`;for(let n of r)e.append(s(n,`k-navbar__link`)),t.append(s(n.cloneNode(!0),`k-navbar__mobile-link`));o.after(e),this.nav=e,e.addEventListener(`pointerover`,e=>this.place(e.target.closest(`.k-navbar__link`))),e.addEventListener(`focusin`,e=>this.place(e.target.closest(`.k-navbar__link`))),e.addEventListener(`pointerleave`,()=>this.toCurrent()),e.addEventListener(`focusout`,()=>this.toCurrent()),c.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-navbar__menu" aria-haspopup="dialog" aria-expanded="false">${w}</button>`);let i=document.createElement(`kashi-drawer`);if(i.setAttribute(`side`,`start`),i.setAttribute(`size`,`sm`),i.dataset.drawerClass=`k-navbar__drawer`,i.append(t),n.length){let e=document.createElement(`div`);e.slot=`footer`,e.style.display=`contents`,e.append(...n),i.append(e)}let l=c.querySelector(`.k-navbar__menu`);l.addEventListener(`click`,()=>i.show()),i.addEventListener(`kashi-open`,()=>l.setAttribute(`aria-expanded`,`true`)),i.addEventListener(`kashi-close`,()=>l.setAttribute(`aria-expanded`,`false`)),t.addEventListener(`click`,e=>{e.target.closest(`a`)&&i.close()}),a.append(i),this.drawer=i}this.replaceChildren(a),this.header=a}place(e){let t=this.nav;if(t){if(!e)return void t.style.setProperty(`--_pill-o`,`0`);t.style.setProperty(`--_pill-x`,`${e.offsetLeft}px`),t.style.setProperty(`--_pill-w`,`${e.offsetWidth}px`),t.style.setProperty(`--_pill-o`,`1`)}}toCurrent(){this.place(this.nav?.querySelector(`[aria-current="page"]`)??null)}update(){let e=this.header,t=r(this,`sticky`,!0);e.className=m(`k-navbar`,t&&`k-navbar--sticky`,this.getAttribute(`variant`)===`pill`&&`k-navbar--pill`,r(this,`centered`)&&`k-navbar--centered`,r(this,`floating`)&&`k-navbar--floating`,r(this,`transparent`)&&`k-navbar--transparent`,`k-navbar--collapse-${this.getAttribute(`collapse-below`)??`md`}`),e.querySelector(`.k-navbar__brand`).setAttribute(`href`,this.getAttribute(`brand-href`)??`/`);let n=c(),i=this.getAttribute(`label`)??n.navbar.label;this.nav?.setAttribute(`aria-label`,i),e.querySelector(`.k-navbar__mobile`)?.setAttribute(`aria-label`,i),e.querySelector(`.k-navbar__menu`)?.setAttribute(`aria-label`,n.navbar.menu),this.drawer?.setAttribute(`heading`,n.navbar.menuTitle),this.toCurrent()}};T.observedAttributes=[`brand-href`,`sticky`,`variant`,`centered`,`floating`,`transparent`,`collapse-below`,`label`];const E=y(`<path d="M5 8a5 5 0 0 1 10 0c0 4 1.5 5.5 1.5 5.5h-13S5 12 5 8ZM8.5 16.5a1.6 1.6 0 0 0 3 0"/>`),D=y(`<path d="M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM16 10a6 6 0 0 0-.1-1l1.6-1.3-1.5-2.6-2 .7a6 6 0 0 0-1.7-1L12 2.8H9l-.4 2a6 6 0 0 0-1.7 1l-2-.7-1.5 2.6L5 9a6 6 0 0 0 0 2l-1.6 1.3 1.5 2.6 2-.7a6 6 0 0 0 1.7 1l.4 2h3l.4-2a6 6 0 0 0 1.7-1l2 .7 1.5-2.6L15.9 11c.1-.3.1-.7.1-1Z"/>`),O=y(`<path d="m2.5 10.5 3 3 6-7M9 13.2l.3.3 6-7"/>`),k=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();var A=class extends d{constructor(){super(...arguments),this.data=null,this.tab=`all`,this.root=null}connectedCallback(){l(()=>{this.isConnected&&(this.root||(this.root=document.createElement(`div`),this.root.className=`k-notif`,this.mount(this.root),this.root.addEventListener(`click`,e=>this.onClick(e))),this.render())})}attributeChangedCallback(e,t,n){t!==n&&(e===`items`&&(this.data=null),this.root&&this.render())}mount(e){this.replaceChildren(e)}get items(){return this.data??h(this,`items`,[])}set items(e){this.data=[...e??[]],this.root&&this.render()}get unread(){return this.items.filter(e=>!e.read).length}markRead(e){this.data=this.items.map(t=>t.id===e?{...t,read:!0}:t),t(this,`kashi-read`,{id:e}),this.render()}markAllRead(){this.data=this.items.map(e=>({...e,read:!0})),t(this,`kashi-read-all`,{}),this.render()}onClick(e){let n=e.target,r=n.closest(`[data-tab]`);if(r){this.tab=r.dataset.tab,this.render(),this.root.querySelector(`[data-tab="${this.tab}"]`)?.focus();return}if(n.closest(`[data-act=all]`))return this.markAllRead();if(n.closest(`[data-act=settings]`))return t(this,`kashi-settings`,{});let i=n.closest(`.k-notif__dot`);if(i)return this.markRead(i.closest(`[data-id]`).dataset.id);let a=n.closest(`.k-notif__main`);if(a){let e=a.closest(`[data-id]`).dataset.id,n=this.items.find(t=>t.id===e);if(!n)return;t(this,`kashi-select`,{item:n}),n.read||this.markRead(e)}}render(){let t=c().notifications,o=this.items,s=o.filter(e=>!e.read).length,l=this.tab===`unread`?o.filter(e=>!e.read):o,d=v(this.getAttribute(`now`))??/* @__PURE__ */ new Date,f=k(d),p=[[t.today,[]],[t.yesterday,[]],[t.earlier,[]]],m=[...l].sort((e,t)=>(v(t.time)?.getTime()??0)-(v(e.time)?.getTime()??0));for(let e of m){let t=k(v(e.time)??d);p[t>=f?0:t>=f-864e5?1:2][1].push(e)}let h=this.root.contains(document.activeElement)?document.activeElement:null,g=h&&{id:h.closest(`[data-id]`)?.dataset.id,tab:h.dataset.tab,act:h.dataset.act},_=this.getAttribute(`view-all-href`),y=r=>{let a=v(r.time)??d,o=`${r.image?`<span class="k-notif__media"${r.tone?` data-tone="${r.tone}"`:``}><img src="${i(r.image)}" alt=""></span>`:r.tone?`<span class="k-notif__media" data-tone="${r.tone}">${E}</span>`:``}<span class="k-notif__text"><span class="k-notif__item-title">${i(r.title)}</span>${r.body?`<span class="k-notif__body">${i(r.body)}</span>`:``}<time class="k-notif__time" datetime="${a.toISOString()}">${i(e(a,{now:d,locale:n(),digits:u(this)}))}</time></span>`;return`<li class="k-notif__item" data-id="${i(r.id)}"${r.read?``:` data-unread`}>${r.href?`<a class="k-notif__main" href="${i(r.href)}">${o}</a>`:`<button type="button" class="k-notif__main">${o}</button>`}${r.read?``:`<button type="button" class="k-notif__dot" aria-label="${i(t.markRead)}" title="${i(t.markRead)}"><span aria-hidden="true"></span></button>`}</li>`};if(this.root.innerHTML=`<div class="k-notif__head"><h2 class="k-notif__title">${i(this.getAttribute(`heading`)??t.label)}</h2>${s>0?`<button type="button" class="k-notif__link" data-act="all">${O}${i(t.markAll)}</button>`:``}${r(this,`settings`)?`<button type="button" class="k-notif__icon" data-act="settings" aria-label="${i(t.settings)}">${D}</button>`:``}</div><div class="k-notif__tabs" role="group">${[`all`,`unread`].map(e=>`<button type="button" class="k-notif__tab" data-tab="${e}" aria-pressed="${this.tab===e}">${i(t[e])}${e===`unread`&&s>0?`<span class="k-notif__count">${a(this,s)}</span>`:``}</button>`).join(``)}</div>${l.length===0?`<div class="k-notif__empty"><span class="k-notif__empty-icon">${E}</span><p>${i(this.tab===`unread`?t.emptyUnread:t.empty)}</p></div>`:`<div class="k-notif__scroll" tabindex="-1">${p.filter(([,e])=>e.length).map(([e,t])=>`<section class="k-notif__group" aria-label="${i(e)}"><h3 class="k-notif__group-title">${i(e)}</h3><ul class="k-notif__list">${t.map(y).join(``)}</ul></section>`).join(``)}</div>`}${_?`<a class="k-notif__all" href="${i(_)}">${i(t.viewAll)}</a>`:``}`,g){let e=this.root;((g.tab?e.querySelector(`[data-tab="${g.tab}"]`):g.act?e.querySelector(`[data-act="${g.act}"]`):g.id?e.querySelector(`[data-id="${g.id.replace(/["\\]/g,`\\$&`)}"] .k-notif__main`):null)??e.querySelector(`.k-notif__tab`))?.focus()}this.rendered(s)}rendered(e){}};A.observedAttributes=[`items`,`heading`,`view-all-href`,`settings`,`now`,`digits`];var j=class extends A{constructor(){super(...arguments),this.last=-1,this.key=f(`kashi-notif`),this.onOutside=e=>{this.contains(e.target)||this.close(!1)}}mount(e){let t=document.createElement(`span`);t.className=`k-popover-anchor`,t.innerHTML=`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-notif__bell" aria-haspopup="dialog" aria-expanded="false" aria-controls="${this.key}">${E}</button><div id="${this.key}" role="dialog" tabindex="-1" hidden><div class="k-popover__body"></div></div>`,this.bell=t.querySelector(`button`),this.panel=t.querySelector(`[role=dialog]`),this.panel.firstElementChild.append(e),this.replaceChildren(t),this.bell.addEventListener(`click`,()=>this.open?this.close(!1):this.show()),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.close(!0))}),this.panel.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t&&!this.contains(t)&&this.close(!1)})}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}get open(){return!!this.panel&&!this.panel.hidden}set open(e){e?this.show():this.close(!1)}show(){this.panel&&!this.open&&(this.panel.hidden=!1,this.bell.setAttribute(`aria-expanded`,`true`),(this.panel.querySelector(`.k-notif__tab`)??this.panel).focus(),document.addEventListener(`pointerdown`,this.onOutside),t(this,`kashi-open`,{}))}close(e=!0){this.panel&&!this.panel.hidden&&(this.panel.hidden=!0,this.bell.setAttribute(`aria-expanded`,`false`),document.removeEventListener(`pointerdown`,this.onOutside),e&&this.bell.focus(),t(this,`kashi-close`,{}))}rendered(e){let t=c().notifications,[,n]=(this.getAttribute(`placement`)??`bottom-end`).split(`-`);this.panel.className=m(`k-popover`,n===`end`&&`k-popover--end`,`k-notif-pop`),this.panel.setAttribute(`aria-label`,t.label),this.bell.setAttribute(`aria-label`,e?t.button(a(this,e)):t.label);let r=this.bell.querySelector(`.k-notif__badge`);e>0&&(e!==this.last||!r)?(r?.remove(),this.bell.insertAdjacentHTML(`beforeend`,`<span class="k-notif__badge" aria-hidden="true">${e>99?`${a(this,99)}+`:a(this,e)}</span>`)):e||r?.remove(),this.last=e}};j.observedAttributes=[...A.observedAttributes,`placement`],s(`kashi-drawer`,x),s(`kashi-bottom-sheet`,C),s(`kashi-navbar`,T,`block`),s(`kashi-notification-list`,A,`block`),s(`kashi-notification-center`,j),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(!t)return;let n=document.getElementById(t.getAttribute(`data-kashi-open`));(n instanceof x||n instanceof C)&&(e.preventDefault(),n.show())});export{C as KashiBottomSheet,x as KashiDrawer,T as KashiNavbar,j as KashiNotificationCenter,A as KashiNotificationList};
|
|
1
|
+
import{t as e}from"./relative-OC1fV3Xh.js";import{c as t,d as n,i as r,l as i,m as a,n 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{f as p,i as m,l as h,m as g,n as _,p as v,s as y}from"./parts-5fVaWtRe.js";var b=class extends d{constructor(){super(...arguments),this.dialog=null,this.opener=null,this.key=f(`kashi-modal`)}connectedCallback(){l(()=>{this.isConnected&&(this.dialog||this.setup(),this.decorate(),this.sync())})}attributeChangedCallback(e,t,n){this.dialog&&t!==n&&(e===`open`?this.sync():this.decorate())}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,!!e)}show(){this.open=!0}close(e){this.open=!1,e!==void 0&&(this.dataset.returnValue=e)}setup(){let e=p(this,`footer`),n=g(this),i=document.createElement(`dialog`);i.setAttribute(`aria-labelledby`,`${this.key}-title`),this.build(i,n,e),this.replaceChildren(i),this.dialog=i,i.addEventListener(`cancel`,e=>{e.preventDefault(),this.close()}),i.addEventListener(`click`,e=>{e.target===i&&r(this,`dismissible`,!0)&&this.close();let t=e.target.closest(`[data-kashi-close], .k-dialog__close`);t&&i.contains(t)&&this.close(t.getAttribute(`data-kashi-close`)||void 0)}),i.addEventListener(`close`,()=>{this.removeAttribute(`open`),i.style.translate=``,this.opener?.focus?.(),t(this,`kashi-close`,{returnValue:this.dataset.returnValue??``}),delete this.dataset.returnValue})}heading(e=``){return`<div class="k-dialog__heading${e}"><h2 class="k-dialog__title" id="${this.key}-title"></h2><p class="k-dialog__description" id="${this.key}-desc"></p></div>`}closeButton(){return`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-dialog__close">${o.close}</button>`}texts(){let e=this.dialog;e.querySelector(`.k-dialog__title`).textContent=this.getAttribute(`heading`)??``;let t=e.querySelector(`.k-dialog__description`),n=this.getAttribute(`description`);t.textContent=n??``,t.hidden=!n,n?e.setAttribute(`aria-describedby`,t.id):e.removeAttribute(`aria-describedby`),e.querySelector(`.k-dialog__close`)?.setAttribute(`aria-label`,this.getAttribute(`close-label`)??c().common.close)}wrap(e,t){let n=document.createElement(`div`);return n.className=e,n.append(...t),n}sync(){let e=this.dialog;e&&this.isConnected&&(this.open?(e.removeAttribute(`data-closing`),e.open||(this.opener=document.activeElement,e.showModal?.(),this.opened(),t(this,`kashi-open`,{}))):e.open&&_(e,this.dataset.returnValue))}opened(){}},x=class extends b{build(e,t,n){e.innerHTML=`<div class="k-dialog__header k-drawer__header">${this.heading()}${this.closeButton()}</div>`,e.append(this.wrap(`k-dialog__body k-drawer__body`,t)),n.length&&e.append(this.wrap(`k-dialog__footer k-drawer__footer`,n))}decorate(){let e=this.dialog,t=this.getAttribute(`side`)===`start`?`start`:`end`,n=this.getAttribute(`size`)??`md`;e.className=m(`k-dialog k-drawer`,`k-dialog--${t}`,n!==`md`&&`k-drawer--${n}`,this.dataset.drawerClass),e.dataset.placement=t,this.texts()}};x.observedAttributes=[`open`,`heading`,`description`,`side`,`size`,`close-label`];const S=.6;var C=class extends b{constructor(){super(...arguments),this.current=0,this.drag=null}get snap(){return this.current}set snap(e){this.current=Math.max(0,Math.min(e,this.points.length-1)),this.dialog&&this.paintSnap()}get points(){return(this.getAttribute(`snap-points`)??``).split(/[\s,]+/).map(Number).filter(e=>e>0&&e<=1)}build(e,t,n){e.innerHTML=`<div class="k-sheet__grab"><span class="k-sheet__handle" aria-hidden="true"></span><div class="k-dialog__header k-sheet__header">${this.heading()}</div></div>`,e.append(this.wrap(`k-dialog__body k-sheet__body`,t)),n.length&&e.append(this.wrap(`k-dialog__footer k-sheet__footer`,n));let r=e.querySelector(`.k-sheet__grab`);r.addEventListener(`pointerdown`,e=>this.down(e)),r.addEventListener(`pointermove`,e=>this.move(e)),r.addEventListener(`pointerup`,()=>this.up()),r.addEventListener(`pointercancel`,()=>this.up()),r.addEventListener(`click`,e=>{if(!e.target.closest(`button.k-sheet__handle`))return;let t=this.points;this.setSnap(this.current===t.length-1?0:this.current+1)}),r.addEventListener(`keydown`,e=>{if(!e.target.closest(`button.k-sheet__handle`))return;let t=this.points;e.key===`ArrowUp`&&this.current<t.length-1?(e.preventDefault(),this.setSnap(this.current+1)):e.key===`ArrowDown`&&this.current>0&&(e.preventDefault(),this.setSnap(this.current-1))})}decorate(){let e=this.dialog,t=this.points;e.className=m(`k-dialog k-dialog--bottom k-sheet`,t.length>0&&`k-sheet--snap`),e.dataset.placement=`bottom`;let n=r(this,`hide-title`),i=r(this,`show-close`),a=e.querySelector(`.k-sheet__header`);a.className=m(`k-dialog__header k-sheet__header`,n&&!i&&`k-sheet__header--hidden`),a.querySelector(`.k-dialog__heading`).className=m(`k-dialog__heading`,n&&`k-sr-only`);let o=a.querySelector(`.k-dialog__close`);i&&!o?a.insertAdjacentHTML(`beforeend`,this.closeButton()):i||o?.remove();let s=e.querySelector(`.k-sheet__handle`);t.length&&s.tagName!==`BUTTON`?s.outerHTML=`<button type="button" class="k-sheet__handle"></button>`:!t.length&&s.tagName===`BUTTON`&&(s.outerHTML=`<span class="k-sheet__handle" aria-hidden="true"></span>`);let c=this.getAttribute(`snap`);c!==null&&(this.current=Math.max(0,Math.min(Number(c)||0,Math.max(0,t.length-1)))),this.texts(),this.paintSnap()}opened(){let e=this.getAttribute(`snap`);this.current=e===null?0:Number(e)||0,this.paintSnap()}paintSnap(){let e=this.dialog,t=this.points;t.length?e.style.setProperty(`--k-sheet-height`,`${t[Math.min(this.current,t.length-1)]*100}dvh`):e.style.removeProperty(`--k-sheet-height`);let n=e.querySelector(`button.k-sheet__handle`);if(n){let e=this.current===t.length-1;n.setAttribute(`aria-label`,e?c().sheet.collapse:c().sheet.expand),n.setAttribute(`aria-expanded`,String(e))}}setSnap(e){this.snap=e,t(this,`kashi-snap`,{index:this.current})}down(e){if(e.button!==0||e.target.closest(`.k-dialog__close`))return;let t=this.dialog;this.drag={y:e.clientY,t:e.timeStamp,h:t.getBoundingClientRect().height,dy:0,v:0},e.currentTarget.setPointerCapture?.(e.pointerId),t.setAttribute(`data-dragging`,``)}move(e){let t=this.drag;if(!t)return;let n=e.clientY-t.y;t.v=(n-t.dy)/Math.max(1,e.timeStamp-t.t),t.dy=n,t.t=e.timeStamp;let r=this.points,i=r.length?r[r.length-1]*innerHeight-t.h:0,a=n<0?-Math.min(-n,Math.max(0,i))-Math.max(0,-n-Math.max(0,i))*.15:n;this.dialog.style.translate=`0 ${a}px`}up(){let e=this.drag,t=this.dialog;if(this.drag=null,!e)return;t.removeAttribute(`data-dragging`),t.style.translate=``;let n=this.points,i=e.h-e.dy;if(r(this,`dismissible`,!0)&&(e.dy>e.h*.3||e.v>S&&e.dy>24)&&(!n.length||this.current===0||e.v>S*1.5||i<n[0]*innerHeight*.6)){t.style.translate=`0 ${Math.max(0,e.dy)}px`,this.close();return}if(!n.length)return;let a=Math.abs(e.v)>S?Math.max(0,Math.min(n.length-1,this.current+(e.v<0?1:-1))):n.reduce((e,t,r)=>Math.abs(t*innerHeight-i)<Math.abs(n[e]*innerHeight-i)?r:e,0);a!==this.current&&this.setSnap(a)}};C.observedAttributes=[`open`,`heading`,`description`,`hide-title`,`snap-points`,`snap`,`show-close`,`close-label`];const w=y(`<path d="M3.75 5.5h12.5M3.75 10h12.5M3.75 14.5h12.5"/>`,1.5);var T=class extends d{constructor(){super(...arguments),this.header=null,this.nav=null,this.drawer=null,this.ro=null,this.onScroll=()=>{this.header?.toggleAttribute(`data-scrolled`,r(this,`sticky`,!0)&&(window.scrollY??0)>4)}}connectedCallback(){l(()=>{this.isConnected&&(this.header||this.build(),this.update(),addEventListener(`scroll`,this.onScroll,{passive:!0}),this.onScroll(),this.nav&&typeof ResizeObserver<`u`&&!this.ro&&(this.ro=new ResizeObserver(()=>this.toCurrent()),this.ro.observe(this.nav)))})}disconnectedCallback(){removeEventListener(`scroll`,this.onScroll),this.ro?.disconnect(),this.ro=null}attributeChangedCallback(){this.header&&this.update()}build(){let e=p(this,`brand`),t=p(this,`actions`),n=p(this,`menu-footer`),r=[...this.children].filter(e=>e.tagName===`A`),a=document.createElement(`header`);a.innerHTML=`<div class="k-navbar__inner"><a class="k-navbar__brand"></a><div class="k-navbar__actions"></div></div>`;let o=a.querySelector(`.k-navbar__brand`);o.append(...e);let s=(e,t)=>{e.className=t;let n=e.dataset.badge;if(!e.querySelector(`:scope > span`)){let t=document.createElement(`span`);t.append(...[...e.childNodes].filter(e=>e.nodeName.toLowerCase()!==`svg`)),e.append(t)}return e.querySelectorAll(`:scope > svg`).forEach(t=>{let n=document.createElement(`span`);n.className=`k-navbar__icon`,n.setAttribute(`aria-hidden`,`true`),t.replaceWith(n),n.append(t),e.prepend(n)}),n&&!e.querySelector(`.k-navbar__badge`)&&e.insertAdjacentHTML(`beforeend`,`<span class="k-navbar__badge">${i(n)}</span>`),e},c=a.querySelector(`.k-navbar__actions`);if(c.append(...t),r.length){let e=document.createElement(`nav`);e.className=`k-navbar__nav`,e.innerHTML=`<span class="k-navbar__pill" aria-hidden="true"></span>`;let t=document.createElement(`nav`);t.className=`k-navbar__mobile`;for(let n of r)e.append(s(n,`k-navbar__link`)),t.append(s(n.cloneNode(!0),`k-navbar__mobile-link`));o.after(e),this.nav=e,e.addEventListener(`pointerover`,e=>this.place(e.target.closest(`.k-navbar__link`))),e.addEventListener(`focusin`,e=>this.place(e.target.closest(`.k-navbar__link`))),e.addEventListener(`pointerleave`,()=>this.toCurrent()),e.addEventListener(`focusout`,()=>this.toCurrent()),c.insertAdjacentHTML(`beforeend`,`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-btn--sm k-navbar__menu" aria-haspopup="dialog" aria-expanded="false">${w}</button>`);let i=document.createElement(`kashi-drawer`);if(i.setAttribute(`side`,`start`),i.setAttribute(`size`,`sm`),i.dataset.drawerClass=`k-navbar__drawer`,i.append(t),n.length){let e=document.createElement(`div`);e.slot=`footer`,e.style.display=`contents`,e.append(...n),i.append(e)}let l=c.querySelector(`.k-navbar__menu`);l.addEventListener(`click`,()=>i.show()),i.addEventListener(`kashi-open`,()=>l.setAttribute(`aria-expanded`,`true`)),i.addEventListener(`kashi-close`,()=>l.setAttribute(`aria-expanded`,`false`)),t.addEventListener(`click`,e=>{e.target.closest(`a`)&&i.close()}),a.append(i),this.drawer=i}this.replaceChildren(a),this.header=a}place(e){let t=this.nav;if(t){if(!e)return void t.style.setProperty(`--_pill-o`,`0`);t.style.setProperty(`--_pill-x`,`${e.offsetLeft}px`),t.style.setProperty(`--_pill-w`,`${e.offsetWidth}px`),t.style.setProperty(`--_pill-o`,`1`)}}toCurrent(){this.place(this.nav?.querySelector(`[aria-current="page"]`)??null)}update(){let e=this.header,t=r(this,`sticky`,!0);e.className=m(`k-navbar`,t&&`k-navbar--sticky`,this.getAttribute(`variant`)===`pill`&&`k-navbar--pill`,r(this,`centered`)&&`k-navbar--centered`,r(this,`floating`)&&`k-navbar--floating`,r(this,`transparent`)&&`k-navbar--transparent`,`k-navbar--collapse-${this.getAttribute(`collapse-below`)??`md`}`),e.querySelector(`.k-navbar__brand`).setAttribute(`href`,this.getAttribute(`brand-href`)??`/`);let n=c(),i=this.getAttribute(`label`)??n.navbar.label;this.nav?.setAttribute(`aria-label`,i),e.querySelector(`.k-navbar__mobile`)?.setAttribute(`aria-label`,i),e.querySelector(`.k-navbar__menu`)?.setAttribute(`aria-label`,n.navbar.menu),this.drawer?.setAttribute(`heading`,n.navbar.menuTitle),this.toCurrent()}};T.observedAttributes=[`brand-href`,`sticky`,`variant`,`centered`,`floating`,`transparent`,`collapse-below`,`label`];const E=y(`<path d="M5 8a5 5 0 0 1 10 0c0 4 1.5 5.5 1.5 5.5h-13S5 12 5 8ZM8.5 16.5a1.6 1.6 0 0 0 3 0"/>`),D=y(`<path d="M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM16 10a6 6 0 0 0-.1-1l1.6-1.3-1.5-2.6-2 .7a6 6 0 0 0-1.7-1L12 2.8H9l-.4 2a6 6 0 0 0-1.7 1l-2-.7-1.5 2.6L5 9a6 6 0 0 0 0 2l-1.6 1.3 1.5 2.6 2-.7a6 6 0 0 0 1.7 1l.4 2h3l.4-2a6 6 0 0 0 1.7-1l2 .7 1.5-2.6L15.9 11c.1-.3.1-.7.1-1Z"/>`),O=y(`<path d="m2.5 10.5 3 3 6-7M9 13.2l.3.3 6-7"/>`),k=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();var A=class extends d{constructor(){super(...arguments),this.data=null,this.tab=`all`,this.root=null}connectedCallback(){l(()=>{this.isConnected&&(this.root||(this.root=document.createElement(`div`),this.root.className=`k-notif`,this.mount(this.root),this.root.addEventListener(`click`,e=>this.onClick(e))),this.render())})}attributeChangedCallback(e,t,n){t!==n&&(e===`items`&&(this.data=null),this.root&&this.render())}mount(e){this.replaceChildren(e)}get items(){return this.data??h(this,`items`,[])}set items(e){this.data=[...e??[]],this.root&&this.render()}get unread(){return this.items.filter(e=>!e.read).length}markRead(e){this.data=this.items.map(t=>t.id===e?{...t,read:!0}:t),t(this,`kashi-read`,{id:e}),this.render()}markAllRead(){this.data=this.items.map(e=>({...e,read:!0})),t(this,`kashi-read-all`,{}),this.render()}onClick(e){let n=e.target,r=n.closest(`[data-tab]`);if(r){this.tab=r.dataset.tab,this.render(),this.root.querySelector(`[data-tab="${this.tab}"]`)?.focus();return}if(n.closest(`[data-act=all]`))return this.markAllRead();if(n.closest(`[data-act=settings]`))return t(this,`kashi-settings`,{});let i=n.closest(`.k-notif__dot`);if(i)return this.markRead(i.closest(`[data-id]`).dataset.id);let a=n.closest(`.k-notif__main`);if(a){let e=a.closest(`[data-id]`).dataset.id,n=this.items.find(t=>t.id===e);if(!n)return;t(this,`kashi-select`,{item:n}),n.read||this.markRead(e)}}render(){let t=c().notifications,o=this.items,s=o.filter(e=>!e.read).length,l=this.tab===`unread`?o.filter(e=>!e.read):o,d=v(this.getAttribute(`now`))??/* @__PURE__ */ new Date,f=k(d),p=[[t.today,[]],[t.yesterday,[]],[t.earlier,[]]],m=[...l].sort((e,t)=>(v(t.time)?.getTime()??0)-(v(e.time)?.getTime()??0));for(let e of m){let t=k(v(e.time)??d);p[t>=f?0:t>=f-864e5?1:2][1].push(e)}let h=this.root.contains(document.activeElement)?document.activeElement:null,g=h&&{id:h.closest(`[data-id]`)?.dataset.id,tab:h.dataset.tab,act:h.dataset.act},_=this.getAttribute(`view-all-href`),y=r=>{let a=v(r.time)??d,o=`${r.image?`<span class="k-notif__media"${r.tone?` data-tone="${r.tone}"`:``}><img src="${i(r.image)}" alt=""></span>`:r.tone?`<span class="k-notif__media" data-tone="${r.tone}">${E}</span>`:``}<span class="k-notif__text"><span class="k-notif__item-title">${i(r.title)}</span>${r.read?``:`<span class="k-sr-only"> ${i(t.unreadDot)}</span>`}${r.body?`<span class="k-notif__body">${i(r.body)}</span>`:``}<time class="k-notif__time" datetime="${a.toISOString()}">${i(e(a,{now:d,locale:n(),digits:u(this)}))}</time></span>`;return`<li class="k-notif__item" data-id="${i(r.id)}"${r.read?``:` data-unread`}>${r.href?`<a class="k-notif__main" href="${i(r.href)}">${o}</a>`:`<button type="button" class="k-notif__main">${o}</button>`}${r.read?``:`<button type="button" class="k-notif__dot" aria-label="${i(t.markRead)}" title="${i(t.markRead)}"><span aria-hidden="true"></span></button>`}</li>`};if(this.root.innerHTML=`<div class="k-notif__head"><h2 class="k-notif__title">${i(this.getAttribute(`heading`)??t.label)}</h2>${s>0?`<button type="button" class="k-notif__link" data-act="all">${O}${i(t.markAll)}</button>`:``}${r(this,`settings`)?`<button type="button" class="k-notif__icon" data-act="settings" aria-label="${i(t.settings)}">${D}</button>`:``}</div><div class="k-notif__tabs" role="group">${[`all`,`unread`].map(e=>`<button type="button" class="k-notif__tab" data-tab="${e}" aria-pressed="${this.tab===e}">${i(t[e])}${e===`unread`&&s>0?`<span class="k-notif__count">${a(this,s)}</span>`:``}</button>`).join(``)}</div>${l.length===0?`<div class="k-notif__empty"><span class="k-notif__empty-icon">${E}</span><p>${i(this.tab===`unread`?t.emptyUnread:t.empty)}</p></div>`:`<div class="k-notif__scroll" tabindex="-1">${p.filter(([,e])=>e.length).map(([e,t])=>`<section class="k-notif__group" aria-label="${i(e)}"><h3 class="k-notif__group-title">${i(e)}</h3><ul class="k-notif__list">${t.map(y).join(``)}</ul></section>`).join(``)}</div>`}${_?`<a class="k-notif__all" href="${i(_)}">${i(t.viewAll)}</a>`:``}`,g){let e=this.root;((g.tab?e.querySelector(`[data-tab="${g.tab}"]`):g.act?e.querySelector(`[data-act="${g.act}"]`):g.id?e.querySelector(`[data-id="${g.id.replace(/["\\]/g,`\\$&`)}"] .k-notif__main`):null)??e.querySelector(`.k-notif__tab`))?.focus()}this.rendered(s)}rendered(e){}};A.observedAttributes=[`items`,`heading`,`view-all-href`,`settings`,`now`,`digits`];var j=class extends A{constructor(){super(...arguments),this.last=-1,this.key=f(`kashi-notif`),this.onOutside=e=>{this.contains(e.target)||this.close(!1)}}mount(e){let t=document.createElement(`span`);t.className=`k-popover-anchor`,t.innerHTML=`<button type="button" class="k-btn k-btn--tertiary k-btn--icon k-notif__bell" aria-haspopup="dialog" aria-expanded="false" aria-controls="${this.key}">${E}</button><div id="${this.key}" role="dialog" tabindex="-1" hidden><div class="k-popover__body"></div></div>`,this.bell=t.querySelector(`button`),this.panel=t.querySelector(`[role=dialog]`),this.panel.firstElementChild.append(e),this.replaceChildren(t),this.bell.addEventListener(`click`,()=>this.open?this.close(!1):this.show()),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.stopPropagation(),this.close(!0))}),this.panel.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t&&!this.contains(t)&&this.close(!1)})}disconnectedCallback(){document.removeEventListener(`pointerdown`,this.onOutside)}get open(){return!!this.panel&&!this.panel.hidden}set open(e){e?this.show():this.close(!1)}show(){this.panel&&!this.open&&(this.panel.hidden=!1,this.bell.setAttribute(`aria-expanded`,`true`),(this.panel.querySelector(`.k-notif__tab`)??this.panel).focus(),document.addEventListener(`pointerdown`,this.onOutside),t(this,`kashi-open`,{}))}close(e=!0){this.panel&&!this.panel.hidden&&(this.panel.hidden=!0,this.bell.setAttribute(`aria-expanded`,`false`),document.removeEventListener(`pointerdown`,this.onOutside),e&&this.bell.focus(),t(this,`kashi-close`,{}))}rendered(e){let t=c().notifications,[,n]=(this.getAttribute(`placement`)??`bottom-end`).split(`-`);this.panel.className=m(`k-popover`,n===`end`&&`k-popover--end`,`k-notif-pop`),this.panel.setAttribute(`aria-label`,t.label),this.bell.setAttribute(`aria-label`,e?t.button(a(this,e)):t.label);let r=this.bell.querySelector(`.k-notif__badge`);e>0&&(e!==this.last||!r)?(r?.remove(),this.bell.insertAdjacentHTML(`beforeend`,`<span class="k-notif__badge" aria-hidden="true">${e>99?`${a(this,99)}+`:a(this,e)}</span>`)):e||r?.remove(),this.last=e}};j.observedAttributes=[...A.observedAttributes,`placement`],s(`kashi-drawer`,x),s(`kashi-bottom-sheet`,C),s(`kashi-navbar`,T,`block`),s(`kashi-notification-list`,A,`block`),s(`kashi-notification-center`,j),typeof document<`u`&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`[data-kashi-open]`);if(!t)return;let n=document.getElementById(t.getAttribute(`data-kashi-open`));(n instanceof x||n instanceof C)&&(e.preventDefault(),n.show())});export{C as KashiBottomSheet,x as KashiDrawer,T as KashiNavbar,j as KashiNotificationCenter,A as KashiNotificationList};
|
package/dist/content.js
CHANGED
|
@@ -478,7 +478,8 @@ export class KashiMeter extends HTMLBase {
|
|
|
478
478
|
const box = this.box;
|
|
479
479
|
box.dataset.status = status;
|
|
480
480
|
box.querySelector(".k-meter__label").textContent = label;
|
|
481
|
-
|
|
481
|
+
// «۷۰ از ۱۰۰» مثل نسخهٔ React؛ بدون ویژگی of، «از» از پیامهای محلی
|
|
482
|
+
box.querySelector(".k-meter__value").innerHTML = `${esc(fmt(v))} <span>${esc(of != null ? `${of} ${fmt(max)}` : msg().common.of("", fmt(max)).trim())}</span>`;
|
|
482
483
|
const track = box.querySelector(".k-meter__track");
|
|
483
484
|
track.setAttribute("aria-valuenow", String(v));
|
|
484
485
|
track.setAttribute("aria-valuemax", String(max));
|
package/dist/manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.24.1",
|
|
3
3
|
"elements": [
|
|
4
4
|
{
|
|
5
5
|
"tag": "kashi-national-id",
|
|
@@ -578,7 +578,11 @@
|
|
|
578
578
|
"module": "overlay",
|
|
579
579
|
"attributes": [
|
|
580
580
|
"content",
|
|
581
|
-
"placement"
|
|
581
|
+
"placement",
|
|
582
|
+
"heading",
|
|
583
|
+
"shortcut",
|
|
584
|
+
"disabled",
|
|
585
|
+
"open"
|
|
582
586
|
],
|
|
583
587
|
"properties": [],
|
|
584
588
|
"model": null
|
|
@@ -1924,7 +1928,8 @@
|
|
|
1924
1928
|
"module": "buttons",
|
|
1925
1929
|
"attributes": [
|
|
1926
1930
|
"type",
|
|
1927
|
-
"flush"
|
|
1931
|
+
"flush",
|
|
1932
|
+
"size"
|
|
1928
1933
|
],
|
|
1929
1934
|
"properties": [],
|
|
1930
1935
|
"model": null
|
package/dist/overlay.d.ts
CHANGED
|
@@ -58,7 +58,8 @@ export declare class KashiTooltip extends HTMLBase {
|
|
|
58
58
|
connectedCallback(): void;
|
|
59
59
|
private setup;
|
|
60
60
|
disconnectedCallback(): void;
|
|
61
|
-
attributeChangedCallback(): void;
|
|
61
|
+
attributeChangedCallback(name: string): void;
|
|
62
|
+
private trigger;
|
|
62
63
|
private place;
|
|
63
64
|
private open;
|
|
64
65
|
private close;
|
package/dist/overlay.js
CHANGED
|
@@ -280,6 +280,7 @@ export class KashiTooltip extends HTMLBase {
|
|
|
280
280
|
super(...arguments);
|
|
281
281
|
this.tip = null;
|
|
282
282
|
this.key = uid("kashi-tip");
|
|
283
|
+
this.trigger = null;
|
|
283
284
|
this.place = () => placeTip(this, this.tip, this.getAttribute("placement") || "top");
|
|
284
285
|
this.onKey = (e) => {
|
|
285
286
|
if (e.key === "Escape") {
|
|
@@ -302,30 +303,39 @@ export class KashiTooltip extends HTMLBase {
|
|
|
302
303
|
this.append(tip);
|
|
303
304
|
this.tip = tip;
|
|
304
305
|
const trigger = this.firstElementChild !== tip ? this.firstElementChild : null;
|
|
305
|
-
if (trigger)
|
|
306
|
-
trigger.setAttribute("aria-describedby", [trigger.getAttribute("aria-describedby"), this.key].filter(Boolean).join(" "));
|
|
307
306
|
this.addEventListener("mouseenter", () => this.show(Number(this.getAttribute("delay") ?? 300)));
|
|
307
|
+
this.trigger = trigger;
|
|
308
308
|
this.addEventListener("mouseleave", () => this.hide());
|
|
309
309
|
this.addEventListener("focusin", () => this.show(0));
|
|
310
310
|
this.addEventListener("focusout", () => this.hide());
|
|
311
311
|
}
|
|
312
312
|
this.decorate();
|
|
313
|
+
if (this.hasAttribute("open"))
|
|
314
|
+
this.open();
|
|
313
315
|
}
|
|
314
316
|
disconnectedCallback() {
|
|
315
317
|
clearTimeout(this.timer);
|
|
316
318
|
this.close();
|
|
317
319
|
}
|
|
318
|
-
attributeChangedCallback() {
|
|
319
|
-
if (this.tip)
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
attributeChangedCallback(name) {
|
|
321
|
+
if (!this.tip)
|
|
322
|
+
return;
|
|
323
|
+
this.decorate();
|
|
324
|
+
if (name === "open" || name === "disabled") {
|
|
325
|
+
if (this.hasAttribute("open") && !this.hasAttribute("disabled"))
|
|
326
|
+
this.open();
|
|
327
|
+
else
|
|
328
|
+
this.close();
|
|
329
|
+
}
|
|
330
|
+
if (!this.tip.hidden)
|
|
322
331
|
this.place();
|
|
323
332
|
}
|
|
324
333
|
open() {
|
|
325
334
|
const tip = this.tip;
|
|
326
|
-
if (!tip.hidden)
|
|
335
|
+
if (!tip.hidden || this.hasAttribute("disabled"))
|
|
327
336
|
return;
|
|
328
337
|
tip.hidden = false;
|
|
338
|
+
emit(this, "kashi-toggle", { open: true });
|
|
329
339
|
this.place();
|
|
330
340
|
document.addEventListener("keydown", this.onKey);
|
|
331
341
|
addEventListener("scroll", this.place, { capture: true, passive: true });
|
|
@@ -334,6 +344,11 @@ export class KashiTooltip extends HTMLBase {
|
|
|
334
344
|
close() {
|
|
335
345
|
if (!this.tip)
|
|
336
346
|
return;
|
|
347
|
+
// با ویژگی open، راهنما کنترلشده است و hover یا فوکوس آن را نمیبندد
|
|
348
|
+
if (this.hasAttribute("open") && !this.hasAttribute("disabled") && this.isConnected)
|
|
349
|
+
return;
|
|
350
|
+
if (!this.tip.hidden)
|
|
351
|
+
emit(this, "kashi-toggle", { open: false });
|
|
337
352
|
this.tip.hidden = true;
|
|
338
353
|
unplaceTip(this.tip);
|
|
339
354
|
document.removeEventListener("keydown", this.onKey);
|
|
@@ -341,9 +356,25 @@ export class KashiTooltip extends HTMLBase {
|
|
|
341
356
|
removeEventListener("resize", this.place);
|
|
342
357
|
}
|
|
343
358
|
decorate() {
|
|
359
|
+
const tip = this.tip;
|
|
344
360
|
const placement = this.getAttribute("placement");
|
|
345
|
-
|
|
346
|
-
|
|
361
|
+
const heading = this.getAttribute("heading");
|
|
362
|
+
const shortcut = this.getAttribute("shortcut");
|
|
363
|
+
tip.className = `k-tooltip${placement && placement !== "top" ? ` k-tooltip--${placement}` : ""}${heading ? " k-tooltip--rich" : ""}`;
|
|
364
|
+
const content = esc(this.getAttribute("content") ?? "");
|
|
365
|
+
tip.innerHTML = (heading ? `<span class="k-tooltip__title">${esc(heading)}</span><span class="k-tooltip__body">${content}</span>` : content)
|
|
366
|
+
+ (shortcut ? `<kbd class="k-tooltip__kbd" dir="ltr">${esc(shortcut)}</kbd>` : "");
|
|
367
|
+
// غیرفعال: راهنما به عنصر وصل نمیماند تا صفحهخوان متن پنهان را نخواند
|
|
368
|
+
const t = this.trigger;
|
|
369
|
+
if (t) {
|
|
370
|
+
const ids = (t.getAttribute("aria-describedby") ?? "").split(" ").filter((x) => x && x !== this.key);
|
|
371
|
+
if (!this.hasAttribute("disabled"))
|
|
372
|
+
ids.push(this.key);
|
|
373
|
+
if (ids.length)
|
|
374
|
+
t.setAttribute("aria-describedby", ids.join(" "));
|
|
375
|
+
else
|
|
376
|
+
t.removeAttribute("aria-describedby");
|
|
377
|
+
}
|
|
347
378
|
}
|
|
348
379
|
show(wait) {
|
|
349
380
|
clearTimeout(this.timer);
|
|
@@ -351,10 +382,10 @@ export class KashiTooltip extends HTMLBase {
|
|
|
351
382
|
}
|
|
352
383
|
hide() {
|
|
353
384
|
clearTimeout(this.timer);
|
|
354
|
-
this.timer = setTimeout(() => this.close(), 100);
|
|
385
|
+
this.timer = setTimeout(() => this.close(), Number(this.getAttribute("close-delay") ?? 100));
|
|
355
386
|
}
|
|
356
387
|
}
|
|
357
|
-
KashiTooltip.observedAttributes = ["content", "placement"];
|
|
388
|
+
KashiTooltip.observedAttributes = ["content", "placement", "heading", "shortcut", "disabled", "open"];
|
|
358
389
|
/** دکمهٔ کپی در کلیپبورد با بازخورد «کپی شد» برای چشم و صفحهخوان */
|
|
359
390
|
export class KashiCopyButton extends HTMLBase {
|
|
360
391
|
constructor() {
|
package/dist/sheets.js
CHANGED
|
@@ -544,7 +544,7 @@ export class KashiNotificationList extends HTMLBase {
|
|
|
544
544
|
const viewAll = this.getAttribute("view-all-href");
|
|
545
545
|
const row = (it) => {
|
|
546
546
|
const t = toDate(it.time) ?? now;
|
|
547
|
-
const inner = `${it.image ? `<span class="k-notif__media"${it.tone ? ` data-tone="${it.tone}"` : ""}><img src="${esc(it.image)}" alt=""></span>` : it.tone ? `<span class="k-notif__media" data-tone="${it.tone}">${BELL}</span>` : ""}<span class="k-notif__text"><span class="k-notif__item-title">${esc(it.title)}</span>${it.body ? `<span class="k-notif__body">${esc(it.body)}</span>` : ""}<time class="k-notif__time" datetime="${t.toISOString()}">${esc(formatRelative(t, { now, locale: lang(), digits: digitsOf(this) }))}</time></span>`;
|
|
547
|
+
const inner = `${it.image ? `<span class="k-notif__media"${it.tone ? ` data-tone="${it.tone}"` : ""}><img src="${esc(it.image)}" alt=""></span>` : it.tone ? `<span class="k-notif__media" data-tone="${it.tone}">${BELL}</span>` : ""}<span class="k-notif__text"><span class="k-notif__item-title">${esc(it.title)}</span>${it.read ? "" : `<span class="k-sr-only"> ${esc(N.unreadDot)}</span>`}${it.body ? `<span class="k-notif__body">${esc(it.body)}</span>` : ""}<time class="k-notif__time" datetime="${t.toISOString()}">${esc(formatRelative(t, { now, locale: lang(), digits: digitsOf(this) }))}</time></span>`;
|
|
548
548
|
return `<li class="k-notif__item" data-id="${esc(it.id)}"${it.read ? "" : " data-unread"}>${it.href ? `<a class="k-notif__main" href="${esc(it.href)}">${inner}</a>` : `<button type="button" class="k-notif__main">${inner}</button>`}${it.read ? "" : `<button type="button" class="k-notif__dot" aria-label="${esc(N.markRead)}" title="${esc(N.markRead)}"><span aria-hidden="true"></span></button>`}</li>`;
|
|
549
549
|
};
|
|
550
550
|
this.root.innerHTML = `<div class="k-notif__head"><h2 class="k-notif__title">${esc(this.getAttribute("heading") ?? N.label)}</h2>${unread > 0 ? `<button type="button" class="k-notif__link" data-act="all">${CHECK_ALL}${esc(N.markAll)}</button>` : ""}${bool(this, "settings") ? `<button type="button" class="k-notif__icon" data-act="settings" aria-label="${esc(N.settings)}">${GEAR}</button>` : ""}</div><div class="k-notif__tabs" role="group">${["all", "unread"].map((t) => `<button type="button" class="k-notif__tab" data-tab="${t}" aria-pressed="${this.tab === t}">${esc(N[t])}${t === "unread" && unread > 0 ? `<span class="k-notif__count">${num(this, unread)}</span>` : ""}</button>`).join("")}</div>${list.length === 0 ? `<div class="k-notif__empty"><span class="k-notif__empty-icon">${BELL}</span><p>${esc(this.tab === "unread" ? N.emptyUnread : N.empty)}</p></div>` : `<div class="k-notif__scroll" tabindex="-1">${groups.filter(([, g]) => g.length).map(([name, g]) => `<section class="k-notif__group" aria-label="${esc(name)}"><h3 class="k-notif__group-title">${esc(name)}</h3><ul class="k-notif__list">${g.map(row).join("")}</ul></section>`).join("")}</div>`}${viewAll ? `<a class="k-notif__all" href="${esc(viewAll)}">${esc(N.viewAll)}</a>` : ""}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/elements",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.1",
|
|
4
4
|
"description": "وب کامپوننتهای کاشی: فیلدهای فارسی، تقویم شمسی و کامپوننتهای تعاملی بدون React؛ برای HTML، Vue، Svelte، Angular و وردپرس",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"test": "node --test test/*.test.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@kashi-ui/bank-logos": "^2.
|
|
32
|
-
"@kashi-ui/persian": "^2.
|
|
31
|
+
"@kashi-ui/bank-logos": "^2.24.1",
|
|
32
|
+
"@kashi-ui/persian": "^2.24.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@kashi-ui/css": "^2.
|
|
35
|
+
"@kashi-ui/css": "^2.24.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"happy-dom": "^21.0.4",
|