@graphysdk/viz-engine 1.9.0-beta.1793272487821 → 1.9.0-beta.1793288163741

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.
@@ -1 +1 @@
1
- const o=require("./annotations-CuIFf0S0.cjs");let F=require("lodash-es"),re=require("d3-time"),Kn=require("date-fns/differenceInDays"),Y=require("d3-regression"),D=require("d3-scale"),ne=require("d3-interpolate");var L=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);return o.isDefined(n)?a=>{const i=a[n];return i===void 0?null:er(i,e.getType(n))}:()=>null},qn=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);if(!o.isDefined(n)||!e.hasVariable(n))return()=>null;const a=e.getValues(n),i=e.getType(n);return s=>{const c=a[s];return c===void 0?null:er(c,i)}},zn=(e,t)=>L(e,t.x),Wn=(e,t)=>L(e,t.y),Hn=(e,t)=>L(e,t.label),Xn=(e,t)=>L(e,t.color),Jn=(e,t)=>L(e,t.size),Zn=(e,t)=>L(e,t.alpha),Qn=(e,t)=>L(e,t.group),ea=(e,t)=>L(e,t.strokeWidth),er=(e,t)=>{switch(t){case"numeric":return o.isStrictNumericDataValue(e)?e:null;case"categorical":return o.isStrictCategoricalDataValue(e)?e:null;case"temporal":return o.isStrictTemporalDataValue(e)?e:null;default:return null}},St={variable:o.POSITION_VARIABLES.yRaw};function Oe(e,t){return o.isStackedPosition(e)?St:t.y??St}function Je(e){return L(e.data,Oe(e.position,e.mapping))}function ta(e){return qn(e.data,Oe(e.position,e.mapping))}var de=e=>{const t=o.readVariableName(e.mapping.x);return t!==null&&t!==o.CONSTANT_VARIABLES.x?t:rr(e)??o.GROUP_VARIABLES.group},Ze=e=>ra(e)?o.readVariableName(e.mapping.y):null,tr=e=>Ze(e)===null?null:Je(e),Qe=e=>e.spatialKind!=="cells"&&de(e)!==rr(e),rr=e=>typeof e.identityKey=="object"?e.identityKey.variable:null,ra=e=>e.spatialKind==="points"||e.spatialKind==="cells",nr=(e,t)=>e.yScaleType===t.yScaleType&&je(e.valueFormat)===je(t.valueFormat),$e=e=>`${e.yScaleType} y axis, ${je(e.valueFormat)}`,je=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,ar=(e,t)=>{const r=o.toExplicitValueFormat(e.data.getValueFormat(de(e))),n=Ze(e);return a=>({...a,anchorValue:o.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:o.parseAddressingValue(a.groupValue,o.toExplicitValueFormat(e.data.getValueFormat(o.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:o.parseAddressingValue(a.crossValue,o.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function ir(e){return e instanceof o.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function na(e,t){return or(e,t)}function ae(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function aa(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function et(e,t){let r=null;for(const[n,a]of e.entries()){const i=t(a,n);if(i===a){r?.push(i);continue}r??=e.slice(0,n),r.push(i)}return r??e}function or(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(o.isPlainObject(i)&&o.isPlainObject(s)){const c=or(s,i);c!==s&&(n[a]=c,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function we(e){return{pipe:t=>{const r=t(e);return we({...e,...r})},result:()=>e}}var ia=(e,t)=>Te(e)===Te(t),Te=e=>JSON.stringify(tt(e)),tt=e=>{const t=e;return typeof t!="object"||t===null?["invalid",String(t)]:"and"in e?["and",...At(e.and)]:"or"in e?["or",...At(e.or)]:"not"in e?["not",tt(e.not)]:[e.variable,...oa(e)]},oa=e=>{if("eq"in e)return["eq",o.readDataValueKey(e.eq)];if("oneOf"in e)return["oneOf",...Tt(e.oneOf)];if("lt"in e)return["lt",o.readDataValueKey(e.lt)];if("lte"in e)return["lte",o.readDataValueKey(e.lte)];if("gt"in e)return["gt",o.readDataValueKey(e.gt)];if("gte"in e)return["gte",o.readDataValueKey(e.gte)];if("range"in e)return["range",...Tt(e.range)];const t=Object.entries(e).sort(([r],[n])=>r.localeCompare(n));return["invalid",JSON.stringify(t)]},At=e=>Array.isArray(e)?e.map(tt):["invalid",JSON.stringify(e)],Tt=e=>Array.isArray(e)?e.map(o.readDataValueKey):["invalid",JSON.stringify(e)],Fe=e=>e.coords.coordType==="polar"?"polar":"cartesian",sr=(e,t,r)=>{const n=rt(e,t,r);return n===-1?void 0:e[n]},rt=(e,t,r)=>{const n=Le(t,r);for(let a=e.length-1;a>=0;a-=1){const i=e[a];if(i!==void 0&&n(i))return a}return-1},sa=(e,t,r)=>{const n=rt(e,t,r);return e.filter((a,i)=>i!==n)},cr=(e,t,r)=>{const n=Le(t,r);let a;for(const i of e)if(n(i)){a??={};for(const[s,c]of Object.entries(i.declarations))c!==void 0&&(a[s]=c)}return a},ca=(e,t,r)=>cr(e,t,r),la=(e,t)=>K(e)===K(t),Le=(e,t)=>{const r=K(e),n=It(e)!==void 0;return a=>{const i=It(a);if(n||i===void 0)return K(a)===r;if(i!==t)return!1;const{coord:s,...c}=a.select;return K({...a,select:c})===r}},K=e=>{const t=Object.entries(e.select).filter(([,n])=>n!==void 0).sort(([n],[a])=>n.localeCompare(a)),r=e.when?.where===void 0?null:Te(e.when.where);return JSON.stringify([t,e.when?.state??null,r])},ua=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>pa(e[r],t[r])),da=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),nt=e=>e.select.target==="geom",ma=(e,t,r)=>{const n=new Map;for(const a of e)!nt(a)||a.when?.where===void 0||Le({...t,when:a.when},r)(a)&&n.set(K(a),a);return[...n.values()]},fa=(e,t,r)=>{const n=sr(e,t,r);if(!(n===void 0||!nt(n)))return n.declarations},It=e=>e.select.coord,pa=(e,t)=>e===t?!0:o.isLightDarkColor(e)?o.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:o.isStyleTokenRef(e)?o.isStyleTokenRef(t)&&e.token===t.token:!1,ga=(e,t)=>{if(!o.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[o.getStableKey(r)]??e.fallback},lr=e=>e.type==="polar"?"disk":"panel",ur=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},ha=(e,t)=>{if(e.space!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=ur(e.space,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function dr(e,t){return e==="x"?t.x:t.y}function mr(e,t){return e==="x"?t.y:t.x}function ya(e,t){return{main:dr(e,t),cross:mr(e,t)}}function Ue(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function Ce(e){return e.type==="cartesian"?e.mainAxis:"x"}function va(e){return e.type==="cartesian"}var me=e=>e[o.GROUP_VARIABLES.group],fr=e=>{const t=de(e),r=tr(e),n=Qe(e)&&t!==o.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const c=n?me(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...c!==null&&{groupValue:c}}}},ye=1e-9;function pr(e){return e?{start:o.POSITION_VARIABLES.yMin,end:o.POSITION_VARIABLES.yMax}:{start:o.POSITION_VARIABLES.xMin,end:o.POSITION_VARIABLES.xMax}}function gr(e,t){const r=new Map;for(const a of e.flatMap(i=>Ta(i,t))){const i=o.getStableKey([a.value]),s=r.get(i);s?s.push(a):r.set(i,[a])}const n=[...r.values()];return n.some(Sa)?null:n.flatMap(a=>Aa(a)??[])}function ba(e,t,r){const n=gr(e,t),a=o.getStableKey([r]),i=n?.find(s=>o.getStableKey([s.value])===a);return i===void 0?null:(i.start+i.end)/2}function Sa(e){const t=[...e].sort((a,i)=>a.start-i.start||a.end-i.end);let r=Number.NEGATIVE_INFINITY,n;for(const a of t){if(!(n!==void 0&&Math.abs(a.start-n.start)<=ye&&Math.abs(a.end-n.end)<=ye)&&a.start<r-ye)return!0;r=Math.max(r,a.end),n=a}return!1}function Aa(e){let t,r;for(const n of[...e].sort((a,i)=>a.start-i.start))t=t!==void 0&&n.start<=t.end+ye?{...t,end:Math.max(t.end,n.end)}:n,(r===void 0||t.end-t.start>r.end-r.start)&&(r=t);return r}function Ta(e,t){const r=o.readVariableName(e.mapping.x),{data:n}=e,{start:a,end:i}=pr(t);if(!o.isDefined(r)||!n.hasVariable(a)||!n.hasVariable(i))return[];const s=n.getValues(r),c=n.getValues(a,{type:"numeric"}),l=n.getValues(i,{type:"numeric"});return s.flatMap((u,d)=>{const m=c[d],f=l[d];return!o.isDefined(u)||!o.isDefined(m)||!o.isDefined(f)?[]:[{value:u,start:Math.min(m,f),end:Math.max(m,f)}]})}var Ia={type:"decimal"};function hr(e){return e.length>0&&e.every(t=>t.data.size()===0)}function at(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):Ia}function Va(e){return at(e,o.readVariableName(e.mapping.y))}function yr(e,t){const r=Vt(t);return[...Vt(e)].filter(n=>r.has(n))}function Vt(e){const t=new Set(o.getGroupVariables(e.data,e.mapping));for(const r of Object.values(e.mapping)){const n=o.readVariableName(r);n===null||!e.data.hasVariable(n)||e.data.getType(n)==="categorical"&&t.add(n)}return t}function vr({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??Oe(t,r)}function br(e,t){const r=vr({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=o.readVariableName(r),a=n===o.POSITION_VARIABLES.yRaw?o.readVariableName(e.mapping.y):n;return{read:L(e.data,r),valueFormat:at(e,a)}}var Sr=e=>{const t=de(e),r=tr(e),n=Qe(e);return(a,i)=>!o.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||o.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:o.areDataValuesEqual(me(a),i.groupValue)},Ar=e=>{const t=o.readVariableName(e.mapping.y),r=Je(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},Tr=e=>t=>{if(t===o.readVariableName(e.mapping.y))return ta(e);const r=e.data.hasVariable(t)?e.data.getValues(t):null;return n=>r?.[n]??null};var xa=["lt","lte","gt","gte","range"],Ea={highlight:{subject:"Highlight predicate",effect:"dropping this highlight"},"selection-anchor":{subject:"Selection anchor predicate",effect:"dropping this annotation"},"style-rule":{subject:"Style rule predicate",effect:"dropping this rule"}},_=()=>!1,X=()=>!0;function Pe(e,t){const r=Ar(e);return{...it(e.data,t),createValueReader:n=>a=>r(a,n)}}function Oa(e,t){return{...it(e.data,t),createValueReader:Tr(e)}}function wa(e,t){return{...it(e,t),createValueReader:r=>{const n=e.hasVariable(r)?e.getValues(r):null;return a=>n?.[a]??null}}}function ve(e){return"and"in e?[...new Set(e.and.flatMap(ve))]:"or"in e?[...new Set(e.or.flatMap(ve))]:"not"in e?ve(e.not):[e.variable]}function q(e,t){if("and"in e){const r=e.and.map(n=>q(n,t)).filter(n=>n!==X);return r.includes(_)?_:r.length===0?X:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>q(n,t)).filter(n=>n!==_);return r.includes(X)?X:r.length===0?_:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=q(e.not,t);return r===_?X:r===X?_:n=>!r(n)}return Ca(e,t)}function z(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>z(n,t,r)):"or"in e?e.or.flatMap(n=>z(n,t,r)):"not"in e?z(e.not,t,r):La(e,t,r)}function it(e,t){return{hasVariable:r=>e.hasVariable(r),getType:r=>e.getType(r),getValueFormat:r=>e.getValueFormat(r),parsingLocale:t}}function La(e,t,r){const{subject:n,effect:a}=Ea[r];if(!t.hasVariable(e.variable))return[{code:"UNKNOWN_VARIABLE",message:`${n} references unknown variable '${e.variable}' — ${a}.`,context:{variableName:e.variable},suggestion:`Map '${e.variable}' in the layer or correct the variable name in the predicate.`}];const i=Pa(e);return i!==null&&t.getType(e.variable)==="categorical"?[{code:"INVALID_PREDICATE_OPERATOR",message:`${n} uses ordering operator '${i}' on categorical variable '${e.variable}' — ${a}. Use 'eq' or 'oneOf' instead.`,context:{variableName:e.variable},suggestion:"Use 'eq' or 'oneOf' for categorical variables."}]:[]}function Ca(e,t){if(!t.hasVariable(e.variable))return _;const r=t.createValueReader(e.variable),n=o.toExplicitValueFormat(t.getValueFormat(e.variable)),a=i=>o.parseAddressingValue(i,n,t.parsingLocale);if("eq"in e){const i=a(e.eq);return s=>o.areDataValuesEqual(r(s),i)}if("oneOf"in e){const i=e.oneOf.map(a);if(i.length>=32){const s=new Set,c=new Set;for(const l of i)o.isStrictTemporalDataValue(l)?c.add(l.getTime()):s.add(l);return l=>{const u=r(l);return o.isStrictTemporalDataValue(u)?c.has(u.getTime()):!Number.isNaN(u)&&s.has(u)}}return s=>{const c=r(s);for(const l of i)if(o.areDataValuesEqual(c,l))return!0;return!1}}if("lt"in e){const i=a(e.lt);return s=>J(r(s),i)==="less"}if("lte"in e){const i=a(e.lte);return s=>{const c=J(r(s),i);return c==="less"||c==="equal"}}if("gt"in e){const i=a(e.gt);return s=>J(r(s),i)==="greater"}if("gte"in e){const i=a(e.gte);return s=>{const c=J(r(s),i);return c==="greater"||c==="equal"}}if("range"in e){const[i,s]=e.range,c=a(i),l=a(s);return u=>{const d=r(u),m=J(d,c),f=J(d,l);return m==="incomparable"||f==="incomparable"?!1:(m==="greater"||m==="equal")&&(f==="less"||f==="equal")}}return _}function Pa(e){for(const t of xa)if(t in e)return t;return null}function J(e,t){if(e===null||t===null)return"incomparable";if(o.isStrictTemporalDataValue(e)&&o.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return o.isStrictNumericDataValue(e)&&o.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var Ra=(e,t)=>{const r=Vr(e,t.predicate);if(r===null)return null;const{box:n,observations:a}=r,i=Ir(t.padding)===null?Da(n,t.padding):n;return{x:i.xMin,y:i.yMin,width:Math.max(0,i.xMax-i.xMin),height:Math.max(0,i.yMax-i.yMin),space:i.space,defer:{type:"observationBox",observations:a,padding:t.padding}}},Na=(e,t)=>{const r=Vr(e,t.predicate);if(r===null)return null;const{box:n,observations:a}=r;return{...o.alignToBoxPoint(n,t.align),space:n.space,defer:{type:"observationBox",observations:a,align:t.align}}},Ir=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"pxOffset",x:e.x??0,y:e.y??0},Vr=({warnings:e,layers:t,coordSystem:r,selectionBoxCache:n,parsingLocale:a},i)=>{if(n.has(i))return n.get(i)??null;let s=null;const c=[];let l=!1;const u=new Map;for(const m of t){if(!m.interactive)continue;const f=z(i,m.data,"selection-anchor");if(f.length>0){for(const h of f)u.set(`${h.code}:${h.message}`,h);continue}l=!0;const p=q(i,Pe(m,a));if(p===_)continue;let g=-1;for(const h of m.data){if(g+=1,!p(h))continue;const v=o.readObservationBox(h,r);v!==null&&(s=s===null?v:_a(s,v),c.push({layerId:m.id,observationIndex:g}))}}l||e.push(...u.values());const d=s===null?null:{box:s,observations:c};return n.set(i,d),d},_a=(e,t)=>({space:e.space,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),Da=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Ie=(e,t,r)=>{const n=Ba(e,t,r);return n===null?null:n.defer?.type==="annotationRef"?n:n.defer?.type==="observationBox"?t.offset===void 0?n:{...n,defer:{...n.defer,offset:t.offset}}:$a(n,t.offset,e.coordSystem)},xr=(e,t)=>t.anchorType==="selection"?Ra(e,t):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotationRef",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},Er=(e,t,r)=>Ve(e,t,r)?.point??null,Ve=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const c=e.geomRegistry.get(s.geom),{resolveAnchorPosition:l}=c;if(l===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=br(s,c),d=Sr(s),m=fr(s),f=ar(s,n)(a);let p=-1;for(const g of s.data){if(p+=1,!d(g,f))continue;const h=l(g,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(h===null)continue;const v=Or(s,g,u);if(v===null)continue;const y=m(g);if(y!==null)return{point:{...h,...v,space:lr(r),observationIndex:p,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id}}}return null},Ma=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,c=a.y;if(s===void 0||c===void 0||s.kind!=="position"||c.kind!=="position")return null;const l=Et(t.x,"x",r,i),u=Et(t.y,"y",r,i);if(l===null||u===null)return null;const d=ka(e,s,l),m=c.map(u);if(!o.isPointWithinPanel(d,m))return null;const f=xt(d,s,ja(e)),p=xt(m,c),g=Ue(n.mainAxis,{main:f.min,cross:p.min}),h=Ue(n.mainAxis,{main:f.max,cross:p.max});return o.alignToBoxPoint({xMin:g.x,xMax:h.x,yMin:g.y,yMax:h.y},t.align??"center")},Or=(e,t,r)=>{const n=r.read(t);return o.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:ga(r.valueFormat,t),yScaleType:e.yScaleType}:null},ka=({layers:e,coordSystem:t,container:r},n,a)=>{if(o.isStrictNumericDataValue(a))return n.map(a);const i=e.filter(s=>o.spansCategoriesOnX(r.geomRegistry.get(s.geom)));return i.length===0?n.map(a):ba(i,Ce(t)==="y",a)??NaN},Ba=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Ma(e,t);case"selection":return Na(e,t);case"annotation":return{x:0,y:0,defer:{type:"annotationRef",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":{const n=Ve(e,Fa(t),r);if(n===null)return null;const{point:a,layerId:i}=n;if(t.align===void 0)return a;const s=[{layerId:i,observationIndex:a.observationIndex}];return{...a,defer:{type:"observationBox",observations:s,align:t.align}}}}},$a=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ir(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},xt=(e,t,r=1)=>{const{bandwidth:n}=t;if(n===null||n<=0)return{min:e,max:e};const a=n*r/2;return{min:e-a,max:e+a}},ja=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},Fa=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Et=(e,t,r,n)=>{for(const a of r){const i=o.readVariableName(a.mapping[t]);if(!(i===null||i===o.CONSTANT_VARIABLES.x))return o.parseAddressingValue(e,o.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Ua=class extends o.Stage{constructor(e){super(),this.container=e,this.warningsByOutput=new WeakMap}compile(e){const t=super.compile(e);for(const r of this.warningsByOutput.get(t)??[])this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s=[],c={container:this.container,warnings:s,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},l={differenceArrows:Qa(c,t.differenceArrows),shapes:qa(c,t.shapes),arrows:Wa(c,t.arrows),textAnnotations:Ha(c,t.textAnnotations),images:za(c,t.images),stickers:Xa(c,t.stickers),pinnedNumbers:Ja(c,t.pinnedNumbers),comments:Za(c,t.comments)};return Ga(s,l),Ya(s,l),this.warningsByOutput.set(l,s),l}},R=(e,t,r,n)=>{e.push({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},Ga=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.push({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation carries id "${a}" — references to it resolve to the first, and the rest cannot be addressed.`,context:{annotationId:a},suggestion:"Give each annotation its own id."});continue}r.add(a)}},Ya=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const a of n)r.add(a.id);for(const{id:n,ref:a}of Ka(t))r.has(a)||e.push({code:"ANNOTATION_REF_NOT_FOUND",message:`Annotation "${n}" references id "${a}", whose annotation could not be anchored and was dropped.`,context:{annotationId:n,ref:a},suggestion:"Fix the anchor on the target annotation or point this reference at one that resolves."})},Ka=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotationRef"&&t.push({id:n,ref:a.defer.ref})};for(const n of e.shapes)r(n.id,n.region);for(const n of e.images)r(n.id,n.region);for(const n of e.arrows)r(n.id,n.start),r(n.id,n.end);for(const n of e.textAnnotations)r(n.id,n.at);for(const n of e.stickers)r(n.id,n.at);return t},qa=(e,t)=>{const r=[];for(const n of t){const a=xr(e,n.region);if(a===null){R(e.warnings,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},za=(e,t)=>{const r=[];for(const n of t){const a=xr(e,n.region);if(a===null){R(e.warnings,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},Wa=(e,t)=>{const r=[];for(const n of t){const a=Ie(e,n.start,"pin"),i=Ie(e,n.end,"pin");if(a===null||i===null){R(e.warnings,"arrow",n.id,`has ${wr(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Ha=(e,t)=>{const r=[];for(const n of t){const a=Ie(e,n.at,"pin");if(a===null){R(e.warnings,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},Xa=(e,t)=>{const r=[];for(const n of t){const a=Ie(e,n.at,"pin");if(a===null){R(e.warnings,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Ja=(e,t)=>{const r=[];for(const n of t){const a=Er(e,n.at,"pin");if(a===null){R(e.warnings,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Za=(e,t)=>{const r=[];for(const n of t){const a=Er(e,n.at,"pin");if(a===null){R(e.warnings,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Qa=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)R(e.warnings,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Ve(e,n.start,"value"),i=Ve(e,n.end,"value");if(a===null||i===null){R(e.warnings,"differenceArrow",n.id,`has ${wr(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){R(e.warnings,"differenceArrow",n.id,"has both ends on the same observation");continue}ei(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},wr=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",ei=(e,t,r,n)=>{nr(r,n)||e.warnings.push({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:$e(r),actual:$e(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function ti(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,c]of r)c.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Lr(i),values:i};return new o.Dataset(n)}function Lr(e){const t=Array.isArray(e)?e:[e];for(const r of t)if(r!==null)return typeof r=="number"?"numeric":r instanceof Date?"temporal":"categorical";return"categorical"}var ri=class extends o.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(o.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:o.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){if(o.isVisualScale(n))continue;const a=o.readConstantValue(r[n]);if(a===void 0)continue;const i=o.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Lr(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},H=class{constructor(){this.perLayerMemo=o.createPerKeyMemo(),this.listMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},ni=class extends o.Stage{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.scales,e.layers]}run(e){return this.registry.get(e.coordSpec.coordType).setup(e)}},ai=class extends H{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,t){const[r]=this.registry.get(t.coordSpec.coordType).transform({coordSpec:t.coordSpec,coordSystem:t.coordSystem,layers:[e]});if(!r)throw new o.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},ii=class{constructor(e){this.setupStage=new ni(e),this.transformStage=new ai(e)}get setupStats(){return this.setupStage.stats}get transformStats(){return this.transformStage.stats}setup(e){return this.setupStage.compile(e)}transform(e){return this.transformStage.compile(e)}},oi=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}},scales:e.scales}}transform(e){return e.layers}},si=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"left",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}},scales:li(e.scales,e.layers)}}transform(e){return e.layers.map(t=>di(t))}},ci=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax],[o.POSITION_VARIABLES.xBand,o.POSITION_VARIABLES.yBand]],Ot=o.prefixInternalVariable("flipSwap"),li=(e,t)=>ui(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,ui=e=>{for(const t of e){const r=o.readVariableName(t.mapping.x);if(!r||!t.data.hasVariable(r))continue;const n=t.data.getType(r);if(n==="categorical"||n==="temporal")return!0}return!1},di=e=>{let t=e.data;for(const[r,n]of ci){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ot).renameVariable(n,r).renameVariable(Ot,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function mi(e){const t=new Set,r=[];for(const n of e){const a=n instanceof Date?n.getTime():String(n);t.has(a)||(t.add(a),r.push(n))}return r}var Cr=(e,t)=>mi(t.domain!==null&&t.domain.length>0?t.domain:e),Pr=(e,t)=>e.scaledAesthetic==="x"&&t.some(r=>o.readVariableName(r.mapping.x)===o.CONSTANT_VARIABLES.x)&&t.every(r=>o.readMainAxisVariable(r.mapping)==="")?{...e,domain:null}:e,fi=e=>{const t=e.length-1,r=e[t];if(r===void 0||t<1)return null;const n=[];for(let i=1;i<=t;i+=1){const s=e[i-1],c=e[i];s===void 0||c===void 0||n.push(c-s)}n.sort((i,s)=>i-s);const a=n[n.length-1>>1];return a===void 0?null:r+a},pi=e=>[...new Set(e)].sort((t,r)=>t-r),gi=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=Si(t,e.scales,e.layers),a=Ti(t,e.scales,e.layers);return{coordSystem:{type:"polar",axisMapping:t.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:t.innerRadius,startAngle:r,spokeRotation:n,bandAxis:a},scales:vi(t,e.scales,e.layers)}}transform(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new o.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=yi(r,n),i=Ii(t);return e.layers.map(s=>Vi(t.theta==="y"?xi(s):s,a,i))}},hi=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax],[o.POSITION_VARIABLES.xBand,o.POSITION_VARIABLES.yBand]],wt=o.prefixInternalVariable("polarSwap");function yi(e,t){return r=>o.positionToAngle(r,e,t)}function vi(e,t,r){return e.theta!=="x"?t:t.map(n=>{if(n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"||n.scaleType==="continuous"&&n.transform!=="linear"||n.domainMax!==null)return n;const a=bi(e,r),i=fi(a),s=a[0];return i===null||s===void 0?n:{...n,domainMin:n.domainMin??s,domainMax:i}})}function bi(e,t){const r=[];for(const n of t){const a=o.readVariableName(n.mapping[e.theta]);if(!(a===null||!n.data.hasVariable(a)))for(const i of n.data.getValues(a))i instanceof Date?r.push(i.getTime()):typeof i=="number"&&r.push(i)}return pi(r)}function Si(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Ai(n,e,r);return a===0?0:-Math.PI/a}function Ai(e,t,r){const n=[];for(const a of r){const i=o.readVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Cr(n,Pr(e,r)).length}function Ti(e,t,r){if(e.theta==="x")return"x";const n=t.find(i=>i.scaledAesthetic==="x")?.scaleType==="discrete",a=r.some(i=>i.position==="fill");return n&&!a?"y":null}function Ii(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Vi(e,t,r){let n=e.data;return n=$(n,o.POSITION_VARIABLES.x,t),n=$(n,o.POSITION_VARIABLES.xMin,t),n=$(n,o.POSITION_VARIABLES.xMax,t),n=$(n,o.POSITION_VARIABLES.xBand,t),n=$(n,o.POSITION_VARIABLES.y,r),n=$(n,o.POSITION_VARIABLES.yMin,r),n=$(n,o.POSITION_VARIABLES.yMax,r),n=$(n,o.POSITION_VARIABLES.yBand,r),{...e,data:n}}function $(e,t,r){if(!e.hasVariable(t))return e;const n=e.getValues(t,{type:"numeric"}).map(a=>a===null?null:r(a));return e.addVariable(t,"numeric",n)}function xi(e){let t=e.data;for(const[r,n]of hi){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,wt).renameVariable(n,r).renameVariable(wt,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}}var Ei=class extends o.Registry{constructor(){super("coord"),this.register("cartesian",new oi),this.register("flip",new si),this.register("polar",new gi)}},Oi=class{constructor(e){this.container=e}compile(e,t){const r=this.container.geomRegistry.get(e),n=r.compile(t),a={...t.mapping,...n.mapping};return{...n,data:o.fillIntervalAesthetics(n.data,r.positionRoles,a)}}},wi=class{compute({data:e,mapping:t}){const r=o.getGroupVariables(e,t);if(r.length===0)return{data:e.addConstantVariable(o.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=o.getStableKey(a.map(c=>c[s]));return{data:e.addVariable(o.GROUP_VARIABLES.group,"categorical",i)}}},Li=e=>{if(e===void 0)return{};const t={};for(const r of e.columns)r.label!==void 0&&(t[r.key]=r.label);return t},Ci=(e,t,r)=>{const n=W(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function W(e,t){const r=o.getAestheticFromScaledAesthetic(t);let n=null;for(const a of Rr(t,e)){const i=o.readVariableName(a.mapping[r]);if(o.isDefined(i)){if(o.isInternalVariable(i)){n??=i;continue}return i}}return n}var ot=(e,t)=>e===null?null:t[e]??e,Pi=(e,t)=>e===null?null:t[String(e)]??null,M=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return ke(t);for(const n of e){if(!n.data.hasVariable(r))continue;const a=n.data.getValueFormat(r),i=a.type==="lookup"?a.fallback:a;return Ni(i,t)?i:ke(t)}return ke(t)},Ri=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Rr(t,e).some(r=>r.position==="fill");function Rr(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var ke=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"identity":return{type:"text"}}},Ni=(e,t)=>{switch(t){case"continuous":return o.isNumericValueFormat(e);case"datetime":return o.isTemporalValueFormat(e);case"discrete":case"identity":return!0}},_i=[{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}],Lt={year:0,quarter:1,month:2,week:3,day:4,hour:5},Z=40,Di=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return $i(r.unit).range(e,new Date(t.valueOf()+1),n)},Mi=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Kn.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Z;case"day":return a/t>Z;case"week":return a/(7*t)>Z;case"month":return a/(30*t)>Z;case"quarter":return a/(90*t)>Z;case"year":return a/(365*t)>Z}},ki=(e,t)=>{const r=!o.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"monthYear"}:{type:"month"};case"week":return r?{type:"weeklyDateRangeWithYear"}:{type:"weeklyDateRange"};case"day":return r?{type:"date"}:{type:"dayMonth"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Bi=(e,t)=>{const r=ji(t);return r===null?!1:Lt[e]>Lt[r]},$i=e=>{switch(e){case"hour":return re.utcHour;case"day":return re.utcDay;case"week":return re.utcMonday;case"month":case"quarter":return re.utcMonth;case"year":return re.utcYear}},ji=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"monthYear":case"month":return"month";case"weeklyDateRange":case"weeklyDateRangeWithYear":return"week";case"date":case"dayMonth":return"day";case"datetime":case"time":return"hour";default:return null}},Nr={left:"right",right:"left",top:"bottom",bottom:"top"},Fi={x:!0,y:!0,ySecondary:!1},be=20,Ct=new Set(["top","bottom"]),Ui={type:"percentage"};function Gi(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:c}=e;if(hr(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const l=qi(c,a,i.type,n),u=new Set(t.map(f=>f.position)),d=Wi(_r(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const f of o.SCALED_POSITION_AESTHETIC_KEYS){const p=r[f];if(!o.isDefined(p)||p.kind!=="position")continue;const g=Yi({scaledAesthetic:f,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:l,variableLabels:s,geomRegistry:c,flipped:Ce(i)==="y"});m.push(g)}return m}function Yi(e){const{scaledAesthetic:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:c,variableLabels:l,geomRegistry:u,flipped:d}=e,{axisConfig:m,position:f,geometry:p}=zi(t,n,i,s),g=W(a,t),h=Xi(t,a,u),v=Ji(h),y=Zi({scale:r,scaledAesthetic:t,layers:a,spanLayers:h,flipped:d,variableName:g});return{scaledAesthetic:t,position:f,geometry:p,label:Ki(m,g,l),visible:m.visible,tickCandidates:Qi({scale:r,spanLayers:h,flipped:d,scaleValueFormat:y,categoryValueFormat:v,tickMode:m.ticks.mode}),valueFormat:y,categorySpan:v===null?void 0:{valueFormat:v,layerIds:h.map(b=>b.id)},tickMode:m.ticks.mode,showTicks:m.ticks.visible,showGrid:Hi(m,c,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Ki(e,t,r){return e.label===""?null:e.label!==null?e.label:t?r[t]??null:null}function qi(e,t,r,n){const a=t.flatMap(c=>{const l=e.get(c.geom).grid[r];return l?[l]:[]}),i=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY);return{x:{showGrid:Pt(i,n.axes.x.grid.visible)},y:{showGrid:Pt(s,n.axes.y.grid.visible)}}}function Pt(e,t){if(e&&t===null)return!1}function zi(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:_r(t.axes[e].position,r[e].position),geometry:r.x.geometry};case"y":return{axisConfig:t.axes[e],position:n,geometry:r.y.geometry};case"ySecondary":{const a=Nr[n],i=(0,F.merge)({},{visible:t.axes.y.visible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function _r(e,t){return Ct.has(e)===Ct.has(t)?e:t}function Wi(e,t){return t.has(e)?Nr[e]:e}function Hi(e,t,r){const{showGrid:n}=r==="x"?t.x:t.y;return n??e.grid.visible??Fi[r]}var Xi=(e,t,r)=>e!=="x"?[]:t.filter(n=>o.spansCategoriesOnX(r.get(n.geom))),Ji=e=>{const[t]=e;return t===void 0?null:M({layers:e,scaleType:"discrete",variableName:o.readVariableName(t.mapping.x)})},Zi=e=>{const{scale:t,scaledAesthetic:r,layers:n,spanLayers:a,flipped:i,variableName:s}=e,c=t.spec.scaleType;return a.length>0?M({layers:a,scaleType:c,variableName:pr(i).start}):Ri(n,r)?Ui:M({layers:n,scaleType:c,variableName:s})},Qi=e=>{const{scale:t,spanLayers:r,flipped:n,scaleValueFormat:a,categoryValueFormat:i,tickMode:s}=e;if(i!==null){const c=eo(r,n).map(l=>({...l,valueFormat:i}));if(c.length>0)return s==="edges"?to(c):c}return io(t,a,s)},eo=(e,t)=>{const r=gr(e,t)?.filter(no);if(r===void 0)return[];const n=new Map([...r].sort((a,i)=>i.end-i.start-(a.end-a.start)).map((a,i)=>[a,i]));return ao(r.length).map(a=>({ticks:r.filter(i=>(n.get(i)??0)<a).map(({value:i,start:s,end:c})=>({value:i,position:(s+c)/2})).sort(ro),source:"categories"}))},to=e=>{const t=e.at(-1);if(t===void 0||t.ticks.length<=2)return e.slice(-1);const r=t.ticks[0],n=t.ticks.at(-1);return r===void 0||n===void 0?e.slice(-1):[{...t,ticks:[r,n]}]},ro=(e,t)=>e.position-t.position,no=({start:e,end:t})=>{const r=(e+t)/2;return r>=-1e-9&&r<=1.000000001},ao=e=>e<=be?Array.from({length:e},(t,r)=>r+1):Array.from({length:be},(t,r)=>Math.round(1+r*(e-1)/(be-1))),io=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=so(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=be;s++){const c=e.generateTicks({count:s}),l=o.getStableKey(c);a.has(l)||(a.add(l),i.push({ticks:c.map(u=>te(e,u)),source:"generated"}))}return i}return e.spec.scaleType==="datetime"?oo(e,t):[{ticks:e.generateTicks().map(a=>te(e,a)),source:"generated"}]},oo=(e,t)=>{const[r,n]=e.domain;if(!o.isStrictTemporalDataValue(r)||!o.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(c=>te(e,c)),source:"generated"}];const a=new Set,i=[],s=(c,l)=>{if(c.length===0)return;const u=o.getStableKey(c);a.has(u)||(a.add(u),i.push({ticks:c.map(d=>te(e,d)),valueFormat:l,source:"generated"}))};for(const c of _i)Mi({...c,start:r,stop:n})||Bi(c.unit,t)||s(e.generateTicks({interval:c}),ki(c,t));return s(e.generateTicks({atInputs:!0})),i.sort((c,l)=>c.ticks.length-l.ticks.length),i},so=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!o.isDefined(r)||!o.isDefined(n)||o.getStableKey([r])===o.getStableKey([n])?null:{ticks:[te(e,r),te(e,n)],source:"generated"}},te=(e,t)=>({value:t,position:e.map(t)});function Dr({scale:e,aesthetics:t,layers:r}){const n=co({layers:r,aesthetics:t}),a=Mr({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function co({layers:e,aesthetics:t}){const r=Mr({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>o.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function Mr({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(l=>o.isDefined(i.mapping[l]));if(s===void 0)continue;const c=o.readVariableName(i.mapping[s]);if(!(c===null||!i.data.hasVariable(c)))for(const l of i.data.getValues(c,{distinct:!0})){const u=o.getStableKey(l);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(o.getStableKey(a))}var st=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function lo({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!st(n))return[];if(!t.some(c=>o.isDefined(c.mapping.color)))return[];const a=W(t,"color");if(kr({colorVariableName:a,xVariableName:W(t,"x"),mapsColorAcrossMultipleLayers:mo(t)>1,sharesColorVariable:uo(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(c=>o.isDefined(c.mapping.color));return Dr({scale:n,aesthetics:["color"],layers:t}).map(({value:c,geom:l,owner:u})=>{const d=u?.layerIndex??s,m=t[d],f=m?o.readVariableName(m.mapping.color):null;return{value:c,color:String(n.map(c)),geom:l,layerIndex:d,valueFormat:M({layers:m?[m]:t,scaleType:i,variableName:f}),label:Pi(c,r)}})}var kr=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,sharesColorVariable:n})=>n?!1:e===null||o.isInternalVariable(e)?!r:t!==null&&e===t;function uo(e,t,r){if(r===null)return!1;for(const n of o.SCALED_VISUAL_AESTHETIC_KEYS){if(n==="color")continue;const a=e[n];if(!(a===void 0||!st(a))&&W(t,n)===r)return!0}return!1}var mo=e=>e.filter(t=>o.isDefined(t.mapping.color)).length;function Br(e,t){return e.get(t.geom).summaries.supportsPerGroupHeadline===!0}function fo(e,t,r,n){const a=r.findIndex(i=>Br(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:ot(o.readVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function Rt(e,t,r){if(r===null||t===null)return[...e];const n=o.getStableKey(r);return e.filter((a,i)=>o.getStableKey(t[i]??null)===n)}var $r=e=>e==="none"?"first":e,po=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Nt(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Nt(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},go=(e,t)=>{if(e.length<2)return null;const r=e.at(-1),n=t==="previous"?e.at(-2):e.at(0);return r===void 0||n===void 0||r.cross===null||n.cross===null||n.cross===0?null:{variation:(r.cross-n.cross)/n.cross,against:n.main}},Nt=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function ho(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?yo(e,n):vo(e,n)}function yo(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=o.readVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:M({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function vo(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:c}=e;if(!a.some(d=>Br(c,d)))return null;const l=fo(c,s,a,i);if(l.length===0)return null;const u=l.map(d=>bo({group:d,show:t,compareWith:r.headline.compareWith,layers:a,scales:n})).filter(d=>d!==null);return u.length===0?null:{kind:"perGroup",items:u}}function bo({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=o.readVariableName(i.mapping.y);if(s===null||i.data.getType(s)!=="numeric"||t==="total"&&i.position==="fill")return null;const c=o.readVariableName(i.mapping.x),l=o.readVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=M({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=To(i.data,c),f=M({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:c}),p=Io(i.data,c),g=p.getValues(s,{type:"numeric"}),h=c!==null?p.getValues(c):[],v=l!==null?p.getValues(l):null,y=Rt(g,v,e.value),b=Rt(h,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:po(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:f,label:e.label,caption:So(t,m,b),comparison:Ao(t,r,m,b,y)}}function So(e,t,r){if(e==="current"){const i=r.at(-1);return i===void 0?null:{kind:"point",value:i}}if(!t)return null;const n=r.at(0),a=r.at(-1);return n===void 0||a===void 0?null:{kind:"range",from:n,to:a}}function Ao(e,t,r,n,a){return e!=="current"||!r?null:go(n.map((i,s)=>({main:i,cross:a[s]??null})),$r(t))}function To(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Io(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}var Vo=new Set(["line","area"]);function xo(e,...t){return e?t.includes(e.geom):!1}function Eo(e,t){return e.find(r=>r.id===t)}function Oo(e,...t){return e.find(r=>t.includes(r.geom))}function wo(e,...t){return e.filter(r=>t.includes(r.geom))}function ie(e,t){return e.interactive?!1:t.some(r=>r!==e&&o.areMappingsEquivalent(r.mapping,e.mapping))}function Lo(e,t){return t.filter(r=>r!==e&&!r.interactive&&o.areMappingsEquivalent(e.mapping,r.mapping))}function Co(e,t){return t.find(r=>r.interactive&&ie(e,[r]))??e}function Po(e){return Vo.has(e)}function ct(e){const t=e.filter(r=>!ie(r,e));return t.length>0?t:[...e]}function jr({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=ct(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Ro=3;function No({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){const c=ct(r),l=Ho(s,t.legend.position,c);if(l==="none")return{drawn:[],position:"none"};const u=new Map(i.map(y=>[o.getStableKey(y.value),y])),d=Fo(ko({scales:e,layers:r})),m=W(r,"x"),f=d.map(y=>{if($o(y,m,r))return null;const b=Go({group:y,variableLabels:a,layers:r,colorGroupsByValue:u});return b.items.length===0?null:{group:y,built:b}}).filter(o.isDefined),p=_o(f),g=Xo(s,l,p,c,n);if(f.length===0)return{drawn:[],position:g};if(l==="auto"&&Wo(s,p,c,n))return{drawn:[],position:g};const h=Jo(t.legend.display,{legendPosition:g,coordSystem:n,layers:r}),v=h==="direct"?ts(c[0]):null;return{drawn:f.map(({built:y})=>Do(y,{position:g,display:h,align:t.legend.align},v)),position:g}}function _o(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function Do(e,t,r){const{position:n,display:a}=t,i=Mo(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function Mo(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function ko(e){const{scales:t,layers:r}=e,n=[];for(const a of o.SCALED_VISUAL_AESTHETIC_KEYS){const i=t[a];if(i===void 0||i.kind==="identity"||!Bo(a,r))continue;const s=W(r,a),c=es(a,i);n.push({scaledAesthetic:a,scale:i,variableName:s,guideType:c})}return n}function Bo(e,t){const r=o.getAestheticFromScaledAesthetic(e);return t.some(n=>o.isDefined(n.mapping[r]))}function $o(e,t,r){const[n]=e;return n.scaledAesthetic!=="color"?!1:kr({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:jo(n.scaledAesthetic,r),sharesColorVariable:e.length>1})}function jo(e,t){const r=o.getAestheticFromScaledAesthetic(e);return t.filter(n=>o.isDefined(n.mapping[r])).length>1}function Fo(e){const t=new Map;for(const r of e){const n=Qo(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function Uo(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Go({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>o.getAestheticFromScaledAesthetic(u.scaledAesthetic)),s=Dr({scale:a.scale,aesthetics:i,layers:r}),c=M({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),l=r.find(u=>i.some(d=>o.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaledAesthetic),title:ot(a.variableName,t),items:s.map(u=>Yo(u,e,i,c,n,l))}}function Yo(e,t,r,n,a,i){const s={};for(const l of t)Uo(s,l.scaledAesthetic,l.scale.map(e.value));if(s.lineType===void 0){const l=o.readConstantValue(e.owner?.layer.mapping.lineType);o.isLineType(l)&&(s.lineType=l)}const c=qo(e,t,r,n,a);return{value:e.value,label:Ko(t,e,a),visual:s,normalizedY:null,geom:e.geom,valueFormat:c,layerId:e.owner?.layer.id??i}}function Ko(e,t,r){return e[0].scaledAesthetic!=="color"?null:r.get(o.getStableKey(t.value))?.label??null}function qo(e,t,r,n,a){if(t[0].scaledAesthetic==="color")return a.get(o.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=zo(i,r);return i===void 0||s===null?n:M({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function zo(e,t){if(e===void 0)return null;for(const r of t){const n=e.mapping[r];if(n===void 0)continue;const a=o.readVariableName(n);if(a!==null)return a}return null}function Wo(e,t,r,n){if(t>1)return!1;const a=n.type==="polar";return r.some(i=>e.get(i.geom).legend.suppressWhenSingleItem||a)}function Ho(e,t,r){if(t!=="auto")return t;const n=new Set(r.map(i=>e.get(i.geom).legend.defaultPosition)),[a]=n;return n.size===1&&a!==void 0?a:"auto"}function Xo(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,c=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,o.isStackedPosition(u.position)&&(c=!0))}const l=r>=Ro;return i&&s?"top":i?l?"right":"top":c?Zo(a)?"top":l?"right":"top":"top"}function Jo(e,t){return e==="pill"?"pill":jr(t)?"direct":"pill"}function Zo(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Qo(e){const t=e.scale.domain.map(o.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function es(e,t){return st(t)?"discrete":`continuous:${e}`}function ts(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(o.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(l=>o.isDefined(o.getYMax(l))||o.isDefined(o.getY(l)));if(!n)return;const a=me(n);if(!o.isDefined(a))return;const i=o.getYMin(n),s=o.getYMax(n)??o.getY(n);if(!o.isDefined(s))return;const c=o.isDefined(i)?(i+s)/2:s;t.set(String(a),c)}),t}var rs=class extends o.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config.axes,e.config.legend,e.config.headline,e.layers,e.coordSystem,e.originalData]}run(e){const t=Li(e.originalData),r=lo({scales:e.scales,layers:e.layers,valueLabels:Ci(e.originalData,e.layers,t)}),n={scales:e.scales,config:e.config,layers:e.layers,coordSystem:e.coordSystem,variableLabels:t,colorGroups:r,geomRegistry:this.container.geomRegistry},a=ho(n),i=No(n),s={...i,drawn:ns(a,i.drawn)};return{axes:Gi(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},ns=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Ge=(e,t,r)=>{switch(e){case"group":return as(t);case"xValue":return lt(t,r)}},Fr=e=>{const t=o.readMainAxisVariable(e);return t===""?null:t},as=e=>o.getStableKey([me(e)]),lt=(e,t)=>o.getStableKey([t!==null?e[t]??null:null]);function Ur(e){return e===null?null:{strategy:e,composition:Gr()}}function Gr(){return{dimmed:!1,matchedLayer:null,overlayCandidates:[]}}var is=class extends H{constructor(e){super(),this.container=e,this.warningsByLayer=new WeakMap}compile(e){const t=super.compile(e);for(const r of t)for(const n of this.warningsByLayer.get(r)??[])this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,t){const r=e.highlight;if(r===null)return e;const n=t.highlights.filter(c=>this.takesHighlight(e,c,t.layers)&&!this.leavesOverlayToHost(e,c,t));if(n.length===0)return e;const a=[],i=os({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,warnings:a}),s={...e,highlight:{...r,composition:i}};return this.warningsByLayer.set(s,a),s}takesHighlight(e,{layerId:t},r){if(t===void 0||t===e.id)return!0;const n=r.find(a=>a.id===t);return n!==void 0&&n.interactive&&ie(e,[n])}leavesOverlayToHost(e,t,r){if(t.scope==="group"||e.highlight?.strategy!=="overlayAnchor")return!1;const n=i=>{const s=r.specLayers.find(c=>c.id===i);return s&&(0,F.pick)(s,["transforms","stat","position","yScaleType"])},a=n(e.id);return r.layers.some(i=>i.interactive&&i.highlight?.strategy==="overlayAnchor"&&ie(e,[i])&&(0,F.isEqual)(n(i.id),a)&&this.takesHighlight(i,t,r.layers))}};function os({layer:e,highlights:t,parsingLocale:r,strategy:n,warnings:a}){const i=t.filter(T=>{const V=z(T.predicate,e.data);for(const x of V)a.push({...x,message:`${x.message} Dropping this highlight.`});return V.length===0}),s=Fr(e.mapping),c=Pe(e,r),l=i.map(T=>({predicate:q(T.predicate,c),scope:T.scope})),u=l.some(({scope:T})=>T==="group"),d=l.some(({scope:T})=>T==="xValue"),m=n==="overlayAnchor",f=e.data.size(),p=u?new Array(f):null,g=d?new Array(f):null,h=m?new Array(f):null,v=new Uint8Array(f),y=new Set,b=new Set;let S=!1,A=0;for(const T of e.data){let V,x;p!==null&&(V=Ge("group",T,s),p[A]=V),g!==null&&(x=Ge("xValue",T,s),g[A]=x),h!==null&&(h[A]=T);for(const{predicate:U,scope:G}of l)if(U(T))switch(G){case"group":V!==void 0&&y.add(V);break;case"xValue":x!==void 0&&b.add(x);break;case"observation":v[A]=1,S=!0;break}A++}if(y.size===0&&b.size===0&&!S)return Gr();const I=new Uint8Array(f),E=[];let C=0;for(let T=0;T<f;T++){const V=p?.[T],x=g?.[T],U=V!==void 0&&y.has(V),G=x!==void 0&&b.has(x),O=v[T]===1;if(n==="observationRerender")(U||O||G)&&(I[T]=1,C++);else if(U)I[T]=1,C++;else if(O||G){const B=h?.[T];B!==void 0&&E.push({observation:B,observationIndex:T})}}const k=C>0?{...e,data:e.data.filterByMask(I)}:null;return{dimmed:(n==="observationRerender"||y.size>0)&&k!==null,matchedLayer:k,overlayCandidates:E}}var ss=o.prefixInternalVariable("__ungrouped__");function cs(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&o.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,c=i.map((l,u)=>{if(l===null)return null;const d=r[u]??ss;let m=s.get(d);return m||(m=new o.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(l)});n=n.addVariable(a,"temporal",c)}return n}function ls(e){const t=e.findIndex(Ye);return e.map((r,n)=>Ye(r)&&n!==t?{...r,heading:!1}:r)}function Ye(e){return e.heading===!0}function Ke(e){return"range"in e?e.key??e.range.join("-"):e.key??e.aesthetic}var Yr=()=>({defaults:[],overrides:[],warnings:[],observation:{vocabulary:o.STYLE_TARGETS.geom.vocabulary,aesthetics:o.STYLE_TARGETS.geom.aesthetics},dashPresets:o.DASH_PRESETS.line,parts:{}}),Kr="y",ut={kind:"group",name:Kr};function qr({contract:e,entries:t,mapping:r,derivedVariables:n}){const a=e.map(Wr),i=a.some(u=>!oe(u)),s=i?a:[...a,ut],c=[];for(const[u,d]of Object.entries(t)){const m=s.findIndex(p=>zr(p,u)),f=m===-1?ds(u,r,n):s.splice(m,1)[0];f===void 0||d===!1||c.push(d===!0?f:ms(f,d))}const l=[...c,...s];return{fields:c.some(oe)?l.map(u=>c.includes(u)?u:fs(u)):l,hidesDefaultRows:!i&&!l.some(u=>u.kind==="group")}}function us({layerId:e,contract:t,entries:r,mapping:n,derivedVariables:a}){const i=t.map(Wr),s=i.some(l=>!oe(l))?i:[...i,ut],c=l=>s.some(u=>zr(u,l))||n[l]!==void 0||a.includes(l);return Object.keys(r).filter(l=>!c(l)).map(l=>({code:"UNKNOWN_TOOLTIP_FIELD",message:`Layer '${e}' has no tooltip field '${l}'; its tooltip entry is ignored.`,context:{layerId:e,requested:l,available:ps(s,n,a)},suggestion:"Name an aesthetic the layer maps, a variable its geom derives, or a field of the geom's tooltip."}))}function oe(e){return e.kind!=="group"&&e.heading}function zr(e,t){return e.name===t||e.kind==="aesthetic"&&e.aesthetic===t}function Wr(e){return"range"in e?{kind:"range",name:Ke(e),title:e.key,range:e.range,heading:e.heading===!0}:{kind:"aesthetic",name:Ke(e),title:e.key,aesthetic:e.aesthetic,heading:e.heading===!0}}function ds(e,t,r){if(t[e]!==void 0)return{kind:"aesthetic",name:e,aesthetic:e,heading:!1};if(r.includes(e))return{kind:"variable",name:e,variable:e,heading:!1}}function ms(e,{title:t,format:r,heading:n}){const a={...t!==void 0&&{title:t},...r!==void 0&&{format:r}};return e.kind==="group"?n===!0?{kind:"aesthetic",name:e.name,aesthetic:Kr,heading:!0,...a}:{...e,...a}:{...e,...a,...n!==void 0&&{heading:n}}}function fs(e){return oe(e)?{...e,heading:!1}:e}function ps(e,t,r){return[...new Set([...e.map(n=>n.name),...Object.keys(t),...r])]}var gs=class extends H{constructor(e,t,r,n,a,i){super(),this.container=e,this.transformCompiler=t,this.statCompiler=r,this.groupCompiler=n,this.geomCompiler=a,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,_t(e),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},hasDiscreteXScale:_t(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,hasDiscreteXScale:n,coordType:a}){const i=we({data:t,mapping:r}).pipe(({data:c,mapping:l})=>{const u=this.statCompiler.compute(e.stat,{data:c,mapping:l,hasDiscreteXScale:n,params:{...e.params},requiredAesthetics:o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(e.geom))});return{data:u.data,mapping:u.mapping}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>({data:cs(c),mapping:l})).pipe(({data:c,mapping:l})=>{const u=this.geomCompiler.compile(e.geom,{data:c,mapping:l,params:e.params,coordType:a});return{data:u.data,mapping:{...l,...u.mapping}}}).pipe(({data:c,mapping:l})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:c,mapping:l,stackMissingAsZero:"missingValues"in e.params&&e.params.missingValues==="zero"});return{data:u.data,mapping:{...l,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,attachment:null,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:qr({contract:ls(s.tooltip),entries:e.tooltip,mapping:i.mapping,derivedVariables:s.derivedVariables}),scaleConstraints:s.scaleConstraints,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:Ur(s.highlightStrategy),styles:Yr()}}};function _t(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Hr(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new o.UserInputError(r)}}function dt(e,t){return t.map(r=>{const n=e.has(r.geom)?e.get(r.geom):void 0;return{...r,scaleConstraints:n?.scaleConstraints,categorySpanAxes:n?.categorySpanAxes}})}function hs(e){return e.some(t=>o.isStackedPosition(t.position)||t.scaleConstraints?.bandPadding===0)}function mt(e){const t=Xr(e),r={};for(const{layer:a,scaleConstraints:i,crossAxis:s}of t)i.includeZero===!0&&(r[s]={nice:(r[s]?.nice??!0)&&a.position!=="fill"});const n=t.find(({scaleConstraints:a})=>a.requireCrossAxisBands===!0);return{discreteAxis:t.some(({scaleConstraints:a})=>a.requireMainAxisBands===!0)?"x":null,discreteCrossAxis:n?.crossAxis??null,bandedAxes:Ss(t),zeroAxes:r,bandPadding:As(t),inferColorScale:t.some(({scaleConstraints:a})=>a.inferColorScale===!0),categorySpanAxis:e.some(o.spansCategoriesOnX)?"x":null}}function ys(e){const t=Xr(e);return vs(t)??bs(e,t)}function vs(e){for(const t of e){if(t.scaleConstraints.requireCrossAxisBands!==!0)continue;const r=e.find(n=>n.scaleConstraints.includeZero===!0&&n.crossAxis===t.crossAxis);if(r!==void 0)return{aesthetic:t.crossAxis,layers:[Q(t.layer,t.index,"band"),Q(r.layer,r.index,"zero-anchored")]}}return null}function bs(e,t){const r=e.findIndex(o.spansCategoriesOnX),n=e[r];if(n===void 0)return null;const a=t.find(({index:c,scaleConstraints:l})=>c!==r&&l.requireMainAxisBands===!0);if(a!==void 0)return{aesthetic:"x",layers:[Q(n,r,"category-span"),Q(a.layer,a.index,"band")]};const i=e.findIndex(c=>c.hasNonNumericX===!0&&!o.spansCategoriesOnX(c)),s=e[i];return s===void 0?null:{aesthetic:"x",layers:[Q(n,r,"category-span"),Q(s,i,"discrete")]}}var Q=(e,t,r)=>({layerId:e.id,layerIndex:t,geom:e.geom,shape:r});function Xr(e){const t=[];return e.forEach((r,n)=>{const{scaleConstraints:a,yScaleType:i}=r;a!==void 0&&t.push({layer:r,index:n,scaleConstraints:a,crossAxis:o.resolveScaledYAesthetic(i)})}),t}function Ss(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.requireMainAxisBands===!0&&t.add("x"),r.requireCrossAxisBands===!0&&t.add(n);return[...t]}function As(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Ts(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Ts({scaleConstraints:e,crossAxis:t}){return e.requireCrossAxisBands!==!0?["x"]:e.requireMainAxisBands===!0?["x",t]:[t]}function Is(e,t,r){const n=Jr(e,t);return t.map((a,i)=>{const s=n[i],c=s===void 0?void 0:t[s];if(c===void 0)return a;const l={layerId:c.id,on:yr(a,c)};return r(a,[l.layerId,...l.on],()=>({...a,attachment:l}))})}function Vs(e,t){const r=Jr(e,t);return t.flatMap((n,a)=>{const i=e[a]?.attachTo??"none";return i==="none"||i==="previous"?[]:r[a]!==void 0?[]:[{code:"UNKNOWN_LAYER_ID",message:`Layer '${n.id}' attaches to '${i}', which is not an interactive, unattached layer of this chart.`,suggestion:"Name the id of an interactive layer that is not itself attached, or use 'previous'.",context:{layerId:n.id,layerIndex:a}}]})}function Jr(e,t){const r=new Map,n=new Set,a=c=>t[c]?.interactive===!0&&!n.has(c)&&s(c)===void 0,i=c=>{const l=e[c]?.attachTo??"none";if(l==="none")return;if(l==="previous"){for(let d=c-1;d>=0;d-=1)if(a(d))return d;return}const u=t.findIndex(d=>d.id===l);return u!==-1&&a(u)?u:void 0},s=c=>{if(r.has(c))return r.get(c);n.add(c);const l=i(c);return n.delete(c),r.set(c,l),l};return t.map((c,l)=>s(l))}var xs=new Set(["label","group"]),Dt={band:"a band scale","zero-anchored":"a value axis anchored at zero","category-span":"a continuous scale of the intervals its categories span",discrete:"a discrete scale of the categories it maps there"},Es=(e,t,r)=>{if(r.some(a=>a.axis==="x"&&a.role==="scalar"&&a.aesthetic==="x"))return!1;const n=o.readVariableName(e.x);return!o.isDefined(n)||o.isInternalVariable(n)||!t.hasVariable(n)||t.size()===0?!1:t.getType(n)!=="numeric"},Os=({aesthetic:e,layers:t})=>e!=="x"?"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'.":t.some(r=>r.shape==="discrete")?"Drop one of the layers, or map the other layer's x to a numeric column.":"Drop one of the layers.",ws=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n,this.attachedLayerMemo=o.createPerKeyMemo(),this.resolvedLayersMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.layerCompiler.stats,this.attachedLayerMemo.stats,this.resolvedLayersMemo.stats)}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);this.checkPostCompile(e.layers,t);const r=Is(e.layers,t,this.attachedLayerMemo);return this.resolvedLayersMemo(r,()=>r)}checkPreCompile(e){const t=[],r=[];e.layers.forEach((n,a)=>{const i=this.transformCompiler.compile({data:e.data,transforms:n.transforms}),s={...e.mapping,...n.mapping};r.push(Es(s,i,this.container.geomRegistry.get(n.geom).positionRoles));const c={layerId:n.id,layerIndex:a,geom:n.geom,position:n.position,stat:n.stat,params:{...n.params},effectiveMapping:s,data:i,coordType:e.coords.coordType,dataLabels:n.dataLabels};t.push(...this.validateLayer(c));const l=[...this.collectUndeclaredAesthetics(c),...this.collectPanelJustifyWarnings(c),...this.collectDuplicateTooltipHeadings(c)];for(const u of l)this.container.diagnostics.addWarning(u)}),t.push(...this.validateSharedScaleDemands(e.layers,r)),Hr(this.container.diagnostics,t)}checkPostCompile(e,t){const r=[...this.collectEmptyDataset(t),...this.collectUnknownTooltipFields(e,t),...Vs(e,t)];for(const n of r)this.container.diagnostics.addWarning(n)}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:c}=i;if(!c||s!=="panelStart"&&s!=="panelEnd")return[];if(a==="polar"||!this.container.geomRegistry.get(e).composite)return[];if(!o.hasMultipleGroups(r,t))return[];const l=s==="panelEnd"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${s}' will render as '${l}'.`,context:{layerIndex:n,expected:l,actual:s},suggestion:`Use justify '${l}' for this layer.`}]}collectDuplicateTooltipHeadings({layerId:e,layerIndex:t,geom:r}){const{tooltip:n}=this.container.geomRegistry.get(r);return n.filter(Ye).slice(1).map(a=>({code:"DUPLICATE_TOOLTIP_HEADING",message:`Layer '${e}': geom '${r}' marks more than one tooltip field as the heading; '${Ke(a)}' is shown as a row`,context:{layerIndex:t,geom:r,..."aesthetic"in a?{aesthetic:a.aesthetic}:{}},suggestion:"Set `heading: true` on one tooltip field only."}))}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i}){const s=[],c=o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(r)),l=this.resolveComputedAesthetics(n,a);for(const u of c)l.has(u)||o.isDefined(i[u])||s.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${u}'`,context:{layerIndex:t,aesthetic:u}});return s}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const c=[],l=this.resolveComputedAesthetics(n,a),{derivedVariables:u}=this.container.geomRegistry.get(r),d=new Set(u);for(const[m,f]of Object.entries(i)){if(l.has(m))continue;const p=o.readVariableName(f);p===null||p===""||d.has(p)||s.hasVariable(p)||c.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return c}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const{positionRoles:c}=this.container.geomRegistry.get(r),l=this.resolveComputedAesthetics(n,a),u=[];for(const d of c){if(!o.POSITION_NUMERIC_ROLES.has(d.role)||!o.isDefined(d.aesthetic)||l.has(d.aesthetic)||d.role==="scalar"&&d.aesthetic===d.axis)continue;const m=o.readVariableName(i[d.aesthetic]);if(m===null||!s.hasVariable(m)||s.size()===0)continue;const f=s.getType(m);f!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aesthetic}' must be numeric, but variable '${m}' is ${f}`,context:{layerIndex:t,aesthetic:d.aesthetic,variableName:m,variableType:f},suggestion:this.suggestNumericAestheticFix(d.aesthetic,d.axis,i,s)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=o.readVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const{validateMapping:c}=this.container.geomRegistry.get(r);return c===void 0?[]:c({mapping:i,computedAesthetics:this.resolveComputedAesthetics(n,a),data:s}).map(l=>({...l,message:`Layer '${e}': ${l.message}`,context:{...l.context,layerIndex:t}}))}resolveComputedAesthetics(e,t){return this.statRegistry.get(e.type).resolveComputedAesthetics(e,t)}validateSharedScaleDemands(e,t){const r=ys(dt(this.container.geomRegistry,e).map((i,s)=>({...i,hasNonNumericX:!!t[s]})));if(r===null)return[];const[n,a]=r.layers;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r.aesthetic}' to be ${Dt[n.shape]}, but layer '${a.layerId}' (geom '${a.geom}') needs it to be ${Dt[a.shape]}. One scale cannot be both.`,context:{aesthetic:r.aesthetic,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:Os(r)}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const a=this.container.geomRegistry.get(r),i=o.spansCategoriesOnX(a)?a.supportedPositions.filter(s=>s!=="dodge"):a.supportedPositions;return i.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${i.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i}){const{positionRoles:s,categorySpanAxes:c,aesthetics:l}=this.container.geomRegistry.get(r),u=this.resolveComputedAesthetics(n,a),d=new Set([...o.deriveDeclaredAesthetics(s),...c,...l.map(p=>p.name)]),m=xs,f=[];for(const p of Object.keys(i))o.isDefined(i[p])&&(d.has(p)||m.has(p)||u.has(p)||f.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return f}collectEmptyDataset(e){return hr(e)?[{code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."}]:[]}collectUnknownTooltipFields(e,t){return e.flatMap((r,n)=>{const a=t[n];if(a===void 0||Object.keys(r.tooltip).length===0)return[];const i=this.container.geomRegistry.get(r.geom);return us({layerId:r.id,contract:i.tooltip,entries:r.tooltip,mapping:a.mapping,derivedVariables:i.derivedVariables})})}},Ls=class extends o.Stat{constructor(...e){super(...e),this.type="count",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.x);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'count' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'count' stat."});if(o.readVariableName(t.y)!==null)throw new o.UserInputError({code:"CONFLICTING_STAT_MAPPING",message:"Cannot map 'y' variable together with 'count' stat",context:{aesthetic:"y"},suggestion:"Remove the 'y' mapping; the 'count' stat computes it."});const n=[...new Set([r,...o.getGroupVariables(e,t)])];return{data:e.groupBy(...n).rollup({[o.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:o.STAT_VARIABLES.count}}}},Cs=class extends o.Stat{constructor(...e){super(...e),this.type="identity",this.computedAesthetics=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Ps=class extends o.Stat{constructor(...e){super(...e),this.type="mean",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'mean' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const n=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'mean' stat requires a numeric 'y' (got '${n}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:n},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."})}return{data:e.size()===0?new o.Dataset({[o.STAT_VARIABLES.mean]:{type:"numeric",values:[]}}):e.rollup({[o.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:o.STAT_VARIABLES.mean}}}},Rs=2,Zr=1440*60*1e3,Ns=class extends o.Stat{constructor(...e){super(...e),this.type="smooth",this.computedAesthetics=new Set}computeStat({data:e,mapping:t,spec:r,hasDiscreteXScale:n}){if(r.type!=="smooth")throw new o.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=o.readVariableName(t.x),i=o.readVariableName(t.y);if(!o.isDefined(a))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'smooth' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'smooth' stat."});if(!o.isDefined(i))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'smooth' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'smooth' stat."});const s=e.getType(a),c=e.getType(i);if(e.size()>0&&c!=="numeric")throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:c}});const l=o.getGroupVariables(e,t),u=js(a,s,i,l,e);return l.length===0?Mt({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},hasDiscreteXScale:n}):e.groupBy(...l).forEach(d=>{const m=Fs(d,l);Mt({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,hasDiscreteXScale:n})}),{data:u.build(),mapping:{}}}},Mt=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,hasDiscreteXScale:c})=>{const{observations:l,temporalOrigin:u}=_s({data:e,xVariable:t,yVariable:n,xType:r});l.length<Rs||(c?$s({observations:l,spec:a,output:i,groupObservation:s}):ks({observations:l,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},_s=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Ds(a):null,c=[],l=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!o.isDefined(d)||!o.isDefined(m)||!Number.isFinite(m))continue;const f=Ms({xValue:d,xType:n,categoryRank:l,temporalOrigin:s});f!==null&&c.push({x:f,y:m,originalX:d})}return{observations:c,temporalOrigin:s}},Ds=e=>{let t=null;for(const r of e){if(!o.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Ms=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!o.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!o.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/Zr+1}case"categorical":{if(!o.isStrictCategoricalDataValue(e))return null;const a=r.get(e);if(a!==void 0)return a;const i=r.size+1;return r.set(e,i),i}default:throw new o.InternalError({message:`Unexpected xType: ${t}`})}},ks=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Qr(n,e);for(const[c,l]of s){if(!Number.isFinite(c)||!Number.isFinite(l))continue;const u=t==="temporal"?Bs(c,r):c;a.push({x:u,y:l,groupObservation:i})}},Bs=(e,t)=>t===null?new Date(e):new Date((e-1)*Zr+t),$s=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const c of e)a.has(c.x)||a.set(c.x,c.originalX);const i=[...a.keys()].sort((c,l)=>c-l);if(t.method==="loess"){const c=Qr(t,e),l=new Map;for(const[u,d]of c)Number.isFinite(d)&&(l.has(u)||l.set(u,d));for(const u of i){const d=l.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=en(t,e);for(const c of i){const l=a.get(c),u=s.predict(c);l===void 0||!Number.isFinite(u)||r.push({x:l,y:u,groupObservation:n})}},Qr=(e,t)=>e.method==="loess"?(0,Y.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):en(e,t),en=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Y.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Y.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Y.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Y.regressionQuad)().x(r).y(n)(t);case"power":return(0,Y.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Y.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new o.InternalError({message:"'loess' does not expose a 'predict' function"})}},js=(e,t,r,n,a)=>{const i=[],s=[],c=Object.fromEntries(n.map(l=>[l,[]]));return{push:({x:l,y:u,groupObservation:d})=>{i.push(l),s.push(u);for(const m of n)c[m]?.push(d[m]??null)},build:()=>{const l={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)l[u]={type:a.getType(u),values:c[u]??[],valueFormat:a.getValueFormat(u)};return new o.Dataset(l)}}},Fs=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Us=class extends o.Stat{constructor(...e){super(...e),this.type="sum",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'sum' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const i=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'sum' stat requires a numeric 'y' (got '${i}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:i},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."})}const n=o.readVariableName(t.x),a=[...new Set([...n===null?[]:[n],...o.getGroupVariables(e,t)])];return{data:e.groupBy(...a).rollup({[o.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:o.STAT_VARIABLES.sum}}}},Gs=7,Be=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],Ys=300,Ks=1e-14,P=1e-300,qs=200;function tn(e,t){if(e===.5)return 0;if(e<.5)return-tn(1-e,t);let r=0,n=1;for(;Bt(n,t)<e;)r=n,n*=2;for(let a=0;a<qs;a++){const i=(r+n)/2;if(i===r||i===n)break;Bt(i,t)<e?r=i:n=i}return(r+n)/2}function Se(e){if(e<.5)return Math.log(Math.PI/Math.sin(Math.PI*e))-Se(1-e);const t=e-1;let r=Be[0]??0;for(let a=1;a<Be.length;a++)r+=(Be[a]??0)/(t+a);const n=t+Gs+.5;return .5*Math.log(2*Math.PI)+(t+.5)*Math.log(n)-n+Math.log(r)}function kt(e,t,r){const n=t+r;let a=1,i=1-n*e/(t+1);Math.abs(i)<P&&(i=P),i=1/i;let s=i;for(let c=1;c<=Ys;c++){const l=2*c;let u=c*(r-c)*e/((t+l-1)*(t+l));i=1+u*i,Math.abs(i)<P&&(i=P),a=1+u/a,Math.abs(a)<P&&(a=P),i=1/i,s*=i*a,u=-((t+c)*(n+c)*e)/((t+l)*(t+l+1)),i=1+u*i,Math.abs(i)<P&&(i=P),a=1+u/a,Math.abs(a)<P&&(a=P),i=1/i;const d=i*a;if(s*=d,Math.abs(d-1)<Ks)break}return s}function zs(e,t,r){if(e<=0)return 0;if(e>=1)return 1;const n=Se(t+r)-Se(t)-Se(r)+t*Math.log(e)+r*Math.log(1-e),a=Math.exp(n);return e<(t+1)/(t+r+2)?a*kt(e,t,r)/t:1-a*kt(1-e,r,t)/r}function Bt(e,t){const r=.5*zs(t/(t+e*e),t/2,.5);return e>=0?1-r:r}var Ws=new Set(["mean","median"]),Hs=new Set(["stderr","stdev","ci","iqr","range"]),Xs=new Set(["stderr","stdev","ci"]),Js=new Set(["iqr"]),Zs=new Set(["y"]),$t=new Set(["y","lower","upper"]),rn={lower:null,upper:null},Qs=class extends o.Stat{constructor(...e){super(...e),this.type="summary",this.computedAesthetics=$t}resolveComputedAesthetics(e){return e.type==="summary"&&e.interval===void 0?Zs:$t}computeStat({data:e,mapping:t,spec:r}){if(r.type!=="summary")throw new o.InternalError({message:`SummaryStat received a spec of type '${r.type}'`});ec(r);const n=o.readVariableName(t.y);if(!o.isDefined(n))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'summary' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'summary' stat."});if(e.size()>0&&e.hasVariable(n)&&e.getType(n)!=="numeric"){const p=e.getType(n);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'summary' stat requires a numeric 'y' (got '${p}' for variable '${n}')`,context:{aesthetic:"y",variableName:n,variableType:p},suggestion:"Map a numeric variable to 'y' when using the 'summary' stat."})}const a=o.readVariableName(t.x),i=[...new Set([...a===null?[]:[a],...o.getGroupVariables(e,t)])],s=e.groupBy(...i),c=ic(r.level),l=[],u=[];s.forEach(p=>{const g=tc(p,n);l.push(rc(g,r.estimate)),u.push(r.interval===void 0?rn:nc(g,r,r.interval,c))});const d=e.getValueFormat(n),m=s.rollup({}).addVariable(o.STAT_VARIABLES.summaryEstimate,"numeric",l,d);if(r.interval===void 0)return{data:m,mapping:{y:o.STAT_VARIABLES.summaryEstimate}};const f={y:o.STAT_VARIABLES.summaryEstimate,lower:o.STAT_VARIABLES.summaryLower,upper:o.STAT_VARIABLES.summaryUpper};return{data:m.addVariable(o.STAT_VARIABLES.summaryLower,"numeric",u.map(p=>p.lower),d).addVariable(o.STAT_VARIABLES.summaryUpper,"numeric",u.map(p=>p.upper),d),mapping:f}}};function ec({estimate:e,interval:t,level:r,mult:n}){if(Ws.has(e)||ge("estimate","'mean' or 'median'",e),t!==void 0){if(Hs.has(t)||ge("interval","'stderr', 'stdev', 'ci', 'iqr' or 'range'",t),e==="median"&&Xs.has(t))throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${t}' interval describes a mean, so it cannot surround a median`,context:{requested:"summary",param:"interval",expected:"'iqr' or 'range'",actual:t},suggestion:"Use estimate 'mean' with this interval, or interval 'iqr' or 'range' with a median."});if(e==="mean"&&Js.has(t))throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${t}' interval describes a median, so it cannot surround a mean`,context:{requested:"summary",param:"interval",expected:"'stderr', 'stdev', 'ci' or 'range'",actual:t},suggestion:"Use estimate 'median' with this interval, or interval 'stderr', 'stdev', 'ci' or 'range' with a mean."});t==="ci"&&!(Number.isFinite(r)&&r>0&&r<1)&&ge("level","a number between 0 and 1",r),(t==="stderr"||t==="stdev")&&!(Number.isFinite(n)&&n>0)&&ge("mult","a number greater than 0",n)}}function ge(e,t,r){throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${e}' must be ${t}, got ${String(r)}`,context:{requested:"summary",param:e,expected:t,actual:String(r)},suggestion:`Set '${e}' to ${t}.`})}function tc(e,t){return e.getValues(t).filter(r=>o.isStrictNumericDataValue(r)&&Number.isFinite(r))}function rc(e,t){return e.length===0?null:t==="mean"?nn(e):qe([...e].sort((r,n)=>r-n),.5)}function nc(e,t,r,n){const a=e.length,i=sc(e);if(a<2||i.lower===i.upper)return rn;switch(r){case"stderr":case"stdev":case"ci":{const s=nn(e),c=ac(r,oc(e,s),a,t.mult,n);return{lower:s-c,upper:s+c}}case"iqr":{const s=[...e].sort((c,l)=>c-l);return{lower:qe(s,.25),upper:qe(s,.75)}}case"range":return i;default:throw new o.InternalError({message:`Unexpected summary interval: ${String(r)}`})}}function ac(e,t,r,n,a){const i=t/Math.sqrt(r);return e==="stdev"?n*t:e==="stderr"?n*i:a(r-1)*i}function ic(e){const t=new Map;return r=>{const n=t.get(r);if(n!==void 0)return n;const a=tn(1-(1-e)/2,r);return t.set(r,a),a}}function nn(e){let t=0;for(const r of e)t+=r;return t/e.length}function oc(e,t){let r=0;for(const n of e)r+=(n-t)**2;return Math.sqrt(r/(e.length-1))}function sc(e){let t=1/0,r=-1/0;for(const n of e)n<t&&(t=n),n>r&&(r=n);return{lower:t,upper:r}}function qe(e,t){const r=(e.length-1)*t,n=Math.floor(r),a=e[n]??0;return a+((e[Math.min(n+1,e.length-1)]??a)-a)*(r-n)}var cc=[new Cs,new Ls,new Ns,new Ps,new Us,new Qs],an=class extends o.Registry{constructor(){super("stat");for(const e of cc)this.register(e.type,e)}};function lc({geoms:e,stats:t,transforms:r}){const n=new o.GeomRegistry,a=new an,i=new o.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}var uc=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Re=class{},dc=class extends Re{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!o.readVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),i=mc(e)??[-.7/2,.7/2],s=r.length>1?o.BAR_GROUP_SCALE_PADDING_FRACTION:0,c=(0,D.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),l=c.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const f=a[m];if(!o.isDefined(f))continue;const p=c(String(f));o.isDefined(p)&&(u[m]=p,d[m]=p+l)}return{data:e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",u).addVariable(o.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},mc=e=>{const t=e.getConstant(o.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(o.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},jt=o.prefixInternalVariable("__ungrouped__"),on=(e,t)=>{const r=o.readVariableName(t.x),n=o.readVariableName(t.y);if(!r||!n)return null;const a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[jt]:a,c=e.getValues(r),l=e.getValues(n,{type:"numeric"}),u=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let f=0;f<d;f++){const p=o.getStableKey(c[f]??null),g=u[f],h=i?jt:g;if(!o.isDefined(h))continue;let v=m.get(p);v||(v=new Map,m.set(p,v));let y=v.get(h);y||(y=[],v.set(h,y)),y.push(f)}return{yValues:l,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},sn=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let c=-1,l=1/0,u=-1/0,d=-1,m=1/0,f=-1/0;for(const p of i.values())for(const g of p){const h=e[g],v=t[g];!o.isDefined(h)||!o.isDefined(v)||(s.push(g),(h<l||h===l&&v>u)&&(c=g,l=h,u=v),(v>f||v===f&&h<m)&&(d=g,m=h,f=v))}for(const p of s)a[p]=fc(p===c,p===d)}return a},fc=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",pc=class extends Re{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t,stackMissingAsZero:r=!1}){const n=on(e,t);if(n===null)return{data:e,mapping:{}};const{yValues:a,observationIndicesByXAndGroup:i,uniqueGroupKeys:s,observationCount:c}=n,l=[...a],u=new Array(c).fill(0);for(const[,m]of i){let f=0,p=0;for(const v of s){const y=m.get(v);if(y!==void 0)for(const b of y){const S=a[b];S!=null&&(S>=0?f+=S:p-=S)}}let g=0,h=0;for(const v of s){const y=m.get(v);if(y!==void 0)for(const b of y){const S=a[b];if(S===void 0)continue;if(S===null){const E=r?g:null;u[b]=E,l[b]=E;continue}const A=S>=0?f:p;if(A===0){u[b]=0,l[b]=0;continue}const I=S/A;S>=0?(u[b]=g,l[b]=g+=I):(l[b]=h,u[b]=h+=I)}}}const d=sn(u,l,i,c);return{data:e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",u).addVariable(o.POSITION_VARIABLES.yMax,"numeric",l).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",a).addVariable(o.STACK_VARIABLES.role,"categorical",d),mapping:{}}}},gc=class extends Re{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},hc=class extends Re{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t,stackMissingAsZero:r=!1}){const n=on(e,t);if(n===null)return{data:e,mapping:{}};const{yValues:a,observationIndicesByXAndGroup:i,uniqueGroupKeys:s,observationCount:c}=n,l=[...a],u=new Array(c).fill(0);for(const[,p]of i){let g=0,h=0;for(const v of s){const y=p.get(v);if(y!==void 0)for(const b of y){const S=a[b];if(S!==void 0){if(S===null){const A=r?g:null;u[b]=A,l[b]=A;continue}S>=0?(u[b]=g,l[b]=g+=S):(l[b]=h,u[b]=h+=S)}}}}const d=sn(u,l,i,c);let m=e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",u).addVariable(o.POSITION_VARIABLES.yMax,"numeric",l).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",a).addVariable(o.STACK_VARIABLES.role,"categorical",d);const f=o.readVariableName(t.y);if(f!==null){const p=l.map((g,h)=>a[h]===null?null:g);m=m.addVariable(f,"numeric",p)}return{data:m,mapping:{}}}},yc=class extends o.Registry{constructor(){super("position"),this.register("identity",new gc),this.register("stack",new hc),this.register("fill",new pc),this.register("dodge",new dc)}},vc=class{map({data:e,layer:t,getPositionScale:r}){if(t.position!=="dodge"||!o.isDefined(r("x")?.bandwidth)||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s=n.map((c,l)=>{const u=a[l],d=i[l];return o.isDefined(u)&&o.isDefined(d)?(u+d)/2:c});return e.addVariable(o.POSITION_VARIABLES.xBand,"numeric",n).addVariable(o.POSITION_VARIABLES.x,"numeric",s)}},bc=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!o.isDefined(s.aesthetic)||o.isVisualScale(s.aesthetic))continue;const c=o.readVariableName(t.mapping[s.aesthetic]);if(!o.isDefined(c)||!a.hasVariable(c))continue;const l=r(o.resolvePositionScaledAesthetic(s.axis,t.yScaleType));if(!l)continue;const u=a.getValues(c,{type:"numeric"}).map(d=>o.isDefined(d)?l.map(d):null);a=a.addVariable(o.resolveScaledAestheticVariable(s.aesthetic),"numeric",u)}return a}},Sc=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){const a=o.readVariableName(t.mapping.x),i=r("x");if(!a||!i)return e;if(o.spansCategoriesOnX(n.get(t.geom)))return Ac(e,i);const s=e.getValues(a).map(c=>o.isDefined(c)?i.map(c):null);return e.addVariable(o.POSITION_VARIABLES.x,"numeric",s)}};function Ac(e,t){if(!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=r.map((i,s)=>{const c=n[s];return o.isDefined(i)&&o.isDefined(c)?(t.map(i)+t.map(c))/2:null});return e.addVariable(o.POSITION_VARIABLES.x,"numeric",a)}var Tc=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=o.isDefined(n)&&e.hasVariable(o.POSITION_VARIABLES.x)?Ic(e,r,n):Vc(e,r);return e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(o.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Ic(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=cn(c);for(let u=0;u<c;u++){const d=n[u],m=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(m)||!o.isDefined(f)||(l.min[u]=d+(s?-f:m)*r,l.max[u]=d+(s?-m:f)*r)}return l}function Vc(e,t){const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=cn(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function cn(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var xc=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.y),a=r(o.resolveScaledYAesthetic(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.y,"numeric",i)}},Ec=class{map({data:e,layer:t,getPositionScale:r}){const n=r(o.resolveScaledYAesthetic(t.yScaleType));if(!n||!e.hasVariable(o.POSITION_VARIABLES.yMin)||!e.hasVariable(o.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=o.isDefined(a)&&e.hasVariable(o.POSITION_VARIABLES.y)?Oc(e,n,a):wc(e,n);return e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(o.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Oc(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=ln(c);for(let u=0;u<c;u++){const d=n[u],m=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(m)||!o.isDefined(f)||(l.min[u]=d+(s?-f:m)*r,l.max[u]=d+(s?-m:f)*r)}return l}function wc(e,t){const r=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=ln(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function ln(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Lc=[new Sc,new xc,new Tc,new Ec,new vc,new bc];function Cc(e,t){const r=e[t];return r?.kind==="position"?r:null}var Pc=class extends H{constructor(e,t=Lc){super(),this.container=e,this.mappers=t}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,t){const r=a=>Cc(t.scales,a);let n=e.data;for(const a of this.mappers)n=a.map({data:n,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:n}}},Ft=e=>{const t=e.find(n=>n.scaledAesthetic==="color"),r=t?.scaleType==="discrete"?t.range?.[0]:void 0;return typeof r=="string"?r:void 0},Rc=(e,t)=>(o.BRICK_TONES_BY_COUNT[e][t]??o.BRICK_TONES_BY_COUNT[e].default).map(r=>o.BRICK_TONES[r]),Nc=(e,t)=>{const r=e.palettes?.categorical;return r!==void 0&&r.length>0?r:e.hasTouchingGeoms?Rc(e.colorScheme,t):o.DEFAULT_COLOR_PALETTE},N={transform:"linear",reverse:!1,nice:!0,domainMin:null,domainMax:null,range:null,interpolate:"lab",domainMid:null,symmetric:!1},Ut={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},he={domainMin:null,domainMax:null,nice:!1,reverse:!1},ee={range:null,domain:null,padding:.1,reverse:!1},_c={rgb:ne.interpolateRgb,lab:ne.interpolateLab,hcl:ne.interpolateHcl,hsl:ne.interpolateHsl};function xe(e){const t=Mc(e);return e.reverse?r=>t(1-r):t}function Dc(e={},t=2){const r=xe(e);return Array.from({length:t},(n,a)=>r(t===1?0:a/(t-1)))}var un=({diverging:e=!1,palettes:t,range:r})=>Gt(r)??Gt(e?t?.diverging:t?.sequential)??(e?o.DEFAULT_DIVERGING_STOPS:o.DEFAULT_SEQUENTIAL_STOPS),Mc=e=>{const t=un(e),r=_c[e.interpolate??N.interpolate];return(0,ne.piecewise)(r,t.map(String))},Gt=e=>e!=null&&e.length>=2?e:void 0,kc=class extends o.Stage{constructor(e,t){super(),this.container=e,this.registry=t}compile(e){const t=super.compile(e);return this.warnEvenDivergingRamp(t),t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:hs(e.layers),zeroAxes:mt(e.layers).zeroAxes,palettes:this.container.theme?.palettes},a={};for(const[i,s]of t){const c=r.get(i)??[],l=s.scaleType==="discrete"?Pr(s,e.layers):s;a[i]=this.registry.get(l.scaleType).compile(l,c,n)}return a}warnEvenDivergingRamp(e){const t=e.color;if(t?.spec.scaleType!=="continuous"||t.domain.length!==3)return;const r=un({...t.spec,diverging:!0,palettes:this.container.theme?.palettes});r.length%2!==1&&this.container.diagnostics.addWarning({code:"EVEN_DIVERGING_RAMP",message:`Diverging colormap has ${r.length} stops. The midpoint blends the two central colors.`,context:{aesthetic:"color",scaleType:"continuous",actual:r.length},suggestion:"Use an odd number of stops with the neutral color in the middle."})}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=o.getAestheticFromScaledAesthetic(r.scaledAesthetic);for(const i of e.layers){if((r.scaledAesthetic==="y"||r.scaledAesthetic==="ySecondary")&&o.resolveScaledYAesthetic(i.yScaleType)!==r.scaledAesthetic||!o.isDefined(i.mapping[a])||r.scaleType==="continuous"&&this.spansCategoriesOf(i,a))continue;const s=o.readVariableName(i.mapping[a]);if(!o.isDefined(s)||o.isInternalVariable(s)||!i.data.hasVariable(s)||i.data.size()===0)continue;const c=i.data.getType(s);if(!n.includes(c)){const l=r.scaleType==="continuous"&&c==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${c})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}if(r.scaledAesthetic==="lineType"&&c!=="categorical"){const l=c==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${s}'. ${l}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}}}Hr(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!o.isDefined(s))continue;const c=i==="y"?o.resolveScaledYAesthetic(n.yScaleType):i,l=a.get(i)??(o.isScaledAestheticKey(c)?c:void 0);if(!o.isDefined(l)||!t.has(l))continue;const u=t.get(l)?.scaleType,d=this.spansCategoriesOf(n,i)?[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.xMax].filter(m=>n.data.hasVariable(m)):this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,l,r)}}return r}spansCategoriesOf(e,t){return t==="x"&&o.spansCategoriesOnX(this.container.geomRegistry.get(e.geom))}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!o.isDefined(n.aesthetic)||o.isVisualScale(n.aesthetic)||t.set(n.aesthetic,o.resolvePositionScaledAesthetic(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];const a=o.readVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(o.POSITION_VARIABLES.yMin)&&e.hasVariable(o.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Ne=class{createPositionScale(e,t){return{kind:"position",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,...t}}},ze=(e,t,r)=>{const[n,a]=e;return t===0&&r===null&&a<=0?{domain:[n,0],pinnedLow:!1,pinnedHigh:!0}:r===0&&t===null&&n>=0?{domain:[0,a],pinnedLow:!0,pinnedHigh:!1}:{domain:[t??n,r??a],pinnedLow:t!==null,pinnedHigh:r!==null}};function Bc(e){const[t,r]=e.domain;return t>0?{...e,domain:[0,r],pinnedLow:!0}:r<0?{...e,domain:[t,0],pinnedHigh:!0}:e}function We(e,t){return[t.pinnedLow?t.domain[0]:e[0],t.pinnedHigh?t.domain[1]:e[1]]}var $c=class extends Ne{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t,r){if(e.scaleType!=="continuous")throw new o.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const n=o.isPositionScale(e.scaledAesthetic),a=e.scaledAesthetic==="color",i=this.computeDataDomain(t);return a?this.buildColorScale(i,e,r.palettes):n?this.buildPositionScale(i,e,r.zeroAxes[e.scaledAesthetic]!==void 0):this.buildVisualScale(i,e)}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e)typeof n!="number"||!Number.isFinite(n)||(n<t&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}createD3Scale(e,t,r,n=!1){const a=ze(e,r.domainMin,r.domainMax),i=n?Bc(a):a;let s=i.domain;n&&jc(a,i)&&this.warnIncompatibleDomain(r,a.domain,`'${r.scaledAesthetic}' holds zero for the geom drawn on it, so the pin at [${a.domain[0]}, ${a.domain[1]}] gives way to [${s[0]}, ${s[1]}].`,`Pin '${r.scaledAesthetic}' at or past zero, or drop the pin.`);const c=r.transform==="log"&&Fc(s);r.transform==="log"&&!c&&this.warnIncompatibleDomain(r,s,`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${s[0]}, ${s[1]}] — rendering a linear scale instead.`,n?`'${r.scaledAesthetic}' holds zero for the geom drawn on it; use a linear or sqrt transform.`:"Filter out non-positive values or set a positive domainMin so the log scale can apply.");const l=c?(0,D.scaleLog)():r.transform==="sqrt"?(0,D.scaleSqrt)():(0,D.scaleLinear)();return r.nice&&!c&&(s=We(l.copy().domain(s).nice().domain(),i)),l.domain(s).range(t).clamp(r.clamp)}warnIncompatibleDomain(e,t,r,n){this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:r,context:{aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),scaleType:e.scaleType,actual:t},suggestion:n})}buildPositionScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t,r);return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildVisualScale(e,t){const r=Uc(t.range)??[0,1],n=t.reverse?[r[1],r[0]]:r,a=this.createD3Scale(e,n,t);return this.createVisualScale(t,{map:a,domain:a.domain(),generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildColorScale(e,t,r){const n=t.domainMid;if(n!==null){const a=this.resolveColorDomain(e,t),[i,s]=a.domain;if(n>i&&n<s){const[c,l]=this.symmetrizeDomain(a,t,n),u=xe({...t,diverging:!0,palettes:r});return this.buildDivergingColorScale([c,n,l],t,u)}}return this.buildSequentialColorScale(e,t,xe({...t,palettes:r}))}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,D.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){const r=ze(e,t.domainMin,t.domainMax);if(!t.nice)return r;const n=(0,D.scaleLinear)().domain(r.domain).nice().domain();return{...r,domain:We(n,r)}}symmetrizeDomain(e,t,r){const{domain:n,pinnedLow:a,pinnedHigh:i}=e;if(!t.symmetric)return n;const s=Math.max(Math.abs(n[0]-r),Math.abs(n[1]-r));return[a?n[0]:r-s,i?n[1]:r+s]}},jc=(e,t)=>e.pinnedLow&&e.domain[0]!==t.domain[0]||e.pinnedHigh&&e.domain[1]!==t.domain[1],Fc=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Uc(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Gc=class extends Ne{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new o.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=o.isPositionScale(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:"Datetime scale is not supported for non-position aesthetics",context:{aesthetic:e.scaledAesthetic},suggestion:"Use a continuous or discrete scale for non-position aesthetics (color, size, alpha, strokeWidth)."});return this.buildScale(n,e,this.collectInputDates(t))}collectInputDates(e){const t=new Set,r=[];for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();t.has(a)||(t.add(a),r.push(n))}return r.sort((n,a)=>n.getTime()-a.getTime()),r}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();a<t&&(t=a),a>r&&(r=a)}return t===1/0?[]:[new Date(t),new Date(r)]}createD3Scale(e,t,r){const n=(0,D.scaleUtc)().range(t).clamp(r.clamp);if(!Yc(e))return n.domain([]);const a=ze([e[0].getTime(),e[1].getTime()],r.domainMin,r.domainMax);if(n.domain(a.domain),r.nice){const[i,s]=n.nice().domain();i!==void 0&&s!==void 0&&n.domain(We([i.getTime(),s.getTime()],a))}return n}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),c=i&&s?r.filter(l=>l>=i&&l<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&s?Di(i,s,l.interval):[]:a.ticks(l?.count)})}},Yc=e=>e.length===2&&o.isStrictTemporalDataValue(e[0])&&o.isStrictTemporalDataValue(e[1]),Kc=class extends Ne{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t,r){if(e.scaleType!=="discrete")throw new o.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const n=o.isPositionScale(e.scaledAesthetic),a=Cr(t,e);if(n)return this.buildPositionScale(a,e);const i=e.scaledAesthetic==="color"?Nc(r,a.length):void 0;return this.buildVisualScale(a,e,i)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??ee.padding,a=t.reverse?[1,0]:[0,1],i=(0,D.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:c=>(i(String(c))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t,r){const n=e.map(String),a=t.range&&t.range.length>0?t.range:r,i=a&&a.length>0?(0,D.scaleOrdinal)().domain(n).range(a).unknown(a[0]):null,s=qc(t.scaledAesthetic,a);return this.createVisualScale(t,{map:c=>{const l=String(c);return i?i(l):l},domain:e,generateTicks:()=>e,...s===void 0?{}:{palette:s},...r===void 0?{}:{defaultPalette:r}})}},qc=(e,t)=>{if(e!=="color"||t===void 0||t.length===0)return;const r=[];for(const n of t){if(typeof n!="string")return;r.push(n)}return r},zc=class extends Ne{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new o.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Wc=class extends o.Registry{constructor(e){super("scale"),this.register("continuous",new $c(e)),this.register("discrete",new Kc),this.register("datetime",new Gc),this.register("identity",new zc)}},dn={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Hc={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 ft(e,t){const{data:r,layers:n,mapping:a}=t;return{container:e,data:r,layers:n,mapping:a,demands:mt(dt(e.geomRegistry,n))}}function _e(e,t){switch(t.scaleType){case"inferred":return{..._e(e,el(e,t)),inferredFrom:t};case"continuous":{const r=dn[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in Ut?Ut[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":N.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??N.reverse,nice:t.nice??N.nice,clamp:t.clamp??r!=="position",domainMin:t.domainMin??N.domainMin,domainMax:t.domainMax??N.domainMax,range:t.range??n??null,interpolate:t.interpolate??N.interpolate,domainMid:t.domainMid??N.domainMid,symmetric:t.symmetric??o.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??he.domainMin,domainMax:t.domainMax??he.domainMax,nice:t.nice??he.nice,reverse:t.reverse??he.reverse,clamp:t.clamp??!1};case"discrete":return mn(t,e.demands);case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new o.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Xc(e,t){const{scales:r,layers:n,mapping:a,coords:i}=t,s=ft(e,t),c=il(al(rl(e,r,n,a),n),s.demands),l=new Map;for(const d of c)l.set(d.scaledAesthetic,d);const u=[...l.values()].map(d=>{const m=Zc(s,Jc(s,d));return _e(s,m)});return i.coordType==="polar"?u.map(pt):u}function mn(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??ee.range,domain:e.domain??ee.domain,padding:e.padding??r??ee.padding,reverse:e.reverse??Qc(e.scaledAesthetic,t)}}var pt=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Jc(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:o.getAestheticFromScaledAesthetic(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),o.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Zc(e,t){return t.scaleType==="inferred"||t.scaledAesthetic!==e.demands.categorySpanAxis?t:t.scaleType==="continuous"?{...t,nice:t.nice??!1}:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom spanning categories on '${t.scaledAesthetic}' needs it to be a continuous scale, but the spec declares a '${t.scaleType}' one; continuous wins.`,context:{aesthetic:o.getAestheticFromScaledAesthetic(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a continuous scale, or omit it and let it be inferred.`}),o.continuous(t.scaledAesthetic,{nice:!1,..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Qc(e,t){return e===t?.discreteCrossAxis?!0:ee.reverse}function el({data:e,layers:t,mapping:r,demands:n},a){const i=tl(t,r,a.scaledAesthetic);if(a.scaledAesthetic===n.categorySpanAxis){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,nice:d?.nice??!1})}if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return o.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,...!s.nice&&{nice:!1}})}const c=o.readVariableName(i);if(!o.isDefined(c)||!e.hasVariable(c)||e.size()===0)return o.continuous(a.scaledAesthetic,a.options);const l=e.getType(c),u=dn[a.scaledAesthetic];switch(Hc[l][u]){case"discrete":return o.discrete(a.scaledAesthetic,a.options);case"datetime":return o.datetime(a.scaledAesthetic,a.options);case"continuous":return o.continuous(a.scaledAesthetic,a.options);default:return o.identity(a.scaledAesthetic)}}function tl(e,t,r){const n=o.getAestheticFromScaledAesthetic(r);for(const a of fn(r,e)){const i=a.mapping[n]??t[n];if(o.isDefined(o.readVariableName(i)))return i}return t[n]}function fn(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}function rl(e,t,r,n){const a=["x","y"].filter(i=>!t.some(s=>s.scaledAesthetic===i)&&fn(i,r).some(s=>nl(e,s,i,n)));return[...t,...a.map(i=>o.inferred(i))]}function nl(e,t,r,n){return e.statRegistry.get(t.stat.type).resolveComputedAesthetics(t.stat,{...t.params}).has(r)?!0:[r,...e.geomRegistry.get(t.geom).positionRoles.filter(a=>a.axis===r).map(a=>a.aesthetic??r)].some(a=>!!o.readVariableName(t.mapping[a]??n[a]))}function al(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,o.inferred("ySecondary")]}function il(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferColorScale?o.inferred("color"):o.discrete("color")]}var gt=class extends o.Stage{constructor(e){super(),this.registry=e}key(e){return e.data}dependencies(e){return[e.transforms]}run(e){return e.transforms.reduce((t,r)=>this.registry.get(r.transformType).apply(t,r),e.data)}},pn=new o.TransformRegistry,ol=new gt(pn),gn=(e,t)=>{const r=t.every(n=>pn.has(n.transformType));return t.length===0||!r?e:ol.compile({data:e,transforms:t})},Yt=0;function w(){return Yt+=1,`${Math.random().toString(36).slice(2,6)}${Yt.toString(36)}`}var sl={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},topLeft:{x:-1,y:-1},topRight:{x:1,y:-1},bottomLeft:{x:-1,y:1},bottomRight:{x:1,y:1}},cl=(e,t,r)=>{const n=ll(e,t),a=ml(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>pl(e,i,r)).filter(o.isDefined),shapes:(n.shapes??[]).map(i=>vl(e,i,a)).filter(o.isDefined),arrows:(n.arrows??[]).map(i=>Al(e,i,r,a)).filter(o.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>fl(e,i,r,a)).filter(o.isDefined),stickers:(n.stickers??[]).map(i=>gl(e,i,r,a)).filter(o.isDefined),images:(n.images??[]).map(i=>bl(e,i,a)).filter(o.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>hl(e,i,r)).filter(o.isDefined),comments:(n.comments??[]).map(i=>yl(e,i,r)).filter(o.isDefined)}},ll=(e,t)=>{if(t===void 0)return{};if(!ul(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:w()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},ul=e=>{const t=new Set;for(const r of dl(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},dl=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],ml=e=>{const t=new Set,r=[e.differenceArrows,e.shapes,e.arrows,e.textAnnotations,e.images,e.stickers,e.pinnedNumbers,e.comments];for(const n of r)for(const a of n??[])a.id!==void 0&&t.add(a.id);return t},ht=(e,t,r,n)=>{if(r.has(t))return!0;const a=n===void 0?"An annotation":`Annotation "${n}"`;return e.diagnostics.addWarning({code:"ANNOTATION_REF_NOT_FOUND",message:`${a} references id "${t}" but no annotation declares that id — dropping this annotation.`,context:{ref:t,...n!==void 0?{annotationId:n}:{}},suggestion:"Reference the explicit id of another annotation in the same spec, or set an id on the target."}),!1},fl=(e,t,r,n)=>{const a=Ee(e,t.at,r,n,t.id);return a===null?null:{id:t.id??w(),content:t.content,at:a,width:t.width,align:t.align??o.TEXT_ANNOTATION_DEFAULTS.align}},pl=(e,t,r)=>{const n=se(e,t.start,r),a=se(e,t.end,r);return n===null||a===null?null:{id:t.id??w(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??o.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},se=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},Ee=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return ht(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=se(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},gl=(e,t,r,n)=>{const a=Ee(e,t.at,r,n,t.id);return a===null?null:{id:t.id??w(),at:a,sticker:t.sticker}},hl=(e,t,r)=>{const n=se(e,t.at,r);return n===null?null:{id:t.id??w(),at:n}},yl=(e,t,r)=>{const n=se(e,t.at,r);return n===null?null:{id:t.id??w(),at:n,content:t.content}},vl=(e,t,r)=>t.region.anchorType==="annotation"&&!ht(e,t.region.ref,r,t.id)?null:{id:t.id??w(),kind:t.kind??o.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??o.SHAPE_DEFAULTS.zOrder,region:Sl(t.region)},bl=(e,t,r)=>t.region.anchorType==="annotation"&&!ht(e,t.region.ref,r,t.id)?null:{id:t.id??w(),src:t.src,zOrder:t.zOrder??o.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??o.IMAGE_ANNOTATION_DEFAULTS.fit},Sl=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:o.SELECTION_PADDING_DEFAULT},Kt=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=sl[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Al=(e,t,r,n)=>{const a=Ee(e,t.start,r,n,t.id),i=Ee(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??w(),start:Kt(a),end:Kt(i),startArrowheadStyle:t.startArrowheadStyle??o.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??o.ARROW_DEFAULTS.endArrowheadStyle}},Tl={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{visible:!0,label:null,position:"bottom",grid:{visible:null},ticks:{visible:!0,mode:"auto"}},y:{visible:!0,label:null,position:"right",grid:{visible:null},ticks:{visible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},tooltip:{mode:"band"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,showTitle:!0,subtitle:null,showSubtitle:!0,caption:null,showCaption:!1,source:null,showSource:!1,graphyBadge:{visible:!1,position:"footer",variant:"full"}}};function hn(e,t){return(0,F.merge)({},Tl,t,e)}var Il={xLimits:null,yLimits:null},Ae={theta:"x",startAngle:0,innerRadius:0};function yn(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,F.merge)({},Il,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Ae.theta,startAngle:t.params?.startAngle??Ae.startAngle,innerRadius:(0,F.clamp)(t.params?.innerRadius??Ae.innerRadius,0,1)}}}}function Vl(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??w(),predicate:a.predicate,scope:a.scope??"observation",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var xl=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"userInput"};t.persistent?this.persistent.push(r):this.diagnostics.push(r)}addError(e){this.diagnostics.push({...e,severity:"error",kind:"userInput"})}reset(){this.diagnostics=[]}drain(){const e=this.persistent.length===0?this.diagnostics:[...this.persistent,...this.diagnostics];if(e.length===0)return{errors:[],warnings:[]};const t=qt(e.filter(n=>n.severity==="error")),r=qt(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},El=class{constructor(e,t){this.sink=e,this.baseContext=t}addWarning(e,t){this.sink.addWarning(this.stampBaseContext(e),t)}addError(e){this.sink.addError(this.stampBaseContext(e))}stampBaseContext(e){const t=e.context??{};return{...e,context:{...t,...this.baseContext}}}};function qt(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var vn={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:o.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4},Ol={stat:{type:"identity"},position:"identity",params:{}},wl={stat:{type:"identity"},position:"identity",params:{curve:"linear",missingValues:"gap"}},Ll={stat:{type:"identity"},position:"stack",params:{curve:"linear",missingValues:"zero"}},Cl={stat:{type:"identity"},position:"dodge",params:{}},Pl={stat:{type:"identity"},position:"identity",interactive:!1,params:{labelPosition:"start"}},Rl={stat:{type:"identity"},position:"identity",params:{}};function bn(e,t){const r=e??(typeof t=="string"?t:t.type),n=typeof r=="string"?r:r.type;if(n==="smooth"){const a=typeof r=="string"?void 0:r;return{type:"smooth",method:a?.method??"linear",order:a?.order??3,bandwidth:a?.bandwidth??.3}}if(n==="summary"){const a=typeof r=="string"?void 0:r,i=a?.interval??void 0;return{type:"summary",estimate:a?.estimate??"mean",...i!==void 0&&{interval:i},level:a?.level??.95,mult:a?.mult??1}}return{type:n}}function Sn(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new El(a,{layerIndex:i}):a,c=e.get(n.geom),l=n.position??c.defaultPosition,u=Dl({dataLabels:kl(e,t,n,l,r),geom:c,position:l,coordType:r,diagnostics:s});return _l({diagnostics:s,coordType:r,geom:c,position:l,dataLabels:u}),{id:n.id??w(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:bn(n.stat,c.defaultStat??"identity"),position:l,yScaleType:n.yScaleType??"primary",params:c.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??c.defaultInteractive,attachTo:n.attachTo??c.defaultAttachTo,tooltip:n.tooltip??{},dataLabels:u}}function Nl(e,t,r,n,a){const i=n.map((s,c)=>Sn(e,t,r,s,a,c));return Tn(e,i)}var An=(e,t,r,n)=>n.label!==void 0?n.label:vr({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Tn=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:et(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=o.readConstantValue(n.mapping.y);if(!o.isStrictNumericDataValue(a))return n;const i=(0,F.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},_l=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&o.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},Dl=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panelStart"&&i!=="panelEnd")return e;const c=Ml(t,r,n);if(c===null)return e;const l=i==="panelEnd"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${c}; justify '${i}' will render as '${l}'.`,context:{expected:l,actual:i},suggestion:`Use justify '${l}' for this layer.`}),{...e,justify:l}},Ml=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&o.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,kl=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=An(e,r.geom,n,i),c=e.get(r.geom);return{...(0,F.merge)({},vn,c.resolveDataLabelDefaults?.(n)??{},c.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},In=e=>{const t={tokens:{},defaults:[],overrides:[]};for(const r of Bl(e))Object.assign(t.tokens,r.tokens),t.defaults.push(...r.defaults??[]),t.overrides.push(...r.overrides??[]);return t},Bl=e=>{const t=[],r=new Set,n=e===void 0?[]:[e];for(;n.length>0;){const a=n.pop();if(!(a===void 0||r.has(a))){r.add(a),t.push(a);for(const i of a.extends??[])n.push(i)}}return t.reverse()};function $l(e,t){const r=yn(t.coords),n=Nl(e.geomRegistry,t.mapping,r.coordType,t.layers,e.diagnostics),a=Xc(e,{data:gn(t.data,t.transforms),scales:t.scales,layers:n,mapping:t.mapping,coords:r}),i=hn(t.config,e.theme?.config),s=Vl(e,t.highlights,n),c=cl(e,t.annotations,n),l=In(t.styles);return{data:t.data,mapping:t.mapping,layers:n,scales:a,transforms:t.transforms,highlights:s,styles:l,annotations:c,coords:r,config:i}}var Vn=class{constructor(e){this.container=e}compile({spec:e,dataset:t}){return $l(this.container,{...e,data:t})}},jl=()=>{let e={},t=null;return{reset:()=>{e={}},getDuration:r=>e[r]??0,wrap:(r,n)=>a=>{const i=t,s={childrenMs:0};t=s;const c=performance.now();try{return n(a)}finally{const l=performance.now()-c;e[r]=(e[r]??0)+l-s.childrenMs,i&&(i.childrenMs+=l),t=i}}}},Fl=class{constructor(e){this.registry=e}compute(e,t){const r=this.registry.get(e.type),n=r.compute({data:t.data,mapping:t.mapping,spec:e,hasDiscreteXScale:t.hasDiscreteXScale,params:t.params});return Gl(r,r.resolveComputedAesthetics(e,t.params),n,t.requiredAesthetics),{data:n.data,mapping:{...Ul(t,n.data),...n.mapping}}}};function Ul({data:e,mapping:t},r){const n={};for(const[a,i]of Object.entries(t)){const s=o.readVariableName(i);s!==null&&e.hasVariable(s)&&!r.hasVariable(s)||(n[a]=i)}return n}function Gl(e,t,{data:r,mapping:n},a){for(const i of a){if(!t.has(i))continue;const s=n[i],c=o.readVariableName(s);if(!(o.isDefined(s)&&(c===null||r.hasVariable(c))))throw new o.UserInputError({code:"MISSING_STAT_OUTPUT",message:`Stat '${e.type}' declares it computes '${i}', which the layer's geom requires, but did not map it to a column of its output`,context:{aesthetic:i,requested:e.type},suggestion:`Return '${i}' in the stat's mapping, naming a column the stat writes.`})}}var xn=Object.keys(o.ANNOTATION_BUCKETS),Yl=e=>Object.hasOwn(o.ANNOTATION_BUCKETS,e),Kl=(e,t)=>{for(const r of xn){const n=zl(e,r,t);if(n)return n}return null},yt=(e,t)=>e[o.ANNOTATION_BUCKETS[t]],En=(e,t,r)=>({...e,[o.ANNOTATION_BUCKETS[t]]:r}),ql=(e,t)=>{const r=yt(e,t.kind);return En(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},zl=(e,t,r)=>{const n=yt(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},zt=Object.freeze({light:"#898373",dark:"#9F9886"}),Wl={graphBackground:o.DEFAULT_GRAPH_BACKGROUND,graphBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),geom:o.DEFAULT_GEOM_COLOR,geomBorder:Object.freeze({light:"rgba(58, 56, 51, 0.55)",dark:"rgba(237, 231, 218, 0.55)"}),textPrimary:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),textSecondary:zt,ruleLine:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),gridLine:Object.freeze({light:"#E1DAC9",dark:"#373531"}),hoverStroke:o.DEFAULT_HOVER_STROKE_COLOR,hoverGuideFill:Object.freeze({light:"#E7E1D2",dark:"#2B2A27"}),hoverGuideLine:Object.freeze({light:"#D5CDBA",dark:"#3B3934"}),legendFocus:Object.freeze({light:"color-mix(in srgb, transparent, #1D2129 50%)",dark:"color-mix(in srgb, transparent, #FFFFFF 50%)"}),tooltipBackground:Object.freeze({light:"#FCFCF9",dark:"#262522"}),tooltipBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),tooltipPrimaryRow:Object.freeze({light:"#F5F1E9",dark:"#2E2C29"}),annotationShape:Object.freeze({light:"#3b82f6",dark:"#60a5fa"}),annotationArrow:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),differenceLabelBackground:o.DEFAULT_GRAPH_BACKGROUND,trendPositive:{light:"#06B299",dark:"#0AC600"},trendNegative:{light:"#E14B49",dark:"#CB3333"},trendNeutral:zt},Hl=o.freezeWalkedEntries(o.walkStyleTargets()),De=Object.freeze({tokens:Object.freeze(Wl),defaults:Object.freeze(Hl),overrides:Object.freeze([])}),Xl=class extends H{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e),r=Tu(this.container.geomRegistry);for(const[n,a]of this.readStylesheets(e.styles)){const i=[...yu(n,t,a),...vu(n,a),...bu(n,a),...r(n,a),...Iu(n,a)];for(const s of i)this.container.diagnostics.addWarning(s)}for(const n of t)for(const a of n.styles.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.config.parsingLocale,e.coord,e.geomColor]}compileLayer(e,t){const r=Ln({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale,styleTarget:Cn(this.container.geomRegistry,e.geom),coord:t.coord,theme:this.container.theme?.styles,geomColor:t.geomColor});return{...e,styles:r}}readStylesheets(e){const t=this.container.theme?.styles;return t===void 0?[[e,"spec"]]:[[t,"theme"],[e,"spec"]]}},Jl=class extends o.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e),r=this.container.theme?.styles,n=[...r===void 0?[]:Jt(r,e.annotations,"theme"),...Jt(e.styles,e.annotations)];for(const a of n)this.container.diagnostics.addWarning(a);for(const a of t.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.coord,e.geomColor]}run(e){return wn(e.styles,{coord:e.coord,theme:this.container.theme?.styles,geomColor:e.geomColor})}},ce=new o.GeomRegistry,Zl=new Set(o.STYLE_PROPERTY_NAMES),Ql=new WeakMap,eu=new WeakMap,Wt={stateless:0,dimmed:1,hovered:2},On={overpaint:{conditions:["where"],reason:"an overpaint covers the layer's shapes as one"},maxWidth:{conditions:["where","state"],reason:"a layer's bars share one cap"}},tu=Object.keys(On),wn=(e,{coord:t="cartesian",theme:r,geomColor:n}={})=>{const a=[],i=jn(e,r,n),s={...ou(),warnings:a},c=(l,u,d,m)=>{if(fe(l)||!kn(l.select,t))return;const f=l.id===void 0?{}:{styleEntryId:l.id},p=l.select.target,g=su(l.select);if(g.status==="unknown-target"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} targets unknown '${String(p)}'.`,context:{param:"target",actual:String(p),...f},suggestion:`Set 'target' to one of ${[...vt].map(A=>`'${A}'`).join(", ")}.`});return}if(g.status==="unknown-partition"){const{key:A,value:I,node:E}=g,C=He(E,A);a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} addresses unknown ${A} '${I}'.`,context:{param:A,actual:I,...f},suggestion:C.length===0?`Remove '${A}' — this target has none.`:`Set '${A}' to one of ${C.map(k=>`'${k}'`).join(", ")}, or omit it.`});return}if(g.status==="namespace"){const A=He(g.node,"part");a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: ${l.select.target} entries need a part.`,context:{param:"part",actual:String(l.select.part),...f},suggestion:`Set 'part' to one of ${A.map(I=>`'${I}'`).join(", ")}.`});return}const h=g.node;if(l.when!==void 0&&!bt(h)){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: chrome entries take no conditions.`,context:{param:"when",...f},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const v=h.options??[],y=l.select;if(y.layer!==void 0){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} does not take a layer.`,context:{param:"layer",actual:j(y.layer),...f},suggestion:"Remove 'layer' — this target is not layer-scoped."});return}if(y.annotation!==void 0){if(!v.includes("annotation")){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} does not take an annotation.`,context:{param:"annotation",actual:j(y.annotation),...f},suggestion:"Remove 'annotation' — this target is not annotation-scoped."});return}if(typeof y.annotation!="string"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} addresses an invalid annotation ${j(y.annotation)}.`,context:{param:"annotation",actual:j(y.annotation),...f},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}const b=$n({declarations:l.declarations,vocabulary:h.vocabulary,tokens:i,location:d,origin:m,warnings:a,entryTarget:l.select.target});if(Object.keys(b).length===0)return;const S=h.select.target;Pn(S)&&s[S][u].push({select:l.select,declarations:b,origin:m})};return De.defaults.forEach((l,u)=>{c(l,"defaults",`builtin[${u}]`,{list:"builtin"})}),r?.defaults.forEach((l,u)=>{c(l,"defaults",ue("theme","defaults",u),Xe(l,u))}),e.defaults.forEach((l,u)=>{c(l,"defaults",`defaults[${u}]`,{list:"defaults",index:u,...l.id===void 0?{}:{id:l.id}})}),r?.overrides.forEach((l,u)=>{c(l,"overrides",ue("theme","overrides",u),Xe(l,u))}),e.overrides.forEach((l,u)=>{c(l,"overrides",`overrides[${u}]`,{list:"overrides",index:u,...l.id===void 0?{}:{id:l.id}})}),s},ru=e=>ce.has(e)?ce.get(e).styleTarget:void 0,nu=e=>ce.has(e)&&ce.get(e).scaleConstraints?.inferColorScale===!0,Ln=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a,styleTarget:i,coord:s="cartesian",theme:c,geomColor:l}=e,u=Pe(t,a),d=[],m=jn(n,c,l),f=g=>g===t.geom?i:void 0,p=(g,h,v="spec")=>{const y=[];return g.forEach((b,S)=>{if(!fe(b)||!kn(b.select,s))return;const A=b.select.kind;if(A!==void 0&&A!==t.geom||b.select.layer!==void 0&&b.select.layer!==t.id)return;const I=ue(v,h,S);if(Bn(b,I,f)!==void 0)return;const E=b.when?.state;if(E!==void 0&&!Mn(E))return;const C=b.id===void 0?{}:{styleEntryId:b.id},k=v==="theme"?Xe(b,S):{list:h,index:S,...b.id===void 0?{}:{id:b.id}},T=b.when?.where;if(T!==void 0){const O=z(T,t.data,"style-rule");if(O.length>0){for(const B of O)d.push({...B,code:"INVALID_STYLE_RULE",message:`Style ${I}: ${B.message}`,context:{...B.context,layerIndex:r,...C}});return}}const V=Dn({select:b.select,declarations:b.declarations,layerGeom:t.geom,styleTarget:i,tokens:m,location:I,origin:k,warnings:d});E==="dimmed"&&V.overpaint!==void 0&&(d.push({code:"INVALID_STYLE_RULE",message:`Style ${I}: 'overpaint' is not supported in the 'dimmed' state; the declaration is ignored.`,context:{param:"overpaint",layerIndex:r,...C},suggestion:"Declare 'overpaint' without a state or in the 'hovered' state."}),delete V.overpaint);const x=[];for(const O of tu){if(V[O]===void 0)continue;const{conditions:B,reason:Gn}=On[O],Me=B.find(Yn=>b.when?.[Yn]!==void 0);Me!==void 0&&(x.push(O),d.push({code:"INVALID_STYLE_RULE",message:`Style ${I}: '${O}' does not take '${Me}'; the declaration is ignored.`,context:{param:O,layerIndex:r,...C},suggestion:`Remove '${Me}': ${Gn}.`}))}const U=x.length===0?V:Object.fromEntries(Object.entries(V).filter(([O])=>!x.includes(O)));if(Object.keys(U).length===0)return;const{part:G}=b.select;y.push({declarations:U,...T===void 0?{}:{matches:q(T,u),where:T},...E===void 0?{}:{state:E},...G===void 0?{}:{part:G},origin:k})}),y};return{defaults:[...hu(t.geom,i,m,d),...p(c?.defaults??[],"defaults","theme"),...p(n.defaults,"defaults")],overrides:[...p(c?.overrides??[],"overrides","theme"),...p(n.overrides,"overrides")],warnings:d,...du(t.geom,i),dashPresets:i?.observation?.dashPresets??o.DASH_PRESETS.line}},Cn=(e,t)=>e.has(t)?e.get(t).styleTarget:void 0,au=e=>t=>Cn(e,t),iu=()=>{const e=new Set,t=r=>{if(e.add(r.select.target),r.children!==void 0)for(const n of Object.values(r.children))t(n)};for(const r of Object.values(o.STYLE_TARGETS))t(r);return e},vt=iu(),Pn=e=>e!=="geom"&&vt.has(e),ou=()=>{const e={};for(const t of vt)Pn(t)&&(e[t]={defaults:[],overrides:[]});return e},He=(e,t)=>{if(e.children===void 0)return[];const r=[];for(const n of Object.values(e.children)){const a=n.select[t];a!==void 0&&r.push(a)}return r},Ht=e=>Object.keys(e.vocabulary).length===0&&e.children!==void 0,su=e=>{const t=o.findStyleTarget(e);if(t!==void 0)return Ht(t)?{status:"namespace",node:t}:{status:"found",node:t};const r=o.findStyleTarget({target:e.target});if(r===void 0)return{status:"unknown-target"};let n=r;for(const a of o.STYLE_SELECT_KEYS){const i=e[a];if(i===void 0)continue;const s=n.children===void 0?void 0:Object.values(n.children).find(c=>c.select[a]===i);if(s===void 0)return{status:"unknown-partition",key:a,value:i,node:n};n=s}return Ht(n)?{status:"namespace",node:n}:{status:"found",node:n}},bt=e=>{const t=e.options??[];return t.includes("where")||t.includes("state")},cu=(e,t)=>{const r=e==="geom"?ce.getAll().find(n=>n.styleTarget!==void 0&&o.readObservationVocabulary(n.styleTarget)[t]!==void 0)?.type:e==="annotation"?Object.entries(o.STYLE_TARGETS.annotation.children).find(([,n])=>n.vocabulary[t]!==void 0)?.[0]:void 0;return r===void 0?void 0:`style.${e}.${r}`},fe=e=>e.select.target==="geom",lu=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Rn=(e,t,r,n)=>{const a=e.get(r)??new Map;e.set(r,a);const i=a.get(t);if(i!==void 0)return i;const s=n();return a.set(t,s),s},Nn=(e,t)=>Rn(Ql,e,t,()=>o.createGeomStyleNode(e,t)),le=(e,t)=>{const{kind:r,part:n}=e;if(r===void 0)return o.findStyleTarget({target:"geom",part:n});const a=t(r);if(a===void 0)return;const i=Nn(r,a);return n===void 0?i:lu(i.children,n)},uu=(e,t)=>{const r=le(e,()=>t);return r===void 0||bt(r)},_n=(e,t)=>[e,t].filter(r=>r!==void 0).join(" "),du=(e,t)=>{const r=le({kind:e},()=>t),n={};for(const a of Object.values(r?.children??{}))a.select.part!==void 0&&(n[a.select.part]={vocabulary:a.vocabulary,aesthetics:a.aesthetics??{}});return{observation:{vocabulary:r?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,aesthetics:r?.aesthetics??o.STYLE_TARGETS.geom.aesthetics},parts:n}},Xt=(e,t)=>le(e,()=>t)?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,mu=(e,t)=>{const r={};for(const n of Object.keys(e)){const a=e[n];a===void 0||t[n]===void 0||(r[n]=a)}return r},Dn=e=>{const t=$n({declarations:e.declarations,vocabulary:Xt(e.select,e.styleTarget),tokens:e.tokens,location:e.location,origin:e.origin,warnings:e.warnings,entryTarget:"geom"});return e.select.part!==void 0?t:mu(t,Xt({kind:e.layerGeom},e.styleTarget))},fu=(e,t)=>Rn(eu,e,t,()=>o.freezeWalkedEntries(o.walkStyleTargets([Nn(e,t)]))),pu=(e,t)=>Wt[e.state??"stateless"]-Wt[t.state??"stateless"],gu=(e,t)=>t===void 0?`builtin ${e}`:`builtin ${e}.${t}`,hu=(e,t,r,n)=>{const a=[],i={list:"builtin"},s=(c,l,u,d)=>{if(c.kind!==void 0&&c.kind!==e)return;if(u!==void 0&&!uu(c,t)){const p=_n(e,c.part);n.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: a ${p} entry takes no conditions.`,context:{param:"state",actual:u},suggestion:`Declare the ${u} paint on 'rest', or add 'state' to the part's options.`});return}const m=Dn({select:c,declarations:l,layerGeom:e,styleTarget:t,tokens:r,location:d,origin:i,warnings:n});if(Object.keys(m).length===0)return;const{part:f}=c;a.push({declarations:m,...u===void 0?{}:{state:u},...f===void 0?{}:{part:f},origin:i})};if(De.defaults.forEach((c,l)=>{fe(c)&&s(c.select,c.declarations,c.when?.state,`builtin[${l}]`)}),t===void 0)return a;for(const c of fu(e,t))s(c.select,c.declarations,c.when?.state,gu(e,c.select.part));return a.sort(pu)},ue=(e,t,r)=>`${e==="theme"?"theme ":""}${t}[${r}]`,pe=(e,t,r)=>{e.defaults.forEach((n,a)=>r(n,ue(t,"defaults",a))),e.overrides.forEach((n,a)=>r(n,ue(t,"overrides",a)))},yu=(e,t,r="spec")=>{const n=new Set(t.map(i=>i.id)),a=[];return pe(e,r,(i,s)=>{const c=i.select;if(c.target!=="geom")return;const l=c.layer;l===void 0||typeof l!="string"||n.has(l)||a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown layer '${l}'.`,context:{param:"layer",actual:l,...i.id===void 0?{}:{styleEntryId:i.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),a},Jt=(e,t,r="spec")=>{const n=new Map(xn.flatMap(i=>t[o.ANNOTATION_BUCKETS[i]].map(s=>[s.id,i]))),a=[];return pe(e,r,(i,s)=>{const c=i.select;if(c.target!=="annotation")return;const l=c.annotation;if(l===void 0||typeof l!="string")return;const u={param:"annotation",actual:l,...i.id===void 0?{}:{styleEntryId:i.id}},d=n.get(l);if(d===void 0){a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown annotation '${l}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets sticker '${l}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const m=c.kind;m!==void 0&&m!==d&&a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets ${d} '${l}' with an entry addressing kind '${String(m)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),a},vu=(e,t="spec")=>{const r=[];return pe(e,t,(n,a)=>{if(!fe(n))return;const i=n.when?.state;i===void 0||Mn(i)||r.push({code:"INVALID_STYLE_RULE",message:`Style ${a} scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...n.id===void 0?{}:{styleEntryId:n.id}},suggestion:`Set 'state' to one of ${o.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),r},Mn=e=>o.STYLE_STATES.includes(e),kn=(e,t)=>e.coord===void 0||e.coord===t,Xe=(e,t)=>({list:"theme",index:t,...e.id===void 0?{}:{id:e.id}}),bu=(e,t="spec")=>{const r=[];return pe(e,t,(n,a)=>{const i=n.select.coord;i===void 0||o.STYLE_COORDS.includes(i)||r.push({code:"INVALID_STYLE_RULE",message:`Style ${a} names unknown coord '${String(i)}'.`,context:{param:"coord",actual:String(i),...n.id===void 0?{}:{styleEntryId:n.id}},suggestion:`Set 'coord' to one of ${o.STYLE_COORDS.map(s=>`'${s}'`).join(", ")}, or omit it.`})}),r},Su=(e,t,r)=>e===void 0?`Set 'kind' to the geom declaring '${t}' — a part is addressed on the kind that has it.`:r.length===0?`Remove 'part' — ${e} has none.`:`Set 'part' to one of ${r.map(n=>`'${n}'`).join(", ")}, or omit it.`,Bn=(e,t,r)=>{const{kind:n,part:a}=e.select;if(a===void 0)return;const i=e.id===void 0?{}:{styleEntryId:e.id},s=le({kind:n,part:a},r);if(s===void 0){const c=le({kind:n},r),l=c===void 0?[]:He(c,"part");return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown part '${a}'.`,context:{param:"part",actual:a,...i},suggestion:Su(n,a,l)}}if(e.when!==void 0&&!bt(s)){const c=_n(n,a);return{code:"INVALID_STYLE_RULE",message:`Style ${t} ignored: a ${c} entry takes no conditions.`,context:{param:"when",...i},suggestion:`Remove the 'when' clause — the ${c} is styled as a whole.`}}},Au=(e,t,r)=>{const{kind:n}=e.select;if(n===void 0||r.has(n))return;const a=r.getAll().map(i=>`'${i.type}'`);return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown geom kind '${n}'.`,context:{param:"kind",actual:n,...e.id===void 0?{}:{styleEntryId:e.id}},suggestion:`Set 'kind' to one of ${a.join(", ")}, or omit it to reach every geom.`}},Tu=e=>{const t=au(e);return(r,n="spec")=>{const a=[];return pe(r,n,(i,s)=>{if(!fe(i))return;const c=Au(i,s,e)??Bn(i,s,t);c!==void 0&&a.push(c)}),a}},Iu=(e,t="spec")=>{const r=[];for(const[n,a]of Object.entries(e.tokens))o.isUsableTokenValue(a)||r.push({code:"INVALID_STYLE_RULE",message:`${t==="theme"?"Theme style":"Style"} token '${n}' has an invalid value: ${j(a)}.`,context:{param:"tokens",actual:j(a)},suggestion:`Set '${n}' to a non-empty color string or a { light, dark } pair of colors.`});return r},j=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),$n=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s,entryTarget:c}=e,l={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(g,h)=>{l[g]=h},m=(g,h,v)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: expected ${h}, got ${j(v)}.`,context:{param:g,expected:h,actual:j(v),...u},suggestion:`Set '${g}' to ${h}.`})},f=(g,h)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: unknown token '${h}'.`,context:{param:g,actual:h,...u},suggestion:`Declare '${h}' in the stylesheet's tokens.`})},p=g=>{const h=Zl.has(g),v=cu(c,g),y=v===void 0?`Declare '${g}' on a target whose vocabulary carries it.`:`Declare '${g}' on an entry whose kind supports it (e.g. ${v}).`;s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: ${h?"not in this entry's vocabulary":"not a style property"}.`,context:{param:g,...u},suggestion:h?y:`Remove the unknown declaration '${g}'.`})};for(const g of Object.keys(t)){const h=t[g];if(h===void 0)continue;const v=r[g];if(v===void 0){p(g);continue}const y=o.STYLE_DOMAINS[v](h,n);switch(y.status){case"accepted":d(g,y.value);break;case"rejected":m(g,y.expected,y.actual);break;case"unknownToken":f(g,y.token);break;case"dropped":break;default:break}}return l},jn=(e,t,r)=>({...De.tokens,...t?.tokens,...r===void 0?{}:{geom:r},...e.tokens}),Vu=({layer:e})=>{if(e.position==="stack")return;const t=o.readVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];o.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},xu=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=o.readVariableName(e.mapping.x);if(r===null)return;const[n,a]=t==="y"?[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.xMax]:[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];if(!e.data.hasVariable(n)||!e.data.hasVariable(a))return;const i=u=>t==="y"?u.xMax:u.yMax,s=u=>t==="y"?u.xMin:u.yMin,c=new Map;for(const u of e.data){const d=u[r],m=t==="y"?o.getY(u):o.getX(u),f=o.getYMin(u)??(t==="y"?m:null),p=o.getYMax(u)??(t==="y"?m:null),g=o.getXMin(u)??(t==="x"?m:null),h=o.getXMax(u)??(t==="x"?m:null),v=o.getYRaw(u);if(!o.isDefined(d)||!o.isDefined(f)||!o.isDefined(p)||!o.isDefined(g)||!o.isDefined(h)||!o.isDefined(v))continue;const y=v>=0;if(Math.abs(v)===0)continue;const b=lt(u,r),S={xMin:g,xMax:h,yMin:f,yMax:p},A=c.get(b);if(A===void 0){c.set(b,{total:v,topPositive:y?S:null,bottomNegative:y?null:S});continue}A.total+=v,y?(A.topPositive===null||i(S)>i(A.topPositive))&&(A.topPositive=S):(A.bottomNegative===null||s(S)<s(A.bottomNegative))&&(A.bottomNegative=S)}const l=[];for(const[u,d]of c){const m=d.topPositive??d.bottomNegative;m!==null&&l.push({xKey:u,total:d.total,anchor:{xMin:m.xMin,xMax:m.xMax,yMin:m.yMin,yMax:m.yMax,direction:d.topPositive!==null?"positive":"negative"}})}return l},Eu=class extends H{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=Ce(t.coordSystem);if(r.summaries.includeStackTotals){const i=xu({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.includeGrandTotal){const i=Vu({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Zt={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Ou=["color","size","alpha","strokeWidth","lineType"],wu=class extends H{dependencies(e){return Ou.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(o.VISUAL_VARIABLES);for(const[a,i]of n){const s=o.readConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Zt[a],s);continue}const c=o.readVariableName(e.mapping[a]),l=t.scales[a];!c||!l||l.kind!=="visual"||(r=r.deriveVariableFrom(c,i,Zt[a],Lu(l)))}return{...e,data:r}}},Lu=e=>t=>o.isDefined(t)?e.map(t):null;function Fn(e=new o.GeomRegistry,t,r=new an){return{diagnostics:new xl,geomRegistry:e,statRegistry:r,theme:t}}var Cu=e=>({styles:Pu(In({type:"styles",...e.styles}),e.palettes?.categorical),palettes:e.palettes,config:e.config===void 0?void 0:Ru(e.config)}),Pu=(e,t)=>{const r=t?.[0];return e.tokens.geom!==void 0||r===void 0?e:{...e,tokens:{...e.tokens,geom:r}}},Ru=e=>{const{content:t,...r}=e;return r},Un=class{constructor(e,t,r,n,a,i,s,c,l,u,d,m,f,p,g,h){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=m,this.stylesCompiler=f,this.chromeStylesCompiler=p,this.highlightsCompiler=g,this.annotationsCompiler=h,this.stageTimer=o.IS_DEV?jl():null,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}],o.IS_DEV&&this.setupStageTiming()}get theme(){return this.container.theme}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??Qt})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??Qt;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,ae(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=ft(this.container,{data:t.data,layers:t.layers,mapping:t.mapping});return ae(t,{scales:et(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=_e(r,a);return t.coords.coordType==="polar"?pt(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[ir(e)],warnings:t.warnings}}setupStageTiming(){this.stageTimer&&(this.dataCompiler.compile=this.stageTimer.wrap("data",this.dataCompiler.compile.bind(this.dataCompiler)),this.transformCompiler.compile=this.stageTimer.wrap("transform",this.transformCompiler.compile.bind(this.transformCompiler)),this.constantMappingCompiler.compile=this.stageTimer.wrap("constantMapping",this.constantMappingCompiler.compile.bind(this.constantMappingCompiler)),this.layerPhasedCompiler.compile=this.stageTimer.wrap("layer",this.layerPhasedCompiler.compile.bind(this.layerPhasedCompiler)),this.coordCompiler.setup=this.stageTimer.wrap("coordSetup",this.coordCompiler.setup.bind(this.coordCompiler)),this.scaleCompiler.compile=this.stageTimer.wrap("scale",this.scaleCompiler.compile.bind(this.scaleCompiler)),this.positionMapperCompiler.compile=this.stageTimer.wrap("positionMapper",this.positionMapperCompiler.compile.bind(this.positionMapperCompiler)),this.visualMapperCompiler.compile=this.stageTimer.wrap("visualMapper",this.visualMapperCompiler.compile.bind(this.visualMapperCompiler)),this.coordCompiler.transform=this.stageTimer.wrap("coordTransform",this.coordCompiler.transform.bind(this.coordCompiler)),this.summarizeCompiler.compile=this.stageTimer.wrap("summarize",this.summarizeCompiler.compile.bind(this.summarizeCompiler)),this.guideCompiler.compile=this.stageTimer.wrap("guide",this.guideCompiler.compile.bind(this.guideCompiler)),this.stylesCompiler.compile=this.stageTimer.wrap("styles",this.stylesCompiler.compile.bind(this.stylesCompiler)),this.chromeStylesCompiler.compile=this.stageTimer.wrap("chromeStyles",this.chromeStylesCompiler.compile.bind(this.chromeStylesCompiler)),this.highlightsCompiler.compile=this.stageTimer.wrap("highlights",this.highlightsCompiler.compile.bind(this.highlightsCompiler)),this.annotationsCompiler.compile=this.stageTimer.wrap("annotations",this.annotationsCompiler.compile.bind(this.annotationsCompiler)))}trackCompile(e){if(!o.IS_DEV)return e();this.stageTimer?.reset();const t=this.getCacheStats(),r=performance.now();try{return e()}finally{const n=performance.now()-r,a={},i={};for(const{name:s,getStats:c}of this.stages){const l=c();a[s]={hits:l.hits-t[s].hits,misses:l.misses-t[s].misses},i[s]=this.stageTimer?.getDuration(s)??0}this.lastCompile={stages:a,durationMs:n,stageDurationsMs:i}}}runPipeline({spec:e,colorScheme:t}){return{...we({spec:e}).pipe(({spec:r})=>({spec:ae(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:ae(r,{data:n.data,mapping:n.mapping})}}).pipe(({spec:r})=>({layers:this.layerPhasedCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales})})).pipe(({spec:r,layers:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config,coord:Fe(r),geomColor:Ft(r.scales)})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations,coord:Fe(r),geomColor:Ft(r.scales)})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,specLayers:r.layers,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},Nu=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],Qt="light",_u=({plugins:e=[],theme:t}={})=>{const r=o.readPlugins(e),{geomRegistry:n,statRegistry:a,transformRegistry:i}=lc(r),s=Fn(n,t===void 0?void 0:Cu(t),a),c=new Wc(s),l=new gt(i);for(const u of r.warnings)s.diagnostics.addWarning(u,{persistent:!0});return new Un(s,new o.DataCompiler,new Vn(s),l,new ri,new ws(s,l,a,new gs(s,l,new Fl(a),new wi,new Oi(s),new uc(new yc))),new kc(s,c),new ii(new Ei),new Pc(s),new wu,new rs(s),new Eu(s),new Xl(s),new Jl(s),new is(s),new Ua(s))};Object.defineProperty(exports,"AREA_DEFAULTS",{enumerable:!0,get:function(){return Ll}});Object.defineProperty(exports,"BAR_DEFAULTS",{enumerable:!0,get:function(){return Cl}});Object.defineProperty(exports,"BUILTIN_STYLES",{enumerable:!0,get:function(){return De}});Object.defineProperty(exports,"COMPILER_STAGE_KEYS",{enumerable:!0,get:function(){return Nu}});Object.defineProperty(exports,"CONTINUOUS_SCALE_DEFAULTS",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"Compiler",{enumerable:!0,get:function(){return Un}});Object.defineProperty(exports,"DATA_LABELS_DEFAULTS",{enumerable:!0,get:function(){return vn}});Object.defineProperty(exports,"DEFAULT_ROWS_FIELD",{enumerable:!0,get:function(){return ut}});Object.defineProperty(exports,"DISCRETE_SCALE_DEFAULTS",{enumerable:!0,get:function(){return ee}});Object.defineProperty(exports,"LINE_DEFAULTS",{enumerable:!0,get:function(){return wl}});Object.defineProperty(exports,"POINT_DEFAULTS",{enumerable:!0,get:function(){return Ol}});Object.defineProperty(exports,"POLAR_COORD_DEFAULTS",{enumerable:!0,get:function(){return Ae}});Object.defineProperty(exports,"RULE_DEFAULTS",{enumerable:!0,get:function(){return Pl}});Object.defineProperty(exports,"SpecCompiler",{enumerable:!0,get:function(){return Vn}});Object.defineProperty(exports,"TILE_DEFAULTS",{enumerable:!0,get:function(){return Rl}});Object.defineProperty(exports,"TransformCompiler",{enumerable:!0,get:function(){return gt}});Object.defineProperty(exports,"applyReplayableTransforms",{enumerable:!0,get:function(){return gn}});Object.defineProperty(exports,"areEndpointsComparable",{enumerable:!0,get:function(){return nr}});Object.defineProperty(exports,"arePredicatesEqual",{enumerable:!0,get:function(){return ia}});Object.defineProperty(exports,"areStyleDeclarationsEqual",{enumerable:!0,get:function(){return ua}});Object.defineProperty(exports,"areStyleRuleAddressesEqual",{enumerable:!0,get:function(){return la}});Object.defineProperty(exports,"buildDiagnostic",{enumerable:!0,get:function(){return ir}});Object.defineProperty(exports,"buildEmptyHighlightForStrategy",{enumerable:!0,get:function(){return Ur}});Object.defineProperty(exports,"buildLayerStyleAddress",{enumerable:!0,get:function(){return da}});Object.defineProperty(exports,"canAnchorDirectLabels",{enumerable:!0,get:function(){return jr}});Object.defineProperty(exports,"clampValuesAgainstFillSiblings",{enumerable:!0,get:function(){return Tn}});Object.defineProperty(exports,"combineKindStyleDeclarations",{enumerable:!0,get:function(){return ca}});Object.defineProperty(exports,"combineStyleDeclarations",{enumerable:!0,get:function(){return cr}});Object.defineProperty(exports,"compileChromeStyles",{enumerable:!0,get:function(){return wn}});Object.defineProperty(exports,"compileLayerStyles",{enumerable:!0,get:function(){return Ln}});Object.defineProperty(exports,"compilePredicate",{enumerable:!0,get:function(){return q}});Object.defineProperty(exports,"composePoint",{enumerable:!0,get:function(){return Ue}});Object.defineProperty(exports,"createAlphaValueReader",{enumerable:!0,get:function(){return Zn}});Object.defineProperty(exports,"createColorValueReader",{enumerable:!0,get:function(){return Xn}});Object.defineProperty(exports,"createCommonContainer",{enumerable:!0,get:function(){return Fn}});Object.defineProperty(exports,"createCompiler",{enumerable:!0,get:function(){return _u}});Object.defineProperty(exports,"createDatasetFromKindPartitions",{enumerable:!0,get:function(){return ti}});Object.defineProperty(exports,"createDatasetPredicateCompileContext",{enumerable:!0,get:function(){return wa}});Object.defineProperty(exports,"createEmptyLayerStyles",{enumerable:!0,get:function(){return Yr}});Object.defineProperty(exports,"createGroupValueReader",{enumerable:!0,get:function(){return Qn}});Object.defineProperty(exports,"createLabelValueReader",{enumerable:!0,get:function(){return Hn}});Object.defineProperty(exports,"createLayerMeasurement",{enumerable:!0,get:function(){return br}});Object.defineProperty(exports,"createObservationAnchorBuilder",{enumerable:!0,get:function(){return fr}});Object.defineProperty(exports,"createObservationAnchorMatcher",{enumerable:!0,get:function(){return Sr}});Object.defineProperty(exports,"createObservationAnchorParser",{enumerable:!0,get:function(){return ar}});Object.defineProperty(exports,"createPipeline",{enumerable:!0,get:function(){return we}});Object.defineProperty(exports,"createPredicateColumnReader",{enumerable:!0,get:function(){return Tr}});Object.defineProperty(exports,"createPredicateCompileContext",{enumerable:!0,get:function(){return Pe}});Object.defineProperty(exports,"createPredicateValueReader",{enumerable:!0,get:function(){return Ar}});Object.defineProperty(exports,"createRawValueReader",{enumerable:!0,get:function(){return L}});Object.defineProperty(exports,"createRowPredicateCompileContext",{enumerable:!0,get:function(){return Oa}});Object.defineProperty(exports,"createScaleContext",{enumerable:!0,get:function(){return ft}});Object.defineProperty(exports,"createSegmentYReader",{enumerable:!0,get:function(){return Je}});Object.defineProperty(exports,"createSizeValueReader",{enumerable:!0,get:function(){return Jn}});Object.defineProperty(exports,"createStrokeWidthValueReader",{enumerable:!0,get:function(){return ea}});Object.defineProperty(exports,"createStyleRuleMatcher",{enumerable:!0,get:function(){return Le}});Object.defineProperty(exports,"createXValueReader",{enumerable:!0,get:function(){return zn}});Object.defineProperty(exports,"createYValueReader",{enumerable:!0,get:function(){return Wn}});Object.defineProperty(exports,"describeMeasurementBasis",{enumerable:!0,get:function(){return $e}});Object.defineProperty(exports,"encodesColorAsValue",{enumerable:!0,get:function(){return nu}});Object.defineProperty(exports,"filterLayersByGeoms",{enumerable:!0,get:function(){return wo}});Object.defineProperty(exports,"findAnnotation",{enumerable:!0,get:function(){return Kl}});Object.defineProperty(exports,"findCompanionLayers",{enumerable:!0,get:function(){return Lo}});Object.defineProperty(exports,"findDefaultKitStyleTarget",{enumerable:!0,get:function(){return ru}});Object.defineProperty(exports,"findDistinctLayers",{enumerable:!0,get:function(){return ct}});Object.defineProperty(exports,"findGroupStyleRules",{enumerable:!0,get:function(){return ma}});Object.defineProperty(exports,"findHostLayer",{enumerable:!0,get:function(){return Co}});Object.defineProperty(exports,"findKindStyleDeclarations",{enumerable:!0,get:function(){return fa}});Object.defineProperty(exports,"findLayerByGeom",{enumerable:!0,get:function(){return Oo}});Object.defineProperty(exports,"findLayerById",{enumerable:!0,get:function(){return Eo}});Object.defineProperty(exports,"findPairingVariables",{enumerable:!0,get:function(){return yr}});Object.defineProperty(exports,"findPredicateProblems",{enumerable:!0,get:function(){return z}});Object.defineProperty(exports,"findStyleRule",{enumerable:!0,get:function(){return sr}});Object.defineProperty(exports,"findStyleRuleIndex",{enumerable:!0,get:function(){return rt}});Object.defineProperty(exports,"getCoordinates",{enumerable:!0,get:function(){return ya}});Object.defineProperty(exports,"getCrossAxisCoordinate",{enumerable:!0,get:function(){return mr}});Object.defineProperty(exports,"getGroup",{enumerable:!0,get:function(){return me}});Object.defineProperty(exports,"getLayerVariableValueFormat",{enumerable:!0,get:function(){return at}});Object.defineProperty(exports,"getLayerYValueFormat",{enumerable:!0,get:function(){return Va}});Object.defineProperty(exports,"getMainAxisCoordinate",{enumerable:!0,get:function(){return dr}});Object.defineProperty(exports,"getObservationXKey",{enumerable:!0,get:function(){return lt}});Object.defineProperty(exports,"isAnnotationKind",{enumerable:!0,get:function(){return Yl}});Object.defineProperty(exports,"isCartesian",{enumerable:!0,get:function(){return va}});Object.defineProperty(exports,"isCompanionLayer",{enumerable:!0,get:function(){return ie}});Object.defineProperty(exports,"isGeomStyleRule",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"isHeadingField",{enumerable:!0,get:function(){return oe}});Object.defineProperty(exports,"isLayerSpecOf",{enumerable:!0,get:function(){return xo}});Object.defineProperty(exports,"mapItems",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"measureAnchorSpace",{enumerable:!0,get:function(){return ur}});Object.defineProperty(exports,"paintsEachGroupFromItsFirstObservation",{enumerable:!0,get:function(){return Po}});Object.defineProperty(exports,"patchSpec",{enumerable:!0,get:function(){return ae}});Object.defineProperty(exports,"readAnnotationBucket",{enumerable:!0,get:function(){return yt}});Object.defineProperty(exports,"readDemandingLayers",{enumerable:!0,get:function(){return dt}});Object.defineProperty(exports,"readMainAxis",{enumerable:!0,get:function(){return Ce}});Object.defineProperty(exports,"readObservationMeasurement",{enumerable:!0,get:function(){return Or}});Object.defineProperty(exports,"readPredicateKey",{enumerable:!0,get:function(){return Te}});Object.defineProperty(exports,"readPredicateVariables",{enumerable:!0,get:function(){return ve}});Object.defineProperty(exports,"readScopeKey",{enumerable:!0,get:function(){return Ge}});Object.defineProperty(exports,"readScopeXVariable",{enumerable:!0,get:function(){return Fr}});Object.defineProperty(exports,"readStyleCoord",{enumerable:!0,get:function(){return Fe}});Object.defineProperty(exports,"readStyleRuleAddressKey",{enumerable:!0,get:function(){return K}});Object.defineProperty(exports,"readStyleRulesBeneath",{enumerable:!0,get:function(){return sa}});Object.defineProperty(exports,"removeDiscreteScalePadding",{enumerable:!0,get:function(){return pt}});Object.defineProperty(exports,"removeLocatedAnnotation",{enumerable:!0,get:function(){return ql}});Object.defineProperty(exports,"replaceAnnotationBucket",{enumerable:!0,get:function(){return En}});Object.defineProperty(exports,"replaceAtIndex",{enumerable:!0,get:function(){return aa}});Object.defineProperty(exports,"resolveAnchorVariable",{enumerable:!0,get:function(){return de}});Object.defineProperty(exports,"resolveColormap",{enumerable:!0,get:function(){return xe}});Object.defineProperty(exports,"resolveComparisonBasis",{enumerable:!0,get:function(){return $r}});Object.defineProperty(exports,"resolveConfig",{enumerable:!0,get:function(){return hn}});Object.defineProperty(exports,"resolveCoord",{enumerable:!0,get:function(){return yn}});Object.defineProperty(exports,"resolveCrossAnchorVariable",{enumerable:!0,get:function(){return Ze}});Object.defineProperty(exports,"resolveDiscreteScale",{enumerable:!0,get:function(){return mn}});Object.defineProperty(exports,"resolveGeomAnchorSpace",{enumerable:!0,get:function(){return lr}});Object.defineProperty(exports,"resolveGeomScaleDemands",{enumerable:!0,get:function(){return mt}});Object.defineProperty(exports,"resolveLabelSource",{enumerable:!0,get:function(){return An}});Object.defineProperty(exports,"resolveLayer",{enumerable:!0,get:function(){return Sn}});Object.defineProperty(exports,"resolveLayerTooltip",{enumerable:!0,get:function(){return qr}});Object.defineProperty(exports,"resolveScale",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"resolveSegmentYSource",{enumerable:!0,get:function(){return Oe}});Object.defineProperty(exports,"resolveStatSpec",{enumerable:!0,get:function(){return bn}});Object.defineProperty(exports,"resolveVariableLabel",{enumerable:!0,get:function(){return ot}});Object.defineProperty(exports,"sampleColormap",{enumerable:!0,get:function(){return Dc}});Object.defineProperty(exports,"shouldNarrowByGroup",{enumerable:!0,get:function(){return Qe}});Object.defineProperty(exports,"toPanelFraction",{enumerable:!0,get:function(){return ha}});Object.defineProperty(exports,"uniqueId",{enumerable:!0,get:function(){return w}});Object.defineProperty(exports,"updateSpec",{enumerable:!0,get:function(){return na}});
1
+ const o=require("./annotations-CuIFf0S0.cjs");let F=require("lodash-es"),re=require("d3-time"),Kn=require("date-fns/differenceInDays"),Y=require("d3-regression"),D=require("d3-scale"),ne=require("d3-interpolate");var L=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);return o.isDefined(n)?a=>{const i=a[n];return i===void 0?null:er(i,e.getType(n))}:()=>null},qn=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);if(!o.isDefined(n)||!e.hasVariable(n))return()=>null;const a=e.getValues(n),i=e.getType(n);return s=>{const c=a[s];return c===void 0?null:er(c,i)}},zn=(e,t)=>L(e,t.x),Wn=(e,t)=>L(e,t.y),Hn=(e,t)=>L(e,t.label),Xn=(e,t)=>L(e,t.color),Jn=(e,t)=>L(e,t.size),Zn=(e,t)=>L(e,t.alpha),Qn=(e,t)=>L(e,t.group),ea=(e,t)=>L(e,t.strokeWidth),er=(e,t)=>{switch(t){case"numeric":return o.isStrictNumericDataValue(e)?e:null;case"categorical":return o.isStrictCategoricalDataValue(e)?e:null;case"temporal":return o.isStrictTemporalDataValue(e)?e:null;default:return null}},St={variable:o.POSITION_VARIABLES.yRaw};function Ee(e,t){return o.isStackedPosition(e)?St:t.y??St}function Je(e){return L(e.data,Ee(e.position,e.mapping))}function ta(e){return qn(e.data,Ee(e.position,e.mapping))}var ue=e=>{const t=o.readVariableName(e.mapping.x);return t!==null&&t!==o.CONSTANT_VARIABLES.x?t:rr(e)??o.GROUP_VARIABLES.group},Ze=e=>ra(e)?o.readVariableName(e.mapping.y):null,tr=e=>Ze(e)===null?null:Je(e),Qe=e=>e.spatialKind!=="cells"&&ue(e)!==rr(e),rr=e=>typeof e.identityKey=="object"?e.identityKey.variable:null,ra=e=>e.spatialKind==="points"||e.spatialKind==="cells",nr=(e,t)=>e.yScaleType===t.yScaleType&&$e(e.valueFormat)===$e(t.valueFormat),Be=e=>`${e.yScaleType} y axis, ${$e(e.valueFormat)}`,$e=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,ar=(e,t)=>{const r=o.toExplicitValueFormat(e.data.getValueFormat(ue(e))),n=Ze(e);return a=>({...a,anchorValue:o.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:o.parseAddressingValue(a.groupValue,o.toExplicitValueFormat(e.data.getValueFormat(o.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:o.parseAddressingValue(a.crossValue,o.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function ir(e){return e instanceof o.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function na(e,t){return or(e,t)}function ae(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function aa(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function et(e,t){let r=null;for(const[n,a]of e.entries()){const i=t(a,n);if(i===a){r?.push(i);continue}r??=e.slice(0,n),r.push(i)}return r??e}function or(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(o.isPlainObject(i)&&o.isPlainObject(s)){const c=or(s,i);c!==s&&(n[a]=c,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function Oe(e){return{pipe:t=>{const r=t(e);return Oe({...e,...r})},result:()=>e}}var ia=(e,t)=>Ae(e)===Ae(t),Ae=e=>JSON.stringify(tt(e)),tt=e=>{const t=e;return typeof t!="object"||t===null?["invalid",String(t)]:"and"in e?["and",...At(e.and)]:"or"in e?["or",...At(e.or)]:"not"in e?["not",tt(e.not)]:[e.variable,...oa(e)]},oa=e=>{if("eq"in e)return["eq",o.readDataValueKey(e.eq)];if("oneOf"in e)return["oneOf",...Tt(e.oneOf)];if("lt"in e)return["lt",o.readDataValueKey(e.lt)];if("lte"in e)return["lte",o.readDataValueKey(e.lte)];if("gt"in e)return["gt",o.readDataValueKey(e.gt)];if("gte"in e)return["gte",o.readDataValueKey(e.gte)];if("range"in e)return["range",...Tt(e.range)];const t=Object.entries(e).sort(([r],[n])=>r.localeCompare(n));return["invalid",JSON.stringify(t)]},At=e=>Array.isArray(e)?e.map(tt):["invalid",JSON.stringify(e)],Tt=e=>Array.isArray(e)?e.map(o.readDataValueKey):["invalid",JSON.stringify(e)],je=e=>e.coords.coordType==="polar"?"polar":"cartesian",sr=(e,t,r)=>{const n=rt(e,t,r);return n===-1?void 0:e[n]},rt=(e,t,r)=>{const n=we(t,r);for(let a=e.length-1;a>=0;a-=1){const i=e[a];if(i!==void 0&&n(i))return a}return-1},sa=(e,t,r)=>{const n=rt(e,t,r);return e.filter((a,i)=>i!==n)},cr=(e,t,r)=>{const n=we(t,r);let a;for(const i of e)if(n(i)){a??={};for(const[s,c]of Object.entries(i.declarations))c!==void 0&&(a[s]=c)}return a},ca=(e,t,r)=>cr(e,t,r),la=(e,t)=>K(e)===K(t),we=(e,t)=>{const r=K(e),n=It(e)!==void 0;return a=>{const i=It(a);if(n||i===void 0)return K(a)===r;if(i!==t)return!1;const{coord:s,...c}=a.select;return K({...a,select:c})===r}},K=e=>{const t=Object.entries(e.select).filter(([,n])=>n!==void 0).sort(([n],[a])=>n.localeCompare(a)),r=e.when?.where===void 0?null:Ae(e.when.where);return JSON.stringify([t,e.when?.state??null,r])},ua=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>pa(e[r],t[r])),da=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),nt=e=>e.select.target==="geom",ma=(e,t,r)=>{const n=new Map;for(const a of e)!nt(a)||a.when?.where===void 0||we({...t,when:a.when},r)(a)&&n.set(K(a),a);return[...n.values()]},fa=(e,t,r)=>{const n=sr(e,t,r);if(!(n===void 0||!nt(n)))return n.declarations},It=e=>e.select.coord,pa=(e,t)=>e===t?!0:o.isLightDarkColor(e)?o.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:o.isStyleTokenRef(e)?o.isStyleTokenRef(t)&&e.token===t.token:!1,ga=(e,t)=>{if(!o.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[o.getStableKey(r)]??e.fallback},lr=e=>e.type==="polar"?"disk":"panel",ur=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},ha=(e,t)=>{if(e.space!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=ur(e.space,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function dr(e,t){return e==="x"?t.x:t.y}function mr(e,t){return e==="x"?t.y:t.x}function ya(e,t){return{main:dr(e,t),cross:mr(e,t)}}function Fe(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function Le(e){return e.type==="cartesian"?e.mainAxis:"x"}function va(e){return e.type==="cartesian"}var de=e=>e[o.GROUP_VARIABLES.group],fr=e=>{const t=ue(e),r=tr(e),n=Qe(e)&&t!==o.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const c=n?de(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...c!==null&&{groupValue:c}}}},he=1e-9;function pr(e){return e?{start:o.POSITION_VARIABLES.yMin,end:o.POSITION_VARIABLES.yMax}:{start:o.POSITION_VARIABLES.xMin,end:o.POSITION_VARIABLES.xMax}}function gr(e,t){const r=new Map;for(const a of e.flatMap(i=>Ta(i,t))){const i=o.getStableKey([a.value]),s=r.get(i);s?s.push(a):r.set(i,[a])}const n=[...r.values()];return n.some(Sa)?null:n.flatMap(a=>Aa(a)??[])}function ba(e,t,r){const n=gr(e,t),a=o.getStableKey([r]),i=n?.find(s=>o.getStableKey([s.value])===a);return i===void 0?null:(i.start+i.end)/2}function Sa(e){const t=[...e].sort((a,i)=>a.start-i.start||a.end-i.end);let r=Number.NEGATIVE_INFINITY,n;for(const a of t){if(!(n!==void 0&&Math.abs(a.start-n.start)<=he&&Math.abs(a.end-n.end)<=he)&&a.start<r-he)return!0;r=Math.max(r,a.end),n=a}return!1}function Aa(e){let t,r;for(const n of[...e].sort((a,i)=>a.start-i.start))t=t!==void 0&&n.start<=t.end+he?{...t,end:Math.max(t.end,n.end)}:n,(r===void 0||t.end-t.start>r.end-r.start)&&(r=t);return r}function Ta(e,t){const r=o.readVariableName(e.mapping.x),{data:n}=e,{start:a,end:i}=pr(t);if(!o.isDefined(r)||!n.hasVariable(a)||!n.hasVariable(i))return[];const s=n.getValues(r),c=n.getValues(a,{type:"numeric"}),l=n.getValues(i,{type:"numeric"});return s.flatMap((u,d)=>{const m=c[d],f=l[d];return!o.isDefined(u)||!o.isDefined(m)||!o.isDefined(f)?[]:[{value:u,start:Math.min(m,f),end:Math.max(m,f)}]})}var Ia={type:"decimal"};function hr(e){return e.length>0&&e.every(t=>t.data.size()===0)}function at(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):Ia}function Va(e){return at(e,o.readVariableName(e.mapping.y))}function yr(e,t){const r=Vt(t);return[...Vt(e)].filter(n=>r.has(n))}function Vt(e){const t=new Set(o.getGroupVariables(e.data,e.mapping));for(const r of Object.values(e.mapping)){const n=o.readVariableName(r);n===null||!e.data.hasVariable(n)||e.data.getType(n)==="categorical"&&t.add(n)}return t}function vr({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??Ee(t,r)}function br(e,t){const r=vr({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=o.readVariableName(r),a=n===o.POSITION_VARIABLES.yRaw?o.readVariableName(e.mapping.y):n;return{read:L(e.data,r),valueFormat:at(e,a)}}var Sr=e=>{const t=ue(e),r=tr(e),n=Qe(e);return(a,i)=>!o.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||o.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:o.areDataValuesEqual(de(a),i.groupValue)},Ar=e=>{const t=o.readVariableName(e.mapping.y),r=Je(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},Tr=e=>t=>{if(t===o.readVariableName(e.mapping.y))return ta(e);const r=e.data.hasVariable(t)?e.data.getValues(t):null;return n=>r?.[n]??null};var xa=["lt","lte","gt","gte","range"],Ea={highlight:{subject:"Highlight predicate",effect:"dropping this highlight"},"selection-anchor":{subject:"Selection anchor predicate",effect:"dropping this annotation"},"style-rule":{subject:"Style rule predicate",effect:"dropping this rule"}},_=()=>!1,X=()=>!0;function Ce(e,t){const r=Ar(e);return{...it(e.data,t),createValueReader:n=>a=>r(a,n)}}function Oa(e,t){return{...it(e.data,t),createValueReader:Tr(e)}}function wa(e,t){return{...it(e,t),createValueReader:r=>{const n=e.hasVariable(r)?e.getValues(r):null;return a=>n?.[a]??null}}}function ye(e){return"and"in e?[...new Set(e.and.flatMap(ye))]:"or"in e?[...new Set(e.or.flatMap(ye))]:"not"in e?ye(e.not):[e.variable]}function q(e,t){if("and"in e){const r=e.and.map(n=>q(n,t)).filter(n=>n!==X);return r.includes(_)?_:r.length===0?X:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>q(n,t)).filter(n=>n!==_);return r.includes(X)?X:r.length===0?_:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=q(e.not,t);return r===_?X:r===X?_:n=>!r(n)}return Ca(e,t)}function z(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>z(n,t,r)):"or"in e?e.or.flatMap(n=>z(n,t,r)):"not"in e?z(e.not,t,r):La(e,t,r)}function it(e,t){return{hasVariable:r=>e.hasVariable(r),getType:r=>e.getType(r),getValueFormat:r=>e.getValueFormat(r),parsingLocale:t}}function La(e,t,r){const{subject:n,effect:a}=Ea[r];if(!t.hasVariable(e.variable))return[{code:"UNKNOWN_VARIABLE",message:`${n} references unknown variable '${e.variable}' — ${a}.`,context:{variableName:e.variable},suggestion:`Map '${e.variable}' in the layer or correct the variable name in the predicate.`}];const i=Pa(e);return i!==null&&t.getType(e.variable)==="categorical"?[{code:"INVALID_PREDICATE_OPERATOR",message:`${n} uses ordering operator '${i}' on categorical variable '${e.variable}' — ${a}. Use 'eq' or 'oneOf' instead.`,context:{variableName:e.variable},suggestion:"Use 'eq' or 'oneOf' for categorical variables."}]:[]}function Ca(e,t){if(!t.hasVariable(e.variable))return _;const r=t.createValueReader(e.variable),n=o.toExplicitValueFormat(t.getValueFormat(e.variable)),a=i=>o.parseAddressingValue(i,n,t.parsingLocale);if("eq"in e){const i=a(e.eq);return s=>o.areDataValuesEqual(r(s),i)}if("oneOf"in e){const i=e.oneOf.map(a);if(i.length>=32){const s=new Set,c=new Set;for(const l of i)o.isStrictTemporalDataValue(l)?c.add(l.getTime()):s.add(l);return l=>{const u=r(l);return o.isStrictTemporalDataValue(u)?c.has(u.getTime()):!Number.isNaN(u)&&s.has(u)}}return s=>{const c=r(s);for(const l of i)if(o.areDataValuesEqual(c,l))return!0;return!1}}if("lt"in e){const i=a(e.lt);return s=>J(r(s),i)==="less"}if("lte"in e){const i=a(e.lte);return s=>{const c=J(r(s),i);return c==="less"||c==="equal"}}if("gt"in e){const i=a(e.gt);return s=>J(r(s),i)==="greater"}if("gte"in e){const i=a(e.gte);return s=>{const c=J(r(s),i);return c==="greater"||c==="equal"}}if("range"in e){const[i,s]=e.range,c=a(i),l=a(s);return u=>{const d=r(u),m=J(d,c),f=J(d,l);return m==="incomparable"||f==="incomparable"?!1:(m==="greater"||m==="equal")&&(f==="less"||f==="equal")}}return _}function Pa(e){for(const t of xa)if(t in e)return t;return null}function J(e,t){if(e===null||t===null)return"incomparable";if(o.isStrictTemporalDataValue(e)&&o.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return o.isStrictNumericDataValue(e)&&o.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var Ra=(e,t)=>{const r=Vr(e,t.predicate);if(r===null)return null;const{box:n,observations:a}=r,i=Ir(t.padding)===null?Da(n,t.padding):n;return{x:i.xMin,y:i.yMin,width:Math.max(0,i.xMax-i.xMin),height:Math.max(0,i.yMax-i.yMin),space:i.space,defer:{type:"observationBox",observations:a,padding:t.padding}}},Na=(e,t)=>{const r=Vr(e,t.predicate);if(r===null)return null;const{box:n,observations:a}=r;return{...o.alignToBoxPoint(n,t.align),space:n.space,defer:{type:"observationBox",observations:a,align:t.align}}},Ir=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"pxOffset",x:e.x??0,y:e.y??0},Vr=({warnings:e,layers:t,coordSystem:r,selectionBoxCache:n,parsingLocale:a},i)=>{if(n.has(i))return n.get(i)??null;let s=null;const c=[];let l=!1;const u=new Map;for(const m of t){if(!m.interactive)continue;const f=z(i,m.data,"selection-anchor");if(f.length>0){for(const h of f)u.set(`${h.code}:${h.message}`,h);continue}l=!0;const p=q(i,Ce(m,a));if(p===_)continue;let g=-1;for(const h of m.data){if(g+=1,!p(h))continue;const v=o.readObservationBox(h,r);v!==null&&(s=s===null?v:_a(s,v),c.push({layerId:m.id,observationIndex:g}))}}l||e.push(...u.values());const d=s===null?null:{box:s,observations:c};return n.set(i,d),d},_a=(e,t)=>({space:e.space,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),Da=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Te=(e,t,r)=>{const n=Ba(e,t,r);return n===null?null:n.defer?.type==="annotationRef"?n:n.defer?.type==="observationBox"?t.offset===void 0?n:{...n,defer:{...n.defer,offset:t.offset}}:$a(n,t.offset,e.coordSystem)},xr=(e,t)=>t.anchorType==="selection"?Ra(e,t):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotationRef",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},Er=(e,t,r)=>Ie(e,t,r)?.point??null,Ie=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const c=e.geomRegistry.get(s.geom),{resolveAnchorPosition:l}=c;if(l===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=br(s,c),d=Sr(s),m=fr(s),f=ar(s,n)(a);let p=-1;for(const g of s.data){if(p+=1,!d(g,f))continue;const h=l(g,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(h===null)continue;const v=Or(s,g,u);if(v===null)continue;const y=m(g);if(y!==null)return{point:{...h,...v,space:lr(r),observationIndex:p,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id}}}return null},Ma=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,c=a.y;if(s===void 0||c===void 0||s.kind!=="position"||c.kind!=="position")return null;const l=Et(t.x,"x",r,i),u=Et(t.y,"y",r,i);if(l===null||u===null)return null;const d=ka(e,s,l),m=c.map(u);if(!o.isPointWithinPanel(d,m))return null;const f=xt(d,s,ja(e)),p=xt(m,c),g=Fe(n.mainAxis,{main:f.min,cross:p.min}),h=Fe(n.mainAxis,{main:f.max,cross:p.max});return o.alignToBoxPoint({xMin:g.x,xMax:h.x,yMin:g.y,yMax:h.y},t.align??"center")},Or=(e,t,r)=>{const n=r.read(t);return o.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:ga(r.valueFormat,t),yScaleType:e.yScaleType}:null},ka=({layers:e,coordSystem:t,container:r},n,a)=>{if(o.isStrictNumericDataValue(a))return n.map(a);const i=e.filter(s=>o.spansCategoriesOnX(r.geomRegistry.get(s.geom)));return i.length===0?n.map(a):ba(i,Le(t)==="y",a)??NaN},Ba=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Ma(e,t);case"selection":return Na(e,t);case"annotation":return{x:0,y:0,defer:{type:"annotationRef",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":{const n=Ie(e,Fa(t),r);if(n===null)return null;const{point:a,layerId:i}=n;if(t.align===void 0)return a;const s=[{layerId:i,observationIndex:a.observationIndex}];return{...a,defer:{type:"observationBox",observations:s,align:t.align}}}}},$a=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ir(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},xt=(e,t,r=1)=>{const{bandwidth:n}=t;if(n===null||n<=0)return{min:e,max:e};const a=n*r/2;return{min:e-a,max:e+a}},ja=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},Fa=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Et=(e,t,r,n)=>{for(const a of r){const i=o.readVariableName(a.mapping[t]);if(!(i===null||i===o.CONSTANT_VARIABLES.x))return o.parseAddressingValue(e,o.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Ua=class extends o.Stage{constructor(e){super(),this.container=e,this.warningsByOutput=new WeakMap}compile(e){const t=super.compile(e);for(const r of this.warningsByOutput.get(t)??[])this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s=[],c={container:this.container,warnings:s,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},l={differenceArrows:Qa(c,t.differenceArrows),shapes:qa(c,t.shapes),arrows:Wa(c,t.arrows),textAnnotations:Ha(c,t.textAnnotations),images:za(c,t.images),stickers:Xa(c,t.stickers),pinnedNumbers:Ja(c,t.pinnedNumbers),comments:Za(c,t.comments)};return Ga(s,l),Ya(s,l),this.warningsByOutput.set(l,s),l}},R=(e,t,r,n)=>{e.push({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},Ga=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.push({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation carries id "${a}" — references to it resolve to the first, and the rest cannot be addressed.`,context:{annotationId:a},suggestion:"Give each annotation its own id."});continue}r.add(a)}},Ya=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const a of n)r.add(a.id);for(const{id:n,ref:a}of Ka(t))r.has(a)||e.push({code:"ANNOTATION_REF_NOT_FOUND",message:`Annotation "${n}" references id "${a}", whose annotation could not be anchored and was dropped.`,context:{annotationId:n,ref:a},suggestion:"Fix the anchor on the target annotation or point this reference at one that resolves."})},Ka=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotationRef"&&t.push({id:n,ref:a.defer.ref})};for(const n of e.shapes)r(n.id,n.region);for(const n of e.images)r(n.id,n.region);for(const n of e.arrows)r(n.id,n.start),r(n.id,n.end);for(const n of e.textAnnotations)r(n.id,n.at);for(const n of e.stickers)r(n.id,n.at);return t},qa=(e,t)=>{const r=[];for(const n of t){const a=xr(e,n.region);if(a===null){R(e.warnings,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},za=(e,t)=>{const r=[];for(const n of t){const a=xr(e,n.region);if(a===null){R(e.warnings,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},Wa=(e,t)=>{const r=[];for(const n of t){const a=Te(e,n.start,"pin"),i=Te(e,n.end,"pin");if(a===null||i===null){R(e.warnings,"arrow",n.id,`has ${wr(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Ha=(e,t)=>{const r=[];for(const n of t){const a=Te(e,n.at,"pin");if(a===null){R(e.warnings,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},Xa=(e,t)=>{const r=[];for(const n of t){const a=Te(e,n.at,"pin");if(a===null){R(e.warnings,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Ja=(e,t)=>{const r=[];for(const n of t){const a=Er(e,n.at,"pin");if(a===null){R(e.warnings,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Za=(e,t)=>{const r=[];for(const n of t){const a=Er(e,n.at,"pin");if(a===null){R(e.warnings,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Qa=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)R(e.warnings,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Ie(e,n.start,"value"),i=Ie(e,n.end,"value");if(a===null||i===null){R(e.warnings,"differenceArrow",n.id,`has ${wr(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){R(e.warnings,"differenceArrow",n.id,"has both ends on the same observation");continue}ei(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},wr=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",ei=(e,t,r,n)=>{nr(r,n)||e.warnings.push({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:Be(r),actual:Be(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function ti(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,c]of r)c.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Lr(i),values:i};return new o.Dataset(n)}function Lr(e){const t=Array.isArray(e)?e:[e];for(const r of t)if(r!==null)return typeof r=="number"?"numeric":r instanceof Date?"temporal":"categorical";return"categorical"}var ri=class extends o.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(o.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:o.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){if(o.isVisualScale(n))continue;const a=o.readConstantValue(r[n]);if(a===void 0)continue;const i=o.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Lr(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},H=class{constructor(){this.perLayerMemo=o.createPerKeyMemo(),this.listMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},ni=class extends o.Stage{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.scales,e.layers]}run(e){return this.registry.get(e.coordSpec.coordType).setup(e)}},ai=class extends H{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,t){const[r]=this.registry.get(t.coordSpec.coordType).transform({coordSpec:t.coordSpec,coordSystem:t.coordSystem,layers:[e]});if(!r)throw new o.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},ii=class{constructor(e){this.setupStage=new ni(e),this.transformStage=new ai(e)}get setupStats(){return this.setupStage.stats}get transformStats(){return this.transformStage.stats}setup(e){return this.setupStage.compile(e)}transform(e){return this.transformStage.compile(e)}},oi=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}},scales:e.scales}}transform(e){return e.layers}},si=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"left",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}},scales:li(e.scales,e.layers)}}transform(e){return e.layers.map(t=>di(t))}},ci=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax],[o.POSITION_VARIABLES.xBand,o.POSITION_VARIABLES.yBand]],Ot=o.prefixInternalVariable("flipSwap"),li=(e,t)=>ui(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,ui=e=>{for(const t of e){const r=o.readVariableName(t.mapping.x);if(!r||!t.data.hasVariable(r))continue;const n=t.data.getType(r);if(n==="categorical"||n==="temporal")return!0}return!1},di=e=>{let t=e.data;for(const[r,n]of ci){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ot).renameVariable(n,r).renameVariable(Ot,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function mi(e){const t=new Set,r=[];for(const n of e){const a=n instanceof Date?n.getTime():String(n);t.has(a)||(t.add(a),r.push(n))}return r}var Cr=(e,t)=>mi(t.domain!==null&&t.domain.length>0?t.domain:e),Pr=(e,t)=>e.scaledAesthetic==="x"&&t.some(r=>o.readVariableName(r.mapping.x)===o.CONSTANT_VARIABLES.x)&&t.every(r=>o.readMainAxisVariable(r.mapping)==="")?{...e,domain:null}:e,fi=e=>{const t=e.length-1,r=e[t];if(r===void 0||t<1)return null;const n=[];for(let i=1;i<=t;i+=1){const s=e[i-1],c=e[i];s===void 0||c===void 0||n.push(c-s)}n.sort((i,s)=>i-s);const a=n[n.length-1>>1];return a===void 0?null:r+a},pi=e=>[...new Set(e)].sort((t,r)=>t-r),gi=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=Si(t,e.scales,e.layers),a=Ti(t,e.scales,e.layers);return{coordSystem:{type:"polar",axisMapping:t.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:t.innerRadius,startAngle:r,spokeRotation:n,bandAxis:a},scales:vi(t,e.scales,e.layers)}}transform(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new o.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=yi(r,n),i=Ii(t);return e.layers.map(s=>Vi(t.theta==="y"?xi(s):s,a,i))}},hi=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax],[o.POSITION_VARIABLES.xBand,o.POSITION_VARIABLES.yBand]],wt=o.prefixInternalVariable("polarSwap");function yi(e,t){return r=>o.positionToAngle(r,e,t)}function vi(e,t,r){return e.theta!=="x"?t:t.map(n=>{if(n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"||n.scaleType==="continuous"&&n.transform!=="linear"||n.domainMax!==null)return n;const a=bi(e,r),i=fi(a),s=a[0];return i===null||s===void 0?n:{...n,domainMin:n.domainMin??s,domainMax:i}})}function bi(e,t){const r=[];for(const n of t){const a=o.readVariableName(n.mapping[e.theta]);if(!(a===null||!n.data.hasVariable(a)))for(const i of n.data.getValues(a))i instanceof Date?r.push(i.getTime()):typeof i=="number"&&r.push(i)}return pi(r)}function Si(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Ai(n,e,r);return a===0?0:-Math.PI/a}function Ai(e,t,r){const n=[];for(const a of r){const i=o.readVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Cr(n,Pr(e,r)).length}function Ti(e,t,r){if(e.theta==="x")return"x";const n=t.find(i=>i.scaledAesthetic==="x")?.scaleType==="discrete",a=r.some(i=>i.position==="fill");return n&&!a?"y":null}function Ii(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Vi(e,t,r){let n=e.data;return n=$(n,o.POSITION_VARIABLES.x,t),n=$(n,o.POSITION_VARIABLES.xMin,t),n=$(n,o.POSITION_VARIABLES.xMax,t),n=$(n,o.POSITION_VARIABLES.xBand,t),n=$(n,o.POSITION_VARIABLES.y,r),n=$(n,o.POSITION_VARIABLES.yMin,r),n=$(n,o.POSITION_VARIABLES.yMax,r),n=$(n,o.POSITION_VARIABLES.yBand,r),{...e,data:n}}function $(e,t,r){if(!e.hasVariable(t))return e;const n=e.getValues(t,{type:"numeric"}).map(a=>a===null?null:r(a));return e.addVariable(t,"numeric",n)}function xi(e){let t=e.data;for(const[r,n]of hi){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,wt).renameVariable(n,r).renameVariable(wt,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}}var Ei=class extends o.Registry{constructor(){super("coord"),this.register("cartesian",new oi),this.register("flip",new si),this.register("polar",new gi)}},Oi=class{constructor(e){this.container=e}compile(e,t){const r=this.container.geomRegistry.get(e),n=r.compile(t),a={...t.mapping,...n.mapping};return{...n,data:o.fillIntervalAesthetics(n.data,r.positionRoles,a)}}},wi=class{compute({data:e,mapping:t}){const r=o.getGroupVariables(e,t);if(r.length===0)return{data:e.addConstantVariable(o.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=o.getStableKey(a.map(c=>c[s]));return{data:e.addVariable(o.GROUP_VARIABLES.group,"categorical",i)}}},Li=e=>{if(e===void 0)return{};const t={};for(const r of e.columns)r.label!==void 0&&(t[r.key]=r.label);return t},Ci=(e,t,r)=>{const n=W(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function W(e,t){const r=o.getAestheticFromScaledAesthetic(t);let n=null;for(const a of Rr(t,e)){const i=o.readVariableName(a.mapping[r]);if(o.isDefined(i)){if(o.isInternalVariable(i)){n??=i;continue}return i}}return n}var ot=(e,t)=>e===null?null:t[e]??e,Pi=(e,t)=>e===null?null:t[String(e)]??null,M=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Me(t);for(const n of e){if(!n.data.hasVariable(r))continue;const a=n.data.getValueFormat(r),i=a.type==="lookup"?a.fallback:a;return Ni(i,t)?i:Me(t)}return Me(t)},Ri=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Rr(t,e).some(r=>r.position==="fill");function Rr(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Me=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"identity":return{type:"text"}}},Ni=(e,t)=>{switch(t){case"continuous":return o.isNumericValueFormat(e);case"datetime":return o.isTemporalValueFormat(e);case"discrete":case"identity":return!0}},_i=[{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}],Lt={year:0,quarter:1,month:2,week:3,day:4,hour:5},Z=40,Di=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return $i(r.unit).range(e,new Date(t.valueOf()+1),n)},Mi=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Kn.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Z;case"day":return a/t>Z;case"week":return a/(7*t)>Z;case"month":return a/(30*t)>Z;case"quarter":return a/(90*t)>Z;case"year":return a/(365*t)>Z}},ki=(e,t)=>{const r=!o.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"monthYear"}:{type:"month"};case"week":return r?{type:"weeklyDateRangeWithYear"}:{type:"weeklyDateRange"};case"day":return r?{type:"date"}:{type:"dayMonth"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Bi=(e,t)=>{const r=ji(t);return r===null?!1:Lt[e]>Lt[r]},$i=e=>{switch(e){case"hour":return re.utcHour;case"day":return re.utcDay;case"week":return re.utcMonday;case"month":case"quarter":return re.utcMonth;case"year":return re.utcYear}},ji=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"monthYear":case"month":return"month";case"weeklyDateRange":case"weeklyDateRangeWithYear":return"week";case"date":case"dayMonth":return"day";case"datetime":case"time":return"hour";default:return null}},Nr={left:"right",right:"left",top:"bottom",bottom:"top"},Fi={x:!0,y:!0,ySecondary:!1},ve=20,Ct=new Set(["top","bottom"]),Ui={type:"percentage"};function Gi(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:c}=e;if(hr(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const l=qi(c,a,i.type,n),u=new Set(t.map(f=>f.position)),d=Wi(_r(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const f of o.SCALED_POSITION_AESTHETIC_KEYS){const p=r[f];if(!o.isDefined(p)||p.kind!=="position")continue;const g=Yi({scaledAesthetic:f,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:l,variableLabels:s,geomRegistry:c,flipped:Le(i)==="y"});m.push(g)}return m}function Yi(e){const{scaledAesthetic:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:c,variableLabels:l,geomRegistry:u,flipped:d}=e,{axisConfig:m,position:f,geometry:p}=zi(t,n,i,s),g=W(a,t),h=Xi(t,a,u),v=Ji(h),y=Zi({scale:r,scaledAesthetic:t,layers:a,spanLayers:h,flipped:d,variableName:g});return{scaledAesthetic:t,position:f,geometry:p,label:Ki(m,g,l),visible:m.visible,tickCandidates:Qi({scale:r,spanLayers:h,flipped:d,scaleValueFormat:y,categoryValueFormat:v,tickMode:m.ticks.mode}),valueFormat:y,categorySpan:v===null?void 0:{valueFormat:v,layerIds:h.map(b=>b.id)},tickMode:m.ticks.mode,showTicks:m.ticks.visible,showGrid:Hi(m,c,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Ki(e,t,r){return e.label===""?null:e.label!==null?e.label:t?r[t]??null:null}function qi(e,t,r,n){const a=t.flatMap(c=>{const l=e.get(c.geom).grid[r];return l?[l]:[]}),i=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY);return{x:{showGrid:Pt(i,n.axes.x.grid.visible)},y:{showGrid:Pt(s,n.axes.y.grid.visible)}}}function Pt(e,t){if(e&&t===null)return!1}function zi(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:_r(t.axes[e].position,r[e].position),geometry:r.x.geometry};case"y":return{axisConfig:t.axes[e],position:n,geometry:r.y.geometry};case"ySecondary":{const a=Nr[n],i=(0,F.merge)({},{visible:t.axes.y.visible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function _r(e,t){return Ct.has(e)===Ct.has(t)?e:t}function Wi(e,t){return t.has(e)?Nr[e]:e}function Hi(e,t,r){const{showGrid:n}=r==="x"?t.x:t.y;return n??e.grid.visible??Fi[r]}var Xi=(e,t,r)=>e!=="x"?[]:t.filter(n=>o.spansCategoriesOnX(r.get(n.geom))),Ji=e=>{const[t]=e;return t===void 0?null:M({layers:e,scaleType:"discrete",variableName:o.readVariableName(t.mapping.x)})},Zi=e=>{const{scale:t,scaledAesthetic:r,layers:n,spanLayers:a,flipped:i,variableName:s}=e,c=t.spec.scaleType;return a.length>0?M({layers:a,scaleType:c,variableName:pr(i).start}):Ri(n,r)?Ui:M({layers:n,scaleType:c,variableName:s})},Qi=e=>{const{scale:t,spanLayers:r,flipped:n,scaleValueFormat:a,categoryValueFormat:i,tickMode:s}=e;if(i!==null){const c=eo(r,n).map(l=>({...l,valueFormat:i}));if(c.length>0)return s==="edges"?to(c):c}return io(t,a,s)},eo=(e,t)=>{const r=gr(e,t)?.filter(no);if(r===void 0)return[];const n=new Map([...r].sort((a,i)=>i.end-i.start-(a.end-a.start)).map((a,i)=>[a,i]));return ao(r.length).map(a=>({ticks:r.filter(i=>(n.get(i)??0)<a).map(({value:i,start:s,end:c})=>({value:i,position:(s+c)/2})).sort(ro),source:"categories"}))},to=e=>{const t=e.at(-1);if(t===void 0||t.ticks.length<=2)return e.slice(-1);const r=t.ticks[0],n=t.ticks.at(-1);return r===void 0||n===void 0?e.slice(-1):[{...t,ticks:[r,n]}]},ro=(e,t)=>e.position-t.position,no=({start:e,end:t})=>{const r=(e+t)/2;return r>=-1e-9&&r<=1.000000001},ao=e=>e<=ve?Array.from({length:e},(t,r)=>r+1):Array.from({length:ve},(t,r)=>Math.round(1+r*(e-1)/(ve-1))),io=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=so(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=ve;s++){const c=e.generateTicks({count:s}),l=o.getStableKey(c);a.has(l)||(a.add(l),i.push({ticks:c.map(u=>te(e,u)),source:"generated"}))}return i}return e.spec.scaleType==="datetime"?oo(e,t):[{ticks:e.generateTicks().map(a=>te(e,a)),source:"generated"}]},oo=(e,t)=>{const[r,n]=e.domain;if(!o.isStrictTemporalDataValue(r)||!o.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(c=>te(e,c)),source:"generated"}];const a=new Set,i=[],s=(c,l)=>{if(c.length===0)return;const u=o.getStableKey(c);a.has(u)||(a.add(u),i.push({ticks:c.map(d=>te(e,d)),valueFormat:l,source:"generated"}))};for(const c of _i)Mi({...c,start:r,stop:n})||Bi(c.unit,t)||s(e.generateTicks({interval:c}),ki(c,t));return s(e.generateTicks({atInputs:!0})),i.sort((c,l)=>c.ticks.length-l.ticks.length),i},so=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!o.isDefined(r)||!o.isDefined(n)||o.getStableKey([r])===o.getStableKey([n])?null:{ticks:[te(e,r),te(e,n)],source:"generated"}},te=(e,t)=>({value:t,position:e.map(t)});function Dr({scale:e,aesthetics:t,layers:r}){const n=co({layers:r,aesthetics:t}),a=Mr({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function co({layers:e,aesthetics:t}){const r=Mr({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>o.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function Mr({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(l=>o.isDefined(i.mapping[l]));if(s===void 0)continue;const c=o.readVariableName(i.mapping[s]);if(!(c===null||!i.data.hasVariable(c)))for(const l of i.data.getValues(c,{distinct:!0})){const u=o.getStableKey(l);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(o.getStableKey(a))}var st=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function lo({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!st(n))return[];if(!t.some(c=>o.isDefined(c.mapping.color)))return[];const a=W(t,"color");if(kr({colorVariableName:a,xVariableName:W(t,"x"),mapsColorAcrossMultipleLayers:mo(t)>1,sharesColorVariable:uo(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(c=>o.isDefined(c.mapping.color));return Dr({scale:n,aesthetics:["color"],layers:t}).map(({value:c,geom:l,owner:u})=>{const d=u?.layerIndex??s,m=t[d],f=m?o.readVariableName(m.mapping.color):null;return{value:c,color:String(n.map(c)),geom:l,layerIndex:d,valueFormat:M({layers:m?[m]:t,scaleType:i,variableName:f}),label:Pi(c,r)}})}var kr=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,sharesColorVariable:n})=>n?!1:e===null||o.isInternalVariable(e)?!r:t!==null&&e===t;function uo(e,t,r){if(r===null)return!1;for(const n of o.SCALED_VISUAL_AESTHETIC_KEYS){if(n==="color")continue;const a=e[n];if(!(a===void 0||!st(a))&&W(t,n)===r)return!0}return!1}var mo=e=>e.filter(t=>o.isDefined(t.mapping.color)).length;function Br(e,t){return e.get(t.geom).summaries.supportsPerGroupHeadline===!0}function fo(e,t,r,n){const a=r.findIndex(i=>Br(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:ot(o.readVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function Rt(e,t,r){if(r===null||t===null)return[...e];const n=o.getStableKey(r);return e.filter((a,i)=>o.getStableKey(t[i]??null)===n)}var $r=e=>e==="none"?"first":e,po=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Nt(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Nt(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},go=(e,t)=>{if(e.length<2)return null;const r=e.at(-1),n=t==="previous"?e.at(-2):e.at(0);return r===void 0||n===void 0||r.cross===null||n.cross===null||n.cross===0?null:{variation:(r.cross-n.cross)/n.cross,against:n.main}},Nt=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function ho(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?yo(e,n):vo(e,n)}function yo(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=o.readVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:M({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function vo(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:c}=e;if(!a.some(d=>Br(c,d)))return null;const l=fo(c,s,a,i);if(l.length===0)return null;const u=l.map(d=>bo({group:d,show:t,compareWith:r.headline.compareWith,layers:a,scales:n})).filter(d=>d!==null);return u.length===0?null:{kind:"perGroup",items:u}}function bo({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=o.readVariableName(i.mapping.y);if(s===null||i.data.getType(s)!=="numeric"||t==="total"&&i.position==="fill")return null;const c=o.readVariableName(i.mapping.x),l=o.readVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=M({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=To(i.data,c),f=M({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:c}),p=Io(i.data,c),g=p.getValues(s,{type:"numeric"}),h=c!==null?p.getValues(c):[],v=l!==null?p.getValues(l):null,y=Rt(g,v,e.value),b=Rt(h,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:po(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:f,label:e.label,caption:So(t,m,b),comparison:Ao(t,r,m,b,y)}}function So(e,t,r){if(e==="current"){const i=r.at(-1);return i===void 0?null:{kind:"point",value:i}}if(!t)return null;const n=r.at(0),a=r.at(-1);return n===void 0||a===void 0?null:{kind:"range",from:n,to:a}}function Ao(e,t,r,n,a){return e!=="current"||!r?null:go(n.map((i,s)=>({main:i,cross:a[s]??null})),$r(t))}function To(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Io(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}var Vo=new Set(["line","area"]);function xo(e,...t){return e?t.includes(e.geom):!1}function Eo(e,t){return e.find(r=>r.id===t)}function Oo(e,...t){return e.find(r=>t.includes(r.geom))}function wo(e,...t){return e.filter(r=>t.includes(r.geom))}function ie(e,t){return e.interactive?!1:t.some(r=>r!==e&&o.areMappingsEquivalent(r.mapping,e.mapping))}function Lo(e,t){return t.filter(r=>r!==e&&!r.interactive&&o.areMappingsEquivalent(e.mapping,r.mapping))}function Co(e,t){return t.find(r=>r.interactive&&ie(e,[r]))??e}function Po(e){return Vo.has(e)}function ct(e){const t=e.filter(r=>!ie(r,e));return t.length>0?t:[...e]}function jr({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=ct(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Ro=3;function No({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){const c=ct(r),l=Ho(s,t.legend.position,c);if(l==="none")return{drawn:[],position:"none"};const u=new Map(i.map(y=>[o.getStableKey(y.value),y])),d=Fo(ko({scales:e,layers:r})),m=W(r,"x"),f=d.map(y=>{if($o(y,m,r))return null;const b=Go({group:y,variableLabels:a,layers:r,colorGroupsByValue:u});return b.items.length===0?null:{group:y,built:b}}).filter(o.isDefined),p=_o(f),g=Xo(s,l,p,c,n);if(f.length===0)return{drawn:[],position:g};if(l==="auto"&&Wo(s,p,c,n))return{drawn:[],position:g};const h=Jo(t.legend.display,{legendPosition:g,coordSystem:n,layers:r}),v=h==="direct"?ts(c[0]):null;return{drawn:f.map(({built:y})=>Do(y,{position:g,display:h,align:t.legend.align},v)),position:g}}function _o(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function Do(e,t,r){const{position:n,display:a}=t,i=Mo(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function Mo(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function ko(e){const{scales:t,layers:r}=e,n=[];for(const a of o.SCALED_VISUAL_AESTHETIC_KEYS){const i=t[a];if(i===void 0||i.kind==="identity"||!Bo(a,r))continue;const s=W(r,a),c=es(a,i);n.push({scaledAesthetic:a,scale:i,variableName:s,guideType:c})}return n}function Bo(e,t){const r=o.getAestheticFromScaledAesthetic(e);return t.some(n=>o.isDefined(n.mapping[r]))}function $o(e,t,r){const[n]=e;return n.scaledAesthetic!=="color"?!1:kr({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:jo(n.scaledAesthetic,r),sharesColorVariable:e.length>1})}function jo(e,t){const r=o.getAestheticFromScaledAesthetic(e);return t.filter(n=>o.isDefined(n.mapping[r])).length>1}function Fo(e){const t=new Map;for(const r of e){const n=Qo(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function Uo(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Go({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>o.getAestheticFromScaledAesthetic(u.scaledAesthetic)),s=Dr({scale:a.scale,aesthetics:i,layers:r}),c=M({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),l=r.find(u=>i.some(d=>o.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaledAesthetic),title:ot(a.variableName,t),items:s.map(u=>Yo(u,e,i,c,n,l))}}function Yo(e,t,r,n,a,i){const s={};for(const l of t)Uo(s,l.scaledAesthetic,l.scale.map(e.value));if(s.lineType===void 0){const l=o.readConstantValue(e.owner?.layer.mapping.lineType);o.isLineType(l)&&(s.lineType=l)}const c=qo(e,t,r,n,a);return{value:e.value,label:Ko(t,e,a),visual:s,normalizedY:null,geom:e.geom,valueFormat:c,layerId:e.owner?.layer.id??i}}function Ko(e,t,r){return e[0].scaledAesthetic!=="color"?null:r.get(o.getStableKey(t.value))?.label??null}function qo(e,t,r,n,a){if(t[0].scaledAesthetic==="color")return a.get(o.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=zo(i,r);return i===void 0||s===null?n:M({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function zo(e,t){if(e===void 0)return null;for(const r of t){const n=e.mapping[r];if(n===void 0)continue;const a=o.readVariableName(n);if(a!==null)return a}return null}function Wo(e,t,r,n){if(t>1)return!1;const a=n.type==="polar";return r.some(i=>e.get(i.geom).legend.suppressWhenSingleItem||a)}function Ho(e,t,r){if(t!=="auto")return t;const n=new Set(r.map(i=>e.get(i.geom).legend.defaultPosition)),[a]=n;return n.size===1&&a!==void 0?a:"auto"}function Xo(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,c=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,o.isStackedPosition(u.position)&&(c=!0))}const l=r>=Ro;return i&&s?"top":i?l?"right":"top":c?Zo(a)?"top":l?"right":"top":"top"}function Jo(e,t){return e==="pill"?"pill":jr(t)?"direct":"pill"}function Zo(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Qo(e){const t=e.scale.domain.map(o.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function es(e,t){return st(t)?"discrete":`continuous:${e}`}function ts(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(o.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(l=>o.isDefined(o.getYMax(l))||o.isDefined(o.getY(l)));if(!n)return;const a=de(n);if(!o.isDefined(a))return;const i=o.getYMin(n),s=o.getYMax(n)??o.getY(n);if(!o.isDefined(s))return;const c=o.isDefined(i)?(i+s)/2:s;t.set(String(a),c)}),t}var rs=class extends o.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config.axes,e.config.legend,e.config.headline,e.layers,e.coordSystem,e.originalData]}run(e){const t=Li(e.originalData),r=lo({scales:e.scales,layers:e.layers,valueLabels:Ci(e.originalData,e.layers,t)}),n={scales:e.scales,config:e.config,layers:e.layers,coordSystem:e.coordSystem,variableLabels:t,colorGroups:r,geomRegistry:this.container.geomRegistry},a=ho(n),i=No(n),s={...i,drawn:ns(a,i.drawn)};return{axes:Gi(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},ns=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Ue=(e,t,r)=>{switch(e){case"group":return as(t);case"xValue":return lt(t,r)}},Fr=e=>{const t=o.readMainAxisVariable(e);return t===""?null:t},as=e=>o.getStableKey([de(e)]),lt=(e,t)=>o.getStableKey([t!==null?e[t]??null:null]);function Ur(e){return e===null?null:{strategy:e,composition:Gr()}}function Gr(){return{dimmed:!1,matchedLayer:null,overlayCandidates:[]}}var is=class extends H{constructor(e){super(),this.container=e,this.warningsByLayer=new WeakMap}compile(e){const t=super.compile(e);for(const r of t)for(const n of this.warningsByLayer.get(r)??[])this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,t){const r=e.highlight;if(r===null)return e;const n=t.highlights.filter(c=>this.takesHighlight(e,c,t.layers)&&!this.leavesOverlayToHost(e,c,t));if(n.length===0)return e;const a=[],i=os({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,warnings:a}),s={...e,highlight:{...r,composition:i}};return this.warningsByLayer.set(s,a),s}takesHighlight(e,{layerId:t},r){if(t===void 0||t===e.id)return!0;const n=r.find(a=>a.id===t);return n!==void 0&&n.interactive&&ie(e,[n])}leavesOverlayToHost(e,t,r){if(t.scope==="group"||e.highlight?.strategy!=="overlayAnchor")return!1;const n=i=>{const s=r.specLayers.find(c=>c.id===i);return s&&(0,F.pick)(s,["transforms","stat","position","yScaleType"])},a=n(e.id);return r.layers.some(i=>i.interactive&&i.highlight?.strategy==="overlayAnchor"&&ie(e,[i])&&(0,F.isEqual)(n(i.id),a)&&this.takesHighlight(i,t,r.layers))}};function os({layer:e,highlights:t,parsingLocale:r,strategy:n,warnings:a}){const i=t.filter(T=>{const V=z(T.predicate,e.data);for(const x of V)a.push({...x,message:`${x.message} Dropping this highlight.`});return V.length===0}),s=Fr(e.mapping),c=Ce(e,r),l=i.map(T=>({predicate:q(T.predicate,c),scope:T.scope})),u=l.some(({scope:T})=>T==="group"),d=l.some(({scope:T})=>T==="xValue"),m=n==="overlayAnchor",f=e.data.size(),p=u?new Array(f):null,g=d?new Array(f):null,h=m?new Array(f):null,v=new Uint8Array(f),y=new Set,b=new Set;let S=!1,A=0;for(const T of e.data){let V,x;p!==null&&(V=Ue("group",T,s),p[A]=V),g!==null&&(x=Ue("xValue",T,s),g[A]=x),h!==null&&(h[A]=T);for(const{predicate:U,scope:G}of l)if(U(T))switch(G){case"group":V!==void 0&&y.add(V);break;case"xValue":x!==void 0&&b.add(x);break;case"observation":v[A]=1,S=!0;break}A++}if(y.size===0&&b.size===0&&!S)return Gr();const I=new Uint8Array(f),E=[];let C=0;for(let T=0;T<f;T++){const V=p?.[T],x=g?.[T],U=V!==void 0&&y.has(V),G=x!==void 0&&b.has(x),O=v[T]===1;if(n==="observationRerender")(U||O||G)&&(I[T]=1,C++);else if(U)I[T]=1,C++;else if(O||G){const B=h?.[T];B!==void 0&&E.push({observation:B,observationIndex:T})}}const k=C>0?{...e,data:e.data.filterByMask(I)}:null;return{dimmed:(n==="observationRerender"||y.size>0)&&k!==null,matchedLayer:k,overlayCandidates:E}}var ss=o.prefixInternalVariable("__ungrouped__");function cs(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&o.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,c=i.map((l,u)=>{if(l===null)return null;const d=r[u]??ss;let m=s.get(d);return m||(m=new o.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(l)});n=n.addVariable(a,"temporal",c)}return n}function ls(e){const t=e.findIndex(Ge);return e.map((r,n)=>Ge(r)&&n!==t?{...r,heading:!1}:r)}function Ge(e){return e.heading===!0}function Ye(e){return"range"in e?e.key??e.range.join("-"):e.key??e.aesthetic}var Yr=()=>({defaults:[],overrides:[],warnings:[],observation:{vocabulary:o.STYLE_TARGETS.geom.vocabulary,aesthetics:o.STYLE_TARGETS.geom.aesthetics},dashPresets:o.DASH_PRESETS.line,parts:{}}),Kr="y",ut={kind:"group",name:Kr};function qr({contract:e,entries:t,mapping:r,derivedVariables:n}){const a=e.map(Wr),i=a.some(u=>!oe(u)),s=i?a:[...a,ut],c=[];for(const[u,d]of Object.entries(t)){const m=s.findIndex(p=>zr(p,u)),f=m===-1?ds(u,r,n):s.splice(m,1)[0];f===void 0||d===!1||c.push(d===!0?f:ms(f,d))}const l=[...c,...s];return{fields:c.some(oe)?l.map(u=>c.includes(u)?u:fs(u)):l,hidesDefaultRows:!i&&!l.some(u=>u.kind==="group")}}function us({layerId:e,contract:t,entries:r,mapping:n,derivedVariables:a}){const i=t.map(Wr),s=i.some(l=>!oe(l))?i:[...i,ut],c=l=>s.some(u=>zr(u,l))||n[l]!==void 0||a.includes(l);return Object.keys(r).filter(l=>!c(l)).map(l=>({code:"UNKNOWN_TOOLTIP_FIELD",message:`Layer '${e}' has no tooltip field '${l}'; its tooltip entry is ignored.`,context:{layerId:e,requested:l,available:ps(s,n,a)},suggestion:"Name an aesthetic the layer maps, a variable its geom derives, or a field of the geom's tooltip."}))}function oe(e){return e.kind!=="group"&&e.heading}function zr(e,t){return e.name===t||e.kind==="aesthetic"&&e.aesthetic===t}function Wr(e){return"range"in e?{kind:"range",name:Ye(e),title:e.key,range:e.range,heading:e.heading===!0}:{kind:"aesthetic",name:Ye(e),title:e.key,aesthetic:e.aesthetic,heading:e.heading===!0}}function ds(e,t,r){if(t[e]!==void 0)return{kind:"aesthetic",name:e,aesthetic:e,heading:!1};if(r.includes(e))return{kind:"variable",name:e,variable:e,heading:!1}}function ms(e,{title:t,format:r,heading:n}){const a={...t!==void 0&&{title:t},...r!==void 0&&{format:r}};return e.kind==="group"?n===!0?{kind:"aesthetic",name:e.name,aesthetic:Kr,heading:!0,...a}:{...e,...a}:{...e,...a,...n!==void 0&&{heading:n}}}function fs(e){return oe(e)?{...e,heading:!1}:e}function ps(e,t,r){return[...new Set([...e.map(n=>n.name),...Object.keys(t),...r])]}var gs=class extends H{constructor(e,t,r,n,a,i){super(),this.container=e,this.transformCompiler=t,this.statCompiler=r,this.groupCompiler=n,this.geomCompiler=a,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,_t(e),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},hasDiscreteXScale:_t(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,hasDiscreteXScale:n,coordType:a}){const i=Oe({data:t,mapping:r}).pipe(({data:c,mapping:l})=>{const u=this.statCompiler.compute(e.stat,{data:c,mapping:l,hasDiscreteXScale:n,params:{...e.params},requiredAesthetics:o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(e.geom))});return{data:u.data,mapping:u.mapping}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>({data:cs(c),mapping:l})).pipe(({data:c,mapping:l})=>{const u=this.geomCompiler.compile(e.geom,{data:c,mapping:l,params:e.params,coordType:a});return{data:u.data,mapping:{...l,...u.mapping}}}).pipe(({data:c,mapping:l})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:c,mapping:l,stackMissingAsZero:"missingValues"in e.params&&e.params.missingValues==="zero"});return{data:u.data,mapping:{...l,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,attachment:null,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:qr({contract:ls(s.tooltip),entries:e.tooltip,mapping:i.mapping,derivedVariables:s.derivedVariables}),scaleConstraints:s.scaleConstraints,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:Ur(s.highlightStrategy),styles:Yr()}}};function _t(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Hr(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new o.UserInputError(r)}}function dt(e,t){return t.map(r=>{const n=e.has(r.geom)?e.get(r.geom):void 0;return{...r,scaleConstraints:n?.scaleConstraints,categorySpanAxes:n?.categorySpanAxes}})}function hs(e){return e.some(t=>o.isStackedPosition(t.position)||t.scaleConstraints?.bandPadding===0)}function mt(e){const t=Xr(e),r={};for(const{layer:a,scaleConstraints:i,crossAxis:s}of t)i.includeZero===!0&&(r[s]={nice:(r[s]?.nice??!0)&&a.position!=="fill"});const n=t.find(({scaleConstraints:a})=>a.requireCrossAxisBands===!0);return{discreteAxis:t.some(({scaleConstraints:a})=>a.requireMainAxisBands===!0)?"x":null,discreteCrossAxis:n?.crossAxis??null,bandedAxes:Ss(t),zeroAxes:r,bandPadding:As(t),inferColorScale:t.some(({scaleConstraints:a})=>a.inferColorScale===!0),categorySpanAxis:e.some(o.spansCategoriesOnX)?"x":null}}function ys(e){const t=Xr(e);return vs(t)??bs(e,t)}function vs(e){for(const t of e){if(t.scaleConstraints.requireCrossAxisBands!==!0)continue;const r=e.find(n=>n.scaleConstraints.includeZero===!0&&n.crossAxis===t.crossAxis);if(r!==void 0)return{aesthetic:t.crossAxis,layers:[Q(t.layer,t.index,"band"),Q(r.layer,r.index,"zero-anchored")]}}return null}function bs(e,t){const r=e.findIndex(o.spansCategoriesOnX),n=e[r];if(n===void 0)return null;const a=t.find(({index:c,scaleConstraints:l})=>c!==r&&l.requireMainAxisBands===!0);if(a!==void 0)return{aesthetic:"x",layers:[Q(n,r,"category-span"),Q(a.layer,a.index,"band")]};const i=e.findIndex(c=>c.hasNonNumericX===!0&&!o.spansCategoriesOnX(c)),s=e[i];return s===void 0?null:{aesthetic:"x",layers:[Q(n,r,"category-span"),Q(s,i,"discrete")]}}var Q=(e,t,r)=>({layerId:e.id,layerIndex:t,geom:e.geom,shape:r});function Xr(e){const t=[];return e.forEach((r,n)=>{const{scaleConstraints:a,yScaleType:i}=r;a!==void 0&&t.push({layer:r,index:n,scaleConstraints:a,crossAxis:o.resolveScaledYAesthetic(i)})}),t}function Ss(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.requireMainAxisBands===!0&&t.add("x"),r.requireCrossAxisBands===!0&&t.add(n);return[...t]}function As(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Ts(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Ts({scaleConstraints:e,crossAxis:t}){return e.requireCrossAxisBands!==!0?["x"]:e.requireMainAxisBands===!0?["x",t]:[t]}function Is(e,t,r){const n=Jr(e,t);return t.map((a,i)=>{const s=n[i],c=s===void 0?void 0:t[s];if(c===void 0)return a;const l={layerId:c.id,on:yr(a,c)};return r(a,[l.layerId,...l.on],()=>({...a,attachment:l}))})}function Vs(e,t){const r=Jr(e,t);return t.flatMap((n,a)=>{const i=e[a]?.attachTo??"none";return i==="none"||i==="previous"?[]:r[a]!==void 0?[]:[{code:"UNKNOWN_LAYER_ID",message:`Layer '${n.id}' attaches to '${i}', which is not an interactive, unattached layer of this chart.`,suggestion:"Name the id of an interactive layer that is not itself attached, or use 'previous'.",context:{layerId:n.id,layerIndex:a}}]})}function Jr(e,t){const r=new Map,n=new Set,a=c=>t[c]?.interactive===!0&&!n.has(c)&&s(c)===void 0,i=c=>{const l=e[c]?.attachTo??"none";if(l==="none")return;if(l==="previous"){for(let d=c-1;d>=0;d-=1)if(a(d))return d;return}const u=t.findIndex(d=>d.id===l);return u!==-1&&a(u)?u:void 0},s=c=>{if(r.has(c))return r.get(c);n.add(c);const l=i(c);return n.delete(c),r.set(c,l),l};return t.map((c,l)=>s(l))}var xs=new Set(["label","group"]),Dt={band:"a band scale","zero-anchored":"a value axis anchored at zero","category-span":"a continuous scale of the intervals its categories span",discrete:"a discrete scale of the categories it maps there"},Es=(e,t,r)=>{if(r.some(a=>a.axis==="x"&&a.role==="scalar"&&a.aesthetic==="x"))return!1;const n=o.readVariableName(e.x);return!o.isDefined(n)||o.isInternalVariable(n)||!t.hasVariable(n)||t.size()===0?!1:t.getType(n)!=="numeric"},Os=({aesthetic:e,layers:t})=>e!=="x"?"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'.":t.some(r=>r.shape==="discrete")?"Drop one of the layers, or map the other layer's x to a numeric column.":"Drop one of the layers.",ws=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n,this.attachedLayerMemo=o.createPerKeyMemo(),this.resolvedLayersMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.layerCompiler.stats,this.attachedLayerMemo.stats,this.resolvedLayersMemo.stats)}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);this.checkPostCompile(e.layers,t);const r=Is(e.layers,t,this.attachedLayerMemo);return this.resolvedLayersMemo(r,()=>r)}checkPreCompile(e){const t=[],r=[];e.layers.forEach((n,a)=>{const i=this.transformCompiler.compile({data:e.data,transforms:n.transforms}),s={...e.mapping,...n.mapping};r.push(Es(s,i,this.container.geomRegistry.get(n.geom).positionRoles));const c={layerId:n.id,layerIndex:a,geom:n.geom,position:n.position,stat:n.stat,params:{...n.params},effectiveMapping:s,data:i,coordType:e.coords.coordType,dataLabels:n.dataLabels};t.push(...this.validateLayer(c));const l=[...this.collectUndeclaredAesthetics(c),...this.collectPanelJustifyWarnings(c),...this.collectDuplicateTooltipHeadings(c)];for(const u of l)this.container.diagnostics.addWarning(u)}),t.push(...this.validateSharedScaleDemands(e.layers,r)),Hr(this.container.diagnostics,t)}checkPostCompile(e,t){const r=[...this.collectEmptyDataset(t),...this.collectUnknownTooltipFields(e,t),...Vs(e,t)];for(const n of r)this.container.diagnostics.addWarning(n)}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:c}=i;if(!c||s!=="panelStart"&&s!=="panelEnd")return[];if(a==="polar"||!this.container.geomRegistry.get(e).composite)return[];if(!o.hasMultipleGroups(r,t))return[];const l=s==="panelEnd"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${s}' will render as '${l}'.`,context:{layerIndex:n,expected:l,actual:s},suggestion:`Use justify '${l}' for this layer.`}]}collectDuplicateTooltipHeadings({layerId:e,layerIndex:t,geom:r}){const{tooltip:n}=this.container.geomRegistry.get(r);return n.filter(Ge).slice(1).map(a=>({code:"DUPLICATE_TOOLTIP_HEADING",message:`Layer '${e}': geom '${r}' marks more than one tooltip field as the heading; '${Ye(a)}' is shown as a row`,context:{layerIndex:t,geom:r,..."aesthetic"in a?{aesthetic:a.aesthetic}:{}},suggestion:"Set `heading: true` on one tooltip field only."}))}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i}){const s=[],c=o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(r)),l=this.resolveComputedAesthetics(n,a);for(const u of c)l.has(u)||o.isDefined(i[u])||s.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${u}'`,context:{layerIndex:t,aesthetic:u}});return s}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const c=[],l=this.resolveComputedAesthetics(n,a),{derivedVariables:u}=this.container.geomRegistry.get(r),d=new Set(u);for(const[m,f]of Object.entries(i)){if(l.has(m))continue;const p=o.readVariableName(f);p===null||p===""||d.has(p)||s.hasVariable(p)||c.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return c}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const{positionRoles:c}=this.container.geomRegistry.get(r),l=this.resolveComputedAesthetics(n,a),u=[];for(const d of c){if(!o.POSITION_NUMERIC_ROLES.has(d.role)||!o.isDefined(d.aesthetic)||l.has(d.aesthetic)||d.role==="scalar"&&d.aesthetic===d.axis)continue;const m=o.readVariableName(i[d.aesthetic]);if(m===null||!s.hasVariable(m)||s.size()===0)continue;const f=s.getType(m);f!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aesthetic}' must be numeric, but variable '${m}' is ${f}`,context:{layerIndex:t,aesthetic:d.aesthetic,variableName:m,variableType:f},suggestion:this.suggestNumericAestheticFix(d.aesthetic,d.axis,i,s)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=o.readVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i,data:s}){const{validateMapping:c}=this.container.geomRegistry.get(r);return c===void 0?[]:c({mapping:i,computedAesthetics:this.resolveComputedAesthetics(n,a),data:s}).map(l=>({...l,message:`Layer '${e}': ${l.message}`,context:{...l.context,layerIndex:t}}))}resolveComputedAesthetics(e,t){return this.statRegistry.get(e.type).resolveComputedAesthetics(e,t)}validateSharedScaleDemands(e,t){const r=ys(dt(this.container.geomRegistry,e).map((i,s)=>({...i,hasNonNumericX:!!t[s]})));if(r===null)return[];const[n,a]=r.layers;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r.aesthetic}' to be ${Dt[n.shape]}, but layer '${a.layerId}' (geom '${a.geom}') needs it to be ${Dt[a.shape]}. One scale cannot be both.`,context:{aesthetic:r.aesthetic,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:Os(r)}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const a=this.container.geomRegistry.get(r),i=o.spansCategoriesOnX(a)?a.supportedPositions.filter(s=>s!=="dodge"):a.supportedPositions;return i.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${i.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,params:a,effectiveMapping:i}){const{positionRoles:s,categorySpanAxes:c,aesthetics:l}=this.container.geomRegistry.get(r),u=this.resolveComputedAesthetics(n,a),d=new Set([...o.deriveDeclaredAesthetics(s),...c,...l.map(p=>p.name)]),m=xs,f=[];for(const p of Object.keys(i))o.isDefined(i[p])&&(d.has(p)||m.has(p)||u.has(p)||f.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return f}collectEmptyDataset(e){return hr(e)?[{code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."}]:[]}collectUnknownTooltipFields(e,t){return e.flatMap((r,n)=>{const a=t[n];if(a===void 0||Object.keys(r.tooltip).length===0)return[];const i=this.container.geomRegistry.get(r.geom);return us({layerId:r.id,contract:i.tooltip,entries:r.tooltip,mapping:a.mapping,derivedVariables:i.derivedVariables})})}},Ls=class extends o.Stat{constructor(...e){super(...e),this.type="count",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.x);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'count' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'count' stat."});if(o.readVariableName(t.y)!==null)throw new o.UserInputError({code:"CONFLICTING_STAT_MAPPING",message:"Cannot map 'y' variable together with 'count' stat",context:{aesthetic:"y"},suggestion:"Remove the 'y' mapping; the 'count' stat computes it."});const n=[...new Set([r,...o.getGroupVariables(e,t)])];return{data:e.groupBy(...n).rollup({[o.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:o.STAT_VARIABLES.count}}}},Cs=class extends o.Stat{constructor(...e){super(...e),this.type="identity",this.computedAesthetics=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Ps=class extends o.Stat{constructor(...e){super(...e),this.type="mean",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'mean' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const n=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'mean' stat requires a numeric 'y' (got '${n}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:n},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."})}return{data:e.size()===0?new o.Dataset({[o.STAT_VARIABLES.mean]:{type:"numeric",values:[]}}):e.rollup({[o.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:o.STAT_VARIABLES.mean}}}},Rs=2,Zr=1440*60*1e3,Ns=class extends o.Stat{constructor(...e){super(...e),this.type="smooth",this.computedAesthetics=new Set}computeStat({data:e,mapping:t,spec:r,hasDiscreteXScale:n}){if(r.type!=="smooth")throw new o.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=o.readVariableName(t.x),i=o.readVariableName(t.y);if(!o.isDefined(a))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'smooth' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'smooth' stat."});if(!o.isDefined(i))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'smooth' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'smooth' stat."});const s=e.getType(a),c=e.getType(i);if(e.size()>0&&c!=="numeric")throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:c}});const l=o.getGroupVariables(e,t),u=js(a,s,i,l,e);return l.length===0?Mt({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},hasDiscreteXScale:n}):e.groupBy(...l).forEach(d=>{const m=Fs(d,l);Mt({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,hasDiscreteXScale:n})}),{data:u.build(),mapping:{}}}},Mt=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,hasDiscreteXScale:c})=>{const{observations:l,temporalOrigin:u}=_s({data:e,xVariable:t,yVariable:n,xType:r});l.length<Rs||(c?$s({observations:l,spec:a,output:i,groupObservation:s}):ks({observations:l,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},_s=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Ds(a):null,c=[],l=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!o.isDefined(d)||!o.isDefined(m)||!Number.isFinite(m))continue;const f=Ms({xValue:d,xType:n,categoryRank:l,temporalOrigin:s});f!==null&&c.push({x:f,y:m,originalX:d})}return{observations:c,temporalOrigin:s}},Ds=e=>{let t=null;for(const r of e){if(!o.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Ms=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!o.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!o.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/Zr+1}case"categorical":{if(!o.isStrictCategoricalDataValue(e))return null;const a=r.get(e);if(a!==void 0)return a;const i=r.size+1;return r.set(e,i),i}default:throw new o.InternalError({message:`Unexpected xType: ${t}`})}},ks=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Qr(n,e);for(const[c,l]of s){if(!Number.isFinite(c)||!Number.isFinite(l))continue;const u=t==="temporal"?Bs(c,r):c;a.push({x:u,y:l,groupObservation:i})}},Bs=(e,t)=>t===null?new Date(e):new Date((e-1)*Zr+t),$s=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const c of e)a.has(c.x)||a.set(c.x,c.originalX);const i=[...a.keys()].sort((c,l)=>c-l);if(t.method==="loess"){const c=Qr(t,e),l=new Map;for(const[u,d]of c)Number.isFinite(d)&&(l.has(u)||l.set(u,d));for(const u of i){const d=l.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=en(t,e);for(const c of i){const l=a.get(c),u=s.predict(c);l===void 0||!Number.isFinite(u)||r.push({x:l,y:u,groupObservation:n})}},Qr=(e,t)=>e.method==="loess"?(0,Y.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):en(e,t),en=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Y.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Y.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Y.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Y.regressionQuad)().x(r).y(n)(t);case"power":return(0,Y.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Y.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new o.InternalError({message:"'loess' does not expose a 'predict' function"})}},js=(e,t,r,n,a)=>{const i=[],s=[],c=Object.fromEntries(n.map(l=>[l,[]]));return{push:({x:l,y:u,groupObservation:d})=>{i.push(l),s.push(u);for(const m of n)c[m]?.push(d[m]??null)},build:()=>{const l={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)l[u]={type:a.getType(u),values:c[u]??[],valueFormat:a.getValueFormat(u)};return new o.Dataset(l)}}},Fs=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Us=class extends o.Stat{constructor(...e){super(...e),this.type="sum",this.computedAesthetics=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'sum' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const i=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'sum' stat requires a numeric 'y' (got '${i}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:i},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."})}const n=o.readVariableName(t.x),a=[...new Set([...n===null?[]:[n],...o.getGroupVariables(e,t)])];return{data:e.groupBy(...a).rollup({[o.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:o.STAT_VARIABLES.sum}}}},Gs=7,ke=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],Ys=300,Ks=1e-14,P=1e-300,qs=200;function tn(e,t){if(e===.5)return 0;if(e<.5)return-tn(1-e,t);let r=0,n=1;for(;Bt(n,t)<e;)r=n,n*=2;for(let a=0;a<qs;a++){const i=(r+n)/2;if(i===r||i===n)break;Bt(i,t)<e?r=i:n=i}return(r+n)/2}function be(e){if(e<.5)return Math.log(Math.PI/Math.sin(Math.PI*e))-be(1-e);const t=e-1;let r=ke[0]??0;for(let a=1;a<ke.length;a++)r+=(ke[a]??0)/(t+a);const n=t+Gs+.5;return .5*Math.log(2*Math.PI)+(t+.5)*Math.log(n)-n+Math.log(r)}function kt(e,t,r){const n=t+r;let a=1,i=1-n*e/(t+1);Math.abs(i)<P&&(i=P),i=1/i;let s=i;for(let c=1;c<=Ys;c++){const l=2*c;let u=c*(r-c)*e/((t+l-1)*(t+l));i=1+u*i,Math.abs(i)<P&&(i=P),a=1+u/a,Math.abs(a)<P&&(a=P),i=1/i,s*=i*a,u=-((t+c)*(n+c)*e)/((t+l)*(t+l+1)),i=1+u*i,Math.abs(i)<P&&(i=P),a=1+u/a,Math.abs(a)<P&&(a=P),i=1/i;const d=i*a;if(s*=d,Math.abs(d-1)<Ks)break}return s}function zs(e,t,r){if(e<=0)return 0;if(e>=1)return 1;const n=be(t+r)-be(t)-be(r)+t*Math.log(e)+r*Math.log(1-e),a=Math.exp(n);return e<(t+1)/(t+r+2)?a*kt(e,t,r)/t:1-a*kt(1-e,r,t)/r}function Bt(e,t){const r=.5*zs(t/(t+e*e),t/2,.5);return e>=0?1-r:r}var Ws=new Set(["mean","median"]),Hs=new Set(["stderr","stdev","ci","iqr","range"]),Xs=new Set(["stderr","stdev","ci"]),Js=new Set(["iqr"]),Zs=new Set(["y"]),$t=new Set(["y","lower","upper"]),rn={lower:null,upper:null},Qs=class extends o.Stat{constructor(...e){super(...e),this.type="summary",this.computedAesthetics=$t}resolveComputedAesthetics(e){return e.type==="summary"&&e.interval===void 0?Zs:$t}computeStat({data:e,mapping:t,spec:r}){if(r.type!=="summary")throw new o.InternalError({message:`SummaryStat received a spec of type '${r.type}'`});ec(r);const n=o.readVariableName(t.y);if(!o.isDefined(n))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'summary' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'summary' stat."});if(e.size()>0&&e.hasVariable(n)&&e.getType(n)!=="numeric"){const p=e.getType(n);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'summary' stat requires a numeric 'y' (got '${p}' for variable '${n}')`,context:{aesthetic:"y",variableName:n,variableType:p},suggestion:"Map a numeric variable to 'y' when using the 'summary' stat."})}const a=o.readVariableName(t.x),i=[...new Set([...a===null?[]:[a],...o.getGroupVariables(e,t)])],s=e.groupBy(...i),c=ic(r.level),l=[],u=[];s.forEach(p=>{const g=tc(p,n);l.push(rc(g,r.estimate)),u.push(r.interval===void 0?rn:nc(g,r,r.interval,c))});const d=e.getValueFormat(n),m=s.rollup({}).addVariable(o.STAT_VARIABLES.summaryEstimate,"numeric",l,d);if(r.interval===void 0)return{data:m,mapping:{y:o.STAT_VARIABLES.summaryEstimate}};const f={y:o.STAT_VARIABLES.summaryEstimate,lower:o.STAT_VARIABLES.summaryLower,upper:o.STAT_VARIABLES.summaryUpper};return{data:m.addVariable(o.STAT_VARIABLES.summaryLower,"numeric",u.map(p=>p.lower),d).addVariable(o.STAT_VARIABLES.summaryUpper,"numeric",u.map(p=>p.upper),d),mapping:f}}};function ec({estimate:e,interval:t,level:r,mult:n}){if(Ws.has(e)||pe("estimate","'mean' or 'median'",e),t!==void 0){if(Hs.has(t)||pe("interval","'stderr', 'stdev', 'ci', 'iqr' or 'range'",t),e==="median"&&Xs.has(t))throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${t}' interval describes a mean, so it cannot surround a median`,context:{requested:"summary",param:"interval",expected:"'iqr' or 'range'",actual:t},suggestion:"Use estimate 'mean' with this interval, or interval 'iqr' or 'range' with a median."});if(e==="mean"&&Js.has(t))throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${t}' interval describes a median, so it cannot surround a mean`,context:{requested:"summary",param:"interval",expected:"'stderr', 'stdev', 'ci' or 'range'",actual:t},suggestion:"Use estimate 'median' with this interval, or interval 'stderr', 'stdev', 'ci' or 'range' with a mean."});t==="ci"&&!(Number.isFinite(r)&&r>0&&r<1)&&pe("level","a number between 0 and 1",r),(t==="stderr"||t==="stdev")&&!(Number.isFinite(n)&&n>0)&&pe("mult","a number greater than 0",n)}}function pe(e,t,r){throw new o.UserInputError({code:"INVALID_STAT_PARAM",message:`'summary' stat's '${e}' must be ${t}, got ${String(r)}`,context:{requested:"summary",param:e,expected:t,actual:String(r)},suggestion:`Set '${e}' to ${t}.`})}function tc(e,t){return e.getValues(t).filter(r=>o.isStrictNumericDataValue(r)&&Number.isFinite(r))}function rc(e,t){return e.length===0?null:t==="mean"?nn(e):Ke([...e].sort((r,n)=>r-n),.5)}function nc(e,t,r,n){const a=e.length,i=sc(e);if(a<2||i.lower===i.upper)return rn;switch(r){case"stderr":case"stdev":case"ci":{const s=nn(e),c=ac(r,oc(e,s),a,t.mult,n);return{lower:s-c,upper:s+c}}case"iqr":{const s=[...e].sort((c,l)=>c-l);return{lower:Ke(s,.25),upper:Ke(s,.75)}}case"range":return i;default:throw new o.InternalError({message:`Unexpected summary interval: ${String(r)}`})}}function ac(e,t,r,n,a){const i=t/Math.sqrt(r);return e==="stdev"?n*t:e==="stderr"?n*i:a(r-1)*i}function ic(e){const t=new Map;return r=>{const n=t.get(r);if(n!==void 0)return n;const a=tn(1-(1-e)/2,r);return t.set(r,a),a}}function nn(e){let t=0;for(const r of e)t+=r;return t/e.length}function oc(e,t){let r=0;for(const n of e)r+=(n-t)**2;return Math.sqrt(r/(e.length-1))}function sc(e){let t=1/0,r=-1/0;for(const n of e)n<t&&(t=n),n>r&&(r=n);return{lower:t,upper:r}}function Ke(e,t){const r=(e.length-1)*t,n=Math.floor(r),a=e[n]??0;return a+((e[Math.min(n+1,e.length-1)]??a)-a)*(r-n)}var cc=[new Cs,new Ls,new Ns,new Ps,new Us,new Qs],an=class extends o.Registry{constructor(){super("stat");for(const e of cc)this.register(e.type,e)}};function lc({geoms:e,stats:t,transforms:r}){const n=new o.GeomRegistry,a=new an,i=new o.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}var uc=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Pe=class{},dc=class extends Pe{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!o.readVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),i=mc(e)??[-.7/2,.7/2],s=r.length>1?o.BAR_GROUP_SCALE_PADDING_FRACTION:0,c=(0,D.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),l=c.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const f=a[m];if(!o.isDefined(f))continue;const p=c(String(f));o.isDefined(p)&&(u[m]=p,d[m]=p+l)}return{data:e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",u).addVariable(o.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},mc=e=>{const t=e.getConstant(o.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(o.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},jt=o.prefixInternalVariable("__ungrouped__"),on=(e,t)=>{const r=o.readVariableName(t.x),n=o.readVariableName(t.y);if(!r||!n)return null;const a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[jt]:a,c=e.getValues(r),l=e.getValues(n,{type:"numeric"}),u=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let f=0;f<d;f++){const p=o.getStableKey(c[f]??null),g=u[f],h=i?jt:g;if(!o.isDefined(h))continue;let v=m.get(p);v||(v=new Map,m.set(p,v));let y=v.get(h);y||(y=[],v.set(h,y)),y.push(f)}return{yValues:l,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},sn=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let c=-1,l=1/0,u=-1/0,d=-1,m=1/0,f=-1/0;for(const p of i.values())for(const g of p){const h=e[g],v=t[g];!o.isDefined(h)||!o.isDefined(v)||(s.push(g),(h<l||h===l&&v>u)&&(c=g,l=h,u=v),(v>f||v===f&&h<m)&&(d=g,m=h,f=v))}for(const p of s)a[p]=fc(p===c,p===d)}return a},fc=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",pc=class extends Pe{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t,stackMissingAsZero:r=!1}){const n=on(e,t);if(n===null)return{data:e,mapping:{}};const{yValues:a,observationIndicesByXAndGroup:i,uniqueGroupKeys:s,observationCount:c}=n,l=[...a],u=new Array(c).fill(0);for(const[,m]of i){let f=0,p=0;for(const v of s){const y=m.get(v);if(y!==void 0)for(const b of y){const S=a[b];S!=null&&(S>=0?f+=S:p-=S)}}let g=0,h=0;for(const v of s){const y=m.get(v);if(y!==void 0)for(const b of y){const S=a[b];if(S===void 0)continue;if(S===null){const E=r?g:null;u[b]=E,l[b]=E;continue}const A=S>=0?f:p;if(A===0){u[b]=0,l[b]=0;continue}const I=S/A;S>=0?(u[b]=g,l[b]=g+=I):(l[b]=h,u[b]=h+=I)}}}const d=sn(u,l,i,c);return{data:e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",u).addVariable(o.POSITION_VARIABLES.yMax,"numeric",l).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",a).addVariable(o.STACK_VARIABLES.role,"categorical",d),mapping:{}}}},gc=class extends Pe{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},hc=class extends Pe{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t,stackMissingAsZero:r=!1}){const n=on(e,t);if(n===null)return{data:e,mapping:{}};const{yValues:a,observationIndicesByXAndGroup:i,uniqueGroupKeys:s,observationCount:c}=n,l=[...a],u=new Array(c).fill(0);for(const[,p]of i){let g=0,h=0;for(const v of s){const y=p.get(v);if(y!==void 0)for(const b of y){const S=a[b];if(S!==void 0){if(S===null){const A=r?g:null;u[b]=A,l[b]=A;continue}S>=0?(u[b]=g,l[b]=g+=S):(l[b]=h,u[b]=h+=S)}}}}const d=sn(u,l,i,c);let m=e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",u).addVariable(o.POSITION_VARIABLES.yMax,"numeric",l).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",a).addVariable(o.STACK_VARIABLES.role,"categorical",d);const f=o.readVariableName(t.y);if(f!==null){const p=l.map((g,h)=>a[h]===null?null:g);m=m.addVariable(f,"numeric",p)}return{data:m,mapping:{}}}},yc=class extends o.Registry{constructor(){super("position"),this.register("identity",new gc),this.register("stack",new hc),this.register("fill",new pc),this.register("dodge",new dc)}},vc=class{map({data:e,layer:t,getPositionScale:r}){if(t.position!=="dodge"||!o.isDefined(r("x")?.bandwidth)||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s=n.map((c,l)=>{const u=a[l],d=i[l];return o.isDefined(u)&&o.isDefined(d)?(u+d)/2:c});return e.addVariable(o.POSITION_VARIABLES.xBand,"numeric",n).addVariable(o.POSITION_VARIABLES.x,"numeric",s)}},bc=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!o.isDefined(s.aesthetic)||o.isVisualScale(s.aesthetic))continue;const c=o.readVariableName(t.mapping[s.aesthetic]);if(!o.isDefined(c)||!a.hasVariable(c))continue;const l=r(o.resolvePositionScaledAesthetic(s.axis,t.yScaleType));if(!l)continue;const u=a.getValues(c,{type:"numeric"}).map(d=>o.isDefined(d)?l.map(d):null);a=a.addVariable(o.resolveScaledAestheticVariable(s.aesthetic),"numeric",u)}return a}},Sc=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){const a=o.readVariableName(t.mapping.x),i=r("x");if(!a||!i)return e;if(o.spansCategoriesOnX(n.get(t.geom)))return Ac(e,i);const s=e.getValues(a).map(c=>o.isDefined(c)?i.map(c):null);return e.addVariable(o.POSITION_VARIABLES.x,"numeric",s)}};function Ac(e,t){if(!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=r.map((i,s)=>{const c=n[s];return o.isDefined(i)&&o.isDefined(c)?(t.map(i)+t.map(c))/2:null});return e.addVariable(o.POSITION_VARIABLES.x,"numeric",a)}var Tc=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=o.isDefined(n)&&e.hasVariable(o.POSITION_VARIABLES.x)?Ic(e,r,n):Vc(e,r);return e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(o.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Ic(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=cn(c);for(let u=0;u<c;u++){const d=n[u],m=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(m)||!o.isDefined(f)||(l.min[u]=d+(s?-f:m)*r,l.max[u]=d+(s?-m:f)*r)}return l}function Vc(e,t){const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=cn(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function cn(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var xc=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.y),a=r(o.resolveScaledYAesthetic(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.y,"numeric",i)}},Ec=class{map({data:e,layer:t,getPositionScale:r}){const n=r(o.resolveScaledYAesthetic(t.yScaleType));if(!n||!e.hasVariable(o.POSITION_VARIABLES.yMin)||!e.hasVariable(o.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=o.isDefined(a)&&e.hasVariable(o.POSITION_VARIABLES.y)?Oc(e,n,a):wc(e,n);return e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(o.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Oc(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=ln(c);for(let u=0;u<c;u++){const d=n[u],m=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(m)||!o.isDefined(f)||(l.min[u]=d+(s?-f:m)*r,l.max[u]=d+(s?-m:f)*r)}return l}function wc(e,t){const r=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=ln(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function ln(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Lc=[new Sc,new xc,new Tc,new Ec,new vc,new bc];function Cc(e,t){const r=e[t];return r?.kind==="position"?r:null}var Pc=class extends H{constructor(e,t=Lc){super(),this.container=e,this.mappers=t}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,t){const r=a=>Cc(t.scales,a);let n=e.data;for(const a of this.mappers)n=a.map({data:n,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:n}}},Ft=e=>{const t=e.find(n=>n.scaledAesthetic==="color"),r=t?.scaleType==="discrete"?t.range?.[0]:void 0;return typeof r=="string"?r:void 0},Rc=(e,t)=>(o.BRICK_TONES_BY_COUNT[e][t]??o.BRICK_TONES_BY_COUNT[e].default).map(r=>o.BRICK_TONES[r]),Nc=(e,t)=>{const r=e.palettes?.categorical;return r!==void 0&&r.length>0?r:e.hasTouchingGeoms?Rc(e.colorScheme,t):o.DEFAULT_COLOR_PALETTE},N={transform:"linear",reverse:!1,nice:!0,domainMin:null,domainMax:null,range:null,interpolate:"lab",domainMid:null,symmetric:!1},Ut={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},ge={domainMin:null,domainMax:null,nice:!1,reverse:!1},ee={range:null,domain:null,padding:.1,reverse:!1},_c={rgb:ne.interpolateRgb,lab:ne.interpolateLab,hcl:ne.interpolateHcl,hsl:ne.interpolateHsl};function Ve(e){const t=Mc(e);return e.reverse?r=>t(1-r):t}function Dc(e={},t=2){const r=Ve(e);return Array.from({length:t},(n,a)=>r(t===1?0:a/(t-1)))}var un=({diverging:e=!1,palettes:t,range:r})=>Gt(r)??Gt(e?t?.diverging:t?.sequential)??(e?o.DEFAULT_DIVERGING_STOPS:o.DEFAULT_SEQUENTIAL_STOPS),Mc=e=>{const t=un(e),r=_c[e.interpolate??N.interpolate];return(0,ne.piecewise)(r,t.map(String))},Gt=e=>e!=null&&e.length>=2?e:void 0,kc=class extends o.Stage{constructor(e,t){super(),this.container=e,this.registry=t}compile(e){const t=super.compile(e);return this.warnEvenDivergingRamp(t),t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:hs(e.layers),zeroAxes:mt(e.layers).zeroAxes,palettes:this.container.theme?.palettes},a={};for(const[i,s]of t){const c=r.get(i)??[],l=s.scaleType==="discrete"?Pr(s,e.layers):s;a[i]=this.registry.get(l.scaleType).compile(l,c,n)}return a}warnEvenDivergingRamp(e){const t=e.color;if(t?.spec.scaleType!=="continuous"||t.domain.length!==3)return;const r=un({...t.spec,diverging:!0,palettes:this.container.theme?.palettes});r.length%2!==1&&this.container.diagnostics.addWarning({code:"EVEN_DIVERGING_RAMP",message:`Diverging colormap has ${r.length} stops. The midpoint blends the two central colors.`,context:{aesthetic:"color",scaleType:"continuous",actual:r.length},suggestion:"Use an odd number of stops with the neutral color in the middle."})}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=o.getAestheticFromScaledAesthetic(r.scaledAesthetic);for(const i of e.layers){if((r.scaledAesthetic==="y"||r.scaledAesthetic==="ySecondary")&&o.resolveScaledYAesthetic(i.yScaleType)!==r.scaledAesthetic||!o.isDefined(i.mapping[a])||r.scaleType==="continuous"&&this.spansCategoriesOf(i,a))continue;const s=o.readVariableName(i.mapping[a]);if(!o.isDefined(s)||o.isInternalVariable(s)||!i.data.hasVariable(s)||i.data.size()===0)continue;const c=i.data.getType(s);if(!n.includes(c)){const l=r.scaleType==="continuous"&&c==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${c})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}if(r.scaledAesthetic==="lineType"&&c!=="categorical"){const l=c==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${s}'. ${l}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}}}Hr(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!o.isDefined(s))continue;const c=i==="y"?o.resolveScaledYAesthetic(n.yScaleType):i,l=a.get(i)??(o.isScaledAestheticKey(c)?c:void 0);if(!o.isDefined(l)||!t.has(l))continue;const u=t.get(l)?.scaleType,d=this.spansCategoriesOf(n,i)?[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.xMax].filter(m=>n.data.hasVariable(m)):this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,l,r)}}return r}spansCategoriesOf(e,t){return t==="x"&&o.spansCategoriesOnX(this.container.geomRegistry.get(e.geom))}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!o.isDefined(n.aesthetic)||o.isVisualScale(n.aesthetic)||t.set(n.aesthetic,o.resolvePositionScaledAesthetic(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];const a=o.readVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(o.POSITION_VARIABLES.yMin)&&e.hasVariable(o.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Re=class{createPositionScale(e,t){return{kind:"position",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,...t}}},qe=(e,t,r)=>{const[n,a]=e;return t===0&&r===null&&a<=0?{domain:[n,0],pinnedLow:!1,pinnedHigh:!0}:r===0&&t===null&&n>=0?{domain:[0,a],pinnedLow:!0,pinnedHigh:!1}:{domain:[t??n,r??a],pinnedLow:t!==null,pinnedHigh:r!==null}};function Bc(e){const[t,r]=e.domain;return t>0?{...e,domain:[0,r],pinnedLow:!0}:r<0?{...e,domain:[t,0],pinnedHigh:!0}:e}function ze(e,t){return[t.pinnedLow?t.domain[0]:e[0],t.pinnedHigh?t.domain[1]:e[1]]}var $c=class extends Re{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t,r){if(e.scaleType!=="continuous")throw new o.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const n=o.isPositionScale(e.scaledAesthetic),a=e.scaledAesthetic==="color",i=this.computeDataDomain(t);return a?this.buildColorScale(i,e,r.palettes):n?this.buildPositionScale(i,e,r.zeroAxes[e.scaledAesthetic]!==void 0):this.buildVisualScale(i,e)}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e)typeof n!="number"||!Number.isFinite(n)||(n<t&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}createD3Scale(e,t,r,n=!1){const a=qe(e,r.domainMin,r.domainMax),i=n?Bc(a):a;let s=i.domain;n&&jc(a,i)&&this.warnIncompatibleDomain(r,a.domain,`'${r.scaledAesthetic}' holds zero for the geom drawn on it, so the pin at [${a.domain[0]}, ${a.domain[1]}] gives way to [${s[0]}, ${s[1]}].`,`Pin '${r.scaledAesthetic}' at or past zero, or drop the pin.`);const c=r.transform==="log"&&Fc(s);r.transform==="log"&&!c&&this.warnIncompatibleDomain(r,s,`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${s[0]}, ${s[1]}] — rendering a linear scale instead.`,n?`'${r.scaledAesthetic}' holds zero for the geom drawn on it; use a linear or sqrt transform.`:"Filter out non-positive values or set a positive domainMin so the log scale can apply.");const l=c?(0,D.scaleLog)():r.transform==="sqrt"?(0,D.scaleSqrt)():(0,D.scaleLinear)();return r.nice&&!c&&(s=ze(l.copy().domain(s).nice().domain(),i)),l.domain(s).range(t).clamp(r.clamp)}warnIncompatibleDomain(e,t,r,n){this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:r,context:{aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),scaleType:e.scaleType,actual:t},suggestion:n})}buildPositionScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t,r);return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildVisualScale(e,t){const r=Uc(t.range)??[0,1],n=t.reverse?[r[1],r[0]]:r,a=this.createD3Scale(e,n,t);return this.createVisualScale(t,{map:a,domain:a.domain(),generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildColorScale(e,t,r){const n=t.domainMid;if(n!==null){const a=this.resolveColorDomain(e,t),[i,s]=a.domain;if(n>i&&n<s){const[c,l]=this.symmetrizeDomain(a,t,n),u=Ve({...t,diverging:!0,palettes:r});return this.buildDivergingColorScale([c,n,l],t,u)}}return this.buildSequentialColorScale(e,t,Ve({...t,palettes:r}))}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,D.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){const r=qe(e,t.domainMin,t.domainMax);if(!t.nice)return r;const n=(0,D.scaleLinear)().domain(r.domain).nice().domain();return{...r,domain:ze(n,r)}}symmetrizeDomain(e,t,r){const{domain:n,pinnedLow:a,pinnedHigh:i}=e;if(!t.symmetric)return n;const s=Math.max(Math.abs(n[0]-r),Math.abs(n[1]-r));return[a?n[0]:r-s,i?n[1]:r+s]}},jc=(e,t)=>e.pinnedLow&&e.domain[0]!==t.domain[0]||e.pinnedHigh&&e.domain[1]!==t.domain[1],Fc=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Uc(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Gc=class extends Re{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new o.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=o.isPositionScale(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:"Datetime scale is not supported for non-position aesthetics",context:{aesthetic:e.scaledAesthetic},suggestion:"Use a continuous or discrete scale for non-position aesthetics (color, size, alpha, strokeWidth)."});return this.buildScale(n,e,this.collectInputDates(t))}collectInputDates(e){const t=new Set,r=[];for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();t.has(a)||(t.add(a),r.push(n))}return r.sort((n,a)=>n.getTime()-a.getTime()),r}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();a<t&&(t=a),a>r&&(r=a)}return t===1/0?[]:[new Date(t),new Date(r)]}createD3Scale(e,t,r){const n=(0,D.scaleUtc)().range(t).clamp(r.clamp);if(!Yc(e))return n.domain([]);const a=qe([e[0].getTime(),e[1].getTime()],r.domainMin,r.domainMax);if(n.domain(a.domain),r.nice){const[i,s]=n.nice().domain();i!==void 0&&s!==void 0&&n.domain(ze([i.getTime(),s.getTime()],a))}return n}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),c=i&&s?r.filter(l=>l>=i&&l<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&s?Di(i,s,l.interval):[]:a.ticks(l?.count)})}},Yc=e=>e.length===2&&o.isStrictTemporalDataValue(e[0])&&o.isStrictTemporalDataValue(e[1]),Kc=class extends Re{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t,r){if(e.scaleType!=="discrete")throw new o.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const n=o.isPositionScale(e.scaledAesthetic),a=Cr(t,e);if(n)return this.buildPositionScale(a,e);const i=e.scaledAesthetic==="color"?Nc(r,a.length):void 0;return this.buildVisualScale(a,e,i)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??ee.padding,a=t.reverse?[1,0]:[0,1],i=(0,D.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:c=>(i(String(c))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t,r){const n=e.map(String),a=t.range&&t.range.length>0?t.range:r,i=a&&a.length>0?(0,D.scaleOrdinal)().domain(n).range(a).unknown(a[0]):null,s=qc(t.scaledAesthetic,a);return this.createVisualScale(t,{map:c=>{const l=String(c);return i?i(l):l},domain:e,generateTicks:()=>e,...s===void 0?{}:{palette:s},...r===void 0?{}:{defaultPalette:r}})}},qc=(e,t)=>{if(e!=="color"||t===void 0||t.length===0)return;const r=[];for(const n of t){if(typeof n!="string")return;r.push(n)}return r},zc=class extends Re{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new o.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:o.getAestheticFromScaledAesthetic(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Wc=class extends o.Registry{constructor(e){super("scale"),this.register("continuous",new $c(e)),this.register("discrete",new Kc),this.register("datetime",new Gc),this.register("identity",new zc)}},dn={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Hc={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 ft(e,t){const{data:r,layers:n,mapping:a}=t;return{container:e,data:r,layers:n,mapping:a,demands:mt(dt(e.geomRegistry,n))}}function Ne(e,t){switch(t.scaleType){case"inferred":return{...Ne(e,el(e,t)),inferredFrom:t};case"continuous":{const r=dn[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in Ut?Ut[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":N.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??N.reverse,nice:t.nice??N.nice,clamp:t.clamp??r!=="position",domainMin:t.domainMin??N.domainMin,domainMax:t.domainMax??N.domainMax,range:t.range??n??null,interpolate:t.interpolate??N.interpolate,domainMid:t.domainMid??N.domainMid,symmetric:t.symmetric??o.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??ge.domainMin,domainMax:t.domainMax??ge.domainMax,nice:t.nice??ge.nice,reverse:t.reverse??ge.reverse,clamp:t.clamp??!1};case"discrete":return mn(t,e.demands);case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new o.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Xc(e,t){const{scales:r,layers:n,mapping:a,coords:i}=t,s=ft(e,t),c=il(al(rl(e,r,n,a),n),s.demands),l=new Map;for(const d of c)l.set(d.scaledAesthetic,d);const u=[...l.values()].map(d=>{const m=Zc(s,Jc(s,d));return Ne(s,m)});return i.coordType==="polar"?u.map(pt):u}function mn(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??ee.range,domain:e.domain??ee.domain,padding:e.padding??r??ee.padding,reverse:e.reverse??Qc(e.scaledAesthetic,t)}}var pt=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Jc(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:o.getAestheticFromScaledAesthetic(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),o.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Zc(e,t){return t.scaleType==="inferred"||t.scaledAesthetic!==e.demands.categorySpanAxis?t:t.scaleType==="continuous"?{...t,nice:t.nice??!1}:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom spanning categories on '${t.scaledAesthetic}' needs it to be a continuous scale, but the spec declares a '${t.scaleType}' one; continuous wins.`,context:{aesthetic:o.getAestheticFromScaledAesthetic(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a continuous scale, or omit it and let it be inferred.`}),o.continuous(t.scaledAesthetic,{nice:!1,..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Qc(e,t){return e===t?.discreteCrossAxis?!0:ee.reverse}function el({data:e,layers:t,mapping:r,demands:n},a){const i=tl(t,r,a.scaledAesthetic);if(a.scaledAesthetic===n.categorySpanAxis){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,nice:d?.nice??!1})}if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return o.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,...!s.nice&&{nice:!1}})}const c=o.readVariableName(i);if(!o.isDefined(c)||!e.hasVariable(c)||e.size()===0)return o.continuous(a.scaledAesthetic,a.options);const l=e.getType(c),u=dn[a.scaledAesthetic];switch(Hc[l][u]){case"discrete":return o.discrete(a.scaledAesthetic,a.options);case"datetime":return o.datetime(a.scaledAesthetic,a.options);case"continuous":return o.continuous(a.scaledAesthetic,a.options);default:return o.identity(a.scaledAesthetic)}}function tl(e,t,r){const n=o.getAestheticFromScaledAesthetic(r);for(const a of fn(r,e)){const i=a.mapping[n]??t[n];if(o.isDefined(o.readVariableName(i)))return i}return t[n]}function fn(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}function rl(e,t,r,n){const a=["x","y"].filter(i=>!t.some(s=>s.scaledAesthetic===i)&&fn(i,r).some(s=>nl(e,s,i,n)));return[...t,...a.map(i=>o.inferred(i))]}function nl(e,t,r,n){return e.statRegistry.get(t.stat.type).resolveComputedAesthetics(t.stat,{...t.params}).has(r)?!0:[r,...e.geomRegistry.get(t.geom).positionRoles.filter(a=>a.axis===r).map(a=>a.aesthetic??r)].some(a=>!!o.readVariableName(t.mapping[a]??n[a]))}function al(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,o.inferred("ySecondary")]}function il(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferColorScale?o.inferred("color"):o.discrete("color")]}var gt=class extends o.Stage{constructor(e){super(),this.registry=e}key(e){return e.data}dependencies(e){return[e.transforms]}run(e){return e.transforms.reduce((t,r)=>this.registry.get(r.transformType).apply(t,r),e.data)}},pn=new o.TransformRegistry,ol=new gt(pn),gn=(e,t)=>{const r=t.every(n=>pn.has(n.transformType));return t.length===0||!r?e:ol.compile({data:e,transforms:t})},Yt=0;function w(){return Yt+=1,`${Math.random().toString(36).slice(2,6)}${Yt.toString(36)}`}var sl={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},topLeft:{x:-1,y:-1},topRight:{x:1,y:-1},bottomLeft:{x:-1,y:1},bottomRight:{x:1,y:1}},cl=(e,t,r)=>{const n=ll(e,t),a=ml(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>pl(e,i,r)).filter(o.isDefined),shapes:(n.shapes??[]).map(i=>vl(e,i,a)).filter(o.isDefined),arrows:(n.arrows??[]).map(i=>Al(e,i,r,a)).filter(o.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>fl(e,i,r,a)).filter(o.isDefined),stickers:(n.stickers??[]).map(i=>gl(e,i,r,a)).filter(o.isDefined),images:(n.images??[]).map(i=>bl(e,i,a)).filter(o.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>hl(e,i,r)).filter(o.isDefined),comments:(n.comments??[]).map(i=>yl(e,i,r)).filter(o.isDefined)}},ll=(e,t)=>{if(t===void 0)return{};if(!ul(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:w()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},ul=e=>{const t=new Set;for(const r of dl(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},dl=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],ml=e=>{const t=new Set,r=[e.differenceArrows,e.shapes,e.arrows,e.textAnnotations,e.images,e.stickers,e.pinnedNumbers,e.comments];for(const n of r)for(const a of n??[])a.id!==void 0&&t.add(a.id);return t},ht=(e,t,r,n)=>{if(r.has(t))return!0;const a=n===void 0?"An annotation":`Annotation "${n}"`;return e.diagnostics.addWarning({code:"ANNOTATION_REF_NOT_FOUND",message:`${a} references id "${t}" but no annotation declares that id — dropping this annotation.`,context:{ref:t,...n!==void 0?{annotationId:n}:{}},suggestion:"Reference the explicit id of another annotation in the same spec, or set an id on the target."}),!1},fl=(e,t,r,n)=>{const a=xe(e,t.at,r,n,t.id);return a===null?null:{id:t.id??w(),content:t.content,at:a,width:t.width,align:t.align??o.TEXT_ANNOTATION_DEFAULTS.align}},pl=(e,t,r)=>{const n=se(e,t.start,r),a=se(e,t.end,r);return n===null||a===null?null:{id:t.id??w(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??o.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},se=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},xe=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return ht(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=se(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},gl=(e,t,r,n)=>{const a=xe(e,t.at,r,n,t.id);return a===null?null:{id:t.id??w(),at:a,sticker:t.sticker}},hl=(e,t,r)=>{const n=se(e,t.at,r);return n===null?null:{id:t.id??w(),at:n}},yl=(e,t,r)=>{const n=se(e,t.at,r);return n===null?null:{id:t.id??w(),at:n,content:t.content}},vl=(e,t,r)=>t.region.anchorType==="annotation"&&!ht(e,t.region.ref,r,t.id)?null:{id:t.id??w(),kind:t.kind??o.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??o.SHAPE_DEFAULTS.zOrder,region:Sl(t.region)},bl=(e,t,r)=>t.region.anchorType==="annotation"&&!ht(e,t.region.ref,r,t.id)?null:{id:t.id??w(),src:t.src,zOrder:t.zOrder??o.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??o.IMAGE_ANNOTATION_DEFAULTS.fit},Sl=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:o.SELECTION_PADDING_DEFAULT},Kt=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=sl[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Al=(e,t,r,n)=>{const a=xe(e,t.start,r,n,t.id),i=xe(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??w(),start:Kt(a),end:Kt(i),startArrowheadStyle:t.startArrowheadStyle??o.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??o.ARROW_DEFAULTS.endArrowheadStyle}},Tl={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{visible:!0,label:null,position:"bottom",grid:{visible:null},ticks:{visible:!0,mode:"auto"}},y:{visible:!0,label:null,position:"right",grid:{visible:null},ticks:{visible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},tooltip:{mode:"band"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,showTitle:!0,subtitle:null,showSubtitle:!0,caption:null,showCaption:!1,source:null,showSource:!1,graphyBadge:{visible:!1,position:"footer",variant:"full"}}};function hn(e,t){return(0,F.merge)({},Tl,t,e)}var Il={xLimits:null,yLimits:null},Se={theta:"x",startAngle:0,innerRadius:0};function yn(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,F.merge)({},Il,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Se.theta,startAngle:t.params?.startAngle??Se.startAngle,innerRadius:(0,F.clamp)(t.params?.innerRadius??Se.innerRadius,0,1)}}}}function Vl(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??w(),predicate:a.predicate,scope:a.scope??"observation",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var xl=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"userInput"};t.persistent?this.persistent.push(r):this.diagnostics.push(r)}addError(e){this.diagnostics.push({...e,severity:"error",kind:"userInput"})}reset(){this.diagnostics=[]}drain(){const e=this.persistent.length===0?this.diagnostics:[...this.persistent,...this.diagnostics];if(e.length===0)return{errors:[],warnings:[]};const t=qt(e.filter(n=>n.severity==="error")),r=qt(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},El=class{constructor(e,t){this.sink=e,this.baseContext=t}addWarning(e,t){this.sink.addWarning(this.stampBaseContext(e),t)}addError(e){this.sink.addError(this.stampBaseContext(e))}stampBaseContext(e){const t=e.context??{};return{...e,context:{...t,...this.baseContext}}}};function qt(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var vn={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:o.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4},Ol={stat:{type:"identity"},position:"identity",params:{}},wl={stat:{type:"identity"},position:"identity",params:{curve:"linear",missingValues:"gap"}},Ll={stat:{type:"identity"},position:"stack",params:{curve:"linear",missingValues:"zero"}},Cl={stat:{type:"identity"},position:"dodge",params:{}},Pl={stat:{type:"identity"},position:"identity",interactive:!1,params:{labelPosition:"start"}},Rl={stat:{type:"identity"},position:"identity",params:{}};function bn(e,t){const r=e??(typeof t=="string"?t:t.type),n=typeof r=="string"?r:r.type;if(n==="smooth"){const a=typeof r=="string"?void 0:r;return{type:"smooth",method:a?.method??"linear",order:a?.order??3,bandwidth:a?.bandwidth??.3}}if(n==="summary"){const a=typeof r=="string"?void 0:r,i=a?.interval??void 0;return{type:"summary",estimate:a?.estimate??"mean",...i!==void 0&&{interval:i},level:a?.level??.95,mult:a?.mult??1}}return{type:n}}function Sn(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new El(a,{layerIndex:i}):a,c=e.get(n.geom),l=n.position??c.defaultPosition,u=Dl({dataLabels:kl(e,t,n,l,r),geom:c,position:l,coordType:r,diagnostics:s});return _l({diagnostics:s,coordType:r,geom:c,position:l,dataLabels:u}),{id:n.id??w(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:bn(n.stat,c.defaultStat??"identity"),position:l,yScaleType:n.yScaleType??"primary",params:c.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??c.defaultInteractive,attachTo:n.attachTo??c.defaultAttachTo,tooltip:n.tooltip??{},dataLabels:u}}function Nl(e,t,r,n,a){const i=n.map((s,c)=>Sn(e,t,r,s,a,c));return Tn(e,i)}var An=(e,t,r,n)=>n.label!==void 0?n.label:vr({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Tn=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:et(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=o.readConstantValue(n.mapping.y);if(!o.isStrictNumericDataValue(a))return n;const i=(0,F.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},_l=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&o.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},Dl=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panelStart"&&i!=="panelEnd")return e;const c=Ml(t,r,n);if(c===null)return e;const l=i==="panelEnd"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${c}; justify '${i}' will render as '${l}'.`,context:{expected:l,actual:i},suggestion:`Use justify '${l}' for this layer.`}),{...e,justify:l}},Ml=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&o.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,kl=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=An(e,r.geom,n,i),c=e.get(r.geom);return{...(0,F.merge)({},vn,c.resolveDataLabelDefaults?.(n)??{},c.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},In=e=>{const t={tokens:{},defaults:[],overrides:[]};for(const r of Bl(e))Object.assign(t.tokens,r.tokens),t.defaults.push(...r.defaults??[]),t.overrides.push(...r.overrides??[]);return t},Bl=e=>{const t=[],r=new Set,n=e===void 0?[]:[e];for(;n.length>0;){const a=n.pop();if(!(a===void 0||r.has(a))){r.add(a),t.push(a);for(const i of a.extends??[])n.push(i)}}return t.reverse()};function $l(e,t){const r=yn(t.coords),n=Nl(e.geomRegistry,t.mapping,r.coordType,t.layers,e.diagnostics),a=Xc(e,{data:gn(t.data,t.transforms),scales:t.scales,layers:n,mapping:t.mapping,coords:r}),i=hn(t.config,e.theme?.config),s=Vl(e,t.highlights,n),c=cl(e,t.annotations,n),l=In(t.styles);return{data:t.data,mapping:t.mapping,layers:n,scales:a,transforms:t.transforms,highlights:s,styles:l,annotations:c,coords:r,config:i}}var Vn=class{constructor(e){this.container=e}compile({spec:e,dataset:t}){return $l(this.container,{...e,data:t})}},jl=()=>{let e={},t=null;return{reset:()=>{e={}},getDuration:r=>e[r]??0,wrap:(r,n)=>a=>{const i=t,s={childrenMs:0};t=s;const c=performance.now();try{return n(a)}finally{const l=performance.now()-c;e[r]=(e[r]??0)+l-s.childrenMs,i&&(i.childrenMs+=l),t=i}}}},Fl=class{constructor(e){this.registry=e}compute(e,t){const r=this.registry.get(e.type),n=r.compute({data:t.data,mapping:t.mapping,spec:e,hasDiscreteXScale:t.hasDiscreteXScale,params:t.params});return Gl(r,r.resolveComputedAesthetics(e,t.params),n,t.requiredAesthetics),{data:n.data,mapping:{...Ul(t,n.data),...n.mapping}}}};function Ul({data:e,mapping:t},r){const n={};for(const[a,i]of Object.entries(t)){const s=o.readVariableName(i);s!==null&&e.hasVariable(s)&&!r.hasVariable(s)||(n[a]=i)}return n}function Gl(e,t,{data:r,mapping:n},a){for(const i of a){if(!t.has(i))continue;const s=n[i],c=o.readVariableName(s);if(!(o.isDefined(s)&&(c===null||r.hasVariable(c))))throw new o.UserInputError({code:"MISSING_STAT_OUTPUT",message:`Stat '${e.type}' declares it computes '${i}', which the layer's geom requires, but did not map it to a column of its output`,context:{aesthetic:i,requested:e.type},suggestion:`Return '${i}' in the stat's mapping, naming a column the stat writes.`})}}var xn=Object.keys(o.ANNOTATION_BUCKETS),Yl=e=>Object.hasOwn(o.ANNOTATION_BUCKETS,e),Kl=(e,t)=>{for(const r of xn){const n=zl(e,r,t);if(n)return n}return null},yt=(e,t)=>e[o.ANNOTATION_BUCKETS[t]],En=(e,t,r)=>({...e,[o.ANNOTATION_BUCKETS[t]]:r}),ql=(e,t)=>{const r=yt(e,t.kind);return En(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},zl=(e,t,r)=>{const n=yt(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},zt=Object.freeze({light:"#898373",dark:"#9F9886"}),Wl={graphBackground:o.DEFAULT_GRAPH_BACKGROUND,graphBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),geom:o.DEFAULT_GEOM_COLOR,geomBorder:Object.freeze({light:"rgba(58, 56, 51, 0.55)",dark:"rgba(237, 231, 218, 0.55)"}),textPrimary:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),textSecondary:zt,ruleLine:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),gridLine:Object.freeze({light:"#E1DAC9",dark:"#373531"}),hoverStroke:o.DEFAULT_HOVER_STROKE_COLOR,hoverGuideFill:Object.freeze({light:"#E7E1D2",dark:"#2B2A27"}),hoverGuideLine:Object.freeze({light:"#D5CDBA",dark:"#3B3934"}),legendFocus:Object.freeze({light:"color-mix(in srgb, transparent, #1D2129 50%)",dark:"color-mix(in srgb, transparent, #FFFFFF 50%)"}),tooltipBackground:Object.freeze({light:"#FCFCF9",dark:"#262522"}),tooltipBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),tooltipPrimaryRow:Object.freeze({light:"#F5F1E9",dark:"#2E2C29"}),annotationShape:Object.freeze({light:"#3b82f6",dark:"#60a5fa"}),annotationArrow:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),differenceLabelBackground:o.DEFAULT_GRAPH_BACKGROUND,trendPositive:{light:"#06B299",dark:"#0AC600"},trendNegative:{light:"#E14B49",dark:"#CB3333"},trendNeutral:zt},Hl=o.freezeWalkedEntries(o.walkStyleTargets()),_e=Object.freeze({tokens:Object.freeze(Wl),defaults:Object.freeze(Hl),overrides:Object.freeze([])}),Xl=class extends H{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e),r=Au(this.container.geomRegistry);for(const[n,a]of this.readStylesheets(e.styles)){const i=[...hu(n,t,a),...yu(n,a),...vu(n,a),...r(n,a),...Tu(n,a)];for(const s of i)this.container.diagnostics.addWarning(s)}for(const n of t)for(const a of n.styles.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.config.parsingLocale,e.coord,e.geomColor]}compileLayer(e,t){const r=Ln({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale,styleTarget:Cn(this.container.geomRegistry,e.geom),coord:t.coord,theme:this.container.theme?.styles,geomColor:t.geomColor});return{...e,styles:r}}readStylesheets(e){const t=this.container.theme?.styles;return t===void 0?[[e,"spec"]]:[[t,"theme"],[e,"spec"]]}},Jl=class extends o.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e),r=this.container.theme?.styles,n=[...r===void 0?[]:Jt(r,e.annotations,"theme"),...Jt(e.styles,e.annotations)];for(const a of n)this.container.diagnostics.addWarning(a);for(const a of t.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.coord,e.geomColor]}run(e){return wn(e.styles,{coord:e.coord,theme:this.container.theme?.styles,geomColor:e.geomColor})}},We=new o.GeomRegistry,Zl=new Set(o.STYLE_PROPERTY_NAMES),Ql=new WeakMap,eu=new WeakMap,Wt={stateless:0,dimmed:1,hovered:2},On={overpaint:{conditions:["where"],reason:"an overpaint covers the layer's shapes as one"},maxWidth:{conditions:["where","state"],reason:"a layer's bars share one cap"}},tu=Object.keys(On),wn=(e,{coord:t="cartesian",theme:r,geomColor:n}={})=>{const a=[],i=jn(e,r,n),s={...iu(),warnings:a},c=(l,u,d,m)=>{if(me(l)||!kn(l.select,t))return;const f=l.id===void 0?{}:{styleEntryId:l.id},p=l.select.target,g=ou(l.select);if(g.status==="unknown-target"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} targets unknown '${String(p)}'.`,context:{param:"target",actual:String(p),...f},suggestion:`Set 'target' to one of ${[...vt].map(A=>`'${A}'`).join(", ")}.`});return}if(g.status==="unknown-partition"){const{key:A,value:I,node:E}=g,C=He(E,A);a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} addresses unknown ${A} '${I}'.`,context:{param:A,actual:I,...f},suggestion:C.length===0?`Remove '${A}' — this target has none.`:`Set '${A}' to one of ${C.map(k=>`'${k}'`).join(", ")}, or omit it.`});return}if(g.status==="namespace"){const A=He(g.node,"part");a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: ${l.select.target} entries need a part.`,context:{param:"part",actual:String(l.select.part),...f},suggestion:`Set 'part' to one of ${A.map(I=>`'${I}'`).join(", ")}.`});return}const h=g.node;if(l.when!==void 0&&!bt(h)){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: chrome entries take no conditions.`,context:{param:"when",...f},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const v=h.options??[],y=l.select;if(y.layer!==void 0){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} does not take a layer.`,context:{param:"layer",actual:j(y.layer),...f},suggestion:"Remove 'layer' — this target is not layer-scoped."});return}if(y.annotation!==void 0){if(!v.includes("annotation")){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} does not take an annotation.`,context:{param:"annotation",actual:j(y.annotation),...f},suggestion:"Remove 'annotation' — this target is not annotation-scoped."});return}if(typeof y.annotation!="string"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${d} addresses an invalid annotation ${j(y.annotation)}.`,context:{param:"annotation",actual:j(y.annotation),...f},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}const b=$n({declarations:l.declarations,vocabulary:h.vocabulary,tokens:i,location:d,origin:m,warnings:a,entryTarget:l.select.target});if(Object.keys(b).length===0)return;const S=h.select.target;Pn(S)&&s[S][u].push({select:l.select,declarations:b,origin:m})};return _e.defaults.forEach((l,u)=>{c(l,"defaults",`builtin[${u}]`,{list:"builtin"})}),r?.defaults.forEach((l,u)=>{c(l,"defaults",le("theme","defaults",u),Xe(l,u))}),e.defaults.forEach((l,u)=>{c(l,"defaults",`defaults[${u}]`,{list:"defaults",index:u,...l.id===void 0?{}:{id:l.id}})}),r?.overrides.forEach((l,u)=>{c(l,"overrides",le("theme","overrides",u),Xe(l,u))}),e.overrides.forEach((l,u)=>{c(l,"overrides",`overrides[${u}]`,{list:"overrides",index:u,...l.id===void 0?{}:{id:l.id}})}),s},ru=e=>We.has(e)?We.get(e).styleTarget:void 0,Ln=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a,styleTarget:i,coord:s="cartesian",theme:c,geomColor:l}=e,u=Ce(t,a),d=[],m=jn(n,c,l),f=g=>g===t.geom?i:void 0,p=(g,h,v="spec")=>{const y=[];return g.forEach((b,S)=>{if(!me(b)||!kn(b.select,s))return;const A=b.select.kind;if(A!==void 0&&A!==t.geom||b.select.layer!==void 0&&b.select.layer!==t.id)return;const I=le(v,h,S);if(Bn(b,I,f)!==void 0)return;const E=b.when?.state;if(E!==void 0&&!Mn(E))return;const C=b.id===void 0?{}:{styleEntryId:b.id},k=v==="theme"?Xe(b,S):{list:h,index:S,...b.id===void 0?{}:{id:b.id}},T=b.when?.where;if(T!==void 0){const O=z(T,t.data,"style-rule");if(O.length>0){for(const B of O)d.push({...B,code:"INVALID_STYLE_RULE",message:`Style ${I}: ${B.message}`,context:{...B.context,layerIndex:r,...C}});return}}const V=Dn({select:b.select,declarations:b.declarations,layerGeom:t.geom,styleTarget:i,tokens:m,location:I,origin:k,warnings:d});E==="dimmed"&&V.overpaint!==void 0&&(d.push({code:"INVALID_STYLE_RULE",message:`Style ${I}: 'overpaint' is not supported in the 'dimmed' state; the declaration is ignored.`,context:{param:"overpaint",layerIndex:r,...C},suggestion:"Declare 'overpaint' without a state or in the 'hovered' state."}),delete V.overpaint);const x=[];for(const O of tu){if(V[O]===void 0)continue;const{conditions:B,reason:Gn}=On[O],De=B.find(Yn=>b.when?.[Yn]!==void 0);De!==void 0&&(x.push(O),d.push({code:"INVALID_STYLE_RULE",message:`Style ${I}: '${O}' does not take '${De}'; the declaration is ignored.`,context:{param:O,layerIndex:r,...C},suggestion:`Remove '${De}': ${Gn}.`}))}const U=x.length===0?V:Object.fromEntries(Object.entries(V).filter(([O])=>!x.includes(O)));if(Object.keys(U).length===0)return;const{part:G}=b.select;y.push({declarations:U,...T===void 0?{}:{matches:q(T,u),where:T},...E===void 0?{}:{state:E},...G===void 0?{}:{part:G},origin:k})}),y};return{defaults:[...gu(t.geom,i,m,d),...p(c?.defaults??[],"defaults","theme"),...p(n.defaults,"defaults")],overrides:[...p(c?.overrides??[],"overrides","theme"),...p(n.overrides,"overrides")],warnings:d,...uu(t.geom,i),dashPresets:i?.observation?.dashPresets??o.DASH_PRESETS.line}},Cn=(e,t)=>e.has(t)?e.get(t).styleTarget:void 0,nu=e=>t=>Cn(e,t),au=()=>{const e=new Set,t=r=>{if(e.add(r.select.target),r.children!==void 0)for(const n of Object.values(r.children))t(n)};for(const r of Object.values(o.STYLE_TARGETS))t(r);return e},vt=au(),Pn=e=>e!=="geom"&&vt.has(e),iu=()=>{const e={};for(const t of vt)Pn(t)&&(e[t]={defaults:[],overrides:[]});return e},He=(e,t)=>{if(e.children===void 0)return[];const r=[];for(const n of Object.values(e.children)){const a=n.select[t];a!==void 0&&r.push(a)}return r},Ht=e=>Object.keys(e.vocabulary).length===0&&e.children!==void 0,ou=e=>{const t=o.findStyleTarget(e);if(t!==void 0)return Ht(t)?{status:"namespace",node:t}:{status:"found",node:t};const r=o.findStyleTarget({target:e.target});if(r===void 0)return{status:"unknown-target"};let n=r;for(const a of o.STYLE_SELECT_KEYS){const i=e[a];if(i===void 0)continue;const s=n.children===void 0?void 0:Object.values(n.children).find(c=>c.select[a]===i);if(s===void 0)return{status:"unknown-partition",key:a,value:i,node:n};n=s}return Ht(n)?{status:"namespace",node:n}:{status:"found",node:n}},bt=e=>{const t=e.options??[];return t.includes("where")||t.includes("state")},su=(e,t)=>{const r=e==="geom"?We.getAll().find(n=>n.styleTarget!==void 0&&o.readObservationVocabulary(n.styleTarget)[t]!==void 0)?.type:e==="annotation"?Object.entries(o.STYLE_TARGETS.annotation.children).find(([,n])=>n.vocabulary[t]!==void 0)?.[0]:void 0;return r===void 0?void 0:`style.${e}.${r}`},me=e=>e.select.target==="geom",cu=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Rn=(e,t,r,n)=>{const a=e.get(r)??new Map;e.set(r,a);const i=a.get(t);if(i!==void 0)return i;const s=n();return a.set(t,s),s},Nn=(e,t)=>Rn(Ql,e,t,()=>o.createGeomStyleNode(e,t)),ce=(e,t)=>{const{kind:r,part:n}=e;if(r===void 0)return o.findStyleTarget({target:"geom",part:n});const a=t(r);if(a===void 0)return;const i=Nn(r,a);return n===void 0?i:cu(i.children,n)},lu=(e,t)=>{const r=ce(e,()=>t);return r===void 0||bt(r)},_n=(e,t)=>[e,t].filter(r=>r!==void 0).join(" "),uu=(e,t)=>{const r=ce({kind:e},()=>t),n={};for(const a of Object.values(r?.children??{}))a.select.part!==void 0&&(n[a.select.part]={vocabulary:a.vocabulary,aesthetics:a.aesthetics??{}});return{observation:{vocabulary:r?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,aesthetics:r?.aesthetics??o.STYLE_TARGETS.geom.aesthetics},parts:n}},Xt=(e,t)=>ce(e,()=>t)?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,du=(e,t)=>{const r={};for(const n of Object.keys(e)){const a=e[n];a===void 0||t[n]===void 0||(r[n]=a)}return r},Dn=e=>{const t=$n({declarations:e.declarations,vocabulary:Xt(e.select,e.styleTarget),tokens:e.tokens,location:e.location,origin:e.origin,warnings:e.warnings,entryTarget:"geom"});return e.select.part!==void 0?t:du(t,Xt({kind:e.layerGeom},e.styleTarget))},mu=(e,t)=>Rn(eu,e,t,()=>o.freezeWalkedEntries(o.walkStyleTargets([Nn(e,t)]))),fu=(e,t)=>Wt[e.state??"stateless"]-Wt[t.state??"stateless"],pu=(e,t)=>t===void 0?`builtin ${e}`:`builtin ${e}.${t}`,gu=(e,t,r,n)=>{const a=[],i={list:"builtin"},s=(c,l,u,d)=>{if(c.kind!==void 0&&c.kind!==e)return;if(u!==void 0&&!lu(c,t)){const p=_n(e,c.part);n.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: a ${p} entry takes no conditions.`,context:{param:"state",actual:u},suggestion:`Declare the ${u} paint on 'rest', or add 'state' to the part's options.`});return}const m=Dn({select:c,declarations:l,layerGeom:e,styleTarget:t,tokens:r,location:d,origin:i,warnings:n});if(Object.keys(m).length===0)return;const{part:f}=c;a.push({declarations:m,...u===void 0?{}:{state:u},...f===void 0?{}:{part:f},origin:i})};if(_e.defaults.forEach((c,l)=>{me(c)&&s(c.select,c.declarations,c.when?.state,`builtin[${l}]`)}),t===void 0)return a;for(const c of mu(e,t))s(c.select,c.declarations,c.when?.state,pu(e,c.select.part));return a.sort(fu)},le=(e,t,r)=>`${e==="theme"?"theme ":""}${t}[${r}]`,fe=(e,t,r)=>{e.defaults.forEach((n,a)=>r(n,le(t,"defaults",a))),e.overrides.forEach((n,a)=>r(n,le(t,"overrides",a)))},hu=(e,t,r="spec")=>{const n=new Set(t.map(i=>i.id)),a=[];return fe(e,r,(i,s)=>{const c=i.select;if(c.target!=="geom")return;const l=c.layer;l===void 0||typeof l!="string"||n.has(l)||a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown layer '${l}'.`,context:{param:"layer",actual:l,...i.id===void 0?{}:{styleEntryId:i.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),a},Jt=(e,t,r="spec")=>{const n=new Map(xn.flatMap(i=>t[o.ANNOTATION_BUCKETS[i]].map(s=>[s.id,i]))),a=[];return fe(e,r,(i,s)=>{const c=i.select;if(c.target!=="annotation")return;const l=c.annotation;if(l===void 0||typeof l!="string")return;const u={param:"annotation",actual:l,...i.id===void 0?{}:{styleEntryId:i.id}},d=n.get(l);if(d===void 0){a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown annotation '${l}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets sticker '${l}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const m=c.kind;m!==void 0&&m!==d&&a.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets ${d} '${l}' with an entry addressing kind '${String(m)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),a},yu=(e,t="spec")=>{const r=[];return fe(e,t,(n,a)=>{if(!me(n))return;const i=n.when?.state;i===void 0||Mn(i)||r.push({code:"INVALID_STYLE_RULE",message:`Style ${a} scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...n.id===void 0?{}:{styleEntryId:n.id}},suggestion:`Set 'state' to one of ${o.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),r},Mn=e=>o.STYLE_STATES.includes(e),kn=(e,t)=>e.coord===void 0||e.coord===t,Xe=(e,t)=>({list:"theme",index:t,...e.id===void 0?{}:{id:e.id}}),vu=(e,t="spec")=>{const r=[];return fe(e,t,(n,a)=>{const i=n.select.coord;i===void 0||o.STYLE_COORDS.includes(i)||r.push({code:"INVALID_STYLE_RULE",message:`Style ${a} names unknown coord '${String(i)}'.`,context:{param:"coord",actual:String(i),...n.id===void 0?{}:{styleEntryId:n.id}},suggestion:`Set 'coord' to one of ${o.STYLE_COORDS.map(s=>`'${s}'`).join(", ")}, or omit it.`})}),r},bu=(e,t,r)=>e===void 0?`Set 'kind' to the geom declaring '${t}' — a part is addressed on the kind that has it.`:r.length===0?`Remove 'part' — ${e} has none.`:`Set 'part' to one of ${r.map(n=>`'${n}'`).join(", ")}, or omit it.`,Bn=(e,t,r)=>{const{kind:n,part:a}=e.select;if(a===void 0)return;const i=e.id===void 0?{}:{styleEntryId:e.id},s=ce({kind:n,part:a},r);if(s===void 0){const c=ce({kind:n},r),l=c===void 0?[]:He(c,"part");return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown part '${a}'.`,context:{param:"part",actual:a,...i},suggestion:bu(n,a,l)}}if(e.when!==void 0&&!bt(s)){const c=_n(n,a);return{code:"INVALID_STYLE_RULE",message:`Style ${t} ignored: a ${c} entry takes no conditions.`,context:{param:"when",...i},suggestion:`Remove the 'when' clause — the ${c} is styled as a whole.`}}},Su=(e,t,r)=>{const{kind:n}=e.select;if(n===void 0||r.has(n))return;const a=r.getAll().map(i=>`'${i.type}'`);return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown geom kind '${n}'.`,context:{param:"kind",actual:n,...e.id===void 0?{}:{styleEntryId:e.id}},suggestion:`Set 'kind' to one of ${a.join(", ")}, or omit it to reach every geom.`}},Au=e=>{const t=nu(e);return(r,n="spec")=>{const a=[];return fe(r,n,(i,s)=>{if(!me(i))return;const c=Su(i,s,e)??Bn(i,s,t);c!==void 0&&a.push(c)}),a}},Tu=(e,t="spec")=>{const r=[];for(const[n,a]of Object.entries(e.tokens))o.isUsableTokenValue(a)||r.push({code:"INVALID_STYLE_RULE",message:`${t==="theme"?"Theme style":"Style"} token '${n}' has an invalid value: ${j(a)}.`,context:{param:"tokens",actual:j(a)},suggestion:`Set '${n}' to a non-empty color string or a { light, dark } pair of colors.`});return r},j=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),$n=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s,entryTarget:c}=e,l={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(g,h)=>{l[g]=h},m=(g,h,v)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: expected ${h}, got ${j(v)}.`,context:{param:g,expected:h,actual:j(v),...u},suggestion:`Set '${g}' to ${h}.`})},f=(g,h)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: unknown token '${h}'.`,context:{param:g,actual:h,...u},suggestion:`Declare '${h}' in the stylesheet's tokens.`})},p=g=>{const h=Zl.has(g),v=su(c,g),y=v===void 0?`Declare '${g}' on a target whose vocabulary carries it.`:`Declare '${g}' on an entry whose kind supports it (e.g. ${v}).`;s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${g}' ignored: ${h?"not in this entry's vocabulary":"not a style property"}.`,context:{param:g,...u},suggestion:h?y:`Remove the unknown declaration '${g}'.`})};for(const g of Object.keys(t)){const h=t[g];if(h===void 0)continue;const v=r[g];if(v===void 0){p(g);continue}const y=o.STYLE_DOMAINS[v](h,n);switch(y.status){case"accepted":d(g,y.value);break;case"rejected":m(g,y.expected,y.actual);break;case"unknownToken":f(g,y.token);break;case"dropped":break;default:break}}return l},jn=(e,t,r)=>({..._e.tokens,...t?.tokens,...r===void 0?{}:{geom:r},...e.tokens}),Iu=({layer:e})=>{if(e.position==="stack")return;const t=o.readVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];o.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Vu=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=o.readVariableName(e.mapping.x);if(r===null)return;const[n,a]=t==="y"?[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.xMax]:[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];if(!e.data.hasVariable(n)||!e.data.hasVariable(a))return;const i=u=>t==="y"?u.xMax:u.yMax,s=u=>t==="y"?u.xMin:u.yMin,c=new Map;for(const u of e.data){const d=u[r],m=t==="y"?o.getY(u):o.getX(u),f=o.getYMin(u)??(t==="y"?m:null),p=o.getYMax(u)??(t==="y"?m:null),g=o.getXMin(u)??(t==="x"?m:null),h=o.getXMax(u)??(t==="x"?m:null),v=o.getYRaw(u);if(!o.isDefined(d)||!o.isDefined(f)||!o.isDefined(p)||!o.isDefined(g)||!o.isDefined(h)||!o.isDefined(v))continue;const y=v>=0;if(Math.abs(v)===0)continue;const b=lt(u,r),S={xMin:g,xMax:h,yMin:f,yMax:p},A=c.get(b);if(A===void 0){c.set(b,{total:v,topPositive:y?S:null,bottomNegative:y?null:S});continue}A.total+=v,y?(A.topPositive===null||i(S)>i(A.topPositive))&&(A.topPositive=S):(A.bottomNegative===null||s(S)<s(A.bottomNegative))&&(A.bottomNegative=S)}const l=[];for(const[u,d]of c){const m=d.topPositive??d.bottomNegative;m!==null&&l.push({xKey:u,total:d.total,anchor:{xMin:m.xMin,xMax:m.xMax,yMin:m.yMin,yMax:m.yMax,direction:d.topPositive!==null?"positive":"negative"}})}return l},xu=class extends H{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=Le(t.coordSystem);if(r.summaries.includeStackTotals){const i=Vu({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.includeGrandTotal){const i=Iu({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Zt={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Eu=["color","size","alpha","strokeWidth","lineType"],Ou=class extends H{dependencies(e){return Eu.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(o.VISUAL_VARIABLES);for(const[a,i]of n){const s=o.readConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Zt[a],s);continue}const c=o.readVariableName(e.mapping[a]),l=t.scales[a];!c||!l||l.kind!=="visual"||(r=r.deriveVariableFrom(c,i,Zt[a],wu(l)))}return{...e,data:r}}},wu=e=>t=>o.isDefined(t)?e.map(t):null;function Fn(e=new o.GeomRegistry,t,r=new an){return{diagnostics:new xl,geomRegistry:e,statRegistry:r,theme:t}}var Lu=e=>({styles:Cu(In({type:"styles",...e.styles}),e.palettes?.categorical),palettes:e.palettes,config:e.config===void 0?void 0:Pu(e.config)}),Cu=(e,t)=>{const r=t?.[0];return e.tokens.geom!==void 0||r===void 0?e:{...e,tokens:{...e.tokens,geom:r}}},Pu=e=>{const{content:t,...r}=e;return r},Un=class{constructor(e,t,r,n,a,i,s,c,l,u,d,m,f,p,g,h){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=m,this.stylesCompiler=f,this.chromeStylesCompiler=p,this.highlightsCompiler=g,this.annotationsCompiler=h,this.stageTimer=o.IS_DEV?jl():null,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}],o.IS_DEV&&this.setupStageTiming()}get theme(){return this.container.theme}findGeom(e){const{geomRegistry:t}=this.container;return t.has(e)?t.get(e):null}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??Qt})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??Qt;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,ae(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=ft(this.container,{data:t.data,layers:t.layers,mapping:t.mapping});return ae(t,{scales:et(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=Ne(r,a);return t.coords.coordType==="polar"?pt(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[ir(e)],warnings:t.warnings}}setupStageTiming(){this.stageTimer&&(this.dataCompiler.compile=this.stageTimer.wrap("data",this.dataCompiler.compile.bind(this.dataCompiler)),this.transformCompiler.compile=this.stageTimer.wrap("transform",this.transformCompiler.compile.bind(this.transformCompiler)),this.constantMappingCompiler.compile=this.stageTimer.wrap("constantMapping",this.constantMappingCompiler.compile.bind(this.constantMappingCompiler)),this.layerPhasedCompiler.compile=this.stageTimer.wrap("layer",this.layerPhasedCompiler.compile.bind(this.layerPhasedCompiler)),this.coordCompiler.setup=this.stageTimer.wrap("coordSetup",this.coordCompiler.setup.bind(this.coordCompiler)),this.scaleCompiler.compile=this.stageTimer.wrap("scale",this.scaleCompiler.compile.bind(this.scaleCompiler)),this.positionMapperCompiler.compile=this.stageTimer.wrap("positionMapper",this.positionMapperCompiler.compile.bind(this.positionMapperCompiler)),this.visualMapperCompiler.compile=this.stageTimer.wrap("visualMapper",this.visualMapperCompiler.compile.bind(this.visualMapperCompiler)),this.coordCompiler.transform=this.stageTimer.wrap("coordTransform",this.coordCompiler.transform.bind(this.coordCompiler)),this.summarizeCompiler.compile=this.stageTimer.wrap("summarize",this.summarizeCompiler.compile.bind(this.summarizeCompiler)),this.guideCompiler.compile=this.stageTimer.wrap("guide",this.guideCompiler.compile.bind(this.guideCompiler)),this.stylesCompiler.compile=this.stageTimer.wrap("styles",this.stylesCompiler.compile.bind(this.stylesCompiler)),this.chromeStylesCompiler.compile=this.stageTimer.wrap("chromeStyles",this.chromeStylesCompiler.compile.bind(this.chromeStylesCompiler)),this.highlightsCompiler.compile=this.stageTimer.wrap("highlights",this.highlightsCompiler.compile.bind(this.highlightsCompiler)),this.annotationsCompiler.compile=this.stageTimer.wrap("annotations",this.annotationsCompiler.compile.bind(this.annotationsCompiler)))}trackCompile(e){if(!o.IS_DEV)return e();this.stageTimer?.reset();const t=this.getCacheStats(),r=performance.now();try{return e()}finally{const n=performance.now()-r,a={},i={};for(const{name:s,getStats:c}of this.stages){const l=c();a[s]={hits:l.hits-t[s].hits,misses:l.misses-t[s].misses},i[s]=this.stageTimer?.getDuration(s)??0}this.lastCompile={stages:a,durationMs:n,stageDurationsMs:i}}}runPipeline({spec:e,colorScheme:t}){return{...Oe({spec:e}).pipe(({spec:r})=>({spec:ae(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:ae(r,{data:n.data,mapping:n.mapping})}}).pipe(({spec:r})=>({layers:this.layerPhasedCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales})})).pipe(({spec:r,layers:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config,coord:je(r),geomColor:Ft(r.scales)})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations,coord:je(r),geomColor:Ft(r.scales)})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,specLayers:r.layers,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},Ru=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],Qt="light",Nu=({plugins:e=[],theme:t}={})=>{const r=o.readPlugins(e),{geomRegistry:n,statRegistry:a,transformRegistry:i}=lc(r),s=Fn(n,t===void 0?void 0:Lu(t),a),c=new Wc(s),l=new gt(i);for(const u of r.warnings)s.diagnostics.addWarning(u,{persistent:!0});return new Un(s,new o.DataCompiler,new Vn(s),l,new ri,new ws(s,l,a,new gs(s,l,new Fl(a),new wi,new Oi(s),new uc(new yc))),new kc(s,c),new ii(new Ei),new Pc(s),new Ou,new rs(s),new xu(s),new Xl(s),new Jl(s),new is(s),new Ua(s))};Object.defineProperty(exports,"AREA_DEFAULTS",{enumerable:!0,get:function(){return Ll}});Object.defineProperty(exports,"BAR_DEFAULTS",{enumerable:!0,get:function(){return Cl}});Object.defineProperty(exports,"BUILTIN_STYLES",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"COMPILER_STAGE_KEYS",{enumerable:!0,get:function(){return Ru}});Object.defineProperty(exports,"CONTINUOUS_SCALE_DEFAULTS",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"Compiler",{enumerable:!0,get:function(){return Un}});Object.defineProperty(exports,"DATA_LABELS_DEFAULTS",{enumerable:!0,get:function(){return vn}});Object.defineProperty(exports,"DEFAULT_ROWS_FIELD",{enumerable:!0,get:function(){return ut}});Object.defineProperty(exports,"DISCRETE_SCALE_DEFAULTS",{enumerable:!0,get:function(){return ee}});Object.defineProperty(exports,"LINE_DEFAULTS",{enumerable:!0,get:function(){return wl}});Object.defineProperty(exports,"POINT_DEFAULTS",{enumerable:!0,get:function(){return Ol}});Object.defineProperty(exports,"POLAR_COORD_DEFAULTS",{enumerable:!0,get:function(){return Se}});Object.defineProperty(exports,"RULE_DEFAULTS",{enumerable:!0,get:function(){return Pl}});Object.defineProperty(exports,"SpecCompiler",{enumerable:!0,get:function(){return Vn}});Object.defineProperty(exports,"TILE_DEFAULTS",{enumerable:!0,get:function(){return Rl}});Object.defineProperty(exports,"TransformCompiler",{enumerable:!0,get:function(){return gt}});Object.defineProperty(exports,"applyReplayableTransforms",{enumerable:!0,get:function(){return gn}});Object.defineProperty(exports,"areEndpointsComparable",{enumerable:!0,get:function(){return nr}});Object.defineProperty(exports,"arePredicatesEqual",{enumerable:!0,get:function(){return ia}});Object.defineProperty(exports,"areStyleDeclarationsEqual",{enumerable:!0,get:function(){return ua}});Object.defineProperty(exports,"areStyleRuleAddressesEqual",{enumerable:!0,get:function(){return la}});Object.defineProperty(exports,"buildDiagnostic",{enumerable:!0,get:function(){return ir}});Object.defineProperty(exports,"buildEmptyHighlightForStrategy",{enumerable:!0,get:function(){return Ur}});Object.defineProperty(exports,"buildLayerStyleAddress",{enumerable:!0,get:function(){return da}});Object.defineProperty(exports,"canAnchorDirectLabels",{enumerable:!0,get:function(){return jr}});Object.defineProperty(exports,"clampValuesAgainstFillSiblings",{enumerable:!0,get:function(){return Tn}});Object.defineProperty(exports,"combineKindStyleDeclarations",{enumerable:!0,get:function(){return ca}});Object.defineProperty(exports,"combineStyleDeclarations",{enumerable:!0,get:function(){return cr}});Object.defineProperty(exports,"compileChromeStyles",{enumerable:!0,get:function(){return wn}});Object.defineProperty(exports,"compileLayerStyles",{enumerable:!0,get:function(){return Ln}});Object.defineProperty(exports,"compilePredicate",{enumerable:!0,get:function(){return q}});Object.defineProperty(exports,"composePoint",{enumerable:!0,get:function(){return Fe}});Object.defineProperty(exports,"createAlphaValueReader",{enumerable:!0,get:function(){return Zn}});Object.defineProperty(exports,"createColorValueReader",{enumerable:!0,get:function(){return Xn}});Object.defineProperty(exports,"createCommonContainer",{enumerable:!0,get:function(){return Fn}});Object.defineProperty(exports,"createCompiler",{enumerable:!0,get:function(){return Nu}});Object.defineProperty(exports,"createDatasetFromKindPartitions",{enumerable:!0,get:function(){return ti}});Object.defineProperty(exports,"createDatasetPredicateCompileContext",{enumerable:!0,get:function(){return wa}});Object.defineProperty(exports,"createEmptyLayerStyles",{enumerable:!0,get:function(){return Yr}});Object.defineProperty(exports,"createGroupValueReader",{enumerable:!0,get:function(){return Qn}});Object.defineProperty(exports,"createLabelValueReader",{enumerable:!0,get:function(){return Hn}});Object.defineProperty(exports,"createLayerMeasurement",{enumerable:!0,get:function(){return br}});Object.defineProperty(exports,"createObservationAnchorBuilder",{enumerable:!0,get:function(){return fr}});Object.defineProperty(exports,"createObservationAnchorMatcher",{enumerable:!0,get:function(){return Sr}});Object.defineProperty(exports,"createObservationAnchorParser",{enumerable:!0,get:function(){return ar}});Object.defineProperty(exports,"createPipeline",{enumerable:!0,get:function(){return Oe}});Object.defineProperty(exports,"createPredicateColumnReader",{enumerable:!0,get:function(){return Tr}});Object.defineProperty(exports,"createPredicateCompileContext",{enumerable:!0,get:function(){return Ce}});Object.defineProperty(exports,"createPredicateValueReader",{enumerable:!0,get:function(){return Ar}});Object.defineProperty(exports,"createRawValueReader",{enumerable:!0,get:function(){return L}});Object.defineProperty(exports,"createRowPredicateCompileContext",{enumerable:!0,get:function(){return Oa}});Object.defineProperty(exports,"createScaleContext",{enumerable:!0,get:function(){return ft}});Object.defineProperty(exports,"createSegmentYReader",{enumerable:!0,get:function(){return Je}});Object.defineProperty(exports,"createSizeValueReader",{enumerable:!0,get:function(){return Jn}});Object.defineProperty(exports,"createStrokeWidthValueReader",{enumerable:!0,get:function(){return ea}});Object.defineProperty(exports,"createStyleRuleMatcher",{enumerable:!0,get:function(){return we}});Object.defineProperty(exports,"createXValueReader",{enumerable:!0,get:function(){return zn}});Object.defineProperty(exports,"createYValueReader",{enumerable:!0,get:function(){return Wn}});Object.defineProperty(exports,"describeMeasurementBasis",{enumerable:!0,get:function(){return Be}});Object.defineProperty(exports,"filterLayersByGeoms",{enumerable:!0,get:function(){return wo}});Object.defineProperty(exports,"findAnnotation",{enumerable:!0,get:function(){return Kl}});Object.defineProperty(exports,"findCompanionLayers",{enumerable:!0,get:function(){return Lo}});Object.defineProperty(exports,"findDefaultKitStyleTarget",{enumerable:!0,get:function(){return ru}});Object.defineProperty(exports,"findDistinctLayers",{enumerable:!0,get:function(){return ct}});Object.defineProperty(exports,"findGroupStyleRules",{enumerable:!0,get:function(){return ma}});Object.defineProperty(exports,"findHostLayer",{enumerable:!0,get:function(){return Co}});Object.defineProperty(exports,"findKindStyleDeclarations",{enumerable:!0,get:function(){return fa}});Object.defineProperty(exports,"findLayerByGeom",{enumerable:!0,get:function(){return Oo}});Object.defineProperty(exports,"findLayerById",{enumerable:!0,get:function(){return Eo}});Object.defineProperty(exports,"findPairingVariables",{enumerable:!0,get:function(){return yr}});Object.defineProperty(exports,"findPredicateProblems",{enumerable:!0,get:function(){return z}});Object.defineProperty(exports,"findStyleRule",{enumerable:!0,get:function(){return sr}});Object.defineProperty(exports,"findStyleRuleIndex",{enumerable:!0,get:function(){return rt}});Object.defineProperty(exports,"getCoordinates",{enumerable:!0,get:function(){return ya}});Object.defineProperty(exports,"getCrossAxisCoordinate",{enumerable:!0,get:function(){return mr}});Object.defineProperty(exports,"getGroup",{enumerable:!0,get:function(){return de}});Object.defineProperty(exports,"getLayerVariableValueFormat",{enumerable:!0,get:function(){return at}});Object.defineProperty(exports,"getLayerYValueFormat",{enumerable:!0,get:function(){return Va}});Object.defineProperty(exports,"getMainAxisCoordinate",{enumerable:!0,get:function(){return dr}});Object.defineProperty(exports,"getObservationXKey",{enumerable:!0,get:function(){return lt}});Object.defineProperty(exports,"isAnnotationKind",{enumerable:!0,get:function(){return Yl}});Object.defineProperty(exports,"isCartesian",{enumerable:!0,get:function(){return va}});Object.defineProperty(exports,"isCompanionLayer",{enumerable:!0,get:function(){return ie}});Object.defineProperty(exports,"isGeomStyleRule",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"isHeadingField",{enumerable:!0,get:function(){return oe}});Object.defineProperty(exports,"isLayerSpecOf",{enumerable:!0,get:function(){return xo}});Object.defineProperty(exports,"mapItems",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"measureAnchorSpace",{enumerable:!0,get:function(){return ur}});Object.defineProperty(exports,"paintsEachGroupFromItsFirstObservation",{enumerable:!0,get:function(){return Po}});Object.defineProperty(exports,"patchSpec",{enumerable:!0,get:function(){return ae}});Object.defineProperty(exports,"readAnnotationBucket",{enumerable:!0,get:function(){return yt}});Object.defineProperty(exports,"readDemandingLayers",{enumerable:!0,get:function(){return dt}});Object.defineProperty(exports,"readMainAxis",{enumerable:!0,get:function(){return Le}});Object.defineProperty(exports,"readObservationMeasurement",{enumerable:!0,get:function(){return Or}});Object.defineProperty(exports,"readPredicateKey",{enumerable:!0,get:function(){return Ae}});Object.defineProperty(exports,"readPredicateVariables",{enumerable:!0,get:function(){return ye}});Object.defineProperty(exports,"readScopeKey",{enumerable:!0,get:function(){return Ue}});Object.defineProperty(exports,"readScopeXVariable",{enumerable:!0,get:function(){return Fr}});Object.defineProperty(exports,"readStyleCoord",{enumerable:!0,get:function(){return je}});Object.defineProperty(exports,"readStyleRuleAddressKey",{enumerable:!0,get:function(){return K}});Object.defineProperty(exports,"readStyleRulesBeneath",{enumerable:!0,get:function(){return sa}});Object.defineProperty(exports,"removeDiscreteScalePadding",{enumerable:!0,get:function(){return pt}});Object.defineProperty(exports,"removeLocatedAnnotation",{enumerable:!0,get:function(){return ql}});Object.defineProperty(exports,"replaceAnnotationBucket",{enumerable:!0,get:function(){return En}});Object.defineProperty(exports,"replaceAtIndex",{enumerable:!0,get:function(){return aa}});Object.defineProperty(exports,"resolveAnchorVariable",{enumerable:!0,get:function(){return ue}});Object.defineProperty(exports,"resolveColormap",{enumerable:!0,get:function(){return Ve}});Object.defineProperty(exports,"resolveComparisonBasis",{enumerable:!0,get:function(){return $r}});Object.defineProperty(exports,"resolveConfig",{enumerable:!0,get:function(){return hn}});Object.defineProperty(exports,"resolveCoord",{enumerable:!0,get:function(){return yn}});Object.defineProperty(exports,"resolveCrossAnchorVariable",{enumerable:!0,get:function(){return Ze}});Object.defineProperty(exports,"resolveDiscreteScale",{enumerable:!0,get:function(){return mn}});Object.defineProperty(exports,"resolveGeomAnchorSpace",{enumerable:!0,get:function(){return lr}});Object.defineProperty(exports,"resolveGeomScaleDemands",{enumerable:!0,get:function(){return mt}});Object.defineProperty(exports,"resolveLabelSource",{enumerable:!0,get:function(){return An}});Object.defineProperty(exports,"resolveLayer",{enumerable:!0,get:function(){return Sn}});Object.defineProperty(exports,"resolveLayerTooltip",{enumerable:!0,get:function(){return qr}});Object.defineProperty(exports,"resolveScale",{enumerable:!0,get:function(){return Ne}});Object.defineProperty(exports,"resolveSegmentYSource",{enumerable:!0,get:function(){return Ee}});Object.defineProperty(exports,"resolveStatSpec",{enumerable:!0,get:function(){return bn}});Object.defineProperty(exports,"resolveVariableLabel",{enumerable:!0,get:function(){return ot}});Object.defineProperty(exports,"sampleColormap",{enumerable:!0,get:function(){return Dc}});Object.defineProperty(exports,"shouldNarrowByGroup",{enumerable:!0,get:function(){return Qe}});Object.defineProperty(exports,"toPanelFraction",{enumerable:!0,get:function(){return ha}});Object.defineProperty(exports,"uniqueId",{enumerable:!0,get:function(){return w}});Object.defineProperty(exports,"updateSpec",{enumerable:!0,get:function(){return na}});