@graphysdk/viz-engine 1.9.0-beta.1789110926690 → 1.9.0-beta.1789367356750

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var md=Object.create,zi=Object.defineProperty,hd=Object.getOwnPropertyDescriptor,fd=Object.getOwnPropertyNames,gd=Object.getPrototypeOf,yd=Object.prototype.hasOwnProperty,vd=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=fd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!yd.call(e,s)&&s!==r&&zi(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=hd(t,s))||n.enumerable});return e},Zt=(e,t,r)=>(r=e!=null?md(gd(e)):{},vd(t||!e||!e.__esModule?zi(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-BC4IbM6k.cjs");let ue=require("color2k"),Yi=require("date-fns"),Je=require("lodash-es"),tt=require("d3-time"),bd=require("date-fns/differenceInDays"),xe=require("d3-regression"),re=require("d3-scale"),Ue=require("d3-interpolate"),k=require("d3-scale-chromatic"),Ke=require("lodash-es/clamp");Ke=Zt(Ke,1);let $t=require("lodash-es/merge");$t=Zt($t,1);let Pr=require("humanize-duration");Pr=Zt(Pr,1);let Ee=require("d3-shape"),Sd=require("d3-delaunay"),Gt=require("lodash-es/isEqual");Gt=Zt(Gt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789110926690");var xd=1e6;function Z(e){return String(Math.round(e*xd))}var wa="#FFFFFF",br="#1A1A1A",Ad=4.5,qi=e=>{try{return(0,ue.getContrast)(e,wa)>(0,ue.getContrast)(e,br)?wa:br}catch{return br}},Id=(e,t)=>{try{const r=ji(void 0,t);return r===void 0||(0,ue.getContrast)(r,e)>=Ad?e:qi(r)}catch{return e}},ji=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ue.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ue.parseToRgba)(e);return r>=1?e:(0,ue.parseToRgba)(t)[3]<1?void 0:(0,ue.mix)(t,(0,ue.opacify)(e,1),r)}catch{return}},Ra=0;function F(){return Ra+=1,`${Math.random().toString(36).slice(2,6)}${Ra.toString(36)}`}var pe=Math.PI*2,Td=8,Ld=1e-9,Ed=[0,Math.PI/2,Math.PI,pe*3/4],Xi=(e,t)=>Math.abs(t-e)>=pe-Ld,ze=e=>(e%pe+pe)%pe,tn=(e,t,r)=>{if(Xi(t,r))return!0;const n=ze(r-t);return ze(e-t)<=n},Ut=(e,t)=>{const r=Math.abs(ze(e)-ze(t));return Math.min(r,pe-r)},Zi=(e,t,r)=>e*pe+t+r,at=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Ae=(e,t)=>{const r=at(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},wd=(e,t,r,n)=>{const a=[Ae(e,r),Ae(e,n),Ae(t,r),Ae(t,n)],i=Math.max(r,n),o=Ed.filter(c=>tn(c,e,t)).map(c=>Ae(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))}},Ji=(e,t)=>({angle:ze(Math.atan2(e,t)),radius:Math.hypot(e,t)}),rn=(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}},Jt=(e,t)=>{const{x:r,y:n}=rn(e,t);return Ji(r,n)};function _(e){return e[l.POSITION_VARIABLES.x]}function R(e){return e[l.POSITION_VARIABLES.y]}function W(e){return e[l.POSITION_VARIABLES.xMin]}function K(e){return e[l.POSITION_VARIABLES.xMax]}function M(e){return e[l.POSITION_VARIABLES.yMin]}function O(e){return e[l.POSITION_VARIABLES.yMax]}function nn(e){return e[l.POSITION_VARIABLES.yRaw]}function Rd(e,t){return e[l.resolveScaledAestheticVariable(t)]}var Vd={xMin:0,xMax:1,yMin:0,yMax:1},Qi=(e,t)=>{const r=W(e)??_(e),n=K(e)??_(e),a=M(e)??R(e),i=O(e)??R(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}:{...wd(r,n,a,i),frame:"disk"}},lt=(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}}},eo=e=>lt(Vd,e),to=["stack","dodge","identity","fill"],an=["solid","dashed","dotted"],on=e=>an.includes(e);function N(e){return e==="stack"||e==="fill"}var Y=(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},Qe=(e,t)=>Y(e,t.x),sn=(e,t)=>Y(e,t.y),Cd=(e,t)=>Y(e,t.label),ro=(e,t)=>Y(e,t.color),_d=(e,t)=>Y(e,t.size),Dd=(e,t)=>Y(e,t.alpha),Pd=(e,t)=>Y(e,t.group),Od=(e,t)=>Y(e,t.strokeWidth),Va={variable:l.POSITION_VARIABLES.yRaw};function Qt(e,t){return N(e)?Va:t.y??Va}function ct(e){return Y(e.data,Qt(e.position,e.mapping))}var Ve=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},ln=e=>kd(e)?l.extractVariableName(e.mapping.y):null,no=e=>ln(e)===null?null:ct(e),cn=e=>e.spatialKind!=="cells",kd=e=>e.spatialKind==="points"||e.spatialKind==="cells",ao=(e,t)=>e.yScaleType===t.yScaleType&&kr(e.valueFormat)===kr(t.valueFormat),Or=e=>`${e.yScaleType} y axis, ${kr(e.valueFormat)}`,kr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,io=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(Ve(e))),n=ln(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 oo(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 C(e,t){return lo(e,t)}function w(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 so(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Ce(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 lo(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=lo(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 er(e){return{pipe:t=>{const r=t(e);return er({...e,...r})},result:()=>e}}var Md=(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},un=e=>e.type==="polar"?"disk":"panel",tr=(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}},Ca=(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=tr(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 Ye(e,t){return e==="x"?t.x:t.y}function rr(e,t){return e==="x"?t.y:t.x}function Nd(e,t){return{main:Ye(e,t),cross:rr(e,t)}}function _a(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function Bd(e){return e.type==="cartesian"}var J=e=>e[l.GROUP_VARIABLES.group],ut=e=>{const t=Ve(e),r=no(e),n=cn(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?J(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},qe=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,Fd={type:"decimal"};function co(e){return e.length>0&&e.every(t=>t.data.size()===0)}function dn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):Fd}function $d(e){return dn(e,l.extractVariableName(e.mapping.y))}function uo({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??Qt(t,r)}function po(e,t){const r=uo({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:Y(e.data,r),valueFormat:dn(e,a)}}var mo=e=>{const t=Ve(e),r=no(e),n=cn(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(J(a),i.groupValue)},ho=e=>{const t=l.extractVariableName(e.mapping.y),r=ct(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},Gd=["lt","lte","gt","gte","range"],Ud={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"}},se=()=>!1,Me=()=>!0;function dt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:ho(e),parsingLocale:t}}function me(e,t){if("and"in e){const r=e.and.map(n=>me(n,t)).filter(n=>n!==Me);return r.includes(se)?se:r.length===0?Me:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>me(n,t)).filter(n=>n!==se);return r.includes(Me)?Me:r.length===0?se:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=me(e.not,t);return r===se?Me:r===Me?se:n=>!r(n)}return Wd(e,t)}function he(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>he(n,t,r)):"or"in e?e.or.flatMap(n=>he(n,t,r)):"not"in e?he(e.not,t,r):Hd(e,t,r)}function Hd(e,t,r){const{subject:n,effect:a}=Ud[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=Kd(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 Wd(e,t){if(!t.hasVariable(e.variable))return se;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=>Ne(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=Ne(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Ne(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=Ne(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=Ne(u,o),p=Ne(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return se}function Kd(e){for(const t of Gd)if(t in e)return t;return null}function Ne(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 zd=(e,t,r,n,a,i)=>{const o=go(e,t,r.predicate,n,a,i);if(o===null)return null;const s=fo(r.padding),c=s===null?jd(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}},Yd=(e,t,r,n,a,i)=>{const o=go(e,t,r.predicate,n,a,i);return o===null?null:{...lt(o,r.align),frame:o.frame}},fo=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},go=(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=he(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=me(r,dt(u,i));if(p!==se)for(const h of u.data){if(!p(h))continue;const m=Qi(h,a);m!==null&&(o=o===null?m:qd(o,m))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},qd=(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)}),jd=(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}},Ht=(e,t,r)=>{const n=Zd(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Jd(n,t.offset,e.coordSystem)},yo=(e,t)=>t.anchorType==="selection"?zd(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},pn=(e,t,r)=>Mr(e,t,r)?.point??null,Mr=({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=po(o,s),d=mo(o),p=ut(o),h=io(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=vo(o,f,u);if(v===null)continue;const y=p(f);if(y!==null)return{point:{...g,...v,frame:un(r),observationIndex:m,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:o.id}}}return null},Xd=(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=Pa(t.x,"x",r,i),u=Pa(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!qe(d,p))return null;const h=Da(d,o,Qd(e)),m=Da(p,s),f=_a(n.mainAxis,{main:h.min,cross:m.min}),g=_a(n.mainAxis,{main:h.max,cross:m.max});return lt({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},vo=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:Md(r.valueFormat,t),yScaleType:e.yScaleType}:null},Zd=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Xd(e,t);case"selection":return Yd(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 pn(e,ep(t),r)}},Jd=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=fo(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Da=(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}},Qd=({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},ep=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Pa=(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},tp=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:pp(o,t.differenceArrows),shapes:ip(o,t.shapes),arrows:sp(o,t.arrows),textAnnotations:lp(o,t.textAnnotations),images:op(o,t.images),stickers:cp(o,t.stickers),pinnedNumbers:up(o,t.pinnedNumbers),comments:dp(o,t.comments)};return rp(this.container,s),np(this.container,s),s}},ne=(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."})},rp=(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)}},np=(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 ap(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."})},ap=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},ip=(e,t)=>{const r=[];for(const n of t){const a=yo(e,n.region);if(a===null){ne(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},op=(e,t)=>{const r=[];for(const n of t){const a=yo(e,n.region);if(a===null){ne(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},sp=(e,t)=>{const r=[];for(const n of t){const a=Ht(e,n.start,"pin"),i=Ht(e,n.end,"pin");if(a===null||i===null){ne(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},lp=(e,t)=>{const r=[];for(const n of t){const a=Ht(e,n.at,"pin");if(a===null){ne(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},cp=(e,t)=>{const r=[];for(const n of t){const a=Ht(e,n.at,"pin");if(a===null){ne(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},up=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ne(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},dp=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ne(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},pp=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ne(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Mr(e,n.start,"value"),i=Mr(e,n.end,"value");if(a===null||i===null){ne(e.container,"differenceArrow",n.id,`has ${bo(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ne(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}mp(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",mp=(e,t,r,n)=>{ao(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:Or(r),actual:Or(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:So(i),values:i};return new l.Dataset(n)}function So(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 fp=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,So(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},_e=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)}},gp=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)}},yp=class extends _e{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}},vp=class{constructor(e){this.setupStage=new gp(e),this.transformStage=new yp(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)}},bp=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}},Sp=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:Ap(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Tp(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]],Oa=l.prefixInternalVariable("flipSwap"),Ap=(e,t)=>Ip(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Ip=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},Tp=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,Oa).renameVariable(n,r).renameVariable(Oa,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function xo(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 Ao=(e,t)=>xo(t.domain!==null&&t.domain.length>0?t.domain:e),Lp=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=Rp(t,e.scales,e.layers),a=Cp(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=wp(r,n),i=_p(t);return e.layers.map(o=>Dp(t.theta==="y"?Pp(o):o,a,i))}},Ep=[[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 wp(e,t){return r=>Zi(r,e,t)}function Rp(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Vp(n,e,r);return a===0?0:-Math.PI/a}function Vp(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 Ao(n,e).length}function Cp(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 _p(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Dp(e,t,r){let n=e.data;return n=Be(n,l.POSITION_VARIABLES.x,t),n=Be(n,l.POSITION_VARIABLES.xMin,t),n=Be(n,l.POSITION_VARIABLES.xMax,t),n=Be(n,l.POSITION_VARIABLES.y,r),n=Be(n,l.POSITION_VARIABLES.yMin,r),n=Be(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Be(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 Pp(e){let t=e.data;for(const[r,n]of Ep){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 Op=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new bp),this.register("flip",new Sp),this.register("polar",new Lp)}},Io=new Set(["min","max","scalar"]),kp={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function Mp(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 Np(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 Bp(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=kp[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 Fp=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:Bp(n.data,r.positionRoles,a)}}},mn=["x","y"],hn=new Set(["x","y","ySecondary"]),pt=new Set(["color","size","alpha","strokeWidth","lineType"]),De=e=>hn.has(e),fn=e=>pt.has(e),To=e=>De(e)||fn(e);function fe(e){return e==="secondary"?"ySecondary":"y"}function Lo(e,t){return e==="y"?fe(t):"x"}function B(e){return e==="ySecondary"?"y":e}var Pe=(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 pt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},nr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Pe(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),$p=class{compute({data:e,mapping:t}){const r=Pe(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)}}},Gp=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},Up=(e,t,r)=>{const n=we(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function we(e,t){const r=B(t);for(const n of Eo(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var ar=(e,t)=>e===null?null:t[e]??e,Hp=(e,t)=>e===null?null:t[String(e)]??null,Re=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Sr(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 Kp(i,t)?i:Sr(t)}return Sr(t)},Wp=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Eo(t,e).some(r=>r.position==="fill");function Eo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Sr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Kp=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},zp=[{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}],ka={year:0,quarter:1,month:2,week:3,day:4,hour:5},Fe=40,Yp=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Zp(r.unit).range(e,new Date(t.valueOf()+1),n)},qp=({unit:e,step:t,start:r,stop:n})=>{const a=(0,bd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Fe;case"day":return a/t>Fe;case"week":return a/(7*t)>Fe;case"month":return a/(30*t)>Fe;case"quarter":return a/(90*t)>Fe;case"year":return a/(365*t)>Fe}},jp=(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"}}},Xp=(e,t)=>{const r=Jp(t);return r===null?!1:ka[e]>ka[r]},Zp=e=>{switch(e){case"hour":return tt.utcHour;case"day":return tt.utcDay;case"week":return tt.utcMonday;case"month":case"quarter":return tt.utcMonth;case"year":return tt.utcYear}},Jp=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}},wo={left:"right",right:"left",top:"bottom",bottom:"top"},Qp={x:!0,y:!0,ySecondary:!1},em=20,Ma=new Set(["top","bottom"]),tm={type:"percentage"};function rm(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=im(s,a,i.type,n),u=new Set(t.map(h=>h.position)),d=sm(Ro(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const h of hn){const m=r[h];if(!l.isDefined(m)||m.kind!=="position")continue;const f=nm({scaleAestheticKey:h,scale:m,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function nm(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}=om(t,n,i,o),h=we(a,t),m=Wp(a,t)?tm:Re({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:p,label:am(u,h,c),isVisible:u.isVisible,tickCandidates:cm(r,m,u.ticks.mode),valueFormat:m,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:lm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function am(e,t,r){return e.label?e.label:t?r[t]??null:null}function im(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:Na(i,n.axes.x.grid.isVisible)},y:{gridVisible:Na(o,n.axes.y.grid.isVisible)}}}function Na(e,t){if(e&&t===null)return!1}function om(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Ro(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=wo[n],i=(0,Je.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 Ro(e,t){return Ma.has(e)===Ma.has(t)?e:t}function sm(e,t){return t.has(e)?wo[e]:e}function lm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Qp[r]}var cm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=dm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=em;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>je(e,u))}))}return i}return e.spec.scaleType==="datetime"?um(e,t):[{ticks:e.generateTicks().map(a=>je(e,a))}]},um=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>je(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=>je(e,d)),valueFormat:c}))};for(const s of zp)qp({...s,start:r,stop:n})||Xp(s.unit,t)||o(e.generateTicks({interval:s}),jp(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},dm=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:[je(e,r),je(e,n)]}},je=(e,t)=>({value:t,position:e.map(t)});function Vo({scale:e,aesthetics:t,layers:r}){const n=pm({layers:r,aesthetics:t}),a=Co({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function pm({layers:e,aesthetics:t}){const r=Co({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 Co({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 gn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function mm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!gn(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=we(t,"color");if(_o({colorVariableName:a,xVariableName:we(t,"x"),mapsColorAcrossMultipleLayers:fm(t)>1,isMergedWithAnotherAesthetic:hm(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return Vo({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:Re({layers:p?[p]:t,scaleType:i,variableName:h}),label:Hp(s,r)}})}var _o=({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 pt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!gn(a))&&we(t,n)===r)return!0}return!1}var fm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Do(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function gm(e,t,r,n){const a=r.findIndex(i=>Do(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:ar(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 Ba(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 Po=e=>e==="none"?"first":e,ym=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Fa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Fa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},vm=(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}},Fa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function bm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Sm(e,n):xm(e,n)}function Sm(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:Re({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=>Do(s,d)))return null;const c=gm(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Am({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 Am({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=Re({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=Lm(i.data,s),h=Re({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),m=Em(i.data,s),f=m.getValues(o,{type:"numeric"}),g=s!==null?m.getValues(s):[],v=c!==null?m.getValues(c):null,y=Ba(f,v,e.value),b=Ba(g,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:ym(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,caption:Im(t,p,b),comparison:Tm(t,r,p,b,y)}}function Im(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 Tm(e,t,r,n,a){return e!=="current"||!r?null:vm(n.map((i,o)=>({main:i,cross:a[o]??null})),Po(t))}function Lm(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Em(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function Q(e,...t){return e?t.includes(e.geom):!1}function P(e,t){return e.find(r=>r.id===t)}function ge(e,...t){return e.find(r=>t.includes(r.geom))}function wm(e,...t){return e.filter(r=>t.includes(r.geom))}function yn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function vn(e){const t=e.filter(r=>!yn(r,e));return t.length>0?t:e}function Oo({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=vn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Rm=3;function Vm({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=Nm(Pm({scales:e,layers:r})),u=we(r,"x"),d=c.map(v=>{if(km(v,u,r))return null;const y=Fm({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return y.items.length===0?null:{group:v,built:y}}).filter(l.isDefined),p=Cm(d),h=vn(r),m=Km(o,t.legend.position,p,h,n);if(d.length===0)return{drawn:[],position:m};if(t.legend.position==="auto"&&Wm(o,p,h,n))return{drawn:[],position:m};const f=zm(t.legend.display,{legendPosition:m,coordSystem:n,layers:r}),g=f==="direct"?Xm(h[0]):null;return{drawn:d.map(({built:v})=>_m(v,{position:m,display:f,align:t.legend.align},g)),position:m}}function Cm(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function _m(e,t,r){const{position:n,display:a}=t,i=Dm(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 Dm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function Pm(e){const{scales:t,layers:r}=e,n=[];for(const a of pt){const i=t[a];if(i===void 0||i.kind==="identity"||!Om(a,r))continue;const o=we(r,a),s=jm(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function Om(e,t){const r=B(e);return t.some(n=>l.isDefined(n.mapping[r]))}function km(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:_o({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:Mm(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function Mm(e,t){const r=B(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function Nm(e){const t=new Map;for(const r of e){const n=qm(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function Bm(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Fm({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>B(u.scaleAestheticKey)),o=Vo({scale:a.scale,aesthetics:i,layers:r}),s=Re({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:ar(a.variableName,t),items:o.map(u=>$m(u,e,i,s,n,c))}}function $m(e,t,r,n,a,i){const o={};for(const c of t)Bm(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);on(c)&&(o.lineType=c)}const s=Um(e,t,r,n,a);return{value:e.value,label:Gm(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function Gm(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function Um(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=Hm(i,r);return i===void 0||o===null?n:Re({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function Hm(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 Wm(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 Km(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,N(u.position)&&(s=!0))}const c=r>=Rm;return i&&o?"top":i?c?"right":"top":s?Ym(a)?"top":c?"right":"top":"top"}function zm(e,t){return e==="pill"?"pill":Oo(t)?"direct":"pill"}function Ym(e){return e.type==="cartesian"&&e.mainAxis==="y"}function qm(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function jm(e,t){return gn(t)?"discrete":`continuous:${e}`}function Xm(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(O(c))||l.isDefined(R(c)));if(!n)return;const a=J(n);if(!l.isDefined(a))return;const i=M(n),o=O(n)??R(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var Zm=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=Gp(e.originalData),r=mm({scales:e.scales,layers:e.layers,valueLabels:Up(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=bm(n),i=Vm(n),o={...i,drawn:Jm(a,i.drawn)};return{axes:rm(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},Jm=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],it=(e,t,r)=>{switch(e){case"series":return Qm(t);case"x-value":return bn(t,r)}},Qm=e=>l.getStableKey([J(e)]),bn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),eh={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function ko(e){const t=eh[e]??null;return t===null?null:{strategy:t,composition:Mo()}}function Mo(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var th=class extends _e{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=rh({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function rh({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(L=>{const G=he(L.predicate,e.data);for(const j of G)a.diagnostics.addWarning({...j,message:`${j.message} Dropping this highlight.`});return G.length===0}),o=l.extractVariableName(e.mapping.x),s=dt(e,r),c=i.map(L=>({predicate:me(L.predicate,s),scope:L.scope})),u=c.some(({scope:L})=>L==="series"),d=c.some(({scope:L})=>L==="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,I=0;for(const L of e.data){let G,j;m!==null&&(G=it("series",L,o),m[I]=G),f!==null&&(j=it("x-value",L,o),f[I]=j),g!==null&&(g[I]=L);for(const{predicate:Se,scope:Rt}of c)if(Se(L))switch(Rt){case"series":G!==void 0&&y.add(G);break;case"x-value":j!==void 0&&b.add(j);break;case"data-point":v[I]=1,A=!0;break}I++}if(y.size===0&&b.size===0&&!A)return Mo();const T=new Uint8Array(h),E=[];let ee=0;for(let L=0;L<h;L++){const G=m?.[L],j=f?.[L],Se=G!==void 0&&y.has(G),Rt=j!==void 0&&b.has(j),La=v[L]===1;if(n==="observation-rerender")(Se||La||Rt)&&(T[L]=1,ee++);else if(Se)T[L]=1,ee++;else if(La||Rt){const Ea=g?.[L];Ea!==void 0&&E.push({observation:Ea,observationIndex:L})}}const be=ee>0?{...e,data:e.data.filterByMask(T)}:null;return{isDimmed:(n==="observation-rerender"||y.size>0)&&be!==null,matchedLayer:be,overlayCandidates:E}}var nh=l.prefixInternalVariable("__ungrouped__");function ah(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]??nh;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 ih=()=>({defaults:[],overrides:[],warnings:[]}),oh=class extends _e{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,$a(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:$a(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=er({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:ah(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:ko(e.geom),styles:ih()}}};function $a(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function No(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function sh(e,t){return t.some(r=>N(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function Nr(e,t){const r=Bo(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:ch(r),zeroAxes:n,bandPadding:uh(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function lh(e,t){const r=Bo(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:Ga(n),zeroAnchored:Ga(a)}}return null}var Ga=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function Bo(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:fe(n.yScaleType)})}),r}function ch(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of Fo(r))t.add(n);return[...t]}function uh(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Fo(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Fo({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var dh=new Set(["label","group"]),ph=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)),No(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(!nr(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=[...Mp(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(!Io.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=lh(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([...Np(i),...o.map(h=>h.name)]),u=dh,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}},le=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=to,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,Je.merge)({},this.defaultParams,e.params)}},Sn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},xn=(e,{coordSystem:t})=>{const r=_(e),n=R(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?Ae(r,n):{x:r,y:n}},mh=class extends le{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="buckets",this.resolveAnchorPosition=xn}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=Sn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},hh=.7,fh=.1,gh=.03,yh=.05,$o=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},vh=class extends le{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=>N(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>Br(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=Qi(t,r);return p===null?null:lt(p,i)}if(r.type==="polar")return bh(t);const o=N(n),s={isSolo:!o||$o(t)==="solo",isNegative:o&&Sh(t),purpose:a};if(r.mainAxis==="x"){const p=W(t),h=K(t),m=Ua({lowerBound:M(t),upperBound:O(t)??R(t),options:s});return p===null||h===null||m===null?null:{x:(p+h)/2,y:m}}const c=M(t),u=O(t),d=Ua({lowerBound:W(t),upperBound:K(t)??_(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=Br(r,n);e=Sn(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}},Br=({width:e},t)=>e!==void 0?e:t==="polar"?1:hh,bh=e=>{const t=W(e),r=K(e),n=M(e),a=O(e);return t===null||r===null||n===null||a===null?null:Ae((t+r)/2,(n+a)/2)},Sh=e=>{const t=nn(e);return l.isStrictNumericDataValue(t)&&t<0},Ua=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 le{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=xn}compile(e){return{data:Sn(e.data,e.mapping),mapping:{}}}},Ah=class extends le{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=xn,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:{}}}},Ih=class extends le{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=Ha(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=Ha(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}}}},Ha=(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},Th=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},Lh=class extends le{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=Th,this.resolveAnchorPosition=t=>{const r=W(t),n=K(t),a=M(t),i=O(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:{}}}},Eh=[new vh,new Ah,new xh,new mh,new Ih,new Lh],ir=class extends l.Registry{constructor(){super("geom");for(const e of Eh)this.register(e.type,e)}},Oe=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},wh=class extends Oe{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,...Pe(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},Rh=class extends Oe{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Vh=class extends Oe{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}}}},Ch=2,Go=1440*60*1e3,_h=class extends Oe{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=Pe(e,t),u=Bh(a,o,i,c,e);return c.length===0?Wa({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=Fh(d,c);Wa({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Wa=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=Dh({data:e,xVariable:t,yVariable:n,xType:r});c.length<Ch||(s?Nh({observations:c,spec:a,output:i,groupObservation:o}):kh({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},Dh=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?Ph(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=Oh({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});h!==null&&s.push({x:h,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},Ph=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},Oh=({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)/Go+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}`})}},kh=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=Uo(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?Mh(s,r):s;a.push({x:u,y:c,groupObservation:i})}},Mh=(e,t)=>t===null?new Date(e):new Date((e-1)*Go+t),Nh=({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=Uo(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=Ho(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})}},Uo=(e,t)=>e.method==="loess"?(0,xe.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):Ho(e,t),Ho=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,xe.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,xe.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,xe.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,xe.regressionQuad)().x(r).y(n)(t);case"power":return(0,xe.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,xe.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},Bh=(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)}}},Fh=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},$h=class extends Oe{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],...Pe(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},Gh=[new Rh,new wh,new _h,new Vh,new $h],Uh=class extends l.Registry{constructor(){super("stat");for(const e of Gh)this.register(e.type,e)}};function Hh({geoms:e,stats:t,transforms:r}){const n=new ir,a=new Uh,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 An(e){if("definition"in e)return e.definition;if(Ko(e)||zo(e)||Yo(e))return e}function Wo(e){const t=[],r=[],n=[];for(const a of e){const i=An(a);i&&(Ko(i)?t.push(i):zo(i)?r.push(i):Yo(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...xr("geom",t,a=>a.type),...xr("stat",r,a=>a.type),...xr("transform",n,a=>a.transformType),...Wh(t),...Kh(t)]}}function Wh(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 Kh(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 xr(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 Ko=e=>e instanceof le,zo=e=>e instanceof Oe,Yo=e=>"transformType"in e&&typeof e.apply=="function",zh=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},or=class{},Yh=class extends or{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=qh(e)??[-.7/2,.7/2],o=r.length>1?fh:0,s=(0,re.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:{}}}},qh=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]},Ka=l.prefixInternalVariable("__ungrouped__"),qo=(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?[Ka]: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?Ka: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}},jo=(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]=jh(m===s,m===d)}return a},jh=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Xh=class extends or{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=qo(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 I=b/A;b>=0?(c[y]=m,s[y]=m+=I):(s[y]=f,c[y]=f+=I)}}}const u=jo(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:{}}}},Zh=class extends or{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Jh=class extends or{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=qo(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=jo(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:{}}}},Qh=class extends l.Registry{constructor(){super("position"),this.register("identity",new Zh),this.register("stack",new Jh),this.register("fill",new Xh),this.register("dodge",new Yh)}},ef=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)||fn(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Lo(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}},tf=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)}},rf=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)?nf(e,r,n):af(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function nf(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=Xo(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 af(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=Xo(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 Xo(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var of=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(fe(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)}},sf=class{map({data:e,layer:t,getPositionScale:r}){const n=r(fe(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)?lf(e,n,a):cf(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function lf(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=Zo(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 cf(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=Zo(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 Zo(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var uf=[new tf,new of,new rf,new sf,new ef];function df(e,t){const r=e[t];return r?.kind==="position"?r:null}var pf=class extends _e{constructor(e,t=uf){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=>df(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}}},mf=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:sh(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=B(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})}}No(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"?fe(n.yScaleType):i,c=a.get(i)??(To(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)||fn(n.aes)||t.set(n.aes,Lo(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"],ff=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],Jo=["RdBu","BrBG","PuOr","Spectral"],Qo={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},gf=new Set(Jo.map(e=>e.toLowerCase()));function es(e){const t=e.toLowerCase(),r=Qo[t];return r?r.toLowerCase():t}function yf(e){return gf.has(es(e))}var vf={rgb:Ue.interpolateRgb,lab:Ue.interpolateLab,hcl:Ue.interpolateHcl,hsl:Ue.interpolateHsl},bf={viridis:k.interpolateViridis,magma:k.interpolateMagma,inferno:k.interpolateInferno,plasma:k.interpolatePlasma,cividis:k.interpolateCividis,turbo:k.interpolateTurbo,blues:k.interpolateBlues,greens:k.interpolateGreens,greys:k.interpolateGreys,oranges:k.interpolateOranges,purples:k.interpolatePurples,reds:k.interpolateReds,rdbu:k.interpolateRdBu,brbg:k.interpolateBrBG,puor:k.interpolatePuOr,spectral:k.interpolateSpectral};function In(e){const t=xf(e);return e.reverse?r=>t(1-r):t}function Sf(e={},t=2){const r=In({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=vf[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ue.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=bf[es(e.scheme)];if(r)return r}return(0,Ue.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var mt=class{createPositionScale(e,t){return{kind:"position",aesthetic:B(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:B(e.scaledAesthetic),spec:e,...t}}},Af=class extends mt{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=De(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"&&If(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:B(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,re.scaleLog)():r.transform==="sqrt"?(0,re.scaleSqrt)():(0,re.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=Tf(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=In(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,re.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,re.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]}},If=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Tf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Lf=class extends mt{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=De(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=Ef(e)?e:[],a=(0,re.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?Yp(i,o,c.interval):[]:a.ticks(c?.count)})}},Ef=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),wf=class extends mt{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=De(e.scaledAesthetic),n=Ao(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,re.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,re.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})}},Rf=class extends mt{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:B(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Vf=class extends mt{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=xo(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,re.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},Cf=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Af(e)),this.register("discrete",new wf),this.register("datetime",new Lf),this.register("identity",new Rf),this.register("palette",new Vf)}},ts={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},_f={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 Tn(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Nr(e.geomRegistry,n)}}function sr(e,t){switch(t.scaleType){case"inferred":return{...sr(e,kf(e,t)),inferredFrom:t};case"continuous":{const r=ts[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:Mf(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 Fr(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 Df(e,t){const{scales:r,layers:n,coords:a}=t,i=Tn(e,t),o=Ff(Bf(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=Pf(i,u);return sr(i,d)});return a.coordType==="polar"?c.map(Ln):c}function Fr(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??Of(e.scaledAesthetic,t)}}var Ln=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Pf(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:B(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 Of(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function kf({data:e,layers:t,mapping:r,demands:n},a){const i=B(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?Nf(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=ts[a.scaledAesthetic];switch(_f[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 Mf(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:B(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&yf(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:B(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Nf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function Bf(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Ff(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var $f={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}},Gf=(e,t,r)=>{const n=Uf(e,t),a=Kf(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Yf(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Zf(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>eg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>zf(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>qf(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Jf(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>jf(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Xf(e,i,r)).filter(l.isDefined)}},Uf=(e,t)=>{if(t===void 0)return{};if(!Hf(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:F()}):(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))}},Hf=e=>{const t=new Set;for(const r of Wf(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},Wf=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Kf=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},En=(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},zf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??F(),content:t.content,at:a,width:t.width,align:t.align??l.TEXT_ANNOTATION_DEFAULTS.align}},Yf=(e,t,r)=>{const n=ot(e,t.start,r),a=ot(e,t.end,r);return n===null||a===null?null:{id:t.id??F(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},ot=(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)},Wt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return En(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=ot(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},qf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??F(),at:a,sticker:t.sticker}},jf=(e,t,r)=>{const n=ot(e,t.at,r);return n===null?null:{id:t.id??F(),at:n}},Xf=(e,t,r)=>{const n=ot(e,t.at,r);return n===null?null:{id:t.id??F(),at:n,content:t.content}},Zf=(e,t,r)=>t.region.anchorType==="annotation"&&!En(e,t.region.ref,r,t.id)?null:{id:t.id??F(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Qf(t.region)},Jf=(e,t,r)=>t.region.anchorType==="annotation"&&!En(e,t.region.ref,r,t.id)?null:{id:t.id??F(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Qf=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},za=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=$f[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},eg=(e,t,r,n)=>{const a=Wt(e,t.start,r,n,t.id),i=Wt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??F(),start:za(a),end:za(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},tg={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},layout:{gaps:{}}};function rg(e){const t=(0,Je.merge)({},tg,e);return t.content=ng(t.content,e?.content),t}var ng=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},ag={xLimits:null,yLimits:null},Mt={theta:"x",startAngle:0,innerRadius:0};function $r(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,$t.default)({},ag,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Mt.theta,startAngle:t.params?.startAngle??Mt.startAngle,innerRadius:(0,Ke.default)(t.params?.innerRadius??Mt.innerRadius,0,1)}}}}function ig(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??F(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var og=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=Ya(e.filter(n=>n.severity==="error")),r=Ya(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},sg=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 Ya(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var lg={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 rs(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 ke(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new sg(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=dg({dataLabels:mg(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return ug({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??F(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:rs(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 cg(e,t,r,n,a){const i=n.map((o,s)=>ke(e,t,r,o,a,s));return as(e,i)}var ns=(e,t,r,n)=>n.label!==void 0?n.label:uo({geom:e.get(t),position:r,mapping:n,purpose:"label"}),as=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Ce(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,Je.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},ug=({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&&N(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'."})},dg=({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=pg(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}},pg=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&N(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,mg=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=ns(e,r.geom,n,i),s=e.get(r.geom);return{...(0,Je.merge)({},lg,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},hg=e=>{const t=new Set;e!==void 0&&is(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},is=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])is(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function fg(e,t,r){const n=$r(t.coords),a=cg(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Df(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=rg(t.config),s=ig(e,t.highlights,a),c=Gf(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 os=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return fg(this.container,{...e,data:t},r)}},gg=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})}},ht={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},yg={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}}},ss=Object.keys(ht),vg=e=>Object.hasOwn(ht,e),ft=(e,t)=>{for(const r of ss){const n=bg(e,r,t);if(n)return n}return null},gt=(e,t)=>e[ht[t]],wn=(e,t,r)=>({...e,[ht[t]]:r}),ls=(e,t)=>{const r=gt(e,t.kind);return wn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},bg=(e,t,r)=>{const n=gt(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},Sg=class extends _e{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Gg(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of Hg(e.styles))this.container.diagnostics.addWarning(r);for(const r of Wg(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=gs({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Ie={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Kt={bar:{...Ie,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Ie,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Ie,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Ie,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...Ie,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},qa=1,ja=1e3,xg="'none' or a shadow object { offsetX, offsetY, blur, color }",Ag="a non-negative number of pixels, or an object of those per edge",Ig=["top","right","bottom","left"],Vt={color:"color",strokeWidth:"pixels",lineType:"lineType"},X={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Ct={...X,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},Xa={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},V={panelBorder:{...Vt,borderRadius:"pixels"},panelBorderEdge:Vt,gridLine:Vt,tickLine:{...Vt,length:"pixels"},axisLabel:X,tickLabel:{...X,offset:"pixels"},ruleLabel:X,dataLabel:Ct,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",textScale:"multiplier",padding:"padding"},heading:{fontFamily:"fontFamily"},hoverGuide:{color:"color",background:"color"},tooltip:Xa,tooltipText:X,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels"},legend:{gap:"pixels"},legendPopover:Xa,legendItem:{...X,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},legendItemSwatch:{size:"pixels",strokeWidth:"pixels"},directLabel:{...X,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:Ct,annotationText:{...Ct,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...Ct,shadow:"shadow"}},cs={number:X,numberCenter:X,caption:X,label:X,swatch:{size:"pixels"},trend:X,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},Tg=new Set([...Object.keys(Ie),...Object.values(Kt).flatMap(e=>Object.keys(e??{})),...Object.values(V).flatMap(e=>Object.keys(e)),...Object.values(cs).flatMap(e=>Object.keys(e))]),us=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],Lg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Eg=(e,t,r="en-US")=>gs({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),wg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Ug(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:[]},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(lr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!Vg(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 ${us.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&&!Ng(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=Bg(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 ${de(v)}.`,context:{param:"annotation",actual:de(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(p.target==="panelBorder"){const m=p.edge;if(m!==void 0&&!Cg(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(Lg.has(p.target)){const m=p.axis;if(m!==void 0&&!Fg(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 ${mn.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 ${de(m)}.`,context:{param:"layer",actual:de(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&&!Pg(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==="legend"){const m=p.part;if(m!==void 0&&!Og(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&&!kg(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(!Mg(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&&!_g(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(!Dg(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=Vn({declarations:i.declarations,vocabulary:ms(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},Rg=(e,t)=>{if(e==="geom"){const r=Object.keys(Kt).find(n=>Kt[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>ms({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},lr=e=>e.select.target==="geom",Vg=e=>{const t=e.select.target;return t!=="geom"&&us.includes(t)},ps=e=>(e!==void 0?Kt[e]:void 0)??Ie,ms=e=>{if(e.target==="panelBorder")return e.edge===void 0?V.panelBorder:V.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?V.tooltip:e.part==="primaryRow"?V.tooltipPrimaryRow:V.tooltipText;if(e.target==="legend")return e.part==="popover"?V.legendPopover:V.legend;if(e.target==="legendItem")return e.part===void 0?V.legendItem:V.legendItemSwatch;if(e.target==="headlineItem")return cs[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return V.annotationShape;case"arrow":return V.annotationArrow;case"differenceArrow":return e.part==="label"?V.annotationDifferenceArrowLabel:V.annotationDifferenceArrow;case"text":return V.annotationText;case"image":return V.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?V.annotationCalloutLabel:V.annotationCallout;default:return V.annotation}return V[e.target]},Cg=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),_g=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),Dg=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Pg=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),Og=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),kg=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),Mg=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),Ng=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),Bg=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],Fg=e=>typeof e=="string"&&mn.includes(e),$g=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!lr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=Vn({declarations:a.declarations,vocabulary:ps(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},Rn=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},Gg=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Rn(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},Ug=(e,t)=>{const r=new Map(ss.flatMap(a=>t[ht[a]].map(i=>[i.id,a]))),n=[];return Rn(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},Hg=e=>{const t=[];return Rn(e,(r,n,a)=>{if(!lr(r))return;const i=r.when?.state;i===void 0||hs(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},hs=e=>l.STYLE_STATES.includes(e),Wg=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))fs(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${de(n)}.`,context:{param:"tokens",actual:de(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},fs=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,oe=e=>typeof e=="number"&&Number.isFinite(e),Kg=e=>{if(oe(e)&&e>=0)return{top:e,right:e,bottom:e,left:e};if(typeof e!="object"||e===null)return;const t=e,r={...l.DEFAULT_GRAPH_PADDING_EDGES};for(const n of Ig){const a=t[n];if(a!==void 0){if(!oe(a)||a<0)return;r[n]=a}}return r},de=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),gs=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=dt(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((h,m)=>{if(!lr(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&&!hs(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=he(y,t.data,"style-rule");if(A.length>0){for(const I of A)o.push({...I,code:"INVALID_STYLE_RULE",message:`Style ${d}[${m}]: ${I.message}`,context:{...I.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const b=Vn({declarations:h.declarations,vocabulary:ps(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:me(y,i)},...g===void 0?{}:{state:g},origin:v})}),p};return{defaults:[...$g(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},Vn=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 ${de(v)}.`,context:{param:f,expected:g,actual:de(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 fs(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=Tg.has(f),v=Rg(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":oe(g)&&g>=0&&g<=1?d(f,g):p(f,"a number in [0, 1]",g);break;case"pixels":oe(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":on(g)?d(f,g):p(f,`one of ${an.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":oe(g)&&g>=qa&&g<=ja?d(f,g):p(f,`a number in [${qa}, ${ja}]`,g);break;case"multiplier":oe(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(!oe(y.offsetX)||!oe(y.offsetY)||!oe(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=Kg(g);y===void 0?p(f,Ag,g):d(f,y);break}default:break}}return c},zg=({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}},Yg=({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=M(s),d=O(s),p=W(s),h=K(s),m=nn(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=bn(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},qg=class extends _e{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=Yg({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=zg({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},ys=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)}},Za={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},jg=["color","size","alpha","strokeWidth","lineType"],Xg=class extends _e{dependencies(e){return jg.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,Za[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,Za[a],Zg(c)))}return{...e,data:r}}},Zg=e=>t=>l.isDefined(t)?e.map(t):null;function vs(e=new ir){return{diagnostics:new og,geomRegistry:e}}var bs=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??Ja})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??Ja;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,w(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=Tn(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return w(t,{scales:Ce(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=sr(r,a);return t.coords.coordType==="polar"?Ln(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:[oo(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{...er({spec:e}).pipe(({spec:r})=>({spec:w(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:w(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}}},Jg=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],Ja="light",Qg=({plugins:e=[]}={})=>{const t=Wo(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Hh(t),i=vs(r),o=new Cf(i),s=new ys(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new bs(i,new l.DataCompiler,new os(i),s,new fp,new ph(i,s,n,new oh(i,s,new gg(n),new $p,new Fp(i),new zh(new Qh))),new mf(i,o),new vp(new Op),new pf(i),new Xg,new Zm(i),new qg(i),new Sg(i),new wg(i),new th(i),new tp(i))};function Ss(e,t){return e.geom===t}function xs(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!ey(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>Is(o,s),i)}function As(e,...t){return t.reduce((r,n)=>Is(r,n),e)}function ey(e){return typeof e=="object"&&e!==null&&"type"in e}function Is(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,$t.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 ty(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function ty(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 ry(e){const t=e?.plugins??[],r=ay(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:xs,pipe:As,plugins:t}}var ny=e=>(t={})=>l.buildLayerInput(e,t);function ay(e){const{geoms:t,stats:r,transforms:n}=Wo(e),a={};for(const s of t)a[s.type]=ny(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 Ar="…",Ts=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Ar)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Ar)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Ar};var U={timeZone:"UTC"},$=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},ye=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Cn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",iy=Pr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ls=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>ye(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Pn(a,i),{base:s,suffix:c}=Dn(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),Es=({locale:e,numberFormat:t,intlOptions:r})=>ye(n=>{const{base:a,suffix:i}=Dn(n,t.abbreviation),o={...Pn(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),_n=e=>ye(t=>iy(t)),ws=({locale:e,intlOptions:t})=>ye(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Rs=({locale:e,numberFormat:t,intlOptions:r})=>ye(n=>{const a=Pn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Dn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=oy(e);return Dn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Pn=(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}},oy=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"},sy=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...U,...t}).format(r)),ly=({locale:e,intlOptions:t})=>$(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...U,...t}).formatToParts(r);return cy(n.map(uy))}),Vs=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...U,...t}).format(r)),Cs=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{month:"long",...U,...t}).format(r)),On=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...U,...t}).format(r)),kn=e=>$(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),_s=({locale:e,intlOptions:t})=>$(r=>{const n=(0,Yi.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...U,...t,year:void 0}).formatRange(r,n)}),Ds=({locale:e,intlOptions:t})=>$(r=>{const n=(0,Yi.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...U,...t}).formatRange(r,n)}),Mn=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{year:"numeric",...U,...t}).format(r)),Ps=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...U,...t}).format(r)),cy=e=>e.map(t=>t.value).join(""),uy=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},Qa=1e3,dy=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>ye(a=>{const i={...Bn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Nn(a,t,i)}),py=({locale:e,tickValues:t,intlOptions:r})=>ye(n=>{const a={...Bn(n,t),notation:"compact",...r};return Nn(n,e,a)}),my=({locale:e,tickValues:t,intlOptions:r})=>ye(n=>{const a={...Bn(n,t),notation:"compact",...r,style:"percent"};return Nn(n,e,a)}),Nn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Os=e=>Math.abs(e)>Qa?Os(e/Qa):Number.isInteger(e),hy=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Bn=(e,t)=>Os(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:hy(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},fy=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...U,...t}).format(r)),gy=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{month:"short",...U,...t}).format(r)),yy=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...U,...t}).format(r)),vy=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...U,...t}).format(r)),Fn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return dy(e);case"date":case"datetime":return fy(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return yy(e);case"decimal":case"integer":return py(e);case"duration":return _n(e);case"month":return gy(e);case"month_year":return On(e);case"percentage":return my(e);case"quarter":return kn(e);case"text":return Cn(e);case"time":return vy(e);case"year":return Mn(e);case"lookup":return Fn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},by=.9,Sy=1/3,xy=1/4,Ay=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Iy(e):Ty(e),Iy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=ks(e.ticks,n),s=Ly(e.ticks,r.width),c=s*by;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Ur(c);return{...e,ticks:Gr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Ur(r.height*Sy);return{...e,ticks:Gr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Ty=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=ks(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Ur(r.width*xy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Gr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Ly=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},ks=(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}},Gr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Ts(i.formattedLabel,r,a)})},Ur=e=>Math.max(0,Math.floor(e)),Ey=(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},wy=({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?Ry(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;Ey(s(p).map(h=>h.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},Ry=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),ei=.5,yt=e=>({x:0,y:0,width:e.width,height:e.height}),$n=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,vt=({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:Cy(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},m={anchor:_y(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=ri(y,{min:g.x,max:g.x+g.width,halfExtent:c/2}),I=ri(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:A,y:I,position:Vy(e,A,I,c,u)}},ti=(e,t,r,n)=>r-n>=e-ei&&r+n<=t+ei,Vy=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||ti(e.x,e.x+e.width,t,n/2),o=e.height===0||ti(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},Cy=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",_y=e=>e==="center"?"center":e==="start"?"min":"max",ri=({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},Dy=(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}}},Py=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=ky(e.layer);for(const a of e.layer.data){const i=_(a),o=O(a)??R(a);if(i===null||o===null||!qe(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}=Dy(o,M(a),i,e.panelRect.width,e.panelRect.height),h=vt({box:d,panel:yt(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}},Oy={place:Py,getPercentageValueStrategy:e=>e.position==="fill"?"fill":N(e.position)?"stack":"none"},ky=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:nr(e.data,e.mapping)?$n(r):r,align:n}};function bt(e){return e[l.VISUAL_VARIABLES.color]}function Ms(e){return e[l.VISUAL_VARIABLES.alpha]}function Gn(e){return e[l.VISUAL_VARIABLES.size]}function Hr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Ns(e){return e[l.VISUAL_VARIABLES.lineType]}var My={color:bt,alpha:Ms,strokeWidth:Hr,lineType:Ns,size:Gn,borderWidth:Hr},et=(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=By(s.styles,t);return r.set(s,u),u},chromeReaders:s=>{const c=n.get(s);if(c!==void 0)return c;const u=Ny(s,t);return n.set(s,u),u},explain:(s,c,u,d)=>{if(d!==void 0){const f=nt(s.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=nt(s.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const p=nt(s.styles.overrides,c,u,void 0,t);if(p!==void 0)return{value:p.value,tier:"override",origin:p.origin};const h=Bs(c,u);if(h!==void 0)return{value:h,tier:"data"};const m=nt(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"}}}},Ny=(e,t)=>{const r=(h,m)=>{const f=b=>ni(h.overrides,b,m)??ni(h.defaults,b,m);return{get:b=>{const A=f(b)?.declarations[b];if(A!==void 0)return ai(A,t)},getSource:b=>{const A=f(b);return A===void 0?"unresolved":A.origin.list==="builtin"?"builtin":"authored"},explain:b=>{const A=f(b),I=A?.declarations[b];return A===void 0||I===void 0?{value:void 0,source:"unresolved"}:{value:ai(I,t),source:A.origin.list==="builtin"?"builtin":"authored",origin:A.origin,select:A.select}}}},n=h=>r(e.panelBorder,m=>{const f=m.select.target==="panelBorder"?m.select.edge:void 0;return f===void 0||f===h}),a=h=>m=>r(e[h],f=>f.select.target!==h?!1:f.select.axis===void 0||f.select.axis===m),i=h=>r(e.ruleLabel,m=>m.select.target!=="ruleLabel"?!1:m.select.layer===void 0||m.select.layer===h),o=(h,m)=>r(e.dataLabel,f=>f.select.target!=="dataLabel"||f.select.role!==void 0&&f.select.role!==h?!1:f.select.position===void 0||f.select.position===m),s=h=>r(e.tooltip,m=>m.select.target==="tooltip"&&m.select.part===h),c=h=>r(e.legend,m=>m.select.target==="legend"&&m.select.part===h),u=h=>r(e.legendItem,m=>m.select.target==="legendItem"&&m.select.part===h),d=h=>r(e.headlineItem,m=>m.select.target==="headlineItem"&&m.select.part===h),p=(h,m)=>{const f=new Map;return g=>{const v=f.get(g);if(v!==void 0)return v;const y=r(e.annotation,b=>{if(b.select.target!=="annotation")return!1;const A=b.select.kind;return A!==void 0&&A!==h||b.select.part!==m?!1:b.select.annotation===void 0||b.select.annotation===g});return f.set(g,y),y}};return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:o,graph:r(e.graph,()=>!0),heading:r(e.heading,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:s(void 0),heading:s("heading"),label:s("label"),value:s("value"),primaryRow:s("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:d("number"),numberCenter:d("numberCenter"),caption:d("caption"),label:d("label"),swatch:d("swatch"),trend:d("trend"),trendUp:d("trendUp"),trendDown:d("trendDown"),trendFlat:d("trendFlat")},legend:{gap:c(void 0),popover:c("popover")},legendItem:{item:u(void 0),swatch:u("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:p("shape"),arrow:p("arrow"),differenceArrow:Object.assign(p("differenceArrow"),{label:p("differenceArrow","label")}),text:p("text"),image:p("image"),pinnedNumber:Object.assign(p("pinnedNumber"),{label:p("pinnedNumber","label")}),comment:Object.assign(p("comment"),{label:p("comment","label")})}}},ni=(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}},ai=(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},By=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=_t(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=_t(e.defaults,n,a,i,t);if(u!==void 0)return u}const o=_t(e.overrides,n,a,void 0,t);if(o!==void 0)return o;const s=Bs(n,a);return s!==void 0?s:_t(e.defaults,n,a,void 0,t)}}),_t=(e,t,r,n,a)=>nt(e,t,r,n,a)?.value,nt=(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&&Fy(o,r))return{value:$y(s,a),origin:o.origin}}},Fy=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),$y=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Bs=(e,t)=>{const r=My[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Un=(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")}}},Dt=6,Gy=.5,Uy=e=>{const t=[];let r=0;const n=N(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=Wy({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"?Yy({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}):jy(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,yt(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 Xy(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=ev({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}},Hy={place:Uy,getPercentageValueStrategy:e=>e.position==="fill"?"fill":N(e.position)?"stack":"absoluteGrandTotal"},Wy=({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=et().geomReaders(e);for(const p of e.data){const h=$s(t,p);if(h===null)continue;const m=a(p);if(m==="")continue;const f=Un(n,"observation",m),g=Hn(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}},Hn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),Fs=(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}},$s=(e,t)=>{const r=W(t),n=K(t),a=M(t),i=O(t)??R(t);return r===null||n===null||a===null||i===null?null:Fs(e,r,n,a,i)},Ky=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return Fs(e,r,n,a,i)},zy=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Wr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Yy=e=>e.isStacked?Zy({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Qy({edge:zy(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),Gs=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},qy=e=>e==="panel-start"||e==="panel-end",jy=(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=vt({box:n.bounds,panel:a,frame:Gs(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!qy(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+Gy?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},Xy=(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=yt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const h=$s(c,p);if(h===null)continue;const m=e.formatCategory(p);if(m===null||m==="")continue;const f=Un(e.measureDataLabel,"category",m),g=f[s],v=Hn(h,e.panelRect),y=d===null?null:p[d],b=l.isStrictNumericDataValue(y)&&y<0,A=vt({box:v,panel:u,frame:Gs(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:g.width,labelHeight:g.height}),I=f[A.position];r.push({layerId:e.layer.id,x:A.x,y:A.y,text:m,width:I.width,height:I.height,isRotated:!1,target:"category",position:A.position})}return r},Zy=({bounds:e,box:t,isRotated:r})=>{const n=Wr(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"}},Jy=(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}}},Qy=({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}=Jy(e,t,a,i),g=Wr(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 ee=h-m*(v/2+o);return{...s?{x:c,y:ee}:{x:ee,y:u},isRotated:!1,position:"inside"}}const I=Wr(r.outside.width,r.outside.height,n),T=(s?I.height:I.width)/2,E=h+m*(T+o);return E-T<0||E+T>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},ev=({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=Hn(Ky(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+Dt+p/2:u.x-Dt-p/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=m?u.y-Dt-h/2:u.y+u.height+Dt+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},tv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=nv(e.layer);for(const a of e.layer.data){const i=_(a),o=R(a);if(i===null||o===null||!qe(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=vt({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:yt(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}},rv={place:tv,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:nr(e.data,e.mapping)?$n(r):r,align:n}},av=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=ov(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=et().geomReaders(e.layer);for(const o of e.layer.data){const s=_(o),c=R(o);if(s===null||c===null||!qe(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=vt({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:yt(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}},iv={place:av,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:r,align:n}},Us=e=>{const t=W(e),r=K(e),n=M(e),a=O(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}},Hs=e=>{const t=Us(e);if(!t)return null;const r=t.width*gh,n=t.height*yh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},ii=4,sv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=et().geomReaders(e.layer);for(const n of e.layer.data){const a=Hs(n);if(a===null||!bt(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+ii>c||s+ii>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}},lv={place:sv,getPercentageValueStrategy:()=>"none"};function Wn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Kn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var cv=" · ",Ir=2,st=(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)},uv=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=st("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Ir&&t+i<=e.outerRadiusPx+Ir)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=st("tangential",r,n,a)/t,c=Ir/t;return Math.abs(r-e.midAngle)+s<=o+c},dv=({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,oi=({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+st("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},pv=({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+st("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=st("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:uv({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},mv=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=et().geomReaders(e.layer);for(const h of e.layer.data){const{startAngle:m,endAngle:f}=Wn(h),{innerRadius:g,outerRadius:v}=Kn(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}${cv}${y}`,I={startAngle:m,endAngle:f,midAngle:(m+f)/2,innerRadiusPx:(g??0)*d,outerRadiusPx:v*d};let T,E;if(r==="auto"){const L=e.measureDataLabel("observation",s,A);E={width:L.width,height:L.height},T=oi({wedge:I,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const G=c+Math.sin(T.labelAngle)*T.labelRadius,j=u-Math.cos(T.labelAngle)*T.labelRadius;if(T.position==="outside"&&!dv({x:G,y:j,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const Se=e.measureDataLabel("observation","inside",A);E={width:Se.width,height:Se.height},T=oi({wedge:I,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const L=Un(e.measureDataLabel,"observation",A),G=L[r];T=pv({wedge:I,placement:r,justify:$n(n),align:a,offset:i,labelWidth:G.width,labelHeight:G.height}),E=L[T.position]}const ee=c+Math.sin(T.labelAngle)*T.labelRadius,be=u-Math.cos(T.labelAngle)*T.labelRadius;t.push({layerId:e.layer.id,x:ee,y:be,text:A,width:E.width,height:E.height,isRotated:!1,target:"observation",position:T.position,...T.position==="inside"?{backdropColor:p.get("color",h)}:{}})}return{labels:t,droppedCount:0}},hv={place:mv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},fv=e=>{const t=D({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=D({...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)}},D=e=>{switch(e.valueFormat.type){case"currency":return Ls(e);case"date":return sy(e);case"datetime":return ly(e);case"day_month":return Vs(e);case"decimal":return Es(e);case"duration":return _n(e);case"integer":return ws(e);case"month":return Cs(e);case"month_year":return On(e);case"percentage":return Rs(e);case"quarter":return kn(e);case"text":return Cn(e);case"weekly_date_range":return _s(e);case"weekly_date_range_with_year":return Ds(e);case"year":return Mn(e);case"time":return Ps(e);case"lookup":return fv({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function zn({layer:e,numberFormat:t,locale:r}){return D({valueFormat:$d(e),locale:r,numberFormat:t})}var gv=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Qe(e,t),variable:r}:{read:J,variable:l.GROUP_VARIABLES.group}},Ws=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=zn({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:xv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:yv({layer:e,numberFormat:n,locale:o})}},yv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=gv(e.data,e.mapping),i=D({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)}},vv=(e,t,r)=>{switch(t){case"stack":return bv(e);case"fill":return Sv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},bv=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(bn(a,t));return s===void 0?null:s.total}},Sv=(e,t)=>{const r=t?W:M,n=t?K:O,a=ct(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}},xv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=Y(e.data,e.dataLabels.labelSource),c=vv(e,i,o),u=Av({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=D({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&Ks(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)}},Av=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(Ks(e))return a;const s=Iv(e,r,t,n,o);if(s!==null)return s}return D({valueFormat:Tv(e.data,i),locale:n,numberFormat:t})},Ks=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Qt(e.position,e.mapping))},Iv=(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:D({valueFormat:o.valueFormat,locale:n,numberFormat:r})},Tv=(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)},Yn={bar:{cartesian:Hy,polar:hv},line:{cartesian:rv},point:{cartesian:iv},area:{cartesian:Oy},tile:{cartesian:lv}},Lv=(e,t)=>Yn[e]?.[t]!==void 0,Ev=({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=Yn[g]?.[h];if(v===void 0)continue;const y=Ws({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)Rv(A,h,c,u)||d.push(A)}return{labels:d,warnings:m>0?[wv(m)]:[]}},wv=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}}),Rv=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Vv({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=Yn[s.geom]?.cartesian;if(c===void 0)continue;const u=Ws({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 Tr={abbreviation:"none",decimals:"auto"},zs=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return D({valueFormat:a,locale:e,numberFormat:Tr,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?"-∞":D({valueFormat:{type:"percentage"},locale:e,numberFormat:Tr,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${D({valueFormat:{type:"decimal"},locale:e,numberFormat:Tr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},Cv=2,_v=6,Dv=6,Pv=15,Ov=15,kv=2.5,Mv=.5,Nv=.25,Ys=e=>{const t=e-Cv,r=1+Mv*t,n=1+Nv*t;return{arrowStartGap:_v*r,arrowEndGap:Dv*r,offsetFromHigherObservation:Pv*n,arrowheadSize:kv*e,curveRadius:Ov*n,strokeWidth:e}},Bv=(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},Fv=(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 Fd=Object.create,co=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,Gd=Object.getOwnPropertyNames,Ud=Object.getPrototypeOf,Hd=Object.prototype.hasOwnProperty,Wd=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Gd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!Hd.call(e,s)&&s!==r&&co(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=$d(t,s))||n.enumerable});return e},rr=(e,t,r)=>(r=e!=null?Fd(Ud(e)):{},Wd(t||!e||!e.__esModule?co(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-BC4IbM6k.cjs");let ge=require("color2k"),uo=require("date-fns"),rt=require("lodash-es"),it=require("d3-time"),Kd=require("date-fns/differenceInDays"),Ee=require("d3-regression"),ie=require("d3-scale"),Ye=require("d3-interpolate"),N=require("d3-scale-chromatic"),Xe=require("lodash-es/clamp");Xe=rr(Xe,1);let zt=require("lodash-es/merge");zt=rr(zt,1);let Gr=require("humanize-duration");Gr=rr(Gr,1);let De=require("d3-shape"),zd=require("d3-delaunay"),Yt=require("lodash-es/isEqual");Yt=rr(Yt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789367356750");var Yd=1e6;function J(e){return String(Math.round(e*Yd))}var Oa="#FFFFFF",wr="#1A1A1A",qd=4.5,po=e=>{try{return(0,ge.getContrast)(e,Oa)>(0,ge.getContrast)(e,wr)?Oa:wr}catch{return wr}},jd=(e,t)=>{try{const r=mo(void 0,t);return r===void 0||(0,ge.getContrast)(r,e)>=qd?e:po(r)}catch{return e}},mo=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ge.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ge.parseToRgba)(e);return r>=1?e:(0,ge.parseToRgba)(t)[3]<1?void 0:(0,ge.mix)(t,(0,ge.opacify)(e,1),r)}catch{return}},Ma=0;function G(){return Ma+=1,`${Math.random().toString(36).slice(2,6)}${Ma.toString(36)}`}var de=Math.PI*2,Xd=8,Zd=1e-9,Jd=[0,Math.PI/2,Math.PI,de*3/4],ho=(e,t)=>Math.abs(t-e)>=de-Zd,_e=e=>(e%de+de)%de,qt=(e,t,r)=>{if(ho(t,r))return!0;const n=_e(r-t);return _e(e-t)<=n},Ze=(e,t)=>{const r=Math.abs(_e(e)-_e(t));return Math.min(r,de-r)},ka=(e,t)=>{const r=_e(t-e);return r>Math.PI?r-de:r},fo=(e,t,r)=>e*de+t+r,pe=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),we=(e,t)=>{const r=pe(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},Qd=(e,t,r,n)=>{const a=[we(e,r),we(e,n),we(t,r),we(t,n)],i=Math.max(r,n),o=Jd.filter(c=>qt(c,e,t)).map(c=>we(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))}},nr=(e,t)=>({angle:_e(Math.atan2(e,t)),radius:Math.hypot(e,t)}),ar=(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}},un=(e,t)=>{const{x:r,y:n}=ar(e,t);return nr(r,n)};function D(e){return e[l.POSITION_VARIABLES.x]}function R(e){return e[l.POSITION_VARIABLES.y]}function K(e){return e[l.POSITION_VARIABLES.xMin]}function z(e){return e[l.POSITION_VARIABLES.xMax]}function B(e){return e[l.POSITION_VARIABLES.yMin]}function M(e){return e[l.POSITION_VARIABLES.yMax]}function dn(e){return e[l.POSITION_VARIABLES.yRaw]}function ep(e,t){return e[l.resolveScaledAestheticVariable(t)]}var tp={xMin:0,xMax:1,yMin:0,yMax:1},go=(e,t)=>{const r=K(e)??D(e),n=z(e)??D(e),a=B(e)??R(e),i=M(e)??R(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}:{...Qd(r,n,a,i),frame:"disk"}},mt=(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}}},yo=e=>mt(tp,e),vo=["stack","dodge","identity","fill"],pn=["solid","dashed","dotted"],mn=e=>pn.includes(e);function F(e){return e==="stack"||e==="fill"}var j=(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},nt=(e,t)=>j(e,t.x),hn=(e,t)=>j(e,t.y),rp=(e,t)=>j(e,t.label),bo=(e,t)=>j(e,t.color),np=(e,t)=>j(e,t.size),ap=(e,t)=>j(e,t.alpha),ip=(e,t)=>j(e,t.group),op=(e,t)=>j(e,t.strokeWidth),Na={variable:l.POSITION_VARIABLES.yRaw};function ir(e,t){return F(e)?Na:t.y??Na}function ht(e){return j(e.data,ir(e.position,e.mapping))}var Me=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},fn=e=>sp(e)?l.extractVariableName(e.mapping.y):null,So=e=>fn(e)===null?null:ht(e),gn=e=>e.spatialKind!=="cells",sp=e=>e.spatialKind==="points"||e.spatialKind==="cells",xo=(e,t)=>e.yScaleType===t.yScaleType&&Hr(e.valueFormat)===Hr(t.valueFormat),Ur=e=>`${e.yScaleType} y axis, ${Hr(e.valueFormat)}`,Hr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Ao=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(Me(e))),n=fn(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 Io(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 V(e,t){return Lo(e,t)}function w(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 To(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function ke(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 Lo(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=Lo(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 or(e){return{pipe:t=>{const r=t(e);return or({...e,...r})},result:()=>e}}var lp=(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},yn=e=>e.type==="polar"?"disk":"panel",sr=(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}},Ba=(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=sr(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 Y(e,t){return e==="x"?t.x:t.y}function me(e,t){return e==="x"?t.y:t.x}function lt(e,t){return{main:Y(e,t),cross:me(e,t)}}function Fa(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function cp(e){return e.type==="cartesian"}var Q=e=>e[l.GROUP_VARIABLES.group],ft=e=>{const t=Me(e),r=So(e),n=gn(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?Q(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},Je=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,up={type:"decimal"};function Eo(e){return e.length>0&&e.every(t=>t.data.size()===0)}function vn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):up}function dp(e){return vn(e,l.extractVariableName(e.mapping.y))}function wo({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??ir(t,r)}function Ro(e,t){const r=wo({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:j(e.data,r),valueFormat:vn(e,a)}}var Co=e=>{const t=Me(e),r=So(e),n=gn(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(Q(a),i.groupValue)},Vo=e=>{const t=l.extractVariableName(e.mapping.y),r=ht(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},pp=["lt","lte","gt","gte","range"],mp={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"}},ue=()=>!1,Ge=()=>!0;function gt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Vo(e),parsingLocale:t}}function ve(e,t){if("and"in e){const r=e.and.map(n=>ve(n,t)).filter(n=>n!==Ge);return r.includes(ue)?ue:r.length===0?Ge:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>ve(n,t)).filter(n=>n!==ue);return r.includes(Ge)?Ge:r.length===0?ue:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=ve(e.not,t);return r===ue?Ge:r===Ge?ue:n=>!r(n)}return fp(e,t)}function be(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>be(n,t,r)):"or"in e?e.or.flatMap(n=>be(n,t,r)):"not"in e?be(e.not,t,r):hp(e,t,r)}function hp(e,t,r){const{subject:n,effect:a}=mp[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=gp(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 fp(e,t){if(!t.hasVariable(e.variable))return ue;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=>Ue(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=Ue(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Ue(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=Ue(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=Ue(u,o),p=Ue(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return ue}function gp(e){for(const t of pp)if(t in e)return t;return null}function Ue(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 yp=(e,t,r,n,a,i)=>{const o=_o(e,t,r.predicate,n,a,i);if(o===null)return null;const s=Do(r.padding),c=s===null?Sp(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}},vp=(e,t,r,n,a,i)=>{const o=_o(e,t,r.predicate,n,a,i);return o===null?null:{...mt(o,r.align),frame:o.frame}},Do=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},_o=(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=be(r,u.data,"selection-anchor");if(d.length>0){for(const m of d)c.set(`${m.code}:${m.message}`,m);continue}s=!0;const p=ve(r,gt(u,i));if(p!==ue)for(const m of u.data){if(!p(m))continue;const h=go(m,a);h!==null&&(o=o===null?h:bp(o,h))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},bp=(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)}),Sp=(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=Ap(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Ip(n,t.offset,e.coordSystem)},Po=(e,t)=>t.anchorType==="selection"?yp(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},bn=(e,t,r)=>Wr(e,t,r)?.point??null,Wr=({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=Ro(o,s),d=Co(o),p=ft(o),m=Ao(o,n)(a);let h=-1;for(const f of o.data){if(h+=1,!d(f,m))continue;const g=c(f,{coordSystem:r,position:o.position,purpose:i,align:a.align});if(g===null)continue;const v=Oo(o,f,u);if(v===null)continue;const y=p(f);if(y!==null)return{point:{...g,...v,frame:yn(r),observationIndex:h,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:o.id}}}return null},xp=(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=Ga(t.x,"x",r,i),u=Ga(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!Je(d,p))return null;const m=$a(d,o,Tp(e)),h=$a(p,s),f=Fa(n.mainAxis,{main:m.min,cross:h.min}),g=Fa(n.mainAxis,{main:m.max,cross:h.max});return mt({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},Oo=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:lp(r.valueFormat,t),yScaleType:e.yScaleType}:null},Ap=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return xp(e,t);case"selection":return vp(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 bn(e,Lp(t),r)}},Ip=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Do(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},$a=(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}},Tp=({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},Lp=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Ga=(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},Ep=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:Np(o,t.differenceArrows),shapes:Vp(o,t.shapes),arrows:_p(o,t.arrows),textAnnotations:Pp(o,t.textAnnotations),images:Dp(o,t.images),stickers:Op(o,t.stickers),pinnedNumbers:Mp(o,t.pinnedNumbers),comments:kp(o,t.comments)};return wp(this.container,s),Rp(this.container,s),s}},oe=(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."})},wp=(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)}},Rp=(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 Cp(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."})},Cp=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},Vp=(e,t)=>{const r=[];for(const n of t){const a=Po(e,n.region);if(a===null){oe(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},Dp=(e,t)=>{const r=[];for(const n of t){const a=Po(e,n.region);if(a===null){oe(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},_p=(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){oe(e.container,"arrow",n.id,`has ${Mo(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Pp=(e,t)=>{const r=[];for(const n of t){const a=jt(e,n.at,"pin");if(a===null){oe(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},Op=(e,t)=>{const r=[];for(const n of t){const a=jt(e,n.at,"pin");if(a===null){oe(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},Mp=(e,t)=>{const r=[];for(const n of t){const a=bn(e,n.at,"pin");if(a===null){oe(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},kp=(e,t)=>{const r=[];for(const n of t){const a=bn(e,n.at,"pin");if(a===null){oe(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Np=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)oe(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Wr(e,n.start,"value"),i=Wr(e,n.end,"value");if(a===null||i===null){oe(e.container,"differenceArrow",n.id,`has ${Mo(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){oe(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Bp(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},Mo=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Bp=(e,t,r,n)=>{xo(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:Ur(r),actual:Ur(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Fp(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:ko(i),values:i};return new l.Dataset(n)}function ko(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 $p=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,ko(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Ne=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)}},Gp=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)}},Up=class extends Ne{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}},Hp=class{constructor(e){this.setupStage=new Gp(e),this.transformStage=new Up(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)}},Wp=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}},Kp=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:Yp(e.scales,e.layers)}}transform(e){return e.layers.map(t=>jp(t))}},zp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ua=l.prefixInternalVariable("flipSwap"),Yp=(e,t)=>qp(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,qp=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},jp=e=>{let t=e.data;for(const[r,n]of zp){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ua).renameVariable(n,r).renameVariable(Ua,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function No(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 Bo=(e,t)=>No(t.domain!==null&&t.domain.length>0?t.domain:e),Xp=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=Qp(t,e.scales,e.layers),a=tm(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=Jp(r,n),i=rm(t);return e.layers.map(o=>nm(t.theta==="y"?am(o):o,a,i))}},Zp=[[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 Jp(e,t){return r=>fo(r,e,t)}function Qp(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=em(n,e,r);return a===0?0:-Math.PI/a}function em(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 Bo(n,e).length}function tm(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 rm(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function nm(e,t,r){let n=e.data;return n=He(n,l.POSITION_VARIABLES.x,t),n=He(n,l.POSITION_VARIABLES.xMin,t),n=He(n,l.POSITION_VARIABLES.xMax,t),n=He(n,l.POSITION_VARIABLES.y,r),n=He(n,l.POSITION_VARIABLES.yMin,r),n=He(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function He(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 am(e){let t=e.data;for(const[r,n]of Zp){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 im=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Wp),this.register("flip",new Kp),this.register("polar",new Xp)}},Fo=new Set(["min","max","scalar"]),om={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function sm(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 lm(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 cm(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=om[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 um=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:cm(n.data,r.positionRoles,a)}}},Sn=["x","y"],xn=new Set(["x","y","ySecondary"]),yt=new Set(["color","size","alpha","strokeWidth","lineType"]),Be=e=>xn.has(e),An=e=>yt.has(e),$o=e=>Be(e)||An(e);function xe(e){return e==="secondary"?"ySecondary":"y"}function Go(e,t){return e==="y"?xe(t):"x"}function $(e){return e==="ySecondary"?"y":e}var Ae=(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 yt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},lr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Ae(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),dm=class{compute({data:e,mapping:t}){const r=Ae(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)}}},pm=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},mm=(e,t,r)=>{const n=Pe(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Pe(e,t){const r=$(t);for(const n of Uo(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var cr=(e,t)=>e===null?null:t[e]??e,hm=(e,t)=>e===null?null:t[String(e)]??null,Oe=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Rr(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 gm(i,t)?i:Rr(t)}return Rr(t)},fm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Uo(t,e).some(r=>r.position==="fill");function Uo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Rr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},gm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},ym=[{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}],Ha={year:0,quarter:1,month:2,week:3,day:4,hour:5},We=40,vm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Am(r.unit).range(e,new Date(t.valueOf()+1),n)},bm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Kd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>We;case"day":return a/t>We;case"week":return a/(7*t)>We;case"month":return a/(30*t)>We;case"quarter":return a/(90*t)>We;case"year":return a/(365*t)>We}},Sm=(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"}}},xm=(e,t)=>{const r=Im(t);return r===null?!1:Ha[e]>Ha[r]},Am=e=>{switch(e){case"hour":return it.utcHour;case"day":return it.utcDay;case"week":return it.utcMonday;case"month":case"quarter":return it.utcMonth;case"year":return it.utcYear}},Im=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}},Ho={left:"right",right:"left",top:"bottom",bottom:"top"},Tm={x:!0,y:!0,ySecondary:!1},Lm=20,Wa=new Set(["top","bottom"]),Em={type:"percentage"};function wm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:o,geomRegistry:s}=e;if(Eo(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Vm(s,a,i.type,n),u=new Set(t.map(m=>m.position)),d=_m(Wo(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const m of xn){const h=r[m];if(!l.isDefined(h)||h.kind!=="position")continue;const f=Rm({scaleAestheticKey:m,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function Rm(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}=Dm(t,n,i,o),m=Pe(a,t),h=fm(a,t)?Em:Oe({layers:a,scaleType:r.spec.scaleType,variableName:m});return{scaleAestheticKey:t,position:d,geometry:p,label:Cm(u,m,c),isVisible:u.isVisible,tickCandidates:Om(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Pm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Cm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Vm(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:Ka(i,n.axes.x.grid.isVisible)},y:{gridVisible:Ka(o,n.axes.y.grid.isVisible)}}}function Ka(e,t){if(e&&t===null)return!1}function Dm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Wo(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=Ho[n],i=(0,rt.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 Wo(e,t){return Wa.has(e)===Wa.has(t)?e:t}function _m(e,t){return t.has(e)?Ho[e]:e}function Pm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Tm[r]}var Om=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=km(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=Lm;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>Qe(e,u))}))}return i}return e.spec.scaleType==="datetime"?Mm(e,t):[{ticks:e.generateTicks().map(a=>Qe(e,a))}]},Mm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>Qe(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=>Qe(e,d)),valueFormat:c}))};for(const s of ym)bm({...s,start:r,stop:n})||xm(s.unit,t)||o(e.generateTicks({interval:s}),Sm(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},km=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:[Qe(e,r),Qe(e,n)]}},Qe=(e,t)=>({value:t,position:e.map(t)});function Ko({scale:e,aesthetics:t,layers:r}){const n=Nm({layers:r,aesthetics:t}),a=zo({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Nm({layers:e,aesthetics:t}){const r=zo({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 zo({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 In=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Bm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!In(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=Pe(t,"color");if(Yo({colorVariableName:a,xVariableName:Pe(t,"x"),mapsColorAcrossMultipleLayers:$m(t)>1,isMergedWithAnotherAesthetic:Fm(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return Ko({scale:n,aesthetics:["color"],layers:t}).map(({value:s,geom:c,owner:u})=>{const d=u?.layerIndex??o,p=t[d],m=p?l.extractVariableName(p.mapping.color):null;return{value:s,color:String(n.map(s)),geom:c,layerIndex:d,valueFormat:Oe({layers:p?[p]:t,scaleType:i,variableName:m}),label:hm(s,r)}})}var Yo=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Fm(e,t,r){if(r===null)return!1;for(const n of yt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!In(a))&&Pe(t,n)===r)return!0}return!1}var $m=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function qo(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Gm(e,t,r,n){const a=r.findIndex(i=>qo(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:cr(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 za(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,Um=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Ya(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Ya(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Hm=(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}},Ya=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Wm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Km(e,n):zm(e,n)}function Km(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:Oe({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:o})}}function zm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:o,geomRegistry:s}=e;if(!a.some(d=>qo(s,d)))return null;const c=Gm(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Ym({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 Ym({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=Oe({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=Xm(i.data,s),m=Oe({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),h=Zm(i.data,s),f=h.getValues(o,{type:"numeric"}),g=s!==null?h.getValues(s):[],v=c!==null?h.getValues(c):null,y=za(f,v,e.value),b=za(g,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:Um(y,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:m,label:e.label,caption:qm(t,p,b),comparison:jm(t,r,p,b,y)}}function qm(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 jm(e,t,r,n,a){return e!=="current"||!r?null:Hm(n.map((i,o)=>({main:i,cross:a[o]??null})),jo(t))}function Xm(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Zm(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function te(e,...t){return e?t.includes(e.geom):!1}function O(e,t){return e.find(r=>r.id===t)}function Ie(e,...t){return e.find(r=>t.includes(r.geom))}function Jm(e,...t){return e.filter(r=>t.includes(r.geom))}function Tn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Ln(e){const t=e.filter(r=>!Tn(r,e));return t.length>0?t:e}function Xo({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Ln(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Qm=3;function eh({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=lh(ah({scales:e,layers:r})),u=Pe(r,"x"),d=c.map(v=>{if(oh(v,u,r))return null;const y=uh({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return y.items.length===0?null:{group:v,built:y}}).filter(l.isDefined),p=th(d),m=Ln(r),h=gh(o,t.legend.position,p,m,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&fh(o,p,m,n))return{drawn:[],position:h};const f=yh(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),g=f==="direct"?xh(m[0]):null;return{drawn:d.map(({built:v})=>rh(v,{position:h,display:f,align:t.legend.align},g)),position:h}}function th(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function rh(e,t,r){const{position:n,display:a}=t,i=nh(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 nh(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function ah(e){const{scales:t,layers:r}=e,n=[];for(const a of yt){const i=t[a];if(i===void 0||i.kind==="identity"||!ih(a,r))continue;const o=Pe(r,a),s=Sh(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function ih(e,t){const r=$(e);return t.some(n=>l.isDefined(n.mapping[r]))}function oh(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Yo({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:sh(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function sh(e,t){const r=$(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function lh(e){const t=new Map;for(const r of e){const n=bh(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function ch(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function uh({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>$(u.scaleAestheticKey)),o=Ko({scale:a.scale,aesthetics:i,layers:r}),s=Oe({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:cr(a.variableName,t),items:o.map(u=>dh(u,e,i,s,n,c))}}function dh(e,t,r,n,a,i){const o={};for(const c of t)ch(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);mn(c)&&(o.lineType=c)}const s=mh(e,t,r,n,a);return{value:e.value,label:ph(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function ph(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function mh(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=hh(i,r);return i===void 0||o===null?n:Oe({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function hh(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 fh(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 gh(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,F(u.position)&&(s=!0))}const c=r>=Qm;return i&&o?"top":i?c?"right":"top":s?vh(a)?"top":c?"right":"top":"top"}function yh(e,t){return e==="pill"?"pill":Xo(t)?"direct":"pill"}function vh(e){return e.type==="cartesian"&&e.mainAxis==="y"}function bh(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Sh(e,t){return In(t)?"discrete":`continuous:${e}`}function xh(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(M(c))||l.isDefined(R(c)));if(!n)return;const a=Q(n);if(!l.isDefined(a))return;const i=B(n),o=M(n)??R(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var Ah=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=pm(e.originalData),r=Bm({scales:e.scales,layers:e.layers,valueLabels:mm(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=Wm(n),i=eh(n),o={...i,drawn:Ih(a,i.drawn)};return{axes:wm(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},Ih=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],ct=(e,t,r)=>{switch(e){case"series":return Th(t);case"x-value":return En(t,r)}},ur=e=>{const t=l.readMainAxisVariable(e);return t===""?null:t},Th=e=>l.getStableKey([Q(e)]),En=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Lh={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function Zo(e){const t=Lh[e]??null;return t===null?null:{strategy:t,composition:Jo()}}function Jo(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Eh=class extends Ne{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=wh({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function wh({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const P=be(T.predicate,e.data);for(const k of P)a.diagnostics.addWarning({...k,message:`${k.message} Dropping this highlight.`});return P.length===0}),o=ur(e.mapping),s=gt(e,r),c=i.map(T=>({predicate:ve(T.predicate,s),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),p=n==="overlay-anchor",m=e.data.size(),h=u?new Array(m):null,f=d?new Array(m):null,g=p?new Array(m):null,v=new Uint8Array(m),y=new Set,b=new Set;let A=!1,I=0;for(const T of e.data){let P,k;h!==null&&(P=ct("series",T,o),h[I]=P),f!==null&&(k=ct("x-value",T,o),f[I]=k),g!==null&&(g[I]=T);for(const{predicate:ne,scope:Ot}of c)if(ne(T))switch(Ot){case"series":P!==void 0&&y.add(P);break;case"x-value":k!==void 0&&b.add(k);break;case"data-point":v[I]=1,A=!0;break}I++}if(y.size===0&&b.size===0&&!A)return Jo();const L=new Uint8Array(m),E=[];let re=0;for(let T=0;T<m;T++){const P=h?.[T],k=f?.[T],ne=P!==void 0&&y.has(P),Ot=k!==void 0&&b.has(k),_a=v[T]===1;if(n==="observation-rerender")(ne||_a||Ot)&&(L[T]=1,re++);else if(ne)L[T]=1,re++;else if(_a||Ot){const Pa=g?.[T];Pa!==void 0&&E.push({observation:Pa,observationIndex:T})}}const Le=re>0?{...e,data:e.data.filterByMask(L)}:null;return{isDimmed:(n==="observation-rerender"||y.size>0)&&Le!==null,matchedLayer:Le,overlayCandidates:E}}var Rh=l.prefixInternalVariable("__ungrouped__");function Ch(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]??Rh;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 Vh=()=>({defaults:[],overrides:[],warnings:[]}),Dh=class extends Ne{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,qa(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:qa(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=or({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:Ch(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:Zo(e.geom),styles:Vh()}}};function qa(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Qo(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function _h(e,t){return t.some(r=>F(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function Kr(e,t){const r=es(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:Oh(r),zeroAxes:n,bandPadding:Mh(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Ph(e,t){const r=es(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 es(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:xe(n.yScaleType)})}),r}function Oh(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of ts(r))t.add(n);return[...t]}function Mh(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of ts(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function ts({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var kh=new Set(["label","group"]),Nh=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)),Qo(this.container.diagnostics,t)}checkPostCompile(e){Eo(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(!lr(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=[...sm(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,m]of Object.entries(a)){if(u.has(p))continue;const h=l.extractVariableName(m);h===null||h===""||d.has(h)||i.hasVariable(h)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${p}' references variable '${h}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:p,variableName:h}})}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(!Fo.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 m=i.getType(p);m!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${p}' is ${m}`,context:{layerIndex:t,aesthetic:d.aes,variableName:p,variableType:m},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=Ph(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([...lm(i),...o.map(m=>m.name)]),u=kh,d=s,p=[];for(const m of Object.keys(a))l.isDefined(a[m])&&(c.has(m)||u.has(m)||d.has(m)||p.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${m}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:m}}));return p}},he=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=vo,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,rt.merge)({},this.defaultParams,e.params)}},wn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},Rn=(e,{coordSystem:t})=>{const r=D(e),n=R(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?we(r,n):{x:r,y:n}},Bh=class extends he{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=Rn}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=wn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Fh=.7,$h=.1,Gh=.03,Uh=.05,rs=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Hh=class extends he{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=>F(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>zr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=go(t,r);return p===null?null:mt(p,i)}if(r.type==="polar")return Wh(t);const o=F(n),s={isSolo:!o||rs(t)==="solo",isNegative:o&&Kh(t),purpose:a};if(r.mainAxis==="x"){const p=K(t),m=z(t),h=Xa({lowerBound:B(t),upperBound:M(t)??R(t),options:s});return p===null||m===null||h===null?null:{x:(p+m)/2,y:h}}const c=B(t),u=M(t),d=Xa({lowerBound:K(t),upperBound:z(t)??D(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=zr(r,n);e=wn(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}},zr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Fh,Wh=e=>{const t=K(e),r=z(e),n=B(e),a=M(e);return t===null||r===null||n===null||a===null?null:we((t+r)/2,(n+a)/2)},Kh=e=>{const t=dn(e);return l.isStrictNumericDataValue(t)&&t<0},Xa=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},zh=class extends he{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=Rn}compile(e){return{data:wn(e.data,e.mapping),mapping:{}}}},Yh=class extends he{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=Rn,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:{}}}},qh=class extends he{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=Za(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=Za(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}}}},Za=(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},jh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},Xh=class extends he{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=jh,this.resolveAnchorPosition=t=>{const r=K(t),n=z(t),a=B(t),i=M(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:{}}}},Zh=[new Hh,new Yh,new zh,new Bh,new qh,new Xh],dr=class extends l.Registry{constructor(){super("geom");for(const e of Zh)this.register(e.type,e)}},Fe=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},Jh=class extends Fe{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,...Ae(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},Qh=class extends Fe{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},ef=class extends Fe{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}}}},tf=2,ns=1440*60*1e3,rf=class extends Fe{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=Ae(e,t),u=uf(a,o,i,c,e);return c.length===0?Ja({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=df(d,c);Ja({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Ja=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=nf({data:e,xVariable:t,yVariable:n,xType:r});c.length<tf||(s?cf({observations:c,spec:a,output:i,groupObservation:o}):sf({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},nf=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?af(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 m=of({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});m!==null&&s.push({x:m,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},af=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},of=({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)/ns+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}`})}},sf=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=as(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?lf(s,r):s;a.push({x:u,y:c,groupObservation:i})}},lf=(e,t)=>t===null?new Date(e):new Date((e-1)*ns+t),cf=({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=as(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=is(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})}},as=(e,t)=>e.method==="loess"?(0,Ee.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):is(e,t),is=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Ee.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Ee.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Ee.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Ee.regressionQuad)().x(r).y(n)(t);case"power":return(0,Ee.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Ee.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},uf=(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)}}},df=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},pf=class extends Fe{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],...Ae(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},mf=[new Qh,new Jh,new rf,new ef,new pf],hf=class extends l.Registry{constructor(){super("stat");for(const e of mf)this.register(e.type,e)}};function ff({geoms:e,stats:t,transforms:r}){const n=new dr,a=new hf,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 Cn(e){if("definition"in e)return e.definition;if(ss(e)||ls(e)||cs(e))return e}function os(e){const t=[],r=[],n=[];for(const a of e){const i=Cn(a);i&&(ss(i)?t.push(i):ls(i)?r.push(i):cs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...Cr("geom",t,a=>a.type),...Cr("stat",r,a=>a.type),...Cr("transform",n,a=>a.transformType),...gf(t),...yf(t)]}}function gf(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 yf(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 Cr(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 ss=e=>e instanceof he,ls=e=>e instanceof Fe,cs=e=>"transformType"in e&&typeof e.apply=="function",vf=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},pr=class{},bf=class extends pr{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=Sf(e)??[-.7/2,.7/2],o=r.length>1?$h:0,s=(0,ie.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 m=a[p];if(!l.isDefined(m))continue;const h=s(String(m));l.isDefined(h)&&(u[p]=h,d[p]=h+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Sf=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]},Qa=l.prefixInternalVariable("__ungrouped__"),us=(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?[Qa]: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 m=0;m<d;m++){const h=l.getStableKey(s[m]??null),f=u[m],g=i?Qa:f;if(!l.isDefined(g))continue;let v=p.get(h);v||(v=new Map,p.set(h,v));let y=v.get(g);y||(y=[],v.set(g,y)),y.push(m)}return{yValues:c,observationIndicesByXAndGroup:p,uniqueGroupKeys:o,observationCount:d}},ds=(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,m=-1/0;for(const h of i.values())for(const f of h){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>m||v===m&&g<p)&&(d=f,p=g,m=v))}for(const h of o)a[h]=xf(h===s,h===d)}return a},xf=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Af=class extends pr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=us(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,m=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:m-=b)}}let h=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:m;if(A===0){c[y]=0,s[y]=0;continue}const I=b/A;b>=0?(c[y]=h,s[y]=h+=I):(s[y]=f,c[y]=f+=I)}}}const u=ds(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:{}}}},If=class extends pr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Tf=class extends pr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=us(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[,m]of a){let h=0,f=0;for(const g of i){const v=m.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]=h,s[y]=h+=b):(s[y]=f,c[y]=f+=b)}}}}const u=ds(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:{}}}},Lf=class extends l.Registry{constructor(){super("position"),this.register("identity",new If),this.register("stack",new Tf),this.register("fill",new Af),this.register("dodge",new bf)}},Ef=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)||An(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Go(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}},wf=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)}},Rf=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)?Cf(e,r,n):Vf(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Cf(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=ps(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function Vf(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=ps(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 ps(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Df=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(xe(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)}},_f=class{map({data:e,layer:t,getPositionScale:r}){const n=r(xe(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)?Pf(e,n,a):Of(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Pf(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=ms(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function Of(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=ms(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 ms(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Mf=[new wf,new Df,new Rf,new _f,new Ef];function kf(e,t){const r=e[t];return r?.kind==="position"?r:null}var Nf=class extends Ne{constructor(e,t=Mf){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=>kf(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}}},Bf=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:_h(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=$(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})}}Qo(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"?xe(n.yScaleType):i,c=a.get(i)??($o(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)||An(n.aes)||t.set(n.aes,Go(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)}},Ff=["rgb","lab","hcl","hsl"],$f=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],hs=["RdBu","BrBG","PuOr","Spectral"],fs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Gf=new Set(hs.map(e=>e.toLowerCase()));function gs(e){const t=e.toLowerCase(),r=fs[t];return r?r.toLowerCase():t}function Uf(e){return Gf.has(gs(e))}var Hf={rgb:Ye.interpolateRgb,lab:Ye.interpolateLab,hcl:Ye.interpolateHcl,hsl:Ye.interpolateHsl},Wf={viridis:N.interpolateViridis,magma:N.interpolateMagma,inferno:N.interpolateInferno,plasma:N.interpolatePlasma,cividis:N.interpolateCividis,turbo:N.interpolateTurbo,blues:N.interpolateBlues,greens:N.interpolateGreens,greys:N.interpolateGreys,oranges:N.interpolateOranges,purples:N.interpolatePurples,reds:N.interpolateReds,rdbu:N.interpolateRdBu,brbg:N.interpolateBrBG,puor:N.interpolatePuOr,spectral:N.interpolateSpectral};function Vn(e){const t=zf(e);return e.reverse?r=>t(1-r):t}function Kf(e={},t=2){const r=Vn({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 zf(e){const t=Hf[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ye.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Wf[gs(e.scheme)];if(r)return r}return(0,Ye.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var vt=class{createPositionScale(e,t){return{kind:"position",aesthetic:$(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:$(e.scaledAesthetic),spec:e,...t}}},Yf=class extends vt{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=Be(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"&&qf(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:$(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,ie.scaleLog)():r.transform==="sqrt"?(0,ie.scaleSqrt)():(0,ie.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=jf(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=Vn(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,ie.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,ie.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]}},qf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function jf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Xf=class extends vt{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=Be(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=Zf(e)?e:[],a=(0,ie.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?vm(i,o,c.interval):[]:a.ticks(c?.count)})}},Zf=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Jf=class extends vt{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=Be(e.scaledAesthetic),n=Bo(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,ie.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,ie.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})}},Qf=class extends vt{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:$(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},eg=class extends vt{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=No(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,ie.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},tg=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Yf(e)),this.register("discrete",new Jf),this.register("datetime",new Xf),this.register("identity",new Qf),this.register("palette",new eg)}},ys={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},rg={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 Dn(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Kr(e.geomRegistry,n)}}function mr(e,t){switch(t.scaleType){case"inferred":return{...mr(e,og(e,t)),inferredFrom:t};case"continuous":{const r=ys[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:sg(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 Yr(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 ng(e,t){const{scales:r,layers:n,coords:a}=t,i=Dn(e,t),o=ug(cg(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=ag(i,u);return mr(i,d)});return a.coordType==="polar"?c.map(_n):c}function Yr(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??ig(e.scaledAesthetic,t)}}var _n=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function ag(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:$(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 ig(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function og({data:e,layers:t,mapping:r,demands:n},a){const i=$(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?lg(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=ys[a.scaledAesthetic];switch(rg[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 sg(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:$(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&Uf(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:$(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function lg(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function cg(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function ug(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var dg={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}},pg=(e,t,r)=>{const n=mg(e,t),a=gg(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>vg(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Ag(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Lg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>yg(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>bg(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Ig(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>Sg(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>xg(e,i,r)).filter(l.isDefined)}},mg=(e,t)=>{if(t===void 0)return{};if(!hg(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:G()}):(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))}},hg=e=>{const t=new Set;for(const r of fg(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},fg=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],gg=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},Pn=(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},yg=(e,t,r,n)=>{const a=Xt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??G(),content:t.content,at:a,width:t.width,align:t.align??l.TEXT_ANNOTATION_DEFAULTS.align}},vg=(e,t,r)=>{const n=ut(e,t.start,r),a=ut(e,t.end,r);return n===null||a===null?null:{id:t.id??G(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},ut=(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)},Xt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return Pn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=ut(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},bg=(e,t,r,n)=>{const a=Xt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??G(),at:a,sticker:t.sticker}},Sg=(e,t,r)=>{const n=ut(e,t.at,r);return n===null?null:{id:t.id??G(),at:n}},xg=(e,t,r)=>{const n=ut(e,t.at,r);return n===null?null:{id:t.id??G(),at:n,content:t.content}},Ag=(e,t,r)=>t.region.anchorType==="annotation"&&!Pn(e,t.region.ref,r,t.id)?null:{id:t.id??G(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Tg(t.region)},Ig=(e,t,r)=>t.region.anchorType==="annotation"&&!Pn(e,t.region.ref,r,t.id)?null:{id:t.id??G(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Tg=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},ei=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=dg[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Lg=(e,t,r,n)=>{const a=Xt(e,t.start,r,n,t.id),i=Xt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??G(),start:ei(a),end:ei(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},Eg={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},layout:{gaps:{}}};function wg(e){const t=(0,rt.merge)({},Eg,e);return t.content=Rg(t.content,e?.content),t}var Rg=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Cg={xLimits:null,yLimits:null},Ut={theta:"x",startAngle:0,innerRadius:0};function qr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,zt.default)({},Cg,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Ut.theta,startAngle:t.params?.startAngle??Ut.startAngle,innerRadius:(0,Xe.default)(t.params?.innerRadius??Ut.innerRadius,0,1)}}}}function Vg(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??G(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Dg=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=ti(e.filter(n=>n.severity==="error")),r=ti(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},_g=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 ti(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Pg={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 vs(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 $e(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new _g(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=kg({dataLabels:Bg(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return Mg({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??G(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:vs(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 Og(e,t,r,n,a){const i=n.map((o,s)=>$e(e,t,r,o,a,s));return Ss(e,i)}var bs=(e,t,r,n)=>n.label!==void 0?n.label:wo({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Ss=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:ke(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,rt.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Mg=({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&&F(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'."})},kg=({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=Ng(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}},Ng=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&F(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Bg=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=bs(e,r.geom,n,i),s=e.get(r.geom);return{...(0,rt.merge)({},Pg,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},Fg=e=>{const t=new Set;e!==void 0&&xs(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},xs=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])xs(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function $g(e,t,r){const n=qr(t.coords),a=Og(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=ng(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=wg(t.config),s=Vg(e,t.highlights,a),c=pg(e,t.annotations,a),u=Fg(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 As=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return $g(this.container,{...e,data:t},r)}},Gg=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})}},bt={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},Ug={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}}},Is=Object.keys(bt),Hg=e=>Object.hasOwn(bt,e),St=(e,t)=>{for(const r of Is){const n=Wg(e,r,t);if(n)return n}return null},xt=(e,t)=>e[bt[t]],On=(e,t,r)=>({...e,[bt[t]]:r}),Ts=(e,t)=>{const r=xt(e,t.kind);return On(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Wg=(e,t,r)=>{const n=xt(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},Kg=class extends Ne{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of py(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of hy(e.styles))this.container.diagnostics.addWarning(r);for(const r of fy(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=_s({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Re={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Zt={bar:{...Re,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Re,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Re,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Re,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...Re,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},ri=1,ni=1e3,zg="'none' or a shadow object { offsetX, offsetY, blur, color }",Yg="a non-negative number of pixels, or an object of those per edge",qg=["top","right","bottom","left"],Mt={color:"color",strokeWidth:"pixels",lineType:"lineType"},Z={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},kt={...Z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},ai={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},C={panelBorder:{...Mt,borderRadius:"pixels"},panelBorderEdge:Mt,gridLine:Mt,tickLine:{...Mt,length:"pixels"},axisLabel:Z,tickLabel:{...Z,offset:"pixels"},ruleLabel:Z,dataLabel:kt,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",textScale:"multiplier",padding:"padding"},heading:{fontFamily:"fontFamily"},hoverGuide:{color:"color",background:"color"},tooltip:ai,tooltipText:Z,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels"},legend:{gap:"pixels"},legendPopover:ai,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:kt,annotationText:{...kt,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...kt,shadow:"shadow"}},Ls={number:Z,numberCenter:Z,caption:Z,label:Z,swatch:{size:"pixels"},trend:Z,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},jg=new Set([...Object.keys(Re),...Object.values(Zt).flatMap(e=>Object.keys(e??{})),...Object.values(C).flatMap(e=>Object.keys(e)),...Object.values(Ls).flatMap(e=>Object.keys(e))]),Es=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],Xg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Zg=(e,t,r="en-US")=>_s({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Jg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of my(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 ws(e.styles)}},ws=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:[]},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(hr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ey(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 ${Es.map(h=>`'${h}'`).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 h=p.kind;if(h!==void 0&&!ly(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown annotation kind '${String(h)}'.`,context:{param:"kind",actual:String(h),...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=cy(h);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 ${h==="differenceArrow"?"line":"marker"}.`:`Remove 'part' — ${h===void 0?"kind-agnostic":`'${String(h)}'`} 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 ${ye(v)}.`,context:{param:"annotation",actual:ye(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(p.target==="panelBorder"){const h=p.edge;if(h!==void 0&&!ty(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown edge '${String(h)}'.`,context:{param:"edge",actual:String(h),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Xg.has(p.target)){const h=p.axis;if(h!==void 0&&!uy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown axis '${String(h)}'.`,context:{param:"axis",actual:String(h),...u},suggestion:`Set 'axis' to one of ${Sn.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="ruleLabel"){const h=p.layer;if(h!==void 0&&typeof h!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid layer ${ye(h)}.`,context:{param:"layer",actual:ye(h),...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 h=p.part;if(h!==void 0&&!ay(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...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==="legend"){const h=p.part;if(h!==void 0&&!iy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...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 h=p.part;if(h!==void 0&&!oy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...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 h=p.part;if(!sy(h)){t.push({code:"INVALID_STYLE_RULE",message:h===void 0?`Style ${s} ignored: headlineItem entries need a part.`:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.HEADLINE_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="dataLabel"){const h=p.role;if(h!==void 0&&!ry(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown role '${String(h)}'.`,context:{param:"role",actual:String(h),...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(!ny(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(h===void 0||h==="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 m=kn({declarations:i.declarations,vocabulary:Cs(p),tokens:r,location:s,origin:c,warnings:t,entryTarget:p.target});Object.keys(m).length!==0&&n[p.target][o].push({select:p,declarations:m,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},Qg=(e,t)=>{if(e==="geom"){const r=Object.keys(Zt).find(n=>Zt[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>Cs({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},hr=e=>e.select.target==="geom",ey=e=>{const t=e.select.target;return t!=="geom"&&Es.includes(t)},Rs=e=>(e!==void 0?Zt[e]:void 0)??Re,Cs=e=>{if(e.target==="panelBorder")return e.edge===void 0?C.panelBorder:C.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?C.tooltip:e.part==="primaryRow"?C.tooltipPrimaryRow:C.tooltipText;if(e.target==="legend")return e.part==="popover"?C.legendPopover:C.legend;if(e.target==="legendItem")return e.part===void 0?C.legendItem:C.legendItemSwatch;if(e.target==="headlineItem")return Ls[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return C.annotationShape;case"arrow":return C.annotationArrow;case"differenceArrow":return e.part==="label"?C.annotationDifferenceArrowLabel:C.annotationDifferenceArrow;case"text":return C.annotationText;case"image":return C.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?C.annotationCalloutLabel:C.annotationCallout;default:return C.annotation}return C[e.target]},ty=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),ry=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),ny=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),ay=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),iy=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),oy=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),sy=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),ly=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),cy=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],uy=e=>typeof e=="string"&&Sn.includes(e),dy=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!hr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=kn({declarations:a.declarations,vocabulary:Rs(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},Mn=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},py=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Mn(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},my=(e,t)=>{const r=new Map(Is.flatMap(a=>t[bt[a]].map(i=>[i.id,a]))),n=[];return Mn(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},hy=e=>{const t=[];return Mn(e,(r,n,a)=>{if(!hr(r))return;const i=r.when?.state;i===void 0||Vs(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},Vs=e=>l.STYLE_STATES.includes(e),fy=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Ds(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${ye(n)}.`,context:{param:"tokens",actual:ye(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ds=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,ce=e=>typeof e=="number"&&Number.isFinite(e),gy=e=>{if(ce(e)&&e>=0)return{top:e,right:e,bottom:e,left:e};if(typeof e!="object"||e===null)return;const t=e,r={...l.DEFAULT_GRAPH_PADDING_EDGES};for(const n of qg){const a=t[n];if(a!==void 0){if(!ce(a)||a<0)return;r[n]=a}}return r},ye=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),_s=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=gt(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((m,h)=>{if(!hr(m))return;const f=m.select.kind;if(f!==void 0&&f!==t.geom||m.select.layer!==void 0&&m.select.layer!==t.id)return;const g=m.when?.state;if(g!==void 0&&!Vs(g))return;const v={list:d,index:h,...m.id===void 0?{}:{id:m.id}},y=m.when?.where;if(y!==void 0){const A=be(y,t.data,"style-rule");if(A.length>0){for(const I of A)o.push({...I,code:"INVALID_STYLE_RULE",message:`Style ${d}[${h}]: ${I.message}`,context:{...I.context,layerIndex:r,...m.id===void 0?{}:{styleEntryId:m.id}}});return}}const b=kn({declarations:m.declarations,vocabulary:Rs(f),tokens:s,location:`${d}[${h}]`,origin:v,warnings:o,entryTarget:"geom"});Object.keys(b).length!==0&&p.push({declarations:b,...y===void 0?{}:{matches:ve(y,i)},...g===void 0?{}:{state:g},origin:v})}),p};return{defaults:[...dy(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},kn=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 ${ye(v)}.`,context:{param:f,expected:g,actual:ye(v),...u},suggestion:`Set '${f}' to ${g}.`})},m=(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 Ds(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)},h=f=>{const g=jg.has(f),v=Qg(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){h(f);continue}switch(v){case"color":{const y=m(f,g);y!==void 0&&d(f,y);break}case"unitInterval":ce(g)&&g>=0&&g<=1?d(f,g):p(f,"a number in [0, 1]",g);break;case"pixels":ce(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":mn(g)?d(f,g):p(f,`one of ${pn.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":ce(g)&&g>=ri&&g<=ni?d(f,g):p(f,`a number in [${ri}, ${ni}]`,g);break;case"multiplier":ce(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(!ce(y.offsetX)||!ce(y.offsetY)||!ce(y.blur)||y.blur<0){p(f,zg,g);break}const b=m(f,y.color);b!==void 0&&d(f,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:b});break}case"padding":{const y=gy(g);y===void 0?p(f,Yg,g):d(f,y);break}default:break}}return c},yy=({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}},vy=({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=B(s),d=M(s),p=K(s),m=z(s),h=dn(s);if(!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||!l.isDefined(h))continue;const f=h>=0;if(Math.abs(h)===0)continue;const g=En(s,r),v={xMin:p,xMax:m,yMin:u,yMax:d},y=i.get(g);if(y===void 0){i.set(g,{total:h,topPositive:f?v:null,bottomNegative:f?null:v});continue}y.total+=h,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},by=class extends Ne{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=vy({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=yy({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Ps=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)}},ii={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Sy=["color","size","alpha","strokeWidth","lineType"],xy=class extends Ne{dependencies(e){return Sy.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,ii[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,ii[a],Ay(c)))}return{...e,data:r}}},Ay=e=>t=>l.isDefined(t)?e.map(t):null;function Os(e=new dr){return{diagnostics:new Dg,geomRegistry:e}}var Ms=class{constructor(e,t,r,n,a,i,o,s,c,u,d,p,m,h,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=m,this.chromeStylesCompiler=h,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??oi})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??oi;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,w(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=Dn(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return w(t,{scales:ke(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=mr(r,a);return t.coords.coordType==="polar"?_n(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:[Io(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{...or({spec:e}).pipe(({spec:r})=>({spec:w(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:w(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}}},Iy=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],oi="light",Ty=({plugins:e=[]}={})=>{const t=os(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=ff(t),i=Os(r),o=new tg(i),s=new Ps(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new Ms(i,new l.DataCompiler,new As(i),s,new $p,new Nh(i,s,n,new Dh(i,s,new Gg(n),new dm,new um(i),new vf(new Lf))),new Bf(i,o),new Hp(new im),new Nf(i),new xy,new Ah(i),new by(i),new Kg(i),new Jg(i),new Eh(i),new Ep(i))};function ks(e,t){return e.geom===t}function Ns(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Ly(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>Fs(o,s),i)}function Bs(e,...t){return t.reduce((r,n)=>Fs(r,n),e)}function Ly(e){return typeof e=="object"&&e!==null&&"type"in e}function Fs(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,zt.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 Ey(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Ey(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 wy(e){const t=e?.plugins??[],r=Cy(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Ns,pipe:Bs,plugins:t}}var Ry=e=>(t={})=>l.buildLayerInput(e,t);function Cy(e){const{geoms:t,stats:r,transforms:n}=os(e),a={};for(const s of t)a[s.type]=Ry(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 Vr="…",$s=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Vr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Vr)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Vr};var H={timeZone:"UTC"},U=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Te=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Nn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Vy=Gr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Gs=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Te(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=$n(a,i),{base:s,suffix:c}=Fn(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),Us=({locale:e,numberFormat:t,intlOptions:r})=>Te(n=>{const{base:a,suffix:i}=Fn(n,t.abbreviation),o={...$n(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),Bn=e=>Te(t=>Vy(t)),Hs=({locale:e,intlOptions:t})=>Te(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Ws=({locale:e,numberFormat:t,intlOptions:r})=>Te(n=>{const a=$n(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Fn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Dy(e);return Fn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},$n=(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}},Dy=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"},_y=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...H,...t}).format(r)),Py=({locale:e,intlOptions:t})=>U(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...H,...t}).formatToParts(r);return Oy(n.map(My))}),Ks=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...H,...t}).format(r)),zs=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{month:"long",...H,...t}).format(r)),Gn=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...H,...t}).format(r)),Un=e=>U(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Ys=({locale:e,intlOptions:t})=>U(r=>{const n=(0,uo.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...H,...t,year:void 0}).formatRange(r,n)}),qs=({locale:e,intlOptions:t})=>U(r=>{const n=(0,uo.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...H,...t}).formatRange(r,n)}),Hn=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{year:"numeric",...H,...t}).format(r)),js=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...H,...t}).format(r)),Oy=e=>e.map(t=>t.value).join(""),My=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},si=1e3,ky=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Te(a=>{const i={...Kn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Wn(a,t,i)}),Ny=({locale:e,tickValues:t,intlOptions:r})=>Te(n=>{const a={...Kn(n,t),notation:"compact",...r};return Wn(n,e,a)}),By=({locale:e,tickValues:t,intlOptions:r})=>Te(n=>{const a={...Kn(n,t),notation:"compact",...r,style:"percent"};return Wn(n,e,a)}),Wn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Xs=e=>Math.abs(e)>si?Xs(e/si):Number.isInteger(e),Fy=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Kn=(e,t)=>Xs(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Fy(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},$y=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...H,...t}).format(r)),Gy=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{month:"short",...H,...t}).format(r)),Uy=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...H,...t}).format(r)),Hy=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...H,...t}).format(r)),zn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ky(e);case"date":case"datetime":return $y(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Uy(e);case"decimal":case"integer":return Ny(e);case"duration":return Bn(e);case"month":return Gy(e);case"month_year":return Gn(e);case"percentage":return By(e);case"quarter":return Un(e);case"text":return Nn(e);case"time":return Hy(e);case"year":return Hn(e);case"lookup":return zn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Wy=.9,Ky=1/3,zy=1/4,Yy=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?qy(e):jy(e),qy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Zs(e.ticks,n),s=Xy(e.ticks,r.width),c=s*Wy;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Xr(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=Xr(r.height*Ky);return{...e,ticks:jr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},jy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Zs(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Xr(r.width*zy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:jr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Xy=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Zs=(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:$s(i.formattedLabel,r,a)})},Xr=e=>Math.max(0,Math.floor(e)),Zy=(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},Jy=({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 m=o.get(p);if(m)return m;const h=a[p],f=h?Qy(h.ticks,n(h)):[];return o.set(p,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1;Zy(s(p).map(m=>m.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},Qy=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),li=.5,At=e=>({x:0,y:0,width:e.width,height:e.height}),Yn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,It=({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,m={anchor:tv(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},h={anchor:rv(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"?m:h,b=r.valueAxis==="x"?h:m,A=ui(y,{min:g.x,max:g.x+g.width,halfExtent:c/2}),I=ui(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:A,y:I,position:ev(e,A,I,c,u)}},ci=(e,t,r,n)=>r-n>=e-li&&r+n<=t+li,ev=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||ci(e.x,e.x+e.width,t,n/2),o=e.height===0||ci(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},tv=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",rv=e=>e==="center"?"center":e==="start"?"min":"max",ui=({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},nv=(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}}},av=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=D(a),o=M(a)??R(a);if(i===null||o===null||!Je(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}=nv(o,B(a),i,e.panelRect.width,e.panelRect.height),m=It({box:d,panel:At(e.panelRect),frame:p,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:m.x,y:m.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return{labels:t,droppedCount:0}},iv={place:av,getPercentageValueStrategy:e=>e.position==="fill"?"fill":F(e.position)?"stack":"none"},ov=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:lr(e.data,e.mapping)?Yn(r):r,align:n}};function Tt(e){return e[l.VISUAL_VARIABLES.color]}function Js(e){return e[l.VISUAL_VARIABLES.alpha]}function qn(e){return e[l.VISUAL_VARIABLES.size]}function Zr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Qs(e){return e[l.VISUAL_VARIABLES.lineType]}var sv={color:Tt,alpha:Js,strokeWidth:Zr,lineType:Qs,size:qn,borderWidth:Zr},at=(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=cv(s.styles,t);return r.set(s,u),u},chromeReaders:s=>{const c=n.get(s);if(c!==void 0)return c;const u=lv(s,t);return n.set(s,u),u},explain:(s,c,u,d)=>{if(d!==void 0){const f=st(s.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=st(s.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const p=st(s.styles.overrides,c,u,void 0,t);if(p!==void 0)return{value:p.value,tier:"override",origin:p.origin};const m=el(c,u);if(m!==void 0)return{value:m,tier:"data"};const h=st(s.styles.defaults,c,u,void 0,t);return h!==void 0?{value:h.value,tier:"default",origin:h.origin}:{value:void 0,tier:"unresolved"}}}},lv=(e,t)=>{const r=(m,h)=>{const f=b=>di(m.overrides,b,h)??di(m.defaults,b,h);return{get:b=>{const A=f(b)?.declarations[b];if(A!==void 0)return pi(A,t)},getSource:b=>{const A=f(b);return A===void 0?"unresolved":A.origin.list==="builtin"?"builtin":"authored"},explain:b=>{const A=f(b),I=A?.declarations[b];return A===void 0||I===void 0?{value:void 0,source:"unresolved"}:{value:pi(I,t),source:A.origin.list==="builtin"?"builtin":"authored",origin:A.origin,select:A.select}}}},n=m=>r(e.panelBorder,h=>{const f=h.select.target==="panelBorder"?h.select.edge:void 0;return f===void 0||f===m}),a=m=>h=>r(e[m],f=>f.select.target!==m?!1:f.select.axis===void 0||f.select.axis===h),i=m=>r(e.ruleLabel,h=>h.select.target!=="ruleLabel"?!1:h.select.layer===void 0||h.select.layer===m),o=(m,h)=>r(e.dataLabel,f=>f.select.target!=="dataLabel"||f.select.role!==void 0&&f.select.role!==m?!1:f.select.position===void 0||f.select.position===h),s=m=>r(e.tooltip,h=>h.select.target==="tooltip"&&h.select.part===m),c=m=>r(e.legend,h=>h.select.target==="legend"&&h.select.part===m),u=m=>r(e.legendItem,h=>h.select.target==="legendItem"&&h.select.part===m),d=m=>r(e.headlineItem,h=>h.select.target==="headlineItem"&&h.select.part===m),p=(m,h)=>{const f=new Map;return g=>{const v=f.get(g);if(v!==void 0)return v;const y=r(e.annotation,b=>{if(b.select.target!=="annotation")return!1;const A=b.select.kind;return A!==void 0&&A!==m||b.select.part!==h?!1:b.select.annotation===void 0||b.select.annotation===g});return f.set(g,y),y}};return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:o,graph:r(e.graph,()=>!0),heading:r(e.heading,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:s(void 0),heading:s("heading"),label:s("label"),value:s("value"),primaryRow:s("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:d("number"),numberCenter:d("numberCenter"),caption:d("caption"),label:d("label"),swatch:d("swatch"),trend:d("trend"),trendUp:d("trendUp"),trendDown:d("trendDown"),trendFlat:d("trendFlat")},legend:{gap:c(void 0),popover:c("popover")},legendItem:{item:u(void 0),swatch:u("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:p("shape"),arrow:p("arrow"),differenceArrow:Object.assign(p("differenceArrow"),{label:p("differenceArrow","label")}),text:p("text"),image:p("image"),pinnedNumber:Object.assign(p("pinnedNumber"),{label:p("pinnedNumber","label")}),comment:Object.assign(p("comment"),{label:p("comment","label")})}}},di=(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}},pi=(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},cv=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=Nt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=Nt(e.defaults,n,a,i,t);if(u!==void 0)return u}const o=Nt(e.overrides,n,a,void 0,t);if(o!==void 0)return o;const s=el(n,a);return s!==void 0?s:Nt(e.defaults,n,a,void 0,t)}}),Nt=(e,t,r,n,a)=>st(e,t,r,n,a)?.value,st=(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&&uv(o,r))return{value:dv(s,a),origin:o.origin}}},uv=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),dv=(e,t)=>l.isLightDarkColor(e)?e[t]:e,el=(e,t)=>{const r=sv[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")}}},Bt=6,pv=.5,mv=e=>{const t=[];let r=0;const n=F(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=fv({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"?vv({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}):Sv(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,At(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 xv(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=Lv({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}},hv={place:mv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":F(e.position)?"stack":"absoluteGrandTotal"},fv=({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=at().geomReaders(e);for(const p of e.data){const m=rl(t,p);if(m===null)continue;const h=a(p);if(h==="")continue;const f=jn(n,"observation",h),g=Xn(m,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:h,boxes:f,bounds:g,backdropColor:d.get("color",p)})}return{entries:o,shouldRotate:!i&&s}},Xn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),tl=(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}},rl=(e,t)=>{const r=K(t),n=z(t),a=B(t),i=M(t)??R(t);return r===null||n===null||a===null||i===null?null:tl(e,r,n,a,i)},gv=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return tl(e,r,n,a,i)},yv=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Jr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},vv=e=>e.isStacked?Av({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Tv({edge:yv(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),nl=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},bv=e=>e==="panel-start"||e==="panel-end",Sv=(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=It({box:n.bounds,panel:a,frame:nl(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!bv(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+pv?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},xv=(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=At(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const m=rl(c,p);if(m===null)continue;const h=e.formatCategory(p);if(h===null||h==="")continue;const f=jn(e.measureDataLabel,"category",h),g=f[s],v=Xn(m,e.panelRect),y=d===null?null:p[d],b=l.isStrictNumericDataValue(y)&&y<0,A=It({box:v,panel:u,frame:nl(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:g.width,labelHeight:g.height}),I=f[A.position];r.push({layerId:e.layer.id,x:A.x,y:A.y,text:h,width:I.width,height:I.height,isRotated:!1,target:"category",position:A.position})}return r},Av=({bounds:e,box:t,isRotated:r})=>{const n=Jr(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"}},Iv=(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}}},Tv=({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:m,outwardSign:h,panelExtent:f}=Iv(e,t,a,i),g=Jr(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 re=m-h*(v/2+o);return{...s?{x:c,y:re}:{x:re,y:u},isRotated:!1,position:"inside"}}const I=Jr(r.outside.width,r.outside.height,n),L=(s?I.height:I.width)/2,E=m+h*(L+o);return E-L<0||E+L>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Lv=({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=Xn(gv(t,c),r),d=a(c.total),{width:p,height:m}=n("aggregate","outside",d),h=c.anchor.direction==="positive";let f,g;s?(f=h?u.x+u.width+Bt+p/2:u.x-Bt-p/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=h?u.y-Bt-m/2:u.y+u.height+Bt+m/2),i.push({layerId:e.id,x:f,y:g,text:d,width:p,height:m,isRotated:!1,target:"aggregate",position:"outside"})}return i},Ev=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Rv(e.layer);for(const a of e.layer.data){const i=D(a),o=R(a);if(i===null||o===null||!Je(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=It({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:At(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}},wv={place:Ev,getPercentageValueStrategy:()=>"none"},Rv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:lr(e.data,e.mapping)?Yn(r):r,align:n}},Cv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Dv(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=at().geomReaders(e.layer);for(const o of e.layer.data){const s=D(o),c=R(o);if(s===null||c===null||!Je(s,c))continue;const u=e.formatLabel(o);if(u==="")continue;const{width:d,height:p}=e.measureDataLabel("observation","outside",u),m=i.get("size",o)/2,h=It({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:At(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+m,alignOffset:r+m,labelWidth:d,labelHeight:p});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:u,width:d,height:p,isRotated:!1,target:"observation",position:h.position})}return{labels:t,droppedCount:0}},Vv={place:Cv,getPercentageValueStrategy:()=>"none"},Dv=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}},al=e=>{const t=K(e),r=z(e),n=B(e),a=M(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}},il=e=>{const t=al(e);if(!t)return null;const r=t.width*Gh,n=t.height*Uh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},mi=4,_v=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=at().geomReaders(e.layer);for(const n of e.layer.data){const a=il(n);if(a===null||!Tt(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+mi>c||s+mi>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}},Pv={place:_v,getPercentageValueStrategy:()=>"none"};function Zn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Jn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var Ov=" · ",Dr=2,dt=(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)},Mv=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=dt("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Dr&&t+i<=e.outerRadiusPx+Dr)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=dt("tangential",r,n,a)/t,c=Dr/t;return Math.abs(r-e.midAngle)+s<=o+c},kv=({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,hi=({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+dt("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},Nv=({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+dt("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=dt("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:Mv({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},Bv=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=at().geomReaders(e.layer);for(const m of e.layer.data){const{startAngle:h,endAngle:f}=Zn(m),{innerRadius:g,outerRadius:v}=Jn(m);if(h===null||f===null||v===null)continue;const y=e.formatLabel(m);if(y==="")continue;const b=o?e.formatCategory(m):null,A=b===null?y:`${b}${Ov}${y}`,I={startAngle:h,endAngle:f,midAngle:(h+f)/2,innerRadiusPx:(g??0)*d,outerRadiusPx:v*d};let L,E;if(r==="auto"){const T=e.measureDataLabel("observation",s,A);E={width:T.width,height:T.height},L=hi({wedge:I,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const P=c+Math.sin(L.labelAngle)*L.labelRadius,k=u-Math.cos(L.labelAngle)*L.labelRadius;if(L.position==="outside"&&!kv({x:P,y:k,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const ne=e.measureDataLabel("observation","inside",A);E={width:ne.width,height:ne.height},L=hi({wedge:I,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const T=jn(e.measureDataLabel,"observation",A),P=T[r];L=Nv({wedge:I,placement:r,justify:Yn(n),align:a,offset:i,labelWidth:P.width,labelHeight:P.height}),E=T[L.position]}const re=c+Math.sin(L.labelAngle)*L.labelRadius,Le=u-Math.cos(L.labelAngle)*L.labelRadius;t.push({layerId:e.layer.id,x:re,y:Le,text:A,width:E.width,height:E.height,isRotated:!1,target:"observation",position:L.position,...L.position==="inside"?{backdropColor:p.get("color",m)}:{}})}return{labels:t,droppedCount:0}},Fv={place:Bv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},$v=e=>{const t=_({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=_({...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)}},_=e=>{switch(e.valueFormat.type){case"currency":return Gs(e);case"date":return _y(e);case"datetime":return Py(e);case"day_month":return Ks(e);case"decimal":return Us(e);case"duration":return Bn(e);case"integer":return Hs(e);case"month":return zs(e);case"month_year":return Gn(e);case"percentage":return Ws(e);case"quarter":return Un(e);case"text":return Nn(e);case"weekly_date_range":return Ys(e);case"weekly_date_range_with_year":return qs(e);case"year":return Hn(e);case"time":return js(e);case"lookup":return $v({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Qn({layer:e,numberFormat:t,locale:r}){return _({valueFormat:dp(e),locale:r,numberFormat:t})}var Gv=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:nt(e,t),variable:r}:{read:Q,variable:l.GROUP_VARIABLES.group}},ol=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=Qn({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:zv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:Uv({layer:e,numberFormat:n,locale:o})}},Uv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Gv(e.data,e.mapping),i=_({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)}},Hv=(e,t,r)=>{switch(t){case"stack":return Wv(e);case"fill":return Kv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Wv=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(En(a,t));return s===void 0?null:s.total}},Kv=(e,t)=>{const r=t?K:B,n=t?z:M,a=ht(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}},zv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=j(e.data,e.dataLabels.labelSource),c=Hv(e,i,o),u=Yv({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=_({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&sl(e);return m=>{const h=s(m);if(h===null)return"";if(!p||!l.isStrictNumericDataValue(h))return u(h,m);const f=c(m);return f===null||f===0?u(h,m):d(h/f)}},Yv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(sl(e))return a;const s=qv(e,r,t,n,o);if(s!==null)return s}return _({valueFormat:jv(e.data,i),locale:n,numberFormat:t})},sl=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(ir(e.position,e.mapping))},qv=(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:_({valueFormat:o.valueFormat,locale:n,numberFormat:r})},jv=(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)},ea={bar:{cartesian:hv,polar:Fv},line:{cartesian:wv},point:{cartesian:Vv},area:{cartesian:iv},tile:{cartesian:Pv}},Xv=(e,t)=>ea[e]?.[t]!==void 0,Zv=({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,m=t.type;let h=0;for(const f of e){if(!f.dataLabels.showDataLabels&&!f.dataLabels.showStackTotals&&!f.dataLabels.showCategoryLabels)continue;const g=f.geom,v=ea[g]?.[m];if(v===void 0)continue;const y=ol({layer:f,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:o,formattingLocale:p,percentageValueStrategy:v.getPercentageValueStrategy(f)}),b=v.place(y);h+=b.droppedCount;for(const A of b.labels)Qv(A,m,c,u)||d.push(A)}return{labels:d,warnings:h>0?[Jv(h)]:[]}},Jv=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}}),Qv=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*eb({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=ea[s.geom]?.cartesian;if(c===void 0)continue;const u=ol({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 _r={abbreviation:"none",decimals:"auto"},ll=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return _({valueFormat:a,locale:e,numberFormat:_r,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?"-∞":_({valueFormat:{type:"percentage"},locale:e,numberFormat:_r,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${_({valueFormat:{type:"decimal"},locale:e,numberFormat:_r,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},tb=2,rb=6,nb=6,ab=15,ib=15,ob=2.5,sb=.5,lb=.25,cl=e=>{const t=e-tb,r=1+sb*t,n=1+lb*t;return{arrowStartGap:rb*r,arrowEndGap:nb*r,offsetFromHigherObservation:ab*n,arrowheadSize:ob*e,curveRadius:ib*n,strokeWidth:e}},cb=(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},ub=(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}
5
5
  L ${c.x-d*i} ${c.y}
6
6
  Q ${c.x} ${c.y} ${c.x} ${c.y+i}
7
7
  L ${u.x} ${u.y}
8
- `},$v=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x+n,y:e.y},s={x:r,y:e.y},c={x:r,y:t.y},u={x:t.x+a,y:t.y},d=t.y>e.y?1:-1;return`
8
+ `},db=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x+n,y:e.y},s={x:r,y:e.y},c={x:r,y:t.y},u={x:t.x+a,y:t.y},d=t.y>e.y?1:-1;return`
9
9
  M ${o.x} ${o.y}
10
10
  L ${s.x-i} ${s.y}
11
11
  Q ${s.x} ${s.y} ${s.x} ${s.y+d*i}
12
12
  L ${c.x} ${c.y-d*i}
13
13
  Q ${c.x} ${c.y} ${c.x-i} ${c.y}
14
14
  L ${u.x} ${u.y}
15
- `},Gv=(e,t,{arrowEndGap:r,arrowheadSize:n})=>e?`
15
+ `},pb=(e,t,{arrowEndGap:r,arrowheadSize:n})=>e?`
16
16
  M ${t.x+r+n} ${t.y-n}
17
17
  L ${t.x+r} ${t.y}
18
18
  L ${t.x+r+n} ${t.y+n}
@@ -20,4 +20,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var md=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
- `,Uv=(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},Hv=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),qs=({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=Ys(t.strokeWidth),d=Bv(o,s,c,u),p=(o?$v:Fv)(s,c,d,u),h=Gv(o,c,u),m=Uv(o,s,c,d,Hv(o,s,c),e.labelCrossPosition),f=zs({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}},si={large:1,medium:23/26,small:19/26},Wv={large:1,medium:10/12,small:10/12},Kv=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],js=e=>e.fontSize*e.lineHeight,zv=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),H=(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")}),Yv=(e,t)=>H(e.axisLabel(t),e.graph),qv=(e,t)=>{const r=e.tickLabel(t);return{...H(r,e.graph),offset:r.get("offset")}},jv=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...H(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}}},Xv=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=H(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},Zv=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:H(e.tooltip.heading,r),label:H(e.tooltip.label,r),value:H(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},Jv=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...H(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")}}},Qv=e=>{const t=e.directLabel;return{...H(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},eb=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=si[t]*n,i=Wv[t]*n,o=e.headlineItem,s=H(o.number,e.graph),c={...s,fontSize:s.fontSize*si[t]},u=o.numberCenter.get("fontSize");return{number:c,...rb(o.numberCenter)?{numberCenter:Pt(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:Pt(o.caption,o.caption.get("fontSize")*i,r),label:Pt(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:Pt(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")}}},tb=(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}},rb=e=>Kv.some(t=>e.getSource(t)!=="unresolved"),Pt=(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}}},Xs=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=js(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*nb({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!qe(o.start.x,o.start.y)||!qe(o.end.x,o.end.y))continue;const s=a(o.id),c=qs({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=Xs({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 ab={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:8,before:0},topAxisLabel:{after:8,before:0},topAxis:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16},footer:{after:0,before:16}},ib={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},ob=e=>{const t=e.padding,r=li(e.rows,t?.top??0,t?.bottom??0),n=li(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:ub(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},sb=e=>{const t=ci(e.rows,e.height),r=ci(e.cols,e.width),n=ui(t),a=ui(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=di(r,o.col,c),h=di(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,h)})}return i},li=(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;Kr(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push(lb(s));const c=cb(e,o);if(Kr(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}},lb=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Kr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,cb=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Kr(n))return n}},ub=(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},ci=(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)},ui=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},di=(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},Xe={top:0,right:0,bottom:0,left:0},Zs={outer:Xe,inner:Xe},db=(e,t,r,n=Xe,a=Zs,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=pi(ab,o),d=pi(ib,o);return ob({rows:[{name:"header",size:t.headerSize.height,gaps:u.header},{name:"topLegend",size:r.legends.top,gaps:u.topLegend},{name:"headline",size:r.headline,gaps:u.headline},{name:"topAxisLabel",size:c,gaps:u.topAxisLabel},{name:"topAxis",size:r.axes.top,gaps:u.topAxis},{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:u.bottomAxis},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:u.bottomAxisLabel},{name:"bottomLegend",size:r.legends.bottom,gaps:u.bottomLegend},{name:"footer",size:t.footerSize.height,gaps:u.footer}],cols:[{name:"leftLegend",size:r.legends.left,gaps:d.leftLegend},{name:"leftAxis",size:r.axes.left,gaps:d.leftAxis},{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:d.rightAxis},{name:"rightLegend",size:r.legends.right}],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"},...mb(r.axes),...hb(r.axesLabels,r.axes),...fb(r.legends)],containerSize:e,padding:i})},pb=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Lr(t,e.after)}:{before:Lr(t.before,e.before),after:Lr(t.after,e.after)}:e,Lr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,pi=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=pb(e[n],t[n]);return r},mb=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},hb=(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},fb=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 gb=class{constructor(e){this.outer={...Xe},this.inner={...Xe},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)))}},yb=["top","right","bottom","left"],Er=(e,t)=>{const r={};for(const n of yb){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function mi(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var zr=["large","medium","small"],vb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of zr)if(r(n)<=t)return n;return"small"},bb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:zr.indexOf(e);for(const a of zr.slice(n))if(r(a)<=t)return a;return null},Sb=({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},xb=({headline:e,containerSize:t,measurer:r})=>{if(cr(e))return 0;const n=Js(e,t.width,r);return r.measureHeadline(e.formatted,n).height},Ab=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(cr(e)){const s=Ib(t.panel,e.innerRadius),c=bb({size:e.size,availableWidth:s.width,measureStripWidth:Qs(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=Js(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=Sb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},cr=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Ib=(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}},Js=(e,t,r)=>vb({size:e.size,availableWidth:t,measureStripWidth:Qs(e,r)}),Qs=(e,t)=>r=>t.measureHeadline(e.formatted,r,cr(e)).width,$e={x:0,y:0,width:0,height:0},Tb="0000",Lb=3,Eb=e=>e.plot.y+e.plot.height-e.panel.y,wb=class{constructor(e){this.measurer=e}compile(e){return er({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Zs,panelBorder:e.panelBorder??Xe,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:Rb(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>hi(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,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>hi(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,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,gaps: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,gaps:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:Eb(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new gb(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of nb({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 Vv({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 mi(i.inner,n.inner)&&mi(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,gaps:p}){let h=t,m=o;for(let f=0;f<Lb;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,gaps: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?fi(r,a,0,0):fi(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=B(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:Tb}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=B(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=wy({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?Ay({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,gaps:c}){const u=sb(db(r,n,this.measureGuides(e,t,o,r),i,a,s,c));return{header:u.get("header")??$e,headline:u.get("headline")??$e,footer:u.get("footer")??$e,plot:u.get("plot")??$e,panelFrame:u.get("panelFrame")??$e,panel:u.get("panel")??$e,axes:Er(u,"Axis"),axisLabels:Er(u,"AxisLabel"),legends:Er(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:xb({headline:e,containerSize:t,measurer:this.measurer})}},hi=e=>e==="left"||e==="right",fi=(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}}},Rb=(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=Fn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},Vb=(e=[])=>{const t=Cb(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:un(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?po(r,t.get(r.geom)):null}},Cb=e=>{const t=new ir;for(const r of e){const n=An(r);n instanceof le&&t.register(n.type,n)}return t};function _b(e){return e}function ae(e){return 1-e}var Te=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,zt=(e,t)=>{const r=tr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+ae(e.y)*r.height}},Db=(e,t)=>{const r=tr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(ae(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},Pb=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}=Yr(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=lt(t,e.defer.align),{x:n,y:a}=Ob(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}=Yr(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:kb(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:gi(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=eo(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:yi(this.toPanelPoint(r))}case"differenceArrow":return gi(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return yi(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Ca(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Ca(e,this.panelRect),r=tr(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}}},Yr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Ob=(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}=Yr({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}},kb=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),gi=(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)}),yi=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},Mb=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!Nb(t))return t;const o=new Pb(t,r,n),s={...t,shapes:rt(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:rt(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:rt(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:rt(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:rt(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},rt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Nb=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),Bb=800,bi=400,Fb=.75,$b=.875,Gb=4,Ub=e=>Math.max(1,(e-bi)/(Bb-bi)+1),Hb=(e,t)=>{const r=Ub(t),n=e*Gb;return{strokeWidth:Math.min(e,e*Fb*r),arrowheadLength:Math.min(n,n*$b*r)}},Ot=Math.PI/4,qr=1.5,Wb=2,Kb=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,Si=(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-Ot)} ${o-r*Math.sin(s-Ot)} M ${i} ${o} L ${i-r*Math.cos(s+Ot)} ${o-r*Math.sin(s+Ot)}`},zb=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*Wb}`:`${t*qr} ${t*qr*2}`,Yb=(e,t,r)=>e==="dashed"&&r?t*qr:0,qb=64,jb=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:zt(e.start,a),end:zt(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=Hb(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=Xb(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:Kb(i),startArrowheadPath:d?Si("start",i,u):"",endArrowheadPath:p?Si("end",i,u):"",strokeWidth:o,dashArray:zb(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:Yb(t.lineType,o,d),arrowheadExtent:h}},Xb=(e,t)=>Math.min(e,t*e/qb);function Zb(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=Jb(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 Jb(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 el=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),Qb=0,eS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:el(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:Qb})),tS=9,rS=8,nS=2,tl=e=>typeof e=="string"?e:rl(e),rl=e=>e.text!==void 0?e.text:e.content?e.content.map(rl).join(""):"",xi={top:"bottom",bottom:"top",right:"left",left:"right"};function aS(e,t,r){return r.type==="polar"?sS(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function jr(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 Ai(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function iS(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 oS(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 sS(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,xi[o],s,xi[s]]}function lS(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 Ii(p,"pinned-number",h,o(d),i,n)}),...r.map(({id:d,at:p,content:h})=>Ii(d,"comment",p,tl(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(Ti(n,d,"top"));continue}const p=Ti(n,d,uS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Ii(e,t,r,n,a,i){const o=zt(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:cS(o,i)}}function cS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function uS(e,t,r,n){const a=aS(t.anchorPx,e,r);for(const i of a){const o=jr(t.anchorPx,i,t.mini);if(Ai(o,e)&&!n.some(s=>oS(o,s)))return i}for(const i of a)if(Ai(jr(t.anchorPx,i,t.mini),e))return i;return"top"}function Ti(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:iS(e,jr(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var dS=(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,pS=100,mS=({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>pS)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}},nl=(e,t)=>Yt(e,t,hS(e),{allowNull:!1}),Yt=(e,t,r,{allowNull:n})=>{const a=ho(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}},hS=e=>{const t=cn(e)?Pe(e.data,e.mapping):[],r=ln(e),n=r===null?t:[...t,r],a=Ve(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},qn=e=>e!=="data-point",al=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(he(t.predicate,e.data).length>0)return[];const n=me(t.predicate,dt(e,r));return qn(t.scope)?gS(e,n,t.scope):fS(e,n)},fS=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},gS=(e,t,r)=>{const n=l.extractVariableName(e.mapping.x),a=[],i=new Set;for(const s of e.data){const c=it(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},yS=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=bS(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return vS(o,e,t,n)?o:null},vS=(e,t,r,n)=>al({layer:t,target:e,parsingLocale:n}).includes(r),bS=(e,t,r)=>{switch(r){case"data-point":return Li(e,t);case"series":{const n=Pe(e.data,e.mapping);return n.length===0?Li(e,t):Yt(e,t,n,{allowNull:!0})}case"x-value":{const n=l.readMainAxisVariable(e.mapping);return n===""?null:Yt(e,t,[n],{allowNull:!0})}}},Li=(e,t)=>{const r=e.identityKey;if(typeof r=="object")return Yt(e,t,[r.variable],{allowNull:!0});switch(r){case"index":return null;case"x-group":case"x-y":return nl(e,t)}},jn=(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},SS=(e,t)=>{for(const r of t)if(jn(e,r.shape))return r;return null},xS=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},AS=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>IS(r,t[n])),IS=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&TS(e.shape,t.shape)&&LS(e.tooltip,t.tooltip),TS=(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},LS=(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},ES=100,wS=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:ES}),RS=(e,t)=>jn(e,{kind:"circle",center:t.center,radius:t.radius}),VS=(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&&CS(e.target,t.target),CS=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,_S=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=dt(e,n),i=DS(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||he(o.predicate,e.data).length>0)return!1;const s=me(o.predicate,a);return s(r)?!0:qn(o.scope)&&i(o.scope).some(s)})},DS=(e,t)=>{const r=l.extractVariableName(e.mapping.x),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=it(a,t,r),s=[];for(const c of e.data)it(a,c,r)===o&&s.push(c);return n.set(a,s),s}},Nt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=ut(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?PS(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=>He(h,m)))return{anchor:h,observation:p,observationIndex:d}}return null},il=(e,t)=>{const r=mo(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},He=(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),PS=(e,t)=>(e%t+t)%t,ol=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=Ve(e),a=il(e,t),i=e.data.getAt(a);if(i===null)return null;const o=J(i),s=h=>l.areDataValuesEqual(J(h),o),c=[t],u=Nt({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=Nt({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=Nt({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},OS=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=ut(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=ol({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>kS(s,o)))return o}}return null},kS=(e,t)=>He(e.start,t.start)&&He(e.end,t.end)||He(e.start,t.end)&&He(e.end,t.start),MS=(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}},NS=({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=vo(t,r,c);if(u===null)return null;const d=ut(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},BS=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=Ve(e),s=il(e,t),c=e.data.getAt(s);if(c===null)return null;const u=FS(c),d=n==="main"?u:m=>!u(m)&&l.areDataValuesEqual(m[o]??null,t.anchorValue),p=Nt({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}},FS=e=>{const t=J(e);return r=>l.areDataValuesEqual(J(r),t)};function $S({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=D({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var GS=({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"?US(e,o,r):HS(e,t,o,r,i)},US=(e,t,r)=>({kind:"grandTotal",value:D({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),HS=(e,t,r,n,a)=>{const i=D({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=D({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=D({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=Fn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:YS(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:zS(s.caption,d),comparison:WS(s.comparison,d,i,a)}})}},WS=(e,t,r,n)=>e===null?null:{direction:KS(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},KS=e=>e>0?"up":e<0?"down":"flat",zS=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,YS=(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}},qS=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>jS(i,a,t))},jS=(e,t,r)=>({...e,items:e.items.map(n=>{const a=D({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function Xn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function XS(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var ZS=({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?sn:Qe)(r.data,r.mapping)(a);return o===null?null:D({valueFormat:Xn(e,i?fe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},JS=4,QS=4,ex=12,tx=4,rx=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:wr([kt("value",r??"–"),kt("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:ox(a),segments:wr([ax(a),ix(a),kt("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:wr([nx(i,t),kt("label",o)])}].filter(s=>s.segments.length>0)},kt=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},nx=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},ax=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},ix=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},ox=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}`}},wr=e=>e.filter(t=>t!==null),ur=e=>e==="catmull-rom"?Ee.curveCatmullRom:Ee.curveLinear,sx=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},lx=(e,t)=>{const r=ur(t.interpolate),n=(0,Ee.area)().curve(r),a=(0,Ee.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ae(R(c)??0),o=c=>W(c)??0,s=c=>K(c)??_(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>_(c)??0,o=c=>ae(M(c)??0),s=c=>ae(O(c)??R(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>_(o)!==null&&R(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},cx=(e,t)=>t!=="connect"?e:e.filter(r=>_(r)!==null&&R(r)!==null),Zn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},Jn=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return Zn[e.borderRadius??"sm"]},ux=e=>{const t=Jn(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},dx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),sl=(e,t)=>{const r=W(t),n=K(t),a=M(t),i=O(t)??R(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}},ll=(e,t)=>e==="x"?`${Z(t.x)}-${Z(t.width)}`:`${Z(t.y)}-${Z(t.height)}`,px=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}},mx=e=>{const t=(0,Ee.line)().x(r=>_(r)??0).y(r=>ae(R(r)??0)).curve(ur(e.interpolate));return e.missingValues==="gap"&&t.defined(cl),t},hx=e=>{const t=(0,Ee.area)().x(r=>_(r)??0).y0(()=>1).y1(r=>ae(R(r)??0)).curve(ur(e.interpolate));return e.missingValues==="gap"&&t.defined(cl),t},fx=(e,t)=>t!=="connect"?e:e.filter(r=>_(r)!==null&&R(r)!==null),cl=e=>_(e)!==null&&R(e)!==null,ul=(0,Ee.arc)().cornerRadius(e=>e.cornerRadius??0);ul.digits(8);var gx=200,yx=e=>ul(e)??void 0,vx=(e,t)=>e==="full"?Math.max(0,t)/2:Zn[e??"sm"]/gx,dl=(e,t)=>e==="x"?`${Z(t.startAngle)}-${Z(t.endAngle)}`:e==="y"?`${Z(t.innerRadius)}-${Z(t.outerRadius)}`:"sweep",bx=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}},Sx=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],dr=(e,t,r)=>{const n=Qe(e,t);return a=>{const i=J(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},xx=(e,t,r)=>{const n=Qe(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},Ax=(e,t,r)=>{const n=Qe(e,t),a=sn(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}`}},Ix=()=>(e,t)=>bt(e)??`default-${t}`,Ei=2,Qn=(e,t,r,n)=>{const a=e.get("alpha",r);if(!Ss(t,"bar"))return{alpha:a};const i=n.width-Ei,o=n.height-Ei,s=Jn({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 ea(e,t,r){return Math.hypot(e*r,t)}function qt(e,t,r){return e<t?t-e:e>r?e-r:0}function ve(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 Tx(e,t,r,n){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const i=a.find(t.x*r,t.y,n??void 0),o=e.points[i];return o?{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,observationIndex:o.observationIndex,x:o.x,y:o.y,observation:o.observation},index:e,distance:ea(o.x-t.x,o.y-t.y,r)}:null}function Lx(e,t){if(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 pl(e,t){return ta(e.buckets,t,r=>r.main)}function Ex(e,t){return ta(e.bands,t,r=>r.bandCenter)}function ml(e,t){return ta(e.columns,t,r=>r.mainMid)}function ta(e,t,r){if(e.length===0)return null;let n=0,a=e.length;for(;n<a;){const s=n+a>>>1,c=e[s];c&&r(c)<t?n=s+1:a=s}const i=e[n-1],o=e[n];return i?o&&Math.abs(r(o)-t)<Math.abs(r(i)-t)?o:i:o??null}function wx(e,t){return{group:Rx(e),related:Dx(e,t)}}function Rx(e){switch(e.kind){case"buckets":{const t=e.match.index;return N(t.position)?Vx(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return N(t.position)?Cx(t.layerId,r,n.pointIndex):_x(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function Vx(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 Cx(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(ra(e,a));return n}function _x(e,t,r,n){const a=e.find(o=>o.columns.includes(r));if(!a)return[];const i=[];for(const o of a.columns)for(const s of o.rects)s.pointIndex!==n&&i.push(ra(t,s));return i}function Dx(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||Ox(r,i,e.match.hit);continue}e.kind==="buckets"&&(N(i.position)||i.kind==="buckets"&&Px(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function Px(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Bt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function Ox(e,t,r){switch(t.kind){case"buckets":{const n=pl(t,Ye(t.mainAxis,r));if(!n)return;const a=Bt(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=Ex(t,Ye(t.mainAxis,r));if(!n)return;const a=Bt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(ra(t.layerId,o));return}case"points":{const n=Lx(t,r);if(!n)return;Bt(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 Bt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function ra(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 hl(e,t,r){const{columns:n,bands:a}=kx(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function kx(e,t){const r=Mx(e,t);r.sort((s,c)=>s.mainMid-c.mainMid);const n=new Map,a=new Map;for(const s of r){const c=Z(s.mainMid);let u=n.get(c);if(!u){u={mainMid:s.mainMid,rects:[]},n.set(c,u);const d=Z(s.bandCenter);let p=a.get(d);p||(p={bandCenter:s.bandCenter,columns:[]},a.set(d,p)),p.columns.push(u)}u.rects.push(s.entry)}const i=[...n.values()].sort((s,c)=>s.mainMid-c.mainMid),o=[...a.values()].sort((s,c)=>s.bandCenter-c.bandCenter);for(const s of o)s.columns.sort((c,u)=>c.mainMid-u.mainMid);return{columns:i,bands:o}}function Mx(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 Nx=1e-9;function fl(e,t,r){const n=Bx(e,t);n.sort((i,o)=>i.main-o.main);const a=[];for(const i of n){const o=a[a.length-1];o&&Math.abs(o.main-i.main)<=Nx?o.entries.push(i.entry):a.push({main:i.main,entries:[i.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:a}}function Bx(e,t){const r=e.data;if(r.size()===0)return[];const n=r.hasVariable(l.POSITION_VARIABLES.x),a=r.hasVariable(l.POSITION_VARIABLES.y);if(!n||!a)return[];const i=r.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),s=t==="y",c=s?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,u=s?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,d=N(e.position),p=d?r.getValues(c,{type:"numeric"}):null,h=d?r.getValues(u,{type:"numeric"}):null,m=r.hasVariable(l.GROUP_VARIABLES.group)?r.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,f=[];let g=0;for(const v of r){const y=i[g],b=o[g];if(!l.isDefined(y)||!l.isDefined(b)){g+=1;continue}const A=m?.[g]??null,I=s?b:y;if(d){const T=p?.[g],E=h?.[g];if(!l.isDefined(T)||!l.isDefined(E)){g+=1;continue}const ee=s?E:y,be=s?b:E;f.push({main:I,entry:{isStacked:d,pointIndex:g,x:ee,y:be,stackMin:T,stackMax:E,groupKey:A,observation:v}})}else f.push({main:I,entry:{isStacked:d,pointIndex:g,x:y,y:b,groupKey:A,observation:v}});g+=1}return f}function gl(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:Fx(e,t)}}function Fx(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&&!bt(p)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:m,yMin:f,yMax:g,observation:p}),d++}return u}function Xr(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function $x(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:vl(e),delaunay:null,delaunayAspectRatio:null};return yl(r,t),r}function Gx(e){const t=vl(e).map(r=>{const n=at(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,delaunay:null,delaunayAspectRatio:null}}function yl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Sd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function vl(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 bl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:Ux(e)}}function Sl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function Ux(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 wi(e,t,r){return t.type==="polar"?Hx(e,t.bandAxis):Wx(e,t.mainAxis,r)}function Hx(e,t){switch(e.spatialKind){case"points":return Gx(e);case"buckets":return fl(e,"x","polar");case"rects":return t===null?gl(e,"polar"):hl(e,t,"polar");case"cells":return Xr(e);case"noop":return Xr(e);case"render-hit-test":return bl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function Wx(e,t,r){switch(e.spatialKind){case"points":return $x(e,r);case"buckets":return fl(e,t,"cartesian");case"rects":return hl(e,t,"cartesian");case"cells":return gl(e,"cartesian");case"noop":return Xr(e);case"render-hit-test":return bl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function Kx(e,t,r){if(e.columns.length===0)return null;const n=ml(e,Ye(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=N(e.position)?zx(a,t,e.mainAxis):Yx(a,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:xl(i,t,r)}}function zx(e,t,r){const n=rr(r,t);return ve(e,i=>qx(i,r,n),{shortCircuitOnZero:!0})}function Yx(e,t,r){return ve(e,a=>xl(a,t,r))}function xl(e,t,r){return ea(qt(t.x,e.xMin,e.xMax),qt(t.y,e.yMin,e.yMax),r)}function qx(e,t,r){return qt(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function jx(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=Nd(e.mainAxis,t),i=pl(e,n),o=i?.entries??[];if(!i||!l.isNonEmptyArray(o))return null;const s=Al(o,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation},index:e,bucket:i,distance:ea(s.x-t.x,s.y-t.y,r)}}function Al(e,t,r){return ve(e,a=>Math.abs(rr(r,a)-t))}function Xx(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};return null}function Zx(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Jt(t,r),i=e.mainAxis==="x",o=i?Jx(e.columns,n):ml(e,a),s=o?.rects??[];if(!o||!l.isNonEmptyArray(s))return null;const c=i?Qx(s,a):eA(s,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:(c.xMin+c.xMax)/2,y:(c.yMin+c.yMax)/2,observation:c.observation},index:e,column:o,distance:0}}function Jx(e,t){return l.isNonEmptyArray(e)?ve(e,r=>Ut(t,r.mainMid)):null}function Qx(e,t){return ve(e,r=>qt(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function eA(e,t){return ve(e,r=>tn(t,r.xMin,r.xMax)?0:Math.min(Ut(t,r.xMin),Ut(t,r.xMax)),{shortCircuitOnZero:!0})}function tA(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Jt(t,r),i=rA(e.buckets,n),o=i?.entries??[];if(!i||!l.isNonEmptyArray(o))return null;const s=Al(o,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation},index:e,bucket:i,distance:0}}function rA(e,t){return l.isNonEmptyArray(e)?ve(e,r=>Ut(r.main,t)):null}function nA(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=Jt(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&tn(n,i.xMin,i.xMax))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};return null}function aA(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=rn(t,r),i=ve(e.points,o=>Ri(o,n,a));return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,observationIndex:i.observationIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:Math.sqrt(Ri(i,n,a))}}function Ri(e,t,r){const n=e.unitX??at(e.x,e.y).x,a=e.unitY??at(e.x,e.y).y,i=n-t,o=a-r;return i*i+o*o}var iA=.05;function oA({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a}){const i={match:null,distance:Number.POSITIVE_INFINITY},o={match:null,distance:Number.POSITIVE_INFINITY};for(const s of e){if(s.kind==="render-hit-test"){const u=uA(s,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(s.projection==="polar"){const u=cA(s,t,r);if(u)return u;continue}const c=lA({layer:s,cursor:t,aspectRatio:r,warmStarts:n});if(c){if(c.kind==="banded"||c.kind==="enclosure"){const u=c.kind==="banded"?c.match.distance:0;u<i.distance&&(i.match=c,i.distance=u);continue}c.match.distance<o.distance&&(o.match=c,o.distance=c.match.distance)}}return sA({containment:i,continuous:o})}function sA({containment:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+iA?t.match:e.match:e.match??t.match}function lA({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=jx(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=Kx(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=Tx(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"enclosure":{const a=Xx(e,t);return a?{kind:"enclosure",match:a}:null}case"noop":return null}}function cA(e,t,r){switch(e.kind){case"enclosure":{const n=nA(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=aA(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=tA(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=Zx(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function uA(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:Sl(e.layerId,i)}:null}var te={primary:null,group:[],related:new Map},dA=1,pA=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=dA,this.warmStarts=new Map,this.cachedState=te,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=te,this.layerIndexes=e.map(r=>wi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>Vi(r,t)),this.nonInteractiveLayerIds=Ci(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=Vi(i,t);if(o!==void 0&&mA(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push(wi(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=Ci(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&yl(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return te;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(s=>!this.nonInteractiveLayerIds.has(s.layerId)),r=oA({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),te;const n=r.match.hit;this.warmStarts.set(n.layerId,n.pointIndex);const a=`${n.layerId}:${n.pointIndex}`;if(this.cachedKey===a)return this.cachedState;const{group:i,related:o}=wx(r,t);return this.cachedKey=a,this.cachedState={primary:n,group:i,related: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 te;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return te;const n=r.byKey.get(t);if(!n)return te;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Sl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=te,this.cachedByKeyId=null,this.cachedByKeyState=te}};function Vi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Ci(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function mA(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var hA=Math.PI*2;function fA(e,t){const r=Ye(e.mainAxis,t);if(e.mainAxis==="y"){const a=Te(ae(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=Te(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function gA(e,t,r){const n=e.mainAxis==="y"?R(r.observation):_(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Tl(r):Il(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:Te(ae(n+o)),width:"100%",height:Te(i)}:{x:Te(n-o),y:0,width:Te(i),height:"100%"}}function yA(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=W(t.observation),i=K(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=M(t.observation),n=O(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+hA,innerRadius:r,outerRadius:n}}function Il(e){const t=W(e.observation),r=K(e.observation);return t===null||r===null?null:r-t}function Tl(e){const t=M(e.observation),r=O(e.observation);return t===null||r===null?null:r-t}function vA(e){return e.observationIndex??e.pointIndex}var pr=.5,bA=.3,SA=.4,xA=10,AA=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?TA(e,t,r,n):LA(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?RA(e,t,n):e.spatialKind==="cells"?wA(e,n):e.spatialKind==="points"?EA(e,n):null,IA=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},TA=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:pr*n.durationScale,baseline:VA(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?CA(e,t.mainAxis,n):{}}),LA=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:pr*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?PA(e,t,r):{}}},EA=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:pr*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?_A(e,t):{}}),wA=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:bA*t.durationScale}),RA=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:pr*r.durationScale,axis:t.mainAxis}),VA=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[fe(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},CA=(e,t,r)=>{const n=dr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=sl(t,i);if(!o)continue;const s=ll(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 na([...a.values()],r)},_A=(e,t)=>{const r=dr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=DA(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return na(n,t)},DA=(e,t)=>{if(t==="main-axis")return _(e);const r=Gn(e)??_(e);return r===null?null:t==="value-descending"?-r:r},PA=(e,t,r)=>{const n=dr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=Wn(i),{innerRadius:c,outerRadius:u}=Kn(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 na([...a.values()],r)},na=(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/xA),i=Math.ceil(n.length/a),o=SA*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},Ge=["top","right","bottom","left"],_i={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},OA={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},kA={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},MA=(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]=kA[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=BA(t,a),s=FA(t,a,i);return $A(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:GA(c,o,s,i)}))},NA=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),BA=(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}}},FA=(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")}}}},$A=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(Ge.indexOf(o)+s+Ge.length)%Ge.length;return Ge[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=Ge.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Ge],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}})},GA=(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=_i[s];if(!e.isClosed&&n(u)){const p=t[u],h=i(p),m=UA(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=_i[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=OA[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},UA=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),HA=/^(?:https?:|mailto:)/i,WA=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:HA.test(t)},KA=({locale:e,intlOptions:t})=>$(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...U,...t}).format(r)),zA=({locale:e,intlOptions:t})=>$(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,...U,...t}).format(r)}),jt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ls(e);case"date":return KA(e);case"datetime":return zA(e);case"day_month":return Vs(e);case"decimal":return Es(e);case"duration":return _n(e);case"integer":return ws(e);case"month":return Cs(e);case"month_year":return On(e);case"percentage":return Rs(e);case"quarter":return kn(e);case"text":return Cn(e);case"time":return Ps(e);case"weekly_date_range":return _s(e);case"weekly_date_range_with_year":return Ds(e);case"year":return Mn(e);case"lookup":return jt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Ll={width:12,height:12},YA=({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=qA(u,d);return{header:m===null?jA({layers:e,coordSystem:t,guides:n,primary:p,locale:h,numberFormat:a}):null,rows:XA({layers:e,scales:r,guides:n,hover:o,locale:h,numberFormat:a,colorScheme:s}),comment:m}};function qA(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function jA(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=Xn(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)?jt({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function XA(e){const t=[],r=e.scales.color??null,n=et({colorScheme:e.colorScheme}),a=eI({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=JA(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...ZA(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=ro(i.data,i.mapping),u=QA(o,i,r,c),d=zn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=tI(e.guides,i),h=ct(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=Qn(f,i,g.observation,Ll),I=m&&v!==null?a(v):p,T=h(g.observation),E=T===null?"":d(T,g.observation);t.push({swatchColor:y,geom:i.geom,swatchLineType:b,swatchAlpha:A.alpha,swatchCornerRadius:A.cornerRadiusPx,label:I,value:E,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function ZA(e,t,r,n,a){const i=Qn(n,e,t.observation,Ll);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=Y(e.data,s)(t.observation),d=D({valueFormat:dn(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??ar(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function JA(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 QA(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 eI({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:jt({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=jt({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 tI(e,t){return ar(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function rI(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function nI(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var aI=(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")}},iI=(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")}},oI=(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:{...H(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")}}},sI=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...H(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")}},lI=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},cI=(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:{...H(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")}}},uI=e=>e.borderWidth>0?e.borderColor??e.color:void 0,dI=e=>({edges:{top:We(e.panelBorder("top")),right:We(e.panelBorder("right")),bottom:We(e.panelBorder("bottom")),left:We(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),pI=(e,t)=>We(e.gridLine(t)),mI=(e,t)=>{const r=e.tickLine(t);return{...We(r),length:r.get("length")}},hI=e=>e.heading.get("fontFamily")??e.graph.get("fontFamily"),fI=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")}},gI=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}},yI=e=>{const t=e.legend.popover;return{gap:e.legend.gap.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")}}},vI=e=>({gap:e.headline.get("gap")}),bI=e=>({color:e.hoverGuide.get("color"),background:e.hoverGuide.get("background")}),SI=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},We=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),aa=["sticker","pinnedNumber","comment","image"],xI=e=>aa.includes(e),ia=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?II(e.annotation.at):null;default:return null}},El=(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),wl=(e,t,r=AI)=>{const n=r(t);for(const a of aa){const i=gt(e,a),o=i.findIndex(c=>{const u=ia({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return El(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},AI=e=>({...e,anchorValue:Rr(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Rr(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Rr(e.crossValue)}}),Rr=e=>l.readISOInstant(e)??e,II=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function TI(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var LI=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&oa(r.predicate,t.predicate))??null,oa=(e,t)=>"and"in e?"and"in t&&Di(e.and,t.and):"or"in e?"or"in t&&Di(e.or,t.or):"not"in e?"not"in t&&oa(e.not,t.not):EI(t)&&e.variable===t.variable&&wI(e,t),EI=e=>"variable"in e,Di=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&oa(r,a)}),wI=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Pi(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&&Pi(e.range,t.range),Pi=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),RI={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},VI=e=>Object.hasOwn(RI,e);function CI(e){return{type:"mapping",mapping:e}}var St=(e,t)=>"and"in e?"and"in t&&Oi(e.and,t.and):"or"in e?"or"in t&&Oi(e.or,t.or):"not"in e?"not"in t&&St(e.not,t.not):_I(t)&&e.variable===t.variable&&DI(e,t),_I=e=>"variable"in e,Oi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&St(r,a)}),DI=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ki(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&&ki(e.range,t.range),ki=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),Rl=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)))),Vl=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),Cl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function _l(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(PI),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function PI(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?OI(r):r}function OI(e){return{...e,palette:kI(e.palette),overrides:MI(e.overrides)}}function kI(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function MI(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var xt=(e,t)=>{const r=sa(e,t);return r===-1?void 0:e[r]},sa=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&mr(n,t))return r}return-1},mr=(e,t)=>NI(e.select,t.select)&&e.when?.state===t.when?.state&&BI(e.when?.where,t.when?.where),Dl=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>FI(e[r],t[r])),Le=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),la=e=>e.select.target==="geom",At=(e,t)=>{const r=xt(e,t);if(!(r===void 0||!la(r)))return r.declarations},NI=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},BI=(e,t)=>e===void 0||t===void 0?e===t:St(e,t),FI=(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??F(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function Ze(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>Ze(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=>Ze(e[a],t[a]))}return!1}var ca=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=ft(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:w(e,{annotations:ls(e.annotations,t)}),revert:new ua({kind:r,annotation:a,index:n},this.metadata)}}},$I={type:"remove-annotation",deserialize:(e,t)=>new ca(e,t)},ua=class Pl{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??F()},...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(!vg(r)||ft(t.annotations,n.id))return null;const i=UI(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:ls(t.annotations,i),s=gt(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:w(t,{annotations:wn(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new ca({id:n.id},this.metadata):new Pl({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},GI={type:"add-annotation",deserialize:(e,t)=>new ua({kind:e.kind,annotation:e.annotation,index:e.index},t)},UI=(e,t)=>{const r=ia(t);return r===null?null:wl(e,r)},HI=(e,t)=>{const r=da(e);return r===null?null:Ol(r.points,t)},WI=e=>da(e)!==null,KI=(e,t)=>{const r=da(e);if(r===null)return null;const n=Ol(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},da=e=>{const t=YI[e.kind];return t===null?null:t(e.annotation)},Mi=(e,t)=>e.anchorType!=="panel"?null:{points:[Zr(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Ni=(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})},zI=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[Zr(e,e.offset),Zr(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}})},YI={text:e=>Mi(e.at,t=>({at:t})),sticker:e=>Mi(e.at,t=>({at:t})),shape:e=>Ni(e.region,t=>({region:t})),image:e=>Ni(e.region,t=>({region:t})),arrow:e=>zI(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},Zr=(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)},Ol=(e,t)=>({x:Bi(e.map(r=>r.x),t.x),y:Bi(e.map(r=>r.y),t.y)}),Bi=(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,Ke.default)(t,r,n)},kl=(e,t,r)=>{const n=t.annotation;if(!XI(n,r))return null;const a=gt(e.annotations,t.kind),i=qI(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:w(e,{annotations:wn(e.annotations,t.kind,o)}),inverse:jI(n,r)}},qI=(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)))},jI=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},XI=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),pa=class Ml{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=ft(t.annotations,n);if(i===null||i.kind!==r)return null;const o=kl(t,i,a);return o===null?null:{spec:o.spec,revert:new Ml({kind:r,id:n,patch:o.inverse},this.metadata)}}},ZI={type:"update-annotation",deserialize:(e,t)=>new pa(e,t)},Nl=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=ft(e.annotations,this.params.id);if(t===null)return null;const r=KI(t,this.params.translation);if(r===null)return null;const n=kl(e,t,r);return n===null?null:{spec:n.spec,revert:new pa({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},JI={type:"move-annotation",deserialize:(e,t)=>new Nl(e,t)},ce=class Ft{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=sa(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new Ft({list:r,rule:s,index:o},this.metadata),g=i.filter(v=>!mr(v,n));return{spec:Vr(t,r,g),revert:f}}if(s!==void 0){if(Dl(s.declarations,c))return null;const f={...s,declarations:c},g=new Ft({list:r,rule:s,index:o},this.metadata),v=i.map(y=>y===s?f:y);return{spec:Vr(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 Ft({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:Vr(t,r,h),revert:m}}},QI=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."})},eT={type:"set-style-rule",deserialize:(e,t)=>(QI(e),new ce(e,t))},Vr=(e,t,r)=>w(e,{styles:{...e.styles,[t]:r}}),tT={type:"set-difference-arrow-style",deserialize:(e,t)=>new Bl(e,t)},Bl=class Fl{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=xt(s.styles.overrides,d),h=new ce({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 Fl(c,this.metadata)}}},rT=["cartesian","polar","flip"],z=new ir,$l=e=>z.has(e)?z.get(e):null,Gl=new l.TransformRegistry,nT=new ys(Gl),hr=e=>{const t=e.transforms.every(r=>Gl.has(r.transformType));return e.transforms.length===0||!t?e.data:nT.compile({data:e.data,transforms:e.transforms})};function ma(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 It(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function Tt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:w(e,{scales:so(e.scales,n,r)})}function Lt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function Jr(e,t,r){const n=sr(Tn(vs(z),{data:hr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Ln(n):n}var Ul=class Hl{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:fT(t)})}apply(t){const r="previous"in this.params?this.params.previous:gT(t,this.params);if(r===null)return null;const n=w(t,r);return n===t?null:{spec:n,revert:new Hl({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},aT={type:"set-chart-type",deserialize:(e,t)=>new Ul(e,t)},Wl={type:"sum"},iT={type:"identity"},oT=["bar","line","area","point","tile"],ha="tile",sT=["y","color"],lT=Object.values(l.LAYER_LABEL_VARIABLES),cT={coordType:"cartesian",geom:ha,position:"identity"},Et=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),uT=e=>{const t=e.layers.filter(ie),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=zl(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}},dT=e=>{if(!e)return!1;const t=e.layers.filter(ie);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:Yl(e,r)?ql(e,r).length>=1:fr(e,e.data.groupVariableNamesByType().numeric).length>=2},pT=e=>e?ec(e,cT)!==null:!1,mT=e=>Kl(e)?.at(-1)?.id??null,Kl=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(ie);return zl(t)===null?null:t},zl=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 hT(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)},hT=e=>e.some(t=>t.yScaleType==="secondary"||Xt(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,fT=e=>"previous"in e?"Restore the previous chart type":Et(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,gT=(e,t)=>{const r=ec(e,t);if(r===null)return null;const n=Et(t)?vT(r,t):yT(r,t,e);return n===null||r===e?n:{...n,scales:_T({...e,...n},n.scales)}},yT=(e,t,r)=>{if(Et(t)||!DT(t))return null;const n={...e,layers:sc(e.layers)},a=kT(n.layers.filter(ie),t),i=cc(n.coords,t),o=Jl(n,t),s=oc({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:ma(uc(r,s,i.coordType),s),mapping:o}},vT=(e,t)=>{const r=xT(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=MT(r.filter(ie),t.comboType),i=cc(n.coords,t),o=Jl(n,t),s=oc({...n,mapping:o},t,a,o!==n.mapping),c=bT(e)?s:ST(s);return{coords:i,layers:c,scales:ma(uc(e,c,i.coordType),c),mapping:o}},bT=e=>Kl(e)!==null,ST=e=>{const t=e.filter(ie).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},xT=(e,t)=>{const r=e.layers.filter(ie);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:Yl(e,n)?AT(e,n):IT(e,n,t)},Yl=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},AT=(e,t)=>{const[r]=ql(e,t);if(r===void 0)return null;const n=ke(z,e.mapping,e.coords.coordType,{type:"layer",id:jl(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:Wl,...Zl(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},fr=(e,t)=>{const r=wt(e);return t.filter(n=>n!==r)},ql=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return fr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},wt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),IT=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=fr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,wt(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=TT(t,Fi(a.slice(0,-1),o,s)),u=ke(z,e.mapping,e.coords.coordType,{type:"layer",id:jl(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...Fi([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},jl=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},Fi=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?Zl(n,r):Xl(e,t)},Xl=(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})]}),Zl=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),TT=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Jl=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Ql(t)?"":wt(e);return n===r?e.mapping:{...e.mapping,x:n}},Ql=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",LT=e=>!Et(e)&&e.geom===ha,ET=e=>e.layers.filter(ie).some(t=>t.geom===ha),ec=(e,t)=>{const r=LT(t);return r===ET(e)?e:r?wT({...e,layers:sc(e.layers)}):RT(e)??e},wT=e=>{const t=rc(e);if(t===null)return null;const r=VT(e,t)===null?CT(e,t):nc(e,t);return r===null?null:tc(e,t,r)},RT=e=>{const t=rc(e);if(t===null)return null;const r=nc(e,t);return r===null?null:tc(e,t,r)},tc=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),rc=e=>{const t=e.layers.filter(ie);return t.length===1?t[0]??null:null},nc=(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:ac(t)}},ac=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}},VT=(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===wt(e))return null;const i=hr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},CT=(e,t)=>{const r=fr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,wt(e)),a=Xl(r,n),i=ac(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},_T=(e,t)=>sT.reduce((r,n)=>{const a=Jr(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Ce(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),DT=e=>rT.includes(e.coordType)&&ic(e.geom)&&PT(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),PT=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=z.get(e);return n.includes(t)&&a.includes(r)},ic=e=>oT.includes(e),ie=e=>ic(e.geom)&&!OT(e.stat),OT=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},kT=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},MT=(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:NT(i,t,n)}]);return new Map(a)},NT=(e,t,r)=>e.geom!=="bar"||Xt(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,oc=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return as(z,Ce(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=BT(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?$T(e,{...i,stat:s},t.coordType,o):i}))},BT=(e,t,r)=>Ql(r)?e.type==="identity"?Wl:e:FT(t)&&e.type==="sum"?iT:e,FT=e=>e.coordType==="polar"&&e.params.theta==="y",$T=(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{...ke(z,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}},sc=e=>{const t=e.filter(ie);if(t.length<2||!e.some(Xt))return e;const[r]=t;return e.flatMap(n=>n===r?[GT(n)]:Xt(n)?[]:[n])},Xt=e=>lc(e)!==null,lc=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:lT.includes(t.options.variableName)?t:null},GT=e=>{const t=lc(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)}},cc=(e,t)=>{const r=UT(e,t);return(0,Gt.default)(r,e)?e:r},UT=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return $r({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Mt;return $r({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},uc=(e,t,r)=>{const n=Nr(z,t),a=Nr(z,e.layers),i=e.coords.coordType==="polar";return Ce(e.scales,o=>{const s=HT(o,n,a),c=WT(s,n,a);return zT(c,r,i)})},HT=(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 Fr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Fr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=KT(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},WT=(e,t,r)=>{if(e.scaleType!=="discrete"||!De(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}},KT=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,zT=(e,t,r)=>{if(e.scaleType!=="discrete"||!De(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}},dc=class pc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:qT(t)})}apply(t){const r="previous"in this.params?this.params.previous:jT(t,this.params);if(r===null)return null;const n=w(t,r);return n===t?null:{spec:n,revert:new pc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},YT={type:"set-mapping",deserialize:(e,t)=>new dc(e,t)},mc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},hc=e=>e===""?null:e,qT=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=hc(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},jT=(e,{aesthetic:t,variable:r})=>{if(!VI(t))return null;const n=hc(r),a=ZT(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:QT(e,t,a,n),layers:XT(e.layers,a)}},XT=(e,t)=>Ce(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&$l(r.geom)===null)return r;const a=ns(z,r.geom,r.position,n);return(0,Gt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),ZT=(e,t,r)=>r===null?JT(e,t):mc(e,t)===r?e:{...e,[t]:r},JT=(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},QT=(e,t,r,n)=>{if(!To(t))return e.scales;let a=e.scales;for(const i of eL(e,t))a=rL(e,a,i,r,n);return a},eL=(e,t)=>t==="y"&&tL(e.layers)?["y","ySecondary"]:[t],tL=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},rL=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,Jr(e,r,n)];if(a===null&&!De(r)||a!==null&&!hr(e).hasVariable(a))return t;const o=Jr(e,r,n);return nL(i,o)?t:Ce(t,s=>s.scaledAesthetic===r?o:s)},nL=(e,t)=>e.scaleType===t.scaleType||$i(e)&&$i(t),$i=e=>e.scaleType==="discrete"||e.scaleType==="palette",fa=e=>e==="both"?["x","y"]:[e],fc=e=>e==="both"?"the":`${e} axis`;function ga(e,t){return gr(e)?e[t]:e}function aL(e,t){return e.config.axes[t]??{}}function iL(e,t,r){if(t!=="ySecondary")return C(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=gc(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,w(e,{config:w(e.config,{axes:i})})}function gr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function gc(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?oL(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 oL(e,t){return l.isPlainObject(t)?gc(l.isPlainObject(e)?e:void 0,t):t}var yc=class vc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${lL(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=aL(t,r).label;if(a===n)return null;const i=iL(t,r,{label:n});return i===t?null:{spec:i,revert:new vc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},sL={type:"set-axis-label",deserialize:(e,t)=>new yc(e,t)};function lL(e){return e===void 0?"(inherited)":e??"(none)"}var bc=class Sc{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:C(t,{config:{axes:{[r]:{position:n}}}}),revert:new Sc({axis:r,position:a},this.metadata)}}},cL={type:"set-axis-position",deserialize:(e,t)=>new bc(e,t)},xc=class Ac{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:C(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new Ac({axis:r,tickMode:a},this.metadata)}}},uL={type:"set-axis-tick-mode",deserialize:(e,t)=>new xc(e,t)},Ic=class Tc{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:C(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new Tc({axis:r,isVisible:a},this.metadata)}}},dL={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new Ic(e,t)},Lc=class Ec{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:C(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new Ec({axis:r,isVisible:a},this.metadata)}}},pL={type:"set-axis-visibility",deserialize:(e,t)=>new Lc(e,t)},wc=class Rc{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:C(t,{config:{content:{caption:this.params.caption}}}),revert:new Rc({caption:r},this.metadata)}}},mL={type:"set-content-caption",deserialize:(e,t)=>new wc(e,t)},Vc=class Cc{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(Ze(r,this.params.source))return null;const n=w(t.config.content,{source:this.params.source});return{spec:w(t,{config:w(t.config,{content:n})}),revert:new Cc({source:r},this.metadata)}}},hL={type:"set-content-source",deserialize:(e,t)=>new Vc(e,t)},_c=class Dc{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:C(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new Dc({subtitle:r},this.metadata)}}},fL={type:"set-content-subtitle",deserialize:(e,t)=>new _c(e,t)},Pc=class Oc{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:C(t,{config:{content:{title:this.params.title}}}),revert:new Oc({title:r},this.metadata)}}},gL={type:"set-content-title",deserialize:(e,t)=>new Pc(e,t)},yL="dashed",vL=1,kc=(e,t,r,n)=>{const a=bL(t,r),i=xL(e,a,n);let o=e,s=!1;for(const c of a){const u=IL(o,c,n,AL(n,SL(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},bL=(e,t)=>e==="both"&&!gr(t)?[void 0]:fa(e),SL=(e,t)=>t===void 0?gr(e)?e.x:e:ga(e,t),xL=(e,t,r)=>t.length===1?Cr(e,t[0],r):{x:Cr(e,"x",r),y:Cr(e,"y",r)},Cr=(e,t,r)=>Mc(e.styles.overrides,t)?.[r]??null,AL=(e,t)=>t===null||e==="lineType"&&t===yL||e==="strokeWidth"&&t===vL?null:t,IL=(e,t,r,n)=>{const a=Mc(e.styles.overrides,t);return(a?.[r]??null)===n?null:new ce({list:"overrides",rule:EL(t,LL(a,r,n))}).apply(e)?.spec??null},TL=e=>e.select.target==="gridLine",Mc=(e,t)=>{const r=xt(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!TL(r)))return r.declarations},LL=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},EL=(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),Nc=class Bc{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${fc(t.axis)} grid line style to ${RL(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=kc(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new Bc({axis:r,lineStyle:a.previous},this.metadata)}}},wL={type:"set-grid-line-style",deserialize:(e,t)=>new Nc(e,t)},RL=({axis:e,lineStyle:t})=>{const r=fa(e).map(n=>ga(t,n)??"(theme)");return[...new Set(r)].join(" and ")},VL={type:"set-grid-line-width",deserialize:(e,t)=>new Fc(e,t)},Fc=class $c{constructor(t,r={}){this.type="set-grid-line-width";const n=CL(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${fc(t.axis)} grid line width to ${_L(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=kc(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new $c({axis:r,lineWidth:a.previous},this.metadata)}}},CL=e=>gr(e)?{x:_r(e.x),y:_r(e.y)}:_r(e),_r=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),_L=(e,t)=>{const r=fa(e).map(n=>ga(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Gc=class Uc{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:C(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new Uc({axis:r,isVisible:a},this.metadata)}}},DL={type:"set-grid-visibility",deserialize:(e,t)=>new Gc(e,t)},Hc=class Wc{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:C(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Wc({compareWith:r},this.metadata)}}},PL={type:"set-headline-compare-with",deserialize:(e,t)=>new Hc(e,t)},Kc=class zc{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:C(t,{config:{headline:{position:this.params.position}}}),revert:new zc({position:r},this.metadata)}}},OL={type:"set-headline-position",deserialize:(e,t)=>new Kc(e,t)},Yc=class qc{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:C(t,{config:{headline:{show:this.params.show}}}),revert:new qc({show:r},this.metadata)}}},kL={type:"set-headline-show",deserialize:(e,t)=>new Yc(e,t)},jc=class Xc{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:C(t,{config:{headline:{size:this.params.size}}}),revert:new Xc({size:r},this.metadata)}}},ML={type:"set-headline-size",deserialize:(e,t)=>new jc(e,t)},NL={type:"set-highlight-dim-style",deserialize:(e,t)=>new Zc(e,t)},Zc=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(Jc(e)===this.params.dimStyle)return null;const t=new ce({list:"overrides",rule:FL(this.params.dimStyle)},this.metadata).apply(e);return t||null}},BL={select:{target:"geom"},when:{state:"dimmed"}},Jc=e=>{const t=xt(e.styles.overrides,BL);return(t!==void 0&&la(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},FL=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Qc=class eu{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:C(t,{config:{legend:{align:this.params.align}}}),revert:new eu({align:r},this.metadata)}}},$L={type:"set-legend-align",deserialize:(e,t)=>new Qc(e,t)},tu=class ru{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:C(t,{config:{legend:{display:this.params.display}}}),revert:new ru({display:r},this.metadata)}}},GL={type:"set-legend-display",deserialize:(e,t)=>new tu(e,t)},nu=class au{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:C(t,{config:{legend:{position:this.params.position}}}),revert:new au({position:r},this.metadata)}}},UL={type:"set-legend-position",deserialize:(e,t)=>new nu(e,t)},iu=class ou{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:C(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new ou({abbreviation:r},this.metadata)}}},HL={type:"set-number-format-abbreviation",deserialize:(e,t)=>new iu(e,t)},su=class lu{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:C(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new lu({decimals:r},this.metadata)}}},WL={type:"set-number-format-decimals",deserialize:(e,t)=>new su(e,t)},cu=class uu{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=zL(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:C(t,{config:{content:{[a]:n}}}),revert:new uu({slot:r,isVisible:i},this.metadata)}}},KL={type:"toggle-content-visibility",deserialize:(e,t)=>new cu(e,t)},Gi={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function zL(e){return Object.hasOwn(Gi,e)?Gi[e]:void 0}var du=class pu{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(Ze(i.xLimits,a.xLimits)&&Ze(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 pu(o,this.metadata);return{spec:w(t,{coords:qL(t.coords,i)}),revert:s}}},YL={type:"set-coord-limits",deserialize:(e,t)=>new du(e,t)};function qL(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 mu=class hu{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Ke.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:w(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new hu({innerRadius:n},this.metadata)}}},jL={type:"set-polar-inner-radius",deserialize:(e,t)=>new mu(e,t)},XL={type:"set-polar-start-angle",deserialize:(e,t)=>new fu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:Ui(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 Ui(n)===this.params.startAngle?null:{spec:w(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new gu({startAngle:n},this.metadata)}}},Dr=360,Ui=e=>(e%Dr+Dr)%Dr,ya=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 va({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:w(e,{highlights:n}),revert:a}}},ZL={type:"remove-highlight",deserialize:(e,t)=>new ya(e,t)},va=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??F(),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 ya({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:w(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},JL={type:"add-highlight",deserialize:(e,t)=>new va(e,t)};function ba(e,t){return{...e,params:{...e.params,...t}}}function yr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function Sa(e,t){return w(e,{layers:[...e.layers,t]})}function q(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:w(e,{layers:so(e.layers,n,r)})}function vr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:w(e,{layers:e.layers.filter((n,a)=>a!==r)})}var xa=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=vr(e,this.params.layerId);return n===e?null:{spec:n,revert:new Aa({layer:r,index:t},this.metadata)}}},QL={type:"remove-layer",deserialize:(e,t)=>new xa(e,t)},Aa=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??F()},...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:w(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new xa({layerId:t.id},this.metadata)}}},eE={type:"add-layer",deserialize:(e,t)=>new Aa(e,t)},yu=class vu{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(!Q(P(t.layers,r),"bar"))return null;const a=Le("bar",r),i=At(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new ce({list:"overrides",rule:{...a,declarations:rE(i,n)}}).apply(t);if(!s)return null;const c=new vu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},tE={type:"set-bar-border-radius",deserialize:(e,t)=>new yu(e,t)},rE=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},nE={type:"set-bar-width",deserialize:(e,t)=>new Su(e,t)},bu=.05,aE=1,Su=class xu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Ke.default)(t.width,bu,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?P(t.layers,this.params.layerId):ge(t.layers,"bar");if(!Q(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:q(t,r.id,ba(r,{width:this.params.width})),revert:new xu({layerId:r.id,width:n},this.metadata)}}},Au=class Iu{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?P(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:q(t,r.id,yr(r,{format:this.params.format})),revert:new Iu({layerId:r.id,format:n},this.metadata)}}},iE={type:"set-data-labels-format",deserialize:(e,t)=>new Au(e,t)},Tu=class Lu{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?P(t.layers,this.params.layerId):ge(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:q(t,r.id,{...r,position:this.params.position}),revert:new Lu({layerId:r.id,position:n},this.metadata)}}},oE={type:"set-layer-position",deserialize:(e,t)=>new Tu(e,t)},Eu=class wu{constructor(t,r={}){this.type="set-layer-stat";const n=rs(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?P(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return lE(n,this.params.stat)?null:{spec:q(t,r.id,{...r,stat:this.params.stat}),revert:new wu({layerId:r.id,stat:n},this.metadata)}}},sE={type:"set-layer-stat",deserialize:(e,t)=>new Eu(e,t)},lE=(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},Ru=class Vu{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?P(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=q(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:w(a,{scales:ma(a.scales,a.layers)}),revert:new Vu({layerId:r.id,yScaleType:n},this.metadata)}}},cE={type:"set-layer-y-scale-type",deserialize:(e,t)=>new Ru(e,t)},Cu=class _u{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?P(t.layers,this.params.layerId):ge(t.layers,"line","area");if(!Q(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:q(t,r.id,ba(r,{interpolate:this.params.interpolate})),revert:new _u({layerId:r.id,interpolate:n},this.metadata)}}},uE={type:"set-line-interpolation",deserialize:(e,t)=>new Cu(e,t)},Du=class Pu{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?P(t.layers,this.params.layerId):ge(t.layers,"line","area");if(!Q(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:q(t,r.id,ba(r,{missingValues:this.params.missingValues})),revert:new Pu({layerId:r.id,missingValues:n},this.metadata)}}},dE={type:"set-line-missing-values",deserialize:(e,t)=>new Du(e,t)},Ou=class ku{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=P(t.layers,r);if(!Q(a,"line","area"))return null;const i=At(t.styles.overrides,Le(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=mE(i,n),c=new ce({list:"overrides",rule:a.geom==="area"?{...Le("area",r),declarations:s}:{...Le("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new ku({layerId:r,lineWidth:o},this.metadata)}:null}},pE={type:"set-line-width",deserialize:(e,t)=>new Ou(e,t)},mE=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},Mu=class Nu{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(!Q(P(t.layers,r),"point"))return null;const a=Le("point",r),i=At(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new ce({list:"overrides",rule:{...a,declarations:fE(i,n)}}).apply(t);return s?{spec:s.spec,revert:new Nu({layerId:r,size:o},this.metadata)}:null}},hE={type:"set-point-size",deserialize:(e,t)=>new Mu(e,t)},fE=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},Bu=class Fu{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?P(t.layers,this.params.layerId):ge(t.layers,"rule");if(!Q(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:q(t,r.id,{...r,params:i}),revert:new Fu({layerId:r.id,label:n??null},this.metadata)}}},gE={type:"set-rule-label",deserialize:(e,t)=>new Bu(e,t)},$u=class Gu{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?P(t.layers,this.params.layerId):ge(t.layers,"rule");if(!Q(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:q(t,r.id,{...r,mapping:i}),revert:new Gu({layerId:r.id,value:a},this.metadata)}}},yE={type:"set-rule-value",deserialize:(e,t)=>new $u(e,t)},vE={type:"set-stat-line",deserialize:(e,t)=>new Uu(e,t)},Uu=class Hu{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:LE(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=SE(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&&TE(r.layer,n))return null;const a=new Hu({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:q(t,r.layer.id,n),revert:a};const i=r===void 0?t:vr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:Sa(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"?xE(this.params):AE(t,this.params);if(n===null)return null;const a=ke(z,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},bE="linear",SE=e=>{const t=Vl(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=Cl(e.layers);if(r!==void 0)return{line:"average",layer:r}},xE=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??bE}),interactive:!1}),AE=(e,{group:t,label:r})=>{const n=IE(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})},IE=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),TE=(e,t)=>(0,Je.isEqual)({...e,id:""},{...t,id:""}),LE=e=>e==="none"?"Hide stat line":`Show ${e} line`,Wu=class Ku{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?P(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:q(t,r.id,yr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new Ku({layerId:r.id,showCategoryLabels:n},this.metadata)}}},EE={type:"toggle-category-labels",deserialize:(e,t)=>new Wu(e,t)},zu=class Yu{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?P(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:q(t,r.id,yr(r,{showDataLabels:this.params.showDataLabels})),revert:new Yu({layerId:r.id,showDataLabels:n},this.metadata)}}},wE={type:"toggle-data-labels",deserialize:(e,t)=>new zu(e,t)},RE={type:"toggle-goal-line",deserialize:(e,t)=>new qu(e,t)},qu=class Qr{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=Rl(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=vr(t,r.id);return a===t?null:{spec:a,revert:new Qr({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:Sa(t,n),revert:new Qr({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return ke(z,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??VE}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},VE=0,CE={type:"toggle-line-fill",deserialize:(e,t)=>new ju(e,t)},ju=class Xu{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(!Q(P(t.layers,r),"line"))return null;const i=Le("line",r),o=At(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new ce({list:"overrides",rule:{...i,declarations:DE(o,n?a??_E:null)}}).apply(t);if(!u)return null;const d=new Xu({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},_E=.2,DE=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},PE={type:"toggle-line-points",deserialize:(e,t)=>new Zu(e,t)},Zu=class en{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?P(t.layers,this.params.layerId):ge(t.layers,"line","area");return Q(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:Sa(t,this.params.removedLayer??ke(z,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new en({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:vr(t,n.id),revert:new en({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:yn(n,[r]))}},Ju=class Qu{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?P(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:q(t,r.id,yr(r,{showStackTotals:this.params.showStackTotals})),revert:new Qu({layerId:r.id,showStackTotals:n},this.metadata)}}},OE={type:"toggle-stack-totals",deserialize:(e,t)=>new Ju(e,t)},ed=class td{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${Lt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=It(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=Tt(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 td(c,this.metadata)}}},kE={type:"set-scale-domain",deserialize:(e,t)=>new ed(e,t)},rd=class nd{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${Lt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=It(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||Ze(r.palette,this.params.palette)?null:{spec:Tt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new nd({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},ME={type:"set-scale-palette",deserialize:(e,t)=>new rd(e,t)},ad=class id{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${Lt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=It(t,this.params.scaledAesthetic);if(!r||!BE(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:Tt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new id({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},NE={type:"set-scale-reverse",deserialize:(e,t)=>new ad(e,t)};function BE(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var od=class sd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${Lt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=It(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:Tt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new sd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},FE={type:"set-scale-transform",deserialize:(e,t)=>new od(e,t)},ld=class cd{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${Lt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=It(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:Tt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new cd({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},$E={type:"set-scale-zero",deserialize:(e,t)=>new ld(e,t)},ud=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 ud;S.register(aT);S.register(YT);S.register(eE);S.register(QL);S.register(iE);S.register(oE);S.register(sE);S.register(cE);S.register(uE);S.register(pE);S.register(tE);S.register(nE);S.register(hE);S.register(dE);S.register(gE);S.register(yE);S.register(vE);S.register(EE);S.register(wE);S.register(RE);S.register(CE);S.register(PE);S.register(OE);S.register(kE);S.register(ME);S.register(NE);S.register(FE);S.register($E);S.register(sL);S.register(uL);S.register(cL);S.register(dL);S.register(pL);S.register(mL);S.register(hL);S.register(fL);S.register(gL);S.register(wL);S.register(VL);S.register(DL);S.register(PL);S.register(OL);S.register(kL);S.register(ML);S.register(NL);S.register($L);S.register(GL);S.register(UL);S.register(HL);S.register(WL);S.register(KL);S.register(JL);S.register(ZL);S.register(eT);S.register(GI);S.register($I);S.register(ZI);S.register(tT);S.register(JI);S.register(YL);S.register(jL);S.register(XL);var dd=(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&&mr(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&&St(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"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},pd=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:Hi(this.undoStack),redoStack:Hi(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&&UE(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)}}},GE=Object.freeze([]),UE=(e,t)=>e.type===t.type&&dd(e.target,t.target),Hi=e=>e.length===0?GE:e.map(t=>t.command.metadata),HE=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}},WE=class{constructor(e){this.compiler=e,this.history=new pd,this.current=null,this.last=null,this.hostInput=null,this.run=new HE(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=_l(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}},KE=new Set(["x","y"]),Wi=["numeric","categorical","temporal"],Ki=["numeric"],zE=(e,t)=>{const r=e.layers.map(a=>$l(a.geom)).filter(l.isDefined),n=hr(e);return t.filter(a=>YE(e,r,a)).map(a=>({aesthetic:a,variables:qE(n,r,a),isRequired:KE.has(a)}))},YE=(e,t,r)=>{switch(r){case"x":return!ZE(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))}},qE=(e,t,r)=>{const n=jE(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},jE=(e,t)=>t==="size"?Ki:t!=="x"&&t!=="y"?Wi:XE(e,t)?Ki:Wi,XE=(e,t)=>e.some(r=>r.positionRoles.some(n=>Io.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),ZE=e=>e.coordType==="polar"&&e.params.theta==="y",JE=500,QE="normal",Ia={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},ew=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}`},Ta=e=>typeof e!="string"?e??500:Ia[e],tw="\0",rw=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,Ta(t.weight),t.style??"normal",e].join(tw)}},nw={" ":.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 aw=1.05,iw=.84,ow=.21,sw=class{measureText(e,t){let r=0;for(const i of e)r+=(nw[i]??.55)*t.size;Ta(t.weight)>=Ia.semiBold&&(r*=aw);const n=iw*t.size,a=ow*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=tS;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=mn;exports.AddAnnotationCommand=ua;exports.AddHighlightCommand=va;exports.AddLayerCommand=Aa;exports.BORDER_RADIUS_PX=Zn;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=Jg;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=rw;exports.CommandRegistry=ud;exports.CommandStackManager=pd;exports.Compiler=bs;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=QE;exports.DEFAULT_FONT_WEIGHT=JE;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=Jo;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=le;exports.GraphCompilationSession=WE;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=JS;exports.HEADLINE_TREND_GAP=tx;exports.HEADLINE_TREND_ICON_SIZE=ex;exports.HEADLINE_VALUE_LABEL_GAP=QS;exports.HeuristicTextMeasurer=sw;exports.HoverEngine=pA;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=an;exports.LayoutCompiler=wb;exports.MAX_BAR_WIDTH=aE;exports.MIN_BAR_WIDTH=bu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=Nl;exports.NAMED_WEIGHTS=Ia;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=aa;exports.OUT_OF_VIEW_MARGIN_PX=rS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=Td;exports.POSITION_TYPES=to;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=te;exports.RemoveAnnotationCommand=ca;exports.RemoveHighlightCommand=ya;exports.RemoveLayerCommand=xa;exports.SCALED_POSITION_AESTHETIC_KEYS=hn;exports.SCALED_VISUAL_AESTHETIC_KEYS=pt;exports.SCHEME_ALIASES=Qo;exports.SEQUENTIAL_SCHEME_NAMES=ff;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=nS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=yc;exports.SetAxisPositionCommand=bc;exports.SetAxisTickModeCommand=xc;exports.SetAxisTicksVisibilityCommand=Ic;exports.SetAxisVisibilityCommand=Lc;exports.SetBarBorderRadiusCommand=yu;exports.SetBarWidthCommand=Su;exports.SetChartTypeCommand=Ul;exports.SetContentCaptionCommand=wc;exports.SetContentSourceCommand=Vc;exports.SetContentSubtitleCommand=_c;exports.SetContentTitleCommand=Pc;exports.SetCoordLimitsCommand=du;exports.SetDataLabelsFormatCommand=Au;exports.SetDifferenceArrowStyleCommand=Bl;exports.SetGridLineStyleCommand=Nc;exports.SetGridLineWidthCommand=Fc;exports.SetGridVisibilityCommand=Gc;exports.SetHeadlineCompareWithCommand=Hc;exports.SetHeadlinePositionCommand=Kc;exports.SetHeadlineShowCommand=Yc;exports.SetHeadlineSizeCommand=jc;exports.SetHighlightDimStyleCommand=Zc;exports.SetLayerPositionCommand=Tu;exports.SetLayerStatCommand=Eu;exports.SetLayerYScaleTypeCommand=Ru;exports.SetLegendAlignCommand=Qc;exports.SetLegendDisplayCommand=tu;exports.SetLegendPositionCommand=nu;exports.SetLineInterpolationCommand=Cu;exports.SetLineMissingValuesCommand=Du;exports.SetLineWidthCommand=Ou;exports.SetMappingCommand=dc;exports.SetNumberFormatAbbreviationCommand=iu;exports.SetNumberFormatDecimalsCommand=su;exports.SetPointSizeCommand=Mu;exports.SetPolarInnerRadiusCommand=mu;exports.SetPolarStartAngleCommand=fu;exports.SetRuleLabelCommand=Bu;exports.SetRuleValueCommand=$u;exports.SetScaleDomainCommand=ed;exports.SetScalePaletteCommand=rd;exports.SetScaleReverseCommand=ad;exports.SetScaleTransformCommand=od;exports.SetScaleZeroCommand=ld;exports.SetStatLineCommand=Uu;exports.SetStyleRuleCommand=ce;exports.SpecResolver=os;exports.Stat=Oe;exports.TAU=pe;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=Wu;exports.ToggleContentVisibilityCommand=cu;exports.ToggleDataLabelsCommand=zu;exports.ToggleGoalLineCommand=qu;exports.ToggleLineFillCommand=ju;exports.ToggleLinePointsVisibilityCommand=Zu;exports.ToggleStackTotalsCommand=Ju;exports.UpdateAnnotationCommand=pa;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=eo;exports.annotation=yg;exports.areAnchorsEqual=He;exports.areEditMenuTriggersEqual=VS;exports.areEditTargetsEqual=dd;exports.areEndpointsComparable=ao;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=El;exports.arePointerRegionListsEqual=AS;exports.arePredicatesEqual=St;exports.areStyleDeclarationsEqual=Dl;exports.areStyleRuleAddressesEqual=mr;exports.buildAverageLineSymbols=Zb;exports.buildCalloutHitRegions=eS;exports.buildColumnKey=ll;exports.buildDataLabelsContent=Ev;exports.buildDiagnostic=oo;exports.buildEditMenuTriggerRegion=wS;exports.buildFontString=ew;exports.buildLayerIntroPlan=AA;exports.buildLayerStyleAddress=Le;exports.buildLayerYValueFormatter=zn;exports.buildObservationPredicate=nl;exports.buildObservationsTarget=yS;exports.buildPinnedNumberValueFormatter=$S;exports.buildPolarBarArcPath=yx;exports.buildSliceGroupKey=dl;exports.buildTooltipContent=YA;exports.canAnchorDirectLabels=Oo;exports.canBecomeCombo=dT;exports.canBecomeHeatmap=pT;exports.canPlaceDataLabels=Lv;exports.clampAnnotationTranslation=HI;exports.commandRegistry=S;exports.compileChromeStyles=ds;exports.compileStylesheetForLayer=Eg;exports.compositeColor=ji;exports.computeArrow=jb;exports.computeDifferenceArrow=qs;exports.computeDirectLabelsLayout=mS;exports.computeLineBoxHeight=js;exports.computePanelBorderPaths=MA;exports.computePanelBorderSizes=NA;exports.config=l.config;exports.convertSpecToInput=_l;exports.coord=l.coord;exports.countLayerGeoms=IA;exports.createAlphaValueReader=Dd;exports.createAnchorResolver=Vb;exports.createAreaPathGenerators=lx;exports.createColorValueReader=ro;exports.createCompiler=Qg;exports.createDatasetFromKindPartitions=hp;exports.createEmptyHighlight=ko;exports.createGraphyBuilder=ry;exports.createGroupValueReader=Pd;exports.createHeadlineItemRows=rx;exports.createLabelValueReader=Cd;exports.createLineFillAreaGenerator=hx;exports.createLinePathGenerator=mx;exports.createObservationAnchorBuilder=ut;exports.createObservationAnchorParser=io;exports.createRawValueReader=Y;exports.createSegmentYReader=ct;exports.createSizeValueReader=_d;exports.createSpec=xs;exports.createStableBandKeyGenerator=xx;exports.createStableCellKeyGenerator=Ax;exports.createStableKeyGenerator=dr;exports.createStrokeWidthValueReader=Od;exports.createStyleResolver=et;exports.createValueFormatter=D;exports.createXValueReader=Qe;exports.createYValueReader=sn;exports.cursorToPiePlane=rn;exports.cursorToPolar=Jt;exports.describeMeasurementBasis=Or;exports.ensureReadableTextColor=Id;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=tl;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=wm;exports.findAnnotation=ft;exports.findAverageLineLayer=Cl;exports.findAxisGuide=Xn;exports.findDistinctLayers=vn;exports.findEquivalentHighlight=LI;exports.findGoalLineLayer=Rl;exports.findHighlightsAtObservation=_S;exports.findKindStyleDeclarations=At;exports.findLayerByGeom=ge;exports.findLayerById=P;exports.findLegendForAesthetic=XS;exports.findObservationAttachment=wl;exports.findPointerRegion=SS;exports.findStyleRule=xt;exports.findStyleRuleIndex=sa;exports.findTrendLineLayer=Vl;exports.formatDifferenceLabel=zs;exports.formatHeadline=GS;exports.formatLegends=qS;exports.formatRuleValue=ZS;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=B;exports.getAlpha=Ms;exports.getAngleExtent=Wn;exports.getBarRectBounds=sl;exports.getBoundingRect=px;exports.getChromeDashArray=SI;exports.getColor=bt;exports.getCrossAxisCoordinate=rr;exports.getCurve=ur;exports.getDashArray=sx;exports.getDifferenceArrowDimensions=Ys;exports.getDifferenceArrowLabelBox=Xs;exports.getGroup=J;exports.getHoverGuideLineProps=fA;exports.getHoverGuideRectProps=gA;exports.getInsetTileRect=Hs;exports.getLineType=Ns;exports.getMainAxisCoordinate=Ye;exports.getNumericWeight=Ta;exports.getPolarHoverGuideArcProps=yA;exports.getRadiusExtent=Kn;exports.getRuleDashPattern=Sx;exports.getScaledAesthetic=Rd;exports.getShapeAnnotationStroke=uI;exports.getSize=Gn;exports.getStablePolarBarKeyGenerator=Ix;exports.getStackRole=$o;exports.getStrokeWidth=Hr;exports.getTileRectBounds=Us;exports.getUnionExtent=bx;exports.getX=_;exports.getXMax=K;exports.getXMin=W;exports.getY=R;exports.getYMax=O;exports.getYMin=M;exports.getYRaw=nn;exports.hasMultipleGroups=nr;exports.highlight=TI;exports.inferDefaultDifferenceArrowEndpoints=OS;exports.inferDifferenceArrowEndpoints=ol;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=WI;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=Bd;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=Et;exports.isCompanionLayer=yn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=Xi;exports.isGeomStyleRule=la;exports.isKeyedScope=qn;exports.isLayerOf=Ss;exports.isLayerOfType=Q;exports.isLineStyleType=on;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=xI;exports.isPointWithinEditMenuTrigger=RS;exports.isPointWithinRegionShape=jn;exports.isSafeUrl=WA;exports.isStackedPosition=N;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=CI;exports.normalizeAngle=ze;exports.orderPointerRegions=xS;exports.paintsInDonutHole=cr;exports.pickReadableTextColor=qi;exports.pipe=As;exports.placeCallouts=lS;exports.polarToUnit=at;exports.positionToAngle=Zi;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=cx;exports.prepareLineObservations=fx;exports.projectAnchorToPanel=zt;exports.projectRegionToPanel=Db;exports.quantiseKey=Z;exports.readAnchoredObservation=MS;exports.readAttachedObservation=ia;exports.readAuthoredNumber=rI;exports.readAuthoredString=nI;exports.readChartType=uT;exports.readComboLineLayerId=mT;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Jc;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=zE;exports.readMappedVariable=mc;exports.readObservationIndex=vA;exports.readXExtent=Il;exports.readYExtent=Tl;exports.resolveAnchorVariable=Ve;exports.resolveArrowAnnotationStyle=iI;exports.resolveArrowColor=dS;exports.resolveAxisLabelStyle=Yv;exports.resolveBarBandFraction=Br;exports.resolveBarBorderRadiusPx=Jn;exports.resolveBarBorderTreatment=dx;exports.resolveBarCornerRadiiPx=ux;exports.resolveCalloutAnnotationStyle=cI;exports.resolveColorRamp=In;exports.resolveComparisonBasis=Po;exports.resolveDataLabelStyle=jv;exports.resolveDeferredAnchors=Mb;exports.resolveDefinition=An;exports.resolveDifferenceArrowAnnotationStyle=oI;exports.resolveDirectLabelStyle=Qv;exports.resolveGeomAnchorFrame=un;exports.resolveGraphChromeStyle=fI;exports.resolveGraphPadding=gI;exports.resolveGridLineStyle=pI;exports.resolveHeadingFontFamily=hI;exports.resolveHeadlineFigure=tb;exports.resolveHeadlineItemStyle=eb;exports.resolveHeadlinePlacement=Ab;exports.resolveHeadlineStyle=vI;exports.resolveHoverGuideStyle=bI;exports.resolveImageAnnotationStyle=lI;exports.resolveLegendItemStyle=Jv;exports.resolveLegendStyle=yI;exports.resolveObservationPoint=NS;exports.resolveObservationsTarget=al;exports.resolvePanelBorderStyle=dI;exports.resolvePolarBarCornerRadiusUnit=vx;exports.resolveRuleLabelStyle=Xv;exports.resolveSegmentYSource=Qt;exports.resolveShapeAnnotationStyle=aI;exports.resolveSwatchGeomPaint=Qn;exports.resolveTextAnnotationStyle=sI;exports.resolveTextStyle=H;exports.resolveTickLabelStyle=qv;exports.resolveTickLineStyle=mI;exports.resolveTooltipStyle=Zv;exports.resolveYScaleAesthetic=fe;exports.sampleColorScheme=Sf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=BS;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=zv;exports.toPanelCursor=el;exports.toPercent=Te;exports.toViewBoxX=_b;exports.toViewBoxY=ae;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=Ts;exports.uniqueId=F;exports.unitToPolar=Ji;exports.updateSpec=C;
23
+ `,mb=(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},hb=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),ul=({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=cl(t.strokeWidth),d=cb(o,s,c,u),p=(o?db:ub)(s,c,d,u),m=pb(o,c,u),h=mb(o,s,c,d,hb(o,s,c),e.labelCrossPosition),f=ll({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:m,labelPosition:h,labelText:f}},fi={large:1,medium:23/26,small:19/26},fb={large:1,medium:10/12,small:10/12},gb=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],dl=e=>e.fontSize*e.lineHeight,yb=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),W=(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")}),vb=(e,t)=>W(e.axisLabel(t),e.graph),bb=(e,t)=>{const r=e.tickLabel(t);return{...W(r,e.graph),offset:r.get("offset")}},Sb=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...W(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}}},xb=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=W(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},Ab=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:W(e.tooltip.heading,r),label:W(e.tooltip.label,r),value:W(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},Ib=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...W(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")}}},Tb=e=>{const t=e.directLabel;return{...W(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},Lb=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=fi[t]*n,i=fb[t]*n,o=e.headlineItem,s=W(o.number,e.graph),c={...s,fontSize:s.fontSize*fi[t]},u=o.numberCenter.get("fontSize");return{number:c,...wb(o.numberCenter)?{numberCenter:Ft(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:Ft(o.caption,o.caption.get("fontSize")*i,r),label:Ft(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:Ft(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")}}},Eb=(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}},wb=e=>gb.some(t=>e.getSource(t)!=="unresolved"),Ft=(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}}},pl=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=dl(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*Rb({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!Je(o.start.x,o.start.y)||!Je(o.end.x,o.end.y))continue;const s=a(o.id),c=ul({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=pl({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 Cb={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:8,before:0},topAxisLabel:{after:8,before:0},topAxis:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16},footer:{after:0,before:16}},Vb={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},Db=e=>{const t=e.padding,r=gi(e.rows,t?.top??0,t?.bottom??0),n=gi(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:Mb(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},_b=e=>{const t=yi(e.rows,e.height),r=yi(e.cols,e.width),n=vi(t),a=vi(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=bi(r,o.col,c),m=bi(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,m)})}return i},gi=(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;Qr(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push(Pb(s));const c=Ob(e,o);if(Qr(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}},Pb=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Qr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ob=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Qr(n))return n}},Mb=(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},yi=(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)},vi=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},bi=(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},et={top:0,right:0,bottom:0,left:0},ml={outer:et,inner:et},kb=(e,t,r,n=et,a=ml,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=Si(Cb,o),d=Si(Vb,o);return Db({rows:[{name:"header",size:t.headerSize.height,gaps:u.header},{name:"topLegend",size:r.legends.top,gaps:u.topLegend},{name:"headline",size:r.headline,gaps:u.headline},{name:"topAxisLabel",size:c,gaps:u.topAxisLabel},{name:"topAxis",size:r.axes.top,gaps:u.topAxis},{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:u.bottomAxis},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:u.bottomAxisLabel},{name:"bottomLegend",size:r.legends.bottom,gaps:u.bottomLegend},{name:"footer",size:t.footerSize.height,gaps:u.footer}],cols:[{name:"leftLegend",size:r.legends.left,gaps:d.leftLegend},{name:"leftAxis",size:r.axes.left,gaps:d.leftAxis},{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:d.rightAxis},{name:"rightLegend",size:r.legends.right}],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"},...Bb(r.axes),...Fb(r.axesLabels,r.axes),...$b(r.legends)],containerSize:e,padding:i})},Nb=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Pr(t,e.after)}:{before:Pr(t.before,e.before),after:Pr(t.after,e.after)}:e,Pr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,Si=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=Nb(e[n],t[n]);return r},Bb=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},Fb=(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},$b=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 Gb=class{constructor(e){this.outer={...et},this.inner={...et},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)))}},Ub=["top","right","bottom","left"],Or=(e,t)=>{const r={};for(const n of Ub){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function xi(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var en=["large","medium","small"],Hb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of en)if(r(n)<=t)return n;return"small"},Wb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:en.indexOf(e);for(const a of en.slice(n))if(r(a)<=t)return a;return null},Kb=({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},zb=({headline:e,containerSize:t,measurer:r})=>{if(fr(e))return 0;const n=hl(e,t.width,r);return r.measureHeadline(e.formatted,n).height},Yb=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(fr(e)){const s=qb(t.panel,e.innerRadius),c=Wb({size:e.size,availableWidth:s.width,measureStripWidth:fl(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=hl(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=Kb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},fr=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,qb=(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}},hl=(e,t,r)=>Hb({size:e.size,availableWidth:t,measureStripWidth:fl(e,r)}),fl=(e,t)=>r=>t.measureHeadline(e.formatted,r,fr(e)).width,Ke={x:0,y:0,width:0,height:0},jb="0000",Xb=3,Zb=e=>e.plot.y+e.plot.height-e.panel.y,Jb=class{constructor(e){this.measurer=e}compile(e){return or({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:ml,panelBorder:e.panelBorder??et,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:Qb(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Ai(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,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Ai(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,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,gaps: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,gaps:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:Zb(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new Gb(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of Rb({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 eb({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 xi(i.inner,n.inner)&&xi(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,gaps:p}){let m=t,h=o;for(let f=0;f<Xb;f++){const g=this.measurePanelOverflow(e,m.panelFrame,u,h);if(g===h)break;h=g,m=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:s,headline:c,padding:d,gaps:p})}return m}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?Ii(r,a,0,0):Ii(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=$(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:jb}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=$(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=Jy({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?Yy({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,gaps:c}){const u=_b(kb(r,n,this.measureGuides(e,t,o,r),i,a,s,c));return{header:u.get("header")??Ke,headline:u.get("headline")??Ke,footer:u.get("footer")??Ke,plot:u.get("plot")??Ke,panelFrame:u.get("panelFrame")??Ke,panel:u.get("panel")??Ke,axes:Or(u,"Axis"),axisLabels:Or(u,"AxisLabel"),legends:Or(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:zb({headline:e,containerSize:t,measurer:this.measurer})}},Ai=e=>e==="left"||e==="right",Ii=(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}}},Qb=(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=zn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},eS=(e=[])=>{const t=tS(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:yn(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?Ro(r,t.get(r.geom)):null}},tS=e=>{const t=new dr;for(const r of e){const n=Cn(r);n instanceof he&&t.register(n.type,n)}return t};function rS(e){return e}function se(e){return 1-e}var Ce=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Jt=(e,t)=>{const r=sr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+se(e.y)*r.height}},nS=(e,t)=>{const r=sr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(se(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},aS=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}=tn(e.defer,this.panelRect);return Ei({...e,x:i.x+o,y:i.y-s})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=mt(t,e.defer.align),{x:n,y:a}=iS(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}=tn(e.defer,this.panelRect);return Ei({...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:oS(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:Ti(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=yo(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:Li(this.toPanelPoint(r))}case"differenceArrow":return Ti(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return Li(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Ba(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Ba(e,this.panelRect),r=sr(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}}},tn=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),iS=(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}=tn({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}},oS=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),Ti=(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)}),Li=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),Ei=e=>{const t={...e};return delete t.defer,delete t.frame,t},sS=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!lS(t))return t;const o=new aS(t,r,n),s={...t,shapes:ot(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:ot(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:ot(t.arrows,d=>d.start.defer!==void 0||d.end.defer!==void 0,d=>{const p=o.resolvePoint(d.start),m=o.resolvePoint(d.end);return p===null||m===null?null:{...d,start:p,end:m}}),textAnnotations:ot(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:ot(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},ot=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,lS=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),cS=800,wi=400,uS=.75,dS=.875,pS=4,mS=e=>Math.max(1,(e-wi)/(cS-wi)+1),hS=(e,t)=>{const r=mS(t),n=e*pS;return{strokeWidth:Math.min(e,e*uS*r),arrowheadLength:Math.min(n,n*dS*r)}},$t=Math.PI/4,rn=1.5,fS=2,gS=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,Ri=(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-$t)} ${o-r*Math.sin(s-$t)} M ${i} ${o} L ${i-r*Math.cos(s+$t)} ${o-r*Math.sin(s+$t)}`},yS=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*fS}`:`${t*rn} ${t*rn*2}`,vS=(e,t,r)=>e==="dashed"&&r?t*rn:0,bS=64,SS=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:Jt(e.start,a),end:Jt(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=hS(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=xS(s,c),d=e.startArrowheadStyle==="line-arrow",p=e.endArrowheadStyle==="line-arrow",m=d||p?u*Math.sin(Math.PI/4):0;return{id:e.id,linePath:gS(i),startArrowheadPath:d?Ri("start",i,u):"",endArrowheadPath:p?Ri("end",i,u):"",strokeWidth:o,dashArray:yS(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:vS(t.lineType,o,d),arrowheadExtent:m}},xS=(e,t)=>Math.min(e,t*e/bS);function AS(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=IS(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 IS(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 gl=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),TS=0,LS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:gl(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:TS})),ES=9,wS=8,RS=2,yl=e=>typeof e=="string"?e:vl(e),vl=e=>e.text!==void 0?e.text:e.content?e.content.map(vl).join(""):"",Ci={top:"bottom",bottom:"top",right:"left",left:"right"};function CS(e,t,r){return r.type==="polar"?_S(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function nn(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 Vi(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function VS(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 DS(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 _S(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,Ci[o],s,Ci[s]]}function PS(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:o}=e,s=[...t.map(d=>{const{id:p,at:m}=d;return Di(p,"pinned-number",m,o(d),i,n)}),...r.map(({id:d,at:p,content:m})=>Di(d,"comment",p,yl(m),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(_i(n,d,"top"));continue}const p=_i(n,d,MS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Di(e,t,r,n,a,i){const o=Jt(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:OS(o,i)}}function OS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function MS(e,t,r,n){const a=CS(t.anchorPx,e,r);for(const i of a){const o=nn(t.anchorPx,i,t.mini);if(Vi(o,e)&&!n.some(s=>DS(o,s)))return i}for(const i of a)if(Vi(nn(t.anchorPx,i,t.mini),e))return i;return"top"}function _i(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:VS(e,nn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var kS=(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,NS=100,BS=({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,m=d.y-a;if(p>m){o=!0,i=!0;const h=(p-m)/2+1;u.y-=h,d.y+=h,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(s>NS)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}},bl=(e,t)=>Qt(e,t,FS(e),{allowNull:!1}),Qt=(e,t,r,{allowNull:n})=>{const a=Vo(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}},FS=e=>{const t=gn(e)?Ae(e.data,e.mapping):[],r=fn(e),n=r===null?t:[...t,r],a=Me(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},ta=e=>e!=="data-point",Sl=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(be(t.predicate,e.data).length>0)return[];const n=ve(t.predicate,gt(e,r));return ta(t.scope)?GS(e,n,t.scope):$S(e,n)},$S=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},GS=(e,t,r)=>{const n=ur(e.mapping),a=[],i=new Set;for(const s of e.data){const c=ct(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},US=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=KS(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return WS(o,e,t,n)?o:null},HS=e=>e.identityKey==="x-group"?"series":Ae(e.data,e.mapping).length===0?"data-point":"series",WS=(e,t,r,n)=>Sl({layer:t,target:e,parsingLocale:n}).includes(r),KS=(e,t,r)=>{switch(r){case"data-point":return Pi(e,t);case"series":{const n=Ae(e.data,e.mapping);return n.length===0?Pi(e,t):Qt(e,t,n,{allowNull:!0})}case"x-value":{const n=ur(e.mapping);return n===null?null:Qt(e,t,[n],{allowNull:!0})}}},Pi=(e,t)=>{const r=e.identityKey;if(typeof r=="object")return Qt(e,t,[r.variable],{allowNull:!0});switch(r){case"index":return null;case"x-group":case"x-y":return bl(e,t)}},ra=(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},zS=(e,t)=>{for(const r of t)if(ra(e,r.shape))return r;return null},YS=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},qS=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>jS(r,t[n])),jS=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&XS(e.shape,t.shape)&&ZS(e.tooltip,t.tooltip),XS=(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},ZS=(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},JS=100,QS=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:JS}),ex=(e,t)=>ra(e,{kind:"circle",center:t.center,radius:t.radius}),tx=(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&&rx(e.target,t.target),rx=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,nx=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=gt(e,n),i=ax(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||be(o.predicate,e.data).length>0)return!1;const s=ve(o.predicate,a);return s(r)?!0:ta(o.scope)&&i(o.scope).some(s)})},ax=(e,t)=>{const r=ur(e.mapping),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=ct(a,t,r),s=[];for(const c of e.data)ct(a,c,r)===o&&s.push(c);return n.set(a,s),s}},Ht=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=ft(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?ix(u,o):u;if(d<0||d>=o)break;const p=e.data.getAt(d);if(p===null||!n(p,d))continue;const m=s(p);if(m!==null&&!a.some(h=>qe(m,h)))return{anchor:m,observation:p,observationIndex:d}}return null},xl=(e,t)=>{const r=Co(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},qe=(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),ix=(e,t)=>(e%t+t)%t,Al=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=Me(e),a=xl(e,t),i=e.data.getAt(a);if(i===null)return null;const o=Q(i),s=m=>l.areDataValuesEqual(Q(m),o),c=[t],u=Ht({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=Ht({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=Ht({layer:e,excluding:c,from:0,step:1,accepts:m=>!s(m)&&l.areDataValuesEqual(m[n]??null,t.anchorValue)});return p!==null?{start:t,end:p.anchor}:null},ox=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=ft(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=Al({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>sx(s,o)))return o}}return null},sx=(e,t)=>qe(e.start,t.start)&&qe(e.end,t.end)||qe(e.start,t.end)&&qe(e.end,t.start),lx=(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}},cx=({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=Oo(t,r,c);if(u===null)return null;const d=ft(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},ux=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=Me(e),s=xl(e,t),c=e.data.getAt(s);if(c===null)return null;const u=dx(c),d=n==="main"?u:h=>!u(h)&&l.areDataValuesEqual(h[o]??null,t.anchorValue),p=Ht({layer:e,excluding:[t,r],from:s+a,step:a,accepts:(h,f)=>d(h)&&i(h,f)!==null,cycles:n!=="main"});if(p===null)return null;const m=i(p.observation,p.observationIndex);return m===null?null:{...p,point:m}},dx=e=>{const t=Q(e);return r=>l.areDataValuesEqual(Q(r),t)};function px({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=_({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var mx=({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"?hx(e,o,r):fx(e,t,o,r,i)},hx=(e,t,r)=>({kind:"grandTotal",value:_({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),fx=(e,t,r,n,a)=>{const i=_({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=_({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=_({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=zn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:bx(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:vx(s.caption,d),comparison:gx(s.comparison,d,i,a)}})}},gx=(e,t,r,n)=>e===null?null:{direction:yx(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},yx=e=>e>0?"up":e<0?"down":"flat",vx=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,bx=(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}},Sx=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>xx(i,a,t))},xx=(e,t,r)=>({...e,items:e.items.map(n=>{const a=_({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function na(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function Ax(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Ix=({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?hn:nt)(r.data,r.mapping)(a);return o===null?null:_({valueFormat:na(e,i?xe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},Tx=4,Lx=4,Ex=12,wx=4,Rx=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:Mr([Gt("value",r??"–"),Gt("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:_x(a),segments:Mr([Vx(a),Dx(a),Gt("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:Mr([Cx(i,t),Gt("label",o)])}].filter(s=>s.segments.length>0)},Gt=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},Cx=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},Vx=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Dx=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},_x=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}`}},Mr=e=>e.filter(t=>t!==null),gr=e=>e==="catmull-rom"?De.curveCatmullRom:De.curveLinear,Px=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Ox=(e,t)=>{const r=gr(t.interpolate),n=(0,De.area)().curve(r),a=(0,De.line)().curve(r);if(e.mainAxis==="y"){const i=c=>se(R(c)??0),o=c=>K(c)??0,s=c=>z(c)??D(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>D(c)??0,o=c=>se(B(c)??0),s=c=>se(M(c)??R(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>D(o)!==null&&R(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},Mx=(e,t)=>t!=="connect"?e:e.filter(r=>D(r)!==null&&R(r)!==null),aa={none:0,xs:2,sm:4,md:8,lg:12,xl:16},ia=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return aa[e.borderRadius??"sm"]},kx=e=>{const t=ia(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Nx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Il=(e,t)=>{const r=K(t),n=z(t),a=B(t),i=M(t)??R(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}},Tl=(e,t)=>e==="x"?`${J(t.x)}-${J(t.width)}`:`${J(t.y)}-${J(t.height)}`,Bx=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}},Fx=e=>{const t=(0,De.line)().x(r=>D(r)??0).y(r=>se(R(r)??0)).curve(gr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ll),t},$x=e=>{const t=(0,De.area)().x(r=>D(r)??0).y0(()=>1).y1(r=>se(R(r)??0)).curve(gr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ll),t},Gx=(e,t)=>t!=="connect"?e:e.filter(r=>D(r)!==null&&R(r)!==null),Ll=e=>D(e)!==null&&R(e)!==null,El=(0,De.arc)().cornerRadius(e=>e.cornerRadius??0);El.digits(8);var Ux=200,Hx=e=>El(e)??void 0,Wx=(e,t)=>e==="full"?Math.max(0,t)/2:aa[e??"sm"]/Ux,wl=(e,t)=>e==="x"?`${J(t.startAngle)}-${J(t.endAngle)}`:e==="y"?`${J(t.innerRadius)}-${J(t.outerRadius)}`:"sweep",Kx=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}},zx=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],yr=(e,t,r)=>{const n=nt(e,t);return a=>{const i=Q(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},Yx=(e,t,r)=>{const n=nt(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},qx=(e,t,r)=>{const n=nt(e,t),a=hn(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}`}},jx=()=>(e,t)=>Tt(e)??`default-${t}`,Oi=2,oa=(e,t,r,n)=>{const a=e.get("alpha",r);if(!ks(t,"bar"))return{alpha:a};const i=n.width-Oi,o=n.height-Oi,s=ia({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 sa(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 Xx(e,t,r){return sa(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>t})}function Zx(e,t,r){return sa(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>=t})}function Rl(e,t,r,n){const a=e==="x";return{mainDistance:Math.abs(t)*(a?n:1),crossDistance:Math.abs(r)*(a?1:n)}}function vr(e,t,r){return Math.hypot(e*r,t)}function Se(e,t,r){return e<t?t-e:e>r?e-r:0}function ee(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 Jx(e,t){const r=t.height,n=Math.min(t.width,t.height)/2;return{cartesian:Mi(e,r),polar:Mi(e,n)}}function Lt(e,t){return e<=t.on.point}function pt({mainDistance:e,crossDistance:t},r){return e<=r.near.main&&t<=r.near.cross}function Mi({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 Qx(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=Cl(e,s,t,r);return a===void 0||Lt(c.distance,a)||pt(c,a)?c:tA(e,t,r,a)??c}function eA(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 tA(e,t,r,n){const{mainAxis:a,byMain:i}=e,o=lt(a,t).main,s=a==="x"?n.near.main/r:n.near.main,c=Zx(i,o-s,ki(a)),u=Xx(i,o+s,ki(a));let d=null;for(let p=c;p<u;p+=1){const m=i[p];if(m===void 0)continue;const h=Cl(e,m,t,r);pt(h,n)&&(d===null||h.crossDistance<d.crossDistance)&&(d=h)}return d}function ki(e){return t=>lt(e,t).main}function Cl(e,t,r,n){const{main:a,cross:i}=lt(e.mainAxis,r),{main:o,cross:s}=lt(e.mainAxis,t);return{...Rl(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:vr(t.x-r.x,t.y-r.y,n)}}function Vl(e,t){return e.buckets[rA(e,t)]??null}function rA(e,t){return Pl(e.buckets,t,r=>r.main)}function nA(e,t){return _l(e.bands,t,r=>r.bandCenter)}function Dl(e,t){return _l(e.columns,t,r=>r.mainMid)}function _l(e,t,r){return e[Pl(e,t,r)]??null}function Pl(e,t,r){if(e.length===0)return-1;const n=sa(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 aA(e,t){return{group:iA(e),related:cA(e,t)}}function iA(e){switch(e.kind){case"buckets":{const t=e.match.index;return F(t.position)?oA(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return F(t.position)?sA(t.layerId,r,n.pointIndex):lA(t.bandByColumn,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function oA(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 sA(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(la(e,a));return n}function lA(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(la(t,s));return i}function cA(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||dA(r,i,e.match.hit);continue}e.kind==="buckets"&&(F(i.position)||i.kind==="buckets"&&uA(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function uA(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Wt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function dA(e,t,r){switch(t.kind){case"buckets":{const n=Vl(t,Y(t.mainAxis,r));if(!n)return;const a=Wt(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=nA(t,Y(t.mainAxis,r));if(!n)return;const a=Wt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(la(t.layerId,o));return}case"points":{const n=eA(t,r);if(!n)return;Wt(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 Wt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function la(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 Ol(e,t,r){const{columns:n,bands:a,bandByColumn:i}=pA(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 pA(e,t){const r=hA(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=J(c.mainMid);let d=n.get(u);if(!d){d={mainMid:c.mainMid,rects:[]},n.set(u,d);const p=J(c.bandCenter);let m=a.get(p);m||(m={bandCenter:c.bandCenter,columns:[],mainMin:1/0,mainMax:-1/0},a.set(p,m)),m.columns.push(d),i.set(d,m)}d.rects.push(c.entry),mA(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 mA(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 hA(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 m of r){const h=n[p],f=a[p],g=i[p],v=o[p];if(!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(v)){p++;continue}const y=s?(g+v)/2:(h+f)/2,b=u?.[p]??y;d.push({mainMid:y,bandCenter:b,entry:{pointIndex:p,xMin:Math.min(h,f),xMax:Math.max(h,f),yMin:Math.min(g,v),yMax:Math.max(g,v),observation:m}}),p++}return d}var fA=1e-9,Ni=-1;function Ml(e,t,r){const n=gA(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)<=fA?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 gA(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=F(e.position),m=n.hasVariable(u)?n.getValues(u,{type:"numeric"}):null,h=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 vA(yA(e)),v=new Map,y=[];let b=0;for(const A of n){const I=o[b],L=s[b],E=f?.[b]??null,re=bA(v,E);if(!l.isDefined(I)||!l.isDefined(L)){g.skip(E),b+=1;continue}const Le=c?L:I,T=m?.[b],P=p?h?.[b]:void 0;if(p&&(!l.isDefined(T)||!l.isDefined(P))){g.skip(E),b+=1;continue}const k=P??me(t,{x:I,y:L}),ne={pointIndex:b,...c?{x:k,y:L}:{x:I,y:k},groupKey:E,paintOrder:re,...e.spatialKind==="filled-buckets"&&l.isDefined(T)&&{fill:SA(T,k)},previousAt:Ni,nextAt:Ni,observation:A};g.append(E,{entry:ne,at:y.length}),y.push({main:Le,entry:ne}),b+=1}return r==="polar"&&g.close(),y}function yA(e){return"missingValues"in e.params&&e.params.missingValues==="gap"}var vA=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 bA(e,t){const r=e.get(t);if(r!==void 0)return r;const n=e.size;return e.set(t,n),n}function SA(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function kl(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:xA(e,t)}}function xA(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 m=a[d],h=i[d],f=o[d],g=s[d];if(!l.isDefined(m)||!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!Tt(p)){d++;continue}u.push({pointIndex:d,xMin:m,xMax:h,yMin:f,yMax:g,observation:p}),d++}return u}function an(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function AA(e,t,r){const n=Bl(e),a={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",mainAxis:t,points:n,byMain:TA(t,n),delaunay:null,delaunayAspectRatio:null};return Nl(a,r),a}function IA(e){const t=Bl(e).map(r=>{const n=pe(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 Nl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=zd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function TA(e,t){const r=n=>Y(e,n);return[...t].sort((n,a)=>r(n)-r(a))}function Bl(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 Fl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:LA(e)}}function $l(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function LA(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 Bi(e,t,r){return t.type==="polar"?EA(e,t.bandAxis):wA(e,t.mainAxis,r)}function EA(e,t){switch(e.spatialKind){case"points":return IA(e);case"buckets":case"filled-buckets":return Ml(e,"x","polar");case"rects":return t===null?kl(e,"polar"):Ol(e,t,"polar");case"cells":return an(e);case"noop":return an(e);case"render-hit-test":return Fl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function wA(e,t,r){switch(e.spatialKind){case"points":return AA(e,t,r);case"buckets":case"filled-buckets":return Ml(e,t,"cartesian");case"rects":return Ol(e,t,"cartesian");case"cells":return kl(e,"cartesian");case"noop":return an(e);case"render-hit-test":return Fl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function RA(e,t,r){if(e.columns.length===0)return null;const n=Y(e.mainAxis,t),a=Dl(e,n),i=a?.rects??[];if(!a||!l.isNonEmptyArray(i))return null;const o=F(e.position)?VA(i,t,e.mainAxis):DA(i,t,r),s=Gl(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:CA(e,a,n,r),crossDistance:0}}function CA(e,t,r,n){const a=e.bandByColumn.get(t);if(a===void 0)return Number.POSITIVE_INFINITY;const i=Se(r,a.mainMin,a.mainMax);return e.mainAxis==="x"?vr(i,0,n):i}function VA(e,t,r){const n=me(r,t);return ee(e,i=>_A(i,r,n),{shortCircuitOnZero:!0})}function DA(e,t,r){return ee(e,a=>Gl(a,t,r))}function Gl(e,t,r){return vr(Se(t.x,e.xMin,e.xMax),Se(t.y,e.yMin,e.yMax),r)}function _A(e,t,r){return Se(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function PA(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 OA(e,t,r){const{main:n,cross:a}=lt(e.mainAxis,t),i=Vl(e,n);if(i===null)return null;const o=i.entries.map(f=>({entry:f,crossAtCursor:kA(e,f,n)}));if(!l.isNonEmptyArray(o))return null;const s=Hl(o.filter(f=>BA(e,f.entry,n,a)),f=>f.entry),{entry:c}=s??ee(o,f=>Math.abs(f.crossAtCursor-a)),u=vr(c.x-t.x,c.y-t.y,r),d=f=>({x:f.x*r,y:f.y}),p=br(e,c).map(d),m=Ul(d(t),d(c),p,u),h=Rl(e.mainAxis,i.main-n,me(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?m:0,...h}}function MA(e,t,r){return ee(e,a=>Math.abs(me(r,a)-t))}function Ul(e,t,r,n){const a=r.map(i=>PA(e,t,i));return Math.min(n,...a)}function br(e,t){return[e.entries[t.previousAt],e.entries[t.nextAt]].filter(l.isDefined)}function Hl(e,t){return e.reduce((r,n)=>r===void 0||t(n).paintOrder>t(r).paintOrder?n:r,void 0)}function kA(e,t,r){const{mainAxis:n}=e,a=r===Y(n,t)?null:Wl(e,t,r);return a===null?me(n,t):NA(t,a,n,r)}function NA(e,t,r,n){const a=Y(r,e),i=(n-a)/(Y(r,t)-a),o=me(r,e);return o+(me(r,t)-o)*i}function Wl(e,t,r){const{mainAxis:n}=e,a=Y(n,t),i=o=>Math.sign(Y(n,o)-a)===Math.sign(r-a);return br(e,t).find(i)??null}function BA(e,t,r,n){const a=FA(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function FA(e,t,r){if(t.fill===void 0)return null;const{mainAxis:n}=e,a=Y(n,t);if(r===a)return t.fill;const i=Wl(e,t,r);if(i?.fill===void 0)return null;const o=(r-a)/(Y(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 $A(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 GA(e,t,r){if(e.columns.length===0)return null;const n=un(t,r),{angle:a,radius:i}=n,o=e.mainAxis==="x",s=o?WA(e.columns,a):Dl(e,i),c=s?.rects??[];if(!s||!l.isNonEmptyArray(c))return null;const u=o?KA(c,i):zA(c,a),d=UA(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:HA(e,s,n),crossDistance:0}}function UA(e,{angle:t,radius:r}){const n=ca(t,e.xMin,e.xMax),a=Se(r,e.yMin,e.yMax);return Math.hypot(n*r,a)}function ca(e,t,r){return qt(e,t,r)?0:Math.min(Ze(e,t),Ze(e,r))}function HA(e,t,{angle:r,radius:n}){const a=e.bandByColumn.get(t);return a===void 0?Number.POSITIVE_INFINITY:e.mainAxis==="x"?ca(r,a.mainMin,a.mainMax)*n:Se(n,a.mainMin,a.mainMax)}function WA(e,t){return l.isNonEmptyArray(e)?ee(e,r=>Ze(t,r.mainMid)):null}function KA(e,t){return ee(e,r=>Se(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function zA(e,t){return ee(e,r=>ca(t,r.xMin,r.xMax),{shortCircuitOnZero:!0})}var Fi=1e-9;function YA(e,t,r){if(e.buckets.length===0)return null;const n=ar(t,r),{angle:a,radius:i}=nr(n.x,n.y),o=qA(e.buckets,a),s=o?.entries??[];if(!o||!l.isNonEmptyArray(s))return null;const c=Hl(s.filter(h=>jA(e,h,a,i)),h=>h),u=c??MA(s,i,e.mainAxis),d=$i(u),p=Math.hypot(n.x-d.x,n.y-d.y),m=Ul(n,d,br(e,u).map($i),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?m:0,mainDistance:Ze(o.main,a)*i,crossDistance:Math.abs(i-u.y)}}function $i(e){return pe(e.x,e.y)}function qA(e,t){return l.isNonEmptyArray(e)?ee(e,r=>Ze(r.main,t)):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 n=ka(t.x,r);if(n===0)return t.fill;const a=c=>Math.sign(ka(t.x,c.x))===Math.sign(n),i=br(e,t).find(a);if(i?.fill===void 0)return null;const o=Gi(r,{angle:t.x,radius:t.fill.min},{angle:i.x,radius:i.fill.min}),s=Gi(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 Gi(e,t,r){const n=pe(t.angle,t.radius),a=pe(r.angle,r.radius),i={x:a.x-n.x,y:a.y-n.y};if(Math.hypot(i.x,i.y)<Fi)return t.radius;const o=Ui(pe(e,1),i);return Math.abs(o)<Fi?null:Ui(n,i)/o}function Ui(e,t){return e.x*t.y-e.y*t.x}function ZA(e,t,r,n=!1){if(e.cells.length===0)return null;const{angle:a,radius:i}=un(t,r);for(const u of e.cells)if(!(i<u.yMin||i>u.yMax)&&qt(a,u.xMin,u.xMax))return Hi(e,u,0);if(!n)return null;const o=e.cells.filter(u=>qt(a,u.xMin,u.xMax));if(!l.isNonEmptyArray(o))return null;const s=u=>Se(i,u.yMin,u.yMax),c=ee(o,s);return Hi(e,c,s(c))}function Hi(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 JA(e,t,r,n){if(!l.isNonEmptyArray(e.points))return null;const a=ar(t,r),i=Wi(e,ee(e.points,s=>Kl(s,a)),a);if(n===void 0||Lt(i.distance,n)||pt(i,n))return i;const o=e.points.map(s=>Wi(e,s,a)).filter(s=>pt(s,n));return l.isNonEmptyArray(o)?ee(o,s=>s.crossDistance):i}function Wi(e,t,r){const{angle:n,radius:a}=nr(r.x,r.y);return{mainDistance:Ze(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(Kl(t,r))}}function Kl(e,t){const r=e.unitX??pe(e.x,e.y).x,n=e.unitY??pe(e.x,e.y).y,a=r-t.x,i=n-t.y;return a*a+i*i}var QA=.05;function eI({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 m=sI(d,t,a);if(m)return{kind:"render-hit-test",match:m};continue}if(d.projection==="polar"){const m=oI(d,t,r,i?.polar);if(m&&!Ki(m,i?.polar))return m;continue}const p=iI({layer:d,cursor:t,aspectRatio:r,warmStarts:n,tolerance:i?.cartesian});if(!(!p||Ki(p,i?.cartesian))){if(p.kind==="banded"||p.kind==="enclosure"){const m=p.match.distance;m<o.distance&&(o.match=p,o.distance=m,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 zl(c,rI(s,o)).match}function tI(e,t){if(e.kind==="render-hit-test")return{intersects:!0,onPoint:!1};const r=nI(e,t),n=e.kind==="buckets"&&Lt(e.match.vertexDistance,r);return{intersects:Yl(e,r),onPoint:n}}function rI(e,t){return e.match!==null&&t.match!==null&&e.distance===0&&t.distance===0?e.paintOrder>t.paintOrder?e:t:zl(e,t)}function zl(e,t){return e.match===null?t:t.match===null||e.distance<=t.distance+QA?e:t}function Yl(e,t){switch(e.kind){case"banded":case"enclosure":return e.match.distance<=t.on.edge;case"buckets":return aI(e.match,t);case"points":return Lt(e.match.distance,t)}}function nI(e,t){return e.match.index.projection==="polar"?t.polar:t.cartesian}function aI(e,t){return e.strokeDistance<=t.on.stroke?!0:Lt(e.vertexDistance,t)}function Ki(e,t){return t===void 0?!1:!Yl(e,t)&&!pt(e.match,t)}function iI({layer:e,cursor:t,aspectRatio:r,warmStarts:n,tolerance:a}){switch(e.kind){case"buckets":{const i=OA(e,t,r);return i?{kind:"buckets",match:i}:null}case"banded":{const i=RA(e,t,r);return i?{kind:"banded",match:i}:null}case"points":{const i=Qx(e,t,r,n.get(e.layerId)??null,a);return i?{kind:"points",match:i}:null}case"enclosure":{const i=$A(e,t);return i?{kind:"enclosure",match:i}:null}case"noop":return null}}function oI(e,t,r,n){switch(e.kind){case"enclosure":{const a=ZA(e,t,r,n!==void 0);return a?{kind:"enclosure",match:a}:null}case"points":{const a=JA(e,t,r,n);return a?{kind:"points",match:a}:null}case"buckets":{const a=YA(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=GA(e,t,r);return a?{kind:"banded",match:a}:null}case"noop":case"render-hit-test":return null}}function sI(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:$l(e.layerId,i)}:null}var ae={primary:null,group:[],related:new Map},lI=1,cI=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.viewport=null,this.aspectRatio=lI,this.isAspectStale=!1,this.warmStarts=new Map,this.cachedState=ae,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=ae,this.layerIndexes=e.map(r=>Bi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>zi(r,t)),this.nonInteractiveLayerIds=Yi(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=zi(i,t);if(o!==void 0&&dI(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push(Bi(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=Yi(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 ae;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?Jx(t,this.viewport):void 0,a=eI({layers:r,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e,tolerance:n});if(!a)return this.invalidateCache(),ae;const i=a.match.hit;this.warmStarts.set(i.layerId,i.pointIndex);const o=n===void 0?void 0:tI(a,n),s=uI(i,o);if(this.cachedKey===s)return this.cachedState;const{group:c,related:u}=aA(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 ae;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return ae;const n=r.byKey.get(t);if(!n)return ae;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:$l(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=ae,this.cachedByKeyId=null,this.cachedByKeyState=ae}reindexForAspect(){if(this.isAspectStale){this.isAspectStale=!1;for(const e of this.layerIndexes)e.kind==="points"&&e.projection==="cartesian"&&Nl(e,this.aspectRatio)}}};function uI(e,t){const r=`${e.layerId}:${e.pointIndex}`;return t===void 0?r:`${r}:${t.intersects}:${t.onPoint}`}function zi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Yi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function dI(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var pI=Math.PI*2;function mI(e,t){const r=Y(e.mainAxis,t);if(e.mainAxis==="y"){const a=Ce(se(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=Ce(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function hI(e,t,r){const n=e.mainAxis==="y"?R(r.observation):D(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?jl(r):ql(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:Ce(se(n+o)),width:"100%",height:Ce(i)}:{x:Ce(n-o),y:0,width:Ce(i),height:"100%"}}function fI(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=K(t.observation),i=z(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=B(t.observation),n=M(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+pI,innerRadius:r,outerRadius:n}}function ql(e){const t=K(e.observation),r=z(e.observation);return t===null||r===null?null:r-t}function jl(e){const t=B(e.observation),r=M(e.observation);return t===null||r===null?null:r-t}function gI(e){return e.observationIndex??e.pointIndex}function Xl(e){return e==="buckets"||e==="filled-buckets"}var Sr=.5,yI=.3,vI=.4,bI=10,SI=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?AI(e,t,r,n):II(e,t,n):Xl(e.spatialKind)&&t.type==="cartesian"?EI(e,t,n):e.spatialKind==="cells"?LI(e,n):e.spatialKind==="points"?TI(e,n):null,xI=e=>{if(Xl(e.spatialKind)){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},AI=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:Sr*n.durationScale,baseline:wI(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?RI(e,t.mainAxis,n):{}}),II=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:Sr*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?DI(e,t,r):{}}},TI=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:Sr*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?CI(e,t):{}}),LI=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:yI*t.durationScale}),EI=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:Sr*r.durationScale,axis:t.mainAxis}),wI=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[xe(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},RI=(e,t,r)=>{const n=yr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=Il(t,i);if(!o)continue;const s=Tl(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 ua([...a.values()],r)},CI=(e,t)=>{const r=yr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=VI(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return ua(n,t)},VI=(e,t)=>{if(t==="main-axis")return D(e);const r=qn(e)??D(e);return r===null?null:t==="value-descending"?-r:r},DI=(e,t,r)=>{const n=yr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=Zn(i),{innerRadius:c,outerRadius:u}=Jn(i);if(o===null||s===null||c===null||u===null)continue;const d=wl(t.bandAxis,{startAngle:o,endAngle:s,innerRadius:c,outerRadius:u}),p=n(i),m=a.get(d);m?m.keys.push(p):a.set(d,{position:o,keys:[p]})}return ua([...a.values()],r)},ua=(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/bI),i=Math.ceil(n.length/a),o=vI*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},ze=["top","right","bottom","left"],qi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},_I={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},PI={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},OI=(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]=PI[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=kI(t,a),s=NI(t,a,i);return BI(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:FI(c,o,s,i)}))},MI=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),kI=(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}}},NI=(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")}}}},BI=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(ze.indexOf(o)+s+ze.length)%ze.length;return ze[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=ze.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...ze],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}})},FI=(e,t,r,n)=>{const a=(p,m,h)=>({type:"arc",cx:p.cx,cy:p.cy,radius:p.radius,startAngle:m,endAngle:h}),i=p=>(p.startAngle+p.endAngle)/2,o=[],s=e.firstEdge,c=e.edges[e.edges.length-1],u=qi[s];if(!e.isClosed&&n(u)){const p=t[u],m=i(p),h=$I(p,m);o.push({type:"move",x:h.x,y:h.y}),o.push(a(p,m,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 m=qi[p];if(n(m)){const h=t[m];o.push(a(h,h.startAngle,h.endAngle))}o.push({type:"line",x:r[p].end.x,y:r[p].end.y})}const d=_I[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},$I=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),GI=/^(?:https?:|mailto:)/i,UI=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:GI.test(t)},HI=({locale:e,intlOptions:t})=>U(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...H,...t}).format(r)),WI=({locale:e,intlOptions:t})=>U(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,...H,...t}).format(r)}),er=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Gs(e);case"date":return HI(e);case"datetime":return WI(e);case"day_month":return Ks(e);case"decimal":return Us(e);case"duration":return Bn(e);case"integer":return Hs(e);case"month":return zs(e);case"month_year":return Gn(e);case"percentage":return Ws(e);case"quarter":return Un(e);case"text":return Nn(e);case"time":return js(e);case"weekly_date_range":return Ys(e);case"weekly_date_range_with_year":return qs(e);case"year":return Hn(e);case"lookup":return er({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Zl={width:12,height:12},KI=({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 m=c??i,h=zI(u,d);return{header:h===null?YI({layers:e,coordSystem:t,guides:n,primary:p,locale:m,numberFormat:a}):null,rows:qI({layers:e,scales:r,guides:n,hover:o,locale:m,numberFormat:a,colorScheme:s}),comment:h}};function zI(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function YI(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=na(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)?er({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function qI(e){const t=[],r=e.scales.color??null,n=at({colorScheme:e.colorScheme}),a=JI({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=XI(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...jI(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=bo(i.data,i.mapping),u=ZI(o,i,r,c),d=Qn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=QI(e.guides,i),m=ht(i),h=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const v=h?c(g.observation):null,y=f.get("color",g.observation),b=f.get("lineType",g.observation)??"solid",A=oa(f,i,g.observation,Zl),I=h&&v!==null?a(v):p,L=m(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:I,value:E,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function jI(e,t,r,n,a){const i=oa(n,e,t.observation,Zl);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=j(e.data,s)(t.observation),d=_({valueFormat:vn(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??cr(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function XI(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 ZI(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 JI({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:er({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=er({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 QI(e,t){return cr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function eT(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function tT(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var rT=(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")}},nT=(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")}},aT=(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:{...W(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")}}},iT=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...W(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")}},oT=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},sT=(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:{...W(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")}}},lT=e=>e.borderWidth>0?e.borderColor??e.color:void 0,cT=e=>({edges:{top:je(e.panelBorder("top")),right:je(e.panelBorder("right")),bottom:je(e.panelBorder("bottom")),left:je(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),uT=(e,t)=>je(e.gridLine(t)),dT=(e,t)=>{const r=e.tickLine(t);return{...je(r),length:r.get("length")}},pT=e=>e.heading.get("fontFamily")??e.graph.get("fontFamily"),mT=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")}},hT=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}},fT=e=>{const t=e.legend.popover;return{gap:e.legend.gap.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")}}},gT=e=>({gap:e.headline.get("gap")}),yT=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"},je=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),da=["sticker","pinnedNumber","comment","image"],bT=e=>da.includes(e),pa=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?xT(e.annotation.at):null;default:return null}},Jl=(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),Ql=(e,t,r=ST)=>{const n=r(t);for(const a of da){const i=xt(e,a),o=i.findIndex(c=>{const u=pa({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return Jl(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},ST=e=>({...e,anchorValue:kr(e.anchorValue),...e.groupValue!==void 0&&{groupValue:kr(e.groupValue)},...e.crossValue!==void 0&&{crossValue:kr(e.crossValue)}}),kr=e=>l.readISOInstant(e)??e,xT=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function AT(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var IT=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ma(r.predicate,t.predicate))??null,ma=(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&&ma(e.not,t.not):TT(t)&&e.variable===t.variable&&LT(e,t),TT=e=>"variable"in e,ji=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ma(r,a)}),LT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Xi(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&&Xi(e.range,t.range),Xi=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ET={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},wT=e=>Object.hasOwn(ET,e);function RT(e){return{type:"mapping",mapping:e}}var Et=(e,t)=>"and"in e?"and"in t&&Zi(e.and,t.and):"or"in e?"or"in t&&Zi(e.or,t.or):"not"in e?"not"in t&&Et(e.not,t.not):CT(t)&&e.variable===t.variable&&VT(e,t),CT=e=>"variable"in e,Zi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Et(r,a)}),VT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ji(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&&Ji(e.range,t.range),Ji=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ec=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)))),tc=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),rc=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function nc(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(DT),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function DT(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?_T(r):r}function _T(e){return{...e,palette:PT(e.palette),overrides:OT(e.overrides)}}function PT(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function OT(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var wt=(e,t)=>{const r=ha(e,t);return r===-1?void 0:e[r]},ha=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&xr(n,t))return r}return-1},xr=(e,t)=>MT(e.select,t.select)&&e.when?.state===t.when?.state&&kT(e.when?.where,t.when?.where),ac=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>NT(e[r],t[r])),Ve=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),fa=e=>e.select.target==="geom",Rt=(e,t)=>{const r=wt(e,t);if(!(r===void 0||!fa(r)))return r.declarations},MT=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},kT=(e,t)=>e===void 0||t===void 0?e===t:Et(e,t),NT=(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??G(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function tt(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>tt(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=>tt(e[a],t[a]))}return!1}var ga=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=St(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:w(e,{annotations:Ts(e.annotations,t)}),revert:new ya({kind:r,annotation:a,index:n},this.metadata)}}},BT={type:"remove-annotation",deserialize:(e,t)=>new ga(e,t)},ya=class ic{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??G()},...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(!Hg(r)||St(t.annotations,n.id))return null;const i=$T(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:Ts(t.annotations,i),s=xt(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:w(t,{annotations:On(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new ga({id:n.id},this.metadata):new ic({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},FT={type:"add-annotation",deserialize:(e,t)=>new ya({kind:e.kind,annotation:e.annotation,index:e.index},t)},$T=(e,t)=>{const r=pa(t);return r===null?null:Ql(e,r)},GT=(e,t)=>{const r=va(e);return r===null?null:oc(r.points,t)},UT=e=>va(e)!==null,HT=(e,t)=>{const r=va(e);if(r===null)return null;const n=oc(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},va=e=>{const t=KT[e.kind];return t===null?null:t(e.annotation)},Qi=(e,t)=>e.anchorType!=="panel"?null:{points:[on(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},eo=(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})},WT=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[on(e,e.offset),on(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}})},KT={text:e=>Qi(e.at,t=>({at:t})),sticker:e=>Qi(e.at,t=>({at:t})),shape:e=>eo(e.region,t=>({region:t})),image:e=>eo(e.region,t=>({region:t})),arrow:e=>WT(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},on=(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)},oc=(e,t)=>({x:to(e.map(r=>r.x),t.x),y:to(e.map(r=>r.y),t.y)}),to=(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,Xe.default)(t,r,n)},sc=(e,t,r)=>{const n=t.annotation;if(!qT(n,r))return null;const a=xt(e.annotations,t.kind),i=zT(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:w(e,{annotations:On(e.annotations,t.kind,o)}),inverse:YT(n,r)}},zT=(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)))},YT=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},qT=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),ba=class lc{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=St(t.annotations,n);if(i===null||i.kind!==r)return null;const o=sc(t,i,a);return o===null?null:{spec:o.spec,revert:new lc({kind:r,id:n,patch:o.inverse},this.metadata)}}},jT={type:"update-annotation",deserialize:(e,t)=>new ba(e,t)},cc=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=St(e.annotations,this.params.id);if(t===null)return null;const r=HT(t,this.params.translation);if(r===null)return null;const n=sc(e,t,r);return n===null?null:{spec:n.spec,revert:new ba({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},XT={type:"move-annotation",deserialize:(e,t)=>new cc(e,t)},fe=class Kt{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=ha(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new Kt({list:r,rule:s,index:o},this.metadata),g=i.filter(v=>!xr(v,n));return{spec:Nr(t,r,g),revert:f}}if(s!==void 0){if(ac(s.declarations,c))return null;const f={...s,declarations:c},g=new Kt({list:r,rule:s,index:o},this.metadata),v=i.map(y=>y===s?f:y);return{spec:Nr(t,r,v),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),p={...n,declarations:c},m=[...i.slice(0,d),p,...i.slice(d)],h=new Kt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:Nr(t,r,m),revert:h}}},ZT=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."})},JT={type:"set-style-rule",deserialize:(e,t)=>(ZT(e),new fe(e,t))},Nr=(e,t,r)=>w(e,{styles:{...e.styles,[t]:r}}),QT={type:"set-difference-arrow-style",deserialize:(e,t)=>new uc(e,t)},uc=class dc{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=wt(s.styles.overrides,d),m=new fe({list:"overrides",rule:d}).apply(s);if(m)return s=m.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 dc(c,this.metadata)}}},eL=["cartesian","polar","flip"],q=new dr,pc=e=>q.has(e)?q.get(e):null,mc=new l.TransformRegistry,tL=new Ps(mc),Ar=e=>{const t=e.transforms.every(r=>mc.has(r.transformType));return e.transforms.length===0||!t?e.data:tL.compile({data:e.data,transforms:e.transforms})};function Sa(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 Ct(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function Vt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:w(e,{scales:To(e.scales,n,r)})}function Dt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function sn(e,t,r){const n=mr(Dn(Os(q),{data:Ar(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?_n(n):n}var hc=class fc{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:mL(t)})}apply(t){const r="previous"in this.params?this.params.previous:hL(t,this.params);if(r===null)return null;const n=w(t,r);return n===t?null:{spec:n,revert:new fc({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},rL={type:"set-chart-type",deserialize:(e,t)=>new hc(e,t)},gc={type:"sum"},nL={type:"identity"},aL=["bar","line","area","point","tile"],xa="tile",iL=["y","color"],oL=Object.values(l.LAYER_LABEL_VARIABLES),sL={coordType:"cartesian",geom:xa,position:"identity"},_t=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),lL=e=>{const t=e.layers.filter(le),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=vc(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}},cL=e=>{if(!e)return!1;const t=e.layers.filter(le);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:bc(e,r)?Sc(e,r).length>=1:Ir(e,e.data.groupVariableNamesByType().numeric).length>=2},uL=e=>e?Ec(e,sL)!==null:!1,dL=e=>yc(e)?.at(-1)?.id??null,yc=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(le);return vc(t)===null?null:t},vc=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 pL(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)},pL=e=>e.some(t=>t.yScaleType==="secondary"||tr(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,mL=e=>"previous"in e?"Restore the previous chart type":_t(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,hL=(e,t)=>{const r=Ec(e,t);if(r===null)return null;const n=_t(t)?gL(r,t):fL(r,t,e);return n===null||r===e?n:{...n,scales:CL({...e,...n},n.scales)}},fL=(e,t,r)=>{if(_t(t)||!VL(t))return null;const n={...e,layers:Pc(e.layers)},a=PL(n.layers.filter(le),t),i=Mc(n.coords,t),o=Tc(n,t),s=_c({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:Sa(kc(r,s,i.coordType),s),mapping:o}},gL=(e,t)=>{const r=bL(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=OL(r.filter(le),t.comboType),i=Mc(n.coords,t),o=Tc(n,t),s=_c({...n,mapping:o},t,a,o!==n.mapping),c=yL(e)?s:vL(s);return{coords:i,layers:c,scales:Sa(kc(e,c,i.coordType),c),mapping:o}},yL=e=>yc(e)!==null,vL=e=>{const t=e.filter(le).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},bL=(e,t)=>{const r=e.layers.filter(le);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:bc(e,n)?SL(e,n):xL(e,n,t)},bc=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},SL=(e,t)=>{const[r]=Sc(e,t);if(r===void 0)return null;const n=$e(q,e.mapping,e.coords.coordType,{type:"layer",id:xc(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:gc,...Ic(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},Ir=(e,t)=>{const r=Pt(e);return t.filter(n=>n!==r)},Sc=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return Ir(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},Pt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),xL=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=Ir(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,Pt(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=AL(t,ro(a.slice(0,-1),o,s)),u=$e(q,e.mapping,e.coords.coordType,{type:"layer",id:xc(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...ro([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},xc=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},ro=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?Ic(n,r):Ac(e,t)},Ac=(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})]}),Ic=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),AL=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Tc=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Lc(t)?"":Pt(e);return n===r?e.mapping:{...e.mapping,x:n}},Lc=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",IL=e=>!_t(e)&&e.geom===xa,TL=e=>e.layers.filter(le).some(t=>t.geom===xa),Ec=(e,t)=>{const r=IL(t);return r===TL(e)?e:r?LL({...e,layers:Pc(e.layers)}):EL(e)??e},LL=e=>{const t=Rc(e);if(t===null)return null;const r=wL(e,t)===null?RL(e,t):Cc(e,t);return r===null?null:wc(e,t,r)},EL=e=>{const t=Rc(e);if(t===null)return null;const r=Cc(e,t);return r===null?null:wc(e,t,r)},wc=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Rc=e=>{const t=e.layers.filter(le);return t.length===1?t[0]??null:null},Cc=(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:Vc(t)}},Vc=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}},wL=(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===Pt(e))return null;const i=Ar(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},RL=(e,t)=>{const r=Ir(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,Pt(e)),a=Ac(r,n),i=Vc(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},CL=(e,t)=>iL.reduce((r,n)=>{const a=sn(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?ke(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),VL=e=>eL.includes(e.coordType)&&Dc(e.geom)&&DL(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),DL=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=q.get(e);return n.includes(t)&&a.includes(r)},Dc=e=>aL.includes(e),le=e=>Dc(e.geom)&&!_L(e.stat),_L=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},PL=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},OL=(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:ML(i,t,n)}]);return new Map(a)},ML=(e,t,r)=>e.geom!=="bar"||tr(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,_c=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Ss(q,ke(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=kL(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?BL(e,{...i,stat:s},t.coordType,o):i}))},kL=(e,t,r)=>Lc(r)?e.type==="identity"?gc:e:NL(t)&&e.type==="sum"?nL:e,NL=e=>e.coordType==="polar"&&e.params.theta==="y",BL=(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{...$e(q,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}},Pc=e=>{const t=e.filter(le);if(t.length<2||!e.some(tr))return e;const[r]=t;return e.flatMap(n=>n===r?[FL(n)]:tr(n)?[]:[n])},tr=e=>Oc(e)!==null,Oc=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:oL.includes(t.options.variableName)?t:null},FL=e=>{const t=Oc(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)}},Mc=(e,t)=>{const r=$L(e,t);return(0,Yt.default)(r,e)?e:r},$L=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return qr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Ut;return qr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},kc=(e,t,r)=>{const n=Kr(q,t),a=Kr(q,e.layers),i=e.coords.coordType==="polar";return ke(e.scales,o=>{const s=GL(o,n,a),c=UL(s,n,a);return WL(c,r,i)})},GL=(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 Yr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Yr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=HL(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},UL=(e,t,r)=>{if(e.scaleType!=="discrete"||!Be(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}},HL=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,WL=(e,t,r)=>{if(e.scaleType!=="discrete"||!Be(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}},Nc=class Bc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:zL(t)})}apply(t){const r="previous"in this.params?this.params.previous:YL(t,this.params);if(r===null)return null;const n=w(t,r);return n===t?null:{spec:n,revert:new Bc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},KL={type:"set-mapping",deserialize:(e,t)=>new Nc(e,t)},Fc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},$c=e=>e===""?null:e,zL=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=$c(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},YL=(e,{aesthetic:t,variable:r})=>{if(!wT(t))return null;const n=$c(r),a=jL(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:ZL(e,t,a,n),layers:qL(e.layers,a)}},qL=(e,t)=>ke(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&pc(r.geom)===null)return r;const a=bs(q,r.geom,r.position,n);return(0,Yt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),jL=(e,t,r)=>r===null?XL(e,t):Fc(e,t)===r?e:{...e,[t]:r},XL=(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},ZL=(e,t,r,n)=>{if(!$o(t))return e.scales;let a=e.scales;for(const i of JL(e,t))a=eE(e,a,i,r,n);return a},JL=(e,t)=>t==="y"&&QL(e.layers)?["y","ySecondary"]:[t],QL=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},eE=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,sn(e,r,n)];if(a===null&&!Be(r)||a!==null&&!Ar(e).hasVariable(a))return t;const o=sn(e,r,n);return tE(i,o)?t:ke(t,s=>s.scaledAesthetic===r?o:s)},tE=(e,t)=>e.scaleType===t.scaleType||no(e)&&no(t),no=e=>e.scaleType==="discrete"||e.scaleType==="palette",Aa=e=>e==="both"?["x","y"]:[e],Gc=e=>e==="both"?"the":`${e} axis`;function Ia(e,t){return Tr(e)?e[t]:e}function rE(e,t){return e.config.axes[t]??{}}function nE(e,t,r){if(t!=="ySecondary")return V(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=Uc(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,w(e,{config:w(e.config,{axes:i})})}function Tr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function Uc(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?aE(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 aE(e,t){return l.isPlainObject(t)?Uc(l.isPlainObject(e)?e:void 0,t):t}var Hc=class Wc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${oE(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=rE(t,r).label;if(a===n)return null;const i=nE(t,r,{label:n});return i===t?null:{spec:i,revert:new Wc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},iE={type:"set-axis-label",deserialize:(e,t)=>new Hc(e,t)};function oE(e){return e===void 0?"(inherited)":e??"(none)"}var Kc=class zc{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:V(t,{config:{axes:{[r]:{position:n}}}}),revert:new zc({axis:r,position:a},this.metadata)}}},sE={type:"set-axis-position",deserialize:(e,t)=>new Kc(e,t)},Yc=class qc{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:V(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new qc({axis:r,tickMode:a},this.metadata)}}},lE={type:"set-axis-tick-mode",deserialize:(e,t)=>new Yc(e,t)},jc=class Xc{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:V(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new Xc({axis:r,isVisible:a},this.metadata)}}},cE={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new jc(e,t)},Zc=class Jc{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:V(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new Jc({axis:r,isVisible:a},this.metadata)}}},uE={type:"set-axis-visibility",deserialize:(e,t)=>new Zc(e,t)},Qc=class eu{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:V(t,{config:{content:{caption:this.params.caption}}}),revert:new eu({caption:r},this.metadata)}}},dE={type:"set-content-caption",deserialize:(e,t)=>new Qc(e,t)},tu=class ru{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(tt(r,this.params.source))return null;const n=w(t.config.content,{source:this.params.source});return{spec:w(t,{config:w(t.config,{content:n})}),revert:new ru({source:r},this.metadata)}}},pE={type:"set-content-source",deserialize:(e,t)=>new tu(e,t)},nu=class au{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:V(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new au({subtitle:r},this.metadata)}}},mE={type:"set-content-subtitle",deserialize:(e,t)=>new nu(e,t)},iu=class ou{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:V(t,{config:{content:{title:this.params.title}}}),revert:new ou({title:r},this.metadata)}}},hE={type:"set-content-title",deserialize:(e,t)=>new iu(e,t)},fE="dashed",gE=1,su=(e,t,r,n)=>{const a=yE(t,r),i=bE(e,a,n);let o=e,s=!1;for(const c of a){const u=xE(o,c,n,SE(n,vE(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},yE=(e,t)=>e==="both"&&!Tr(t)?[void 0]:Aa(e),vE=(e,t)=>t===void 0?Tr(e)?e.x:e:Ia(e,t),bE=(e,t,r)=>t.length===1?Br(e,t[0],r):{x:Br(e,"x",r),y:Br(e,"y",r)},Br=(e,t,r)=>lu(e.styles.overrides,t)?.[r]??null,SE=(e,t)=>t===null||e==="lineType"&&t===fE||e==="strokeWidth"&&t===gE?null:t,xE=(e,t,r,n)=>{const a=lu(e.styles.overrides,t);return(a?.[r]??null)===n?null:new fe({list:"overrides",rule:TE(t,IE(a,r,n))}).apply(e)?.spec??null},AE=e=>e.select.target==="gridLine",lu=(e,t)=>{const r=wt(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!AE(r)))return r.declarations},IE=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},TE=(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),cu=class uu{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${Gc(t.axis)} grid line style to ${EE(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=su(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new uu({axis:r,lineStyle:a.previous},this.metadata)}}},LE={type:"set-grid-line-style",deserialize:(e,t)=>new cu(e,t)},EE=({axis:e,lineStyle:t})=>{const r=Aa(e).map(n=>Ia(t,n)??"(theme)");return[...new Set(r)].join(" and ")},wE={type:"set-grid-line-width",deserialize:(e,t)=>new du(e,t)},du=class pu{constructor(t,r={}){this.type="set-grid-line-width";const n=RE(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${Gc(t.axis)} grid line width to ${CE(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=su(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new pu({axis:r,lineWidth:a.previous},this.metadata)}}},RE=e=>Tr(e)?{x:Fr(e.x),y:Fr(e.y)}:Fr(e),Fr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),CE=(e,t)=>{const r=Aa(e).map(n=>Ia(t,n)??"(theme)");return[...new Set(r)].join(" and ")},mu=class hu{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:V(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new hu({axis:r,isVisible:a},this.metadata)}}},VE={type:"set-grid-visibility",deserialize:(e,t)=>new mu(e,t)},fu=class gu{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:V(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new gu({compareWith:r},this.metadata)}}},DE={type:"set-headline-compare-with",deserialize:(e,t)=>new fu(e,t)},yu=class vu{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:V(t,{config:{headline:{position:this.params.position}}}),revert:new vu({position:r},this.metadata)}}},_E={type:"set-headline-position",deserialize:(e,t)=>new yu(e,t)},bu=class Su{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:V(t,{config:{headline:{show:this.params.show}}}),revert:new Su({show:r},this.metadata)}}},PE={type:"set-headline-show",deserialize:(e,t)=>new bu(e,t)},xu=class Au{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:V(t,{config:{headline:{size:this.params.size}}}),revert:new Au({size:r},this.metadata)}}},OE={type:"set-headline-size",deserialize:(e,t)=>new xu(e,t)},ME={type:"set-highlight-dim-style",deserialize:(e,t)=>new Iu(e,t)},Iu=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(Tu(e)===this.params.dimStyle)return null;const t=new fe({list:"overrides",rule:NE(this.params.dimStyle)},this.metadata).apply(e);return t||null}},kE={select:{target:"geom"},when:{state:"dimmed"}},Tu=e=>{const t=wt(e.styles.overrides,kE);return(t!==void 0&&fa(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},NE=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Lu=class Eu{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:V(t,{config:{legend:{align:this.params.align}}}),revert:new Eu({align:r},this.metadata)}}},BE={type:"set-legend-align",deserialize:(e,t)=>new Lu(e,t)},wu=class Ru{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:V(t,{config:{legend:{display:this.params.display}}}),revert:new Ru({display:r},this.metadata)}}},FE={type:"set-legend-display",deserialize:(e,t)=>new wu(e,t)},Cu=class Vu{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:V(t,{config:{legend:{position:this.params.position}}}),revert:new Vu({position:r},this.metadata)}}},$E={type:"set-legend-position",deserialize:(e,t)=>new Cu(e,t)},Du=class _u{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:V(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new _u({abbreviation:r},this.metadata)}}},GE={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Du(e,t)},Pu=class Ou{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:V(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Ou({decimals:r},this.metadata)}}},UE={type:"set-number-format-decimals",deserialize:(e,t)=>new Pu(e,t)},Mu=class ku{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=WE(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:V(t,{config:{content:{[a]:n}}}),revert:new ku({slot:r,isVisible:i},this.metadata)}}},HE={type:"toggle-content-visibility",deserialize:(e,t)=>new Mu(e,t)},ao={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function WE(e){return Object.hasOwn(ao,e)?ao[e]:void 0}var Nu=class Bu{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(tt(i.xLimits,a.xLimits)&&tt(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 Bu(o,this.metadata);return{spec:w(t,{coords:zE(t.coords,i)}),revert:s}}},KE={type:"set-coord-limits",deserialize:(e,t)=>new Nu(e,t)};function zE(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 Fu=class $u{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Xe.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:w(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new $u({innerRadius:n},this.metadata)}}},YE={type:"set-polar-inner-radius",deserialize:(e,t)=>new Fu(e,t)},qE={type:"set-polar-start-angle",deserialize:(e,t)=>new Gu(e,t)},Gu=class Uu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:io(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 io(n)===this.params.startAngle?null:{spec:w(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Uu({startAngle:n},this.metadata)}}},$r=360,io=e=>(e%$r+$r)%$r,Ta=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 La({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:w(e,{highlights:n}),revert:a}}},jE={type:"remove-highlight",deserialize:(e,t)=>new Ta(e,t)},La=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??G(),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 Ta({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:w(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},XE={type:"add-highlight",deserialize:(e,t)=>new La(e,t)};function Ea(e,t){return{...e,params:{...e.params,...t}}}function Lr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function wa(e,t){return w(e,{layers:[...e.layers,t]})}function X(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:w(e,{layers:To(e.layers,n,r)})}function Er(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:w(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Ra=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=Er(e,this.params.layerId);return n===e?null:{spec:n,revert:new Ca({layer:r,index:t},this.metadata)}}},ZE={type:"remove-layer",deserialize:(e,t)=>new Ra(e,t)},Ca=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??G()},...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:w(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Ra({layerId:t.id},this.metadata)}}},JE={type:"add-layer",deserialize:(e,t)=>new Ca(e,t)},Hu=class Wu{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(!te(O(t.layers,r),"bar"))return null;const a=Ve("bar",r),i=Rt(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new fe({list:"overrides",rule:{...a,declarations:ew(i,n)}}).apply(t);if(!s)return null;const c=new Wu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},QE={type:"set-bar-border-radius",deserialize:(e,t)=>new Hu(e,t)},ew=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},tw={type:"set-bar-width",deserialize:(e,t)=>new zu(e,t)},Ku=.05,rw=1,zu=class Yu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Xe.default)(t.width,Ku,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?O(t.layers,this.params.layerId):Ie(t.layers,"bar");if(!te(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:X(t,r.id,Ea(r,{width:this.params.width})),revert:new Yu({layerId:r.id,width:n},this.metadata)}}},qu=class ju{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?O(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:X(t,r.id,Lr(r,{format:this.params.format})),revert:new ju({layerId:r.id,format:n},this.metadata)}}},nw={type:"set-data-labels-format",deserialize:(e,t)=>new qu(e,t)},Xu=class Zu{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?O(t.layers,this.params.layerId):Ie(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:X(t,r.id,{...r,position:this.params.position}),revert:new Zu({layerId:r.id,position:n},this.metadata)}}},aw={type:"set-layer-position",deserialize:(e,t)=>new Xu(e,t)},Ju=class Qu{constructor(t,r={}){this.type="set-layer-stat";const n=vs(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?O(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return ow(n,this.params.stat)?null:{spec:X(t,r.id,{...r,stat:this.params.stat}),revert:new Qu({layerId:r.id,stat:n},this.metadata)}}},iw={type:"set-layer-stat",deserialize:(e,t)=>new Ju(e,t)},ow=(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},ed=class td{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?O(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=X(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:w(a,{scales:Sa(a.scales,a.layers)}),revert:new td({layerId:r.id,yScaleType:n},this.metadata)}}},sw={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ed(e,t)},rd=class nd{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?O(t.layers,this.params.layerId):Ie(t.layers,"line","area");if(!te(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:X(t,r.id,Ea(r,{interpolate:this.params.interpolate})),revert:new nd({layerId:r.id,interpolate:n},this.metadata)}}},lw={type:"set-line-interpolation",deserialize:(e,t)=>new rd(e,t)},ad=class id{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?O(t.layers,this.params.layerId):Ie(t.layers,"line","area");if(!te(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:X(t,r.id,Ea(r,{missingValues:this.params.missingValues})),revert:new id({layerId:r.id,missingValues:n},this.metadata)}}},cw={type:"set-line-missing-values",deserialize:(e,t)=>new ad(e,t)},od=class sd{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=O(t.layers,r);if(!te(a,"line","area"))return null;const i=Rt(t.styles.overrides,Ve(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=dw(i,n),c=new fe({list:"overrides",rule:a.geom==="area"?{...Ve("area",r),declarations:s}:{...Ve("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new sd({layerId:r,lineWidth:o},this.metadata)}:null}},uw={type:"set-line-width",deserialize:(e,t)=>new od(e,t)},dw=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},ld=class cd{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(!te(O(t.layers,r),"point"))return null;const a=Ve("point",r),i=Rt(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new fe({list:"overrides",rule:{...a,declarations:mw(i,n)}}).apply(t);return s?{spec:s.spec,revert:new cd({layerId:r,size:o},this.metadata)}:null}},pw={type:"set-point-size",deserialize:(e,t)=>new ld(e,t)},mw=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},ud=class dd{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?O(t.layers,this.params.layerId):Ie(t.layers,"rule");if(!te(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:X(t,r.id,{...r,params:i}),revert:new dd({layerId:r.id,label:n??null},this.metadata)}}},hw={type:"set-rule-label",deserialize:(e,t)=>new ud(e,t)},pd=class md{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?O(t.layers,this.params.layerId):Ie(t.layers,"rule");if(!te(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:X(t,r.id,{...r,mapping:i}),revert:new md({layerId:r.id,value:a},this.metadata)}}},fw={type:"set-rule-value",deserialize:(e,t)=>new pd(e,t)},gw={type:"set-stat-line",deserialize:(e,t)=>new hd(e,t)},hd=class fd{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:Iw(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&&Aw(r.layer,n))return null;const a=new fd({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:X(t,r.layer.id,n),revert:a};const i=r===void 0?t:Er(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:wa(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"?bw(this.params):Sw(t,this.params);if(n===null)return null;const a=$e(q,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},yw="linear",vw=e=>{const t=tc(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=rc(e.layers);if(r!==void 0)return{line:"average",layer:r}},bw=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??yw}),interactive:!1}),Sw=(e,{group:t,label:r})=>{const n=xw(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})},xw=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),Aw=(e,t)=>(0,rt.isEqual)({...e,id:""},{...t,id:""}),Iw=e=>e==="none"?"Hide stat line":`Show ${e} line`,gd=class yd{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?O(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:X(t,r.id,Lr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new yd({layerId:r.id,showCategoryLabels:n},this.metadata)}}},Tw={type:"toggle-category-labels",deserialize:(e,t)=>new gd(e,t)},vd=class bd{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?O(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:X(t,r.id,Lr(r,{showDataLabels:this.params.showDataLabels})),revert:new bd({layerId:r.id,showDataLabels:n},this.metadata)}}},Lw={type:"toggle-data-labels",deserialize:(e,t)=>new vd(e,t)},Ew={type:"toggle-goal-line",deserialize:(e,t)=>new Sd(e,t)},Sd=class ln{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=ec(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=Er(t,r.id);return a===t?null:{spec:a,revert:new ln({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:wa(t,n),revert:new ln({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return $e(q,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??ww}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},ww=0,Rw={type:"toggle-line-fill",deserialize:(e,t)=>new xd(e,t)},xd=class Ad{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(!te(O(t.layers,r),"line"))return null;const i=Ve("line",r),o=Rt(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new fe({list:"overrides",rule:{...i,declarations:Vw(o,n?a??Cw:null)}}).apply(t);if(!u)return null;const d=new Ad({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},Cw=.2,Vw=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},Dw={type:"toggle-line-points",deserialize:(e,t)=>new Id(e,t)},Id=class cn{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?O(t.layers,this.params.layerId):Ie(t.layers,"line","area");return te(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:wa(t,this.params.removedLayer??$e(q,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new cn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:Er(t,n.id),revert:new cn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:Tn(n,[r]))}},Td=class Ld{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?O(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:X(t,r.id,Lr(r,{showStackTotals:this.params.showStackTotals})),revert:new Ld({layerId:r.id,showStackTotals:n},this.metadata)}}},_w={type:"toggle-stack-totals",deserialize:(e,t)=>new Td(e,t)},Ed=class wd{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${Dt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Ct(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=Vt(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 wd(c,this.metadata)}}},Pw={type:"set-scale-domain",deserialize:(e,t)=>new Ed(e,t)},Rd=class Cd{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${Dt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Ct(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||tt(r.palette,this.params.palette)?null:{spec:Vt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Cd({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},Ow={type:"set-scale-palette",deserialize:(e,t)=>new Rd(e,t)},Vd=class Dd{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${Dt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Ct(t,this.params.scaledAesthetic);if(!r||!kw(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:Vt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Dd({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},Mw={type:"set-scale-reverse",deserialize:(e,t)=>new Vd(e,t)};function kw(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var _d=class Pd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${Dt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Ct(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:Vt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Pd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},Nw={type:"set-scale-transform",deserialize:(e,t)=>new _d(e,t)},Od=class Md{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${Dt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Ct(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:Vt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Md({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},Bw={type:"set-scale-zero",deserialize:(e,t)=>new Od(e,t)},kd=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 kd;S.register(rL);S.register(KL);S.register(JE);S.register(ZE);S.register(nw);S.register(aw);S.register(iw);S.register(sw);S.register(lw);S.register(uw);S.register(QE);S.register(tw);S.register(pw);S.register(cw);S.register(hw);S.register(fw);S.register(gw);S.register(Tw);S.register(Lw);S.register(Ew);S.register(Rw);S.register(Dw);S.register(_w);S.register(Pw);S.register(Ow);S.register(Mw);S.register(Nw);S.register(Bw);S.register(iE);S.register(lE);S.register(sE);S.register(cE);S.register(uE);S.register(dE);S.register(pE);S.register(mE);S.register(hE);S.register(LE);S.register(wE);S.register(VE);S.register(DE);S.register(_E);S.register(PE);S.register(OE);S.register(ME);S.register(BE);S.register(FE);S.register($E);S.register(GE);S.register(UE);S.register(HE);S.register(XE);S.register(jE);S.register(JT);S.register(FT);S.register(BT);S.register(jT);S.register(QT);S.register(XT);S.register(KE);S.register(YE);S.register(qE);var Nd=(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&&xr(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&&Et(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}`})}},Bd=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:oo(this.undoStack),redoStack:oo(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&&$w(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)}}},Fw=Object.freeze([]),$w=(e,t)=>e.type===t.type&&Nd(e.target,t.target),oo=e=>e.length===0?Fw:e.map(t=>t.command.metadata),Gw=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}},Uw=class{constructor(e){this.compiler=e,this.history=new Bd,this.current=null,this.last=null,this.hostInput=null,this.run=new Gw(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=nc(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}},Hw=new Set(["x","y"]),so=["numeric","categorical","temporal"],lo=["numeric"],Ww=(e,t)=>{const r=e.layers.map(a=>pc(a.geom)).filter(l.isDefined),n=Ar(e);return t.filter(a=>Kw(e,r,a)).map(a=>({aesthetic:a,variables:zw(n,r,a),isRequired:Hw.has(a)}))},Kw=(e,t,r)=>{switch(r){case"x":return!jw(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))}},zw=(e,t,r)=>{const n=Yw(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},Yw=(e,t)=>t==="size"?lo:t!=="x"&&t!=="y"?so:qw(e,t)?lo:so,qw=(e,t)=>e.some(r=>r.positionRoles.some(n=>Fo.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),jw=e=>e.coordType==="polar"&&e.params.theta==="y",Xw=500,Zw="normal",Va={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},Jw=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}`},Da=e=>typeof e!="string"?e??500:Va[e],Qw="\0",eR=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,Da(t.weight),t.style??"normal",e].join(Qw)}},tR={" ":.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 rR=1.05,nR=.84,aR=.21,iR=class{measureText(e,t){let r=0;for(const i of e)r+=(tR[i]??.55)*t.size;Da(t.weight)>=Va.semiBold&&(r*=rR);const n=nR*t.size,a=aR*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=ES;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=Sn;exports.AddAnnotationCommand=ya;exports.AddHighlightCommand=La;exports.AddLayerCommand=Ca;exports.BORDER_RADIUS_PX=aa;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Ff;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Iy;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=eR;exports.CommandRegistry=kd;exports.CommandStackManager=Bd;exports.Compiler=Ms;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=Zw;exports.DEFAULT_FONT_WEIGHT=Xw;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=hs;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=he;exports.GraphCompilationSession=Uw;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=Tx;exports.HEADLINE_TREND_GAP=wx;exports.HEADLINE_TREND_ICON_SIZE=Ex;exports.HEADLINE_VALUE_LABEL_GAP=Lx;exports.HeuristicTextMeasurer=iR;exports.HoverEngine=cI;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=pn;exports.LayoutCompiler=Jb;exports.MAX_BAR_WIDTH=rw;exports.MIN_BAR_WIDTH=Ku;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=cc;exports.NAMED_WEIGHTS=Va;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=da;exports.OUT_OF_VIEW_MARGIN_PX=wS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=Xd;exports.POSITION_TYPES=vo;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=ae;exports.RemoveAnnotationCommand=ga;exports.RemoveHighlightCommand=Ta;exports.RemoveLayerCommand=Ra;exports.SCALED_POSITION_AESTHETIC_KEYS=xn;exports.SCALED_VISUAL_AESTHETIC_KEYS=yt;exports.SCHEME_ALIASES=fs;exports.SEQUENTIAL_SCHEME_NAMES=$f;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=RS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=Hc;exports.SetAxisPositionCommand=Kc;exports.SetAxisTickModeCommand=Yc;exports.SetAxisTicksVisibilityCommand=jc;exports.SetAxisVisibilityCommand=Zc;exports.SetBarBorderRadiusCommand=Hu;exports.SetBarWidthCommand=zu;exports.SetChartTypeCommand=hc;exports.SetContentCaptionCommand=Qc;exports.SetContentSourceCommand=tu;exports.SetContentSubtitleCommand=nu;exports.SetContentTitleCommand=iu;exports.SetCoordLimitsCommand=Nu;exports.SetDataLabelsFormatCommand=qu;exports.SetDifferenceArrowStyleCommand=uc;exports.SetGridLineStyleCommand=cu;exports.SetGridLineWidthCommand=du;exports.SetGridVisibilityCommand=mu;exports.SetHeadlineCompareWithCommand=fu;exports.SetHeadlinePositionCommand=yu;exports.SetHeadlineShowCommand=bu;exports.SetHeadlineSizeCommand=xu;exports.SetHighlightDimStyleCommand=Iu;exports.SetLayerPositionCommand=Xu;exports.SetLayerStatCommand=Ju;exports.SetLayerYScaleTypeCommand=ed;exports.SetLegendAlignCommand=Lu;exports.SetLegendDisplayCommand=wu;exports.SetLegendPositionCommand=Cu;exports.SetLineInterpolationCommand=rd;exports.SetLineMissingValuesCommand=ad;exports.SetLineWidthCommand=od;exports.SetMappingCommand=Nc;exports.SetNumberFormatAbbreviationCommand=Du;exports.SetNumberFormatDecimalsCommand=Pu;exports.SetPointSizeCommand=ld;exports.SetPolarInnerRadiusCommand=Fu;exports.SetPolarStartAngleCommand=Gu;exports.SetRuleLabelCommand=ud;exports.SetRuleValueCommand=pd;exports.SetScaleDomainCommand=Ed;exports.SetScalePaletteCommand=Rd;exports.SetScaleReverseCommand=Vd;exports.SetScaleTransformCommand=_d;exports.SetScaleZeroCommand=Od;exports.SetStatLineCommand=hd;exports.SetStyleRuleCommand=fe;exports.SpecResolver=As;exports.Stat=Fe;exports.TAU=de;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=gd;exports.ToggleContentVisibilityCommand=Mu;exports.ToggleDataLabelsCommand=vd;exports.ToggleGoalLineCommand=Sd;exports.ToggleLineFillCommand=xd;exports.ToggleLinePointsVisibilityCommand=Id;exports.ToggleStackTotalsCommand=Td;exports.UpdateAnnotationCommand=ba;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=yo;exports.annotation=Ug;exports.areAnchorsEqual=qe;exports.areEditMenuTriggersEqual=tx;exports.areEditTargetsEqual=Nd;exports.areEndpointsComparable=xo;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=Jl;exports.arePointerRegionListsEqual=qS;exports.arePredicatesEqual=Et;exports.areStyleDeclarationsEqual=ac;exports.areStyleRuleAddressesEqual=xr;exports.buildAverageLineSymbols=AS;exports.buildCalloutHitRegions=LS;exports.buildColumnKey=Tl;exports.buildDataLabelsContent=Zv;exports.buildDiagnostic=Io;exports.buildEditMenuTriggerRegion=QS;exports.buildFontString=Jw;exports.buildLayerIntroPlan=SI;exports.buildLayerStyleAddress=Ve;exports.buildLayerYValueFormatter=Qn;exports.buildObservationPredicate=bl;exports.buildObservationsTarget=US;exports.buildPinnedNumberValueFormatter=px;exports.buildPolarBarArcPath=Hx;exports.buildSliceGroupKey=wl;exports.buildTooltipContent=KI;exports.canAnchorDirectLabels=Xo;exports.canBecomeCombo=cL;exports.canBecomeHeatmap=uL;exports.canPlaceDataLabels=Xv;exports.clampAnnotationTranslation=GT;exports.commandRegistry=S;exports.compileChromeStyles=ws;exports.compileStylesheetForLayer=Zg;exports.compositeColor=mo;exports.computeArrow=SS;exports.computeDifferenceArrow=ul;exports.computeDirectLabelsLayout=BS;exports.computeLineBoxHeight=dl;exports.computePanelBorderPaths=OI;exports.computePanelBorderSizes=MI;exports.config=l.config;exports.convertSpecToInput=nc;exports.coord=l.coord;exports.countLayerGeoms=xI;exports.createAlphaValueReader=ap;exports.createAnchorResolver=eS;exports.createAreaPathGenerators=Ox;exports.createColorValueReader=bo;exports.createCompiler=Ty;exports.createDatasetFromKindPartitions=Fp;exports.createEmptyHighlight=Zo;exports.createGraphyBuilder=wy;exports.createGroupValueReader=ip;exports.createHeadlineItemRows=Rx;exports.createLabelValueReader=rp;exports.createLineFillAreaGenerator=$x;exports.createLinePathGenerator=Fx;exports.createObservationAnchorBuilder=ft;exports.createObservationAnchorParser=Ao;exports.createRawValueReader=j;exports.createSegmentYReader=ht;exports.createSizeValueReader=np;exports.createSpec=Ns;exports.createStableBandKeyGenerator=Yx;exports.createStableCellKeyGenerator=qx;exports.createStableKeyGenerator=yr;exports.createStrokeWidthValueReader=op;exports.createStyleResolver=at;exports.createValueFormatter=_;exports.createXValueReader=nt;exports.createYValueReader=hn;exports.cursorToPiePlane=ar;exports.cursorToPolar=un;exports.describeMeasurementBasis=Ur;exports.ensureReadableTextColor=jd;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=yl;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=Jm;exports.findAnnotation=St;exports.findAverageLineLayer=rc;exports.findAxisGuide=na;exports.findDistinctLayers=Ln;exports.findEquivalentHighlight=IT;exports.findGoalLineLayer=ec;exports.findHighlightsAtObservation=nx;exports.findKindStyleDeclarations=Rt;exports.findLayerByGeom=Ie;exports.findLayerById=O;exports.findLegendForAesthetic=Ax;exports.findObservationAttachment=Ql;exports.findPointerRegion=zS;exports.findStyleRule=wt;exports.findStyleRuleIndex=ha;exports.findTrendLineLayer=tc;exports.formatDifferenceLabel=ll;exports.formatHeadline=mx;exports.formatLegends=Sx;exports.formatRuleValue=Ix;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=$;exports.getAlpha=Js;exports.getAngleExtent=Zn;exports.getBarRectBounds=Il;exports.getBoundingRect=Bx;exports.getChromeDashArray=vT;exports.getColor=Tt;exports.getCrossAxisCoordinate=me;exports.getCurve=gr;exports.getDashArray=Px;exports.getDifferenceArrowDimensions=cl;exports.getDifferenceArrowLabelBox=pl;exports.getGroup=Q;exports.getHoverGuideLineProps=mI;exports.getHoverGuideRectProps=hI;exports.getInsetTileRect=il;exports.getLineType=Qs;exports.getMainAxisCoordinate=Y;exports.getNumericWeight=Da;exports.getPolarHoverGuideArcProps=fI;exports.getRadiusExtent=Jn;exports.getRuleDashPattern=zx;exports.getScaledAesthetic=ep;exports.getShapeAnnotationStroke=lT;exports.getSize=qn;exports.getStablePolarBarKeyGenerator=jx;exports.getStackRole=rs;exports.getStrokeWidth=Zr;exports.getTileRectBounds=al;exports.getUnionExtent=Kx;exports.getX=D;exports.getXMax=z;exports.getXMin=K;exports.getY=R;exports.getYMax=M;exports.getYMin=B;exports.getYRaw=dn;exports.hasMultipleGroups=lr;exports.highlight=AT;exports.inferDefaultDifferenceArrowEndpoints=ox;exports.inferDifferenceArrowEndpoints=Al;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=UT;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=cp;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=_t;exports.isCompanionLayer=Tn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=ho;exports.isGeomStyleRule=fa;exports.isKeyedScope=ta;exports.isLayerOf=ks;exports.isLayerOfType=te;exports.isLineStyleType=mn;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=bT;exports.isPointWithinEditMenuTrigger=ex;exports.isPointWithinRegionShape=ra;exports.isSafeUrl=UI;exports.isStackedPosition=F;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=RT;exports.normalizeAngle=_e;exports.orderPointerRegions=YS;exports.paintsInDonutHole=fr;exports.pickReadableTextColor=po;exports.pipe=Bs;exports.placeCallouts=PS;exports.polarToUnit=pe;exports.positionToAngle=fo;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=Mx;exports.prepareLineObservations=Gx;exports.projectAnchorToPanel=Jt;exports.projectRegionToPanel=nS;exports.quantiseKey=J;exports.readAnchoredObservation=lx;exports.readAttachedObservation=pa;exports.readAuthoredNumber=eT;exports.readAuthoredString=tT;exports.readBroadestObservationsScope=HS;exports.readChartType=lL;exports.readComboLineLayerId=dL;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Tu;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=Ww;exports.readMappedVariable=Fc;exports.readObservationIndex=gI;exports.readXExtent=ql;exports.readYExtent=jl;exports.resolveAnchorVariable=Me;exports.resolveArrowAnnotationStyle=nT;exports.resolveArrowColor=kS;exports.resolveAxisLabelStyle=vb;exports.resolveBarBandFraction=zr;exports.resolveBarBorderRadiusPx=ia;exports.resolveBarBorderTreatment=Nx;exports.resolveBarCornerRadiiPx=kx;exports.resolveCalloutAnnotationStyle=sT;exports.resolveColorRamp=Vn;exports.resolveComparisonBasis=jo;exports.resolveDataLabelStyle=Sb;exports.resolveDeferredAnchors=sS;exports.resolveDefinition=Cn;exports.resolveDifferenceArrowAnnotationStyle=aT;exports.resolveDirectLabelStyle=Tb;exports.resolveGeomAnchorFrame=yn;exports.resolveGraphChromeStyle=mT;exports.resolveGraphPadding=hT;exports.resolveGridLineStyle=uT;exports.resolveHeadingFontFamily=pT;exports.resolveHeadlineFigure=Eb;exports.resolveHeadlineItemStyle=Lb;exports.resolveHeadlinePlacement=Yb;exports.resolveHeadlineStyle=gT;exports.resolveHoverGuideStyle=yT;exports.resolveImageAnnotationStyle=oT;exports.resolveLegendItemStyle=Ib;exports.resolveLegendStyle=fT;exports.resolveObservationPoint=cx;exports.resolveObservationsTarget=Sl;exports.resolvePanelBorderStyle=cT;exports.resolvePolarBarCornerRadiusUnit=Wx;exports.resolveRuleLabelStyle=xb;exports.resolveSegmentYSource=ir;exports.resolveShapeAnnotationStyle=rT;exports.resolveSwatchGeomPaint=oa;exports.resolveTextAnnotationStyle=iT;exports.resolveTextStyle=W;exports.resolveTickLabelStyle=bb;exports.resolveTickLineStyle=dT;exports.resolveTooltipStyle=Ab;exports.resolveYScaleAesthetic=xe;exports.sampleColorScheme=Kf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=ux;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=yb;exports.toPanelCursor=gl;exports.toPercent=Ce;exports.toViewBoxX=rS;exports.toViewBoxY=se;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=$s;exports.uniqueId=G;exports.unitToPolar=nr;exports.updateSpec=V;