@graphysdk/viz-engine 1.9.0-beta.1789377729015 → 1.9.0-beta.1789467548664

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.
Files changed (3) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.mjs +1258 -1246
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Hd=Object.create,mo=Object.defineProperty,Wd=Object.getOwnPropertyDescriptor,Kd=Object.getOwnPropertyNames,zd=Object.getPrototypeOf,Yd=Object.prototype.hasOwnProperty,qd=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Kd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!Yd.call(e,s)&&s!==r&&mo(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=Wd(t,s))||n.enumerable});return e},ir=(e,t,r)=>(r=e!=null?Hd(zd(e)):{},qd(t||!e||!e.__esModule?mo(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-p7nmFVnK.cjs");let be=require("color2k"),ho=require("date-fns"),at=require("lodash-es"),st=require("d3-time"),jd=require("date-fns/differenceInDays"),Re=require("d3-regression"),se=require("d3-scale"),je=require("d3-interpolate"),$=require("d3-scale-chromatic"),Je=require("lodash-es/clamp");Je=ir(Je,1);let jt=require("lodash-es/merge");jt=ir(jt,1);let Wr=require("humanize-duration");Wr=ir(Wr,1);let Pe=require("d3-shape"),Xd=require("d3-delaunay"),Xt=require("lodash-es/isEqual");Xt=ir(Xt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789377729015");var Zd=1e6;function te(e){return String(Math.round(e*Zd))}var Na="#FFFFFF",Vr="#1A1A1A",Jd=4.5,fo=e=>{try{return(0,be.getContrast)(e,Na)>(0,be.getContrast)(e,Vr)?Na:Vr}catch{return Vr}},Qd=(e,t)=>{try{const r=go(void 0,t);return r===void 0||(0,be.getContrast)(r,e)>=Jd?e:fo(r)}catch{return e}},go=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,be.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,be.parseToRgba)(e);return r>=1?e:(0,be.parseToRgba)(t)[3]<1?void 0:(0,be.mix)(t,(0,be.opacify)(e,1),r)}catch{return}},Ba=0;function W(){return Ba+=1,`${Math.random().toString(36).slice(2,6)}${Ba.toString(36)}`}var he=Math.PI*2,ep=8,tp=1e-9,rp=[0,Math.PI/2,Math.PI,he*3/4],yo=(e,t)=>Math.abs(t-e)>=he-tp,Oe=e=>(e%he+he)%he,Zt=(e,t,r)=>{if(yo(t,r))return!0;const n=Oe(r-t);return Oe(e-t)<=n},Qe=(e,t)=>{const r=Math.abs(Oe(e)-Oe(t));return Math.min(r,he-r)},Fa=(e,t)=>{const r=Oe(t-e);return r>Math.PI?r-he:r},vo=(e,t,r)=>e*he+t+r,fe=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Ce=(e,t)=>{const r=fe(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},np=(e,t,r,n)=>{const a=[Ce(e,r),Ce(e,n),Ce(t,r),Ce(t,n)],i=Math.max(r,n),o=rp.filter(c=>Zt(c,e,t)).map(c=>Ce(c,i)),s=[...a,...o];return{xMin:Math.min(...s.map(c=>c.x)),xMax:Math.max(...s.map(c=>c.x)),yMin:Math.min(...s.map(c=>c.y)),yMax:Math.max(...s.map(c=>c.y))}},or=(e,t)=>({angle:Oe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),sr=(e,t)=>{const r=e.x-.5,n=e.y-.5;return{x:t>=1?r*2*t:r*2,y:t>=1?n*2:n*2/t}},mn=(e,t)=>{const{x:r,y:n}=sr(e,t);return or(r,n)};function M(e){return e[l.POSITION_VARIABLES.x]}function D(e){return e[l.POSITION_VARIABLES.y]}function j(e){return e[l.POSITION_VARIABLES.xMin]}function X(e){return e[l.POSITION_VARIABLES.xMax]}function G(e){return e[l.POSITION_VARIABLES.yMin]}function F(e){return e[l.POSITION_VARIABLES.yMax]}function hn(e){return e[l.POSITION_VARIABLES.yRaw]}function ap(e,t){return e[l.resolveScaledAestheticVariable(t)]}var ip={xMin:0,xMax:1,yMin:0,yMax:1},bo=(e,t)=>{const r=j(e)??M(e),n=X(e)??M(e),a=G(e)??D(e),i=F(e)??D(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a)||!l.isStrictNumericDataValue(i)?null:t.type!=="polar"?{xMin:r,xMax:n,yMin:a,yMax:i}:{...np(r,n,a,i),frame:"disk"}},ft=(e,t)=>{const r=(e.xMin+e.xMax)/2,n=(e.yMin+e.yMax)/2;switch(t){case"top":return{x:r,y:e.yMax};case"bottom":return{x:r,y:e.yMin};case"left":return{x:e.xMin,y:n};case"right":return{x:e.xMax,y:n};case"top-left":return{x:e.xMin,y:e.yMax};case"top-right":return{x:e.xMax,y:e.yMax};case"bottom-left":return{x:e.xMin,y:e.yMin};case"bottom-right":return{x:e.xMax,y:e.yMin};default:return{x:r,y:n}}},So=e=>ft(ip,e),xo=["stack","dodge","identity","fill"],fn=["solid","dashed","dotted"],gn=e=>fn.includes(e);function U(e){return e==="stack"||e==="fill"}var Q=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},it=(e,t)=>Q(e,t.x),yn=(e,t)=>Q(e,t.y),op=(e,t)=>Q(e,t.label),Ao=(e,t)=>Q(e,t.color),sp=(e,t)=>Q(e,t.size),lp=(e,t)=>Q(e,t.alpha),cp=(e,t)=>Q(e,t.group),up=(e,t)=>Q(e,t.strokeWidth),$a={variable:l.POSITION_VARIABLES.yRaw};function lr(e,t){return U(e)?$a:t.y??$a}function gt(e){return Q(e.data,lr(e.position,e.mapping))}var Ne=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},vn=e=>dp(e)?l.extractVariableName(e.mapping.y):null,Io=e=>vn(e)===null?null:gt(e),bn=e=>e.spatialKind!=="cells",dp=e=>e.spatialKind==="points"||e.spatialKind==="cells",To=(e,t)=>e.yScaleType===t.yScaleType&&zr(e.valueFormat)===zr(t.valueFormat),Kr=e=>`${e.yScaleType} y axis, ${zr(e.valueFormat)}`,zr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Lo=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(Ne(e))),n=vn(e);return a=>({...a,anchorValue:l.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:l.parseAddressingValue(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:l.parseAddressingValue(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Eo(e){return e instanceof l.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 P(e,t){return Ro(e,t)}function R(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 wo(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Be(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 Ro(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const o=e[a];if(l.isPlainObject(i)&&l.isPlainObject(o)){const s=Ro(o,i);s!==o&&(n[a]=s,r=!0)}else i!==void 0&&i!==o&&(n[a]=i,r=!0)}return r?n:e}function cr(e){return{pipe:t=>{const r=t(e);return cr({...e,...r})},result:()=>e}}var pp=(e,t)=>{if(!l.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[l.getStableKey(r)]??e.fallback},Sn=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}},Ga=(e,t)=>{if(e.frame!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=ur(e.frame,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 Z(e,t){return e==="x"?t.x:t.y}function ge(e,t){return e==="x"?t.y:t.x}function ut(e,t){return{main:Z(e,t),cross:ge(e,t)}}function Ua(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function mp(e){return e.type==="cartesian"}var re=e=>e[l.GROUP_VARIABLES.group],yt=e=>{const t=Ne(e),r=Io(e),n=bn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const o=r===null?null:r(a);if(r!==null&&o===null)return null;const s=n?re(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},et=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,hp={type:"decimal"};function Co(e){return e.length>0&&e.every(t=>t.data.size()===0)}function xn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):hp}function fp(e){return xn(e,l.extractVariableName(e.mapping.y))}function Vo({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??lr(t,r)}function Do(e,t){const r=Vo({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:Q(e.data,r),valueFormat:xn(e,a)}}var _o=e=>{const t=Ne(e),r=Io(e),n=bn(e);return(a,i)=>!l.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||l.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:l.areDataValuesEqual(re(a),i.groupValue)},Po=e=>{const t=l.extractVariableName(e.mapping.y),r=gt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},gp=["lt","lte","gt","gte","range"],yp={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"}},me=()=>!1,He=()=>!0;function vt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Po(e),parsingLocale:t}}function xe(e,t){if("and"in e){const r=e.and.map(n=>xe(n,t)).filter(n=>n!==He);return r.includes(me)?me:r.length===0?He:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>xe(n,t)).filter(n=>n!==me);return r.includes(He)?He:r.length===0?me:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=xe(e.not,t);return r===me?He:r===He?me:n=>!r(n)}return bp(e,t)}function Ae(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Ae(n,t,r)):"or"in e?e.or.flatMap(n=>Ae(n,t,r)):"not"in e?Ae(e.not,t,r):vp(e,t,r)}function vp(e,t,r){const{subject:n,effect:a}=yp[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=Sp(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 bp(e,t){if(!t.hasVariable(e.variable))return me;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>l.parseAddressingValue(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);return i=>{const o=t.readValue(i,e.variable);for(const s of a)if(l.areDataValuesEqual(o,s))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>We(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=We(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>We(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=We(t.readValue(i,e.variable),a);return o==="greater"||o==="equal"}}if("range"in e){const[a,i]=e.range,o=n(a),s=n(i);return c=>{const u=t.readValue(c,e.variable),d=We(u,o),p=We(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return me}function Sp(e){for(const t of gp)if(t in e)return t;return null}function We(e,t){if(e===null||t===null)return"incomparable";if(l.isStrictTemporalDataValue(e)&&l.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return l.isStrictNumericDataValue(e)&&l.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var xp=(e,t,r,n,a,i)=>{const o=Mo(e,t,r.predicate,n,a,i);if(o===null)return null;const s=Oo(r.padding),c=s===null?Tp(o,r.padding):o,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin),frame:c.frame};return s===null?u:{...u,defer:s}},Ap=(e,t,r,n,a,i)=>{const o=Mo(e,t,r.predicate,n,a,i);return o===null?null:{...ft(o,r.align),frame:o.frame}},Oo=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Mo=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let o=null,s=!1;const c=new Map;for(const u of n){if(!u.interactive)continue;const d=Ae(r,u.data,"selection-anchor");if(d.length>0){for(const h of d)c.set(`${h.code}:${h.message}`,h);continue}s=!0;const p=xe(r,vt(u,i));if(p!==me)for(const h of u.data){if(!p(h))continue;const m=bo(h,a);m!==null&&(o=o===null?m:Ip(o,m))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},Ip=(e,t)=>({frame:e.frame,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)}),Tp=(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}},Jt=(e,t,r)=>{const n=Ep(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:wp(n,t.offset,e.coordSystem)},ko=(e,t)=>t.anchorType==="selection"?xp(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotation-ref",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},An=(e,t,r)=>Yr(e,t,r)?.point??null,Yr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const o of t){const s=e.geomRegistry.get(o.geom),{resolveAnchorPosition:c}=s;if(c===void 0||a.layerId!==void 0&&o.id!==a.layerId||a.layerId===void 0&&!o.interactive)continue;const u=Do(o,s),d=_o(o),p=yt(o),h=Lo(o,n)(a);let m=-1;for(const f of o.data){if(m+=1,!d(f,h))continue;const g=c(f,{coordSystem:r,position:o.position,purpose:i,align:a.align});if(g===null)continue;const v=No(o,f,u);if(v===null)continue;const y=p(f);if(y!==null)return{point:{...g,...v,frame:Sn(r),observationIndex:m,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:o.id}}}return null},Lp=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const o=a.x,s=a.y;if(o===void 0||s===void 0||o.kind!=="position"||s.kind!=="position")return null;const c=Wa(t.x,"x",r,i),u=Wa(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!et(d,p))return null;const h=Ha(d,o,Rp(e)),m=Ha(p,s),f=Ua(n.mainAxis,{main:h.min,cross:m.min}),g=Ua(n.mainAxis,{main:h.max,cross:m.max});return ft({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},No=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:pp(r.valueFormat,t),yScaleType:e.yScaleType}:null},Ep=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Lp(e,t);case"selection":return Ap(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return An(e,Cp(t),r)}},wp=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Oo(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Ha=(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}},Rp=({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},Cp=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Wa=(e,t,r,n)=>{for(const a of r){const i=l.extractVariableName(a.mapping[t]);if(!(i===null||i===l.CONSTANT_VARIABLES.x))return l.parseValue(e,l.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Vp=class extends l.Stage{constructor(e){super(),this.container=e}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,o={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},s={differenceArrows:Gp(o,t.differenceArrows),shapes:Op(o,t.shapes),arrows:kp(o,t.arrows),textAnnotations:Np(o,t.textAnnotations),images:Mp(o,t.images),stickers:Bp(o,t.stickers),pinnedNumbers:Fp(o,t.pinnedNumbers),comments:$p(o,t.comments)};return Dp(this.container,s),_p(this.container,s),s}},le=(e,t,r,n)=>{e.diagnostics.addWarning({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."})},Dp=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.diagnostics.addWarning({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)}},_p=(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 Pp(t))r.has(a)||e.diagnostics.addWarning({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."})},Pp=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotation-ref"&&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},Op=(e,t)=>{const r=[];for(const n of t){const a=ko(e,n.region);if(a===null){le(e.container,"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},Mp=(e,t)=>{const r=[];for(const n of t){const a=ko(e,n.region);if(a===null){le(e.container,"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},kp=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.start,"pin"),i=Jt(e,n.end,"pin");if(a===null||i===null){le(e.container,"arrow",n.id,`has ${Bo(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Np=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.at,"pin");if(a===null){le(e.container,"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},Bp=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.at,"pin");if(a===null){le(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Fp=(e,t)=>{const r=[];for(const n of t){const a=An(e,n.at,"pin");if(a===null){le(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},$p=(e,t)=>{const r=[];for(const n of t){const a=An(e,n.at,"pin");if(a===null){le(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Gp=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)le(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Yr(e,n.start,"value"),i=Yr(e,n.end,"value");if(a===null||i===null){le(e.container,"differenceArrow",n.id,`has ${Bo(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){le(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Up(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},Bo=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Up=(e,t,r,n)=>{To(r,n)||e.container.diagnostics.addWarning({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:Kr(r),actual:Kr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Hp(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const o of Object.keys(i))r.has(o)||r.set(o,[]);for(const a of e)for(const i of a.observations)for(const[o,s]of r)s.push(o===t?a.kind:i[o]??null);const n={};for(const[a,i]of r)n[a]={type:Fo(i),values:i};return new l.Dataset(n)}function Fo(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 Wp=class extends l.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(l.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:l.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){const a=l.extractConstantValue(r[n]);if(a===void 0)continue;const i=l.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Fo(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Fe=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.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)}},Kp=class extends l.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)}},zp=class extends Fe{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 l.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},Yp=class{constructor(e){this.setupStage=new Kp(e),this.transformStage=new zp(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)}},qp=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new l.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}},jp=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new l.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:Zp(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Qp(t))}},Xp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ka=l.prefixInternalVariable("flipSwap"),Zp=(e,t)=>Jp(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Jp=e=>{for(const t of e){const r=l.extractVariableName(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},Qp=e=>{let t=e.data;for(const[r,n]of Xp){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ka).renameVariable(n,r).renameVariable(Ka,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function $o(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 Go=(e,t)=>$o(t.domain!==null&&t.domain.length>0?t.domain:e),em=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=nm(t,e.scales,e.layers),a=im(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:e.scales}}transform(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new l.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=rm(r,n),i=om(t);return e.layers.map(o=>sm(t.theta==="y"?lm(o):o,a,i))}},tm=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]];function rm(e,t){return r=>vo(r,e,t)}function nm(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=am(n,e,r);return a===0?0:-Math.PI/a}function am(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const o of a.data.getValues(i))n.push(o)}return Go(n,e).length}function im(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 om(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function sm(e,t,r){let n=e.data;return n=Ke(n,l.POSITION_VARIABLES.x,t),n=Ke(n,l.POSITION_VARIABLES.xMin,t),n=Ke(n,l.POSITION_VARIABLES.xMax,t),n=Ke(n,l.POSITION_VARIABLES.y,r),n=Ke(n,l.POSITION_VARIABLES.yMin,r),n=Ke(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Ke(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 lm(e){let t=e.data;for(const[r,n]of tm){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const o=a?t.getValues(r):null,s=i?t.getValues(n):null;o&&(t=t.addVariable(n,"numeric",o)),s&&(t=t.addVariable(r,"numeric",s))}return{...e,data:t}}var cm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new qp),this.register("flip",new jp),this.register("polar",new em)}},Uo=new Set(["min","max","scalar"]),um={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function dm(e){const t=new Set;for(const r of e)r.role==="point"?t.add(r.axis):(r.role==="min"||r.role==="max")&&l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function pm(e){const t=new Set;for(const r of e)r.role==="point"&&t.add(r.axis),l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function mm(e,t,r){let n=e;for(const a of t){if(a.role!=="min"&&a.role!=="max"||!l.isDefined(a.aes))continue;const i=um[a.axis][a.role];if(n.hasVariable(i))continue;const o=l.extractVariableName(r[a.aes]);!l.isDefined(o)||!n.hasVariable(o)||(n=n.addVariable(i,"numeric",n.getValues(o,{type:"numeric"})))}return n}var hm=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:mm(n.data,r.positionRoles,a)}}},In=["x","y"],Tn=new Set(["x","y","ySecondary"]),bt=new Set(["color","size","alpha","strokeWidth","lineType"]),$e=e=>Tn.has(e),Ln=e=>bt.has(e),Ho=e=>$e(e)||Ln(e);function Te(e){return e==="secondary"?"ySecondary":"y"}function Wo(e,t){return e==="y"?Te(t):"x"}function H(e){return e==="ySecondary"?"y":e}var Le=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of bt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},dr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Le(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),fm=class{compute({data:e,mapping:t}){const r=Le(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(o=>e.getValues(o)),i=new Array(n);for(let o=0;o<n;o++)i[o]=l.getStableKey(a.map(s=>s[o]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},gm=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},ym=(e,t,r)=>{const n=Me(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Me(e,t){const r=H(t);for(const n of Ko(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var pr=(e,t)=>e===null?null:t[e]??e,vm=(e,t)=>e===null?null:t[String(e)]??null,ke=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Dr(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 Sm(i,t)?i:Dr(t)}return Dr(t)},bm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Ko(t,e).some(r=>r.position==="fill");function Ko(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Dr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Sm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},xm=[{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}],za={year:0,quarter:1,month:2,week:3,day:4,hour:5},ze=40,Am=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Em(r.unit).range(e,new Date(t.valueOf()+1),n)},Im=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>ze;case"day":return a/t>ze;case"week":return a/(7*t)>ze;case"month":return a/(30*t)>ze;case"quarter":return a/(90*t)>ze;case"year":return a/(365*t)>ze}},Tm=(e,t)=>{const r=!l.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"month_year"}:{type:"month"};case"week":return r?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return r?{type:"date"}:{type:"day_month"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Lm=(e,t)=>{const r=wm(t);return r===null?!1:za[e]>za[r]},Em=e=>{switch(e){case"hour":return st.utcHour;case"day":return st.utcDay;case"week":return st.utcMonday;case"month":case"quarter":return st.utcMonth;case"year":return st.utcYear}},wm=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}},zo={left:"right",right:"left",top:"bottom",bottom:"top"},Rm={x:!0,y:!0,ySecondary:!1},Cm=20,Ya=new Set(["top","bottom"]),Vm={type:"percentage"};function Dm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:o,geomRegistry:s}=e;if(Co(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Om(s,a,i.type,n),u=new Set(t.map(h=>h.position)),d=km(Yo(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const h of Tn){const m=r[h];if(!l.isDefined(m)||m.kind!=="position")continue;const f=_m({scaleAestheticKey:h,scale:m,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function _m(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:o,gridOverrides:s,variableLabels:c}=e,{axisConfig:u,position:d,geometry:p}=Mm(t,n,i,o),h=Me(a,t),m=bm(a,t)?Vm:ke({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:p,label:Pm(u,h,c),isVisible:u.isVisible,tickCandidates:Bm(r,m,u.ticks.mode),valueFormat:m,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Nm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Pm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Om(e,t,r,n){const a=t.flatMap(s=>{const c=e.get(s.geom).grid[r];return c?[c]:[]}),i=a.some(s=>s.hideGridX),o=a.some(s=>s.hideGridY);return{x:{gridVisible:qa(i,n.axes.x.grid.isVisible)},y:{gridVisible:qa(o,n.axes.y.grid.isVisible)}}}function qa(e,t){if(e&&t===null)return!1}function Mm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Yo(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=zo[n],i=(0,at.merge)({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function Yo(e,t){return Ya.has(e)===Ya.has(t)?e:t}function km(e,t){return t.has(e)?zo[e]:e}function Nm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Rm[r]}var Bm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=$m(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=Cm;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>tt(e,u))}))}return i}return e.spec.scaleType==="datetime"?Fm(e,t):[{ticks:e.generateTicks().map(a=>tt(e,a))}]},Fm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>tt(e,s))}];const a=new Set,i=[],o=(s,c)=>{if(s.length===0)return;const u=l.getStableKey(s);a.has(u)||(a.add(u),i.push({ticks:s.map(d=>tt(e,d)),valueFormat:c}))};for(const s of xm)Im({...s,start:r,stop:n})||Lm(s.unit,t)||o(e.generateTicks({interval:s}),Tm(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},$m=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[tt(e,r),tt(e,n)]}},tt=(e,t)=>({value:t,position:e.map(t)});function qo({scale:e,aesthetics:t,layers:r}){const n=Gm({layers:r,aesthetics:t}),a=jo({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Gm({layers:e,aesthetics:t}){const r=jo({layers:e,aesthetics:t}),n=e.find(i=>t.some(o=>l.isDefined(i.mapping[o]))),a=n?n.geom:"bar";return i=>{const o=r(i);return o?o.layer.geom:a}}function jo({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const o=t.find(c=>l.isDefined(i.mapping[c]));if(o===void 0)continue;const s=l.extractVariableName(i.mapping[o]);if(!(s===null||!i.data.hasVariable(s)))for(const c of i.data.getValues(s,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var En=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Um({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!En(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=Me(t,"color");if(Xo({colorVariableName:a,xVariableName:Me(t,"x"),mapsColorAcrossMultipleLayers:Wm(t)>1,isMergedWithAnotherAesthetic:Hm(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return qo({scale:n,aesthetics:["color"],layers:t}).map(({value:s,geom:c,owner:u})=>{const d=u?.layerIndex??o,p=t[d],h=p?l.extractVariableName(p.mapping.color):null;return{value:s,color:String(n.map(s)),geom:c,layerIndex:d,valueFormat:ke({layers:p?[p]:t,scaleType:i,variableName:h}),label:vm(s,r)}})}var Xo=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Hm(e,t,r){if(r===null)return!1;for(const n of bt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!En(a))&&Me(t,n)===r)return!0}return!1}var Wm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Zo(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Km(e,t,r,n){const a=r.findIndex(i=>Zo(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:pr(l.extractVariableName(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 ja(e,t,r){if(r===null||t===null)return[...e];const n=l.getStableKey(r);return e.filter((a,i)=>l.getStableKey(t[i]??null)===n)}var Jo=e=>e==="none"?"first":e,zm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Xa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Xa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Ym=(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}},Xa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function qm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?jm(e,n):Xm(e,n)}function jm(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(s=>s.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const o=l.extractVariableName(a.mapping.y);return o===null?null:{kind:"grandTotal",value:i,valueFormat:ke({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:o})}}function Xm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:o,geomRegistry:s}=e;if(!a.some(d=>Zo(s,d)))return null;const c=Km(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Zm({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 Zm({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const o=l.extractVariableName(i.mapping.y);if(o===null||t==="total"&&i.position==="fill")return null;const s=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=ke({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=eh(i.data,s),h=ke({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),m=th(i.data,s),f=m.getValues(o,{type:"numeric"}),g=s!==null?m.getValues(s):[],v=c!==null?m.getValues(c):null,y=ja(f,v,e.value),b=ja(g,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:zm(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,caption:Jm(t,p,b),comparison:Qm(t,r,p,b,y)}}function Jm(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 Qm(e,t,r,n,a){return e!=="current"||!r?null:Ym(n.map((i,o)=>({main:i,cross:a[o]??null})),Jo(t))}function eh(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function th(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function ae(e,...t){return e?t.includes(e.geom):!1}function B(e,t){return e.find(r=>r.id===t)}function Ee(e,...t){return e.find(r=>t.includes(r.geom))}function rh(e,...t){return e.filter(r=>t.includes(r.geom))}function wn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Rn(e){const t=e.filter(r=>!wn(r,e));return t.length>0?t:e}function Qo({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Rn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var nh=3;function ah({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:o}){if(t.legend.position==="none")return{drawn:[],position:"none"};const s=new Map(i.map(v=>[l.getStableKey(v.value),v])),c=ph(lh({scales:e,layers:r})),u=Me(r,"x"),d=c.map(v=>{if(uh(v,u,r))return null;const y=hh({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return y.items.length===0?null:{group:v,built:y}}).filter(l.isDefined),p=ih(d),h=Rn(r),m=Sh(o,t.legend.position,p,h,n);if(d.length===0)return{drawn:[],position:m};if(t.legend.position==="auto"&&bh(o,p,h,n))return{drawn:[],position:m};const f=xh(t.legend.display,{legendPosition:m,coordSystem:n,layers:r}),g=f==="direct"?Lh(h[0]):null;return{drawn:d.map(({built:v})=>oh(v,{position:m,display:f,align:t.legend.align},g)),position:m}}function ih(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function oh(e,t,r){const{position:n,display:a}=t,i=sh(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(o=>({...o,normalizedY:r.get(String(o.value))??null}))}}function sh(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function lh(e){const{scales:t,layers:r}=e,n=[];for(const a of bt){const i=t[a];if(i===void 0||i.kind==="identity"||!ch(a,r))continue;const o=Me(r,a),s=Th(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function ch(e,t){const r=H(e);return t.some(n=>l.isDefined(n.mapping[r]))}function uh(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Xo({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:dh(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function dh(e,t){const r=H(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function ph(e){const t=new Map;for(const r of e){const n=Ih(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function mh(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function hh({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>H(u.scaleAestheticKey)),o=qo({scale:a.scale,aesthetics:i,layers:r}),s=ke({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),c=r.find(u=>i.some(d=>l.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:pr(a.variableName,t),items:o.map(u=>fh(u,e,i,s,n,c))}}function fh(e,t,r,n,a,i){const o={};for(const c of t)mh(o,c.scaleAestheticKey,c.scale.map(e.value));if(o.color===void 0&&r.includes("size")&&(o.color=l.DEFAULT_GEOM_COLOR),o.lineType===void 0){const c=l.extractConstantValue(e.owner?.layer.mapping.lineType);gn(c)&&(o.lineType=c)}const s=yh(e,t,r,n,a);return{value:e.value,label:gh(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function gh(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function yh(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,o=vh(i,r);return i===void 0||o===null?n:ke({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function vh(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=l.extractVariableName(n);if(a!==null)return a}return null}function bh(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 Sh(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,o=!1,s=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(o=!0,U(u.position)&&(s=!0))}const c=r>=nh;return i&&o?"top":i?c?"right":"top":s?Ah(a)?"top":c?"right":"top":"top"}function xh(e,t){return e==="pill"?"pill":Qo(t)?"direct":"pill"}function Ah(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Ih(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Th(e,t){return En(t)?"discrete":`continuous:${e}`}function Lh(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(c=>l.isDefined(F(c))||l.isDefined(D(c)));if(!n)return;const a=re(n);if(!l.isDefined(a))return;const i=G(n),o=F(n)??D(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var Eh=class extends l.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=gm(e.originalData),r=Um({scales:e.scales,layers:e.layers,valueLabels:ym(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=qm(n),i=ah(n),o={...i,drawn:wh(a,i.drawn)};return{axes:Dm(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},wh=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],dt=(e,t,r)=>{switch(e){case"series":return Rh(t);case"x-value":return Cn(t,r)}},mr=e=>{const t=l.readMainAxisVariable(e);return t===""?null:t},Rh=e=>l.getStableKey([re(e)]),Cn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Ch={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function es(e){const t=Ch[e]??null;return t===null?null:{strategy:t,composition:ts()}}function ts(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Vh=class extends Fe{constructor(e){super(),this.container=e}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(({layerId:i})=>i===void 0||i===e.id);if(n.length===0)return e;const a=Dh({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Dh({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(I=>{const V=Ae(I.predicate,e.data);for(const O of V)a.diagnostics.addWarning({...O,message:`${O.message} Dropping this highlight.`});return V.length===0}),o=mr(e.mapping),s=vt(e,r),c=i.map(I=>({predicate:xe(I.predicate,s),scope:I.scope})),u=c.some(({scope:I})=>I==="series"),d=c.some(({scope:I})=>I==="x-value"),p=n==="overlay-anchor",h=e.data.size(),m=u?new Array(h):null,f=d?new Array(h):null,g=p?new Array(h):null,v=new Uint8Array(h),y=new Set,b=new Set;let A=!1,T=0;for(const I of e.data){let V,O;m!==null&&(V=dt("series",I,o),m[T]=V),f!==null&&(O=dt("x-value",I,o),f[T]=O),g!==null&&(g[T]=I);for(const{predicate:ie,scope:kt}of c)if(ie(I))switch(kt){case"series":V!==void 0&&y.add(V);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":v[T]=1,A=!0;break}T++}if(y.size===0&&b.size===0&&!A)return ts();const L=new Uint8Array(h),E=[];let w=0;for(let I=0;I<h;I++){const V=m?.[I],O=f?.[I],ie=V!==void 0&&y.has(V),kt=O!==void 0&&b.has(O),Ma=v[I]===1;if(n==="observation-rerender")(ie||Ma||kt)&&(L[I]=1,w++);else if(ie)L[I]=1,w++;else if(Ma||kt){const ka=g?.[I];ka!==void 0&&E.push({observation:ka,observationIndex:I})}}const C=w>0?{...e,data:e.data.filterByMask(L)}:null;return{isDimmed:(n==="observation-rerender"||y.size>0)&&C!==null,matchedLayer:C,overlayCandidates:E}}var _h=l.prefixInternalVariable("__ungrouped__");function Ph(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),o=new Map,s=i.map((c,u)=>{if(c===null)return null;const d=r[u]??_h;let p=o.get(d);return p||(p=new l.ChronologicalDateManager,o.set(d,p)),p.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",s)}return n}var Oh=()=>({defaults:[],overrides:[],warnings:[]}),Mh=class extends Fe{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,Za(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},xScaleIsDiscrete:Za(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=cr({data:t,mapping:r}).pipe(({data:s,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:s,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>({data:this.groupCompiler.compute({data:s,mapping:c}).data,mapping:c})).pipe(({data:s,mapping:c})=>({data:Ph(s),mapping:c})).pipe(({data:s,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:s,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),o=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,dataLabels:e.dataLabels,summary:{},spatialKind:o.spatialKind,identityKey:o.identityKey,tooltip:o.tooltip,supportsDirectLabels:o.legend.directLabelSupport?.[e.position]===!0,highlight:es(e.geom),styles:Oh()}}};function Za(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function rs(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function kh(e,t){return t.some(r=>U(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function qr(e,t){const r=ns(e,t),n={};for(const{layer:i,scaleConstraints:o,crossAxis:s}of r)o.zeroBaseline===!0&&(n[s]={nice:(n[s]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:Bh(r),zeroAxes:n,bandPadding:Fh(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Nh(e,t){const r=ns(e,t);for(const n of r){if(n.scaleConstraints.discreteCrossAxis!==!0)continue;const a=r.find(i=>i.scaleConstraints.zeroBaseline===!0&&i.crossAxis===n.crossAxis);if(a!==void 0)return{crossAxis:n.crossAxis,banded:Ja(n),zeroAnchored:Ja(a)}}return null}var Ja=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function ns(e,t){const r=[];return t.forEach((n,a)=>{if(!e.has(n.geom))return;const{scaleConstraints:i}=e.get(n.geom);i!==void 0&&r.push({layer:n,index:a,scaleConstraints:i,crossAxis:Te(n.yScaleType)})}),r}function Bh(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of as(r))t.add(n);return[...t]}function Fh(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of as(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function as({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var $h=new Set(["label","group"]),Gh=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},o={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(o));const s=[...this.collectUndeclaredAesthetics(o),...this.collectPanelJustifyWarnings(o)];for(const c of s)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),rs(this.container.diagnostics,t)}checkPostCompile(e){Co(e)&&this.container.diagnostics.addWarning({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."})}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:o,showDataLabels:s}=i;if(!s||o!=="panel-start"&&o!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!dr(r,t))return[];const c=o==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${o}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:o},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:o,aesthetics:s}=this.container.geomRegistry.get(r),c=[...dm(o),...s.filter(p=>p.required).map(p=>p.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const p of c)d.has(p)||l.isDefined(a[p])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${p}'`,context:{layerIndex:t,aesthetic:p}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=s,d=new Set(c);for(const[p,h]of Object.entries(a)){if(u.has(p))continue;const m=l.extractVariableName(h);m===null||m===""||d.has(m)||i.hasVariable(m)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${p}' references variable '${m}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:p,variableName:m}})}return o}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=s,u=[];for(const d of o){if(!Uo.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const p=l.extractVariableName(a[d.aes]);if(p===null||!i.hasVariable(p)||i.size()===0)continue;const h=i.getType(p);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${p}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:p,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(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,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:o}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:o}).map(s=>({...s,message:`Layer '${e}': ${s.message}`,context:{...s.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Nh(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}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{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=new Set([...pm(i),...o.map(h=>h.name)]),u=$h,d=s,p=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||p.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return p}},ye=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=xo,this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,at.merge)({},this.defaultParams,e.params)}},Vn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},Dn=(e,{coordSystem:t})=>{const r=M(e),n=D(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?Ce(r,n):{x:r,y:n}},Uh=class extends ye{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="filled-buckets",this.resolveAnchorPosition=Dn}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=Vn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Hh=.7,Wh=.1,Kh=.03,zh=.05,is=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Yh=class extends ye{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveDataLabelDefaults=t=>U(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>jr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=bo(t,r);return p===null?null:ft(p,i)}if(r.type==="polar")return qh(t);const o=U(n),s={isSolo:!o||is(t)==="solo",isNegative:o&&jh(t),purpose:a};if(r.mainAxis==="x"){const p=j(t),h=X(t),m=Qa({lowerBound:G(t),upperBound:F(t)??D(t),options:s});return p===null||h===null||m===null?null:{x:(p+h)/2,y:m}}const c=G(t),u=F(t),d=Qa({lowerBound:j(t),upperBound:X(t)??M(t),options:s});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=jr(r,n);e=Vn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const i=a/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",i),{data:e,mapping:{}}}resolveWidthParam(e,t){if(e===void 0)return;const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return r;const n=r!==null&&r>1?1:void 0;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the category band in (0, 1]."}),n}},jr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Hh,qh=e=>{const t=j(e),r=X(e),n=G(e),a=F(e);return t===null||r===null||n===null||a===null?null:Ce((t+r)/2,(n+a)/2)},jh=e=>{const t=hn(e);return l.isStrictNumericDataValue(t)&&t<0},Qa=e=>{const{lowerBound:t,upperBound:r,options:n}=e,a=n.isNegative?t:r;if(a===null)return null;if(n.purpose==="value"||n.isSolo)return a;const i=n.isNegative?r:t;return i===null?null:(i+a)/2},Xh=class extends ye{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=Dn}compile(e){return{data:Vn(e.data,e.mapping),mapping:{}}}},Zh=class extends ye{constructor(...e){super(...e),this.type="point",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"size"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.resolveAnchorPosition=Dn,this.resolveValueSource=(t,r)=>{if(r!=="label")return null;const n=l.extractVariableName(t.size);return n!==null?{variable:n}:null}}compile({data:e}){return{data:e,mapping:{}}}},Jh=class extends ye{constructor(...e){super(...e),this.type="rule",this.defaultParams={labelPosition:"start"},this.defaultInteractive=!1,this.positionRoles=[{axis:"y",role:"scalar",valueKind:"value",aes:"y"},{axis:"x",role:"scalar",valueKind:"value",aes:"x"}],this.highlightStrategy=null,this.spatialKind="noop",this.validateMapping=({mapping:t,computedVariables:r})=>{const n=r.has("x")||l.isStrictNumericDataValue(l.extractConstantValue(t.x)),a=r.has("y")||l.isStrictNumericDataValue(l.extractConstantValue(t.y));return n&&a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires exactly one of 'x' or 'y', both were provided"}]:!n&&!a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires a numeric value on 'x' or 'y'"}]:[]}}compile({data:e,mapping:t}){const r=ei(t.y,e);if(r!==null)return{data:new l.Dataset({[l.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:l.RULE_VARIABLES.y,x:void 0}};const n=ei(t.x,e);return n!==null?{data:new l.Dataset({[l.RULE_VARIABLES.x]:{type:"numeric",values:[n.value],valueFormat:n.sourceFormat}}),mapping:{x:l.RULE_VARIABLES.x,y:void 0}}:{data:new l.Dataset,mapping:{x:void 0,y:void 0}}}},ei=(e,t)=>{const r=l.extractConstantValue(e);if(l.isStrictNumericDataValue(r))return{value:r,sourceFormat:void 0};const n=l.extractVariableName(e);if(n===null||!l.isStatVariable(n)||!t.hasVariable(n))return null;const[a]=t.getValues(n);return l.isStrictNumericDataValue(a)?{value:a,sourceFormat:t.getValueFormat(n)}:null},Qh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},ef=class extends ye{constructor(...e){super(...e),this.type="tile",this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian"],this.aesthetics=[{kind:"visual",name:"color",required:!0}],this.scaleConstraints={discreteMainAxis:!0,discreteCrossAxis:!0,bandPadding:0,inferredColor:!0},this.grid={cartesian:{hideGridX:!0,hideGridY:!0}},this.legend={suppressWhenSingleItem:!1},this.dataLabels={cartesian:{showDataLabels:!0}},this.dataLabelCoordTypes=["cartesian"],this.highlightStrategy="observation-rerender",this.spatialKind="cells",this.identityKey="x-y",this.tooltip=[{aes:"color"}],this.resolveValueSource=Qh,this.resolveAnchorPosition=t=>{const r=j(t),n=X(t),a=G(t),i=F(t);return r===null||n===null||a===null||i===null?null:{x:(r+n)/2,y:(a+i)/2}}}compile({data:e}){return{data:e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",.5).addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.yMax,"numeric",.5),mapping:{}}}},tf=[new Yh,new Zh,new Xh,new Uh,new Jh,new ef],hr=class extends l.Registry{constructor(){super("geom");for(const e of tf)this.register(e.type,e)}},Ge=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},rf=class extends Ge{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.x);if(!l.isDefined(r))throw new l.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(l.extractVariableName(t.y)!==null)throw new l.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,...Le(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},nf=class extends Ge{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},af=class extends Ge{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});return{data:e.rollup({[l.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:l.STAT_VARIABLES.mean}}}},of=2,os=1440*60*1e3,sf=class extends Ge{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.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(!l.isDefined(i))throw new l.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 o=e.getType(a),s=e.getType(i);if(s!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${s}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:s}});const c=Le(e,t),u=hf(a,o,i,c,e);return c.length===0?ti({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=ff(d,c);ti({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},ti=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=lf({data:e,xVariable:t,yVariable:n,xType:r});c.length<of||(s?mf({observations:c,spec:a,output:i,groupObservation:o}):df({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},lf=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?cf(a):null,s=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!l.isDefined(d)||!l.isDefined(p)||!Number.isFinite(p))continue;const h=uf({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});h!==null&&s.push({x:h,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},cf=e=>{let t=null;for(const r of e){if(!l.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},uf=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!l.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!l.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/os+1}case"categorical":{if(!l.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 l.InternalError({message:`Unexpected xType: ${t}`})}},df=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=ss(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?pf(s,r):s;a.push({x:u,y:c,groupObservation:i})}},pf=(e,t)=>t===null?new Date(e):new Date((e-1)*os+t),mf=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const s of e)a.has(s.x)||a.set(s.x,s.originalX);const i=[...a.keys()].sort((s,c)=>s-c);if(t.method==="loess"){const s=ss(t,e),c=new Map;for(const[u,d]of s)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const o=ls(t,e);for(const s of i){const c=a.get(s),u=o.predict(s);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},ss=(e,t)=>e.method==="loess"?(0,Re.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ls(e,t),ls=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Re.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Re.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Re.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Re.regressionQuad)().x(r).y(n)(t);case"power":return(0,Re.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Re.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},hf=(e,t,r,n,a)=>{const i=[],o=[],s=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),o.push(u);for(const p of n)s[p]?.push(d[p]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:o,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:s[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},ff=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},gf=class extends Ge{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});const n=l.extractVariableName(t.x),a=[...new Set([...n===null?[]:[n],...Le(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},yf=[new nf,new rf,new sf,new af,new gf],vf=class extends l.Registry{constructor(){super("stat");for(const e of yf)this.register(e.type,e)}};function bf({geoms:e,stats:t,transforms:r}){const n=new hr,a=new vf,i=new l.TransformRegistry;for(const o of e)n.register(o.type,o);for(const o of t)a.register(o.type,o);for(const o of r)i.register(o.transformType,o);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function _n(e){if("definition"in e)return e.definition;if(us(e)||ds(e)||ps(e))return e}function cs(e){const t=[],r=[],n=[];for(const a of e){const i=_n(a);i&&(us(i)?t.push(i):ds(i)?r.push(i):ps(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[..._r("geom",t,a=>a.type),..._r("stat",r,a=>a.type),..._r("transform",n,a=>a.transformType),...Sf(t),...xf(t)]}}function Sf(e){const t=[];for(const r of e)r.spatialKind==="render-hit-test"&&(r.identityKey!=="x-group"&&r.identityKey!=="x-y"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the position-derived '${r.identityKey}' identity, which has no meaning for render-owned geometry; its hover lookup will be empty.`,context:{kind:"geom",requested:r.type},suggestion:"Declare 'identityKey' as a column the geom owns (`{ variable: '<column>' }`) or 'index', so a hit-test result resolves to an observation."}));return t}function xf(e){const t=[];for(const r of e)r.spatialKind!=="cells"||!r.supportedCoordTypes.includes("polar")||t.push({code:"SPATIAL_KIND_COORD_UNSUPPORTED",message:`The geom '${r.type}' declares polar support, but its 'cells' hit-test shape has no polar projection; its observations will not respond to hover under polar coords.`,context:{kind:"geom",requested:r.type},suggestion:"Drop 'polar' from 'supportedCoordTypes', or declare 'rects' as the spatial kind so a bandless polar layer hit-tests as an enclosure."});return t}function _r(e,t,r){const n=new Map;for(const i of t){const o=r(i),s=n.get(o);s?s.add(i):n.set(o,new Set([i]))}const a=[];for(const[i,o]of n)o.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${o.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var us=e=>e instanceof ye,ds=e=>e instanceof Ge,ps=e=>"transformType"in e&&typeof e.apply=="function",Af=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},fr=class{},If=class extends fr{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!l.extractVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),i=Tf(e)??[-.7/2,.7/2],o=r.length>1?Wh:0,s=(0,se.scaleBand)().domain(r.map(String)).range(i).paddingInner(o).paddingOuter(0),c=s.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const h=a[p];if(!l.isDefined(h))continue;const m=s(String(h));l.isDefined(m)&&(u[p]=m,d[p]=m+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Tf=e=>{const t=e.getConstant(l.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(l.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},ri=l.prefixInternalVariable("__ungrouped__"),ms=(e,t)=>{const r=l.extractVariableName(t.x),n=l.extractVariableName(t.y);if(!r||!n)return null;const a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,o=i?[ri]:a,s=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let h=0;h<d;h++){const m=l.getStableKey(s[h]??null),f=u[h],g=i?ri:f;if(!l.isDefined(g))continue;let v=p.get(m);v||(v=new Map,p.set(m,v));let y=v.get(g);y||(y=[],v.set(g,y)),y.push(h)}return{yValues:c,observationIndicesByXAndGroup:p,uniqueGroupKeys:o,observationCount:d}},hs=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const o=[];let s=-1,c=1/0,u=-1/0,d=-1,p=1/0,h=-1/0;for(const m of i.values())for(const f of m){const g=e[f],v=t[f];!l.isDefined(g)||!l.isDefined(v)||(o.push(f),(g<c||g===c&&v>u)&&(s=f,c=g,u=v),(v>h||v===h&&g<p)&&(d=f,p=g,h=v))}for(const m of o)a[m]=Lf(m===s,m===d)}return a},Lf=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Ef=class extends fr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=ms(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,d]of a){let p=0,h=0;for(const g of i){const v=d.get(g);if(v!==void 0)for(const y of v){const b=n[y];b!=null&&(b>=0?p+=b:h-=b)}}let m=0,f=0;for(const g of i){const v=d.get(g);if(v!==void 0)for(const y of v){const b=n[y];if(b===void 0)continue;if(b===null){c[y]=null,s[y]=null;continue}const A=b>=0?p:h;if(A===0){c[y]=0,s[y]=0;continue}const T=b/A;b>=0?(c[y]=m,s[y]=m+=T):(s[y]=f,c[y]=f+=T)}}}const u=hs(c,s,a,o);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},wf=class extends fr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Rf=class extends fr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=ms(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,h]of a){let m=0,f=0;for(const g of i){const v=h.get(g);if(v!==void 0)for(const y of v){const b=n[y];if(b!==void 0){if(b===null){c[y]=null,s[y]=null;continue}b>=0?(c[y]=m,s[y]=m+=b):(s[y]=f,c[y]=f+=b)}}}}const u=hs(c,s,a,o);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const p=l.extractVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",s)),{data:d,mapping:{}}}},Cf=class extends l.Registry{constructor(){super("position"),this.register("identity",new wf),this.register("stack",new Rf),this.register("fill",new Ef),this.register("dodge",new If)}},Vf=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const o of i.positionRoles){if(o.role!=="scalar"||!l.isDefined(o.aes)||Ln(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Wo(o.axis,t.yScaleType));if(!c)continue;const u=a.getValues(s,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(o.aes),"numeric",u)}return a}},Df=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},_f=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=l.isDefined(n)&&e.hasVariable(l.POSITION_VARIABLES.x)?Pf(e,r,n):Of(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Pf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=fs(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||(c.min[u]=d+(o?-h:p)*r,c.max[u]=d+(o?-p:h)*r)}return c}function Of(e,t){const r=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=fs(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function fs(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Mf=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(Te(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},kf=class{map({data:e,layer:t,getPositionScale:r}){const n=r(Te(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=l.isDefined(a)&&e.hasVariable(l.POSITION_VARIABLES.y)?Nf(e,n,a):Bf(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Nf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=gs(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||(c.min[u]=d+(o?-h:p)*r,c.max[u]=d+(o?-p:h)*r)}return c}function Bf(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=gs(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function gs(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Ff=[new Df,new Mf,new _f,new kf,new Vf];function $f(e,t){const r=e[t];return r?.kind==="position"?r:null}var Gf=class extends Fe{constructor(e,t=Ff){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=>$f(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}}},Uf=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=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:kh(this.container.geomRegistry,e.layers)},a={};for(const[i,o]of t){const s=r.get(i)??[];a[i]=this.registry.get(o.scaleType).compile(o,s,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=H(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const o=l.extractVariableName(i.mapping[a]);if(!l.isDefined(o)||!i.data.hasVariable(o)||i.data.size()===0)continue;const s=i.data.getType(o);if(n.includes(s)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${s})`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s}}),r.scaledAesthetic==="lineType"&&s!=="categorical"){const c=s==="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 ${s} variable '${o}'. ${c}`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}}rs(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,o]of Object.entries(n.mapping)){if(!l.isDefined(o))continue;const s=i==="y"?Te(n.yScaleType):i,c=a.get(i)??(Ho(s)?s:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,o,n.data,u);this.collectFromVariables(n.data,d,c,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!l.isDefined(n.aes)||Ln(n.aes)||t.set(n.aes,Wo(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const o of t)a=a.concat(e.getValues(o));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Hf=["rgb","lab","hcl","hsl"],Wf=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],ys=["RdBu","BrBG","PuOr","Spectral"],vs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Kf=new Set(ys.map(e=>e.toLowerCase()));function bs(e){const t=e.toLowerCase(),r=vs[t];return r?r.toLowerCase():t}function zf(e){return Kf.has(bs(e))}var Yf={rgb:je.interpolateRgb,lab:je.interpolateLab,hcl:je.interpolateHcl,hsl:je.interpolateHsl},qf={viridis:$.interpolateViridis,magma:$.interpolateMagma,inferno:$.interpolateInferno,plasma:$.interpolatePlasma,cividis:$.interpolateCividis,turbo:$.interpolateTurbo,blues:$.interpolateBlues,greens:$.interpolateGreens,greys:$.interpolateGreys,oranges:$.interpolateOranges,purples:$.interpolatePurples,reds:$.interpolateReds,rdbu:$.interpolateRdBu,brbg:$.interpolateBrBG,puor:$.interpolatePuOr,spectral:$.interpolateSpectral};function Pn(e){const t=Xf(e);return e.reverse?r=>t(1-r):t}function jf(e={},t=2){const r=Pn({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,reverse:e.reverse??!1});return t<2?t===1?[r(0)]:[]:Array.from({length:t},(n,a)=>r(a/(t-1)))}function Xf(e){const t=Yf[e.interpolate];if(e.range&&e.range.length>=2)return(0,je.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=qf[bs(e.scheme)];if(r)return r}return(0,je.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var St=class{createPositionScale(e,t){return{kind:"position",aesthetic:H(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:H(e.scaledAesthetic),spec:e,...t}}},Zf=class extends St{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t){if(e.scaleType!=="continuous")throw new l.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const r=$e(e.scaledAesthetic),n=e.scaledAesthetic==="color",a=this.computeDataDomain(t,e);return n?this.buildColorScale(a,e):r?this.buildPositionScale(a,e):this.buildVisualScale(a,e)}computeDataDomain(e,t){let r=1/0,n=-1/0;for(const a of e)typeof a=="number"&&(a<r&&(r=a),a>n&&(n=a));return r===1/0?[0,0]:(t.zero&&(r>0&&(r=0),n<0&&(n=0)),[r,n])}createD3Scale(e,t,r){let n=[r.domainMin??e[0],r.domainMax??e[1]];const a=r.transform==="log"&&Jf(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:H(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,se.scaleLog)():r.transform==="sqrt"?(0,se.scaleSqrt)():(0,se.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const o=r.domainMin??n[0],s=r.domainMax??n[1];return i.domain([o,s]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=Qf(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){const r=Pn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[o,s]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([o,n,s],t,r)}}return this.buildSequentialColorScale(e,t,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,se.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){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,se.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Jf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Qf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var eg=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new l.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=$e(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new l.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=tg(e)?e:[],a=(0,se.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,o]=a.domain();i!==void 0&&o!==void 0&&a.domain([r.domainMin??i,r.domainMax??o])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,o]=a.domain(),s=i&&o?r.filter(c=>c>=i&&c<=o):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?s:c&&"interval"in c?i&&o?Am(i,o,c.interval):[]:a.ticks(c?.count)})}},tg=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),rg=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new l.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=$e(e.scaledAesthetic),n=Go(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,se.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),o=i.bandwidth()/2;return this.createPositionScale(t,{map:s=>(i(String(s))??NaN)+o,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,se.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},ng=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:H(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},ag=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=$o(t),a=l.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=l.applyOverrides(a.length>0?a:[...l.DEFAULT_COLOR_PALETTE],e.overrides),o=(0,se.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},ig=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Zf(e)),this.register("discrete",new rg),this.register("datetime",new eg),this.register("identity",new ng),this.register("palette",new ag)}},Ss={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},og={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function On(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:qr(e.geomRegistry,n)}}function gr(e,t){switch(t.scaleType){case"inferred":return{...gr(e,ug(e,t)),inferredFrom:t};case"continuous":{const r=Ss[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??l.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??l.CONTINUOUS_SCALE_DEFAULTS.nice,zero:t.zero??l.CONTINUOUS_SCALE_DEFAULTS.zero,clamp:t.clamp??r!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:dg(e.container,t),interpolate:t.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??l.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??l.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??l.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??l.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??l.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return Xr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:l.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function sg(e,t){const{scales:r,layers:n,coords:a}=t,i=On(e,t),o=hg(mg(r,n),i.demands),s=new Map;for(const u of o)s.set(u.scaledAesthetic,u);const c=[...s.values()].map(u=>{const d=lg(i,u);return gr(i,d)});return a.coordType==="polar"?c.map(Mn):c}function Xr(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??l.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??l.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??r??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??cg(e.scaledAesthetic,t)}}var Mn=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function lg(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:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function cg(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function ug({data:e,layers:t,mapping:r,demands:n},a){const i=H(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?pg(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const p=a.options;return l.continuous(a.scaledAesthetic,{...p,zero:!0,...!s.nice&&{nice:!1}})}const c=l.extractVariableName(o);if(!l.isDefined(c)||!e.hasVariable(c)||e.size()===0)return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=Ss[a.scaledAesthetic];switch(og[u][d]){case"discrete":return l.discrete(a.scaledAesthetic,a.options);case"palette":return l.palette(a.scaledAesthetic);case"datetime":return l.datetime(a.scaledAesthetic,a.options);case"continuous":return l.continuous(a.scaledAesthetic,a.options);default:return l.identity(a.scaledAesthetic)}}function dg(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&zf(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function pg(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function mg(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function hg(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var fg={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},"top-left":{x:-1,y:-1},"top-right":{x:1,y:-1},"bottom-left":{x:-1,y:1},"bottom-right":{x:1,y:1}},gg=(e,t,r)=>{const n=yg(e,t),a=Sg(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Ag(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Eg(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Cg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>xg(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>Ig(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>wg(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>Tg(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Lg(e,i,r)).filter(l.isDefined)}},yg=(e,t)=>{if(t===void 0)return{};if(!vg(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))}},vg=e=>{const t=new Set;for(const r of bg(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},bg=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Sg=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},kn=(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},xg=(e,t,r,n)=>{const a=Qt(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??l.TEXT_ANNOTATION_DEFAULTS.align}},Ag=(e,t,r)=>{const n=pt(e,t.start,r),a=pt(e,t.end,r);return n===null||a===null?null:{id:t.id??W(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},pt=(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)},Qt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return kn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=pt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},Ig=(e,t,r,n)=>{const a=Qt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),at:a,sticker:t.sticker}},Tg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n}},Lg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n,content:t.content}},Eg=(e,t,r)=>t.region.anchorType==="annotation"&&!kn(e,t.region.ref,r,t.id)?null:{id:t.id??W(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Rg(t.region)},wg=(e,t,r)=>t.region.anchorType==="annotation"&&!kn(e,t.region.ref,r,t.id)?null:{id:t.id??W(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Rg=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},ni=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=fg[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Cg=(e,t,r,n)=>{const a=Qt(e,t.start,r,n,t.id),i=Qt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??W(),start:ni(a),end:ni(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},Vg={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function Dg(e){const t=(0,at.merge)({},Vg,e);return t.content=_g(t.content,e?.content),t}var _g=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Pg={xLimits:null,yLimits:null},Kt={theta:"x",startAngle:0,innerRadius:0};function Zr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,jt.default)({},Pg,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Kt.theta,startAngle:t.params?.startAngle??Kt.startAngle,innerRadius:(0,Je.default)(t.params?.innerRadius??Kt.innerRadius,0,1)}}}}function Og(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??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Mg=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"user-input"};t.persistent?this.persistent.push(r):this.diagnostics.push(r)}addError(e){this.diagnostics.push({...e,severity:"error",kind:"user-input"})}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=ai(e.filter(n=>n.severity==="error")),r=ai(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},kg=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 ai(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Ng={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:l.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4};function xs(e,t){const r=e??t,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}}return{type:n}}function Ue(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new kg(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=$g({dataLabels:Ug(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return Fg({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??W(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:xs(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:s.resolveParams({params:n.params,diagnostics:o}),transforms:n.transforms??[],interactive:n.interactive??s.defaultInteractive,dataLabels:u}}function Bg(e,t,r,n,a){const i=n.map((o,s)=>Ue(e,t,r,o,a,s));return Is(e,i)}var As=(e,t,r,n)=>n.label!==void 0?n.label:Vo({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Is=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Be(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(o=>o.axis==="y"&&o.role==="scalar"))return n;const a=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,at.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Fg=({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&&U(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'."})},$g=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:o}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const s=Gg(t,r,n);if(s===null)return e;const c=i==="panel-end"?"end":"start";return o&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${s}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Gg=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&U(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Ug=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=As(e,r.geom,n,i),s=e.get(r.geom);return{...(0,at.merge)({},Ng,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},Hg=e=>{const t=new Set;e!==void 0&&Ts(e,t,new Set);const r={tokens:{},defaults:[],overrides:[]};for(const n of t)Object.assign(r.tokens,n.tokens),r.defaults.push(...n.defaults??[]),r.overrides.push(...n.overrides??[]);return r},Ts=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Ts(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function Wg(e,t,r){const n=Zr(t.coords),a=Bg(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=sg(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=Dg(t.config),s=Og(e,t.highlights,a),c=gg(e,t.annotations,a),u=Hg(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:s,styles:u,annotations:c,coords:n,config:o}}var Ls=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return Wg(this.container,{...e,data:t},r)}},Kg=class{constructor(e){this.registry=e}compute(e,t){return this.registry.get(e.type).compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete})}},xt={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},zg={differenceArrow(e){return{type:"annotation",kind:"differenceArrow",annotation:e}},shape(e){return{type:"annotation",kind:"shape",annotation:e}},arrow(e){return{type:"annotation",kind:"arrow",annotation:e}},text(e){return{type:"annotation",kind:"text",annotation:e}},image(e){return{type:"annotation",kind:"image",annotation:e}},sticker(e){return{type:"annotation",kind:"sticker",annotation:e}},pinnedNumber(e){return{type:"annotation",kind:"pinnedNumber",annotation:e}},comment(e){return{type:"annotation",kind:"comment",annotation:e}}},Es=Object.keys(xt),Yg=e=>Object.hasOwn(xt,e),At=(e,t)=>{for(const r of Es){const n=qg(e,r,t);if(n)return n}return null},It=(e,t)=>e[xt[t]],Nn=(e,t,r)=>({...e,[xt[t]]:r}),ws=(e,t)=>{const r=It(e,t.kind);return Nn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},qg=(e,t,r)=>{const n=It(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},jg=class extends Fe{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of yy(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of by(e.styles))this.container.diagnostics.addWarning(r);for(const r of Sy(e.styles))this.container.diagnostics.addWarning(r);for(const r of t)for(const n of r.styles.warnings)this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=ks({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Ve={color:"color",alpha:"unitInterval",saturation:"unitInterval"},er={bar:{...Ve,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Ve,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Ve,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Ve,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...Ve,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},ii=1,oi=1e3,Xg="'none' or a shadow object { offsetX, offsetY, blur, color }",si="a non-negative number of pixels, or an object of those per edge",Nt={color:"color",strokeWidth:"pixels",lineType:"lineType"},z={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Bt={...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},li={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},_={panelBorder:{...Nt,borderRadius:"pixels"},panelBorderEdge:Nt,gridLine:Nt,tickLine:{...Nt,length:"pixels"},axisLabel:{...z,margin:"margin"},tickLabel:{...z,offset:"pixels",margin:"margin"},ruleLabel:z,dataLabel:Bt,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color",textScale:"multiplier",padding:"padding"},heading:z,caption:z,source:z,header:{margin:"margin"},footer:{margin:"margin"},hoverGuide:{color:"color",background:"color"},tooltip:li,tooltipText:z,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels",margin:"margin"},legend:{gap:"pixels",margin:"margin"},legendPopover:li,legendItem:{...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},legendItemSwatch:{size:"pixels",strokeWidth:"pixels"},directLabel:{...z,strokeWidth:"pixels",lineType:"lineType"},annotation:{color:"color",alpha:"unitInterval"},annotationShape:{color:"color",alpha:"unitInterval",borderColor:"color",borderWidth:"pixels"},annotationArrow:{color:"color",strokeWidth:"pixels",lineType:"lineType",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationDifferenceArrow:{color:"color",strokeWidth:"pixels"},annotationDifferenceArrowLabel:Bt,annotationText:{...Bt,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...Bt,shadow:"shadow"}},Rs={number:z,numberCenter:z,caption:z,label:z,swatch:{size:"pixels"},trend:z,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},Zg=new Set([...Object.keys(Ve),...Object.values(er).flatMap(e=>Object.keys(e??{})),...Object.values(_).flatMap(e=>Object.keys(e)),...Object.values(Rs).flatMap(e=>Object.keys(e))]),Cs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","caption","source","header","footer","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],Jg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Qg=new Set(["panelBorder","legend","axisLabel","tickLabel"]),ey=(e,t,r="en-US")=>ks({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),ty=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of vy(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Vs(e.styles)}},Vs=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},heading:{defaults:[],overrides:[]},caption:{defaults:[],overrides:[]},source:{defaults:[],overrides:[]},header:{defaults:[],overrides:[]},footer:{defaults:[],overrides:[]},hoverGuide:{defaults:[],overrides:[]},tooltip:{defaults:[],overrides:[]},headline:{defaults:[],overrides:[]},headlineItem:{defaults:[],overrides:[]},legend:{defaults:[],overrides:[]},legendItem:{defaults:[],overrides:[]},directLabel:{defaults:[],overrides:[]},annotation:{defaults:[],overrides:[]},warnings:t},a=(i,o,s,c)=>{if(yr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ny(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${Cs.map(m=>`'${m}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const p=i.select;if(p.target==="annotation"){const m=p.kind;if(m!==void 0&&!my(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown annotation kind '${String(m)}'.`,context:{param:"kind",actual:String(m),...u},suggestion:`Set 'kind' to one of ${l.ANNOTATION_STYLE_KINDS.map(y=>`'${y}'`).join(", ")}, or omit it to address every annotation.`});return}const f=p.part,g=hy(m);if(f!==void 0&&!(typeof f=="string"&&g.includes(f))){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(f)}'.`,context:{param:"part",actual:String(f),...u},suggestion:g.length>0?`Set 'part' to ${g.map(y=>`'${y}'`).join(", ")}, or omit it to address the ${m==="differenceArrow"?"line":"marker"}.`:`Remove 'part' — ${m===void 0?"kind-agnostic":`'${String(m)}'`} entries have none.`});return}const v=p.annotation;if(v!==void 0&&typeof v!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid annotation ${Se(v)}.`,context:{param:"annotation",actual:Se(v),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}if(Qg.has(p.target)){const m=p.edge;if(m!==void 0&&!ay(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown edge '${String(m)}'.`,context:{param:"edge",actual:String(m),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Jg.has(p.target)){const m=p.axis;if(m!==void 0&&!fy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown axis '${String(m)}'.`,context:{param:"axis",actual:String(m),...u},suggestion:`Set 'axis' to one of ${In.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="ruleLabel"){const m=p.layer;if(m!==void 0&&typeof m!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid layer ${Se(m)}.`,context:{param:"layer",actual:Se(m),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(p.target==="tooltip"){const m=p.part;if(m!==void 0&&!sy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(p.target==="heading"){const m=p.part;if(m!==void 0&&!cy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.HEADING_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address every heading level.`});return}}if(p.target==="source"){const m=p.part;if(m!==void 0&&!ly(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.SOURCE_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the label.`});return}}if(p.target==="legend"){const m=p.part;if(m!==void 0&&!uy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.LEGEND_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the gap.`});return}}if(p.target==="legendItem"){const m=p.part;if(m!==void 0&&!dy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.LEGEND_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the pill.`});return}}if(p.target==="headlineItem"){const m=p.part;if(!py(m)){t.push({code:"INVALID_STYLE_RULE",message:m===void 0?`Style ${s} ignored: headlineItem entries need a part.`:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.HEADLINE_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="dataLabel"){const m=p.role;if(m!==void 0&&!iy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown role '${String(m)}'.`,context:{param:"role",actual:String(m),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=p.position;if(f!==void 0){if(!oy(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(m===void 0||m==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=Fn({declarations:i.declarations,vocabulary:_s(p),tokens:r,location:s,origin:c,warnings:t,entryTarget:p.target});Object.keys(h).length!==0&&n[p.target][o].push({select:p,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,o)=>{a(i,"defaults",`builtin[${o}]`,{list:"builtin"})}),e.defaults.forEach((i,o)=>{a(i,"defaults",`defaults[${o}]`,{list:"defaults",index:o,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,o)=>{a(i,"overrides",`overrides[${o}]`,{list:"overrides",index:o,...i.id===void 0?{}:{id:i.id}})}),n},ry=(e,t)=>{if(e==="geom"){const r=Object.keys(er).find(n=>er[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>_s({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},yr=e=>e.select.target==="geom",ny=e=>{const t=e.select.target;return t!=="geom"&&Cs.includes(t)},Ds=e=>(e!==void 0?er[e]:void 0)??Ve,_s=e=>{if(e.target==="panelBorder")return e.edge===void 0?_.panelBorder:_.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?_.tooltip:e.part==="primaryRow"?_.tooltipPrimaryRow:_.tooltipText;if(e.target==="legend")return e.part==="popover"?_.legendPopover:_.legend;if(e.target==="legendItem")return e.part===void 0?_.legendItem:_.legendItemSwatch;if(e.target==="headlineItem")return Rs[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return _.annotationShape;case"arrow":return _.annotationArrow;case"differenceArrow":return e.part==="label"?_.annotationDifferenceArrowLabel:_.annotationDifferenceArrow;case"text":return _.annotationText;case"image":return _.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?_.annotationCalloutLabel:_.annotationCallout;default:return _.annotation}return _[e.target]},ay=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),iy=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),oy=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),sy=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),ly=e=>typeof e=="string"&&l.SOURCE_PARTS.includes(e),cy=e=>typeof e=="string"&&l.HEADING_PARTS.includes(e),uy=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),dy=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),py=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),my=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),hy=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],fy=e=>typeof e=="string"&&In.includes(e),gy=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!yr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=Fn({declarations:a.declarations,vocabulary:Ds(o),tokens:t,location:`builtin[${i}]`,origin:s,warnings:r,entryTarget:"geom"});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:s})}),n},Bn=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},yy=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Bn(e,(a,i,o)=>{const s=a.select;if(s.target!=="geom"&&s.target!=="ruleLabel")return;const c=s.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},vy=(e,t)=>{const r=new Map(Es.flatMap(a=>t[xt[a]].map(i=>[i.id,a]))),n=[];return Bn(e,(a,i,o)=>{const s=a.select;if(s.target!=="annotation")return;const c=s.annotation;if(c===void 0||typeof c!="string")return;const u={param:"annotation",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(c);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown annotation '${c}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets sticker '${c}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=s.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets ${d} '${c}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},by=e=>{const t=[];return Bn(e,(r,n,a)=>{if(!yr(r))return;const i=r.when?.state;i===void 0||Ps(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${l.STYLE_STATES.map(o=>`'${o}'`).join(", ")}.`})}),t},Ps=e=>l.STYLE_STATES.includes(e),Sy=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Os(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Se(n)}.`,context:{param:"tokens",actual:Se(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Os=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,pe=e=>typeof e=="number"&&Number.isFinite(e),Ms=e=>{if(pe(e)&&e>=0)return{top:e,right:e,bottom:e,left:e};if(typeof e!="object"||e===null)return;const t=e,r={};for(const n of l.PANEL_BORDER_EDGES){const a=t[n];if(a!==void 0){if(!pe(a)||a<0)return;r[n]=a}}return r},xy=e=>{const t=Ms(e);return t===void 0?void 0:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},Ay=e=>Ms(e),Se=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),ks=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=vt(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((h,m)=>{if(!yr(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!Ps(g))return;const v={list:d,index:m,...h.id===void 0?{}:{id:h.id}},y=h.when?.where;if(y!==void 0){const A=Ae(y,t.data,"style-rule");if(A.length>0){for(const T of A)o.push({...T,code:"INVALID_STYLE_RULE",message:`Style ${d}[${m}]: ${T.message}`,context:{...T.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const b=Fn({declarations:h.declarations,vocabulary:Ds(f),tokens:s,location:`${d}[${m}]`,origin:v,warnings:o,entryTarget:"geom"});Object.keys(b).length!==0&&p.push({declarations:b,...y===void 0?{}:{matches:xe(y,i)},...g===void 0?{}:{state:g},origin:v})}),p};return{defaults:[...gy(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},Fn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:o,entryTarget:s}=e,c={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(f,g)=>{c[f]=g},p=(f,g,v)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: expected ${g}, got ${Se(v)}.`,context:{param:f,expected:g,actual:Se(v),...u},suggestion:`Set '${f}' to ${g}.`})},h=(f,g)=>{if(typeof g=="string"){if(g.trim().length>0)return g;p(f,"a non-empty color string",g);return}if(l.isStyleTokenRef(g)){const v=n[g.token];if(v===void 0){o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: unknown token '${g.token}'.`,context:{param:f,actual:g.token,...u},suggestion:`Declare '${g.token}' in the stylesheet's tokens.`});return}return Os(v)?typeof v=="string"?v:{light:v.light,dark:v.dark}:void 0}if(l.isLightDarkColor(g)&&g.light.trim().length>0&&g.dark.trim().length>0)return{light:g.light,dark:g.dark};p(f,"a non-empty color string, a { light, dark } pair, or a token(...) reference",g)},m=f=>{const g=Zg.has(f),v=ry(s,f),y=v===void 0?`Declare '${f}' on a target whose vocabulary carries it.`:`Declare '${f}' on an entry whose kind supports it (e.g. ${v}).`;o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: ${g?"not in this entry's vocabulary":"not a style property"}.`,context:{param:f,...u},suggestion:g?y:`Remove the unknown declaration '${f}'.`})};for(const f of Object.keys(t)){const g=t[f];if(g===void 0)continue;const v=r[f];if(v===void 0){m(f);continue}switch(v){case"color":{const y=h(f,g);y!==void 0&&d(f,y);break}case"unitInterval":pe(g)&&g>=0&&g<=1?d(f,g):p(f,"a number in [0, 1]",g);break;case"pixels":pe(g)&&g>=0?d(f,g):p(f,"a non-negative number of pixels",g);break;case"radiusToken":l.isBorderRadiusToken(g)?d(f,g):p(f,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,g);break;case"lineType":gn(g)?d(f,g):p(f,`one of ${fn.map(y=>`'${y}'`).join(", ")}`,g);break;case"fontFamily":typeof g=="string"&&g.trim().length>0?d(f,g):p(f,"a non-empty CSS font-family list",g);break;case"fontWeight":pe(g)&&g>=ii&&g<=oi?d(f,g):p(f,`a number in [${ii}, ${oi}]`,g);break;case"multiplier":pe(g)&&g>0?d(f,g):p(f,"a positive multiple of the font size",g);break;case"shadow":{if(g==="none"){d(f,g);break}const y=g;if(!pe(y.offsetX)||!pe(y.offsetY)||!pe(y.blur)||y.blur<0){p(f,Xg,g);break}const b=h(f,y.color);b!==void 0&&d(f,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:b});break}case"padding":{const y=xy(g);y===void 0?p(f,si,g):d(f,y);break}case"margin":{const y=Ay(g);y===void 0?p(f,si,g):d(f,y);break}default:break}}return c},Iy=({layer:e})=>{if(e.position==="stack")return;const t=l.extractVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];l.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Ty=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=l.extractVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const n=s=>t==="y"?s.xMax:s.yMax,a=s=>t==="y"?s.xMin:s.yMin,i=new Map;for(const s of e.data){const c=s[r],u=G(s),d=F(s),p=j(s),h=X(s),m=hn(s);if(!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||!l.isDefined(m))continue;const f=m>=0;if(Math.abs(m)===0)continue;const g=Cn(s,r),v={xMin:p,xMax:h,yMin:u,yMax:d},y=i.get(g);if(y===void 0){i.set(g,{total:m,topPositive:f?v:null,bottomNegative:f?null:v});continue}y.total+=m,f?(y.topPositive===null||n(v)>n(y.topPositive))&&(y.topPositive=v):(y.bottomNegative===null||a(v)<a(y.bottomNegative))&&(y.bottomNegative=v)}const o=[];for(const[s,c]of i){const u=c.topPositive??c.bottomNegative;u!==null&&o.push({xKey:s,total:c.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:c.topPositive!==null?"positive":"negative"}})}return o},Ly=class extends Fe{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=t.coordSystem.type==="cartesian"?t.coordSystem.mainAxis:"x";if(r.summaries.stackTotals){const i=Ty({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=Iy({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Ns=class extends l.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)}},ci={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Ey=["color","size","alpha","strokeWidth","lineType"],wy=class extends Fe{dependencies(e){return Ey.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const o=l.extractConstantValue(e.mapping[a]);if(o!==void 0){r=r.addConstantVariable(i,ci[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,ci[a],Ry(c)))}return{...e,data:r}}},Ry=e=>t=>l.isDefined(t)?e.map(t):null;function Bs(e=new hr){return{diagnostics:new Mg,geomRegistry:e}}var Fs=class{constructor(e,t,r,n,a,i,o,s,c,u,d,p,h,m,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=o,this.coordCompiler=s,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=p,this.stylesCompiler=h,this.chromeStylesCompiler=m,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},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:"summarise",getStats:()=>this.summariseCompiler.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}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??ui})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??ui;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,R(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=On(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return R(t,{scales:Be(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=gr(r,a);return t.coords.coordType==="polar"?Mn(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,compiled: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:[Eo(e)],warnings:t.warnings}}trackCompile(e){if(!l.IS_DEV)return e();const t=this.getCacheStats(),r=performance.now(),n=e(),a=performance.now()-r,i={};for(const{name:o,getStats:s}of this.stages){const c=s();i[o]={hits:c.hits-t[o].hits,misses:c.misses-t[o].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e,colorScheme:t}){return{...cr({spec:e}).pipe(({spec:r})=>({spec:R(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:R(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.summariseCompiler.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})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,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}}},Cy=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],ui="light",Vy=({plugins:e=[]}={})=>{const t=cs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=bf(t),i=Bs(r),o=new ig(i),s=new Ns(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new Fs(i,new l.DataCompiler,new Ls(i),s,new Wp,new Gh(i,s,n,new Mh(i,s,new Kg(n),new fm,new hm(i),new Af(new Cf))),new Uf(i,o),new Yp(new cm),new Gf(i),new wy,new Eh(i),new Ly(i),new jg(i),new ty(i),new Vh(i),new Vp(i))};function $s(e,t){return e.geom===t}function Gs(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Dy(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>Hs(o,s),i)}function Us(e,...t){return t.reduce((r,n)=>Hs(r,n),e)}function Dy(e){return typeof e=="object"&&e!==null&&"type"in e}function Hs(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:(0,jt.default)({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};case"highlight":return{...e,highlights:[...e.highlights,t]};case"styles":return{...e,styles:e.styles===void 0?t:{...t,extends:[e.styles,...t.extends??[]]}};case"annotation":return _y(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function _y(e,t){const r={...e.annotations};switch(t.kind){case"differenceArrow":r.differenceArrows=[...r.differenceArrows??[],t.annotation];break;case"shape":r.shapes=[...r.shapes??[],t.annotation];break;case"arrow":r.arrows=[...r.arrows??[],t.annotation];break;case"text":r.textAnnotations=[...r.textAnnotations??[],t.annotation];break;case"image":r.images=[...r.images??[],t.annotation];break;case"sticker":r.stickers=[...r.stickers??[],t.annotation];break;case"pinnedNumber":r.pinnedNumbers=[...r.pinnedNumbers??[],t.annotation];break;case"comment":r.comments=[...r.comments??[],t.annotation];break;default:throw new Error(`Unknown annotation kind: ${t.kind}`)}return{...e,annotations:r}}function Py(e){const t=e?.plugins??[],r=My(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Gs,pipe:Us,plugins:t}}var Oy=e=>(t={})=>l.buildLayerInput(e,t);function My(e){const{geoms:t,stats:r,transforms:n}=cs(e),a={};for(const s of t)a[s.type]=Oy(s.type);const i={};for(const s of r)i[s.type]=()=>({type:s.type});const o={};for(const s of n)o[s.transformType]=c=>({type:"transform",transformType:s.transformType,options:c?.options});return{geom:a,stat:i,transform:o}}var Pr="…",Ws=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Pr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Pr)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Pr};var Y={timeZone:"UTC"},K=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},we=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",$n=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ky=Wr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ks=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>we(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Hn(a,i),{base:s,suffix:c}=Un(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),zs=({locale:e,numberFormat:t,intlOptions:r})=>we(n=>{const{base:a,suffix:i}=Un(n,t.abbreviation),o={...Hn(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),Gn=e=>we(t=>ky(t)),Ys=({locale:e,intlOptions:t})=>we(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),qs=({locale:e,numberFormat:t,intlOptions:r})=>we(n=>{const a=Hn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Un=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Ny(e);return Un(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Hn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},Ny=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},By=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).format(r)),Fy=({locale:e,intlOptions:t})=>K(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...Y,...t}).formatToParts(r);return $y(n.map(Gy))}),js=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t}).format(r)),Xs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"long",...Y,...t}).format(r)),Wn=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...Y,...t}).format(r)),Kn=e=>K(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Zs=({locale:e,intlOptions:t})=>K(r=>{const n=(0,ho.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t,year:void 0}).formatRange(r,n)}),Js=({locale:e,intlOptions:t})=>K(r=>{const n=(0,ho.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).formatRange(r,n)}),zn=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{year:"numeric",...Y,...t}).format(r)),Qs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),$y=e=>e.map(t=>t.value).join(""),Gy=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},di=1e3,Uy=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>we(a=>{const i={...qn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Yn(a,t,i)}),Hy=({locale:e,tickValues:t,intlOptions:r})=>we(n=>{const a={...qn(n,t),notation:"compact",...r};return Yn(n,e,a)}),Wy=({locale:e,tickValues:t,intlOptions:r})=>we(n=>{const a={...qn(n,t),notation:"compact",...r,style:"percent"};return Yn(n,e,a)}),Yn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),el=e=>Math.abs(e)>di?el(e/di):Number.isInteger(e),Ky=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},qn=(e,t)=>el(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Ky(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},zy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Yy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",...Y,...t}).format(r)),qy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),jy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),jn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Uy(e);case"date":case"datetime":return zy(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return qy(e);case"decimal":case"integer":return Hy(e);case"duration":return Gn(e);case"month":return Yy(e);case"month_year":return Wn(e);case"percentage":return Wy(e);case"quarter":return Kn(e);case"text":return $n(e);case"time":return jy(e);case"year":return zn(e);case"lookup":return jn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Xy=.9,Zy=1/3,Jy=1/4,Qy=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?ev(e):tv(e),ev=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=tl(e.ticks,n),s=rv(e.ticks,r.width),c=s*Xy;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Qr(c);return{...e,ticks:Jr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Qr(r.height*Zy);return{...e,ticks:Jr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},tv=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=tl(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Qr(r.width*Jy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Jr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},rv=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},tl=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},Jr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Ws(i.formattedLabel,r,a)})},Qr=e=>Math.max(0,Math.floor(e)),nv=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let o=r-(e.length-1)*i;for(const s of e){const{width:c,height:u}=n(s);if(o-=a?c:u,o<0)return!1}return!0},av=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const h=o.get(p);if(h)return h;const m=a[p],f=m?iv(m.ticks,n(m)):[];return o.set(p,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1;nv(s(p).map(h=>h.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},iv=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),pi=.5,Tt=e=>({x:0,y:0,width:e.width,height:e.height}),Xn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,Lt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:o,alignOffset:s,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",p=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:sv(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},m={anchor:lv(i),placement:p?n:"inside",offset:p?s??o:0},f=d?t:e,g=r.valueAxis==="x"?f:e,v=r.valueAxis==="y"?f:e,y=r.valueAxis==="x"?h:m,b=r.valueAxis==="x"?m:h,A=hi(y,{min:g.x,max:g.x+g.width,halfExtent:c/2}),T=hi(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:A,y:T,position:ov(e,A,T,c,u)}},mi=(e,t,r,n)=>r-n>=e-pi&&r+n<=t+pi,ov=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||mi(e.x,e.x+e.width,t,n/2),o=e.height===0||mi(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},sv=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",lv=e=>e==="center"?"center":e==="start"?"min":"max",hi=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const o=r+i;return e==="min"?t==="inside"?n+o:n-o:t==="inside"?a-o:a+o},cv=(e,t,r,n,a)=>{const i=t??e,o=1-Math.max(e,i);return{box:{x:r*n,y:o*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},uv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=pv(e.layer);for(const a of e.layer.data){const i=M(a),o=F(a)??D(a);if(i===null||o===null||!et(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),{box:d,frame:p}=cv(o,G(a),i,e.panelRect.width,e.panelRect.height),h=Lt({box:d,panel:Tt(e.panelRect),frame:p,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return{labels:t,droppedCount:0}},dv={place:uv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":U(e.position)?"stack":"none"},pv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:dr(e.data,e.mapping)?Xn(r):r,align:n}};function Et(e){return e[l.VISUAL_VARIABLES.color]}function rl(e){return e[l.VISUAL_VARIABLES.alpha]}function Zn(e){return e[l.VISUAL_VARIABLES.size]}function en(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function nl(e){return e[l.VISUAL_VARIABLES.lineType]}var mv={color:Et,alpha:rl,strokeWidth:en,lineType:nl,size:Zn,borderWidth:en},ot=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:s=>{const c=r.get(s);if(c!==void 0)return c;const u=fv(s.styles,t);return r.set(s,u),u},chromeReaders:s=>{const c=n.get(s);if(c!==void 0)return c;const u=hv(s,t);return n.set(s,u),u},explain:(s,c,u,d)=>{if(d!==void 0){const f=ct(s.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=ct(s.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const p=ct(s.styles.overrides,c,u,void 0,t);if(p!==void 0)return{value:p.value,tier:"override",origin:p.origin};const h=al(c,u);if(h!==void 0)return{value:h,tier:"data"};const m=ct(s.styles.defaults,c,u,void 0,t);return m!==void 0?{value:m.value,tier:"default",origin:m.origin}:{value:void 0,tier:"unresolved"}}}},hv=(e,t)=>{const r=(v,y)=>{const b=w=>fi(v.overrides,w,y)??fi(v.defaults,w,y);return{get:w=>{const C=b(w)?.declarations[w];if(C!==void 0)return Or(C,t)},getSource:w=>{const C=b(w);return C===void 0?"unresolved":C.origin.list==="builtin"?"builtin":"authored"},explain:w=>{const C=b(w),I=C?.declarations[w];return C===void 0||I===void 0?{value:void 0,source:"unresolved"}:{value:Or(I,t),source:C.origin.list==="builtin"?"builtin":"authored",origin:C.origin,select:C.select}},collectAll:w=>{const C=[];for(const I of[v.defaults,v.overrides])for(const V of I){if(!y(V))continue;const O=V.declarations[w];O!==void 0&&C.push(Or(O,t))}return C}}},n=(v,y)=>{const b="edge"in v.select?v.select.edge:void 0;return b===void 0||b===y},a=v=>r(e.panelBorder,y=>n(y,v)),i=v=>r(e.legend,y=>y.select.target!=="legend"||y.select.part!==void 0?!1:n(y,v)),o=v=>(y,b)=>r(e[v],A=>A.select.target!==v||A.select.axis!==void 0&&A.select.axis!==y?!1:n(A,b)),s=v=>r(e.ruleLabel,y=>y.select.target!=="ruleLabel"?!1:y.select.layer===void 0||y.select.layer===v),c=(v,y)=>r(e.dataLabel,b=>b.select.target!=="dataLabel"||b.select.role!==void 0&&b.select.role!==v?!1:b.select.position===void 0||b.select.position===y),u=v=>r(e.tooltip,y=>y.select.target==="tooltip"&&y.select.part===v),d=v=>r(e.source,y=>y.select.target==="source"&&y.select.part===v),p=v=>r(e.heading,y=>y.select.target!=="heading"?!1:y.select.part===void 0||y.select.part===v),h=v=>r(e.legend,y=>y.select.target==="legend"&&y.select.part===v),m=v=>r(e.legendItem,y=>y.select.target==="legendItem"&&y.select.part===v),f=v=>r(e.headlineItem,y=>y.select.target==="headlineItem"&&y.select.part===v),g=(v,y)=>{const b=new Map;return A=>{const T=b.get(A);if(T!==void 0)return T;const L=r(e.annotation,E=>{if(E.select.target!=="annotation")return!1;const w=E.select.kind;return w!==void 0&&w!==v||E.select.part!==y?!1:E.select.annotation===void 0||E.select.annotation===A});return b.set(A,L),L}};return{panelBorder:a,gridLine:o("gridLine"),tickLine:o("tickLine"),axisLabel:o("axisLabel"),tickLabel:o("tickLabel"),ruleLabel:s,dataLabel:c,graph:r(e.graph,()=>!0),heading:{h1:p("h1"),h2:p("h2")},caption:r(e.caption,()=>!0),source:{label:d(void 0),link:d("link")},header:r(e.header,()=>!0),footer:r(e.footer,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:u(void 0),heading:u("heading"),label:u("label"),value:u("value"),primaryRow:u("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:f("number"),numberCenter:f("numberCenter"),caption:f("caption"),label:f("label"),swatch:f("swatch"),trend:f("trend"),trendUp:f("trendUp"),trendDown:f("trendDown"),trendFlat:f("trendFlat")},legend:Object.assign(i,{popover:h("popover")}),legendItem:{item:m(void 0),swatch:m("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:g("shape"),arrow:g("arrow"),differenceArrow:Object.assign(g("differenceArrow"),{label:g("differenceArrow","label")}),text:g("text"),image:g("image"),pinnedNumber:Object.assign(g("pinnedNumber"),{label:g("pinnedNumber","label")}),comment:Object.assign(g("comment"),{label:g("comment","label")})}}},fi=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const a=e[n];if(!(a===void 0||!r(a))&&a.declarations[t]!==void 0)return a}},Or=(e,t)=>{if(l.isLightDarkColor(e))return e[t];if(typeof e=="object"&&"offsetX"in e){const{offsetX:r,offsetY:n,blur:a,color:i}=e;return{offsetX:r,offsetY:n,blur:a,color:l.isLightDarkColor(i)?i[t]:i}}return e},fv=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=Ft(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=Ft(e.defaults,n,a,i,t);if(u!==void 0)return u}const o=Ft(e.overrides,n,a,void 0,t);if(o!==void 0)return o;const s=al(n,a);return s!==void 0?s:Ft(e.defaults,n,a,void 0,t)}}),Ft=(e,t,r,n,a)=>ct(e,t,r,n,a)?.value,ct=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const o=e[i];if(o===void 0||o.state!==n)continue;const s=o.declarations[t];if(s!==void 0&&gv(o,r))return{value:yv(s,a),origin:o.origin}}},gv=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),yv=(e,t)=>l.isLightDarkColor(e)?e[t]:e,al=(e,t)=>{const r=mv[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Jn=(e,t,r)=>{const n={},a=i=>{const o=n[i];if(o!==void 0)return o;const{width:s,height:c}=e(t,i,r),u={width:s,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},$t=6,vv=.5,bv=e=>{const t=[];let r=0;const n=U(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=xv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:a});for(const s of i){const c=e.layer.dataLabels.position==="auto"?Tv({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Ev(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,Tt(e.panelRect));if(c===null){r+=1;continue}const u=s.boxes[c.position];t.push({layerId:e.layer.id,x:c.x,y:c.y,text:s.text,width:u.width,height:u.height,isRotated:c.isRotated,target:"observation",position:c.position,...c.position==="inside"?{backdropColor:s.backdropColor}:{}})}}if(e.layer.dataLabels.showCategoryLabels)for(const i of wv(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=Dv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of i)t.push(o)}return{labels:t,droppedCount:r}},Sv={place:bv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":U(e.position)?"stack":"absoluteGrandTotal"},xv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const o=[];let s=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y),d=ot().geomReaders(e);for(const p of e.data){const h=ol(t,p);if(h===null)continue;const m=a(p);if(m==="")continue;const f=Jn(n,"observation",m),g=Qn(h,r);c&&f.inside.width>g.width&&(s=!0);const v=u===null?null:p[u],y=l.isStrictNumericDataValue(v)&&v<0;o.push({isNegative:y,text:m,boxes:f,bounds:g,backdropColor:d.get("color",p)})}return{entries:o,shouldRotate:!i&&s}},Qn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),il=(e,t,r,n,a)=>{if(e==="x"){let s=1-a,c=a-n;return c<0&&(s+=c,c=-c),{x:t,y:s,width:r-t,height:c}}let i=t,o=r-t;return o<0&&(i+=o,o=-o),{x:i,y:1-a,width:o,height:a-n}},ol=(e,t)=>{const r=j(t),n=X(t),a=G(t),i=F(t)??D(t);return r===null||n===null||a===null||i===null?null:il(e,r,n,a,i)},Av=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return il(e,r,n,a,i)},Iv=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",tn=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Tv=e=>e.isStacked?Rv({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Vv({edge:Iv(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),sl=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Lv=e=>e==="panel-start"||e==="panel-end",Ev=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,o=n.boxes[i],s=Lt({box:n.bounds,panel:a,frame:sl(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!Lv(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+vv?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},wv=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:o}=e.layer.dataLabels,s=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=Tt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const h=ol(c,p);if(h===null)continue;const m=e.formatCategory(p);if(m===null||m==="")continue;const f=Jn(e.measureDataLabel,"category",m),g=f[s],v=Qn(h,e.panelRect),y=d===null?null:p[d],b=l.isStrictNumericDataValue(y)&&y<0,A=Lt({box:v,panel:u,frame:sl(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:g.width,labelHeight:g.height}),T=f[A.position];r.push({layerId:e.layer.id,x:A.x,y:A.y,text:m,width:T.width,height:T.height,isRotated:!1,target:"category",position:A.position})}return r},Rv=({bounds:e,box:t,isRotated:r})=>{const n=tn(t.width,t.height,r);return n.width>e.width||n.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},Cv=(e,t,r,n)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:n};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:n};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:r};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:r}}},Vv=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:o})=>{const s=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=s?t.height:t.width,p=s?t.width:t.height,{edgeCoord:h,outwardSign:m,panelExtent:f}=Cv(e,t,a,i),g=tn(r.inside.width,r.inside.height,n),v=s?g.height:g.width,y=s?g.width:g.height,b=v+o<d,A=y<=p;if(s?b:b&&A){if(s&&!A)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const w=h-m*(v/2+o);return{...s?{x:c,y:w}:{x:w,y:u},isRotated:!1,position:"inside"}}const T=tn(r.outside.width,r.outside.height,n),L=(s?T.height:T.width)/2,E=h+m*(L+o);return E-L<0||E+L>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Dv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],o=e.summary.stackTotals;if(o===void 0||o.length===0)return i;const s=t==="y";for(const c of o){const u=Qn(Av(t,c),r),d=a(c.total),{width:p,height:h}=n("aggregate","outside",d),m=c.anchor.direction==="positive";let f,g;s?(f=m?u.x+u.width+$t+p/2:u.x-$t-p/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=m?u.y-$t-h/2:u.y+u.height+$t+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:p,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},_v=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Ov(e.layer);for(const a of e.layer.data){const i=M(a),o=D(a);if(i===null||o===null||!et(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=Lt({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:Tt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return{labels:t,droppedCount:0}},Pv={place:_v,getPercentageValueStrategy:()=>"none"},Ov=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:dr(e.data,e.mapping)?Xn(r):r,align:n}},Mv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Nv(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=ot().geomReaders(e.layer);for(const o of e.layer.data){const s=M(o),c=D(o);if(s===null||c===null||!et(s,c))continue;const u=e.formatLabel(o);if(u==="")continue;const{width:d,height:p}=e.measureDataLabel("observation","outside",u),h=i.get("size",o)/2,m=Lt({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:Tt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:p});t.push({layerId:e.layer.id,x:m.x,y:m.y,text:u,width:d,height:p,isRotated:!1,target:"observation",position:m.position})}return{labels:t,droppedCount:0}},kv={place:Mv,getPercentageValueStrategy:()=>"none"},Nv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:r,align:n}},ll=e=>{const t=j(e),r=X(e),n=G(e),a=F(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),o=Math.abs(r-t),s=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-s,width:o,height:c}},cl=e=>{const t=ll(e);if(!t)return null;const r=t.width*Kh,n=t.height*zh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},gi=4,Bv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=ot().geomReaders(e.layer);for(const n of e.layer.data){const a=cl(n);if(a===null||!Et(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:o,height:s}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;o+gi>c||s+gi>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:o,height:s,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return{labels:t,droppedCount:0}},Fv={place:Bv,getPercentageValueStrategy:()=>"none"};function ea(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function ta(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var $v=" · ",Mr=2,mt=(e,t,r,n)=>{const a=Math.abs(e==="radial"?Math.sin(t):Math.cos(t)),i=Math.abs(e==="radial"?Math.cos(t):Math.sin(t));return a*(r/2)+i*(n/2)},Gv=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=mt("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Mr&&t+i<=e.outerRadiusPx+Mr)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=mt("tangential",r,n,a)/t,c=Mr/t;return Math.abs(r-e.midAngle)+s<=o+c},Uv=({x:e,y:t,labelWidth:r,labelHeight:n,panelRect:a})=>e-r/2>=0&&e+r/2<=a.width&&t-n/2>=0&&t+n/2<=a.height,yi=({wedge:e,position:t,offset:r,labelWidth:n,labelHeight:a})=>t==="inside"?{labelRadius:(e.innerRadiusPx+e.outerRadiusPx)/2,labelAngle:e.midAngle,position:"inside"}:{labelRadius:e.outerRadiusPx+r+mt("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},Hv=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:o})=>{const s=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+mt("radial",s,i,o);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const p=e.innerRadiusPx-c;u=p>=0?p:e.innerRadiusPx+c}let d=s;if(n!=="center"&&u>0){const p=mt("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:Gv({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},Wv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{position:r,justify:n,align:a,offset:i,showCategoryLabels:o}=e.layer.dataLabels,s=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2,p=ot().geomReaders(e.layer);for(const h of e.layer.data){const{startAngle:m,endAngle:f}=ea(h),{innerRadius:g,outerRadius:v}=ta(h);if(m===null||f===null||v===null)continue;const y=e.formatLabel(h);if(y==="")continue;const b=o?e.formatCategory(h):null,A=b===null?y:`${b}${$v}${y}`,T={startAngle:m,endAngle:f,midAngle:(m+f)/2,innerRadiusPx:(g??0)*d,outerRadiusPx:v*d};let L,E;if(r==="auto"){const I=e.measureDataLabel("observation",s,A);E={width:I.width,height:I.height},L=yi({wedge:T,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const V=c+Math.sin(L.labelAngle)*L.labelRadius,O=u-Math.cos(L.labelAngle)*L.labelRadius;if(L.position==="outside"&&!Uv({x:V,y:O,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const ie=e.measureDataLabel("observation","inside",A);E={width:ie.width,height:ie.height},L=yi({wedge:T,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const I=Jn(e.measureDataLabel,"observation",A),V=I[r];L=Hv({wedge:T,placement:r,justify:Xn(n),align:a,offset:i,labelWidth:V.width,labelHeight:V.height}),E=I[L.position]}const w=c+Math.sin(L.labelAngle)*L.labelRadius,C=u-Math.cos(L.labelAngle)*L.labelRadius;t.push({layerId:e.layer.id,x:w,y:C,text:A,width:E.width,height:E.height,isRotated:!1,target:"observation",position:L.position,...L.position==="inside"?{backdropColor:p.get("color",h)}:{}})}return{labels:t,droppedCount:0}},Kv={place:Wv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},zv=e=>{const t=k({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=k({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},k=e=>{switch(e.valueFormat.type){case"currency":return Ks(e);case"date":return By(e);case"datetime":return Fy(e);case"day_month":return js(e);case"decimal":return zs(e);case"duration":return Gn(e);case"integer":return Ys(e);case"month":return Xs(e);case"month_year":return Wn(e);case"percentage":return qs(e);case"quarter":return Kn(e);case"text":return $n(e);case"weekly_date_range":return Zs(e);case"weekly_date_range_with_year":return Js(e);case"year":return zn(e);case"time":return Qs(e);case"lookup":return zv({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function ra({layer:e,numberFormat:t,locale:r}){return k({valueFormat:fp(e),locale:r,numberFormat:t})}var Yv=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:it(e,t),variable:r}:{read:re,variable:l.GROUP_VARIABLES.group}},ul=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=ra({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Jv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:qv({layer:e,numberFormat:n,locale:o})}},qv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Yv(e.data,e.mapping),i=k({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},jv=(e,t,r)=>{switch(t){case"stack":return Xv(e);case"fill":return Zv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Xv=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(Cn(a,t));return s===void 0?null:s.total}},Zv=(e,t)=>{const r=t?j:G,n=t?X:F,a=gt(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Jv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=Q(e.data,e.dataLabels.labelSource),c=jv(e,i,o),u=Qv({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=k({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&dl(e);return h=>{const m=s(h);if(m===null)return"";if(!p||!l.isStrictNumericDataValue(m))return u(m,h);const f=c(h);return f===null||f===0?u(m,h):d(m/f)}},Qv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(dl(e))return a;const s=eb(e,r,t,n,o);if(s!==null)return s}return k({valueFormat:tb(e.data,i),locale:n,numberFormat:t})},dl=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(lr(e.position,e.mapping))},eb=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:k({valueFormat:o.valueFormat,locale:n,numberFormat:r})},tb=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},na={bar:{cartesian:Sv,polar:Kv},line:{cartesian:Pv},point:{cartesian:kv},area:{cartesian:dv},tile:{cartesian:Fv}},rb=(e,t)=>na[e]?.[t]!==void 0,nb=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:o,formattingLocale:s,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],p=s??a,h=t.type;let m=0;for(const f of e){if(!f.dataLabels.showDataLabels&&!f.dataLabels.showStackTotals&&!f.dataLabels.showCategoryLabels)continue;const g=f.geom,v=na[g]?.[h];if(v===void 0)continue;const y=ul({layer:f,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:o,formattingLocale:p,percentageValueStrategy:v.getPercentageValueStrategy(f)}),b=v.place(y);m+=b.droppedCount;for(const A of b.labels)ib(A,h,c,u)||d.push(A)}return{labels:d,warnings:m>0?[ab(m)]:[]}},ab=e=>({code:"DATA_LABELS_DROPPED",severity:"warning",kind:"user-input",message:e===1?"Dropped 1 data label that did not fit under position 'auto'.":`Dropped ${e} data labels that did not fit under position 'auto'.`,suggestion:"Set dataLabels.position to 'outside' to keep labels that do not fit inside the bars.",context:{actual:e}}),ib=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*ob({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:o}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const s of e){if(!s.dataLabels.showDataLabels&&!s.dataLabels.showStackTotals)continue;const c=na[s.geom]?.cartesian;if(c===void 0)continue;const u=ul({layer:s,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:c.getPercentageValueStrategy(s)});for(const d of c.place(u).labels)yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var kr={abbreviation:"none",decimals:"auto"},pl=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return k({valueFormat:a,locale:e,numberFormat:kr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/r;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":k({valueFormat:{type:"percentage"},locale:e,numberFormat:kr,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${k({valueFormat:{type:"decimal"},locale:e,numberFormat:kr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},sb=2,lb=6,cb=6,ub=15,db=15,pb=2.5,mb=.5,hb=.25,ml=e=>{const t=e-sb,r=1+mb*t,n=1+hb*t;return{arrowStartGap:lb*r,arrowEndGap:cb*r,offsetFromHigherObservation:ub*n,arrowheadSize:pb*e,curveRadius:db*n,strokeWidth:e}},fb=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},gb=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Hd=Object.create,ho=Object.defineProperty,Wd=Object.getOwnPropertyDescriptor,Kd=Object.getOwnPropertyNames,zd=Object.getPrototypeOf,Yd=Object.prototype.hasOwnProperty,qd=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Kd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!Yd.call(e,s)&&s!==r&&ho(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=Wd(t,s))||n.enumerable});return e},or=(e,t,r)=>(r=e!=null?Hd(zd(e)):{},qd(t||!e||!e.__esModule?ho(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-p7nmFVnK.cjs");let Se=require("color2k"),fo=require("date-fns"),it=require("lodash-es"),lt=require("d3-time"),jd=require("date-fns/differenceInDays"),Re=require("d3-regression"),se=require("d3-scale"),je=require("d3-interpolate"),$=require("d3-scale-chromatic"),Je=require("lodash-es/clamp");Je=or(Je,1);let jt=require("lodash-es/merge");jt=or(jt,1);let Wr=require("humanize-duration");Wr=or(Wr,1);let Pe=require("d3-shape"),Xd=require("d3-delaunay"),Xt=require("lodash-es/isEqual");Xt=or(Xt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789467548664");var Zd=1e6;function te(e){return String(Math.round(e*Zd))}var Ba="#FFFFFF",Vr="#1A1A1A",Jd=4.5,go=e=>{try{return(0,Se.getContrast)(e,Ba)>(0,Se.getContrast)(e,Vr)?Ba:Vr}catch{return Vr}},Qd=(e,t)=>{try{const r=yo(void 0,t);return r===void 0||(0,Se.getContrast)(r,e)>=Jd?e:go(r)}catch{return e}},yo=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,Se.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,Se.parseToRgba)(e);return r>=1?e:(0,Se.parseToRgba)(t)[3]<1?void 0:(0,Se.mix)(t,(0,Se.opacify)(e,1),r)}catch{return}},Fa=0;function W(){return Fa+=1,`${Math.random().toString(36).slice(2,6)}${Fa.toString(36)}`}var fe=Math.PI*2,ep=8,tp=1e-9,rp=[0,Math.PI/2,Math.PI,fe*3/4],vo=(e,t)=>Math.abs(t-e)>=fe-tp,Oe=e=>(e%fe+fe)%fe,Zt=(e,t,r)=>{if(vo(t,r))return!0;const n=Oe(r-t);return Oe(e-t)<=n},Qe=(e,t)=>{const r=Math.abs(Oe(e)-Oe(t));return Math.min(r,fe-r)},$a=(e,t)=>{const r=Oe(t-e);return r>Math.PI?r-fe:r},bo=(e,t,r)=>e*fe+t+r,ge=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Ce=(e,t)=>{const r=ge(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},np=(e,t,r,n)=>{const a=[Ce(e,r),Ce(e,n),Ce(t,r),Ce(t,n)],i=Math.max(r,n),o=rp.filter(c=>Zt(c,e,t)).map(c=>Ce(c,i)),s=[...a,...o];return{xMin:Math.min(...s.map(c=>c.x)),xMax:Math.max(...s.map(c=>c.x)),yMin:Math.min(...s.map(c=>c.y)),yMax:Math.max(...s.map(c=>c.y))}},sr=(e,t)=>({angle:Oe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),lr=(e,t)=>{const r=e.x-.5,n=e.y-.5;return{x:t>=1?r*2*t:r*2,y:t>=1?n*2:n*2/t}},mn=(e,t)=>{const{x:r,y:n}=lr(e,t);return sr(r,n)};function M(e){return e[l.POSITION_VARIABLES.x]}function D(e){return e[l.POSITION_VARIABLES.y]}function j(e){return e[l.POSITION_VARIABLES.xMin]}function X(e){return e[l.POSITION_VARIABLES.xMax]}function G(e){return e[l.POSITION_VARIABLES.yMin]}function F(e){return e[l.POSITION_VARIABLES.yMax]}function hn(e){return e[l.POSITION_VARIABLES.yRaw]}function ap(e,t){return e[l.resolveScaledAestheticVariable(t)]}var ip={xMin:0,xMax:1,yMin:0,yMax:1},So=(e,t)=>{const r=j(e)??M(e),n=X(e)??M(e),a=G(e)??D(e),i=F(e)??D(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a)||!l.isStrictNumericDataValue(i)?null:t.type!=="polar"?{xMin:r,xMax:n,yMin:a,yMax:i}:{...np(r,n,a,i),frame:"disk"}},ft=(e,t)=>{const r=(e.xMin+e.xMax)/2,n=(e.yMin+e.yMax)/2;switch(t){case"top":return{x:r,y:e.yMax};case"bottom":return{x:r,y:e.yMin};case"left":return{x:e.xMin,y:n};case"right":return{x:e.xMax,y:n};case"top-left":return{x:e.xMin,y:e.yMax};case"top-right":return{x:e.xMax,y:e.yMax};case"bottom-left":return{x:e.xMin,y:e.yMin};case"bottom-right":return{x:e.xMax,y:e.yMin};default:return{x:r,y:n}}},xo=e=>ft(ip,e),Ao=["stack","dodge","identity","fill"],fn=["solid","dashed","dotted"],gn=e=>fn.includes(e);function U(e){return e==="stack"||e==="fill"}var Q=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},ot=(e,t)=>Q(e,t.x),yn=(e,t)=>Q(e,t.y),op=(e,t)=>Q(e,t.label),Io=(e,t)=>Q(e,t.color),sp=(e,t)=>Q(e,t.size),lp=(e,t)=>Q(e,t.alpha),cp=(e,t)=>Q(e,t.group),up=(e,t)=>Q(e,t.strokeWidth),Ga={variable:l.POSITION_VARIABLES.yRaw};function cr(e,t){return U(e)?Ga:t.y??Ga}function gt(e){return Q(e.data,cr(e.position,e.mapping))}var Ne=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},vn=e=>dp(e)?l.extractVariableName(e.mapping.y):null,To=e=>vn(e)===null?null:gt(e),bn=e=>e.spatialKind!=="cells",dp=e=>e.spatialKind==="points"||e.spatialKind==="cells",Lo=(e,t)=>e.yScaleType===t.yScaleType&&zr(e.valueFormat)===zr(t.valueFormat),Kr=e=>`${e.yScaleType} y axis, ${zr(e.valueFormat)}`,zr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Eo=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(Ne(e))),n=vn(e);return a=>({...a,anchorValue:l.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:l.parseAddressingValue(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:l.parseAddressingValue(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function wo(e){return e instanceof l.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 P(e,t){return Co(e,t)}function R(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 Ro(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Be(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 Co(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const o=e[a];if(l.isPlainObject(i)&&l.isPlainObject(o)){const s=Co(o,i);s!==o&&(n[a]=s,r=!0)}else i!==void 0&&i!==o&&(n[a]=i,r=!0)}return r?n:e}function ur(e){return{pipe:t=>{const r=t(e);return ur({...e,...r})},result:()=>e}}var pp=(e,t)=>{if(!l.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[l.getStableKey(r)]??e.fallback},Sn=e=>e.type==="polar"?"disk":"panel",dr=(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}},Ua=(e,t)=>{if(e.frame!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=dr(e.frame,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 Z(e,t){return e==="x"?t.x:t.y}function ye(e,t){return e==="x"?t.y:t.x}function et(e,t){return{main:Z(e,t),cross:ye(e,t)}}function Ha(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function mp(e){return e.type==="cartesian"}var re=e=>e[l.GROUP_VARIABLES.group],yt=e=>{const t=Ne(e),r=To(e),n=bn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const o=r===null?null:r(a);if(r!==null&&o===null)return null;const s=n?re(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},tt=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,hp={type:"decimal"};function Vo(e){return e.length>0&&e.every(t=>t.data.size()===0)}function xn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):hp}function fp(e){return xn(e,l.extractVariableName(e.mapping.y))}function Do({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??cr(t,r)}function _o(e,t){const r=Do({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:Q(e.data,r),valueFormat:xn(e,a)}}var Po=e=>{const t=Ne(e),r=To(e),n=bn(e);return(a,i)=>!l.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||l.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:l.areDataValuesEqual(re(a),i.groupValue)},Oo=e=>{const t=l.extractVariableName(e.mapping.y),r=gt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},gp=["lt","lte","gt","gte","range"],yp={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"}},he=()=>!1,He=()=>!0;function vt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Oo(e),parsingLocale:t}}function Ae(e,t){if("and"in e){const r=e.and.map(n=>Ae(n,t)).filter(n=>n!==He);return r.includes(he)?he:r.length===0?He:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>Ae(n,t)).filter(n=>n!==he);return r.includes(He)?He:r.length===0?he:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=Ae(e.not,t);return r===he?He:r===He?he:n=>!r(n)}return bp(e,t)}function Ie(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Ie(n,t,r)):"or"in e?e.or.flatMap(n=>Ie(n,t,r)):"not"in e?Ie(e.not,t,r):vp(e,t,r)}function vp(e,t,r){const{subject:n,effect:a}=yp[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=Sp(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 bp(e,t){if(!t.hasVariable(e.variable))return he;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>l.parseAddressingValue(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);return i=>{const o=t.readValue(i,e.variable);for(const s of a)if(l.areDataValuesEqual(o,s))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>We(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=We(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>We(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=We(t.readValue(i,e.variable),a);return o==="greater"||o==="equal"}}if("range"in e){const[a,i]=e.range,o=n(a),s=n(i);return c=>{const u=t.readValue(c,e.variable),d=We(u,o),p=We(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return he}function Sp(e){for(const t of gp)if(t in e)return t;return null}function We(e,t){if(e===null||t===null)return"incomparable";if(l.isStrictTemporalDataValue(e)&&l.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return l.isStrictNumericDataValue(e)&&l.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var xp=(e,t,r,n,a,i)=>{const o=ko(e,t,r.predicate,n,a,i);if(o===null)return null;const s=Mo(r.padding),c=s===null?Tp(o,r.padding):o,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin),frame:c.frame};return s===null?u:{...u,defer:s}},Ap=(e,t,r,n,a,i)=>{const o=ko(e,t,r.predicate,n,a,i);return o===null?null:{...ft(o,r.align),frame:o.frame}},Mo=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},ko=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let o=null,s=!1;const c=new Map;for(const u of n){if(!u.interactive)continue;const d=Ie(r,u.data,"selection-anchor");if(d.length>0){for(const h of d)c.set(`${h.code}:${h.message}`,h);continue}s=!0;const p=Ae(r,vt(u,i));if(p!==he)for(const h of u.data){if(!p(h))continue;const m=So(h,a);m!==null&&(o=o===null?m:Ip(o,m))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},Ip=(e,t)=>({frame:e.frame,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)}),Tp=(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}},Jt=(e,t,r)=>{const n=Ep(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:wp(n,t.offset,e.coordSystem)},No=(e,t)=>t.anchorType==="selection"?xp(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotation-ref",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},An=(e,t,r)=>Yr(e,t,r)?.point??null,Yr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const o of t){const s=e.geomRegistry.get(o.geom),{resolveAnchorPosition:c}=s;if(c===void 0||a.layerId!==void 0&&o.id!==a.layerId||a.layerId===void 0&&!o.interactive)continue;const u=_o(o,s),d=Po(o),p=yt(o),h=Eo(o,n)(a);let m=-1;for(const f of o.data){if(m+=1,!d(f,h))continue;const g=c(f,{coordSystem:r,position:o.position,purpose:i,align:a.align});if(g===null)continue;const v=Bo(o,f,u);if(v===null)continue;const y=p(f);if(y!==null)return{point:{...g,...v,frame:Sn(r),observationIndex:m,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:o.id}}}return null},Lp=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const o=a.x,s=a.y;if(o===void 0||s===void 0||o.kind!=="position"||s.kind!=="position")return null;const c=Ka(t.x,"x",r,i),u=Ka(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!tt(d,p))return null;const h=Wa(d,o,Rp(e)),m=Wa(p,s),f=Ha(n.mainAxis,{main:h.min,cross:m.min}),g=Ha(n.mainAxis,{main:h.max,cross:m.max});return ft({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},Bo=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:pp(r.valueFormat,t),yScaleType:e.yScaleType}:null},Ep=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Lp(e,t);case"selection":return Ap(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return An(e,Cp(t),r)}},wp=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Mo(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Wa=(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}},Rp=({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},Cp=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Ka=(e,t,r,n)=>{for(const a of r){const i=l.extractVariableName(a.mapping[t]);if(!(i===null||i===l.CONSTANT_VARIABLES.x))return l.parseValue(e,l.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Vp=class extends l.Stage{constructor(e){super(),this.container=e}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,o={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},s={differenceArrows:Gp(o,t.differenceArrows),shapes:Op(o,t.shapes),arrows:kp(o,t.arrows),textAnnotations:Np(o,t.textAnnotations),images:Mp(o,t.images),stickers:Bp(o,t.stickers),pinnedNumbers:Fp(o,t.pinnedNumbers),comments:$p(o,t.comments)};return Dp(this.container,s),_p(this.container,s),s}},le=(e,t,r,n)=>{e.diagnostics.addWarning({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."})},Dp=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.diagnostics.addWarning({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)}},_p=(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 Pp(t))r.has(a)||e.diagnostics.addWarning({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."})},Pp=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotation-ref"&&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},Op=(e,t)=>{const r=[];for(const n of t){const a=No(e,n.region);if(a===null){le(e.container,"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},Mp=(e,t)=>{const r=[];for(const n of t){const a=No(e,n.region);if(a===null){le(e.container,"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},kp=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.start,"pin"),i=Jt(e,n.end,"pin");if(a===null||i===null){le(e.container,"arrow",n.id,`has ${Fo(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Np=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.at,"pin");if(a===null){le(e.container,"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},Bp=(e,t)=>{const r=[];for(const n of t){const a=Jt(e,n.at,"pin");if(a===null){le(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Fp=(e,t)=>{const r=[];for(const n of t){const a=An(e,n.at,"pin");if(a===null){le(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},$p=(e,t)=>{const r=[];for(const n of t){const a=An(e,n.at,"pin");if(a===null){le(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Gp=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)le(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Yr(e,n.start,"value"),i=Yr(e,n.end,"value");if(a===null||i===null){le(e.container,"differenceArrow",n.id,`has ${Fo(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){le(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Up(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},Fo=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Up=(e,t,r,n)=>{Lo(r,n)||e.container.diagnostics.addWarning({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:Kr(r),actual:Kr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Hp(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const o of Object.keys(i))r.has(o)||r.set(o,[]);for(const a of e)for(const i of a.observations)for(const[o,s]of r)s.push(o===t?a.kind:i[o]??null);const n={};for(const[a,i]of r)n[a]={type:$o(i),values:i};return new l.Dataset(n)}function $o(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 Wp=class extends l.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(l.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:l.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){const a=l.extractConstantValue(r[n]);if(a===void 0)continue;const i=l.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,$o(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Fe=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.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)}},Kp=class extends l.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)}},zp=class extends Fe{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 l.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},Yp=class{constructor(e){this.setupStage=new Kp(e),this.transformStage=new zp(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)}},qp=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new l.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}},jp=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new l.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:Zp(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Qp(t))}},Xp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],za=l.prefixInternalVariable("flipSwap"),Zp=(e,t)=>Jp(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Jp=e=>{for(const t of e){const r=l.extractVariableName(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},Qp=e=>{let t=e.data;for(const[r,n]of Xp){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,za).renameVariable(n,r).renameVariable(za,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function Go(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 Uo=(e,t)=>Go(t.domain!==null&&t.domain.length>0?t.domain:e),em=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=nm(t,e.scales,e.layers),a=im(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:e.scales}}transform(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new l.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=rm(r,n),i=om(t);return e.layers.map(o=>sm(t.theta==="y"?lm(o):o,a,i))}},tm=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]];function rm(e,t){return r=>bo(r,e,t)}function nm(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=am(n,e,r);return a===0?0:-Math.PI/a}function am(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const o of a.data.getValues(i))n.push(o)}return Uo(n,e).length}function im(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 om(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function sm(e,t,r){let n=e.data;return n=Ke(n,l.POSITION_VARIABLES.x,t),n=Ke(n,l.POSITION_VARIABLES.xMin,t),n=Ke(n,l.POSITION_VARIABLES.xMax,t),n=Ke(n,l.POSITION_VARIABLES.y,r),n=Ke(n,l.POSITION_VARIABLES.yMin,r),n=Ke(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Ke(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 lm(e){let t=e.data;for(const[r,n]of tm){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const o=a?t.getValues(r):null,s=i?t.getValues(n):null;o&&(t=t.addVariable(n,"numeric",o)),s&&(t=t.addVariable(r,"numeric",s))}return{...e,data:t}}var cm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new qp),this.register("flip",new jp),this.register("polar",new em)}},Ho=new Set(["min","max","scalar"]),um={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function dm(e){const t=new Set;for(const r of e)r.role==="point"?t.add(r.axis):(r.role==="min"||r.role==="max")&&l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function pm(e){const t=new Set;for(const r of e)r.role==="point"&&t.add(r.axis),l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function mm(e,t,r){let n=e;for(const a of t){if(a.role!=="min"&&a.role!=="max"||!l.isDefined(a.aes))continue;const i=um[a.axis][a.role];if(n.hasVariable(i))continue;const o=l.extractVariableName(r[a.aes]);!l.isDefined(o)||!n.hasVariable(o)||(n=n.addVariable(i,"numeric",n.getValues(o,{type:"numeric"})))}return n}var hm=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:mm(n.data,r.positionRoles,a)}}},In=["x","y"],Tn=new Set(["x","y","ySecondary"]),bt=new Set(["color","size","alpha","strokeWidth","lineType"]),$e=e=>Tn.has(e),Ln=e=>bt.has(e),Wo=e=>$e(e)||Ln(e);function Te(e){return e==="secondary"?"ySecondary":"y"}function Ko(e,t){return e==="y"?Te(t):"x"}function H(e){return e==="ySecondary"?"y":e}var Le=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of bt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},pr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Le(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),fm=class{compute({data:e,mapping:t}){const r=Le(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(o=>e.getValues(o)),i=new Array(n);for(let o=0;o<n;o++)i[o]=l.getStableKey(a.map(s=>s[o]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},gm=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},ym=(e,t,r)=>{const n=Me(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Me(e,t){const r=H(t);for(const n of zo(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var mr=(e,t)=>e===null?null:t[e]??e,vm=(e,t)=>e===null?null:t[String(e)]??null,ke=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Dr(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 Sm(i,t)?i:Dr(t)}return Dr(t)},bm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:zo(t,e).some(r=>r.position==="fill");function zo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Dr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Sm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},xm=[{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}],Ya={year:0,quarter:1,month:2,week:3,day:4,hour:5},ze=40,Am=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Em(r.unit).range(e,new Date(t.valueOf()+1),n)},Im=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>ze;case"day":return a/t>ze;case"week":return a/(7*t)>ze;case"month":return a/(30*t)>ze;case"quarter":return a/(90*t)>ze;case"year":return a/(365*t)>ze}},Tm=(e,t)=>{const r=!l.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"month_year"}:{type:"month"};case"week":return r?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return r?{type:"date"}:{type:"day_month"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Lm=(e,t)=>{const r=wm(t);return r===null?!1:Ya[e]>Ya[r]},Em=e=>{switch(e){case"hour":return lt.utcHour;case"day":return lt.utcDay;case"week":return lt.utcMonday;case"month":case"quarter":return lt.utcMonth;case"year":return lt.utcYear}},wm=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}},Yo={left:"right",right:"left",top:"bottom",bottom:"top"},Rm={x:!0,y:!0,ySecondary:!1},Cm=20,qa=new Set(["top","bottom"]),Vm={type:"percentage"};function Dm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:o,geomRegistry:s}=e;if(Vo(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Om(s,a,i.type,n),u=new Set(t.map(h=>h.position)),d=km(qo(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const h of Tn){const m=r[h];if(!l.isDefined(m)||m.kind!=="position")continue;const f=_m({scaleAestheticKey:h,scale:m,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function _m(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:o,gridOverrides:s,variableLabels:c}=e,{axisConfig:u,position:d,geometry:p}=Mm(t,n,i,o),h=Me(a,t),m=bm(a,t)?Vm:ke({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:p,label:Pm(u,h,c),isVisible:u.isVisible,tickCandidates:Bm(r,m,u.ticks.mode),valueFormat:m,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Nm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Pm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Om(e,t,r,n){const a=t.flatMap(s=>{const c=e.get(s.geom).grid[r];return c?[c]:[]}),i=a.some(s=>s.hideGridX),o=a.some(s=>s.hideGridY);return{x:{gridVisible:ja(i,n.axes.x.grid.isVisible)},y:{gridVisible:ja(o,n.axes.y.grid.isVisible)}}}function ja(e,t){if(e&&t===null)return!1}function Mm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:qo(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=Yo[n],i=(0,it.merge)({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function qo(e,t){return qa.has(e)===qa.has(t)?e:t}function km(e,t){return t.has(e)?Yo[e]:e}function Nm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Rm[r]}var Bm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=$m(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=Cm;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>rt(e,u))}))}return i}return e.spec.scaleType==="datetime"?Fm(e,t):[{ticks:e.generateTicks().map(a=>rt(e,a))}]},Fm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>rt(e,s))}];const a=new Set,i=[],o=(s,c)=>{if(s.length===0)return;const u=l.getStableKey(s);a.has(u)||(a.add(u),i.push({ticks:s.map(d=>rt(e,d)),valueFormat:c}))};for(const s of xm)Im({...s,start:r,stop:n})||Lm(s.unit,t)||o(e.generateTicks({interval:s}),Tm(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},$m=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[rt(e,r),rt(e,n)]}},rt=(e,t)=>({value:t,position:e.map(t)});function jo({scale:e,aesthetics:t,layers:r}){const n=Gm({layers:r,aesthetics:t}),a=Xo({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Gm({layers:e,aesthetics:t}){const r=Xo({layers:e,aesthetics:t}),n=e.find(i=>t.some(o=>l.isDefined(i.mapping[o]))),a=n?n.geom:"bar";return i=>{const o=r(i);return o?o.layer.geom:a}}function Xo({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const o=t.find(c=>l.isDefined(i.mapping[c]));if(o===void 0)continue;const s=l.extractVariableName(i.mapping[o]);if(!(s===null||!i.data.hasVariable(s)))for(const c of i.data.getValues(s,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var En=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Um({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!En(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=Me(t,"color");if(Zo({colorVariableName:a,xVariableName:Me(t,"x"),mapsColorAcrossMultipleLayers:Wm(t)>1,isMergedWithAnotherAesthetic:Hm(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return jo({scale:n,aesthetics:["color"],layers:t}).map(({value:s,geom:c,owner:u})=>{const d=u?.layerIndex??o,p=t[d],h=p?l.extractVariableName(p.mapping.color):null;return{value:s,color:String(n.map(s)),geom:c,layerIndex:d,valueFormat:ke({layers:p?[p]:t,scaleType:i,variableName:h}),label:vm(s,r)}})}var Zo=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Hm(e,t,r){if(r===null)return!1;for(const n of bt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!En(a))&&Me(t,n)===r)return!0}return!1}var Wm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Jo(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Km(e,t,r,n){const a=r.findIndex(i=>Jo(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:mr(l.extractVariableName(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 Xa(e,t,r){if(r===null||t===null)return[...e];const n=l.getStableKey(r);return e.filter((a,i)=>l.getStableKey(t[i]??null)===n)}var Qo=e=>e==="none"?"first":e,zm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Za(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Za(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Ym=(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}},Za=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function qm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?jm(e,n):Xm(e,n)}function jm(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(s=>s.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const o=l.extractVariableName(a.mapping.y);return o===null?null:{kind:"grandTotal",value:i,valueFormat:ke({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:o})}}function Xm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:o,geomRegistry:s}=e;if(!a.some(d=>Jo(s,d)))return null;const c=Km(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Zm({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 Zm({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const o=l.extractVariableName(i.mapping.y);if(o===null||t==="total"&&i.position==="fill")return null;const s=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=ke({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=eh(i.data,s),h=ke({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),m=th(i.data,s),f=m.getValues(o,{type:"numeric"}),g=s!==null?m.getValues(s):[],v=c!==null?m.getValues(c):null,y=Xa(f,v,e.value),b=Xa(g,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:zm(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,caption:Jm(t,p,b),comparison:Qm(t,r,p,b,y)}}function Jm(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 Qm(e,t,r,n,a){return e!=="current"||!r?null:Ym(n.map((i,o)=>({main:i,cross:a[o]??null})),Qo(t))}function eh(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function th(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function ae(e,...t){return e?t.includes(e.geom):!1}function B(e,t){return e.find(r=>r.id===t)}function Ee(e,...t){return e.find(r=>t.includes(r.geom))}function rh(e,...t){return e.filter(r=>t.includes(r.geom))}function wn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Rn(e){const t=e.filter(r=>!wn(r,e));return t.length>0?t:e}function es({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Rn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var nh=3;function ah({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:o}){if(t.legend.position==="none")return{drawn:[],position:"none"};const s=new Map(i.map(v=>[l.getStableKey(v.value),v])),c=ph(lh({scales:e,layers:r})),u=Me(r,"x"),d=c.map(v=>{if(uh(v,u,r))return null;const y=hh({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return y.items.length===0?null:{group:v,built:y}}).filter(l.isDefined),p=ih(d),h=Rn(r),m=Sh(o,t.legend.position,p,h,n);if(d.length===0)return{drawn:[],position:m};if(t.legend.position==="auto"&&bh(o,p,h,n))return{drawn:[],position:m};const f=xh(t.legend.display,{legendPosition:m,coordSystem:n,layers:r}),g=f==="direct"?Lh(h[0]):null;return{drawn:d.map(({built:v})=>oh(v,{position:m,display:f,align:t.legend.align},g)),position:m}}function ih(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function oh(e,t,r){const{position:n,display:a}=t,i=sh(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(o=>({...o,normalizedY:r.get(String(o.value))??null}))}}function sh(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function lh(e){const{scales:t,layers:r}=e,n=[];for(const a of bt){const i=t[a];if(i===void 0||i.kind==="identity"||!ch(a,r))continue;const o=Me(r,a),s=Th(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function ch(e,t){const r=H(e);return t.some(n=>l.isDefined(n.mapping[r]))}function uh(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Zo({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:dh(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function dh(e,t){const r=H(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function ph(e){const t=new Map;for(const r of e){const n=Ih(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function mh(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function hh({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>H(u.scaleAestheticKey)),o=jo({scale:a.scale,aesthetics:i,layers:r}),s=ke({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),c=r.find(u=>i.some(d=>l.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:mr(a.variableName,t),items:o.map(u=>fh(u,e,i,s,n,c))}}function fh(e,t,r,n,a,i){const o={};for(const c of t)mh(o,c.scaleAestheticKey,c.scale.map(e.value));if(o.color===void 0&&r.includes("size")&&(o.color=l.DEFAULT_GEOM_COLOR),o.lineType===void 0){const c=l.extractConstantValue(e.owner?.layer.mapping.lineType);gn(c)&&(o.lineType=c)}const s=yh(e,t,r,n,a);return{value:e.value,label:gh(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function gh(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function yh(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,o=vh(i,r);return i===void 0||o===null?n:ke({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function vh(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=l.extractVariableName(n);if(a!==null)return a}return null}function bh(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 Sh(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,o=!1,s=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(o=!0,U(u.position)&&(s=!0))}const c=r>=nh;return i&&o?"top":i?c?"right":"top":s?Ah(a)?"top":c?"right":"top":"top"}function xh(e,t){return e==="pill"?"pill":es(t)?"direct":"pill"}function Ah(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Ih(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Th(e,t){return En(t)?"discrete":`continuous:${e}`}function Lh(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(c=>l.isDefined(F(c))||l.isDefined(D(c)));if(!n)return;const a=re(n);if(!l.isDefined(a))return;const i=G(n),o=F(n)??D(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var Eh=class extends l.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=gm(e.originalData),r=Um({scales:e.scales,layers:e.layers,valueLabels:ym(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=qm(n),i=ah(n),o={...i,drawn:wh(a,i.drawn)};return{axes:Dm(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},wh=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],dt=(e,t,r)=>{switch(e){case"series":return Rh(t);case"x-value":return Cn(t,r)}},hr=e=>{const t=l.readMainAxisVariable(e);return t===""?null:t},Rh=e=>l.getStableKey([re(e)]),Cn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Ch={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function ts(e){const t=Ch[e]??null;return t===null?null:{strategy:t,composition:rs()}}function rs(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Vh=class extends Fe{constructor(e){super(),this.container=e}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(({layerId:i})=>i===void 0||i===e.id);if(n.length===0)return e;const a=Dh({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Dh({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(I=>{const V=Ie(I.predicate,e.data);for(const O of V)a.diagnostics.addWarning({...O,message:`${O.message} Dropping this highlight.`});return V.length===0}),o=hr(e.mapping),s=vt(e,r),c=i.map(I=>({predicate:Ae(I.predicate,s),scope:I.scope})),u=c.some(({scope:I})=>I==="series"),d=c.some(({scope:I})=>I==="x-value"),p=n==="overlay-anchor",h=e.data.size(),m=u?new Array(h):null,f=d?new Array(h):null,g=p?new Array(h):null,v=new Uint8Array(h),y=new Set,b=new Set;let A=!1,T=0;for(const I of e.data){let V,O;m!==null&&(V=dt("series",I,o),m[T]=V),f!==null&&(O=dt("x-value",I,o),f[T]=O),g!==null&&(g[T]=I);for(const{predicate:ie,scope:kt}of c)if(ie(I))switch(kt){case"series":V!==void 0&&y.add(V);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":v[T]=1,A=!0;break}T++}if(y.size===0&&b.size===0&&!A)return rs();const L=new Uint8Array(h),E=[];let w=0;for(let I=0;I<h;I++){const V=m?.[I],O=f?.[I],ie=V!==void 0&&y.has(V),kt=O!==void 0&&b.has(O),ka=v[I]===1;if(n==="observation-rerender")(ie||ka||kt)&&(L[I]=1,w++);else if(ie)L[I]=1,w++;else if(ka||kt){const Na=g?.[I];Na!==void 0&&E.push({observation:Na,observationIndex:I})}}const C=w>0?{...e,data:e.data.filterByMask(L)}:null;return{isDimmed:(n==="observation-rerender"||y.size>0)&&C!==null,matchedLayer:C,overlayCandidates:E}}var _h=l.prefixInternalVariable("__ungrouped__");function Ph(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),o=new Map,s=i.map((c,u)=>{if(c===null)return null;const d=r[u]??_h;let p=o.get(d);return p||(p=new l.ChronologicalDateManager,o.set(d,p)),p.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",s)}return n}var Oh=()=>({defaults:[],overrides:[],warnings:[]}),Mh=class extends Fe{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,Ja(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},xScaleIsDiscrete:Ja(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=ur({data:t,mapping:r}).pipe(({data:s,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:s,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>({data:this.groupCompiler.compute({data:s,mapping:c}).data,mapping:c})).pipe(({data:s,mapping:c})=>({data:Ph(s),mapping:c})).pipe(({data:s,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:s,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),o=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,dataLabels:e.dataLabels,summary:{},spatialKind:o.spatialKind,identityKey:o.identityKey,tooltip:o.tooltip,supportsDirectLabels:o.legend.directLabelSupport?.[e.position]===!0,highlight:ts(e.geom),styles:Oh()}}};function Ja(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function ns(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function kh(e,t){return t.some(r=>U(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function qr(e,t){const r=as(e,t),n={};for(const{layer:i,scaleConstraints:o,crossAxis:s}of r)o.zeroBaseline===!0&&(n[s]={nice:(n[s]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:Bh(r),zeroAxes:n,bandPadding:Fh(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Nh(e,t){const r=as(e,t);for(const n of r){if(n.scaleConstraints.discreteCrossAxis!==!0)continue;const a=r.find(i=>i.scaleConstraints.zeroBaseline===!0&&i.crossAxis===n.crossAxis);if(a!==void 0)return{crossAxis:n.crossAxis,banded:Qa(n),zeroAnchored:Qa(a)}}return null}var Qa=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function as(e,t){const r=[];return t.forEach((n,a)=>{if(!e.has(n.geom))return;const{scaleConstraints:i}=e.get(n.geom);i!==void 0&&r.push({layer:n,index:a,scaleConstraints:i,crossAxis:Te(n.yScaleType)})}),r}function Bh(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of is(r))t.add(n);return[...t]}function Fh(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of is(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function is({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var $h=new Set(["label","group"]),Gh=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},o={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(o));const s=[...this.collectUndeclaredAesthetics(o),...this.collectPanelJustifyWarnings(o)];for(const c of s)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),ns(this.container.diagnostics,t)}checkPostCompile(e){Vo(e)&&this.container.diagnostics.addWarning({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."})}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:o,showDataLabels:s}=i;if(!s||o!=="panel-start"&&o!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!pr(r,t))return[];const c=o==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${o}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:o},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:o,aesthetics:s}=this.container.geomRegistry.get(r),c=[...dm(o),...s.filter(p=>p.required).map(p=>p.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const p of c)d.has(p)||l.isDefined(a[p])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${p}'`,context:{layerIndex:t,aesthetic:p}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=s,d=new Set(c);for(const[p,h]of Object.entries(a)){if(u.has(p))continue;const m=l.extractVariableName(h);m===null||m===""||d.has(m)||i.hasVariable(m)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${p}' references variable '${m}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:p,variableName:m}})}return o}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=s,u=[];for(const d of o){if(!Ho.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const p=l.extractVariableName(a[d.aes]);if(p===null||!i.hasVariable(p)||i.size()===0)continue;const h=i.getType(p);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${p}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:p,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(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,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:o}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:o}).map(s=>({...s,message:`Layer '${e}': ${s.message}`,context:{...s.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Nh(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}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{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=new Set([...pm(i),...o.map(h=>h.name)]),u=$h,d=s,p=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||p.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return p}},ve=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=Ao,this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,it.merge)({},this.defaultParams,e.params)}},Vn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},Dn=(e,{coordSystem:t})=>{const r=M(e),n=D(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?Ce(r,n):{x:r,y:n}},Uh=class extends ve{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="filled-buckets",this.resolveAnchorPosition=Dn}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=Vn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Hh=.7,Wh=.1,Kh=.03,zh=.05,os=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Yh=class extends ve{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveDataLabelDefaults=t=>U(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>jr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=So(t,r);return p===null?null:ft(p,i)}if(r.type==="polar")return qh(t);const o=U(n),s={isSolo:!o||os(t)==="solo",isNegative:o&&jh(t),purpose:a};if(r.mainAxis==="x"){const p=j(t),h=X(t),m=ei({lowerBound:G(t),upperBound:F(t)??D(t),options:s});return p===null||h===null||m===null?null:{x:(p+h)/2,y:m}}const c=G(t),u=F(t),d=ei({lowerBound:j(t),upperBound:X(t)??M(t),options:s});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=jr(r,n);e=Vn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const i=a/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",i),{data:e,mapping:{}}}resolveWidthParam(e,t){if(e===void 0)return;const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return r;const n=r!==null&&r>1?1:void 0;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the category band in (0, 1]."}),n}},jr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Hh,qh=e=>{const t=j(e),r=X(e),n=G(e),a=F(e);return t===null||r===null||n===null||a===null?null:Ce((t+r)/2,(n+a)/2)},jh=e=>{const t=hn(e);return l.isStrictNumericDataValue(t)&&t<0},ei=e=>{const{lowerBound:t,upperBound:r,options:n}=e,a=n.isNegative?t:r;if(a===null)return null;if(n.purpose==="value"||n.isSolo)return a;const i=n.isNegative?r:t;return i===null?null:(i+a)/2},Xh=class extends ve{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=Dn}compile(e){return{data:Vn(e.data,e.mapping),mapping:{}}}},Zh=class extends ve{constructor(...e){super(...e),this.type="point",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"size"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.resolveAnchorPosition=Dn,this.resolveValueSource=(t,r)=>{if(r!=="label")return null;const n=l.extractVariableName(t.size);return n!==null?{variable:n}:null}}compile({data:e}){return{data:e,mapping:{}}}},Jh=class extends ve{constructor(...e){super(...e),this.type="rule",this.defaultParams={labelPosition:"start"},this.defaultInteractive=!1,this.positionRoles=[{axis:"y",role:"scalar",valueKind:"value",aes:"y"},{axis:"x",role:"scalar",valueKind:"value",aes:"x"}],this.highlightStrategy=null,this.spatialKind="noop",this.validateMapping=({mapping:t,computedVariables:r})=>{const n=r.has("x")||l.isStrictNumericDataValue(l.extractConstantValue(t.x)),a=r.has("y")||l.isStrictNumericDataValue(l.extractConstantValue(t.y));return n&&a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires exactly one of 'x' or 'y', both were provided"}]:!n&&!a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires a numeric value on 'x' or 'y'"}]:[]}}compile({data:e,mapping:t}){const r=ti(t.y,e);if(r!==null)return{data:new l.Dataset({[l.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:l.RULE_VARIABLES.y,x:void 0}};const n=ti(t.x,e);return n!==null?{data:new l.Dataset({[l.RULE_VARIABLES.x]:{type:"numeric",values:[n.value],valueFormat:n.sourceFormat}}),mapping:{x:l.RULE_VARIABLES.x,y:void 0}}:{data:new l.Dataset,mapping:{x:void 0,y:void 0}}}},ti=(e,t)=>{const r=l.extractConstantValue(e);if(l.isStrictNumericDataValue(r))return{value:r,sourceFormat:void 0};const n=l.extractVariableName(e);if(n===null||!l.isStatVariable(n)||!t.hasVariable(n))return null;const[a]=t.getValues(n);return l.isStrictNumericDataValue(a)?{value:a,sourceFormat:t.getValueFormat(n)}:null},Qh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},ef=class extends ve{constructor(...e){super(...e),this.type="tile",this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian"],this.aesthetics=[{kind:"visual",name:"color",required:!0}],this.scaleConstraints={discreteMainAxis:!0,discreteCrossAxis:!0,bandPadding:0,inferredColor:!0},this.grid={cartesian:{hideGridX:!0,hideGridY:!0}},this.legend={suppressWhenSingleItem:!1},this.dataLabels={cartesian:{showDataLabels:!0}},this.dataLabelCoordTypes=["cartesian"],this.highlightStrategy="observation-rerender",this.spatialKind="cells",this.identityKey="x-y",this.tooltip=[{aes:"color"}],this.resolveValueSource=Qh,this.resolveAnchorPosition=t=>{const r=j(t),n=X(t),a=G(t),i=F(t);return r===null||n===null||a===null||i===null?null:{x:(r+n)/2,y:(a+i)/2}}}compile({data:e}){return{data:e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",.5).addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.yMax,"numeric",.5),mapping:{}}}},tf=[new Yh,new Zh,new Xh,new Uh,new Jh,new ef],fr=class extends l.Registry{constructor(){super("geom");for(const e of tf)this.register(e.type,e)}},Ge=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},rf=class extends Ge{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.x);if(!l.isDefined(r))throw new l.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(l.extractVariableName(t.y)!==null)throw new l.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,...Le(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},nf=class extends Ge{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},af=class extends Ge{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});return{data:e.rollup({[l.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:l.STAT_VARIABLES.mean}}}},of=2,ss=1440*60*1e3,sf=class extends Ge{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.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(!l.isDefined(i))throw new l.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 o=e.getType(a),s=e.getType(i);if(s!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${s}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:s}});const c=Le(e,t),u=hf(a,o,i,c,e);return c.length===0?ri({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=ff(d,c);ri({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},ri=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=lf({data:e,xVariable:t,yVariable:n,xType:r});c.length<of||(s?mf({observations:c,spec:a,output:i,groupObservation:o}):df({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},lf=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?cf(a):null,s=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!l.isDefined(d)||!l.isDefined(p)||!Number.isFinite(p))continue;const h=uf({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});h!==null&&s.push({x:h,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},cf=e=>{let t=null;for(const r of e){if(!l.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},uf=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!l.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!l.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/ss+1}case"categorical":{if(!l.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 l.InternalError({message:`Unexpected xType: ${t}`})}},df=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=ls(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?pf(s,r):s;a.push({x:u,y:c,groupObservation:i})}},pf=(e,t)=>t===null?new Date(e):new Date((e-1)*ss+t),mf=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const s of e)a.has(s.x)||a.set(s.x,s.originalX);const i=[...a.keys()].sort((s,c)=>s-c);if(t.method==="loess"){const s=ls(t,e),c=new Map;for(const[u,d]of s)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const o=cs(t,e);for(const s of i){const c=a.get(s),u=o.predict(s);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},ls=(e,t)=>e.method==="loess"?(0,Re.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):cs(e,t),cs=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Re.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Re.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Re.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Re.regressionQuad)().x(r).y(n)(t);case"power":return(0,Re.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Re.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},hf=(e,t,r,n,a)=>{const i=[],o=[],s=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),o.push(u);for(const p of n)s[p]?.push(d[p]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:o,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:s[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},ff=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},gf=class extends Ge{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});const n=l.extractVariableName(t.x),a=[...new Set([...n===null?[]:[n],...Le(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},yf=[new nf,new rf,new sf,new af,new gf],vf=class extends l.Registry{constructor(){super("stat");for(const e of yf)this.register(e.type,e)}};function bf({geoms:e,stats:t,transforms:r}){const n=new fr,a=new vf,i=new l.TransformRegistry;for(const o of e)n.register(o.type,o);for(const o of t)a.register(o.type,o);for(const o of r)i.register(o.transformType,o);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function _n(e){if("definition"in e)return e.definition;if(ds(e)||ps(e)||ms(e))return e}function us(e){const t=[],r=[],n=[];for(const a of e){const i=_n(a);i&&(ds(i)?t.push(i):ps(i)?r.push(i):ms(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[..._r("geom",t,a=>a.type),..._r("stat",r,a=>a.type),..._r("transform",n,a=>a.transformType),...Sf(t),...xf(t)]}}function Sf(e){const t=[];for(const r of e)r.spatialKind==="render-hit-test"&&(r.identityKey!=="x-group"&&r.identityKey!=="x-y"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the position-derived '${r.identityKey}' identity, which has no meaning for render-owned geometry; its hover lookup will be empty.`,context:{kind:"geom",requested:r.type},suggestion:"Declare 'identityKey' as a column the geom owns (`{ variable: '<column>' }`) or 'index', so a hit-test result resolves to an observation."}));return t}function xf(e){const t=[];for(const r of e)r.spatialKind!=="cells"||!r.supportedCoordTypes.includes("polar")||t.push({code:"SPATIAL_KIND_COORD_UNSUPPORTED",message:`The geom '${r.type}' declares polar support, but its 'cells' hit-test shape has no polar projection; its observations will not respond to hover under polar coords.`,context:{kind:"geom",requested:r.type},suggestion:"Drop 'polar' from 'supportedCoordTypes', or declare 'rects' as the spatial kind so a bandless polar layer hit-tests as an enclosure."});return t}function _r(e,t,r){const n=new Map;for(const i of t){const o=r(i),s=n.get(o);s?s.add(i):n.set(o,new Set([i]))}const a=[];for(const[i,o]of n)o.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${o.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var ds=e=>e instanceof ve,ps=e=>e instanceof Ge,ms=e=>"transformType"in e&&typeof e.apply=="function",Af=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},gr=class{},If=class extends gr{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!l.extractVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),i=Tf(e)??[-.7/2,.7/2],o=r.length>1?Wh:0,s=(0,se.scaleBand)().domain(r.map(String)).range(i).paddingInner(o).paddingOuter(0),c=s.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const h=a[p];if(!l.isDefined(h))continue;const m=s(String(h));l.isDefined(m)&&(u[p]=m,d[p]=m+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Tf=e=>{const t=e.getConstant(l.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(l.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},ni=l.prefixInternalVariable("__ungrouped__"),hs=(e,t)=>{const r=l.extractVariableName(t.x),n=l.extractVariableName(t.y);if(!r||!n)return null;const a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,o=i?[ni]:a,s=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let h=0;h<d;h++){const m=l.getStableKey(s[h]??null),f=u[h],g=i?ni:f;if(!l.isDefined(g))continue;let v=p.get(m);v||(v=new Map,p.set(m,v));let y=v.get(g);y||(y=[],v.set(g,y)),y.push(h)}return{yValues:c,observationIndicesByXAndGroup:p,uniqueGroupKeys:o,observationCount:d}},fs=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const o=[];let s=-1,c=1/0,u=-1/0,d=-1,p=1/0,h=-1/0;for(const m of i.values())for(const f of m){const g=e[f],v=t[f];!l.isDefined(g)||!l.isDefined(v)||(o.push(f),(g<c||g===c&&v>u)&&(s=f,c=g,u=v),(v>h||v===h&&g<p)&&(d=f,p=g,h=v))}for(const m of o)a[m]=Lf(m===s,m===d)}return a},Lf=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Ef=class extends gr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=hs(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,d]of a){let p=0,h=0;for(const g of i){const v=d.get(g);if(v!==void 0)for(const y of v){const b=n[y];b!=null&&(b>=0?p+=b:h-=b)}}let m=0,f=0;for(const g of i){const v=d.get(g);if(v!==void 0)for(const y of v){const b=n[y];if(b===void 0)continue;if(b===null){c[y]=null,s[y]=null;continue}const A=b>=0?p:h;if(A===0){c[y]=0,s[y]=0;continue}const T=b/A;b>=0?(c[y]=m,s[y]=m+=T):(s[y]=f,c[y]=f+=T)}}}const u=fs(c,s,a,o);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},wf=class extends gr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Rf=class extends gr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=hs(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,h]of a){let m=0,f=0;for(const g of i){const v=h.get(g);if(v!==void 0)for(const y of v){const b=n[y];if(b!==void 0){if(b===null){c[y]=null,s[y]=null;continue}b>=0?(c[y]=m,s[y]=m+=b):(s[y]=f,c[y]=f+=b)}}}}const u=fs(c,s,a,o);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const p=l.extractVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",s)),{data:d,mapping:{}}}},Cf=class extends l.Registry{constructor(){super("position"),this.register("identity",new wf),this.register("stack",new Rf),this.register("fill",new Ef),this.register("dodge",new If)}},Vf=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const o of i.positionRoles){if(o.role!=="scalar"||!l.isDefined(o.aes)||Ln(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Ko(o.axis,t.yScaleType));if(!c)continue;const u=a.getValues(s,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(o.aes),"numeric",u)}return a}},Df=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},_f=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=l.isDefined(n)&&e.hasVariable(l.POSITION_VARIABLES.x)?Pf(e,r,n):Of(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Pf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=gs(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||(c.min[u]=d+(o?-h:p)*r,c.max[u]=d+(o?-p:h)*r)}return c}function Of(e,t){const r=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=gs(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function gs(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Mf=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(Te(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},kf=class{map({data:e,layer:t,getPositionScale:r}){const n=r(Te(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=l.isDefined(a)&&e.hasVariable(l.POSITION_VARIABLES.y)?Nf(e,n,a):Bf(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Nf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=ys(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||(c.min[u]=d+(o?-h:p)*r,c.max[u]=d+(o?-p:h)*r)}return c}function Bf(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=ys(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function ys(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Ff=[new Df,new Mf,new _f,new kf,new Vf];function $f(e,t){const r=e[t];return r?.kind==="position"?r:null}var Gf=class extends Fe{constructor(e,t=Ff){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=>$f(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}}},Uf=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=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:kh(this.container.geomRegistry,e.layers)},a={};for(const[i,o]of t){const s=r.get(i)??[];a[i]=this.registry.get(o.scaleType).compile(o,s,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=H(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const o=l.extractVariableName(i.mapping[a]);if(!l.isDefined(o)||!i.data.hasVariable(o)||i.data.size()===0)continue;const s=i.data.getType(o);if(n.includes(s)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${s})`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s}}),r.scaledAesthetic==="lineType"&&s!=="categorical"){const c=s==="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 ${s} variable '${o}'. ${c}`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}}ns(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,o]of Object.entries(n.mapping)){if(!l.isDefined(o))continue;const s=i==="y"?Te(n.yScaleType):i,c=a.get(i)??(Wo(s)?s:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,o,n.data,u);this.collectFromVariables(n.data,d,c,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!l.isDefined(n.aes)||Ln(n.aes)||t.set(n.aes,Ko(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const o of t)a=a.concat(e.getValues(o));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Hf=["rgb","lab","hcl","hsl"],Wf=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],vs=["RdBu","BrBG","PuOr","Spectral"],bs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Kf=new Set(vs.map(e=>e.toLowerCase()));function Ss(e){const t=e.toLowerCase(),r=bs[t];return r?r.toLowerCase():t}function zf(e){return Kf.has(Ss(e))}var Yf={rgb:je.interpolateRgb,lab:je.interpolateLab,hcl:je.interpolateHcl,hsl:je.interpolateHsl},qf={viridis:$.interpolateViridis,magma:$.interpolateMagma,inferno:$.interpolateInferno,plasma:$.interpolatePlasma,cividis:$.interpolateCividis,turbo:$.interpolateTurbo,blues:$.interpolateBlues,greens:$.interpolateGreens,greys:$.interpolateGreys,oranges:$.interpolateOranges,purples:$.interpolatePurples,reds:$.interpolateReds,rdbu:$.interpolateRdBu,brbg:$.interpolateBrBG,puor:$.interpolatePuOr,spectral:$.interpolateSpectral};function Pn(e){const t=Xf(e);return e.reverse?r=>t(1-r):t}function jf(e={},t=2){const r=Pn({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,reverse:e.reverse??!1});return t<2?t===1?[r(0)]:[]:Array.from({length:t},(n,a)=>r(a/(t-1)))}function Xf(e){const t=Yf[e.interpolate];if(e.range&&e.range.length>=2)return(0,je.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=qf[Ss(e.scheme)];if(r)return r}return(0,je.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var St=class{createPositionScale(e,t){return{kind:"position",aesthetic:H(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:H(e.scaledAesthetic),spec:e,...t}}},Zf=class extends St{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t){if(e.scaleType!=="continuous")throw new l.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const r=$e(e.scaledAesthetic),n=e.scaledAesthetic==="color",a=this.computeDataDomain(t,e);return n?this.buildColorScale(a,e):r?this.buildPositionScale(a,e):this.buildVisualScale(a,e)}computeDataDomain(e,t){let r=1/0,n=-1/0;for(const a of e)typeof a=="number"&&(a<r&&(r=a),a>n&&(n=a));return r===1/0?[0,0]:(t.zero&&(r>0&&(r=0),n<0&&(n=0)),[r,n])}createD3Scale(e,t,r){let n=[r.domainMin??e[0],r.domainMax??e[1]];const a=r.transform==="log"&&Jf(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:H(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,se.scaleLog)():r.transform==="sqrt"?(0,se.scaleSqrt)():(0,se.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const o=r.domainMin??n[0],s=r.domainMax??n[1];return i.domain([o,s]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=Qf(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){const r=Pn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[o,s]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([o,n,s],t,r)}}return this.buildSequentialColorScale(e,t,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,se.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){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,se.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Jf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Qf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var eg=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new l.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=$e(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new l.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=tg(e)?e:[],a=(0,se.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,o]=a.domain();i!==void 0&&o!==void 0&&a.domain([r.domainMin??i,r.domainMax??o])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,o]=a.domain(),s=i&&o?r.filter(c=>c>=i&&c<=o):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?s:c&&"interval"in c?i&&o?Am(i,o,c.interval):[]:a.ticks(c?.count)})}},tg=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),rg=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new l.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=$e(e.scaledAesthetic),n=Uo(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,se.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),o=i.bandwidth()/2;return this.createPositionScale(t,{map:s=>(i(String(s))??NaN)+o,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,se.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},ng=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:H(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},ag=class extends St{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=Go(t),a=l.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=l.applyOverrides(a.length>0?a:[...l.DEFAULT_COLOR_PALETTE],e.overrides),o=(0,se.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},ig=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Zf(e)),this.register("discrete",new rg),this.register("datetime",new eg),this.register("identity",new ng),this.register("palette",new ag)}},xs={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},og={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function On(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:qr(e.geomRegistry,n)}}function yr(e,t){switch(t.scaleType){case"inferred":return{...yr(e,ug(e,t)),inferredFrom:t};case"continuous":{const r=xs[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??l.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??l.CONTINUOUS_SCALE_DEFAULTS.nice,zero:t.zero??l.CONTINUOUS_SCALE_DEFAULTS.zero,clamp:t.clamp??r!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:dg(e.container,t),interpolate:t.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??l.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??l.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??l.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??l.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??l.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return Xr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:l.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function sg(e,t){const{scales:r,layers:n,coords:a}=t,i=On(e,t),o=hg(mg(r,n),i.demands),s=new Map;for(const u of o)s.set(u.scaledAesthetic,u);const c=[...s.values()].map(u=>{const d=lg(i,u);return yr(i,d)});return a.coordType==="polar"?c.map(Mn):c}function Xr(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??l.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??l.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??r??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??cg(e.scaledAesthetic,t)}}var Mn=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function lg(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:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function cg(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function ug({data:e,layers:t,mapping:r,demands:n},a){const i=H(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?pg(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const p=a.options;return l.continuous(a.scaledAesthetic,{...p,zero:!0,...!s.nice&&{nice:!1}})}const c=l.extractVariableName(o);if(!l.isDefined(c)||!e.hasVariable(c)||e.size()===0)return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=xs[a.scaledAesthetic];switch(og[u][d]){case"discrete":return l.discrete(a.scaledAesthetic,a.options);case"palette":return l.palette(a.scaledAesthetic);case"datetime":return l.datetime(a.scaledAesthetic,a.options);case"continuous":return l.continuous(a.scaledAesthetic,a.options);default:return l.identity(a.scaledAesthetic)}}function dg(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&zf(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function pg(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function mg(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function hg(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var fg={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},"top-left":{x:-1,y:-1},"top-right":{x:1,y:-1},"bottom-left":{x:-1,y:1},"bottom-right":{x:1,y:1}},gg=(e,t,r)=>{const n=yg(e,t),a=Sg(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Ag(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Eg(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Cg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>xg(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>Ig(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>wg(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>Tg(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Lg(e,i,r)).filter(l.isDefined)}},yg=(e,t)=>{if(t===void 0)return{};if(!vg(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))}},vg=e=>{const t=new Set;for(const r of bg(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},bg=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Sg=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},kn=(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},xg=(e,t,r,n)=>{const a=Qt(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??l.TEXT_ANNOTATION_DEFAULTS.align}},Ag=(e,t,r)=>{const n=pt(e,t.start,r),a=pt(e,t.end,r);return n===null||a===null?null:{id:t.id??W(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},pt=(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)},Qt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return kn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=pt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},Ig=(e,t,r,n)=>{const a=Qt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),at:a,sticker:t.sticker}},Tg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n}},Lg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n,content:t.content}},Eg=(e,t,r)=>t.region.anchorType==="annotation"&&!kn(e,t.region.ref,r,t.id)?null:{id:t.id??W(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Rg(t.region)},wg=(e,t,r)=>t.region.anchorType==="annotation"&&!kn(e,t.region.ref,r,t.id)?null:{id:t.id??W(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Rg=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},ai=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=fg[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Cg=(e,t,r,n)=>{const a=Qt(e,t.start,r,n,t.id),i=Qt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??W(),start:ai(a),end:ai(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},Vg={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function Dg(e){const t=(0,it.merge)({},Vg,e);return t.content=_g(t.content,e?.content),t}var _g=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Pg={xLimits:null,yLimits:null},Kt={theta:"x",startAngle:0,innerRadius:0};function Zr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,jt.default)({},Pg,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Kt.theta,startAngle:t.params?.startAngle??Kt.startAngle,innerRadius:(0,Je.default)(t.params?.innerRadius??Kt.innerRadius,0,1)}}}}function Og(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??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Mg=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"user-input"};t.persistent?this.persistent.push(r):this.diagnostics.push(r)}addError(e){this.diagnostics.push({...e,severity:"error",kind:"user-input"})}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=ii(e.filter(n=>n.severity==="error")),r=ii(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},kg=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 ii(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Ng={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:l.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4};function As(e,t){const r=e??t,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}}return{type:n}}function Ue(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new kg(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=$g({dataLabels:Ug(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return Fg({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??W(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:As(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:s.resolveParams({params:n.params,diagnostics:o}),transforms:n.transforms??[],interactive:n.interactive??s.defaultInteractive,dataLabels:u}}function Bg(e,t,r,n,a){const i=n.map((o,s)=>Ue(e,t,r,o,a,s));return Ts(e,i)}var Is=(e,t,r,n)=>n.label!==void 0?n.label:Do({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Ts=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Be(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(o=>o.axis==="y"&&o.role==="scalar"))return n;const a=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,it.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Fg=({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&&U(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'."})},$g=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:o}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const s=Gg(t,r,n);if(s===null)return e;const c=i==="panel-end"?"end":"start";return o&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${s}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Gg=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&U(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Ug=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=Is(e,r.geom,n,i),s=e.get(r.geom);return{...(0,it.merge)({},Ng,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},Hg=e=>{const t=new Set;e!==void 0&&Ls(e,t,new Set);const r={tokens:{},defaults:[],overrides:[]};for(const n of t)Object.assign(r.tokens,n.tokens),r.defaults.push(...n.defaults??[]),r.overrides.push(...n.overrides??[]);return r},Ls=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Ls(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function Wg(e,t,r){const n=Zr(t.coords),a=Bg(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=sg(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=Dg(t.config),s=Og(e,t.highlights,a),c=gg(e,t.annotations,a),u=Hg(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:s,styles:u,annotations:c,coords:n,config:o}}var Es=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return Wg(this.container,{...e,data:t},r)}},Kg=class{constructor(e){this.registry=e}compute(e,t){return this.registry.get(e.type).compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete})}},xt={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},zg={differenceArrow(e){return{type:"annotation",kind:"differenceArrow",annotation:e}},shape(e){return{type:"annotation",kind:"shape",annotation:e}},arrow(e){return{type:"annotation",kind:"arrow",annotation:e}},text(e){return{type:"annotation",kind:"text",annotation:e}},image(e){return{type:"annotation",kind:"image",annotation:e}},sticker(e){return{type:"annotation",kind:"sticker",annotation:e}},pinnedNumber(e){return{type:"annotation",kind:"pinnedNumber",annotation:e}},comment(e){return{type:"annotation",kind:"comment",annotation:e}}},ws=Object.keys(xt),Yg=e=>Object.hasOwn(xt,e),At=(e,t)=>{for(const r of ws){const n=qg(e,r,t);if(n)return n}return null},It=(e,t)=>e[xt[t]],Nn=(e,t,r)=>({...e,[xt[t]]:r}),Rs=(e,t)=>{const r=It(e,t.kind);return Nn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},qg=(e,t,r)=>{const n=It(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},jg=class extends Fe{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of yy(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of by(e.styles))this.container.diagnostics.addWarning(r);for(const r of Sy(e.styles))this.container.diagnostics.addWarning(r);for(const r of t)for(const n of r.styles.warnings)this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=Ns({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Ve={color:"color",alpha:"unitInterval",saturation:"unitInterval"},er={bar:{...Ve,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Ve,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Ve,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Ve,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...Ve,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},oi=1,si=1e3,Xg="'none' or a shadow object { offsetX, offsetY, blur, color }",li="a non-negative number of pixels, or an object of those per edge",Nt={color:"color",strokeWidth:"pixels",lineType:"lineType"},z={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Bt={...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},ci={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},_={panelBorder:{...Nt,borderRadius:"pixels"},panelBorderEdge:Nt,gridLine:Nt,tickLine:{...Nt,length:"pixels"},axisLabel:{...z,margin:"margin"},tickLabel:{...z,offset:"pixels",margin:"margin"},ruleLabel:z,dataLabel:Bt,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color",textScale:"multiplier",padding:"padding"},heading:z,caption:z,source:z,header:{margin:"margin"},footer:{margin:"margin"},hoverGuide:{color:"color",background:"color"},tooltip:ci,tooltipText:z,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels",margin:"margin"},legend:{gap:"pixels",margin:"margin"},legendPopover:ci,legendItem:{...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},legendItemSwatch:{size:"pixels",strokeWidth:"pixels"},directLabel:{...z,strokeWidth:"pixels",lineType:"lineType"},annotation:{color:"color",alpha:"unitInterval"},annotationShape:{color:"color",alpha:"unitInterval",borderColor:"color",borderWidth:"pixels"},annotationArrow:{color:"color",strokeWidth:"pixels",lineType:"lineType",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationDifferenceArrow:{color:"color",strokeWidth:"pixels"},annotationDifferenceArrowLabel:Bt,annotationText:{...Bt,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...Bt,shadow:"shadow"}},Cs={number:z,numberCenter:z,caption:z,label:z,swatch:{size:"pixels"},trend:z,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},Zg=new Set([...Object.keys(Ve),...Object.values(er).flatMap(e=>Object.keys(e??{})),...Object.values(_).flatMap(e=>Object.keys(e)),...Object.values(Cs).flatMap(e=>Object.keys(e))]),Vs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","caption","source","header","footer","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],Jg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Qg=new Set(["panelBorder","legend","axisLabel","tickLabel"]),ey=(e,t,r="en-US")=>Ns({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),ty=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of vy(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Ds(e.styles)}},Ds=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},heading:{defaults:[],overrides:[]},caption:{defaults:[],overrides:[]},source:{defaults:[],overrides:[]},header:{defaults:[],overrides:[]},footer:{defaults:[],overrides:[]},hoverGuide:{defaults:[],overrides:[]},tooltip:{defaults:[],overrides:[]},headline:{defaults:[],overrides:[]},headlineItem:{defaults:[],overrides:[]},legend:{defaults:[],overrides:[]},legendItem:{defaults:[],overrides:[]},directLabel:{defaults:[],overrides:[]},annotation:{defaults:[],overrides:[]},warnings:t},a=(i,o,s,c)=>{if(vr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ny(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${Vs.map(m=>`'${m}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const p=i.select;if(p.target==="annotation"){const m=p.kind;if(m!==void 0&&!my(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown annotation kind '${String(m)}'.`,context:{param:"kind",actual:String(m),...u},suggestion:`Set 'kind' to one of ${l.ANNOTATION_STYLE_KINDS.map(y=>`'${y}'`).join(", ")}, or omit it to address every annotation.`});return}const f=p.part,g=hy(m);if(f!==void 0&&!(typeof f=="string"&&g.includes(f))){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(f)}'.`,context:{param:"part",actual:String(f),...u},suggestion:g.length>0?`Set 'part' to ${g.map(y=>`'${y}'`).join(", ")}, or omit it to address the ${m==="differenceArrow"?"line":"marker"}.`:`Remove 'part' — ${m===void 0?"kind-agnostic":`'${String(m)}'`} entries have none.`});return}const v=p.annotation;if(v!==void 0&&typeof v!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid annotation ${xe(v)}.`,context:{param:"annotation",actual:xe(v),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}if(Qg.has(p.target)){const m=p.edge;if(m!==void 0&&!ay(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown edge '${String(m)}'.`,context:{param:"edge",actual:String(m),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Jg.has(p.target)){const m=p.axis;if(m!==void 0&&!fy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown axis '${String(m)}'.`,context:{param:"axis",actual:String(m),...u},suggestion:`Set 'axis' to one of ${In.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="ruleLabel"){const m=p.layer;if(m!==void 0&&typeof m!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid layer ${xe(m)}.`,context:{param:"layer",actual:xe(m),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(p.target==="tooltip"){const m=p.part;if(m!==void 0&&!sy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(p.target==="heading"){const m=p.part;if(m!==void 0&&!cy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.HEADING_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address every heading level.`});return}}if(p.target==="source"){const m=p.part;if(m!==void 0&&!ly(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.SOURCE_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the label.`});return}}if(p.target==="legend"){const m=p.part;if(m!==void 0&&!uy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.LEGEND_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the gap.`});return}}if(p.target==="legendItem"){const m=p.part;if(m!==void 0&&!dy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.LEGEND_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the pill.`});return}}if(p.target==="headlineItem"){const m=p.part;if(!py(m)){t.push({code:"INVALID_STYLE_RULE",message:m===void 0?`Style ${s} ignored: headlineItem entries need a part.`:`Style ${s} addresses unknown part '${String(m)}'.`,context:{param:"part",actual:String(m),...u},suggestion:`Set 'part' to one of ${l.HEADLINE_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="dataLabel"){const m=p.role;if(m!==void 0&&!iy(m)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown role '${String(m)}'.`,context:{param:"role",actual:String(m),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=p.position;if(f!==void 0){if(!oy(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(m===void 0||m==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=Fn({declarations:i.declarations,vocabulary:Ps(p),tokens:r,location:s,origin:c,warnings:t,entryTarget:p.target});Object.keys(h).length!==0&&n[p.target][o].push({select:p,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,o)=>{a(i,"defaults",`builtin[${o}]`,{list:"builtin"})}),e.defaults.forEach((i,o)=>{a(i,"defaults",`defaults[${o}]`,{list:"defaults",index:o,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,o)=>{a(i,"overrides",`overrides[${o}]`,{list:"overrides",index:o,...i.id===void 0?{}:{id:i.id}})}),n},ry=(e,t)=>{if(e==="geom"){const r=Object.keys(er).find(n=>er[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>Ps({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},vr=e=>e.select.target==="geom",ny=e=>{const t=e.select.target;return t!=="geom"&&Vs.includes(t)},_s=e=>(e!==void 0?er[e]:void 0)??Ve,Ps=e=>{if(e.target==="panelBorder")return e.edge===void 0?_.panelBorder:_.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?_.tooltip:e.part==="primaryRow"?_.tooltipPrimaryRow:_.tooltipText;if(e.target==="legend")return e.part==="popover"?_.legendPopover:_.legend;if(e.target==="legendItem")return e.part===void 0?_.legendItem:_.legendItemSwatch;if(e.target==="headlineItem")return Cs[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return _.annotationShape;case"arrow":return _.annotationArrow;case"differenceArrow":return e.part==="label"?_.annotationDifferenceArrowLabel:_.annotationDifferenceArrow;case"text":return _.annotationText;case"image":return _.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?_.annotationCalloutLabel:_.annotationCallout;default:return _.annotation}return _[e.target]},ay=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),iy=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),oy=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),sy=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),ly=e=>typeof e=="string"&&l.SOURCE_PARTS.includes(e),cy=e=>typeof e=="string"&&l.HEADING_PARTS.includes(e),uy=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),dy=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),py=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),my=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),hy=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],fy=e=>typeof e=="string"&&In.includes(e),gy=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!vr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=Fn({declarations:a.declarations,vocabulary:_s(o),tokens:t,location:`builtin[${i}]`,origin:s,warnings:r,entryTarget:"geom"});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:s})}),n},Bn=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},yy=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Bn(e,(a,i,o)=>{const s=a.select;if(s.target!=="geom"&&s.target!=="ruleLabel")return;const c=s.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},vy=(e,t)=>{const r=new Map(ws.flatMap(a=>t[xt[a]].map(i=>[i.id,a]))),n=[];return Bn(e,(a,i,o)=>{const s=a.select;if(s.target!=="annotation")return;const c=s.annotation;if(c===void 0||typeof c!="string")return;const u={param:"annotation",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(c);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown annotation '${c}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets sticker '${c}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=s.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets ${d} '${c}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},by=e=>{const t=[];return Bn(e,(r,n,a)=>{if(!vr(r))return;const i=r.when?.state;i===void 0||Os(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${l.STYLE_STATES.map(o=>`'${o}'`).join(", ")}.`})}),t},Os=e=>l.STYLE_STATES.includes(e),Sy=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Ms(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${xe(n)}.`,context:{param:"tokens",actual:xe(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ms=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,me=e=>typeof e=="number"&&Number.isFinite(e),ks=e=>{if(me(e)&&e>=0)return{top:e,right:e,bottom:e,left:e};if(typeof e!="object"||e===null)return;const t=e,r={};for(const n of l.PANEL_BORDER_EDGES){const a=t[n];if(a!==void 0){if(!me(a)||a<0)return;r[n]=a}}return r},xy=e=>{const t=ks(e);return t===void 0?void 0:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},Ay=e=>ks(e),xe=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Ns=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=vt(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((h,m)=>{if(!vr(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!Os(g))return;const v={list:d,index:m,...h.id===void 0?{}:{id:h.id}},y=h.when?.where;if(y!==void 0){const A=Ie(y,t.data,"style-rule");if(A.length>0){for(const T of A)o.push({...T,code:"INVALID_STYLE_RULE",message:`Style ${d}[${m}]: ${T.message}`,context:{...T.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const b=Fn({declarations:h.declarations,vocabulary:_s(f),tokens:s,location:`${d}[${m}]`,origin:v,warnings:o,entryTarget:"geom"});Object.keys(b).length!==0&&p.push({declarations:b,...y===void 0?{}:{matches:Ae(y,i)},...g===void 0?{}:{state:g},origin:v})}),p};return{defaults:[...gy(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},Fn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:o,entryTarget:s}=e,c={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(f,g)=>{c[f]=g},p=(f,g,v)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: expected ${g}, got ${xe(v)}.`,context:{param:f,expected:g,actual:xe(v),...u},suggestion:`Set '${f}' to ${g}.`})},h=(f,g)=>{if(typeof g=="string"){if(g.trim().length>0)return g;p(f,"a non-empty color string",g);return}if(l.isStyleTokenRef(g)){const v=n[g.token];if(v===void 0){o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: unknown token '${g.token}'.`,context:{param:f,actual:g.token,...u},suggestion:`Declare '${g.token}' in the stylesheet's tokens.`});return}return Ms(v)?typeof v=="string"?v:{light:v.light,dark:v.dark}:void 0}if(l.isLightDarkColor(g)&&g.light.trim().length>0&&g.dark.trim().length>0)return{light:g.light,dark:g.dark};p(f,"a non-empty color string, a { light, dark } pair, or a token(...) reference",g)},m=f=>{const g=Zg.has(f),v=ry(s,f),y=v===void 0?`Declare '${f}' on a target whose vocabulary carries it.`:`Declare '${f}' on an entry whose kind supports it (e.g. ${v}).`;o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: ${g?"not in this entry's vocabulary":"not a style property"}.`,context:{param:f,...u},suggestion:g?y:`Remove the unknown declaration '${f}'.`})};for(const f of Object.keys(t)){const g=t[f];if(g===void 0)continue;const v=r[f];if(v===void 0){m(f);continue}switch(v){case"color":{const y=h(f,g);y!==void 0&&d(f,y);break}case"unitInterval":me(g)&&g>=0&&g<=1?d(f,g):p(f,"a number in [0, 1]",g);break;case"pixels":me(g)&&g>=0?d(f,g):p(f,"a non-negative number of pixels",g);break;case"radiusToken":l.isBorderRadiusToken(g)?d(f,g):p(f,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,g);break;case"lineType":gn(g)?d(f,g):p(f,`one of ${fn.map(y=>`'${y}'`).join(", ")}`,g);break;case"fontFamily":typeof g=="string"&&g.trim().length>0?d(f,g):p(f,"a non-empty CSS font-family list",g);break;case"fontWeight":me(g)&&g>=oi&&g<=si?d(f,g):p(f,`a number in [${oi}, ${si}]`,g);break;case"multiplier":me(g)&&g>0?d(f,g):p(f,"a positive multiple of the font size",g);break;case"shadow":{if(g==="none"){d(f,g);break}const y=g;if(!me(y.offsetX)||!me(y.offsetY)||!me(y.blur)||y.blur<0){p(f,Xg,g);break}const b=h(f,y.color);b!==void 0&&d(f,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:b});break}case"padding":{const y=xy(g);y===void 0?p(f,li,g):d(f,y);break}case"margin":{const y=Ay(g);y===void 0?p(f,li,g):d(f,y);break}default:break}}return c},Iy=({layer:e})=>{if(e.position==="stack")return;const t=l.extractVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];l.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Ty=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=l.extractVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const n=s=>t==="y"?s.xMax:s.yMax,a=s=>t==="y"?s.xMin:s.yMin,i=new Map;for(const s of e.data){const c=s[r],u=G(s),d=F(s),p=j(s),h=X(s),m=hn(s);if(!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(h)||!l.isDefined(m))continue;const f=m>=0;if(Math.abs(m)===0)continue;const g=Cn(s,r),v={xMin:p,xMax:h,yMin:u,yMax:d},y=i.get(g);if(y===void 0){i.set(g,{total:m,topPositive:f?v:null,bottomNegative:f?null:v});continue}y.total+=m,f?(y.topPositive===null||n(v)>n(y.topPositive))&&(y.topPositive=v):(y.bottomNegative===null||a(v)<a(y.bottomNegative))&&(y.bottomNegative=v)}const o=[];for(const[s,c]of i){const u=c.topPositive??c.bottomNegative;u!==null&&o.push({xKey:s,total:c.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:c.topPositive!==null?"positive":"negative"}})}return o},Ly=class extends Fe{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=t.coordSystem.type==="cartesian"?t.coordSystem.mainAxis:"x";if(r.summaries.stackTotals){const i=Ty({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=Iy({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Bs=class extends l.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)}},ui={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Ey=["color","size","alpha","strokeWidth","lineType"],wy=class extends Fe{dependencies(e){return Ey.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const o=l.extractConstantValue(e.mapping[a]);if(o!==void 0){r=r.addConstantVariable(i,ui[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,ui[a],Ry(c)))}return{...e,data:r}}},Ry=e=>t=>l.isDefined(t)?e.map(t):null;function Fs(e=new fr){return{diagnostics:new Mg,geomRegistry:e}}var $s=class{constructor(e,t,r,n,a,i,o,s,c,u,d,p,h,m,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=o,this.coordCompiler=s,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=p,this.stylesCompiler=h,this.chromeStylesCompiler=m,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},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:"summarise",getStats:()=>this.summariseCompiler.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}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??di})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??di;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,R(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=On(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return R(t,{scales:Be(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=yr(r,a);return t.coords.coordType==="polar"?Mn(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,compiled: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:[wo(e)],warnings:t.warnings}}trackCompile(e){if(!l.IS_DEV)return e();const t=this.getCacheStats(),r=performance.now(),n=e(),a=performance.now()-r,i={};for(const{name:o,getStats:s}of this.stages){const c=s();i[o]={hits:c.hits-t[o].hits,misses:c.misses-t[o].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e,colorScheme:t}){return{...ur({spec:e}).pipe(({spec:r})=>({spec:R(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:R(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.summariseCompiler.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})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,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}}},Cy=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],di="light",Vy=({plugins:e=[]}={})=>{const t=us(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=bf(t),i=Fs(r),o=new ig(i),s=new Bs(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new $s(i,new l.DataCompiler,new Es(i),s,new Wp,new Gh(i,s,n,new Mh(i,s,new Kg(n),new fm,new hm(i),new Af(new Cf))),new Uf(i,o),new Yp(new cm),new Gf(i),new wy,new Eh(i),new Ly(i),new jg(i),new ty(i),new Vh(i),new Vp(i))};function Gs(e,t){return e.geom===t}function Us(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Dy(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>Ws(o,s),i)}function Hs(e,...t){return t.reduce((r,n)=>Ws(r,n),e)}function Dy(e){return typeof e=="object"&&e!==null&&"type"in e}function Ws(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:(0,jt.default)({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};case"highlight":return{...e,highlights:[...e.highlights,t]};case"styles":return{...e,styles:e.styles===void 0?t:{...t,extends:[e.styles,...t.extends??[]]}};case"annotation":return _y(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function _y(e,t){const r={...e.annotations};switch(t.kind){case"differenceArrow":r.differenceArrows=[...r.differenceArrows??[],t.annotation];break;case"shape":r.shapes=[...r.shapes??[],t.annotation];break;case"arrow":r.arrows=[...r.arrows??[],t.annotation];break;case"text":r.textAnnotations=[...r.textAnnotations??[],t.annotation];break;case"image":r.images=[...r.images??[],t.annotation];break;case"sticker":r.stickers=[...r.stickers??[],t.annotation];break;case"pinnedNumber":r.pinnedNumbers=[...r.pinnedNumbers??[],t.annotation];break;case"comment":r.comments=[...r.comments??[],t.annotation];break;default:throw new Error(`Unknown annotation kind: ${t.kind}`)}return{...e,annotations:r}}function Py(e){const t=e?.plugins??[],r=My(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Us,pipe:Hs,plugins:t}}var Oy=e=>(t={})=>l.buildLayerInput(e,t);function My(e){const{geoms:t,stats:r,transforms:n}=us(e),a={};for(const s of t)a[s.type]=Oy(s.type);const i={};for(const s of r)i[s.type]=()=>({type:s.type});const o={};for(const s of n)o[s.transformType]=c=>({type:"transform",transformType:s.transformType,options:c?.options});return{geom:a,stat:i,transform:o}}var Pr="…",Ks=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Pr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Pr)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Pr};var Y={timeZone:"UTC"},K=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},we=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",$n=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ky=Wr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),zs=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>we(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Hn(a,i),{base:s,suffix:c}=Un(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),Ys=({locale:e,numberFormat:t,intlOptions:r})=>we(n=>{const{base:a,suffix:i}=Un(n,t.abbreviation),o={...Hn(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),Gn=e=>we(t=>ky(t)),qs=({locale:e,intlOptions:t})=>we(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),js=({locale:e,numberFormat:t,intlOptions:r})=>we(n=>{const a=Hn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Un=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Ny(e);return Un(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Hn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},Ny=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},By=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).format(r)),Fy=({locale:e,intlOptions:t})=>K(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...Y,...t}).formatToParts(r);return $y(n.map(Gy))}),Xs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t}).format(r)),Zs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"long",...Y,...t}).format(r)),Wn=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...Y,...t}).format(r)),Kn=e=>K(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Js=({locale:e,intlOptions:t})=>K(r=>{const n=(0,fo.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t,year:void 0}).formatRange(r,n)}),Qs=({locale:e,intlOptions:t})=>K(r=>{const n=(0,fo.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).formatRange(r,n)}),zn=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{year:"numeric",...Y,...t}).format(r)),el=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),$y=e=>e.map(t=>t.value).join(""),Gy=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},pi=1e3,Uy=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>we(a=>{const i={...qn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Yn(a,t,i)}),Hy=({locale:e,tickValues:t,intlOptions:r})=>we(n=>{const a={...qn(n,t),notation:"compact",...r};return Yn(n,e,a)}),Wy=({locale:e,tickValues:t,intlOptions:r})=>we(n=>{const a={...qn(n,t),notation:"compact",...r,style:"percent"};return Yn(n,e,a)}),Yn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),tl=e=>Math.abs(e)>pi?tl(e/pi):Number.isInteger(e),Ky=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},qn=(e,t)=>tl(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Ky(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},zy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Yy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",...Y,...t}).format(r)),qy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),jy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),jn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Uy(e);case"date":case"datetime":return zy(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return qy(e);case"decimal":case"integer":return Hy(e);case"duration":return Gn(e);case"month":return Yy(e);case"month_year":return Wn(e);case"percentage":return Wy(e);case"quarter":return Kn(e);case"text":return $n(e);case"time":return jy(e);case"year":return zn(e);case"lookup":return jn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Xy=.9,Zy=1/3,Jy=1/4,Qy=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?ev(e):tv(e),ev=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=rl(e.ticks,n),s=rv(e.ticks,r.width),c=s*Xy;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Qr(c);return{...e,ticks:Jr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Qr(r.height*Zy);return{...e,ticks:Jr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},tv=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=rl(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Qr(r.width*Jy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Jr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},rv=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},rl=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},Jr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Ks(i.formattedLabel,r,a)})},Qr=e=>Math.max(0,Math.floor(e)),nv=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let o=r-(e.length-1)*i;for(const s of e){const{width:c,height:u}=n(s);if(o-=a?c:u,o<0)return!1}return!0},av=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const h=o.get(p);if(h)return h;const m=a[p],f=m?iv(m.ticks,n(m)):[];return o.set(p,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1;nv(s(p).map(h=>h.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},iv=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),mi=.5,Tt=e=>({x:0,y:0,width:e.width,height:e.height}),Xn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,Lt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:o,alignOffset:s,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",p=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:sv(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},m={anchor:lv(i),placement:p?n:"inside",offset:p?s??o:0},f=d?t:e,g=r.valueAxis==="x"?f:e,v=r.valueAxis==="y"?f:e,y=r.valueAxis==="x"?h:m,b=r.valueAxis==="x"?m:h,A=fi(y,{min:g.x,max:g.x+g.width,halfExtent:c/2}),T=fi(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:A,y:T,position:ov(e,A,T,c,u)}},hi=(e,t,r,n)=>r-n>=e-mi&&r+n<=t+mi,ov=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||hi(e.x,e.x+e.width,t,n/2),o=e.height===0||hi(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},sv=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",lv=e=>e==="center"?"center":e==="start"?"min":"max",fi=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const o=r+i;return e==="min"?t==="inside"?n+o:n-o:t==="inside"?a-o:a+o},cv=(e,t,r,n,a)=>{const i=t??e,o=1-Math.max(e,i);return{box:{x:r*n,y:o*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},uv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=pv(e.layer);for(const a of e.layer.data){const i=M(a),o=F(a)??D(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),{box:d,frame:p}=cv(o,G(a),i,e.panelRect.width,e.panelRect.height),h=Lt({box:d,panel:Tt(e.panelRect),frame:p,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return{labels:t,droppedCount:0}},dv={place:uv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":U(e.position)?"stack":"none"},pv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:pr(e.data,e.mapping)?Xn(r):r,align:n}};function Et(e){return e[l.VISUAL_VARIABLES.color]}function nl(e){return e[l.VISUAL_VARIABLES.alpha]}function Zn(e){return e[l.VISUAL_VARIABLES.size]}function en(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function al(e){return e[l.VISUAL_VARIABLES.lineType]}var mv={color:Et,alpha:nl,strokeWidth:en,lineType:al,size:Zn,borderWidth:en},st=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:s=>{const c=r.get(s);if(c!==void 0)return c;const u=fv(s.styles,t);return r.set(s,u),u},chromeReaders:s=>{const c=n.get(s);if(c!==void 0)return c;const u=hv(s,t);return n.set(s,u),u},explain:(s,c,u,d)=>{if(d!==void 0){const f=ut(s.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=ut(s.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const p=ut(s.styles.overrides,c,u,void 0,t);if(p!==void 0)return{value:p.value,tier:"override",origin:p.origin};const h=il(c,u);if(h!==void 0)return{value:h,tier:"data"};const m=ut(s.styles.defaults,c,u,void 0,t);return m!==void 0?{value:m.value,tier:"default",origin:m.origin}:{value:void 0,tier:"unresolved"}}}},hv=(e,t)=>{const r=(v,y)=>{const b=w=>gi(v.overrides,w,y)??gi(v.defaults,w,y);return{get:w=>{const C=b(w)?.declarations[w];if(C!==void 0)return Or(C,t)},getSource:w=>{const C=b(w);return C===void 0?"unresolved":C.origin.list==="builtin"?"builtin":"authored"},explain:w=>{const C=b(w),I=C?.declarations[w];return C===void 0||I===void 0?{value:void 0,source:"unresolved"}:{value:Or(I,t),source:C.origin.list==="builtin"?"builtin":"authored",origin:C.origin,select:C.select}},collectAll:w=>{const C=[];for(const I of[v.defaults,v.overrides])for(const V of I){if(!y(V))continue;const O=V.declarations[w];O!==void 0&&C.push(Or(O,t))}return C}}},n=(v,y)=>{const b="edge"in v.select?v.select.edge:void 0;return b===void 0||b===y},a=v=>r(e.panelBorder,y=>n(y,v)),i=v=>r(e.legend,y=>y.select.target!=="legend"||y.select.part!==void 0?!1:n(y,v)),o=v=>(y,b)=>r(e[v],A=>A.select.target!==v||A.select.axis!==void 0&&A.select.axis!==y?!1:n(A,b)),s=v=>r(e.ruleLabel,y=>y.select.target!=="ruleLabel"?!1:y.select.layer===void 0||y.select.layer===v),c=(v,y)=>r(e.dataLabel,b=>b.select.target!=="dataLabel"||b.select.role!==void 0&&b.select.role!==v?!1:b.select.position===void 0||b.select.position===y),u=v=>r(e.tooltip,y=>y.select.target==="tooltip"&&y.select.part===v),d=v=>r(e.source,y=>y.select.target==="source"&&y.select.part===v),p=v=>r(e.heading,y=>y.select.target!=="heading"?!1:y.select.part===void 0||y.select.part===v),h=v=>r(e.legend,y=>y.select.target==="legend"&&y.select.part===v),m=v=>r(e.legendItem,y=>y.select.target==="legendItem"&&y.select.part===v),f=v=>r(e.headlineItem,y=>y.select.target==="headlineItem"&&y.select.part===v),g=(v,y)=>{const b=new Map;return A=>{const T=b.get(A);if(T!==void 0)return T;const L=r(e.annotation,E=>{if(E.select.target!=="annotation")return!1;const w=E.select.kind;return w!==void 0&&w!==v||E.select.part!==y?!1:E.select.annotation===void 0||E.select.annotation===A});return b.set(A,L),L}};return{panelBorder:a,gridLine:o("gridLine"),tickLine:o("tickLine"),axisLabel:o("axisLabel"),tickLabel:o("tickLabel"),ruleLabel:s,dataLabel:c,graph:r(e.graph,()=>!0),heading:{h1:p("h1"),h2:p("h2")},caption:r(e.caption,()=>!0),source:{label:d(void 0),link:d("link")},header:r(e.header,()=>!0),footer:r(e.footer,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:u(void 0),heading:u("heading"),label:u("label"),value:u("value"),primaryRow:u("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:f("number"),numberCenter:f("numberCenter"),caption:f("caption"),label:f("label"),swatch:f("swatch"),trend:f("trend"),trendUp:f("trendUp"),trendDown:f("trendDown"),trendFlat:f("trendFlat")},legend:Object.assign(i,{popover:h("popover")}),legendItem:{item:m(void 0),swatch:m("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:g("shape"),arrow:g("arrow"),differenceArrow:Object.assign(g("differenceArrow"),{label:g("differenceArrow","label")}),text:g("text"),image:g("image"),pinnedNumber:Object.assign(g("pinnedNumber"),{label:g("pinnedNumber","label")}),comment:Object.assign(g("comment"),{label:g("comment","label")})}}},gi=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const a=e[n];if(!(a===void 0||!r(a))&&a.declarations[t]!==void 0)return a}},Or=(e,t)=>{if(l.isLightDarkColor(e))return e[t];if(typeof e=="object"&&"offsetX"in e){const{offsetX:r,offsetY:n,blur:a,color:i}=e;return{offsetX:r,offsetY:n,blur:a,color:l.isLightDarkColor(i)?i[t]:i}}return e},fv=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=Ft(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=Ft(e.defaults,n,a,i,t);if(u!==void 0)return u}const o=Ft(e.overrides,n,a,void 0,t);if(o!==void 0)return o;const s=il(n,a);return s!==void 0?s:Ft(e.defaults,n,a,void 0,t)}}),Ft=(e,t,r,n,a)=>ut(e,t,r,n,a)?.value,ut=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const o=e[i];if(o===void 0||o.state!==n)continue;const s=o.declarations[t];if(s!==void 0&&gv(o,r))return{value:yv(s,a),origin:o.origin}}},gv=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),yv=(e,t)=>l.isLightDarkColor(e)?e[t]:e,il=(e,t)=>{const r=mv[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Jn=(e,t,r)=>{const n={},a=i=>{const o=n[i];if(o!==void 0)return o;const{width:s,height:c}=e(t,i,r),u={width:s,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},$t=6,vv=.5,bv=e=>{const t=[];let r=0;const n=U(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=xv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:a});for(const s of i){const c=e.layer.dataLabels.position==="auto"?Tv({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Ev(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,Tt(e.panelRect));if(c===null){r+=1;continue}const u=s.boxes[c.position];t.push({layerId:e.layer.id,x:c.x,y:c.y,text:s.text,width:u.width,height:u.height,isRotated:c.isRotated,target:"observation",position:c.position,...c.position==="inside"?{backdropColor:s.backdropColor}:{}})}}if(e.layer.dataLabels.showCategoryLabels)for(const i of wv(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=Dv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of i)t.push(o)}return{labels:t,droppedCount:r}},Sv={place:bv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":U(e.position)?"stack":"absoluteGrandTotal"},xv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const o=[];let s=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y),d=st().geomReaders(e);for(const p of e.data){const h=sl(t,p);if(h===null)continue;const m=a(p);if(m==="")continue;const f=Jn(n,"observation",m),g=Qn(h,r);c&&f.inside.width>g.width&&(s=!0);const v=u===null?null:p[u],y=l.isStrictNumericDataValue(v)&&v<0;o.push({isNegative:y,text:m,boxes:f,bounds:g,backdropColor:d.get("color",p)})}return{entries:o,shouldRotate:!i&&s}},Qn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),ol=(e,t,r,n,a)=>{if(e==="x"){let s=1-a,c=a-n;return c<0&&(s+=c,c=-c),{x:t,y:s,width:r-t,height:c}}let i=t,o=r-t;return o<0&&(i+=o,o=-o),{x:i,y:1-a,width:o,height:a-n}},sl=(e,t)=>{const r=j(t),n=X(t),a=G(t),i=F(t)??D(t);return r===null||n===null||a===null||i===null?null:ol(e,r,n,a,i)},Av=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return ol(e,r,n,a,i)},Iv=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",tn=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Tv=e=>e.isStacked?Rv({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Vv({edge:Iv(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),ll=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Lv=e=>e==="panel-start"||e==="panel-end",Ev=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,o=n.boxes[i],s=Lt({box:n.bounds,panel:a,frame:ll(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!Lv(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+vv?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},wv=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:o}=e.layer.dataLabels,s=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=Tt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const h=sl(c,p);if(h===null)continue;const m=e.formatCategory(p);if(m===null||m==="")continue;const f=Jn(e.measureDataLabel,"category",m),g=f[s],v=Qn(h,e.panelRect),y=d===null?null:p[d],b=l.isStrictNumericDataValue(y)&&y<0,A=Lt({box:v,panel:u,frame:ll(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:g.width,labelHeight:g.height}),T=f[A.position];r.push({layerId:e.layer.id,x:A.x,y:A.y,text:m,width:T.width,height:T.height,isRotated:!1,target:"category",position:A.position})}return r},Rv=({bounds:e,box:t,isRotated:r})=>{const n=tn(t.width,t.height,r);return n.width>e.width||n.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},Cv=(e,t,r,n)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:n};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:n};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:r};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:r}}},Vv=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:o})=>{const s=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=s?t.height:t.width,p=s?t.width:t.height,{edgeCoord:h,outwardSign:m,panelExtent:f}=Cv(e,t,a,i),g=tn(r.inside.width,r.inside.height,n),v=s?g.height:g.width,y=s?g.width:g.height,b=v+o<d,A=y<=p;if(s?b:b&&A){if(s&&!A)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const w=h-m*(v/2+o);return{...s?{x:c,y:w}:{x:w,y:u},isRotated:!1,position:"inside"}}const T=tn(r.outside.width,r.outside.height,n),L=(s?T.height:T.width)/2,E=h+m*(L+o);return E-L<0||E+L>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Dv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],o=e.summary.stackTotals;if(o===void 0||o.length===0)return i;const s=t==="y";for(const c of o){const u=Qn(Av(t,c),r),d=a(c.total),{width:p,height:h}=n("aggregate","outside",d),m=c.anchor.direction==="positive";let f,g;s?(f=m?u.x+u.width+$t+p/2:u.x-$t-p/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=m?u.y-$t-h/2:u.y+u.height+$t+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:p,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},_v=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Ov(e.layer);for(const a of e.layer.data){const i=M(a),o=D(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=Lt({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:Tt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return{labels:t,droppedCount:0}},Pv={place:_v,getPercentageValueStrategy:()=>"none"},Ov=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:pr(e.data,e.mapping)?Xn(r):r,align:n}},Mv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Nv(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=st().geomReaders(e.layer);for(const o of e.layer.data){const s=M(o),c=D(o);if(s===null||c===null||!tt(s,c))continue;const u=e.formatLabel(o);if(u==="")continue;const{width:d,height:p}=e.measureDataLabel("observation","outside",u),h=i.get("size",o)/2,m=Lt({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:Tt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:p});t.push({layerId:e.layer.id,x:m.x,y:m.y,text:u,width:d,height:p,isRotated:!1,target:"observation",position:m.position})}return{labels:t,droppedCount:0}},kv={place:Mv,getPercentageValueStrategy:()=>"none"},Nv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:r,align:n}},cl=e=>{const t=j(e),r=X(e),n=G(e),a=F(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),o=Math.abs(r-t),s=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-s,width:o,height:c}},ul=e=>{const t=cl(e);if(!t)return null;const r=t.width*Kh,n=t.height*zh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},yi=4,Bv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=st().geomReaders(e.layer);for(const n of e.layer.data){const a=ul(n);if(a===null||!Et(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:o,height:s}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;o+yi>c||s+yi>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:o,height:s,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return{labels:t,droppedCount:0}},Fv={place:Bv,getPercentageValueStrategy:()=>"none"};function ea(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function ta(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var $v=" · ",Mr=2,mt=(e,t,r,n)=>{const a=Math.abs(e==="radial"?Math.sin(t):Math.cos(t)),i=Math.abs(e==="radial"?Math.cos(t):Math.sin(t));return a*(r/2)+i*(n/2)},Gv=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=mt("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Mr&&t+i<=e.outerRadiusPx+Mr)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=mt("tangential",r,n,a)/t,c=Mr/t;return Math.abs(r-e.midAngle)+s<=o+c},Uv=({x:e,y:t,labelWidth:r,labelHeight:n,panelRect:a})=>e-r/2>=0&&e+r/2<=a.width&&t-n/2>=0&&t+n/2<=a.height,vi=({wedge:e,position:t,offset:r,labelWidth:n,labelHeight:a})=>t==="inside"?{labelRadius:(e.innerRadiusPx+e.outerRadiusPx)/2,labelAngle:e.midAngle,position:"inside"}:{labelRadius:e.outerRadiusPx+r+mt("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},Hv=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:o})=>{const s=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+mt("radial",s,i,o);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const p=e.innerRadiusPx-c;u=p>=0?p:e.innerRadiusPx+c}let d=s;if(n!=="center"&&u>0){const p=mt("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:Gv({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},Wv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{position:r,justify:n,align:a,offset:i,showCategoryLabels:o}=e.layer.dataLabels,s=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2,p=st().geomReaders(e.layer);for(const h of e.layer.data){const{startAngle:m,endAngle:f}=ea(h),{innerRadius:g,outerRadius:v}=ta(h);if(m===null||f===null||v===null)continue;const y=e.formatLabel(h);if(y==="")continue;const b=o?e.formatCategory(h):null,A=b===null?y:`${b}${$v}${y}`,T={startAngle:m,endAngle:f,midAngle:(m+f)/2,innerRadiusPx:(g??0)*d,outerRadiusPx:v*d};let L,E;if(r==="auto"){const I=e.measureDataLabel("observation",s,A);E={width:I.width,height:I.height},L=vi({wedge:T,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const V=c+Math.sin(L.labelAngle)*L.labelRadius,O=u-Math.cos(L.labelAngle)*L.labelRadius;if(L.position==="outside"&&!Uv({x:V,y:O,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const ie=e.measureDataLabel("observation","inside",A);E={width:ie.width,height:ie.height},L=vi({wedge:T,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const I=Jn(e.measureDataLabel,"observation",A),V=I[r];L=Hv({wedge:T,placement:r,justify:Xn(n),align:a,offset:i,labelWidth:V.width,labelHeight:V.height}),E=I[L.position]}const w=c+Math.sin(L.labelAngle)*L.labelRadius,C=u-Math.cos(L.labelAngle)*L.labelRadius;t.push({layerId:e.layer.id,x:w,y:C,text:A,width:E.width,height:E.height,isRotated:!1,target:"observation",position:L.position,...L.position==="inside"?{backdropColor:p.get("color",h)}:{}})}return{labels:t,droppedCount:0}},Kv={place:Wv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},zv=e=>{const t=k({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=k({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},k=e=>{switch(e.valueFormat.type){case"currency":return zs(e);case"date":return By(e);case"datetime":return Fy(e);case"day_month":return Xs(e);case"decimal":return Ys(e);case"duration":return Gn(e);case"integer":return qs(e);case"month":return Zs(e);case"month_year":return Wn(e);case"percentage":return js(e);case"quarter":return Kn(e);case"text":return $n(e);case"weekly_date_range":return Js(e);case"weekly_date_range_with_year":return Qs(e);case"year":return zn(e);case"time":return el(e);case"lookup":return zv({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function ra({layer:e,numberFormat:t,locale:r}){return k({valueFormat:fp(e),locale:r,numberFormat:t})}var Yv=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:ot(e,t),variable:r}:{read:re,variable:l.GROUP_VARIABLES.group}},dl=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=ra({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Jv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:qv({layer:e,numberFormat:n,locale:o})}},qv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Yv(e.data,e.mapping),i=k({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},jv=(e,t,r)=>{switch(t){case"stack":return Xv(e);case"fill":return Zv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Xv=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(Cn(a,t));return s===void 0?null:s.total}},Zv=(e,t)=>{const r=t?j:G,n=t?X:F,a=gt(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Jv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=Q(e.data,e.dataLabels.labelSource),c=jv(e,i,o),u=Qv({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=k({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&pl(e);return h=>{const m=s(h);if(m===null)return"";if(!p||!l.isStrictNumericDataValue(m))return u(m,h);const f=c(h);return f===null||f===0?u(m,h):d(m/f)}},Qv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(pl(e))return a;const s=eb(e,r,t,n,o);if(s!==null)return s}return k({valueFormat:tb(e.data,i),locale:n,numberFormat:t})},pl=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(cr(e.position,e.mapping))},eb=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:k({valueFormat:o.valueFormat,locale:n,numberFormat:r})},tb=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},na={bar:{cartesian:Sv,polar:Kv},line:{cartesian:Pv},point:{cartesian:kv},area:{cartesian:dv},tile:{cartesian:Fv}},rb=(e,t)=>na[e]?.[t]!==void 0,nb=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:o,formattingLocale:s,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],p=s??a,h=t.type;let m=0;for(const f of e){if(!f.dataLabels.showDataLabels&&!f.dataLabels.showStackTotals&&!f.dataLabels.showCategoryLabels)continue;const g=f.geom,v=na[g]?.[h];if(v===void 0)continue;const y=dl({layer:f,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:o,formattingLocale:p,percentageValueStrategy:v.getPercentageValueStrategy(f)}),b=v.place(y);m+=b.droppedCount;for(const A of b.labels)ib(A,h,c,u)||d.push(A)}return{labels:d,warnings:m>0?[ab(m)]:[]}},ab=e=>({code:"DATA_LABELS_DROPPED",severity:"warning",kind:"user-input",message:e===1?"Dropped 1 data label that did not fit under position 'auto'.":`Dropped ${e} data labels that did not fit under position 'auto'.`,suggestion:"Set dataLabels.position to 'outside' to keep labels that do not fit inside the bars.",context:{actual:e}}),ib=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*ob({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:o}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const s of e){if(!s.dataLabels.showDataLabels&&!s.dataLabels.showStackTotals)continue;const c=na[s.geom]?.cartesian;if(c===void 0)continue;const u=dl({layer:s,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:c.getPercentageValueStrategy(s)});for(const d of c.place(u).labels)yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var kr={abbreviation:"none",decimals:"auto"},ml=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return k({valueFormat:a,locale:e,numberFormat:kr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/r;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":k({valueFormat:{type:"percentage"},locale:e,numberFormat:kr,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${k({valueFormat:{type:"decimal"},locale:e,numberFormat:kr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},sb=2,lb=6,cb=6,ub=15,db=15,pb=2.5,mb=.5,hb=.25,hl=e=>{const t=e-sb,r=1+mb*t,n=1+hb*t;return{arrowStartGap:lb*r,arrowEndGap:cb*r,offsetFromHigherObservation:ub*n,arrowheadSize:pb*e,curveRadius:db*n,strokeWidth:e}},fb=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},gb=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
2
2
  M ${o.x} ${o.y}
3
3
  L ${s.x} ${s.y+i}
4
4
  Q ${s.x} ${s.y} ${s.x+d*i} ${s.y}
@@ -20,4 +20,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Hd=Object
20
20
  M ${t.x-n} ${t.y-r-n}
21
21
  L ${t.x} ${t.y-r}
22
22
  L ${t.x+n} ${t.y-r-n}
23
- `,bb=(e,t,r,n,a,i=.5)=>e?{x:n,y:Math.min(t.y,r.y)+i*a}:{x:Math.min(t.x,r.x)+i*a,y:n},Sb=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),hl=({arrow:e,style:t,mainAxis:r,panelWidth:n,panelHeight:a,locale:i})=>{const o=r==="y",s={x:e.start.x*n,y:(1-e.start.y)*a},c={x:e.end.x*n,y:(1-e.end.y)*a},u=ml(t.strokeWidth),d=fb(o,s,c,u),p=(o?yb:gb)(s,c,d,u),h=vb(o,c,u),m=bb(o,s,c,d,Sb(o,s,c),e.labelCrossPosition),f=pl({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:s,end:c,linePath:p,arrowheadPath:h,labelPosition:m,labelText:f}},vi={large:1,medium:23/26,small:19/26},xb={large:1,medium:10/12,small:10/12},Ab=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],fl=e=>e.fontSize*e.lineHeight,Ib=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),N=(e,t)=>({fontFamily:e.get("fontFamily")??t.get("fontFamily"),fontSize:e.get("fontSize")*t.get("textScale"),fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),Tb=e=>N(e.heading.h1,e.graph),Lb=e=>N(e.heading.h2,e.graph),Eb=e=>N(e.caption,e.graph),wb=e=>({label:N(e.source.label,e.graph),link:N(e.source.link,e.graph)}),Rb=(e,t)=>N(e.axisLabel(t),e.graph),Cb=(e,t,r)=>{const n=e.tickLabel(t,r);return{...N(n,e.graph),offset:n.get("offset")}},Vb=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...N(n,e.graph),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock"),borderRadius:n.get("borderRadius"),isTextColorAuthored:n.getSource("textColor")==="authored",...a===void 0?{}:{background:a},...i===void 0?{}:{borderColor:i},...o===void 0?{}:{borderWidth:o}}},Db=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=N(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},_b=e=>{const t=e.tooltip.box,r=e.graph;return{box:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")},heading:N(e.tooltip.heading,r),label:N(e.tooltip.label,r),value:N(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},Pb=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...N(t,e.graph),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),borderRadius:t.get("borderRadius"),borderWidth:t.get("borderWidth"),...r===void 0?{}:{background:r},...n===void 0?{}:{borderColor:n}},swatch:{size:e.legendItem.swatch.get("size"),strokeWidth:e.legendItem.swatch.get("strokeWidth")}}},Ob=e=>{const t=e.directLabel;return{...N(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},Mb=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=vi[t]*n,i=xb[t]*n,o=e.headlineItem,s=N(o.number,e.graph),c={...s,fontSize:s.fontSize*vi[t]},u=o.numberCenter.get("fontSize");return{number:c,...Nb(o.numberCenter)?{numberCenter:Gt(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:Gt(o.caption,o.caption.get("fontSize")*i,r),label:Gt(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:Gt(o.trend,o.trend.get("fontSize")*i,r),trendUp:{textColor:o.trendUp.get("textColor")},trendDown:{textColor:o.trendDown.get("textColor")},trendFlat:{textColor:o.trendFlat.get("textColor")}}},kb=(e,t)=>{const r=t?e.numberCenter:void 0;return r===void 0?e.number:{fontFamily:r.fontFamily??e.number.fontFamily,fontSize:r.fontSize,fontWeight:r.fontWeight??e.number.fontWeight,lineHeight:r.lineHeight??e.number.lineHeight,textColor:r.textColor??e.number.textColor}},Nb=e=>Ab.some(t=>e.getSource(t)!=="unresolved"),Gt=(e,t,r)=>{const n=e.get("fontFamily")??r,a=e.get("fontWeight"),i=e.get("lineHeight"),o=e.get("textColor");return{fontSize:t,...n===void 0?{}:{fontFamily:n},...a===void 0?{}:{fontWeight:a},...i===void 0?{}:{lineHeight:i},...o===void 0?{}:{textColor:o}}},gl=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=fl(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*Bb({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!et(o.start.x,o.start.y)||!et(o.end.x,o.end.y))continue;const s=a(o.id),c=hl({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=gl({labelPosition:c.labelPosition,measuredTextWidth:i(c.labelText,s.label).width,label:s.label});yield{...u,x:r.x+u.x,y:r.y+u.y}}}var Fb=e=>{const t=e.padding,r=bi(e.rows,t?.top??0,t?.bottom??0),n=bi(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:Hb(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},$b=e=>{const t=Si(e.rows,e.height),r=Si(e.cols,e.width),n=xi(t),a=xi(r),i=new Map;for(const o of e.placements){const s=o.rowSpan??1,c=o.colSpan??1,u=a[o.col]??0,d=n[o.row]??0,p=Ai(r,o.col,c),h=Ai(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,h)})}return i},bi=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;rn(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push(Gb(s));const c=Ub(e,o);if(rn(s)&&c){const u=s.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},Gb=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},rn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ub=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&rn(n))return n}},Hb=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),o=r.get(a.col);if(i===void 0||o===void 0)continue;const s=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):o;s===void 0||c===void 0||n.push({name:a.name,row:i,col:o,rowSpan:Math.max(1,s-i+1),colSpan:Math.max(1,c-o+1)})}return n},Si=(e,t)=>{let r=0,n=0;for(const i of e)i.type==="fixed"?r+=i.pixels:n+=i.weight;const a=Math.max(0,t-r);return e.map(i=>i.type==="fixed"?i.pixels:n===0?0:i.weight/n*a)},xi=e=>{const t=new Array(e.length);let r=0;for(let n=0;n<e.length;n++)t[n]=r,r+=e[n]??0;return t},Ai=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},rt={top:0,right:0,bottom:0,left:0},yl={outer:rt,inner:rt},Wb=(e,t,r,n=rt,a=yl,i=l.DEFAULT_GRAPH_PADDING_EDGES,o)=>{const s={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=[{name:"header",size:t.headerSize.height,gaps:de(o.header)},{name:"topLegend",size:r.legends.top,gaps:de(o.legend.top)},{name:"headline",size:r.headline,gaps:de(o.headline)},{name:"topAxisLabel",size:c,gaps:de(o.axisLabel.top)},{name:"topAxis",size:r.axes.top,gaps:de(o.tickLabel.top)},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:s.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:s.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:de(o.tickLabel.bottom)},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:de(o.axisLabel.bottom)},{name:"bottomLegend",size:r.legends.bottom,gaps:de(o.legend.bottom)},{name:"footer",size:t.footerSize.height,gaps:de(o.footer)}],d=[{name:"leftLegend",size:r.legends.left,gaps:Ut(o.legend.left)},{name:"leftAxis",size:r.axes.left,gaps:Ut(o.tickLabel.left)},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:s.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:s.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:Ut(o.tickLabel.right)},{name:"rightLegend",size:r.legends.right,gaps:Ut(o.legend.right)}],p=Ii(u,i.top,i.bottom),h=Ii(d,i.left,i.right);return Fb({rows:u,cols:d,placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...zb(r.axes),...Yb(r.axesLabels,r.axes),...qb(r.legends)],containerSize:e,padding:{top:p.start,bottom:p.end,left:h.start,right:h.end}})},de=e=>({before:e.top,after:e.bottom}),Ut=e=>({before:e.left,after:e.right}),Kb=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ii=(e,t,r)=>{const n=e.filter(Kb),a=n[0],i=n[n.length-1];return{start:t+(a?.gaps?.before??0),end:r+(i?.gaps?.after??0)}},zb=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Yb=(e,t)=>{const r=[];return e.top>0||t.top>0?(e.top>0&&r.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&r.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&r.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&r.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),r},qb=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t};var jb=class{constructor(e){this.outer={...rt},this.inner={...rt},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},Xb=["top","right","bottom","left"],Nr=(e,t)=>{const r={};for(const n of Xb){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function Ti(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var nn=["large","medium","small"],Zb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of nn)if(r(n)<=t)return n;return"small"},Jb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:nn.indexOf(e);for(const a of nn.slice(n))if(r(a)<=t)return a;return null},Qb=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const o=a===0?i:n+t+i;if(o>r)break;n=o,a+=1}return a},eS=({headline:e,containerSize:t,measurer:r})=>{if(vr(e))return 0;const n=vl(e,t.width,r);return r.measureHeadline(e.formatted,n).height},tS=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(vr(e)){const s=rS(t.panel,e.innerRadius),c=Jb({size:e.size,availableWidth:s.width,measureStripWidth:bl(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=vl(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=Qb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},vr=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,rS=(e,t)=>{const r=t*(Math.min(e.width,e.height)/2)*Math.SQRT2,n=e.x+e.width/2,a=e.y+e.height/2;return{x:n-r/2,y:a-r/2,width:r,height:r}},vl=(e,t,r)=>Zb({size:e.size,availableWidth:t,measureStripWidth:bl(e,r)}),bl=(e,t)=>r=>t.measureHeadline(e.formatted,r,vr(e)).width,Ye={x:0,y:0,width:0,height:0},nS={top:0,right:0,bottom:0,left:0},aS="0000",iS=3,oS=e=>e.plot.y+e.plot.height-e.panel.y,sS=class{constructor(e){this.measurer=e}compile(e){return cr({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:yl,panelBorder:e.panelBorder??rt,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,margins:e.margins}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:lS(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Li(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Li(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:oS(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new jb(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of Bb({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,locale:r,resolveStyle:e.resolveDifferenceArrowStyle,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(o,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const o of ob({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(o,e.overflowStrategy.dataLabels);const i=a.resolve();return Ti(i.inner,n.inner)&&Ti(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p}){let h=t,m=o;for(let f=0;f<iS;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,m);if(g===m)break;m=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:s,headline:c,padding:d,margins:p})}return h}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,o=a.height-n.vertical*2;return i<=0||o<=0?Ei(r,a,0,0):Ei(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=H(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const o=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,o.width),a=Math.max(a,o.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:aS}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=H(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=av({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:s,...c}=e,u={...c,ticks:o,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?Qy({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:o,padding:s,margins:c}){const u=$b(Wb(r,n,this.measureGuides(e,t,o,r),i,a,s,cS(c,t)));return{header:u.get("header")??Ye,headline:u.get("headline")??Ye,footer:u.get("footer")??Ye,plot:u.get("plot")??Ye,panelFrame:u.get("panelFrame")??Ye,panel:u.get("panel")??Ye,axes:Nr(u,"Axis"),axisLabels:Nr(u,"AxisLabel"),legends:Nr(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const s of e)s.isVisible&&s.geometry==="linear"&&(a[s.position]=this.measurer.measureAxis(s),s.label!==null&&(i[s.position]=this.measurer.measureAxisLabel(s)));const o={top:0,right:0,bottom:0,left:0};for(const s of t)o[s.position]=this.measurer.measureLegend(s);return{axes:a,axesLabels:i,legends:o,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:eS({headline:e,containerSize:t,measurer:this.measurer})}},Li=e=>e==="left"||e==="right",Ei=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,o=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-o)/2,y:t.y+n+(i-o)/2,width:o,height:o}}},lS=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(o=>o.value)),a=new WeakMap;return i=>{const o=a.get(i);if(o)return o;const s=jn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},cS=(e,t)=>{const r={...e.legend};for(const n of t)n.display==="direct"&&(r[n.position]=nS);return{...e,legend:r}},uS=(e=[])=>{const t=dS(e);return{resolve:(r,n,a)=>{if(!t.has(r))return null;const i=t.get(r).resolveAnchorPosition?.(n,a)??null;return i===null?null:{...i,frame:Sn(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?Do(r,t.get(r.geom)):null}},dS=e=>{const t=new hr;for(const r of e){const n=_n(r);n instanceof ye&&t.register(n.type,n)}return t};function pS(e){return e}function ce(e){return 1-e}var De=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,tr=(e,t)=>{const r=ur(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+ce(e.y)*r.height}},mS=(e,t)=>{const r=ur(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(ce(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},hS=class{constructor(e,t,r){this.annotations=e,this.panelRect=t,this.measuredBoxes=r,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const i=this.toPanelPoint(e),{x:o,y:s}=an(e.defer,this.panelRect);return Ci({...e,x:i.x+o,y:i.y-s})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=ft(t,e.defer.align),{x:n,y:a}=fS(r,e.defer.offset,this.panelRect);return{x:n,y:a}}resolveRegion(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const a=this.toPanelRegion(e),{x:i,y:o}=an(e.defer,this.panelRect);return Ci({...e,x:a.x-i,y:a.y-o,width:Math.max(0,a.width+2*i),height:Math.max(0,a.height+2*o)})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=t.xMax-t.xMin,n=t.yMax-t.yMin;return r<=0||n<=0?null:{x:t.xMin,y:t.yMin,width:r,height:n}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:gS(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:wi(this.toPanelPoint(r),this.toPanelPoint(n))}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=this.toPanelPoint(r),i=t.annotation.width,o=n.height/this.panelRect.height,s=So(t.annotation.align),c=a.x-s.x*i,u=a.y+(1-s.y)*o;return{xMin:c,xMax:c+i,yMin:u-o,yMax:u}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Ri(this.toPanelPoint(r))}case"differenceArrow":return wi(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return Ri(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Ga(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Ga(e,this.panelRect),r=ur(e.frame,this.panelRect);return{...t,width:this.panelRect.width>0?e.width*r.width/this.panelRect.width:0,height:this.panelRect.height>0?e.height*r.height/this.panelRect.height:0}}},an=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),fS=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:o}=an({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-o}}return{x:e.x+n,y:e.y-a}},gS=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),wi=(e,t)=>({xMin:Math.min(e.x,t.x),xMax:Math.max(e.x,t.x),yMin:Math.min(e.y,t.y),yMax:Math.max(e.y,t.y)}),Ri=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),Ci=e=>{const t={...e};return delete t.defer,delete t.frame,t},yS=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!vS(t))return t;const o=new hS(t,r,n),s={...t,shapes:lt(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:lt(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:lt(t.arrows,d=>d.start.defer!==void 0||d.end.defer!==void 0,d=>{const p=o.resolvePoint(d.start),h=o.resolvePoint(d.end);return p===null||h===null?null:{...d,start:p,end:h}}),textAnnotations:lt(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:lt(t.stickers,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}})},c=o.cyclicIds();c.length>0&&a?.(c);const u=o.missingRefIds();return u.length>0&&i?.(u),s},lt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,vS=e=>e.shapes.some(t=>t.region.defer!==void 0)||e.images.some(t=>t.region.defer!==void 0)||e.arrows.some(t=>t.start.defer!==void 0||t.end.defer!==void 0)||e.textAnnotations.some(t=>t.at.defer!==void 0)||e.stickers.some(t=>t.at.defer!==void 0),bS=800,Vi=400,SS=.75,xS=.875,AS=4,IS=e=>Math.max(1,(e-Vi)/(bS-Vi)+1),TS=(e,t)=>{const r=IS(t),n=e*AS;return{strokeWidth:Math.min(e,e*SS*r),arrowheadLength:Math.min(n,n*xS*r)}},Ht=Math.PI/4,on=1.5,LS=2,ES=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,Di=(e,t,r)=>{if(r<=0)return"";const{start:n,end:a}=t,i=e==="start"?n.x:a.x,o=e==="start"?n.y:a.y,s=e==="start"?Math.atan2(n.y-a.y,n.x-a.x):Math.atan2(a.y-n.y,a.x-n.x);return`M ${i} ${o} L ${i-r*Math.cos(s-Ht)} ${o-r*Math.sin(s-Ht)} M ${i} ${o} L ${i-r*Math.cos(s+Ht)} ${o-r*Math.sin(s+Ht)}`},wS=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*LS}`:`${t*on} ${t*on*2}`,RS=(e,t,r)=>e==="dashed"&&r?t*on:0,CS=64,VS=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:tr(e.start,a),end:tr(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=TS(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=DS(s,c),d=e.startArrowheadStyle==="line-arrow",p=e.endArrowheadStyle==="line-arrow",h=d||p?u*Math.sin(Math.PI/4):0;return{id:e.id,linePath:ES(i),startArrowheadPath:d?Di("start",i,u):"",endArrowheadPath:p?Di("end",i,u):"",strokeWidth:o,dashArray:wS(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:RS(t.lineType,o,d),arrowheadExtent:h}},DS=(e,t)=>Math.min(e,t*e/CS);function _S(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(p=>p.transformType==="filter"&&p.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let o,s,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")o="color",s=a.options.variableName,c=a.options.value;else if(i!==null)o="y",s=i,c=i;else continue;const u=PS(e,o,s);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d,layerId:u.id,groupValue:c})}return r}function PS(e,t,r){let n=null;for(const a of e)if(a.geom!=="rule"&&(n===null&&(n=a),l.extractVariableName(a.mapping[t])===r))return a;return n}var Sl=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),OS=0,MS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:Sl(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:OS})),kS=9,NS=8,BS=2,xl=e=>typeof e=="string"?e:Al(e),Al=e=>e.text!==void 0?e.text:e.content?e.content.map(Al).join(""):"",_i={top:"bottom",bottom:"top",right:"left",left:"right"};function FS(e,t,r){return r.type==="polar"?US(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function sn(e,t,r){const{width:n,height:a}=r;switch(t){case"top":return{x:e.x-n/2,y:e.y-9-a,width:n,height:a};case"bottom":return{x:e.x-n/2,y:e.y+9,width:n,height:a};case"right":return{x:e.x+9,y:e.y-a/2,width:n,height:a};case"left":return{x:e.x-9-n,y:e.y-a/2,width:n,height:a}}}function Pi(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function $S(e,t){return{...t,x:Math.max(0,Math.min(t.x,e.width-t.width)),y:Math.max(0,Math.min(t.y,e.height-t.height))}}function GS(e,t,r=2){return e.x<t.x+t.width-r&&e.x+e.width>t.x+r&&e.y<t.y+t.height-r&&e.y+e.height>t.y+r}function US(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[o,s]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[o,_i[o],s,_i[s]]}function HS(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:o}=e,s=[...t.map(d=>{const{id:p,at:h}=d;return Oi(p,"pinned-number",h,o(d),i,n)}),...r.map(({id:d,at:p,content:h})=>Oi(d,"comment",p,xl(h),i,n))];s.sort((d,p)=>d.anchorPx.x-p.anchorPx.x||d.anchorPx.y-p.anchorPx.y);const c=[],u=[];for(const d of s){if(!d.inView){c.push(Mi(n,d,"top"));continue}const p=Mi(n,d,KS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Oi(e,t,r,n,a,i){const o=tr(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:WS(o,i)}}function WS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function KS(e,t,r,n){const a=FS(t.anchorPx,e,r);for(const i of a){const o=sn(t.anchorPx,i,t.mini);if(Pi(o,e)&&!n.some(s=>GS(o,s)))return i}for(const i of a)if(Pi(sn(t.anchorPx,i,t.mini),e))return i;return"top"}function Mi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:$S(e,sn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var zS=(e,t,r)=>e.anchor.layerId!==t.anchor.layerId||!l.areDataValuesEqual(e.anchor.groupValue??null,t.anchor.groupValue??null)||r.start===void 0||r.start!==r.end?null:r.start,YS=100,qS=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,o=!0,s=0;for(;o;){o=!1,s++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const p=u.y+a,h=d.y-a;if(p>h){o=!0,i=!0;const m=(p-h)/2+1;u.y-=m,d.y+=m,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(s>YS)break}return{placements:n.filter(c=>c.y>=0&&c.y<=t).map(c=>({y:c.y,anchorY:c.anchorY,payload:c.payload})),hasOverlap:i}},Il=(e,t)=>rr(e,t,jS(e),{allowNull:!1}),rr=(e,t,r,{allowNull:n})=>{const a=Po(e),i=[];for(const s of r){const c=a(t,s);if(c===null&&!n)return null;i.push({variable:s,eq:c})}const[o]=i;return o===void 0?null:i.length===1?o:{and:i}},jS=e=>{const t=bn(e)?Le(e.data,e.mapping):[],r=vn(e),n=r===null?t:[...t,r],a=Ne(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},aa=e=>e!=="data-point",Tl=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(Ae(t.predicate,e.data).length>0)return[];const n=xe(t.predicate,vt(e,r));return aa(t.scope)?ZS(e,n,t.scope):XS(e,n)},XS=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},ZS=(e,t,r)=>{const n=mr(e.mapping),a=[],i=new Set;for(const s of e.data){const c=dt(r,s,n);a.push(c),t(s)&&i.add(c)}const o=[];return a.forEach((s,c)=>{i.has(s)&&o.push(c)}),o},JS=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=tx(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return ex(o,e,t,n)?o:null},QS=e=>e.identityKey==="x-group"?"series":Le(e.data,e.mapping).length===0?"data-point":"series",ex=(e,t,r,n)=>Tl({layer:t,target:e,parsingLocale:n}).includes(r),tx=(e,t,r)=>{switch(r){case"data-point":return ki(e,t);case"series":{const n=Le(e.data,e.mapping);return n.length===0?ki(e,t):rr(e,t,n,{allowNull:!0})}case"x-value":{const n=mr(e.mapping);return n===null?null:rr(e,t,[n],{allowNull:!0})}}},ki=(e,t)=>{const r=e.identityKey;if(typeof r=="object")return rr(e,t,[r.variable],{allowNull:!0});switch(r){case"index":return null;case"x-group":case"x-y":return Il(e,t)}},ia=(e,t)=>{if(t.kind==="circle"){const n=e.x-t.center.x,a=e.y-t.center.y;return n*n+a*a<=t.radius*t.radius}const{rect:r}=t;return e.x>=r.x&&e.x<=r.x+r.width&&e.y>=r.y&&e.y<=r.y+r.height},rx=(e,t)=>{for(const r of t)if(ia(e,r.shape))return r;return null},nx=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},ax=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>ix(r,t[n])),ix=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&ox(e.shape,t.shape)&&sx(e.tooltip,t.tooltip),ox=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="circle"){const n=t;return e.center.x===n.center.x&&e.center.y===n.center.y&&e.radius===n.radius}const{rect:r}=t;return e.rect.x===r.x&&e.rect.y===r.y&&e.rect.width===r.width&&e.rect.height===r.height},sx=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="cursor")return!0;const r=t;return e.point.x===r.point.x&&e.point.y===r.point.y&&e.placement===r.placement&&e.annotationId===r.annotationId},lx=100,cx=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:lx}),ux=(e,t)=>ia(e,{kind:"circle",center:t.center,radius:t.radius}),dx=(e,t)=>e===t?!0:e===null||t===null?!1:e.center.x===t.center.x&&e.center.y===t.center.y&&e.radius===t.radius&&px(e.target,t.target),px=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,mx=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=vt(e,n),i=hx(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||Ae(o.predicate,e.data).length>0)return!1;const s=xe(o.predicate,a);return s(r)?!0:aa(o.scope)&&i(o.scope).some(s)})},hx=(e,t)=>{const r=mr(e.mapping),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=dt(a,t,r),s=[];for(const c of e.data)dt(a,c,r)===o&&s.push(c);return n.set(a,s),s}},zt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=yt(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?fx(u,o):u;if(d<0||d>=o)break;const p=e.data.getAt(d);if(p===null||!n(p,d))continue;const h=s(p);if(h!==null&&!a.some(m=>Xe(h,m)))return{anchor:h,observation:p,observationIndex:d}}return null},Ll=(e,t)=>{const r=_o(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Xe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),fx=(e,t)=>(e%t+t)%t,El=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=Ne(e),a=Ll(e,t),i=e.data.getAt(a);if(i===null)return null;const o=re(i),s=h=>l.areDataValuesEqual(re(h),o),c=[t],u=zt({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=zt({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=zt({layer:e,excluding:c,from:0,step:1,accepts:h=>!s(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return p!==null?{start:t,end:p.anchor}:null},gx=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=yt(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=El({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>yx(s,o)))return o}}return null},yx=(e,t)=>Xe(e.start,t.start)&&Xe(e.end,t.end)||Xe(e.start,t.end)&&Xe(e.end,t.start),vx=(e,t)=>{const r=e.find(a=>a.id===t.anchor.layerId);if(r===void 0)return null;const n=r.data.getAt(t.observationIndex);return n===null?null:{layer:r,observation:n}},bx=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:o})=>{const s=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(s===null)return null;const c=o??e.createLayerMeasurement(t);if(c===null)return null;const u=No(t,r,c);if(u===null)return null;const d=yt(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Sx=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=Ne(e),s=Ll(e,t),c=e.data.getAt(s);if(c===null)return null;const u=xx(c),d=n==="main"?u:m=>!u(m)&&l.areDataValuesEqual(m[o]??null,t.anchorValue),p=zt({layer:e,excluding:[t,r],from:s+a,step:a,accepts:(m,f)=>d(m)&&i(m,f)!==null,cycles:n!=="main"});if(p===null)return null;const h=i(p.observation,p.observationIndex);return h===null?null:{...p,point:h}},xx=e=>{const t=re(e);return r=>l.areDataValuesEqual(re(r),t)};function Ax({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=k({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Ix=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const o=a??n;return e.kind==="grandTotal"?Tx(e,o,r):Lx(e,t,o,r,i)},Tx=(e,t,r)=>({kind:"grandTotal",value:k({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Lx=(e,t,r,n,a)=>{const i=k({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=k({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=k({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=jn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:Cx(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:Rx(s.caption,d),comparison:Ex(s.comparison,d,i,a)}})}},Ex=(e,t,r,n)=>e===null?null:{direction:wx(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},wx=e=>e>0?"up":e<0?"down":"flat",Rx=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Cx=(e,t,r,n)=>{switch(e){case"total":return n("graph.headlineMetrics.total",{value:r});case"average":return t?n("graph.headlineMetrics.averageShort",{value:r}):n("graph.headlineMetrics.averageLong",{value:r});case"current":case"conversion":case"none":return r}},Vx=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Dx(i,a,t))},Dx=(e,t,r)=>({...e,items:e.items.map(n=>{const a=k({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function oa(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function _x(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Px=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,o=(i?yn:it)(r.data,r.mapping)(a);return o===null?null:k({valueFormat:oa(e,i?Te(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},Ox=4,Mx=4,kx=12,Nx=4,Bx=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:Br([Wt("value",r??"–"),Wt("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:Ux(a),segments:Br([$x(a),Gx(a),Wt("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:Br([Fx(i,t),Wt("label",o)])}].filter(s=>s.segments.length>0)},Wt=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},Fx=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},$x=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Gx=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},Ux=e=>{switch(e.direction){case"up":return`Increased ${e.percentage} ${e.reference}`;case"down":return`Decreased ${e.percentage} ${e.reference}`;case"flat":return`No change ${e.reference}`}},Br=e=>e.filter(t=>t!==null),br=e=>e==="catmull-rom"?Pe.curveCatmullRom:Pe.curveLinear,Hx=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Wx=(e,t)=>{const r=br(t.interpolate),n=(0,Pe.area)().curve(r),a=(0,Pe.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ce(D(c)??0),o=c=>j(c)??0,s=c=>X(c)??M(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>M(c)??0,o=c=>ce(G(c)??0),s=c=>ce(F(c)??D(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>M(o)!==null&&D(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},Kx=(e,t)=>t!=="connect"?e:e.filter(r=>M(r)!==null&&D(r)!==null),sa={none:0,xs:2,sm:4,md:8,lg:12,xl:16},la=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return sa[e.borderRadius??"sm"]},zx=e=>{const t=la(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Yx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),wl=(e,t)=>{const r=j(t),n=X(t),a=G(t),i=F(t)??D(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let o=r,s=n-r;return s<0&&(o+=s,s=-s),{x:o,y:1-i,width:s,height:i-a}},Rl=(e,t)=>e==="x"?`${te(t.x)}-${te(t.width)}`:`${te(t.y)}-${te(t.height)}`,qx=e=>{let t=1/0,r=1/0,n=-1/0,a=-1/0;for(const i of e)i.x<t&&(t=i.x),i.y<r&&(r=i.y),i.x+i.width>n&&(n=i.x+i.width),i.y+i.height>a&&(a=i.y+i.height);return{x:t,y:r,width:n-t,height:a-r}},jx=e=>{const t=(0,Pe.line)().x(r=>M(r)??0).y(r=>ce(D(r)??0)).curve(br(e.interpolate));return e.missingValues==="gap"&&t.defined(Cl),t},Xx=e=>{const t=(0,Pe.area)().x(r=>M(r)??0).y0(()=>1).y1(r=>ce(D(r)??0)).curve(br(e.interpolate));return e.missingValues==="gap"&&t.defined(Cl),t},Zx=(e,t)=>t!=="connect"?e:e.filter(r=>M(r)!==null&&D(r)!==null),Cl=e=>M(e)!==null&&D(e)!==null,Vl=(0,Pe.arc)().cornerRadius(e=>e.cornerRadius??0);Vl.digits(8);var Jx=200,Qx=e=>Vl(e)??void 0,eA=(e,t)=>e==="full"?Math.max(0,t)/2:sa[e??"sm"]/Jx,Dl=(e,t)=>e==="x"?`${te(t.startAngle)}-${te(t.endAngle)}`:e==="y"?`${te(t.innerRadius)}-${te(t.outerRadius)}`:"sweep",tA=e=>{let t=1/0,r=-1/0,n=1/0,a=-1/0;for(const i of e)t=Math.min(t,i.startAngle,i.endAngle),r=Math.max(r,i.startAngle,i.endAngle),n=Math.min(n,i.innerRadius,i.outerRadius),a=Math.max(a,i.innerRadius,i.outerRadius);return{startAngle:t,endAngle:r,innerRadius:n,outerRadius:a}},rA=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],Sr=(e,t,r)=>{const n=it(e,t);return a=>{const i=re(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},nA=(e,t,r)=>{const n=it(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},aA=(e,t,r)=>{const n=it(e,t),a=yn(e,t),i=new Map;return o=>{const s=n(o),c=a(o),u=s!==null&&s!==""&&c!==null&&c!==""?`${r}-${s}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},iA=()=>(e,t)=>Et(e)??`default-${t}`,Ni=2,oA=(e,t)=>{const r=l.extractVariableName(e.mapping.color);if(t!==void 0&&r!==null&&e.data.hasVariable(r)){const n=e.data.getValues(r).findIndex(a=>l.areDataValuesEqual(a,t));if(n!==-1)return e.data.getAt(n)??void 0}return e.data.getFirst()??void 0},ca=(e,t,r,n)=>{const a=e.get("alpha",r);if(!$s(t,"bar"))return{alpha:a};const i=n.width-Ni,o=n.height-Ni,s=la({borderRadius:e.get("borderRadius",r),mainAxis:"x",bounds:{width:i,height:o}});return{alpha:a,cornerRadiusPx:Math.min(s,Math.min(i,o)/2)}};function ua(e,t){let r=0,n=e;for(;r<n;){const a=r+n>>>1;t(a)?n=a:r=a+1}return r}function sA(e,t,r){return ua(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>t})}function lA(e,t,r){return ua(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>=t})}function _l(e,t,r,n){const a=e==="x";return{mainDistance:Math.abs(t)*(a?n:1),crossDistance:Math.abs(r)*(a?1:n)}}function xr(e,t,r){return Math.hypot(e*r,t)}function Ie(e,t,r){return e<t?t-e:e>r?e-r:0}function ne(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const o=e[i];if(o===void 0)continue;const s=t(o);if(r&&s===0)return o;s<a&&(n=o,a=s)}return n}function cA(e,t){const r=t.height,n=Math.min(t.width,t.height)/2;return{cartesian:Bi(e,r),polar:Bi(e,n)}}function wt(e,t){return e<=t.on.point}function ht({mainDistance:e,crossDistance:t},r){return e<=r.near.main&&t<=r.near.cross}function Bi({on:e,near:t},r){return{on:{edge:e.edge/r,stroke:(e.stroke??e.edge)/r,point:(e.point??e.edge)/r},near:{main:t.main/r,cross:(t.cross??t.main)/r}}}function uA(e,t,r,n,a){if(e.points.length===0)return null;const i=e.delaunay;if(!i)return null;const o=i.find(t.x*r,t.y,n??void 0),s=e.points[o];if(!s)return null;const c=Pl(e,s,t,r);return a===void 0||wt(c.distance,a)||ht(c,a)?c:pA(e,t,r,a)??c}function dA(e,t){if(e.projection==="polar"||e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function pA(e,t,r,n){const{mainAxis:a,byMain:i}=e,o=ut(a,t).main,s=a==="x"?n.near.main/r:n.near.main,c=lA(i,o-s,Fi(a)),u=sA(i,o+s,Fi(a));let d=null;for(let p=c;p<u;p+=1){const h=i[p];if(h===void 0)continue;const m=Pl(e,h,t,r);ht(m,n)&&(d===null||m.crossDistance<d.crossDistance)&&(d=m)}return d}function Fi(e){return t=>ut(e,t).main}function Pl(e,t,r,n){const{main:a,cross:i}=ut(e.mainAxis,r),{main:o,cross:s}=ut(e.mainAxis,t);return{..._l(e.mainAxis,o-a,s-i,n),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:xr(t.x-r.x,t.y-r.y,n)}}function Ol(e,t){return e.buckets[mA(e,t)]??null}function mA(e,t){return Nl(e.buckets,t,r=>r.main)}function hA(e,t){return kl(e.bands,t,r=>r.bandCenter)}function Ml(e,t){return kl(e.columns,t,r=>r.mainMid)}function kl(e,t,r){return e[Nl(e,t,r)]??null}function Nl(e,t,r){if(e.length===0)return-1;const n=ua(e.length,o=>{const s=e[o];return s!==void 0&&r(s)>=t}),a=e[n-1],i=e[n];return a?i&&Math.abs(r(i)-t)<Math.abs(r(a)-t)?n:n-1:n}function fA(e,t){return{group:gA(e),related:SA(e,t)}}function gA(e){switch(e.kind){case"buckets":{const t=e.match.index;return U(t.position)?yA(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return U(t.position)?vA(t.layerId,r,n.pointIndex):bA(t.bandByColumn,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function yA(e,t,r){const n=[];for(const a of t.entries)a.pointIndex!==r&&n.push({anchored:!0,layerId:e,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation});return n}function vA(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(da(e,a));return n}function bA(e,t,r,n){const a=e.get(r);if(!a)return[];const i=[];for(const o of a.columns)for(const s of o.rects)s.pointIndex!==n&&i.push(da(t,s));return i}function SA(e,t){const r=new Map;if(e.kind==="render-hit-test"||e.kind==="enclosure")return r;const n=e.match.index,a=n.projection==="polar";for(const i of t){if(i.layerId!==n.layerId){a||AA(r,i,e.match.hit);continue}e.kind==="buckets"&&(U(i.position)||i.kind==="buckets"&&xA(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function xA(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Yt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function AA(e,t,r){switch(t.kind){case"buckets":{const n=Ol(t,Z(t.mainAxis,r));if(!n)return;const a=Yt(e,t.layerId);for(const i of n.entries)a.push({anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation});return}case"banded":{const n=hA(t,Z(t.mainAxis,r));if(!n)return;const a=Yt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(da(t.layerId,o));return}case"points":{const n=dA(t,r);if(!n)return;Yt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,observationIndex:n.observationIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function Yt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function da(e,t){return{anchored:!0,layerId:e,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function Bl(e,t,r){const{columns:n,bands:a,bandByColumn:i}=IA(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a,bandByColumn:i}}function IA(e,t){const r=LA(e,t);r.sort((c,u)=>c.mainMid-u.mainMid);const n=new Map,a=new Map,i=new Map;for(const c of r){const u=te(c.mainMid);let d=n.get(u);if(!d){d={mainMid:c.mainMid,rects:[]},n.set(u,d);const p=te(c.bandCenter);let h=a.get(p);h||(h={bandCenter:c.bandCenter,columns:[],mainMin:1/0,mainMax:-1/0},a.set(p,h)),h.columns.push(d),i.set(d,h)}d.rects.push(c.entry),TA(i.get(d),c.entry,t)}const o=[...n.values()].sort((c,u)=>c.mainMid-u.mainMid),s=[...a.values()].sort((c,u)=>c.bandCenter-u.bandCenter);for(const c of s)c.columns.sort((u,d)=>u.mainMid-d.mainMid);return{columns:o,bands:s,bandByColumn:i}}function TA(e,t,r){if(e===void 0)return;const n=r==="x"?t.xMin:t.yMin,a=r==="x"?t.xMax:t.yMax;e.mainMin=Math.min(e.mainMin,n),e.mainMax=Math.max(e.mainMax,a)}function LA(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=t==="y",c=s?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let p=0;for(const h of r){const m=n[p],f=a[p],g=i[p],v=o[p];if(!l.isDefined(m)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(v)){p++;continue}const y=s?(g+v)/2:(m+f)/2,b=u?.[p]??y;d.push({mainMid:y,bandCenter:b,entry:{pointIndex:p,xMin:Math.min(m,f),xMax:Math.max(m,f),yMin:Math.min(g,v),yMax:Math.max(g,v),observation:h}}),p++}return d}var EA=1e-9,$i=-1;function Fl(e,t,r){const n=wA(e,t,r),a=n.map(o=>o.entry);n.sort((o,s)=>o.main-s.main);const i=[];for(const o of n){const s=i[i.length-1];s&&Math.abs(s.main-o.main)<=EA?s.entries.push(o.entry):i.push({main:o.main,entries:[o.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:i,entries:a}}function wA(e,t,r){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(l.POSITION_VARIABLES.x),i=n.hasVariable(l.POSITION_VARIABLES.y);if(!a||!i)return[];const o=n.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=n.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),c=t==="y",u=c?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,d=c?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,p=U(e.position),h=n.hasVariable(u)?n.getValues(u,{type:"numeric"}):null,m=n.hasVariable(d)?n.getValues(d,{type:"numeric"}):null,f=n.hasVariable(l.GROUP_VARIABLES.group)?n.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,g=new CA(RA(e)),v=new Map,y=[];let b=0;for(const A of n){const T=o[b],L=s[b],E=f?.[b]??null,w=VA(v,E);if(!l.isDefined(T)||!l.isDefined(L)){g.skip(E),b+=1;continue}const C=c?L:T,I=h?.[b],V=p?m?.[b]:void 0;if(p&&(!l.isDefined(I)||!l.isDefined(V))){g.skip(E),b+=1;continue}const O=V??ge(t,{x:T,y:L}),ie={pointIndex:b,...c?{x:O,y:L}:{x:T,y:O},groupKey:E,paintOrder:w,...e.spatialKind==="filled-buckets"&&l.isDefined(I)&&{fill:DA(I,O)},previousAt:$i,nextAt:$i,observation:A};g.append(E,{entry:ie,at:y.length}),y.push({main:C,entry:ie}),b+=1}return r==="polar"&&g.close(),y}function RA(e){return"missingValues"in e.params&&e.params.missingValues==="gap"}var CA=class{constructor(e){this.breaksAtNull=e,this.firstByGroup=new Map,this.lastByGroup=new Map,this.brokenGroups=new Set}append(e,t){const r=this.lastByGroup.get(e);r!==void 0&&(r.entry.nextAt=t.at,t.entry.previousAt=r.at),this.firstByGroup.has(e)||this.firstByGroup.set(e,t),this.lastByGroup.set(e,t)}skip(e){this.breaksAtNull&&(this.lastByGroup.delete(e),this.brokenGroups.add(e))}close(){for(const[e,t]of this.firstByGroup){const r=this.lastByGroup.get(e);r===void 0||r===t||this.brokenGroups.has(e)||(r.entry.nextAt=t.at,t.entry.previousAt=r.at)}}};function VA(e,t){const r=e.get(t);if(r!==void 0)return r;const n=e.size;return e.set(t,n),n}function DA(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function $l(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:_A(e,t)}}function _A(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const p of n)if(!r.hasVariable(p))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const p of r){const h=a[d],m=i[d],f=o[d],g=s[d];if(!l.isDefined(h)||!l.isDefined(m)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!Et(p)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:m,yMin:f,yMax:g,observation:p}),d++}return u}function ln(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function PA(e,t,r){const n=Ul(e),a={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",mainAxis:t,points:n,byMain:MA(t,n),delaunay:null,delaunayAspectRatio:null};return Gl(a,r),a}function OA(e){const t=Ul(e).map(r=>{const n=fe(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t}}function Gl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Xd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function MA(e,t){const r=n=>Z(e,n);return[...t].sort((n,a)=>r(n)-r(a))}function Ul(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const o of t){const s=r[i],c=n[i];l.isDefined(s)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:s,y:c,observation:o}),i+=1}return a}function Hl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:kA(e)}}function Wl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function kA(e){const t=e.identityKey,r=new Map;if(typeof t=="object"){let n=0;for(const a of e.data){const i=a[t.variable];l.isDefined(i)&&r.set(l.getStableKey(i),{pointIndex:n,observation:a}),n+=1}return r}if(t==="index"){let n=0;for(const a of e.data)r.set(String(n),{pointIndex:n,observation:a}),n+=1}return r}function Gi(e,t,r){return t.type==="polar"?NA(e,t.bandAxis):BA(e,t.mainAxis,r)}function NA(e,t){switch(e.spatialKind){case"points":return OA(e);case"buckets":case"filled-buckets":return Fl(e,"x","polar");case"rects":return t===null?$l(e,"polar"):Bl(e,t,"polar");case"cells":return ln(e);case"noop":return ln(e);case"render-hit-test":return Hl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function BA(e,t,r){switch(e.spatialKind){case"points":return PA(e,t,r);case"buckets":case"filled-buckets":return Fl(e,t,"cartesian");case"rects":return Bl(e,t,"cartesian");case"cells":return $l(e,"cartesian");case"noop":return ln(e);case"render-hit-test":return Hl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function FA(e,t,r){if(e.columns.length===0)return null;const n=Z(e.mainAxis,t),a=Ml(e,n),i=a?.rects??[];if(!a||!l.isNonEmptyArray(i))return null;const o=U(e.position)?GA(i,t,e.mainAxis):UA(i,t,r),s=Kl(o,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:(o.xMin+o.xMax)/2,y:(o.yMin+o.yMax)/2,observation:o.observation},index:e,column:a,distance:s,mainDistance:$A(e,a,n,r),crossDistance:0}}function $A(e,t,r,n){const a=e.bandByColumn.get(t);if(a===void 0)return Number.POSITIVE_INFINITY;const i=Ie(r,a.mainMin,a.mainMax);return e.mainAxis==="x"?xr(i,0,n):i}function GA(e,t,r){const n=ge(r,t);return ne(e,i=>HA(i,r,n),{shortCircuitOnZero:!0})}function UA(e,t,r){return ne(e,a=>Kl(a,t,r))}function Kl(e,t,r){return xr(Ie(t.x,e.xMin,e.xMax),Ie(t.y,e.yMin,e.yMax),r)}function HA(e,t,r){return Ie(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function WA(e,t,r){const n=r.x-t.x,a=r.y-t.y,i=n*n+a*a;if(i===0)return Math.hypot(e.x-t.x,e.y-t.y);const o=((e.x-t.x)*n+(e.y-t.y)*a)/i,s=Math.max(0,Math.min(1,o));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*a))}function KA(e,t,r){const{main:n,cross:a}=ut(e.mainAxis,t),i=Ol(e,n);if(i===null)return null;const o=i.entries.map(f=>({entry:f,crossAtCursor:YA(e,f,n)}));if(!l.isNonEmptyArray(o))return null;const s=Yl(o.filter(f=>jA(e,f.entry,n,a)),f=>f.entry),{entry:c}=s??ne(o,f=>Math.abs(f.crossAtCursor-a)),u=xr(c.x-t.x,c.y-t.y,r),d=f=>({x:f.x*r,y:f.y}),p=Ar(e,c).map(d),h=zl(d(t),d(c),p,u),m=_l(e.mainAxis,i.main-n,ge(e.mainAxis,c)-a,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:c.x,y:c.y,observation:c.observation},index:e,bucket:i,distance:s===void 0?u:0,vertexDistance:u,insideFill:s!==void 0,strokeDistance:s===void 0?h:0,...m}}function zA(e,t,r){return ne(e,a=>Math.abs(ge(r,a)-t))}function zl(e,t,r,n){const a=r.map(i=>WA(e,t,i));return Math.min(n,...a)}function Ar(e,t){return[e.entries[t.previousAt],e.entries[t.nextAt]].filter(l.isDefined)}function Yl(e,t){return e.reduce((r,n)=>r===void 0||t(n).paintOrder>t(r).paintOrder?n:r,void 0)}function YA(e,t,r){const{mainAxis:n}=e,a=r===Z(n,t)?null:ql(e,t,r);return a===null?ge(n,t):qA(t,a,n,r)}function qA(e,t,r,n){const a=Z(r,e),i=(n-a)/(Z(r,t)-a),o=ge(r,e);return o+(ge(r,t)-o)*i}function ql(e,t,r){const{mainAxis:n}=e,a=Z(n,t),i=o=>Math.sign(Z(n,o)-a)===Math.sign(r-a);return Ar(e,t).find(i)??null}function jA(e,t,r,n){const a=XA(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function XA(e,t,r){if(t.fill===void 0)return null;const{mainAxis:n}=e,a=Z(n,t);if(r===a)return t.fill;const i=ql(e,t,r);if(i?.fill===void 0)return null;const o=(r-a)/(Z(n,i)-a);return{min:t.fill.min+(i.fill.min-t.fill.min)*o,max:t.fill.max+(i.fill.max-t.fill.max)*o}}function ZA(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e,distance:0,mainDistance:0,crossDistance:0};return null}function JA(e,t,r){if(e.columns.length===0)return null;const n=mn(t,r),{angle:a,radius:i}=n,o=e.mainAxis==="x",s=o?tI(e.columns,a):Ml(e,i),c=s?.rects??[];if(!s||!l.isNonEmptyArray(c))return null;const u=o?rI(c,i):nI(c,a),d=QA(u,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:(u.xMin+u.xMax)/2,y:(u.yMin+u.yMax)/2,observation:u.observation},index:e,column:s,distance:d,mainDistance:eI(e,s,n),crossDistance:0}}function QA(e,{angle:t,radius:r}){const n=pa(t,e.xMin,e.xMax),a=Ie(r,e.yMin,e.yMax);return Math.hypot(n*r,a)}function pa(e,t,r){return Zt(e,t,r)?0:Math.min(Qe(e,t),Qe(e,r))}function eI(e,t,{angle:r,radius:n}){const a=e.bandByColumn.get(t);return a===void 0?Number.POSITIVE_INFINITY:e.mainAxis==="x"?pa(r,a.mainMin,a.mainMax)*n:Ie(n,a.mainMin,a.mainMax)}function tI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(t,r.mainMid)):null}function rI(e,t){return ne(e,r=>Ie(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function nI(e,t){return ne(e,r=>pa(t,r.xMin,r.xMax),{shortCircuitOnZero:!0})}var Ui=1e-9;function aI(e,t,r){if(e.buckets.length===0)return null;const n=sr(t,r),{angle:a,radius:i}=or(n.x,n.y),o=iI(e.buckets,a),s=o?.entries??[];if(!o||!l.isNonEmptyArray(s))return null;const c=Yl(s.filter(m=>oI(e,m,a,i)),m=>m),u=c??zA(s,i,e.mainAxis),d=Hi(u),p=Math.hypot(n.x-d.x,n.y-d.y),h=zl(n,d,Ar(e,u).map(Hi),p);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:u.x,y:u.y,observation:u.observation},index:e,bucket:o,distance:c===void 0?p:0,vertexDistance:p,insideFill:c!==void 0,strokeDistance:c===void 0?h:0,mainDistance:Qe(o.main,a)*i,crossDistance:Math.abs(i-u.y)}}function Hi(e){return fe(e.x,e.y)}function iI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(r.main,t)):null}function oI(e,t,r,n){const a=sI(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function sI(e,t,r){if(t.fill===void 0)return null;const n=Fa(t.x,r);if(n===0)return t.fill;const a=c=>Math.sign(Fa(t.x,c.x))===Math.sign(n),i=Ar(e,t).find(a);if(i?.fill===void 0)return null;const o=Wi(r,{angle:t.x,radius:t.fill.min},{angle:i.x,radius:i.fill.min}),s=Wi(r,{angle:t.x,radius:t.fill.max},{angle:i.x,radius:i.fill.max});return o===null||s===null?null:{min:o,max:s}}function Wi(e,t,r){const n=fe(t.angle,t.radius),a=fe(r.angle,r.radius),i={x:a.x-n.x,y:a.y-n.y};if(Math.hypot(i.x,i.y)<Ui)return t.radius;const o=Ki(fe(e,1),i);return Math.abs(o)<Ui?null:Ki(n,i)/o}function Ki(e,t){return e.x*t.y-e.y*t.x}function lI(e,t,r,n=!1){if(e.cells.length===0)return null;const{angle:a,radius:i}=mn(t,r);for(const u of e.cells)if(!(i<u.yMin||i>u.yMax)&&Zt(a,u.xMin,u.xMax))return zi(e,u,0);if(!n)return null;const o=e.cells.filter(u=>Zt(a,u.xMin,u.xMax));if(!l.isNonEmptyArray(o))return null;const s=u=>Ie(i,u.yMin,u.yMax),c=ne(o,s);return zi(e,c,s(c))}function zi(e,t,r){return{hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation},index:e,distance:r,mainDistance:0,crossDistance:r}}function cI(e,t,r,n){if(!l.isNonEmptyArray(e.points))return null;const a=sr(t,r),i=Yi(e,ne(e.points,s=>jl(s,a)),a);if(n===void 0||wt(i.distance,n)||ht(i,n))return i;const o=e.points.map(s=>Yi(e,s,a)).filter(s=>ht(s,n));return l.isNonEmptyArray(o)?ne(o,s=>s.crossDistance):i}function Yi(e,t,r){const{angle:n,radius:a}=or(r.x,r.y);return{mainDistance:Qe(t.x,n)*a,crossDistance:Math.abs(a-t.y),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:Math.sqrt(jl(t,r))}}function jl(e,t){const r=e.unitX??fe(e.x,e.y).x,n=e.unitY??fe(e.x,e.y).y,a=r-t.x,i=n-t.y;return a*a+i*i}var uI=.05;function dI({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a,tolerance:i}){const o={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},s={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},c={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1};for(const[u,d]of e.entries()){if(d.kind==="render-hit-test"){const h=vI(d,t,a);if(h)return{kind:"render-hit-test",match:h};continue}if(d.projection==="polar"){const h=yI(d,t,r,i?.polar);if(h&&!qi(h,i?.polar))return h;continue}const p=gI({layer:d,cursor:t,aspectRatio:r,warmStarts:n,tolerance:i?.cartesian});if(!(!p||qi(p,i?.cartesian))){if(p.kind==="banded"||p.kind==="enclosure"){const h=p.match.distance;h<o.distance&&(o.match=p,o.distance=h,o.paintOrder=u);continue}if(p.kind==="buckets"&&p.match.insideFill){s.match=p,s.distance=0,s.paintOrder=u;continue}p.match.distance<c.distance&&(c.match=p,c.distance=p.match.distance,c.paintOrder=u)}}return Xl(c,mI(s,o)).match}function pI(e,t){if(e.kind==="render-hit-test")return{intersects:!0,onPoint:!1};const r=hI(e,t),n=e.kind==="buckets"&&wt(e.match.vertexDistance,r);return{intersects:Zl(e,r),onPoint:n}}function mI(e,t){return e.match!==null&&t.match!==null&&e.distance===0&&t.distance===0?e.paintOrder>t.paintOrder?e:t:Xl(e,t)}function Xl(e,t){return e.match===null?t:t.match===null||e.distance<=t.distance+uI?e:t}function Zl(e,t){switch(e.kind){case"banded":case"enclosure":return e.match.distance<=t.on.edge;case"buckets":return fI(e.match,t);case"points":return wt(e.match.distance,t)}}function hI(e,t){return e.match.index.projection==="polar"?t.polar:t.cartesian}function fI(e,t){return e.strokeDistance<=t.on.stroke?!0:wt(e.vertexDistance,t)}function qi(e,t){return t===void 0?!1:!Zl(e,t)&&!ht(e.match,t)}function gI({layer:e,cursor:t,aspectRatio:r,warmStarts:n,tolerance:a}){switch(e.kind){case"buckets":{const i=KA(e,t,r);return i?{kind:"buckets",match:i}:null}case"banded":{const i=FA(e,t,r);return i?{kind:"banded",match:i}:null}case"points":{const i=uA(e,t,r,n.get(e.layerId)??null,a);return i?{kind:"points",match:i}:null}case"enclosure":{const i=ZA(e,t);return i?{kind:"enclosure",match:i}:null}case"noop":return null}}function yI(e,t,r,n){switch(e.kind){case"enclosure":{const a=lI(e,t,r,n!==void 0);return a?{kind:"enclosure",match:a}:null}case"points":{const a=cI(e,t,r,n);return a?{kind:"points",match:a}:null}case"buckets":{const a=aI(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=JA(e,t,r);return a?{kind:"banded",match:a}:null}case"noop":case"render-hit-test":return null}}function vI(e,t,r){const n=r.get(e.layerId);if(!n)return null;const a=n({x:t.x,y:1-t.y});if(!a)return null;const i=e.byKey.get(a.key);return i?{hit:Wl(e.layerId,i)}:null}var oe={primary:null,group:[],related:new Map},bI=1,SI=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.viewport=null,this.aspectRatio=bI,this.isAspectStale=!1,this.warmStarts=new Map,this.cachedState=oe,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=oe,this.layerIndexes=e.map(r=>Gi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>ji(r,t)),this.nonInteractiveLayerIds=Xi(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const o=this.layerIndexes[i],s=this.layerRefs[i];!o||!s||r.set(o.layerId,{index:o,ref:s})}const n=[],a=[];for(const i of e){const o=r.get(i.id),s=ji(i,t);if(o!==void 0&&AI(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push(Gi(i,t,this.aspectRatio)),a.push(s)}for(const i of this.warmStarts.keys())e.some(o=>o.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=Xi(e),this.invalidateCache()}setViewport(e){if(e.width<=0||e.height<=0)return;this.viewport=e;const t=e.width/e.height;t!==this.aspectRatio&&(this.aspectRatio=t,this.isAspectStale=!0)}query(e,t){if(this.layerIndexes.length===0)return oe;this.reindexForAspect();const r=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(d=>!this.nonInteractiveLayerIds.has(d.layerId)),n=t!==void 0&&this.viewport!==null?cA(t,this.viewport):void 0,a=dI({layers:r,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e,tolerance:n});if(!a)return this.invalidateCache(),oe;const i=a.match.hit;this.warmStarts.set(i.layerId,i.pointIndex);const o=n===void 0?void 0:pI(a,n),s=xI(i,o);if(this.cachedKey===s)return this.cachedState;const{group:c,related:u}=fA(a,r);return this.cachedKey=s,this.cachedState=o===void 0?{primary:i,group:c,related:u}:{primary:i,group:c,related:u,intersection:o},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return oe;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return oe;const n=r.byKey.get(t);if(!n)return oe;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Wl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=oe,this.cachedByKeyId=null,this.cachedByKeyState=oe}reindexForAspect(){if(this.isAspectStale){this.isAspectStale=!1;for(const e of this.layerIndexes)e.kind==="points"&&e.projection==="cartesian"&&Gl(e,this.aspectRatio)}}};function xI(e,t){const r=`${e.layerId}:${e.pointIndex}`;return t===void 0?r:`${r}:${t.intersects}:${t.onPoint}`}function ji(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Xi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function AI(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var II=Math.PI*2;function TI(e,t){const r=Z(e.mainAxis,t);if(e.mainAxis==="y"){const a=De(ce(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=De(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function LI(e,t,r){const n=e.mainAxis==="y"?D(r.observation):M(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Ql(r):Jl(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const o=i/2;return e.mainAxis==="y"?{x:0,y:De(ce(n+o)),width:"100%",height:De(i)}:{x:De(n-o),y:0,width:De(i),height:"100%"}}function EI(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=j(t.observation),i=X(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=G(t.observation),n=F(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+II,innerRadius:r,outerRadius:n}}function Jl(e){const t=j(e.observation),r=X(e.observation);return t===null||r===null?null:r-t}function Ql(e){const t=G(e.observation),r=F(e.observation);return t===null||r===null?null:r-t}function wI(e){return e.observationIndex??e.pointIndex}function ec(e){return e==="buckets"||e==="filled-buckets"}var Ir=.5,RI=.3,CI=.4,VI=10,DI=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?PI(e,t,r,n):OI(e,t,n):ec(e.spatialKind)&&t.type==="cartesian"?NI(e,t,n):e.spatialKind==="cells"?kI(e,n):e.spatialKind==="points"?MI(e,n):null,_I=e=>{if(ec(e.spatialKind)){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},PI=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:Ir*n.durationScale,baseline:BI(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?FI(e,t.mainAxis,n):{}}),OI=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:Ir*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?UI(e,t,r):{}}},MI=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:Ir*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?$I(e,t):{}}),kI=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:RI*t.durationScale}),NI=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:Ir*r.durationScale,axis:t.mainAxis}),BI=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[Te(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const o=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-o:o},FI=(e,t,r)=>{const n=Sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=wl(t,i);if(!o)continue;const s=Rl(t,o),c=n(i),u=a.get(s);u?u.keys.push(c):a.set(s,{position:t==="x"?o.x:o.y,keys:[c]})}return ma([...a.values()],r)},$I=(e,t)=>{const r=Sr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=GI(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return ma(n,t)},GI=(e,t)=>{if(t==="main-axis")return M(e);const r=Zn(e)??M(e);return r===null?null:t==="value-descending"?-r:r},UI=(e,t,r)=>{const n=Sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=ea(i),{innerRadius:c,outerRadius:u}=ta(i);if(o===null||s===null||c===null||u===null)continue;const d=Dl(t.bandAxis,{startAngle:o,endAngle:s,innerRadius:c,outerRadius:u}),p=n(i),h=a.get(d);h?h.keys.push(p):a.set(d,{position:o,keys:[p]})}return ma([...a.values()],r)},ma=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((s,c)=>s.position-c.position),a=Math.ceil(n.length/VI),i=Math.ceil(n.length/a),o=CI*t.durationScale/i;return n.forEach((s,c)=>{const u=Math.floor(c/a)*o;for(const d of s.keys)r[d]=u}),r},qe=["top","right","bottom","left"],Zi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},HI={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},WI={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},KI=(e,t)=>{const{edges:r,borderRadius:n}=e,a=Math.max(0,Math.min(n,t.width/2,t.height/2)),i=c=>{const[u,d]=WI[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=YI(t,a),s=qI(t,a,i);return jI(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:XI(c,o,s,i)}))},zI=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),YI=(e,t)=>{const{x:r,y:n,width:a,height:i}=e;return{topLeft:{cx:r+t,cy:n+t,startAngle:Math.PI,endAngle:Math.PI*1.5,radius:t},topRight:{cx:r+a-t,cy:n+t,startAngle:Math.PI*1.5,endAngle:Math.PI*2,radius:t},bottomRight:{cx:r+a-t,cy:n+i-t,startAngle:0,endAngle:Math.PI*.5,radius:t},bottomLeft:{cx:r+t,cy:n+i-t,startAngle:Math.PI*.5,endAngle:Math.PI,radius:t}}},qI=(e,t,r)=>{const{x:n,y:a,width:i,height:o}=e,s=c=>r(c)?t:0;return{top:{start:{x:n+s("topLeft"),y:a},end:{x:n+i-s("topRight"),y:a}},right:{start:{x:n+i,y:a+s("topRight")},end:{x:n+i,y:a+o-s("bottomRight")}},bottom:{start:{x:n+i-s("bottomRight"),y:a+o},end:{x:n+s("bottomLeft"),y:a+o}},left:{start:{x:n,y:a+o-s("bottomLeft")},end:{x:n,y:a+s("topLeft")}}}},jI=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(qe.indexOf(o)+s+qe.length)%qe.length;return qe[c]},n=o=>{const s=r(o,-1);return!t(s)||e[s].lineType!==e[o].lineType||e[s].strokeWidth!==e[o].strokeWidth||e[s].color!==e[o].color},a=qe.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...qe],isClosed:!0}]:i.map(o=>{const s=[o];for(let c=r(o,1);t(c)&&!n(c);c=r(c,1))s.push(c);return{firstEdge:o,edges:s,isClosed:!1}})},XI=(e,t,r,n)=>{const a=(p,h,m)=>({type:"arc",cx:p.cx,cy:p.cy,radius:p.radius,startAngle:h,endAngle:m}),i=p=>(p.startAngle+p.endAngle)/2,o=[],s=e.firstEdge,c=e.edges[e.edges.length-1],u=Zi[s];if(!e.isClosed&&n(u)){const p=t[u],h=i(p),m=ZI(p,h);o.push({type:"move",x:m.x,y:m.y}),o.push(a(p,h,p.endAngle))}else o.push({type:"move",x:r[s].start.x,y:r[s].start.y});o.push({type:"line",x:r[s].end.x,y:r[s].end.y});for(const p of e.edges.slice(1)){const h=Zi[p];if(n(h)){const m=t[h];o.push(a(m,m.startAngle,m.endAngle))}o.push({type:"line",x:r[p].end.x,y:r[p].end.y})}const d=HI[c];if(e.isClosed){if(n(d)){const p=t[d];o.push(a(p,p.startAngle,p.endAngle))}o.push({type:"close"})}else if(n(d)){const p=t[d];o.push(a(p,p.startAngle,i(p)))}return o},ZI=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),JI=/^(?:https?:|mailto:)/i,QI=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:JI.test(t)},eT=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...Y,...t}).format(r)),tT=({locale:e,intlOptions:t})=>K(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...Y,...t}).format(r)}),nr=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ks(e);case"date":return eT(e);case"datetime":return tT(e);case"day_month":return js(e);case"decimal":return zs(e);case"duration":return Gn(e);case"integer":return Ys(e);case"month":return Xs(e);case"month_year":return Wn(e);case"percentage":return qs(e);case"quarter":return Kn(e);case"text":return $n(e);case"time":return Qs(e);case"weekly_date_range":return Zs(e);case"weekly_date_range_with_year":return Js(e);case"year":return zn(e);case"lookup":return nr({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},tc={width:12,height:12},rT=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:o,colorScheme:s,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:p}=o;if(p===null)return null;const h=c??i,m=nT(u,d);return{header:m===null?aT({layers:e,coordSystem:t,guides:n,primary:p,locale:h,numberFormat:a}):null,rows:iT({layers:e,scales:r,guides:n,hover:o,locale:h,numberFormat:a,colorScheme:s}),comment:m}};function nT(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function aT(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=oa(e.guides,"x");if(!t)return null;const r=e.layers.find(i=>i.id===e.primary.layerId);if(!r)return null;const n=l.extractVariableName(r.mapping.x);if(!l.isDefined(n))return null;const a=e.primary.observation[n];return l.isDefined(a)?nr({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function iT(e){const t=[],r=e.scales.color??null,n=ot({colorScheme:e.colorScheme}),a=cT({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=sT(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...oT(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Ao(i.data,i.mapping),u=lT(o,i,r,c),d=ra({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=uT(e.guides,i),h=gt(i),m=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const v=m?c(g.observation):null,y=f.get("color",g.observation),b=f.get("lineType",g.observation)??"solid",A=ca(f,i,g.observation,tc),T=m&&v!==null?a(v):p,L=h(g.observation),E=L===null?"":d(L,g.observation);t.push({swatchColor:y,geom:i.geom,swatchLineType:b,swatchAlpha:A.alpha,swatchCornerRadius:A.cornerRadiusPx,label:T,value:E,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function oT(e,t,r,n,a){const i=ca(n,e,t.observation,tc);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=Q(e.data,s)(t.observation),d=k({valueFormat:xn(e,c),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:o.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",swatchAlpha:i.alpha,swatchCornerRadius:i.cornerRadiusPx,label:o.key??pr(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function sT(e,t){const r=[];return t.primary!==null&&t.primary.layerId===e.id&&r.push(t.primary,...t.group),r.push(...t.related.get(e.id)??[]),r}function lT(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,o)=>{a.set(l.getStableKey(i),o)}),e.map((i,o)=>{const s=n(i.observation),c=s===null?null:l.getStableKey(s);return{hit:i,originalIndex:o,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,o)=>i.rank===o.rank?i.originalIndex-o.originalIndex:i.rank-o.rank).map(i=>i.hit)}function cT({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:nr({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=nr({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const o=n.get(l.getStableKey(i));return o===void 0?a(i):o.label??o.format(i)}}function uT(e,t){return pr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function dT(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function pT(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var mT=(e,t)=>{const r=e.annotation.shape(t),n=r.get("borderColor");return{color:r.get("color"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth")}},hT=(e,t)=>{const r=e.annotation.arrow(t),n=r.get("borderColor");return{color:r.get("color"),strokeWidth:r.get("strokeWidth"),lineType:r.get("lineType"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),shadow:r.get("shadow")}},fT=(e,t)=>{const r=e.annotation.differenceArrow(t),n=e.annotation.differenceArrow.label(t),a=n.get("borderColor");return{color:r.get("color"),isColorAuthored:r.getSource("color")==="authored",strokeWidth:r.get("strokeWidth"),label:{...N(n,e.graph),background:n.get("background"),...a===void 0?{}:{borderColor:a},borderWidth:n.get("borderWidth"),borderRadius:n.get("borderRadius"),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock")}}},gT=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...N(r,e.graph),background:r.get("background"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock")}},yT=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},vT=(e,t,r)=>{const n=e.annotation[t](r),a=e.annotation[t].label(r);return{marker:{color:n.get("color"),isColorAuthored:n.getSource("color")==="authored",size:n.get("size"),borderColor:n.get("borderColor"),borderWidth:n.get("borderWidth"),shadow:n.get("shadow")},label:{...N(a,e.graph),isTextColorAuthored:a.getSource("textColor")==="authored",background:a.get("background"),borderColor:a.get("borderColor"),borderWidth:a.get("borderWidth"),borderRadius:a.get("borderRadius"),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),shadow:a.get("shadow")}}},bT=e=>e.borderWidth>0?e.borderColor??e.color:void 0,ST=e=>({edges:{top:Ze(e.panelBorder("top")),right:Ze(e.panelBorder("right")),bottom:Ze(e.panelBorder("bottom")),left:Ze(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),xT=(e,t)=>Ze(e.gridLine(t)),AT=(e,t)=>{const r=e.tickLine(t);return{...Ze(r),length:r.get("length")}},IT=e=>e.heading.h1.get("fontFamily")??e.graph.get("fontFamily"),TT=e=>{const t=e.graph.get("borderColor");return{background:e.graph.get("background"),...t===void 0?{}:{borderColor:t},borderWidth:e.graph.get("borderWidth"),borderRadius:e.graph.get("borderRadius")}},LT=e=>{const t=e.graph.get("padding");return typeof t=="number"?{top:t,right:t,bottom:t,left:t}:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},ET=e=>{const t=e.legend.popover;return{gap:e.legend().get("gap"),popover:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")}}},wT=e=>({gap:e.headline.get("gap")}),q=e=>{let t={top:0,right:0,bottom:0,left:0};for(const r of e.collectAll("margin"))t=typeof r=="number"?{top:r,right:r,bottom:r,left:r}:{...t,...r};return t},RT=e=>({header:q(e.header),footer:q(e.footer),headline:q(e.headline),legend:{top:q(e.legend("top")),right:q(e.legend("right")),bottom:q(e.legend("bottom")),left:q(e.legend("left"))},axisLabel:{top:q(e.axisLabel("x","top")),bottom:q(e.axisLabel("x","bottom"))},tickLabel:{top:q(e.tickLabel("x","top")),right:q(e.tickLabel("y","right")),bottom:q(e.tickLabel("x","bottom")),left:q(e.tickLabel("y","left"))}}),CT=e=>({color:e.hoverGuide.get("color"),background:e.hoverGuide.get("background")}),VT=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Ze=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),ha=["sticker","pinnedNumber","comment","image"],DT=e=>ha.includes(e),fa=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?PT(e.annotation.at):null;default:return null}},rc=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),nc=(e,t,r=_T)=>{const n=r(t);for(const a of ha){const i=It(e,a),o=i.findIndex(c=>{const u=fa({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return rc(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},_T=e=>({...e,anchorValue:Fr(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Fr(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Fr(e.crossValue)}}),Fr=e=>l.readISOInstant(e)??e,PT=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function OT(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var MT=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ga(r.predicate,t.predicate))??null,ga=(e,t)=>"and"in e?"and"in t&&Ji(e.and,t.and):"or"in e?"or"in t&&Ji(e.or,t.or):"not"in e?"not"in t&&ga(e.not,t.not):kT(t)&&e.variable===t.variable&&NT(e,t),kT=e=>"variable"in e,Ji=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ga(r,a)}),NT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Qi(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&Qi(e.range,t.range),Qi=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),BT={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},FT=e=>Object.hasOwn(BT,e);function $T(e){return{type:"mapping",mapping:e}}var Rt=(e,t)=>"and"in e?"and"in t&&eo(e.and,t.and):"or"in e?"or"in t&&eo(e.or,t.or):"not"in e?"not"in t&&Rt(e.not,t.not):GT(t)&&e.variable===t.variable&&UT(e,t),GT=e=>"variable"in e,eo=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Rt(r,a)}),UT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&to(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&to(e.range,t.range),to=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ac=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="identity"&&(l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.y))||l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.x)))),ic=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),oc=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function sc(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(HT),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function HT(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?WT(r):r}function WT(e){return{...e,palette:KT(e.palette),overrides:zT(e.overrides)}}function KT(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function zT(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Ct=(e,t)=>{const r=ya(e,t);return r===-1?void 0:e[r]},ya=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&Tr(n,t))return r}return-1},Tr=(e,t)=>YT(e.select,t.select)&&e.when?.state===t.when?.state&&qT(e.when?.where,t.when?.where),lc=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>jT(e[r],t[r])),_e=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),va=e=>e.select.target==="geom",Vt=(e,t)=>{const r=Ct(e,t);if(!(r===void 0||!va(r)))return r.declarations},YT=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},qT=(e,t)=>e===void 0||t===void 0?e===t:Rt(e,t),jT=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function x(e){return{id:e.id??W(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function nt(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>nt(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>nt(e[a],t[a]))}return!1}var ba=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=x({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=At(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:R(e,{annotations:ws(e.annotations,t)}),revert:new Sa({kind:r,annotation:a,index:n},this.metadata)}}},XT={type:"remove-annotation",deserialize:(e,t)=>new ba(e,t)},Sa=class cc{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??W()},...t.index!==void 0&&{index:t.index}},this.metadata=x({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Yg(r)||At(t.annotations,n.id))return null;const i=JT(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:ws(t.annotations,i),s=It(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:R(t,{annotations:Nn(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new ba({id:n.id},this.metadata):new cc({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},ZT={type:"add-annotation",deserialize:(e,t)=>new Sa({kind:e.kind,annotation:e.annotation,index:e.index},t)},JT=(e,t)=>{const r=fa(t);return r===null?null:nc(e,r)},QT=(e,t)=>{const r=xa(e);return r===null?null:uc(r.points,t)},eL=e=>xa(e)!==null,tL=(e,t)=>{const r=xa(e);if(r===null)return null;const n=uc(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},xa=e=>{const t=nL[e.kind];return t===null?null:t(e.annotation)},ro=(e,t)=>e.anchorType!=="panel"?null:{points:[cn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},no=(e,t)=>e.anchorType!=="panel"?null:{points:[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},rL=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[cn(e,e.offset),cn(t,t.offset)],createPatch:r=>({start:{...e,x:e.x+r.x,y:e.y+r.y},end:{...t,x:t.x+r.x,y:t.y+r.y}})},nL={text:e=>ro(e.at,t=>({at:t})),sticker:e=>ro(e.at,t=>({at:t})),shape:e=>no(e.region,t=>({region:t})),image:e=>no(e.region,t=>({region:t})),arrow:e=>rL(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},cn=(e,t)=>t===void 0||t.unit==="px"?{x:e.x,y:e.y}:{x:e.x+(t.x??0),y:e.y+(t.y??0)},uc=(e,t)=>({x:ao(e.map(r=>r.x),t.x),y:ao(e.map(r=>r.y),t.y)}),ao=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:(0,Je.default)(t,r,n)},dc=(e,t,r)=>{const n=t.annotation;if(!oL(n,r))return null;const a=It(e.annotations,t.kind),i=aL(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:R(e,{annotations:Nn(e.annotations,t.kind,o)}),inverse:iL(n,r)}},aL=(e,t)=>{const r=new Set(Object.entries(t).filter(([,n])=>n===void 0).map(([n])=>n));return Object.fromEntries(Object.entries({...e,...t}).filter(([n])=>!r.has(n)))},iL=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},oL=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),Aa=class pc{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=x({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=At(t.annotations,n);if(i===null||i.kind!==r)return null;const o=dc(t,i,a);return o===null?null:{spec:o.spec,revert:new pc({kind:r,id:n,patch:o.inverse},this.metadata)}}},sL={type:"update-annotation",deserialize:(e,t)=>new Aa(e,t)},mc=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=x({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=At(e.annotations,this.params.id);if(t===null)return null;const r=tL(t,this.params.translation);if(r===null)return null;const n=dc(e,t,r);return n===null?null:{spec:n.spec,revert:new Aa({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},lL={type:"move-annotation",deserialize:(e,t)=>new mc(e,t)},ve=class qt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=x({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],o=ya(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new qt({list:r,rule:s,index:o},this.metadata),g=i.filter(v=>!Tr(v,n));return{spec:$r(t,r,g),revert:f}}if(s!==void 0){if(lc(s.declarations,c))return null;const f={...s,declarations:c},g=new qt({list:r,rule:s,index:o},this.metadata),v=i.map(y=>y===s?f:y);return{spec:$r(t,r,v),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),p={...n,declarations:c},h=[...i.slice(0,d),p,...i.slice(d)],m=new qt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:$r(t,r,h),revert:m}}},cL=e=>{const{rule:t}=e;if(t==null)throw new l.UserInputError({code:"INVALID_STYLE_RULE",message:"Command 'set-style-rule' is missing its 'rule'.",suggestion:"Send the entry's 'select' (and 'when') with 'declarations: null' to remove it."})},uL={type:"set-style-rule",deserialize:(e,t)=>(cL(e),new ve(e,t))},$r=(e,t,r)=>R(e,{styles:{...e.styles,[t]:r}}),dL={type:"set-difference-arrow-style",deserialize:(e,t)=>new hc(e,t)},hc=class fc{constructor(t,r={}){this.type="set-difference-arrow-style",this.params=t,this.metadata=x({...r,description:"Set difference arrow style"})}get target(){return{kind:"annotation",id:this.params.annotationId}}apply(t){const{annotationId:r,arrow:n,label:a}=this.params,i={target:"annotation",kind:"differenceArrow",annotation:r},o={...i,part:"label"};let s=t;const c={annotationId:r},u=d=>{const p=Ct(s.styles.overrides,d),h=new ve({list:"overrides",rule:d}).apply(s);if(h)return s=h.spec,p?.declarations??null};if(n!==void 0){const d=u({select:i,declarations:n});d!==void 0&&(c.arrow=d)}if(a!==void 0){const d=u({select:o,declarations:a});d!==void 0&&(c.label=d)}return s===t?null:{spec:s,revert:new fc(c,this.metadata)}}},pL=["cartesian","polar","flip"],J=new hr,gc=e=>J.has(e)?J.get(e):null,yc=new l.TransformRegistry,mL=new Ns(yc),Lr=e=>{const t=e.transforms.every(r=>yc.has(r.transformType));return e.transforms.length===0||!t?e.data:mL.compile({data:e.data,transforms:e.transforms})};function Ia(e,t){const r=t.some(i=>i.yScaleType==="secondary"),n=e.find(i=>i.scaledAesthetic==="ySecondary");if(!r)return n===void 0?e:e.filter(i=>i!==n);if(n!==void 0)return e;const a=e.find(i=>i.scaledAesthetic==="y");return a===void 0?e:[...e,{...a,scaledAesthetic:"ySecondary"}]}function Dt(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function _t(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:R(e,{scales:wo(e.scales,n,r)})}function Pt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function un(e,t,r){const n=gr(On(Bs(J),{data:Lr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Mn(n):n}var vc=class bc{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:LL(t)})}apply(t){const r="previous"in this.params?this.params.previous:EL(t,this.params);if(r===null)return null;const n=R(t,r);return n===t?null:{spec:n,revert:new bc({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},hL={type:"set-chart-type",deserialize:(e,t)=>new vc(e,t)},Sc={type:"sum"},fL={type:"identity"},gL=["bar","line","area","point","tile"],Ta="tile",yL=["y","color"],vL=Object.values(l.LAYER_LABEL_VARIABLES),bL={coordType:"cartesian",geom:Ta,position:"identity"},Ot=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),SL=e=>{const t=e.layers.filter(ue),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=Ac(t);if(o!==null)return{coordType:"cartesian",comboType:o}}if(!t.every(o=>o.geom===r.geom&&o.position===r.position))return null;const{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},xL=e=>{if(!e)return!1;const t=e.layers.filter(ue);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:Ic(e,r)?Tc(e,r).length>=1:Er(e,e.data.groupVariableNamesByType().numeric).length>=2},AL=e=>e?Vc(e,bL)!==null:!1,IL=e=>xc(e)?.at(-1)?.id??null,xc=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(ue);return Ac(t)===null?null:t},Ac=e=>{const t=e.at(-1);if(e.length<2||t?.geom!=="line")return null;const r=e.slice(0,-1);if(r.every(a=>a.geom==="line"))return TL(e)?"lines":null;if(!r.every(a=>a.geom==="bar"))return null;const[n]=r;return n===void 0||!r.every(a=>a.position===n.position)?null:l.readComboTypeOfBarPosition(n.position)},TL=e=>e.some(t=>t.yScaleType==="secondary"||ar(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,LL=e=>"previous"in e?"Restore the previous chart type":Ot(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,EL=(e,t)=>{const r=Vc(e,t);if(r===null)return null;const n=Ot(t)?RL(r,t):wL(r,t,e);return n===null||r===e?n:{...n,scales:GL({...e,...n},n.scales)}},wL=(e,t,r)=>{if(Ot(t)||!UL(t))return null;const n={...e,layers:Nc(e.layers)},a=KL(n.layers.filter(ue),t),i=Fc(n.coords,t),o=Rc(n,t),s=kc({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:Ia($c(r,s,i.coordType),s),mapping:o}},RL=(e,t)=>{const r=DL(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=zL(r.filter(ue),t.comboType),i=Fc(n.coords,t),o=Rc(n,t),s=kc({...n,mapping:o},t,a,o!==n.mapping),c=CL(e)?s:VL(s);return{coords:i,layers:c,scales:Ia($c(e,c,i.coordType),c),mapping:o}},CL=e=>xc(e)!==null,VL=e=>{const t=e.filter(ue).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},DL=(e,t)=>{const r=e.layers.filter(ue);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:Ic(e,n)?_L(e,n):PL(e,n,t)},Ic=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},_L=(e,t)=>{const[r]=Tc(e,t);if(r===void 0)return null;const n=Ue(J,e.mapping,e.coords.coordType,{type:"layer",id:Lc(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:Sc,...wc(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},Er=(e,t)=>{const r=Mt(e);return t.filter(n=>n!==r)},Tc=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return Er(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},Mt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),PL=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=Er(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,Mt(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=OL(t,io(a.slice(0,-1),o,s)),u=Ue(J,e.mapping,e.coords.coordType,{type:"layer",id:Lc(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...io([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Lc=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},io=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?wc(n,r):Ec(e,t)},Ec=(e,t)=>({mapping:{y:l.DEFAULT_RESHAPE_VALUE_NAME,color:"key"},transforms:[l.transform.reshape({keep:t,reshape:e,keyName:"key",valueName:l.DEFAULT_RESHAPE_VALUE_NAME})]}),wc=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),OL=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Rc=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Cc(t)?"":Mt(e);return n===r?e.mapping:{...e.mapping,x:n}},Cc=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",ML=e=>!Ot(e)&&e.geom===Ta,kL=e=>e.layers.filter(ue).some(t=>t.geom===Ta),Vc=(e,t)=>{const r=ML(t);return r===kL(e)?e:r?NL({...e,layers:Nc(e.layers)}):BL(e)??e},NL=e=>{const t=_c(e);if(t===null)return null;const r=FL(e,t)===null?$L(e,t):Pc(e,t);return r===null?null:Dc(e,t,r)},BL=e=>{const t=_c(e);if(t===null)return null;const r=Pc(e,t);return r===null?null:Dc(e,t,r)},Dc=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),_c=e=>{const t=e.layers.filter(ue);return t.length===1?t[0]??null:null},Pc=(e,t)=>{const r={...e.mapping,...t.mapping};return r.y===void 0||r.color===void 0?null:{mapping:{...e.mapping,y:r.color,color:r.y},layer:Oc(t)}},Oc=e=>{if(e.mapping.y===void 0&&e.mapping.color===void 0)return e;const{y:t,color:r,...n}=e.mapping;return{...e,mapping:n}},FL=(e,t)=>{const r={...e.mapping,...t.mapping},n=l.extractVariableName(r.color),a=l.extractVariableName(r.y);if(n===null||n===""||a===null||a===""||n===Mt(e))return null;const i=Lr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},$L=(e,t)=>{const r=Er(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,Mt(e)),a=Ec(r,n),i=Oc(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},GL=(e,t)=>yL.reduce((r,n)=>{const a=un(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Be(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),UL=e=>pL.includes(e.coordType)&&Mc(e.geom)&&HL(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),HL=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=J.get(e);return n.includes(t)&&a.includes(r)},Mc=e=>gL.includes(e),ue=e=>Mc(e.geom)&&!WL(e.stat),WL=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},KL=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},zL=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,o)=>n===null||o===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:YL(i,t,n)}]);return new Map(a)},YL=(e,t,r)=>e.geom!=="bar"||ar(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,kc=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Is(J,Be(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=qL(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?XL(e,{...i,stat:s},t.coordType,o):i}))},qL=(e,t,r)=>Cc(r)?e.type==="identity"?Sc:e:jL(t)&&e.type==="sum"?fL:e,jL=e=>e.coordType==="polar"&&e.params.theta==="y",XL=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:o,format:s,offset:c,justify:u,...d}=t.dataLabels;return{...Ue(J,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:s},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Nc=e=>{const t=e.filter(ue);if(t.length<2||!e.some(ar))return e;const[r]=t;return e.flatMap(n=>n===r?[ZL(n)]:ar(n)?[]:[n])},ar=e=>Bc(e)!==null,Bc=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:vL.includes(t.options.variableName)?t:null},ZL=e=>{const t=Bc(e);if(t===null)return e;const{color:r,...n}=e.mapping,a=t.transformType==="reshape"?t.options.reshape?.[0]:void 0;return{...e,mapping:a===void 0?n:{...n,y:a},transforms:e.transforms.slice(0,-1)}},Fc=(e,t)=>{const r=JL(e,t);return(0,Xt.default)(r,e)?e:r},JL=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Zr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Kt;return Zr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},$c=(e,t,r)=>{const n=qr(J,t),a=qr(J,e.layers),i=e.coords.coordType==="polar";return Be(e.scales,o=>{const s=QL(o,n,a),c=eE(s,n,a);return rE(c,r,i)})},QL=(e,t,r)=>{if(e.scaleType==="discrete"){const a=t.bandPadding[e.scaledAesthetic];return a===void 0||e.padding===a?e:{...e,padding:a}}if(e.scaledAesthetic===t.discreteAxis)return Xr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Xr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=tE(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},eE=(e,t,r)=>{if(e.scaleType!=="discrete"||!$e(e.scaledAesthetic))return e;const n=t.bandPadding[e.scaledAesthetic];if(n===r.bandPadding[e.scaledAesthetic])return e;const a=n??l.DISCRETE_SCALE_DEFAULTS.padding;return e.padding===a?e:{...e,padding:a}},tE=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,rE=(e,t,r)=>{if(e.scaleType!=="discrete"||!$e(e.scaledAesthetic))return e;if(t==="polar")return e.padding===0?e:{...e,padding:0};if(!r)return e;const{padding:n}=l.DISCRETE_SCALE_DEFAULTS;return e.padding===n?e:{...e,padding:n}},Gc=class Uc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:aE(t)})}apply(t){const r="previous"in this.params?this.params.previous:iE(t,this.params);if(r===null)return null;const n=R(t,r);return n===t?null:{spec:n,revert:new Uc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},nE={type:"set-mapping",deserialize:(e,t)=>new Gc(e,t)},Hc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Wc=e=>e===""?null:e,aE=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Wc(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},iE=(e,{aesthetic:t,variable:r})=>{if(!FT(t))return null;const n=Wc(r),a=sE(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:cE(e,t,a,n),layers:oE(e.layers,a)}},oE=(e,t)=>Be(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&gc(r.geom)===null)return r;const a=As(J,r.geom,r.position,n);return(0,Xt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),sE=(e,t,r)=>r===null?lE(e,t):Hc(e,t)===r?e:{...e,[t]:r},lE=(e,t)=>{if(t==="x")return l.readMainAxisVariable(e)===""?e:{...e,x:""};const r=e[t];if(r===void 0||l.extractVariableName(r)==="")return e;const n={};for(const[a,i]of Object.entries(e))a!==t&&(n[a]=i);return n},cE=(e,t,r,n)=>{if(!Ho(t))return e.scales;let a=e.scales;for(const i of uE(e,t))a=pE(e,a,i,r,n);return a},uE=(e,t)=>t==="y"&&dE(e.layers)?["y","ySecondary"]:[t],dE=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},pE=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,un(e,r,n)];if(a===null&&!$e(r)||a!==null&&!Lr(e).hasVariable(a))return t;const o=un(e,r,n);return mE(i,o)?t:Be(t,s=>s.scaledAesthetic===r?o:s)},mE=(e,t)=>e.scaleType===t.scaleType||oo(e)&&oo(t),oo=e=>e.scaleType==="discrete"||e.scaleType==="palette",La=e=>e==="both"?["x","y"]:[e],Kc=e=>e==="both"?"the":`${e} axis`;function Ea(e,t){return wr(e)?e[t]:e}function hE(e,t){return e.config.axes[t]??{}}function fE(e,t,r){if(t!=="ySecondary")return P(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=zc(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,R(e,{config:R(e.config,{axes:i})})}function wr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function zc(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],o=a in t?gE(i,t[a]):i;o!==i&&(n=!0),o!==void 0&&(r[a]=o)}return n?Object.keys(r).length>0?r:void 0:e}function gE(e,t){return l.isPlainObject(t)?zc(l.isPlainObject(e)?e:void 0,t):t}var Yc=class qc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${vE(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=hE(t,r).label;if(a===n)return null;const i=fE(t,r,{label:n});return i===t?null:{spec:i,revert:new qc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},yE={type:"set-axis-label",deserialize:(e,t)=>new Yc(e,t)};function vE(e){return e===void 0?"(inherited)":e??"(none)"}var jc=class Xc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:P(t,{config:{axes:{[r]:{position:n}}}}),revert:new Xc({axis:r,position:a},this.metadata)}}},bE={type:"set-axis-position",deserialize:(e,t)=>new jc(e,t)},Zc=class Jc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new Jc({axis:r,tickMode:a},this.metadata)}}},SE={type:"set-axis-tick-mode",deserialize:(e,t)=>new Zc(e,t)},Qc=class eu{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new eu({axis:r,isVisible:a},this.metadata)}}},xE={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new Qc(e,t)},tu=class ru{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new ru({axis:r,isVisible:a},this.metadata)}}},AE={type:"set-axis-visibility",deserialize:(e,t)=>new tu(e,t)},nu=class au{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=x({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:P(t,{config:{content:{caption:this.params.caption}}}),revert:new au({caption:r},this.metadata)}}},IE={type:"set-content-caption",deserialize:(e,t)=>new nu(e,t)},iu=class ou{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=x({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(nt(r,this.params.source))return null;const n=R(t.config.content,{source:this.params.source});return{spec:R(t,{config:R(t.config,{content:n})}),revert:new ou({source:r},this.metadata)}}},TE={type:"set-content-source",deserialize:(e,t)=>new iu(e,t)},su=class lu{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=x({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:P(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new lu({subtitle:r},this.metadata)}}},LE={type:"set-content-subtitle",deserialize:(e,t)=>new su(e,t)},cu=class uu{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=x({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:P(t,{config:{content:{title:this.params.title}}}),revert:new uu({title:r},this.metadata)}}},EE={type:"set-content-title",deserialize:(e,t)=>new cu(e,t)},wE="dashed",RE=1,du=(e,t,r,n)=>{const a=CE(t,r),i=DE(e,a,n);let o=e,s=!1;for(const c of a){const u=PE(o,c,n,_E(n,VE(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},CE=(e,t)=>e==="both"&&!wr(t)?[void 0]:La(e),VE=(e,t)=>t===void 0?wr(e)?e.x:e:Ea(e,t),DE=(e,t,r)=>t.length===1?Gr(e,t[0],r):{x:Gr(e,"x",r),y:Gr(e,"y",r)},Gr=(e,t,r)=>pu(e.styles.overrides,t)?.[r]??null,_E=(e,t)=>t===null||e==="lineType"&&t===wE||e==="strokeWidth"&&t===RE?null:t,PE=(e,t,r,n)=>{const a=pu(e.styles.overrides,t);return(a?.[r]??null)===n?null:new ve({list:"overrides",rule:kE(t,ME(a,r,n))}).apply(e)?.spec??null},OE=e=>e.select.target==="gridLine",pu=(e,t)=>{const r=Ct(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!OE(r)))return r.declarations},ME=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},kE=(e,t)=>t===null?e===void 0?{select:{target:"gridLine"},declarations:null}:{select:{target:"gridLine",axis:e},declarations:null}:e===void 0?l.style.gridLine(t):e==="x"?l.style.gridLine.x(t):l.style.gridLine.y(t),mu=class hu{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${Kc(t.axis)} grid line style to ${BE(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=du(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new hu({axis:r,lineStyle:a.previous},this.metadata)}}},NE={type:"set-grid-line-style",deserialize:(e,t)=>new mu(e,t)},BE=({axis:e,lineStyle:t})=>{const r=La(e).map(n=>Ea(t,n)??"(theme)");return[...new Set(r)].join(" and ")},FE={type:"set-grid-line-width",deserialize:(e,t)=>new fu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-grid-line-width";const n=$E(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${Kc(t.axis)} grid line width to ${GE(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=du(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new gu({axis:r,lineWidth:a.previous},this.metadata)}}},$E=e=>wr(e)?{x:Ur(e.x),y:Ur(e.y)}:Ur(e),Ur=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),GE=(e,t)=>{const r=La(e).map(n=>Ea(t,n)??"(theme)");return[...new Set(r)].join(" and ")},yu=class vu{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new vu({axis:r,isVisible:a},this.metadata)}}},UE={type:"set-grid-visibility",deserialize:(e,t)=>new yu(e,t)},bu=class Su{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:P(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Su({compareWith:r},this.metadata)}}},HE={type:"set-headline-compare-with",deserialize:(e,t)=>new bu(e,t)},xu=class Au{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:P(t,{config:{headline:{position:this.params.position}}}),revert:new Au({position:r},this.metadata)}}},WE={type:"set-headline-position",deserialize:(e,t)=>new xu(e,t)},Iu=class Tu{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:P(t,{config:{headline:{show:this.params.show}}}),revert:new Tu({show:r},this.metadata)}}},KE={type:"set-headline-show",deserialize:(e,t)=>new Iu(e,t)},Lu=class Eu{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:P(t,{config:{headline:{size:this.params.size}}}),revert:new Eu({size:r},this.metadata)}}},zE={type:"set-headline-size",deserialize:(e,t)=>new Lu(e,t)},YE={type:"set-highlight-dim-style",deserialize:(e,t)=>new wu(e,t)},wu=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=x({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Ru(e)===this.params.dimStyle)return null;const t=new ve({list:"overrides",rule:jE(this.params.dimStyle)},this.metadata).apply(e);return t||null}},qE={select:{target:"geom"},when:{state:"dimmed"}},Ru=e=>{const t=Ct(e.styles.overrides,qE);return(t!==void 0&&va(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},jE=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Cu=class Vu{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:P(t,{config:{legend:{align:this.params.align}}}),revert:new Vu({align:r},this.metadata)}}},XE={type:"set-legend-align",deserialize:(e,t)=>new Cu(e,t)},Du=class _u{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:P(t,{config:{legend:{display:this.params.display}}}),revert:new _u({display:r},this.metadata)}}},ZE={type:"set-legend-display",deserialize:(e,t)=>new Du(e,t)},Pu=class Ou{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:P(t,{config:{legend:{position:this.params.position}}}),revert:new Ou({position:r},this.metadata)}}},JE={type:"set-legend-position",deserialize:(e,t)=>new Pu(e,t)},Mu=class ku{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:P(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new ku({abbreviation:r},this.metadata)}}},QE={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Mu(e,t)},Nu=class Bu{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:P(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Bu({decimals:r},this.metadata)}}},ew={type:"set-number-format-decimals",deserialize:(e,t)=>new Nu(e,t)},Fu=class $u{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=rw(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:P(t,{config:{content:{[a]:n}}}),revert:new $u({slot:r,isVisible:i},this.metadata)}}},tw={type:"toggle-content-visibility",deserialize:(e,t)=>new Fu(e,t)},so={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function rw(e){return Object.hasOwn(so,e)?so[e]:void 0}var Gu=class Uu{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if(nt(i.xLimits,a.xLimits)&&nt(i.yLimits,a.yLimits))return null;const o={};r!==void 0&&(o.xLimits=a.xLimits),n!==void 0&&(o.yLimits=a.yLimits);const s=new Uu(o,this.metadata);return{spec:R(t,{coords:aw(t.coords,i)}),revert:s}}},nw={type:"set-coord-limits",deserialize:(e,t)=>new Gu(e,t)};function aw(e,t){switch(e.coordType){case"cartesian":return{...e,params:{...e.params,...t}};case"flip":return{...e,params:{...e.params,...t}};case"polar":return{...e,params:{...e.params,...t}}}}var Hu=class Wu{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Je.default)(t.innerRadius,0,1)},this.metadata=x({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:R(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Wu({innerRadius:n},this.metadata)}}},iw={type:"set-polar-inner-radius",deserialize:(e,t)=>new Hu(e,t)},ow={type:"set-polar-start-angle",deserialize:(e,t)=>new Ku(e,t)},Ku=class zu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:lo(t.startAngle)},this.metadata=x({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return lo(n)===this.params.startAngle?null:{spec:R(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new zu({startAngle:n},this.metadata)}}},Hr=360,lo=e=>(e%Hr+Hr)%Hr,wa=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=x({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new Ra({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:R(e,{highlights:n}),revert:a}}},sw={type:"remove-highlight",deserialize:(e,t)=>new wa(e,t)},Ra=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??W(),scope:e.scope??"data-point"},this.metadata=x({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const o=new wa({id:r},this.metadata),s={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:R(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},lw={type:"add-highlight",deserialize:(e,t)=>new Ra(e,t)};function Ca(e,t){return{...e,params:{...e.params,...t}}}function Rr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function Va(e,t){return R(e,{layers:[...e.layers,t]})}function ee(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:R(e,{layers:wo(e.layers,n,r)})}function Cr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:R(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Da=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=x({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=Cr(e,this.params.layerId);return n===e?null:{spec:n,revert:new _a({layer:r,index:t},this.metadata)}}},cw={type:"remove-layer",deserialize:(e,t)=>new Da(e,t)},_a=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??W()},...e.index!==void 0&&{index:e.index}},this.metadata=x({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:R(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Da({layerId:t.id},this.metadata)}}},uw={type:"add-layer",deserialize:(e,t)=>new _a(e,t)},Yu=class qu{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=x({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!ae(B(t.layers,r),"bar"))return null;const a=_e("bar",r),i=Vt(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new ve({list:"overrides",rule:{...a,declarations:pw(i,n)}}).apply(t);if(!s)return null;const c=new qu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},dw={type:"set-bar-border-radius",deserialize:(e,t)=>new Yu(e,t)},pw=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},mw={type:"set-bar-width",deserialize:(e,t)=>new Xu(e,t)},ju=.05,hw=1,Xu=class Zu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Je.default)(t.width,ju,1);this.params={...t,width:n},this.metadata=x({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"bar");if(!ae(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:ee(t,r.id,Ca(r,{width:this.params.width})),revert:new Zu({layerId:r.id,width:n},this.metadata)}}},Ju=class Qu{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=x({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:ee(t,r.id,Rr(r,{format:this.params.format})),revert:new Qu({layerId:r.id,format:n},this.metadata)}}},fw={type:"set-data-labels-format",deserialize:(e,t)=>new Ju(e,t)},ed=class td{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=x({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:ee(t,r.id,{...r,position:this.params.position}),revert:new td({layerId:r.id,position:n},this.metadata)}}},gw={type:"set-layer-position",deserialize:(e,t)=>new ed(e,t)},rd=class nd{constructor(t,r={}){this.type="set-layer-stat";const n=xs(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=x({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return vw(n,this.params.stat)?null:{spec:ee(t,r.id,{...r,stat:this.params.stat}),revert:new nd({layerId:r.id,stat:n},this.metadata)}}},yw={type:"set-layer-stat",deserialize:(e,t)=>new rd(e,t)},vw=(e,t)=>{if(e.type!==t.type)return!1;const r=e,n=t,a=new Set([...Object.keys(r),...Object.keys(n)]);for(const i of a)if(!Object.is(r[i],n[i]))return!1;return!0},ad=class id{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=x({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=ee(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:R(a,{scales:Ia(a.scales,a.layers)}),revert:new id({layerId:r.id,yScaleType:n},this.metadata)}}},bw={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ad(e,t)},od=class sd{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=x({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:ee(t,r.id,Ca(r,{interpolate:this.params.interpolate})),revert:new sd({layerId:r.id,interpolate:n},this.metadata)}}},Sw={type:"set-line-interpolation",deserialize:(e,t)=>new od(e,t)},ld=class cd{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=x({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:ee(t,r.id,Ca(r,{missingValues:this.params.missingValues})),revert:new cd({layerId:r.id,missingValues:n},this.metadata)}}},xw={type:"set-line-missing-values",deserialize:(e,t)=>new ld(e,t)},ud=class dd{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=x({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=B(t.layers,r);if(!ae(a,"line","area"))return null;const i=Vt(t.styles.overrides,_e(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=Iw(i,n),c=new ve({list:"overrides",rule:a.geom==="area"?{..._e("area",r),declarations:s}:{..._e("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new dd({layerId:r,lineWidth:o},this.metadata)}:null}},Aw={type:"set-line-width",deserialize:(e,t)=>new ud(e,t)},Iw=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},pd=class md{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=x({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!ae(B(t.layers,r),"point"))return null;const a=_e("point",r),i=Vt(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new ve({list:"overrides",rule:{...a,declarations:Lw(i,n)}}).apply(t);return s?{spec:s.spec,revert:new md({layerId:r,size:o},this.metadata)}:null}},Tw={type:"set-point-size",deserialize:(e,t)=>new pd(e,t)},Lw=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},hd=class fd{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=x({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"rule");if(!ae(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([o])=>o!=="label")):{...r.params,label:a};return{spec:ee(t,r.id,{...r,params:i}),revert:new fd({layerId:r.id,label:n??null},this.metadata)}}},Ew={type:"set-rule-label",deserialize:(e,t)=>new hd(e,t)},gd=class yd{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=x({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"rule");if(!ae(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:ee(t,r.id,{...r,mapping:i}),revert:new yd({layerId:r.id,value:a},this.metadata)}}},ww={type:"set-rule-value",deserialize:(e,t)=>new gd(e,t)},Rw={type:"set-stat-line",deserialize:(e,t)=>new vd(e,t)},vd=class bd{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:Mw(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=Vw(t),n=this.buildStatLine(t,r?.line===this.params.line?r.layer.id:void 0);if(this.params.line!=="none"&&n===null||r===void 0&&n===null||r!==void 0&&n!==null&&Ow(r.layer,n))return null;const a=new bd({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:ee(t,r.layer.id,n),revert:a};const i=r===void 0?t:Cr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:Va(i,n),revert:a}}buildStatLine(t,r){if(this.params.line==="none")return null;if(this.params.removedLayer!==void 0)return this.params.removedLayer;const n=this.params.line==="trend"?Dw(this.params):_w(t,this.params);if(n===null)return null;const a=Ue(J,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},Cw="linear",Vw=e=>{const t=ic(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=oc(e.layers);if(r!==void 0)return{line:"average",layer:r}},Dw=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??Cw}),interactive:!1}),_w=(e,{group:t,label:r})=>{const n=Pw(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),o=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:o?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},Pw=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),Ow=(e,t)=>(0,at.isEqual)({...e,id:""},{...t,id:""}),Mw=e=>e==="none"?"Hide stat line":`Show ${e} line`,Sd=class xd{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=x({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:ee(t,r.id,Rr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new xd({layerId:r.id,showCategoryLabels:n},this.metadata)}}},kw={type:"toggle-category-labels",deserialize:(e,t)=>new Sd(e,t)},Ad=class Id{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=x({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:ee(t,r.id,Rr(r,{showDataLabels:this.params.showDataLabels})),revert:new Id({layerId:r.id,showDataLabels:n},this.metadata)}}},Nw={type:"toggle-data-labels",deserialize:(e,t)=>new Ad(e,t)},Bw={type:"toggle-goal-line",deserialize:(e,t)=>new Td(e,t)},Td=class dn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=x({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=ac(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=Cr(t,r.id);return a===t?null:{spec:a,revert:new dn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:Va(t,n),revert:new dn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ue(J,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??Fw}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},Fw=0,$w={type:"toggle-line-fill",deserialize:(e,t)=>new Ld(e,t)},Ld=class Ed{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=x({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!ae(B(t.layers,r),"line"))return null;const i=_e("line",r),o=Vt(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new ve({list:"overrides",rule:{...i,declarations:Uw(o,n?a??Gw:null)}}).apply(t);if(!u)return null;const d=new Ed({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},Gw=.2,Uw=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},Hw={type:"toggle-line-points",deserialize:(e,t)=>new wd(e,t)},wd=class pn{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=x({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");return ae(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:Va(t,this.params.removedLayer??Ue(J,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new pn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:Cr(t,n.id),revert:new pn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:wn(n,[r]))}},Rd=class Cd{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=x({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:ee(t,r.id,Rr(r,{showStackTotals:this.params.showStackTotals})),revert:new Cd({layerId:r.id,showStackTotals:n},this.metadata)}}},Ww={type:"toggle-stack-totals",deserialize:(e,t)=>new Rd(e,t)},Vd=class Dd{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const o={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},s=_t(t,this.params.scaledAesthetic,o),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:s,revert:new Dd(c,this.metadata)}}},Kw={type:"set-scale-domain",deserialize:(e,t)=>new Vd(e,t)},_d=class Pd{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||nt(r.palette,this.params.palette)?null:{spec:_t(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Pd({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},zw={type:"set-scale-palette",deserialize:(e,t)=>new _d(e,t)},Od=class Md{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||!qw(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:_t(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Md({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},Yw={type:"set-scale-reverse",deserialize:(e,t)=>new Od(e,t)};function qw(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var kd=class Nd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:_t(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Nd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},jw={type:"set-scale-transform",deserialize:(e,t)=>new kd(e,t)},Bd=class Fd{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:_t(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Fd({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},Xw={type:"set-scale-zero",deserialize:(e,t)=>new Bd(e,t)},$d=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new $d;S.register(hL);S.register(nE);S.register(uw);S.register(cw);S.register(fw);S.register(gw);S.register(yw);S.register(bw);S.register(Sw);S.register(Aw);S.register(dw);S.register(mw);S.register(Tw);S.register(xw);S.register(Ew);S.register(ww);S.register(Rw);S.register(kw);S.register(Nw);S.register(Bw);S.register($w);S.register(Hw);S.register(Ww);S.register(Kw);S.register(zw);S.register(Yw);S.register(jw);S.register(Xw);S.register(yE);S.register(SE);S.register(bE);S.register(xE);S.register(AE);S.register(IE);S.register(TE);S.register(LE);S.register(EE);S.register(NE);S.register(FE);S.register(UE);S.register(HE);S.register(WE);S.register(KE);S.register(zE);S.register(YE);S.register(XE);S.register(ZE);S.register(JE);S.register(QE);S.register(ew);S.register(tw);S.register(lw);S.register(sw);S.register(uL);S.register(ZT);S.register(XT);S.register(sL);S.register(dL);S.register(lL);S.register(nw);S.register(iw);S.register(ow);var Gd=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return!1;switch(e.kind){case"annotation":return t.kind==="annotation"&&e.id===t.id;case"highlight":return t.kind==="highlight"&&e.id===t.id;case"styleRule":return t.kind==="styleRule"&&e.list===t.list&&Tr(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observations":return t.kind==="observations"&&e.layerId===t.layerId&&e.scope===t.scope&&Rt(e.predicate,t.predicate);case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"graph":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},Ud=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,o=e.apply(t);if(!o)return a||(this.hasOpenRun=!1),i(t,null);const s=r?.({spec:o.spec,command:e})??null,c=s?s.adopted:o.spec;return c?(this.push(e,c,o.revert,a),i(c,s?.value??null)):(a||(this.hasOpenRun=!1),i(t,s?.value??null))})}seal(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"seal"}),!0):!1)}undo(e,t){return this.withReentrancyGuard(()=>{const r=this.undoStack[this.undoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.undoStack.pop(),this.redoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"undo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}redo(e,t){return this.withReentrancyGuard(()=>{const r=this.redoStack[this.redoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.redoStack.pop(),this.undoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"redo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}clear(){this.withReentrancyGuard(()=>{this.hasOpenRun=!1,!(this.undoStack.length===0&&this.redoStack.length===0)&&(this.undoStack=[],this.redoStack=[],this.emit({type:"clear"}))})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null,undoStack:co(this.undoStack),redoStack:co(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],o=this.hasOpenRun&&i!==void 0&&Jw(i.command,e);if(n&&o){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},Zw=Object.freeze([]),Jw=(e,t)=>e.type===t.type&&Gd(e.target,t.target),co=e=>e.length===0?Zw:e.map(t=>t.command.metadata),Qw=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.seal(),t=this.frame;return this.frame=null,e?t:null}},eR=class{constructor(e){this.compiler=e,this.history=new Ud,this.current=null,this.last=null,this.hostInput=null,this.run=new Qw(this.history)}get compiled(){return this.current}compile(e){return this.last=e,this.hostInput=e.input,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.input!==this.hostInput&&e.input!==t.input,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes,i=!t||e.colorScheme!==t.colorScheme;if(this.hostInput=e.input,!r&&!n&&!a&&!i)return null;let o=null;r?this.run.close():o=this.closeAndConvert();const s=this.last,c=s&&!r?s.input:e.input;this.last={input:c,data:e.data,customPalettes:e.customPalettes,colorScheme:e.colorScheme};const u=this.current,d=r||a||!u?this.absorb(this.compiler.compile(this.last)):this.absorb(this.compiler.recompile({spec:u.spec,data:e.data,colorScheme:e.colorScheme}));return r&&d.ok&&this.history.clear(),{result:d,inputChanged:r,...o&&{sealedInput:o.input}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.sealNotification(!1);c&&n.push(c)}const{current:a,last:i,history:o}=this;if(!a||!i)return n;const s=o.apply(e,a.spec,({spec:c})=>{const u=this.commit(c,i,r,e);return{adopted:u.ok?u.compiled.spec:null,value:u}},t);return s&&n.push(this.renderedNotification(s,e,r)),n}seal(){const e=this.sealNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const o=this.commit(a,r);return{adopted:o.ok?o.compiled.spec:null,value:{result:o,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{compiled:e.compiled}:{compiled:e.compiled,result:e,command:t,...e.input&&{input:e.input}}:{errors:e.errors}}sealNotification(e){const t=this.closeAndConvert();return t?{result:t.result,input:t.input,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{input:this.recordCompiledInput(t.spec,r),result:e.result,command:e.command}}commit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e,colorScheme:t.colorScheme});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const o={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:o,command:n}),o}this.run.clear();const i=this.recordCompiledInput(a.compiled.spec,t);return{ok:!0,compiled:a.compiled,warnings:a.warnings,input:i}}recordCompiledInput(e,t){const r=sc(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes,colorScheme:t.colorScheme},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},tR=new Set(["x","y"]),uo=["numeric","categorical","temporal"],po=["numeric"],rR=(e,t)=>{const r=e.layers.map(a=>gc(a.geom)).filter(l.isDefined),n=Lr(e);return t.filter(a=>nR(e,r,a)).map(a=>({aesthetic:a,variables:aR(n,r,a),isRequired:tR.has(a)}))},nR=(e,t,r)=>{switch(r){case"x":return!sR(e.coords);case"y":return!0;case"label":return t.some(n=>n.dataLabelCoordTypes.includes(e.coords.coordType));default:return t.some(n=>n.aesthetics.some(a=>a.kind==="visual"&&a.name===r))}},aR=(e,t,r)=>{const n=iR(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},iR=(e,t)=>t==="size"?po:t!=="x"&&t!=="y"?uo:oR(e,t)?po:uo,oR=(e,t)=>e.some(r=>r.positionRoles.some(n=>Uo.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),sR=e=>e.coordType==="polar"&&e.params.theta==="y",lR=500,cR="normal",Pa={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},uR=e=>{const t=e.style??"normal",r=e.weight??500,n=e.family.includes(",")?e.family:`'${e.family}'`;return`${t} ${r} ${e.size}px ${n}`},Oa=e=>typeof e!="string"?e??500:Pa[e],dR="\0",pR=class{constructor(e){this.inner=e,this.cache=new Map}measureText(e,t){const r=this.getCacheKey(e,t),n=this.cache.get(r);if(n)return n;const a=this.inner.measureText(e,t);return this.cache.set(r,a),a}getCacheKey(e,t){return[t.family,t.size,Oa(t.weight),t.style??"normal",e].join(dR)}},mR={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56};var hR=1.05,fR=.84,gR=.21,yR=class{measureText(e,t){let r=0;for(const i of e)r+=(mR[i]??.55)*t.size;Oa(t.weight)>=Pa.semiBold&&(r*=hR);const n=fR*t.size,a=gR*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_PARTS=l.ANNOTATION_PARTS;exports.ANNOTATION_STYLE_KINDS=l.ANNOTATION_STYLE_KINDS;exports.ANNOTATION_TOOLTIP_MARKER_GAP=kS;exports.ARROW_DEFAULTS=l.ARROW_DEFAULTS;exports.ARROW_STICKER_DECLARATIONS=l.ARROW_STICKER_DECLARATIONS;exports.ARROW_STROKE_WIDTHS=l.ARROW_STROKE_WIDTHS;exports.AXIS_KEYS=In;exports.AddAnnotationCommand=Sa;exports.AddHighlightCommand=Ra;exports.AddLayerCommand=_a;exports.BORDER_RADIUS_PX=sa;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Hf;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Cy;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=pR;exports.CommandRegistry=$d;exports.CommandStackManager=Ud;exports.Compiler=Fs;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=cR;exports.DEFAULT_FONT_WEIGHT=lR;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRAPH_BORDER_WIDTH=l.DEFAULT_GRAPH_BORDER_WIDTH;exports.DEFAULT_GRAPH_PADDING=l.DEFAULT_GRAPH_PADDING;exports.DEFAULT_HEADLINE_SWATCH_SIZE=l.DEFAULT_HEADLINE_SWATCH_SIZE;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_MONO_BASE=l.DEFAULT_MONO_BASE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DIFFERENCE_ARROW_DEFAULTS=l.DIFFERENCE_ARROW_DEFAULTS;exports.DIFFERENCE_ARROW_SIZE_DECLARATIONS=l.DIFFERENCE_ARROW_SIZE_DECLARATIONS;exports.DIVERGING_SCHEME_NAMES=ys;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ye;exports.GraphCompilationSession=eR;exports.HEADING_PARTS=l.HEADING_PARTS;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=Ox;exports.HEADLINE_TREND_GAP=Nx;exports.HEADLINE_TREND_ICON_SIZE=kx;exports.HEADLINE_VALUE_LABEL_GAP=Mx;exports.HeuristicTextMeasurer=yR;exports.HoverEngine=SI;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=fn;exports.LayoutCompiler=sS;exports.MAX_BAR_WIDTH=hw;exports.MIN_BAR_WIDTH=ju;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=mc;exports.NAMED_WEIGHTS=Pa;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ha;exports.OUT_OF_VIEW_MARGIN_PX=NS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=ep;exports.POSITION_TYPES=xo;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=oe;exports.RemoveAnnotationCommand=ba;exports.RemoveHighlightCommand=wa;exports.RemoveLayerCommand=Da;exports.SCALED_POSITION_AESTHETIC_KEYS=Tn;exports.SCALED_VISUAL_AESTHETIC_KEYS=bt;exports.SCHEME_ALIASES=vs;exports.SEQUENTIAL_SCHEME_NAMES=Wf;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=BS;exports.SOURCE_PARTS=l.SOURCE_PARTS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=Yc;exports.SetAxisPositionCommand=jc;exports.SetAxisTickModeCommand=Zc;exports.SetAxisTicksVisibilityCommand=Qc;exports.SetAxisVisibilityCommand=tu;exports.SetBarBorderRadiusCommand=Yu;exports.SetBarWidthCommand=Xu;exports.SetChartTypeCommand=vc;exports.SetContentCaptionCommand=nu;exports.SetContentSourceCommand=iu;exports.SetContentSubtitleCommand=su;exports.SetContentTitleCommand=cu;exports.SetCoordLimitsCommand=Gu;exports.SetDataLabelsFormatCommand=Ju;exports.SetDifferenceArrowStyleCommand=hc;exports.SetGridLineStyleCommand=mu;exports.SetGridLineWidthCommand=fu;exports.SetGridVisibilityCommand=yu;exports.SetHeadlineCompareWithCommand=bu;exports.SetHeadlinePositionCommand=xu;exports.SetHeadlineShowCommand=Iu;exports.SetHeadlineSizeCommand=Lu;exports.SetHighlightDimStyleCommand=wu;exports.SetLayerPositionCommand=ed;exports.SetLayerStatCommand=rd;exports.SetLayerYScaleTypeCommand=ad;exports.SetLegendAlignCommand=Cu;exports.SetLegendDisplayCommand=Du;exports.SetLegendPositionCommand=Pu;exports.SetLineInterpolationCommand=od;exports.SetLineMissingValuesCommand=ld;exports.SetLineWidthCommand=ud;exports.SetMappingCommand=Gc;exports.SetNumberFormatAbbreviationCommand=Mu;exports.SetNumberFormatDecimalsCommand=Nu;exports.SetPointSizeCommand=pd;exports.SetPolarInnerRadiusCommand=Hu;exports.SetPolarStartAngleCommand=Ku;exports.SetRuleLabelCommand=hd;exports.SetRuleValueCommand=gd;exports.SetScaleDomainCommand=Vd;exports.SetScalePaletteCommand=_d;exports.SetScaleReverseCommand=Od;exports.SetScaleTransformCommand=kd;exports.SetScaleZeroCommand=Bd;exports.SetStatLineCommand=vd;exports.SetStyleRuleCommand=ve;exports.SpecResolver=Ls;exports.Stat=Ge;exports.TAU=he;exports.TEXT_ANNOTATION_DEFAULTS=l.TEXT_ANNOTATION_DEFAULTS;exports.TEXT_ANNOTATION_FADE_ALPHA=l.TEXT_ANNOTATION_FADE_ALPHA;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Sd;exports.ToggleContentVisibilityCommand=Fu;exports.ToggleDataLabelsCommand=Ad;exports.ToggleGoalLineCommand=Td;exports.ToggleLineFillCommand=Ld;exports.ToggleLinePointsVisibilityCommand=wd;exports.ToggleStackTotalsCommand=Rd;exports.UpdateAnnotationCommand=Aa;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=So;exports.annotation=zg;exports.areAnchorsEqual=Xe;exports.areEditMenuTriggersEqual=dx;exports.areEditTargetsEqual=Gd;exports.areEndpointsComparable=To;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=rc;exports.arePointerRegionListsEqual=ax;exports.arePredicatesEqual=Rt;exports.areStyleDeclarationsEqual=lc;exports.areStyleRuleAddressesEqual=Tr;exports.buildAverageLineSymbols=_S;exports.buildCalloutHitRegions=MS;exports.buildColumnKey=Rl;exports.buildDataLabelsContent=nb;exports.buildDiagnostic=Eo;exports.buildEditMenuTriggerRegion=cx;exports.buildFontString=uR;exports.buildLayerIntroPlan=DI;exports.buildLayerStyleAddress=_e;exports.buildLayerYValueFormatter=ra;exports.buildObservationPredicate=Il;exports.buildObservationsTarget=JS;exports.buildPinnedNumberValueFormatter=Ax;exports.buildPolarBarArcPath=Qx;exports.buildSliceGroupKey=Dl;exports.buildTooltipContent=rT;exports.canAnchorDirectLabels=Qo;exports.canBecomeCombo=xL;exports.canBecomeHeatmap=AL;exports.canPlaceDataLabels=rb;exports.clampAnnotationTranslation=QT;exports.commandRegistry=S;exports.compileChromeStyles=Vs;exports.compileStylesheetForLayer=ey;exports.compositeColor=go;exports.computeArrow=VS;exports.computeDifferenceArrow=hl;exports.computeDirectLabelsLayout=qS;exports.computeLineBoxHeight=fl;exports.computePanelBorderPaths=KI;exports.computePanelBorderSizes=zI;exports.config=l.config;exports.convertSpecToInput=sc;exports.coord=l.coord;exports.countLayerGeoms=_I;exports.createAlphaValueReader=lp;exports.createAnchorResolver=uS;exports.createAreaPathGenerators=Wx;exports.createColorValueReader=Ao;exports.createCompiler=Vy;exports.createDatasetFromKindPartitions=Hp;exports.createEmptyHighlight=es;exports.createGraphyBuilder=Py;exports.createGroupValueReader=cp;exports.createHeadlineItemRows=Bx;exports.createLabelValueReader=op;exports.createLineFillAreaGenerator=Xx;exports.createLinePathGenerator=jx;exports.createObservationAnchorBuilder=yt;exports.createObservationAnchorParser=Lo;exports.createRawValueReader=Q;exports.createSegmentYReader=gt;exports.createSizeValueReader=sp;exports.createSpec=Gs;exports.createStableBandKeyGenerator=nA;exports.createStableCellKeyGenerator=aA;exports.createStableKeyGenerator=Sr;exports.createStrokeWidthValueReader=up;exports.createStyleResolver=ot;exports.createValueFormatter=k;exports.createXValueReader=it;exports.createYValueReader=yn;exports.cursorToPiePlane=sr;exports.cursorToPolar=mn;exports.describeMeasurementBasis=Kr;exports.ensureReadableTextColor=Qd;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=xl;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=rh;exports.findAnnotation=At;exports.findAverageLineLayer=oc;exports.findAxisGuide=oa;exports.findDistinctLayers=Rn;exports.findEquivalentHighlight=MT;exports.findGoalLineLayer=ac;exports.findHighlightsAtObservation=mx;exports.findKindStyleDeclarations=Vt;exports.findLayerByGeom=Ee;exports.findLayerById=B;exports.findLegendForAesthetic=_x;exports.findObservationAttachment=nc;exports.findPointerRegion=rx;exports.findStyleRule=Ct;exports.findStyleRuleIndex=ya;exports.findTrendLineLayer=ic;exports.formatDifferenceLabel=pl;exports.formatHeadline=Ix;exports.formatLegends=Vx;exports.formatRuleValue=Px;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=H;exports.getAlpha=rl;exports.getAngleExtent=ea;exports.getBarRectBounds=wl;exports.getBoundingRect=qx;exports.getChromeDashArray=VT;exports.getColor=Et;exports.getCrossAxisCoordinate=ge;exports.getCurve=br;exports.getDashArray=Hx;exports.getDifferenceArrowDimensions=ml;exports.getDifferenceArrowLabelBox=gl;exports.getGroup=re;exports.getHoverGuideLineProps=TI;exports.getHoverGuideRectProps=LI;exports.getInsetTileRect=cl;exports.getLineType=nl;exports.getMainAxisCoordinate=Z;exports.getNumericWeight=Oa;exports.getPolarHoverGuideArcProps=EI;exports.getRadiusExtent=ta;exports.getRuleDashPattern=rA;exports.getScaledAesthetic=ap;exports.getShapeAnnotationStroke=bT;exports.getSize=Zn;exports.getStablePolarBarKeyGenerator=iA;exports.getStackRole=is;exports.getStrokeWidth=en;exports.getTileRectBounds=ll;exports.getUnionExtent=tA;exports.getX=M;exports.getXMax=X;exports.getXMin=j;exports.getY=D;exports.getYMax=F;exports.getYMin=G;exports.getYRaw=hn;exports.hasMultipleGroups=dr;exports.highlight=OT;exports.inferDefaultDifferenceArrowEndpoints=gx;exports.inferDifferenceArrowEndpoints=El;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=eL;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=mp;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=Ot;exports.isCompanionLayer=wn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=yo;exports.isGeomStyleRule=va;exports.isKeyedScope=aa;exports.isLayerOf=$s;exports.isLayerOfType=ae;exports.isLineStyleType=gn;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=DT;exports.isPointWithinEditMenuTrigger=ux;exports.isPointWithinRegionShape=ia;exports.isSafeUrl=QI;exports.isStackedPosition=U;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=$T;exports.normalizeAngle=Oe;exports.orderPointerRegions=nx;exports.paintsInDonutHole=vr;exports.pickReadableTextColor=fo;exports.pipe=Us;exports.placeCallouts=HS;exports.polarToUnit=fe;exports.positionToAngle=vo;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=Kx;exports.prepareLineObservations=Zx;exports.projectAnchorToPanel=tr;exports.projectRegionToPanel=mS;exports.quantiseKey=te;exports.readAnchoredObservation=vx;exports.readAttachedObservation=fa;exports.readAuthoredNumber=dT;exports.readAuthoredString=pT;exports.readBroadestObservationsScope=QS;exports.readChartType=SL;exports.readColorGroupObservation=oA;exports.readComboLineLayerId=IL;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Ru;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=rR;exports.readMappedVariable=Hc;exports.readObservationIndex=wI;exports.readXExtent=Jl;exports.readYExtent=Ql;exports.resolveAnchorVariable=Ne;exports.resolveArrowAnnotationStyle=hT;exports.resolveArrowColor=zS;exports.resolveAxisLabelStyle=Rb;exports.resolveBarBandFraction=jr;exports.resolveBarBorderRadiusPx=la;exports.resolveBarBorderTreatment=Yx;exports.resolveBarCornerRadiiPx=zx;exports.resolveCalloutAnnotationStyle=vT;exports.resolveCaptionStyle=Eb;exports.resolveChromeMargin=q;exports.resolveChromeMargins=RT;exports.resolveColorRamp=Pn;exports.resolveComparisonBasis=Jo;exports.resolveDataLabelStyle=Vb;exports.resolveDeferredAnchors=yS;exports.resolveDefinition=_n;exports.resolveDifferenceArrowAnnotationStyle=fT;exports.resolveDirectLabelStyle=Ob;exports.resolveGeomAnchorFrame=Sn;exports.resolveGraphChromeStyle=TT;exports.resolveGraphPadding=LT;exports.resolveGridLineStyle=xT;exports.resolveHeadingFontFamily=IT;exports.resolveHeadingStyle=Tb;exports.resolveHeadlineFigure=kb;exports.resolveHeadlineItemStyle=Mb;exports.resolveHeadlinePlacement=tS;exports.resolveHeadlineStyle=wT;exports.resolveHoverGuideStyle=CT;exports.resolveImageAnnotationStyle=yT;exports.resolveLegendItemStyle=Pb;exports.resolveLegendStyle=ET;exports.resolveObservationPoint=bx;exports.resolveObservationsTarget=Tl;exports.resolvePanelBorderStyle=ST;exports.resolvePolarBarCornerRadiusUnit=eA;exports.resolveRuleLabelStyle=Db;exports.resolveSegmentYSource=lr;exports.resolveShapeAnnotationStyle=mT;exports.resolveSourceStyle=wb;exports.resolveSubtitleStyle=Lb;exports.resolveSwatchGeomPaint=ca;exports.resolveTextAnnotationStyle=gT;exports.resolveTextStyle=N;exports.resolveTickLabelStyle=Cb;exports.resolveTickLineStyle=AT;exports.resolveTooltipStyle=_b;exports.resolveYScaleAesthetic=Te;exports.sampleColorScheme=jf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Sx;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=Ib;exports.toPanelCursor=Sl;exports.toPercent=De;exports.toViewBoxX=pS;exports.toViewBoxY=ce;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=Ws;exports.uniqueId=W;exports.unitToPolar=or;exports.updateSpec=P;
23
+ `,bb=(e,t,r,n,a,i=.5)=>e?{x:n,y:Math.min(t.y,r.y)+i*a}:{x:Math.min(t.x,r.x)+i*a,y:n},Sb=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),fl=({arrow:e,style:t,mainAxis:r,panelWidth:n,panelHeight:a,locale:i})=>{const o=r==="y",s={x:e.start.x*n,y:(1-e.start.y)*a},c={x:e.end.x*n,y:(1-e.end.y)*a},u=hl(t.strokeWidth),d=fb(o,s,c,u),p=(o?yb:gb)(s,c,d,u),h=vb(o,c,u),m=bb(o,s,c,d,Sb(o,s,c),e.labelCrossPosition),f=ml({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:s,end:c,linePath:p,arrowheadPath:h,labelPosition:m,labelText:f}},bi={large:1,medium:23/26,small:19/26},xb={large:1,medium:10/12,small:10/12},Ab=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],gl=e=>e.fontSize*e.lineHeight,Ib=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),N=(e,t)=>({fontFamily:e.get("fontFamily")??t.get("fontFamily"),fontSize:e.get("fontSize")*t.get("textScale"),fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),Tb=e=>N(e.heading.h1,e.graph),Lb=e=>N(e.heading.h2,e.graph),Eb=e=>N(e.caption,e.graph),wb=e=>({label:N(e.source.label,e.graph),link:N(e.source.link,e.graph)}),Rb=(e,t)=>N(e.axisLabel(t),e.graph),Cb=(e,t,r)=>{const n=e.tickLabel(t,r);return{...N(n,e.graph),offset:n.get("offset")}},Vb=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...N(n,e.graph),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock"),borderRadius:n.get("borderRadius"),isTextColorAuthored:n.getSource("textColor")==="authored",...a===void 0?{}:{background:a},...i===void 0?{}:{borderColor:i},...o===void 0?{}:{borderWidth:o}}},Db=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=N(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},_b=e=>{const t=e.tooltip.box,r=e.graph;return{box:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")},heading:N(e.tooltip.heading,r),label:N(e.tooltip.label,r),value:N(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},Pb=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...N(t,e.graph),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),borderRadius:t.get("borderRadius"),borderWidth:t.get("borderWidth"),...r===void 0?{}:{background:r},...n===void 0?{}:{borderColor:n}},swatch:{size:e.legendItem.swatch.get("size"),strokeWidth:e.legendItem.swatch.get("strokeWidth")}}},Ob=e=>{const t=e.directLabel;return{...N(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},Mb=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=bi[t]*n,i=xb[t]*n,o=e.headlineItem,s=N(o.number,e.graph),c={...s,fontSize:s.fontSize*bi[t]},u=o.numberCenter.get("fontSize");return{number:c,...Nb(o.numberCenter)?{numberCenter:Gt(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:Gt(o.caption,o.caption.get("fontSize")*i,r),label:Gt(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:Gt(o.trend,o.trend.get("fontSize")*i,r),trendUp:{textColor:o.trendUp.get("textColor")},trendDown:{textColor:o.trendDown.get("textColor")},trendFlat:{textColor:o.trendFlat.get("textColor")}}},kb=(e,t)=>{const r=t?e.numberCenter:void 0;return r===void 0?e.number:{fontFamily:r.fontFamily??e.number.fontFamily,fontSize:r.fontSize,fontWeight:r.fontWeight??e.number.fontWeight,lineHeight:r.lineHeight??e.number.lineHeight,textColor:r.textColor??e.number.textColor}},Nb=e=>Ab.some(t=>e.getSource(t)!=="unresolved"),Gt=(e,t,r)=>{const n=e.get("fontFamily")??r,a=e.get("fontWeight"),i=e.get("lineHeight"),o=e.get("textColor");return{fontSize:t,...n===void 0?{}:{fontFamily:n},...a===void 0?{}:{fontWeight:a},...i===void 0?{}:{lineHeight:i},...o===void 0?{}:{textColor:o}}},yl=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=gl(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*Bb({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!tt(o.start.x,o.start.y)||!tt(o.end.x,o.end.y))continue;const s=a(o.id),c=fl({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=yl({labelPosition:c.labelPosition,measuredTextWidth:i(c.labelText,s.label).width,label:s.label});yield{...u,x:r.x+u.x,y:r.y+u.y}}}var Fb=e=>{const t=e.padding,r=Si(e.rows,t?.top??0,t?.bottom??0),n=Si(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:Hb(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},$b=e=>{const t=xi(e.rows,e.height),r=xi(e.cols,e.width),n=Ai(t),a=Ai(r),i=new Map;for(const o of e.placements){const s=o.rowSpan??1,c=o.colSpan??1,u=a[o.col]??0,d=n[o.row]??0,p=Ii(r,o.col,c),h=Ii(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,h)})}return i},Si=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;rn(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push(Gb(s));const c=Ub(e,o);if(rn(s)&&c){const u=s.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},Gb=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},rn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ub=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&rn(n))return n}},Hb=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),o=r.get(a.col);if(i===void 0||o===void 0)continue;const s=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):o;s===void 0||c===void 0||n.push({name:a.name,row:i,col:o,rowSpan:Math.max(1,s-i+1),colSpan:Math.max(1,c-o+1)})}return n},xi=(e,t)=>{let r=0,n=0;for(const i of e)i.type==="fixed"?r+=i.pixels:n+=i.weight;const a=Math.max(0,t-r);return e.map(i=>i.type==="fixed"?i.pixels:n===0?0:i.weight/n*a)},Ai=e=>{const t=new Array(e.length);let r=0;for(let n=0;n<e.length;n++)t[n]=r,r+=e[n]??0;return t},Ii=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},nt={top:0,right:0,bottom:0,left:0},vl={outer:nt,inner:nt},Wb=(e,t,r,n=nt,a=vl,i=l.DEFAULT_GRAPH_PADDING_EDGES,o)=>{const s={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=[{name:"header",size:t.headerSize.height,gaps:pe(o.header)},{name:"topLegend",size:r.legends.top,gaps:pe(o.legend.top)},{name:"headline",size:r.headline,gaps:pe(o.headline)},{name:"topAxisLabel",size:c,gaps:pe(o.axisLabel.top)},{name:"topAxis",size:r.axes.top,gaps:pe(o.tickLabel.top)},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:s.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:s.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:pe(o.tickLabel.bottom)},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:pe(o.axisLabel.bottom)},{name:"bottomLegend",size:r.legends.bottom,gaps:pe(o.legend.bottom)},{name:"footer",size:t.footerSize.height,gaps:pe(o.footer)}],d=[{name:"leftLegend",size:r.legends.left,gaps:Ut(o.legend.left)},{name:"leftAxis",size:r.axes.left,gaps:Ut(o.tickLabel.left)},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:s.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:s.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:Ut(o.tickLabel.right)},{name:"rightLegend",size:r.legends.right,gaps:Ut(o.legend.right)}],p=Ti(u,i.top,i.bottom),h=Ti(d,i.left,i.right);return Fb({rows:u,cols:d,placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...zb(r.axes),...Yb(r.axesLabels,r.axes),...qb(r.legends)],containerSize:e,padding:{top:p.start,bottom:p.end,left:h.start,right:h.end}})},pe=e=>({before:e.top,after:e.bottom}),Ut=e=>({before:e.left,after:e.right}),Kb=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ti=(e,t,r)=>{const n=e.filter(Kb),a=n[0],i=n[n.length-1];return{start:t+(a?.gaps?.before??0),end:r+(i?.gaps?.after??0)}},zb=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Yb=(e,t)=>{const r=[];return e.top>0||t.top>0?(e.top>0&&r.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&r.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&r.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&r.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),r},qb=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t};var jb=class{constructor(e){this.outer={...nt},this.inner={...nt},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},Xb=["top","right","bottom","left"],Nr=(e,t)=>{const r={};for(const n of Xb){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function Li(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var nn=["large","medium","small"],Zb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of nn)if(r(n)<=t)return n;return"small"},Jb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:nn.indexOf(e);for(const a of nn.slice(n))if(r(a)<=t)return a;return null},Qb=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const o=a===0?i:n+t+i;if(o>r)break;n=o,a+=1}return a},eS=({headline:e,containerSize:t,measurer:r})=>{if(br(e))return 0;const n=bl(e,t.width,r);return r.measureHeadline(e.formatted,n).height},tS=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(br(e)){const s=rS(t.panel,e.innerRadius),c=Jb({size:e.size,availableWidth:s.width,measureStripWidth:Sl(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=bl(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=Qb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},br=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,rS=(e,t)=>{const r=t*(Math.min(e.width,e.height)/2)*Math.SQRT2,n=e.x+e.width/2,a=e.y+e.height/2;return{x:n-r/2,y:a-r/2,width:r,height:r}},bl=(e,t,r)=>Zb({size:e.size,availableWidth:t,measureStripWidth:Sl(e,r)}),Sl=(e,t)=>r=>t.measureHeadline(e.formatted,r,br(e)).width,Ye={x:0,y:0,width:0,height:0},nS={top:0,right:0,bottom:0,left:0},aS="0000",iS=3,oS=e=>e.plot.y+e.plot.height-e.panel.y,sS=class{constructor(e){this.measurer=e}compile(e){return ur({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:vl,panelBorder:e.panelBorder??nt,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,margins:e.margins}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:lS(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Ei(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Ei(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:oS(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new jb(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of Bb({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,locale:r,resolveStyle:e.resolveDifferenceArrowStyle,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(o,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const o of ob({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(o,e.overflowStrategy.dataLabels);const i=a.resolve();return Li(i.inner,n.inner)&&Li(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p}){let h=t,m=o;for(let f=0;f<iS;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,m);if(g===m)break;m=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:s,headline:c,padding:d,margins:p})}return h}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,o=a.height-n.vertical*2;return i<=0||o<=0?wi(r,a,0,0):wi(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=H(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const o=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,o.width),a=Math.max(a,o.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:aS}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=H(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=av({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:s,...c}=e,u={...c,ticks:o,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?Qy({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:o,padding:s,margins:c}){const u=$b(Wb(r,n,this.measureGuides(e,t,o,r),i,a,s,cS(c,t)));return{header:u.get("header")??Ye,headline:u.get("headline")??Ye,footer:u.get("footer")??Ye,plot:u.get("plot")??Ye,panelFrame:u.get("panelFrame")??Ye,panel:u.get("panel")??Ye,axes:Nr(u,"Axis"),axisLabels:Nr(u,"AxisLabel"),legends:Nr(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const s of e)s.isVisible&&s.geometry==="linear"&&(a[s.position]=this.measurer.measureAxis(s),s.label!==null&&(i[s.position]=this.measurer.measureAxisLabel(s)));const o={top:0,right:0,bottom:0,left:0};for(const s of t)o[s.position]=this.measurer.measureLegend(s);return{axes:a,axesLabels:i,legends:o,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:eS({headline:e,containerSize:t,measurer:this.measurer})}},Ei=e=>e==="left"||e==="right",wi=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,o=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-o)/2,y:t.y+n+(i-o)/2,width:o,height:o}}},lS=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(o=>o.value)),a=new WeakMap;return i=>{const o=a.get(i);if(o)return o;const s=jn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},cS=(e,t)=>{const r={...e.legend};for(const n of t)n.display==="direct"&&(r[n.position]=nS);return{...e,legend:r}},uS=(e=[])=>{const t=dS(e);return{resolve:(r,n,a)=>{if(!t.has(r))return null;const i=t.get(r).resolveAnchorPosition?.(n,a)??null;return i===null?null:{...i,frame:Sn(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?_o(r,t.get(r.geom)):null}},dS=e=>{const t=new fr;for(const r of e){const n=_n(r);n instanceof ve&&t.register(n.type,n)}return t};function pS(e){return e}function ce(e){return 1-e}var De=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,tr=(e,t)=>{const r=dr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+ce(e.y)*r.height}},mS=(e,t)=>{const r=dr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(ce(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},hS=class{constructor(e,t,r){this.annotations=e,this.panelRect=t,this.measuredBoxes=r,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const i=this.toPanelPoint(e),{x:o,y:s}=an(e.defer,this.panelRect);return Vi({...e,x:i.x+o,y:i.y-s})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=ft(t,e.defer.align),{x:n,y:a}=fS(r,e.defer.offset,this.panelRect);return{x:n,y:a}}resolveRegion(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const a=this.toPanelRegion(e),{x:i,y:o}=an(e.defer,this.panelRect);return Vi({...e,x:a.x-i,y:a.y-o,width:Math.max(0,a.width+2*i),height:Math.max(0,a.height+2*o)})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=t.xMax-t.xMin,n=t.yMax-t.yMin;return r<=0||n<=0?null:{x:t.xMin,y:t.yMin,width:r,height:n}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:gS(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:Ri(this.toPanelPoint(r),this.toPanelPoint(n))}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=this.toPanelPoint(r),i=t.annotation.width,o=n.height/this.panelRect.height,s=xo(t.annotation.align),c=a.x-s.x*i,u=a.y+(1-s.y)*o;return{xMin:c,xMax:c+i,yMin:u-o,yMax:u}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Ci(this.toPanelPoint(r))}case"differenceArrow":return Ri(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return Ci(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Ua(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Ua(e,this.panelRect),r=dr(e.frame,this.panelRect);return{...t,width:this.panelRect.width>0?e.width*r.width/this.panelRect.width:0,height:this.panelRect.height>0?e.height*r.height/this.panelRect.height:0}}},an=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),fS=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:o}=an({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-o}}return{x:e.x+n,y:e.y-a}},gS=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),Ri=(e,t)=>({xMin:Math.min(e.x,t.x),xMax:Math.max(e.x,t.x),yMin:Math.min(e.y,t.y),yMax:Math.max(e.y,t.y)}),Ci=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),Vi=e=>{const t={...e};return delete t.defer,delete t.frame,t},yS=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!vS(t))return t;const o=new hS(t,r,n),s={...t,shapes:ct(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:ct(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:ct(t.arrows,d=>d.start.defer!==void 0||d.end.defer!==void 0,d=>{const p=o.resolvePoint(d.start),h=o.resolvePoint(d.end);return p===null||h===null?null:{...d,start:p,end:h}}),textAnnotations:ct(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:ct(t.stickers,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}})},c=o.cyclicIds();c.length>0&&a?.(c);const u=o.missingRefIds();return u.length>0&&i?.(u),s},ct=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,vS=e=>e.shapes.some(t=>t.region.defer!==void 0)||e.images.some(t=>t.region.defer!==void 0)||e.arrows.some(t=>t.start.defer!==void 0||t.end.defer!==void 0)||e.textAnnotations.some(t=>t.at.defer!==void 0)||e.stickers.some(t=>t.at.defer!==void 0),bS=800,Di=400,SS=.75,xS=.875,AS=4,IS=e=>Math.max(1,(e-Di)/(bS-Di)+1),TS=(e,t)=>{const r=IS(t),n=e*AS;return{strokeWidth:Math.min(e,e*SS*r),arrowheadLength:Math.min(n,n*xS*r)}},Ht=Math.PI/4,on=1.5,LS=2,ES=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,_i=(e,t,r)=>{if(r<=0)return"";const{start:n,end:a}=t,i=e==="start"?n.x:a.x,o=e==="start"?n.y:a.y,s=e==="start"?Math.atan2(n.y-a.y,n.x-a.x):Math.atan2(a.y-n.y,a.x-n.x);return`M ${i} ${o} L ${i-r*Math.cos(s-Ht)} ${o-r*Math.sin(s-Ht)} M ${i} ${o} L ${i-r*Math.cos(s+Ht)} ${o-r*Math.sin(s+Ht)}`},wS=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*LS}`:`${t*on} ${t*on*2}`,RS=(e,t,r)=>e==="dashed"&&r?t*on:0,CS=64,VS=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:tr(e.start,a),end:tr(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=TS(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=DS(s,c),d=e.startArrowheadStyle==="line-arrow",p=e.endArrowheadStyle==="line-arrow",h=d||p?u*Math.sin(Math.PI/4):0;return{id:e.id,linePath:ES(i),startArrowheadPath:d?_i("start",i,u):"",endArrowheadPath:p?_i("end",i,u):"",strokeWidth:o,dashArray:wS(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:RS(t.lineType,o,d),arrowheadExtent:h}},DS=(e,t)=>Math.min(e,t*e/CS);function _S(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(p=>p.transformType==="filter"&&p.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let o,s,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")o="color",s=a.options.variableName,c=a.options.value;else if(i!==null)o="y",s=i,c=i;else continue;const u=PS(e,o,s);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d,layerId:u.id,groupValue:c})}return r}function PS(e,t,r){let n=null;for(const a of e)if(a.geom!=="rule"&&(n===null&&(n=a),l.extractVariableName(a.mapping[t])===r))return a;return n}var xl=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),OS=0,MS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:xl(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:OS})),kS=9,NS=8,BS=2,Al=e=>typeof e=="string"?e:Il(e),Il=e=>e.text!==void 0?e.text:e.content?e.content.map(Il).join(""):"",Pi={top:"bottom",bottom:"top",right:"left",left:"right"};function FS(e,t,r){return r.type==="polar"?US(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function sn(e,t,r){const{width:n,height:a}=r;switch(t){case"top":return{x:e.x-n/2,y:e.y-9-a,width:n,height:a};case"bottom":return{x:e.x-n/2,y:e.y+9,width:n,height:a};case"right":return{x:e.x+9,y:e.y-a/2,width:n,height:a};case"left":return{x:e.x-9-n,y:e.y-a/2,width:n,height:a}}}function Oi(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function $S(e,t){return{...t,x:Math.max(0,Math.min(t.x,e.width-t.width)),y:Math.max(0,Math.min(t.y,e.height-t.height))}}function GS(e,t,r=2){return e.x<t.x+t.width-r&&e.x+e.width>t.x+r&&e.y<t.y+t.height-r&&e.y+e.height>t.y+r}function US(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[o,s]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[o,Pi[o],s,Pi[s]]}function HS(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:o}=e,s=[...t.map(d=>{const{id:p,at:h}=d;return Mi(p,"pinned-number",h,o(d),i,n)}),...r.map(({id:d,at:p,content:h})=>Mi(d,"comment",p,Al(h),i,n))];s.sort((d,p)=>d.anchorPx.x-p.anchorPx.x||d.anchorPx.y-p.anchorPx.y);const c=[],u=[];for(const d of s){if(!d.inView){c.push(ki(n,d,"top"));continue}const p=ki(n,d,KS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Mi(e,t,r,n,a,i){const o=tr(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:WS(o,i)}}function WS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function KS(e,t,r,n){const a=FS(t.anchorPx,e,r);for(const i of a){const o=sn(t.anchorPx,i,t.mini);if(Oi(o,e)&&!n.some(s=>GS(o,s)))return i}for(const i of a)if(Oi(sn(t.anchorPx,i,t.mini),e))return i;return"top"}function ki(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:$S(e,sn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var zS=(e,t,r)=>e.anchor.layerId!==t.anchor.layerId||!l.areDataValuesEqual(e.anchor.groupValue??null,t.anchor.groupValue??null)||r.start===void 0||r.start!==r.end?null:r.start,YS=100,qS=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,o=!0,s=0;for(;o;){o=!1,s++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const p=u.y+a,h=d.y-a;if(p>h){o=!0,i=!0;const m=(p-h)/2+1;u.y-=m,d.y+=m,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(s>YS)break}return{placements:n.filter(c=>c.y>=0&&c.y<=t).map(c=>({y:c.y,anchorY:c.anchorY,payload:c.payload})),hasOverlap:i}},Tl=(e,t)=>rr(e,t,jS(e),{allowNull:!1}),rr=(e,t,r,{allowNull:n})=>{const a=Oo(e),i=[];for(const s of r){const c=a(t,s);if(c===null&&!n)return null;i.push({variable:s,eq:c})}const[o]=i;return o===void 0?null:i.length===1?o:{and:i}},jS=e=>{const t=bn(e)?Le(e.data,e.mapping):[],r=vn(e),n=r===null?t:[...t,r],a=Ne(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},aa=e=>e!=="data-point",Ll=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(Ie(t.predicate,e.data).length>0)return[];const n=Ae(t.predicate,vt(e,r));return aa(t.scope)?ZS(e,n,t.scope):XS(e,n)},XS=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},ZS=(e,t,r)=>{const n=hr(e.mapping),a=[],i=new Set;for(const s of e.data){const c=dt(r,s,n);a.push(c),t(s)&&i.add(c)}const o=[];return a.forEach((s,c)=>{i.has(s)&&o.push(c)}),o},JS=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=tx(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return ex(o,e,t,n)?o:null},QS=e=>e.identityKey==="x-group"?"series":Le(e.data,e.mapping).length===0?"data-point":"series",ex=(e,t,r,n)=>Ll({layer:t,target:e,parsingLocale:n}).includes(r),tx=(e,t,r)=>{switch(r){case"data-point":return Ni(e,t);case"series":{const n=Le(e.data,e.mapping);return n.length===0?Ni(e,t):rr(e,t,n,{allowNull:!0})}case"x-value":{const n=hr(e.mapping);return n===null?null:rr(e,t,[n],{allowNull:!0})}}},Ni=(e,t)=>{const r=e.identityKey;if(typeof r=="object")return rr(e,t,[r.variable],{allowNull:!0});switch(r){case"index":return null;case"x-group":case"x-y":return Tl(e,t)}},ia=(e,t)=>{if(t.kind==="circle"){const n=e.x-t.center.x,a=e.y-t.center.y;return n*n+a*a<=t.radius*t.radius}const{rect:r}=t;return e.x>=r.x&&e.x<=r.x+r.width&&e.y>=r.y&&e.y<=r.y+r.height},rx=(e,t)=>{for(const r of t)if(ia(e,r.shape))return r;return null},nx=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},ax=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>ix(r,t[n])),ix=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&ox(e.shape,t.shape)&&sx(e.tooltip,t.tooltip),ox=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="circle"){const n=t;return e.center.x===n.center.x&&e.center.y===n.center.y&&e.radius===n.radius}const{rect:r}=t;return e.rect.x===r.x&&e.rect.y===r.y&&e.rect.width===r.width&&e.rect.height===r.height},sx=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="cursor")return!0;const r=t;return e.point.x===r.point.x&&e.point.y===r.point.y&&e.placement===r.placement&&e.annotationId===r.annotationId},lx=100,cx=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:lx}),ux=(e,t)=>ia(e,{kind:"circle",center:t.center,radius:t.radius}),dx=(e,t)=>e===t?!0:e===null||t===null?!1:e.center.x===t.center.x&&e.center.y===t.center.y&&e.radius===t.radius&&px(e.target,t.target),px=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,mx=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=vt(e,n),i=hx(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||Ie(o.predicate,e.data).length>0)return!1;const s=Ae(o.predicate,a);return s(r)?!0:aa(o.scope)&&i(o.scope).some(s)})},hx=(e,t)=>{const r=hr(e.mapping),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=dt(a,t,r),s=[];for(const c of e.data)dt(a,c,r)===o&&s.push(c);return n.set(a,s),s}},zt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=yt(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?fx(u,o):u;if(d<0||d>=o)break;const p=e.data.getAt(d);if(p===null||!n(p,d))continue;const h=s(p);if(h!==null&&!a.some(m=>Xe(h,m)))return{anchor:h,observation:p,observationIndex:d}}return null},El=(e,t)=>{const r=Po(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Xe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),fx=(e,t)=>(e%t+t)%t,wl=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=Ne(e),a=El(e,t),i=e.data.getAt(a);if(i===null)return null;const o=re(i),s=h=>l.areDataValuesEqual(re(h),o),c=[t],u=zt({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=zt({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=zt({layer:e,excluding:c,from:0,step:1,accepts:h=>!s(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return p!==null?{start:t,end:p.anchor}:null},gx=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=yt(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=wl({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>yx(s,o)))return o}}return null},yx=(e,t)=>Xe(e.start,t.start)&&Xe(e.end,t.end)||Xe(e.start,t.end)&&Xe(e.end,t.start),vx=(e,t)=>{const r=e.find(a=>a.id===t.anchor.layerId);if(r===void 0)return null;const n=r.data.getAt(t.observationIndex);return n===null?null:{layer:r,observation:n}},bx=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:o})=>{const s=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(s===null)return null;const c=o??e.createLayerMeasurement(t);if(c===null)return null;const u=Bo(t,r,c);if(u===null)return null;const d=yt(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Sx=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=Ne(e),s=El(e,t),c=e.data.getAt(s);if(c===null)return null;const u=xx(c),d=n==="main"?u:m=>!u(m)&&l.areDataValuesEqual(m[o]??null,t.anchorValue),p=zt({layer:e,excluding:[t,r],from:s+a,step:a,accepts:(m,f)=>d(m)&&i(m,f)!==null,cycles:n!=="main"});if(p===null)return null;const h=i(p.observation,p.observationIndex);return h===null?null:{...p,point:h}},xx=e=>{const t=re(e);return r=>l.areDataValuesEqual(re(r),t)};function Ax({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=k({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Ix=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const o=a??n;return e.kind==="grandTotal"?Tx(e,o,r):Lx(e,t,o,r,i)},Tx=(e,t,r)=>({kind:"grandTotal",value:k({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Lx=(e,t,r,n,a)=>{const i=k({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=k({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=k({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=jn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:Cx(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:Rx(s.caption,d),comparison:Ex(s.comparison,d,i,a)}})}},Ex=(e,t,r,n)=>e===null?null:{direction:wx(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},wx=e=>e>0?"up":e<0?"down":"flat",Rx=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Cx=(e,t,r,n)=>{switch(e){case"total":return n("graph.headlineMetrics.total",{value:r});case"average":return t?n("graph.headlineMetrics.averageShort",{value:r}):n("graph.headlineMetrics.averageLong",{value:r});case"current":case"conversion":case"none":return r}},Vx=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Dx(i,a,t))},Dx=(e,t,r)=>({...e,items:e.items.map(n=>{const a=k({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function oa(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function _x(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Px=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,o=(i?yn:ot)(r.data,r.mapping)(a);return o===null?null:k({valueFormat:oa(e,i?Te(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},Ox=4,Mx=4,kx=12,Nx=4,Bx=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:Br([Wt("value",r??"–"),Wt("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:Ux(a),segments:Br([$x(a),Gx(a),Wt("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:Br([Fx(i,t),Wt("label",o)])}].filter(s=>s.segments.length>0)},Wt=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},Fx=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},$x=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Gx=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},Ux=e=>{switch(e.direction){case"up":return`Increased ${e.percentage} ${e.reference}`;case"down":return`Decreased ${e.percentage} ${e.reference}`;case"flat":return`No change ${e.reference}`}},Br=e=>e.filter(t=>t!==null),Sr=e=>e==="catmull-rom"?Pe.curveCatmullRom:Pe.curveLinear,Hx=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Wx=(e,t)=>{const r=Sr(t.interpolate),n=(0,Pe.area)().curve(r),a=(0,Pe.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ce(D(c)??0),o=c=>j(c)??0,s=c=>X(c)??M(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>M(c)??0,o=c=>ce(G(c)??0),s=c=>ce(F(c)??D(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>M(o)!==null&&D(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},Kx=(e,t)=>t!=="connect"?e:e.filter(r=>M(r)!==null&&D(r)!==null),sa={none:0,xs:2,sm:4,md:8,lg:12,xl:16},la=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return sa[e.borderRadius??"sm"]},zx=e=>{const t=la(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Yx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Rl=(e,t)=>{const r=j(t),n=X(t),a=G(t),i=F(t)??D(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let o=r,s=n-r;return s<0&&(o+=s,s=-s),{x:o,y:1-i,width:s,height:i-a}},Cl=(e,t)=>e==="x"?`${te(t.x)}-${te(t.width)}`:`${te(t.y)}-${te(t.height)}`,qx=e=>{let t=1/0,r=1/0,n=-1/0,a=-1/0;for(const i of e)i.x<t&&(t=i.x),i.y<r&&(r=i.y),i.x+i.width>n&&(n=i.x+i.width),i.y+i.height>a&&(a=i.y+i.height);return{x:t,y:r,width:n-t,height:a-r}},jx=e=>{const t=(0,Pe.line)().x(r=>M(r)??0).y(r=>ce(D(r)??0)).curve(Sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Vl),t},Xx=e=>{const t=(0,Pe.area)().x(r=>M(r)??0).y0(()=>1).y1(r=>ce(D(r)??0)).curve(Sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Vl),t},Zx=(e,t)=>t!=="connect"?e:e.filter(r=>M(r)!==null&&D(r)!==null),Vl=e=>M(e)!==null&&D(e)!==null,Dl=(0,Pe.arc)().cornerRadius(e=>e.cornerRadius??0);Dl.digits(8);var Jx=200,Qx=e=>Dl(e)??void 0,eA=(e,t)=>e==="full"?Math.max(0,t)/2:sa[e??"sm"]/Jx,_l=(e,t)=>e==="x"?`${te(t.startAngle)}-${te(t.endAngle)}`:e==="y"?`${te(t.innerRadius)}-${te(t.outerRadius)}`:"sweep",tA=e=>{let t=1/0,r=-1/0,n=1/0,a=-1/0;for(const i of e)t=Math.min(t,i.startAngle,i.endAngle),r=Math.max(r,i.startAngle,i.endAngle),n=Math.min(n,i.innerRadius,i.outerRadius),a=Math.max(a,i.innerRadius,i.outerRadius);return{startAngle:t,endAngle:r,innerRadius:n,outerRadius:a}},rA=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],xr=(e,t,r)=>{const n=ot(e,t);return a=>{const i=re(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},nA=(e,t,r)=>{const n=ot(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},aA=(e,t,r)=>{const n=ot(e,t),a=yn(e,t),i=new Map;return o=>{const s=n(o),c=a(o),u=s!==null&&s!==""&&c!==null&&c!==""?`${r}-${s}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},iA=()=>(e,t)=>Et(e)??`default-${t}`,Bi=2,oA=(e,t)=>{const r=l.extractVariableName(e.mapping.color);if(t!==void 0&&r!==null&&e.data.hasVariable(r)){const n=e.data.getValues(r).findIndex(a=>l.areDataValuesEqual(a,t));if(n!==-1)return e.data.getAt(n)??void 0}return e.data.getFirst()??void 0},ca=(e,t,r,n)=>{const a=e.get("alpha",r);if(!Gs(t,"bar"))return{alpha:a};const i=n.width-Bi,o=n.height-Bi,s=la({borderRadius:e.get("borderRadius",r),mainAxis:"x",bounds:{width:i,height:o}});return{alpha:a,cornerRadiusPx:Math.min(s,Math.min(i,o)/2)}};function ua(e,t){let r=0,n=e;for(;r<n;){const a=r+n>>>1;t(a)?n=a:r=a+1}return r}function sA(e,t,r){return ua(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>t})}function lA(e,t,r){return ua(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>=t})}function da(e,t,r,n){const a=e==="x";return{mainDistance:Math.abs(t)*(a?n:1),crossDistance:Math.abs(r)*(a?1:n)}}function pa(e,t,r){return Math.hypot(e*r,t)}function ue(e,t,r){return e<t?t-e:e>r?e-r:0}function ne(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const o=e[i];if(o===void 0)continue;const s=t(o);if(r&&s===0)return o;s<a&&(n=o,a=s)}return n}function cA(e,t){const r=t.height,n=Math.min(t.width,t.height)/2;return{cartesian:Fi(e,r),polar:Fi(e,n)}}function wt(e,t){return e<=t.on.point}function ht({mainDistance:e,crossDistance:t},r){return e<=r.near.main&&t<=r.near.cross}function Fi({on:e,near:t},r){return{on:{edge:e.edge/r,stroke:(e.stroke??e.edge)/r,point:(e.point??e.edge)/r},near:{main:t.main/r,cross:(t.cross??t.main)/r}}}function uA(e,t,r,n,a){if(e.points.length===0)return null;const i=e.delaunay;if(!i)return null;const o=i.find(t.x*r,t.y,n??void 0),s=e.points[o];if(!s)return null;const c=Pl(e,s,t,r);return a===void 0||wt(c.distance,a)||ht(c,a)?c:pA(e,t,r,a)??c}function dA(e,t){if(e.projection==="polar"||e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function pA(e,t,r,n){const{mainAxis:a,byMain:i}=e,o=et(a,t).main,s=a==="x"?n.near.main/r:n.near.main,c=lA(i,o-s,$i(a)),u=sA(i,o+s,$i(a));let d=null;for(let p=c;p<u;p+=1){const h=i[p];if(h===void 0)continue;const m=Pl(e,h,t,r);ht(m,n)&&(d===null||m.crossDistance<d.crossDistance)&&(d=m)}return d}function $i(e){return t=>et(e,t).main}function Pl(e,t,r,n){const{main:a,cross:i}=et(e.mainAxis,r),{main:o,cross:s}=et(e.mainAxis,t);return{...da(e.mainAxis,o-a,s-i,n),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:pa(t.x-r.x,t.y-r.y,n)}}function Ol(e,t){return e.buckets[mA(e,t)]??null}function mA(e,t){return Nl(e.buckets,t,r=>r.main)}function hA(e,t){return kl(e.bands,t,r=>r.bandCenter)}function Ml(e,t){return kl(e.columns,t,r=>r.mainMid)}function kl(e,t,r){return e[Nl(e,t,r)]??null}function Nl(e,t,r){if(e.length===0)return-1;const n=ua(e.length,o=>{const s=e[o];return s!==void 0&&r(s)>=t}),a=e[n-1],i=e[n];return a?i&&Math.abs(r(i)-t)<Math.abs(r(a)-t)?n:n-1:n}function fA(e,t){return{group:gA(e),related:SA(e,t)}}function gA(e){switch(e.kind){case"buckets":{const t=e.match.index;return U(t.position)?yA(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return U(t.position)?vA(t.layerId,r,n.pointIndex):bA(t.bandByColumn,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function yA(e,t,r){const n=[];for(const a of t.entries)a.pointIndex!==r&&n.push({anchored:!0,layerId:e,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation});return n}function vA(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(ma(e,a));return n}function bA(e,t,r,n){const a=e.get(r);if(!a)return[];const i=[];for(const o of a.columns)for(const s of o.rects)s.pointIndex!==n&&i.push(ma(t,s));return i}function SA(e,t){const r=new Map;if(e.kind==="render-hit-test"||e.kind==="enclosure")return r;const n=e.match.index,a=n.projection==="polar";for(const i of t){if(i.layerId!==n.layerId){a||AA(r,i,e.match.hit);continue}e.kind==="buckets"&&(U(i.position)||i.kind==="buckets"&&xA(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function xA(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Yt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function AA(e,t,r){switch(t.kind){case"buckets":{const n=Ol(t,Z(t.mainAxis,r));if(!n)return;const a=Yt(e,t.layerId);for(const i of n.entries)a.push({anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation});return}case"banded":{const n=hA(t,Z(t.mainAxis,r));if(!n)return;const a=Yt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(ma(t.layerId,o));return}case"points":{const n=dA(t,r);if(!n)return;Yt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,observationIndex:n.observationIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function Yt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function ma(e,t){return{anchored:!0,layerId:e,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function Bl(e,t,r){const{columns:n,bands:a,bandByColumn:i}=IA(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a,bandByColumn:i}}function IA(e,t){const r=LA(e,t);r.sort((c,u)=>c.mainMid-u.mainMid);const n=new Map,a=new Map,i=new Map;for(const c of r){const u=te(c.mainMid);let d=n.get(u);if(!d){d={mainMid:c.mainMid,rects:[]},n.set(u,d);const p=te(c.bandCenter);let h=a.get(p);h||(h={bandCenter:c.bandCenter,columns:[],mainMin:1/0,mainMax:-1/0,crossMin:1/0,crossMax:-1/0},a.set(p,h)),h.columns.push(d),i.set(d,h)}d.rects.push(c.entry),TA(i.get(d),c.entry,t)}const o=[...n.values()].sort((c,u)=>c.mainMid-u.mainMid),s=[...a.values()].sort((c,u)=>c.bandCenter-u.bandCenter);for(const c of s)c.columns.sort((u,d)=>u.mainMid-d.mainMid);return{columns:o,bands:s,bandByColumn:i}}function TA(e,t,r){if(e===void 0)return;const n=r==="x",a=n?t.xMin:t.yMin,i=n?t.xMax:t.yMax,o=n?t.yMin:t.xMin,s=n?t.yMax:t.xMax;e.mainMin=Math.min(e.mainMin,a),e.mainMax=Math.max(e.mainMax,i),e.crossMin=Math.min(e.crossMin,o),e.crossMax=Math.max(e.crossMax,s)}function LA(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=t==="y",c=s?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let p=0;for(const h of r){const m=n[p],f=a[p],g=i[p],v=o[p];if(!l.isDefined(m)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(v)){p++;continue}const y=s?(g+v)/2:(m+f)/2,b=u?.[p]??y;d.push({mainMid:y,bandCenter:b,entry:{pointIndex:p,xMin:Math.min(m,f),xMax:Math.max(m,f),yMin:Math.min(g,v),yMax:Math.max(g,v),observation:h}}),p++}return d}var EA=1e-9,Gi=-1;function Fl(e,t,r){const n=wA(e,t,r),a=n.map(o=>o.entry);n.sort((o,s)=>o.main-s.main);const i=[];for(const o of n){const s=i[i.length-1];s&&Math.abs(s.main-o.main)<=EA?s.entries.push(o.entry):i.push({main:o.main,entries:[o.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:i,entries:a}}function wA(e,t,r){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(l.POSITION_VARIABLES.x),i=n.hasVariable(l.POSITION_VARIABLES.y);if(!a||!i)return[];const o=n.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=n.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),c=t==="y",u=c?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,d=c?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,p=U(e.position),h=n.hasVariable(u)?n.getValues(u,{type:"numeric"}):null,m=n.hasVariable(d)?n.getValues(d,{type:"numeric"}):null,f=n.hasVariable(l.GROUP_VARIABLES.group)?n.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,g=new CA(RA(e)),v=new Map,y=[];let b=0;for(const A of n){const T=o[b],L=s[b],E=f?.[b]??null,w=VA(v,E);if(!l.isDefined(T)||!l.isDefined(L)){g.skip(E),b+=1;continue}const C=c?L:T,I=h?.[b],V=p?m?.[b]:void 0;if(p&&(!l.isDefined(I)||!l.isDefined(V))){g.skip(E),b+=1;continue}const O=V??ye(t,{x:T,y:L}),ie={pointIndex:b,...c?{x:O,y:L}:{x:T,y:O},groupKey:E,paintOrder:w,...e.spatialKind==="filled-buckets"&&l.isDefined(I)&&{fill:DA(I,O)},previousAt:Gi,nextAt:Gi,observation:A};g.append(E,{entry:ie,at:y.length}),y.push({main:C,entry:ie}),b+=1}return r==="polar"&&g.close(),y}function RA(e){return"missingValues"in e.params&&e.params.missingValues==="gap"}var CA=class{constructor(e){this.breaksAtNull=e,this.firstByGroup=new Map,this.lastByGroup=new Map,this.brokenGroups=new Set}append(e,t){const r=this.lastByGroup.get(e);r!==void 0&&(r.entry.nextAt=t.at,t.entry.previousAt=r.at),this.firstByGroup.has(e)||this.firstByGroup.set(e,t),this.lastByGroup.set(e,t)}skip(e){this.breaksAtNull&&(this.lastByGroup.delete(e),this.brokenGroups.add(e))}close(){for(const[e,t]of this.firstByGroup){const r=this.lastByGroup.get(e);r===void 0||r===t||this.brokenGroups.has(e)||(r.entry.nextAt=t.at,t.entry.previousAt=r.at)}}};function VA(e,t){const r=e.get(t);if(r!==void 0)return r;const n=e.size;return e.set(t,n),n}function DA(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function $l(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:_A(e,t)}}function _A(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const p of n)if(!r.hasVariable(p))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const p of r){const h=a[d],m=i[d],f=o[d],g=s[d];if(!l.isDefined(h)||!l.isDefined(m)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!Et(p)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:m,yMin:f,yMax:g,observation:p}),d++}return u}function ln(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function PA(e,t,r){const n=Ul(e),a={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",mainAxis:t,points:n,byMain:MA(t,n),delaunay:null,delaunayAspectRatio:null};return Gl(a,r),a}function OA(e){const t=Ul(e).map(r=>{const n=ge(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t}}function Gl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Xd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function MA(e,t){const r=n=>Z(e,n);return[...t].sort((n,a)=>r(n)-r(a))}function Ul(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const o of t){const s=r[i],c=n[i];l.isDefined(s)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:s,y:c,observation:o}),i+=1}return a}function Hl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:kA(e)}}function Wl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function kA(e){const t=e.identityKey,r=new Map;if(typeof t=="object"){let n=0;for(const a of e.data){const i=a[t.variable];l.isDefined(i)&&r.set(l.getStableKey(i),{pointIndex:n,observation:a}),n+=1}return r}if(t==="index"){let n=0;for(const a of e.data)r.set(String(n),{pointIndex:n,observation:a}),n+=1}return r}function Ui(e,t,r){return t.type==="polar"?NA(e,t.bandAxis):BA(e,t.mainAxis,r)}function NA(e,t){switch(e.spatialKind){case"points":return OA(e);case"buckets":case"filled-buckets":return Fl(e,"x","polar");case"rects":return t===null?$l(e,"polar"):Bl(e,t,"polar");case"cells":return ln(e);case"noop":return ln(e);case"render-hit-test":return Hl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function BA(e,t,r){switch(e.spatialKind){case"points":return PA(e,t,r);case"buckets":case"filled-buckets":return Fl(e,t,"cartesian");case"rects":return Bl(e,t,"cartesian");case"cells":return $l(e,"cartesian");case"noop":return ln(e);case"render-hit-test":return Hl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function FA(e,t,r){if(e.columns.length===0)return null;const n=Ml(e,Z(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=U(e.position)?GA(a,t,e.mainAxis):UA(a,t,r),o=Kl(i,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:n,distance:o,...$A(e,n,t,r)}}function $A(e,t,r,n){const a=e.bandByColumn.get(t);if(a===void 0)return{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY};const{main:i,cross:o}=et(e.mainAxis,r),s=ue(i,a.mainMin,a.mainMax),c=ue(o,a.crossMin,a.crossMax);return da(e.mainAxis,s,c,n)}function GA(e,t,r){const n=ye(r,t);return ne(e,i=>HA(i,r,n),{shortCircuitOnZero:!0})}function UA(e,t,r){return ne(e,a=>Kl(a,t,r))}function Kl(e,t,r){return pa(ue(t.x,e.xMin,e.xMax),ue(t.y,e.yMin,e.yMax),r)}function HA(e,t,r){return ue(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function WA(e,t,r){const n=r.x-t.x,a=r.y-t.y,i=n*n+a*a;if(i===0)return Math.hypot(e.x-t.x,e.y-t.y);const o=((e.x-t.x)*n+(e.y-t.y)*a)/i,s=Math.max(0,Math.min(1,o));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*a))}function KA(e,t,r){const{main:n,cross:a}=et(e.mainAxis,t),i=Ol(e,n);if(i===null)return null;const o=i.entries.map(f=>({entry:f,crossAtCursor:YA(e,f,n)}));if(!l.isNonEmptyArray(o))return null;const s=Yl(o.filter(f=>jA(e,f.entry,n,a)),f=>f.entry),{entry:c}=s??ne(o,f=>Math.abs(f.crossAtCursor-a)),u=pa(c.x-t.x,c.y-t.y,r),d=f=>({x:f.x*r,y:f.y}),p=Ar(e,c).map(d),h=zl(d(t),d(c),p,u),m=da(e.mainAxis,i.main-n,ye(e.mainAxis,c)-a,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:c.x,y:c.y,observation:c.observation},index:e,bucket:i,distance:s===void 0?u:0,vertexDistance:u,insideFill:s!==void 0,strokeDistance:s===void 0?h:0,...m}}function zA(e,t,r){return ne(e,a=>Math.abs(ye(r,a)-t))}function zl(e,t,r,n){const a=r.map(i=>WA(e,t,i));return Math.min(n,...a)}function Ar(e,t){return[e.entries[t.previousAt],e.entries[t.nextAt]].filter(l.isDefined)}function Yl(e,t){return e.reduce((r,n)=>r===void 0||t(n).paintOrder>t(r).paintOrder?n:r,void 0)}function YA(e,t,r){const{mainAxis:n}=e,a=r===Z(n,t)?null:ql(e,t,r);return a===null?ye(n,t):qA(t,a,n,r)}function qA(e,t,r,n){const a=Z(r,e),i=(n-a)/(Z(r,t)-a),o=ye(r,e);return o+(ye(r,t)-o)*i}function ql(e,t,r){const{mainAxis:n}=e,a=Z(n,t),i=o=>Math.sign(Z(n,o)-a)===Math.sign(r-a);return Ar(e,t).find(i)??null}function jA(e,t,r,n){const a=XA(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function XA(e,t,r){if(t.fill===void 0)return null;const{mainAxis:n}=e,a=Z(n,t);if(r===a)return t.fill;const i=ql(e,t,r);if(i?.fill===void 0)return null;const o=(r-a)/(Z(n,i)-a);return{min:t.fill.min+(i.fill.min-t.fill.min)*o,max:t.fill.max+(i.fill.max-t.fill.max)*o}}function ZA(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e,distance:0,mainDistance:0,crossDistance:0};return null}function JA(e,t,r){if(e.columns.length===0)return null;const n=mn(t,r),{angle:a,radius:i}=n,o=e.mainAxis==="x",s=o?tI(e.columns,a):Ml(e,i),c=s?.rects??[];if(!s||!l.isNonEmptyArray(c))return null;const u=o?rI(c,i):nI(c,a),d=QA(u,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:(u.xMin+u.xMax)/2,y:(u.yMin+u.yMax)/2,observation:u.observation},index:e,column:s,distance:d,...eI(e,s,n)}}function QA(e,{angle:t,radius:r}){const n=nr(t,e.xMin,e.xMax),a=ue(r,e.yMin,e.yMax);return Math.hypot(n*r,a)}function nr(e,t,r){return Zt(e,t,r)?0:Math.min(Qe(e,t),Qe(e,r))}function eI(e,t,{angle:r,radius:n}){const a=e.bandByColumn.get(t);return a===void 0?{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY}:e.mainAxis==="x"?{mainDistance:nr(r,a.mainMin,a.mainMax)*n,crossDistance:ue(n,a.crossMin,a.crossMax)}:{mainDistance:ue(n,a.mainMin,a.mainMax),crossDistance:nr(r,a.crossMin,a.crossMax)*n}}function tI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(t,r.mainMid)):null}function rI(e,t){return ne(e,r=>ue(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function nI(e,t){return ne(e,r=>nr(t,r.xMin,r.xMax),{shortCircuitOnZero:!0})}var Hi=1e-9;function aI(e,t,r){if(e.buckets.length===0)return null;const n=lr(t,r),{angle:a,radius:i}=sr(n.x,n.y),o=iI(e.buckets,a),s=o?.entries??[];if(!o||!l.isNonEmptyArray(s))return null;const c=Yl(s.filter(m=>oI(e,m,a,i)),m=>m),u=c??zA(s,i,e.mainAxis),d=Wi(u),p=Math.hypot(n.x-d.x,n.y-d.y),h=zl(n,d,Ar(e,u).map(Wi),p);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:u.x,y:u.y,observation:u.observation},index:e,bucket:o,distance:c===void 0?p:0,vertexDistance:p,insideFill:c!==void 0,strokeDistance:c===void 0?h:0,mainDistance:Qe(o.main,a)*i,crossDistance:Math.abs(i-u.y)}}function Wi(e){return ge(e.x,e.y)}function iI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(r.main,t)):null}function oI(e,t,r,n){const a=sI(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function sI(e,t,r){if(t.fill===void 0)return null;const n=$a(t.x,r);if(n===0)return t.fill;const a=c=>Math.sign($a(t.x,c.x))===Math.sign(n),i=Ar(e,t).find(a);if(i?.fill===void 0)return null;const o=Ki(r,{angle:t.x,radius:t.fill.min},{angle:i.x,radius:i.fill.min}),s=Ki(r,{angle:t.x,radius:t.fill.max},{angle:i.x,radius:i.fill.max});return o===null||s===null?null:{min:o,max:s}}function Ki(e,t,r){const n=ge(t.angle,t.radius),a=ge(r.angle,r.radius),i={x:a.x-n.x,y:a.y-n.y};if(Math.hypot(i.x,i.y)<Hi)return t.radius;const o=zi(ge(e,1),i);return Math.abs(o)<Hi?null:zi(n,i)/o}function zi(e,t){return e.x*t.y-e.y*t.x}function lI(e,t,r,n=!1){if(e.cells.length===0)return null;const{angle:a,radius:i}=mn(t,r);for(const u of e.cells)if(!(i<u.yMin||i>u.yMax)&&Zt(a,u.xMin,u.xMax))return Yi(e,u,0);if(!n)return null;const o=e.cells.filter(u=>Zt(a,u.xMin,u.xMax));if(!l.isNonEmptyArray(o))return null;const s=u=>ue(i,u.yMin,u.yMax),c=ne(o,s);return Yi(e,c,s(c))}function Yi(e,t,r){return{hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation},index:e,distance:r,mainDistance:0,crossDistance:r}}function cI(e,t,r,n){if(!l.isNonEmptyArray(e.points))return null;const a=lr(t,r),i=qi(e,ne(e.points,s=>jl(s,a)),a);if(n===void 0||wt(i.distance,n)||ht(i,n))return i;const o=e.points.map(s=>qi(e,s,a)).filter(s=>ht(s,n));return l.isNonEmptyArray(o)?ne(o,s=>s.crossDistance):i}function qi(e,t,r){const{angle:n,radius:a}=sr(r.x,r.y);return{mainDistance:Qe(t.x,n)*a,crossDistance:Math.abs(a-t.y),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:Math.sqrt(jl(t,r))}}function jl(e,t){const r=e.unitX??ge(e.x,e.y).x,n=e.unitY??ge(e.x,e.y).y,a=r-t.x,i=n-t.y;return a*a+i*i}var uI=.05;function dI({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a,tolerance:i}){const o={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},s={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},c={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1};for(const[u,d]of e.entries()){if(d.kind==="render-hit-test"){const h=vI(d,t,a);if(h)return{kind:"render-hit-test",match:h};continue}if(d.projection==="polar"){const h=yI(d,t,r,i?.polar);if(h&&!ji(h,i?.polar))return h;continue}const p=gI({layer:d,cursor:t,aspectRatio:r,warmStarts:n,tolerance:i?.cartesian});if(!(!p||ji(p,i?.cartesian))){if(p.kind==="banded"||p.kind==="enclosure"){const h=p.match.distance;h<o.distance&&(o.match=p,o.distance=h,o.paintOrder=u);continue}if(p.kind==="buckets"&&p.match.insideFill){s.match=p,s.distance=0,s.paintOrder=u;continue}p.match.distance<c.distance&&(c.match=p,c.distance=p.match.distance,c.paintOrder=u)}}return Xl(c,mI(s,o)).match}function pI(e,t){if(e.kind==="render-hit-test")return{intersects:!0,onPoint:!1};const r=hI(e,t),n=e.kind==="buckets"&&wt(e.match.vertexDistance,r);return{intersects:Zl(e,r),onPoint:n}}function mI(e,t){return e.match!==null&&t.match!==null&&e.distance===0&&t.distance===0?e.paintOrder>t.paintOrder?e:t:Xl(e,t)}function Xl(e,t){return e.match===null?t:t.match===null||e.distance<=t.distance+uI?e:t}function Zl(e,t){switch(e.kind){case"banded":case"enclosure":return e.match.distance<=t.on.edge;case"buckets":return fI(e.match,t);case"points":return wt(e.match.distance,t)}}function hI(e,t){return e.match.index.projection==="polar"?t.polar:t.cartesian}function fI(e,t){return e.strokeDistance<=t.on.stroke?!0:wt(e.vertexDistance,t)}function ji(e,t){return t===void 0?!1:!Zl(e,t)&&!ht(e.match,t)}function gI({layer:e,cursor:t,aspectRatio:r,warmStarts:n,tolerance:a}){switch(e.kind){case"buckets":{const i=KA(e,t,r);return i?{kind:"buckets",match:i}:null}case"banded":{const i=FA(e,t,r);return i?{kind:"banded",match:i}:null}case"points":{const i=uA(e,t,r,n.get(e.layerId)??null,a);return i?{kind:"points",match:i}:null}case"enclosure":{const i=ZA(e,t);return i?{kind:"enclosure",match:i}:null}case"noop":return null}}function yI(e,t,r,n){switch(e.kind){case"enclosure":{const a=lI(e,t,r,n!==void 0);return a?{kind:"enclosure",match:a}:null}case"points":{const a=cI(e,t,r,n);return a?{kind:"points",match:a}:null}case"buckets":{const a=aI(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=JA(e,t,r);return a?{kind:"banded",match:a}:null}case"noop":case"render-hit-test":return null}}function vI(e,t,r){const n=r.get(e.layerId);if(!n)return null;const a=n({x:t.x,y:1-t.y});if(!a)return null;const i=e.byKey.get(a.key);return i?{hit:Wl(e.layerId,i)}:null}var oe={primary:null,group:[],related:new Map},bI=1,SI=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.viewport=null,this.aspectRatio=bI,this.isAspectStale=!1,this.warmStarts=new Map,this.cachedState=oe,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=oe,this.layerIndexes=e.map(r=>Ui(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>Xi(r,t)),this.nonInteractiveLayerIds=Zi(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const o=this.layerIndexes[i],s=this.layerRefs[i];!o||!s||r.set(o.layerId,{index:o,ref:s})}const n=[],a=[];for(const i of e){const o=r.get(i.id),s=Xi(i,t);if(o!==void 0&&AI(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push(Ui(i,t,this.aspectRatio)),a.push(s)}for(const i of this.warmStarts.keys())e.some(o=>o.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=Zi(e),this.invalidateCache()}setViewport(e){if(e.width<=0||e.height<=0)return;this.viewport=e;const t=e.width/e.height;t!==this.aspectRatio&&(this.aspectRatio=t,this.isAspectStale=!0)}query(e,t){if(this.layerIndexes.length===0)return oe;this.reindexForAspect();const r=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(d=>!this.nonInteractiveLayerIds.has(d.layerId)),n=t!==void 0&&this.viewport!==null?cA(t,this.viewport):void 0,a=dI({layers:r,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e,tolerance:n});if(!a)return this.invalidateCache(),oe;const i=a.match.hit;this.warmStarts.set(i.layerId,i.pointIndex);const o=n===void 0?void 0:pI(a,n),s=xI(i,o);if(this.cachedKey===s)return this.cachedState;const{group:c,related:u}=fA(a,r);return this.cachedKey=s,this.cachedState=o===void 0?{primary:i,group:c,related:u}:{primary:i,group:c,related:u,intersection:o},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return oe;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return oe;const n=r.byKey.get(t);if(!n)return oe;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Wl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=oe,this.cachedByKeyId=null,this.cachedByKeyState=oe}reindexForAspect(){if(this.isAspectStale){this.isAspectStale=!1;for(const e of this.layerIndexes)e.kind==="points"&&e.projection==="cartesian"&&Gl(e,this.aspectRatio)}}};function xI(e,t){const r=`${e.layerId}:${e.pointIndex}`;return t===void 0?r:`${r}:${t.intersects}:${t.onPoint}`}function Xi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Zi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function AI(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var II=Math.PI*2;function TI(e,t){const r=Z(e.mainAxis,t);if(e.mainAxis==="y"){const a=De(ce(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=De(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function LI(e,t,r){const n=e.mainAxis==="y"?D(r.observation):M(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Ql(r):Jl(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const o=i/2;return e.mainAxis==="y"?{x:0,y:De(ce(n+o)),width:"100%",height:De(i)}:{x:De(n-o),y:0,width:De(i),height:"100%"}}function EI(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=j(t.observation),i=X(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=G(t.observation),n=F(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+II,innerRadius:r,outerRadius:n}}function Jl(e){const t=j(e.observation),r=X(e.observation);return t===null||r===null?null:r-t}function Ql(e){const t=G(e.observation),r=F(e.observation);return t===null||r===null?null:r-t}function wI(e){return e.observationIndex??e.pointIndex}function ec(e){return e==="buckets"||e==="filled-buckets"}var Ir=.5,RI=.3,CI=.4,VI=10,DI=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?PI(e,t,r,n):OI(e,t,n):ec(e.spatialKind)&&t.type==="cartesian"?NI(e,t,n):e.spatialKind==="cells"?kI(e,n):e.spatialKind==="points"?MI(e,n):null,_I=e=>{if(ec(e.spatialKind)){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},PI=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:Ir*n.durationScale,baseline:BI(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?FI(e,t.mainAxis,n):{}}),OI=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:Ir*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?UI(e,t,r):{}}},MI=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:Ir*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?$I(e,t):{}}),kI=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:RI*t.durationScale}),NI=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:Ir*r.durationScale,axis:t.mainAxis}),BI=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[Te(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const o=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-o:o},FI=(e,t,r)=>{const n=xr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=Rl(t,i);if(!o)continue;const s=Cl(t,o),c=n(i),u=a.get(s);u?u.keys.push(c):a.set(s,{position:t==="x"?o.x:o.y,keys:[c]})}return ha([...a.values()],r)},$I=(e,t)=>{const r=xr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=GI(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return ha(n,t)},GI=(e,t)=>{if(t==="main-axis")return M(e);const r=Zn(e)??M(e);return r===null?null:t==="value-descending"?-r:r},UI=(e,t,r)=>{const n=xr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=ea(i),{innerRadius:c,outerRadius:u}=ta(i);if(o===null||s===null||c===null||u===null)continue;const d=_l(t.bandAxis,{startAngle:o,endAngle:s,innerRadius:c,outerRadius:u}),p=n(i),h=a.get(d);h?h.keys.push(p):a.set(d,{position:o,keys:[p]})}return ha([...a.values()],r)},ha=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((s,c)=>s.position-c.position),a=Math.ceil(n.length/VI),i=Math.ceil(n.length/a),o=CI*t.durationScale/i;return n.forEach((s,c)=>{const u=Math.floor(c/a)*o;for(const d of s.keys)r[d]=u}),r},qe=["top","right","bottom","left"],Ji={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},HI={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},WI={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},KI=(e,t)=>{const{edges:r,borderRadius:n}=e,a=Math.max(0,Math.min(n,t.width/2,t.height/2)),i=c=>{const[u,d]=WI[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=YI(t,a),s=qI(t,a,i);return jI(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:XI(c,o,s,i)}))},zI=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),YI=(e,t)=>{const{x:r,y:n,width:a,height:i}=e;return{topLeft:{cx:r+t,cy:n+t,startAngle:Math.PI,endAngle:Math.PI*1.5,radius:t},topRight:{cx:r+a-t,cy:n+t,startAngle:Math.PI*1.5,endAngle:Math.PI*2,radius:t},bottomRight:{cx:r+a-t,cy:n+i-t,startAngle:0,endAngle:Math.PI*.5,radius:t},bottomLeft:{cx:r+t,cy:n+i-t,startAngle:Math.PI*.5,endAngle:Math.PI,radius:t}}},qI=(e,t,r)=>{const{x:n,y:a,width:i,height:o}=e,s=c=>r(c)?t:0;return{top:{start:{x:n+s("topLeft"),y:a},end:{x:n+i-s("topRight"),y:a}},right:{start:{x:n+i,y:a+s("topRight")},end:{x:n+i,y:a+o-s("bottomRight")}},bottom:{start:{x:n+i-s("bottomRight"),y:a+o},end:{x:n+s("bottomLeft"),y:a+o}},left:{start:{x:n,y:a+o-s("bottomLeft")},end:{x:n,y:a+s("topLeft")}}}},jI=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(qe.indexOf(o)+s+qe.length)%qe.length;return qe[c]},n=o=>{const s=r(o,-1);return!t(s)||e[s].lineType!==e[o].lineType||e[s].strokeWidth!==e[o].strokeWidth||e[s].color!==e[o].color},a=qe.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...qe],isClosed:!0}]:i.map(o=>{const s=[o];for(let c=r(o,1);t(c)&&!n(c);c=r(c,1))s.push(c);return{firstEdge:o,edges:s,isClosed:!1}})},XI=(e,t,r,n)=>{const a=(p,h,m)=>({type:"arc",cx:p.cx,cy:p.cy,radius:p.radius,startAngle:h,endAngle:m}),i=p=>(p.startAngle+p.endAngle)/2,o=[],s=e.firstEdge,c=e.edges[e.edges.length-1],u=Ji[s];if(!e.isClosed&&n(u)){const p=t[u],h=i(p),m=ZI(p,h);o.push({type:"move",x:m.x,y:m.y}),o.push(a(p,h,p.endAngle))}else o.push({type:"move",x:r[s].start.x,y:r[s].start.y});o.push({type:"line",x:r[s].end.x,y:r[s].end.y});for(const p of e.edges.slice(1)){const h=Ji[p];if(n(h)){const m=t[h];o.push(a(m,m.startAngle,m.endAngle))}o.push({type:"line",x:r[p].end.x,y:r[p].end.y})}const d=HI[c];if(e.isClosed){if(n(d)){const p=t[d];o.push(a(p,p.startAngle,p.endAngle))}o.push({type:"close"})}else if(n(d)){const p=t[d];o.push(a(p,p.startAngle,i(p)))}return o},ZI=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),JI=/^(?:https?:|mailto:)/i,QI=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:JI.test(t)},eT=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...Y,...t}).format(r)),tT=({locale:e,intlOptions:t})=>K(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...Y,...t}).format(r)}),ar=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return zs(e);case"date":return eT(e);case"datetime":return tT(e);case"day_month":return Xs(e);case"decimal":return Ys(e);case"duration":return Gn(e);case"integer":return qs(e);case"month":return Zs(e);case"month_year":return Wn(e);case"percentage":return js(e);case"quarter":return Kn(e);case"text":return $n(e);case"time":return el(e);case"weekly_date_range":return Js(e);case"weekly_date_range_with_year":return Qs(e);case"year":return zn(e);case"lookup":return ar({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},tc={width:12,height:12},rT=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:o,colorScheme:s,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:p}=o;if(p===null)return null;const h=c??i,m=nT(u,d);return{header:m===null?aT({layers:e,coordSystem:t,guides:n,primary:p,locale:h,numberFormat:a}):null,rows:iT({layers:e,scales:r,guides:n,hover:o,locale:h,numberFormat:a,colorScheme:s}),comment:m}};function nT(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function aT(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=oa(e.guides,"x");if(!t)return null;const r=e.layers.find(i=>i.id===e.primary.layerId);if(!r)return null;const n=l.extractVariableName(r.mapping.x);if(!l.isDefined(n))return null;const a=e.primary.observation[n];return l.isDefined(a)?ar({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function iT(e){const t=[],r=e.scales.color??null,n=st({colorScheme:e.colorScheme}),a=cT({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=sT(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...oT(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Io(i.data,i.mapping),u=lT(o,i,r,c),d=ra({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=uT(e.guides,i),h=gt(i),m=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const v=m?c(g.observation):null,y=f.get("color",g.observation),b=f.get("lineType",g.observation)??"solid",A=ca(f,i,g.observation,tc),T=m&&v!==null?a(v):p,L=h(g.observation),E=L===null?"":d(L,g.observation);t.push({swatchColor:y,geom:i.geom,swatchLineType:b,swatchAlpha:A.alpha,swatchCornerRadius:A.cornerRadiusPx,label:T,value:E,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function oT(e,t,r,n,a){const i=ca(n,e,t.observation,tc);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=Q(e.data,s)(t.observation),d=k({valueFormat:xn(e,c),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:o.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",swatchAlpha:i.alpha,swatchCornerRadius:i.cornerRadiusPx,label:o.key??mr(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function sT(e,t){const r=[];return t.primary!==null&&t.primary.layerId===e.id&&r.push(t.primary,...t.group),r.push(...t.related.get(e.id)??[]),r}function lT(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,o)=>{a.set(l.getStableKey(i),o)}),e.map((i,o)=>{const s=n(i.observation),c=s===null?null:l.getStableKey(s);return{hit:i,originalIndex:o,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,o)=>i.rank===o.rank?i.originalIndex-o.originalIndex:i.rank-o.rank).map(i=>i.hit)}function cT({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:ar({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=ar({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const o=n.get(l.getStableKey(i));return o===void 0?a(i):o.label??o.format(i)}}function uT(e,t){return mr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function dT(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function pT(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var mT=(e,t)=>{const r=e.annotation.shape(t),n=r.get("borderColor");return{color:r.get("color"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth")}},hT=(e,t)=>{const r=e.annotation.arrow(t),n=r.get("borderColor");return{color:r.get("color"),strokeWidth:r.get("strokeWidth"),lineType:r.get("lineType"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),shadow:r.get("shadow")}},fT=(e,t)=>{const r=e.annotation.differenceArrow(t),n=e.annotation.differenceArrow.label(t),a=n.get("borderColor");return{color:r.get("color"),isColorAuthored:r.getSource("color")==="authored",strokeWidth:r.get("strokeWidth"),label:{...N(n,e.graph),background:n.get("background"),...a===void 0?{}:{borderColor:a},borderWidth:n.get("borderWidth"),borderRadius:n.get("borderRadius"),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock")}}},gT=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...N(r,e.graph),background:r.get("background"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock")}},yT=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},vT=(e,t,r)=>{const n=e.annotation[t](r),a=e.annotation[t].label(r);return{marker:{color:n.get("color"),isColorAuthored:n.getSource("color")==="authored",size:n.get("size"),borderColor:n.get("borderColor"),borderWidth:n.get("borderWidth"),shadow:n.get("shadow")},label:{...N(a,e.graph),isTextColorAuthored:a.getSource("textColor")==="authored",background:a.get("background"),borderColor:a.get("borderColor"),borderWidth:a.get("borderWidth"),borderRadius:a.get("borderRadius"),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),shadow:a.get("shadow")}}},bT=e=>e.borderWidth>0?e.borderColor??e.color:void 0,ST=e=>({edges:{top:Ze(e.panelBorder("top")),right:Ze(e.panelBorder("right")),bottom:Ze(e.panelBorder("bottom")),left:Ze(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),xT=(e,t)=>Ze(e.gridLine(t)),AT=(e,t)=>{const r=e.tickLine(t);return{...Ze(r),length:r.get("length")}},IT=e=>e.heading.h1.get("fontFamily")??e.graph.get("fontFamily"),TT=e=>{const t=e.graph.get("borderColor");return{background:e.graph.get("background"),...t===void 0?{}:{borderColor:t},borderWidth:e.graph.get("borderWidth"),borderRadius:e.graph.get("borderRadius")}},LT=e=>{const t=e.graph.get("padding");return typeof t=="number"?{top:t,right:t,bottom:t,left:t}:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},ET=e=>{const t=e.legend.popover;return{gap:e.legend().get("gap"),popover:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")}}},wT=e=>({gap:e.headline.get("gap")}),q=e=>{let t={top:0,right:0,bottom:0,left:0};for(const r of e.collectAll("margin"))t=typeof r=="number"?{top:r,right:r,bottom:r,left:r}:{...t,...r};return t},RT=e=>({header:q(e.header),footer:q(e.footer),headline:q(e.headline),legend:{top:q(e.legend("top")),right:q(e.legend("right")),bottom:q(e.legend("bottom")),left:q(e.legend("left"))},axisLabel:{top:q(e.axisLabel("x","top")),bottom:q(e.axisLabel("x","bottom"))},tickLabel:{top:q(e.tickLabel("x","top")),right:q(e.tickLabel("y","right")),bottom:q(e.tickLabel("x","bottom")),left:q(e.tickLabel("y","left"))}}),CT=e=>({color:e.hoverGuide.get("color"),background:e.hoverGuide.get("background")}),VT=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Ze=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),fa=["sticker","pinnedNumber","comment","image"],DT=e=>fa.includes(e),ga=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?PT(e.annotation.at):null;default:return null}},rc=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),nc=(e,t,r=_T)=>{const n=r(t);for(const a of fa){const i=It(e,a),o=i.findIndex(c=>{const u=ga({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return rc(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},_T=e=>({...e,anchorValue:Fr(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Fr(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Fr(e.crossValue)}}),Fr=e=>l.readISOInstant(e)??e,PT=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function OT(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var MT=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ya(r.predicate,t.predicate))??null,ya=(e,t)=>"and"in e?"and"in t&&Qi(e.and,t.and):"or"in e?"or"in t&&Qi(e.or,t.or):"not"in e?"not"in t&&ya(e.not,t.not):kT(t)&&e.variable===t.variable&&NT(e,t),kT=e=>"variable"in e,Qi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ya(r,a)}),NT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&eo(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&eo(e.range,t.range),eo=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),BT={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},FT=e=>Object.hasOwn(BT,e);function $T(e){return{type:"mapping",mapping:e}}var Rt=(e,t)=>"and"in e?"and"in t&&to(e.and,t.and):"or"in e?"or"in t&&to(e.or,t.or):"not"in e?"not"in t&&Rt(e.not,t.not):GT(t)&&e.variable===t.variable&&UT(e,t),GT=e=>"variable"in e,to=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Rt(r,a)}),UT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ro(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&ro(e.range,t.range),ro=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ac=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="identity"&&(l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.y))||l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.x)))),ic=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),oc=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function sc(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(HT),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function HT(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?WT(r):r}function WT(e){return{...e,palette:KT(e.palette),overrides:zT(e.overrides)}}function KT(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function zT(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Ct=(e,t)=>{const r=va(e,t);return r===-1?void 0:e[r]},va=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&Tr(n,t))return r}return-1},Tr=(e,t)=>YT(e.select,t.select)&&e.when?.state===t.when?.state&&qT(e.when?.where,t.when?.where),lc=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>jT(e[r],t[r])),_e=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),ba=e=>e.select.target==="geom",Vt=(e,t)=>{const r=Ct(e,t);if(!(r===void 0||!ba(r)))return r.declarations},YT=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},qT=(e,t)=>e===void 0||t===void 0?e===t:Rt(e,t),jT=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function x(e){return{id:e.id??W(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function at(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>at(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>at(e[a],t[a]))}return!1}var Sa=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=x({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=At(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:R(e,{annotations:Rs(e.annotations,t)}),revert:new xa({kind:r,annotation:a,index:n},this.metadata)}}},XT={type:"remove-annotation",deserialize:(e,t)=>new Sa(e,t)},xa=class cc{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??W()},...t.index!==void 0&&{index:t.index}},this.metadata=x({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Yg(r)||At(t.annotations,n.id))return null;const i=JT(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:Rs(t.annotations,i),s=It(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:R(t,{annotations:Nn(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new Sa({id:n.id},this.metadata):new cc({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},ZT={type:"add-annotation",deserialize:(e,t)=>new xa({kind:e.kind,annotation:e.annotation,index:e.index},t)},JT=(e,t)=>{const r=ga(t);return r===null?null:nc(e,r)},QT=(e,t)=>{const r=Aa(e);return r===null?null:uc(r.points,t)},eL=e=>Aa(e)!==null,tL=(e,t)=>{const r=Aa(e);if(r===null)return null;const n=uc(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},Aa=e=>{const t=nL[e.kind];return t===null?null:t(e.annotation)},no=(e,t)=>e.anchorType!=="panel"?null:{points:[cn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},ao=(e,t)=>e.anchorType!=="panel"?null:{points:[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},rL=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[cn(e,e.offset),cn(t,t.offset)],createPatch:r=>({start:{...e,x:e.x+r.x,y:e.y+r.y},end:{...t,x:t.x+r.x,y:t.y+r.y}})},nL={text:e=>no(e.at,t=>({at:t})),sticker:e=>no(e.at,t=>({at:t})),shape:e=>ao(e.region,t=>({region:t})),image:e=>ao(e.region,t=>({region:t})),arrow:e=>rL(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},cn=(e,t)=>t===void 0||t.unit==="px"?{x:e.x,y:e.y}:{x:e.x+(t.x??0),y:e.y+(t.y??0)},uc=(e,t)=>({x:io(e.map(r=>r.x),t.x),y:io(e.map(r=>r.y),t.y)}),io=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:(0,Je.default)(t,r,n)},dc=(e,t,r)=>{const n=t.annotation;if(!oL(n,r))return null;const a=It(e.annotations,t.kind),i=aL(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:R(e,{annotations:Nn(e.annotations,t.kind,o)}),inverse:iL(n,r)}},aL=(e,t)=>{const r=new Set(Object.entries(t).filter(([,n])=>n===void 0).map(([n])=>n));return Object.fromEntries(Object.entries({...e,...t}).filter(([n])=>!r.has(n)))},iL=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},oL=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),Ia=class pc{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=x({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=At(t.annotations,n);if(i===null||i.kind!==r)return null;const o=dc(t,i,a);return o===null?null:{spec:o.spec,revert:new pc({kind:r,id:n,patch:o.inverse},this.metadata)}}},sL={type:"update-annotation",deserialize:(e,t)=>new Ia(e,t)},mc=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=x({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=At(e.annotations,this.params.id);if(t===null)return null;const r=tL(t,this.params.translation);if(r===null)return null;const n=dc(e,t,r);return n===null?null:{spec:n.spec,revert:new Ia({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},lL={type:"move-annotation",deserialize:(e,t)=>new mc(e,t)},be=class qt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=x({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],o=va(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new qt({list:r,rule:s,index:o},this.metadata),g=i.filter(v=>!Tr(v,n));return{spec:$r(t,r,g),revert:f}}if(s!==void 0){if(lc(s.declarations,c))return null;const f={...s,declarations:c},g=new qt({list:r,rule:s,index:o},this.metadata),v=i.map(y=>y===s?f:y);return{spec:$r(t,r,v),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),p={...n,declarations:c},h=[...i.slice(0,d),p,...i.slice(d)],m=new qt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:$r(t,r,h),revert:m}}},cL=e=>{const{rule:t}=e;if(t==null)throw new l.UserInputError({code:"INVALID_STYLE_RULE",message:"Command 'set-style-rule' is missing its 'rule'.",suggestion:"Send the entry's 'select' (and 'when') with 'declarations: null' to remove it."})},uL={type:"set-style-rule",deserialize:(e,t)=>(cL(e),new be(e,t))},$r=(e,t,r)=>R(e,{styles:{...e.styles,[t]:r}}),dL={type:"set-difference-arrow-style",deserialize:(e,t)=>new hc(e,t)},hc=class fc{constructor(t,r={}){this.type="set-difference-arrow-style",this.params=t,this.metadata=x({...r,description:"Set difference arrow style"})}get target(){return{kind:"annotation",id:this.params.annotationId}}apply(t){const{annotationId:r,arrow:n,label:a}=this.params,i={target:"annotation",kind:"differenceArrow",annotation:r},o={...i,part:"label"};let s=t;const c={annotationId:r},u=d=>{const p=Ct(s.styles.overrides,d),h=new be({list:"overrides",rule:d}).apply(s);if(h)return s=h.spec,p?.declarations??null};if(n!==void 0){const d=u({select:i,declarations:n});d!==void 0&&(c.arrow=d)}if(a!==void 0){const d=u({select:o,declarations:a});d!==void 0&&(c.label=d)}return s===t?null:{spec:s,revert:new fc(c,this.metadata)}}},pL=["cartesian","polar","flip"],J=new fr,gc=e=>J.has(e)?J.get(e):null,yc=new l.TransformRegistry,mL=new Bs(yc),Lr=e=>{const t=e.transforms.every(r=>yc.has(r.transformType));return e.transforms.length===0||!t?e.data:mL.compile({data:e.data,transforms:e.transforms})};function Ta(e,t){const r=t.some(i=>i.yScaleType==="secondary"),n=e.find(i=>i.scaledAesthetic==="ySecondary");if(!r)return n===void 0?e:e.filter(i=>i!==n);if(n!==void 0)return e;const a=e.find(i=>i.scaledAesthetic==="y");return a===void 0?e:[...e,{...a,scaledAesthetic:"ySecondary"}]}function Dt(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function _t(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:R(e,{scales:Ro(e.scales,n,r)})}function Pt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function un(e,t,r){const n=yr(On(Fs(J),{data:Lr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Mn(n):n}var vc=class bc{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:LL(t)})}apply(t){const r="previous"in this.params?this.params.previous:EL(t,this.params);if(r===null)return null;const n=R(t,r);return n===t?null:{spec:n,revert:new bc({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},hL={type:"set-chart-type",deserialize:(e,t)=>new vc(e,t)},Sc={type:"sum"},fL={type:"identity"},gL=["bar","line","area","point","tile"],La="tile",yL=["y","color"],vL=Object.values(l.LAYER_LABEL_VARIABLES),bL={coordType:"cartesian",geom:La,position:"identity"},Ot=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),SL=e=>{const t=e.layers.filter(de),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=Ac(t);if(o!==null)return{coordType:"cartesian",comboType:o}}if(!t.every(o=>o.geom===r.geom&&o.position===r.position))return null;const{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},xL=e=>{if(!e)return!1;const t=e.layers.filter(de);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:Ic(e,r)?Tc(e,r).length>=1:Er(e,e.data.groupVariableNamesByType().numeric).length>=2},AL=e=>e?Vc(e,bL)!==null:!1,IL=e=>xc(e)?.at(-1)?.id??null,xc=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(de);return Ac(t)===null?null:t},Ac=e=>{const t=e.at(-1);if(e.length<2||t?.geom!=="line")return null;const r=e.slice(0,-1);if(r.every(a=>a.geom==="line"))return TL(e)?"lines":null;if(!r.every(a=>a.geom==="bar"))return null;const[n]=r;return n===void 0||!r.every(a=>a.position===n.position)?null:l.readComboTypeOfBarPosition(n.position)},TL=e=>e.some(t=>t.yScaleType==="secondary"||ir(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,LL=e=>"previous"in e?"Restore the previous chart type":Ot(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,EL=(e,t)=>{const r=Vc(e,t);if(r===null)return null;const n=Ot(t)?RL(r,t):wL(r,t,e);return n===null||r===e?n:{...n,scales:GL({...e,...n},n.scales)}},wL=(e,t,r)=>{if(Ot(t)||!UL(t))return null;const n={...e,layers:Nc(e.layers)},a=KL(n.layers.filter(de),t),i=Fc(n.coords,t),o=Rc(n,t),s=kc({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:Ta($c(r,s,i.coordType),s),mapping:o}},RL=(e,t)=>{const r=DL(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=zL(r.filter(de),t.comboType),i=Fc(n.coords,t),o=Rc(n,t),s=kc({...n,mapping:o},t,a,o!==n.mapping),c=CL(e)?s:VL(s);return{coords:i,layers:c,scales:Ta($c(e,c,i.coordType),c),mapping:o}},CL=e=>xc(e)!==null,VL=e=>{const t=e.filter(de).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},DL=(e,t)=>{const r=e.layers.filter(de);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:Ic(e,n)?_L(e,n):PL(e,n,t)},Ic=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},_L=(e,t)=>{const[r]=Tc(e,t);if(r===void 0)return null;const n=Ue(J,e.mapping,e.coords.coordType,{type:"layer",id:Lc(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:Sc,...wc(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},Er=(e,t)=>{const r=Mt(e);return t.filter(n=>n!==r)},Tc=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return Er(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},Mt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),PL=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=Er(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,Mt(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=OL(t,oo(a.slice(0,-1),o,s)),u=Ue(J,e.mapping,e.coords.coordType,{type:"layer",id:Lc(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...oo([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Lc=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},oo=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?wc(n,r):Ec(e,t)},Ec=(e,t)=>({mapping:{y:l.DEFAULT_RESHAPE_VALUE_NAME,color:"key"},transforms:[l.transform.reshape({keep:t,reshape:e,keyName:"key",valueName:l.DEFAULT_RESHAPE_VALUE_NAME})]}),wc=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),OL=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Rc=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Cc(t)?"":Mt(e);return n===r?e.mapping:{...e.mapping,x:n}},Cc=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",ML=e=>!Ot(e)&&e.geom===La,kL=e=>e.layers.filter(de).some(t=>t.geom===La),Vc=(e,t)=>{const r=ML(t);return r===kL(e)?e:r?NL({...e,layers:Nc(e.layers)}):BL(e)??e},NL=e=>{const t=_c(e);if(t===null)return null;const r=FL(e,t)===null?$L(e,t):Pc(e,t);return r===null?null:Dc(e,t,r)},BL=e=>{const t=_c(e);if(t===null)return null;const r=Pc(e,t);return r===null?null:Dc(e,t,r)},Dc=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),_c=e=>{const t=e.layers.filter(de);return t.length===1?t[0]??null:null},Pc=(e,t)=>{const r={...e.mapping,...t.mapping};return r.y===void 0||r.color===void 0?null:{mapping:{...e.mapping,y:r.color,color:r.y},layer:Oc(t)}},Oc=e=>{if(e.mapping.y===void 0&&e.mapping.color===void 0)return e;const{y:t,color:r,...n}=e.mapping;return{...e,mapping:n}},FL=(e,t)=>{const r={...e.mapping,...t.mapping},n=l.extractVariableName(r.color),a=l.extractVariableName(r.y);if(n===null||n===""||a===null||a===""||n===Mt(e))return null;const i=Lr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},$L=(e,t)=>{const r=Er(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,Mt(e)),a=Ec(r,n),i=Oc(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},GL=(e,t)=>yL.reduce((r,n)=>{const a=un(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Be(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),UL=e=>pL.includes(e.coordType)&&Mc(e.geom)&&HL(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),HL=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=J.get(e);return n.includes(t)&&a.includes(r)},Mc=e=>gL.includes(e),de=e=>Mc(e.geom)&&!WL(e.stat),WL=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},KL=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},zL=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,o)=>n===null||o===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:YL(i,t,n)}]);return new Map(a)},YL=(e,t,r)=>e.geom!=="bar"||ir(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,kc=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Ts(J,Be(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=qL(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?XL(e,{...i,stat:s},t.coordType,o):i}))},qL=(e,t,r)=>Cc(r)?e.type==="identity"?Sc:e:jL(t)&&e.type==="sum"?fL:e,jL=e=>e.coordType==="polar"&&e.params.theta==="y",XL=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:o,format:s,offset:c,justify:u,...d}=t.dataLabels;return{...Ue(J,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:s},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Nc=e=>{const t=e.filter(de);if(t.length<2||!e.some(ir))return e;const[r]=t;return e.flatMap(n=>n===r?[ZL(n)]:ir(n)?[]:[n])},ir=e=>Bc(e)!==null,Bc=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:vL.includes(t.options.variableName)?t:null},ZL=e=>{const t=Bc(e);if(t===null)return e;const{color:r,...n}=e.mapping,a=t.transformType==="reshape"?t.options.reshape?.[0]:void 0;return{...e,mapping:a===void 0?n:{...n,y:a},transforms:e.transforms.slice(0,-1)}},Fc=(e,t)=>{const r=JL(e,t);return(0,Xt.default)(r,e)?e:r},JL=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Zr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Kt;return Zr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},$c=(e,t,r)=>{const n=qr(J,t),a=qr(J,e.layers),i=e.coords.coordType==="polar";return Be(e.scales,o=>{const s=QL(o,n,a),c=eE(s,n,a);return rE(c,r,i)})},QL=(e,t,r)=>{if(e.scaleType==="discrete"){const a=t.bandPadding[e.scaledAesthetic];return a===void 0||e.padding===a?e:{...e,padding:a}}if(e.scaledAesthetic===t.discreteAxis)return Xr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Xr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=tE(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},eE=(e,t,r)=>{if(e.scaleType!=="discrete"||!$e(e.scaledAesthetic))return e;const n=t.bandPadding[e.scaledAesthetic];if(n===r.bandPadding[e.scaledAesthetic])return e;const a=n??l.DISCRETE_SCALE_DEFAULTS.padding;return e.padding===a?e:{...e,padding:a}},tE=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,rE=(e,t,r)=>{if(e.scaleType!=="discrete"||!$e(e.scaledAesthetic))return e;if(t==="polar")return e.padding===0?e:{...e,padding:0};if(!r)return e;const{padding:n}=l.DISCRETE_SCALE_DEFAULTS;return e.padding===n?e:{...e,padding:n}},Gc=class Uc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:aE(t)})}apply(t){const r="previous"in this.params?this.params.previous:iE(t,this.params);if(r===null)return null;const n=R(t,r);return n===t?null:{spec:n,revert:new Uc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},nE={type:"set-mapping",deserialize:(e,t)=>new Gc(e,t)},Hc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Wc=e=>e===""?null:e,aE=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Wc(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},iE=(e,{aesthetic:t,variable:r})=>{if(!FT(t))return null;const n=Wc(r),a=sE(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:cE(e,t,a,n),layers:oE(e.layers,a)}},oE=(e,t)=>Be(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&gc(r.geom)===null)return r;const a=Is(J,r.geom,r.position,n);return(0,Xt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),sE=(e,t,r)=>r===null?lE(e,t):Hc(e,t)===r?e:{...e,[t]:r},lE=(e,t)=>{if(t==="x")return l.readMainAxisVariable(e)===""?e:{...e,x:""};const r=e[t];if(r===void 0||l.extractVariableName(r)==="")return e;const n={};for(const[a,i]of Object.entries(e))a!==t&&(n[a]=i);return n},cE=(e,t,r,n)=>{if(!Wo(t))return e.scales;let a=e.scales;for(const i of uE(e,t))a=pE(e,a,i,r,n);return a},uE=(e,t)=>t==="y"&&dE(e.layers)?["y","ySecondary"]:[t],dE=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},pE=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,un(e,r,n)];if(a===null&&!$e(r)||a!==null&&!Lr(e).hasVariable(a))return t;const o=un(e,r,n);return mE(i,o)?t:Be(t,s=>s.scaledAesthetic===r?o:s)},mE=(e,t)=>e.scaleType===t.scaleType||so(e)&&so(t),so=e=>e.scaleType==="discrete"||e.scaleType==="palette",Ea=e=>e==="both"?["x","y"]:[e],Kc=e=>e==="both"?"the":`${e} axis`;function wa(e,t){return wr(e)?e[t]:e}function hE(e,t){return e.config.axes[t]??{}}function fE(e,t,r){if(t!=="ySecondary")return P(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=zc(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,R(e,{config:R(e.config,{axes:i})})}function wr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function zc(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],o=a in t?gE(i,t[a]):i;o!==i&&(n=!0),o!==void 0&&(r[a]=o)}return n?Object.keys(r).length>0?r:void 0:e}function gE(e,t){return l.isPlainObject(t)?zc(l.isPlainObject(e)?e:void 0,t):t}var Yc=class qc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${vE(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=hE(t,r).label;if(a===n)return null;const i=fE(t,r,{label:n});return i===t?null:{spec:i,revert:new qc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},yE={type:"set-axis-label",deserialize:(e,t)=>new Yc(e,t)};function vE(e){return e===void 0?"(inherited)":e??"(none)"}var jc=class Xc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:P(t,{config:{axes:{[r]:{position:n}}}}),revert:new Xc({axis:r,position:a},this.metadata)}}},bE={type:"set-axis-position",deserialize:(e,t)=>new jc(e,t)},Zc=class Jc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new Jc({axis:r,tickMode:a},this.metadata)}}},SE={type:"set-axis-tick-mode",deserialize:(e,t)=>new Zc(e,t)},Qc=class eu{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new eu({axis:r,isVisible:a},this.metadata)}}},xE={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new Qc(e,t)},tu=class ru{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new ru({axis:r,isVisible:a},this.metadata)}}},AE={type:"set-axis-visibility",deserialize:(e,t)=>new tu(e,t)},nu=class au{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=x({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:P(t,{config:{content:{caption:this.params.caption}}}),revert:new au({caption:r},this.metadata)}}},IE={type:"set-content-caption",deserialize:(e,t)=>new nu(e,t)},iu=class ou{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=x({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(at(r,this.params.source))return null;const n=R(t.config.content,{source:this.params.source});return{spec:R(t,{config:R(t.config,{content:n})}),revert:new ou({source:r},this.metadata)}}},TE={type:"set-content-source",deserialize:(e,t)=>new iu(e,t)},su=class lu{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=x({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:P(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new lu({subtitle:r},this.metadata)}}},LE={type:"set-content-subtitle",deserialize:(e,t)=>new su(e,t)},cu=class uu{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=x({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:P(t,{config:{content:{title:this.params.title}}}),revert:new uu({title:r},this.metadata)}}},EE={type:"set-content-title",deserialize:(e,t)=>new cu(e,t)},wE="dashed",RE=1,du=(e,t,r,n)=>{const a=CE(t,r),i=DE(e,a,n);let o=e,s=!1;for(const c of a){const u=PE(o,c,n,_E(n,VE(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},CE=(e,t)=>e==="both"&&!wr(t)?[void 0]:Ea(e),VE=(e,t)=>t===void 0?wr(e)?e.x:e:wa(e,t),DE=(e,t,r)=>t.length===1?Gr(e,t[0],r):{x:Gr(e,"x",r),y:Gr(e,"y",r)},Gr=(e,t,r)=>pu(e.styles.overrides,t)?.[r]??null,_E=(e,t)=>t===null||e==="lineType"&&t===wE||e==="strokeWidth"&&t===RE?null:t,PE=(e,t,r,n)=>{const a=pu(e.styles.overrides,t);return(a?.[r]??null)===n?null:new be({list:"overrides",rule:kE(t,ME(a,r,n))}).apply(e)?.spec??null},OE=e=>e.select.target==="gridLine",pu=(e,t)=>{const r=Ct(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!OE(r)))return r.declarations},ME=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},kE=(e,t)=>t===null?e===void 0?{select:{target:"gridLine"},declarations:null}:{select:{target:"gridLine",axis:e},declarations:null}:e===void 0?l.style.gridLine(t):e==="x"?l.style.gridLine.x(t):l.style.gridLine.y(t),mu=class hu{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${Kc(t.axis)} grid line style to ${BE(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=du(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new hu({axis:r,lineStyle:a.previous},this.metadata)}}},NE={type:"set-grid-line-style",deserialize:(e,t)=>new mu(e,t)},BE=({axis:e,lineStyle:t})=>{const r=Ea(e).map(n=>wa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},FE={type:"set-grid-line-width",deserialize:(e,t)=>new fu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-grid-line-width";const n=$E(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${Kc(t.axis)} grid line width to ${GE(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=du(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new gu({axis:r,lineWidth:a.previous},this.metadata)}}},$E=e=>wr(e)?{x:Ur(e.x),y:Ur(e.y)}:Ur(e),Ur=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),GE=(e,t)=>{const r=Ea(e).map(n=>wa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},yu=class vu{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new vu({axis:r,isVisible:a},this.metadata)}}},UE={type:"set-grid-visibility",deserialize:(e,t)=>new yu(e,t)},bu=class Su{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:P(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Su({compareWith:r},this.metadata)}}},HE={type:"set-headline-compare-with",deserialize:(e,t)=>new bu(e,t)},xu=class Au{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:P(t,{config:{headline:{position:this.params.position}}}),revert:new Au({position:r},this.metadata)}}},WE={type:"set-headline-position",deserialize:(e,t)=>new xu(e,t)},Iu=class Tu{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:P(t,{config:{headline:{show:this.params.show}}}),revert:new Tu({show:r},this.metadata)}}},KE={type:"set-headline-show",deserialize:(e,t)=>new Iu(e,t)},Lu=class Eu{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:P(t,{config:{headline:{size:this.params.size}}}),revert:new Eu({size:r},this.metadata)}}},zE={type:"set-headline-size",deserialize:(e,t)=>new Lu(e,t)},YE={type:"set-highlight-dim-style",deserialize:(e,t)=>new wu(e,t)},wu=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=x({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Ru(e)===this.params.dimStyle)return null;const t=new be({list:"overrides",rule:jE(this.params.dimStyle)},this.metadata).apply(e);return t||null}},qE={select:{target:"geom"},when:{state:"dimmed"}},Ru=e=>{const t=Ct(e.styles.overrides,qE);return(t!==void 0&&ba(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},jE=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Cu=class Vu{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:P(t,{config:{legend:{align:this.params.align}}}),revert:new Vu({align:r},this.metadata)}}},XE={type:"set-legend-align",deserialize:(e,t)=>new Cu(e,t)},Du=class _u{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:P(t,{config:{legend:{display:this.params.display}}}),revert:new _u({display:r},this.metadata)}}},ZE={type:"set-legend-display",deserialize:(e,t)=>new Du(e,t)},Pu=class Ou{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:P(t,{config:{legend:{position:this.params.position}}}),revert:new Ou({position:r},this.metadata)}}},JE={type:"set-legend-position",deserialize:(e,t)=>new Pu(e,t)},Mu=class ku{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:P(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new ku({abbreviation:r},this.metadata)}}},QE={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Mu(e,t)},Nu=class Bu{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:P(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Bu({decimals:r},this.metadata)}}},ew={type:"set-number-format-decimals",deserialize:(e,t)=>new Nu(e,t)},Fu=class $u{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=rw(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:P(t,{config:{content:{[a]:n}}}),revert:new $u({slot:r,isVisible:i},this.metadata)}}},tw={type:"toggle-content-visibility",deserialize:(e,t)=>new Fu(e,t)},lo={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function rw(e){return Object.hasOwn(lo,e)?lo[e]:void 0}var Gu=class Uu{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if(at(i.xLimits,a.xLimits)&&at(i.yLimits,a.yLimits))return null;const o={};r!==void 0&&(o.xLimits=a.xLimits),n!==void 0&&(o.yLimits=a.yLimits);const s=new Uu(o,this.metadata);return{spec:R(t,{coords:aw(t.coords,i)}),revert:s}}},nw={type:"set-coord-limits",deserialize:(e,t)=>new Gu(e,t)};function aw(e,t){switch(e.coordType){case"cartesian":return{...e,params:{...e.params,...t}};case"flip":return{...e,params:{...e.params,...t}};case"polar":return{...e,params:{...e.params,...t}}}}var Hu=class Wu{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Je.default)(t.innerRadius,0,1)},this.metadata=x({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:R(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Wu({innerRadius:n},this.metadata)}}},iw={type:"set-polar-inner-radius",deserialize:(e,t)=>new Hu(e,t)},ow={type:"set-polar-start-angle",deserialize:(e,t)=>new Ku(e,t)},Ku=class zu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:co(t.startAngle)},this.metadata=x({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return co(n)===this.params.startAngle?null:{spec:R(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new zu({startAngle:n},this.metadata)}}},Hr=360,co=e=>(e%Hr+Hr)%Hr,Ra=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=x({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new Ca({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:R(e,{highlights:n}),revert:a}}},sw={type:"remove-highlight",deserialize:(e,t)=>new Ra(e,t)},Ca=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??W(),scope:e.scope??"data-point"},this.metadata=x({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const o=new Ra({id:r},this.metadata),s={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:R(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},lw={type:"add-highlight",deserialize:(e,t)=>new Ca(e,t)};function Va(e,t){return{...e,params:{...e.params,...t}}}function Rr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function Da(e,t){return R(e,{layers:[...e.layers,t]})}function ee(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:R(e,{layers:Ro(e.layers,n,r)})}function Cr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:R(e,{layers:e.layers.filter((n,a)=>a!==r)})}var _a=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=x({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=Cr(e,this.params.layerId);return n===e?null:{spec:n,revert:new Pa({layer:r,index:t},this.metadata)}}},cw={type:"remove-layer",deserialize:(e,t)=>new _a(e,t)},Pa=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??W()},...e.index!==void 0&&{index:e.index}},this.metadata=x({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:R(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new _a({layerId:t.id},this.metadata)}}},uw={type:"add-layer",deserialize:(e,t)=>new Pa(e,t)},Yu=class qu{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=x({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!ae(B(t.layers,r),"bar"))return null;const a=_e("bar",r),i=Vt(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new be({list:"overrides",rule:{...a,declarations:pw(i,n)}}).apply(t);if(!s)return null;const c=new qu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},dw={type:"set-bar-border-radius",deserialize:(e,t)=>new Yu(e,t)},pw=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},mw={type:"set-bar-width",deserialize:(e,t)=>new Xu(e,t)},ju=.05,hw=1,Xu=class Zu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Je.default)(t.width,ju,1);this.params={...t,width:n},this.metadata=x({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"bar");if(!ae(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:ee(t,r.id,Va(r,{width:this.params.width})),revert:new Zu({layerId:r.id,width:n},this.metadata)}}},Ju=class Qu{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=x({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:ee(t,r.id,Rr(r,{format:this.params.format})),revert:new Qu({layerId:r.id,format:n},this.metadata)}}},fw={type:"set-data-labels-format",deserialize:(e,t)=>new Ju(e,t)},ed=class td{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=x({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:ee(t,r.id,{...r,position:this.params.position}),revert:new td({layerId:r.id,position:n},this.metadata)}}},gw={type:"set-layer-position",deserialize:(e,t)=>new ed(e,t)},rd=class nd{constructor(t,r={}){this.type="set-layer-stat";const n=As(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=x({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return vw(n,this.params.stat)?null:{spec:ee(t,r.id,{...r,stat:this.params.stat}),revert:new nd({layerId:r.id,stat:n},this.metadata)}}},yw={type:"set-layer-stat",deserialize:(e,t)=>new rd(e,t)},vw=(e,t)=>{if(e.type!==t.type)return!1;const r=e,n=t,a=new Set([...Object.keys(r),...Object.keys(n)]);for(const i of a)if(!Object.is(r[i],n[i]))return!1;return!0},ad=class id{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=x({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=ee(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:R(a,{scales:Ta(a.scales,a.layers)}),revert:new id({layerId:r.id,yScaleType:n},this.metadata)}}},bw={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ad(e,t)},od=class sd{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=x({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:ee(t,r.id,Va(r,{interpolate:this.params.interpolate})),revert:new sd({layerId:r.id,interpolate:n},this.metadata)}}},Sw={type:"set-line-interpolation",deserialize:(e,t)=>new od(e,t)},ld=class cd{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=x({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:ee(t,r.id,Va(r,{missingValues:this.params.missingValues})),revert:new cd({layerId:r.id,missingValues:n},this.metadata)}}},xw={type:"set-line-missing-values",deserialize:(e,t)=>new ld(e,t)},ud=class dd{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=x({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=B(t.layers,r);if(!ae(a,"line","area"))return null;const i=Vt(t.styles.overrides,_e(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=Iw(i,n),c=new be({list:"overrides",rule:a.geom==="area"?{..._e("area",r),declarations:s}:{..._e("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new dd({layerId:r,lineWidth:o},this.metadata)}:null}},Aw={type:"set-line-width",deserialize:(e,t)=>new ud(e,t)},Iw=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},pd=class md{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=x({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!ae(B(t.layers,r),"point"))return null;const a=_e("point",r),i=Vt(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new be({list:"overrides",rule:{...a,declarations:Lw(i,n)}}).apply(t);return s?{spec:s.spec,revert:new md({layerId:r,size:o},this.metadata)}:null}},Tw={type:"set-point-size",deserialize:(e,t)=>new pd(e,t)},Lw=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},hd=class fd{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=x({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"rule");if(!ae(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([o])=>o!=="label")):{...r.params,label:a};return{spec:ee(t,r.id,{...r,params:i}),revert:new fd({layerId:r.id,label:n??null},this.metadata)}}},Ew={type:"set-rule-label",deserialize:(e,t)=>new hd(e,t)},gd=class yd{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=x({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"rule");if(!ae(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:ee(t,r.id,{...r,mapping:i}),revert:new yd({layerId:r.id,value:a},this.metadata)}}},ww={type:"set-rule-value",deserialize:(e,t)=>new gd(e,t)},Rw={type:"set-stat-line",deserialize:(e,t)=>new vd(e,t)},vd=class bd{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:Mw(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=Vw(t),n=this.buildStatLine(t,r?.line===this.params.line?r.layer.id:void 0);if(this.params.line!=="none"&&n===null||r===void 0&&n===null||r!==void 0&&n!==null&&Ow(r.layer,n))return null;const a=new bd({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:ee(t,r.layer.id,n),revert:a};const i=r===void 0?t:Cr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:Da(i,n),revert:a}}buildStatLine(t,r){if(this.params.line==="none")return null;if(this.params.removedLayer!==void 0)return this.params.removedLayer;const n=this.params.line==="trend"?Dw(this.params):_w(t,this.params);if(n===null)return null;const a=Ue(J,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},Cw="linear",Vw=e=>{const t=ic(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=oc(e.layers);if(r!==void 0)return{line:"average",layer:r}},Dw=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??Cw}),interactive:!1}),_w=(e,{group:t,label:r})=>{const n=Pw(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),o=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:o?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},Pw=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),Ow=(e,t)=>(0,it.isEqual)({...e,id:""},{...t,id:""}),Mw=e=>e==="none"?"Hide stat line":`Show ${e} line`,Sd=class xd{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=x({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:ee(t,r.id,Rr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new xd({layerId:r.id,showCategoryLabels:n},this.metadata)}}},kw={type:"toggle-category-labels",deserialize:(e,t)=>new Sd(e,t)},Ad=class Id{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=x({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:ee(t,r.id,Rr(r,{showDataLabels:this.params.showDataLabels})),revert:new Id({layerId:r.id,showDataLabels:n},this.metadata)}}},Nw={type:"toggle-data-labels",deserialize:(e,t)=>new Ad(e,t)},Bw={type:"toggle-goal-line",deserialize:(e,t)=>new Td(e,t)},Td=class dn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=x({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=ac(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=Cr(t,r.id);return a===t?null:{spec:a,revert:new dn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:Da(t,n),revert:new dn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ue(J,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??Fw}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},Fw=0,$w={type:"toggle-line-fill",deserialize:(e,t)=>new Ld(e,t)},Ld=class Ed{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=x({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!ae(B(t.layers,r),"line"))return null;const i=_e("line",r),o=Vt(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new be({list:"overrides",rule:{...i,declarations:Uw(o,n?a??Gw:null)}}).apply(t);if(!u)return null;const d=new Ed({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},Gw=.2,Uw=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},Hw={type:"toggle-line-points",deserialize:(e,t)=>new wd(e,t)},wd=class pn{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=x({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):Ee(t.layers,"line","area");return ae(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:Da(t,this.params.removedLayer??Ue(J,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new pn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:Cr(t,n.id),revert:new pn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:wn(n,[r]))}},Rd=class Cd{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=x({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?B(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:ee(t,r.id,Rr(r,{showStackTotals:this.params.showStackTotals})),revert:new Cd({layerId:r.id,showStackTotals:n},this.metadata)}}},Ww={type:"toggle-stack-totals",deserialize:(e,t)=>new Rd(e,t)},Vd=class Dd{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const o={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},s=_t(t,this.params.scaledAesthetic,o),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:s,revert:new Dd(c,this.metadata)}}},Kw={type:"set-scale-domain",deserialize:(e,t)=>new Vd(e,t)},_d=class Pd{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||at(r.palette,this.params.palette)?null:{spec:_t(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Pd({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},zw={type:"set-scale-palette",deserialize:(e,t)=>new _d(e,t)},Od=class Md{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||!qw(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:_t(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Md({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},Yw={type:"set-scale-reverse",deserialize:(e,t)=>new Od(e,t)};function qw(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var kd=class Nd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:_t(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Nd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},jw={type:"set-scale-transform",deserialize:(e,t)=>new kd(e,t)},Bd=class Fd{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${Pt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Dt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:_t(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Fd({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},Xw={type:"set-scale-zero",deserialize:(e,t)=>new Bd(e,t)},$d=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new $d;S.register(hL);S.register(nE);S.register(uw);S.register(cw);S.register(fw);S.register(gw);S.register(yw);S.register(bw);S.register(Sw);S.register(Aw);S.register(dw);S.register(mw);S.register(Tw);S.register(xw);S.register(Ew);S.register(ww);S.register(Rw);S.register(kw);S.register(Nw);S.register(Bw);S.register($w);S.register(Hw);S.register(Ww);S.register(Kw);S.register(zw);S.register(Yw);S.register(jw);S.register(Xw);S.register(yE);S.register(SE);S.register(bE);S.register(xE);S.register(AE);S.register(IE);S.register(TE);S.register(LE);S.register(EE);S.register(NE);S.register(FE);S.register(UE);S.register(HE);S.register(WE);S.register(KE);S.register(zE);S.register(YE);S.register(XE);S.register(ZE);S.register(JE);S.register(QE);S.register(ew);S.register(tw);S.register(lw);S.register(sw);S.register(uL);S.register(ZT);S.register(XT);S.register(sL);S.register(dL);S.register(lL);S.register(nw);S.register(iw);S.register(ow);var Gd=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return!1;switch(e.kind){case"annotation":return t.kind==="annotation"&&e.id===t.id;case"highlight":return t.kind==="highlight"&&e.id===t.id;case"styleRule":return t.kind==="styleRule"&&e.list===t.list&&Tr(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observations":return t.kind==="observations"&&e.layerId===t.layerId&&e.scope===t.scope&&Rt(e.predicate,t.predicate);case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"graph":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},Ud=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,o=e.apply(t);if(!o)return a||(this.hasOpenRun=!1),i(t,null);const s=r?.({spec:o.spec,command:e})??null,c=s?s.adopted:o.spec;return c?(this.push(e,c,o.revert,a),i(c,s?.value??null)):(a||(this.hasOpenRun=!1),i(t,s?.value??null))})}seal(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"seal"}),!0):!1)}undo(e,t){return this.withReentrancyGuard(()=>{const r=this.undoStack[this.undoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.undoStack.pop(),this.redoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"undo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}redo(e,t){return this.withReentrancyGuard(()=>{const r=this.redoStack[this.redoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.redoStack.pop(),this.undoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"redo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}clear(){this.withReentrancyGuard(()=>{this.hasOpenRun=!1,!(this.undoStack.length===0&&this.redoStack.length===0)&&(this.undoStack=[],this.redoStack=[],this.emit({type:"clear"}))})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null,undoStack:uo(this.undoStack),redoStack:uo(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],o=this.hasOpenRun&&i!==void 0&&Jw(i.command,e);if(n&&o){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},Zw=Object.freeze([]),Jw=(e,t)=>e.type===t.type&&Gd(e.target,t.target),uo=e=>e.length===0?Zw:e.map(t=>t.command.metadata),Qw=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.seal(),t=this.frame;return this.frame=null,e?t:null}},eR=class{constructor(e){this.compiler=e,this.history=new Ud,this.current=null,this.last=null,this.hostInput=null,this.run=new Qw(this.history)}get compiled(){return this.current}compile(e){return this.last=e,this.hostInput=e.input,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.input!==this.hostInput&&e.input!==t.input,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes,i=!t||e.colorScheme!==t.colorScheme;if(this.hostInput=e.input,!r&&!n&&!a&&!i)return null;let o=null;r?this.run.close():o=this.closeAndConvert();const s=this.last,c=s&&!r?s.input:e.input;this.last={input:c,data:e.data,customPalettes:e.customPalettes,colorScheme:e.colorScheme};const u=this.current,d=r||a||!u?this.absorb(this.compiler.compile(this.last)):this.absorb(this.compiler.recompile({spec:u.spec,data:e.data,colorScheme:e.colorScheme}));return r&&d.ok&&this.history.clear(),{result:d,inputChanged:r,...o&&{sealedInput:o.input}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.sealNotification(!1);c&&n.push(c)}const{current:a,last:i,history:o}=this;if(!a||!i)return n;const s=o.apply(e,a.spec,({spec:c})=>{const u=this.commit(c,i,r,e);return{adopted:u.ok?u.compiled.spec:null,value:u}},t);return s&&n.push(this.renderedNotification(s,e,r)),n}seal(){const e=this.sealNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const o=this.commit(a,r);return{adopted:o.ok?o.compiled.spec:null,value:{result:o,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{compiled:e.compiled}:{compiled:e.compiled,result:e,command:t,...e.input&&{input:e.input}}:{errors:e.errors}}sealNotification(e){const t=this.closeAndConvert();return t?{result:t.result,input:t.input,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{input:this.recordCompiledInput(t.spec,r),result:e.result,command:e.command}}commit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e,colorScheme:t.colorScheme});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const o={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:o,command:n}),o}this.run.clear();const i=this.recordCompiledInput(a.compiled.spec,t);return{ok:!0,compiled:a.compiled,warnings:a.warnings,input:i}}recordCompiledInput(e,t){const r=sc(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes,colorScheme:t.colorScheme},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},tR=new Set(["x","y"]),po=["numeric","categorical","temporal"],mo=["numeric"],rR=(e,t)=>{const r=e.layers.map(a=>gc(a.geom)).filter(l.isDefined),n=Lr(e);return t.filter(a=>nR(e,r,a)).map(a=>({aesthetic:a,variables:aR(n,r,a),isRequired:tR.has(a)}))},nR=(e,t,r)=>{switch(r){case"x":return!sR(e.coords);case"y":return!0;case"label":return t.some(n=>n.dataLabelCoordTypes.includes(e.coords.coordType));default:return t.some(n=>n.aesthetics.some(a=>a.kind==="visual"&&a.name===r))}},aR=(e,t,r)=>{const n=iR(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},iR=(e,t)=>t==="size"?mo:t!=="x"&&t!=="y"?po:oR(e,t)?mo:po,oR=(e,t)=>e.some(r=>r.positionRoles.some(n=>Ho.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),sR=e=>e.coordType==="polar"&&e.params.theta==="y",lR=500,cR="normal",Oa={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},uR=e=>{const t=e.style??"normal",r=e.weight??500,n=e.family.includes(",")?e.family:`'${e.family}'`;return`${t} ${r} ${e.size}px ${n}`},Ma=e=>typeof e!="string"?e??500:Oa[e],dR="\0",pR=class{constructor(e){this.inner=e,this.cache=new Map}measureText(e,t){const r=this.getCacheKey(e,t),n=this.cache.get(r);if(n)return n;const a=this.inner.measureText(e,t);return this.cache.set(r,a),a}getCacheKey(e,t){return[t.family,t.size,Ma(t.weight),t.style??"normal",e].join(dR)}},mR={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56};var hR=1.05,fR=.84,gR=.21,yR=class{measureText(e,t){let r=0;for(const i of e)r+=(mR[i]??.55)*t.size;Ma(t.weight)>=Oa.semiBold&&(r*=hR);const n=fR*t.size,a=gR*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_PARTS=l.ANNOTATION_PARTS;exports.ANNOTATION_STYLE_KINDS=l.ANNOTATION_STYLE_KINDS;exports.ANNOTATION_TOOLTIP_MARKER_GAP=kS;exports.ARROW_DEFAULTS=l.ARROW_DEFAULTS;exports.ARROW_STICKER_DECLARATIONS=l.ARROW_STICKER_DECLARATIONS;exports.ARROW_STROKE_WIDTHS=l.ARROW_STROKE_WIDTHS;exports.AXIS_KEYS=In;exports.AddAnnotationCommand=xa;exports.AddHighlightCommand=Ca;exports.AddLayerCommand=Pa;exports.BORDER_RADIUS_PX=sa;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Hf;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Cy;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=pR;exports.CommandRegistry=$d;exports.CommandStackManager=Ud;exports.Compiler=$s;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=cR;exports.DEFAULT_FONT_WEIGHT=lR;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRAPH_BORDER_WIDTH=l.DEFAULT_GRAPH_BORDER_WIDTH;exports.DEFAULT_GRAPH_PADDING=l.DEFAULT_GRAPH_PADDING;exports.DEFAULT_HEADLINE_SWATCH_SIZE=l.DEFAULT_HEADLINE_SWATCH_SIZE;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_MONO_BASE=l.DEFAULT_MONO_BASE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DIFFERENCE_ARROW_DEFAULTS=l.DIFFERENCE_ARROW_DEFAULTS;exports.DIFFERENCE_ARROW_SIZE_DECLARATIONS=l.DIFFERENCE_ARROW_SIZE_DECLARATIONS;exports.DIVERGING_SCHEME_NAMES=vs;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ve;exports.GraphCompilationSession=eR;exports.HEADING_PARTS=l.HEADING_PARTS;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=Ox;exports.HEADLINE_TREND_GAP=Nx;exports.HEADLINE_TREND_ICON_SIZE=kx;exports.HEADLINE_VALUE_LABEL_GAP=Mx;exports.HeuristicTextMeasurer=yR;exports.HoverEngine=SI;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=fn;exports.LayoutCompiler=sS;exports.MAX_BAR_WIDTH=hw;exports.MIN_BAR_WIDTH=ju;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=mc;exports.NAMED_WEIGHTS=Oa;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=fa;exports.OUT_OF_VIEW_MARGIN_PX=NS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=ep;exports.POSITION_TYPES=Ao;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=oe;exports.RemoveAnnotationCommand=Sa;exports.RemoveHighlightCommand=Ra;exports.RemoveLayerCommand=_a;exports.SCALED_POSITION_AESTHETIC_KEYS=Tn;exports.SCALED_VISUAL_AESTHETIC_KEYS=bt;exports.SCHEME_ALIASES=bs;exports.SEQUENTIAL_SCHEME_NAMES=Wf;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=BS;exports.SOURCE_PARTS=l.SOURCE_PARTS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=Yc;exports.SetAxisPositionCommand=jc;exports.SetAxisTickModeCommand=Zc;exports.SetAxisTicksVisibilityCommand=Qc;exports.SetAxisVisibilityCommand=tu;exports.SetBarBorderRadiusCommand=Yu;exports.SetBarWidthCommand=Xu;exports.SetChartTypeCommand=vc;exports.SetContentCaptionCommand=nu;exports.SetContentSourceCommand=iu;exports.SetContentSubtitleCommand=su;exports.SetContentTitleCommand=cu;exports.SetCoordLimitsCommand=Gu;exports.SetDataLabelsFormatCommand=Ju;exports.SetDifferenceArrowStyleCommand=hc;exports.SetGridLineStyleCommand=mu;exports.SetGridLineWidthCommand=fu;exports.SetGridVisibilityCommand=yu;exports.SetHeadlineCompareWithCommand=bu;exports.SetHeadlinePositionCommand=xu;exports.SetHeadlineShowCommand=Iu;exports.SetHeadlineSizeCommand=Lu;exports.SetHighlightDimStyleCommand=wu;exports.SetLayerPositionCommand=ed;exports.SetLayerStatCommand=rd;exports.SetLayerYScaleTypeCommand=ad;exports.SetLegendAlignCommand=Cu;exports.SetLegendDisplayCommand=Du;exports.SetLegendPositionCommand=Pu;exports.SetLineInterpolationCommand=od;exports.SetLineMissingValuesCommand=ld;exports.SetLineWidthCommand=ud;exports.SetMappingCommand=Gc;exports.SetNumberFormatAbbreviationCommand=Mu;exports.SetNumberFormatDecimalsCommand=Nu;exports.SetPointSizeCommand=pd;exports.SetPolarInnerRadiusCommand=Hu;exports.SetPolarStartAngleCommand=Ku;exports.SetRuleLabelCommand=hd;exports.SetRuleValueCommand=gd;exports.SetScaleDomainCommand=Vd;exports.SetScalePaletteCommand=_d;exports.SetScaleReverseCommand=Od;exports.SetScaleTransformCommand=kd;exports.SetScaleZeroCommand=Bd;exports.SetStatLineCommand=vd;exports.SetStyleRuleCommand=be;exports.SpecResolver=Es;exports.Stat=Ge;exports.TAU=fe;exports.TEXT_ANNOTATION_DEFAULTS=l.TEXT_ANNOTATION_DEFAULTS;exports.TEXT_ANNOTATION_FADE_ALPHA=l.TEXT_ANNOTATION_FADE_ALPHA;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Sd;exports.ToggleContentVisibilityCommand=Fu;exports.ToggleDataLabelsCommand=Ad;exports.ToggleGoalLineCommand=Td;exports.ToggleLineFillCommand=Ld;exports.ToggleLinePointsVisibilityCommand=wd;exports.ToggleStackTotalsCommand=Rd;exports.UpdateAnnotationCommand=Ia;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=xo;exports.annotation=zg;exports.areAnchorsEqual=Xe;exports.areEditMenuTriggersEqual=dx;exports.areEditTargetsEqual=Gd;exports.areEndpointsComparable=Lo;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=rc;exports.arePointerRegionListsEqual=ax;exports.arePredicatesEqual=Rt;exports.areStyleDeclarationsEqual=lc;exports.areStyleRuleAddressesEqual=Tr;exports.buildAverageLineSymbols=_S;exports.buildCalloutHitRegions=MS;exports.buildColumnKey=Cl;exports.buildDataLabelsContent=nb;exports.buildDiagnostic=wo;exports.buildEditMenuTriggerRegion=cx;exports.buildFontString=uR;exports.buildLayerIntroPlan=DI;exports.buildLayerStyleAddress=_e;exports.buildLayerYValueFormatter=ra;exports.buildObservationPredicate=Tl;exports.buildObservationsTarget=JS;exports.buildPinnedNumberValueFormatter=Ax;exports.buildPolarBarArcPath=Qx;exports.buildSliceGroupKey=_l;exports.buildTooltipContent=rT;exports.canAnchorDirectLabels=es;exports.canBecomeCombo=xL;exports.canBecomeHeatmap=AL;exports.canPlaceDataLabels=rb;exports.clampAnnotationTranslation=QT;exports.commandRegistry=S;exports.compileChromeStyles=Ds;exports.compileStylesheetForLayer=ey;exports.compositeColor=yo;exports.computeArrow=VS;exports.computeDifferenceArrow=fl;exports.computeDirectLabelsLayout=qS;exports.computeLineBoxHeight=gl;exports.computePanelBorderPaths=KI;exports.computePanelBorderSizes=zI;exports.config=l.config;exports.convertSpecToInput=sc;exports.coord=l.coord;exports.countLayerGeoms=_I;exports.createAlphaValueReader=lp;exports.createAnchorResolver=uS;exports.createAreaPathGenerators=Wx;exports.createColorValueReader=Io;exports.createCompiler=Vy;exports.createDatasetFromKindPartitions=Hp;exports.createEmptyHighlight=ts;exports.createGraphyBuilder=Py;exports.createGroupValueReader=cp;exports.createHeadlineItemRows=Bx;exports.createLabelValueReader=op;exports.createLineFillAreaGenerator=Xx;exports.createLinePathGenerator=jx;exports.createObservationAnchorBuilder=yt;exports.createObservationAnchorParser=Eo;exports.createRawValueReader=Q;exports.createSegmentYReader=gt;exports.createSizeValueReader=sp;exports.createSpec=Us;exports.createStableBandKeyGenerator=nA;exports.createStableCellKeyGenerator=aA;exports.createStableKeyGenerator=xr;exports.createStrokeWidthValueReader=up;exports.createStyleResolver=st;exports.createValueFormatter=k;exports.createXValueReader=ot;exports.createYValueReader=yn;exports.cursorToPiePlane=lr;exports.cursorToPolar=mn;exports.describeMeasurementBasis=Kr;exports.ensureReadableTextColor=Qd;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=Al;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=rh;exports.findAnnotation=At;exports.findAverageLineLayer=oc;exports.findAxisGuide=oa;exports.findDistinctLayers=Rn;exports.findEquivalentHighlight=MT;exports.findGoalLineLayer=ac;exports.findHighlightsAtObservation=mx;exports.findKindStyleDeclarations=Vt;exports.findLayerByGeom=Ee;exports.findLayerById=B;exports.findLegendForAesthetic=_x;exports.findObservationAttachment=nc;exports.findPointerRegion=rx;exports.findStyleRule=Ct;exports.findStyleRuleIndex=va;exports.findTrendLineLayer=ic;exports.formatDifferenceLabel=ml;exports.formatHeadline=Ix;exports.formatLegends=Vx;exports.formatRuleValue=Px;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=H;exports.getAlpha=nl;exports.getAngleExtent=ea;exports.getBarRectBounds=Rl;exports.getBoundingRect=qx;exports.getChromeDashArray=VT;exports.getColor=Et;exports.getCrossAxisCoordinate=ye;exports.getCurve=Sr;exports.getDashArray=Hx;exports.getDifferenceArrowDimensions=hl;exports.getDifferenceArrowLabelBox=yl;exports.getGroup=re;exports.getHoverGuideLineProps=TI;exports.getHoverGuideRectProps=LI;exports.getInsetTileRect=ul;exports.getLineType=al;exports.getMainAxisCoordinate=Z;exports.getNumericWeight=Ma;exports.getPolarHoverGuideArcProps=EI;exports.getRadiusExtent=ta;exports.getRuleDashPattern=rA;exports.getScaledAesthetic=ap;exports.getShapeAnnotationStroke=bT;exports.getSize=Zn;exports.getStablePolarBarKeyGenerator=iA;exports.getStackRole=os;exports.getStrokeWidth=en;exports.getTileRectBounds=cl;exports.getUnionExtent=tA;exports.getX=M;exports.getXMax=X;exports.getXMin=j;exports.getY=D;exports.getYMax=F;exports.getYMin=G;exports.getYRaw=hn;exports.hasMultipleGroups=pr;exports.highlight=OT;exports.inferDefaultDifferenceArrowEndpoints=gx;exports.inferDifferenceArrowEndpoints=wl;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=eL;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=mp;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=Ot;exports.isCompanionLayer=wn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=vo;exports.isGeomStyleRule=ba;exports.isKeyedScope=aa;exports.isLayerOf=Gs;exports.isLayerOfType=ae;exports.isLineStyleType=gn;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=DT;exports.isPointWithinEditMenuTrigger=ux;exports.isPointWithinRegionShape=ia;exports.isSafeUrl=QI;exports.isStackedPosition=U;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=$T;exports.normalizeAngle=Oe;exports.orderPointerRegions=nx;exports.paintsInDonutHole=br;exports.pickReadableTextColor=go;exports.pipe=Hs;exports.placeCallouts=HS;exports.polarToUnit=ge;exports.positionToAngle=bo;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=Kx;exports.prepareLineObservations=Zx;exports.projectAnchorToPanel=tr;exports.projectRegionToPanel=mS;exports.quantiseKey=te;exports.readAnchoredObservation=vx;exports.readAttachedObservation=ga;exports.readAuthoredNumber=dT;exports.readAuthoredString=pT;exports.readBroadestObservationsScope=QS;exports.readChartType=SL;exports.readColorGroupObservation=oA;exports.readComboLineLayerId=IL;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Ru;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=rR;exports.readMappedVariable=Hc;exports.readObservationIndex=wI;exports.readXExtent=Jl;exports.readYExtent=Ql;exports.resolveAnchorVariable=Ne;exports.resolveArrowAnnotationStyle=hT;exports.resolveArrowColor=zS;exports.resolveAxisLabelStyle=Rb;exports.resolveBarBandFraction=jr;exports.resolveBarBorderRadiusPx=la;exports.resolveBarBorderTreatment=Yx;exports.resolveBarCornerRadiiPx=zx;exports.resolveCalloutAnnotationStyle=vT;exports.resolveCaptionStyle=Eb;exports.resolveChromeMargin=q;exports.resolveChromeMargins=RT;exports.resolveColorRamp=Pn;exports.resolveComparisonBasis=Qo;exports.resolveDataLabelStyle=Vb;exports.resolveDeferredAnchors=yS;exports.resolveDefinition=_n;exports.resolveDifferenceArrowAnnotationStyle=fT;exports.resolveDirectLabelStyle=Ob;exports.resolveGeomAnchorFrame=Sn;exports.resolveGraphChromeStyle=TT;exports.resolveGraphPadding=LT;exports.resolveGridLineStyle=xT;exports.resolveHeadingFontFamily=IT;exports.resolveHeadingStyle=Tb;exports.resolveHeadlineFigure=kb;exports.resolveHeadlineItemStyle=Mb;exports.resolveHeadlinePlacement=tS;exports.resolveHeadlineStyle=wT;exports.resolveHoverGuideStyle=CT;exports.resolveImageAnnotationStyle=yT;exports.resolveLegendItemStyle=Pb;exports.resolveLegendStyle=ET;exports.resolveObservationPoint=bx;exports.resolveObservationsTarget=Ll;exports.resolvePanelBorderStyle=ST;exports.resolvePolarBarCornerRadiusUnit=eA;exports.resolveRuleLabelStyle=Db;exports.resolveSegmentYSource=cr;exports.resolveShapeAnnotationStyle=mT;exports.resolveSourceStyle=wb;exports.resolveSubtitleStyle=Lb;exports.resolveSwatchGeomPaint=ca;exports.resolveTextAnnotationStyle=gT;exports.resolveTextStyle=N;exports.resolveTickLabelStyle=Cb;exports.resolveTickLineStyle=AT;exports.resolveTooltipStyle=_b;exports.resolveYScaleAesthetic=Te;exports.sampleColorScheme=jf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Sx;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=Ib;exports.toPanelCursor=xl;exports.toPercent=De;exports.toViewBoxX=pS;exports.toViewBoxY=ce;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=Ks;exports.uniqueId=W;exports.unitToPolar=sr;exports.updateSpec=P;