@graphysdk/viz-engine 0.0.1-alpha.1 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +0,0 @@
1
- # `@graphysdk/viz-engine`
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("lodash-es"),T=require("date-fns"),te=require("d3-time"),cr=require("date-fns/differenceInDays"),B=require("d3-scale"),F=require("arquero"),$t=require("lodash-es/merge"),lr=require("humanize-duration"),ur=require("d3-delaunay");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-alpha.1");const Wt=e=>e.length>0;function m(e){return e!=null}const Ht=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],Kt="default";class K{constructor(t){this.label=t,this.items=new Map}register(t,n){return this.items.set(t,n),this}get(t){if(!this.items.has(t)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new Error(`Unknown ${this.label}: '${t}' (available: ${n})`)}return this.items.get(t)}getAll(){return[...this.items.values()]}has(t){return this.items.has(t)}}class dr extends K{constructor(){super("palette")}}function le(e){return{pipe:t=>{const n=t(e);return le({...e,...n})},result:()=>e}}class pr{constructor(t){this.registry=t}setup(t){return this.registry.get(t.coordSpec.coordType).setup(t)}transform(t){return this.registry.get(t.coordSpec.coordType).transform(t)}}class mr{constructor(){this.coordType="cartesian"}setup(t){if(t.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}}}transform(t){return t.layers}}const jt="\0graphy\0_",A=e=>`${jt}${e}`,He=e=>e.startsWith(jt),gt={x:A("constantX")},Ke={count:A("count")},fr={[Ke.count]:{type:"integer"}},V={group:A("group")},u={x:A("x"),y:A("y"),xMin:A("xMin"),xMax:A("xMax"),yMin:A("yMin"),yMax:A("yMax")},j={color:A("color"),size:A("size"),alpha:A("alpha"),strokeWidth:A("strokeWidth")};({...V,...u,...j});class yr{constructor(){this.coordType="flip"}setup(t){if(t.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}}}transform(t){return t.layers.map(n=>gr(n))}}const hr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]],bt=A("flipSwap");function gr(e){let t=e.data;for(const[n,r]of hr){const a=t.hasVariable(n),s=t.hasVariable(r);a&&s?t=t.renameVariable(n,bt).renameVariable(r,n).renameVariable(bt,r):a?t=t.renameVariable(n,r):s&&(t=t.renameVariable(r,n))}return{...e,data:t}}class br{constructor(){this.coordType="polar"}setup(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec;return{type:"polar",axisMapping:n.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}}}}transform(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec,r=xr(n),a=Mr(n);return t.layers.map(s=>{const i=n.theta==="y"?Ar(s):s;return Sr(i,r,a)})}}function xr(e){const t=e.startAngle*(Math.PI/180);return n=>n*2*Math.PI+t}function Mr(e){const{innerRadius:t}=e;return n=>t+n*(1-t)}function Sr(e,t,n){let r=e.data;return r=q(r,u.x,t),r=q(r,u.xMin,t),r=q(r,u.xMax,t),r=q(r,u.y,n),r=q(r,u.yMin,n),r=q(r,u.yMax,n),{...e,data:r}}function q(e,t,n){if(!e.hasVariable(t))return e;const a=e.getValues(t,{type:"numeric"}).map(s=>s===null?null:n(s));return e.addVariable(t,"numeric",a)}const Tr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]];function Ar(e){let t=e.data;for(const[n,r]of Tr){const a=t.hasVariable(n),s=t.hasVariable(r);if(!a&&!s)continue;const i=a?t.getValues(n):null,o=s?t.getValues(r):null;i&&(t=t.addVariable(r,"numeric",i)),o&&(t=t.addVariable(n,"numeric",o))}return{...e,data:t}}class wr extends K{constructor(){super("coord"),this.register("cartesian",new mr),this.register("flip",new yr),this.register("polar",new br)}}class vr{constructor(t){this.registry=t}compile(t,n){return this.registry.get(t).compile(n)}}function Vr(e){return{type:"mapping",mapping:e}}function M(e){return m(e)?typeof e=="string"?e:"variable"in e?e.variable:null:null}function Ir(e){if(!(!m(e)||typeof e=="string")&&"value"in e)return e.value}const qt=(e,t)=>{if(m(t.group)){const a=M(t.group);if(a!==null)return[a]}const n=new Set([M(t.x),M(t.y)].filter(m)),r=new Set;for(const a in t){if(a==="x"||a==="y")continue;const s=M(t[a]);m(s)&&(n.has(s)||e.getType(s)==="categorical"&&r.add(s))}return[...r]};class Le{constructor(){this.requiredAesthetics=[]}}const Xt=(e,t)=>{const n=M(t.x);return!n||!["numeric","temporal"].includes(e.getType(n))?e:e.orderBy(n,"asc")};class Er extends Le{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"]}compile({data:t,mapping:n}){if(t=Xt(t,n),t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const r=M(n.y);m(r)&&t.hasVariable(r)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(r,{type:"numeric"})))}return{data:t,mapping:{}}}}const Qt=.7,_r=.1;class Lr extends Le{constructor(){super(...arguments),this.type="bar"}compile({data:t,mapping:n}){if(t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const a=M(n.y);m(a)&&t.hasVariable(a)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(a,{type:"numeric"})))}const r=Qt/2;return t=t.addConstantVariable(u.xMin,"numeric",-r).addConstantVariable(u.xMax,"numeric",r),{data:t,mapping:{}}}}class kr extends Le{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"]}compile(t){return{data:Xt(t.data,t.mapping),mapping:{}}}}class Dr extends Le{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"]}compile({data:t}){return{data:t,mapping:{}}}}class Cr extends K{constructor(){super("geom"),this.register("bar",new Lr),this.register("point",new Dr),this.register("line",new kr),this.register("area",new Er)}}const $=e=>(Array.isArray(e)?e:[e]).map(n=>n instanceof Date?n.toISOString():String(n??"<null>")).join("\0");class Rr{compute({data:t,mapping:n}){const r=qt(t,n);if(r.length===0)return{data:t.addConstantVariable(V.group,"categorical",null)};const a=t.size(),s=r.map(o=>t.getValues(o)),i=new Array(a);for(let o=0;o<a;o++)i[o]=$(s.map(c=>c[o]));return{data:t.addVariable(V.group,"categorical",i)}}}const Jt=new Set(["x","y","ySecondary"]),Zt=new Set(["color","size","alpha","strokeWidth"]),ke=e=>Jt.has(e),Nr=e=>Zt.has(e),Fr=e=>ke(e)||Nr(e);function ue(e){return e==="secondary"?"ySecondary":"y"}function U(e){return e==="ySecondary"?"y":e}const Z=e=>e instanceof Date&&T.isValid(e),en=e=>typeof e=="string",tn=e=>typeof e=="number"&&!Number.isNaN(e),Or=e=>e.type==="text",de=e=>e.type==="date"||e.type==="datetime"||e.type==="year"||e.type==="month_year"||e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range"||e.type==="weekly_date_range_with_year"||e.type==="quarter"||e.type==="time",nn=e=>e.type==="decimal"||e.type==="integer"||e.type==="percentage"||e.type==="duration"||e.type==="currency",rn=e=>e.type==="currency",an=e=>e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range",Pr=e=>{if(de(e))return"temporal";if(nn(e))return"numeric";if(Or(e))return"categorical";const t=e;throw new Error(`No data type found for value format: ${t.type}`)},xt={year:0,quarter:1,month:2,week:3,day:4,hour:5},Br=[{unit:"year",step:1e3},{unit:"year",step:100},{unit:"year",step:50},{unit:"year",step:20},{unit:"year",step:10},{unit:"year",step:5},{unit:"year",step:2},{unit:"year",step:1},{unit:"month",step:6},{unit:"month",step:3},{unit:"month",step:2},{unit:"month",step:1},{unit:"week",step:2},{unit:"week",step:1},{unit:"day",step:2},{unit:"day",step:1},{unit:"hour",step:12},{unit:"hour",step:6},{unit:"hour",step:3}],X=40,Ur=(e,t,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return $r(n.unit).range(e,new Date(t.valueOf()+1),r)},Yr=({unit:e,step:t,start:n,stop:r})=>{const a=cr.differenceInDays(r,n);switch(e){case"hour":return 24*a/t>X;case"day":return a/t>X;case"week":return a/(7*t)>X;case"month":return a/(30*t)>X;case"quarter":return a/(90*t)>X;case"year":return a/(365*t)>X}},Gr=(e,t)=>{const n=!an(t);switch(e.unit){case"year":return n?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return n?{type:"month_year"}:{type:"month"};case"week":return n?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return n?{type:"date"}:{type:"day_month"};case"hour":return n?{type:"datetime"}:{type:"time"}}},zr=(e,t)=>{const n=Wr(t);return n===null?!1:xt[e]>xt[n]},$r=e=>{switch(e){case"hour":return te.utcHour;case"day":return te.utcDay;case"week":return te.utcMonday;case"month":case"quarter":return te.utcMonth;case"year":return te.utcYear}},Wr=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}};function Ie(e,t){const n=U(t);for(const r of Hr(t,e)){const a=M(r.mapping[n]);if(m(a))return a}return null}const Je=(e,t)=>e===null?null:t.columns[e]?.label??e,sn=(e,t,n)=>{if(e!==null){const r=fr[e];if(r)return r;const a=t.columns[e]?.valueFormat;if(a&&jr(a,n))return a}return Kr(n)};function Hr(e,t){return e==="ySecondary"?t.filter(n=>n.yScaleType==="secondary"):e==="y"?t.filter(n=>n.yScaleType==="primary"):t}const Kr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},jr=(e,t)=>{switch(t){case"continuous":return nn(e);case"datetime":return de(e);case"discrete":case"palette":case"identity":return!0}},on={left:"right",right:"left",top:"bottom",bottom:"top"},qr={x:!0,y:!0,ySecondary:!1},Xr={bar:{cartesian:{hideGridX:!0},flip:{hideGridX:!0},polar:{hideGridX:!0,hideGridY:!0}}},Qr=20;function Jr(e,t){const{scales:n,config:r,layers:a,coordSystem:s,datasetMetadata:i}=e;if(s.type==="polar")return[];const o=ea(a,s.type,r),c=new Set(t.map(d=>d.position)),l=na(s.axisMapping.y.position,c),p=[];for(const d of Jt){const y=n[d];if(!m(y)||y.kind!=="position")continue;const f=Zr({scaleAestheticKey:d,scale:y,config:r,layers:a,axisMapping:s.axisMapping,resolvedYPosition:l,gridOverrides:o,datasetMetadata:i});p.push(f)}return p}function Zr(e){const{scaleAestheticKey:t,scale:n,config:r,layers:a,axisMapping:s,resolvedYPosition:i,gridOverrides:o,datasetMetadata:c}=e,l=U(t),{axisConfig:p,position:d}=ta(t,r,s,i),y=Ie(a,t),f=sn(y,c,n.spec.scaleType),h=Je(y,c);return{scaleAestheticKey:t,aesthetic:l,position:d,label:p.label??h,isVisible:p.isVisible,tickCandidates:aa(n,f),valueFormat:f,tickMode:p.ticks.mode,ticksVisible:p.ticks.isVisible,gridVisible:ra(p,o,t),scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function ea(e,t,n){const r=e.flatMap(o=>{const c=Xr[o.geom]?.[t];return c?[c]:[]}),a=r.some(o=>o.hideGridX),s=r.some(o=>o.hideGridY),i=r.some(o=>o.hideBorder);return{x:{gridVisible:Mt(a,n.axes.x.grid.isVisible)},y:{gridVisible:Mt(s,n.axes.y.grid.isVisible)},borderVisible:i?!1:void 0}}function Mt(e,t){if(e&&t===null)return!1}function ta(e,t,n,r){switch(e){case"x":return{axisConfig:t.axes[e],position:n[e].position};case"y":return{axisConfig:t.axes[e],position:r};case"ySecondary":{const a=on[r],s=ee.merge({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:s,position:s.position}}}}function na(e,t){return t.has(e)?on[e]:e}function ra(e,t,n){const{gridVisible:r}=n==="x"?t.x:t.y;return r??e.grid.isVisible??qr[n]}const aa=(e,t)=>{if(e.spec.scaleType==="continuous"){const r=new Set,a=[];for(let s=1;s<=Qr;s++){const i=e.generateTicks({count:s}),o=$(i);r.has(o)||(r.add(o),a.push({ticks:i.map(c=>Ee(e,c))}))}return a}return e.spec.scaleType==="datetime"?sa(e,t):[{ticks:e.generateTicks().map(r=>Ee(e,r))}]},sa=(e,t)=>{const[n,r]=e.domain;if(!Z(n)||!Z(r))return[{ticks:e.generateTicks().map(c=>Ee(e,c))}];const a=new Set,s=[],i=(o,c)=>{if(o.length===0)return;const l=$(o);a.has(l)||(a.add(l),s.push({ticks:o.map(p=>Ee(e,p)),valueFormat:c}))};for(const o of Br)Yr({...o,start:n,stop:r})||zr(o.unit,t)||i(e.generateTicks({interval:o}),Gr(o,t));return i(e.generateTicks({atInputs:!0})),s.sort((o,c)=>o.ticks.length-c.ticks.length),s},Ee=(e,t)=>({value:t,position:e.map(t)}),cn=e=>e[V.group];function ia(e){return e[u.x]}function je(e){return e[u.y]}function oa(e){return e[u.xMin]}function ca(e){return e[u.xMax]}function ln(e){return e[u.yMin]}function qe(e){return e[u.yMax]}const la={line:{stack:!0,dodge:!0,identity:!0,fill:!0},area:{stack:!0,dodge:!0,identity:!0,fill:!0},bar:{stack:!0,fill:!0}};function ua(e){const{scales:t,config:n,layers:r,coordSystem:a,datasetMetadata:s}=e;if(da(n))return[];const i=pa({scales:t,layers:r}),o=ya(i),c=xa(n.legend.position,r,a,i),l=Sa(n.legend.display,c,r,a),p=l==="direct"?va(r):null,d=Ie(r,"x"),y=Ie(r,"y");return o.map(f=>fa(f,d)?ga({group:f,position:c,display:l,yVariableName:y,datasetMetadata:s}):ha({group:f,position:c,display:l,endpointsBySeries:p,datasetMetadata:s})).filter(f=>!!(f&&f.items.length>0))}function da(e){return e.legend.position==="none"||e.headline.show!=="none"&&e.legend.position==="auto"}function pa(e){const{scales:t,layers:n}=e,r=[];for(const a of Zt){const s=t[a];if(s===void 0||s.kind==="identity"||!ma(a,n))continue;const i=Ie(n,a),o=wa(a,s);r.push({scaleAestheticKey:a,scale:s,variableName:i,guideType:o})}return r}function ma(e,t){const n=U(e);return t.some(r=>m(r.mapping[n]))}function fa(e,t){if(e.length>1)return!1;const[n]=e;return n.scaleAestheticKey!=="color"?!1:n.variableName===null||He(n.variableName)?!0:t!==null&&n.variableName===t}function ya(e){const t=new Map;for(const n of e){const r=Aa(n),a=t.get(r);a?a.push(n):t.set(r,[n])}return[...t.values()]}function ha({group:e,position:t,display:n,endpointsBySeries:r,datasetMetadata:a}){const s=e[0],i=e.find(l=>m(l.variableName))?.variableName??null,o=Je(i,a),c=sn(s.variableName,a,s.scale.spec.scaleType);return{aesthetics:e.map(l=>l.scaleAestheticKey),title:o,position:t,display:n,items:s.scale.domain.map(l=>{const p={};for(const d of e)p[d.scaleAestheticKey]=d.scale.map(l);return{value:l,visual:p,normalizedY:r?.get(l)??null}}),valueFormat:c}}function ga({yVariableName:e,group:t,position:n,display:r,datasetMetadata:a}){const s=ba(t,e,a);if(s===null)return null;const i={};for(const o of t){const c=o.scale.domain.map(l=>String(o.scale.map(l)));i[o.scaleAestheticKey]=c.length===1?c[0]:c}return{aesthetics:t.map(o=>o.scaleAestheticKey),title:s,position:n,display:r,items:[{value:s,visual:i,normalizedY:null}],valueFormat:{type:"text"}}}function ba(e,t,n){const r=e.find(a=>a.scaleAestheticKey==="color");if(m(r?.variableName)&&He(r.variableName)){const[a]=r.scale.domain;if(m(a))return String(a)}return!t||He(t)?null:Je(t,n)}function xa(e,t,n,r){if(e!=="auto")return e;const a=t.some(c=>c.geom==="line"||c.geom==="area"),s=t.some(c=>c.geom==="bar"&&(c.position==="stack"||c.position==="fill")),i=n.type==="polar",o=Math.max(0,...r.map(c=>c.scale.domain.length));return i?"top":(a||s)&&o>=3?"right":"top"}function Ma(e){if(e.length!==1)return!1;const t=e[0];return t?la[t.geom]?.[t.position]===!0:!1}function Sa(e,t,n,r){const a=t==="right"&&!Ta(r);return e==="pill"||!a?"pill":e==="direct"||Ma(n)?"direct":"pill"}function Ta(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Aa(e){const t=e.scale.domain.map($);return JSON.stringify([e.variableName,e.guideType,...t])}function wa(e,t){const n=t.spec.scaleType;return n==="continuous"||n==="datetime"?`continuous:${e}`:"discrete"}function va(e){const t=e[0];if(!t)return new Map;const n=new Map;return t.data.groupBy(V.group).forEach(r=>{const a=r.findLast(l=>m(qe(l))||m(je(l)));if(!a)return;const s=cn(a);if(!m(s))return;const i=ln(a),o=qe(a)??je(a);if(!m(o))return;const c=m(i)?(i+o)/2:o;n.set(String(s),c)}),n}class Va{compile(t){const n=ua(t);return{axes:Jr(t,n),legends:n,panel:{border:{isVisible:t.config.panel.border.isVisible}}}}}class un extends Error{constructor(t){const n=t.map(r=>`- ${r.message}`).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ze=require("lodash-es"),ye=require("lodash-es/merge"),C=require("d3-scale"),he=require("date-fns"),E=require("arquero");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1");const be=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],xe="default",Be="\0graphy\0_",T=t=>`${Be}${t}`,se={x:T("constantX")},oe={count:T("count")},M={group:T("group")},l={x:T("x"),y:T("y"),xMin:T("xMin"),xMax:T("xMax"),yMin:T("yMin"),yMax:T("yMax")},R={color:T("color"),size:T("size"),alpha:T("alpha"),strokeWidth:T("strokeWidth")};({...M,...l,...R});const Ge={mode:"readonly",parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,subtitle:null,caption:null}},Ue={xLimits:null,yLimits:null},q={theta:"x",startAngle:0,innerRadius:0};function je(t){const e=t??{type:"coord",coordType:"cartesian"},r=ye({},Ue,e.params??{});switch(e.coordType){case"cartesian":case"flip":return{...e,params:r};case"polar":return{...e,params:{...r,theta:e.params?.theta??q.theta,startAngle:e.params?.startAngle??q.startAngle,innerRadius:e.params?.innerRadius??q.innerRadius}}}}const X={stat:"identity",position:"identity",params:{size:8}},H={stat:"identity",position:"identity",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"gap"}},J={stat:"identity",position:"stack",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"gap"}},Z={stat:"identity",position:"dodge",params:{}},j="primary";function $e(t){return{id:t.id??crypto.randomUUID(),type:t.type,geom:t.geom,mapping:t.mapping??{},stat:t.stat??X.stat,position:t.position??X.position,yScaleType:t.yScaleType??j,params:{...X.params,...t.params}}}function Ke(t){return{id:t.id??crypto.randomUUID(),type:t.type,geom:t.geom,mapping:t.mapping??{},stat:t.stat??H.stat,position:t.position??H.position,yScaleType:t.yScaleType??j,params:{...H.params,...t.params}}}function We(t){return{id:t.id??crypto.randomUUID(),type:t.type,geom:t.geom,mapping:t.mapping??{},stat:t.stat??J.stat,position:t.position??J.position,yScaleType:t.yScaleType??j,params:{...J.params,...t.params}}}function Ye(t){return{id:t.id??crypto.randomUUID(),type:t.type,geom:t.geom,mapping:t.mapping??{},stat:t.stat??Z.stat,position:t.position??Z.position,yScaleType:t.yScaleType??j,params:{...Z.params,...t.params}}}function qe(t){switch(t.geom){case"point":return $e(t);case"line":return Ke(t);case"area":return We(t);case"bar":return Ye(t)}}function Xe(t){return t.map(qe)}function y(t){return t!=null}function He(t,...e){return t.find(r=>e.includes(r.geom))}const Se=new Set(["x","y","ySecondary"]),Te=new Set(["color","size","alpha","strokeWidth"]),$=t=>Se.has(t),Je=t=>Te.has(t),Ze=t=>$(t)||Je(t);function ne(t){return t==="secondary"?"ySecondary":"y"}function _(t){return t==="ySecondary"?"y":t}function h(t){return t==null?null:typeof t=="string"?t:"variable"in t?t.variable:null}const Ae=(t,e)=>{if(y(e.group)){const n=h(e.group);if(n!==null)return[n]}const r=new Set;for(const n in e){if(n==="x"||n==="y")continue;const i=h(e[n]);i!=null&&t.getType(i)==="categorical"&&r.add(i)}return[...r]};function x(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"continuous",transform:e.transform,reverse:e.reverse,nice:e.nice,zero:e.zero,clamp:e.clamp,domainMin:e.domainMin??null,domainMax:e.domainMax??null,range:e.range}}function z(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"datetime",domainMin:e.domainMin??null,domainMax:e.domainMax??null,nice:e.nice,reverse:e.reverse,clamp:e.clamp}}function v(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"discrete",range:e.range,sort:e.sort,domain:e.domain??null,padding:e.padding}}function B(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"identity"}}function G(t,e){return{type:"scale",scaledAesthetic:t,scaleType:"inferred",...e!=null?{options:e}:{}}}const D={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},ce={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},k={domainMin:null,domainMax:null,nice:!1,reverse:!1},N={range:null,sort:"none",domain:null,padding:.1},Qe={palette:"default"},we={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range"},et={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Ve(t,e,r,n){switch(t.scaleType){case"inferred":{const i=rt(t,e,r,n);return Ve(i,e,r,n)}case"continuous":{const i=we[t.scaledAesthetic],a=i==="continuous-range"&&t.scaledAesthetic in ce?ce[t.scaledAesthetic]:null,s=t.scaledAesthetic==="size"&&i==="continuous-range"?"sqrt":D.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??s,reverse:t.reverse??D.reverse,nice:t.nice??D.nice,zero:t.zero??D.zero,clamp:t.clamp??i!=="position",domainMin:t.domainMin??D.domainMin,domainMax:t.domainMax??D.domainMax,range:t.range??a??null}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??k.domainMin,domainMax:t.domainMax??k.domainMax,nice:t.nice??k.nice,reverse:t.reverse??k.reverse,clamp:t.clamp??!1};case"discrete":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,range:t.range??N.range,sort:t.sort??N.sort,domain:t.domain??N.domain,padding:t.padding??N.padding};case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:t.palette??Qe.palette};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:{const i=t;throw new Error(`Unknown scale type: ${i.scaleType}`)}}}function tt(t,e,r,n){const i=it(e,r),a=new Map;for(const s of i)a.set(s.scaledAesthetic,s);return[...a.values()].map(s=>Ve(s,t,r,n))}function rt(t,e,r,n){const i=_(t.scaledAesthetic),a=t.scaledAesthetic==="ySecondary"?nt(r,n):n[i],s=He(r,"bar");if(t.scaledAesthetic==="x"&&s)return v(t.scaledAesthetic,t.options);if(s&&t.scaledAesthetic===(s.yScaleType==="secondary"?"ySecondary":"y")){const m=t.options,d=s.position==="fill";return x(t.scaledAesthetic,{...m,zero:!0,...d&&{nice:!1}})}const o=h(a);if(o==null||!e.hasVariable(o))return x(t.scaledAesthetic,t.options);const c=e.getType(o),u=we[t.scaledAesthetic];switch(et[c][u]){case"discrete":return v(t.scaledAesthetic,t.options);case"datetime":return z(t.scaledAesthetic,t.options);case"continuous":return x(t.scaledAesthetic,t.options);case"identity":default:return B(t.scaledAesthetic)}}function nt(t,e){const r=t.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??e.y:e.y}function it(t,e){return!e.some(i=>i.yScaleType==="secondary")||t.some(i=>i.scaledAesthetic==="ySecondary")?t:[...t,G("ySecondary")]}function at(t){const{data:e,mapping:r}=ot(t.data,t.mapping),n=je(t.coords),i=Xe(t.layers),a=tt(e,t.scales,i,r);return{data:e,mapping:r,layers:i,scales:n.coordType==="polar"?st(a):a,coords:n,config:ze.merge({},Ge,t.config)}}const st=t=>t.map(e=>e.scaleType==="discrete"?{...e,padding:0}:e),ot=(t,e)=>e.x!==""?{data:t,mapping:e}:{data:t.addConstantVariable(se.x,"categorical",""),mapping:{...e,x:se.x}};class I{constructor(e){this.label=e,this.items=new Map}register(e,r){return this.items.set(e,r),this}get(e){if(!this.items.has(e)){const r=[...this.items.keys()].map(n=>`'${n}'`).join(", ");throw new Error(`Unknown ${this.label}: '${e}' (available: ${r})`)}return this.items.get(e)}getAll(){return[...this.items.values()]}has(e){return this.items.has(e)}}class ct extends I{constructor(){super("palette")}}function K(t){return{pipe:e=>{const r=e(t);return K({...t,...r})},result:()=>t}}class lt{constructor(e){this.registry=e}setup(e){return this.registry.get(e.coordSpec.coordType).setup(e)}transform(e){return this.registry.get(e.coordSpec.coordType).transform(e)}}class ut{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${e.coordSpec.coordType}`);return{type:"cartesian",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}}}transform(e){return e.layers}}class pt{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${e.coordSpec.coordType}`);return{type:"cartesian",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}}}transform(e){return e.layers.map(r=>mt(r))}}const dt=[[l.x,l.y],[l.xMin,l.yMin],[l.xMax,l.y],[l.xMax,l.yMax]];function mt(t){let e=t.data;for(const[r,n]of dt){const i=e.hasVariable(r),a=e.hasVariable(n);!i||!a||(e=e.renameVariable(r,T("temp")).renameVariable(n,r).renameVariable(T("temp"),n))}return{...t,data:e}}class gt{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${e.coordSpec.coordType}`);const{params:r}=e.coordSpec;return{type:"polar",axisMapping:r.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}}}}transform(e){if(e.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${e.coordSpec.coordType}`);const{params:r}=e.coordSpec,n=ft(r),i=yt(r);return e.layers.map(a=>{const s=r.theta==="y"?xt(a):a;return ht(s,n,i)})}}function ft(t){const e=t.startAngle*(Math.PI/180);return r=>r*2*Math.PI+e}function yt(t){const{innerRadius:e}=t;return r=>e+r*(1-e)}function ht(t,e,r){let n=t.data;return n=O(n,l.x,e),n=O(n,l.xMin,e),n=O(n,l.xMax,e),n=O(n,l.y,r),n=O(n,l.yMin,r),n=O(n,l.yMax,r),{...t,data:n}}function O(t,e,r){if(!t.hasVariable(e))return t;const i=t.getValues(e,{type:"numeric"}).map(a=>a==null?null:r(a));return t.addVariable(e,"numeric",i)}const bt=[[l.x,l.y],[l.xMin,l.yMin],[l.xMax,l.yMax]];function xt(t){let e=t.data;for(const[r,n]of bt){const i=e.hasVariable(r),a=e.hasVariable(n);if(!i&&!a)continue;const s=i?e.getValues(r):null,o=a?e.getValues(n):null;s&&(e=e.addVariable(n,"numeric",s)),o&&(e=e.addVariable(r,"numeric",o))}return{...t,data:e}}class St extends I{constructor(){super("coord"),this.register("cartesian",new ut),this.register("flip",new pt),this.register("polar",new gt)}}class Tt{constructor(e){this.registry=e}compile(e,r){return this.registry.get(e).compile(r)}}class W{constructor(){this.requiredAesthetics=[]}}const Me=(t,e)=>{const r=h(e.x);return!r||!["numeric","temporal"].includes(t.getType(r))?t:t.orderBy(r,"asc")};class At extends W{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"]}compile(e){let r=Me(e.data,e.mapping);return r.hasVariable(l.yMin)||(r=r.addConstantVariable(l.yMin,"numeric",0)),{data:r,mapping:{}}}}const U=.5;class wt extends W{constructor(){super(...arguments),this.type="bar"}compile({data:e,mapping:r}){if(e.hasVariable(l.yMin)||(e=e.addConstantVariable(l.yMin,"numeric",0)),!e.hasVariable(l.yMax)){const n=h(r.y);n!=null&&e.hasVariable(n)&&(e=e.addVariable(l.yMax,"numeric",e.getValues(n,{type:"numeric"})))}return e=e.addConstantVariable(l.xMin,"numeric",-U).addConstantVariable(l.xMax,"numeric",U),{data:e,mapping:{}}}}class Vt extends W{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"]}compile(e){return{data:Me(e.data,e.mapping),mapping:{}}}}class Mt extends W{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"]}compile({data:e}){return{data:e,mapping:{}}}}class vt extends I{constructor(){super("geom"),this.register("bar",new wt),this.register("point",new Mt),this.register("line",new Vt),this.register("area",new At)}}const ve=t=>t.map(e=>e instanceof Date?e.toISOString():String(e??"<null>")).join("\0");class Et{compute({data:e,mapping:r}){const n=Ae(e,r);if(n.length===0)return{data:e.addConstantVariable(M.group,"categorical",null)};const i=e.size(),a=n.map(o=>e.getValues(o)),s=new Array(i);for(let o=0;o<i;o++)s[o]=ve(a.map(c=>c[o]));return{data:e.addVariable(M.group,"categorical",s)}}}function Ee(t,e){const r=_(e);for(const n of Lt(e,t)){const i=h(n.mapping[r]);if(i)return i}return null}function Lt(t,e){return t==="ySecondary"?e.filter(r=>r.yScaleType==="secondary"):t==="y"?e.filter(r=>r.yScaleType==="primary"):e}const Le={left:"right",right:"left",top:"bottom",bottom:"top"},Ct={x:!1,y:!0,ySecondary:!1},_t={bar:{polar:{hideGrid:!0,hideBorder:!1}}};function Rt(t,e){const{scales:r,config:n,layers:i,coordSystem:a}=t;if(a.type==="polar")return[];const s=Dt(i,a.type,n),o=[];for(const c of Se){const u=r[c];if(!y(u)||u.kind!=="position")continue;const p=It({scaleAestheticKey:c,scale:u,config:n,layers:i,axisMapping:a.axisMapping,legends:e,gridOverrides:s});o.push(p)}return o}function It(t){const{scaleAestheticKey:e,scale:r,config:n,layers:i,axisMapping:a,legends:s,gridOverrides:o}=t,c=_(e),{axisConfig:u,position:p}=Ot(e,n,a,s);return{scaleAestheticKey:e,aesthetic:c,position:p,label:u.label??Ee(i,e),isVisible:u.isVisible,ticks:Pt(r),tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Nt(u,o,e),scaleType:r.spec.scaleType}}function Dt(t,e,r){const n=t.flatMap(s=>{const o=_t[s.geom]?.[e];return o?[o]:[]}),i=n.some(s=>s.hideGrid),a=n.some(s=>s.hideBorder);return{x:{gridVisible:le(i,r.axes.x.grid.isVisible)},y:{gridVisible:le(i,r.axes.y.grid.isVisible)},borderVisible:a?!1:void 0}}function le(t,e){if(t&&e===null)return!1}function Ot(t,e,r,n){const i=new Set(n.map(a=>a.position));switch(t){case"x":case"y":return{axisConfig:e.axes[t],position:ue(r[t].position,i)};case"ySecondary":{const a=Le[r.y.position],s=e.axes.ySecondary??{isVisible:e.axes.y.isVisible,label:null,position:a,grid:e.axes.y.grid,ticks:e.axes.y.ticks};return{axisConfig:s,position:ue(s.position??a,i)}}}}function ue(t,e){return e.has(t)?Le[t]:t}function Nt(t,e,r){const{gridVisible:n}=r==="x"?e.x:e.y;return n??t.grid.isVisible??Ct[r]??!1}function Pt(t){return t.generateTicks().map(e=>({value:e,position:t.map(e)}))}const Ce=t=>t[M.group];function kt(t){return t[l.x]}function ee(t){return t[l.y]}function Ft(t){return t[l.xMin]}function zt(t){return t[l.xMax]}function _e(t){return t[l.yMin]}function te(t){return t[l.yMax]}const Bt={line:{stack:!0,dodge:!0,identity:!0,fill:!0},area:{stack:!0,dodge:!0,identity:!0,fill:!0},bar:{stack:!0,fill:!0}};function Gt(t){const{scales:e,config:r,layers:n,coordSystem:i}=t;if(Ut(r))return[];const a=jt({scales:e,layers:n}),s=$t(a),o=Wt(r.legend.position,n,i,a),c=qt(r.legend.display,o,n),u=c==="direct"?Zt(n):null;return s.map(p=>Kt(p,o,c,u))}function Ut(t){return t.legend.position==="none"||t.headline.show!=="none"&&t.legend.position==="auto"}function jt(t){const{scales:e,layers:r}=t,n=[];for(const i of Te){const a=e[i];if(a==null||a.kind==="identity")continue;const s=Ee(r,i),o=Ht(i,a);n.push({scaleAestheticKey:i,scale:a,variableName:s,guideType:o})}return n}function $t(t){const e=new Map;for(const r of t){const n=Xt(r),i=e.get(n);i?i.push(r):e.set(n,[r])}return[...e.values()]}function Kt(t,e,r,n){const i=t[0];return{aesthetics:t.map(a=>a.scaleAestheticKey),title:t.find(a=>y(a.variableName))?.variableName??null,position:e,display:r,items:i.scale.domain.map(a=>{const s={};for(const o of t)s[o.scaleAestheticKey]=o.scale.map(a);return{value:a,visual:s,normalizedY:n?.get(a)??null}})}}function Wt(t,e,r,n){if(t!=="auto")return t;const i=e.some(c=>c.geom==="line"||c.geom==="area"),a=e.some(c=>c.geom==="bar"&&(c.position==="stack"||c.position==="fill")),s=r.type==="polar",o=Math.max(0,...n.map(c=>c.scale.domain.length));return s?"top":(i||a)&&o>=3?"right":"top"}function Yt(t){if(t.length!==1)return!1;const e=t[0];return e?Bt[e.geom]?.[e.position]===!0:!1}function qt(t,e,r){return t==="pill"?"pill":t==="direct"?e==="right"?"direct":"pill":e==="right"&&Yt(r)?"direct":"pill"}function Xt(t){const e=t.scale.domain.map(Jt);return JSON.stringify([t.variableName,t.guideType,...e])}function Ht(t,e){const r=e.spec.scaleType;return r==="continuous"||r==="datetime"?`continuous:${t}`:"discrete"}function Jt(t){return t instanceof Date?`date:${t.getTime()}`:`${typeof t}:${String(t)}`}function Zt(t){const e=t[0];if(!e)return new Map;const r=new Map;return e.data.groupBy(M.group).forEach(n=>{const i=n.findLast(u=>y(te(u))||y(ee(u)));if(!i)return;const a=Ce(i);if(!y(a))return;const s=_e(i),o=te(i)??ee(i);if(!y(o))return;const c=y(s)?(s+o)/2:o;r.set(String(a),c)}),r}class Qt{compile(e){const r=Gt(e);return{axes:Rt(e,r),legends:r}}}class er{constructor(e,r,n,i){this.statCompiler=e,this.groupCompiler=r,this.geomCompiler=n,this.positionAdjusterCompiler=i}compile(e){return e.layers.map((r,n)=>({...K({data:e.data,mapping:{...e.mapping,...r.mapping}}).pipe(({data:a,mapping:s})=>{const o=this.statCompiler.compute(r.stat,{data:a,mapping:s});return{data:o.data,mapping:{...s,...o.mapping}}}).pipe(({data:a,mapping:s})=>({data:this.groupCompiler.compute({data:a,mapping:s}).data,mapping:s})).pipe(({data:a,mapping:s})=>{const o=this.geomCompiler.compile(r.geom,{data:a,mapping:s,params:r.params});return{data:o.data,mapping:{...s,...o.mapping}}}).pipe(({data:a,mapping:s})=>{const o=this.positionAdjusterCompiler.adjust(r.position,{data:a,mapping:s});return{data:o.data,mapping:{...s,...o.mapping}}}).result(),index:n,geom:r.geom,position:r.position,yScaleType:r.yScaleType,params:r.params}))}}class tr{constructor(e){this.registry=e}adjust(e,r){return this.registry.get(e).adjust(r)}}class Y{}class rr extends Y{constructor(){super(...arguments),this.type="dodge"}adjust({data:e,mapping:r}){if(!h(r.x))return{data:e,mapping:{}};const i=e.getValues(M.group,{type:"categorical",distinct:!0,skipNulls:!0});if(i.length===0)return{data:e,mapping:{}};const a=e.size(),s=e.getValues(M.group,{type:"categorical"}),o=i.length,c=new Map(i.map((d,g)=>[d,g])),u=new Array(a).fill(null),p=new Array(a).fill(null);for(let d=0;d<a;d++){const g=s[d];if(g==null)continue;const f=c.get(g);f!==void 0&&(u[d]=f/o-U,p[d]=(f+1)/o-U)}return{data:e.addVariable(l.xMin,"numeric",u).addVariable(l.xMax,"numeric",p),mapping:{}}}}const Re=(t,e)=>{const r=h(e.x),n=h(e.y);if(!r||!n)return null;const i=t.getValues(M.group,{type:"categorical",distinct:!0,skipNulls:!0});if(i.length===0)return null;const a=t.getValues(r),s=t.getValues(n,{type:"numeric"}),o=t.getValues(M.group,{type:"categorical"}),c=t.size(),u=new Map;for(let p=0;p<c;p++){const m=a[p]??null,d=o[p];if(d==null)continue;let g=u.get(m);g||(g=new Map,u.set(m,g)),g.set(d,p)}return{yValues:s,observationIndexByXAndGroup:u,uniqueGroupKeys:i,observationCount:c}};class nr extends Y{constructor(){super(...arguments),this.type="fill"}adjust({data:e,mapping:r}){const n=Re(e,r);if(n===null)return{data:e,mapping:{}};const{yValues:i,observationIndexByXAndGroup:a,uniqueGroupKeys:s,observationCount:o}=n,c=[...i],u=new Array(o).fill(0);for(const[,m]of a){let d=0,g=0;for(const w of s){const A=m.get(w);if(A===void 0)continue;const V=i[A];V!=null&&(V>=0?d+=V:g-=V)}let f=0,b=0;for(const w of s){const A=m.get(w);if(A===void 0)continue;const V=i[A];if(V===void 0)continue;if(V===null){u[A]=null,c[A]=null;continue}const ie=V>=0?d:g;if(ie===0){u[A]=0,c[A]=0;continue}const ae=V/ie;V>=0?(u[A]=f,c[A]=f+=ae):(c[A]=b,u[A]=b+=ae)}}return{data:e.addVariable(l.yMin,"numeric",u).addVariable(l.yMax,"numeric",c),mapping:{}}}}class ir extends Y{constructor(){super(...arguments),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}}class ar extends Y{constructor(){super(...arguments),this.type="stack"}adjust({data:e,mapping:r}){const n=Re(e,r);if(n===null)return{data:e,mapping:{}};const{yValues:i,observationIndexByXAndGroup:a,uniqueGroupKeys:s,observationCount:o}=n,c=[...i],u=new Array(o).fill(0);for(const[,m]of a){let d=0,g=0;for(const f of s){const b=m.get(f);if(b===void 0)continue;const w=i[b];if(w!==void 0){if(w===null){u[b]=null,c[b]=null;continue}w>=0?(u[b]=d,c[b]=d+=w):(c[b]=g,u[b]=g+=w)}}}return{data:e.addVariable(l.yMin,"numeric",u).addVariable(l.yMax,"numeric",c),mapping:{}}}}class sr extends I{constructor(){super("position"),this.register("identity",new ir),this.register("stack",new ar),this.register("fill",new nr),this.register("dodge",new rr)}}class or{map({data:e,layer:r,getPositionScale:n}){const i=h(r.mapping.x),a=n("x");if(!i||!a)return e;const o=e.getValues(i).map(c=>y(c)?a.map(c):null);return e.addVariable(l.x,"numeric",o)}}class cr{map({data:e,getPositionScale:r}){const n=r("x");if(!n?.bandwidth||!e.hasVariable(l.x)||!e.hasVariable(l.xMin)||!e.hasVariable(l.xMax))return e;const i=e.getValues(l.x,{type:"numeric"}),a=e.getValues(l.xMin,{type:"numeric"}),s=e.getValues(l.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let p=0;p<o;p++){const m=i[p],d=a[p],g=s[p];y(m)&&y(d)&&y(g)?(c[p]=m+d*n.bandwidth,u[p]=m+g*n.bandwidth):(c[p]=null,u[p]=null)}return e.addVariable(l.xMin,"numeric",c).addVariable(l.xMax,"numeric",u)}}class lr{map({data:e,layer:r,getPositionScale:n}){const i=h(r.mapping.y),a=ne(r.yScaleType),s=n(a);if(!i||!s)return e;const c=e.getValues(i).map(u=>y(u)?s.map(u):null);return e.addVariable(l.y,"numeric",c)}}class ur{map({data:e,layer:r,getPositionScale:n}){const i=ne(r.yScaleType),a=n(i);if(!a||!e.hasVariable(l.yMin)||!e.hasVariable(l.yMax))return e;const s=e.getValues(l.yMin,{type:"numeric"}),o=e.getValues(l.yMax,{type:"numeric"}),c=e.size(),u=new Array(c),p=new Array(c);for(let m=0;m<c;m++){const d=s[m],g=o[m];y(d)&&y(g)?(u[m]=a.map(d),p[m]=a.map(g)):(u[m]=null,p[m]=null)}return e.addVariable(l.yMin,"numeric",u).addVariable(l.yMax,"numeric",p)}}const pr=[new or,new lr,new cr,new ur];function dr(t,e){const r=t[e];return r?.kind==="position"?r:null}class mr{constructor(e=pr){this.mappers=e}compile(e){const r=n=>dr(e.scales,n);return e.layers.map(n=>this.compileLayer(n,r))}compileLayer(e,r){let n=e.data;for(const i of this.mappers)n=i.map({data:n,layer:e,getPositionScale:r});return{...e,data:n}}}class gr{constructor(e){this.registry=e}compile(e){const r=new Map;for(const a of e.scales)r.set(a.scaledAesthetic,a);const n=this.collectValues(e.layers,r),i={};for(const[a,s]of r){const o=n.get(a)??[],c=this.registry.get(s.scaleType);i[a]=c.compile(s,o)}return i}collectValues(e,r){const n=new Map;for(const i of e)for(const[a,s]of Object.entries(i.mapping)){const o=a,c=o==="y"?ne(i.yScaleType):o;if(!Ze(c)||!r.has(c))continue;const u=this.resolveVariables(o,s,i.data);this.collectFromVariables(i.data,u,c,n)}return n}resolveVariables(e,r,n){if(e==="y"&&this.hasPositionAdjustedY(n))return[l.yMin,l.yMax];const i=h(r);return!i||!n.hasVariable(i)?[]:[i]}hasPositionAdjustedY(e){return e.hasVariable(l.yMin)&&e.hasVariable(l.yMax)}collectFromVariables(e,r,n,i){if(r.length===0)return;let a=[];for(const o of r)a=a.concat(e.getValues(o));const s=i.get(n);i.set(n,s?s.concat(a):a)}}class P{createPositionScale(e,r){return{kind:"position",aesthetic:_(e.scaledAesthetic),spec:e,...r}}createVisualScale(e,r){return{kind:"visual",aesthetic:_(e.scaledAesthetic),spec:e,...r}}}class fr extends P{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(e,r){if(e.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const n=$(e.scaledAesthetic),i=this.computeDataDomain(r,e);return n?this.buildPositionScale(i,e):this.buildVisualScale(i,e)}computeDataDomain(e,r){let n=1/0,i=-1/0;for(const a of e)typeof a=="number"&&(a<n&&(n=a),a>i&&(i=a));return n===1/0?[0,0]:(r.zero&&(n>0&&(n=0),i<0&&(i=0)),[n,i])}createD3Scale(e,r,n){let i=[n.domainMin??e[0],n.domainMax??e[1]];const a=n.transform==="log"&&yr(i),s=a?C.scaleLog():n.transform==="sqrt"?C.scaleSqrt():C.scaleLinear();return n.nice&&!a&&(i=s.copy().domain(i).nice().domain()),s.domain([n.domainMin??i[0],n.domainMax??i[1]]).range(r).clamp(n.clamp)}buildPositionScale(e,r){const n=r.reverse?[1,0]:[0,1],i=this.createD3Scale(e,n,r);return this.createPositionScale(r,{map:i,domain:i.domain(),bandwidth:null,generateTicks:()=>i.ticks()})}buildVisualScale(e,r){const n=r.range??[0,1],i=r.reverse?[n[1],n[0]]:n,a=this.createD3Scale(e,i,r);return this.createVisualScale(r,{map:a,domain:a.domain(),generateTicks:()=>a.ticks()})}}const yr=t=>{const[e,r]=t;return e>0&&r>0||e<0&&r<0};class hr extends P{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(e,r){if(e.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const n=$(e.scaledAesthetic),i=this.computeDataDomain(r);if(!n)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(i,e)}computeDataDomain(e){let r=1/0,n=-1/0;for(const i of e){if(!(i instanceof Date))continue;const a=i.getTime();a<r&&(r=a),a>n&&(n=a)}return r===1/0?[]:[new Date(r),new Date(n)]}createD3Scale(e,r,n){const i=br(e)?e:[],a=C.scaleUtc().domain(i).range(r).clamp(n.clamp);if(n.nice&&a.nice(),y(n.domainMin)||y(n.domainMax)){const[s,o]=a.domain();s!==void 0&&o!==void 0&&a.domain([n.domainMin??s,n.domainMax??o])}return a}buildScale(e,r){const n=r.reverse?[1,0]:[0,1],i=this.createD3Scale(e,n,r);return this.createPositionScale(r,{map:i,domain:i.domain(),bandwidth:null,generateTicks:()=>i.ticks()})}}const br=t=>t.length===2&&t[0]instanceof Date&&t[1]instanceof Date;class xr extends P{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,r){if(e.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const n=$(e.scaledAesthetic),i=this.computeDataDomain(r,e);return n?this.buildPositionScale(i,e):this.buildVisualScale(i,e)}computeDataDomain(e,r){if(r.domain!=null&&r.domain.length>0)return[...r.domain];const n=new Set,i=[];for(const a of e)n.has(a)||(n.add(a),i.push(a));return r.sort==="ascending"?i.sort((a,s)=>String(a).localeCompare(String(s))):r.sort==="descending"&&i.sort((a,s)=>String(s).localeCompare(String(a))),i}buildPositionScale(e,r){const n=e.map(String),i=r.padding??N.padding,a=C.scaleBand().domain(n).range([0,1]).paddingInner(i).paddingOuter(i/2),s=a.bandwidth()/2;return this.createPositionScale(r,{map:o=>(a(String(o))??0)+s,domain:e,bandwidth:a.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,r){const n=e.map(String),i=r.range&&r.range.length>0?C.scaleOrdinal().domain(n).range(r.range).unknown(r.range[0]):null;return this.createVisualScale(r,{map:a=>{const s=String(a);return i?i(s):s},domain:e,generateTicks:()=>e})}}class Sr extends P{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:_(e.scaledAesthetic),spec:e,map:r=>r,domain:[],generateTicks:()=>[]}}}class Tr extends P{constructor(e){super(),this.paletteRegistry=e,this.compatibleDataTypes=["categorical"]}compile(e,r){if(e.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const n=this.computeDomain(r),i=this.paletteRegistry.get(e.palette),a=C.scaleOrdinal().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>a?a(String(s)):String(s),domain:n,generateTicks:()=>n})}computeDomain(e){const r=new Set,n=[];for(const i of e)r.has(i)||(r.add(i),n.push(i));return n}}class Ar extends I{constructor(e){super("scale"),this.paletteRegistry=e,this.register("continuous",new fr),this.register("discrete",new xr),this.register("datetime",new hr),this.register("identity",new Sr),this.register("palette",new Tr(this.paletteRegistry))}}class wr{constructor(e){this.registry=e}compute(e,r){return this.registry.get(e).compute(r)}}class Ie{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}}class Vr extends Ie{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:r}){const n=h(r.x);if(n==null)throw new Error("'x' variable is required for 'count' stat");if(h(r.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const a=[...new Set([n,...Ae(e,r)])];return{data:e.groupBy(...a).rollup({[oe.count]:{variableName:n,aggregation:"count"}}),mapping:{y:oe.count}}}}class Mr extends Ie{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}}class vr extends I{constructor(){super("stat"),this.register("identity",new Mr),this.register("count",new Vr)}}class Er{constructor(e){this.registry=e}compile(e,r){return r.reduce((n,i)=>this.registry.get(i.transformType).apply(n,i),e)}}class Lr{constructor(){this.transformType="aggregate"}apply(e,r){const{options:n}=r,i={};for(const a of n.operations)i[a.as]={variableName:a.variableName,aggregation:a.op};return e.groupBy(...n.groupby).rollup(i)}}class Cr{constructor(){this.transformType="filter"}apply(e,r){const{options:n}=r;return e.filter(n.variableName,n.operator,n.value)}}class _r{constructor(){this.transformType="reshape"}apply(e,r){const{options:n}=r;return e.reshapeFromWideToLong(n.keep,n.reshape,n.keyName,n.valueName)}}class Rr{constructor(){this.transformType="sort"}apply(e,r){const{options:n}=r;return e.orderBy(n.variableName,n.direction??"asc")}}class Ir extends I{constructor(){super("transform"),this.register("aggregate",new Lr),this.register("filter",new Cr),this.register("reshape",new _r),this.register("sort",new Rr)}}class Dr extends Error{constructor(e){const r=e.map(n=>`- ${n.message}`).join(`
2
2
  `);super(`Spec validation failed:
3
- ${n}`),this.issues=t,this.name="SpecValidationError"}}class Ia{constructor(t,n,r,a,s,i){this.transformCompiler=t,this.statCompiler=n,this.groupCompiler=r,this.geomCompiler=a,this.positionAdjusterCompiler=s,this.layerValidator=i}compile(t){const n=this.prepareLayers(t);return this.validateLayers(n),n.map(({layer:r,data:a,effectiveMapping:s})=>this.compileLayer(r,a,s))}prepareLayers(t){return t.layers.map(n=>({layer:n,data:this.transformCompiler.compile(t.data,n.transforms),effectiveMapping:{...t.mapping,...n.mapping}}))}validateLayers(t){const n=[];for(const{layer:r,data:a,effectiveMapping:s}of t)n.push(...this.layerValidator.validate({layerId:r.id,geom:r.geom,stat:r.stat,effectiveMapping:s,data:a}));if(n.length>0)throw new un(n)}compileLayer(t,n,r){return{...le({data:n,mapping:r}).pipe(({data:s,mapping:i})=>{const o=this.statCompiler.compute(t.stat,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>({data:this.groupCompiler.compute({data:s,mapping:i}).data,mapping:i})).pipe(({data:s,mapping:i})=>{const o=this.geomCompiler.compile(t.geom,{data:s,mapping:i,params:t.params});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>{const o=this.positionAdjusterCompiler.adjust(t.position,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).result(),id:t.id,geom:t.geom,position:t.position,yScaleType:t.yScaleType,params:t.params,interactive:t.interactive}}}class Ea{constructor(t,n){this.geomRegistry=t,this.statRegistry=n}validate(t){return[...this.validateRequiredAesthetics(t),...this.validateVariableExistence(t)]}validateRequiredAesthetics({layerId:t,geom:n,stat:r,effectiveMapping:a}){const s=[],{requiredAesthetics:i}=this.geomRegistry.get(n),{computedVariables:o}=this.statRegistry.get(r);for(const c of i)o.has(c)||m(a[c])||s.push({code:"MISSING_AESTHETIC",message:`Layer '${t}': geom '${n}' requires aesthetic '${c}'`,layerId:t,aesthetic:c});return s}validateVariableExistence({layerId:t,stat:n,effectiveMapping:r,data:a}){const s=[],{computedVariables:i}=this.statRegistry.get(n);for(const[o,c]of Object.entries(r)){if(i.has(o))continue;const l=M(c);l!==null&&(a.hasVariable(l)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${t}': aesthetic '${o}' references variable '${l}' which does not exist in the dataset`,layerId:t,aesthetic:o}))}return s}}class _a{constructor(t){this.registry=t}adjust(t,n){return this.registry.get(t).adjust(n)}}class De{}class La extends De{constructor(){super(...arguments),this.type="dodge"}adjust({data:t,mapping:n}){if(!M(n.x))return{data:t,mapping:{}};const a=t.getValues(V.group,{type:"categorical",distinct:!0,skipNulls:!0});if(a.length===0)return{data:t,mapping:{}};const s=t.size(),i=t.getValues(V.group,{type:"categorical"}),o=Qt/2,c=a.length>1?_r:0,l=B.scaleBand().domain(a.map(String)).range([-o,o]).paddingInner(c).paddingOuter(0),p=l.bandwidth(),d=new Array(s).fill(null),y=new Array(s).fill(null);for(let h=0;h<s;h++){const b=i[h];if(!m(b))continue;const g=l(String(b));m(g)&&(d[h]=g,y[h]=g+p)}return{data:t.addVariable(u.xMin,"numeric",d).addVariable(u.xMax,"numeric",y),mapping:{}}}}const St=A("__ungrouped__"),dn=(e,t)=>{const n=M(t.x),r=M(t.y);if(!n||!r)return null;const a=e.getValues(V.group,{type:"categorical",distinct:!0,skipNulls:!0}),s=a.length===0,i=s?[St]:a,o=e.getValues(n),c=e.getValues(r,{type:"numeric"}),l=e.getValues(V.group,{type:"categorical"}),p=e.size(),d=new Map;for(let y=0;y<p;y++){const f=o[y]??null,h=l[y],b=s?St:h;if(!m(b))continue;let g=d.get(f);g||(g=new Map,d.set(f,g)),g.set(b,y)}return{yValues:c,observationIndexByXAndGroup:d,uniqueGroupKeys:i,observationCount:p}};class ka extends De{constructor(){super(...arguments),this.type="fill"}adjust({data:t,mapping:n}){const r=dn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,d]of s){let y=0,f=0;for(const g of i){const x=d.get(g);if(x===void 0)continue;const S=a[x];S!=null&&(S>=0?y+=S:f-=S)}let h=0,b=0;for(const g of i){const x=d.get(g);if(x===void 0)continue;const S=a[x];if(S===void 0)continue;if(S===null){l[x]=null,c[x]=null;continue}const k=S>=0?y:f;if(k===0){l[x]=0,c[x]=0;continue}const D=S/k;S>=0?(l[x]=h,c[x]=h+=D):(c[x]=b,l[x]=b+=D)}}return{data:t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c),mapping:{}}}}class Da extends De{constructor(){super(...arguments),this.type="identity"}adjust({data:t}){return{data:t,mapping:{}}}}class Ca extends De{constructor(){super(...arguments),this.type="stack"}adjust({data:t,mapping:n}){const r=dn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,y]of s){let f=0,h=0;for(const b of i){const g=y.get(b);if(g===void 0)continue;const x=a[g];if(x!==void 0){if(x===null){l[g]=null,c[g]=null;continue}x>=0?(l[g]=f,c[g]=f+=x):(c[g]=h,l[g]=h+=x)}}}let p=t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c);const d=M(n.y);return d!==null&&(p=p.addVariable(d,"numeric",c)),{data:p,mapping:{}}}}class Ra extends K{constructor(){super("position"),this.register("identity",new Da),this.register("stack",new Ca),this.register("fill",new ka),this.register("dodge",new La)}}class Na{map({data:t,layer:n,getPositionScale:r}){const a=M(n.mapping.x),s=r("x");if(!a||!s)return t;const o=t.getValues(a).map(c=>m(c)?s.map(c):null);return t.addVariable(u.x,"numeric",o)}}class Fa{map({data:t,getPositionScale:n}){const r=n("x");if(!r?.bandwidth||!t.hasVariable(u.x)||!t.hasVariable(u.xMin)||!t.hasVariable(u.xMax))return t;const a=t.getValues(u.x,{type:"numeric"}),s=t.getValues(u.xMin,{type:"numeric"}),i=t.getValues(u.xMax,{type:"numeric"}),o=t.size(),c=new Array(o),l=new Array(o);for(let p=0;p<o;p++){const d=a[p],y=s[p],f=i[p];m(d)&&m(y)&&m(f)?(c[p]=d+y*r.bandwidth,l[p]=d+f*r.bandwidth):(c[p]=null,l[p]=null)}return t.addVariable(u.xMin,"numeric",c).addVariable(u.xMax,"numeric",l)}}class Oa{map({data:t,layer:n,getPositionScale:r}){const a=M(n.mapping.y),s=ue(n.yScaleType),i=r(s);if(!a||!i)return t;const c=t.getValues(a).map(l=>m(l)?i.map(l):null);return t.addVariable(u.y,"numeric",c)}}class Pa{map({data:t,layer:n,getPositionScale:r}){const a=ue(n.yScaleType),s=r(a);if(!s||!t.hasVariable(u.yMin)||!t.hasVariable(u.yMax))return t;const i=t.getValues(u.yMin,{type:"numeric"}),o=t.getValues(u.yMax,{type:"numeric"}),c=t.size(),l=new Array(c),p=new Array(c);for(let d=0;d<c;d++){const y=i[d],f=o[d];m(y)&&m(f)?(l[d]=s.map(y),p[d]=s.map(f)):(l[d]=null,p[d]=null)}return t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",p)}}const Ba=[new Na,new Oa,new Fa,new Pa];function Ua(e,t){const n=e[t];return n?.kind==="position"?n:null}class Ya{constructor(t=Ba){this.mappers=t}compile(t){const n=r=>Ua(t.scales,r);return t.layers.map(r=>this.compileLayer(r,n))}compileLayer(t,n){let r=t.data;for(const a of this.mappers)r=a.map({data:r,layer:t,getPositionScale:n});return{...t,data:r}}}class Ga{constructor(t){this.registry=t}compile(t){this.validateScaleTypeCompatibility(t);const n=new Map;for(const s of t.scales)n.set(s.scaledAesthetic,s);const r=this.collectValues(t.layers,n),a={};for(const[s,i]of n){const o=r.get(s)??[],c=this.registry.get(i.scaleType);a[s]=c.compile(i,o)}return a}validateScaleTypeCompatibility(t){const n=[];for(const r of t.scales){const{compatibleDataTypes:a}=this.registry.get(r.scaleType),s=U(r.scaledAesthetic),i=t.layers.find(l=>m(l.mapping[s]));if(!i)continue;const o=M(i.mapping[s]);if(!m(o)||!i.data.hasVariable(o))continue;const c=i.data.getType(o);a.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${c})`,aesthetic:s})}if(n.length>0)throw new un(n)}collectValues(t,n){const r=new Map;for(const a of t)for(const[s,i]of Object.entries(a.mapping)){const o=s,c=o==="y"?ue(a.yScaleType):o;if(!Fr(c)||!n.has(c))continue;const l=this.resolveVariables(o,i,a.data);this.collectFromVariables(a.data,l,c,r)}return r}resolveVariables(t,n,r){if(t==="y"&&this.hasPositionAdjustedY(r))return[u.yMin,u.yMax];const a=M(n);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(t){return t.hasVariable(u.yMin)&&t.hasVariable(u.yMax)}collectFromVariables(t,n,r,a){if(n.length===0)return;let s=[];for(const o of n)s=s.concat(t.getValues(o));const i=a.get(r);a.set(r,i?i.concat(s):s)}}class pe{createPositionScale(t,n){return{kind:"position",aesthetic:U(t.scaledAesthetic),spec:t,...n}}createVisualScale(t,n){return{kind:"visual",aesthetic:U(t.scaledAesthetic),spec:t,...n}}}class za extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(t,n){if(t.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){let r=1/0,a=-1/0;for(const s of t)typeof s=="number"&&(s<r&&(r=s),s>a&&(a=s));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),a<0&&(a=0)),[r,a])}createD3Scale(t,n,r){let a=[r.domainMin??t[0],r.domainMax??t[1]];const s=r.transform==="log"&&$a(a),i=s?B.scaleLog():r.transform==="sqrt"?B.scaleSqrt():B.scaleLinear();return r.nice&&!s&&(a=i.copy().domain(a).nice().domain()),i.domain([r.domainMin??a[0],r.domainMax??a[1]]).range(n).clamp(r.clamp)}buildPositionScale(t,n){const r=n.reverse?[1,0]:[0,1],a=this.createD3Scale(t,r,n);return this.createPositionScale(n,{map:a,domain:a.domain(),bandwidth:null,generateTicks:s=>s&&"count"in s?a.ticks(s.count):a.ticks()})}buildVisualScale(t,n){const r=n.range??[0,1],a=n.reverse?[r[1],r[0]]:r,s=this.createD3Scale(t,a,n);return this.createVisualScale(n,{map:s,domain:s.domain(),generateTicks:i=>i&&"count"in i?s.ticks(i.count):s.ticks()})}}const $a=e=>{const[t,n]=e;return t>0&&n>0||t<0&&n<0};class Wa extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(t,n){if(t.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n);if(!r)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(a,t,this.collectInputDates(n))}collectInputDates(t){const n=new Set,r=[];for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();n.has(s)||(n.add(s),r.push(a))}return r.sort((a,s)=>a.getTime()-s.getTime()),r}computeDataDomain(t){let n=1/0,r=-1/0;for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();s<n&&(n=s),s>r&&(r=s)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(t,n,r){const a=Ha(t)?t:[],s=B.scaleUtc().domain(a).range(n).clamp(r.clamp);if(r.nice&&s.nice(),m(r.domainMin)||m(r.domainMax)){const[i,o]=s.domain();i!==void 0&&o!==void 0&&s.domain([r.domainMin??i,r.domainMax??o])}return s}buildScale(t,n,r){const a=n.reverse?[1,0]:[0,1],s=this.createD3Scale(t,a,n),[i,o]=s.domain(),c=i&&o?r.filter(l=>l>=i&&l<=o):[];return this.createPositionScale(n,{map:s,domain:s.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&o?Ur(i,o,l.interval):[]:s.ticks(l?.count)})}}const Ha=e=>e.length===2&&Z(e[0])&&Z(e[1]),Q={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},Tt={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},xe={domainMin:null,domainMax:null,nice:!1,reverse:!1},re={range:null,sort:"none",domain:null,padding:.1},Ka={palette:"default"};class ja extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(t,n){if(t.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){if(n.domain!==null&&n.domain.length>0)return[...n.domain];const r=new Set,a=[];for(const s of t)r.has(s)||(r.add(s),a.push(s));return n.sort==="ascending"?a.sort((s,i)=>String(s).localeCompare(String(i))):n.sort==="descending"&&a.sort((s,i)=>String(i).localeCompare(String(s))),a}buildPositionScale(t,n){const r=t.map(String),a=n.padding??re.padding,s=B.scaleBand().domain(r).range([0,1]).paddingInner(a).paddingOuter(a/2),i=s.bandwidth()/2;return this.createPositionScale(n,{map:o=>(s(String(o))??0)+i,domain:t,bandwidth:s.bandwidth(),generateTicks:()=>[...t]})}buildVisualScale(t,n){const r=t.map(String),a=n.range&&n.range.length>0?B.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:s=>{const i=String(s);return a?a(i):i},domain:t,generateTicks:()=>t})}}class qa extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(t){if(t.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:U(t.scaledAesthetic),spec:t,map:n=>n,domain:[],generateTicks:()=>[]}}}class Xa extends pe{constructor(t){super(),this.paletteRegistry=t,this.compatibleDataTypes=["categorical","temporal"]}compile(t,n){if(t.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const r=this.computeDomain(n),a=this.paletteRegistry.get(t.palette),s=B.scaleOrdinal().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(t,{map:i=>s(String(i)),domain:r,generateTicks:()=>r})}computeDomain(t){const n=new Set,r=[];for(const a of t)n.has(a)||(n.add(a),r.push(a));return r}}class Qa extends K{constructor(t){super("scale"),this.paletteRegistry=t,this.register("continuous",new za),this.register("discrete",new ja),this.register("datetime",new Wa),this.register("identity",new qa),this.register("palette",new Xa(this.paletteRegistry))}}const Ja=new Set(["count","sum","mean","median"]);function pn(e,t){return Ja.has(e)?"numeric":t}const Za="key",es="value",ts={eq:(e,t)=>e[t.__variableName]===t.__value,neq:(e,t)=>e[t.__variableName]!==t.__value,gt:(e,t)=>e[t.__variableName]>t.__value,gte:(e,t)=>e[t.__variableName]>=t.__value,lt:(e,t)=>e[t.__variableName]<t.__value,lte:(e,t)=>e[t.__variableName]<=t.__value};class w{constructor(t={}){const{table:n,variableMetadata:r}=this.parseVariableMap(t);this.table=n,this.variableMetadata=r}static merge(...t){if(t.length===0)return w.fromTrusted(F.table({}),{});const n=t.map(o=>o.table),[r,...a]=n,s=a.reduce((o,c)=>o.concat(c),r),i=t.reduce((o,c)=>({...o,...c.variableMetadata}),{});return w.fromTrusted(s,i)}static fromTrusted(t,n){const r=Object.create(w.prototype);return r.table=t,r.variableMetadata=n,r}size(){return this.table.numRows()}getVariableNames(){return this.table.columnNames()}hasVariable(t){return this.table.column(t)!==void 0}toData(){const n=this.getVariableNames().map(a=>({key:a})),r=Array.from({length:this.size()},(a,s)=>this.table.object(s));return{columns:n,rows:r}}addVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},s=this.normalizeRawValues(n,r),i=this.table.assign(F.table({[t]:s}));return w.fromTrusted(i,a)}addConstantVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},[s]=this.normalizeRawValues(n,[r]),i=this.table.assign(F.table({[t]:Array(this.size()).fill(s)}));return w.fromTrusted(i,a)}deriveVariable(t,n,r){const a=Array.from({length:this.size()},(s,i)=>r(this.table.object(i)));return this.addVariable(t,n,a)}renameVariable(t,n){const r=this.variableMetadata[t];if(!r)throw new Error(`Variable ${t} not defined`);const a=this.table.rename({[t]:n}),{[t]:s,...i}=this.variableMetadata,o={...i,[n]:r};return w.fromTrusted(a,o)}selectVariables(...t){const n=this.table.select(...t),r=Object.fromEntries(Object.entries(this.variableMetadata).filter(([a])=>t.includes(a)));return w.fromTrusted(n,r)}getType(t){const n=this.variableMetadata[t];if(!n)throw new Error(`Variable ${t} not defined`);return n.type}groupVariableNamesByType(){const t={numeric:[],categorical:[],temporal:[]};for(const[n,{type:r}]of Object.entries(this.variableMetadata))t[r].push(n);return t}getValues(t,n){if(!this.hasVariable(t))throw new Error(`Variable '${t}' not defined`);const r=this.getType(t);if(n?.type!==void 0&&r!==n.type)throw new Error(`Variable '${t}' has type '${r}', expected '${n.type}'`);let a=this.table.array(t);return n?.distinct&&(a=this.getDistinctValues(r,a)),n?.skipNulls&&(a=this.skipNulls(a)),a}filter(t,n,r){const a=ts[n],s=this.table.params({__variableName:t,__value:r}).filter(a);return w.fromTrusted(s,this.variableMetadata)}orderBy(t,n="asc"){const r=this.table.orderby(n==="asc"?t:F.desc(t));return w.fromTrusted(r,this.variableMetadata)}getFirst(){return this.size()===0?null:this.table.object(0)}getLast(){return this.size()===0?null:this.table.object(this.size()-1)}findLast(t){for(let n=this.size()-1;n>=0;n--){const r=this.table.object(n);if(t(r))return r}return null}groupBy(...t){const n=this.table.groupby(...t);return new ns(t,n,this.variableMetadata)}rollup(t){const n=this.table.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,F.op[s.aggregation](s.variableName)]))),r={};for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=pn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}reshapeFromWideToLong({keep:t,reshape:n,keyName:r=Za,valueName:a=es}={}){const{numeric:s,categorical:i,temporal:o}=this.groupVariableNamesByType(),c=t??[...i,...o],l=n??s.filter(h=>!c.includes(h));if(c.includes(r)||c.includes(a))throw new Error(`The variables to keep includes the variables '${r}' or '${a}' to create the key and value variables`);if(l.length===0){const h={};for(const b of c){const g=this.variableMetadata[b];g&&(h[b]={type:g.type,values:[]})}return h[r]={type:"categorical",values:[]},h[a]={type:"numeric",values:[]},new w(h)}if(l.filter(h=>this.variableMetadata[h]?.type!=="numeric").length>0)throw new Error("Only numeric variables can be reshaped");const y=this.table.select([...c,...l]).fold(l,{as:[r,a]}),f={};for(const h of c){const b=this.variableMetadata[h];b&&(f[h]=b)}return f[r]={type:"categorical"},f[a]={type:"numeric"},w.fromTrusted(y,f)}print(){console.table(this.variableMetadata),this.table.print()}[Symbol.iterator](){return this.table[Symbol.iterator]()}parseVariableMap(t){const n={},r={};for(const[s,{type:i,values:o}]of Object.entries(t))n[s]=o,r[s]={type:i};return{table:F.table(n),variableMetadata:r}}normalizeRawValues(t,n){switch(t){case"numeric":return n.map(r=>typeof r!="number"||Number.isNaN(r)?null:r);case"categorical":return n.map(r=>typeof r!="string"?null:r);case"temporal":return n.map(r=>!(r instanceof Date)||!T.isValid(r)?null:r);default:{const r=t;throw new Error(`Cannot normalize raw value of unknown type: ${r}`)}}}skipNulls(t){return t.filter(n=>n!==null)}getDistinctValues(t,n){const r=t==="temporal",a=new Set,s=[];for(const i of n){const o=r&&i instanceof Date?i.getTime():i;a.has(o)||(a.add(o),s.push(i))}return s}}class ns{constructor(t,n,r){this.groupedBy=t,this.grouped=n,this.variableMetadata=r}forEach(t){const n=this.grouped.partitions(),r=this.grouped.columnNames(),a=this.groupedBy.map(i=>this.grouped.column(i)).filter(i=>i!==void 0);let s=0;for(const i of n){const o=i[0];if(o===void 0)continue;const c=this.getStableKey(a,o),l=Object.fromEntries(r.map(d=>{const y=this.grouped.column(d);return[d,i.map(f=>y?.get(f))]})),p=F.table(l);t(w.fromTrusted(p,this.variableMetadata),c,s++)}}rollup(t){const n=this.grouped.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,F.op[s.aggregation](s.variableName)]))),r=Object.fromEntries(this.groupedBy.map(a=>[a,{type:this.variableMetadata[a]?.type??"categorical"}]));for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=pn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}getStableKey(t,n){return $(t.map(r=>r.get(n)))}}const se={k:1e3,m:1e6,b:1e9,t:1e12},Ze=["k","m","b","t"],rs=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${Ze.join("|")})?$`,"i"),as=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,W=e=>e===null||e instanceof Date||Array.isArray(e)||typeof e=="boolean"?!1:typeof e=="string"?rs.test(e)&&!Number.isNaN(Number(e.replace(new RegExp(`[,${Ze.join("")}]`,"gi"),""))):!Number.isNaN(Number(e)),mn=e=>W(e)?!0:typeof e=="string"?as.test(e):!1,fn={$:"usd","£":"gbp","€":"eur","¥":"jpy","₹":"inr","₱":"php",P:"php","₩":"krw","₪":"ils","₫":"vnd","₽":"rub","฿":"thb",R$:"brl",Rp:"idr",RM:"myr","₦":"ngn",zł:"pln","₺":"try",kr:"dkk",Fr:"chf",R:"zar","د.إ":"aed","﷼":"sar",Ch$:"clp",NT$:"twd",HK$:"hkd",S$:"sgd",A$:"aud",C$:"cad",NZ$:"nzd",MX$:"mxn"},yn=e=>{if(typeof e=="string"){const t=hn(e);return t.length?W(t):!1}return W(e)},ss=e=>{const t=gn(e),n=t?fn[t]:void 0;if(!n)throw new Error("Could not get currency ISO");return n},hn=e=>{const t=gn(e);let n=e;if(t){const r=e.indexOf(t);r===0?n=e.slice(t.length):r===e.length-t.length?n=e.slice(0,e.length-t.length):e[0]==="-"&&r===1&&(n=`-${e.slice(t.length+1)}`)}return W(n)?n.split(",").join(""):""},gn=e=>Object.keys(fn).sort((n,r)=>r.length-n.length).find(n=>e.includes(n)),me="en-GB";class bn{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(t){this.previousYear===null?this.previousYear=t.getUTCFullYear():this.previousDate!==null&&T.isBefore(new Date(this.currentYear,t.getUTCMonth(),t.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(t.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const is=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,os=/^\s*(19\d{2}|2[01]\d{2})\s*$/,cs=[[/\bJan\b/i,"January"],[/\bFeb\b/i,"February"],[/\bMar\b/i,"March"],[/\bApr\b/i,"April"],[/\bJun\b/i,"June"],[/\bJul\b/i,"July"],[/\bAug\b/i,"August"],[/\bSept?\b/i,"September"],[/\bOct\b/i,"October"],[/\bNov\b/i,"November"],[/\bDec\b/i,"December"]],ls={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},xn=["/","-","."," "],At=[["d","M","yy"],["d","MM","yy"],["d","MMMM","yy"],["dd","M","yy"],["dd","MM","yy"],["dd","MMMM","yy"],["do","MMMM","yy"],["d","M","yyyy"],["d","MM","yyyy"],["d","MMMM","yyyy"],["dd","M","yyyy"],["dd","MM","yyyy"],["dd","MMMM","yyyy"],["do","MMMM","yyyy"]],wt=[["M","d","yy"],["M","dd","yy"],["MM","d","yy"],["MM","dd","yy"],["MMMM","d","yy"],["MMMM","dd","yy"],["MMMM","do","yy"],["M","d","yyyy"],["M","dd","yyyy"],["MM","d","yyyy"],["MM","dd","yyyy"],["MMMM","d","yyyy"],["MMMM","dd","yyyy"],["MMMM","do","yyyy"]],vt=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],Mn=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],us=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],Sn=1900,Tn=2199,ds=3,ps=6,ms=5,fs=1,ys=28,hs=/\s*[–—]\s*|\s-\s/,gs=e=>typeof e=="number"?Number.isNaN(e)?!1:e>=Sn&&e<=Tn:typeof e=="string"?os.test(e):!1,An=(e,t)=>{const n=oe(e);return W(n)?Ms(n):typeof n=="string"?!!wn(n)||vn(n)&&T.isValid(new Date(n)):T.isValid(n)},oe=e=>{if(typeof e!="string")return e;let t=e;for(const[n,r]of cs)t=t.replace(n,r);return t},wn=(e,t=me)=>{const n=oe(e);return vn(n)?{type:"datetime"}:In(t).find(r=>!de(r)||r.type==="month"&&n.length<ds?!1:r.dateFormat&&T.isValid(T.parse(n,r.dateFormat,new Date)))},vn=e=>is.test(e.trim()),bs=(e,t=me)=>{const[n,r]=e.split(hs);if(!n||!r)return;const a=oe(n).trim(),s=oe(r).trim();return xs(t).find(i=>{if(!de(i)||!i.dateFormat)return!1;const o=T.parse(a,i.dateFormat,new Date),c=T.parse(s,i.dateFormat,new Date);if(!T.isValid(o)||!T.isValid(c))return!1;const l=new bn,p=l.incrementYearIfNeeded(o),d=l.incrementYearIfNeeded(c),y=T.differenceInDays(d,p);return T.isWithinInterval(new Date(p.getFullYear(),fs,ys),{start:p,end:d})&&y===ms?!0:y===ps})},Vn=e=>ls[e]==="MDY"?[...wt,...At,...vt]:[...At,...wt,...vt],In=e=>{const t={date:Vn(e),year:[["yyyy"]],day_month:Mn,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...us,...Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>xn.map(s=>({dateFormat:a.join(s),type:n}))))]},xs=e=>{const t={weekly_date_range:Mn,weekly_date_range_with_year:Vn(e)};return Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>xn.map(s=>({dateFormat:a.join(s),type:n}))))},Ms=e=>{const t=Number(e);if(!ee.isInteger(t))return!1;const n=new Date(t),r=new Date(t*1e3),a=s=>T.isValid(s)&&s.getFullYear()>=Sn&&s.getFullYear()<=Tn;return a(n)||a(r)},Ss=(e,t)=>{const n=typeof e=="string"?e.trim():e;if(W(n))return{type:"decimal"};const r=typeof n=="string"&&wn(n,t);if(r)return r;const a=typeof n=="string"&&bs(n,t);return a||(An(e)?{type:"date"}:mn(e)?{type:"percentage"}:yn(e)&&typeof e=="string"?{type:"currency",iso:ss(e)}:{type:"text"})},Ts=e=>{const t=Object.entries(e);return!t.length||!t.some(([,n])=>!fe(n))},fe=e=>typeof e=="string"&&e.trim()===""||e===void 0||e===null||e==="-",As=/\s*[–—]\s*|\s-\s/,ws=(e,t,n)=>{if(fe(e))return null;switch(t.type){case"decimal":case"integer":case"duration":return En(e);case"percentage":return vs(e);case"currency":return Vs(e);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return _n(e,t.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return Is(e,t.dateFormat,n);case"text":return Es(e);default:{const r=t;throw new Error(`Unhandled value format: ${r.type}`)}}},En=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;let t=e.trim();if(!W(t))return null;let n=1;for(const r of Ze)if(new RegExp(`${r}$`,"i").test(t)){n=se[r],t=t.slice(0,-1);break}return Number(t.split(",").join(""))*n},vs=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();if(!mn(t))return null;const n=Number(t.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},Vs=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();return yn(t)?En(hn(t)):null},_n=(e,t,n)=>{if(e instanceof Date)return T.isValid(e)?e:null;const r=oe(String(e).trim());if(r.length===0)return null;const a=new Date;if(t){const i=T.parse(r,t,a);return T.isValid(i)?Oe(i):null}for(const i of In(n)){if(!de(i)||!i.dateFormat)continue;const o=T.parse(r,i.dateFormat,a);if(T.isValid(o))return Oe(o)}const s=new Date(r);return An(s)?Oe(s):null},Is=(e,t,n)=>{const r=String(e).trim().split(As),[a,s]=[r[0]?.trim(),r[1]?.trim()];return!a||!s?null:_n(a,t,n)},Es=e=>String(e).trim(),Oe=e=>new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())),_s={type:"year",dateFormat:"yyyy"},Ln=(e,t)=>{const n={},r={},a=Ds(e),s=Ls(e);for(const[i,o]of e.columns.entries()){const c=a.get(o.key);if(fe(c))continue;const l=i===s?_s:Ss(c,t),p=Pr(l);r[o.key]={type:p,valueFormat:l,label:o.label},n[o.key]=ks(o.key,e.rows,l,p,t)}return{dataset:new w(n),datasetMetadata:{columns:r}}},Ls=e=>{const t=Cs(e.rows,5);return e.columns.findIndex(n=>{const r=t.map(a=>a[n.key]).filter(a=>!fe(a));return r.length>=2&&r.every(gs)})},ks=(e,t,n,r,a)=>{const s=new bn,i=t.map(o=>{const c=ws(o[e],n,a);return an(n)&&c instanceof Date?s.incrementYearIfNeeded(c):c});return{type:r,values:i}},Ds=e=>{const t=new Map,n=new Set(e.columns.map(r=>r.key));for(const r of e.rows){for(const a of n){const s=r[a];fe(s)||(t.set(a,s),n.delete(a))}if(n.size===0)break}return t},Cs=(e,t)=>{const n=[];for(const r of e)if(Ts(r)||n.push(r),n.length===t)return n;return n},Rs=e=>"data"in e&&e.data instanceof w,Ns=e=>!("layers"in e);function kn(e){return{type:"config",config:e}}function Fs(e){return kn({legend:Ps(e.legend),axes:Bs(e.axes),headline:Us(e.headlineNumbers),numberFormat:Ys(e.appearance),content:Gs(e.content),appearance:Os(e.appearance)}).config}function Os(e){if(e?.background)return{background:e.background}}function Ps(e){if(e)return{position:e.position}}function Pe(e,t){return!e&&t===void 0?{}:{...e?.isHidden!==void 0?{isVisible:!e.isHidden}:void 0,...e?.label!==void 0?{label:e.label}:void 0,...e?.tickDisplayMode?{labels:{mode:e.tickDisplayMode}}:void 0,...t!==void 0?{grid:{isVisible:t}}:void 0}}function Bs(e){if(e)return{x:Pe(e.x,e.showGridLines),y:Pe(e.y,e.showGridLines),...e.y2?{ySecondary:Pe(e.y2)}:void 0}}function Us(e){if(e)return{show:e.show,compareWith:e.compareWith,size:e.size}}function Ys(e){if(e?.numberFormat)return{decimals:e.numberFormat.decimalPlaces,abbreviation:e.numberFormat.abbreviation}}function Gs(e){if(e)return{...!e.isTitleHidden&&e.title!==void 0?{title:e.title}:void 0,...!e.isSubtitleHidden&&e.subtitle!==void 0?{subtitle:e.subtitle}:void 0,...!e.isCaptionHidden&&e.caption!==void 0?{caption:e.caption}:void 0}}const E={cartesian:(e={})=>({type:"coord",coordType:"cartesian",params:e}),flip:(e={})=>({type:"coord",coordType:"flip",params:e}),polar:(e={})=>({type:"coord",coordType:"polar",params:e})};function zs(e={}){return{type:"layer",geom:"point",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function $s(e={}){return{type:"layer",geom:"line",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Ws(e={}){return{type:"layer",geom:"area",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Hs(e={}){return{type:"layer",geom:"bar",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}const _={point:zs,line:$s,area:Ws,bar:Hs},Te={stat:"identity",position:"identity",params:{size:8}},Be={stat:"identity",position:"identity",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"gap"}},Ue={stat:"identity",position:"stack",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"zero"}},Ye={stat:"identity",position:"dodge",params:{}},Ce="primary";function v(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"continuous",transform:t.transform,reverse:t.reverse,nice:t.nice,zero:t.zero,clamp:t.clamp,domainMin:t.domainMin??null,domainMax:t.domainMax??null,range:t.range}}function Ae(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"datetime",domainMin:t.domainMin??null,domainMax:t.domainMax??null,nice:t.nice,reverse:t.reverse,clamp:t.clamp}}function R(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"discrete",range:t.range,sort:t.sort,domain:t.domain??null,padding:t.padding}}function we(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"identity"}}function ve(e,t){return{type:"scale",scaledAesthetic:e,scaleType:"inferred",options:t}}function Dn(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"palette",palette:t.palette}}const z={x:Object.assign(e=>ve("x",e),{continuous:e=>v("x",e),discrete:e=>R("x",e),datetime:e=>Ae("x",e),log:e=>v("x",{...e,transform:"log"}),sqrt:e=>v("x",{...e,transform:"sqrt"})}),y:Object.assign(e=>ve("y",e),{continuous:e=>v("y",e),discrete:e=>R("y",e),datetime:e=>Ae("y",e),log:e=>v("y",{...e,transform:"log"}),sqrt:e=>v("y",{...e,transform:"sqrt"})}),ySecondary:Object.assign(e=>ve("ySecondary",e),{continuous:e=>v("ySecondary",e),discrete:e=>R("ySecondary",e),datetime:e=>Ae("ySecondary",e),log:e=>v("ySecondary",{...e,transform:"log"}),sqrt:e=>v("ySecondary",{...e,transform:"sqrt"})}),color:{continuous:e=>v("color",e),discrete:e=>R("color",e),palette:e=>Dn("color",e)},size:{continuous:e=>v("size",e),discrete:e=>R("size",e),identity:e=>we("size",e)},alpha:{continuous:e=>v("alpha",e),discrete:e=>R("alpha",e),identity:e=>we("alpha",e)},strokeWidth:{continuous:e=>v("strokeWidth",e),discrete:e=>R("strokeWidth",e),identity:e=>we("strokeWidth",e)}};function Ks(e={}){return{type:"transform",transformType:"reshape",options:e}}function js(e){return{type:"transform",transformType:"filter",options:e}}function qs(e){return{type:"transform",transformType:"sort",options:e}}function Xs(e){return{type:"transform",transformType:"aggregate",options:e}}function Qs(e){return{type:"transform",transformType:"constant",options:e}}const ie={reshape:Ks,filter:js,sort:qs,aggregate:Xs,constant:Qs},O="key",P="value",Vt=A("lineSeriesLabel"),It=A("barSeriesLabel"),Et=A("constantY"),Cn=e=>{if(m(e.color))return e;const t=M(e.y);return t===null?e:{...e,color:{value:t}}},et=e=>{const{numeric:t,categorical:n,temporal:r}=e.groupVariableNamesByType();return m(r[0])?r[0]:m(n[0])?n[0]:m(t[0])?t[0]:""},tt=e=>{const t=et(e),{numeric:n}=e.groupVariableNamesByType(),r=n.filter(s=>s!==t);return r.length<=1?{dataset:e,mapping:{x:t,y:r[0]??""}}:{dataset:e.reshapeFromWideToLong({keep:[t],keyName:O,valueName:P}),mapping:{x:t,y:P,color:O}}},Js=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType(),a=r[0];if(!m(a))throw new Error("No first numeric variable found");const s=r.slice(1);return s.length===0?{dataset:e.addConstantVariable(Et,"categorical",""),mapping:{x:a,y:Et,label:t[0]}}:s.length===1?{dataset:e,mapping:{x:a,y:s[0]??"",label:t[0]}}:{dataset:e.reshapeFromWideToLong({keep:[a,...t,...n],keyName:O,valueName:P}),mapping:{x:a,y:P,label:t[0],color:O}}},Zs=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType();let a,s;if(m(t[0])&&m(r[0]))a=t[0],s=r[0];else if(m(n[0])&&m(r[0]))a=n[0],s=r[0];else if(m(r[0])&&m(r[1]))a=r[0],s=r[1];else throw new Error("No label or value variable found");return{x:"",y:s,color:a}},ei=(e,t)=>{const{dataset:n,mapping:r}=tt(e.dataset),a=Cn(r),s=[_.line({params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&s.push(_.point({params:{size:Rn(t.pointSize)},interactive:!1})),{dataset:n,layers:s,coords:E.cartesian(),mapping:a,scales:[]}},ti=(e,t)=>{const{dataset:n,mapping:r}=tt(e.dataset),a=Cn(r),s=[_.area({position:"stack",params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&s.push(_.point({params:{size:Rn(t.pointSize)},position:"stack",interactive:!1})),{dataset:n,layers:s,coords:E.cartesian(),mapping:a,scales:[]}},J=(e,t,n,r,a)=>{const{dataset:s,mapping:i}=tt(e.dataset),o=[];if(r?.sortBars&&o.push(z.x.discrete({sort:"descending"})),!a?.useSingleColorForBars){const c=et(e.dataset),{numeric:l}=e.dataset.groupVariableNamesByType();l.filter(d=>d!==c).length===1&&e.dataset.getType(c)==="categorical"&&(i.color=c)}return{dataset:s,layers:[_.bar({position:t})],coords:n,mapping:i,scales:o}},_t=(e,t)=>({dataset:e.dataset,layers:[_.bar({position:"fill"})],coords:E.polar({theta:"y",innerRadius:t==="donut"?.55:0}),mapping:Zs(e.dataset),scales:[]}),ni=e=>{const{dataset:t,mapping:n}=Js(e.dataset);return{dataset:t,layers:[_.point()],coords:E.cartesian(),mapping:n,scales:[]}},ri=e=>{const{numeric:t,categorical:n}=e.dataset.groupVariableNamesByType(),r={x:t[0],y:t[1],size:t[2],label:n[0]},a=[];return m(r.size)&&a.push(z.size.continuous()),{dataset:e.dataset,layers:[_.point()],coords:E.cartesian(),mapping:r,scales:a}},Ge=(e,t)=>_.line({transforms:[ie.constant({variableName:Vt,type:"categorical",value:e})],aes:{y:e,color:Vt},...t?{yScaleType:"secondary"}:void 0}),ai=(e,t)=>{const{numeric:n,categorical:r,temporal:a}=e.dataset.groupVariableNamesByType(),s=et(e.dataset),i=[...r,...a],o=n.filter(h=>h!==s),c=t?.comboType??"grouped-bars",l=e.axes?.hasDualYAxis===!0,p=c==="lines"||o.length<2,d=p?[]:o.slice(0,-1),y=p?o:o.slice(-1),f=[];if(d.length>0){const h=c==="stacked-bars"?"stack":"dodge",b=d.length===1?d[0]:null;m(b)?f.push(_.bar({transforms:[ie.constant({variableName:It,type:"categorical",value:b})],aes:{y:b,color:It},position:h})):f.push(_.bar({transforms:[ie.reshape({keep:i,reshape:d,keyName:O,valueName:P})],aes:{y:P,color:O},position:h}))}if(p&&y.length>=2){const h=l?y.slice(0,-1):y,b=h.length===1?h[0]:null;if(m(b)?f.push(Ge(b,!1)):f.push(_.line({transforms:[ie.reshape({keep:i,reshape:h,keyName:O,valueName:P})],aes:{y:P,color:O}})),l){const g=y[y.length-1];m(g)&&f.push(Ge(g,!0))}}else for(const h of y)f.push(Ge(h,l));return{dataset:e.dataset,layers:f,coords:E.cartesian(),mapping:{x:s},scales:[]}},Rn=(e="auto")=>e==="auto"?Te.params.size:e,ne=e=>()=>{throw new Error(`Unsupported graph type: ${e}`)},si={line:(e,t)=>ei(e,t),areaStacked:(e,t)=>ti(e,t),bar:(e,t,n)=>J(e,"dodge",E.flip(),t,n),barStacked:(e,t,n)=>J(e,"stack",E.flip(),t,n),barStackedFill:(e,t,n)=>J(e,"fill",E.flip(),t,n),column:(e,t,n)=>J(e,"dodge",E.cartesian(),t,n),columnStacked:(e,t,n)=>J(e,"stack",E.cartesian(),t,n),columnStackedFill:(e,t,n)=>J(e,"fill",E.cartesian(),t,n),pie:e=>_t(e,"pie"),donut:e=>_t(e,"donut"),scatter:e=>ni(e),bubble:e=>ri(e),combo:(e,t)=>ai(e,t),funnel:ne("funnel"),heatmap:ne("heatmap"),waterfall:ne("waterfall"),mekko:ne("mekko"),table:ne("table")},ii=(e,t,n,r)=>si[t](e,n,r);function oi(e,t){const n=[];return n.push(Lt("x",e?.x)),n.push(Lt("y",e?.y)),n.push(z.color.palette({palette:t?.paletteId})),n}function Lt(e,t){return t?.scaleType==="logarithmic"||t?.isReversed||t?.min!==void 0||t?.max!==void 0?t.scaleType==="logarithmic"?z[e].log({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):z[e].continuous({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):z[e]()}function ci(e,t,n){const r=n.type??"column",a={dataset:e,axes:n.axes},s=ii(a,r,n.options??void 0,n.appearance??void 0);return{data:s.dataset,datasetMetadata:t,mapping:s.mapping,layers:s.layers,scales:[...oi(n.axes,n.appearance),...s.scales],transforms:[],coords:s.coords,config:Fs(n)}}const li={mode:"readonly",parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{isVisible:!0,title:null,subtitle:null,caption:null},appearance:{background:null}},ui={xLimits:null,yLimits:null},ze={theta:"x",startAngle:0,innerRadius:0};function di(e){const t=e??{type:"coord",coordType:"cartesian"},n=$t({},ui,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:n};case"polar":return{...t,params:{...n,theta:t.params?.theta??ze.theta,startAngle:t.params?.startAngle??ze.startAngle,innerRadius:t.params?.innerRadius??ze.innerRadius}}}}function pi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Te.stat,position:e.position??Te.position,yScaleType:e.yScaleType??Ce,params:ee.merge({},Te.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function mi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Be.stat,position:e.position??Be.position,yScaleType:e.yScaleType??Ce,params:ee.merge({},Be.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function fi(e){const t=ee.merge({},Ue.params,e.params);return t.missingValues==="gap"&&(t.missingValues="zero"),{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ue.stat,position:e.position??Ue.position,yScaleType:e.yScaleType??Ce,params:t,transforms:e.transforms??[],interactive:e.interactive??!0}}function yi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ye.stat,position:e.position??Ye.position,yScaleType:e.yScaleType??Ce,params:{...Ye.params,...e.params},transforms:e.transforms??[],interactive:e.interactive??!0}}function hi(e){switch(e.geom){case"point":return pi(e);case"line":return mi(e);case"area":return fi(e);case"bar":return yi(e)}}function gi(e){return e.map(hi)}function bi(e,...t){return e.find(n=>t.includes(n.geom))}const Nn={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range"},xi={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Fn(e,t,n,r){switch(e.scaleType){case"inferred":{const a=Si(e,t,n,r);return Fn(a,t,n,r)}case"continuous":{const a=Nn[e.scaledAesthetic],s=a==="continuous-range"&&e.scaledAesthetic in Tt?Tt[e.scaledAesthetic]:null,i=e.scaledAesthetic==="size"&&a==="continuous-range"?"sqrt":Q.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??i,reverse:e.reverse??Q.reverse,nice:e.nice??Q.nice,zero:e.zero??Q.zero,clamp:e.clamp??a!=="position",domainMin:e.domainMin??Q.domainMin,domainMax:e.domainMax??Q.domainMax,range:e.range??s??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??xe.domainMin,domainMax:e.domainMax??xe.domainMax,nice:e.nice??xe.nice,reverse:e.reverse??xe.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??re.range,sort:e.sort??re.sort,domain:e.domain??re.domain,padding:e.padding??re.padding};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:e.palette??Ka.palette};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const a=e;throw new Error(`Unknown scale type: ${a.scaleType}`)}}}function Mi(e,t,n,r){const a=Ai(t,n),s=wi(a),i=new Map;for(const o of s)i.set(o.scaledAesthetic,o);return[...i.values()].map(o=>Fn(o,e,n,r))}function Si(e,t,n,r){const a=U(e.scaledAesthetic),s=e.scaledAesthetic==="ySecondary"?Ti(n,r):r[a],i=bi(n,"bar");if(e.scaledAesthetic==="x"&&i)return R(e.scaledAesthetic,e.options);if(i&&e.scaledAesthetic===(i.yScaleType==="secondary"?"ySecondary":"y")){const d=e.options,y=i.position==="fill";return v(e.scaledAesthetic,{...d,zero:!0,...y&&{nice:!1}})}const o=M(s);if(!m(o)||!t.hasVariable(o))return v(e.scaledAesthetic,e.options);const c=t.getType(o),l=Nn[e.scaledAesthetic];switch(xi[c][l]){case"discrete":return R(e.scaledAesthetic,e.options);case"datetime":return Ae(e.scaledAesthetic,e.options);case"continuous":return v(e.scaledAesthetic,e.options);case"identity":default:return we(e.scaledAesthetic)}}function Ti(e,t){const n=e.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??t.y:t.y}function Ai(e,t){return!t.some(a=>a.yScaleType==="secondary")||e.some(a=>a.scaledAesthetic==="ySecondary")?e:[...e,ve("ySecondary")]}function wi(e){return e.some(n=>n.scaledAesthetic==="color")?e:[...e,Dn("color")]}function kt(e){const{data:t,mapping:n}=Vi(e.data,e.mapping),r=di(e.coords),a=gi(e.layers),s=Mi(t,e.scales,a,n);return{data:t,datasetMetadata:e.datasetMetadata,mapping:n,layers:a,scales:r.coordType==="polar"?vi(s):s,transforms:e.transforms,coords:r,config:ee.merge({},li,e.config)}}const vi=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t),Vi=(e,t)=>{let n=e,r=t;r.x===""&&(n=n.addConstantVariable(gt.x,"categorical",""),r={...r,x:gt.x});for(const a of Object.keys(r)){const s=Ir(r[a]);if(s===void 0)continue;const i=A(`const_${a}`);n=n.addConstantVariable(i,Ii(s),s),r={...r,[a]:i}}return{data:n,mapping:r}},Ii=e=>typeof e=="number"?"numeric":e instanceof Date?"temporal":"categorical";class On{compile(t){return le({input:t}).pipe(({input:r})=>Ei(r.data)).pipe(({input:r,dataset:a,datasetMetadata:s})=>({spec:this.resolveFromInput(r,a,s)})).result().spec}resolveFromInput(t,n,r){if(Ns(t)){const{data:a,...s}=t;return kt(ci(n,r,s))}return kt({...t,data:n,datasetMetadata:r})}}const Ei=e=>{const t=e._metadata?.parsingLocale??me;return Ln(e,t)};class _i{constructor(t){this.registry=t}compute(t,n){return this.registry.get(t).compute(n)}}class Pn{compute(t){return t.data.size()===0?{data:t.data,mapping:{}}:this.computeStat(t)}}class Li extends Pn{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=M(n.x);if(!m(r))throw new Error("'x' variable is required for 'count' stat");if(M(n.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const s=[...new Set([r,...qt(t,n)])];return{data:t.groupBy(...s).rollup({[Ke.count]:{variableName:r,aggregation:"count"}}),mapping:{y:Ke.count}}}}class ki extends Pn{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:t}){return{data:t,mapping:{}}}}class Di extends K{constructor(){super("stat"),this.register("identity",new ki),this.register("count",new Li)}}class Ci{constructor(t){this.registry=t}compile(t,n){return n.reduce((r,a)=>this.registry.get(a.transformType).apply(r,a),t)}}class Ri{constructor(){this.transformType="aggregate"}apply(t,n){const{options:r}=n,a={};for(const s of r.operations)a[s.as]={variableName:s.variableName,aggregation:s.op};return t.groupBy(...r.groupby).rollup(a)}}class Ni{constructor(){this.transformType="constant"}apply(t,n){const{options:r}=n;return t.addConstantVariable(r.variableName,r.type,r.value)}}class Fi{constructor(){this.transformType="filter"}apply(t,n){const{options:r}=n;return t.filter(r.variableName,r.operator,r.value)}}class Oi{constructor(){this.transformType="reshape"}apply(t,n){const{options:r}=n;return t.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}}class Pi{constructor(){this.transformType="sort"}apply(t,n){const{options:r}=n;return t.orderBy(r.variableName,r.direction??"asc")}}class Bi extends K{constructor(){super("transform"),this.register("aggregate",new Ri),this.register("constant",new Ni),this.register("filter",new Fi),this.register("reshape",new Oi),this.register("sort",new Pi)}}const Ui={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric"};class Yi{compile(t){return t.layers.map(n=>this.compileLayer(n,t.scales))}compileLayer(t,n){let r=t.data;const a=Object.entries(j);for(const[s,i]of a){const o=M(t.mapping[s]),c=n[s];if(!c||c.kind!=="visual")continue;const l=Gi(s,o,c);l&&(r=r.deriveVariable(i,Ui[s],l))}return{...t,data:r}}}const Gi=(e,t,n)=>{if(!t){if(e!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>m(r[t])?n.map(r[t]):null};class Bn{constructor(t,n,r,a,s,i,o,c){this.specCompiler=t,this.transformCompiler=n,this.layerCompiler=r,this.scaleCompiler=a,this.coordCompiler=s,this.positionMapperCompiler=i,this.visualMapperCompiler=o,this.guideCompiler=c}compile(t){const n=le({input:t}).pipe(({input:r})=>({spec:Rs(r)?r:this.specCompiler.compile(r)})).pipe(({spec:r})=>({spec:{...r,data:this.transformCompiler.compile(r.data,r.transforms)}})).pipe(({spec:r})=>({layers:this.layerCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping})})).pipe(({spec:r,layers:a})=>({scales:this.scaleCompiler.compile({layers:a,scales:r.scales})})).pipe(({spec:r})=>({coordSystem:this.coordCompiler.setup({coordSpec:r.coords})})).pipe(({layers:r,scales:a})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,scales:a,layers:s,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:a,config:r.config,layers:s,coordSystem:i,datasetMetadata:r.datasetMetadata})})).pipe(({layers:r,scales:a})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,layers:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,layers:a})})).result();return{...n,config:n.spec.config}}}const zi=e=>{const t=new dr,n=new Di,r=new Qa(t),a=new Cr,s=new Ci(new Bi);return t.register(Kt,[...Ht]),new Bn(new On,s,new Ia(s,new _i(n),new Rr,new vr(a),new _a(new Ra),new Ea(a,n)),new Ga(r),new pr(new wr),new Ya,new Yi,new Va).compile(e)};function $i(e,t){return e.geom===t}const nt="–",Wi="n/a",L={timeZone:"UTC"},I=e=>t=>{if(!Z(t))return nt;try{return e(t)}catch{return Wi}},Y=e=>t=>tn(t)?e(t):nt,Un=e=>t=>en(t)?t:nt,Hi=2,Ki=3,ji=2,qi=0,Xi=1,Qi=2,Ji=({valueFormat:e,locale:t,numberFormat:n,intlOptions:r})=>Y(a=>{const s=typeof n.decimals=="number"?n.decimals:Hi,i=rt(a,s),{base:o,suffix:c}=at(a,n.abbreviation),l={...i,...rn(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return`${Intl.NumberFormat(t,l).format(o)}${c}`}),Zi=({locale:e,numberFormat:t,intlOptions:n})=>Y(r=>{const{base:a,suffix:s}=at(r,t.abbreviation),o={...rt(a,t.decimals),...n};return`${Intl.NumberFormat(e,o).format(a)}${s}`}),Yn=e=>Y(t=>ro(t)),eo=({locale:e,intlOptions:t})=>Y(n=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(n)),to=({locale:e,numberFormat:t,intlOptions:n})=>Y(r=>{const a=rt(r,t.decimals);return Intl.NumberFormat(e,{...a,...n,style:"percent"}).format(r)}),rt=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const n=Math.ceil(Math.log10(Math.abs(e))),r=n>=Ki?qi:n===ji?Xi:Qi;return{minimumFractionDigits:t==="auto"?0:r,maximumFractionDigits:r}},no=e=>{const t=Math.abs(e);return t>=se.b?"b":t>=se.m?"m":t>=se.k?"k":"none"},at=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const n=no(e);return at(e,n)}default:return{base:e/se[t],suffix:t}}},ro=lr.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),ao=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{dateStyle:"medium",...L,...t}).format(n)),so=({locale:e,intlOptions:t})=>I(n=>{const r=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...L,...t}).formatToParts(n);return po(r.map(mo))}),io=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...L,...t}).format(n)),oo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"long",...L,...t}).format(n)),Gn=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...L,...t}).format(n)),zn=e=>I(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),co=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...L,...t,year:void 0}).formatRange(n,r)}),lo=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...L,...t}).formatRange(n,r)}),$n=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{year:"numeric",...L,...t}).format(n)),uo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...L,...t}).format(n)),po=e=>e.map(t=>t.value).join(""),mo=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},fo=1,yo=4,ho=1,go=({valueFormat:e,locale:t,tickValues:n,intlOptions:r})=>Y(a=>{const i={...it(a,n),notation:"compact",...rn(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return st(a,t,i)}),bo=({locale:e,tickValues:t,intlOptions:n})=>Y(r=>{const s={...it(r,t),notation:"compact",...n};return st(r,e,s)}),xo=({locale:e,tickValues:t,intlOptions:n})=>Y(r=>{const s={...it(r,t),notation:"compact",...n,style:"percent"};return st(r,e,s)}),st=(e,t,n)=>Intl.NumberFormat(t,n).formatToParts(e).map(a=>a.type==="compact"?a.value.toLowerCase():a.value).join(""),Dt=1e3,Wn=e=>Math.abs(e)>Dt?Wn(e/Dt):Number.isInteger(e),Mo=e=>{if(e.length<2)return!1;const[t,n]=e;return typeof t!="number"||typeof n!="number"?!1:Math.abs(n-t)<fo},it=(e,t)=>Wn(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Mo(t)?{minimumFractionDigits:0,maximumFractionDigits:yo}:{minimumFractionDigits:0,maximumFractionDigits:ho},So=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...L,...t}).format(n)),To=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",...L,...t}).format(n)),Ao=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...L,...t}).format(n)),wo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...L,...t}).format(n)),vo=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return go(e);case"date":case"datetime":return So(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Ao(e);case"decimal":case"integer":return bo(e);case"duration":return Yn();case"month":return To(e);case"month_year":return Gn(e);case"percentage":return xo(e);case"quarter":return zn();case"text":return Un();case"time":return wo(e);case"year":return $n(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},Vo=40,Io=60,Ct=8,Eo=50,_o=1/3,Lo=1/4,$e="…",ko=(e,t,n)=>{if(t<=0||e.length===0)return"";if(n(e)<=t)return e;if(n($e)>t)return"";let r=0,a=e.length-1,s=0;for(;r<=a;){const i=r+a>>>1,o=e.slice(0,i)+$e;n(o)<=t?(s=i,r=i+1):a=i-1}return e.slice(0,s)+$e},Do=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Co(e):Ro(e),Co=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=Hn(e.ticks,r),o=t-Ct;if(s<=o)return{...e,labelRotation:0,labelMaxWidthPx:null};if(t>=Eo){const l=Qe(o);return{...e,ticks:Xe(e.ticks,a,l,r),labelRotation:0,labelMaxWidthPx:l}}if(i+Ct>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=Qe(n.height*_o);return{...e,ticks:Xe(e.ticks,a,c,r),labelRotation:-90,labelMaxWidthPx:c}},Ro=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=Hn(e.ticks,r);if(i>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Qe(n.width*Lo);return s<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Xe(e.ticks,a,o,r),labelRotation:0,labelMaxWidthPx:o}},Hn=(e,t)=>{const n=[];let r=0,a=0;for(const s of e){const{width:i,height:o}=t(s.formattedLabel);n.push(i),i>r&&(r=i),o>a&&(a=o)}return{widths:n,maxWidth:r,maxHeight:a}},Xe=(e,t,n,r)=>{const a=s=>r(s).width;return e.map((s,i)=>(t[i]??0)<=n?s:{...s,formattedLabel:ko(s.formattedLabel,n,a)})},Qe=e=>Math.max(0,Math.floor(e)),No=(e,t,n,r)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",s=a?Io:Vo;let i=n-(e.length-1)*s;for(const o of e){const{width:c,height:l}=r(o);if(i-=a?c:l,i<0)return!1}return!0},Fo=({axis:e,availableSpacePx:t,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:a,position:s}=e;if(a.length===0)return[];const i=new Map,o=d=>{const y=i.get(d);if(y)return y;const f=a[d],h=f?Oo(f.ticks,r(f)):[];return i.set(d,h),h};let c=0,l=a.length-1,p=-1;for(;c<=l;){const d=c+l>>>1,f=o(d).map(h=>h.formattedLabel);No(f,s,t,n)?(p=d,c=d+1):l=d-1}return p>=0?o(p):o(0)},Oo=(e,t)=>e.map(n=>({...n,formattedLabel:t(n.value)})),Po=e=>{const t=e.padding??0,n=Rt(e.rows,t),r=Rt(e.cols,t);return{rows:n.tracks,cols:r.tracks,placements:Go(e.placements,n.nameToIndex,r.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Bo=e=>{const t=Nt(e.rows,e.height),n=Nt(e.cols,e.width),r=Ft(t),a=Ft(n),s=new Map;for(const i of e.placements){const o=i.rowSpan??1,c=i.colSpan??1,l=a[i.col]??0,p=r[i.row]??0,d=Ot(n,i.col,c),y=Ot(t,i.row,o);s.set(i.name,{x:l,y:p,width:Math.max(0,d),height:Math.max(0,y)})}return s},Rt=(e,t)=>{const n=[],r=new Map;t>0&&n.push({type:"fixed",pixels:t});for(let a=0;a<e.length;a++){const s=e[a];if(!s)continue;r.set(s.name,n.length),n.push(Uo(s));const i=Yo(e,a);if(Kn(s)&&i){const o=s.gaps?.after??0,c=i.gaps?.before??0,l=Math.max(o,c);l>0&&n.push({type:"fixed",pixels:l})}}return t>0&&n.push({type:"fixed",pixels:t}),{tracks:n,nameToIndex:r}},Uo=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Kn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Yo=(e,t)=>{for(let n=t+1;n<e.length;n++){const r=e[n];if(r&&Kn(r))return r}},Go=(e,t,n)=>{const r=[];for(const a of e){const s=t.get(a.row),i=n.get(a.col);if(s===void 0||i===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):s,c=a.colEnd!==void 0?n.get(a.colEnd):i;o===void 0||c===void 0||r.push({name:a.name,row:s,col:i,rowSpan:Math.max(1,o-s+1),colSpan:Math.max(1,c-i+1)})}return r},Nt=(e,t)=>{let n=0,r=0;for(const s of e)s.type==="fixed"?n+=s.pixels:r+=s.weight;const a=Math.max(0,t-n);return e.map(s=>s.type==="fixed"?s.pixels:r===0?0:s.weight/r*a)},Ft=e=>{const t=new Array(e.length);let n=0;for(let r=0;r<e.length;r++)t[r]=n,n+=e[r]??0;return t},Ot=(e,t,n)=>{let r=0;const a=Math.min(t+n,e.length);for(let s=t;s<a;s++)r+=e[s]??0;return r},zo=["top","right","bottom","left"],We=(e,t)=>{const n={};for(const r of zo){const a=e.get(`${r}${t}`);a&&(n[r]=a)}return n},jn=24,N={header:{after:10,before:0},topLegend:{after:16,before:0},topAxisLabel:{after:4,before:0},topAxis:{after:0,before:0},panel:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},Me={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},panel:{after:4,before:0},rightAxis:{after:10,before:0}},$o=(e,t,n)=>{const a=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return Po({rows:[{name:"header",size:t.headerSize.height,gaps:N.header},{name:"topLegend",size:n.legends.top,gaps:N.topLegend},{name:"topAxisLabel",size:a,gaps:N.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:N.topAxis},{name:"panel",size:{flex:1},gaps:N.panel},{name:"bottomAxis",size:n.axes.bottom,gaps:N.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:N.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:N.bottomLegend},{name:"footer",size:t.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:Me.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:Me.leftAxis},{name:"panel",size:{flex:1},gaps:Me.panel},{name:"rightAxis",size:n.axes.right,gaps:Me.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panel",row:"panel",col:"panel"},...Wo(n.axes),...Ho(n.axesLabels,n.axes),...Ko(n.legends)],containerSize:e,padding:jn})},Wo=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Ho=(e,t)=>{const n=[];return e.top>0||t.top>0?(e.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},Ko=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t},Se={x:0,y:0,width:0,height:0},jo="0000";class qo{constructor(t){this.measurer=t}compile(t){return le({compiled:t.compiled,formattedLegends:t.formattedLegends,containerSize:t.containerSize,externalMeasurements:t.externalMeasurements,locale:t.formattingLocale??t.compiled.config.parsingLocale}).pipe(({compiled:n,locale:r})=>({axisBundles:n.guides.axes.map(a=>({axis:a,resolveFormatter:Xo(a,r,n.config),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({axisBundles:n.map(a=>Pt(a.axis.position)?{...a,formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel)}:a)})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({formattedAxes:n.map(a=>Pt(a.axis.position)?a.formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel))})).pipe(({formattedAxes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})})).result()}seedAxis(t){const{tickCandidates:n,...r}=t;return{...r,ticks:[{value:0,position:0,formattedLabel:jo}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(t,n,r){const s=t.position==="top"||t.position==="bottom"?r.width:r.height,i=Fo({axis:t,availableSpacePx:s,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:o,...c}=t,l={...c,ticks:i,labelRotation:0,labelMaxWidthPx:null};if(t.scaleType==="discrete"&&t.bandwidth!==void 0){const p=t.bandwidth*s;return Do({formattedAxis:l,bandwidthPx:p,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:t,formattedLegends:n,containerSize:r,externalMeasurements:a}){const s=this.measureGuides(t,n),i=$o(r,a,s),o=Bo(i);return{header:o.get("header")??Se,footer:o.get("footer")??Se,plot:o.get("plot")??Se,panel:o.get("panel")??Se,axes:We(o,"Axis"),axisLabels:We(o,"AxisLabel"),legends:We(o,"Legend")}}measureGuides(t,n){const r={top:0,right:0,bottom:0,left:0},a={top:0,right:0,bottom:0,left:0};for(const i of t)i.isVisible&&(r[i.position]=this.measurer.measureAxis(i),i.label!==null&&(a[i.position]=this.measurer.measureAxisLabel()));const s={top:0,right:0,bottom:0,left:0};for(const i of n)s[i.position]=this.measurer.measureLegend(i);return{axes:r,axesLabels:a,legends:s}}}const Pt=e=>e==="left"||e==="right",Xo=(e,t,n)=>{const r=e.tickCandidates.flatMap(s=>s.ticks.map(i=>i.value)),a=new WeakMap;return s=>{const i=a.get(s);if(i)return i;const o=vo({valueFormat:s.valueFormat??e.valueFormat,locale:t,numberFormat:n.numberFormat,tickValues:r});return a.set(s,o),o}};function ce(e,t){return e==="x"?t.x:t.y}function Re(e,t){return e==="x"?t.y:t.x}function Qo(e,t){return{main:ce(e,t),cross:Re(e,t)}}function Jo(e){return e.type==="cartesian"}const Ne=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ji(e);case"date":return ao(e);case"datetime":return so(e);case"day_month":return io(e);case"decimal":return Zi(e);case"duration":return Yn();case"integer":return eo(e);case"month":return oo(e);case"month_year":return Gn(e);case"percentage":return to(e);case"quarter":return zn();case"text":return Un();case"weekly_date_range":return co(e);case"weekly_date_range_with_year":return lo(e);case"year":return $n(e);case"time":return uo(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},Zo=(e,{formattingLocale:t}={})=>{const n=t??e.config.parsingLocale,r=e.config.numberFormat;return e.guides.legends.map(a=>ec(a,n,r))},ec=(e,t,n)=>{const r=Ne({valueFormat:e.valueFormat,locale:t,numberFormat:n});return{...e,items:e.items.map(a=>({...a,formattedLabel:r(a.value)}))}};function H(e){return e==="stack"||e==="fill"}function qn(e,t){return ot(e.buckets,t,n=>n.main)}function tc(e,t){return ot(e.bands,t,n=>n.bandCenter)}function nc(e,t){return ot(e.columns,t,n=>n.mainMid)}function ot(e,t,n){if(e.length===0)return null;let r=0,a=e.length;for(;r<a;){const o=r+a>>>1,c=e[o];c&&n(c)<t?r=o+1:a=o}const s=e[r-1],i=e[r];return s?i&&Math.abs(n(i)-t)<Math.abs(n(s)-t)?i:s:i??null}function ct(e,t,n){return Math.hypot(e*n,t)}function rc(e,t,n,r){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const s=a.find(t.x*n,t.y,r??void 0),i=e.points[s];return i?{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:ct(i.x-t.x,i.y-t.y,n)}:null}function ac(e,t){if(e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const n=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[n]??null}function sc(e,t){return{group:ic(e),related:uc(e,t)}}function ic(e){switch(e.kind){case"buckets":{const t=e.match.index;return H(t.position)?oc(t,e.match):[]}case"rects":{const t=e.match.index;return H(t.position)?cc(t,e.match):lc(t,e.match)}case"points":case"arcs":return[]}}function oc(e,t){const n=[];for(const r of t.bucket.entries)r.pointIndex!==t.hit.pointIndex&&n.push({layerId:e.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return n}function cc(e,t){const n=[];for(const r of t.column.rects)r.pointIndex!==t.hit.pointIndex&&n.push(lt(e,r));return n}function lc(e,t){const n=e.bands.find(a=>a.columns.includes(t.column));if(!n)return[];const r=[];for(const a of n.columns)for(const s of a.rects)s.pointIndex!==t.hit.pointIndex&&r.push(lt(e,s));return r}function uc(e,t){const n=new Map;if(e.kind==="arcs")return n;for(const r of t){if(r.layerId!==e.match.index.layerId){pc(n,r,e.match.hit);continue}e.kind==="buckets"&&(H(r.position)||r.kind==="buckets"&&dc(n,r,e.match))}return n}function dc(e,t,n){for(const r of n.bucket.entries){if(r.pointIndex===n.hit.pointIndex)continue;Ve(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation})}}function pc(e,t,n){switch(t.kind){case"buckets":{const r=qn(t,ce(t.mainAxis,n));if(!r)return;const a=Ve(e,t.layerId);for(const s of r.entries)a.push({layerId:t.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation});return}case"rects":{const r=tc(t,ce(t.mainAxis,n));if(!r)return;const a=Ve(e,t.layerId);for(const s of r.columns)for(const i of s.rects)a.push(lt(t,i));return}case"points":{const r=ac(t,n);if(!r)return;Ve(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return}case"arcs":return}}function Ve(e,t){let n=e.get(t);return n||(n=[],e.set(t,n)),n}function lt(e,t){return{layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function mc(e){const t=fc(e);return{kind:"arcs",layerId:e.id,geom:e.geom,position:e.position,arcs:t}}function fc(e){const t=e.data;if(t.size()===0)return[];const n=[u.xMin,u.xMax,u.yMin,u.yMax];for(const l of n)if(!t.hasVariable(l))return[];const r=t.getValues(u.xMin,{type:"numeric"}),a=t.getValues(u.xMax,{type:"numeric"}),s=t.getValues(u.yMin,{type:"numeric"}),i=t.getValues(u.yMax,{type:"numeric"}),o=[];let c=0;for(const l of t){const p=r[c],d=a[c],y=s[c],f=i[c];if(!m(p)||!m(d)||!m(y)||!m(f)){c++;continue}o.push({pointIndex:c,startAngle:p,endAngle:d,innerRadius:y,outerRadius:f,observation:l}),c++}return o}const yc=1e-9;function hc(e,t){const n=gc(e,t);n.sort((a,s)=>a.main-s.main);const r=[];for(const a of n){const s=r[r.length-1];s&&Math.abs(s.main-a.main)<=yc?s.entries.push(a.entry):r.push({main:a.main,entries:[a.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,buckets:r}}function gc(e,t){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(u.x),s=n.hasVariable(u.y);if(!a||!s)return[];const i=n.getValues(u.x,{type:"numeric"}),o=n.getValues(u.y,{type:"numeric"}),c=t==="y",l=c?u.xMin:u.yMin,p=c?u.xMax:u.yMax,d=H(e.position),y=d?n.getValues(l,{type:"numeric"}):null,f=d?n.getValues(p,{type:"numeric"}):null,h=n.hasVariable(V.group)?n.getValues(V.group,{type:"categorical"}):null,b=[];let g=0;for(const x of n){const S=i[g],k=o[g];if(!m(S)||!m(k)){g+=1;continue}const D=h?.[g]??null,ge=c?k:S;if(d){const ht=y?.[g],be=f?.[g];if(!m(ht)||!m(be)){g+=1;continue}const ir=c?be:S,or=c?k:be;b.push({main:ge,entry:{isStacked:d,pointIndex:g,x:ir,y:or,stackMin:ht,stackMax:be,groupKey:D,observation:x}})}else b.push({main:ge,entry:{isStacked:d,pointIndex:g,x:S,y:k,groupKey:D,observation:x}});g+=1}return b}function bc(e,t){const n={kind:"points",layerId:e.id,geom:e.geom,position:e.position,points:xc(e),delaunay:null,delaunayAspectRatio:null};return Xn(n,t),n}function Xn(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=ur.Delaunay.from(e.points,n=>n.x*t,n=>n.y),e.delaunayAspectRatio=t)}function xc(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(u.x)||!t.hasVariable(u.y))return[];const n=t.getValues(u.x,{type:"numeric"}),r=t.getValues(u.y,{type:"numeric"}),a=[];let s=0;for(const i of t){const o=n[s],c=r[s];s+=1,!(!m(o)||!m(c))&&a.push({pointIndex:a.length,x:o,y:c,observation:i})}return a}const Mc=1e6;function Sc(e,t){const n=Tc(e,t);n.sort((o,c)=>o.mainMid-c.mainMid);const r=new Map,a=new Map;for(const o of n){const c=Bt(o.mainMid);let l=r.get(c);if(!l){l={mainMid:o.mainMid,columnKey:c,rects:[]},r.set(c,l);const p=Bt(o.bandCenter);let d=a.get(p);d||(d={bandCenter:o.bandCenter,bandKey:p,columns:[]},a.set(p,d)),d.columns.push(l)}l.rects.push(o.entry)}const s=[...r.values()].sort((o,c)=>o.mainMid-c.mainMid),i=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of i)o.columns.sort((c,l)=>c.mainMid-l.mainMid);return{kind:"rects",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,columns:s,bands:i}}function Bt(e){return String(Math.round(e*Mc))}function Tc(e,t){const n=e.data;if(n.size()===0)return[];if(!(n.hasVariable(u.xMin)&&n.hasVariable(u.xMax)&&n.hasVariable(u.yMin)&&n.hasVariable(u.yMax)))return[];const a=n.getValues(u.xMin,{type:"numeric"}),s=n.getValues(u.xMax,{type:"numeric"}),i=n.getValues(u.yMin,{type:"numeric"}),o=n.getValues(u.yMax,{type:"numeric"}),c=t==="y",l=c?u.y:u.x,p=n.hasVariable(l)?n.getValues(l,{type:"numeric"}):null,d=n.hasVariable(V.group)?n.getValues(V.group,{type:"categorical"}):null,y=[];let f=0;for(const h of n){const b=a[f],g=s[f],x=i[f],S=o[f];if(!m(b)||!m(g)||!m(x)||!m(S)){f++;continue}const k=c?(x+S)/2:(b+g)/2,D=p?.[f]??k;y.push({mainMid:k,bandCenter:D,entry:{pointIndex:f,xMin:b,xMax:g,yMin:x,yMax:S,segmentKey:d?.[f]??null,observation:h}}),f++}return y}function Ut(e,t,n){if(t.type==="polar")return mc(e);switch(e.geom){case"point":return bc(e,n);case"line":case"area":return hc(e,t.mainAxis);case"bar":return Sc(e,t.mainAxis);default:{const r=e.geom;throw new Error(`buildLayerIndex: unhandled geom ${String(r)}`)}}}const C=Math.PI*2,Ac=1e-9;function wc(e,t,n){if(e.arcs.length===0)return null;const{angle:r,radius:a}=vc(t,n);for(const s of e.arcs)if(!(a<s.innerRadius||a>s.outerRadius)&&Vc(r,s))return{hit:{layerId:e.layerId,pointIndex:s.pointIndex,x:(s.startAngle+s.endAngle)/2,y:(s.innerRadius+s.outerRadius)/2,observation:s.observation},index:e};return null}function vc(e,t){const n=e.x-.5,r=e.y-.5,a=t>=1?n*2*t:n*2,s=t>=1?r*2:r*2/t,i=Math.hypot(a,s);return{angle:(Math.atan2(a,s)%C+C)%C,radius:i}}function Vc(e,t){const n=t.endAngle-t.startAngle;if(Math.abs(n)>=C-Ac)return!0;const r=(n%C+C)%C;return((e-t.startAngle)%C+C)%C<=r}function Ic(e,t,n){if(e.buckets.length===0)return null;const{main:r,cross:a}=Qo(e.mainAxis,t),s=qn(e,r),i=s?.entries??[];if(!s||!Wt(i))return null;const o=H(e.position)?Dc(i,a):kc(i,a,e.mainAxis);return{hit:{layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:s,distance:ct(o.x-t.x,o.y-t.y,n)}}function Ec(e,t,n){if(e.columns.length===0)return null;const r=ce(e.mainAxis,t),a=nc(e,r),s=a?.rects??[];if(!a||!Wt(s))return null;const i=H(e.position)?_c(s,t,e.mainAxis):Lc(s,t,n);return{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:a,distance:Qn(i,t,n)}}function _c(e,t,n){const r=Re(n,t);return Fe(e,s=>Rc(s,n,r),{shortCircuitOnZero:!0})}function Lc(e,t,n){return Fe(e,a=>Qn(a,t,n))}function kc(e,t,n){return Fe(e,a=>Math.abs(Re(n,a)-t))}function Dc(e,t){const n=Cc(e);return Fe(n,a=>Nc(a,t),{shortCircuitOnZero:!0})}function Cc(e){for(const t of e)if(!t.isStacked)throw new Error("pickStackedBucketEntry: expected stacked entries in a stacked bucket index");return e}function Fe(e,t,{shortCircuitOnZero:n=!1}={}){let r=e[0],a=t(r);if(n&&a===0)return r;for(let s=1;s<e.length;s+=1){const i=e[s];if(i===void 0)continue;const o=t(i);if(n&&o===0)return i;o<a&&(r=i,a=o)}return r}function Qn(e,t,n){const r=_e(t.x,e.xMin,e.xMax),a=_e(t.y,e.yMin,e.yMax);return ct(r,a,n)}function Rc(e,t,n){const r=t==="x"?e.yMin:e.xMin,a=t==="x"?e.yMax:e.xMax;return _e(n,r,a)}function Nc(e,t){return _e(t,e.stackMin,e.stackMax)}function _e(e,t,n){return e<t?t-e:e>n?e-n:0}const Fc=.05;function Oc({layers:e,cursor:t,aspectRatio:n,warmStarts:r}){const a={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const i of e){if(i.kind==="arcs"){const c=wc(i,t,n);return c?{kind:"arcs",match:c}:null}const o=Bc({layer:i,cursor:t,aspectRatio:n,warmStarts:r});if(o){if(o.kind==="rects"){o.match.distance<a.distance&&(a.match=o,a.distance=o.match.distance);continue}o.match.distance<s.distance&&(s.match=o,s.distance=o.match.distance)}}return Pc({rect:a,continuous:s})}function Pc({rect:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+Fc?t.match:e.match:e.match??t.match}function Bc({layer:e,cursor:t,aspectRatio:n,warmStarts:r}){switch(e.kind){case"buckets":{const a=Ic(e,t,n);return a?{kind:"buckets",match:a}:null}case"rects":{const a=Ec(e,t,n);return a?{kind:"rects",match:a}:null}case"points":{const a=r.get(e.layerId)??null,s=rc(e,t,n,a);return s?{kind:"points",match:s}:null}}}const Uc=1,ae={primary:null,group:[],related:new Map};class Yc{constructor(t){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=Uc,this.warmStarts=new Map,this.cachedState=ae,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.layerIndexes=t.layers.map(n=>Ut(n,t.coordSystem,this.aspectRatio)),this.layerRefs=t.layers.map(n=>Yt(n,t.coordSystem)),this.nonInteractiveLayerIds=Gt(t.layers)}update(t){const n=new Map;for(let s=0;s<this.layerIndexes.length;s+=1){const i=this.layerIndexes[s],o=this.layerRefs[s];!i||!o||n.set(i.layerId,{index:i,ref:o})}const r=[],a=[];for(const s of t.layers){const i=n.get(s.id),o=Yt(s,t.coordSystem);if(i!==void 0&&Gc(i.ref,o)){r.push(i.index),a.push(i.ref);continue}this.warmStarts.delete(s.id),r.push(Ut(s,t.coordSystem,this.aspectRatio)),a.push(o)}for(const s of this.warmStarts.keys())t.layers.some(i=>i.id===s)||this.warmStarts.delete(s);this.layerIndexes=r,this.layerRefs=a,this.nonInteractiveLayerIds=Gt(t.layers),this.invalidateCache()}setViewport(t){this.aspectRatio=t.width/t.height;for(const n of this.layerIndexes)n.kind==="points"&&Xn(n,this.aspectRatio)}query(t){if(this.layerIndexes.length===0)return ae;const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(c=>!this.nonInteractiveLayerIds.has(c.layerId)),r=Oc({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,cursor:t});if(!r)return this.invalidateCache(),ae;const a=r.match.hit;this.warmStarts.set(a.layerId,a.pointIndex);const s=`${a.layerId}:${a.pointIndex}`;if(this.cachedKey===s)return this.cachedState;const{group:i,related:o}=sc(r,n);return this.cachedKey=s,this.cachedState={primary:a,group:i,related:o},this.cachedState}invalidateCache(){this.cachedKey=null,this.cachedState=ae}}function Yt(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Gt(e){const t=new Set;for(const n of e)n.interactive||t.add(n.id);return t}function Gc(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}const G=(e,t,n)=>{const r=M(t[n]);return a=>{if(!m(r))return null;const s=a[r];if(s===void 0)return null;switch(e.getType(r)){case"numeric":return tn(s)?s:null;case"categorical":return en(s)?s:null;case"temporal":return Z(s)?s:null;default:return null}}},zc=(e,t)=>G(e,t,"x"),Jn=(e,t)=>G(e,t,"y"),$c=(e,t)=>G(e,t,"label"),Zn=(e,t)=>G(e,t,"color"),Wc=(e,t)=>G(e,t,"size"),Hc=(e,t)=>G(e,t,"alpha"),Kc=(e,t)=>G(e,t,"group"),jc=(e,t)=>G(e,t,"strokeWidth");function er(e){return e[j.color]}function qc(e){return e[j.alpha]}function Xc(e){return e[j.size]}function Qc(e){return e[j.strokeWidth]}function ut(e,t){return e.axes.find(n=>n.scaleAestheticKey===t)??null}function Jc(e,t){return e.legends.find(n=>n.aesthetics.includes(t))??null}const Zc=({compiled:e,hover:t,formattingLocale:n})=>{const{primary:r}=t;if(r===null)return null;const a=n??e.config.parsingLocale;return{header:el({compiled:e,primary:r,locale:a,numberFormat:e.config.numberFormat}),rows:tl({compiled:e,hover:t,locale:a,numberFormat:e.config.numberFormat})}};function el({compiled:e,primary:t,locale:n,numberFormat:r}){if(e.coordSystem.type!=="cartesian")return null;const a=e.coordSystem.mainAxis,s=ut(e.guides,a);if(!s)return null;const i=e.layers.find(p=>p.id===t.layerId);if(!i)return null;const o=M(i.mapping[a]);if(!m(o))return null;const c=t.observation[o];return m(c)?Ne({valueFormat:s.valueFormat,locale:n,numberFormat:r})(c):null}function tl({compiled:e,hover:t,locale:n,numberFormat:r}){const a=[],s=e.scales.color??null,i=sl({compiled:e,locale:n,numberFormat:r});for(const o of e.layers){const c=nl(o,t);if(c.length===0)continue;const l=Zn(o.data,o.mapping),p=rl(c,o,s,l),d=al({compiled:e,layer:o,locale:n,numberFormat:r}),y=il(e,o),f=Jn(o.data,o.mapping),h=o.mapping.color!==void 0,b=ol(o,e.coordSystem);for(const g of p){const x=h?l(g.observation):null,S=er(g.observation)??null,k=h&&x!==null?i(x):y,D=f(g.observation),ge=D===null?"":d(D);a.push({swatchColor:S,swatchShape:b,label:k,value:ge,isPrimary:g===t.primary,key:`${g.layerId}:${g.pointIndex}`})}}return a}function nl(e,t){const n=[];return t.primary!==null&&t.primary.layerId===e.id&&n.push(t.primary,...t.group),n.push(...t.related.get(e.id)??[]),n}function rl(e,t,n,r){if(n===null||t.mapping.color===void 0)return e;const a=new Map;return n.domain.forEach((s,i)=>{a.set($(s),i)}),e.map((s,i)=>{const o=r(s.observation),c=o===null?null:$(o),l=c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY;return{hit:s,originalIndex:i,rank:l}}).sort((s,i)=>s.rank===i.rank?s.originalIndex-i.originalIndex:s.rank-i.rank).map(s=>s.hit)}function al({compiled:e,layer:t,locale:n,numberFormat:r}){const a=ue(t.yScaleType),i=ut(e.guides,a)?.valueFormat??{type:"decimal"};return Ne({valueFormat:i,locale:n,numberFormat:r})}function sl({compiled:e,locale:t,numberFormat:n}){const a=Jc(e.guides,"color")?.valueFormat??{type:"text"};return Ne({valueFormat:a,locale:t,numberFormat:n})}function il(e,t){const n=ue(t.yScaleType);return ut(e.guides,n)?.label??""}function ol(e,t){switch(e.geom){case"bar":return t.type==="polar"?"slice":"square";case"line":return"line";case"area":return"area";case"point":return"circle";default:return"square"}}function cl(e){return{startAngle:e[u.xMin],endAngle:e[u.xMax]}}function ll(e){return{innerRadius:e[u.yMin],outerRadius:e[u.yMax]??e[u.y]}}function ul(e){return typeof e=="object"&&e!==null&&"type"in e}function dl(e,...t){let n={},r;const[a,...s]=t;m(a)&&!ul(a)?(n=a,r=s):r=t;const i={data:e,mapping:n,layers:[],scales:[],transforms:[],config:{}};return r.reduce((o,c)=>tr(o,c),i)}function pl(e,...t){return t.reduce((n,r)=>tr(n,r),e)}function tr(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:$t({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};default:{const n=t;throw new Error(`Unknown spec item type: ${n.type}`)}}}class ml{constructor(t={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.maxHistorySize=t.maxHistorySize??100}apply(t,n){return this.withReentrancyGuard(()=>{const r=t.apply(n);return r?(this.undoStack.push({command:t,revert:r.revert}),this.redoStack=[],this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.emit({type:"apply",command:t,spec:r.spec}),r.spec):n})}undo(t){return this.withReentrancyGuard(()=>{const n=this.undoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.redoStack.push({command:n.command,revert:r.revert}),this.emit({type:"undo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.undoStack.push(n),null)})}redo(t){return this.withReentrancyGuard(()=>{const n=this.redoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.undoStack.push({command:n.command,revert:r.revert}),this.emit({type:"redo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.redoStack.push(n),null)})}clear(){this.withReentrancyGuard(()=>{this.undoStack=[],this.redoStack=[],this.emit({type:"clear"})})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null}),this.cachedSnapshot}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}withReentrancyGuard(t){if(this.isEmitting)throw new Error("CommandStack: cannot call apply/undo/redo/clear from within a listener");this.isEmitting=!0;try{return t()}finally{this.isEmitting=!1}}emit(t){this.cachedSnapshot=null;for(const n of this.listeners)try{n(t)}catch(r){console.error("CommandStack listener error:",r)}}}function ye(e,t){return Object.entries(t).reduce((n,[r,a])=>{const s=e[r];return zt(a)&&zt(s)?n[r]=ye(s,a):a!==void 0&&(n[r]=a),n},{...e})}function zt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function he(e){return{id:e.id??crypto.randomUUID(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}class dt{constructor(t,n={}){this.type="set-appearance-background",this.params=t,this.metadata=he({...n,description:`Set background to ${t.background??"(none)"}`})}apply(t){const n=t.config.appearance.background,r=ye(t,{config:{appearance:{background:this.params.background}}}),a=new dt({background:n},this.metadata);return{spec:r,revert:a}}}class pt{constructor(t,n={}){this.type="set-content-visibility",this.params=t,this.metadata=he({...n,description:`Set content visibility to ${t.isVisible}`})}apply(t){const n=t.config.content.isVisible,r=ye(t,{config:{content:{isVisible:this.params.isVisible}}}),a=new pt({isVisible:n},this.metadata);return{spec:r,revert:a}}}class mt{constructor(t,n={}){this.type="set-grid-visibility",this.params=t,this.metadata=he({...n,description:`Set grid visibility to x=${t.xIsVisible}, y=${t.yIsVisible}`})}apply(t){const n=t.config.axes.x.grid.isVisible,r=t.config.axes.y.grid.isVisible,a=ye(t,{config:{axes:{x:{grid:{isVisible:this.params.xIsVisible}},y:{grid:{isVisible:this.params.yIsVisible}}}}}),s=new mt({xIsVisible:n,yIsVisible:r},this.metadata);return{spec:a,revert:s}}}class ft{constructor(t,n={}){this.type="set-legend-position",this.params=t,this.metadata=he({...n,description:`Set legend position to ${t.position}`})}apply(t){const n=t.config.legend.position,r=ye(t,{config:{legend:{position:this.params.position}}}),a=new ft({position:n},this.metadata);return{spec:r,revert:a}}}class yt{constructor(t,n={}){this.type="set-data",this.params=t,this.metadata=he({...n,description:"Set dataset"})}apply(t){const n=t.data,r=fl(this.params.data),a={...t,data:r},s=new yt({data:n},this.metadata);return{spec:a,revert:s}}}const fl=e=>{if(e instanceof w)return e;const t=e._metadata?.parsingLocale??me;return Ln(e,t).dataset},nr=500,rr="normal",ar={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},sr=e=>typeof e!="string"?e??nr:ar[e],yl="\0";class hl{constructor(t){this.inner=t,this.cache=new Map}measureText(t,n){const r=this.getCacheKey(t,n),a=this.cache.get(r);if(a)return a;const s=this.inner.measureText(t,n);return this.cache.set(r,s),s}getCacheKey(t,n){return[n.family,n.size,sr(n.weight),n.style??rr,t].join(yl)}}const gl={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56},bl=.55,xl=1.05,Ml=.84,Sl=.21;class Tl{measureText(t,n){let r=0;for(const o of t)r+=(gl[o]??bl)*n.size;sr(n.weight)>=ar.semiBold&&(r*=xl);const s=Ml*n.size,i=Sl*n.size;return{width:r,height:s+i,ascent:s,descent:i}}}exports.CachedTextMeasurer=hl;exports.CommandStackManager=ml;exports.Compiler=Bn;exports.DEFAULT_COLOR_PALETTE=Ht;exports.DEFAULT_FONT_STYLE=rr;exports.DEFAULT_FONT_WEIGHT=nr;exports.DEFAULT_LOCALE=me;exports.DEFAULT_PALETTE_NAME=Kt;exports.Dataset=w;exports.GROUP_VARIABLES=V;exports.HeuristicTextMeasurer=Tl;exports.HoverEngine=Yc;exports.LAYOUT_PADDING=jn;exports.LayoutCompiler=qo;exports.POSITION_VARIABLES=u;exports.RESTING_HOVER_STATE=ae;exports.SetAppearanceBackgroundCommand=dt;exports.SetContentVisibilityCommand=pt;exports.SetDataCommand=yt;exports.SetGridVisibilityCommand=mt;exports.SetLegendPositionCommand=ft;exports.SpecResolver=On;exports.VISUAL_VARIABLES=j;exports.buildTooltipContent=Zc;exports.compile=zi;exports.config=kn;exports.coord=E;exports.createAlphaValueReader=Hc;exports.createColorValueReader=Zn;exports.createGroupValueReader=Kc;exports.createLabelValueReader=$c;exports.createSizeValueReader=Wc;exports.createSpec=dl;exports.createStrokeWidthValueReader=jc;exports.createXValueReader=zc;exports.createYValueReader=Jn;exports.formatLegends=Zo;exports.geom=_;exports.getAlpha=qc;exports.getAngleExtent=cl;exports.getColor=er;exports.getCrossAxisCoordinate=Re;exports.getGroup=cn;exports.getMainAxisCoordinate=ce;exports.getRadiusExtent=ll;exports.getSize=Xc;exports.getStrokeWidth=Qc;exports.getX=ia;exports.getXMax=ca;exports.getXMin=oa;exports.getY=je;exports.getYMax=qe;exports.getYMin=ln;exports.isCartesian=Jo;exports.isDefined=m;exports.isLayerOf=$i;exports.isStackedPosition=H;exports.mapping=Vr;exports.pipe=pl;exports.prefixInternalVariable=A;exports.scale=z;exports.transform=ie;
3
+ ${r}`),this.issues=e,this.name="SpecValidationError"}}class Or{constructor(e){this.statRegistry=e.statRegistry,this.scaleRegistry=e.scaleRegistry,this.geomRegistry=e.geomRegistry}validate(e){const r=[];for(const n of e.layers){const i={...e.mapping,...n.mapping};r.push(...this.validateRequiredAesthetics(i,n.id,n.geom,n.stat)),r.push(...this.validateVariableExistence(e,i,n.id,n.stat))}if(r.push(...this.validateScaleTypeCompatibility(e)),r.length>0)throw new Dr(r);return e}validateRequiredAesthetics(e,r,n,i){const a=[],{requiredAesthetics:s}=this.geomRegistry.get(n),{computedVariables:o}=this.statRegistry.get(i);for(const c of s)o.has(c)||e[c]==null&&a.push({code:"MISSING_AESTHETIC",message:`Layer '${r}': geom '${n}' requires aesthetic '${c}'`,layerId:r,aesthetic:c});return a}validateVariableExistence(e,r,n,i){const a=[],{computedVariables:s}=this.statRegistry.get(i);for(const[o,c]of Object.entries(r)){if(s.has(o))continue;const u=h(c);u!==null&&(e.data.hasVariable(u)||a.push({code:"UNKNOWN_VARIABLE",message:`Layer '${n}': aesthetic '${o}' references variable '${u}' which does not exist in the dataset`,layerId:n,aesthetic:o}))}return a}validateScaleTypeCompatibility(e){const r=[];for(const n of e.scales){const{compatibleDataTypes:i}=this.scaleRegistry.get(n.scaleType),a=_(n.scaledAesthetic),s=Nr(e,a);if(s===null||!e.data.hasVariable(s))continue;const o=e.data.getType(s);i.includes(o)||r.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${n.scaledAesthetic}' (${n.scaleType}) is incompatible with variable '${s}' (${o})`,aesthetic:a})}return r}}function Nr(t,e){for(const r of t.layers){const n=r.mapping[e];if(y(n))return h(n)}return h(t.mapping[e])}const Pr={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric"};class kr{compile(e){return e.layers.map(r=>this.compileLayer(r,e.scales))}compileLayer(e,r){let n=e.data;const i=Object.entries(R);for(const[a,s]of i){const o=h(e.mapping[a]),c=r[a];!o||!c||c.kind!=="visual"||(n=n.deriveVariable(s,Pr[a],u=>y(u[o])?c.map(u[o]):null))}return{...e,data:n}}}class De{constructor(e,r,n,i,a,s,o,c){this.specValidator=e,this.transformCompiler=r,this.layerCompiler=n,this.scaleCompiler=i,this.coordCompiler=a,this.positionMapperCompiler=s,this.visualMapperCompiler=o,this.guideCompiler=c}compile(e){const r=K({input:e}).pipe(({input:n})=>({spec:at(n)})).pipe(({spec:n})=>({spec:this.specValidator.validate(n)})).pipe(({spec:n})=>({spec:{...n,data:this.transformCompiler.compile(n.data,e.transforms)}})).pipe(({spec:n})=>({layers:this.layerCompiler.compile({data:n.data,layers:n.layers,mapping:n.mapping})})).pipe(({spec:n,layers:i})=>({scales:this.scaleCompiler.compile({layers:i,scales:n.scales})})).pipe(({spec:n})=>({coordSystem:this.coordCompiler.setup({coordSpec:n.coords})})).pipe(({layers:n,scales:i})=>({layers:this.positionMapperCompiler.compile({layers:n,scales:i})})).pipe(({spec:n,scales:i,layers:a,coordSystem:s})=>({guides:this.guideCompiler.compile({scales:i,config:n.config,layers:a,coordSystem:s})})).pipe(({layers:n,scales:i})=>({layers:this.visualMapperCompiler.compile({layers:n,scales:i})})).pipe(({spec:n,layers:i})=>({layers:this.coordCompiler.transform({coordSpec:n.coords,layers:i})})).result();return{...r,config:r.spec.config}}}const Fr=t=>{const e=new ct,r=new vr,n=new Ar(e),i=new vt;return e.register(xe,[...be]),new De(new Or({statRegistry:r,scaleRegistry:n,geomRegistry:i}),new Er(new Ir),new er(new wr(r),new Et,new Tt(i),new tr(new sr)),new gr(n),new lt(new St),new mr,new kr,new Qt).compile(t)},zr=t=>{const e=pe(t.rows),r=pe(t.cols);return{rows:t.rows.map(de),cols:t.cols.map(de),placements:Gr(t.placements,e,r),width:t.containerSize.width,height:t.containerSize.height}},Br=t=>{const e=me(t.rows,t.height),r=me(t.cols,t.width),n=ge(e),i=ge(r),a=new Map;for(const s of t.placements){const o=s.rowSpan??1,c=s.colSpan??1,u=i[s.col]??0,p=n[s.row]??0,m=fe(r,s.col,c),d=fe(e,s.row,o);a.set(s.name,{x:u,y:p,width:Math.max(0,m),height:Math.max(0,d)})}return a},pe=t=>{const e=new Map;for(let r=0;r<t.length;r++){const n=t[r];n&&e.set(n.name,r)}return e},de=t=>typeof t.size=="number"?{type:"fixed",pixels:t.size}:{type:"flex",weight:t.size.flex},Gr=(t,e,r)=>{const n=[];for(const i of t){const a=e.get(i.row),s=r.get(i.col);if(a===void 0||s===void 0)continue;const o={name:i.name,row:a,col:s};i.rowSpan!=null&&(o.rowSpan=i.rowSpan),i.colSpan!=null&&(o.colSpan=i.colSpan),n.push(o)}return n},me=(t,e)=>{let r=0,n=0;for(const a of t)a.type==="fixed"?r+=a.pixels:n+=a.weight;const i=Math.max(0,e-r);return t.map(a=>a.type==="fixed"?a.pixels:n===0?0:a.weight/n*i)},ge=t=>{const e=new Array(t.length);let r=0;for(let n=0;n<t.length;n++)e[n]=r,r+=t[n]??0;return e},fe=(t,e,r)=>{let n=0;const i=Math.min(e+r,t.length);for(let a=e;a<i;a++)n+=t[a]??0;return n},Ur=["top","right","bottom","left"],Q=(t,e)=>{const r={};for(const n of Ur){const i=t.get(`${n}${e}`);i&&(r[n]=i)}return r},jr=(t,e,r)=>{const i=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right);return zr({rows:[{name:"title",size:e.titleSize.height},{name:"topLegend",size:r.legends.top},{name:"topAxisLabel",size:i},{name:"topAxis",size:r.axes.top},{name:"panel",size:{flex:1}},{name:"bottomAxis",size:r.axes.bottom},{name:"bottomAxisLabel",size:r.axesLabels.bottom},{name:"bottomLegend",size:r.legends.bottom},{name:"caption",size:e.captionSize.height}],cols:[{name:"leftLegend",size:r.legends.left},{name:"leftAxis",size:r.axes.left},{name:"panel",size:{flex:1}},{name:"rightAxis",size:r.axes.right},{name:"rightLegend",size:r.legends.right}],placements:[{name:"title",row:"title",col:"leftLegend",colSpan:5},{name:"caption",row:"caption",col:"leftLegend",colSpan:5},{name:"plot",row:"topAxisLabel",col:"leftAxis",rowSpan:5,colSpan:3},{name:"panel",row:"panel",col:"panel"},...$r(r.axes),...Kr(r.axesLabels,r.axes),...Wr(r.legends)],containerSize:t})},$r=t=>{const e=[];return t.top>0&&e.push({name:"topAxis",row:"topAxis",col:"panel"}),t.bottom>0&&e.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),t.left>0&&e.push({name:"leftAxis",row:"panel",col:"leftAxis"}),t.right>0&&e.push({name:"rightAxis",row:"panel",col:"rightAxis"}),e},Kr=(t,e)=>{const r=[];return t.top>0||e.top>0?(t.top>0&&r.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),t.left>0&&r.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),t.right>0&&r.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(t.left>0&&r.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis",colSpan:2}),t.right>0&&r.push({name:"rightAxisLabel",row:"topAxisLabel",col:"panel",colSpan:2})),t.bottom>0&&r.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),r},Wr=t=>{const e=[];return t.top>0&&e.push({name:"topLegend",row:"topLegend",col:"leftLegend",colSpan:5}),t.bottom>0&&e.push({name:"bottomLegend",row:"bottomLegend",col:"leftLegend",colSpan:5}),t.left>0&&e.push({name:"leftLegend",row:"topAxisLabel",col:"leftLegend",rowSpan:5}),t.right>0&&e.push({name:"rightLegend",row:"topAxisLabel",col:"rightLegend",rowSpan:5}),e},F={x:0,y:0,width:0,height:0};class Yr{constructor(e){this.measurer=e}compile(e){const r=K({guides:e.guides,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements}).pipe(({guides:n})=>({sizes:this.measureGuides(n)})).pipe(({containerSize:n,externalMeasurements:i,sizes:a})=>{const s=jr(n,i,a);return{rects:Br(s)}}).pipe(({rects:n})=>({title:n.get("title")??F,caption:n.get("caption")??F,plot:n.get("plot")??F,panel:n.get("panel")??F,axes:Q(n,"Axis"),axisLabels:Q(n,"AxisLabel"),legends:Q(n,"Legend")})).result();return{title:r.title,caption:r.caption,plot:r.plot,panel:r.panel,axes:r.axes,axisLabels:r.axisLabels,legends:r.legends}}measureGuides(e){const r={top:0,right:0,bottom:0,left:0},n={top:0,right:0,bottom:0,left:0};for(const a of e.axes)a.isVisible&&(r[a.position]=this.measurer.measureAxis(a),a.label!==null&&(n[a.position]=this.measurer.measureAxisLabel()));const i={top:0,right:0,bottom:0,left:0};for(const a of e.legends)i[a.position]=this.measurer.measureLegend(a);return{axes:r,axesLabels:n,legends:i}}}function qr(t){return t[l.xMin]}function Xr(t){return t[l.xMax]}function Hr(t){return t[l.yMin]}function Jr(t){return t[l.yMax]??t[l.y]}const Zr=t=>t instanceof Date&&he.isValid(t),Qr=t=>typeof t=="string",en=t=>typeof t=="number"&&!Number.isNaN(t),L=(t,e,r)=>{const n=h(e[r]);return i=>{if(n==null)return null;const a=i[n];if(a===void 0)return null;switch(n!==null?t.getType(n):null){case"numeric":return en(a)?a:null;case"categorical":return Qr(a)?a:null;case"temporal":return Zr(a)?a:null;default:return null}}},tn=(t,e)=>L(t,e,"x"),rn=(t,e)=>L(t,e,"y"),nn=(t,e)=>L(t,e,"label"),an=(t,e)=>L(t,e,"color"),sn=(t,e)=>L(t,e,"size"),on=(t,e)=>L(t,e,"alpha"),cn=(t,e)=>L(t,e,"group"),ln=(t,e)=>L(t,e,"strokeWidth");function un(t){return t[R.color]}function pn(t){return t[R.alpha]}function dn(t){return t[R.size]}function mn(t){return t[R.strokeWidth]}const gn=new Set(["count","sum","mean","median"]);function Oe(t,e){return gn.has(t)?"numeric":e}const fn="key",yn="value",hn={eq:(t,e)=>t[e.__variableName]===e.__value,neq:(t,e)=>t[e.__variableName]!==e.__value,gt:(t,e)=>t[e.__variableName]>e.__value,gte:(t,e)=>t[e.__variableName]>=e.__value,lt:(t,e)=>t[e.__variableName]<e.__value,lte:(t,e)=>t[e.__variableName]<=e.__value};class S{constructor(e={}){const{table:r,variableMetadata:n}=this.parseVariableMap(e);this.table=r,this.variableMetadata=n}static merge(...e){if(e.length===0)return S.fromTrusted(E.table({}),{});const r=e.map(o=>o.table),[n,...i]=r,a=i.reduce((o,c)=>o.concat(c),n),s=e.reduce((o,c)=>({...o,...c.variableMetadata}),{});return S.fromTrusted(a,s)}static fromTrusted(e,r){const n=Object.create(S.prototype);return n.table=e,n.variableMetadata=r,n}size(){return this.table.numRows()}getVariableNames(){return this.table.columnNames()}hasVariable(e){return this.table.column(e)!==void 0}addVariable(e,r,n){const i={...this.variableMetadata,[e]:{type:r}},a=this.normalizeRawValues(r,n),s=this.table.assign(E.table({[e]:a}));return S.fromTrusted(s,i)}addConstantVariable(e,r,n){const i={...this.variableMetadata,[e]:{type:r}},[a]=this.normalizeRawValues(r,[n]),s=this.table.assign(E.table({[e]:Array(this.size()).fill(a)}));return S.fromTrusted(s,i)}deriveVariable(e,r,n){const i=Array.from({length:this.size()},(a,s)=>n(this.table.object(s)));return this.addVariable(e,r,i)}renameVariable(e,r){const n=this.variableMetadata[e];if(!n)throw new Error(`Variable ${e} not defined`);const i=this.table.rename({[e]:r}),{[e]:a,...s}=this.variableMetadata,o={...s,[r]:n};return S.fromTrusted(i,o)}selectVariables(...e){const r=this.table.select(...e),n=Object.fromEntries(Object.entries(this.variableMetadata).filter(([i])=>e.includes(i)));return S.fromTrusted(r,n)}getType(e){const r=this.variableMetadata[e];if(!r)throw new Error(`Variable ${e} not defined`);return r.type}groupVariableNamesByType(){const e={numeric:[],categorical:[],temporal:[]};for(const[r,{type:n}]of Object.entries(this.variableMetadata))e[n].push(r);return e}getValues(e,r){if(!this.hasVariable(e))throw new Error(`Variable '${e}' not defined`);const n=this.getType(e);if(r?.type!==void 0&&n!==r.type)throw new Error(`Variable '${e}' has type '${n}', expected '${r.type}'`);let i=this.table.array(e);return r?.distinct&&(i=this.getDistinctValues(n,i)),r?.skipNulls&&(i=this.skipNulls(i)),i}filter(e,r,n){const i=hn[r],a=this.table.params({__variableName:e,__value:n}).filter(i);return S.fromTrusted(a,this.variableMetadata)}orderBy(e,r="asc"){const n=this.table.orderby(r==="asc"?e:E.desc(e));return S.fromTrusted(n,this.variableMetadata)}getFirst(){return this.size()===0?null:this.table.object(0)}getLast(){return this.size()===0?null:this.table.object(this.size()-1)}findLast(e){for(let r=this.size()-1;r>=0;r--){const n=this.table.object(r);if(e(n))return n}return null}groupBy(...e){const r=this.table.groupby(...e);return new bn(e,r,this.variableMetadata)}rollup(e){const r=this.table.rollup(Object.fromEntries(Object.entries(e).map(([i,a])=>[i,E.op[a.aggregation](a.variableName)]))),n={};for(const[i,{variableName:a,aggregation:s}]of Object.entries(e)){const o=this.variableMetadata[a]?.type??"numeric",c=Oe(s,o);n[i]={type:c}}return S.fromTrusted(r,n)}reshapeFromWideToLong(e,r,n=fn,i=yn){const{numeric:a,categorical:s,temporal:o}=this.groupVariableNamesByType(),c=e??[...s,...o],u=r??a.filter(f=>!c.includes(f));if(c.includes(n)||c.includes(i))throw new Error(`The variables to keep includes the variables '${n}' or '${i}' to create the key and value variables`);if(u.length===0){const f={};for(const b of c){const w=this.variableMetadata[b];w&&(f[b]={type:w.type,values:[]})}return f[n]={type:"categorical",values:[]},f[i]={type:"numeric",values:[]},new S(f)}if(u.filter(f=>this.variableMetadata[f]?.type!=="numeric").length>0)throw new Error("Only numeric variables can be reshaped");const d=this.table.select([...c,...u]).fold(u,{as:[n,i]}),g={};for(const f of c){const b=this.variableMetadata[f];b&&(g[f]=b)}return g[n]={type:"categorical"},g[i]={type:"numeric"},S.fromTrusted(d,g)}print(){console.table(this.variableMetadata),this.table.print()}[Symbol.iterator](){return this.table[Symbol.iterator]()}parseVariableMap(e){const r={},n={};for(const[a,{type:s,values:o}]of Object.entries(e))r[a]=o,n[a]={type:s};return{table:E.table(r),variableMetadata:n}}normalizeRawValues(e,r){switch(e){case"numeric":return r.map(n=>typeof n!="number"||Number.isNaN(n)?null:n);case"categorical":return r.map(n=>typeof n!="string"?null:n);case"temporal":return r.map(n=>!(n instanceof Date)||!he.isValid(n)?null:n);default:{const n=e;throw new Error(`Cannot normalize raw value of unknown type: ${n}`)}}}skipNulls(e){return e.filter(r=>r!==null)}getDistinctValues(e,r){const n=e==="temporal",i=new Set,a=[];for(const s of r){const o=n&&s instanceof Date?s.getTime():s;i.has(o)||(i.add(o),a.push(s))}return a}}class bn{constructor(e,r,n){this.groupedBy=e,this.grouped=r,this.variableMetadata=n}forEach(e){const r=this.grouped.partitions(),n=this.grouped.columnNames(),i=this.groupedBy.map(s=>this.grouped.column(s)).filter(s=>s!==void 0);let a=0;for(const s of r){const o=s[0];if(o===void 0)continue;const c=this.getGroupKey(i,o),u=Object.fromEntries(n.map(m=>{const d=this.grouped.column(m);return[m,s.map(g=>d?.get(g))]})),p=E.table(u);e(S.fromTrusted(p,this.variableMetadata),c,a++)}}rollup(e){const r=this.grouped.rollup(Object.fromEntries(Object.entries(e).map(([i,a])=>[i,E.op[a.aggregation](a.variableName)]))),n=Object.fromEntries(this.groupedBy.map(i=>[i,{type:this.variableMetadata[i]?.type??"categorical"}]));for(const[i,{variableName:a,aggregation:s}]of Object.entries(e)){const o=this.variableMetadata[a]?.type??"numeric",c=Oe(s,o);n[i]={type:c}}return S.fromTrusted(r,n)}getGroupKey(e,r){return ve(e.map(n=>n.get(r)))}}function xn(t){return{type:"config",config:t}}const Sn={cartesian:(t={})=>({type:"coord",coordType:"cartesian",params:t}),flip:(t={})=>({type:"coord",coordType:"flip",params:t}),polar:(t={})=>({type:"coord",coordType:"polar",params:t})};function Tn(t={}){return{type:"layer",geom:"point",mapping:t.aes,stat:t.stat,params:t.params,position:t.position,yScaleType:t.yScaleType}}function An(t={}){return{type:"layer",geom:"line",mapping:t.aes,stat:t.stat,params:t.params,position:t.position,yScaleType:t.yScaleType}}function wn(t={}){return{type:"layer",geom:"area",mapping:t.aes,stat:t.stat,params:t.params,position:t.position,yScaleType:t.yScaleType}}function Vn(t={}){return{type:"layer",geom:"bar",mapping:t.aes,stat:t.stat,params:t.params,position:t.position,yScaleType:t.yScaleType}}const Mn={point:Tn,line:An,area:wn,bar:Vn};function vn(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"palette",palette:e.palette}}const En={x:Object.assign(t=>G("x",t),{continuous:t=>x("x",t),discrete:t=>v("x",t),datetime:t=>z("x",t),log:t=>x("x",{...t,transform:"log"}),sqrt:t=>x("x",{...t,transform:"sqrt"})}),y:Object.assign(t=>G("y",t),{continuous:t=>x("y",t),discrete:t=>v("y",t),datetime:t=>z("y",t),log:t=>x("y",{...t,transform:"log"}),sqrt:t=>x("y",{...t,transform:"sqrt"})}),ySecondary:Object.assign(t=>G("ySecondary",t),{continuous:t=>x("ySecondary",t),discrete:t=>v("ySecondary",t),datetime:t=>z("ySecondary",t),log:t=>x("ySecondary",{...t,transform:"log"}),sqrt:t=>x("ySecondary",{...t,transform:"sqrt"})}),color:{continuous:t=>x("color",t),discrete:t=>v("color",t),palette:t=>vn("color",t)},size:{continuous:t=>x("size",t),discrete:t=>v("size",t),identity:t=>B("size",t)},alpha:{continuous:t=>x("alpha",t),discrete:t=>v("alpha",t),identity:t=>B("alpha",t)},strokeWidth:{continuous:t=>x("strokeWidth",t),discrete:t=>v("strokeWidth",t),identity:t=>B("strokeWidth",t)}};function Ln(t){return typeof t=="object"&&t!==null&&"type"in t}function Cn(t,...e){let r={},n;const[i,...a]=e;y(i)&&!Ln(i)?(r=i,n=a):n=e;const s={data:t,mapping:r,layers:[],scales:[],transforms:[],config:{}};return n.reduce((o,c)=>Ne(o,c),s)}function _n(t,...e){return e.reduce((r,n)=>Ne(r,n),t)}function Ne(t,e){switch(e.type){case"scale":return{...t,scales:[...t.scales,e]};case"coord":return{...t,coords:e};case"config":return{...t,config:ye({},t.config,e.config)};case"layer":return{...t,layers:[...t.layers,e]};case"transform":return{...t,transforms:[...t.transforms,e]};case"mapping":return{...t,mapping:{...t.mapping,...e.mapping}};default:{const r=e;throw new Error(`Unknown spec item type: ${r.type}`)}}}const re=500,Pe="normal",ke={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},Fe=t=>typeof t!="string"?t??re:ke[t]??(Number.parseInt(t,10)||re),Rn="\0";class In{constructor(e){this.inner=e,this.cache=new Map}measureText(e,r){const n=this.getCacheKey(e,r),i=this.cache.get(n);if(i)return i;const a=this.inner.measureText(e,r);return this.cache.set(n,a),a}getCacheKey(e,r){return[r.family,r.size,Fe(r.weight),r.style??Pe,e].join(Rn)}}const Dn={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56},On=.55,Nn=1.05,Pn=.84,kn=.21;class Fn{measureText(e,r){let n=0;for(const o of e)n+=(Dn[o]??On)*r.size;Fe(r.weight)>=ke.semiBold&&(n*=Nn);const a=Pn*r.size,s=kn*r.size;return{width:n,height:a+s,ascent:a,descent:s}}}exports.CachedTextMeasurer=In;exports.Compiler=De;exports.DEFAULT_COLOR_PALETTE=be;exports.DEFAULT_FONT_STYLE=Pe;exports.DEFAULT_FONT_WEIGHT=re;exports.DEFAULT_PALETTE_NAME=xe;exports.Dataset=S;exports.GROUP_VARIABLES=M;exports.HeuristicTextMeasurer=Fn;exports.LayoutCompiler=Yr;exports.POSITION_VARIABLES=l;exports.VISUAL_VARIABLES=R;exports.compile=Fr;exports.config=xn;exports.coord=Sn;exports.createAlphaValueReader=on;exports.createColorValueReader=an;exports.createGroupValueReader=cn;exports.createLabelValueReader=nn;exports.createSizeValueReader=sn;exports.createSpec=Cn;exports.createStrokeWidthValueReader=ln;exports.createXValueReader=tn;exports.createYValueReader=rn;exports.geom=Mn;exports.getAlpha=pn;exports.getColor=un;exports.getEndAngle=Xr;exports.getGroup=Ce;exports.getInnerRadius=Hr;exports.getOuterRadius=Jr;exports.getSize=dn;exports.getStartAngle=qr;exports.getStrokeWidth=mn;exports.getX=kt;exports.getXMax=zt;exports.getXMin=Ft;exports.getY=ee;exports.getYMax=te;exports.getYMin=_e;exports.pipe=_n;exports.scale=En;