@kashi-ui/elements 2.11.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,D as t,E as n,O as r,a as i,d as a,f as o,k as s,l as c,o as l,p as u,t as d,x as f,y as p}from"./base-DKLHnHWK.js";const m=e=>s(e,{digits:o()}),h=e=>m(Math.round(e*10)/10).replace(`.`,u().common.decimal),g=e=>{let t=Math.abs(e),n=u().chart;return t>=1e9?h(e/1e9)+n.billion:t>=1e6?h(e/1e6)+n.million:t>=1e3?h(e/1e3)+n.thousand:m(e)};function _(e,t=4){if(e<=0)return[0];let n=e/t,r=10**Math.floor(Math.log10(n)),i=[1,2,2.5,5,10].map(e=>e*r).find(e=>e>=n);return Array.from({length:Math.ceil(e/i)+1},(e,t)=>t*i)}const v=(e,t)=>u().common.percent(h(e/(t||1)*100)),y=e=>e<8?`var(--k-chart-${e+1})`:`var(--k-text-quaternary)`,b=(e,t)=>{if(!e)return t;try{return JSON.parse(e)}catch{return t}};var x=class extends d{constructor(){super(...arguments),this.key=p(`kashi-chart`),this.props={}}connectedCallback(){this.draw()}attributeChangedCallback(){this.isConnected&&this.draw()}get format(){let e=this.getAttribute(`unit`);return this.fmt??(t=>`${m(Math.round(t))}${e?` ${e}`:``}`)}set format(e){this.fmt=e,this.isConnected&&this.draw()}read(e,t){return this.props[e]??b(this.getAttribute(e),t)}write(e,t){this.props[e]=t,this.isConnected&&this.draw()}get heading(){return this.getAttribute(`label`)??``}tip(e,t,n=0,r,i=[]){let a=e.querySelector(`:scope > .k-chart__tip`);if(t===null){a?.remove();return}a||(a=document.createElement(`div`),a.className=`k-chart__tip`,a.setAttribute(`aria-hidden`,`true`),e.append(a));let o=e.clientWidth;a.style.left=`${o?Math.min(Math.max(t,80),o-80):t}px`,a.style.top=`${n}px`,a.innerHTML=`${r?`<span class="k-chart__tip-title">${c(r)}</span>`:``}${i.map(e=>`<span class="k-chart__tip-row"${e.color?` style="--_c: ${e.color}"`:``}>${e.name===void 0?``:`<span>${e.color?`<i></i>`:``}${c(e.name)}</span>`}<strong>${c(e.value)}</strong></span>`).join(``)}`}at(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return{x:r.left+r.width/2-n.left,y:r.top-n.top}}},S=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}draw(){let e=this.format,t=this.series.length?this.series.slice(0,4):null,n=this.data,r=t?this.labels:n.map(e=>e.label),i=r.map((e,r)=>t?t.reduce((e,t)=>e+(t.values[r]??0),0):n[r].value),a=Math.max(0,...i),o=_(a),s=o.at(-1)||1,l=i.indexOf(a),d=this.getAttribute(`label-max`)!==`false`,f=n=>t?`${r[n]}: ${t.map(t=>`${t.name} ${e(t.values[n]??0)}`).join(u().common.list)}${u().common.list}${u().common.total} ${e(i[n])}`:`${r[n]}: ${e(i[n])}`,p=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart k-chart--bar" aria-labelledby="${this.key}-t" style="margin: 0${p?`; --k-chart-height: ${c(p)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p>${t&&t.length>1?`<ul class="k-chart__legend" aria-hidden="true">${t.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key k-chart__key--box"></span>${c(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot"><div class="k-bars__grid" aria-hidden="true">${o.map(e=>`<span data-v="${c(g(e))}"></span>`).join(``)}</div><div class="k-bars" role="list" aria-label="${c(this.heading)}">${r.map((n,r)=>`<div class="k-bars__col" role="listitem" tabindex="0" data-i="${r}" aria-label="${c(f(r))}" style="--_d: ${r*40}ms">${d&&r===l?`<span class="k-bars__value" aria-hidden="true">${c(e(i[r]))}</span>`:``}${t?`<span class="k-bars__stack" style="block-size: ${i[r]/s*100}%" aria-hidden="true">${t.map((e,t)=>`<span class="k-bars__seg" style="--_c: ${y(t)}; flex-grow: ${e.values[r]??0}"></span>`).join(``)}</span>`:`<span class="k-bars__bar" style="block-size: ${i[r]/s*100}%" aria-hidden="true"></span>`}<span class="k-bars__label" aria-hidden="true">${c(n)}</span></div>`).join(``)}</div></div></figure>`;let m=this.querySelector(`.k-chart__plot`),h=n=>{let a=Number(n.dataset.i);m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-bars__bar, .k-bars__stack`)??n,m);this.tip(m,o.x,o.y,r[a],t?[...t.map((t,n)=>({name:t.name,value:e(t.values[a]??0),color:y(n)})),{name:u().common.total,value:e(i[a])}]:[{value:e(i[a])}])},v=()=>{m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),this.tip(m,null)};m.querySelectorAll(`.k-bars__col`).forEach(e=>{e.addEventListener(`pointerenter`,()=>h(e)),e.addEventListener(`focus`,()=>h(e)),e.addEventListener(`pointerleave`,v),e.addEventListener(`blur`,v)})}};S.observedAttributes=[`label`,`data`,`labels`,`series`,`unit`,`label-max`,`height`];var C=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data,n=Math.max(1,...t.map(e=>e.value)),r=t.reduce((e,t)=>e+t.value,0);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><ol class="k-barlist" style="position: relative">${t.map((t,i)=>`<li class="k-barlist__row" data-i="${i}" style="--_d: ${i*60}ms"><span class="k-barlist__track"><span class="k-barlist__fill" style="inline-size: ${t.value/n*100}%" aria-hidden="true"></span>${t.href?`<a class="k-barlist__label" href="${c(t.href)}">${c(t.label)}</a>`:`<span class="k-barlist__label">${c(t.label)}</span>`}</span><span class="k-barlist__value">${c(e(t.value))} <span class="k-barlist__share">${v(t.value,r)}</span></span></li>`).join(``)}</ol></figure>`;let i=this.querySelector(`.k-barlist`);i.querySelectorAll(`.k-barlist__row`).forEach(n=>{n.addEventListener(`pointerenter`,()=>{let a=t[Number(n.dataset.i)];n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-barlist__fill`),i);this.tip(i,o.x,o.y,a.label,[{name:u().chart.value,value:e(a.value)},{name:u().chart.share,value:v(a.value,r)}])}),n.addEventListener(`pointerleave`,()=>{n.removeAttribute(`data-active`),this.tip(i,null)})})}};C.observedAttributes=[`label`,`data`,`unit`];var w=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data.slice(0,4),n=t.reduce((e,t)=>e+t.value,0),r=this.getAttribute(`percent`)!==`false`;this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><div class="k-proportion__wrap"><div class="k-proportion" aria-hidden="true">${t.map((e,t)=>`<span class="k-proportion__seg" data-i="${t}" style="--_c: ${y(t)}; flex-grow: ${e.value}"></span>`).join(``)}</div></div><ul class="k-proportion__legend">${t.map((t,i)=>`<li data-i="${i}" style="--_c: ${y(i)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span>${c(t.label)}</span><strong>${c(r?v(t.value,n):e(t.value))}</strong>${r?`<span class="k-proportion__abs">${c(e(t.value))}</span>`:``}</li>`).join(``)}</ul></figure>`;let i=this.querySelector(`.k-proportion__wrap`),a=e=>this.querySelectorAll(`[data-i]`).forEach(t=>t.toggleAttribute(`data-active`,Number(t.dataset.i)===e));i.querySelectorAll(`.k-proportion__seg`).forEach(r=>{r.addEventListener(`pointerenter`,()=>{let o=Number(r.dataset.i);a(o);let s=this.at(r,i);this.tip(i,s.x,s.y,void 0,[{name:t[o].label,value:v(t[o].value,n),color:y(o)},{name:u().chart.count,value:e(t[o].value)}])}),r.addEventListener(`pointerleave`,()=>{a(null),this.tip(i,null)})})}};w.observedAttributes=[`label`,`data`,`unit`,`percent`];var T=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=[...this.data].sort((e,t)=>t.value-e.value),n=t.length>5?[...t.slice(0,4),{label:u().common.other,value:t.slice(4).reduce((e,t)=>e+t.value,0)}]:t,r=n.reduce((e,t)=>e+t.value,0)||1,i=e=>e<4?y(e):`var(--k-text-quaternary)`,a=this.getAttribute(`variant`)!==`pie`,o=Number(this.getAttribute(`size`))||176,s=this.getAttribute(`total-label`)??u().common.total,l=a?40:25,d=a?16:50,f=2*Math.PI*l,p=n.length>1?a?1.6:.8:0,m=0,h=n.map(e=>{let t=e.value/r*f,n={start:m,len:t};return m+=t,n});this.innerHTML=`<figure class="k-chart k-pie" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><div class="k-pie__body"><div class="k-pie__plot" style="inline-size: ${o}px; block-size: ${o}px"><svg viewBox="0 0 100 100" class="k-pie__svg" aria-hidden="true">${a?`<circle cx="50" cy="50" r="${l}" fill="none" stroke="var(--k-bg-tertiary)" stroke-width="${d}"></circle>`:``}${n.map((e,t)=>`<circle class="k-pie__slice" data-i="${t}" cx="50" cy="50" r="${l}" fill="none" stroke="${i(t)}" stroke-width="${d}" stroke-dasharray="${Math.max(0,h[t].len-p)} ${f}" stroke-dashoffset="${-h[t].start}" transform="rotate(-90 50 50)" style="--_d: ${t*80}ms"></circle>`).join(``)}</svg>${a?`<div class="k-pie__center" aria-hidden="true"><strong>${c(e(r))}</strong><span>${c(s)}</span></div>`:``}</div><ul class="k-pie__legend">${n.map((t,n)=>`<li data-i="${n}" style="--_c: ${i(n)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span class="k-pie__name">${c(t.label)}</span><strong>${v(t.value,r)}</strong><span class="k-pie__abs">${c(e(t.value))}</span></li>`).join(``)}</ul></div></figure>`;let g=this.querySelector(`.k-pie__plot`),_=this.querySelector(`.k-pie__center`),b=e=>{let t=(h[e].start+h[e].len/2)/f*2*Math.PI-Math.PI/2,n=a?l:l*1.3;return{x:(50+n*Math.cos(t))/100*o,y:(50+n*Math.sin(t))/100*o-8}},x=t=>{this.querySelectorAll(`[data-i]`).forEach(e=>e.toggleAttribute(`data-active`,Number(e.dataset.i)===t)),_&&(_.innerHTML=t===null?`<strong>${c(e(r))}</strong><span>${c(s)}</span>`:`<strong>${v(n[t].value,r)}</strong><span>${c(n[t].label)}</span>`),a||(t===null?this.tip(g,null):this.tip(g,b(t).x,b(t).y,void 0,[{name:n[t].label,value:v(n[t].value,r),color:i(t)},{name:u().chart.count,value:e(n[t].value)}]))};this.querySelectorAll(`.k-pie__slice, .k-pie__legend li`).forEach(e=>e.addEventListener(`pointerenter`,()=>x(Number(e.dataset.i)))),g.addEventListener(`pointerleave`,()=>x(null)),this.querySelector(`.k-pie__legend`).addEventListener(`pointerleave`,()=>x(null))}};T.observedAttributes=[`label`,`data`,`unit`,`variant`,`total-label`,`size`];var E=class extends x{get values(){return this.props.values??(this.getAttribute(`values`)??``).split(/[,،\s]+/).filter(Boolean).map(Number).filter(e=>!Number.isNaN(e))}set values(e){this.write(`values`,e)}draw(){let e=this.values;if(!e.length){this.innerHTML=``;return}let t=Math.max(...e),n=Math.min(...e),r=Math.max(t-n,Math.abs(t)*.25)||1,i=(t+n)/2-r/2,a=e.map((t,n)=>`${n?`L`:`M`}${n/Math.max(1,e.length-1)*100},${28-(t-i)/r*24}`).join(` `),o=this.getAttribute(`tone`)??`brand`,s=o===`neutral`?`var(--k-text-tertiary)`:o===`brand`?`var(--k-text-brand)`:`var(--k-text-${o})`,l=this.getAttribute(`label`);this.innerHTML=`<svg class="k-sparkline" viewBox="0 0 100 30" preserveAspectRatio="none"${l?` role="img" aria-label="${c(l)}"`:` aria-hidden="true"`} style="color: ${s}">${this.getAttribute(`area`)===`false`?``:`<path d="${a} L100,30 L0,30 Z" fill="currentColor" opacity="0.1"></path>`}<path d="${a}" fill="none" stroke="currentColor" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round" stroke-linecap="round"></path></svg>`}};E.observedAttributes=[`values`,`tone`,`area`,`label`];var D=class extends x{constructor(){super(...arguments),this.ro=null,this.active=null}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}connectedCallback(){if(super.connectedCallback(),typeof ResizeObserver<`u`&&!this.ro){let e=0;this.ro=new ResizeObserver(()=>{let t=this.clientWidth;t&&t!==e&&(e=t,this.paintSvg())}),this.ro.observe(this)}}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}draw(){let e=this.series.slice(0,4),t=this.format,n=this.labels,r=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0${r?`; --k-chart-height: ${c(r)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p>${e.length>1?`<ul class="k-chart__legend" aria-hidden="true">${e.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key"></span>${c(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot" tabindex="0" role="img" aria-label="${c(u().chart.keyboard(this.heading))}" aria-describedby="${this.key}-live"><svg class="k-chart__svg" aria-hidden="true" direction="ltr"></svg></div><span class="k-sr-only" aria-live="polite" id="${this.key}-live"></span><table class="k-sr-only"><caption>${c(this.heading)}</caption><thead><tr><th scope="col">${c(u().chart.period)}</th>${e.map(e=>`<th scope="col">${c(e.name)}</th>`).join(``)}</tr></thead><tbody>${n.map((n,r)=>`<tr><th scope="row">${c(n)}</th>${e.map(e=>`<td>${c(t(e.values[r]))}</td>`).join(``)}</tr>`).join(``)}</tbody></table></figure>`;let i=this.querySelector(`.k-chart__plot`);i.addEventListener(`pointermove`,e=>this.pick(e.clientX)),i.addEventListener(`pointerleave`,()=>this.setActive(null)),i.addEventListener(`blur`,()=>this.setActive(null)),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,r=n.length,a={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];a?(e.preventDefault(),this.setActive(Math.min(r-1,Math.max(0,(this.active??(a>0?-1:r))+a)))):e.key===`Home`?this.setActive(0):e.key===`End`?this.setActive(r-1):e.key===`Escape`&&this.setActive(null)}),this.active=null,this.paintSvg()}geometry(){let e=this.querySelector(`.k-chart__plot`),t=this.series.slice(0,4),n=this.labels,r=e.clientWidth||600,i=e.clientHeight||220,a=getComputedStyle(e).direction===`rtl`,o={top:12,bottom:24,start:52,end:t.length>1?64:16},s=_(Math.max(0,...t.flatMap(e=>e.values))),c=s.at(-1)||1,l=Math.max(1,r-o.start-o.end),u=Math.max(1,i-o.top-o.bottom);return{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:u,x:e=>{let t=n.length>1?e/(n.length-1):.5;return a?r-o.start-t*l:o.start+t*l},y:e=>o.top+u-e/c*u}}paintSvg(){if(!this.querySelector(`.k-chart__plot`))return;let{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:d,x:f,y:p}=this.geometry(),m=e.querySelector(`svg`),h=a?r-o.start+8:o.start-8,_=a?`start`:`end`,v=n.length-1,b=t.map((e,t)=>({i:t,y:p(e.values[v])})).sort((e,t)=>e.y-t.y);for(let e=1;e<b.length;e++)b[e].y-b[e-1].y<14&&(b[e].y=b[e-1].y+14);let x=Object.fromEntries(b.map(e=>[e.i,e.y])),S=Math.max(1,Math.ceil(n.length/Math.max(2,Math.floor(l/64)))),C=`${this.key}-fade`,w=this.active;m.innerHTML=`<g class="k-chart__grid">${s.map(e=>`<line x1="${o.start}" x2="${r-o.end}" y1="${p(e)}" y2="${p(e)}"${a?` transform="translate(${o.end-o.start} 0)"`:``}></line>`).join(``)}</g>${s.map(e=>`<text class="k-chart__tick" x="${h}" y="${p(e)+4}" text-anchor="${_}">${c(g(e))}</text>`).join(``)}${n.map((e,t)=>t%S===0||t===v?`<text class="k-chart__tick" x="${f(t)}" y="${i-6}" text-anchor="middle">${c(e)}</text>`:``).join(``)}<defs><linearGradient id="${C}" x1="0" y1="0" x2="0" y2="1"><stop offset="0" style="stop-color: var(--k-chart-1); stop-opacity: 0.28"></stop><stop offset="1" style="stop-color: var(--k-chart-1); stop-opacity: 0"></stop></linearGradient></defs>${t.length===1&&this.getAttribute(`area`)!==`false`?`<path class="k-chart__area" fill="url(#${C})" d="M${f(0)},${p(0)} ${t[0].values.map((e,t)=>`L${f(t)},${p(e)}`).join(` `)} L${f(v)},${p(0)} Z"></path>`:``}${w===null?``:`<line class="k-chart__cross" x1="${f(w)}" x2="${f(w)}" y1="${o.top}" y2="${o.top+d}"></line>`}${t.map((e,n)=>`<g style="--_c: ${y(n)}"><path class="k-chart__line" pathLength="1" d="${e.values.map((e,t)=>`${t?`L`:`M`}${f(t)},${p(e)}`).join(` `)}"></path><circle class="k-chart__dot" cx="${f(e.values.length-1)}" cy="${p(e.values.at(-1)??0)}" r="4"></circle>${t.length>1?`<text class="k-chart__end" x="${f(v)+(a?-8:8)}" y="${x[n]+4}" text-anchor="${a?`end`:`start`}">${c(e.name)}</text>`:``}${w===null?``:`<circle class="k-chart__dot" cx="${f(w)}" cy="${p(e.values[w])}" r="4.5"></circle>`}</g>`).join(``)}`;let T=this.format;w===null?this.tip(e,null):this.tip(e,f(w),Math.min(...t.map(e=>p(e.values[w])))-6,n[w],t.map((e,t)=>({name:e.name,value:T(e.values[w]),color:y(t)}))),this.querySelector(`#${this.key}-live`).textContent=w===null?``:`${n[w]}: ${t.map(e=>`${e.name} ${T(e.values[w])}`).join(u().common.list)}`}pick(e){let{plot:t,labels:n,x:r}=this.geometry(),i=e-t.getBoundingClientRect().left,a=0;n.forEach((e,t)=>{Math.abs(r(t)-i)<Math.abs(r(a)-i)&&(a=t)}),a!==this.active&&this.setActive(a)}setActive(e){this.active=e,this.paintSvg()}};D.observedAttributes=[`label`,`labels`,`series`,`unit`,`area`,`height`];var O=class extends x{get data(){return this.read(`data`,{})}set data(e){this.write(`data`,e)}draw(){let s=this.data,l=Number(this.getAttribute(`year`))||r(/* @__PURE__ */ new Date).jy,d=u().heatmap,p=this.getAttribute(`unit`)??d.unit,h=[];for(let r=1;r<=12;r++)for(let i=1;i<=e(l,r);i++){let e=n(l,r,i);h.push({date:e,value:s[t(e)]??0})}let g=Math.max(0,...h.map(e=>e.value)),_=e=>e<=0||g===0?0:Math.max(1,Math.ceil(e/g*4)),v=(h[0].date.getDay()+1)%7,y=e=>Math.floor((e+v)/7),b=i().months.map((e,t)=>({name:e,col:y(h.findIndex(e=>r(e.date).jm===t+1))})),x=h.reduce((e,t)=>e+t.value,0),S=i().months.map((e,t)=>({name:e,sum:h.filter(e=>r(e.date).jm===t+1).reduce((e,t)=>e+t.value,0)})),C=m(l).replace(/[٬,]/g,``),w=this.getAttribute(`label`)??d.inYear(p,C);this.innerHTML=`<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll" tabindex="0" role="region" aria-label="${c(w)}"><div role="img" aria-label="${c(`${w}: ${m(x)} ${p}`)}"><div class="k-heatmap__months" aria-hidden="true">${b.map(e=>`<span style="grid-column: ${e.col+1}">${e.name}</span>`).join(``)}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${d.weekdays.map(e=>`<span>${e}</span>`).join(``)}</div><div class="k-heatmap__grid">${`<span class="k-heatmap__cell" data-empty=""></span>`.repeat(v)}${h.map((e,t)=>`<span class="k-heatmap__cell" data-l="${_(e.value)}" data-i="${t}"></span>`).join(``)}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${c(d.total(m(x),p,C))}</span><span class="k-heatmap__scale" aria-hidden="true">${c(d.less)} ${[0,1,2,3,4].map(e=>`<span class="k-heatmap__cell" data-l="${e}"></span>`).join(``)} ${c(d.more)}</span></figcaption><table class="k-sr-only"><caption>${c(d.byMonth(w))}</caption><tbody>${S.map(e=>`<tr><th scope="row">${e.name}</th><td>${m(e.sum)}</td></tr>`).join(``)}</tbody></table></figure>`;let T=this.querySelector(`figure`);this.querySelector(`.k-heatmap__grid`).addEventListener(`pointerover`,e=>{let t=e.target.closest(`[data-i]`);if(T.querySelector(`.k-heatmap__cell[data-active]`)?.removeAttribute(`data-active`),!t)return this.tip(T,null);t.setAttribute(`data-active`,``);let n=this.at(t,T),r=h[Number(t.dataset.i)];this.tip(T,n.x,n.y-2,f(r.date,{style:`full`,digits:o(),locale:a()}),[{value:`${m(r.value)} ${p}`}])}),T.addEventListener(`pointerleave`,()=>this.tip(T,null))}};O.observedAttributes=[`data`,`year`,`unit`,`label`],l(`kashi-bar-chart`,S,`block`),l(`kashi-line-chart`,D,`block`),l(`kashi-pie-chart`,T,`block`),l(`kashi-bar-list`,C,`block`),l(`kashi-proportion-bar`,w,`block`),l(`kashi-sparkline`,E),l(`kashi-activity-heatmap`,O,`block`);export{O as KashiActivityHeatmap,S as KashiBarChart,C as KashiBarList,D as KashiLineChart,T as KashiPieChart,w as KashiProportionBar,E as KashiSparkline};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e,l as t,n,o as r,p as i,t as a}from"./base-DKLHnHWK.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`],()=>import(`./inputs-uY1a-nre.js`)],[[`kashi-otp`],()=>import(`./fields-CxnKgSuq.js`)],[[`kashi-combobox`,`kashi-province-select`,`kashi-city-select`],()=>import(`./combobox-BwKxOiJ1.js`)],[[`kashi-iran-map`,`kashi-address-form`],()=>import(`./map-CFucCeEn.js`)],[[`kashi-calendar`,`kashi-date-picker`],()=>import(`./calendar-Vpy7ydVP.js`)],[[`kashi-money`,`kashi-date`,`kashi-relative-time`,`kashi-countdown`],()=>import(`./display-Dikm099Q.js`)],[[`kashi-dialog`,`kashi-tabs`,`kashi-tooltip`,`kashi-copy-button`],()=>import(`./overlay-Dv3Bup1h.js`)],[[`kashi-dropdown-menu`,`kashi-popover`],()=>import(`./menu-w0p-awwh.js`)],[[`kashi-tag-input`,`kashi-number-input`,`kashi-rating`,`kashi-pagination`],()=>import(`./controls-WVlXKp7B.js`)],[[`kashi-data-table`],()=>import(`./table-2bO-Sb5-.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-Dm0gErE1.js`)],[[`kashi-date-range-picker`,`kashi-month-picker`,`kashi-file-upload`,`kashi-color-picker`],()=>import(`./pickers-Bfnbpl1p.js`)],[[`kashi-bar-chart`,`kashi-line-chart`,`kashi-pie-chart`,`kashi-bar-list`,`kashi-proportion-bar`,`kashi-sparkline`,`kashi-activity-heatmap`],()=>import(`./charts-
|
|
1
|
+
import{g as e,l as t,n,o as r,p as i,t as a}from"./base-DKLHnHWK.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`],()=>import(`./inputs-uY1a-nre.js`)],[[`kashi-otp`],()=>import(`./fields-CxnKgSuq.js`)],[[`kashi-combobox`,`kashi-province-select`,`kashi-city-select`],()=>import(`./combobox-BwKxOiJ1.js`)],[[`kashi-iran-map`,`kashi-address-form`],()=>import(`./map-CFucCeEn.js`)],[[`kashi-calendar`,`kashi-date-picker`],()=>import(`./calendar-Vpy7ydVP.js`)],[[`kashi-money`,`kashi-date`,`kashi-relative-time`,`kashi-countdown`],()=>import(`./display-Dikm099Q.js`)],[[`kashi-dialog`,`kashi-tabs`,`kashi-tooltip`,`kashi-copy-button`],()=>import(`./overlay-Dv3Bup1h.js`)],[[`kashi-dropdown-menu`,`kashi-popover`],()=>import(`./menu-w0p-awwh.js`)],[[`kashi-tag-input`,`kashi-number-input`,`kashi-rating`,`kashi-pagination`],()=>import(`./controls-WVlXKp7B.js`)],[[`kashi-data-table`],()=>import(`./table-2bO-Sb5-.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-Dm0gErE1.js`)],[[`kashi-date-range-picker`,`kashi-month-picker`,`kashi-file-upload`,`kashi-color-picker`],()=>import(`./pickers-Bfnbpl1p.js`)],[[`kashi-bar-chart`,`kashi-line-chart`,`kashi-pie-chart`,`kashi-bar-list`,`kashi-proportion-bar`,`kashi-sparkline`,`kashi-activity-heatmap`],()=>import(`./charts-CyrkwBTe.js`)],[[`kashi-input`,`kashi-textarea`,`kashi-banner`],()=>import(`./basic-CFsfGFWP.js`)],[[`kashi-appointment-picker`],()=>import(`./appointment-DCVtcife.js`)],[[`kashi-price-range`,`kashi-swatch-group`,`kashi-search-suggest`],()=>import(`./commerce-CC6ltOJm.js`)],[[`kashi-command-palette`,`kashi-context-menu`,`kashi-carousel`,`kashi-tree-view`,`kashi-tour`,`kashi-splitter`,`kashi-side-nav`],()=>import(`./nav-sNJGrKcE.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};
|
package/dist/charts.js
CHANGED
|
@@ -25,7 +25,8 @@ function niceTicks(max, count = 4) {
|
|
|
25
25
|
return Array.from({ length: Math.ceil(max / step) + 1 }, (_, i) => i * step);
|
|
26
26
|
}
|
|
27
27
|
const pctOf = (v, total) => msg().common.percent(dec((v / (total || 1)) * 100));
|
|
28
|
-
|
|
28
|
+
/** هشت رنگ دستهای با ترتیب ثابت؛ سری نهم به بعد خنثی («سایر») */
|
|
29
|
+
const chartColor = (i) => (i < 8 ? `var(--k-chart-${i + 1})` : "var(--k-text-quaternary)");
|
|
29
30
|
const json = (t, fallback) => {
|
|
30
31
|
if (!t)
|
|
31
32
|
return fallback;
|
|
@@ -204,6 +205,7 @@ export class KashiPieChart extends Chart {
|
|
|
204
205
|
const sorted = [...this.data].sort((a, b) => b.value - a.value);
|
|
205
206
|
const parts = sorted.length > 5 ? [...sorted.slice(0, 4), { label: msg().common.other, value: sorted.slice(4).reduce((n, d) => n + d.value, 0) }] : sorted;
|
|
206
207
|
const total = parts.reduce((n, d) => n + d.value, 0) || 1;
|
|
208
|
+
// چهار برش رنگی، بقیه در «سایر» با رنگ خنثی جمع میشوند
|
|
207
209
|
const slot = (i) => (i < 4 ? chartColor(i) : "var(--k-text-quaternary)");
|
|
208
210
|
const donut = this.getAttribute("variant") !== "pie";
|
|
209
211
|
const size = Number(this.getAttribute("size")) || 176;
|
|
@@ -414,7 +416,7 @@ export class KashiActivityHeatmap extends Chart {
|
|
|
414
416
|
const monthly = calendarNames().months.map((name, m) => ({ name, sum: days.filter((d) => toJalali(d.date).jm === m + 1).reduce((s, d) => s + d.value, 0) }));
|
|
415
417
|
const yearText = formatNumber(year).replace(/[٬,]/g, "");
|
|
416
418
|
const name = this.getAttribute("label") ?? H.inYear(unit, yearText);
|
|
417
|
-
this.innerHTML = `<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll"><div role="img" aria-label="${esc(`${name}: ${formatNumber(total)} ${unit}`)}"><div class="k-heatmap__months" aria-hidden="true">${months.map((m) => `<span style="grid-column: ${m.col + 1}">${m.name}</span>`).join("")}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${H.weekdays.map((w) => `<span>${w}</span>`).join("")}</div><div class="k-heatmap__grid">${'<span class="k-heatmap__cell" data-empty=""></span>'.repeat(offset)}${days.map((d, i) => `<span class="k-heatmap__cell" data-l="${level(d.value)}" data-i="${i}"></span>`).join("")}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${esc(H.total(formatNumber(total), unit, yearText))}</span><span class="k-heatmap__scale" aria-hidden="true">${esc(H.less)} ${[0, 1, 2, 3, 4].map((l) => `<span class="k-heatmap__cell" data-l="${l}"></span>`).join("")} ${esc(H.more)}</span></figcaption><table class="k-sr-only"><caption>${esc(H.byMonth(name))}</caption><tbody>${monthly.map((m) => `<tr><th scope="row">${m.name}</th><td>${formatNumber(m.sum)}</td></tr>`).join("")}</tbody></table></figure>`;
|
|
419
|
+
this.innerHTML = `<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll" tabindex="0" role="region" aria-label="${esc(name)}"><div role="img" aria-label="${esc(`${name}: ${formatNumber(total)} ${unit}`)}"><div class="k-heatmap__months" aria-hidden="true">${months.map((m) => `<span style="grid-column: ${m.col + 1}">${m.name}</span>`).join("")}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${H.weekdays.map((w) => `<span>${w}</span>`).join("")}</div><div class="k-heatmap__grid">${'<span class="k-heatmap__cell" data-empty=""></span>'.repeat(offset)}${days.map((d, i) => `<span class="k-heatmap__cell" data-l="${level(d.value)}" data-i="${i}"></span>`).join("")}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${esc(H.total(formatNumber(total), unit, yearText))}</span><span class="k-heatmap__scale" aria-hidden="true">${esc(H.less)} ${[0, 1, 2, 3, 4].map((l) => `<span class="k-heatmap__cell" data-l="${l}"></span>`).join("")} ${esc(H.more)}</span></figcaption><table class="k-sr-only"><caption>${esc(H.byMonth(name))}</caption><tbody>${monthly.map((m) => `<tr><th scope="row">${m.name}</th><td>${formatNumber(m.sum)}</td></tr>`).join("")}</tbody></table></figure>`;
|
|
418
420
|
const fig = this.querySelector("figure");
|
|
419
421
|
this.querySelector(".k-heatmap__grid").addEventListener("pointerover", (e) => {
|
|
420
422
|
const cell = e.target.closest("[data-i]");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/elements",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "وب کامپوننتهای کاشی: فیلدهای فارسی، تقویم شمسی و کامپوننتهای تعاملی بدون React؛ برای HTML، Vue، Svelte، Angular و وردپرس",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"test": "node --test test/*.test.mjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@kashi-ui/bank-logos": "^2.
|
|
31
|
-
"@kashi-ui/persian": "^2.
|
|
30
|
+
"@kashi-ui/bank-logos": "^2.15.0",
|
|
31
|
+
"@kashi-ui/persian": "^2.15.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@kashi-ui/css": "^2.
|
|
34
|
+
"@kashi-ui/css": "^2.15.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"happy-dom": "^21.0.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,D as t,E as n,O as r,a as i,d as a,f as o,k as s,l as c,o as l,p as u,t as d,x as f,y as p}from"./base-DKLHnHWK.js";const m=e=>s(e,{digits:o()}),h=e=>m(Math.round(e*10)/10).replace(`.`,u().common.decimal),g=e=>{let t=Math.abs(e),n=u().chart;return t>=1e9?h(e/1e9)+n.billion:t>=1e6?h(e/1e6)+n.million:t>=1e3?h(e/1e3)+n.thousand:m(e)};function _(e,t=4){if(e<=0)return[0];let n=e/t,r=10**Math.floor(Math.log10(n)),i=[1,2,2.5,5,10].map(e=>e*r).find(e=>e>=n);return Array.from({length:Math.ceil(e/i)+1},(e,t)=>t*i)}const v=(e,t)=>u().common.percent(h(e/(t||1)*100)),y=e=>`var(--k-chart-${e+1})`,b=(e,t)=>{if(!e)return t;try{return JSON.parse(e)}catch{return t}};var x=class extends d{constructor(){super(...arguments),this.key=p(`kashi-chart`),this.props={}}connectedCallback(){this.draw()}attributeChangedCallback(){this.isConnected&&this.draw()}get format(){let e=this.getAttribute(`unit`);return this.fmt??(t=>`${m(Math.round(t))}${e?` ${e}`:``}`)}set format(e){this.fmt=e,this.isConnected&&this.draw()}read(e,t){return this.props[e]??b(this.getAttribute(e),t)}write(e,t){this.props[e]=t,this.isConnected&&this.draw()}get heading(){return this.getAttribute(`label`)??``}tip(e,t,n=0,r,i=[]){let a=e.querySelector(`:scope > .k-chart__tip`);if(t===null){a?.remove();return}a||(a=document.createElement(`div`),a.className=`k-chart__tip`,a.setAttribute(`aria-hidden`,`true`),e.append(a));let o=e.clientWidth;a.style.left=`${o?Math.min(Math.max(t,80),o-80):t}px`,a.style.top=`${n}px`,a.innerHTML=`${r?`<span class="k-chart__tip-title">${c(r)}</span>`:``}${i.map(e=>`<span class="k-chart__tip-row"${e.color?` style="--_c: ${e.color}"`:``}>${e.name===void 0?``:`<span>${e.color?`<i></i>`:``}${c(e.name)}</span>`}<strong>${c(e.value)}</strong></span>`).join(``)}`}at(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return{x:r.left+r.width/2-n.left,y:r.top-n.top}}},S=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}draw(){let e=this.format,t=this.series.length?this.series.slice(0,4):null,n=this.data,r=t?this.labels:n.map(e=>e.label),i=r.map((e,r)=>t?t.reduce((e,t)=>e+(t.values[r]??0),0):n[r].value),a=Math.max(0,...i),o=_(a),s=o.at(-1)||1,l=i.indexOf(a),d=this.getAttribute(`label-max`)!==`false`,f=n=>t?`${r[n]}: ${t.map(t=>`${t.name} ${e(t.values[n]??0)}`).join(u().common.list)}${u().common.list}${u().common.total} ${e(i[n])}`:`${r[n]}: ${e(i[n])}`,p=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart k-chart--bar" aria-labelledby="${this.key}-t" style="margin: 0${p?`; --k-chart-height: ${c(p)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p>${t&&t.length>1?`<ul class="k-chart__legend" aria-hidden="true">${t.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key k-chart__key--box"></span>${c(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot"><div class="k-bars__grid" aria-hidden="true">${o.map(e=>`<span data-v="${c(g(e))}"></span>`).join(``)}</div><div class="k-bars" role="list" aria-label="${c(this.heading)}">${r.map((n,r)=>`<div class="k-bars__col" role="listitem" tabindex="0" data-i="${r}" aria-label="${c(f(r))}" style="--_d: ${r*40}ms">${d&&r===l?`<span class="k-bars__value" aria-hidden="true">${c(e(i[r]))}</span>`:``}${t?`<span class="k-bars__stack" style="block-size: ${i[r]/s*100}%" aria-hidden="true">${t.map((e,t)=>`<span class="k-bars__seg" style="--_c: ${y(t)}; flex-grow: ${e.values[r]??0}"></span>`).join(``)}</span>`:`<span class="k-bars__bar" style="block-size: ${i[r]/s*100}%" aria-hidden="true"></span>`}<span class="k-bars__label" aria-hidden="true">${c(n)}</span></div>`).join(``)}</div></div></figure>`;let m=this.querySelector(`.k-chart__plot`),h=n=>{let a=Number(n.dataset.i);m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-bars__bar, .k-bars__stack`)??n,m);this.tip(m,o.x,o.y,r[a],t?[...t.map((t,n)=>({name:t.name,value:e(t.values[a]??0),color:y(n)})),{name:u().common.total,value:e(i[a])}]:[{value:e(i[a])}])},v=()=>{m.querySelector(`[data-active]`)?.removeAttribute(`data-active`),this.tip(m,null)};m.querySelectorAll(`.k-bars__col`).forEach(e=>{e.addEventListener(`pointerenter`,()=>h(e)),e.addEventListener(`focus`,()=>h(e)),e.addEventListener(`pointerleave`,v),e.addEventListener(`blur`,v)})}};S.observedAttributes=[`label`,`data`,`labels`,`series`,`unit`,`label-max`,`height`];var C=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data,n=Math.max(1,...t.map(e=>e.value)),r=t.reduce((e,t)=>e+t.value,0);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><ol class="k-barlist" style="position: relative">${t.map((t,i)=>`<li class="k-barlist__row" data-i="${i}" style="--_d: ${i*60}ms"><span class="k-barlist__track"><span class="k-barlist__fill" style="inline-size: ${t.value/n*100}%" aria-hidden="true"></span>${t.href?`<a class="k-barlist__label" href="${c(t.href)}">${c(t.label)}</a>`:`<span class="k-barlist__label">${c(t.label)}</span>`}</span><span class="k-barlist__value">${c(e(t.value))} <span class="k-barlist__share">${v(t.value,r)}</span></span></li>`).join(``)}</ol></figure>`;let i=this.querySelector(`.k-barlist`);i.querySelectorAll(`.k-barlist__row`).forEach(n=>{n.addEventListener(`pointerenter`,()=>{let a=t[Number(n.dataset.i)];n.setAttribute(`data-active`,``);let o=this.at(n.querySelector(`.k-barlist__fill`),i);this.tip(i,o.x,o.y,a.label,[{name:u().chart.value,value:e(a.value)},{name:u().chart.share,value:v(a.value,r)}])}),n.addEventListener(`pointerleave`,()=>{n.removeAttribute(`data-active`),this.tip(i,null)})})}};C.observedAttributes=[`label`,`data`,`unit`];var w=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=this.data.slice(0,4),n=t.reduce((e,t)=>e+t.value,0),r=this.getAttribute(`percent`)!==`false`;this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><div class="k-proportion__wrap"><div class="k-proportion" aria-hidden="true">${t.map((e,t)=>`<span class="k-proportion__seg" data-i="${t}" style="--_c: ${y(t)}; flex-grow: ${e.value}"></span>`).join(``)}</div></div><ul class="k-proportion__legend">${t.map((t,i)=>`<li data-i="${i}" style="--_c: ${y(i)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span>${c(t.label)}</span><strong>${c(r?v(t.value,n):e(t.value))}</strong>${r?`<span class="k-proportion__abs">${c(e(t.value))}</span>`:``}</li>`).join(``)}</ul></figure>`;let i=this.querySelector(`.k-proportion__wrap`),a=e=>this.querySelectorAll(`[data-i]`).forEach(t=>t.toggleAttribute(`data-active`,Number(t.dataset.i)===e));i.querySelectorAll(`.k-proportion__seg`).forEach(r=>{r.addEventListener(`pointerenter`,()=>{let o=Number(r.dataset.i);a(o);let s=this.at(r,i);this.tip(i,s.x,s.y,void 0,[{name:t[o].label,value:v(t[o].value,n),color:y(o)},{name:u().chart.count,value:e(t[o].value)}])}),r.addEventListener(`pointerleave`,()=>{a(null),this.tip(i,null)})})}};w.observedAttributes=[`label`,`data`,`unit`,`percent`];var T=class extends x{get data(){return this.read(`data`,[])}set data(e){this.write(`data`,e)}draw(){let e=this.format,t=[...this.data].sort((e,t)=>t.value-e.value),n=t.length>5?[...t.slice(0,4),{label:u().common.other,value:t.slice(4).reduce((e,t)=>e+t.value,0)}]:t,r=n.reduce((e,t)=>e+t.value,0)||1,i=e=>e<4?y(e):`var(--k-text-quaternary)`,a=this.getAttribute(`variant`)!==`pie`,o=Number(this.getAttribute(`size`))||176,s=this.getAttribute(`total-label`)??u().common.total,l=a?40:25,d=a?16:50,f=2*Math.PI*l,p=n.length>1?a?1.6:.8:0,m=0,h=n.map(e=>{let t=e.value/r*f,n={start:m,len:t};return m+=t,n});this.innerHTML=`<figure class="k-chart k-pie" aria-labelledby="${this.key}-t" style="margin: 0"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p></figcaption><div class="k-pie__body"><div class="k-pie__plot" style="inline-size: ${o}px; block-size: ${o}px"><svg viewBox="0 0 100 100" class="k-pie__svg" aria-hidden="true">${a?`<circle cx="50" cy="50" r="${l}" fill="none" stroke="var(--k-bg-tertiary)" stroke-width="${d}"></circle>`:``}${n.map((e,t)=>`<circle class="k-pie__slice" data-i="${t}" cx="50" cy="50" r="${l}" fill="none" stroke="${i(t)}" stroke-width="${d}" stroke-dasharray="${Math.max(0,h[t].len-p)} ${f}" stroke-dashoffset="${-h[t].start}" transform="rotate(-90 50 50)" style="--_d: ${t*80}ms"></circle>`).join(``)}</svg>${a?`<div class="k-pie__center" aria-hidden="true"><strong>${c(e(r))}</strong><span>${c(s)}</span></div>`:``}</div><ul class="k-pie__legend">${n.map((t,n)=>`<li data-i="${n}" style="--_c: ${i(n)}"><span class="k-chart__key k-chart__key--box" aria-hidden="true"></span><span class="k-pie__name">${c(t.label)}</span><strong>${v(t.value,r)}</strong><span class="k-pie__abs">${c(e(t.value))}</span></li>`).join(``)}</ul></div></figure>`;let g=this.querySelector(`.k-pie__plot`),_=this.querySelector(`.k-pie__center`),b=e=>{let t=(h[e].start+h[e].len/2)/f*2*Math.PI-Math.PI/2,n=a?l:l*1.3;return{x:(50+n*Math.cos(t))/100*o,y:(50+n*Math.sin(t))/100*o-8}},x=t=>{this.querySelectorAll(`[data-i]`).forEach(e=>e.toggleAttribute(`data-active`,Number(e.dataset.i)===t)),_&&(_.innerHTML=t===null?`<strong>${c(e(r))}</strong><span>${c(s)}</span>`:`<strong>${v(n[t].value,r)}</strong><span>${c(n[t].label)}</span>`),a||(t===null?this.tip(g,null):this.tip(g,b(t).x,b(t).y,void 0,[{name:n[t].label,value:v(n[t].value,r),color:i(t)},{name:u().chart.count,value:e(n[t].value)}]))};this.querySelectorAll(`.k-pie__slice, .k-pie__legend li`).forEach(e=>e.addEventListener(`pointerenter`,()=>x(Number(e.dataset.i)))),g.addEventListener(`pointerleave`,()=>x(null)),this.querySelector(`.k-pie__legend`).addEventListener(`pointerleave`,()=>x(null))}};T.observedAttributes=[`label`,`data`,`unit`,`variant`,`total-label`,`size`];var E=class extends x{get values(){return this.props.values??(this.getAttribute(`values`)??``).split(/[,،\s]+/).filter(Boolean).map(Number).filter(e=>!Number.isNaN(e))}set values(e){this.write(`values`,e)}draw(){let e=this.values;if(!e.length){this.innerHTML=``;return}let t=Math.max(...e),n=Math.min(...e),r=Math.max(t-n,Math.abs(t)*.25)||1,i=(t+n)/2-r/2,a=e.map((t,n)=>`${n?`L`:`M`}${n/Math.max(1,e.length-1)*100},${28-(t-i)/r*24}`).join(` `),o=this.getAttribute(`tone`)??`brand`,s=o===`neutral`?`var(--k-text-tertiary)`:o===`brand`?`var(--k-text-brand)`:`var(--k-text-${o})`,l=this.getAttribute(`label`);this.innerHTML=`<svg class="k-sparkline" viewBox="0 0 100 30" preserveAspectRatio="none"${l?` role="img" aria-label="${c(l)}"`:` aria-hidden="true"`} style="color: ${s}">${this.getAttribute(`area`)===`false`?``:`<path d="${a} L100,30 L0,30 Z" fill="currentColor" opacity="0.1"></path>`}<path d="${a}" fill="none" stroke="currentColor" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round" stroke-linecap="round"></path></svg>`}};E.observedAttributes=[`values`,`tone`,`area`,`label`];var D=class extends x{constructor(){super(...arguments),this.ro=null,this.active=null}get labels(){return this.read(`labels`,[])}set labels(e){this.write(`labels`,e)}get series(){return this.read(`series`,[])}set series(e){this.write(`series`,e)}connectedCallback(){if(super.connectedCallback(),typeof ResizeObserver<`u`&&!this.ro){let e=0;this.ro=new ResizeObserver(()=>{let t=this.clientWidth;t&&t!==e&&(e=t,this.paintSvg())}),this.ro.observe(this)}}disconnectedCallback(){this.ro?.disconnect(),this.ro=null}draw(){let e=this.series.slice(0,4),t=this.format,n=this.labels,r=this.getAttribute(`height`);this.innerHTML=`<figure class="k-chart" aria-labelledby="${this.key}-t" style="margin: 0${r?`; --k-chart-height: ${c(r)}`:``}"><figcaption class="k-chart__head"><p class="k-chart__title" id="${this.key}-t">${c(this.heading)}</p>${e.length>1?`<ul class="k-chart__legend" aria-hidden="true">${e.map((e,t)=>`<li style="--_c: ${y(t)}"><span class="k-chart__key"></span>${c(e.name)}</li>`).join(``)}</ul>`:``}</figcaption><div class="k-chart__plot" tabindex="0" role="img" aria-label="${c(u().chart.keyboard(this.heading))}" aria-describedby="${this.key}-live"><svg class="k-chart__svg" aria-hidden="true" direction="ltr"></svg></div><span class="k-sr-only" aria-live="polite" id="${this.key}-live"></span><table class="k-sr-only"><caption>${c(this.heading)}</caption><thead><tr><th scope="col">${c(u().chart.period)}</th>${e.map(e=>`<th scope="col">${c(e.name)}</th>`).join(``)}</tr></thead><tbody>${n.map((n,r)=>`<tr><th scope="row">${c(n)}</th>${e.map(e=>`<td>${c(t(e.values[r]))}</td>`).join(``)}</tr>`).join(``)}</tbody></table></figure>`;let i=this.querySelector(`.k-chart__plot`);i.addEventListener(`pointermove`,e=>this.pick(e.clientX)),i.addEventListener(`pointerleave`,()=>this.setActive(null)),i.addEventListener(`blur`,()=>this.setActive(null)),i.addEventListener(`keydown`,e=>{let t=getComputedStyle(i).direction===`rtl`,r=n.length,a={ArrowLeft:t?1:-1,ArrowRight:t?-1:1}[e.key];a?(e.preventDefault(),this.setActive(Math.min(r-1,Math.max(0,(this.active??(a>0?-1:r))+a)))):e.key===`Home`?this.setActive(0):e.key===`End`?this.setActive(r-1):e.key===`Escape`&&this.setActive(null)}),this.active=null,this.paintSvg()}geometry(){let e=this.querySelector(`.k-chart__plot`),t=this.series.slice(0,4),n=this.labels,r=e.clientWidth||600,i=e.clientHeight||220,a=getComputedStyle(e).direction===`rtl`,o={top:12,bottom:24,start:52,end:t.length>1?64:16},s=_(Math.max(0,...t.flatMap(e=>e.values))),c=s.at(-1)||1,l=Math.max(1,r-o.start-o.end),u=Math.max(1,i-o.top-o.bottom);return{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:u,x:e=>{let t=n.length>1?e/(n.length-1):.5;return a?r-o.start-t*l:o.start+t*l},y:e=>o.top+u-e/c*u}}paintSvg(){if(!this.querySelector(`.k-chart__plot`))return;let{plot:e,shown:t,labels:n,w:r,h:i,rtl:a,pad:o,ticks:s,innerW:l,innerH:d,x:f,y:p}=this.geometry(),m=e.querySelector(`svg`),h=a?r-o.start+8:o.start-8,_=a?`start`:`end`,v=n.length-1,b=t.map((e,t)=>({i:t,y:p(e.values[v])})).sort((e,t)=>e.y-t.y);for(let e=1;e<b.length;e++)b[e].y-b[e-1].y<14&&(b[e].y=b[e-1].y+14);let x=Object.fromEntries(b.map(e=>[e.i,e.y])),S=Math.max(1,Math.ceil(n.length/Math.max(2,Math.floor(l/64)))),C=`${this.key}-fade`,w=this.active;m.innerHTML=`<g class="k-chart__grid">${s.map(e=>`<line x1="${o.start}" x2="${r-o.end}" y1="${p(e)}" y2="${p(e)}"${a?` transform="translate(${o.end-o.start} 0)"`:``}></line>`).join(``)}</g>${s.map(e=>`<text class="k-chart__tick" x="${h}" y="${p(e)+4}" text-anchor="${_}">${c(g(e))}</text>`).join(``)}${n.map((e,t)=>t%S===0||t===v?`<text class="k-chart__tick" x="${f(t)}" y="${i-6}" text-anchor="middle">${c(e)}</text>`:``).join(``)}<defs><linearGradient id="${C}" x1="0" y1="0" x2="0" y2="1"><stop offset="0" style="stop-color: var(--k-chart-1); stop-opacity: 0.28"></stop><stop offset="1" style="stop-color: var(--k-chart-1); stop-opacity: 0"></stop></linearGradient></defs>${t.length===1&&this.getAttribute(`area`)!==`false`?`<path class="k-chart__area" fill="url(#${C})" d="M${f(0)},${p(0)} ${t[0].values.map((e,t)=>`L${f(t)},${p(e)}`).join(` `)} L${f(v)},${p(0)} Z"></path>`:``}${w===null?``:`<line class="k-chart__cross" x1="${f(w)}" x2="${f(w)}" y1="${o.top}" y2="${o.top+d}"></line>`}${t.map((e,n)=>`<g style="--_c: ${y(n)}"><path class="k-chart__line" pathLength="1" d="${e.values.map((e,t)=>`${t?`L`:`M`}${f(t)},${p(e)}`).join(` `)}"></path><circle class="k-chart__dot" cx="${f(e.values.length-1)}" cy="${p(e.values.at(-1)??0)}" r="4"></circle>${t.length>1?`<text class="k-chart__end" x="${f(v)+(a?-8:8)}" y="${x[n]+4}" text-anchor="${a?`end`:`start`}">${c(e.name)}</text>`:``}${w===null?``:`<circle class="k-chart__dot" cx="${f(w)}" cy="${p(e.values[w])}" r="4.5"></circle>`}</g>`).join(``)}`;let T=this.format;w===null?this.tip(e,null):this.tip(e,f(w),Math.min(...t.map(e=>p(e.values[w])))-6,n[w],t.map((e,t)=>({name:e.name,value:T(e.values[w]),color:y(t)}))),this.querySelector(`#${this.key}-live`).textContent=w===null?``:`${n[w]}: ${t.map(e=>`${e.name} ${T(e.values[w])}`).join(u().common.list)}`}pick(e){let{plot:t,labels:n,x:r}=this.geometry(),i=e-t.getBoundingClientRect().left,a=0;n.forEach((e,t)=>{Math.abs(r(t)-i)<Math.abs(r(a)-i)&&(a=t)}),a!==this.active&&this.setActive(a)}setActive(e){this.active=e,this.paintSvg()}};D.observedAttributes=[`label`,`labels`,`series`,`unit`,`area`,`height`];var O=class extends x{get data(){return this.read(`data`,{})}set data(e){this.write(`data`,e)}draw(){let s=this.data,l=Number(this.getAttribute(`year`))||r(/* @__PURE__ */ new Date).jy,d=u().heatmap,p=this.getAttribute(`unit`)??d.unit,h=[];for(let r=1;r<=12;r++)for(let i=1;i<=e(l,r);i++){let e=n(l,r,i);h.push({date:e,value:s[t(e)]??0})}let g=Math.max(0,...h.map(e=>e.value)),_=e=>e<=0||g===0?0:Math.max(1,Math.ceil(e/g*4)),v=(h[0].date.getDay()+1)%7,y=e=>Math.floor((e+v)/7),b=i().months.map((e,t)=>({name:e,col:y(h.findIndex(e=>r(e.date).jm===t+1))})),x=h.reduce((e,t)=>e+t.value,0),S=i().months.map((e,t)=>({name:e,sum:h.filter(e=>r(e.date).jm===t+1).reduce((e,t)=>e+t.value,0)})),C=m(l).replace(/[٬,]/g,``),w=this.getAttribute(`label`)??d.inYear(p,C);this.innerHTML=`<figure class="k-heatmap" style="margin: 0"><div class="k-heatmap__scroll"><div role="img" aria-label="${c(`${w}: ${m(x)} ${p}`)}"><div class="k-heatmap__months" aria-hidden="true">${b.map(e=>`<span style="grid-column: ${e.col+1}">${e.name}</span>`).join(``)}</div><div class="k-heatmap__body" aria-hidden="true"><div class="k-heatmap__days">${d.weekdays.map(e=>`<span>${e}</span>`).join(``)}</div><div class="k-heatmap__grid">${`<span class="k-heatmap__cell" data-empty=""></span>`.repeat(v)}${h.map((e,t)=>`<span class="k-heatmap__cell" data-l="${_(e.value)}" data-i="${t}"></span>`).join(``)}</div></div></div></div><figcaption class="k-heatmap__foot"><span>${c(d.total(m(x),p,C))}</span><span class="k-heatmap__scale" aria-hidden="true">${c(d.less)} ${[0,1,2,3,4].map(e=>`<span class="k-heatmap__cell" data-l="${e}"></span>`).join(``)} ${c(d.more)}</span></figcaption><table class="k-sr-only"><caption>${c(d.byMonth(w))}</caption><tbody>${S.map(e=>`<tr><th scope="row">${e.name}</th><td>${m(e.sum)}</td></tr>`).join(``)}</tbody></table></figure>`;let T=this.querySelector(`figure`);this.querySelector(`.k-heatmap__grid`).addEventListener(`pointerover`,e=>{let t=e.target.closest(`[data-i]`);if(T.querySelector(`.k-heatmap__cell[data-active]`)?.removeAttribute(`data-active`),!t)return this.tip(T,null);t.setAttribute(`data-active`,``);let n=this.at(t,T),r=h[Number(t.dataset.i)];this.tip(T,n.x,n.y-2,f(r.date,{style:`full`,digits:o(),locale:a()}),[{value:`${m(r.value)} ${p}`}])}),T.addEventListener(`pointerleave`,()=>this.tip(T,null))}};O.observedAttributes=[`data`,`year`,`unit`,`label`],l(`kashi-bar-chart`,S,`block`),l(`kashi-line-chart`,D,`block`),l(`kashi-pie-chart`,T,`block`),l(`kashi-bar-list`,C,`block`),l(`kashi-proportion-bar`,w,`block`),l(`kashi-sparkline`,E),l(`kashi-activity-heatmap`,O,`block`);export{O as KashiActivityHeatmap,S as KashiBarChart,C as KashiBarList,D as KashiLineChart,T as KashiPieChart,w as KashiProportionBar,E as KashiSparkline};
|