@graphysdk/viz-engine 1.9.0-beta.1789582064893 → 1.9.0-beta.1789643389031
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +55 -4
- package/dist/index.mjs +3547 -3468
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Od=Object.create,so=Object.defineProperty,Md=Object.getOwnPropertyDescriptor,kd=Object.getOwnPropertyNames,Nd=Object.getPrototypeOf,Bd=Object.prototype.hasOwnProperty,Fd=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=kd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!Bd.call(e,s)&&s!==r&&so(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=Md(t,s))||n.enumerable});return e},nr=(e,t,r)=>(r=e!=null?Od(Nd(e)):{},Fd(t||!e||!e.__esModule?so(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-DBSz4rJf.cjs");let Ae=require("color2k"),lo=require("date-fns"),it=require("lodash-es"),ct=require("d3-time"),$d=require("date-fns/differenceInDays"),Re=require("d3-regression"),se=require("d3-scale"),je=require("d3-interpolate"),G=require("d3-scale-chromatic"),Je=require("lodash-es/clamp");Je=nr(Je,1);let qt=require("lodash-es/merge");qt=nr(qt,1);let Gr=require("humanize-duration");Gr=nr(Gr,1);let _e=require("d3-shape"),Gd=require("d3-delaunay"),jt=require("lodash-es/isEqual");jt=nr(jt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789582064893");var Ud=1e6;function te(e){return String(Math.round(e*Ud))}var Pa="#FFFFFF",Rr="#1A1A1A",Hd=4.5,co=e=>{try{return(0,Ae.getContrast)(e,Pa)>(0,Ae.getContrast)(e,Rr)?Pa:Rr}catch{return Rr}},Wd=(e,t)=>{try{const r=uo(void 0,t);return r===void 0||(0,Ae.getContrast)(r,e)>=Hd?e:co(r)}catch{return e}},uo=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,Ae.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,Ae.parseToRgba)(e);return r>=1?e:(0,Ae.parseToRgba)(t)[3]<1?void 0:(0,Ae.mix)(t,(0,Ae.opacify)(e,1),r)}catch{return}},Oa=0;function W(){return Oa+=1,`${Math.random().toString(36).slice(2,6)}${Oa.toString(36)}`}var he=Math.PI*2,Kd=8,zd=1e-9,Yd=[0,Math.PI/2,Math.PI,he*3/4],po=(e,t)=>Math.abs(t-e)>=he-zd,Pe=e=>(e%he+he)%he,Xt=(e,t,r)=>{if(po(t,r))return!0;const n=Pe(r-t);return Pe(e-t)<=n},Qe=(e,t)=>{const r=Math.abs(Pe(e)-Pe(t));return Math.min(r,he-r)},Ma=(e,t)=>{const r=Pe(t-e);return r>Math.PI?r-he:r},mo=(e,t,r)=>e*he+t+r,fe=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Ce=(e,t)=>{const r=fe(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},qd=(e,t,r,n)=>{const a=[Ce(e,r),Ce(e,n),Ce(t,r),Ce(t,n)],i=Math.max(r,n),o=Yd.filter(c=>Xt(c,e,t)).map(c=>Ce(c,i)),s=[...a,...o];return{xMin:Math.min(...s.map(c=>c.x)),xMax:Math.max(...s.map(c=>c.x)),yMin:Math.min(...s.map(c=>c.y)),yMax:Math.max(...s.map(c=>c.y))}},ar=(e,t)=>({angle:Pe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),ir=(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}},dn=(e,t)=>{const{x:r,y:n}=ir(e,t);return ar(r,n)};function k(e){return e[l.POSITION_VARIABLES.x]}function _(e){return e[l.POSITION_VARIABLES.y]}function j(e){return e[l.POSITION_VARIABLES.xMin]}function X(e){return e[l.POSITION_VARIABLES.xMax]}function U(e){return e[l.POSITION_VARIABLES.yMin]}function $(e){return e[l.POSITION_VARIABLES.yMax]}function pn(e){return e[l.POSITION_VARIABLES.yRaw]}function jd(e,t){return e[l.resolveScaledAestheticVariable(t)]}var Xd={xMin:0,xMax:1,yMin:0,yMax:1},ho=(e,t)=>{const r=j(e)??k(e),n=X(e)??k(e),a=U(e)??_(e),i=$(e)??_(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a)||!l.isStrictNumericDataValue(i)?null:t.type!=="polar"?{xMin:r,xMax:n,yMin:a,yMax:i}:{...qd(r,n,a,i),frame:"disk"}},ft=(e,t)=>{const r=(e.xMin+e.xMax)/2,n=(e.yMin+e.yMax)/2;switch(t){case"top":return{x:r,y:e.yMax};case"bottom":return{x:r,y:e.yMin};case"left":return{x:e.xMin,y:n};case"right":return{x:e.xMax,y:n};case"top-left":return{x:e.xMin,y:e.yMax};case"top-right":return{x:e.xMax,y:e.yMax};case"bottom-left":return{x:e.xMin,y:e.yMin};case"bottom-right":return{x:e.xMax,y:e.yMin};default:return{x:r,y:n}}},fo=e=>ft(Xd,e),Q=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},ot=(e,t)=>Q(e,t.x),mn=(e,t)=>Q(e,t.y),Zd=(e,t)=>Q(e,t.label),go=(e,t)=>Q(e,t.color),Jd=(e,t)=>Q(e,t.size),Qd=(e,t)=>Q(e,t.alpha),ep=(e,t)=>Q(e,t.group),tp=(e,t)=>Q(e,t.strokeWidth),ka={variable:l.POSITION_VARIABLES.yRaw};function or(e,t){return l.isStackedPosition(e)?ka:t.y??ka}function gt(e){return Q(e.data,or(e.position,e.mapping))}var ke=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},hn=e=>rp(e)?l.extractVariableName(e.mapping.y):null,yo=e=>hn(e)===null?null:gt(e),fn=e=>e.spatialKind!=="cells",rp=e=>e.spatialKind==="points"||e.spatialKind==="cells",vo=(e,t)=>e.yScaleType===t.yScaleType&&Hr(e.valueFormat)===Hr(t.valueFormat),Ur=e=>`${e.yScaleType} y axis, ${Hr(e.valueFormat)}`,Hr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,bo=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(ke(e))),n=hn(e);return a=>({...a,anchorValue:l.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:l.parseAddressingValue(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:l.parseAddressingValue(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function So(e){return e instanceof l.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function P(e,t){return Ao(e,t)}function C(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 xo(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Ne(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 Ao(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const o=e[a];if(l.isPlainObject(i)&&l.isPlainObject(o)){const s=Ao(o,i);s!==o&&(n[a]=s,r=!0)}else i!==void 0&&i!==o&&(n[a]=i,r=!0)}return r?n:e}function sr(e){return{pipe:t=>{const r=t(e);return sr({...e,...r})},result:()=>e}}var np=(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},gn=e=>e.type==="polar"?"disk":"panel",lr=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},Na=(e,t)=>{if(e.frame!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=lr(e.frame,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function Z(e,t){return e==="x"?t.x:t.y}function ve(e,t){return e==="x"?t.y:t.x}function et(e,t){return{main:Z(e,t),cross:ve(e,t)}}function Ba(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function ap(e){return e.type==="cartesian"}var re=e=>e[l.GROUP_VARIABLES.group],yt=e=>{const t=ke(e),r=yo(e),n=fn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const o=r===null?null:r(a);if(r!==null&&o===null)return null;const s=n?re(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},tt=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,ip={type:"decimal"};function Io(e){return e.length>0&&e.every(t=>t.data.size()===0)}function yn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):ip}function op(e){return yn(e,l.extractVariableName(e.mapping.y))}function To({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??or(t,r)}function Lo(e,t){const r=To({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:Q(e.data,r),valueFormat:yn(e,a)}}var wo=e=>{const t=ke(e),r=yo(e),n=fn(e);return(a,i)=>!l.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||l.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:l.areDataValuesEqual(re(a),i.groupValue)},Eo=e=>{const t=l.extractVariableName(e.mapping.y),r=gt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},sp=["lt","lte","gt","gte","range"],lp={highlight:{subject:"Highlight predicate",effect:"dropping this highlight"},"selection-anchor":{subject:"Selection anchor predicate",effect:"dropping this annotation"},"style-rule":{subject:"Style rule predicate",effect:"dropping this rule"}},me=()=>!1,Ue=()=>!0;function st(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Eo(e),parsingLocale:t}}function ge(e,t){if("and"in e){const r=e.and.map(n=>ge(n,t)).filter(n=>n!==Ue);return r.includes(me)?me:r.length===0?Ue:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>ge(n,t)).filter(n=>n!==me);return r.includes(Ue)?Ue:r.length===0?me:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=ge(e.not,t);return r===me?Ue:r===Ue?me:n=>!r(n)}return up(e,t)}function ye(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>ye(n,t,r)):"or"in e?e.or.flatMap(n=>ye(n,t,r)):"not"in e?ye(e.not,t,r):cp(e,t,r)}function cp(e,t,r){const{subject:n,effect:a}=lp[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=dp(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 up(e,t){if(!t.hasVariable(e.variable))return me;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>l.parseAddressingValue(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);return i=>{const o=t.readValue(i,e.variable);for(const s of a)if(l.areDataValuesEqual(o,s))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>He(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=He(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>He(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=He(t.readValue(i,e.variable),a);return o==="greater"||o==="equal"}}if("range"in e){const[a,i]=e.range,o=n(a),s=n(i);return c=>{const u=t.readValue(c,e.variable),d=He(u,o),p=He(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return me}function dp(e){for(const t of sp)if(t in e)return t;return null}function He(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 pp=(e,t,r,n,a,i)=>{const o=Co(e,t,r.predicate,n,a,i);if(o===null)return null;const s=Ro(r.padding),c=s===null?fp(o,r.padding):o,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin),frame:c.frame};return s===null?u:{...u,defer:s}},mp=(e,t,r,n,a,i)=>{const o=Co(e,t,r.predicate,n,a,i);return o===null?null:{...ft(o,r.align),frame:o.frame}},Ro=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Co=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let o=null,s=!1;const c=new Map;for(const u of n){if(!u.interactive)continue;const d=ye(r,u.data,"selection-anchor");if(d.length>0){for(const m of d)c.set(`${m.code}:${m.message}`,m);continue}s=!0;const p=ge(r,st(u,i));if(p!==me)for(const m of u.data){if(!p(m))continue;const h=ho(m,a);h!==null&&(o=o===null?h:hp(o,h))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},hp=(e,t)=>({frame:e.frame,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),fp=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Zt=(e,t,r)=>{const n=yp(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:vp(n,t.offset,e.coordSystem)},Vo=(e,t)=>t.anchorType==="selection"?pp(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},vn=(e,t,r)=>Wr(e,t,r)?.point??null,Wr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const o of t){const s=e.geomRegistry.get(o.geom),{resolveAnchorPosition:c}=s;if(c===void 0||a.layerId!==void 0&&o.id!==a.layerId||a.layerId===void 0&&!o.interactive)continue;const u=Lo(o,s),d=wo(o),p=yt(o),m=bo(o,n)(a);let h=-1;for(const f of o.data){if(h+=1,!d(f,m))continue;const y=c(f,{coordSystem:r,position:o.position,purpose:i,align:a.align});if(y===null)continue;const v=Do(o,f,u);if(v===null)continue;const g=p(f);if(g!==null)return{point:{...y,...v,frame:gn(r),observationIndex:h,anchor:a.align===void 0?g:{...g,align:a.align}},layerId:o.id}}}return null},gp=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const o=a.x,s=a.y;if(o===void 0||s===void 0||o.kind!=="position"||s.kind!=="position")return null;const c=$a(t.x,"x",r,i),u=$a(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!tt(d,p))return null;const m=Fa(d,o,bp(e)),h=Fa(p,s),f=Ba(n.mainAxis,{main:m.min,cross:h.min}),y=Ba(n.mainAxis,{main:m.max,cross:h.max});return ft({xMin:f.x,xMax:y.x,yMin:f.y,yMax:y.y},t.align??"center")},Do=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:np(r.valueFormat,t),yScaleType:e.yScaleType}:null},yp=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return gp(e,t);case"selection":return mp(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 vn(e,Sp(t),r)}},vp=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ro(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Fa=(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}},bp=({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},Sp=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),$a=(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},xp=class extends l.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,o={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},s={differenceArrows:_p(o,t.differenceArrows),shapes:Lp(o,t.shapes),arrows:Ep(o,t.arrows),textAnnotations:Rp(o,t.textAnnotations),images:wp(o,t.images),stickers:Cp(o,t.stickers),pinnedNumbers:Vp(o,t.pinnedNumbers),comments:Dp(o,t.comments)};return Ap(this.container,s),Ip(this.container,s),s}},le=(e,t,r,n)=>{e.diagnostics.addWarning({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},Ap=(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)}},Ip=(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 Tp(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."})},Tp=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},Lp=(e,t)=>{const r=[];for(const n of t){const a=Vo(e,n.region);if(a===null){le(e.container,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},wp=(e,t)=>{const r=[];for(const n of t){const a=Vo(e,n.region);if(a===null){le(e.container,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},Ep=(e,t)=>{const r=[];for(const n of t){const a=Zt(e,n.start,"pin"),i=Zt(e,n.end,"pin");if(a===null||i===null){le(e.container,"arrow",n.id,`has ${_o(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Rp=(e,t)=>{const r=[];for(const n of t){const a=Zt(e,n.at,"pin");if(a===null){le(e.container,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},Cp=(e,t)=>{const r=[];for(const n of t){const a=Zt(e,n.at,"pin");if(a===null){le(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Vp=(e,t)=>{const r=[];for(const n of t){const a=vn(e,n.at,"pin");if(a===null){le(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Dp=(e,t)=>{const r=[];for(const n of t){const a=vn(e,n.at,"pin");if(a===null){le(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},_p=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)le(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Wr(e,n.start,"value"),i=Wr(e,n.end,"value");if(a===null||i===null){le(e.container,"differenceArrow",n.id,`has ${_o(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){le(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Pp(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},_o=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Pp=(e,t,r,n)=>{vo(r,n)||e.container.diagnostics.addWarning({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:Ur(r),actual:Ur(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Op(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const o of Object.keys(i))r.has(o)||r.set(o,[]);for(const a of e)for(const i of a.observations)for(const[o,s]of r)s.push(o===t?a.kind:i[o]??null);const n={};for(const[a,i]of r)n[a]={type:Po(i),values:i};return new l.Dataset(n)}function Po(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 Mp=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,Po(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Be=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},kp=class extends l.Stage{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.scales,e.layers]}run(e){return this.registry.get(e.coordSpec.coordType).setup(e)}},Np=class extends Be{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}},Bp=class{constructor(e){this.setupStage=new kp(e),this.transformStage=new Np(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)}},Fp=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}},$p=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:Up(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Wp(t))}},Gp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ga=l.prefixInternalVariable("flipSwap"),Up=(e,t)=>Hp(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Hp=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},Wp=e=>{let t=e.data;for(const[r,n]of Gp){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ga).renameVariable(n,r).renameVariable(Ga,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function Oo(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 Mo=(e,t)=>Oo(t.domain!==null&&t.domain.length>0?t.domain:e),Kp=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=qp(t,e.scales,e.layers),a=Xp(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=Yp(r,n),i=Zp(t);return e.layers.map(o=>Jp(t.theta==="y"?Qp(o):o,a,i))}},zp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]];function Yp(e,t){return r=>mo(r,e,t)}function qp(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=jp(n,e,r);return a===0?0:-Math.PI/a}function jp(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const o of a.data.getValues(i))n.push(o)}return Mo(n,e).length}function Xp(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 Zp(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Jp(e,t,r){let n=e.data;return n=We(n,l.POSITION_VARIABLES.x,t),n=We(n,l.POSITION_VARIABLES.xMin,t),n=We(n,l.POSITION_VARIABLES.xMax,t),n=We(n,l.POSITION_VARIABLES.y,r),n=We(n,l.POSITION_VARIABLES.yMin,r),n=We(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function We(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 Qp(e){let t=e.data;for(const[r,n]of zp){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const o=a?t.getValues(r):null,s=i?t.getValues(n):null;o&&(t=t.addVariable(n,"numeric",o)),s&&(t=t.addVariable(r,"numeric",s))}return{...e,data:t}}var em=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Fp),this.register("flip",new $p),this.register("polar",new Kp)}},ko=new Set(["min","max","scalar"]),tm={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function rm(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 nm(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 am(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=tm[a.axis][a.role];if(n.hasVariable(i))continue;const o=l.extractVariableName(r[a.aes]);!l.isDefined(o)||!n.hasVariable(o)||(n=n.addVariable(i,"numeric",n.getValues(o,{type:"numeric"})))}return n}var im=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:am(n.data,r.positionRoles,a)}}},bn=["x","y"],Sn=new Set(["x","y","ySecondary"]),vt=new Set(["color","size","alpha","strokeWidth","lineType"]),Fe=e=>Sn.has(e),xn=e=>vt.has(e),No=e=>Fe(e)||xn(e);function Te(e){return e==="secondary"?"ySecondary":"y"}function Bo(e,t){return e==="y"?Te(t):"x"}function H(e){return e==="ySecondary"?"y":e}var Le=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of vt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},cr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Le(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),om=class{compute({data:e,mapping:t}){const r=Le(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(o=>e.getValues(o)),i=new Array(n);for(let o=0;o<n;o++)i[o]=l.getStableKey(a.map(s=>s[o]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},sm=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},lm=(e,t,r)=>{const n=Oe(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Oe(e,t){const r=H(t);for(const n of Fo(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var ur=(e,t)=>e===null?null:t[e]??e,cm=(e,t)=>e===null?null:t[String(e)]??null,Me=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Cr(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 dm(i,t)?i:Cr(t)}return Cr(t)},um=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Fo(t,e).some(r=>r.position==="fill");function Fo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Cr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},dm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},pm=[{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}],Ua={year:0,quarter:1,month:2,week:3,day:4,hour:5},Ke=40,mm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return ym(r.unit).range(e,new Date(t.valueOf()+1),n)},hm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,$d.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}},fm=(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"}}},gm=(e,t)=>{const r=vm(t);return r===null?!1:Ua[e]>Ua[r]},ym=e=>{switch(e){case"hour":return ct.utcHour;case"day":return ct.utcDay;case"week":return ct.utcMonday;case"month":case"quarter":return ct.utcMonth;case"year":return ct.utcYear}},vm=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}},$o={left:"right",right:"left",top:"bottom",bottom:"top"},bm={x:!0,y:!0,ySecondary:!1},Sm=20,Ha=new Set(["top","bottom"]),xm={type:"percentage"};function Am(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:o,geomRegistry:s}=e;if(Io(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Lm(s,a,i.type,n),u=new Set(t.map(m=>m.position)),d=Em(Go(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const m of Sn){const h=r[m];if(!l.isDefined(h)||h.kind!=="position")continue;const f=Im({scaleAestheticKey:m,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function Im(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:o,gridOverrides:s,variableLabels:c}=e,{axisConfig:u,position:d,geometry:p}=wm(t,n,i,o),m=Oe(a,t),h=um(a,t)?xm:Me({layers:a,scaleType:r.spec.scaleType,variableName:m});return{scaleAestheticKey:t,position:d,geometry:p,label:Tm(u,m,c),isVisible:u.isVisible,tickCandidates:Cm(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Rm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Tm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Lm(e,t,r,n){const a=t.flatMap(s=>{const c=e.get(s.geom).grid[r];return c?[c]:[]}),i=a.some(s=>s.hideGridX),o=a.some(s=>s.hideGridY);return{x:{gridVisible:Wa(i,n.axes.x.grid.isVisible)},y:{gridVisible:Wa(o,n.axes.y.grid.isVisible)}}}function Wa(e,t){if(e&&t===null)return!1}function wm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Go(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=$o[n],i=(0,it.merge)({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function Go(e,t){return Ha.has(e)===Ha.has(t)?e:t}function Em(e,t){return t.has(e)?$o[e]:e}function Rm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??bm[r]}var Cm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Dm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=Sm;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>rt(e,u))}))}return i}return e.spec.scaleType==="datetime"?Vm(e,t):[{ticks:e.generateTicks().map(a=>rt(e,a))}]},Vm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>rt(e,s))}];const a=new Set,i=[],o=(s,c)=>{if(s.length===0)return;const u=l.getStableKey(s);a.has(u)||(a.add(u),i.push({ticks:s.map(d=>rt(e,d)),valueFormat:c}))};for(const s of pm)hm({...s,start:r,stop:n})||gm(s.unit,t)||o(e.generateTicks({interval:s}),fm(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},Dm=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[rt(e,r),rt(e,n)]}},rt=(e,t)=>({value:t,position:e.map(t)});function Uo({scale:e,aesthetics:t,layers:r}){const n=_m({layers:r,aesthetics:t}),a=Ho({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function _m({layers:e,aesthetics:t}){const r=Ho({layers:e,aesthetics:t}),n=e.find(i=>t.some(o=>l.isDefined(i.mapping[o]))),a=n?n.geom:"bar";return i=>{const o=r(i);return o?o.layer.geom:a}}function Ho({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const o=t.find(c=>l.isDefined(i.mapping[c]));if(o===void 0)continue;const s=l.extractVariableName(i.mapping[o]);if(!(s===null||!i.data.hasVariable(s)))for(const c of i.data.getValues(s,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var An=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Pm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!An(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=Oe(t,"color");if(Wo({colorVariableName:a,xVariableName:Oe(t,"x"),mapsColorAcrossMultipleLayers:Mm(t)>1,isMergedWithAnotherAesthetic:Om(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return Uo({scale:n,aesthetics:["color"],layers:t}).map(({value:s,geom:c,owner:u})=>{const d=u?.layerIndex??o,p=t[d],m=p?l.extractVariableName(p.mapping.color):null;return{value:s,color:String(n.map(s)),geom:c,layerIndex:d,valueFormat:Me({layers:p?[p]:t,scaleType:i,variableName:m}),label:cm(s,r)}})}var Wo=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Om(e,t,r){if(r===null)return!1;for(const n of vt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!An(a))&&Oe(t,n)===r)return!0}return!1}var Mm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Ko(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function km(e,t,r,n){const a=r.findIndex(i=>Ko(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:ur(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function 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 zo=e=>e==="none"?"first":e,Nm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=za(e);return n===0?null:r}case"average":{const{sum:r,count:n}=za(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Bm=(e,t)=>{if(e.length<2)return null;const r=e.at(-1),n=t==="previous"?e.at(-2):e.at(0);return r===void 0||n===void 0||r.cross===null||n.cross===null||n.cross===0?null:{variation:(r.cross-n.cross)/n.cross,against:n.main}},za=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Fm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?$m(e,n):Gm(e,n)}function $m(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(s=>s.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const o=l.extractVariableName(a.mapping.y);return o===null?null:{kind:"grandTotal",value:i,valueFormat:Me({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:o})}}function Gm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:o,geomRegistry:s}=e;if(!a.some(d=>Ko(s,d)))return null;const c=km(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Um({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 Um({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const o=l.extractVariableName(i.mapping.y);if(o===null||t==="total"&&i.position==="fill")return null;const s=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Me({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=Km(i.data,s),m=Me({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),h=zm(i.data,s),f=h.getValues(o,{type:"numeric"}),y=s!==null?h.getValues(s):[],v=c!==null?h.getValues(c):null,g=Ka(f,v,e.value),b=Ka(y,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:Nm(g,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:m,label:e.label,caption:Hm(t,p,b),comparison:Wm(t,r,p,b,g)}}function Hm(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 Wm(e,t,r,n,a){return e!=="current"||!r?null:Bm(n.map((i,o)=>({main:i,cross:a[o]??null})),zo(t))}function Km(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function zm(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function ae(e,...t){return e?t.includes(e.geom):!1}function F(e,t){return e.find(r=>r.id===t)}function we(e,...t){return e.find(r=>t.includes(r.geom))}function Ym(e,...t){return e.filter(r=>t.includes(r.geom))}function In(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function Tn(e){const t=e.filter(r=>!In(r,e));return t.length>0?t:e}function Yo({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Tn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var qm=3;function jm({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:o}){if(t.legend.position==="none")return{drawn:[],position:"none"};const s=new Map(i.map(v=>[l.getStableKey(v.value),v])),c=nh(Qm({scales:e,layers:r})),u=Oe(r,"x"),d=c.map(v=>{if(th(v,u,r))return null;const g=ih({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return g.items.length===0?null:{group:v,built:g}}).filter(l.isDefined),p=Xm(d),m=Tn(r),h=dh(o,t.legend.position,p,m,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&uh(o,p,m,n))return{drawn:[],position:h};const f=ph(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),y=f==="direct"?gh(m[0]):null;return{drawn:d.map(({built:v})=>Zm(v,{position:h,display:f,align:t.legend.align},y)),position:h}}function Xm(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function Zm(e,t,r){const{position:n,display:a}=t,i=Jm(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(o=>({...o,normalizedY:r.get(String(o.value))??null}))}}function Jm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function Qm(e){const{scales:t,layers:r}=e,n=[];for(const a of vt){const i=t[a];if(i===void 0||i.kind==="identity"||!eh(a,r))continue;const o=Oe(r,a),s=fh(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function eh(e,t){const r=H(e);return t.some(n=>l.isDefined(n.mapping[r]))}function th(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Wo({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:rh(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function rh(e,t){const r=H(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function nh(e){const t=new Map;for(const r of e){const n=hh(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function ah(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function ih({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>H(u.scaleAestheticKey)),o=Uo({scale:a.scale,aesthetics:i,layers:r}),s=Me({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),c=r.find(u=>i.some(d=>l.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:ur(a.variableName,t),items:o.map(u=>oh(u,e,i,s,n,c))}}function oh(e,t,r,n,a,i){const o={};for(const c of t)ah(o,c.scaleAestheticKey,c.scale.map(e.value));if(o.color===void 0&&r.includes("size")&&(o.color=l.DEFAULT_GEOM_COLOR),o.lineType===void 0){const c=l.extractConstantValue(e.owner?.layer.mapping.lineType);l.isLineStyleType(c)&&(o.lineType=c)}const s=lh(e,t,r,n,a);return{value:e.value,label:sh(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function sh(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function lh(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,o=ch(i,r);return i===void 0||o===null?n:Me({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function ch(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 uh(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 dh(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,o=!1,s=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(o=!0,l.isStackedPosition(u.position)&&(s=!0))}const c=r>=qm;return i&&o?"top":i?c?"right":"top":s?mh(a)?"top":c?"right":"top":"top"}function ph(e,t){return e==="pill"?"pill":Yo(t)?"direct":"pill"}function mh(e){return e.type==="cartesian"&&e.mainAxis==="y"}function hh(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function fh(e,t){return An(t)?"discrete":`continuous:${e}`}function gh(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(_(c)));if(!n)return;const a=re(n);if(!l.isDefined(a))return;const i=U(n),o=$(n)??_(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var yh=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=sm(e.originalData),r=Pm({scales:e.scales,layers:e.layers,valueLabels:lm(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=Fm(n),i=jm(n),o={...i,drawn:vh(a,i.drawn)};return{axes:Am(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},vh=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],dt=(e,t,r)=>{switch(e){case"series":return bh(t);case"x-value":return Ln(t,r)}},dr=e=>{const t=l.readMainAxisVariable(e);return t===""?null:t},bh=e=>l.getStableKey([re(e)]),Ln=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Sh={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function qo(e){const t=Sh[e]??null;return t===null?null:{strategy:t,composition:jo()}}function jo(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var xh=class extends Be{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=Ah({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Ah({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const D=ye(T.predicate,e.data);for(const O of D)a.diagnostics.addWarning({...O,message:`${O.message} Dropping this highlight.`});return D.length===0}),o=dr(e.mapping),s=st(e,r),c=i.map(T=>({predicate:ge(T.predicate,s),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),p=n==="overlay-anchor",m=e.data.size(),h=u?new Array(m):null,f=d?new Array(m):null,y=p?new Array(m):null,v=new Uint8Array(m),g=new Set,b=new Set;let I=!1,L=0;for(const T of e.data){let D,O;h!==null&&(D=dt("series",T,o),h[L]=D),f!==null&&(O=dt("x-value",T,o),f[L]=O),y!==null&&(y[L]=T);for(const{predicate:ie,scope:Mt}of c)if(ie(T))switch(Mt){case"series":D!==void 0&&g.add(D);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":v[L]=1,I=!0;break}L++}if(g.size===0&&b.size===0&&!I)return jo();const w=new Uint8Array(m),E=[];let R=0;for(let T=0;T<m;T++){const D=h?.[T],O=f?.[T],ie=D!==void 0&&g.has(D),Mt=O!==void 0&&b.has(O),Da=v[T]===1;if(n==="observation-rerender")(ie||Da||Mt)&&(w[T]=1,R++);else if(ie)w[T]=1,R++;else if(Da||Mt){const _a=y?.[T];_a!==void 0&&E.push({observation:_a,observationIndex:T})}}const V=R>0?{...e,data:e.data.filterByMask(w)}:null;return{isDimmed:(n==="observation-rerender"||g.size>0)&&V!==null,matchedLayer:V,overlayCandidates:E}}var Ih=l.prefixInternalVariable("__ungrouped__");function Th(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),o=new Map,s=i.map((c,u)=>{if(c===null)return null;const d=r[u]??Ih;let p=o.get(d);return p||(p=new l.ChronologicalDateManager,o.set(d,p)),p.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",s)}return n}var Lh=()=>({defaults:[],overrides:[],warnings:[]}),wh=class extends Be{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,Ya(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:Ya(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=sr({data:t,mapping:r}).pipe(({data:s,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:s,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>({data:this.groupCompiler.compute({data:s,mapping:c}).data,mapping:c})).pipe(({data:s,mapping:c})=>({data:Th(s),mapping:c})).pipe(({data:s,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:s,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),o=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:o.spatialKind,identityKey:o.identityKey,tooltip:o.tooltip,supportsDirectLabels:o.legend.directLabelSupport?.[e.position]===!0,highlight:qo(e.geom),styles:Lh()}}};function Ya(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Xo(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Eh(e,t){return t.some(r=>l.isStackedPosition(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function Kr(e,t){const r=Zo(e,t),n={};for(const{layer:i,scaleConstraints:o,crossAxis:s}of r)o.zeroBaseline===!0&&(n[s]={nice:(n[s]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:Ch(r),zeroAxes:n,bandPadding:Vh(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Rh(e,t){const r=Zo(e,t);for(const n of r){if(n.scaleConstraints.discreteCrossAxis!==!0)continue;const a=r.find(i=>i.scaleConstraints.zeroBaseline===!0&&i.crossAxis===n.crossAxis);if(a!==void 0)return{crossAxis:n.crossAxis,banded:qa(n),zeroAnchored:qa(a)}}return null}var qa=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function Zo(e,t){const r=[];return t.forEach((n,a)=>{if(!e.has(n.geom))return;const{scaleConstraints:i}=e.get(n.geom);i!==void 0&&r.push({layer:n,index:a,scaleConstraints:i,crossAxis:Te(n.yScaleType)})}),r}function Ch(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.discreteMainAxis===!0&&t.add("x"),r.discreteCrossAxis===!0&&t.add(n);return[...t]}function Vh(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Dh(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Dh({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var _h=new Set(["label","group"]),Ph=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},o={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(o));const s=[...this.collectUndeclaredAesthetics(o),...this.collectPanelJustifyWarnings(o)];for(const c of s)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),Xo(this.container.diagnostics,t)}checkPostCompile(e){Io(e)&&this.container.diagnostics.addWarning({code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."})}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:o,showDataLabels:s}=i;if(!s||o!=="panel-start"&&o!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!cr(r,t))return[];const c=o==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${o}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:o},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:o,aesthetics:s}=this.container.geomRegistry.get(r),c=[...rm(o),...s.filter(p=>p.required).map(p=>p.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const p of c)d.has(p)||l.isDefined(a[p])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${p}'`,context:{layerIndex:t,aesthetic:p}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=s,d=new Set(c);for(const[p,m]of Object.entries(a)){if(u.has(p))continue;const h=l.extractVariableName(m);h===null||h===""||d.has(h)||i.hasVariable(h)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${p}' references variable '${h}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:p,variableName:h}})}return o}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=s,u=[];for(const d of o){if(!ko.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const p=l.extractVariableName(a[d.aes]);if(p===null||!i.hasVariable(p)||i.size()===0)continue;const m=i.getType(p);m!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${p}' is ${m}`,context:{layerIndex:t,aesthetic:d.aes,variableName:p,variableType:m},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:o}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:o}).map(s=>({...s,message:`Layer '${e}': ${s.message}`,context:{...s.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Rh(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=new Set([...nm(i),...o.map(m=>m.name)]),u=_h,d=s,p=[];for(const m of Object.keys(a))l.isDefined(a[m])&&(c.has(m)||u.has(m)||d.has(m)||p.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${m}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:m}}));return p}},be=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=l.POSITION_TYPES,this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,it.merge)({},this.defaultParams,e.params)}},wn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},En=(e,{coordSystem:t})=>{const r=k(e),n=_(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?Ce(r,n):{x:r,y:n}},Oh=class extends be{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="filled-buckets",this.resolveAnchorPosition=En}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=wn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Mh=.7,kh=.1,Nh=.03,Bh=.05,Jo=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Fh=class extends be{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveDataLabelDefaults=t=>l.isStackedPosition(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>zr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=ho(t,r);return p===null?null:ft(p,i)}if(r.type==="polar")return $h(t);const o=l.isStackedPosition(n),s={isSolo:!o||Jo(t)==="solo",isNegative:o&&Gh(t),purpose:a};if(r.mainAxis==="x"){const p=j(t),m=X(t),h=ja({lowerBound:U(t),upperBound:$(t)??_(t),options:s});return p===null||m===null||h===null?null:{x:(p+m)/2,y:h}}const c=U(t),u=$(t),d=ja({lowerBound:j(t),upperBound:X(t)??k(t),options:s});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=zr(r,n);e=wn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const i=a/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",i),{data:e,mapping:{}}}resolveWidthParam(e,t){if(e===void 0)return;const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return r;const n=r!==null&&r>1?1:void 0;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the category band in (0, 1]."}),n}},zr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Mh,$h=e=>{const t=j(e),r=X(e),n=U(e),a=$(e);return t===null||r===null||n===null||a===null?null:Ce((t+r)/2,(n+a)/2)},Gh=e=>{const t=pn(e);return l.isStrictNumericDataValue(t)&&t<0},ja=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},Uh=class extends be{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=En}compile(e){return{data:wn(e.data,e.mapping),mapping:{}}}},Hh=class extends be{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=En,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:{}}}},Wh=class extends be{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=Xa(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=Xa(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}}}},Xa=(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},Kh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},zh=class extends be{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=Kh,this.resolveAnchorPosition=t=>{const r=j(t),n=X(t),a=U(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:{}}}},Yh=[new Fh,new Hh,new Uh,new Oh,new Wh,new zh],pr=class extends l.Registry{constructor(){super("geom");for(const e of Yh)this.register(e.type,e)}},$e=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},qh=class extends $e{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.x);if(!l.isDefined(r))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'count' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'count' stat."});if(l.extractVariableName(t.y)!==null)throw new l.UserInputError({code:"CONFLICTING_STAT_MAPPING",message:"Cannot map 'y' variable together with 'count' stat",context:{aesthetic:"y"},suggestion:"Remove the 'y' mapping; the 'count' stat computes it."});const n=[...new Set([r,...Le(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},jh=class extends $e{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Xh=class extends $e{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}}}},Zh=2,Qo=1440*60*1e3,Jh=class extends $e{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'smooth' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'smooth' stat."});if(!l.isDefined(i))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'smooth' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'smooth' stat."});const o=e.getType(a),s=e.getType(i);if(s!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${s}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:s}});const c=Le(e,t),u=of(a,o,i,c,e);return c.length===0?Za({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=sf(d,c);Za({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Za=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=Qh({data:e,xVariable:t,yVariable:n,xType:r});c.length<Zh||(s?af({observations:c,spec:a,output:i,groupObservation:o}):rf({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},Qh=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?ef(a):null,s=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!l.isDefined(d)||!l.isDefined(p)||!Number.isFinite(p))continue;const m=tf({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});m!==null&&s.push({x:m,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},ef=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},tf=({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)/Qo+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}`})}},rf=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=es(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?nf(s,r):s;a.push({x:u,y:c,groupObservation:i})}},nf=(e,t)=>t===null?new Date(e):new Date((e-1)*Qo+t),af=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const s of e)a.has(s.x)||a.set(s.x,s.originalX);const i=[...a.keys()].sort((s,c)=>s-c);if(t.method==="loess"){const s=es(t,e),c=new Map;for(const[u,d]of s)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const o=ts(t,e);for(const s of i){const c=a.get(s),u=o.predict(s);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},es=(e,t)=>e.method==="loess"?(0,Re.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ts(e,t),ts=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Re.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Re.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Re.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Re.regressionQuad)().x(r).y(n)(t);case"power":return(0,Re.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Re.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},of=(e,t,r,n,a)=>{const i=[],o=[],s=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),o.push(u);for(const p of n)s[p]?.push(d[p]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:o,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:s[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},sf=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},lf=class extends $e{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'sum' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."});const n=l.extractVariableName(t.x),a=[...new Set([...n===null?[]:[n],...Le(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},cf=[new jh,new qh,new Jh,new Xh,new lf],uf=class extends l.Registry{constructor(){super("stat");for(const e of cf)this.register(e.type,e)}};function df({geoms:e,stats:t,transforms:r}){const n=new pr,a=new uf,i=new l.TransformRegistry;for(const o of e)n.register(o.type,o);for(const o of t)a.register(o.type,o);for(const o of r)i.register(o.transformType,o);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function Rn(e){if("definition"in e)return e.definition;if(ns(e)||as(e)||is(e))return e}function rs(e){const t=[],r=[],n=[];for(const a of e){const i=Rn(a);i&&(ns(i)?t.push(i):as(i)?r.push(i):is(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...Vr("geom",t,a=>a.type),...Vr("stat",r,a=>a.type),...Vr("transform",n,a=>a.transformType),...pf(t),...mf(t)]}}function pf(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 mf(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 Vr(e,t,r){const n=new Map;for(const i of t){const o=r(i),s=n.get(o);s?s.add(i):n.set(o,new Set([i]))}const a=[];for(const[i,o]of n)o.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${o.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var ns=e=>e instanceof be,as=e=>e instanceof $e,is=e=>"transformType"in e&&typeof e.apply=="function",hf=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},mr=class{},ff=class extends mr{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=gf(e)??[-.7/2,.7/2],o=r.length>1?kh:0,s=(0,se.scaleBand)().domain(r.map(String)).range(i).paddingInner(o).paddingOuter(0),c=s.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const m=a[p];if(!l.isDefined(m))continue;const h=s(String(m));l.isDefined(h)&&(u[p]=h,d[p]=h+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},gf=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]},Ja=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,o=i?[Ja]:a,s=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let m=0;m<d;m++){const h=l.getStableKey(s[m]??null),f=u[m],y=i?Ja:f;if(!l.isDefined(y))continue;let v=p.get(h);v||(v=new Map,p.set(h,v));let g=v.get(y);g||(g=[],v.set(y,g)),g.push(m)}return{yValues:c,observationIndicesByXAndGroup:p,uniqueGroupKeys:o,observationCount:d}},ss=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const o=[];let s=-1,c=1/0,u=-1/0,d=-1,p=1/0,m=-1/0;for(const h of i.values())for(const f of h){const y=e[f],v=t[f];!l.isDefined(y)||!l.isDefined(v)||(o.push(f),(y<c||y===c&&v>u)&&(s=f,c=y,u=v),(v>m||v===m&&y<p)&&(d=f,p=y,m=v))}for(const h of o)a[h]=yf(h===s,h===d)}return a},yf=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",vf=class extends mr{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:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,d]of a){let p=0,m=0;for(const y of i){const v=d.get(y);if(v!==void 0)for(const g of v){const b=n[g];b!=null&&(b>=0?p+=b:m-=b)}}let h=0,f=0;for(const y of i){const v=d.get(y);if(v!==void 0)for(const g of v){const b=n[g];if(b===void 0)continue;if(b===null){c[g]=null,s[g]=null;continue}const I=b>=0?p:m;if(I===0){c[g]=0,s[g]=0;continue}const L=b/I;b>=0?(c[g]=h,s[g]=h+=L):(s[g]=f,c[g]=f+=L)}}}const u=ss(c,s,a,o);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},bf=class extends mr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Sf=class extends mr{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:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,m]of a){let h=0,f=0;for(const y of i){const v=m.get(y);if(v!==void 0)for(const g of v){const b=n[g];if(b!==void 0){if(b===null){c[g]=null,s[g]=null;continue}b>=0?(c[g]=h,s[g]=h+=b):(s[g]=f,c[g]=f+=b)}}}}const u=ss(c,s,a,o);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const p=l.extractVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",s)),{data:d,mapping:{}}}},xf=class extends l.Registry{constructor(){super("position"),this.register("identity",new bf),this.register("stack",new Sf),this.register("fill",new vf),this.register("dodge",new ff)}},Af=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const o of i.positionRoles){if(o.role!=="scalar"||!l.isDefined(o.aes)||xn(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Bo(o.axis,t.yScaleType));if(!c)continue;const u=a.getValues(s,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(o.aes),"numeric",u)}return a}},If=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},Tf=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=l.isDefined(n)&&e.hasVariable(l.POSITION_VARIABLES.x)?Lf(e,r,n):wf(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Lf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=ls(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function wf(e,t){const r=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=ls(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function ls(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Ef=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(Te(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},Rf=class{map({data:e,layer:t,getPositionScale:r}){const n=r(Te(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=l.isDefined(a)&&e.hasVariable(l.POSITION_VARIABLES.y)?Cf(e,n,a):Vf(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Cf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=cs(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function Vf(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=cs(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function cs(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Df=[new If,new Ef,new Tf,new Rf,new Af];function _f(e,t){const r=e[t];return r?.kind==="position"?r:null}var Pf=class extends Be{constructor(e,t=Df){super(),this.container=e,this.mappers=t}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,t){const r=a=>_f(t.scales,a);let n=e.data;for(const a of this.mappers)n=a.map({data:n,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:n}}},Of=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:Eh(this.container.geomRegistry,e.layers)},a={};for(const[i,o]of t){const s=r.get(i)??[];a[i]=this.registry.get(o.scaleType).compile(o,s,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=H(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const o=l.extractVariableName(i.mapping[a]);if(!l.isDefined(o)||!i.data.hasVariable(o)||i.data.size()===0)continue;const s=i.data.getType(o);if(!n.includes(s)){const c=r.scaleType==="continuous"&&s==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${s})`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}if(r.scaledAesthetic==="lineType"&&s!=="categorical"){const c=s==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${s} variable '${o}'. ${c}`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}}Xo(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,o]of Object.entries(n.mapping)){if(!l.isDefined(o))continue;const s=i==="y"?Te(n.yScaleType):i,c=a.get(i)??(No(s)?s:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,o,n.data,u);this.collectFromVariables(n.data,d,c,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!l.isDefined(n.aes)||xn(n.aes)||t.set(n.aes,Bo(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const o of t)a=a.concat(e.getValues(o));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Mf=["rgb","lab","hcl","hsl"],kf=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],us=["RdBu","BrBG","PuOr","Spectral"],ds={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Nf=new Set(us.map(e=>e.toLowerCase()));function ps(e){const t=e.toLowerCase(),r=ds[t];return r?r.toLowerCase():t}function Bf(e){return Nf.has(ps(e))}var Ff={rgb:je.interpolateRgb,lab:je.interpolateLab,hcl:je.interpolateHcl,hsl:je.interpolateHsl},$f={viridis:G.interpolateViridis,magma:G.interpolateMagma,inferno:G.interpolateInferno,plasma:G.interpolatePlasma,cividis:G.interpolateCividis,turbo:G.interpolateTurbo,blues:G.interpolateBlues,greens:G.interpolateGreens,greys:G.interpolateGreys,oranges:G.interpolateOranges,purples:G.interpolatePurples,reds:G.interpolateReds,rdbu:G.interpolateRdBu,brbg:G.interpolateBrBG,puor:G.interpolatePuOr,spectral:G.interpolateSpectral};function Cn(e){const t=Uf(e);return e.reverse?r=>t(1-r):t}function Gf(e={},t=2){const r=Cn({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 Uf(e){const t=Ff[e.interpolate];if(e.range&&e.range.length>=2)return(0,je.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=$f[ps(e.scheme)];if(r)return r}return(0,je.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var bt=class{createPositionScale(e,t){return{kind:"position",aesthetic:H(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:H(e.scaledAesthetic),spec:e,...t}}},Hf=class extends bt{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=Fe(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"&&Wf(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:H(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,se.scaleLog)():r.transform==="sqrt"?(0,se.scaleSqrt)():(0,se.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const o=r.domainMin??n[0],s=r.domainMax??n[1];return i.domain([o,s]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=Kf(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=Cn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[o,s]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([o,n,s],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,se.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,se.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Wf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Kf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var zf=class extends bt{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=Fe(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=Yf(e)?e:[],a=(0,se.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,o]=a.domain();i!==void 0&&o!==void 0&&a.domain([r.domainMin??i,r.domainMax??o])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,o]=a.domain(),s=i&&o?r.filter(c=>c>=i&&c<=o):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?s:c&&"interval"in c?i&&o?mm(i,o,c.interval):[]:a.ticks(c?.count)})}},Yf=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),qf=class extends bt{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=Fe(e.scaledAesthetic),n=Mo(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,se.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),o=i.bandwidth()/2;return this.createPositionScale(t,{map:s=>(i(String(s))??NaN)+o,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,se.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},jf=class extends bt{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:H(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Xf=class extends bt{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=Oo(t),a=l.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=l.applyOverrides(a.length>0?a:[...l.DEFAULT_COLOR_PALETTE],e.overrides),o=(0,se.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},Zf=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Hf(e)),this.register("discrete",new qf),this.register("datetime",new zf),this.register("identity",new jf),this.register("palette",new Xf)}},ms={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Jf={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 Vn(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Kr(e.geomRegistry,n)}}function hr(e,t){switch(t.scaleType){case"inferred":return{...hr(e,rg(e,t)),inferredFrom:t};case"continuous":{const r=ms[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:ng(e.container,t),interpolate:t.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??l.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??l.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??l.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??l.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??l.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return Yr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:l.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Qf(e,t){const{scales:r,layers:n,coords:a}=t,i=Vn(e,t),o=og(ig(r,n),i.demands),s=new Map;for(const u of o)s.set(u.scaledAesthetic,u);const c=[...s.values()].map(u=>{const d=eg(i,u);return hr(i,d)});return a.coordType==="polar"?c.map(Dn):c}function Yr(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??l.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??l.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??r??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??tg(e.scaledAesthetic,t)}}var Dn=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function eg(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function tg(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function rg({data:e,layers:t,mapping:r,demands:n},a){const i=H(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?ag(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const p=a.options;return l.continuous(a.scaledAesthetic,{...p,zero:!0,...!s.nice&&{nice:!1}})}const c=l.extractVariableName(o);if(!l.isDefined(c)||!e.hasVariable(c)||e.size()===0)return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=ms[a.scaledAesthetic];switch(Jf[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 ng(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&Bf(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function ag(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function ig(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function og(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var sg={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}},lg=(e,t,r)=>{const n=cg(e,t),a=pg(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>hg(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>vg(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>xg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>mg(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>fg(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>bg(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>gg(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>yg(e,i,r)).filter(l.isDefined)}},cg=(e,t)=>{if(t===void 0)return{};if(!ug(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:W()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},ug=e=>{const t=new Set;for(const r of dg(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},dg=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],pg=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},_n=(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},mg=(e,t,r,n)=>{const a=Jt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),content:t.content,at:a,width:t.width,align:t.align??l.TEXT_ANNOTATION_DEFAULTS.align}},hg=(e,t,r)=>{const n=pt(e,t.start,r),a=pt(e,t.end,r);return n===null||a===null?null:{id:t.id??W(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},pt=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},Jt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return _n(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=pt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},fg=(e,t,r,n)=>{const a=Jt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),at:a,sticker:t.sticker}},gg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n}},yg=(e,t,r)=>{const n=pt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n,content:t.content}},vg=(e,t,r)=>t.region.anchorType==="annotation"&&!_n(e,t.region.ref,r,t.id)?null:{id:t.id??W(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Sg(t.region)},bg=(e,t,r)=>t.region.anchorType==="annotation"&&!_n(e,t.region.ref,r,t.id)?null:{id:t.id??W(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Sg=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},Qa=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=sg[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},xg=(e,t,r,n)=>{const a=Jt(e,t.start,r,n,t.id),i=Jt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??W(),start:Qa(a),end:Qa(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},Ag={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function Ig(e){const t=(0,it.merge)({},Ag,e);return t.content=Tg(t.content,e?.content),t}var Tg=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Lg={xLimits:null,yLimits:null},Wt={theta:"x",startAngle:0,innerRadius:0};function qr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,qt.default)({},Lg,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Wt.theta,startAngle:t.params?.startAngle??Wt.startAngle,innerRadius:(0,Je.default)(t.params?.innerRadius??Wt.innerRadius,0,1)}}}}function wg(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??W(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Eg=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=ei(e.filter(n=>n.severity==="error")),r=ei(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Rg=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 ei(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Cg={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 hs(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 Ge(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new Rg(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=_g({dataLabels:Og(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return Dg({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??W(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:hs(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:s.resolveParams({params:n.params,diagnostics:o}),transforms:n.transforms??[],interactive:n.interactive??s.defaultInteractive,dataLabels:u}}function Vg(e,t,r,n,a){const i=n.map((o,s)=>Ge(e,t,r,o,a,s));return gs(e,i)}var fs=(e,t,r,n)=>n.label!==void 0?n.label:To({geom:e.get(t),position:r,mapping:n,purpose:"label"}),gs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Ne(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(o=>o.axis==="y"&&o.role==="scalar"))return n;const a=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,it.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Dg=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&l.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},_g=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:o}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const s=Pg(t,r,n);if(s===null)return e;const c=i==="panel-end"?"end":"start";return o&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${s}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Pg=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&l.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Og=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=fs(e,r.geom,n,i),s=e.get(r.geom);return{...(0,it.merge)({},Cg,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},Mg=e=>{const t=new Set;e!==void 0&&ys(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},ys=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])ys(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function kg(e,t,r){const n=qr(t.coords),a=Vg(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Qf(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=Ig(t.config),s=wg(e,t.highlights,a),c=lg(e,t.annotations,a),u=Mg(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:s,styles:u,annotations:c,coords:n,config:o}}var vs=class{constructor(e){this.container=e}compile({spec:e,dataset:t,customPalettes:r}){return kg(this.container,{...e,data:t},r)}},Ng=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})}},St={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},Bg={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}}},bs=Object.keys(St),Fg=e=>Object.hasOwn(St,e),xt=(e,t)=>{for(const r of bs){const n=$g(e,r,t);if(n)return n}return null},At=(e,t)=>e[St[t]],Pn=(e,t,r)=>({...e,[St[t]]:r}),Ss=(e,t)=>{const r=At(e,t.kind);return Pn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},$g=(e,t,r)=>{const n=At(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},Gg=class extends Be{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of cy(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of dy(e.styles))this.container.diagnostics.addWarning(r);for(const r of py(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=ws({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},qe={color:"color",alpha:"unitInterval",saturation:"unitInterval"},jr={bar:{...qe,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...qe,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...qe,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...qe,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...qe,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},kt={color:"color",strokeWidth:"pixels",lineType:"lineType"},z={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Nt={...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},ti={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},M={panelBorder:{...kt,borderRadius:"pixels"},panelBorderEdge:kt,gridLine:kt,tickLine:{...kt,length:"pixels"},axisLabel:{...z,margin:"margin"},tickLabel:{...z,offset:"pixels",margin:"margin"},ruleLabel:z,dataLabel:Nt,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color",textScale:"multiplier",padding:"padding"},heading:z,caption:z,source:z,header:{margin:"margin"},footer:{margin:"margin"},hoverGuide:{color:"color",background:"color"},tooltip:ti,tooltipText:z,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels",margin:"margin"},legend:{gap:"pixels",margin:"margin"},legendPopover:ti,legendItem:{...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},legendItemSwatch:{size:"pixels",strokeWidth:"pixels"},directLabel:{...z,strokeWidth:"pixels",lineType:"lineType"},annotation:{color:"color",alpha:"unitInterval"},annotationShape:{color:"color",alpha:"unitInterval",borderColor:"color",borderWidth:"pixels"},annotationArrow:{color:"color",strokeWidth:"pixels",lineType:"lineType",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationDifferenceArrow:{color:"color",strokeWidth:"pixels"},annotationDifferenceArrowLabel:Nt,annotationText:{...Nt,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...Nt,shadow:"shadow"}},Ug={number:z,numberCenter:z,caption:z,label:z,swatch:{size:"pixels"},trend:z,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},Hg=new Set(l.STYLE_PROPERTY_NAMES),xs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","caption","source","header","footer","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],Wg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Kg=new Set(["panelBorder","legend","axisLabel","tickLabel"]),zg=(e,t,r="en-US")=>ws({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Yg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of uy(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return As(e.styles)}},As=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},heading:{defaults:[],overrides:[]},caption:{defaults:[],overrides:[]},source:{defaults:[],overrides:[]},header:{defaults:[],overrides:[]},footer:{defaults:[],overrides:[]},hoverGuide:{defaults:[],overrides:[]},tooltip:{defaults:[],overrides:[]},headline:{defaults:[],overrides:[]},headlineItem:{defaults:[],overrides:[]},legend:{defaults:[],overrides:[]},legendItem:{defaults:[],overrides:[]},directLabel:{defaults:[],overrides:[]},annotation:{defaults:[],overrides:[]},warnings:t},a=(i,o,s,c)=>{if(fr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!jg(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${xs.map(h=>`'${h}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const p=i.select;if(p.target==="annotation"){const h=p.kind;if(h!==void 0&&!iy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown annotation kind '${String(h)}'.`,context:{param:"kind",actual:String(h),...u},suggestion:`Set 'kind' to one of ${l.ANNOTATION_STYLE_KINDS.map(g=>`'${g}'`).join(", ")}, or omit it to address every annotation.`});return}const f=p.part,y=oy(h);if(f!==void 0&&!(typeof f=="string"&&y.includes(f))){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(f)}'.`,context:{param:"part",actual:String(f),...u},suggestion:y.length>0?`Set 'part' to ${y.map(g=>`'${g}'`).join(", ")}, or omit it to address the ${h==="differenceArrow"?"line":"marker"}.`:`Remove 'part' — ${h===void 0?"kind-agnostic":`'${String(h)}'`} entries have none.`});return}const v=p.annotation;if(v!==void 0&&typeof v!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid annotation ${Ie(v)}.`,context:{param:"annotation",actual:Ie(v),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}if(Kg.has(p.target)){const h=p.edge;if(h!==void 0&&!Xg(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown edge '${String(h)}'.`,context:{param:"edge",actual:String(h),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Wg.has(p.target)){const h=p.axis;if(h!==void 0&&!sy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown axis '${String(h)}'.`,context:{param:"axis",actual:String(h),...u},suggestion:`Set 'axis' to one of ${bn.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="ruleLabel"){const h=p.layer;if(h!==void 0&&typeof h!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid layer ${Ie(h)}.`,context:{param:"layer",actual:Ie(h),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(p.target==="tooltip"){const h=p.part;if(h!==void 0&&!Qg(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(p.target==="heading"){const h=p.part;if(h!==void 0&&!ty(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.HEADING_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address every heading level.`});return}}if(p.target==="source"){const h=p.part;if(h!==void 0&&!ey(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.SOURCE_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the label.`});return}}if(p.target==="legend"){const h=p.part;if(h!==void 0&&!ry(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.LEGEND_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the gap.`});return}}if(p.target==="legendItem"){const h=p.part;if(h!==void 0&&!ny(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.LEGEND_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the pill.`});return}}if(p.target==="headlineItem"){const h=p.part;if(!ay(h)){t.push({code:"INVALID_STYLE_RULE",message:h===void 0?`Style ${s} ignored: headlineItem entries need a part.`:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.HEADLINE_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="dataLabel"){const h=p.role;if(h!==void 0&&!Zg(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown role '${String(h)}'.`,context:{param:"role",actual:String(h),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(y=>`'${y}'`).join(", ")}.`});return}const f=p.position;if(f!==void 0){if(!Jg(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(y=>`'${y}'`).join(", ")}.`});return}if(h===void 0||h==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const m=Mn({declarations:i.declarations,vocabulary:Ts(p),tokens:r,location:s,origin:c,warnings:t,entryTarget:p.target});Object.keys(m).length!==0&&n[p.target][o].push({select:p,declarations:m,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,o)=>{a(i,"defaults",`builtin[${o}]`,{list:"builtin"})}),e.defaults.forEach((i,o)=>{a(i,"defaults",`defaults[${o}]`,{list:"defaults",index:o,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,o)=>{a(i,"overrides",`overrides[${o}]`,{list:"overrides",index:o,...i.id===void 0?{}:{id:i.id}})}),n},qg=(e,t)=>{if(e==="geom"){const r=Object.keys(jr).find(n=>jr[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>Ts({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},fr=e=>e.select.target==="geom",jg=e=>{const t=e.select.target;return t!=="geom"&&xs.includes(t)},Is=e=>(e!==void 0?jr[e]:void 0)??qe,Ts=e=>{if(e.target==="panelBorder")return e.edge===void 0?M.panelBorder:M.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?M.tooltip:e.part==="primaryRow"?M.tooltipPrimaryRow:M.tooltipText;if(e.target==="legend")return e.part==="popover"?M.legendPopover:M.legend;if(e.target==="legendItem")return e.part===void 0?M.legendItem:M.legendItemSwatch;if(e.target==="headlineItem")return Ug[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return M.annotationShape;case"arrow":return M.annotationArrow;case"differenceArrow":return e.part==="label"?M.annotationDifferenceArrowLabel:M.annotationDifferenceArrow;case"text":return M.annotationText;case"image":return M.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?M.annotationCalloutLabel:M.annotationCallout;default:return M.annotation}return M[e.target]},Xg=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),Zg=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),Jg=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Qg=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),ey=e=>typeof e=="string"&&l.SOURCE_PARTS.includes(e),ty=e=>typeof e=="string"&&l.HEADING_PARTS.includes(e),ry=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),ny=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),ay=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),iy=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),oy=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],sy=e=>typeof e=="string"&&bn.includes(e),ly=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!fr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=Mn({declarations:a.declarations,vocabulary:Is(o),tokens:t,location:`builtin[${i}]`,origin:s,warnings:r,entryTarget:"geom"});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:s})}),n},On=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},cy=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return On(e,(a,i,o)=>{const s=a.select;if(s.target!=="geom"&&s.target!=="ruleLabel")return;const c=s.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},uy=(e,t)=>{const r=new Map(bs.flatMap(a=>t[St[a]].map(i=>[i.id,a]))),n=[];return On(e,(a,i,o)=>{const s=a.select;if(s.target!=="annotation")return;const c=s.annotation;if(c===void 0||typeof c!="string")return;const u={param:"annotation",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(c);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown annotation '${c}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets sticker '${c}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=s.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets ${d} '${c}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},dy=e=>{const t=[];return On(e,(r,n,a)=>{if(!fr(r))return;const i=r.when?.state;i===void 0||Ls(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${l.STYLE_STATES.map(o=>`'${o}'`).join(", ")}.`})}),t},Ls=e=>l.STYLE_STATES.includes(e),py=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))l.isUsableTokenValue(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Ie(n)}.`,context:{param:"tokens",actual:Ie(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ie=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),ws=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=st(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((m,h)=>{if(!fr(m))return;const f=m.select.kind;if(f!==void 0&&f!==t.geom||m.select.layer!==void 0&&m.select.layer!==t.id)return;const y=m.when?.state;if(y!==void 0&&!Ls(y))return;const v={list:d,index:h,...m.id===void 0?{}:{id:m.id}},g=m.when?.where;if(g!==void 0){const I=ye(g,t.data,"style-rule");if(I.length>0){for(const L of I)o.push({...L,code:"INVALID_STYLE_RULE",message:`Style ${d}[${h}]: ${L.message}`,context:{...L.context,layerIndex:r,...m.id===void 0?{}:{styleEntryId:m.id}}});return}}const b=Mn({declarations:m.declarations,vocabulary:Is(f),tokens:s,location:`${d}[${h}]`,origin:v,warnings:o,entryTarget:"geom"});Object.keys(b).length!==0&&p.push({declarations:b,...g===void 0?{}:{matches:ge(g,i)},...y===void 0?{}:{state:y},origin:v})}),p};return{defaults:[...ly(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},Mn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:o,entryTarget:s}=e,c={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(f,y)=>{c[f]=y},p=(f,y,v)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: expected ${y}, got ${Ie(v)}.`,context:{param:f,expected:y,actual:Ie(v),...u},suggestion:`Set '${f}' to ${y}.`})},m=(f,y)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: unknown token '${y}'.`,context:{param:f,actual:y,...u},suggestion:`Declare '${y}' in the stylesheet's tokens.`})},h=f=>{const y=Hg.has(f),v=qg(s,f),g=v===void 0?`Declare '${f}' on a target whose vocabulary carries it.`:`Declare '${f}' on an entry whose kind supports it (e.g. ${v}).`;o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: ${y?"not in this entry's vocabulary":"not a style property"}.`,context:{param:f,...u},suggestion:y?g:`Remove the unknown declaration '${f}'.`})};for(const f of Object.keys(t)){const y=t[f];if(y===void 0)continue;const v=r[f];if(v===void 0){h(f);continue}const g=l.STYLE_DOMAINS[v](y,n);switch(g.status){case"accepted":d(f,g.value);break;case"rejected":p(f,g.expected,g.actual);break;case"unknownToken":m(f,g.token);break;case"dropped":break;default:break}}return c},my=({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}},hy=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=l.extractVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const n=s=>t==="y"?s.xMax:s.yMax,a=s=>t==="y"?s.xMin:s.yMin,i=new Map;for(const s of e.data){const c=s[r],u=U(s),d=$(s),p=j(s),m=X(s),h=pn(s);if(!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||!l.isDefined(h))continue;const f=h>=0;if(Math.abs(h)===0)continue;const y=Ln(s,r),v={xMin:p,xMax:m,yMin:u,yMax:d},g=i.get(y);if(g===void 0){i.set(y,{total:h,topPositive:f?v:null,bottomNegative:f?null:v});continue}g.total+=h,f?(g.topPositive===null||n(v)>n(g.topPositive))&&(g.topPositive=v):(g.bottomNegative===null||a(v)<a(g.bottomNegative))&&(g.bottomNegative=v)}const o=[];for(const[s,c]of i){const u=c.topPositive??c.bottomNegative;u!==null&&o.push({xKey:s,total:c.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:c.topPositive!==null?"positive":"negative"}})}return o},fy=class extends Be{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=t.coordSystem.type==="cartesian"?t.coordSystem.mainAxis:"x";if(r.summaries.stackTotals){const i=hy({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=my({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Es=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)}},ri={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},gy=["color","size","alpha","strokeWidth","lineType"],yy=class extends Be{dependencies(e){return gy.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const o=l.extractConstantValue(e.mapping[a]);if(o!==void 0){r=r.addConstantVariable(i,ri[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,ri[a],vy(c)))}return{...e,data:r}}},vy=e=>t=>l.isDefined(t)?e.map(t):null;function Rs(e=new pr){return{diagnostics:new Eg,geomRegistry:e}}var Cs=class{constructor(e,t,r,n,a,i,o,s,c,u,d,p,m,h,f,y){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=o,this.coordCompiler=s,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=p,this.stylesCompiler=m,this.chromeStylesCompiler=h,this.highlightsCompiler=f,this.annotationsCompiler=y,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??ni})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??ni;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,C(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=Vn(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return C(t,{scales:Ne(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=hr(r,a);return t.coords.coordType==="polar"?Dn(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[So(e)],warnings:t.warnings}}trackCompile(e){if(!l.IS_DEV)return e();const t=this.getCacheStats(),r=performance.now(),n=e(),a=performance.now()-r,i={};for(const{name:o,getStats:s}of this.stages){const c=s();i[o]={hits:c.hits-t[o].hits,misses:c.misses-t[o].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e,colorScheme:t}){return{...sr({spec:e}).pipe(({spec:r})=>({spec:C(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:C(r,{data:n.data,mapping:n.mapping})}}).pipe(({spec:r})=>({layers:this.layerPhasedCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales})})).pipe(({spec:r,layers:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},by=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],ni="light",Sy=({plugins:e=[]}={})=>{const t=rs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=df(t),i=Rs(r),o=new Zf(i),s=new Es(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new Cs(i,new l.DataCompiler,new vs(i),s,new Mp,new Ph(i,s,n,new wh(i,s,new Ng(n),new om,new im(i),new hf(new xf))),new Of(i,o),new Bp(new em),new Pf(i),new yy,new yh(i),new fy(i),new Gg(i),new Yg(i),new xh(i),new xp(i))};function Vs(e,t){return e.geom===t}function Ds(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!xy(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>Ps(o,s),i)}function _s(e,...t){return t.reduce((r,n)=>Ps(r,n),e)}function xy(e){return typeof e=="object"&&e!==null&&"type"in e}function Ps(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,qt.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 Ay(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Ay(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 Iy(e){const t=e?.plugins??[],r=Ly(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Ds,pipe:_s,plugins:t}}var Ty=e=>(t={})=>l.buildLayerSpec(e,t);function Ly(e){const{geoms:t,stats:r,transforms:n}=rs(e),a={};for(const s of t)a[s.type]=Ty(s.type);const i={};for(const s of r)i[s.type]=()=>({type:s.type});const o={};for(const s of n)o[s.transformType]=c=>({type:"transform",transformType:s.transformType,options:c?.options});return{geom:a,stat:i,transform:o}}var Dr="…",Os=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Dr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Dr)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Dr};var Y={timeZone:"UTC"},K=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Ee=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",kn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",wy=Gr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ms=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Ee(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Fn(a,i),{base:s,suffix:c}=Bn(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),ks=({locale:e,numberFormat:t,intlOptions:r})=>Ee(n=>{const{base:a,suffix:i}=Bn(n,t.abbreviation),o={...Fn(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),Nn=e=>Ee(t=>wy(t)),Ns=({locale:e,intlOptions:t})=>Ee(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Bs=({locale:e,numberFormat:t,intlOptions:r})=>Ee(n=>{const a=Fn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Bn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Ey(e);return Bn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Fn=(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}},Ey=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"},Ry=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).format(r)),Cy=({locale:e,intlOptions:t})=>K(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...Y,...t}).formatToParts(r);return Vy(n.map(Dy))}),Fs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t}).format(r)),$s=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"long",...Y,...t}).format(r)),$n=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...Y,...t}).format(r)),Gn=e=>K(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Gs=({locale:e,intlOptions:t})=>K(r=>{const n=(0,lo.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t,year:void 0}).formatRange(r,n)}),Us=({locale:e,intlOptions:t})=>K(r=>{const n=(0,lo.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).formatRange(r,n)}),Un=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{year:"numeric",...Y,...t}).format(r)),Hs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),Vy=e=>e.map(t=>t.value).join(""),Dy=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},ai=1e3,_y=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Ee(a=>{const i={...Wn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Hn(a,t,i)}),Py=({locale:e,tickValues:t,intlOptions:r})=>Ee(n=>{const a={...Wn(n,t),notation:"compact",...r};return Hn(n,e,a)}),Oy=({locale:e,tickValues:t,intlOptions:r})=>Ee(n=>{const a={...Wn(n,t),notation:"compact",...r,style:"percent"};return Hn(n,e,a)}),Hn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Ws=e=>Math.abs(e)>ai?Ws(e/ai):Number.isInteger(e),My=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Wn=(e,t)=>Ws(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:My(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},ky=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Ny=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",...Y,...t}).format(r)),By=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Fy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),Kn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return _y(e);case"date":case"datetime":return ky(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return By(e);case"decimal":case"integer":return Py(e);case"duration":return Nn(e);case"month":return Ny(e);case"month_year":return $n(e);case"percentage":return Oy(e);case"quarter":return Gn(e);case"text":return kn(e);case"time":return Fy(e);case"year":return Un(e);case"lookup":return Kn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},$y=.9,Gy=1/3,Uy=1/4,Hy=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Wy(e):Ky(e),Wy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Ks(e.ticks,n),s=zy(e.ticks,r.width),c=s*$y;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Zr(c);return{...e,ticks:Xr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Zr(r.height*Gy);return{...e,ticks:Xr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Ky=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Ks(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Zr(r.width*Uy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Xr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},zy=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Ks=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},Xr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Os(i.formattedLabel,r,a)})},Zr=e=>Math.max(0,Math.floor(e)),Yy=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let o=r-(e.length-1)*i;for(const s of e){const{width:c,height:u}=n(s);if(o-=a?c:u,o<0)return!1}return!0},qy=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const m=o.get(p);if(m)return m;const h=a[p],f=h?jy(h.ticks,n(h)):[];return o.set(p,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1;Yy(s(p).map(m=>m.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},jy=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),ii=.5,It=e=>({x:0,y:0,width:e.width,height:e.height}),zn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,Tt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:o,alignOffset:s,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",p=(r.valueAxis==="x"?e.height:e.width)===0,m={anchor:Zy(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},h={anchor:Jy(i),placement:p?n:"inside",offset:p?s??o:0},f=d?t:e,y=r.valueAxis==="x"?f:e,v=r.valueAxis==="y"?f:e,g=r.valueAxis==="x"?m:h,b=r.valueAxis==="x"?h:m,I=si(g,{min:y.x,max:y.x+y.width,halfExtent:c/2}),L=si(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:I,y:L,position:Xy(e,I,L,c,u)}},oi=(e,t,r,n)=>r-n>=e-ii&&r+n<=t+ii,Xy=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||oi(e.x,e.x+e.width,t,n/2),o=e.height===0||oi(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},Zy=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",Jy=e=>e==="center"?"center":e==="start"?"min":"max",si=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const o=r+i;return e==="min"?t==="inside"?n+o:n-o:t==="inside"?a-o:a+o},Qy=(e,t,r,n,a)=>{const i=t??e,o=1-Math.max(e,i);return{box:{x:r*n,y:o*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},ev=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=rv(e.layer);for(const a of e.layer.data){const i=k(a),o=$(a)??_(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),{box:d,frame:p}=Qy(o,U(a),i,e.panelRect.width,e.panelRect.height),m=Tt({box:d,panel:It(e.panelRect),frame:p,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:m.x,y:m.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return{labels:t,droppedCount:0}},tv={place:ev,getPercentageValueStrategy:e=>e.position==="fill"?"fill":l.isStackedPosition(e.position)?"stack":"none"},rv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:cr(e.data,e.mapping)?zn(r):r,align:n}};function Lt(e){return e[l.VISUAL_VARIABLES.color]}function zs(e){return e[l.VISUAL_VARIABLES.alpha]}function Yn(e){return e[l.VISUAL_VARIABLES.size]}function Jr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Ys(e){return e[l.VISUAL_VARIABLES.lineType]}var qs=["color","alpha","saturation","borderRadius","borderColor","borderWidth","strokeWidth","lineType","strokeAlpha","fillAlpha","size","background","fontFamily","fontSize","fontWeight","lineHeight","textScale","textColor","offset","gap","length","paddingInline","paddingBlock","padding","margin","shadow"],Bt={top:["x","top"],right:["y","right"],bottom:["x","bottom"],left:["y","left"]},nv=(e,t)=>{const r=li(e.graph,e.graph),n=c=>li(c,r),a=c=>ov(u=>n(c(u))),i=a(c=>e.ruleLabel(c)),o=Object.assign(c=>t(c),{bar:c=>t(c),line:c=>t(c),area:c=>t(c),point:c=>t(c),rule:Object.assign(c=>t(c),{label:c=>i(c.id)}),tile:c=>t(c)}),s=c=>({x:A(()=>n(c("x"))),y:A(()=>n(c("y"))),top:A(()=>n(c(...Bt.top))),right:A(()=>n(c(...Bt.right))),bottom:A(()=>n(c(...Bt.bottom))),left:A(()=>n(c(...Bt.left)))});return{geom:o,graph:()=>r,heading:{h1:A(()=>n(e.heading.h1)),h2:A(()=>n(e.heading.h2))},caption:A(()=>n(e.caption)),source:Object.assign(A(()=>n(e.source.label)),{link:A(()=>n(e.source.link))}),header:A(()=>n(e.header)),footer:A(()=>n(e.footer)),hoverGuide:A(()=>n(e.hoverGuide)),tooltip:Object.assign(A(()=>n(e.tooltip.box)),{heading:A(()=>n(e.tooltip.heading)),label:A(()=>n(e.tooltip.label)),value:A(()=>n(e.tooltip.value)),primaryRow:A(()=>n(e.tooltip.primaryRow))}),gridLine:{x:A(()=>n(e.gridLine("x"))),y:A(()=>n(e.gridLine("y")))},tickLine:{x:A(()=>n(e.tickLine("x"))),y:A(()=>n(e.tickLine("y")))},axisLabel:s(e.axisLabel),tickLabel:s(e.tickLabel),panelBorder:Object.assign(A(()=>n(e.panelBorder())),{top:A(()=>n(e.panelBorder("top"))),right:A(()=>n(e.panelBorder("right"))),bottom:A(()=>n(e.panelBorder("bottom"))),left:A(()=>n(e.panelBorder("left")))}),dataLabel:{observation:{inside:A(()=>n(e.dataLabel("observation","inside"))),outside:A(()=>n(e.dataLabel("observation","outside")))},category:{inside:A(()=>n(e.dataLabel("category","inside"))),outside:A(()=>n(e.dataLabel("category","outside")))},aggregate:A(()=>n(e.dataLabel("aggregate","outside")))},headline:A(()=>n(e.headline)),headlineItem:{number:Object.assign(A(()=>n(e.headlineItem.number)),{center:A(()=>n(e.headlineItem.numberCenter))}),caption:A(()=>n(e.headlineItem.caption)),label:A(()=>n(e.headlineItem.label)),swatch:A(()=>n(e.headlineItem.swatch)),trend:Object.assign(A(()=>n(e.headlineItem.trend)),{up:A(()=>n(e.headlineItem.trendUp)),down:A(()=>n(e.headlineItem.trendDown)),flat:A(()=>n(e.headlineItem.trendFlat))})},legend:Object.assign(A(()=>n(e.legend())),{popover:A(()=>n(e.legend.popover)),top:A(()=>n(e.legend("top"))),right:A(()=>n(e.legend("right"))),bottom:A(()=>n(e.legend("bottom"))),left:A(()=>n(e.legend("left")))}),legendItem:Object.assign(A(()=>n(e.legendItem.item)),{swatch:A(()=>n(e.legendItem.swatch))}),directLabel:A(()=>n(e.directLabel)),annotation:{shape:a(c=>e.annotation.shape(c)),arrow:a(c=>e.annotation.arrow(c)),differenceArrow:Object.assign(a(c=>e.annotation.differenceArrow(c)),{label:a(c=>e.annotation.differenceArrow.label(c))}),text:a(c=>e.annotation.text(c)),image:a(c=>e.annotation.image(c)),pinnedNumber:Object.assign(a(c=>e.annotation.pinnedNumber(c)),{label:a(c=>e.annotation.pinnedNumber.label(c))}),comment:Object.assign(a(c=>e.annotation.comment(c)),{label:a(c=>e.annotation.comment.label(c))})}}},av=(e,t)=>{if(typeof e.fontSize!="number"||(e.fontSize*=t.get("textScale"),e.fontFamily!==void 0))return;const r=t.get("fontFamily");r!==void 0&&(e.fontFamily=r)},iv=(e,t)=>{const r={};for(const n of qs){const a=e.get(n);a!==void 0&&Object.assign(r,{[n]:a})}return av(r,t),r},li=(e,t)=>{let r;return{...e,resolve:()=>(r??=iv(e,t),r)}},ov=e=>{const t=new Map;return r=>{const n=t.get(r);if(n!==void 0)return n;const a=e(r);return t.set(r,a),a}},A=e=>{let t;return()=>(t??=e(),t)},sv={color:Lt,alpha:zs,strokeWidth:Jr,lineType:Ys,size:Yn,borderWidth:Jr},lt=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap,a=new WeakMap,i=u=>{const d=r.get(u);if(d!==void 0)return d;const p=cv(u.styles,t);return r.set(u,p),p},o=u=>{const d=n.get(u);if(d!==void 0)return d;const p=lv(u,t);return n.set(u,p),p};return{readers:u=>{const d=a.get(u.chrome);if(d!==void 0)return d;const p=nv(o(u.chrome),i);return a.set(u.chrome,p),p},geomReaders:i,chromeReaders:o,explain:(u,d,p,m)=>i(u).explain(d,p,m)}},lv=(e,t)=>{const r=(v,g)=>{const b=R=>ci(v.overrides,R,g)??ci(v.defaults,R,g);return{get:R=>{const V=b(R)?.declarations[R];if(V!==void 0)return l.resolveColorScheme(V,t)},getSource:R=>{const V=b(R);return V===void 0?"unresolved":V.origin.list==="builtin"?"builtin":"authored"},explain:R=>{const V=b(R),T=V?.declarations[R];return V===void 0||T===void 0?{value:void 0,source:"unresolved"}:{value:l.resolveColorScheme(T,t),source:V.origin.list==="builtin"?"builtin":"authored",origin:V.origin,select:V.select}},collectAll:R=>{const V=[];for(const T of[v.defaults,v.overrides])for(const D of T){if(!g(D))continue;const O=D.declarations[R];O!==void 0&&V.push(l.resolveColorScheme(O,t))}return V}}},n=(v,g)=>{const b="edge"in v.select?v.select.edge:void 0;return b===void 0||b===g},a=v=>r(e.panelBorder,g=>n(g,v)),i=v=>r(e.legend,g=>g.select.target!=="legend"||g.select.part!==void 0?!1:n(g,v)),o=v=>(g,b)=>r(e[v],I=>I.select.target!==v||I.select.axis!==void 0&&I.select.axis!==g?!1:n(I,b)),s=v=>r(e.ruleLabel,g=>g.select.target!=="ruleLabel"?!1:g.select.layer===void 0||g.select.layer===v),c=(v,g)=>r(e.dataLabel,b=>b.select.target!=="dataLabel"||b.select.role!==void 0&&b.select.role!==v?!1:b.select.position===void 0||b.select.position===g),u=v=>r(e.tooltip,g=>g.select.target==="tooltip"&&g.select.part===v),d=v=>r(e.source,g=>g.select.target==="source"&&g.select.part===v),p=v=>r(e.heading,g=>g.select.target!=="heading"?!1:g.select.part===void 0||g.select.part===v),m=v=>r(e.legend,g=>g.select.target==="legend"&&g.select.part===v),h=v=>r(e.legendItem,g=>g.select.target==="legendItem"&&g.select.part===v),f=v=>r(e.headlineItem,g=>g.select.target==="headlineItem"&&g.select.part===v),y=(v,g)=>{const b=new Map;return I=>{const L=b.get(I);if(L!==void 0)return L;const w=r(e.annotation,E=>{if(E.select.target!=="annotation")return!1;const R=E.select.kind;return R!==void 0&&R!==v||E.select.part!==g?!1:E.select.annotation===void 0||E.select.annotation===I});return b.set(I,w),w}};return{panelBorder:a,gridLine:o("gridLine"),tickLine:o("tickLine"),axisLabel:o("axisLabel"),tickLabel:o("tickLabel"),ruleLabel:s,dataLabel:c,graph:r(e.graph,()=>!0),heading:{h1:p("h1"),h2:p("h2")},caption:r(e.caption,()=>!0),source:{label:d(void 0),link:d("link")},header:r(e.header,()=>!0),footer:r(e.footer,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:u(void 0),heading:u("heading"),label:u("label"),value:u("value"),primaryRow:u("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:f("number"),numberCenter:f("numberCenter"),caption:f("caption"),label:f("label"),swatch:f("swatch"),trend:f("trend"),trendUp:f("trendUp"),trendDown:f("trendDown"),trendFlat:f("trendFlat")},legend:Object.assign(i,{popover:m("popover")}),legendItem:{item:h(void 0),swatch:h("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:y("shape"),arrow:y("arrow"),differenceArrow:Object.assign(y("differenceArrow"),{label:y("differenceArrow","label")}),text:y("text"),image:y("image"),pinnedNumber:Object.assign(y("pinnedNumber"),{label:y("pinnedNumber","label")}),comment:Object.assign(y("comment"),{label:y("comment","label")})}}},ci=(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}},cv=(e,t)=>{const r=(o,s,c)=>{if(c!==void 0){const m=xe(e.overrides,o,s,c,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin,state:c};const h=xe(e.defaults,o,s,c,t);if(h!==void 0)return{value:h.value,tier:"default",origin:h.origin,state:c}}const u=xe(e.overrides,o,s,void 0,t);if(u!==void 0)return{value:u.value,tier:"override",origin:u.origin};const d=ui(o,s);if(d!==void 0)return{value:d,tier:"data"};const p=xe(e.defaults,o,s,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}},n=(o,s,c)=>{if(c!==void 0){const p=xe(e.overrides,o,s,c,t);if(p!==void 0)return p.value;const m=xe(e.defaults,o,s,c,t);if(m!==void 0)return m.value}const u=xe(e.overrides,o,s,void 0,t);if(u!==void 0)return u.value;const d=ui(o,s);return d!==void 0?d:xe(e.defaults,o,s,void 0,t)?.value};return{get:n,getSource:(o,s,c)=>r(o,s,c).tier,explain:r,collectAll:(o,s,c)=>{const u=[];for(const d of[e.defaults,e.overrides])for(const p of d){if(p.state!==c)continue;const m=p.declarations[o];m!==void 0&&js(p,s)&&u.push(uv(m,t))}return u},resolve:(o,s)=>{const c={};for(const u of qs){const d=n(u,o,s);d!==void 0&&Object.assign(c,{[u]:d})}return c}}},xe=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const o=e[i];if(o===void 0||o.state!==n)continue;const s=o.declarations[t];if(s!==void 0&&js(o,r))return{value:l.resolveColorScheme(s,a),origin:o.origin}}},js=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),uv=(e,t)=>l.isLightDarkColor(e)?e[t]:e,ui=(e,t)=>{const r=sv[e];if(!(r===void 0||t===void 0))return r(t)??void 0},qn=(e,t,r)=>{const n={},a=i=>{const o=n[i];if(o!==void 0)return o;const{width:s,height:c}=e(t,i,r),u={width:s,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},Ft=6,dv=.5,pv=e=>{const t=[];let r=0;const n=l.isStackedPosition(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=hv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:a});for(const s of i){const c=e.layer.dataLabels.position==="auto"?yv({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):bv(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,It(e.panelRect));if(c===null){r+=1;continue}const u=s.boxes[c.position];t.push({layerId:e.layer.id,x:c.x,y:c.y,text:s.text,width:u.width,height:u.height,isRotated:c.isRotated,target:"observation",position:c.position,...c.position==="inside"?{backdropColor:s.backdropColor}:{}})}}if(e.layer.dataLabels.showCategoryLabels)for(const i of Sv(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=Tv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of i)t.push(o)}return{labels:t,droppedCount:r}},mv={place:pv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":l.isStackedPosition(e.position)?"stack":"absoluteGrandTotal"},hv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const o=[];let s=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y),d=lt().geomReaders(e);for(const p of e.data){const m=Zs(t,p);if(m===null)continue;const h=a(p);if(h==="")continue;const f=qn(n,"observation",h),y=jn(m,r);c&&f.inside.width>y.width&&(s=!0);const v=u===null?null:p[u],g=l.isStrictNumericDataValue(v)&&v<0;o.push({isNegative:g,text:h,boxes:f,bounds:y,backdropColor:d.get("color",p)})}return{entries:o,shouldRotate:!i&&s}},jn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),Xs=(e,t,r,n,a)=>{if(e==="x"){let s=1-a,c=a-n;return c<0&&(s+=c,c=-c),{x:t,y:s,width:r-t,height:c}}let i=t,o=r-t;return o<0&&(i+=o,o=-o),{x:i,y:1-a,width:o,height:a-n}},Zs=(e,t)=>{const r=j(t),n=X(t),a=U(t),i=$(t)??_(t);return r===null||n===null||a===null||i===null?null:Xs(e,r,n,a,i)},fv=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return Xs(e,r,n,a,i)},gv=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Qr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},yv=e=>e.isStacked?xv({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Iv({edge:gv(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),Js=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},vv=e=>e==="panel-start"||e==="panel-end",bv=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,o=n.boxes[i],s=Tt({box:n.bounds,panel:a,frame:Js(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!vv(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+dv?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},Sv=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:o}=e.layer.dataLabels,s=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=It(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const m=Zs(c,p);if(m===null)continue;const h=e.formatCategory(p);if(h===null||h==="")continue;const f=qn(e.measureDataLabel,"category",h),y=f[s],v=jn(m,e.panelRect),g=d===null?null:p[d],b=l.isStrictNumericDataValue(g)&&g<0,I=Tt({box:v,panel:u,frame:Js(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:y.width,labelHeight:y.height}),L=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:h,width:L.width,height:L.height,isRotated:!1,target:"category",position:I.position})}return r},xv=({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"}},Av=(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}}},Iv=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:o})=>{const s=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=s?t.height:t.width,p=s?t.width:t.height,{edgeCoord:m,outwardSign:h,panelExtent:f}=Av(e,t,a,i),y=Qr(r.inside.width,r.inside.height,n),v=s?y.height:y.width,g=s?y.width:y.height,b=v+o<d,I=g<=p;if(s?b:b&&I){if(s&&!I)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const R=m-h*(v/2+o);return{...s?{x:c,y:R}:{x:R,y:u},isRotated:!1,position:"inside"}}const L=Qr(r.outside.width,r.outside.height,n),w=(s?L.height:L.width)/2,E=m+h*(w+o);return E-w<0||E+w>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Tv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],o=e.summary.stackTotals;if(o===void 0||o.length===0)return i;const s=t==="y";for(const c of o){const u=jn(fv(t,c),r),d=a(c.total),{width:p,height:m}=n("aggregate","outside",d),h=c.anchor.direction==="positive";let f,y;s?(f=h?u.x+u.width+Ft+p/2:u.x-Ft-p/2,y=u.y+u.height/2):(f=u.x+u.width/2,y=h?u.y-Ft-m/2:u.y+u.height+Ft+m/2),i.push({layerId:e.id,x:f,y,text:d,width:p,height:m,isRotated:!1,target:"aggregate",position:"outside"})}return i},Lv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Ev(e.layer);for(const a of e.layer.data){const i=k(a),o=_(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=Tt({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:It(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return{labels:t,droppedCount:0}},wv={place:Lv,getPercentageValueStrategy:()=>"none"},Ev=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:cr(e.data,e.mapping)?zn(r):r,align:n}},Rv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Vv(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=lt().geomReaders(e.layer);for(const o of e.layer.data){const s=k(o),c=_(o);if(s===null||c===null||!tt(s,c))continue;const u=e.formatLabel(o);if(u==="")continue;const{width:d,height:p}=e.measureDataLabel("observation","outside",u),m=i.get("size",o)/2,h=Tt({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:It(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+m,alignOffset:r+m,labelWidth:d,labelHeight:p});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:u,width:d,height:p,isRotated:!1,target:"observation",position:h.position})}return{labels:t,droppedCount:0}},Cv={place:Rv,getPercentageValueStrategy:()=>"none"},Vv=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}},Qs=e=>{const t=j(e),r=X(e),n=U(e),a=$(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),o=Math.abs(r-t),s=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-s,width:o,height:c}},el=e=>{const t=Qs(e);if(!t)return null;const r=t.width*Nh,n=t.height*Bh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},di=4,Dv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=lt().geomReaders(e.layer);for(const n of e.layer.data){const a=el(n);if(a===null||!Lt(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:o,height:s}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;o+di>c||s+di>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:o,height:s,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return{labels:t,droppedCount:0}},_v={place:Dv,getPercentageValueStrategy:()=>"none"};function Xn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Zn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var Pv=" · ",_r=2,mt=(e,t,r,n)=>{const a=Math.abs(e==="radial"?Math.sin(t):Math.cos(t)),i=Math.abs(e==="radial"?Math.cos(t):Math.sin(t));return a*(r/2)+i*(n/2)},Ov=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=mt("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-_r&&t+i<=e.outerRadiusPx+_r)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=mt("tangential",r,n,a)/t,c=_r/t;return Math.abs(r-e.midAngle)+s<=o+c},Mv=({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,pi=({wedge:e,position:t,offset:r,labelWidth:n,labelHeight:a})=>t==="inside"?{labelRadius:(e.innerRadiusPx+e.outerRadiusPx)/2,labelAngle:e.midAngle,position:"inside"}:{labelRadius:e.outerRadiusPx+r+mt("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},kv=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:o})=>{const s=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+mt("radial",s,i,o);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const p=e.innerRadiusPx-c;u=p>=0?p:e.innerRadiusPx+c}let d=s;if(n!=="center"&&u>0){const p=mt("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:Ov({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},Nv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{position:r,justify:n,align:a,offset:i,showCategoryLabels:o}=e.layer.dataLabels,s=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2,p=lt().geomReaders(e.layer);for(const m of e.layer.data){const{startAngle:h,endAngle:f}=Xn(m),{innerRadius:y,outerRadius:v}=Zn(m);if(h===null||f===null||v===null)continue;const g=e.formatLabel(m);if(g==="")continue;const b=o?e.formatCategory(m):null,I=b===null?g:`${b}${Pv}${g}`,L={startAngle:h,endAngle:f,midAngle:(h+f)/2,innerRadiusPx:(y??0)*d,outerRadiusPx:v*d};let w,E;if(r==="auto"){const T=e.measureDataLabel("observation",s,I);E={width:T.width,height:T.height},w=pi({wedge:L,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const D=c+Math.sin(w.labelAngle)*w.labelRadius,O=u-Math.cos(w.labelAngle)*w.labelRadius;if(w.position==="outside"&&!Mv({x:D,y:O,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const ie=e.measureDataLabel("observation","inside",I);E={width:ie.width,height:ie.height},w=pi({wedge:L,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const T=qn(e.measureDataLabel,"observation",I),D=T[r];w=kv({wedge:L,placement:r,justify:zn(n),align:a,offset:i,labelWidth:D.width,labelHeight:D.height}),E=T[w.position]}const R=c+Math.sin(w.labelAngle)*w.labelRadius,V=u-Math.cos(w.labelAngle)*w.labelRadius;t.push({layerId:e.layer.id,x:R,y:V,text:I,width:E.width,height:E.height,isRotated:!1,target:"observation",position:w.position,...w.position==="inside"?{backdropColor:p.get("color",m)}:{}})}return{labels:t,droppedCount:0}},Bv={place:Nv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Fv=e=>{const t=N({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=N({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},N=e=>{switch(e.valueFormat.type){case"currency":return Ms(e);case"date":return Ry(e);case"datetime":return Cy(e);case"day_month":return Fs(e);case"decimal":return ks(e);case"duration":return Nn(e);case"integer":return Ns(e);case"month":return $s(e);case"month_year":return $n(e);case"percentage":return Bs(e);case"quarter":return Gn(e);case"text":return kn(e);case"weekly_date_range":return Gs(e);case"weekly_date_range_with_year":return Us(e);case"year":return Un(e);case"time":return Hs(e);case"lookup":return Fv({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Jn({layer:e,numberFormat:t,locale:r}){return N({valueFormat:op(e),locale:r,numberFormat:t})}var $v=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:ot(e,t),variable:r}:{read:re,variable:l.GROUP_VARIABLES.group}},tl=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=Jn({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Kv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:Gv({layer:e,numberFormat:n,locale:o})}},Gv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=$v(e.data,e.mapping),i=N({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},Uv=(e,t,r)=>{switch(t){case"stack":return Hv(e);case"fill":return Wv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Hv=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(Ln(a,t));return s===void 0?null:s.total}},Wv=(e,t)=>{const r=t?j:U,n=t?X:$,a=gt(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Kv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=Q(e.data,e.dataLabels.labelSource),c=Uv(e,i,o),u=zv({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=N({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&rl(e);return m=>{const h=s(m);if(h===null)return"";if(!p||!l.isStrictNumericDataValue(h))return u(h,m);const f=c(m);return f===null||f===0?u(h,m):d(h/f)}},zv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(rl(e))return a;const s=Yv(e,r,t,n,o);if(s!==null)return s}return N({valueFormat:qv(e.data,i),locale:n,numberFormat:t})},rl=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(or(e.position,e.mapping))},Yv=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:N({valueFormat:o.valueFormat,locale:n,numberFormat:r})},qv=(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)},Qn={bar:{cartesian:mv,polar:Bv},line:{cartesian:wv},point:{cartesian:Cv},area:{cartesian:tv},tile:{cartesian:_v}},jv=(e,t)=>Qn[e]?.[t]!==void 0,Xv=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:o,formattingLocale:s,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],p=s??a,m=t.type;let h=0;for(const f of e){if(!f.dataLabels.showDataLabels&&!f.dataLabels.showStackTotals&&!f.dataLabels.showCategoryLabels)continue;const y=f.geom,v=Qn[y]?.[m];if(v===void 0)continue;const g=tl({layer:f,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:o,formattingLocale:p,percentageValueStrategy:v.getPercentageValueStrategy(f)}),b=v.place(g);h+=b.droppedCount;for(const I of b.labels)Jv(I,m,c,u)||d.push(I)}return{labels:d,warnings:h>0?[Zv(h)]:[]}},Zv=e=>({code:"DATA_LABELS_DROPPED",severity:"warning",kind:"user-input",message:e===1?"Dropped 1 data label that did not fit under position 'auto'.":`Dropped ${e} data labels that did not fit under position 'auto'.`,suggestion:"Set dataLabels.position to 'outside' to keep labels that do not fit inside the bars.",context:{actual:e}}),Jv=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Qv({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:o}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const s of e){if(!s.dataLabels.showDataLabels&&!s.dataLabels.showStackTotals)continue;const c=Qn[s.geom]?.cartesian;if(c===void 0)continue;const u=tl({layer:s,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:c.getPercentageValueStrategy(s)});for(const d of c.place(u).labels)yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var Pr={abbreviation:"none",decimals:"auto"},nl=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return N({valueFormat:a,locale:e,numberFormat:Pr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/r;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":N({valueFormat:{type:"percentage"},locale:e,numberFormat:Pr,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${N({valueFormat:{type:"decimal"},locale:e,numberFormat:Pr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},eb=2,tb=6,rb=6,nb=15,ab=15,ib=2.5,ob=.5,sb=.25,al=e=>{const t=e-eb,r=1+ob*t,n=1+sb*t;return{arrowStartGap:tb*r,arrowEndGap:rb*r,offsetFromHigherObservation:nb*n,arrowheadSize:ib*e,curveRadius:ab*n,strokeWidth:e}},lb=(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},cb=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Nd=Object.create,po=Object.defineProperty,Bd=Object.getOwnPropertyDescriptor,Fd=Object.getOwnPropertyNames,$d=Object.getPrototypeOf,Gd=Object.prototype.hasOwnProperty,Ud=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=Fd(t),i=0,o=a.length,s;i<o;i++)s=a[i],!Gd.call(e,s)&&s!==r&&po(e,s,{get:(c=>t[c]).bind(null,s),enumerable:!(n=Bd(t,s))||n.enumerable});return e},or=(e,t,r)=>(r=e!=null?Nd($d(e)):{},Ud(t||!e||!e.__esModule?po(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-DBSz4rJf.cjs");let Ae=require("color2k"),mo=require("date-fns"),it=require("lodash-es"),lt=require("d3-time"),Hd=require("date-fns/differenceInDays"),Re=require("d3-regression"),se=require("d3-scale"),je=require("d3-interpolate"),G=require("d3-scale-chromatic"),Je=require("lodash-es/clamp");Je=or(Je,1);let Zt=require("lodash-es/merge");Zt=or(Zt,1);let Hr=require("humanize-duration");Hr=or(Hr,1);let _e=require("d3-shape"),Wd=require("d3-delaunay"),Jt=require("lodash-es/isEqual");Jt=or(Jt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1789643389031");var Kd=1e6;function te(e){return String(Math.round(e*Kd))}var Ma="#FFFFFF",Vr="#1A1A1A",zd=4.5,ho=e=>{try{return(0,Ae.getContrast)(e,Ma)>(0,Ae.getContrast)(e,Vr)?Ma:Vr}catch{return Vr}},Yd=(e,t)=>{try{const r=fo(void 0,t);return r===void 0||(0,Ae.getContrast)(r,e)>=zd?e:ho(r)}catch{return e}},fo=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,Ae.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,Ae.parseToRgba)(e);return r>=1?e:(0,Ae.parseToRgba)(t)[3]<1?void 0:(0,Ae.mix)(t,(0,Ae.opacify)(e,1),r)}catch{return}},ka=0;function W(){return ka+=1,`${Math.random().toString(36).slice(2,6)}${ka.toString(36)}`}var ge=Math.PI*2,qd=8,jd=1e-9,Xd=[0,Math.PI/2,Math.PI,ge*3/4],go=(e,t)=>Math.abs(t-e)>=ge-jd,Pe=e=>(e%ge+ge)%ge,Qt=(e,t,r)=>{if(go(t,r))return!0;const n=Pe(r-t);return Pe(e-t)<=n},Qe=(e,t)=>{const r=Math.abs(Pe(e)-Pe(t));return Math.min(r,ge-r)},Na=(e,t)=>{const r=Pe(t-e);return r>Math.PI?r-ge:r},yo=(e,t,r)=>e*ge+t+r,ye=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Ce=(e,t)=>{const r=ye(e,t);return{x:.5+r.x/2,y:.5+r.y/2}},Zd=(e,t,r,n)=>{const a=[Ce(e,r),Ce(e,n),Ce(t,r),Ce(t,n)],i=Math.max(r,n),o=Xd.filter(c=>Qt(c,e,t)).map(c=>Ce(c,i)),s=[...a,...o];return{xMin:Math.min(...s.map(c=>c.x)),xMax:Math.max(...s.map(c=>c.x)),yMin:Math.min(...s.map(c=>c.y)),yMax:Math.max(...s.map(c=>c.y))}},sr=(e,t)=>({angle:Pe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),lr=(e,t)=>{const r=e.x-.5,n=e.y-.5;return{x:t>=1?r*2*t:r*2,y:t>=1?n*2:n*2/t}},mn=(e,t)=>{const{x:r,y:n}=lr(e,t);return sr(r,n)};function k(e){return e[l.POSITION_VARIABLES.x]}function _(e){return e[l.POSITION_VARIABLES.y]}function j(e){return e[l.POSITION_VARIABLES.xMin]}function X(e){return e[l.POSITION_VARIABLES.xMax]}function U(e){return e[l.POSITION_VARIABLES.yMin]}function $(e){return e[l.POSITION_VARIABLES.yMax]}function hn(e){return e[l.POSITION_VARIABLES.yRaw]}function Jd(e,t){return e[l.resolveScaledAestheticVariable(t)]}var Qd={xMin:0,xMax:1,yMin:0,yMax:1},vo=(e,t)=>{const r=j(e)??k(e),n=X(e)??k(e),a=U(e)??_(e),i=$(e)??_(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a)||!l.isStrictNumericDataValue(i)?null:t.type!=="polar"?{xMin:r,xMax:n,yMin:a,yMax:i}:{...Zd(r,n,a,i),frame:"disk"}},gt=(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}}},bo=e=>gt(Qd,e),Q=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},ot=(e,t)=>Q(e,t.x),fn=(e,t)=>Q(e,t.y),ep=(e,t)=>Q(e,t.label),So=(e,t)=>Q(e,t.color),tp=(e,t)=>Q(e,t.size),rp=(e,t)=>Q(e,t.alpha),np=(e,t)=>Q(e,t.group),ap=(e,t)=>Q(e,t.strokeWidth),Ba={variable:l.POSITION_VARIABLES.yRaw};function cr(e,t){return l.isStackedPosition(e)?Ba:t.y??Ba}function yt(e){return Q(e.data,cr(e.position,e.mapping))}var ke=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},gn=e=>ip(e)?l.extractVariableName(e.mapping.y):null,xo=e=>gn(e)===null?null:yt(e),yn=e=>e.spatialKind!=="cells",ip=e=>e.spatialKind==="points"||e.spatialKind==="cells",Ao=(e,t)=>e.yScaleType===t.yScaleType&&Kr(e.valueFormat)===Kr(t.valueFormat),Wr=e=>`${e.yScaleType} y axis, ${Kr(e.valueFormat)}`,Kr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Io=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(ke(e))),n=gn(e);return a=>({...a,anchorValue:l.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:l.parseAddressingValue(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:l.parseAddressingValue(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function To(e){return e instanceof l.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function P(e,t){return wo(e,t)}function C(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 Lo(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Ne(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 wo(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const o=e[a];if(l.isPlainObject(i)&&l.isPlainObject(o)){const s=wo(o,i);s!==o&&(n[a]=s,r=!0)}else i!==void 0&&i!==o&&(n[a]=i,r=!0)}return r?n:e}function ur(e){return{pipe:t=>{const r=t(e);return ur({...e,...r})},result:()=>e}}var op=(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},vn=e=>e.type==="polar"?"disk":"panel",dr=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},Fa=(e,t)=>{if(e.frame!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=dr(e.frame,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function Z(e,t){return e==="x"?t.x:t.y}function ve(e,t){return e==="x"?t.y:t.x}function et(e,t){return{main:Z(e,t),cross:ve(e,t)}}function $a(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function sp(e){return e.type==="cartesian"}var re=e=>e[l.GROUP_VARIABLES.group],vt=e=>{const t=ke(e),r=xo(e),n=yn(e)&&t!==l.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const o=r===null?null:r(a);if(r!==null&&o===null)return null;const s=n?re(a)??null:null;return{layerId:e.id,anchorValue:i,...o!==null&&{crossValue:o},...s!==null&&{groupValue:s}}}},tt=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,lp={type:"decimal"};function Eo(e){return e.length>0&&e.every(t=>t.data.size()===0)}function bn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):lp}function cp(e){return bn(e,l.extractVariableName(e.mapping.y))}function Ro({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??cr(t,r)}function Co(e,t){const r=Ro({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:Q(e.data,r),valueFormat:bn(e,a)}}var Vo=e=>{const t=ke(e),r=xo(e),n=yn(e);return(a,i)=>!l.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||l.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:l.areDataValuesEqual(re(a),i.groupValue)},Do=e=>{const t=l.extractVariableName(e.mapping.y),r=yt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null};var up=["lt","lte","gt","gte","range"],dp={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"}},fe=()=>!1,Ue=()=>!0;function Be(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Do(e),parsingLocale:t}}function le(e,t){if("and"in e){const r=e.and.map(n=>le(n,t)).filter(n=>n!==Ue);return r.includes(fe)?fe:r.length===0?Ue:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>le(n,t)).filter(n=>n!==fe);return r.includes(Ue)?Ue:r.length===0?fe:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=le(e.not,t);return r===fe?Ue:r===Ue?fe:n=>!r(n)}return mp(e,t)}function ce(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>ce(n,t,r)):"or"in e?e.or.flatMap(n=>ce(n,t,r)):"not"in e?ce(e.not,t,r):pp(e,t,r)}function pp(e,t,r){const{subject:n,effect:a}=dp[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=hp(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 mp(e,t){if(!t.hasVariable(e.variable))return fe;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>l.parseAddressingValue(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);if(a.length>=32){const i=new Set,o=new Set;for(const s of a)l.isStrictTemporalDataValue(s)?o.add(s.getTime()):i.add(s);return s=>{const c=t.readValue(s,e.variable);return l.isStrictTemporalDataValue(c)?o.has(c.getTime()):!Number.isNaN(c)&&i.has(c)}}return i=>{const o=t.readValue(i,e.variable);for(const s of a)if(l.areDataValuesEqual(o,s))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>He(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const o=He(t.readValue(i,e.variable),a);return o==="less"||o==="equal"}}if("gt"in e){const a=n(e.gt);return i=>He(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const o=He(t.readValue(i,e.variable),a);return o==="greater"||o==="equal"}}if("range"in e){const[a,i]=e.range,o=n(a),s=n(i);return c=>{const u=t.readValue(c,e.variable),d=He(u,o),p=He(u,s);return d==="incomparable"||p==="incomparable"?!1:(d==="greater"||d==="equal")&&(p==="less"||p==="equal")}}return fe}function hp(e){for(const t of up)if(t in e)return t;return null}function He(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 fp=(e,t,r,n,a,i)=>{const o=Po(e,t,r.predicate,n,a,i);if(o===null)return null;const s=_o(r.padding),c=s===null?vp(o,r.padding):o,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin),frame:c.frame};return s===null?u:{...u,defer:s}},gp=(e,t,r,n,a,i)=>{const o=Po(e,t,r.predicate,n,a,i);return o===null?null:{...gt(o,r.align),frame:o.frame}},_o=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Po=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let o=null,s=!1;const c=new Map;for(const u of n){if(!u.interactive)continue;const d=ce(r,u.data,"selection-anchor");if(d.length>0){for(const m of d)c.set(`${m.code}:${m.message}`,m);continue}s=!0;const p=le(r,Be(u,i));if(p!==fe)for(const m of u.data){if(!p(m))continue;const h=vo(m,a);h!==null&&(o=o===null?h:yp(o,h))}}if(!s)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,o),o},yp=(e,t)=>({frame:e.frame,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),vp=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},er=(e,t,r)=>{const n=Sp(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:xp(n,t.offset,e.coordSystem)},Oo=(e,t)=>t.anchorType==="selection"?fp(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},Sn=(e,t,r)=>zr(e,t,r)?.point??null,zr=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const o of t){const s=e.geomRegistry.get(o.geom),{resolveAnchorPosition:c}=s;if(c===void 0||a.layerId!==void 0&&o.id!==a.layerId||a.layerId===void 0&&!o.interactive)continue;const u=Co(o,s),d=Vo(o),p=vt(o),m=Io(o,n)(a);let h=-1;for(const f of o.data){if(h+=1,!d(f,m))continue;const y=c(f,{coordSystem:r,position:o.position,purpose:i,align:a.align});if(y===null)continue;const v=Mo(o,f,u);if(v===null)continue;const g=p(f);if(g!==null)return{point:{...y,...v,frame:vn(r),observationIndex:h,anchor:a.align===void 0?g:{...g,align:a.align}},layerId:o.id}}}return null},bp=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const o=a.x,s=a.y;if(o===void 0||s===void 0||o.kind!=="position"||s.kind!=="position")return null;const c=Ua(t.x,"x",r,i),u=Ua(t.y,"y",r,i);if(c===null||u===null)return null;const d=o.map(c),p=s.map(u);if(!tt(d,p))return null;const m=Ga(d,o,Ap(e)),h=Ga(p,s),f=$a(n.mainAxis,{main:m.min,cross:h.min}),y=$a(n.mainAxis,{main:m.max,cross:h.max});return gt({xMin:f.x,xMax:y.x,yMin:f.y,yMax:y.y},t.align??"center")},Mo=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:op(r.valueFormat,t),yScaleType:e.yScaleType}:null},Sp=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return bp(e,t);case"selection":return gp(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 Sn(e,Ip(t),r)}},xp=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=_o(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Ga=(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}},Ap=({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},Ip=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Ua=(e,t,r,n)=>{for(const a of r){const i=l.extractVariableName(a.mapping[t]);if(!(i===null||i===l.CONSTANT_VARIABLES.x))return l.parseValue(e,l.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Tp=class extends l.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,o={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},s={differenceArrows:Mp(o,t.differenceArrows),shapes:Rp(o,t.shapes),arrows:Vp(o,t.arrows),textAnnotations:Dp(o,t.textAnnotations),images:Cp(o,t.images),stickers:_p(o,t.stickers),pinnedNumbers:Pp(o,t.pinnedNumbers),comments:Op(o,t.comments)};return Lp(this.container,s),wp(this.container,s),s}},ue=(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."})},Lp=(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)}},wp=(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 Ep(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."})},Ep=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},Rp=(e,t)=>{const r=[];for(const n of t){const a=Oo(e,n.region);if(a===null){ue(e.container,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},Cp=(e,t)=>{const r=[];for(const n of t){const a=Oo(e,n.region);if(a===null){ue(e.container,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},Vp=(e,t)=>{const r=[];for(const n of t){const a=er(e,n.start,"pin"),i=er(e,n.end,"pin");if(a===null||i===null){ue(e.container,"arrow",n.id,`has ${ko(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Dp=(e,t)=>{const r=[];for(const n of t){const a=er(e,n.at,"pin");if(a===null){ue(e.container,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},_p=(e,t)=>{const r=[];for(const n of t){const a=er(e,n.at,"pin");if(a===null){ue(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},Pp=(e,t)=>{const r=[];for(const n of t){const a=Sn(e,n.at,"pin");if(a===null){ue(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Op=(e,t)=>{const r=[];for(const n of t){const a=Sn(e,n.at,"pin");if(a===null){ue(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Mp=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ue(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=zr(e,n.start,"value"),i=zr(e,n.end,"value");if(a===null||i===null){ue(e.container,"differenceArrow",n.id,`has ${ko(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ue(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}kp(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},ko=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",kp=(e,t,r,n)=>{Ao(r,n)||e.container.diagnostics.addWarning({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:Wr(r),actual:Wr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Np(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const o of Object.keys(i))r.has(o)||r.set(o,[]);for(const a of e)for(const i of a.observations)for(const[o,s]of r)s.push(o===t?a.kind:i[o]??null);const n={};for(const[a,i]of r)n[a]={type:No(i),values:i};return new l.Dataset(n)}function No(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 Bp=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,No(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Fe=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},Fp=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)}},$p=class extends Fe{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,t){const[r]=this.registry.get(t.coordSpec.coordType).transform({coordSpec:t.coordSpec,coordSystem:t.coordSystem,layers:[e]});if(!r)throw new l.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},Gp=class{constructor(e){this.setupStage=new Fp(e),this.transformStage=new $p(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)}},Up=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}},Hp=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:Kp(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Yp(t))}},Wp=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ha=l.prefixInternalVariable("flipSwap"),Kp=(e,t)=>zp(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,zp=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},Yp=e=>{let t=e.data;for(const[r,n]of Wp){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ha).renameVariable(n,r).renameVariable(Ha,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function Bo(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 Fo=(e,t)=>Bo(t.domain!==null&&t.domain.length>0?t.domain:e),qp=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=Zp(t,e.scales,e.layers),a=Qp(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=Xp(r,n),i=em(t);return e.layers.map(o=>tm(t.theta==="y"?rm(o):o,a,i))}},jp=[[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 Xp(e,t){return r=>yo(r,e,t)}function Zp(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Jp(n,e,r);return a===0?0:-Math.PI/a}function Jp(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const o of a.data.getValues(i))n.push(o)}return Fo(n,e).length}function Qp(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 em(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function tm(e,t,r){let n=e.data;return n=We(n,l.POSITION_VARIABLES.x,t),n=We(n,l.POSITION_VARIABLES.xMin,t),n=We(n,l.POSITION_VARIABLES.xMax,t),n=We(n,l.POSITION_VARIABLES.y,r),n=We(n,l.POSITION_VARIABLES.yMin,r),n=We(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function We(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 rm(e){let t=e.data;for(const[r,n]of jp){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const o=a?t.getValues(r):null,s=i?t.getValues(n):null;o&&(t=t.addVariable(n,"numeric",o)),s&&(t=t.addVariable(r,"numeric",s))}return{...e,data:t}}var nm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Up),this.register("flip",new Hp),this.register("polar",new qp)}},$o=new Set(["min","max","scalar"]),am={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function im(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 om(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 sm(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=am[a.axis][a.role];if(n.hasVariable(i))continue;const o=l.extractVariableName(r[a.aes]);!l.isDefined(o)||!n.hasVariable(o)||(n=n.addVariable(i,"numeric",n.getValues(o,{type:"numeric"})))}return n}var lm=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:sm(n.data,r.positionRoles,a)}}},xn=["x","y"],An=new Set(["x","y","ySecondary"]),bt=new Set(["color","size","alpha","strokeWidth","lineType"]),Te=e=>An.has(e),In=e=>bt.has(e),Go=e=>Te(e)||In(e);function Le(e){return e==="secondary"?"ySecondary":"y"}function Uo(e,t){return e==="y"?Le(t):"x"}function H(e){return e==="ySecondary"?"y":e}var be=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of bt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},pr=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:be(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),cm=class{compute({data:e,mapping:t}){const r=be(e,t);if(r.length===0)return{data:e.addConstantVariable(l.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(o=>e.getValues(o)),i=new Array(n);for(let o=0;o<n;o++)i[o]=l.getStableKey(a.map(s=>s[o]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},um=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},dm=(e,t,r)=>{const n=Oe(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Oe(e,t){const r=H(t);for(const n of Ho(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var mr=(e,t)=>e===null?null:t[e]??e,pm=(e,t)=>e===null?null:t[String(e)]??null,Me=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return Dr(t);for(const n of e){if(!n.data.hasVariable(r))continue;const a=n.data.getValueFormat(r),i=a.type==="lookup"?a.fallback:a;return hm(i,t)?i:Dr(t)}return Dr(t)},mm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Ho(t,e).some(r=>r.position==="fill");function Ho(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var Dr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},hm=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},fm=[{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}],Wa={year:0,quarter:1,month:2,week:3,day:4,hour:5},Ke=40,gm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Sm(r.unit).range(e,new Date(t.valueOf()+1),n)},ym=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Hd.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}},vm=(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"}}},bm=(e,t)=>{const r=xm(t);return r===null?!1:Wa[e]>Wa[r]},Sm=e=>{switch(e){case"hour":return lt.utcHour;case"day":return lt.utcDay;case"week":return lt.utcMonday;case"month":case"quarter":return lt.utcMonth;case"year":return lt.utcYear}},xm=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}},Wo={left:"right",right:"left",top:"bottom",bottom:"top"},Am={x:!0,y:!0,ySecondary:!1},Im=20,Ka=new Set(["top","bottom"]),Tm={type:"percentage"};function Lm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:o,geomRegistry:s}=e;if(Eo(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Rm(s,a,i.type,n),u=new Set(t.map(m=>m.position)),d=Vm(Ko(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const m of An){const h=r[m];if(!l.isDefined(h)||h.kind!=="position")continue;const f=wm({scaleAestheticKey:m,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:o});p.push(f)}return p}function wm(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:o,gridOverrides:s,variableLabels:c}=e,{axisConfig:u,position:d,geometry:p}=Cm(t,n,i,o),m=Oe(a,t),h=mm(a,t)?Tm:Me({layers:a,scaleType:r.spec.scaleType,variableName:m});return{scaleAestheticKey:t,position:d,geometry:p,label:Em(u,m,c),isVisible:u.isVisible,tickCandidates:_m(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Dm(u,s,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Em(e,t,r){return e.label?e.label:t?r[t]??null:null}function Rm(e,t,r,n){const a=t.flatMap(s=>{const c=e.get(s.geom).grid[r];return c?[c]:[]}),i=a.some(s=>s.hideGridX),o=a.some(s=>s.hideGridY);return{x:{gridVisible:za(i,n.axes.x.grid.isVisible)},y:{gridVisible:za(o,n.axes.y.grid.isVisible)}}}function za(e,t){if(e&&t===null)return!1}function Cm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Ko(t.axes[e].position,r[e].position),geometry:r.x.geometry};case"y":return{axisConfig:t.axes[e],position:n,geometry:r.y.geometry};case"ySecondary":{const a=Wo[n],i=(0,it.merge)({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:i,position:i.position,geometry:r.y.geometry}}}}function Ko(e,t){return Ka.has(e)===Ka.has(t)?e:t}function Vm(e,t){return t.has(e)?Wo[e]:e}function Dm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Am[r]}var _m=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Om(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let o=1;o<=Im;o++){const s=e.generateTicks({count:o}),c=l.getStableKey(s);a.has(c)||(a.add(c),i.push({ticks:s.map(u=>rt(e,u))}))}return i}return e.spec.scaleType==="datetime"?Pm(e,t):[{ticks:e.generateTicks().map(a=>rt(e,a))}]},Pm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(s=>rt(e,s))}];const a=new Set,i=[],o=(s,c)=>{if(s.length===0)return;const u=l.getStableKey(s);a.has(u)||(a.add(u),i.push({ticks:s.map(d=>rt(e,d)),valueFormat:c}))};for(const s of fm)ym({...s,start:r,stop:n})||bm(s.unit,t)||o(e.generateTicks({interval:s}),vm(s,t));return o(e.generateTicks({atInputs:!0})),i.sort((s,c)=>s.ticks.length-c.ticks.length),i},Om=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[rt(e,r),rt(e,n)]}},rt=(e,t)=>({value:t,position:e.map(t)});function zo({scale:e,aesthetics:t,layers:r}){const n=Mm({layers:r,aesthetics:t}),a=Yo({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Mm({layers:e,aesthetics:t}){const r=Yo({layers:e,aesthetics:t}),n=e.find(i=>t.some(o=>l.isDefined(i.mapping[o]))),a=n?n.geom:"bar";return i=>{const o=r(i);return o?o.layer.geom:a}}function Yo({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const o=t.find(c=>l.isDefined(i.mapping[c]));if(o===void 0)continue;const s=l.extractVariableName(i.mapping[o]);if(!(s===null||!i.data.hasVariable(s)))for(const c of i.data.getValues(s,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var Tn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function km({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!Tn(n))return[];if(!t.some(s=>l.isDefined(s.mapping.color)))return[];const a=Oe(t,"color");if(qo({colorVariableName:a,xVariableName:Oe(t,"x"),mapsColorAcrossMultipleLayers:Bm(t)>1,isMergedWithAnotherAesthetic:Nm(e,t,a)}))return[];const i=n.spec.scaleType,o=t.findIndex(s=>l.isDefined(s.mapping.color));return zo({scale:n,aesthetics:["color"],layers:t}).map(({value:s,geom:c,owner:u})=>{const d=u?.layerIndex??o,p=t[d],m=p?l.extractVariableName(p.mapping.color):null;return{value:s,color:String(n.map(s)),geom:c,layerIndex:d,valueFormat:Me({layers:p?[p]:t,scaleType:i,variableName:m}),label:pm(s,r)}})}var qo=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Nm(e,t,r){if(r===null)return!1;for(const n of bt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!Tn(a))&&Oe(t,n)===r)return!0}return!1}var Bm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function jo(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Fm(e,t,r,n){const a=r.findIndex(i=>jo(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:mr(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function Ya(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 Xo=e=>e==="none"?"first":e,$m=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=qa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=qa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Gm=(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}},qa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Um(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Hm(e,n):Wm(e,n)}function Hm(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(s=>s.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const o=l.extractVariableName(a.mapping.y);return o===null?null:{kind:"grandTotal",value:i,valueFormat:Me({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:o})}}function Wm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:o,geomRegistry:s}=e;if(!a.some(d=>jo(s,d)))return null;const c=Fm(s,o,a,i);if(c.length===0)return null;const u=c.map(d=>Km({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 Km({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const o=l.extractVariableName(i.mapping.y);if(o===null||t==="total"&&i.position==="fill")return null;const s=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Me({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:o}),p=qm(i.data,s),m=Me({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:s}),h=jm(i.data,s),f=h.getValues(o,{type:"numeric"}),y=s!==null?h.getValues(s):[],v=c!==null?h.getValues(c):null,g=Ya(f,v,e.value),b=Ya(y,v,e.value);return{value:e.value,swatch:e.swatch,aggregate:$m(g,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:m,label:e.label,caption:zm(t,p,b),comparison:Ym(t,r,p,b,g)}}function zm(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 Ym(e,t,r,n,a){return e!=="current"||!r?null:Gm(n.map((i,o)=>({main:i,cross:a[o]??null})),Xo(t))}function qm(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function jm(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function ae(e,...t){return e?t.includes(e.geom):!1}function F(e,t){return e.find(r=>r.id===t)}function we(e,...t){return e.find(r=>t.includes(r.geom))}function Xm(e,...t){return e.filter(r=>t.includes(r.geom))}function Ln(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function wn(e){const t=e.filter(r=>!Ln(r,e));return t.length>0?t:e}function Zo({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=wn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Zm=3;function Jm({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:o}){if(t.legend.position==="none")return{drawn:[],position:"none"};const s=new Map(i.map(v=>[l.getStableKey(v.value),v])),c=oh(rh({scales:e,layers:r})),u=Oe(r,"x"),d=c.map(v=>{if(ah(v,u,r))return null;const g=lh({group:v,variableLabels:a,layers:r,colorGroupsByValue:s});return g.items.length===0?null:{group:v,built:g}}).filter(l.isDefined),p=Qm(d),m=wn(r),h=hh(o,t.legend.position,p,m,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&mh(o,p,m,n))return{drawn:[],position:h};const f=fh(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),y=f==="direct"?bh(m[0]):null;return{drawn:d.map(({built:v})=>eh(v,{position:h,display:f,align:t.legend.align},y)),position:h}}function Qm(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function eh(e,t,r){const{position:n,display:a}=t,i=th(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(o=>({...o,normalizedY:r.get(String(o.value))??null}))}}function th(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function rh(e){const{scales:t,layers:r}=e,n=[];for(const a of bt){const i=t[a];if(i===void 0||i.kind==="identity"||!nh(a,r))continue;const o=Oe(r,a),s=vh(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:o,guideType:s})}return n}function nh(e,t){const r=H(e);return t.some(n=>l.isDefined(n.mapping[r]))}function ah(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:qo({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:ih(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function ih(e,t){const r=H(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function oh(e){const t=new Map;for(const r of e){const n=yh(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function sh(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function lh({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>H(u.scaleAestheticKey)),o=zo({scale:a.scale,aesthetics:i,layers:r}),s=Me({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),c=r.find(u=>i.some(d=>l.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:mr(a.variableName,t),items:o.map(u=>ch(u,e,i,s,n,c))}}function ch(e,t,r,n,a,i){const o={};for(const c of t)sh(o,c.scaleAestheticKey,c.scale.map(e.value));if(o.color===void 0&&r.includes("size")&&(o.color=l.DEFAULT_GEOM_COLOR),o.lineType===void 0){const c=l.extractConstantValue(e.owner?.layer.mapping.lineType);l.isLineStyleType(c)&&(o.lineType=c)}const s=dh(e,t,r,n,a);return{value:e.value,label:uh(t,e,a),visual:o,normalizedY:null,geom:e.geom,valueFormat:s,layerId:e.owner?.layer.id??i}}function uh(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function dh(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,o=ph(i,r);return i===void 0||o===null?n:Me({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:o})}function ph(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 mh(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 hh(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,o=!1,s=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(o=!0,l.isStackedPosition(u.position)&&(s=!0))}const c=r>=Zm;return i&&o?"top":i?c?"right":"top":s?gh(a)?"top":c?"right":"top":"top"}function fh(e,t){return e==="pill"?"pill":Zo(t)?"direct":"pill"}function gh(e){return e.type==="cartesian"&&e.mainAxis==="y"}function yh(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function vh(e,t){return Tn(t)?"discrete":`continuous:${e}`}function bh(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(_(c)));if(!n)return;const a=re(n);if(!l.isDefined(a))return;const i=U(n),o=$(n)??_(n);if(!l.isDefined(o))return;const s=l.isDefined(i)?(i+o)/2:o;t.set(String(a),s)}),t}var Sh=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=um(e.originalData),r=km({scales:e.scales,layers:e.layers,valueLabels:dm(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=Um(n),i=Jm(n),o={...i,drawn:xh(a,i.drawn)};return{axes:Lm(n,o.drawn),legends:o,headline:a,colorGroups:r,variableLabels:t}}},xh=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],pt=(e,t,r)=>{switch(e){case"series":return Ah(t);case"x-value":return En(t,r)}},St=e=>{const t=l.readMainAxisVariable(e);return t===""?null:t},Ah=e=>l.getStableKey([re(e)]),En=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Ih={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function Jo(e){const t=Ih[e]??null;return t===null?null:{strategy:t,composition:Qo()}}function Qo(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Th=class extends Fe{constructor(e){super(),this.container=e}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,t){const r=e.highlight;if(r===null)return e;const n=t.highlights.filter(({layerId:i})=>i===void 0||i===e.id);if(n.length===0)return e;const a=Lh({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Lh({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const D=ce(T.predicate,e.data);for(const O of D)a.diagnostics.addWarning({...O,message:`${O.message} Dropping this highlight.`});return D.length===0}),o=St(e.mapping),s=Be(e,r),c=i.map(T=>({predicate:le(T.predicate,s),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),p=n==="overlay-anchor",m=e.data.size(),h=u?new Array(m):null,f=d?new Array(m):null,y=p?new Array(m):null,v=new Uint8Array(m),g=new Set,b=new Set;let I=!1,L=0;for(const T of e.data){let D,O;h!==null&&(D=pt("series",T,o),h[L]=D),f!==null&&(O=pt("x-value",T,o),f[L]=O),y!==null&&(y[L]=T);for(const{predicate:ie,scope:Nt}of c)if(ie(T))switch(Nt){case"series":D!==void 0&&g.add(D);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":v[L]=1,I=!0;break}L++}if(g.size===0&&b.size===0&&!I)return Qo();const w=new Uint8Array(m),E=[];let R=0;for(let T=0;T<m;T++){const D=h?.[T],O=f?.[T],ie=D!==void 0&&g.has(D),Nt=O!==void 0&&b.has(O),Pa=v[T]===1;if(n==="observation-rerender")(ie||Pa||Nt)&&(w[T]=1,R++);else if(ie)w[T]=1,R++;else if(Pa||Nt){const Oa=y?.[T];Oa!==void 0&&E.push({observation:Oa,observationIndex:T})}}const V=R>0?{...e,data:e.data.filterByMask(w)}:null;return{isDimmed:(n==="observation-rerender"||g.size>0)&&V!==null,matchedLayer:V,overlayCandidates:E}}var wh=l.prefixInternalVariable("__ungrouped__");function Eh(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),o=new Map,s=i.map((c,u)=>{if(c===null)return null;const d=r[u]??wh;let p=o.get(d);return p||(p=new l.ChronologicalDateManager,o.set(d,p)),p.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",s)}return n}var Rh=()=>({defaults:[],overrides:[],warnings:[]}),Ch=class extends Fe{constructor(e,t,r,n,a,i){super(),this.container=e,this.transformCompiler=t,this.statCompiler=r,this.groupCompiler=n,this.geomCompiler=a,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,ja(e),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},xScaleIsDiscrete:ja(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=ur({data:t,mapping:r}).pipe(({data:s,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:s,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>({data:this.groupCompiler.compute({data:s,mapping:c}).data,mapping:c})).pipe(({data:s,mapping:c})=>({data:Eh(s),mapping:c})).pipe(({data:s,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:s,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:s,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),o=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:o.spatialKind,identityKey:o.identityKey,tooltip:o.tooltip,supportsDirectLabels:o.legend.directLabelSupport?.[e.position]===!0,highlight:Jo(e.geom),styles:Rh()}}};function ja(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function es(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Vh(e,t){return t.some(r=>l.isStackedPosition(r.position)||e.get(r.geom).scaleConstraints?.bandPadding===0)}function Yr(e,t){const r=ts(e,t),n={};for(const{layer:i,scaleConstraints:o,crossAxis:s}of r)o.zeroBaseline===!0&&(n[s]={nice:(n[s]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:_h(r),zeroAxes:n,bandPadding:Ph(r),inferredColor:r.some(({scaleConstraints:i})=>i.inferredColor===!0)}}function Dh(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:Xa(n),zeroAnchored:Xa(a)}}return null}var Xa=({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:Le(n.yScaleType)})}),r}function _h(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.discreteMainAxis===!0&&t.add("x"),r.discreteCrossAxis===!0&&t.add(n);return[...t]}function Ph(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of Oh(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function Oh({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var Mh=new Set(["label","group"]),kh=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},o={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(o));const s=[...this.collectUndeclaredAesthetics(o),...this.collectPanelJustifyWarnings(o)];for(const c of s)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),es(this.container.diagnostics,t)}checkPostCompile(e){Eo(e)&&this.container.diagnostics.addWarning({code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."})}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:o,showDataLabels:s}=i;if(!s||o!=="panel-start"&&o!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!pr(r,t))return[];const c=o==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${o}' will render as '${c}'.`,context:{layerIndex:n,expected:c,actual:o},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:o,aesthetics:s}=this.container.geomRegistry.get(r),c=[...im(o),...s.filter(p=>p.required).map(p=>p.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const p of c)d.has(p)||l.isDefined(a[p])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${p}'`,context:{layerIndex:t,aesthetic:p}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=s,d=new Set(c);for(const[p,m]of Object.entries(a)){if(u.has(p))continue;const h=l.extractVariableName(m);h===null||h===""||d.has(h)||i.hasVariable(h)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${p}' references variable '${h}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:p,variableName:h}})}return o}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=s,u=[];for(const d of o){if(!$o.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const p=l.extractVariableName(a[d.aes]);if(p===null||!i.hasVariable(p)||i.size()===0)continue;const m=i.getType(p);m!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${p}' is ${m}`,context:{layerIndex:t,aesthetic:d.aes,variableName:p,variableType:m},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:o}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:o}).map(s=>({...s,message:`Layer '${e}': ${s.message}`,context:{...s.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Dh(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:o}=this.container.geomRegistry.get(r),{computedVariables:s}=this.statRegistry.get(n.type),c=new Set([...om(i),...o.map(m=>m.name)]),u=Mh,d=s,p=[];for(const m of Object.keys(a))l.isDefined(a[m])&&(c.has(m)||u.has(m)||d.has(m)||p.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${m}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:m}}));return p}},Se=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=l.POSITION_TYPES,this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,it.merge)({},this.defaultParams,e.params)}},Rn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},Cn=(e,{coordSystem:t})=>{const r=k(e),n=_(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:t.type==="polar"?Ce(r,n):{x:r,y:n}},Nh=class extends Se{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="filled-buckets",this.resolveAnchorPosition=Cn}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=Rn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Bh=.7,Fh=.1,$h=.03,Gh=.05,rs=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Uh=class extends Se{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveDataLabelDefaults=t=>l.isStackedPosition(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>qr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(i!==void 0){const p=vo(t,r);return p===null?null:gt(p,i)}if(r.type==="polar")return Hh(t);const o=l.isStackedPosition(n),s={isSolo:!o||rs(t)==="solo",isNegative:o&&Wh(t),purpose:a};if(r.mainAxis==="x"){const p=j(t),m=X(t),h=Za({lowerBound:U(t),upperBound:$(t)??_(t),options:s});return p===null||m===null||h===null?null:{x:(p+m)/2,y:h}}const c=U(t),u=$(t),d=Za({lowerBound:j(t),upperBound:X(t)??k(t),options:s});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=qr(r,n);e=Rn(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}},qr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Bh,Hh=e=>{const t=j(e),r=X(e),n=U(e),a=$(e);return t===null||r===null||n===null||a===null?null:Ce((t+r)/2,(n+a)/2)},Wh=e=>{const t=hn(e);return l.isStrictNumericDataValue(t)&&t<0},Za=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},Kh=class extends Se{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=Cn}compile(e){return{data:Rn(e.data,e.mapping),mapping:{}}}},zh=class extends Se{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=Cn,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:{}}}},Yh=class extends Se{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=Ja(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=Ja(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}}}},Ja=(e,t)=>{const r=l.extractConstantValue(e);if(l.isStrictNumericDataValue(r))return{value:r,sourceFormat:void 0};const n=l.extractVariableName(e);if(n===null||!l.isStatVariable(n)||!t.hasVariable(n))return null;const[a]=t.getValues(n);return l.isStrictNumericDataValue(a)?{value:a,sourceFormat:t.getValueFormat(n)}:null},qh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},jh=class extends Se{constructor(...e){super(...e),this.type="tile",this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian"],this.aesthetics=[{kind:"visual",name:"color",required:!0}],this.scaleConstraints={discreteMainAxis:!0,discreteCrossAxis:!0,bandPadding:0,inferredColor:!0},this.grid={cartesian:{hideGridX:!0,hideGridY:!0}},this.legend={suppressWhenSingleItem:!1},this.dataLabels={cartesian:{showDataLabels:!0}},this.dataLabelCoordTypes=["cartesian"],this.highlightStrategy="observation-rerender",this.spatialKind="cells",this.identityKey="x-y",this.tooltip=[{aes:"color"}],this.resolveValueSource=qh,this.resolveAnchorPosition=t=>{const r=j(t),n=X(t),a=U(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:{}}}},Xh=[new Uh,new zh,new Kh,new Nh,new Yh,new jh],hr=class extends l.Registry{constructor(){super("geom");for(const e of Xh)this.register(e.type,e)}},$e=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},Zh=class extends $e{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,...be(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},Jh=class extends $e{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Qh=class extends $e{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}}}},ef=2,ns=1440*60*1e3,tf=class extends $e{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'smooth' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'smooth' stat."});if(!l.isDefined(i))throw new l.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'smooth' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'smooth' stat."});const o=e.getType(a),s=e.getType(i);if(s!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${s}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:s}});const c=be(e,t),u=cf(a,o,i,c,e);return c.length===0?Qa({data:e,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const p=uf(d,c);Qa({data:d,xVariable:a,xType:o,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Qa=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:o,xScaleIsDiscrete:s})=>{const{observations:c,temporalOrigin:u}=rf({data:e,xVariable:t,yVariable:n,xType:r});c.length<ef||(s?lf({observations:c,spec:a,output:i,groupObservation:o}):of({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:o}))},rf=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),o=n==="temporal"?nf(a):null,s=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!l.isDefined(d)||!l.isDefined(p)||!Number.isFinite(p))continue;const m=af({xValue:d,xType:n,categoryRank:c,temporalOrigin:o});m!==null&&s.push({x:m,y:p,originalX:d})}return{observations:s,temporalOrigin:o}},nf=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},af=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!l.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!l.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/ns+1}case"categorical":{if(!l.isStrictCategoricalDataValue(e))return null;const a=r.get(e);if(a!==void 0)return a;const i=r.size+1;return r.set(e,i),i}default:throw new l.InternalError({message:`Unexpected xType: ${t}`})}},of=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const o=as(n,e);for(const[s,c]of o){if(!Number.isFinite(s)||!Number.isFinite(c))continue;const u=t==="temporal"?sf(s,r):s;a.push({x:u,y:c,groupObservation:i})}},sf=(e,t)=>t===null?new Date(e):new Date((e-1)*ns+t),lf=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const s of e)a.has(s.x)||a.set(s.x,s.originalX);const i=[...a.keys()].sort((s,c)=>s-c);if(t.method==="loess"){const s=as(t,e),c=new Map;for(const[u,d]of s)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const o=is(t,e);for(const s of i){const c=a.get(s),u=o.predict(s);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},as=(e,t)=>e.method==="loess"?(0,Re.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):is(e,t),is=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,Re.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,Re.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,Re.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,Re.regressionQuad)().x(r).y(n)(t);case"power":return(0,Re.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,Re.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},cf=(e,t,r,n,a)=>{const i=[],o=[],s=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),o.push(u);for(const p of n)s[p]?.push(d[p]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:o,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:s[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},uf=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},df=class extends $e{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],...be(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},pf=[new Jh,new Zh,new tf,new Qh,new df],mf=class extends l.Registry{constructor(){super("stat");for(const e of pf)this.register(e.type,e)}};function hf({geoms:e,stats:t,transforms:r}){const n=new hr,a=new mf,i=new l.TransformRegistry;for(const o of e)n.register(o.type,o);for(const o of t)a.register(o.type,o);for(const o of r)i.register(o.transformType,o);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}function Vn(e){if("definition"in e)return e.definition;if(ss(e)||ls(e)||cs(e))return e}function os(e){const t=[],r=[],n=[];for(const a of e){const i=Vn(a);i&&(ss(i)?t.push(i):ls(i)?r.push(i):cs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[..._r("geom",t,a=>a.type),..._r("stat",r,a=>a.type),..._r("transform",n,a=>a.transformType),...ff(t),...gf(t)]}}function ff(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 gf(e){const t=[];for(const r of e)r.spatialKind!=="cells"||!r.supportedCoordTypes.includes("polar")||t.push({code:"SPATIAL_KIND_COORD_UNSUPPORTED",message:`The geom '${r.type}' declares polar support, but its 'cells' hit-test shape has no polar projection; its observations will not respond to hover under polar coords.`,context:{kind:"geom",requested:r.type},suggestion:"Drop 'polar' from 'supportedCoordTypes', or declare 'rects' as the spatial kind so a bandless polar layer hit-tests as an enclosure."});return t}function _r(e,t,r){const n=new Map;for(const i of t){const o=r(i),s=n.get(o);s?s.add(i):n.set(o,new Set([i]))}const a=[];for(const[i,o]of n)o.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${o.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var ss=e=>e instanceof Se,ls=e=>e instanceof $e,cs=e=>"transformType"in e&&typeof e.apply=="function",yf=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},fr=class{},vf=class extends fr{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!l.extractVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),i=bf(e)??[-.7/2,.7/2],o=r.length>1?Fh:0,s=(0,se.scaleBand)().domain(r.map(String)).range(i).paddingInner(o).paddingOuter(0),c=s.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const m=a[p];if(!l.isDefined(m))continue;const h=s(String(m));l.isDefined(h)&&(u[p]=h,d[p]=h+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},bf=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]},ei=l.prefixInternalVariable("__ungrouped__"),us=(e,t)=>{const r=l.extractVariableName(t.x),n=l.extractVariableName(t.y);if(!r||!n)return null;const a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,o=i?[ei]:a,s=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let m=0;m<d;m++){const h=l.getStableKey(s[m]??null),f=u[m],y=i?ei:f;if(!l.isDefined(y))continue;let v=p.get(h);v||(v=new Map,p.set(h,v));let g=v.get(y);g||(g=[],v.set(y,g)),g.push(m)}return{yValues:c,observationIndicesByXAndGroup:p,uniqueGroupKeys:o,observationCount:d}},ds=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const o=[];let s=-1,c=1/0,u=-1/0,d=-1,p=1/0,m=-1/0;for(const h of i.values())for(const f of h){const y=e[f],v=t[f];!l.isDefined(y)||!l.isDefined(v)||(o.push(f),(y<c||y===c&&v>u)&&(s=f,c=y,u=v),(v>m||v===m&&y<p)&&(d=f,p=y,m=v))}for(const h of o)a[h]=Sf(h===s,h===d)}return a},Sf=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",xf=class extends fr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=us(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,d]of a){let p=0,m=0;for(const y of i){const v=d.get(y);if(v!==void 0)for(const g of v){const b=n[g];b!=null&&(b>=0?p+=b:m-=b)}}let h=0,f=0;for(const y of i){const v=d.get(y);if(v!==void 0)for(const g of v){const b=n[g];if(b===void 0)continue;if(b===null){c[g]=null,s[g]=null;continue}const I=b>=0?p:m;if(I===0){c[g]=0,s[g]=0;continue}const L=b/I;b>=0?(c[g]=h,s[g]=h+=L):(s[g]=f,c[g]=f+=L)}}}const u=ds(c,s,a,o);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},Af=class extends fr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},If=class extends fr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=us(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:o}=r,s=[...n],c=new Array(o).fill(0);for(const[,m]of a){let h=0,f=0;for(const y of i){const v=m.get(y);if(v!==void 0)for(const g of v){const b=n[g];if(b!==void 0){if(b===null){c[g]=null,s[g]=null;continue}b>=0?(c[g]=h,s[g]=h+=b):(s[g]=f,c[g]=f+=b)}}}}const u=ds(c,s,a,o);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",s).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const p=l.extractVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",s)),{data:d,mapping:{}}}},Tf=class extends l.Registry{constructor(){super("position"),this.register("identity",new Af),this.register("stack",new If),this.register("fill",new xf),this.register("dodge",new vf)}},Lf=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const o of i.positionRoles){if(o.role!=="scalar"||!l.isDefined(o.aes)||In(o.aes))continue;const s=l.extractVariableName(t.mapping[o.aes]);if(!l.isDefined(s)||!a.hasVariable(s))continue;const c=r(Uo(o.axis,t.yScaleType));if(!c)continue;const u=a.getValues(s,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(o.aes),"numeric",u)}return a}},wf=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},Ef=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=l.isDefined(n)&&e.hasVariable(l.POSITION_VARIABLES.x)?Rf(e,r,n):Cf(e,r);return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(l.POSITION_VARIABLES.xMax,"numeric",a.max)}};function Rf(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=ps(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function Cf(e,t){const r=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=ps(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function ps(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Vf=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(Le(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(o=>l.isDefined(o)?a.map(o):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},Df=class{map({data:e,layer:t,getPositionScale:r}){const n=r(Le(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)?_f(e,n,a):Pf(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function _f(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o="reverse"in t.spec&&t.spec.reverse===!0,s=e.size(),c=ms(s);for(let u=0;u<s;u++){const d=n[u],p=a[u],m=i[u];!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||(c.min[u]=d+(o?-m:p)*r,c.max[u]=d+(o?-p:m)*r)}return c}function Pf(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=ms(a);for(let o=0;o<a;o++){const s=r[o],c=n[o];!l.isDefined(s)||!l.isDefined(c)||(i.min[o]=t.map(s),i.max[o]=t.map(c))}return i}function ms(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Of=[new wf,new Vf,new Ef,new Df,new Lf];function Mf(e,t){const r=e[t];return r?.kind==="position"?r:null}var kf=class extends Fe{constructor(e,t=Of){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=>Mf(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}}},Nf=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:Vh(this.container.geomRegistry,e.layers)},a={};for(const[i,o]of t){const s=r.get(i)??[];a[i]=this.registry.get(o.scaleType).compile(o,s,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=H(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const o=l.extractVariableName(i.mapping[a]);if(!l.isDefined(o)||!i.data.hasVariable(o)||i.data.size()===0)continue;const s=i.data.getType(o);if(!n.includes(s)){const c=r.scaleType==="continuous"&&s==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${s})`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}if(r.scaledAesthetic==="lineType"&&s!=="categorical"){const c=s==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${s} variable '${o}'. ${c}`,context:{aesthetic:a,variableName:o,scaleType:r.scaleType,variableType:s},suggestion:c})}}es(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,o]of Object.entries(n.mapping)){if(!l.isDefined(o))continue;const s=i==="y"?Le(n.yScaleType):i,c=a.get(i)??(Go(s)?s:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,o,n.data,u);this.collectFromVariables(n.data,d,c,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!l.isDefined(n.aes)||In(n.aes)||t.set(n.aes,Uo(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const o of t)a=a.concat(e.getValues(o));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Bf=["rgb","lab","hcl","hsl"],Ff=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],hs=["RdBu","BrBG","PuOr","Spectral"],fs={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},$f=new Set(hs.map(e=>e.toLowerCase()));function gs(e){const t=e.toLowerCase(),r=fs[t];return r?r.toLowerCase():t}function Gf(e){return $f.has(gs(e))}var Uf={rgb:je.interpolateRgb,lab:je.interpolateLab,hcl:je.interpolateHcl,hsl:je.interpolateHsl},Hf={viridis:G.interpolateViridis,magma:G.interpolateMagma,inferno:G.interpolateInferno,plasma:G.interpolatePlasma,cividis:G.interpolateCividis,turbo:G.interpolateTurbo,blues:G.interpolateBlues,greens:G.interpolateGreens,greys:G.interpolateGreys,oranges:G.interpolateOranges,purples:G.interpolatePurples,reds:G.interpolateReds,rdbu:G.interpolateRdBu,brbg:G.interpolateBrBG,puor:G.interpolatePuOr,spectral:G.interpolateSpectral};function Dn(e){const t=Kf(e);return e.reverse?r=>t(1-r):t}function Wf(e={},t=2){const r=Dn({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 Kf(e){const t=Uf[e.interpolate];if(e.range&&e.range.length>=2)return(0,je.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Hf[gs(e.scheme)];if(r)return r}return(0,je.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var xt=class{createPositionScale(e,t){return{kind:"position",aesthetic:H(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:H(e.scaledAesthetic),spec:e,...t}}},zf=class extends xt{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=Te(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"&&Yf(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:H(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,se.scaleLog)():r.transform==="sqrt"?(0,se.scaleSqrt)():(0,se.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const o=r.domainMin??n[0],s=r.domainMax??n[1];return i.domain([o,s]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=qf(t.range)??[0,1],n=t.reverse?[r[1],r[0]]:r,a=this.createD3Scale(e,n,t);return this.createVisualScale(t,{map:a,domain:a.domain(),generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildColorScale(e,t){const r=Dn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[o,s]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([o,n,s],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,se.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,se.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Yf=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function qf(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var jf=class extends xt{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=Te(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=Xf(e)?e:[],a=(0,se.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,o]=a.domain();i!==void 0&&o!==void 0&&a.domain([r.domainMin??i,r.domainMax??o])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,o]=a.domain(),s=i&&o?r.filter(c=>c>=i&&c<=o):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?s:c&&"interval"in c?i&&o?gm(i,o,c.interval):[]:a.ticks(c?.count)})}},Xf=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Zf=class extends xt{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=Te(e.scaledAesthetic),n=Fo(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,se.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),o=i.bandwidth()/2;return this.createPositionScale(t,{map:s=>(i(String(s))??NaN)+o,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,se.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},Jf=class extends xt{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:H(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Qf=class extends xt{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=Bo(t),a=l.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=l.applyOverrides(a.length>0?a:[...l.DEFAULT_COLOR_PALETTE],e.overrides),o=(0,se.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:s=>o(String(s)),domain:n,generateTicks:()=>n})}},eg=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new zf(e)),this.register("discrete",new Zf),this.register("datetime",new jf),this.register("identity",new Jf),this.register("palette",new Qf)}},ys={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},tg={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 _n(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Yr(e.geomRegistry,n)}}function gr(e,t){switch(t.scaleType){case"inferred":return{...gr(e,ig(e,t)),inferredFrom:t};case"continuous":{const r=ys[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??l.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??l.CONTINUOUS_SCALE_DEFAULTS.nice,zero:t.zero??l.CONTINUOUS_SCALE_DEFAULTS.zero,clamp:t.clamp??r!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:og(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 jr(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 rg(e,t){const{scales:r,layers:n,coords:a}=t,i=_n(e,t),o=cg(lg(r,n),i.demands),s=new Map;for(const u of o)s.set(u.scaledAesthetic,u);const c=[...s.values()].map(u=>{const d=ng(i,u);return gr(i,d)});return a.coordType==="polar"?c.map(Pn):c}function jr(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??ag(e.scaledAesthetic,t)}}var Pn=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function ng(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function ag(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function ig({data:e,layers:t,mapping:r,demands:n},a){const i=H(a.scaledAesthetic),o=a.scaledAesthetic==="ySecondary"?sg(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const p=a.options;return l.continuous(a.scaledAesthetic,{...p,zero:!0,...!s.nice&&{nice:!1}})}const c=l.extractVariableName(o);if(!l.isDefined(c)||!e.hasVariable(c)||e.size()===0)return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=ys[a.scaledAesthetic];switch(tg[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 og(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&Gf(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:H(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function sg(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function lg(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function cg(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?l.inferred("color"):l.palette("color")]}var ug={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}},dg=(e,t,r)=>{const n=pg(e,t),a=fg(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>yg(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>xg(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Tg(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>gg(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>vg(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Ag(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>bg(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Sg(e,i,r)).filter(l.isDefined)}},pg=(e,t)=>{if(t===void 0)return{};if(!mg(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:W()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},mg=e=>{const t=new Set;for(const r of hg(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},hg=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],fg=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},On=(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},gg=(e,t,r,n)=>{const a=tr(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),content:t.content,at:a,width:t.width,align:t.align??l.TEXT_ANNOTATION_DEFAULTS.align}},yg=(e,t,r)=>{const n=mt(e,t.start,r),a=mt(e,t.end,r);return n===null||a===null?null:{id:t.id??W(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??l.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},mt=(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)},tr=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return On(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=mt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},vg=(e,t,r,n)=>{const a=tr(e,t.at,r,n,t.id);return a===null?null:{id:t.id??W(),at:a,sticker:t.sticker}},bg=(e,t,r)=>{const n=mt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n}},Sg=(e,t,r)=>{const n=mt(e,t.at,r);return n===null?null:{id:t.id??W(),at:n,content:t.content}},xg=(e,t,r)=>t.region.anchorType==="annotation"&&!On(e,t.region.ref,r,t.id)?null:{id:t.id??W(),kind:t.kind??l.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??l.SHAPE_DEFAULTS.zOrder,region:Ig(t.region)},Ag=(e,t,r)=>t.region.anchorType==="annotation"&&!On(e,t.region.ref,r,t.id)?null:{id:t.id??W(),src:t.src,zOrder:t.zOrder??l.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??l.IMAGE_ANNOTATION_DEFAULTS.fit},Ig=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:l.SELECTION_PADDING_DEFAULT},ti=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=ug[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Tg=(e,t,r,n)=>{const a=tr(e,t.start,r,n,t.id),i=tr(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??W(),start:ti(a),end:ti(i),startArrowheadStyle:t.startArrowheadStyle??l.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??l.ARROW_DEFAULTS.endArrowheadStyle}},Lg={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function wg(e){const t=(0,it.merge)({},Lg,e);return t.content=Eg(t.content,e?.content),t}var Eg=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Rg={xLimits:null,yLimits:null},Yt={theta:"x",startAngle:0,innerRadius:0};function Xr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Zt.default)({},Rg,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??Yt.theta,startAngle:t.params?.startAngle??Yt.startAngle,innerRadius:(0,Je.default)(t.params?.innerRadius??Yt.innerRadius,0,1)}}}}function Cg(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??W(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Vg=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=ri(e.filter(n=>n.severity==="error")),r=ri(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Dg=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 ri(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var _g={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:l.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4};function vs(e,t){const r=e??t,n=typeof r=="string"?r:r.type;if(n==="smooth"){const a=typeof r=="string"?void 0:r;return{type:"smooth",method:a?.method??"linear",order:a?.order??3,bandwidth:a?.bandwidth??.3}}return{type:n}}function Ge(e,t,r,n,a,i){const o=a!==void 0&&i!==void 0?new Dg(a,{layerIndex:i}):a,s=e.get(n.geom),c=n.position??s.defaultPosition,u=Mg({dataLabels:Ng(e,t,n,c,r),geom:s,position:c,coordType:r,diagnostics:o});return Og({diagnostics:o,coordType:r,geom:s,position:c,dataLabels:u}),{id:n.id??W(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:vs(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:s.resolveParams({params:n.params,diagnostics:o}),transforms:n.transforms??[],interactive:n.interactive??s.defaultInteractive,dataLabels:u}}function Pg(e,t,r,n,a){const i=n.map((o,s)=>Ge(e,t,r,o,a,s));return Ss(e,i)}var bs=(e,t,r,n)=>n.label!==void 0?n.label:Ro({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Ss=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Ne(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(o=>o.axis==="y"&&o.role==="scalar"))return n;const a=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,it.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Og=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&l.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},Mg=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:o}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const s=kg(t,r,n);if(s===null)return e;const c=i==="panel-end"?"end":"start";return o&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${s}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},kg=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&l.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Ng=(e,t,r,n,a)=>{const i={...t,...r.mapping},o=bs(e,r.geom,n,i),s=e.get(r.geom);return{...(0,it.merge)({},_g,s.resolveDataLabelDefaults?.(n)??{},s.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:o}},Bg=e=>{const t={tokens:{},defaults:[],overrides:[]};for(const r of Fg(e))Object.assign(t.tokens,r.tokens),t.defaults.push(...r.defaults??[]),t.overrides.push(...r.overrides??[]);return t},Fg=e=>{const t=[],r=new Set,n=e===void 0?[]:[e];for(;n.length>0;){const a=n.pop();if(!(a===void 0||r.has(a))){r.add(a),t.push(a);for(const i of a.extends??[])n.push(i)}}return t.reverse()};function $g(e,t,r){const n=Xr(t.coords),a=Pg(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=rg(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),o=wg(t.config),s=Cg(e,t.highlights,a),c=dg(e,t.annotations,a),u=Bg(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:s,styles:u,annotations:c,coords:n,config:o}}var xs=class{constructor(e){this.container=e}compile({spec:e,dataset:t,customPalettes:r}){return $g(this.container,{...e,data:t},r)}},Gg=()=>{let e={},t=null;return{reset:()=>{e={}},getDuration:r=>e[r]??0,wrap:(r,n)=>a=>{const i=t,o={childrenMs:0};t=o;const s=performance.now();try{return n(a)}finally{const c=performance.now()-s;e[r]=(e[r]??0)+c-o.childrenMs,i&&(i.childrenMs+=c),t=i}}}},Ug=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})}},At={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},Hg={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}}},As=Object.keys(At),Wg=e=>Object.hasOwn(At,e),It=(e,t)=>{for(const r of As){const n=Kg(e,r,t);if(n)return n}return null},Tt=(e,t)=>e[At[t]],Mn=(e,t,r)=>({...e,[At[t]]:r}),Is=(e,t)=>{const r=Tt(e,t.kind);return Mn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Kg=(e,t,r)=>{const n=Tt(e,t),a=n.findIndex(o=>o.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},zg=class extends Fe{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of hy(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of gy(e.styles))this.container.diagnostics.addWarning(r);for(const r of yy(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=Cs({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},qe={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Zr={bar:{...qe,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...qe,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...qe,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...qe,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"},tile:{...qe,borderRadius:"pixels",borderColor:"color",borderWidth:"pixels"}},Bt={color:"color",strokeWidth:"pixels",lineType:"lineType"},z={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Ft={...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},ni={background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},M={panelBorder:{...Bt,borderRadius:"pixels"},panelBorderEdge:Bt,gridLine:Bt,tickLine:{...Bt,length:"pixels"},axisLabel:{...z,margin:"margin"},tickLabel:{...z,offset:"pixels",margin:"margin"},ruleLabel:z,dataLabel:Ft,graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color",textScale:"multiplier",padding:"padding"},heading:z,caption:z,source:z,header:{margin:"margin"},footer:{margin:"margin"},hoverGuide:{color:"color",background:"color"},tooltip:ni,tooltipText:z,tooltipPrimaryRow:{background:"color"},headline:{gap:"pixels",margin:"margin"},legend:{gap:"pixels",margin:"margin"},legendPopover:ni,legendItem:{...z,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},legendItemSwatch:{size:"pixels",strokeWidth:"pixels"},directLabel:{...z,strokeWidth:"pixels",lineType:"lineType"},annotation:{color:"color",alpha:"unitInterval"},annotationShape:{color:"color",alpha:"unitInterval",borderColor:"color",borderWidth:"pixels"},annotationArrow:{color:"color",strokeWidth:"pixels",lineType:"lineType",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationDifferenceArrow:{color:"color",strokeWidth:"pixels"},annotationDifferenceArrowLabel:Ft,annotationText:{...Ft,alpha:"unitInterval"},annotationImage:{alpha:"unitInterval",borderRadius:"pixels"},annotationCallout:{color:"color",size:"pixels",borderColor:"color",borderWidth:"pixels",shadow:"shadow"},annotationCalloutLabel:{...Ft,shadow:"shadow"}},Yg={number:z,numberCenter:z,caption:z,label:z,swatch:{size:"pixels"},trend:z,trendUp:{textColor:"color"},trendDown:{textColor:"color"},trendFlat:{textColor:"color"}},qg=new Set(l.STYLE_PROPERTY_NAMES),Ts=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","heading","caption","source","header","footer","hoverGuide","tooltip","headline","headlineItem","legend","legendItem","directLabel","annotation"],jg=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Xg=new Set(["panelBorder","legend","axisLabel","tickLabel"]),Zg=(e,t,r="en-US")=>Cs({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Jg=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of fy(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Ls(e.styles)}},Ls=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},heading:{defaults:[],overrides:[]},caption:{defaults:[],overrides:[]},source:{defaults:[],overrides:[]},header:{defaults:[],overrides:[]},footer:{defaults:[],overrides:[]},hoverGuide:{defaults:[],overrides:[]},tooltip:{defaults:[],overrides:[]},headline:{defaults:[],overrides:[]},headlineItem:{defaults:[],overrides:[]},legend:{defaults:[],overrides:[]},legendItem:{defaults:[],overrides:[]},directLabel:{defaults:[],overrides:[]},annotation:{defaults:[],overrides:[]},warnings:t},a=(i,o,s,c)=>{if(yr(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!ey(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${Ts.map(h=>`'${h}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const p=i.select;if(p.target==="annotation"){const h=p.kind;if(h!==void 0&&!uy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown annotation kind '${String(h)}'.`,context:{param:"kind",actual:String(h),...u},suggestion:`Set 'kind' to one of ${l.ANNOTATION_STYLE_KINDS.map(g=>`'${g}'`).join(", ")}, or omit it to address every annotation.`});return}const f=p.part,y=dy(h);if(f!==void 0&&!(typeof f=="string"&&y.includes(f))){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(f)}'.`,context:{param:"part",actual:String(f),...u},suggestion:y.length>0?`Set 'part' to ${y.map(g=>`'${g}'`).join(", ")}, or omit it to address the ${h==="differenceArrow"?"line":"marker"}.`:`Remove 'part' — ${h===void 0?"kind-agnostic":`'${String(h)}'`} entries have none.`});return}const v=p.annotation;if(v!==void 0&&typeof v!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid annotation ${Ie(v)}.`,context:{param:"annotation",actual:Ie(v),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}if(Xg.has(p.target)){const h=p.edge;if(h!==void 0&&!ty(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown edge '${String(h)}'.`,context:{param:"edge",actual:String(h),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(jg.has(p.target)){const h=p.axis;if(h!==void 0&&!py(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown axis '${String(h)}'.`,context:{param:"axis",actual:String(h),...u},suggestion:`Set 'axis' to one of ${xn.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="ruleLabel"){const h=p.layer;if(h!==void 0&&typeof h!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses an invalid layer ${Ie(h)}.`,context:{param:"layer",actual:Ie(h),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(p.target==="tooltip"){const h=p.part;if(h!==void 0&&!ay(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(p.target==="heading"){const h=p.part;if(h!==void 0&&!oy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.HEADING_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address every heading level.`});return}}if(p.target==="source"){const h=p.part;if(h!==void 0&&!iy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.SOURCE_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the label.`});return}}if(p.target==="legend"){const h=p.part;if(h!==void 0&&!sy(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.LEGEND_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the gap.`});return}}if(p.target==="legendItem"){const h=p.part;if(h!==void 0&&!ly(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.LEGEND_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the pill.`});return}}if(p.target==="headlineItem"){const h=p.part;if(!cy(h)){t.push({code:"INVALID_STYLE_RULE",message:h===void 0?`Style ${s} ignored: headlineItem entries need a part.`:`Style ${s} addresses unknown part '${String(h)}'.`,context:{param:"part",actual:String(h),...u},suggestion:`Set 'part' to one of ${l.HEADLINE_ITEM_PARTS.map(f=>`'${f}'`).join(", ")}.`});return}}if(p.target==="dataLabel"){const h=p.role;if(h!==void 0&&!ry(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown role '${String(h)}'.`,context:{param:"role",actual:String(h),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(y=>`'${y}'`).join(", ")}.`});return}const f=p.position;if(f!==void 0){if(!ny(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(y=>`'${y}'`).join(", ")}.`});return}if(h===void 0||h==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${s} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const m=Nn({declarations:i.declarations,vocabulary:Es(p),tokens:r,location:s,origin:c,warnings:t,entryTarget:p.target});Object.keys(m).length!==0&&n[p.target][o].push({select:p,declarations:m,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,o)=>{a(i,"defaults",`builtin[${o}]`,{list:"builtin"})}),e.defaults.forEach((i,o)=>{a(i,"defaults",`defaults[${o}]`,{list:"defaults",index:o,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,o)=>{a(i,"overrides",`overrides[${o}]`,{list:"overrides",index:o,...i.id===void 0?{}:{id:i.id}})}),n},Qg=(e,t)=>{if(e==="geom"){const r=Object.keys(Zr).find(n=>Zr[n]?.[t]!==void 0);return r===void 0?void 0:`style.geom.${r}`}if(e==="annotation"){const r=l.ANNOTATION_STYLE_KINDS.find(n=>Es({target:"annotation",kind:n})[t]!==void 0);return r===void 0?void 0:`style.annotation.${r}`}},yr=e=>e.select.target==="geom",ey=e=>{const t=e.select.target;return t!=="geom"&&Ts.includes(t)},ws=e=>(e!==void 0?Zr[e]:void 0)??qe,Es=e=>{if(e.target==="panelBorder")return e.edge===void 0?M.panelBorder:M.panelBorderEdge;if(e.target==="tooltip")return e.part===void 0?M.tooltip:e.part==="primaryRow"?M.tooltipPrimaryRow:M.tooltipText;if(e.target==="legend")return e.part==="popover"?M.legendPopover:M.legend;if(e.target==="legendItem")return e.part===void 0?M.legendItem:M.legendItemSwatch;if(e.target==="headlineItem")return Yg[e.part];if(e.target==="annotation")switch(e.kind){case"shape":return M.annotationShape;case"arrow":return M.annotationArrow;case"differenceArrow":return e.part==="label"?M.annotationDifferenceArrowLabel:M.annotationDifferenceArrow;case"text":return M.annotationText;case"image":return M.annotationImage;case"pinnedNumber":case"comment":return e.part==="label"?M.annotationCalloutLabel:M.annotationCallout;default:return M.annotation}return M[e.target]},ty=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),ry=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),ny=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),ay=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),iy=e=>typeof e=="string"&&l.SOURCE_PARTS.includes(e),oy=e=>typeof e=="string"&&l.HEADING_PARTS.includes(e),sy=e=>typeof e=="string"&&l.LEGEND_PARTS.includes(e),ly=e=>typeof e=="string"&&l.LEGEND_ITEM_PARTS.includes(e),cy=e=>typeof e=="string"&&l.HEADLINE_ITEM_PARTS.includes(e),uy=e=>typeof e=="string"&&l.ANNOTATION_STYLE_KINDS.includes(e),dy=e=>typeof e=="string"&&e in l.ANNOTATION_PARTS?l.ANNOTATION_PARTS[e]:[],py=e=>typeof e=="string"&&xn.includes(e),my=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!yr(a))return;const o=a.select.kind;if(o!==void 0&&o!==e)return;const s={list:"builtin"},c=Nn({declarations:a.declarations,vocabulary:ws(o),tokens:t,location:`builtin[${i}]`,origin:s,warnings:r,entryTarget:"geom"});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:s})}),n},kn=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},hy=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return kn(e,(a,i,o)=>{const s=a.select;if(s.target!=="geom"&&s.target!=="ruleLabel")return;const c=s.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},fy=(e,t)=>{const r=new Map(As.flatMap(a=>t[At[a]].map(i=>[i.id,a]))),n=[];return kn(e,(a,i,o)=>{const s=a.select;if(s.target!=="annotation")return;const c=s.annotation;if(c===void 0||typeof c!="string")return;const u={param:"annotation",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(c);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets unknown annotation '${c}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets sticker '${c}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=s.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${o}] targets ${d} '${c}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},gy=e=>{const t=[];return kn(e,(r,n,a)=>{if(!yr(r))return;const i=r.when?.state;i===void 0||Rs(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${l.STYLE_STATES.map(o=>`'${o}'`).join(", ")}.`})}),t},Rs=e=>l.STYLE_STATES.includes(e),yy=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))l.isUsableTokenValue(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Ie(n)}.`,context:{param:"tokens",actual:Ie(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ie=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Cs=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Be(t,a),o=[],s={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const p=[];return u.forEach((m,h)=>{if(!yr(m))return;const f=m.select.kind;if(f!==void 0&&f!==t.geom||m.select.layer!==void 0&&m.select.layer!==t.id)return;const y=m.when?.state;if(y!==void 0&&!Rs(y))return;const v={list:d,index:h,...m.id===void 0?{}:{id:m.id}},g=m.when?.where;if(g!==void 0){const I=ce(g,t.data,"style-rule");if(I.length>0){for(const L of I)o.push({...L,code:"INVALID_STYLE_RULE",message:`Style ${d}[${h}]: ${L.message}`,context:{...L.context,layerIndex:r,...m.id===void 0?{}:{styleEntryId:m.id}}});return}}const b=Nn({declarations:m.declarations,vocabulary:ws(f),tokens:s,location:`${d}[${h}]`,origin:v,warnings:o,entryTarget:"geom"});Object.keys(b).length!==0&&p.push({declarations:b,...g===void 0?{}:{matches:le(g,i)},...y===void 0?{}:{state:y},origin:v})}),p};return{defaults:[...my(t.geom,s,o),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:o}},Nn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:o,entryTarget:s}=e,c={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(f,y)=>{c[f]=y},p=(f,y,v)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: expected ${y}, got ${Ie(v)}.`,context:{param:f,expected:y,actual:Ie(v),...u},suggestion:`Set '${f}' to ${y}.`})},m=(f,y)=>{o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: unknown token '${y}'.`,context:{param:f,actual:y,...u},suggestion:`Declare '${y}' in the stylesheet's tokens.`})},h=f=>{const y=qg.has(f),v=Qg(s,f),g=v===void 0?`Declare '${f}' on a target whose vocabulary carries it.`:`Declare '${f}' on an entry whose kind supports it (e.g. ${v}).`;o.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${f}' ignored: ${y?"not in this entry's vocabulary":"not a style property"}.`,context:{param:f,...u},suggestion:y?g:`Remove the unknown declaration '${f}'.`})};for(const f of Object.keys(t)){const y=t[f];if(y===void 0)continue;const v=r[f];if(v===void 0){h(f);continue}const g=l.STYLE_DOMAINS[v](y,n);switch(g.status){case"accepted":d(f,g.value);break;case"rejected":p(f,g.expected,g.actual);break;case"unknownToken":m(f,g.token);break;case"dropped":break;default:break}}return c},vy=({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}},by=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=l.extractVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const n=s=>t==="y"?s.xMax:s.yMax,a=s=>t==="y"?s.xMin:s.yMin,i=new Map;for(const s of e.data){const c=s[r],u=U(s),d=$(s),p=j(s),m=X(s),h=hn(s);if(!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d)||!l.isDefined(p)||!l.isDefined(m)||!l.isDefined(h))continue;const f=h>=0;if(Math.abs(h)===0)continue;const y=En(s,r),v={xMin:p,xMax:m,yMin:u,yMax:d},g=i.get(y);if(g===void 0){i.set(y,{total:h,topPositive:f?v:null,bottomNegative:f?null:v});continue}g.total+=h,f?(g.topPositive===null||n(v)>n(g.topPositive))&&(g.topPositive=v):(g.bottomNegative===null||a(v)<a(g.bottomNegative))&&(g.bottomNegative=v)}const o=[];for(const[s,c]of i){const u=c.topPositive??c.bottomNegative;u!==null&&o.push({xKey:s,total:c.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:c.topPositive!==null?"positive":"negative"}})}return o},Sy=class extends Fe{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=t.coordSystem.type==="cartesian"?t.coordSystem.mainAxis:"x";if(r.summaries.stackTotals){const i=by({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=vy({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},Vs=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)}},ai={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},xy=["color","size","alpha","strokeWidth","lineType"],Ay=class extends Fe{dependencies(e){return xy.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const o=l.extractConstantValue(e.mapping[a]);if(o!==void 0){r=r.addConstantVariable(i,ai[a],o);continue}const s=l.extractVariableName(e.mapping[a]),c=t.scales[a];!s||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(s,i,ai[a],Iy(c)))}return{...e,data:r}}},Iy=e=>t=>l.isDefined(t)?e.map(t):null;function Ds(e=new hr){return{diagnostics:new Vg,geomRegistry:e}}var _s=class{constructor(e,t,r,n,a,i,o,s,c,u,d,p,m,h,f,y){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=o,this.coordCompiler=s,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=p,this.stylesCompiler=m,this.chromeStylesCompiler=h,this.highlightsCompiler=f,this.annotationsCompiler=y,this.stageTimer=l.IS_DEV?Gg():null,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}],l.IS_DEV&&this.setupStageTiming()}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??ii})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??ii;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,C(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=_n(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return C(t,{scales:Ne(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=gr(r,a);return t.coords.coordType==="polar"?Pn(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[To(e)],warnings:t.warnings}}setupStageTiming(){this.stageTimer&&(this.dataCompiler.compile=this.stageTimer.wrap("data",this.dataCompiler.compile.bind(this.dataCompiler)),this.transformCompiler.compile=this.stageTimer.wrap("transform",this.transformCompiler.compile.bind(this.transformCompiler)),this.constantMappingCompiler.compile=this.stageTimer.wrap("constantMapping",this.constantMappingCompiler.compile.bind(this.constantMappingCompiler)),this.layerPhasedCompiler.compile=this.stageTimer.wrap("layer",this.layerPhasedCompiler.compile.bind(this.layerPhasedCompiler)),this.coordCompiler.setup=this.stageTimer.wrap("coordSetup",this.coordCompiler.setup.bind(this.coordCompiler)),this.scaleCompiler.compile=this.stageTimer.wrap("scale",this.scaleCompiler.compile.bind(this.scaleCompiler)),this.positionMapperCompiler.compile=this.stageTimer.wrap("positionMapper",this.positionMapperCompiler.compile.bind(this.positionMapperCompiler)),this.visualMapperCompiler.compile=this.stageTimer.wrap("visualMapper",this.visualMapperCompiler.compile.bind(this.visualMapperCompiler)),this.coordCompiler.transform=this.stageTimer.wrap("coordTransform",this.coordCompiler.transform.bind(this.coordCompiler)),this.summarizeCompiler.compile=this.stageTimer.wrap("summarize",this.summarizeCompiler.compile.bind(this.summarizeCompiler)),this.guideCompiler.compile=this.stageTimer.wrap("guide",this.guideCompiler.compile.bind(this.guideCompiler)),this.stylesCompiler.compile=this.stageTimer.wrap("styles",this.stylesCompiler.compile.bind(this.stylesCompiler)),this.chromeStylesCompiler.compile=this.stageTimer.wrap("chromeStyles",this.chromeStylesCompiler.compile.bind(this.chromeStylesCompiler)),this.highlightsCompiler.compile=this.stageTimer.wrap("highlights",this.highlightsCompiler.compile.bind(this.highlightsCompiler)),this.annotationsCompiler.compile=this.stageTimer.wrap("annotations",this.annotationsCompiler.compile.bind(this.annotationsCompiler)))}trackCompile(e){if(!l.IS_DEV)return e();this.stageTimer?.reset();const t=this.getCacheStats(),r=performance.now();try{return e()}finally{const n=performance.now()-r,a={},i={};for(const{name:o,getStats:s}of this.stages){const c=s();a[o]={hits:c.hits-t[o].hits,misses:c.misses-t[o].misses},i[o]=this.stageTimer?.getDuration(o)??0}this.lastCompile={stages:a,durationMs:n,stageDurationsMs:i}}}runPipeline({spec:e,colorScheme:t}){return{...ur({spec:e}).pipe(({spec:r})=>({spec:C(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:C(r,{data:n.data,mapping:n.mapping})}}).pipe(({spec:r})=>({layers:this.layerPhasedCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales})})).pipe(({spec:r,layers:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},Ty=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],ii="light",Ly=({plugins:e=[]}={})=>{const t=os(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=hf(t),i=Ds(r),o=new eg(i),s=new Vs(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new _s(i,new l.DataCompiler,new xs(i),s,new Bp,new kh(i,s,n,new Ch(i,s,new Ug(n),new cm,new lm(i),new yf(new Tf))),new Nf(i,o),new Gp(new nm),new kf(i),new Ay,new Sh(i),new Sy(i),new zg(i),new Jg(i),new Th(i),new Tp(i))};function Ps(e,t){return e.geom===t}function Os(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!wy(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((o,s)=>ks(o,s),i)}function Ms(e,...t){return t.reduce((r,n)=>ks(r,n),e)}function wy(e){return typeof e=="object"&&e!==null&&"type"in e}function ks(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:(0,Zt.default)({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};case"highlight":return{...e,highlights:[...e.highlights,t]};case"styles":return{...e,styles:e.styles===void 0?t:{...t,extends:[e.styles,...t.extends??[]]}};case"annotation":return Ey(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Ey(e,t){const r={...e.annotations};switch(t.kind){case"differenceArrow":r.differenceArrows=[...r.differenceArrows??[],t.annotation];break;case"shape":r.shapes=[...r.shapes??[],t.annotation];break;case"arrow":r.arrows=[...r.arrows??[],t.annotation];break;case"text":r.textAnnotations=[...r.textAnnotations??[],t.annotation];break;case"image":r.images=[...r.images??[],t.annotation];break;case"sticker":r.stickers=[...r.stickers??[],t.annotation];break;case"pinnedNumber":r.pinnedNumbers=[...r.pinnedNumbers??[],t.annotation];break;case"comment":r.comments=[...r.comments??[],t.annotation];break;default:throw new Error(`Unknown annotation kind: ${t.kind}`)}return{...e,annotations:r}}function Ry(e){const t=e?.plugins??[],r=Vy(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Os,pipe:Ms,plugins:t}}var Cy=e=>(t={})=>l.buildLayerSpec(e,t);function Vy(e){const{geoms:t,stats:r,transforms:n}=os(e),a={};for(const s of t)a[s.type]=Cy(s.type);const i={};for(const s of r)i[s.type]=()=>({type:s.type});const o={};for(const s of n)o[s.transformType]=c=>({type:"transform",transformType:s.transformType,options:c?.options});return{geom:a,stat:i,transform:o}}var Pr="…",Ns=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Pr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Pr)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Pr};var Y={timeZone:"UTC"},K=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Ee=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Bn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Dy=Hr.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Bs=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Ee(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Gn(a,i),{base:s,suffix:c}=$n(a,r.abbreviation),u={...o,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(s)}${c}`}),Fs=({locale:e,numberFormat:t,intlOptions:r})=>Ee(n=>{const{base:a,suffix:i}=$n(n,t.abbreviation),o={...Gn(a,t.decimals),...r};return`${Intl.NumberFormat(e,o).format(a)}${i}`}),Fn=e=>Ee(t=>Dy(t)),$s=({locale:e,intlOptions:t})=>Ee(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Gs=({locale:e,numberFormat:t,intlOptions:r})=>Ee(n=>{const a=Gn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),$n=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=_y(e);return $n(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Gn=(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}},_y=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"},Py=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).format(r)),Oy=({locale:e,intlOptions:t})=>K(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...Y,...t}).formatToParts(r);return My(n.map(ky))}),Us=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t}).format(r)),Hs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"long",...Y,...t}).format(r)),Un=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...Y,...t}).format(r)),Hn=e=>K(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Ws=({locale:e,intlOptions:t})=>K(r=>{const n=(0,mo.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...Y,...t,year:void 0}).formatRange(r,n)}),Ks=({locale:e,intlOptions:t})=>K(r=>{const n=(0,mo.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...Y,...t}).formatRange(r,n)}),Wn=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{year:"numeric",...Y,...t}).format(r)),zs=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),My=e=>e.map(t=>t.value).join(""),ky=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},oi=1e3,Ny=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Ee(a=>{const i={...zn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Kn(a,t,i)}),By=({locale:e,tickValues:t,intlOptions:r})=>Ee(n=>{const a={...zn(n,t),notation:"compact",...r};return Kn(n,e,a)}),Fy=({locale:e,tickValues:t,intlOptions:r})=>Ee(n=>{const a={...zn(n,t),notation:"compact",...r,style:"percent"};return Kn(n,e,a)}),Kn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Ys=e=>Math.abs(e)>oi?Ys(e/oi):Number.isInteger(e),$y=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},zn=(e,t)=>Ys(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:$y(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Gy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Uy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{month:"short",...Y,...t}).format(r)),Hy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...Y,...t}).format(r)),Wy=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...Y,...t}).format(r)),Yn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ny(e);case"date":case"datetime":return Gy(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Hy(e);case"decimal":case"integer":return By(e);case"duration":return Fn(e);case"month":return Uy(e);case"month_year":return Un(e);case"percentage":return Fy(e);case"quarter":return Hn(e);case"text":return Bn(e);case"time":return Wy(e);case"year":return Wn(e);case"lookup":return Yn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Ky=.9,zy=1/3,Yy=1/4,qy=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?jy(e):Xy(e),jy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=qs(e.ticks,n),s=Zy(e.ticks,r.width),c=s*Ky;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=Qr(c);return{...e,ticks:Jr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Qr(r.height*zy);return{...e,ticks:Jr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Xy=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=qs(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=Qr(r.width*Yy);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Jr(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Zy=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},qs=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},Jr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Ns(i.formattedLabel,r,a)})},Qr=e=>Math.max(0,Math.floor(e)),Jy=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let o=r-(e.length-1)*i;for(const s of e){const{width:c,height:u}=n(s);if(o-=a?c:u,o<0)return!1}return!0},Qy=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const m=o.get(p);if(m)return m;const h=a[p],f=h?ev(h.ticks,n(h)):[];return o.set(p,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1;Jy(s(p).map(m=>m.formattedLabel),i,t,r)?(d=p,c=p+1):u=p-1}return d>=0?s(d):s(0)},ev=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),si=.5,Lt=e=>({x:0,y:0,width:e.width,height:e.height}),qn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,wt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:o,alignOffset:s,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",p=(r.valueAxis==="x"?e.height:e.width)===0,m={anchor:rv(a,r.valueDirectionSign),placement:d?"inside":n,offset:o},h={anchor:nv(i),placement:p?n:"inside",offset:p?s??o:0},f=d?t:e,y=r.valueAxis==="x"?f:e,v=r.valueAxis==="y"?f:e,g=r.valueAxis==="x"?m:h,b=r.valueAxis==="x"?h:m,I=ci(g,{min:y.x,max:y.x+y.width,halfExtent:c/2}),L=ci(b,{min:v.y,max:v.y+v.height,halfExtent:u/2});return{x:I,y:L,position:tv(e,I,L,c,u)}},li=(e,t,r,n)=>r-n>=e-si&&r+n<=t+si,tv=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||li(e.x,e.x+e.width,t,n/2),o=e.height===0||li(e.y,e.y+e.height,r,a/2);return i&&o?"inside":"outside"},rv=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",nv=e=>e==="center"?"center":e==="start"?"min":"max",ci=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const o=r+i;return e==="min"?t==="inside"?n+o:n-o:t==="inside"?a-o:a+o},av=(e,t,r,n,a)=>{const i=t??e,o=1-Math.max(e,i);return{box:{x:r*n,y:o*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},iv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=sv(e.layer);for(const a of e.layer.data){const i=k(a),o=$(a)??_(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),{box:d,frame:p}=av(o,U(a),i,e.panelRect.width,e.panelRect.height),m=wt({box:d,panel:Lt(e.panelRect),frame:p,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:m.x,y:m.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return{labels:t,droppedCount:0}},ov={place:iv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":l.isStackedPosition(e.position)?"stack":"none"},sv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:pr(e.data,e.mapping)?qn(r):r,align:n}};function Et(e){return e[l.VISUAL_VARIABLES.color]}function js(e){return e[l.VISUAL_VARIABLES.alpha]}function jn(e){return e[l.VISUAL_VARIABLES.size]}function en(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Xs(e){return e[l.VISUAL_VARIABLES.lineType]}var Zs=["color","alpha","saturation","borderRadius","borderColor","borderWidth","strokeWidth","lineType","strokeAlpha","fillAlpha","size","background","fontFamily","fontSize","fontWeight","lineHeight","textScale","textColor","offset","gap","length","paddingInline","paddingBlock","padding","margin","shadow"],$t={top:["x","top"],right:["y","right"],bottom:["x","bottom"],left:["y","left"]},lv=(e,t)=>{const r=ui(e.graph,e.graph),n=c=>ui(c,r),a=c=>dv(u=>n(c(u))),i=a(c=>e.ruleLabel(c)),o=Object.assign(c=>t(c),{bar:c=>t(c),line:c=>t(c),area:c=>t(c),point:c=>t(c),rule:Object.assign(c=>t(c),{label:c=>i(c.id)}),tile:c=>t(c)}),s=c=>({x:A(()=>n(c("x"))),y:A(()=>n(c("y"))),top:A(()=>n(c(...$t.top))),right:A(()=>n(c(...$t.right))),bottom:A(()=>n(c(...$t.bottom))),left:A(()=>n(c(...$t.left)))});return{geom:o,graph:()=>r,heading:{h1:A(()=>n(e.heading.h1)),h2:A(()=>n(e.heading.h2))},caption:A(()=>n(e.caption)),source:Object.assign(A(()=>n(e.source.label)),{link:A(()=>n(e.source.link))}),header:A(()=>n(e.header)),footer:A(()=>n(e.footer)),hoverGuide:A(()=>n(e.hoverGuide)),tooltip:Object.assign(A(()=>n(e.tooltip.box)),{heading:A(()=>n(e.tooltip.heading)),label:A(()=>n(e.tooltip.label)),value:A(()=>n(e.tooltip.value)),primaryRow:A(()=>n(e.tooltip.primaryRow))}),gridLine:{x:A(()=>n(e.gridLine("x"))),y:A(()=>n(e.gridLine("y")))},tickLine:{x:A(()=>n(e.tickLine("x"))),y:A(()=>n(e.tickLine("y")))},axisLabel:s(e.axisLabel),tickLabel:s(e.tickLabel),panelBorder:Object.assign(A(()=>n(e.panelBorder())),{top:A(()=>n(e.panelBorder("top"))),right:A(()=>n(e.panelBorder("right"))),bottom:A(()=>n(e.panelBorder("bottom"))),left:A(()=>n(e.panelBorder("left")))}),dataLabel:{observation:{inside:A(()=>n(e.dataLabel("observation","inside"))),outside:A(()=>n(e.dataLabel("observation","outside")))},category:{inside:A(()=>n(e.dataLabel("category","inside"))),outside:A(()=>n(e.dataLabel("category","outside")))},aggregate:A(()=>n(e.dataLabel("aggregate","outside")))},headline:A(()=>n(e.headline)),headlineItem:{number:Object.assign(A(()=>n(e.headlineItem.number)),{center:A(()=>n(e.headlineItem.numberCenter))}),caption:A(()=>n(e.headlineItem.caption)),label:A(()=>n(e.headlineItem.label)),swatch:A(()=>n(e.headlineItem.swatch)),trend:Object.assign(A(()=>n(e.headlineItem.trend)),{up:A(()=>n(e.headlineItem.trendUp)),down:A(()=>n(e.headlineItem.trendDown)),flat:A(()=>n(e.headlineItem.trendFlat))})},legend:Object.assign(A(()=>n(e.legend())),{popover:A(()=>n(e.legend.popover)),top:A(()=>n(e.legend("top"))),right:A(()=>n(e.legend("right"))),bottom:A(()=>n(e.legend("bottom"))),left:A(()=>n(e.legend("left")))}),legendItem:Object.assign(A(()=>n(e.legendItem.item)),{swatch:A(()=>n(e.legendItem.swatch))}),directLabel:A(()=>n(e.directLabel)),annotation:{shape:a(c=>e.annotation.shape(c)),arrow:a(c=>e.annotation.arrow(c)),differenceArrow:Object.assign(a(c=>e.annotation.differenceArrow(c)),{label:a(c=>e.annotation.differenceArrow.label(c))}),text:a(c=>e.annotation.text(c)),image:a(c=>e.annotation.image(c)),pinnedNumber:Object.assign(a(c=>e.annotation.pinnedNumber(c)),{label:a(c=>e.annotation.pinnedNumber.label(c))}),comment:Object.assign(a(c=>e.annotation.comment(c)),{label:a(c=>e.annotation.comment.label(c))})}}},cv=(e,t)=>{if(typeof e.fontSize!="number"||(e.fontSize*=t.get("textScale"),e.fontFamily!==void 0))return;const r=t.get("fontFamily");r!==void 0&&(e.fontFamily=r)},uv=(e,t)=>{const r={};for(const n of Zs){const a=e.get(n);a!==void 0&&Object.assign(r,{[n]:a})}return cv(r,t),r},ui=(e,t)=>{let r;return{...e,resolve:()=>(r??=uv(e,t),r)}},dv=e=>{const t=new Map;return r=>{const n=t.get(r);if(n!==void 0)return n;const a=e(r);return t.set(r,a),a}},A=e=>{let t;return()=>(t??=e(),t)},pv={color:Et,alpha:js,strokeWidth:en,lineType:Xs,size:jn,borderWidth:en},di=new WeakMap,st=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap,a=new WeakMap,i=u=>{const d=r.get(u);if(d!==void 0)return d;const p=fv(mv(u.styles),t);return r.set(u,p),p},o=u=>{const d=n.get(u);if(d!==void 0)return d;const p=hv(u,t);return n.set(u,p),p};return{readers:u=>{const d=a.get(u.chrome);if(d!==void 0)return d;const p=lv(o(u.chrome),i);return a.set(u.chrome,p),p},geomReaders:i,chromeReaders:o,explain:(u,d,p,m)=>i(u).explain(d,p,m)}},mv=e=>{const t=di.get(e);if(t!==void 0)return t;const r={defaults:pi(e.defaults),overrides:pi(e.overrides)};return di.set(e,r),r},pi=e=>{const t={};for(const r of e)for(const n of Object.keys(r.declarations)){if(r.declarations[n]===void 0)continue;const a=t[n]??={};(a[r.state??"stateless"]??=[]).push(r)}return t},hv=(e,t)=>{const r=(v,g)=>{const b=R=>mi(v.overrides,R,g)??mi(v.defaults,R,g);return{get:R=>{const V=b(R)?.declarations[R];if(V!==void 0)return l.resolveColorScheme(V,t)},getSource:R=>{const V=b(R);return V===void 0?"unresolved":V.origin.list==="builtin"?"builtin":"authored"},explain:R=>{const V=b(R),T=V?.declarations[R];return V===void 0||T===void 0?{value:void 0,source:"unresolved"}:{value:l.resolveColorScheme(T,t),source:V.origin.list==="builtin"?"builtin":"authored",origin:V.origin,select:V.select}},collectAll:R=>{const V=[];for(const T of[v.defaults,v.overrides])for(const D of T){if(!g(D))continue;const O=D.declarations[R];O!==void 0&&V.push(l.resolveColorScheme(O,t))}return V}}},n=(v,g)=>{const b="edge"in v.select?v.select.edge:void 0;return b===void 0||b===g},a=v=>r(e.panelBorder,g=>n(g,v)),i=v=>r(e.legend,g=>g.select.target!=="legend"||g.select.part!==void 0?!1:n(g,v)),o=v=>(g,b)=>r(e[v],I=>I.select.target!==v||I.select.axis!==void 0&&I.select.axis!==g?!1:n(I,b)),s=v=>r(e.ruleLabel,g=>g.select.target!=="ruleLabel"?!1:g.select.layer===void 0||g.select.layer===v),c=(v,g)=>r(e.dataLabel,b=>b.select.target!=="dataLabel"||b.select.role!==void 0&&b.select.role!==v?!1:b.select.position===void 0||b.select.position===g),u=v=>r(e.tooltip,g=>g.select.target==="tooltip"&&g.select.part===v),d=v=>r(e.source,g=>g.select.target==="source"&&g.select.part===v),p=v=>r(e.heading,g=>g.select.target!=="heading"?!1:g.select.part===void 0||g.select.part===v),m=v=>r(e.legend,g=>g.select.target==="legend"&&g.select.part===v),h=v=>r(e.legendItem,g=>g.select.target==="legendItem"&&g.select.part===v),f=v=>r(e.headlineItem,g=>g.select.target==="headlineItem"&&g.select.part===v),y=(v,g)=>{const b=new Map;return I=>{const L=b.get(I);if(L!==void 0)return L;const w=r(e.annotation,E=>{if(E.select.target!=="annotation")return!1;const R=E.select.kind;return R!==void 0&&R!==v||E.select.part!==g?!1:E.select.annotation===void 0||E.select.annotation===I});return b.set(I,w),w}};return{panelBorder:a,gridLine:o("gridLine"),tickLine:o("tickLine"),axisLabel:o("axisLabel"),tickLabel:o("tickLabel"),ruleLabel:s,dataLabel:c,graph:r(e.graph,()=>!0),heading:{h1:p("h1"),h2:p("h2")},caption:r(e.caption,()=>!0),source:{label:d(void 0),link:d("link")},header:r(e.header,()=>!0),footer:r(e.footer,()=>!0),hoverGuide:r(e.hoverGuide,()=>!0),tooltip:{box:u(void 0),heading:u("heading"),label:u("label"),value:u("value"),primaryRow:u("primaryRow")},headline:r(e.headline,()=>!0),headlineItem:{number:f("number"),numberCenter:f("numberCenter"),caption:f("caption"),label:f("label"),swatch:f("swatch"),trend:f("trend"),trendUp:f("trendUp"),trendDown:f("trendDown"),trendFlat:f("trendFlat")},legend:Object.assign(i,{popover:m("popover")}),legendItem:{item:h(void 0),swatch:h("swatch")},directLabel:r(e.directLabel,()=>!0),annotation:{shape:y("shape"),arrow:y("arrow"),differenceArrow:Object.assign(y("differenceArrow"),{label:y("differenceArrow","label")}),text:y("text"),image:y("image"),pinnedNumber:Object.assign(y("pinnedNumber"),{label:y("pinnedNumber","label")}),comment:Object.assign(y("comment"),{label:y("comment","label")})}}},mi=(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}},fv=(e,t)=>{const r=(o,s,c)=>{if(c!==void 0){const m=dt(e.overrides,o,s,c);if(m!==void 0)return{value:ut(m,o,t),tier:"override",origin:m.origin,state:c};const h=dt(e.defaults,o,s,c);if(h!==void 0)return{value:ut(h,o,t),tier:"default",origin:h.origin,state:c}}const u=dt(e.overrides,o,s,void 0);if(u!==void 0)return{value:ut(u,o,t),tier:"override",origin:u.origin};const d=hi(o,s);if(d!==void 0)return{value:d,tier:"data"};const p=dt(e.defaults,o,s,void 0);return p!==void 0?{value:ut(p,o,t),tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}},n=(o,s,c)=>{if(c!==void 0){const p=Gt(e.overrides,o,s,c,t);if(p!==void 0)return p;const m=Gt(e.defaults,o,s,c,t);if(m!==void 0)return m}const u=Gt(e.overrides,o,s,void 0,t);if(u!==void 0)return u;const d=hi(o,s);return d!==void 0?d:Gt(e.defaults,o,s,void 0,t)};return{get:n,getSource:(o,s,c)=>r(o,s,c).tier,explain:r,collectAll:(o,s,c)=>{const u=[];for(const d of[e.defaults,e.overrides]){const p=d[o]?.[c??"stateless"];if(p!==void 0)for(const m of p){const h=m.declarations[o];h!==void 0&&Js(m,s)&&u.push(gv(h,t))}}return u},resolve:(o,s)=>{const c={};for(const u of Zs){const d=n(u,o,s);d!==void 0&&Object.assign(c,{[u]:d})}return c}}},Gt=(e,t,r,n,a)=>ut(dt(e,t,r,n),t,a),ut=(e,t,r)=>{const n=e?.declarations[t];return n===void 0?void 0:l.resolveColorScheme(n,r)},dt=(e,t,r,n)=>{const a=e[t]?.[n??"stateless"];if(a!==void 0)for(let i=a.length-1;i>=0;i--){const o=a[i];if(o!==void 0&&Js(o,r))return o}},Js=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),gv=(e,t)=>l.isLightDarkColor(e)?e[t]:e,hi=(e,t)=>{const r=pv[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Xn=(e,t,r)=>{const n={},a=i=>{const o=n[i];if(o!==void 0)return o;const{width:s,height:c}=e(t,i,r),u={width:s,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},Ut=6,yv=.5,vv=e=>{const t=[];let r=0;const n=l.isStackedPosition(e.layer.position),a=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:i,shouldRotate:o}=Sv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:a});for(const s of i){const c=e.layer.dataLabels.position==="auto"?Iv({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Lv(e.layer.dataLabels,e.coordSystem.mainAxis,n,s,Lt(e.panelRect));if(c===null){r+=1;continue}const u=s.boxes[c.position];t.push({layerId:e.layer.id,x:c.x,y:c.y,text:s.text,width:u.width,height:u.height,isRotated:c.isRotated,target:"observation",position:c.position,...c.position==="inside"?{backdropColor:s.backdropColor}:{}})}}if(e.layer.dataLabels.showCategoryLabels)for(const i of wv(e,n))t.push(i);if(e.layer.dataLabels.showStackTotals){const i=Vv({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of i)t.push(o)}return{labels:t,droppedCount:r}},bv={place:vv,getPercentageValueStrategy:e=>e.position==="fill"?"fill":l.isStackedPosition(e.position)?"stack":"absoluteGrandTotal"},Sv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const o=[];let s=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y),d=st().geomReaders(e);for(const p of e.data){const m=el(t,p);if(m===null)continue;const h=a(p);if(h==="")continue;const f=Xn(n,"observation",h),y=Zn(m,r);c&&f.inside.width>y.width&&(s=!0);const v=u===null?null:p[u],g=l.isStrictNumericDataValue(v)&&v<0;o.push({isNegative:g,text:h,boxes:f,bounds:y,backdropColor:d.get("color",p)})}return{entries:o,shouldRotate:!i&&s}},Zn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),Qs=(e,t,r,n,a)=>{if(e==="x"){let s=1-a,c=a-n;return c<0&&(s+=c,c=-c),{x:t,y:s,width:r-t,height:c}}let i=t,o=r-t;return o<0&&(i+=o,o=-o),{x:i,y:1-a,width:o,height:a-n}},el=(e,t)=>{const r=j(t),n=X(t),a=U(t),i=$(t)??_(t);return r===null||n===null||a===null||i===null?null:Qs(e,r,n,a,i)},xv=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return Qs(e,r,n,a,i)},Av=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",tn=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Iv=e=>e.isStacked?Ev({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):Cv({edge:Av(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),tl=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Tv=e=>e==="panel-start"||e==="panel-end",Lv=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,o=n.boxes[i],s=wt({box:n.bounds,panel:a,frame:tl(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:o.width,labelHeight:o.height});if(i==="inside"&&!Tv(e.justify)){const c=t==="y",u=c?n.bounds.width:n.bounds.height;return(c?o.width:o.height)>u+yv?null:{x:s.x,y:s.y,isRotated:!1,position:"inside"}}return{x:s.x,y:s.y,isRotated:!1,position:s.position}},wv=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:o}=e.layer.dataLabels,s=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=Lt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const p of e.layer.data){const m=el(c,p);if(m===null)continue;const h=e.formatCategory(p);if(h===null||h==="")continue;const f=Xn(e.measureDataLabel,"category",h),y=f[s],v=Zn(m,e.panelRect),g=d===null?null:p[d],b=l.isStrictNumericDataValue(g)&&g<0,I=wt({box:v,panel:u,frame:tl(c,b),placement:s,justify:a,align:i,offset:o,labelWidth:y.width,labelHeight:y.height}),L=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:h,width:L.width,height:L.height,isRotated:!1,target:"category",position:I.position})}return r},Ev=({bounds:e,box:t,isRotated:r})=>{const n=tn(t.width,t.height,r);return n.width>e.width||n.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},Rv=(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}}},Cv=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:o})=>{const s=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=s?t.height:t.width,p=s?t.width:t.height,{edgeCoord:m,outwardSign:h,panelExtent:f}=Rv(e,t,a,i),y=tn(r.inside.width,r.inside.height,n),v=s?y.height:y.width,g=s?y.width:y.height,b=v+o<d,I=g<=p;if(s?b:b&&I){if(s&&!I)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const R=m-h*(v/2+o);return{...s?{x:c,y:R}:{x:R,y:u},isRotated:!1,position:"inside"}}const L=tn(r.outside.width,r.outside.height,n),w=(s?L.height:L.width)/2,E=m+h*(w+o);return E-w<0||E+w>f?null:{...s?{x:c,y:E}:{x:E,y:u},isRotated:n,position:"outside"}},Vv=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],o=e.summary.stackTotals;if(o===void 0||o.length===0)return i;const s=t==="y";for(const c of o){const u=Zn(xv(t,c),r),d=a(c.total),{width:p,height:m}=n("aggregate","outside",d),h=c.anchor.direction==="positive";let f,y;s?(f=h?u.x+u.width+Ut+p/2:u.x-Ut-p/2,y=u.y+u.height/2):(f=u.x+u.width/2,y=h?u.y-Ut-m/2:u.y+u.height+Ut+m/2),i.push({layerId:e.id,x:f,y,text:d,width:p,height:m,isRotated:!1,target:"aggregate",position:"outside"})}return i},Dv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=Pv(e.layer);for(const a of e.layer.data){const i=k(a),o=_(a);if(i===null||o===null||!tt(i,o))continue;const s=e.formatLabel(a);if(s==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",s),d=wt({box:{x:i*e.panelRect.width,y:(1-o)*e.panelRect.height,width:0,height:0},panel:Lt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:s,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return{labels:t,droppedCount:0}},_v={place:Dv,getPercentageValueStrategy:()=>"none"},Pv=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:pr(e.data,e.mapping)?qn(r):r,align:n}},Ov=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{offset:r}=e.layer.dataLabels,n=kv(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=st().geomReaders(e.layer);for(const o of e.layer.data){const s=k(o),c=_(o);if(s===null||c===null||!tt(s,c))continue;const u=e.formatLabel(o);if(u==="")continue;const{width:d,height:p}=e.measureDataLabel("observation","outside",u),m=i.get("size",o)/2,h=wt({box:{x:s*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:Lt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+m,alignOffset:r+m,labelWidth:d,labelHeight:p});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:u,width:d,height:p,isRotated:!1,target:"observation",position:h.position})}return{labels:t,droppedCount:0}},Mv={place:Ov,getPercentageValueStrategy:()=>"none"},kv=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}},rl=e=>{const t=j(e),r=X(e),n=U(e),a=$(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),o=Math.abs(r-t),s=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-s,width:o,height:c}},nl=e=>{const t=rl(e);if(!t)return null;const r=t.width*$h,n=t.height*Gh;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},fi=4,Nv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const r=st().geomReaders(e.layer);for(const n of e.layer.data){const a=nl(n);if(a===null||!Et(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:o,height:s}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;o+fi>c||s+fi>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:o,height:s,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return{labels:t,droppedCount:0}},Bv={place:Nv,getPercentageValueStrategy:()=>"none"};function Jn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Qn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var Fv=" · ",Or=2,ht=(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)},$v=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=ht("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Or&&t+i<=e.outerRadiusPx+Or)||t<=0)return!1;const o=Math.abs(e.endAngle-e.startAngle)/2,s=ht("tangential",r,n,a)/t,c=Or/t;return Math.abs(r-e.midAngle)+s<=o+c},Gv=({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,gi=({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+ht("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},Uv=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:o})=>{const s=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+ht("radial",s,i,o);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const p=e.innerRadiusPx-c;u=p>=0?p:e.innerRadiusPx+c}let d=s;if(n!=="center"&&u>0){const p=ht("tangential",s,i,o)/u;d=s+(n==="start"?1:-1)*p}return{labelRadius:u,labelAngle:d,position:$v({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:o})?"inside":"outside"}},Hv=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{position:r,justify:n,align:a,offset:i,showCategoryLabels:o}=e.layer.dataLabels,s=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2,p=st().geomReaders(e.layer);for(const m of e.layer.data){const{startAngle:h,endAngle:f}=Jn(m),{innerRadius:y,outerRadius:v}=Qn(m);if(h===null||f===null||v===null)continue;const g=e.formatLabel(m);if(g==="")continue;const b=o?e.formatCategory(m):null,I=b===null?g:`${b}${Fv}${g}`,L={startAngle:h,endAngle:f,midAngle:(h+f)/2,innerRadiusPx:(y??0)*d,outerRadiusPx:v*d};let w,E;if(r==="auto"){const T=e.measureDataLabel("observation",s,I);E={width:T.width,height:T.height},w=gi({wedge:L,position:s,offset:i,labelWidth:E.width,labelHeight:E.height});const D=c+Math.sin(w.labelAngle)*w.labelRadius,O=u-Math.cos(w.labelAngle)*w.labelRadius;if(w.position==="outside"&&!Gv({x:D,y:O,labelWidth:E.width,labelHeight:E.height,panelRect:e.panelRect})){const ie=e.measureDataLabel("observation","inside",I);E={width:ie.width,height:ie.height},w=gi({wedge:L,position:"inside",offset:i,labelWidth:E.width,labelHeight:E.height})}}else{const T=Xn(e.measureDataLabel,"observation",I),D=T[r];w=Uv({wedge:L,placement:r,justify:qn(n),align:a,offset:i,labelWidth:D.width,labelHeight:D.height}),E=T[w.position]}const R=c+Math.sin(w.labelAngle)*w.labelRadius,V=u-Math.cos(w.labelAngle)*w.labelRadius;t.push({layerId:e.layer.id,x:R,y:V,text:I,width:E.width,height:E.height,isRotated:!1,target:"observation",position:w.position,...w.position==="inside"?{backdropColor:p.get("color",m)}:{}})}return{labels:t,droppedCount:0}},Wv={place:Hv,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Kv=e=>{const t=N({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=N({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},N=e=>{switch(e.valueFormat.type){case"currency":return Bs(e);case"date":return Py(e);case"datetime":return Oy(e);case"day_month":return Us(e);case"decimal":return Fs(e);case"duration":return Fn(e);case"integer":return $s(e);case"month":return Hs(e);case"month_year":return Un(e);case"percentage":return Gs(e);case"quarter":return Hn(e);case"text":return Bn(e);case"weekly_date_range":return Ws(e);case"weekly_date_range_with_year":return Ks(e);case"year":return Wn(e);case"time":return zs(e);case"lookup":return Kv({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function ea({layer:e,numberFormat:t,locale:r}){return N({valueFormat:cp(e),locale:r,numberFormat:t})}var zv=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:ot(e,t),variable:r}:{read:re,variable:l.GROUP_VARIABLES.group}},al=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:s})=>{const c=ea({layer:e,numberFormat:n,locale:o}),u=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Zv({layer:e,numberFormat:n,axes:r,locale:o,absoluteFormatter:c,percentageValueStrategy:s,isFlipped:u}),formatAbsolute:c,formatCategory:Yv({layer:e,numberFormat:n,locale:o})}},Yv=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=zv(e.data,e.mapping),i=N({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},qv=(e,t,r)=>{switch(t){case"stack":return jv(e);case"fill":return Xv(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},jv=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(En(a,t));return s===void 0?null:s.total}},Xv=(e,t)=>{const r=t?j:U,n=t?X:$,a=yt(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Zv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=Q(e.data,e.dataLabels.labelSource),c=qv(e,i,o),u=Jv({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=N({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),p=e.dataLabels.format==="percentage"&&il(e);return m=>{const h=s(m);if(h===null)return"";if(!p||!l.isStrictNumericDataValue(h))return u(h,m);const f=c(m);return f===null||f===0?u(h,m):d(h/f)}},Jv=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.extractVariableName(i);if(o!==null){if(il(e))return a;const s=Qv(e,r,t,n,o);if(s!==null)return s}return N({valueFormat:eb(e.data,i),locale:n,numberFormat:t})},il=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(cr(e.position,e.mapping))},Qv=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:N({valueFormat:o.valueFormat,locale:n,numberFormat:r})},eb=(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)},ta={bar:{cartesian:bv,polar:Wv},line:{cartesian:_v},point:{cartesian:Mv},area:{cartesian:ov},tile:{cartesian:Bv}},tb=(e,t)=>ta[e]?.[t]!==void 0,rb=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:o,formattingLocale:s,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],p=s??a,m=t.type;let h=0;for(const f of e){if(!f.dataLabels.showDataLabels&&!f.dataLabels.showStackTotals&&!f.dataLabels.showCategoryLabels)continue;const y=f.geom,v=ta[y]?.[m];if(v===void 0)continue;const g=al({layer:f,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:o,formattingLocale:p,percentageValueStrategy:v.getPercentageValueStrategy(f)}),b=v.place(g);h+=b.droppedCount;for(const I of b.labels)ab(I,m,c,u)||d.push(I)}return{labels:d,warnings:h>0?[nb(h)]:[]}},nb=e=>({code:"DATA_LABELS_DROPPED",severity:"warning",kind:"user-input",message:e===1?"Dropped 1 data label that did not fit under position 'auto'.":`Dropped ${e} data labels that did not fit under position 'auto'.`,suggestion:"Set dataLabels.position to 'outside' to keep labels that do not fit inside the bars.",context:{actual:e}}),ab=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*ib({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:o}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const s of e){if(!s.dataLabels.showDataLabels&&!s.dataLabels.showStackTotals)continue;const c=ta[s.geom]?.cartesian;if(c===void 0)continue;const u=al({layer:s,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:o,percentageValueStrategy:c.getPercentageValueStrategy(s)});for(const d of c.place(u).labels)yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var Mr={abbreviation:"none",decimals:"auto"},ol=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return N({valueFormat:a,locale:e,numberFormat:Mr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/r;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":N({valueFormat:{type:"percentage"},locale:e,numberFormat:Mr,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${N({valueFormat:{type:"decimal"},locale:e,numberFormat:Mr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},ob=2,sb=6,lb=6,cb=15,ub=15,db=2.5,pb=.5,mb=.25,sl=e=>{const t=e-ob,r=1+pb*t,n=1+mb*t;return{arrowStartGap:sb*r,arrowEndGap:lb*r,offsetFromHigherObservation:cb*n,arrowheadSize:db*e,curveRadius:ub*n,strokeWidth:e}},hb=(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},fb=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
|
|
2
2
|
M ${o.x} ${o.y}
|
|
3
3
|
L ${s.x} ${s.y+i}
|
|
4
4
|
Q ${s.x} ${s.y} ${s.x+d*i} ${s.y}
|
|
5
5
|
L ${c.x-d*i} ${c.y}
|
|
6
6
|
Q ${c.x} ${c.y} ${c.x} ${c.y+i}
|
|
7
7
|
L ${u.x} ${u.y}
|
|
8
|
-
`},
|
|
8
|
+
`},gb=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x+n,y:e.y},s={x:r,y:e.y},c={x:r,y:t.y},u={x:t.x+a,y:t.y},d=t.y>e.y?1:-1;return`
|
|
9
9
|
M ${o.x} ${o.y}
|
|
10
10
|
L ${s.x-i} ${s.y}
|
|
11
11
|
Q ${s.x} ${s.y} ${s.x} ${s.y+d*i}
|
|
12
12
|
L ${c.x} ${c.y-d*i}
|
|
13
13
|
Q ${c.x} ${c.y} ${c.x-i} ${c.y}
|
|
14
14
|
L ${u.x} ${u.y}
|
|
15
|
-
`},
|
|
15
|
+
`},yb=(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 Od=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
|
-
`,pb=(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},mb=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),il=({arrow:e,style:t,mainAxis:r,panelWidth:n,panelHeight:a,locale:i})=>{const o=r==="y",s={x:e.start.x*n,y:(1-e.start.y)*a},c={x:e.end.x*n,y:(1-e.end.y)*a},u=al(t.strokeWidth),d=lb(o,s,c,u),p=(o?ub:cb)(s,c,d,u),m=db(o,c,u),h=pb(o,s,c,d,mb(o,s,c),e.labelCrossPosition),f=nl({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:s,end:c,linePath:p,arrowheadPath:m,labelPosition:h,labelText:f}},mi={large:1,medium:23/26,small:19/26},hb={large:1,medium:10/12,small:10/12},fb=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],ol=e=>e.fontSize*e.lineHeight,gb=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),B=(e,t)=>({fontFamily:e.get("fontFamily")??t.get("fontFamily"),fontSize:e.get("fontSize")*t.get("textScale"),fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),yb=e=>B(e.heading.h1,e.graph),vb=e=>B(e.heading.h2,e.graph),bb=e=>B(e.caption,e.graph),Sb=e=>({label:B(e.source.label,e.graph),link:B(e.source.link,e.graph)}),xb=(e,t)=>B(e.axisLabel(t),e.graph),Ab=(e,t,r)=>{const n=e.tickLabel(t,r);return{...B(n,e.graph),offset:n.get("offset")}},Ib=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...B(n,e.graph),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock"),borderRadius:n.get("borderRadius"),isTextColorAuthored:n.getSource("textColor")==="authored",...a===void 0?{}:{background:a},...i===void 0?{}:{borderColor:i},...o===void 0?{}:{borderWidth:o}}},Tb=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=B(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},Lb=e=>{const t=e.tooltip.box,r=e.graph;return{box:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")},heading:B(e.tooltip.heading,r),label:B(e.tooltip.label,r),value:B(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},wb=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...B(t,e.graph),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),borderRadius:t.get("borderRadius"),borderWidth:t.get("borderWidth"),...r===void 0?{}:{background:r},...n===void 0?{}:{borderColor:n}},swatch:{size:e.legendItem.swatch.get("size"),strokeWidth:e.legendItem.swatch.get("strokeWidth")}}},Eb=e=>{const t=e.directLabel;return{...B(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},Rb=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=mi[t]*n,i=hb[t]*n,o=e.headlineItem,s=B(o.number,e.graph),c={...s,fontSize:s.fontSize*mi[t]},u=o.numberCenter.get("fontSize");return{number:c,...Vb(o.numberCenter)?{numberCenter:$t(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:$t(o.caption,o.caption.get("fontSize")*i,r),label:$t(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:$t(o.trend,o.trend.get("fontSize")*i,r),trendUp:{textColor:o.trendUp.get("textColor")},trendDown:{textColor:o.trendDown.get("textColor")},trendFlat:{textColor:o.trendFlat.get("textColor")}}},Cb=(e,t)=>{const r=t?e.numberCenter:void 0;return r===void 0?e.number:{fontFamily:r.fontFamily??e.number.fontFamily,fontSize:r.fontSize,fontWeight:r.fontWeight??e.number.fontWeight,lineHeight:r.lineHeight??e.number.lineHeight,textColor:r.textColor??e.number.textColor}},Vb=e=>fb.some(t=>e.getSource(t)!=="unresolved"),$t=(e,t,r)=>{const n=e.get("fontFamily")??r,a=e.get("fontWeight"),i=e.get("lineHeight"),o=e.get("textColor");return{fontSize:t,...n===void 0?{}:{fontFamily:n},...a===void 0?{}:{fontWeight:a},...i===void 0?{}:{lineHeight:i},...o===void 0?{}:{textColor:o}}},sl=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=ol(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*Db({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!tt(o.start.x,o.start.y)||!tt(o.end.x,o.end.y))continue;const s=a(o.id),c=il({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=sl({labelPosition:c.labelPosition,measuredTextWidth:i(c.labelText,s.label).width,label:s.label});yield{...u,x:r.x+u.x,y:r.y+u.y}}}var _b=e=>{const t=e.padding,r=hi(e.rows,t?.top??0,t?.bottom??0),n=hi(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:kb(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Pb=e=>{const t=fi(e.rows,e.height),r=fi(e.cols,e.width),n=gi(t),a=gi(r),i=new Map;for(const o of e.placements){const s=o.rowSpan??1,c=o.colSpan??1,u=a[o.col]??0,d=n[o.row]??0,p=yi(r,o.col,c),m=yi(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,m)})}return i},hi=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;en(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push(Ob(s));const c=Mb(e,o);if(en(s)&&c){const u=s.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},Ob=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},en=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Mb=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&en(n))return n}},kb=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),o=r.get(a.col);if(i===void 0||o===void 0)continue;const s=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):o;s===void 0||c===void 0||n.push({name:a.name,row:i,col:o,rowSpan:Math.max(1,s-i+1),colSpan:Math.max(1,c-o+1)})}return n},fi=(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)},gi=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},yi=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},nt={top:0,right:0,bottom:0,left:0},ll={outer:nt,inner:nt},Nb=(e,t,r,n=nt,a=ll,i=l.DEFAULT_GRAPH_PADDING_EDGES,o)=>{const s={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=[{name:"header",size:t.headerSize.height,gaps:pe(o.header)},{name:"topLegend",size:r.legends.top,gaps:pe(o.legend.top)},{name:"headline",size:r.headline,gaps:pe(o.headline)},{name:"topAxisLabel",size:c,gaps:pe(o.axisLabel.top)},{name:"topAxis",size:r.axes.top,gaps:pe(o.tickLabel.top)},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:s.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:s.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:pe(o.tickLabel.bottom)},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:pe(o.axisLabel.bottom)},{name:"bottomLegend",size:r.legends.bottom,gaps:pe(o.legend.bottom)},{name:"footer",size:t.footerSize.height,gaps:pe(o.footer)}],d=[{name:"leftLegend",size:r.legends.left,gaps:Gt(o.legend.left)},{name:"leftAxis",size:r.axes.left,gaps:Gt(o.tickLabel.left)},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:s.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:s.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:Gt(o.tickLabel.right)},{name:"rightLegend",size:r.legends.right,gaps:Gt(o.legend.right)}],p=vi(u,i.top,i.bottom),m=vi(d,i.left,i.right);return _b({rows:u,cols:d,placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...Fb(r.axes),...$b(r.axesLabels,r.axes),...Gb(r.legends)],containerSize:e,padding:{top:p.start,bottom:p.end,left:m.start,right:m.end}})},pe=e=>({before:e.top,after:e.bottom}),Gt=e=>({before:e.left,after:e.right}),Bb=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,vi=(e,t,r)=>{const n=e.filter(Bb),a=n[0],i=n[n.length-1];return{start:t+(a?.gaps?.before??0),end:r+(i?.gaps?.after??0)}},Fb=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},$b=(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},Gb=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 Ub=class{constructor(e){this.outer={...nt},this.inner={...nt},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},Hb=["top","right","bottom","left"],Or=(e,t)=>{const r={};for(const n of Hb){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function bi(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var tn=["large","medium","small"],Wb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of tn)if(r(n)<=t)return n;return"small"},Kb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:tn.indexOf(e);for(const a of tn.slice(n))if(r(a)<=t)return a;return null},zb=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const o=a===0?i:n+t+i;if(o>r)break;n=o,a+=1}return a},Yb=({headline:e,containerSize:t,measurer:r})=>{if(gr(e))return 0;const n=cl(e,t.width,r);return r.measureHeadline(e.formatted,n).height},qb=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(gr(e)){const s=jb(t.panel,e.innerRadius),c=Kb({size:e.size,availableWidth:s.width,measureStripWidth:ul(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=cl(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=zb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},gr=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,jb=(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}},cl=(e,t,r)=>Wb({size:e.size,availableWidth:t,measureStripWidth:ul(e,r)}),ul=(e,t)=>r=>t.measureHeadline(e.formatted,r,gr(e)).width,ze={x:0,y:0,width:0,height:0},Xb={top:0,right:0,bottom:0,left:0},Zb="0000",Jb=3,Qb=e=>e.plot.y+e.plot.height-e.panel.y,eS=class{constructor(e){this.measurer=e}compile(e){return sr({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:ll,panelBorder:e.panelBorder??nt,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,margins:e.margins}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:tS(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Si(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Si(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:Qb(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new Ub(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of Db({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,locale:r,resolveStyle:e.resolveDifferenceArrowStyle,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(o,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const o of Qv({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(o,e.overflowStrategy.dataLabels);const i=a.resolve();return bi(i.inner,n.inner)&&bi(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p}){let m=t,h=o;for(let f=0;f<Jb;f++){const y=this.measurePanelOverflow(e,m.panelFrame,u,h);if(y===h)break;h=y,m=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:y,panelBorder:s,headline:c,padding:d,margins:p})}return m}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,o=a.height-n.vertical*2;return i<=0||o<=0?xi(r,a,0,0):xi(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=H(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const o=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,o.width),a=Math.max(a,o.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:Zb}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=H(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=qy({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:s,...c}=e,u={...c,ticks:o,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?Hy({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:o,padding:s,margins:c}){const u=Pb(Nb(r,n,this.measureGuides(e,t,o,r),i,a,s,rS(c,t)));return{header:u.get("header")??ze,headline:u.get("headline")??ze,footer:u.get("footer")??ze,plot:u.get("plot")??ze,panelFrame:u.get("panelFrame")??ze,panel:u.get("panel")??ze,axes:Or(u,"Axis"),axisLabels:Or(u,"AxisLabel"),legends:Or(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const s of e)s.isVisible&&s.geometry==="linear"&&(a[s.position]=this.measurer.measureAxis(s),s.label!==null&&(i[s.position]=this.measurer.measureAxisLabel(s)));const o={top:0,right:0,bottom:0,left:0};for(const s of t)o[s.position]=this.measurer.measureLegend(s);return{axes:a,axesLabels:i,legends:o,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:Yb({headline:e,containerSize:t,measurer:this.measurer})}},Si=e=>e==="left"||e==="right",xi=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,o=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-o)/2,y:t.y+n+(i-o)/2,width:o,height:o}}},tS=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(o=>o.value)),a=new WeakMap;return i=>{const o=a.get(i);if(o)return o;const s=Kn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},rS=(e,t)=>{const r={...e.legend};for(const n of t)n.display==="direct"&&(r[n.position]=Xb);return{...e,legend:r}},nS=(e=[])=>{const t=aS(e);return{resolve:(r,n,a)=>{if(!t.has(r))return null;const i=t.get(r).resolveAnchorPosition?.(n,a)??null;return i===null?null:{...i,frame:gn(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?Lo(r,t.get(r.geom)):null}},aS=e=>{const t=new pr;for(const r of e){const n=Rn(r);n instanceof be&&t.register(n.type,n)}return t};function iS(e){return e}function ce(e){return 1-e}var Ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Qt=(e,t)=>{const r=lr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+ce(e.y)*r.height}},oS=(e,t)=>{const r=lr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(ce(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},sS=class{constructor(e,t,r){this.annotations=e,this.panelRect=t,this.measuredBoxes=r,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const i=this.toPanelPoint(e),{x:o,y:s}=rn(e.defer,this.panelRect);return Ti({...e,x:i.x+o,y:i.y-s})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=ft(t,e.defer.align),{x:n,y:a}=lS(r,e.defer.offset,this.panelRect);return{x:n,y:a}}resolveRegion(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const a=this.toPanelRegion(e),{x:i,y:o}=rn(e.defer,this.panelRect);return Ti({...e,x:a.x-i,y:a.y-o,width:Math.max(0,a.width+2*i),height:Math.max(0,a.height+2*o)})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=t.xMax-t.xMin,n=t.yMax-t.yMin;return r<=0||n<=0?null:{x:t.xMin,y:t.yMin,width:r,height:n}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:cS(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:Ai(this.toPanelPoint(r),this.toPanelPoint(n))}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=this.toPanelPoint(r),i=t.annotation.width,o=n.height/this.panelRect.height,s=fo(t.annotation.align),c=a.x-s.x*i,u=a.y+(1-s.y)*o;return{xMin:c,xMax:c+i,yMin:u-o,yMax:u}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Ii(this.toPanelPoint(r))}case"differenceArrow":return Ai(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return Ii(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Na(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Na(e,this.panelRect),r=lr(e.frame,this.panelRect);return{...t,width:this.panelRect.width>0?e.width*r.width/this.panelRect.width:0,height:this.panelRect.height>0?e.height*r.height/this.panelRect.height:0}}},rn=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),lS=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:o}=rn({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-o}}return{x:e.x+n,y:e.y-a}},cS=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),Ai=(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)}),Ii=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),Ti=e=>{const t={...e};return delete t.defer,delete t.frame,t},uS=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!dS(t))return t;const o=new sS(t,r,n),s={...t,shapes:ut(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:ut(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:ut(t.arrows,d=>d.start.defer!==void 0||d.end.defer!==void 0,d=>{const p=o.resolvePoint(d.start),m=o.resolvePoint(d.end);return p===null||m===null?null:{...d,start:p,end:m}}),textAnnotations:ut(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:ut(t.stickers,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}})},c=o.cyclicIds();c.length>0&&a?.(c);const u=o.missingRefIds();return u.length>0&&i?.(u),s},ut=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,dS=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),pS=800,Li=400,mS=.75,hS=.875,fS=4,gS=e=>Math.max(1,(e-Li)/(pS-Li)+1),yS=(e,t)=>{const r=gS(t),n=e*fS;return{strokeWidth:Math.min(e,e*mS*r),arrowheadLength:Math.min(n,n*hS*r)}},Ut=Math.PI/4,nn=1.5,vS=2,bS=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,wi=(e,t,r)=>{if(r<=0)return"";const{start:n,end:a}=t,i=e==="start"?n.x:a.x,o=e==="start"?n.y:a.y,s=e==="start"?Math.atan2(n.y-a.y,n.x-a.x):Math.atan2(a.y-n.y,a.x-n.x);return`M ${i} ${o} L ${i-r*Math.cos(s-Ut)} ${o-r*Math.sin(s-Ut)} M ${i} ${o} L ${i-r*Math.cos(s+Ut)} ${o-r*Math.sin(s+Ut)}`},SS=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*vS}`:`${t*nn} ${t*nn*2}`,xS=(e,t,r)=>e==="dashed"&&r?t*nn:0,AS=64,IS=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:Qt(e.start,a),end:Qt(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=yS(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=TS(s,c),d=e.startArrowheadStyle==="line-arrow",p=e.endArrowheadStyle==="line-arrow",m=d||p?u*Math.sin(Math.PI/4):0;return{id:e.id,linePath:bS(i),startArrowheadPath:d?wi("start",i,u):"",endArrowheadPath:p?wi("end",i,u):"",strokeWidth:o,dashArray:SS(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:xS(t.lineType,o,d),arrowheadExtent:m}},TS=(e,t)=>Math.min(e,t*e/AS);function LS(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(p=>p.transformType==="filter"&&p.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let o,s,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")o="color",s=a.options.variableName,c=a.options.value;else if(i!==null)o="y",s=i,c=i;else continue;const u=wS(e,o,s);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d,layerId:u.id,groupValue:c})}return r}function wS(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 dl=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),ES=0,RS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:dl(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:ES})),CS=9,VS=8,DS=2,pl=e=>typeof e=="string"?e:ml(e),ml=e=>e.text!==void 0?e.text:e.content?e.content.map(ml).join(""):"",Ei={top:"bottom",bottom:"top",right:"left",left:"right"};function _S(e,t,r){return r.type==="polar"?MS(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function an(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 Ri(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function PS(e,t){return{...t,x:Math.max(0,Math.min(t.x,e.width-t.width)),y:Math.max(0,Math.min(t.y,e.height-t.height))}}function OS(e,t,r=2){return e.x<t.x+t.width-r&&e.x+e.width>t.x+r&&e.y<t.y+t.height-r&&e.y+e.height>t.y+r}function MS(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[o,s]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[o,Ei[o],s,Ei[s]]}function kS(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:o}=e,s=[...t.map(d=>{const{id:p,at:m}=d;return Ci(p,"pinned-number",m,o(d),i,n)}),...r.map(({id:d,at:p,content:m})=>Ci(d,"comment",p,pl(m),i,n))];s.sort((d,p)=>d.anchorPx.x-p.anchorPx.x||d.anchorPx.y-p.anchorPx.y);const c=[],u=[];for(const d of s){if(!d.inView){c.push(Vi(n,d,"top"));continue}const p=Vi(n,d,BS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Ci(e,t,r,n,a,i){const o=Qt(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:NS(o,i)}}function NS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function BS(e,t,r,n){const a=_S(t.anchorPx,e,r);for(const i of a){const o=an(t.anchorPx,i,t.mini);if(Ri(o,e)&&!n.some(s=>OS(o,s)))return i}for(const i of a)if(Ri(an(t.anchorPx,i,t.mini),e))return i;return"top"}function Vi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:PS(e,an(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var FS=(e,t,r)=>e.anchor.layerId!==t.anchor.layerId||!l.areDataValuesEqual(e.anchor.groupValue??null,t.anchor.groupValue??null)||r.start===void 0||r.start!==r.end?null:r.start,$S=100,GS=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,o=!0,s=0;for(;o;){o=!1,s++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const p=u.y+a,m=d.y-a;if(p>m){o=!0,i=!0;const h=(p-m)/2+1;u.y-=h,d.y+=h,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(s>$S)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}},US=(e,t)=>hl(e,t,{variables:fl(e),allowNull:!1}),hl=(e,t,{variables:r,allowNull:n})=>{const a=Eo(e),i=[];for(const s of r){const c=a(t,s);if(c===null&&!n)return null;i.push({variable:s,eq:c})}const[o]=i;return o===void 0?null:i.length===1?o:{and:i}},fl=e=>{const t=fn(e)?Le(e.data,e.mapping):[],r=hn(e),n=r===null?t:[...t,r],a=ke(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},yr=e=>e!=="data-point",HS=(e,t)=>{switch(t){case"series":{const r=Le(e.data,e.mapping);return r.length===0?Di(e):{variables:r,allowNull:!0}}case"x-value":{const r=dr(e.mapping);return r===null?null:{variables:[r],allowNull:!0}}case"data-point":return Di(e)}},Di=e=>typeof e.identityKey=="object"?{variables:[e.identityKey.variable],allowNull:!0}:e.identityKey==="index"?null:{variables:fl(e),allowNull:!1},gl=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(ye(t.predicate,e.data).length>0)return[];const n=ge(t.predicate,st(e,r));return yr(t.scope)?KS(e,n,t.scope):WS(e,n)},WS=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},KS=(e,t,r)=>{const n=dr(e.mapping),a=[],i=new Set;for(const s of e.data){const c=dt(r,s,n);a.push(c),t(s)&&i.add(c)}const o=[];return a.forEach((s,c)=>{i.has(s)&&o.push(c)}),o},zS=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=jS(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return qS(o,e,a,t,n)?o:null},YS=e=>e.identityKey==="x-group"?"series":Le(e.data,e.mapping).length===0?"data-point":"series",qS=(e,t,r,n,a)=>ye(e.predicate,t.data).length>0?!1:ge(e.predicate,st(t,a))(r)?!0:yr(e.scope)?gl({layer:t,target:e,parsingLocale:a}).includes(n):!1,jS=(e,t,r)=>{const n=HS(e,r);return n===null?null:hl(e,t,n)},ea=(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},XS=(e,t)=>{for(const r of t)if(ea(e,r.shape))return r;return null},ZS=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},JS=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>QS(r,t[n])),QS=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&ex(e.shape,t.shape)&&tx(e.tooltip,t.tooltip),ex=(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},tx=(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},rx=100,nx=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:rx}),ax=(e,t)=>ea(e,{kind:"circle",center:t.center,radius:t.radius}),ix=(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&&ox(e.target,t.target),ox=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,sx=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=st(e,n),i=lx(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||ye(o.predicate,e.data).length>0)return!1;const s=ge(o.predicate,a);return s(r)?!0:yr(o.scope)&&i(o.scope).some(s)})},lx=(e,t)=>{const r=dr(e.mapping),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=dt(a,t,r),s=[];for(const c of e.data)dt(a,c,r)===o&&s.push(c);return n.set(a,s),s}},Kt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=yt(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?cx(u,o):u;if(d<0||d>=o)break;const p=e.data.getAt(d);if(p===null||!n(p,d))continue;const m=s(p);if(m!==null&&!a.some(h=>Xe(m,h)))return{anchor:m,observation:p,observationIndex:d}}return null},yl=(e,t)=>{const r=wo(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Xe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),cx=(e,t)=>(e%t+t)%t,vl=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=ke(e),a=yl(e,t),i=e.data.getAt(a);if(i===null)return null;const o=re(i),s=m=>l.areDataValuesEqual(re(m),o),c=[t],u=Kt({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=Kt({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=Kt({layer:e,excluding:c,from:0,step:1,accepts:m=>!s(m)&&l.areDataValuesEqual(m[n]??null,t.anchorValue)});return p!==null?{start:t,end:p.anchor}:null},ux=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=yt(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=vl({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>dx(s,o)))return o}}return null},dx=(e,t)=>Xe(e.start,t.start)&&Xe(e.end,t.end)||Xe(e.start,t.end)&&Xe(e.end,t.start),px=(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}},mx=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:o})=>{const s=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(s===null)return null;const c=o??e.createLayerMeasurement(t);if(c===null)return null;const u=Do(t,r,c);if(u===null)return null;const d=yt(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},hx=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=ke(e),s=yl(e,t),c=e.data.getAt(s);if(c===null)return null;const u=fx(c),d=n==="main"?u:h=>!u(h)&&l.areDataValuesEqual(h[o]??null,t.anchorValue),p=Kt({layer:e,excluding:[t,r],from:s+a,step:a,accepts:(h,f)=>d(h)&&i(h,f)!==null,cycles:n!=="main"});if(p===null)return null;const m=i(p.observation,p.observationIndex);return m===null?null:{...p,point:m}},fx=e=>{const t=re(e);return r=>l.areDataValuesEqual(re(r),t)};function gx({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=N({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var yx=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const o=a??n;return e.kind==="grandTotal"?vx(e,o,r):bx(e,t,o,r,i)},vx=(e,t,r)=>({kind:"grandTotal",value:N({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),bx=(e,t,r,n,a)=>{const i=N({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=N({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=N({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=Kn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:Ix(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:Ax(s.caption,d),comparison:Sx(s.comparison,d,i,a)}})}},Sx=(e,t,r,n)=>e===null?null:{direction:xx(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},xx=e=>e>0?"up":e<0?"down":"flat",Ax=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Ix=(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}},Tx=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Lx(i,a,t))},Lx=(e,t,r)=>({...e,items:e.items.map(n=>{const a=N({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function ta(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function wx(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Ex=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,o=(i?mn:ot)(r.data,r.mapping)(a);return o===null?null:N({valueFormat:ta(e,i?Te(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},Rx=4,Cx=4,Vx=12,Dx=4,_x=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:Mr([Ht("value",r??"–"),Ht("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:kx(a),segments:Mr([Ox(a),Mx(a),Ht("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:Mr([Px(i,t),Ht("label",o)])}].filter(s=>s.segments.length>0)},Ht=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},Px=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},Ox=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Mx=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},kx=e=>{switch(e.direction){case"up":return`Increased ${e.percentage} ${e.reference}`;case"down":return`Decreased ${e.percentage} ${e.reference}`;case"flat":return`No change ${e.reference}`}},Mr=e=>e.filter(t=>t!==null),vr=e=>e==="catmull-rom"?_e.curveCatmullRom:_e.curveLinear,Nx=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Bx=(e,t)=>{const r=vr(t.interpolate),n=(0,_e.area)().curve(r),a=(0,_e.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ce(_(c)??0),o=c=>j(c)??0,s=c=>X(c)??k(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>k(c)??0,o=c=>ce(U(c)??0),s=c=>ce($(c)??_(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>k(o)!==null&&_(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},Fx=(e,t)=>t!=="connect"?e:e.filter(r=>k(r)!==null&&_(r)!==null),ra={none:0,xs:2,sm:4,md:8,lg:12,xl:16},na=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return ra[e.borderRadius??"sm"]},$x=e=>{const t=na(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Gx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),bl=(e,t)=>{const r=j(t),n=X(t),a=U(t),i=$(t)??_(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let o=r,s=n-r;return s<0&&(o+=s,s=-s),{x:o,y:1-i,width:s,height:i-a}},Sl=(e,t)=>e==="x"?`${te(t.x)}-${te(t.width)}`:`${te(t.y)}-${te(t.height)}`,Ux=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}},Hx=e=>{const t=(0,_e.line)().x(r=>k(r)??0).y(r=>ce(_(r)??0)).curve(vr(e.interpolate));return e.missingValues==="gap"&&t.defined(xl),t},Wx=e=>{const t=(0,_e.area)().x(r=>k(r)??0).y0(()=>1).y1(r=>ce(_(r)??0)).curve(vr(e.interpolate));return e.missingValues==="gap"&&t.defined(xl),t},Kx=(e,t)=>t!=="connect"?e:e.filter(r=>k(r)!==null&&_(r)!==null),xl=e=>k(e)!==null&&_(e)!==null,Al=(0,_e.arc)().cornerRadius(e=>e.cornerRadius??0);Al.digits(8);var zx=200,Yx=e=>Al(e)??void 0,qx=(e,t)=>e==="full"?Math.max(0,t)/2:ra[e??"sm"]/zx,Il=(e,t)=>e==="x"?`${te(t.startAngle)}-${te(t.endAngle)}`:e==="y"?`${te(t.innerRadius)}-${te(t.outerRadius)}`:"sweep",jx=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}},Xx=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],br=(e,t,r)=>{const n=ot(e,t);return a=>{const i=re(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},Zx=(e,t,r)=>{const n=ot(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},Jx=(e,t,r)=>{const n=ot(e,t),a=mn(e,t),i=new Map;return o=>{const s=n(o),c=a(o),u=s!==null&&s!==""&&c!==null&&c!==""?`${r}-${s}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},Qx=()=>(e,t)=>Lt(e)??`default-${t}`,_i=2,eA=(e,t)=>{const r=l.extractVariableName(e.mapping.color);if(t!==void 0&&r!==null&&e.data.hasVariable(r)){const n=e.data.getValues(r).findIndex(a=>l.areDataValuesEqual(a,t));if(n!==-1)return e.data.getAt(n)??void 0}return e.data.getFirst()??void 0},aa=(e,t,r,n)=>{const a=e.get("alpha",r);if(!Vs(t,"bar"))return{alpha:a};const i=n.width-_i,o=n.height-_i,s=na({borderRadius:e.get("borderRadius",r),mainAxis:"x",bounds:{width:i,height:o}});return{alpha:a,cornerRadiusPx:Math.min(s,Math.min(i,o)/2)}};function ia(e,t){let r=0,n=e;for(;r<n;){const a=r+n>>>1;t(a)?n=a:r=a+1}return r}function tA(e,t,r){return ia(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>t})}function rA(e,t,r){return ia(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>=t})}function oa(e,t,r,n){const a=e==="x";return{mainDistance:Math.abs(t)*(a?n:1),crossDistance:Math.abs(r)*(a?1:n)}}function sa(e,t,r){return Math.hypot(e*r,t)}function ue(e,t,r){return e<t?t-e:e>r?e-r:0}function ne(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const o=e[i];if(o===void 0)continue;const s=t(o);if(r&&s===0)return o;s<a&&(n=o,a=s)}return n}function nA(e,t){const r=t.height,n=Math.min(t.width,t.height)/2;return{cartesian:Pi(e,r),polar:Pi(e,n)}}function wt(e,t){return e<=t.on.point}function ht({mainDistance:e,crossDistance:t},r){return e<=r.near.main&&t<=r.near.cross}function Pi({on:e,near:t},r){return{on:{edge:e.edge/r,stroke:(e.stroke??e.edge)/r,point:(e.point??e.edge)/r},near:{main:t.main/r,cross:(t.cross??t.main)/r}}}function aA(e,t,r,n,a){if(e.points.length===0)return null;const i=e.delaunay;if(!i)return null;const o=i.find(t.x*r,t.y,n??void 0),s=e.points[o];if(!s)return null;const c=Tl(e,s,t,r);return a===void 0||wt(c.distance,a)||ht(c,a)?c:oA(e,t,r,a)??c}function iA(e,t){if(e.projection==="polar"||e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function oA(e,t,r,n){const{mainAxis:a,byMain:i}=e,o=et(a,t).main,s=a==="x"?n.near.main/r:n.near.main,c=rA(i,o-s,Oi(a)),u=tA(i,o+s,Oi(a));let d=null;for(let p=c;p<u;p+=1){const m=i[p];if(m===void 0)continue;const h=Tl(e,m,t,r);ht(h,n)&&(d===null||h.crossDistance<d.crossDistance)&&(d=h)}return d}function Oi(e){return t=>et(e,t).main}function Tl(e,t,r,n){const{main:a,cross:i}=et(e.mainAxis,r),{main:o,cross:s}=et(e.mainAxis,t);return{...oa(e.mainAxis,o-a,s-i,n),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:sa(t.x-r.x,t.y-r.y,n)}}function Ll(e,t){return e.buckets[sA(e,t)]??null}function sA(e,t){return Rl(e.buckets,t,r=>r.main)}function lA(e,t){return El(e.bands,t,r=>r.bandCenter)}function wl(e,t){return El(e.columns,t,r=>r.mainMid)}function El(e,t,r){return e[Rl(e,t,r)]??null}function Rl(e,t,r){if(e.length===0)return-1;const n=ia(e.length,o=>{const s=e[o];return s!==void 0&&r(s)>=t}),a=e[n-1],i=e[n];return a?i&&Math.abs(r(i)-t)<Math.abs(r(a)-t)?n:n-1:n}function cA(e,t){return{group:uA(e),related:hA(e,t)}}function uA(e){switch(e.kind){case"buckets":{const t=e.match.index;return l.isStackedPosition(t.position)?dA(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return l.isStackedPosition(t.position)?pA(t.layerId,r,n.pointIndex):mA(t.bandByColumn,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function dA(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 pA(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(la(e,a));return n}function mA(e,t,r,n){const a=e.get(r);if(!a)return[];const i=[];for(const o of a.columns)for(const s of o.rects)s.pointIndex!==n&&i.push(la(t,s));return i}function hA(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||gA(r,i,e.match.hit);continue}e.kind==="buckets"&&(l.isStackedPosition(i.position)||i.kind==="buckets"&&fA(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function fA(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&zt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function gA(e,t,r){switch(t.kind){case"buckets":{const n=Ll(t,Z(t.mainAxis,r));if(!n)return;const a=zt(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=lA(t,Z(t.mainAxis,r));if(!n)return;const a=zt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(la(t.layerId,o));return}case"points":{const n=iA(t,r);if(!n)return;zt(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 zt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function la(e,t){return{anchored:!0,layerId:e,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function Cl(e,t,r){const{columns:n,bands:a,bandByColumn:i}=yA(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a,bandByColumn:i}}function yA(e,t){const r=bA(e,t);r.sort((c,u)=>c.mainMid-u.mainMid);const n=new Map,a=new Map,i=new Map;for(const c of r){const u=te(c.mainMid);let d=n.get(u);if(!d){d={mainMid:c.mainMid,rects:[]},n.set(u,d);const p=te(c.bandCenter);let m=a.get(p);m||(m={bandCenter:c.bandCenter,columns:[],mainMin:1/0,mainMax:-1/0,crossMin:1/0,crossMax:-1/0},a.set(p,m)),m.columns.push(d),i.set(d,m)}d.rects.push(c.entry),vA(i.get(d),c.entry,t)}const o=[...n.values()].sort((c,u)=>c.mainMid-u.mainMid),s=[...a.values()].sort((c,u)=>c.bandCenter-u.bandCenter);for(const c of s)c.columns.sort((u,d)=>u.mainMid-d.mainMid);return{columns:o,bands:s,bandByColumn:i}}function vA(e,t,r){if(e===void 0)return;const n=r==="x",a=n?t.xMin:t.yMin,i=n?t.xMax:t.yMax,o=n?t.yMin:t.xMin,s=n?t.yMax:t.xMax;e.mainMin=Math.min(e.mainMin,a),e.mainMax=Math.max(e.mainMax,i),e.crossMin=Math.min(e.crossMin,o),e.crossMax=Math.max(e.crossMax,s)}function bA(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=t==="y",c=s?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let p=0;for(const m of r){const h=n[p],f=a[p],y=i[p],v=o[p];if(!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(y)||!l.isDefined(v)){p++;continue}const g=s?(y+v)/2:(h+f)/2,b=u?.[p]??g;d.push({mainMid:g,bandCenter:b,entry:{pointIndex:p,xMin:Math.min(h,f),xMax:Math.max(h,f),yMin:Math.min(y,v),yMax:Math.max(y,v),observation:m}}),p++}return d}var SA=1e-9,Mi=-1;function Vl(e,t,r){const n=xA(e,t,r),a=n.map(o=>o.entry);n.sort((o,s)=>o.main-s.main);const i=[];for(const o of n){const s=i[i.length-1];s&&Math.abs(s.main-o.main)<=SA?s.entries.push(o.entry):i.push({main:o.main,entries:[o.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:i,entries:a}}function xA(e,t,r){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(l.POSITION_VARIABLES.x),i=n.hasVariable(l.POSITION_VARIABLES.y);if(!a||!i)return[];const o=n.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=n.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),c=t==="y",u=c?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,d=c?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,p=l.isStackedPosition(e.position),m=n.hasVariable(u)?n.getValues(u,{type:"numeric"}):null,h=n.hasVariable(d)?n.getValues(d,{type:"numeric"}):null,f=n.hasVariable(l.GROUP_VARIABLES.group)?n.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,y=new IA(AA(e)),v=new Map,g=[];let b=0;for(const I of n){const L=o[b],w=s[b],E=f?.[b]??null,R=TA(v,E);if(!l.isDefined(L)||!l.isDefined(w)){y.skip(E),b+=1;continue}const V=c?w:L,T=m?.[b],D=p?h?.[b]:void 0;if(p&&(!l.isDefined(T)||!l.isDefined(D))){y.skip(E),b+=1;continue}const O=D??ve(t,{x:L,y:w}),ie={pointIndex:b,...c?{x:O,y:w}:{x:L,y:O},groupKey:E,paintOrder:R,...e.spatialKind==="filled-buckets"&&l.isDefined(T)&&{fill:LA(T,O)},previousAt:Mi,nextAt:Mi,observation:I};y.append(E,{entry:ie,at:g.length}),g.push({main:V,entry:ie}),b+=1}return r==="polar"&&y.close(),g}function AA(e){return"missingValues"in e.params&&e.params.missingValues==="gap"}var IA=class{constructor(e){this.breaksAtNull=e,this.firstByGroup=new Map,this.lastByGroup=new Map,this.brokenGroups=new Set}append(e,t){const r=this.lastByGroup.get(e);r!==void 0&&(r.entry.nextAt=t.at,t.entry.previousAt=r.at),this.firstByGroup.has(e)||this.firstByGroup.set(e,t),this.lastByGroup.set(e,t)}skip(e){this.breaksAtNull&&(this.lastByGroup.delete(e),this.brokenGroups.add(e))}close(){for(const[e,t]of this.firstByGroup){const r=this.lastByGroup.get(e);r===void 0||r===t||this.brokenGroups.has(e)||(r.entry.nextAt=t.at,t.entry.previousAt=r.at)}}};function TA(e,t){const r=e.get(t);if(r!==void 0)return r;const n=e.size;return e.set(t,n),n}function LA(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function Dl(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:wA(e,t)}}function wA(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const p of n)if(!r.hasVariable(p))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const p of r){const m=a[d],h=i[d],f=o[d],y=s[d];if(!l.isDefined(m)||!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(y)){d++;continue}if(c&&!Lt(p)){d++;continue}u.push({pointIndex:d,xMin:m,xMax:h,yMin:f,yMax:y,observation:p}),d++}return u}function on(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function EA(e,t,r){const n=Pl(e),a={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",mainAxis:t,points:n,byMain:CA(t,n),delaunay:null,delaunayAspectRatio:null};return _l(a,r),a}function RA(e){const t=Pl(e).map(r=>{const n=fe(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t}}function _l(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Gd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function CA(e,t){const r=n=>Z(e,n);return[...t].sort((n,a)=>r(n)-r(a))}function Pl(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const o of t){const s=r[i],c=n[i];l.isDefined(s)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:s,y:c,observation:o}),i+=1}return a}function Ol(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:VA(e)}}function Ml(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function VA(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 ki(e,t,r){return t.type==="polar"?DA(e,t.bandAxis):_A(e,t.mainAxis,r)}function DA(e,t){switch(e.spatialKind){case"points":return RA(e);case"buckets":case"filled-buckets":return Vl(e,"x","polar");case"rects":return t===null?Dl(e,"polar"):Cl(e,t,"polar");case"cells":return on(e);case"noop":return on(e);case"render-hit-test":return Ol(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function _A(e,t,r){switch(e.spatialKind){case"points":return EA(e,t,r);case"buckets":case"filled-buckets":return Vl(e,t,"cartesian");case"rects":return Cl(e,t,"cartesian");case"cells":return Dl(e,"cartesian");case"noop":return on(e);case"render-hit-test":return Ol(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function PA(e,t,r){if(e.columns.length===0)return null;const n=wl(e,Z(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=l.isStackedPosition(e.position)?MA(a,t,e.mainAxis):kA(a,t,r),o=kl(i,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:n,distance:o,...OA(e,n,t,r)}}function OA(e,t,r,n){const a=e.bandByColumn.get(t);if(a===void 0)return{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY};const{main:i,cross:o}=et(e.mainAxis,r),s=ue(i,a.mainMin,a.mainMax),c=ue(o,a.crossMin,a.crossMax);return oa(e.mainAxis,s,c,n)}function MA(e,t,r){const n=ve(r,t);return ne(e,i=>NA(i,r,n),{shortCircuitOnZero:!0})}function kA(e,t,r){return ne(e,a=>kl(a,t,r))}function kl(e,t,r){return sa(ue(t.x,e.xMin,e.xMax),ue(t.y,e.yMin,e.yMax),r)}function NA(e,t,r){return ue(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function BA(e,t,r){const n=r.x-t.x,a=r.y-t.y,i=n*n+a*a;if(i===0)return Math.hypot(e.x-t.x,e.y-t.y);const o=((e.x-t.x)*n+(e.y-t.y)*a)/i,s=Math.max(0,Math.min(1,o));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*a))}function FA(e,t,r){const{main:n,cross:a}=et(e.mainAxis,t),i=Ll(e,n);if(i===null)return null;const o=i.entries.map(f=>({entry:f,crossAtCursor:GA(e,f,n)}));if(!l.isNonEmptyArray(o))return null;const s=Bl(o.filter(f=>HA(e,f.entry,n,a)),f=>f.entry),{entry:c}=s??ne(o,f=>Math.abs(f.crossAtCursor-a)),u=sa(c.x-t.x,c.y-t.y,r),d=f=>({x:f.x*r,y:f.y}),p=Sr(e,c).map(d),m=Nl(d(t),d(c),p,u),h=oa(e.mainAxis,i.main-n,ve(e.mainAxis,c)-a,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:c.x,y:c.y,observation:c.observation},index:e,bucket:i,distance:s===void 0?u:0,vertexDistance:u,insideFill:s!==void 0,strokeDistance:s===void 0?m:0,...h}}function $A(e,t,r){return ne(e,a=>Math.abs(ve(r,a)-t))}function Nl(e,t,r,n){const a=r.map(i=>BA(e,t,i));return Math.min(n,...a)}function Sr(e,t){return[e.entries[t.previousAt],e.entries[t.nextAt]].filter(l.isDefined)}function Bl(e,t){return e.reduce((r,n)=>r===void 0||t(n).paintOrder>t(r).paintOrder?n:r,void 0)}function GA(e,t,r){const{mainAxis:n}=e,a=r===Z(n,t)?null:Fl(e,t,r);return a===null?ve(n,t):UA(t,a,n,r)}function UA(e,t,r,n){const a=Z(r,e),i=(n-a)/(Z(r,t)-a),o=ve(r,e);return o+(ve(r,t)-o)*i}function Fl(e,t,r){const{mainAxis:n}=e,a=Z(n,t),i=o=>Math.sign(Z(n,o)-a)===Math.sign(r-a);return Sr(e,t).find(i)??null}function HA(e,t,r,n){const a=WA(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function WA(e,t,r){if(t.fill===void 0)return null;const{mainAxis:n}=e,a=Z(n,t);if(r===a)return t.fill;const i=Fl(e,t,r);if(i?.fill===void 0)return null;const o=(r-a)/(Z(n,i)-a);return{min:t.fill.min+(i.fill.min-t.fill.min)*o,max:t.fill.max+(i.fill.max-t.fill.max)*o}}function KA(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e,distance:0,mainDistance:0,crossDistance:0};return null}function zA(e,t,r){if(e.columns.length===0)return null;const n=dn(t,r),{angle:a,radius:i}=n,o=e.mainAxis==="x",s=o?jA(e.columns,a):wl(e,i),c=s?.rects??[];if(!s||!l.isNonEmptyArray(c))return null;const u=o?XA(c,i):ZA(c,a),d=YA(u,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:(u.xMin+u.xMax)/2,y:(u.yMin+u.yMax)/2,observation:u.observation},index:e,column:s,distance:d,...qA(e,s,n)}}function YA(e,{angle:t,radius:r}){const n=er(t,e.xMin,e.xMax),a=ue(r,e.yMin,e.yMax);return Math.hypot(n*r,a)}function er(e,t,r){return Xt(e,t,r)?0:Math.min(Qe(e,t),Qe(e,r))}function qA(e,t,{angle:r,radius:n}){const a=e.bandByColumn.get(t);return a===void 0?{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY}:e.mainAxis==="x"?{mainDistance:er(r,a.mainMin,a.mainMax)*n,crossDistance:ue(n,a.crossMin,a.crossMax)}:{mainDistance:ue(n,a.mainMin,a.mainMax),crossDistance:er(r,a.crossMin,a.crossMax)*n}}function jA(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(t,r.mainMid)):null}function XA(e,t){return ne(e,r=>ue(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function ZA(e,t){return ne(e,r=>er(t,r.xMin,r.xMax),{shortCircuitOnZero:!0})}var Ni=1e-9;function JA(e,t,r){if(e.buckets.length===0)return null;const n=ir(t,r),{angle:a,radius:i}=ar(n.x,n.y),o=QA(e.buckets,a),s=o?.entries??[];if(!o||!l.isNonEmptyArray(s))return null;const c=Bl(s.filter(h=>eI(e,h,a,i)),h=>h),u=c??$A(s,i,e.mainAxis),d=Bi(u),p=Math.hypot(n.x-d.x,n.y-d.y),m=Nl(n,d,Sr(e,u).map(Bi),p);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:u.x,y:u.y,observation:u.observation},index:e,bucket:o,distance:c===void 0?p:0,vertexDistance:p,insideFill:c!==void 0,strokeDistance:c===void 0?m:0,mainDistance:Qe(o.main,a)*i,crossDistance:Math.abs(i-u.y)}}function Bi(e){return fe(e.x,e.y)}function QA(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(r.main,t)):null}function eI(e,t,r,n){const a=tI(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function tI(e,t,r){if(t.fill===void 0)return null;const n=Ma(t.x,r);if(n===0)return t.fill;const a=c=>Math.sign(Ma(t.x,c.x))===Math.sign(n),i=Sr(e,t).find(a);if(i?.fill===void 0)return null;const o=Fi(r,{angle:t.x,radius:t.fill.min},{angle:i.x,radius:i.fill.min}),s=Fi(r,{angle:t.x,radius:t.fill.max},{angle:i.x,radius:i.fill.max});return o===null||s===null?null:{min:o,max:s}}function Fi(e,t,r){const n=fe(t.angle,t.radius),a=fe(r.angle,r.radius),i={x:a.x-n.x,y:a.y-n.y};if(Math.hypot(i.x,i.y)<Ni)return t.radius;const o=$i(fe(e,1),i);return Math.abs(o)<Ni?null:$i(n,i)/o}function $i(e,t){return e.x*t.y-e.y*t.x}function rI(e,t,r,n=!1){if(e.cells.length===0)return null;const{angle:a,radius:i}=dn(t,r);for(const u of e.cells)if(!(i<u.yMin||i>u.yMax)&&Xt(a,u.xMin,u.xMax))return Gi(e,u,0);if(!n)return null;const o=e.cells.filter(u=>Xt(a,u.xMin,u.xMax));if(!l.isNonEmptyArray(o))return null;const s=u=>ue(i,u.yMin,u.yMax),c=ne(o,s);return Gi(e,c,s(c))}function Gi(e,t,r){return{hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation},index:e,distance:r,mainDistance:0,crossDistance:r}}function nI(e,t,r,n){if(!l.isNonEmptyArray(e.points))return null;const a=ir(t,r),i=Ui(e,ne(e.points,s=>$l(s,a)),a);if(n===void 0||wt(i.distance,n)||ht(i,n))return i;const o=e.points.map(s=>Ui(e,s,a)).filter(s=>ht(s,n));return l.isNonEmptyArray(o)?ne(o,s=>s.crossDistance):i}function Ui(e,t,r){const{angle:n,radius:a}=ar(r.x,r.y);return{mainDistance:Qe(t.x,n)*a,crossDistance:Math.abs(a-t.y),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:Math.sqrt($l(t,r))}}function $l(e,t){const r=e.unitX??fe(e.x,e.y).x,n=e.unitY??fe(e.x,e.y).y,a=r-t.x,i=n-t.y;return a*a+i*i}var aI=.05;function iI({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a,tolerance:i}){const o={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},s={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},c={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1};for(const[u,d]of e.entries()){if(d.kind==="render-hit-test"){const m=pI(d,t,a);if(m)return{kind:"render-hit-test",match:m};continue}if(d.projection==="polar"){const m=dI(d,t,r,i?.polar);if(m&&!Hi(m,i?.polar))return m;continue}const p=uI({layer:d,cursor:t,aspectRatio:r,warmStarts:n,tolerance:i?.cartesian});if(!(!p||Hi(p,i?.cartesian))){if(p.kind==="banded"||p.kind==="enclosure"){const m=p.match.distance;m<o.distance&&(o.match=p,o.distance=m,o.paintOrder=u);continue}if(p.kind==="buckets"&&p.match.insideFill){s.match=p,s.distance=0,s.paintOrder=u;continue}p.match.distance<c.distance&&(c.match=p,c.distance=p.match.distance,c.paintOrder=u)}}return Gl(c,sI(s,o)).match}function oI(e,t){if(e.kind==="render-hit-test")return{intersects:!0,onPoint:!1};const r=lI(e,t),n=e.kind==="buckets"&&wt(e.match.vertexDistance,r);return{intersects:Ul(e,r),onPoint:n}}function sI(e,t){return e.match!==null&&t.match!==null&&e.distance===0&&t.distance===0?e.paintOrder>t.paintOrder?e:t:Gl(e,t)}function Gl(e,t){return e.match===null?t:t.match===null||e.distance<=t.distance+aI?e:t}function Ul(e,t){switch(e.kind){case"banded":case"enclosure":return e.match.distance<=t.on.edge;case"buckets":return cI(e.match,t);case"points":return wt(e.match.distance,t)}}function lI(e,t){return e.match.index.projection==="polar"?t.polar:t.cartesian}function cI(e,t){return e.strokeDistance<=t.on.stroke?!0:wt(e.vertexDistance,t)}function Hi(e,t){return t===void 0?!1:!Ul(e,t)&&!ht(e.match,t)}function uI({layer:e,cursor:t,aspectRatio:r,warmStarts:n,tolerance:a}){switch(e.kind){case"buckets":{const i=FA(e,t,r);return i?{kind:"buckets",match:i}:null}case"banded":{const i=PA(e,t,r);return i?{kind:"banded",match:i}:null}case"points":{const i=aA(e,t,r,n.get(e.layerId)??null,a);return i?{kind:"points",match:i}:null}case"enclosure":{const i=KA(e,t);return i?{kind:"enclosure",match:i}:null}case"noop":return null}}function dI(e,t,r,n){switch(e.kind){case"enclosure":{const a=rI(e,t,r,n!==void 0);return a?{kind:"enclosure",match:a}:null}case"points":{const a=nI(e,t,r,n);return a?{kind:"points",match:a}:null}case"buckets":{const a=JA(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=zA(e,t,r);return a?{kind:"banded",match:a}:null}case"noop":case"render-hit-test":return null}}function pI(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:Ml(e.layerId,i)}:null}var oe={primary:null,group:[],related:new Map},mI=1,hI=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.viewport=null,this.aspectRatio=mI,this.isAspectStale=!1,this.warmStarts=new Map,this.cachedState=oe,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=oe,this.layerIndexes=e.map(r=>ki(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>Wi(r,t)),this.nonInteractiveLayerIds=Ki(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const o=this.layerIndexes[i],s=this.layerRefs[i];!o||!s||r.set(o.layerId,{index:o,ref:s})}const n=[],a=[];for(const i of e){const o=r.get(i.id),s=Wi(i,t);if(o!==void 0&&gI(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push(ki(i,t,this.aspectRatio)),a.push(s)}for(const i of this.warmStarts.keys())e.some(o=>o.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=Ki(e),this.invalidateCache()}setViewport(e){if(e.width<=0||e.height<=0)return;this.viewport=e;const t=e.width/e.height;t!==this.aspectRatio&&(this.aspectRatio=t,this.isAspectStale=!0)}query(e,t,r){if(this.layerIndexes.length===0)return oe;this.reindexForAspect();const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(m=>!this.nonInteractiveLayerIds.has(m.layerId)),a=r??this.viewport,i=t!==void 0&&a!==null?nA(t,a):void 0,o=iI({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e,tolerance:i});if(!o)return this.invalidateCache(),oe;const s=o.match.hit;this.warmStarts.set(s.layerId,s.pointIndex);const c=i===void 0?void 0:oI(o,i),u=fI(s,c);if(this.cachedKey===u)return this.cachedState;const{group:d,related:p}=cA(o,n);return this.cachedKey=u,this.cachedState=c===void 0?{primary:s,group:d,related:p}:{primary:s,group:d,related:p,intersection:c},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return oe;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return oe;const n=r.byKey.get(t);if(!n)return oe;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Ml(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=oe,this.cachedByKeyId=null,this.cachedByKeyState=oe}reindexForAspect(){if(this.isAspectStale){this.isAspectStale=!1;for(const e of this.layerIndexes)e.kind==="points"&&e.projection==="cartesian"&&_l(e,this.aspectRatio)}}};function fI(e,t){const r=`${e.layerId}:${e.pointIndex}`;return t===void 0?r:`${r}:${t.intersects}:${t.onPoint}`}function Wi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Ki(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function gI(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var yI=Math.PI*2;function vI(e,t){const r=Z(e.mainAxis,t);if(e.mainAxis==="y"){const a=Ve(ce(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=Ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function bI(e,t,r){const n=e.mainAxis==="y"?_(r.observation):k(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Wl(r):Hl(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const o=i/2;return e.mainAxis==="y"?{x:0,y:Ve(ce(n+o)),width:"100%",height:Ve(i)}:{x:Ve(n-o),y:0,width:Ve(i),height:"100%"}}function SI(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=j(t.observation),i=X(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=U(t.observation),n=$(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+yI,innerRadius:r,outerRadius:n}}function Hl(e){const t=j(e.observation),r=X(e.observation);return t===null||r===null?null:r-t}function Wl(e){const t=U(e.observation),r=$(e.observation);return t===null||r===null?null:r-t}function xI(e){return e.observationIndex??e.pointIndex}function Kl(e){return e==="buckets"||e==="filled-buckets"}var xr=.5,AI=.3,II=.4,TI=10,LI=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?EI(e,t,r,n):RI(e,t,n):Kl(e.spatialKind)&&t.type==="cartesian"?DI(e,t,n):e.spatialKind==="cells"?VI(e,n):e.spatialKind==="points"?CI(e,n):null,wI=e=>{if(Kl(e.spatialKind)){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},EI=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:xr*n.durationScale,baseline:_I(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?PI(e,t.mainAxis,n):{}}),RI=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:xr*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?kI(e,t,r):{}}},CI=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:xr*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?OI(e,t):{}}),VI=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:AI*t.durationScale}),DI=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:xr*r.durationScale,axis:t.mainAxis}),_I=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[Te(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const o=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-o:o},PI=(e,t,r)=>{const n=br(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=bl(t,i);if(!o)continue;const s=Sl(t,o),c=n(i),u=a.get(s);u?u.keys.push(c):a.set(s,{position:t==="x"?o.x:o.y,keys:[c]})}return ca([...a.values()],r)},OI=(e,t)=>{const r=br(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=MI(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return ca(n,t)},MI=(e,t)=>{if(t==="main-axis")return k(e);const r=Yn(e)??k(e);return r===null?null:t==="value-descending"?-r:r},kI=(e,t,r)=>{const n=br(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=Xn(i),{innerRadius:c,outerRadius:u}=Zn(i);if(o===null||s===null||c===null||u===null)continue;const d=Il(t.bandAxis,{startAngle:o,endAngle:s,innerRadius:c,outerRadius:u}),p=n(i),m=a.get(d);m?m.keys.push(p):a.set(d,{position:o,keys:[p]})}return ca([...a.values()],r)},ca=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((s,c)=>s.position-c.position),a=Math.ceil(n.length/TI),i=Math.ceil(n.length/a),o=II*t.durationScale/i;return n.forEach((s,c)=>{const u=Math.floor(c/a)*o;for(const d of s.keys)r[d]=u}),r},Ye=["top","right","bottom","left"],zi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},NI={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},BI={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},FI=(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]=BI[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=GI(t,a),s=UI(t,a,i);return HI(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:WI(c,o,s,i)}))},$I=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),GI=(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}}},UI=(e,t,r)=>{const{x:n,y:a,width:i,height:o}=e,s=c=>r(c)?t:0;return{top:{start:{x:n+s("topLeft"),y:a},end:{x:n+i-s("topRight"),y:a}},right:{start:{x:n+i,y:a+s("topRight")},end:{x:n+i,y:a+o-s("bottomRight")}},bottom:{start:{x:n+i-s("bottomRight"),y:a+o},end:{x:n+s("bottomLeft"),y:a+o}},left:{start:{x:n,y:a+o-s("bottomLeft")},end:{x:n,y:a+s("topLeft")}}}},HI=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(Ye.indexOf(o)+s+Ye.length)%Ye.length;return Ye[c]},n=o=>{const s=r(o,-1);return!t(s)||e[s].lineType!==e[o].lineType||e[s].strokeWidth!==e[o].strokeWidth||e[s].color!==e[o].color},a=Ye.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Ye],isClosed:!0}]:i.map(o=>{const s=[o];for(let c=r(o,1);t(c)&&!n(c);c=r(c,1))s.push(c);return{firstEdge:o,edges:s,isClosed:!1}})},WI=(e,t,r,n)=>{const a=(p,m,h)=>({type:"arc",cx:p.cx,cy:p.cy,radius:p.radius,startAngle:m,endAngle:h}),i=p=>(p.startAngle+p.endAngle)/2,o=[],s=e.firstEdge,c=e.edges[e.edges.length-1],u=zi[s];if(!e.isClosed&&n(u)){const p=t[u],m=i(p),h=KI(p,m);o.push({type:"move",x:h.x,y:h.y}),o.push(a(p,m,p.endAngle))}else o.push({type:"move",x:r[s].start.x,y:r[s].start.y});o.push({type:"line",x:r[s].end.x,y:r[s].end.y});for(const p of e.edges.slice(1)){const m=zi[p];if(n(m)){const h=t[m];o.push(a(h,h.startAngle,h.endAngle))}o.push({type:"line",x:r[p].end.x,y:r[p].end.y})}const d=NI[c];if(e.isClosed){if(n(d)){const p=t[d];o.push(a(p,p.startAngle,p.endAngle))}o.push({type:"close"})}else if(n(d)){const p=t[d];o.push(a(p,p.startAngle,i(p)))}return o},KI=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),zI=/^(?:https?:|mailto:)/i,YI=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:zI.test(t)},qI=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...Y,...t}).format(r)),jI=({locale:e,intlOptions:t})=>K(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...Y,...t}).format(r)}),tr=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ms(e);case"date":return qI(e);case"datetime":return jI(e);case"day_month":return Fs(e);case"decimal":return ks(e);case"duration":return Nn(e);case"integer":return Ns(e);case"month":return $s(e);case"month_year":return $n(e);case"percentage":return Bs(e);case"quarter":return Gn(e);case"text":return kn(e);case"time":return Hs(e);case"weekly_date_range":return Gs(e);case"weekly_date_range_with_year":return Us(e);case"year":return Un(e);case"lookup":return tr({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},zl={width:12,height:12},XI=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:o,colorScheme:s,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:p}=o;if(p===null)return null;const m=c??i,h=ZI(u,d);return{header:h===null?JI({layers:e,coordSystem:t,guides:n,primary:p,locale:m,numberFormat:a}):null,rows:QI({layers:e,scales:r,guides:n,hover:o,locale:m,numberFormat:a,colorScheme:s}),comment:h}};function ZI(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function JI(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=ta(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)?tr({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function QI(e){const t=[],r=e.scales.color??null,n=lt({colorScheme:e.colorScheme}),a=nT({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=tT(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...eT(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=go(i.data,i.mapping),u=rT(o,i,r,c),d=Jn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=aT(e.guides,i),m=gt(i),h=i.mapping.color!==void 0,f=n.geomReaders(i);for(const y of u){const v=h?c(y.observation):null,g=f.get("color",y.observation),b=f.get("lineType",y.observation)??"solid",I=aa(f,i,y.observation,zl),L=h&&v!==null?a(v):p,w=m(y.observation),E=w===null?"":d(w,y.observation);t.push({swatchColor:g,geom:i.geom,swatchLineType:b,swatchAlpha:I.alpha,swatchCornerRadius:I.cornerRadiusPx,label:L,value:E,isPrimary:y===e.hover.primary,key:`${y.layerId}:${y.pointIndex}`})}}return t}function eT(e,t,r,n,a){const i=aa(n,e,t.observation,zl);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=Q(e.data,s)(t.observation),d=N({valueFormat:yn(e,c),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:o.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",swatchAlpha:i.alpha,swatchCornerRadius:i.cornerRadiusPx,label:o.key??ur(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function tT(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 rT(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,o)=>{a.set(l.getStableKey(i),o)}),e.map((i,o)=>{const s=n(i.observation),c=s===null?null:l.getStableKey(s);return{hit:i,originalIndex:o,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,o)=>i.rank===o.rank?i.originalIndex-o.originalIndex:i.rank-o.rank).map(i=>i.hit)}function nT({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:tr({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=tr({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const o=n.get(l.getStableKey(i));return o===void 0?a(i):o.label??o.format(i)}}function aT(e,t){return ur(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function iT(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function oT(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var sT=(e,t)=>{const r=e.annotation.shape(t),n=r.get("borderColor");return{color:r.get("color"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth")}},lT=(e,t)=>{const r=e.annotation.arrow(t),n=r.get("borderColor");return{color:r.get("color"),strokeWidth:r.get("strokeWidth"),lineType:r.get("lineType"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),shadow:r.get("shadow")}},cT=(e,t)=>{const r=e.annotation.differenceArrow(t),n=e.annotation.differenceArrow.label(t),a=n.get("borderColor");return{color:r.get("color"),isColorAuthored:r.getSource("color")==="authored",strokeWidth:r.get("strokeWidth"),label:{...B(n,e.graph),background:n.get("background"),...a===void 0?{}:{borderColor:a},borderWidth:n.get("borderWidth"),borderRadius:n.get("borderRadius"),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock")}}},uT=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...B(r,e.graph),background:r.get("background"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock")}},dT=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},pT=(e,t,r)=>{const n=e.annotation[t](r),a=e.annotation[t].label(r);return{marker:{color:n.get("color"),isColorAuthored:n.getSource("color")==="authored",size:n.get("size"),borderColor:n.get("borderColor"),borderWidth:n.get("borderWidth"),shadow:n.get("shadow")},label:{...B(a,e.graph),isTextColorAuthored:a.getSource("textColor")==="authored",background:a.get("background"),borderColor:a.get("borderColor"),borderWidth:a.get("borderWidth"),borderRadius:a.get("borderRadius"),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),shadow:a.get("shadow")}}},mT=e=>e.borderWidth>0?e.borderColor??e.color:void 0,hT=e=>({edges:{top:Ze(e.panelBorder("top")),right:Ze(e.panelBorder("right")),bottom:Ze(e.panelBorder("bottom")),left:Ze(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),fT=(e,t)=>Ze(e.gridLine(t)),gT=(e,t)=>{const r=e.tickLine(t);return{...Ze(r),length:r.get("length")}},yT=e=>e.heading.h1.get("fontFamily")??e.graph.get("fontFamily"),vT=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")}},bT=e=>{const t=e.graph.get("padding");return typeof t=="number"?{top:t,right:t,bottom:t,left:t}:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},ST=e=>{const t=e.legend.popover;return{gap:e.legend().get("gap"),popover:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")}}},xT=e=>({gap:e.headline.get("gap")}),q=e=>{let t={top:0,right:0,bottom:0,left:0};for(const r of e.collectAll("margin"))t=typeof r=="number"?{top:r,right:r,bottom:r,left:r}:{...t,...r};return t},AT=e=>({header:q(e.header),footer:q(e.footer),headline:q(e.headline),legend:{top:q(e.legend("top")),right:q(e.legend("right")),bottom:q(e.legend("bottom")),left:q(e.legend("left"))},axisLabel:{top:q(e.axisLabel("x","top")),bottom:q(e.axisLabel("x","bottom"))},tickLabel:{top:q(e.tickLabel("x","top")),right:q(e.tickLabel("y","right")),bottom:q(e.tickLabel("x","bottom")),left:q(e.tickLabel("y","left"))}}),IT=e=>({color:e.hoverGuide.get("color"),background:e.hoverGuide.get("background")}),TT=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Ze=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),ua=["sticker","pinnedNumber","comment","image"],LT=e=>ua.includes(e),da=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?ET(e.annotation.at):null;default:return null}},Yl=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),ql=(e,t,r=wT)=>{const n=r(t);for(const a of ua){const i=At(e,a),o=i.findIndex(c=>{const u=da({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return Yl(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},wT=e=>({...e,anchorValue:kr(e.anchorValue),...e.groupValue!==void 0&&{groupValue:kr(e.groupValue)},...e.crossValue!==void 0&&{crossValue:kr(e.crossValue)}}),kr=e=>l.readISOInstant(e)??e,ET=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function RT(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var CT=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&pa(r.predicate,t.predicate))??null,pa=(e,t)=>"and"in e?"and"in t&&Yi(e.and,t.and):"or"in e?"or"in t&&Yi(e.or,t.or):"not"in e?"not"in t&&pa(e.not,t.not):VT(t)&&e.variable===t.variable&&DT(e,t),VT=e=>"variable"in e,Yi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&pa(r,a)}),DT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&qi(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&qi(e.range,t.range),qi=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),_T={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},PT=e=>Object.hasOwn(_T,e);function OT(e){return{type:"mapping",mapping:e}}var Et=(e,t)=>"and"in e?"and"in t&&ji(e.and,t.and):"or"in e?"or"in t&&ji(e.or,t.or):"not"in e?"not"in t&&Et(e.not,t.not):MT(t)&&e.variable===t.variable&&kT(e,t),MT=e=>"variable"in e,ji=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Et(r,a)}),kT=(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)),jl=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)))),Xl=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),Zl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function Jl(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(NT),transforms:e.transforms,highlights:e.highlights,styles:l.styles(e.styles),annotations:e.annotations,coords:e.coords,config:e.config}}function NT(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?BT(r):r}function BT(e){return{...e,palette:FT(e.palette),overrides:$T(e.overrides)}}function FT(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function $T(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Rt=(e,t)=>{const r=ma(e,t);return r===-1?void 0:e[r]},ma=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&Ar(n,t))return r}return-1},Ar=(e,t)=>GT(e.select,t.select)&&e.when?.state===t.when?.state&&UT(e.when?.where,t.when?.where),Ql=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>HT(e[r],t[r])),De=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),ha=e=>e.select.target==="geom",Ct=(e,t)=>{const r=Rt(e,t);if(!(r===void 0||!ha(r)))return r.declarations},GT=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},UT=(e,t)=>e===void 0||t===void 0?e===t:Et(e,t),HT=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function x(e){return{id:e.id??W(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function at(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>at(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>at(e[a],t[a]))}return!1}var fa=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=x({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=xt(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:C(e,{annotations:Ss(e.annotations,t)}),revert:new ga({kind:r,annotation:a,index:n},this.metadata)}}},WT={type:"remove-annotation",deserialize:(e,t)=>new fa(e,t)},ga=class ec{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??W()},...t.index!==void 0&&{index:t.index}},this.metadata=x({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Fg(r)||xt(t.annotations,n.id))return null;const i=zT(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:Ss(t.annotations,i),s=At(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:C(t,{annotations:Pn(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new fa({id:n.id},this.metadata):new ec({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},KT={type:"add-annotation",deserialize:(e,t)=>new ga({kind:e.kind,annotation:e.annotation,index:e.index},t)},zT=(e,t)=>{const r=da(t);return r===null?null:ql(e,r)},YT=(e,t)=>{const r=ya(e);return r===null?null:tc(r.points,t)},qT=e=>ya(e)!==null,jT=(e,t)=>{const r=ya(e);if(r===null)return null;const n=tc(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},ya=e=>{const t=ZT[e.kind];return t===null?null:t(e.annotation)},Zi=(e,t)=>e.anchorType!=="panel"?null:{points:[sn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Ji=(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})},XT=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[sn(e,e.offset),sn(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}})},ZT={text:e=>Zi(e.at,t=>({at:t})),sticker:e=>Zi(e.at,t=>({at:t})),shape:e=>Ji(e.region,t=>({region:t})),image:e=>Ji(e.region,t=>({region:t})),arrow:e=>XT(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},sn=(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)},tc=(e,t)=>({x:Qi(e.map(r=>r.x),t.x),y:Qi(e.map(r=>r.y),t.y)}),Qi=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:(0,Je.default)(t,r,n)},rc=(e,t,r)=>{const n=t.annotation;if(!eL(n,r))return null;const a=At(e.annotations,t.kind),i=JT(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:C(e,{annotations:Pn(e.annotations,t.kind,o)}),inverse:QT(n,r)}},JT=(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)))},QT=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},eL=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),va=class nc{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=x({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=xt(t.annotations,n);if(i===null||i.kind!==r)return null;const o=rc(t,i,a);return o===null?null:{spec:o.spec,revert:new nc({kind:r,id:n,patch:o.inverse},this.metadata)}}},tL={type:"update-annotation",deserialize:(e,t)=>new va(e,t)},ac=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=x({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=xt(e.annotations,this.params.id);if(t===null)return null;const r=jT(t,this.params.translation);if(r===null)return null;const n=rc(e,t,r);return n===null?null:{spec:n.spec,revert:new va({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},rL={type:"move-annotation",deserialize:(e,t)=>new ac(e,t)},Se=class Yt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=x({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],o=ma(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new Yt({list:r,rule:s,index:o},this.metadata),y=i.filter(v=>!Ar(v,n));return{spec:Nr(t,r,y),revert:f}}if(s!==void 0){if(Ql(s.declarations,c))return null;const f={...s,declarations:c},y=new Yt({list:r,rule:s,index:o},this.metadata),v=i.map(g=>g===s?f:g);return{spec:Nr(t,r,v),revert:y}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),p={...n,declarations:c},m=[...i.slice(0,d),p,...i.slice(d)],h=new Yt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:Nr(t,r,m),revert:h}}},nL=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."})},aL={type:"set-style-rule",deserialize:(e,t)=>(nL(e),new Se(e,t))},Nr=(e,t,r)=>C(e,{styles:{...e.styles,[t]:r}}),iL={type:"set-difference-arrow-style",deserialize:(e,t)=>new ic(e,t)},ic=class oc{constructor(t,r={}){this.type="set-difference-arrow-style",this.params=t,this.metadata=x({...r,description:"Set difference arrow style"})}get target(){return{kind:"annotation",id:this.params.annotationId}}apply(t){const{annotationId:r,arrow:n,label:a}=this.params,i={target:"annotation",kind:"differenceArrow",annotation:r},o={...i,part:"label"};let s=t;const c={annotationId:r},u=d=>{const p=Rt(s.styles.overrides,d),m=new Se({list:"overrides",rule:d}).apply(s);if(m)return s=m.spec,p?.declarations??null};if(n!==void 0){const d=u({select:i,declarations:n});d!==void 0&&(c.arrow=d)}if(a!==void 0){const d=u({select:o,declarations:a});d!==void 0&&(c.label=d)}return s===t?null:{spec:s,revert:new oc(c,this.metadata)}}},oL=["cartesian","polar","flip"],J=new pr,sc=e=>J.has(e)?J.get(e):null,lc=new l.TransformRegistry,sL=new Es(lc),Ir=e=>{const t=e.transforms.every(r=>lc.has(r.transformType));return e.transforms.length===0||!t?e.data:sL.compile({data:e.data,transforms:e.transforms})};function ba(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 Vt(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function Dt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:C(e,{scales:xo(e.scales,n,r)})}function _t(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function ln(e,t,r){const n=hr(Vn(Rs(J),{data:Ir(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Dn(n):n}var cc=class uc{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:bL(t)})}apply(t){const r="previous"in this.params?this.params.previous:SL(t,this.params);if(r===null)return null;const n=C(t,r);return n===t?null:{spec:n,revert:new uc({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},lL={type:"set-chart-type",deserialize:(e,t)=>new cc(e,t)},dc={type:"sum"},cL={type:"identity"},uL=["bar","line","area","point","tile"],Sa="tile",dL=["y","color"],pL=Object.values(l.LAYER_LABEL_VARIABLES),mL={coordType:"cartesian",geom:Sa,position:"identity"},Pt=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),hL=e=>{const t=e.layers.filter(de),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=mc(t);if(o!==null)return{coordType:"cartesian",comboType:o}}if(!t.every(o=>o.geom===r.geom&&o.position===r.position))return null;const{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},fL=e=>{if(!e)return!1;const t=e.layers.filter(de);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:hc(e,r)?fc(e,r).length>=1:Tr(e,e.data.groupVariableNamesByType().numeric).length>=2},gL=e=>e?xc(e,mL)!==null:!1,yL=e=>pc(e)?.at(-1)?.id??null,pc=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(de);return mc(t)===null?null:t},mc=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 vL(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)},vL=e=>e.some(t=>t.yScaleType==="secondary"||rr(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,bL=e=>"previous"in e?"Restore the previous chart type":Pt(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,SL=(e,t)=>{const r=xc(e,t);if(r===null)return null;const n=Pt(t)?AL(r,t):xL(r,t,e);return n===null||r===e?n:{...n,scales:ML({...e,...n},n.scales)}},xL=(e,t,r)=>{if(Pt(t)||!kL(t))return null;const n={...e,layers:Rc(e.layers)},a=FL(n.layers.filter(de),t),i=Vc(n.coords,t),o=bc(n,t),s=Ec({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:ba(Dc(r,s,i.coordType),s),mapping:o}},AL=(e,t)=>{const r=LL(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=$L(r.filter(de),t.comboType),i=Vc(n.coords,t),o=bc(n,t),s=Ec({...n,mapping:o},t,a,o!==n.mapping),c=IL(e)?s:TL(s);return{coords:i,layers:c,scales:ba(Dc(e,c,i.coordType),c),mapping:o}},IL=e=>pc(e)!==null,TL=e=>{const t=e.filter(de).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},LL=(e,t)=>{const r=e.layers.filter(de);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:hc(e,n)?wL(e,n):EL(e,n,t)},hc=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},wL=(e,t)=>{const[r]=fc(e,t);if(r===void 0)return null;const n=Ge(J,e.mapping,e.coords.coordType,{type:"layer",id:gc(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:dc,...vc(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},Tr=(e,t)=>{const r=Ot(e);return t.filter(n=>n!==r)},fc=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return Tr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},Ot=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),EL=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=Tr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,Ot(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=RL(t,eo(a.slice(0,-1),o,s)),u=Ge(J,e.mapping,e.coords.coordType,{type:"layer",id:gc(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...eo([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},gc=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},eo=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?vc(n,r):yc(e,t)},yc=(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})]}),vc=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),RL=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),bc=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Sc(t)?"":Ot(e);return n===r?e.mapping:{...e.mapping,x:n}},Sc=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",CL=e=>!Pt(e)&&e.geom===Sa,VL=e=>e.layers.filter(de).some(t=>t.geom===Sa),xc=(e,t)=>{const r=CL(t);return r===VL(e)?e:r?DL({...e,layers:Rc(e.layers)}):_L(e)??e},DL=e=>{const t=Ic(e);if(t===null)return null;const r=PL(e,t)===null?OL(e,t):Tc(e,t);return r===null?null:Ac(e,t,r)},_L=e=>{const t=Ic(e);if(t===null)return null;const r=Tc(e,t);return r===null?null:Ac(e,t,r)},Ac=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Ic=e=>{const t=e.layers.filter(de);return t.length===1?t[0]??null:null},Tc=(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:Lc(t)}},Lc=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}},PL=(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===Ot(e))return null;const i=Ir(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},OL=(e,t)=>{const r=Tr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,Ot(e)),a=yc(r,n),i=Lc(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},ML=(e,t)=>dL.reduce((r,n)=>{const a=ln(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Ne(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),kL=e=>oL.includes(e.coordType)&&wc(e.geom)&&NL(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),NL=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=J.get(e);return n.includes(t)&&a.includes(r)},wc=e=>uL.includes(e),de=e=>wc(e.geom)&&!BL(e.stat),BL=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},FL=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},$L=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,o)=>n===null||o===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:GL(i,t,n)}]);return new Map(a)},GL=(e,t,r)=>e.geom!=="bar"||rr(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Ec=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return gs(J,Ne(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=UL(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?WL(e,{...i,stat:s},t.coordType,o):i}))},UL=(e,t,r)=>Sc(r)?e.type==="identity"?dc:e:HL(t)&&e.type==="sum"?cL:e,HL=e=>e.coordType==="polar"&&e.params.theta==="y",WL=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:o,format:s,offset:c,justify:u,...d}=t.dataLabels;return{...Ge(J,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:s},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Rc=e=>{const t=e.filter(de);if(t.length<2||!e.some(rr))return e;const[r]=t;return e.flatMap(n=>n===r?[KL(n)]:rr(n)?[]:[n])},rr=e=>Cc(e)!==null,Cc=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:pL.includes(t.options.variableName)?t:null},KL=e=>{const t=Cc(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)}},Vc=(e,t)=>{const r=zL(e,t);return(0,jt.default)(r,e)?e:r},zL=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return qr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Wt;return qr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},Dc=(e,t,r)=>{const n=Kr(J,t),a=Kr(J,e.layers),i=e.coords.coordType==="polar";return Ne(e.scales,o=>{const s=YL(o,n,a),c=qL(s,n,a);return XL(c,r,i)})},YL=(e,t,r)=>{if(e.scaleType==="discrete"){const a=t.bandPadding[e.scaledAesthetic];return a===void 0||e.padding===a?e:{...e,padding:a}}if(e.scaledAesthetic===t.discreteAxis)return Yr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return Yr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=jL(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},qL=(e,t,r)=>{if(e.scaleType!=="discrete"||!Fe(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}},jL=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,XL=(e,t,r)=>{if(e.scaleType!=="discrete"||!Fe(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}},_c=class Pc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:JL(t)})}apply(t){const r="previous"in this.params?this.params.previous:QL(t,this.params);if(r===null)return null;const n=C(t,r);return n===t?null:{spec:n,revert:new Pc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},ZL={type:"set-mapping",deserialize:(e,t)=>new _c(e,t)},Oc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Mc=e=>e===""?null:e,JL=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Mc(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},QL=(e,{aesthetic:t,variable:r})=>{if(!PT(t))return null;const n=Mc(r),a=tw(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:nw(e,t,a,n),layers:ew(e.layers,a)}},ew=(e,t)=>Ne(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&sc(r.geom)===null)return r;const a=fs(J,r.geom,r.position,n);return(0,jt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),tw=(e,t,r)=>r===null?rw(e,t):Oc(e,t)===r?e:{...e,[t]:r},rw=(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},nw=(e,t,r,n)=>{if(!No(t))return e.scales;let a=e.scales;for(const i of aw(e,t))a=ow(e,a,i,r,n);return a},aw=(e,t)=>t==="y"&&iw(e.layers)?["y","ySecondary"]:[t],iw=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},ow=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,ln(e,r,n)];if(a===null&&!Fe(r)||a!==null&&!Ir(e).hasVariable(a))return t;const o=ln(e,r,n);return sw(i,o)?t:Ne(t,s=>s.scaledAesthetic===r?o:s)},sw=(e,t)=>e.scaleType===t.scaleType||to(e)&&to(t),to=e=>e.scaleType==="discrete"||e.scaleType==="palette",xa=e=>e==="both"?["x","y"]:[e],kc=e=>e==="both"?"the":`${e} axis`;function Aa(e,t){return Lr(e)?e[t]:e}function lw(e,t){return e.config.axes[t]??{}}function cw(e,t,r){if(t!=="ySecondary")return P(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=Nc(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,C(e,{config:C(e.config,{axes:i})})}function Lr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function Nc(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],o=a in t?uw(i,t[a]):i;o!==i&&(n=!0),o!==void 0&&(r[a]=o)}return n?Object.keys(r).length>0?r:void 0:e}function uw(e,t){return l.isPlainObject(t)?Nc(l.isPlainObject(e)?e:void 0,t):t}var Bc=class Fc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${pw(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=lw(t,r).label;if(a===n)return null;const i=cw(t,r,{label:n});return i===t?null:{spec:i,revert:new Fc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},dw={type:"set-axis-label",deserialize:(e,t)=>new Bc(e,t)};function pw(e){return e===void 0?"(inherited)":e??"(none)"}var $c=class Gc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:P(t,{config:{axes:{[r]:{position:n}}}}),revert:new Gc({axis:r,position:a},this.metadata)}}},mw={type:"set-axis-position",deserialize:(e,t)=>new $c(e,t)},Uc=class Hc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new Hc({axis:r,tickMode:a},this.metadata)}}},hw={type:"set-axis-tick-mode",deserialize:(e,t)=>new Uc(e,t)},Wc=class Kc{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new Kc({axis:r,isVisible:a},this.metadata)}}},fw={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new Wc(e,t)},zc=class Yc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new Yc({axis:r,isVisible:a},this.metadata)}}},gw={type:"set-axis-visibility",deserialize:(e,t)=>new zc(e,t)},qc=class jc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=x({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:P(t,{config:{content:{caption:this.params.caption}}}),revert:new jc({caption:r},this.metadata)}}},yw={type:"set-content-caption",deserialize:(e,t)=>new qc(e,t)},Xc=class Zc{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=x({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(at(r,this.params.source))return null;const n=C(t.config.content,{source:this.params.source});return{spec:C(t,{config:C(t.config,{content:n})}),revert:new Zc({source:r},this.metadata)}}},vw={type:"set-content-source",deserialize:(e,t)=>new Xc(e,t)},Jc=class Qc{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=x({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:P(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new Qc({subtitle:r},this.metadata)}}},bw={type:"set-content-subtitle",deserialize:(e,t)=>new Jc(e,t)},eu=class tu{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=x({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:P(t,{config:{content:{title:this.params.title}}}),revert:new tu({title:r},this.metadata)}}},Sw={type:"set-content-title",deserialize:(e,t)=>new eu(e,t)},xw="dashed",Aw=1,ru=(e,t,r,n)=>{const a=Iw(t,r),i=Lw(e,a,n);let o=e,s=!1;for(const c of a){const u=Ew(o,c,n,ww(n,Tw(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},Iw=(e,t)=>e==="both"&&!Lr(t)?[void 0]:xa(e),Tw=(e,t)=>t===void 0?Lr(e)?e.x:e:Aa(e,t),Lw=(e,t,r)=>t.length===1?Br(e,t[0],r):{x:Br(e,"x",r),y:Br(e,"y",r)},Br=(e,t,r)=>nu(e.styles.overrides,t)?.[r]??null,ww=(e,t)=>t===null||e==="lineType"&&t===xw||e==="strokeWidth"&&t===Aw?null:t,Ew=(e,t,r,n)=>{const a=nu(e.styles.overrides,t);return(a?.[r]??null)===n?null:new Se({list:"overrides",rule:Vw(t,Cw(a,r,n))}).apply(e)?.spec??null},Rw=e=>e.select.target==="gridLine",nu=(e,t)=>{const r=Rt(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!Rw(r)))return r.declarations},Cw=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},Vw=(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),au=class iu{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${kc(t.axis)} grid line style to ${_w(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=ru(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new iu({axis:r,lineStyle:a.previous},this.metadata)}}},Dw={type:"set-grid-line-style",deserialize:(e,t)=>new au(e,t)},_w=({axis:e,lineStyle:t})=>{const r=xa(e).map(n=>Aa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Pw={type:"set-grid-line-width",deserialize:(e,t)=>new ou(e,t)},ou=class su{constructor(t,r={}){this.type="set-grid-line-width";const n=Ow(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${kc(t.axis)} grid line width to ${Mw(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=ru(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new su({axis:r,lineWidth:a.previous},this.metadata)}}},Ow=e=>Lr(e)?{x:Fr(e.x),y:Fr(e.y)}:Fr(e),Fr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),Mw=(e,t)=>{const r=xa(e).map(n=>Aa(t,n)??"(theme)");return[...new Set(r)].join(" and ")},lu=class cu{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new cu({axis:r,isVisible:a},this.metadata)}}},kw={type:"set-grid-visibility",deserialize:(e,t)=>new lu(e,t)},uu=class du{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:P(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new du({compareWith:r},this.metadata)}}},Nw={type:"set-headline-compare-with",deserialize:(e,t)=>new uu(e,t)},pu=class mu{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:P(t,{config:{headline:{position:this.params.position}}}),revert:new mu({position:r},this.metadata)}}},Bw={type:"set-headline-position",deserialize:(e,t)=>new pu(e,t)},hu=class fu{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:P(t,{config:{headline:{show:this.params.show}}}),revert:new fu({show:r},this.metadata)}}},Fw={type:"set-headline-show",deserialize:(e,t)=>new hu(e,t)},gu=class yu{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:P(t,{config:{headline:{size:this.params.size}}}),revert:new yu({size:r},this.metadata)}}},$w={type:"set-headline-size",deserialize:(e,t)=>new gu(e,t)},Gw={type:"set-highlight-dim-style",deserialize:(e,t)=>new vu(e,t)},vu=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=x({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(bu(e)===this.params.dimStyle)return null;const t=new Se({list:"overrides",rule:Hw(this.params.dimStyle)},this.metadata).apply(e);return t||null}},Uw={select:{target:"geom"},when:{state:"dimmed"}},bu=e=>{const t=Rt(e.styles.overrides,Uw);return(t!==void 0&&ha(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},Hw=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Su=class xu{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:P(t,{config:{legend:{align:this.params.align}}}),revert:new xu({align:r},this.metadata)}}},Ww={type:"set-legend-align",deserialize:(e,t)=>new Su(e,t)},Au=class Iu{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:P(t,{config:{legend:{display:this.params.display}}}),revert:new Iu({display:r},this.metadata)}}},Kw={type:"set-legend-display",deserialize:(e,t)=>new Au(e,t)},Tu=class Lu{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:P(t,{config:{legend:{position:this.params.position}}}),revert:new Lu({position:r},this.metadata)}}},zw={type:"set-legend-position",deserialize:(e,t)=>new Tu(e,t)},wu=class Eu{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:P(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Eu({abbreviation:r},this.metadata)}}},Yw={type:"set-number-format-abbreviation",deserialize:(e,t)=>new wu(e,t)},Ru=class Cu{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:P(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Cu({decimals:r},this.metadata)}}},qw={type:"set-number-format-decimals",deserialize:(e,t)=>new Ru(e,t)},Vu=class Du{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=Xw(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:P(t,{config:{content:{[a]:n}}}),revert:new Du({slot:r,isVisible:i},this.metadata)}}},jw={type:"toggle-content-visibility",deserialize:(e,t)=>new Vu(e,t)},ro={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function Xw(e){return Object.hasOwn(ro,e)?ro[e]:void 0}var _u=class Pu{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if(at(i.xLimits,a.xLimits)&&at(i.yLimits,a.yLimits))return null;const o={};r!==void 0&&(o.xLimits=a.xLimits),n!==void 0&&(o.yLimits=a.yLimits);const s=new Pu(o,this.metadata);return{spec:C(t,{coords:Jw(t.coords,i)}),revert:s}}},Zw={type:"set-coord-limits",deserialize:(e,t)=>new _u(e,t)};function Jw(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 Ou=class Mu{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Je.default)(t.innerRadius,0,1)},this.metadata=x({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:C(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Mu({innerRadius:n},this.metadata)}}},Qw={type:"set-polar-inner-radius",deserialize:(e,t)=>new Ou(e,t)},eE={type:"set-polar-start-angle",deserialize:(e,t)=>new ku(e,t)},ku=class Nu{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:no(t.startAngle)},this.metadata=x({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return no(n)===this.params.startAngle?null:{spec:C(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Nu({startAngle:n},this.metadata)}}},$r=360,no=e=>(e%$r+$r)%$r,Ia=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=x({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new Ta({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:C(e,{highlights:n}),revert:a}}},tE={type:"remove-highlight",deserialize:(e,t)=>new Ia(e,t)},Ta=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??W(),scope:e.scope??"data-point"},this.metadata=x({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const o=new Ia({id:r},this.metadata),s={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:C(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},rE={type:"add-highlight",deserialize:(e,t)=>new Ta(e,t)};function La(e,t){return{...e,params:{...e.params,...t}}}function wr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function wa(e,t){return C(e,{layers:[...e.layers,t]})}function ee(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:C(e,{layers:xo(e.layers,n,r)})}function Er(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:C(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Ea=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=x({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=Er(e,this.params.layerId);return n===e?null:{spec:n,revert:new Ra({layer:r,index:t},this.metadata)}}},nE={type:"remove-layer",deserialize:(e,t)=>new Ea(e,t)},Ra=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??W()},...e.index!==void 0&&{index:e.index}},this.metadata=x({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:C(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Ea({layerId:t.id},this.metadata)}}},aE={type:"add-layer",deserialize:(e,t)=>new Ra(e,t)},Bu=class Fu{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=x({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!ae(F(t.layers,r),"bar"))return null;const a=De("bar",r),i=Ct(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new Se({list:"overrides",rule:{...a,declarations:oE(i,n)}}).apply(t);if(!s)return null;const c=new Fu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},iE={type:"set-bar-border-radius",deserialize:(e,t)=>new Bu(e,t)},oE=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},sE={type:"set-bar-width",deserialize:(e,t)=>new Gu(e,t)},$u=.05,lE=1,Gu=class Uu{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Je.default)(t.width,$u,1);this.params={...t,width:n},this.metadata=x({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"bar");if(!ae(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:ee(t,r.id,La(r,{width:this.params.width})),revert:new Uu({layerId:r.id,width:n},this.metadata)}}},Hu=class Wu{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=x({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:ee(t,r.id,wr(r,{format:this.params.format})),revert:new Wu({layerId:r.id,format:n},this.metadata)}}},cE={type:"set-data-labels-format",deserialize:(e,t)=>new Hu(e,t)},Ku=class zu{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=x({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:ee(t,r.id,{...r,position:this.params.position}),revert:new zu({layerId:r.id,position:n},this.metadata)}}},uE={type:"set-layer-position",deserialize:(e,t)=>new Ku(e,t)},Yu=class qu{constructor(t,r={}){this.type="set-layer-stat";const n=hs(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=x({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return pE(n,this.params.stat)?null:{spec:ee(t,r.id,{...r,stat:this.params.stat}),revert:new qu({layerId:r.id,stat:n},this.metadata)}}},dE={type:"set-layer-stat",deserialize:(e,t)=>new Yu(e,t)},pE=(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},ju=class Xu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=x({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=ee(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:C(a,{scales:ba(a.scales,a.layers)}),revert:new Xu({layerId:r.id,yScaleType:n},this.metadata)}}},mE={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ju(e,t)},Zu=class Ju{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=x({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:ee(t,r.id,La(r,{interpolate:this.params.interpolate})),revert:new Ju({layerId:r.id,interpolate:n},this.metadata)}}},hE={type:"set-line-interpolation",deserialize:(e,t)=>new Zu(e,t)},Qu=class ed{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=x({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:ee(t,r.id,La(r,{missingValues:this.params.missingValues})),revert:new ed({layerId:r.id,missingValues:n},this.metadata)}}},fE={type:"set-line-missing-values",deserialize:(e,t)=>new Qu(e,t)},td=class rd{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=x({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=F(t.layers,r);if(!ae(a,"line","area"))return null;const i=Ct(t.styles.overrides,De(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=yE(i,n),c=new Se({list:"overrides",rule:a.geom==="area"?{...De("area",r),declarations:s}:{...De("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new rd({layerId:r,lineWidth:o},this.metadata)}:null}},gE={type:"set-line-width",deserialize:(e,t)=>new td(e,t)},yE=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},nd=class ad{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=x({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!ae(F(t.layers,r),"point"))return null;const a=De("point",r),i=Ct(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new Se({list:"overrides",rule:{...a,declarations:bE(i,n)}}).apply(t);return s?{spec:s.spec,revert:new ad({layerId:r,size:o},this.metadata)}:null}},vE={type:"set-point-size",deserialize:(e,t)=>new nd(e,t)},bE=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},id=class od{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=x({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"rule");if(!ae(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([o])=>o!=="label")):{...r.params,label:a};return{spec:ee(t,r.id,{...r,params:i}),revert:new od({layerId:r.id,label:n??null},this.metadata)}}},SE={type:"set-rule-label",deserialize:(e,t)=>new id(e,t)},sd=class ld{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=x({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"rule");if(!ae(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:ee(t,r.id,{...r,mapping:i}),revert:new ld({layerId:r.id,value:a},this.metadata)}}},xE={type:"set-rule-value",deserialize:(e,t)=>new sd(e,t)},AE={type:"set-stat-line",deserialize:(e,t)=>new cd(e,t)},cd=class ud{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:CE(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=TE(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&&RE(r.layer,n))return null;const a=new ud({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:ee(t,r.layer.id,n),revert:a};const i=r===void 0?t:Er(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:wa(i,n),revert:a}}buildStatLine(t,r){if(this.params.line==="none")return null;if(this.params.removedLayer!==void 0)return this.params.removedLayer;const n=this.params.line==="trend"?LE(this.params):wE(t,this.params);if(n===null)return null;const a=Ge(J,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},IE="linear",TE=e=>{const t=Xl(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=Zl(e.layers);if(r!==void 0)return{line:"average",layer:r}},LE=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??IE}),interactive:!1}),wE=(e,{group:t,label:r})=>{const n=EE(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),o=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:o?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},EE=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),RE=(e,t)=>(0,it.isEqual)({...e,id:""},{...t,id:""}),CE=e=>e==="none"?"Hide stat line":`Show ${e} line`,dd=class pd{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=x({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:ee(t,r.id,wr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new pd({layerId:r.id,showCategoryLabels:n},this.metadata)}}},VE={type:"toggle-category-labels",deserialize:(e,t)=>new dd(e,t)},md=class hd{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=x({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:ee(t,r.id,wr(r,{showDataLabels:this.params.showDataLabels})),revert:new hd({layerId:r.id,showDataLabels:n},this.metadata)}}},DE={type:"toggle-data-labels",deserialize:(e,t)=>new md(e,t)},_E={type:"toggle-goal-line",deserialize:(e,t)=>new fd(e,t)},fd=class cn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=x({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=jl(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=Er(t,r.id);return a===t?null:{spec:a,revert:new cn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:wa(t,n),revert:new cn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ge(J,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??PE}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},PE=0,OE={type:"toggle-line-fill",deserialize:(e,t)=>new gd(e,t)},gd=class yd{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=x({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!ae(F(t.layers,r),"line"))return null;const i=De("line",r),o=Ct(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new Se({list:"overrides",rule:{...i,declarations:kE(o,n?a??ME:null)}}).apply(t);if(!u)return null;const d=new yd({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},ME=.2,kE=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},NE={type:"toggle-line-points",deserialize:(e,t)=>new vd(e,t)},vd=class un{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=x({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");return ae(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:wa(t,this.params.removedLayer??Ge(J,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new un({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:Er(t,n.id),revert:new un({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:In(n,[r]))}},bd=class Sd{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=x({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:ee(t,r.id,wr(r,{showStackTotals:this.params.showStackTotals})),revert:new Sd({layerId:r.id,showStackTotals:n},this.metadata)}}},BE={type:"toggle-stack-totals",deserialize:(e,t)=>new bd(e,t)},xd=class Ad{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${_t(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Vt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const o={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},s=Dt(t,this.params.scaledAesthetic,o),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:s,revert:new Ad(c,this.metadata)}}},FE={type:"set-scale-domain",deserialize:(e,t)=>new xd(e,t)},Id=class Td{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${_t(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Vt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||at(r.palette,this.params.palette)?null:{spec:Dt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Td({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},$E={type:"set-scale-palette",deserialize:(e,t)=>new Id(e,t)},Ld=class wd{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${_t(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Vt(t,this.params.scaledAesthetic);if(!r||!UE(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:Dt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new wd({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},GE={type:"set-scale-reverse",deserialize:(e,t)=>new Ld(e,t)};function UE(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Ed=class Rd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${_t(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Vt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:Dt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Rd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},HE={type:"set-scale-transform",deserialize:(e,t)=>new Ed(e,t)},Cd=class Vd{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${_t(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=Vt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:Dt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Vd({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},WE={type:"set-scale-zero",deserialize:(e,t)=>new Cd(e,t)},Dd=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new Dd;S.register(lL);S.register(ZL);S.register(aE);S.register(nE);S.register(cE);S.register(uE);S.register(dE);S.register(mE);S.register(hE);S.register(gE);S.register(iE);S.register(sE);S.register(vE);S.register(fE);S.register(SE);S.register(xE);S.register(AE);S.register(VE);S.register(DE);S.register(_E);S.register(OE);S.register(NE);S.register(BE);S.register(FE);S.register($E);S.register(GE);S.register(HE);S.register(WE);S.register(dw);S.register(hw);S.register(mw);S.register(fw);S.register(gw);S.register(yw);S.register(vw);S.register(bw);S.register(Sw);S.register(Dw);S.register(Pw);S.register(kw);S.register(Nw);S.register(Bw);S.register(Fw);S.register($w);S.register(Gw);S.register(Ww);S.register(Kw);S.register(zw);S.register(Yw);S.register(qw);S.register(jw);S.register(rE);S.register(tE);S.register(aL);S.register(KT);S.register(WT);S.register(tL);S.register(iL);S.register(rL);S.register(Zw);S.register(Qw);S.register(eE);var _d=(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&&Ar(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observations":return t.kind==="observations"&&e.layerId===t.layerId&&e.scope===t.scope&&Et(e.predicate,t.predicate);case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"graph":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},Pd=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,o=e.apply(t);if(!o)return a||(this.hasOpenRun=!1),i(t,null);const s=r?.({spec:o.spec,command:e})??null,c=s?s.adopted:o.spec;return c?(this.push(e,c,o.revert,a),i(c,s?.value??null)):(a||(this.hasOpenRun=!1),i(t,s?.value??null))})}commit(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"commit"}),!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:ao(this.undoStack),redoStack:ao(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],o=this.hasOpenRun&&i!==void 0&&zE(i.command,e);if(n&&o){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},KE=Object.freeze([]),zE=(e,t)=>e.type===t.type&&_d(e.target,t.target),ao=e=>e.length===0?KE:e.map(t=>t.command.metadata),YE=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.commit(),t=this.frame;return this.frame=null,e?t:null}},qE=class{constructor(e){this.compiler=e,this.history=new Pd,this.current=null,this.last=null,this.hostSpec=null,this.run=new YE(this.history)}get scene(){return this.current}compile(e){return this.last=e,this.hostSpec=e.spec,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.spec!==this.hostSpec&&e.spec!==t.spec,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes,i=!t||e.colorScheme!==t.colorScheme;if(this.hostSpec=e.spec,!r&&!n&&!a&&!i)return null;let o=null;r?this.run.close():o=this.closeAndConvert();const s=this.last,c=s&&!r?s.spec:e.spec;this.last={spec:c,data:e.data,customPalettes:e.customPalettes,colorScheme:e.colorScheme};const u=this.current,d=r||a||!u?this.absorb(this.compiler.compile(this.last)):this.absorb(this.compiler.recompile({spec:u.spec,data:e.data,colorScheme:e.colorScheme}));return r&&d.ok&&this.history.clear(),{result:d,specChanged:r,...o&&{committedSpec:o.spec}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.commitNotification(!1);c&&n.push(c)}const{current:a,last:i,history:o}=this;if(!a||!i)return n;const s=o.apply(e,a.spec,({spec:c})=>{const u=this.applyEdit(c,i,r,e);return{adopted:u.ok?u.scene.spec:null,value:u}},t);return s&&n.push(this.renderedNotification(s,e,r)),n}commit(){const e=this.commitNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const o=this.applyEdit(a,r);return{adopted:o.ok?o.scene.spec:null,value:{result:o,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{scene:e.scene}:{scene:e.scene,result:e,command:t,...e.spec&&{spec:e.spec}}:{errors:e.errors}}commitNotification(e){const t=this.closeAndConvert();return t?{result:t.result,spec:t.spec,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{spec:this.recordSpec(t.spec,r),result:e.result,command:e.command}}applyEdit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e,colorScheme:t.colorScheme});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.scene,r&&n){const o={ok:!0,scene:a.scene,warnings:a.warnings};return this.run.open({result:o,command:n}),o}this.run.clear();const i=this.recordSpec(a.scene.spec,t);return{ok:!0,scene:a.scene,warnings:a.warnings,spec:i}}recordSpec(e,t){const r=Jl(e);return this.last={spec:r,data:t.data,customPalettes:t.customPalettes,colorScheme:t.colorScheme},r}absorb(e){return e.ok&&(this.current=e.scene),e}},jE=new Set(["x","y"]),io=["numeric","categorical","temporal"],oo=["numeric"],XE=(e,t)=>{const r=e.layers.map(a=>sc(a.geom)).filter(l.isDefined),n=Ir(e);return t.filter(a=>ZE(e,r,a)).map(a=>({aesthetic:a,variables:JE(n,r,a),isRequired:jE.has(a)}))},ZE=(e,t,r)=>{switch(r){case"x":return!tR(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))}},JE=(e,t,r)=>{const n=QE(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},QE=(e,t)=>t==="size"?oo:t!=="x"&&t!=="y"?io:eR(e,t)?oo:io,eR=(e,t)=>e.some(r=>r.positionRoles.some(n=>ko.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),tR=e=>e.coordType==="polar"&&e.params.theta==="y",rR=500,nR="normal",Ca={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},aR=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}`},Va=e=>typeof e!="string"?e??500:Ca[e],iR="\0",oR=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,Va(t.weight),t.style??"normal",e].join(iR)}},sR={" ":.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 lR=1.05,cR=.84,uR=.21,dR=class{measureText(e,t){let r=0;for(const i of e)r+=(sR[i]??.55)*t.size;Va(t.weight)>=Ca.semiBold&&(r*=lR);const n=cR*t.size,a=uR*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_PARTS=l.ANNOTATION_PARTS;exports.ANNOTATION_STYLE_KINDS=l.ANNOTATION_STYLE_KINDS;exports.ANNOTATION_TOOLTIP_MARKER_GAP=CS;exports.ARROW_DEFAULTS=l.ARROW_DEFAULTS;exports.ARROW_STICKER_DECLARATIONS=l.ARROW_STICKER_DECLARATIONS;exports.ARROW_STROKE_WIDTHS=l.ARROW_STROKE_WIDTHS;exports.AXIS_KEYS=bn;exports.AddAnnotationCommand=ga;exports.AddHighlightCommand=Ta;exports.AddLayerCommand=Ra;exports.BORDER_RADIUS_PX=ra;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Mf;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=by;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=oR;exports.CommandRegistry=Dd;exports.CommandStackManager=Pd;exports.Compiler=Cs;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=nR;exports.DEFAULT_FONT_WEIGHT=rR;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRAPH_BORDER_WIDTH=l.DEFAULT_GRAPH_BORDER_WIDTH;exports.DEFAULT_GRAPH_PADDING=l.DEFAULT_GRAPH_PADDING;exports.DEFAULT_HEADLINE_SWATCH_SIZE=l.DEFAULT_HEADLINE_SWATCH_SIZE;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_MONO_BASE=l.DEFAULT_MONO_BASE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DIFFERENCE_ARROW_DEFAULTS=l.DIFFERENCE_ARROW_DEFAULTS;exports.DIFFERENCE_ARROW_SIZE_DECLARATIONS=l.DIFFERENCE_ARROW_SIZE_DECLARATIONS;exports.DIVERGING_SCHEME_NAMES=us;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=be;exports.GraphCompilationSession=qE;exports.HEADING_PARTS=l.HEADING_PARTS;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=Rx;exports.HEADLINE_TREND_GAP=Dx;exports.HEADLINE_TREND_ICON_SIZE=Vx;exports.HEADLINE_VALUE_LABEL_GAP=Cx;exports.HeuristicTextMeasurer=dR;exports.HoverEngine=hI;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=l.LINE_STYLE_TYPES;exports.LayoutCompiler=eS;exports.MAX_BAR_WIDTH=lE;exports.MIN_BAR_WIDTH=$u;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=ac;exports.NAMED_WEIGHTS=Ca;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ua;exports.OUT_OF_VIEW_MARGIN_PX=VS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=Kd;exports.POSITION_TYPES=l.POSITION_TYPES;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=oe;exports.RemoveAnnotationCommand=fa;exports.RemoveHighlightCommand=Ia;exports.RemoveLayerCommand=Ea;exports.SCALED_POSITION_AESTHETIC_KEYS=Sn;exports.SCALED_VISUAL_AESTHETIC_KEYS=vt;exports.SCHEME_ALIASES=ds;exports.SEQUENTIAL_SCHEME_NAMES=kf;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=DS;exports.SOURCE_PARTS=l.SOURCE_PARTS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=Bc;exports.SetAxisPositionCommand=$c;exports.SetAxisTickModeCommand=Uc;exports.SetAxisTicksVisibilityCommand=Wc;exports.SetAxisVisibilityCommand=zc;exports.SetBarBorderRadiusCommand=Bu;exports.SetBarWidthCommand=Gu;exports.SetChartTypeCommand=cc;exports.SetContentCaptionCommand=qc;exports.SetContentSourceCommand=Xc;exports.SetContentSubtitleCommand=Jc;exports.SetContentTitleCommand=eu;exports.SetCoordLimitsCommand=_u;exports.SetDataLabelsFormatCommand=Hu;exports.SetDifferenceArrowStyleCommand=ic;exports.SetGridLineStyleCommand=au;exports.SetGridLineWidthCommand=ou;exports.SetGridVisibilityCommand=lu;exports.SetHeadlineCompareWithCommand=uu;exports.SetHeadlinePositionCommand=pu;exports.SetHeadlineShowCommand=hu;exports.SetHeadlineSizeCommand=gu;exports.SetHighlightDimStyleCommand=vu;exports.SetLayerPositionCommand=Ku;exports.SetLayerStatCommand=Yu;exports.SetLayerYScaleTypeCommand=ju;exports.SetLegendAlignCommand=Su;exports.SetLegendDisplayCommand=Au;exports.SetLegendPositionCommand=Tu;exports.SetLineInterpolationCommand=Zu;exports.SetLineMissingValuesCommand=Qu;exports.SetLineWidthCommand=td;exports.SetMappingCommand=_c;exports.SetNumberFormatAbbreviationCommand=wu;exports.SetNumberFormatDecimalsCommand=Ru;exports.SetPointSizeCommand=nd;exports.SetPolarInnerRadiusCommand=Ou;exports.SetPolarStartAngleCommand=ku;exports.SetRuleLabelCommand=id;exports.SetRuleValueCommand=sd;exports.SetScaleDomainCommand=xd;exports.SetScalePaletteCommand=Id;exports.SetScaleReverseCommand=Ld;exports.SetScaleTransformCommand=Ed;exports.SetScaleZeroCommand=Cd;exports.SetStatLineCommand=cd;exports.SetStyleRuleCommand=Se;exports.SpecResolver=vs;exports.Stat=$e;exports.TAU=he;exports.TEXT_ANNOTATION_DEFAULTS=l.TEXT_ANNOTATION_DEFAULTS;exports.TEXT_ANNOTATION_FADE_ALPHA=l.TEXT_ANNOTATION_FADE_ALPHA;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=dd;exports.ToggleContentVisibilityCommand=Vu;exports.ToggleDataLabelsCommand=md;exports.ToggleGoalLineCommand=fd;exports.ToggleLineFillCommand=gd;exports.ToggleLinePointsVisibilityCommand=vd;exports.ToggleStackTotalsCommand=bd;exports.UpdateAnnotationCommand=va;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=fo;exports.annotation=Bg;exports.areAnchorsEqual=Xe;exports.areEditMenuTriggersEqual=ix;exports.areEditTargetsEqual=_d;exports.areEndpointsComparable=vo;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=Yl;exports.arePointerRegionListsEqual=JS;exports.arePredicatesEqual=Et;exports.areStyleDeclarationsEqual=Ql;exports.areStyleRuleAddressesEqual=Ar;exports.buildAverageLineSymbols=LS;exports.buildCalloutHitRegions=RS;exports.buildColumnKey=Sl;exports.buildDataLabelsContent=Xv;exports.buildDiagnostic=So;exports.buildEditMenuTriggerRegion=nx;exports.buildFontString=aR;exports.buildLayerIntroPlan=LI;exports.buildLayerStyleAddress=De;exports.buildLayerYValueFormatter=Jn;exports.buildObservationPredicate=US;exports.buildObservationsTarget=zS;exports.buildPinnedNumberValueFormatter=gx;exports.buildPolarBarArcPath=Yx;exports.buildSliceGroupKey=Il;exports.buildTooltipContent=XI;exports.canAnchorDirectLabels=Yo;exports.canBecomeCombo=fL;exports.canBecomeHeatmap=gL;exports.canPlaceDataLabels=jv;exports.clampAnnotationTranslation=YT;exports.commandRegistry=S;exports.compileChromeStyles=As;exports.compileStylesheetForLayer=zg;exports.compositeColor=uo;exports.computeArrow=IS;exports.computeDifferenceArrow=il;exports.computeDirectLabelsLayout=GS;exports.computeLineBoxHeight=ol;exports.computePanelBorderPaths=FI;exports.computePanelBorderSizes=$I;exports.config=l.config;exports.coord=l.coord;exports.countLayerGeoms=wI;exports.createAlphaValueReader=Qd;exports.createAnchorResolver=nS;exports.createAreaPathGenerators=Bx;exports.createColorValueReader=go;exports.createCompiler=Sy;exports.createDatasetFromKindPartitions=Op;exports.createEmptyHighlight=qo;exports.createGraphyBuilder=Iy;exports.createGroupValueReader=ep;exports.createHeadlineItemRows=_x;exports.createLabelValueReader=Zd;exports.createLineFillAreaGenerator=Wx;exports.createLinePathGenerator=Hx;exports.createObservationAnchorBuilder=yt;exports.createObservationAnchorParser=bo;exports.createRawValueReader=Q;exports.createSegmentYReader=gt;exports.createSizeValueReader=Jd;exports.createSpec=Ds;exports.createStableBandKeyGenerator=Zx;exports.createStableCellKeyGenerator=Jx;exports.createStableKeyGenerator=br;exports.createStrokeWidthValueReader=tp;exports.createStyleResolver=lt;exports.createValueFormatter=N;exports.createXValueReader=ot;exports.createYValueReader=mn;exports.cursorToPiePlane=ir;exports.cursorToPolar=dn;exports.describeMeasurementBasis=Ur;exports.ensureReadableTextColor=Wd;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=pl;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=Ym;exports.findAnnotation=xt;exports.findAverageLineLayer=Zl;exports.findAxisGuide=ta;exports.findDistinctLayers=Tn;exports.findEquivalentHighlight=CT;exports.findGoalLineLayer=jl;exports.findHighlightsAtObservation=sx;exports.findKindStyleDeclarations=Ct;exports.findLayerByGeom=we;exports.findLayerById=F;exports.findLegendForAesthetic=wx;exports.findObservationAttachment=ql;exports.findPointerRegion=XS;exports.findStyleRule=Rt;exports.findStyleRuleIndex=ma;exports.findTrendLineLayer=Xl;exports.formatDifferenceLabel=nl;exports.formatHeadline=yx;exports.formatLegends=Tx;exports.formatRuleValue=Ex;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=H;exports.getAlpha=zs;exports.getAngleExtent=Xn;exports.getBarRectBounds=bl;exports.getBoundingRect=Ux;exports.getChromeDashArray=TT;exports.getColor=Lt;exports.getCrossAxisCoordinate=ve;exports.getCurve=vr;exports.getDashArray=Nx;exports.getDifferenceArrowDimensions=al;exports.getDifferenceArrowLabelBox=sl;exports.getGroup=re;exports.getHoverGuideLineProps=vI;exports.getHoverGuideRectProps=bI;exports.getInsetTileRect=el;exports.getLineType=Ys;exports.getMainAxisCoordinate=Z;exports.getNumericWeight=Va;exports.getPolarHoverGuideArcProps=SI;exports.getRadiusExtent=Zn;exports.getRuleDashPattern=Xx;exports.getScaledAesthetic=jd;exports.getShapeAnnotationStroke=mT;exports.getSize=Yn;exports.getStablePolarBarKeyGenerator=Qx;exports.getStackRole=Jo;exports.getStrokeWidth=Jr;exports.getTileRectBounds=Qs;exports.getUnionExtent=jx;exports.getX=k;exports.getXMax=X;exports.getXMin=j;exports.getY=_;exports.getYMax=$;exports.getYMin=U;exports.getYRaw=pn;exports.hasMultipleGroups=cr;exports.highlight=RT;exports.inferDefaultDifferenceArrowEndpoints=ux;exports.inferDifferenceArrowEndpoints=vl;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=qT;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=ap;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=Pt;exports.isCompanionLayer=In;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=po;exports.isGeomStyleRule=ha;exports.isKeyedScope=yr;exports.isLayerOf=Vs;exports.isLayerOfType=ae;exports.isLineStyleType=l.isLineStyleType;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=LT;exports.isPointWithinEditMenuTrigger=ax;exports.isPointWithinRegionShape=ea;exports.isSafeUrl=YI;exports.isStackedPosition=l.isStackedPosition;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=OT;exports.normalizeAngle=Pe;exports.orderPointerRegions=ZS;exports.paintsInDonutHole=gr;exports.pickReadableTextColor=co;exports.pipe=_s;exports.placeCallouts=kS;exports.polarToUnit=fe;exports.positionToAngle=mo;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=Fx;exports.prepareLineObservations=Kx;exports.projectAnchorToPanel=Qt;exports.projectRegionToPanel=oS;exports.quantizeKey=te;exports.readAnchoredObservation=px;exports.readAttachedObservation=da;exports.readAuthoredNumber=iT;exports.readAuthoredString=oT;exports.readBroadestObservationsScope=YS;exports.readChartType=hL;exports.readColorGroupObservation=eA;exports.readComboLineLayerId=yL;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=bu;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=XE;exports.readMappedVariable=Oc;exports.readObservationIndex=xI;exports.readXExtent=Hl;exports.readYExtent=Wl;exports.resolveAnchorVariable=ke;exports.resolveArrowAnnotationStyle=lT;exports.resolveArrowColor=FS;exports.resolveAxisLabelStyle=xb;exports.resolveBarBandFraction=zr;exports.resolveBarBorderRadiusPx=na;exports.resolveBarBorderTreatment=Gx;exports.resolveBarCornerRadiiPx=$x;exports.resolveCalloutAnnotationStyle=pT;exports.resolveCaptionStyle=bb;exports.resolveChromeMargin=q;exports.resolveChromeMargins=AT;exports.resolveColorRamp=Cn;exports.resolveComparisonBasis=zo;exports.resolveDataLabelStyle=Ib;exports.resolveDeferredAnchors=uS;exports.resolveDefinition=Rn;exports.resolveDifferenceArrowAnnotationStyle=cT;exports.resolveDirectLabelStyle=Eb;exports.resolveGeomAnchorFrame=gn;exports.resolveGraphChromeStyle=vT;exports.resolveGraphPadding=bT;exports.resolveGridLineStyle=fT;exports.resolveHeadingFontFamily=yT;exports.resolveHeadingStyle=yb;exports.resolveHeadlineFigure=Cb;exports.resolveHeadlineItemStyle=Rb;exports.resolveHeadlinePlacement=qb;exports.resolveHeadlineStyle=xT;exports.resolveHoverGuideStyle=IT;exports.resolveImageAnnotationStyle=dT;exports.resolveLegendItemStyle=wb;exports.resolveLegendStyle=ST;exports.resolveObservationPoint=mx;exports.resolveObservationsTarget=gl;exports.resolvePanelBorderStyle=hT;exports.resolvePolarBarCornerRadiusUnit=qx;exports.resolveRuleLabelStyle=Tb;exports.resolveSegmentYSource=or;exports.resolveShapeAnnotationStyle=sT;exports.resolveSourceStyle=Sb;exports.resolveSubtitleStyle=vb;exports.resolveSwatchGeomPaint=aa;exports.resolveTextAnnotationStyle=uT;exports.resolveTextStyle=B;exports.resolveTickLabelStyle=Ab;exports.resolveTickLineStyle=gT;exports.resolveTooltipStyle=Lb;exports.resolveYScaleAesthetic=Te;exports.sampleColorScheme=Gf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=hx;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=gb;exports.toPanelCursor=dl;exports.toPercent=Ve;exports.toSpec=Jl;exports.toViewBoxX=iS;exports.toViewBoxY=ce;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=Os;exports.uniqueId=W;exports.unitToPolar=ar;exports.updateSpec=P;
|
|
23
|
+
`,vb=(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},bb=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),ll=({arrow:e,style:t,mainAxis:r,panelWidth:n,panelHeight:a,locale:i})=>{const o=r==="y",s={x:e.start.x*n,y:(1-e.start.y)*a},c={x:e.end.x*n,y:(1-e.end.y)*a},u=sl(t.strokeWidth),d=hb(o,s,c,u),p=(o?gb:fb)(s,c,d,u),m=yb(o,c,u),h=vb(o,s,c,d,bb(o,s,c),e.labelCrossPosition),f=ol({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:s,end:c,linePath:p,arrowheadPath:m,labelPosition:h,labelText:f}},yi={large:1,medium:23/26,small:19/26},Sb={large:1,medium:10/12,small:10/12},xb=["fontFamily","fontSize","fontWeight","lineHeight","textColor"],cl=e=>e.fontSize*e.lineHeight,Ab=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),B=(e,t)=>({fontFamily:e.get("fontFamily")??t.get("fontFamily"),fontSize:e.get("fontSize")*t.get("textScale"),fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),Ib=e=>B(e.heading.h1,e.graph),Tb=e=>B(e.heading.h2,e.graph),Lb=e=>B(e.caption,e.graph),wb=e=>({label:B(e.source.label,e.graph),link:B(e.source.link,e.graph)}),Eb=(e,t)=>B(e.axisLabel(t),e.graph),Rb=(e,t,r)=>{const n=e.tickLabel(t,r);return{...B(n,e.graph),offset:n.get("offset")}},Cb=(e,t,r)=>{const n=e.dataLabel(t,r),a=n.get("background"),i=n.get("borderColor"),o=n.get("borderWidth");return{...B(n,e.graph),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock"),borderRadius:n.get("borderRadius"),isTextColorAuthored:n.getSource("textColor")==="authored",...a===void 0?{}:{background:a},...i===void 0?{}:{borderColor:i},...o===void 0?{}:{borderWidth:o}}},Vb=(e,t)=>{const r=e.ruleLabel(t),{textColor:n,...a}=B(r,e.graph);return r.getSource("textColor")==="authored"?{...a,textColor:n}:a},Db=e=>{const t=e.tooltip.box,r=e.graph;return{box:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")},heading:B(e.tooltip.heading,r),label:B(e.tooltip.label,r),value:B(e.tooltip.value,r),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},_b=e=>{const t=e.legendItem.item,r=t.get("background"),n=t.get("borderColor");return{item:{...B(t,e.graph),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),borderRadius:t.get("borderRadius"),borderWidth:t.get("borderWidth"),...r===void 0?{}:{background:r},...n===void 0?{}:{borderColor:n}},swatch:{size:e.legendItem.swatch.get("size"),strokeWidth:e.legendItem.swatch.get("strokeWidth")}}},Pb=e=>{const t=e.directLabel;return{...B(t,e.graph),strokeWidth:t.get("strokeWidth"),lineType:t.get("lineType"),isTextColorAuthored:t.getSource("textColor")==="authored"}},Ob=(e,t)=>{const r=e.graph.get("fontFamily"),n=e.graph.get("textScale"),a=yi[t]*n,i=Sb[t]*n,o=e.headlineItem,s=B(o.number,e.graph),c={...s,fontSize:s.fontSize*yi[t]},u=o.numberCenter.get("fontSize");return{number:c,...kb(o.numberCenter)?{numberCenter:Ht(o.numberCenter,u===void 0?c.fontSize:u*a,r)}:{},caption:Ht(o.caption,o.caption.get("fontSize")*i,r),label:Ht(o.label,o.label.get("fontSize")*i,r),swatch:{size:o.swatch.get("size")},trend:Ht(o.trend,o.trend.get("fontSize")*i,r),trendUp:{textColor:o.trendUp.get("textColor")},trendDown:{textColor:o.trendDown.get("textColor")},trendFlat:{textColor:o.trendFlat.get("textColor")}}},Mb=(e,t)=>{const r=t?e.numberCenter:void 0;return r===void 0?e.number:{fontFamily:r.fontFamily??e.number.fontFamily,fontSize:r.fontSize,fontWeight:r.fontWeight??e.number.fontWeight,lineHeight:r.lineHeight??e.number.lineHeight,textColor:r.textColor??e.number.textColor}},kb=e=>xb.some(t=>e.getSource(t)!=="unresolved"),Ht=(e,t,r)=>{const n=e.get("fontFamily")??r,a=e.get("fontWeight"),i=e.get("lineHeight"),o=e.get("textColor");return{fontSize:t,...n===void 0?{}:{fontFamily:n},...a===void 0?{}:{fontWeight:a},...i===void 0?{}:{lineHeight:i},...o===void 0?{}:{textColor:o}}},ul=({labelPosition:e,measuredTextWidth:t,label:r})=>{const n=t+2*r.paddingInline,a=cl(r)+2*r.paddingBlock;return{x:e.x-n/2,y:e.y-a/2,width:n,height:a}};function*Nb({annotations:e,mainAxis:t,panelRect:r,locale:n,resolveStyle:a,measureLabel:i}){for(const o of e.differenceArrows){if(!tt(o.start.x,o.start.y)||!tt(o.end.x,o.end.y))continue;const s=a(o.id),c=ll({arrow:o,style:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,locale:n}),u=ul({labelPosition:c.labelPosition,measuredTextWidth:i(c.labelText,s.label).width,label:s.label});yield{...u,x:r.x+u.x,y:r.y+u.y}}}var Bb=e=>{const t=e.padding,r=vi(e.rows,t?.top??0,t?.bottom??0),n=vi(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:Ub(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Fb=e=>{const t=bi(e.rows,e.height),r=bi(e.cols,e.width),n=Si(t),a=Si(r),i=new Map;for(const o of e.placements){const s=o.rowSpan??1,c=o.colSpan??1,u=a[o.col]??0,d=n[o.row]??0,p=xi(r,o.col,c),m=xi(t,o.row,s);i.set(o.name,{x:u,y:d,width:Math.max(0,p),height:Math.max(0,m)})}return i},vi=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;rn(s)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(s.name,n.length),n.push($b(s));const c=Gb(e,o);if(rn(s)&&c){const u=s.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},$b=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},rn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Gb=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&rn(n))return n}},Ub=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),o=r.get(a.col);if(i===void 0||o===void 0)continue;const s=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):o;s===void 0||c===void 0||n.push({name:a.name,row:i,col:o,rowSpan:Math.max(1,s-i+1),colSpan:Math.max(1,c-o+1)})}return n},bi=(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)},Si=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},xi=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},nt={top:0,right:0,bottom:0,left:0},dl={outer:nt,inner:nt},Hb=(e,t,r,n=nt,a=dl,i=l.DEFAULT_GRAPH_PADDING_EDGES,o)=>{const s={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=[{name:"header",size:t.headerSize.height,gaps:he(o.header)},{name:"topLegend",size:r.legends.top,gaps:he(o.legend.top)},{name:"headline",size:r.headline,gaps:he(o.headline)},{name:"topAxisLabel",size:c,gaps:he(o.axisLabel.top)},{name:"topAxis",size:r.axes.top,gaps:he(o.tickLabel.top)},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:s.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:s.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:he(o.tickLabel.bottom)},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:he(o.axisLabel.bottom)},{name:"bottomLegend",size:r.legends.bottom,gaps:he(o.legend.bottom)},{name:"footer",size:t.footerSize.height,gaps:he(o.footer)}],d=[{name:"leftLegend",size:r.legends.left,gaps:Wt(o.legend.left)},{name:"leftAxis",size:r.axes.left,gaps:Wt(o.tickLabel.left)},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:s.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:s.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:Wt(o.tickLabel.right)},{name:"rightLegend",size:r.legends.right,gaps:Wt(o.legend.right)}],p=Ai(u,i.top,i.bottom),m=Ai(d,i.left,i.right);return Bb({rows:u,cols:d,placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...Kb(r.axes),...zb(r.axesLabels,r.axes),...Yb(r.legends)],containerSize:e,padding:{top:p.start,bottom:p.end,left:m.start,right:m.end}})},he=e=>({before:e.top,after:e.bottom}),Wt=e=>({before:e.left,after:e.right}),Wb=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ai=(e,t,r)=>{const n=e.filter(Wb),a=n[0],i=n[n.length-1];return{start:t+(a?.gaps?.before??0),end:r+(i?.gaps?.after??0)}},Kb=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},zb=(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},Yb=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 qb=class{constructor(e){this.outer={...nt},this.inner={...nt},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},jb=["top","right","bottom","left"],kr=(e,t)=>{const r={};for(const n of jb){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function Ii(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var nn=["large","medium","small"],Xb=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of nn)if(r(n)<=t)return n;return"small"},Zb=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:nn.indexOf(e);for(const a of nn.slice(n))if(r(a)<=t)return a;return null},Jb=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const o=a===0?i:n+t+i;if(o>r)break;n=o,a+=1}return a},Qb=({headline:e,containerSize:t,measurer:r})=>{if(vr(e))return 0;const n=pl(e,t.width,r);return r.measureHeadline(e.formatted,n).height},eS=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(vr(e)){const s=tS(t.panel,e.innerRadius),c=Zb({size:e.size,availableWidth:s.width,measureStripWidth:ml(e,n)});return c===null?null:{rect:s,resolvedSize:c,visibleItemCount:1}}const i=pl(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const o=Jb({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return o===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:o}},vr=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,tS=(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}},pl=(e,t,r)=>Xb({size:e.size,availableWidth:t,measureStripWidth:ml(e,r)}),ml=(e,t)=>r=>t.measureHeadline(e.formatted,r,vr(e)).width,ze={x:0,y:0,width:0,height:0},rS={top:0,right:0,bottom:0,left:0},nS="0000",aS=3,iS=e=>e.plot.y+e.plot.height-e.panel.y,oS=class{constructor(e){this.measurer=e}compile(e){return ur({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:dl,panelBorder:e.panelBorder??nt,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??l.DEFAULT_GRAPH_PADDING_EDGES,margins:e.margins}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:sS(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Ti(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Ti(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:o,headline:s,padding:c,margins:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:iS(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new qb(t);if(e.annotations&&e.resolveDifferenceArrowStyle&&e.overflowStrategy.differenceArrows)for(const o of Nb({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,locale:r,resolveStyle:e.resolveDifferenceArrowStyle,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(o,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const o of ib({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(o,e.overflowStrategy.dataLabels);const i=a.resolve();return Ii(i.inner,n.inner)&&Ii(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:o,panelBorder:s,headline:c,locale:u,padding:d,margins:p}){let m=t,h=o;for(let f=0;f<aS;f++){const y=this.measurePanelOverflow(e,m.panelFrame,u,h);if(y===h)break;h=y,m=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:y,panelBorder:s,headline:c,padding:d,margins:p})}return m}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,o=a.height-n.vertical*2;return i<=0||o<=0?Li(r,a,0,0):Li(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=H(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const o=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,o.width),a=Math.max(a,o.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:nS}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=H(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),o=Qy({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:s,...c}=e,u={...c,ticks:o,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?qy({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:o,padding:s,margins:c}){const u=Fb(Hb(r,n,this.measureGuides(e,t,o,r),i,a,s,lS(c,t)));return{header:u.get("header")??ze,headline:u.get("headline")??ze,footer:u.get("footer")??ze,plot:u.get("plot")??ze,panelFrame:u.get("panelFrame")??ze,panel:u.get("panel")??ze,axes:kr(u,"Axis"),axisLabels:kr(u,"AxisLabel"),legends:kr(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const s of e)s.isVisible&&s.geometry==="linear"&&(a[s.position]=this.measurer.measureAxis(s),s.label!==null&&(i[s.position]=this.measurer.measureAxisLabel(s)));const o={top:0,right:0,bottom:0,left:0};for(const s of t)o[s.position]=this.measurer.measureLegend(s);return{axes:a,axesLabels:i,legends:o,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:Qb({headline:e,containerSize:t,measurer:this.measurer})}},Ti=e=>e==="left"||e==="right",Li=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,o=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-o)/2,y:t.y+n+(i-o)/2,width:o,height:o}}},sS=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(o=>o.value)),a=new WeakMap;return i=>{const o=a.get(i);if(o)return o;const s=Yn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,s),s}},lS=(e,t)=>{const r={...e.legend};for(const n of t)n.display==="direct"&&(r[n.position]=rS);return{...e,legend:r}},cS=(e=[])=>{const t=uS(e);return{resolve:(r,n,a)=>{if(!t.has(r))return null;const i=t.get(r).resolveAnchorPosition?.(n,a)??null;return i===null?null:{...i,frame:vn(a.coordSystem)}},hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0,createLayerMeasurement:r=>t.has(r.geom)?Co(r,t.get(r.geom)):null}},uS=e=>{const t=new hr;for(const r of e){const n=Vn(r);n instanceof Se&&t.register(n.type,n)}return t};function dS(e){return e}function de(e){return 1-e}var Ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,rr=(e,t)=>{const r=dr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+de(e.y)*r.height}},pS=(e,t)=>{const r=dr(e.frame,t);return{x:r.x+e.x*r.width,y:r.y+(de(e.y)-e.height)*r.height,width:e.width*r.width,height:e.height*r.height}},mS=class{constructor(e,t,r){this.annotations=e,this.panelRect=t,this.measuredBoxes=r,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const i=this.toPanelPoint(e),{x:o,y:s}=an(e.defer,this.panelRect);return Ri({...e,x:i.x+o,y:i.y-s})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=gt(t,e.defer.align),{x:n,y:a}=hS(r,e.defer.offset,this.panelRect);return{x:n,y:a}}resolveRegion(e){if(e.defer===void 0)return e;if(e.defer.type==="px-offset"){const a=this.toPanelRegion(e),{x:i,y:o}=an(e.defer,this.panelRect);return Ri({...e,x:a.x-i,y:a.y-o,width:Math.max(0,a.width+2*i),height:Math.max(0,a.height+2*o)})}const t=this.boxOf(e.defer.ref);if(t===null)return null;const r=t.xMax-t.xMin,n=t.yMax-t.yMin;return r<=0||n<=0?null:{x:t.xMin,y:t.yMin,width:r,height:n}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:fS(this.toPanelRegion(r))}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:wi(this.toPanelPoint(r),this.toPanelPoint(n))}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=this.toPanelPoint(r),i=t.annotation.width,o=n.height/this.panelRect.height,s=bo(t.annotation.align),c=a.x-s.x*i,u=a.y+(1-s.y)*o;return{xMin:c,xMax:c+i,yMin:u-o,yMax:u}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Ei(this.toPanelPoint(r))}case"differenceArrow":return wi(this.toPanelPoint(t.annotation.start),this.toPanelPoint(t.annotation.end));case"pinnedNumber":case"comment":return Ei(this.toPanelPoint(t.annotation.at))}}toPanelPoint(e){return Fa(e,this.panelRect)}toPanelRegion(e){if(e.frame!=="disk")return e;const t=Fa(e,this.panelRect),r=dr(e.frame,this.panelRect);return{...t,width:this.panelRect.width>0?e.width*r.width/this.panelRect.width:0,height:this.panelRect.height>0?e.height*r.height/this.panelRect.height:0}}},an=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),hS=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:o}=an({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-o}}return{x:e.x+n,y:e.y-a}},fS=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),wi=(e,t)=>({xMin:Math.min(e.x,t.x),xMax:Math.max(e.x,t.x),yMin:Math.min(e.y,t.y),yMax:Math.max(e.y,t.y)}),Ei=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),Ri=e=>{const t={...e};return delete t.defer,delete t.frame,t},gS=e=>{const{annotations:t,panelRect:r,measuredBoxes:n,onCycle:a,onMissingRef:i}=e;if(!yS(t))return t;const o=new mS(t,r,n),s={...t,shapes:ct(t.shapes,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),images:ct(t.images,d=>d.region.defer!==void 0,d=>{const p=o.resolveRegion(d.region);return p===null?null:{...d,region:p}}),arrows:ct(t.arrows,d=>d.start.defer!==void 0||d.end.defer!==void 0,d=>{const p=o.resolvePoint(d.start),m=o.resolvePoint(d.end);return p===null||m===null?null:{...d,start:p,end:m}}),textAnnotations:ct(t.textAnnotations,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}}),stickers:ct(t.stickers,d=>d.at.defer!==void 0,d=>{const p=o.resolvePoint(d.at);return p===null?null:{...d,at:p}})},c=o.cyclicIds();c.length>0&&a?.(c);const u=o.missingRefIds();return u.length>0&&i?.(u),s},ct=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,yS=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),vS=800,Ci=400,bS=.75,SS=.875,xS=4,AS=e=>Math.max(1,(e-Ci)/(vS-Ci)+1),IS=(e,t)=>{const r=AS(t),n=e*xS;return{strokeWidth:Math.min(e,e*bS*r),arrowheadLength:Math.min(n,n*SS*r)}},Kt=Math.PI/4,on=1.5,TS=2,LS=({start:e,end:t})=>`M ${e.x} ${e.y} L ${t.x} ${t.y}`,Vi=(e,t,r)=>{if(r<=0)return"";const{start:n,end:a}=t,i=e==="start"?n.x:a.x,o=e==="start"?n.y:a.y,s=e==="start"?Math.atan2(n.y-a.y,n.x-a.x):Math.atan2(a.y-n.y,a.x-n.x);return`M ${i} ${o} L ${i-r*Math.cos(s-Kt)} ${o-r*Math.sin(s-Kt)} M ${i} ${o} L ${i-r*Math.cos(s+Kt)} ${o-r*Math.sin(s+Kt)}`},wS=(e,t)=>e==="solid"?null:e==="dotted"?`0 ${t*TS}`:`${t*on} ${t*on*2}`,ES=(e,t,r)=>e==="dashed"&&r?t*on:0,RS=64,CS=({arrow:e,style:t,panelWidth:r,panelHeight:n})=>{const a={width:r,height:n},i={start:rr(e.start,a),end:rr(e.end,a)};if(i.start.x===i.end.x&&i.start.y===i.end.y)return null;const{strokeWidth:o,arrowheadLength:s}=IS(t.strokeWidth,r),c=Math.hypot(i.end.x-i.start.x,i.end.y-i.start.y),u=VS(s,c),d=e.startArrowheadStyle==="line-arrow",p=e.endArrowheadStyle==="line-arrow",m=d||p?u*Math.sin(Math.PI/4):0;return{id:e.id,linePath:LS(i),startArrowheadPath:d?Vi("start",i,u):"",endArrowheadPath:p?Vi("end",i,u):"",strokeWidth:o,dashArray:wS(t.lineType,o),startX:i.start.x,startY:i.start.y,endX:i.end.x,endY:i.end.y,dashOffset:ES(t.lineType,o,d),arrowheadExtent:m}},VS=(e,t)=>Math.min(e,t*e/RS);function DS(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(p=>p.transformType==="filter"&&p.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let o,s,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")o="color",s=a.options.variableName,c=a.options.value;else if(i!==null)o="y",s=i,c=i;else continue;const u=_S(e,o,s);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d,layerId:u.id,groupValue:c})}return r}function _S(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 hl=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),PS=0,OS=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:hl(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:PS})),MS=9,kS=8,NS=2,fl=e=>typeof e=="string"?e:gl(e),gl=e=>e.text!==void 0?e.text:e.content?e.content.map(gl).join(""):"",Di={top:"bottom",bottom:"top",right:"left",left:"right"};function BS(e,t,r){return r.type==="polar"?GS(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function sn(e,t,r){const{width:n,height:a}=r;switch(t){case"top":return{x:e.x-n/2,y:e.y-9-a,width:n,height:a};case"bottom":return{x:e.x-n/2,y:e.y+9,width:n,height:a};case"right":return{x:e.x+9,y:e.y-a/2,width:n,height:a};case"left":return{x:e.x-9-n,y:e.y-a/2,width:n,height:a}}}function _i(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function FS(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 $S(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 GS(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[o,s]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[o,Di[o],s,Di[s]]}function US(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:o}=e,s=[...t.map(d=>{const{id:p,at:m}=d;return Pi(p,"pinned-number",m,o(d),i,n)}),...r.map(({id:d,at:p,content:m})=>Pi(d,"comment",p,fl(m),i,n))];s.sort((d,p)=>d.anchorPx.x-p.anchorPx.x||d.anchorPx.y-p.anchorPx.y);const c=[],u=[];for(const d of s){if(!d.inView){c.push(Oi(n,d,"top"));continue}const p=Oi(n,d,WS(n,d,a,u));c.push(p),u.push(p.miniRect)}return c}function Pi(e,t,r,n,a,i){const o=rr(r,i);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,e,n),inView:HS(o,i)}}function HS(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function WS(e,t,r,n){const a=BS(t.anchorPx,e,r);for(const i of a){const o=sn(t.anchorPx,i,t.mini);if(_i(o,e)&&!n.some(s=>$S(o,s)))return i}for(const i of a)if(_i(sn(t.anchorPx,i,t.mini),e))return i;return"top"}function Oi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:FS(e,sn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var KS=(e,t,r)=>e.anchor.layerId!==t.anchor.layerId||!l.areDataValuesEqual(e.anchor.groupValue??null,t.anchor.groupValue??null)||r.start===void 0||r.start!==r.end?null:r.start,zS=100,YS=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,o=!0,s=0;for(;o;){o=!1,s++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const p=u.y+a,m=d.y-a;if(p>m){o=!0,i=!0;const h=(p-m)/2+1;u.y-=h,d.y+=h,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(s>zS)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}},qS=(e,t)=>yl(e,t,{variables:vl(e),allowNull:!1}),yl=(e,t,{variables:r,allowNull:n})=>{const a=Do(e),i=[];for(const s of r){const c=a(t,s);if(c===null&&!n)return null;i.push({variable:s,eq:c})}const[o]=i;return o===void 0?null:i.length===1?o:{and:i}},vl=e=>{const t=yn(e)?be(e.data,e.mapping):[],r=gn(e),n=r===null?t:[...t,r],a=ke(e);return a===l.GROUP_VARIABLES.group?[...new Set(n)]:[...new Set([a,...n])]},br=e=>e!=="data-point",jS=(e,t)=>{switch(t){case"series":{const r=be(e.data,e.mapping);return r.length===0?Mi(e):{variables:r,allowNull:!0}}case"x-value":{const r=St(e.mapping);return r===null?null:{variables:[r],allowNull:!0}}case"data-point":return Mi(e)}},Mi=e=>typeof e.identityKey=="object"?{variables:[e.identityKey.variable],allowNull:!0}:e.identityKey==="index"?null:{variables:vl(e),allowNull:!1},bl=({layer:e,target:t,parsingLocale:r})=>{if(t.layerId!==e.id)return[];if(ce(t.predicate,e.data).length>0)return[];const n=le(t.predicate,Be(e,r));return br(t.scope)?ZS(e,n,t.scope):XS(e,n)},XS=(e,t)=>{const r=[];let n=0;for(const a of e.data)t(a)&&r.push(n),n+=1;return r},ZS=(e,t,r)=>{const n=St(e.mapping),a=[],i=new Set;for(const s of e.data){const c=pt(r,s,n);a.push(c),t(s)&&i.add(c)}const o=[];return a.forEach((s,c)=>{i.has(s)&&o.push(c)}),o},JS=({layer:e,observationIndex:t,scope:r,parsingLocale:n})=>{const a=e.data.getAt(t);if(a===null)return null;const i=nx(e,a,r);if(i===null)return null;const o={kind:"observations",layerId:e.id,scope:r,predicate:i};return rx(o,e,a,t,n)?o:null},QS=({layer:e,scope:t,variable:r,value:n,parsingLocale:a})=>{const i={kind:"observations",layerId:e.id,scope:t,predicate:{variable:r,eq:n}};return tx(i,e,a)?i:null},ex=e=>e.identityKey==="x-group"?"series":be(e.data,e.mapping).length===0?"data-point":"series",tx=(e,t,r)=>{if(ce(e.predicate,t.data).length>0)return!1;const n=le(e.predicate,Be(t,r));for(const a of t.data)if(n(a))return!0;return!1},rx=(e,t,r,n,a)=>ce(e.predicate,t.data).length>0?!1:le(e.predicate,Be(t,a))(r)?!0:br(e.scope)?bl({layer:t,target:e,parsingLocale:a}).includes(n):!1,nx=(e,t,r)=>{const n=jS(e,r);return n===null?null:yl(e,t,n)},ra=(e,t)=>{if(t.kind==="circle"){const n=e.x-t.center.x,a=e.y-t.center.y;return n*n+a*a<=t.radius*t.radius}const{rect:r}=t;return e.x>=r.x&&e.x<=r.x+r.width&&e.y>=r.y&&e.y<=r.y+r.height},ax=(e,t)=>{for(const r of t)if(ra(e,r.shape))return r;return null},ix=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},ox=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>sx(r,t[n])),sx=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&lx(e.shape,t.shape)&&cx(e.tooltip,t.tooltip),lx=(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},cx=(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},ux=100,dx=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:ux}),px=(e,t)=>ra(e,{kind:"circle",center:t.center,radius:t.radius}),mx=(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&&hx(e.target,t.target),hx=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,fx=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Be(e,n),i=gx(e,r);return t.filter(o=>{if(o.layerId!==void 0&&o.layerId!==e.id||ce(o.predicate,e.data).length>0)return!1;const s=le(o.predicate,a);return s(r)?!0:br(o.scope)&&i(o.scope).some(s)})},gx=(e,t)=>{const r=St(e.mapping),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const o=pt(a,t,r),s=[];for(const c of e.data)pt(a,c,r)===o&&s.push(c);return n.set(a,s),s}},qt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const o=e.data.size(),s=vt(e);for(let c=0;c<o;c+=1){const u=t+c*r,d=i?yx(u,o):u;if(d<0||d>=o)break;const p=e.data.getAt(d);if(p===null||!n(p,d))continue;const m=s(p);if(m!==null&&!a.some(h=>Xe(m,h)))return{anchor:m,observation:p,observationIndex:d}}return null},Sl=(e,t)=>{const r=Vo(e);let n=0;for(const a of e.data){if(r(a,t))return n;n+=1}return-1},Xe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),yx=(e,t)=>(e%t+t)%t,xl=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.spatialKind==="cells")return null;const n=ke(e),a=Sl(e,t),i=e.data.getAt(a);if(i===null)return null;const o=re(i),s=m=>l.areDataValuesEqual(re(m),o),c=[t],u=qt({layer:e,excluding:c,from:a+1,step:1,accepts:s});if(u!==null)return{start:t,end:u.anchor};const d=qt({layer:e,excluding:c,from:a-1,step:-1,accepts:s});if(d!==null)return{start:d.anchor,end:t};const p=qt({layer:e,excluding:c,from:0,step:1,accepts:m=>!s(m)&&l.areDataValuesEqual(m[n]??null,t.anchorValue)});return p!==null?{start:t,end:p.anchor}:null},vx=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers){const n=vt(r);for(const a of r.data){const i=n(a);if(i===null)continue;const o=xl({layer:r,at:i,coordSystem:e.coordSystem});if(o!==null&&!t.some(s=>bx(s,o)))return o}}return null},bx=(e,t)=>Xe(e.start,t.start)&&Xe(e.end,t.end)||Xe(e.start,t.end)&&Xe(e.end,t.start),Sx=(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}},xx=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:o})=>{const s=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(s===null)return null;const c=o??e.createLayerMeasurement(t);if(c===null)return null;const u=Mo(t,r,c);if(u===null)return null;const d=vt(t)(r);return d===null?null:{...s,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Ax=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const o=ke(e),s=Sl(e,t),c=e.data.getAt(s);if(c===null)return null;const u=Ix(c),d=n==="main"?u:h=>!u(h)&&l.areDataValuesEqual(h[o]??null,t.anchorValue),p=qt({layer:e,excluding:[t,r],from:s+a,step:a,accepts:(h,f)=>d(h)&&i(h,f)!==null,cycles:n!=="main"});if(p===null)return null;const m=i(p.observation,p.observationIndex);return m===null?null:{...p,point:m}},Ix=e=>{const t=re(e);return r=>l.areDataValuesEqual(re(r),t)};function Tx({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=N({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Lx=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const o=a??n;return e.kind==="grandTotal"?wx(e,o,r):Ex(e,t,o,r,i)},wx=(e,t,r)=>({kind:"grandTotal",value:N({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Ex=(e,t,r,n,a)=>{const i=N({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),o=e.items.length>1;return{kind:"perGroup",items:e.items.map(s=>{const c=N({valueFormat:s.valueFormat,locale:r,numberFormat:n}),u=N({valueFormat:s.groupLabelFormat,locale:r,numberFormat:n}),d=Yn({valueFormat:s.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),p=s.label??u(s.value);return{swatch:s.swatch,label:Dx(t,o,p,a),value:s.aggregate===null?null:c(s.aggregate),caption:Vx(s.caption,d),comparison:Rx(s.comparison,d,i,a)}})}},Rx=(e,t,r,n)=>e===null?null:{direction:Cx(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},Cx=e=>e>0?"up":e<0?"down":"flat",Vx=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Dx=(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}},_x=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Px(i,a,t))},Px=(e,t,r)=>({...e,items:e.items.map(n=>{const a=N({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function na(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function Ox(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Mx=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,o=(i?fn:ot)(r.data,r.mapping)(a);return o===null?null:N({valueFormat:na(e,i?Le(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(o)},kx=4,Nx=4,Bx=12,Fx=4,$x=(e,t)=>{const{value:r,caption:n,comparison:a,swatch:i,label:o}=e;return[{role:"valueRow",gap:4,segments:Nr([zt("value",r??"–"),zt("caption",n)])},{role:"trendRow",gap:4,ariaLabel:a===null?void 0:Wx(a),segments:Nr([Ux(a),Hx(a),zt("trendReference",a?.reference??null)])},{role:"groupRow",gap:4,segments:Nr([Gx(i,t),zt("label",o)])}].filter(s=>s.segments.length>0)},zt=(e,t)=>t===null?null:{kind:"text",textRole:e,text:t},Gx=(e,t)=>e===null?null:{kind:"swatch",swatch:e,size:t},Ux=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Hx=e=>e===null?null:{kind:"text",textRole:"trendPercentage",text:e.percentage,trendDirection:e.direction},Wx=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}`}},Nr=e=>e.filter(t=>t!==null),Sr=e=>e==="catmull-rom"?_e.curveCatmullRom:_e.curveLinear,Kx=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},zx=(e,t)=>{const r=Sr(t.interpolate),n=(0,_e.area)().curve(r),a=(0,_e.line)().curve(r);if(e.mainAxis==="y"){const i=c=>de(_(c)??0),o=c=>j(c)??0,s=c=>X(c)??k(c)??0;n.y(i).x0(o).x1(s),a.y(i).x(s)}else{const i=c=>k(c)??0,o=c=>de(U(c)??0),s=c=>de($(c)??_(c)??0);n.x(i).y0(o).y1(s),a.x(i).y(s)}if(t.missingValues==="gap"){const i=o=>k(o)!==null&&_(o)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},Yx=(e,t)=>t!=="connect"?e:e.filter(r=>k(r)!==null&&_(r)!==null),aa={none:0,xs:2,sm:4,md:8,lg:12,xl:16},ia=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return aa[e.borderRadius??"sm"]},qx=e=>{const t=ia(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},jx=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Al=(e,t)=>{const r=j(t),n=X(t),a=U(t),i=$(t)??_(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let o=r,s=n-r;return s<0&&(o+=s,s=-s),{x:o,y:1-i,width:s,height:i-a}},Il=(e,t)=>e==="x"?`${te(t.x)}-${te(t.width)}`:`${te(t.y)}-${te(t.height)}`,Xx=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}},Zx=e=>{const t=(0,_e.line)().x(r=>k(r)??0).y(r=>de(_(r)??0)).curve(Sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Tl),t},Jx=e=>{const t=(0,_e.area)().x(r=>k(r)??0).y0(()=>1).y1(r=>de(_(r)??0)).curve(Sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Tl),t},Qx=(e,t)=>t!=="connect"?e:e.filter(r=>k(r)!==null&&_(r)!==null),Tl=e=>k(e)!==null&&_(e)!==null,Ll=(0,_e.arc)().cornerRadius(e=>e.cornerRadius??0);Ll.digits(8);var eA=200,tA=e=>Ll(e)??void 0,rA=(e,t)=>e==="full"?Math.max(0,t)/2:aa[e??"sm"]/eA,wl=(e,t)=>e==="x"?`${te(t.startAngle)}-${te(t.endAngle)}`:e==="y"?`${te(t.innerRadius)}-${te(t.outerRadius)}`:"sweep",nA=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}},aA=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],xr=(e,t,r)=>{const n=ot(e,t);return a=>{const i=re(a)??"default",o=n(a);return`${r}-${i}${o!==null&&o!==""?`-${o}`:""}`}},iA=(e,t,r)=>{const n=ot(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},oA=(e,t,r)=>{const n=ot(e,t),a=fn(e,t),i=new Map;return o=>{const s=n(o),c=a(o),u=s!==null&&s!==""&&c!==null&&c!==""?`${r}-${s}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},sA=()=>(e,t)=>Et(e)??`default-${t}`,ki=2,lA=(e,t)=>{const r=l.extractVariableName(e.mapping.color);if(t!==void 0&&r!==null&&e.data.hasVariable(r)){const n=e.data.getValues(r).findIndex(a=>l.areDataValuesEqual(a,t));if(n!==-1)return e.data.getAt(n)??void 0}return e.data.getFirst()??void 0},oa=(e,t,r,n)=>{const a=e.get("alpha",r);if(!Ps(t,"bar"))return{alpha:a};const i=n.width-ki,o=n.height-ki,s=ia({borderRadius:e.get("borderRadius",r),mainAxis:"x",bounds:{width:i,height:o}});return{alpha:a,cornerRadiusPx:Math.min(s,Math.min(i,o)/2)}};function sa(e,t){let r=0,n=e;for(;r<n;){const a=r+n>>>1;t(a)?n=a:r=a+1}return r}function cA(e,t,r){return sa(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>t})}function uA(e,t,r){return sa(e.length,n=>{const a=e[n];return a!==void 0&&r(a)>=t})}function la(e,t,r,n){const a=e==="x";return{mainDistance:Math.abs(t)*(a?n:1),crossDistance:Math.abs(r)*(a?1:n)}}function ca(e,t,r){return Math.hypot(e*r,t)}function pe(e,t,r){return e<t?t-e:e>r?e-r:0}function ne(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const o=e[i];if(o===void 0)continue;const s=t(o);if(r&&s===0)return o;s<a&&(n=o,a=s)}return n}function dA(e,t){const r=t.height,n=Math.min(t.width,t.height)/2;return{cartesian:Ni(e,r),polar:Ni(e,n)}}function Rt(e,t){return e<=t.on.point}function ft({mainDistance:e,crossDistance:t},r){return e<=r.near.main&&t<=r.near.cross}function Ni({on:e,near:t},r){return{on:{edge:e.edge/r,stroke:(e.stroke??e.edge)/r,point:(e.point??e.edge)/r},near:{main:t.main/r,cross:(t.cross??t.main)/r}}}function pA(e,t,r,n,a){if(e.points.length===0)return null;const i=e.delaunay;if(!i)return null;const o=i.find(t.x*r,t.y,n??void 0),s=e.points[o];if(!s)return null;const c=El(e,s,t,r);return a===void 0||Rt(c.distance,a)||ft(c,a)?c:hA(e,t,r,a)??c}function mA(e,t){if(e.projection==="polar"||e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function hA(e,t,r,n){const{mainAxis:a,byMain:i}=e,o=et(a,t).main,s=a==="x"?n.near.main/r:n.near.main,c=uA(i,o-s,Bi(a)),u=cA(i,o+s,Bi(a));let d=null;for(let p=c;p<u;p+=1){const m=i[p];if(m===void 0)continue;const h=El(e,m,t,r);ft(h,n)&&(d===null||h.crossDistance<d.crossDistance)&&(d=h)}return d}function Bi(e){return t=>et(e,t).main}function El(e,t,r,n){const{main:a,cross:i}=et(e.mainAxis,r),{main:o,cross:s}=et(e.mainAxis,t);return{...la(e.mainAxis,o-a,s-i,n),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:ca(t.x-r.x,t.y-r.y,n)}}function Rl(e,t){return e.buckets[fA(e,t)]??null}function fA(e,t){return Dl(e.buckets,t,r=>r.main)}function gA(e,t){return Vl(e.bands,t,r=>r.bandCenter)}function Cl(e,t){return Vl(e.columns,t,r=>r.mainMid)}function Vl(e,t,r){return e[Dl(e,t,r)]??null}function Dl(e,t,r){if(e.length===0)return-1;const n=sa(e.length,o=>{const s=e[o];return s!==void 0&&r(s)>=t}),a=e[n-1],i=e[n];return a?i&&Math.abs(r(i)-t)<Math.abs(r(a)-t)?n:n-1:n}function yA(e,t){return{group:vA(e),related:AA(e,t)}}function vA(e){switch(e.kind){case"buckets":{const t=e.match.index;return l.isStackedPosition(t.position)?bA(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return l.isStackedPosition(t.position)?SA(t.layerId,r,n.pointIndex):xA(t.bandByColumn,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function bA(e,t,r){const n=[];for(const a of t.entries)a.pointIndex!==r&&n.push({anchored:!0,layerId:e,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation});return n}function SA(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(ua(e,a));return n}function xA(e,t,r,n){const a=e.get(r);if(!a)return[];const i=[];for(const o of a.columns)for(const s of o.rects)s.pointIndex!==n&&i.push(ua(t,s));return i}function AA(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||TA(r,i,e.match.hit);continue}e.kind==="buckets"&&(l.isStackedPosition(i.position)||i.kind==="buckets"&&IA(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function IA(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&jt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function TA(e,t,r){switch(t.kind){case"buckets":{const n=Rl(t,Z(t.mainAxis,r));if(!n)return;const a=jt(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=gA(t,Z(t.mainAxis,r));if(!n)return;const a=jt(e,t.layerId);for(const i of n.columns)for(const o of i.rects)a.push(ua(t.layerId,o));return}case"points":{const n=mA(t,r);if(!n)return;jt(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 jt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function ua(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 _l(e,t,r){const{columns:n,bands:a,bandByColumn:i}=LA(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a,bandByColumn:i}}function LA(e,t){const r=EA(e,t);r.sort((c,u)=>c.mainMid-u.mainMid);const n=new Map,a=new Map,i=new Map;for(const c of r){const u=te(c.mainMid);let d=n.get(u);if(!d){d={mainMid:c.mainMid,rects:[]},n.set(u,d);const p=te(c.bandCenter);let m=a.get(p);m||(m={bandCenter:c.bandCenter,columns:[],mainMin:1/0,mainMax:-1/0,crossMin:1/0,crossMax:-1/0},a.set(p,m)),m.columns.push(d),i.set(d,m)}d.rects.push(c.entry),wA(i.get(d),c.entry,t)}const o=[...n.values()].sort((c,u)=>c.mainMid-u.mainMid),s=[...a.values()].sort((c,u)=>c.bandCenter-u.bandCenter);for(const c of s)c.columns.sort((u,d)=>u.mainMid-d.mainMid);return{columns:o,bands:s,bandByColumn:i}}function wA(e,t,r){if(e===void 0)return;const n=r==="x",a=n?t.xMin:t.yMin,i=n?t.xMax:t.yMax,o=n?t.yMin:t.xMin,s=n?t.yMax:t.xMax;e.mainMin=Math.min(e.mainMin,a),e.mainMax=Math.max(e.mainMax,i),e.crossMin=Math.min(e.crossMin,o),e.crossMax=Math.max(e.crossMax,s)}function EA(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=t==="y",c=s?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let p=0;for(const m of r){const h=n[p],f=a[p],y=i[p],v=o[p];if(!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(y)||!l.isDefined(v)){p++;continue}const g=s?(y+v)/2:(h+f)/2,b=u?.[p]??g;d.push({mainMid:g,bandCenter:b,entry:{pointIndex:p,xMin:Math.min(h,f),xMax:Math.max(h,f),yMin:Math.min(y,v),yMax:Math.max(y,v),observation:m}}),p++}return d}var RA=1e-9,Fi=-1;function Pl(e,t,r){const n=CA(e,t,r),a=n.map(o=>o.entry);n.sort((o,s)=>o.main-s.main);const i=[];for(const o of n){const s=i[i.length-1];s&&Math.abs(s.main-o.main)<=RA?s.entries.push(o.entry):i.push({main:o.main,entries:[o.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:i,entries:a}}function CA(e,t,r){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(l.POSITION_VARIABLES.x),i=n.hasVariable(l.POSITION_VARIABLES.y);if(!a||!i)return[];const o=n.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=n.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),c=t==="y",u=c?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,d=c?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,p=l.isStackedPosition(e.position),m=n.hasVariable(u)?n.getValues(u,{type:"numeric"}):null,h=n.hasVariable(d)?n.getValues(d,{type:"numeric"}):null,f=n.hasVariable(l.GROUP_VARIABLES.group)?n.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,y=new DA(VA(e)),v=new Map,g=[];let b=0;for(const I of n){const L=o[b],w=s[b],E=f?.[b]??null,R=_A(v,E);if(!l.isDefined(L)||!l.isDefined(w)){y.skip(E),b+=1;continue}const V=c?w:L,T=m?.[b],D=p?h?.[b]:void 0;if(p&&(!l.isDefined(T)||!l.isDefined(D))){y.skip(E),b+=1;continue}const O=D??ve(t,{x:L,y:w}),ie={pointIndex:b,...c?{x:O,y:w}:{x:L,y:O},groupKey:E,paintOrder:R,...e.spatialKind==="filled-buckets"&&l.isDefined(T)&&{fill:PA(T,O)},previousAt:Fi,nextAt:Fi,observation:I};y.append(E,{entry:ie,at:g.length}),g.push({main:V,entry:ie}),b+=1}return r==="polar"&&y.close(),g}function VA(e){return"missingValues"in e.params&&e.params.missingValues==="gap"}var DA=class{constructor(e){this.breaksAtNull=e,this.firstByGroup=new Map,this.lastByGroup=new Map,this.brokenGroups=new Set}append(e,t){const r=this.lastByGroup.get(e);r!==void 0&&(r.entry.nextAt=t.at,t.entry.previousAt=r.at),this.firstByGroup.has(e)||this.firstByGroup.set(e,t),this.lastByGroup.set(e,t)}skip(e){this.breaksAtNull&&(this.lastByGroup.delete(e),this.brokenGroups.add(e))}close(){for(const[e,t]of this.firstByGroup){const r=this.lastByGroup.get(e);r===void 0||r===t||this.brokenGroups.has(e)||(r.entry.nextAt=t.at,t.entry.previousAt=r.at)}}};function _A(e,t){const r=e.get(t);if(r!==void 0)return r;const n=e.size;return e.set(t,n),n}function PA(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function Ol(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:OA(e,t)}}function OA(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const p of n)if(!r.hasVariable(p))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const p of r){const m=a[d],h=i[d],f=o[d],y=s[d];if(!l.isDefined(m)||!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(y)){d++;continue}if(c&&!Et(p)){d++;continue}u.push({pointIndex:d,xMin:m,xMax:h,yMin:f,yMax:y,observation:p}),d++}return u}function ln(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function MA(e,t,r){const n=kl(e),a={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",mainAxis:t,points:n,byMain:NA(t,n),delaunay:null,delaunayAspectRatio:null};return Ml(a,r),a}function kA(e){const t=kl(e).map(r=>{const n=ye(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t}}function Ml(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Wd.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function NA(e,t){const r=n=>Z(e,n);return[...t].sort((n,a)=>r(n)-r(a))}function kl(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const o of t){const s=r[i],c=n[i];l.isDefined(s)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:s,y:c,observation:o}),i+=1}return a}function Nl(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:BA(e)}}function Bl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function BA(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 $i(e,t,r){return t.type==="polar"?FA(e,t.bandAxis):$A(e,t.mainAxis,r)}function FA(e,t){switch(e.spatialKind){case"points":return kA(e);case"buckets":case"filled-buckets":return Pl(e,"x","polar");case"rects":return t===null?Ol(e,"polar"):_l(e,t,"polar");case"cells":return ln(e);case"noop":return ln(e);case"render-hit-test":return Nl(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function $A(e,t,r){switch(e.spatialKind){case"points":return MA(e,t,r);case"buckets":case"filled-buckets":return Pl(e,t,"cartesian");case"rects":return _l(e,t,"cartesian");case"cells":return Ol(e,"cartesian");case"noop":return ln(e);case"render-hit-test":return Nl(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function GA(e,t,r){if(e.columns.length===0)return null;const n=Cl(e,Z(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=l.isStackedPosition(e.position)?HA(a,t,e.mainAxis):WA(a,t,r),o=Fl(i,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:n,distance:o,...UA(e,n,t,r)}}function UA(e,t,r,n){const a=e.bandByColumn.get(t);if(a===void 0)return{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY};const{main:i,cross:o}=et(e.mainAxis,r),s=pe(i,a.mainMin,a.mainMax),c=pe(o,a.crossMin,a.crossMax);return la(e.mainAxis,s,c,n)}function HA(e,t,r){const n=ve(r,t);return ne(e,i=>KA(i,r,n),{shortCircuitOnZero:!0})}function WA(e,t,r){return ne(e,a=>Fl(a,t,r))}function Fl(e,t,r){return ca(pe(t.x,e.xMin,e.xMax),pe(t.y,e.yMin,e.yMax),r)}function KA(e,t,r){return pe(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function zA(e,t,r){const n=r.x-t.x,a=r.y-t.y,i=n*n+a*a;if(i===0)return Math.hypot(e.x-t.x,e.y-t.y);const o=((e.x-t.x)*n+(e.y-t.y)*a)/i,s=Math.max(0,Math.min(1,o));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*a))}function YA(e,t,r){const{main:n,cross:a}=et(e.mainAxis,t),i=Rl(e,n);if(i===null)return null;const o=i.entries.map(f=>({entry:f,crossAtCursor:jA(e,f,n)}));if(!l.isNonEmptyArray(o))return null;const s=Gl(o.filter(f=>ZA(e,f.entry,n,a)),f=>f.entry),{entry:c}=s??ne(o,f=>Math.abs(f.crossAtCursor-a)),u=ca(c.x-t.x,c.y-t.y,r),d=f=>({x:f.x*r,y:f.y}),p=Ar(e,c).map(d),m=$l(d(t),d(c),p,u),h=la(e.mainAxis,i.main-n,ve(e.mainAxis,c)-a,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:c.x,y:c.y,observation:c.observation},index:e,bucket:i,distance:s===void 0?u:0,vertexDistance:u,insideFill:s!==void 0,strokeDistance:s===void 0?m:0,...h}}function qA(e,t,r){return ne(e,a=>Math.abs(ve(r,a)-t))}function $l(e,t,r,n){const a=r.map(i=>zA(e,t,i));return Math.min(n,...a)}function Ar(e,t){return[e.entries[t.previousAt],e.entries[t.nextAt]].filter(l.isDefined)}function Gl(e,t){return e.reduce((r,n)=>r===void 0||t(n).paintOrder>t(r).paintOrder?n:r,void 0)}function jA(e,t,r){const{mainAxis:n}=e,a=r===Z(n,t)?null:Ul(e,t,r);return a===null?ve(n,t):XA(t,a,n,r)}function XA(e,t,r,n){const a=Z(r,e),i=(n-a)/(Z(r,t)-a),o=ve(r,e);return o+(ve(r,t)-o)*i}function Ul(e,t,r){const{mainAxis:n}=e,a=Z(n,t),i=o=>Math.sign(Z(n,o)-a)===Math.sign(r-a);return Ar(e,t).find(i)??null}function ZA(e,t,r,n){const a=JA(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function JA(e,t,r){if(t.fill===void 0)return null;const{mainAxis:n}=e,a=Z(n,t);if(r===a)return t.fill;const i=Ul(e,t,r);if(i?.fill===void 0)return null;const o=(r-a)/(Z(n,i)-a);return{min:t.fill.min+(i.fill.min-t.fill.min)*o,max:t.fill.max+(i.fill.max-t.fill.max)*o}}function QA(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e,distance:0,mainDistance:0,crossDistance:0};return null}function eI(e,t,r){if(e.columns.length===0)return null;const n=mn(t,r),{angle:a,radius:i}=n,o=e.mainAxis==="x",s=o?nI(e.columns,a):Cl(e,i),c=s?.rects??[];if(!s||!l.isNonEmptyArray(c))return null;const u=o?aI(c,i):iI(c,a),d=tI(u,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:(u.xMin+u.xMax)/2,y:(u.yMin+u.yMax)/2,observation:u.observation},index:e,column:s,distance:d,...rI(e,s,n)}}function tI(e,{angle:t,radius:r}){const n=nr(t,e.xMin,e.xMax),a=pe(r,e.yMin,e.yMax);return Math.hypot(n*r,a)}function nr(e,t,r){return Qt(e,t,r)?0:Math.min(Qe(e,t),Qe(e,r))}function rI(e,t,{angle:r,radius:n}){const a=e.bandByColumn.get(t);return a===void 0?{mainDistance:Number.POSITIVE_INFINITY,crossDistance:Number.POSITIVE_INFINITY}:e.mainAxis==="x"?{mainDistance:nr(r,a.mainMin,a.mainMax)*n,crossDistance:pe(n,a.crossMin,a.crossMax)}:{mainDistance:pe(n,a.mainMin,a.mainMax),crossDistance:nr(r,a.crossMin,a.crossMax)*n}}function nI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(t,r.mainMid)):null}function aI(e,t){return ne(e,r=>pe(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function iI(e,t){return ne(e,r=>nr(t,r.xMin,r.xMax),{shortCircuitOnZero:!0})}var Gi=1e-9;function oI(e,t,r){if(e.buckets.length===0)return null;const n=lr(t,r),{angle:a,radius:i}=sr(n.x,n.y),o=sI(e.buckets,a),s=o?.entries??[];if(!o||!l.isNonEmptyArray(s))return null;const c=Gl(s.filter(h=>lI(e,h,a,i)),h=>h),u=c??qA(s,i,e.mainAxis),d=Ui(u),p=Math.hypot(n.x-d.x,n.y-d.y),m=$l(n,d,Ar(e,u).map(Ui),p);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:u.pointIndex,x:u.x,y:u.y,observation:u.observation},index:e,bucket:o,distance:c===void 0?p:0,vertexDistance:p,insideFill:c!==void 0,strokeDistance:c===void 0?m:0,mainDistance:Qe(o.main,a)*i,crossDistance:Math.abs(i-u.y)}}function Ui(e){return ye(e.x,e.y)}function sI(e,t){return l.isNonEmptyArray(e)?ne(e,r=>Qe(r.main,t)):null}function lI(e,t,r,n){const a=cI(e,t,r);return a!==null&&n>=a.min&&n<=a.max}function cI(e,t,r){if(t.fill===void 0)return null;const n=Na(t.x,r);if(n===0)return t.fill;const a=c=>Math.sign(Na(t.x,c.x))===Math.sign(n),i=Ar(e,t).find(a);if(i?.fill===void 0)return null;const o=Hi(r,{angle:t.x,radius:t.fill.min},{angle:i.x,radius:i.fill.min}),s=Hi(r,{angle:t.x,radius:t.fill.max},{angle:i.x,radius:i.fill.max});return o===null||s===null?null:{min:o,max:s}}function Hi(e,t,r){const n=ye(t.angle,t.radius),a=ye(r.angle,r.radius),i={x:a.x-n.x,y:a.y-n.y};if(Math.hypot(i.x,i.y)<Gi)return t.radius;const o=Wi(ye(e,1),i);return Math.abs(o)<Gi?null:Wi(n,i)/o}function Wi(e,t){return e.x*t.y-e.y*t.x}function uI(e,t,r,n=!1){if(e.cells.length===0)return null;const{angle:a,radius:i}=mn(t,r);for(const u of e.cells)if(!(i<u.yMin||i>u.yMax)&&Qt(a,u.xMin,u.xMax))return Ki(e,u,0);if(!n)return null;const o=e.cells.filter(u=>Qt(a,u.xMin,u.xMax));if(!l.isNonEmptyArray(o))return null;const s=u=>pe(i,u.yMin,u.yMax),c=ne(o,s);return Ki(e,c,s(c))}function Ki(e,t,r){return{hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation},index:e,distance:r,mainDistance:0,crossDistance:r}}function dI(e,t,r,n){if(!l.isNonEmptyArray(e.points))return null;const a=lr(t,r),i=zi(e,ne(e.points,s=>Hl(s,a)),a);if(n===void 0||Rt(i.distance,n)||ft(i,n))return i;const o=e.points.map(s=>zi(e,s,a)).filter(s=>ft(s,n));return l.isNonEmptyArray(o)?ne(o,s=>s.crossDistance):i}function zi(e,t,r){const{angle:n,radius:a}=sr(r.x,r.y);return{mainDistance:Qe(t.x,n)*a,crossDistance:Math.abs(a-t.y),hit:{anchored:!0,layerId:e.layerId,pointIndex:t.pointIndex,observationIndex:t.observationIndex,x:t.x,y:t.y,observation:t.observation},index:e,distance:Math.sqrt(Hl(t,r))}}function Hl(e,t){const r=e.unitX??ye(e.x,e.y).x,n=e.unitY??ye(e.x,e.y).y,a=r-t.x,i=n-t.y;return a*a+i*i}var pI=.05;function mI({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a,tolerance:i}){const o={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},s={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1},c={match:null,distance:Number.POSITIVE_INFINITY,paintOrder:-1};for(const[u,d]of e.entries()){if(d.kind==="render-hit-test"){const m=SI(d,t,a);if(m)return{kind:"render-hit-test",match:m};continue}if(d.projection==="polar"){const m=bI(d,t,r,i?.polar);if(m&&!Yi(m,i?.polar))return m;continue}const p=vI({layer:d,cursor:t,aspectRatio:r,warmStarts:n,tolerance:i?.cartesian});if(!(!p||Yi(p,i?.cartesian))){if(p.kind==="banded"||p.kind==="enclosure"){const m=p.match.distance;m<o.distance&&(o.match=p,o.distance=m,o.paintOrder=u);continue}if(p.kind==="buckets"&&p.match.insideFill){s.match=p,s.distance=0,s.paintOrder=u;continue}p.match.distance<c.distance&&(c.match=p,c.distance=p.match.distance,c.paintOrder=u)}}return Wl(c,fI(s,o)).match}function hI(e,t){if(e.kind==="render-hit-test")return{intersects:!0,onPoint:!1};const r=gI(e,t),n=e.kind==="buckets"&&Rt(e.match.vertexDistance,r);return{intersects:Kl(e,r),onPoint:n}}function fI(e,t){return e.match!==null&&t.match!==null&&e.distance===0&&t.distance===0?e.paintOrder>t.paintOrder?e:t:Wl(e,t)}function Wl(e,t){return e.match===null?t:t.match===null||e.distance<=t.distance+pI?e:t}function Kl(e,t){switch(e.kind){case"banded":case"enclosure":return e.match.distance<=t.on.edge;case"buckets":return yI(e.match,t);case"points":return Rt(e.match.distance,t)}}function gI(e,t){return e.match.index.projection==="polar"?t.polar:t.cartesian}function yI(e,t){return e.strokeDistance<=t.on.stroke?!0:Rt(e.vertexDistance,t)}function Yi(e,t){return t===void 0?!1:!Kl(e,t)&&!ft(e.match,t)}function vI({layer:e,cursor:t,aspectRatio:r,warmStarts:n,tolerance:a}){switch(e.kind){case"buckets":{const i=YA(e,t,r);return i?{kind:"buckets",match:i}:null}case"banded":{const i=GA(e,t,r);return i?{kind:"banded",match:i}:null}case"points":{const i=pA(e,t,r,n.get(e.layerId)??null,a);return i?{kind:"points",match:i}:null}case"enclosure":{const i=QA(e,t);return i?{kind:"enclosure",match:i}:null}case"noop":return null}}function bI(e,t,r,n){switch(e.kind){case"enclosure":{const a=uI(e,t,r,n!==void 0);return a?{kind:"enclosure",match:a}:null}case"points":{const a=dI(e,t,r,n);return a?{kind:"points",match:a}:null}case"buckets":{const a=oI(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=eI(e,t,r);return a?{kind:"banded",match:a}:null}case"noop":case"render-hit-test":return null}}function SI(e,t,r){const n=r.get(e.layerId);if(!n)return null;const a=n({x:t.x,y:1-t.y});if(!a)return null;const i=e.byKey.get(a.key);return i?{hit:Bl(e.layerId,i)}:null}var oe={primary:null,group:[],related:new Map},xI=1,AI=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.viewport=null,this.aspectRatio=xI,this.isAspectStale=!1,this.warmStarts=new Map,this.cachedState=oe,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=oe,this.layerIndexes=e.map(r=>$i(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>qi(r,t)),this.nonInteractiveLayerIds=ji(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const o=this.layerIndexes[i],s=this.layerRefs[i];!o||!s||r.set(o.layerId,{index:o,ref:s})}const n=[],a=[];for(const i of e){const o=r.get(i.id),s=qi(i,t);if(o!==void 0&&TI(o.ref,s)){n.push(o.index),a.push(o.ref);continue}this.warmStarts.delete(i.id),n.push($i(i,t,this.aspectRatio)),a.push(s)}for(const i of this.warmStarts.keys())e.some(o=>o.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=ji(e),this.invalidateCache()}setViewport(e){if(e.width<=0||e.height<=0)return;this.viewport=e;const t=e.width/e.height;t!==this.aspectRatio&&(this.aspectRatio=t,this.isAspectStale=!0)}query(e,t,r){if(this.layerIndexes.length===0)return oe;this.reindexForAspect();const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(m=>!this.nonInteractiveLayerIds.has(m.layerId)),a=r??this.viewport,i=t!==void 0&&a!==null?dA(t,a):void 0,o=mI({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e,tolerance:i});if(!o)return this.invalidateCache(),oe;const s=o.match.hit;this.warmStarts.set(s.layerId,s.pointIndex);const c=i===void 0?void 0:hI(o,i),u=II(s,c);if(this.cachedKey===u)return this.cachedState;const{group:d,related:p}=yA(o,n);return this.cachedKey=u,this.cachedState=c===void 0?{primary:s,group:d,related:p}:{primary:s,group:d,related:p,intersection:c},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return oe;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return oe;const n=r.byKey.get(t);if(!n)return oe;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Bl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=oe,this.cachedByKeyId=null,this.cachedByKeyState=oe}reindexForAspect(){if(this.isAspectStale){this.isAspectStale=!1;for(const e of this.layerIndexes)e.kind==="points"&&e.projection==="cartesian"&&Ml(e,this.aspectRatio)}}};function II(e,t){const r=`${e.layerId}:${e.pointIndex}`;return t===void 0?r:`${r}:${t.intersects}:${t.onPoint}`}function qi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function ji(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function TI(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var LI=Math.PI*2;function wI(e,t){const r=Z(e.mainAxis,t);if(e.mainAxis==="y"){const a=Ve(de(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=Ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function EI(e,t,r){const n=e.mainAxis==="y"?_(r.observation):k(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Yl(r):zl(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const o=i/2;return e.mainAxis==="y"?{x:0,y:Ve(de(n+o)),width:"100%",height:Ve(i)}:{x:Ve(n-o),y:0,width:Ve(i),height:"100%"}}function RI(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=j(t.observation),i=X(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=U(t.observation),n=$(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+LI,innerRadius:r,outerRadius:n}}function zl(e){const t=j(e.observation),r=X(e.observation);return t===null||r===null?null:r-t}function Yl(e){const t=U(e.observation),r=$(e.observation);return t===null||r===null?null:r-t}function CI(e){return e.observationIndex??e.pointIndex}function ql(e){return e==="buckets"||e==="filled-buckets"}var Ir=.5,VI=.3,DI=.4,_I=10,PI=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?MI(e,t,r,n):kI(e,t,n):ql(e.spatialKind)&&t.type==="cartesian"?FI(e,t,n):e.spatialKind==="cells"?BI(e,n):e.spatialKind==="points"?NI(e,n):null,OI=e=>{if(ql(e.spatialKind)){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},MI=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:Ir*n.durationScale,baseline:$I(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?GI(e,t.mainAxis,n):{}}),kI=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:Ir*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?WI(e,t,r):{}}},NI=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:Ir*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?UI(e,t):{}}),BI=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:VI*t.durationScale}),FI=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:Ir*r.durationScale,axis:t.mainAxis}),$I=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[Le(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const o=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-o:o},GI=(e,t,r)=>{const n=xr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const o=Al(t,i);if(!o)continue;const s=Il(t,o),c=n(i),u=a.get(s);u?u.keys.push(c):a.set(s,{position:t==="x"?o.x:o.y,keys:[c]})}return da([...a.values()],r)},UI=(e,t)=>{const r=xr(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=HI(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return da(n,t)},HI=(e,t)=>{if(t==="main-axis")return k(e);const r=jn(e)??k(e);return r===null?null:t==="value-descending"?-r:r},WI=(e,t,r)=>{const n=xr(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:o,endAngle:s}=Jn(i),{innerRadius:c,outerRadius:u}=Qn(i);if(o===null||s===null||c===null||u===null)continue;const d=wl(t.bandAxis,{startAngle:o,endAngle:s,innerRadius:c,outerRadius:u}),p=n(i),m=a.get(d);m?m.keys.push(p):a.set(d,{position:o,keys:[p]})}return da([...a.values()],r)},da=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((s,c)=>s.position-c.position),a=Math.ceil(n.length/_I),i=Math.ceil(n.length/a),o=DI*t.durationScale/i;return n.forEach((s,c)=>{const u=Math.floor(c/a)*o;for(const d of s.keys)r[d]=u}),r},Ye=["top","right","bottom","left"],Xi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},KI={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},zI={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},YI=(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]=zI[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},o=jI(t,a),s=XI(t,a,i);return ZI(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:JI(c,o,s,i)}))},qI=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),jI=(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}}},XI=(e,t,r)=>{const{x:n,y:a,width:i,height:o}=e,s=c=>r(c)?t:0;return{top:{start:{x:n+s("topLeft"),y:a},end:{x:n+i-s("topRight"),y:a}},right:{start:{x:n+i,y:a+s("topRight")},end:{x:n+i,y:a+o-s("bottomRight")}},bottom:{start:{x:n+i-s("bottomRight"),y:a+o},end:{x:n+s("bottomLeft"),y:a+o}},left:{start:{x:n,y:a+o-s("bottomLeft")},end:{x:n,y:a+s("topLeft")}}}},ZI=e=>{const t=o=>e[o].strokeWidth>0,r=(o,s)=>{const c=(Ye.indexOf(o)+s+Ye.length)%Ye.length;return Ye[c]},n=o=>{const s=r(o,-1);return!t(s)||e[s].lineType!==e[o].lineType||e[s].strokeWidth!==e[o].strokeWidth||e[s].color!==e[o].color},a=Ye.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Ye],isClosed:!0}]:i.map(o=>{const s=[o];for(let c=r(o,1);t(c)&&!n(c);c=r(c,1))s.push(c);return{firstEdge:o,edges:s,isClosed:!1}})},JI=(e,t,r,n)=>{const a=(p,m,h)=>({type:"arc",cx:p.cx,cy:p.cy,radius:p.radius,startAngle:m,endAngle:h}),i=p=>(p.startAngle+p.endAngle)/2,o=[],s=e.firstEdge,c=e.edges[e.edges.length-1],u=Xi[s];if(!e.isClosed&&n(u)){const p=t[u],m=i(p),h=QI(p,m);o.push({type:"move",x:h.x,y:h.y}),o.push(a(p,m,p.endAngle))}else o.push({type:"move",x:r[s].start.x,y:r[s].start.y});o.push({type:"line",x:r[s].end.x,y:r[s].end.y});for(const p of e.edges.slice(1)){const m=Xi[p];if(n(m)){const h=t[m];o.push(a(h,h.startAngle,h.endAngle))}o.push({type:"line",x:r[p].end.x,y:r[p].end.y})}const d=KI[c];if(e.isClosed){if(n(d)){const p=t[d];o.push(a(p,p.startAngle,p.endAngle))}o.push({type:"close"})}else if(n(d)){const p=t[d];o.push(a(p,p.startAngle,i(p)))}return o},QI=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),eT=/^(?:https?:|mailto:)/i,tT=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:eT.test(t)},rT=({locale:e,intlOptions:t})=>K(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...Y,...t}).format(r)),nT=({locale:e,intlOptions:t})=>K(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...Y,...t}).format(r)}),ar=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Bs(e);case"date":return rT(e);case"datetime":return nT(e);case"day_month":return Us(e);case"decimal":return Fs(e);case"duration":return Fn(e);case"integer":return $s(e);case"month":return Hs(e);case"month_year":return Un(e);case"percentage":return Gs(e);case"quarter":return Hn(e);case"text":return Bn(e);case"time":return zs(e);case"weekly_date_range":return Ws(e);case"weekly_date_range_with_year":return Ks(e);case"year":return Wn(e);case"lookup":return ar({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},jl={width:12,height:12},aT=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:o,colorScheme:s,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:p}=o;if(p===null)return null;const m=c??i,h=iT(u,d);return{header:h===null?oT({layers:e,coordSystem:t,guides:n,primary:p,locale:m,numberFormat:a}):null,rows:sT({layers:e,scales:r,guides:n,hover:o,locale:m,numberFormat:a,colorScheme:s}),comment:h}};function iT(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function oT(e){if(e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null)return null;const t=na(e.guides,"x");if(!t)return null;const r=e.layers.find(i=>i.id===e.primary.layerId);if(!r)return null;const n=l.extractVariableName(r.mapping.x);if(!l.isDefined(n))return null;const a=e.primary.observation[n];return l.isDefined(a)?ar({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function sT(e){const t=[],r=e.scales.color??null,n=st({colorScheme:e.colorScheme}),a=dT({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const o=cT(i,e.hover);if(o.length===0)continue;const s=o[0];if(i.tooltip.length>0&&s){t.push(...lT(i,s,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=So(i.data,i.mapping),u=uT(o,i,r,c),d=ea({layer:i,numberFormat:e.numberFormat,locale:e.locale}),p=pT(e.guides,i),m=yt(i),h=i.mapping.color!==void 0,f=n.geomReaders(i);for(const y of u){const v=h?c(y.observation):null,g=f.get("color",y.observation),b=f.get("lineType",y.observation)??"solid",I=oa(f,i,y.observation,jl),L=h&&v!==null?a(v):p,w=m(y.observation),E=w===null?"":d(w,y.observation);t.push({swatchColor:g,geom:i.geom,swatchLineType:b,swatchAlpha:I.alpha,swatchCornerRadius:I.cornerRadiusPx,label:L,value:E,isPrimary:y===e.hover.primary,key:`${y.layerId}:${y.pointIndex}`})}}return t}function lT(e,t,r,n,a){const i=oa(n,e,t.observation,jl);return e.tooltip.map(o=>{const s=e.mapping[o.aes],c=l.extractVariableName(s),u=Q(e.data,s)(t.observation),d=N({valueFormat:bn(e,c),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:o.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",swatchAlpha:i.alpha,swatchCornerRadius:i.cornerRadiusPx,label:o.key??mr(c,r.variableLabels)??"",value:u===null?"":d(u,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${o.aes}`}})}function cT(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 uT(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,o)=>{a.set(l.getStableKey(i),o)}),e.map((i,o)=>{const s=n(i.observation),c=s===null?null:l.getStableKey(s);return{hit:i,originalIndex:o,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,o)=>i.rank===o.rank?i.originalIndex-o.originalIndex:i.rank-o.rank).map(i=>i.hit)}function dT({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:ar({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=ar({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const o=n.get(l.getStableKey(i));return o===void 0?a(i):o.label??o.format(i)}}function pT(e,t){return mr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function mT(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function hT(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var fT=(e,t)=>{const r=e.annotation.shape(t),n=r.get("borderColor");return{color:r.get("color"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth")}},gT=(e,t)=>{const r=e.annotation.arrow(t),n=r.get("borderColor");return{color:r.get("color"),strokeWidth:r.get("strokeWidth"),lineType:r.get("lineType"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),shadow:r.get("shadow")}},yT=(e,t)=>{const r=e.annotation.differenceArrow(t),n=e.annotation.differenceArrow.label(t),a=n.get("borderColor");return{color:r.get("color"),isColorAuthored:r.getSource("color")==="authored",strokeWidth:r.get("strokeWidth"),label:{...B(n,e.graph),background:n.get("background"),...a===void 0?{}:{borderColor:a},borderWidth:n.get("borderWidth"),borderRadius:n.get("borderRadius"),paddingInline:n.get("paddingInline"),paddingBlock:n.get("paddingBlock")}}},vT=(e,t)=>{const r=e.annotation.text(t),n=r.get("borderColor");return{...B(r,e.graph),background:r.get("background"),alpha:r.get("alpha"),...n===void 0?{}:{borderColor:n},borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock")}},bT=(e,t)=>{const r=e.annotation.image(t);return{alpha:r.get("alpha"),borderRadius:r.get("borderRadius")}},ST=(e,t,r)=>{const n=e.annotation[t](r),a=e.annotation[t].label(r);return{marker:{color:n.get("color"),isColorAuthored:n.getSource("color")==="authored",size:n.get("size"),borderColor:n.get("borderColor"),borderWidth:n.get("borderWidth"),shadow:n.get("shadow")},label:{...B(a,e.graph),isTextColorAuthored:a.getSource("textColor")==="authored",background:a.get("background"),borderColor:a.get("borderColor"),borderWidth:a.get("borderWidth"),borderRadius:a.get("borderRadius"),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),shadow:a.get("shadow")}}},xT=e=>e.borderWidth>0?e.borderColor??e.color:void 0,AT=e=>({edges:{top:Ze(e.panelBorder("top")),right:Ze(e.panelBorder("right")),bottom:Ze(e.panelBorder("bottom")),left:Ze(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),IT=(e,t)=>Ze(e.gridLine(t)),TT=(e,t)=>{const r=e.tickLine(t);return{...Ze(r),length:r.get("length")}},LT=e=>e.heading.h1.get("fontFamily")??e.graph.get("fontFamily"),wT=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")}},ET=e=>{const t=e.graph.get("padding");return typeof t=="number"?{top:t,right:t,bottom:t,left:t}:{...l.DEFAULT_GRAPH_PADDING_EDGES,...t}},RT=e=>{const t=e.legend.popover;return{gap:e.legend().get("gap"),popover:{background:t.get("background"),borderColor:t.get("borderColor"),borderWidth:t.get("borderWidth"),borderRadius:t.get("borderRadius"),paddingInline:t.get("paddingInline"),paddingBlock:t.get("paddingBlock"),shadow:t.get("shadow")}}},CT=e=>({gap:e.headline.get("gap")}),q=e=>{let t={top:0,right:0,bottom:0,left:0};for(const r of e.collectAll("margin"))t=typeof r=="number"?{top:r,right:r,bottom:r,left:r}:{...t,...r};return t},VT=e=>({header:q(e.header),footer:q(e.footer),headline:q(e.headline),legend:{top:q(e.legend("top")),right:q(e.legend("right")),bottom:q(e.legend("bottom")),left:q(e.legend("left"))},axisLabel:{top:q(e.axisLabel("x","top")),bottom:q(e.axisLabel("x","bottom"))},tickLabel:{top:q(e.tickLabel("x","top")),right:q(e.tickLabel("y","right")),bottom:q(e.tickLabel("x","bottom")),left:q(e.tickLabel("y","left"))}}),DT=e=>({color:e.hoverGuide.get("color"),background:e.hoverGuide.get("background")}),_T=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Ze=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),pa=["sticker","pinnedNumber","comment","image"],PT=e=>pa.includes(e),ma=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?MT(e.annotation.at):null;default:return null}},Xl=(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),Zl=(e,t,r=OT)=>{const n=r(t);for(const a of pa){const i=Tt(e,a),o=i.findIndex(c=>{const u=ma({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return Xl(d,n)}),s=i[o];if(s!==void 0)return{kind:a,index:o,annotation:s}}return null},OT=e=>({...e,anchorValue:Br(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Br(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Br(e.crossValue)}}),Br=e=>l.readISOInstant(e)??e,MT=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function kT(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var NT=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ha(r.predicate,t.predicate))??null,ha=(e,t)=>"and"in e?"and"in t&&Zi(e.and,t.and):"or"in e?"or"in t&&Zi(e.or,t.or):"not"in e?"not"in t&&ha(e.not,t.not):BT(t)&&e.variable===t.variable&&FT(e,t),BT=e=>"variable"in e,Zi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ha(r,a)}),FT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ji(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&Ji(e.range,t.range),Ji=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),$T={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},GT=e=>Object.hasOwn($T,e);function UT(e){return{type:"mapping",mapping:e}}var Ct=(e,t)=>"and"in e?"and"in t&&Qi(e.and,t.and):"or"in e?"or"in t&&Qi(e.or,t.or):"not"in e?"not"in t&&Ct(e.not,t.not):HT(t)&&e.variable===t.variable&&WT(e,t),HT=e=>"variable"in e,Qi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Ct(r,a)}),WT=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&eo(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&eo(e.range,t.range),eo=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),Jl=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)))),Ql=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),ec=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function tc(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(KT),transforms:e.transforms,highlights:e.highlights,styles:l.styles(e.styles),annotations:e.annotations,coords:e.coords,config:e.config}}function KT(e){const{inferredFrom:t,...r}=e;return r.scaleType==="palette"?zT(r):r}function zT(e){return{...e,palette:YT(e.palette),overrides:qT(e.overrides)}}function YT(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function qT(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Vt=(e,t)=>{const r=fa(e,t);return r===-1?void 0:e[r]},fa=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&Tr(n,t))return r}return-1},Tr=(e,t)=>jT(e.select,t.select)&&e.when?.state===t.when?.state&&XT(e.when?.where,t.when?.where),rc=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>ZT(e[r],t[r])),De=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),ga=e=>e.select.target==="geom",Dt=(e,t)=>{const r=Vt(e,t);if(!(r===void 0||!ga(r)))return r.declarations},jT=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},XT=(e,t)=>e===void 0||t===void 0?e===t:Ct(e,t),ZT=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function x(e){return{id:e.id??W(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function at(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>at(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>at(e[a],t[a]))}return!1}var ya=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=x({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=It(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:C(e,{annotations:Is(e.annotations,t)}),revert:new va({kind:r,annotation:a,index:n},this.metadata)}}},JT={type:"remove-annotation",deserialize:(e,t)=>new ya(e,t)},va=class nc{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??W()},...t.index!==void 0&&{index:t.index}},this.metadata=x({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Wg(r)||It(t.annotations,n.id))return null;const i=eL(t.annotations,{kind:r,annotation:n}),o=i===null?t.annotations:Is(t.annotations,i),s=Tt(o,r),c=a??s.length,u=Math.min(Math.max(c,0),s.length);return{spec:C(t,{annotations:Mn(o,r,[...s.slice(0,u),n,...s.slice(u)])}),revert:i===null?new ya({id:n.id},this.metadata):new nc({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},QT={type:"add-annotation",deserialize:(e,t)=>new va({kind:e.kind,annotation:e.annotation,index:e.index},t)},eL=(e,t)=>{const r=ma(t);return r===null?null:Zl(e,r)},tL=(e,t)=>{const r=ba(e);return r===null?null:ac(r.points,t)},rL=e=>ba(e)!==null,nL=(e,t)=>{const r=ba(e);if(r===null)return null;const n=ac(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},ba=e=>{const t=iL[e.kind];return t===null?null:t(e.annotation)},to=(e,t)=>e.anchorType!=="panel"?null:{points:[cn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},ro=(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})},aL=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[cn(e,e.offset),cn(t,t.offset)],createPatch:r=>({start:{...e,x:e.x+r.x,y:e.y+r.y},end:{...t,x:t.x+r.x,y:t.y+r.y}})},iL={text:e=>to(e.at,t=>({at:t})),sticker:e=>to(e.at,t=>({at:t})),shape:e=>ro(e.region,t=>({region:t})),image:e=>ro(e.region,t=>({region:t})),arrow:e=>aL(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},cn=(e,t)=>t===void 0||t.unit==="px"?{x:e.x,y:e.y}:{x:e.x+(t.x??0),y:e.y+(t.y??0)},ac=(e,t)=>({x:no(e.map(r=>r.x),t.x),y:no(e.map(r=>r.y),t.y)}),no=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:(0,Je.default)(t,r,n)},ic=(e,t,r)=>{const n=t.annotation;if(!lL(n,r))return null;const a=Tt(e.annotations,t.kind),i=oL(t.annotation,r),o=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:C(e,{annotations:Mn(e.annotations,t.kind,o)}),inverse:sL(n,r)}},oL=(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)))},sL=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},lL=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),Sa=class oc{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=x({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=It(t.annotations,n);if(i===null||i.kind!==r)return null;const o=ic(t,i,a);return o===null?null:{spec:o.spec,revert:new oc({kind:r,id:n,patch:o.inverse},this.metadata)}}},cL={type:"update-annotation",deserialize:(e,t)=>new Sa(e,t)},sc=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=x({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=It(e.annotations,this.params.id);if(t===null)return null;const r=nL(t,this.params.translation);if(r===null)return null;const n=ic(e,t,r);return n===null?null:{spec:n.spec,revert:new Sa({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},uL={type:"move-annotation",deserialize:(e,t)=>new sc(e,t)},xe=class Xt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=x({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],o=fa(i,n),s=o===-1?void 0:i[o],{declarations:c}=n;if(c===null){if(s===void 0)return null;const f=new Xt({list:r,rule:s,index:o},this.metadata),y=i.filter(v=>!Tr(v,n));return{spec:Fr(t,r,y),revert:f}}if(s!==void 0){if(rc(s.declarations,c))return null;const f={...s,declarations:c},y=new Xt({list:r,rule:s,index:o},this.metadata),v=i.map(g=>g===s?f:g);return{spec:Fr(t,r,v),revert:y}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),p={...n,declarations:c},m=[...i.slice(0,d),p,...i.slice(d)],h=new Xt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:Fr(t,r,m),revert:h}}},dL=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."})},pL={type:"set-style-rule",deserialize:(e,t)=>(dL(e),new xe(e,t))},Fr=(e,t,r)=>C(e,{styles:{...e.styles,[t]:r}}),mL={type:"set-difference-arrow-style",deserialize:(e,t)=>new lc(e,t)},lc=class cc{constructor(t,r={}){this.type="set-difference-arrow-style",this.params=t,this.metadata=x({...r,description:"Set difference arrow style"})}get target(){return{kind:"annotation",id:this.params.annotationId}}apply(t){const{annotationId:r,arrow:n,label:a}=this.params,i={target:"annotation",kind:"differenceArrow",annotation:r},o={...i,part:"label"};let s=t;const c={annotationId:r},u=d=>{const p=Vt(s.styles.overrides,d),m=new xe({list:"overrides",rule:d}).apply(s);if(m)return s=m.spec,p?.declarations??null};if(n!==void 0){const d=u({select:i,declarations:n});d!==void 0&&(c.arrow=d)}if(a!==void 0){const d=u({select:o,declarations:a});d!==void 0&&(c.label=d)}return s===t?null:{spec:s,revert:new cc(c,this.metadata)}}},hL=["cartesian","polar","flip"],J=new hr,uc=e=>J.has(e)?J.get(e):null,dc=new l.TransformRegistry,fL=new Vs(dc),Lr=e=>{const t=e.transforms.every(r=>dc.has(r.transformType));return e.transforms.length===0||!t?e.data:fL.compile({data:e.data,transforms:e.transforms})};function xa(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 _t(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function Pt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:C(e,{scales:Lo(e.scales,n,r)})}function Ot(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function un(e,t,r){const n=gr(_n(Ds(J),{data:Lr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Pn(n):n}var pc=class mc{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:EL(t)})}apply(t){const r="previous"in this.params?this.params.previous:RL(t,this.params);if(r===null)return null;const n=C(t,r);return n===t?null:{spec:n,revert:new mc({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},gL={type:"set-chart-type",deserialize:(e,t)=>new pc(e,t)},hc={type:"sum"},yL={type:"identity"},vL=["bar","line","area","point","tile"],Aa="tile",bL=["y","color"],SL=Object.values(l.LAYER_LABEL_VARIABLES),xL={coordType:"cartesian",geom:Aa,position:"identity"},Mt=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),AL=e=>{const t=e.layers.filter(me),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const o=gc(t);if(o!==null)return{coordType:"cartesian",comboType:o}}if(!t.every(o=>o.geom===r.geom&&o.position===r.position))return null;const{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},IL=e=>{if(!e)return!1;const t=e.layers.filter(me);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:yc(e,r)?vc(e,r).length>=1:wr(e,e.data.groupVariableNamesByType().numeric).length>=2},TL=e=>e?Tc(e,xL)!==null:!1,LL=e=>fc(e)?.at(-1)?.id??null,fc=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(me);return gc(t)===null?null:t},gc=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 wL(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)},wL=e=>e.some(t=>t.yScaleType==="secondary"||ir(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,EL=e=>"previous"in e?"Restore the previous chart type":Mt(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,RL=(e,t)=>{const r=Tc(e,t);if(r===null)return null;const n=Mt(t)?VL(r,t):CL(r,t,e);return n===null||r===e?n:{...n,scales:HL({...e,...n},n.scales)}},CL=(e,t,r)=>{if(Mt(t)||!WL(t))return null;const n={...e,layers:Dc(e.layers)},a=YL(n.layers.filter(me),t),i=Pc(n.coords,t),o=Ac(n,t),s=Vc({...n,mapping:o},t,a,o!==n.mapping);return{coords:i,layers:s,scales:xa(Oc(r,s,i.coordType),s),mapping:o}},VL=(e,t)=>{const r=PL(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=qL(r.filter(me),t.comboType),i=Pc(n.coords,t),o=Ac(n,t),s=Vc({...n,mapping:o},t,a,o!==n.mapping),c=DL(e)?s:_L(s);return{coords:i,layers:c,scales:xa(Oc(e,c,i.coordType),c),mapping:o}},DL=e=>fc(e)!==null,_L=e=>{const t=e.filter(me).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},PL=(e,t)=>{const r=e.layers.filter(me);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:yc(e,n)?OL(e,n):ML(e,n,t)},yc=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},OL=(e,t)=>{const[r]=vc(e,t);if(r===void 0)return null;const n=Ge(J,e.mapping,e.coords.coordType,{type:"layer",id:bc(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:hc,...xc(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},wr=(e,t)=>{const r=kt(e);return t.filter(n=>n!==r)},vc=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return wr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},kt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),ML=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=wr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const o=l.readFoldKeepVariables(e.data,kt(e)),s=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=kL(t,ao(a.slice(0,-1),o,s)),u=Ge(J,e.mapping,e.coords.coordType,{type:"layer",id:bc(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...ao([i],o,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},bc=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},ao=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?xc(n,r):Sc(e,t)},Sc=(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})]}),xc=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),kL=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Ac=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Ic(t)?"":kt(e);return n===r?e.mapping:{...e.mapping,x:n}},Ic=e=>e.coordType==="polar"&&e.theta==="y"&&e.position==="fill",NL=e=>!Mt(e)&&e.geom===Aa,BL=e=>e.layers.filter(me).some(t=>t.geom===Aa),Tc=(e,t)=>{const r=NL(t);return r===BL(e)?e:r?FL({...e,layers:Dc(e.layers)}):$L(e)??e},FL=e=>{const t=wc(e);if(t===null)return null;const r=GL(e,t)===null?UL(e,t):Ec(e,t);return r===null?null:Lc(e,t,r)},$L=e=>{const t=wc(e);if(t===null)return null;const r=Ec(e,t);return r===null?null:Lc(e,t,r)},Lc=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),wc=e=>{const t=e.layers.filter(me);return t.length===1?t[0]??null:null},Ec=(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:Rc(t)}},Rc=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}},GL=(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===kt(e))return null;const i=Lr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},UL=(e,t)=>{const r=wr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,kt(e)),a=Sc(r,n),i=Rc(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},HL=(e,t)=>bL.reduce((r,n)=>{const a=un(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Ne(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),WL=e=>hL.includes(e.coordType)&&Cc(e.geom)&&KL(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),KL=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=J.get(e);return n.includes(t)&&a.includes(r)},Cc=e=>vL.includes(e),me=e=>Cc(e.geom)&&!zL(e.stat),zL=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},YL=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},qL=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,o)=>n===null||o===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:jL(i,t,n)}]);return new Map(a)},jL=(e,t,r)=>e.geom!=="bar"||ir(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Vc=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Ss(J,Ne(e.layers,i=>{const o=r.get(i.id);if(o===void 0)return i;const s=XL(i.stat,e.coords,t);return a||n||i.geom!==o.geom||i.position!==o.position||s!==i.stat?JL(e,{...i,stat:s},t.coordType,o):i}))},XL=(e,t,r)=>Ic(r)?e.type==="identity"?hc:e:ZL(t)&&e.type==="sum"?yL:e,ZL=e=>e.coordType==="polar"&&e.params.theta==="y",JL=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:o,format:s,offset:c,justify:u,...d}=t.dataLabels;return{...Ge(J,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:s},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Dc=e=>{const t=e.filter(me);if(t.length<2||!e.some(ir))return e;const[r]=t;return e.flatMap(n=>n===r?[QL(n)]:ir(n)?[]:[n])},ir=e=>_c(e)!==null,_c=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:SL.includes(t.options.variableName)?t:null},QL=e=>{const t=_c(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)}},Pc=(e,t)=>{const r=ew(e,t);return(0,Jt.default)(r,e)?e:r},ew=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Xr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:Yt;return Xr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},Oc=(e,t,r)=>{const n=Yr(J,t),a=Yr(J,e.layers),i=e.coords.coordType==="polar";return Ne(e.scales,o=>{const s=tw(o,n,a),c=rw(s,n,a);return aw(c,r,i)})},tw=(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 jr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return jr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=nw(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},rw=(e,t,r)=>{if(e.scaleType!=="discrete"||!Te(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}},nw=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,aw=(e,t,r)=>{if(e.scaleType!=="discrete"||!Te(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}},Mc=class kc{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=x({...r,description:ow(t)})}apply(t){const r="previous"in this.params?this.params.previous:sw(t,this.params);if(r===null)return null;const n=C(t,r);return n===t?null:{spec:n,revert:new kc({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},iw={type:"set-mapping",deserialize:(e,t)=>new Mc(e,t)},Nc=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Bc=e=>e===""?null:e,ow=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Bc(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},sw=(e,{aesthetic:t,variable:r})=>{if(!GT(t))return null;const n=Bc(r),a=cw(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:dw(e,t,a,n),layers:lw(e.layers,a)}},lw=(e,t)=>Ne(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&uc(r.geom)===null)return r;const a=bs(J,r.geom,r.position,n);return(0,Jt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),cw=(e,t,r)=>r===null?uw(e,t):Nc(e,t)===r?e:{...e,[t]:r},uw=(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},dw=(e,t,r,n)=>{if(!Go(t))return e.scales;let a=e.scales;for(const i of pw(e,t))a=hw(e,a,i,r,n);return a},pw=(e,t)=>t==="y"&&mw(e.layers)?["y","ySecondary"]:[t],mw=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},hw=(e,t,r,n,a)=>{const i=t.find(s=>s.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,un(e,r,n)];if(a===null&&!Te(r)||a!==null&&!Lr(e).hasVariable(a))return t;const o=un(e,r,n);return fw(i,o)?t:Ne(t,s=>s.scaledAesthetic===r?o:s)},fw=(e,t)=>e.scaleType===t.scaleType||io(e)&&io(t),io=e=>e.scaleType==="discrete"||e.scaleType==="palette",Ia=e=>e==="both"?["x","y"]:[e],Fc=e=>e==="both"?"the":`${e} axis`;function Ta(e,t){return Er(e)?e[t]:e}function gw(e,t){return e.config.axes[t]??{}}function yw(e,t,r){if(t!=="ySecondary")return P(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=$c(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,C(e,{config:C(e.config,{axes:i})})}function Er(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function $c(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],o=a in t?vw(i,t[a]):i;o!==i&&(n=!0),o!==void 0&&(r[a]=o)}return n?Object.keys(r).length>0?r:void 0:e}function vw(e,t){return l.isPlainObject(t)?$c(l.isPlainObject(e)?e:void 0,t):t}var Gc=class Uc{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis label to ${Sw(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=gw(t,r).label;if(a===n)return null;const i=yw(t,r,{label:n});return i===t?null:{spec:i,revert:new Uc(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},bw={type:"set-axis-label",deserialize:(e,t)=>new Gc(e,t)};function Sw(e){return e===void 0?"(inherited)":e??"(none)"}var Hc=class Wc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:P(t,{config:{axes:{[r]:{position:n}}}}),revert:new Wc({axis:r,position:a},this.metadata)}}},xw={type:"set-axis-position",deserialize:(e,t)=>new Hc(e,t)},Kc=class zc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new zc({axis:r,tickMode:a},this.metadata)}}},Aw={type:"set-axis-tick-mode",deserialize:(e,t)=>new Kc(e,t)},Yc=class qc{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new qc({axis:r,isVisible:a},this.metadata)}}},Iw={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new Yc(e,t)},jc=class Xc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new Xc({axis:r,isVisible:a},this.metadata)}}},Tw={type:"set-axis-visibility",deserialize:(e,t)=>new jc(e,t)},Zc=class Jc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=x({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:P(t,{config:{content:{caption:this.params.caption}}}),revert:new Jc({caption:r},this.metadata)}}},Lw={type:"set-content-caption",deserialize:(e,t)=>new Zc(e,t)},Qc=class eu{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=x({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(at(r,this.params.source))return null;const n=C(t.config.content,{source:this.params.source});return{spec:C(t,{config:C(t.config,{content:n})}),revert:new eu({source:r},this.metadata)}}},ww={type:"set-content-source",deserialize:(e,t)=>new Qc(e,t)},tu=class ru{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=x({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:P(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new ru({subtitle:r},this.metadata)}}},Ew={type:"set-content-subtitle",deserialize:(e,t)=>new tu(e,t)},nu=class au{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=x({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:P(t,{config:{content:{title:this.params.title}}}),revert:new au({title:r},this.metadata)}}},Rw={type:"set-content-title",deserialize:(e,t)=>new nu(e,t)},Cw="dashed",Vw=1,iu=(e,t,r,n)=>{const a=Dw(t,r),i=Pw(e,a,n);let o=e,s=!1;for(const c of a){const u=Mw(o,c,n,Ow(n,_w(r,c)));u!==null&&(o=u,s=!0)}return s?{spec:o,previous:i}:null},Dw=(e,t)=>e==="both"&&!Er(t)?[void 0]:Ia(e),_w=(e,t)=>t===void 0?Er(e)?e.x:e:Ta(e,t),Pw=(e,t,r)=>t.length===1?$r(e,t[0],r):{x:$r(e,"x",r),y:$r(e,"y",r)},$r=(e,t,r)=>ou(e.styles.overrides,t)?.[r]??null,Ow=(e,t)=>t===null||e==="lineType"&&t===Cw||e==="strokeWidth"&&t===Vw?null:t,Mw=(e,t,r,n)=>{const a=ou(e.styles.overrides,t);return(a?.[r]??null)===n?null:new xe({list:"overrides",rule:Bw(t,Nw(a,r,n))}).apply(e)?.spec??null},kw=e=>e.select.target==="gridLine",ou=(e,t)=>{const r=Vt(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!kw(r)))return r.declarations},Nw=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},Bw=(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),su=class lu{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=x({...r,description:`Set ${Fc(t.axis)} grid line style to ${$w(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=iu(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new lu({axis:r,lineStyle:a.previous},this.metadata)}}},Fw={type:"set-grid-line-style",deserialize:(e,t)=>new su(e,t)},$w=({axis:e,lineStyle:t})=>{const r=Ia(e).map(n=>Ta(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Gw={type:"set-grid-line-width",deserialize:(e,t)=>new cu(e,t)},cu=class uu{constructor(t,r={}){this.type="set-grid-line-width";const n=Uw(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=x({...r,description:`Set ${Fc(t.axis)} grid line width to ${Hw(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=iu(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new uu({axis:r,lineWidth:a.previous},this.metadata)}}},Uw=e=>Er(e)?{x:Gr(e.x),y:Gr(e.y)}:Gr(e),Gr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),Hw=(e,t)=>{const r=Ia(e).map(n=>Ta(t,n)??"(theme)");return[...new Set(r)].join(" and ")},du=class pu{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:P(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new pu({axis:r,isVisible:a},this.metadata)}}},Ww={type:"set-grid-visibility",deserialize:(e,t)=>new du(e,t)},mu=class hu{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:P(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new hu({compareWith:r},this.metadata)}}},Kw={type:"set-headline-compare-with",deserialize:(e,t)=>new mu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:P(t,{config:{headline:{position:this.params.position}}}),revert:new gu({position:r},this.metadata)}}},zw={type:"set-headline-position",deserialize:(e,t)=>new fu(e,t)},yu=class vu{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:P(t,{config:{headline:{show:this.params.show}}}),revert:new vu({show:r},this.metadata)}}},Yw={type:"set-headline-show",deserialize:(e,t)=>new yu(e,t)},bu=class Su{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=x({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:P(t,{config:{headline:{size:this.params.size}}}),revert:new Su({size:r},this.metadata)}}},qw={type:"set-headline-size",deserialize:(e,t)=>new bu(e,t)},jw={type:"set-highlight-dim-style",deserialize:(e,t)=>new xu(e,t)},xu=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=x({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Au(e)===this.params.dimStyle)return null;const t=new xe({list:"overrides",rule:Zw(this.params.dimStyle)},this.metadata).apply(e);return t||null}},Xw={select:{target:"geom"},when:{state:"dimmed"}},Au=e=>{const t=Vt(e.styles.overrides,Xw);return(t!==void 0&&ga(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},Zw=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Iu=class Tu{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:P(t,{config:{legend:{align:this.params.align}}}),revert:new Tu({align:r},this.metadata)}}},Jw={type:"set-legend-align",deserialize:(e,t)=>new Iu(e,t)},Lu=class wu{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:P(t,{config:{legend:{display:this.params.display}}}),revert:new wu({display:r},this.metadata)}}},Qw={type:"set-legend-display",deserialize:(e,t)=>new Lu(e,t)},Eu=class Ru{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=x({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:P(t,{config:{legend:{position:this.params.position}}}),revert:new Ru({position:r},this.metadata)}}},eE={type:"set-legend-position",deserialize:(e,t)=>new Eu(e,t)},Cu=class Vu{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:P(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Vu({abbreviation:r},this.metadata)}}},tE={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Cu(e,t)},Du=class _u{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=x({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:P(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new _u({decimals:r},this.metadata)}}},rE={type:"set-number-format-decimals",deserialize:(e,t)=>new Du(e,t)},Pu=class Ou{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=x({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=aE(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:P(t,{config:{content:{[a]:n}}}),revert:new Ou({slot:r,isVisible:i},this.metadata)}}},nE={type:"toggle-content-visibility",deserialize:(e,t)=>new Pu(e,t)},oo={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function aE(e){return Object.hasOwn(oo,e)?oo[e]:void 0}var Mu=class ku{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=x({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if(at(i.xLimits,a.xLimits)&&at(i.yLimits,a.yLimits))return null;const o={};r!==void 0&&(o.xLimits=a.xLimits),n!==void 0&&(o.yLimits=a.yLimits);const s=new ku(o,this.metadata);return{spec:C(t,{coords:oE(t.coords,i)}),revert:s}}},iE={type:"set-coord-limits",deserialize:(e,t)=>new Mu(e,t)};function oE(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 Nu=class Bu{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Je.default)(t.innerRadius,0,1)},this.metadata=x({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:C(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new Bu({innerRadius:n},this.metadata)}}},sE={type:"set-polar-inner-radius",deserialize:(e,t)=>new Nu(e,t)},lE={type:"set-polar-start-angle",deserialize:(e,t)=>new Fu(e,t)},Fu=class $u{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:so(t.startAngle)},this.metadata=x({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return so(n)===this.params.startAngle?null:{spec:C(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new $u({startAngle:n},this.metadata)}}},Ur=360,so=e=>(e%Ur+Ur)%Ur,La=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=x({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new wa({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:C(e,{highlights:n}),revert:a}}},cE={type:"remove-highlight",deserialize:(e,t)=>new La(e,t)},wa=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??W(),scope:e.scope??"data-point"},this.metadata=x({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const o=new La({id:r},this.metadata),s={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:C(e,{highlights:[...e.highlights.slice(0,u),s,...e.highlights.slice(u)]}),revert:o}}},uE={type:"add-highlight",deserialize:(e,t)=>new wa(e,t)};function Ea(e,t){return{...e,params:{...e.params,...t}}}function Rr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function Ra(e,t){return C(e,{layers:[...e.layers,t]})}function ee(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:C(e,{layers:Lo(e.layers,n,r)})}function Cr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:C(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Ca=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=x({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=Cr(e,this.params.layerId);return n===e?null:{spec:n,revert:new Va({layer:r,index:t},this.metadata)}}},dE={type:"remove-layer",deserialize:(e,t)=>new Ca(e,t)},Va=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??W()},...e.index!==void 0&&{index:e.index}},this.metadata=x({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:C(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Ca({layerId:t.id},this.metadata)}}},pE={type:"add-layer",deserialize:(e,t)=>new Va(e,t)},Gu=class Uu{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=x({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!ae(F(t.layers,r),"bar"))return null;const a=De("bar",r),i=Dt(t.styles.overrides,a),o=i?.borderRadius??null;if(o===n)return null;const s=new xe({list:"overrides",rule:{...a,declarations:hE(i,n)}}).apply(t);if(!s)return null;const c=new Uu({layerId:r,borderRadius:o},this.metadata);return{spec:s.spec,revert:c}}},mE={type:"set-bar-border-radius",deserialize:(e,t)=>new Gu(e,t)},hE=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},fE={type:"set-bar-width",deserialize:(e,t)=>new Wu(e,t)},Hu=.05,gE=1,Wu=class Ku{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Je.default)(t.width,Hu,1);this.params={...t,width:n},this.metadata=x({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"bar");if(!ae(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:ee(t,r.id,Ea(r,{width:this.params.width})),revert:new Ku({layerId:r.id,width:n},this.metadata)}}},zu=class Yu{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=x({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:ee(t,r.id,Rr(r,{format:this.params.format})),revert:new Yu({layerId:r.id,format:n},this.metadata)}}},yE={type:"set-data-labels-format",deserialize:(e,t)=>new zu(e,t)},qu=class ju{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=x({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:ee(t,r.id,{...r,position:this.params.position}),revert:new ju({layerId:r.id,position:n},this.metadata)}}},vE={type:"set-layer-position",deserialize:(e,t)=>new qu(e,t)},Xu=class Zu{constructor(t,r={}){this.type="set-layer-stat";const n=vs(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=x({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return SE(n,this.params.stat)?null:{spec:ee(t,r.id,{...r,stat:this.params.stat}),revert:new Zu({layerId:r.id,stat:n},this.metadata)}}},bE={type:"set-layer-stat",deserialize:(e,t)=>new Xu(e,t)},SE=(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},Ju=class Qu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=x({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=ee(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:C(a,{scales:xa(a.scales,a.layers)}),revert:new Qu({layerId:r.id,yScaleType:n},this.metadata)}}},xE={type:"set-layer-y-scale-type",deserialize:(e,t)=>new Ju(e,t)},ed=class td{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=x({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:ee(t,r.id,Ea(r,{interpolate:this.params.interpolate})),revert:new td({layerId:r.id,interpolate:n},this.metadata)}}},AE={type:"set-line-interpolation",deserialize:(e,t)=>new ed(e,t)},rd=class nd{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=x({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");if(!ae(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:ee(t,r.id,Ea(r,{missingValues:this.params.missingValues})),revert:new nd({layerId:r.id,missingValues:n},this.metadata)}}},IE={type:"set-line-missing-values",deserialize:(e,t)=>new rd(e,t)},ad=class id{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=x({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=F(t.layers,r);if(!ae(a,"line","area"))return null;const i=Dt(t.styles.overrides,De(a.geom,r)),o=i?.strokeWidth??null;if(o===n)return null;const s=LE(i,n),c=new xe({list:"overrides",rule:a.geom==="area"?{...De("area",r),declarations:s}:{...De("line",r),declarations:s}}).apply(t);return c?{spec:c.spec,revert:new id({layerId:r,lineWidth:o},this.metadata)}:null}},TE={type:"set-line-width",deserialize:(e,t)=>new ad(e,t)},LE=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},od=class sd{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=x({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!ae(F(t.layers,r),"point"))return null;const a=De("point",r),i=Dt(t.styles.overrides,a),o=i?.size??null;if(o===n)return null;const s=new xe({list:"overrides",rule:{...a,declarations:EE(i,n)}}).apply(t);return s?{spec:s.spec,revert:new sd({layerId:r,size:o},this.metadata)}:null}},wE={type:"set-point-size",deserialize:(e,t)=>new od(e,t)},EE=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},ld=class cd{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=x({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"rule");if(!ae(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([o])=>o!=="label")):{...r.params,label:a};return{spec:ee(t,r.id,{...r,params:i}),revert:new cd({layerId:r.id,label:n??null},this.metadata)}}},RE={type:"set-rule-label",deserialize:(e,t)=>new ld(e,t)},ud=class dd{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=x({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"rule");if(!ae(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:ee(t,r.id,{...r,mapping:i}),revert:new dd({layerId:r.id,value:a},this.metadata)}}},CE={type:"set-rule-value",deserialize:(e,t)=>new ud(e,t)},VE={type:"set-stat-line",deserialize:(e,t)=>new pd(e,t)},pd=class md{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=x({...r,description:NE(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=_E(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&&kE(r.layer,n))return null;const a=new md({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:ee(t,r.layer.id,n),revert:a};const i=r===void 0?t:Cr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:Ra(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"?PE(this.params):OE(t,this.params);if(n===null)return null;const a=Ge(J,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},DE="linear",_E=e=>{const t=Ql(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=ec(e.layers);if(r!==void 0)return{line:"average",layer:r}},PE=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??DE}),interactive:!1}),OE=(e,{group:t,label:r})=>{const n=ME(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),o=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:o?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},ME=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),kE=(e,t)=>(0,it.isEqual)({...e,id:""},{...t,id:""}),NE=e=>e==="none"?"Hide stat line":`Show ${e} line`,hd=class fd{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=x({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:ee(t,r.id,Rr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new fd({layerId:r.id,showCategoryLabels:n},this.metadata)}}},BE={type:"toggle-category-labels",deserialize:(e,t)=>new hd(e,t)},gd=class yd{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=x({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:ee(t,r.id,Rr(r,{showDataLabels:this.params.showDataLabels})),revert:new yd({layerId:r.id,showDataLabels:n},this.metadata)}}},FE={type:"toggle-data-labels",deserialize:(e,t)=>new gd(e,t)},$E={type:"toggle-goal-line",deserialize:(e,t)=>new vd(e,t)},vd=class dn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=x({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=Jl(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=Cr(t,r.id);return a===t?null:{spec:a,revert:new dn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:Ra(t,n),revert:new dn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ge(J,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??GE}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},GE=0,UE={type:"toggle-line-fill",deserialize:(e,t)=>new bd(e,t)},bd=class Sd{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=x({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!ae(F(t.layers,r),"line"))return null;const i=De("line",r),o=Dt(t.styles.overrides,i),s=o?.fillAlpha,c=s!==void 0;if(c===n)return null;const u=new xe({list:"overrides",rule:{...i,declarations:WE(o,n?a??HE:null)}}).apply(t);if(!u)return null;const d=new Sd({layerId:r,showFill:c,...s===void 0?{}:{fillAlpha:s}},this.metadata);return{spec:u.spec,revert:d}}},HE=.2,WE=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},KE={type:"toggle-line-points",deserialize:(e,t)=>new xd(e,t)},xd=class pn{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=x({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):we(t.layers,"line","area");return ae(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:Ra(t,this.params.removedLayer??Ge(J,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new pn({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:Cr(t,n.id),revert:new pn({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:Ln(n,[r]))}},Ad=class Id{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=x({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?F(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:ee(t,r.id,Rr(r,{showStackTotals:this.params.showStackTotals})),revert:new Id({layerId:r.id,showStackTotals:n},this.metadata)}}},zE={type:"toggle-stack-totals",deserialize:(e,t)=>new Ad(e,t)},Td=class Ld{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=x({...r,description:`Set ${Ot(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=_t(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const o={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},s=Pt(t,this.params.scaledAesthetic,o),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:s,revert:new Ld(c,this.metadata)}}},YE={type:"set-scale-domain",deserialize:(e,t)=>new Td(e,t)},wd=class Ed{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=x({...r,description:`Set ${Ot(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=_t(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||at(r.palette,this.params.palette)?null:{spec:Pt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Ed({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},qE={type:"set-scale-palette",deserialize:(e,t)=>new wd(e,t)},Rd=class Cd{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=x({...r,description:`Set ${Ot(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=_t(t,this.params.scaledAesthetic);if(!r||!XE(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:Pt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Cd({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},jE={type:"set-scale-reverse",deserialize:(e,t)=>new Rd(e,t)};function XE(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Vd=class Dd{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=x({...r,description:`Set ${Ot(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=_t(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:Pt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Dd({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},ZE={type:"set-scale-transform",deserialize:(e,t)=>new Vd(e,t)},_d=class Pd{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=x({...r,description:`Set ${Ot(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=_t(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:Pt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Pd({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},JE={type:"set-scale-zero",deserialize:(e,t)=>new _d(e,t)},Od=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new Od;S.register(gL);S.register(iw);S.register(pE);S.register(dE);S.register(yE);S.register(vE);S.register(bE);S.register(xE);S.register(AE);S.register(TE);S.register(mE);S.register(fE);S.register(wE);S.register(IE);S.register(RE);S.register(CE);S.register(VE);S.register(BE);S.register(FE);S.register($E);S.register(UE);S.register(KE);S.register(zE);S.register(YE);S.register(qE);S.register(jE);S.register(ZE);S.register(JE);S.register(bw);S.register(Aw);S.register(xw);S.register(Iw);S.register(Tw);S.register(Lw);S.register(ww);S.register(Ew);S.register(Rw);S.register(Fw);S.register(Gw);S.register(Ww);S.register(Kw);S.register(zw);S.register(Yw);S.register(qw);S.register(jw);S.register(Jw);S.register(Qw);S.register(eE);S.register(tE);S.register(rE);S.register(nE);S.register(uE);S.register(cE);S.register(pL);S.register(QT);S.register(JT);S.register(cL);S.register(mL);S.register(uL);S.register(iE);S.register(sE);S.register(lE);var Md=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return!1;switch(e.kind){case"annotation":return t.kind==="annotation"&&e.id===t.id;case"highlight":return t.kind==="highlight"&&e.id===t.id;case"styleRule":return t.kind==="styleRule"&&e.list===t.list&&Tr(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observations":return t.kind==="observations"&&e.layerId===t.layerId&&e.scope===t.scope&&Ct(e.predicate,t.predicate);case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"graph":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},kd=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,o=e.apply(t);if(!o)return a||(this.hasOpenRun=!1),i(t,null);const s=r?.({spec:o.spec,command:e})??null,c=s?s.adopted:o.spec;return c?(this.push(e,c,o.revert,a),i(c,s?.value??null)):(a||(this.hasOpenRun=!1),i(t,s?.value??null))})}commit(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"commit"}),!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:lo(this.undoStack),redoStack:lo(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],o=this.hasOpenRun&&i!==void 0&&eR(i.command,e);if(n&&o){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},QE=Object.freeze([]),eR=(e,t)=>e.type===t.type&&Md(e.target,t.target),lo=e=>e.length===0?QE:e.map(t=>t.command.metadata),tR=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.commit(),t=this.frame;return this.frame=null,e?t:null}},rR=class{constructor(e){this.compiler=e,this.history=new kd,this.current=null,this.last=null,this.hostSpec=null,this.run=new tR(this.history)}get scene(){return this.current}compile(e){return this.last=e,this.hostSpec=e.spec,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.spec!==this.hostSpec&&e.spec!==t.spec,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes,i=!t||e.colorScheme!==t.colorScheme;if(this.hostSpec=e.spec,!r&&!n&&!a&&!i)return null;let o=null;r?this.run.close():o=this.closeAndConvert();const s=this.last,c=s&&!r?s.spec:e.spec;this.last={spec:c,data:e.data,customPalettes:e.customPalettes,colorScheme:e.colorScheme};const u=this.current,d=r||a||!u?this.absorb(this.compiler.compile(this.last)):this.absorb(this.compiler.recompile({spec:u.spec,data:e.data,colorScheme:e.colorScheme}));return r&&d.ok&&this.history.clear(),{result:d,specChanged:r,...o&&{committedSpec:o.spec}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.commitNotification(!1);c&&n.push(c)}const{current:a,last:i,history:o}=this;if(!a||!i)return n;const s=o.apply(e,a.spec,({spec:c})=>{const u=this.applyEdit(c,i,r,e);return{adopted:u.ok?u.scene.spec:null,value:u}},t);return s&&n.push(this.renderedNotification(s,e,r)),n}commit(){const e=this.commitNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const o=this.applyEdit(a,r);return{adopted:o.ok?o.scene.spec:null,value:{result:o,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{scene:e.scene}:{scene:e.scene,result:e,command:t,...e.spec&&{spec:e.spec}}:{errors:e.errors}}commitNotification(e){const t=this.closeAndConvert();return t?{result:t.result,spec:t.spec,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{spec:this.recordSpec(t.spec,r),result:e.result,command:e.command}}applyEdit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e,colorScheme:t.colorScheme});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.scene,r&&n){const o={ok:!0,scene:a.scene,warnings:a.warnings};return this.run.open({result:o,command:n}),o}this.run.clear();const i=this.recordSpec(a.scene.spec,t);return{ok:!0,scene:a.scene,warnings:a.warnings,spec:i}}recordSpec(e,t){const r=tc(e);return this.last={spec:r,data:t.data,customPalettes:t.customPalettes,colorScheme:t.colorScheme},r}absorb(e){return e.ok&&(this.current=e.scene),e}},nR=new Set(["x","y"]),co=["numeric","categorical","temporal"],uo=["numeric"],aR=(e,t)=>{const r=e.layers.map(a=>uc(a.geom)).filter(l.isDefined),n=Lr(e);return t.filter(a=>iR(e,r,a)).map(a=>({aesthetic:a,variables:oR(n,r,a),isRequired:nR.has(a)}))},iR=(e,t,r)=>{switch(r){case"x":return!cR(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))}},oR=(e,t,r)=>{const n=sR(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},sR=(e,t)=>t==="size"?uo:t!=="x"&&t!=="y"?co:lR(e,t)?uo:co,lR=(e,t)=>e.some(r=>r.positionRoles.some(n=>$o.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),cR=e=>e.coordType==="polar"&&e.params.theta==="y",uR=500,dR="normal",Da={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},pR=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}`},_a=e=>typeof e!="string"?e??500:Da[e],mR="\0",hR=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,_a(t.weight),t.style??"normal",e].join(mR)}},fR={" ":.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 gR=1.05,yR=.84,vR=.21,bR=class{measureText(e,t){let r=0;for(const i of e)r+=(fR[i]??.55)*t.size;_a(t.weight)>=Da.semiBold&&(r*=gR);const n=yR*t.size,a=vR*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_PARTS=l.ANNOTATION_PARTS;exports.ANNOTATION_STYLE_KINDS=l.ANNOTATION_STYLE_KINDS;exports.ANNOTATION_TOOLTIP_MARKER_GAP=MS;exports.ARROW_DEFAULTS=l.ARROW_DEFAULTS;exports.ARROW_STICKER_DECLARATIONS=l.ARROW_STICKER_DECLARATIONS;exports.ARROW_STROKE_WIDTHS=l.ARROW_STROKE_WIDTHS;exports.AXIS_KEYS=xn;exports.AddAnnotationCommand=va;exports.AddHighlightCommand=wa;exports.AddLayerCommand=Va;exports.BORDER_RADIUS_PX=aa;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Bf;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=Ty;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=hR;exports.CommandRegistry=Od;exports.CommandStackManager=kd;exports.Compiler=_s;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=dR;exports.DEFAULT_FONT_WEIGHT=uR;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRAPH_BORDER_WIDTH=l.DEFAULT_GRAPH_BORDER_WIDTH;exports.DEFAULT_GRAPH_PADDING=l.DEFAULT_GRAPH_PADDING;exports.DEFAULT_HEADLINE_SWATCH_SIZE=l.DEFAULT_HEADLINE_SWATCH_SIZE;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_MONO_BASE=l.DEFAULT_MONO_BASE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DIFFERENCE_ARROW_DEFAULTS=l.DIFFERENCE_ARROW_DEFAULTS;exports.DIFFERENCE_ARROW_SIZE_DECLARATIONS=l.DIFFERENCE_ARROW_SIZE_DECLARATIONS;exports.DIVERGING_SCHEME_NAMES=hs;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=Se;exports.GraphCompilationSession=rR;exports.HEADING_PARTS=l.HEADING_PARTS;exports.HEADLINE_ITEM_PARTS=l.HEADLINE_ITEM_PARTS;exports.HEADLINE_SWATCH_GAP=kx;exports.HEADLINE_TREND_GAP=Fx;exports.HEADLINE_TREND_ICON_SIZE=Bx;exports.HEADLINE_VALUE_LABEL_GAP=Nx;exports.HeuristicTextMeasurer=bR;exports.HoverEngine=AI;exports.InternalError=l.InternalError;exports.LEGEND_ITEM_PARTS=l.LEGEND_ITEM_PARTS;exports.LEGEND_PARTS=l.LEGEND_PARTS;exports.LINE_STYLE_TYPES=l.LINE_STYLE_TYPES;exports.LayoutCompiler=oS;exports.MAX_BAR_WIDTH=gE;exports.MIN_BAR_WIDTH=Hu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=sc;exports.NAMED_WEIGHTS=Da;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=pa;exports.OUT_OF_VIEW_MARGIN_PX=kS;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=qd;exports.POSITION_TYPES=l.POSITION_TYPES;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=oe;exports.RemoveAnnotationCommand=ya;exports.RemoveHighlightCommand=La;exports.RemoveLayerCommand=Ca;exports.SCALED_POSITION_AESTHETIC_KEYS=An;exports.SCALED_VISUAL_AESTHETIC_KEYS=bt;exports.SCHEME_ALIASES=fs;exports.SEQUENTIAL_SCHEME_NAMES=Ff;exports.SHAPE_DEFAULTS=l.SHAPE_DEFAULTS;exports.SIBLING_OVERLAP_THRESHOLD_PX=NS;exports.SOURCE_PARTS=l.SOURCE_PARTS;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAxisLabelCommand=Gc;exports.SetAxisPositionCommand=Hc;exports.SetAxisTickModeCommand=Kc;exports.SetAxisTicksVisibilityCommand=Yc;exports.SetAxisVisibilityCommand=jc;exports.SetBarBorderRadiusCommand=Gu;exports.SetBarWidthCommand=Wu;exports.SetChartTypeCommand=pc;exports.SetContentCaptionCommand=Zc;exports.SetContentSourceCommand=Qc;exports.SetContentSubtitleCommand=tu;exports.SetContentTitleCommand=nu;exports.SetCoordLimitsCommand=Mu;exports.SetDataLabelsFormatCommand=zu;exports.SetDifferenceArrowStyleCommand=lc;exports.SetGridLineStyleCommand=su;exports.SetGridLineWidthCommand=cu;exports.SetGridVisibilityCommand=du;exports.SetHeadlineCompareWithCommand=mu;exports.SetHeadlinePositionCommand=fu;exports.SetHeadlineShowCommand=yu;exports.SetHeadlineSizeCommand=bu;exports.SetHighlightDimStyleCommand=xu;exports.SetLayerPositionCommand=qu;exports.SetLayerStatCommand=Xu;exports.SetLayerYScaleTypeCommand=Ju;exports.SetLegendAlignCommand=Iu;exports.SetLegendDisplayCommand=Lu;exports.SetLegendPositionCommand=Eu;exports.SetLineInterpolationCommand=ed;exports.SetLineMissingValuesCommand=rd;exports.SetLineWidthCommand=ad;exports.SetMappingCommand=Mc;exports.SetNumberFormatAbbreviationCommand=Cu;exports.SetNumberFormatDecimalsCommand=Du;exports.SetPointSizeCommand=od;exports.SetPolarInnerRadiusCommand=Nu;exports.SetPolarStartAngleCommand=Fu;exports.SetRuleLabelCommand=ld;exports.SetRuleValueCommand=ud;exports.SetScaleDomainCommand=Td;exports.SetScalePaletteCommand=wd;exports.SetScaleReverseCommand=Rd;exports.SetScaleTransformCommand=Vd;exports.SetScaleZeroCommand=_d;exports.SetStatLineCommand=pd;exports.SetStyleRuleCommand=xe;exports.SpecResolver=xs;exports.Stat=$e;exports.TAU=ge;exports.TEXT_ANNOTATION_DEFAULTS=l.TEXT_ANNOTATION_DEFAULTS;exports.TEXT_ANNOTATION_FADE_ALPHA=l.TEXT_ANNOTATION_FADE_ALPHA;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=hd;exports.ToggleContentVisibilityCommand=Pu;exports.ToggleDataLabelsCommand=gd;exports.ToggleGoalLineCommand=vd;exports.ToggleLineFillCommand=bd;exports.ToggleLinePointsVisibilityCommand=xd;exports.ToggleStackTotalsCommand=Ad;exports.UpdateAnnotationCommand=Sa;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=bo;exports.annotation=Hg;exports.areAnchorsEqual=Xe;exports.areEditMenuTriggersEqual=mx;exports.areEditTargetsEqual=Md;exports.areEndpointsComparable=Ao;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=Xl;exports.arePointerRegionListsEqual=ox;exports.arePredicatesEqual=Ct;exports.areStyleDeclarationsEqual=rc;exports.areStyleRuleAddressesEqual=Tr;exports.buildAverageLineSymbols=DS;exports.buildCalloutHitRegions=OS;exports.buildColumnKey=Il;exports.buildDataLabelsContent=rb;exports.buildDiagnostic=To;exports.buildEditMenuTriggerRegion=dx;exports.buildFontString=pR;exports.buildLayerIntroPlan=PI;exports.buildLayerStyleAddress=De;exports.buildLayerYValueFormatter=ea;exports.buildObservationPredicate=qS;exports.buildObservationsTarget=JS;exports.buildObservationsTargetAtValue=QS;exports.buildPinnedNumberValueFormatter=Tx;exports.buildPolarBarArcPath=tA;exports.buildSliceGroupKey=wl;exports.buildTooltipContent=aT;exports.canAnchorDirectLabels=Zo;exports.canBecomeCombo=IL;exports.canBecomeHeatmap=TL;exports.canPlaceDataLabels=tb;exports.clampAnnotationTranslation=tL;exports.commandRegistry=S;exports.compileChromeStyles=Ls;exports.compileStylesheetForLayer=Zg;exports.compositeColor=fo;exports.computeArrow=CS;exports.computeDifferenceArrow=ll;exports.computeDirectLabelsLayout=YS;exports.computeLineBoxHeight=cl;exports.computePanelBorderPaths=YI;exports.computePanelBorderSizes=qI;exports.config=l.config;exports.coord=l.coord;exports.countLayerGeoms=OI;exports.createAlphaValueReader=rp;exports.createAnchorResolver=cS;exports.createAreaPathGenerators=zx;exports.createColorValueReader=So;exports.createCompiler=Ly;exports.createDatasetFromKindPartitions=Np;exports.createEmptyHighlight=Jo;exports.createGraphyBuilder=Ry;exports.createGroupValueReader=np;exports.createHeadlineItemRows=$x;exports.createLabelValueReader=ep;exports.createLineFillAreaGenerator=Jx;exports.createLinePathGenerator=Zx;exports.createObservationAnchorBuilder=vt;exports.createObservationAnchorParser=Io;exports.createRawValueReader=Q;exports.createSegmentYReader=yt;exports.createSizeValueReader=tp;exports.createSpec=Os;exports.createStableBandKeyGenerator=iA;exports.createStableCellKeyGenerator=oA;exports.createStableKeyGenerator=xr;exports.createStrokeWidthValueReader=ap;exports.createStyleResolver=st;exports.createValueFormatter=N;exports.createXValueReader=ot;exports.createYValueReader=fn;exports.cursorToPiePlane=lr;exports.cursorToPolar=mn;exports.describeMeasurementBasis=Wr;exports.ensureReadableTextColor=Yd;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=fl;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=Xm;exports.findAnnotation=It;exports.findAverageLineLayer=ec;exports.findAxisGuide=na;exports.findDistinctLayers=wn;exports.findEquivalentHighlight=NT;exports.findGoalLineLayer=Jl;exports.findHighlightsAtObservation=fx;exports.findKindStyleDeclarations=Dt;exports.findLayerByGeom=we;exports.findLayerById=F;exports.findLegendForAesthetic=Ox;exports.findObservationAttachment=Zl;exports.findPointerRegion=ax;exports.findStyleRule=Vt;exports.findStyleRuleIndex=fa;exports.findTrendLineLayer=Ql;exports.formatDifferenceLabel=ol;exports.formatHeadline=Lx;exports.formatLegends=_x;exports.formatRuleValue=Mx;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=H;exports.getAlpha=js;exports.getAngleExtent=Jn;exports.getBarRectBounds=Al;exports.getBoundingRect=Xx;exports.getChromeDashArray=_T;exports.getColor=Et;exports.getCrossAxisCoordinate=ve;exports.getCurve=Sr;exports.getDashArray=Kx;exports.getDifferenceArrowDimensions=sl;exports.getDifferenceArrowLabelBox=ul;exports.getGroup=re;exports.getGroupVariables=be;exports.getHoverGuideLineProps=wI;exports.getHoverGuideRectProps=EI;exports.getInsetTileRect=nl;exports.getLineType=Xs;exports.getMainAxisCoordinate=Z;exports.getNumericWeight=_a;exports.getPolarHoverGuideArcProps=RI;exports.getRadiusExtent=Qn;exports.getRuleDashPattern=aA;exports.getScaledAesthetic=Jd;exports.getShapeAnnotationStroke=xT;exports.getSize=jn;exports.getStablePolarBarKeyGenerator=sA;exports.getStackRole=rs;exports.getStrokeWidth=en;exports.getTileRectBounds=rl;exports.getUnionExtent=nA;exports.getX=k;exports.getXMax=X;exports.getXMin=j;exports.getY=_;exports.getYMax=$;exports.getYMin=U;exports.getYRaw=hn;exports.hasMultipleGroups=pr;exports.highlight=kT;exports.inferDefaultDifferenceArrowEndpoints=vx;exports.inferDifferenceArrowEndpoints=xl;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=rL;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=sp;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=Mt;exports.isCompanionLayer=Ln;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=go;exports.isGeomStyleRule=ga;exports.isKeyedScope=br;exports.isLayerOf=Ps;exports.isLayerOfType=ae;exports.isLineStyleType=l.isLineStyleType;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=PT;exports.isPointWithinEditMenuTrigger=px;exports.isPointWithinRegionShape=ra;exports.isPositionScale=Te;exports.isSafeUrl=tT;exports.isStackedPosition=l.isStackedPosition;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=UT;exports.normalizeAngle=Pe;exports.orderPointerRegions=ix;exports.paintsInDonutHole=vr;exports.pickReadableTextColor=ho;exports.pipe=Ms;exports.placeCallouts=US;exports.polarToUnit=ye;exports.positionToAngle=yo;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=Yx;exports.prepareLineObservations=Qx;exports.projectAnchorToPanel=rr;exports.projectRegionToPanel=pS;exports.quantizeKey=te;exports.readAnchoredObservation=Sx;exports.readAttachedObservation=ma;exports.readAuthoredNumber=mT;exports.readAuthoredString=hT;exports.readBroadestObservationsScope=ex;exports.readChartType=AL;exports.readColorGroupObservation=lA;exports.readComboLineLayerId=LL;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Au;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=aR;exports.readMappedVariable=Nc;exports.readObservationIndex=CI;exports.readScopeXVariable=St;exports.readXExtent=zl;exports.readYExtent=Yl;exports.resolveAnchorVariable=ke;exports.resolveArrowAnnotationStyle=gT;exports.resolveArrowColor=KS;exports.resolveAxisLabelStyle=Eb;exports.resolveBarBandFraction=qr;exports.resolveBarBorderRadiusPx=ia;exports.resolveBarBorderTreatment=jx;exports.resolveBarCornerRadiiPx=qx;exports.resolveCalloutAnnotationStyle=ST;exports.resolveCaptionStyle=Lb;exports.resolveChromeMargin=q;exports.resolveChromeMargins=VT;exports.resolveColorRamp=Dn;exports.resolveComparisonBasis=Xo;exports.resolveDataLabelStyle=Cb;exports.resolveDeferredAnchors=gS;exports.resolveDefinition=Vn;exports.resolveDifferenceArrowAnnotationStyle=yT;exports.resolveDirectLabelStyle=Pb;exports.resolveGeomAnchorFrame=vn;exports.resolveGraphChromeStyle=wT;exports.resolveGraphPadding=ET;exports.resolveGridLineStyle=IT;exports.resolveHeadingFontFamily=LT;exports.resolveHeadingStyle=Ib;exports.resolveHeadlineFigure=Mb;exports.resolveHeadlineItemStyle=Ob;exports.resolveHeadlinePlacement=eS;exports.resolveHeadlineStyle=CT;exports.resolveHoverGuideStyle=DT;exports.resolveImageAnnotationStyle=bT;exports.resolveLegendItemStyle=_b;exports.resolveLegendStyle=RT;exports.resolveObservationPoint=xx;exports.resolveObservationsTarget=bl;exports.resolvePanelBorderStyle=AT;exports.resolvePolarBarCornerRadiusUnit=rA;exports.resolveRuleLabelStyle=Vb;exports.resolveSegmentYSource=cr;exports.resolveShapeAnnotationStyle=fT;exports.resolveSourceStyle=wb;exports.resolveSubtitleStyle=Tb;exports.resolveSwatchGeomPaint=oa;exports.resolveTextAnnotationStyle=vT;exports.resolveTextStyle=B;exports.resolveTickLabelStyle=Rb;exports.resolveTickLineStyle=TT;exports.resolveTooltipStyle=Db;exports.resolveYScaleAesthetic=Le;exports.sampleColorScheme=Wf;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Ax;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=Ab;exports.toPanelCursor=hl;exports.toPercent=Ve;exports.toSpec=tc;exports.toViewBoxX=dS;exports.toViewBoxY=de;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=Ns;exports.uniqueId=W;exports.unitToPolar=sr;exports.updateSpec=P;
|