@graphysdk/viz-engine 1.8.1-beta.1787584545684 → 1.8.1-beta.1787820383880

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +4 -4
  2. package/dist/index.mjs +2084 -2071
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Xu=Object.create,ki=Object.defineProperty,Zu=Object.getOwnPropertyDescriptor,Ju=Object.getOwnPropertyNames,Qu=Object.getPrototypeOf,ed=Object.prototype.hasOwnProperty,td=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Ju(t),i=0,s=a.length,o;i<s;i++)o=a[i],!ed.call(e,o)&&o!==r&&ki(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Zu(t,o))||n.enumerable});return e},Yt=(e,t,r)=>(r=e!=null?Xu(Qu(e)):{},td(t||!e||!e.__esModule?ki(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-C_KBOU1F.cjs");let ye=require("color2k"),Pi=require("date-fns"),je=require("lodash-es"),Qe=require("d3-time"),rd=require("date-fns/differenceInDays"),pe=require("d3-regression"),Q=require("d3-scale"),Ne=require("d3-interpolate"),O=require("d3-scale-chromatic"),Ge=require("lodash-es/clamp");Ge=Yt(Ge,1);let Nt=require("lodash-es/merge");Nt=Yt(Nt,1);let Nr=require("humanize-duration");Nr=Yt(Nr,1);let Ie=require("d3-shape"),nd=require("d3-delaunay"),Bt=require("lodash-es/isEqual");Bt=Yt(Bt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787584545684");var ad=1e6;function z(e){return String(Math.round(e*ad))}var Ta="#FFFFFF",yr="#1A1A1A",id=e=>{try{return(0,ye.getContrast)(e,Ta)>(0,ye.getContrast)(e,yr)?Ta:yr}catch{return yr}},sd=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ye.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ye.parseToRgba)(e);return r>=1?e:(0,ye.parseToRgba)(t)[3]<1?void 0:(0,ye.mix)(t,(0,ye.opacify)(e,1),r)}catch{return}},La=0;function M(){return La+=1,`${Math.random().toString(36).slice(2,6)}${La.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function w(e){return e[l.POSITION_VARIABLES.y]}function G(e){return e[l.POSITION_VARIABLES.xMin]}function U(e){return e[l.POSITION_VARIABLES.xMax]}function k(e){return e[l.POSITION_VARIABLES.yMin]}function _(e){return e[l.POSITION_VARIABLES.yMax]}function on(e){return e[l.POSITION_VARIABLES.yRaw]}function od(e,t){return e[l.resolveScaledAestheticVariable(t)]}var ld={xMin:0,xMax:1,yMin:0,yMax:1},Br=(e,t)=>{if(t.type==="polar")return null;const r=G(e)??R(e),n=U(e)??R(e),a=k(e)??w(e),i=_(e)??w(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},it=(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}}},Mi=e=>it(ld,e),Ni=["stack","dodge","identity","fill"],ln=["solid","dashed","dotted"],Bi=e=>ln.includes(e);function B(e){return e==="stack"||e==="fill"}var W=(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},Xe=(e,t)=>W(e,t.x),cn=(e,t)=>W(e,t.y),cd=(e,t)=>W(e,t.label),Fi=(e,t)=>W(e,t.color),ud=(e,t)=>W(e,t.size),dd=(e,t)=>W(e,t.alpha),md=(e,t)=>W(e,t.group),pd=(e,t)=>W(e,t.strokeWidth),wa={variable:l.POSITION_VARIABLES.yRaw};function qt(e,t){return B(e)?wa:t.y??wa}function st(e){return W(e.data,qt(e.position,e.mapping))}var we=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},un=e=>hd(e)?l.extractVariableName(e.mapping.y):null,$i=e=>un(e)===null?null:st(e),dn=e=>e.spatialKind!=="cells",hd=e=>e.spatialKind==="points"||e.spatialKind==="cells",Gi=(e,t)=>e.yScaleType===t.yScaleType&&$r(e.valueFormat)===$r(t.valueFormat),Fr=e=>`${e.yScaleType} y axis, ${$r(e.valueFormat)}`,$r=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Ct=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Ui=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(we(e))),n=un(e);return a=>({...a,anchorValue:Ct(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:Ct(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:Ct(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Wi(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 E(e,t){return Ki(e,t)}function L(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 Hi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Ze(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 Ki(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(l.isPlainObject(i)&&l.isPlainObject(s)){const o=Ki(s,i);o!==s&&(n[a]=o,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function jt(e){return{pipe:t=>{const r=t(e);return jt({...e,...r})},result:()=>e}}var fd=(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};function Ue(e,t){return e==="x"?t.x:t.y}function Xt(e,t){return e==="x"?t.y:t.x}function gd(e,t){return{main:Ue(e,t),cross:Xt(e,t)}}function Ea(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function yd(e){return e.type==="cartesian"}var Y=e=>e[l.GROUP_VARIABLES.group],ot=e=>{const t=we(e),r=$i(e),n=dn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const o=n?Y(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...o!==null&&{groupValue:o}}}},We=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,vd={type:"decimal"};function zi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function mn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):vd}function bd(e){return mn(e,l.extractVariableName(e.mapping.y))}function Yi({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??qt(t,r)}function qi(e,t){const r=Yi({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:W(e.data,r),valueFormat:mn(e,a)}}var ji=e=>{const t=we(e),r=$i(e),n=dn(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(Y(a),i.groupValue)},Xi=e=>{const t=l.extractVariableName(e.mapping.y),r=st(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},Sd=["lt","lte","gt","gte","range"],xd={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"}},re=()=>!1,De=()=>!0;function Zt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Xi(e),parsingLocale:t}}function be(e,t){if("and"in e){const r=e.and.map(n=>be(n,t)).filter(n=>n!==De);return r.includes(re)?re:r.length===0?De:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>be(n,t)).filter(n=>n!==re);return r.includes(De)?De:r.length===0?re:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=be(e.not,t);return r===re?De:r===De?re:n=>!r(n)}return Id(e,t)}function Se(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Se(n,t,r)):"or"in e?e.or.flatMap(n=>Se(n,t,r)):"not"in e?Se(e.not,t,r):Ad(e,t,r)}function Ad(e,t,r){const{subject:n,effect:a}=xd[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=Td(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 Id(e,t){if(!t.hasVariable(e.variable))return re;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Ct(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 s=t.readValue(i,e.variable);for(const o of a)if(l.areDataValuesEqual(s,o))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>_e(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>_e(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="greater"||s==="equal"}}if("range"in e){const[a,i]=e.range,s=n(a),o=n(i);return c=>{const u=t.readValue(c,e.variable),d=_e(u,s),m=_e(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return re}function Td(e){for(const t of Sd)if(t in e)return t;return null}function _e(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 Ld=(e,t,r,n,a,i)=>{const s=Ji(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Zi(r.padding),c=o===null?Vd(s,r.padding):s,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin)};return o===null?u:{...u,defer:o}},wd=(e,t,r,n,a,i)=>{const s=Ji(e,t,r.predicate,n,a,i);return s===null?null:it(s,r.align)},Zi=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Ji=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let s=null,o=!1;const c=new Map;for(const u of n){const d=Se(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=be(r,Zt(u,i));if(h!==re)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Ed(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Ed=(e,t)=>({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)}),Vd=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Ft=(e,t,r)=>{const n=Cd(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Dd(n,t.offset,e.coordSystem)},Qi=(e,t)=>t.anchorType==="selection"?Ld(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)=>Gr(e,t,r)?.point??null,Gr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const o=e.geomRegistry.get(s.geom),{resolveAnchorPosition:c}=o;if(c===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=qi(s,o),d=ji(s),m=ot(s),h=Ui(s,n)(a);let p=-1;for(const f of s.data){if(p+=1,!d(f,h))continue;const g=c(f,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(g===null)continue;const y=es(s,f,u);if(y===null)continue;const v=m(f);if(v!==null)return{point:{...g,...y,observationIndex:p,anchor:a.align===void 0?v:{...v,align:a.align}},layerId:s.id}}}return null},Rd=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,o=a.y;if(s===void 0||o===void 0||s.kind!=="position"||o.kind!=="position")return null;const c=Ra(t.x,"x",r,i),u=Ra(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!We(d,m))return null;const h=Va(d,s,_d(e)),p=Va(m,o),f=Ea(n.mainAxis,{main:h.min,cross:p.min}),g=Ea(n.mainAxis,{main:h.max,cross:p.max});return it({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},es=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:fd(r.valueFormat,t),yScaleType:e.yScaleType}:null},Cd=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Rd(e,t);case"selection":return wd(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,Od(t),r)}},Dd=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Zi(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Va=(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}},_d=({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},Od=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Ra=(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},kd=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,s={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:Kd(s,t.differenceArrows),shapes:Bd(s,t.shapes),arrows:$d(s,t.arrows),textAnnotations:Gd(s,t.textAnnotations),images:Fd(s,t.images),stickers:Ud(s,t.stickers),pinnedNumbers:Wd(s,t.pinnedNumbers),comments:Hd(s,t.comments)};return Pd(this.container,o),Md(this.container,o),o}},ee=(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."})},Pd=(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)}},Md=(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 Nd(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."})},Nd=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},Bd=(e,t)=>{const r=[];for(const n of t){const a=Qi(e,n.region);if(a===null){ee(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,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},Fd=(e,t)=>{const r=[];for(const n of t){const a=Qi(e,n.region);if(a===null){ee(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,opacity:n.opacity})}return r},$d=(e,t)=>{const r=[];for(const n of t){const a=Ft(e,n.start,"pin"),i=Ft(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${ts(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,color:n.color,thickness:n.thickness,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle,lineStyle:n.lineStyle,hasStickerStyle:n.hasStickerStyle})}return r},Gd=(e,t)=>{const r=[];for(const n of t){const a=Ft(e,n.at,"pin");if(a===null){ee(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,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},Ud=(e,t)=>{const r=[];for(const n of t){const a=Ft(e,n.at,"pin");if(a===null){ee(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},Wd=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Hd=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Kd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Gr(e,n.start,"value"),i=Gr(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${ts(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}zd(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},ts=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",zd=(e,t,r,n)=>{Gi(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:Fr(r),actual:Fr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Yd(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,o]of r)o.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:rs(i),values:i};return new l.Dataset(n)}function rs(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 qd=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,rs(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Ee=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)}},jd=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)}},Xd=class extends Ee{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}},Zd=class{constructor(e){this.setupStage=new jd(e),this.transformStage=new Xd(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)}},Jd=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}},Qd=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:tm(e.scales,e.layers)}}transform(e){return e.layers.map(t=>nm(t))}},em=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ca=l.prefixInternalVariable("flipSwap"),tm=(e,t)=>rm(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,rm=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},nm=e=>{let t=e.data;for(const[r,n]of em){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ca).renameVariable(n,r).renameVariable(Ca,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},xe=Math.PI*2,am=8,im=1e-9,ns=(e,t)=>Math.abs(t-e)>=xe-im,He=e=>(e%xe+xe)%xe,as=(e,t,r)=>{if(ns(t,r))return!0;const n=He(r-t);return He(e-t)<=n},$t=(e,t)=>{const r=Math.abs(He(e)-He(t));return Math.min(r,xe-r)},is=(e,t,r)=>e*xe+t+r,Gt=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),ss=(e,t)=>({angle:He(Math.atan2(e,t)),radius:Math.hypot(e,t)}),hn=(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}=hn(e,t);return ss(r,n)};function os(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 ls=(e,t)=>os(t.domain!==null&&t.domain.length>0?t.domain:e),sm=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=cm(t,e.scales,e.layers),a=dm(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=lm(r,n),i=mm(t);return e.layers.map(s=>pm(t.theta==="y"?hm(s):s,a,i))}},om=[[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 lm(e,t){return r=>is(r,e,t)}function cm(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=um(n,e,r);return a===0?0:-Math.PI/a}function um(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 s of a.data.getValues(i))n.push(s)}return ls(n,e).length}function dm(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 mm(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function pm(e,t,r){let n=e.data;return n=Oe(n,l.POSITION_VARIABLES.x,t),n=Oe(n,l.POSITION_VARIABLES.xMin,t),n=Oe(n,l.POSITION_VARIABLES.xMax,t),n=Oe(n,l.POSITION_VARIABLES.y,r),n=Oe(n,l.POSITION_VARIABLES.yMin,r),n=Oe(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Oe(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 hm(e){let t=e.data;for(const[r,n]of om){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,o=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),o&&(t=t.addVariable(r,"numeric",o))}return{...e,data:t}}var fm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Jd),this.register("flip",new Qd),this.register("polar",new sm)}},cs=new Set(["min","max","scalar"]),gm={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function ym(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 vm(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 bm(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=gm[a.axis][a.role];if(n.hasVariable(i))continue;const s=l.extractVariableName(r[a.aes]);!l.isDefined(s)||!n.hasVariable(s)||(n=n.addVariable(i,"numeric",n.getValues(s,{type:"numeric"})))}return n}var Sm=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:bm(n.data,r.positionRoles,a)}}},fn=["x","y"],gn=new Set(["x","y","ySecondary"]),lt=new Set(["color","size","alpha","strokeWidth","lineType"]),Ve=e=>gn.has(e),yn=e=>lt.has(e),us=e=>Ve(e)||yn(e);function oe(e){return e==="secondary"?"ySecondary":"y"}function ds(e,t){return e==="y"?oe(t):"x"}function P(e){return e==="ySecondary"?"y":e}var Je=(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 lt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},Qt=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Je(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),xm=class{compute({data:e,mapping:t}){const r=Je(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=l.getStableKey(a.map(o=>o[s]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},Am=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},Im=(e,t,r)=>{const n=Te(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Te(e,t){const r=P(t);for(const n of ms(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var er=(e,t)=>e===null?null:t[e]??e,Tm=(e,t)=>e===null?null:t[String(e)]??null,Le=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return vr(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 wm(i,t)?i:vr(t)}return vr(t)},Lm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:ms(t,e).some(r=>r.position==="fill");function ms(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var vr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},wm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Em=[{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}],Da={year:0,quarter:1,month:2,week:3,day:4,hour:5},ke=40,Vm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return _m(r.unit).range(e,new Date(t.valueOf()+1),n)},Rm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,rd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>ke;case"day":return a/t>ke;case"week":return a/(7*t)>ke;case"month":return a/(30*t)>ke;case"quarter":return a/(90*t)>ke;case"year":return a/(365*t)>ke}},Cm=(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"}}},Dm=(e,t)=>{const r=Om(t);return r===null?!1:Da[e]>Da[r]},_m=e=>{switch(e){case"hour":return Qe.utcHour;case"day":return Qe.utcDay;case"week":return Qe.utcMonday;case"month":case"quarter":return Qe.utcMonth;case"year":return Qe.utcYear}},Om=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}},ps={left:"right",right:"left",top:"bottom",bottom:"top"},km={x:!0,y:!0,ySecondary:!1},Pm=20,_a=new Set(["top","bottom"]),Mm={type:"percentage"};function Nm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(zi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=$m(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=Um(hs(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of gn){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=Bm({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function Bm(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:o,variableLabels:c}=e,{axisConfig:u,position:d,geometry:m}=Gm(t,n,i,s),h=Te(a,t),p=Lm(a,t)?Mm:Le({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:Fm(u,h,c),isVisible:u.isVisible,tickCandidates:Hm(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Wm(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Fm(e,t,r){return e.label?e.label:t?r[t]??null:null}function $m(e,t,r,n){const a=t.flatMap(o=>{const c=e.get(o.geom).grid[r];return c?[c]:[]}),i=a.some(o=>o.hideGridX),s=a.some(o=>o.hideGridY);return{x:{gridVisible:Oa(i,n.axes.x.grid.isVisible)},y:{gridVisible:Oa(s,n.axes.y.grid.isVisible)}}}function Oa(e,t){if(e&&t===null)return!1}function Gm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:hs(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=ps[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 hs(e,t){return _a.has(e)===_a.has(t)?e:t}function Um(e,t){return t.has(e)?ps[e]:e}function Wm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??km[r]}var Hm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=zm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Pm;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Ke(e,u))}))}return i}return e.spec.scaleType==="datetime"?Km(e,t):[{ticks:e.generateTicks().map(a=>Ke(e,a))}]},Km=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Ke(e,o))}];const a=new Set,i=[],s=(o,c)=>{if(o.length===0)return;const u=l.getStableKey(o);a.has(u)||(a.add(u),i.push({ticks:o.map(d=>Ke(e,d)),valueFormat:c}))};for(const o of Em)Rm({...o,start:r,stop:n})||Dm(o.unit,t)||s(e.generateTicks({interval:o}),Cm(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},zm=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:[Ke(e,r),Ke(e,n)]}},Ke=(e,t)=>({value:t,position:e.map(t)});function fs({scale:e,aesthetics:t,layers:r}){const n=Ym({layers:r,aesthetics:t}),a=gs({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Ym({layers:e,aesthetics:t}){const r=gs({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>l.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function gs({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(c=>l.isDefined(i.mapping[c]));if(s===void 0)continue;const o=l.extractVariableName(i.mapping[s]);if(!(o===null||!i.data.hasVariable(o)))for(const c of i.data.getValues(o,{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 vn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function qm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!vn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=Te(t,"color");if(ys({colorVariableName:a,xVariableName:Te(t,"x"),mapsColorAcrossMultipleLayers:Xm(t)>1,isMergedWithAnotherAesthetic:jm(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return fs({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Le({layers:m?[m]:t,scaleType:i,variableName:h}),label:Tm(o,r)}})}var ys=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function jm(e,t,r){if(r===null)return!1;for(const n of lt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!vn(a))&&Te(t,n)===r)return!0}return!1}var Xm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function vs(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Zm(e,t,r,n){const a=r.findIndex(i=>vs(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:er(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function ka(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 bs=e=>e==="none"?"first":e,Jm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Pa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Pa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Qm=(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}},Pa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function ep(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?tp(e,n):rp(e,n)}function tp(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(o=>o.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=l.extractVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:Le({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function rp(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>vs(o,d)))return null;const c=Zm(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>np({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 np({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=l.extractVariableName(i.mapping.y);if(s===null||t==="total"&&i.position==="fill")return null;const o=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Le({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=sp(i.data,o),h=Le({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=op(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=ka(f,y,e.value),x=ka(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Jm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:ap(t,m,x),comparison:ip(t,r,m,x,v)}}function ap(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 ip(e,t,r,n,a){return e!=="current"||!r?null:Qm(n.map((i,s)=>({main:i,cross:a[s]??null})),bs(t))}function sp(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function op(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 D(e,t){return e.find(r=>r.id===t)}function le(e,...t){return e.find(r=>t.includes(r.geom))}function lp(e,...t){return e.filter(r=>t.includes(r.geom))}function bn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Sn(e){const t=e.filter(r=>!bn(r,e));return t.length>0?t:e}function Ss({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Sn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var cp=3;function up({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const o=new Map(i.map(y=>[l.getStableKey(y.value),y])),c=vp(hp({scales:e,layers:r})),u=Te(r,"x"),d=c.map(y=>{if(gp(y,u,r))return null;const v=Sp({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=dp(d),h=Sn(r),p=wp(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&Lp(s,m,h,n))return{drawn:[],position:p};const f=Ep(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?Dp(h[0]):null;return{drawn:d.map(({built:y})=>mp(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function dp(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function mp(e,t,r){const{position:n,display:a}=t,i=pp(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function pp(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function hp(e){const{scales:t,layers:r}=e,n=[];for(const a of lt){const i=t[a];if(i===void 0||i.kind==="identity"||!fp(a,r))continue;const s=Te(r,a),o=Cp(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function fp(e,t){const r=P(e);return t.some(n=>l.isDefined(n.mapping[r]))}function gp(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:ys({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:yp(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function yp(e,t){const r=P(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function vp(e){const t=new Map;for(const r of e){const n=Rp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function bp(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Sp({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>P(c.scaleAestheticKey)),s=fs({scale:a.scale,aesthetics:i,layers:r}),o=Le({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:er(a.variableName,t),items:s.map(c=>xp(c,e,i,o,n))}}function xp(e,t,r,n,a){const i={};for(const o of t)bp(i,o.scaleAestheticKey,o.scale.map(e.value));const s=Ip(e,t,r,n,a);return{value:e.value,label:Ap(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function Ap(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function Ip(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=Tp(i,r);return i===void 0||s===null?n:Le({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function Tp(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 Lp(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 wp(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,o=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,B(u.position)&&(o=!0))}const c=r>=cp;return i&&s?"top":i?c?"right":"top":o?Vp(a)?"top":c?"right":"top":"top"}function Ep(e,t){return e==="pill"?"pill":Ss(t)?"direct":"pill"}function Vp(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Rp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Cp(e,t){return vn(t)?"discrete":`continuous:${e}`}function Dp(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(_(c))||l.isDefined(w(c)));if(!n)return;const a=Y(n);if(!l.isDefined(a))return;const i=k(n),s=_(n)??w(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var _p=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=Am(e.originalData),r=qm({scales:e.scales,layers:e.layers,valueLabels:Im(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=ep(n),i=up(n),s={...i,drawn:Op(a,i.drawn)};return{axes:Nm(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},Op=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],kp=e=>l.getStableKey([Y(e)]),xn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Pp=e=>e!=="data-point",Ut=(e,t,r)=>{switch(e){case"series":return kp(t);case"x-value":return xn(t,r)}},Mp={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function xs(e){const t=Mp[e]??null;return t===null?null:{strategy:t,composition:As()}}function As(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Np=class extends Ee{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=Bp({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Bp({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const X=Se(T.predicate,e.data);for(const Z of X)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return X.length===0}),s=l.extractVariableName(e.mapping.x),o=Zt(e,r),c=i.map(T=>({predicate:be(T.predicate,o),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let I=!1,A=0;for(const T of e.data){let X,Z;p!==null&&(X=Ut("series",T,s),p[A]=X),f!==null&&(Z=Ut("x-value",T,s),f[A]=Z),g!==null&&(g[A]=T);for(const{predicate:xt,scope:At}of c)if(xt(T))switch(At){case"series":X!==void 0&&v.add(X);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return As();const V=new Uint8Array(h),j=[];let ie=0;for(let T=0;T<h;T++){const X=p?.[T],Z=f?.[T],xt=X!==void 0&&v.has(X),At=Z!==void 0&&x.has(Z),Aa=y[T]===1;if(n==="observation-rerender")(xt||Aa||At)&&(V[T]=1,ie++);else if(xt)V[T]=1,ie++;else if(Aa||At){const Ia=g?.[T];Ia!==void 0&&j.push({observation:Ia,observationIndex:T})}}const K=ie>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&K!==null,matchedLayer:K,overlayCandidates:j}}var Fp=l.prefixInternalVariable("__ungrouped__");function $p(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"}),s=new Map,o=i.map((c,u)=>{if(c===null)return null;const d=r[u]??Fp;let m=s.get(d);return m||(m=new l.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",o)}return n}var Gp=()=>({defaults:[],overrides:[],warnings:[]}),Up=class extends Ee{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,Ma(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:Ma(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=jt({data:t,mapping:r}).pipe(({data:o,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:o,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>({data:this.groupCompiler.compute({data:o,mapping:c}).data,mapping:c})).pipe(({data:o,mapping:c})=>({data:$p(o),mapping:c})).pipe(({data:o,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:o,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:o,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:xs(e.geom),styles:Gp()}}};function Ma(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Is(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Ur(e,t){const r=Ts(e,t),n={};for(const{layer:i,scaleConstraints:s,crossAxis:o}of r)s.zeroBaseline===!0&&(n[o]={nice:(n[o]?.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:Hp(r),zeroAxes:n,bandPadding:Kp(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Wp(e,t){const r=Ts(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:Na(n),zeroAnchored:Na(a)}}return null}var Na=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function Ts(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:oe(n.yScaleType)})}),r}function Hp(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of Ls(r))t.add(n);return[...t]}function Kp(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Ls(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Ls({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var zp=new Set(["label","group"]),Yp=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},s={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(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),Is(this.container.diagnostics,t)}checkPostCompile(e){zi(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:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!Qt(r,t))return[];const c=s==="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 '${s}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:s},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:s,aesthetics:o}=this.container.geomRegistry.get(r),c=[...ym(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!cs.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,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:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Wp(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:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...vm(i),...s.map(h=>h.name)]),u=zp,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},ae=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=Ni,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)}},An=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},In=(e,{coordSystem:t})=>{if(t.type==="polar")return null;const r=R(e),n=w(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},qp=class extends ae{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=In}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=An(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},jp=.7,Xp=.1,Zp=.03,Jp=.05,ws=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Qp=class extends ae{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.resolveAnchorBox=Br,this.resolveDataLabelDefaults=t=>B(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>Wr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return eh(t);if(i!==void 0){const m=Br(t,r);return m===null?null:it(m,i)}const s=B(n),o={isSolo:!s||ws(t)==="solo",isNegative:s&&th(t),purpose:a};if(r.mainAxis==="x"){const m=G(t),h=U(t),p=Ba({lowerBound:k(t),upperBound:_(t)??w(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=k(t),u=_(t),d=Ba({lowerBound:G(t),upperBound:U(t)??R(t),options:o});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=Wr(r,n);e=An(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}},Wr=({width:e},t)=>e!==void 0?e:t==="polar"?1:jp,eh=e=>{const t=G(e),r=U(e),n=k(e),a=_(e);if(t===null||r===null||n===null||a===null)return null;const i=(t+r)/2,s=(n+a)/2;return{x:.5+.5*s*Math.sin(i),y:.5-.5*s*Math.cos(i)}},th=e=>{const t=on(e);return l.isStrictNumericDataValue(t)&&t<0},Ba=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},rh=class extends ae{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.resolveAnchorBox=Br,this.resolveAnchorPosition=In}compile(e){return{data:An(e.data,e.mapping),mapping:{}}}},nh=class extends ae{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=In,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:{}}}},ah=class extends ae{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=Fa(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=Fa(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}}}},Fa=(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},ih=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},sh=class extends ae{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=ih,this.resolveAnchorPosition=t=>{const r=G(t),n=U(t),a=k(t),i=_(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:{}}}},oh=[new Qp,new nh,new rh,new qp,new ah,new sh],tr=class extends l.Registry{constructor(){super("geom");for(const e of oh)this.register(e.type,e)}},Re=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},lh=class extends Re{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,...Je(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},ch=class extends Re{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},uh=class extends Re{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}}}},dh=2,Es=1440*60*1e3,mh=class extends Re{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 s=e.getType(a),o=e.getType(i);if(o!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${o}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:o}});const c=Je(e,t),u=bh(a,s,i,c,e);return c.length===0?$a({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=Sh(d,c);$a({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},$a=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=ph({data:e,xVariable:t,yVariable:n,xType:r});c.length<dh||(o?vh({observations:c,spec:a,output:i,groupObservation:s}):gh({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},ph=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?hh(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=fh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},hh=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},fh=({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)/Es+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}`})}},gh=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Vs(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?yh(o,r):o;a.push({x:u,y:c,groupObservation:i})}},yh=(e,t)=>t===null?new Date(e):new Date((e-1)*Es+t),vh=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const o of e)a.has(o.x)||a.set(o.x,o.originalX);const i=[...a.keys()].sort((o,c)=>o-c);if(t.method==="loess"){const o=Vs(t,e),c=new Map;for(const[u,d]of o)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=Rs(t,e);for(const o of i){const c=a.get(o),u=s.predict(o);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},Vs=(e,t)=>e.method==="loess"?(0,pe.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):Rs(e,t),Rs=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,pe.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,pe.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,pe.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,pe.regressionQuad)().x(r).y(n)(t);case"power":return(0,pe.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,pe.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=[],s=[],o=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),s.push(u);for(const m of n)o[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:o[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},Sh=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},xh=class extends Re{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],...Je(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},Ah=[new ch,new lh,new mh,new uh,new xh],Ih=class extends l.Registry{constructor(){super("stat");for(const e of Ah)this.register(e.type,e)}};function Th({geoms:e,stats:t,transforms:r}){const n=new tr,a=new Ih,i=new l.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function Tn(e){if("definition"in e)return e.definition;if(Ds(e)||_s(e)||Os(e))return e}function Cs(e){const t=[],r=[],n=[];for(const a of e){const i=Tn(a);i&&(Ds(i)?t.push(i):_s(i)?r.push(i):Os(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...br("geom",t,a=>a.type),...br("stat",r,a=>a.type),...br("transform",n,a=>a.transformType),...Lh(t),...wh(t)]}}function Lh(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 wh(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 br(e,t,r){const n=new Map;for(const i of t){const s=r(i),o=n.get(s);o?o.add(i):n.set(s,new Set([i]))}const a=[];for(const[i,s]of n)s.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${s.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var Ds=e=>e instanceof ae,_s=e=>e instanceof Re,Os=e=>"transformType"in e&&typeof e.apply=="function",Eh=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},rr=class{},Vh=class extends rr{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=Rh(e)??[-.7/2,.7/2],s=r.length>1?Xp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Rh=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]},Ga=l.prefixInternalVariable("__ungrouped__"),ks=(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,s=i?[Ga]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?Ga:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},Ps=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=Ch(p===o,p===d)}return a},Ch=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Dh=class extends rr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=ks(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const I=x>=0?m:h;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=Ps(c,o,a,s);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},_h=class extends rr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Oh=class extends rr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=ks(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=Ps(c,o,a,s);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const m=l.extractVariableName(t.y);return m!==null&&(d=d.addVariable(m,"numeric",o)),{data:d,mapping:{}}}},kh=class extends l.Registry{constructor(){super("position"),this.register("identity",new _h),this.register("stack",new Oh),this.register("fill",new Dh),this.register("dodge",new Vh)}},Ph=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!l.isDefined(s.aes)||yn(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ds(s.axis,t.yScaleType));if(!c)continue;const u=a.getValues(o,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},Mh=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(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},Nh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},Bh=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(oe(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},Fh=class{map({data:e,layer:t,getPositionScale:r}){const n=r(oe(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)?$h(e,n,a):Gh(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function $h(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"}),s="reverse"in t.spec&&t.spec.reverse===!0,o=e.size(),c=Ms(o);for(let u=0;u<o;u++){const d=n[u],m=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(h)||(c.min[u]=d+(s?-h:m)*r,c.max[u]=d+(s?-m:h)*r)}return c}function Gh(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 s=0;s<a;s++){const o=r[s],c=n[s];!l.isDefined(o)||!l.isDefined(c)||(i.min[s]=t.map(o),i.max[s]=t.map(c))}return i}function Ms(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Uh=[new Mh,new Bh,new Nh,new Fh,new Ph];function Wh(e,t){const r=e[t];return r?.kind==="position"?r:null}var Hh=class extends Ee{constructor(e,t=Uh){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=>Wh(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}}},Kh=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const a of e.scales)t.set(a.scaledAesthetic,a);const r=this.collectValues(e.layers,t),n={};for(const[a,i]of t){const s=r.get(a)??[];n[a]=this.registry.get(i.scaleType).compile(i,s)}return n}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=P(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const s=l.extractVariableName(i.mapping[a]);if(!l.isDefined(s)||!i.data.hasVariable(s))continue;const o=i.data.getType(s);if(n.includes(o)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${o})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o}}),r.scaledAesthetic==="lineType"&&o!=="categorical"){const c=o==="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 ${o} variable '${s}'. ${c}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o},suggestion:c})}}Is(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!l.isDefined(s))continue;const o=i==="y"?oe(n.yScaleType):i,c=a.get(i)??(us(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,s,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)||yn(n.aes)||t.set(n.aes,ds(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 s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},zh=["rgb","lab","hcl","hsl"],Yh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],Ns=["RdBu","BrBG","PuOr","Spectral"],Bs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},qh=new Set(Ns.map(e=>e.toLowerCase()));function Fs(e){const t=e.toLowerCase(),r=Bs[t];return r?r.toLowerCase():t}function jh(e){return qh.has(Fs(e))}var Xh={rgb:Ne.interpolateRgb,lab:Ne.interpolateLab,hcl:Ne.interpolateHcl,hsl:Ne.interpolateHsl},Zh={viridis:O.interpolateViridis,magma:O.interpolateMagma,inferno:O.interpolateInferno,plasma:O.interpolatePlasma,cividis:O.interpolateCividis,turbo:O.interpolateTurbo,blues:O.interpolateBlues,greens:O.interpolateGreens,greys:O.interpolateGreys,oranges:O.interpolateOranges,purples:O.interpolatePurples,reds:O.interpolateReds,rdbu:O.interpolateRdBu,brbg:O.interpolateBrBG,puor:O.interpolatePuOr,spectral:O.interpolateSpectral};function Ln(e){const t=Qh(e);return e.reverse?r=>t(1-r):t}function Jh(e={},t=2){const r=Ln({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 Qh(e){const t=Xh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ne.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Zh[Fs(e.scheme)];if(r)return r}return(0,Ne.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var ct=class{createPositionScale(e,t){return{kind:"position",aesthetic:P(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:P(e.scaledAesthetic),spec:e,...t}}},ef=class extends ct{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=Ve(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"&&tf(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:P(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,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).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=rf(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=Ln(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],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,Q.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,Q.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]}},tf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function rf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var nf=class extends ct{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=Ve(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=af(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?Vm(i,s,c.interval):[]:a.ticks(c?.count)})}},af=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),sf=class extends ct{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=Ve(e.scaledAesthetic),n=ls(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,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,Q.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})}},of=class extends ct{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:P(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},lf=class extends ct{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const r=os(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},cf=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new ef(e)),this.register("discrete",new sf),this.register("datetime",new nf),this.register("identity",new of),this.register("palette",new lf)}},Dt={color:null,size:"small",labelCrossPosition:.5},he={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},Sr={zOrder:"foreground",fit:"contain",opacity:1},uf={x:8,y:8,unit:"px"},_t={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},fe={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},df={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}},mf=(e,t,r)=>{const n=pf(e,t),a=gf(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>vf(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Af(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Lf(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>yf(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>bf(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>If(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>Sf(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>xf(e,i,r)).filter(l.isDefined)}},pf=(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:M()}):(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 ff(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},ff=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],gf=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},wn=(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},yf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),content:t.content,at:a,width:t.width,align:t.align??_t.align,backgroundColor:t.backgroundColor??_t.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??_t.backgroundColorStyle}},vf=(e,t,r)=>{const n=nt(e,t.start,r),a=nt(e,t.end,r);return n===null||a===null?null:{id:t.id??M(),start:n,end:a,label:t.label,color:t.color??Dt.color,size:t.size??Dt.size,labelCrossPosition:t.labelCrossPosition??Dt.labelCrossPosition}},nt=(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 wn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=nt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},bf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),at:a,sticker:t.sticker}},Sf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n}},xf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n,content:t.content}},Af=(e,t,r)=>t.region.anchorType==="annotation"&&!wn(e,t.region.ref,r,t.id)?null:{id:t.id??M(),kind:t.kind??he.kind,zOrder:t.zOrder??he.zOrder,region:Tf(t.region),fillColor:t.fillColor===void 0?he.fillColor:t.fillColor,fillOpacity:t.fillOpacity??he.fillOpacity,strokeWidth:t.strokeWidth??he.strokeWidth,strokeColor:t.strokeColor??he.strokeColor},If=(e,t,r)=>t.region.anchorType==="annotation"&&!wn(e,t.region.ref,r,t.id)?null:{id:t.id??M(),src:t.src,zOrder:t.zOrder??Sr.zOrder,region:t.region,fit:t.fit??Sr.fit,opacity:t.opacity??Sr.opacity},Tf=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:uf},Ua=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=df[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Lf=(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??M(),start:Ua(a),end:Ua(i),color:t.color??fe.color,thickness:t.thickness??fe.thickness,startArrowheadStyle:t.startArrowheadStyle??fe.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??fe.endArrowheadStyle,lineStyle:t.lineStyle??fe.lineStyle,hasStickerStyle:t.hasStickerStyle??fe.hasStickerStyle}},wf={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},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function Ef(e){const t=(0,je.merge)({},wf,e);return t.content=Vf(t.content,e?.content),t}var Vf=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Rf={xLimits:null,yLimits:null},Ot={theta:"x",startAngle:0,innerRadius:0};function Hr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Nt.default)({},Rf,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Ot.theta,startAngle:t.params?.startAngle??Ot.startAngle,innerRadius:(0,Ge.default)(t.params?.innerRadius??Ot.innerRadius,0,1)}}}}function Cf(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??M(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Df=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=Wa(e.filter(n=>n.severity==="error")),r=Wa(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},_f=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 Wa(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Of={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 $s(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 Ce(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new _f(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=Mf({dataLabels:Bf(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return Pf({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??M(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:$s(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:o.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??o.defaultInteractive,dataLabels:u}}function kf(e,t,r,n,a){const i=n.map((s,o)=>Ce(e,t,r,s,a,o));return Us(e,i)}var Gs=(e,t,r,n)=>n.label!==void 0?n.label:Yi({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Us=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Ze(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=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}}}})},Pf=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t==="polar",s=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"&&s&&B(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&&!(s&&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'."}),a.showCategoryLabels&&a.showDataLabels&&!i&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showCategoryLabels only applies to polar bars (pie / donut); it will be ignored.",suggestion:"Turn off showCategoryLabels for this layer."})},Mf=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const o=Nf(t,r,n);if(o===null)return e;const c=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${o}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Nf=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&B(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Bf=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Gs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,je.merge)({},Of,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Ws={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ff={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 Hs(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Ur(e.geomRegistry,n)}}function En(e,t){switch(t.scaleType){case"inferred":return En(e,Wf(e,t));case"continuous":{const r=Ws[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:Hf(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 Kr(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 $f(e,t){const{scales:r,layers:n,coords:a}=t,i=Hs(e,t),s=Yf(zf(r,n),i.demands),o=new Map;for(const u of s)o.set(u.scaledAesthetic,u);const c=[...o.values()].map(u=>{const d=Gf(i,u);return En(i,d)});return a.coordType==="polar"?c.map(Ks):c}function Kr(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??Uf(e.scaledAesthetic,t)}}var Ks=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Gf(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:P(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 Uf(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function Wf({data:e,layers:t,mapping:r,demands:n},a){const i=P(a.scaledAesthetic),s=a.scaledAesthetic==="ySecondary"?Kf(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const o=n.zeroAxes[a.scaledAesthetic];if(o!==void 0){const m=a.options;return l.continuous(a.scaledAesthetic,{...m,zero:!0,...!o.nice&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!e.hasVariable(c))return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=Ws[a.scaledAesthetic];switch(Ff[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 Hf(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:P(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&jh(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:P(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Kf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function zf(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Yf(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var qf=e=>{const t=new Set;e!==void 0&&zs(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},zs=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])zs(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function jf(e,t,r){const n=Hr(t.coords),a=kf(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=$f(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=Ef(t.config),o=Cf(e,t.highlights,a),c=mf(e,t.annotations,a),u=qf(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:o,styles:u,annotations:c,coords:n,config:s}}var Ys=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return jf(this.container,{...e,data:t},r)}},Xf=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})}},Zf=class extends Ee{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of dg(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of mg(e.styles))this.container.diagnostics.addWarning(r);for(const r of pg(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=to({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Be={color:"color",alpha:"unitInterval",saturation:"unitInterval"},qs={bar:{...Be,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Be,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Be,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Be,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Ha=1,Ka=1e3,Jf="'none' or a shadow object { offsetX, offsetY, blur, color }",It={color:"color",strokeWidth:"pixels",lineType:"lineType"},Tt={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},ge={panelBorder:{...It,borderRadius:"pixels"},panelBorderEdge:It,gridLine:It,tickLine:{...It,length:"pixels"},axisLabel:Tt,tickLabel:{...Tt,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...Tt,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily"},tooltip:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},tooltipText:Tt,tooltipPrimaryRow:{background:"color"}},Qf=new Set([...Object.keys(Be),...Object.values(qs).flatMap(e=>Object.keys(e??{})),...Object.values(ge).flatMap(e=>Object.keys(e))]),js=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","tooltip"],eg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),tg=(e,t,r="en-US")=>to({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),rg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Xs(e.styles)}},Xs=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:[]},tooltip:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(nr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ng(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${js.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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 m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!ig(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(eg.has(m.target)){const p=m.axis;if(p!==void 0&&!cg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${fn.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${ze(p)}.`,context:{param:"layer",actual:ze(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="tooltip"){const p=m.part;if(p!==void 0&&!lg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown part '${String(p)}'.`,context:{param:"part",actual:String(p),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!sg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!og(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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:ag(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},nr=e=>e.select.target==="geom",ng=e=>{const t=e.select.target;return t!=="geom"&&js.includes(t)},Zs=e=>(e!==void 0?qs[e]:void 0)??Be,ag=e=>e.target==="panelBorder"?e.edge===void 0?ge.panelBorder:ge.panelBorderEdge:e.target==="tooltip"?e.part===void 0?ge.tooltip:e.part==="primaryRow"?ge.tooltipPrimaryRow:ge.tooltipText:ge[e.target],ig=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),sg=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),og=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),lg=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),cg=e=>typeof e=="string"&&fn.includes(e),ug=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!nr(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=Vn({declarations:a.declarations,vocabulary:Zs(s),tokens:t,location:`builtin[${i}]`,origin:o,warnings:r});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:o})}),n},Js=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},dg=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Js(e,(a,i,s)=>{const o=a.select;if(o.target!=="geom"&&o.target!=="ruleLabel")return;const c=o.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] 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},mg=e=>{const t=[];return Js(e,(r,n,a)=>{if(!nr(r))return;const i=r.when?.state;i===void 0||Qs(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(s=>`'${s}'`).join(", ")}.`})}),t},Qs=e=>l.STYLE_STATES.includes(e),pg=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))eo(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${ze(n)}.`,context:{param:"tokens",actual:ze(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},eo=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,me=e=>typeof e=="number"&&Number.isFinite(e),ze=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),to=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Zt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!nr(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&&!Qs(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const I=Se(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=Vn({declarations:h.declarations,vocabulary:Zs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:be(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...ug(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},Vn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${ze(g)}.`,context:{param:p,expected:f,actual:ze(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return eo(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=Qf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":me(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":me(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Bi(f)?u(p,f):d(p,`one of ${ln.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":me(f)&&f>=Ha&&f<=Ka?u(p,f):d(p,`a number in [${Ha}, ${Ka}]`,f);break;case"multiplier":me(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;case"shadow":{if(f==="none"){u(p,f);break}const y=f;if(!me(y.offsetX)||!me(y.offsetY)||!me(y.blur)||y.blur<0){d(p,Jf,f);break}const v=m(p,y.color);v!==void 0&&u(p,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:v});break}default:break}}return o},hg=({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}},fg=({layer:e})=>{if(e.position!=="stack")return;const t=l.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const r=new Map;for(const a of e.data){const i=a[t],s=k(a),o=_(a),c=G(a),u=U(a),d=on(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=xn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},gg=class extends Ee{constructor(e){super(),this.container=e}dependencies(){return[]}compileLayer(e){const t=this.container.geomRegistry.get(e.geom),r={};if(t.summaries.stackTotals){const n=fg({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=hg({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},ro=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"},yg=["color","size","alpha","strokeWidth","lineType"],vg=class extends Ee{dependencies(e){return yg.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 s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,za[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,za[a],bg(c)))}return{...e,data:r}}},bg=e=>t=>l.isDefined(t)?e.map(t):null;function no(e=new tr){return{diagnostics:new Df,geomRegistry:e}}var ao=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"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.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>e.data===void 0?this.runPipeline({spec:e.spec}):(this.lastData=e.data,this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data)})})));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}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:[Wi(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:s,getStats:o}of this.stages){const c=o();i[s]={hits:c.hits-t[s].hits,misses:c.misses-t[s].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e}){return{...jt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result(),spec:e}}},Sg=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],xg=({plugins:e=[]}={})=>{const t=Cs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Th(t),i=no(r),s=new cf(i),o=new ro(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new ao(i,new l.DataCompiler,new Ys(i),o,new qd,new Yp(i,o,n,new Up(i,o,new Xf(n),new xm,new Sm(i),new Eh(new kh))),new Kh(i,s),new Zd(new fm),new Hh(i),new vg,new _p(i),new gg(i),new Zf(i),new rg(i),new Np(i),new kd(i))};function Ag(e,t){return e.geom===t}function io(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Ig(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>oo(s,o),i)}function so(e,...t){return t.reduce((r,n)=>oo(r,n),e)}function Ig(e){return typeof e=="object"&&e!==null&&"type"in e}function oo(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,Nt.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 Tg(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Tg(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 Lg(e){const t=e?.plugins??[],r=Eg(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:io,pipe:so,plugins:t}}var wg=e=>(t={})=>l.buildLayerInput(e,t);function Eg(e){const{geoms:t,stats:r,transforms:n}=Cs(e),a={};for(const o of t)a[o.type]=wg(o.type);const i={};for(const o of r)i[o.type]=()=>({type:o.type});const s={};for(const o of n)s[o.transformType]=c=>({type:"transform",transformType:o.transformType,options:c?.options});return{geom:a,stat:i,transform:s}}var Vg=24,Rg={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}},Cg={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},xr="…",lo=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(xr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+xr)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+xr};var F={timeZone:"UTC"},N=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},ce=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Rn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Dg=Nr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),co=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>ce(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=_n(a,i),{base:o,suffix:c}=Dn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),uo=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const{base:a,suffix:i}=Dn(n,t.abbreviation),s={..._n(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),Cn=e=>ce(t=>Dg(t)),mo=({locale:e,intlOptions:t})=>ce(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),po=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const a=_n(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=_g(e);return Dn(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}},_g=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"},Og=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).format(r)),kg=({locale:e,intlOptions:t})=>N(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...F,...t}).formatToParts(r);return Pg(n.map(Mg))}),ho=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t}).format(r)),fo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"long",...F,...t}).format(r)),On=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...F,...t}).format(r)),kn=e=>N(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),go=({locale:e,intlOptions:t})=>N(r=>{const n=(0,Pi.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t,year:void 0}).formatRange(r,n)}),yo=({locale:e,intlOptions:t})=>N(r=>{const n=(0,Pi.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).formatRange(r,n)}),Pn=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{year:"numeric",...F,...t}).format(r)),vo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),Pg=e=>e.map(t=>t.value).join(""),Mg=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},Ya=1e3,Ng=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>ce(a=>{const i={...Nn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Mn(a,t,i)}),Bg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Nn(n,t),notation:"compact",...r};return Mn(n,e,a)}),Fg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Nn(n,t),notation:"compact",...r,style:"percent"};return Mn(n,e,a)}),Mn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),bo=e=>Math.abs(e)>Ya?bo(e/Ya):Number.isInteger(e),$g=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Nn=(e,t)=>bo(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:$g(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Gg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),Ug=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",...F,...t}).format(r)),Wg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),Hg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),Bn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ng(e);case"date":case"datetime":return Gg(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Wg(e);case"decimal":case"integer":return Bg(e);case"duration":return Cn(e);case"month":return Ug(e);case"month_year":return On(e);case"percentage":return Fg(e);case"quarter":return kn(e);case"text":return Rn(e);case"time":return Hg(e);case"year":return Pn(e);case"lookup":return Bn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Kg=.9,zg=1/3,Yg=1/4,qg=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?jg(e):Xg(e),jg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=So(e.ticks,n),o=Zg(e.ticks,r.width),c=o*Kg;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=Yr(c);return{...e,ticks:zr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Yr(r.height*zg);return{...e,ticks:zr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Xg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=So(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Yr(r.width*Yg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:zr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},Zg=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},So=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:s,height:o}=t(i.formattedLabel);r.push(s),s>n&&(n=s),o>a&&(a=o)}return{widths:r,maxWidth:n,maxHeight:a}},zr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:lo(i.formattedLabel,r,a)})},Yr=e=>Math.max(0,Math.floor(e)),Jg=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let s=r-(e.length-1)*i;for(const o of e){const{width:c,height:u}=n(o);if(s-=a?c:u,s<0)return!1}return!0},Qg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?ey(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;Jg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},ey=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),qa=.5,ut=e=>({x:0,y:0,width:e.width,height:e.height}),Fn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,dt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:ry(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:ny(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,I=Xa(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Xa(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:ty(e,I,A,c,u)}},ja=(e,t,r,n)=>r-n>=e-qa&&r+n<=t+qa,ty=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||ja(e.x,e.x+e.width,t,n/2),s=e.height===0||ja(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},ry=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",ny=e=>e==="center"?"center":e==="start"?"min":"max",Xa=({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 s=r+i;return e==="min"?t==="inside"?n+s:n-s:t==="inside"?a-s:a+s},ay=(e,t,r,n,a)=>{const i=t??e,s=1-Math.max(e,i);return{box:{x:r*n,y:s*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},iy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=oy(e.layer);for(const a of e.layer.data){const i=R(a),s=_(a)??w(a);if(i===null||s===null||!We(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),{box:d,frame:m}=ay(s,k(a),i,e.panelRect.width,e.panelRect.height),h=dt({box:d,panel:ut(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},sy={place:iy,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"none"},oy=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Qt(e.data,e.mapping)?Fn(r):r,align:n}},$n=(e,t,r)=>{const n={},a=i=>{const s=n[i];if(s!==void 0)return s;const{width:o,height:c}=e(t,i,r),u={width:o,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},Lt=6,ly=e=>{const t=[],r=B(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=uy({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:n});for(const s of a){const o=e.layer.dataLabels.position==="auto"?py({mainAxis:e.coordSystem.mainAxis,isStacked:r,isNegativeBar:s.isNegative,shouldRotate:i,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):hy(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,ut(e.panelRect));if(o===null)continue;const c=s.boxes[o.position];t.push({layerId:e.layer.id,x:o.x,y:o.y,text:s.text,width:c.width,height:c.height,isRotated:o.isRotated,target:"observation",position:o.position})}}if(e.layer.dataLabels.showCategoryLabels)for(const a of fy(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=by({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const i of a)t.push(i)}return t},cy={place:ly,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"absoluteGrandTotal"},uy=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const s=[];let o=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y);for(const d of e.data){const m=Ao(t,d);if(m===null)continue;const h=a(d);if(h==="")continue;const p=$n(n,"observation",h),f=Gn(m,r);c&&p.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:h,boxes:p,bounds:f})}return{entries:s,shouldRotate:!i&&o}},Gn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),xo=(e,t,r,n,a)=>{if(e==="x"){let o=1-a,c=a-n;return c<0&&(o+=c,c=-c),{x:t,y:o,width:r-t,height:c}}let i=t,s=r-t;return s<0&&(i+=s,s=-s),{x:i,y:1-a,width:s,height:a-n}},Ao=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(t);return r===null||n===null||a===null||i===null?null:xo(e,r,n,a,i)},dy=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return xo(e,r,n,a,i)},my=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",qr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},py=e=>e.isStacked?gy({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):vy({edge:my(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),Io=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},hy=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,s=n.boxes[i],o=dt({box:n.bounds,panel:a,frame:Io(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:s.width,labelHeight:s.height});return{x:o.x,y:o.y,isRotated:!1,position:o.position}},fy=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:s}=e.layer.dataLabels,o=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=ut(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=Ao(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=$n(e.measureDataLabel,"category",p),g=f[o],y=Gn(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=dt({box:y,panel:u,frame:Io(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},gy=({bounds:e,box:t,isRotated:r})=>{const n=qr(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"}},yy=(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}}},vy=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=yy(e,t,a,i),g=qr(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height;if(y+s<d){if(v>m)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const V=h-p*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=qr(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=h+p*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},by=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return i;const o=t==="y";for(const c of s){const u=Gn(dy(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+Lt+m/2:u.x-Lt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-Lt-h/2:u.y+u.height+Lt+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},Sy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Ay(e.layer);for(const a of e.layer.data){const i=R(a),s=w(a);if(i===null||s===null||!We(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=dt({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:ut(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:o,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return t},xy={place:Sy,getPercentageValueStrategy:()=>"none"},Ay=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Qt(e.data,e.mapping)?Fn(r):r,align:n}};function mt(e){return e[l.VISUAL_VARIABLES.color]}function To(e){return e[l.VISUAL_VARIABLES.alpha]}function Un(e){return e[l.VISUAL_VARIABLES.size]}function jr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Lo(e){return e[l.VISUAL_VARIABLES.lineType]}var Iy={color:mt,alpha:To,strokeWidth:jr,lineType:Lo,size:Un,borderWidth:jr},ar=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:o=>{const c=r.get(o);if(c!==void 0)return c;const u=wy(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=Ty(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=rt(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=rt(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=rt(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=wo(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=rt(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},Ty=(e,t)=>{const r=(c,u)=>{const d=p=>Za(c.overrides,p,u)??Za(c.defaults,p,u);return{get:p=>{const f=d(p)?.declarations[p];if(f!==void 0)return Ly(f,t)},getSource:p=>{const f=d(p);return f===void 0?"unresolved":f.origin.list==="builtin"?"builtin":"authored"}}},n=c=>r(e.panelBorder,u=>{const d=u.select.target==="panelBorder"?u.select.edge:void 0;return d===void 0||d===c}),a=c=>u=>r(e[c],d=>d.select.target!==c?!1:d.select.axis===void 0||d.select.axis===u),i=c=>r(e.ruleLabel,u=>u.select.target!=="ruleLabel"?!1:u.select.layer===void 0||u.select.layer===c),s=(c,u)=>r(e.dataLabel,d=>d.select.target!=="dataLabel"||d.select.role!==void 0&&d.select.role!==c?!1:d.select.position===void 0||d.select.position===u),o=c=>r(e.tooltip,u=>u.select.target==="tooltip"&&u.select.part===c);return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:s,graph:r(e.graph,()=>!0),tooltip:{box:o(void 0),heading:o("heading"),label:o("label"),value:o("value"),primaryRow:o("primaryRow")}}},Za=(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}},Ly=(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},wy=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=wt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=wt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=wt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=wo(n,a);return o!==void 0?o:wt(e.defaults,n,a,void 0,t)}}),wt=(e,t,r,n,a)=>rt(e,t,r,n,a)?.value,rt=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(s===void 0||s.state!==n)continue;const o=s.declarations[t];if(o!==void 0&&Ey(s,r))return{value:Vy(o,a),origin:s.origin}}},Ey=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),Vy=(e,t)=>l.isLightDarkColor(e)?e[t]:e,wo=(e,t)=>{const r=Iy[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Ry=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Dy(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=ar().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=w(s);if(o===null||c===null||!We(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=dt({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:ut(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},Cy={place:Ry,getPercentageValueStrategy:()=>"none"},Dy=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}},Eo=e=>{const t=G(e),r=U(e),n=k(e),a=_(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),s=Math.abs(r-t),o=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-o,width:s,height:c}},Vo=e=>{const t=Eo(e);if(!t)return null;const r=t.width*Zp,n=t.height*Jp;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},Ja=4,_y=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const r=ar().geomReaders(e.layer);for(const n of e.layer.data){const a=Vo(n);if(a===null||!mt(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:s,height:o}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;s+Ja>c||o+Ja>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:s,height:o,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return t},Oy={place:_y,getPercentageValueStrategy:()=>"none"};function Wn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Hn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var ky=" · ",Ar=2,at=(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)},Py=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=at("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Ar&&t+i<=e.outerRadiusPx+Ar)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=at("tangential",r,n,a)/t,c=Ar/t;return Math.abs(r-e.midAngle)+o<=s+c},My=({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,Ny=({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+at("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},By=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:s})=>{const o=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+at("radial",o,i,s);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 m=e.innerRadiusPx-c;u=m>=0?m:e.innerRadiusPx+c}let d=o;if(n!=="center"&&u>0){const m=at("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:Py({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},Fy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=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;for(const m of e.layer.data){const{startAngle:h,endAngle:p}=Wn(m),{innerRadius:f,outerRadius:g}=Hn(m);if(h===null||p===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${ky}${y}`,I={startAngle:h,endAngle:p,midAngle:(h+p)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const K=e.measureDataLabel("observation",o,x);V={width:K.width,height:K.height},A=Ny({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const K=$n(e.measureDataLabel,"observation",x),T=K[r];A=By({wedge:I,placement:r,justify:Fn(n),align:a,offset:i,labelWidth:T.width,labelHeight:T.height}),V=K[A.position]}const j=c+Math.sin(A.labelAngle)*A.labelRadius,ie=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!My({x:j,y:ie,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:j,y:ie,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},$y={place:Fy,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Gy=e=>{const t=C({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=C({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const s=l.getStableKey(i[n]),o=r[s];return o!==void 0?o(a,i):t(a)}},C=e=>{switch(e.valueFormat.type){case"currency":return co(e);case"date":return Og(e);case"datetime":return kg(e);case"day_month":return ho(e);case"decimal":return uo(e);case"duration":return Cn(e);case"integer":return mo(e);case"month":return fo(e);case"month_year":return On(e);case"percentage":return po(e);case"quarter":return kn(e);case"text":return Rn(e);case"weekly_date_range":return go(e);case"weekly_date_range_with_year":return yo(e);case"year":return Pn(e);case"time":return vo(e);case"lookup":return Gy({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Kn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:bd(e),locale:r,numberFormat:t})}var Uy=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Xe(e,t),variable:r}:{read:Y,variable:l.GROUP_VARIABLES.group}},Ro=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Kn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Yy({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:Wy({layer:e,numberFormat:n,locale:s})}},Wy=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Uy(e.data,e.mapping),i=C({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return s=>{const o=n(s);return o===null?null:i(o,s)}},Hy=(e,t)=>{switch(t){case"stack":return Ky(e);case"fill":return zy(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Ky=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 s=a[t];if(s==null)return null;const o=r?.get(xn(a,t));return o===void 0?null:o.total}},zy=e=>{const t=st(e);return r=>{const n=k(r),a=_(r);if(!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a))return null;const i=Math.abs(a-n);if(i===0)return null;const s=t(r);return l.isStrictNumericDataValue(s)?s/i:null}},Yy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=W(e.data,e.dataLabels.labelSource),o=Hy(e,i),c=qy({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&Co(e);return m=>{const h=s(m);if(h===null)return"";if(!d||!l.isStrictNumericDataValue(h))return c(h,m);const p=o(m);return p===null||p===0?c(h,m):u(h/p)}},qy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(Co(e))return a;const o=jy(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:Xy(e.data,i),locale:n,numberFormat:t})},Co=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(qt(e.position,e.mapping))},jy=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const s=t.find(o=>o.scaleAestheticKey==="x");return s===void 0?null:C({valueFormat:s.valueFormat,locale:n,numberFormat:r})},Xy=(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)},zn={bar:{cartesian:cy,polar:$y},line:{cartesian:xy},point:{cartesian:Cy},area:{cartesian:sy},tile:{cartesian:Oy}},Zy=(e,t)=>zn[e]?.[t]!==void 0,Jy=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=zn[f]?.[h];if(g===void 0)continue;const y=Ro({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)Qy(x,h,c,u)||d.push(x)}return{labels:d}},Qy=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*ev({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=zn[o.geom]?.cartesian;if(c===void 0)continue;const u=Ro({layer:o,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:c.getPercentageValueStrategy(o)});for(const d of c.place(u))yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var Ir={abbreviation:"none",decimals:"auto"},Do=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return C({valueFormat:a,locale:e,numberFormat:Ir,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const s=i/r;return s===Number.POSITIVE_INFINITY?"∞":s===Number.NEGATIVE_INFINITY?"-∞":C({valueFormat:{type:"percentage"},locale:e,numberFormat:Ir,intlOptions:{signDisplay:"always"}})(s)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${C({valueFormat:{type:"decimal"},locale:e,numberFormat:Ir,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},Tr=6,Lr=6,wr=15,Er=5,Vr=15,_o=(e,t)=>{switch(e){case"small":return{arrowStartGap:Tr,arrowEndGap:Lr,offsetFromHigherObservation:wr,arrowheadSize:Er,curveRadius:Vr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Tr*1.5,arrowEndGap:Lr*1.5,offsetFromHigherObservation:wr*1.25,arrowheadSize:Er*1.5,curveRadius:Vr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Tr*2,arrowEndGap:Lr*2,offsetFromHigherObservation:wr*1.75,arrowheadSize:Er*2.5,curveRadius:Vr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},tv=(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},rv=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x,y:e.y-n},o={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 Xu=Object.create,Oi=Object.defineProperty,Zu=Object.getOwnPropertyDescriptor,Ju=Object.getOwnPropertyNames,Qu=Object.getPrototypeOf,ed=Object.prototype.hasOwnProperty,td=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Ju(t),i=0,s=a.length,o;i<s;i++)o=a[i],!ed.call(e,o)&&o!==r&&Oi(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Zu(t,o))||n.enumerable});return e},qt=(e,t,r)=>(r=e!=null?Xu(Qu(e)):{},td(t||!e||!e.__esModule?Oi(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-C_KBOU1F.cjs");let ye=require("color2k"),Pi=require("date-fns"),je=require("lodash-es"),et=require("d3-time"),rd=require("date-fns/differenceInDays"),pe=require("d3-regression"),Q=require("d3-scale"),Ne=require("d3-interpolate"),O=require("d3-scale-chromatic"),Ge=require("lodash-es/clamp");Ge=qt(Ge,1);let Bt=require("lodash-es/merge");Bt=qt(Bt,1);let Nr=require("humanize-duration");Nr=qt(Nr,1);let Ie=require("d3-shape"),nd=require("d3-delaunay"),Ft=require("lodash-es/isEqual");Ft=qt(Ft,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787820383880");var ad=1e6;function q(e){return String(Math.round(e*ad))}var Ta="#FFFFFF",yr="#1A1A1A",id=e=>{try{return(0,ye.getContrast)(e,Ta)>(0,ye.getContrast)(e,yr)?Ta:yr}catch{return yr}},sd=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ye.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ye.parseToRgba)(e);return r>=1?e:(0,ye.parseToRgba)(t)[3]<1?void 0:(0,ye.mix)(t,(0,ye.opacify)(e,1),r)}catch{return}},La=0;function N(){return La+=1,`${Math.random().toString(36).slice(2,6)}${La.toString(36)}`}function C(e){return e[l.POSITION_VARIABLES.x]}function V(e){return e[l.POSITION_VARIABLES.y]}function G(e){return e[l.POSITION_VARIABLES.xMin]}function U(e){return e[l.POSITION_VARIABLES.xMax]}function P(e){return e[l.POSITION_VARIABLES.yMin]}function k(e){return e[l.POSITION_VARIABLES.yMax]}function on(e){return e[l.POSITION_VARIABLES.yRaw]}function od(e,t){return e[l.resolveScaledAestheticVariable(t)]}var ld={xMin:0,xMax:1,yMin:0,yMax:1},Br=(e,t)=>{if(t.type==="polar")return null;const r=G(e)??C(e),n=U(e)??C(e),a=P(e)??V(e),i=k(e)??V(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},st=(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}}},Mi=e=>st(ld,e),Ni=["stack","dodge","identity","fill"],ln=["solid","dashed","dotted"],Bi=e=>ln.includes(e);function F(e){return e==="stack"||e==="fill"}var K=(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},Xe=(e,t)=>K(e,t.x),cn=(e,t)=>K(e,t.y),cd=(e,t)=>K(e,t.label),Fi=(e,t)=>K(e,t.color),ud=(e,t)=>K(e,t.size),dd=(e,t)=>K(e,t.alpha),md=(e,t)=>K(e,t.group),pd=(e,t)=>K(e,t.strokeWidth),wa={variable:l.POSITION_VARIABLES.yRaw};function jt(e,t){return F(e)?wa:t.y??wa}function ot(e){return K(e.data,jt(e.position,e.mapping))}var we=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},un=e=>hd(e)?l.extractVariableName(e.mapping.y):null,$i=e=>un(e)===null?null:ot(e),dn=e=>e.spatialKind!=="cells",hd=e=>e.spatialKind==="points"||e.spatialKind==="cells",Gi=(e,t)=>e.yScaleType===t.yScaleType&&$r(e.valueFormat)===$r(t.valueFormat),Fr=e=>`${e.yScaleType} y axis, ${$r(e.valueFormat)}`,$r=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Dt=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Ui=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(we(e))),n=un(e);return a=>({...a,anchorValue:Dt(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:Dt(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:Dt(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Hi(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 R(e,t){return Ki(e,t)}function L(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 Wi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Ze(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 Ki(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(l.isPlainObject(i)&&l.isPlainObject(s)){const o=Ki(s,i);o!==s&&(n[a]=o,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function Xt(e){return{pipe:t=>{const r=t(e);return Xt({...e,...r})},result:()=>e}}var fd=(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};function Ue(e,t){return e==="x"?t.x:t.y}function Zt(e,t){return e==="x"?t.y:t.x}function gd(e,t){return{main:Ue(e,t),cross:Zt(e,t)}}function Ea(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function yd(e){return e.type==="cartesian"}var j=e=>e[l.GROUP_VARIABLES.group],lt=e=>{const t=we(e),r=$i(e),n=dn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const o=n?j(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...o!==null&&{groupValue:o}}}},He=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,vd={type:"decimal"};function zi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function mn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):vd}function bd(e){return mn(e,l.extractVariableName(e.mapping.y))}function Yi({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??jt(t,r)}function qi(e,t){const r=Yi({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:K(e.data,r),valueFormat:mn(e,a)}}var ji=e=>{const t=we(e),r=$i(e),n=dn(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)},Xi=e=>{const t=l.extractVariableName(e.mapping.y),r=ot(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},Sd=["lt","lte","gt","gte","range"],xd={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"}},re=()=>!1,De=()=>!0;function Jt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Xi(e),parsingLocale:t}}function be(e,t){if("and"in e){const r=e.and.map(n=>be(n,t)).filter(n=>n!==De);return r.includes(re)?re:r.length===0?De:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>be(n,t)).filter(n=>n!==re);return r.includes(De)?De:r.length===0?re:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=be(e.not,t);return r===re?De:r===De?re:n=>!r(n)}return Id(e,t)}function Se(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Se(n,t,r)):"or"in e?e.or.flatMap(n=>Se(n,t,r)):"not"in e?Se(e.not,t,r):Ad(e,t,r)}function Ad(e,t,r){const{subject:n,effect:a}=xd[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=Td(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 Id(e,t){if(!t.hasVariable(e.variable))return re;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Dt(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 s=t.readValue(i,e.variable);for(const o of a)if(l.areDataValuesEqual(s,o))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>_e(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>_e(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="greater"||s==="equal"}}if("range"in e){const[a,i]=e.range,s=n(a),o=n(i);return c=>{const u=t.readValue(c,e.variable),d=_e(u,s),m=_e(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return re}function Td(e){for(const t of Sd)if(t in e)return t;return null}function _e(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 Ld=(e,t,r,n,a,i)=>{const s=Ji(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Zi(r.padding),c=o===null?Vd(s,r.padding):s,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin)};return o===null?u:{...u,defer:o}},wd=(e,t,r,n,a,i)=>{const s=Ji(e,t,r.predicate,n,a,i);return s===null?null:st(s,r.align)},Zi=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Ji=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let s=null,o=!1;const c=new Map;for(const u of n){const d=Se(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=be(r,Jt(u,i));if(h!==re)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Ed(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Ed=(e,t)=>({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)}),Vd=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},$t=(e,t,r)=>{const n=Cd(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Dd(n,t.offset,e.coordSystem)},Qi=(e,t)=>t.anchorType==="selection"?Ld(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)=>Gr(e,t,r)?.point??null,Gr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const o=e.geomRegistry.get(s.geom),{resolveAnchorPosition:c}=o;if(c===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=qi(s,o),d=ji(s),m=lt(s),h=Ui(s,n)(a);let p=-1;for(const f of s.data){if(p+=1,!d(f,h))continue;const g=c(f,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(g===null)continue;const y=es(s,f,u);if(y===null)continue;const v=m(f);if(v!==null)return{point:{...g,...y,observationIndex:p,anchor:a.align===void 0?v:{...v,align:a.align}},layerId:s.id}}}return null},Rd=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,o=a.y;if(s===void 0||o===void 0||s.kind!=="position"||o.kind!=="position")return null;const c=Ra(t.x,"x",r,i),u=Ra(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!He(d,m))return null;const h=Va(d,s,_d(e)),p=Va(m,o),f=Ea(n.mainAxis,{main:h.min,cross:p.min}),g=Ea(n.mainAxis,{main:h.max,cross:p.max});return st({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},es=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:fd(r.valueFormat,t),yScaleType:e.yScaleType}:null},Cd=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Rd(e,t);case"selection":return wd(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,kd(t),r)}},Dd=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Zi(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Va=(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}},_d=({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},kd=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Ra=(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},Od=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,s={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:Kd(s,t.differenceArrows),shapes:Bd(s,t.shapes),arrows:$d(s,t.arrows),textAnnotations:Gd(s,t.textAnnotations),images:Fd(s,t.images),stickers:Ud(s,t.stickers),pinnedNumbers:Hd(s,t.pinnedNumbers),comments:Wd(s,t.comments)};return Pd(this.container,o),Md(this.container,o),o}},ee=(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."})},Pd=(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)}},Md=(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 Nd(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."})},Nd=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},Bd=(e,t)=>{const r=[];for(const n of t){const a=Qi(e,n.region);if(a===null){ee(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,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},Fd=(e,t)=>{const r=[];for(const n of t){const a=Qi(e,n.region);if(a===null){ee(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,opacity:n.opacity})}return r},$d=(e,t)=>{const r=[];for(const n of t){const a=$t(e,n.start,"pin"),i=$t(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${ts(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,color:n.color,thickness:n.thickness,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle,lineStyle:n.lineStyle,hasStickerStyle:n.hasStickerStyle})}return r},Gd=(e,t)=>{const r=[];for(const n of t){const a=$t(e,n.at,"pin");if(a===null){ee(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,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},Ud=(e,t)=>{const r=[];for(const n of t){const a=$t(e,n.at,"pin");if(a===null){ee(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},Hd=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Wd=(e,t)=>{const r=[];for(const n of t){const a=pn(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Kd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Gr(e,n.start,"value"),i=Gr(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${ts(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}zd(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},ts=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",zd=(e,t,r,n)=>{Gi(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:Fr(r),actual:Fr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Yd(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,o]of r)o.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:rs(i),values:i};return new l.Dataset(n)}function rs(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 qd=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,rs(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Ee=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)}},jd=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)}},Xd=class extends Ee{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}},Zd=class{constructor(e){this.setupStage=new jd(e),this.transformStage=new Xd(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)}},Jd=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}},Qd=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:tm(e.scales,e.layers)}}transform(e){return e.layers.map(t=>nm(t))}},em=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ca=l.prefixInternalVariable("flipSwap"),tm=(e,t)=>rm(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,rm=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},nm=e=>{let t=e.data;for(const[r,n]of em){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ca).renameVariable(n,r).renameVariable(Ca,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},xe=Math.PI*2,am=8,im=1e-9,ns=(e,t)=>Math.abs(t-e)>=xe-im,We=e=>(e%xe+xe)%xe,as=(e,t,r)=>{if(ns(t,r))return!0;const n=We(r-t);return We(e-t)<=n},Gt=(e,t)=>{const r=Math.abs(We(e)-We(t));return Math.min(r,xe-r)},is=(e,t,r)=>e*xe+t+r,Ut=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),ss=(e,t)=>({angle:We(Math.atan2(e,t)),radius:Math.hypot(e,t)}),hn=(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}},Qt=(e,t)=>{const{x:r,y:n}=hn(e,t);return ss(r,n)};function os(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 ls=(e,t)=>os(t.domain!==null&&t.domain.length>0?t.domain:e),sm=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=cm(t,e.scales,e.layers),a=dm(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=lm(r,n),i=mm(t);return e.layers.map(s=>pm(t.theta==="y"?hm(s):s,a,i))}},om=[[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 lm(e,t){return r=>is(r,e,t)}function cm(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=um(n,e,r);return a===0?0:-Math.PI/a}function um(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 s of a.data.getValues(i))n.push(s)}return ls(n,e).length}function dm(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 mm(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function pm(e,t,r){let n=e.data;return n=ke(n,l.POSITION_VARIABLES.x,t),n=ke(n,l.POSITION_VARIABLES.xMin,t),n=ke(n,l.POSITION_VARIABLES.xMax,t),n=ke(n,l.POSITION_VARIABLES.y,r),n=ke(n,l.POSITION_VARIABLES.yMin,r),n=ke(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function ke(e,t,r){if(!e.hasVariable(t))return e;const n=e.getValues(t,{type:"numeric"}).map(a=>a===null?null:r(a));return e.addVariable(t,"numeric",n)}function hm(e){let t=e.data;for(const[r,n]of om){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,o=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),o&&(t=t.addVariable(r,"numeric",o))}return{...e,data:t}}var fm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Jd),this.register("flip",new Qd),this.register("polar",new sm)}},cs=new Set(["min","max","scalar"]),gm={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function ym(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 vm(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 bm(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=gm[a.axis][a.role];if(n.hasVariable(i))continue;const s=l.extractVariableName(r[a.aes]);!l.isDefined(s)||!n.hasVariable(s)||(n=n.addVariable(i,"numeric",n.getValues(s,{type:"numeric"})))}return n}var Sm=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:bm(n.data,r.positionRoles,a)}}},fn=["x","y"],gn=new Set(["x","y","ySecondary"]),ct=new Set(["color","size","alpha","strokeWidth","lineType"]),Ve=e=>gn.has(e),yn=e=>ct.has(e),us=e=>Ve(e)||yn(e);function oe(e){return e==="secondary"?"ySecondary":"y"}function ds(e,t){return e==="y"?oe(t):"x"}function M(e){return e==="ySecondary"?"y":e}var Je=(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 ct){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},er=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Je(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),xm=class{compute({data:e,mapping:t}){const r=Je(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=l.getStableKey(a.map(o=>o[s]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},Am=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},Im=(e,t,r)=>{const n=Te(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Te(e,t){const r=M(t);for(const n of ms(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var tr=(e,t)=>e===null?null:t[e]??e,Tm=(e,t)=>e===null?null:t[String(e)]??null,Le=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return vr(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 wm(i,t)?i:vr(t)}return vr(t)},Lm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:ms(t,e).some(r=>r.position==="fill");function ms(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var vr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},wm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Em=[{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}],Da={year:0,quarter:1,month:2,week:3,day:4,hour:5},Oe=40,Vm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return _m(r.unit).range(e,new Date(t.valueOf()+1),n)},Rm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,rd.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Oe;case"day":return a/t>Oe;case"week":return a/(7*t)>Oe;case"month":return a/(30*t)>Oe;case"quarter":return a/(90*t)>Oe;case"year":return a/(365*t)>Oe}},Cm=(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"}}},Dm=(e,t)=>{const r=km(t);return r===null?!1:Da[e]>Da[r]},_m=e=>{switch(e){case"hour":return et.utcHour;case"day":return et.utcDay;case"week":return et.utcMonday;case"month":case"quarter":return et.utcMonth;case"year":return et.utcYear}},km=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}},ps={left:"right",right:"left",top:"bottom",bottom:"top"},Om={x:!0,y:!0,ySecondary:!1},Pm=20,_a=new Set(["top","bottom"]),Mm={type:"percentage"};function Nm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(zi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=$m(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=Um(hs(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of gn){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=Bm({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function Bm(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:o,variableLabels:c}=e,{axisConfig:u,position:d,geometry:m}=Gm(t,n,i,s),h=Te(a,t),p=Lm(a,t)?Mm:Le({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:Fm(u,h,c),isVisible:u.isVisible,tickCandidates:Wm(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Hm(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Fm(e,t,r){return e.label?e.label:t?r[t]??null:null}function $m(e,t,r,n){const a=t.flatMap(o=>{const c=e.get(o.geom).grid[r];return c?[c]:[]}),i=a.some(o=>o.hideGridX),s=a.some(o=>o.hideGridY);return{x:{gridVisible:ka(i,n.axes.x.grid.isVisible)},y:{gridVisible:ka(s,n.axes.y.grid.isVisible)}}}function ka(e,t){if(e&&t===null)return!1}function Gm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:hs(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=ps[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 hs(e,t){return _a.has(e)===_a.has(t)?e:t}function Um(e,t){return t.has(e)?ps[e]:e}function Hm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Om[r]}var Wm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=zm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Pm;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Ke(e,u))}))}return i}return e.spec.scaleType==="datetime"?Km(e,t):[{ticks:e.generateTicks().map(a=>Ke(e,a))}]},Km=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Ke(e,o))}];const a=new Set,i=[],s=(o,c)=>{if(o.length===0)return;const u=l.getStableKey(o);a.has(u)||(a.add(u),i.push({ticks:o.map(d=>Ke(e,d)),valueFormat:c}))};for(const o of Em)Rm({...o,start:r,stop:n})||Dm(o.unit,t)||s(e.generateTicks({interval:o}),Cm(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},zm=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:[Ke(e,r),Ke(e,n)]}},Ke=(e,t)=>({value:t,position:e.map(t)});function fs({scale:e,aesthetics:t,layers:r}){const n=Ym({layers:r,aesthetics:t}),a=gs({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Ym({layers:e,aesthetics:t}){const r=gs({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>l.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function gs({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(c=>l.isDefined(i.mapping[c]));if(s===void 0)continue;const o=l.extractVariableName(i.mapping[s]);if(!(o===null||!i.data.hasVariable(o)))for(const c of i.data.getValues(o,{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 vn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function qm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!vn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=Te(t,"color");if(ys({colorVariableName:a,xVariableName:Te(t,"x"),mapsColorAcrossMultipleLayers:Xm(t)>1,isMergedWithAnotherAesthetic:jm(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return fs({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Le({layers:m?[m]:t,scaleType:i,variableName:h}),label:Tm(o,r)}})}var ys=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function jm(e,t,r){if(r===null)return!1;for(const n of ct){if(n==="color")continue;const a=e[n];if(!(a===void 0||!vn(a))&&Te(t,n)===r)return!0}return!1}var Xm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function vs(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Zm(e,t,r,n){const a=r.findIndex(i=>vs(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:tr(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function Oa(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 bs=e=>e==="none"?"first":e,Jm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Pa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Pa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Qm=(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}},Pa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function ep(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?tp(e,n):rp(e,n)}function tp(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(o=>o.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=l.extractVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:Le({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function rp(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>vs(o,d)))return null;const c=Zm(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>np({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 np({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=l.extractVariableName(i.mapping.y);if(s===null||t==="total"&&i.position==="fill")return null;const o=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Le({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=sp(i.data,o),h=Le({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=op(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=Oa(f,y,e.value),x=Oa(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Jm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:ap(t,m,x),comparison:ip(t,r,m,x,v)}}function ap(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 ip(e,t,r,n,a){return e!=="current"||!r?null:Qm(n.map((i,s)=>({main:i,cross:a[s]??null})),bs(t))}function sp(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function op(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function X(e,...t){return e?t.includes(e.geom):!1}function _(e,t){return e.find(r=>r.id===t)}function le(e,...t){return e.find(r=>t.includes(r.geom))}function lp(e,...t){return e.filter(r=>t.includes(r.geom))}function bn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Sn(e){const t=e.filter(r=>!bn(r,e));return t.length>0?t:e}function Ss({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Sn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var cp=3;function up({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const o=new Map(i.map(y=>[l.getStableKey(y.value),y])),c=vp(hp({scales:e,layers:r})),u=Te(r,"x"),d=c.map(y=>{if(gp(y,u,r))return null;const v=Sp({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=dp(d),h=Sn(r),p=wp(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&Lp(s,m,h,n))return{drawn:[],position:p};const f=Ep(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?Dp(h[0]):null;return{drawn:d.map(({built:y})=>mp(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function dp(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function mp(e,t,r){const{position:n,display:a}=t,i=pp(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function pp(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function hp(e){const{scales:t,layers:r}=e,n=[];for(const a of ct){const i=t[a];if(i===void 0||i.kind==="identity"||!fp(a,r))continue;const s=Te(r,a),o=Cp(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function fp(e,t){const r=M(e);return t.some(n=>l.isDefined(n.mapping[r]))}function gp(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:ys({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:yp(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function yp(e,t){const r=M(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function vp(e){const t=new Map;for(const r of e){const n=Rp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function bp(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Sp({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>M(c.scaleAestheticKey)),s=fs({scale:a.scale,aesthetics:i,layers:r}),o=Le({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:tr(a.variableName,t),items:s.map(c=>xp(c,e,i,o,n))}}function xp(e,t,r,n,a){const i={};for(const o of t)bp(i,o.scaleAestheticKey,o.scale.map(e.value));const s=Ip(e,t,r,n,a);return{value:e.value,label:Ap(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function Ap(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function Ip(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=Tp(i,r);return i===void 0||s===null?n:Le({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function Tp(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 Lp(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 wp(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,o=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,F(u.position)&&(o=!0))}const c=r>=cp;return i&&s?"top":i?c?"right":"top":o?Vp(a)?"top":c?"right":"top":"top"}function Ep(e,t){return e==="pill"?"pill":Ss(t)?"direct":"pill"}function Vp(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Rp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Cp(e,t){return vn(t)?"discrete":`continuous:${e}`}function Dp(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(k(c))||l.isDefined(V(c)));if(!n)return;const a=j(n);if(!l.isDefined(a))return;const i=P(n),s=k(n)??V(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var _p=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=Am(e.originalData),r=qm({scales:e.scales,layers:e.layers,valueLabels:Im(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=ep(n),i=up(n),s={...i,drawn:kp(a,i.drawn)};return{axes:Nm(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},kp=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Op=e=>l.getStableKey([j(e)]),xn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Pp=e=>e!=="data-point",Ht=(e,t,r)=>{switch(e){case"series":return Op(t);case"x-value":return xn(t,r)}},Mp={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function xs(e){const t=Mp[e]??null;return t===null?null:{strategy:t,composition:As()}}function As(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Np=class extends Ee{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=Bp({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Bp({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(I=>{const W=Se(I.predicate,e.data);for(const Z of W)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return W.length===0}),s=l.extractVariableName(e.mapping.x),o=Jt(e,r),c=i.map(I=>({predicate:be(I.predicate,o),scope:I.scope})),u=c.some(({scope:I})=>I==="series"),d=c.some(({scope:I})=>I==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let T=!1,A=0;for(const I of e.data){let W,Z;p!==null&&(W=Ht("series",I,s),p[A]=W),f!==null&&(Z=Ht("x-value",I,s),f[A]=Z),g!==null&&(g[A]=I);for(const{predicate:At,scope:It}of c)if(At(I))switch(It){case"series":W!==void 0&&v.add(W);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,T=!0;break}A++}if(v.size===0&&x.size===0&&!T)return As();const w=new Uint8Array(h),E=[];let Y=0;for(let I=0;I<h;I++){const W=p?.[I],Z=f?.[I],At=W!==void 0&&v.has(W),It=Z!==void 0&&x.has(Z),Aa=y[I]===1;if(n==="observation-rerender")(At||Aa||It)&&(w[I]=1,Y++);else if(At)w[I]=1,Y++;else if(Aa||It){const Ia=g?.[I];Ia!==void 0&&E.push({observation:Ia,observationIndex:I})}}const ie=Y>0?{...e,data:e.data.filterByMask(w)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&ie!==null,matchedLayer:ie,overlayCandidates:E}}var Fp=l.prefixInternalVariable("__ungrouped__");function $p(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"}),s=new Map,o=i.map((c,u)=>{if(c===null)return null;const d=r[u]??Fp;let m=s.get(d);return m||(m=new l.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",o)}return n}var Gp=()=>({defaults:[],overrides:[],warnings:[]}),Up=class extends Ee{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,Ma(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:Ma(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=Xt({data:t,mapping:r}).pipe(({data:o,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:o,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>({data:this.groupCompiler.compute({data:o,mapping:c}).data,mapping:c})).pipe(({data:o,mapping:c})=>({data:$p(o),mapping:c})).pipe(({data:o,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:o,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:o,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:xs(e.geom),styles:Gp()}}};function Ma(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Is(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Ur(e,t){const r=Ts(e,t),n={};for(const{layer:i,scaleConstraints:s,crossAxis:o}of r)s.zeroBaseline===!0&&(n[o]={nice:(n[o]?.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:Wp(r),zeroAxes:n,bandPadding:Kp(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Hp(e,t){const r=Ts(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:Na(n),zeroAnchored:Na(a)}}return null}var Na=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function Ts(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:oe(n.yScaleType)})}),r}function Wp(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of Ls(r))t.add(n);return[...t]}function Kp(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Ls(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Ls({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var zp=new Set(["label","group"]),Yp=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},s={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(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),Is(this.container.diagnostics,t)}checkPostCompile(e){zi(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:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!er(r,t))return[];const c=s==="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 '${s}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:s},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:s,aesthetics:o}=this.container.geomRegistry.get(r),c=[...ym(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!cs.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,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:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Hp(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:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...vm(i),...s.map(h=>h.name)]),u=zp,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},ae=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=Ni,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)}},An=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},In=(e,{coordSystem:t})=>{if(t.type==="polar")return null;const r=C(e),n=V(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},qp=class extends ae{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=In}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=An(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},jp=.7,Xp=.1,Zp=.03,Jp=.05,ws=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Qp=class extends ae{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.resolveAnchorBox=Br,this.resolveDataLabelDefaults=t=>F(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>Hr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return eh(t);if(i!==void 0){const m=Br(t,r);return m===null?null:st(m,i)}const s=F(n),o={isSolo:!s||ws(t)==="solo",isNegative:s&&th(t),purpose:a};if(r.mainAxis==="x"){const m=G(t),h=U(t),p=Ba({lowerBound:P(t),upperBound:k(t)??V(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=P(t),u=k(t),d=Ba({lowerBound:G(t),upperBound:U(t)??C(t),options:o});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=Hr(r,n);e=An(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}},Hr=({width:e},t)=>e!==void 0?e:t==="polar"?1:jp,eh=e=>{const t=G(e),r=U(e),n=P(e),a=k(e);if(t===null||r===null||n===null||a===null)return null;const i=(t+r)/2,s=(n+a)/2;return{x:.5+.5*s*Math.sin(i),y:.5-.5*s*Math.cos(i)}},th=e=>{const t=on(e);return l.isStrictNumericDataValue(t)&&t<0},Ba=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},rh=class extends ae{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.resolveAnchorBox=Br,this.resolveAnchorPosition=In}compile(e){return{data:An(e.data,e.mapping),mapping:{}}}},nh=class extends ae{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=In,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:{}}}},ah=class extends ae{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=Fa(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=Fa(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}}}},Fa=(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},ih=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},sh=class extends ae{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=ih,this.resolveAnchorPosition=t=>{const r=G(t),n=U(t),a=P(t),i=k(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:{}}}},oh=[new Qp,new nh,new rh,new qp,new ah,new sh],rr=class extends l.Registry{constructor(){super("geom");for(const e of oh)this.register(e.type,e)}},Re=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},lh=class extends Re{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,...Je(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},ch=class extends Re{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},uh=class extends Re{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}}}},dh=2,Es=1440*60*1e3,mh=class extends Re{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 s=e.getType(a),o=e.getType(i);if(o!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${o}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:o}});const c=Je(e,t),u=bh(a,s,i,c,e);return c.length===0?$a({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=Sh(d,c);$a({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},$a=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=ph({data:e,xVariable:t,yVariable:n,xType:r});c.length<dh||(o?vh({observations:c,spec:a,output:i,groupObservation:s}):gh({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},ph=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?hh(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=fh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},hh=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},fh=({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)/Es+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}`})}},gh=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Vs(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?yh(o,r):o;a.push({x:u,y:c,groupObservation:i})}},yh=(e,t)=>t===null?new Date(e):new Date((e-1)*Es+t),vh=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const o of e)a.has(o.x)||a.set(o.x,o.originalX);const i=[...a.keys()].sort((o,c)=>o-c);if(t.method==="loess"){const o=Vs(t,e),c=new Map;for(const[u,d]of o)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=Rs(t,e);for(const o of i){const c=a.get(o),u=s.predict(o);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},Vs=(e,t)=>e.method==="loess"?(0,pe.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):Rs(e,t),Rs=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,pe.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,pe.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,pe.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,pe.regressionQuad)().x(r).y(n)(t);case"power":return(0,pe.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,pe.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=[],s=[],o=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),s.push(u);for(const m of n)o[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:o[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},Sh=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},xh=class extends Re{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],...Je(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},Ah=[new ch,new lh,new mh,new uh,new xh],Ih=class extends l.Registry{constructor(){super("stat");for(const e of Ah)this.register(e.type,e)}};function Th({geoms:e,stats:t,transforms:r}){const n=new rr,a=new Ih,i=new l.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function Tn(e){if("definition"in e)return e.definition;if(Ds(e)||_s(e)||ks(e))return e}function Cs(e){const t=[],r=[],n=[];for(const a of e){const i=Tn(a);i&&(Ds(i)?t.push(i):_s(i)?r.push(i):ks(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...br("geom",t,a=>a.type),...br("stat",r,a=>a.type),...br("transform",n,a=>a.transformType),...Lh(t),...wh(t)]}}function Lh(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 wh(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 br(e,t,r){const n=new Map;for(const i of t){const s=r(i),o=n.get(s);o?o.add(i):n.set(s,new Set([i]))}const a=[];for(const[i,s]of n)s.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${s.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var Ds=e=>e instanceof ae,_s=e=>e instanceof Re,ks=e=>"transformType"in e&&typeof e.apply=="function",Eh=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},nr=class{},Vh=class extends nr{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=Rh(e)??[-.7/2,.7/2],s=r.length>1?Xp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Rh=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]},Ga=l.prefixInternalVariable("__ungrouped__"),Os=(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,s=i?[Ga]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?Ga:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},Ps=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=Ch(p===o,p===d)}return a},Ch=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Dh=class extends nr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=Os(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const T=x>=0?m:h;if(T===0){c[v]=0,o[v]=0;continue}const A=x/T;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=Ps(c,o,a,s);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},_h=class extends nr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},kh=class extends nr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=Os(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=Ps(c,o,a,s);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const m=l.extractVariableName(t.y);return m!==null&&(d=d.addVariable(m,"numeric",o)),{data:d,mapping:{}}}},Oh=class extends l.Registry{constructor(){super("position"),this.register("identity",new _h),this.register("stack",new kh),this.register("fill",new Dh),this.register("dodge",new Vh)}},Ph=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!l.isDefined(s.aes)||yn(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ds(s.axis,t.yScaleType));if(!c)continue;const u=a.getValues(o,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},Mh=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(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},Nh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},Bh=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(oe(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},Fh=class{map({data:e,layer:t,getPositionScale:r}){const n=r(oe(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)?$h(e,n,a):Gh(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function $h(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"}),s="reverse"in t.spec&&t.spec.reverse===!0,o=e.size(),c=Ms(o);for(let u=0;u<o;u++){const d=n[u],m=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(h)||(c.min[u]=d+(s?-h:m)*r,c.max[u]=d+(s?-m:h)*r)}return c}function Gh(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 s=0;s<a;s++){const o=r[s],c=n[s];!l.isDefined(o)||!l.isDefined(c)||(i.min[s]=t.map(o),i.max[s]=t.map(c))}return i}function Ms(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Uh=[new Mh,new Bh,new Nh,new Fh,new Ph];function Hh(e,t){const r=e[t];return r?.kind==="position"?r:null}var Wh=class extends Ee{constructor(e,t=Uh){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=>Hh(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}}},Kh=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const a of e.scales)t.set(a.scaledAesthetic,a);const r=this.collectValues(e.layers,t),n={};for(const[a,i]of t){const s=r.get(a)??[];n[a]=this.registry.get(i.scaleType).compile(i,s)}return n}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=M(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const s=l.extractVariableName(i.mapping[a]);if(!l.isDefined(s)||!i.data.hasVariable(s))continue;const o=i.data.getType(s);if(n.includes(o)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${o})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o}}),r.scaledAesthetic==="lineType"&&o!=="categorical"){const c=o==="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 ${o} variable '${s}'. ${c}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o},suggestion:c})}}Is(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!l.isDefined(s))continue;const o=i==="y"?oe(n.yScaleType):i,c=a.get(i)??(us(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,s,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)||yn(n.aes)||t.set(n.aes,ds(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 s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},zh=["rgb","lab","hcl","hsl"],Yh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],Ns=["RdBu","BrBG","PuOr","Spectral"],Bs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},qh=new Set(Ns.map(e=>e.toLowerCase()));function Fs(e){const t=e.toLowerCase(),r=Bs[t];return r?r.toLowerCase():t}function jh(e){return qh.has(Fs(e))}var Xh={rgb:Ne.interpolateRgb,lab:Ne.interpolateLab,hcl:Ne.interpolateHcl,hsl:Ne.interpolateHsl},Zh={viridis:O.interpolateViridis,magma:O.interpolateMagma,inferno:O.interpolateInferno,plasma:O.interpolatePlasma,cividis:O.interpolateCividis,turbo:O.interpolateTurbo,blues:O.interpolateBlues,greens:O.interpolateGreens,greys:O.interpolateGreys,oranges:O.interpolateOranges,purples:O.interpolatePurples,reds:O.interpolateReds,rdbu:O.interpolateRdBu,brbg:O.interpolateBrBG,puor:O.interpolatePuOr,spectral:O.interpolateSpectral};function Ln(e){const t=Qh(e);return e.reverse?r=>t(1-r):t}function Jh(e={},t=2){const r=Ln({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 Qh(e){const t=Xh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ne.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Zh[Fs(e.scheme)];if(r)return r}return(0,Ne.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var ut=class{createPositionScale(e,t){return{kind:"position",aesthetic:M(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:M(e.scaledAesthetic),spec:e,...t}}},ef=class extends ut{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=Ve(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"&&tf(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:M(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,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).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=rf(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=Ln(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],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,Q.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,Q.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]}},tf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function rf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var nf=class extends ut{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=Ve(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=af(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?Vm(i,s,c.interval):[]:a.ticks(c?.count)})}},af=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),sf=class extends ut{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=Ve(e.scaledAesthetic),n=ls(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,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,Q.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})}},of=class extends ut{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:M(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},lf=class extends ut{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const r=os(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},cf=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new ef(e)),this.register("discrete",new sf),this.register("datetime",new nf),this.register("identity",new of),this.register("palette",new lf)}},_t={color:null,size:"small",labelCrossPosition:.5},he={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},Sr={zOrder:"foreground",fit:"contain",opacity:1},uf={x:8,y:8,unit:"px"},kt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},fe={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},df={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}},mf=(e,t,r)=>{const n=pf(e,t),a=gf(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>vf(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Af(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Lf(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>yf(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>bf(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>If(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>Sf(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>xf(e,i,r)).filter(l.isDefined)}},pf=(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:N()}):(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 ff(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},ff=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],gf=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},wn=(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},yf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??N(),content:t.content,at:a,width:t.width,align:t.align??kt.align,backgroundColor:t.backgroundColor??kt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??kt.backgroundColorStyle}},vf=(e,t,r)=>{const n=at(e,t.start,r),a=at(e,t.end,r);return n===null||a===null?null:{id:t.id??N(),start:n,end:a,label:t.label,color:t.color??_t.color,size:t.size??_t.size,labelCrossPosition:t.labelCrossPosition??_t.labelCrossPosition}},at=(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 wn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=at(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},bf=(e,t,r,n)=>{const a=Wt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??N(),at:a,sticker:t.sticker}},Sf=(e,t,r)=>{const n=at(e,t.at,r);return n===null?null:{id:t.id??N(),at:n}},xf=(e,t,r)=>{const n=at(e,t.at,r);return n===null?null:{id:t.id??N(),at:n,content:t.content}},Af=(e,t,r)=>t.region.anchorType==="annotation"&&!wn(e,t.region.ref,r,t.id)?null:{id:t.id??N(),kind:t.kind??he.kind,zOrder:t.zOrder??he.zOrder,region:Tf(t.region),fillColor:t.fillColor===void 0?he.fillColor:t.fillColor,fillOpacity:t.fillOpacity??he.fillOpacity,strokeWidth:t.strokeWidth??he.strokeWidth,strokeColor:t.strokeColor??he.strokeColor},If=(e,t,r)=>t.region.anchorType==="annotation"&&!wn(e,t.region.ref,r,t.id)?null:{id:t.id??N(),src:t.src,zOrder:t.zOrder??Sr.zOrder,region:t.region,fit:t.fit??Sr.fit,opacity:t.opacity??Sr.opacity},Tf=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:uf},Ua=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=df[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Lf=(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??N(),start:Ua(a),end:Ua(i),color:t.color??fe.color,thickness:t.thickness??fe.thickness,startArrowheadStyle:t.startArrowheadStyle??fe.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??fe.endArrowheadStyle,lineStyle:t.lineStyle??fe.lineStyle,hasStickerStyle:t.hasStickerStyle??fe.hasStickerStyle}},wf={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},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function Ef(e){const t=(0,je.merge)({},wf,e);return t.content=Vf(t.content,e?.content),t}var Vf=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Rf={xLimits:null,yLimits:null},Ot={theta:"x",startAngle:0,innerRadius:0};function Wr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Bt.default)({},Rf,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Ot.theta,startAngle:t.params?.startAngle??Ot.startAngle,innerRadius:(0,Ge.default)(t.params?.innerRadius??Ot.innerRadius,0,1)}}}}function Cf(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??N(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Df=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=Ha(e.filter(n=>n.severity==="error")),r=Ha(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},_f=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 Ha(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var kf={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 $s(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 Ce(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new _f(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=Mf({dataLabels:Bf(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return Pf({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??N(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:$s(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:o.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??o.defaultInteractive,dataLabels:u}}function Of(e,t,r,n,a){const i=n.map((s,o)=>Ce(e,t,r,s,a,o));return Us(e,i)}var Gs=(e,t,r,n)=>n.label!==void 0?n.label:Yi({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Us=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Ze(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=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}}}})},Pf=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t==="polar",s=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"&&s&&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&&!(s&&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'."}),a.showCategoryLabels&&a.showDataLabels&&!i&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showCategoryLabels only applies to polar bars (pie / donut); it will be ignored.",suggestion:"Turn off showCategoryLabels for this layer."})},Mf=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const o=Nf(t,r,n);if(o===null)return e;const c=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${o}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Nf=(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,Bf=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Gs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,je.merge)({},kf,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Hs={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ff={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 Ws(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Ur(e.geomRegistry,n)}}function En(e,t){switch(t.scaleType){case"inferred":return En(e,Hf(e,t));case"continuous":{const r=Hs[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:Wf(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 Kr(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 $f(e,t){const{scales:r,layers:n,coords:a}=t,i=Ws(e,t),s=Yf(zf(r,n),i.demands),o=new Map;for(const u of s)o.set(u.scaledAesthetic,u);const c=[...o.values()].map(u=>{const d=Gf(i,u);return En(i,d)});return a.coordType==="polar"?c.map(Ks):c}function Kr(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??Uf(e.scaledAesthetic,t)}}var Ks=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Gf(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:M(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 Uf(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function Hf({data:e,layers:t,mapping:r,demands:n},a){const i=M(a.scaledAesthetic),s=a.scaledAesthetic==="ySecondary"?Kf(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const o=n.zeroAxes[a.scaledAesthetic];if(o!==void 0){const m=a.options;return l.continuous(a.scaledAesthetic,{...m,zero:!0,...!o.nice&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!e.hasVariable(c))return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=Hs[a.scaledAesthetic];switch(Ff[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 Wf(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:M(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&jh(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:M(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Kf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function zf(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Yf(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var qf=e=>{const t=new Set;e!==void 0&&zs(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},zs=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])zs(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function jf(e,t,r){const n=Wr(t.coords),a=Of(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=$f(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=Ef(t.config),o=Cf(e,t.highlights,a),c=mf(e,t.annotations,a),u=qf(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:o,styles:u,annotations:c,coords:n,config:s}}var Ys=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return jf(this.container,{...e,data:t},r)}},Xf=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})}},Zf=class extends Ee{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of dg(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of mg(e.styles))this.container.diagnostics.addWarning(r);for(const r of pg(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=to({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Be={color:"color",alpha:"unitInterval",saturation:"unitInterval"},qs={bar:{...Be,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Be,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Be,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Be,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Wa=1,Ka=1e3,Jf="'none' or a shadow object { offsetX, offsetY, blur, color }",Tt={color:"color",strokeWidth:"pixels",lineType:"lineType"},Lt={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},ge={panelBorder:{...Tt,borderRadius:"pixels"},panelBorderEdge:Tt,gridLine:Tt,tickLine:{...Tt,length:"pixels"},axisLabel:Lt,tickLabel:{...Lt,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...Lt,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily"},tooltip:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},tooltipText:Lt,tooltipPrimaryRow:{background:"color"}},Qf=new Set([...Object.keys(Be),...Object.values(qs).flatMap(e=>Object.keys(e??{})),...Object.values(ge).flatMap(e=>Object.keys(e))]),js=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","tooltip"],eg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),tg=(e,t,r="en-US")=>to({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),rg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Xs(e.styles)}},Xs=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:[]},tooltip:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(ar(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ng(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${js.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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 m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!ig(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(eg.has(m.target)){const p=m.axis;if(p!==void 0&&!cg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${fn.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${ze(p)}.`,context:{param:"layer",actual:ze(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="tooltip"){const p=m.part;if(p!==void 0&&!lg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown part '${String(p)}'.`,context:{param:"part",actual:String(p),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!sg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!og(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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:ag(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},ar=e=>e.select.target==="geom",ng=e=>{const t=e.select.target;return t!=="geom"&&js.includes(t)},Zs=e=>(e!==void 0?qs[e]:void 0)??Be,ag=e=>e.target==="panelBorder"?e.edge===void 0?ge.panelBorder:ge.panelBorderEdge:e.target==="tooltip"?e.part===void 0?ge.tooltip:e.part==="primaryRow"?ge.tooltipPrimaryRow:ge.tooltipText:ge[e.target],ig=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),sg=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),og=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),lg=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),cg=e=>typeof e=="string"&&fn.includes(e),ug=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!ar(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=Vn({declarations:a.declarations,vocabulary:Zs(s),tokens:t,location:`builtin[${i}]`,origin:o,warnings:r});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:o})}),n},Js=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},dg=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Js(e,(a,i,s)=>{const o=a.select;if(o.target!=="geom"&&o.target!=="ruleLabel")return;const c=o.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] 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},mg=e=>{const t=[];return Js(e,(r,n,a)=>{if(!ar(r))return;const i=r.when?.state;i===void 0||Qs(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(s=>`'${s}'`).join(", ")}.`})}),t},Qs=e=>l.STYLE_STATES.includes(e),pg=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))eo(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${ze(n)}.`,context:{param:"tokens",actual:ze(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},eo=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,me=e=>typeof e=="number"&&Number.isFinite(e),ze=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),to=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Jt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!ar(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&&!Qs(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const T=Se(v,t.data,"style-rule");if(T.length>0){for(const A of T)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=Vn({declarations:h.declarations,vocabulary:Zs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:be(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...ug(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},Vn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${ze(g)}.`,context:{param:p,expected:f,actual:ze(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return eo(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=Qf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":me(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":me(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Bi(f)?u(p,f):d(p,`one of ${ln.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":me(f)&&f>=Wa&&f<=Ka?u(p,f):d(p,`a number in [${Wa}, ${Ka}]`,f);break;case"multiplier":me(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;case"shadow":{if(f==="none"){u(p,f);break}const y=f;if(!me(y.offsetX)||!me(y.offsetY)||!me(y.blur)||y.blur<0){d(p,Jf,f);break}const v=m(p,y.color);v!==void 0&&u(p,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:v});break}default:break}}return o},hg=({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}},fg=({layer:e})=>{if(e.position!=="stack")return;const t=l.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const r=new Map;for(const a of e.data){const i=a[t],s=P(a),o=k(a),c=G(a),u=U(a),d=on(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=xn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},gg=class extends Ee{constructor(e){super(),this.container=e}dependencies(){return[]}compileLayer(e){const t=this.container.geomRegistry.get(e.geom),r={};if(t.summaries.stackTotals){const n=fg({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=hg({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},ro=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"},yg=["color","size","alpha","strokeWidth","lineType"],vg=class extends Ee{dependencies(e){return yg.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 s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,za[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,za[a],bg(c)))}return{...e,data:r}}},bg=e=>t=>l.isDefined(t)?e.map(t):null;function no(e=new rr){return{diagnostics:new Df,geomRegistry:e}}var ao=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"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.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>e.data===void 0?this.runPipeline({spec:e.spec}):(this.lastData=e.data,this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data)})})));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}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:[Hi(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:s,getStats:o}of this.stages){const c=o();i[s]={hits:c.hits-t[s].hits,misses:c.misses-t[s].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e}){return{...Xt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result(),spec:e}}},Sg=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],xg=({plugins:e=[]}={})=>{const t=Cs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Th(t),i=no(r),s=new cf(i),o=new ro(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new ao(i,new l.DataCompiler,new Ys(i),o,new qd,new Yp(i,o,n,new Up(i,o,new Xf(n),new xm,new Sm(i),new Eh(new Oh))),new Kh(i,s),new Zd(new fm),new Wh(i),new vg,new _p(i),new gg(i),new Zf(i),new rg(i),new Np(i),new Od(i))};function Ag(e,t){return e.geom===t}function io(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Ig(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>oo(s,o),i)}function so(e,...t){return t.reduce((r,n)=>oo(r,n),e)}function Ig(e){return typeof e=="object"&&e!==null&&"type"in e}function oo(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,Bt.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 Tg(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Tg(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 Lg(e){const t=e?.plugins??[],r=Eg(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:io,pipe:so,plugins:t}}var wg=e=>(t={})=>l.buildLayerInput(e,t);function Eg(e){const{geoms:t,stats:r,transforms:n}=Cs(e),a={};for(const o of t)a[o.type]=wg(o.type);const i={};for(const o of r)i[o.type]=()=>({type:o.type});const s={};for(const o of n)s[o.transformType]=c=>({type:"transform",transformType:o.transformType,options:c?.options});return{geom:a,stat:i,transform:s}}var Vg=24,Rg={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}},Cg={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},xr="…",lo=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(xr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+xr)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+xr};var $={timeZone:"UTC"},B=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},ce=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Rn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Dg=Nr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),co=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>ce(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=_n(a,i),{base:o,suffix:c}=Dn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),uo=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const{base:a,suffix:i}=Dn(n,t.abbreviation),s={..._n(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),Cn=e=>ce(t=>Dg(t)),mo=({locale:e,intlOptions:t})=>ce(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),po=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const a=_n(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=_g(e);return Dn(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}},_g=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"},kg=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...$,...t}).format(r)),Og=({locale:e,intlOptions:t})=>B(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...$,...t}).formatToParts(r);return Pg(n.map(Mg))}),ho=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...$,...t}).format(r)),fo=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{month:"long",...$,...t}).format(r)),kn=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...$,...t}).format(r)),On=e=>B(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),go=({locale:e,intlOptions:t})=>B(r=>{const n=(0,Pi.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...$,...t,year:void 0}).formatRange(r,n)}),yo=({locale:e,intlOptions:t})=>B(r=>{const n=(0,Pi.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...$,...t}).formatRange(r,n)}),Pn=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{year:"numeric",...$,...t}).format(r)),vo=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...$,...t}).format(r)),Pg=e=>e.map(t=>t.value).join(""),Mg=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},Ya=1e3,Ng=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>ce(a=>{const i={...Nn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Mn(a,t,i)}),Bg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Nn(n,t),notation:"compact",...r};return Mn(n,e,a)}),Fg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Nn(n,t),notation:"compact",...r,style:"percent"};return Mn(n,e,a)}),Mn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),bo=e=>Math.abs(e)>Ya?bo(e/Ya):Number.isInteger(e),$g=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Nn=(e,t)=>bo(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:$g(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Gg=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...$,...t}).format(r)),Ug=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{month:"short",...$,...t}).format(r)),Hg=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...$,...t}).format(r)),Wg=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...$,...t}).format(r)),Bn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ng(e);case"date":case"datetime":return Gg(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Hg(e);case"decimal":case"integer":return Bg(e);case"duration":return Cn(e);case"month":return Ug(e);case"month_year":return kn(e);case"percentage":return Fg(e);case"quarter":return On(e);case"text":return Rn(e);case"time":return Wg(e);case"year":return Pn(e);case"lookup":return Bn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Kg=.9,zg=1/3,Yg=1/4,qg=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?jg(e):Xg(e),jg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=So(e.ticks,n),o=Zg(e.ticks,r.width),c=o*Kg;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=Yr(c);return{...e,ticks:zr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Yr(r.height*zg);return{...e,ticks:zr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Xg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=So(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Yr(r.width*Yg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:zr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},Zg=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},So=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:s,height:o}=t(i.formattedLabel);r.push(s),s>n&&(n=s),o>a&&(a=o)}return{widths:r,maxWidth:n,maxHeight:a}},zr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:lo(i.formattedLabel,r,a)})},Yr=e=>Math.max(0,Math.floor(e)),Jg=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let s=r-(e.length-1)*i;for(const o of e){const{width:c,height:u}=n(o);if(s-=a?c:u,s<0)return!1}return!0},Qg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?ey(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;Jg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},ey=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),qa=.5,dt=e=>({x:0,y:0,width:e.width,height:e.height}),Fn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,mt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:ry(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:ny(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,T=Xa(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Xa(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:T,y:A,position:ty(e,T,A,c,u)}},ja=(e,t,r,n)=>r-n>=e-qa&&r+n<=t+qa,ty=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||ja(e.x,e.x+e.width,t,n/2),s=e.height===0||ja(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},ry=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",ny=e=>e==="center"?"center":e==="start"?"min":"max",Xa=({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 s=r+i;return e==="min"?t==="inside"?n+s:n-s:t==="inside"?a-s:a+s},ay=(e,t,r,n,a)=>{const i=t??e,s=1-Math.max(e,i);return{box:{x:r*n,y:s*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},iy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=oy(e.layer);for(const a of e.layer.data){const i=C(a),s=k(a)??V(a);if(i===null||s===null||!He(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),{box:d,frame:m}=ay(s,P(a),i,e.panelRect.width,e.panelRect.height),h=mt({box:d,panel:dt(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},sy={place:iy,getPercentageValueStrategy:e=>e.position==="fill"?"fill":F(e.position)?"stack":"none"},oy=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Fn(r):r,align:n}};function pt(e){return e[l.VISUAL_VARIABLES.color]}function xo(e){return e[l.VISUAL_VARIABLES.alpha]}function $n(e){return e[l.VISUAL_VARIABLES.size]}function qr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Ao(e){return e[l.VISUAL_VARIABLES.lineType]}var ly={color:pt,alpha:xo,strokeWidth:qr,lineType:Ao,size:$n,borderWidth:qr},Qe=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:o=>{const c=r.get(o);if(c!==void 0)return c;const u=dy(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=cy(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=nt(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=nt(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=nt(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=Io(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=nt(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},cy=(e,t)=>{const r=(c,u)=>{const d=p=>Za(c.overrides,p,u)??Za(c.defaults,p,u);return{get:p=>{const f=d(p)?.declarations[p];if(f!==void 0)return uy(f,t)},getSource:p=>{const f=d(p);return f===void 0?"unresolved":f.origin.list==="builtin"?"builtin":"authored"}}},n=c=>r(e.panelBorder,u=>{const d=u.select.target==="panelBorder"?u.select.edge:void 0;return d===void 0||d===c}),a=c=>u=>r(e[c],d=>d.select.target!==c?!1:d.select.axis===void 0||d.select.axis===u),i=c=>r(e.ruleLabel,u=>u.select.target!=="ruleLabel"?!1:u.select.layer===void 0||u.select.layer===c),s=(c,u)=>r(e.dataLabel,d=>d.select.target!=="dataLabel"||d.select.role!==void 0&&d.select.role!==c?!1:d.select.position===void 0||d.select.position===u),o=c=>r(e.tooltip,u=>u.select.target==="tooltip"&&u.select.part===c);return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:s,graph:r(e.graph,()=>!0),tooltip:{box:o(void 0),heading:o("heading"),label:o("label"),value:o("value"),primaryRow:o("primaryRow")}}},Za=(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}},uy=(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},dy=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=wt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=wt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=wt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=Io(n,a);return o!==void 0?o:wt(e.defaults,n,a,void 0,t)}}),wt=(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 s=e[i];if(s===void 0||s.state!==n)continue;const o=s.declarations[t];if(o!==void 0&&my(s,r))return{value:py(o,a),origin:s.origin}}},my=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),py=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Io=(e,t)=>{const r=ly[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Gn=(e,t,r)=>{const n={},a=i=>{const s=n[i];if(s!==void 0)return s;const{width:o,height:c}=e(t,i,r),u={width:o,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},Et=6,hy=.5,fy=e=>{const t=[],r=F(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=yy({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:n});for(const s of a){const o=e.layer.dataLabels.position==="auto"?Sy({mainAxis:e.coordSystem.mainAxis,isStacked:r,isNegativeBar:s.isNegative,shouldRotate:i,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Ay(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,dt(e.panelRect));if(o===null)continue;const c=s.boxes[o.position];t.push({layerId:e.layer.id,x:o.x,y:o.y,text:s.text,width:c.width,height:c.height,isRotated:o.isRotated,target:"observation",position:o.position,...o.position==="inside"?{backdropColor:s.backdropColor}:{}})}}if(e.layer.dataLabels.showCategoryLabels)for(const a of Iy(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=Ey({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const i of a)t.push(i)}return t},gy={place:fy,getPercentageValueStrategy:e=>e.position==="fill"?"fill":F(e.position)?"stack":"absoluteGrandTotal"},yy=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const s=[];let o=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y),d=Qe().geomReaders(e);for(const m of e.data){const h=Lo(t,m);if(h===null)continue;const p=a(m);if(p==="")continue;const f=Gn(n,"observation",p),g=Un(h,r);c&&f.inside.width>g.width&&(o=!0);const y=u===null?null:m[u],v=l.isStrictNumericDataValue(y)&&y<0;s.push({isNegative:v,text:p,boxes:f,bounds:g,backdropColor:d.get("color",m)})}return{entries:s,shouldRotate:!i&&o}},Un=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),To=(e,t,r,n,a)=>{if(e==="x"){let o=1-a,c=a-n;return c<0&&(o+=c,c=-c),{x:t,y:o,width:r-t,height:c}}let i=t,s=r-t;return s<0&&(i+=s,s=-s),{x:i,y:1-a,width:s,height:a-n}},Lo=(e,t)=>{const r=G(t),n=U(t),a=P(t),i=k(t)??V(t);return r===null||n===null||a===null||i===null?null:To(e,r,n,a,i)},vy=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return To(e,r,n,a,i)},by=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",jr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Sy=e=>e.isStacked?Ty({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):wy({edge:by(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),wo=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},xy=e=>e==="panel-start"||e==="panel-end",Ay=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,s=n.boxes[i],o=mt({box:n.bounds,panel:a,frame:wo(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:s.width,labelHeight:s.height});if(i==="inside"&&!xy(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?s.width:s.height)>u+hy?null:{x:o.x,y:o.y,isRotated:!1,position:"inside"}}return{x:o.x,y:o.y,isRotated:!1,position:o.position}},Iy=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:s}=e.layer.dataLabels,o=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=dt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=Lo(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=Gn(e.measureDataLabel,"category",p),g=f[o],y=Un(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,T=mt({box:y,panel:u,frame:wo(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[T.position];r.push({layerId:e.layer.id,x:T.x,y:T.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:T.position})}return r},Ty=({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"}},Ly=(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}}},wy=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=Ly(e,t,a,i),g=jr(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height,x=y+s<d,T=v<=m;if(o?x:x&&T){if(o&&!T)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const Y=h-p*(y/2+s);return{...o?{x:c,y:Y}:{x:Y,y:u},isRotated:!1,position:"inside"}}const A=jr(r.outside.width,r.outside.height,n),w=(o?A.height:A.width)/2,E=h+p*(w+s);return E-w<0||E+w>f?null:{...o?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Ey=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return i;const o=t==="y";for(const c of s){const u=Un(vy(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+Et+m/2:u.x-Et-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-Et-h/2:u.y+u.height+Et+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},Vy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Cy(e.layer);for(const a of e.layer.data){const i=C(a),s=V(a);if(i===null||s===null||!He(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=mt({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:dt(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:o,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return t},Ry={place:Vy,getPercentageValueStrategy:()=>"none"},Cy=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Fn(r):r,align:n}},Dy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=ky(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=Qe().geomReaders(e.layer);for(const s of e.layer.data){const o=C(s),c=V(s);if(o===null||c===null||!He(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=mt({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:dt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},_y={place:Dy,getPercentageValueStrategy:()=>"none"},ky=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}},Eo=e=>{const t=G(e),r=U(e),n=P(e),a=k(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),s=Math.abs(r-t),o=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-o,width:s,height:c}},Vo=e=>{const t=Eo(e);if(!t)return null;const r=t.width*Zp,n=t.height*Jp;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},Ja=4,Oy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const r=Qe().geomReaders(e.layer);for(const n of e.layer.data){const a=Vo(n);if(a===null||!pt(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:s,height:o}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;s+Ja>c||o+Ja>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:s,height:o,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return t},Py={place:Oy,getPercentageValueStrategy:()=>"none"};function Hn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Wn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var My=" · ",Ar=2,it=(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)},Ny=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=it("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Ar&&t+i<=e.outerRadiusPx+Ar)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=it("tangential",r,n,a)/t,c=Ar/t;return Math.abs(r-e.midAngle)+o<=s+c},By=({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,Fy=({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+it("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},$y=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:s})=>{const o=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+it("radial",o,i,s);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 m=e.innerRadiusPx-c;u=m>=0?m:e.innerRadiusPx+c}let d=o;if(n!=="center"&&u>0){const m=it("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:Ny({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},Gy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=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,m=Qe().geomReaders(e.layer);for(const h of e.layer.data){const{startAngle:p,endAngle:f}=Hn(h),{innerRadius:g,outerRadius:y}=Wn(h);if(p===null||f===null||y===null)continue;const v=e.formatLabel(h);if(v==="")continue;const x=s?e.formatCategory(h):null,T=x===null?v:`${x}${My}${v}`,A={startAngle:p,endAngle:f,midAngle:(p+f)/2,innerRadiusPx:(g??0)*d,outerRadiusPx:y*d};let w,E;if(r==="auto"){const I=e.measureDataLabel("observation",o,T);E={width:I.width,height:I.height},w=Fy({wedge:A,position:o,offset:i,labelWidth:E.width,labelHeight:E.height})}else{const I=Gn(e.measureDataLabel,"observation",T),W=I[r];w=$y({wedge:A,placement:r,justify:Fn(n),align:a,offset:i,labelWidth:W.width,labelHeight:W.height}),E=I[w.position]}const Y=c+Math.sin(w.labelAngle)*w.labelRadius,ie=u-Math.cos(w.labelAngle)*w.labelRadius;r==="auto"&&!By({x:Y,y:ie,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:Y,y:ie,text:T,width:E.width,height:E.height,isRotated:!1,target:"observation",position:w.position,...w.position==="inside"?{backdropColor:m.get("color",h)}:{}})}return t},Uy={place:Gy,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Hy=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 s=l.getStableKey(i[n]),o=r[s];return o!==void 0?o(a,i):t(a)}},D=e=>{switch(e.valueFormat.type){case"currency":return co(e);case"date":return kg(e);case"datetime":return Og(e);case"day_month":return ho(e);case"decimal":return uo(e);case"duration":return Cn(e);case"integer":return mo(e);case"month":return fo(e);case"month_year":return kn(e);case"percentage":return po(e);case"quarter":return On(e);case"text":return Rn(e);case"weekly_date_range":return go(e);case"weekly_date_range_with_year":return yo(e);case"year":return Pn(e);case"time":return vo(e);case"lookup":return Hy({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Kn({layer:e,numberFormat:t,locale:r}){return D({valueFormat:bd(e),locale:r,numberFormat:t})}var Wy=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Xe(e,t),variable:r}:{read:j,variable:l.GROUP_VARIABLES.group}},Ro=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Kn({layer:e,numberFormat:n,locale:s}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:jy({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o,isFlipped:u}),formatAbsolute:c,formatCategory:Ky({layer:e,numberFormat:n,locale:s})}},Ky=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Wy(e.data,e.mapping),i=D({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return s=>{const o=n(s);return o===null?null:i(o,s)}},zy=(e,t,r)=>{switch(t){case"stack":return Yy(e);case"fill":return qy(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Yy=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 s=a[t];if(s==null)return null;const o=r?.get(xn(a,t));return o===void 0?null:o.total}},qy=(e,t)=>{const r=t?G:P,n=t?U:k,a=ot(e);return i=>{const s=r(i),o=n(i);if(!l.isStrictNumericDataValue(s)||!l.isStrictNumericDataValue(o))return null;const c=Math.abs(o-s);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},jy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:s})=>{const o=K(e.data,e.dataLabels.labelSource),c=zy(e,i,s),u=Xy({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=D({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),m=e.dataLabels.format==="percentage"&&Co(e);return h=>{const p=o(h);if(p===null)return"";if(!m||!l.isStrictNumericDataValue(p))return u(p,h);const f=c(h);return f===null||f===0?u(p,h):d(p/f)}},Xy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(Co(e))return a;const o=Zy(e,r,t,n,s);if(o!==null)return o}return D({valueFormat:Jy(e.data,i),locale:n,numberFormat:t})},Co=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(jt(e.position,e.mapping))},Zy=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const s=t.find(o=>o.scaleAestheticKey==="x");return s===void 0?null:D({valueFormat:s.valueFormat,locale:n,numberFormat:r})},Jy=(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)},zn={bar:{cartesian:gy,polar:Uy},line:{cartesian:Ry},point:{cartesian:_y},area:{cartesian:sy},tile:{cartesian:Py}},Qy=(e,t)=>zn[e]?.[t]!==void 0,ev=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=zn[f]?.[h];if(g===void 0)continue;const y=Ro({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)tv(x,h,c,u)||d.push(x)}return{labels:d}},tv=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*rv({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=zn[o.geom]?.cartesian;if(c===void 0)continue;const u=Ro({layer:o,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:c.getPercentageValueStrategy(o)});for(const d of c.place(u))yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var Ir={abbreviation:"none",decimals:"auto"},Do=({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:Ir,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const s=i/r;return s===Number.POSITIVE_INFINITY?"∞":s===Number.NEGATIVE_INFINITY?"-∞":D({valueFormat:{type:"percentage"},locale:e,numberFormat:Ir,intlOptions:{signDisplay:"always"}})(s)}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:Ir,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},Tr=6,Lr=6,wr=15,Er=5,Vr=15,_o=(e,t)=>{switch(e){case"small":return{arrowStartGap:Tr,arrowEndGap:Lr,offsetFromHigherObservation:wr,arrowheadSize:Er,curveRadius:Vr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Tr*1.5,arrowEndGap:Lr*1.5,offsetFromHigherObservation:wr*1.25,arrowheadSize:Er*1.5,curveRadius:Vr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Tr*2,arrowEndGap:Lr*2,offsetFromHigherObservation:wr*1.75,arrowheadSize:Er*2.5,curveRadius:Vr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},nv=(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},av=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x,y:e.y-n},o={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 ${s.x} ${s.y}
3
3
  L ${o.x} ${o.y+i}
4
4
  Q ${o.x} ${o.y} ${o.x+d*i} ${o.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
- `},nv=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x+n,y:e.y},o={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
+ `},iv=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x+n,y:e.y},o={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 ${s.x} ${s.y}
10
10
  L ${o.x-i} ${o.y}
11
11
  Q ${o.x} ${o.y} ${o.x} ${o.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
- `},av=(e,t,{arrowEndGap:r,arrowheadSize:n})=>e?`
15
+ `},sv=(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 Xu=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
- `,iv=(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},sv=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),Oo=({arrow:e,mainAxis:t,panelWidth:r,panelHeight:n,textScale:a,locale:i})=>{const s=t==="y",o={x:e.start.x*r,y:(1-e.start.y)*n},c={x:e.end.x*r,y:(1-e.end.y)*n},u=_o(e.size,a),d=tv(s,o,c,u),m=(s?nv:rv)(o,c,d,u),h=av(s,c,u),p=iv(s,o,c,d,sv(s,o,c),e.labelCrossPosition),f=Do({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:o,end:c,linePath:m,arrowheadPath:h,labelPosition:p,labelText:f,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*ov({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!We(s.start.x,s.start.y)||!We(s.end.x,s.end.y))continue;const o=Oo({arrow:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,textScale:n,locale:a}),c=i(o.labelText,s.size).width+2*o.labelPaddingX,u=o.labelLineHeight+2*o.labelPaddingY;yield{x:r.x+o.labelPosition.x-c/2,y:r.y+o.labelPosition.y-u/2,width:c,height:u}}}var lv=e=>{const t=e.padding,r=Qa(e.rows,t?.top??0,t?.bottom??0),n=Qa(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:mv(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},cv=e=>{const t=ei(e.rows,e.height),r=ei(e.cols,e.width),n=ti(t),a=ti(r),i=new Map;for(const s of e.placements){const o=s.rowSpan??1,c=s.colSpan??1,u=a[s.col]??0,d=n[s.row]??0,m=ri(r,s.col,c),h=ri(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,h)})}return i},Qa=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let s=0;s<e.length;s++){const o=e[s];if(!o)continue;Xr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(uv(o));const c=dv(e,s);if(Xr(o)&&c){const u=o.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}},uv=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Xr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,dv=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Xr(n))return n}},mv=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),s=r.get(a.col);if(i===void 0||s===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):s;o===void 0||c===void 0||n.push({name:a.name,row:i,col:s,rowSpan:Math.max(1,o-i+1),colSpan:Math.max(1,c-s+1)})}return n},ei=(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)},ti=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},ri=(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},Ye={top:0,right:0,bottom:0,left:0},ko={outer:Ye,inner:Ye},pv={top:24,right:24,bottom:24,left:24},hv=(e,t,r,n=Ye,a=ko,i=pv,s={})=>{const o={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=ni(Rg,s),d=ni(Cg,s);return lv({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:o.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:o.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:o.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:o.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"},...gv(r.axes),...yv(r.axesLabels,r.axes),...vv(r.legends)],containerSize:e,padding:i})},fv=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Rr(t,e.after)}:{before:Rr(t.before,e.before),after:Rr(t.after,e.after)}:e,Rr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,ni=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=fv(e[n],t[n]);return r},gv=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},yv=(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},vv=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 bv=class{constructor(e){this.outer={...Ye},this.inner={...Ye},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)))}},Sv=["top","right","bottom","left"],Cr=(e,t)=>{const r={};for(const n of Sv){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function ai(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Zr=["large","medium","small"],xv=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Zr)if(r(n)<=t)return n;return"small"},Av=({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},Iv=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const s=a===0?i:n+t+i;if(s>r)break;n=s,a+=1}return a},Tv=({headline:e,containerSize:t,measurer:r})=>{if(Po(e))return 0;const n=Mo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},Lv=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(Po(e)){const o=wv(t.panel,e.innerRadius),c=Av({size:e.size,availableWidth:o.width,measureStripWidth:No(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=Mo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=Iv({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},Po=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,wv=(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}},Mo=(e,t,r)=>xv({size:e.size,availableWidth:t,measureStripWidth:No(e,r)}),No=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Pe={x:0,y:0,width:0,height:0},Ev="0000",Vv=3,et=e=>typeof e=="number"&&Number.isFinite(e)?e:24,Rv=e=>e.plot.y+e.plot.height-e.panel.y,Cv=e=>{if(typeof e=="object"&&e!==null)return{top:et(e.top),right:et(e.right),bottom:et(e.bottom),left:et(e.left)};const t=et(e);return{top:t,right:t,bottom:t,left:t}},Dv=class{constructor(e){this.measurer=e}compile(e){return jt({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:ko,panelBorder:e.panelBorder??Ye,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:Cv(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:_v(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>ii(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:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>ii(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:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:Rv(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new bv(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of ov({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,textScale:e.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(s,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const s of ev({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(s,e.overflowStrategy.dataLabels);const i=a.resolve();return ai(i.inner,n.inner)&&ai(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m}){let h=t,p=s;for(let f=0;f<Vv;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,p);if(g===p)break;p=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}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,s=a.height-n.vertical*2;return i<=0||s<=0?si(r,a,0,0):si(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=P(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const s=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,s.width),a=Math.max(a,s.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:Ev}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=P(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=Qg({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:o,...c}=e,u={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?qg({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:s,padding:o,gaps:c}){const u=cv(hv(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Pe,headline:u.get("headline")??Pe,footer:u.get("footer")??Pe,plot:u.get("plot")??Pe,panelFrame:u.get("panelFrame")??Pe,panel:u.get("panel")??Pe,axes:Cr(u,"Axis"),axisLabels:Cr(u,"AxisLabel"),legends:Cr(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 o of e)o.isVisible&&o.geometry==="linear"&&(a[o.position]=this.measurer.measureAxis(o),o.label!==null&&(i[o.position]=this.measurer.measureAxisLabel(o)));const s={top:0,right:0,bottom:0,left:0};for(const o of t)s[o.position]=this.measurer.measureLegend(o);return{axes:a,axesLabels:i,legends:s,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:Tv({headline:e,containerSize:t,measurer:this.measurer})}},ii=e=>e==="left"||e==="right",si=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,s=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-s)/2,y:t.y+n+(i-s)/2,width:s,height:s}}},_v=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(s=>s.value)),a=new WeakMap;return i=>{const s=a.get(i);if(s)return s;const o=Bn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},Ov=(e=[])=>{const t=kv(e);return{resolve:(r,n,a)=>t.has(r)?t.get(r).resolveAnchorPosition?.(n,a)??null:null,hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?qi(r,t.get(r.geom)):null}},kv=e=>{const t=new tr;for(const r of e){const n=Tn(r);n instanceof ae&&t.register(n.type,n)}return t};function Pv(e){return e}function ne(e){return 1-e}var ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Bo=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:ne(e.y)*t.height};const n=Math.min(t.width,t.height),a=(t.width-n)/2,i=(t.height-n)/2;return{x:a+e.x*n,y:i+e.y*n}},Mv=class{constructor(e,t,r,n){this.annotations=e,this.panelRect=t,this.coordSystem=r,this.measuredBoxes=n,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;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return Et(e);const{x:s,y:o}=Jr(e.defer,this.panelRect);return Et({...e,x:e.x+s,y:e.y-o})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=it(r,e.defer.align),{x:a,y:i}=Nv(n,e.defer.offset,this.panelRect);return{x:a,y:i}}resolveRegion(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return Et(e);const{x:i,y:s}=Jr(e.defer,this.panelRect);return Et({...e,x:e.x-i,y:e.y-s,width:Math.max(0,e.width+2*i),height:Math.max(0,e.height+2*s)})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=r.xMax-r.xMin,a=r.yMax-r.yMin;return n<=0||a<=0?null:{x:r.xMin,y:r.yMin,width:n,height:a}}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:Bv(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:oi(r,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=t.annotation.width,i=n.height/this.panelRect.height,s=Mi(t.annotation.align),o=r.x-s.x*a,c=r.y+(1-s.y)*i;return{xMin:o,xMax:o+a,yMin:c-i,yMax:c}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:li(r)}case"differenceArrow":return oi(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return li(t.annotation.at)}}},Jr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Nv=(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:s}=Jr({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-s}}return{x:e.x+n,y:e.y-a}},Bv=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),oi=(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}),Et=e=>{const t={...e};return delete t.defer,t},Fv=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!$v(t))return t;const o=new Mv(t,r,n,a),c={...t,shapes:tt(t.shapes,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),images:tt(t.images,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),arrows:tt(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const h=o.resolvePoint(m.start),p=o.resolvePoint(m.end);return h===null||p===null?null:{...m,start:h,end:p}}),textAnnotations:tt(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}}),stickers:tt(t.stickers,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},tt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,$v=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),Gv=800,ci=400,Uv={thin:{strokeWidth:{minValue:1.5,targetValue:2},arrowheadLength:{minValue:7,targetValue:8}},medium:{strokeWidth:{minValue:3,targetValue:4},arrowheadLength:{minValue:14,targetValue:16}},thick:{strokeWidth:{minValue:6,targetValue:8},arrowheadLength:{minValue:28,targetValue:32}}},Wv=e=>Math.max(1,(e-ci)/(Gv-ci)+1),Hv=(e,t)=>{const r=Wv(t),n=Uv[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},Vt=Math.PI/4,Qr=1.5,Kv=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,ui=(e,t,r)=>{if(r<=0)return"";const{startX:n,startY:a,endX:i,endY:s}=t,o=e==="start"?n:i,c=e==="start"?a:s,u=e==="start"?Math.atan2(a-s,n-i):Math.atan2(s-a,i-n);return`M ${o} ${c} L ${o-r*Math.cos(u-Vt)} ${c-r*Math.sin(u-Vt)} M ${o} ${c} L ${o-r*Math.cos(u+Vt)} ${c-r*Math.sin(u+Vt)}`},zv=(e,t)=>e==="solid"?null:`${t*Qr} ${t*Qr*2}`,Yv=(e,t)=>t?e*Qr:0,qv=64,jv=({arrow:e,panelWidth:t,panelHeight:r})=>{const n={startX:e.start.x*t,startY:(1-e.start.y)*r,endX:e.end.x*t,endY:(1-e.end.y)*r};if(n.startX===n.endX&&n.startY===n.endY)return null;const{strokeWidth:a,arrowheadLength:i}=Hv(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=Xv(i,s),c=e.startArrowheadStyle==="line-arrow",u=e.endArrowheadStyle==="line-arrow",d=c||u?o*Math.sin(Math.PI/4):0;return{id:e.id,linePath:Kv(n),startArrowheadPath:c?ui("start",n,o):"",endArrowheadPath:u?ui("end",n,o):"",color:e.color,strokeWidth:a,dashArray:zv(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:Yv(a,c),arrowheadExtent:d}},Xv=(e,t)=>Math.min(e,t*e/qv);function Zv(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(m=>m.transformType==="filter"&&m.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let s,o,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")s="color",o=a.options.variableName,c=a.options.value;else if(i!==null)s="y",o=i,c=i;else continue;const u=Jv(e,s,o);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d})}return r}function Jv(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 Fo=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),Qv=0,eb=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:Fo(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:Qv})),tb=9,rb=8,nb=2,$o=e=>typeof e=="string"?e:Go(e),Go=e=>e.text!==void 0?e.text:e.content?e.content.map(Go).join(""):"",di={top:"bottom",bottom:"top",right:"left",left:"right"};function ab(e,t,r){return r.type==="polar"?ob(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function en(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 mi(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function ib(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 sb(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 ob(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",[s,o]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[s,di[s],o,di[o]]}function lb(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:h}=d;return pi(m,"pinned-number",h,s(d),i,n,a)}),...r.map(({id:d,at:m,content:h})=>pi(d,"comment",m,$o(h),i,n,a))];o.sort((d,m)=>d.anchorPx.x-m.anchorPx.x||d.anchorPx.y-m.anchorPx.y);const c=[],u=[];for(const d of o){if(!d.inView){c.push(hi(n,d,"top"));continue}const m=hi(n,d,ub(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function pi(e,t,r,n,a,i,s){const o=Bo(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:cb(o,i)}}function cb(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function ub(e,t,r,n){const a=ab(t.anchorPx,e,r);for(const i of a){const s=en(t.anchorPx,i,t.mini);if(mi(s,e)&&!n.some(o=>sb(s,o)))return i}for(const i of a)if(mi(en(t.anchorPx,i,t.mini),e))return i;return"top"}function hi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:ib(e,en(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var db=({labelPosition:e,measuredTextWidth:t,labelLineHeight:r,labelPaddingX:n,labelPaddingY:a})=>{const i=t+2*n,s=r+2*a;return{x:e.x-i/2,y:e.y-s/2,width:i,height:s}},mb=(e,t,r,n)=>e!==null?e:t.anchor.layerId!==r.anchor.layerId||!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||n.start===void 0||n.start!==n.end?null:n.start,pb=100,hb=({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,s=!0,o=0;for(;s;){s=!1,o++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const m=u.y+a,h=d.y-a;if(m>h){s=!0,i=!0;const p=(m-h)/2+1;u.y-=p,d.y+=p,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>pb)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}},fb=(e,t)=>{const r=Xi(e),n=yb(t,gb(e),r);if(n===null)return null;const[a]=n;return a===void 0?null:n.length===1?a:{and:n}},gb=e=>{const t=dn(e)?Je(e.data,e.mapping):[],r=un(e),n=r===null?t:[...t,r],a=we(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},yb=(e,t,r)=>{const n=[];for(const a of t){const i=r(e,a);if(i===null)return null;n.push({variable:a,eq:i})}return n},Yn=(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},vb=(e,t)=>{for(const r of t)if(Yn(e,r.shape))return r;return null},bb=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},Sb=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>xb(r,t[n])),xb=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&Ab(e.shape,t.shape)&&Ib(e.tooltip,t.tooltip),Ab=(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},Ib=(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},Tb=100,Lb=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:Tb}),wb=(e,t)=>Yn(e,{kind:"circle",center:t.center,radius:t.radius}),Eb=(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&&Vb(e.target,t.target),Vb=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,Rb=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Zt(e,n),i=Cb(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||Se(s.predicate,e.data).length>0)return!1;const o=be(s.predicate,a);return o(r)?!0:Pp(s.scope)&&i(s.scope).some(o)})},Cb=(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 s=Ut(a,t,r),o=[];for(const c of e.data)Ut(a,c,r)===s&&o.push(c);return n.set(a,o),o}},kt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const s=e.data.size(),o=ot(e);for(let c=0;c<s;c+=1){const u=t+c*r,d=i?Db(u,s):u;if(d<0||d>=s)break;const m=e.data.getAt(d);if(m===null||!n(m,d))continue;const h=o(m);if(h!==null&&!a.some(p=>Fe(h,p)))return{anchor:h,observation:m,observationIndex:d}}return null},Uo=(e,t)=>{const r=ji(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Fe=(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),Db=(e,t)=>(e%t+t)%t,Wo=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=we(e),a=Uo(e,t),i=e.data.getAt(a);if(i===null)return null;const s=Y(i),o=h=>l.areDataValuesEqual(Y(h),s),c=[t],u=kt({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=kt({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=kt({layer:e,excluding:c,from:0,step:1,accepts:h=>!o(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},_b=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=ot(r);for(const a of r.data){const i=n(a);if(i===null)continue;const s=Wo({layer:r,at:i,coordSystem:e.coordSystem});if(s!==null&&!t.some(o=>Ob(o,s)))return s}}return null},Ob=(e,t)=>Fe(e.start,t.start)&&Fe(e.end,t.end)||Fe(e.start,t.end)&&Fe(e.end,t.start),kb=(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}},Pb=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:s})=>{const o=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(o===null)return null;const c=s??e.createLayerMeasurement(t);if(c===null)return null;const u=es(t,r,c);if(u===null)return null;const d=ot(t)(r);return d===null?null:{...o,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Mb=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const s=we(e),o=Uo(e,t),c=e.data.getAt(o);if(c===null)return null;const u=Nb(c),d=n==="main"?u:p=>!u(p)&&l.areDataValuesEqual(p[s]??null,t.anchorValue),m=kt({layer:e,excluding:[t,r],from:o+a,step:a,accepts:(p,f)=>d(p)&&i(p,f)!==null,cycles:n!=="main"});if(m===null)return null;const h=i(m.observation,m.observationIndex);return h===null?null:{...m,point:h}},Nb=e=>{const t=Y(e);return r=>l.areDataValuesEqual(Y(r),t)};function Bb({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=C({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Fb=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const s=a??n;return e.kind==="grandTotal"?$b(e,s,r):Gb(e,t,s,r,i)},$b=(e,t,r)=>({kind:"grandTotal",value:C({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Gb=(e,t,r,n,a)=>{const i=C({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),s=e.items.length>1;return{kind:"perGroup",items:e.items.map(o=>{const c=C({valueFormat:o.valueFormat,locale:r,numberFormat:n}),u=C({valueFormat:o.groupLabelFormat,locale:r,numberFormat:n}),d=Bn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Kb(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:Hb(o.observationLabel,d),comparison:Ub(o.comparison,d,i,a)}})}},Ub=(e,t,r,n)=>e===null?null:{direction:Wb(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},Wb=e=>e>0?"up":e<0?"down":"flat",Hb=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Kb=(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}},zb=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Yb(i,a,t))},Yb=(e,t,r)=>({...e,items:e.items.map(n=>{const a=C({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function qn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function qb(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var jb=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,s=(i?cn:Xe)(r.data,r.mapping)(a);return s===null?null:C({valueFormat:qn(e,i?oe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},Xb=12,Zb=4,Jb=4,Qb=12,eS=4,tS=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:Dr([Rt("value","value",t??"–"),Rt("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:iS(n),segments:Dr([nS(n),aS(n),Rt("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:Dr([rS(a),Rt("label","label",i)])}].filter(s=>s.segments.length>0)},Rt=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},rS=e=>e===null?null:{kind:"swatch",swatch:e,size:12},nS=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},aS=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},iS=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}`}},Dr=e=>e.filter(t=>t!==null),ir=e=>e==="catmull-rom"?Ie.curveCatmullRom:Ie.curveLinear,sS=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},oS=(e,t)=>{const r=ir(t.interpolate),n=(0,Ie.area)().curve(r),a=(0,Ie.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ne(w(c)??0),s=c=>G(c)??0,o=c=>U(c)??R(c)??0;n.y(i).x0(s).x1(o),a.y(i).x(o)}else{const i=c=>R(c)??0,s=c=>ne(k(c)??0),o=c=>ne(_(c)??w(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>R(s)!==null&&w(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},lS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),jn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},Ho=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return jn[e.borderRadius??"sm"]},cS=e=>{const t=Ho(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},uS=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Ko=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(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 s=r,o=n-r;return o<0&&(s+=o,o=-o),{x:s,y:1-i,width:o,height:i-a}},zo=(e,t)=>e==="x"?`${z(t.x)}-${z(t.width)}`:`${z(t.y)}-${z(t.height)}`,dS=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}},mS=e=>{const t=(0,Ie.line)().x(r=>R(r)??0).y(r=>ne(w(r)??0)).curve(ir(e.interpolate));return e.missingValues==="gap"&&t.defined(Yo),t},pS=e=>{const t=(0,Ie.area)().x(r=>R(r)??0).y0(()=>1).y1(r=>ne(w(r)??0)).curve(ir(e.interpolate));return e.missingValues==="gap"&&t.defined(Yo),t},hS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),Yo=e=>R(e)!==null&&w(e)!==null,qo=(0,Ie.arc)().cornerRadius(e=>e.cornerRadius??0);qo.digits(8);var fS=200,gS=e=>qo(e)??void 0,yS=(e,t)=>e==="full"?Math.max(0,t)/2:jn[e??"sm"]/fS,jo=(e,t)=>e==="x"?`${z(t.startAngle)}-${z(t.endAngle)}`:e==="y"?`${z(t.innerRadius)}-${z(t.outerRadius)}`:"sweep",vS=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}},bS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],sr=(e,t,r)=>{const n=Xe(e,t);return a=>{const i=Y(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},SS=(e,t,r)=>{const n=Xe(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},xS=(e,t,r)=>{const n=Xe(e,t),a=cn(e,t),i=new Map;return s=>{const o=n(s),c=a(s),u=o!==null&&o!==""&&c!==null&&c!==""?`${r}-${o}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},AS=()=>(e,t)=>mt(e)??`default-${t}`;function Xn(e,t,r){return Math.hypot(e*r,t)}function Ht(e,t,r){return e<t?t-e:e>r?e-r:0}function ue(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 s=e[i];if(s===void 0)continue;const o=t(s);if(r&&o===0)return s;o<a&&(n=s,a=o)}return n}function IS(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),s=e.points[i];return s?{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,observationIndex:s.observationIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:Xn(s.x-t.x,s.y-t.y,r)}:null}function TS(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 Xo(e,t){return Zn(e.buckets,t,r=>r.main)}function LS(e,t){return Zn(e.bands,t,r=>r.bandCenter)}function Zo(e,t){return Zn(e.columns,t,r=>r.mainMid)}function Zn(e,t,r){if(e.length===0)return null;let n=0,a=e.length;for(;n<a;){const o=n+a>>>1,c=e[o];c&&r(c)<t?n=o+1:a=o}const i=e[n-1],s=e[n];return i?s&&Math.abs(r(s)-t)<Math.abs(r(i)-t)?s:i:s??null}function wS(e,t){return{group:ES(e),related:DS(e,t)}}function ES(e){switch(e.kind){case"buckets":{const t=e.match.index;return B(t.position)?VS(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return B(t.position)?RS(t.layerId,r,n.pointIndex):CS(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function VS(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 RS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(Jn(e,a));return n}function CS(e,t,r,n){const a=e.find(s=>s.columns.includes(r));if(!a)return[];const i=[];for(const s of a.columns)for(const o of s.rects)o.pointIndex!==n&&i.push(Jn(t,o));return i}function DS(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||OS(r,i,e.match.hit);continue}e.kind==="buckets"&&(B(i.position)||i.kind==="buckets"&&_S(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function _S(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Pt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function OS(e,t,r){switch(t.kind){case"buckets":{const n=Xo(t,Ue(t.mainAxis,r));if(!n)return;const a=Pt(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=LS(t,Ue(t.mainAxis,r));if(!n)return;const a=Pt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(Jn(t.layerId,s));return}case"points":{const n=TS(t,r);if(!n)return;Pt(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 Pt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function Jn(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 Jo(e,t,r){const{columns:n,bands:a}=kS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function kS(e,t){const r=PS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=z(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=z(o.bandCenter);let m=a.get(d);m||(m={bandCenter:o.bandCenter,columns:[]},a.set(d,m)),m.columns.push(u)}u.rects.push(o.entry)}const i=[...n.values()].sort((o,c)=>o.mainMid-c.mainMid),s=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of s)o.columns.sort((c,u)=>c.mainMid-u.mainMid);return{columns:i,bands:s}}function PS(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"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let m=0;for(const h of r){const p=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(p+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(p,f),xMax:Math.max(p,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:h}}),m++}return d}var MS=1e-9;function Qo(e,t,r){const n=NS(e,t);n.sort((i,s)=>i.main-s.main);const a=[];for(const i of n){const s=a[a.length-1];s&&Math.abs(s.main-i.main)<=MS?s.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 NS(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"}),s=r.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,u=o?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,d=B(e.position),m=d?r.getValues(c,{type:"numeric"}):null,h=d?r.getValues(u,{type:"numeric"}):null,p=r.hasVariable(l.GROUP_VARIABLES.group)?r.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,f=[];let g=0;for(const y of r){const v=i[g],x=s[g];if(!l.isDefined(v)||!l.isDefined(x)){g+=1;continue}const I=p?.[g]??null,A=o?x:v;if(d){const V=m?.[g],j=h?.[g];if(!l.isDefined(V)||!l.isDefined(j)){g+=1;continue}const ie=o?j:v,K=o?x:j;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:ie,y:K,stackMin:V,stackMax:j,groupKey:I,observation:y}})}else f.push({main:A,entry:{isStacked:d,pointIndex:g,x:v,y:x,groupKey:I,observation:y}});g+=1}return f}function el(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:BS(e,t)}}function BS(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 m of n)if(!r.hasVariable(m))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const m of r){const h=a[d],p=i[d],f=s[d],g=o[d];if(!l.isDefined(h)||!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!mt(m)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:p,yMin:f,yMax:g,observation:m}),d++}return u}function tn(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function FS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:rl(e),delaunay:null,delaunayAspectRatio:null};return tl(r,t),r}function $S(e){const t=rl(e).map(r=>{const n=Gt(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 tl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=nd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function rl(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 s of t){const o=r[i],c=n[i];l.isDefined(o)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:o,y:c,observation:s}),i+=1}return a}function nl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:GS(e)}}function al(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function GS(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 fi(e,t,r){return t.type==="polar"?US(e,t.bandAxis):WS(e,t.mainAxis,r)}function US(e,t){switch(e.spatialKind){case"points":return $S(e);case"buckets":return Qo(e,"x","polar");case"rects":return t===null?el(e,"polar"):Jo(e,t,"polar");case"cells":return tn(e);case"noop":return tn(e);case"render-hit-test":return nl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function WS(e,t,r){switch(e.spatialKind){case"points":return FS(e,r);case"buckets":return Qo(e,t,"cartesian");case"rects":return Jo(e,t,"cartesian");case"cells":return el(e,"cartesian");case"noop":return tn(e);case"render-hit-test":return nl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function HS(e,t,r){if(e.columns.length===0)return null;const n=Zo(e,Ue(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=B(e.position)?KS(a,t,e.mainAxis):zS(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:il(i,t,r)}}function KS(e,t,r){const n=Xt(r,t);return ue(e,i=>YS(i,r,n),{shortCircuitOnZero:!0})}function zS(e,t,r){return ue(e,a=>il(a,t,r))}function il(e,t,r){return Xn(Ht(t.x,e.xMin,e.xMax),Ht(t.y,e.yMin,e.yMax),r)}function YS(e,t,r){return Ht(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function qS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=gd(e.mainAxis,t),i=Xo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=sl(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:Xn(o.x-t.x,o.y-t.y,r)}}function sl(e,t,r){return ue(e,a=>Math.abs(Xt(r,a)-t))}function jS(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 XS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Jt(t,r),i=e.mainAxis==="x",s=i?ZS(e.columns,n):Zo(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?JS(o,a):QS(o,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:s,distance:0}}function ZS(e,t){return l.isNonEmptyArray(e)?ue(e,r=>$t(t,r.mainMid)):null}function JS(e,t){return ue(e,r=>Ht(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function QS(e,t){return ue(e,r=>as(t,r.xMin,r.xMax)?0:Math.min($t(t,r.xMin),$t(t,r.xMax)),{shortCircuitOnZero:!0})}function ex(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Jt(t,r),i=tx(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=sl(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:0}}function tx(e,t){return l.isNonEmptyArray(e)?ue(e,r=>$t(r.main,t)):null}function rx(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)&&as(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 nx(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=hn(t,r),i=ue(e.points,s=>gi(s,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(gi(i,n,a))}}function gi(e,t,r){const n=e.unitX??Gt(e.x,e.y).x,a=e.unitY??Gt(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var ax=.05;function ix({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a}){const i={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const o of e){if(o.kind==="render-hit-test"){const u=cx(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=lx(o,t,r);if(u)return u;continue}const c=ox({layer:o,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<s.distance&&(s.match=c,s.distance=c.match.distance)}}return sx({containment:i,continuous:s})}function sx({containment:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+ax?t.match:e.match:e.match??t.match}function ox({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=qS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=HS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=IS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"enclosure":{const a=jS(e,t);return a?{kind:"enclosure",match:a}:null}case"noop":return null}}function lx(e,t,r){switch(e.kind){case"enclosure":{const n=rx(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=nx(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=ex(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=XS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function cx(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:al(e.layerId,i)}:null}var J={primary:null,group:[],related:new Map},ux=1,dx=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=ux,this.warmStarts=new Map,this.cachedState=J,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=J,this.layerIndexes=e.map(r=>fi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>yi(r,t)),this.nonInteractiveLayerIds=vi(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const s=this.layerIndexes[i],o=this.layerRefs[i];!s||!o||r.set(s.layerId,{index:s,ref:o})}const n=[],a=[];for(const i of e){const s=r.get(i.id),o=yi(i,t);if(s!==void 0&&mx(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(fi(i,t,this.aspectRatio)),a.push(o)}for(const i of this.warmStarts.keys())e.some(s=>s.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=vi(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&tl(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return J;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=ix({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),J;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:s}=wS(r,t);return this.cachedKey=a,this.cachedState={primary:n,group:i,related:s},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 J;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return J;const n=r.byKey.get(t);if(!n)return J;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:al(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=J,this.cachedByKeyId=null,this.cachedByKeyState=J}};function yi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function vi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function mx(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var px=Math.PI*2;function hx(e,t){const r=Ue(e.mainAxis,t);if(e.mainAxis==="y"){const a=ve(ne(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function fx(e,t,r){const n=e.mainAxis==="y"?w(r.observation):R(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?ll(r):ol(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const s=i/2;return e.mainAxis==="y"?{x:0,y:ve(ne(n+s)),width:"100%",height:ve(i)}:{x:ve(n-s),y:0,width:ve(i),height:"100%"}}function gx(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=G(t.observation),i=U(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=k(t.observation),n=_(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+px,innerRadius:r,outerRadius:n}}function ol(e){const t=G(e.observation),r=U(e.observation);return t===null||r===null?null:r-t}function ll(e){const t=k(e.observation),r=_(e.observation);return t===null||r===null?null:r-t}function yx(e){return e.observationIndex??e.pointIndex}var or=.5,vx=.3,bx=.4,Sx=10,xx=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?Ix(e,t,r,n):Tx(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?Ex(e,t,n):e.spatialKind==="cells"?wx(e,n):e.spatialKind==="points"?Lx(e,n):null,Ax=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},Ix=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:or*n.durationScale,baseline:Vx(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?Rx(e,t.mainAxis,n):{}}),Tx=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:or*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?_x(e,t,r):{}}},Lx=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:or*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?Cx(e,t):{}}),wx=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:vx*t.durationScale}),Ex=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:or*r.durationScale,axis:t.mainAxis}),Vx=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[oe(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const s=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-s:s},Rx=(e,t,r)=>{const n=sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=Ko(t,i);if(!s)continue;const o=zo(t,s),c=n(i),u=a.get(o);u?u.keys.push(c):a.set(o,{position:t==="x"?s.x:s.y,keys:[c]})}return Qn([...a.values()],r)},Cx=(e,t)=>{const r=sr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=Dx(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return Qn(n,t)},Dx=(e,t)=>{if(t==="main-axis")return R(e);const r=Un(e)??R(e);return r===null?null:t==="value-descending"?-r:r},_x=(e,t,r)=>{const n=sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Wn(i),{innerRadius:c,outerRadius:u}=Hn(i);if(s===null||o===null||c===null||u===null)continue;const d=jo(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),h=a.get(d);h?h.keys.push(m):a.set(d,{position:s,keys:[m]})}return Qn([...a.values()],r)},Qn=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((o,c)=>o.position-c.position),a=Math.ceil(n.length/Sx),i=Math.ceil(n.length/a),s=bx*t.durationScale/i;return n.forEach((o,c)=>{const u=Math.floor(c/a)*s;for(const d of o.keys)r[d]=u}),r},Me=["top","right","bottom","left"],bi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},Ox={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},kx={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},Px=(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]=kx[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=Nx(t,a),o=Bx(t,a,i);return Fx(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:$x(c,s,o,i)}))},Mx=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),Nx=(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}}},Bx=(e,t,r)=>{const{x:n,y:a,width:i,height:s}=e,o=c=>r(c)?t:0;return{top:{start:{x:n+o("topLeft"),y:a},end:{x:n+i-o("topRight"),y:a}},right:{start:{x:n+i,y:a+o("topRight")},end:{x:n+i,y:a+s-o("bottomRight")}},bottom:{start:{x:n+i-o("bottomRight"),y:a+s},end:{x:n+o("bottomLeft"),y:a+s}},left:{start:{x:n,y:a+s-o("bottomLeft")},end:{x:n,y:a+o("topLeft")}}}},Fx=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Me.indexOf(s)+o+Me.length)%Me.length;return Me[c]},n=s=>{const o=r(s,-1);return!t(o)||e[o].lineType!==e[s].lineType||e[o].strokeWidth!==e[s].strokeWidth||e[o].color!==e[s].color},a=Me.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Me],isClosed:!0}]:i.map(s=>{const o=[s];for(let c=r(s,1);t(c)&&!n(c);c=r(c,1))o.push(c);return{firstEdge:s,edges:o,isClosed:!1}})},$x=(e,t,r,n)=>{const a=(m,h,p)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:h,endAngle:p}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=bi[o];if(!e.isClosed&&n(u)){const m=t[u],h=i(m),p=Gx(m,h);s.push({type:"move",x:p.x,y:p.y}),s.push(a(m,h,m.endAngle))}else s.push({type:"move",x:r[o].start.x,y:r[o].start.y});s.push({type:"line",x:r[o].end.x,y:r[o].end.y});for(const m of e.edges.slice(1)){const h=bi[m];if(n(h)){const p=t[h];s.push(a(p,p.startAngle,p.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=Ox[c];if(e.isClosed){if(n(d)){const m=t[d];s.push(a(m,m.startAngle,m.endAngle))}s.push({type:"close"})}else if(n(d)){const m=t[d];s.push(a(m,m.startAngle,i(m)))}return s},Gx=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Ux=/^(?:https?:|mailto:)/i,Wx=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Ux.test(t)},Hx=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...F,...t}).format(r)),Kx=({locale:e,intlOptions:t})=>N(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,...F,...t}).format(r)}),Kt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return co(e);case"date":return Hx(e);case"datetime":return Kx(e);case"day_month":return ho(e);case"decimal":return uo(e);case"duration":return Cn(e);case"integer":return mo(e);case"month":return fo(e);case"month_year":return On(e);case"percentage":return po(e);case"quarter":return kn(e);case"text":return Rn(e);case"time":return vo(e);case"weekly_date_range":return go(e);case"weekly_date_range_with_year":return yo(e);case"year":return Pn(e);case"lookup":return Kt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},zx=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:s,colorScheme:o,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:m}=s;if(m===null)return null;const h=c??i,p=Yx(u,d);return{header:p===null?qx({layers:e,coordSystem:t,guides:n,primary:m,locale:h,numberFormat:a}):null,rows:jx({layers:e,scales:r,guides:n,hover:s,locale:h,numberFormat:a,colorScheme:o}),comment:p}};function Yx(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function qx(e){if(e.coordSystem.type!=="cartesian")return null;const t=qn(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)?Kt({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function jx(e){const t=[],r=e.scales.color??null,n=ar({colorScheme:e.colorScheme}),a=Qx({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=Zx(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...Xx(i,o,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Fi(i.data,i.mapping),u=Jx(s,i,r,c),d=Kn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=eA(e.guides,i),h=st(i),p=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=p?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",I=p&&y!==null?a(y):m,A=h(g.observation),V=A===null?"":d(A,g.observation);t.push({swatchColor:v,geom:i.geom,swatchLineType:x,label:I,value:V,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function Xx(e,t,r,n,a){return e.tooltip.map(i=>{const s=e.mapping[i.aes],o=l.extractVariableName(s),c=W(e.data,s)(t.observation),u=C({valueFormat:mn(e,o),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:i.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",label:i.key??er(o,r.variableLabels)??"",value:c===null?"":u(c,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${i.aes}`}})}function Zx(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 Jx(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,s)=>{a.set(l.getStableKey(i),s)}),e.map((i,s)=>{const o=n(i.observation),c=o===null?null:l.getStableKey(o);return{hit:i,originalIndex:s,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,s)=>i.rank===s.rank?i.originalIndex-s.originalIndex:i.rank-s.rank).map(i=>i.hit)}function Qx({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:Kt({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=Kt({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const s=n.get(l.getStableKey(i));return s===void 0?a(i):s.label??s.format(i)}}function eA(e,t){return er(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function tA(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function rA(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var nA=e=>({edges:{top:$e(e.panelBorder("top")),right:$e(e.panelBorder("right")),bottom:$e(e.panelBorder("bottom")),left:$e(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),aA=(e,t)=>$e(e.gridLine(t)),iA=(e,t)=>{const r=e.tickLine(t);return{...$e(r),length:r.get("length")}},sA=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")}},oA=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},$e=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),lA=e=>e.fontSize*e.lineHeight,cA=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),se=(e,t,r)=>({fontFamily:e.get("fontFamily")??r,fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),uA=(e,t,r)=>se(e.axisLabel(t),r,e.graph.get("fontFamily")),dA=(e,t,r)=>{const n=e.tickLabel(t);return{...se(n,r,e.graph.get("fontFamily")),offset:n.get("offset")}},mA=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...se(a,n,e.graph.get("fontFamily")),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),isTextColorAuthored:a.getSource("textColor")==="authored",...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},pA=(e,t,r)=>{const n=se(e.ruleLabel(t),r,e.graph.get("fontFamily"));return{fontFamily:n.fontFamily,fontSize:n.fontSize,fontWeight:n.fontWeight,lineHeight:n.lineHeight}},hA=(e,t)=>{const r=e.tooltip.box,n=e.graph.get("fontFamily");return{box:{background:r.get("background"),borderColor:r.get("borderColor"),borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock"),shadow:r.get("shadow")},heading:se(e.tooltip.heading,t,n),label:se(e.tooltip.label,t,n),value:se(e.tooltip.value,t,n),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},lr={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},fA={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}}},gA=Object.keys(lr),yA=e=>Object.hasOwn(lr,e),pt=(e,t)=>{for(const r of gA){const n=vA(e,r,t);if(n)return n}return null},ht=(e,t)=>e[lr[t]],ea=(e,t,r)=>({...e,[lr[t]]:r}),cl=(e,t)=>{const r=ht(e,t.kind);return ea(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},vA=(e,t,r)=>{const n=ht(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},ta=["sticker","pinnedNumber","comment","image"],bA=e=>ta.includes(e),ra=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?xA(e.annotation.at):null;default:return null}},ul=(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),dl=(e,t,r=SA)=>{const n=r(t);for(const a of ta){const i=ht(e,a),s=i.findIndex(c=>{const u=ra({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return ul(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},SA=e=>({...e,anchorValue:_r(e.anchorValue),...e.groupValue!==void 0&&{groupValue:_r(e.groupValue)},...e.crossValue!==void 0&&{crossValue:_r(e.crossValue)}}),_r=e=>l.readISOInstant(e)??e,xA=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function AA(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var IA=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&na(r.predicate,t.predicate))??null,na=(e,t)=>"and"in e?"and"in t&&Si(e.and,t.and):"or"in e?"or"in t&&Si(e.or,t.or):"not"in e?"not"in t&&na(e.not,t.not):TA(t)&&e.variable===t.variable&&LA(e,t),TA=e=>"variable"in e,Si=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&na(r,a)}),LA=(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)),wA={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},EA=e=>Object.hasOwn(wA,e);function VA(e){return{type:"mapping",mapping:e}}var cr=(e,t)=>"and"in e?"and"in t&&Ai(e.and,t.and):"or"in e?"or"in t&&Ai(e.or,t.or):"not"in e?"not"in t&&cr(e.not,t.not):RA(t)&&e.variable===t.variable&&CA(e,t),RA=e=>"variable"in e,Ai=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&cr(r,a)}),CA=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ii(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&&Ii(e.range,t.range),Ii=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ml=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)))),pl=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),hl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function fl(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(DA),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function DA(e){return e.scaleType==="palette"?_A(e):e}function _A(e){return{...e,palette:OA(e.palette),overrides:kA(e.overrides)}}function OA(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function kA(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var ur=(e,t)=>{const r=aa(e,t);return r===-1?void 0:e[r]},aa=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&dr(n,t))return r}return-1},dr=(e,t)=>PA(e.select,t.select)&&e.when?.state===t.when?.state&&MA(e.when?.where,t.when?.where),gl=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>NA(e[r],t[r])),Ae=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),ia=e=>e.select.target==="geom",ft=(e,t)=>{const r=ur(e,t);if(!(r===void 0||!ia(r)))return r.declarations},PA=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},MA=(e,t)=>e===void 0||t===void 0?e===t:cr(e,t),NA=(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 S(e){return{id:e.id??M(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function qe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>qe(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=>qe(e[a],t[a]))}return!1}var sa=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=S({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=pt(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:L(e,{annotations:cl(e.annotations,t)}),revert:new oa({kind:r,annotation:a,index:n},this.metadata)}}},BA={type:"remove-annotation",deserialize:(e,t)=>new sa(e,t)},oa=class yl{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??M()},...t.index!==void 0&&{index:t.index}},this.metadata=S({...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(!yA(r)||pt(t.annotations,n.id))return null;const i=$A(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:cl(t.annotations,i),o=ht(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:L(t,{annotations:ea(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new sa({id:n.id},this.metadata):new yl({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},FA={type:"add-annotation",deserialize:(e,t)=>new oa({kind:e.kind,annotation:e.annotation,index:e.index},t)},$A=(e,t)=>{const r=ra(t);return r===null?null:dl(e,r)},GA=(e,t)=>{const r=la(e);return r===null?null:vl(r.points,t)},UA=e=>la(e)!==null,WA=(e,t)=>{const r=la(e);if(r===null)return null;const n=vl(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},la=e=>{const t=KA[e.kind];return t===null?null:t(e.annotation)},Ti=(e,t)=>e.anchorType!=="panel"?null:{points:[rn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Li=(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})},HA=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[rn(e,e.offset),rn(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}})},KA={text:e=>Ti(e.at,t=>({at:t})),sticker:e=>Ti(e.at,t=>({at:t})),shape:e=>Li(e.region,t=>({region:t})),image:e=>Li(e.region,t=>({region:t})),arrow:e=>HA(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},rn=(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)},vl=(e,t)=>({x:wi(e.map(r=>r.x),t.x),y:wi(e.map(r=>r.y),t.y)}),wi=(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,Ge.default)(t,r,n)},bl=(e,t,r)=>{const n=t.annotation;if(!qA(n,r))return null;const a=ht(e.annotations,t.kind),i=zA(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:L(e,{annotations:ea(e.annotations,t.kind,s)}),inverse:YA(n,r)}},zA=(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)))},YA=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},qA=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),ca=class Sl{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=S({...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=pt(t.annotations,n);if(i===null||i.kind!==r)return null;const s=bl(t,i,a);return s===null?null:{spec:s.spec,revert:new Sl({kind:r,id:n,patch:s.inverse},this.metadata)}}},jA={type:"update-annotation",deserialize:(e,t)=>new ca(e,t)},xl=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=S({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=pt(e.annotations,this.params.id);if(t===null)return null;const r=WA(t,this.params.translation);if(r===null)return null;const n=bl(e,t,r);return n===null?null:{spec:n.spec,revert:new ca({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},XA={type:"move-annotation",deserialize:(e,t)=>new xl(e,t)},ZA=["cartesian","polar","flip"],$=new tr,Al=e=>$.has(e)?$.get(e):null,Il=new l.TransformRegistry,JA=new ro(Il),mr=e=>{const t=e.transforms.every(r=>Il.has(r.transformType));return e.transforms.length===0||!t?e.data:JA.compile({data:e.data,transforms:e.transforms})};function ua(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 gt(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function yt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:L(e,{scales:Hi(e.scales,n,r)})}function vt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function nn(e,t,r){const n=En(Hs(no($),{data:mr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Ks(n):n}var Tl=class Ll{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=S({...r,description:uI(t)})}apply(t){const r="previous"in this.params?this.params.previous:dI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Ll({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},QA={type:"set-chart-type",deserialize:(e,t)=>new Tl(e,t)},wl={type:"sum"},eI={type:"identity"},tI=["bar","line","area","point","tile"],da="tile",rI=["y","color"],nI=Object.values(l.LAYER_LABEL_VARIABLES),aI={coordType:"cartesian",geom:da,position:"identity"},bt=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),iI=e=>{const t=e.layers.filter(te),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const s=Vl(t);if(s!==null)return{coordType:"cartesian",comboType:s}}if(!t.every(s=>s.geom===r.geom&&s.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}},sI=e=>{if(!e)return!1;const t=e.layers.filter(te);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:Rl(e,r)?Cl(e,r).length>=1:pr(e,e.data.groupVariableNamesByType().numeric).length>=2},oI=e=>e?Ml(e,aI)!==null:!1,lI=e=>El(e)?.at(-1)?.id??null,El=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(te);return Vl(t)===null?null:t},Vl=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 cI(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)},cI=e=>e.some(t=>t.yScaleType==="secondary"||zt(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,uI=e=>"previous"in e?"Restore the previous chart type":bt(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,dI=(e,t)=>{const r=Ml(e,t);if(r===null)return null;const n=bt(t)?pI(r,t):mI(r,t,e);return n===null||r===e?n:{...n,scales:wI({...e,...n},n.scales)}},mI=(e,t,r)=>{if(bt(t)||!EI(t))return null;const n={...e,layers:Wl(e.layers)},a=CI(n.layers.filter(te),t),i=Kl(n.coords,t),s=kl(n,t),o=Ul({...n,mapping:s},t,a,s!==n.mapping);return{coords:i,layers:o,scales:ua(zl(r,o,i.coordType),o),mapping:s}},pI=(e,t)=>{const r=gI(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=DI(r.filter(te),t.comboType),i=Kl(n.coords,t),s=kl(n,t),o=Ul({...n,mapping:s},t,a,s!==n.mapping),c=hI(e)?o:fI(o);return{coords:i,layers:c,scales:ua(zl(e,c,i.coordType),c),mapping:s}},hI=e=>El(e)!==null,fI=e=>{const t=e.filter(te).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},gI=(e,t)=>{const r=e.layers.filter(te);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:Rl(e,n)?yI(e,n):vI(e,n,t)},Rl=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},yI=(e,t)=>{const[r]=Cl(e,t);if(r===void 0)return null;const n=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Dl(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:wl,...Ol(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},pr=(e,t)=>{const r=St(e);return t.filter(n=>n!==r)},Cl=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return pr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},St=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),vI=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=pr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const s=l.readFoldKeepVariables(e.data,St(e)),o=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=bI(t,Ei(a.slice(0,-1),s,o)),u=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Dl(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...Ei([i],s,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Dl=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},Ei=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?Ol(n,r):_l(e,t)},_l=(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})]}),Ol=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),bI=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),kl=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Pl(t)?"":St(e);return n===r?e.mapping:{...e.mapping,x:n}},Pl=e=>e.coordType==="polar"&&e.theta==="y",SI=e=>!bt(e)&&e.geom===da,xI=e=>e.layers.filter(te).some(t=>t.geom===da),Ml=(e,t)=>{const r=SI(t);return r===xI(e)?e:r?AI({...e,layers:Wl(e.layers)}):II(e)??e},AI=e=>{const t=Bl(e);if(t===null)return null;const r=TI(e,t)===null?LI(e,t):Fl(e,t);return r===null?null:Nl(e,t,r)},II=e=>{const t=Bl(e);if(t===null)return null;const r=Fl(e,t);return r===null?null:Nl(e,t,r)},Nl=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Bl=e=>{const t=e.layers.filter(te);return t.length===1?t[0]??null:null},Fl=(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:$l(t)}},$l=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}},TI=(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===St(e))return null;const i=mr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},LI=(e,t)=>{const r=pr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,St(e)),a=_l(r,n),i=$l(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},wI=(e,t)=>rI.reduce((r,n)=>{const a=nn(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Ze(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),EI=e=>ZA.includes(e.coordType)&&Gl(e.geom)&&VI(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),VI=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=$.get(e);return n.includes(t)&&a.includes(r)},Gl=e=>tI.includes(e),te=e=>Gl(e.geom)&&!RI(e.stat),RI=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},CI=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},DI=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,s)=>n===null||s===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:_I(i,t,n)}]);return new Map(a)},_I=(e,t,r)=>e.geom!=="bar"||zt(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Ul=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Us($,Ze(e.layers,i=>{const s=r.get(i.id);if(s===void 0)return i;const o=OI(i.stat,e.coords,t);return a||n||i.geom!==s.geom||i.position!==s.position||o!==i.stat?PI(e,{...i,stat:o},t.coordType,s):i}))},OI=(e,t,r)=>Pl(r)?e.type==="identity"?wl:e:kI(t)&&e.type==="sum"?eI:e,kI=e=>e.coordType==="polar"&&e.params.theta==="y",PI=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...Ce($,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:o},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Wl=e=>{const t=e.filter(te);if(t.length<2||!e.some(zt))return e;const[r]=t;return e.flatMap(n=>n===r?[MI(n)]:zt(n)?[]:[n])},zt=e=>Hl(e)!==null,Hl=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:nI.includes(t.options.variableName)?t:null},MI=e=>{const t=Hl(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)}},Kl=(e,t)=>{const r=NI(e,t);return(0,Bt.default)(r,e)?e:r},NI=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Hr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Ot;return Hr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},zl=(e,t,r)=>{const n=Ur($,t),a=Ur($,e.layers),i=e.coords.coordType==="polar";return Ze(e.scales,s=>{const o=BI(s,n,a),c=FI(o,n,a);return GI(c,r,i)})},BI=(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 Kr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Kr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=$I(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},FI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},$I=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,GI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},Yl=class ql{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=S({...r,description:WI(t)})}apply(t){const r="previous"in this.params?this.params.previous:HI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new ql({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},UI={type:"set-mapping",deserialize:(e,t)=>new Yl(e,t)},jl=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Xl=e=>e===""?null:e,WI=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Xl(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},HI=(e,{aesthetic:t,variable:r})=>{if(!EA(t))return null;const n=Xl(r),a=zI(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:qI(e,t,a,n),layers:KI(e.layers,a)}},KI=(e,t)=>Ze(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&Al(r.geom)===null)return r;const a=Gs($,r.geom,r.position,n);return(0,Bt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),zI=(e,t,r)=>r===null?YI(e,t):jl(e,t)===r?e:{...e,[t]:r},YI=(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},qI=(e,t,r,n)=>{if(!us(t))return e.scales;let a=e.scales;for(const i of jI(e,t))a=ZI(e,a,i,r,n);return a},jI=(e,t)=>t==="y"&&XI(e.layers)?["y","ySecondary"]:[t],XI=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},ZI=(e,t,r,n,a)=>{const i=t.find(o=>o.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,nn(e,r,n)];if(a===null&&!Ve(r)||a!==null&&!mr(e).hasVariable(a))return t;const s=nn(e,r,n);return JI(i,s)?t:Ze(t,o=>o.scaledAesthetic===r?s:o)},JI=(e,t)=>e.scaleType===t.scaleType||Vi(e)&&Vi(t),Vi=e=>e.scaleType==="discrete"||e.scaleType==="palette",Zl=class Jl{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=S({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:E(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new Jl({textScale:r},this.metadata)}}},QI={type:"set-appearance-text-scale",deserialize:(e,t)=>new Zl(e,t)},ma=e=>e==="both"?["x","y"]:[e],Ql=e=>e==="both"?"the":`${e} axis`;function pa(e,t){return hr(e)?e[t]:e}function eT(e,t){return e.config.axes[t]??{}}function tT(e,t,r){if(t!=="ySecondary")return E(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=ec(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,L(e,{config:L(e.config,{axes:i})})}function hr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function ec(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],s=a in t?rT(i,t[a]):i;s!==i&&(n=!0),s!==void 0&&(r[a]=s)}return n?Object.keys(r).length>0?r:void 0:e}function rT(e,t){return l.isPlainObject(t)?ec(l.isPlainObject(e)?e:void 0,t):t}var tc=class rc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=S({...r,description:`Set ${t.axis} axis label to ${aT(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=eT(t,r).label;if(a===n)return null;const i=tT(t,r,{label:n});return i===t?null:{spec:i,revert:new rc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},nT={type:"set-axis-label",deserialize:(e,t)=>new tc(e,t)};function aT(e){return e===void 0?"(inherited)":e??"(none)"}var nc=class ac{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{position:n}}}}),revert:new ac({axis:r,position:a},this.metadata)}}},iT={type:"set-axis-position",deserialize:(e,t)=>new nc(e,t)},ic=class sc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new sc({axis:r,tickMode:a},this.metadata)}}},sT={type:"set-axis-tick-mode",deserialize:(e,t)=>new ic(e,t)},oc=class lc{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new lc({axis:r,isVisible:a},this.metadata)}}},oT={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new oc(e,t)},cc=class uc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new uc({axis:r,isVisible:a},this.metadata)}}},lT={type:"set-axis-visibility",deserialize:(e,t)=>new cc(e,t)},dc=class mc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=S({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:E(t,{config:{content:{caption:this.params.caption}}}),revert:new mc({caption:r},this.metadata)}}},cT={type:"set-content-caption",deserialize:(e,t)=>new dc(e,t)},pc=class hc{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=S({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(qe(r,this.params.source))return null;const n=L(t.config.content,{source:this.params.source});return{spec:L(t,{config:L(t.config,{content:n})}),revert:new hc({source:r},this.metadata)}}},uT={type:"set-content-source",deserialize:(e,t)=>new pc(e,t)},fc=class gc{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=S({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:E(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new gc({subtitle:r},this.metadata)}}},dT={type:"set-content-subtitle",deserialize:(e,t)=>new fc(e,t)},yc=class vc{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=S({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:E(t,{config:{content:{title:this.params.title}}}),revert:new vc({title:r},this.metadata)}}},mT={type:"set-content-title",deserialize:(e,t)=>new yc(e,t)},de=class Mt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=S({...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],s=aa(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new Mt({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!dr(y,n));return{spec:Or(t,r,g),revert:f}}if(o!==void 0){if(gl(o.declarations,c))return null;const f={...o,declarations:c},g=new Mt({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:Or(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},h=[...i.slice(0,d),m,...i.slice(d)],p=new Mt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:Or(t,r,h),revert:p}}},pT=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."})},hT={type:"set-style-rule",deserialize:(e,t)=>(pT(e),new de(e,t))},Or=(e,t,r)=>L(e,{styles:{...e.styles,[t]:r}}),fT="dashed",gT=1,bc=(e,t,r,n)=>{const a=yT(t,r),i=bT(e,a,n);let s=e,o=!1;for(const c of a){const u=xT(s,c,n,ST(n,vT(r,c)));u!==null&&(s=u,o=!0)}return o?{spec:s,previous:i}:null},yT=(e,t)=>e==="both"&&!hr(t)?[void 0]:ma(e),vT=(e,t)=>t===void 0?hr(e)?e.x:e:pa(e,t),bT=(e,t,r)=>t.length===1?kr(e,t[0],r):{x:kr(e,"x",r),y:kr(e,"y",r)},kr=(e,t,r)=>Sc(e.styles.overrides,t)?.[r]??null,ST=(e,t)=>t===null||e==="lineType"&&t===fT||e==="strokeWidth"&&t===gT?null:t,xT=(e,t,r,n)=>{const a=Sc(e.styles.overrides,t);return(a?.[r]??null)===n?null:new de({list:"overrides",rule:TT(t,IT(a,r,n))}).apply(e)?.spec??null},AT=e=>e.select.target==="gridLine",Sc=(e,t)=>{const r=ur(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!AT(r)))return r.declarations},IT=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},TT=(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),xc=class Ac{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=S({...r,description:`Set ${Ql(t.axis)} grid line style to ${wT(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=bc(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new Ac({axis:r,lineStyle:a.previous},this.metadata)}}},LT={type:"set-grid-line-style",deserialize:(e,t)=>new xc(e,t)},wT=({axis:e,lineStyle:t})=>{const r=ma(e).map(n=>pa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},ET={type:"set-grid-line-width",deserialize:(e,t)=>new Ic(e,t)},Ic=class Tc{constructor(t,r={}){this.type="set-grid-line-width";const n=VT(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=S({...r,description:`Set ${Ql(t.axis)} grid line width to ${RT(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=bc(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new Tc({axis:r,lineWidth:a.previous},this.metadata)}}},VT=e=>hr(e)?{x:Pr(e.x),y:Pr(e.y)}:Pr(e),Pr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),RT=(e,t)=>{const r=ma(e).map(n=>pa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Lc=class wc{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new wc({axis:r,isVisible:a},this.metadata)}}},CT={type:"set-grid-visibility",deserialize:(e,t)=>new Lc(e,t)},Ec=class Vc{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:E(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Vc({compareWith:r},this.metadata)}}},DT={type:"set-headline-compare-with",deserialize:(e,t)=>new Ec(e,t)},Rc=class Cc{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:E(t,{config:{headline:{position:this.params.position}}}),revert:new Cc({position:r},this.metadata)}}},_T={type:"set-headline-position",deserialize:(e,t)=>new Rc(e,t)},Dc=class _c{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:E(t,{config:{headline:{show:this.params.show}}}),revert:new _c({show:r},this.metadata)}}},OT={type:"set-headline-show",deserialize:(e,t)=>new Dc(e,t)},Oc=class kc{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:E(t,{config:{headline:{size:this.params.size}}}),revert:new kc({size:r},this.metadata)}}},kT={type:"set-headline-size",deserialize:(e,t)=>new Oc(e,t)},PT={type:"set-highlight-dim-style",deserialize:(e,t)=>new Pc(e,t)},Pc=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=S({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Mc(e)===this.params.dimStyle)return null;const t=new de({list:"overrides",rule:NT(this.params.dimStyle)},this.metadata).apply(e);return t||null}},MT={select:{target:"geom"},when:{state:"dimmed"}},Mc=e=>{const t=ur(e.styles.overrides,MT);return(t!==void 0&&ia(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},NT=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Nc=class Bc{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:E(t,{config:{legend:{align:this.params.align}}}),revert:new Bc({align:r},this.metadata)}}},BT={type:"set-legend-align",deserialize:(e,t)=>new Nc(e,t)},Fc=class $c{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:E(t,{config:{legend:{display:this.params.display}}}),revert:new $c({display:r},this.metadata)}}},FT={type:"set-legend-display",deserialize:(e,t)=>new Fc(e,t)},Gc=class Uc{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:E(t,{config:{legend:{position:this.params.position}}}),revert:new Uc({position:r},this.metadata)}}},$T={type:"set-legend-position",deserialize:(e,t)=>new Gc(e,t)},Wc=class Hc{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:E(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Hc({abbreviation:r},this.metadata)}}},GT={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Wc(e,t)},Kc=class zc{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:E(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new zc({decimals:r},this.metadata)}}},UT={type:"set-number-format-decimals",deserialize:(e,t)=>new Kc(e,t)},Yc=class qc{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=S({...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=HT(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:E(t,{config:{content:{[a]:n}}}),revert:new qc({slot:r,isVisible:i},this.metadata)}}},WT={type:"toggle-content-visibility",deserialize:(e,t)=>new Yc(e,t)},Ri={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function HT(e){return Object.hasOwn(Ri,e)?Ri[e]:void 0}var jc=class Xc{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=S({...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(qe(i.xLimits,a.xLimits)&&qe(i.yLimits,a.yLimits))return null;const s={};r!==void 0&&(s.xLimits=a.xLimits),n!==void 0&&(s.yLimits=a.yLimits);const o=new Xc(s,this.metadata);return{spec:L(t,{coords:zT(t.coords,i)}),revert:o}}},KT={type:"set-coord-limits",deserialize:(e,t)=>new jc(e,t)};function zT(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 Zc=class Jc{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Ge.default)(t.innerRadius,0,1)},this.metadata=S({...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:L(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Jc({innerRadius:n},this.metadata)}}},YT={type:"set-polar-inner-radius",deserialize:(e,t)=>new Zc(e,t)},qT={type:"set-polar-start-angle",deserialize:(e,t)=>new Qc(e,t)},Qc=class eu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:Ci(t.startAngle)},this.metadata=S({...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 Ci(n)===this.params.startAngle?null:{spec:L(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new eu({startAngle:n},this.metadata)}}},Mr=360,Ci=e=>(e%Mr+Mr)%Mr,ha=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=S({...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 fa({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:L(e,{highlights:n}),revert:a}}},jT={type:"remove-highlight",deserialize:(e,t)=>new ha(e,t)},fa=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??M(),scope:e.scope??"data-point"},this.metadata=S({...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 s=new ha({id:r},this.metadata),o={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:L(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},XT={type:"add-highlight",deserialize:(e,t)=>new fa(e,t)};function ga(e,t){return{...e,params:{...e.params,...t}}}function fr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function ya(e,t){return L(e,{layers:[...e.layers,t]})}function H(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:L(e,{layers:Hi(e.layers,n,r)})}function gr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:L(e,{layers:e.layers.filter((n,a)=>a!==r)})}var va=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=S({...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=gr(e,this.params.layerId);return n===e?null:{spec:n,revert:new ba({layer:r,index:t},this.metadata)}}},ZT={type:"remove-layer",deserialize:(e,t)=>new va(e,t)},ba=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??M()},...e.index!==void 0&&{index:e.index}},this.metadata=S({...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:L(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new va({layerId:t.id},this.metadata)}}},JT={type:"add-layer",deserialize:(e,t)=>new ba(e,t)},tu=class ru{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=S({...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(D(t.layers,r),"bar"))return null;const a=Ae("bar",r),i=ft(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:eL(i,n)}}).apply(t);if(!o)return null;const c=new ru({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},QT={type:"set-bar-border-radius",deserialize:(e,t)=>new tu(e,t)},eL=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},tL={type:"set-bar-width",deserialize:(e,t)=>new au(e,t)},nu=.05,rL=1,au=class iu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Ge.default)(t.width,nu,1);this.params={...t,width:n},this.metadata=S({...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?D(t.layers,this.params.layerId):le(t.layers,"bar");if(!q(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:H(t,r.id,ga(r,{width:this.params.width})),revert:new iu({layerId:r.id,width:n},this.metadata)}}},su=class ou{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:H(t,r.id,fr(r,{format:this.params.format})),revert:new ou({layerId:r.id,format:n},this.metadata)}}},nL={type:"set-data-labels-format",deserialize:(e,t)=>new su(e,t)},lu=class cu{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=S({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:H(t,r.id,{...r,position:this.params.position}),revert:new cu({layerId:r.id,position:n},this.metadata)}}},aL={type:"set-layer-position",deserialize:(e,t)=>new lu(e,t)},uu=class du{constructor(t,r={}){this.type="set-layer-stat";const n=$s(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=S({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return sL(n,this.params.stat)?null:{spec:H(t,r.id,{...r,stat:this.params.stat}),revert:new du({layerId:r.id,stat:n},this.metadata)}}},iL={type:"set-layer-stat",deserialize:(e,t)=>new uu(e,t)},sL=(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},mu=class pu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=S({...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?D(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=H(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:L(a,{scales:ua(a.scales,a.layers)}),revert:new pu({layerId:r.id,yScaleType:n},this.metadata)}}},oL={type:"set-layer-y-scale-type",deserialize:(e,t)=>new mu(e,t)},hu=class fu{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=S({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:H(t,r.id,ga(r,{interpolate:this.params.interpolate})),revert:new fu({layerId:r.id,interpolate:n},this.metadata)}}},lL={type:"set-line-interpolation",deserialize:(e,t)=>new hu(e,t)},gu=class yu{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:H(t,r.id,ga(r,{missingValues:this.params.missingValues})),revert:new yu({layerId:r.id,missingValues:n},this.metadata)}}},cL={type:"set-line-missing-values",deserialize:(e,t)=>new gu(e,t)},vu=class bu{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=S({...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=D(t.layers,r);if(!q(a,"line","area"))return null;const i=ft(t.styles.overrides,Ae(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=dL(i,n),c=new de({list:"overrides",rule:a.geom==="area"?{...Ae("area",r),declarations:o}:{...Ae("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new bu({layerId:r,lineWidth:s},this.metadata)}:null}},uL={type:"set-line-width",deserialize:(e,t)=>new vu(e,t)},dL=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},Su=class xu{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=S({...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(D(t.layers,r),"point"))return null;const a=Ae("point",r),i=ft(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:pL(i,n)}}).apply(t);return o?{spec:o.spec,revert:new xu({layerId:r,size:s},this.metadata)}:null}},mL={type:"set-point-size",deserialize:(e,t)=>new Su(e,t)},pL=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},Au=class Iu{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=S({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(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(([s])=>s!=="label")):{...r.params,label:a};return{spec:H(t,r.id,{...r,params:i}),revert:new Iu({layerId:r.id,label:n??null},this.metadata)}}},hL={type:"set-rule-label",deserialize:(e,t)=>new Au(e,t)},Tu=class Lu{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=S({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(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:H(t,r.id,{...r,mapping:i}),revert:new Lu({layerId:r.id,value:a},this.metadata)}}},fL={type:"set-rule-value",deserialize:(e,t)=>new Tu(e,t)},gL={type:"set-stat-line",deserialize:(e,t)=>new wu(e,t)},wu=class Eu{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=S({...r,description:IL(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=vL(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&&AL(r.layer,n))return null;const a=new Eu({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:H(t,r.layer.id,n),revert:a};const i=r===void 0?t:gr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:ya(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"?bL(this.params):SL(t,this.params);if(n===null)return null;const a=Ce($,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},yL="linear",vL=e=>{const t=pl(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=hl(e.layers);if(r!==void 0)return{line:"average",layer:r}},bL=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??yL}),interactive:!1}),SL=(e,{group:t,label:r})=>{const n=xL(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),s=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:s?[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})},xL=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),AL=(e,t)=>(0,je.isEqual)({...e,id:""},{...t,id:""}),IL=e=>e==="none"?"Hide stat line":`Show ${e} line`,Vu=class Ru{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=S({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:H(t,r.id,fr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new Ru({layerId:r.id,showCategoryLabels:n},this.metadata)}}},TL={type:"toggle-category-labels",deserialize:(e,t)=>new Vu(e,t)},Cu=class Du{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=S({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:H(t,r.id,fr(r,{showDataLabels:this.params.showDataLabels})),revert:new Du({layerId:r.id,showDataLabels:n},this.metadata)}}},LL={type:"toggle-data-labels",deserialize:(e,t)=>new Cu(e,t)},wL={type:"toggle-goal-line",deserialize:(e,t)=>new _u(e,t)},_u=class an{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=S({...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=ml(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=gr(t,r.id);return a===t?null:{spec:a,revert:new an({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:ya(t,n),revert:new an({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ce($,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??EL}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},EL=0,VL={type:"toggle-line-fill",deserialize:(e,t)=>new Ou(e,t)},Ou=class ku{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=S({...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(D(t.layers,r),"line"))return null;const i=Ae("line",r),s=ft(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new de({list:"overrides",rule:{...i,declarations:CL(s,n?a??RL:null)}}).apply(t);if(!u)return null;const d=new ku({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},RL=.2,CL=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},DL={type:"toggle-line-points",deserialize:(e,t)=>new Pu(e,t)},Pu=class sn{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=S({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(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:ya(t,this.params.removedLayer??Ce($,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new sn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:gr(t,n.id),revert:new sn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:bn(n,[r]))}},Mu=class Nu{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=S({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:H(t,r.id,fr(r,{showStackTotals:this.params.showStackTotals})),revert:new Nu({layerId:r.id,showStackTotals:n},this.metadata)}}},_L={type:"toggle-stack-totals",deserialize:(e,t)=>new Mu(e,t)},Bu=class Fu{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=S({...r,description:`Set ${vt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=gt(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 s={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},o=yt(t,this.params.scaledAesthetic,s),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:o,revert:new Fu(c,this.metadata)}}},OL={type:"set-scale-domain",deserialize:(e,t)=>new Bu(e,t)},$u=class Gu{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=S({...r,description:`Set ${vt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=gt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||qe(r.palette,this.params.palette)?null:{spec:yt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Gu({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},kL={type:"set-scale-palette",deserialize:(e,t)=>new $u(e,t)},Uu=class Wu{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=S({...r,description:`Set ${vt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=gt(t,this.params.scaledAesthetic);if(!r||!ML(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:yt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Wu({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},PL={type:"set-scale-reverse",deserialize:(e,t)=>new Uu(e,t)};function ML(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Hu=class Ku{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=S({...r,description:`Set ${vt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=gt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:yt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Ku({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},NL={type:"set-scale-transform",deserialize:(e,t)=>new Hu(e,t)},zu=class Yu{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=S({...r,description:`Set ${vt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=gt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:yt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Yu({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},BL={type:"set-scale-zero",deserialize:(e,t)=>new zu(e,t)},qu=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}},b=new qu;b.register(QA);b.register(UI);b.register(JT);b.register(ZT);b.register(nL);b.register(aL);b.register(iL);b.register(oL);b.register(lL);b.register(uL);b.register(QT);b.register(tL);b.register(mL);b.register(cL);b.register(hL);b.register(fL);b.register(gL);b.register(TL);b.register(LL);b.register(wL);b.register(VL);b.register(DL);b.register(_L);b.register(OL);b.register(kL);b.register(PL);b.register(NL);b.register(BL);b.register(QI);b.register(nT);b.register(sT);b.register(iT);b.register(oT);b.register(lT);b.register(cT);b.register(uT);b.register(dT);b.register(mT);b.register(LT);b.register(ET);b.register(CT);b.register(DT);b.register(_T);b.register(OT);b.register(kT);b.register(PT);b.register(BT);b.register(FT);b.register($T);b.register(GT);b.register(UT);b.register(WT);b.register(XT);b.register(jT);b.register(hT);b.register(FA);b.register(BA);b.register(jA);b.register(XA);b.register(KT);b.register(YT);b.register(qT);var ju=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,s=e.apply(t);if(!s)return a||(this.hasOpenRun=!1),i(t,null);const o=r?.({spec:s.spec,command:e})??null,c=o?o.adopted:s.spec;return c?(this.push(e,c,s.revert,a),i(c,o?.value??null)):(a||(this.hasOpenRun=!1),i(t,o?.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:Di(this.undoStack),redoStack:Di(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],s=this.hasOpenRun&&i!==void 0&&$L(i.command,e);if(n&&s){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)}}},FL=Object.freeze([]),$L=(e,t)=>{if(e.type!==t.type||e.target.kind!==t.target.kind)return!1;const r=e.target,n=t.target;for(const a of new Set([...Object.keys(r),...Object.keys(n)]))if(!Object.is(r[a],n[a]))return!1;return!0},Di=e=>e.length===0?FL:e.map(t=>t.command.metadata),GL=(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&&dr(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"observation":return t.kind==="observation"&&e.layerId===t.layerId&&e.index===t.index;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}`})}},UL=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}},WL=class{constructor(e){this.compiler=e,this.history=new ju,this.current=null,this.last=null,this.hostInput=null,this.run=new UL(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;if(this.hostInput=e.input,!r&&!n&&!a)return null;let i=null;r?this.run.close():i=this.closeAndConvert();const s=this.last,o=s&&!r?s.input:e.input;this.last={input:o,data:e.data,customPalettes:e.customPalettes};const c=this.current,u=r||a||!c?this.absorb(this.compiler.compile({input:o,data:e.data,customPalettes:e.customPalettes})):this.absorb(this.compiler.recompile({spec:c.spec,data:e.data}));return r&&u.ok&&this.history.clear(),{result:u,inputChanged:r,...i&&{sealedInput:i.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:s}=this;if(!a||!i)return n;const o=s.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 o&&n.push(this.renderedNotification(o,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 s=this.commit(a,r);return{adopted:s.ok?s.compiled.spec:null,value:{result:s,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});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const s={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:s,command:n}),s}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=fl(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},HL=new Set(["x","y"]),_i=["numeric","categorical","temporal"],Oi=["numeric"],KL=(e,t)=>{const r=e.layers.map(a=>Al(a.geom)).filter(l.isDefined),n=mr(e);return t.filter(a=>zL(e,r,a)).map(a=>({aesthetic:a,variables:YL(n,r,a),isRequired:HL.has(a)}))},zL=(e,t,r)=>{switch(r){case"x":return!XL(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))}},YL=(e,t,r)=>{const n=qL(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},qL=(e,t)=>t==="size"?Oi:t!=="x"&&t!=="y"?_i:jL(e,t)?Oi:_i,jL=(e,t)=>e.some(r=>r.positionRoles.some(n=>cs.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),XL=e=>e.coordType==="polar"&&e.params.theta==="y",ZL=500,JL="normal",Sa={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},QL=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}`},xa=e=>typeof e!="string"?e??500:Sa[e],ew="\0",tw=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,xa(t.weight),t.style??"normal",e].join(ew)}},rw={" ":.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 nw=1.05,aw=.84,iw=.21,sw=class{measureText(e,t){let r=0;for(const i of e)r+=(rw[i]??.55)*t.size;xa(t.weight)>=Sa.semiBold&&(r*=nw);const n=aw*t.size,a=iw*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=tb;exports.ARROW_DEFAULTS=fe;exports.AXIS_KEYS=fn;exports.AddAnnotationCommand=oa;exports.AddHighlightCommand=fa;exports.AddLayerCommand=ba;exports.BORDER_RADIUS_PX=jn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=zh;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Sg;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=tw;exports.CommandRegistry=qu;exports.CommandStackManager=ju;exports.Compiler=ao;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_AREA_ALPHA=l.DEFAULT_AREA_ALPHA;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_BORDER_WIDTH=l.DEFAULT_BORDER_WIDTH;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=JL;exports.DEFAULT_FONT_WEIGHT=ZL;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRID_LINE_COLOR=l.DEFAULT_GRID_LINE_COLOR;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DEFAULT_TEXT_PRIMARY=l.DEFAULT_TEXT_PRIMARY;exports.DEFAULT_TEXT_SECONDARY=l.DEFAULT_TEXT_SECONDARY;exports.DEFAULT_TICK_LABEL_OFFSET=l.DEFAULT_TICK_LABEL_OFFSET;exports.DEFAULT_TICK_LINE_COLOR=l.DEFAULT_TICK_LINE_COLOR;exports.DEFAULT_TICK_LINE_LENGTH=l.DEFAULT_TICK_LINE_LENGTH;exports.DIFFERENCE_ARROW_DEFAULTS=Dt;exports.DIVERGING_SCHEME_NAMES=Ns;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ae;exports.GraphCompilationSession=WL;exports.HEADLINE_SWATCH_GAP=Zb;exports.HEADLINE_SWATCH_SIZE=Xb;exports.HEADLINE_TREND_GAP=eS;exports.HEADLINE_TREND_ICON_SIZE=Qb;exports.HEADLINE_VALUE_LABEL_GAP=Jb;exports.HeuristicTextMeasurer=sw;exports.HoverEngine=dx;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=Vg;exports.LINE_STYLE_TYPES=ln;exports.LayoutCompiler=Dv;exports.MAX_BAR_WIDTH=rL;exports.MIN_BAR_WIDTH=nu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=xl;exports.NAMED_WEIGHTS=Sa;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ta;exports.OUT_OF_VIEW_MARGIN_PX=rb;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=am;exports.POSITION_TYPES=Ni;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=J;exports.RemoveAnnotationCommand=sa;exports.RemoveHighlightCommand=ha;exports.RemoveLayerCommand=va;exports.SCALED_POSITION_AESTHETIC_KEYS=gn;exports.SCALED_VISUAL_AESTHETIC_KEYS=lt;exports.SCHEME_ALIASES=Bs;exports.SEQUENTIAL_SCHEME_NAMES=Yh;exports.SHAPE_DEFAULTS=he;exports.SIBLING_OVERLAP_THRESHOLD_PX=nb;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=Zl;exports.SetAxisLabelCommand=tc;exports.SetAxisPositionCommand=nc;exports.SetAxisTickModeCommand=ic;exports.SetAxisTicksVisibilityCommand=oc;exports.SetAxisVisibilityCommand=cc;exports.SetBarBorderRadiusCommand=tu;exports.SetBarWidthCommand=au;exports.SetChartTypeCommand=Tl;exports.SetContentCaptionCommand=dc;exports.SetContentSourceCommand=pc;exports.SetContentSubtitleCommand=fc;exports.SetContentTitleCommand=yc;exports.SetCoordLimitsCommand=jc;exports.SetDataLabelsFormatCommand=su;exports.SetGridLineStyleCommand=xc;exports.SetGridLineWidthCommand=Ic;exports.SetGridVisibilityCommand=Lc;exports.SetHeadlineCompareWithCommand=Ec;exports.SetHeadlinePositionCommand=Rc;exports.SetHeadlineShowCommand=Dc;exports.SetHeadlineSizeCommand=Oc;exports.SetHighlightDimStyleCommand=Pc;exports.SetLayerPositionCommand=lu;exports.SetLayerStatCommand=uu;exports.SetLayerYScaleTypeCommand=mu;exports.SetLegendAlignCommand=Nc;exports.SetLegendDisplayCommand=Fc;exports.SetLegendPositionCommand=Gc;exports.SetLineInterpolationCommand=hu;exports.SetLineMissingValuesCommand=gu;exports.SetLineWidthCommand=vu;exports.SetMappingCommand=Yl;exports.SetNumberFormatAbbreviationCommand=Wc;exports.SetNumberFormatDecimalsCommand=Kc;exports.SetPointSizeCommand=Su;exports.SetPolarInnerRadiusCommand=Zc;exports.SetPolarStartAngleCommand=Qc;exports.SetRuleLabelCommand=Au;exports.SetRuleValueCommand=Tu;exports.SetScaleDomainCommand=Bu;exports.SetScalePaletteCommand=$u;exports.SetScaleReverseCommand=Uu;exports.SetScaleTransformCommand=Hu;exports.SetScaleZeroCommand=zu;exports.SetStatLineCommand=wu;exports.SetStyleRuleCommand=de;exports.SpecResolver=Ys;exports.Stat=Re;exports.TAU=xe;exports.TEXT_ANNOTATION_DEFAULTS=_t;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Vu;exports.ToggleContentVisibilityCommand=Yc;exports.ToggleDataLabelsCommand=Cu;exports.ToggleGoalLineCommand=_u;exports.ToggleLineFillCommand=Ou;exports.ToggleLinePointsVisibilityCommand=Pu;exports.ToggleStackTotalsCommand=Mu;exports.UpdateAnnotationCommand=ca;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=Mi;exports.annotation=fA;exports.areAnchorsEqual=Fe;exports.areEditMenuTriggersEqual=Eb;exports.areEditTargetsEqual=GL;exports.areEndpointsComparable=Gi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=ul;exports.arePointerRegionListsEqual=Sb;exports.arePredicatesEqual=cr;exports.areStyleDeclarationsEqual=gl;exports.areStyleRuleAddressesEqual=dr;exports.buildAverageLineSymbols=Zv;exports.buildCalloutHitRegions=eb;exports.buildColumnKey=zo;exports.buildDataLabelsContent=Jy;exports.buildDiagnostic=Wi;exports.buildEditMenuTriggerRegion=Lb;exports.buildFontString=QL;exports.buildLayerIntroPlan=xx;exports.buildLayerStyleAddress=Ae;exports.buildLayerYValueFormatter=Kn;exports.buildObservationPredicate=fb;exports.buildPinnedNumberValueFormatter=Bb;exports.buildPolarBarArcPath=gS;exports.buildSliceGroupKey=jo;exports.buildTooltipContent=zx;exports.canAnchorDirectLabels=Ss;exports.canBecomeCombo=sI;exports.canBecomeHeatmap=oI;exports.canPlaceDataLabels=Zy;exports.clampAnnotationTranslation=GA;exports.commandRegistry=b;exports.compileChromeStyles=Xs;exports.compileStylesheetForLayer=tg;exports.compositeColor=sd;exports.computeArrow=jv;exports.computeDifferenceArrow=Oo;exports.computeDirectLabelsLayout=hb;exports.computeLineBoxHeight=lA;exports.computePanelBorderPaths=Px;exports.computePanelBorderSizes=Mx;exports.config=l.config;exports.convertSpecToInput=fl;exports.coord=l.coord;exports.countLayerGeoms=Ax;exports.createAlphaValueReader=dd;exports.createAnchorResolver=Ov;exports.createAreaPathGenerators=oS;exports.createColorValueReader=Fi;exports.createCompiler=xg;exports.createDatasetFromKindPartitions=Yd;exports.createEmptyHighlight=xs;exports.createGraphyBuilder=Lg;exports.createGroupValueReader=md;exports.createHeadlineItemRows=tS;exports.createLabelValueReader=cd;exports.createLineFillAreaGenerator=pS;exports.createLinePathGenerator=mS;exports.createObservationAnchorBuilder=ot;exports.createObservationAnchorParser=Ui;exports.createRawValueReader=W;exports.createSegmentYReader=st;exports.createSizeValueReader=ud;exports.createSpec=io;exports.createStableBandKeyGenerator=SS;exports.createStableCellKeyGenerator=xS;exports.createStableKeyGenerator=sr;exports.createStrokeWidthValueReader=pd;exports.createStyleResolver=ar;exports.createValueFormatter=C;exports.createXValueReader=Xe;exports.createYValueReader=cn;exports.cursorToPiePlane=hn;exports.cursorToPolar=Jt;exports.describeMeasurementBasis=Fr;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=$o;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=lp;exports.findAnnotation=pt;exports.findAverageLineLayer=hl;exports.findAxisGuide=qn;exports.findDistinctLayers=Sn;exports.findEquivalentHighlight=IA;exports.findGoalLineLayer=ml;exports.findHighlightsAtObservation=Rb;exports.findKindStyleDeclarations=ft;exports.findLayerByGeom=le;exports.findLayerById=D;exports.findLegendForAesthetic=qb;exports.findObservationAttachment=dl;exports.findPointerRegion=vb;exports.findStyleRule=ur;exports.findStyleRuleIndex=aa;exports.findTrendLineLayer=pl;exports.formatDifferenceLabel=Do;exports.formatHeadline=Fb;exports.formatLegends=zb;exports.formatRuleValue=jb;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=P;exports.getAlpha=To;exports.getAngleExtent=Wn;exports.getBarRectBounds=Ko;exports.getBoundingRect=dS;exports.getChromeDashArray=oA;exports.getColor=mt;exports.getCrossAxisCoordinate=Xt;exports.getCurve=ir;exports.getDashArray=sS;exports.getDifferenceArrowDimensions=_o;exports.getDifferenceArrowLabelBox=db;exports.getGroup=Y;exports.getHoverGuideLineProps=hx;exports.getHoverGuideRectProps=fx;exports.getInsetTileRect=Vo;exports.getLineType=Lo;exports.getMainAxisCoordinate=Ue;exports.getNumericWeight=xa;exports.getPolarHoverGuideArcProps=gx;exports.getRadiusExtent=Hn;exports.getRuleDashPattern=bS;exports.getScaledAesthetic=od;exports.getSize=Un;exports.getStablePolarBarKeyGenerator=AS;exports.getStackRole=ws;exports.getStrokeWidth=jr;exports.getTileRectBounds=Eo;exports.getUnionExtent=vS;exports.getX=R;exports.getXMax=U;exports.getXMin=G;exports.getY=w;exports.getYMax=_;exports.getYMin=k;exports.getYRaw=on;exports.hasMultipleGroups=Qt;exports.highlight=AA;exports.inferDefaultDifferenceArrowEndpoints=_b;exports.inferDifferenceArrowEndpoints=Wo;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=UA;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=yd;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=bt;exports.isCompanionLayer=bn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=ns;exports.isGeomStyleRule=ia;exports.isLayerOf=Ag;exports.isLayerOfType=q;exports.isLineStyleType=Bi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=bA;exports.isPointWithinEditMenuTrigger=wb;exports.isPointWithinRegionShape=Yn;exports.isSafeUrl=Wx;exports.isStackedPosition=B;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=VA;exports.normalizeAngle=He;exports.orderPointerRegions=bb;exports.pickReadableTextColor=id;exports.pipe=so;exports.placeCallouts=lb;exports.polarToUnit=Gt;exports.positionToAngle=is;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=lS;exports.prepareLineObservations=hS;exports.projectAnchorToPanel=Bo;exports.quantiseKey=z;exports.readAnchoredObservation=kb;exports.readAttachedObservation=ra;exports.readAuthoredNumber=tA;exports.readAuthoredString=rA;exports.readChartType=iI;exports.readComboLineLayerId=lI;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Mc;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=KL;exports.readMappedVariable=jl;exports.readObservationIndex=yx;exports.readXExtent=ol;exports.readYExtent=ll;exports.resolveAnchorVariable=we;exports.resolveArrowColor=mb;exports.resolveAxisLabelStyle=uA;exports.resolveBarBandFraction=Wr;exports.resolveBarBorderRadiusPx=Ho;exports.resolveBarBorderTreatment=uS;exports.resolveBarCornerRadiiPx=cS;exports.resolveColorRamp=Ln;exports.resolveComparisonBasis=bs;exports.resolveDataLabelStyle=mA;exports.resolveDeferredAnchors=Fv;exports.resolveDefinition=Tn;exports.resolveGraphChromeStyle=sA;exports.resolveGridLineStyle=aA;exports.resolveHeadlinePlacement=Lv;exports.resolveObservationPoint=Pb;exports.resolvePanelBorderStyle=nA;exports.resolvePolarBarCornerRadiusUnit=yS;exports.resolveRuleLabelStyle=pA;exports.resolveSegmentYSource=qt;exports.resolveTextStyle=se;exports.resolveTickLabelStyle=dA;exports.resolveTickLineStyle=iA;exports.resolveTooltipStyle=hA;exports.resolveYScaleAesthetic=oe;exports.sampleColorScheme=Jh;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Mb;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=cA;exports.toPanelCursor=Fo;exports.toPercent=ve;exports.toViewBoxX=Pv;exports.toViewBoxY=ne;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=lo;exports.uniqueId=M;exports.unitToPolar=ss;exports.updateSpec=E;
23
+ `,ov=(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},lv=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),ko=({arrow:e,mainAxis:t,panelWidth:r,panelHeight:n,textScale:a,locale:i})=>{const s=t==="y",o={x:e.start.x*r,y:(1-e.start.y)*n},c={x:e.end.x*r,y:(1-e.end.y)*n},u=_o(e.size,a),d=nv(s,o,c,u),m=(s?iv:av)(o,c,d,u),h=sv(s,c,u),p=ov(s,o,c,d,lv(s,o,c),e.labelCrossPosition),f=Do({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:o,end:c,linePath:m,arrowheadPath:h,labelPosition:p,labelText:f,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*cv({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!He(s.start.x,s.start.y)||!He(s.end.x,s.end.y))continue;const o=ko({arrow:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,textScale:n,locale:a}),c=i(o.labelText,s.size).width+2*o.labelPaddingX,u=o.labelLineHeight+2*o.labelPaddingY;yield{x:r.x+o.labelPosition.x-c/2,y:r.y+o.labelPosition.y-u/2,width:c,height:u}}}var uv=e=>{const t=e.padding,r=Qa(e.rows,t?.top??0,t?.bottom??0),n=Qa(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:hv(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},dv=e=>{const t=ei(e.rows,e.height),r=ei(e.cols,e.width),n=ti(t),a=ti(r),i=new Map;for(const s of e.placements){const o=s.rowSpan??1,c=s.colSpan??1,u=a[s.col]??0,d=n[s.row]??0,m=ri(r,s.col,c),h=ri(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,h)})}return i},Qa=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let s=0;s<e.length;s++){const o=e[s];if(!o)continue;Xr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(mv(o));const c=pv(e,s);if(Xr(o)&&c){const u=o.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}},mv=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Xr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,pv=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Xr(n))return n}},hv=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),s=r.get(a.col);if(i===void 0||s===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):s;o===void 0||c===void 0||n.push({name:a.name,row:i,col:s,rowSpan:Math.max(1,o-i+1),colSpan:Math.max(1,c-s+1)})}return n},ei=(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)},ti=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},ri=(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},Ye={top:0,right:0,bottom:0,left:0},Oo={outer:Ye,inner:Ye},fv={top:24,right:24,bottom:24,left:24},gv=(e,t,r,n=Ye,a=Oo,i=fv,s={})=>{const o={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=ni(Rg,s),d=ni(Cg,s);return uv({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:o.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:o.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:o.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:o.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"},...vv(r.axes),...bv(r.axesLabels,r.axes),...Sv(r.legends)],containerSize:e,padding:i})},yv=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Rr(t,e.after)}:{before:Rr(t.before,e.before),after:Rr(t.after,e.after)}:e,Rr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,ni=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=yv(e[n],t[n]);return r},vv=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},bv=(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},Sv=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 xv=class{constructor(e){this.outer={...Ye},this.inner={...Ye},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)))}},Av=["top","right","bottom","left"],Cr=(e,t)=>{const r={};for(const n of Av){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function ai(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Zr=["large","medium","small"],Iv=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Zr)if(r(n)<=t)return n;return"small"},Tv=({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},Lv=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const s=a===0?i:n+t+i;if(s>r)break;n=s,a+=1}return a},wv=({headline:e,containerSize:t,measurer:r})=>{if(Po(e))return 0;const n=Mo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},Ev=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(Po(e)){const o=Vv(t.panel,e.innerRadius),c=Tv({size:e.size,availableWidth:o.width,measureStripWidth:No(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=Mo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=Lv({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},Po=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Vv=(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}},Mo=(e,t,r)=>Iv({size:e.size,availableWidth:t,measureStripWidth:No(e,r)}),No=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Pe={x:0,y:0,width:0,height:0},Rv="0000",Cv=3,tt=e=>typeof e=="number"&&Number.isFinite(e)?e:24,Dv=e=>e.plot.y+e.plot.height-e.panel.y,_v=e=>{if(typeof e=="object"&&e!==null)return{top:tt(e.top),right:tt(e.right),bottom:tt(e.bottom),left:tt(e.left)};const t=tt(e);return{top:t,right:t,bottom:t,left:t}},kv=class{constructor(e){this.measurer=e}compile(e){return Xt({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Oo,panelBorder:e.panelBorder??Ye,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:_v(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:Ov(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>ii(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:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>ii(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:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:Dv(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new xv(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of cv({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,textScale:e.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(s,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const s of rv({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(s,e.overflowStrategy.dataLabels);const i=a.resolve();return ai(i.inner,n.inner)&&ai(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m}){let h=t,p=s;for(let f=0;f<Cv;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,p);if(g===p)break;p=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}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,s=a.height-n.vertical*2;return i<=0||s<=0?si(r,a,0,0):si(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=M(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const s=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,s.width),a=Math.max(a,s.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:Rv}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=M(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=Qg({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:o,...c}=e,u={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?qg({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:s,padding:o,gaps:c}){const u=dv(gv(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Pe,headline:u.get("headline")??Pe,footer:u.get("footer")??Pe,plot:u.get("plot")??Pe,panelFrame:u.get("panelFrame")??Pe,panel:u.get("panel")??Pe,axes:Cr(u,"Axis"),axisLabels:Cr(u,"AxisLabel"),legends:Cr(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 o of e)o.isVisible&&o.geometry==="linear"&&(a[o.position]=this.measurer.measureAxis(o),o.label!==null&&(i[o.position]=this.measurer.measureAxisLabel(o)));const s={top:0,right:0,bottom:0,left:0};for(const o of t)s[o.position]=this.measurer.measureLegend(o);return{axes:a,axesLabels:i,legends:s,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:wv({headline:e,containerSize:t,measurer:this.measurer})}},ii=e=>e==="left"||e==="right",si=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,s=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-s)/2,y:t.y+n+(i-s)/2,width:s,height:s}}},Ov=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(s=>s.value)),a=new WeakMap;return i=>{const s=a.get(i);if(s)return s;const o=Bn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},Pv=(e=[])=>{const t=Mv(e);return{resolve:(r,n,a)=>t.has(r)?t.get(r).resolveAnchorPosition?.(n,a)??null:null,hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?qi(r,t.get(r.geom)):null}},Mv=e=>{const t=new rr;for(const r of e){const n=Tn(r);n instanceof ae&&t.register(n.type,n)}return t};function Nv(e){return e}function ne(e){return 1-e}var ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Bo=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:ne(e.y)*t.height};const n=Math.min(t.width,t.height),a=(t.width-n)/2,i=(t.height-n)/2;return{x:a+e.x*n,y:i+e.y*n}},Bv=class{constructor(e,t,r,n){this.annotations=e,this.panelRect=t,this.coordSystem=r,this.measuredBoxes=n,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;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return Vt(e);const{x:s,y:o}=Jr(e.defer,this.panelRect);return Vt({...e,x:e.x+s,y:e.y-o})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=st(r,e.defer.align),{x:a,y:i}=Fv(n,e.defer.offset,this.panelRect);return{x:a,y:i}}resolveRegion(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return Vt(e);const{x:i,y:s}=Jr(e.defer,this.panelRect);return Vt({...e,x:e.x-i,y:e.y-s,width:Math.max(0,e.width+2*i),height:Math.max(0,e.height+2*s)})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=r.xMax-r.xMin,a=r.yMax-r.yMin;return n<=0||a<=0?null:{x:r.xMin,y:r.yMin,width:n,height:a}}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:$v(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:oi(r,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=t.annotation.width,i=n.height/this.panelRect.height,s=Mi(t.annotation.align),o=r.x-s.x*a,c=r.y+(1-s.y)*i;return{xMin:o,xMax:o+a,yMin:c-i,yMax:c}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:li(r)}case"differenceArrow":return oi(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return li(t.annotation.at)}}},Jr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Fv=(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:s}=Jr({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-s}}return{x:e.x+n,y:e.y-a}},$v=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),oi=(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}),Vt=e=>{const t={...e};return delete t.defer,t},Gv=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!Uv(t))return t;const o=new Bv(t,r,n,a),c={...t,shapes:rt(t.shapes,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),images:rt(t.images,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),arrows:rt(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const h=o.resolvePoint(m.start),p=o.resolvePoint(m.end);return h===null||p===null?null:{...m,start:h,end:p}}),textAnnotations:rt(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}}),stickers:rt(t.stickers,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},rt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Uv=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),Hv=800,ci=400,Wv={thin:{strokeWidth:{minValue:1.5,targetValue:2},arrowheadLength:{minValue:7,targetValue:8}},medium:{strokeWidth:{minValue:3,targetValue:4},arrowheadLength:{minValue:14,targetValue:16}},thick:{strokeWidth:{minValue:6,targetValue:8},arrowheadLength:{minValue:28,targetValue:32}}},Kv=e=>Math.max(1,(e-ci)/(Hv-ci)+1),zv=(e,t)=>{const r=Kv(t),n=Wv[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},Rt=Math.PI/4,Qr=1.5,Yv=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,ui=(e,t,r)=>{if(r<=0)return"";const{startX:n,startY:a,endX:i,endY:s}=t,o=e==="start"?n:i,c=e==="start"?a:s,u=e==="start"?Math.atan2(a-s,n-i):Math.atan2(s-a,i-n);return`M ${o} ${c} L ${o-r*Math.cos(u-Rt)} ${c-r*Math.sin(u-Rt)} M ${o} ${c} L ${o-r*Math.cos(u+Rt)} ${c-r*Math.sin(u+Rt)}`},qv=(e,t)=>e==="solid"?null:`${t*Qr} ${t*Qr*2}`,jv=(e,t)=>t?e*Qr:0,Xv=64,Zv=({arrow:e,panelWidth:t,panelHeight:r})=>{const n={startX:e.start.x*t,startY:(1-e.start.y)*r,endX:e.end.x*t,endY:(1-e.end.y)*r};if(n.startX===n.endX&&n.startY===n.endY)return null;const{strokeWidth:a,arrowheadLength:i}=zv(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=Jv(i,s),c=e.startArrowheadStyle==="line-arrow",u=e.endArrowheadStyle==="line-arrow",d=c||u?o*Math.sin(Math.PI/4):0;return{id:e.id,linePath:Yv(n),startArrowheadPath:c?ui("start",n,o):"",endArrowheadPath:u?ui("end",n,o):"",color:e.color,strokeWidth:a,dashArray:qv(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:jv(a,c),arrowheadExtent:d}},Jv=(e,t)=>Math.min(e,t*e/Xv);function Qv(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(m=>m.transformType==="filter"&&m.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let s,o,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")s="color",o=a.options.variableName,c=a.options.value;else if(i!==null)s="y",o=i,c=i;else continue;const u=eb(e,s,o);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d})}return r}function eb(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 Fo=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),tb=0,rb=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:Fo(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:tb})),nb=9,ab=8,ib=2,$o=e=>typeof e=="string"?e:Go(e),Go=e=>e.text!==void 0?e.text:e.content?e.content.map(Go).join(""):"",di={top:"bottom",bottom:"top",right:"left",left:"right"};function sb(e,t,r){return r.type==="polar"?cb(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function en(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 mi(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function ob(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 lb(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 cb(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",[s,o]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[s,di[s],o,di[o]]}function ub(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:h}=d;return pi(m,"pinned-number",h,s(d),i,n,a)}),...r.map(({id:d,at:m,content:h})=>pi(d,"comment",m,$o(h),i,n,a))];o.sort((d,m)=>d.anchorPx.x-m.anchorPx.x||d.anchorPx.y-m.anchorPx.y);const c=[],u=[];for(const d of o){if(!d.inView){c.push(hi(n,d,"top"));continue}const m=hi(n,d,mb(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function pi(e,t,r,n,a,i,s){const o=Bo(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:db(o,i)}}function db(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function mb(e,t,r,n){const a=sb(t.anchorPx,e,r);for(const i of a){const s=en(t.anchorPx,i,t.mini);if(mi(s,e)&&!n.some(o=>lb(s,o)))return i}for(const i of a)if(mi(en(t.anchorPx,i,t.mini),e))return i;return"top"}function hi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:ob(e,en(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var pb=({labelPosition:e,measuredTextWidth:t,labelLineHeight:r,labelPaddingX:n,labelPaddingY:a})=>{const i=t+2*n,s=r+2*a;return{x:e.x-i/2,y:e.y-s/2,width:i,height:s}},hb=(e,t,r,n)=>e!==null?e:t.anchor.layerId!==r.anchor.layerId||!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||n.start===void 0||n.start!==n.end?null:n.start,fb=100,gb=({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,s=!0,o=0;for(;s;){s=!1,o++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const m=u.y+a,h=d.y-a;if(m>h){s=!0,i=!0;const p=(m-h)/2+1;u.y-=p,d.y+=p,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>fb)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}},yb=(e,t)=>{const r=Xi(e),n=bb(t,vb(e),r);if(n===null)return null;const[a]=n;return a===void 0?null:n.length===1?a:{and:n}},vb=e=>{const t=dn(e)?Je(e.data,e.mapping):[],r=un(e),n=r===null?t:[...t,r],a=we(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},bb=(e,t,r)=>{const n=[];for(const a of t){const i=r(e,a);if(i===null)return null;n.push({variable:a,eq:i})}return n},Yn=(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},Sb=(e,t)=>{for(const r of t)if(Yn(e,r.shape))return r;return null},xb=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},Ab=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>Ib(r,t[n])),Ib=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&Tb(e.shape,t.shape)&&Lb(e.tooltip,t.tooltip),Tb=(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},Lb=(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},wb=100,Eb=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:wb}),Vb=(e,t)=>Yn(e,{kind:"circle",center:t.center,radius:t.radius}),Rb=(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&&Cb(e.target,t.target),Cb=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,Db=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Jt(e,n),i=_b(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||Se(s.predicate,e.data).length>0)return!1;const o=be(s.predicate,a);return o(r)?!0:Pp(s.scope)&&i(s.scope).some(o)})},_b=(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 s=Ht(a,t,r),o=[];for(const c of e.data)Ht(a,c,r)===s&&o.push(c);return n.set(a,o),o}},Pt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const s=e.data.size(),o=lt(e);for(let c=0;c<s;c+=1){const u=t+c*r,d=i?kb(u,s):u;if(d<0||d>=s)break;const m=e.data.getAt(d);if(m===null||!n(m,d))continue;const h=o(m);if(h!==null&&!a.some(p=>Fe(h,p)))return{anchor:h,observation:m,observationIndex:d}}return null},Uo=(e,t)=>{const r=ji(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Fe=(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),kb=(e,t)=>(e%t+t)%t,Ho=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=we(e),a=Uo(e,t),i=e.data.getAt(a);if(i===null)return null;const s=j(i),o=h=>l.areDataValuesEqual(j(h),s),c=[t],u=Pt({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=Pt({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=Pt({layer:e,excluding:c,from:0,step:1,accepts:h=>!o(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},Ob=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=lt(r);for(const a of r.data){const i=n(a);if(i===null)continue;const s=Ho({layer:r,at:i,coordSystem:e.coordSystem});if(s!==null&&!t.some(o=>Pb(o,s)))return s}}return null},Pb=(e,t)=>Fe(e.start,t.start)&&Fe(e.end,t.end)||Fe(e.start,t.end)&&Fe(e.end,t.start),Mb=(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}},Nb=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:s})=>{const o=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(o===null)return null;const c=s??e.createLayerMeasurement(t);if(c===null)return null;const u=es(t,r,c);if(u===null)return null;const d=lt(t)(r);return d===null?null:{...o,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Bb=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const s=we(e),o=Uo(e,t),c=e.data.getAt(o);if(c===null)return null;const u=Fb(c),d=n==="main"?u:p=>!u(p)&&l.areDataValuesEqual(p[s]??null,t.anchorValue),m=Pt({layer:e,excluding:[t,r],from:o+a,step:a,accepts:(p,f)=>d(p)&&i(p,f)!==null,cycles:n!=="main"});if(m===null)return null;const h=i(m.observation,m.observationIndex);return h===null?null:{...m,point:h}},Fb=e=>{const t=j(e);return r=>l.areDataValuesEqual(j(r),t)};function $b({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 Gb=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const s=a??n;return e.kind==="grandTotal"?Ub(e,s,r):Hb(e,t,s,r,i)},Ub=(e,t,r)=>({kind:"grandTotal",value:D({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Hb=(e,t,r,n,a)=>{const i=D({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),s=e.items.length>1;return{kind:"perGroup",items:e.items.map(o=>{const c=D({valueFormat:o.valueFormat,locale:r,numberFormat:n}),u=D({valueFormat:o.groupLabelFormat,locale:r,numberFormat:n}),d=Bn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Yb(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:zb(o.observationLabel,d),comparison:Wb(o.comparison,d,i,a)}})}},Wb=(e,t,r,n)=>e===null?null:{direction:Kb(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},Kb=e=>e>0?"up":e<0?"down":"flat",zb=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Yb=(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}},qb=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>jb(i,a,t))},jb=(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 qn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function Xb(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Zb=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,s=(i?cn:Xe)(r.data,r.mapping)(a);return s===null?null:D({valueFormat:qn(e,i?oe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},Jb=12,Qb=4,eS=4,tS=12,rS=4,nS=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:Dr([Ct("value","value",t??"–"),Ct("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:oS(n),segments:Dr([iS(n),sS(n),Ct("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:Dr([aS(a),Ct("label","label",i)])}].filter(s=>s.segments.length>0)},Ct=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},aS=e=>e===null?null:{kind:"swatch",swatch:e,size:12},iS=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},sS=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},oS=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}`}},Dr=e=>e.filter(t=>t!==null),ir=e=>e==="catmull-rom"?Ie.curveCatmullRom:Ie.curveLinear,lS=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},cS=(e,t)=>{const r=ir(t.interpolate),n=(0,Ie.area)().curve(r),a=(0,Ie.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ne(V(c)??0),s=c=>G(c)??0,o=c=>U(c)??C(c)??0;n.y(i).x0(s).x1(o),a.y(i).x(o)}else{const i=c=>C(c)??0,s=c=>ne(P(c)??0),o=c=>ne(k(c)??V(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>C(s)!==null&&V(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},uS=(e,t)=>t!=="connect"?e:e.filter(r=>C(r)!==null&&V(r)!==null),jn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},Wo=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return jn[e.borderRadius??"sm"]},dS=e=>{const t=Wo(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},mS=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Ko=(e,t)=>{const r=G(t),n=U(t),a=P(t),i=k(t)??V(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 s=r,o=n-r;return o<0&&(s+=o,o=-o),{x:s,y:1-i,width:o,height:i-a}},zo=(e,t)=>e==="x"?`${q(t.x)}-${q(t.width)}`:`${q(t.y)}-${q(t.height)}`,pS=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}},hS=e=>{const t=(0,Ie.line)().x(r=>C(r)??0).y(r=>ne(V(r)??0)).curve(ir(e.interpolate));return e.missingValues==="gap"&&t.defined(Yo),t},fS=e=>{const t=(0,Ie.area)().x(r=>C(r)??0).y0(()=>1).y1(r=>ne(V(r)??0)).curve(ir(e.interpolate));return e.missingValues==="gap"&&t.defined(Yo),t},gS=(e,t)=>t!=="connect"?e:e.filter(r=>C(r)!==null&&V(r)!==null),Yo=e=>C(e)!==null&&V(e)!==null,qo=(0,Ie.arc)().cornerRadius(e=>e.cornerRadius??0);qo.digits(8);var yS=200,vS=e=>qo(e)??void 0,bS=(e,t)=>e==="full"?Math.max(0,t)/2:jn[e??"sm"]/yS,jo=(e,t)=>e==="x"?`${q(t.startAngle)}-${q(t.endAngle)}`:e==="y"?`${q(t.innerRadius)}-${q(t.outerRadius)}`:"sweep",SS=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}},xS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],sr=(e,t,r)=>{const n=Xe(e,t);return a=>{const i=j(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},AS=(e,t,r)=>{const n=Xe(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},IS=(e,t,r)=>{const n=Xe(e,t),a=cn(e,t),i=new Map;return s=>{const o=n(s),c=a(s),u=o!==null&&o!==""&&c!==null&&c!==""?`${r}-${o}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},TS=()=>(e,t)=>pt(e)??`default-${t}`;function Xn(e,t,r){return Math.hypot(e*r,t)}function Kt(e,t,r){return e<t?t-e:e>r?e-r:0}function ue(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 s=e[i];if(s===void 0)continue;const o=t(s);if(r&&o===0)return s;o<a&&(n=s,a=o)}return n}function LS(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),s=e.points[i];return s?{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,observationIndex:s.observationIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:Xn(s.x-t.x,s.y-t.y,r)}:null}function wS(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 Xo(e,t){return Zn(e.buckets,t,r=>r.main)}function ES(e,t){return Zn(e.bands,t,r=>r.bandCenter)}function Zo(e,t){return Zn(e.columns,t,r=>r.mainMid)}function Zn(e,t,r){if(e.length===0)return null;let n=0,a=e.length;for(;n<a;){const o=n+a>>>1,c=e[o];c&&r(c)<t?n=o+1:a=o}const i=e[n-1],s=e[n];return i?s&&Math.abs(r(s)-t)<Math.abs(r(i)-t)?s:i:s??null}function VS(e,t){return{group:RS(e),related:kS(e,t)}}function RS(e){switch(e.kind){case"buckets":{const t=e.match.index;return F(t.position)?CS(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return F(t.position)?DS(t.layerId,r,n.pointIndex):_S(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function CS(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 DS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(Jn(e,a));return n}function _S(e,t,r,n){const a=e.find(s=>s.columns.includes(r));if(!a)return[];const i=[];for(const s of a.columns)for(const o of s.rects)o.pointIndex!==n&&i.push(Jn(t,o));return i}function kS(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||PS(r,i,e.match.hit);continue}e.kind==="buckets"&&(F(i.position)||i.kind==="buckets"&&OS(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function OS(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Mt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function PS(e,t,r){switch(t.kind){case"buckets":{const n=Xo(t,Ue(t.mainAxis,r));if(!n)return;const a=Mt(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=ES(t,Ue(t.mainAxis,r));if(!n)return;const a=Mt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(Jn(t.layerId,s));return}case"points":{const n=wS(t,r);if(!n)return;Mt(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 Mt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function Jn(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 Jo(e,t,r){const{columns:n,bands:a}=MS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function MS(e,t){const r=NS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=q(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=q(o.bandCenter);let m=a.get(d);m||(m={bandCenter:o.bandCenter,columns:[]},a.set(d,m)),m.columns.push(u)}u.rects.push(o.entry)}const i=[...n.values()].sort((o,c)=>o.mainMid-c.mainMid),s=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of s)o.columns.sort((c,u)=>c.mainMid-u.mainMid);return{columns:i,bands:s}}function NS(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"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let m=0;for(const h of r){const p=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(p+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(p,f),xMax:Math.max(p,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:h}}),m++}return d}var BS=1e-9;function Qo(e,t,r){const n=FS(e,t);n.sort((i,s)=>i.main-s.main);const a=[];for(const i of n){const s=a[a.length-1];s&&Math.abs(s.main-i.main)<=BS?s.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 FS(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"}),s=r.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,u=o?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,d=F(e.position),m=d?r.getValues(c,{type:"numeric"}):null,h=d?r.getValues(u,{type:"numeric"}):null,p=r.hasVariable(l.GROUP_VARIABLES.group)?r.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,f=[];let g=0;for(const y of r){const v=i[g],x=s[g];if(!l.isDefined(v)||!l.isDefined(x)){g+=1;continue}const T=p?.[g]??null,A=o?x:v;if(d){const w=m?.[g],E=h?.[g];if(!l.isDefined(w)||!l.isDefined(E)){g+=1;continue}const Y=o?E:v,ie=o?x:E;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:Y,y:ie,stackMin:w,stackMax:E,groupKey:T,observation:y}})}else f.push({main:A,entry:{isStacked:d,pointIndex:g,x:v,y:x,groupKey:T,observation:y}});g+=1}return f}function el(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:$S(e,t)}}function $S(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 m of n)if(!r.hasVariable(m))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const m of r){const h=a[d],p=i[d],f=s[d],g=o[d];if(!l.isDefined(h)||!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!pt(m)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:p,yMin:f,yMax:g,observation:m}),d++}return u}function tn(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function GS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:rl(e),delaunay:null,delaunayAspectRatio:null};return tl(r,t),r}function US(e){const t=rl(e).map(r=>{const n=Ut(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 tl(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=nd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function rl(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 s of t){const o=r[i],c=n[i];l.isDefined(o)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:o,y:c,observation:s}),i+=1}return a}function nl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:HS(e)}}function al(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function HS(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 fi(e,t,r){return t.type==="polar"?WS(e,t.bandAxis):KS(e,t.mainAxis,r)}function WS(e,t){switch(e.spatialKind){case"points":return US(e);case"buckets":return Qo(e,"x","polar");case"rects":return t===null?el(e,"polar"):Jo(e,t,"polar");case"cells":return tn(e);case"noop":return tn(e);case"render-hit-test":return nl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function KS(e,t,r){switch(e.spatialKind){case"points":return GS(e,r);case"buckets":return Qo(e,t,"cartesian");case"rects":return Jo(e,t,"cartesian");case"cells":return el(e,"cartesian");case"noop":return tn(e);case"render-hit-test":return nl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function zS(e,t,r){if(e.columns.length===0)return null;const n=Zo(e,Ue(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=F(e.position)?YS(a,t,e.mainAxis):qS(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:il(i,t,r)}}function YS(e,t,r){const n=Zt(r,t);return ue(e,i=>jS(i,r,n),{shortCircuitOnZero:!0})}function qS(e,t,r){return ue(e,a=>il(a,t,r))}function il(e,t,r){return Xn(Kt(t.x,e.xMin,e.xMax),Kt(t.y,e.yMin,e.yMax),r)}function jS(e,t,r){return Kt(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function XS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=gd(e.mainAxis,t),i=Xo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=sl(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:Xn(o.x-t.x,o.y-t.y,r)}}function sl(e,t,r){return ue(e,a=>Math.abs(Zt(r,a)-t))}function ZS(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 JS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=e.mainAxis==="x",s=i?QS(e.columns,n):Zo(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?ex(o,a):tx(o,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:s,distance:0}}function QS(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Gt(t,r.mainMid)):null}function ex(e,t){return ue(e,r=>Kt(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function tx(e,t){return ue(e,r=>as(t,r.xMin,r.xMax)?0:Math.min(Gt(t,r.xMin),Gt(t,r.xMax)),{shortCircuitOnZero:!0})}function rx(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=nx(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=sl(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:0}}function nx(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Gt(r.main,t)):null}function ax(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=Qt(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&as(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 ix(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=hn(t,r),i=ue(e.points,s=>gi(s,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(gi(i,n,a))}}function gi(e,t,r){const n=e.unitX??Ut(e.x,e.y).x,a=e.unitY??Ut(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var sx=.05;function ox({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a}){const i={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const o of e){if(o.kind==="render-hit-test"){const u=dx(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=ux(o,t,r);if(u)return u;continue}const c=cx({layer:o,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<s.distance&&(s.match=c,s.distance=c.match.distance)}}return lx({containment:i,continuous:s})}function lx({containment:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+sx?t.match:e.match:e.match??t.match}function cx({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=XS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=zS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=LS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"enclosure":{const a=ZS(e,t);return a?{kind:"enclosure",match:a}:null}case"noop":return null}}function ux(e,t,r){switch(e.kind){case"enclosure":{const n=ax(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=ix(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=rx(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=JS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function dx(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:al(e.layerId,i)}:null}var J={primary:null,group:[],related:new Map},mx=1,px=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=mx,this.warmStarts=new Map,this.cachedState=J,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=J,this.layerIndexes=e.map(r=>fi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>yi(r,t)),this.nonInteractiveLayerIds=vi(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const s=this.layerIndexes[i],o=this.layerRefs[i];!s||!o||r.set(s.layerId,{index:s,ref:o})}const n=[],a=[];for(const i of e){const s=r.get(i.id),o=yi(i,t);if(s!==void 0&&hx(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(fi(i,t,this.aspectRatio)),a.push(o)}for(const i of this.warmStarts.keys())e.some(s=>s.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=vi(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&tl(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return J;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=ox({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),J;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:s}=VS(r,t);return this.cachedKey=a,this.cachedState={primary:n,group:i,related:s},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 J;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return J;const n=r.byKey.get(t);if(!n)return J;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:al(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=J,this.cachedByKeyId=null,this.cachedByKeyState=J}};function yi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function vi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function hx(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var fx=Math.PI*2;function gx(e,t){const r=Ue(e.mainAxis,t);if(e.mainAxis==="y"){const a=ve(ne(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function yx(e,t,r){const n=e.mainAxis==="y"?V(r.observation):C(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?ll(r):ol(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const s=i/2;return e.mainAxis==="y"?{x:0,y:ve(ne(n+s)),width:"100%",height:ve(i)}:{x:ve(n-s),y:0,width:ve(i),height:"100%"}}function vx(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=G(t.observation),i=U(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=P(t.observation),n=k(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+fx,innerRadius:r,outerRadius:n}}function ol(e){const t=G(e.observation),r=U(e.observation);return t===null||r===null?null:r-t}function ll(e){const t=P(e.observation),r=k(e.observation);return t===null||r===null?null:r-t}function bx(e){return e.observationIndex??e.pointIndex}var or=.5,Sx=.3,xx=.4,Ax=10,Ix=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?Lx(e,t,r,n):wx(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?Rx(e,t,n):e.spatialKind==="cells"?Vx(e,n):e.spatialKind==="points"?Ex(e,n):null,Tx=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},Lx=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:or*n.durationScale,baseline:Cx(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?Dx(e,t.mainAxis,n):{}}),wx=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:or*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?Ox(e,t,r):{}}},Ex=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:or*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?_x(e,t):{}}),Vx=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:Sx*t.durationScale}),Rx=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:or*r.durationScale,axis:t.mainAxis}),Cx=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[oe(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const s=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-s:s},Dx=(e,t,r)=>{const n=sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=Ko(t,i);if(!s)continue;const o=zo(t,s),c=n(i),u=a.get(o);u?u.keys.push(c):a.set(o,{position:t==="x"?s.x:s.y,keys:[c]})}return Qn([...a.values()],r)},_x=(e,t)=>{const r=sr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=kx(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return Qn(n,t)},kx=(e,t)=>{if(t==="main-axis")return C(e);const r=$n(e)??C(e);return r===null?null:t==="value-descending"?-r:r},Ox=(e,t,r)=>{const n=sr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Hn(i),{innerRadius:c,outerRadius:u}=Wn(i);if(s===null||o===null||c===null||u===null)continue;const d=jo(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),h=a.get(d);h?h.keys.push(m):a.set(d,{position:s,keys:[m]})}return Qn([...a.values()],r)},Qn=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((o,c)=>o.position-c.position),a=Math.ceil(n.length/Ax),i=Math.ceil(n.length/a),s=xx*t.durationScale/i;return n.forEach((o,c)=>{const u=Math.floor(c/a)*s;for(const d of o.keys)r[d]=u}),r},Me=["top","right","bottom","left"],bi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},Px={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},Mx={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},Nx=(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]=Mx[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=Fx(t,a),o=$x(t,a,i);return Gx(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:Ux(c,s,o,i)}))},Bx=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),Fx=(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}}},$x=(e,t,r)=>{const{x:n,y:a,width:i,height:s}=e,o=c=>r(c)?t:0;return{top:{start:{x:n+o("topLeft"),y:a},end:{x:n+i-o("topRight"),y:a}},right:{start:{x:n+i,y:a+o("topRight")},end:{x:n+i,y:a+s-o("bottomRight")}},bottom:{start:{x:n+i-o("bottomRight"),y:a+s},end:{x:n+o("bottomLeft"),y:a+s}},left:{start:{x:n,y:a+s-o("bottomLeft")},end:{x:n,y:a+o("topLeft")}}}},Gx=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Me.indexOf(s)+o+Me.length)%Me.length;return Me[c]},n=s=>{const o=r(s,-1);return!t(o)||e[o].lineType!==e[s].lineType||e[o].strokeWidth!==e[s].strokeWidth||e[o].color!==e[s].color},a=Me.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Me],isClosed:!0}]:i.map(s=>{const o=[s];for(let c=r(s,1);t(c)&&!n(c);c=r(c,1))o.push(c);return{firstEdge:s,edges:o,isClosed:!1}})},Ux=(e,t,r,n)=>{const a=(m,h,p)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:h,endAngle:p}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=bi[o];if(!e.isClosed&&n(u)){const m=t[u],h=i(m),p=Hx(m,h);s.push({type:"move",x:p.x,y:p.y}),s.push(a(m,h,m.endAngle))}else s.push({type:"move",x:r[o].start.x,y:r[o].start.y});s.push({type:"line",x:r[o].end.x,y:r[o].end.y});for(const m of e.edges.slice(1)){const h=bi[m];if(n(h)){const p=t[h];s.push(a(p,p.startAngle,p.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=Px[c];if(e.isClosed){if(n(d)){const m=t[d];s.push(a(m,m.startAngle,m.endAngle))}s.push({type:"close"})}else if(n(d)){const m=t[d];s.push(a(m,m.startAngle,i(m)))}return s},Hx=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Wx=/^(?:https?:|mailto:)/i,Kx=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Wx.test(t)},zx=({locale:e,intlOptions:t})=>B(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...$,...t}).format(r)),Yx=({locale:e,intlOptions:t})=>B(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,...$,...t}).format(r)}),zt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return co(e);case"date":return zx(e);case"datetime":return Yx(e);case"day_month":return ho(e);case"decimal":return uo(e);case"duration":return Cn(e);case"integer":return mo(e);case"month":return fo(e);case"month_year":return kn(e);case"percentage":return po(e);case"quarter":return On(e);case"text":return Rn(e);case"time":return vo(e);case"weekly_date_range":return go(e);case"weekly_date_range_with_year":return yo(e);case"year":return Pn(e);case"lookup":return zt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},qx=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:s,colorScheme:o,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:m}=s;if(m===null)return null;const h=c??i,p=jx(u,d);return{header:p===null?Xx({layers:e,coordSystem:t,guides:n,primary:m,locale:h,numberFormat:a}):null,rows:Zx({layers:e,scales:r,guides:n,hover:s,locale:h,numberFormat:a,colorScheme:o}),comment:p}};function jx(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function Xx(e){if(e.coordSystem.type!=="cartesian")return null;const t=qn(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)?zt({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function Zx(e){const t=[],r=e.scales.color??null,n=Qe({colorScheme:e.colorScheme}),a=tA({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=Qx(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...Jx(i,o,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Fi(i.data,i.mapping),u=eA(s,i,r,c),d=Kn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=rA(e.guides,i),h=ot(i),p=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=p?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",T=p&&y!==null?a(y):m,A=h(g.observation),w=A===null?"":d(A,g.observation);t.push({swatchColor:v,geom:i.geom,swatchLineType:x,label:T,value:w,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function Jx(e,t,r,n,a){return e.tooltip.map(i=>{const s=e.mapping[i.aes],o=l.extractVariableName(s),c=K(e.data,s)(t.observation),u=D({valueFormat:mn(e,o),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:i.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",label:i.key??tr(o,r.variableLabels)??"",value:c===null?"":u(c,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${i.aes}`}})}function Qx(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 eA(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,s)=>{a.set(l.getStableKey(i),s)}),e.map((i,s)=>{const o=n(i.observation),c=o===null?null:l.getStableKey(o);return{hit:i,originalIndex:s,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,s)=>i.rank===s.rank?i.originalIndex-s.originalIndex:i.rank-s.rank).map(i=>i.hit)}function tA({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:zt({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=zt({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const s=n.get(l.getStableKey(i));return s===void 0?a(i):s.label??s.format(i)}}function rA(e,t){return tr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function nA(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function aA(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var iA=e=>({edges:{top:$e(e.panelBorder("top")),right:$e(e.panelBorder("right")),bottom:$e(e.panelBorder("bottom")),left:$e(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),sA=(e,t)=>$e(e.gridLine(t)),oA=(e,t)=>{const r=e.tickLine(t);return{...$e(r),length:r.get("length")}},lA=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")}},cA=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},$e=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),uA=e=>e.fontSize*e.lineHeight,dA=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),se=(e,t,r)=>({fontFamily:e.get("fontFamily")??r,fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),mA=(e,t,r)=>se(e.axisLabel(t),r,e.graph.get("fontFamily")),pA=(e,t,r)=>{const n=e.tickLabel(t);return{...se(n,r,e.graph.get("fontFamily")),offset:n.get("offset")}},hA=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...se(a,n,e.graph.get("fontFamily")),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),isTextColorAuthored:a.getSource("textColor")==="authored",...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},fA=(e,t,r)=>{const n=se(e.ruleLabel(t),r,e.graph.get("fontFamily"));return{fontFamily:n.fontFamily,fontSize:n.fontSize,fontWeight:n.fontWeight,lineHeight:n.lineHeight}},gA=(e,t)=>{const r=e.tooltip.box,n=e.graph.get("fontFamily");return{box:{background:r.get("background"),borderColor:r.get("borderColor"),borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock"),shadow:r.get("shadow")},heading:se(e.tooltip.heading,t,n),label:se(e.tooltip.label,t,n),value:se(e.tooltip.value,t,n),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},lr={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},yA={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}}},vA=Object.keys(lr),bA=e=>Object.hasOwn(lr,e),ht=(e,t)=>{for(const r of vA){const n=SA(e,r,t);if(n)return n}return null},ft=(e,t)=>e[lr[t]],ea=(e,t,r)=>({...e,[lr[t]]:r}),cl=(e,t)=>{const r=ft(e,t.kind);return ea(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},SA=(e,t,r)=>{const n=ft(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},ta=["sticker","pinnedNumber","comment","image"],xA=e=>ta.includes(e),ra=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?IA(e.annotation.at):null;default:return null}},ul=(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),dl=(e,t,r=AA)=>{const n=r(t);for(const a of ta){const i=ft(e,a),s=i.findIndex(c=>{const u=ra({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return ul(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},AA=e=>({...e,anchorValue:_r(e.anchorValue),...e.groupValue!==void 0&&{groupValue:_r(e.groupValue)},...e.crossValue!==void 0&&{crossValue:_r(e.crossValue)}}),_r=e=>l.readISOInstant(e)??e,IA=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function TA(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var LA=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&na(r.predicate,t.predicate))??null,na=(e,t)=>"and"in e?"and"in t&&Si(e.and,t.and):"or"in e?"or"in t&&Si(e.or,t.or):"not"in e?"not"in t&&na(e.not,t.not):wA(t)&&e.variable===t.variable&&EA(e,t),wA=e=>"variable"in e,Si=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&na(r,a)}),EA=(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)),VA={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},RA=e=>Object.hasOwn(VA,e);function CA(e){return{type:"mapping",mapping:e}}var cr=(e,t)=>"and"in e?"and"in t&&Ai(e.and,t.and):"or"in e?"or"in t&&Ai(e.or,t.or):"not"in e?"not"in t&&cr(e.not,t.not):DA(t)&&e.variable===t.variable&&_A(e,t),DA=e=>"variable"in e,Ai=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&cr(r,a)}),_A=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ii(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&&Ii(e.range,t.range),Ii=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ml=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)))),pl=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),hl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function fl(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(kA),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function kA(e){return e.scaleType==="palette"?OA(e):e}function OA(e){return{...e,palette:PA(e.palette),overrides:MA(e.overrides)}}function PA(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function MA(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var ur=(e,t)=>{const r=aa(e,t);return r===-1?void 0:e[r]},aa=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&dr(n,t))return r}return-1},dr=(e,t)=>NA(e.select,t.select)&&e.when?.state===t.when?.state&&BA(e.when?.where,t.when?.where),gl=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>FA(e[r],t[r])),Ae=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),ia=e=>e.select.target==="geom",gt=(e,t)=>{const r=ur(e,t);if(!(r===void 0||!ia(r)))return r.declarations},NA=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},BA=(e,t)=>e===void 0||t===void 0?e===t:cr(e,t),FA=(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 S(e){return{id:e.id??N(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function qe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>qe(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=>qe(e[a],t[a]))}return!1}var sa=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=S({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=ht(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:L(e,{annotations:cl(e.annotations,t)}),revert:new oa({kind:r,annotation:a,index:n},this.metadata)}}},$A={type:"remove-annotation",deserialize:(e,t)=>new sa(e,t)},oa=class yl{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??N()},...t.index!==void 0&&{index:t.index}},this.metadata=S({...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(!bA(r)||ht(t.annotations,n.id))return null;const i=UA(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:cl(t.annotations,i),o=ft(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:L(t,{annotations:ea(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new sa({id:n.id},this.metadata):new yl({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},GA={type:"add-annotation",deserialize:(e,t)=>new oa({kind:e.kind,annotation:e.annotation,index:e.index},t)},UA=(e,t)=>{const r=ra(t);return r===null?null:dl(e,r)},HA=(e,t)=>{const r=la(e);return r===null?null:vl(r.points,t)},WA=e=>la(e)!==null,KA=(e,t)=>{const r=la(e);if(r===null)return null;const n=vl(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},la=e=>{const t=YA[e.kind];return t===null?null:t(e.annotation)},Ti=(e,t)=>e.anchorType!=="panel"?null:{points:[rn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Li=(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})},zA=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[rn(e,e.offset),rn(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}})},YA={text:e=>Ti(e.at,t=>({at:t})),sticker:e=>Ti(e.at,t=>({at:t})),shape:e=>Li(e.region,t=>({region:t})),image:e=>Li(e.region,t=>({region:t})),arrow:e=>zA(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},rn=(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)},vl=(e,t)=>({x:wi(e.map(r=>r.x),t.x),y:wi(e.map(r=>r.y),t.y)}),wi=(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,Ge.default)(t,r,n)},bl=(e,t,r)=>{const n=t.annotation;if(!XA(n,r))return null;const a=ft(e.annotations,t.kind),i=qA(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:L(e,{annotations:ea(e.annotations,t.kind,s)}),inverse:jA(n,r)}},qA=(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)))},jA=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},XA=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),ca=class Sl{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=S({...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=ht(t.annotations,n);if(i===null||i.kind!==r)return null;const s=bl(t,i,a);return s===null?null:{spec:s.spec,revert:new Sl({kind:r,id:n,patch:s.inverse},this.metadata)}}},ZA={type:"update-annotation",deserialize:(e,t)=>new ca(e,t)},xl=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=S({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=ht(e.annotations,this.params.id);if(t===null)return null;const r=KA(t,this.params.translation);if(r===null)return null;const n=bl(e,t,r);return n===null?null:{spec:n.spec,revert:new ca({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},JA={type:"move-annotation",deserialize:(e,t)=>new xl(e,t)},QA=["cartesian","polar","flip"],H=new rr,Al=e=>H.has(e)?H.get(e):null,Il=new l.TransformRegistry,eI=new ro(Il),mr=e=>{const t=e.transforms.every(r=>Il.has(r.transformType));return e.transforms.length===0||!t?e.data:eI.compile({data:e.data,transforms:e.transforms})};function ua(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 yt(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:L(e,{scales:Wi(e.scales,n,r)})}function bt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function nn(e,t,r){const n=En(Ws(no(H),{data:mr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Ks(n):n}var Tl=class Ll{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=S({...r,description:mI(t)})}apply(t){const r="previous"in this.params?this.params.previous:pI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Ll({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},tI={type:"set-chart-type",deserialize:(e,t)=>new Tl(e,t)},wl={type:"sum"},rI={type:"identity"},nI=["bar","line","area","point","tile"],da="tile",aI=["y","color"],iI=Object.values(l.LAYER_LABEL_VARIABLES),sI={coordType:"cartesian",geom:da,position:"identity"},St=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),oI=e=>{const t=e.layers.filter(te),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const s=Vl(t);if(s!==null)return{coordType:"cartesian",comboType:s}}if(!t.every(s=>s.geom===r.geom&&s.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}},lI=e=>{if(!e)return!1;const t=e.layers.filter(te);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:Rl(e,r)?Cl(e,r).length>=1:pr(e,e.data.groupVariableNamesByType().numeric).length>=2},cI=e=>e?Ml(e,sI)!==null:!1,uI=e=>El(e)?.at(-1)?.id??null,El=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(te);return Vl(t)===null?null:t},Vl=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 dI(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)},dI=e=>e.some(t=>t.yScaleType==="secondary"||Yt(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,mI=e=>"previous"in e?"Restore the previous chart type":St(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,pI=(e,t)=>{const r=Ml(e,t);if(r===null)return null;const n=St(t)?fI(r,t):hI(r,t,e);return n===null||r===e?n:{...n,scales:VI({...e,...n},n.scales)}},hI=(e,t,r)=>{if(St(t)||!RI(t))return null;const n={...e,layers:Hl(e.layers)},a=_I(n.layers.filter(te),t),i=Kl(n.coords,t),s=Ol(n,t),o=Ul({...n,mapping:s},t,a,s!==n.mapping);return{coords:i,layers:o,scales:ua(zl(r,o,i.coordType),o),mapping:s}},fI=(e,t)=>{const r=vI(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=kI(r.filter(te),t.comboType),i=Kl(n.coords,t),s=Ol(n,t),o=Ul({...n,mapping:s},t,a,s!==n.mapping),c=gI(e)?o:yI(o);return{coords:i,layers:c,scales:ua(zl(e,c,i.coordType),c),mapping:s}},gI=e=>El(e)!==null,yI=e=>{const t=e.filter(te).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},vI=(e,t)=>{const r=e.layers.filter(te);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:Rl(e,n)?bI(e,n):SI(e,n,t)},Rl=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},bI=(e,t)=>{const[r]=Cl(e,t);if(r===void 0)return null;const n=Ce(H,e.mapping,e.coords.coordType,{type:"layer",id:Dl(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:wl,...kl(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},pr=(e,t)=>{const r=xt(e);return t.filter(n=>n!==r)},Cl=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return pr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},xt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),SI=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=pr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const s=l.readFoldKeepVariables(e.data,xt(e)),o=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=xI(t,Ei(a.slice(0,-1),s,o)),u=Ce(H,e.mapping,e.coords.coordType,{type:"layer",id:Dl(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...Ei([i],s,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Dl=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},Ei=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?kl(n,r):_l(e,t)},_l=(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})]}),kl=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),xI=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Ol=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Pl(t)?"":xt(e);return n===r?e.mapping:{...e.mapping,x:n}},Pl=e=>e.coordType==="polar"&&e.theta==="y",AI=e=>!St(e)&&e.geom===da,II=e=>e.layers.filter(te).some(t=>t.geom===da),Ml=(e,t)=>{const r=AI(t);return r===II(e)?e:r?TI({...e,layers:Hl(e.layers)}):LI(e)??e},TI=e=>{const t=Bl(e);if(t===null)return null;const r=wI(e,t)===null?EI(e,t):Fl(e,t);return r===null?null:Nl(e,t,r)},LI=e=>{const t=Bl(e);if(t===null)return null;const r=Fl(e,t);return r===null?null:Nl(e,t,r)},Nl=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Bl=e=>{const t=e.layers.filter(te);return t.length===1?t[0]??null:null},Fl=(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:$l(t)}},$l=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}},wI=(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===xt(e))return null;const i=mr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},EI=(e,t)=>{const r=pr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,xt(e)),a=_l(r,n),i=$l(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},VI=(e,t)=>aI.reduce((r,n)=>{const a=nn(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Ze(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),RI=e=>QA.includes(e.coordType)&&Gl(e.geom)&&CI(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),CI=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=H.get(e);return n.includes(t)&&a.includes(r)},Gl=e=>nI.includes(e),te=e=>Gl(e.geom)&&!DI(e.stat),DI=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},_I=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},kI=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,s)=>n===null||s===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:OI(i,t,n)}]);return new Map(a)},OI=(e,t,r)=>e.geom!=="bar"||Yt(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Ul=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Us(H,Ze(e.layers,i=>{const s=r.get(i.id);if(s===void 0)return i;const o=PI(i.stat,e.coords,t);return a||n||i.geom!==s.geom||i.position!==s.position||o!==i.stat?NI(e,{...i,stat:o},t.coordType,s):i}))},PI=(e,t,r)=>Pl(r)?e.type==="identity"?wl:e:MI(t)&&e.type==="sum"?rI:e,MI=e=>e.coordType==="polar"&&e.params.theta==="y",NI=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...Ce(H,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:o},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Hl=e=>{const t=e.filter(te);if(t.length<2||!e.some(Yt))return e;const[r]=t;return e.flatMap(n=>n===r?[BI(n)]:Yt(n)?[]:[n])},Yt=e=>Wl(e)!==null,Wl=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:iI.includes(t.options.variableName)?t:null},BI=e=>{const t=Wl(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)}},Kl=(e,t)=>{const r=FI(e,t);return(0,Ft.default)(r,e)?e:r},FI=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Wr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Ot;return Wr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},zl=(e,t,r)=>{const n=Ur(H,t),a=Ur(H,e.layers),i=e.coords.coordType==="polar";return Ze(e.scales,s=>{const o=$I(s,n,a),c=GI(o,n,a);return HI(c,r,i)})},$I=(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 Kr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Kr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=UI(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},GI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},UI=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,HI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},Yl=class ql{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=S({...r,description:KI(t)})}apply(t){const r="previous"in this.params?this.params.previous:zI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new ql({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},WI={type:"set-mapping",deserialize:(e,t)=>new Yl(e,t)},jl=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Xl=e=>e===""?null:e,KI=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Xl(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},zI=(e,{aesthetic:t,variable:r})=>{if(!RA(t))return null;const n=Xl(r),a=qI(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:XI(e,t,a,n),layers:YI(e.layers,a)}},YI=(e,t)=>Ze(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&Al(r.geom)===null)return r;const a=Gs(H,r.geom,r.position,n);return(0,Ft.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),qI=(e,t,r)=>r===null?jI(e,t):jl(e,t)===r?e:{...e,[t]:r},jI=(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},XI=(e,t,r,n)=>{if(!us(t))return e.scales;let a=e.scales;for(const i of ZI(e,t))a=QI(e,a,i,r,n);return a},ZI=(e,t)=>t==="y"&&JI(e.layers)?["y","ySecondary"]:[t],JI=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},QI=(e,t,r,n,a)=>{const i=t.find(o=>o.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,nn(e,r,n)];if(a===null&&!Ve(r)||a!==null&&!mr(e).hasVariable(a))return t;const s=nn(e,r,n);return eT(i,s)?t:Ze(t,o=>o.scaledAesthetic===r?s:o)},eT=(e,t)=>e.scaleType===t.scaleType||Vi(e)&&Vi(t),Vi=e=>e.scaleType==="discrete"||e.scaleType==="palette",Zl=class Jl{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=S({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:R(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new Jl({textScale:r},this.metadata)}}},tT={type:"set-appearance-text-scale",deserialize:(e,t)=>new Zl(e,t)},ma=e=>e==="both"?["x","y"]:[e],Ql=e=>e==="both"?"the":`${e} axis`;function pa(e,t){return hr(e)?e[t]:e}function rT(e,t){return e.config.axes[t]??{}}function nT(e,t,r){if(t!=="ySecondary")return R(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=ec(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,L(e,{config:L(e.config,{axes:i})})}function hr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function ec(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],s=a in t?aT(i,t[a]):i;s!==i&&(n=!0),s!==void 0&&(r[a]=s)}return n?Object.keys(r).length>0?r:void 0:e}function aT(e,t){return l.isPlainObject(t)?ec(l.isPlainObject(e)?e:void 0,t):t}var tc=class rc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=S({...r,description:`Set ${t.axis} axis label to ${sT(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=rT(t,r).label;if(a===n)return null;const i=nT(t,r,{label:n});return i===t?null:{spec:i,revert:new rc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},iT={type:"set-axis-label",deserialize:(e,t)=>new tc(e,t)};function sT(e){return e===void 0?"(inherited)":e??"(none)"}var nc=class ac{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=S({...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:R(t,{config:{axes:{[r]:{position:n}}}}),revert:new ac({axis:r,position:a},this.metadata)}}},oT={type:"set-axis-position",deserialize:(e,t)=>new nc(e,t)},ic=class sc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=S({...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:R(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new sc({axis:r,tickMode:a},this.metadata)}}},lT={type:"set-axis-tick-mode",deserialize:(e,t)=>new ic(e,t)},oc=class lc{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=S({...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:R(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new lc({axis:r,isVisible:a},this.metadata)}}},cT={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new oc(e,t)},cc=class uc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=S({...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:R(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new uc({axis:r,isVisible:a},this.metadata)}}},uT={type:"set-axis-visibility",deserialize:(e,t)=>new cc(e,t)},dc=class mc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=S({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:R(t,{config:{content:{caption:this.params.caption}}}),revert:new mc({caption:r},this.metadata)}}},dT={type:"set-content-caption",deserialize:(e,t)=>new dc(e,t)},pc=class hc{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=S({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(qe(r,this.params.source))return null;const n=L(t.config.content,{source:this.params.source});return{spec:L(t,{config:L(t.config,{content:n})}),revert:new hc({source:r},this.metadata)}}},mT={type:"set-content-source",deserialize:(e,t)=>new pc(e,t)},fc=class gc{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=S({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:R(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new gc({subtitle:r},this.metadata)}}},pT={type:"set-content-subtitle",deserialize:(e,t)=>new fc(e,t)},yc=class vc{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=S({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:R(t,{config:{content:{title:this.params.title}}}),revert:new vc({title:r},this.metadata)}}},hT={type:"set-content-title",deserialize:(e,t)=>new yc(e,t)},de=class Nt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=S({...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],s=aa(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new Nt({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!dr(y,n));return{spec:kr(t,r,g),revert:f}}if(o!==void 0){if(gl(o.declarations,c))return null;const f={...o,declarations:c},g=new Nt({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:kr(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},h=[...i.slice(0,d),m,...i.slice(d)],p=new Nt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:kr(t,r,h),revert:p}}},fT=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."})},gT={type:"set-style-rule",deserialize:(e,t)=>(fT(e),new de(e,t))},kr=(e,t,r)=>L(e,{styles:{...e.styles,[t]:r}}),yT="dashed",vT=1,bc=(e,t,r,n)=>{const a=bT(t,r),i=xT(e,a,n);let s=e,o=!1;for(const c of a){const u=IT(s,c,n,AT(n,ST(r,c)));u!==null&&(s=u,o=!0)}return o?{spec:s,previous:i}:null},bT=(e,t)=>e==="both"&&!hr(t)?[void 0]:ma(e),ST=(e,t)=>t===void 0?hr(e)?e.x:e:pa(e,t),xT=(e,t,r)=>t.length===1?Or(e,t[0],r):{x:Or(e,"x",r),y:Or(e,"y",r)},Or=(e,t,r)=>Sc(e.styles.overrides,t)?.[r]??null,AT=(e,t)=>t===null||e==="lineType"&&t===yT||e==="strokeWidth"&&t===vT?null:t,IT=(e,t,r,n)=>{const a=Sc(e.styles.overrides,t);return(a?.[r]??null)===n?null:new de({list:"overrides",rule:wT(t,LT(a,r,n))}).apply(e)?.spec??null},TT=e=>e.select.target==="gridLine",Sc=(e,t)=>{const r=ur(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!TT(r)))return r.declarations},LT=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},wT=(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),xc=class Ac{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=S({...r,description:`Set ${Ql(t.axis)} grid line style to ${VT(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=bc(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new Ac({axis:r,lineStyle:a.previous},this.metadata)}}},ET={type:"set-grid-line-style",deserialize:(e,t)=>new xc(e,t)},VT=({axis:e,lineStyle:t})=>{const r=ma(e).map(n=>pa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},RT={type:"set-grid-line-width",deserialize:(e,t)=>new Ic(e,t)},Ic=class Tc{constructor(t,r={}){this.type="set-grid-line-width";const n=CT(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=S({...r,description:`Set ${Ql(t.axis)} grid line width to ${DT(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=bc(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new Tc({axis:r,lineWidth:a.previous},this.metadata)}}},CT=e=>hr(e)?{x:Pr(e.x),y:Pr(e.y)}:Pr(e),Pr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),DT=(e,t)=>{const r=ma(e).map(n=>pa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Lc=class wc{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=S({...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:R(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new wc({axis:r,isVisible:a},this.metadata)}}},_T={type:"set-grid-visibility",deserialize:(e,t)=>new Lc(e,t)},Ec=class Vc{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:R(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Vc({compareWith:r},this.metadata)}}},kT={type:"set-headline-compare-with",deserialize:(e,t)=>new Ec(e,t)},Rc=class Cc{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:R(t,{config:{headline:{position:this.params.position}}}),revert:new Cc({position:r},this.metadata)}}},OT={type:"set-headline-position",deserialize:(e,t)=>new Rc(e,t)},Dc=class _c{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:R(t,{config:{headline:{show:this.params.show}}}),revert:new _c({show:r},this.metadata)}}},PT={type:"set-headline-show",deserialize:(e,t)=>new Dc(e,t)},kc=class Oc{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:R(t,{config:{headline:{size:this.params.size}}}),revert:new Oc({size:r},this.metadata)}}},MT={type:"set-headline-size",deserialize:(e,t)=>new kc(e,t)},NT={type:"set-highlight-dim-style",deserialize:(e,t)=>new Pc(e,t)},Pc=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=S({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Mc(e)===this.params.dimStyle)return null;const t=new de({list:"overrides",rule:FT(this.params.dimStyle)},this.metadata).apply(e);return t||null}},BT={select:{target:"geom"},when:{state:"dimmed"}},Mc=e=>{const t=ur(e.styles.overrides,BT);return(t!==void 0&&ia(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},FT=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Nc=class Bc{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:R(t,{config:{legend:{align:this.params.align}}}),revert:new Bc({align:r},this.metadata)}}},$T={type:"set-legend-align",deserialize:(e,t)=>new Nc(e,t)},Fc=class $c{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:R(t,{config:{legend:{display:this.params.display}}}),revert:new $c({display:r},this.metadata)}}},GT={type:"set-legend-display",deserialize:(e,t)=>new Fc(e,t)},Gc=class Uc{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:R(t,{config:{legend:{position:this.params.position}}}),revert:new Uc({position:r},this.metadata)}}},UT={type:"set-legend-position",deserialize:(e,t)=>new Gc(e,t)},Hc=class Wc{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:R(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Wc({abbreviation:r},this.metadata)}}},HT={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Hc(e,t)},Kc=class zc{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:R(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new zc({decimals:r},this.metadata)}}},WT={type:"set-number-format-decimals",deserialize:(e,t)=>new Kc(e,t)},Yc=class qc{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=S({...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=zT(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:R(t,{config:{content:{[a]:n}}}),revert:new qc({slot:r,isVisible:i},this.metadata)}}},KT={type:"toggle-content-visibility",deserialize:(e,t)=>new Yc(e,t)},Ri={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function zT(e){return Object.hasOwn(Ri,e)?Ri[e]:void 0}var jc=class Xc{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=S({...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(qe(i.xLimits,a.xLimits)&&qe(i.yLimits,a.yLimits))return null;const s={};r!==void 0&&(s.xLimits=a.xLimits),n!==void 0&&(s.yLimits=a.yLimits);const o=new Xc(s,this.metadata);return{spec:L(t,{coords:qT(t.coords,i)}),revert:o}}},YT={type:"set-coord-limits",deserialize:(e,t)=>new jc(e,t)};function qT(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 Zc=class Jc{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Ge.default)(t.innerRadius,0,1)},this.metadata=S({...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:L(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Jc({innerRadius:n},this.metadata)}}},jT={type:"set-polar-inner-radius",deserialize:(e,t)=>new Zc(e,t)},XT={type:"set-polar-start-angle",deserialize:(e,t)=>new Qc(e,t)},Qc=class eu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:Ci(t.startAngle)},this.metadata=S({...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 Ci(n)===this.params.startAngle?null:{spec:L(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new eu({startAngle:n},this.metadata)}}},Mr=360,Ci=e=>(e%Mr+Mr)%Mr,ha=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=S({...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 fa({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:L(e,{highlights:n}),revert:a}}},ZT={type:"remove-highlight",deserialize:(e,t)=>new ha(e,t)},fa=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??N(),scope:e.scope??"data-point"},this.metadata=S({...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 s=new ha({id:r},this.metadata),o={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:L(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},JT={type:"add-highlight",deserialize:(e,t)=>new fa(e,t)};function ga(e,t){return{...e,params:{...e.params,...t}}}function fr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function ya(e,t){return L(e,{layers:[...e.layers,t]})}function z(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:L(e,{layers:Wi(e.layers,n,r)})}function gr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:L(e,{layers:e.layers.filter((n,a)=>a!==r)})}var va=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=S({...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=gr(e,this.params.layerId);return n===e?null:{spec:n,revert:new ba({layer:r,index:t},this.metadata)}}},QT={type:"remove-layer",deserialize:(e,t)=>new va(e,t)},ba=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??N()},...e.index!==void 0&&{index:e.index}},this.metadata=S({...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:L(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new va({layerId:t.id},this.metadata)}}},eL={type:"add-layer",deserialize:(e,t)=>new ba(e,t)},tu=class ru{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=S({...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(!X(_(t.layers,r),"bar"))return null;const a=Ae("bar",r),i=gt(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:rL(i,n)}}).apply(t);if(!o)return null;const c=new ru({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},tL={type:"set-bar-border-radius",deserialize:(e,t)=>new tu(e,t)},rL=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},nL={type:"set-bar-width",deserialize:(e,t)=>new au(e,t)},nu=.05,aL=1,au=class iu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Ge.default)(t.width,nu,1);this.params={...t,width:n},this.metadata=S({...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?_(t.layers,this.params.layerId):le(t.layers,"bar");if(!X(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:z(t,r.id,ga(r,{width:this.params.width})),revert:new iu({layerId:r.id,width:n},this.metadata)}}},su=class ou{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=S({...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?_(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:z(t,r.id,fr(r,{format:this.params.format})),revert:new ou({layerId:r.id,format:n},this.metadata)}}},iL={type:"set-data-labels-format",deserialize:(e,t)=>new su(e,t)},lu=class cu{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=S({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):le(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:z(t,r.id,{...r,position:this.params.position}),revert:new cu({layerId:r.id,position:n},this.metadata)}}},sL={type:"set-layer-position",deserialize:(e,t)=>new lu(e,t)},uu=class du{constructor(t,r={}){this.type="set-layer-stat";const n=$s(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=S({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return lL(n,this.params.stat)?null:{spec:z(t,r.id,{...r,stat:this.params.stat}),revert:new du({layerId:r.id,stat:n},this.metadata)}}},oL={type:"set-layer-stat",deserialize:(e,t)=>new uu(e,t)},lL=(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},mu=class pu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=S({...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?_(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=z(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:L(a,{scales:ua(a.scales,a.layers)}),revert:new pu({layerId:r.id,yScaleType:n},this.metadata)}}},cL={type:"set-layer-y-scale-type",deserialize:(e,t)=>new mu(e,t)},hu=class fu{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=S({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):le(t.layers,"line","area");if(!X(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:z(t,r.id,ga(r,{interpolate:this.params.interpolate})),revert:new fu({layerId:r.id,interpolate:n},this.metadata)}}},uL={type:"set-line-interpolation",deserialize:(e,t)=>new hu(e,t)},gu=class yu{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=S({...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?_(t.layers,this.params.layerId):le(t.layers,"line","area");if(!X(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:z(t,r.id,ga(r,{missingValues:this.params.missingValues})),revert:new yu({layerId:r.id,missingValues:n},this.metadata)}}},dL={type:"set-line-missing-values",deserialize:(e,t)=>new gu(e,t)},vu=class bu{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=S({...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=_(t.layers,r);if(!X(a,"line","area"))return null;const i=gt(t.styles.overrides,Ae(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=pL(i,n),c=new de({list:"overrides",rule:a.geom==="area"?{...Ae("area",r),declarations:o}:{...Ae("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new bu({layerId:r,lineWidth:s},this.metadata)}:null}},mL={type:"set-line-width",deserialize:(e,t)=>new vu(e,t)},pL=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},Su=class xu{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=S({...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(!X(_(t.layers,r),"point"))return null;const a=Ae("point",r),i=gt(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:fL(i,n)}}).apply(t);return o?{spec:o.spec,revert:new xu({layerId:r,size:s},this.metadata)}:null}},hL={type:"set-point-size",deserialize:(e,t)=>new Su(e,t)},fL=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},Au=class Iu{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=S({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):le(t.layers,"rule");if(!X(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(([s])=>s!=="label")):{...r.params,label:a};return{spec:z(t,r.id,{...r,params:i}),revert:new Iu({layerId:r.id,label:n??null},this.metadata)}}},gL={type:"set-rule-label",deserialize:(e,t)=>new Au(e,t)},Tu=class Lu{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=S({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):le(t.layers,"rule");if(!X(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:z(t,r.id,{...r,mapping:i}),revert:new Lu({layerId:r.id,value:a},this.metadata)}}},yL={type:"set-rule-value",deserialize:(e,t)=>new Tu(e,t)},vL={type:"set-stat-line",deserialize:(e,t)=>new wu(e,t)},wu=class Eu{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=S({...r,description:LL(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=SL(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&&TL(r.layer,n))return null;const a=new Eu({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:z(t,r.layer.id,n),revert:a};const i=r===void 0?t:gr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:ya(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"?xL(this.params):AL(t,this.params);if(n===null)return null;const a=Ce(H,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},bL="linear",SL=e=>{const t=pl(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=hl(e.layers);if(r!==void 0)return{line:"average",layer:r}},xL=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??bL}),interactive:!1}),AL=(e,{group:t,label:r})=>{const n=IL(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),s=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:s?[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})},IL=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),TL=(e,t)=>(0,je.isEqual)({...e,id:""},{...t,id:""}),LL=e=>e==="none"?"Hide stat line":`Show ${e} line`,Vu=class Ru{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=S({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:z(t,r.id,fr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new Ru({layerId:r.id,showCategoryLabels:n},this.metadata)}}},wL={type:"toggle-category-labels",deserialize:(e,t)=>new Vu(e,t)},Cu=class Du{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=S({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:z(t,r.id,fr(r,{showDataLabels:this.params.showDataLabels})),revert:new Du({layerId:r.id,showDataLabels:n},this.metadata)}}},EL={type:"toggle-data-labels",deserialize:(e,t)=>new Cu(e,t)},VL={type:"toggle-goal-line",deserialize:(e,t)=>new _u(e,t)},_u=class an{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=S({...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=ml(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=gr(t,r.id);return a===t?null:{spec:a,revert:new an({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:ya(t,n),revert:new an({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ce(H,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??RL}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},RL=0,CL={type:"toggle-line-fill",deserialize:(e,t)=>new ku(e,t)},ku=class Ou{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=S({...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(!X(_(t.layers,r),"line"))return null;const i=Ae("line",r),s=gt(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new de({list:"overrides",rule:{...i,declarations:_L(s,n?a??DL:null)}}).apply(t);if(!u)return null;const d=new Ou({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},DL=.2,_L=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},kL={type:"toggle-line-points",deserialize:(e,t)=>new Pu(e,t)},Pu=class sn{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=S({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):le(t.layers,"line","area");return X(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:ya(t,this.params.removedLayer??Ce(H,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new sn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:gr(t,n.id),revert:new sn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:bn(n,[r]))}},Mu=class Nu{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=S({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?_(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:z(t,r.id,fr(r,{showStackTotals:this.params.showStackTotals})),revert:new Nu({layerId:r.id,showStackTotals:n},this.metadata)}}},OL={type:"toggle-stack-totals",deserialize:(e,t)=>new Mu(e,t)},Bu=class Fu{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=S({...r,description:`Set ${bt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=yt(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 s={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},o=vt(t,this.params.scaledAesthetic,s),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:o,revert:new Fu(c,this.metadata)}}},PL={type:"set-scale-domain",deserialize:(e,t)=>new Bu(e,t)},$u=class Gu{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=S({...r,description:`Set ${bt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=yt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||qe(r.palette,this.params.palette)?null:{spec:vt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Gu({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},ML={type:"set-scale-palette",deserialize:(e,t)=>new $u(e,t)},Uu=class Hu{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=S({...r,description:`Set ${bt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=yt(t,this.params.scaledAesthetic);if(!r||!BL(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 Hu({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},NL={type:"set-scale-reverse",deserialize:(e,t)=>new Uu(e,t)};function BL(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Wu=class Ku{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=S({...r,description:`Set ${bt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=yt(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 Ku({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},FL={type:"set-scale-transform",deserialize:(e,t)=>new Wu(e,t)},zu=class Yu{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=S({...r,description:`Set ${bt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=yt(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 Yu({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},$L={type:"set-scale-zero",deserialize:(e,t)=>new zu(e,t)},qu=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}},b=new qu;b.register(tI);b.register(WI);b.register(eL);b.register(QT);b.register(iL);b.register(sL);b.register(oL);b.register(cL);b.register(uL);b.register(mL);b.register(tL);b.register(nL);b.register(hL);b.register(dL);b.register(gL);b.register(yL);b.register(vL);b.register(wL);b.register(EL);b.register(VL);b.register(CL);b.register(kL);b.register(OL);b.register(PL);b.register(ML);b.register(NL);b.register(FL);b.register($L);b.register(tT);b.register(iT);b.register(lT);b.register(oT);b.register(cT);b.register(uT);b.register(dT);b.register(mT);b.register(pT);b.register(hT);b.register(ET);b.register(RT);b.register(_T);b.register(kT);b.register(OT);b.register(PT);b.register(MT);b.register(NT);b.register($T);b.register(GT);b.register(UT);b.register(HT);b.register(WT);b.register(KT);b.register(JT);b.register(ZT);b.register(gT);b.register(GA);b.register($A);b.register(ZA);b.register(JA);b.register(YT);b.register(jT);b.register(XT);var ju=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,s=e.apply(t);if(!s)return a||(this.hasOpenRun=!1),i(t,null);const o=r?.({spec:s.spec,command:e})??null,c=o?o.adopted:s.spec;return c?(this.push(e,c,s.revert,a),i(c,o?.value??null)):(a||(this.hasOpenRun=!1),i(t,o?.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:Di(this.undoStack),redoStack:Di(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],s=this.hasOpenRun&&i!==void 0&&UL(i.command,e);if(n&&s){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)}}},GL=Object.freeze([]),UL=(e,t)=>{if(e.type!==t.type||e.target.kind!==t.target.kind)return!1;const r=e.target,n=t.target;for(const a of new Set([...Object.keys(r),...Object.keys(n)]))if(!Object.is(r[a],n[a]))return!1;return!0},Di=e=>e.length===0?GL:e.map(t=>t.command.metadata),HL=(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&&dr(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"observation":return t.kind==="observation"&&e.layerId===t.layerId&&e.index===t.index;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}`})}},WL=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}},KL=class{constructor(e){this.compiler=e,this.history=new ju,this.current=null,this.last=null,this.hostInput=null,this.run=new WL(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;if(this.hostInput=e.input,!r&&!n&&!a)return null;let i=null;r?this.run.close():i=this.closeAndConvert();const s=this.last,o=s&&!r?s.input:e.input;this.last={input:o,data:e.data,customPalettes:e.customPalettes};const c=this.current,u=r||a||!c?this.absorb(this.compiler.compile({input:o,data:e.data,customPalettes:e.customPalettes})):this.absorb(this.compiler.recompile({spec:c.spec,data:e.data}));return r&&u.ok&&this.history.clear(),{result:u,inputChanged:r,...i&&{sealedInput:i.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:s}=this;if(!a||!i)return n;const o=s.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 o&&n.push(this.renderedNotification(o,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 s=this.commit(a,r);return{adopted:s.ok?s.compiled.spec:null,value:{result:s,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});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const s={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:s,command:n}),s}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=fl(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},zL=new Set(["x","y"]),_i=["numeric","categorical","temporal"],ki=["numeric"],YL=(e,t)=>{const r=e.layers.map(a=>Al(a.geom)).filter(l.isDefined),n=mr(e);return t.filter(a=>qL(e,r,a)).map(a=>({aesthetic:a,variables:jL(n,r,a),isRequired:zL.has(a)}))},qL=(e,t,r)=>{switch(r){case"x":return!JL(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))}},jL=(e,t,r)=>{const n=XL(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},XL=(e,t)=>t==="size"?ki:t!=="x"&&t!=="y"?_i:ZL(e,t)?ki:_i,ZL=(e,t)=>e.some(r=>r.positionRoles.some(n=>cs.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),JL=e=>e.coordType==="polar"&&e.params.theta==="y",QL=500,ew="normal",Sa={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},tw=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}`},xa=e=>typeof e!="string"?e??500:Sa[e],rw="\0",nw=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,xa(t.weight),t.style??"normal",e].join(rw)}},aw={" ":.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 iw=1.05,sw=.84,ow=.21,lw=class{measureText(e,t){let r=0;for(const i of e)r+=(aw[i]??.55)*t.size;xa(t.weight)>=Sa.semiBold&&(r*=iw);const n=sw*t.size,a=ow*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=nb;exports.ARROW_DEFAULTS=fe;exports.AXIS_KEYS=fn;exports.AddAnnotationCommand=oa;exports.AddHighlightCommand=fa;exports.AddLayerCommand=ba;exports.BORDER_RADIUS_PX=jn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=zh;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Sg;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=nw;exports.CommandRegistry=qu;exports.CommandStackManager=ju;exports.Compiler=ao;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_AREA_ALPHA=l.DEFAULT_AREA_ALPHA;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_BORDER_WIDTH=l.DEFAULT_BORDER_WIDTH;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=ew;exports.DEFAULT_FONT_WEIGHT=QL;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRID_LINE_COLOR=l.DEFAULT_GRID_LINE_COLOR;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DEFAULT_TEXT_PRIMARY=l.DEFAULT_TEXT_PRIMARY;exports.DEFAULT_TEXT_SECONDARY=l.DEFAULT_TEXT_SECONDARY;exports.DEFAULT_TICK_LABEL_OFFSET=l.DEFAULT_TICK_LABEL_OFFSET;exports.DEFAULT_TICK_LINE_COLOR=l.DEFAULT_TICK_LINE_COLOR;exports.DEFAULT_TICK_LINE_LENGTH=l.DEFAULT_TICK_LINE_LENGTH;exports.DIFFERENCE_ARROW_DEFAULTS=_t;exports.DIVERGING_SCHEME_NAMES=Ns;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ae;exports.GraphCompilationSession=KL;exports.HEADLINE_SWATCH_GAP=Qb;exports.HEADLINE_SWATCH_SIZE=Jb;exports.HEADLINE_TREND_GAP=rS;exports.HEADLINE_TREND_ICON_SIZE=tS;exports.HEADLINE_VALUE_LABEL_GAP=eS;exports.HeuristicTextMeasurer=lw;exports.HoverEngine=px;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=Vg;exports.LINE_STYLE_TYPES=ln;exports.LayoutCompiler=kv;exports.MAX_BAR_WIDTH=aL;exports.MIN_BAR_WIDTH=nu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=xl;exports.NAMED_WEIGHTS=Sa;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ta;exports.OUT_OF_VIEW_MARGIN_PX=ab;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=am;exports.POSITION_TYPES=Ni;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=J;exports.RemoveAnnotationCommand=sa;exports.RemoveHighlightCommand=ha;exports.RemoveLayerCommand=va;exports.SCALED_POSITION_AESTHETIC_KEYS=gn;exports.SCALED_VISUAL_AESTHETIC_KEYS=ct;exports.SCHEME_ALIASES=Bs;exports.SEQUENTIAL_SCHEME_NAMES=Yh;exports.SHAPE_DEFAULTS=he;exports.SIBLING_OVERLAP_THRESHOLD_PX=ib;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=Zl;exports.SetAxisLabelCommand=tc;exports.SetAxisPositionCommand=nc;exports.SetAxisTickModeCommand=ic;exports.SetAxisTicksVisibilityCommand=oc;exports.SetAxisVisibilityCommand=cc;exports.SetBarBorderRadiusCommand=tu;exports.SetBarWidthCommand=au;exports.SetChartTypeCommand=Tl;exports.SetContentCaptionCommand=dc;exports.SetContentSourceCommand=pc;exports.SetContentSubtitleCommand=fc;exports.SetContentTitleCommand=yc;exports.SetCoordLimitsCommand=jc;exports.SetDataLabelsFormatCommand=su;exports.SetGridLineStyleCommand=xc;exports.SetGridLineWidthCommand=Ic;exports.SetGridVisibilityCommand=Lc;exports.SetHeadlineCompareWithCommand=Ec;exports.SetHeadlinePositionCommand=Rc;exports.SetHeadlineShowCommand=Dc;exports.SetHeadlineSizeCommand=kc;exports.SetHighlightDimStyleCommand=Pc;exports.SetLayerPositionCommand=lu;exports.SetLayerStatCommand=uu;exports.SetLayerYScaleTypeCommand=mu;exports.SetLegendAlignCommand=Nc;exports.SetLegendDisplayCommand=Fc;exports.SetLegendPositionCommand=Gc;exports.SetLineInterpolationCommand=hu;exports.SetLineMissingValuesCommand=gu;exports.SetLineWidthCommand=vu;exports.SetMappingCommand=Yl;exports.SetNumberFormatAbbreviationCommand=Hc;exports.SetNumberFormatDecimalsCommand=Kc;exports.SetPointSizeCommand=Su;exports.SetPolarInnerRadiusCommand=Zc;exports.SetPolarStartAngleCommand=Qc;exports.SetRuleLabelCommand=Au;exports.SetRuleValueCommand=Tu;exports.SetScaleDomainCommand=Bu;exports.SetScalePaletteCommand=$u;exports.SetScaleReverseCommand=Uu;exports.SetScaleTransformCommand=Wu;exports.SetScaleZeroCommand=zu;exports.SetStatLineCommand=wu;exports.SetStyleRuleCommand=de;exports.SpecResolver=Ys;exports.Stat=Re;exports.TAU=xe;exports.TEXT_ANNOTATION_DEFAULTS=kt;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Vu;exports.ToggleContentVisibilityCommand=Yc;exports.ToggleDataLabelsCommand=Cu;exports.ToggleGoalLineCommand=_u;exports.ToggleLineFillCommand=ku;exports.ToggleLinePointsVisibilityCommand=Pu;exports.ToggleStackTotalsCommand=Mu;exports.UpdateAnnotationCommand=ca;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=Mi;exports.annotation=yA;exports.areAnchorsEqual=Fe;exports.areEditMenuTriggersEqual=Rb;exports.areEditTargetsEqual=HL;exports.areEndpointsComparable=Gi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=ul;exports.arePointerRegionListsEqual=Ab;exports.arePredicatesEqual=cr;exports.areStyleDeclarationsEqual=gl;exports.areStyleRuleAddressesEqual=dr;exports.buildAverageLineSymbols=Qv;exports.buildCalloutHitRegions=rb;exports.buildColumnKey=zo;exports.buildDataLabelsContent=ev;exports.buildDiagnostic=Hi;exports.buildEditMenuTriggerRegion=Eb;exports.buildFontString=tw;exports.buildLayerIntroPlan=Ix;exports.buildLayerStyleAddress=Ae;exports.buildLayerYValueFormatter=Kn;exports.buildObservationPredicate=yb;exports.buildPinnedNumberValueFormatter=$b;exports.buildPolarBarArcPath=vS;exports.buildSliceGroupKey=jo;exports.buildTooltipContent=qx;exports.canAnchorDirectLabels=Ss;exports.canBecomeCombo=lI;exports.canBecomeHeatmap=cI;exports.canPlaceDataLabels=Qy;exports.clampAnnotationTranslation=HA;exports.commandRegistry=b;exports.compileChromeStyles=Xs;exports.compileStylesheetForLayer=tg;exports.compositeColor=sd;exports.computeArrow=Zv;exports.computeDifferenceArrow=ko;exports.computeDirectLabelsLayout=gb;exports.computeLineBoxHeight=uA;exports.computePanelBorderPaths=Nx;exports.computePanelBorderSizes=Bx;exports.config=l.config;exports.convertSpecToInput=fl;exports.coord=l.coord;exports.countLayerGeoms=Tx;exports.createAlphaValueReader=dd;exports.createAnchorResolver=Pv;exports.createAreaPathGenerators=cS;exports.createColorValueReader=Fi;exports.createCompiler=xg;exports.createDatasetFromKindPartitions=Yd;exports.createEmptyHighlight=xs;exports.createGraphyBuilder=Lg;exports.createGroupValueReader=md;exports.createHeadlineItemRows=nS;exports.createLabelValueReader=cd;exports.createLineFillAreaGenerator=fS;exports.createLinePathGenerator=hS;exports.createObservationAnchorBuilder=lt;exports.createObservationAnchorParser=Ui;exports.createRawValueReader=K;exports.createSegmentYReader=ot;exports.createSizeValueReader=ud;exports.createSpec=io;exports.createStableBandKeyGenerator=AS;exports.createStableCellKeyGenerator=IS;exports.createStableKeyGenerator=sr;exports.createStrokeWidthValueReader=pd;exports.createStyleResolver=Qe;exports.createValueFormatter=D;exports.createXValueReader=Xe;exports.createYValueReader=cn;exports.cursorToPiePlane=hn;exports.cursorToPolar=Qt;exports.describeMeasurementBasis=Fr;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=$o;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=lp;exports.findAnnotation=ht;exports.findAverageLineLayer=hl;exports.findAxisGuide=qn;exports.findDistinctLayers=Sn;exports.findEquivalentHighlight=LA;exports.findGoalLineLayer=ml;exports.findHighlightsAtObservation=Db;exports.findKindStyleDeclarations=gt;exports.findLayerByGeom=le;exports.findLayerById=_;exports.findLegendForAesthetic=Xb;exports.findObservationAttachment=dl;exports.findPointerRegion=Sb;exports.findStyleRule=ur;exports.findStyleRuleIndex=aa;exports.findTrendLineLayer=pl;exports.formatDifferenceLabel=Do;exports.formatHeadline=Gb;exports.formatLegends=qb;exports.formatRuleValue=Zb;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=M;exports.getAlpha=xo;exports.getAngleExtent=Hn;exports.getBarRectBounds=Ko;exports.getBoundingRect=pS;exports.getChromeDashArray=cA;exports.getColor=pt;exports.getCrossAxisCoordinate=Zt;exports.getCurve=ir;exports.getDashArray=lS;exports.getDifferenceArrowDimensions=_o;exports.getDifferenceArrowLabelBox=pb;exports.getGroup=j;exports.getHoverGuideLineProps=gx;exports.getHoverGuideRectProps=yx;exports.getInsetTileRect=Vo;exports.getLineType=Ao;exports.getMainAxisCoordinate=Ue;exports.getNumericWeight=xa;exports.getPolarHoverGuideArcProps=vx;exports.getRadiusExtent=Wn;exports.getRuleDashPattern=xS;exports.getScaledAesthetic=od;exports.getSize=$n;exports.getStablePolarBarKeyGenerator=TS;exports.getStackRole=ws;exports.getStrokeWidth=qr;exports.getTileRectBounds=Eo;exports.getUnionExtent=SS;exports.getX=C;exports.getXMax=U;exports.getXMin=G;exports.getY=V;exports.getYMax=k;exports.getYMin=P;exports.getYRaw=on;exports.hasMultipleGroups=er;exports.highlight=TA;exports.inferDefaultDifferenceArrowEndpoints=Ob;exports.inferDifferenceArrowEndpoints=Ho;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=WA;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=yd;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=St;exports.isCompanionLayer=bn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=ns;exports.isGeomStyleRule=ia;exports.isLayerOf=Ag;exports.isLayerOfType=X;exports.isLineStyleType=Bi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=xA;exports.isPointWithinEditMenuTrigger=Vb;exports.isPointWithinRegionShape=Yn;exports.isSafeUrl=Kx;exports.isStackedPosition=F;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=CA;exports.normalizeAngle=We;exports.orderPointerRegions=xb;exports.pickReadableTextColor=id;exports.pipe=so;exports.placeCallouts=ub;exports.polarToUnit=Ut;exports.positionToAngle=is;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=uS;exports.prepareLineObservations=gS;exports.projectAnchorToPanel=Bo;exports.quantiseKey=q;exports.readAnchoredObservation=Mb;exports.readAttachedObservation=ra;exports.readAuthoredNumber=nA;exports.readAuthoredString=aA;exports.readChartType=oI;exports.readComboLineLayerId=uI;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Mc;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=YL;exports.readMappedVariable=jl;exports.readObservationIndex=bx;exports.readXExtent=ol;exports.readYExtent=ll;exports.resolveAnchorVariable=we;exports.resolveArrowColor=hb;exports.resolveAxisLabelStyle=mA;exports.resolveBarBandFraction=Hr;exports.resolveBarBorderRadiusPx=Wo;exports.resolveBarBorderTreatment=mS;exports.resolveBarCornerRadiiPx=dS;exports.resolveColorRamp=Ln;exports.resolveComparisonBasis=bs;exports.resolveDataLabelStyle=hA;exports.resolveDeferredAnchors=Gv;exports.resolveDefinition=Tn;exports.resolveGraphChromeStyle=lA;exports.resolveGridLineStyle=sA;exports.resolveHeadlinePlacement=Ev;exports.resolveObservationPoint=Nb;exports.resolvePanelBorderStyle=iA;exports.resolvePolarBarCornerRadiusUnit=bS;exports.resolveRuleLabelStyle=fA;exports.resolveSegmentYSource=jt;exports.resolveTextStyle=se;exports.resolveTickLabelStyle=pA;exports.resolveTickLineStyle=oA;exports.resolveTooltipStyle=gA;exports.resolveYScaleAesthetic=oe;exports.sampleColorScheme=Jh;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Bb;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=dA;exports.toPanelCursor=Fo;exports.toPercent=ve;exports.toViewBoxX=Nv;exports.toViewBoxY=ne;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=lo;exports.uniqueId=N;exports.unitToPolar=ss;exports.updateSpec=R;