mayacharts 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! mayacharts v0.1.0 | MIT | https://github.com/BbekShr/mayacharts */
2
- var e={noData:`No data`,other:`Other`,back:`Back`,reset:`Reset zoom`,showing:`Showing {0}`,drilledInto:`Drilled into {0}`,zoomedTo:`Zoomed to {0} – {1}`,selected:`{0} selected`,selectionCleared:`Selection cleared`,chartOf:`{0} chart of {1} by {2}`,firstOf:`First {0} of {1} rows`,measures:`Measure`,crumbs:`Drill path`,positive:`positive`,negative:`negative`,above:`above target`,below:`below target`,vs:`{0} vs {1}`,ofTarget:`{0} of target {1}`};function t(t,n,...r){return((t.text&&Object.hasOwn(t.text,n)?t.text[n]:void 0)??e[n]).replace(/\{(\d)\}/g,(e,t)=>String(r[+t]??``))}var n={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};function r(e){return String(e).replace(/[&<>"']/g,e=>n[e])}function i(e){return Math.round(e*100)/100}function a(e,t,n){let i=``;for(let e in t){let n=t[e];n!=null&&n!==!1&&(i+=n===!0?` ${e}=""`:` ${e}="${r(n)}"`)}return n===void 0?`<${e}${i}/>`:`<${e}${i}>${n}</${e}>`}var o=`\0other`,s=(...e)=>e.map(e=>encodeURIComponent(String(e).replace(/\p{Cs}/gu,`�`)).replace(/~/g,`%7E`)).join(`~`);function c(e,t,n,r,o){let[s,c]=[Math.max(r,24),Math.max(o,24)];return r<24||o<24?a(`rect`,Object.assign({"data-maya":`hit`},e,{"data-maya":`hit`,x:i(t-(s-r)/2),y:i(n-(c-o)/2),width:i(s),height:i(c),fill:`transparent`})):``}var l=e=>e.title??`${e.titles.get(e.y)??e.y} by ${e.titles.get(e.x)??(e.x||e.path.join(` / `))}`,u=[`scatter`,`treemap`,`sunburst`,`sankey`,`hexmap`],d=1e3;function f(e,n,r,i){if(e.description!==null)return e.description;let a=t=>e.titles.get(t)??t,o=t(e,`chartOf`,i,a(e.y),e.x?a(e.x):e.path.join(` / `));if(e.series!==null&&n.series.length&&(o+=`, ${e.stack?`stacked`:`grouped`} by ${a(e.series)} (${n.series.join(`, `)})`),u.includes(e.type))return`${o}. ${e.data.length} rows.`;let s=0,c=1/0,l=-1/0;for(let e of n.cells)e.value!==null&&(s++,c=Math.min(c,e.value),l=Math.max(l,e.value));let d=t=>r(e.y,t);return s?s===1?`${o}. 1 value: ${d(c)}.`:`${o}. ${s} values from ${d(c)} to ${d(l)}.`:o+`. No data.`}function p(e,n,i,a){let o=t=>e.titles.get(t)??t,s=(t,n)=>{if(n==null)return``;let o=t===e.y&&typeof n==`number`?a(n):null;return r(i(t,n))+(o?` (${r(o)})`:``)},c=n=>n>d?t(e,`firstOf`,d,n):l(e),f,p,m;if(u.includes(e.type)){let t=[...new Set([e.x,...e.path,e.series,e.name,e.size,e.y,typeof e.colorBy==`string`&&e.colorBy!==`sign`?e.colorBy:null].filter(e=>!!e))];m=e.data.length,f=t.map(e=>`<th>${r(o(e))}</th>`).join(``),p=e.data.slice(0,d).map(e=>`<tr>${t.map(t=>`<td>${s(t,e[t])}</td>`).join(``)}</tr>`).join(``)}else{let t=e.series===null?[o(e.y)]:n.visible.map(e=>n.series[e]);m=n.categories.length,f=`<th>${r(o(e.x))}</th>`+t.map(e=>`<th>${r(e)}</th>`).join(``);let i=new Map(n.cells.map(e=>[e.ci+`,`+e.si,e.value]));p=``;for(let t=0;t<Math.min(m,d);t++){p+=`<tr><th scope="row">${r(n.categories[t])}</th>`;for(let r of n.visible)p+=`<td>${s(e.y,i.get(t+`,`+r))}</td>`;p+=`</tr>`}}return`<table class="maya-sr"><caption>${r(c(m))}</caption><thead><tr>${f}</tr></thead><tbody>${p}</tbody></table>`}var m=e=>{for(let t=0;t<8;t++)if(Math.abs(e*10**t-Math.round(e*10**t))<1e-9)return t;return 8},h=`year month day hour minute second weekday era timeZone dateStyle timeStyle fractionalSecondDigits hour12 dayPeriod timeZoneName`.split(` `),g={date:{dateStyle:`medium`},month:{month:`short`,year:`numeric`},year:{year:`numeric`},time:{timeStyle:`short`},datetime:{dateStyle:`medium`,timeStyle:`short`}};function _(e,t=e.y,n){typeof t==`number`&&([t,n]=[e.y,t]);let r=e.format.get(t),i=Intl.NumberFormat.supportedLocalesOf(e.locale).length?e.locale:`en-US`,a=n===void 0?2:m(n),o=``,s=``,c=null,l=null,u=typeof r==`string`?r:`auto`;if(typeof r==`string`&&Object.hasOwn(g,r))c=new Intl.DateTimeFormat(i,{timeZone:`UTC`,...g[r]});else if(typeof r==`object`&&r){let{prefix:e=``,suffix:t=``,...n}=r;[o,s]=[String(e),String(t)],h.some(e=>Object.hasOwn(n,e))?c=new Intl.DateTimeFormat(i,{timeZone:`UTC`,...n}):l=new Intl.NumberFormat(i,n)}if(!c&&!l){let t=u===`integer`?{maximumFractionDigits:0}:u===`decimal`?{minimumFractionDigits:2,maximumFractionDigits:2}:u===`compact`?{notation:`compact`,maximumFractionDigits:1}:u===`percent`?{style:`percent`,minimumFractionDigits:Math.max(0,a-2),maximumFractionDigits:Math.max(1,a-2)}:u===`currency`?{style:`currency`,currency:e.currency,minimumFractionDigits:n!==void 0&&n>=1?0:a,maximumFractionDigits:n!==void 0&&n>=1?0:Math.max(a,2)}:{maximumFractionDigits:Math.max(a,2)};l=new Intl.NumberFormat(i,t)}return e=>{if(e==null)return``;let t;if(c){let n=typeof e==`string`&&/^-?\d+$/.test(e)?/* @__PURE__ */ new Date(+e):typeof e==`number`||typeof e==`string`||e instanceof Date?new Date(e):NaN;t=Number.isNaN(+n)?String(e):c.format(n)}else t=typeof e==`number`?l.format(e):String(e);return o+t+s}}function v(e,t,n=.2,r=.1){let i=e.length,a=t[1]-t[0],o=a/(i-n+r*2)||1,s=t[0]+(a-o*(i-n))/2;return{domain:e,step:o,bandwidth:o*(1-n),at:e=>s+o*e}}function y(e,t){let[n,r]=e,[i,a]=t,o=r===n?0:(a-i)/(r-n);return{domain:e,range:t,of:e=>r===n?(i+a)/2:i+(e-n)*o}}var b=e=>parseFloat(e.toPrecision(12));function x(e,t,n=5){t===e&&([e,t]=e===0?[0,1]:[e-1,t+1]);let r=10**Math.floor(Math.log10((t-e)/n)),i=r,a=1/0,o=e<0&&t>0;for(let s of[1,2,2.5,5,10]){let c=r*s,l=Math.floor(e/c+1e-9),u=Math.ceil(t/c-1e-9)-l+1,d=o?u>n+3?1/0:(u-1+Math.abs(u-n)/1e3)*c:Math.abs(u-n);d<a-1e-9*Math.abs(d)&&(a=d,i=c)}let s=Math.floor(e/i+1e-9),c=Math.ceil(t/i-1e-9),l=[];for(let e=s;e<=c;e++)l.push(b(e*i));return{domain:[b(s*i),b(c*i)],values:l,step:b(i)}}var S=e=>e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510,C=e=>{let t=0,n=0;for(let r of e)S(r.codePointAt(0))?n++:t++;return t*7.2+n*12},w=e=>C(e)+8,T=e=>e.reduce((e,t)=>Math.max(e,w(t)),0);function E(e,t){if(C(e)<=t)return e;let n=``,r=0;for(let i of e){if(r+=C(i),r+7.2>t)break;n+=i}return n+`…`}function D(e,t,n){let r=(t.field===e.y?e.yDomain:e.xDomain)??null,[i,a]=r??t.domain,o=x(i,a),s=r?o.values.filter(e=>e>=i&&e<=a):o.values;return{domain:r??o.domain,values:s,labels:s.map(e=>n(t.field,e,o.step))}}function O(e,[t,n,o],s,c){let{width:l,height:u}=s,d=t&&t.kind===`linear`?D(e,t,c):null,f=n&&n.kind===`linear`?D(e,n,c):null,p=t&&!d?t.domain.map(e=>c(t.field,e)):[],m=n&&!f?n.domain.map(e=>c(n.field,e)):[],h=f?f.labels:m.map(e=>E(e,l*.4-8)),g=o&&o.kind===`linear`?D(e,o,c):null,_=g&&o&&e.titles.get(o.field),b=n&&e.titles.get(n.field),x=t&&e.titles.get(t.field),S=(e.yAxis&&n?T(h)+10:8)+(b?18:0),w=(e.xAxis&&t?24:8)+(x?18:0),O={x:S,y:10,w:Math.max(1,l-S-(g?(e.yAxis?T(g.labels)+4:8)+(_?18:0):Math.max(12,d?C(d.labels.at(-1)??``)/2+2:0))),h:Math.max(1,u-10-w)},k=t?t.kind===`band`?v(t.domain,[O.x,O.x+O.w]):y(d.domain,[O.x,O.x+O.w]):null,A=n?n.kind===`band`?v(n.domain,[O.y,O.y+O.h]):y(f.domain,[O.y+O.h,O.y]):null,j=g?y(g.domain,[O.y+O.h,O.y]):null,M=``;if(e.grid){let e=i(O.x+O.w);if(f)for(let t of f.values){let n=i(A.of(t));M+=a(`line`,{x1:i(O.x),x2:e,y1:n,y2:n})}if(d)for(let e of d.values){let t=i(k.of(e));M+=a(`line`,{x1:t,x2:t,y1:i(O.y),y2:i(O.y+O.h)})}}let N=``;if(e.yAxis&&n){if(f)f.values.forEach((e,t)=>{N+=a(`text`,{x:i(O.x-6),y:i(A.of(e)),"text-anchor":`end`,"dominant-baseline":`middle`},r(f.labels[t]))});else{let e=A,t=Math.max(1,Math.ceil(14/(O.h/Math.max(1,n.domain.length))));m.forEach((n,o)=>{if(o%t)return;let s=h[o];N+=a(`text`,{x:i(O.x-6),y:i(e.at(o)+e.bandwidth/2),"text-anchor":`end`,"dominant-baseline":`middle`},r(s)+(s===n?``:a(`title`,{},r(n))))})}}if(b){let e=i(O.y+O.h/2);N+=a(`text`,{x:9,y:e,"text-anchor":`middle`,transform:`rotate(-90 9 ${e})`},r(b))}if(g&&j&&(e.yAxis&&g.values.forEach((e,t)=>{N+=a(`text`,{x:i(O.x+O.w+6),y:i(j.of(e)),"text-anchor":`start`,"dominant-baseline":`middle`},r(g.labels[t]))}),_)){let[e,t]=[l-9,i(O.y+O.h/2)];N+=a(`text`,{x:e,y:t,"text-anchor":`middle`,transform:`rotate(90 ${e} ${t})`},r(_))}let P=``;if(e.xAxis&&t){let e=i(O.y+O.h+16);if(d){let t=Math.max(1,Math.ceil(T(d.labels)/(O.w/Math.max(1,d.values.length-1))));d.values.forEach((n,o)=>{o%t||(P+=a(`text`,{x:i(k.of(n)),y:e,"text-anchor":`middle`},r(d.labels[o])))})}else{let t=k,n=Math.max(1,Math.ceil(T(p)/(O.w/Math.max(1,p.length))));p.forEach((o,s)=>{s%n===0&&(P+=a(`text`,{x:i(t.at(s)+t.bandwidth/2),y:e,"text-anchor":`middle`},r(o)))})}}x&&(P+=a(`text`,{x:i(O.x+O.w/2),y:u-4,"text-anchor":`middle`},r(x)));let F=d&&f,I=t?.kind===`band`?t:n?.kind===`band`?n:null;return{plot:O,x:k,y:A,y2:j,grid:M,ay:N,ax:P,attrs:{"data-plot":`${i(O.x)} ${i(O.y)} ${i(O.w)} ${i(O.h)}`,"data-n":F||!I?null:I.domain.length,"data-xd":F?d.domain.join(` `):null,"data-yd":F?f.domain.join(` `):null}}}function k(e){let t=0,n=0;return{add(r){n=t===0||e===`sum`||e===`mean`?n+r:e===`min`?Math.min(n,r):e===`max`?Math.max(n,r):n,t++},value:()=>e===`count`?t:t===0?null:e===`mean`?n/t:n}}function A(e,t={}){let{hidden:n=[],window:r}=Array.isArray(t)?{hidden:t}:t,i=[],a=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map;for(let t of e.data){let n=String(t[e.x]),r=e.series===null?``:String(t[e.series]),o=a.get(r);o===void 0&&a.set(r,o=i.push(r)-1);let c=s.get(n);c||s.set(n,c={label:n,rows:[],vals:[]}),c.rows.push([o,t[e.y],e.y2===null?void 0:t[e.y2]])}let c=t=>{let n=/* @__PURE__ */ new Map;for(let[r,i]of t){let t=n.get(r);t||n.set(r,t=k(e.aggregate)),typeof i==`number`&&t.add(i)}return i.map((e,t)=>n.get(t)?.value()??null)},l=t=>{let n=k(e.aggregate);for(let[,,e]of t.rows)typeof e==`number`&&n.add(e);t.y2=n.value()},u=[...s.values()];for(let e of u)e.vals=c(e.rows),l(e);let d=e=>e.vals.reduce((e,t)=>e+(t??0),0);if(e.sort){let t=e.sort===`asc`?1:-1;u=u.map(e=>[e,d(e)]).sort((e,n)=>t*(e[1]-n[1])).map(e=>e[0])}if(e.limit!==null&&u.length>e.limit){let t=new Set(u.map(e=>[e,d(e)]).sort((e,t)=>t[1]-e[1]).slice(0,e.limit).map(e=>e[0])),n={label:o,rows:u.filter(e=>!t.has(e)).flatMap(e=>e.rows),vals:[]};n.vals=c(n.rows),l(n),u=[...u.filter(e=>t.has(e)),n]}let f=e.type===`waterfall`,p=/* @__PURE__ */ new Map;if(f){let t=0;for(let n of u)e.totals.includes(n.label)?p.set(n,[0,t]):p.set(n,[t,t+=d(n)])}if(r?.length===2&&u.length){let e=Math.min(u.length-1,Math.max(0,Math.trunc(r[1]))),t=Math.min(e,Math.max(0,Math.trunc(r[0])));u=u.slice(t,e+1)}let m=[];i.forEach((e,t)=>n.includes(e)||m.push(t));let h=[],g=0,_=0;return u.forEach((t,n)=>{let r=0,i=0;for(let a of m){let o=t.vals[a]??null,s=o??0,[c,l]=f?p.get(t):[0,s];e.stack&&(s<0?[c,l]=[i,i+=s]:[c,l]=[r,r+=s]),g=Math.min(g,c,l),_=Math.max(_,c,l),h.push({ci:n,si:a,value:o,y0:c,y1:l})}}),{categories:u.map(e=>e.label),totals:u.map(t=>e.totals.includes(t.label)),series:i,visible:m,cells:h,extent:[g,_],y2:e.y2===null?[]:u.map(e=>e.y2??null)}}function j(e){let t=typeof e.colorBy==`string`&&e.colorBy!==`sign`?e.colorBy:null,n=/* @__PURE__ */ new Map;if(t)for(let r of e.data){let i=r[t];if(typeof i!=`number`)continue;let a=String(r[e.x])+`\0`+(e.series===null?``:String(r[e.series]));(n.get(a)??n.set(a,k(e.aggregate)).get(a)).add(i)}return(e,t)=>n.get(e+`\0`+t)?.value()??null}function M(e){let t=[];for(let n of e.cells)t[n.ci]=n;let n=e.visible[0]??0,r=0,i=[];return e.categories.forEach((a,o)=>{let s=t[o];if(s){if(e.totals[o])return void i.push({ci:o,si:n,y0:0,y1:r,v:r,s:2});s.value!==null&&i.push({ci:o,si:n,y0:r,y1:r+=s.value,v:s.value,s:+(s.value<0)})}}),i}var N=(e,t)=>e.type===`waterfall`?M(t):t.cells.flatMap(e=>e.value===null?[]:[{ci:e.ci,si:e.si,y0:e.y0,y1:e.y1,v:e.value,s:e.si%8}]),P={noun:`Bar`,axes(e,t){let n=t.extent[0],r=t.extent[1];if(e.type===`waterfall`){n=r=0;for(let e of M(t))n=Math.min(n,e.y0,e.y1),r=Math.max(r,e.y0,e.y1)}let i={kind:`band`,field:e.x,domain:t.categories},a={kind:`linear`,field:e.y,domain:[n,r]};if(e.y2!==null){let n=t.y2.filter(e=>e!==null);return[i,a,{kind:`linear`,field:e.y2,domain:[Math.min(0,...n),Math.max(0,...n)]}]}return e.horizontal?[a,i]:[i,a]},draw(e){let{spec:t,shaped:n}=e,r=t.horizontal,l=r?e.y:e.x,u=r?e.x:e.y,d=v(n.visible.map(e=>n.series[e]),[0,l.bandwidth],.1,0),f=j(t),p=``,m=``;for(let h of N(t,n)){let g=n.visible.indexOf(h.si),_=l.at(h.ci)+(t.stack||t.type===`waterfall`?0:d.at(g)),v=t.stack||t.type===`waterfall`?l.bandwidth:d.bandwidth,[y,b]=[u.of(h.y0),u.of(h.y1)],x=Math.min(y,b),S=Math.abs(y-b),[C,w,T,E]=r?[x,_,S,v]:[_,x,v,S],D=n.categories[h.ci],O=n.series[h.si],k=f(D,O),A={"data-key":s(O,D),"data-c":h.ci,"data-s":h.s,"data-x":e.fmt(t.x,D),"data-series":O,"data-f":e.fmt(t.y,h.v),"data-y":h.v,"data-neg":h.v<0,"data-tone":e.tone(h.v),"data-q":k===null?null:e.q(k),"data-other":D===o,"data-total":n.totals[h.ci]};if(p+=a(`rect`,{"data-maya":`mark`,...A,x:i(C),y:i(w),width:i(T),height:i(E)}),m+=c(A,C,w,T,E),t.labels){let n=e.fmt(t.y,h.v),i=n.length*7.2+4,[a,o]=[C+T/2,w+E/2],s=h.v<0;r?i<=T&&E>=14?e.label(a,o,n,`center`):e.label(s?C-4:C+T+4,o,n,s?`end`:`start`):i<=T&&E>=16?e.label(a,o,n,`center`):e.label(a,s?w+E:w,n,s?`below`:`above`)}}if(e.y2&&t.y2!==null&&n.y2.length){let r=t.y2,o=n.series.length%8,u=t.titles.get(r)??r,d=``,f=!0,h=``;n.y2.forEach((p,g)=>{if(p===null){f=!0;return}let _=i(l.at(g)+l.bandwidth/2),v=i(e.y2.of(p));d+=`${f?`M`:`L`}${_} ${v}`,f=!1;let y=n.categories[g],b={"data-key":s(`\0y2`,y),"data-c":g,"data-s":o,"data-x":e.fmt(t.x,y),"data-series":u,"data-f":e.fmt(r,p),"data-y":p,"data-neg":p<0};h+=a(`circle`,{"data-maya":`mark`,...b,r:3,cx:_,cy:v}),m+=c(b,_-3,v-3,6,6),t.labels&&e.label(+_,+v,e.fmt(r,p),`above`)}),p+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,`\0y2`),"data-s":o,pathLength:1,d:d||null})+h}return{marks:p,hits:m}}},F={noun:`Dumbbell`,axes(e,t){let n={kind:`band`,field:e.x,domain:t.categories},r={kind:`linear`,field:e.y,domain:t.extent};return e.horizontal?[r,n]:[n,r]},draw(e){let{spec:t,shaped:n}=e,r=t.horizontal,l=r?e.y:e.x,u=r?e.x:e.y,d=Math.max(3,Math.min(5,l.bandwidth/2-1)),f=/* @__PURE__ */ new Map;for(let e of n.cells)e.value!==null&&e.si<2&&((f.get(e.ci)??f.set(e.ci,[]).get(e.ci))[e.si]=e.value);let p=``,m=``,h=``;for(let[g,_]of[...f].sort((e,t)=>e[0]-t[0])){let f=n.categories[g],v=l.at(g)+l.bandwidth/2,y=e=>r?[u.of(e),v]:[v,u.of(e)],[b,x]=_;if(b!==void 0&&x!==void 0){let[t,n]=y(b),[r,o]=y(x);p+=a(`line`,{"data-maya":`link`,"data-key":s(`k`,f),"data-c":g,"data-tone":e.tone(x-b),"stroke-width":2,x1:i(t),y1:i(n),x2:i(r),y2:i(o)})}for(let l of[0,1]){let u=_[l];if(u===void 0)continue;let[p,v]=y(u),b=n.series[l],x={"data-key":s(b,f),"data-c":g,"data-s":l%8,"data-x":e.fmt(t.x,f),"data-series":b,"data-f":e.fmt(t.y,u),"data-y":u,"data-neg":u<0,"data-other":f===o};if(m+=a(`circle`,{"data-maya":`mark`,...x,cx:i(p),cy:i(v),r:d}),h+=c(x,p-d,v-d,d*2,d*2),t.labels){let n=_[1-l],[i,a]=y(n??u),o=e.fmt(t.y,u),s=r?p>=i:v>=a,c=n===void 0?r:l===1?s:!s;r?e.label(p+(c?d+4:-d-4),v,o,c?`start`:`end`):e.label(p,v+(c?d:-d),o,c?`below`:`above`)}}}return{marks:p+m,hits:h}}},I={noun:`Heatmap`,axes:(e,t)=>[{kind:`band`,field:e.x,domain:t.categories},{kind:`band`,field:e.series??``,domain:t.series}],draw(e){let{spec:t,shaped:n}=e,o=e.x,l=e.y,u=n.cells.filter(e=>e.value!==null),d=1/0,f=-1/0;for(let e of u)d=Math.min(d,e.value),f=Math.max(f,e.value);let p=e=>f>d?Math.min(9,Math.max(0,Math.floor((e-d)/(f-d)*10))):9,m=``,h=``;for(let[r,d]of u.entries()){let u=d.value,f=n.visible.indexOf(d.si),g=o.at(d.ci)+1,_=l.at(f)+1,v=Math.max(0,o.bandwidth-2),y=Math.max(0,l.bandwidth-2),b=n.categories[d.ci],x=n.series[d.si],S={"data-key":s(x,b),"data-c":r,"data-x":e.fmt(t.x,b),"data-series":x,"data-y":u,"data-f":e.fmt(t.y,u),"data-q":p(u)};m+=a(`rect`,{"data-maya":`mark`,...S,x:i(g),y:i(_),width:i(v),height:i(y)}),h+=c(S,g,_,v,y),t.labels!==!1&&v>=24&&y>=24&&e.label(g+v/2,_+y/2,e.fmt(t.y,u),`center`)}let g=u.length>0?`<div class="maya-legend" data-maya="ramp"><span>${r(e.fmt(t.y,d))}</span><i></i><span>${r(e.fmt(t.y,f))}</span></div>`:``;return{marks:m,hits:h,grid:``,legend:g}}},L=12,R=e=>typeof e==`number`?e:null;function ee(e){let{spec:t,shaped:n,width:o,height:c}=e,l=t.x?n.categories:[],u=t.x?n.cells.filter(e=>e.si===0).sort((e,t)=>e.ci-t.ci):[],d=u.filter(e=>e.value!==null),f=d[d.length-1],p=t.x?f?.value??null:e.agg(t.aggregate)(t.data.map(e=>R(e[t.y]))),m=o/2;if(p===null)return{marks:``,hits:``,labels:a(`text`,{"data-maya":`empty`,x:i(m),y:i(c/2),"text-anchor":`middle`},r(e.t(`noData`)))};let h=f?.ci??0,g=t.x?e.fmt(t.x,l[h]):``,_=e.fmt(t.y,p),v=i(Math.max(16,Math.min(c*.32,72,(o-24)/(_.length*.62)))),y={"data-c":h,"data-s":0,"data-x":g,"data-series":``,"data-y":p,"data-f":_},b=(e,t)=>a(`text`,{"dominant-baseline":`hanging`,x:L,...e},r(t)),x=a(`text`,{"data-maya":`mark`,"data-key":`v`,...y,"font-size":v,x:L,y:L,"dominant-baseline":`hanging`},r(_)),S=``,C=``,w=L+v+4,T=d[d.length-2];if(f&&T&&T.value){let n=(p-T.value)/Math.abs(T.value),r=new Intl.NumberFormat(t.locale,{style:`percent`,maximumFractionDigits:1,signDisplay:`exceptZero`}).format(n);S+=b({"data-kpi":`delta`,"data-tone":n>0?`good`:n<0?`bad`:null,y:i(w),"font-size":12},e.t(`vs`,r,e.fmt(t.x,l[T.ci]))),w+=16}g&&(S+=b({"data-kpi":`period`,y:i(w),"font-size":11},g)),w+=18;let E=``,D=typeof t.colorBy==`object`&&t.colorBy?t.colorBy.target:null,O=c-L;if(D){let n=o-24,r=Math.min(Math.max(p/D,0),1.2)/1.2,s=new Intl.NumberFormat(t.locale,{style:`percent`,maximumFractionDigits:1});O-=8,E=a(`rect`,{"data-kpi":`track`,x:L,y:O,width:i(n),height:8,rx:4}),x+=a(`rect`,{"data-maya":`mark`,"data-key":`b`,...y,"data-kpi":`fill`,"data-tone":e.tone(p),x:L,y:O,width:i(n*r),height:8,rx:4}),S+=a(`line`,{"data-kpi":`target`,"stroke-width":2,x1:i(L+n/1.2),x2:i(L+n/1.2),y1:O-3,y2:O+11}),S+=b({"data-kpi":`of`,y:O-16,"font-size":11},e.t(`ofTarget`,s.format(p/D),e.fmt(t.y,D))),O-=24}if(l.length>=3&&O-w>=28){let n=d.map(e=>e.value),r=Math.min(...n),p=Math.max(...n)-r||1,m=l.length-1,h=(o-24)/m,g=e=>i(L+e*h),_=e=>i(O-(e-r)/p*(O-w-4)-2),v=``,y=!0;u.forEach(n=>{if(n.value===null)return void(y=!0);v+=`${y?`M`:`L`}${g(n.ci)} ${_(n.value)}`,y=!1,x+=a(`circle`,{"data-maya":`mark`,"data-key":s(``,l[n.ci]),"data-c":n.ci,"data-s":0,"data-x":e.fmt(t.x,l[n.ci]),"data-series":``,"data-y":n.value,"data-f":e.fmt(t.y,n.value),"data-neg":n.value<0,"data-last":n===f,r:3,cx:g(n.ci),cy:_(n.value)})}),x=a(`path`,{"data-maya":`line`,"data-key":s(`l`,``),"data-s":0,pathLength:1,d:v||null})+x,l.forEach((e,t)=>{C+=a(`rect`,{"data-maya":`hit`,"data-c":t,x:i(Math.max(0,L+t*h-h/2)),y:0,width:i(h),height:c,fill:`transparent`})})}return{marks:x,hits:C,labels:S,grid:E}}var te={noun:`KPI`,draw:ee},ne=(e,t)=>[{kind:`band`,field:e.x,domain:t.categories},{kind:`linear`,field:e.y,domain:t.extent}];function re(e,t){let{spec:n,shaped:r,plot:c}=e,l=e.x,u=e.y,d=j(n),f=e=>i(l.at(e)+l.bandwidth/2),p=``,m=``,h=``;for(let c of r.visible){let l=r.series[c],g=r.cells.filter(e=>e.si===c).sort((e,t)=>e.ci-t.ci),_=``,v=!0,y=[[]];for(let t of g){if(t.value===null&&!n.stack?y.push([]):y[y.length-1].push(t),t.value===null){v=!0;continue}_+=`${v?`M`:`L`}${f(t.ci)} ${i(u.of(t.y1))}`,v=!1;let p=r.categories[t.ci],m=d(p,l),g=p===o,b=e.fmt(n.x,p);h+=a(`circle`,{"data-maya":`mark`,"data-key":s(l,p),"data-c":t.ci,"data-s":c%8,"data-x":b,"data-series":l,"data-y":t.value,"data-f":e.fmt(n.y,t.value),"data-neg":t.value<0,"data-tone":e.tone(t.value),"data-q":m===null?null:e.q(m),"data-other":g,r:3,cx:f(t.ci),cy:i(u.of(t.y1))}),n.labels&&e.label(f(t.ci),u.of(t.y1),e.fmt(n.y,t.value),`above`)}if(t){let e=y.filter(e=>e.length>0).map(e=>e.map((e,t)=>`${t?`L`:`M`}${f(e.ci)} ${i(u.of(e.y1))}`).join(``)+[...e].reverse().map(e=>`L${f(e.ci)} ${i(u.of(e.y0))}`).join(``)+`Z`).join(``);e&&(p+=a(`path`,{"data-maya":`area`,"data-key":s(`a`,l),"data-s":c%8,d:e}))}m+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,l),"data-s":c%8,pathLength:1,d:_||null})}let g=``;return r.categories.forEach((e,t)=>{g+=a(`rect`,{"data-maya":`hit`,"data-c":t,x:i(l.at(t)),y:i(c.y),width:i(l.bandwidth),height:i(c.h),fill:`transparent`})}),{marks:p+m+h,hits:g,cross:a(`line`,{x1:0,x2:0,y1:i(c.y),y2:i(c.y+c.h)})}}var ie={noun:`Line`,axes:ne,draw:e=>re(e,!1)},ae={noun:`Area`,axes:ne,draw:e=>re(e,!0)},oe=24;function se(e,t){let n=[],r=e.xDomain,i=e.yDomain,a=e.window;return e.data.forEach((o,s)=>{let c=o[e.x],l=o[e.y];if(typeof c!=`number`||typeof l!=`number`||r&&(c<r[0]||c>r[1])||i&&(l<i[0]||l>i[1])||a&&(c<a[0]||c>a[1]||l<a[2]||l>a[3]))return;let u=t.series.indexOf(e.series===null?``:String(o[e.series]));if(!t.visible.includes(u))return;let d=e.size===null?null:o[e.size],f=e.name===null?null:o[e.name];n.push({i:s,x:c,y:l,sz:typeof d==`number`?d:null,si:u,name:f==null?null:String(f),row:o})}),n}var ce={noun:`Scatter`,axes(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let o of se(e,t))n=Math.min(n,o.x),r=Math.max(r,o.x),i=Math.min(i,o.y),a=Math.max(a,o.y);n>r&&(n=r=0,i=a=0);let o=e.size===null?0:(r-n)*.06,s=e.size===null?0:(a-i)*.06,c=(e,t)=>e>=0?Math.max(0,e-t):e-t;return[n,r,i,a]=[c(n,o),r+o,c(i,s),a+s],[{kind:`linear`,field:e.x,domain:e.xDomain??[n,r]},{kind:`linear`,field:e.y,domain:e.yDomain??[i,a]}]},draw(e){let{spec:t,shaped:n,plot:r}=e,o=e.x,c=e.y,l=se(t,n),u=0;for(let e of l)e.sz!==null&&(u=Math.max(u,Math.abs(e.sz)));let d=Math.min(r.w,r.h)/16,f=typeof t.colorBy==`string`&&t.colorBy!==`sign`?t.colorBy:null,p=/* @__PURE__ */ new Map,m=l.map(r=>{let i=r.sz!==null&&u>0?2+Math.sqrt(Math.abs(r.sz)/u)*d:4,a=r.i;if(r.name!==null){let e=(p.get(r.name)??0)+1;p.set(r.name,e),a=e>1?`${r.name}#${e}`:r.name}let l=n.series[r.si],m=e.fmt(t.x,r.x),h=e.fmt(t.y,r.y),g=f?r.row[f]:null;return{p:r,rad:i,d:{"data-key":s(l,a),"data-c":r.i,"data-s":r.si%8,"data-x":r.name??m,"data-series":l,"data-y":r.y,"data-f":r.name===null&&r.sz===null?h:[m,h,r.sz===null?null:e.fmt(t.size,r.sz)].filter(e=>e!==null).join(` · `),"data-neg":r.y<0,"data-tone":e.tone(r.y),"data-q":typeof g==`number`?e.q(g):null},cx:o.of(r.x),cy:c.of(r.y)}});m.sort((e,t)=>t.rad-e.rad);let h=``,g=``;for(let{p:n,rad:r,d:o,cx:s,cy:c}of m)h+=a(`circle`,{"data-maya":`mark`,...o,r:i(r),cx:i(s),cy:i(c)}),r*2<oe&&(g+=a(`circle`,{"data-maya":`hit`,...o,r:i(Math.max(r,12)),cx:i(s),cy:i(c),fill:`transparent`})),t.labels&&e.label(s,c-r,e.fmt(t.y,n.y),`above`);return{marks:h,hits:g}}},le=`0.1.0`,z=Symbol.for(`mayacharts.marks@0`);Object.hasOwn(globalThis,z)||Object.defineProperty(globalThis,z,{value:/* @__PURE__ */ new Map});var B=globalThis[z],ue=[`bar`,`line`,`area`,`scatter`,`heatmap`,`waterfall`,`kpi`,`dumbbell`],de={treemap:`hierarchy`,sunburst:`hierarchy`,sankey:`flow`,hexmap:`geo`},fe=()=>[...B.keys()],pe=`--maya-fg:#1f2328;--maya-fg-muted:#656d76;--maya-bg:#fff`,me=`--maya-fg:#e6edf3;--maya-fg-muted:#9198a1;--maya-bg:#0d1117`,V=(e,t=0)=>Array.from({length:e},(e,n)=>n+t),he=V(8).map(e=>`[data-s="${e}"]{--c:var(--maya-series-${e+1})}`).join(``),ge=V(10).map(e=>`[data-q="${e}"]{--q:${Math.round(20+e*80/9)}%}`).join(``),_e=V(8).map(e=>`.maya:has([data-s="${e}"]:hover) [data-maya=mark]:not([data-s="${e}"]){opacity:.3}`).join(``),ve=V(3,2).map(e=>`.maya-ctl[data-n="${e}"]::before{width:calc((100% - 4px)/${e})}`).join(``)+V(3,1).map(e=>`.maya-ctl[data-i="${e}"]::before{transform:translateX(${e*100}%)}`).join(``),ye=`border:0;background:none;padding:0;font:inherit;color:var(--maya-fg-muted);cursor:pointer`,be=`:host,.maya-root{--maya-font:system-ui,sans-serif;--maya-font-size:12px;--maya-fg:light-dark(#1f2328,#e6edf3);--maya-fg-muted:light-dark(#656d76,#9198a1);--maya-grid:color-mix(in oklab,var(--maya-fg) 12%,transparent);--maya-bg:light-dark(#fff,#0d1117);--maya-accent:oklch(.6 .17 255);--maya-radius:2px;--maya-tooltip-bg:var(--maya-fg);--maya-tooltip-fg:var(--maya-bg);--maya-focus:var(--maya-accent);--maya-good:light-dark(#1a7f37,#3fb950);--maya-bad:light-dark(#cf222e,#f85149);--maya-series-1:var(--maya-accent);--maya-series-2:oklch(.66 .16 50);--maya-series-3:oklch(.62 .15 160);--maya-series-4:oklch(.66 .17 330);--maya-series-5:oklch(.62 .14 90);--maya-series-6:oklch(.62 .12 205);--maya-series-7:oklch(.64 .19 22);--maya-series-8:oklch(.62 .16 295);color-scheme:light dark}@supports not (color:light-dark(#000,#fff)){:host,.maya-root{${pe}}@media (prefers-color-scheme:dark){:host,.maya-root{${me}}}}:host{display:block;position:relative;container-type:inline-size;min-height:200px}.maya{display:flex;flex-direction:column;height:100%;font:var(--maya-font-size) var(--maya-font);font-variant-numeric:tabular-nums;color:var(--maya-fg)}.maya-title{font-weight:600;font-size:14px}.maya-legend,.maya-crumbs{color:var(--maya-fg-muted);display:flex;flex-wrap:wrap;align-items:center;gap:4px 12px;margin:0 0 8px}.maya-crumbs{min-height:1.25em;line-height:1.25}.maya-legend button,.maya-crumbs button,.maya-reset{display:inline-flex;align-items:center;gap:6px;${ye};border-radius:4px}.maya-legend [aria-pressed=false]{opacity:.4}:is(.maya-legend,.maya-crumbs) button:focus-visible,.maya-reset:focus-visible,.maya-ctl :focus-visible{outline:2px solid var(--maya-focus);outline-offset:2px}i{width:10px;height:10px;border-radius:3px;background:var(--c)}[data-maya=ramp]{display:flex;align-items:center;gap:6px}[data-maya=ramp] i{width:80px;height:8px;background:linear-gradient(90deg,color-mix(in oklab,var(--maya-accent) 20%,var(--b)),var(--maya-accent))}[data-q],[data-maya=ramp] i{--b:light-dark(var(--maya-bg),color-mix(in oklab,var(--maya-accent) 15%,var(--maya-bg)))}.maya-legend span{display:inline-flex;align-items:center;gap:6px}.maya-reset{position:absolute;top:4px;right:4px;border:1px solid var(--maya-grid);border-radius:99px;padding:2px 10px;background:var(--maya-bg)}.maya-ctl{position:relative;display:inline-grid;grid-auto-flow:column;grid-auto-columns:1fr;align-self:flex-start;margin:0 0 8px;padding:2px;border-radius:8px;background:var(--maya-grid)}.maya-ctl::before{content:'';position:absolute;inset:2px auto 2px 2px;width:calc(100% - 4px);border-radius:6px;background:var(--maya-bg);transition:transform .2s}`+ve+`.maya-ctl [role=radio]{${ye};position:relative;padding:4px 12px;border-radius:6px}.maya-ctl [aria-checked=true]{color:var(--maya-fg);font-weight:600}.maya-err{margin:0;padding:8px;color:var(--maya-bad);white-space:pre-wrap;font:12px monospace}.maya-box{flex:1;min-height:0;position:relative}.maya-box svg{display:block;width:100%;height:100%;overflow:visible}.maya-svg{direction:ltr;font:var(--maya-font-size) var(--maya-font);font-variant-numeric:tabular-nums}.maya-svg text{fill:var(--maya-fg-muted);unicode-bidi:plaintext}[data-maya=grid] *{stroke:var(--maya-grid);shape-rendering:crispEdges}`+he+`[data-other],[data-total]{--c:var(--maya-fg-muted)}[data-tone=good]{--c:var(--maya-good)}[data-tone=bad]{--c:var(--maya-bad)}[data-q]{--c:color-mix(in oklab,var(--maya-accent) var(--q),var(--b))}`+ge+`[data-maya=mark]{fill:var(--c,var(--maya-series-1));rx:var(--maya-radius);transform-box:fill-box;transform-origin:0 0}[data-dir=h] [data-neg]{transform-origin:100% 0}[data-maya=mark],[data-maya=link]{transition:opacity .2s}[data-maya=mark][data-active]{fill:color-mix(in oklab,var(--c,var(--maya-series-1)),var(--maya-fg) 18%)}:where([data-xd] circle[data-maya=mark]){stroke:var(--maya-bg);stroke-width:1}[data-maya=line]~circle[data-maya=mark]:not([data-active],[data-selected],[data-last]){fill-opacity:0}[data-maya=line]{fill:none;stroke:var(--c);stroke-width:2;stroke-linejoin:round}[data-maya=area]{fill:color-mix(in oklab,var(--c) 18%,transparent);stroke:none}[data-maya=link]{fill:var(--c);opacity:.3}[data-maya=link][data-active]{opacity:.6}line[data-maya=link]{stroke:var(--c,var(--maya-fg-muted));opacity:1}text[data-maya=mark]{fill:var(--maya-fg);font-weight:600}[data-kpi=track]{fill:var(--maya-grid)}[data-kpi=target]{stroke:var(--maya-fg)}[data-maya=labels] [data-tone]{fill:var(--c)}[data-maya=labels] :is([data-kpi=period],[data-kpi=of]){fill:var(--maya-fg-muted)}[data-line] i{height:2px;border-radius:1px}[data-depth]{stroke:var(--maya-bg);stroke-width:1}[data-maya=marks]:has([data-active]) [data-maya=mark]:not([data-active],text){opacity:.55}[data-maya=marks]:has([data-selected]) [data-maya=mark]:not([data-selected]){opacity:.35}[data-selected]{stroke:var(--maya-fg);stroke-width:2}`+_e+`[data-maya=labels],[data-maya=cross]{pointer-events:none}[data-maya=cross]{opacity:0}[data-maya=labels] text{fill:var(--maya-fg);paint-order:stroke;stroke:var(--maya-bg);stroke-width:3;stroke-linejoin:round}[data-maya=labels] [data-in]{stroke:none}[data-maya=cross] line{stroke:var(--maya-fg-muted);stroke-dasharray:3 3}[data-maya=brush]{fill:var(--maya-accent);fill-opacity:.12;stroke:var(--maya-accent);vector-effect:non-scaling-stroke;pointer-events:none}.maya-svg:focus-visible{outline:2px solid var(--maya-focus)}.maya-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.maya-probe{position:absolute;width:0;height:0;pointer-events:none;anchor-name:--maya-probe}.maya-tip{margin:0;inset:auto;border:0;padding:6px 8px;background:var(--maya-tooltip-bg);color:var(--maya-tooltip-fg);border-radius:6px;box-shadow:0 2px 8px #0003;font:var(--maya-font-size) var(--maya-font);pointer-events:none}@supports (anchor-name:--x){.maya-tip{position-anchor:--maya-probe;position-area:block-start;position-try-fallbacks:flip-block,block-start span-inline-start,block-start span-inline-end;margin:8px}}.maya-tip{opacity:0;transition:opacity .12s}.maya-tip.maya-open{opacity:1}.maya-tip b{display:block}.maya-tip div{display:flex;align-items:center;gap:6px}.maya-tip i{outline:1px solid}.maya-tip [data-on]{font-weight:600}@media (pointer:coarse){:is(.maya-legend,.maya-crumbs) button,.maya-ctl [role=radio],.maya-reset,.maya-crumbs{min-height:24px}}@container (max-width:320px){.maya-legend{display:none}.maya-title{font-size:12px}}@media (prefers-contrast:more){:host,.maya-root{--maya-fg-muted:var(--maya-fg);--maya-grid:color-mix(in oklab,var(--maya-fg) 40%,transparent)}}@media (forced-colors:active){.maya-svg,i{forced-color-adjust:none}[data-maya=mark]{stroke:CanvasText;stroke-width:1}[data-tone=bad]{stroke-dasharray:4 2}}@media (prefers-reduced-motion:reduce){*{transition:none!important}}`,xe=class extends Error{code;path;constructor(e,t,n){super(n),this.name=`MayaSpecError`,this.code=e,this.path=t}},H=e=>e.split(` `),U=Object.fromEntries([...H(`$schema x y2 series size name title description locale currency`).map(e=>[e,`string`]),...H(`stack horizontal labels legend tooltip drill zoom grid xAxis yAxis table animate`).map(e=>[e,`boolean`])]),Se=[...H(`type data y path totals aggregate sort limit format titles text yDomain xDomain select`),...H(`colors colorBy theme`),...Object.keys(U)],Ce=[`bar`,`line`,`area`],we=[`treemap`,`sunburst`,`sankey`],W=`bar,line,area`,Te=`treemap,sunburst,sankey`,Ee=Object.fromEntries(H(`horizontal:bar,dumbbell y2:bar size:scatter name:scatter path:${W},${Te} totals:waterfall series:${W},scatter,heatmap,dumbbell sort:${W},heatmap,dumbbell limit:${W},heatmap,dumbbell stack:bar,area colorBy:${W},waterfall,scatter,dumbbell,kpi,treemap,sunburst,hexmap xDomain:scatter drill:${W},${Te} select:${W},waterfall,scatter,heatmap,dumbbell,treemap,sunburst,hexmap zoom:line,area,scatter`).map(e=>e.split(`:`)).map(([e,t])=>[e,t.split(`,`)])),De=H(`sum mean count min max`),Oe=H(`auto integer decimal compact percent currency date month year time datetime`),ke=H(`dateStyle timeStyle weekday era year month day dayPeriod hour minute second fractionalSecondDigits timeZoneName timeZone hour12 hourCycle calendar`),Ae=e=>ke.some(t=>Object.hasOwn(e,t)),je=[...H(`font fontSize fg fgMuted grid bg accent radius tooltipBg tooltipFg focus good bad`),...[1,2,3,4,5,6,7,8].map(e=>`series`+e)],Me={x:`the category axis`,y:`the plotted numbers`,y2:`the right-axis line`,series:`splitting rows into series`,size:`bubble area`,name:`point identity`,path:`the hierarchy levels`,colorBy:`colouring marks by value`,format:`formatting that field`,titles:`naming that field`},Ne=`Use horizontal: true to put categories on the left axis.`,Pe=`Size comes from the element's CSS box, or render(spec, { width, height }).`,Fe=`Pie and donut charts are not supported: use "bar" or "treemap" to compare parts.`,Ie=`Use type: "hexmap" (import "mayacharts/geo").`,Le=`Example: { type: "bar", data: [{ month: "Jan", revenue: 10 }], x: "month", y: "revenue" }`,Re={label:`Use titles: { <field>: "Name" } for display names, or labels: true for values on marks.`,xLabel:`Use titles: { <x field>: "Name" }. titles is keyed by field and also names tooltips and table headers.`,yLabel:`Use titles: { <y field>: "Name" }. titles is keyed by field and also names tooltips, legend and table headers.`,yFormat:`Use format: "compact" (applies to every y), or format: { <field>: "currency" }.`,dataKey:`Use y: "<field>" for values and x: "<field>" for categories.`,indexAxis:Ne,orientation:Ne,width:Pe,height:Pe,color:`Use colors: [...] for the palette, or colorBy: "sign" | { target: n } | "<field>".`,groupBy:`Use series: "<field>".`,formatter:`Functions are not supported (the spec is JSON). Use format presets or Intl options.`,"size:number":`spec.size names a field for bubble area. For chart size use CSS, or render(spec, { width, height }).`,"select:boolean":`Use select: true or "multi"; omit it to disable selection.`},ze={column:`Use type: "bar".`,barh:`Use type: "bar" with horizontal: true.`,bubble:`Use type: "scatter" with size: "<field>".`,choropleth:Ie,map:Ie,pie:Fe,donut:Fe},Be=H(`rgb rgba hsl hsla oklch oklab lab lch color color-mix light-dark var calc`),Ve=String.raw`\s*(?:"[\w\s.\-]*"|'[\w\s.\-]*'|[\w\-]+(?:\s+[\w\-]+)*)\s*`,He=RegExp(`^${Ve}(?:,${Ve})*$`),G=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0,K=e=>typeof e==`object`&&!!e&&!Array.isArray(e),q=(e,t=0)=>Array.isArray(e)&&e.length>=t&&e.every(e=>typeof e==`string`),J=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Y=e=>{let t=typeof e==`string`||K(e)||Array.isArray(e)?JSON.stringify(e):String(e);return t.length>60?t.slice(0,59)+`…`:t},X=(e,t)=>{let n=e.toLowerCase(),r=``,i=40;for(let e of t){let t=e.toLowerCase(),a=Math.abs(n.length-t.length)+[...t].filter(e=>!n.includes(e)).length,o=0;for(;o<9&&n[o]!==void 0&&n[o]===t[o];)o++;a<4&&a*10-o<i&&([i,r]=[a*10-o,e])}return r&&`Did you mean "${r}"?`},Z=(e,t,n,...r)=>{throw new xe(e,t,`mayacharts: ${n}\n${[...r,`-> https://bbekshr.github.io/mayacharts/errors.html#${e}`].filter(Boolean).map(e=>` `+e).join(`
3
- `)}`)},Q=(e,t,n)=>Z(`invalid-option`,e,`spec.${e} must be ${n}, received ${Y(t)}.`,G(Re,`${e}:${J(t)}`)??``),Ue=(e,t,n)=>{let r=n?He.test(t):/^[#\w\s.,%()+\-\/]*$/.test(t)&&[...t.matchAll(/([\w-]*)\s*\(/g)].every(e=>Be.includes(e[1].toLowerCase()));(!t||!r)&&Z(`unsafe-css-value`,e,`spec.${e} = ${Y(t)} is not a safe CSS value.`,`Allowed: colours, lengths, numbers and ${Be.join(`() `)}(); fonts are family names.`,`Not allowed: url(), image-set(), other functions, ; { } < > \\ and (outside fonts) quotes.`)},$=(e,t,...n)=>Z(`invalid-format`,e,t,...n),We=(e,t,n)=>{if(typeof t==`string`){Oe.includes(t)||$(e,`spec.${e} = ${Y(t)} is not a format preset.`,`Presets: ${Oe.join(`, `)}. Or per field: { <field>: preset or Intl options }.`,X(t,Oe));return}K(t)||$(e,`spec.${e} must be a preset or Intl options, received ${Y(t)}.`);let{prefix:r,suffix:i,...a}=t;for(let[t,n]of[[`prefix`,r],[`suffix`,i]])n!==void 0&&typeof n!=`string`&&$(`${e}.${t}`,`spec.${e}.${t} must be a string, received ${Y(n)}.`);let o=Ae(a);try{o?new Intl.DateTimeFormat(n,a):new Intl.NumberFormat(n,a)}catch(n){$(e,`spec.${e} = ${Y(t)} is not valid ${o?`Intl.DateTimeFormat`:`Intl.NumberFormat`} options.`,n instanceof Error?n.message:String(n))}},Ge=[[`y`,`a field name or a non-empty array of field names`,e=>typeof e==`string`||q(e,1)],[`path`,`a non-empty array of field names`,e=>q(e,1)],[`totals`,`an array of x values (strings)`,e=>q(e)],[`aggregate`,`one of ${De.join(`, `)}`,e=>De.includes(e)],[`sort`,`"asc" or "desc"`,e=>e===`asc`||e===`desc`],[`limit`,`a positive integer`,e=>Number.isInteger(e)&&e>0],[`select`,`true or "multi"`,e=>e===!0||e===`multi`],[`colorBy`,`"sign", { target: number } or a numeric field name`,e=>typeof e==`string`&&!!e||K(e)&&Object.keys(e).join()===`target`&&Number.isFinite(e.target)],[`titles`,`an object of strings keyed by field`,e=>K(e)&&Object.values(e).every(e=>typeof e==`string`)]];function Ke(t){K(t)||Z(`spec-not-object`,`spec`,`spec must be a plain object, received ${J(t)}.`,`Received: ${Y(t)}`);let n=t;for(let e of Object.keys(n))Se.includes(e)||Z(`unknown-option`,e,`spec.${e} is not a known option.`,G(Re,e)??X(e,Se),`Known options: ${Se.join(`, `)}.`);let r=n.type;r===void 0&&Z(`missing-field`,`type`,`spec.type is required but missing.`,`Required fields: type, data, x, y.`,Le);let i=[...ue,...fe()],a=typeof r==`string`?r:void 0;if(a===void 0||!i.includes(a)){let e=a===void 0?void 0:G(de,a);e&&Z(`unknown-type`,`type`,`spec.type = "${r}" needs the "${e}" module, which is not loaded.`,`Add: import "mayacharts/${e}"`),Z(`unknown-type`,`type`,`spec.type = ${Y(r)} is not a chart type.`,`Valid types: ${i.join(`, `)}.`,a===void 0?``:G(ze,a)??X(a,[...i,...Object.keys(de)]))}let o=r,s=we.includes(o),c=s?`path`:`x`,l=t.path;o===`sankey`&&Array.isArray(l)&&l.length<2&&Z(`invalid-option`,`path`,`spec.path needs at least two levels for a sankey.`,`Example: path: ["region", "family"]`);let u=e=>Z(`missing-field`,e,`spec.${e} is required but missing.`,`Required fields: type, data, ${c}, y.`,s?`Example: { type: "${o}", data: [{ region: "N", state: "NY", sales: 10 }], path: ["region", "state"], y: "sales" }`:Le);n.data===void 0&&u(`data`),Array.isArray(n.data)||Z(`data-not-array`,`data`,`spec.data must be an array of rows, received ${J(n.data)}.`);let d=n.data;d.forEach((e,t)=>{K(e)||Z(`row-not-object`,`data[${t}]`,`spec.data[${t}] must be an object, received ${J(e)}.`,`Received: ${Y(e)}`)}),n[c]===void 0&&o!==`kpi`&&!(c===`x`&&Ce.includes(o)&&n.path!==void 0)&&u(c),n.y===void 0&&u(`y`),o===`dumbbell`&&n.series===void 0&&u(`series`);for(let e in U)n[e]!==void 0&&typeof n[e]!==U[e]&&Q(e,n[e],`a ${U[e]}`);for(let[e,t,r]of Ge)n[e]!==void 0&&!r(n[e])&&Q(e,n[e],t);let{y:f,path:p,select:m,colors:h,colorBy:g,theme:_,text:v}=n;if(v!==void 0){K(v)||Q(`text`,v,`an object of strings`);for(let[t,n]of Object.entries(v))Object.hasOwn(e,t)||Z(`invalid-option`,`text.${t}`,`spec.text.${t} is not a text key.`,X(t,Object.keys(e)),`Text keys: ${Object.keys(e).join(`, `)}.`),typeof n!=`string`&&Q(`text.${t}`,n,`a string`)}for(let e of[`yDomain`,`xDomain`]){let t=n[e];t!==void 0&&!(Array.isArray(t)&&t.length===2&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&t[0]<t[1])&&Z(`invalid-domain`,e,`spec.${e} = ${Y(t)} is not a valid domain.`,`Expected [min, max] with finite numbers and min < max, e.g. [0, 100].`)}let y=`en-US`;if(typeof n.locale==`string`){let e=!1;try{e=Intl.NumberFormat.supportedLocalesOf(n.locale).length>0}catch{}e||$(`locale`,`spec.locale = ${Y(n.locale)} is not a locale this runtime supports.`,`Use a BCP 47 tag such as "de-DE". Node built with small ICU supports English only.`),y=n.locale}if(typeof n.currency==`string`)try{new Intl.NumberFormat(y,{style:`currency`,currency:n.currency})}catch{$(`currency`,`spec.currency = ${Y(n.currency)} is not an ISO 4217 currency code.`,`Use a three-letter code such as "USD" or "EUR".`)}if(typeof n.format==`string`)We(`format`,n.format,y);else if(n.format!==void 0){K(n.format)||Q(`format`,n.format,`a preset or an object keyed by field`);for(let[e,t]of Object.entries(n.format))We(`format.${e}`,t,y)}if(h!==void 0){let e=Array.isArray(h)?h.map((e,t)=>[`[${t}]`,e]):K(h)?Object.entries(h).map(([e,t])=>[`.${e}`,t]):null;(!e||!e.every(([,e])=>typeof e==`string`))&&Q(`colors`,h,`an array of colours, or an object of colours by series value`),e.length>8&&Z(`invalid-option`,`colors`,`spec.colors has ${e.length} colours; the palette has 8 slots.`,`Pass at most 8. Series 9 and later reuse slots in order.`);for(let[t,n]of e)Ue(`colors${t}`,n,!1)}if(_!==void 0){K(_)&&Object.values(_).every(e=>typeof e==`string`)||Q(`theme`,_,`an object of string values`);for(let e of Object.keys(_))je.includes(e)||Z(`invalid-theme`,`theme.${e}`,`spec.theme.${e} is not a theme token.`,`Valid tokens: ${je.join(`, `)}.`,X(e,je));for(let[e,t]of Object.entries(_))Ue(`theme.${e}`,t,e===`font`)}n.stack===!0&&o===`line`&&Z(`stack-unsupported`,`stack`,`spec.stack is not supported with spec.type = "line".`,`Use type "area" (or "bar") to stack series.`);for(let e in Ee)n[e]!==void 0&&n[e]!==!1&&!Ee[e].includes(o)&&Z(`option-unsupported`,e,`spec.${e} is not supported with spec.type = "${o}".`,`spec.${e} works with: ${Ee[e].join(`, `)}.`);let b=Ce.includes(o),x=[[g!==void 0&&n.series!==void 0&&o!==`dumbbell`,`colorBy`,`spec.colorBy cannot be combined with spec.series.`,`Series already set the colours; remove one of them.`],[n.yDomain!==void 0&&Array.isArray(f),`yDomain`,`spec.yDomain cannot be combined with a y array.`,`Each measure needs its own domain; use a single y or remove yDomain.`],[n.drill===!0&&m!==void 0,`select`,`spec.select cannot be combined with spec.drill.`,`A click either drills or selects; choose one.`],[b&&p!==void 0&&n.x!==void 0,`x`,`spec.x cannot be combined with spec.path.`,`With path, the current drill level is the category; remove x.`],[n.y2!==void 0&&n.horizontal===!0,`y2`,`spec.y2 cannot be combined with spec.horizontal.`,`The y2 line needs a right value axis; draw vertical bars.`],[o===`kpi`&&g!==void 0&&!K(g),`colorBy`,`spec.colorBy on "kpi" must be { target: number }.`,`A kpi compares its headline with one target, drawn as a bullet bar.`],[b&&n.drill===!0&&p===void 0,`drill`,`spec.drill on "${o}" needs spec.path.`,`Replace x with path: ["region", "state"] (outer to inner).`]];for(let[e,t,n,r]of x)e&&Z(`option-unsupported`,t,n,r);if(d.length){let e=[...new Set(d.flatMap(e=>Object.keys(e)))],t=(t,n,r,i)=>Z(`unknown-field`,t,n,`Fields found: ${e.slice(0,20).join(`, `)}.`,X(r,e),i),r=typeof f==`string`?[f]:f,i=(e,t)=>t.map((t,n)=>[`${e}[${n}]`,t]),a=[[`x`,n.x],...typeof f==`string`?[[`y`,f]]:i(`y`,r),[`series`,n.series],[`y2`,n.y2],[`size`,n.size],[`name`,n.name],...i(`path`,p??[]),[`colorBy`,g===`sign`?void 0:g]];for(let[n,r]of a){if(typeof r!=`string`||e.includes(r))continue;let i=n.replace(/\[.*/,``);t(n,`spec.${n} = ${Y(r)} is not a field in spec.data.`,r,`spec.${i} names the field used for ${Me[i]}.`)}for(let r of[`format`,`titles`])if(K(n[r]))for(let i of Object.keys(n[r]))e.includes(i)||t(`${r}.${i}`,`spec.${r} key "${i}" is not a field in spec.data.`,i,`spec.${r} keys name fields, for ${Me[r]}.`);g===`sign`&&e.includes(`sign`)&&Z(`invalid-option`,`colorBy`,`spec.colorBy = "sign" colours by the sign of y, but spec.data also has a field named "sign".`,`Rename that field (e.g. data.map(({ sign, ...r }) => ({ ...r, signValue: sign }))) to colour by it.`);let c=(e,t)=>d.forEach((n,r)=>t(n[e],`data[${r}].${e}`)),l=(e,t,n)=>c(e,(r,i)=>{r==null||typeof r==`number`&&Number.isFinite(r)||Z(t,i,`spec.${i} is ${Y(r)} (a ${J(r)}), but spec.${n} requires numbers.`,typeof r==`string`&&r.trim()&&Number.isFinite(Number(r))?`Convert first: data.map(r => ({ ...r, ${e}: Number(r.${e}) }))`:`Use null for a gap in the data.`)});for(let e of r)l(e,`non-numeric-y`,`y`);if(typeof n.size==`string`&&l(n.size,`non-numeric-field`,`size`),typeof n.y2==`string`&&l(n.y2,`non-numeric-field`,`y2`),o===`dumbbell`&&typeof n.series==`string`){let e=new Set(d.map(e=>String(e[n.series]))).size;e!==2&&Z(`invalid-option`,`series`,`spec.series on "dumbbell" needs exactly 2 values, found ${e}.`,`The first value seen is the start of each bar, the second the end, e.g. last year and this year.`)}if(o===`scatter`&&typeof n.x==`string`&&l(n.x,`non-numeric-field`,`x`),typeof g==`string`&&g!==`sign`&&l(g,`non-numeric-field`,`colorBy`),s)for(let e of r)c(e,(t,n)=>{typeof t==`number`&&t<=0&&Z(`non-positive-value`,n,`spec.${n} is ${t}, but ${o} sizes must be positive.`,`Filter first: data.filter(r => r.${e} > 0), or chart the signed values with "bar".`)})}B.get(o)?.check?.(t,Z)}function qe(e){if(e===void 0)return;K(e)||Z(`invalid-option`,`options`,`options must be a plain object, received ${J(e)}.`);let t=e,n=(e,t,n)=>Z(`unknown-option`,`${e}.${t}`,`${e}.${t} is not a known render option.`,X(t,n),`Known options: ${n.join(`, `)}.`),r=H(`width height view selected nonce`);for(let e of Object.keys(t))r.includes(e)||n(`options`,e,r);let i=(e,t,n)=>Z(`invalid-option`,`options.${e}`,`options.${e} must be ${n}, received ${Y(t)}.`);for(let e of[`width`,`height`]){let n=t[e];n!==void 0&&!(typeof n==`number`&&Number.isFinite(n)&&n>0)&&Z(`invalid-size`,`options.${e}`,`options.${e} = ${Y(n)} is not a valid size.`,`Size must be a finite number greater than 0.`)}let{view:a,selected:o,nonce:s}=t;if(a!==void 0){K(a)||i(`view`,a,`an object`);let e=H(`measure drill window hidden`);for(let t of Object.keys(a))e.includes(t)||n(`options.view`,t,e);let{measure:t,drill:r,window:o,hidden:s}=a;t!==void 0&&!(Number.isInteger(t)&&t>=0)&&i(`view.measure`,t,`an index (integer >= 0)`),r!==void 0&&!q(r)&&i(`view.drill`,r,`an array of strings`),s!==void 0&&!q(s)&&i(`view.hidden`,s,`an array of strings`),o!==void 0&&(!Array.isArray(o)||o.length!==2&&o.length!==4||!o.every(Number.isFinite))&&i(`view.window`,o,`[i0, i1] or [x0, x1, y0, y1] of finite numbers`)}o!==void 0&&!(Array.isArray(o)&&o.every(e=>K(e)&&Object.keys(e).every(e=>[`x`,`series`,`name`].includes(e))))&&i(`selected`,o,`an array of { x?, series?, name? }`),s!==void 0&&!(typeof s==`string`&&/^[\w+/=-]+$/.test(s))&&i(`nonce`,s,`a base64 nonce string`)}function Je(e,t={}){let n=typeof e.y==`string`?[e.y]:[...e.y],r=Math.min(t.measure??0,n.length-1),i=[...e.path??[]],a=e.drill?(t.drill??[]).slice(0,Math.max(0,i.length-1)):[],o=i.slice(a.length),s=e.format,c=e=>Object.entries(e??{}).filter(e=>e[1]!==void 0);return{type:e.type,data:a.length?e.data.filter(e=>a.every((t,n)=>String(e[i[n]])===t)):e.data,x:e.x??(Ce.includes(e.type)?o[0]??``:``),y:n[r],measures:n,measure:r,series:e.series??null,y2:e.y2??null,path:o,drilled:a,window:t.window&&t.window.length===4?t.window:null,size:e.size??null,name:e.name??null,totals:[...e.totals??[]],stack:e.stack??!1,horizontal:e.horizontal??!1,aggregate:e.aggregate??`sum`,sort:e.sort??null,limit:e.limit??null,format:new Map(typeof s==`string`?n.map(e=>[e,s]):c(s)),titles:new Map(c(e.titles)),labels:e.labels??null,text:{...e.text},title:e.title??null,description:e.description??null,legend:e.legend??(e.series!==void 0||e.y2!==void 0),tooltip:e.tooltip??!0,drill:e.drill??!1,select:e.select??!1,zoom:e.zoom??!1,grid:e.grid??!0,xAxis:e.xAxis??!0,yAxis:e.yAxis??!0,locale:e.locale??`en-US`,currency:e.currency??`USD`,yDomain:e.yDomain??null,xDomain:e.xDomain??null,table:e.table??!0,animate:e.animate??!0,colors:Array.isArray(e.colors)?e.colors:e.colors?new Map(Object.entries(e.colors)):null,colorBy:e.colorBy??null,theme:e.theme??{}}}var Ye={bar:P,waterfall:P,line:ie,area:ae,scatter:ce,heatmap:I,kpi:te,dumbbell:F},Xe=e=>e.replace(/[A-Z]|\d+/g,e=>`-`+e.toLowerCase());function Ze(e,n,o){Ke(e),n!==void 0&&qe(n);let s=Object.hasOwn(Ye,e.type)?Ye[e.type]:B.get(e.type),c=Je(e,n?.view),u=n?.width??640,d=n?.height??320,m=A(c,n?.view??{}),h=e=>e>5e3&&Z(`too-many-marks`,`data`,`${e} marks exceed the limit of 5000.`,`Use spec.limit to keep the top N categories, or aggregate the rows first.`);h(m.cells.length);let g=/* @__PURE__ */ new Map,v=(e,n,r)=>{if(n===`\0other`)return t(c,`other`);let i=e+`\0`+r,a=g.get(i);return a||g.set(i,a=_(c,e,r)),a(n)},y=c.colorBy,b=1/0,x=-1/0;if(typeof y==`string`&&y!==`sign`)for(let e of c.data){let t=e[y];typeof t==`number`&&(b=Math.min(b,t),x=Math.max(x,t))}let S=e=>y===`sign`?e<0?`bad`:`good`:y&&typeof y==`object`?e>=y.target?`good`:`bad`:null,C=e=>{let n=S(e);return n===null?null:t(c,y===`sign`?n===`good`?`positive`:`negative`:n===`good`?`above`:`below`)},w=[],T=``,E=(e,t,n,o)=>{let s=n.length*7.2+4,c=o===`start`?e:o===`end`?e-s:e-s/2,l=o===`above`?t-16:o===`below`?t+2:t-7;return c<0||l<0||c+s>u||l+14>d||w.some(e=>c<e[2]&&c+s>e[0]&&l<e[3]&&l+14>e[1])?!1:(w.push([c,l,c+s,l+14]),T+=a(`text`,{x:i(e),y:i(o===`above`?t-4:o===`below`?t+13:t),"text-anchor":o===`start`||o===`end`?o:`middle`,"dominant-baseline":o===`above`||o===`below`?null:`middle`,"data-in":o===`center`},r(n)),!0)},D=s.axes?O(c,s.axes(c,m),{width:u,height:d},v):null,j=D?.plot??{x:0,y:0,w:u,h:d},M={spec:c,shaped:m,width:u,height:d,plot:j,x:D?.x??null,y:D?.y??null,y2:D?.y2??null,fmt:v,label:E,tone:S,q:e=>x>b?Math.min(9,Math.max(0,Math.floor((e-b)/(x-b)*10))):9,agg:e=>t=>{let n=k(e);for(let e of t)typeof e==`number`&&n.add(e);return n.value()},fail:Z,t:(e,...n)=>t(c,e,...n)};s.check?.(e,Z);let N=null,P=``;if(c.data.length===0)P=a(`text`,{"data-maya":`empty`,x:u/2,y:d/2,"text-anchor":`middle`,"dominant-baseline":`middle`},r(t(c,`noData`)));else{let e=(e,t)=>a(`g`,{"data-maya":e},t),t=s.draw(M);h(t.marks.split(` data-maya="mark"`).length-1),N=t.legend??null,P=e(`grid`,t.grid??D?.grid??``)+e(`axis-y`,D?.ay??``)+e(`axis-x`,D?.ax??``)+e(`marks`,t.marks)+e(`labels`,(t.labels??``)+T)+e(`cross`,t.cross??``)+e(`hits`,t.hits)}let F=[];if(Array.isArray(c.colors))c.colors.forEach((e,t)=>F.push([`--maya-series-${t+1}`,e]));else if(c.colors)for(let[e,t]of c.colors){let n=m.series.indexOf(e);n>=0&&F.push([`--maya-series-${n%8+1}`,t])}for(let e in c.theme)F.push([`--maya-${Xe(e)}`,c.theme[e]]);let I=F.map(([e,t])=>`${e}:${t};`).join(``),L=a(`svg`,{class:o===null?`maya-svg`:`maya-root maya-svg`,viewBox:`0 0 ${u} ${d}`,width:u,height:d,role:`img`,"aria-label":o===null?null:l(c),"aria-labelledby":o===null?`maya-t`:null,"aria-describedby":o===null?`maya-d`:null,tabindex:o===null?`0`:null,style:o===null?null:I||null,"data-plot":`${i(j.x)} ${i(j.y)} ${i(j.w)} ${i(j.h)}`,...D?.attrs,"data-dir":c.horizontal?`h`:null},(o?`<style>${o}</style>`:``)+a(`title`,{id:o===null?`maya-t`:null},r(l(c)))+a(`desc`,{id:o===null?`maya-d`:null},r(f(c,m,v,s.noun)))+P),R=``;return N!==null&&c.legend?R=N:(c.series!==null||c.y2!==null)&&c.legend?R=`<div class="maya-legend" data-maya="legend">`+(c.series===null&&c.y2!==null?`<span data-s="0"><i></i>${r(c.titles.get(c.y)??c.y)}</span>`:``)+(c.series===null?[]:m.series).map((e,t)=>a(`button`,{type:`button`,"data-si":t,"data-s":t%8,"data-key":e,"aria-pressed":String(m.visible.includes(t))},`<i></i>${r(e)}`)).join(``)+(c.y2===null?``:`<span data-s="${m.series.length%8}" data-line><i></i>${r(c.titles.get(c.y2)??c.y2)}</span>`)+`</div>`:e.legend!==!1&&y!==null&&c.series===null&&c.type!==`kpi`&&(R=y===`sign`||typeof y==`object`?`<div class="maya-legend" data-maya="tone">`+[`good`,`bad`].map(e=>`<span data-tone="${e}"><i></i>${r(t(c,y===`sign`?e===`good`?`positive`:`negative`:e===`good`?`above`:`below`))}</span>`).join(``)+`</div>`:x>b?`<div class="maya-legend" data-maya="ramp"><span>${r(v(y,b))}</span><i></i><span>${r(v(y,x))}</span></div>`:``),{svg:L,legend:R,controls:c.measures.length>1?`<div class="maya-ctl" role="radiogroup" aria-label="${r(t(c,`measures`))}" data-n="${c.measures.length}" data-i="${c.measure}">`+c.measures.map((e,t)=>`<button type="button" role="radio" aria-checked="${t===c.measure}" data-i="${t}" tabindex="${t===c.measure?0:-1}">${r(c.titles.get(e)??e)}</button>`).join(``)+`</div>`:``,crumbs:c.drilled.length>0?`<nav class="maya-crumbs" aria-label="${r(t(c,`crumbs`))}"><button type="button" data-depth="0">${r(t(c,`back`))}</button>`+c.drilled.map((e,t)=>`<span aria-hidden="true">›</span><button type="button" data-depth="${t+1}"${t===c.drilled.length-1?` aria-current="page"`:``}>${r(String(e))}</button>`).join(``)+`</nav>`:c.drill?`<div class="maya-crumbs" aria-hidden="true"></div>`:``,table:c.table?p(c,m,v,C):``,title:c.title===null?``:`<div class="maya-title">${r(c.title)}</div>`,style:I,vars:F,warnings:[]}}function Qe(e,t){return Ze(e,t,null)}function $e(e,t){return Ze(e,t,be).svg}function et(e,t,n){let i=e.style?` style="${r(e.style)}"`:``,a=n?` nonce="${r(n)}"`:``;return`${t?`<style${a}>${t}</style>`:``}<div class="maya"${i}>${e.title}${e.controls}${e.legend}${e.crumbs}<div class="maya-box">${e.svg}</div>${e.table}<div class="maya-sr" data-maya="live" aria-live="polite"></div><div class="maya-probe" data-maya="probe"></div><div class="maya-tip" popover="manual" role="tooltip"></div></div>`}function tt(e){let t=e=>typeof e==`object`?Object.keys(e):[],n=/* @__PURE__ */ new Set([e.x,...typeof e.y==`string`?[e.y]:e.y,e.series,e.y2,e.size,e.name,...e.path??[],typeof e.colorBy==`string`?e.colorBy:void 0,...t(e.format),...t(e.titles)]);return{...e,data:e.data.map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>n.has(e))))}}function nt(e,t){let n=Qe(e,t),r=JSON.stringify(tt(e)).replace(/</g,`\\u003c`);return`<maya-chart><template shadowrootmode="open">${et(n,be,t?.nonce)}</template><script type="application/json">${r}<\/script></maya-chart>`}export{xe as MayaSpecError,$e as render,Qe as renderParts,nt as renderShell,Ke as validateSpec,le as version};
1
+ /*! mayacharts v0.2.0 | MIT | https://github.com/BbekShr/mayacharts */
2
+ var e={noData:`No data`,other:`Other`,back:`Back`,reset:`Reset zoom`,showing:`Showing {0}`,drilledInto:`Drilled into {0}`,zoomedTo:`Zoomed to {0} – {1}`,selected:`{0} selected`,selectionCleared:`Selection cleared`,chartOf:`{0} chart of {1} by {2}`,chartOfAll:`{0} chart of {1}`,firstOf:`First {0} of {1} rows`,measures:`Measure`,crumbs:`Drill path`,positive:`positive`,negative:`negative`,above:`above target`,below:`below target`,vs:`{0} vs {1}`,sortedBy:`Sorted by {0}, {1}`,ascending:`ascending`,descending:`descending`,ofTarget:`{0} of target {1}`};function t(t,n,...r){return((t.text&&Object.hasOwn(t.text,n)?t.text[n]:void 0)??e[n]).replace(/\{(\d)\}/g,(e,t)=>String(r[+t]??``))}var n={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};function r(e){return String(e).replace(/[&<>"']/g,e=>n[e])}function i(e){return Math.round(e*100)/100}function a(e,t,n){let i=``;for(let e in t){let n=t[e];n!=null&&n!==!1&&(i+=n===!0?` ${e}=""`:` ${e}="${r(n)}"`)}return n===void 0?`<${e}${i}/>`:`<${e}${i}>${n}</${e}>`}var o=`\0other`,s=(...e)=>e.map(e=>encodeURIComponent(String(e).replace(/\p{Cs}/gu,`�`)).replace(/~/g,`%7E`)).join(`~`);function c(e,t,n,r,o){let[s,c]=[Math.max(r,24),Math.max(o,24)];return r<24||o<24?a(`rect`,Object.assign({"data-maya":`hit`},e,{"data-maya":`hit`,x:i(t-(s-r)/2),y:i(n-(c-o)/2),width:i(s),height:i(c),fill:`transparent`})):``}var l=e=>e.title??`${e.titles.get(e.y)??e.y}`+(e.x||e.path.length?` by ${e.titles.get(e.x)??(e.x||e.path.join(` / `))}`:``),u=[`scatter`,`treemap`,`sunburst`,`sankey`,`hexmap`],d=1e3;function f(e,n,r,i){if(e.description!==null)return e.description;let a=t=>e.titles.get(t)??t,o=e.x||e.path.length?t(e,`chartOf`,i,a(e.y),e.x?a(e.x):e.path.join(` / `)):t(e,`chartOfAll`,i,a(e.y));if(e.series!==null&&n.series.length&&(o+=`, ${e.stack?`stacked`:`grouped`} by ${a(e.series)} (${n.series.join(`, `)})`),u.includes(e.type))return`${o}. ${e.data.length} rows.`;let s=0,c=1/0,l=-1/0;for(let e of n.cells)e.value!==null&&(s++,c=Math.min(c,e.value),l=Math.max(l,e.value));let d=t=>r(e.y,t);return s?s===1?`${o}. 1 value: ${d(c)}.`:`${o}. ${s} values from ${d(c)} to ${d(l)}.`:o+`. No data.`}function p(e,n,i,a){let o=t=>e.titles.get(t)??t,s=(t,n)=>{if(n==null)return``;let o=t===e.y&&typeof n==`number`?a(n):null;return r(i(t,n))+(o?` (${r(o)})`:``)},c=n=>n>d?t(e,`firstOf`,d,n):l(e),f,p,m;if(u.includes(e.type)){let t=[...new Set([e.x,...e.path,e.series,e.name,e.size,e.y,typeof e.colorBy==`string`&&e.colorBy!==`sign`?e.colorBy:null].filter(e=>!!e))];m=e.data.length,f=t.map(e=>`<th>${r(o(e))}</th>`).join(``),p=e.data.slice(0,d).map(e=>`<tr>${t.map(t=>`<td>${s(t,e[t])}</td>`).join(``)}</tr>`).join(``)}else{let t=e.series===null?[o(e.y)]:n.visible.map(e=>n.series[e]);m=n.categories.length,f=`<th>${r(o(e.x))}</th>`+t.map(e=>`<th>${r(e)}</th>`).join(``);let i=new Map(n.cells.map(e=>[e.ci+`,`+e.si,e.value]));p=``;for(let t=0;t<Math.min(m,d);t++){p+=`<tr><th scope="row">${r(n.categories[t])}</th>`;for(let r of n.visible)p+=`<td>${s(e.y,i.get(t+`,`+r))}</td>`;p+=`</tr>`}}return`<table class="maya-sr"><caption>${r(c(m))}</caption><thead><tr>${f}</tr></thead><tbody>${p}</tbody></table>`}var m=e=>{for(let t=0;t<8;t++)if(Math.abs(e*10**t-Math.round(e*10**t))<1e-9)return t;return 8},h=`year month day hour minute second weekday era timeZone dateStyle timeStyle fractionalSecondDigits hour12 dayPeriod timeZoneName`.split(` `),g={date:{dateStyle:`medium`},month:{month:`short`,year:`numeric`},year:{year:`numeric`},time:{timeStyle:`short`},datetime:{dateStyle:`medium`,timeStyle:`short`}};function _(e,t=e.y,n){typeof t==`number`&&([t,n]=[e.y,t]);let r=e.format.get(t),i=Intl.NumberFormat.supportedLocalesOf(e.locale).length?e.locale:`en-US`,a=n===void 0?2:m(n),o=``,s=``,c=null,l=null,u=typeof r==`string`?r:`auto`;if(typeof r==`string`&&Object.hasOwn(g,r))c=new Intl.DateTimeFormat(i,{timeZone:`UTC`,...g[r]});else if(typeof r==`object`&&r){let{prefix:e=``,suffix:t=``,...n}=r;[o,s]=[String(e),String(t)],h.some(e=>Object.hasOwn(n,e))?c=new Intl.DateTimeFormat(i,{timeZone:`UTC`,...n}):l=new Intl.NumberFormat(i,n)}if(!c&&!l){let t=u===`integer`?{maximumFractionDigits:0}:u===`decimal`?{minimumFractionDigits:2,maximumFractionDigits:2}:u===`compact`?{notation:`compact`,maximumFractionDigits:1}:u===`percent`?{style:`percent`,minimumFractionDigits:Math.max(0,a-2),maximumFractionDigits:Math.max(1,a-2)}:u===`currency`?{style:`currency`,currency:e.currency,minimumFractionDigits:n!==void 0&&n>=1?0:a,maximumFractionDigits:n!==void 0&&n>=1?0:Math.max(a,2)}:{maximumFractionDigits:Math.max(a,2)};l=new Intl.NumberFormat(i,t)}return e=>{if(e==null)return``;let t;if(c){let n=typeof e==`string`&&/^-?\d+$/.test(e)?/* @__PURE__ */ new Date(+e):typeof e==`number`||typeof e==`string`||e instanceof Date?new Date(e):NaN;t=Number.isNaN(+n)?String(e):c.format(n)}else t=typeof e==`number`?l.format(e):String(e);return o+t+s}}function v(e,t,n=.2,r=.1){let i=e.length,a=t[1]-t[0],o=a/(i-n+r*2)||1,s=t[0]+(a-o*(i-n))/2;return{domain:e,step:o,bandwidth:o*(1-n),at:e=>s+o*e}}function y(e,t){let[n,r]=e,[i,a]=t,o=r===n?0:(a-i)/(r-n);return{domain:e,range:t,of:e=>r===n?(i+a)/2:i+(e-n)*o}}var b=e=>parseFloat(e.toPrecision(12));function x(e,t,n=5){t===e&&([e,t]=e===0?[0,1]:[e-1,t+1]);let r=10**Math.floor(Math.log10((t-e)/n)),i=r,a=1/0,o=e<0&&t>0;for(let s of[1,2,2.5,5,10]){let c=r*s,l=Math.floor(e/c+1e-9),u=Math.ceil(t/c-1e-9)-l+1,d=o?u>n+3?1/0:(u-1+Math.abs(u-n)/1e3)*c:Math.abs(u-n);d<a-1e-9*Math.abs(d)&&(a=d,i=c)}let s=Math.floor(e/i+1e-9),c=Math.ceil(t/i-1e-9),l=[];for(let e=s;e<=c;e++)l.push(b(e*i));return{domain:[b(s*i),b(c*i)],values:l,step:b(i)}}var S=e=>e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510,C=e=>{let t=0,n=0;for(let r of e)S(r.codePointAt(0))?n++:t++;return t*7.2+n*12},w=e=>C(e)+8,T=e=>e.reduce((e,t)=>Math.max(e,w(t)),0);function E(e,t){if(C(e)<=t)return e;let n=``,r=0;for(let i of e){if(r+=C(i),r+7.2>t)break;n+=i}return n+`…`}function D(e,t,n){let r=(t.field===e.y?e.yDomain:e.xDomain)??null,[i,a]=r??t.domain,[o,s]=i>a?[a,i]:[i,a],c=x(o,s),l=r?c.values.filter(e=>e>=o&&e<=s):c.values;return{domain:r??c.domain,values:l,labels:l.map(e=>n(t.field,e,c.step))}}function O(e,[t,n,o],s,c){let{width:l,height:u}=s,d=t&&t.kind===`linear`?D(e,t,c):null,f=n&&n.kind===`linear`?D(e,n,c):null,p=t&&!d?t.domain.map(e=>c(t.field,e)):[],m=n&&!f?n.domain.map(e=>c(n.field,e)):[],h=f?f.labels:m.map(e=>E(e,l*.4-8)),g=o&&o.kind===`linear`?D(e,o,c):null,_=g&&o&&e.titles.get(o.field),b=n&&e.titles.get(n.field),x=t&&e.titles.get(t.field),S=Math.max((e.yAxis&&n?T(h)+10:8)+(b?18:0),d?C(d.labels[0]??``)/2+2:0),w=(e.xAxis&&t?24:8)+(x?18:0),O={x:S,y:10,w:Math.max(1,l-S-(g?(e.yAxis?T(g.labels)+4:8)+(_?18:0):Math.max(12,d?C(d.labels.at(-1)??``)/2+2:0))),h:Math.max(1,u-10-w)},k=t?t.kind===`band`?v(t.domain,[O.x,O.x+O.w]):y(d.domain,[O.x,O.x+O.w]):null,A=n?n.kind===`band`?v(n.domain,[O.y,O.y+O.h]):y(f.domain,[O.y+O.h,O.y]):null,j=g?y(g.domain,[O.y+O.h,O.y]):null,M=``;if(e.grid){let e=i(O.x+O.w);if(f)for(let t of f.values){let n=i(A.of(t));M+=a(`line`,{x1:i(O.x),x2:e,y1:n,y2:n})}if(d)for(let e of d.values){let t=i(k.of(e));M+=a(`line`,{x1:t,x2:t,y1:i(O.y),y2:i(O.y+O.h)})}}let N=``;if(e.yAxis&&n){if(f)f.values.forEach((e,t)=>{N+=a(`text`,{x:i(O.x-6),y:i(A.of(e)),"text-anchor":`end`,"dominant-baseline":`middle`},r(f.labels[t]))});else{let e=A,t=Math.max(1,Math.ceil(14/(O.h/Math.max(1,n.domain.length))));m.forEach((n,o)=>{if(o%t)return;let s=h[o];N+=a(`text`,{x:i(O.x-6),y:i(e.at(o)+e.bandwidth/2),"text-anchor":`end`,"dominant-baseline":`middle`},r(s)+(s===n?``:a(`title`,{},r(n))))})}}if(b){let e=i(O.y+O.h/2);N+=a(`text`,{x:9,y:e,"text-anchor":`middle`,transform:`rotate(-90 9 ${e})`},r(b))}if(g&&j&&(e.yAxis&&g.values.forEach((e,t)=>{N+=a(`text`,{x:i(O.x+O.w+6),y:i(j.of(e)),"text-anchor":`start`,"dominant-baseline":`middle`},r(g.labels[t]))}),_)){let[e,t]=[l-9,i(O.y+O.h/2)];N+=a(`text`,{x:e,y:t,"text-anchor":`middle`,transform:`rotate(90 ${e} ${t})`},r(_))}let P=``;if(e.xAxis&&t){let e=i(O.y+O.h+16);if(d){let t=Math.max(1,Math.ceil(T(d.labels)/(O.w/Math.max(1,d.values.length-1))));d.values.forEach((n,o)=>{o%t||(P+=a(`text`,{x:i(k.of(n)),y:e,"text-anchor":`middle`},r(d.labels[o])))})}else{let t=k,n=Math.max(1,Math.ceil(T(p)/(O.w/Math.max(1,p.length))));p.forEach((o,s)=>{s%n===0&&(P+=a(`text`,{x:i(t.at(s)+t.bandwidth/2),y:e,"text-anchor":`middle`},r(o)))})}}x&&(P+=a(`text`,{x:i(O.x+O.w/2),y:u-4,"text-anchor":`middle`},r(x)));let F=d&&f,I=t?.kind===`band`?t:n?.kind===`band`?n:null;return{plot:O,x:k,y:A,y2:j,grid:M,ay:N,ax:P,attrs:{"data-plot":`${i(O.x)} ${i(O.y)} ${i(O.w)} ${i(O.h)}`,"data-n":F||!I?null:I.domain.length,"data-xd":F?d.domain.join(` `):null,"data-yd":F?f.domain.join(` `):null}}}function k(e){let t=0,n=0;return{add(r){n=t===0||e===`sum`||e===`mean`?n+r:e===`min`?Math.min(n,r):e===`max`?Math.max(n,r):n,t++},value:()=>e===`count`?t:t===0?null:e===`mean`?n/t:n}}function A(e,t={}){let{hidden:n=[],window:r}=Array.isArray(t)?{hidden:t}:t,i=[],a=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map;for(let t of e.data){let n=String(t[e.x]),r=e.series===null?``:String(t[e.series]),o=a.get(r);o===void 0&&a.set(r,o=i.push(r)-1);let c=s.get(n);c||s.set(n,c={label:n,rows:[],vals:[]}),c.rows.push([o,t[e.y],e.y2===null?void 0:t[e.y2]])}let c=t=>{let n=/* @__PURE__ */ new Map;for(let[r,i]of t){let t=n.get(r);t||n.set(r,t=k(e.aggregate)),typeof i==`number`&&t.add(i)}return i.map((e,t)=>n.get(t)?.value()??null)},l=t=>{let n=k(e.aggregate);for(let[,,e]of t.rows)typeof e==`number`&&n.add(e);t.y2=n.value()},u=[...s.values()];for(let e of u)e.vals=c(e.rows),l(e);let d=e=>e.vals.reduce((e,t)=>e+(t??0),0);if(e.sort){let t=e.sort===`asc`?1:-1;u=u.map(e=>[e,d(e)]).sort((e,n)=>t*(e[1]-n[1])).map(e=>e[0])}if(e.limit!==null&&u.length>e.limit){let t=new Set(u.map(e=>[e,d(e)]).sort((e,t)=>t[1]-e[1]).slice(0,e.limit).map(e=>e[0])),n={label:o,rows:u.filter(e=>!t.has(e)).flatMap(e=>e.rows),vals:[]};n.vals=c(n.rows),l(n),u=[...u.filter(e=>t.has(e)),n]}let f=e.type===`waterfall`,p=/* @__PURE__ */ new Map;if(f){let t=0;for(let n of u)e.totals.includes(n.label)?p.set(n,[0,t]):p.set(n,[t,t+=d(n)])}if(r?.length===2&&u.length){let e=Math.min(u.length-1,Math.max(0,Math.trunc(r[1]))),t=Math.min(e,Math.max(0,Math.trunc(r[0])));u=u.slice(t,e+1)}let m=[];i.forEach((e,t)=>n.includes(e)||m.push(t));let h=[],g=0,_=0;return u.forEach((t,n)=>{let r=0,i=0;for(let a of m){let o=t.vals[a]??null,s=o??0,[c,l]=f?p.get(t):[0,s];e.stack&&(s<0?[c,l]=[i,i+=s]:[c,l]=[r,r+=s]),g=Math.min(g,c,l),_=Math.max(_,c,l),h.push({ci:n,si:a,value:o,y0:c,y1:l})}}),{categories:u.map(e=>e.label),totals:u.map(t=>e.totals.includes(t.label)),series:i,visible:m,cells:h,extent:[g,_],y2:e.y2===null?[]:u.map(e=>e.y2??null)}}function j(e){let t=typeof e.colorBy==`string`&&e.colorBy!==`sign`?e.colorBy:null,n=/* @__PURE__ */ new Map;if(t)for(let r of e.data){let i=r[t];if(typeof i!=`number`)continue;let a=String(r[e.x])+`\0`+(e.series===null?``:String(r[e.series]));(n.get(a)??n.set(a,k(e.aggregate)).get(a)).add(i)}return(e,t)=>n.get(e+`\0`+t)?.value()??null}function M(e){let t=[];for(let n of e.cells)t[n.ci]=n;let n=e.visible[0]??0,r=0,i=[];return e.categories.forEach((a,o)=>{let s=t[o];if(s){if(e.totals[o])return void i.push({ci:o,si:n,y0:0,y1:r,v:r,s:2});s.value!==null&&i.push({ci:o,si:n,y0:r,y1:r+=s.value,v:s.value,s:+(s.value<0)})}}),i}var N=(e,t)=>e.type===`waterfall`?M(t):t.cells.flatMap(e=>e.value===null?[]:[{ci:e.ci,si:e.si,y0:e.y0,y1:e.y1,v:e.value,s:e.si%8}]),P={noun:`Bar`,axes(e,t){let n=t.extent[0],r=t.extent[1];if(e.type===`waterfall`){n=r=0;for(let e of M(t))n=Math.min(n,e.y0,e.y1),r=Math.max(r,e.y0,e.y1)}let i={kind:`band`,field:e.x,domain:t.categories},a={kind:`linear`,field:e.y,domain:[n,r]};if(e.y2!==null){let n=t.y2.filter(e=>e!==null);return[i,a,{kind:`linear`,field:e.y2,domain:[Math.min(0,...n),Math.max(0,...n)]}]}return e.horizontal?[a,i]:[i,a]},draw(e){let{spec:t,shaped:n}=e,r=t.horizontal,l=r?e.y:e.x,u=r?e.x:e.y,d=v(n.visible.map(e=>n.series[e]),[0,l.bandwidth],.1,0),f=j(t),p=``,m=``;for(let h of N(t,n)){let g=n.visible.indexOf(h.si),_=l.at(h.ci)+(t.stack||t.type===`waterfall`?0:d.at(g)),v=t.stack||t.type===`waterfall`?l.bandwidth:d.bandwidth,[y,b]=[u.of(h.y0),u.of(h.y1)],x=Math.min(y,b),S=Math.abs(y-b),[C,w,T,E]=r?[x,_,S,v]:[_,x,v,S],D=n.categories[h.ci],O=n.series[h.si],k=f(D,O),A={"data-key":s(O,D),"data-c":h.ci,"data-s":h.s,"data-x":e.fmt(t.x,D),"data-series":O,"data-f":e.fmt(t.y,h.v),"data-y":h.v,"data-neg":h.v<0,"data-tone":e.tone(h.v),"data-q":k===null?null:e.q(k),"data-other":D===o,"data-total":n.totals[h.ci]};if(p+=a(`rect`,{"data-maya":`mark`,...A,x:i(C),y:i(w),width:i(T),height:i(E)}),m+=c(A,C,w,T,E),t.labels){let n=e.fmt(t.y,h.v),i=n.length*7.2+4,[a,o]=[C+T/2,w+E/2],s=h.v<0;r?i<=T&&E>=14?e.label(a,o,n,`center`):e.label(s?C-4:C+T+4,o,n,s?`end`:`start`):i<=T&&E>=16?e.label(a,o,n,`center`):e.label(a,s?w+E:w,n,s?`below`:`above`)}}if(e.y2&&t.y2!==null&&n.y2.length){let r=t.y2,o=n.series.length%8,u=t.titles.get(r)??r,d=``,f=!0,h=``;n.y2.forEach((p,g)=>{if(p===null){f=!0;return}let _=i(l.at(g)+l.bandwidth/2),v=i(e.y2.of(p));d+=`${f?`M`:`L`}${_} ${v}`,f=!1;let y=n.categories[g],b={"data-key":s(`\0y2`,y),"data-c":g,"data-s":o,"data-x":e.fmt(t.x,y),"data-series":u,"data-f":e.fmt(r,p),"data-y":p,"data-neg":p<0};h+=a(`circle`,{"data-maya":`mark`,...b,r:3,cx:_,cy:v}),m+=c(b,_-3,v-3,6,6),t.labels&&e.label(+_,+v,e.fmt(r,p),`above`)}),p+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,`\0y2`),"data-s":o,pathLength:1,d:d||null})+h}return{marks:p,hits:m}}};function F(e,t){let n=[],r=new Map(t.categories.map((e,t)=>[e,t])),i=e.yDomain;return e.data.forEach((a,o)=>{let s=a[e.y];if(typeof s!=`number`||!Number.isFinite(s)||i&&(s<i[0]||s>i[1]))return;let c=e.x===``?0:r.get(String(a[e.x]));if(c===void 0)return;let l=t.series.indexOf(e.series===null?``:String(a[e.series]));if(!t.visible.includes(l))return;let u=e.name===null?null:a[e.name];n.push({i:o,v:s,ci:c,si:l,name:u==null?null:String(u),row:a})}),n}function I(e,t,n){let r=e.map((e,t)=>t).sort((t,n)=>e[t]-e[n]||t-n),i=(2*t)**2,a=Array(e.length).fill(0),o=[],s=0;for(let c of r){let r=e[c];for(;s<o.length&&r-e[o[s]]>=2*t;)s++;let l=o.slice(s),u=[0];for(let t of l){let n=Math.sqrt(Math.max(0,i-(r-e[t])**2));u.push(a[t]+n,a[t]-n)}u.sort((e,t)=>Math.abs(e)-Math.abs(t)||t-e);let d=u.find(t=>l.every(n=>(r-e[n])**2+(t-a[n])**2>=i-1e-6))??0;d=Math.max(-n,Math.min(n,d)),a[c]=d,o.push(c)}return a}var ee={noun:`Beeswarm`,axes(e,t){let n=1/0,r=-1/0;for(let i of F(e,t))n=Math.min(n,i.v),r=Math.max(r,i.v);n>r&&(n=r=0);let i=e.x===``?null:{kind:`band`,field:e.x,domain:t.categories};return[{kind:`linear`,field:e.y,domain:e.yDomain??[n,r]},i]},draw(e){let{spec:t,shaped:n,plot:r}=e,o=e.x,l=e.y,u=F(t,n),d=l?l.bandwidth:r.h,f=/* @__PURE__ */ new Map;for(let e of u)(f.get(e.ci)??f.set(e.ci,[]).get(e.ci)).push(e);let p=1;for(let e of f.values())p=Math.max(p,e.length);let m=Math.max(3,Math.min(6,Math.sqrt(r.w*d/p)/4)),h=typeof t.colorBy==`string`&&t.colorBy!==`sign`?t.colorBy:null,g=/* @__PURE__ */ new Map,_=``,v=``;for(let[u,p]of[...f].sort((e,t)=>e[0]-t[0])){let f=l?l.at(u)+l.bandwidth/2:r.y+r.h/2,y=p.map(e=>o.of(e.v)),b=I(y,m+.5,Math.max(0,d/2-m));p.forEach((r,o)=>{let d=r.i;if(r.name!==null){let e=(g.get(r.name)??0)+1;g.set(r.name,e),d=e>1?`${r.name}#${e}`:r.name}let p=n.series[r.si],x=e.fmt(t.y,r.v),S=h?r.row[h]:null,C={"data-key":s(p,d),"data-c":r.i,"data-s":r.si%8,"data-x":r.name??(l?e.fmt(t.x,n.categories[u]):``),"data-series":p,"data-y":r.v,"data-f":x,"data-neg":r.v<0,"data-tone":e.tone(r.v),"data-q":typeof S==`number`?e.q(S):null},w=y[o],T=f+b[o];_+=a(`circle`,{"data-maya":`mark`,...C,r:i(m),cx:i(w),cy:i(T)}),v+=c(C,w-m,T-m,m*2,m*2),t.labels&&e.label(w,T-m,x,`above`)})}return{marks:_,hits:v}}},L={noun:`Dumbbell`,axes(e,t){let n={kind:`band`,field:e.x,domain:t.categories},r={kind:`linear`,field:e.y,domain:t.extent};return e.horizontal?[r,n]:[n,r]},draw(e){let{spec:t,shaped:n}=e,r=t.horizontal,l=r?e.y:e.x,u=r?e.x:e.y,d=Math.max(3,Math.min(5,l.bandwidth/2-1)),f=/* @__PURE__ */ new Map;for(let e of n.cells)e.value!==null&&e.si<2&&((f.get(e.ci)??f.set(e.ci,[]).get(e.ci))[e.si]=e.value);let p=``,m=``,h=``;for(let[g,_]of[...f].sort((e,t)=>e[0]-t[0])){let f=n.categories[g],v=l.at(g)+l.bandwidth/2,y=e=>r?[u.of(e),v]:[v,u.of(e)],[b,x]=_;if(b!==void 0&&x!==void 0){let[t,n]=y(b),[r,o]=y(x);p+=a(`line`,{"data-maya":`link`,"data-key":s(`k`,f),"data-c":g,"data-tone":e.tone(x-b),"stroke-width":2,x1:i(t),y1:i(n),x2:i(r),y2:i(o)})}for(let l of[0,1]){let u=_[l];if(u===void 0)continue;let[p,v]=y(u),b=n.series[l],x={"data-key":s(b,f),"data-c":g,"data-s":l%8,"data-x":e.fmt(t.x,f),"data-series":b,"data-f":e.fmt(t.y,u),"data-y":u,"data-neg":u<0,"data-other":f===o};if(m+=a(`circle`,{"data-maya":`mark`,...x,cx:i(p),cy:i(v),r:d}),h+=c(x,p-d,v-d,d*2,d*2),t.labels){let n=_[1-l],[i,a]=y(n??u),o=e.fmt(t.y,u),s=r?p>=i:v>=a,c=n===void 0?r:l===1?s:!s;r?e.label(p+(c?d+4:-d-4),v,o,c?`start`:`end`):e.label(p,v+(c?d:-d),o,c?`below`:`above`)}}}return{marks:p+m,hits:h}}},te={noun:`Heatmap`,axes:(e,t)=>[{kind:`band`,field:e.x,domain:t.categories},{kind:`band`,field:e.series??``,domain:t.series}],draw(e){let{spec:t,shaped:n}=e,o=e.x,l=e.y,u=n.cells.filter(e=>e.value!==null),d=1/0,f=-1/0;for(let e of u)d=Math.min(d,e.value),f=Math.max(f,e.value);let p=e=>f>d?Math.min(9,Math.max(0,Math.floor((e-d)/(f-d)*10))):9,m=``,h=``;for(let[r,d]of u.entries()){let u=d.value,f=n.visible.indexOf(d.si),g=o.at(d.ci)+1,_=l.at(f)+1,v=Math.max(0,o.bandwidth-2),y=Math.max(0,l.bandwidth-2),b=n.categories[d.ci],x=n.series[d.si],S={"data-key":s(x,b),"data-c":r,"data-x":e.fmt(t.x,b),"data-series":x,"data-y":u,"data-f":e.fmt(t.y,u),"data-q":p(u)};m+=a(`rect`,{"data-maya":`mark`,...S,x:i(g),y:i(_),width:i(v),height:i(y)}),h+=c(S,g,_,v,y),t.labels!==!1&&v>=24&&y>=24&&e.label(g+v/2,_+y/2,e.fmt(t.y,u),`center`)}let g=u.length>0?`<div class="maya-legend" data-maya="ramp"><span>${r(e.fmt(t.y,d))}</span><i></i><span>${r(e.fmt(t.y,f))}</span></div>`:``;return{marks:m,hits:h,grid:``,legend:g}}},R=12,ne=e=>typeof e==`number`?e:null;function re(e){let{spec:t,shaped:n,width:o,height:c}=e,l=t.x?n.categories:[],u=t.x?n.cells.filter(e=>e.si===0).sort((e,t)=>e.ci-t.ci):[],d=u.filter(e=>e.value!==null),f=d[d.length-1],p=t.x?f?.value??null:e.agg(t.aggregate)(t.data.map(e=>ne(e[t.y]))),m=o/2;if(p===null)return{marks:``,hits:``,labels:a(`text`,{"data-maya":`empty`,x:i(m),y:i(c/2),"text-anchor":`middle`},r(e.t(`noData`)))};let h=f?.ci??0,g=t.x?e.fmt(t.x,l[h]):``,_=e.fmt(t.y,p),v=i(Math.max(16,Math.min(c*.32,72,(o-24)/(_.length*.62)))),y={"data-c":h,"data-s":0,"data-x":g,"data-series":``,"data-y":p,"data-f":_},b=(e,t)=>a(`text`,{"dominant-baseline":`hanging`,x:R,...e},r(t)),x=a(`text`,{"data-maya":`mark`,"data-key":`v`,...y,"font-size":v,x:R,y:R,"dominant-baseline":`hanging`},r(_)),S=``,C=``,w=R+v+4,T=d[d.length-2];if(f&&T&&T.value){let n=(p-T.value)/Math.abs(T.value),r=new Intl.NumberFormat(t.locale,{style:`percent`,maximumFractionDigits:1,signDisplay:`exceptZero`}).format(n);S+=b({"data-kpi":`delta`,"data-tone":n>0?`good`:n<0?`bad`:null,y:i(w),"font-size":12},e.t(`vs`,r,e.fmt(t.x,l[T.ci]))),w+=16}g&&(S+=b({"data-kpi":`period`,y:i(w),"font-size":11},g)),w+=18;let E=``,D=typeof t.colorBy==`object`&&t.colorBy?t.colorBy.target:null,O=c-R;if(D){let n=o-24,r=Math.min(Math.max(p/D,0),1.2)/1.2,s=new Intl.NumberFormat(t.locale,{style:`percent`,maximumFractionDigits:1});O-=8,E=a(`rect`,{"data-kpi":`track`,x:R,y:O,width:i(n),height:8,rx:4}),x+=a(`rect`,{"data-maya":`mark`,"data-key":`b`,...y,"data-kpi":`fill`,"data-tone":e.tone(p),x:R,y:O,width:i(n*r),height:8,rx:4}),S+=a(`line`,{"data-kpi":`target`,"stroke-width":2,x1:i(R+n/1.2),x2:i(R+n/1.2),y1:O-3,y2:O+11}),S+=b({"data-kpi":`of`,y:O-16,"font-size":11},e.t(`ofTarget`,s.format(p/D),e.fmt(t.y,D))),O-=24}if(l.length>=3&&O-w>=28){let n=d.map(e=>e.value),r=Math.min(...n),p=Math.max(...n)-r||1,m=l.length-1,h=(o-24)/m,g=e=>i(R+e*h),_=e=>i(O-(e-r)/p*(O-w-4)-2),v=``,y=!0;u.forEach(n=>{if(n.value===null)return void(y=!0);v+=`${y?`M`:`L`}${g(n.ci)} ${_(n.value)}`,y=!1,x+=a(`circle`,{"data-maya":`mark`,"data-key":s(``,l[n.ci]),"data-c":n.ci,"data-s":0,"data-x":e.fmt(t.x,l[n.ci]),"data-series":``,"data-y":n.value,"data-f":e.fmt(t.y,n.value),"data-neg":n.value<0,"data-last":n===f,r:3,cx:g(n.ci),cy:_(n.value)})}),x=a(`path`,{"data-maya":`line`,"data-key":s(`l`,``),"data-s":0,pathLength:1,d:v||null})+x,l.forEach((e,t)=>{C+=a(`rect`,{"data-maya":`hit`,"data-c":t,x:i(Math.max(0,R+t*h-h/2)),y:0,width:i(h),height:c,fill:`transparent`})})}return{marks:x,hits:C,labels:S,grid:E}}var ie={noun:`KPI`,draw:re},ae=26,oe=12,se=48,ce=14,le={noun:`Parallel coordinates`,draw(e){let{spec:t,shaped:n,width:o,height:c}=e,l=t.measures,u=/* @__PURE__ */ new Map;for(let e of t.data){let n=String(e[t.x]);(u.get(n)??u.set(n,[]).get(n)).push(e)}let d=e.agg(t.aggregate),f=n.categories.flatMap((e,r)=>{let i=u.get(e);if(!i||e===`\0other`)return[];let a=l.map(e=>d(i.map(t=>t[e]))),o=t.series===null?0:Math.max(0,n.series.indexOf(String(i[0][t.series])));return n.visible.includes(o)?[{cat:e,ci:r,vals:a,si:o}]:[]}),p=se,m=Math.max(49,o-ce),[h,g]=[ae,Math.max(27,c-oe)],_=e=>i(l.length<2?p:p+(m-p)*e/(l.length-1)),v=``,y=``,b=l.map((n,o)=>{let s=f.map(e=>e.vals[o]).filter(e=>e!==null),c=x(Math.min(0,...s),Math.max(0,...s),4),[u,d]=c.domain,p=e=>i(g-(e-u)/(d-u||1)*(g-h)),m=_(o);v+=a(`line`,{x1:m,x2:m,y1:i(h),y2:i(g)});for(let t of c.values){let i=p(t);v+=a(`line`,{x1:m-3,x2:m,y1:i,y2:i}),y+=a(`text`,{x:m-6,y:i,"text-anchor":`end`,"dominant-baseline":`middle`,"data-in":!0},r(e.fmt(n,t,c.step)))}return y+=a(`text`,{x:m,y:12,"text-anchor":o===0?`start`:o===l.length-1?`end`:`middle`,"font-weight":600,"data-in":!0},r(t.titles.get(n)??n)),p}),S=``,C=``,w=``;for(let{cat:n,ci:r,vals:i,si:o}of f){let c=e.fmt(t.x,n),u=``,d=!0;i.forEach((i,f)=>{if(i===null){d=!0;return}let[p,m]=[_(f),b[f](i)];u+=`${d?`M`:`L`}${p} ${m}`,d=!1,S+=a(`circle`,{"data-maya":`mark`,"data-key":s(n,l[f]),"data-c":r,"data-s":o%8,"data-x":c,"data-series":t.titles.get(l[f])??l[f],"data-y":i,"data-f":e.fmt(l[f],i),"data-neg":i<0,r:3.5,cx:p,cy:m})}),u&&(C+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,n),"data-c":r,"data-s":o%8,pathLength:1,d:u}),w+=a(`path`,{"data-maya":`hit`,"data-c":r,d:u,fill:`none`,stroke:`transparent`,"stroke-width":16,"stroke-linejoin":`round`}))}return{marks:S+C,hits:w,grid:v,labels:y}}},ue={noun:`Ridgeline`,axes:(e,t)=>[{kind:`band`,field:e.x,domain:t.categories},{kind:`band`,field:e.series??``,domain:t.visible.map(e=>t.series[e])}],draw(e){let{spec:t,shaped:n,plot:r}=e,c=e.x,l=e.y,u=j(t),d=e=>i(c.at(e)+c.bandwidth/2),f=0;for(let e of n.cells)e.value!==null&&e.value>f&&(f=e.value);f<=0&&(f=1);let p=e=>l.at(e)+l.bandwidth/2+l.step/2,m=Math.min(1.4*l.step,p(0)-r.y),h=``,g=``;n.visible.forEach((r,c)=>{let l=n.series[r],_=p(c),v=e=>i(_-e/f*m),y=n.cells.filter(e=>e.si===r).sort((e,t)=>e.ci-t.ci),b=[[]];for(let i of y){if(i.value===null){b.push([]);continue}b[b.length-1].push(i);let c=n.categories[i.ci],f=u(c,l);g+=a(`circle`,{"data-maya":`mark`,"data-key":s(l,c),"data-c":i.ci,"data-s":r%8,"data-x":e.fmt(t.x,c),"data-series":l,"data-y":i.value,"data-f":e.fmt(t.y,i.value),"data-neg":i.value<0,"data-tone":e.tone(i.value),"data-q":f===null?null:e.q(f),"data-other":c===o,r:3,cx:d(i.ci),cy:v(i.value)})}let x=e=>e.map((e,t)=>`${t?`L`:`M`}${d(e.ci)} ${v(e.value)}`),S=b.filter(e=>e.length>0),C=S.map(e=>`${x(e).join(``)}L${d(e.at(-1).ci)} ${i(_)}L${d(e[0].ci)} ${i(_)}Z`).join(``);C&&(h+=a(`path`,{"data-maya":`area`,"data-ridge":!0,"data-key":s(`a`,l),"data-s":r%8,d:C})),h+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,l),"data-s":r%8,pathLength:1,d:S.map(e=>x(e).join(``)).join(``)||null})});let _=``;return n.categories.forEach((e,t)=>{_+=a(`rect`,{"data-maya":`hit`,"data-c":t,x:i(c.at(t)),y:i(r.y),width:i(c.bandwidth),height:i(r.h),fill:`transparent`})}),{marks:h+g,hits:_,cross:a(`line`,{x1:0,x2:0,y1:i(r.y),y2:i(r.y+r.h)})}}},de=(e,t)=>[{kind:`band`,field:e.x,domain:t.categories},{kind:`linear`,field:e.y,domain:t.extent}];function fe(e,t){let{spec:n,shaped:r,plot:c}=e,l=e.x,u=e.y,d=j(n),f=e=>i(l.at(e)+l.bandwidth/2),p=``,m=``,h=``;for(let c of r.visible){let l=r.series[c],g=r.cells.filter(e=>e.si===c).sort((e,t)=>e.ci-t.ci),_=``,v=!0,y=[[]];for(let t of g){if(t.value===null&&!n.stack?y.push([]):y[y.length-1].push(t),t.value===null){v=!0;continue}_+=`${v?`M`:`L`}${f(t.ci)} ${i(u.of(t.y1))}`,v=!1;let p=r.categories[t.ci],m=d(p,l),g=p===o,b=e.fmt(n.x,p);h+=a(`circle`,{"data-maya":`mark`,"data-key":s(l,p),"data-c":t.ci,"data-s":c%8,"data-x":b,"data-series":l,"data-y":t.value,"data-f":e.fmt(n.y,t.value),"data-neg":t.value<0,"data-tone":e.tone(t.value),"data-q":m===null?null:e.q(m),"data-other":g,r:3,cx:f(t.ci),cy:i(u.of(t.y1))}),n.labels&&e.label(f(t.ci),u.of(t.y1),e.fmt(n.y,t.value),`above`)}if(t){let e=y.filter(e=>e.length>0).map(e=>e.map((e,t)=>`${t?`L`:`M`}${f(e.ci)} ${i(u.of(e.y1))}`).join(``)+[...e].reverse().map(e=>`L${f(e.ci)} ${i(u.of(e.y0))}`).join(``)+`Z`).join(``);e&&(p+=a(`path`,{"data-maya":`area`,"data-key":s(`a`,l),"data-s":c%8,d:e}))}m+=a(`path`,{"data-maya":`line`,"data-key":s(`l`,l),"data-s":c%8,pathLength:1,d:_||null})}let g=``;return r.categories.forEach((e,t)=>{g+=a(`rect`,{"data-maya":`hit`,"data-c":t,x:i(l.at(t)),y:i(c.y),width:i(l.bandwidth),height:i(c.h),fill:`transparent`})}),{marks:p+m+h,hits:g,cross:a(`line`,{x1:0,x2:0,y1:i(c.y),y2:i(c.y+c.h)})}}var pe={noun:`Line`,axes:de,draw:e=>fe(e,!1)},me={noun:`Area`,axes:de,draw:e=>fe(e,!0)},he=24;function ge(e,t){let n=[],r=e.xDomain,i=e.yDomain,a=e.window;return e.data.forEach((o,s)=>{let c=o[e.x],l=o[e.y];if(typeof c!=`number`||typeof l!=`number`||r&&(c<r[0]||c>r[1])||i&&(l<i[0]||l>i[1])||a&&(c<a[0]||c>a[1]||l<a[2]||l>a[3]))return;let u=t.series.indexOf(e.series===null?``:String(o[e.series]));if(!t.visible.includes(u))return;let d=e.size===null?null:o[e.size],f=e.name===null?null:o[e.name];n.push({i:s,x:c,y:l,sz:typeof d==`number`?d:null,si:u,name:f==null?null:String(f),row:o})}),n}var _e={noun:`Scatter`,axes(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let o of ge(e,t))n=Math.min(n,o.x),r=Math.max(r,o.x),i=Math.min(i,o.y),a=Math.max(a,o.y);n>r&&(n=r=0,i=a=0);let o=e.size===null?0:(r-n)*.06,s=e.size===null?0:(a-i)*.06,c=(e,t)=>e>=0?Math.max(0,e-t):e-t;return[n,r,i,a]=[c(n,o),r+o,c(i,s),a+s],[{kind:`linear`,field:e.x,domain:e.xDomain??[n,r]},{kind:`linear`,field:e.y,domain:e.yDomain??[i,a]}]},draw(e){let{spec:t,shaped:n,plot:r}=e,o=e.x,c=e.y,l=ge(t,n),u=0;for(let e of l)e.sz!==null&&(u=Math.max(u,Math.abs(e.sz)));let d=Math.min(r.w,r.h)/16,f=typeof t.colorBy==`string`&&t.colorBy!==`sign`?t.colorBy:null,p=/* @__PURE__ */ new Map,m=l.map(r=>{let i=r.sz!==null&&u>0?2+Math.sqrt(Math.abs(r.sz)/u)*d:4,a=r.i;if(r.name!==null){let e=(p.get(r.name)??0)+1;p.set(r.name,e),a=e>1?`${r.name}#${e}`:r.name}let l=n.series[r.si],m=e.fmt(t.x,r.x),h=e.fmt(t.y,r.y),g=f?r.row[f]:null;return{p:r,rad:i,d:{"data-key":s(l,a),"data-c":r.i,"data-s":r.si%8,"data-x":r.name??m,"data-series":l,"data-y":r.y,"data-f":r.name===null&&r.sz===null?h:[m,h,r.sz===null?null:e.fmt(t.size,r.sz)].filter(e=>e!==null).join(` · `),"data-neg":r.y<0,"data-tone":e.tone(r.y),"data-q":typeof g==`number`?e.q(g):null},cx:o.of(r.x),cy:c.of(r.y)}});m.sort((e,t)=>t.rad-e.rad);let h=``,g=``;for(let{p:n,rad:r,d:o,cx:s,cy:c}of m)h+=a(`circle`,{"data-maya":`mark`,...o,r:i(r),cx:i(s),cy:i(c)}),r*2<he&&(g+=a(`circle`,{"data-maya":`hit`,...o,r:i(Math.max(r,12)),cx:i(s),cy:i(c),fill:`transparent`})),t.labels&&e.label(s,c-r,e.fmt(t.y,n.y),`above`);return{marks:h,hits:g}}},z=30,B=26,V=8,ve=e=>typeof e==`number`?e:null,ye={noun:`Table`,draw(e){let{spec:t,width:n,height:o}=e,l=t.measures,u=e=>t.titles.get(e)??e,d=e.agg(t.aggregate),f=/* @__PURE__ */ new Map;for(let e of t.data){let n=String(e[t.x]),r=f.get(n)??f.set(n,l.map(()=>[])).get(n);l.forEach((t,n)=>r[n].push(ve(e[t])))}let p=[...f].map(([e,t])=>({name:e,vals:t.map(e=>d(e))})),m=(e,t)=>e===null?1/0:e*t,h=(e,t)=>(n,r)=>m(n.vals[e],t)-m(r.vals[e],t)||0;t.limit!==null&&p.length>t.limit&&(p=p.sort(h(0,-1)).slice(0,t.limit));let g=t.sortBy&&(t.sortBy[0]===t.x||l.includes(t.sortBy[0]))?t.sortBy:null;if(g){let e=g[1]===`asc`?1:-1,n=l.indexOf(g[0]);if(n<0){let n=new Intl.Collator(t.locale,{numeric:!0});p.sort((t,r)=>e*n.compare(t.name,r.name))}else p.sort((t,r)=>{let[i,a]=[t.vals[n],r.vals[n]];return i===null||a===null?(i===null)-+(a===null):e*(i-a)})}else t.sort&&p.sort(h(0,t.sort===`asc`?1:-1));let _=Math.max(80,Math.min(n*.34,180)),v=(n-_)/l.length,y=e=>_+e*v,b=l.map((e,t)=>Math.max(0,...p.map(e=>Math.abs(e.vals[t]??0)))),x=(e,t)=>{let n=Math.max(1,Math.floor((t-V)/7));return e.length>n?e.slice(0,n-1)+`…`:e},S=``,C=``;[t.x,...l].forEach((t,n)=>{let o=n?y(n-1):0,s=n?v:_,c=g?.[0]===t?g[1]:null,l=x(u(t),s-(c?14:0))+(c?c===`asc`?` ▲`:` ▼`:``);C+=a(`g`,{"data-maya":`sort`,"data-field":t,"data-sort":c,role:`button`,tabindex:0,"aria-label":c?e.t(`sortedBy`,u(t),e.t(c===`asc`?`ascending`:`descending`)):u(t)},a(`rect`,{x:i(o),y:0,width:i(s),height:z,fill:`transparent`})+a(`text`,{"data-th":!0,x:i(n?o+s-V:V),y:z/2,"text-anchor":n?`end`:`start`,"dominant-baseline":`middle`},r(l)))}),S+=a(`line`,{x1:0,x2:n,y1:z,y2:z});let w=Math.max(0,Math.floor((o-z)/B)),T=``;return p.slice(0,w).forEach((n,o)=>{let d=z+o*B,f=e.fmt(t.x,n.name);T+=a(`text`,{"data-key":s(`t`,n.name),x:V,y:d+B/2-2,"dominant-baseline":`middle`,"data-td":`label`},r(x(f,_))),l.forEach((t,p)=>{let m=n.vals[p],h=y(p)+v-V,g=m===null?`–`:e.fmt(t,m);if(T+=a(`text`,{"data-key":s(`v`,t,n.name),x:i(h),y:d+B/2-2,"text-anchor":`end`,"dominant-baseline":`middle`},r(g)),m===null)return;let _=b[p]?(v-16)*Math.abs(m)/b[p]:0,x={"data-key":s(t,n.name),"data-c":o,"data-s":l.length>1?p%8:0,"data-x":f,"data-series":u(t),"data-f":g,"data-y":m,"data-neg":m<0},S=d+B-7;T+=a(`rect`,{"data-maya":`mark`,...x,x:i(y(p)+V),y:S,width:i(_),height:4}),C+=c(x,y(p)+V,S,_,4)})}),{marks:T,hits:C,labels:``,grid:S}}},be=`0.2.0`,xe=Symbol.for(`mayacharts.marks@0`);Object.hasOwn(globalThis,xe)||Object.defineProperty(globalThis,xe,{value:/* @__PURE__ */ new Map});var Se=globalThis[xe],Ce=[`bar`,`line`,`area`,`scatter`,`heatmap`,`waterfall`,`kpi`,`dumbbell`,`ridgeline`,`beeswarm`,`parallel`,`table`],we={treemap:`hierarchy`,sunburst:`hierarchy`,marimekko:`hierarchy`,waffle:`hierarchy`,sankey:`flow`,chord:`flow`,radial:`radial`,hexmap:`geo`},Te=()=>[...Se.keys()],Ee=`--maya-fg:#1f2328;--maya-fg-muted:#656d76;--maya-bg:#fff`,De=`--maya-fg:#e6edf3;--maya-fg-muted:#9198a1;--maya-bg:#0d1117`,H=(e,t=0)=>Array.from({length:e},(e,n)=>n+t),Oe=H(8).map(e=>`[data-s="${e}"]{--c:var(--maya-series-${e+1})}`).join(``),ke=H(10).map(e=>`[data-q="${e}"]{--q:${Math.round(20+e*80/9)}%}`).join(``),Ae=H(8).map(e=>`.maya:has([data-s="${e}"]:hover) [data-maya=mark]:not([data-s="${e}"]){opacity:.3}`).join(``),je=H(3,2).map(e=>`.maya-ctl[data-n="${e}"]::before{width:calc((100% - 4px)/${e})}`).join(``)+H(3,1).map(e=>`.maya-ctl[data-i="${e}"]::before{transform:translateX(${e*100}%)}`).join(``),Me=`border:0;background:none;padding:0;font:inherit;color:var(--maya-fg-muted);cursor:pointer`,Ne=`:host,.maya-root{--maya-font:system-ui,sans-serif;--maya-font-size:12px;--maya-fg:light-dark(#1f2328,#e6edf3);--maya-fg-muted:light-dark(#656d76,#9198a1);--maya-grid:color-mix(in oklab,var(--maya-fg) 12%,transparent);--maya-bg:light-dark(#fff,#0d1117);--maya-accent:oklch(.6 .17 255);--maya-radius:2px;--maya-tooltip-bg:var(--maya-fg);--maya-tooltip-fg:var(--maya-bg);--maya-focus:var(--maya-accent);--maya-good:light-dark(#1a7f37,#3fb950);--maya-bad:light-dark(#cf222e,#f85149);--maya-series-1:var(--maya-accent);--maya-series-2:oklch(.66 .16 50);--maya-series-3:oklch(.62 .15 160);--maya-series-4:oklch(.66 .17 330);--maya-series-5:oklch(.62 .14 90);--maya-series-6:oklch(.62 .12 205);--maya-series-7:oklch(.64 .19 22);--maya-series-8:oklch(.62 .16 295);color-scheme:light dark}@supports not (color:light-dark(#000,#fff)){:host,.maya-root{${Ee}}@media (prefers-color-scheme:dark){:host,.maya-root{${De}}}}:host{display:block;position:relative;container-type:inline-size;min-height:200px}.maya{display:flex;flex-direction:column;height:100%;font:var(--maya-font-size) var(--maya-font);font-variant-numeric:tabular-nums;color:var(--maya-fg)}.maya-title{font-weight:600;font-size:14px}.maya-legend,.maya-crumbs{color:var(--maya-fg-muted);display:flex;flex-wrap:wrap;align-items:center;gap:4px 12px;margin:0 0 8px}.maya-crumbs{min-height:1.25em;line-height:1.25}.maya-legend button,.maya-crumbs button,.maya-reset{display:inline-flex;align-items:center;gap:6px;${Me};border-radius:4px}.maya-legend [aria-pressed=false]{opacity:.4}:is(.maya-legend,.maya-crumbs) button:focus-visible,.maya-reset:focus-visible,.maya-ctl :focus-visible{outline:2px solid var(--maya-focus);outline-offset:2px}i{width:10px;height:10px;border-radius:3px;background:var(--c)}[data-maya=ramp]{display:flex;align-items:center;gap:6px}[data-maya=ramp] i{width:80px;height:8px;background:linear-gradient(90deg,color-mix(in oklab,var(--maya-accent) 20%,var(--b)),var(--maya-accent))}[data-q],[data-maya=ramp] i{--b:light-dark(var(--maya-bg),color-mix(in oklab,var(--maya-accent) 15%,var(--maya-bg)))}.maya-legend span{display:inline-flex;align-items:center;gap:6px}.maya-reset{position:absolute;top:4px;right:4px;border:1px solid var(--maya-grid);border-radius:99px;padding:2px 10px;background:var(--maya-bg)}.maya-ctl{position:relative;display:inline-grid;grid-auto-flow:column;grid-auto-columns:1fr;align-self:flex-start;margin:0 0 8px;padding:2px;border-radius:8px;background:var(--maya-grid)}.maya-ctl::before{content:'';position:absolute;inset:2px auto 2px 2px;width:calc(100% - 4px);border-radius:6px;background:var(--maya-bg);transition:transform .2s}`+je+`.maya-ctl [role=radio]{${Me};position:relative;padding:4px 12px;border-radius:6px}.maya-ctl [aria-checked=true]{color:var(--maya-fg);font-weight:600}.maya-err{margin:0;padding:8px;color:var(--maya-bad);white-space:pre-wrap;font:12px monospace}.maya-box{flex:1;min-height:0;position:relative}.maya-box svg{display:block;width:100%;height:100%;overflow:visible}.maya-svg{direction:ltr;font:var(--maya-font-size) var(--maya-font);font-variant-numeric:tabular-nums}.maya-svg text{fill:var(--maya-fg-muted);unicode-bidi:plaintext}[data-maya=grid] *{stroke:var(--maya-grid);shape-rendering:crispEdges}`+Oe+`[data-other],[data-total]{--c:var(--maya-fg-muted)}[data-tone=good]{--c:var(--maya-good)}[data-tone=bad]{--c:var(--maya-bad)}[data-q]{--c:color-mix(in oklab,var(--maya-accent) var(--q),var(--b))}`+ke+`[data-maya=mark]{fill:var(--c,var(--maya-series-1));rx:var(--maya-radius);transform-box:fill-box;transform-origin:0 0}[data-dir=h] [data-neg]{transform-origin:100% 0}[data-maya=mark],[data-maya=link]{transition:opacity .2s}[data-maya=mark][data-active]{fill:color-mix(in oklab,var(--c,var(--maya-series-1)),var(--maya-fg) 18%)}:where([data-xd] circle[data-maya=mark]){stroke:var(--maya-bg);stroke-width:1}[data-maya=line]~circle[data-maya=mark]:not([data-active],[data-selected],[data-last]){fill-opacity:0}[data-maya=line]{fill:none;stroke:var(--c);stroke-width:2;stroke-linejoin:round}[data-maya=area]{fill:color-mix(in oklab,var(--c) 18%,transparent);stroke:none}[data-maya=link]{fill:var(--c);opacity:.3}[data-maya=link][data-active]{opacity:.6}line[data-maya=link]{stroke:var(--c,var(--maya-fg-muted));opacity:1}text[data-maya=mark]{fill:var(--maya-fg);font-weight:600}[data-kpi=track]{fill:var(--maya-grid)}[data-kpi=target]{stroke:var(--maya-fg)}[data-maya=labels] [data-tone]{fill:var(--c)}[data-maya=labels] :is([data-kpi=period],[data-kpi=of]){fill:var(--maya-fg-muted)}[data-line] i{height:2px;border-radius:1px}[data-ridge]{fill:color-mix(in oklab,var(--c) 40%,var(--maya-bg))}[data-maya=grid] circle{fill:none;shape-rendering:auto}[data-maya=labels] [data-ring]{fill:var(--maya-fg-muted)}[data-maya=marks] text{fill:var(--maya-fg)}[data-maya=sort]{cursor:pointer}[data-maya=sort] rect{fill:transparent}[data-maya=sort] text{font-weight:600}[data-maya=sort]:focus-visible{outline:2px solid var(--maya-focus)}[data-maya=line]{transition:opacity .2s}[data-maya=marks]:has(path[data-active]) path[data-maya=line]:not([data-active]){opacity:.25}[data-depth]{stroke:var(--maya-bg);stroke-width:1}[data-maya=marks]:has([data-active]) [data-maya=mark]:not([data-active],text){opacity:.55}[data-maya=marks]:has([data-selected]) [data-maya=mark]:not([data-selected]){opacity:.35}[data-selected]{stroke:var(--maya-fg);stroke-width:2}`+Ae+`[data-maya=labels],[data-maya=cross]{pointer-events:none}[data-maya=cross]{opacity:0}[data-maya=labels] text{fill:var(--maya-fg);paint-order:stroke;stroke:var(--maya-bg);stroke-width:3;stroke-linejoin:round}[data-maya=labels] [data-in]{stroke:none}[data-maya=cross] line{stroke:var(--maya-fg-muted);stroke-dasharray:3 3}[data-maya=brush]{fill:var(--maya-accent);fill-opacity:.12;stroke:var(--maya-accent);vector-effect:non-scaling-stroke;pointer-events:none}.maya-svg:focus-visible{outline:2px solid var(--maya-focus)}.maya-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.maya-probe{position:absolute;width:0;height:0;pointer-events:none;anchor-name:--maya-probe}.maya-tip{margin:0;inset:auto;border:0;padding:6px 8px;background:var(--maya-tooltip-bg);color:var(--maya-tooltip-fg);border-radius:6px;box-shadow:0 2px 8px #0003;font:var(--maya-font-size) var(--maya-font);pointer-events:none}@supports (anchor-name:--x){.maya-tip{position-anchor:--maya-probe;position-area:block-start;position-try-fallbacks:flip-block,block-start span-inline-start,block-start span-inline-end;margin:8px}}.maya-tip{opacity:0;transition:opacity .12s}.maya-tip.maya-open{opacity:1}.maya-tip b{display:block}.maya-tip div{display:flex;align-items:center;gap:6px}.maya-tip i{outline:1px solid}.maya-tip [data-on]{font-weight:600}@media (pointer:coarse){:is(.maya-legend,.maya-crumbs) button,.maya-ctl [role=radio],.maya-reset,.maya-crumbs{min-height:24px}}@container (max-width:320px){.maya-legend{display:none}.maya-title{font-size:12px}}@media (prefers-contrast:more){:host,.maya-root{--maya-fg-muted:var(--maya-fg);--maya-grid:color-mix(in oklab,var(--maya-fg) 40%,transparent)}}@media (forced-colors:active){.maya-svg,i{forced-color-adjust:none}[data-maya=mark]{stroke:CanvasText;stroke-width:1}[data-tone=bad]{stroke-dasharray:4 2}}@media (prefers-reduced-motion:reduce){*{transition:none!important}}`,Pe=class extends Error{code;path;constructor(e,t,n){super(n),this.name=`MayaSpecError`,this.code=e,this.path=t}},U=e=>e.split(` `),W=Object.fromEntries([...U(`$schema x y2 series size name title description locale currency`).map(e=>[e,`string`]),...U(`stack horizontal labels legend tooltip drill zoom grid xAxis yAxis table animate`).map(e=>[e,`boolean`])]),Fe=[...U(`type data y path totals aggregate sort limit format titles text yDomain xDomain select`),...U(`colors colorBy theme`),...Object.keys(W)],Ie=[`bar`,`line`,`area`,`dumbbell`],Le=[`treemap`,`sunburst`,`sankey`,`chord`],Re=[`parallel`,`table`],G=`bar,line,area`,ze=`treemap,sunburst,sankey,chord`,Be=Object.fromEntries(U(`horizontal:bar,dumbbell y2:bar size:scatter name:scatter,beeswarm path:${G},dumbbell,${ze} totals:waterfall series:${G},scatter,heatmap,dumbbell,ridgeline,beeswarm,parallel,marimekko,radial sort:${G},heatmap,dumbbell,table,radial,waffle limit:${G},heatmap,dumbbell,table,waffle,radial stack:bar,area colorBy:${G},waterfall,scatter,dumbbell,kpi,treemap,sunburst,hexmap xDomain:scatter drill:${G},dumbbell,${ze} select:${G},waterfall,scatter,heatmap,dumbbell,beeswarm,parallel,table,marimekko,waffle,radial,treemap,sunburst,hexmap zoom:line,area,scatter`).map(e=>e.split(`:`)).map(([e,t])=>[e,t.split(`,`)])),Ve=U(`sum mean count min max`),He=U(`auto integer decimal compact percent currency date month year time datetime`),Ue=U(`dateStyle timeStyle weekday era year month day dayPeriod hour minute second fractionalSecondDigits timeZoneName timeZone hour12 hourCycle calendar`),We=e=>Ue.some(t=>Object.hasOwn(e,t)),Ge=[...U(`font fontSize fg fgMuted grid bg accent radius tooltipBg tooltipFg focus good bad`),...[1,2,3,4,5,6,7,8].map(e=>`series`+e)],Ke={x:`the category axis`,y:`the plotted numbers`,y2:`the right-axis line`,series:`splitting rows into series`,size:`bubble area`,name:`point identity`,path:`the hierarchy levels`,colorBy:`colouring marks by value`,format:`formatting that field`,titles:`naming that field`},qe=`Use horizontal: true to put categories on the left axis.`,Je=`Size comes from the element's CSS box, or render(spec, { width, height }).`,Ye=`Pie and donut charts are not supported: use "bar" or "treemap" to compare parts.`,Xe=`Use type: "hexmap" (import "mayacharts/geo").`,Ze=`Example: { type: "bar", data: [{ month: "Jan", revenue: 10 }], x: "month", y: "revenue" }`,Qe={label:`Use titles: { <field>: "Name" } for display names, or labels: true for values on marks.`,xLabel:`Use titles: { <x field>: "Name" }. titles is keyed by field and also names tooltips and table headers.`,yLabel:`Use titles: { <y field>: "Name" }. titles is keyed by field and also names tooltips, legend and table headers.`,yFormat:`Use format: "compact" (applies to every y), or format: { <field>: "currency" }.`,dataKey:`Use y: "<field>" for values and x: "<field>" for categories.`,indexAxis:qe,orientation:qe,width:Je,height:Je,color:`Use colors: [...] for the palette, or colorBy: "sign" | { target: n } | "<field>".`,groupBy:`Use series: "<field>".`,formatter:`Functions are not supported (the spec is JSON). Use format presets or Intl options.`,"size:number":`spec.size names a field for bubble area. For chart size use CSS, or render(spec, { width, height }).`,"select:boolean":`Use select: true or "multi"; omit it to disable selection.`},$e={column:`Use type: "bar".`,barh:`Use type: "bar" with horizontal: true.`,bubble:`Use type: "scatter" with size: "<field>".`,choropleth:Xe,map:Xe,pie:Ye,donut:Ye},et=U(`rgb rgba hsl hsla oklch oklab lab lch color color-mix light-dark var calc`),tt=String.raw`\s*(?:"[\w\s.\-]*"|'[\w\s.\-]*'|[\w\-]+(?:\s+[\w\-]+)*)\s*`,nt=RegExp(`^${tt}(?:,${tt})*$`),rt=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0,K=e=>typeof e==`object`&&!!e&&!Array.isArray(e),q=(e,t=0)=>Array.isArray(e)&&e.length>=t&&e.every(e=>typeof e==`string`),J=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Y=e=>{let t=typeof e==`string`||K(e)||Array.isArray(e)?JSON.stringify(e):String(e);return t.length>60?t.slice(0,59)+`…`:t},X=(e,t)=>{let n=e.toLowerCase(),r=``,i=40;for(let e of t){let t=e.toLowerCase(),a=Math.abs(n.length-t.length)+[...t].filter(e=>!n.includes(e)).length,o=0;for(;o<9&&n[o]!==void 0&&n[o]===t[o];)o++;a<4&&a*10-o<i&&([i,r]=[a*10-o,e])}return r&&`Did you mean "${r}"?`},Z=(e,t,n,...r)=>{throw new Pe(e,t,`mayacharts: ${n}\n${[...r,`-> https://bbekshr.github.io/mayacharts/errors.html#${e}`].filter(Boolean).map(e=>` `+e).join(`
3
+ `)}`)},Q=(e,t,n)=>Z(`invalid-option`,e,`spec.${e} must be ${n}, received ${Y(t)}.`,rt(Qe,`${e}:${J(t)}`)??``),it=(e,t,n)=>{let r=n?nt.test(t):/^[#\w\s.,%()+\-\/]*$/.test(t)&&[...t.matchAll(/([\w-]*)\s*\(/g)].every(e=>et.includes(e[1].toLowerCase()));(!t||!r)&&Z(`unsafe-css-value`,e,`spec.${e} = ${Y(t)} is not a safe CSS value.`,`Allowed: colours, lengths, numbers and ${et.join(`() `)}(); fonts are family names.`,`Not allowed: url(), image-set(), other functions, ; { } < > \\ and (outside fonts) quotes.`)},$=(e,t,...n)=>Z(`invalid-format`,e,t,...n),at=(e,t,n)=>{if(typeof t==`string`){He.includes(t)||$(e,`spec.${e} = ${Y(t)} is not a format preset.`,`Presets: ${He.join(`, `)}. Or per field: { <field>: preset or Intl options }.`,X(t,He));return}K(t)||$(e,`spec.${e} must be a preset or Intl options, received ${Y(t)}.`);let{prefix:r,suffix:i,...a}=t;for(let[t,n]of[[`prefix`,r],[`suffix`,i]])n!==void 0&&typeof n!=`string`&&$(`${e}.${t}`,`spec.${e}.${t} must be a string, received ${Y(n)}.`);let o=We(a);try{o?new Intl.DateTimeFormat(n,a):new Intl.NumberFormat(n,a)}catch(n){$(e,`spec.${e} = ${Y(t)} is not valid ${o?`Intl.DateTimeFormat`:`Intl.NumberFormat`} options.`,n instanceof Error?n.message:String(n))}},ot=[[`y`,`a field name or a non-empty array of field names`,e=>typeof e==`string`||q(e,1)],[`path`,`a non-empty array of field names`,e=>q(e,1)],[`totals`,`an array of x values (strings)`,e=>q(e)],[`aggregate`,`one of ${Ve.join(`, `)}`,e=>Ve.includes(e)],[`sort`,`"asc" or "desc"`,e=>e===`asc`||e===`desc`],[`limit`,`a positive integer`,e=>Number.isInteger(e)&&e>0],[`select`,`true or "multi"`,e=>e===!0||e===`multi`],[`colorBy`,`"sign", { target: number } or a numeric field name`,e=>typeof e==`string`&&!!e||K(e)&&Object.keys(e).join()===`target`&&Number.isFinite(e.target)],[`titles`,`an object of strings keyed by field`,e=>K(e)&&Object.values(e).every(e=>typeof e==`string`)]];function st(t){K(t)||Z(`spec-not-object`,`spec`,`spec must be a plain object, received ${J(t)}.`,`Received: ${Y(t)}`);let n=t;for(let e of Object.keys(n))Fe.includes(e)||Z(`unknown-option`,e,`spec.${e} is not a known option.`,rt(Qe,e)??X(e,Fe),`Known options: ${Fe.join(`, `)}.`);let r=n.type;r===void 0&&Z(`missing-field`,`type`,`spec.type is required but missing.`,`Required fields: type, data, x, y.`,Ze);let i=[...Ce,...Te()],a=typeof r==`string`?r:void 0;if(a===void 0||!i.includes(a)){let e=a===void 0?void 0:rt(we,a);e&&Z(`unknown-type`,`type`,`spec.type = "${r}" needs the "${e}" module, which is not loaded.`,`Add: import "mayacharts/${e}"`),Z(`unknown-type`,`type`,`spec.type = ${Y(r)} is not a chart type.`,`Valid types: ${i.join(`, `)}.`,a===void 0?``:rt($e,a)??X(a,[...i,...Object.keys(we)]))}let o=r,s=Le.includes(o),c=s?`path`:`x`,l=t.path;o===`sankey`&&Array.isArray(l)&&l.length<2&&Z(`invalid-option`,`path`,`spec.path needs at least two levels for a sankey.`,`Example: path: ["region", "family"]`),o===`chord`&&Array.isArray(l)&&l.length!==2&&Z(`invalid-option`,`path`,`spec.path needs exactly two levels for a chord: from and to.`,`Example: path: ["region", "family"]`);let u=e=>Z(`missing-field`,e,`spec.${e} is required but missing.`,`Required fields: type, data, ${c}, y.`,s?`Example: { type: "${o}", data: [{ region: "N", state: "NY", sales: 10 }], path: ["region", "state"], y: "sales" }`:Ze);n.data===void 0&&u(`data`),Array.isArray(n.data)||Z(`data-not-array`,`data`,`spec.data must be an array of rows, received ${J(n.data)}.`);let d=n.data;d.forEach((e,t)=>{K(e)||Z(`row-not-object`,`data[${t}]`,`spec.data[${t}] must be an object, received ${J(e)}.`,`Received: ${Y(e)}`)}),n[c]===void 0&&o!==`kpi`&&o!==`beeswarm`&&!(c===`x`&&Ie.includes(o)&&n.path!==void 0)&&u(c),n.y===void 0&&u(`y`),(o===`dumbbell`||o===`ridgeline`||o===`marimekko`)&&n.series===void 0&&u(`series`),o===`parallel`&&!(Array.isArray(n.y)&&n.y.length>=2)&&Z(`invalid-option`,`y`,`spec.y on "parallel" needs an array of at least 2 measures, one axis each.`,`Example: y: ["sales", "units", "price"]`);for(let e in W)n[e]!==void 0&&typeof n[e]!==W[e]&&Q(e,n[e],`a ${W[e]}`);for(let[e,t,r]of ot)n[e]!==void 0&&!r(n[e])&&Q(e,n[e],t);let{y:f,path:p,select:m,colors:h,colorBy:g,theme:_,text:v}=n;if(v!==void 0){K(v)||Q(`text`,v,`an object of strings`);for(let[t,n]of Object.entries(v))Object.hasOwn(e,t)||Z(`invalid-option`,`text.${t}`,`spec.text.${t} is not a text key.`,X(t,Object.keys(e)),`Text keys: ${Object.keys(e).join(`, `)}.`),typeof n!=`string`&&Q(`text.${t}`,n,`a string`)}for(let e of[`yDomain`,`xDomain`]){let t=n[e];t!==void 0&&!(Array.isArray(t)&&t.length===2&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&(e===`yDomain`?t[0]!==t[1]:t[0]<t[1]))&&Z(`invalid-domain`,e,`spec.${e} = ${Y(t)} is not a valid domain.`,e===`yDomain`?`Expected [min, max] (or [max, min] to reverse) with two different finite numbers.`:`Expected [min, max] with finite numbers and min < max, e.g. [0, 100].`)}let y=`en-US`;if(typeof n.locale==`string`){let e=!1;try{e=Intl.NumberFormat.supportedLocalesOf(n.locale).length>0}catch{}e||$(`locale`,`spec.locale = ${Y(n.locale)} is not a locale this runtime supports.`,`Use a BCP 47 tag such as "de-DE". Node built with small ICU supports English only.`),y=n.locale}if(typeof n.currency==`string`)try{new Intl.NumberFormat(y,{style:`currency`,currency:n.currency})}catch{$(`currency`,`spec.currency = ${Y(n.currency)} is not an ISO 4217 currency code.`,`Use a three-letter code such as "USD" or "EUR".`)}if(typeof n.format==`string`)at(`format`,n.format,y);else if(n.format!==void 0){K(n.format)||Q(`format`,n.format,`a preset or an object keyed by field`);for(let[e,t]of Object.entries(n.format))at(`format.${e}`,t,y)}if(h!==void 0){let e=Array.isArray(h)?h.map((e,t)=>[`[${t}]`,e]):K(h)?Object.entries(h).map(([e,t])=>[`.${e}`,t]):null;(!e||!e.every(([,e])=>typeof e==`string`))&&Q(`colors`,h,`an array of colours, or an object of colours by series value`),e.length>8&&Z(`invalid-option`,`colors`,`spec.colors has ${e.length} colours; the palette has 8 slots.`,`Pass at most 8. Series 9 and later reuse slots in order.`);for(let[t,n]of e)it(`colors${t}`,n,!1)}if(_!==void 0){K(_)&&Object.values(_).every(e=>typeof e==`string`)||Q(`theme`,_,`an object of string values`);for(let e of Object.keys(_))Ge.includes(e)||Z(`invalid-theme`,`theme.${e}`,`spec.theme.${e} is not a theme token.`,`Valid tokens: ${Ge.join(`, `)}.`,X(e,Ge));for(let[e,t]of Object.entries(_))it(`theme.${e}`,t,e===`font`)}n.stack===!0&&o===`line`&&Z(`stack-unsupported`,`stack`,`spec.stack is not supported with spec.type = "line".`,`Use type "area" (or "bar") to stack series.`);for(let e in Be)n[e]!==void 0&&n[e]!==!1&&!Be[e].includes(o)&&Z(`option-unsupported`,e,`spec.${e} is not supported with spec.type = "${o}".`,`spec.${e} works with: ${Be[e].join(`, `)}.`);let b=Ie.includes(o),x=[[g!==void 0&&n.series!==void 0&&o!==`dumbbell`,`colorBy`,`spec.colorBy cannot be combined with spec.series.`,`Series already set the colours; remove one of them.`],[n.yDomain!==void 0&&Array.isArray(f),`yDomain`,`spec.yDomain cannot be combined with a y array.`,`Each measure needs its own domain; use a single y or remove yDomain.`],[n.drill===!0&&m!==void 0,`select`,`spec.select cannot be combined with spec.drill.`,`A click either drills or selects; choose one.`],[b&&p!==void 0&&n.x!==void 0,`x`,`spec.x cannot be combined with spec.path.`,`With path, the current drill level is the category; remove x.`],[n.y2!==void 0&&n.horizontal===!0,`y2`,`spec.y2 cannot be combined with spec.horizontal.`,`The y2 line needs a right value axis; draw vertical bars.`],[o===`kpi`&&g!==void 0&&!K(g),`colorBy`,`spec.colorBy on "kpi" must be { target: number }.`,`A kpi compares its headline with one target, drawn as a bullet bar.`],[b&&n.drill===!0&&p===void 0,`drill`,`spec.drill on "${o}" needs spec.path.`,`Replace x with path: ["region", "state"] (outer to inner).`]];for(let[e,t,n,r]of x)e&&Z(`option-unsupported`,t,n,r);if(d.length){let e=[...new Set(d.flatMap(e=>Object.keys(e)))],t=(t,n,r,i)=>Z(`unknown-field`,t,n,`Fields found: ${e.slice(0,20).join(`, `)}.`,X(r,e),i),r=typeof f==`string`?[f]:f,i=(e,t)=>t.map((t,n)=>[`${e}[${n}]`,t]),a=[[`x`,n.x],...typeof f==`string`?[[`y`,f]]:i(`y`,r),[`series`,n.series],[`y2`,n.y2],[`size`,n.size],[`name`,n.name],...i(`path`,p??[]),[`colorBy`,g===`sign`?void 0:g]];for(let[n,r]of a){if(typeof r!=`string`||e.includes(r))continue;let i=n.replace(/\[.*/,``);t(n,`spec.${n} = ${Y(r)} is not a field in spec.data.`,r,`spec.${i} names the field used for ${Ke[i]}.`)}for(let r of[`format`,`titles`])if(K(n[r]))for(let i of Object.keys(n[r]))e.includes(i)||t(`${r}.${i}`,`spec.${r} key "${i}" is not a field in spec.data.`,i,`spec.${r} keys name fields, for ${Ke[r]}.`);g===`sign`&&e.includes(`sign`)&&Z(`invalid-option`,`colorBy`,`spec.colorBy = "sign" colours by the sign of y, but spec.data also has a field named "sign".`,`Rename that field (e.g. data.map(({ sign, ...r }) => ({ ...r, signValue: sign }))) to colour by it.`);let c=(e,t)=>d.forEach((n,r)=>t(n[e],`data[${r}].${e}`)),l=(e,t,n)=>c(e,(r,i)=>{r==null||typeof r==`number`&&Number.isFinite(r)||Z(t,i,`spec.${i} is ${Y(r)} (a ${J(r)}), but spec.${n} requires numbers.`,typeof r==`string`&&r.trim()&&Number.isFinite(Number(r))?`Convert first: data.map(r => ({ ...r, ${e}: Number(r.${e}) }))`:`Use null for a gap in the data.`)});for(let e of r)l(e,`non-numeric-y`,`y`);if(typeof n.size==`string`&&l(n.size,`non-numeric-field`,`size`),typeof n.y2==`string`&&l(n.y2,`non-numeric-field`,`y2`),o===`dumbbell`&&typeof n.series==`string`){let e=new Set(d.map(e=>String(e[n.series]))).size;e!==2&&Z(`invalid-option`,`series`,`spec.series on "dumbbell" needs exactly 2 values, found ${e}.`,`The first value seen is the start of each bar, the second the end, e.g. last year and this year.`)}if(o===`scatter`&&typeof n.x==`string`&&l(n.x,`non-numeric-field`,`x`),typeof g==`string`&&g!==`sign`&&l(g,`non-numeric-field`,`colorBy`),s)for(let e of r)c(e,(t,n)=>{typeof t==`number`&&t<=0&&Z(`non-positive-value`,n,`spec.${n} is ${t}, but ${o} sizes must be positive.`,`Filter first: data.filter(r => r.${e} > 0), or chart the signed values with "bar".`)})}Se.get(o)?.check?.(t,Z)}function ct(e){if(e===void 0)return;K(e)||Z(`invalid-option`,`options`,`options must be a plain object, received ${J(e)}.`);let t=e,n=(e,t,n)=>Z(`unknown-option`,`${e}.${t}`,`${e}.${t} is not a known render option.`,X(t,n),`Known options: ${n.join(`, `)}.`),r=U(`width height view selected nonce`);for(let e of Object.keys(t))r.includes(e)||n(`options`,e,r);let i=(e,t,n)=>Z(`invalid-option`,`options.${e}`,`options.${e} must be ${n}, received ${Y(t)}.`);for(let e of[`width`,`height`]){let n=t[e];n!==void 0&&!(typeof n==`number`&&Number.isFinite(n)&&n>0)&&Z(`invalid-size`,`options.${e}`,`options.${e} = ${Y(n)} is not a valid size.`,`Size must be a finite number greater than 0.`)}let{view:a,selected:o,nonce:s}=t;if(a!==void 0){K(a)||i(`view`,a,`an object`);let e=U(`measure drill window hidden sortBy`);for(let t of Object.keys(a))e.includes(t)||n(`options.view`,t,e);let{measure:t,drill:r,window:o,hidden:s,sortBy:c}=a;c!==void 0&&(!Array.isArray(c)||c.length!==2||typeof c[0]!=`string`||c[1]!==`asc`&&c[1]!==`desc`)&&i(`view.sortBy`,c,`[field, "asc" | "desc"]`),t!==void 0&&!(Number.isInteger(t)&&t>=0)&&i(`view.measure`,t,`an index (integer >= 0)`),r!==void 0&&!q(r)&&i(`view.drill`,r,`an array of strings`),s!==void 0&&!q(s)&&i(`view.hidden`,s,`an array of strings`),o!==void 0&&(!Array.isArray(o)||o.length!==2&&o.length!==4||!o.every(Number.isFinite))&&i(`view.window`,o,`[i0, i1] or [x0, x1, y0, y1] of finite numbers`)}o!==void 0&&!(Array.isArray(o)&&o.every(e=>K(e)&&Object.keys(e).every(e=>[`x`,`series`,`name`].includes(e))))&&i(`selected`,o,`an array of { x?, series?, name? }`),s!==void 0&&!(typeof s==`string`&&/^[\w+/=-]+$/.test(s))&&i(`nonce`,s,`a base64 nonce string`)}function lt(e,t={}){let n=typeof e.y==`string`?[e.y]:[...e.y],r=Math.min(t.measure??0,n.length-1),i=[...e.path??[]],a=e.drill?(t.drill??[]).slice(0,Math.max(0,i.length-1)):[],o=i.slice(a.length),s=e.format,c=e=>Object.entries(e??{}).filter(e=>e[1]!==void 0);return{type:e.type,data:a.length?e.data.filter(e=>a.every((t,n)=>String(e[i[n]])===t)):e.data,x:e.x??(Ie.includes(e.type)?o[0]??``:``),y:n[r],measures:n,measure:r,series:e.series??null,y2:e.y2??null,path:o,drilled:a,window:t.window&&t.window.length===4?t.window:null,size:e.size??null,name:e.name??null,totals:[...e.totals??[]],stack:e.stack??!1,horizontal:e.horizontal??!1,aggregate:e.aggregate??`sum`,sort:e.sort??null,sortBy:t.sortBy??null,limit:e.limit??null,format:new Map(typeof s==`string`?n.map(e=>[e,s]):c(s)),titles:new Map(c(e.titles)),labels:e.labels??null,text:{...e.text},title:e.title??null,description:e.description??null,legend:e.legend??(e.series!==void 0||e.y2!==void 0||e.type===`waffle`),tooltip:e.tooltip??!0,drill:e.drill??!1,select:e.select??!1,zoom:e.zoom??!1,grid:e.grid??!0,xAxis:e.xAxis??!0,yAxis:e.yAxis??!0,locale:e.locale??`en-US`,currency:e.currency??`USD`,yDomain:e.yDomain??null,xDomain:e.xDomain??null,table:e.table??!0,animate:e.animate??!0,colors:Array.isArray(e.colors)?e.colors:e.colors?new Map(Object.entries(e.colors)):null,colorBy:e.colorBy??null,theme:e.theme??{}}}var ut={bar:P,waterfall:P,line:pe,area:me,scatter:_e,heatmap:te,kpi:ie,dumbbell:L,ridgeline:ue,beeswarm:ee,parallel:le,table:ye},dt=e=>e.replace(/[A-Z]|\d+/g,e=>`-`+e.toLowerCase());function ft(e,n,o){st(e),n!==void 0&&ct(n);let s=Object.hasOwn(ut,e.type)?ut[e.type]:Se.get(e.type),c=lt(e,n?.view),u=n?.width??640,d=n?.height??320,m=A(c,n?.view??{}),h=e=>e>5e3&&Z(`too-many-marks`,`data`,`${e} marks exceed the limit of 5000.`,`Use spec.limit to keep the top N categories, or aggregate the rows first.`);h(m.cells.length);let g=/* @__PURE__ */ new Map,v=(e,n,r)=>{if(n===`\0other`)return t(c,`other`);let i=e+`\0`+r,a=g.get(i);return a||g.set(i,a=_(c,e,r)),a(n)},y=c.colorBy,b=1/0,x=-1/0;if(typeof y==`string`&&y!==`sign`)for(let e of c.data){let t=e[y];typeof t==`number`&&(b=Math.min(b,t),x=Math.max(x,t))}let S=e=>y===`sign`?e<0?`bad`:`good`:y&&typeof y==`object`?e>=y.target?`good`:`bad`:null,C=e=>{let n=S(e);return n===null?null:t(c,y===`sign`?n===`good`?`positive`:`negative`:n===`good`?`above`:`below`)},w=[],T=``,E=(e,t,n,o)=>{let s=n.length*7.2+4,c=o===`start`?e:o===`end`?e-s:e-s/2,l=o===`above`?t-16:o===`below`?t+2:t-7;return c<0||l<0||c+s>u||l+14>d||w.some(e=>c<e[2]&&c+s>e[0]&&l<e[3]&&l+14>e[1])?!1:(w.push([c,l,c+s,l+14]),T+=a(`text`,{x:i(e),y:i(o===`above`?t-4:o===`below`?t+13:t),"text-anchor":o===`start`||o===`end`?o:`middle`,"dominant-baseline":o===`above`||o===`below`?null:`middle`,"data-in":o===`center`},r(n)),!0)},D=s.axes?O(c,s.axes(c,m),{width:u,height:d},v):null,j=D?.plot??{x:0,y:0,w:u,h:d},M={spec:c,shaped:m,width:u,height:d,plot:j,x:D?.x??null,y:D?.y??null,y2:D?.y2??null,fmt:v,label:E,tone:S,q:e=>x>b?Math.min(9,Math.max(0,Math.floor((e-b)/(x-b)*10))):9,agg:e=>t=>{let n=k(e);for(let e of t)typeof e==`number`&&n.add(e);return n.value()},fail:Z,t:(e,...n)=>t(c,e,...n)};s.check?.(e,Z);let N=null,P=``;if(c.data.length===0)P=a(`text`,{"data-maya":`empty`,x:u/2,y:d/2,"text-anchor":`middle`,"dominant-baseline":`middle`},r(t(c,`noData`)));else{let e=(e,t)=>a(`g`,{"data-maya":e},t),t=s.draw(M);h(t.marks.split(` data-maya="mark"`).length-1),N=t.legend??null,P=e(`grid`,t.grid??D?.grid??``)+e(`axis-y`,D?.ay??``)+e(`axis-x`,D?.ax??``)+e(`marks`,t.marks)+e(`labels`,(t.labels??``)+T)+e(`cross`,t.cross??``)+e(`hits`,t.hits)}let F=[];if(Array.isArray(c.colors))c.colors.forEach((e,t)=>F.push([`--maya-series-${t+1}`,e]));else if(c.colors)for(let[e,t]of c.colors){let n=m.series.indexOf(e);n>=0&&F.push([`--maya-series-${n%8+1}`,t])}for(let e in c.theme)F.push([`--maya-${dt(e)}`,c.theme[e]]);let I=F.map(([e,t])=>`${e}:${t};`).join(``),ee=a(`svg`,{class:o===null?`maya-svg`:`maya-root maya-svg`,viewBox:`0 0 ${u} ${d}`,width:u,height:d,role:`img`,"aria-label":o===null?null:l(c),"aria-labelledby":o===null?`maya-t`:null,"aria-describedby":o===null?`maya-d`:null,tabindex:o===null?`0`:null,style:o===null?null:I||null,"data-plot":`${i(j.x)} ${i(j.y)} ${i(j.w)} ${i(j.h)}`,...D?.attrs,"data-dir":c.horizontal?`h`:null},(o?`<style>${o}</style>`:``)+a(`title`,{id:o===null?`maya-t`:null},r(l(c)))+a(`desc`,{id:o===null?`maya-d`:null},r(f(c,m,v,s.noun)))+P),L=``;return N!==null&&c.legend?L=N:(c.series!==null||c.y2!==null)&&c.legend?L=`<div class="maya-legend" data-maya="legend">`+(c.series===null&&c.y2!==null?`<span data-s="0"><i></i>${r(c.titles.get(c.y)??c.y)}</span>`:``)+(c.series===null?[]:m.series).map((e,t)=>a(`button`,{type:`button`,"data-si":t,"data-s":t%8,"data-key":e,"aria-pressed":String(m.visible.includes(t))},`<i></i>${r(e)}`)).join(``)+(c.y2===null?``:`<span data-s="${m.series.length%8}" data-line><i></i>${r(c.titles.get(c.y2)??c.y2)}</span>`)+`</div>`:e.legend!==!1&&y!==null&&c.series===null&&c.type!==`kpi`&&(L=y===`sign`||typeof y==`object`?`<div class="maya-legend" data-maya="tone">`+[`good`,`bad`].map(e=>`<span data-tone="${e}"><i></i>${r(t(c,y===`sign`?e===`good`?`positive`:`negative`:e===`good`?`above`:`below`))}</span>`).join(``)+`</div>`:x>b?`<div class="maya-legend" data-maya="ramp"><span>${r(v(y,b))}</span><i></i><span>${r(v(y,x))}</span></div>`:``),{svg:ee,legend:L,controls:c.measures.length>1&&!Re.includes(c.type)?`<div class="maya-ctl" role="radiogroup" aria-label="${r(t(c,`measures`))}" data-n="${c.measures.length}" data-i="${c.measure}">`+c.measures.map((e,t)=>`<button type="button" role="radio" aria-checked="${t===c.measure}" data-i="${t}" tabindex="${t===c.measure?0:-1}">${r(c.titles.get(e)??e)}</button>`).join(``)+`</div>`:``,crumbs:c.drilled.length>0?`<nav class="maya-crumbs" aria-label="${r(t(c,`crumbs`))}"><button type="button" data-depth="0">${r(t(c,`back`))}</button>`+c.drilled.map((e,t)=>`<span aria-hidden="true">›</span><button type="button" data-depth="${t+1}"${t===c.drilled.length-1?` aria-current="page"`:``}>${r(String(e))}</button>`).join(``)+`</nav>`:c.drill?`<div class="maya-crumbs" aria-hidden="true"></div>`:``,table:c.table?p(c,m,v,C):``,title:c.title===null?``:`<div class="maya-title">${r(c.title)}</div>`,style:I,vars:F,warnings:[]}}function pt(e,t){return ft(e,t,null)}function mt(e,t){return ft(e,t,Ne).svg}function ht(e,t,n){let i=e.style?` style="${r(e.style)}"`:``,a=n?` nonce="${r(n)}"`:``;return`${t?`<style${a}>${t}</style>`:``}<div class="maya"${i}>${e.title}${e.controls}${e.legend}${e.crumbs}<div class="maya-box">${e.svg}</div>${e.table}<div class="maya-sr" data-maya="live" aria-live="polite"></div><div class="maya-probe" data-maya="probe"></div><div class="maya-tip" popover="manual" role="tooltip"></div></div>`}function gt(e){let t=e=>typeof e==`object`?Object.keys(e):[],n=/* @__PURE__ */ new Set([e.x,...typeof e.y==`string`?[e.y]:e.y,e.series,e.y2,e.size,e.name,...e.path??[],typeof e.colorBy==`string`?e.colorBy:void 0,...t(e.format),...t(e.titles)]);return{...e,data:e.data.map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>n.has(e))))}}function _t(e,t){let n=pt(e,t),r=JSON.stringify(gt(e)).replace(/</g,`\\u003c`);return`<maya-chart><template shadowrootmode="open">${ht(n,Ne,t?.nonce)}</template><script type="application/json">${r}<\/script></maya-chart>`}export{Pe as MayaSpecError,mt as render,pt as renderParts,_t as renderShell,st as validateSpec,be as version};
4
4
  //# sourceMappingURL=index.js.map