diacode 0.2.3 → 0.3.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,16 @@
1
- import{M as M1,N as E1,O as A1,P as mc,Q as Bd,R as T1,T as Uy,U as O1,V as C1,W as Ky,X as Er,Y as Yy,Z as N1,L as mi,_ as jt,$ as xt,a0 as Xr,a1 as wr,a2 as Gy,S as Ta,a3 as Oa,a4 as Eo,a5 as I1,a6 as Vy,F as Br,a7 as L1,a8 as Xy,a9 as Jy,aa as fa,ab as ff,ac as F1,ad as da,y as Al,k as R1,I as Zy,ae as P1,l as Ao,a as Qy,af as z1,ag as df,u as ou,z as Ji,ah as D1,ai as eg,aj as j1,ak as W1,al as q1,am as tg,an as B1,ao as H1,ap as U1,aq as K1,ar as Y1,d as Ca,K as ng,as as Hd,r as G1,D as V1,at as X1,au as Li,av as J1,aw as Z1,x as Q1,ax as ew,ay as tw,A as nw,az as rg,c as rw,i as og,p as ow,aA as iw,aB as sw,v as hf,aC as aw,B as lw,aD as cw,n as uw,aE as fw,q as dw,o as hw,aF as pw,aG as yw,aH as gw,aI as mw,aJ as ig,aK as bw,H as ww,aL as Ud,aM as xw,C as vw,m as kw,J as bc,aN as sg,aO as Sw,aP as $w,aQ as _w,aR as Mw}from"./fonts-D2FlQA0D.js";const Kd=e=>e.kind==="context"||e.status==="done"||e.status==="cancelled",Ew=(e,t)=>e.edges.filter(n=>n.to===t&&Uy.has(n.kind??"needs")&&!n.passed),ag=e=>e.phase==="executing"||e.phase==="paused",Aw=e=>e.phase==="approved"||ag(e);function Tw(e){return e.kind==="approve"?`the person to approve ${e.from}'s result`:e.kind==="ask"?e.question?`the person's answer to the question asked before ${e.to}`:`you to ask the person before ${e.to} (step_ask)`:`input from the person${e.label?` (${e.label})`:""}`}const wc=e=>E1.has(e.op)||e.op==="plan.set"&&(e.title!==void 0||e.goal!==void 0),Yd=e=>e.phase==="approved"?"the person has approved the plan but has not started it: check the architecture against it and end your turn; they press Start when it is settled":"the plan is still a draft: the person approves it, then starts it. End your turn and say it is ready for review";let pf=class extends Error{};const Ne=e=>{throw new pf(e)};function Ow(e,t,n){for(let r=0;r<t.length;r++){const o=M1(t[r]);if(o.length)return{kind:"rejected",index:r,op:t[r],why:o.join("; ")}}if((Aw(e)||n.propose)&&n.actor!=="you"&&t.some(wc)){const r=t.filter(wc),o=t.filter(u=>!wc(u)),i=xc(e,r,{...n,actor:"you"});if(i.kind==="rejected")return{...i,index:t.indexOf(r[i.index])};const s={id:n.proposalId??`p${e.rev+1}`,by:n.actor,...n.at?{at:n.at}:{},...n.reason?{reason:n.reason}:{},ops:i.ops},a={...structuredClone(e),proposals:[...e.proposals??[],s]};if(!o.length)return{kind:"proposed",plan:{...a,rev:e.rev+1},proposal:s};const l=xc({...a,rev:e.rev},o,n);return l.kind==="rejected"?{...l,index:t.indexOf(o[l.index])}:l.kind==="applied"?{...l,proposal:s}:l}return xc(e,t,n)}function xc(e,t,n){const r=structuredClone(e),o={who:n,you:n.actor==="you",impact:new Map,touched:new Set,placements:[]},i=[];for(let s=0;s<t.length;s++)try{i.push(lg(r,t[s],o))}catch(a){if(a instanceof pf)return{kind:"rejected",index:s,op:t[s],why:a.message};throw a}return r.rev=e.rev+1,r.proposals&&!r.proposals.length&&delete r.proposals,{kind:"applied",plan:r,ops:i,impact:Cw(r,o),touched:[...o.touched].filter(s=>r.nodes[s]),placements:o.placements}}function Cw(e,t){return[...t.impact].filter(([n])=>e.nodes[n]&&e.nodes[n].kind!=="context"&&!t.touched.has(n)).map(([n,{distance:r,reasons:o}])=>({id:n,distance:r,reasons:[...o],done:e.nodes[n].status==="done"})).sort((n,r)=>n.distance-r.distance||n.id.localeCompare(r.id))}function lg(e,t,n){const{you:r,who:o}=n,i=c=>e.nodes[c]??Ne(`there is no step ${c}`),s=c=>!r&&e.nodes[c]?.status==="done",a=(c,d,f)=>{const p=n.impact.get(c);p?(p.distance=Math.min(p.distance,d),p.reasons.add(f)):n.impact.set(c,{distance:d,reasons:new Set([f])})},l=(c,d)=>{a(c,1,`${c} ${d}`);for(const[f,p]of mc(e,c))a(f,p+1,`${c} ${d}`)},u=(c,d,f)=>{for(const[p,h]of Object.entries(e.nodes))p!==c&&C1(d,h.files)&&a(p,1,`${c} ${f}`)};switch(t.op){case"node.add":{const c=t.id??T1(t.label,e.nodes);e.nodes[c]&&Ne(`step ${c} exists`);const d={label:t.label};t.kind==="context"&&(d.kind="context"),t.detail&&(d.detail=t.detail),t.group!==void 0&&(d.group=t.group),t.files?.length&&(d.files=t.files),t.touches?.length&&(d.touches=t.touches),e.nodes[c]=d;for(const f of t.after??[])Gd(e,f,c);return n.touched.add(c),{...t,id:c}}case"node.set":{const c=i(t.id);s(t.id)&&Ne(`${t.id} is done; only you can change it`);const d={label:c.label,kind:c.kind,detail:c.detail,files:c.files};if(t.label!==void 0&&(c.label=t.label),t.kind==="task"?delete c.kind:t.kind!==void 0&&(c.kind=t.kind),t.detail===""?delete c.detail:t.detail!==void 0&&(c.detail=t.detail),Array.isArray(t.files)&&!t.files.length?delete c.files:t.files!==void 0&&(c.files=t.files),Array.isArray(t.touches)&&!t.touches.length?delete c.touches:t.touches!==void 0&&(c.touches=t.touches),t.group===null?delete c.group:t.group!==void 0&&(c.group=t.group),c.kind==="context")for(const p of["status","statusFrom","statusBy","note","owner"])delete c[p];if(n.touched.add(t.id),c.kind!==d.kind||c.detail!==d.detail||JSON.stringify(c.files)!==JSON.stringify(d.files)){for(const[p,h]of mc(e,t.id,!0))a(p,h,`${t.id} changed`);u(t.id,[...d.files??[],...c.files??[]],"changed")}return t}case"node.remove":{const c=i(t.id);s(t.id)&&Ne(`${t.id} is done; only you can remove it`);for(const d of Bd(e,t.id))a(d,1,`${t.id} was removed`);return u(t.id,c.files,"was removed"),delete e.nodes[t.id],e.edges=e.edges.filter(d=>d.from!==t.id&&d.to!==t.id),t}case"edge.add":return s(t.to)&&Ne(`${t.to} is done; what it depended on is history`),Gd(e,t.from,t.to,t.label,t.kind,t.options),l(t.to,`now depends on ${t.from}`),t;case"edge.remove":{const c=ha(e,t.from,t.to);return s(c.to)&&Ne(`${c.to} is done; what it depended on is history`),e.edges.splice(e.edges.indexOf(c),1),l(t.to,`no longer depends on ${t.from}`),t}case"edge.rewire":case"edge.reverse":{const c=ha(e,t.from,t.to),d=t.op==="edge.reverse"?c.to:t.newFrom??c.from,f=t.op==="edge.reverse"?c.from:t.newTo??c.to;return(s(c.to)||s(f))&&Ne("a done step's prerequisites are history"),cg(e,d,f,c),c.from=d,c.to=f,pa(c),f===t.to?l(f,`now depends on ${d} instead of ${t.from}`):(l(t.to,`no longer depends on ${t.from}`),l(f,`now depends on ${d}`)),t}case"edge.set":{const c=ha(e,t.from,t.to);return t.label!==void 0&&(c.label=t.label),t.kind!==void 0&&t.kind!==(c.kind??"needs")&&(s(c.to)&&Ne(`${c.to} is done; what it depended on is history`),t.kind==="needs"?delete c.kind:c.kind=t.kind,pa(c)),t.options!==void 0&&(c.kind!=="ask"&&Ne(`${t.from} → ${t.to} is not an "ask" checkpoint; only one has options`),c.options=t.options),t}case"gate.pass":{r||Ne("only the person passes a checkpoint");const c=vc(e,t.from,t.to);return c.passed&&Ne(`the checkpoint ${t.from} → ${t.to} is passed already`),c.kind==="approve"&&!Kd(i(t.from))&&Ne(`${t.from} is not done: there is no result to approve yet`),c.passed=!0,t.answer&&(c.answer=t.answer),t}case"gate.ask":{const c=vc(e,t.from,t.to);return c.kind!=="ask"&&Ne(`${t.from} → ${t.to} is an "${c.kind}" checkpoint; only an "ask" one takes a question`),c.passed&&Ne(`the checkpoint ${t.from} → ${t.to} is passed already: ${t.to} can start`),c.question=t.question,t.options!==void 0&&(c.options=t.options),t}case"gate.reject":{r||Ne("only the person sends a step back");const c=vc(e,t.from,t.to);return c.kind!=="approve"&&Ne(`${t.from} → ${t.to} is an "${c.kind}" checkpoint; only an approval is withheld`),i(t.from).status!=="done"&&Ne(`${t.from} is not done: there is nothing to send back`),Vd(e,t.from,{status:"not_started",note:t.reason?`sent back: ${t.reason}`:"sent back: not approved",who:o}),t}case"status.set":{const c=i(t.id);if(c.kind==="context"&&Ne(`${t.id} is context; it has no status`),s(t.id)&&Ne(`${t.id} is done; only you can reopen it`),!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),t.status==="cancelled"&&!r&&Ne("only you cancel a step; an agent proposes removing it"),t.status==="in_progress"&&!r&&(e.phase==="planning"||e.phase==="approved")&&Ne(Yd(e)),t.status==="in_progress"&&!r&&e.phase==="paused"&&c.status!=="in_progress"&&Ne("the person paused the plan: start nothing new until they resume it. Finish the step you are on, if any, then end your turn"),(t.status==="in_progress"||t.status==="done")&&!r){const f=A1(e,t.id).filter(h=>!Kd(e.nodes[h]));f.length&&Ne(`${t.id} is blocked: ${f.join(", ")} unfinished${t.status==="done"?", so it cannot be finished yet":""}`);const p=Ew(e,t.id);p.length&&Ne(`${t.id} waits at a checkpoint: it needs ${p.map(Tw).join(", and ")}${t.status==="done"?", so it cannot be finished yet":""}`)}const d=c.status==="done";if(c.status=t.status,c.statusFrom=r?"you":o.via==="plugin"?"observed":"reported",c.statusBy=o.actor,t.note!==void 0?c.note=t.note:delete c.note,d&&t.status!=="done")for(const f of e.edges)f.from===t.id&&f.kind==="approve"&&pa(f);if(t.status==="failed")for(const[f,p]of mc(e,t.id))a(f,p,`${t.id} failed`);if(t.status==="cancelled")for(const f of Bd(e,t.id))a(f,1,`${t.id} was cancelled`);return t}case"claim":{const c=i(t.id);return c.kind==="context"&&Ne(`${t.id} is context; nobody works on it`),!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),!r&&e.phase==="paused"&&c.owner!==o.actor&&Ne("the person paused the plan: start nothing new until they resume it"),!r&&(e.phase==="planning"||e.phase==="approved")&&Ne(Yd(e)),c.owner=o.actor,t}case"release":{const c=i(t.id);return!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),delete c.owner,t}case"group.rename":{const c=Object.values(e.nodes).filter(d=>d.group===t.from);c.length||Ne(`there is no group "${t.from}"`);for(const d of c)d.group=t.to;return t}case"plan.set":if(t.phase!==void 0&&t.phase!==e.phase&&!r&&Ne("only you change the phase: approving the plan is yours"),t.phase==="paused"&&e.phase!=="paused"&&e.phase!=="executing"&&Ne("only a plan that is being carried out can be paused"),t.title!==void 0&&(e.title=t.title),t.goal!==void 0&&t.goal!==e.goal){e.goal=t.goal;for(const c of Object.keys(e.nodes))a(c,1,"the goal changed")}return t.phase!==void 0&&(e.phase=t.phase),t;case"plan.stop":r||Ne("only the person stops the plan"),ag(e)||Ne(`the plan is ${e.phase}, not running: there is nothing to stop`),e.phase="approved";for(const[c,d]of Object.entries(e.nodes))d.status==="in_progress"||d.status==="waiting"?Vd(e,c,{status:"not_started",note:"stopped by you",who:o}):d.owner&&delete d.owner;return t;case"layout.place":return r||Ne("only you place a step: the layout is yours"),i(t.id),n.placements.push({id:t.id,x:t.x,y:t.y}),t;case"proposal.accept":{r||Ne("only you accept a proposal");const c=(e.proposals??[]).find(d=>d.id===t.id)??Ne(`there is no proposal ${t.id}`);e.proposals=(e.proposals??[]).filter(d=>d!==c);for(const d of c.ops)try{lg(e,d,n)}catch(f){throw f instanceof pf&&Ne(`proposal ${t.id} no longer applies: ${f.message}`),f}return t}case"proposal.reject":return r||Ne("only you reject a proposal"),(e.proposals??[]).some(c=>c.id===t.id)||Ne(`there is no proposal ${t.id}`),e.proposals=(e.proposals??[]).filter(c=>c.id!==t.id),t;case"review":for(const c of t.ids)i(c).kind==="context"&&Ne(`${c} is context; there is nothing to review`);return t;default:return Ne(`"${t.op}" is not an op`)}}function ha(e,t,n){return e.edges.find(r=>r.from===t&&r.to===n)??Ne(`there is no dependency ${t} → ${n}`)}function cg(e,t,n,r){e.nodes[t]||Ne(`there is no step ${t}`),e.nodes[n]||Ne(`there is no step ${n}`),t===n&&Ne(`${t} cannot depend on itself`),e.edges.some(i=>i!==r&&i.from===t&&i.to===n)&&Ne(`${n} already depends on ${t}`);const o=r?{...e,edges:e.edges.filter(i=>i!==r)}:e;O1(o,n,t)&&Ne(`${t} → ${n} would make a loop`)}function Gd(e,t,n,r,o,i){cg(e,t,n),i&&o!=="ask"&&Ne('only an "ask" checkpoint has options'),e.edges.push({from:t,to:n,...r?{label:r}:{},...o&&o!=="needs"?{kind:o}:{},...i?{options:i}:{}})}function vc(e,t,n){const r=ha(e,t,n);return Uy.has(r.kind??"needs")||Ne(`${t} → ${n} is not a checkpoint`),r}function pa(e){delete e.question,delete e.options,delete e.passed,delete e.answer}function Vd(e,t,{status:n,note:r,who:o}){const i=e.nodes[t];if(i.status==="done")for(const s of e.edges)s.from===t&&s.kind==="approve"&&pa(s);i.status=n,i.statusFrom="you",i.statusBy=o.actor,i.note=r,delete i.owner}const Nw=100;function iu(e){if(Array.isArray(e))return`[${e.map(iu).join(", ")}]`;if(e&&typeof e=="object"){const t=Object.entries(e).map(([n,r])=>`${JSON.stringify(n)}: ${iu(r)}`);return t.length?`{ ${t.join(", ")} }`:"{}"}return JSON.stringify(e)}function su(e,t="",n=0,r=!1){const o=iu(e);if(!e||typeof e!="object"||r!==!0&&t.length+n+o.length<=Nw&&!Array.isArray(r))return o;const i=`${t} `;if(Array.isArray(e))return e.length?`[
1
+ import{M as M1,N as E1,O as A1,P as mc,Q as Bd,R as T1,T as Uy,U as O1,V as C1,W as Ky,X as Er,Y as Yy,Z as N1,L as mi,_ as Wt,$ as wt,a0 as Xr,a1 as wr,a2 as Gy,S as Ta,a3 as Oa,a4 as Eo,a5 as I1,a6 as Vy,F as Br,a7 as L1,a8 as Xy,a9 as Jy,aa as fa,ab as ff,ac as F1,ad as da,y as Al,k as R1,I as Zy,ae as P1,l as Ao,a as Qy,af as z1,ag as df,u as ou,z as Ji,ah as D1,ai as eg,aj as j1,ak as W1,al as q1,am as tg,an as B1,ao as H1,ap as U1,aq as K1,ar as Y1,d as Ca,K as ng,as as Hd,r as G1,D as V1,at as X1,au as Li,av as J1,aw as Z1,x as Q1,ax as ew,ay as tw,A as nw,az as rg,c as rw,i as og,p as ow,aA as iw,aB as sw,v as hf,aC as aw,B as lw,aD as cw,n as uw,aE as fw,q as dw,o as hw,aF as pw,aG as yw,aH as gw,aI as mw,aJ as ig,aK as bw,H as ww,aL as Ud,aM as xw,C as vw,m as kw,J as bc,aN as sg,aO as Sw,aP as $w,aQ as _w,aR as Mw}from"./fonts-B3jhzXCH.js";const Kd=e=>e.kind==="context"||e.status==="done"||e.status==="cancelled",Ew=(e,t)=>e.edges.filter(n=>n.to===t&&Uy.has(n.kind??"needs")&&!n.passed),ag=e=>e.phase==="executing"||e.phase==="paused",Aw=e=>e.phase==="approved"||ag(e);function Tw(e){return e.kind==="approve"?`the person to approve ${e.from}'s result`:e.kind==="ask"?e.question?`the person's answer to the question asked before ${e.to}`:`you to ask the person before ${e.to} (step_ask)`:`input from the person${e.label?` (${e.label})`:""}`}const wc=e=>E1.has(e.op)||e.op==="plan.set"&&(e.title!==void 0||e.goal!==void 0),Yd=e=>e.phase==="approved"?"the person has approved the plan but has not started it: check the architecture against it and end your turn; they press Start when it is settled":"the plan is still a draft: the person approves it, then starts it. End your turn and say it is ready for review";let pf=class extends Error{};const Ne=e=>{throw new pf(e)};function Ow(e,t,n){for(let r=0;r<t.length;r++){const o=M1(t[r]);if(o.length)return{kind:"rejected",index:r,op:t[r],why:o.join("; ")}}if((Aw(e)||n.propose)&&n.actor!=="you"&&t.some(wc)){const r=t.filter(wc),o=t.filter(u=>!wc(u)),i=xc(e,r,{...n,actor:"you"});if(i.kind==="rejected")return{...i,index:t.indexOf(r[i.index])};const s={id:n.proposalId??`p${e.rev+1}`,by:n.actor,...n.at?{at:n.at}:{},...n.reason?{reason:n.reason}:{},ops:i.ops},a={...structuredClone(e),proposals:[...e.proposals??[],s]};if(!o.length)return{kind:"proposed",plan:{...a,rev:e.rev+1},proposal:s};const l=xc({...a,rev:e.rev},o,n);return l.kind==="rejected"?{...l,index:t.indexOf(o[l.index])}:l.kind==="applied"?{...l,proposal:s}:l}return xc(e,t,n)}function xc(e,t,n){const r=structuredClone(e),o={who:n,you:n.actor==="you",impact:new Map,touched:new Set,placements:[]},i=[];for(let s=0;s<t.length;s++)try{i.push(lg(r,t[s],o))}catch(a){if(a instanceof pf)return{kind:"rejected",index:s,op:t[s],why:a.message};throw a}return r.rev=e.rev+1,r.proposals&&!r.proposals.length&&delete r.proposals,{kind:"applied",plan:r,ops:i,impact:Cw(r,o),touched:[...o.touched].filter(s=>r.nodes[s]),placements:o.placements}}function Cw(e,t){return[...t.impact].filter(([n])=>e.nodes[n]&&e.nodes[n].kind!=="context"&&!t.touched.has(n)).map(([n,{distance:r,reasons:o}])=>({id:n,distance:r,reasons:[...o],done:e.nodes[n].status==="done"})).sort((n,r)=>n.distance-r.distance||n.id.localeCompare(r.id))}function lg(e,t,n){const{you:r,who:o}=n,i=c=>e.nodes[c]??Ne(`there is no step ${c}`),s=c=>!r&&e.nodes[c]?.status==="done",a=(c,d,f)=>{const p=n.impact.get(c);p?(p.distance=Math.min(p.distance,d),p.reasons.add(f)):n.impact.set(c,{distance:d,reasons:new Set([f])})},l=(c,d)=>{a(c,1,`${c} ${d}`);for(const[f,p]of mc(e,c))a(f,p+1,`${c} ${d}`)},u=(c,d,f)=>{for(const[p,h]of Object.entries(e.nodes))p!==c&&C1(d,h.files)&&a(p,1,`${c} ${f}`)};switch(t.op){case"node.add":{const c=t.id??T1(t.label,e.nodes);e.nodes[c]&&Ne(`step ${c} exists`);const d={label:t.label};t.kind==="context"&&(d.kind="context"),t.detail&&(d.detail=t.detail),t.group!==void 0&&(d.group=t.group),t.files?.length&&(d.files=t.files),t.touches?.length&&(d.touches=t.touches),e.nodes[c]=d;for(const f of t.after??[])Gd(e,f,c);return n.touched.add(c),{...t,id:c}}case"node.set":{const c=i(t.id);s(t.id)&&Ne(`${t.id} is done; only you can change it`);const d={label:c.label,kind:c.kind,detail:c.detail,files:c.files};if(t.label!==void 0&&(c.label=t.label),t.kind==="task"?delete c.kind:t.kind!==void 0&&(c.kind=t.kind),t.detail===""?delete c.detail:t.detail!==void 0&&(c.detail=t.detail),Array.isArray(t.files)&&!t.files.length?delete c.files:t.files!==void 0&&(c.files=t.files),Array.isArray(t.touches)&&!t.touches.length?delete c.touches:t.touches!==void 0&&(c.touches=t.touches),t.group===null?delete c.group:t.group!==void 0&&(c.group=t.group),c.kind==="context")for(const p of["status","statusFrom","statusBy","note","owner"])delete c[p];if(n.touched.add(t.id),c.kind!==d.kind||c.detail!==d.detail||JSON.stringify(c.files)!==JSON.stringify(d.files)){for(const[p,h]of mc(e,t.id,!0))a(p,h,`${t.id} changed`);u(t.id,[...d.files??[],...c.files??[]],"changed")}return t}case"node.remove":{const c=i(t.id);s(t.id)&&Ne(`${t.id} is done; only you can remove it`);for(const d of Bd(e,t.id))a(d,1,`${t.id} was removed`);return u(t.id,c.files,"was removed"),delete e.nodes[t.id],e.edges=e.edges.filter(d=>d.from!==t.id&&d.to!==t.id),t}case"edge.add":return s(t.to)&&Ne(`${t.to} is done; what it depended on is history`),Gd(e,t.from,t.to,t.label,t.kind,t.options),l(t.to,`now depends on ${t.from}`),t;case"edge.remove":{const c=ha(e,t.from,t.to);return s(c.to)&&Ne(`${c.to} is done; what it depended on is history`),e.edges.splice(e.edges.indexOf(c),1),l(t.to,`no longer depends on ${t.from}`),t}case"edge.rewire":case"edge.reverse":{const c=ha(e,t.from,t.to),d=t.op==="edge.reverse"?c.to:t.newFrom??c.from,f=t.op==="edge.reverse"?c.from:t.newTo??c.to;return(s(c.to)||s(f))&&Ne("a done step's prerequisites are history"),cg(e,d,f,c),c.from=d,c.to=f,pa(c),f===t.to?l(f,`now depends on ${d} instead of ${t.from}`):(l(t.to,`no longer depends on ${t.from}`),l(f,`now depends on ${d}`)),t}case"edge.set":{const c=ha(e,t.from,t.to);return t.label!==void 0&&(c.label=t.label),t.kind!==void 0&&t.kind!==(c.kind??"needs")&&(s(c.to)&&Ne(`${c.to} is done; what it depended on is history`),t.kind==="needs"?delete c.kind:c.kind=t.kind,pa(c)),t.options!==void 0&&(c.kind!=="ask"&&Ne(`${t.from} → ${t.to} is not an "ask" checkpoint; only one has options`),c.options=t.options),t}case"gate.pass":{r||Ne("only the person passes a checkpoint");const c=vc(e,t.from,t.to);return c.passed&&Ne(`the checkpoint ${t.from} → ${t.to} is passed already`),c.kind==="approve"&&!Kd(i(t.from))&&Ne(`${t.from} is not done: there is no result to approve yet`),c.passed=!0,t.answer&&(c.answer=t.answer),t}case"gate.ask":{const c=vc(e,t.from,t.to);return c.kind!=="ask"&&Ne(`${t.from} → ${t.to} is an "${c.kind}" checkpoint; only an "ask" one takes a question`),c.passed&&Ne(`the checkpoint ${t.from} → ${t.to} is passed already: ${t.to} can start`),c.question=t.question,t.options!==void 0&&(c.options=t.options),t}case"gate.reject":{r||Ne("only the person sends a step back");const c=vc(e,t.from,t.to);return c.kind!=="approve"&&Ne(`${t.from} → ${t.to} is an "${c.kind}" checkpoint; only an approval is withheld`),i(t.from).status!=="done"&&Ne(`${t.from} is not done: there is nothing to send back`),Vd(e,t.from,{status:"not_started",note:t.reason?`sent back: ${t.reason}`:"sent back: not approved",who:o}),t}case"status.set":{const c=i(t.id);if(c.kind==="context"&&Ne(`${t.id} is context; it has no status`),s(t.id)&&Ne(`${t.id} is done; only you can reopen it`),!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),t.status==="cancelled"&&!r&&Ne("only you cancel a step; an agent proposes removing it"),t.status==="in_progress"&&!r&&(e.phase==="planning"||e.phase==="approved")&&Ne(Yd(e)),t.status==="in_progress"&&!r&&e.phase==="paused"&&c.status!=="in_progress"&&Ne("the person paused the plan: start nothing new until they resume it. Finish the step you are on, if any, then end your turn"),(t.status==="in_progress"||t.status==="done")&&!r){const f=A1(e,t.id).filter(h=>!Kd(e.nodes[h]));f.length&&Ne(`${t.id} is blocked: ${f.join(", ")} unfinished${t.status==="done"?", so it cannot be finished yet":""}`);const p=Ew(e,t.id);p.length&&Ne(`${t.id} waits at a checkpoint: it needs ${p.map(Tw).join(", and ")}${t.status==="done"?", so it cannot be finished yet":""}`)}const d=c.status==="done";if(c.status=t.status,c.statusFrom=r?"you":o.via==="plugin"?"observed":"reported",c.statusBy=o.actor,t.note!==void 0?c.note=t.note:delete c.note,d&&t.status!=="done")for(const f of e.edges)f.from===t.id&&f.kind==="approve"&&pa(f);if(t.status==="failed")for(const[f,p]of mc(e,t.id))a(f,p,`${t.id} failed`);if(t.status==="cancelled")for(const f of Bd(e,t.id))a(f,1,`${t.id} was cancelled`);return t}case"claim":{const c=i(t.id);return c.kind==="context"&&Ne(`${t.id} is context; nobody works on it`),!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),!r&&e.phase==="paused"&&c.owner!==o.actor&&Ne("the person paused the plan: start nothing new until they resume it"),!r&&(e.phase==="planning"||e.phase==="approved")&&Ne(Yd(e)),c.owner=o.actor,t}case"release":{const c=i(t.id);return!r&&c.owner&&c.owner!==o.actor&&Ne(`${t.id} is ${c.owner}'s`),delete c.owner,t}case"group.rename":{const c=Object.values(e.nodes).filter(d=>d.group===t.from);c.length||Ne(`there is no group "${t.from}"`);for(const d of c)d.group=t.to;return t}case"plan.set":if(t.phase!==void 0&&t.phase!==e.phase&&!r&&Ne("only you change the phase: approving the plan is yours"),t.phase==="paused"&&e.phase!=="paused"&&e.phase!=="executing"&&Ne("only a plan that is being carried out can be paused"),t.title!==void 0&&(e.title=t.title),t.goal!==void 0&&t.goal!==e.goal){e.goal=t.goal;for(const c of Object.keys(e.nodes))a(c,1,"the goal changed")}return t.phase!==void 0&&(e.phase=t.phase),t;case"plan.stop":r||Ne("only the person stops the plan"),ag(e)||Ne(`the plan is ${e.phase}, not running: there is nothing to stop`),e.phase="approved";for(const[c,d]of Object.entries(e.nodes))d.status==="in_progress"||d.status==="waiting"?Vd(e,c,{status:"not_started",note:"stopped by you",who:o}):d.owner&&delete d.owner;return t;case"layout.place":return r||Ne("only you place a step: the layout is yours"),i(t.id),n.placements.push({id:t.id,x:t.x,y:t.y}),t;case"proposal.accept":{r||Ne("only you accept a proposal");const c=(e.proposals??[]).find(d=>d.id===t.id)??Ne(`there is no proposal ${t.id}`);e.proposals=(e.proposals??[]).filter(d=>d!==c);for(const d of c.ops)try{lg(e,d,n)}catch(f){throw f instanceof pf&&Ne(`proposal ${t.id} no longer applies: ${f.message}`),f}return t}case"proposal.reject":return r||Ne("only you reject a proposal"),(e.proposals??[]).some(c=>c.id===t.id)||Ne(`there is no proposal ${t.id}`),e.proposals=(e.proposals??[]).filter(c=>c.id!==t.id),t;case"review":for(const c of t.ids)i(c).kind==="context"&&Ne(`${c} is context; there is nothing to review`);return t;default:return Ne(`"${t.op}" is not an op`)}}function ha(e,t,n){return e.edges.find(r=>r.from===t&&r.to===n)??Ne(`there is no dependency ${t} → ${n}`)}function cg(e,t,n,r){e.nodes[t]||Ne(`there is no step ${t}`),e.nodes[n]||Ne(`there is no step ${n}`),t===n&&Ne(`${t} cannot depend on itself`),e.edges.some(i=>i!==r&&i.from===t&&i.to===n)&&Ne(`${n} already depends on ${t}`);const o=r?{...e,edges:e.edges.filter(i=>i!==r)}:e;O1(o,n,t)&&Ne(`${t} → ${n} would make a loop`)}function Gd(e,t,n,r,o,i){cg(e,t,n),i&&o!=="ask"&&Ne('only an "ask" checkpoint has options'),e.edges.push({from:t,to:n,...r?{label:r}:{},...o&&o!=="needs"?{kind:o}:{},...i?{options:i}:{}})}function vc(e,t,n){const r=ha(e,t,n);return Uy.has(r.kind??"needs")||Ne(`${t} → ${n} is not a checkpoint`),r}function pa(e){delete e.question,delete e.options,delete e.passed,delete e.answer}function Vd(e,t,{status:n,note:r,who:o}){const i=e.nodes[t];if(i.status==="done")for(const s of e.edges)s.from===t&&s.kind==="approve"&&pa(s);i.status=n,i.statusFrom="you",i.statusBy=o.actor,i.note=r,delete i.owner}const Nw=100;function iu(e){if(Array.isArray(e))return`[${e.map(iu).join(", ")}]`;if(e&&typeof e=="object"){const t=Object.entries(e).map(([n,r])=>`${JSON.stringify(n)}: ${iu(r)}`);return t.length?`{ ${t.join(", ")} }`:"{}"}return JSON.stringify(e)}function su(e,t="",n=0,r=!1){const o=iu(e);if(!e||typeof e!="object"||r!==!0&&t.length+n+o.length<=Nw&&!Array.isArray(r))return o;const i=`${t} `;if(Array.isArray(e))return e.length?`[
2
2
  ${e.map(a=>i+su(a,i)).join(`,
3
3
  `)}
4
4
  ${t}]`:"[]";const s=Object.entries(e);return s.length?`{
5
5
  ${s.map(([a,l])=>{const u=`${JSON.stringify(a)}: `;return i+u+su(l,i,u.length,Array.isArray(r)&&r.includes(a))}).join(`,
6
6
  `)}
7
7
  ${t}}`:"{}"}const xo={left:16,right:16,top:32,bottom:14},Na={LR:{gap:74,cross:34,pad:40},TD:{gap:44,cross:60,pad:40}},kc={chars:26,fontSize:10.5,pad:26},Iw=e=>Math.min(String(e??"").length,kc.chars)*kc.fontSize*ug+kc.pad,rr={padding:9,maxWidth:168,minWidth:66,minHeight:34,fontSize:12.5},ug=.55,Xd=24,Lw=1.28,Fw=e=>{const t=Rw(e);return{w:t.width,h:t.height}};function Rw(e){const t=String(e??""),n=rr.maxWidth-rr.padding*2,r=t.length*rr.fontSize*ug,o=Math.max(rr.minWidth,Math.min(rr.maxWidth,r+rr.padding*2)),i=Math.max(1,Math.ceil(r/n)),s=Math.max(rr.minHeight,i*rr.fontSize*Lw+rr.padding*2);return{width:o,height:s}}function Pw(e,t){const n=new Map(e.map(i=>[i.id,[]]));for(const i of t)n.has(i.source)&&n.has(i.target)&&n.get(i.source).push(i);const r=new Map(e.map(i=>[i.id,0])),o=new Set;for(const i of e){if(r.get(i.id)!==0)continue;const s=[{id:i.id,i:0}];for(r.set(i.id,1);s.length;){const a=s[s.length-1],l=n.get(a.id);if(a.i>=l.length){r.set(a.id,2),s.pop();continue}const u=l[a.i++];r.get(u.target)===1?o.add(u):r.get(u.target)===0&&(r.set(u.target,1),s.push({id:u.target,i:0}))}}return t.filter(i=>!o.has(i))}function Jd(e,t){const n=new Map(e.map(l=>[l.id,0])),r=new Map(e.map(l=>[l.id,[]]));for(const l of t)!n.has(l.source)||!n.has(l.target)||(n.set(l.target,n.get(l.target)+1),r.get(l.source).push(l.target));const o=new Map(e.map(l=>[l.id,0])),i=e.filter(l=>n.get(l.id)===0).map(l=>l.id),s=new Map(n),a=[];for(;i.length;){const l=i.shift();a.push(l);for(const u of r.get(l))o.set(u,Math.max(o.get(u),o.get(l)+1)),s.set(u,s.get(u)-1),s.get(u)===0&&i.push(u)}if(a.length!==e.length)throw new Error("the plan loops, so it has no layers");return o}function zw(e,t,n){const r=new Map;for(const u of e){const c=n.get(u.id);r.has(c)||r.set(c,[]),r.get(c).push(u.id)}const o=[...r.keys()].sort((u,c)=>u-c),i=new Map;for(const u of o)r.get(u).forEach((c,d)=>i.set(c,d));const s=new Map(e.map(u=>[u.id,[]])),a=new Map(e.map(u=>[u.id,[]]));for(const u of t)!s.has(u.target)||!a.has(u.source)||(s.get(u.target).push(u.source),a.get(u.source).push(u.target));const l=(u,c)=>{const d=c==="up"?s.get(u):a.get(u);return d.length?d.reduce((f,p)=>f+i.get(p),0)/d.length:i.get(u)};for(let u=0;u<8;u++){const c=u%2===0?"up":"down",d=c==="up"?o:[...o].reverse();for(const f of d){const p=r.get(f),h=p.map(y=>[y,l(y,c)]);h.sort((y,g)=>y[1]-g[1]||p.indexOf(y[0])-p.indexOf(g[0])),r.set(f,h.map(([y])=>y)),r.get(f).forEach((y,g)=>i.set(y,g))}}return{byRank:r,ranks:o}}function Dw(e,t,n,r=!1){let o=e,i=t;if(r){const L=Jd(e.map(O=>({id:O.id,label:O.label})),t),N=[],I=[];for(const O of t){const M=L.get(O.source),$=L.get(O.target);if($-M<=1){I.push(O);continue}let F=O.source;for(let D=M+1;D<$;D++){const z=`\0lane:${O.source}${O.target}${D}`;N.push({id:z,label:"",w:Xd,h:Xd}),I.push({source:F,target:z}),F=z}I.push({source:F,target:O.target,...O.label?{label:O.label}:{}})}o=[...e,...N],i=I}const s=o.map(L=>({id:L.id,label:L.label})),a=Jd(s,i),{byRank:l,ranks:u}=zw(s,i,a),c=Na[n]||Na.LR,d=L=>o.find(N=>N.id===L),f=L=>n==="LR"?L.w:L.h,p=L=>n==="LR"?L.h:L.w,h=Math.max(...e.map(p))+c.cross,y=L=>l.get(L),g=Math.max(...u.map(L=>y(L).length)),m=h*g,b=new Map;for(const L of u)for(const N of y(L))b.set(N,L);const w=L=>Math.max(0,...i.filter(N=>b.get(N.source)===L&&N.label).map(N=>Iw(N.label))),x=new Map;let S=0,v=0;for(const L of u){const N=Math.max(...y(L).map(I=>f(d(I))));x.set(L,S+N/2),v=n==="LR"?Math.max(c.gap,w(L)):c.gap,S+=N+v}const k=S-v,_=(L,N)=>m/2-h*(N-1)/2+h*L,T=new Map;for(const L of u){const N=y(L);N.forEach((I,O)=>{const M=x.get(L),$=_(O,N.length);T.set(I,n==="LR"?{x:M,y:$}:{x:$,y:M})})}return n==="LR"?{at:T,width:k,height:m}:{at:T,width:m,height:k}}function fg(e,t,n,r,o,i=!1){const s=new Map,a=[],l=new Map,u=new Map;for(const h of e){const y=h.path?.[n];if(y===void 0)a.push({id:h.id,label:h.label,...Fw(h.label)}),l.set(h.id,h.id);else{const g=s.get(y);g?g.push(h):s.set(y,[h])}}for(const[h,y]of s){const g=`\0frame:${h}`,m=fg(y,t,n+1,r,o,i);u.set(g,m),a.push({id:g,label:h,w:m.width+xo.left+xo.right,h:m.height+xo.top+xo.bottom});for(const b of y)l.set(b.id,g)}let c=[];const d=new Set;for(const h of t){const y=l.get(h.source),g=l.get(h.target);y===void 0||g===void 0||y===g||d.has(`${y}${g}`)||(d.add(`${y}${g}`),c.push({source:y,target:g,...h.label?{label:h.label}:{}}))}o&&(c=Pw(a,c));const f=Dw(a,c,r,i),p=new Map;for(const h of e){const y=l.get(h.id),g=f.at.get(y),m=u.get(y);if(!m){p.set(h.id,g);continue}const b=a.find(v=>v.id===y),w=g.x-b.w/2+xo.left,x=g.y-b.h/2+xo.top,S=m.at.get(h.id);p.set(h.id,{x:w+S.x,y:x+S.y})}return{at:p,width:f.width,height:f.height}}function jw({steps:e,depends:t,direction:n="LR",loops:r=!1}){if(!e.length)return{canvas:{width:0,height:0},positions:new Map};const o=Na[n]||Na.LR,i=fg(e,t,0,n,r||e.some(a=>a.path?.length),!0),s=new Map;for(const[a,l]of i.at)s.set(a,{x:Math.round(l.x+o.pad),y:Math.round(l.y+o.pad)});return{canvas:{width:Math.round(i.width+o.pad*2),height:Math.round(i.height+o.pad*2)},positions:s}}const _r={along:230,across:72},Bs={along:90,across:50},Zd={x:70,y:55},Ww={width:640,height:240};function dg(e,t,{paths:n,loops:r=!1}={}){const o=t.direction==="TD",i=m=>o?{along:m.y,across:m.x}:{along:m.x,across:m.y},s=(m,b)=>o?{x:b,y:m}:{x:m,y:b},a={};for(const[m,b]of Object.entries(t.nodes))e.nodes[m]&&(a[m]=b);const l=[],u=new Set,c=new Set(Object.keys(e.nodes).filter(m=>!a[m])),d=new Map;for(const m of Object.values(e.nodes))m.group&&d.set(m.group,(d.get(m.group)??0)+1);const f=m=>{const b=e.nodes[m]?.group;return b&&d.get(b)>1?b:void 0},p=m=>(n?n[m]?.[0]:f(m))??"",h=new Set(Object.keys(a).map(p)),y=n!==void 0&&[...c].some(m=>p(m)!==""&&!h.has(p(m))),g=Object.values(a).some(m=>m.pinned);if(c.size&&y&&!g)for(const m of Object.keys(a))delete a[m];if(c.size&&!Object.keys(a).length){const{positions:m,canvas:b}=jw({steps:Object.entries(e.nodes).map(([w,x])=>({id:w,label:x.label,path:n?n[w]:f(w)?[f(w)]:[]})),depends:e.edges.map(w=>({source:w.from,target:w.to,label:w.label})),direction:t.direction,loops:r});for(const[w,x]of m)a[w]=x;return{layout:{...t,nodes:a,canvas:Qd(a,b)},placed:[...m.keys()],moved:[]}}for(;c.size;){const m=[...c].find(I=>e.edges.every(O=>O.to!==I||a[O.from]))??[...c][0];c.delete(m);const b=e.edges.filter(I=>I.to===m&&a[I.from]).map(I=>i(a[I.from])),w=e.edges.filter(I=>I.from===m&&a[I.to]).map(I=>I.to);let x=b.length?Math.max(...b.map(I=>I.along))+_r.along:Bs.along;!b.length&&w.length&&(x=Math.max(Bs.along,Math.min(...w.map(I=>i(a[I]).along))-_r.along));const S=b.length?b:w.map(I=>i(a[I])),v=S.length?S.reduce((I,O)=>I+O.across,0)/S.length:Bs.across,k=new Set,_=(I,O)=>{const M=i(a[I]);if(!(M.along>=O||a[I].pinned||k.has(I))){k.add(I),a[I]={...a[I],...s(O,M.across)},u.add(I);for(const $ of e.edges)$.from===I&&a[$.to]&&!c.has($.to)&&_($.to,O+_r.along)}};for(const I of w)_(I,x+_r.along);const T=p(m),L=Object.entries(a).filter(([,I])=>Math.abs(i(I).along-x)<_r.along/2).map(([I,O])=>({across:i(O).across,gap:p(I)===T?_r.across*.9:_r.across*1.9}));let N=v;for(let I=0;L.some(O=>Math.abs(O.across-N)<O.gap);I++){const O=Math.ceil((I+1)/2)*(I%2===0?1:-1)*_r.across;N=Math.max(Bs.across,v+O)}a[m]={...s(Math.round(x),Math.round(N))},l.push(m)}for(const m of l)u.delete(m);return{layout:{...t,nodes:a,canvas:Qd(a,t.canvas)},placed:l,moved:[...u]}}function Qd(e,t=Ww){const n=Object.values(e),r=Math.max(t.width,...n.map(i=>i.x+Zd.x)),o=Math.max(t.height,...n.map(i=>i.y+Zd.y));return{width:Math.round(r),height:Math.round(o)}}function hg(e,t,n){const r={applies:!0,addedNodes:[],addedEdges:[],removedNodes:[],removedEdges:[],changedNodes:[]},o=Ow(e,n,{actor:"you",via:"editor"});if(o.kind!=="applied")return{...r,applies:!1,why:o.kind==="rejected"?`${o.why}`:"it is not a change you can apply"};const i=o.plan,{layout:s}=dg(i,t);for(const[c,d]of Object.entries(i.nodes)){const f=e.nodes[c];if(!f){const h=s.nodes[c]??{x:0,y:0};r.addedNodes.push({id:c,label:d.label,...d.kind==="context"?{kind:"context"}:{},x:h.x,y:h.y});continue}const p=[];f.label!==d.label&&p.push("label"),f.detail!==d.detail&&p.push("detail"),JSON.stringify(f.files)!==JSON.stringify(d.files)&&p.push("files"),JSON.stringify(f.touches)!==JSON.stringify(d.touches)&&p.push("touches"),f.group!==d.group&&p.push("group"),f.kind!==d.kind&&p.push("kind"),p.length&&r.changedNodes.push({id:c,...p.includes("label")?{label:d.label}:{},what:p})}for(const c of Object.keys(e.nodes))i.nodes[c]||r.removedNodes.push(c);const a=c=>`${c.from}\0${c.to}`,l=new Set(e.edges.map(a)),u=new Set(i.edges.map(a));for(const c of i.edges)l.has(a(c))||r.addedEdges.push(c.label?{from:c.from,to:c.to,label:c.label}:{from:c.from,to:c.to});for(const c of e.edges)!u.has(a(c))&&i.nodes[c.from]&&i.nodes[c.to]&&r.removedEdges.push({from:c.from,to:c.to});return r}const qw=["Task","Architecture","Plan","Start","Running"],vo={arch:["schema","title","goal","rev","phase","source","nodes","edges","flows","proposals"],box:["label","kind","external","in","tech","detail","files","planned","retiring"],arrow:["from","to","label","tech","async","via","planned","retiring"],flow:["id","title","steps"],step:["from","to","label"],proposal:["id","by","at","reason","ops"]};function ko(e,t){const n={};for(const r of t)e[r]!==void 0&&(n[r]=e[r]);for(const r of Object.keys(e))!(r in n)&&e[r]!==void 0&&(n[r]=e[r]);return n}function Bw(e){return ko({...e,nodes:Object.fromEntries(Object.entries(e.nodes).map(([t,n])=>[t,ko(n,vo.box)])),edges:e.edges.map(t=>ko(t,vo.arrow)),flows:e.flows.map(t=>ko({...t,steps:t.steps.map(n=>ko(n,vo.step))},vo.flow)),proposals:e.proposals?.length?e.proposals.map(t=>ko(t,vo.proposal)):void 0},vo.arch)}const Hw=e=>`${su(Bw(e),"",0,["nodes","edges","flows","proposals"])}
8
- `,Hs=(e,t)=>JSON.stringify(e)===JSON.stringify(t),eh=e=>`${e.from}\0${e.to}`;function Us(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Sc(e,t){const n={};return(e.label??"")!==(t.label??"")&&(n.label=t.label??""),(e.tech??"")!==(t.tech??"")&&(n.tech=t.tech??""),!!e.async!=!!t.async&&(n.async=!!t.async),e.via!==t.via&&(n.via=t.via??null),e.planned!==t.planned&&(n.planned=t.planned??null),e.retiring!==t.retiring&&(n.retiring=t.retiring??null),Object.keys(n).length?{op:"arrow.set",from:t.from,to:t.to,...n}:null}function pg(e,t){const n=[],r=[],o={};for(const h of["title","goal","phase"])e[h]!==t[h]&&(t[h]!==void 0||h==="goal")&&(o[h]=t[h]??"");Object.keys(o).length&&n.push({op:"arch.set",...o}),t.rev!==e.rev&&r.push("rev (the server counts revisions)"),Hs(e.proposals??[],t.proposals??[])||r.push("proposals (accept or reject them instead)");const i=Object.keys(t.nodes).filter(h=>!(h in e.nodes)),s=Object.keys(e.nodes).filter(h=>!(h in t.nodes)),a=Object.keys(t.nodes).filter(h=>h in e.nodes);for(const h of i){const y=t.nodes[h];n.push(Us({op:"box.add",id:h,label:y.label,kind:y.kind,external:y.external,tech:y.tech,detail:y.detail,files:y.files,planned:y.planned,retiring:y.retiring}))}for(const h of a)e.nodes[h].in!==void 0&&e.nodes[h].in!==t.nodes[h].in&&n.push({op:"box.set",id:h,in:null});const l=new Map(e.edges.map(h=>[eh(h),h])),u=new Map(t.edges.map(h=>[eh(h),h])),c=[...l].filter(([h,y])=>!u.has(h)&&y.from in t.nodes&&y.to in t.nodes).map(([,h])=>h),d=[...u].filter(([h])=>!l.has(h)).map(([,h])=>h);for(const h of[...c]){const y=d.find(m=>m.from===h.to&&m.to===h.from);if(!y)continue;n.push({op:"arrow.reverse",from:h.from,to:h.to});const g=Sc({...h,from:y.from,to:y.to},y);g&&n.push(g),c.splice(c.indexOf(h),1),d.splice(d.indexOf(y),1)}for(const h of[...c]){const y=d.find(m=>m.from===h.from||m.to===h.to);if(!y)continue;n.push(Us({op:"arrow.rewire",from:h.from,to:h.to,newFrom:y.from!==h.from?y.from:void 0,newTo:y.to!==h.to?y.to:void 0}));const g=Sc({...h,from:y.from,to:y.to},y);g&&n.push(g),c.splice(c.indexOf(h),1),d.splice(d.indexOf(y),1)}for(const h of c)n.push({op:"arrow.remove",from:h.from,to:h.to});for(const h of s)n.push({op:"box.remove",id:h});for(const h of a){const y=e.nodes[h],g=t.nodes[h],m={};y.label!==g.label&&(m.label=g.label),y.kind!==g.kind&&(m.kind=g.kind),(y.tech??"")!==(g.tech??"")&&(m.tech=g.tech??""),(y.detail??"")!==(g.detail??"")&&(m.detail=g.detail??""),Hs(y.files??[],g.files??[])||(m.files=g.files??[]),!!y.external!=!!g.external&&(m.external=!!g.external),y.retiring!==g.retiring&&g.retiring===void 0&&(m.retiring=null),y.planned!==g.planned&&g.planned===void 0&&(m.planned=null),Object.keys(m).length&&n.push({op:"box.set",id:h,...m});const b={};y.planned!==g.planned&&g.planned!==void 0&&(b.planned=g.planned),y.retiring!==g.retiring&&g.retiring!==void 0&&(b.retiring=g.retiring),Object.keys(b).length&&n.push({op:"box.set",id:h,...b})}for(const h of[...a,...i]){const y=t.nodes[h].in,g=i.includes(h)?void 0:e.nodes[h].in;y!==void 0&&y!==g&&n.push({op:"box.set",id:h,in:y})}for(const h of d)n.push(Us({op:"arrow.add",from:h.from,to:h.to,label:h.label,tech:h.tech,async:h.async,via:h.via,planned:h.planned,retiring:h.retiring}));for(const[h,y]of u){const g=l.get(h),m=g&&Sc(g,y);m&&n.push(m)}const f=new Map(e.flows.map(h=>[h.id,h])),p=new Map(t.flows.map(h=>[h.id,h]));for(const[h,y]of p){const g=f.get(h),m=g?g.steps.filter(b=>!s.includes(b.from)&&!s.includes(b.to)):[];!g||!m.length?n.push({op:"flow.add",id:h,title:y.title,steps:y.steps}):(g.title!==y.title||!Hs(m,y.steps))&&n.push(Us({op:"flow.set",id:h,title:g.title!==y.title?y.title:void 0,steps:Hs(m,y.steps)?void 0:y.steps}))}for(const[h,y]of f)!p.has(h)&&y.steps.some(g=>!s.includes(g.from)&&!s.includes(g.to))&&n.push({op:"flow.remove",id:h});return{ops:n,ignored:r}}const Uw=e=>Object.keys(e.nodes).filter(t=>!Er(e,t));function au(e,t){const n=Uw(e),r={nodes:Object.fromEntries(n.map(a=>[a,e.nodes[a]])),edges:e.edges},o=Object.fromEntries(n.map(a=>[a,Ky(e,a).reverse()])),i=dg(r,t,{paths:o,loops:!0}),s=(t.collapsed??[]).filter(a=>Er(e,a));return{...i,layout:{...i.layout,...s.length?{collapsed:s}:{}}}}function th(e,t,n){const r={applies:!0,addedNodes:[],addedEdges:[],removedNodes:[],removedEdges:[],changedNodes:[]},o=Yy(e,n,{actor:"you",via:"editor"});if(o.kind!=="applied")return{...r,applies:!1,why:o.kind==="rejected"?o.why:"it is not a change you can apply"};const i=o.arch,{layout:s}=au(i,t);for(const[c,d]of Object.entries(i.nodes)){const f=e.nodes[c];if(!f){const h=s.nodes[c]??{x:0,y:0};r.addedNodes.push({id:c,label:d.label,kind:d.kind,x:h.x,y:h.y});continue}const p=[];f.label!==d.label&&p.push("label"),f.kind!==d.kind&&p.push("kind"),f.tech!==d.tech&&p.push("tech"),f.detail!==d.detail&&p.push("detail"),JSON.stringify(f.files)!==JSON.stringify(d.files)&&p.push("files"),f.in!==d.in&&p.push("place"),!!f.external!=!!d.external&&p.push("external"),(f.planned!==d.planned||f.retiring!==d.retiring)&&p.push("plan"),p.length&&r.changedNodes.push({id:c,...p.includes("label")?{label:d.label}:{},what:p})}for(const c of Object.keys(e.nodes))i.nodes[c]||r.removedNodes.push(c);const a=c=>`${c.from}\0${c.to}`,l=new Set(e.edges.map(a)),u=new Set(i.edges.map(a));for(const c of i.edges)l.has(a(c))||r.addedEdges.push(c.label?{from:c.from,to:c.to,label:c.label}:{from:c.from,to:c.to});for(const c of e.edges)!u.has(a(c))&&i.nodes[c.from]&&i.nodes[c.to]&&r.removedEdges.push({from:c.from,to:c.to});return r}const Jr=[],nh={id:"",title:"",plan:"",repo:"",source:"",direction:"LR",note:"",canvas:{width:640,height:360},steps:[],depends:[]},Tl=e=>Jr.find(t=>t.id===e)||Jr[0],Fi=e=>({steps:e.steps.map(t=>({...t})),depends:e.depends.map(t=>({...t}))}),Zi=[],yf=e=>Zi.find(t=>t.id===e)||Zi[0];function Kw(e){const t=o=>e()?.plan.nodes[o.id],n=o=>t(o)?.kind==="context"?"context":t(o)?.status??"not_started",r=o=>mi[n(o)];return{stroke:o=>r(o)?.edge?r(o).colour:void 0,strokeWidth:o=>r(o)?.edge?3:void 0,opacity:o=>n(o)==="context"?.55:1,look:o=>{const i=r(o),s=o.id;return{status:n(o),...i?{colour:i.colour,icon:i.icon,word:i.word,strike:i.strike}:{},review:s in(e()?.review??{}),atRisk:s in(e()?.derived.atRisk??{})}},owner:o=>N1(t(o)&&{status:"not_started",...t(o)},{stalled:e()?.derived.stalled?.[o.id]?.state,blockedOn:e()?.derived.blocked?.[o.id],held:e()?.derived.held?.[o.id]}),arrow:o=>(e()?.derived.gates??[]).some(i=>i.from===o.source&&i.to===o.target&&i.turn==="you")?"yours":"",frozen:(o,i)=>i==="depends"?n({id:o.target})==="done":n(o)==="done"}}class Yw{constructor(){this.children=[]}add(t){this.children.push(t)}clear(){this.children=[]}}const rh=e=>[e.hit?0:1,typeof e.index=="number"?e.index:-1];function oh(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n].glyph;if(!r){t.push(...e[n].nodes);continue}const o=[];let i=n;for(;i<e.length&&e[i].glyph===r;)o.push(...e[i].nodes),i++;n=i-1,o.sort((s,a)=>{const[l,u]=rh(s),[c,d]=rh(a);return l!==c?l-c:u-d}),t.push(...o)}return t.some(n=>n&&n.raise)?[...t.filter(n=>!(n&&n.raise)),...t.filter(n=>n&&n.raise)]:t}function ya(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Gw(e,t){return e==null||t==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function gf(e){let t,n,r;e.length!==2?(t=ya,n=(a,l)=>ya(e(a),l),r=(a,l)=>e(a)-l):(t=e===ya||e===Gw?e:Vw,n=e,r=e);function o(a,l,u=0,c=a.length){if(u<c){if(t(l,l)!==0)return c;do{const d=u+c>>>1;n(a[d],l)<0?u=d+1:c=d}while(u<c)}return u}function i(a,l,u=0,c=a.length){if(u<c){if(t(l,l)!==0)return c;do{const d=u+c>>>1;n(a[d],l)<=0?u=d+1:c=d}while(u<c)}return u}function s(a,l,u=0,c=a.length){const d=o(a,l,u,c-1);return d>u&&r(a[d-1],l)>-r(a[d],l)?d-1:d}return{left:o,center:s,right:i}}function Vw(){return 0}function Xw(e){return e===null?NaN:+e}const Jw=gf(ya),Zw=Jw.right;gf(Xw).center;class Ln{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const n=this._partials;let r=0;for(let o=0;o<this._n&&o<32;o++){const i=n[o],s=t+i,a=Math.abs(t)<Math.abs(i)?t-(s-i):i-(s-t);a&&(n[r++]=a),t=s}return n[r]=t,this._n=r+1,this}valueOf(){const t=this._partials;let n=this._n,r,o,i,s=0;if(n>0){for(s=t[--n];n>0&&(r=s,o=t[--n],s=r+o,i=o-(s-r),!i););n>0&&(i<0&&t[n-1]<0||i>0&&t[n-1]>0)&&(o=i*2,r=s+o,o==r-s&&(s=r))}return s}}class ih extends Map{constructor(t,n=tx){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),t!=null)for(const[r,o]of t)this.set(r,o)}get(t){return super.get(sh(this,t))}has(t){return super.has(sh(this,t))}set(t,n){return super.set(Qw(this,t),n)}delete(t){return super.delete(ex(this,t))}}function sh({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):n}function Qw({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):(e.set(r,n),n)}function ex({_intern:e,_key:t},n){const r=t(n);return e.has(r)&&(n=e.get(r),e.delete(r)),n}function tx(e){return e!==null&&typeof e=="object"?e.valueOf():e}const nx=Math.sqrt(50),rx=Math.sqrt(10),ox=Math.sqrt(2);function Ia(e,t,n){const r=(t-e)/Math.max(0,n),o=Math.floor(Math.log10(r)),i=r/Math.pow(10,o),s=i>=nx?10:i>=rx?5:i>=ox?2:1;let a,l,u;return o<0?(u=Math.pow(10,-o)/s,a=Math.round(e*u),l=Math.round(t*u),a/u<e&&++a,l/u>t&&--l,u=-u):(u=Math.pow(10,o)*s,a=Math.round(e/u),l=Math.round(t/u),a*u<e&&++a,l*u>t&&--l),l<a&&.5<=n&&n<2?Ia(e,t,n*2):[a,l,u]}function lu(e,t,n){if(t=+t,e=+e,n=+n,!(n>0))return[];if(e===t)return[e];const r=t<e,[o,i,s]=r?Ia(t,e,n):Ia(e,t,n);if(!(i>=o))return[];const a=i-o+1,l=new Array(a);if(r)if(s<0)for(let u=0;u<a;++u)l[u]=(i-u)/-s;else for(let u=0;u<a;++u)l[u]=(i-u)*s;else if(s<0)for(let u=0;u<a;++u)l[u]=(o+u)/-s;else for(let u=0;u<a;++u)l[u]=(o+u)*s;return l}function cu(e,t,n){return t=+t,e=+e,n=+n,Ia(e,t,n)[2]}function uu(e,t,n){t=+t,e=+e,n=+n;const r=t<e,o=r?cu(t,e,n):cu(e,t,n);return(r?-1:1)*(o<0?1/-o:o)}function*ix(e){for(const t of e)yield*t}function yg(e){return Array.from(ix(e))}function sx(e,t,n){e=+e,t=+t,n=(o=arguments.length)<2?(t=e,e=0,1):o<3?1:+n;for(var r=-1,o=Math.max(0,Math.ceil((t-e)/n))|0,i=new Array(o);++r<o;)i[r]=e+r*n;return i}var ax={value:()=>{}};function mf(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new ga(n)}function ga(e){this._=e}function lx(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",o=n.indexOf(".");if(o>=0&&(r=n.slice(o+1),n=n.slice(0,o)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}ga.prototype=mf.prototype={constructor:ga,on:function(e,t){var n=this._,r=lx(e+"",n),o,i=-1,s=r.length;if(arguments.length<2){for(;++i<s;)if((o=(e=r[i]).type)&&(o=cx(n[o],e.name)))return o;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++i<s;)if(o=(e=r[i]).type)n[o]=ah(n[o],e.name,t);else if(t==null)for(o in n)n[o]=ah(n[o],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ga(e)},call:function(e,t){if((o=arguments.length-2)>0)for(var n=new Array(o),r=0,o,i;r<o;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],o=0,i=r.length;o<i;++o)r[o].value.apply(t,n)}};function cx(e,t){for(var n=0,r=e.length,o;n<r;++n)if((o=e[n]).name===t)return o.value}function ah(e,t,n){for(var r=0,o=e.length;r<o;++r)if(e[r].name===t){e[r]=ax,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var fu="http://www.w3.org/1999/xhtml";const lh={svg:"http://www.w3.org/2000/svg",xhtml:fu,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ol(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),lh.hasOwnProperty(t)?{space:lh[t],local:e}:e}function ux(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fu&&t.documentElement.namespaceURI===fu?t.createElement(e):t.createElementNS(n,e)}}function fx(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function gg(e){var t=Ol(e);return(t.local?fx:ux)(t)}function dx(){}function bf(e){return e==null?dx:function(){return this.querySelector(e)}}function hx(e){typeof e!="function"&&(e=bf(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=new Array(s),l,u,c=0;c<s;++c)(l=i[c])&&(u=e.call(l,l.__data__,c,i))&&("__data__"in l&&(u.__data__=l.__data__),a[c]=u);return new gn(r,this._parents)}function px(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function yx(){return[]}function mg(e){return e==null?yx:function(){return this.querySelectorAll(e)}}function gx(e){return function(){return px(e.apply(this,arguments))}}function mx(e){typeof e=="function"?e=gx(e):e=mg(e);for(var t=this._groups,n=t.length,r=[],o=[],i=0;i<n;++i)for(var s=t[i],a=s.length,l,u=0;u<a;++u)(l=s[u])&&(r.push(e.call(l,l.__data__,u,s)),o.push(l));return new gn(r,o)}function bg(e){return function(){return this.matches(e)}}function wg(e){return function(t){return t.matches(e)}}var bx=Array.prototype.find;function wx(e){return function(){return bx.call(this.children,e)}}function xx(){return this.firstElementChild}function vx(e){return this.select(e==null?xx:wx(typeof e=="function"?e:wg(e)))}var kx=Array.prototype.filter;function Sx(){return Array.from(this.children)}function $x(e){return function(){return kx.call(this.children,e)}}function _x(e){return this.selectAll(e==null?Sx:$x(typeof e=="function"?e:wg(e)))}function Mx(e){typeof e!="function"&&(e=bg(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=[],l,u=0;u<s;++u)(l=i[u])&&e.call(l,l.__data__,u,i)&&a.push(l);return new gn(r,this._parents)}function xg(e){return new Array(e.length)}function Ex(){return new gn(this._enter||this._groups.map(xg),this._parents)}function La(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}La.prototype={constructor:La,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Ax(e){return function(){return e}}function Tx(e,t,n,r,o,i){for(var s=0,a,l=t.length,u=i.length;s<u;++s)(a=t[s])?(a.__data__=i[s],r[s]=a):n[s]=new La(e,i[s]);for(;s<l;++s)(a=t[s])&&(o[s]=a)}function Ox(e,t,n,r,o,i,s){var a,l,u=new Map,c=t.length,d=i.length,f=new Array(c),p;for(a=0;a<c;++a)(l=t[a])&&(f[a]=p=s.call(l,l.__data__,a,t)+"",u.has(p)?o[a]=l:u.set(p,l));for(a=0;a<d;++a)p=s.call(e,i[a],a,i)+"",(l=u.get(p))?(r[a]=l,l.__data__=i[a],u.delete(p)):n[a]=new La(e,i[a]);for(a=0;a<c;++a)(l=t[a])&&u.get(f[a])===l&&(o[a]=l)}function Cx(e){return e.__data__}function Nx(e,t){if(!arguments.length)return Array.from(this,Cx);var n=t?Ox:Tx,r=this._parents,o=this._groups;typeof e!="function"&&(e=Ax(e));for(var i=o.length,s=new Array(i),a=new Array(i),l=new Array(i),u=0;u<i;++u){var c=r[u],d=o[u],f=d.length,p=Ix(e.call(c,c&&c.__data__,u,r)),h=p.length,y=a[u]=new Array(h),g=s[u]=new Array(h),m=l[u]=new Array(f);n(c,d,y,g,m,p,t);for(var b=0,w=0,x,S;b<h;++b)if(x=y[b]){for(b>=w&&(w=b+1);!(S=g[w])&&++w<h;);x._next=S||null}}return s=new gn(s,r),s._enter=a,s._exit=l,s}function Ix(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Lx(){return new gn(this._exit||this._groups.map(xg),this._parents)}function Fx(e,t,n){var r=this.enter(),o=this,i=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(o=t(o),o&&(o=o.selection())),n==null?i.remove():n(i),r&&o?r.merge(o).order():o}function Rx(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,o=n.length,i=r.length,s=Math.min(o,i),a=new Array(o),l=0;l<s;++l)for(var u=n[l],c=r[l],d=u.length,f=a[l]=new Array(d),p,h=0;h<d;++h)(p=u[h]||c[h])&&(f[h]=p);for(;l<o;++l)a[l]=n[l];return new gn(a,this._parents)}function Px(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],o=r.length-1,i=r[o],s;--o>=0;)(s=r[o])&&(i&&s.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(s,i),i=s);return this}function zx(e){e||(e=Dx);function t(d,f){return d&&f?e(d.__data__,f.__data__):!d-!f}for(var n=this._groups,r=n.length,o=new Array(r),i=0;i<r;++i){for(var s=n[i],a=s.length,l=o[i]=new Array(a),u,c=0;c<a;++c)(u=s[c])&&(l[c]=u);l.sort(t)}return new gn(o,this._parents).order()}function Dx(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function jx(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Wx(){return Array.from(this)}function qx(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,i=r.length;o<i;++o){var s=r[o];if(s)return s}return null}function Bx(){let e=0;for(const t of this)++e;return e}function Hx(){return!this.node()}function Ux(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var o=t[n],i=0,s=o.length,a;i<s;++i)(a=o[i])&&e.call(a,a.__data__,i,o);return this}function Kx(e){return function(){this.removeAttribute(e)}}function Yx(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Gx(e,t){return function(){this.setAttribute(e,t)}}function Vx(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Xx(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Jx(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Zx(e,t){var n=Ol(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Yx:Kx:typeof t=="function"?n.local?Jx:Xx:n.local?Vx:Gx)(n,t))}function vg(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Qx(e){return function(){this.style.removeProperty(e)}}function ev(e,t,n){return function(){this.style.setProperty(e,t,n)}}function tv(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function nv(e,t,n){return arguments.length>1?this.each((t==null?Qx:typeof t=="function"?tv:ev)(e,t,n??"")):jo(this.node(),e)}function jo(e,t){return e.style.getPropertyValue(t)||vg(e).getComputedStyle(e,null).getPropertyValue(t)}function rv(e){return function(){delete this[e]}}function ov(e,t){return function(){this[e]=t}}function iv(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function sv(e,t){return arguments.length>1?this.each((t==null?rv:typeof t=="function"?iv:ov)(e,t)):this.node()[e]}function kg(e){return e.trim().split(/^|\s+/)}function wf(e){return e.classList||new Sg(e)}function Sg(e){this._node=e,this._names=kg(e.getAttribute("class")||"")}Sg.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function $g(e,t){for(var n=wf(e),r=-1,o=t.length;++r<o;)n.add(t[r])}function _g(e,t){for(var n=wf(e),r=-1,o=t.length;++r<o;)n.remove(t[r])}function av(e){return function(){$g(this,e)}}function lv(e){return function(){_g(this,e)}}function cv(e,t){return function(){(t.apply(this,arguments)?$g:_g)(this,e)}}function uv(e,t){var n=kg(e+"");if(arguments.length<2){for(var r=wf(this.node()),o=-1,i=n.length;++o<i;)if(!r.contains(n[o]))return!1;return!0}return this.each((typeof t=="function"?cv:t?av:lv)(n,t))}function fv(){this.textContent=""}function dv(e){return function(){this.textContent=e}}function hv(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function pv(e){return arguments.length?this.each(e==null?fv:(typeof e=="function"?hv:dv)(e)):this.node().textContent}function yv(){this.innerHTML=""}function gv(e){return function(){this.innerHTML=e}}function mv(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function bv(e){return arguments.length?this.each(e==null?yv:(typeof e=="function"?mv:gv)(e)):this.node().innerHTML}function wv(){this.nextSibling&&this.parentNode.appendChild(this)}function xv(){return this.each(wv)}function vv(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function kv(){return this.each(vv)}function Sv(e){var t=typeof e=="function"?e:gg(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $v(){return null}function _v(e,t){var n=typeof e=="function"?e:gg(e),r=t==null?$v:typeof t=="function"?t:bf(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Mv(){var e=this.parentNode;e&&e.removeChild(this)}function Ev(){return this.each(Mv)}function Av(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tv(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ov(e){return this.select(e?Tv:Av)}function Cv(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Nv(e){return function(t){e.call(this,t,this.__data__)}}function Iv(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function Lv(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,o=t.length,i;n<o;++n)i=t[n],(!e.type||i.type===e.type)&&i.name===e.name?this.removeEventListener(i.type,i.listener,i.options):t[++r]=i;++r?t.length=r:delete this.__on}}}function Fv(e,t,n){return function(){var r=this.__on,o,i=Nv(t);if(r){for(var s=0,a=r.length;s<a;++s)if((o=r[s]).type===e.type&&o.name===e.name){this.removeEventListener(o.type,o.listener,o.options),this.addEventListener(o.type,o.listener=i,o.options=n),o.value=t;return}}this.addEventListener(e.type,i,n),o={type:e.type,name:e.name,value:t,listener:i,options:n},r?r.push(o):this.__on=[o]}}function Rv(e,t,n){var r=Iv(e+""),o,i=r.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,u=a.length,c;l<u;++l)for(o=0,c=a[l];o<i;++o)if((s=r[o]).type===c.type&&s.name===c.name)return c.value}return}for(a=t?Fv:Lv,o=0;o<i;++o)this.each(a(r[o],t,n));return this}function Mg(e,t,n){var r=vg(e),o=r.CustomEvent;typeof o=="function"?o=new o(t,n):(o=r.document.createEvent("Event"),n?(o.initEvent(t,n.bubbles,n.cancelable),o.detail=n.detail):o.initEvent(t,!1,!1)),e.dispatchEvent(o)}function Pv(e,t){return function(){return Mg(this,e,t)}}function zv(e,t){return function(){return Mg(this,e,t.apply(this,arguments))}}function Dv(e,t){return this.each((typeof t=="function"?zv:Pv)(e,t))}function*jv(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,i=r.length,s;o<i;++o)(s=r[o])&&(yield s)}var Eg=[null];function gn(e,t){this._groups=e,this._parents=t}function ks(){return new gn([[document.documentElement]],Eg)}function Wv(){return this}gn.prototype=ks.prototype={constructor:gn,select:hx,selectAll:mx,selectChild:vx,selectChildren:_x,filter:Mx,data:Nx,enter:Ex,exit:Lx,join:Fx,merge:Rx,selection:Wv,order:Px,sort:zx,call:jx,nodes:Wx,node:qx,size:Bx,empty:Hx,each:Ux,attr:Zx,style:nv,property:sv,classed:uv,text:pv,html:bv,raise:xv,lower:kv,append:Sv,insert:_v,remove:Ev,clone:Ov,datum:Cv,on:Rv,dispatch:Dv,[Symbol.iterator]:jv};function sr(e){return typeof e=="string"?new gn([[document.querySelector(e)]],[document.documentElement]):new gn([[e]],Eg)}function qv(e){let t;for(;t=e.sourceEvent;)e=t;return e}function du(e,t){if(e=qv(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var o=t.getBoundingClientRect();return[e.clientX-o.left-t.clientLeft,e.clientY-o.top-t.clientTop]}}return[e.pageX,e.pageY]}const Bv={passive:!1},Qi={capture:!0,passive:!1};function $c(e){e.stopImmediatePropagation()}function Fo(e){e.preventDefault(),e.stopImmediatePropagation()}function Hv(e){var t=e.document.documentElement,n=sr(e).on("dragstart.drag",Fo,Qi);"onselectstart"in t?n.on("selectstart.drag",Fo,Qi):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Uv(e,t){var n=e.document.documentElement,r=sr(e).on("dragstart.drag",null);t&&(r.on("click.drag",Fo,Qi),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Ks=e=>()=>e;function hu(e,{sourceEvent:t,subject:n,target:r,identifier:o,active:i,x:s,y:a,dx:l,dy:u,dispatch:c}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:c}})}hu.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Kv(e){return!e.ctrlKey&&!e.button}function Yv(){return this.parentNode}function Gv(e,t){return t??{x:e.x,y:e.y}}function Vv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Xv(){var e=Kv,t=Yv,n=Gv,r=Vv,o={},i=mf("start","drag","end"),s=0,a,l,u,c,d=0;function f(x){x.on("mousedown.drag",p).filter(r).on("touchstart.drag",g).on("touchmove.drag",m,Bv).on("touchend.drag touchcancel.drag",b).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(x,S){if(!(c||!e.call(this,x,S))){var v=w(this,t.call(this,x,S),x,S,"mouse");v&&(sr(x.view).on("mousemove.drag",h,Qi).on("mouseup.drag",y,Qi),Hv(x.view),$c(x),u=!1,a=x.clientX,l=x.clientY,v("start",x))}}function h(x){if(Fo(x),!u){var S=x.clientX-a,v=x.clientY-l;u=S*S+v*v>d}o.mouse("drag",x)}function y(x){sr(x.view).on("mousemove.drag mouseup.drag",null),Uv(x.view,u),Fo(x),o.mouse("end",x)}function g(x,S){if(e.call(this,x,S)){var v=x.changedTouches,k=t.call(this,x,S),_=v.length,T,L;for(T=0;T<_;++T)(L=w(this,k,x,S,v[T].identifier,v[T]))&&($c(x),L("start",x,v[T]))}}function m(x){var S=x.changedTouches,v=S.length,k,_;for(k=0;k<v;++k)(_=o[S[k].identifier])&&(Fo(x),_("drag",x,S[k]))}function b(x){var S=x.changedTouches,v=S.length,k,_;for(c&&clearTimeout(c),c=setTimeout(function(){c=null},500),k=0;k<v;++k)(_=o[S[k].identifier])&&($c(x),_("end",x,S[k]))}function w(x,S,v,k,_,T){var L=i.copy(),N=du(T||v,S),I,O,M;if((M=n.call(x,new hu("beforestart",{sourceEvent:v,target:f,identifier:_,active:s,x:N[0],y:N[1],dx:0,dy:0,dispatch:L}),k))!=null)return I=M.x-N[0]||0,O=M.y-N[1]||0,function $(F,D,z){var j=N,G;switch(F){case"start":o[_]=$,G=s++;break;case"end":delete o[_],--s;case"drag":N=du(z||D,S),G=s;break}L.call(F,x,new hu(F,{sourceEvent:D,subject:M,target:f,identifier:_,active:G,x:N[0]+I,y:N[1]+O,dx:N[0]-j[0],dy:N[1]-j[1],dispatch:L}),k)}}return f.filter=function(x){return arguments.length?(e=typeof x=="function"?x:Ks(!!x),f):e},f.container=function(x){return arguments.length?(t=typeof x=="function"?x:Ks(x),f):t},f.subject=function(x){return arguments.length?(n=typeof x=="function"?x:Ks(x),f):n},f.touchable=function(x){return arguments.length?(r=typeof x=="function"?x:Ks(!!x),f):r},f.on=function(){var x=i.on.apply(i,arguments);return x===i?f:x},f.clickDistance=function(x){return arguments.length?(d=(x=+x)*x,f):Math.sqrt(d)},f}function Cl(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function xf(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function ei(){}var Zr=.7,Wo=1/Zr,Ro="\\s*([+-]?\\d+)\\s*",es="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Kn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Jv=/^#([0-9a-f]{3,8})$/,Zv=new RegExp(`^rgb\\(${Ro},${Ro},${Ro}\\)$`),Qv=new RegExp(`^rgb\\(${Kn},${Kn},${Kn}\\)$`),ek=new RegExp(`^rgba\\(${Ro},${Ro},${Ro},${es}\\)$`),tk=new RegExp(`^rgba\\(${Kn},${Kn},${Kn},${es}\\)$`),nk=new RegExp(`^hsl\\(${es},${Kn},${Kn}\\)$`),rk=new RegExp(`^hsla\\(${es},${Kn},${Kn},${es}\\)$`),ch={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Cl(ei,Qr,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:uh,formatHex:uh,formatHex8:ok,formatHsl:ik,formatRgb:fh,toString:fh});function uh(){return this.rgb().formatHex()}function ok(){return this.rgb().formatHex8()}function ik(){return Tg(this).formatHsl()}function fh(){return this.rgb().formatRgb()}function Qr(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Jv.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?dh(t):n===3?new Yt(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Ys(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Ys(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Zv.exec(e))?new Yt(t[1],t[2],t[3],1):(t=Qv.exec(e))?new Yt(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=ek.exec(e))?Ys(t[1],t[2],t[3],t[4]):(t=tk.exec(e))?Ys(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=nk.exec(e))?yh(t[1],t[2]/100,t[3]/100,1):(t=rk.exec(e))?yh(t[1],t[2]/100,t[3]/100,t[4]):ch.hasOwnProperty(e)?dh(ch[e]):e==="transparent"?new Yt(NaN,NaN,NaN,0):null}function dh(e){return new Yt(e>>16&255,e>>8&255,e&255,1)}function Ys(e,t,n,r){return r<=0&&(e=t=n=NaN),new Yt(e,t,n,r)}function Ag(e){return e instanceof ei||(e=Qr(e)),e?(e=e.rgb(),new Yt(e.r,e.g,e.b,e.opacity)):new Yt}function Fa(e,t,n,r){return arguments.length===1?Ag(e):new Yt(e,t,n,r??1)}function Yt(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cl(Yt,Fa,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Yt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Yt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Yt(Ur(this.r),Ur(this.g),Ur(this.b),Ra(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:hh,formatHex:hh,formatHex8:sk,formatRgb:ph,toString:ph}));function hh(){return`#${Hr(this.r)}${Hr(this.g)}${Hr(this.b)}`}function sk(){return`#${Hr(this.r)}${Hr(this.g)}${Hr(this.b)}${Hr((isNaN(this.opacity)?1:this.opacity)*255)}`}function ph(){const e=Ra(this.opacity);return`${e===1?"rgb(":"rgba("}${Ur(this.r)}, ${Ur(this.g)}, ${Ur(this.b)}${e===1?")":`, ${e})`}`}function Ra(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ur(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Hr(e){return e=Ur(e),(e<16?"0":"")+e.toString(16)}function yh(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Cn(e,t,n,r)}function Tg(e){if(e instanceof Cn)return new Cn(e.h,e.s,e.l,e.opacity);if(e instanceof ei||(e=Qr(e)),!e)return new Cn;if(e instanceof Cn)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,o=Math.min(t,n,r),i=Math.max(t,n,r),s=NaN,a=i-o,l=(i+o)/2;return a?(t===i?s=(n-r)/a+(n<r)*6:n===i?s=(r-t)/a+2:s=(t-n)/a+4,a/=l<.5?i+o:2-i-o,s*=60):a=l>0&&l<1?0:s,new Cn(s,a,l,e.opacity)}function ak(e,t,n,r){return arguments.length===1?Tg(e):new Cn(e,t,n,r??1)}function Cn(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cl(Cn,ak,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Cn(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Cn(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,o=2*n-r;return new Yt(_c(e>=240?e-240:e+120,o,r),_c(e,o,r),_c(e<120?e+240:e-120,o,r),this.opacity)},clamp(){return new Cn(gh(this.h),Gs(this.s),Gs(this.l),Ra(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Ra(this.opacity);return`${e===1?"hsl(":"hsla("}${gh(this.h)}, ${Gs(this.s)*100}%, ${Gs(this.l)*100}%${e===1?")":`, ${e})`}`}}));function gh(e){return e=(e||0)%360,e<0?e+360:e}function Gs(e){return Math.max(0,Math.min(1,e||0))}function _c(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const lk=Math.PI/180,ck=180/Math.PI;var Og=-.14861,vf=1.78277,kf=-.29227,Nl=-.90649,ts=1.97294,mh=ts*Nl,bh=ts*vf,wh=vf*kf-Nl*Og;function uk(e){if(e instanceof Kr)return new Kr(e.h,e.s,e.l,e.opacity);e instanceof Yt||(e=Ag(e));var t=e.r/255,n=e.g/255,r=e.b/255,o=(wh*r+mh*t-bh*n)/(wh+mh-bh),i=r-o,s=(ts*(n-o)-kf*i)/Nl,a=Math.sqrt(s*s+i*i)/(ts*o*(1-o)),l=a?Math.atan2(s,i)*ck-120:NaN;return new Kr(l<0?l+360:l,a,o,e.opacity)}function Tr(e,t,n,r){return arguments.length===1?uk(e):new Kr(e,t,n,r??1)}function Kr(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cl(Kr,Tr,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Kr(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Kr(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=isNaN(this.h)?0:(this.h+120)*lk,t=+this.l,n=isNaN(this.s)?0:this.s*t*(1-t),r=Math.cos(e),o=Math.sin(e);return new Yt(255*(t+n*(Og*r+vf*o)),255*(t+n*(kf*r+Nl*o)),255*(t+n*(ts*r)),this.opacity)}}));function fk(e,t,n,r,o){var i=e*e,s=i*e;return((1-3*e+3*i-s)*t+(4-6*i+3*s)*n+(1+3*e+3*i-3*s)*r+s*o)/6}function dk(e){var t=e.length-1;return function(n){var r=n<=0?n=0:n>=1?(n=1,t-1):Math.floor(n*t),o=e[r],i=e[r+1],s=r>0?e[r-1]:2*o-i,a=r<t-1?e[r+2]:2*i-o;return fk((n-r/t)*t,s,o,i,a)}}const Il=e=>()=>e;function Cg(e,t){return function(n){return e+n*t}}function hk(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function pk(e,t){var n=t-e;return n?Cg(e,n>180||n<-180?n-360*Math.round(n/360):n):Il(isNaN(e)?t:e)}function yk(e){return(e=+e)==1?Po:function(t,n){return n-t?hk(t,n,e):Il(isNaN(t)?n:t)}}function Po(e,t){var n=t-e;return n?Cg(e,n):Il(isNaN(e)?t:e)}const eo=(function e(t){var n=yk(t);function r(o,i){var s=n((o=Fa(o)).r,(i=Fa(i)).r),a=n(o.g,i.g),l=n(o.b,i.b),u=Po(o.opacity,i.opacity);return function(c){return o.r=s(c),o.g=a(c),o.b=l(c),o.opacity=u(c),o+""}}return r.gamma=e,r})(1);function gk(e){return function(t){var n=t.length,r=new Array(n),o=new Array(n),i=new Array(n),s,a;for(s=0;s<n;++s)a=Fa(t[s]),r[s]=a.r||0,o[s]=a.g||0,i[s]=a.b||0;return r=e(r),o=e(o),i=e(i),a.opacity=1,function(l){return a.r=r(l),a.g=o(l),a.b=i(l),a+""}}}var mk=gk(dk);function bk(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),o;return function(i){for(o=0;o<n;++o)r[o]=e[o]*(1-i)+t[o]*i;return r}}function wk(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function xk(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,o=new Array(r),i=new Array(n),s;for(s=0;s<r;++s)o[s]=Ll(e[s],t[s]);for(;s<n;++s)i[s]=t[s];return function(a){for(s=0;s<r;++s)i[s]=o[s](a);return i}}function vk(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Tn(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function kk(e,t){var n={},r={},o;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(o in t)o in e?n[o]=Ll(e[o],t[o]):r[o]=t[o];return function(i){for(o in n)r[o]=n[o](i);return r}}var pu=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mc=new RegExp(pu.source,"g");function Sk(e){return function(){return e}}function $k(e){return function(t){return e(t)+""}}function Ng(e,t){var n=pu.lastIndex=Mc.lastIndex=0,r,o,i,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=pu.exec(e))&&(o=Mc.exec(t));)(i=o.index)>n&&(i=t.slice(n,i),a[s]?a[s]+=i:a[++s]=i),(r=r[0])===(o=o[0])?a[s]?a[s]+=o:a[++s]=o:(a[++s]=null,l.push({i:s,x:Tn(r,o)})),n=Mc.lastIndex;return n<t.length&&(i=t.slice(n),a[s]?a[s]+=i:a[++s]=i),a.length<2?l[0]?$k(l[0].x):Sk(t):(t=l.length,function(u){for(var c=0,d;c<t;++c)a[(d=l[c]).i]=d.x(u);return a.join("")})}function Ll(e,t){var n=typeof t,r;return t==null||n==="boolean"?Il(t):(n==="number"?Tn:n==="string"?(r=Qr(t))?(t=r,eo):Ng:t instanceof Qr?eo:t instanceof Date?vk:wk(t)?bk:Array.isArray(t)?xk:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?kk:Tn)(e,t)}function _k(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var xh=180/Math.PI,yu={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ig(e,t,n,r,o,i){var s,a,l;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),e*r<t*n&&(e=-e,t=-t,l=-l,s=-s),{translateX:o,translateY:i,rotate:Math.atan2(t,e)*xh,skewX:Math.atan(l)*xh,scaleX:s,scaleY:a}}var Vs;function Mk(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?yu:Ig(t.a,t.b,t.c,t.d,t.e,t.f)}function Ek(e){return e==null||(Vs||(Vs=document.createElementNS("http://www.w3.org/2000/svg","g")),Vs.setAttribute("transform",e),!(e=Vs.transform.baseVal.consolidate()))?yu:(e=e.matrix,Ig(e.a,e.b,e.c,e.d,e.e,e.f))}function Lg(e,t,n,r){function o(u){return u.length?u.pop()+" ":""}function i(u,c,d,f,p,h){if(u!==d||c!==f){var y=p.push("translate(",null,t,null,n);h.push({i:y-4,x:Tn(u,d)},{i:y-2,x:Tn(c,f)})}else(d||f)&&p.push("translate("+d+t+f+n)}function s(u,c,d,f){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),f.push({i:d.push(o(d)+"rotate(",null,r)-2,x:Tn(u,c)})):c&&d.push(o(d)+"rotate("+c+r)}function a(u,c,d,f){u!==c?f.push({i:d.push(o(d)+"skewX(",null,r)-2,x:Tn(u,c)}):c&&d.push(o(d)+"skewX("+c+r)}function l(u,c,d,f,p,h){if(u!==d||c!==f){var y=p.push(o(p)+"scale(",null,",",null,")");h.push({i:y-4,x:Tn(u,d)},{i:y-2,x:Tn(c,f)})}else(d!==1||f!==1)&&p.push(o(p)+"scale("+d+","+f+")")}return function(u,c){var d=[],f=[];return u=e(u),c=e(c),i(u.translateX,u.translateY,c.translateX,c.translateY,d,f),s(u.rotate,c.rotate,d,f),a(u.skewX,c.skewX,d,f),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,d,f),u=c=null,function(p){for(var h=-1,y=f.length,g;++h<y;)d[(g=f[h]).i]=g.x(p);return d.join("")}}}var Ak=Lg(Mk,"px, ","px)","deg)"),Tk=Lg(Ek,", ",")",")");function Fg(e){return(function t(n){n=+n;function r(o,i){var s=e((o=Tr(o)).h,(i=Tr(i)).h),a=Po(o.s,i.s),l=Po(o.l,i.l),u=Po(o.opacity,i.opacity);return function(c){return o.h=s(c),o.s=a(c),o.l=l(Math.pow(c,n)),o.opacity=u(c),o+""}}return r.gamma=t,r})(1)}Fg(pk);var Rg=Fg(Po);function Pg(e,t){t===void 0&&(t=e,e=Ll);for(var n=0,r=t.length-1,o=t[0],i=new Array(r<0?0:r);n<r;)i[n]=e(o,o=t[++n]);return function(s){var a=Math.max(0,Math.min(r-1,Math.floor(s*=r)));return i[a](s-a)}}function zg(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e(r/(t-1));return n}var qo=0,bi=0,fi=0,Dg=1e3,Pa,wi,za=0,to=0,Fl=0,ns=typeof performance=="object"&&performance.now?performance:Date,jg=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Sf(){return to||(jg(Ok),to=ns.now()+Fl)}function Ok(){to=0}function Da(){this._call=this._time=this._next=null}Da.prototype=Wg.prototype={constructor:Da,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Sf():+n)+(t==null?0:+t),!this._next&&wi!==this&&(wi?wi._next=this:Pa=this,wi=this),this._call=e,this._time=n,gu()},stop:function(){this._call&&(this._call=null,this._time=1/0,gu())}};function Wg(e,t,n){var r=new Da;return r.restart(e,t,n),r}function Ck(){Sf(),++qo;for(var e=Pa,t;e;)(t=to-e._time)>=0&&e._call.call(void 0,t),e=e._next;--qo}function vh(){to=(za=ns.now())+Fl,qo=bi=0;try{Ck()}finally{qo=0,Ik(),to=0}}function Nk(){var e=ns.now(),t=e-za;t>Dg&&(Fl-=t,za=e)}function Ik(){for(var e,t=Pa,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Pa=n);wi=e,gu(r)}function gu(e){if(!qo){bi&&(bi=clearTimeout(bi));var t=e-to;t>24?(e<1/0&&(bi=setTimeout(vh,e-ns.now()-Fl)),fi&&(fi=clearInterval(fi))):(fi||(za=ns.now(),fi=setInterval(Nk,Dg)),qo=1,jg(vh))}}function kh(e,t,n){var r=new Da;return t=t==null?0:+t,r.restart(o=>{r.stop(),e(o+t)},t,n),r}var Lk=mf("start","end","cancel","interrupt"),Fk=[],qg=0,Sh=1,mu=2,ma=3,$h=4,bu=5,ba=6;function Rl(e,t,n,r,o,i){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Rk(e,n,{name:t,index:r,group:o,on:Lk,tween:Fk,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qg})}function $f(e,t){var n=Pn(e,t);if(n.state>qg)throw new Error("too late; already scheduled");return n}function Jn(e,t){var n=Pn(e,t);if(n.state>ma)throw new Error("too late; already running");return n}function Pn(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Rk(e,t,n){var r=e.__transition,o;r[t]=n,n.timer=Wg(i,0,n.time);function i(u){n.state=Sh,n.timer.restart(s,n.delay,n.time),n.delay<=u&&s(u-n.delay)}function s(u){var c,d,f,p;if(n.state!==Sh)return l();for(c in r)if(p=r[c],p.name===n.name){if(p.state===ma)return kh(s);p.state===$h?(p.state=ba,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete r[c]):+c<t&&(p.state=ba,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete r[c])}if(kh(function(){n.state===ma&&(n.state=$h,n.timer.restart(a,n.delay,n.time),a(u))}),n.state=mu,n.on.call("start",e,e.__data__,n.index,n.group),n.state===mu){for(n.state=ma,o=new Array(f=n.tween.length),c=0,d=-1;c<f;++c)(p=n.tween[c].value.call(e,e.__data__,n.index,n.group))&&(o[++d]=p);o.length=d+1}}function a(u){for(var c=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(l),n.state=bu,1),d=-1,f=o.length;++d<f;)o[d].call(e,c);n.state===bu&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=ba,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function Pk(e,t){var n=e.__transition,r,o,i=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((r=n[s]).name!==t){i=!1;continue}o=r.state>mu&&r.state<bu,r.state=ba,r.timer.stop(),r.on.call(o?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}i&&delete e.__transition}}function zk(e){return this.each(function(){Pk(this,e)})}function Dk(e,t){var n,r;return function(){var o=Jn(this,e),i=o.tween;if(i!==n){r=n=i;for(var s=0,a=r.length;s<a;++s)if(r[s].name===t){r=r.slice(),r.splice(s,1);break}}o.tween=r}}function jk(e,t,n){var r,o;if(typeof n!="function")throw new Error;return function(){var i=Jn(this,e),s=i.tween;if(s!==r){o=(r=s).slice();for(var a={name:t,value:n},l=0,u=o.length;l<u;++l)if(o[l].name===t){o[l]=a;break}l===u&&o.push(a)}i.tween=o}}function Wk(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Pn(this.node(),n).tween,o=0,i=r.length,s;o<i;++o)if((s=r[o]).name===e)return s.value;return null}return this.each((t==null?Dk:jk)(n,e,t))}function _f(e,t,n){var r=e._id;return e.each(function(){var o=Jn(this,r);(o.value||(o.value={}))[t]=n.apply(this,arguments)}),function(o){return Pn(o,r).value[t]}}function Bg(e,t){var n;return(typeof t=="number"?Tn:t instanceof Qr?eo:(n=Qr(t))?(t=n,eo):Ng)(e,t)}function qk(e){return function(){this.removeAttribute(e)}}function Bk(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Hk(e,t,n){var r,o=n+"",i;return function(){var s=this.getAttribute(e);return s===o?null:s===r?i:i=t(r=s,n)}}function Uk(e,t,n){var r,o=n+"",i;return function(){var s=this.getAttributeNS(e.space,e.local);return s===o?null:s===r?i:i=t(r=s,n)}}function Kk(e,t,n){var r,o,i;return function(){var s,a=n(this),l;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),l=a+"",s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a)))}}function Yk(e,t,n){var r,o,i;return function(){var s,a=n(this),l;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),l=a+"",s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a)))}}function Gk(e,t){var n=Ol(e),r=n==="transform"?Tk:Bg;return this.attrTween(e,typeof t=="function"?(n.local?Yk:Kk)(n,r,_f(this,"attr."+e,t)):t==null?(n.local?Bk:qk)(n):(n.local?Uk:Hk)(n,r,t))}function Vk(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Xk(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Jk(e,t){var n,r;function o(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Xk(e,i)),n}return o._value=t,o}function Zk(e,t){var n,r;function o(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Vk(e,i)),n}return o._value=t,o}function Qk(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=Ol(e);return this.tween(n,(r.local?Jk:Zk)(r,t))}function e2(e,t){return function(){$f(this,e).delay=+t.apply(this,arguments)}}function t2(e,t){return t=+t,function(){$f(this,e).delay=t}}function n2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?e2:t2)(t,e)):Pn(this.node(),t).delay}function r2(e,t){return function(){Jn(this,e).duration=+t.apply(this,arguments)}}function o2(e,t){return t=+t,function(){Jn(this,e).duration=t}}function i2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?r2:o2)(t,e)):Pn(this.node(),t).duration}function s2(e,t){if(typeof t!="function")throw new Error;return function(){Jn(this,e).ease=t}}function a2(e){var t=this._id;return arguments.length?this.each(s2(t,e)):Pn(this.node(),t).ease}function l2(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Jn(this,e).ease=n}}function c2(e){if(typeof e!="function")throw new Error;return this.each(l2(this._id,e))}function u2(e){typeof e!="function"&&(e=bg(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=[],l,u=0;u<s;++u)(l=i[u])&&e.call(l,l.__data__,u,i)&&a.push(l);return new xr(r,this._parents,this._name,this._id)}function f2(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,o=n.length,i=Math.min(r,o),s=new Array(r),a=0;a<i;++a)for(var l=t[a],u=n[a],c=l.length,d=s[a]=new Array(c),f,p=0;p<c;++p)(f=l[p]||u[p])&&(d[p]=f);for(;a<r;++a)s[a]=t[a];return new xr(s,this._parents,this._name,this._id)}function d2(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function h2(e,t,n){var r,o,i=d2(t)?$f:Jn;return function(){var s=i(this,e),a=s.on;a!==r&&(o=(r=a).copy()).on(t,n),s.on=o}}function p2(e,t){var n=this._id;return arguments.length<2?Pn(this.node(),n).on.on(e):this.each(h2(n,e,t))}function y2(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function g2(){return this.on("end.remove",y2(this._id))}function m2(e){var t=this._name,n=this._id;typeof e!="function"&&(e=bf(e));for(var r=this._groups,o=r.length,i=new Array(o),s=0;s<o;++s)for(var a=r[s],l=a.length,u=i[s]=new Array(l),c,d,f=0;f<l;++f)(c=a[f])&&(d=e.call(c,c.__data__,f,a))&&("__data__"in c&&(d.__data__=c.__data__),u[f]=d,Rl(u[f],t,n,f,u,Pn(c,n)));return new xr(i,this._parents,t,n)}function b2(e){var t=this._name,n=this._id;typeof e!="function"&&(e=mg(e));for(var r=this._groups,o=r.length,i=[],s=[],a=0;a<o;++a)for(var l=r[a],u=l.length,c,d=0;d<u;++d)if(c=l[d]){for(var f=e.call(c,c.__data__,d,l),p,h=Pn(c,n),y=0,g=f.length;y<g;++y)(p=f[y])&&Rl(p,t,n,y,f,h);i.push(f),s.push(c)}return new xr(i,s,t,n)}var w2=ks.prototype.constructor;function x2(){return new w2(this._groups,this._parents)}function v2(e,t){var n,r,o;return function(){var i=jo(this,e),s=(this.style.removeProperty(e),jo(this,e));return i===s?null:i===n&&s===r?o:o=t(n=i,r=s)}}function Hg(e){return function(){this.style.removeProperty(e)}}function k2(e,t,n){var r,o=n+"",i;return function(){var s=jo(this,e);return s===o?null:s===r?i:i=t(r=s,n)}}function S2(e,t,n){var r,o,i;return function(){var s=jo(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),jo(this,e))),s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a))}}function $2(e,t){var n,r,o,i="style."+t,s="end."+i,a;return function(){var l=Jn(this,e),u=l.on,c=l.value[i]==null?a||(a=Hg(t)):void 0;(u!==n||o!==c)&&(r=(n=u).copy()).on(s,o=c),l.on=r}}function _2(e,t,n){var r=(e+="")=="transform"?Ak:Bg;return t==null?this.styleTween(e,v2(e,r)).on("end.style."+e,Hg(e)):typeof t=="function"?this.styleTween(e,S2(e,r,_f(this,"style."+e,t))).each($2(this._id,e)):this.styleTween(e,k2(e,r,t),n).on("end.style."+e,null)}function M2(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function E2(e,t,n){var r,o;function i(){var s=t.apply(this,arguments);return s!==o&&(r=(o=s)&&M2(e,s,n)),r}return i._value=t,i}function A2(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,E2(e,t,n??""))}function T2(e){return function(){this.textContent=e}}function O2(e){return function(){var t=e(this);this.textContent=t??""}}function C2(e){return this.tween("text",typeof e=="function"?O2(_f(this,"text",e)):T2(e==null?"":e+""))}function N2(e){return function(t){this.textContent=e.call(this,t)}}function I2(e){var t,n;function r(){var o=e.apply(this,arguments);return o!==n&&(t=(n=o)&&N2(o)),t}return r._value=e,r}function L2(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,I2(e))}function F2(){for(var e=this._name,t=this._id,n=Ug(),r=this._groups,o=r.length,i=0;i<o;++i)for(var s=r[i],a=s.length,l,u=0;u<a;++u)if(l=s[u]){var c=Pn(l,t);Rl(l,e,n,u,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new xr(r,this._parents,e,n)}function R2(){var e,t,n=this,r=n._id,o=n.size();return new Promise(function(i,s){var a={value:s},l={value:function(){--o===0&&i()}};n.each(function(){var u=Jn(this,r),c=u.on;c!==e&&(t=(e=c).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(l)),u.on=t}),o===0&&i()})}var P2=0;function xr(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Ug(){return++P2}var or=ks.prototype;xr.prototype={constructor:xr,select:m2,selectAll:b2,selectChild:or.selectChild,selectChildren:or.selectChildren,filter:u2,merge:f2,selection:x2,transition:F2,call:or.call,nodes:or.nodes,node:or.node,size:or.size,empty:or.empty,each:or.each,on:p2,attr:Gk,attrTween:Qk,style:_2,styleTween:A2,text:C2,textTween:L2,remove:g2,tween:Wk,delay:n2,duration:i2,ease:a2,easeVarying:c2,end:R2,[Symbol.iterator]:or[Symbol.iterator]};function z2(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var D2={time:null,delay:0,duration:250,ease:z2};function j2(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function W2(e){var t,n;e instanceof xr?(t=e._id,e=e._name):(t=Ug(),(n=D2).time=Sf(),e=e==null?null:e+"");for(var r=this._groups,o=r.length,i=0;i<o;++i)for(var s=r[i],a=s.length,l,u=0;u<a;++u)(l=s[u])&&Rl(l,e,t,u,s,n||j2(l,t));return new xr(r,this._parents,e,t)}ks.prototype.interrupt=zk;ks.prototype.transition=W2;const wu=Math.PI,xu=2*wu,Wr=1e-6,q2=xu-Wr;function Kg(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function B2(e){let t=Math.floor(e);if(!(t>=0))throw new Error(`invalid digits: ${e}`);if(t>15)return Kg;const n=10**t;return function(r){this._+=r[0];for(let o=1,i=r.length;o<i;++o)this._+=Math.round(arguments[o]*n)/n+r[o]}}class H2{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=t==null?Kg:B2(t)}moveTo(t,n){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,n){this._append`L${this._x1=+t},${this._y1=+n}`}quadraticCurveTo(t,n,r,o){this._append`Q${+t},${+n},${this._x1=+r},${this._y1=+o}`}bezierCurveTo(t,n,r,o,i,s){this._append`C${+t},${+n},${+r},${+o},${this._x1=+i},${this._y1=+s}`}arcTo(t,n,r,o,i){if(t=+t,n=+n,r=+r,o=+o,i=+i,i<0)throw new Error(`negative radius: ${i}`);let s=this._x1,a=this._y1,l=r-t,u=o-n,c=s-t,d=a-n,f=c*c+d*d;if(this._x1===null)this._append`M${this._x1=t},${this._y1=n}`;else if(f>Wr)if(!(Math.abs(d*l-u*c)>Wr)||!i)this._append`L${this._x1=t},${this._y1=n}`;else{let p=r-s,h=o-a,y=l*l+u*u,g=p*p+h*h,m=Math.sqrt(y),b=Math.sqrt(f),w=i*Math.tan((wu-Math.acos((y+f-g)/(2*m*b)))/2),x=w/b,S=w/m;Math.abs(x-1)>Wr&&this._append`L${t+x*c},${n+x*d}`,this._append`A${i},${i},0,0,${+(d*p>c*h)},${this._x1=t+S*l},${this._y1=n+S*u}`}}arc(t,n,r,o,i,s){if(t=+t,n=+n,r=+r,s=!!s,r<0)throw new Error(`negative radius: ${r}`);let a=r*Math.cos(o),l=r*Math.sin(o),u=t+a,c=n+l,d=1^s,f=s?o-i:i-o;this._x1===null?this._append`M${u},${c}`:(Math.abs(this._x1-u)>Wr||Math.abs(this._y1-c)>Wr)&&this._append`L${u},${c}`,r&&(f<0&&(f=f%xu+xu),f>q2?this._append`A${r},${r},0,1,${d},${t-a},${n-l}A${r},${r},0,1,${d},${this._x1=u},${this._y1=c}`:f>Wr&&this._append`A${r},${r},0,${+(f>=wu)},${d},${this._x1=t+r*Math.cos(i)},${this._y1=n+r*Math.sin(i)}`)}rect(t,n,r,o){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${r=+r}v${+o}h${-r}Z`}toString(){return this._}}function U2(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function ja(e,t){if(!isFinite(e)||e===0)return null;var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"),r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function Bo(e){return e=ja(Math.abs(e)),e?e[1]:NaN}function K2(e,t){return function(n,r){for(var o=n.length,i=[],s=0,a=e[0],l=0;o>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),i.push(n.substring(o-=a,o+a)),!((l+=a+1)>r));)a=e[s=(s+1)%e.length];return i.reverse().join(t)}}function Y2(e){return function(t){return t.replace(/[0-9]/g,function(n){return e[+n]})}}var G2=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function rs(e){if(!(t=G2.exec(e)))throw new Error("invalid format: "+e);var t;return new Mf({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}rs.prototype=Mf.prototype;function Mf(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}Mf.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function V2(e){e:for(var t=e.length,n=1,r=-1,o;n<t;++n)switch(e[n]){case".":r=o=n;break;case"0":r===0&&(r=n),o=n;break;default:if(!+e[n])break e;r>0&&(r=0);break}return r>0?e.slice(0,r)+e.slice(o+1):e}var Wa;function X2(e,t){var n=ja(e,t);if(!n)return Wa=void 0,e.toPrecision(t);var r=n[0],o=n[1],i=o-(Wa=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,s=r.length;return i===s?r:i>s?r+new Array(i-s+1).join("0"):i>0?r.slice(0,i)+"."+r.slice(i):"0."+new Array(1-i).join("0")+ja(e,Math.max(0,t+i-1))[0]}function _h(e,t){var n=ja(e,t);if(!n)return e+"";var r=n[0],o=n[1];return o<0?"0."+new Array(-o).join("0")+r:r.length>o+1?r.slice(0,o+1)+"."+r.slice(o+1):r+new Array(o-r.length+2).join("0")}const Mh={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:U2,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>_h(e*100,t),r:_h,s:X2,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Eh(e){return e}var Ah=Array.prototype.map,Th=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function J2(e){var t=e.grouping===void 0||e.thousands===void 0?Eh:K2(Ah.call(e.grouping,Number),e.thousands+""),n=e.currency===void 0?"":e.currency[0]+"",r=e.currency===void 0?"":e.currency[1]+"",o=e.decimal===void 0?".":e.decimal+"",i=e.numerals===void 0?Eh:Y2(Ah.call(e.numerals,String)),s=e.percent===void 0?"%":e.percent+"",a=e.minus===void 0?"−":e.minus+"",l=e.nan===void 0?"NaN":e.nan+"";function u(d,f){d=rs(d);var p=d.fill,h=d.align,y=d.sign,g=d.symbol,m=d.zero,b=d.width,w=d.comma,x=d.precision,S=d.trim,v=d.type;v==="n"?(w=!0,v="g"):Mh[v]||(x===void 0&&(x=12),S=!0,v="g"),(m||p==="0"&&h==="=")&&(m=!0,p="0",h="=");var k=(f&&f.prefix!==void 0?f.prefix:"")+(g==="$"?n:g==="#"&&/[boxX]/.test(v)?"0"+v.toLowerCase():""),_=(g==="$"?r:/[%p]/.test(v)?s:"")+(f&&f.suffix!==void 0?f.suffix:""),T=Mh[v],L=/[defgprs%]/.test(v);x=x===void 0?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,x)):Math.max(0,Math.min(20,x));function N(I){var O=k,M=_,$,F,D;if(v==="c")M=T(I)+M,I="";else{I=+I;var z=I<0||1/I<0;if(I=isNaN(I)?l:T(Math.abs(I),x),S&&(I=V2(I)),z&&+I==0&&y!=="+"&&(z=!1),O=(z?y==="("?y:a:y==="-"||y==="("?"":y)+O,M=(v==="s"&&!isNaN(I)&&Wa!==void 0?Th[8+Wa/3]:"")+M+(z&&y==="("?")":""),L){for($=-1,F=I.length;++$<F;)if(D=I.charCodeAt($),48>D||D>57){M=(D===46?o+I.slice($+1):I.slice($))+M,I=I.slice(0,$);break}}}w&&!m&&(I=t(I,1/0));var j=O.length+I.length+M.length,G=j<b?new Array(b-j+1).join(p):"";switch(w&&m&&(I=t(G+I,G.length?b-M.length:1/0),G=""),h){case"<":I=O+I+M+G;break;case"=":I=O+G+I+M;break;case"^":I=G.slice(0,j=G.length>>1)+O+I+M+G.slice(j);break;default:I=G+O+I+M;break}return i(I)}return N.toString=function(){return d+""},N}function c(d,f){var p=Math.max(-8,Math.min(8,Math.floor(Bo(f)/3)))*3,h=Math.pow(10,-p),y=u((d=rs(d),d.type="f",d),{suffix:Th[8+p/3]});return function(g){return y(h*g)}}return{format:u,formatPrefix:c}}var Xs,ti,Yg;Z2({thousands:",",grouping:[3],currency:["$",""]});function Z2(e){return Xs=J2(e),ti=Xs.format,Yg=Xs.formatPrefix,Xs}function Q2(e){return Math.max(0,-Bo(Math.abs(e)))}function eS(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Bo(t)/3)))*3-Bo(Math.abs(e)))}function tS(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,Bo(t)-Bo(e))+1}var He=1e-6,Gg=1e-12,Ve=Math.PI,St=Ve/2,qa=Ve/4,en=Ve*2,Ut=180/Ve,ut=Ve/180,ot=Math.abs,ni=Math.atan,Yn=Math.atan2,qe=Math.cos,Vg=Math.exp,Ba=Math.log,Ec=Math.pow,De=Math.sin,kn=Math.sign||function(e){return e>0?1:e<0?-1:0},un=Math.sqrt,Ef=Math.tan;function Xg(e){return e>1?0:e<-1?Ve:Math.acos(e)}function Mn(e){return e>1?St:e<-1?-St:Math.asin(e)}function Gt(){}function Ha(e,t){e&&Ch.hasOwnProperty(e.type)&&Ch[e.type](e,t)}var Oh={Feature:function(e,t){Ha(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,r=-1,o=n.length;++r<o;)Ha(n[r].geometry,t)}},Ch={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)e=n[r],t.point(e[0],e[1],e[2])},LineString:function(e,t){vu(e.coordinates,t,0)},MultiLineString:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)vu(n[r],t,0)},Polygon:function(e,t){Nh(e.coordinates,t)},MultiPolygon:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)Nh(n[r],t)},GeometryCollection:function(e,t){for(var n=e.geometries,r=-1,o=n.length;++r<o;)Ha(n[r],t)}};function vu(e,t,n){var r=-1,o=e.length-n,i;for(t.lineStart();++r<o;)i=e[r],t.point(i[0],i[1],i[2]);t.lineEnd()}function Nh(e,t){var n=-1,r=e.length;for(t.polygonStart();++n<r;)vu(e[n],t,1);t.polygonEnd()}function qr(e,t){e&&Oh.hasOwnProperty(e.type)?Oh[e.type](e,t):Ha(e,t)}var ku=new Ln,Ua=new Ln,Jg,Zg,Su,$u,_u,os={point:Gt,lineStart:Gt,lineEnd:Gt,polygonStart:function(){ku=new Ln,os.lineStart=nS,os.lineEnd=rS},polygonEnd:function(){var e=+ku;Ua.add(e<0?en+e:e),this.lineStart=this.lineEnd=this.point=Gt},sphere:function(){Ua.add(en)}};function nS(){os.point=oS}function rS(){Qg(Jg,Zg)}function oS(e,t){os.point=Qg,Jg=e,Zg=t,e*=ut,t*=ut,Su=e,$u=qe(t=t/2+qa),_u=De(t)}function Qg(e,t){e*=ut,t*=ut,t=t/2+qa;var n=e-Su,r=n>=0?1:-1,o=r*n,i=qe(t),s=De(t),a=_u*s,l=$u*i+a*qe(o),u=a*r*De(o);ku.add(Yn(u,l)),Su=e,$u=i,_u=s}function iS(e){return Ua=new Ln,qr(e,os),Ua*2}function Mu(e){return[Yn(e[1],e[0]),Mn(e[2])]}function Ho(e){var t=e[0],n=e[1],r=qe(n);return[r*qe(t),r*De(t),De(n)]}function Js(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Ka(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Ac(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function Zs(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Eu(e){var t=un(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}function Au(e,t){function n(r,o){return r=e(r,o),t(r[0],r[1])}return e.invert&&t.invert&&(n.invert=function(r,o){return r=t.invert(r,o),r&&e.invert(r[0],r[1])}),n}function Tu(e,t){return ot(e)>Ve&&(e-=Math.round(e/en)*en),[e,t]}Tu.invert=Tu;function em(e,t,n){return(e%=en)?t||n?Au(Lh(e),Fh(t,n)):Lh(e):t||n?Fh(t,n):Tu}function Ih(e){return function(t,n){return t+=e,ot(t)>Ve&&(t-=Math.round(t/en)*en),[t,n]}}function Lh(e){var t=Ih(e);return t.invert=Ih(-e),t}function Fh(e,t){var n=qe(e),r=De(e),o=qe(t),i=De(t);function s(a,l){var u=qe(l),c=qe(a)*u,d=De(a)*u,f=De(l),p=f*n+c*r;return[Yn(d*o-p*i,c*n-f*r),Mn(p*o+d*i)]}return s.invert=function(a,l){var u=qe(l),c=qe(a)*u,d=De(a)*u,f=De(l),p=f*o-d*i;return[Yn(d*o+f*i,c*n+p*r),Mn(p*n-c*r)]},s}function sS(e){e=em(e[0]*ut,e[1]*ut,e.length>2?e[2]*ut:0);function t(n){return n=e(n[0]*ut,n[1]*ut),n[0]*=Ut,n[1]*=Ut,n}return t.invert=function(n){return n=e.invert(n[0]*ut,n[1]*ut),n[0]*=Ut,n[1]*=Ut,n},t}function aS(e,t,n,r,o,i){if(n){var s=qe(t),a=De(t),l=r*n;o==null?(o=t+r*en,i=t-l/2):(o=Rh(s,o),i=Rh(s,i),(r>0?o<i:o>i)&&(o+=r*en));for(var u,c=o;r>0?c>i:c<i;c-=l)u=Mu([s,-a*qe(c),-a*De(c)]),e.point(u[0],u[1])}}function Rh(e,t){t=Ho(t),t[0]-=e,Eu(t);var n=Xg(-t[1]);return((-t[2]<0?-n:n)+en-He)%en}function tm(){var e=[],t;return{point:function(n,r,o){t.push([n,r,o])},lineStart:function(){e.push(t=[])},lineEnd:Gt,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function wa(e,t){return ot(e[0]-t[0])<He&&ot(e[1]-t[1])<He}function Qs(e,t,n,r){this.x=e,this.z=t,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function nm(e,t,n,r,o){var i=[],s=[],a,l;if(e.forEach(function(h){if(!((y=h.length-1)<=0)){var y,g=h[0],m=h[y],b;if(wa(g,m)){if(!g[2]&&!m[2]){for(o.lineStart(),a=0;a<y;++a)o.point((g=h[a])[0],g[1]);o.lineEnd();return}m[0]+=2*He}i.push(b=new Qs(g,h,null,!0)),s.push(b.o=new Qs(g,null,b,!1)),i.push(b=new Qs(m,h,null,!1)),s.push(b.o=new Qs(m,null,b,!0))}}),!!i.length){for(s.sort(t),Ph(i),Ph(s),a=0,l=s.length;a<l;++a)s[a].e=n=!n;for(var u=i[0],c,d;;){for(var f=u,p=!0;f.v;)if((f=f.n)===u)return;c=f.z,o.lineStart();do{if(f.v=f.o.v=!0,f.e){if(p)for(a=0,l=c.length;a<l;++a)o.point((d=c[a])[0],d[1]);else r(f.x,f.n.x,1,o);f=f.n}else{if(p)for(c=f.p.z,a=c.length-1;a>=0;--a)o.point((d=c[a])[0],d[1]);else r(f.x,f.p.x,-1,o);f=f.p}f=f.o,c=f.z,p=!p}while(!f.v);o.lineEnd()}}}function Ph(e){if(t=e.length){for(var t,n=0,r=e[0],o;++n<t;)r.n=o=e[n],o.p=r,r=o;r.n=o=e[0],o.p=r}}function Tc(e){return ot(e[0])<=Ve?e[0]:kn(e[0])*((ot(e[0])+Ve)%en-Ve)}function lS(e,t){var n=Tc(t),r=t[1],o=De(r),i=[De(n),-qe(n),0],s=0,a=0,l=new Ln;o===1?r=St+He:o===-1&&(r=-St-He);for(var u=0,c=e.length;u<c;++u)if(f=(d=e[u]).length)for(var d,f,p=d[f-1],h=Tc(p),y=p[1]/2+qa,g=De(y),m=qe(y),b=0;b<f;++b,h=x,g=v,m=k,p=w){var w=d[b],x=Tc(w),S=w[1]/2+qa,v=De(S),k=qe(S),_=x-h,T=_>=0?1:-1,L=T*_,N=L>Ve,I=g*v;if(l.add(Yn(I*T*De(L),m*k+I*qe(L))),s+=N?_+T*en:_,N^h>=n^x>=n){var O=Ka(Ho(p),Ho(w));Eu(O);var M=Ka(i,O);Eu(M);var $=(N^_>=0?-1:1)*Mn(M[2]);(r>$||r===$&&(O[0]||O[1]))&&(a+=N^_>=0?1:-1)}}return(s<-He||s<He&&l<-Gg)^a&1}function rm(e,t,n,r){return function(o){var i=t(o),s=tm(),a=t(s),l=!1,u,c,d,f={point:p,lineStart:y,lineEnd:g,polygonStart:function(){f.point=m,f.lineStart=b,f.lineEnd=w,c=[],u=[]},polygonEnd:function(){f.point=p,f.lineStart=y,f.lineEnd=g,c=yg(c);var x=lS(u,r);c.length?(l||(o.polygonStart(),l=!0),nm(c,uS,x,n,o)):x&&(l||(o.polygonStart(),l=!0),o.lineStart(),n(null,null,1,o),o.lineEnd()),l&&(o.polygonEnd(),l=!1),c=u=null},sphere:function(){o.polygonStart(),o.lineStart(),n(null,null,1,o),o.lineEnd(),o.polygonEnd()}};function p(x,S){e(x,S)&&o.point(x,S)}function h(x,S){i.point(x,S)}function y(){f.point=h,i.lineStart()}function g(){f.point=p,i.lineEnd()}function m(x,S){d.push([x,S]),a.point(x,S)}function b(){a.lineStart(),d=[]}function w(){m(d[0][0],d[0][1]),a.lineEnd();var x=a.clean(),S=s.result(),v,k=S.length,_,T,L;if(d.pop(),u.push(d),d=null,!!k){if(x&1){if(T=S[0],(_=T.length-1)>0){for(l||(o.polygonStart(),l=!0),o.lineStart(),v=0;v<_;++v)o.point((L=T[v])[0],L[1]);o.lineEnd()}return}k>1&&x&2&&S.push(S.pop().concat(S.shift())),c.push(S.filter(cS))}}return f}}function cS(e){return e.length>1}function uS(e,t){return((e=e.x)[0]<0?e[1]-St-He:St-e[1])-((t=t.x)[0]<0?t[1]-St-He:St-t[1])}const zh=rm(function(){return!0},fS,hS,[-Ve,-St]);function fS(e){var t=NaN,n=NaN,r=NaN,o;return{lineStart:function(){e.lineStart(),o=1},point:function(i,s){var a=i>0?Ve:-Ve,l=ot(i-t);ot(l-Ve)<He?(e.point(t,n=(n+s)/2>0?St:-St),e.point(r,n),e.lineEnd(),e.lineStart(),e.point(a,n),e.point(i,n),o=0):r!==a&&l>=Ve&&(ot(t-r)<He&&(t-=r*He),ot(i-a)<He&&(i-=a*He),n=dS(t,n,i,s),e.point(r,n),e.lineEnd(),e.lineStart(),e.point(a,n),o=0),e.point(t=i,n=s),r=a},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-o}}}function dS(e,t,n,r){var o,i,s=De(e-n);return ot(s)>He?ni((De(t)*(i=qe(r))*De(n)-De(r)*(o=qe(t))*De(e))/(o*i*s)):(t+r)/2}function hS(e,t,n,r){var o;if(e==null)o=n*St,r.point(-Ve,o),r.point(0,o),r.point(Ve,o),r.point(Ve,0),r.point(Ve,-o),r.point(0,-o),r.point(-Ve,-o),r.point(-Ve,0),r.point(-Ve,o);else if(ot(e[0]-t[0])>He){var i=e[0]<t[0]?Ve:-Ve;o=n*i/2,r.point(-i,o),r.point(0,o),r.point(i,o)}else r.point(t[0],t[1])}function pS(e){var t=qe(e),n=2*ut,r=t>0,o=ot(t)>He;function i(c,d,f,p){aS(p,e,n,f,c,d)}function s(c,d){return qe(c)*qe(d)>t}function a(c){var d,f,p,h,y;return{lineStart:function(){h=p=!1,y=1},point:function(g,m){var b=[g,m],w,x=s(g,m),S=r?x?0:u(g,m):x?u(g+(g<0?Ve:-Ve),m):0;if(!d&&(h=p=x)&&c.lineStart(),x!==p&&(w=l(d,b),(!w||wa(d,w)||wa(b,w))&&(b[2]=1)),x!==p)y=0,x?(c.lineStart(),w=l(b,d),c.point(w[0],w[1])):(w=l(d,b),c.point(w[0],w[1],2),c.lineEnd()),d=w;else if(o&&d&&r^x){var v;!(S&f)&&(v=l(b,d,!0))&&(y=0,r?(c.lineStart(),c.point(v[0][0],v[0][1]),c.point(v[1][0],v[1][1]),c.lineEnd()):(c.point(v[1][0],v[1][1]),c.lineEnd(),c.lineStart(),c.point(v[0][0],v[0][1],3)))}x&&(!d||!wa(d,b))&&c.point(b[0],b[1]),d=b,p=x,f=S},lineEnd:function(){p&&c.lineEnd(),d=null},clean:function(){return y|(h&&p)<<1}}}function l(c,d,f){var p=Ho(c),h=Ho(d),y=[1,0,0],g=Ka(p,h),m=Js(g,g),b=g[0],w=m-b*b;if(!w)return!f&&c;var x=t*m/w,S=-t*b/w,v=Ka(y,g),k=Zs(y,x),_=Zs(g,S);Ac(k,_);var T=v,L=Js(k,T),N=Js(T,T),I=L*L-N*(Js(k,k)-1);if(!(I<0)){var O=un(I),M=Zs(T,(-L-O)/N);if(Ac(M,k),M=Mu(M),!f)return M;var $=c[0],F=d[0],D=c[1],z=d[1],j;F<$&&(j=$,$=F,F=j);var G=F-$,J=ot(G-Ve)<He,re=J||G<He;if(!J&&z<D&&(j=D,D=z,z=j),re?J?D+z>0^M[1]<(ot(M[0]-$)<He?D:z):D<=M[1]&&M[1]<=z:G>Ve^($<=M[0]&&M[0]<=F)){var Q=Zs(T,(-L+O)/N);return Ac(Q,k),[M,Mu(Q)]}}}function u(c,d){var f=r?e:Ve-e,p=0;return c<-f?p|=1:c>f&&(p|=2),d<-f?p|=4:d>f&&(p|=8),p}return rm(s,a,i,r?[0,-e]:[-Ve,e-Ve])}function yS(e,t,n,r,o,i){var s=e[0],a=e[1],l=t[0],u=t[1],c=0,d=1,f=l-s,p=u-a,h;if(h=n-s,!(!f&&h>0)){if(h/=f,f<0){if(h<c)return;h<d&&(d=h)}else if(f>0){if(h>d)return;h>c&&(c=h)}if(h=o-s,!(!f&&h<0)){if(h/=f,f<0){if(h>d)return;h>c&&(c=h)}else if(f>0){if(h<c)return;h<d&&(d=h)}if(h=r-a,!(!p&&h>0)){if(h/=p,p<0){if(h<c)return;h<d&&(d=h)}else if(p>0){if(h>d)return;h>c&&(c=h)}if(h=i-a,!(!p&&h<0)){if(h/=p,p<0){if(h>d)return;h>c&&(c=h)}else if(p>0){if(h<c)return;h<d&&(d=h)}return c>0&&(e[0]=s+c*f,e[1]=a+c*p),d<1&&(t[0]=s+d*f,t[1]=a+d*p),!0}}}}}var xi=1e9,ea=-xi;function om(e,t,n,r){function o(u,c){return e<=u&&u<=n&&t<=c&&c<=r}function i(u,c,d,f){var p=0,h=0;if(u==null||(p=s(u,d))!==(h=s(c,d))||l(u,c)<0^d>0)do f.point(p===0||p===3?e:n,p>1?r:t);while((p=(p+d+4)%4)!==h);else f.point(c[0],c[1])}function s(u,c){return ot(u[0]-e)<He?c>0?0:3:ot(u[0]-n)<He?c>0?2:1:ot(u[1]-t)<He?c>0?1:0:c>0?3:2}function a(u,c){return l(u.x,c.x)}function l(u,c){var d=s(u,1),f=s(c,1);return d!==f?d-f:d===0?c[1]-u[1]:d===1?u[0]-c[0]:d===2?u[1]-c[1]:c[0]-u[0]}return function(u){var c=u,d=tm(),f,p,h,y,g,m,b,w,x,S,v,k={point:_,lineStart:I,lineEnd:O,polygonStart:L,polygonEnd:N};function _($,F){o($,F)&&c.point($,F)}function T(){for(var $=0,F=0,D=p.length;F<D;++F)for(var z=p[F],j=1,G=z.length,J=z[0],re,Q,ve=J[0],Ce=J[1];j<G;++j)re=ve,Q=Ce,J=z[j],ve=J[0],Ce=J[1],Q<=r?Ce>r&&(ve-re)*(r-Q)>(Ce-Q)*(e-re)&&++$:Ce<=r&&(ve-re)*(r-Q)<(Ce-Q)*(e-re)&&--$;return $}function L(){c=d,f=[],p=[],v=!0}function N(){var $=T(),F=v&&$,D=(f=yg(f)).length;(F||D)&&(u.polygonStart(),F&&(u.lineStart(),i(null,null,1,u),u.lineEnd()),D&&nm(f,a,$,i,u),u.polygonEnd()),c=u,f=p=h=null}function I(){k.point=M,p&&p.push(h=[]),S=!0,x=!1,b=w=NaN}function O(){f&&(M(y,g),m&&x&&d.rejoin(),f.push(d.result())),k.point=_,x&&c.lineEnd()}function M($,F){var D=o($,F);if(p&&h.push([$,F]),S)y=$,g=F,m=D,S=!1,D&&(c.lineStart(),c.point($,F));else if(D&&x)c.point($,F);else{var z=[b=Math.max(ea,Math.min(xi,b)),w=Math.max(ea,Math.min(xi,w))],j=[$=Math.max(ea,Math.min(xi,$)),F=Math.max(ea,Math.min(xi,F))];yS(z,j,e,t,n,r)?(x||(c.lineStart(),c.point(z[0],z[1])),c.point(j[0],j[1]),D||c.lineEnd(),v=!1):D&&(c.lineStart(),c.point($,F),v=!1)}b=$,w=F,x=D}return k}}const is=e=>e;var Oc=new Ln,Ou=new Ln,im,sm,Cu,Nu,ar={point:Gt,lineStart:Gt,lineEnd:Gt,polygonStart:function(){ar.lineStart=gS,ar.lineEnd=bS},polygonEnd:function(){ar.lineStart=ar.lineEnd=ar.point=Gt,Oc.add(ot(Ou)),Ou=new Ln},result:function(){var e=Oc/2;return Oc=new Ln,e}};function gS(){ar.point=mS}function mS(e,t){ar.point=am,im=Cu=e,sm=Nu=t}function am(e,t){Ou.add(Nu*e-Cu*t),Cu=e,Nu=t}function bS(){am(im,sm)}var Uo=1/0,Ya=Uo,ss=-Uo,Ga=ss,Va={point:wS,lineStart:Gt,lineEnd:Gt,polygonStart:Gt,polygonEnd:Gt,result:function(){var e=[[Uo,Ya],[ss,Ga]];return ss=Ga=-(Ya=Uo=1/0),e}};function wS(e,t){e<Uo&&(Uo=e),e>ss&&(ss=e),t<Ya&&(Ya=t),t>Ga&&(Ga=t)}var Iu=0,Lu=0,vi=0,Xa=0,Ja=0,To=0,Fu=0,Ru=0,ki=0,lm,cm,Wn,qn,vn={point:no,lineStart:Dh,lineEnd:jh,polygonStart:function(){vn.lineStart=kS,vn.lineEnd=SS},polygonEnd:function(){vn.point=no,vn.lineStart=Dh,vn.lineEnd=jh},result:function(){var e=ki?[Fu/ki,Ru/ki]:To?[Xa/To,Ja/To]:vi?[Iu/vi,Lu/vi]:[NaN,NaN];return Iu=Lu=vi=Xa=Ja=To=Fu=Ru=ki=0,e}};function no(e,t){Iu+=e,Lu+=t,++vi}function Dh(){vn.point=xS}function xS(e,t){vn.point=vS,no(Wn=e,qn=t)}function vS(e,t){var n=e-Wn,r=t-qn,o=un(n*n+r*r);Xa+=o*(Wn+e)/2,Ja+=o*(qn+t)/2,To+=o,no(Wn=e,qn=t)}function jh(){vn.point=no}function kS(){vn.point=$S}function SS(){um(lm,cm)}function $S(e,t){vn.point=um,no(lm=Wn=e,cm=qn=t)}function um(e,t){var n=e-Wn,r=t-qn,o=un(n*n+r*r);Xa+=o*(Wn+e)/2,Ja+=o*(qn+t)/2,To+=o,o=qn*e-Wn*t,Fu+=o*(Wn+e),Ru+=o*(qn+t),ki+=o*3,no(Wn=e,qn=t)}function fm(e){this._context=e}fm.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,en);break}}},result:Gt};var Pu=new Ln,Cc,dm,hm,Si,$i,as={point:Gt,lineStart:function(){as.point=_S},lineEnd:function(){Cc&&pm(dm,hm),as.point=Gt},polygonStart:function(){Cc=!0},polygonEnd:function(){Cc=null},result:function(){var e=+Pu;return Pu=new Ln,e}};function _S(e,t){as.point=pm,dm=Si=e,hm=$i=t}function pm(e,t){Si-=e,$i-=t,Pu.add(un(Si*Si+$i*$i)),Si=e,$i=t}let Wh,Za,qh,Bh;class Hh{constructor(t){this._append=t==null?ym:MS(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==qh||this._append!==Za){const r=this._radius,o=this._;this._="",this._append`m0,${r}a${r},${r} 0 1,1 0,${-2*r}a${r},${r} 0 1,1 0,${2*r}z`,qh=r,Za=this._append,Bh=this._,this._=o}this._+=Bh;break}}}result(){const t=this._;return this._="",t.length?t:null}}function ym(e){let t=1;this._+=e[0];for(const n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function MS(e){const t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return ym;if(t!==Wh){const n=10**t;Wh=t,Za=function(o){let i=1;this._+=o[0];for(const s=o.length;i<s;++i)this._+=Math.round(arguments[i]*n)/n+o[i]}}return Za}function ES(e,t){let n=3,r=4.5,o,i;function s(a){return a&&(typeof r=="function"&&i.pointRadius(+r.apply(this,arguments)),qr(a,o(i))),i.result()}return s.area=function(a){return qr(a,o(ar)),ar.result()},s.measure=function(a){return qr(a,o(as)),as.result()},s.bounds=function(a){return qr(a,o(Va)),Va.result()},s.centroid=function(a){return qr(a,o(vn)),vn.result()},s.projection=function(a){return arguments.length?(o=a==null?(e=null,is):(e=a).stream,s):e},s.context=function(a){return arguments.length?(i=a==null?(t=null,new Hh(n)):new fm(t=a),typeof r!="function"&&i.pointRadius(r),s):t},s.pointRadius=function(a){return arguments.length?(r=typeof a=="function"?a:(i.pointRadius(+a),+a),s):r},s.digits=function(a){if(!arguments.length)return n;if(a==null)n=null;else{const l=Math.floor(a);if(!(l>=0))throw new RangeError(`invalid digits: ${a}`);n=l}return t===null&&(i=new Hh(n)),s},s.projection(e).digits(n).context(t)}function Pl(e){return function(t){var n=new zu;for(var r in e)n[r]=e[r];return n.stream=t,n}}function zu(){}zu.prototype={constructor:zu,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function Af(e,t,n){var r=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),r!=null&&e.clipExtent(null),qr(n,e.stream(Va)),t(Va.result()),r!=null&&e.clipExtent(r),e}function zl(e,t,n){return Af(e,function(r){var o=t[1][0]-t[0][0],i=t[1][1]-t[0][1],s=Math.min(o/(r[1][0]-r[0][0]),i/(r[1][1]-r[0][1])),a=+t[0][0]+(o-s*(r[1][0]+r[0][0]))/2,l=+t[0][1]+(i-s*(r[1][1]+r[0][1]))/2;e.scale(150*s).translate([a,l])},n)}function Tf(e,t,n){return zl(e,[[0,0],t],n)}function Of(e,t,n){return Af(e,function(r){var o=+t,i=o/(r[1][0]-r[0][0]),s=(o-i*(r[1][0]+r[0][0]))/2,a=-i*r[0][1];e.scale(150*i).translate([s,a])},n)}function Cf(e,t,n){return Af(e,function(r){var o=+t,i=o/(r[1][1]-r[0][1]),s=-i*r[0][0],a=(o-i*(r[1][1]+r[0][1]))/2;e.scale(150*i).translate([s,a])},n)}var Uh=16,AS=qe(30*ut);function Kh(e,t){return+t?OS(e,t):TS(e)}function TS(e){return Pl({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function OS(e,t){function n(r,o,i,s,a,l,u,c,d,f,p,h,y,g){var m=u-r,b=c-o,w=m*m+b*b;if(w>4*t&&y--){var x=s+f,S=a+p,v=l+h,k=un(x*x+S*S+v*v),_=Mn(v/=k),T=ot(ot(v)-1)<He||ot(i-d)<He?(i+d)/2:Yn(S,x),L=e(T,_),N=L[0],I=L[1],O=N-r,M=I-o,$=b*O-m*M;($*$/w>t||ot((m*O+b*M)/w-.5)>.3||s*f+a*p+l*h<AS)&&(n(r,o,i,s,a,l,N,I,T,x/=k,S/=k,v,y,g),g.point(N,I),n(N,I,T,x,S,v,u,c,d,f,p,h,y,g))}}return function(r){var o,i,s,a,l,u,c,d,f,p,h,y,g={point:m,lineStart:b,lineEnd:x,polygonStart:function(){r.polygonStart(),g.lineStart=S},polygonEnd:function(){r.polygonEnd(),g.lineStart=b}};function m(_,T){_=e(_,T),r.point(_[0],_[1])}function b(){d=NaN,g.point=w,r.lineStart()}function w(_,T){var L=Ho([_,T]),N=e(_,T);n(d,f,c,p,h,y,d=N[0],f=N[1],c=_,p=L[0],h=L[1],y=L[2],Uh,r),r.point(d,f)}function x(){g.point=m,r.lineEnd()}function S(){b(),g.point=v,g.lineEnd=k}function v(_,T){w(o=_,T),i=d,s=f,a=p,l=h,u=y,g.point=w}function k(){n(d,f,c,p,h,y,i,s,o,a,l,u,Uh,r),g.lineEnd=x,x()}return g}}var CS=Pl({point:function(e,t){this.stream.point(e*ut,t*ut)}});function NS(e){return Pl({point:function(t,n){var r=e(t,n);return this.stream.point(r[0],r[1])}})}function IS(e,t,n,r,o){function i(s,a){return s*=r,a*=o,[t+e*s,n-e*a]}return i.invert=function(s,a){return[(s-t)/e*r,(n-a)/e*o]},i}function Yh(e,t,n,r,o,i){if(!i)return IS(e,t,n,r,o);var s=qe(i),a=De(i),l=s*e,u=a*e,c=s/e,d=a/e,f=(a*n-s*t)/e,p=(a*t+s*n)/e;function h(y,g){return y*=r,g*=o,[l*y-u*g+t,n-u*y-l*g]}return h.invert=function(y,g){return[r*(c*y-d*g+f),o*(p-d*y-c*g)]},h}function Lr(e){return gm(function(){return e})()}function gm(e){var t,n=150,r=480,o=250,i=0,s=0,a=0,l=0,u=0,c,d=0,f=1,p=1,h=null,y=zh,g=null,m,b,w,x=is,S=.5,v,k,_,T,L;function N($){return _($[0]*ut,$[1]*ut)}function I($){return $=_.invert($[0],$[1]),$&&[$[0]*Ut,$[1]*Ut]}N.stream=function($){return T&&L===$?T:T=CS(NS(c)(y(v(x(L=$)))))},N.preclip=function($){return arguments.length?(y=$,h=void 0,M()):y},N.postclip=function($){return arguments.length?(x=$,g=m=b=w=null,M()):x},N.clipAngle=function($){return arguments.length?(y=+$?pS(h=$*ut):(h=null,zh),M()):h*Ut},N.clipExtent=function($){return arguments.length?(x=$==null?(g=m=b=w=null,is):om(g=+$[0][0],m=+$[0][1],b=+$[1][0],w=+$[1][1]),M()):g==null?null:[[g,m],[b,w]]},N.scale=function($){return arguments.length?(n=+$,O()):n},N.translate=function($){return arguments.length?(r=+$[0],o=+$[1],O()):[r,o]},N.center=function($){return arguments.length?(i=$[0]%360*ut,s=$[1]%360*ut,O()):[i*Ut,s*Ut]},N.rotate=function($){return arguments.length?(a=$[0]%360*ut,l=$[1]%360*ut,u=$.length>2?$[2]%360*ut:0,O()):[a*Ut,l*Ut,u*Ut]},N.angle=function($){return arguments.length?(d=$%360*ut,O()):d*Ut},N.reflectX=function($){return arguments.length?(f=$?-1:1,O()):f<0},N.reflectY=function($){return arguments.length?(p=$?-1:1,O()):p<0},N.precision=function($){return arguments.length?(v=Kh(k,S=$*$),M()):un(S)},N.fitExtent=function($,F){return zl(N,$,F)},N.fitSize=function($,F){return Tf(N,$,F)},N.fitWidth=function($,F){return Of(N,$,F)},N.fitHeight=function($,F){return Cf(N,$,F)};function O(){var $=Yh(n,0,0,f,p,d).apply(null,t(i,s)),F=Yh(n,r-$[0],o-$[1],f,p,d);return c=em(a,l,u),k=Au(t,F),_=Au(c,k),v=Kh(k,S),M()}function M(){return T=L=null,N}return function(){return t=e.apply(this,arguments),N.invert=t.invert&&I,O()}}function Nf(e){var t=0,n=Ve/3,r=gm(e),o=r(t,n);return o.parallels=function(i){return arguments.length?r(t=i[0]*ut,n=i[1]*ut):[t*Ut,n*Ut]},o}function LS(e){var t=qe(e);function n(r,o){return[r*t,De(o)/t]}return n.invert=function(r,o){return[r/t,Mn(o*t)]},n}function FS(e,t){var n=De(e),r=(n+De(t))/2;if(ot(r)<He)return LS(e);var o=1+n*(2*r-n),i=un(o)/r;function s(a,l){var u=un(o-2*r*De(l))/r;return[u*De(a*=r),i-u*qe(a)]}return s.invert=function(a,l){var u=i-l,c=Yn(a,ot(u))*kn(u);return u*r<0&&(c-=Ve*kn(a)*kn(u)),[c/r,Mn((o-(a*a+u*u)*r*r)/(2*r))]},s}function Qa(){return Nf(FS).scale(155.424).center([0,33.6442])}function mm(){return Qa().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function RS(e){var t=e.length;return{point:function(n,r){for(var o=-1;++o<t;)e[o].point(n,r)},sphere:function(){for(var n=-1;++n<t;)e[n].sphere()},lineStart:function(){for(var n=-1;++n<t;)e[n].lineStart()},lineEnd:function(){for(var n=-1;++n<t;)e[n].lineEnd()},polygonStart:function(){for(var n=-1;++n<t;)e[n].polygonStart()},polygonEnd:function(){for(var n=-1;++n<t;)e[n].polygonEnd()}}}function PS(){var e,t,n=mm(),r,o=Qa().rotate([154,0]).center([-2,58.5]).parallels([55,65]),i,s=Qa().rotate([157,0]).center([-3,19.9]).parallels([8,18]),a,l,u={point:function(f,p){l=[f,p]}};function c(f){var p=f[0],h=f[1];return l=null,r.point(p,h),l||(i.point(p,h),l)||(a.point(p,h),l)}c.invert=function(f){var p=n.scale(),h=n.translate(),y=(f[0]-h[0])/p,g=(f[1]-h[1])/p;return(g>=.12&&g<.234&&y>=-.425&&y<-.214?o:g>=.166&&g<.234&&y>=-.214&&y<-.115?s:n).invert(f)},c.stream=function(f){return e&&t===f?e:e=RS([n.stream(t=f),o.stream(f),s.stream(f)])},c.precision=function(f){return arguments.length?(n.precision(f),o.precision(f),s.precision(f),d()):n.precision()},c.scale=function(f){return arguments.length?(n.scale(f),o.scale(f*.35),s.scale(f),c.translate(n.translate())):n.scale()},c.translate=function(f){if(!arguments.length)return n.translate();var p=n.scale(),h=+f[0],y=+f[1];return r=n.translate(f).clipExtent([[h-.455*p,y-.238*p],[h+.455*p,y+.238*p]]).stream(u),i=o.translate([h-.307*p,y+.201*p]).clipExtent([[h-.425*p+He,y+.12*p+He],[h-.214*p-He,y+.234*p-He]]).stream(u),a=s.translate([h-.205*p,y+.212*p]).clipExtent([[h-.214*p+He,y+.166*p+He],[h-.115*p-He,y+.234*p-He]]).stream(u),d()},c.fitExtent=function(f,p){return zl(c,f,p)},c.fitSize=function(f,p){return Tf(c,f,p)},c.fitWidth=function(f,p){return Of(c,f,p)},c.fitHeight=function(f,p){return Cf(c,f,p)};function d(){return e=t=null,c}return c.scale(1070)}function bm(e){return function(t,n){var r=qe(t),o=qe(n),i=e(r*o);return i===1/0?[2,0]:[i*o*De(t),i*De(n)]}}function Ss(e){return function(t,n){var r=un(t*t+n*n),o=e(r),i=De(o),s=qe(o);return[Yn(t*i,r*s),Mn(r&&n*i/r)]}}var wm=bm(function(e){return un(2/(1+e))});wm.invert=Ss(function(e){return 2*Mn(e/2)});function zS(){return Lr(wm).scale(124.75).clipAngle(180-.001)}var xm=bm(function(e){return(e=Xg(e))&&e/De(e)});xm.invert=Ss(function(e){return e});function DS(){return Lr(xm).scale(79.4188).clipAngle(180-.001)}function Dl(e,t){return[e,Ba(Ef((St+t)/2))]}Dl.invert=function(e,t){return[e,2*ni(Vg(t))-St]};function jS(){return vm(Dl).scale(961/en)}function vm(e){var t=Lr(e),n=t.center,r=t.scale,o=t.translate,i=t.clipExtent,s=null,a,l,u;t.scale=function(d){return arguments.length?(r(d),c()):r()},t.translate=function(d){return arguments.length?(o(d),c()):o()},t.center=function(d){return arguments.length?(n(d),c()):n()},t.clipExtent=function(d){return arguments.length?(d==null?s=a=l=u=null:(s=+d[0][0],a=+d[0][1],l=+d[1][0],u=+d[1][1]),c()):s==null?null:[[s,a],[l,u]]};function c(){var d=Ve*r(),f=t(sS(t.rotate()).invert([0,0]));return i(s==null?[[f[0]-d,f[1]-d],[f[0]+d,f[1]+d]]:e===Dl?[[Math.max(f[0]-d,s),a],[Math.min(f[0]+d,l),u]]:[[s,Math.max(f[1]-d,a)],[l,Math.min(f[1]+d,u)]])}return c()}function ta(e){return Ef((St+e)/2)}function WS(e,t){var n=qe(e),r=e===t?De(e):Ba(n/qe(t))/Ba(ta(t)/ta(e)),o=n*Ec(ta(e),r)/r;if(!r)return Dl;function i(s,a){o>0?a<-St+He&&(a=-St+He):a>St-He&&(a=St-He);var l=o/Ec(ta(a),r);return[l*De(r*s),o-l*qe(r*s)]}return i.invert=function(s,a){var l=o-a,u=kn(r)*un(s*s+l*l),c=Yn(s,ot(l))*kn(l);return l*r<0&&(c-=Ve*kn(s)*kn(l)),[c/r,2*ni(Ec(o/u,1/r))-St]},i}function qS(){return Nf(WS).scale(109.5).parallels([30,30])}function el(e,t){return[e,t]}el.invert=el;function BS(){return Lr(el).scale(152.63)}function HS(e,t){var n=qe(e),r=e===t?De(e):(n-qe(t))/(t-e),o=n/r+e;if(ot(r)<He)return el;function i(s,a){var l=o-a,u=r*s;return[l*De(u),o-l*qe(u)]}return i.invert=function(s,a){var l=o-a,u=Yn(s,ot(l))*kn(l);return l*r<0&&(u-=Ve*kn(s)*kn(l)),[u/r,o-kn(r)*un(s*s+l*l)]},i}function US(){return Nf(HS).scale(131.154).center([0,13.9389])}var Ri=1.340264,Pi=-.081106,zi=893e-6,Di=.003796,tl=un(3)/2,KS=12;function km(e,t){var n=Mn(tl*De(t)),r=n*n,o=r*r*r;return[e*qe(n)/(tl*(Ri+3*Pi*r+o*(7*zi+9*Di*r))),n*(Ri+Pi*r+o*(zi+Di*r))]}km.invert=function(e,t){for(var n=t,r=n*n,o=r*r*r,i=0,s,a,l;i<KS&&(a=n*(Ri+Pi*r+o*(zi+Di*r))-t,l=Ri+3*Pi*r+o*(7*zi+9*Di*r),n-=s=a/l,r=n*n,o=r*r*r,!(ot(s)<Gg));++i);return[tl*e*(Ri+3*Pi*r+o*(7*zi+9*Di*r))/qe(n),Mn(De(n)/tl)]};function YS(){return Lr(km).scale(177.158)}function Sm(e,t){var n=qe(t),r=qe(e)*n;return[n*De(e)/r,De(t)/r]}Sm.invert=Ss(ni);function GS(){return Lr(Sm).scale(144.049).clipAngle(60)}function VS(){var e=1,t=0,n=0,r=1,o=1,i=0,s,a,l=null,u,c,d,f=1,p=1,h=Pl({point:function(x,S){var v=w([x,S]);this.stream.point(v[0],v[1])}}),y=is,g,m;function b(){return f=e*r,p=e*o,g=m=null,w}function w(x){var S=x[0]*f,v=x[1]*p;if(i){var k=v*s-S*a;S=S*s+v*a,v=k}return[S+t,v+n]}return w.invert=function(x){var S=x[0]-t,v=x[1]-n;if(i){var k=v*s+S*a;S=S*s-v*a,v=k}return[S/f,v/p]},w.stream=function(x){return g&&m===x?g:g=h(y(m=x))},w.postclip=function(x){return arguments.length?(y=x,l=u=c=d=null,b()):y},w.clipExtent=function(x){return arguments.length?(y=x==null?(l=u=c=d=null,is):om(l=+x[0][0],u=+x[0][1],c=+x[1][0],d=+x[1][1]),b()):l==null?null:[[l,u],[c,d]]},w.scale=function(x){return arguments.length?(e=+x,b()):e},w.translate=function(x){return arguments.length?(t=+x[0],n=+x[1],b()):[t,n]},w.angle=function(x){return arguments.length?(i=x%360*ut,a=De(i),s=qe(i),b()):i*Ut},w.reflectX=function(x){return arguments.length?(r=x?-1:1,b()):r<0},w.reflectY=function(x){return arguments.length?(o=x?-1:1,b()):o<0},w.fitExtent=function(x,S){return zl(w,x,S)},w.fitSize=function(x,S){return Tf(w,x,S)},w.fitWidth=function(x,S){return Of(w,x,S)},w.fitHeight=function(x,S){return Cf(w,x,S)},w}function $m(e,t){return[qe(t)*De(e),De(t)]}$m.invert=Ss(Mn);function XS(){return Lr($m).scale(249.5).clipAngle(90+He)}function _m(e,t){var n=qe(t),r=1+qe(e)*n;return[n*De(e)/r,De(t)/r]}_m.invert=Ss(function(e){return 2*ni(e)});function JS(){return Lr(_m).scale(250).clipAngle(142)}function Mm(e,t){return[Ba(Ef((St+t)/2)),-e]}Mm.invert=function(e,t){return[-t,2*ni(Vg(e))-St]};function ZS(){var e=vm(Mm),t=e.center,n=e.rotate;return e.center=function(r){return arguments.length?t([-r[1],r[0]]):(r=t(),[r[1],-r[0]])},e.rotate=function(r){return arguments.length?n([r[0],r[1],r.length>2?r[2]+90:90]):(r=n(),[r[0],r[1],r[2]-90])},n([0,0,90]).scale(159.155)}function ao(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e);break}return this}const Gh=Symbol("implicit");function If(){var e=new ih,t=[],n=[],r=Gh;function o(i){let s=e.get(i);if(s===void 0){if(r!==Gh)return r;e.set(i,s=t.push(i)-1)}return n[s%n.length]}return o.domain=function(i){if(!arguments.length)return t.slice();t=[],e=new ih;for(const s of i)e.has(s)||e.set(s,t.push(s)-1);return o},o.range=function(i){return arguments.length?(n=Array.from(i),o):n.slice()},o.unknown=function(i){return arguments.length?(r=i,o):r},o.copy=function(){return If(t,n).unknown(r)},ao.apply(o,arguments),o}function Lf(){var e=If().unknown(void 0),t=e.domain,n=e.range,r=0,o=1,i,s,a=!1,l=0,u=0,c=.5;delete e.unknown;function d(){var f=t().length,p=o<r,h=p?o:r,y=p?r:o;i=(y-h)/Math.max(1,f-l+u*2),a&&(i=Math.floor(i)),h+=(y-h-i*(f-l))*c,s=i*(1-l),a&&(h=Math.round(h),s=Math.round(s));var g=sx(f).map(function(m){return h+i*m});return n(p?g.reverse():g)}return e.domain=function(f){return arguments.length?(t(f),d()):t()},e.range=function(f){return arguments.length?([r,o]=f,r=+r,o=+o,d()):[r,o]},e.rangeRound=function(f){return[r,o]=f,r=+r,o=+o,a=!0,d()},e.bandwidth=function(){return s},e.step=function(){return i},e.round=function(f){return arguments.length?(a=!!f,d()):a},e.padding=function(f){return arguments.length?(l=Math.min(1,u=+f),d()):l},e.paddingInner=function(f){return arguments.length?(l=Math.min(1,f),d()):l},e.paddingOuter=function(f){return arguments.length?(u=+f,d()):u},e.align=function(f){return arguments.length?(c=Math.max(0,Math.min(1,f)),d()):c},e.copy=function(){return Lf(t(),[r,o]).round(a).paddingInner(l).paddingOuter(u).align(c)},ao.apply(d(),arguments)}function Em(e){var t=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,delete e.paddingOuter,e.copy=function(){return Em(t())},e}function QS(){return Em(Lf.apply(null,arguments).paddingInner(1))}function e$(e){return function(){return e}}function t$(e){return+e}var Vh=[0,1];function Hn(e){return e}function Du(e,t){return(t-=e=+e)?function(n){return(n-e)/t}:e$(isNaN(t)?NaN:.5)}function n$(e,t){var n;return e>t&&(n=e,e=t,t=n),function(r){return Math.max(e,Math.min(t,r))}}function r$(e,t,n){var r=e[0],o=e[1],i=t[0],s=t[1];return o<r?(r=Du(o,r),i=n(s,i)):(r=Du(r,o),i=n(i,s)),function(a){return i(r(a))}}function o$(e,t,n){var r=Math.min(e.length,t.length)-1,o=new Array(r),i=new Array(r),s=-1;for(e[r]<e[0]&&(e=e.slice().reverse(),t=t.slice().reverse());++s<r;)o[s]=Du(e[s],e[s+1]),i[s]=n(t[s],t[s+1]);return function(a){var l=Zw(e,a,1,r)-1;return i[l](o[l](a))}}function $s(e,t){return t.domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown())}function jl(){var e=Vh,t=Vh,n=Ll,r,o,i,s=Hn,a,l,u;function c(){var f=Math.min(e.length,t.length);return s!==Hn&&(s=n$(e[0],e[f-1])),a=f>2?o$:r$,l=u=null,d}function d(f){return f==null||isNaN(f=+f)?i:(l||(l=a(e.map(r),t,n)))(r(s(f)))}return d.invert=function(f){return s(o((u||(u=a(t,e.map(r),Tn)))(f)))},d.domain=function(f){return arguments.length?(e=Array.from(f,t$),c()):e.slice()},d.range=function(f){return arguments.length?(t=Array.from(f),c()):t.slice()},d.rangeRound=function(f){return t=Array.from(f),n=_k,c()},d.clamp=function(f){return arguments.length?(s=f?!0:Hn,c()):s!==Hn},d.interpolate=function(f){return arguments.length?(n=f,c()):n},d.unknown=function(f){return arguments.length?(i=f,d):i},function(f,p){return r=f,o=p,c()}}function Am(){return jl()(Hn,Hn)}function i$(e,t,n,r){var o=uu(e,t,n),i;switch(r=rs(r??",f"),r.type){case"s":{var s=Math.max(Math.abs(e),Math.abs(t));return r.precision==null&&!isNaN(i=eS(o,s))&&(r.precision=i),Yg(r,s)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(i=tS(o,Math.max(Math.abs(e),Math.abs(t))))&&(r.precision=i-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(i=Q2(o))&&(r.precision=i-(r.type==="%")*2);break}}return ti(r)}function Ff(e){var t=e.domain;return e.ticks=function(n){var r=t();return lu(r[0],r[r.length-1],n??10)},e.tickFormat=function(n,r){var o=t();return i$(o[0],o[o.length-1],n??10,r)},e.nice=function(n){n==null&&(n=10);var r=t(),o=0,i=r.length-1,s=r[o],a=r[i],l,u,c=10;for(a<s&&(u=s,s=a,a=u,u=o,o=i,i=u);c-- >0;){if(u=cu(s,a,n),u===l)return r[o]=s,r[i]=a,t(r);if(u>0)s=Math.floor(s/u)*u,a=Math.ceil(a/u)*u;else if(u<0)s=Math.ceil(s*u)/u,a=Math.floor(a*u)/u;else break;l=u}return e},e}function ji(){var e=Am();return e.copy=function(){return $s(e,ji())},ao.apply(e,arguments),Ff(e)}function Tm(e,t){e=e.slice();var n=0,r=e.length-1,o=e[n],i=e[r],s;return i<o&&(s=n,n=r,r=s,s=o,o=i,i=s),e[n]=t.floor(o),e[r]=t.ceil(i),e}function Xh(e){return Math.log(e)}function Jh(e){return Math.exp(e)}function s$(e){return-Math.log(-e)}function a$(e){return-Math.exp(-e)}function l$(e){return isFinite(e)?+("1e"+e):e<0?0:e}function c$(e){return e===10?l$:e===Math.E?Math.exp:t=>Math.pow(e,t)}function u$(e){return e===Math.E?Math.log:e===10&&Math.log10||e===2&&Math.log2||(e=Math.log(e),t=>Math.log(t)/e)}function Zh(e){return(t,n)=>-e(-t,n)}function f$(e){const t=e(Xh,Jh),n=t.domain;let r=10,o,i;function s(){return o=u$(r),i=c$(r),n()[0]<0?(o=Zh(o),i=Zh(i),e(s$,a$)):e(Xh,Jh),t}return t.base=function(a){return arguments.length?(r=+a,s()):r},t.domain=function(a){return arguments.length?(n(a),s()):n()},t.ticks=a=>{const l=n();let u=l[0],c=l[l.length-1];const d=c<u;d&&([u,c]=[c,u]);let f=o(u),p=o(c),h,y;const g=a==null?10:+a;let m=[];if(!(r%1)&&p-f<g){if(f=Math.floor(f),p=Math.ceil(p),u>0){for(;f<=p;++f)for(h=1;h<r;++h)if(y=f<0?h/i(-f):h*i(f),!(y<u)){if(y>c)break;m.push(y)}}else for(;f<=p;++f)for(h=r-1;h>=1;--h)if(y=f>0?h/i(-f):h*i(f),!(y<u)){if(y>c)break;m.push(y)}m.length*2<g&&(m=lu(u,c,g))}else m=lu(f,p,Math.min(p-f,g)).map(i);return d?m.reverse():m},t.tickFormat=(a,l)=>{if(a==null&&(a=10),l==null&&(l=r===10?"s":","),typeof l!="function"&&(!(r%1)&&(l=rs(l)).precision==null&&(l.trim=!0),l=ti(l)),a===1/0)return l;const u=Math.max(1,r*a/t.ticks().length);return c=>{let d=c/i(Math.round(o(c)));return d*r<r-.5&&(d*=r),d<=u?l(c):""}},t.nice=()=>n(Tm(n(),{floor:a=>i(Math.floor(o(a))),ceil:a=>i(Math.ceil(o(a)))})),t}function Om(){const e=f$(jl()).domain([1,10]);return e.copy=()=>$s(e,Om()).base(e.base()),ao.apply(e,arguments),e}function Qh(e){return function(t){return Math.sign(t)*Math.log1p(Math.abs(t/e))}}function ep(e){return function(t){return Math.sign(t)*Math.expm1(Math.abs(t))*e}}function d$(e){var t=1,n=e(Qh(t),ep(t));return n.constant=function(r){return arguments.length?e(Qh(t=+r),ep(t)):t},Ff(n)}function Cm(){var e=d$(jl());return e.copy=function(){return $s(e,Cm()).constant(e.constant())},ao.apply(e,arguments)}function tp(e){return function(t){return t<0?-Math.pow(-t,e):Math.pow(t,e)}}function h$(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function p$(e){return e<0?-e*e:e*e}function y$(e){var t=e(Hn,Hn),n=1;function r(){return n===1?e(Hn,Hn):n===.5?e(h$,p$):e(tp(n),tp(1/n))}return t.exponent=function(o){return arguments.length?(n=+o,r()):n},Ff(t)}function Nm(){var e=y$(jl());return e.copy=function(){return $s(e,Nm()).exponent(e.exponent())},ao.apply(e,arguments),e}const Nc=new Date,Ic=new Date;function Ct(e,t,n,r){function o(i){return e(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(e(i=new Date(+i)),i),o.ceil=i=>(e(i=new Date(i-1)),t(i,1),e(i),i),o.round=i=>{const s=o(i),a=o.ceil(i);return i-s<a-i?s:a},o.offset=(i,s)=>(t(i=new Date(+i),s==null?1:Math.floor(s)),i),o.range=(i,s,a)=>{const l=[];if(i=o.ceil(i),a=a==null?1:Math.floor(a),!(i<s)||!(a>0))return l;let u;do l.push(u=new Date(+i)),t(i,a),e(i);while(u<i&&i<s);return l},o.filter=i=>Ct(s=>{if(s>=s)for(;e(s),!i(s);)s.setTime(s-1)},(s,a)=>{if(s>=s)if(a<0)for(;++a<=0;)for(;t(s,-1),!i(s););else for(;--a>=0;)for(;t(s,1),!i(s););}),n&&(o.count=(i,s)=>(Nc.setTime(+i),Ic.setTime(+s),e(Nc),e(Ic),Math.floor(n(Nc,Ic))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(r?s=>r(s)%i===0:s=>o.count(0,s)%i===0):o)),o}const nl=Ct(()=>{},(e,t)=>{e.setTime(+e+t)},(e,t)=>t-e);nl.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?Ct(t=>{t.setTime(Math.floor(t/e)*e)},(t,n)=>{t.setTime(+t+n*e)},(t,n)=>(n-t)/e):nl);nl.range;const lr=1e3,Sn=lr*60,cr=Sn*60,vr=cr*24,Rf=vr*7,np=vr*30,Lc=vr*365,Oo=Ct(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*lr)},(e,t)=>(t-e)/lr,e=>e.getUTCSeconds());Oo.range;const Wl=Ct(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*lr)},(e,t)=>{e.setTime(+e+t*Sn)},(e,t)=>(t-e)/Sn,e=>e.getMinutes());Wl.range;const g$=Ct(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*Sn)},(e,t)=>(t-e)/Sn,e=>e.getUTCMinutes());g$.range;const ql=Ct(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*lr-e.getMinutes()*Sn)},(e,t)=>{e.setTime(+e+t*cr)},(e,t)=>(t-e)/cr,e=>e.getHours());ql.range;const m$=Ct(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*cr)},(e,t)=>(t-e)/cr,e=>e.getUTCHours());m$.range;const ri=Ct(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*Sn)/vr,e=>e.getDate()-1);ri.range;const Pf=Ct(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/vr,e=>e.getUTCDate()-1);Pf.range;const b$=Ct(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/vr,e=>Math.floor(e/vr));b$.range;function lo(e){return Ct(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(t,n)=>{t.setDate(t.getDate()+n*7)},(t,n)=>(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Sn)/Rf)}const _s=lo(0),rl=lo(1),w$=lo(2),x$=lo(3),Ko=lo(4),v$=lo(5),k$=lo(6);_s.range;rl.range;w$.range;x$.range;Ko.range;v$.range;k$.range;function co(e){return Ct(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCDate(t.getUTCDate()+n*7)},(t,n)=>(n-t)/Rf)}const Im=co(0),ol=co(1),S$=co(2),$$=co(3),Yo=co(4),_$=co(5),M$=co(6);Im.range;ol.range;S$.range;$$.range;Yo.range;_$.range;M$.range;const Bl=Ct(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+(t.getFullYear()-e.getFullYear())*12,e=>e.getMonth());Bl.range;const E$=Ct(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+(t.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());E$.range;const Gn=Ct(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());Gn.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Ct(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)});Gn.range;const ro=Ct(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());ro.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Ct(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)});ro.range;function A$(e,t,n,r,o,i){const s=[[Oo,1,lr],[Oo,5,5*lr],[Oo,15,15*lr],[Oo,30,30*lr],[i,1,Sn],[i,5,5*Sn],[i,15,15*Sn],[i,30,30*Sn],[o,1,cr],[o,3,3*cr],[o,6,6*cr],[o,12,12*cr],[r,1,vr],[r,2,2*vr],[n,1,Rf],[t,1,np],[t,3,3*np],[e,1,Lc]];function a(u,c,d){const f=c<u;f&&([u,c]=[c,u]);const p=d&&typeof d.range=="function"?d:l(u,c,d),h=p?p.range(u,+c+1):[];return f?h.reverse():h}function l(u,c,d){const f=Math.abs(c-u)/d,p=gf(([,,g])=>g).right(s,f);if(p===s.length)return e.every(uu(u/Lc,c/Lc,d));if(p===0)return nl.every(Math.max(uu(u,c,d),1));const[h,y]=s[f/s[p-1][2]<s[p][2]/f?p-1:p];return h.every(y)}return[a,l]}const[T$,O$]=A$(Gn,Bl,_s,ri,ql,Wl);function Fc(e){if(0<=e.y&&e.y<100){var t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return t.setFullYear(e.y),t}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function Rc(e){if(0<=e.y&&e.y<100){var t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return t.setUTCFullYear(e.y),t}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function di(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}function C$(e){var t=e.dateTime,n=e.date,r=e.time,o=e.periods,i=e.days,s=e.shortDays,a=e.months,l=e.shortMonths,u=hi(o),c=pi(o),d=hi(i),f=pi(i),p=hi(s),h=pi(s),y=hi(a),g=pi(a),m=hi(l),b=pi(l),w={a:D,A:z,b:j,B:G,c:null,d:lp,e:lp,f:e_,g:u_,G:d_,H:J$,I:Z$,j:Q$,L:Lm,m:t_,M:n_,p:J,q:re,Q:fp,s:dp,S:r_,u:o_,U:i_,V:s_,w:a_,W:l_,x:null,X:null,y:c_,Y:f_,Z:h_,"%":up},x={a:Q,A:ve,b:Ce,B:le,c:null,d:cp,e:cp,f:m_,g:E_,G:T_,H:p_,I:y_,j:g_,L:Rm,m:b_,M:w_,p:me,q:ce,Q:fp,s:dp,S:x_,u:v_,U:k_,V:S_,w:$_,W:__,x:null,X:null,y:M_,Y:A_,Z:O_,"%":up},S={a:L,A:N,b:I,B:O,c:M,d:sp,e:sp,f:Y$,g:ip,G:op,H:ap,I:ap,j:B$,L:K$,m:q$,M:H$,p:T,q:W$,Q:V$,s:X$,S:U$,u:R$,U:P$,V:z$,w:F$,W:D$,x:$,X:F,y:ip,Y:op,Z:j$,"%":G$};w.x=v(n,w),w.X=v(r,w),w.c=v(t,w),x.x=v(n,x),x.X=v(r,x),x.c=v(t,x);function v(Y,fe){return function(ie){var U=[],we=-1,xe=0,P=Y.length,H,oe,he;for(ie instanceof Date||(ie=new Date(+ie));++we<P;)Y.charCodeAt(we)===37&&(U.push(Y.slice(xe,we)),(oe=rp[H=Y.charAt(++we)])!=null?H=Y.charAt(++we):oe=H==="e"?" ":"0",(he=fe[H])&&(H=he(ie,oe)),U.push(H),xe=we+1);return U.push(Y.slice(xe,we)),U.join("")}}function k(Y,fe){return function(ie){var U=di(1900,void 0,1),we=_(U,Y,ie+="",0),xe,P;if(we!=ie.length)return null;if("Q"in U)return new Date(U.Q);if("s"in U)return new Date(U.s*1e3+("L"in U?U.L:0));if(fe&&!("Z"in U)&&(U.Z=0),"p"in U&&(U.H=U.H%12+U.p*12),U.m===void 0&&(U.m="q"in U?U.q:0),"V"in U){if(U.V<1||U.V>53)return null;"w"in U||(U.w=1),"Z"in U?(xe=Rc(di(U.y,0,1)),P=xe.getUTCDay(),xe=P>4||P===0?ol.ceil(xe):ol(xe),xe=Pf.offset(xe,(U.V-1)*7),U.y=xe.getUTCFullYear(),U.m=xe.getUTCMonth(),U.d=xe.getUTCDate()+(U.w+6)%7):(xe=Fc(di(U.y,0,1)),P=xe.getDay(),xe=P>4||P===0?rl.ceil(xe):rl(xe),xe=ri.offset(xe,(U.V-1)*7),U.y=xe.getFullYear(),U.m=xe.getMonth(),U.d=xe.getDate()+(U.w+6)%7)}else("W"in U||"U"in U)&&("w"in U||(U.w="u"in U?U.u%7:"W"in U?1:0),P="Z"in U?Rc(di(U.y,0,1)).getUTCDay():Fc(di(U.y,0,1)).getDay(),U.m=0,U.d="W"in U?(U.w+6)%7+U.W*7-(P+5)%7:U.w+U.U*7-(P+6)%7);return"Z"in U?(U.H+=U.Z/100|0,U.M+=U.Z%100,Rc(U)):Fc(U)}}function _(Y,fe,ie,U){for(var we=0,xe=fe.length,P=ie.length,H,oe;we<xe;){if(U>=P)return-1;if(H=fe.charCodeAt(we++),H===37){if(H=fe.charAt(we++),oe=S[H in rp?fe.charAt(we++):H],!oe||(U=oe(Y,ie,U))<0)return-1}else if(H!=ie.charCodeAt(U++))return-1}return U}function T(Y,fe,ie){var U=u.exec(fe.slice(ie));return U?(Y.p=c.get(U[0].toLowerCase()),ie+U[0].length):-1}function L(Y,fe,ie){var U=p.exec(fe.slice(ie));return U?(Y.w=h.get(U[0].toLowerCase()),ie+U[0].length):-1}function N(Y,fe,ie){var U=d.exec(fe.slice(ie));return U?(Y.w=f.get(U[0].toLowerCase()),ie+U[0].length):-1}function I(Y,fe,ie){var U=m.exec(fe.slice(ie));return U?(Y.m=b.get(U[0].toLowerCase()),ie+U[0].length):-1}function O(Y,fe,ie){var U=y.exec(fe.slice(ie));return U?(Y.m=g.get(U[0].toLowerCase()),ie+U[0].length):-1}function M(Y,fe,ie){return _(Y,t,fe,ie)}function $(Y,fe,ie){return _(Y,n,fe,ie)}function F(Y,fe,ie){return _(Y,r,fe,ie)}function D(Y){return s[Y.getDay()]}function z(Y){return i[Y.getDay()]}function j(Y){return l[Y.getMonth()]}function G(Y){return a[Y.getMonth()]}function J(Y){return o[+(Y.getHours()>=12)]}function re(Y){return 1+~~(Y.getMonth()/3)}function Q(Y){return s[Y.getUTCDay()]}function ve(Y){return i[Y.getUTCDay()]}function Ce(Y){return l[Y.getUTCMonth()]}function le(Y){return a[Y.getUTCMonth()]}function me(Y){return o[+(Y.getUTCHours()>=12)]}function ce(Y){return 1+~~(Y.getUTCMonth()/3)}return{format:function(Y){var fe=v(Y+="",w);return fe.toString=function(){return Y},fe},parse:function(Y){var fe=k(Y+="",!1);return fe.toString=function(){return Y},fe},utcFormat:function(Y){var fe=v(Y+="",x);return fe.toString=function(){return Y},fe},utcParse:function(Y){var fe=k(Y+="",!0);return fe.toString=function(){return Y},fe}}}var rp={"-":"",_:" ",0:"0"},Ft=/^\s*\d+/,N$=/^%/,I$=/[\\^$*+?|[\]().{}]/g;function et(e,t,n){var r=e<0?"-":"",o=(r?-e:e)+"",i=o.length;return r+(i<n?new Array(n-i+1).join(t)+o:o)}function L$(e){return e.replace(I$,"\\$&")}function hi(e){return new RegExp("^(?:"+e.map(L$).join("|")+")","i")}function pi(e){return new Map(e.map((t,n)=>[t.toLowerCase(),n]))}function F$(e,t,n){var r=Ft.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function R$(e,t,n){var r=Ft.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function P$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function z$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function D$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function op(e,t,n){var r=Ft.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function ip(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function j$(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function W$(e,t,n){var r=Ft.exec(t.slice(n,n+1));return r?(e.q=r[0]*3-3,n+r[0].length):-1}function q$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function sp(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function B$(e,t,n){var r=Ft.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function ap(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function H$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function U$(e,t,n){var r=Ft.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function K$(e,t,n){var r=Ft.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function Y$(e,t,n){var r=Ft.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function G$(e,t,n){var r=N$.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function V$(e,t,n){var r=Ft.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function X$(e,t,n){var r=Ft.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function lp(e,t){return et(e.getDate(),t,2)}function J$(e,t){return et(e.getHours(),t,2)}function Z$(e,t){return et(e.getHours()%12||12,t,2)}function Q$(e,t){return et(1+ri.count(Gn(e),e),t,3)}function Lm(e,t){return et(e.getMilliseconds(),t,3)}function e_(e,t){return Lm(e,t)+"000"}function t_(e,t){return et(e.getMonth()+1,t,2)}function n_(e,t){return et(e.getMinutes(),t,2)}function r_(e,t){return et(e.getSeconds(),t,2)}function o_(e){var t=e.getDay();return t===0?7:t}function i_(e,t){return et(_s.count(Gn(e)-1,e),t,2)}function Fm(e){var t=e.getDay();return t>=4||t===0?Ko(e):Ko.ceil(e)}function s_(e,t){return e=Fm(e),et(Ko.count(Gn(e),e)+(Gn(e).getDay()===4),t,2)}function a_(e){return e.getDay()}function l_(e,t){return et(rl.count(Gn(e)-1,e),t,2)}function c_(e,t){return et(e.getFullYear()%100,t,2)}function u_(e,t){return e=Fm(e),et(e.getFullYear()%100,t,2)}function f_(e,t){return et(e.getFullYear()%1e4,t,4)}function d_(e,t){var n=e.getDay();return e=n>=4||n===0?Ko(e):Ko.ceil(e),et(e.getFullYear()%1e4,t,4)}function h_(e){var t=e.getTimezoneOffset();return(t>0?"-":(t*=-1,"+"))+et(t/60|0,"0",2)+et(t%60,"0",2)}function cp(e,t){return et(e.getUTCDate(),t,2)}function p_(e,t){return et(e.getUTCHours(),t,2)}function y_(e,t){return et(e.getUTCHours()%12||12,t,2)}function g_(e,t){return et(1+Pf.count(ro(e),e),t,3)}function Rm(e,t){return et(e.getUTCMilliseconds(),t,3)}function m_(e,t){return Rm(e,t)+"000"}function b_(e,t){return et(e.getUTCMonth()+1,t,2)}function w_(e,t){return et(e.getUTCMinutes(),t,2)}function x_(e,t){return et(e.getUTCSeconds(),t,2)}function v_(e){var t=e.getUTCDay();return t===0?7:t}function k_(e,t){return et(Im.count(ro(e)-1,e),t,2)}function Pm(e){var t=e.getUTCDay();return t>=4||t===0?Yo(e):Yo.ceil(e)}function S_(e,t){return e=Pm(e),et(Yo.count(ro(e),e)+(ro(e).getUTCDay()===4),t,2)}function $_(e){return e.getUTCDay()}function __(e,t){return et(ol.count(ro(e)-1,e),t,2)}function M_(e,t){return et(e.getUTCFullYear()%100,t,2)}function E_(e,t){return e=Pm(e),et(e.getUTCFullYear()%100,t,2)}function A_(e,t){return et(e.getUTCFullYear()%1e4,t,4)}function T_(e,t){var n=e.getUTCDay();return e=n>=4||n===0?Yo(e):Yo.ceil(e),et(e.getUTCFullYear()%1e4,t,4)}function O_(){return"+0000"}function up(){return"%"}function fp(e){return+e}function dp(e){return Math.floor(+e/1e3)}var So,zf;C_({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function C_(e){return So=C$(e),zf=So.format,So.parse,So.utcFormat,So.utcParse,So}function N_(e){return new Date(e)}function I_(e){return e instanceof Date?+e:+new Date(+e)}function zm(e,t,n,r,o,i,s,a,l,u){var c=Am(),d=c.invert,f=c.domain,p=u(".%L"),h=u(":%S"),y=u("%I:%M"),g=u("%I %p"),m=u("%a %d"),b=u("%b %d"),w=u("%B"),x=u("%Y");function S(v){return(l(v)<v?p:a(v)<v?h:s(v)<v?y:i(v)<v?g:r(v)<v?o(v)<v?m:b:n(v)<v?w:x)(v)}return c.invert=function(v){return new Date(d(v))},c.domain=function(v){return arguments.length?f(Array.from(v,I_)):f().map(N_)},c.ticks=function(v){var k=f();return e(k[0],k[k.length-1],v??10)},c.tickFormat=function(v,k){return k==null?S:u(k)},c.nice=function(v){var k=f();return(!v||typeof v.range!="function")&&(v=t(k[0],k[k.length-1],v??10)),v?f(Tm(k,v)):c},c.copy=function(){return $s(c,zm(e,t,n,r,o,i,s,a,l,u))},c}function L_(){return ao.apply(zm(T$,O$,Gn,Bl,_s,ri,ql,Wl,Oo,zf).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function ft(e){for(var t=e.length/6|0,n=new Array(t),r=0;r<t;)n[r]="#"+e.slice(r*6,++r*6);return n}const F_=ft("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),R_=ft("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),P_=ft("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),z_=ft("4269d0efb118ff725c6cc5b03ca951ff8ab7a463f297bbf59c6b4e9498a0"),D_=ft("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),j_=ft("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),W_=ft("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),q_=ft("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),B_=ft("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),H_=ft("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),U_=ft("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab"),En=e=>mk(e[e.length-1]);var Dm=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(ft);const K_=En(Dm);var jm=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(ft);const Y_=En(jm);var Wm=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(ft);const G_=En(Wm);var qm=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(ft);const V_=En(qm);var Bm=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(ft);const X_=En(Bm);var Hm=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(ft);const J_=En(Hm);var Um=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(ft);const Z_=En(Um);var Km=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(ft);const Q_=En(Km);var Ym=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(ft);const eM=En(Ym);var Gm=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(ft);const tM=En(Gm);var Vm=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(ft);const nM=En(Vm);var Xm=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(ft);const rM=En(Xm);function oM(e){return e=Math.max(0,Math.min(1,e)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-e*(35.34-e*(2381.73-e*(6402.7-e*(7024.72-e*2710.57)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+e*(170.73+e*(52.82-e*(131.46-e*(176.58-e*67.37)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+e*(442.36-e*(2482.43-e*(6167.24-e*(6614.94-e*2475.67)))))))+")"}var iM=Rg(Tr(-100,.75,.35),Tr(80,1.5,.8)),sM=Rg(Tr(260,.75,.35),Tr(80,1.5,.8));Tr();function aM(e){return e=Math.max(0,Math.min(1,e)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+e*(1172.33-e*(10793.56-e*(33300.12-e*(38394.49-e*14825.05)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+e*(557.33+e*(1225.33-e*(3574.96-e*(1073.77+e*707.56)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+e*(3211.1-e*(15327.97-e*(27814-e*(22569.18-e*6838.66)))))))+")"}function Hl(e){var t=e.length;return function(n){return e[Math.max(0,Math.min(t-1,Math.floor(n*t)))]}}const lM=Hl(ft("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var cM=Hl(ft("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),uM=Hl(ft("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),fM=Hl(ft("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));function $o(e){return function(){return e}}const hp=1e-12;function dM(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);t=r}return e},()=>new H2(t)}function hM(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Jm(e){this._context=e}Jm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function Df(e){return new Jm(e)}function pM(e){return e[0]}function yM(e){return e[1]}function _i(e,t){var n=$o(!0),r=null,o=Df,i=null,s=dM(a);e=typeof e=="function"?e:e===void 0?pM:$o(e),t=typeof t=="function"?t:t===void 0?yM:$o(t);function a(l){var u,c=(l=hM(l)).length,d,f=!1,p;for(r==null&&(i=o(p=s())),u=0;u<=c;++u)!(u<c&&n(d=l[u],u,l))===f&&((f=!f)?i.lineStart():i.lineEnd()),f&&i.point(+e(d,u,l),+t(d,u,l));if(p)return i=null,p+""||null}return a.x=function(l){return arguments.length?(e=typeof l=="function"?l:$o(+l),a):e},a.y=function(l){return arguments.length?(t=typeof l=="function"?l:$o(+l),a):t},a.defined=function(l){return arguments.length?(n=typeof l=="function"?l:$o(!!l),a):n},a.curve=function(l){return arguments.length?(o=l,r!=null&&(i=o(r)),a):o},a.context=function(l){return arguments.length?(l==null?r=i=null:i=o(r=l),a):r},a}function pp(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function Zm(e){this._context=e}Zm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:pp(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:pp(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function gM(e){return new Zm(e)}function yp(e,t,n){e._context.bezierCurveTo(e._x1+e._k*(e._x2-e._x0),e._y1+e._k*(e._y2-e._y0),e._x2+e._k*(e._x1-t),e._y2+e._k*(e._y1-n),e._x2,e._y2)}function jf(e,t){this._context=e,this._k=(1-t)/6}jf.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:yp(this,this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2,this._x1=e,this._y1=t;break;case 2:this._point=3;default:yp(this,e,t);break}this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const mM=(function e(t){function n(r){return new jf(r,t)}return n.tension=function(r){return e(+r)},n})(0);function bM(e,t,n){var r=e._x1,o=e._y1,i=e._x2,s=e._y2;if(e._l01_a>hp){var a=2*e._l01_2a+3*e._l01_a*e._l12_a+e._l12_2a,l=3*e._l01_a*(e._l01_a+e._l12_a);r=(r*a-e._x0*e._l12_2a+e._x2*e._l01_2a)/l,o=(o*a-e._y0*e._l12_2a+e._y2*e._l01_2a)/l}if(e._l23_a>hp){var u=2*e._l23_2a+3*e._l23_a*e._l12_a+e._l12_2a,c=3*e._l23_a*(e._l23_a+e._l12_a);i=(i*u+e._x1*e._l23_2a-t*e._l12_2a)/c,s=(s*u+e._y1*e._l23_2a-n*e._l12_2a)/c}e._context.bezierCurveTo(r,o,i,s,e._x2,e._y2)}function Qm(e,t){this._context=e,this._alpha=t}Qm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){if(e=+e,t=+t,this._point){var n=this._x2-e,r=this._y2-t;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3;default:bM(this,e,t);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const wM=(function e(t){function n(r){return t?new Qm(r,t):new jf(r,0)}return n.alpha=function(r){return e(+r)},n})(.5);function gp(e){return e<0?-1:1}function mp(e,t,n){var r=e._x1-e._x0,o=t-e._x1,i=(e._y1-e._y0)/(r||o<0&&-0),s=(n-e._y1)/(o||r<0&&-0),a=(i*o+s*r)/(r+o);return(gp(i)+gp(s))*Math.min(Math.abs(i),Math.abs(s),.5*Math.abs(a))||0}function bp(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function Pc(e,t,n){var r=e._x0,o=e._y0,i=e._x1,s=e._y1,a=(i-r)/3;e._context.bezierCurveTo(r+a,o+a*t,i-a,s-a*n,i,s)}function il(e){this._context=e}il.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Pc(this,this._t0,bp(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,Pc(this,bp(this,n=mp(this,e,t)),n);break;default:Pc(this,this._t0,n=mp(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function e0(e){this._context=new t0(e)}(e0.prototype=Object.create(il.prototype)).point=function(e,t){il.prototype.point.call(this,t,e)};function t0(e){this._context=e}t0.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,o,i){this._context.bezierCurveTo(t,e,r,n,i,o)}};function xM(e){return new il(e)}function vM(e){return new e0(e)}function n0(e){this._context=e}n0.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=wp(e),o=wp(t),i=0,s=1;s<n;++i,++s)this._context.bezierCurveTo(r[0][i],o[0][i],r[1][i],o[1][i],e[s],t[s]);(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function wp(e){var t,n=e.length-1,r,o=new Array(n),i=new Array(n),s=new Array(n);for(o[0]=0,i[0]=2,s[0]=e[0]+2*e[1],t=1;t<n-1;++t)o[t]=1,i[t]=4,s[t]=4*e[t]+2*e[t+1];for(o[n-1]=2,i[n-1]=7,s[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=o[t]/i[t-1],i[t]-=r,s[t]-=r*s[t-1];for(o[n-1]=s[n-1]/i[n-1],t=n-2;t>=0;--t)o[t]=(s[t]-o[t+1])/i[t];for(i[n-1]=(e[n]+o[n-1])/2,t=0;t<n-1;++t)i[t]=2*e[t+1]-o[t+1];return[o,i]}function kM(e){return new n0(e)}function Ul(e,t){this._context=e,this._t=t}Ul.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}}this._x=e,this._y=t}};function SM(e){return new Ul(e,.5)}function $M(e){return new Ul(e,0)}function _M(e){return new Ul(e,1)}function Mi(e,t,n){this.k=e,this.x=t,this.y=n}Mi.prototype={constructor:Mi,scale:function(e){return e===1?this:new Mi(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Mi(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};Mi.prototype;function uo(e,t){return t==null?e:`${e}\0${t}`}function r0(e){return e instanceof Date?e:new Date(e)}function MM(e){return typeof e.bandwidth=="function"?typeof e.paddingInner=="function"?"band":"point":typeof e.invert=="function"?"continuous":"discrete"}function o0(e,t){e.type=t,e.kind=MM(e);const n=typeof e.domain=="function"?e.domain():[];return e.temporal=n.some(r=>r instanceof Date),e.domainConfig=n,e.invertible=e.kind==="band"||e.kind==="point"||typeof e.invert=="function",e.ramp=e.ramp===!0||typeof e.interpolator=="function",e.encode=(r,o)=>Mr(e,r,o),e.invertValue=e.invertible?r=>TM(e,r):()=>{},e}function EM(e,{range:t,positional:n,domain:r}={}){return r&&typeof e.domain=="function"&&!e.domain().length&&e.domain(r),t&&n&&typeof e.range=="function"&&e.range(t),o0(e)}function ju(e,t){if(!e)return null;const n=e.type||"linear";let r;if(n==="time")r=L_().domain(e.domain.map(r0)).range(t);else if(n==="band")r=Lf().domain(e.domain).range(t).padding(e.padding!=null?e.padding:.1);else if(n==="point")r=QS().domain(e.domain).range(t).padding(e.padding!=null?e.padding:.5);else if(n==="ordinal")r=If().domain(e.domain).range(t);else if(n==="sequential"){const[o,i]=[Math.min(...e.domain),Math.max(...e.domain)],s=ji().domain([o,i]).range([0,1]).clamp(!0),a=eo(t[0],t[1]);r=l=>a(s(l)),r.domain=()=>e.domain,r.range=()=>t,r.ramp=!0}else if(n==="diverging"){const[o,i]=[Math.min(...e.domain),Math.max(...e.domain)],s=e.pivot!=null?e.pivot:o<0&&i>0?0:(o+i)/2,a=ji().domain([o,s,i]).range([0,.5,1]).clamp(!0),l=t.length>=3?[t[0],t[1],t[t.length-1]]:[t[0],"#f7f7f7",t[t.length-1]],u=Pg(eo,l);r=c=>u(a(c)),r.domain=()=>e.domain,r.range=()=>t,r.ramp=!0,r.pivot=()=>s}else n==="log"?(r=Om().domain(e.domain).range(t),e.base!=null&&r.base(e.base)):n==="symlog"?(r=Cm().domain(e.domain).range(t),e.constant!=null&&r.constant(e.constant)):n==="pow"||n==="sqrt"?r=Nm().domain(e.domain).range(t).exponent(e.exponent!=null?e.exponent:n==="sqrt"?.5:1):r=ji().domain(e.domain).range(t);return e.nice&&typeof r.nice=="function"&&r.nice(),e.clamp&&typeof r.clamp=="function"&&r.clamp(!0),o0(r,n)}function AM({domain:e,localRange:t,origin:n=0,halfSize:r=1,family:o="plain"}){const i=o==="x"?l=>n+l*r:o==="y"?l=>n-l*r:o==="size"?l=>l*r:l=>l,s=e.some(l=>l instanceof Date)?"time":"linear",a=ju({type:s,domain:e},t.map(i));return a.frameExtent=Math.abs(r)||void 0,a}function Vn(e){return!!e&&e.kind==="band"}function fo(e){return!!e&&(e.kind==="band"||e.kind==="point")}function oo(e){const t=e.range();return[Math.min(t[0],t[1]),Math.max(t[0],t[1])]}function Mr(e,t,n){if(!e)return n;if(e.kind==="band"){const o=e(t);return o==null?n:o+e.bandwidth()/2}if(e.kind==="point"){const o=e(t);return o??n}if(e.temporal)return e(r0(t));if(t==null)return n;const r=e(t);return typeof r=="number"&&!Number.isFinite(r)?n:r}function yn(e,t){return e&&e.bandwidth?e.bandwidth():t}function Yr(e,t,n){if(!e)return n;if(e.kind==="band"||e.kind==="point"){const r=e(t);return r??n}return Mr(e,t,n)}function i0(e,t,n,{inset:r=0,length:o}={}){let i,s;if(Vn(e)){const a=e(t),l=e.bandwidth();i=a,s=a+l}else i=0,s=n;if(o!=null){const a=(i+s)/2;return[a-o/2,a+o/2]}return[i+r,s-r]}function TM(e,t){if(!e||!e.invertible)return;if(fo(e)){const s=e.domain();if(!s.length)return;const a=e.kind==="band"?e.bandwidth()/2:0;let l=s[0],u=1/0;for(const c of s){const d=e(c)+a,f=Math.abs(d-t);f<u&&(u=f,l=c)}return l}const n=e.invert(t),r=e.domain();if(e.temporal){const s=Math.min(...r.map(Number)),a=Math.max(...r.map(Number));return new Date(Math.max(s,Math.min(a,Number(n))))}const o=Math.min(...r),i=Math.max(...r);return Math.max(o,Math.min(i,n))}function yr(e){const[t,n]=oo(e),r=e(0);return Math.max(t,Math.min(n,r))}const ls=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Ei=["#e6f0ff","#08519c"],Wu=["#2166ac","#f7f7f7","#b2182b"],s0=["●","■","▲","◆","★","✚","▼","◀","▶","⬟"],xp={faces:["😞","😐","🙂"],faces5:["😢","🙁","😐","🙂","😄"],hearts:["🖤","💛","❤️"],weather:["☀️","⛅","☁️","🌧️","⛈️"],arrows:["⬇️","↘️","➡️","↗️","⬆️"],shapes:s0},vp={category10:F_,tableau10:U_,observable10:z_,accent:R_,dark2:P_,paired:D_,pastel1:j_,pastel2:W_,set1:q_,set2:B_,set3:H_},OM={rdbu:G_,rdylbu:V_,rdylgn:X_,brbg:K_,piyg:Y_,spectral:J_,blues:Z_,greens:Q_,greys:eM,oranges:rM,purples:tM,reds:nM,viridis:lM,magma:cM,inferno:uM,plasma:fM,cividis:oM,turbo:aM,warm:iM,cool:sM},CM={rdbu:Wm,rdylbu:qm,rdylgn:Bm,brbg:Dm,piyg:jm,spectral:Hm,blues:Um,greens:Km,greys:Ym,oranges:Xm,purples:Gm,reds:Vm};function Ai(e,t,n){if(!e||typeof e!="string")return null;const r=e.toLowerCase();if(xp[r])return[...xp[r]];if(vp[r])return[...vp[r]];const o=OM[r];if(!o)return null;if(t==="diverging")return[o(0),o(.5),o(1)];if(t==="sequential")return[o(0),o(1)];const i=Math.max(2,n||2),s=CM[r];if(s){const a=Math.max(3,Math.min(11,i)),l=s[a];if(l)return[...l]}return zg(o,i)}const a0=new Set(["fill","stroke"]),NM=new Set(["opacity","fillOpacity","strokeOpacity"]),l0=new Set(["symbol"]),IM={x:"x",x1:"x",x2:"x",y:"y",y1:"y",y2:"y",theta:"theta",theta2:"theta",count:"count"};function $t(e){return IM[e]}function Gr(e){if(!e)return null;const t=e.scale;return t==="frame"?{}:t&&typeof t=="object"&&t.type==="frame"?t:null}function LM(e){if(!e||typeof e!="object"||e.frame===void 0)return e;const{frame:t,...n}=e;return n.scale!==void 0?n:Array.isArray(t)?{...n,scale:{type:"frame",range:t}}:typeof t=="number"?{...n,datum:t,scale:"frame"}:{...n,scale:"frame"}}const FM=new Set(["size","rx","ry","strokeWidth"]);function Wf(e){const t=$t(e);return t==="x"||t==="y"?t:FM.has(e)?"size":"plain"}function RM(e){const t=Wf(e);return t==="x"||t==="y"?[-1,1]:t==="size"?[0,1]:null}function qf(e){const t=e.find(n=>n!=null);return t instanceof Date?"temporal":typeof t=="number"||t===void 0?"quantitative":"categorical"}function PM(e,t,n="band"){const r=t==="quantitative"||t==="temporal";return a0.has(e)?r?"sequential":"ordinal":l0.has(e)?"ordinal":t==="temporal"?"time":t==="quantitative"?"linear":n}function c0(e,t){if(e==="band"||e==="point"||e==="ordinal")return[...new Set(t.filter(r=>r!=null))];const n=t.filter(r=>r!=null);return n.length?[Math.min(...n),Math.max(...n)]:[0,1]}function zM(e,t){if(t.length){if(t.length===1)return t[0];if(e==="quantitative"||e==="temporal"){const n=t.map(s=>Math.min(...s.map(Number))),r=t.map(s=>Math.max(...s.map(Number))),[o,i]=[Math.min(...n),Math.max(...r)];return e==="temporal"?[new Date(o),new Date(i)]:[o,i]}return[...new Set(t.flat())]}}const DM=["tableau10","dark2","set2","accent","paired","set3"],kp=["blues","oranges","greens","purples","greys"];function Sp(e,t){if(t<=1)return[e[e.length-1]];const n=Pg(eo,e);return zg(n,t)}function jM(e,t,n={}){const{measure:r,index:o=0,count:i=2}=n,s=a=>a[o%a.length];return e==="diverging"?o===0?t&&t.diverging||Wu:Ai(s(["rdbu","brbg","piyg","rdylgn"]),"diverging",i)||Wu:e==="sequential"?o===0?t&&t.ramp||Ei:Ai(s(kp),"sequential",i)||Ei:r==="ordinal"?o===0?Sp(t&&t.ramp||Ei,Math.max(2,i)):Ai(s(kp),"ordinal",i)||Sp(Ei,Math.max(2,i)):o===0?t&&t.palette||ls:Ai(s(DM),"ordinal",i)||ls}function u0(e,t,n,r,o={}){switch(e){case"x":return[0,n.width];case"y":return[n.height,0];case"size":return[3,18];case"rx":return[3,18];case"ry":return[3,18];case"curvature":return[-1,1];case"theta":return[180,0];case"angle":return[180,0];case"count":return o.countAxis==="x"?[0,n.width]:[n.height,0]}return NM.has(e)?[.15,1]:a0.has(e)?jM(t,r,o):l0.has(e)?[...s0]:e==="strokeWidth"?[1,8]:[0,1]}function WM(e){return e.channels||{}}function Bf(e,t){return Math.atan2(-(e.y-t.cy),e.x-t.cx)*180/Math.PI}function qM(e,t,n){const r=Math.min(t,n),o=Math.max(t,n),i=(r+o)/2,s=i+((e-i)%360+540)%360-180;return Math.max(r,Math.min(o,s))}function BM(e,t,n){const r=$t(e);if(r==="x")return t.x;if(r==="y")return t.y;if(e==="size")return n?Math.hypot(t.x-n.cx,t.y-n.cy):void 0;if(e==="theta"||e==="angle")return n?Bf(t,n):void 0}function HM(e,t,n=null){const r=$t(e);if(r==="x")return{x:t,y:n?n.cy:0};if(r==="y")return{x:n?n.cx:0,y:t};if(n){if(e==="size")return{x:n.cx+t,y:n.cy};if(e==="theta"||e==="angle"){const o=t*Math.PI/180,i=100;return{x:n.cx+i*Math.cos(o),y:n.cy-i*Math.sin(o)}}}}var UM={};function KM(){try{const e=typeof process<"u"&&UM&&"production";if(e)return e!=="production"}catch{}return!0}let Hf=KM();const qu=new Set;function YM(e){Hf=!!e,qu.clear()}function oi(){return Hf}function ge(e,t){!Hf||qu.has(e)||(qu.add(e),console.warn(`[elicit] ${t}`))}const f0=200,Bu={table:{roles:["data"],primary:"data"},network:{roles:["nodes","links"],primary:"nodes"}},d0="table",zc="fields";function GM(e){return!e||typeof e!="object"||Array.isArray(e)?!1:typeof e.type=="string"||"domain"in e||"default"in e||"key"in e||"open"in e}const Uf=["directed","multi","selfLoops"],VM=["role","fields",...Uf];function XM(e){return!e||typeof e!="object"?!1:typeof e.role=="string"?!0:!e.fields||typeof e.fields!="object"?!1:Object.keys(e).every(t=>VM.includes(t))}function $p(e,t){const n=Object.keys(e).filter(r=>e[r]&&e[r].key===!0);if(n.length>1)throw new Error(`[elicit] table "${t}" declares more than one \`key: true\` field (${n.map(r=>`"${r}"`).join(", ")}). A table has at most one key — it is the identity a \`ref\` points at.`);return n.length?n[0]:null}function h0(e){const t={};for(const n of Uf)typeof e[n]=="boolean"&&(t[n]=e[n]);return t}function JM(e,t){if(!t||typeof t!="object")throw new Error(`[elicit] schema.tables.${e} must be a field map, or { role, fields }. Got ${t===null?"null":typeof t}.`);if(XM(t)){if(typeof t.role!="string"&&GM(t.fields))throw new Error(`[elicit] table "${e}" is ambiguous: \`fields\` is its only key and its value looks like a single FieldSchema, so this reads equally as the long form or as a one-column table whose column is called "fields". Say which: ${e}: { fields: { fields: … } } for the column, or add \`role\` for the long form.`);const n=t.fields||{};return{name:e,role:t.role||e,fields:n,key:$p(n,e),...h0(t)}}if(Object.prototype.hasOwnProperty.call(t,zc))throw new Error(`[elicit] table "${e}" declares a column named "${zc}", which is reserved in this short form — it is how a table entry says "here are my columns". Use the long form to keep the column: ${e}: { fields: { ${zc}: … } }.`);return{name:e,role:e,fields:t,key:$p(t,e)}}function ZM(e){const t=e&&typeof e=="object"?e:{},n=typeof t.structure=="string",r=n?t.structure:d0,o=Bu[r];if(!o)throw new Error(`[elicit] unknown schema structure "${r}". Known structures: ${Object.keys(Bu).map(u=>`"${u}"`).join(", ")}.`);let i;if(!n)i={[o.primary]:t};else if(t.tables&&typeof t.tables=="object")i=t.tables;else throw t.fields&&typeof t.fields=="object"?new Error(`[elicit] schema declares \`fields\` at the top level. Columns belong to a named TABLE: schema: { structure: "${r}", tables: { ${o.primary}: { … } } }.`):new Error(`[elicit] schema declares structure "${r}" but no \`tables\`. A structure is a set of named tables: tables: { ${o.roles.map(u=>`${u}: { … }`).join(", ")} }.`);const s={},a={};for(const[u,c]of Object.entries(i)){const d=JM(u,c);if(!o.roles.includes(d.role))throw new Error(`[elicit] table "${u}" claims role "${d.role}", which structure "${r}" does not define. Its roles are ${o.roles.map(f=>`"${f}"`).join(", ")}.`);if(a[d.role])throw new Error(`[elicit] tables "${a[d.role]}" and "${u}" both claim role "${d.role}". Each role is filled by exactly one table.`);a[d.role]=u,s[u]=d}const l=o.roles.filter(u=>!a[u]);if(l.length)throw new Error(`[elicit] structure "${r}" needs a table for ${l.map(u=>`"${u}"`).join(", ")}, but the schema declares none. The schema is the contract of the elicited dataset, and a table built entirely by gesture has no rows to infer one from — declare it, even empty.`);for(const[u,c]of Object.entries(s))if(c.role!=="links")for(const d of Uf)c[d]!==void 0&&ge(`schema:${d}:${u}`,`table "${u}" declares \`${d}\`, but that describes the pairs of \`ref\` columns in a links table, and this table fills the "${c.role}" role. Move it to the table filling the "links" role, or drop it.`);return{structure:r,tables:s,byRole:a,primary:a[o.primary]}}function Ms(e){const t=e&&e.byRole&&e.byRole.links,n=t?e.tables[t]:null;return n?n.directed:void 0}function sl(e){const t=e&&e.byRole&&e.byRole.links,n=t?e.tables[t]:null;return{multi:!!(n&&n.multi),selfLoops:!!(n&&n.selfLoops)}}function xa(e){const t=Bu[e.structure],n=Object.keys(e.tables);return e.structure===d0&&n.length===1&&n[0]===t.primary}function QM(e){if(xa(e))return e.tables[e.primary].fields;const t={};for(const[n,r]of Object.entries(e.tables)){const o=h0(r),i=Object.keys(o).length?o:null;t[n]=r.role===n&&!i?r.fields:{...r.role===n?{}:{role:r.role},...i,fields:r.fields}}return{structure:e.structure,tables:t}}function Kf(e,t){const n=t&&typeof t.to=="string"?t.to:null,r=e.byRole.nodes||e.primary;if(n&&n.includes(".")){const s=n.indexOf("."),a=n.slice(0,s),l=n.slice(s+1);return e.tables[a]?{table:a,field:l}:null}const o=e.tables[r];if(!o)return null;const i=n||o.key;return i?{table:r,field:i}:null}function p0(e,t,n){const r=Kf(e,t);if(!r)return[];const o=e.tables[r.table].fields[r.field],i=[...o&&o.domain||[]];for(const s of n&&n[r.table]||[]){const a=s?s[r.field]:void 0;a!=null&&!i.includes(a)&&i.push(a)}return i}function Dc(e,t){const n=[];for(const[o,i]of Object.entries(e.tables))for(const[s,a]of Object.entries(i.fields)){if(!a||a.type!=="ref")continue;const l=Kf(e,a);l&&n.push({table:o,field:s,target:l})}if(!n.length)return!1;let r=!1;for(let o=0;o<=n.length;o++){let i=!1;for(const s of n){const a=t[s.table];if(!a||!a.length)continue;const l=new Set;for(const c of t[s.target.table]||[]){const d=c?c[s.target.field]:void 0;d!=null&&l.add(d)}const u=a.filter(c=>{const d=c?c[s.field]:void 0;return d==null||l.has(d)});u.length!==a.length&&(t[s.table]=u,i=!0,r=!0)}if(!i)break}return r}function _p(e,t){const n={};for(const r of Object.keys(t.tables))n[r]=[];if(e==null)return n;if(Array.isArray(e))return n[t.primary]=e,n;if(typeof e!="object")throw new Error(`[elicit] data must be an array of rows, or an object keyed by table name (${Object.keys(t.tables).map(r=>`"${r}"`).join(", ")}). Got ${typeof e}.`);for(const[r,o]of Object.entries(e)){if(!n[r]){ge(`data:table:${r}`,`data has a table "${r}" that the schema does not declare. The schema is the contract of the elicited dataset, so every table belongs in it; these rows are ignored. Declared tables: ${Object.keys(t.tables).map(i=>`"${i}"`).join(", ")}.`);continue}if(!Array.isArray(o))throw new Error(`[elicit] data.${r} must be an array of rows. Got ${o===null?"null":typeof o}.`);n[r]=o}return n}function Es(e){const t={};if(!e)return t;for(const[n,r]of Object.entries(e))t[n]=r&&r.default!==void 0?r.default:null;return t}function y0(e){const t=e||[];return t.some(n=>n instanceof Date)?"temporal":t.every(n=>typeof n=="number")?"quantitative":"categorical"}function g0(e){const t=new Set;for(const n of e.slice(0,f0))if(n&&typeof n=="object")for(const r of Object.keys(n))t.add(r);return[...t]}function al(e,t){const n=[];for(const r of e.slice(0,f0)){const o=r?r[t]:void 0;o!=null&&n.push(o)}return n}function e5(e){const t={};if(!Array.isArray(e)||!e.length)return t;for(const n of g0(e)){const r=al(e,n),o=qf(r),i=o==="categorical"||o==="ordinal";t[n]={type:o,domain:c0(i?"band":"linear",r),...i?{open:!0}:{}}}return t}function t5(e){return`schema: {
8
+ `,Hs=(e,t)=>JSON.stringify(e)===JSON.stringify(t),eh=e=>`${e.from}\0${e.to}`;function Us(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Sc(e,t){const n={};return(e.label??"")!==(t.label??"")&&(n.label=t.label??""),(e.tech??"")!==(t.tech??"")&&(n.tech=t.tech??""),!!e.async!=!!t.async&&(n.async=!!t.async),e.via!==t.via&&(n.via=t.via??null),e.planned!==t.planned&&(n.planned=t.planned??null),e.retiring!==t.retiring&&(n.retiring=t.retiring??null),Object.keys(n).length?{op:"arrow.set",from:t.from,to:t.to,...n}:null}function pg(e,t){const n=[],r=[],o={};for(const h of["title","goal","phase"])e[h]!==t[h]&&(t[h]!==void 0||h==="goal")&&(o[h]=t[h]??"");Object.keys(o).length&&n.push({op:"arch.set",...o}),t.rev!==e.rev&&r.push("rev (the server counts revisions)"),Hs(e.proposals??[],t.proposals??[])||r.push("proposals (accept or reject them instead)");const i=Object.keys(t.nodes).filter(h=>!(h in e.nodes)),s=Object.keys(e.nodes).filter(h=>!(h in t.nodes)),a=Object.keys(t.nodes).filter(h=>h in e.nodes);for(const h of i){const y=t.nodes[h];n.push(Us({op:"box.add",id:h,label:y.label,kind:y.kind,external:y.external,tech:y.tech,detail:y.detail,files:y.files,planned:y.planned,retiring:y.retiring}))}for(const h of a)e.nodes[h].in!==void 0&&e.nodes[h].in!==t.nodes[h].in&&n.push({op:"box.set",id:h,in:null});const l=new Map(e.edges.map(h=>[eh(h),h])),u=new Map(t.edges.map(h=>[eh(h),h])),c=[...l].filter(([h,y])=>!u.has(h)&&y.from in t.nodes&&y.to in t.nodes).map(([,h])=>h),d=[...u].filter(([h])=>!l.has(h)).map(([,h])=>h);for(const h of[...c]){const y=d.find(m=>m.from===h.to&&m.to===h.from);if(!y)continue;n.push({op:"arrow.reverse",from:h.from,to:h.to});const g=Sc({...h,from:y.from,to:y.to},y);g&&n.push(g),c.splice(c.indexOf(h),1),d.splice(d.indexOf(y),1)}for(const h of[...c]){const y=d.find(m=>m.from===h.from||m.to===h.to);if(!y)continue;n.push(Us({op:"arrow.rewire",from:h.from,to:h.to,newFrom:y.from!==h.from?y.from:void 0,newTo:y.to!==h.to?y.to:void 0}));const g=Sc({...h,from:y.from,to:y.to},y);g&&n.push(g),c.splice(c.indexOf(h),1),d.splice(d.indexOf(y),1)}for(const h of c)n.push({op:"arrow.remove",from:h.from,to:h.to});for(const h of s)n.push({op:"box.remove",id:h});for(const h of a){const y=e.nodes[h],g=t.nodes[h],m={};y.label!==g.label&&(m.label=g.label),y.kind!==g.kind&&(m.kind=g.kind),(y.tech??"")!==(g.tech??"")&&(m.tech=g.tech??""),(y.detail??"")!==(g.detail??"")&&(m.detail=g.detail??""),Hs(y.files??[],g.files??[])||(m.files=g.files??[]),!!y.external!=!!g.external&&(m.external=!!g.external),y.retiring!==g.retiring&&g.retiring===void 0&&(m.retiring=null),y.planned!==g.planned&&g.planned===void 0&&(m.planned=null),Object.keys(m).length&&n.push({op:"box.set",id:h,...m});const b={};y.planned!==g.planned&&g.planned!==void 0&&(b.planned=g.planned),y.retiring!==g.retiring&&g.retiring!==void 0&&(b.retiring=g.retiring),Object.keys(b).length&&n.push({op:"box.set",id:h,...b})}for(const h of[...a,...i]){const y=t.nodes[h].in,g=i.includes(h)?void 0:e.nodes[h].in;y!==void 0&&y!==g&&n.push({op:"box.set",id:h,in:y})}for(const h of d)n.push(Us({op:"arrow.add",from:h.from,to:h.to,label:h.label,tech:h.tech,async:h.async,via:h.via,planned:h.planned,retiring:h.retiring}));for(const[h,y]of u){const g=l.get(h),m=g&&Sc(g,y);m&&n.push(m)}const f=new Map(e.flows.map(h=>[h.id,h])),p=new Map(t.flows.map(h=>[h.id,h]));for(const[h,y]of p){const g=f.get(h),m=g?g.steps.filter(b=>!s.includes(b.from)&&!s.includes(b.to)):[];!g||!m.length?n.push({op:"flow.add",id:h,title:y.title,steps:y.steps}):(g.title!==y.title||!Hs(m,y.steps))&&n.push(Us({op:"flow.set",id:h,title:g.title!==y.title?y.title:void 0,steps:Hs(m,y.steps)?void 0:y.steps}))}for(const[h,y]of f)!p.has(h)&&y.steps.some(g=>!s.includes(g.from)&&!s.includes(g.to))&&n.push({op:"flow.remove",id:h});return{ops:n,ignored:r}}const Uw=e=>Object.keys(e.nodes).filter(t=>!Er(e,t));function au(e,t){const n=Uw(e),r={nodes:Object.fromEntries(n.map(a=>[a,e.nodes[a]])),edges:e.edges},o=Object.fromEntries(n.map(a=>[a,Ky(e,a).reverse()])),i=dg(r,t,{paths:o,loops:!0}),s=(t.collapsed??[]).filter(a=>Er(e,a));return{...i,layout:{...i.layout,...s.length?{collapsed:s}:{}}}}function th(e,t,n){const r={applies:!0,addedNodes:[],addedEdges:[],removedNodes:[],removedEdges:[],changedNodes:[]},o=Yy(e,n,{actor:"you",via:"editor"});if(o.kind!=="applied")return{...r,applies:!1,why:o.kind==="rejected"?o.why:"it is not a change you can apply"};const i=o.arch,{layout:s}=au(i,t);for(const[c,d]of Object.entries(i.nodes)){const f=e.nodes[c];if(!f){const h=s.nodes[c]??{x:0,y:0};r.addedNodes.push({id:c,label:d.label,kind:d.kind,x:h.x,y:h.y});continue}const p=[];f.label!==d.label&&p.push("label"),f.kind!==d.kind&&p.push("kind"),f.tech!==d.tech&&p.push("tech"),f.detail!==d.detail&&p.push("detail"),JSON.stringify(f.files)!==JSON.stringify(d.files)&&p.push("files"),f.in!==d.in&&p.push("place"),!!f.external!=!!d.external&&p.push("external"),(f.planned!==d.planned||f.retiring!==d.retiring)&&p.push("plan"),p.length&&r.changedNodes.push({id:c,...p.includes("label")?{label:d.label}:{},what:p})}for(const c of Object.keys(e.nodes))i.nodes[c]||r.removedNodes.push(c);const a=c=>`${c.from}\0${c.to}`,l=new Set(e.edges.map(a)),u=new Set(i.edges.map(a));for(const c of i.edges)l.has(a(c))||r.addedEdges.push(c.label?{from:c.from,to:c.to,label:c.label}:{from:c.from,to:c.to});for(const c of e.edges)!u.has(a(c))&&i.nodes[c.from]&&i.nodes[c.to]&&r.removedEdges.push({from:c.from,to:c.to});return r}const Jr=[],nh={id:"",title:"",plan:"",repo:"",source:"",direction:"LR",note:"",canvas:{width:640,height:360},steps:[],depends:[]},Tl=e=>Jr.find(t=>t.id===e)||Jr[0],Fi=e=>({steps:e.steps.map(t=>({...t})),depends:e.depends.map(t=>({...t}))}),Zi=[],yf=e=>Zi.find(t=>t.id===e)||Zi[0];function Kw(e){const t=o=>e()?.plan.nodes[o.id],n=o=>t(o)?.kind==="context"?"context":t(o)?.status??"not_started",r=o=>mi[n(o)];return{stroke:o=>r(o)?.edge?r(o).colour:void 0,strokeWidth:o=>r(o)?.edge?3:void 0,opacity:o=>n(o)==="context"?.55:1,look:o=>{const i=r(o),s=o.id;return{status:n(o),...i?{colour:i.colour,icon:i.icon,word:i.word,strike:i.strike}:{},review:s in(e()?.review??{}),atRisk:s in(e()?.derived.atRisk??{})}},owner:o=>N1(t(o)&&{status:"not_started",...t(o)},{stalled:e()?.derived.stalled?.[o.id]?.state,blockedOn:e()?.derived.blocked?.[o.id],held:e()?.derived.held?.[o.id]}),arrow:o=>(e()?.derived.gates??[]).some(i=>i.from===o.source&&i.to===o.target&&i.turn==="you")?"yours":"",frozen:(o,i)=>i==="depends"?n({id:o.target})==="done":n(o)==="done"}}class Yw{constructor(){this.children=[]}add(t){this.children.push(t)}clear(){this.children=[]}}const rh=e=>[e.hit?0:1,typeof e.index=="number"?e.index:-1];function oh(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n].glyph;if(!r){t.push(...e[n].nodes);continue}const o=[];let i=n;for(;i<e.length&&e[i].glyph===r;)o.push(...e[i].nodes),i++;n=i-1,o.sort((s,a)=>{const[l,u]=rh(s),[c,d]=rh(a);return l!==c?l-c:u-d}),t.push(...o)}return t.some(n=>n&&n.raise)?[...t.filter(n=>!(n&&n.raise)),...t.filter(n=>n&&n.raise)]:t}function ya(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Gw(e,t){return e==null||t==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function gf(e){let t,n,r;e.length!==2?(t=ya,n=(a,l)=>ya(e(a),l),r=(a,l)=>e(a)-l):(t=e===ya||e===Gw?e:Vw,n=e,r=e);function o(a,l,u=0,c=a.length){if(u<c){if(t(l,l)!==0)return c;do{const d=u+c>>>1;n(a[d],l)<0?u=d+1:c=d}while(u<c)}return u}function i(a,l,u=0,c=a.length){if(u<c){if(t(l,l)!==0)return c;do{const d=u+c>>>1;n(a[d],l)<=0?u=d+1:c=d}while(u<c)}return u}function s(a,l,u=0,c=a.length){const d=o(a,l,u,c-1);return d>u&&r(a[d-1],l)>-r(a[d],l)?d-1:d}return{left:o,center:s,right:i}}function Vw(){return 0}function Xw(e){return e===null?NaN:+e}const Jw=gf(ya),Zw=Jw.right;gf(Xw).center;class Ln{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const n=this._partials;let r=0;for(let o=0;o<this._n&&o<32;o++){const i=n[o],s=t+i,a=Math.abs(t)<Math.abs(i)?t-(s-i):i-(s-t);a&&(n[r++]=a),t=s}return n[r]=t,this._n=r+1,this}valueOf(){const t=this._partials;let n=this._n,r,o,i,s=0;if(n>0){for(s=t[--n];n>0&&(r=s,o=t[--n],s=r+o,i=o-(s-r),!i););n>0&&(i<0&&t[n-1]<0||i>0&&t[n-1]>0)&&(o=i*2,r=s+o,o==r-s&&(s=r))}return s}}class ih extends Map{constructor(t,n=tx){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),t!=null)for(const[r,o]of t)this.set(r,o)}get(t){return super.get(sh(this,t))}has(t){return super.has(sh(this,t))}set(t,n){return super.set(Qw(this,t),n)}delete(t){return super.delete(ex(this,t))}}function sh({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):n}function Qw({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):(e.set(r,n),n)}function ex({_intern:e,_key:t},n){const r=t(n);return e.has(r)&&(n=e.get(r),e.delete(r)),n}function tx(e){return e!==null&&typeof e=="object"?e.valueOf():e}const nx=Math.sqrt(50),rx=Math.sqrt(10),ox=Math.sqrt(2);function Ia(e,t,n){const r=(t-e)/Math.max(0,n),o=Math.floor(Math.log10(r)),i=r/Math.pow(10,o),s=i>=nx?10:i>=rx?5:i>=ox?2:1;let a,l,u;return o<0?(u=Math.pow(10,-o)/s,a=Math.round(e*u),l=Math.round(t*u),a/u<e&&++a,l/u>t&&--l,u=-u):(u=Math.pow(10,o)*s,a=Math.round(e/u),l=Math.round(t/u),a*u<e&&++a,l*u>t&&--l),l<a&&.5<=n&&n<2?Ia(e,t,n*2):[a,l,u]}function lu(e,t,n){if(t=+t,e=+e,n=+n,!(n>0))return[];if(e===t)return[e];const r=t<e,[o,i,s]=r?Ia(t,e,n):Ia(e,t,n);if(!(i>=o))return[];const a=i-o+1,l=new Array(a);if(r)if(s<0)for(let u=0;u<a;++u)l[u]=(i-u)/-s;else for(let u=0;u<a;++u)l[u]=(i-u)*s;else if(s<0)for(let u=0;u<a;++u)l[u]=(o+u)/-s;else for(let u=0;u<a;++u)l[u]=(o+u)*s;return l}function cu(e,t,n){return t=+t,e=+e,n=+n,Ia(e,t,n)[2]}function uu(e,t,n){t=+t,e=+e,n=+n;const r=t<e,o=r?cu(t,e,n):cu(e,t,n);return(r?-1:1)*(o<0?1/-o:o)}function*ix(e){for(const t of e)yield*t}function yg(e){return Array.from(ix(e))}function sx(e,t,n){e=+e,t=+t,n=(o=arguments.length)<2?(t=e,e=0,1):o<3?1:+n;for(var r=-1,o=Math.max(0,Math.ceil((t-e)/n))|0,i=new Array(o);++r<o;)i[r]=e+r*n;return i}var ax={value:()=>{}};function mf(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new ga(n)}function ga(e){this._=e}function lx(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",o=n.indexOf(".");if(o>=0&&(r=n.slice(o+1),n=n.slice(0,o)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}ga.prototype=mf.prototype={constructor:ga,on:function(e,t){var n=this._,r=lx(e+"",n),o,i=-1,s=r.length;if(arguments.length<2){for(;++i<s;)if((o=(e=r[i]).type)&&(o=cx(n[o],e.name)))return o;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++i<s;)if(o=(e=r[i]).type)n[o]=ah(n[o],e.name,t);else if(t==null)for(o in n)n[o]=ah(n[o],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ga(e)},call:function(e,t){if((o=arguments.length-2)>0)for(var n=new Array(o),r=0,o,i;r<o;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],o=0,i=r.length;o<i;++o)r[o].value.apply(t,n)}};function cx(e,t){for(var n=0,r=e.length,o;n<r;++n)if((o=e[n]).name===t)return o.value}function ah(e,t,n){for(var r=0,o=e.length;r<o;++r)if(e[r].name===t){e[r]=ax,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var fu="http://www.w3.org/1999/xhtml";const lh={svg:"http://www.w3.org/2000/svg",xhtml:fu,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ol(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),lh.hasOwnProperty(t)?{space:lh[t],local:e}:e}function ux(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fu&&t.documentElement.namespaceURI===fu?t.createElement(e):t.createElementNS(n,e)}}function fx(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function gg(e){var t=Ol(e);return(t.local?fx:ux)(t)}function dx(){}function bf(e){return e==null?dx:function(){return this.querySelector(e)}}function hx(e){typeof e!="function"&&(e=bf(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=new Array(s),l,u,c=0;c<s;++c)(l=i[c])&&(u=e.call(l,l.__data__,c,i))&&("__data__"in l&&(u.__data__=l.__data__),a[c]=u);return new gn(r,this._parents)}function px(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function yx(){return[]}function mg(e){return e==null?yx:function(){return this.querySelectorAll(e)}}function gx(e){return function(){return px(e.apply(this,arguments))}}function mx(e){typeof e=="function"?e=gx(e):e=mg(e);for(var t=this._groups,n=t.length,r=[],o=[],i=0;i<n;++i)for(var s=t[i],a=s.length,l,u=0;u<a;++u)(l=s[u])&&(r.push(e.call(l,l.__data__,u,s)),o.push(l));return new gn(r,o)}function bg(e){return function(){return this.matches(e)}}function wg(e){return function(t){return t.matches(e)}}var bx=Array.prototype.find;function wx(e){return function(){return bx.call(this.children,e)}}function xx(){return this.firstElementChild}function vx(e){return this.select(e==null?xx:wx(typeof e=="function"?e:wg(e)))}var kx=Array.prototype.filter;function Sx(){return Array.from(this.children)}function $x(e){return function(){return kx.call(this.children,e)}}function _x(e){return this.selectAll(e==null?Sx:$x(typeof e=="function"?e:wg(e)))}function Mx(e){typeof e!="function"&&(e=bg(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=[],l,u=0;u<s;++u)(l=i[u])&&e.call(l,l.__data__,u,i)&&a.push(l);return new gn(r,this._parents)}function xg(e){return new Array(e.length)}function Ex(){return new gn(this._enter||this._groups.map(xg),this._parents)}function La(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}La.prototype={constructor:La,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Ax(e){return function(){return e}}function Tx(e,t,n,r,o,i){for(var s=0,a,l=t.length,u=i.length;s<u;++s)(a=t[s])?(a.__data__=i[s],r[s]=a):n[s]=new La(e,i[s]);for(;s<l;++s)(a=t[s])&&(o[s]=a)}function Ox(e,t,n,r,o,i,s){var a,l,u=new Map,c=t.length,d=i.length,f=new Array(c),p;for(a=0;a<c;++a)(l=t[a])&&(f[a]=p=s.call(l,l.__data__,a,t)+"",u.has(p)?o[a]=l:u.set(p,l));for(a=0;a<d;++a)p=s.call(e,i[a],a,i)+"",(l=u.get(p))?(r[a]=l,l.__data__=i[a],u.delete(p)):n[a]=new La(e,i[a]);for(a=0;a<c;++a)(l=t[a])&&u.get(f[a])===l&&(o[a]=l)}function Cx(e){return e.__data__}function Nx(e,t){if(!arguments.length)return Array.from(this,Cx);var n=t?Ox:Tx,r=this._parents,o=this._groups;typeof e!="function"&&(e=Ax(e));for(var i=o.length,s=new Array(i),a=new Array(i),l=new Array(i),u=0;u<i;++u){var c=r[u],d=o[u],f=d.length,p=Ix(e.call(c,c&&c.__data__,u,r)),h=p.length,y=a[u]=new Array(h),g=s[u]=new Array(h),m=l[u]=new Array(f);n(c,d,y,g,m,p,t);for(var b=0,w=0,x,S;b<h;++b)if(x=y[b]){for(b>=w&&(w=b+1);!(S=g[w])&&++w<h;);x._next=S||null}}return s=new gn(s,r),s._enter=a,s._exit=l,s}function Ix(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Lx(){return new gn(this._exit||this._groups.map(xg),this._parents)}function Fx(e,t,n){var r=this.enter(),o=this,i=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(o=t(o),o&&(o=o.selection())),n==null?i.remove():n(i),r&&o?r.merge(o).order():o}function Rx(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,o=n.length,i=r.length,s=Math.min(o,i),a=new Array(o),l=0;l<s;++l)for(var u=n[l],c=r[l],d=u.length,f=a[l]=new Array(d),p,h=0;h<d;++h)(p=u[h]||c[h])&&(f[h]=p);for(;l<o;++l)a[l]=n[l];return new gn(a,this._parents)}function Px(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],o=r.length-1,i=r[o],s;--o>=0;)(s=r[o])&&(i&&s.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(s,i),i=s);return this}function zx(e){e||(e=Dx);function t(d,f){return d&&f?e(d.__data__,f.__data__):!d-!f}for(var n=this._groups,r=n.length,o=new Array(r),i=0;i<r;++i){for(var s=n[i],a=s.length,l=o[i]=new Array(a),u,c=0;c<a;++c)(u=s[c])&&(l[c]=u);l.sort(t)}return new gn(o,this._parents).order()}function Dx(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function jx(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Wx(){return Array.from(this)}function qx(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,i=r.length;o<i;++o){var s=r[o];if(s)return s}return null}function Bx(){let e=0;for(const t of this)++e;return e}function Hx(){return!this.node()}function Ux(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var o=t[n],i=0,s=o.length,a;i<s;++i)(a=o[i])&&e.call(a,a.__data__,i,o);return this}function Kx(e){return function(){this.removeAttribute(e)}}function Yx(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Gx(e,t){return function(){this.setAttribute(e,t)}}function Vx(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Xx(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Jx(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Zx(e,t){var n=Ol(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Yx:Kx:typeof t=="function"?n.local?Jx:Xx:n.local?Vx:Gx)(n,t))}function vg(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Qx(e){return function(){this.style.removeProperty(e)}}function ev(e,t,n){return function(){this.style.setProperty(e,t,n)}}function tv(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function nv(e,t,n){return arguments.length>1?this.each((t==null?Qx:typeof t=="function"?tv:ev)(e,t,n??"")):jo(this.node(),e)}function jo(e,t){return e.style.getPropertyValue(t)||vg(e).getComputedStyle(e,null).getPropertyValue(t)}function rv(e){return function(){delete this[e]}}function ov(e,t){return function(){this[e]=t}}function iv(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function sv(e,t){return arguments.length>1?this.each((t==null?rv:typeof t=="function"?iv:ov)(e,t)):this.node()[e]}function kg(e){return e.trim().split(/^|\s+/)}function wf(e){return e.classList||new Sg(e)}function Sg(e){this._node=e,this._names=kg(e.getAttribute("class")||"")}Sg.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function $g(e,t){for(var n=wf(e),r=-1,o=t.length;++r<o;)n.add(t[r])}function _g(e,t){for(var n=wf(e),r=-1,o=t.length;++r<o;)n.remove(t[r])}function av(e){return function(){$g(this,e)}}function lv(e){return function(){_g(this,e)}}function cv(e,t){return function(){(t.apply(this,arguments)?$g:_g)(this,e)}}function uv(e,t){var n=kg(e+"");if(arguments.length<2){for(var r=wf(this.node()),o=-1,i=n.length;++o<i;)if(!r.contains(n[o]))return!1;return!0}return this.each((typeof t=="function"?cv:t?av:lv)(n,t))}function fv(){this.textContent=""}function dv(e){return function(){this.textContent=e}}function hv(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function pv(e){return arguments.length?this.each(e==null?fv:(typeof e=="function"?hv:dv)(e)):this.node().textContent}function yv(){this.innerHTML=""}function gv(e){return function(){this.innerHTML=e}}function mv(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function bv(e){return arguments.length?this.each(e==null?yv:(typeof e=="function"?mv:gv)(e)):this.node().innerHTML}function wv(){this.nextSibling&&this.parentNode.appendChild(this)}function xv(){return this.each(wv)}function vv(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function kv(){return this.each(vv)}function Sv(e){var t=typeof e=="function"?e:gg(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $v(){return null}function _v(e,t){var n=typeof e=="function"?e:gg(e),r=t==null?$v:typeof t=="function"?t:bf(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Mv(){var e=this.parentNode;e&&e.removeChild(this)}function Ev(){return this.each(Mv)}function Av(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tv(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ov(e){return this.select(e?Tv:Av)}function Cv(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Nv(e){return function(t){e.call(this,t,this.__data__)}}function Iv(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function Lv(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,o=t.length,i;n<o;++n)i=t[n],(!e.type||i.type===e.type)&&i.name===e.name?this.removeEventListener(i.type,i.listener,i.options):t[++r]=i;++r?t.length=r:delete this.__on}}}function Fv(e,t,n){return function(){var r=this.__on,o,i=Nv(t);if(r){for(var s=0,a=r.length;s<a;++s)if((o=r[s]).type===e.type&&o.name===e.name){this.removeEventListener(o.type,o.listener,o.options),this.addEventListener(o.type,o.listener=i,o.options=n),o.value=t;return}}this.addEventListener(e.type,i,n),o={type:e.type,name:e.name,value:t,listener:i,options:n},r?r.push(o):this.__on=[o]}}function Rv(e,t,n){var r=Iv(e+""),o,i=r.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,u=a.length,c;l<u;++l)for(o=0,c=a[l];o<i;++o)if((s=r[o]).type===c.type&&s.name===c.name)return c.value}return}for(a=t?Fv:Lv,o=0;o<i;++o)this.each(a(r[o],t,n));return this}function Mg(e,t,n){var r=vg(e),o=r.CustomEvent;typeof o=="function"?o=new o(t,n):(o=r.document.createEvent("Event"),n?(o.initEvent(t,n.bubbles,n.cancelable),o.detail=n.detail):o.initEvent(t,!1,!1)),e.dispatchEvent(o)}function Pv(e,t){return function(){return Mg(this,e,t)}}function zv(e,t){return function(){return Mg(this,e,t.apply(this,arguments))}}function Dv(e,t){return this.each((typeof t=="function"?zv:Pv)(e,t))}function*jv(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,i=r.length,s;o<i;++o)(s=r[o])&&(yield s)}var Eg=[null];function gn(e,t){this._groups=e,this._parents=t}function ks(){return new gn([[document.documentElement]],Eg)}function Wv(){return this}gn.prototype=ks.prototype={constructor:gn,select:hx,selectAll:mx,selectChild:vx,selectChildren:_x,filter:Mx,data:Nx,enter:Ex,exit:Lx,join:Fx,merge:Rx,selection:Wv,order:Px,sort:zx,call:jx,nodes:Wx,node:qx,size:Bx,empty:Hx,each:Ux,attr:Zx,style:nv,property:sv,classed:uv,text:pv,html:bv,raise:xv,lower:kv,append:Sv,insert:_v,remove:Ev,clone:Ov,datum:Cv,on:Rv,dispatch:Dv,[Symbol.iterator]:jv};function sr(e){return typeof e=="string"?new gn([[document.querySelector(e)]],[document.documentElement]):new gn([[e]],Eg)}function qv(e){let t;for(;t=e.sourceEvent;)e=t;return e}function du(e,t){if(e=qv(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var o=t.getBoundingClientRect();return[e.clientX-o.left-t.clientLeft,e.clientY-o.top-t.clientTop]}}return[e.pageX,e.pageY]}const Bv={passive:!1},Qi={capture:!0,passive:!1};function $c(e){e.stopImmediatePropagation()}function Fo(e){e.preventDefault(),e.stopImmediatePropagation()}function Hv(e){var t=e.document.documentElement,n=sr(e).on("dragstart.drag",Fo,Qi);"onselectstart"in t?n.on("selectstart.drag",Fo,Qi):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Uv(e,t){var n=e.document.documentElement,r=sr(e).on("dragstart.drag",null);t&&(r.on("click.drag",Fo,Qi),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Ks=e=>()=>e;function hu(e,{sourceEvent:t,subject:n,target:r,identifier:o,active:i,x:s,y:a,dx:l,dy:u,dispatch:c}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:c}})}hu.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Kv(e){return!e.ctrlKey&&!e.button}function Yv(){return this.parentNode}function Gv(e,t){return t??{x:e.x,y:e.y}}function Vv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Xv(){var e=Kv,t=Yv,n=Gv,r=Vv,o={},i=mf("start","drag","end"),s=0,a,l,u,c,d=0;function f(x){x.on("mousedown.drag",p).filter(r).on("touchstart.drag",g).on("touchmove.drag",m,Bv).on("touchend.drag touchcancel.drag",b).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(x,S){if(!(c||!e.call(this,x,S))){var v=w(this,t.call(this,x,S),x,S,"mouse");v&&(sr(x.view).on("mousemove.drag",h,Qi).on("mouseup.drag",y,Qi),Hv(x.view),$c(x),u=!1,a=x.clientX,l=x.clientY,v("start",x))}}function h(x){if(Fo(x),!u){var S=x.clientX-a,v=x.clientY-l;u=S*S+v*v>d}o.mouse("drag",x)}function y(x){sr(x.view).on("mousemove.drag mouseup.drag",null),Uv(x.view,u),Fo(x),o.mouse("end",x)}function g(x,S){if(e.call(this,x,S)){var v=x.changedTouches,k=t.call(this,x,S),_=v.length,T,L;for(T=0;T<_;++T)(L=w(this,k,x,S,v[T].identifier,v[T]))&&($c(x),L("start",x,v[T]))}}function m(x){var S=x.changedTouches,v=S.length,k,_;for(k=0;k<v;++k)(_=o[S[k].identifier])&&(Fo(x),_("drag",x,S[k]))}function b(x){var S=x.changedTouches,v=S.length,k,_;for(c&&clearTimeout(c),c=setTimeout(function(){c=null},500),k=0;k<v;++k)(_=o[S[k].identifier])&&($c(x),_("end",x,S[k]))}function w(x,S,v,k,_,T){var L=i.copy(),N=du(T||v,S),I,O,M;if((M=n.call(x,new hu("beforestart",{sourceEvent:v,target:f,identifier:_,active:s,x:N[0],y:N[1],dx:0,dy:0,dispatch:L}),k))!=null)return I=M.x-N[0]||0,O=M.y-N[1]||0,function $(F,D,z){var j=N,G;switch(F){case"start":o[_]=$,G=s++;break;case"end":delete o[_],--s;case"drag":N=du(z||D,S),G=s;break}L.call(F,x,new hu(F,{sourceEvent:D,subject:M,target:f,identifier:_,active:G,x:N[0]+I,y:N[1]+O,dx:N[0]-j[0],dy:N[1]-j[1],dispatch:L}),k)}}return f.filter=function(x){return arguments.length?(e=typeof x=="function"?x:Ks(!!x),f):e},f.container=function(x){return arguments.length?(t=typeof x=="function"?x:Ks(x),f):t},f.subject=function(x){return arguments.length?(n=typeof x=="function"?x:Ks(x),f):n},f.touchable=function(x){return arguments.length?(r=typeof x=="function"?x:Ks(!!x),f):r},f.on=function(){var x=i.on.apply(i,arguments);return x===i?f:x},f.clickDistance=function(x){return arguments.length?(d=(x=+x)*x,f):Math.sqrt(d)},f}function Cl(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function xf(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function ei(){}var Zr=.7,Wo=1/Zr,Ro="\\s*([+-]?\\d+)\\s*",es="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Kn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Jv=/^#([0-9a-f]{3,8})$/,Zv=new RegExp(`^rgb\\(${Ro},${Ro},${Ro}\\)$`),Qv=new RegExp(`^rgb\\(${Kn},${Kn},${Kn}\\)$`),ek=new RegExp(`^rgba\\(${Ro},${Ro},${Ro},${es}\\)$`),tk=new RegExp(`^rgba\\(${Kn},${Kn},${Kn},${es}\\)$`),nk=new RegExp(`^hsl\\(${es},${Kn},${Kn}\\)$`),rk=new RegExp(`^hsla\\(${es},${Kn},${Kn},${es}\\)$`),ch={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Cl(ei,Qr,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:uh,formatHex:uh,formatHex8:ok,formatHsl:ik,formatRgb:fh,toString:fh});function uh(){return this.rgb().formatHex()}function ok(){return this.rgb().formatHex8()}function ik(){return Tg(this).formatHsl()}function fh(){return this.rgb().formatRgb()}function Qr(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Jv.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?dh(t):n===3?new Yt(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Ys(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Ys(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Zv.exec(e))?new Yt(t[1],t[2],t[3],1):(t=Qv.exec(e))?new Yt(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=ek.exec(e))?Ys(t[1],t[2],t[3],t[4]):(t=tk.exec(e))?Ys(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=nk.exec(e))?yh(t[1],t[2]/100,t[3]/100,1):(t=rk.exec(e))?yh(t[1],t[2]/100,t[3]/100,t[4]):ch.hasOwnProperty(e)?dh(ch[e]):e==="transparent"?new Yt(NaN,NaN,NaN,0):null}function dh(e){return new Yt(e>>16&255,e>>8&255,e&255,1)}function Ys(e,t,n,r){return r<=0&&(e=t=n=NaN),new Yt(e,t,n,r)}function Ag(e){return e instanceof ei||(e=Qr(e)),e?(e=e.rgb(),new Yt(e.r,e.g,e.b,e.opacity)):new Yt}function Fa(e,t,n,r){return arguments.length===1?Ag(e):new Yt(e,t,n,r??1)}function Yt(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cl(Yt,Fa,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Yt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Yt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Yt(Ur(this.r),Ur(this.g),Ur(this.b),Ra(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:hh,formatHex:hh,formatHex8:sk,formatRgb:ph,toString:ph}));function hh(){return`#${Hr(this.r)}${Hr(this.g)}${Hr(this.b)}`}function sk(){return`#${Hr(this.r)}${Hr(this.g)}${Hr(this.b)}${Hr((isNaN(this.opacity)?1:this.opacity)*255)}`}function ph(){const e=Ra(this.opacity);return`${e===1?"rgb(":"rgba("}${Ur(this.r)}, ${Ur(this.g)}, ${Ur(this.b)}${e===1?")":`, ${e})`}`}function Ra(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ur(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Hr(e){return e=Ur(e),(e<16?"0":"")+e.toString(16)}function yh(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Cn(e,t,n,r)}function Tg(e){if(e instanceof Cn)return new Cn(e.h,e.s,e.l,e.opacity);if(e instanceof ei||(e=Qr(e)),!e)return new Cn;if(e instanceof Cn)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,o=Math.min(t,n,r),i=Math.max(t,n,r),s=NaN,a=i-o,l=(i+o)/2;return a?(t===i?s=(n-r)/a+(n<r)*6:n===i?s=(r-t)/a+2:s=(t-n)/a+4,a/=l<.5?i+o:2-i-o,s*=60):a=l>0&&l<1?0:s,new Cn(s,a,l,e.opacity)}function ak(e,t,n,r){return arguments.length===1?Tg(e):new Cn(e,t,n,r??1)}function Cn(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cl(Cn,ak,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Cn(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Cn(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,o=2*n-r;return new Yt(_c(e>=240?e-240:e+120,o,r),_c(e,o,r),_c(e<120?e+240:e-120,o,r),this.opacity)},clamp(){return new Cn(gh(this.h),Gs(this.s),Gs(this.l),Ra(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Ra(this.opacity);return`${e===1?"hsl(":"hsla("}${gh(this.h)}, ${Gs(this.s)*100}%, ${Gs(this.l)*100}%${e===1?")":`, ${e})`}`}}));function gh(e){return e=(e||0)%360,e<0?e+360:e}function Gs(e){return Math.max(0,Math.min(1,e||0))}function _c(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const lk=Math.PI/180,ck=180/Math.PI;var Og=-.14861,vf=1.78277,kf=-.29227,Nl=-.90649,ts=1.97294,mh=ts*Nl,bh=ts*vf,wh=vf*kf-Nl*Og;function uk(e){if(e instanceof Kr)return new Kr(e.h,e.s,e.l,e.opacity);e instanceof Yt||(e=Ag(e));var t=e.r/255,n=e.g/255,r=e.b/255,o=(wh*r+mh*t-bh*n)/(wh+mh-bh),i=r-o,s=(ts*(n-o)-kf*i)/Nl,a=Math.sqrt(s*s+i*i)/(ts*o*(1-o)),l=a?Math.atan2(s,i)*ck-120:NaN;return new Kr(l<0?l+360:l,a,o,e.opacity)}function Tr(e,t,n,r){return arguments.length===1?uk(e):new Kr(e,t,n,r??1)}function Kr(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cl(Kr,Tr,xf(ei,{brighter(e){return e=e==null?Wo:Math.pow(Wo,e),new Kr(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Zr:Math.pow(Zr,e),new Kr(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=isNaN(this.h)?0:(this.h+120)*lk,t=+this.l,n=isNaN(this.s)?0:this.s*t*(1-t),r=Math.cos(e),o=Math.sin(e);return new Yt(255*(t+n*(Og*r+vf*o)),255*(t+n*(kf*r+Nl*o)),255*(t+n*(ts*r)),this.opacity)}}));function fk(e,t,n,r,o){var i=e*e,s=i*e;return((1-3*e+3*i-s)*t+(4-6*i+3*s)*n+(1+3*e+3*i-3*s)*r+s*o)/6}function dk(e){var t=e.length-1;return function(n){var r=n<=0?n=0:n>=1?(n=1,t-1):Math.floor(n*t),o=e[r],i=e[r+1],s=r>0?e[r-1]:2*o-i,a=r<t-1?e[r+2]:2*i-o;return fk((n-r/t)*t,s,o,i,a)}}const Il=e=>()=>e;function Cg(e,t){return function(n){return e+n*t}}function hk(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function pk(e,t){var n=t-e;return n?Cg(e,n>180||n<-180?n-360*Math.round(n/360):n):Il(isNaN(e)?t:e)}function yk(e){return(e=+e)==1?Po:function(t,n){return n-t?hk(t,n,e):Il(isNaN(t)?n:t)}}function Po(e,t){var n=t-e;return n?Cg(e,n):Il(isNaN(e)?t:e)}const eo=(function e(t){var n=yk(t);function r(o,i){var s=n((o=Fa(o)).r,(i=Fa(i)).r),a=n(o.g,i.g),l=n(o.b,i.b),u=Po(o.opacity,i.opacity);return function(c){return o.r=s(c),o.g=a(c),o.b=l(c),o.opacity=u(c),o+""}}return r.gamma=e,r})(1);function gk(e){return function(t){var n=t.length,r=new Array(n),o=new Array(n),i=new Array(n),s,a;for(s=0;s<n;++s)a=Fa(t[s]),r[s]=a.r||0,o[s]=a.g||0,i[s]=a.b||0;return r=e(r),o=e(o),i=e(i),a.opacity=1,function(l){return a.r=r(l),a.g=o(l),a.b=i(l),a+""}}}var mk=gk(dk);function bk(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),o;return function(i){for(o=0;o<n;++o)r[o]=e[o]*(1-i)+t[o]*i;return r}}function wk(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function xk(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,o=new Array(r),i=new Array(n),s;for(s=0;s<r;++s)o[s]=Ll(e[s],t[s]);for(;s<n;++s)i[s]=t[s];return function(a){for(s=0;s<r;++s)i[s]=o[s](a);return i}}function vk(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Tn(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function kk(e,t){var n={},r={},o;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(o in t)o in e?n[o]=Ll(e[o],t[o]):r[o]=t[o];return function(i){for(o in n)r[o]=n[o](i);return r}}var pu=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mc=new RegExp(pu.source,"g");function Sk(e){return function(){return e}}function $k(e){return function(t){return e(t)+""}}function Ng(e,t){var n=pu.lastIndex=Mc.lastIndex=0,r,o,i,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=pu.exec(e))&&(o=Mc.exec(t));)(i=o.index)>n&&(i=t.slice(n,i),a[s]?a[s]+=i:a[++s]=i),(r=r[0])===(o=o[0])?a[s]?a[s]+=o:a[++s]=o:(a[++s]=null,l.push({i:s,x:Tn(r,o)})),n=Mc.lastIndex;return n<t.length&&(i=t.slice(n),a[s]?a[s]+=i:a[++s]=i),a.length<2?l[0]?$k(l[0].x):Sk(t):(t=l.length,function(u){for(var c=0,d;c<t;++c)a[(d=l[c]).i]=d.x(u);return a.join("")})}function Ll(e,t){var n=typeof t,r;return t==null||n==="boolean"?Il(t):(n==="number"?Tn:n==="string"?(r=Qr(t))?(t=r,eo):Ng:t instanceof Qr?eo:t instanceof Date?vk:wk(t)?bk:Array.isArray(t)?xk:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?kk:Tn)(e,t)}function _k(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var xh=180/Math.PI,yu={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ig(e,t,n,r,o,i){var s,a,l;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),e*r<t*n&&(e=-e,t=-t,l=-l,s=-s),{translateX:o,translateY:i,rotate:Math.atan2(t,e)*xh,skewX:Math.atan(l)*xh,scaleX:s,scaleY:a}}var Vs;function Mk(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?yu:Ig(t.a,t.b,t.c,t.d,t.e,t.f)}function Ek(e){return e==null||(Vs||(Vs=document.createElementNS("http://www.w3.org/2000/svg","g")),Vs.setAttribute("transform",e),!(e=Vs.transform.baseVal.consolidate()))?yu:(e=e.matrix,Ig(e.a,e.b,e.c,e.d,e.e,e.f))}function Lg(e,t,n,r){function o(u){return u.length?u.pop()+" ":""}function i(u,c,d,f,p,h){if(u!==d||c!==f){var y=p.push("translate(",null,t,null,n);h.push({i:y-4,x:Tn(u,d)},{i:y-2,x:Tn(c,f)})}else(d||f)&&p.push("translate("+d+t+f+n)}function s(u,c,d,f){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),f.push({i:d.push(o(d)+"rotate(",null,r)-2,x:Tn(u,c)})):c&&d.push(o(d)+"rotate("+c+r)}function a(u,c,d,f){u!==c?f.push({i:d.push(o(d)+"skewX(",null,r)-2,x:Tn(u,c)}):c&&d.push(o(d)+"skewX("+c+r)}function l(u,c,d,f,p,h){if(u!==d||c!==f){var y=p.push(o(p)+"scale(",null,",",null,")");h.push({i:y-4,x:Tn(u,d)},{i:y-2,x:Tn(c,f)})}else(d!==1||f!==1)&&p.push(o(p)+"scale("+d+","+f+")")}return function(u,c){var d=[],f=[];return u=e(u),c=e(c),i(u.translateX,u.translateY,c.translateX,c.translateY,d,f),s(u.rotate,c.rotate,d,f),a(u.skewX,c.skewX,d,f),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,d,f),u=c=null,function(p){for(var h=-1,y=f.length,g;++h<y;)d[(g=f[h]).i]=g.x(p);return d.join("")}}}var Ak=Lg(Mk,"px, ","px)","deg)"),Tk=Lg(Ek,", ",")",")");function Fg(e){return(function t(n){n=+n;function r(o,i){var s=e((o=Tr(o)).h,(i=Tr(i)).h),a=Po(o.s,i.s),l=Po(o.l,i.l),u=Po(o.opacity,i.opacity);return function(c){return o.h=s(c),o.s=a(c),o.l=l(Math.pow(c,n)),o.opacity=u(c),o+""}}return r.gamma=t,r})(1)}Fg(pk);var Rg=Fg(Po);function Pg(e,t){t===void 0&&(t=e,e=Ll);for(var n=0,r=t.length-1,o=t[0],i=new Array(r<0?0:r);n<r;)i[n]=e(o,o=t[++n]);return function(s){var a=Math.max(0,Math.min(r-1,Math.floor(s*=r)));return i[a](s-a)}}function zg(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e(r/(t-1));return n}var qo=0,bi=0,fi=0,Dg=1e3,Pa,wi,za=0,to=0,Fl=0,ns=typeof performance=="object"&&performance.now?performance:Date,jg=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Sf(){return to||(jg(Ok),to=ns.now()+Fl)}function Ok(){to=0}function Da(){this._call=this._time=this._next=null}Da.prototype=Wg.prototype={constructor:Da,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Sf():+n)+(t==null?0:+t),!this._next&&wi!==this&&(wi?wi._next=this:Pa=this,wi=this),this._call=e,this._time=n,gu()},stop:function(){this._call&&(this._call=null,this._time=1/0,gu())}};function Wg(e,t,n){var r=new Da;return r.restart(e,t,n),r}function Ck(){Sf(),++qo;for(var e=Pa,t;e;)(t=to-e._time)>=0&&e._call.call(void 0,t),e=e._next;--qo}function vh(){to=(za=ns.now())+Fl,qo=bi=0;try{Ck()}finally{qo=0,Ik(),to=0}}function Nk(){var e=ns.now(),t=e-za;t>Dg&&(Fl-=t,za=e)}function Ik(){for(var e,t=Pa,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Pa=n);wi=e,gu(r)}function gu(e){if(!qo){bi&&(bi=clearTimeout(bi));var t=e-to;t>24?(e<1/0&&(bi=setTimeout(vh,e-ns.now()-Fl)),fi&&(fi=clearInterval(fi))):(fi||(za=ns.now(),fi=setInterval(Nk,Dg)),qo=1,jg(vh))}}function kh(e,t,n){var r=new Da;return t=t==null?0:+t,r.restart(o=>{r.stop(),e(o+t)},t,n),r}var Lk=mf("start","end","cancel","interrupt"),Fk=[],qg=0,Sh=1,mu=2,ma=3,$h=4,bu=5,ba=6;function Rl(e,t,n,r,o,i){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Rk(e,n,{name:t,index:r,group:o,on:Lk,tween:Fk,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qg})}function $f(e,t){var n=Pn(e,t);if(n.state>qg)throw new Error("too late; already scheduled");return n}function Jn(e,t){var n=Pn(e,t);if(n.state>ma)throw new Error("too late; already running");return n}function Pn(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Rk(e,t,n){var r=e.__transition,o;r[t]=n,n.timer=Wg(i,0,n.time);function i(u){n.state=Sh,n.timer.restart(s,n.delay,n.time),n.delay<=u&&s(u-n.delay)}function s(u){var c,d,f,p;if(n.state!==Sh)return l();for(c in r)if(p=r[c],p.name===n.name){if(p.state===ma)return kh(s);p.state===$h?(p.state=ba,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete r[c]):+c<t&&(p.state=ba,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete r[c])}if(kh(function(){n.state===ma&&(n.state=$h,n.timer.restart(a,n.delay,n.time),a(u))}),n.state=mu,n.on.call("start",e,e.__data__,n.index,n.group),n.state===mu){for(n.state=ma,o=new Array(f=n.tween.length),c=0,d=-1;c<f;++c)(p=n.tween[c].value.call(e,e.__data__,n.index,n.group))&&(o[++d]=p);o.length=d+1}}function a(u){for(var c=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(l),n.state=bu,1),d=-1,f=o.length;++d<f;)o[d].call(e,c);n.state===bu&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=ba,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function Pk(e,t){var n=e.__transition,r,o,i=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((r=n[s]).name!==t){i=!1;continue}o=r.state>mu&&r.state<bu,r.state=ba,r.timer.stop(),r.on.call(o?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}i&&delete e.__transition}}function zk(e){return this.each(function(){Pk(this,e)})}function Dk(e,t){var n,r;return function(){var o=Jn(this,e),i=o.tween;if(i!==n){r=n=i;for(var s=0,a=r.length;s<a;++s)if(r[s].name===t){r=r.slice(),r.splice(s,1);break}}o.tween=r}}function jk(e,t,n){var r,o;if(typeof n!="function")throw new Error;return function(){var i=Jn(this,e),s=i.tween;if(s!==r){o=(r=s).slice();for(var a={name:t,value:n},l=0,u=o.length;l<u;++l)if(o[l].name===t){o[l]=a;break}l===u&&o.push(a)}i.tween=o}}function Wk(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Pn(this.node(),n).tween,o=0,i=r.length,s;o<i;++o)if((s=r[o]).name===e)return s.value;return null}return this.each((t==null?Dk:jk)(n,e,t))}function _f(e,t,n){var r=e._id;return e.each(function(){var o=Jn(this,r);(o.value||(o.value={}))[t]=n.apply(this,arguments)}),function(o){return Pn(o,r).value[t]}}function Bg(e,t){var n;return(typeof t=="number"?Tn:t instanceof Qr?eo:(n=Qr(t))?(t=n,eo):Ng)(e,t)}function qk(e){return function(){this.removeAttribute(e)}}function Bk(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Hk(e,t,n){var r,o=n+"",i;return function(){var s=this.getAttribute(e);return s===o?null:s===r?i:i=t(r=s,n)}}function Uk(e,t,n){var r,o=n+"",i;return function(){var s=this.getAttributeNS(e.space,e.local);return s===o?null:s===r?i:i=t(r=s,n)}}function Kk(e,t,n){var r,o,i;return function(){var s,a=n(this),l;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),l=a+"",s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a)))}}function Yk(e,t,n){var r,o,i;return function(){var s,a=n(this),l;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),l=a+"",s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a)))}}function Gk(e,t){var n=Ol(e),r=n==="transform"?Tk:Bg;return this.attrTween(e,typeof t=="function"?(n.local?Yk:Kk)(n,r,_f(this,"attr."+e,t)):t==null?(n.local?Bk:qk)(n):(n.local?Uk:Hk)(n,r,t))}function Vk(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Xk(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Jk(e,t){var n,r;function o(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Xk(e,i)),n}return o._value=t,o}function Zk(e,t){var n,r;function o(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Vk(e,i)),n}return o._value=t,o}function Qk(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=Ol(e);return this.tween(n,(r.local?Jk:Zk)(r,t))}function e2(e,t){return function(){$f(this,e).delay=+t.apply(this,arguments)}}function t2(e,t){return t=+t,function(){$f(this,e).delay=t}}function n2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?e2:t2)(t,e)):Pn(this.node(),t).delay}function r2(e,t){return function(){Jn(this,e).duration=+t.apply(this,arguments)}}function o2(e,t){return t=+t,function(){Jn(this,e).duration=t}}function i2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?r2:o2)(t,e)):Pn(this.node(),t).duration}function s2(e,t){if(typeof t!="function")throw new Error;return function(){Jn(this,e).ease=t}}function a2(e){var t=this._id;return arguments.length?this.each(s2(t,e)):Pn(this.node(),t).ease}function l2(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Jn(this,e).ease=n}}function c2(e){if(typeof e!="function")throw new Error;return this.each(l2(this._id,e))}function u2(e){typeof e!="function"&&(e=bg(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var i=t[o],s=i.length,a=r[o]=[],l,u=0;u<s;++u)(l=i[u])&&e.call(l,l.__data__,u,i)&&a.push(l);return new xr(r,this._parents,this._name,this._id)}function f2(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,o=n.length,i=Math.min(r,o),s=new Array(r),a=0;a<i;++a)for(var l=t[a],u=n[a],c=l.length,d=s[a]=new Array(c),f,p=0;p<c;++p)(f=l[p]||u[p])&&(d[p]=f);for(;a<r;++a)s[a]=t[a];return new xr(s,this._parents,this._name,this._id)}function d2(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function h2(e,t,n){var r,o,i=d2(t)?$f:Jn;return function(){var s=i(this,e),a=s.on;a!==r&&(o=(r=a).copy()).on(t,n),s.on=o}}function p2(e,t){var n=this._id;return arguments.length<2?Pn(this.node(),n).on.on(e):this.each(h2(n,e,t))}function y2(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function g2(){return this.on("end.remove",y2(this._id))}function m2(e){var t=this._name,n=this._id;typeof e!="function"&&(e=bf(e));for(var r=this._groups,o=r.length,i=new Array(o),s=0;s<o;++s)for(var a=r[s],l=a.length,u=i[s]=new Array(l),c,d,f=0;f<l;++f)(c=a[f])&&(d=e.call(c,c.__data__,f,a))&&("__data__"in c&&(d.__data__=c.__data__),u[f]=d,Rl(u[f],t,n,f,u,Pn(c,n)));return new xr(i,this._parents,t,n)}function b2(e){var t=this._name,n=this._id;typeof e!="function"&&(e=mg(e));for(var r=this._groups,o=r.length,i=[],s=[],a=0;a<o;++a)for(var l=r[a],u=l.length,c,d=0;d<u;++d)if(c=l[d]){for(var f=e.call(c,c.__data__,d,l),p,h=Pn(c,n),y=0,g=f.length;y<g;++y)(p=f[y])&&Rl(p,t,n,y,f,h);i.push(f),s.push(c)}return new xr(i,s,t,n)}var w2=ks.prototype.constructor;function x2(){return new w2(this._groups,this._parents)}function v2(e,t){var n,r,o;return function(){var i=jo(this,e),s=(this.style.removeProperty(e),jo(this,e));return i===s?null:i===n&&s===r?o:o=t(n=i,r=s)}}function Hg(e){return function(){this.style.removeProperty(e)}}function k2(e,t,n){var r,o=n+"",i;return function(){var s=jo(this,e);return s===o?null:s===r?i:i=t(r=s,n)}}function S2(e,t,n){var r,o,i;return function(){var s=jo(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),jo(this,e))),s===l?null:s===r&&l===o?i:(o=l,i=t(r=s,a))}}function $2(e,t){var n,r,o,i="style."+t,s="end."+i,a;return function(){var l=Jn(this,e),u=l.on,c=l.value[i]==null?a||(a=Hg(t)):void 0;(u!==n||o!==c)&&(r=(n=u).copy()).on(s,o=c),l.on=r}}function _2(e,t,n){var r=(e+="")=="transform"?Ak:Bg;return t==null?this.styleTween(e,v2(e,r)).on("end.style."+e,Hg(e)):typeof t=="function"?this.styleTween(e,S2(e,r,_f(this,"style."+e,t))).each($2(this._id,e)):this.styleTween(e,k2(e,r,t),n).on("end.style."+e,null)}function M2(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function E2(e,t,n){var r,o;function i(){var s=t.apply(this,arguments);return s!==o&&(r=(o=s)&&M2(e,s,n)),r}return i._value=t,i}function A2(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,E2(e,t,n??""))}function T2(e){return function(){this.textContent=e}}function O2(e){return function(){var t=e(this);this.textContent=t??""}}function C2(e){return this.tween("text",typeof e=="function"?O2(_f(this,"text",e)):T2(e==null?"":e+""))}function N2(e){return function(t){this.textContent=e.call(this,t)}}function I2(e){var t,n;function r(){var o=e.apply(this,arguments);return o!==n&&(t=(n=o)&&N2(o)),t}return r._value=e,r}function L2(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,I2(e))}function F2(){for(var e=this._name,t=this._id,n=Ug(),r=this._groups,o=r.length,i=0;i<o;++i)for(var s=r[i],a=s.length,l,u=0;u<a;++u)if(l=s[u]){var c=Pn(l,t);Rl(l,e,n,u,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new xr(r,this._parents,e,n)}function R2(){var e,t,n=this,r=n._id,o=n.size();return new Promise(function(i,s){var a={value:s},l={value:function(){--o===0&&i()}};n.each(function(){var u=Jn(this,r),c=u.on;c!==e&&(t=(e=c).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(l)),u.on=t}),o===0&&i()})}var P2=0;function xr(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Ug(){return++P2}var or=ks.prototype;xr.prototype={constructor:xr,select:m2,selectAll:b2,selectChild:or.selectChild,selectChildren:or.selectChildren,filter:u2,merge:f2,selection:x2,transition:F2,call:or.call,nodes:or.nodes,node:or.node,size:or.size,empty:or.empty,each:or.each,on:p2,attr:Gk,attrTween:Qk,style:_2,styleTween:A2,text:C2,textTween:L2,remove:g2,tween:Wk,delay:n2,duration:i2,ease:a2,easeVarying:c2,end:R2,[Symbol.iterator]:or[Symbol.iterator]};function z2(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var D2={time:null,delay:0,duration:250,ease:z2};function j2(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function W2(e){var t,n;e instanceof xr?(t=e._id,e=e._name):(t=Ug(),(n=D2).time=Sf(),e=e==null?null:e+"");for(var r=this._groups,o=r.length,i=0;i<o;++i)for(var s=r[i],a=s.length,l,u=0;u<a;++u)(l=s[u])&&Rl(l,e,t,u,s,n||j2(l,t));return new xr(r,this._parents,e,t)}ks.prototype.interrupt=zk;ks.prototype.transition=W2;const wu=Math.PI,xu=2*wu,Wr=1e-6,q2=xu-Wr;function Kg(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function B2(e){let t=Math.floor(e);if(!(t>=0))throw new Error(`invalid digits: ${e}`);if(t>15)return Kg;const n=10**t;return function(r){this._+=r[0];for(let o=1,i=r.length;o<i;++o)this._+=Math.round(arguments[o]*n)/n+r[o]}}class H2{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=t==null?Kg:B2(t)}moveTo(t,n){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,n){this._append`L${this._x1=+t},${this._y1=+n}`}quadraticCurveTo(t,n,r,o){this._append`Q${+t},${+n},${this._x1=+r},${this._y1=+o}`}bezierCurveTo(t,n,r,o,i,s){this._append`C${+t},${+n},${+r},${+o},${this._x1=+i},${this._y1=+s}`}arcTo(t,n,r,o,i){if(t=+t,n=+n,r=+r,o=+o,i=+i,i<0)throw new Error(`negative radius: ${i}`);let s=this._x1,a=this._y1,l=r-t,u=o-n,c=s-t,d=a-n,f=c*c+d*d;if(this._x1===null)this._append`M${this._x1=t},${this._y1=n}`;else if(f>Wr)if(!(Math.abs(d*l-u*c)>Wr)||!i)this._append`L${this._x1=t},${this._y1=n}`;else{let p=r-s,h=o-a,y=l*l+u*u,g=p*p+h*h,m=Math.sqrt(y),b=Math.sqrt(f),w=i*Math.tan((wu-Math.acos((y+f-g)/(2*m*b)))/2),x=w/b,S=w/m;Math.abs(x-1)>Wr&&this._append`L${t+x*c},${n+x*d}`,this._append`A${i},${i},0,0,${+(d*p>c*h)},${this._x1=t+S*l},${this._y1=n+S*u}`}}arc(t,n,r,o,i,s){if(t=+t,n=+n,r=+r,s=!!s,r<0)throw new Error(`negative radius: ${r}`);let a=r*Math.cos(o),l=r*Math.sin(o),u=t+a,c=n+l,d=1^s,f=s?o-i:i-o;this._x1===null?this._append`M${u},${c}`:(Math.abs(this._x1-u)>Wr||Math.abs(this._y1-c)>Wr)&&this._append`L${u},${c}`,r&&(f<0&&(f=f%xu+xu),f>q2?this._append`A${r},${r},0,1,${d},${t-a},${n-l}A${r},${r},0,1,${d},${this._x1=u},${this._y1=c}`:f>Wr&&this._append`A${r},${r},0,${+(f>=wu)},${d},${this._x1=t+r*Math.cos(i)},${this._y1=n+r*Math.sin(i)}`)}rect(t,n,r,o){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${r=+r}v${+o}h${-r}Z`}toString(){return this._}}function U2(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function ja(e,t){if(!isFinite(e)||e===0)return null;var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"),r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function Bo(e){return e=ja(Math.abs(e)),e?e[1]:NaN}function K2(e,t){return function(n,r){for(var o=n.length,i=[],s=0,a=e[0],l=0;o>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),i.push(n.substring(o-=a,o+a)),!((l+=a+1)>r));)a=e[s=(s+1)%e.length];return i.reverse().join(t)}}function Y2(e){return function(t){return t.replace(/[0-9]/g,function(n){return e[+n]})}}var G2=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function rs(e){if(!(t=G2.exec(e)))throw new Error("invalid format: "+e);var t;return new Mf({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}rs.prototype=Mf.prototype;function Mf(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}Mf.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function V2(e){e:for(var t=e.length,n=1,r=-1,o;n<t;++n)switch(e[n]){case".":r=o=n;break;case"0":r===0&&(r=n),o=n;break;default:if(!+e[n])break e;r>0&&(r=0);break}return r>0?e.slice(0,r)+e.slice(o+1):e}var Wa;function X2(e,t){var n=ja(e,t);if(!n)return Wa=void 0,e.toPrecision(t);var r=n[0],o=n[1],i=o-(Wa=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,s=r.length;return i===s?r:i>s?r+new Array(i-s+1).join("0"):i>0?r.slice(0,i)+"."+r.slice(i):"0."+new Array(1-i).join("0")+ja(e,Math.max(0,t+i-1))[0]}function _h(e,t){var n=ja(e,t);if(!n)return e+"";var r=n[0],o=n[1];return o<0?"0."+new Array(-o).join("0")+r:r.length>o+1?r.slice(0,o+1)+"."+r.slice(o+1):r+new Array(o-r.length+2).join("0")}const Mh={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:U2,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>_h(e*100,t),r:_h,s:X2,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Eh(e){return e}var Ah=Array.prototype.map,Th=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function J2(e){var t=e.grouping===void 0||e.thousands===void 0?Eh:K2(Ah.call(e.grouping,Number),e.thousands+""),n=e.currency===void 0?"":e.currency[0]+"",r=e.currency===void 0?"":e.currency[1]+"",o=e.decimal===void 0?".":e.decimal+"",i=e.numerals===void 0?Eh:Y2(Ah.call(e.numerals,String)),s=e.percent===void 0?"%":e.percent+"",a=e.minus===void 0?"−":e.minus+"",l=e.nan===void 0?"NaN":e.nan+"";function u(d,f){d=rs(d);var p=d.fill,h=d.align,y=d.sign,g=d.symbol,m=d.zero,b=d.width,w=d.comma,x=d.precision,S=d.trim,v=d.type;v==="n"?(w=!0,v="g"):Mh[v]||(x===void 0&&(x=12),S=!0,v="g"),(m||p==="0"&&h==="=")&&(m=!0,p="0",h="=");var k=(f&&f.prefix!==void 0?f.prefix:"")+(g==="$"?n:g==="#"&&/[boxX]/.test(v)?"0"+v.toLowerCase():""),_=(g==="$"?r:/[%p]/.test(v)?s:"")+(f&&f.suffix!==void 0?f.suffix:""),T=Mh[v],L=/[defgprs%]/.test(v);x=x===void 0?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,x)):Math.max(0,Math.min(20,x));function N(I){var O=k,M=_,$,F,D;if(v==="c")M=T(I)+M,I="";else{I=+I;var z=I<0||1/I<0;if(I=isNaN(I)?l:T(Math.abs(I),x),S&&(I=V2(I)),z&&+I==0&&y!=="+"&&(z=!1),O=(z?y==="("?y:a:y==="-"||y==="("?"":y)+O,M=(v==="s"&&!isNaN(I)&&Wa!==void 0?Th[8+Wa/3]:"")+M+(z&&y==="("?")":""),L){for($=-1,F=I.length;++$<F;)if(D=I.charCodeAt($),48>D||D>57){M=(D===46?o+I.slice($+1):I.slice($))+M,I=I.slice(0,$);break}}}w&&!m&&(I=t(I,1/0));var j=O.length+I.length+M.length,G=j<b?new Array(b-j+1).join(p):"";switch(w&&m&&(I=t(G+I,G.length?b-M.length:1/0),G=""),h){case"<":I=O+I+M+G;break;case"=":I=O+G+I+M;break;case"^":I=G.slice(0,j=G.length>>1)+O+I+M+G.slice(j);break;default:I=G+O+I+M;break}return i(I)}return N.toString=function(){return d+""},N}function c(d,f){var p=Math.max(-8,Math.min(8,Math.floor(Bo(f)/3)))*3,h=Math.pow(10,-p),y=u((d=rs(d),d.type="f",d),{suffix:Th[8+p/3]});return function(g){return y(h*g)}}return{format:u,formatPrefix:c}}var Xs,ti,Yg;Z2({thousands:",",grouping:[3],currency:["$",""]});function Z2(e){return Xs=J2(e),ti=Xs.format,Yg=Xs.formatPrefix,Xs}function Q2(e){return Math.max(0,-Bo(Math.abs(e)))}function eS(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Bo(t)/3)))*3-Bo(Math.abs(e)))}function tS(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,Bo(t)-Bo(e))+1}var He=1e-6,Gg=1e-12,Ve=Math.PI,kt=Ve/2,qa=Ve/4,en=Ve*2,Ut=180/Ve,ft=Ve/180,ot=Math.abs,ni=Math.atan,Yn=Math.atan2,qe=Math.cos,Vg=Math.exp,Ba=Math.log,Ec=Math.pow,De=Math.sin,kn=Math.sign||function(e){return e>0?1:e<0?-1:0},un=Math.sqrt,Ef=Math.tan;function Xg(e){return e>1?0:e<-1?Ve:Math.acos(e)}function Mn(e){return e>1?kt:e<-1?-kt:Math.asin(e)}function Gt(){}function Ha(e,t){e&&Ch.hasOwnProperty(e.type)&&Ch[e.type](e,t)}var Oh={Feature:function(e,t){Ha(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,r=-1,o=n.length;++r<o;)Ha(n[r].geometry,t)}},Ch={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)e=n[r],t.point(e[0],e[1],e[2])},LineString:function(e,t){vu(e.coordinates,t,0)},MultiLineString:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)vu(n[r],t,0)},Polygon:function(e,t){Nh(e.coordinates,t)},MultiPolygon:function(e,t){for(var n=e.coordinates,r=-1,o=n.length;++r<o;)Nh(n[r],t)},GeometryCollection:function(e,t){for(var n=e.geometries,r=-1,o=n.length;++r<o;)Ha(n[r],t)}};function vu(e,t,n){var r=-1,o=e.length-n,i;for(t.lineStart();++r<o;)i=e[r],t.point(i[0],i[1],i[2]);t.lineEnd()}function Nh(e,t){var n=-1,r=e.length;for(t.polygonStart();++n<r;)vu(e[n],t,1);t.polygonEnd()}function qr(e,t){e&&Oh.hasOwnProperty(e.type)?Oh[e.type](e,t):Ha(e,t)}var ku=new Ln,Ua=new Ln,Jg,Zg,Su,$u,_u,os={point:Gt,lineStart:Gt,lineEnd:Gt,polygonStart:function(){ku=new Ln,os.lineStart=nS,os.lineEnd=rS},polygonEnd:function(){var e=+ku;Ua.add(e<0?en+e:e),this.lineStart=this.lineEnd=this.point=Gt},sphere:function(){Ua.add(en)}};function nS(){os.point=oS}function rS(){Qg(Jg,Zg)}function oS(e,t){os.point=Qg,Jg=e,Zg=t,e*=ft,t*=ft,Su=e,$u=qe(t=t/2+qa),_u=De(t)}function Qg(e,t){e*=ft,t*=ft,t=t/2+qa;var n=e-Su,r=n>=0?1:-1,o=r*n,i=qe(t),s=De(t),a=_u*s,l=$u*i+a*qe(o),u=a*r*De(o);ku.add(Yn(u,l)),Su=e,$u=i,_u=s}function iS(e){return Ua=new Ln,qr(e,os),Ua*2}function Mu(e){return[Yn(e[1],e[0]),Mn(e[2])]}function Ho(e){var t=e[0],n=e[1],r=qe(n);return[r*qe(t),r*De(t),De(n)]}function Js(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Ka(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Ac(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function Zs(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Eu(e){var t=un(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}function Au(e,t){function n(r,o){return r=e(r,o),t(r[0],r[1])}return e.invert&&t.invert&&(n.invert=function(r,o){return r=t.invert(r,o),r&&e.invert(r[0],r[1])}),n}function Tu(e,t){return ot(e)>Ve&&(e-=Math.round(e/en)*en),[e,t]}Tu.invert=Tu;function em(e,t,n){return(e%=en)?t||n?Au(Lh(e),Fh(t,n)):Lh(e):t||n?Fh(t,n):Tu}function Ih(e){return function(t,n){return t+=e,ot(t)>Ve&&(t-=Math.round(t/en)*en),[t,n]}}function Lh(e){var t=Ih(e);return t.invert=Ih(-e),t}function Fh(e,t){var n=qe(e),r=De(e),o=qe(t),i=De(t);function s(a,l){var u=qe(l),c=qe(a)*u,d=De(a)*u,f=De(l),p=f*n+c*r;return[Yn(d*o-p*i,c*n-f*r),Mn(p*o+d*i)]}return s.invert=function(a,l){var u=qe(l),c=qe(a)*u,d=De(a)*u,f=De(l),p=f*o-d*i;return[Yn(d*o+f*i,c*n+p*r),Mn(p*n-c*r)]},s}function sS(e){e=em(e[0]*ft,e[1]*ft,e.length>2?e[2]*ft:0);function t(n){return n=e(n[0]*ft,n[1]*ft),n[0]*=Ut,n[1]*=Ut,n}return t.invert=function(n){return n=e.invert(n[0]*ft,n[1]*ft),n[0]*=Ut,n[1]*=Ut,n},t}function aS(e,t,n,r,o,i){if(n){var s=qe(t),a=De(t),l=r*n;o==null?(o=t+r*en,i=t-l/2):(o=Rh(s,o),i=Rh(s,i),(r>0?o<i:o>i)&&(o+=r*en));for(var u,c=o;r>0?c>i:c<i;c-=l)u=Mu([s,-a*qe(c),-a*De(c)]),e.point(u[0],u[1])}}function Rh(e,t){t=Ho(t),t[0]-=e,Eu(t);var n=Xg(-t[1]);return((-t[2]<0?-n:n)+en-He)%en}function tm(){var e=[],t;return{point:function(n,r,o){t.push([n,r,o])},lineStart:function(){e.push(t=[])},lineEnd:Gt,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function wa(e,t){return ot(e[0]-t[0])<He&&ot(e[1]-t[1])<He}function Qs(e,t,n,r){this.x=e,this.z=t,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function nm(e,t,n,r,o){var i=[],s=[],a,l;if(e.forEach(function(h){if(!((y=h.length-1)<=0)){var y,g=h[0],m=h[y],b;if(wa(g,m)){if(!g[2]&&!m[2]){for(o.lineStart(),a=0;a<y;++a)o.point((g=h[a])[0],g[1]);o.lineEnd();return}m[0]+=2*He}i.push(b=new Qs(g,h,null,!0)),s.push(b.o=new Qs(g,null,b,!1)),i.push(b=new Qs(m,h,null,!1)),s.push(b.o=new Qs(m,null,b,!0))}}),!!i.length){for(s.sort(t),Ph(i),Ph(s),a=0,l=s.length;a<l;++a)s[a].e=n=!n;for(var u=i[0],c,d;;){for(var f=u,p=!0;f.v;)if((f=f.n)===u)return;c=f.z,o.lineStart();do{if(f.v=f.o.v=!0,f.e){if(p)for(a=0,l=c.length;a<l;++a)o.point((d=c[a])[0],d[1]);else r(f.x,f.n.x,1,o);f=f.n}else{if(p)for(c=f.p.z,a=c.length-1;a>=0;--a)o.point((d=c[a])[0],d[1]);else r(f.x,f.p.x,-1,o);f=f.p}f=f.o,c=f.z,p=!p}while(!f.v);o.lineEnd()}}}function Ph(e){if(t=e.length){for(var t,n=0,r=e[0],o;++n<t;)r.n=o=e[n],o.p=r,r=o;r.n=o=e[0],o.p=r}}function Tc(e){return ot(e[0])<=Ve?e[0]:kn(e[0])*((ot(e[0])+Ve)%en-Ve)}function lS(e,t){var n=Tc(t),r=t[1],o=De(r),i=[De(n),-qe(n),0],s=0,a=0,l=new Ln;o===1?r=kt+He:o===-1&&(r=-kt-He);for(var u=0,c=e.length;u<c;++u)if(f=(d=e[u]).length)for(var d,f,p=d[f-1],h=Tc(p),y=p[1]/2+qa,g=De(y),m=qe(y),b=0;b<f;++b,h=x,g=v,m=k,p=w){var w=d[b],x=Tc(w),S=w[1]/2+qa,v=De(S),k=qe(S),_=x-h,T=_>=0?1:-1,L=T*_,N=L>Ve,I=g*v;if(l.add(Yn(I*T*De(L),m*k+I*qe(L))),s+=N?_+T*en:_,N^h>=n^x>=n){var O=Ka(Ho(p),Ho(w));Eu(O);var M=Ka(i,O);Eu(M);var $=(N^_>=0?-1:1)*Mn(M[2]);(r>$||r===$&&(O[0]||O[1]))&&(a+=N^_>=0?1:-1)}}return(s<-He||s<He&&l<-Gg)^a&1}function rm(e,t,n,r){return function(o){var i=t(o),s=tm(),a=t(s),l=!1,u,c,d,f={point:p,lineStart:y,lineEnd:g,polygonStart:function(){f.point=m,f.lineStart=b,f.lineEnd=w,c=[],u=[]},polygonEnd:function(){f.point=p,f.lineStart=y,f.lineEnd=g,c=yg(c);var x=lS(u,r);c.length?(l||(o.polygonStart(),l=!0),nm(c,uS,x,n,o)):x&&(l||(o.polygonStart(),l=!0),o.lineStart(),n(null,null,1,o),o.lineEnd()),l&&(o.polygonEnd(),l=!1),c=u=null},sphere:function(){o.polygonStart(),o.lineStart(),n(null,null,1,o),o.lineEnd(),o.polygonEnd()}};function p(x,S){e(x,S)&&o.point(x,S)}function h(x,S){i.point(x,S)}function y(){f.point=h,i.lineStart()}function g(){f.point=p,i.lineEnd()}function m(x,S){d.push([x,S]),a.point(x,S)}function b(){a.lineStart(),d=[]}function w(){m(d[0][0],d[0][1]),a.lineEnd();var x=a.clean(),S=s.result(),v,k=S.length,_,T,L;if(d.pop(),u.push(d),d=null,!!k){if(x&1){if(T=S[0],(_=T.length-1)>0){for(l||(o.polygonStart(),l=!0),o.lineStart(),v=0;v<_;++v)o.point((L=T[v])[0],L[1]);o.lineEnd()}return}k>1&&x&2&&S.push(S.pop().concat(S.shift())),c.push(S.filter(cS))}}return f}}function cS(e){return e.length>1}function uS(e,t){return((e=e.x)[0]<0?e[1]-kt-He:kt-e[1])-((t=t.x)[0]<0?t[1]-kt-He:kt-t[1])}const zh=rm(function(){return!0},fS,hS,[-Ve,-kt]);function fS(e){var t=NaN,n=NaN,r=NaN,o;return{lineStart:function(){e.lineStart(),o=1},point:function(i,s){var a=i>0?Ve:-Ve,l=ot(i-t);ot(l-Ve)<He?(e.point(t,n=(n+s)/2>0?kt:-kt),e.point(r,n),e.lineEnd(),e.lineStart(),e.point(a,n),e.point(i,n),o=0):r!==a&&l>=Ve&&(ot(t-r)<He&&(t-=r*He),ot(i-a)<He&&(i-=a*He),n=dS(t,n,i,s),e.point(r,n),e.lineEnd(),e.lineStart(),e.point(a,n),o=0),e.point(t=i,n=s),r=a},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-o}}}function dS(e,t,n,r){var o,i,s=De(e-n);return ot(s)>He?ni((De(t)*(i=qe(r))*De(n)-De(r)*(o=qe(t))*De(e))/(o*i*s)):(t+r)/2}function hS(e,t,n,r){var o;if(e==null)o=n*kt,r.point(-Ve,o),r.point(0,o),r.point(Ve,o),r.point(Ve,0),r.point(Ve,-o),r.point(0,-o),r.point(-Ve,-o),r.point(-Ve,0),r.point(-Ve,o);else if(ot(e[0]-t[0])>He){var i=e[0]<t[0]?Ve:-Ve;o=n*i/2,r.point(-i,o),r.point(0,o),r.point(i,o)}else r.point(t[0],t[1])}function pS(e){var t=qe(e),n=2*ft,r=t>0,o=ot(t)>He;function i(c,d,f,p){aS(p,e,n,f,c,d)}function s(c,d){return qe(c)*qe(d)>t}function a(c){var d,f,p,h,y;return{lineStart:function(){h=p=!1,y=1},point:function(g,m){var b=[g,m],w,x=s(g,m),S=r?x?0:u(g,m):x?u(g+(g<0?Ve:-Ve),m):0;if(!d&&(h=p=x)&&c.lineStart(),x!==p&&(w=l(d,b),(!w||wa(d,w)||wa(b,w))&&(b[2]=1)),x!==p)y=0,x?(c.lineStart(),w=l(b,d),c.point(w[0],w[1])):(w=l(d,b),c.point(w[0],w[1],2),c.lineEnd()),d=w;else if(o&&d&&r^x){var v;!(S&f)&&(v=l(b,d,!0))&&(y=0,r?(c.lineStart(),c.point(v[0][0],v[0][1]),c.point(v[1][0],v[1][1]),c.lineEnd()):(c.point(v[1][0],v[1][1]),c.lineEnd(),c.lineStart(),c.point(v[0][0],v[0][1],3)))}x&&(!d||!wa(d,b))&&c.point(b[0],b[1]),d=b,p=x,f=S},lineEnd:function(){p&&c.lineEnd(),d=null},clean:function(){return y|(h&&p)<<1}}}function l(c,d,f){var p=Ho(c),h=Ho(d),y=[1,0,0],g=Ka(p,h),m=Js(g,g),b=g[0],w=m-b*b;if(!w)return!f&&c;var x=t*m/w,S=-t*b/w,v=Ka(y,g),k=Zs(y,x),_=Zs(g,S);Ac(k,_);var T=v,L=Js(k,T),N=Js(T,T),I=L*L-N*(Js(k,k)-1);if(!(I<0)){var O=un(I),M=Zs(T,(-L-O)/N);if(Ac(M,k),M=Mu(M),!f)return M;var $=c[0],F=d[0],D=c[1],z=d[1],j;F<$&&(j=$,$=F,F=j);var G=F-$,J=ot(G-Ve)<He,re=J||G<He;if(!J&&z<D&&(j=D,D=z,z=j),re?J?D+z>0^M[1]<(ot(M[0]-$)<He?D:z):D<=M[1]&&M[1]<=z:G>Ve^($<=M[0]&&M[0]<=F)){var Q=Zs(T,(-L+O)/N);return Ac(Q,k),[M,Mu(Q)]}}}function u(c,d){var f=r?e:Ve-e,p=0;return c<-f?p|=1:c>f&&(p|=2),d<-f?p|=4:d>f&&(p|=8),p}return rm(s,a,i,r?[0,-e]:[-Ve,e-Ve])}function yS(e,t,n,r,o,i){var s=e[0],a=e[1],l=t[0],u=t[1],c=0,d=1,f=l-s,p=u-a,h;if(h=n-s,!(!f&&h>0)){if(h/=f,f<0){if(h<c)return;h<d&&(d=h)}else if(f>0){if(h>d)return;h>c&&(c=h)}if(h=o-s,!(!f&&h<0)){if(h/=f,f<0){if(h>d)return;h>c&&(c=h)}else if(f>0){if(h<c)return;h<d&&(d=h)}if(h=r-a,!(!p&&h>0)){if(h/=p,p<0){if(h<c)return;h<d&&(d=h)}else if(p>0){if(h>d)return;h>c&&(c=h)}if(h=i-a,!(!p&&h<0)){if(h/=p,p<0){if(h>d)return;h>c&&(c=h)}else if(p>0){if(h<c)return;h<d&&(d=h)}return c>0&&(e[0]=s+c*f,e[1]=a+c*p),d<1&&(t[0]=s+d*f,t[1]=a+d*p),!0}}}}}var xi=1e9,ea=-xi;function om(e,t,n,r){function o(u,c){return e<=u&&u<=n&&t<=c&&c<=r}function i(u,c,d,f){var p=0,h=0;if(u==null||(p=s(u,d))!==(h=s(c,d))||l(u,c)<0^d>0)do f.point(p===0||p===3?e:n,p>1?r:t);while((p=(p+d+4)%4)!==h);else f.point(c[0],c[1])}function s(u,c){return ot(u[0]-e)<He?c>0?0:3:ot(u[0]-n)<He?c>0?2:1:ot(u[1]-t)<He?c>0?1:0:c>0?3:2}function a(u,c){return l(u.x,c.x)}function l(u,c){var d=s(u,1),f=s(c,1);return d!==f?d-f:d===0?c[1]-u[1]:d===1?u[0]-c[0]:d===2?u[1]-c[1]:c[0]-u[0]}return function(u){var c=u,d=tm(),f,p,h,y,g,m,b,w,x,S,v,k={point:_,lineStart:I,lineEnd:O,polygonStart:L,polygonEnd:N};function _($,F){o($,F)&&c.point($,F)}function T(){for(var $=0,F=0,D=p.length;F<D;++F)for(var z=p[F],j=1,G=z.length,J=z[0],re,Q,ve=J[0],Ce=J[1];j<G;++j)re=ve,Q=Ce,J=z[j],ve=J[0],Ce=J[1],Q<=r?Ce>r&&(ve-re)*(r-Q)>(Ce-Q)*(e-re)&&++$:Ce<=r&&(ve-re)*(r-Q)<(Ce-Q)*(e-re)&&--$;return $}function L(){c=d,f=[],p=[],v=!0}function N(){var $=T(),F=v&&$,D=(f=yg(f)).length;(F||D)&&(u.polygonStart(),F&&(u.lineStart(),i(null,null,1,u),u.lineEnd()),D&&nm(f,a,$,i,u),u.polygonEnd()),c=u,f=p=h=null}function I(){k.point=M,p&&p.push(h=[]),S=!0,x=!1,b=w=NaN}function O(){f&&(M(y,g),m&&x&&d.rejoin(),f.push(d.result())),k.point=_,x&&c.lineEnd()}function M($,F){var D=o($,F);if(p&&h.push([$,F]),S)y=$,g=F,m=D,S=!1,D&&(c.lineStart(),c.point($,F));else if(D&&x)c.point($,F);else{var z=[b=Math.max(ea,Math.min(xi,b)),w=Math.max(ea,Math.min(xi,w))],j=[$=Math.max(ea,Math.min(xi,$)),F=Math.max(ea,Math.min(xi,F))];yS(z,j,e,t,n,r)?(x||(c.lineStart(),c.point(z[0],z[1])),c.point(j[0],j[1]),D||c.lineEnd(),v=!1):D&&(c.lineStart(),c.point($,F),v=!1)}b=$,w=F,x=D}return k}}const is=e=>e;var Oc=new Ln,Ou=new Ln,im,sm,Cu,Nu,ar={point:Gt,lineStart:Gt,lineEnd:Gt,polygonStart:function(){ar.lineStart=gS,ar.lineEnd=bS},polygonEnd:function(){ar.lineStart=ar.lineEnd=ar.point=Gt,Oc.add(ot(Ou)),Ou=new Ln},result:function(){var e=Oc/2;return Oc=new Ln,e}};function gS(){ar.point=mS}function mS(e,t){ar.point=am,im=Cu=e,sm=Nu=t}function am(e,t){Ou.add(Nu*e-Cu*t),Cu=e,Nu=t}function bS(){am(im,sm)}var Uo=1/0,Ya=Uo,ss=-Uo,Ga=ss,Va={point:wS,lineStart:Gt,lineEnd:Gt,polygonStart:Gt,polygonEnd:Gt,result:function(){var e=[[Uo,Ya],[ss,Ga]];return ss=Ga=-(Ya=Uo=1/0),e}};function wS(e,t){e<Uo&&(Uo=e),e>ss&&(ss=e),t<Ya&&(Ya=t),t>Ga&&(Ga=t)}var Iu=0,Lu=0,vi=0,Xa=0,Ja=0,To=0,Fu=0,Ru=0,ki=0,lm,cm,Wn,qn,vn={point:no,lineStart:Dh,lineEnd:jh,polygonStart:function(){vn.lineStart=kS,vn.lineEnd=SS},polygonEnd:function(){vn.point=no,vn.lineStart=Dh,vn.lineEnd=jh},result:function(){var e=ki?[Fu/ki,Ru/ki]:To?[Xa/To,Ja/To]:vi?[Iu/vi,Lu/vi]:[NaN,NaN];return Iu=Lu=vi=Xa=Ja=To=Fu=Ru=ki=0,e}};function no(e,t){Iu+=e,Lu+=t,++vi}function Dh(){vn.point=xS}function xS(e,t){vn.point=vS,no(Wn=e,qn=t)}function vS(e,t){var n=e-Wn,r=t-qn,o=un(n*n+r*r);Xa+=o*(Wn+e)/2,Ja+=o*(qn+t)/2,To+=o,no(Wn=e,qn=t)}function jh(){vn.point=no}function kS(){vn.point=$S}function SS(){um(lm,cm)}function $S(e,t){vn.point=um,no(lm=Wn=e,cm=qn=t)}function um(e,t){var n=e-Wn,r=t-qn,o=un(n*n+r*r);Xa+=o*(Wn+e)/2,Ja+=o*(qn+t)/2,To+=o,o=qn*e-Wn*t,Fu+=o*(Wn+e),Ru+=o*(qn+t),ki+=o*3,no(Wn=e,qn=t)}function fm(e){this._context=e}fm.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,en);break}}},result:Gt};var Pu=new Ln,Cc,dm,hm,Si,$i,as={point:Gt,lineStart:function(){as.point=_S},lineEnd:function(){Cc&&pm(dm,hm),as.point=Gt},polygonStart:function(){Cc=!0},polygonEnd:function(){Cc=null},result:function(){var e=+Pu;return Pu=new Ln,e}};function _S(e,t){as.point=pm,dm=Si=e,hm=$i=t}function pm(e,t){Si-=e,$i-=t,Pu.add(un(Si*Si+$i*$i)),Si=e,$i=t}let Wh,Za,qh,Bh;class Hh{constructor(t){this._append=t==null?ym:MS(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==qh||this._append!==Za){const r=this._radius,o=this._;this._="",this._append`m0,${r}a${r},${r} 0 1,1 0,${-2*r}a${r},${r} 0 1,1 0,${2*r}z`,qh=r,Za=this._append,Bh=this._,this._=o}this._+=Bh;break}}}result(){const t=this._;return this._="",t.length?t:null}}function ym(e){let t=1;this._+=e[0];for(const n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function MS(e){const t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return ym;if(t!==Wh){const n=10**t;Wh=t,Za=function(o){let i=1;this._+=o[0];for(const s=o.length;i<s;++i)this._+=Math.round(arguments[i]*n)/n+o[i]}}return Za}function ES(e,t){let n=3,r=4.5,o,i;function s(a){return a&&(typeof r=="function"&&i.pointRadius(+r.apply(this,arguments)),qr(a,o(i))),i.result()}return s.area=function(a){return qr(a,o(ar)),ar.result()},s.measure=function(a){return qr(a,o(as)),as.result()},s.bounds=function(a){return qr(a,o(Va)),Va.result()},s.centroid=function(a){return qr(a,o(vn)),vn.result()},s.projection=function(a){return arguments.length?(o=a==null?(e=null,is):(e=a).stream,s):e},s.context=function(a){return arguments.length?(i=a==null?(t=null,new Hh(n)):new fm(t=a),typeof r!="function"&&i.pointRadius(r),s):t},s.pointRadius=function(a){return arguments.length?(r=typeof a=="function"?a:(i.pointRadius(+a),+a),s):r},s.digits=function(a){if(!arguments.length)return n;if(a==null)n=null;else{const l=Math.floor(a);if(!(l>=0))throw new RangeError(`invalid digits: ${a}`);n=l}return t===null&&(i=new Hh(n)),s},s.projection(e).digits(n).context(t)}function Pl(e){return function(t){var n=new zu;for(var r in e)n[r]=e[r];return n.stream=t,n}}function zu(){}zu.prototype={constructor:zu,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function Af(e,t,n){var r=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),r!=null&&e.clipExtent(null),qr(n,e.stream(Va)),t(Va.result()),r!=null&&e.clipExtent(r),e}function zl(e,t,n){return Af(e,function(r){var o=t[1][0]-t[0][0],i=t[1][1]-t[0][1],s=Math.min(o/(r[1][0]-r[0][0]),i/(r[1][1]-r[0][1])),a=+t[0][0]+(o-s*(r[1][0]+r[0][0]))/2,l=+t[0][1]+(i-s*(r[1][1]+r[0][1]))/2;e.scale(150*s).translate([a,l])},n)}function Tf(e,t,n){return zl(e,[[0,0],t],n)}function Of(e,t,n){return Af(e,function(r){var o=+t,i=o/(r[1][0]-r[0][0]),s=(o-i*(r[1][0]+r[0][0]))/2,a=-i*r[0][1];e.scale(150*i).translate([s,a])},n)}function Cf(e,t,n){return Af(e,function(r){var o=+t,i=o/(r[1][1]-r[0][1]),s=-i*r[0][0],a=(o-i*(r[1][1]+r[0][1]))/2;e.scale(150*i).translate([s,a])},n)}var Uh=16,AS=qe(30*ft);function Kh(e,t){return+t?OS(e,t):TS(e)}function TS(e){return Pl({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function OS(e,t){function n(r,o,i,s,a,l,u,c,d,f,p,h,y,g){var m=u-r,b=c-o,w=m*m+b*b;if(w>4*t&&y--){var x=s+f,S=a+p,v=l+h,k=un(x*x+S*S+v*v),_=Mn(v/=k),T=ot(ot(v)-1)<He||ot(i-d)<He?(i+d)/2:Yn(S,x),L=e(T,_),N=L[0],I=L[1],O=N-r,M=I-o,$=b*O-m*M;($*$/w>t||ot((m*O+b*M)/w-.5)>.3||s*f+a*p+l*h<AS)&&(n(r,o,i,s,a,l,N,I,T,x/=k,S/=k,v,y,g),g.point(N,I),n(N,I,T,x,S,v,u,c,d,f,p,h,y,g))}}return function(r){var o,i,s,a,l,u,c,d,f,p,h,y,g={point:m,lineStart:b,lineEnd:x,polygonStart:function(){r.polygonStart(),g.lineStart=S},polygonEnd:function(){r.polygonEnd(),g.lineStart=b}};function m(_,T){_=e(_,T),r.point(_[0],_[1])}function b(){d=NaN,g.point=w,r.lineStart()}function w(_,T){var L=Ho([_,T]),N=e(_,T);n(d,f,c,p,h,y,d=N[0],f=N[1],c=_,p=L[0],h=L[1],y=L[2],Uh,r),r.point(d,f)}function x(){g.point=m,r.lineEnd()}function S(){b(),g.point=v,g.lineEnd=k}function v(_,T){w(o=_,T),i=d,s=f,a=p,l=h,u=y,g.point=w}function k(){n(d,f,c,p,h,y,i,s,o,a,l,u,Uh,r),g.lineEnd=x,x()}return g}}var CS=Pl({point:function(e,t){this.stream.point(e*ft,t*ft)}});function NS(e){return Pl({point:function(t,n){var r=e(t,n);return this.stream.point(r[0],r[1])}})}function IS(e,t,n,r,o){function i(s,a){return s*=r,a*=o,[t+e*s,n-e*a]}return i.invert=function(s,a){return[(s-t)/e*r,(n-a)/e*o]},i}function Yh(e,t,n,r,o,i){if(!i)return IS(e,t,n,r,o);var s=qe(i),a=De(i),l=s*e,u=a*e,c=s/e,d=a/e,f=(a*n-s*t)/e,p=(a*t+s*n)/e;function h(y,g){return y*=r,g*=o,[l*y-u*g+t,n-u*y-l*g]}return h.invert=function(y,g){return[r*(c*y-d*g+f),o*(p-d*y-c*g)]},h}function Lr(e){return gm(function(){return e})()}function gm(e){var t,n=150,r=480,o=250,i=0,s=0,a=0,l=0,u=0,c,d=0,f=1,p=1,h=null,y=zh,g=null,m,b,w,x=is,S=.5,v,k,_,T,L;function N($){return _($[0]*ft,$[1]*ft)}function I($){return $=_.invert($[0],$[1]),$&&[$[0]*Ut,$[1]*Ut]}N.stream=function($){return T&&L===$?T:T=CS(NS(c)(y(v(x(L=$)))))},N.preclip=function($){return arguments.length?(y=$,h=void 0,M()):y},N.postclip=function($){return arguments.length?(x=$,g=m=b=w=null,M()):x},N.clipAngle=function($){return arguments.length?(y=+$?pS(h=$*ft):(h=null,zh),M()):h*Ut},N.clipExtent=function($){return arguments.length?(x=$==null?(g=m=b=w=null,is):om(g=+$[0][0],m=+$[0][1],b=+$[1][0],w=+$[1][1]),M()):g==null?null:[[g,m],[b,w]]},N.scale=function($){return arguments.length?(n=+$,O()):n},N.translate=function($){return arguments.length?(r=+$[0],o=+$[1],O()):[r,o]},N.center=function($){return arguments.length?(i=$[0]%360*ft,s=$[1]%360*ft,O()):[i*Ut,s*Ut]},N.rotate=function($){return arguments.length?(a=$[0]%360*ft,l=$[1]%360*ft,u=$.length>2?$[2]%360*ft:0,O()):[a*Ut,l*Ut,u*Ut]},N.angle=function($){return arguments.length?(d=$%360*ft,O()):d*Ut},N.reflectX=function($){return arguments.length?(f=$?-1:1,O()):f<0},N.reflectY=function($){return arguments.length?(p=$?-1:1,O()):p<0},N.precision=function($){return arguments.length?(v=Kh(k,S=$*$),M()):un(S)},N.fitExtent=function($,F){return zl(N,$,F)},N.fitSize=function($,F){return Tf(N,$,F)},N.fitWidth=function($,F){return Of(N,$,F)},N.fitHeight=function($,F){return Cf(N,$,F)};function O(){var $=Yh(n,0,0,f,p,d).apply(null,t(i,s)),F=Yh(n,r-$[0],o-$[1],f,p,d);return c=em(a,l,u),k=Au(t,F),_=Au(c,k),v=Kh(k,S),M()}function M(){return T=L=null,N}return function(){return t=e.apply(this,arguments),N.invert=t.invert&&I,O()}}function Nf(e){var t=0,n=Ve/3,r=gm(e),o=r(t,n);return o.parallels=function(i){return arguments.length?r(t=i[0]*ft,n=i[1]*ft):[t*Ut,n*Ut]},o}function LS(e){var t=qe(e);function n(r,o){return[r*t,De(o)/t]}return n.invert=function(r,o){return[r/t,Mn(o*t)]},n}function FS(e,t){var n=De(e),r=(n+De(t))/2;if(ot(r)<He)return LS(e);var o=1+n*(2*r-n),i=un(o)/r;function s(a,l){var u=un(o-2*r*De(l))/r;return[u*De(a*=r),i-u*qe(a)]}return s.invert=function(a,l){var u=i-l,c=Yn(a,ot(u))*kn(u);return u*r<0&&(c-=Ve*kn(a)*kn(u)),[c/r,Mn((o-(a*a+u*u)*r*r)/(2*r))]},s}function Qa(){return Nf(FS).scale(155.424).center([0,33.6442])}function mm(){return Qa().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function RS(e){var t=e.length;return{point:function(n,r){for(var o=-1;++o<t;)e[o].point(n,r)},sphere:function(){for(var n=-1;++n<t;)e[n].sphere()},lineStart:function(){for(var n=-1;++n<t;)e[n].lineStart()},lineEnd:function(){for(var n=-1;++n<t;)e[n].lineEnd()},polygonStart:function(){for(var n=-1;++n<t;)e[n].polygonStart()},polygonEnd:function(){for(var n=-1;++n<t;)e[n].polygonEnd()}}}function PS(){var e,t,n=mm(),r,o=Qa().rotate([154,0]).center([-2,58.5]).parallels([55,65]),i,s=Qa().rotate([157,0]).center([-3,19.9]).parallels([8,18]),a,l,u={point:function(f,p){l=[f,p]}};function c(f){var p=f[0],h=f[1];return l=null,r.point(p,h),l||(i.point(p,h),l)||(a.point(p,h),l)}c.invert=function(f){var p=n.scale(),h=n.translate(),y=(f[0]-h[0])/p,g=(f[1]-h[1])/p;return(g>=.12&&g<.234&&y>=-.425&&y<-.214?o:g>=.166&&g<.234&&y>=-.214&&y<-.115?s:n).invert(f)},c.stream=function(f){return e&&t===f?e:e=RS([n.stream(t=f),o.stream(f),s.stream(f)])},c.precision=function(f){return arguments.length?(n.precision(f),o.precision(f),s.precision(f),d()):n.precision()},c.scale=function(f){return arguments.length?(n.scale(f),o.scale(f*.35),s.scale(f),c.translate(n.translate())):n.scale()},c.translate=function(f){if(!arguments.length)return n.translate();var p=n.scale(),h=+f[0],y=+f[1];return r=n.translate(f).clipExtent([[h-.455*p,y-.238*p],[h+.455*p,y+.238*p]]).stream(u),i=o.translate([h-.307*p,y+.201*p]).clipExtent([[h-.425*p+He,y+.12*p+He],[h-.214*p-He,y+.234*p-He]]).stream(u),a=s.translate([h-.205*p,y+.212*p]).clipExtent([[h-.214*p+He,y+.166*p+He],[h-.115*p-He,y+.234*p-He]]).stream(u),d()},c.fitExtent=function(f,p){return zl(c,f,p)},c.fitSize=function(f,p){return Tf(c,f,p)},c.fitWidth=function(f,p){return Of(c,f,p)},c.fitHeight=function(f,p){return Cf(c,f,p)};function d(){return e=t=null,c}return c.scale(1070)}function bm(e){return function(t,n){var r=qe(t),o=qe(n),i=e(r*o);return i===1/0?[2,0]:[i*o*De(t),i*De(n)]}}function Ss(e){return function(t,n){var r=un(t*t+n*n),o=e(r),i=De(o),s=qe(o);return[Yn(t*i,r*s),Mn(r&&n*i/r)]}}var wm=bm(function(e){return un(2/(1+e))});wm.invert=Ss(function(e){return 2*Mn(e/2)});function zS(){return Lr(wm).scale(124.75).clipAngle(180-.001)}var xm=bm(function(e){return(e=Xg(e))&&e/De(e)});xm.invert=Ss(function(e){return e});function DS(){return Lr(xm).scale(79.4188).clipAngle(180-.001)}function Dl(e,t){return[e,Ba(Ef((kt+t)/2))]}Dl.invert=function(e,t){return[e,2*ni(Vg(t))-kt]};function jS(){return vm(Dl).scale(961/en)}function vm(e){var t=Lr(e),n=t.center,r=t.scale,o=t.translate,i=t.clipExtent,s=null,a,l,u;t.scale=function(d){return arguments.length?(r(d),c()):r()},t.translate=function(d){return arguments.length?(o(d),c()):o()},t.center=function(d){return arguments.length?(n(d),c()):n()},t.clipExtent=function(d){return arguments.length?(d==null?s=a=l=u=null:(s=+d[0][0],a=+d[0][1],l=+d[1][0],u=+d[1][1]),c()):s==null?null:[[s,a],[l,u]]};function c(){var d=Ve*r(),f=t(sS(t.rotate()).invert([0,0]));return i(s==null?[[f[0]-d,f[1]-d],[f[0]+d,f[1]+d]]:e===Dl?[[Math.max(f[0]-d,s),a],[Math.min(f[0]+d,l),u]]:[[s,Math.max(f[1]-d,a)],[l,Math.min(f[1]+d,u)]])}return c()}function ta(e){return Ef((kt+e)/2)}function WS(e,t){var n=qe(e),r=e===t?De(e):Ba(n/qe(t))/Ba(ta(t)/ta(e)),o=n*Ec(ta(e),r)/r;if(!r)return Dl;function i(s,a){o>0?a<-kt+He&&(a=-kt+He):a>kt-He&&(a=kt-He);var l=o/Ec(ta(a),r);return[l*De(r*s),o-l*qe(r*s)]}return i.invert=function(s,a){var l=o-a,u=kn(r)*un(s*s+l*l),c=Yn(s,ot(l))*kn(l);return l*r<0&&(c-=Ve*kn(s)*kn(l)),[c/r,2*ni(Ec(o/u,1/r))-kt]},i}function qS(){return Nf(WS).scale(109.5).parallels([30,30])}function el(e,t){return[e,t]}el.invert=el;function BS(){return Lr(el).scale(152.63)}function HS(e,t){var n=qe(e),r=e===t?De(e):(n-qe(t))/(t-e),o=n/r+e;if(ot(r)<He)return el;function i(s,a){var l=o-a,u=r*s;return[l*De(u),o-l*qe(u)]}return i.invert=function(s,a){var l=o-a,u=Yn(s,ot(l))*kn(l);return l*r<0&&(u-=Ve*kn(s)*kn(l)),[u/r,o-kn(r)*un(s*s+l*l)]},i}function US(){return Nf(HS).scale(131.154).center([0,13.9389])}var Ri=1.340264,Pi=-.081106,zi=893e-6,Di=.003796,tl=un(3)/2,KS=12;function km(e,t){var n=Mn(tl*De(t)),r=n*n,o=r*r*r;return[e*qe(n)/(tl*(Ri+3*Pi*r+o*(7*zi+9*Di*r))),n*(Ri+Pi*r+o*(zi+Di*r))]}km.invert=function(e,t){for(var n=t,r=n*n,o=r*r*r,i=0,s,a,l;i<KS&&(a=n*(Ri+Pi*r+o*(zi+Di*r))-t,l=Ri+3*Pi*r+o*(7*zi+9*Di*r),n-=s=a/l,r=n*n,o=r*r*r,!(ot(s)<Gg));++i);return[tl*e*(Ri+3*Pi*r+o*(7*zi+9*Di*r))/qe(n),Mn(De(n)/tl)]};function YS(){return Lr(km).scale(177.158)}function Sm(e,t){var n=qe(t),r=qe(e)*n;return[n*De(e)/r,De(t)/r]}Sm.invert=Ss(ni);function GS(){return Lr(Sm).scale(144.049).clipAngle(60)}function VS(){var e=1,t=0,n=0,r=1,o=1,i=0,s,a,l=null,u,c,d,f=1,p=1,h=Pl({point:function(x,S){var v=w([x,S]);this.stream.point(v[0],v[1])}}),y=is,g,m;function b(){return f=e*r,p=e*o,g=m=null,w}function w(x){var S=x[0]*f,v=x[1]*p;if(i){var k=v*s-S*a;S=S*s+v*a,v=k}return[S+t,v+n]}return w.invert=function(x){var S=x[0]-t,v=x[1]-n;if(i){var k=v*s+S*a;S=S*s-v*a,v=k}return[S/f,v/p]},w.stream=function(x){return g&&m===x?g:g=h(y(m=x))},w.postclip=function(x){return arguments.length?(y=x,l=u=c=d=null,b()):y},w.clipExtent=function(x){return arguments.length?(y=x==null?(l=u=c=d=null,is):om(l=+x[0][0],u=+x[0][1],c=+x[1][0],d=+x[1][1]),b()):l==null?null:[[l,u],[c,d]]},w.scale=function(x){return arguments.length?(e=+x,b()):e},w.translate=function(x){return arguments.length?(t=+x[0],n=+x[1],b()):[t,n]},w.angle=function(x){return arguments.length?(i=x%360*ft,a=De(i),s=qe(i),b()):i*Ut},w.reflectX=function(x){return arguments.length?(r=x?-1:1,b()):r<0},w.reflectY=function(x){return arguments.length?(o=x?-1:1,b()):o<0},w.fitExtent=function(x,S){return zl(w,x,S)},w.fitSize=function(x,S){return Tf(w,x,S)},w.fitWidth=function(x,S){return Of(w,x,S)},w.fitHeight=function(x,S){return Cf(w,x,S)},w}function $m(e,t){return[qe(t)*De(e),De(t)]}$m.invert=Ss(Mn);function XS(){return Lr($m).scale(249.5).clipAngle(90+He)}function _m(e,t){var n=qe(t),r=1+qe(e)*n;return[n*De(e)/r,De(t)/r]}_m.invert=Ss(function(e){return 2*ni(e)});function JS(){return Lr(_m).scale(250).clipAngle(142)}function Mm(e,t){return[Ba(Ef((kt+t)/2)),-e]}Mm.invert=function(e,t){return[-t,2*ni(Vg(e))-kt]};function ZS(){var e=vm(Mm),t=e.center,n=e.rotate;return e.center=function(r){return arguments.length?t([-r[1],r[0]]):(r=t(),[r[1],-r[0]])},e.rotate=function(r){return arguments.length?n([r[0],r[1],r.length>2?r[2]+90:90]):(r=n(),[r[0],r[1],r[2]-90])},n([0,0,90]).scale(159.155)}function ao(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e);break}return this}const Gh=Symbol("implicit");function If(){var e=new ih,t=[],n=[],r=Gh;function o(i){let s=e.get(i);if(s===void 0){if(r!==Gh)return r;e.set(i,s=t.push(i)-1)}return n[s%n.length]}return o.domain=function(i){if(!arguments.length)return t.slice();t=[],e=new ih;for(const s of i)e.has(s)||e.set(s,t.push(s)-1);return o},o.range=function(i){return arguments.length?(n=Array.from(i),o):n.slice()},o.unknown=function(i){return arguments.length?(r=i,o):r},o.copy=function(){return If(t,n).unknown(r)},ao.apply(o,arguments),o}function Lf(){var e=If().unknown(void 0),t=e.domain,n=e.range,r=0,o=1,i,s,a=!1,l=0,u=0,c=.5;delete e.unknown;function d(){var f=t().length,p=o<r,h=p?o:r,y=p?r:o;i=(y-h)/Math.max(1,f-l+u*2),a&&(i=Math.floor(i)),h+=(y-h-i*(f-l))*c,s=i*(1-l),a&&(h=Math.round(h),s=Math.round(s));var g=sx(f).map(function(m){return h+i*m});return n(p?g.reverse():g)}return e.domain=function(f){return arguments.length?(t(f),d()):t()},e.range=function(f){return arguments.length?([r,o]=f,r=+r,o=+o,d()):[r,o]},e.rangeRound=function(f){return[r,o]=f,r=+r,o=+o,a=!0,d()},e.bandwidth=function(){return s},e.step=function(){return i},e.round=function(f){return arguments.length?(a=!!f,d()):a},e.padding=function(f){return arguments.length?(l=Math.min(1,u=+f),d()):l},e.paddingInner=function(f){return arguments.length?(l=Math.min(1,f),d()):l},e.paddingOuter=function(f){return arguments.length?(u=+f,d()):u},e.align=function(f){return arguments.length?(c=Math.max(0,Math.min(1,f)),d()):c},e.copy=function(){return Lf(t(),[r,o]).round(a).paddingInner(l).paddingOuter(u).align(c)},ao.apply(d(),arguments)}function Em(e){var t=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,delete e.paddingOuter,e.copy=function(){return Em(t())},e}function QS(){return Em(Lf.apply(null,arguments).paddingInner(1))}function e$(e){return function(){return e}}function t$(e){return+e}var Vh=[0,1];function Hn(e){return e}function Du(e,t){return(t-=e=+e)?function(n){return(n-e)/t}:e$(isNaN(t)?NaN:.5)}function n$(e,t){var n;return e>t&&(n=e,e=t,t=n),function(r){return Math.max(e,Math.min(t,r))}}function r$(e,t,n){var r=e[0],o=e[1],i=t[0],s=t[1];return o<r?(r=Du(o,r),i=n(s,i)):(r=Du(r,o),i=n(i,s)),function(a){return i(r(a))}}function o$(e,t,n){var r=Math.min(e.length,t.length)-1,o=new Array(r),i=new Array(r),s=-1;for(e[r]<e[0]&&(e=e.slice().reverse(),t=t.slice().reverse());++s<r;)o[s]=Du(e[s],e[s+1]),i[s]=n(t[s],t[s+1]);return function(a){var l=Zw(e,a,1,r)-1;return i[l](o[l](a))}}function $s(e,t){return t.domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown())}function jl(){var e=Vh,t=Vh,n=Ll,r,o,i,s=Hn,a,l,u;function c(){var f=Math.min(e.length,t.length);return s!==Hn&&(s=n$(e[0],e[f-1])),a=f>2?o$:r$,l=u=null,d}function d(f){return f==null||isNaN(f=+f)?i:(l||(l=a(e.map(r),t,n)))(r(s(f)))}return d.invert=function(f){return s(o((u||(u=a(t,e.map(r),Tn)))(f)))},d.domain=function(f){return arguments.length?(e=Array.from(f,t$),c()):e.slice()},d.range=function(f){return arguments.length?(t=Array.from(f),c()):t.slice()},d.rangeRound=function(f){return t=Array.from(f),n=_k,c()},d.clamp=function(f){return arguments.length?(s=f?!0:Hn,c()):s!==Hn},d.interpolate=function(f){return arguments.length?(n=f,c()):n},d.unknown=function(f){return arguments.length?(i=f,d):i},function(f,p){return r=f,o=p,c()}}function Am(){return jl()(Hn,Hn)}function i$(e,t,n,r){var o=uu(e,t,n),i;switch(r=rs(r??",f"),r.type){case"s":{var s=Math.max(Math.abs(e),Math.abs(t));return r.precision==null&&!isNaN(i=eS(o,s))&&(r.precision=i),Yg(r,s)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(i=tS(o,Math.max(Math.abs(e),Math.abs(t))))&&(r.precision=i-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(i=Q2(o))&&(r.precision=i-(r.type==="%")*2);break}}return ti(r)}function Ff(e){var t=e.domain;return e.ticks=function(n){var r=t();return lu(r[0],r[r.length-1],n??10)},e.tickFormat=function(n,r){var o=t();return i$(o[0],o[o.length-1],n??10,r)},e.nice=function(n){n==null&&(n=10);var r=t(),o=0,i=r.length-1,s=r[o],a=r[i],l,u,c=10;for(a<s&&(u=s,s=a,a=u,u=o,o=i,i=u);c-- >0;){if(u=cu(s,a,n),u===l)return r[o]=s,r[i]=a,t(r);if(u>0)s=Math.floor(s/u)*u,a=Math.ceil(a/u)*u;else if(u<0)s=Math.ceil(s*u)/u,a=Math.floor(a*u)/u;else break;l=u}return e},e}function ji(){var e=Am();return e.copy=function(){return $s(e,ji())},ao.apply(e,arguments),Ff(e)}function Tm(e,t){e=e.slice();var n=0,r=e.length-1,o=e[n],i=e[r],s;return i<o&&(s=n,n=r,r=s,s=o,o=i,i=s),e[n]=t.floor(o),e[r]=t.ceil(i),e}function Xh(e){return Math.log(e)}function Jh(e){return Math.exp(e)}function s$(e){return-Math.log(-e)}function a$(e){return-Math.exp(-e)}function l$(e){return isFinite(e)?+("1e"+e):e<0?0:e}function c$(e){return e===10?l$:e===Math.E?Math.exp:t=>Math.pow(e,t)}function u$(e){return e===Math.E?Math.log:e===10&&Math.log10||e===2&&Math.log2||(e=Math.log(e),t=>Math.log(t)/e)}function Zh(e){return(t,n)=>-e(-t,n)}function f$(e){const t=e(Xh,Jh),n=t.domain;let r=10,o,i;function s(){return o=u$(r),i=c$(r),n()[0]<0?(o=Zh(o),i=Zh(i),e(s$,a$)):e(Xh,Jh),t}return t.base=function(a){return arguments.length?(r=+a,s()):r},t.domain=function(a){return arguments.length?(n(a),s()):n()},t.ticks=a=>{const l=n();let u=l[0],c=l[l.length-1];const d=c<u;d&&([u,c]=[c,u]);let f=o(u),p=o(c),h,y;const g=a==null?10:+a;let m=[];if(!(r%1)&&p-f<g){if(f=Math.floor(f),p=Math.ceil(p),u>0){for(;f<=p;++f)for(h=1;h<r;++h)if(y=f<0?h/i(-f):h*i(f),!(y<u)){if(y>c)break;m.push(y)}}else for(;f<=p;++f)for(h=r-1;h>=1;--h)if(y=f>0?h/i(-f):h*i(f),!(y<u)){if(y>c)break;m.push(y)}m.length*2<g&&(m=lu(u,c,g))}else m=lu(f,p,Math.min(p-f,g)).map(i);return d?m.reverse():m},t.tickFormat=(a,l)=>{if(a==null&&(a=10),l==null&&(l=r===10?"s":","),typeof l!="function"&&(!(r%1)&&(l=rs(l)).precision==null&&(l.trim=!0),l=ti(l)),a===1/0)return l;const u=Math.max(1,r*a/t.ticks().length);return c=>{let d=c/i(Math.round(o(c)));return d*r<r-.5&&(d*=r),d<=u?l(c):""}},t.nice=()=>n(Tm(n(),{floor:a=>i(Math.floor(o(a))),ceil:a=>i(Math.ceil(o(a)))})),t}function Om(){const e=f$(jl()).domain([1,10]);return e.copy=()=>$s(e,Om()).base(e.base()),ao.apply(e,arguments),e}function Qh(e){return function(t){return Math.sign(t)*Math.log1p(Math.abs(t/e))}}function ep(e){return function(t){return Math.sign(t)*Math.expm1(Math.abs(t))*e}}function d$(e){var t=1,n=e(Qh(t),ep(t));return n.constant=function(r){return arguments.length?e(Qh(t=+r),ep(t)):t},Ff(n)}function Cm(){var e=d$(jl());return e.copy=function(){return $s(e,Cm()).constant(e.constant())},ao.apply(e,arguments)}function tp(e){return function(t){return t<0?-Math.pow(-t,e):Math.pow(t,e)}}function h$(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function p$(e){return e<0?-e*e:e*e}function y$(e){var t=e(Hn,Hn),n=1;function r(){return n===1?e(Hn,Hn):n===.5?e(h$,p$):e(tp(n),tp(1/n))}return t.exponent=function(o){return arguments.length?(n=+o,r()):n},Ff(t)}function Nm(){var e=y$(jl());return e.copy=function(){return $s(e,Nm()).exponent(e.exponent())},ao.apply(e,arguments),e}const Nc=new Date,Ic=new Date;function Nt(e,t,n,r){function o(i){return e(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(e(i=new Date(+i)),i),o.ceil=i=>(e(i=new Date(i-1)),t(i,1),e(i),i),o.round=i=>{const s=o(i),a=o.ceil(i);return i-s<a-i?s:a},o.offset=(i,s)=>(t(i=new Date(+i),s==null?1:Math.floor(s)),i),o.range=(i,s,a)=>{const l=[];if(i=o.ceil(i),a=a==null?1:Math.floor(a),!(i<s)||!(a>0))return l;let u;do l.push(u=new Date(+i)),t(i,a),e(i);while(u<i&&i<s);return l},o.filter=i=>Nt(s=>{if(s>=s)for(;e(s),!i(s);)s.setTime(s-1)},(s,a)=>{if(s>=s)if(a<0)for(;++a<=0;)for(;t(s,-1),!i(s););else for(;--a>=0;)for(;t(s,1),!i(s););}),n&&(o.count=(i,s)=>(Nc.setTime(+i),Ic.setTime(+s),e(Nc),e(Ic),Math.floor(n(Nc,Ic))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(r?s=>r(s)%i===0:s=>o.count(0,s)%i===0):o)),o}const nl=Nt(()=>{},(e,t)=>{e.setTime(+e+t)},(e,t)=>t-e);nl.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?Nt(t=>{t.setTime(Math.floor(t/e)*e)},(t,n)=>{t.setTime(+t+n*e)},(t,n)=>(n-t)/e):nl);nl.range;const lr=1e3,Sn=lr*60,cr=Sn*60,vr=cr*24,Rf=vr*7,np=vr*30,Lc=vr*365,Oo=Nt(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*lr)},(e,t)=>(t-e)/lr,e=>e.getUTCSeconds());Oo.range;const Wl=Nt(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*lr)},(e,t)=>{e.setTime(+e+t*Sn)},(e,t)=>(t-e)/Sn,e=>e.getMinutes());Wl.range;const g$=Nt(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*Sn)},(e,t)=>(t-e)/Sn,e=>e.getUTCMinutes());g$.range;const ql=Nt(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*lr-e.getMinutes()*Sn)},(e,t)=>{e.setTime(+e+t*cr)},(e,t)=>(t-e)/cr,e=>e.getHours());ql.range;const m$=Nt(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*cr)},(e,t)=>(t-e)/cr,e=>e.getUTCHours());m$.range;const ri=Nt(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*Sn)/vr,e=>e.getDate()-1);ri.range;const Pf=Nt(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/vr,e=>e.getUTCDate()-1);Pf.range;const b$=Nt(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/vr,e=>Math.floor(e/vr));b$.range;function lo(e){return Nt(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(t,n)=>{t.setDate(t.getDate()+n*7)},(t,n)=>(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Sn)/Rf)}const _s=lo(0),rl=lo(1),w$=lo(2),x$=lo(3),Ko=lo(4),v$=lo(5),k$=lo(6);_s.range;rl.range;w$.range;x$.range;Ko.range;v$.range;k$.range;function co(e){return Nt(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCDate(t.getUTCDate()+n*7)},(t,n)=>(n-t)/Rf)}const Im=co(0),ol=co(1),S$=co(2),$$=co(3),Yo=co(4),_$=co(5),M$=co(6);Im.range;ol.range;S$.range;$$.range;Yo.range;_$.range;M$.range;const Bl=Nt(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+(t.getFullYear()-e.getFullYear())*12,e=>e.getMonth());Bl.range;const E$=Nt(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+(t.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());E$.range;const Gn=Nt(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());Gn.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Nt(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)});Gn.range;const ro=Nt(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());ro.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Nt(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)});ro.range;function A$(e,t,n,r,o,i){const s=[[Oo,1,lr],[Oo,5,5*lr],[Oo,15,15*lr],[Oo,30,30*lr],[i,1,Sn],[i,5,5*Sn],[i,15,15*Sn],[i,30,30*Sn],[o,1,cr],[o,3,3*cr],[o,6,6*cr],[o,12,12*cr],[r,1,vr],[r,2,2*vr],[n,1,Rf],[t,1,np],[t,3,3*np],[e,1,Lc]];function a(u,c,d){const f=c<u;f&&([u,c]=[c,u]);const p=d&&typeof d.range=="function"?d:l(u,c,d),h=p?p.range(u,+c+1):[];return f?h.reverse():h}function l(u,c,d){const f=Math.abs(c-u)/d,p=gf(([,,g])=>g).right(s,f);if(p===s.length)return e.every(uu(u/Lc,c/Lc,d));if(p===0)return nl.every(Math.max(uu(u,c,d),1));const[h,y]=s[f/s[p-1][2]<s[p][2]/f?p-1:p];return h.every(y)}return[a,l]}const[T$,O$]=A$(Gn,Bl,_s,ri,ql,Wl);function Fc(e){if(0<=e.y&&e.y<100){var t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return t.setFullYear(e.y),t}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function Rc(e){if(0<=e.y&&e.y<100){var t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return t.setUTCFullYear(e.y),t}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function di(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}function C$(e){var t=e.dateTime,n=e.date,r=e.time,o=e.periods,i=e.days,s=e.shortDays,a=e.months,l=e.shortMonths,u=hi(o),c=pi(o),d=hi(i),f=pi(i),p=hi(s),h=pi(s),y=hi(a),g=pi(a),m=hi(l),b=pi(l),w={a:D,A:z,b:j,B:G,c:null,d:lp,e:lp,f:e_,g:u_,G:d_,H:J$,I:Z$,j:Q$,L:Lm,m:t_,M:n_,p:J,q:re,Q:fp,s:dp,S:r_,u:o_,U:i_,V:s_,w:a_,W:l_,x:null,X:null,y:c_,Y:f_,Z:h_,"%":up},x={a:Q,A:ve,b:Ce,B:le,c:null,d:cp,e:cp,f:m_,g:E_,G:T_,H:p_,I:y_,j:g_,L:Rm,m:b_,M:w_,p:me,q:ce,Q:fp,s:dp,S:x_,u:v_,U:k_,V:S_,w:$_,W:__,x:null,X:null,y:M_,Y:A_,Z:O_,"%":up},S={a:L,A:N,b:I,B:O,c:M,d:sp,e:sp,f:Y$,g:ip,G:op,H:ap,I:ap,j:B$,L:K$,m:q$,M:H$,p:T,q:W$,Q:V$,s:X$,S:U$,u:R$,U:P$,V:z$,w:F$,W:D$,x:$,X:F,y:ip,Y:op,Z:j$,"%":G$};w.x=v(n,w),w.X=v(r,w),w.c=v(t,w),x.x=v(n,x),x.X=v(r,x),x.c=v(t,x);function v(Y,fe){return function(ie){var U=[],we=-1,xe=0,P=Y.length,H,oe,he;for(ie instanceof Date||(ie=new Date(+ie));++we<P;)Y.charCodeAt(we)===37&&(U.push(Y.slice(xe,we)),(oe=rp[H=Y.charAt(++we)])!=null?H=Y.charAt(++we):oe=H==="e"?" ":"0",(he=fe[H])&&(H=he(ie,oe)),U.push(H),xe=we+1);return U.push(Y.slice(xe,we)),U.join("")}}function k(Y,fe){return function(ie){var U=di(1900,void 0,1),we=_(U,Y,ie+="",0),xe,P;if(we!=ie.length)return null;if("Q"in U)return new Date(U.Q);if("s"in U)return new Date(U.s*1e3+("L"in U?U.L:0));if(fe&&!("Z"in U)&&(U.Z=0),"p"in U&&(U.H=U.H%12+U.p*12),U.m===void 0&&(U.m="q"in U?U.q:0),"V"in U){if(U.V<1||U.V>53)return null;"w"in U||(U.w=1),"Z"in U?(xe=Rc(di(U.y,0,1)),P=xe.getUTCDay(),xe=P>4||P===0?ol.ceil(xe):ol(xe),xe=Pf.offset(xe,(U.V-1)*7),U.y=xe.getUTCFullYear(),U.m=xe.getUTCMonth(),U.d=xe.getUTCDate()+(U.w+6)%7):(xe=Fc(di(U.y,0,1)),P=xe.getDay(),xe=P>4||P===0?rl.ceil(xe):rl(xe),xe=ri.offset(xe,(U.V-1)*7),U.y=xe.getFullYear(),U.m=xe.getMonth(),U.d=xe.getDate()+(U.w+6)%7)}else("W"in U||"U"in U)&&("w"in U||(U.w="u"in U?U.u%7:"W"in U?1:0),P="Z"in U?Rc(di(U.y,0,1)).getUTCDay():Fc(di(U.y,0,1)).getDay(),U.m=0,U.d="W"in U?(U.w+6)%7+U.W*7-(P+5)%7:U.w+U.U*7-(P+6)%7);return"Z"in U?(U.H+=U.Z/100|0,U.M+=U.Z%100,Rc(U)):Fc(U)}}function _(Y,fe,ie,U){for(var we=0,xe=fe.length,P=ie.length,H,oe;we<xe;){if(U>=P)return-1;if(H=fe.charCodeAt(we++),H===37){if(H=fe.charAt(we++),oe=S[H in rp?fe.charAt(we++):H],!oe||(U=oe(Y,ie,U))<0)return-1}else if(H!=ie.charCodeAt(U++))return-1}return U}function T(Y,fe,ie){var U=u.exec(fe.slice(ie));return U?(Y.p=c.get(U[0].toLowerCase()),ie+U[0].length):-1}function L(Y,fe,ie){var U=p.exec(fe.slice(ie));return U?(Y.w=h.get(U[0].toLowerCase()),ie+U[0].length):-1}function N(Y,fe,ie){var U=d.exec(fe.slice(ie));return U?(Y.w=f.get(U[0].toLowerCase()),ie+U[0].length):-1}function I(Y,fe,ie){var U=m.exec(fe.slice(ie));return U?(Y.m=b.get(U[0].toLowerCase()),ie+U[0].length):-1}function O(Y,fe,ie){var U=y.exec(fe.slice(ie));return U?(Y.m=g.get(U[0].toLowerCase()),ie+U[0].length):-1}function M(Y,fe,ie){return _(Y,t,fe,ie)}function $(Y,fe,ie){return _(Y,n,fe,ie)}function F(Y,fe,ie){return _(Y,r,fe,ie)}function D(Y){return s[Y.getDay()]}function z(Y){return i[Y.getDay()]}function j(Y){return l[Y.getMonth()]}function G(Y){return a[Y.getMonth()]}function J(Y){return o[+(Y.getHours()>=12)]}function re(Y){return 1+~~(Y.getMonth()/3)}function Q(Y){return s[Y.getUTCDay()]}function ve(Y){return i[Y.getUTCDay()]}function Ce(Y){return l[Y.getUTCMonth()]}function le(Y){return a[Y.getUTCMonth()]}function me(Y){return o[+(Y.getUTCHours()>=12)]}function ce(Y){return 1+~~(Y.getUTCMonth()/3)}return{format:function(Y){var fe=v(Y+="",w);return fe.toString=function(){return Y},fe},parse:function(Y){var fe=k(Y+="",!1);return fe.toString=function(){return Y},fe},utcFormat:function(Y){var fe=v(Y+="",x);return fe.toString=function(){return Y},fe},utcParse:function(Y){var fe=k(Y+="",!0);return fe.toString=function(){return Y},fe}}}var rp={"-":"",_:" ",0:"0"},Rt=/^\s*\d+/,N$=/^%/,I$=/[\\^$*+?|[\]().{}]/g;function et(e,t,n){var r=e<0?"-":"",o=(r?-e:e)+"",i=o.length;return r+(i<n?new Array(n-i+1).join(t)+o:o)}function L$(e){return e.replace(I$,"\\$&")}function hi(e){return new RegExp("^(?:"+e.map(L$).join("|")+")","i")}function pi(e){return new Map(e.map((t,n)=>[t.toLowerCase(),n]))}function F$(e,t,n){var r=Rt.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function R$(e,t,n){var r=Rt.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function P$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function z$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function D$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function op(e,t,n){var r=Rt.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function ip(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function j$(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function W$(e,t,n){var r=Rt.exec(t.slice(n,n+1));return r?(e.q=r[0]*3-3,n+r[0].length):-1}function q$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function sp(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function B$(e,t,n){var r=Rt.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function ap(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function H$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function U$(e,t,n){var r=Rt.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function K$(e,t,n){var r=Rt.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function Y$(e,t,n){var r=Rt.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function G$(e,t,n){var r=N$.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function V$(e,t,n){var r=Rt.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function X$(e,t,n){var r=Rt.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function lp(e,t){return et(e.getDate(),t,2)}function J$(e,t){return et(e.getHours(),t,2)}function Z$(e,t){return et(e.getHours()%12||12,t,2)}function Q$(e,t){return et(1+ri.count(Gn(e),e),t,3)}function Lm(e,t){return et(e.getMilliseconds(),t,3)}function e_(e,t){return Lm(e,t)+"000"}function t_(e,t){return et(e.getMonth()+1,t,2)}function n_(e,t){return et(e.getMinutes(),t,2)}function r_(e,t){return et(e.getSeconds(),t,2)}function o_(e){var t=e.getDay();return t===0?7:t}function i_(e,t){return et(_s.count(Gn(e)-1,e),t,2)}function Fm(e){var t=e.getDay();return t>=4||t===0?Ko(e):Ko.ceil(e)}function s_(e,t){return e=Fm(e),et(Ko.count(Gn(e),e)+(Gn(e).getDay()===4),t,2)}function a_(e){return e.getDay()}function l_(e,t){return et(rl.count(Gn(e)-1,e),t,2)}function c_(e,t){return et(e.getFullYear()%100,t,2)}function u_(e,t){return e=Fm(e),et(e.getFullYear()%100,t,2)}function f_(e,t){return et(e.getFullYear()%1e4,t,4)}function d_(e,t){var n=e.getDay();return e=n>=4||n===0?Ko(e):Ko.ceil(e),et(e.getFullYear()%1e4,t,4)}function h_(e){var t=e.getTimezoneOffset();return(t>0?"-":(t*=-1,"+"))+et(t/60|0,"0",2)+et(t%60,"0",2)}function cp(e,t){return et(e.getUTCDate(),t,2)}function p_(e,t){return et(e.getUTCHours(),t,2)}function y_(e,t){return et(e.getUTCHours()%12||12,t,2)}function g_(e,t){return et(1+Pf.count(ro(e),e),t,3)}function Rm(e,t){return et(e.getUTCMilliseconds(),t,3)}function m_(e,t){return Rm(e,t)+"000"}function b_(e,t){return et(e.getUTCMonth()+1,t,2)}function w_(e,t){return et(e.getUTCMinutes(),t,2)}function x_(e,t){return et(e.getUTCSeconds(),t,2)}function v_(e){var t=e.getUTCDay();return t===0?7:t}function k_(e,t){return et(Im.count(ro(e)-1,e),t,2)}function Pm(e){var t=e.getUTCDay();return t>=4||t===0?Yo(e):Yo.ceil(e)}function S_(e,t){return e=Pm(e),et(Yo.count(ro(e),e)+(ro(e).getUTCDay()===4),t,2)}function $_(e){return e.getUTCDay()}function __(e,t){return et(ol.count(ro(e)-1,e),t,2)}function M_(e,t){return et(e.getUTCFullYear()%100,t,2)}function E_(e,t){return e=Pm(e),et(e.getUTCFullYear()%100,t,2)}function A_(e,t){return et(e.getUTCFullYear()%1e4,t,4)}function T_(e,t){var n=e.getUTCDay();return e=n>=4||n===0?Yo(e):Yo.ceil(e),et(e.getUTCFullYear()%1e4,t,4)}function O_(){return"+0000"}function up(){return"%"}function fp(e){return+e}function dp(e){return Math.floor(+e/1e3)}var So,zf;C_({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function C_(e){return So=C$(e),zf=So.format,So.parse,So.utcFormat,So.utcParse,So}function N_(e){return new Date(e)}function I_(e){return e instanceof Date?+e:+new Date(+e)}function zm(e,t,n,r,o,i,s,a,l,u){var c=Am(),d=c.invert,f=c.domain,p=u(".%L"),h=u(":%S"),y=u("%I:%M"),g=u("%I %p"),m=u("%a %d"),b=u("%b %d"),w=u("%B"),x=u("%Y");function S(v){return(l(v)<v?p:a(v)<v?h:s(v)<v?y:i(v)<v?g:r(v)<v?o(v)<v?m:b:n(v)<v?w:x)(v)}return c.invert=function(v){return new Date(d(v))},c.domain=function(v){return arguments.length?f(Array.from(v,I_)):f().map(N_)},c.ticks=function(v){var k=f();return e(k[0],k[k.length-1],v??10)},c.tickFormat=function(v,k){return k==null?S:u(k)},c.nice=function(v){var k=f();return(!v||typeof v.range!="function")&&(v=t(k[0],k[k.length-1],v??10)),v?f(Tm(k,v)):c},c.copy=function(){return $s(c,zm(e,t,n,r,o,i,s,a,l,u))},c}function L_(){return ao.apply(zm(T$,O$,Gn,Bl,_s,ri,ql,Wl,Oo,zf).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function dt(e){for(var t=e.length/6|0,n=new Array(t),r=0;r<t;)n[r]="#"+e.slice(r*6,++r*6);return n}const F_=dt("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),R_=dt("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),P_=dt("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),z_=dt("4269d0efb118ff725c6cc5b03ca951ff8ab7a463f297bbf59c6b4e9498a0"),D_=dt("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),j_=dt("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),W_=dt("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),q_=dt("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),B_=dt("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),H_=dt("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),U_=dt("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab"),En=e=>mk(e[e.length-1]);var Dm=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(dt);const K_=En(Dm);var jm=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(dt);const Y_=En(jm);var Wm=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(dt);const G_=En(Wm);var qm=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(dt);const V_=En(qm);var Bm=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(dt);const X_=En(Bm);var Hm=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(dt);const J_=En(Hm);var Um=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(dt);const Z_=En(Um);var Km=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(dt);const Q_=En(Km);var Ym=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(dt);const eM=En(Ym);var Gm=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(dt);const tM=En(Gm);var Vm=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(dt);const nM=En(Vm);var Xm=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(dt);const rM=En(Xm);function oM(e){return e=Math.max(0,Math.min(1,e)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-e*(35.34-e*(2381.73-e*(6402.7-e*(7024.72-e*2710.57)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+e*(170.73+e*(52.82-e*(131.46-e*(176.58-e*67.37)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+e*(442.36-e*(2482.43-e*(6167.24-e*(6614.94-e*2475.67)))))))+")"}var iM=Rg(Tr(-100,.75,.35),Tr(80,1.5,.8)),sM=Rg(Tr(260,.75,.35),Tr(80,1.5,.8));Tr();function aM(e){return e=Math.max(0,Math.min(1,e)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+e*(1172.33-e*(10793.56-e*(33300.12-e*(38394.49-e*14825.05)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+e*(557.33+e*(1225.33-e*(3574.96-e*(1073.77+e*707.56)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+e*(3211.1-e*(15327.97-e*(27814-e*(22569.18-e*6838.66)))))))+")"}function Hl(e){var t=e.length;return function(n){return e[Math.max(0,Math.min(t-1,Math.floor(n*t)))]}}const lM=Hl(dt("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var cM=Hl(dt("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),uM=Hl(dt("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),fM=Hl(dt("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));function $o(e){return function(){return e}}const hp=1e-12;function dM(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);t=r}return e},()=>new H2(t)}function hM(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Jm(e){this._context=e}Jm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function Df(e){return new Jm(e)}function pM(e){return e[0]}function yM(e){return e[1]}function _i(e,t){var n=$o(!0),r=null,o=Df,i=null,s=dM(a);e=typeof e=="function"?e:e===void 0?pM:$o(e),t=typeof t=="function"?t:t===void 0?yM:$o(t);function a(l){var u,c=(l=hM(l)).length,d,f=!1,p;for(r==null&&(i=o(p=s())),u=0;u<=c;++u)!(u<c&&n(d=l[u],u,l))===f&&((f=!f)?i.lineStart():i.lineEnd()),f&&i.point(+e(d,u,l),+t(d,u,l));if(p)return i=null,p+""||null}return a.x=function(l){return arguments.length?(e=typeof l=="function"?l:$o(+l),a):e},a.y=function(l){return arguments.length?(t=typeof l=="function"?l:$o(+l),a):t},a.defined=function(l){return arguments.length?(n=typeof l=="function"?l:$o(!!l),a):n},a.curve=function(l){return arguments.length?(o=l,r!=null&&(i=o(r)),a):o},a.context=function(l){return arguments.length?(l==null?r=i=null:i=o(r=l),a):r},a}function pp(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function Zm(e){this._context=e}Zm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:pp(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:pp(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function gM(e){return new Zm(e)}function yp(e,t,n){e._context.bezierCurveTo(e._x1+e._k*(e._x2-e._x0),e._y1+e._k*(e._y2-e._y0),e._x2+e._k*(e._x1-t),e._y2+e._k*(e._y1-n),e._x2,e._y2)}function jf(e,t){this._context=e,this._k=(1-t)/6}jf.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:yp(this,this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2,this._x1=e,this._y1=t;break;case 2:this._point=3;default:yp(this,e,t);break}this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const mM=(function e(t){function n(r){return new jf(r,t)}return n.tension=function(r){return e(+r)},n})(0);function bM(e,t,n){var r=e._x1,o=e._y1,i=e._x2,s=e._y2;if(e._l01_a>hp){var a=2*e._l01_2a+3*e._l01_a*e._l12_a+e._l12_2a,l=3*e._l01_a*(e._l01_a+e._l12_a);r=(r*a-e._x0*e._l12_2a+e._x2*e._l01_2a)/l,o=(o*a-e._y0*e._l12_2a+e._y2*e._l01_2a)/l}if(e._l23_a>hp){var u=2*e._l23_2a+3*e._l23_a*e._l12_a+e._l12_2a,c=3*e._l23_a*(e._l23_a+e._l12_a);i=(i*u+e._x1*e._l23_2a-t*e._l12_2a)/c,s=(s*u+e._y1*e._l23_2a-n*e._l12_2a)/c}e._context.bezierCurveTo(r,o,i,s,e._x2,e._y2)}function Qm(e,t){this._context=e,this._alpha=t}Qm.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){if(e=+e,t=+t,this._point){var n=this._x2-e,r=this._y2-t;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3;default:bM(this,e,t);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const wM=(function e(t){function n(r){return t?new Qm(r,t):new jf(r,0)}return n.alpha=function(r){return e(+r)},n})(.5);function gp(e){return e<0?-1:1}function mp(e,t,n){var r=e._x1-e._x0,o=t-e._x1,i=(e._y1-e._y0)/(r||o<0&&-0),s=(n-e._y1)/(o||r<0&&-0),a=(i*o+s*r)/(r+o);return(gp(i)+gp(s))*Math.min(Math.abs(i),Math.abs(s),.5*Math.abs(a))||0}function bp(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function Pc(e,t,n){var r=e._x0,o=e._y0,i=e._x1,s=e._y1,a=(i-r)/3;e._context.bezierCurveTo(r+a,o+a*t,i-a,s-a*n,i,s)}function il(e){this._context=e}il.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Pc(this,this._t0,bp(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,Pc(this,bp(this,n=mp(this,e,t)),n);break;default:Pc(this,this._t0,n=mp(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function e0(e){this._context=new t0(e)}(e0.prototype=Object.create(il.prototype)).point=function(e,t){il.prototype.point.call(this,t,e)};function t0(e){this._context=e}t0.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,o,i){this._context.bezierCurveTo(t,e,r,n,i,o)}};function xM(e){return new il(e)}function vM(e){return new e0(e)}function n0(e){this._context=e}n0.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=wp(e),o=wp(t),i=0,s=1;s<n;++i,++s)this._context.bezierCurveTo(r[0][i],o[0][i],r[1][i],o[1][i],e[s],t[s]);(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function wp(e){var t,n=e.length-1,r,o=new Array(n),i=new Array(n),s=new Array(n);for(o[0]=0,i[0]=2,s[0]=e[0]+2*e[1],t=1;t<n-1;++t)o[t]=1,i[t]=4,s[t]=4*e[t]+2*e[t+1];for(o[n-1]=2,i[n-1]=7,s[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=o[t]/i[t-1],i[t]-=r,s[t]-=r*s[t-1];for(o[n-1]=s[n-1]/i[n-1],t=n-2;t>=0;--t)o[t]=(s[t]-o[t+1])/i[t];for(i[n-1]=(e[n]+o[n-1])/2,t=0;t<n-1;++t)i[t]=2*e[t+1]-o[t+1];return[o,i]}function kM(e){return new n0(e)}function Ul(e,t){this._context=e,this._t=t}Ul.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}}this._x=e,this._y=t}};function SM(e){return new Ul(e,.5)}function $M(e){return new Ul(e,0)}function _M(e){return new Ul(e,1)}function Mi(e,t,n){this.k=e,this.x=t,this.y=n}Mi.prototype={constructor:Mi,scale:function(e){return e===1?this:new Mi(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Mi(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};Mi.prototype;function uo(e,t){return t==null?e:`${e}\0${t}`}function r0(e){return e instanceof Date?e:new Date(e)}function MM(e){return typeof e.bandwidth=="function"?typeof e.paddingInner=="function"?"band":"point":typeof e.invert=="function"?"continuous":"discrete"}function o0(e,t){e.type=t,e.kind=MM(e);const n=typeof e.domain=="function"?e.domain():[];return e.temporal=n.some(r=>r instanceof Date),e.domainConfig=n,e.invertible=e.kind==="band"||e.kind==="point"||typeof e.invert=="function",e.ramp=e.ramp===!0||typeof e.interpolator=="function",e.encode=(r,o)=>Mr(e,r,o),e.invertValue=e.invertible?r=>TM(e,r):()=>{},e}function EM(e,{range:t,positional:n,domain:r}={}){return r&&typeof e.domain=="function"&&!e.domain().length&&e.domain(r),t&&n&&typeof e.range=="function"&&e.range(t),o0(e)}function ju(e,t){if(!e)return null;const n=e.type||"linear";let r;if(n==="time")r=L_().domain(e.domain.map(r0)).range(t);else if(n==="band")r=Lf().domain(e.domain).range(t).padding(e.padding!=null?e.padding:.1);else if(n==="point")r=QS().domain(e.domain).range(t).padding(e.padding!=null?e.padding:.5);else if(n==="ordinal")r=If().domain(e.domain).range(t);else if(n==="sequential"){const[o,i]=[Math.min(...e.domain),Math.max(...e.domain)],s=ji().domain([o,i]).range([0,1]).clamp(!0),a=eo(t[0],t[1]);r=l=>a(s(l)),r.domain=()=>e.domain,r.range=()=>t,r.ramp=!0}else if(n==="diverging"){const[o,i]=[Math.min(...e.domain),Math.max(...e.domain)],s=e.pivot!=null?e.pivot:o<0&&i>0?0:(o+i)/2,a=ji().domain([o,s,i]).range([0,.5,1]).clamp(!0),l=t.length>=3?[t[0],t[1],t[t.length-1]]:[t[0],"#f7f7f7",t[t.length-1]],u=Pg(eo,l);r=c=>u(a(c)),r.domain=()=>e.domain,r.range=()=>t,r.ramp=!0,r.pivot=()=>s}else n==="log"?(r=Om().domain(e.domain).range(t),e.base!=null&&r.base(e.base)):n==="symlog"?(r=Cm().domain(e.domain).range(t),e.constant!=null&&r.constant(e.constant)):n==="pow"||n==="sqrt"?r=Nm().domain(e.domain).range(t).exponent(e.exponent!=null?e.exponent:n==="sqrt"?.5:1):r=ji().domain(e.domain).range(t);return e.nice&&typeof r.nice=="function"&&r.nice(),e.clamp&&typeof r.clamp=="function"&&r.clamp(!0),o0(r,n)}function AM({domain:e,localRange:t,origin:n=0,halfSize:r=1,family:o="plain"}){const i=o==="x"?l=>n+l*r:o==="y"?l=>n-l*r:o==="size"?l=>l*r:l=>l,s=e.some(l=>l instanceof Date)?"time":"linear",a=ju({type:s,domain:e},t.map(i));return a.frameExtent=Math.abs(r)||void 0,a}function Vn(e){return!!e&&e.kind==="band"}function fo(e){return!!e&&(e.kind==="band"||e.kind==="point")}function oo(e){const t=e.range();return[Math.min(t[0],t[1]),Math.max(t[0],t[1])]}function Mr(e,t,n){if(!e)return n;if(e.kind==="band"){const o=e(t);return o==null?n:o+e.bandwidth()/2}if(e.kind==="point"){const o=e(t);return o??n}if(e.temporal)return e(r0(t));if(t==null)return n;const r=e(t);return typeof r=="number"&&!Number.isFinite(r)?n:r}function yn(e,t){return e&&e.bandwidth?e.bandwidth():t}function Yr(e,t,n){if(!e)return n;if(e.kind==="band"||e.kind==="point"){const r=e(t);return r??n}return Mr(e,t,n)}function i0(e,t,n,{inset:r=0,length:o}={}){let i,s;if(Vn(e)){const a=e(t),l=e.bandwidth();i=a,s=a+l}else i=0,s=n;if(o!=null){const a=(i+s)/2;return[a-o/2,a+o/2]}return[i+r,s-r]}function TM(e,t){if(!e||!e.invertible)return;if(fo(e)){const s=e.domain();if(!s.length)return;const a=e.kind==="band"?e.bandwidth()/2:0;let l=s[0],u=1/0;for(const c of s){const d=e(c)+a,f=Math.abs(d-t);f<u&&(u=f,l=c)}return l}const n=e.invert(t),r=e.domain();if(e.temporal){const s=Math.min(...r.map(Number)),a=Math.max(...r.map(Number));return new Date(Math.max(s,Math.min(a,Number(n))))}const o=Math.min(...r),i=Math.max(...r);return Math.max(o,Math.min(i,n))}function yr(e){const[t,n]=oo(e),r=e(0);return Math.max(t,Math.min(n,r))}const ls=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Ei=["#e6f0ff","#08519c"],Wu=["#2166ac","#f7f7f7","#b2182b"],s0=["●","■","▲","◆","★","✚","▼","◀","▶","⬟"],xp={faces:["😞","😐","🙂"],faces5:["😢","🙁","😐","🙂","😄"],hearts:["🖤","💛","❤️"],weather:["☀️","⛅","☁️","🌧️","⛈️"],arrows:["⬇️","↘️","➡️","↗️","⬆️"],shapes:s0},vp={category10:F_,tableau10:U_,observable10:z_,accent:R_,dark2:P_,paired:D_,pastel1:j_,pastel2:W_,set1:q_,set2:B_,set3:H_},OM={rdbu:G_,rdylbu:V_,rdylgn:X_,brbg:K_,piyg:Y_,spectral:J_,blues:Z_,greens:Q_,greys:eM,oranges:rM,purples:tM,reds:nM,viridis:lM,magma:cM,inferno:uM,plasma:fM,cividis:oM,turbo:aM,warm:iM,cool:sM},CM={rdbu:Wm,rdylbu:qm,rdylgn:Bm,brbg:Dm,piyg:jm,spectral:Hm,blues:Um,greens:Km,greys:Ym,oranges:Xm,purples:Gm,reds:Vm};function Ai(e,t,n){if(!e||typeof e!="string")return null;const r=e.toLowerCase();if(xp[r])return[...xp[r]];if(vp[r])return[...vp[r]];const o=OM[r];if(!o)return null;if(t==="diverging")return[o(0),o(.5),o(1)];if(t==="sequential")return[o(0),o(1)];const i=Math.max(2,n||2),s=CM[r];if(s){const a=Math.max(3,Math.min(11,i)),l=s[a];if(l)return[...l]}return zg(o,i)}const a0=new Set(["fill","stroke"]),NM=new Set(["opacity","fillOpacity","strokeOpacity"]),l0=new Set(["symbol"]),IM={x:"x",x1:"x",x2:"x",y:"y",y1:"y",y2:"y",theta:"theta",theta2:"theta",count:"count"};function _t(e){return IM[e]}function Gr(e){if(!e)return null;const t=e.scale;return t==="frame"?{}:t&&typeof t=="object"&&t.type==="frame"?t:null}function LM(e){if(!e||typeof e!="object"||e.frame===void 0)return e;const{frame:t,...n}=e;return n.scale!==void 0?n:Array.isArray(t)?{...n,scale:{type:"frame",range:t}}:typeof t=="number"?{...n,datum:t,scale:"frame"}:{...n,scale:"frame"}}const FM=new Set(["size","rx","ry","strokeWidth"]);function Wf(e){const t=_t(e);return t==="x"||t==="y"?t:FM.has(e)?"size":"plain"}function RM(e){const t=Wf(e);return t==="x"||t==="y"?[-1,1]:t==="size"?[0,1]:null}function qf(e){const t=e.find(n=>n!=null);return t instanceof Date?"temporal":typeof t=="number"||t===void 0?"quantitative":"categorical"}function PM(e,t,n="band"){const r=t==="quantitative"||t==="temporal";return a0.has(e)?r?"sequential":"ordinal":l0.has(e)?"ordinal":t==="temporal"?"time":t==="quantitative"?"linear":n}function c0(e,t){if(e==="band"||e==="point"||e==="ordinal")return[...new Set(t.filter(r=>r!=null))];const n=t.filter(r=>r!=null);return n.length?[Math.min(...n),Math.max(...n)]:[0,1]}function zM(e,t){if(t.length){if(t.length===1)return t[0];if(e==="quantitative"||e==="temporal"){const n=t.map(s=>Math.min(...s.map(Number))),r=t.map(s=>Math.max(...s.map(Number))),[o,i]=[Math.min(...n),Math.max(...r)];return e==="temporal"?[new Date(o),new Date(i)]:[o,i]}return[...new Set(t.flat())]}}const DM=["tableau10","dark2","set2","accent","paired","set3"],kp=["blues","oranges","greens","purples","greys"];function Sp(e,t){if(t<=1)return[e[e.length-1]];const n=Pg(eo,e);return zg(n,t)}function jM(e,t,n={}){const{measure:r,index:o=0,count:i=2}=n,s=a=>a[o%a.length];return e==="diverging"?o===0?t&&t.diverging||Wu:Ai(s(["rdbu","brbg","piyg","rdylgn"]),"diverging",i)||Wu:e==="sequential"?o===0?t&&t.ramp||Ei:Ai(s(kp),"sequential",i)||Ei:r==="ordinal"?o===0?Sp(t&&t.ramp||Ei,Math.max(2,i)):Ai(s(kp),"ordinal",i)||Sp(Ei,Math.max(2,i)):o===0?t&&t.palette||ls:Ai(s(DM),"ordinal",i)||ls}function u0(e,t,n,r,o={}){switch(e){case"x":return[0,n.width];case"y":return[n.height,0];case"size":return[3,18];case"rx":return[3,18];case"ry":return[3,18];case"curvature":return[-1,1];case"theta":return[180,0];case"angle":return[180,0];case"count":return o.countAxis==="x"?[0,n.width]:[n.height,0]}return NM.has(e)?[.15,1]:a0.has(e)?jM(t,r,o):l0.has(e)?[...s0]:e==="strokeWidth"?[1,8]:[0,1]}function WM(e){return e.channels||{}}function Bf(e,t){return Math.atan2(-(e.y-t.cy),e.x-t.cx)*180/Math.PI}function qM(e,t,n){const r=Math.min(t,n),o=Math.max(t,n),i=(r+o)/2,s=i+((e-i)%360+540)%360-180;return Math.max(r,Math.min(o,s))}function BM(e,t,n){const r=_t(e);if(r==="x")return t.x;if(r==="y")return t.y;if(e==="size")return n?Math.hypot(t.x-n.cx,t.y-n.cy):void 0;if(e==="theta"||e==="angle")return n?Bf(t,n):void 0}function HM(e,t,n=null){const r=_t(e);if(r==="x")return{x:t,y:n?n.cy:0};if(r==="y")return{x:n?n.cx:0,y:t};if(n){if(e==="size")return{x:n.cx+t,y:n.cy};if(e==="theta"||e==="angle"){const o=t*Math.PI/180,i=100;return{x:n.cx+i*Math.cos(o),y:n.cy-i*Math.sin(o)}}}}var UM={};function KM(){try{const e=typeof process<"u"&&UM&&"production";if(e)return e!=="production"}catch{}return!0}let Hf=KM();const qu=new Set;function YM(e){Hf=!!e,qu.clear()}function oi(){return Hf}function ge(e,t){!Hf||qu.has(e)||(qu.add(e),console.warn(`[elicit] ${t}`))}const f0=200,Bu={table:{roles:["data"],primary:"data"},network:{roles:["nodes","links"],primary:"nodes"}},d0="table",zc="fields";function GM(e){return!e||typeof e!="object"||Array.isArray(e)?!1:typeof e.type=="string"||"domain"in e||"default"in e||"key"in e||"open"in e}const Uf=["directed","multi","selfLoops"],VM=["role","fields",...Uf];function XM(e){return!e||typeof e!="object"?!1:typeof e.role=="string"?!0:!e.fields||typeof e.fields!="object"?!1:Object.keys(e).every(t=>VM.includes(t))}function $p(e,t){const n=Object.keys(e).filter(r=>e[r]&&e[r].key===!0);if(n.length>1)throw new Error(`[elicit] table "${t}" declares more than one \`key: true\` field (${n.map(r=>`"${r}"`).join(", ")}). A table has at most one key — it is the identity a \`ref\` points at.`);return n.length?n[0]:null}function h0(e){const t={};for(const n of Uf)typeof e[n]=="boolean"&&(t[n]=e[n]);return t}function JM(e,t){if(!t||typeof t!="object")throw new Error(`[elicit] schema.tables.${e} must be a field map, or { role, fields }. Got ${t===null?"null":typeof t}.`);if(XM(t)){if(typeof t.role!="string"&&GM(t.fields))throw new Error(`[elicit] table "${e}" is ambiguous: \`fields\` is its only key and its value looks like a single FieldSchema, so this reads equally as the long form or as a one-column table whose column is called "fields". Say which: ${e}: { fields: { fields: … } } for the column, or add \`role\` for the long form.`);const n=t.fields||{};return{name:e,role:t.role||e,fields:n,key:$p(n,e),...h0(t)}}if(Object.prototype.hasOwnProperty.call(t,zc))throw new Error(`[elicit] table "${e}" declares a column named "${zc}", which is reserved in this short form — it is how a table entry says "here are my columns". Use the long form to keep the column: ${e}: { fields: { ${zc}: … } }.`);return{name:e,role:e,fields:t,key:$p(t,e)}}function ZM(e){const t=e&&typeof e=="object"?e:{},n=typeof t.structure=="string",r=n?t.structure:d0,o=Bu[r];if(!o)throw new Error(`[elicit] unknown schema structure "${r}". Known structures: ${Object.keys(Bu).map(u=>`"${u}"`).join(", ")}.`);let i;if(!n)i={[o.primary]:t};else if(t.tables&&typeof t.tables=="object")i=t.tables;else throw t.fields&&typeof t.fields=="object"?new Error(`[elicit] schema declares \`fields\` at the top level. Columns belong to a named TABLE: schema: { structure: "${r}", tables: { ${o.primary}: { … } } }.`):new Error(`[elicit] schema declares structure "${r}" but no \`tables\`. A structure is a set of named tables: tables: { ${o.roles.map(u=>`${u}: { … }`).join(", ")} }.`);const s={},a={};for(const[u,c]of Object.entries(i)){const d=JM(u,c);if(!o.roles.includes(d.role))throw new Error(`[elicit] table "${u}" claims role "${d.role}", which structure "${r}" does not define. Its roles are ${o.roles.map(f=>`"${f}"`).join(", ")}.`);if(a[d.role])throw new Error(`[elicit] tables "${a[d.role]}" and "${u}" both claim role "${d.role}". Each role is filled by exactly one table.`);a[d.role]=u,s[u]=d}const l=o.roles.filter(u=>!a[u]);if(l.length)throw new Error(`[elicit] structure "${r}" needs a table for ${l.map(u=>`"${u}"`).join(", ")}, but the schema declares none. The schema is the contract of the elicited dataset, and a table built entirely by gesture has no rows to infer one from — declare it, even empty.`);for(const[u,c]of Object.entries(s))if(c.role!=="links")for(const d of Uf)c[d]!==void 0&&ge(`schema:${d}:${u}`,`table "${u}" declares \`${d}\`, but that describes the pairs of \`ref\` columns in a links table, and this table fills the "${c.role}" role. Move it to the table filling the "links" role, or drop it.`);return{structure:r,tables:s,byRole:a,primary:a[o.primary]}}function Ms(e){const t=e&&e.byRole&&e.byRole.links,n=t?e.tables[t]:null;return n?n.directed:void 0}function sl(e){const t=e&&e.byRole&&e.byRole.links,n=t?e.tables[t]:null;return{multi:!!(n&&n.multi),selfLoops:!!(n&&n.selfLoops)}}function xa(e){const t=Bu[e.structure],n=Object.keys(e.tables);return e.structure===d0&&n.length===1&&n[0]===t.primary}function QM(e){if(xa(e))return e.tables[e.primary].fields;const t={};for(const[n,r]of Object.entries(e.tables)){const o=h0(r),i=Object.keys(o).length?o:null;t[n]=r.role===n&&!i?r.fields:{...r.role===n?{}:{role:r.role},...i,fields:r.fields}}return{structure:e.structure,tables:t}}function Kf(e,t){const n=t&&typeof t.to=="string"?t.to:null,r=e.byRole.nodes||e.primary;if(n&&n.includes(".")){const s=n.indexOf("."),a=n.slice(0,s),l=n.slice(s+1);return e.tables[a]?{table:a,field:l}:null}const o=e.tables[r];if(!o)return null;const i=n||o.key;return i?{table:r,field:i}:null}function p0(e,t,n){const r=Kf(e,t);if(!r)return[];const o=e.tables[r.table].fields[r.field],i=[...o&&o.domain||[]];for(const s of n&&n[r.table]||[]){const a=s?s[r.field]:void 0;a!=null&&!i.includes(a)&&i.push(a)}return i}function Dc(e,t){const n=[];for(const[o,i]of Object.entries(e.tables))for(const[s,a]of Object.entries(i.fields)){if(!a||a.type!=="ref")continue;const l=Kf(e,a);l&&n.push({table:o,field:s,target:l})}if(!n.length)return!1;let r=!1;for(let o=0;o<=n.length;o++){let i=!1;for(const s of n){const a=t[s.table];if(!a||!a.length)continue;const l=new Set;for(const c of t[s.target.table]||[]){const d=c?c[s.target.field]:void 0;d!=null&&l.add(d)}const u=a.filter(c=>{const d=c?c[s.field]:void 0;return d==null||l.has(d)});u.length!==a.length&&(t[s.table]=u,i=!0,r=!0)}if(!i)break}return r}function _p(e,t){const n={};for(const r of Object.keys(t.tables))n[r]=[];if(e==null)return n;if(Array.isArray(e))return n[t.primary]=e,n;if(typeof e!="object")throw new Error(`[elicit] data must be an array of rows, or an object keyed by table name (${Object.keys(t.tables).map(r=>`"${r}"`).join(", ")}). Got ${typeof e}.`);for(const[r,o]of Object.entries(e)){if(!n[r]){ge(`data:table:${r}`,`data has a table "${r}" that the schema does not declare. The schema is the contract of the elicited dataset, so every table belongs in it; these rows are ignored. Declared tables: ${Object.keys(t.tables).map(i=>`"${i}"`).join(", ")}.`);continue}if(!Array.isArray(o))throw new Error(`[elicit] data.${r} must be an array of rows. Got ${o===null?"null":typeof o}.`);n[r]=o}return n}function Es(e){const t={};if(!e)return t;for(const[n,r]of Object.entries(e))t[n]=r&&r.default!==void 0?r.default:null;return t}function y0(e){const t=e||[];return t.some(n=>n instanceof Date)?"temporal":t.every(n=>typeof n=="number")?"quantitative":"categorical"}function g0(e){const t=new Set;for(const n of e.slice(0,f0))if(n&&typeof n=="object")for(const r of Object.keys(n))t.add(r);return[...t]}function al(e,t){const n=[];for(const r of e.slice(0,f0)){const o=r?r[t]:void 0;o!=null&&n.push(o)}return n}function e5(e){const t={};if(!Array.isArray(e)||!e.length)return t;for(const n of g0(e)){const r=al(e,n),o=qf(r),i=o==="categorical"||o==="ordinal";t[n]={type:o,domain:c0(i?"band":"linear",r),...i?{open:!0}:{}}}return t}function t5(e){return`schema: {
9
9
  ${Object.entries(e).map(([n,r])=>` ${JSON.stringify(n)}: { type: ${JSON.stringify(r.type)}, domain: ${JSON.stringify(r.domain)}${r.open?", open: true":""} }`).join(`,
10
10
  `)}
11
11
  }`}function n5(e,t){return t==="quantitative"?typeof e!="number"||!Number.isFinite(e):t==="temporal"?e instanceof Date?Number.isNaN(e.getTime()):typeof e=="number"?!Number.isFinite(e):typeof e=="string"?Number.isNaN(new Date(e).getTime()):!0:!1}function r5(e,t,n){if(!Array.isArray(n)||!n.length)return!1;if(t==="quantitative"||t==="temporal"){if(n.length<2)return!1;const r=e instanceof Date?e.getTime():Number(e);if(!Number.isFinite(r))return!1;const o=n.map(a=>a instanceof Date?a.getTime():Number(a)),i=Math.min(...o),s=Math.max(...o);return!Number.isFinite(i)||!Number.isFinite(s)?!1:r<i||r>s}return!n.includes(e)}function o5(e,t,n="data"){if(!Array.isArray(t)||!t.length)return;const r=e||{};if(!Object.keys(r).length){ge("schema:missing",`${n} was given but the spec declares no schema. The schema is the contract of the elicited dataset — it owns each field's measurement type and domain, and is what a created row is minted from. Inferring both from the data for now; declare it:
12
- ${t5(e5(t))}`);return}for(const i of g0(t))r[i]||ge(`schema:extra:${i}`,`${n} has a column "${i}" that the schema does not declare. The schema is the contract of the elicited dataset, so every column belongs in it — an undeclared one gets no domain, no type and no creation default, so a row made by an edit will be missing it. Declare it: schema: { ${JSON.stringify(i)}: { type: ${JSON.stringify(qf(al(t,i)))} } }.`);for(const[i,s]of Object.entries(r)){if(!s)continue;const a=al(t,i);if(!s.type){s.domain&&ge(`schema:notype:${i}`,`schema.${i} declares a domain but no \`type\`. A field's measurement type is required — without it the type is inferred from the data and can disagree with the domain you declared. Add type: ${JSON.stringify(y0(s.domain))}.`);continue}const l=a.find(d=>n5(d,s.type));if(l!==void 0){ge(`schema:type:${i}`,`${n} has a value in "${i}" (${JSON.stringify(l)}) that contradicts its declared type "${s.type}". The schema owns the data type; either fix the value or declare the type the data actually has.`);continue}const u=s.domain;if(!u||s.open)continue;const c=a.find(d=>r5(d,s.type,u));c!==void 0&&ge(`schema:domain:${i}`,`${n} has a value in "${i}" (${JSON.stringify(c)}) outside its declared domain ${JSON.stringify(s.domain)}. The domain is what the axis spans, so that row draws clipped or off-plot. Widen the domain or fix the data.`)}}function jc(e,t,n="data"){const r=Object.keys(e.tables);for(const o of r){const i=r.length>1?`${n}.${o}`:n;o5(e.tables[o].fields,t[o]||[],i),s5(e,t,o,i),e.tables[o].role==="links"&&i5(e,t,o,i)}}function i5(e,t,n,r){const o=e.tables[n];if(o.multi!==!1&&o.selfLoops!==!1)return;const i=Object.keys(o.fields).filter(u=>o.fields[u]&&o.fields[u].type==="ref");if(i.length<2)return;const[s,a]=i,l=new Set;for(const u of t[n]||[]){if(!u)continue;const c=u[s],d=u[a];if(o.selfLoops===!1&&c!=null&&c===d&&ge(`schema:selfLoops:${n}`,`${r} has a link from ${JSON.stringify(c)} to itself, but the "${n}" table declares selfLoops: false. Remove the row, or declare selfLoops: true.`),o.multi===!1){const f=o.directed===!1&&String(d)<String(c)?[d,c]:[c,d],p=JSON.stringify(f);l.has(p)&&ge(`schema:multi:${n}`,`${r} links ${JSON.stringify(c)} and ${JSON.stringify(d)} more than once, but the "${n}" table declares multi: false. Remove the duplicate, or declare multi: true.`),l.add(p)}}}function s5(e,t,n,r){const o=e.tables[n].fields,i=t[n]||[];if(i.length)for(const[s,a]of Object.entries(o)){if(!a||a.type!=="ref")continue;const l=Kf(e,a);if(!l){ge(`schema:ref:${n}:${s}`,`schema.${n}.${s} is a \`ref\` but its target cannot be resolved${a.to?` (to: ${JSON.stringify(a.to)})`:""}. A ref points at a table's \`key: true\` column — declare one, or name the column with \`to\`. Nothing references anything until then.`);continue}const u=new Set(p0(e,a,t)),c=al(i,s).find(d=>!u.has(d));c!==void 0&&ge(`schema:dangling:${n}:${s}`,`${r} has a value in "${s}" (${JSON.stringify(c)}) that names no row of "${l.table}" (its ${JSON.stringify(l.field)}). A \`ref\` must name an existing identity — a link to a node that isn't there connects nothing, and draws nothing.`)}}function Mp(e){return e==null?{}:typeof e=="function"?{instance:e}:typeof e=="string"?{type:e}:e}function Wc(e,t,n,r){const o=n.schema||{},i=n.schemaSpec||null,s=n.scales||{},a=m=>t&&(t[m.table]||t[n.schemaSpec?n.schemaSpec.primary:""])||[],l=m=>{const b=i&&i.tables[m.table];return b&&b.fields||o},u={},c=m=>u[m]||(u[m]={fields:[],fieldRefs:[],schemas:[],undeclared:[],values:[]}),d={},f={},p=(m,b)=>{const w=$t(m),x=w||uo(m,b&&b.field!=null?b.field:void 0);return(d[x]||(d[x]=new Set)).add(m),f[x]=w||m,x};for(const m of e){const b=WM(m),w=m.discreteScale||"band",x=new Set(m.rawChannels||[]);for(const[S,v]of Object.entries(b)){if(!v||v.scale===null||Gr(v)||x.has(S))continue;if(typeof v.fn=="function"&&v.field==null){(v.scale!==void 0||v.type!==void 0)&&ge(`fnopt:${S}`,`channel "${S}" is derived ({ fn }) — its result is used as-is in visual space, so its "${v.scale!==void 0?"scale":"type"}" is ignored. Drop it, or use a field channel if you want a scale.`);continue}for(const[_,T]of[["domain","the spec's schema"],["range","this channel's `scale`"]])v[_]!==void 0&&ge(`stray:${_}:${S}`,`channel "${S}" declares "${_}", which is ignored. Move it to ${T}: ${_==="range"?"scale: { range: [...] }":"schema: { <field>: { domain: [...] } }"}.`);const k=c(p(S,v));if(k.measure==null&&v.type!=null&&(k.measure=v.type),k.scaleOpt==null&&v.scale!=null&&(k.scaleOpt=v.scale),k.discretePref!=="band"&&(k.discretePref=w),k.countAxis==null&&m.countAxis&&(k.countAxis=m.countAxis),v.field!=null){k.fields.includes(v.field)||k.fields.push(v.field);const _=m.table;_!=null&&!k.fieldRefs.some(L=>L.table===_&&L.field===v.field)&&k.fieldRefs.push({table:_,field:v.field});const T=l(m)[v.field];T&&T.type==="ref"&&i?k.schemas.push({type:"categorical",domain:p0(i,T,t),open:!0}):T?k.schemas.push(T):k.undeclared.includes(v.field)||k.undeclared.push(v.field);for(const L of a(m))k.values.push(L[v.field])}else v.datum!==void 0&&k.values.push(v.datum)}}const h={},y={},g={};for(const m of Object.keys(u)){const b=f[m]||m;y[m]=g[b]||0,g[b]=y[m]+1}for(const[m,b]of Object.entries(u)){const w=f[m]||m,x=b.values.some($=>$!=null);if(!b.fields.length&&!x)continue;const S=b.schemas;for(const $ of b.undeclared)ge(`schema:${$}:${w}`,`field "${$}" is encoded on channel "${w}" but not declared in schema; inferring its type and domain from data. Declare it in the Elicit spec's schema — the schema is the contract of the elicited dataset.`);if(!S.length&&!x)throw new Error(`[elicit] cannot resolve a scale for channel "${w}": field(s) ${b.fields.map($=>`"${$}"`).join(", ")} have no schema entry and there is no data to infer from. Declare them in the Elicit spec's schema.`);const v={...Mp(b.scaleOpt),...Mp(s[w])},k=S.map($=>$.type).filter(Boolean);new Set(k).size>1&&ge(`measure:${w}`,`fields ${b.fields.map($=>`"${$}"`).join(", ")} share channel "${w}" but declare different schema types (${[...new Set(k)].join(", ")}). Using "${k[0]}".`);const _=b.measure||k[0]||qf(b.values),T=v.type||PM(w,_,b.discretePref||"band"),L=[];for(const $ of S)$.domain&&L.push($.domain);const N=zM(_,L)||c0(T,b.values),I=!!$t(w);let O=v.range||Ai(v.scheme,T,N.length)||u0(w,T,r,n.theme,{measure:_,index:y[m]||0,count:N.length,countAxis:b.countAxis});v.reverse&&Array.isArray(O)&&(O=[...O].reverse());const M=v.instance?EM(v.instance,{range:v.range?void 0:O,positional:I,domain:N}):ju({...v,type:T,domain:N},O);if(M){M.fields=b.fields,M.fieldRefs=b.fieldRefs,h[m]=M;for(const $ of d[m]||[])h[$]===void 0&&(h[$]=M)}}if(h.count===void 0){const m=e.find(b=>b&&b.countAxis&&b.countPitch>0);if(m){const b=m.countAxis==="x"?r.width:r.height,w=Math.max(1,Math.floor(b/m.countPitch)),x=w*m.countPitch,S=ju({type:"linear",domain:[0,w]},m.countAxis==="x"?[0,x]:[r.height,r.height-x]);S&&(h.count=S)}}return h}const a5={"albers-usa":()=>PS(),albers:()=>mm(),"azimuthal-equal-area":()=>zS(),"azimuthal-equidistant":()=>DS(),"conic-conformal":()=>qS(),"conic-equal-area":()=>Qa(),"conic-equidistant":()=>US(),"equal-earth":()=>YS(),equirectangular:()=>BS(),gnomonic:()=>GS(),mercator:()=>jS(),orthographic:()=>XS(),stereographic:()=>JS(),"transverse-mercator":()=>ZS(),identity:()=>VS()};function l5(e){if(typeof e=="function"&&typeof e.stream!="function")return e();if(typeof e=="string"){const t=e.toLowerCase(),n=a5[t];if(!n)throw new Error(`[elicit] unknown projection type: ${e}`);return n()}return e}const Ep=new WeakSet;function c5(e){if(!oi()||!e||typeof e!="object"||Ep.has(e))return;Ep.add(e);const n=(e.type==="FeatureCollection"&&Array.isArray(e.features)?e.features:[e]).filter(o=>{const i=o&&o.type==="Feature"?o.geometry:o;return!i||i.type!=="Polygon"&&i.type!=="MultiPolygon"?!1:iS(i)>Math.PI});if(!n.length)return;const r=n.map((o,i)=>o.properties&&(o.properties.name||o.properties.NAME)||`feature ${i}`).slice(0,3);ge(`rings:${r.join(",")}`,`projection domain has ${n.length} polygon(s) with reversed ring winding (${r.join(", ")}${n.length>3?", …":""}). d3 reads these as covering the whole globe, so the map fits the world and your features shrink to a dot. Rewind the exterior rings counterclockwise (RFC 7946).`)}function na(e){const t=ES(e),n=typeof e.invert=="function";return{apply(r){if(!r||r[0]==null||r[1]==null)return null;const o=e(r);return!o||o[0]==null||o[1]==null||!Number.isFinite(o[0])||!Number.isFinite(o[1])?null:o},invert(r){if(!n||!r||r[0]==null||r[1]==null)return null;const o=e.invert(r);return!o||o[0]==null||o[1]==null||!Number.isFinite(o[0])||!Number.isFinite(o[1])?null:o},path(r){return r==null?null:t(r)},invertible:n,raw:e}}function m0(e,t){if(e==null)return null;if(typeof e=="object"&&typeof e.apply=="function"&&typeof e.invert=="function"&&e.raw)return e;if(typeof e=="function"&&typeof e.stream=="function"||typeof e=="object"&&typeof e.stream=="function")return na(e);let n={},r=e,o,i=0,s,a,l,u;if(typeof e=="object"&&e!==null){if({type:r,domain:o,inset:i=0,insetTop:s=i,insetRight:a=i,insetBottom:l=i,insetLeft:u=i,...n}={type:void 0,domain:void 0,...e},r==null&&typeof e.stream=="function")return na(e);if(r==null)return null}else s=a=l=u=0;const c=l5(r),{rotate:d,parallels:f,precision:p=.15,clipAngle:h}=n;p!=null&&typeof c.precision=="function"&&c.precision(p),d!=null&&typeof c.rotate=="function"&&c.rotate(d),f!=null&&typeof c.parallels=="function"&&c.parallels(f),h!=null&&typeof c.clipAngle=="function"&&c.clipAngle(h);const y=Math.max(0,t.width-(u||0)-(a||0)),g=Math.max(0,t.height-(s||0)-(l||0));if(o!=null&&typeof c.fitExtent=="function")c5(o),c.fitExtent([[u||0,s||0],[(u||0)+y,(s||0)+g]],o);else if(typeof c.fitSize=="function"){try{c.fitSize([y,g],{type:"Sphere"})}catch{}if(u||s){const m=c.translate();c.translate([m[0]+(u||0),m[1]+(s||0)])}}return na(c)}function ur(e,t,n){if(!e||t==null||n==null)return null;const r=e.apply([+t,+n]);return r?{x:r[0],y:r[1]}:null}function Fr(e,t){if(!e||!t)return null;const n=e.invert([t.x,t.y]);return n?{lon:n[0],lat:n[1]}:null}function b0(e,t,n,r,o){if(!e)return null;const i=[ur(e,t,n),ur(e,t,o),ur(e,r,n),ur(e,r,o)];if(i.some(f=>!f))return null;const s=i.map(f=>f.x),a=i.map(f=>f.y),l=Math.min(...s),u=Math.max(...s),c=Math.min(...a),d=Math.max(...a);return{x:l,y:c,width:u-l,height:d-c}}const w0=["channels","id","edits","table"],x0=["fill","stroke","strokeWidth","opacity","fillOpacity","strokeOpacity","size","symbol","text","fontSize","textAnchor","lineAnchor","dx","dy","angle"],v0=["id","edit","edits","field","table"],k0=["id"],st={arc:["outerRadius","innerRadius","padAngle","arc","start","end","handles","handleSize","handleColor"],area:["orientation","curve","handles","handleSize","handleColor","connect"],bar:["orientation","stack","handles","handleSize","handleColor"],composite:["parts","discreteScale"],curve:["orientation","length"],dotStack:["orientation","gap","ghost","label"],ellipse:[],face:["ink"],geoBasemap:["geojson","stroke","strokeWidth","fill"],geoTile:["url","subdomains","tileSize","minZoom","maxZoom","zoomOffset","attribution","attributionSize","opacity"],geoPoint:[],geoPolygon:[],geoLine:["curve","handles","handleSize","handleColor","connect","showVertices"],geoText:["format"],geoRect:[],line:["orientation","curve","handles","handleSize","handleColor","connect"],link:["curve","curvature","spread","arrow","arrowSize","inset","sourceInset","targetInset","loopRadius","format","labelBackground","labelPadding","labelRadius","labelOpacity","cornerRadius","sourceSide","targetSide","sourceOffset","targetOffset","handles","handleSize","handleColor"],needle:["length","handles","handleSize","handleColor","baseWidth"],node:["dy","shape","format"],point:["shape"],rect:["orientation","width","height","rx"],rule:["orientation","strokeDasharray","discreteScale"],sticker:["padding","radius","maxWidth","minWidth","minHeight","lineHeight","fontFamily","format"],text:["orientation","format","wrap","lineHeight"],tick:["orientation","inset","length"],trend:["anchor","probe","grip","handles","handleSize","handleColor"],trendBand:["render","levels","samples","seed","sigma","distribution","anchor","probe","grip","handles","handleSize","handleColor"],waffle:["orientation","unit","multiple","gap","shape","showEmpty","emptyFill"]},As={axis:["channel","anchor","transform","ticks","tickValues","tickFormat","tickSize","title","stroke","fill","fontSize","grid","handleColor","handleSize"],grid:["channel","ticks","tickValues","stroke","strokeWidth"],legend:["channel","anchor","orient","swatchSize","gap","labelWidth","rampLength","rampThickness","ticks","tickFormat","title","row","stroke","fill","fontSize","handleColor","handleSize"],axisRadial:["channel","channels","radius","innerRadius","bandWidth","ticks","tickValues","tickFormat","tickSize","labelOffset","bands","title","arc","orient","start","end","labelFill","stroke","strokeWidth","fontSize"]},Ts={rule:["x","y","stroke","strokeDasharray","strokeWidth","opacity","label"],region:["x","y","fill","opacity","stroke","label"],remaining:["field","total","unit","format","anchor","label","fill","fontSize"],proximity:["target","stroke","strokeDasharray","strokeWidth","opacity"],prompt:["y"],optionRings:["labelOffset","radius"],cellGrid:["pad"],sliderTrack:["format"],crosshair:["x","y"],custom:[]},S0=["type","name","gesture","channel","channels","when","pick","threshold","scope","into","constrain","guide","stage","advance","target","cardinality","inverts","table","inline","multiline","defaults","apply","targets"],$0={move:["mode"],moveSpan:[],brushSpan:["edgeInset"],brushRect:["edgeInset","resize","move"],slide:["axis","increase","extent","mode"],resize:[],rotate:["relativeTo","pivot","fold"],cycle:[],create:[],toggle:[],remove:[],set:[],editText:[],rank:[],select:["exclusive","toggle","multi"],custom:[],"line.anchor":["series"],"line.newSeries":["along","value","samples","series"],"line.draw":["along","value","samples","minDist","series"],"line.sweep":["mode"],"line.removeSeries":["series"],"axis.scale":["field","mode"],"scale.addCategory":["field","mode"],"scale.renameCategory":["field","mode"],"scale.removeCategory":["field","mode"],"legend.category":[],"legend.value":[],"stack.cut":["label","categoryField"],"stack.edge":[],"stack.merge":[],"trend.intercept":["anchor","probe"],"trend.slope":["anchor","probe"],"trend.interceptSpread":["anchor","probe"],"trend.slopeSpread":["anchor","probe"],"waffle.fill":[],"network.connect":[],"network.rewire":[],"network.reverse":[],"geo.move":[],"geo.create":[],"geo.dragVertex":[],"geo.removeVertex":["min"],"geo.draw":["minDist"],"geo.brush":["move","edgeInset"],"geo.createRect":["width","height","edgeInset"]},_0={clamp:["min","max","field"],snap:["step","origin","field"],count:["max","strategy"],unique:["field","max","strategy"],maintainSum:["total","field","strategy"],ordering:["field","strategy"],monotonic:["field","along","dir","series"],spacing:["field","min","series"],custom:[]};function u5(e,t,n){if(!(!e||!t||!n))for(const r of Object.keys(n)){const o=n[r];if(!o||o.field!==e)continue;const i=t[uo(r,e)]||t[r];if(i){if(i.domainConfig)return i.domainConfig;if(typeof i.domain=="function")return i.domain()}}}const f5={targetSum:"the total is `total` — maintainSum({ total: 100 }) — the same word guides.remaining uses.",fields:'the columns a rule is about are `field`, singular, which takes one name or an ordered list: ordering({ field: ["lo", "mean", "hi"] }).',lower:'ordering takes its columns as one ordered list: ordering({ field: ["lo", "hi"] }).',upper:'ordering takes its columns as one ordered list: ordering({ field: ["lo", "hi"] }).',mode:"what a constraint does when its rule is broken is `strategy` (cap | normalize | redistribute | push | block | reject | replace)."};function Rr(e,t){if(!t||!oi())return t;const n=_0[e]||[];for(const r of Object.keys(t)){if(n.includes(r))continue;const o=f5[r];ge(`constraintopt:${e}:${r}`,o?`${e}({ ${r}: … }): ${o}`:`${e}({ ${r}: … }) is not an option this constraint reads, so it is ignored. ${e} options are: ${n.slice().sort().join(", ")}.`)}return t}function d5(e){return{type:e.type,field:e.field,options:e.options||{},...e.table!=null?{table:e.table}:{},...typeof e.guide=="function"?{guide:e.guide}:{},apply:e.apply}}function Vt(e,t={}){return d5({...t,type:t.type||"custom",apply:e})}function h5(e,t,n,r){if(typeof e=="function")return e(t,n,r||{});const o=e;r=r||{};const i=Array.isArray(o.field)?o.field[0]:o.field,s=i??r.field,a=r.activeIndex!=null?r.activeIndex:null,l=a!=null&&a>=0&&a<t.length,u=l?t[a]:void 0,c={data:t,oldData:n,activeIndex:a,active:u,field:s,fields:Array.isArray(o.field)?o.field:s!=null?[s]:[],value:u&&s!=null?u[s]:void 0,domain:u5(s,r.scales,r.markChannels),table:r.table,tables:r.tables},d=o.apply(c);return d===!1||d===!0||d===void 0||Array.isArray(d)?d:typeof d=="number"?!l||s==null?t:t.map((f,p)=>p===a?{...f,[s]:d}:f):d&&typeof d=="object"&&l?t.map((f,p)=>p===a?{...f,...d}:f):t}function ll(e){return e==null||typeof e!="object"?JSON.stringify(e)||"null":JSON.stringify(Object.keys(e).sort().map(t=>[t,e[t]]))}const p5=(e,t)=>e===t||e!=null&&t!=null&&ll(e)===ll(t);function y5(e,t,n){return e==null||e===!1?null:typeof e=="function"?(r,o)=>!!e(r,o,n):e===!0||e==="seed"?(r,o)=>o<t():(console.warn(`[elicit] spec.lock: expected "seed", true, or a (datum, index) => boolean predicate; got ${JSON.stringify(e)}. Nothing is locked.`),null)}function g5(e){return Vt(({data:t,oldData:n})=>{if(!n||!n.length)return;if(t.length<n.length){const o=new Map;if(n.forEach((i,s)=>{if(!e(i,s))return;const a=ll(i);o.set(a,(o.get(a)||0)+1)}),!o.size)return;for(const i of t){const s=ll(i),a=o.get(s);a&&(a===1?o.delete(s):o.set(s,a-1))}return o.size===0?void 0:!1}let r=null;for(let o=0;o<n.length;o++){const i=n[o];e(i,o)&&(p5(t[o],i)||(r=r||t.slice(),r[o]=i))}return r||void 0},{type:"lock"})}function m5(e,t,n,r){if(e.index!=null){const s=n[e.index];return s!=null&&r(s,e.index)}if(e.series===void 0)return!1;const o=t.seriesKey||null;let i=!1;for(let s=0;s<n.length;s++){const a=n[s];if(!(o&&a[o]!==e.series)&&(i=!0,!r(a,s)))return!1}return i}function b5(e){return!!(e&&typeof e=="object"&&typeof e.apply=="function"&&e.gesture)}function va(e){const t=[],n=e.channels||{};for(const[r,o]of Object.entries(n))if(o&&o.edit){if(typeof o.fn=="function"&&o.field==null)continue;const i=o.edit;t.push(i.channels?i:{...i,channels:[r]})}for(const r of e.edits||[])t.push(r);return t}function w5(e,t){const n=e.channels||{},r=t?t(e):`"${e.id||"?"}"`,o=e.id||e.type||"?";for(const[i,s]of Object.entries(n)){const a=`${o}:${i}`;i==="edit"||b5(s)?ge(a,`mark ${r} has a misplaced edit under channels.${i}. Attach edits on a channel (y: { field, edit: move() }) or at mark level (edits: [move({ channels: ['x','y'] })]). A bare channels.edit key is ignored.`):s&&s.edit&&typeof s.fn=="function"&&s.field==null?ge(a,`mark ${r} puts an edit on the derived channel "${i}" ({ fn }). A derived channel is read-only — it recomputes from the committed rows on every render, so the edit is ignored. Attach the edit to the source field's channel (e.g. x: { field: "x", edit: move() }); the fn re-derives automatically after each commit.`):s&&s.edit&&s.field==null&&typeof s.fn!="function"&&ge(`${a}:nofield`,`mark ${r} puts an edit on channel "${i}", which has no field (it is a constant: ${s.value!==void 0?"{ value }":"{ datum }"}). An edit writes back to a COLUMN, so give the channel a field (${i}: { field: "…", edit: … }) — otherwise there is nothing to elicit.`)}}function Ti(e,t,n,r=void 0){const o=!!(r&&r.views==="scale"),i=r&&r.field!=null?r.field:void 0,s=o||!t||Object.keys(t).length===0,a=[];for(const l of e||[]){const u=t&&t[l];let c=u&&u.field;if(c==null&&s)if(i!=null)c=i;else{const f=n[l],p=f&&f.fields;c=p&&p[0]}if(c==null)continue;const d=n[uo(l,c)]||n[l]||void 0;a.push({name:l,field:c,scale:d})}return a}const M0=Symbol("elicit.unverifiedOptions"),x5=e=>e==null?[]:Array.isArray(e)?e:[e],Vr=(e,t)=>n=>e(n)&&(typeof t=="function"?!!t(n):!0);function Kl(e,t,n){const{pick:r,...o}=e||{};return r!=null&&r!==n&&ge(`fixedpick:${t}`,`${t} is bound to the "${n}" driver — it reads a zone lock only that driver writes — so { pick: "${r}" } is ignored. Drop it, or use an edit that supports the strategy you want (move/moveSpan take any pick).`),o}function je(e){const{channel:t,channels:n,...r}=e,o=$0[e.type],i=o?Object.keys(r).filter(s=>!S0.includes(s)&&!o.includes(s)):[];return{...r,...i.length?{[M0]:i}:{},type:e.type,name:e.name||null,gesture:e.gesture||"drag",channels:t?[t]:n||null,when:e.when||null,pick:e.pick||"direct",threshold:e.threshold!=null?e.threshold:0,scope:e.scope||null,into:e.into||null,constrain:x5(e.constrain),guide:e.guide||null,stage:e.stage!=null?e.stage:null,advance:e.advance!==!1,target:e.target||void 0,cardinality:e.cardinality||null,inverts:!!e.inverts,apply:e.apply}}function cl(e,t){const n=e.when;return{...e,when:r=>{const o=r.node&&r.node.channel;return o!=null&&o!==t?!1:n?n(r):!0}}}function Yl(e,t){if(!t)return 0;const n=new Set((e||[]).map(o=>o[t]));let r=0;for(;n.has(r);)r++;return r}function Yf(e,t,n,{open:r=!1,label:o="Category"}={}){if(!t)return;const i=new Set((e||[]).map(a=>a[t]));for(const a of n||[])if(!i.has(a))return a;if(!r)return;let s=(n||[]).length+1;for(;i.has(`${o} ${s}`)||(n||[]).includes(`${o} ${s}`);)s++;return`${o} ${s}`}function Fn(e,{defaults:t={},seed:n={},label:r}={}){const o={...Es(e.schema),...t,...n};let i=Object.keys(n).length>0;for(const a of e.channels){const l=ho(a,e.pointer);l!==void 0&&(o[a.field]=l,i=!0)}if(!i)return;const s=v5(e.schema);if(s&&o[s]==null){const a=e.schema&&e.schema[s]||{},l=Yf(e.data,s,a.domain||[],{open:a.open!==!1,label:r||"Item"});if(l===void 0)return;o[s]=l}return o}function v5(e){if(!e)return null;for(const[t,n]of Object.entries(e))if(n&&n.key===!0)return t;return null}function Pr(e){return e.node?e.node:e.index==null||!e.marks?null:e.marks.find(t=>t&&t.index===e.index)||null}function Rn(e){return e?e.cx!=null&&e.cy!=null?{cx:e.cx,cy:e.cy}:e.x!=null&&e.width!=null?{cx:e.x+e.width/2,cy:e.y+(e.height||0)/2}:e.x1!=null&&e.y1!=null&&e.x2!=null&&e.y2!=null?{cx:(e.x1+e.x2)/2,cy:(e.y1+e.y2)/2}:e.x!=null&&e.y!=null?{cx:e.x,cy:e.y}:null:null}const k5=.01,S5=.1;function Hu(e,t,n,r=!1){if(!e||!n||!e.invertible)return t;if(e.kind==="band"||e.kind==="point"){const a=e.domain();if(a.length<2)return t;const l=e.invertValue(t),u=a.indexOf(l);if(u<0)return t;const c=e.encode(a[a.length-1])>e.encode(a[0]),d=u+(c?n:-n);return d<0||d>=a.length?t:e.encode(a[d])}const[o,i]=oo(e),s=(i-o)*(r?S5:k5);return Math.max(o,Math.min(i,t+n*s))}const xn=e=>e instanceof Date?e.getTime():e;function E0(e,t,n,r,o){if(n===t)return;let i=(e-t)/(n-t);return i=i<0?0:i>1?1:i,r+i*(o-r)}function A0(e){const t=e&&e.scale&&e.scale.domainConfig;return Array.isArray(t)&&t.length?[t[0],t[t.length-1]]:[0,1]}function T0(e,t){const n=e&&e.scale&&typeof e.scale.domain=="function"?e.scale.domain():null;if(Array.isArray(n)&&n.length)return n;const r=e&&e.field!=null&&t?t[e.field]:null,o=r&&r.domain;return Array.isArray(o)&&o.length?o:null}function ho(e,t,n=null){if(!e||!e.scale||!e.scale.invertible)return;const r=BM(e.name,t,n);if(r!==void 0)return e.scale.invertValue(r)}function Gl(e,t,n,r){if(!e||!t||!n||!t.scale||!n.scale||!t.scale.invertible||!n.scale.invertible)return;const o=$t(t.name);if(!o||o!==$t(n.name))return;const i=o==="x"?r.x:r.y,s=o==="x"?e.width:e.height;if(i===void 0||s==null)return;let a=i-s/2,l=i+s/2;const[u,c]=oo(t.scale),d=Math.min(u,c),f=Math.max(u,c),p=f-d;return s>=p?(a=d,l=f):(a<d&&(l+=d-a,a=d),l>f&&(a-=l-f,l=f)),{a:t.scale.invertValue(a),b:n.scale.invertValue(l)}}const O0=["filter","opacity","fill","stroke","strokeWidth","cursor"],$5=["hovered","selected","grabbed"],ul={hovered:{outline:{color:"#ff9800",width:2,pad:5,dash:null,opacity:.65}},selected:{outline:{color:"#ff9800",width:2.5,pad:5,dash:null,opacity:.95}},grabbed:{filter:"brightness(0.82)"}},_5={color:"#ff9800",dash:"2 4",width:1,opacity:.45};function M5(e,t){const n=t||{};if(e===!1)return{enabled:!1};if(typeof e=="string")return{...n,enabled:!0,filter:e};const r=e||{},o=r.outline===!1?null:n.outline||r.outline?{...n.outline,...r.outline||{}}:null;return{...n,...r,outline:o,enabled:!0}}function E5(e={},t=ul){const n=e||{},r=t||ul,o={};for(const i of $5)o[i]=M5(n[i],r[i]);return o}function Uu(e){if(!e||e.enabled===!1)return null;const t={};let n=!1;for(const r of O0)e[r]!=null&&(t[r]=e[r],n=!0);return n?t:null}function A5(e){const t={};let n=!1;for(const r of e||[]){const o=Uu(r);o&&(Object.assign(t,o),n=!0)}return n?t:null}function Gf(e,t){if(!e||!t||t.enabled===!1||!t.outline)return[];if(e.effectShape)return Gf({...e.effectShape,...e.angle?{angle:e.angle}:{}},t);const{color:n,width:r,pad:o,dash:i,opacity:s}=t.outline,a={fill:"none",stroke:n,strokeWidth:r,opacity:s,...i?{strokeDasharray:i}:{},...e.angle?{angle:e.angle}:{},guide:!0,effect:!0,pointerEvents:"none"};if(e.type==="circle")return[{type:"circle",cx:e.cx,cy:e.cy,r:(e.r||5)+o,...a}];if(e.type==="ellipse")return[{type:"ellipse",cx:e.cx,cy:e.cy,rx:(e.rx!=null?e.rx:5)+o,ry:(e.ry!=null?e.ry:5)+o,...a}];if(e.type==="rect")return[{type:"rect",x:e.x-o,y:e.y-o,width:e.width+o*2,height:e.height+o*2,...a}];if(e.type==="line"){const l=Math.min(e.x1,e.x2),u=Math.min(e.y1,e.y2);return[{type:"rect",x:l-o,y:u-o,width:Math.abs(e.x2-e.x1)+o*2,height:Math.abs(e.y2-e.y1)+o*2,...a}]}if(e.type==="path")return e.d?[{type:"path",d:e.d,...a}]:[];if(e.type==="text"){const l=(e.fontSize||12)*.9+o;return[{type:"circle",cx:e.x,cy:e.y,r:l,...a}]}return[]}function Ap(e,t,n){if(!n||n.enabled===!1||!n.outline)return[];const r=[];for(const o of t){if(o==null)continue;const i=(e||[]).find(s=>s&&s.index===o)||(e||[])[o];!i||i.ghost||r.push(...Gf(i,n))}return r}const Vf={ink:"steelblue",accent:"#2563eb",muted:"#9ca3af",handle:"#2563eb",handleStroke:"#fff",background:null,palette:ls,ramp:Ei,diverging:Wu,font:{family:null,size:10,labelSize:12,titleSize:13},axis:{stroke:"#6b7280",labelFill:"#374151",fontSize:10,handle:"#2563eb"},grid:{stroke:"#e5e7eb",strokeWidth:1},guide:{rule:{stroke:"#64748b",strokeDasharray:"5 4",strokeWidth:1,opacity:.9},region:{fill:"#64748b",opacity:.1},legend:{stroke:"#374151",labelFill:"#374151",fontSize:11,currentStroke:"#111827",currentWidth:2},bounds:{dash:"4 4",width:1,opacity:.9},catchment:{dash:"2 4",width:1,opacity:.45},track:{dash:"3 3",width:2,opacity:.35}},constraint:{color:"#e4572e"},effects:ul,ghost:{opacity:.45,fill:null,stroke:null,strokeDasharray:null},widget:{accent:"#2563eb",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#334155",question:"#0f172a",labelSize:12,questionSize:13,radius:11},marks:{}};function qc(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof Date)}function Ku(e,t){if(!qc(t))return t===void 0?e:t;const n={...e};for(const r of Object.keys(t)){const o=e?e[r]:void 0,i=t[r];n[r]=qc(o)&&qc(i)?Ku(o,i):i===void 0?o:i}return n}let C0={};function T5(e){C0=e||{}}function Xf(e){const t=Ku(Vf,C0);return e==null||typeof e=="string"?t:Ku(t,e)}function it(e){return e&&e.theme||Vf}function Nt(e,t,n){const r=it(e),o=r.marks&&r.marks[t]||{};return{...n,...o}}const N0={fill:void 0,stroke:void 0,strokeWidth:void 0,opacity:void 0,fillOpacity:void 0,strokeOpacity:void 0},I0=Object.keys(N0),L0=x0;function Vl(e,t,n,r,o,i){if(n==null)return i;try{const s=e.fn(n,r,o);return s??i}catch(s){return ge(`fn:${t}`,`fn on channel "${t}" threw: ${s instanceof Error?s.message:s}; using the fallback.`),i}}function se(e,t,n,r,o,i,s){const a=t[n];if(!a)return o;if(a.expr!==void 0&&ge(`expr:${n}`,`channel "${n}" uses { expr: … }, which is RESERVED for the planned JSON spec layer and is not implemented in 0.1. In JavaScript, write the derived form instead: { fn: (d, i, data) => … }.`),a.field===void 0){if(typeof a.fn=="function")return Vl(a,n,r,i,s,o);if(a.value!==void 0)return a.value;if(a.datum!==void 0){if(a.scale===null)return a.datum;const c=e[n];return c?c.encode(a.datum,o):o}return o}const l=r?r[a.field]:void 0;if(l==null)return o;if(a.scale===null)return l;const u=e[uo(n,a.field)]||e[n];return u?u.encode(l,o):o}const Jf={size:5};function fn(e,t,n={}){const{handles:r=!0,handleSize:o,handleColor:i}=t||{},s=it(e),a=r!==!1&&r!=="hit",l=r!==!1;return{visible:a,grabbable:l,size:o??Jf.size,fill:a?i||n.fill||s.handle||s.accent:l?"transparent":i||n.fill||s.handle||s.accent,stroke:a?n.stroke||s.handleStroke:"none",strokeWidth:a?1.25:0}}function Xt(e){const t=e||{};return{xKey:t.x&&t.x.field||"x",yKey:t.y&&t.y.field||"y"}}function kr(e,t,{orientation:n,extent:r="value",single:o="value"}={}){if(n==="horizontal")return"x";if(n==="vertical")return"y";const i=e||{},s=d=>d==="x"?"y":"x",a=!!(i.x1||i.x2),l=!!(i.y1||i.y2);if(a!==l){const d=a?"x":"y";return r==="span"?s(d):d}if(t){const d=Tp(t.x),f=Tp(t.y);if(d&&!f)return"y";if(f&&!d)return"x"}const u=!!i.x,c=!!i.y;if(u!==c){const d=u?"x":"y";return o==="value"?d:s(d)}return"y"}const Tp=e=>!!(e&&e.kind==="band"),Zf=e=>e==="x"?"horizontal":"vertical";function Nn(e,t,n,r,o,i){const s=e?e[t]:void 0,a=r??t;r==null&&n&&n[t]!==void 0&&ge(`implicitcol:${t}`,`a mark places rows on the "${t}" category axis but declares no "${t}" channel, so it is reading the column named "${t}" implicitly. Declare it — channels: { ${t}: { field: "${t}" } } — so the spec says which column the mark draws (and which one an edit would write).`);const l=n?n[a]:void 0;if(!s)return l;if(s.field===void 0)return typeof s.fn=="function"?Vl(s,t,n,o,i,l):s.datum!==void 0?s.datum:(s.value!==void 0&&ge(`catvalue:${t}`,`channel "${t}" is a CATEGORY axis on this mark, and { value: … } is a visual-space constant — there is no visual constant for "which band". Use { datum: … } to pin every row to one category, or { field: "…" } to read it from the data.`),l);const u=n?n[s.field]:void 0;return u??l}function Lt(e,t,n,r,o){if(r==null)return o;const i=t[n];if(i&&i.scale===null)return r;const s=e[n];return s?s.encode(r,o):o}function zr(e,t,n,r,o=0,i,s){if(!t||!t[n])return o;if(e[n])return se(e,t,n,r,o,i,s);const l=t[n];if(typeof l.fn=="function")return+Vl(l,n,r,i,s,o);if(l.field!=null){const u=r?r[l.field]:void 0;return u==null?o:+u}return l.value!==void 0?+l.value:o}function cs(e,t,n,r,o){if(!t||!t.symbol)return;const i=se(e,t,"symbol",n,void 0,r,o);return i==null||i===""?void 0:String(i)}function Xl(e,t,n,r,o={}){return{type:"text",x:t,y:n,text:e,fontSize:Math.max(1,r*2),textAnchor:"middle",dominantBaseline:"central",...o}}function yt(e,t,n,r={},o,i){const s={};for(const a of I0){const l=a in r?r[a]:N0[a],u=se(e,t,a,n,l,o,i);u!==void 0&&(s[a]=u)}return s}function Os(e={}){return e.series&&e.series.field||e.fill&&e.fill.field||e.stroke&&e.stroke.field||null}function pt(e,t,n,r,o,i){const s=e[t];if(!s)return r;if(s.field!=null){const a=n[s.field];return a??r}return typeof s.fn=="function"?Vl(s,t,n,o,i,r):s.value!==void 0?s.value:(s.datum!==void 0&&ge(`rawdatum:${t}`,`channel "${t}" on a text mark has no scale — its value IS the output — so { datum: … } has nothing to go through. Use { value: … } for a constant.`),r)}function Qf(e={}){return e.order&&e.order.field||null}const O5=w0;function lt(e){return{id:e.id,edits:e.edits,table:e.table}}const F0={color:"there is no `color` channel — use `fill` (or `stroke` for a line).",data:"a mark never owns data. Put `data` on the Elicit spec; the engine hands the rows to every mark.",onChange:"put `onChange` on the Elicit spec, not on a mark.",domain:"a domain describes the DATA, so it lives on the spec's schema: schema: { field: { domain: [...] } }.",range:"a range belongs to the scale: channels.<name>.scale = { range: [...] }.",scale:"a scale is per channel: channels.<name>.scale, or spec.scales for the whole chart.",channel:"did you mean `channels`? (Axis/grid/legend marks take a singular `channel`; data marks take a `channels` map.)",edit:'attach an edit to a channel — y: { field: "…", edit: move() } — or pass several with `edits: [...]`.',r:"the radius channel is `size` (px), on every mark.",handleRadius:"a sub-element's radius is `handleSize`.",order:'order is a CHANNEL — it names the column to sort by: channels: { order: { field: "…" } }. The MODE (sort by the domain axis, or connect in array order) is the `connect` option: connect: "domain" | "sequence".',series:'series is a CHANNEL — it names a column, and `channels` is the only place a mark names one: channels: { series: { field: "…" } }.',z:'the grouping channel is `series`: channels: { series: { field: "…" } }.',constraints:"a constraint is a DATASET invariant — it gates every edit from every mark, whichever one declared it — so writing it inside a mark says something the engine does not mean. Put it on the Elicit spec: constraints: [...].",value:"a constant belongs on a channel: channels.<name> = { value: … } for visual space, { datum: … } for data space.",field:'a field belongs on a channel: channels.<name> = { field: "…" }.',...C5()};function C5(){const e={};for(const t of["x","y","x1","x2","y1","y2","lon","lat"])e[t]=`positional channels are not top-level shorthands (only style names like fill/stroke/size are). For a constant in the field's own units, write channels: { ${t}: { datum: … } } — it goes THROUGH the scale, so it lands where that value is. For a column, channels: { ${t}: { field: "…" } }. And for a plain reference line, a guide is the mark-free way to say it: guides.rule({ ${t}: … }).`;return e}function N5(e,t,n){if(!t||!oi())return;const r=e||"this mark";e&&!n&&ge(`noallow:${e}`,`${r}() calls normalizeMarkOptions without an \`allow\` list, which turns off its unknown-option diagnostics. Declare the mark's own option vocabulary — see the "Adding a new mark" contract in CLAUDE.md.`);const o=n?new Set([...O5,...L0,...n]):null;for(const i of Object.keys(t)){const s=F0[i];if(s){if(o&&o.has(i))continue;ge(`opt:${r}:${i}`,`${r}({ ${i}: … }): ${s}`);continue}!o||o.has(i)||ge(`opt:${r}:${i}`,`${r}({ ${i}: … }) is not an option this mark reads, so it is ignored. Mark options are: ${[...o].sort().join(", ")}.`)}}function at(e={},{except:t=[],mark:n,allow:r}={}){N5(n,e,r);const{channels:o={},...i}=e,s={...o};for(const a of L0)i[a]===void 0||t.includes(a)||(s[a]===void 0&&(s[a]=typeof i[a]=="function"?{fn:i[a]}:{value:i[a]}),delete i[a]);return{...i,channels:s}}const I5=["stroke","strokeWidth","fill","fontSize"],L5=v0;function Cs(e,t,n){if(!t||!oi())return;const r=new Set([...L5,...n]);for(const o of Object.keys(t)){if(r.has(o))continue;const i=F0[o];if(i){ge(`opt:${e}:${o}`,`${e}({ ${o}: … }): ${i}`);continue}ge(`opt:${e}:${o}`,`${e}({ ${o}: … }) is not an option this chart element reads, so it is ignored. ${e} options are: ${[...r].sort().join(", ")}.`)}}function Wi(e,t){return[e&&e.edit,e&&e.edits].flat(1/0).filter(r=>r&&typeof r.apply=="function").map(r=>r.channels?r:{...r,channels:[t]})}const Yu=16,Oi=.4,R0=8,F5=30,R5=.25,P5=25e4,Et=["top","right","bottom","left"];function Op(e,t,n){let r=t[0],o=1/0;for(const i of t){const s=tn[i],a=Math.hypot(e.cx+s.x*e.hw-n.x,e.cy+s.y*e.hh-n.y);a<o&&(o=a,r=i)}return r}function z5(e,t,n,r,o){const i=e||Et,s=t||Et,a=(c,d)=>{if(d.includes(c))return c;const f=Et.indexOf(c),p=h=>{const y=Math.abs(Et.indexOf(h)-f);return Math.min(y,4-y)};return d.slice().sort((h,y)=>p(h)-p(y))[0]};if(n||r){const c=n||a(r,i);return{out:c,in:r||a(c,s),nest:o}}const l=Et.filter(c=>i.includes(c)&&s.includes(c));if(l.length){const c=l[o%l.length];return{out:c,in:c,nest:Math.floor(o/l.length)}}const u=i[0];return{out:u,in:a(u,s),nest:o}}const tn={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}},D5={top:"bottom",bottom:"top",left:"right",right:"left"};function j5(e,t,n){return Math.max(t,Math.min(n,e))}function P0(e){const t=[];for(const n of e){const r=t[t.length-1];r&&Math.abs(r[0]-n[0])<.01&&Math.abs(r[1]-n[1])<.01||t.push(n)}for(let n=t.length-2;n>=1;n--){const r=t[n-1],o=t[n],i=t[n+1],s=(o[0]-r[0])*(i[1]-r[1])-(o[1]-r[1])*(i[0]-r[0]),a=(o[0]-r[0])*(i[0]-o[0])+(o[1]-r[1])*(i[1]-o[1]);Math.abs(s)<.01&&a>0&&t.splice(n,1)}return t}function Go(e,t,n,r,o=Oi){const i=tn[t],s=i.x?e.hh:e.hw,a=j5(r,-o,o),l=a*s*2;return{side:t,offset:a,x:e.cx+i.x*(e.hw+n)+-i.y*l,y:e.cy+i.y*(e.hh+n)+i.x*l}}function Cp(e,t,n,r=0){const o=t.x-e.cx,i=t.y-e.cy,s=e.hw||1e-6,a=e.hh||1e-6;let l,u;if(Math.abs(o)*a>=Math.abs(i)*s){l=o>=0?"right":"left";const f=o===0?0:i*(s/Math.abs(o));u=l==="right"?f:-f}else{l=i>=0?"bottom":"top";const f=i===0?0:o*(a/Math.abs(i));u=l==="top"?f:-f}const d=(tn[l].x?a:s)*2;return Go(e,l,n,u/d+r,.5)}function W5(e,t,n,r,o,i){const s=tn[e.side],a=tn[t.side];if(s.x!==-a.x||s.y!==-a.y)return{a:e,b:t};if(!ka(e,t,s))return{a:e,b:t};const l=!!s.x,u=l?t.y-e.y:t.x-e.x;if(Math.abs(u)<.01)return{a:e,b:t};const c=Math.sign(u),d=(m,b,w)=>{const x=l?b.hh:b.hw,S=l?m.y-b.cy:m.x-b.cx;return Math.max(0,x-w*S)},f=o?Math.min(Yu,d(e,n,c)):0,p=i?Math.min(Yu,d(t,r,-c)):0,h=Math.min(Math.abs(u),f+p);if(!h)return{a:e,b:t};const y=h*f/(f+p)*c,g=h*c-y;return{a:l?{...e,y:e.y+y}:{...e,x:e.x+y},b:l?{...t,y:t.y-g}:{...t,x:t.x-g}}}function q5(e,t,n,r){const o=n.cx-n.hw-r,i=n.cx+n.hw+r,s=n.cy-n.hh-r,a=n.cy+n.hh+r,l=Math.min(e[0],t[0]),u=Math.max(e[0],t[0]),c=Math.min(e[1],t[1]),d=Math.max(e[1],t[1]);return l<i&&u>o&&c<a&&d>s}function Gu(e,t){return e===t||e.cx===t.cx&&e.cy===t.cy&&e.hw===t.hw&&e.hh===t.hh}function B5(e,t,n,r){let o=0;const i=e.length-2;for(let s=0;s<=i;s++)for(const a of r)s===0&&Gu(a,t)||s===i&&Gu(a,n)||q5(e[s],e[s+1],a,R0)&&o++;return o}function ka(e,t,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y>=0}function H5(e,t,n,r,o,i,s,a,l){const u=[e.x,e.y],c=[t.x,t.y],d=[n.x,n.y],f=[r.x,r.y];if(o.x===-i.x&&o.y===-i.y){if(ka(e,r,o)){if(o.x){const S=(e.x+r.x)/2;return[u,[S,e.y],[S,r.y],f]}const x=(e.y+r.y)/2;return[u,[e.x,x],[r.x,x],f]}if(o.x){const x=Math.min(s.cy-s.hh,a.cy-a.hh)-l,S=Math.max(s.cy+s.hh,a.cy+a.hh)+l,v=_=>Math.abs(_-t.y)+Math.abs(_-n.y),k=v(x)<=v(S)?x:S;return[u,c,[t.x,k],[n.x,k],d,f]}const g=Math.min(s.cx-s.hw,a.cx-a.hw)-l,m=Math.max(s.cx+s.hw,a.cx+a.hw)+l,b=x=>Math.abs(x-t.x)+Math.abs(x-n.x),w=b(g)<=b(m)?g:m;return[u,c,[w,t.y],[w,n.y],d,f]}if(o.x===i.x&&o.y===i.y){if(o.x){const m=o.x>0?Math.max(t.x,n.x):Math.min(t.x,n.x);return[u,c,[m,t.y],[m,n.y],d,f]}const g=o.y>0?Math.max(t.y,n.y):Math.min(t.y,n.y);return[u,c,[t.x,g],[n.x,g],d,f]}const p=o.x?{x:n.x,y:t.y}:{x:t.x,y:n.y},h={x:-i.x,y:-i.y};if(ka(t,p,o)&&ka(p,n,h))return[u,c,[p.x,p.y],d,f];const y=o.x?{x:t.x,y:n.y}:{x:n.x,y:t.y};return[u,c,[y.x,y.y],d,f]}function z0(e,t,n,r,o,i){const s=+t.offset||0,a=+o.offset||0,l=t.side?Go(e,t.side,n,s):null,u=o.side?Go(r,o.side,i,a):null,c=l||Cp(e,u||{x:r.cx,y:r.cy},n,s),d=u||Cp(r,l||{x:e.cx,y:e.cy},i,a);return{a:c,b:d}}function U5(e){const t=e.source.box,n=e.target.box;if(t.cx===n.cx&&t.cy===n.cy)return null;const r=e.sourceGap||0,o=e.targetGap||0,i=Math.max(Yu,r,o),s=e.obstacles||[],a=z0(t,e.source.port,r,n,e.target.port,o),{a:l,b:u}=W5(a.a,a.b,t,n,!e.source.port.side,!e.target.port.side),c=tn[l.side],d=tn[u.side],f={x:l.x+c.x*i,y:l.y+c.y*i},p={x:u.x+d.x*i,y:u.y+d.y*i},h=P0(H5(l,f,p,u,c,d,t,n,i)),y=B5(h,t,n,s),g={points:h,sourceSide:l.side,targetSide:u.side,crossings:y};if(y&&e.grid){const m=G5(e.grid,t,n,l,u,i);if(m)return m}return g}function Np(e){const t=[...e].sort((o,i)=>o-i),n=[];for(const o of t)(!n.length||o-n[n.length-1]>.5)&&n.push(o);const r=[];for(let o=0;o<n.length;o++)o&&r.push((n[o-1]+n[o])/2),r.push(n[o]);return r}function K5(e,t=R0){const n=[],r=[];for(const o of e)n.push(o.cx-o.hw-t,o.cx+o.hw+t),r.push(o.cy-o.hh-t,o.cy+o.hh+t);return{xs:Np(n),ys:Np(r),boxes:e,margin:t}}function Ip(e,t){const n=[...e];for(const r of t){let o=0,i=n.length;for(;o<i;){const s=o+i>>1;n[s]<r?o=s+1:i=s}Math.abs((n[o]??1/0)-r)<.01||o>0&&Math.abs(n[o-1]-r)<.01||n.splice(o,0,r)}return n}function ra(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=n+r>>1,i=e[o]-t;if(Math.abs(i)<.01)return o;i<0?n=o+1:r=o-1}return-1}class Y5{constructor(){this.a=[]}get size(){return this.a.length}push(t,n){const r=this.a;r.push([t,n]);let o=r.length-1;for(;o>0;){const i=o-1>>1;if(r[i][0]<=r[o][0])break;[r[o],r[i]]=[r[i],r[o]],o=i}}pop(){const t=this.a,n=t[0],r=t.pop();if(t.length){t[0]=r;let o=0;for(;;){const i=2*o+1,s=i+1;let a=o;if(i<t.length&&t[i][0]<t[a][0]&&(a=i),s<t.length&&t[s][0]<t[a][0]&&(a=s),a===o)break;[t[o],t[a]]=[t[a],t[o]],o=a}}return n}}const Lp=[[0,-1],[1,0],[0,1],[-1,0]];function G5(e,t,n,r,o,i){const s=tn[r.side],a=tn[o.side],l={x:r.x,y:r.y},u={x:o.x,y:o.y},c=Ip(e.xs,[l.x,u.x,r.x+s.x*i,o.x+a.x*i]),d=Ip(e.ys,[l.y,u.y,r.y+s.y*i,o.y+a.y*i]),f=c.length,p=d.length;if(f*p>P5)return null;const h=e.margin-.5,y=e.boxes,g=new Int8Array(f*p).fill(-1),m=(z,j)=>{const G=j*f+z;if(g[G]>=0)return g[G];const J=c[z],re=d[j];let Q=0;for(const ve of y){const Ce=Math.abs(J-ve.cx)-ve.hw,le=Math.abs(re-ve.cy)-ve.hh;if(Ce<h&&le<h){Q=1;break}Ce<=e.margin+.5&&le<=e.margin+.5&&(Q=2)}return g[G]=Q,Q},b=ra(c,l.x),w=ra(d,l.y),x=ra(c,u.x),S=ra(d,u.y);if(b<0||w<0||x<0||S<0)return null;const v=(z,j)=>y.some(G=>!Gu(G,j)&&Math.abs(z.x-G.cx)-G.hw<h&&Math.abs(z.y-G.cy)-G.hh<h);if(v(l,t)||v(u,n))return null;const k=Et.indexOf(D5[o.side]),_=f*p*4,T=new Float64Array(_).fill(1/0),L=new Int32Array(_).fill(-1),N=new Y5,I=(z,j)=>Math.abs(c[z]-c[x])+Math.abs(d[j]-d[S]),O=(w*f+b)*4+Et.indexOf(r.side);T[O]=0,N.push(I(b,w),O);let M=1/0,$=-1;for(;N.size;){const[z,j]=N.pop();if(z>=M)break;const G=j&3,J=j>>2,re=J%f,Q=(J-re)/f,ve=T[j];if(!(z>ve+I(re,Q)+1e-9)){re===x&&Q===S&&G===k&&ve<M&&(M=ve,$=j);for(let Ce=0;Ce<4;Ce++){if(j===O&&Ce!==G)continue;const le=re+Lp[Ce][0],me=Q+Lp[Ce][1];if(le<0||me<0||le>=f||me>=p)continue;const ce=le===x&&me===S?0:m(le,me);if(ce===1)continue;const Y=Math.abs(c[le]-c[re])+Math.abs(d[me]-d[Q]),fe=ve+Y*(ce===2?1+R5:1)+(Ce===G?0:F5),ie=(me*f+le)*4+Ce;fe<T[ie]&&(T[ie]=fe,L[ie]=j,N.push(fe+I(le,me),ie))}}}if($<0)return null;const F=[];for(let z=$;z>=0;z=L[z]){const j=z>>2,G=j%f;F.push([c[G],d[(j-G)/f]])}return F.reverse(),{points:P0(F),sourceSide:r.side,targetSide:o.side,crossings:0}}function D0(e,t){if(e==null||e===!1)return null;const n={},r=(o,i)=>(o===!0?Et:Array.isArray(o)?o:o==null?[]:[o]).filter(a=>Et.includes(a)?!0:(ge(`ports:side:${a}`,`ports got ${JSON.stringify(a)}${i}, which is not an edge. Use any of ${Et.map(l=>`"${l}"`).join(", ")}. Skipping it.`),!1));if(e===!0||typeof e=="string"||Array.isArray(e))for(const o of r(e,""))n[o]="both";else if(typeof e=="object"){const o=r(e.out," in `out`"),i=r(e.in," in `in`");if(t===!1&&(e.out||e.in)){ge("ports:undirected","ports splits its sides into `out` and `in`, but the links table is declared directed: false, so a link has no direction to leave or enter by. Using every side listed, both ways. List them as one array instead.");for(const s of[...o,...i])n[s]="both"}else{for(const s of o)n[s]="out";for(const s of i)n[s]=n[s]==="out"?"both":"in"}}else return ge("ports:value",`ports got ${JSON.stringify(e)}. Use true, a side, a list of sides, or { out: [...], in: [...] }.`),null;return Object.keys(n).length?n:null}function ed(e,t,n){return`${e}\0${t}\0${n}`}function j0(e,t){return e?e==="both"||e===(t==="source"?"out":"in"):!1}function V5(e,t){const{edit:n,...r}=t||{},o={ports:r};return{id:`${e.id}/ports`,type:"port",table:e.table,...e.glyph?{glyph:e.glyph}:{},channels:o,edits:n?[n]:[],rawChannels:["ports"],discreteScale:"point",portHost:e,build:(i,s,a,l,u)=>{if(typeof e.nodeBox!="function")return[];const c=fn(s,{}),d=u&&u.schema?Ms(u.schema):void 0,f=[];return i.forEach((p,h)=>{if(!p)return;const y=D0(pt(o,"ports",p,!1,h,i),d);if(!y)return;const g=e.nodeBox(p,h,i,s,a,l);if(g)for(const m of Et){const b=y[m];if(!b)continue;const w=Go(g,m,0,0);f.push({type:"circle",cx:w.x,cy:w.y,r:c.size,fill:c.fill,stroke:c.stroke,strokeWidth:c.strokeWidth,channel:"port",side:m,portRole:b,onHover:!0,data:p,index:h})}}),f}}}const X5={name:"plane",sessionKeys:[],onEvent({event:e,edits:t,runEdit:n}){let r=!1;return t.filter(o=>o.gesture===e.type).forEach(o=>{n(o,null)&&(r=!0)}),r}};function us(e,t,n){const r=Vu(e,t,n);if(e.type==="circle"||e.type==="ellipse")return Math.hypot(r.x-e.cx,r.y-e.cy);if(e.type==="rect"){if(e.bandAxis==="y"){const s=e.y,a=e.y+e.height;return r.y<s?s-r.y:r.y>a?r.y-a:0}const o=e.x,i=e.x+e.width;return r.x<o?o-r.x:r.x>i?r.x-i:0}if(e.type==="line")return Fp(r.x,r.y,e.x1,e.y1,e.x2,e.y2);if(e.type==="path"){const o=e.points||[];let i=1/0;for(let s=1;s<o.length;s++){const a=Fp(r.x,r.y,o[s-1][0],o[s-1][1],o[s][0],o[s][1]);a<i&&(i=a)}return i}return 1/0}function Vu(e,t,n){if(!e.angle)return{x:t,y:n};const r=Rn(e);if(!r)return{x:t,y:n};const o=-e.angle*Math.PI/180,i=t-r.cx,s=n-r.cy,a=Math.cos(o),l=Math.sin(o);return{x:r.cx+i*a+s*l,y:r.cy-i*l+s*a}}function Fp(e,t,n,r,o,i){const s=o-n,a=i-r,l=s*s+a*a,u=l?Math.max(0,Math.min(1,((e-n)*s+(t-r)*a)/l)):0;return Math.hypot(e-(n+u*s),t-(r+u*a))}function In(e,t,n,r,o){let i=null,s=1/0;return(e||[]).forEach(a=>{if(a.index==null||a.locked||o!==void 0&&a.series!==o)return;const l=us(a,t,n);l<s&&(s=l,i=a.index)}),i!=null&&s<=r?i:null}function Ar(e,t,n,r){let o=null,i=1/0;return(e||[]).forEach(s=>{if(s.series===void 0||s.locked)return;let a;if(s.type==="path")a=us(s,t,n);else if(s.cx!=null)a=Math.hypot(t-s.cx,n-s.cy);else return;a<i&&(i=a,o=s.series)}),o!=null&&i<=r?o:null}function td(e,t,n,r,o,i){let s=null,a=1/0;return(e||[]).forEach((l,u)=>{if(l.locked||i!==void 0&&l.series!==i)return;const c=o==="x"?l.cx:l.cy;if(c==null)return;const d=Math.abs((o==="x"?t:n)-c);d<a&&(a=d,s=l.index!=null?l.index:u)}),s!=null&&a<=r?s:null}const wn=4,fl=12;function Ci(e){const t=e.width||0,n=e.height||0,r=Math.max(t,fl),o=Math.max(n,fl);return{x:e.x-(r-t)/2,y:e.y-(o-n)/2,w:r,h:o}}function Sa(e,t,n){const r=e||[];for(let o=r.length-1;o>=0;o--){const i=r[o];if(!(!i||!i.editable)&&!(i.locked||i.guide||i.background)&&i.pointerEvents!=="none"&&J5(i,t,n))return i}return null}function J5(e,t,n){if(e.type==="circle"){const r=e.r!=null?e.r:5;return us(e,t,n)<=r+wn}if(e.type==="ellipse"){const r=Vu(e,t,n),o=Math.max(1e-6,(e.rx!=null?e.rx:5)+wn),i=Math.max(1e-6,(e.ry!=null?e.ry:5)+wn);return Math.hypot((r.x-e.cx)/o,(r.y-e.cy)/i)<=1}if(e.type==="rect"){const r=Ci(e),o=Vu(e,t,n);return o.x>=r.x-wn&&o.x<=r.x+r.w+wn&&o.y>=r.y-wn&&o.y<=r.y+r.h+wn}if(e.sector){const{cx:r,cy:o,r0:i,r1:s,a0:a,a1:l}=e.sector,u=Math.hypot(t-r,n-o);if(u<Math.max(0,i)-wn||u>s+wn)return!1;const c=l-a,d=Math.sign(c)||1;return((Math.atan2(-(n-o),t-r)*180/Math.PI-a)*d%360+360)%360<=Math.abs(c)}if(e.type==="line"||e.type==="path"){const r=(e.strokeWidth||1)/2;return us(e,t,n)<=r+wn}return e.type==="text"?Math.hypot(t-e.x,n-e.y)<=(e.fontSize||10)+wn:!1}const Jl=40;function W0(e,t=Jl){return e&&e>0?e:t}function Zn(e,t=Jl){return W0(e?e.threshold:void 0,t)}const Z5=8;function Zl(e){const t=e.edgeInset;return t&&t>0?t:Z5}const Q5={name:"nearest",sessionKeys:["px","py","threshold","hoverIndex","activeIndex"],selects:!0,onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=Zn(t[0]);let s=!1;if(e.type==="hover"){const a=In(n,e.x,e.y,i);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:a}),s=!0}else if(e.type==="hoverout")r.clear(),s=!0;else if(e.type==="dragstart"){const a=In(n,e.x,e.y,i);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:a,activeIndex:a}),s=!0}else if(e.type==="dragend"){const a=r.get();a&&(a.activeIndex=null),s=!0}else{const a=r.get();a&&(a.px=e.x,a.py=e.y);const l=t.filter(u=>u.gesture===e.type);if(l.length>0){let u=a?a.activeIndex:null;u==null&&(u=In(n,e.x,e.y,i)),u!=null&&l.forEach(c=>{o(c,u)&&(s=!0)})}else a&&(s=!0)}return s}},eE={name:"sweep",sessionKeys:["px","py","threshold","hoverIndex","activeIndex","series"],selects:!0,onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=Zn(t[0]),s=t[0].channels||["y"],a=s.includes("x")&&s.includes("y"),u=(s[0]||"y")==="x"?"y":"x",c=f=>a?In(n,e.x,e.y,i,f):td(n,e.x,e.y,i,u,f);let d=!1;if(e.type==="hover"){const f=Ar(n,e.x,e.y,i),p=c(f??void 0);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:p,series:f}),d=!0}else if(e.type==="hoverout")r.clear(),d=!0;else if(e.type==="dragstart"){const f=Ar(n,e.x,e.y,i),p=c(f??void 0);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:p,activeIndex:p,series:f}),p!=null&&t.forEach(h=>{o(h,p)&&(d=!0)}),d=!0}else if(e.type==="dragend"){const f=r.get();f&&(f.activeIndex=null,f.series=null),d=!0}else if(e.type==="drag"){const f=r.get(),p=f&&f.series!=null?f.series:void 0,h=c(p);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:h,activeIndex:h}),h!=null&&t.forEach(y=>{o(y,h)&&(d=!0)}),d=!0}return d}},tE={name:"draw",sessionKeys:["mode","drawSeries","lastDomain","lastX","lastY","px","py"],onEvent({feature:e,event:t,edits:n,marks:r,data:o,session:i,runEdit:s}){const a=Zn(n[0]);let l=!1;if(t.type==="dragstart"){const u=n[0].into==="new"?null:Ar(r,t.x,t.y,a);if(u!=null)i.set({mode:"edit",drawSeries:u,px:t.x,py:t.y});else{const c=e.seriesKey||null,f=e.connect==="sequence"&&o.length>0&&n[0].into!=="new"?c?o[o.length-1][c]:0:Yl(o,c);i.set({mode:"draw",drawSeries:f,lastDomain:null,lastX:null,lastY:null,px:t.x,py:t.y})}n.forEach(c=>{s(c,null)&&(l=!0)}),l=!0}else if(t.type==="drag"){const u=i.get();u&&(u.px=t.x,u.py=t.y),n.forEach(c=>{s(c,null)&&(l=!0)}),l=!0}else t.type==="dragend"&&(i.clear(),l=!0);return l}};function nE(e,t,n,r,o,i,s){const a=e.channels||{},[l,u]=r,c=a[l],d=a[u];if(!c||!d||!n)return null;const f=$t(l);if(!f)return null;const p=se(t,a,l,n),h=se(t,a,u,n);if(p==null||h==null)return null;const y=Math.min(p,h),g=Math.max(p,h),m=p<=h?c.field:d.field,b=p<=h?d.field:c.field,w=f==="x"?o:i,x=Math.abs(w-y),S=Math.abs(w-g);return Math.min(x,S)<=s?x<=S?{zone:"edgeA",field:m}:{zone:"edgeB",field:b}:{zone:"body"}}const rE={name:"brush",options:["edgeInset"],sessionKeys:["px","py","threshold","hoverIndex","activeIndex","zone","field"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zn(l),c=Zl(l),d=l.channels||[];let f=!1;if(t.type==="hover"){const p=In(r,t.x,t.y,u);s.set({px:t.x,py:t.y,threshold:u,hoverIndex:p}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const p=In(r,t.x,t.y,u),h=p!=null?nE(e,i,o[p],d,t.x,t.y,c):null;s.set({px:t.x,py:t.y,threshold:u,hoverIndex:p,activeIndex:p,zone:h?h.zone:null,field:h?h.field:null}),f=!0}else if(t.type==="drag"){const p=s.get();p&&(p.px=t.x,p.py=t.y);const h=p?p.activeIndex:null;h!=null&&p&&p.zone&&a(l,h)&&(f=!0),f=!0}else if(t.type==="dragend"){const p=s.get(),h=p?p.activeIndex:null;h!=null&&p&&p.zone&&(p.zone="canonicalize",a(l,h)),p&&(p.activeIndex=null),f=!0}return f}};function Rp(e,t,n,r){const o=e.channels||{},i=o[r+"1"],s=o[r+"2"];if(!i||!s||!i.field||!s.field||!n)return null;const a=se(t,o,r+"1",n),l=se(t,o,r+"2",n);if(a==null||l==null)return null;const u=a<=l?i.field:s.field,c=a<=l?s.field:i.field;return{loField:u,hiField:c}}function Pp(e,t,n,r,o,i,s,a,l){const u=r.x,c=r.x+r.width,d=r.y,f=r.y+r.height,p=a==="both"||a==="x",h=a==="both"||a==="y",y=p?Rp(e,t,n,"x"):null,g=h?Rp(e,t,n,"y"):null;let m=null;if(y){const w=Math.abs(o-u),x=Math.abs(o-c);Math.min(w,x)<=s&&(m=w<=x?y.loField:y.hiField)}let b=null;if(g){const w=Math.abs(i-d),x=Math.abs(i-f);Math.min(w,x)<=s&&(b=w<=x?g.loField:g.hiField)}return m&&b?{zone:"corner",fields:[m,b]}:m?{zone:"edgeX",fields:[m]}:b?{zone:"edgeY",fields:[b]}:l?{zone:"body",fields:[]}:null}function zp(e,t,n,r){let o=null;return(e||[]).forEach(i=>{i.type!=="rect"||i.index==null||i.width==null||t>=i.x-r&&t<=i.x+i.width+r&&n>=i.y-r&&n<=i.y+i.height+r&&(o=i.index)}),o}function Dp(e){return e==="corner"?"nwse-resize":e==="edgeX"?"ew-resize":e==="edgeY"?"ns-resize":e==="body"?"move":"default"}const oE={name:"brushRect",options:["edgeInset","resize","move"],sessionKeys:["px","py","hoverIndex","activeIndex","zone","fields","cursor"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zl(l),c=l.resize||"both",d=l.move!==!1;let f=!1;if(t.type==="hover"){const p=zp(r,t.x,t.y,u),h=p!=null?r.find(g=>g.index===p):null,y=p!=null&&h?Pp(e,i,o[p],h,t.x,t.y,u,c,d):null;s.set({px:t.x,py:t.y,hoverIndex:p,cursor:Dp(y?y.zone:null)}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const p=zp(r,t.x,t.y,u),h=p!=null?r.find(g=>g.index===p):null,y=p!=null&&h?Pp(e,i,o[p],h,t.x,t.y,u,c,d):null;s.set({px:t.x,py:t.y,hoverIndex:p,activeIndex:p,zone:y?y.zone:null,fields:y?y.fields:null,cursor:Dp(y?y.zone:null)}),f=!0}else if(t.type==="drag"){const p=s.get();p&&(p.px=t.x,p.py=t.y);const h=p?p.activeIndex:null;h!=null&&p&&p.zone&&a(l,h)&&(f=!0),f=!0}else if(t.type==="dragend"){const p=s.get(),h=p?p.activeIndex:null;h!=null&&p&&p.zone&&(p.zone="canonicalize",a(l,h)),p&&(p.activeIndex=null,p.cursor="default"),f=!0}return f}};function iE(e,t,n,r){let o=null;return(e||[]).forEach(i=>{i.type!=="rect"||i.index==null||i.width==null||t>=i.x-r&&t<=i.x+i.width+r&&n>=i.y-r&&n<=i.y+i.height+r&&(o=i.index)}),o}function sE(e,t,n,r,o){const i=e.x,s=e.x+e.width,a=e.y,l=e.y+e.height,u=[],c=Math.abs(t-i),d=Math.abs(t-s);Math.min(c,d)<=r&&u.push(c<=d?"west":"east");const f=Math.abs(n-a),p=Math.abs(n-l);return Math.min(f,p)<=r&&u.push(f<=p?"north":"south"),u.length===2?{zone:"corner",edges:u}:u.length===1?{zone:"edge",edges:u}:o?{zone:"body",edges:[]}:null}function jp(e,t){return e==="corner"?t.includes("west")&&t.includes("north")||t.includes("east")&&t.includes("south")?"nwse-resize":"nesw-resize":e==="edge"?t[0]==="west"||t[0]==="east"?"ew-resize":"ns-resize":e==="body"?"move":"default"}function aE(e){const t=e&&e.channels||{};return{west:t.west&&t.west.field||"west",south:t.south&&t.south.field||"south",east:t.east&&t.east.field||"east",north:t.north&&t.north.field||"north"}}const lE={name:"geoBrush",options:["edgeInset","move"],sessionKeys:["px","py","hoverIndex","activeIndex","zone","edges","grab","box0","cursor"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zl(l),c=l.move!==!1,d=i.projection||null;let f=!1;const p=(h,y)=>{const g=iE(r,h,y,u);if(g==null)return{hit:null,zone:null};const m=r.find(b=>b.index===g&&b.type==="rect");return m?{hit:g,zone:sE(m,h,y,u,c)}:{hit:null,zone:null}};if(t.type==="hover"){const{hit:h,zone:y}=p(t.x,t.y);s.set({px:t.x,py:t.y,hoverIndex:h,cursor:jp(y?y.zone:null,y?y.edges:[])}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const{hit:h,zone:y}=p(t.x,t.y),g=h!=null?o[h]:null,m=Fr(d,{x:t.x,y:t.y}),b=aE(e);s.set({px:t.x,py:t.y,hoverIndex:h,activeIndex:y?h:null,zone:y?y.zone:null,edges:y?y.edges:null,grab:m,box0:g?{west:g[b.west],south:g[b.south],east:g[b.east],north:g[b.north]}:null,cursor:jp(y?y.zone:null,y?y.edges:[])}),f=!0}else if(t.type==="drag"){const h=s.get();h&&(h.px=t.x,h.py=t.y);const y=h?h.activeIndex:null;y!=null&&h&&h.zone&&a(l,y)&&(f=!0),f=!0}else if(t.type==="dragend"){const h=s.get(),y=h?h.activeIndex:null;y!=null&&h&&h.zone&&(h.zone="canonicalize",a(l,y)),h&&(h.activeIndex=null,h.zone=null,h.edges=null,h.grab=null,h.box0=null,h.cursor="default"),f=!0}return f}};function Wp(e,t){const{marks:n,data:r,event:o}=e;if(o.x!=null&&o.y!=null){const i=In(n,o.x,o.y,Zn(t));if(i!=null)return i}return r.length===1?0:null}const cE={name:"probe",sessionKeys:[],onEvent:e=>{const{event:t,edits:n,preview:r,stage:o,runEdit:i,previewEdit:s}=e;if(!n.length)return!1;const a=t.type;if(a==="hover"||a==="dragstart"||a==="drag"){let l=!1;for(const u of n)s(u,Wp(e,u))&&(l=!0);return l||r.clear()}if(a==="hoverout")return r.clear();if(a==="click"||a==="dragend"){let l=!1,u=!1;for(const c of n)i(c,Wp(e,c))&&(l=!0,c.stage!=null&&c.advance!==!1&&(u=!0));return u&&o.next(),l}return!1}},uE=14;function qp(e,t,n,r){let o=null,i=r;for(const s of e||[]){if(!s||!s.axisHandle)continue;const a=s.cx!=null?s.cx:s.x,l=s.cy!=null?s.cy:s.y,u=Math.hypot(t-a,n-l);u<=i&&(i=u,o=s)}return o}function fE(e){return{axis:e.axis,grabEnd:e.handle,anchorPixel:e.anchorPixel,anchorValue:e.anchorValue,grabPixel:e.grabPixel,grabValue:e.grabValue,pxPerUnit:e.pxPerUnit,cursor:e.axis==="x"?"ew-resize":"ns-resize"}}const dE={name:"axisDrag",sessionKeys:["axis","grabEnd","anchorPixel","anchorValue","grabPixel","grabValue","pxPerUnit","cursor"],onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=t[0],s=Zn(i,uE);let a=!1;if(e.type==="hover"){const l=qp(n,e.x,e.y,s),u=l?l.axis==="x"?"ew-resize":"ns-resize":null,c=r.get();(c&&c.cursor)!==u&&(r.set({cursor:u}),a=!0)}else if(e.type==="hoverout")r.clear(),a=!0;else if(e.type==="dragstart"){const l=qp(n,e.x,e.y,s);l&&(r.set(fE(l)),a=!0)}else if(e.type==="drag"){const l=r.get();l&&l.grabEnd&&o(i,null)&&(a=!0)}else e.type==="dragend"&&(r.clear(),a=!0);return a}};function Xn(e={}){const{mode:t="absolute",...n}=e,r=t==="relative";return r&&n.pick!=null&&n.pick!=="direct"&&ge("move:relative:pick",`move({ mode: "relative" }) is direct-pick: it measures from where you GRABBED the mark, so there has to be a mark under the press. { pick: "${n.pick}" } is ignored. Use the default mode: "absolute" with that pick.`),je({type:"move",inverts:!0,gesture:"drag",mode:t,...n,...r?{pick:"direct"}:{},apply:o=>{const i={...o.datum},s=Rn(Pr(o)),a=r?(o.session||{}).move:null,l=a&&a.anchors;for(const u of o.channels){if(r){const d=l&&l[u.field],f=$t(u.name);if(!d||!f||!u.scale||!u.scale.invertible)continue;const p=u.scale.encode(d.startValue);if(typeof p!="number"||Number.isNaN(p))continue;const h=(f==="x"?o.pointer.x:o.pointer.y)-d.startPx;i[u.field]=u.scale.invertValue(p+h);continue}const c=ho(u,o.pointer,s);c!==void 0&&(i[u.field]=c)}return i}})}function hE(e={}){return je({type:"moveSpan",inverts:!0,gesture:"drag",...e,apply:t=>{const[n,r]=t.channels,o=Pr(t),i=Gl(o,n,r,t.pointer);if(i)return{...t.datum,[n.field]:i.a,[r.field]:i.b}}})}function pE(e={}){const t=Kl(e,"brushSpan","brush");return je({type:"brushSpan",inverts:!0,gesture:"drag",...t,pick:"brush",apply:n=>{const[r,o]=n.channels,i=n.datum;if(!r||!o||!i)return;const s=n.session&&n.session.zone;if(!s)return;if(s==="canonicalize"){const c=i[r.field],d=i[o.field];return c==null||d==null||c<=d?void 0:{...i,[r.field]:d,[o.field]:c}}if(s==="body"){const c=Pr(n),d=Gl(c,r,o,n.pointer);return d?{...i,[r.field]:d.a,[o.field]:d.b}:void 0}const a=n.session&&n.session.field,l=a===r.field?r:a===o.field?o:null;if(!l)return;const u=ho(l,n.pointer);if(u!==void 0)return{...i,[l.field]:u}}})}function q0(e={}){const{resize:t="both",move:n=!0,...r}=Kl(e,"brushRect","brushRect");return je({type:"brushRect",inverts:!0,gesture:"drag",channels:["x1","x2","y1","y2"],...r,resize:t,move:n,pick:"brushRect",apply:o=>{const i=o.session&&o.session.zone,s=o.datum;if(!i||!s)return;const a=o.channels.filter(p=>$t(p.name)==="x"),l=o.channels.filter(p=>$t(p.name)==="y"),u=Pr(o);if(i==="canonicalize"){const p={...s};let h=!1;for(const[y,g]of[a,l]){if(!y||!g)continue;const m=s[y.field],b=s[g.field];m==null||b==null||m<=b||(p[y.field]=b,p[g.field]=m,h=!0)}return h?p:void 0}if(i==="body"){const p={...s};let h=!1;for(const[y,g]of[a,l]){if(!y||!g)continue;const m=Gl(u,y,g,o.pointer);m&&(p[y.field]=m.a,p[g.field]=m.b,h=!0)}return h?p:void 0}const c=o.session&&o.session.fields||[],d={...s};let f=!1;for(const p of o.channels){if(!p.field||!c.includes(p.field))continue;const h=ho(p,o.pointer);h!==void 0&&(d[p.field]=h,f=!0)}return f?d:void 0}})}function yE(e,t){const n=t||(e==="x"?"left":"up");return{axis:e,towardSmaller:n==="left"||n==="up"}}function gE(e,t){if(typeof e=="number"&&e>0)return e;const n=t&&t.scale&&t.scale.frameExtent;return typeof n=="number"&&n>0?n:120}const B0=(e,t)=>`${e}:${t}`;function mE(e={}){const{axis:t="x",increase:n,extent:r,mode:o="relative",...i}=e,{towardSmaller:s}=yE(t,n);return o==="relative"&&i.pick!=null&&i.pick!=="direct"&&i.pick!=="slide"&&(ge("slide:relative:pick",`slide({ mode: "relative" }) needs the slide driver's dragstart anchor, so it is served by that driver alone. { pick: "${i.pick}" } is ignored (direct pick); use mode: "absolute" with that pick, or pick: "slide" for the plane form.`),delete i.pick),je({type:"slide",inverts:!0,gesture:"drag",pick:"direct",axis:t,increase:n,extent:r,mode:o,...i,apply:a=>{const l=a.channels[0];if(!l||!l.field)return;const[u,c]=A0(l),d=t==="x"?a.pointer.x:a.pointer.y,f=gE(r,l);if(o==="relative"){const b=(a.session||{}).slide,w=b&&b[B0(t,l.field)];if(!w||typeof w.startValue!="number")return;const x=(d-w.startPx)*(s?-1:1),S=c-u,v=Math.min(u,c),k=Math.max(u,c),_=Math.max(v,Math.min(k,w.startValue+x/f*S));return{...a.datum,[l.field]:_}}const p=Rn(Pr(a));if(!p)return;const h=t==="x"?p.cx:p.cy,y=s?h+f:h-f,g=s?h-f:h+f,m=E0(d,y,g,u,c);if(m!==void 0)return{...a.datum,[l.field]:m}}})}function bE(e={}){return je({type:"resize",inverts:!0,gesture:"drag",...e,apply:t=>{const n=t.channels[0],r=Rn(Pr(t));if(!n||!n.scale||!n.scale.invertible||!r)return;const o=Math.hypot(t.pointer.x-r.cx,t.pointer.y-r.cy);return{...t.datum,[n.field]:n.scale.invertValue(o)}}})}function wE(e={}){const{relativeTo:t,pivot:n="plot",fold:r=!0,...o}=e,i=o.pick||"plane",s=a=>{let l=(a.width||0)/2,u=(a.height||0)/2;if(n==="mark"){const d=Rn(Pr(a));d&&(l=d.cx,u=d.cy)}let c=Bf(a.pointer,{cx:l,cy:u});if(r)c>90?c-=180:c<=-90&&(c+=180);else{const d=a.channels[0]&&a.channels[0].scale,f=d&&typeof d.range=="function"?d.range():null;f&&f.length>=2&&typeof f[0]=="number"&&typeof f[f.length-1]=="number"&&(c=qM(c,f[0],f[f.length-1]))}return c};return je({type:"rotate",inverts:!0,gesture:"drag",pick:"plane",...o,apply:a=>{const l=a.channels[0],u=l&&l.scale;if(!u||!u.invertible)return;const c=s(a),d=f=>{if(!t)return{...f,[l.field]:u.invertValue(c)};const p=a.markChannels[t],h=p?p.field:null,y=a.scales[t],g=h!=null&&y?.encode?y.encode(f[h]):0,m=Math.abs(c-g);return{...f,[l.field]:u.invertValue(m)}};if(i==="direct")return a.datum?d(a.datum):void 0;if(a.data.length)return a.data.map(d)}})}function xE(e={}){return je({type:"cycle",gesture:"click",...e,apply:t=>{const n=t.channels[0];if(!n||!t.datum)return;const r=T0(n,t.schema);if(!r||!r.length)return;const o=r.indexOf(t.datum[n.field]);return{...t.datum,[n.field]:r[(o+1)%r.length]}}})}function nd(e={}){const{defaults:t={},...n}=e;return je({type:"create",gesture:"click",channels:["x","y"],pick:"plane",cardinality:"append",defaults:t,...n,apply:r=>{const o=Fn(r,{defaults:t});return o?[...r.data,o]:void 0}})}function rd(e={}){const{defaults:t={},...n}=e;return je({type:"toggle",gesture:"click",channels:["x"],pick:"plane",cardinality:"toggle",defaults:t,...n,apply:r=>{const o=Fn(r,{defaults:t});if(!o)return;const i=r.channels.map(a=>a.field),s=r.data.findIndex(a=>i.every(l=>a[l]===o[l]));return s>=0?r.data.filter((a,l)=>l!==s):[...r.data,o]}})}function H0(e={}){return je({type:"remove",gesture:"click",cardinality:"delete",...e,apply:t=>{if(t.index!=null)return t.data.filter((n,r)=>r!==t.index)}})}function U0(e){const t=e.channels[0];if(!(!t||!t.field||e.value===void 0||!e.datum))return{...e.datum,[t.field]:e.value}}function vE(e={}){return je({type:"set",gesture:"commit",pick:"direct",...e,apply:U0})}function K0(e={}){return je({type:"editText",gesture:"commit",pick:"direct",channels:["text"],inline:!0,...e,apply:U0})}function Y0(e={}){return je({type:"rank",inverts:!0,gesture:"drag",...e,apply:t=>{const n=t.channels[0];if(!n||!t.datum||t.index==null)return;const r=n.field;if(!r)return;const o=ho(n,t.pointer);if(o===void 0)return;const i=t.datum[r];if(i!==o)return t.data.map((s,a)=>a===t.index?{...s,[r]:o}:s[r]===o?{...s,[r]:i}:s)}})}function kE(e={}){const{exclusive:t=!0,toggle:n=!0,multi:r=!1,...o}=e;return je({type:"select",gesture:"click",pick:"direct",target:"selection",...o,apply:i=>{if(i.index==null)return;const s=i.event||{},a=r&&!!(s.shiftKey||s.metaKey);return{index:i.index,exclusive:a?!1:t,toggle:n}}})}function G0(e,t={}){return je({type:"custom",gesture:"drag",...t,apply:e})}const SE=40,$E={name:"slide",sessionKeys:["index","slide"],wants:e=>e.type==="slide"&&e.mode==="relative",onEvent({feature:e,event:t,edits:n,marks:r,data:o,index:i,session:s,runEdit:a}){if(!n.length)return!1;let l=!1;if(t.type==="dragstart"){const u=i??In(r,t.x,t.y,Zn(n[0],SE));if(u==null)return!1;const c=o[u],d={};for(const f of n){const p=f.axis==="y"?"y":"x",h=f.channels&&f.channels[0]||null,y=h&&e.channels&&e.channels[h],g=y&&y.field;if(!g)continue;const m=c&&c[g];typeof m=="number"&&(d[B0(p,g)]={startPx:p==="x"?t.x:t.y,startValue:m})}if(!Object.keys(d).length)return!1;s.set({index:u,slide:d}),l=!0}else if(t.type==="drag"){const u=s.get();if(!u||u.index==null||!u.slide)return!1;for(const c of n)a(c,u.index)&&(l=!0)}else if(t.type==="dragend"||t.type==="hoverout"){if(!s.get())return!1;s.set({index:null,slide:null}),l=!0}return l}},_E=40,ME={name:"move",sessionKeys:["move"],wants:e=>e.type==="move"&&e.mode==="relative",onEvent({feature:e,event:t,edits:n,marks:r,data:o,index:i,session:s,runEdit:a}){if(!n.length)return!1;let l=!1;if(t.type==="dragstart"){const u=i??In(r,t.x,t.y,Zn(n[0],_E));if(u==null)return!1;const c=o[u],d={};for(const f of n)for(const p of f.channels||[]){const h=e.channels&&e.channels[p],y=h&&h.field;!y||!c||c[y]===void 0||(d[y]={startPx:$t(p)==="y"?t.y:t.x,startValue:c[y]})}if(!Object.keys(d).length)return!1;s.set({move:{index:u,anchors:d}}),l=!0}else if(t.type==="drag"){const u=(s.get()||{}).move;if(!u||u.index==null)return!1;for(const c of n)a(c,u.index)&&(l=!0)}else if(t.type==="dragend"||t.type==="hoverout"){if(!(s.get()||{}).move)return!1;s.set({move:null}),l=!0}return l}},EE={name:"connect",sessionKeys:["fromIndex","fromSide","fromPoint","targets"],wants:e=>e.type==="network.connect"||e.type==="network.rewire",onEvent({event:e,edits:t,index:n,session:r,runEdit:o,previewEdit:i,preview:s,reachable:a}){if(!t.length)return!1;let l=!1;if(e.type==="dragstart"){if(n==null)return!1;const c=e.node;r.set({fromIndex:n,fromSide:c&&c.side?c.side:null,fromPoint:{x:e.x,y:e.y}});let d=null;for(const p of t){const h=a?a(p,n):null;h&&(d=[...d||[],...h])}const f=t.some(p=>p.cardinality==="append");if(d&&!d.length&&f)return r.clear(),!0;d&&r.set({targets:d});for(const p of t)i(p,n)&&(l=!0);return!0}const u=r.get();if(!u||u.fromIndex==null)return!1;if(e.type==="drag"){let c=!1;for(const d of t)i(d,u.fromIndex)&&(c=!0);(!c&&s.clear()||c)&&(l=!0)}else if(e.type==="dragend"){for(const c of t)o(c,u.fromIndex)&&(l=!0);s.clear()&&(l=!0),r.clear(),l=!0}return l}},zo=[X5,Q5,eE,tE,rE,oE,lE,cE,dE,$E,ME,EE];function AE(e){if(!e||!e.name||typeof e.onEvent!="function"||e.wants!=null&&typeof e.wants!="function")throw new Error("[elicit] registerDriver expects { name, onEvent(ctx), wants?(edit), sessionKeys? }");const t=zo.findIndex(n=>n.name===e.name);t>=0?zo[t]=e:zo.push(e)}function gr(e){return zo.find(t=>t.name===e.pick)||zo.find(t=>t.wants?t.wants(e):!1)}function TE(e){return e.some(t=>t.pick==="direct"||t.pick==="plane"?!1:!!gr(t))}const OE="#e4572e",CE={bounds:{dash:"4 4",width:1,opacity:.9,bandOpacity:.07,fontSize:10,labelOpacity:.95,tickLength:6,tickOpacity:.5},catchment:{dash:"2 4",width:1,opacity:.45},track:{dash:"3 3",width:2,opacity:.35}},NE=["bounds","catchment"];function V0(e,t){let n=e&&e.guide;if(n==null){const a=gr(e);n=a&&a.selects?{catchment:!0}:!1}if(n===!1)return{bounds:null,catchment:null,track:null};const r=t&&t.theme&&t.theme.guide,o=t&&t.theme&&t.theme.constraint&&t.theme.constraint.color,i=n&&typeof n=="object"&&n.color||o||OE,s=a=>{const l=n===!0?NE.includes(a):n&&typeof n=="object"?n[a]:!1;if(!l)return null;const u=r&&r[a];return{color:i,...CE[a],...u&&typeof u=="object"?u:{},...typeof l=="object"?l:{}}};return{bounds:s("bounds"),catchment:s("catchment"),track:s("track")}}function IE(e){const t=[],n=new Set;for(const r of e)va(r).forEach((o,i)=>{if(o.guide===!1)return;if(!o.guide){const l=gr(o);if(!(l&&l.selects))return}const s=`${r.id}:edit-${o.type}-${i}`;if(n.has(s))return;n.add(s);const a={views:"state",build:(l,u,c,d,f)=>LE(r,o,f)};t.push(a)});return t}function LE(e,t,n){const{scales:r,width:o,height:i}=n,s=n.tableOf?n.tableOf(e):n.data,a=n.constraintsIn?n.constraintsIn(e.table):n.constraints,l=e.channels||{},u=Ti(t.channels,l,r,e),c=u[0],d=V0(t,n),f=[];if(d.bounds&&c&&c.scale){const h=d.bounds,y=[...a||[],...t.constrain].filter(g=>typeof g!="function");for(const g of y){const m=g.field==null?null:[].concat(g.field);m&&c.field&&!m.includes(c.field)||f.push(...RE(g,{feature:e,data:s,scales:r,width:o,height:i,primary:c,color:h.color,style:h}))}u.length>=2&&f.push(...jE(y,u,{color:h.color,style:h}))}const p=gr(t);return p&&p.selects&&f.push(...qE(e,t,n)),d.track&&f.push(...FE(e,t,n,d.track)),f}function FE(e,t,n,r){const o=n.featureNodes&&n.featureNodes[e.id]||[],i=t.channels&&t.channels.length?t.channels:null,s=[],a={stroke:r.color,strokeWidth:r.width,strokeDasharray:r.dash,opacity:r.opacity,fill:"none",guide:!0,pointerEvents:"none"};for(const l of o){const u=l&&l.dm;if(!u)continue;const c=Rn(l);if(c)for(const d of["x","y"]){const f=u[d];!f||f.pxAt0==null||f.pxAt1==null||i&&!i.includes(f.channel)||s.push(d==="x"?{type:"line",x1:f.pxAt0,x2:f.pxAt1,y1:c.cy,y2:c.cy,...a}:{type:"line",x1:c.cx,x2:c.cx,y1:f.pxAt0,y2:f.pxAt1,...a})}}return s}function RE(e,t){if(typeof e.guide=="function")return e.guide(t)||[];switch(e.type){case"clamp":return DE(e.options||{},t);case"maintainSum":return WE(e.options||{},t);case"snap":return zE(e.options||{},t);default:return[]}}const PE=200;function zE({step:e=1,origin:t=0},n){const{primary:r,width:o,height:i,color:s,style:a}=n,l=r.scale;if(!l||!(e>0)||fo(l))return[];const u=l.domain().map(Number),c=Math.min(...u),d=Math.max(...u);if(!Number.isFinite(c)||!Number.isFinite(d))return[];if((d-c)/e>PE)return[];const f=$t(r.name)==="x",[p,h]=oo(l),y=a&&a.tickLength||6,g=(a&&a.tickOpacity)!=null?a.tickOpacity:.5,m=[],b=Math.ceil((c-t)/e),w=Math.floor((d-t)/e);for(let x=b;x<=w;x++){const S=l(t+x*e);!Number.isFinite(S)||S<p-.5||S>h+.5||m.push(f?{type:"line",x1:S,x2:S,y1:i,y2:i-y,stroke:s,strokeWidth:1,opacity:g,pointerEvents:"none",guide:!0}:{type:"line",x1:0,x2:y,y1:S,y2:S,stroke:s,strokeWidth:1,opacity:g,pointerEvents:"none",guide:!0})}return m}function Bp(e,t,n){const{primary:r,width:o,height:i,color:s,style:a}=n;if(e===void 0)return[];const l=r.scale(e),u=a||{},c={stroke:s,strokeDasharray:u.dash,strokeWidth:u.width,opacity:u.opacity,pointerEvents:"none",guide:!0},d={fill:s,fontSize:u.fontSize,opacity:u.labelOpacity,pointerEvents:"none",guide:!0},f=[];return $t(r.name)==="x"?(f.push({type:"line",x1:l,x2:l,y1:0,y2:i,...c}),f.push({type:"text",x:l+4,y:12,text:t,textAnchor:"start",...d})):(f.push({type:"line",x1:0,x2:o,y1:l,y2:l,...c}),f.push({type:"text",x:o-4,y:l-4,text:t,textAnchor:"end",...d})),f}function DE({min:e,max:t},n){const{primary:r,width:o,height:i,color:s}=n,a=[],l=$t(r.name)==="x";if(e!==void 0&&t!==void 0){const u=r.scale(e),c=r.scale(t),d=Math.min(u,c),f=Math.max(u,c),p=(n.style&&n.style.bandOpacity)!=null?n.style.bandOpacity:.07;a.push(l?{type:"rect",x:d,y:0,width:f-d,height:i,fill:s,opacity:p,pointerEvents:"none",guide:!0}:{type:"rect",x:0,y:d,width:o,height:f-d,fill:s,opacity:p,pointerEvents:"none",guide:!0})}return a.push(...Bp(e,`min ${e}`,n)),a.push(...Bp(t,`max ${t}`,n)),a}function jE(e,t,n){const r=t.find(y=>$t(y.name)==="x"),o=t.find(y=>$t(y.name)==="y");if(!r||!o||!r.scale||!o.scale)return[];const i=e.filter(y=>typeof y!="function"),s=i.find(y=>y.type==="clamp"&&y.field===r.field),a=i.find(y=>y.type==="clamp"&&y.field===o.field);if(!s||!a)return[];const l=s.options||{},u=a.options||{};if(l.min==null||l.max==null||u.min==null||u.max==null)return[];const c=r.scale(l.min),d=r.scale(l.max),f=o.scale(u.min),p=o.scale(u.max),{color:h}=n;return[{type:"rect",x:Math.min(c,d),y:Math.min(f,p),width:Math.abs(d-c),height:Math.abs(p-f),fill:h,opacity:(n.style&&n.style.bandOpacity)!=null?n.style.bandOpacity:.08,stroke:h,strokeWidth:n.style&&n.style.width||1,strokeDasharray:n.style&&n.style.dash||"4 4",pointerEvents:"none",guide:!0}]}function WE({total:e},t){if(typeof e!="number")return[];const{feature:n,data:r,scales:o,primary:i,color:s}=t,a=i.name,l=$t(a)||(a==="x"?"x":"y"),u=l==="y"?"x":"y",c=l==="y"?n.yKey||"y":n.xKey||"x",d=u==="y"?n.yKey||"y":n.xKey||"x",f=i.scale,p=o[u];if(!p||!Vn(p))return[];const[h,y]=[Math.min(...f.domain()),Math.max(...f.domain())],g=p.bandwidth(),m=[];return r.forEach(b=>{const w=r.reduce((_,T)=>T[d]===b[d]?_:_+T[c],0),x=e-w;if(x<h||x>y)return;const S=p(b[d]),v=f(x),k={stroke:s,strokeDasharray:t.style&&t.style.dash||"3 3",strokeWidth:(t.style&&t.style.width||1)*1.5,opacity:(t.style&&t.style.opacity)!=null?t.style.opacity:.9,pointerEvents:"none",guide:!0};m.push(l==="y"?{type:"line",x1:S-2,x2:S+g+2,y1:v,y2:v,...k}:{type:"line",x1:v,x2:v,y1:S-2,y2:S+g+2,...k})}),m}function qE(e,t,n){const r=n.ui&&n.ui.session&&n.ui.session[e.id];if(!r||r.px==null||r.py==null||r.threshold==null)return[];const o=V0(t,n).catchment;return o?[{type:"circle",cx:r.px,cy:r.py,r:r.threshold,fill:"none",stroke:o.color,strokeDasharray:o.dash,strokeWidth:o.width,opacity:o.opacity,guide:!0,effect:!0,pointerEvents:"none"}]:[]}const BE={linear:Df,catmullRom:wM,natural:kM,step:SM,stepAfter:_M,stepBefore:$M,basis:gM,cardinal:mM,monotoneX:xM,monotoneY:vM};function Ni(e){return e&&BE[e]||Df}const X0=[{field:"fill",svgAttr:"fill",base:null},{field:"stroke",svgAttr:"stroke",base:null},{field:"strokeWidth",svgAttr:"stroke-width",base:null},{field:"strokeDasharray",svgAttr:"stroke-dasharray",base:null},{field:"strokeLinecap",svgAttr:"stroke-linecap",base:null},{field:"opacity",svgAttr:"opacity",base:null},{field:"fillOpacity",svgAttr:"fill-opacity",base:null},{field:"strokeOpacity",svgAttr:"stroke-opacity",base:null}];function J0(e){const t=[],n=[],r=[],o=[],i=[];for(const s of e||[])if(s){if(s.effect){i.push(s);continue}if(s.background){t.push(s);continue}if(s.guide){s.type==="rect"?n.push(s):o.push(s);continue}r.push(s)}return{background:t,guideRegions:n,marks:r,guideFront:o,effects:i}}const HE=e=>e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase());class Z0{constructor(){this.STYLE_ATTRS=X0.map(({field:t,svgAttr:n,base:r})=>[t,n,r]),this._planeGesture=null,this._planeTracking=null,this._planePointer=null,this._planeNode=null,this._markDragLive=!1}_themeFontSize(){return this._theme&&this._theme.font&&this._theme.font.size||10}render(t){const{container:n,scene:r,width:o,height:i,margins:s,onEvent:a,planeOnTop:l=!1,planeCursor:u="pointer",responsive:c="fixed",overflow:d="hidden",focusOutline:f=!1}=t,p=t.effects||ul,h=o-s.left-s.right,y=i-s.top-s.bottom,{g,plane:m}=this._ensureScene(n,{width:o,height:i,margins:s,innerWidth:h,innerHeight:y,responsive:c,overflow:d});this._sceneG=g,this._onEvent=a,this._theme=t.theme||null;const b=this._theme&&this._theme.font;sr(n).select("svg").style("font-family",b&&b.family||null).style("background",this._theme&&this._theme.background||null);const w=F=>du(F,g.node());this._bindPlaneGestures(m,w,a,l);const x=this._makeDrag(a),S=this._makeHover(a,p.hovered),v=this._makeKeyboard(a,f),k=(F,D)=>{const[z,j]=w(F);a({type:"click",x:z,y:j,node:D,rawEvent:F})},_=(F,D)=>{F.preventDefault(),F.stopPropagation();const[z,j]=w(F);a({type:"dblclick",x:z,y:j,node:D,rawEvent:F})},{background:T,guideRegions:L,marks:N,guideFront:I,effects:O}=J0(r.children),M=(F,D)=>F.filter(z=>z.type===D),$=this._sceneLayers(g);if(this._drawBackground($.bg,M(T,"image"),M(T,"path"),M(T,"line"),M(T,"text"),M(T,"rect"),M(T,"circle")),this._drawGuideRegions($.guideBack,L),this._drawPaths($.marks,M(N,"path"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawMarks($.marks,M(N,"rect"),M(N,"circle"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawEllipses($.marks,M(N,"ellipse"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawLines($.marks,M(N,"line"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawTextMarks($.marks,M(N,"text"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._orderMarkLayer($.marks,N),this._drawGuideFront($.guideFront,I),this._drawEffects($.effects,O),l){g.selectAll(".mark, .mark-hit").style("pointer-events","none");const F=m.node(),D=$.effects.node(),z=F&&F.parentNode;z&&z.lastElementChild===D&&D.previousElementSibling===F||(m.raise(),$.effects.raise()),m.style("cursor",u||"pointer")}}_ensureScene(t,{width:n,height:r,margins:o,innerWidth:i,innerHeight:s,responsive:a="fixed",overflow:l="hidden"}){let u=sr(t).select("svg");if(u.empty()){u=sr(t).append("svg").style("user-select","none").style("display","block");const d=u.append("g").attr("class","scene-container");d.append("rect").attr("class","plane").attr("x",0).attr("y",0).style("fill","transparent").style("pointer-events","all"),d.append("g").attr("class","bg-layer"),d.append("g").attr("class","guide-back-layer"),d.append("g").attr("class","mark-layer"),d.append("g").attr("class","guide-front-layer"),d.append("g").attr("class","effects-layer")}a==="scale"?u.attr("viewBox",`0 0 ${n} ${r}`).attr("preserveAspectRatio","xMidYMid meet").attr("width",null).attr("height",null).style("width","100%").style("height","auto"):u.attr("viewBox",null).attr("width",n).attr("height",r).style("width",null).style("height",null),u.style("overflow",l==="visible"?"visible":null);const c=u.select(".scene-container").attr("transform",`translate(${o.left},${o.top})`);return c.select("rect.plane").attr("width",i).attr("height",s),this._sceneLayers(c),{svg:u,g:c,plane:c.select("rect.plane")}}_sceneLayers(t){const n=!t.select("g.mark-layer").empty(),r=[],o=c=>{let d=t.select(`g.${c}`);return d.empty()&&(d=t.append("g").attr("class",c),r.push(c)),d},i=o("bg-layer"),s=o("guide-back-layer"),a=o("mark-layer"),l=o("guide-front-layer"),u=o("effects-layer");if(n||t.selectAll(":scope > .mark, :scope > path.mark-line, :scope > .guide-region, :scope > .guide-circle, :scope > .guide-label").remove(),r.length){const c=t.node(),d=t.select("rect.plane").node();for(const f of[d,i.node(),s.node(),a.node(),l.node(),u.node()])f&&c.appendChild(f)}return{bg:i,guideBack:s,marks:a,guideFront:l,effects:u}}_orderMarkLayer(t,n){const r=new Map(n.map((c,d)=>[c,d])),o=t.selectAll(".mark, path.mark-line").filter(c=>r.has(c)),i=o.nodes();let s=-1,a=!1;for(const c of i){const d=r.get(sr(c).datum());if(d<s){a=!0;break}s=d}if(!a)return;const l=typeof document<"u"?document.activeElement:null,u=t.node();o.sort((c,d)=>r.get(c)-r.get(d)),l&&u&&u.contains(l)&&typeof l.focus=="function"&&l.focus()}_bindPlaneGestures(t,n,r,o){if(t.on("click",i=>{if(this._suppressClick){this._suppressClick=!1;return}const[s,a]=n(i);r({type:"click",x:s,y:a,rawEvent:i})}).on("dblclick",i=>{const[s,a]=n(i);r({type:"dblclick",x:s,y:a,rawEvent:i})}),!o){this._abortPlaneGesture(),t.on("pointerdown",null).on("pointermove",null).on("pointerleave",null);return}this._planePointer=n,this._planeNode=t.node(),t.on("pointerdown",i=>{const[s,a]=n(i);this._planeGesture={startX:s,startY:a,down:!0,dragging:!1,pointerId:i.pointerId},this._trackPlaneGesture()}).on("pointermove",i=>{if(this._planeGesture)return;const[s,a]=n(i);r({type:"hover",x:s,y:a,rawEvent:i})}).on("pointerleave",i=>{this._planeGesture||r({type:"hoverout",rawEvent:i})})}_trackPlaneGesture(){if(this._planeTracking||typeof window>"u")return;const t=r=>this._planeMoved(r),n=r=>this._planeReleased(r);this._planeTracking={move:t,end:n},window.addEventListener("pointermove",t,!0),window.addEventListener("pointerup",n,!0),window.addEventListener("pointercancel",n,!0)}_releasePlaneTracking(){const t=this._planeTracking;!t||typeof window>"u"||(window.removeEventListener("pointermove",t.move,!0),window.removeEventListener("pointerup",t.end,!0),window.removeEventListener("pointercancel",t.end,!0),this._planeTracking=null)}_abortPlaneGesture(){this._releasePlaneTracking(),this._planeGesture=null}_planeMoved(t){const n=this._planeGesture;if(!n||!this._planePointer||!this._onEvent||n.pointerId!=null&&t.pointerId!==n.pointerId)return;if(t.pointerType==="mouse"&&t.buttons===0)return this._planeReleased(t);const[r,o]=this._planePointer(t);!n.dragging&&Math.hypot(r-n.startX,o-n.startY)>3&&(n.dragging=!0,this._onEvent({type:"dragstart",x:n.startX,y:n.startY,rawEvent:t})),n.dragging&&this._onEvent({type:"drag",x:r,y:o,rawEvent:t})}_planeReleased(t){const n=this._planeGesture;if(!n)return this._releasePlaneTracking();if(n.pointerId!=null&&t.pointerId!==n.pointerId||(this._releasePlaneTracking(),this._planeGesture=null,!this._planePointer||!this._onEvent))return;const[r,o]=this._planePointer(t);n.dragging&&(this._onEvent({type:"dragend",x:r,y:o,rawEvent:t}),this._suppressClick=!0),this._pointerOverPlane(t)||this._onEvent({type:"hoverout",rawEvent:t})}_pointerOverPlane(t){const n=this._planeNode;if(!n||typeof n.getBoundingClientRect!="function")return!1;const r=n.getBoundingClientRect();return t.clientX>=r.left&&t.clientX<=r.right&&t.clientY>=r.top&&t.clientY<=r.bottom}_makeKeyboard(t,n=!1){const r={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};return o=>{o.attr("tabindex",i=>i.editable?0:null).attr("role",i=>i.editable?"button":null).style("outline",n?null:"none").on("keydown",(i,s)=>{if(!s||!s.editable)return;const a=r[i.key];if(!a)return;i.preventDefault();const[l,u]=a;t({type:"nudge",node:s,dx:l,dy:u,coarse:!!i.shiftKey,rawEvent:i})})}}_makeHover(t,n){const r=!n||n.enabled!==!1;return o=>{o.on("pointerenter",(i,s)=>{!r||!s||!s.editable||t({type:"pointerover",node:s})}).on("pointerleave",(i,s)=>{!r||!s||!s.editable||t({type:"pointerout",node:s})})}}_makeDrag(t){return Xv().clickDistance(4).subject(n=>({x:n.x,y:n.y})).on("start",(n,r)=>{this._markDragLive=!0,t({type:"dragstart",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent})}).on("drag",(n,r)=>{const o=n.sourceEvent;if(o&&o.type==="mousemove"&&o.buttons===0){this._endMarkDrag(t,n,r);return}this._markDragLive&&t({type:"drag",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent})}).on("end",(n,r)=>{this._endMarkDrag(t,n,r)})}_endMarkDrag(t,n,r){this._markDragLive&&(this._markDragLive=!1,t({type:"dragend",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent}))}_applyStyle(t,n={}){for(const[r,o,i]of this.STYLE_ATTRS){const s=r in n?n[r]:i;t.attr(o,a=>a[r]!=null?a[r]:s)}return t.attr("data-ghost",r=>r.ghost?"":null),t.attr("data-hit",r=>r.hit?"":null),t.attr("data-channel",r=>r.channel!=null?r.channel:null),t}_applyEffectStyle(t,n="move"){for(const r of O0)r!=="cursor"&&t.style(HE(r),o=>o.effectStyle&&o.effectStyle[r]!=null?o.effectStyle[r]:null);return t.style("cursor",r=>r.effectStyle&&r.effectStyle.cursor!=null?r.effectStyle.cursor:r.editable?r.cursor||n:"default"),t}_angleTransform(t){if(t==null||t.angle==null||t.angle===0)return null;const n=Rn(t);return n?`rotate(${-t.angle} ${n.cx} ${n.cy})`:null}_geomRect(t){t.attr("x",n=>n.x).attr("y",n=>n.y).attr("width",n=>n.width).attr("height",n=>Math.max(0,n.height)).attr("rx",n=>n.rx!=null?n.rx:null).attr("ry",n=>n.ry!=null?n.ry:n.rx!=null?n.rx:null).attr("transform",n=>this._angleTransform(n))}_geomCircle(t){t.attr("cx",n=>n.cx).attr("cy",n=>n.cy).attr("r",n=>Math.max(0,n.r!=null?n.r:5)).attr("transform",n=>this._angleTransform(n))}_geomEllipse(t){t.attr("cx",n=>n.cx).attr("cy",n=>n.cy).attr("rx",n=>Math.max(0,n.rx!=null?n.rx:5)).attr("ry",n=>Math.max(0,n.ry!=null?n.ry:5)).attr("transform",n=>this._angleTransform(n))}_geomLine(t){t.attr("x1",n=>n.x1).attr("x2",n=>n.x2).attr("y1",n=>n.y1).attr("y2",n=>n.y2).attr("transform",n=>this._angleTransform(n))}_geomText(t,n="start"){t.attr("x",r=>r.x).attr("y",r=>r.y).attr("text-anchor",r=>r.textAnchor||n).attr("dominant-baseline",r=>r.dominantBaseline||null).attr("font-size",r=>r.fontSize!=null?r.fontSize:this._themeFontSize()).attr("transform",r=>this._angleTransform(r)),t.each(function(r){const o=sr(this),i=Array.isArray(r.lines)?r.lines:null;if(!i||i.length<=1){o.selectAll("tspan").remove(),o.text(i?i[0]||"":r.text);return}const s=r.fontSize!=null?r.fontSize:12,a=r.lineHeight!=null?r.lineHeight:Math.round(s*1.35),l=-(i.length-1)*a/2;o.text(null),o.selectAll("tspan").data(i).join("tspan").attr("x",r.x).attr("dy",(u,c)=>c===0?l:a).text(u=>u)})}_drawBackground(t,n,r,o,i,s=[],a=[]){t.selectAll("image").data(n,h=>h.key).join("image").style("pointer-events","none").attr("x",h=>h.x).attr("y",h=>h.y).attr("width",h=>h.width).attr("height",h=>h.height).attr("transform",h=>this._angleTransform(h)).attr("preserveAspectRatio","none").attr("href",h=>h.href).attr("opacity",h=>h.opacity!=null?h.opacity:null).lower();const u=t.selectAll("rect.bg-rect").data(s).join("rect").attr("class","bg-rect").style("pointer-events","none");this._geomRect(u),this._applyStyle(u,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const c=t.selectAll("circle.bg-circle").data(a).join("circle").attr("class","bg-circle").style("pointer-events","none");this._geomCircle(c),this._applyStyle(c,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const d=t.selectAll("line").data(o).join("line").style("pointer-events","none");this._geomLine(d),this._applyStyle(d,{stroke:"#6b7280",strokeWidth:1,opacity:1});const f=t.selectAll("text").data(i).join("text").style("pointer-events","none");this._geomText(f,"middle"),this._applyStyle(f,{fill:"#374151",opacity:1});const p=t.selectAll("path.bg-path").data(r).join("path").attr("class","bg-path").style("pointer-events","none").attr("d",h=>h.d?h.d:_i().curve(Ni(h.curve))(h.points||[]));this._applyStyle(p,{fill:"none",stroke:"black",strokeWidth:1,opacity:1})}_drawGuideRegions(t,n){const r=t.selectAll("rect.guide-region").data(n).join("rect").attr("class","guide-region").style("pointer-events","none");this._geomRect(r),this._applyStyle(r,{fill:"none",stroke:"none",strokeWidth:1,opacity:1})}_drawGuideFront(t,n){const r=u=>n.filter(c=>c.type===u),o=t.selectAll("line.guide-line").data(r("line")).join("line").attr("class","guide-line").style("pointer-events","none");this._geomLine(o),this._applyStyle(o,{stroke:"black",strokeWidth:1,opacity:1});const i=t.selectAll("circle.guide-circle").data(r("circle")).join("circle").attr("class","guide-circle").style("pointer-events","none");this._geomCircle(i),this._applyStyle(i,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const s=t.selectAll("path.guide-path").data(r("path")).join("path").attr("class","guide-path").style("pointer-events","none").attr("d",u=>u.d?u.d:_i().curve(Ni(u.curve))(u.points||[]));this._applyStyle(s,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});const a=t.selectAll("text.guide-label").data(r("text")).join("text").attr("class","guide-label").style("pointer-events","none");this._geomText(a,"start"),this._applyStyle(a,{fill:"black",opacity:1});const l=new Map(n.map((u,c)=>[u,c]));t.selectAll("line.guide-line, circle.guide-circle, path.guide-path, text.guide-label").filter(u=>l.has(u)).sort((u,c)=>l.get(u)-l.get(c))}_drawEffects(t,n){const r=d=>n.filter(f=>f.type===d),o={fill:"none",stroke:"none",strokeWidth:1,opacity:1},i=t.selectAll("circle.effect").data(r("circle")).join("circle").attr("class","effect").style("pointer-events","none");this._geomCircle(i),this._applyStyle(i,o);const s=t.selectAll("rect.effect").data(r("rect")).join("rect").attr("class","effect").style("pointer-events","none");this._geomRect(s),this._applyStyle(s,o);const a=t.selectAll("ellipse.effect").data(r("ellipse")).join("ellipse").attr("class","effect").style("pointer-events","none");this._geomEllipse(a),this._applyStyle(a,o);const l=t.selectAll("line.effect").data(r("line")).join("line").attr("class","effect").style("pointer-events","none");this._geomLine(l),this._applyStyle(l,o);const u=t.selectAll("path.effect").data(r("path")).join("path").attr("class","effect").style("pointer-events","none").attr("d",d=>d.d?d.d:_i().curve(Ni(d.curve))(d.points||[]));this._applyStyle(u,o);const c=new Map(n.map((d,f)=>[d,f]));t.selectAll("circle.effect, rect.effect, ellipse.effect, line.effect, path.effect").filter(d=>c.has(d)).sort((d,f)=>c.get(d)-c.get(f))}_dblClick(t){return(n,r)=>{if(r&&r.editText){n.preventDefault(),n.stopPropagation(),this._editText(n,r);return}t&&t(n,r)}}_drawMarks(t,n,r,{drag:o,markClick:i,markDblClick:s,keys:a,hover:l}){const u=t.selectAll("rect.mark").data(n).join("rect").attr("class","mark").style("pointer-events",p=>p.pointerEvents||"auto").style("cursor",p=>p.editable?p.cursor||"ns-resize":"default").on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).call(a);this._geomRect(u),this._applyStyle(u,{fill:"black"}),this._applyEffectStyle(u,"ns-resize");const c=n.filter(p=>p.editable&&p.pointerEvents!=="none"&&((p.width||0)<fl||(p.height||0)<fl));t.selectAll("rect.mark-hit").data(c).join("rect").attr("class","mark-hit").style("pointer-events","all").style("fill","transparent").style("cursor",p=>p.cursor||"ns-resize").attr("x",p=>Ci(p).x).attr("y",p=>Ci(p).y).attr("width",p=>Ci(p).w).attr("height",p=>Ci(p).h).attr("transform",p=>this._angleTransform(p)).on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).lower();const f=t.selectAll("circle.mark").data(r).join("circle").attr("class","mark").style("pointer-events",p=>p.pointerEvents||"auto").style("cursor",p=>p.editable?p.cursor||"move":"default").on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).call(a);this._geomCircle(f),this._applyStyle(f,{fill:"black"}),this._applyEffectStyle(f,"move")}_drawEllipses(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("ellipse.mark").data(n).join("ellipse").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomEllipse(l),this._applyStyle(l,{fill:"black"}),this._applyEffectStyle(l,"move")}_drawLines(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("line.mark").data(n).join("line").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomLine(l),this._applyStyle(l,{stroke:"black",strokeWidth:1,opacity:1}),this._applyEffectStyle(l,"move")}_drawPaths(t,n,r){const o=t.selectAll("path.mark-line").data(n).join("path").attr("class","mark-line").style("pointer-events",i=>i.pointerEvents||(i.editable?"auto":"none")).style("cursor",i=>i.editable?i.cursor||"pointer":"default").attr("d",i=>i.d?i.d:_i().curve(Ni(i.curve))(i.points||[]));this._applyStyle(o,{fill:"none",stroke:"black",strokeWidth:1,opacity:1}),this._applyEffectStyle(o,"pointer"),r&&o.on("click",r.markClick).on("dblclick",this._dblClick(r.markDblClick)).call(r.drag).call(r.hover).call(r.keys)}_drawTextMarks(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("text.mark").data(n).join("text").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomText(l,"middle"),this._applyStyle(l,{fill:"black",opacity:1}),this._applyEffectStyle(l,"move")}_editText(t,n){if(!n||!n.editText)return;const r=this._sceneG,o=this._onEvent;if(!r||!o)return;r.selectAll("foreignObject.text-editor").remove();const i=n.fontSize!=null?n.fontSize:12,s=n.editBox||(n.type==="rect"&&n.width!=null?{x:n.x,y:n.y,width:n.width,height:Math.max(0,n.height)}:null),a=s?s.width:140,l=s?s.height:i+10,u=s?s.x:n.x-a/2,c=s?s.y:n.y-l+4,d=r.append("foreignObject").attr("class","text-editor").attr("x",u).attr("y",c).attr("width",a).attr("height",l),f=!!n.multiline,p=d.append(f?"xhtml:textarea":"xhtml:input").attr("type",f?null:"text").style("width","100%").style("height",f?"100%":null).style("box-sizing","border-box").style("font-size",i+"px").style("font-family","inherit").style("text-align","center").style("resize",f?"none":null).node();p.value=n.text!=null?String(n.text):n.editValue!=null?String(n.editValue):"",p.focus(),f?p.setSelectionRange(p.value.length,p.value.length):p.select();let h=!1;const y=()=>{if(h)return;h=!0;const m=p.value;d.remove(),o({type:"commit",node:n,value:m,x:n.x,y:n.y,rawEvent:t})},g=()=>{h||(h=!0,d.remove())};p.addEventListener("keydown",m=>{m.key==="Enter"?(!f||m.metaKey||m.ctrlKey)&&(m.preventDefault(),y()):m.key==="Escape"&&(m.preventDefault(),g()),m.stopPropagation()}),p.addEventListener("blur",y)}}const Q0=As.axis,od=As.grid,Hp=e=>e instanceof Date?e.getTime():e;function Up({x:e,y:t,textAnchor:n,v:r,format:o,fill:i,fontSize:s}){return{type:"text",x:e,y:t,text:o(r),textAnchor:n,fill:i,fontSize:s,category:r,editText:!0,index:0,cursor:"text"}}function Kp({x:e,y:t,v:n,fontSize:r}){return{type:"text",x:e,y:t,text:"×",textAnchor:"middle",fill:"#dc2626",fontSize:r+1,cursor:"pointer",removeCategory:n,index:0}}function UE(e,t,n){switch(e){case"top":return{x:0,y:0};case"bottom":return{x:0,y:n};case"left":return{x:0,y:0};case"right":return{x:t,y:0};default:return{x:0,y:0}}}function Ql(e,t={}){const{ticks:n=5,tickValues:r,tickFormat:o}=t,i=e.kind!=="continuous";let s;r?s=r:i?s=e.domain():typeof e.ticks=="function"?s=e.ticks(n):s=e.domain();let a;return typeof o=="function"?a=o:typeof o=="string"?a=ti(o):!i&&typeof e.tickFormat=="function"?a=e.tickFormat(n):a=l=>`${l}`,{values:s,format:a}}function ec(e={}){Cs("axis",e,Q0);const{channel:t="x",anchor:n=t==="x"?"bottom":"left",transform:r,ticks:o=5,tickValues:i,tickFormat:s,tickSize:a=6,title:l,stroke:u,fill:c,fontSize:d,grid:f=!1,field:p,table:h,handleColor:y,handleSize:g,id:m}=e,b=t==="x"||t!=="y"&&(n==="bottom"||n==="top"),w=Wi(e,t),x=w.length>0;return{id:m,type:"axis",isAxis:!0,views:"scale",channel:t,layer:"background",edits:w,field:p,table:h,grid:f,build:(S,v,k,_)=>{const T=v[t];if(!T)return[];const L=it(v),N=u??L.axis.stroke,I=c??L.axis.labelFill,O=d??L.axis.fontSize,M=fn(v,{handles:!0,handleSize:g,handleColor:y??L.axis.handle}),$=M.fill,F=M.size,D=M.stroke,z=UE(n,k,_),j=r?{...z,...r({width:k,height:_,scales:v,anchor:n,base:z})||{}}:z,{values:G,format:J}=Ql(T,{ticks:o,tickValues:i,tickFormat:s}),re=n==="bottom"||n==="right"?1:-1,Q=[],ve=x&&fo(T),Ce=x&&T.kind==="continuous";b?Q.push({type:"line",x1:j.x,x2:j.x+k,y1:j.y,y2:j.y,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"}):Q.push({type:"line",x1:j.x,x2:j.x,y1:j.y,y2:j.y+_,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});for(const le of G){const me=Mr(T,le);if(!(me==null||Number.isNaN(me)))if(b){const ce=j.x+me;Q.push({type:"line",x1:ce,x2:ce,y1:j.y,y2:j.y+re*a,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});const Y=j.y+re*(a+O);Q.push(ve?Up({x:ce,y:Y,textAnchor:"middle",v:le,format:J,fill:I,fontSize:O}):{type:"text",x:ce,y:Y,text:J(le),textAnchor:"middle",fill:I,fontSize:O,background:!0,pointerEvents:"none"}),ve&&Q.push(Kp({x:ce,y:Y+O,v:le,fontSize:O}))}else{const ce=j.y+me;Q.push({type:"line",x1:j.x,x2:j.x+re*a,y1:ce,y2:ce,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});const Y=j.x+re*(a+3);Q.push(ve?Up({x:Y,y:ce+O/3,textAnchor:re<0?"end":"start",v:le,format:J,fill:I,fontSize:O}):{type:"text",x:Y,y:ce+O/3,text:J(le),textAnchor:re<0?"end":"start",fill:I,fontSize:O,background:!0,pointerEvents:"none"}),ve&&Q.push(Kp({x:Y+re*(O+4),y:ce+O/3,v:le,fontSize:O}))}}if(ve){const le=b?j.x+k+O:j.x,me=b?j.y+re*(a+O):j.y+_+re*(a+O);Q.push({type:"text",x:le,y:me,text:"+",textAnchor:"middle",fill:$,fontSize:O+4,cursor:"pointer",addCategory:!0,editText:!0,index:0})}else if(Ce){const le=typeof T.domain=="function"?T.domain():[],me=le[0],ce=le[le.length-1],Y=fe=>(b?j.x:j.y)+Mr(T,fe);for(const fe of["min","max"]){const ie=fe==="max"?ce:me,U=fe==="max"?me:ce,we=Y(ie),xe=Y(U),P=Hp(ie)-Hp(U)||1;Q.push({type:"circle",cx:b?j.x+Mr(T,ie):j.x,cy:b?j.y:j.y+Mr(T,ie),r:F,fill:$,stroke:D,strokeWidth:M.strokeWidth,axisHandle:!0,handle:fe,axis:t,anchorPixel:xe,anchorValue:U,grabPixel:we,grabValue:ie,pxPerUnit:(we-xe)/P,cursor:b?"ew-resize":"ns-resize"})}}return l&&(b?Q.push({type:"text",x:j.x+k/2,y:j.y+re*(a+O*2.4),text:l,textAnchor:"middle",fill:I,fontSize:O+1,background:!0,pointerEvents:"none"}):Q.push({type:"text",x:j.x+re*(a+O*2.4),y:j.y+_/2,text:l,textAnchor:"middle",fill:I,fontSize:O+1,background:!0,pointerEvents:"none"})),Q}}}function id(e={}){Cs("grid",e,od);const{channel:t="x",ticks:n=5,tickValues:r,stroke:o,strokeWidth:i,id:s}=e,a=t==="x";return{id:s,type:"grid",isGrid:!0,views:"scale",channel:t,layer:"background",build:(l,u,c,d)=>{const f=u[t];if(!f)return[];const p=it(u),h=o??p.grid.stroke,y=i??p.grid.strokeWidth,{values:g}=Ql(f,{ticks:n,tickValues:r}),m=[];for(const b of g){const w=Mr(f,b);w==null||Number.isNaN(w)||(a?m.push({type:"line",x1:w,x2:w,y1:0,y2:d,stroke:h,strokeWidth:y,background:!0,pointerEvents:"none"}):m.push({type:"line",x1:0,x2:c,y1:w,y2:w,stroke:h,strokeWidth:y,background:!0,pointerEvents:"none"}))}return m}}}const eb=(e={})=>ec({...e,channel:"x"}),tb=(e={})=>ec({...e,channel:"y"}),nb=(e={})=>id({...e,channel:"x"}),rb=(e={})=>id({...e,channel:"y"});function KE(e){const t={};for(const n of od)e[n]!==void 0&&(t[n]=e[n]);return t}function YE(e){return(e||[]).flat(1/0).filter(t=>t&&typeof t=="object")}function GE(e){return({scales:t})=>{if(e==="x"){const o=t.y;if(!o)return{};const i=typeof o.encode=="function"?o.encode(0):o(0);return i!=null&&!Number.isNaN(Number(i))?{y:Number(i)}:{}}const n=t.x;if(!n)return{};const r=typeof n.encode=="function"?n.encode(0):n(0);return r!=null&&!Number.isNaN(Number(r))?{x:Number(r)}:{}}}function VE(e,t){if(t===!1)return[];const n=YE(e),r=t&&typeof t=="object"?t.origin:void 0,o=r===!0||r===void 0&&t==null&&n.some(l=>l.isTrend),i=[],s=l=>n.some(u=>(u.isAxis||u.isGrid)&&u.channel===l),a={x:{axis:eb,grid:nb},y:{axis:tb,grid:rb}};if(t&&t.count&&!s("count")){const l=n.find(u=>u.countAxis);if(l){const u=t.count===!0?{}:{...t.count};i.push(ec({anchor:l.countAxis==="x"?"bottom":"left",...u,channel:"count"}))}}for(const l of["x","y"]){const u=t?t[l]:void 0;if(u===!1||s(l))continue;const c=u?{...u}:{};o&&c.transform==null&&(c.transform=GE(l)),i.push(a[l].axis(c)),c.grid&&i.push(a[l].grid(KE(c)))}return i}const ob=As.legend,Co=e=>e instanceof Date?e.getTime():e,XE=e=>e==="fill"||e==="stroke";function JE(e){return e.kind==="continuous"||!!e.ramp}function ZE(e,t){return JE(t)?e==="size"?"graduated":e==="theta"?"fan":e==="strokeWidth"?"weights":"ramp":"swatches"}function Yp(e,t,n,r){if(e!=="size")return r;let o=0;for(const i of n){const s=Number(typeof t.encode=="function"?t.encode(i):t(i));Number.isFinite(s)&&(o=Math.max(o,s))}return Math.max(r,2*o)}function Gp(e,t,n){if(e===!1||e===null)return null;if(e!=null)return String(e);const r=t??(n&&n.fields&&n.fields[0]||null);return r==null?null:String(r)}function QE(e,t,n){let r=0;for(const o of e)r=Math.max(r,String(t(o)).length);return Math.ceil(r*n*.6)}function Ns(e={}){Cs("legend",e,ob);const{channel:t="fill",anchor:n="right",orient:r,swatchSize:o=14,gap:i=6,labelWidth:s,rampLength:a=140,rampThickness:l=12,ticks:u=4,tickFormat:c,title:d,row:f,stroke:p,fill:h,fontSize:y,handleColor:g,handleSize:m,field:b,table:w,id:x}=e,S=r||(n==="left"||n==="right"?"vertical":"horizontal"),v=S==="vertical",k=Wi(e,t),_=k.length>0,T=k.some(O=>O.target==="domain"),L=O=>O[uo(t,b)]||O[t],N={offset:0,size:0},I=(O,M)=>{const $=y??(M.guide.legend.fontSize||11),F=ZE(t,O),D=F!=="swatches";let z,j;if(D){const J=O.domain(),re=ji().domain([Math.min(...J.map(Co)),Math.max(...J.map(Co))]);z=re.ticks(u),j=typeof c=="string"?ti(c):typeof c=="function"?c:re.tickFormat(u)}else z=O.domain(),j=c?Ql(O,{tickFormat:c}).format:J=>`${J}`;const G=s??QE(z,j,$);return{ramp:D,form:F,values:z,format:j,labelW:G,fontSize:$}};return{id:x,type:"legend",isLegend:!0,views:"scale",channel:t,anchor:n,orient:S,layer:"background",edits:k,field:b,table:w,_place:N,measure(O){const M=L(O);if(!M||typeof M.domain!="function")return null;const $=it(O),{form:F,values:D,labelW:z,fontSize:j}=I(M,$),J=Gp(d,b,M)?j+4:0;if(F==="graduated"){const le=ib(M,D);if(!le.length)return{width:z,height:j+J};const me=le[le.length-1].r,ce=le.reduce((Y,fe)=>Y+2*fe.r+i,0);return v?{width:2*me+6+z,height:ce+J}:{width:le.reduce((Y,fe)=>Y+2*fe.r+6+z+i,0),height:2*me+j+J}}if(F==="fan"){const le=sb(M,D,z,j);return{width:le.width,height:le.height+J}}if(F==="weights"){const le=D.reduce((me,ce)=>{const Y=Number(typeof M.encode=="function"?M.encode(ce):M(ce));return me+Math.max(Number.isFinite(Y)?Y:0,j)+i},0);return{width:2*fs+6+z,height:le+J}}if(F==="ramp")return v?{width:l+6+z,height:a+J}:{width:a,height:l+6+j+J};const re=(D.length||1)+(T?1:0),Q=T?j+6:0,ve=Yp(t,M,D,o);if(v)return{width:ve+4+z+Q,height:re*(ve+i)+J};const Ce=ve+4+z+Q+i;return{width:re*Ce,height:ve+i+J}},build(O,M,$,F){const D=L(M);if(!D||typeof D.domain!="function")return[];const z=D.domain();if(!z.length)return[];_&&b==null&&!(D.fields||[]).length&&ge(`legend:field:${t}`,`legend({ channel: "${t}", edit: … }) can't tell which column to write: no mark binds a field to "${t}", so the scale carries none and the edit is a no-op. Pin it with legend({ field: "…" }), or bind the channel on a mark.`);const j=it(M),G=p??(j.guide.legend.stroke||"#374151"),J=h??(j.guide.legend.labelFill||"#374151"),re=fn(M,{handles:!0,handleSize:m,handleColor:g??j.axis.handle}),Q=re.fill,ve=re.size,Ce=re.stroke,{form:le,values:me,format:ce,labelW:Y,fontSize:fe}=I(D,j),ie=N.size||(this.measure(M)||{width:0,height:0})[v?"width":"height"];let U=0,we=0;n==="right"?U=$+N.offset:n==="left"?U=-(N.offset+ie):n==="bottom"?we=F+N.offset:n==="top"&&(we=-(N.offset+ie));const xe=[];let P=we;const H=Gp(d,b,D);H&&(xe.push({type:"text",x:U,y:we+fe,text:H,textAnchor:"start",fill:J,fontSize:fe+1,background:!0,pointerEvents:"none"}),P=we+fe+4);const oe=M.selection,he=M.selectionAll,ke=typeof he=="function"?he(this.table):oe!=null?[oe]:[];let pe;if(f!=null&&f!=="selection"){const ae=typeof f=="function"?f(O,{selection:oe}):f;pe=ae==null?[]:Array.isArray(ae)?ae:[ae]}else ke.length?pe=ke:pe=O.length===1?[0]:[];const $e=pe.filter(ae=>Number.isInteger(ae)&&ae>=0&&ae<O.length),Te=$e.length?$e[0]:null,Se={scale:D,values:me,format:ce,cx0:U,cy0:P,vertical:v,anchor:n,fontSize:fe,swatchStroke:G,labelFill:J,editable:_,domainEditable:T,handleColor:Q,data:O,channel:t,field:b,targetRow:Te,targetRows:$e,currentStroke:j.guide.legend.currentStroke||"#111827",currentWidth:j.guide.legend.currentWidth??2};return le==="graduated"?e6(xe,{...Se,gap:i}):le==="fan"?t6(xe,{...Se,labelW:Y}):le==="weights"?n6(xe,{...Se,gap:i}):le==="ramp"?i6(xe,{...Se,rampLength:a,rampThickness:l,handleColor:Q,handleSize:ve,handleStroke:Ce}):o6(xe,{...Se,domain:z,swatchSize:Yp(t,D,z,o),gap:i,labelW:Y}),xe}}}function ib(e,t){const n=[];for(const r of t){const o=Number(typeof e.encode=="function"?e.encode(r):e(r));!Number.isFinite(o)||o<1||n.push({v:r,r:o})}return n.sort((r,o)=>r.r-o.r),n}function e6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,vertical:a,gap:l,labelFill:u,fontSize:c,swatchStroke:d}=t,f=ib(n,r);if(!f.length)return;const p=f[f.length-1].r;let h=0;for(const{v:y,r:g}of f){const m=a?i+p:i+h+g,b=a?s+h+g:s+p;e.push({type:"circle",cx:m,cy:b,r:g,fill:"none",stroke:d,strokeWidth:1,background:!0,pointerEvents:"none"}),e.push({type:"text",x:a?i+2*p+6:m,y:a?b+c*.35:s+2*p+c,text:String(o(y)),fill:u,fontSize:c,textAnchor:a?"start":"middle",background:!0,pointerEvents:"none"}),h+=2*g+l}}const fs=22;function sb(e,t,n,r){const o=[];let i=0,s=0,a=0,l=0;for(const u of t){const c=Number(typeof e.encode=="function"?e.encode(u):e(u));if(!Number.isFinite(c))continue;const d=c*Math.PI/180,f=Math.cos(d)*fs,p=-Math.sin(d)*fs,h=f+Math.cos(d)*6,y=p-Math.sin(d)*6,g=Math.cos(d)<-.1?"end":Math.cos(d)>.1?"start":"middle";o.push({v:u,tx:f,ty:p,lx:h,ly:y,anchor:g});const m=g==="end"?h-n:g==="middle"?h-n/2:h,b=g==="end"?h:g==="middle"?h+n/2:h+n;i=Math.min(i,f,m),s=Math.max(s,f,b),a=Math.min(a,p,y-r),l=Math.max(l,p,y+r*.5)}return{spokes:o,width:s-i,height:l-a,ox:-i,oy:-a}}function t6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,labelFill:a,fontSize:l,swatchStroke:u,labelW:c}=t,{spokes:d,ox:f,oy:p}=sb(n,r,c,l),h=i+f,y=s+p;for(const g of d)e.push({type:"line",x1:h,y1:y,x2:h+g.tx,y2:y+g.ty,stroke:u,strokeWidth:1.5,background:!0,pointerEvents:"none"}),e.push({type:"text",x:h+g.lx,y:y+g.ly+l*.35,text:String(o(g.v)),fill:a,fontSize:l,textAnchor:g.anchor,background:!0,pointerEvents:"none"})}function n6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,gap:a,labelFill:l,fontSize:u,swatchStroke:c}=t,d=[];for(const p of r){const h=Number(typeof n.encode=="function"?n.encode(p):n(p));Number.isFinite(h)&&h>0&&d.push({v:p,w:h})}d.sort((p,h)=>p.w-h.w);let f=0;for(const{v:p,w:h}of d){const y=s+f+h/2;e.push({type:"line",x1:i,y1:y,x2:i+fs*2,y2:y,stroke:c,strokeWidth:h,background:!0,pointerEvents:"none"}),e.push({type:"text",x:i+fs*2+6,y:y+u*.35,text:String(o(p)),fill:l,fontSize:u,textAnchor:"start",background:!0,pointerEvents:"none"}),f+=Math.max(h,u)+a}}function r6({channel:e,x:t,y:n,size:r,encoded:o,stroke:i,ink:s,interactive:a}){const l=a?{}:{background:!0,pointerEvents:"none"};if(e==="symbol")return{type:"text",x:t+r/2,y:n+r/2,text:String(o),fontSize:r,textAnchor:"middle",dominantBaseline:"central",...l};if(e==="size"){const u=Math.max(1,Number(o)||r/2);return{type:"circle",cx:t+r/2,cy:n+r/2,r:u,fill:s,stroke:i,strokeWidth:1,...l}}return e==="opacity"?{type:"rect",x:t,y:n,width:r,height:r,fill:s,fillOpacity:Number(o),stroke:i,strokeWidth:1,...l}:{type:"rect",x:t,y:n,width:r,height:r,fill:o,stroke:i,strokeWidth:1,...l}}function o6(e,t){const{domain:n,cx0:r,cy0:o,vertical:i,swatchSize:s,gap:a,fontSize:l,swatchStroke:u,labelFill:c,editable:d,domainEditable:f,handleColor:p,targetRow:h,targetRows:y,scale:g,channel:m,data:b,field:w,currentStroke:x,currentWidth:S}=t,v=d&&h!=null,k=v||f,_=h??0,T=w??(g.fields&&g.fields[0]||null),L=new Set;if(v&&T!=null)for(const $ of y){const F=b&&b[$];F&&F[T]!==void 0&&L.add(F[T])}const N=f?l+6:0,I=s+4+t.labelW+N+a,O=s+a,M=$=>({sx:i?r:r+$*I,sy:i?o+$*O:o});if(n.forEach(($,F)=>{const D=typeof g.encode=="function"?g.encode($):typeof g=="function"?g($):$,{sx:z,sy:j}=M(F),G=r6({channel:m,x:z,y:j,size:s,encoded:D,stroke:u,ink:c,interactive:k});k&&(G.category=$,G.index=_,G.indices=y,G.cursor=f&&!v?"text":"pointer",f&&(G.editText=!0,G.editValue=String($))),e.push(G),L.has($)&&e.push({type:"rect",x:z-2.5,y:j-2.5,width:s+5,height:s+5,fill:"none",stroke:x,strokeWidth:S,rx:2,effect:!0,background:!0,pointerEvents:"none"}),e.push({type:"text",x:z+s+4,y:j+s*.75,text:String(t.format($)),fill:c,fontSize:l,textAnchor:"start",background:!0,pointerEvents:"none"}),f&&e.push({type:"text",x:z+s+4+t.labelW+l*.5,y:j+s*.75,text:"×",textAnchor:"middle",fill:"#dc2626",fontSize:l+1,cursor:"pointer",removeCategory:$,index:0})}),f){const{sx:$,sy:F}=M(n.length);e.push({type:"text",x:$+s/2,y:F+s*.75,text:"+",textAnchor:"middle",fill:p,fontSize:l+4,cursor:"pointer",addCategory:!0,editText:!0,index:0})}}function i6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,vertical:a,rampLength:l,rampThickness:u,fontSize:c,swatchStroke:d,labelFill:f,handleColor:p,handleSize:h,handleStroke:y,editable:g,data:m,targetRow:b,targetRows:w,channel:x,field:S}=t,v=n.domain(),k=Math.min(...v.map(Co)),_=Math.max(...v.map(Co)),T=_-k||1,L=40,N=a?"y":"x",I=a?s+l:i,O=a?s:i+l,M=XE(x),$=x==="opacity"||x==="fillOpacity"||x==="strokeOpacity",F=D=>M?{fill:D}:$?{fill:f,fillOpacity:Number(D)}:{fill:"#94a3b8"};for(let D=0;D<L;D++){const z=D/L,j=(D+1)/L,G=k+(z+j)/2*T,J=typeof n.encode=="function"?n.encode(G):n(G);if(a){const re=s+(1-j)*l;e.push({type:"rect",x:i,y:re,width:u,height:l/L+.5,...F(J),stroke:"none",background:!0,pointerEvents:"none"})}else{const re=i+z*l;e.push({type:"rect",x:re,y:s,width:l/L+.5,height:u,...F(J),stroke:"none",background:!0,pointerEvents:"none"})}}e.push({type:"rect",x:i,y:s,width:a?u:l,height:a?l:u,fill:"none",stroke:d,strokeWidth:1,background:!0,pointerEvents:"none"});for(const D of r){const z=(Co(D)-k)/T;if(!(z<-.001||z>1.001))if(a){const j=s+(1-z)*l;e.push({type:"text",x:i+u+4,y:j+c*.35,text:String(o(D)),fill:f,fontSize:c,textAnchor:"start",background:!0,pointerEvents:"none"})}else{const j=i+z*l;e.push({type:"text",x:j,y:s+u+c+2,text:String(o(D)),fill:f,fontSize:c,textAnchor:"middle",background:!0,pointerEvents:"none"})}}if(g&&b!=null){const D=S??(n.fields&&n.fields[0]||null),z=D!=null?m[b]&&m[b][D]:null,j=z==null?.5:Math.max(0,Math.min(1,(Co(z)-k)/T)),G=a?i+u/2:i+j*l,J=a?s+(1-j)*l:s+u/2;e.push({type:"circle",cx:G,cy:J,r:h,fill:p,stroke:y,strokeWidth:1.5,index:b,indices:w,along:N,rampStart:I,rampEnd:O,loValue:k,hiValue:_,cursor:a?"ns-resize":"ew-resize"})}}const s6=(e={})=>Ns({...e,channel:e.channel||"fill"}),a6=(e={})=>Ns({...e,channel:"size"}),l6=(e={})=>Ns({...e,channel:"symbol"}),Bc=["fill","stroke","size","symbol","opacity","theta","strokeWidth"];function c6(e){const t=(e||[]).flat(1/0).filter(r=>r&&typeof r=="object"),n=[];for(const r of t){if(r.views==="scale"||!r.channels)continue;const o=new Set(r.rawChannels||[]);for(const[i,s]of Object.entries(r.channels)){const a=s;!a||a.field==null||a.scale===null||o.has(i)||Gr(a)||n.some(l=>l.channel===i&&l.field===a.field)||n.push({channel:i,field:a.field,table:r.table,tableRole:r.tableRole,spec:a,feature:r})}}return n}function u6(e,t){const n=(e||[]).flat(1/0).filter(l=>l&&typeof l=="object"),r=c6(e),o=l=>r.filter(u=>u.channel===l),i=n.filter(l=>l.isLegend);for(const l of i){if(l.field!=null)continue;const u=o(l.channel);u.length&&(u.length>1&&ge(`legend:ambiguous:${l.channel}`,`legend({ channel: "${l.channel}" }) — "${l.channel}" carries ${u.length} encodings (${u.map(c=>`"${c.field}"`).join(", ")}), and a legend is a key for one. Name which: legend({ channel: "${l.channel}", field: "${u[0].field}" }). Using "${u[0].field}".`),l.field=u[0].field,l.table==null&&(l.table=u[0].table),l.tableRole==null&&(l.tableRole=u[0].tableRole))}const s=(l,u)=>i.find(c=>c.channel===l&&c.field===u),a=[];for(const l of r){const{channel:u,field:c,spec:d}=l,f=d.legend;if(f===!1||f===null)continue;const p=[d.edit].flat(1/0).filter(S=>S&&typeof S.apply=="function"),h=p.filter(S=>S.scope==="legend");let y;if(f!==void 0)y=f===!0?{}:f;else if(h.length)y={};else{if(!t)continue;const S=t===!0?void 0:t[u];if(S===!1||t!==!0&&S===void 0||!Bc.includes(u))continue;y=S||{}}if(!Bc.includes(u)){ge(`legend:channel:${u}`,`a legend was asked for on channel "${u}", which has no legend form. Legendable channels are ${Bc.join(", ")}.`+(u==="x"||u==="y"?" An axis is the key for x/y.":""));continue}if(h.length){const S=p.filter(k=>k.scope!=="legend"),v={...d};S.length?v.edit=S.length===1?S[0]:S:delete v.edit,l.feature.channels[u]=v}const g=s(u,c);if(g){const S=[...h,...Wi(y,u)];S.length&&(g.edits=[...g.edits||[],...Wi({edits:S},u)]);for(const[v,k]of Object.entries(y))v==="edit"||v==="edits"||g[v]===void 0&&(g[v]=k);continue}const{edit:m,edits:b,...w}=y,x=Ns({...w,channel:u,field:c,table:l.table,edits:[...Wi(y,u),...h]});x.tableRole=l.tableRole,a.push(x)}return a}function f6(e,t,n,r=8){const o={top:0,right:0,bottom:0,left:0},i=(e||[]).filter(a=>a&&a.isLegend&&typeof a.measure=="function");if(!i.length)return o;const s={top:n.top+r,right:n.right+r,bottom:n.bottom+r,left:n.left+r};for(const a of i){const l=a.anchor||"right",c=t[uo(a.channel,a.field)]||t[a.channel]?a.measure(t):null;if(!c){a._place.offset=0,a._place.size=0;continue}const d=a.orient==="vertical"?c.width:c.height;a._place.offset=s[l],a._place.size=d,s[l]+=d+r,o[l]+=d+r}return o}function nt(e){return e?e.id&&!e.autoId?`"${e.id}"`:e.type?`${e.type}()`:e.id?`"${e.id}"`:"(an unnamed mark)":"(unknown mark)"}const d6={line:{flag:"supportsSeries",expects:"a line mark (line/area)"},geo:{flag:"supportsGeo",expects:"a geo* mark (geoPoint, geoLine, …)"},stack:{flag:"supportsStack",expects:"a stacked mark (bar with `stack`, or arc/donut)"},waffle:{flag:"supportsWaffle",expects:"a waffle mark"},axis:{flag:"isAxis",expects:"an axis element (axisX/axisY/axisRadial)"},trend:{flag:"supportsTrend",expects:"a trend mark (trend/trendBand)"},network:{flag:"supportsNetwork",expects:"a link mark"},legend:{flag:"isLegend",expects:"a legend element"},scale:{test:e=>e.views==="scale",expects:"an axis or legend element"}},h6={discrete:e=>e==="band"||e==="point",band:e=>e==="band",point:e=>e==="point",continuous:e=>e==="continuous"};function p6(e,t){const n=e&&e.requires;if(Array.isArray(n))for(const r of n){const o=h6[r.kind];if(!o)continue;const i=r.channels||[],s=c=>{const d=t[c];return!!(d&&o(d.kind))};if(r.match==="any"?i.some(s):i.every(s))continue;const l=r.match==="any"?`one of ${i.map(c=>`"${c}"`).join(" / ")}`:i.map(c=>`"${c}"`).join(" and "),u=i.map(c=>{const d=t[c];return`${c}: ${d?d.kind:"no scale"}`}).join(", ");ge(`requires:${nt(e)}:${r.kind}:${i.join(",")}`,`mark ${nt(e)} needs a ${r.kind} scale on ${l}, but got ${u}. ${r.why||""} It will still draw, using fallback geometry that is not meaningful — declare the field's type on the spec's schema so the right scale resolves.`)}}function y6(e,t){for(const n of t){if(!n.scope)continue;const r=d6[n.scope];r&&((r.test?r.test(e):e[r.flag])||ge(`${nt(e)}:${n.type}`,`edit.${n.type}() is attached to a mark without ${n.scope} support (mark ${nt(e)}). ${n.scope}-scoped edits expect ${r.expects}; it may not behave.`))}}function g6(e,t){if(!t.projection)return;const n=e.filter(r=>{if(r.supportsGeo||r.views==="scale")return!1;const o=r.channels||{};return Object.keys(o).some(i=>$t(i)&&o[i]&&o[i].scale!==null)});n.length&&ge(`projcartesian:${n.map(nt).join(",")}`,`spec.projection is set together with cartesian x/y channels on ${n.map(nt).join(", ")}. Projection charts use geo* marks (geoPoint, geoLine, …); mixing ordinary positional marks is unsupported.`)}function m6(e,t,n){const r={};for(const o of e)for(const i of t(o)){if(i.pick==="direct")continue;const s=n(o,i),a=r[s]||(r[s]=[]);a.includes(o)||a.push(o)}for(const[o,i]of Object.entries(r))i.length<2||ge(`planedup:${o}:${i.map(nt).join(",")}`,`${i.length} marks carry a plane-pick edit over the same rows (marks ${i.map(nt).join(", ")}). A plane gesture fans to all of them, so a whole-dataset edit (create/remove/rotate/toggle) will apply once per mark. Declare it on exactly one.`)}function b6(e,t,n){const r=s=>t(s).filter(a=>!a.target),o=e.filter(s=>s&&s.isLegend&&r(s).length&&s.row==null);if(!o.length)return;const i=new Set(e.filter(s=>s&&s.views!=="scale"&&t(s).some(a=>a.target==="selection")).map(s=>s.table));for(const s of o)i.has(s.table)||n(s).length<=1||ge(`legend:norow:${s.channel}:${s.id}`,`${nt(s)} is a picker with no way to choose a row. Its target row defaults to the chart's SELECTION, "${s.table}" has more than one row, and no mark over that table carries edit.select(). Add one, pin a row (legend({ row: 0 })), or drive el.select(i) — otherwise clicking a swatch writes nothing.`)}function w6(e,t){if(!t.filter(o=>o.type==="network.connect"&&!o.when).length)return;const r=t.filter(o=>o.type!=="network.connect"&&o.pick==="direct"&&o.gesture==="drag"&&!o.when);r.length&&ge(`connectconflict:${nt(e)}`,`mark ${nt(e)} carries edit.network.connect() beside ${r.map(o=>`${o.type}()`).join(", ")}, and neither arbitrates with \`when\`. A plain drag fans to both: the other edit moves the source node along under the pointer, so connect finds that same node at release and creates nothing. Split them — connect({ when: when.shift }) and ${r[0].type}({ when: when.noShift }).`)}const x6=new Set(["append","appendMany","toggle"]);function sd(e){return e.target!=="domain"&&x6.has(e.cardinality)}function v6(e,t,n){for(const r of t){if(!sd(r)||e.supportsGeo)continue;const o=`${nt(e)}:nomark:${r.type}`;if(e.views==="scale"){ge(o,`a create/${r.type} edit is on ${nt(e)}, which is a chart element (axis/grid/legend), not a data mark. Creation mints dataset rows; a guide edits the DOMAIN instead (edit.axis.*). Move the create to a data mark.`);continue}const i=r.channels&&r.channels.length?r.channels:["x","y"];i.some(a=>{const l=n[a];return l&&l.invertible})||ge(o,`a create/${r.type} edit is on ${nt(e)}, but none of its positional channels (${i.join(", ")}) has an invertible scale — the pointer can't be inverted to a datum, so the create is a no-op. Creation needs a data mark on an axis.`)}}function k6(e,t,n){const r=e.channels||{},o=[];r.x1&&r.x2&&o.push(r.x1.field,r.x2.field),r.y1&&r.y2&&o.push(r.y1.field,r.y2.field);const i=o.filter(Boolean);if(i.length)for(const s of t){if(!sd(s))continue;const a=new Set(Object.keys(s.defaults||{})),l=i.filter(u=>!a.has(u)&&!(n&&n[u]&&n[u].default!==void 0));l.length&&ge(`${nt(e)}:extent:${s.type}`,`create/${s.type} on the extent mark ${nt(e)} doesn't seed ${l.join(", ")}, so a new row is minted with no extent (zero-size, invisible). Seed it via create({ defaults: { … } }) or a field default in the schema.`)}}function S6(e,t){for(const n of t)!n.pick||n.pick==="direct"||gr(n)||ge(`${nt(e)}:nopick:${n.pick}`,`${n.type}() on ${nt(e)} has pick: "${n.pick}", which names no registered driver, so no gesture will ever reach it. Built-in picks are direct, plane, nearest, probe, sweep, draw, brush, brushRect, geoBrush, axisDrag, slide; a custom one needs registerDriver().`)}function $6(e,t){for(const n of t){const r=n[M0];if(!r||!r.length)continue;const o=gr(n),i=new Set(o&&o.options?o.options:[]),s=r.filter(a=>!i.has(a));s.length&&ge(`${nt(e)}:editopt:${n.type}:${s.join(",")}`,`${n.type}() on ${nt(e)} was given ${s.map(a=>`\`${a}\``).join(", ")}, which ${s.length>1?"are":"is"} not ${s.length>1?"options":"an option"} this edit${o?` or its "${o.name}" driver`:""} reads, so ${s.length>1?"they are":"it is"} ignored.`)}}function Vp(e){return e?typeof e!="function"&&e.type?`${e.type}()`:e.name?`${e.name}()`:"(an anonymous constraint)":"(unknown)"}function _6(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const t=typeof e;return t==="object"?"an object":t==="string"?`the string ${JSON.stringify(e.slice(0,20))}`:`the ${t} ${String(e)}`}function M6(e,t,n){const r=e.channels||{};for(const o of t){if(!o.inverts||sd(o)||e.supportsGeo)continue;const i=o.channels||[];if(!i.length)continue;const s=i.filter(a=>{const l=r[a];if(!l||l.field==null)return!1;const u=n[a];return u&&!u.invertible});s.length&&ge(`${nt(e)}:dead:${o.type}:${s.join(",")}`,`${o.type}() on ${nt(e)} edits channel${s.length>1?"s":""} ${s.map(a=>`"${a}"`).join(", ")}, whose scale cannot be inverted (${s.map(a=>n[a].type||"ordinal").join(", ")}). An edit runs a gesture BACKWARD through the scale, so a non-invertible channel silently does nothing. Edit a positional channel (x/y), or give the channel a continuous, band or point scale.`)}}const Xp=["width","height","margins","responsive","overflow","focusOutline","marks","elements","guides","axes","legends","schema","data","constraints","lock","scales","projection","theme","effects","stage","stageLabels","onChange","renderer"],E6={mark:"did you mean `marks`? (an array of marks — plot.*)",element:"did you mean `elements`? (an array of chart elements — elements.*)",guide:"did you mean `guides`? (an array of guides — guides.*)",constraint:"did you mean `constraints`? (an array of dataset invariants)",scale:"did you mean `scales`? (per-channel scale config, keyed by channel name)",edit:"an edit goes on a mark — either on a channel (`y: { field, edit: move() }`) or in the mark's `edits: [...]`. There is no chart-level `edit`.",edits:"edits go on a MARK, not on the spec: `barY({ edits: [move()] })`.",onchange:"did you mean `onChange`? (capital C)",domain:"a domain describes the DATA, so it lives on the schema: schema: { field: { domain: [...] } }.",x:"there is no chart-level `x`. Scale config is `scales: { x: {...} }`; a field's domain is the schema's.",y:"there is no chart-level `y`. Scale config is `scales: { y: {...} }`; a field's domain is the schema's.",type:"a chart has no `type` — what it draws is its `marks`. A FIELD's type belongs on the schema; the DATASET's shape is the schema's `structure`.",title:"there is no chart-level `title`. Draw one with a `text` mark, or a widget's `question`.",container:"Elicit returns the chart element — append it yourself: `container.appendChild(Elicit(spec))`.",el:"Elicit returns the chart element; it does not take one."};function A6(e){if(!e||!oi())return;const t=new Set(Xp);for(const n of Object.keys(e)){if(t.has(n))continue;const r=E6[n];ge(`spec:${n}`,r?`Elicit({ ${n}: … }): ${r}`:`Elicit({ ${n}: … }) is not a key the chart reads, so it is ignored. Spec keys are: ${Xp.slice().sort().join(", ")}.`)}}function T6(e,t){const n=t||{},r=e.opacity!=null?e.opacity:1;e.opacity=r*(n.opacity!=null?n.opacity:.45),n.fill!=null&&(e.fill=n.fill),n.stroke!=null&&(e.stroke=n.stroke),n.strokeDasharray!=null&&(e.strokeDasharray=n.strokeDasharray)}function ab(e){A6(e);const{width:t=600,height:n=400,margins:r={top:20,right:20,bottom:30,left:40},marks:o=[],elements:i=[],axes:s,legends:a,guides:l=[],effects:u,responsive:c,overflow:d="hidden",focusOutline:f=!1,renderer:p=new Z0}=e,h=c===!0?"reflow":c==="scale"||c==="reflow"?c:"fixed",y=Xf(e.theme),g=E5(u,y.effects),m=[...i,...o],b=e.projection!=null&&s===void 0?!1:s,w=[...VE(m,b),...m,...u6(m,a)].flat(1/0),x=w.some(E=>E&&E.isLegend),S=typeof t=="number"?t:600,v=typeof n=="number"?n:400;let k=S,_=v;const T=r;let L={...T},N=k-L.left-L.right,I=_-L.top-L.bottom;w.forEach((E,R)=>{E.id||(E.id=`feature-${R}`,E.autoId=!0)});const O=ZM(structuredClone(e.schema||{})),M=O.tables[O.primary].fields;let $=_p(structuredClone(e.data??null),O);const F=E=>$[E.table]||[],D=(E,R)=>R&&R.table&&O.byRole[R.table]||E.table,z=()=>$[O.primary],j=()=>xa(O)?z():$;w.forEach(E=>{const R=E.table;R!=null&&!O.tables[R]&&ge(`${nt(E)}:table:${R}`,`mark ${nt(E)} draws table "${R}", which the schema does not declare. Declared tables: ${Object.keys(O.tables).map(K=>`"${K}"`).join(", ")}. Falling back to "${O.primary}".`),E.table=R!=null&&O.tables[R]?R:O.byRole[E.tableRole]||O.primary});const G=O.byRole.nodes||null;for(let E=0;E<w.length;E++){const R=w[E],K=R&&!R.portHost&&R.views!=="scale"&&R.channels&&R.channels.ports;if(!K)continue;if(delete R.channels.ports,typeof R.nodeBox!="function"){ge(`${nt(R)}:ports:box`,`mark ${nt(R)} has a \`ports\` channel, but it does not declare the box it draws, so there is no edge to put a port on. Put \`ports\` on a mark that draws a node shape: point, rect, ellipse, text, sticker, node, face, or a composite.`);continue}if(!G||R.table!==G){ge(`${nt(R)}:ports:table`,`mark ${nt(R)} has a \`ports\` channel, but it draws table "${R.table}", which is not a network's nodes table. Ports are where links meet NODES: declare schema: { structure: "network", … } and put \`ports\` on the mark drawing the nodes.`);continue}let X=E+1;for(;R.glyph&&X<w.length&&w[X]&&w[X].glyph===R.glyph;)X++;w.splice(X,0,V5(R,K))}const J=w.filter(E=>E&&E.portHost&&E.table===G);J.length>1&&ge("ports:hosts",`${J.length} marks draw ports over the "${G}" table; only the first (${nt(J[0].portHost)}) decides where links may meet a node. Put \`ports\` on one mark.`);const re=J[0]||null,Q=G?w.filter(E=>E&&E.views!=="scale"&&E.table===G&&typeof E.nodeBox=="function"):[],ve=re?re.portHost:Q.find(E=>!E.labelBox)||Q[0]||null;let Ce=null,le=[];const me=()=>{if(!ve)return null;const E=[tt,N,I];if(!Ce||E.some((R,K)=>R!==le[K])){const R=tt,K=N,X=I;Ce=(ne,de,ye)=>ve.nodeBox(ne,de,ye,R,K,X),le=E}return Ce},ce=re?(E,R,K)=>D0(pt(re.channels,"ports",E,!1,R,K),Ms(O)):null,Y={},fe=E=>{if(E in Y)return Y[E];const R=w.filter(X=>X&&X.views!=="scale"&&!X.portHost&&X.table===E&&X.channels),K=(X,ne)=>X.channels[ne]&&X.channels[ne].field||null;for(const X of["source","target","sourceSide","targetSide"]){const ne=new Set(R.map(de=>K(de,X)).filter(Boolean));ne.size>1&&ge(`viewers:${E}:${X}`,`marks drawing table "${E}" name different columns for \`${X}\` (${[...ne].map(de=>`"${de}"`).join(", ")}). An edit writing that table uses the first. Name the column on one mark, or the same column on each.`)}return Y[E]=R.length?R[0].channels:null,Y[E]};let ie={};for(const E of Object.keys($))ie[E]=$[E].length;const U={},we={},xe=E=>(E in U||(U[E]=y5(e.lock,()=>ie[E]||0,E)),U[E]),P=E=>{if(!(E in we)){const R=xe(E);we[E]=R?g5(R):null}return we[E]};jc(O,$);const H={...e,schema:M,schemaSpec:O,theme:y},oe={},he=(E,R)=>{const K=oe[R]||(oe[R]=[]);K.includes(E)||K.push(E)};for(const E of e.constraints||[]){const R=E.table;he(E,R&&(O.byRole[R]||O.tables[R]&&R)||O.primary)}const ke=E=>oe[E]||[],pe=ke(O.primary),$e=[...IE(w),...l];let Te=e.stage!=null?e.stage:0;const Se=Array.isArray(e.stageLabels)?e.stageLabels:[],ae=E=>Se[E]!=null?Se[E]:null,_e=E=>va(E).filter(R=>R.stage==null||R.stage===Te),Pe=E=>{Te=E,Z.session={},Z.preview=null,Z.hover=null,Z.grab=null,Z.selection.clear();for(const R of qt.stage)R(Te,ae(Te))},Z={session:{},preview:null,selection:new Set,hover:null,grab:null};let vt=!1;const rt=E=>E?`${E.index}\0${E.channel??""}\0${E.side??""}\0${E.vertexIndex??""}`:"",dt=(E,R)=>`${E}\0${R}`,gt=E=>{const R=E.indexOf("\0");return{table:E.slice(0,R),index:Number(E.slice(R+1))}},Wt=E=>{const R=new Set;for(const K of Z.selection){const X=gt(K);X.table===E&&R.add(X.index)}return R},At=()=>{for(const E of Wt(O.primary))if(E>=0&&E<z().length)return E;return null},Jt=(E=O.primary)=>{const R=($[E]||[]).length;return[...Wt(E)].filter(K=>K>=0&&K<R).sort((K,X)=>K-X)},qt={change:new Set,stage:new Set,select:new Set,gesture:new Set},Qn=100;let C=[],W=[],q=null,V=[];const ee=()=>({tables:structuredClone($),schema:structuredClone(M),width:k,height:_}),ue=E=>{$=structuredClone(E.tables);for(const R of Object.keys(M))delete M[R];Object.assign(M,structuredClone(E.schema)),(E.width!==k||E.height!==_)&&Rt({width:E.width,height:E.height}),Z.preview=null},be=()=>{q||(q={recorded:!1,before:null,edits:[]})},Oe=(E=!1)=>{const R=q;q=null,E&&R&&R.recorded&&rn(R),V.length&&$1()},Ze=()=>{if(q||be(),!q||q.recorded)return;const E=ee();C.push(E),C.length>Qn&&C.shift(),W=[],q.before=E.tables,q.recorded=!0},rn=E=>{if(!qt.gesture.size)return;const R=new Set,K=E.edits.filter(de=>{const ye=`${de.type}\0${de.name??""}\0${de.table}`;return R.has(ye)?!1:(R.add(ye),!0)}),X=de=>xa(O)?de[O.primary]:de,ne={edits:K,before:structuredClone(X(E.before)),after:structuredClone(j())};for(const de of qt.gesture)de(ne)},wt=()=>{e.onChange&&e.onChange(j());for(const E of qt.change)E(structuredClone(j()))},ct=()=>{const E=At(),R=xa(O)?[...Wt(O.primary)]:[...Z.selection].map(gt);for(const K of qt.select)K(E,R)},zn=(E,R=O.primary)=>{const K=[...Z.selection].join(",");An(E,R);const X=[...Z.selection].join(",");return K===X?!1:(ct(),!0)},An=(E,R=O.primary)=>{if(E.clear||E.index==null){Z.selection.clear();return}const K=dt(R,E.index),X=Z.selection.has(K);if(E.exclusive!==!1){const ne=X&&Z.selection.size===1;if(Z.selection.clear(),E.toggle&&ne)return}else if(E.toggle&&X){Z.selection.delete(K);return}Z.selection.add(K)},Bt={},Ht=(E,R,K)=>{let X=R&&R.frame?R:null;return!X&&K!=null&&E&&(X=(Bt[E.id]||[]).find(ne=>ne&&ne.index===K&&ne.frame)||null),X?{...tt,...X.frame}:null},It={width:N,height:I};let tt=Wc(w,$,H,It);const Xe=document.createElement("div");Xe.style.position="relative",h==="scale"?(Xe.style.width="100%",Xe.style.height="auto"):h==="reflow"?(Xe.style.width="100%",Xe.style.height=`${_}px`):(Xe.style.width=`${k}px`,Xe.style.height=`${_}px`);const Dr=()=>{N=k-L.left-L.right,I=_-L.top-L.bottom,It.width=N,It.height=I},jr=()=>{if(h!=="reflow")return!1;const E=Xe.clientWidth||S;return E>0&&E!==k?(k=E,Dr(),!0):!1},er=new Yw,on=()=>{if(jr(),er.clear(),x){L={...T},Dr();const te=Wc(w,$,H,It);te.theme=y;const Ae=f6(w,te,T);L={top:T.top+Ae.top,right:T.right+Ae.right,bottom:T.bottom+Ae.bottom,left:T.left+Ae.left},Dr()}tt=Wc(w,$,H,It);const E=m0(H.projection,It);E&&(tt.projection=E),tt.theme=y,tt.selection=At(),tt.selectionAll=Jt,tt.schema=M,g6(w,tt);const R=w.some(te=>TE(_e(te)));let K="pointer";if(R&&Z.session)for(const te of Object.keys(Z.session)){const Ae=Z.session[te]&&Z.session[te].cursor;if(Ae){K=Ae;break}}m6(w,_e,D),b6(w,_e,F);const X=[];if(w.forEach(te=>{const Ae=F(te),Le=xe(te.table),Fe=te.build(Ae,tt,N,I,{tables:$,schema:O,table:te.table,nodeBox:me(),nodePorts:ce});Bt[te.id]=Fe;const Ie=va(te);p6(te,tt),y6(te,Ie),w5(te,nt),v6(te,Ie,tt),k6(te,Ie,H.schema),M6(te,Ie,tt),w6(te,Ie),S6(te,Ie),$6(te,Ie);const _t=_e(te).some(We=>We.pick==="direct"),Mt=_e(te).find(We=>We.inline),Ot=Mt?(Ti(Mt.channels,te.channels||{},tt,te)[0]||{}).field:null;Fe.forEach(We=>{We.featureId=te.id;const mt=Le&&m5(We,te,Ae,Le);if(mt&&(We.locked=!0),_t&&!mt?We.editable=!0:We.pointerEvents==null&&(We.pointerEvents="none"),Mt&&!mt&&(We.editText=!0,Mt.multiline&&(We.multiline=!0),Ot!=null&&We.data)){const bt=We.data[Ot];bt!=null&&(We.editValue=String(bt))}}),X.push({glyph:te.glyph,nodes:Fe})}),oh(X).forEach(te=>er.add(te)),Z.preview){const te=Object.values(Z.preview),Ae=te.length===1?te[0]:null,Le=[];for(const Fe of w){if(Fe.views==="scale")continue;const Ie=Z.preview[Fe.id]||Ae;if(!Ie||Ie.table!==Fe.table)continue;const _t=Ie.rows,Mt=F(Fe),Ot=new Set;let We=_t.length!==Mt.length;const mt=Math.max(_t.length,Mt.length);for(let Ke=0;Ke<mt;Ke++)_t[Ke]!==Mt[Ke]&&(Ot.add(Ke),We=!0);if(!We)continue;const ze=Fe.build(_t,tt,N,I,{tables:{...$,[Ie.table]:_t},schema:O,table:Fe.table,ghost:{pointer:Ie.pointer},nodeBox:me(),nodePorts:ce}).filter(Ke=>(Ke.index!=null?Ot.has(Ke.index):We)?(Ke.ghost=!0,Ke.featureId=Fe.id,Ke.editable=!1,Ke.pointerEvents="none",T6(Ke,y.ghost),!0):!1);Le.push({glyph:Fe.glyph,nodes:ze})}oh(Le).forEach(Fe=>er.add(Fe))}const ne={scales:tt,data:z(),tableOf:F,constraintsIn:ke,constraints:pe,features:w,featureNodes:Bt,ui:Z,effects:g,theme:y,width:N,height:I,stage:Te};$e.forEach(te=>{(te.build(ne.data,tt,N,I,ne)||[]).forEach(Le=>{Le.guide=!0,er.add(Le)})});const de={},ye={},Me=te=>{if(!te||te.index==null)return;const Ae=w.find(Le=>Le.id===te.featureId);!Ae||Ae.table==null||(ye[Ae.table]||(ye[Ae.table]=new Set)).add(te.index)};Me(Z.hover),Me(Z.grab),vt=!1;let Ee=null;for(const te of Object.values(Z.session||{}))if(te&&Array.isArray(te.targets)){Ee=Ee||new Set;for(const Ae of te.targets)Ee.add(Ae)}for(const te of w){if(te.views==="scale")continue;const Ae=de[te.table]||(de[te.table]=Wt(te.table)),Le=Bt[te.id]||[],Fe=new Set,Ie=Z.session&&Z.session[te.id],_t=Ie?Ie.activeIndex!=null?Ie.activeIndex:Ie.hoverIndex:null;_t!=null&&Fe.add(_t),Z.hover&&Z.hover.featureId===te.id&&Z.hover.index!=null&&Fe.add(Z.hover.index);for(const ze of Ae)Fe.delete(ze);const Mt=new Set;Z.grab&&Z.grab.featureId===te.id&&Z.grab.index!=null&&Mt.add(Z.grab.index);const Ot=[[Fe,g.hovered],[Ae,g.selected],[Mt,g.grabbed]],We=new Map;for(const[ze,Ke]of Ot)for(const Pt of ze){const zt=We.get(Pt)||[];zt.push(Ke),We.set(Pt,zt)}for(const ze of Le){if(!ze||ze.ghost||ze.index==null)continue;const Ke=A5(We.get(ze.index)||[]);Ke&&(ze.effectStyle=Ke)}const mt=ye[te.table];for(const ze of Le){if(!ze||ze.ghost||!ze.onHover||ze.index==null)continue;vt=!0;const Ke=ze.index,Pt=mt&&mt.has(Ke)||Fe.has(Ke)||Ae.has(Ke)||Mt.has(Ke)||_t===Ke;let zt=Pt;ze.portRole&&(Ee?zt=!!Ie&&Ie.fromIndex===Ke&&Ie.fromSide===ze.side||Ee.has(ed(te.table,Ke,ze.side)):zt=Pt&&ze.portRole!=="in"&&zs(te,ze)),zt||(ze.effectStyle={...ze.effectStyle||{},opacity:0},ze.pointerEvents="none")}const bt=Z.hover&&Z.hover.featureId===te.id&&Z.hover.node&&Z.hover.node.channel!=null?Le.find(ze=>ze&&rt(ze)===rt(Z.hover&&Z.hover.node)):null;for(const[ze,Ke]of Ot){if(!ze.size)continue;let Pt;if(Ke===g.hovered&&bt&&ze.has(bt.index)){const zt=new Set(ze);zt.delete(bt.index),Pt=[...Gf(bt,Ke),...Ap(Le,zt,Ke)]}else Pt=Ap(Le,ze,Ke);Pt.forEach(zt=>{zt.guide=!0,er.add(zt)})}}p.render({container:Xe,scene:er,width:k,height:_,margins:L,scales:tt,spec:e,planeOnTop:R,planeCursor:K,responsive:h,overflow:d,focusOutline:f,effects:g,theme:y,onEvent:Dd})},Ue=(E,R,K,X,ne=!1,de=void 0)=>{const ye=F(E),Me=D(E,R),Ee=$[Me]||[],te=E.channels||{},Ae=Ht(E,K.node,X)||tt,Le=Ti(R.channels,te,Ae,E),Fe={data:Ee,datum:X!=null?ye[X]:void 0,index:X,tables:$,table:Me,pointer:{x:K.x,y:K.y},node:K.node||null,event:K.rawEvent,value:K.value,channels:Le,scales:Ae,markChannels:te,projection:tt.projection||null,width:N,height:I,margins:L,schema:(O.tables[Me]||O.tables[O.primary]).fields,schemaSpec:O,xKey:E.xKey||"x",yKey:E.yKey||"y",seriesKey:E.seriesKey||null,marks:Bt[E.id]||[],connect:E.connect||null,session:de!==void 0?de:Z.session&&Z.session[E.id]||null,nodeBox:me(),nodePorts:ce,targetChannels:Me!==E.table?fe(Me):null,selection:At(),edit:R,preview:ne};if(R.when&&!R.when(Fe))return null;const Ie=R.apply(Fe);if(Ie===void 0)return null;const _t=mt=>R.cardinality==="append"?mt.length-1:R.cardinality==="delete"?null:X,Mt=(mt,bt=Me)=>{const ze=bt===Me,Ke=P(bt),Pt=[...ke(bt),...ze?R.constrain:[],...Ke?[Ke]:[]],zt={activeIndex:ze?_t(mt):null,scales:tt,markChannels:te,field:ze&&Le[0]?Le[0].field:void 0,tables:$,table:bt};let qs=mt;const _1=ze?Ee:$[bt]||[];for(const gc of Pt){const wo=h5(gc,qs,_1,zt);if(wo===!1)return null;if(!(wo===!0||wo===void 0)){if(!Array.isArray(wo)){ge(`constraint:return:${Vp(gc)}`,`constraint ${Vp(gc)} returned ${_6(wo)}; a constraint must return the repaired rows (an array), false to reject the edit, or true/undefined to accept it unchanged. Ignoring the return value.`);continue}qs=wo}}return qs};if(R.target==="domain"){if(!(Ie&&typeof Ie=="object"&&Ie.domains))return null;const mt={...Ie};if(Array.isArray(Ie.data)){const bt=Mt(Ie.data);if(!bt)return null;mt.data=bt}if(Ie.tables){const bt={};for(const[ze,Ke]of Object.entries(Ie.tables)){const Pt=Ke;if(!Array.isArray(Pt.data)){bt[ze]=Pt;continue}const zt=Mt(Pt.data,ze);if(!zt)return null;bt[ze]={...Pt,data:zt}}mt.tables=bt}return{kind:"domain",result:mt}}if(R.target==="selection")return Ie&&typeof Ie=="object"&&"index"in Ie?{kind:"selection",selection:Ie}:null;const Ot=Array.isArray(Ie)?Ie:Ee.map((mt,bt)=>bt===X?Ie:mt),We=Mt(Ot);return We?{kind:"rows",rows:We}:null},Tt=(E,R,K,X)=>{const ne=Ue(E,R,K,X);return ne?(q&&ne.kind!=="selection"&&q.edits.push({type:R.type,name:R.name,table:D(E,R)}),ne.kind==="domain"?Zt(ne.result,D(E,R)):ne.kind==="selection"?zn(ne.selection,D(E,R)):(Ze(),$[D(E,R)]=ne.rows,Dc(O,$),Z.preview=null,wt(),!0)):!1},Zt=(E,R=O.primary)=>{Ze();const K={[R]:{domains:E.domains,data:E.data}};for(const[ne,de]of Object.entries(E.tables||{})){if(!O.tables[ne]){ge(`domain:table:${ne}`,`a domain edit names table "${ne}", which the schema does not declare. Declared tables: ${Object.keys(O.tables).map(Me=>`"${Me}"`).join(", ")}.`);continue}const ye=K[ne];K[ne]=ye?{domains:{...ye.domains,...de.domains},data:de.data??ye.data}:de}let X=!1;for(const[ne,de]of Object.entries(K)){const ye=(O.tables[ne]||O.tables[O.primary]).fields;for(const[Me,Ee]of Object.entries(de.domains||{})){const te=ye[Me];ye[Me]={...te||{type:y0(Ee)},domain:Ee}}Array.isArray(de.data)&&($[ne]=de.data,X=!0)}return X&&Dc(O,$),E.resize&&Rt(E.resize),Z.preview=null,wt(),!0},Rt=E=>{typeof E.width=="number"&&E.width>0&&(k=E.width),typeof E.height=="number"&&E.height>0&&(_=E.height),h==="fixed"?(Xe.style.width=`${k}px`,Xe.style.height=`${_}px`):h==="reflow"&&(Xe.style.height=`${_}px`),Dr()},sn=(E,R,K,X)=>{const ne=Ue(E,R,K,X,!0);if(!ne||ne.kind!=="rows")return!1;const de=ne.rows;return Z.preview||(Z.preview={}),Z.preview[E.id]={table:D(E,R),rows:de,pointer:typeof K.x=="number"&&typeof K.y=="number"?{x:K.x,y:K.y}:void 0},!0},tr=(E,R,K,X,ne)=>{if(typeof R.targets!="function")return null;const de=D(E,R),ye={scales:tt,schemaSpec:O,tables:$,table:de,data:$[de]||[],nodeBox:me(),nodePorts:ce,width:N,height:I,node:X||null,edit:R,pointer:{x:0,y:0},index:K,datum:K!=null?F(E)[K]:void 0,markChannels:E.channels||{}},Me=[],Ee=R.targets(ye);if(!Ee)return null;for(const te of Ee)Ue(E,R,{x:te.x,y:te.y,node:X},K,!1,ne)!==null&&Me.push(te.key);return Me},yo=new Map;let go=[];const zs=(E,R)=>{const K=Object.keys($).map(Me=>$[Me]);(K.length!==go.length||K.some((Me,Ee)=>Me!==go[Ee]))&&(yo.clear(),go=K);const X=`${E.id}\0${R.index}\0${R.side}`,ne=yo.get(X);if(ne!==void 0)return ne;let de=!1;const ye={...Z.session&&Z.session[E.id]||{},fromIndex:R.index,fromSide:R.side,fromPoint:null};for(const Me of _e(E)){const Ee=tr(E,Me,R.index,R,ye);if(Ee&&Ee.length){de=!0;break}}return yo.set(X,de),de},yc=(E,R)=>{const K=R.node?R.node.index:void 0;if(K==null)return!1;let X=!1;const ne=_e(E).filter(ye=>ye.pick==="direct"&&(!R.editName||ye.name===R.editName)),de=ne.filter(ye=>gr(ye));return de.length&&Ds(E,R,de,K)&&(X=!0),ne.filter(ye=>ye.gesture===R.type&&!gr(ye)).forEach(ye=>{Tt(E,ye,R,K)&&(X=!0)}),X},Ds=(E,R,K,X)=>{if(K.length===0)return!1;const ne=E.id,de=(Le,Fe)=>Tt(E,Le,R,Fe),ye=(Le,Fe)=>sn(E,Le,R,Fe),Me={get:()=>Z.preview&&Z.preview[ne]||null,clear:()=>!Z.preview||!Z.preview[ne]?!1:(delete Z.preview[ne],Object.keys(Z.preview).length===0&&(Z.preview=null),!0)},Ee={get:()=>Te,set:Le=>Pe(Le),next:()=>Pe(Te+1)},te=new Map;for(const Le of K){const Fe=gr(Le);if(!Fe)continue;const Ie=te.get(Fe)||[];Ie.push(Le),te.set(Fe,Ie)}let Ae=!1;for(const Le of zo){const Fe=te.get(Le);if(!Fe)continue;const Ie=Le.sessionKeys||[],_t={get:()=>Z.session&&Z.session[ne]||null,set:Ot=>{Z.session=Z.session||{},Z.session[ne]={...Z.session[ne]||{},...Ot}},clear:()=>{if(!Z.session||!Z.session[ne])return;const Ot={};for(const We of Ie)Ot[We]=null;Z.session[ne]={...Z.session[ne],...Ot}}},Mt={feature:E,event:R,edits:Fe,marks:Bt[ne]||[],data:F(E),scales:tt,index:X??null,session:_t,preview:Me,stage:Ee,runEdit:de,previewEdit:ye,reachable:(Ot,We,mt)=>tr(E,Ot,We,mt!==void 0?mt:R.node)};Le.onEvent(Mt)&&(Ae=!0)}return Ae},js=(E,R)=>Ds(E,R,_e(E).filter(K=>K.pick!=="direct"),null),Dd=E=>{let R=!1;if(E.type==="pointerover"||E.type==="pointerout"){const K=E.node,X=E.type==="pointerover"&&K&&K.index!=null?{featureId:K.featureId,index:K.index,node:K}:null,ne=(ye,Me)=>!ye&&!Me||!!(ye&&Me&&ye.featureId===Me.featureId&&ye.index===Me.index&&rt(ye.node)===rt(Me.node));if(!(E.type==="pointerout"&&Z.hover&&K&&!ne(Z.hover,{featureId:K.featureId,index:K.index,node:K}))&&!ne(Z.hover,X)){Z.hover=X;const ye=g.hovered;ye&&ye.enabled!==!1&&(ye.outline||Uu(ye))&&(R=!0),vt&&(R=!0)}R&&on();return}if(E.type==="nudge"){const K=E.node,X=Rn(K);if(!X)return;const ne=w.find(Ae=>Ae.id===K.featureId),de=ne&&ne.channels||{},ye=K.index!=null?(ne?F(ne):[])[K.index]:K.data,Me=Ht(ne,K,K.index)||tt,Ee=ye?se(Me,de,"x",ye,X.cx):X.cx,te=ye?se(Me,de,"y",ye,X.cy):X.cy;E={type:"drag",node:K,x:Hu(Me.x,Ee,E.dx,E.coarse),y:Hu(Me.y,te,E.dy,E.coarse),nudge:!0,rawEvent:E.rawEvent}}if(E.type==="dragstart"?(Oe(!0),be()):q||be(),E.type==="dragstart"||E.type==="dragend"){const K=E.type==="dragstart"&&E.node&&E.node.index!=null?{featureId:E.node.featureId,index:E.node.index}:null,X=!!Z.grab!=!!K||!!(Z.grab&&K&&(Z.grab.featureId!==K.featureId||Z.grab.index!==K.index));Z.grab=K;const ne=g.grabbed;X&&ne&&ne.enabled!==!1&&(ne.outline||Uu(ne))&&(R=!0)}if(E.node){const K=w.find(X=>X.id===E.node.featureId);K&&yc(K,E)&&(R=!0)}else w.forEach(K=>{js(K,E)&&(R=!0)});(E.type==="dragend"||E.nudge||E.type!=="dragstart"&&E.type!=="drag")&&Oe(!0),R&&on()},Qe=Xe;Qe.getData=()=>structuredClone(j()),Qe.getSchema=()=>structuredClone(QM(O)),Qe.setData=E=>{$=_p(structuredClone(E??null),O),jc(O,$,"setData()"),ie={};for(const R of Object.keys($))ie[R]=$[R].length;Z.preview=null,Z.hover=null,Z.grab=null,Z.selection.clear(),C=[],W=[],V=[],Oe(),on()};const jd=E=>{const R=O.tables[E];if(!R)throw new Error(`patch(): there is no table named "${E}".`);const K=Object.entries(R.fields),X=K.filter(([,de])=>de&&de.key).map(([de])=>de);if(X.length)return X;const ne=K.filter(([,de])=>de&&de.type==="ref").map(([de])=>de);if(ne.length)return ne;throw new Error(`patch(): table "${E}" has no key field (\`key: true\`) and no \`ref\` fields, so its rows cannot be addressed.`)},nr=(E,R)=>JSON.stringify(E.map(K=>R?R[K]:void 0)),v1=(E,R)=>Array.isArray(R)?JSON.stringify(R):R!=null&&typeof R=="object"?nr(E,R):JSON.stringify([R]),k1=E=>Object.entries(E||{}).map(([R,K])=>{const X=jd(R);return{name:R,fields:X,insert:K.insert||[],update:K.update||[],remove:new Set((K.remove||[]).map(ne=>v1(X,ne)))}}),Wd=(E,R,K)=>{for(const X of R){let ne=E[X.name]||[];X.remove.size&&(ne=ne.filter(ye=>!X.remove.has(nr(X.fields,ye))));const de=new Map(ne.map((ye,Me)=>[nr(X.fields,ye),Me]));for(const ye of X.update){const Me=nr(X.fields,ye),Ee=de.get(Me);if(Ee===void 0){K&&K.missing.push({table:X.name,key:JSON.parse(Me)});continue}ne[Ee]={...ne[Ee],...structuredClone(ye)},K&&K.updated++}for(const ye of X.insert){const Me=nr(X.fields,ye);if(de.has(Me)){K&&K.conflicts.push({table:X.name,key:JSON.parse(Me)});continue}de.set(Me,ne.length),ne.push(structuredClone(ye)),K&&K.inserted++}E[X.name]=ne}Dc(O,E)},qd=(E,R)=>{const K=[...Z.selection].map(gt).map(({table:Ee,index:te})=>{const Ae=O.tables[Ee]?S1(Ee):null;return{table:Ee,key:Ae?nr(Ae,($[Ee]||[])[te]):null,fields:Ae}}),X={};for(const Ee of E)X[Ee.name]=new Set(($[Ee.name]||[]).slice(0,ie[Ee.name]||0).map(te=>nr(Ee.fields,te)));const ne=Object.fromEntries(Object.entries($).map(([Ee,te])=>[Ee,te.length]));R==="record"&&(C.push(ee()),C.length>Qn&&C.shift(),W=[]);const de={inserted:0,updated:0,removed:0,missing:[],conflicts:[]};if(Wd($,E,de),jc(O,$,"patch()"),R==="keep")for(const Ee of[...C,...W])Wd(Ee.tables,E);let ye=0;for(const Ee of new Set([...Object.keys(ne),...Object.keys($)]))ye+=(ne[Ee]||0)-($[Ee]||[]).length;de.removed=ye+de.inserted;for(const Ee of E)ie[Ee.name]&&(ie[Ee.name]=($[Ee.name]||[]).filter(te=>X[Ee.name].has(nr(Ee.fields,te))).length);const Me=[...Z.selection].join("|");Z.selection.clear();for(const{table:Ee,key:te,fields:Ae}of K){if(te==null||!Ae)continue;const Le=($[Ee]||[]).findIndex(Fe=>nr(Ae,Fe)===te);Le>=0&&Z.selection.add(dt(Ee,Le))}return Z.preview=null,Z.hover=null,wt(),[...Z.selection].join("|")!==Me&&ct(),on(),de},S1=E=>{try{return jd(E)}catch{return null}},$1=()=>{const E=V;V=[];for(const R of E)qd(R.plan,R.history)};Qe.patch=(E,R={})=>{const K=R.history??"keep";if(K!=="keep"&&K!=="record")throw new Error(`patch(): history is "keep" or "record", not "${K}".`);const X=k1(E);return q&&(V.length||X.some(ne=>ne.remove.size))?(V.push({plan:X,history:K}),{deferred:!0}):qd(X,K)},Qe.getSelection=()=>At(),Qe.getSelectionAll=()=>Jt();const Ws=E=>{const R=zn(E);return R&&on(),R};Qe.select=E=>{const R=z(),K=ne=>typeof ne=="number"&&ne>=0&&ne<R.length;if(Array.isArray(E)){const ne=E.filter(K);if(!ne.length)return Ws({index:null,clear:!0});const de=[...Z.selection].join(",");An({index:ne[0],exclusive:!0,toggle:!1});for(const ye of ne.slice(1))An({index:ye,exclusive:!1,toggle:!1});return[...Z.selection].join(",")===de?!1:(ct(),on(),!0)}const X=K(E)?E:null;return Ws({index:X,exclusive:!0,toggle:!1,clear:X==null})},Qe.toggleSelection=E=>Ws({index:E,exclusive:!1,toggle:!0}),Qe.selectAll=()=>Qe.select(z().map((E,R)=>R)),Qe.selectWhere=(E,R,K)=>{const X=typeof E=="function"?E:ye=>ye&&ye[E]===R,ne=z();if(K&&K.all){const ye=ne.map((Me,Ee)=>X(Me,Ee)?Ee:-1).filter(Me=>Me>=0);return Qe.select(ye.length?ye:null)}const de=ne.findIndex(X);return Qe.select(de<0?null:de)},Qe.clearSelection=()=>Ws({index:null,clear:!0}),Qe.emit=E=>Dd(E);const mo=E=>{let R=null;const K=new Set;for(const X of w)for(const ne of va(X))ne.name===E&&(K.add(ne.apply),R||(R={feature:X,edit:ne}));return K.size===0&&ge(`control:none:${E}`,`el.control("${E}"): no edit is named "${E}".`),K.size>1&&ge(`control:many:${E}`,`el.control("${E}"): ${K.size} different edits share the name "${E}"; driving the first.`),R},bo=(E,R)=>(Bt[E.id]||[]).find(K=>K&&K.index===R)||null;Qe.control=(E,R=0)=>{const K=(de,ye,Me)=>{const Ee=bo(de,R),te=Rn(Ee),Ae=z()[R],Le=de.channels||{},Fe=Ht(de,Ee,R)||tt;let Ie=Ae?se(Fe,Le,"x",Ae,te?te.cx:0):te?te.cx:0,_t=Ae?se(Fe,Le,"y",Ae,te?te.cy:0):te?te.cy:0;const Mt=Ti(ye.channels,Le,Fe,de),Ot=We=>Me!=null&&typeof Me=="object"&&!(Me instanceof Date)?We.name in Me?Me[We.name]:We.field!=null&&We.field in Me?Me[We.field]:void 0:Me;for(const We of Mt){if(!We.scale||!We.scale.invertible)continue;const mt=Ot(We);if(mt===void 0)continue;const bt=We.scale.encode(mt),ze=HM(We.name,bt,te);if(!ze)continue;const Ke=$t(We.name);Ke!=="y"&&(Ie=ze.x),Ke!=="x"&&(_t=ze.y)}return{node:Ee,x:Ie,y:_t}};let X=!1;return{set(de){const ye=mo(E);if(!ye)return;const{feature:Me,edit:Ee}=ye,te=bo(Me,R);if(Ee.gesture==="commit"){Qe.emit({type:"commit",node:te,value:de,editName:E,x:te?te.cx:0,y:te?te.cy:0});return}const{node:Ae,x:Le,y:Fe}=K(Me,Ee,de);Qe.emit(X?{type:"drag",node:Ae,x:Le,y:Fe,editName:E}:{type:"drag",node:Ae,x:Le,y:Fe,nudge:!0,editName:E})},begin(){const de=mo(E);de&&(X=!0,Qe.emit({type:"dragstart",node:bo(de.feature,R),editName:E}))},end(){const de=mo(E);X=!1,de&&Qe.emit({type:"dragend",node:bo(de.feature,R),editName:E})},fire(de){const ye=mo(E);if(!ye)return;const Me=de||ye.edit.gesture||"click";Qe.emit({type:Me,node:bo(ye.feature,R),editName:E})},emit(de){const ye=mo(E);Qe.emit({node:ye?bo(ye.feature,R):void 0,...de})},accepts(){const de=mo(E);if(!de)return null;const{feature:ye,edit:Me}=de,Ee=Ht(ye,null,R)||tt,te=Ti(Me.channels,ye.channels||{},Ee,ye)[0],Ae=te&&te.scale,Le=M&&te&&te.field&&M[te.field]||null,Fe=Le&&Le.type||null,Ie=(Ae&&typeof Ae.domain=="function"?Ae.domain():null)||Le&&Le.domain||null,_t=Ae&&typeof Ae.range=="function"?Ae.range():null;return{field:te?te.field:null,type:Fe,kind:Ae?Ae.kind:null,temporal:!!(Ae&&Ae.temporal),invertible:!!(Ae&&Ae.invertible),domain:Ie,values:Ae&&(Ae.kind==="band"||Ae.kind==="discrete"||Ae.kind==="point")||Fe==="categorical"||Fe==="ordinal"?Ie:null,range:_t}}}},Qe.canUndo=()=>C.length>0,Qe.canRedo=()=>W.length>0,Qe.undo=()=>C.length?(W.push(ee()),ue(C.pop()),Oe(),wt(),on(),!0):!1,Qe.redo=()=>W.length?(C.push(ee()),ue(W.pop()),Oe(),wt(),on(),!0):!1,Qe.on=(E,R)=>(qt[E].add(R),()=>qt[E].delete(R)),Qe.getStage=()=>Te,Qe.getStageLabel=()=>ae(Te),Qe.setStage=E=>{Pe(E),on()},Qe.nextStage=()=>Qe.setStage(Te+1);let ui=null;if(h==="reflow"&&typeof ResizeObserver<"u"){let E=!1;ui=new ResizeObserver(()=>{E||(E=!0,requestAnimationFrame(()=>{E=!1,jr()&&on()}))}),ui.observe(Xe)}return Qe.destroy=()=>{ui&&(ui.disconnect(),ui=null)},setTimeout(on,0),Qe}function ad(e,t,n,r={}){const o=n.filter(s=>t&&t[s]&&t[s].field!=null),i=new Map;return e.forEach((s,a)=>{const l=o.length?o.map(c=>String(Nn(t,c,s,r[c],a,e))).join("\0"):"__all__";let u=i.get(l);u||(u={key:l,rep:s,members:[]},i.set(l,u)),u.members.push(a)}),[...i.values()]}function tc(e,t,n){const r=e.map(s=>{const a=t[s],l=n!=null&&a?Number(a[n]):NaN;return Number.isFinite(l)&&l>0?l:0}),o=[];let i=0;for(const s of r)o.push([i,i+s]),i+=s;return{mags:r,total:i,bounds:o}}function ds({members:e,local:t,field:n,geometry:r}){return{members:e,local:t,field:n,geometry:r}}function O6(e,t,n){if(!n)return e;const r=[];for(const i of t){const s=i[n];r.includes(s)||r.push(s)}const o=i=>{const s=r.indexOf(t[i][n]);return s<0?r.length:s};return[...e].sort((i,s)=>o(i)-o(s))}function C6(e,t,n,r,o,i){const s=new Map;for(const a of ad(e,t,[n],{[n]:r})){const l=O6(a.members,e,i),{bounds:u}=tc(l,e,o);l.forEach((c,d)=>{s.set(c,{y0:u[d][0],y1:u[d][1],members:l,local:d})})}return s}function N6(e){const t=at(e,{mark:"bar",allow:st.bar}),{channels:n={},id:r,edits:o,orientation:i,stack:s,handles:a=!0,handleSize:l,handleColor:u}=t,{xKey:c,yKey:d}=Xt(n),f=!!(n.x1&&n.x2),p=!!(n.y1&&n.y2),h=s?Os(n):null,y=!!s&&!f&&!p,g=o||[],m=g.some(b=>b&&b.scope==="stack");return{...lt(t),type:"bar",channels:n,rawChannels:["series"],edits:g,supportsStack:y,discreteScale:"band",xKey:c,yKey:d,build:(b,w)=>{const{x,y:S}=w,v=Zf(kr(n,w,{orientation:i})),k=v==="horizontal"?"y":"x",_=v==="horizontal"?"x":"y",T=v==="horizontal"?d:c,L=v==="horizontal"?c:d,N=y?C6(b,n,k,T,L,h):null,I=Nt(w,"bar",y?{fill:it(w).ink,stroke:it(w).handleStroke,strokeWidth:1}:{fill:it(w).ink}),O=fn(w,{handles:a,handleSize:l,handleColor:u}),M={kind:"linear",axis:_},$=D=>{const z=N&&N.get(D);return z?ds({members:z.members,local:z.local,field:L,geometry:M}):void 0},F=b.map((D,z)=>{const j=yt(w,n,D,I,z,b),G=$(z);if(v==="horizontal"){const le=Yr(S,Nn(n,"y",D,d,z,b),0),me=yn(S,20),ce=yr(x);let Y,fe;if(f){const ie=se(w,n,"x1",D,ce,z,b),U=se(w,n,"x2",D,ce,z,b);Y=Math.min(ie,U),fe=Math.max(ie,U)}else if(N){const{y0:ie,y1:U}=N.get(z)||{y0:0,y1:D[c]},we=Lt(w,n,"x",ie,ce),xe=Lt(w,n,"x",U,ce);Y=Math.min(we,xe),fe=Math.max(we,xe)}else{const ie=se(w,n,"x",D,ce,z,b);Y=Math.min(ie,ce),fe=Math.max(ie,ce)}return{type:"rect",x:Y,y:le,width:fe-Y,height:me,...j,data:D,index:z,orientation:v,bandAxis:"y",...G?{stack:G}:{}}}const J=Yr(x,Nn(n,"x",D,c,z,b),0),re=yn(x,20),Q=yr(S);let ve,Ce;if(p){const le=se(w,n,"y1",D,Q,z,b),me=se(w,n,"y2",D,Q,z,b);ve=Math.min(le,me),Ce=Math.max(le,me)}else if(N){const{y0:le,y1:me}=N.get(z)||{y0:0,y1:D[d]},ce=Lt(w,n,"y",le,Q),Y=Lt(w,n,"y",me,Q);ve=Math.min(ce,Y),Ce=Math.max(ce,Y)}else{const le=se(w,n,"y",D,Q,z,b);ve=Math.min(le,Q),Ce=Math.max(le,Q)}return{type:"rect",x:J,y:ve,width:re,height:Ce-ve,...j,data:D,index:z,orientation:v,bandAxis:"x",...G?{stack:G}:{}}});if(N&&m&&O.grabbable){const D=k==="x"?x:S,j=yr(_==="x"?x:S),G=yn(D,20),J=new Set;for(const re of N.values()){const Q=re.members;if(J.has(Q))continue;J.add(Q);const ve=b[Q[0]],le=Yr(D,Nn(n,k,ve,T,Q[0],b),0)+G/2;for(let me=0;me<Q.length-1;me++){const ce=Q[me],Y=N.get(ce);if(!Y)continue;const fe=Lt(w,n,_,Y.y1,j);F.push({type:"circle",cx:_==="x"?fe:le,cy:_==="x"?le:fe,r:O.size,fill:O.visible?O.fill:"transparent",stroke:O.visible?O.stroke:"none",strokeWidth:O.visible?O.strokeWidth:0,cursor:"grab",data:b[ce],index:ce,edge:!0,loIndex:ce,hiIndex:Q[me+1],stack:ds({members:Q,local:me,field:L,geometry:M})})}}}return F}}}function ld(e={}){return N6(e)}function nc(e={}){return ld({...e,orientation:"vertical"})}function I6(e={}){return ld({...e,orientation:"horizontal"})}function oa(e,t,n,r,o,i,s,a,l,u){const c=e+"1",d=e+"2";if(t[c]&&t[d]){const y=se(n,t,c,o,0,l,u),g=se(n,t,d,o,0,l,u);return{lo:Math.min(y,g),hi:Math.max(y,g),band:!1}}const f=e==="x"?"width":"height";if(t[f]){const y=se(n,t,f,o,0,l,u),[g,m]=r?oo(r):[0,a],b=se(n,t,e,o,(g+m)/2,l,u);return{lo:b-y/2,hi:b+y/2,band:!1}}if(!s&&Vn(r)){const y=Yr(r,Nn(t,e,o,i,l,u),0),g=yn(r,20);return{lo:y,hi:y+g,band:!0}}if(t[e]){const y=yr(r),g=se(n,t,e,o,y,l,u);return{lo:Math.min(g,y),hi:Math.max(g,y),band:!1}}const[p,h]=r?oo(r):[0,a];return{lo:Math.min(p,h),hi:Math.max(p,h),band:!1}}function L6(e){const t=at(e,{mark:"rect",allow:st.rect}),n=t.orientation==="vertical"?"y":t.orientation==="horizontal"?"x":null,{channels:r={},id:o,edits:i,width:s,height:a,rx:l}=t;s!==void 0&&!r.width&&(r.width={value:s}),a!==void 0&&!r.height&&(r.height={value:a}),l!==void 0&&!r.rx&&(r.rx={value:l});const{xKey:u,yKey:c}=Xt(r);return{...lt(t),type:"rect",channels:r,discreteScale:"band",xKey:u,yKey:c,nodeBox:(d,f,p,h,y,g)=>{const m=oa("x",r,h,h.x,d,u,n==="x",y,f,p),b=oa("y",r,h,h.y,d,c,n==="y",g,f,p);return{cx:(m.lo+m.hi)/2,cy:(b.lo+b.hi)/2,hw:(m.hi-m.lo)/2,hh:(b.hi-b.lo)/2}},build:(d,f,p,h)=>{const{x:y,y:g}=f,m=Nt(f,"rect",{fill:it(f).ink});return d.map((b,w)=>{const x=yt(f,r,b,m,w,d),S=oa("x",r,f,y,b,u,n==="x",p,w,d),v=oa("y",r,f,g,b,c,n==="y",h,w,d);let k;S.band&&!v.band?k="x":v.band&&!S.band&&(k="y");const _=zr(f,r,"angle",b,0,w,d),T=r.rx?se(f,r,"rx",b,0,w,d):void 0;return{type:"rect",x:S.lo,y:v.lo,width:S.hi-S.lo,height:v.hi-v.lo,...x,data:b,index:w,..._?{angle:_}:{},...T?{rx:T}:{},...k?{bandAxis:k}:{}}})}}}function Is(e={}){return L6(e)}function F6(e={}){return Is({...e,orientation:"horizontal"})}function R6(e={}){return Is({...e,orientation:"vertical"})}function Jp(e,t,n,r,o,i,s,a,l,u,c){const d=n[`${e}1`],f=n[`${e}2`];if(d&&f)return[se(r,n,`${e}1`,o,0,u,c),se(r,n,`${e}2`,o,s,u,c)];if(l!=null&&n[e]){const p=se(r,n,e,o,s/2,u,c);return[p-l/2,p+l/2]}return i0(t,Nn(n,e,o,i,u,c),s,{inset:a,length:l})}function P6(e){const t=at(e,{mark:"tick",allow:st.tick}),{channels:n={},id:r,edits:o,inset:i=0,length:s}=t,{xKey:a,yKey:l}=Xt(n);return{...lt(t),type:"tick",channels:n,discreteScale:"band",xKey:a,yKey:l,build:(u,c,d,f)=>{const{x:p,y:h}=c,y=kr(n,c,{orientation:t.orientation,extent:"span"}),g=Nt(c,"tick",{stroke:it(c).ink,strokeWidth:2});return u.map((m,b)=>{const w=yt(c,n,m,g,b,u),x=zr(c,n,"angle",m,0,b,u);if(y==="x"){const _=se(c,n,"x",m,d/2,b,u),[T,L]=Jp("y",h,n,c,m,l,f,i,s,b,u);return{type:"line",x1:_,x2:_,y1:T,y2:L,...w,data:m,index:b,bandAxis:"y",cursor:"ew-resize",...x?{angle:x}:{}}}const S=se(c,n,"y",m,f/2,b,u),[v,k]=Jp("x",p,n,c,m,a,d,i,s,b,u);return{type:"line",x1:v,x2:k,y1:S,y2:S,...w,data:m,index:b,bandAxis:"x",cursor:"ns-resize",...x?{angle:x}:{}}})}}}function hs(e={}){return P6(e)}function lb(e={}){return hs({...e,orientation:"vertical"})}function z6(e={}){return hs({...e,orientation:"horizontal"})}function D6(e){const t=at(e,{mark:"rule",allow:st.rule}),{channels:n={},id:r,edits:o,strokeDasharray:i,discreteScale:s}=t,a=!!(n.y1||n.y2),l=!!(n.x1||n.x2),u=a?"y":l?"x":null,c=kr(n,null,{orientation:t.orientation,extent:"span",single:"value"}),d=!Object.values(n).some(h=>h&&h.field!=null),{xKey:f,yKey:p}=Xt(n);return{...lt(t),type:"rule",channels:n,discreteScale:s,xKey:f,yKey:p,build:(h,y,g,m)=>{const b=[],w=(x,S)=>{const v=yt(y,n,x||{},Nt(y,"rule",{stroke:it(y).ink,strokeWidth:1}),S,h);if(u){const T=u==="y"?"x":"y",L=T==="x"?g:m,N=yr(y[u]),[I,O]=u==="y"?["y1","y2"]:["x1","x2"],M=n[I]?se(y,n,I,x,N,S,h):N,$=n[O]?se(y,n,O,x,N,S,h):N;if(M===void 0||$===void 0)return;const F=y[T];let D=L/2;if(n[T])if(Vn(F)){const G=Nn(n,T,x,T==="x"?f:p,S,h);D=Yr(F,G,0)+yn(F,0)/2}else D=se(y,n,T,x,L/2,S,h);const z={type:"line",...u==="y"?{x1:D,x2:D,y1:M,y2:$}:{x1:M,x2:$,y1:D,y2:D},...v,data:x,index:S};i!=null&&(z.strokeDasharray=i),b.push(z);return}const k=se(y,n,c,x,void 0,S,h);if(k===void 0)return;const _={type:"line",...c==="y"?{x1:0,x2:g,y1:k,y2:k}:{x1:k,x2:k,y1:0,y2:m},...v,data:x,index:S};i!=null&&(_.strokeDasharray=i),b.push(_)};return d?w(null,-1):h.forEach(w),b}}}function cd(e={}){return D6(e)}function cb(e={}){return cd({...e,orientation:"vertical"})}function j6(e={}){return cd({...e,orientation:"horizontal"})}function W6(e){const t=e&&e.domainConfig;if(Array.isArray(t)&&t.length>=2){const n=Math.min(t[0],t[t.length-1]),r=Math.max(t[0],t[t.length-1]);return[n,r]}return ge("waffle:domain",'a waffle needs a declared DOMAIN on its value axis — one cell is a fixed quantity, so the number of cells is (domain span / unit). Without it the domain falls back to [0, 1] and the grid stops being countable. Declare it: schema: { <field>: { type: "quantitative", domain: [0, max] } }, and bind it to the `count` channel.'),[0,1]}function q6(e){const t=at(e,{mark:"waffle",allow:st.waffle}),{channels:n={},id:r,edits:o,orientation:i,unit:s=1,multiple:a,gap:l=1,shape:u="rect",showEmpty:c=!0,emptyFill:d="#eee"}=t,{xKey:f,yKey:p}=Xt(n),y=Zf(kr(n,null,{orientation:i,single:"other"}))!=="horizontal";return{...lt(t),type:"waffle",channels:n,countAxis:y?"y":"x",discreteScale:"band",xKey:f,yKey:p,requires:[{channels:["x","y"],kind:"discrete",match:"any",why:"a waffle tiles ONE category's block into countable cells, so its category axis has to be a band (an interval to tile)."}],supportsWaffle:!0,build:(g,m)=>{const{x:b,y:w}=m,x=[],S=Nt(m,"waffle",{fill:it(m).ink});return g.forEach((v,k)=>{const _=yt(m,n,v,S,k,g),T=u==="symbol"?cs(m,n,v,k,g)||"·":cs(m,n,v,k,g),L=y?b:w,N="count",I=m.count,M=Yr(L,Nn(n,y?"x":"y",v,y?f:p,k,g),0),$=yn(L,20),F=yr(I),[D,z]=W6(I),j=Math.abs(z-D)||1,G=I?I.encode(z,F):F,J=Math.abs(F-G)||1,re=j/s;Math.abs(re-Math.round(re))>1e-9&&ge("waffle:unit",`a waffle's domain span (${j}) is not a whole number of \`unit\`s (${s}) — it needs ${re.toFixed(2)} cells, so the grid is rounded to ${Math.round(re)} and one cell no longer means exactly ${s}. Pick a unit that divides the domain.`);const Q=Math.max(1,Math.round(re));let ve=a;if(!(ve>=1)){const ke=Math.sqrt(Q*$/J);ve=Number.isFinite(ke)&&ke>=1?Math.floor(ke):1}ve=Math.max(1,Math.min(Q,Math.round(ve)));const Ce=Math.ceil(Q/ve),le=Math.min($/ve,J/Ce),me=($-ve*le)/2,ce=Math.max(.5,le-l),Y={axis:y?"y":"x",sign:y?-1:1,baseline:F,cellSize:le,rows:Ce,multiple:ve,bandStart:M,bandInset:me,unit:s,dlo:D,dhi:z,totalCells:Q},fe=y?-1:1,ie=M+me+l/2,U=Math.min(F,F+fe*Ce*le)+l/2,we=Math.max(0,ve*le-l),xe=Math.max(0,Ce*le-l),P={type:"rect",x:y?ie:U,y:y?U:ie,width:y?we:xe,height:y?xe:we},H=se(m,n,N,v,F,k,g),oe=Math.abs(F-H)/J,he=Math.max(0,Math.min(Q,Math.round(oe*Q)));for(let ke=0;ke<Q;ke++){const pe=Math.floor(ke/ve),$e=ke%ve,Te=ke<he,Se=Te?_:{..._,fill:c?d:"transparent"},ae=M+me+$e*le,_e=F+fe*pe*le,Pe=F+fe*(pe+1)*le,Z=Math.min(_e,Pe);if(T!==void 0){const vt=ae+le/2,rt=(_e+Pe)/2,dt={..._,data:v,index:k,grid:Y,effectShape:P};Te||(dt.opacity=c?.2:0),x.push(Xl(T,y?vt:rt,y?rt:vt,ce/2,dt));continue}if(u==="circle"){const vt=ce/2,rt=ae+le/2,dt=(_e+Pe)/2;x.push({type:"circle",cx:y?rt:dt,cy:y?dt:rt,r:vt,...Se,data:v,index:k,grid:Y,effectShape:P});continue}x.push({type:"rect",x:(y?ae:Z)+l/2,y:(y?Z:ae)+l/2,width:ce,height:ce,...Se,data:v,index:k,grid:Y,effectShape:P})}}),x}}}function ud(e={}){return q6(e)}function B6(e={}){return ud({...e,orientation:"vertical"})}function H6(e={}){return ud({...e,orientation:"horizontal"})}function Sr(e={}){const t=at(e,{mark:"point",allow:st.point}),{channels:n={},id:r,edits:o,shape:i="circle"}=t;return{...lt(t),type:"point",channels:n,discreteScale:"point",...Xt(n),nodeBox:(s,a,l,u,c,d)=>{const f=Math.max(0,+se(u,n,"size",s,5,a,l)||0);return{cx:se(u,n,"x",s,c/2,a,l),cy:se(u,n,"y",s,d/2,a,l),hw:f,hh:f,round:i!=="square"}},build:(s,a,l,u)=>{const c=Nt(a,"point",{fill:it(a).ink});return s.map((d,f)=>{const p=yt(a,n,d,c,f,s),h=se(a,n,"x",d,l/2,f,s),y=se(a,n,"y",d,u/2,f,s),g=se(a,n,"size",d,5,f,s),m=zr(a,n,"angle",d,0,f,s),b=cs(a,n,d,f,s);if(b!==void 0)return Xl(b,h,y,g,{...p,data:d,index:f,...m?{angle:m}:{}});if(i==="square"){const w=Math.max(0,g*2);return{type:"rect",x:h-w/2,y:y-w/2,width:w,height:w,...p,data:d,index:f,...m?{angle:m}:{}}}return{type:"circle",cx:h,cy:y,r:g,...p,data:d,index:f,...m?{angle:m}:{}}})}}}function ub(e={}){const t=at(e,{mark:"ellipse",allow:st.ellipse}),{channels:n={},id:r,edits:o}=t;return{...lt(t),type:"ellipse",channels:n,discreteScale:"point",...Xt(n),nodeBox:(i,s,a,l,u,c)=>{const d=se(l,n,"size",i,5,s,a);return{cx:se(l,n,"x",i,u/2,s,a),cy:se(l,n,"y",i,c/2,s,a),hw:Math.max(0,+se(l,n,"rx",i,d,s,a)||0),hh:Math.max(0,+se(l,n,"ry",i,d,s,a)||0),round:!0}},build:(i,s,a,l)=>{const u=Nt(s,"ellipse",{fill:it(s).ink});return i.map((c,d)=>{const f=yt(s,n,c,u,d,i),p=se(s,n,"x",c,a/2,d,i),h=se(s,n,"y",c,l/2,d,i),y=se(s,n,"size",c,5,d,i),g=se(s,n,"rx",c,y,d,i),m=se(s,n,"ry",c,y,d,i),b=zr(s,n,"angle",c,0,d,i);return{type:"ellipse",cx:p,cy:h,rx:g,ry:m,...f,data:c,index:d,...b?{angle:b}:{}}})}}}function Zp(e,t,n){if(e&&Array.isArray(e.domainConfig))return e.domainConfig;const r=[];for(const o of n)r.includes(o[t])||r.push(o[t]);return r}function U6(e){const t=at(e,{mark:"dotStack",allow:st.dotStack}),{channels:n={},id:r,edits:o,orientation:i,gap:s=2,ghost:a=!0,label:l=!1}=t,{xKey:u,yKey:c}=Xt(n),d=kr(n,null,{orientation:i,single:"other"}),f=n.size&&n.size.value!=null?+n.size.value:7;return{...lt(t),type:"dotStack",channels:n,countAxis:d,countPitch:2*f+s,discreteScale:"point",xKey:u,yKey:c,build:(p,h,y,g)=>{const m=se(h,n,"size",null,7),b=2*m+s,w=d==="y"?u:c,x=d==="y"?"x":"y",S=d==="y"?g:0,v=new Map;p.forEach((L,N)=>{const I=Nn(n,x,L,w,N,p);v.set(I,(v.get(I)||0)+1)});const k=(L,N)=>{const I=se(h,n,x,L,(d==="y"?y:g)/2),O=(N+.5)*b;return{cx:d==="y"?I:S+O,cy:d==="y"?S-O:I}},_=[];if(a)for(const L of Zp(h[x],w,p))_.push({type:"circle",...k({[w]:L},v.get(L)||0),r:m,fill:"none",stroke:"#bbb",strokeWidth:1,pointerEvents:"none"});const T=new Map;if(p.forEach((L,N)=>{const I=Nn(n,x,L,w,N,p),O=T.get(I)||0;T.set(I,O+1);const M=yt(h,n,L,Nt(h,"dotStack",{fill:it(h).ink}),N,p),$=k(L,O),F=cs(h,n,L,N,p);F!==void 0?_.push(Xl(F,$.cx,$.cy,m,{...M,data:L,index:N})):_.push({type:"circle",...$,r:m,...M,data:L,index:N})}),l)for(const L of Zp(h[x],w,p)){const N=v.get(L)||0;if(N===0)continue;const I={[w]:L},O=se(h,n,x,I,(d==="y"?y:g)/2),M=(N+1)*b;_.push({type:"text",text:String(N),x:d==="y"?O:S+M,y:d==="y"?S-M:O,textAnchor:"middle",fontSize:11,fill:"#555",pointerEvents:"none"})}return _}}}function fd(e={}){return U6(e)}function fb(e={}){return fd({...e,orientation:"vertical"})}function K6(e={}){return fd({...e,orientation:"horizontal"})}const Y6="__single__";function db(e,t="domain"){const n=at(e,{mark:"line",allow:st.line}),{channels:r={},id:o,edits:i,curve:s="linear",handles:a=!0,handleSize:l,handleColor:u,connect:c=t}=n,{xKey:d,yKey:f}=Xt(r),p=Os(r);return{...lt(n),type:"line",channels:r,rawChannels:["curve","series","order"],discreteScale:"point",xKey:d,yKey:f,seriesKey:p,connect:c,supportsSeries:!0,build:(h,y,g,m)=>{const{x:b,y:w}=y,S=kr(r,y,{orientation:n.orientation})==="y"?"x":"y",v=[],k=h.map((N,I)=>({d:N,i:I,cx:se(y,r,"x",N,g/2,I,h),cy:se(y,r,"y",N,m/2,I,h),series:p?N[p]:Y6})),_=new Map;for(const N of k){const I=_.get(N.series);I?I.push(N):_.set(N.series,[N])}const T=Nt(y,"line",{stroke:it(y).ink,strokeWidth:2});for(const N of _.values()){if(N.length<2)continue;const I=G6(N,c,S,r),O=yt(y,r,N[0].d,T,N[0].i,h),M=String(pt(r,"curve",N[0].d,s,N[0].i,h));v.push({type:"path",points:I.map($=>[$.cx,$.cy]),curve:M,...O,fill:"none",pointerEvents:"none",series:N[0].series})}const L=fn(y,{handles:a,handleSize:l,handleColor:u},{fill:T.stroke});return k.forEach(({d:N,i:I,cx:O,cy:M,series:$})=>{if(!L.grabbable)return;const F=yt(y,r,N,{fill:L.fill,stroke:L.stroke,strokeWidth:L.strokeWidth},I,h);v.push({type:"circle",cx:O,cy:M,r:L.size,...F,...L.visible?{}:{fill:"transparent",stroke:"none",strokeWidth:0},data:N,index:I,series:$,sweepAxis:S})}),v}}}function G6(e,t,n,r){const o=Qf(r);if(o)return[...e].sort((i,s)=>{const a=i.d[o],l=s.d[o];return a<l?-1:a>l?1:0});if(t==="domain"){const i=n==="x"?"cx":"cy";return[...e].sort((s,a)=>s[i]-a[i])}return e}function dd(e={}){return db(e)}function V6(e={}){return dd({...e,orientation:"vertical"})}function X6(e={}){return dd({...e,orientation:"horizontal"})}function J6(e={}){return db(e,"sequence")}const Hc="__single__";function Z6(e,t,n){if(!e)return{channels:t,edits:n};const r={...t};for(const i of e){const s=r[i];s&&s.edit&&(r[i]={...s,edit:cl(s.edit,i)})}const o=n&&n.map(i=>{const s=(i.channels||[]).filter(a=>e.includes(a));return s.length===1?cl(i,s[0]):i});return{channels:r,edits:o}}function Q6(e){const t=at(e,{mark:"area",allow:st.area}),{channels:n={},id:r,edits:o,curve:i="linear",handles:s=!0,handleSize:a,handleColor:l,connect:u="domain"}=t,{xKey:c,yKey:d}=Xt(n),f=Os(n),p=!!(n.x1&&n.x2),h=!!(n.y1&&n.y2),y=h?["y1","y2"]:p?["x1","x2"]:null,{channels:g,edits:m}=Z6(y,n,o);return{...lt(t),type:"area",channels:g,rawChannels:["curve","series","order"],discreteScale:"point",xKey:c,yKey:d,seriesKey:f,connect:u,supportsSeries:!0,build:(b,w,x,S)=>{const{x:v,y:k}=w,_=kr(g,w,{orientation:t.orientation,extent:"value"}),T=_==="y"?h:p,L=new Map;b.forEach(($,F)=>{const D=f!=null?$[f]:Hc;let z=L.get(D);z||(z=[],L.set(D,z)),z.push({d:$,i:F})});const N=[],I=fn(w,{handles:s,handleSize:a,handleColor:l}),O=yr(k),M=yr(v);for(const[$,F]of L){const z=[...F||[]],j=Qf(g);if(j)z.sort((me,ce)=>me.d[j]<ce.d[j]?-1:me.d[j]>ce.d[j]?1:0);else if(u==="domain"){const me=_==="y"?c:d;z.sort((ce,Y)=>{const fe=ce.d[me],ie=Y.d[me];return fe instanceof Date&&ie instanceof Date?fe-ie:fe<ie?-1:fe>ie?1:0})}const G=it(w).ink,J=yt(w,g,z[0]?z[0].d:{},Nt(w,"area",{fill:G,stroke:G,fillOpacity:.35}),z[0]?z[0].i:void 0,b),re=String(pt(g,"curve",z[0]?z[0].d:{},i,z[0]?z[0].i:void 0,b));let Q,ve;if(_==="y"){const me=(ce,Y)=>se(w,g,"x",ce,x/2,Y,b);Q=z.map(({d:ce,i:Y})=>[me(ce,Y),T?se(w,g,"y2",ce,O,Y,b):se(w,g,"y",ce,S/2,Y,b)]),ve=[...z].reverse().map(({d:ce,i:Y})=>[me(ce,Y),T?se(w,g,"y1",ce,O,Y,b):O])}else{const me=(ce,Y)=>se(w,g,"y",ce,S/2,Y,b);Q=z.map(({d:ce,i:Y})=>[T?se(w,g,"x2",ce,M,Y,b):se(w,g,"x",ce,x/2,Y,b),me(ce,Y)]),ve=[...z].reverse().map(({d:ce,i:Y})=>[T?se(w,g,"x1",ce,M,Y,b):M,me(ce,Y)])}const Ce=[...Q,...ve];Ce.length>=2&&N.push({type:"path",points:Ce,curve:re,...J,strokeWidth:J.strokeWidth!=null?J.strokeWidth:1,series:$===Hc?void 0:$,pointerEvents:"none"});const le=T?_==="y"?["y1","y2"]:["x1","x2"]:[_];I.grabbable&&z.forEach(({d:me,i:ce})=>{const Y=yt(w,g,me,{fill:I.fill,stroke:I.stroke,strokeWidth:I.strokeWidth},ce,b);for(const fe of le){const ie=fe[0]==="y",U=ie?se(w,g,"x",me,x/2,ce,b):se(w,g,"y",me,S/2,ce,b),we=se(w,g,fe,me,ie?S/2:x/2,ce,b);N.push({type:"circle",cx:ie?U:we,cy:ie?we:U,r:I.size,...Y,...I.visible?{}:{fill:"transparent",stroke:"none",strokeWidth:0},data:me,index:ce,channel:fe,series:$===Hc?void 0:$})}})}return N}}}function hd(e={}){return Q6(e)}function eA(e={}){return hd({...e,orientation:"vertical"})}function tA(e={}){return hd({...e,orientation:"horizontal"})}const Xu=16,hb=16;function rc(e,t,n,r=Xu){const o=[];for(let i=0;i<=r;i++){const s=i/r,a=1-s;o.push([a*a*e[0]+2*a*s*t[0]+s*s*n[0],a*a*e[1]+2*a*s*t[1]+s*s*n[1]])}return o}function dl(e,t,n,r){const o=[];for(let i=0;i<=Xu;i++){const s=i/Xu,a=1-s,l=a*a*a,u=3*a*a*s,c=3*a*s*s,d=s*s*s;o.push([l*e[0]+u*t[0]+c*n[0]+d*r[0],l*e[1]+u*t[1]+c*n[1]+d*r[1]])}return o}function Uc(e,t,n){if(!n)return e;const r=-n*Math.PI/180,o=Math.cos(r),i=Math.sin(r),s=e[0]-t.cx,a=e[1]-t.cy;return[t.cx+s*o-a*i,t.cy+s*i+a*o]}function nA(e){const t=at(e,{mark:"curve",allow:st.curve}),{channels:n={},id:r,edits:o,length:i}=t,{xKey:s,yKey:a}=Xt(n);return{...lt(t),type:"curve",channels:n,discreteScale:"point",xKey:s,yKey:a,build:(l,u,c,d)=>{const f=kr(n,u,{orientation:t.orientation,extent:"span",single:"other"}),p=f==="x"?"y":"x",h=p==="x"?c:d,y=f==="x"?c:d,g=Nt(u,"curve",{fill:"none",stroke:it(u).ink,strokeWidth:2}),m=[];return l.forEach((b,w)=>{const x=yt(u,n,b,g,w,l),S=se(u,n,f,b,y/2,w,l);let v,k;if(n[`${p}1`]&&n[`${p}2`])v=se(u,n,`${p}1`,b,h*.25,w,l),k=se(u,n,`${p}2`,b,h*.75,w,l);else{const re=se(u,n,p,b,h/2,w,l),Q=(i??Math.min(c,d)*.25)/2;v=re-Q,k=re+Q}let _=p==="x"?[v,S]:[S,v],T=p==="x"?[k,S]:[S,k];const L={cx:(_[0]+T[0])/2,cy:(_[1]+T[1])/2},N=T[0]-_[0],I=T[1]-_[1],O=Math.hypot(N,I)||1,M=I/O,$=-N/O,D=(se(u,n,"curvature",b,0,w,l)||0)*(O/2);let z=[L.cx+M*D*2,L.cy+$*D*2];const j=zr(u,n,"angle",b,0,w,l);j&&(_=Uc(_,L,j),T=Uc(T,L,j),z=Uc(z,L,j));const G=`M ${_[0]} ${_[1]} Q ${z[0]} ${z[1]} ${T[0]} ${T[1]}`,J=rc(_,z,T);m.push({type:"path",d:G,cx:L.cx,cy:L.cy,...x,data:b,index:w,pointerEvents:"none"}),m.push({type:"path",d:G,points:J,cx:L.cx,cy:L.cy,fill:"none",stroke:"transparent",strokeWidth:Math.max(hb,(x.strokeWidth||2)*6),data:b,index:w,cursor:"grab"})}),m}}}function pd(e={}){return nA(e)}function pb(e={}){return pd({...e,orientation:"vertical"})}function rA(e={}){return pd({...e,orientation:"horizontal"})}function yb(e){return e*Math.PI/180}function cn(e,t,n,r){const o=yb(r);return{x:e+n*Math.cos(o),y:t-n*Math.sin(o)}}const $a={top:[180,0],right:[-90,90],bottom:[0,-180],left:[90,270]};function yd(e={}){return e.start!=null&&e.end!=null?[e.start,e.end]:e.arc==="full"?[-180,180]:e.orient&&$a[e.orient]?$a[e.orient]:$a.top}function gb(e,t){let n=t-e;for(;n>360;)n-=360;for(;n<-360;)n+=360;return n}function ps(e,t,n,r,o,i={}){const s=i.innerRadius||0,a=gb(r,o);if(Math.abs(a)<1e-6||n<=0)return"";if(Math.abs(Math.abs(a)-360)<1e-6){const y=r+a/2,g=ps(e,t,n,r,y,i),m=ps(e,t,n,y,o,i);return`${g} ${m}`.trim()}const l=a>=0?0:1,u=Math.abs(a)>180?1:0,c=cn(e,t,n,r),d=cn(e,t,n,o);if(s<=0)return[`M ${e} ${t}`,`L ${c.x} ${c.y}`,`A ${n} ${n} 0 ${u} ${l} ${d.x} ${d.y}`,"Z"].join(" ");const f=cn(e,t,s,r),p=cn(e,t,s,o),h=l===0?1:0;return[`M ${c.x} ${c.y}`,`A ${n} ${n} 0 ${u} ${l} ${d.x} ${d.y}`,`L ${p.x} ${p.y}`,`A ${s} ${s} 0 ${u} ${h} ${f.x} ${f.y}`,"Z"].join(" ")}function hl(e,t,n,r,o){const i=gb(r,o);if(Math.abs(i)<1e-6||n<=0)return"";if(Math.abs(Math.abs(i)-360)<1e-6){const c=r+i/2;return`${hl(e,t,n,r,c)} ${hl(e,t,n,c,o)}`.trim()}const s=cn(e,t,n,r),a=cn(e,t,n,o),l=Math.abs(i)>180?1:0,u=i>=0?0:1;return`M ${s.x} ${s.y} A ${n} ${n} 0 ${l} ${u} ${a.x} ${a.y}`}function mb(e,t){if(!e||!fo(e))return null;const n=e.domain();if(!n.length)return null;if(Vn(e)){const c=e(t);return c==null?null:[c,c+e.bandwidth()]}const r=e.range(),o=r[0],i=r[r.length-1],s=n.indexOf(t);if(s<0)return null;const a=n.map(c=>e(c)),l=s===0?o:(a[s-1]+a[s])/2,u=s===n.length-1?i:(a[s]+a[s+1])/2;return[l,u]}function bb(e,t,n,r,o=10){const i=cn(e,t,n,r),s=o/2,a=cn(e,t,s,r+90),l=cn(e,t,s,r-90);return[[i.x,i.y],[a.x,a.y],[l.x,l.y]]}function wb(e={}){const t=at(e,{mark:"arc",allow:st.arc}),{channels:n={},id:r,edits:o,outerRadius:i,innerRadius:s=0,padAngle:a=0,arc:l,start:u,end:c,handles:d=!0,handleSize:f,handleColor:p}=t,h=o||[],y=h.some(w=>w&&w.scope==="stack"),[g,m]=yd({arc:l||"full",start:u??(l?void 0:-180),end:c??(l?void 0:180)}),b=n.theta&&n.theta.field;return{...lt(t),type:"arc",channels:n,rawChannels:["theta"],edits:h,discreteScale:"band",yKey:b,supportsStack:!0,build:(w,x,S,v)=>{const k=ad(w,n,["x","y"]),_=Vn(x.x),T=Vn(x.y),L=_?yn(x.x,S):S,N=T?yn(x.y,v):v,I=_||T?.42*Math.min(L,N):(k.length>1?.14:.4)*Math.min(S,v),O=m-g,M=a,$=[],F=fn(x,{handles:d,handleSize:f,handleColor:p});return k.forEach(D=>{const z=D.rep,j=D.members,G=j[0],J=se(x,n,"x",z,S/2,G,w),re=se(x,n,"y",z,v/2,G,w),Q=i??(n.size?se(x,n,"size",z,I,G,w):I),ve=s>0&&s<=1?s*Q:Math.min(s,Q*.95),Ce=b!=null?tc(j,w,b).mags:j.map(U=>{const we=se(x,n,"theta",w[U],0,U,w);return Number.isFinite(we)&&we>0?Number(we):0}),le=Ce.reduce((U,we)=>U+we,0),me=j.length,ce=le>0?O-M*me:0,Y={kind:"angular",cx:J,cy:re,spanStart:g,spanEnd:m,pad:M},fe={};let ie=g+M/2;if(j.forEach((U,we)=>{const xe=w[U],P=le>0?Ce[we]/le:0,H=ce*P,oe=ie,he=ie+H;if(ie=he+M,fe[we]=he,H<=0)return;const ke=yt(x,n,xe,Nt(x,"arc",{fill:"#4f46e5",stroke:"#fff",strokeWidth:1}),U,w),pe=ps(J,re,Q,oe,he,{innerRadius:ve});pe&&$.push({type:"path",d:pe,...ke,cx:J,cy:re,index:U,midAngle:(oe+he)/2,a0:oe,a1:he,stack:ds({members:j,local:we,field:b,geometry:Y}),sector:{cx:J,cy:re,r0:ve,r1:Q,a0:oe,a1:he}})}),y&&F.grabbable&&le>0&&me>1)for(let U=0;U<me-1;U++){const we=fe[U]+M/2,xe=cn(J,re,Q,we);$.push({type:"circle",cx:xe.x,cy:xe.y,r:F.size,fill:F.visible?F.fill:"transparent",stroke:F.visible?F.stroke:"none",strokeWidth:F.visible?F.strokeWidth:0,cursor:"grab",index:j[U],edge:!0,loIndex:j[U],hiIndex:j[U+1],stack:ds({members:j,local:U,field:b,geometry:Y})})}}),$}}}function oA(e={}){const t=e.innerRadius!=null?e.innerRadius:e.outerRadius!=null?e.outerRadius*.55:.55;return wb({...e,arc:e.arc||"full",innerRadius:t})}function iA(e={}){const t=at(e,{mark:"needle",allow:st.needle});for(const p of["arc","orient","start","end"])e&&e[p]!==void 0&&ge(`needle:span:${p}`,`needle({ ${p}: … }) does nothing: a needle's sweep is the theta scale's range. Set it on the channel — channels: { theta: { field, scale: { range: [180, 0] } } } — or chart-wide with scales: { theta: { range } }; axisRadial takes arc/orient/start/end for the chrome.`);t.channels&&t.channels.angle&&!t.channels.theta&&ge("needle:angle","needle({ channels: { angle: … } }) — a needle's direction is `theta`, the polar angular POSITION (what axisRadial draws). `angle` is a mark's rotation in place and this mark does not read it, so the needle would point at 0°. Rename the channel to `theta`.");const{channels:n={},id:r,edits:o,length:i,handles:s=!0,handleSize:a,handleColor:l,baseWidth:u=10}=t,c=n.theta&&n.theta.field,d=n.x&&n.x.field,f=n.y&&n.y.field;return{...lt(t),type:"needle",channels:n,discreteScale:"point",xKey:d||c,yKey:f||c,build:(p,h,y,g)=>{const m=[],b=fn(h,{handles:s,handleSize:a,handleColor:l});return p.forEach((w,x)=>{const S=se(h,n,"x",w,y/2,x,p),v=se(h,n,"y",w,g/2,x,p),k=zr(h,n,"theta",w,0,x,p),_=i??se(h,n,"size",w,Math.min(y,g)*.4,x,p),T=yt(h,n,w,Nt(h,"needle",{fill:"#1e293b",stroke:"#1e293b",strokeWidth:1}),x,p),L=bb(S,v,_,k,u),N=`M ${L[0][0]} ${L[0][1]} L ${L[1][0]} ${L[1][1]} L ${L[2][0]} ${L[2][1]} Z`;m.push({type:"path",d:N,...T,cx:S,cy:v,data:w,index:x,cursor:b.grabbable?"grab":void 0}),b.grabbable&&m.push({type:"circle",cx:S,cy:v,r:b.size,fill:b.fill,stroke:b.stroke,strokeWidth:b.strokeWidth,data:w,index:x,cursor:"grab"})}),m}}}const sA=.52,aA=4096,yi=new Map;let _o;function lA(){if(_o!==void 0)return _o;if(_o=null,typeof document<"u")try{_o=document.createElement("canvas").getContext("2d")}catch{_o=null}return _o}function cA({fontSize:e=12,fontFamily:t="sans-serif",fontWeight:n="normal"}){return`${n} ${e}px ${t}`}function qi(e,t={}){const n=e==null?"":String(e);if(!n)return 0;const r=cA(t),o=`${r}\0${n}`,i=yi.get(o);if(i!==void 0)return i;const s=lA();let a;if(s?(s.font=r,a=s.measureText(n).width):a=n.length*(t.fontSize||12)*sA,yi.size>=aA){const l=yi.keys().next().value;l!==void 0&&yi.delete(l)}return yi.set(o,a),a}function xb(e,t={}){const{maxWidth:n,...r}=t,i=(e==null?"":String(e)).split(`
13
- `);if(!n||n<=0)return i;const s=[];for(const a of i){const l=a.split(/\s+/).filter(c=>c.length);if(!l.length){s.push("");continue}let u="";for(const c of l){const d=u?`${u} ${c}`:c;if(qi(d,r)<=n){u=d;continue}if(u&&s.push(u),qi(c,r)>n){let f="";for(const p of c)f&&qi(f+p,r)>n?(s.push(f),f=p):f+=p;u=f}else u=c}s.push(u)}return s}function oc(e,t={}){const{lineHeight:n,...r}=t,o=r.fontSize||12,i=n||Math.round(o*1.35),s=xb(e,r);let a=0;for(const l of s)a=Math.max(a,qi(l,r));return{lines:s,width:a,height:s.length*i,lineHeight:i}}function $n(e,t={}){const{padding:n=10,maxWidth:r=160,minWidth:o=60,minHeight:i=0,fontSize:s=13,fontFamily:a,lineHeight:l}=t,u=oc(e==null?"":String(e),{maxWidth:r-n*2,fontSize:+s||13,fontFamily:a,lineHeight:l});return{block:u,width:Math.max(o,Math.min(r,u.width+n*2)),height:Math.max(i,u.height+n*2)}}function $r(e){if(typeof e=="function")return e;if(typeof e=="string"){const t=ti(e);return n=>n==null||n===""?"":t(n)}return t=>t==null?"":String(t)}function uA(e=""){return $r(e)}function fA(e=".0%"){return $r(e)}function dA(e=".2s"){return $r(e)}function hA(e="%Y-%m-%d"){const t=zf(e);return n=>{if(n==null||n==="")return"";const r=n instanceof Date?n:new Date(n);return Number.isNaN(+r)?String(n):t(r)}}function pA(e,t=""){const n=$r(t);return r=>r==null||r===""?"":`${e}${n(r)}`}function yA(e,t=""){const n=$r(t);return r=>r==null||r===""?"":`${n(r)}${e}`}const gA=Object.freeze(Object.defineProperty({__proto__:null,number:uA,percent:fA,prefix:pA,resolveFormat:$r,si:dA,suffix:yA,time:hA},Symbol.toStringTag,{value:"Module"}));function mA(e){switch(e){case"top":return"text-before-edge";case"bottom":return"text-after-edge";default:return"central"}}function gd(e,t,n,r,o,i,s={}){const{format:a=x=>x,data:l,wrap:u,lineHeight:c}=s,d=typeof u=="function"?u(n,r,l||[n]):u,f=yt(e,t,n,Nt(e,"text",{fill:"#111"}),r,l),p=+pt(t,"dx",n,0,r,l)||0,h=+pt(t,"dy",n,0,r,l)||0,y=zr(e,t,"angle",n,0,r,l),g=pt(t,"lineAnchor",n,"middle",r,l),m=pt(t,"fontSize",n,12,r,l),b=a(pt(t,"text",n,"",r,l)),w=d||c?oc(b,{maxWidth:d,fontSize:+m||12,fontFamily:it(e).font&&it(e).font.family||void 0,lineHeight:c}):null;return{type:"text",x:o+p,y:i+h,text:b,fontSize:m,textAnchor:pt(t,"textAnchor",n,"middle",r,l),lineAnchor:g,dominantBaseline:mA(g),...y?{angle:y}:{},...w&&w.lines.length>1?{lines:w.lines,lineHeight:w.lineHeight}:{},...f,data:n,index:r}}function bA(e){const t=at(e,{mark:"text",allow:st.text}),{channels:n={},id:r,edits:o,format:i,wrap:s,lineHeight:a}=t,l=$r(i);return{...lt(t),type:"text",channels:n,rawChannels:["text","fontSize","textAnchor","lineAnchor","dx","dy"],discreteScale:"point",...Xt(n),build:(c,d,f,p)=>c.map((h,y)=>{const{x:g,y:m}=u(h,y,c,d,f,p);return gd(d,n,h,y,g,m,{format:l,data:c,wrap:s,lineHeight:a})}),labelBox:!0,nodeBox:(c,d,f,p,h,y)=>{const g=u(c,d,f,p,h,y),m=+pt(n,"dx",c,0,d,f)||0,b=+pt(n,"dy",c,0,d,f)||0,w=+pt(n,"fontSize",c,12,d,f)||12,x=oc(l(pt(n,"text",c,"",d,f)),{maxWidth:typeof s=="function"?s(c,d,f):s,fontSize:w,fontFamily:it(p).font&&it(p).font.family||void 0,lineHeight:a}),S=x.width/2,v=x.height/2,k=pt(n,"textAnchor",c,"middle",d,f),_=pt(n,"lineAnchor",c,"middle",d,f),T=g.x+m,L=g.y+b;return{cx:k==="start"?T+S:k==="end"?T-S:T,cy:_==="top"?L+v:_==="bottom"?L-v:L,hw:S,hh:v}}};function u(c,d,f,p,h,y){const g=t.orientation==="vertical"?"y":t.orientation==="horizontal"?"x":null;return{x:g==="y"?h/2:se(p,n,"x",c,h/2,d,f),y:g==="x"?y/2:se(p,n,"y",c,y/2,d,f)}}}function Or(e={}){return bA(e)}function wA(e={}){return Or({...e,orientation:"horizontal"})}function xA(e={}){return Or({...e,orientation:"vertical"})}const vA=["intercept","slope","interceptSpread","slopeSpread","intercept1","intercept2","slope1","slope2"];function md(e,t={}){const n={x:{field:"x"},y:{field:"y"},...t,...e};for(const r of vA){const o=n[r];o&&(n[r]={...o,scale:null})}return n}function bd(e,t,n,r,o){const i=(p,h)=>{const y=se(n,t,p,e,h,r,o),g=Number(y);return Number.isFinite(g)?g:h},s=i("intercept",0),a=i("slope",0),l=(p,h)=>{if(t[`${p}1`]||t[`${p}2`]){const g=i(`${p}1`,h),m=i(`${p}2`,h);return g<=m?[g,m]:[m,g]}const y=Math.abs(i(`${p}Spread`,0));return[h-y,h+y]},[u,c]=l("intercept",s),[d,f]=l("slope",a);return{a:s,b:a,aLo:u,aHi:c,bLo:d,bHi:f}}function wd(e){const t=e.x&&e.x.domainConfig;return{x0:Array.isArray(t)?Number(t[0]):0,x1:Array.isArray(t)?Number(t[t.length-1]):1}}function ic(e,t={}){const{x0:n,x1:r}=wd(e),o=Math.min(n,r),i=Math.max(n,r),s=o<=0&&0<=i?0:n;return{anchor:t.anchor!=null?Number(t.anchor):s,probe:t.probe!=null?Number(t.probe):r}}const Cr=(e,t)=>e.a+e.b*t;function kA(e,t,n,r,o,i){const s=n-e,a=r-t;if(s===0&&a===0)return e<0||e>o||t<0||t>i?null:{x1:e,y1:t,x2:n,y2:r};let l=-1/0,u=1/0;const c=(d,f)=>{if(d===0)return f>=0;const p=f/d;if(d<0){if(p>u)return!1;p>l&&(l=p)}else{if(p<l)return!1;p<u&&(u=p)}return!0};return!c(-s,e-0)||!c(s,o-e)||!c(-a,t-0)||!c(a,i-t)||l>u?null:{x1:e+l*s,y1:t+l*a,x2:e+u*s,y2:t+u*a}}function SA(e,t,n){const r=[{inside:s=>s[0]>=0,at:(s,a)=>o(s,a,0,0)},{inside:s=>s[0]<=t,at:(s,a)=>o(s,a,0,t)},{inside:s=>s[1]>=0,at:(s,a)=>o(s,a,1,0)},{inside:s=>s[1]<=n,at:(s,a)=>o(s,a,1,n)}];function o(s,a,l,u){const c=a[l]-s[l],d=c===0?0:(u-s[l])/c;return[s[0]+d*(a[0]-s[0]),s[1]+d*(a[1]-s[1])]}let i=e;for(const s of r){const a=[];for(let l=0;l<i.length;l++){const u=i[l],c=i[(l+i.length-1)%i.length],d=s.inside(u),f=s.inside(c);d?(f||a.push(s.at(c,u)),a.push(u)):f&&a.push(s.at(c,u))}if(i=a,!i.length)return[]}return i}function pl(e,t,n,r,o){const{x0:i,x1:s}=wd(t),a=u=>Lt(t,n,"x",u,0),l=u=>Lt(t,n,"y",u,0);return kA(a(i),l(Cr(e,i)),a(s),l(Cr(e,s)),r,o)}function vb(e,t=0){if(!e)return null;const n=e.x2-e.x1,r=e.y2-e.y1,o=Math.hypot(n,r);if(!Number.isFinite(o))return null;const i=t>0&&o>4*t?t/o:0;return[{x:e.x1+i*n,y:e.y1+i*r},{x:e.x2-i*n,y:e.y2-i*r}]}function xd(e,t,n,r,o){const{aLo:i,aHi:s,bLo:a,bHi:l}=e,{x0:u,x1:c}=wd(t),d=Math.min(u,c),f=Math.max(u,c),p=[d];d<0&&0<f&&p.push(0),p.push(f);const h=w=>Lt(t,n,"x",w,0),y=w=>Lt(t,n,"y",w,0),g=w=>s+Math.max(a*w,l*w),m=w=>i+Math.min(a*w,l*w),b=[];for(const w of p)b.push([h(w),y(g(w))]);for(let w=p.length-1;w>=0;w--)b.push([h(p[w]),y(m(p[w]))]);return SA(b,r,o)}function kb(e,t,n,r,o,i){const{a:s,b:a,aLo:l,aHi:u,bLo:c,bHi:d}=e,f=[];for(let p=1;p<=t;p++){const h=p/t,y={aLo:s-(s-l)*h,aHi:s+(u-s)*h,bLo:a-(a-c)*h,bHi:a+(d-a)*h},g=xd(y,n,r,o,i);g.length>=3&&f.push(g)}return f}function $A(e){let t=e>>>0;return function(){t|=0,t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function _A(e){let t=0,n=0;for(;t===0;)t=e();for(;n===0;)n=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*n)}function Sb(e,t={}){const{samples:n=60,seed:r=7,distribution:o="normal",sigma:i=1.96}=t,{a:s,b:a,aLo:l,aHi:u,bLo:c,bHi:d}=e,f=$A(r),p=i>0?i:1.96,h=(g,m,b)=>{if(o==="uniform")return m+f()*(b-m);const w=_A(f)/p;return w>=0?g+w*(b-g):g+w*(g-m)},y=[];for(let g=0;g<n;g++)y.push({a:h(s,l,u),b:h(a,c,d)});return y}function $b(e={}){const t=at(e,{mark:"trend",allow:st.trend}),{edits:n,anchor:r,probe:o,grip:i="end",handles:s=!0,handleSize:a,handleColor:l}=t;o!=null&&i!=="probe"&&ge("trend:probe-ignored","trend(): `probe` places the slope handle only under `grip: 'probe'`. The default grip mounts the handles on the line's own ends; add `grip: 'probe'` to pin one at that column instead.");const u=md(t.channels||{},{intercept:{field:"intercept"},slope:{field:"slope"}}),c={anchor:r,probe:o};return{...lt(t),type:"trend",channels:u,isTrend:!0,supportsTrend:!0,...Xt(u),requires:[{channels:["x","y"],kind:"continuous",match:"all",why:"an intercept and a slope are only defined over two continuous axes."}],build:(d,f,p,h)=>{if(!f.x||!f.y)return[];const{anchor:y,probe:g}=ic(f,c),m=[],b=Nt(f,"trend",{stroke:"#333",fill:"#333"}),w=fn(f,{handles:s,handleSize:a,handleColor:l},{fill:b.fill});return d.forEach((x,S)=>{const v=bd(x,u,f,S,d),k=yt(f,u,x,b,S,d),_=pl(v,f,u,p,h);if(_&&m.push({type:"line",..._,stroke:k.stroke||b.stroke,strokeWidth:k.strokeWidth||2,pointerEvents:"none"}),!w.grabbable)return;const T=(L,N,I)=>{m.push({type:"circle",cx:N,cy:I,r:w.size,fill:w.visible?k.fill||w.fill:"transparent",data:x,index:S,channel:L,anchor:y,probe:g,grip:i})};if(T("intercept",Lt(f,u,"x",y,0),Lt(f,u,"y",Cr(v,y),0)),i==="probe"){T("slope",Lt(f,u,"x",g,0),Lt(f,u,"y",Cr(v,g),0));return}for(const L of vb(_,w.size+1)||[])T("slope",L.x,L.y)}),m}}}function _b(e={}){const t=at(e,{mark:"trendBand",allow:st.trendBand}),{edits:n,render:r="region",levels:o=5,samples:i=60,seed:s=7,sigma:a=1.96,distribution:l="normal",anchor:u,probe:c,grip:d="end",handles:f=!1,handleSize:p,handleColor:h}=t;c!=null&&d!=="probe"&&ge("trendBand:probe-ignored","trendBand(): `probe` places the slopeSpread handle only under `grip: 'probe'`. The default grip mounts the handles on the band's own edge ends; add `grip: 'probe'` to pin one at that column instead.");const y=md(t.channels||{},{intercept:{field:"intercept"},slope:{field:"slope"}}),g={anchor:u,probe:c};return{...lt(t),type:"trendBand",channels:y,supportsTrend:!0,isTrend:!0,...Xt(y),requires:[{channels:["x","y"],kind:"continuous",match:"all",why:"an intercept and a slope are only defined over two continuous axes."}],build:(m,b,w,x)=>{if(!b.x||!b.y)return[];const{anchor:S,probe:v}=ic(b,g),k=[],_=fn(b,{handles:f,handleSize:p,handleColor:h}),T=it(b).ink,L=Nt(b,"trendBand",{fill:T,stroke:T,fillOpacity:.18,strokeOpacity:.15}),N=(I,O)=>{const M=vb(pl(I,b,y,w,x),_.size+1);if(!M)return null;const $=b.x,F=$&&$.invertible?j=>Number($.invertValue(j.x)):j=>j.x,[D,z]=M;return O>0==F(D)>=F(z)?D:z};return m.forEach((I,O)=>{const M=bd(I,y,b,O,m),$=yt(b,y,I,L,O,m),F=$.fill||L.fill,D=$.fillOpacity,z=M.aLo===M.aHi&&M.bLo===M.bHi;if(!z&&r==="samples")for(const J of Sb(M,{samples:i,seed:s,distribution:l,sigma:a})){const re=pl(J,b,y,w,x);re&&k.push({type:"line",...re,stroke:$.stroke||L.stroke,strokeWidth:$.strokeWidth!=null?$.strokeWidth:1,strokeOpacity:$.strokeOpacity,pointerEvents:"none",background:!0})}else if(!z&&r==="gradient"){const J=Math.max(1,Math.round(o)),re=1-Math.pow(1-Math.min(.99,D),1/J);for(const Q of kb(M,J,b,y,w,x))k.push({type:"path",points:Q,curve:"linear",fill:F,fillOpacity:re,stroke:"none",pointerEvents:"none",background:!0})}else if(!z){const J=xd(M,b,y,w,x);J.length>=3&&k.push({type:"path",points:J,curve:"linear",fill:F,fillOpacity:D,stroke:"none",pointerEvents:"none",background:!0})}if(!_.grabbable)return;const j=J=>M.aHi+Math.max(M.bLo*J,M.bHi*J),G=(J,re,Q)=>{k.push({type:"circle",cx:re,cy:Q,r:_.size,fill:_.visible?h||F:"transparent",data:I,index:O,channel:J,anchor:S,probe:v,grip:d})};if(y.interceptSpread&&G("interceptSpread",Lt(b,y,"x",S,0),Lt(b,y,"y",z?Cr(M,S):j(S),0)),!!y.slopeSpread){if(d==="probe"){G("slopeSpread",Lt(b,y,"x",v,0),Lt(b,y,"y",z?Cr(M,v):j(v),0));return}for(const[J,re]of[[1,M.bHi],[-1,M.bLo]]){const Q=N({a:M.aHi,b:re},J);Q&&G("slopeSpread",Q.x,Q.y)}}}),k}}}const ia=["x","y","size"],MA=["ports"];let EA=0;function AA(e,t,n){const r={};for(const[o,i]of Object.entries(e||{}))if(i)if(!n&&i.edit){const{edit:s,...a}=i;r[o]=a}else r[o]=i;for(const[o,i]of Object.entries(t||{}))i!==void 0&&(r[o]=i);return r}function Qp(e){for(const[t,n]of Object.entries(e||{})){const r=LM(n);r!==n&&(e[t]=r)}return e}function TA(e){return Object.values(e||{}).some(t=>!!Gr(t))}function OA(e,t,n){const r=[];Vn(e.x)&&r.push(yn(e.x,0)),Vn(e.y)&&r.push(yn(e.y,0));const o=r.filter(i=>i>0);return o.length?Math.min(...o)/2:Math.min(t,n)*.35}function Kc(e,t,n,r,o,i,s){const a=OA(e,i,s);return{cx:se(e,t,"x",n,i/2,r,o),cy:se(e,t,"y",n,s/2,r,o),r:se(e,t,"size",n,a,r,o)}}function CA(e,t,n){if(e.field==null)return t;const r=n&&n[e.field],o=r&&r.domain;return Array.isArray(o)&&o.length?[o[0],o[o.length-1]]:(ge(`frame:domain:${e.field}`,`field "${e.field}" is encoded in a composite's local frame, but the schema declares no domain for it — a frame maps the field's DOMAIN onto the glyph's local box, so without one it falls back to [0, 1]. Declare it: schema: { ${e.field}: { type: "quantitative", domain: [lo, hi] } }.`),[0,1])}function NA(e,t,n,r,o,i){const s={};for(const a of t){const l=e[a],u=Gr(l)||{},c=Wf(a),d=u.range||RM(a)||u0(a,"linear",o,i),f=AM({domain:CA(l,d,r),localRange:d,origin:c==="x"?n.cx:c==="y"?n.cy:0,halfSize:n.r,family:c});f&&(s[a]=f,l&&l.field!=null&&(s[uo(a,l.field)]=f))}return s}function IA(e,t,n){const r={};for(const o of t){const i=e[o],s=n[o];if(!i||!i.edit||i.field==null||!s)continue;const a=Wf(o);if(a!=="x"&&a!=="y")continue;const l=s.domainConfig||[];if(l.length<2||r[a])continue;const u=l[0],c=l[l.length-1];r[a]={channel:o,field:i.field,pxAt0:s.encode(u),pxAt1:s.encode(c),loVal:u,hiVal:c}}return Object.keys(r).length?r:null}function ii(e={}){const t=`glyph#${++EA}`,n=at(e,{mark:"composite",allow:st.composite}),{id:r,parts:o=[],edits:i,table:s,channels:a={},discreteScale:l="band"}=n,u=r||"composite",c=o.length-1;Qp(a);for(const m of o)Qp(m.channels||(m.channels={}));const d=o.some(m=>TA(m.channels))||Object.entries(a).some(([m,b])=>!ia.includes(m)&&Gr(b)),f={};for(const[m,b]of Object.entries(a))d&&ia.includes(m)||MA.includes(m)||(f[m]=b);if(!d&&a.ports){const m=o.filter(w=>typeof w.nodeBox=="function"),b=m.find(w=>!w.labelBox)||m[0]||o[0];b&&((b.channels||(b.channels={})).ports=a.ports)}const p=o.map((m,b)=>{const w=m.channels,x=AA(f,{...w},b===c);for(const _ of Object.keys(w))delete w[_];Object.assign(w,x);let S=Object.keys(w).filter(_=>Gr(w[_]));if(S.length)for(const _ of["x","y"])w[_]===void 0&&(w[_]={datum:0,scale:"frame"},S.push(_));S.length&&m.supportsSeries&&ge(`composite:series:${u}:${b}`,`composite "${u}" contains a series mark (${m.type||"a line-family mark"}) with local (frame) channels. A frame is per ROW, so the mark is built one row at a time and cannot group rows into a series. Position it on the global scales, or move it out of the composite.`);const v=m.build,k=S.length?((_,T,L,N)=>{const I=T.schema||{},O=it(T),M={width:L,height:N},$=[];for(let F=0;F<_.length;F++){const D=_[F],z=Kc(T,a,D,F,_,L,N),j=NA(w,S,z,I,M,O),G=IA(w,S,j),J=v([D],{...T,...j},L,N)||[];for(const re of J)re.index=F,re.data=D,re.frame=j,G&&re.dm==null&&(re.dm=G),$.push(re)}return $}):v;return{...m,channels:w,build:k,nodeBox:S.length?void 0:m.nodeBox,labelBox:m.labelBox,glyph:t,xKey:w.x&&w.x.field||m.xKey,yKey:w.y&&w.y.field||m.yKey,id:m.id||`${u}/${b}`,table:m.table||s,discreteScale:m.discreteScale||l,edits:!d&&b===c&&i?[...i,...m.edits||[]]:m.edits}});if(!d)return p;const h={};for(const m of ia){const b=a[m];!b||Gr(b)||(h[m]=b)}a.ports&&(h.ports=a.ports);const y=!!(i&&i.length)||ia.some(m=>h[m]&&h[m].edit);return[{id:`${u}/frame`,type:"composite",glyph:t,channels:h,edits:i,table:s,discreteScale:l,...Xt(h),nodeBox:(m,b,w,x,S,v)=>{const k=Kc(x,a,m,b,w,S,v);return{cx:k.cx,cy:k.cy,hw:k.r,hh:k.r,round:!0}},build:(m,b,w,x)=>m.map((S,v)=>{const k=Kc(b,a,S,v,m,w,x);return{type:"circle",cx:k.cx,cy:k.cy,r:k.r,fill:"none",stroke:"none",hit:!0,...y?{pointerEvents:"all"}:{},data:S,index:v}})},...p]}const LA=e=>e<0?0:e>1?1:e,FA=["mouthCurve","mouthAsym","eyeScale","eyeSquint","browHeight","browTilt"],kt={ink:"#1f2937",headFill:"#FFD666",headStroke:"#B7791F",headStrokeWidth:.03,lineWidth:.055,eyeX:.4,eyeY:.16,eyeRx:[.055,.185],eyeRy:[.12,.03],eyeNeutral:.12,browInner:.14,browOuter:.5,browY:[.23,.57],browTiltRight:[-45,45],browTiltLeft:[45,-45],mouthY:-.34,mouthX:.36,mouthCurve:[.67,-.67],mouthAsym:[-20,20]};function RA(e={}){const t=at(e,{mark:"face",allow:st.face}),{id:n,edits:r,table:o,ink:i=kt.ink}=t,s={...t.channels};FA.some(x=>s[x])||(s.mouthCurve={field:"valence"},s.eyeScale={field:"arousal"});const a=(x,S,v=.5)=>{const k=s[x];if(k&&k.field!=null)return k.scale!==void 0||k.frame!==void 0?k:{...k,frame:S};const _=k&&k.value!==void 0?LA(+k.value):v;return{frame:S[0]+_*(S[1]-S[0])}},l=x=>({frame:x}),u=x=>({frame:x}),c=a("eyeScale",kt.eyeRx,(kt.eyeNeutral-kt.eyeRx[0])/(kt.eyeRx[1]-kt.eyeRx[0])),d=x=>{if(!x)return x;const{edit:S,...v}=x;return v},f=s.eyeSquint?a("eyeSquint",kt.eyeRy):d(c),p=a("browHeight",kt.browY),h=u(kt.lineWidth),y=n||"face",g=x=>`${y}/${x}`,m=x=>x<0?"left":"right",b=(x,S)=>lb({id:g(`brow-${m(x)}`),channels:{x1:l(x*kt.browInner),x2:l(x*kt.browOuter),y:p,angle:a("browTilt",S),stroke:{value:i},strokeWidth:h}}),w=x=>ub({id:g(`eye-${m(x)}`),channels:{x:l(x*kt.eyeX),y:l(kt.eyeY),rx:c,ry:f,fill:{value:i},stroke:{value:"none"}}});return ii({id:y,edits:r,table:o,channels:{x:s.x,y:s.y,size:s.size,...s.ports?{ports:s.ports}:{}},parts:[Sr({id:g("head"),channels:{size:u(1),fill:s.fill||{value:kt.headFill},stroke:s.stroke||{value:kt.headStroke},strokeWidth:s.strokeWidth||u(kt.headStrokeWidth)}}),w(-1),w(1),b(-1,kt.browTiltLeft),b(1,kt.browTiltRight),pb({id:g("mouth"),channels:{x1:l(-.36),x2:l(kt.mouthX),y:l(kt.mouthY),curvature:a("mouthCurve",kt.mouthCurve),angle:a("mouthAsym",kt.mouthAsym),stroke:{value:i},strokeWidth:h}})]})}const PA=["text","fontSize","textAnchor","lineAnchor","dx"],zA=["x","y"];function DA(e={}){const t=at(e,{mark:"node",except:["dy"],allow:st.node}),{channels:n={},dy:r=-16,shape:o,format:i}=t,s=lt(t),a=s.id||"node",l={},u={},c={};for(const[f,p]of Object.entries(n))zA.includes(f)?l[f]=p:PA.includes(f)?c[f]=p:u[f]=p;const d=[];return n.text&&d.push(Or({id:`${a}/label`,dy:r,...i!==void 0?{format:i}:{},channels:{textAnchor:{value:"middle"},...c}})),d.push(Sr({id:`${a}/dot`,...o!==void 0?{shape:o}:{},channels:u})),ii({...s,channels:l,parts:d})}const jA=["text","fontSize","textAnchor","lineAnchor","dx","dy"],WA=["x","y"],qA=["width","height"],Yc=e=>{if(!e)return e;const{edit:t,...n}=e;return n};function BA(e={}){const t=at(e,{mark:"sticker",except:["padding","radius","maxWidth","minWidth","lineHeight"],allow:st.sticker}),{channels:n={},padding:r=10,radius:o=6,maxWidth:i=160,minWidth:s=60,minHeight:a=0,lineHeight:l,fontFamily:u,format:c}=t,d=lt(t),f=d.id||"sticker",p={},h={},y={};for(const[_,T]of Object.entries(n))WA.includes(_)?p[_]=T:jA.includes(_)?y[_]=T:h[_]=T;const g=y.fontSize&&(y.fontSize.value??y.fontSize)||13,m=n.text&&n.text.field,b=n.text&&n.text.fn,w=n.text&&n.text.value,x=(_,T,L)=>{const N=n.width?+pt(n,"width",_,NaN,T,L):NaN;return Number.isFinite(N)?N:i},S=(_,T,L)=>{const N=m!=null?_[m]:typeof b=="function"?b(_,T,L):w;return $n(N,{padding:r,maxWidth:x(_,T,L),minWidth:s,minHeight:a,fontSize:+g||13,fontFamily:u,lineHeight:l})},v={...h,...p,rx:{value:o}};n.text&&(v.text=Yc(n.text));for(const _ of qA){if(v[_])continue;const T=_==="width"?L=>L.width:L=>L.height;v[_]={fn:(L,N,I)=>T(S(L,N,I))}}const k=[Is({id:`${f}/body`,...d.edits?{edits:d.edits}:{},...d.table?{table:d.table}:{},channels:v}),Or({id:`${f}/label`,wrap:(_,T,L)=>x(_,T,L)-r*2,...l!==void 0?{lineHeight:l}:{},...c!==void 0?{format:c}:{},channels:{textAnchor:{value:"middle"},lineAnchor:{value:"middle"},fontSize:{value:g},...y,...p.x?{x:Yc(p.x)}:{},...p.y?{y:Yc(p.y)}:{}}})];return ii({id:d.id,table:d.table,channels:{},parts:k})}const HA=6;function fr(e,t){const n=Math.hypot(e,t)||1;return{x:e/n,y:t/n}}function UA(e){return fr(e.x2-e.x1,e.y2-e.y1)}function KA(e){const t=UA(e);return{points:[[e.x1,e.y1],[e.x2,e.y2]],curve:"linear",start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2},tangentIn:t,tangentOut:t}}function Gc(e){return(t,n)=>{const r=t.x2-t.x1,o=t.y2-t.y1,i=Math.sign(r)||1,s=Math.sign(o)||1,a={x:i,y:0},l={x:0,y:s};let u,c,d;if(e==="stepAfter")u=[[t.x1,t.y1],[t.x2,t.y1],[t.x2,t.y2]],c=a,d=l;else if(e==="stepBefore")u=[[t.x1,t.y1],[t.x1,t.y2],[t.x2,t.y2]],c=l,d=a;else{const f=Math.min(.85,Math.max(.15,.5+n)),p=t.x1+r*f;u=[[t.x1,t.y1],[p,t.y1],[p,t.y2],[t.x2,t.y2]],c=a,d=a}return{points:u,curve:"linear",start:{x:t.x1,y:t.y1},end:{x:t.x2,y:t.y2},mid:{x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2},tangentIn:c,tangentOut:d}}}function YA(e,t){const n=(e.x1+e.x2)/2,r=(e.y1+e.y2)/2,o=e.x2-e.x1,i=e.y2-e.y1,s=n-i*t,a=r+o*t;return{d:`M${e.x1},${e.y1}Q${s},${a} ${e.x2},${e.y2}`,hit:rc([e.x1,e.y1],[s,a],[e.x2,e.y2]),start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:.25*e.x1+.5*s+.25*e.x2,y:.25*e.y1+.5*a+.25*e.y2},tangentIn:fr(s-e.x1,a-e.y1),tangentOut:fr(e.x2-s,e.y2-a)}}function ey(e,t,n={}){const r=e.x2-e.x1,o=e.y2-e.y1,i=Math.abs(r)>=Math.abs(o),s=Math.abs(i?r:o)*(.5+Math.abs(t)),a=n.sourceNormal,l=n.targetNormal,u=Math.hypot(r,o),c=(w,x)=>x<0?Math.min(s,Math.max(20,u*.2)):s,d=a?c(a,a.x*r+a.y*o):s,f=l?c(l,-(l.x*r+l.y*o)):s,p=a?[e.x1+a.x*d,e.y1+a.y*d]:i?[e.x1+Math.sign(r||1)*s,e.y1]:[e.x1,e.y1+Math.sign(o||1)*s],h=l?[e.x2+l.x*f,e.y2+l.y*f]:i?[e.x2-Math.sign(r||1)*s,e.y2]:[e.x2,e.y2-Math.sign(o||1)*s],y=[e.x1,e.y1],g=[e.x2,e.y2],m=p,b=h;return{d:`M${e.x1},${e.y1}C${p[0]},${p[1]} ${h[0]},${h[1]} ${e.x2},${e.y2}`,hit:dl(y,m,b,g),start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:.125*e.x1+.375*p[0]+.375*h[0]+.125*e.x2,y:.125*e.y1+.375*p[1]+.375*h[1]+.125*e.y2},tangentIn:fr(p[0]-e.x1,p[1]-e.y1),tangentOut:fr(e.x2-h[0],e.y2-h[1])}}const ty=12;function GA(e,t,n,r={}){const o=r.source,i=n*(1+.6*(r.nest||0));if(!o||!r.loopOut){const M=e.x1,$=e.y1,F=t<0?-1:1,D=i*.9,z=i*1.8*F,j=[M-D,$-z],G=[M+D,$-z],J=[M,$];return{d:`M${M},${$}C${j[0]},${j[1]} ${G[0]},${G[1]} ${M},${$}`,hit:dl(J,j,G,J),start:{x:M,y:$},end:{x:M,y:$},mid:{x:M,y:$-z*.75},tangentIn:fr(j[0]-M,j[1]-$),tangentOut:fr(M-G[0],$-G[1])}}const s=r.loopOut,a=r.loopIn||s,l=r.sourceGap||0,u=r.targetGap||0,c=tn[s],d=tn[a];if(s===a){const M=c,$={x:-M.y,y:M.x},F=M.x?o.hh:o.hw,D=Math.min(i*.35,F*.8),z=o.cx+M.x*o.hw,j=o.cy+M.y*o.hh,G=[z-$.x*D+M.x*l,j-$.y*D+M.y*l],J=[z+$.x*D+M.x*u,j+$.y*D+M.y*u],re=[z+M.x*i*1.8-$.x*i*.9,j+M.y*i*1.8-$.y*i*.9],Q=[z+M.x*i*1.8+$.x*i*.9,j+M.y*i*1.8+$.y*i*.9];return{d:`M${G[0]},${G[1]}C${re[0]},${re[1]} ${Q[0]},${Q[1]} ${J[0]},${J[1]}`,hit:dl(G,re,Q,J),start:{x:G[0],y:G[1]},end:{x:J[0],y:J[1]},mid:{x:z+M.x*(i*1.35+ty),y:j+M.y*(i*1.35+ty)},tangentIn:fr(re[0]-G[0],re[1]-G[1]),tangentOut:fr(J[0]-Q[0],J[1]-Q[1])}}const f=Et.indexOf(s),p=Et.indexOf(a),h=(p-f+4)%4,y=M=>{const $=[];for(let F=f;F!==p;F=(F+M+4)%4)$.push(Et[(F+M+4)%4]);return $};let g=h<2?1:h>2?-1:0;if(!g){const M=y(1);g=M.includes("top")||!y(-1).includes("top")&&M.includes("right")?1:-1}const m=o.cx-o.hw-i,b=o.cx+o.hw+i,w=o.cy-o.hh-i,x=o.cy+o.hh+i,S={top:[b,w],right:[b,x],bottom:[m,x],left:[m,w]},v=o.cx+c.x*o.hw,k=o.cy+c.y*o.hh,_=o.cx+d.x*o.hw,T=o.cy+d.y*o.hh,L=[[v+c.x*l,k+c.y*l],[v+c.x*i,k+c.y*i]];for(let M=f;M!==p;M=(M+g+4)%4){const $=g>0?Et[M]:Et[(M+3)%4];L.push(S[$])}L.push([_+d.x*i,T+d.y*i],[_+d.x*u,T+d.y*u]);const N=Mb(L,Number(r.cornerRadius)||i*.4),I=L[0],O=L[L.length-1];return{points:N,curve:"linear",start:{x:I[0],y:I[1]},end:{x:O[0],y:O[1]},mid:Eb(N),tangentIn:c,tangentOut:{x:-d.x||0,y:-d.y||0}}}function Mb(e,t){if(!(t>0)||e.length<3)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const o=e[r-1],i=e[r],s=e[r+1],a=Math.hypot(i[0]-o[0],i[1]-o[1]),l=Math.hypot(s[0]-i[0],s[1]-i[1]),u=Math.min(t,a/2),c=Math.min(t,l/2);if(!a||!l){n.push(i);continue}const d=[i[0]+(o[0]-i[0])/a*u,i[1]+(o[1]-i[1])/a*u],f=[i[0]+(s[0]-i[0])/l*c,i[1]+(s[1]-i[1])/l*c];for(const p of rc(d,i,f,HA))n.push(p)}return n.push(e[e.length-1]),n}function Eb(e){const t=[];let n=0;for(let o=1;o<e.length;o++){const i=Math.hypot(e[o][0]-e[o-1][0],e[o][1]-e[o-1][1]);t.push(i),n+=i}let r=n/2;for(let o=0;o<t.length;o++){if(r<=t[o]||o===t.length-1){const i=t[o]?r/t[o]:0;return{x:e[o][0]+(e[o+1][0]-e[o][0])*i,y:e[o][1]+(e[o+1][1]-e[o][1])*i}}r-=t[o]}return{x:e[0][0],y:e[0][1]}}function ny(e,t){const n=r=>r&&r!=="auto"?String(r):null;return e?{side:n(e.side),offset:+e.offset||0}:{side:n(t),offset:0}}function VA(e,t,n){const r=n.source||{cx:e.x1,cy:e.y1,hw:0,hh:0},o=n.target||{cx:e.x2,cy:e.y2,hw:0,hh:0},i=ny(n.sourcePort,n.sourceSide),s=ny(n.targetPort,n.targetSide),a=U5({source:{box:r,port:{side:i.side,offset:i.offset+t}},target:{box:o,port:{side:s.side,offset:s.offset-t}},sourceGap:n.sourceGap||0,targetGap:n.targetGap||0,obstacles:n.obstacles,grid:n.grid});if(!a)return null;const l=Mb(a.points,Number(n.cornerRadius)||0),u=a.points[0],c=a.points[a.points.length-1],d=tn[a.sourceSide],f=tn[a.targetSide];return{points:l,curve:"linear",start:{x:u[0],y:u[1]},end:{x:c[0],y:c[1]},mid:Eb(l),tangentIn:d,tangentOut:{x:-f.x||0,y:-f.y||0}}}const yl={line:{anchors:"chord",build:e=>KA(e)},step:{anchors:"chord",build:Gc("step")},stepBefore:{anchors:"chord",build:Gc("stepBefore")},stepAfter:{anchors:"chord",build:Gc("stepAfter")},orthogonal:{anchors:"box",build:VA},arc:{anchors:"chord",build:(e,t)=>YA(e,t)},bezier:{anchors:"chord",build:(e,t,n)=>ey(e,t,n)},smooth:{anchors:"chord",build:(e,t,n)=>ey(e,t,n)},loop:{anchors:"chord",build:(e,t,n)=>GA(e,t,n.loopRadius||0,n)}},XA=Object.keys(yl).filter(e=>e!=="loop");function Ab(e,t){const n=r=>!!(t&&t.fields[r]);return{x:e.x||(n("x")?{field:"x"}:void 0),y:e.y||(n("y")?{field:"y"}:void 0)}}function Tb(e,t,n,r,o,i,s,a,l){const u=Ab(t,n);return r.map((c,d)=>{if(!c)return null;if(o){const f=o(c,d,r);if(f&&[f.cx,f.cy,f.hw,f.hh].every(Number.isFinite))return f}return{cx:se(e,u,"x",c,a/2,d,r),cy:se(e,u,"y",c,l/2,d,r),hw:i/2,hh:s/2}})}const JA=.16,ZA=.9,QA=22,ry=12,e4=8,oy=140,iy=10,t4=["stroke","strokeWidth","strokeOpacity"],n4="#ffffff",r4=3,o4=3,i4=.9;function s4(e){return e?Object.keys(e.fields).filter(t=>e.fields[t]&&e.fields[t].type==="ref"):[]}function a4(e,t,n,r){if(!n||!n.schema)return null;const o=n.schema,i=o.tables[r],s=o.byRole.nodes||o.primary,a=o.tables[s];if(!i||!a)return null;const l=s4(i),u=e.source&&e.source.field||l[0],c=e.target&&e.target.field||l[1],d=a.key;return{rows:n.tables&&n.tables[s]||[],nodesName:s,sourceField:u,targetField:c,keyField:d}}function l4(e,t,n,r,o,i){const s=n-e,a=r-t,l=Math.hypot(s,a);if(!l||o+i>=l)return null;const u=s/l,c=a/l;return{x1:e+u*o,y1:t+c*o,x2:n-u*i,y2:r-c*i}}function sy(e,t){if(e==null||e==="auto")return null;const n=String(e);return Et.includes(n)?n:(ge(`link:side:${n}`,`link() got ${t}: ${JSON.stringify(e)}, which is not an edge. Use ${Et.map(r=>`"${r}"`).join(", ")}, or null to let the end slide along the box toward the other node. Sliding.`),null)}function ay(e,t){if(e==null)return 0;const n=+e;return Number.isFinite(n)?Math.max(-Oi,Math.min(Oi,n)):(ge(`link:offset:${t}`,`link() got ${t}: ${JSON.stringify(e)}, which is not a number. It is a fraction of the edge from its midpoint, between ${-Oi} and ${Oi}. Using the midpoint.`),0)}function c4(e,t){let n=e;switch(n==null||n==="auto"?n=t===!0?"target":"none":n===!0?n="target":n===!1&&(n="none"),n){case"none":return{source:!1,target:!1};case"target":return{source:!1,target:!0};case"source":return{source:!0,target:!1};case"both":return{source:!0,target:!0};default:return ge(`link:arrow:${n}`,`link() got arrow: ${JSON.stringify(n)}, which it doesn't know. Use "none", "target", "source", "both", or "auto" (the target end when the links table declares directed: true). Drawing no arrowhead.`),{source:!1,target:!1}}}function ly(e,t,n,r){const o=r*.5;return`M${e+n.x*r},${t+n.y*r}L${e-n.y*o},${t+n.x*o}L${e+n.y*o},${t-n.x*o}Z`}function u4(e,t,n,r,o){const i=new Map,s=new Map,a=u=>{const c=String(u[t]),d=String(u[n]);return c<d?`${c}\0${d}`:`${d}\0${c}`};e.forEach((u,c)=>{if(!u)return;const d=a(u),f=i.get(d);f?f.push(c):i.set(d,[c])});const l=new Array(e.length).fill(0);for(const u of i.values())u.length<2||u.forEach((c,d)=>{const f=e[c];if(r){const p=`${f[t]}\0${f[n]}`,h=s.get(p)||0;s.set(p,h+1),l[c]=o*(h+1)}else l[c]=o*((2*d-(u.length-1))/2)});return l}function f4(e,t,n){const r=new Map;return e.map(o=>{if(!o||o[t]==null||o[t]!==o[n])return-1;const i=String(o[t]),s=r.get(i)||0;return r.set(i,s+1),s})}function d4(e={}){const t=at(e,{mark:"link",allow:st.link}),{channels:n={},id:r,edits:o,table:i,curve:s="line",curvature:a="auto",spread:l=JA,arrow:u="auto",arrowSize:c=6,loopRadius:d=QA,inset:f=0,sourceInset:p,targetInset:h,format:y,cornerRadius:g=e4,sourceSide:m="auto",targetSide:b="auto",sourceOffset:w=0,targetOffset:x=0,labelBackground:S,labelPadding:v=r4,labelRadius:k=o4,labelOpacity:_=i4}=t,T=$r(y),L=I=>!!(n[I]&&n[I].edit)||Array.isArray(o)&&o.some(O=>O&&Array.isArray(O.channels)&&O.channels.includes(I)),N={source:L("source"),target:L("target")};return{...lt(t),type:"link",channels:n,table:i,tableRole:"links",supportsNetwork:!0,rawChannels:["sourceSide","targetSide","sourceOffset","targetOffset","curve","arrow","fontSize"],discreteScale:void 0,build:(I,O,M,$,F)=>{const D=a4(n,t,F,F?F.table:"");if(!D)return ge("link:structure",'link() needs a network dataset: declare schema: { structure: "network", tables: { nodes: {…}, links: {…} } }. Without a links table there is nothing for it to draw.'),[];if(!D.keyField)return ge("link:key",'link() cannot find the column that identifies a node. Mark one in the node table with `key: true` (e.g. id: { type: "categorical", key: true }), or pass link({ key: "id" }). No links are drawn until it can.'),[];if(!D.sourceField||!D.targetField)return ge("link:refs",`link() cannot find the link table's endpoint columns. Declare them as references — source: { type: "ref" }, target: { type: "ref" } — or name them with channels: { source: { field: … }, target: { field: … } }.`),[];const z=F.schema,j=z.tables[D.nodesName],G=Ab(n,j),J=it(O),re=Nt(O,"link",{stroke:J.ink,fill:"none"}),Q=fn(O,t),ve=p??f,Ce=h??f,le=F&&F.nodeBox||null,me=F&&F.nodePorts||null,ce=(f||ry)*2,Y=(f||ry)*2,fe=!!le,ie=Ms(z),U=a==="auto"?u4(I,D.sourceField,D.targetField,ie,l):null,we=f4(I,D.sourceField,D.targetField),xe=n.text?{...n}:null;if(xe)for(const Se of t4)delete xe[Se];const P=xe&&S?S===!0?J.background||n4:String(S):null,H=J.font&&J.font.family||void 0,oe=new Map;D.rows.forEach((Se,ae)=>{const _e=Se?Se[D.keyField]:void 0;_e!=null&&!oe.has(_e)&&oe.set(_e,{row:Se,index:ae})});let he=null,ke=[],pe;const $e=()=>{if(he)return he;const Se=Tb(O,n,j,D.rows,le,ce,Y,M,$);return ke=Se.filter(Boolean),pe=K5(ke),he=Se,Se},Te=[];return I.forEach((Se,ae)=>{const _e=oe.get(Se?Se[D.sourceField]:void 0),Pe=oe.get(Se?Se[D.targetField]:void 0),Z=F&&F.ghost&&F.ghost.pointer?F.ghost.pointer:null,vt=!_e&&Pe&&Z?Z:null,rt=!Pe&&_e&&Z?Z:null,dt=vt||rt;if(!_e&&!vt||!Pe&&!rt)return;const gt=le&&_e?$e()[_e.index]:null,Wt=le&&Pe?$e()[Pe.index]:null,At=gt?gt.cx:_e?se(O,G,"x",_e.row,M/2,_e.index,D.rows):vt.x,Jt=gt?gt.cy:_e?se(O,G,"y",_e.row,$/2,_e.index,D.rows):vt.y,qt=Wt?Wt.cx:Pe?se(O,G,"x",Pe.row,M/2,Pe.index,D.rows):rt.x,Qn=Wt?Wt.cy:Pe?se(O,G,"y",Pe.row,$/2,Pe.index,D.rows):rt.y,C=!!Pe&&!!_e&&_e.index===Pe.index,W=c4(pt(n,"arrow",Se,u,ae,I),ie);let q=U?U[ae]:+a||0,V=C?"loop":String(pt(n,"curve",Se,s,ae,I));yl[V]||(ge(`link:curve:${V}`,`link() got curve: "${V}", which it doesn't know. Use one of ${XA.map(Ue=>`"${Ue}"`).join(", ")}. Drawing a straight line.`),V="line"),V==="line"&&q&&(V="arc");const ee=yl[V];let ue;const be={loopRadius:d,cornerRadius:+g||0},Oe={side:sy(pt(n,"sourceSide",Se,m,ae,I),"sourceSide"),offset:ay(pt(n,"sourceOffset",Se,w,ae,I),"sourceOffset")},Ze={side:sy(pt(n,"targetSide",Se,b,ae,I),"targetSide"),offset:ay(pt(n,"targetOffset",Se,x,ae,I),"targetOffset")},rn=(Ue,Tt,Zt)=>$e()[Ue]||{cx:Tt,cy:Zt,hw:ce/2,hh:Y/2},wt=_e?rn(_e.index,At,Jt):{cx:At,cy:Jt,hw:0,hh:0},ct=Pe?rn(Pe.index,qt,Qn):{cx:qt,cy:Qn,hw:0,hh:0},zn=(Ue,Tt)=>{if(!me||!Ue)return null;const Zt=me(Ue.row,Ue.index,D.rows)||{},Rt=Et.filter(sn=>j0(Zt[sn],Tt));return Rt.length?Rt:null},An=zn(_e,"source"),Bt=zn(Pe,"target");if(C){const Ue=z5(An,Bt,Oe.side,Ze.side,Math.max(0,we[ae]));be.loopOut=Ue.out,be.loopIn=Ue.in,be.nest=Ue.nest}else An&&!Oe.side&&(Oe.side=Op(wt,An,{x:ct.cx,y:ct.cy}));!C&&Bt&&!Ze.side&&(Ze.side=Op(ct,Bt,{x:wt.cx,y:wt.cy}));const Ht=(An?0:ve)+(W.source?c:0),It=(Bt?0:Ce)+(W.target?c:0);if(ee.anchors==="box")ue={x1:At,y1:Jt,x2:qt,y2:Qn},be.source=wt,be.target=ct,be.sourceGap=Ht,be.targetGap=It,be.obstacles=ke,be.grid=pe,be.sourcePort=Oe,be.targetPort=Ze;else if(C)ue={x1:At,y1:Jt,x2:At,y2:Jt},fe?(be.source=wt,be.sourceGap=Ht,be.targetGap=It):(delete be.loopOut,be.nest=Math.floor(Math.max(0,we[ae])/2));else if(fe||Oe.side||Ze.side){const Ue=z0(wt,Oe,Ht,ct,Ze,It),Tt=(sn,tr,yo)=>{const go=yo.x-sn.cx,zs=yo.y-sn.cy,yc=sn.hw+tr,Ds=sn.hh+tr,js=1/(Math.hypot(go/(yc||1e-6),zs/(Ds||1e-6))||1);return{x:sn.cx+go*js,y:sn.cy+zs*js}},Zt=!Oe.side&&wt.round?Tt(wt,Ht,Ze.side?Ue.b:{x:ct.cx,y:ct.cy}):Ue.a,Rt=!Ze.side&&ct.round?Tt(ct,It,Oe.side?Ue.a:{x:wt.cx,y:wt.cy}):Ue.b;ue=Math.hypot(Rt.x-Zt.x,Rt.y-Zt.y)<1?null:{x1:Zt.x,y1:Zt.y,x2:Rt.x,y2:Rt.y},Oe.side&&(be.sourceNormal=tn[Oe.side]),Ze.side&&(be.targetNormal=tn[Ze.side])}else ue=l4(At,Jt,qt,Qn,Ht,It);if(!ue)return;if(U&&q&&xe&&ee.anchors==="chord"&&!C){const Ue=Math.hypot(ue.x2-ue.x1,ue.y2-ue.y1),Tt=l*Ue/2,Rt=(+pt(n,"fontSize",Se,12,ae,I)||12)+v*2+2;Tt>0&&Tt<Rt&&(q=Math.sign(q)*Math.min(Math.abs(q)*(Rt/Tt),ZA))}const tt=yt(O,n,Se,re,ae,I),Xe=ee.build(ue,q,be);if(!Xe)return;const Dr=+pt(n,"fontSize",Se,12,ae,I)||12,jr={x:Xe.mid.x-oy/2,y:Xe.mid.y-(Dr+iy)/2,width:oy,height:Dr+iy},er=Xe.hit||Xe.points;er&&Te.push({type:"path",points:er,curve:Xe.hit?"linear":Xe.curve,stroke:"transparent",strokeWidth:Math.max(hb,+tt.strokeWidth||0),strokeLinecap:"round",fill:"none",hit:!0,editBox:jr,data:Se,index:ae}),Te.push({type:"path",...Xe.d?{d:Xe.d}:{points:Xe.points,curve:Xe.curve},...tt,fill:"none",...dt?{strokeDasharray:"4 3"}:{},editBox:jr,data:Se,index:ae});const on=tt.stroke||re.stroke;if(W.target&&Te.push({type:"path",d:ly(Xe.end.x,Xe.end.y,Xe.tangentOut,c),fill:on,stroke:"none",data:Se,index:ae}),W.source&&Te.push({type:"path",d:ly(Xe.start.x,Xe.start.y,{x:-Xe.tangentIn.x,y:-Xe.tangentIn.y},c),fill:on,stroke:"none",data:Se,index:ae}),xe){const Ue=Object.assign(gd(O,xe,Se,ae,Xe.mid.x,Xe.mid.y,{format:T,data:I}),{editBox:jr});if(P&&Ue.text!==""&&Ue.text!=null){const Tt=oc(String(Ue.text),{fontSize:+(Ue.fontSize||0)||12,fontFamily:H}),Zt=Tt.width+v*2,Rt=Tt.height+v*2,sn=Ue.x||0,tr=Ue.y||0;Te.push({type:"rect",x:Ue.textAnchor==="start"?sn:Ue.textAnchor==="end"?sn-Zt:sn-Zt/2,y:Ue.lineAnchor==="top"?tr:Ue.lineAnchor==="bottom"?tr-Rt:tr-Rt/2,width:Zt,height:Rt,rx:k,fill:P,fillOpacity:_,stroke:"none",...Ue.angle?{angle:Ue.angle}:{},editBox:jr,data:Se,index:ae})}Te.push(Ue)}for(const[Ue,Tt]of[["source",Xe.start],["target",Xe.end]])!N[Ue]||!Q.grabbable||Te.push({type:"circle",cx:Tt.x,cy:Tt.y,r:Q.size,fill:Q.fill,stroke:Q.stroke,strokeWidth:Q.strokeWidth,channel:Ue,onHover:!0,raise:!0,data:Se,index:ae})}),Te}}}function Ob(e){if(!e||!e.raw||typeof e.raw.scale!="function")return!1;const t=2*Math.PI*e.raw.scale();if(!Number.isFinite(t)||t<=0)return!1;const n=e.apply([0,0]);if(!n)return!1;const r=n[0]-t/2,o=n[1]-t/2,i=l=>{const u=l*Math.PI/180;return o+t*(.5-Math.log(Math.tan(Math.PI/4+u/2))/(2*Math.PI))},s=l=>r+t*(l+180)/360,a=Math.max(.5,t*1e-6);for(const[l,u]of[[90,0],[-60,45],[30,-30],[0,60]]){const c=e.apply([l,u]);if(!c||Math.abs(c[0]-s(l))>a||Math.abs(c[1]-i(u))>a)return!1}return!0}function Cb(e,t,n,r={}){const{tileSize:o=256,minZoom:i=0,maxZoom:s=19,zoomOffset:a=0}=r;if(!Ob(e)||!(t>0)||!(n>0))return null;const l=e,u=2*Math.PI*l.raw.scale();if(!Number.isFinite(u)||u<=0)return null;const c=Math.round(Math.log2(u/o))+a,d=Math.max(i,Math.min(s,c)),f=2**d,p=u/f,h=l.apply([0,0]);if(!h)return null;const y=h[0]-u/2,g=h[1]-u/2,m=Math.floor((0-y)/p),b=Math.ceil((t-y)/p),w=Math.floor((0-g)/p),x=Math.ceil((n-g)/p),S=[];for(let v=Math.max(0,w);v<Math.min(f,x);v++)for(let k=m;k<b;k++){const _=(k%f+f)%f;S.push({z:d,x:_,y:v,px:y+k*p,py:g+v*p,size:p,key:`${d}/${_}/${v}`})}return{z:d,size:p,tiles:S}}function Nb(e,t,n=["a","b","c"]){if(typeof e=="function")return e(t);const r=n.length?n[Math.abs(t.x+t.y)%n.length]:"";return e.replace("{s}",r).replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y))}const h4=Symbol("single");function p4(){ge("geoTile:mercator",'geoTile needs projection: "mercator" (unrotated). Tiles are images baked in Web Mercator — under another projection they cannot align with the data, so none are drawn. Use geoBasemap({ geojson }) for vector chrome under other projections.')}function Nr(e){return e&&e.projection||null}function pn(e,t){const n=e[t];return n&&n.field!=null?n.field:null}function y4(e={}){const t=at(e,{mark:"geoBasemap",allow:st.geoBasemap,except:["stroke","strokeWidth","fill"]}),{channels:n={},id:r,edits:o,geojson:i,stroke:s="#94a3b8",strokeWidth:a=.75,fill:l="#e2e8f0"}=t,u=i||null;return{...lt(t),type:"geoBasemap",channels:n,supportsGeo:!0,build:(c,d,f,p)=>{const h=Nr(d);if(!h||!u)return[];const y=yt(d,n,{},{fill:l,stroke:s,strokeWidth:a}),g=y.fill!=null?y.fill:l,m=y.stroke!=null?y.stroke:s,b=y.strokeWidth!=null?y.strokeWidth:a,w=u.type==="FeatureCollection"&&Array.isArray(u.features)?u.features:[u],x=[];return w.forEach((S,v)=>{const k=S&&S.type==="Feature"?S.geometry:S;if(!k)return;const _=h.path(k);_&&x.push({type:"path",d:_,fill:g,stroke:m,strokeWidth:b,opacity:y.opacity,fillOpacity:y.fillOpacity,strokeOpacity:y.strokeOpacity,background:!0,pointerEvents:"none",index:v})}),x}}}function g4(e={}){const t=at(e,{mark:"geoTile",allow:st.geoTile,except:["opacity"]}),{channels:n={},id:r,edits:o,url:i="https://tile.openstreetmap.org/{z}/{x}/{y}.png",subdomains:s=[],tileSize:a=256,minZoom:l=0,maxZoom:u=19,zoomOffset:c=0,opacity:d,attribution:f="© OpenStreetMap contributors",attributionSize:p=9}=t;return{...lt(t),type:"geoTile",channels:n,supportsGeo:!0,build:(h,y,g,m)=>{const b=Nr(y);if(!b)return[];const w=Cb(b,g,m,{tileSize:a,minZoom:l,maxZoom:u,zoomOffset:c});if(!w)return p4(),[];const x=w.tiles.map(S=>({type:"image",x:S.px,y:S.py,width:S.size+.5,height:S.size+.5,href:Nb(i,S,s),opacity:d,background:!0,pointerEvents:"none",key:S.key}));return f&&x.push({type:"text",x:g-4,y:m-4,text:f,fontSize:p,textAnchor:"end",lineAnchor:"bottom",dominantBaseline:"text-after-edge",fill:"#334155",pointerEvents:"none"}),x}}}function m4(e={}){const t=at(e,{mark:"geoPoint",allow:st.geoPoint}),{channels:n={},id:r,edits:o}=t,i=pn(n,"lon")||"lon",s=pn(n,"lat")||"lat";return{...lt(t),type:"geoPoint",channels:n,supportsGeo:!0,lonKey:i,latKey:s,xKey:i,yKey:s,build:(a,l,u,c)=>{const d=Nr(l),f=[],p=Nt(l,"geoPoint",{fill:it(l).ink});return a.forEach((h,y)=>{const g=n.lon?h[i]:h.lon,m=n.lat?h[s]:h.lat,b=ur(d,g,m);if(!b)return;const w=yt(l,n,h,p,y,a);f.push({type:"circle",cx:b.x,cy:b.y,r:se(l,n,"size",h,5,y,a),...w,data:h,index:y})}),f}}}function b4(e={}){const t=at(e,{mark:"geoPolygon",allow:st.geoPolygon}),{channels:n={},id:r,edits:o}=t,i=pn(n,"geometry")||"geometry";return{...lt(t),type:"geoPolygon",channels:n,supportsGeo:!0,geometryKey:i,build:(s,a)=>{const l=Nr(a);if(!l)return[];const u=[];return s.forEach((c,d)=>{const f=c[i];if(!f)return;const p=l.path(f);if(!p)return;const h=yt(a,n,c,{fill:"#93c5fd",stroke:"#1e3a8a",strokeWidth:.75});u.push({type:"path",d:p,...h,data:c,index:d})}),u}}}function w4(e,t){const n=Qf(t);return n?e.slice().sort((r,o)=>{const i=r.d[n],s=o.d[n];return i==null||s==null?0:i<s?-1:i>s?1:0}):e}function x4(e={}){const t=at(e,{mark:"geoLine",allow:st.geoLine}),{channels:n={},id:r,edits:o,curve:i="linear",handles:s=!0,handleSize:a,handleColor:l}=t,u=pn(n,"coordinates")||"coordinates",c=pn(n,"geometry")||null,d=!!(n.lon&&n.lat),f=pn(n,"lon")||"lon",p=pn(n,"lat")||"lat",h=Os(n),y=t.connect||"sequence",g=t.showVertices!=null?t.showVertices:!d;return d?{...lt(t),type:"geoLine",channels:n,rawChannels:["curve","series","order"],supportsGeo:!0,lonKey:f,latKey:p,xKey:f,yKey:p,seriesKey:h,connect:y,supportsSeries:!0,build:(m,b)=>{const w=Nr(b);if(!w)return[];const x=[];m.forEach((_,T)=>{const L=ur(w,_[f],_[p]);L&&x.push({d:_,i:T,x:L.x,y:L.y,series:h?_[h]:h4})});const S=new Map;for(const _ of x){const T=S.get(_.series);T?T.push(_):S.set(_.series,[_])}const v=[],k=fn(b,{handles:s,handleSize:a,handleColor:l});for(const _ of S.values()){if(_.length<2)continue;const T=w4(_,n),L=yt(b,n,_[0].d,{stroke:"#1d4ed8",strokeWidth:2}),N=String(pt(n,"curve",_[0].d,i,_[0].i,m));v.push({type:"path",points:T.map(I=>[I.x,I.y]),curve:N,...L,fill:"none"})}return g&&x.forEach(_=>{v.push({type:"circle",cx:_.x,cy:_.y,r:k.size,fill:k.visible?k.fill:"transparent",stroke:"#fff",strokeWidth:1,data:_.d,index:_.i})}),v}}:{...lt(t),type:"geoLine",channels:n,supportsGeo:!0,coordinatesKey:u,geometryKey:c,supportsSeries:!1,build:(m,b)=>{const w=Nr(b);if(!w)return[];const x=[],S=fn(b,{handles:s,handleSize:a,handleColor:l});return m.forEach((v,k)=>{let _=null;if(c&&v[c]&&v[c].coordinates){const I=v[c];_=I.type==="LineString"?I.coordinates:I.type==="MultiLineString"?I.coordinates.flat():null}if(!_&&Array.isArray(v[u])&&(_=v[u]),!_||!_.length)return;const T={type:"LineString",coordinates:_},L=w.path(T),N=yt(b,n,v,{fill:"none",stroke:"#1d4ed8",strokeWidth:2});L&&x.push({type:"path",d:L,...N,fill:"none",data:v,index:k,pointerEvents:"stroke"}),g&&_.forEach((I,O)=>{const M=ur(w,I[0],I[1]);M&&x.push({type:"circle",cx:M.x,cy:M.y,r:S.size,fill:S.visible?l||N.stroke||S.fill:"transparent",stroke:"#fff",strokeWidth:1,data:v,index:k,channel:"vertex",vertexIndex:O})})}),x}}}function v4(e={}){const t=at(e,{mark:"geoText",allow:st.geoText}),{channels:n={},id:r,edits:o,format:i}=t,s=pn(n,"lon")||"lon",a=pn(n,"lat")||"lat",l=$r(i);return{...lt(t),type:"geoText",channels:n,supportsGeo:!0,lonKey:s,latKey:a,xKey:s,yKey:a,build:(u,c)=>{const d=Nr(c),f=[];return u.forEach((p,h)=>{const y=ur(d,p[s],p[a]);y&&f.push(gd(c,n,p,h,y.x,y.y,{format:l,data:u}))}),f}}}function k4(e={}){const t=at(e,{mark:"geoRect",allow:st.geoRect}),{channels:n={},id:r,edits:o}=t,i=pn(n,"west")||"west",s=pn(n,"south")||"south",a=pn(n,"east")||"east",l=pn(n,"north")||"north";return{...lt(t),type:"geoRect",channels:n,supportsGeo:!0,westKey:i,southKey:s,eastKey:a,northKey:l,xKey:i,yKey:s,build:(u,c)=>{const d=Nr(c),f=[];return u.forEach((p,h)=>{const y=p[i],g=p[s],m=p[a],b=p[l];if(y==null||g==null||m==null||b==null)return;const w=Math.min(y,m),x=Math.max(y,m),S=Math.min(g,b),v=Math.max(g,b),k=b0(d,w,S,x,v);if(!k||k.width<=0||k.height<=0)return;const _=yt(c,n,p,{fill:"rgba(37, 99, 235, 0.2)",stroke:"#1d4ed8",strokeWidth:1.5}),T={type:"Polygon",coordinates:[[[w,S],[w,v],[x,v],[x,S],[w,S]]]},L=d&&d.path(T);L&&f.push({type:"path",d:L,..._,data:p,index:h,pointerEvents:"none"}),f.push({type:"rect",x:k.x,y:k.y,width:k.width,height:k.height,fill:"transparent",stroke:"transparent",data:p,index:h})}),f}}}const vd=Object.freeze(Object.defineProperty({__proto__:null,arc:wb,area:hd,areaX:tA,areaY:eA,bar:ld,barX:I6,barY:nc,composite:ii,curve:pd,curveX:rA,curveY:pb,donut:oA,dotStack:fd,dotStackX:K6,dotStackY:fb,ellipse:ub,face:RA,geoBasemap:y4,geoLine:x4,geoPoint:m4,geoPolygon:b4,geoRect:k4,geoText:v4,geoTile:g4,line:dd,lineX:X6,lineY:V6,link:d4,needle:iA,node:DA,path:J6,point:Sr,rect:Is,rectX:F6,rectY:R6,rule:cd,ruleX:j6,ruleY:cb,sticker:BA,text:Or,textX:wA,textY:xA,tick:hs,tickX:z6,tickY:lb,trend:$b,trendBand:_b,waffle:ud,waffleX:H6,waffleY:B6},Symbol.toStringTag,{value:"Module"}));function S4(e,t,n=1){return e>t+n?"start":e<t-n?"end":"middle"}const Ib=As.axisRadial;function $4(e={}){Cs("axisRadial",e,Ib);const{channels:t={},id:n,edits:r,channel:o="theta",radius:i,innerRadius:s=0,bandWidth:a=18,ticks:l=5,tickValues:u,tickFormat:c,tickSize:d=6,labelOffset:f=14,bands:p=!1,title:h,arc:y,orient:g,start:m,end:b,labelFill:w,stroke:x,strokeWidth:S=1.25,fontSize:v}=e,[k,_]=yd({arc:y,orient:g,start:m,end:b}),T=t.x&&t.x.field,L=t.y&&t.y.field;return{id:n,type:"axisRadial",channel:o,channels:t,edits:r,isAxis:!0,views:"scale",layer:"background",build:(N,I,O,M)=>{const $=I[o];if(!$)return[];const F=it(I),D=w??F.axis.labelFill,z=x??F.axis.stroke,j=v??F.axis.fontSize,G=typeof $.range=="function"?$.range():null;let J=k,re=_;G&&G.length>=2&&typeof G[0]=="number"&&(J=G[0],re=G[G.length-1]);const Q={background:!0,pointerEvents:"none"},{values:ve,format:Ce}=Ql($,{ticks:l,tickValues:u,tickFormat:c}),le=t.fill&&t.fill.field,me=(ie,U,we)=>{const xe=[];p&&fo($)&&$.domain().forEach((oe,he)=>{const ke=mb($,oe);if(!ke)return;const[pe,$e]=ke,Te=le?{[le]:oe}:{};let Se=se(I,t,"fill",Te,null);Se==null&&(Se=ls[he%ls.length]);const ae=s>0?s:Math.max(0,we-a),_e=ps(ie,U,we,pe,$e,{innerRadius:ae});_e&&xe.push({type:"path",d:_e,fill:Se,stroke:"none",fillOpacity:.9,...Q})});const P=hl(ie,U,we,J,re);return P&&xe.push({type:"path",d:P,fill:"none",stroke:z,strokeWidth:S,...Q}),ve.forEach(H=>{const oe=Mr($,H);if(oe==null||Number.isNaN(oe))return;const he=cn(ie,U,we,oe),ke=cn(ie,U,we-d,oe);d>0&&xe.push({type:"line",x1:he.x,y1:he.y,x2:ke.x,y2:ke.y,stroke:z,strokeWidth:1,...Q});const pe=cn(ie,U,we+f,oe);xe.push({type:"text",x:pe.x,y:pe.y,text:Ce(H),textAnchor:S4(pe.x,ie),dominantBaseline:"middle",fontSize:j,fill:D,...Q})}),h&&xe.push({type:"text",x:ie,y:U+we+f+j+8,text:h,textAnchor:"middle",fontSize:j+1,fill:"#0f172a",...Q}),xe};if(T||L){const ie=[],U=i??Math.min(O,M)*.42;return N.forEach((we,xe)=>{const P=se(I,t,"x",we,O/2,xe,N),H=se(I,t,"y",we,M/2,xe,N);ie.push(...me(P,H,U))}),ie}const ce=se(I,t,"x",N[0],O/2,0,N),Y=se(I,t,"y",N[0],M/2,0,N),fe=i??Math.min(O,M)*.42;return me(ce,Y,fe)}}}const _4=Object.freeze(Object.defineProperty({__proto__:null,axis:ec,axisRadial:$4,axisX:eb,axisY:tb,grid:id,gridX:nb,gridY:rb,legend:Ns,legendColor:s6,legendSize:a6,legendSymbol:l6},Symbol.toStringTag,{value:"Module"})),cy=e=>e.edit&&e.edit.threshold>0?e.edit.threshold:Jl,M4={shift:e=>!!(e.event&&e.event.shiftKey),noShift:e=>!(e.event&&e.event.shiftKey),alt:e=>!!(e.event&&e.event.altKey),noAlt:e=>!(e.event&&e.event.altKey),modifier:e=>t=>!!(t.event&&t.event[e]),noModifier:e=>t=>!(t.event&&t.event[e]),near:e=>Ar(e.marks||[],e.pointer.x,e.pointer.y,cy(e))!=null,far:e=>Ar(e.marks||[],e.pointer.x,e.pointer.y,cy(e))==null,nearWithin:e=>t=>Ar(t.marks||[],t.pointer.x,t.pointer.y,e)!=null},uy={year:Gn,month:Bl,week:_s,day:ri,hour:ql,minute:Wl};function Lb(e,t){if(!e)return[];if(fo(e)||e.kind==="discrete")return[...e.domain()];if(Array.isArray(t))return t;if(typeof t=="number")return fy(e,t);if(t&&typeof t=="object"){if(typeof t.count=="number")return fy(e,t.count);if(t.every&&e.temporal&&uy[t.every]&&typeof e.ticks=="function")return e.ticks(uy[t.every])}if(typeof e.ticks=="function"){const n=e.ticks();if(n&&n.length)return n}return[...e.domain()]}function fy(e,t){const n=e.domain(),r=Number(n[0]),o=Number(n[n.length-1]),i=!!e.temporal;if(t<=1)return[n[0]];const s=[];for(let a=0;a<t;a++){const l=r+(o-r)*a/(t-1);s.push(i?new Date(l):l)}return s}function E4(e={}){const{into:t="nearest",series:n,...r}=e,o=W0(e.threshold);return je({type:"line.anchor",gesture:"click",channels:["x","y"],pick:"plane",scope:"line",into:t,cardinality:"append",...r,apply:i=>{const s=n||i.seriesKey||null;let a=null;t==="nearest"&&(a=Ar(i.marks||[],i.pointer.x,i.pointer.y,o),a==null&&i.connect==="sequence"&&s&&(i.data||[]).length&&(a=i.data[i.data.length-1][s])),a==null&&(a=Yl(i.data,s));const l=Fn(i,{defaults:s?{[s]:a}:{}});if(l)return[...i.data,l]}})}function A4(e={}){const{along:t="x",value:n="y",samples:r,series:o,...i}=e;return je({type:"line.newSeries",gesture:"dblclick",cardinality:"appendMany",channels:[t,n],pick:"plane",scope:"line",...i,apply:s=>{const a=o||s.seriesKey||null,l=s.markChannels[t]&&s.markChannels[t].field||(t==="x"?s.xKey:s.yKey),u=s.markChannels[n]&&s.markChannels[n].field||(n==="x"?s.xKey:s.yKey),c=s.scales[t],d=s.scales[n];if(!c||!l)return;const f=Lb(c,r);if(!f.length)return;const p=n==="x"?s.pointer.x:s.pointer.y,h=d&&d.invertible?d.invertValue(p):d&&d.domain?d.domain()[0]:null,y=Yl(s.data,a),g=f.map(m=>{const b={...Es(s.schema)};return a&&(b[a]=y),b[l]=m,u&&(b[u]=h),b});return[...s.data,...g]}})}function T4(e={}){const{along:t="x",value:n="y",samples:r,minDist:o=8,into:i="nearest",series:s,...a}=e;return je({type:"line.draw",gesture:"drag",cardinality:"appendMany",inverts:!0,channels:[t,n],pick:"draw",scope:"line",into:i,...a,apply:l=>{const u=l.session;if(!u)return;const c=s||l.seriesKey||null,d=u.drawSeries,f=l.connect==="sequence",p={};for(const v of l.channels)p[v.name]=v;if(u.mode==="edit"){const v=f?In(l.marks||[],l.pointer.x,l.pointer.y,1/0,d):td(l.marks||[],l.pointer.x,l.pointer.y,1/0,t,d);if(v==null||l.data[v]==null)return;const k={...l.data[v]};for(const _ of l.channels){if(!f&&_.name!==n)continue;const T=ho(_,l.pointer);T!==void 0&&(k[_.field]=T)}return l.data.map((_,T)=>T===v?k:_)}if(f){const v=l.pointer.x,k=l.pointer.y;if(u.lastX!=null&&u.lastY!=null&&Math.hypot(v-u.lastX,k-u.lastY)<o)return;const _=Fn(l,{defaults:c?{[c]:d}:{}});return _?(u.lastX=v,u.lastY=k,[...l.data,_]):void 0}const h=p[t],y=p[n];if(!h||!y||!h.scale||!y.scale||!h.scale.invertible||!y.scale.invertible)return;const g=Lb(l.scales[t],r);if(!g.length)return;const m=h.scale.invertValue(t==="x"?l.pointer.x:l.pointer.y),b=y.scale.invertValue(n==="x"?l.pointer.x:l.pointer.y),w=()=>{let v=null,k=1/0;for(const _ of g){const T=Math.abs(xn(_)-xn(m));T<k&&(k=T,v=_)}return v==null?[]:[v]};let x;if(u.lastDomain==null)x=w();else{const v=Math.min(xn(u.lastDomain),xn(m)),k=Math.max(xn(u.lastDomain),xn(m));x=g.filter(_=>xn(_)>=v&&xn(_)<=k),x.length||(x=w())}u.lastDomain=m;const S=l.data.slice();for(const v of x){const k=S.findIndex(T=>(!c||T[c]===d)&&xn(T[h.field])===xn(v)),_={...Es(l.schema),...k>=0?S[k]:{}};c&&(_[c]=d),_[h.field]=v,_[y.field]=b,k>=0?S[k]=_:S.push(_)}return S}})}function O4(e={}){return e.mode==="relative"&&(ge("sweep:relative",`edit.line.sweep({ mode: "relative" }) is not a mode a sweep has — the pointer's POSITION is the value it paints. Ignoring mode.`),e={...e,mode:"absolute"}),Xn({pick:"sweep",guide:!0,scope:"line",...e,type:"line.sweep"})}function C4(e={}){const{series:t,...n}=e;return je({type:"line.removeSeries",gesture:"click",scope:"line",cardinality:"delete",...n,apply:r=>{if(r.datum==null)return;const o=t||r.seriesKey||null;if(!o)return r.data.filter((s,a)=>a!==r.index);const i=r.datum[o];return r.data.filter(s=>s[o]!==i)}})}function N4(e,t){return t?[t]:e&&e.fields||[]}function I4(e,t){const n={};for(const r of e)n[r]=t;return n}function L4(e={}){const{field:t,mode:n="rescale",...r}=e,o=6;return je({type:"axis.scale",gesture:"drag",pick:"axisDrag",scope:"axis",target:"domain",...r,apply:i=>{const s=i.session,a=i.channels[0];if(!s||!s.grabEnd||!a||!a.scale)return;const l=N4(a.scale,t);if(!l.length)return;const u=s.anchorPixel,c=xn(s.anchorValue),d=xn(s.grabValue),f=s.anchorValue instanceof Date||s.grabValue instanceof Date;let h=(s.axis==="x"?i.pointer.x:i.pointer.y)-u;const y=s.grabPixel-u;Math.abs(h)<o&&(h=h<0?-o:o);let g;if(n==="grow"){const S=s.pxPerUnit||y/(d-c||1);g=c+h/(S||1)}else g=c+(d-c)*(y/h);const m=Math.min(c,g),b=Math.max(c,g);if(!Number.isFinite(m)||!Number.isFinite(b)||b<=m)return;const w=f?[new Date(m),new Date(b)]:[m,b],x={domains:I4(l,w)};if(n==="grow"){const S=Math.abs(s.pxPerUnit||1),v=(b-m)*S,k=i.margins||{top:20,right:20,bottom:30,left:40};x.resize=s.axis==="x"?{width:v+k.left+k.right}:{height:v+k.top+k.bottom}}return x}})}function F4(e,t,n){const r=e&&e.fieldRefs||[];if(t){const o=r.filter(i=>i.field===t);return o.length?o:[{table:n,field:t}]}return r.length?r:(e&&e.fields||[]).map(o=>({table:n,field:o}))}function Vc(e,t,n,r,o){const i={domains:{}},s={},a={};for(const l of e)(a[l.table]||(a[l.table]=[])).push(l.field);for(const[l,u]of Object.entries(a)){const c={};let d=o[l]||[],f=!1;for(const p of u){c[p]=t({table:l,field:p});const h=n({table:l,field:p},d);h&&(d=h,f=!0)}l===r?(i.domains=c,f&&(i.data=d)):s[l]=f?{domains:c,data:d}:{domains:c}}return Object.keys(s).length&&(i.tables=s),i}function dy(e,t){const n=e.channels[0],r=n&&$t(n.name);if(!r)return;const o=n&&n.scale,i=o&&typeof o.step=="function"?o.step():null;if(!i)return;const s=e.margins||{top:20,right:20,bottom:30,left:40};if(r==="y"){const l=(e.height||0)+t*i;return l>i?{height:l+s.top+s.bottom}:void 0}const a=(e.width||0)+t*i;return a>i?{width:a+s.left+s.right}:void 0}function R4(e={}){const{field:t,mode:n="rescale",when:r,...o}=e,i=n==="grow",s=f=>F4(f.channels[0]&&f.channels[0].scale,t,f.table||"data"),a=f=>{const p=f.channels[0];return p&&p.scale&&typeof p.scale.domain=="function"?[...p.scale.domain()]:[]},l=f=>f.tables||{[f.table]:f.data},u=je({type:"scale.addCategory",gesture:"commit",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.addCategory),r),apply:f=>{const p=f.value!=null?String(f.value).trim():"";if(!p)return;const h=a(f);if(h.includes(p))return;const y=s(f);if(!y.length)return;const g=Vc(y,()=>[...h,p],()=>null,f.table,l(f));if(i){const m=dy(f,1);m&&(g.resize=m)}return g}}),c=je({type:"scale.renameCategory",gesture:"commit",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.category!=null),r),apply:f=>{const p=f.node&&f.node.category,h=f.value!=null?String(f.value).trim():"";if(p==null||!h||h===p)return;const y=a(f);if(y.includes(h))return;const g=s(f);if(!g.length)return;const m=y.map(b=>b===p?h:b);return Vc(g,()=>m,({field:b},w)=>w.map(x=>x[b]===p?{...x,[b]:h}:x),f.table,l(f))}}),d=je({type:"scale.removeCategory",gesture:"click",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.removeCategory!=null),r),apply:f=>{const p=f.node&&f.node.removeCategory;if(p==null)return;const h=a(f);if(!h.includes(p))return;const y=s(f);if(!y.length)return;const g=h.filter(b=>b!==p),m=Vc(y,()=>g,({field:b},w)=>w.filter(x=>x[b]!==p),f.table,l(f));if(i){const b=dy(f,-1);b&&(m.resize=b)}return m}});return[u,c,d]}function Fb(e){return e?e.field:void 0}function Rb(e,t,n){const r=e.node&&e.node.indices||[];if(r.length>1){const o=new Set(r);return e.data.map((i,s)=>o.has(s)?{...i,[t]:n}:i)}return{...e.datum,[t]:n}}function P4(e={}){return je({type:"legend.category",gesture:"click",pick:"direct",scope:"legend",...e,apply:t=>{const n=Fb(t.channels[0]);if(!n||!t.node||t.datum==null)return;const r=t.node.category;if(r!==void 0)return Rb(t,n,r)}})}function z4(e={}){return je({type:"legend.value",gesture:"drag",pick:"direct",scope:"legend",...e,apply:t=>{const n=t.node;if(!n||n.rampStart==null||n.rampEnd==null)return;const r=Fb(t.channels[0]);if(!r||t.datum==null)return;const o=n.rampEnd-n.rampStart;if(!o)return;const i=n.along==="y"?t.pointer.y:t.pointer.x,s=Math.max(0,Math.min(1,(i-n.rampStart)/o)),a=n.loValue+s*(n.hiValue-n.loValue);return Rb(t,r,a)}})}const D4={linear:(e,t,n)=>{const r=t.scales&&t.scales[e.axis];if(!r||!r.invertible)return;const o=e.axis==="x"?t.pointer.x:t.pointer.y,i=Number(r.invertValue(o));if(Number.isFinite(i))return Math.max(n.lo,Math.min(n.hi,i))},angular:(e,t,n)=>{const{cx:r,cy:o,spanStart:i,spanEnd:s,pad:a}=e,l=s-i-a*n.n;if(!Number.isFinite(l)||l===0||!(n.total>0))return;const u=Math.sign(l)||1,c=i+a/2+n.local*a+l*(n.lo/n.total),f=((Bf(t.pointer,{cx:r,cy:o})-c)*u%360+360)%360,p=Math.abs(l)*((n.hi-n.lo)/n.total);return p<1e-9?n.lo:f<=p?n.lo+f/Math.abs(l)*n.total:f-p<360-f?n.hi:n.lo}};function Pb(e,t,n){const r=e&&D4[e.kind];return r?r(e,t,n):void 0}function kd(e,t){const n=e&&e.stack;if(!n||!Array.isArray(n.members)||n.local==null||!n.field||!Array.isArray(t.data)||!t.data.length)return null;const{mags:r,total:o,bounds:i}=tc(n.members,t.data,n.field);return{st:n,members:n.members,local:n.local,field:n.field,mags:r,total:o,bounds:i}}function j4(e,t){const n=e.markChannels||{},r=t||n.fill&&n.fill.field||n.stroke&&n.stroke.field||null;if(!r)return{field:null,domain:[],open:!0};const o=e.schema&&e.schema[r],i=o&&Array.isArray(o.domain)?o.domain:null;if(i)return{field:r,domain:i,open:!!o.open};for(const s of["fill","stroke"]){const a=n[s];if(!a||a.field!==r)continue;const l=e.scales[s],u=l&&Array.isArray(l.domainConfig)?l.domainConfig:null;if(u)return{field:r,domain:u,open:!0}}return{field:r,domain:[],open:!0}}function W4(e={}){const{defaults:t={},label:n,categoryField:r,when:o,...i}=e;return je({type:"stack.cut",gesture:"click",pick:"direct",scope:"stack",target:"domain",...i,when:Vr(s=>!!(s.node&&s.node.stack&&!s.node.edge),o),apply:s=>{const a=s.node,l=kd(a,s);if(!l)return;const{members:u,local:c,field:d,mags:f,total:p,bounds:h}=l,[y,g]=h[c];if(!(g>y))return;const m=Pb(l.st.geometry,s,{lo:y,hi:g,local:c,n:u.length,total:p});if(m===void 0)return;const b=u[c],w=s.data[b],x=j4(s,r),S=u.map(N=>s.data[N]),v=Yf(S,x.field,x.domain,{open:x.open,label:n});if(x.field&&v===void 0){ge(`stack:domainfull:${x.field}`,`edit.stack.cut() has no category left to give a new segment: this stack already uses every value in schema.${x.field}'s domain (${JSON.stringify(x.domain)}). A declared domain is the whole vocabulary, so the cut is refused. Declare more categories, or set schema.${x.field}.open = true to let a cut add one.`);return}const k={};for(const N of["x","y"]){const I=s.markChannels[N]&&s.markChannels[N].field;I&&(k[I]=w[I])}const _={...Es(s.schema),...k,...x.field?{[x.field]:v}:{},[d]:g-m,...t},T=s.data.slice();T[b]={...w,[d]:m-y},T.splice(b+1,0,_);const L={};return x.field&&x.open&&!x.domain.includes(v)&&(L[x.field]=[...x.domain,v]),{domains:L,data:T}}})}function q4(e={}){const{when:t,...n}=e;return je({type:"stack.edge",inverts:!0,gesture:"drag",pick:"direct",scope:"stack",...n,when:Vr(r=>!!(r.node&&r.node.edge&&r.node.stack),t),apply:r=>{const o=kd(r.node,r);if(!o)return;const{members:i,local:s,field:a,mags:l,total:u,bounds:c}=o,d=s+1;if(d>=i.length)return;const f=l[s]+l[d];if(!(f>0))return;const p=c[s][0],h=c[d][1],y=Pb(o.st.geometry,r,{lo:p,hi:h,local:s,n:i.length,total:u});if(y===void 0)return;const g=y-p,m=f-g,b=i[s],w=i[d];return r.data.map((x,S)=>S===b?{...x,[a]:g}:S===w?{...x,[a]:m}:x)}})}function B4(e={}){const{when:t,...n}=e;return je({type:"stack.merge",gesture:"dblclick",pick:"direct",scope:"stack",cardinality:"delete",...n,when:Vr(r=>!!(r.node&&r.node.edge&&r.node.stack),t),apply:r=>{const o=kd(r.node,r);if(!o)return;const{members:i,local:s,field:a,mags:l}=o,u=s+1;if(u>=i.length)return;const c=i[s],d=i[u],f=l[s]+l[u];return r.data.map((p,h)=>h===c?{...p,[a]:f}:p).filter((p,h)=>h!==d)}})}const H4=1;function U4(e,t){const n=e.markChannels&&e.markChannels[t];return n&&n.field!=null?n.field:null}function hy(e,t,n){const r=e.markChannels&&e.markChannels[t];if(!r)return n;if(r.field!=null){const i=e.datum?Number(e.datum[r.field]):NaN;return Number.isFinite(i)?i:n}const o=Number(r.datum!==void 0?r.datum:r.value);return Number.isFinite(o)?o:n}function K4(e,t){const n=e.scales.x,r=e.scales.y;if(!r||!r.invertible)return null;const o=e.node?{anchor:e.node.anchor,probe:e.node.probe}:{},{anchor:i,probe:s}=ic(e.scales,{anchor:t.anchor!=null?t.anchor:o.anchor,probe:t.probe!=null?t.probe:o.probe}),a=hy(e,"intercept",0),l=hy(e,"slope",0),u=e.node&&e.node.grip==="probe";let c=s;return u||(c=n&&n.invertible?Number(n.invertValue(e.pointer.x)):null),c!=null&&!Number.isFinite(c)&&(c=null),c!=null&&((n&&n.encode?Math.abs(Number(n.encode(c))-Number(n.encode(i))):c===i?0:1/0)>=H4||(c=null)),{a,b:l,anchor:i,probeX:c,yv:Number(r.invertValue(e.pointer.y)),yAnchor:Cr({a,b:l},i)}}function Y4(e,t){const n={};let r=!1;for(const[o,i]of Object.entries(t)){const s=U4(e,o);s==null||!Number.isFinite(i)||(n[s]=i,r=!0)}if(r){if(e.datum)return{...e.datum,...n};if(e.data.length)return e.data.map(o=>({...o,...n}))}}function sc(e,t,n,r){const{anchor:o,probe:i,...s}=r||{};return cl(je({type:e,gesture:"drag",pick:"direct",scope:"trend",channels:[t],...s,apply:a=>{const l=K4(a,{anchor:o,probe:i});if(!l)return;const u=n(l,a);return u?Y4(a,u):void 0}}),t)}function G4(e={}){return sc("trend.intercept","intercept",t=>({intercept:t.yv-t.b*t.anchor}),e)}function V4(e={}){return sc("trend.slope","slope",t=>{if(t.probeX==null)return;const n=(t.yv-t.yAnchor)/(t.probeX-t.anchor);return{slope:n,intercept:t.yAnchor-n*t.anchor}},e)}function X4(e={}){return sc("trend.interceptSpread","interceptSpread",t=>({interceptSpread:Math.abs(t.yv-t.yAnchor)}),e)}function J4(e={}){return sc("trend.slopeSpread","slopeSpread",t=>{if(t.probeX==null)return;const n=(t.yv-t.yAnchor)/(t.probeX-t.anchor);return{slopeSpread:Math.abs(n-t.b)}},e)}function Z4(e,t){const n=t.axis==="y"?e.y:e.x,r=t.axis==="y"?e.x:e.y,o=t.sign*(n-t.baseline);if(o<=0)return 0;const i=Math.floor(o/t.cellSize);if(i>=t.rows)return t.totalCells;let s=Math.floor((r-(t.bandStart+t.bandInset))/t.cellSize);s=Math.max(0,Math.min(t.multiple-1,s));const a=i*t.multiple+s+1;return Math.max(0,Math.min(t.totalCells,a))}function Q4(e={}){return je({type:"waffle.fill",gesture:"drag",scope:"waffle",...e,apply:t=>{const n=t.node&&t.node.grid,r=t.channels&&t.channels[0];if(!n||!r||!r.field)return;const o=Z4(t.pointer,n),i=Math.max(n.dlo,Math.min(n.dhi,n.dlo+o*n.unit));return{...t.datum,[r.field]:i}}})}const Sd=28,py=12,e8=8;function gl(e){const t=e.schemaSpec;if(!t)return null;const n=t.byRole.nodes||t.primary,r=t.tables[n];return!r||!r.key?null:{name:n,table:r,rows:(e.tables||{})[n]||[],key:r.key}}function ml(e,t){const n=e.schemaSpec,r=n&&(n.byRole.links||e.table),o=n&&n.tables[r];if(!o)return null;const i=Object.keys(o.fields).filter(u=>o.fields[u]&&o.fields[u].type==="ref"),s=u=>t[u]&&t[u].field!=null?t[u].field:null,a=s("source")||i[0],l=s("target")||i[1];return!a||!l?null:{source:a,target:l,sourceSide:s("sourceSide"),targetSide:s("targetSide")}}function $d(e){ge(`${e}:refs`,`edit.network.${e}() cannot find the link table's endpoint columns. Declare them as references (source: { type: "ref" }, target: { type: "ref" }), or name them on the link mark: channels: { source: { field: … }, target: { field: … } }.`)}function zb(e,t){const n=e.nodeBox||null,r=e.nodePorts||null,o=Tb(e.scales,{},t.table,t.rows,n,py*2,py*2,e.width||0,e.height||0),i=t.rows.map((s,a)=>!r||!s?null:r(s,a,t.rows)||{});return{boxed:!!n,ported:!!r,boxes:o,roles:i}}function Bi(e,t){return e?Et.filter(n=>j0(e[n],t)):null}function Ju(e,t,n,r,o=null){const i=zb(e,t),s=e.pointer,a=d=>d===r||!!o&&d===o.index&&!o.body;let l=null,u=1/0;if(i.ported){const d=Jf.size+wn;if(i.boxes.forEach((f,p)=>{if(!(!f||p===r))for(const h of Bi(i.roles[p],n)||[]){if(o&&p===o.index&&h===o.side)continue;const y=Go(f,h,0,0),g=Math.hypot(y.x-s.x,y.y-s.y);g<=d&&g<u&&(u=g,l={row:t.rows[p],index:p,side:h})}}),l)return l}if(i.boxed&&(i.boxes.forEach((d,f)=>{if(!d||a(f))return;const p=Bi(i.roles[f],n);if(p&&!p.length||Math.abs(s.x-d.cx)>d.hw||Math.abs(s.y-d.cy)>d.hh)return;const h=Math.hypot(d.cx-s.x,d.cy-s.y);h<u&&(u=h,l={row:t.rows[f],index:f,side:null})}),l))return l;const c=Zn(e.edit,Sd);return i.boxes.forEach((d,f)=>{if(!d||a(f))return;const p=Bi(i.roles[f],n);if(p&&!p.length)return;const h=Math.hypot(d.cx-s.x,d.cy-s.y);h<=c&&h<u&&(u=h,l={row:t.rows[f],index:f,side:null})}),l}function Db(e,t){const n=gl(e);if(!n)return null;const r=zb(e,n);if(!r.ported)return null;const o=[];return r.boxes.forEach((i,s)=>{if(i)for(const a of Bi(r.roles[s],t)||[]){const l=Go(i,a,0,0);o.push({x:l.x,y:l.y,key:ed(n.name,s,a)})}}),o}function jb(e,t,n,r,o){const i=e.schemaSpec;if(sl(i).multi)return!1;const s=Ms(i)===!1;return e.data.some((a,l)=>!a||l===o?!1:a[t.source]===n&&a[t.target]===r?!0:s&&a[t.source]===r&&a[t.target]===n)}function t8(e={}){const{defaults:t={},threshold:n,...r}=e;return je({type:"network.connect",gesture:"drag",pick:"direct",table:"links",cardinality:"append",threshold:n??Sd,...r,targets:o=>Db(o,"target"),apply:o=>{const i=gl(o),s=o.session;if(!i||!s||s.fromIndex==null)return;const a=ml(o,o.targetChannels||{});if(!a){$d("connect");return}const l=i.rows[s.fromIndex];if(!l)return;const u=l[i.key];if(u==null)return;const c=o.nodePorts;if(c){const w=c(l,s.fromIndex,i.rows)||{},x=Bi(w,"source")||[];if(s.fromSide!=null?!x.includes(s.fromSide):!x.length)return}const d=w=>({...a.sourceSide?{[a.sourceSide]:s.fromSide!=null?s.fromSide:null}:{},...a.targetSide?{[a.targetSide]:w}:{}}),f=()=>{if(!o.preview)return;const w=Fn(o,{defaults:t,seed:{[a.source]:u,[a.target]:null,...d(null)}});return w?[...o.data,w]:void 0},p=sl(o.schemaSpec).selfLoops,h=s.fromPoint,y=!h||Math.hypot(o.pointer.x-h.x,o.pointer.y-h.y)>=e8,g=p?Ju(o,i,"target",null,{index:s.fromIndex,side:s.fromSide,body:y}):Ju(o,i,"target",s.fromIndex);if(!g)return f();const m=g.row[i.key];if(m==null||jb(o,a,u,m,null))return f();const b=Fn(o,{defaults:t,seed:{[a.source]:u,[a.target]:m,...d(g.side)}});return b?[...o.data,b]:void 0}})}function n8(e={}){const{threshold:t,when:n,channel:r,channels:o,...i}=e,s=r?[r]:Array.isArray(o)?o:["source","target"],a=l=>{const u=l.node&&l.node.channel;return u==="source"||u==="target"?u:null};return je({type:"network.rewire",gesture:"drag",pick:"direct",scope:"network",threshold:t??Sd,...i,channels:s,when:l=>{const u=a(l);return!u||!s.includes(u)?!1:n?!!n(l):!0},targets:l=>{const u=a(l),c=gl(l),d=u?Db(l,u):null;if(!d||!c||!l.datum||sl(l.schemaSpec).selfLoops)return d;const f=ml(l,l.markChannels||{}),p=f&&l.datum[u==="source"?f.target:f.source],h=c.rows.findIndex(y=>y&&y[c.key]===p);return d.filter(y=>!y.key.startsWith(ed(c.name,h,"")))},apply:l=>{const u=gl(l),c=a(l);if(!u||!c||l.index==null||!l.datum)return;const d=ml(l,l.markChannels||{});if(!d){$d("rewire");return}const f=c==="source"?d.source:d.target,p=c==="source"?d.sourceSide:d.targetSide,h=l.datum[c==="source"?d.target:d.source],y=u.rows.findIndex(S=>S&&S[u.key]===h),g=sl(l.schemaSpec).selfLoops,m=Ju(l,u,c,!g&&y>=0?y:null);if(!m||m.row[u.key]==null)return l.preview?{...l.datum,[f]:null}:l.data.filter((S,v)=>v!==l.index);const b=m.row[u.key],w=!p||l.datum[p]===m.side;if(l.datum[f]===b&&w)return;const x=c==="source"?[b,h]:[h,b];if(!(l.datum[f]!==b&&jb(l,d,x[0],x[1],l.index)))return{...l.datum,[f]:b,...p?{[p]:m.side}:{}}}})}function r8(e={}){return je({type:"network.reverse",gesture:"click",pick:"direct",scope:"network",...e,apply:t=>{if(!t.datum)return;const n=ml(t,t.markChannels||{});if(!n){$d("reverse");return}if(Ms(t.schemaSpec)===!1){ge("reverse:undirected","edit.network.reverse() is on a links table declared directed: false, where source and target name the same relationship either way round — so swapping them has no visible effect. Declare directed: true, or drop the edit.");return}return{...t.datum,[n.source]:t.datum[n.target],[n.target]:t.datum[n.source]}}})}function si(e){return e.projection||e.scales&&e.scales.projection||null}function Wb(e){const t=e.lon&&e.lon.field||"lon",n=e.lat&&e.lat.field||"lat";return{lon:t,lat:n}}function o8(e={}){const{...t}=e;return je({type:"geo.move",gesture:"drag",channels:null,pick:"direct",scope:"geo",...t,apply:n=>{if(!n.datum)return;const r=Fr(si(n),n.pointer);if(!r)return;const o=Wb(n.markChannels||{});return{...n.datum,[o.lon]:r.lon,[o.lat]:r.lat}}})}function i8(e={}){const{defaults:t={},...n}=e;return je({type:"geo.create",gesture:"click",channels:null,pick:"plane",scope:"geo",cardinality:"append",...n,apply:r=>{const o=Fr(si(r),r.pointer);if(!o)return;const i=Wb(r.markChannels||{}),s=Fn(r,{defaults:t,seed:{[i.lon]:o.lon,[i.lat]:o.lat}});return s?[...r.data,s]:void 0}})}function s8(e={}){const{...t}=e;return je({type:"geo.dragVertex",gesture:"drag",channels:null,pick:"direct",scope:"geo",when:n=>!!(n.node&&n.node.channel==="vertex"),...t,apply:n=>{if(!n.datum||!n.node)return;const r=n.node.vertexIndex;if(r==null)return;const o=Fr(si(n),n.pointer);if(!o)return;const i=n.markChannels.coordinates&&n.markChannels.coordinates.field||"coordinates",s=n.datum[i];if(!Array.isArray(s)||!s[r])return;const a=s.map((l,u)=>u===r?[o.lon,o.lat]:l.slice());return{...n.datum,[i]:a}}})}function a8(e={}){const{min:t=2,...n}=e;return je({type:"geo.removeVertex",gesture:"click",channels:null,pick:"direct",scope:"geo",when:r=>!!(r.node&&r.node.channel==="vertex"),...n,apply:r=>{if(!r.datum||!r.node)return;const o=r.node.vertexIndex;if(o==null)return;const i=r.markChannels.coordinates&&r.markChannels.coordinates.field||"coordinates",s=r.datum[i];if(!Array.isArray(s)||!s[o]||s.length<=t)return;const a=s.filter((l,u)=>u!==o).map(l=>l.slice());return{...r.datum,[i]:a}}})}function l8(e={}){const{threshold:t=24,minDist:n=8,defaults:r={},into:o="new",...i}=e;return je({type:"geo.draw",gesture:"drag",cardinality:"appendMany",channels:null,pick:"draw",scope:"geo",threshold:t,into:o,...i,apply:s=>{const a=s.session;if(!a)return;const l=Fr(si(s),s.pointer);if(!l)return;const u=s.markChannels.coordinates&&s.markChannels.coordinates.field||"coordinates",c=s.pointer.x,d=s.pointer.y;if(a.lastX!=null&&a.lastY!=null&&Math.hypot(c-a.lastX,d-a.lastY)<n)return;if(a.drawIndex!=null&&s.data[a.drawIndex]){const h=a.drawIndex,y=s.data[h],g=Array.isArray(y[u])?y[u].slice():[];return g.push([l.lon,l.lat]),a.lastX=c,a.lastY=d,s.data.map((m,b)=>b===h?{...m,[u]:g}:m)}const f=Fn(s,{defaults:r,seed:{[u]:[[l.lon,l.lat]]}});if(!f)return;const p=[...s.data,f];return a.drawIndex=p.length-1,a.lastX=c,a.lastY=d,p}})}function qb(e){return{west:e.west&&e.west.field||"west",south:e.south&&e.south.field||"south",east:e.east&&e.east.field||"east",north:e.north&&e.north.field||"north"}}function c8(e={}){const{move:t=!0,...n}=Kl(e,"geo.brush","geoBrush");return je({type:"geo.brush",gesture:"drag",channels:null,scope:"geo",...n,move:t,pick:"geoBrush",apply:r=>{const o=r.session,i=o&&o.zone,s=r.datum;if(!i||!s)return;const a=qb(r.markChannels||{});if(i==="canonicalize"){const p={...s};let h=!1;for(const[y,g]of[[a.west,a.east],[a.south,a.north]])s[y]==null||s[g]==null||s[y]<=s[g]||(p[y]=s[g],p[g]=s[y],h=!0);return h?p:void 0}const l=Fr(si(r),r.pointer);if(!l)return;let u=s[a.west],c=s[a.south],d=s[a.east],f=s[a.north];if(i==="body"){if(!t||!o.grab||!o.box0)return;const p=l.lon-o.grab.lon,h=l.lat-o.grab.lat;u=o.box0.west+p,d=o.box0.east+p,c=o.box0.south+h,f=o.box0.north+h}else for(const p of o.edges||[])p==="west"?u=l.lon:p==="east"?d=l.lon:p==="south"?c=l.lat:p==="north"&&(f=l.lat);return{...s,[a.west]:u,[a.south]:c,[a.east]:d,[a.north]:f}}})}function u8(e,t){const{x:n,y:r}=e.pointer;return(e.marks||[]).some(o=>o.type!=="rect"||o.index==null||o.x==null||o.y==null||o.width==null||o.height==null?!1:n>=o.x-t&&n<=o.x+o.width+t&&r>=o.y-t&&r<=o.y+o.height+t)}function f8(e={}){const{defaults:t={},width:n=10,height:r=6,edgeInset:o=8,...i}=e;return je({type:"geo.createRect",gesture:"click",channels:null,pick:"plane",scope:"geo",cardinality:"append",when:s=>!u8(s,o),...i,apply:s=>{const a=Fr(si(s),s.pointer);if(!a)return;const l=qb(s.markChannels||{}),u=n/2,c=r/2,d=Fn(s,{defaults:t,seed:{[l.west]:a.lon-u,[l.east]:a.lon+u,[l.south]:a.lat-c,[l.north]:a.lat+c}});return d?[...s.data,d]:void 0}})}const d8={anchor:E4,newSeries:A4,draw:T4,sweep:O4,removeSeries:C4},h8={categories:R4},p8={scale:L4},y8={category:P4,value:z4},g8={cut:W4,edge:q4,merge:B4},Zu={intercept:G4,slope:V4,interceptSpread:X4,slopeSpread:J4},m8={fill:Q4},b8={connect:t8,rewire:n8,reverse:r8},w8={move:o8,create:i8,draw:l8,dragVertex:s8,removeVertex:a8,brush:c8,createRect:f8},_d=Object.freeze(Object.defineProperty({__proto__:null,axis:p8,brushRect:q0,brushSpan:pE,create:nd,custom:G0,cycle:xE,editText:K0,geo:w8,legend:y8,line:d8,move:Xn,moveSpan:hE,network:b8,rank:Y0,remove:H0,resize:bE,rotate:wE,scale:h8,select:kE,set:vE,slide:mE,stack:g8,toggle:rd,trend:Zu,waffle:m8,when:M4},Symbol.toStringTag,{value:"Module"}));function Qt(e={}){const{min:t,max:n,field:r}=Rr("clamp",e);return Vt(({value:o,domain:i})=>{let s=t,a=n;s===void 0&&i&&(s=Math.min(...i)),a===void 0&&i&&(a=Math.max(...i));let l=o;return s!==void 0&&l!==void 0&&(l=Math.max(s,l)),a!==void 0&&l!==void 0&&(l=Math.min(a,l)),l},{type:"clamp",options:{min:t,max:n},field:r})}function Bb(e={}){const{total:t,field:n,strategy:r="cap"}=Rr("maintainSum",e);return typeof t!="number"?(ge("maintainSum:target","maintainSum() needs the total the rows must sum to — maintainSum({ total: 100 }). Without one the constraint accepts every edit unchanged."),Vt(()=>{},{type:"maintainSum",options:{total:t,strategy:r},field:n})):r==="normalize"?Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;const l=o.map((d,f)=>f===i&&s!==void 0?{...d,[a]:s}:{...d}),u=l.reduce((d,f)=>d+(Number(f[a])||0),0);if(u===0)return l;const c=t/u;return l.map(d=>({...d,[a]:(Number(d[a])||0)*c}))},{type:"maintainSum",options:{total:t,strategy:r},field:n}):r==="redistribute"?Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;if(i==null||s===void 0)return s;const l=Math.max(0,Math.min(t,Number(s)||0)),u=o.map((f,p)=>p===i?0:Number(f[a])||0).reduce((f,p)=>f+p,0),c=Math.max(0,t-l),d=u>0?c/u:0;return o.map((f,p)=>{if(p===i)return{...f,[a]:l};const h=Number(f[a])||0;return{...f,[a]:u>0?h*d:o.length>1?c/(o.length-1):0}})},{type:"maintainSum",options:{total:t,strategy:r},field:n}):Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;if(i==null||s===void 0)return s;const l=o.reduce((c,d,f)=>f===i?c:c+(d[a]||0),0),u=Math.max(0,t-l);return Math.min(s,u)},{type:"maintainSum",options:{total:t,strategy:"cap"},field:n})}function ac(e={}){const{max:t=1/0,strategy:n="replace"}=Rr("count",e);return Vt(({data:r})=>{if(!(r.length<=t))return n==="reject"?!1:r.slice(r.length-t)},{type:"count",options:{max:t,strategy:n}})}function Md(e={}){const{field:t,max:n=1,strategy:r="reject"}=Rr("unique",e);return Vt(({data:o,activeIndex:i,fields:s})=>{const a=d=>s.map(f=>d[f]).join(""),l=new Map;o.forEach((d,f)=>{const p=a(d);let h=l.get(p);h||(h=[],l.set(p,h)),h.push(f)});let u=!1;for(const d of l.values())if(d.length>n){u=!0;break}if(!u)return;if(r==="reject")return!1;const c=new Set;for(const d of l.values()){if(d.length<=n)continue;let f;if(i!=null&&d.includes(i)){const p=d.filter(h=>h!==i);f=new Set([i,...p.slice(p.length-(n-1))])}else f=new Set(d.slice(d.length-n));d.forEach(p=>{f.has(p)||c.add(p)})}return o.filter((d,f)=>!c.has(f))},{type:"unique",options:{field:t,max:n,strategy:r},field:t})}function Ed(e={}){const{step:t=1,origin:n=0,field:r}=Rr("snap",e);return Vt(({value:o})=>o===void 0||t<=0?o:n+Math.round((o-n)/t)*t,{type:"snap",options:{step:t,origin:n},field:r})}function x8(e){for(let t=1;t<e.length;t++)if(e[t]<e[t-1])return!1;return!0}function v8(e,t,n){if(!n)return-1;let r=-1;for(let o=0;o<e.length;o++)if(Number(n[e[o]])!==Number(t[e[o]])){if(r>=0)return-1;r=o}return r}function k8(e={}){const{field:t,strategy:n="push"}=Rr("ordering",e),r=Array.isArray(t)?t:t!=null?[t]:[];return r.length<2?(ge("ordering:fields","ordering() needs at least two columns, in order — ordering({ field: ['lo', 'mean', 'hi'] }). Without them the constraint accepts every edit unchanged."),Vt(()=>{},{type:"ordering",options:{strategy:n},field:r})):Vt(({active:o,oldData:i,activeIndex:s})=>{if(!o)return;const a=r.map(f=>Number(o[f]));if(a.some(f=>!Number.isFinite(f))||x8(a))return;if(n==="block")return!1;const l=i&&s!=null?i[s]:null,u=v8(r,o,l),c=a.slice();if(u>=0){for(let f=u-1;f>=0;f--)c[f]=Math.min(c[f],c[f+1]);for(let f=u+1;f<c.length;f++)c[f]=Math.max(c[f],c[f-1])}else for(let f=1;f<c.length;f++)c[f]=Math.max(c[f],c[f-1]);const d={...o};return r.forEach((f,p)=>{d[f]=c[p]}),d},{type:"ordering",options:{strategy:n},field:r})}function S8(e={}){const{field:t,along:n="x",dir:r="up",series:o=null}=Rr("monotonic",e),i=r!=="down";return Vt(({data:s,activeIndex:a,field:l})=>{if(!s||s.length<2||l==null)return;const u=new Map;s.forEach((f,p)=>{const h=o?f[o]:null;u.has(h)||u.set(h,[]),u.get(h).push(p)});const c=s.map(f=>({...f}));let d=!1;for(const f of u.values()){const p=f.filter(g=>Number.isFinite(Number(c[g][l]))).sort((g,m)=>yy(c[g][n])-yy(c[m][n]));if(p.length<2)continue;const h=p.indexOf(a),y=h>=0?h:0;for(let g=y+1;g<p.length;g++){const m=Number(c[p[g-1]][l]),b=Number(c[p[g]][l]),w=i?Math.max(b,m):Math.min(b,m);w!==b&&(c[p[g]][l]=w,d=!0)}for(let g=y-1;g>=0;g--){const m=Number(c[p[g+1]][l]),b=Number(c[p[g]][l]),w=i?Math.min(b,m):Math.max(b,m);w!==b&&(c[p[g]][l]=w,d=!0)}}return d?c:void 0},{type:"monotonic",options:{dir:r,along:n,series:o},field:t})}function yy(e){return e instanceof Date?e.getTime():Number(e)}function $8(e={}){const{field:t,min:n=1,series:r=null}=Rr("spacing",e);return Vt(({data:o,activeIndex:i,field:s})=>{if(!o||o.length<2||!(n>0)||s==null)return;const a=new Map;o.forEach((c,d)=>{const f=r?c[r]:null;a.has(f)||a.set(f,[]),a.get(f).push(d)});const l=o.map(c=>({...c}));let u=!1;for(const c of a.values()){const d=c.filter(h=>Number.isFinite(Number(l[h][s]))).sort((h,y)=>Number(l[h][s])-Number(l[y][s]));if(d.length<2)continue;const f=d.indexOf(i),p=f>=0?f:0;for(let h=p+1;h<d.length;h++){const y=Number(l[d[h-1]][s])+n;Number(l[d[h]][s])<y&&(l[d[h]][s]=y,u=!0)}for(let h=p-1;h>=0;h--){const y=Number(l[d[h+1]][s])-n;Number(l[d[h]][s])>y&&(l[d[h]][s]=y,u=!0)}}return u?l:void 0},{type:"spacing",options:{min:n,series:r},field:t})}const Hb=Object.freeze(Object.defineProperty({__proto__:null,clamp:Qt,count:ac,custom:Vt,maintainSum:Bb,monotonic:S8,ordering:k8,snap:Ed,spacing:$8,unique:Md},Symbol.toStringTag,{value:"Module"}));function _8(e,t){return typeof e=="function"?e(t):e}function Ad(e,t){const n={};for(const[r,o]of Object.entries(e))n[r]=_8(o,t);return n}const M8=k0,E8={channels:"a guide has no channel map — it views STATE, not columns. Its options take a literal or a function of the chart context: guides.rule({ y: ({ data }) => … }).",field:"a guide names no field: it draws a statement about the chart, not a column. Read the rows in a function option instead: ({ data }) => …",edit:"a guide is read-only by construction — it can never carry an edit. Put the edit on the MARK whose data the gesture should change.",edits:"a guide is read-only by construction. Put edits on a mark.",table:"a guide views chart STATE, so it has no table. It is handed the primary table's rows and may read any of them through the context.",data:"a guide never owns data. It is handed the rows: guides.rule({ y: ({ data }) => … }).",constraints:"invariants belong to the DATASET (spec.constraints), not to a guide. A guide can READ them: ({ constraints }) => …"};function lc(e,t,n){if(!t||!oi())return;const r=new Set([...M8,...n]);for(const o of Object.keys(t)){if(r.has(o))continue;const i=E8[o];if(i){ge(`guideopt:${e}:${o}`,`guides.${e}({ ${o}: … }): ${i}`);continue}ge(`guideopt:${e}:${o}`,`guides.${e}({ ${o}: … }) is not an option this guide reads, so it is ignored. ${e} options are: ${[...r].sort().join(", ")}.`)}}const A8=Ts.rule;function T8(e={}){return lc("rule",e,A8),{views:"state",type:"rule",build:(t,n,r,o,i)=>{const{scales:s,width:a,height:l}=i,u=i.theme&&i.theme.guide&&i.theme.guide.rule||{},{x:c,y:d,label:f,stroke:p=u.stroke,strokeDasharray:h=u.strokeDasharray,strokeWidth:y=u.strokeWidth,opacity:g=u.opacity}=Ad(e,i),m=i.theme&&i.theme.font&&i.theme.font.labelSize||10,b=[];if(d!==void 0&&s.y){const w=s.y.encode(d);b.push({type:"line",x1:0,x2:a,y1:w,y2:w,stroke:p,strokeDasharray:h,strokeWidth:y,opacity:g,pointerEvents:"none",guide:!0}),f&&b.push({type:"text",x:a-4,y:w-4,text:f,fill:p,fontSize:m,textAnchor:"end",pointerEvents:"none",guide:!0})}if(c!==void 0&&s.x){const w=s.x.encode(c);b.push({type:"line",x1:w,x2:w,y1:0,y2:l,stroke:p,strokeDasharray:h,strokeWidth:y,opacity:g,pointerEvents:"none",guide:!0}),f&&b.push({type:"text",x:w+4,y:10,text:f,fill:p,fontSize:m,textAnchor:"start",pointerEvents:"none",guide:!0})}return b}}}const O8=Ts.region;function C8(e={}){return lc("region",e,O8),{views:"state",type:"region",build:(t,n,r,o,i)=>{const{scales:s,width:a,height:l}=i,u=i.theme&&i.theme.guide&&i.theme.guide.region||{},{x:c,y:d,fill:f=u.fill||"#64748b",opacity:p=u.opacity!=null?u.opacity:.1}=Ad(e,i),h=[];if(Array.isArray(d)&&s.y){const y=s.y.encode(d[0]),g=s.y.encode(d[1]);h.push({type:"rect",x:0,y:Math.min(y,g),width:a,height:Math.abs(g-y),fill:f,opacity:p,pointerEvents:"none",guide:!0})}if(Array.isArray(c)&&s.x){const y=s.x.encode(c[0]),g=s.x.encode(c[1]);h.push({type:"rect",x:Math.min(y,g),y:0,width:Math.abs(g-y),height:l,fill:f,opacity:p,pointerEvents:"none",guide:!0})}return h}}}const N8=Ts.remaining;function I8(e,t){for(const n of e||[]){const r=n;if(!r||r.type!=="maintainSum"||r.field!=null&&t!=null&&r.field!==t)continue;const o=r.options&&r.options.total;if(typeof o=="number")return o}return null}function L8(e={}){return lc("remaining",e,N8),{views:"state",type:"remaining",build:(t,n,r,o,i)=>{const s=i&&i.theme&&i.theme.guide&&i.theme.guide.rule||{},{field:a="y",total:l,unit:u,format:c,anchor:d="top-right",label:f,fill:p=s.stroke||"#64748b",fontSize:h=11}=Ad(e,i),y=t||[],g=typeof l=="number"?l:I8(i&&i.constraints||[],a);if(g==null)return[];const m=y.reduce((k,_)=>{const T=_&&_[a];return k+(typeof T=="number"&&Number.isFinite(T)?T:0)},0),b=g-m,w=typeof c=="function"?c:k=>{const _=Math.round(k*100)/100;return String(_)};let x;if(typeof f=="function")x=String(f(b,m,g));else if(u){const k=Math.round(b);x=`${w(b)} ${u}${k===1?"":"s"} left`}else x=`${w(b)} of ${w(g)} left`;const S=d.endsWith("right"),v=d.startsWith("top");return[{type:"text",x:S?r-4:4,y:v?12:o-6,text:x,fill:p,fontSize:h,textAnchor:S?"end":"start",pointerEvents:"none",guide:!0}]}}}const F8=Ts.proximity;function R8(e){lc("proximity",e,F8);const{target:t,stroke:n,strokeDasharray:r,strokeWidth:o,opacity:i}=e;return{views:"state",type:"proximity",build:(s,a,l,u,c)=>{const d=c.ui&&c.ui.session&&c.ui.session[t];if(!d||d.px==null||d.py==null||d.threshold==null)return[];const f={..._5,...n!==void 0?{color:n}:{},...r!==void 0?{dash:r}:{},...o!==void 0?{width:o}:{},...i!==void 0?{opacity:i}:{}};return[{type:"circle",cx:d.px,cy:d.py,r:d.threshold,fill:"none",stroke:f.color,strokeDasharray:f.dash,strokeWidth:f.width,opacity:f.opacity,guide:!0,effect:!0,pointerEvents:"none"}]}}}function ai(e){return{views:"state",type:"custom",build:(t,n,r,o,i)=>(e(i)||[]).map(s=>({pointerEvents:"none",...s,guide:!0}))}}const Ls=(e,t)=>Object.assign(t,{type:e}),Ub={accent:"#2563eb",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#334155",question:"#0f172a",labelSize:12,questionSize:13,radius:11},Fs=e=>e&&e.theme&&e.theme.widget||Ub,Qu=e=>e&&Array.isArray(e.domainConfig)?e.domainConfig:[];function Td(e={}){const{labelOffset:t=30,radius:n}=e;return Ls("optionRings",ai(r=>{const{scales:o,height:i}=r,s=Fs(r),a=n??s.radius,l=Qu(o.x);if(!l.length)return[];const u=i/2,c=f=>o.x.encode(f),d=[];for(let f=0;f<l.length-1;f++)d.push({type:"line",x1:c(l[f])+a,y1:u,x2:c(l[f+1])-a,y2:u,stroke:s.track,strokeWidth:3,background:!0});for(const f of l)d.push({type:"circle",cx:c(f),cy:u,r:a,fill:"none",stroke:s.ring,strokeWidth:1.5}),d.push({type:"text",x:c(f),y:u+t,text:String(f),textAnchor:"middle",fontSize:s.labelSize,fill:s.label});return d}))}function Kb(e={}){const{pad:t=3}=e;return Ls("cellGrid",ai(n=>{const{scales:r}=n,o=Fs(n),i=Qu(r.x),s=Qu(r.y);if(!i.length||!s.length)return[];const a=yn(r.x,40),l=yn(r.y,30),u=[];for(const c of s)for(const d of i)u.push({type:"rect",x:r.x.encode(d)-a/2+t,y:r.y.encode(c)-l/2+t,width:a-2*t,height:l-2*t,fill:o.cellFill,stroke:o.cellStroke,strokeWidth:1});for(const c of i)u.push({type:"text",x:r.x.encode(c),y:-14,text:String(c),textAnchor:"middle",fontSize:o.labelSize,fill:o.label});for(const c of s)u.push({type:"text",x:-10,y:r.y.encode(c)+4,text:String(c),textAnchor:"end",fontSize:o.labelSize,fill:o.label});return u}))}function Yb(e={}){const{format:t=n=>String(n)}=e;return Ls("sliderTrack",ai(n=>{const{scales:r,width:o,height:i}=n,s=Fs(n);if(!r.x)return[];const a=i/2,l=r.x.domainConfig||[0,1],u=l[0],c=l[l.length-1];return[{type:"line",x1:0,y1:a,x2:o,y2:a,stroke:s.track,strokeWidth:4,background:!0},{type:"line",x1:0,y1:a-7,x2:0,y2:a+7,stroke:s.ring,strokeWidth:2},{type:"line",x1:o,y1:a-7,x2:o,y2:a+7,stroke:s.ring,strokeWidth:2},{type:"text",x:0,y:a+26,text:t(u),textAnchor:"start",fontSize:s.labelSize,fill:s.label},{type:"text",x:o,y:a+26,text:t(c),textAnchor:"end",fontSize:s.labelSize,fill:s.label}]}))}function nn(e,t={}){const{y:n=-18}=t;return Ls("prompt",ai(r=>{const o=Fs(r);return e?[{type:"text",x:0,y:n,text:e,textAnchor:"start",fontSize:o.questionSize,fill:o.question}]:[]}))}function Gb(e={}){const{x:t="x",y:n="y"}=e;return Ls("crosshair",ai(r=>{const{width:o,height:i}=r,s=Fs(r),a=o/2,l=i/2,u=(f,p,h,y)=>({type:"text",x:f,y:p,text:h,textAnchor:y,fontSize:s.labelSize,fill:s.label}),c=14,d=(f,p,h)=>{const y=[...String(t).split(/\s+/),`(${p})`],g=l-(y.length-1)*c/2;return y.map((m,b)=>u(f,g+b*c+4,m,h))};return[{type:"line",x1:0,y1:l,x2:o,y2:l,stroke:s.ring,strokeWidth:1,background:!0},{type:"line",x1:a,y1:0,x2:a,y2:i,stroke:s.ring,strokeWidth:1,background:!0},...d(o+10,"high","start"),...d(-10,"low","end"),u(a,-8,`${n} (high)`,"middle"),u(a,i+20,`${n} (low)`,"middle")]}))}const P8=Object.freeze(Object.defineProperty({__proto__:null,cellGrid:Kb,crosshair:Gb,custom:ai,optionRings:Td,prompt:nn,proximity:R8,region:C8,remaining:L8,rule:T8,sliderTrack:Yb},Symbol.toStringTag,{value:"Module"}));function mn(e){return Xf(e)}function z8(e={}){const{question:t,options:n=[],value:r,onChange:o,width:i=560,height:s=130,stage:a,theme:l}=e,u=mn(l);return{width:i,height:s,theme:l,margins:{top:34,right:60,bottom:44,left:60},schema:{choice:{type:"ordinal",domain:n}},scales:{x:{type:"band"}},data:r!=null?[{choice:r}]:[],constraints:[ac({max:1,strategy:"replace"})],onChange:o,axes:!1,guides:[nn(t||""),Td()],marks:[Sr({id:"likert",size:u.widget.radius-3,fill:u.widget.accent,channels:{x:{field:"choice"}},edits:[nd({pick:"probe",channels:["x"],advance:!1,stage:a})]})]}}function D8(e={}){const{question:t,options:n=[],max:r=1/0,value:o=[],onChange:i,width:s=560,height:a=130,stage:l,theme:u}=e,c=mn(u),d=[Md({field:"choice",strategy:"reject"})];return r!==1/0&&d.push(ac({max:r,strategy:"reject"})),{width:s,height:a,theme:u,margins:{top:34,right:60,bottom:44,left:60},schema:{choice:{type:"categorical",domain:n}},scales:{x:{type:"band"}},data:o.map(f=>({choice:f})),constraints:d,onChange:i,axes:!1,guides:[nn(t||""),Td()],marks:[Sr({id:"choice",size:c.widget.radius-3,fill:c.widget.accent,channels:{x:{field:"choice"}},edits:[rd({pick:"probe",channels:["x"],advance:!1,stage:l})]})]}}function j8(e={}){const{question:t,domain:n=[0,1],step:r,value:o,format:i,onChange:s,width:a=560,height:l=120,stage:u,theme:c}=e,d=mn(c),f=[Qt({min:n[0],max:n[1],field:"value"})];return r&&f.push(Ed({field:"value",step:r,origin:n[0]})),{width:a,height:l,theme:c,margins:{top:34,right:40,bottom:40,left:40},schema:{value:{type:"quantitative",domain:n}},data:[{value:o??n[0]}],constraints:f,onChange:s,axes:!1,guides:[nn(t||""),Yb(i?{format:i}:{})],marks:[Sr({id:"slider",size:d.widget.radius-2,fill:d.widget.accent,channels:{x:{field:"value"}},edits:[Xn({pick:"probe",channels:["x"],advance:!1,stage:u})]})]}}function W8(e={}){const{question:t,questions:n=[],options:r=[],value:o=[],onChange:i,width:s=620,height:a=100+n.length*46,stage:l,theme:u}=e,c=mn(u),d={top:62,right:30,bottom:20,left:130},f=a-d.top-d.bottom;return{width:s,height:a,theme:u,margins:d,schema:{option:{type:"ordinal",domain:r},question:{type:"categorical",domain:n}},scales:{x:{type:"band"},y:{type:"band",range:[0,f]}},data:o,constraints:[Md({field:"question",strategy:"replace"})],onChange:i,axes:!1,guides:[nn(t||"",{y:-38}),Kb()],marks:[Sr({id:"matrix",size:c.widget.radius-3,fill:c.widget.accent,channels:{x:{field:"option"},y:{field:"question"}},edits:[rd({pick:"probe",channels:["x","y"],advance:!1,stage:l})]})]}}const q8={top:56,right:92,bottom:52,left:92};function B8(e,t){const n={...q8},r=e-n.left-n.right,o=t-n.top-n.bottom;if(r>o){const i=(r-o)/2;n.left+=i,n.right+=i}else if(o>r){const i=(o-r)/2;n.top+=i,n.bottom+=i}return n}function H8(e={}){const{question:t,x:n="x",y:r="y",r:o=0,spread:i=0,samples:s=60,seed:a=7,render:l="samples",onChange:u,width:c=460,height:d=400,theme:f}=e;return{width:c,height:d,theme:f,margins:B8(c,d),schema:{x:{type:"quantitative",domain:[-1,1]},y:{type:"quantitative",domain:[-1,1]},r:{type:"quantitative",domain:[-1,1],default:0},spread:{type:"quantitative",domain:[0,1],default:0}},data:[{r:o,spread:i}],constraints:[Qt({field:"r",min:-1,max:1}),Qt({field:"spread",min:0,max:1})],onChange:u,axes:!1,guides:[nn(t||"",{y:-32}),Gb({x:n,y:r})],marks:[ii({id:"lineCone",parts:[_b({render:l,samples:s,seed:a,channels:{intercept:{datum:0},slope:{field:"r"},slopeSpread:{field:"spread"}}}),$b({handles:!1,channels:{intercept:{datum:0},slope:{field:"r",edit:Zu.slope({pick:"probe",stage:0})},slopeSpread:{field:"spread",edit:Zu.slopeSpread({pick:"probe",stage:1})}}})]})]}}function U8(e={}){const{question:t="Rank these items",items:n=["A","B","C","D"],onChange:r,width:o=420,height:i=280,stage:s,theme:a}=e,l=mn(a),u=n.map((d,f)=>f+1),c=n.map((d,f)=>({item:d,rank:f+1}));return{width:o,height:i,theme:a,margins:{top:40,right:24,bottom:24,left:100},schema:{item:{type:"categorical",domain:n},rank:{type:"ordinal",domain:u}},data:c,onChange:r,axes:!1,guides:[nn(t)],marks:[Sr({id:"rank-dots",size:l.widget.radius-2,fill:l.widget.accent,channels:{x:{value:40},y:{field:"rank",edit:Y0({stage:s})}}}),Or({id:"rank-labels",fontSize:13,fill:l.widget.label,channels:{x:{value:56},y:{field:"rank"},text:{field:"item"},textAnchor:{value:"start"}}})]}}function K8(e={}){const{question:t="Allocate the budget",categories:n=["A","B","C","D"],total:r=100,values:o,onChange:i,width:s=480,height:a=280,stage:l,theme:u}=e,c=mn(u),d=r/n.length,f=n.map((p,h)=>({cat:p,share:o&&o[h]!=null?o[h]:d}));return{width:s,height:a,theme:u,margins:{top:40,right:24,bottom:36,left:48},schema:{cat:{type:"categorical",domain:n},share:{type:"quantitative",domain:[0,r]}},data:f,constraints:[Qt({min:0,max:r,field:"share"}),Bb({total:r,field:"share",strategy:"redistribute"})],onChange:i,guides:[nn(t)],marks:[nc({id:"alloc",fill:c.widget.accent,fillOpacity:.75,channels:{x:{field:"cat"},y:{field:"share",edit:Xn({guide:!0,stage:l})}}})]}}function Y8(e={}){const{question:t="Place tokens to express probability",bins:n=["Low","Med","High"],maxTokens:r=20,onChange:o,width:i=420,height:s=300,stage:a,theme:l}=e,u=mn(l);return{width:i,height:s,theme:l,margins:{top:40,right:24,bottom:36,left:40},schema:{bin:{type:"categorical",domain:n}},data:[],constraints:[ac({max:r,strategy:"reject"})],onChange:o,guides:[nn(t)],marks:[fb({id:"tokens",fill:u.widget.accent,channels:{x:{field:"bin"}},edits:[nd({pick:"probe",channels:["x"],defaults:{},advance:!1,stage:a}),H0({pick:"direct",stage:a})]})]}}function G8(){return Vt(({active:e})=>{if(e)return{lo:Math.min(e.lo,e.mean),hi:Math.max(e.hi,e.mean)}},{type:"orderInterval"})}function V8(e){return G0(t=>{const n=t.datum,r=t.channels[0];if(!r||!r.scale||!n)return;const o=r.scale.invertValue(t.pointer.y);if(o==null||Number.isNaN(Number(o)))return;const i=r.scale.domainConfig||(typeof r.scale.domain=="function"?r.scale.domain():null);if(!i||i.length<2){const p=o-n.mean;return{...n,mean:o,lo:n.lo+p,hi:n.hi+p}}const s=Math.min(...i.map(Number)),a=Math.max(...i.map(Number)),l=Number(n.hi)-Number(n.lo);let u=Number(o)-Number(n.mean),c=Number(n.lo)+u,d=Number(n.hi)+u;l>=a-s?(c=s,d=a):(c<s&&(d+=s-c,c=s),d>a&&(c-=d-a,d=a));const f=Number(n.mean)+(c-Number(n.lo));return{...n,mean:f,lo:c,hi:d}},{guide:!0,stage:e})}function X8(e={}){const{question:t="Set your interval",category:n="estimate",mean:r=50,lo:o=30,hi:i=70,domain:s=[0,100],onChange:a,width:l=360,height:u=280,stage:c,theme:d}=e,f=mn(d);return{width:l,height:u,theme:d,margins:{top:40,right:24,bottom:36,left:48},schema:{cat:{type:"categorical",domain:[n]},mean:{type:"quantitative",domain:s},lo:{type:"quantitative",domain:s},hi:{type:"quantitative",domain:s}},data:[{cat:n,mean:r,lo:o,hi:i}],constraints:[Qt({min:s[0],max:s[1],field:"mean"}),Qt({min:s[0],max:s[1],field:"lo"}),Qt({min:s[0],max:s[1],field:"hi"}),G8()],onChange:a,guides:[nn(t)],marks:[ii({id:"ci",parts:[cb({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y1:{field:"lo"},y2:{field:"hi"}}}),Sr({size:f.widget.radius-2,fill:f.widget.accent,channels:{x:{field:"cat"},y:{field:"mean",edit:V8(c)}}}),hs({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y:{field:"lo",edit:Xn({stage:c})}}}),hs({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y:{field:"hi",edit:Xn({stage:c})}}})]})]}}function J8(e={}){const{question:t="How often?",bins:n=["0-1","1-2","2-3","3-4","4+"],max:r=40,values:o,onChange:i,width:s=480,height:a=280,stage:l,theme:u}=e,c=mn(u),d=n.map((f,p)=>({bin:f,n:o&&o[p]!=null?o[p]:0}));return{width:s,height:a,theme:u,margins:{top:40,right:24,bottom:40,left:40},schema:{bin:{type:"categorical",domain:n},n:{type:"quantitative",domain:[0,r]}},data:d,constraints:[Qt({min:0,max:r,field:"n"})],onChange:i,guides:[nn(t)],marks:[nc({id:"hist",fill:c.widget.accent,fillOpacity:.7,channels:{x:{field:"bin"},y:{field:"n",edit:Xn({guide:!0,stage:l})}}})]}}function Z8(e={}){const{question:t="Drag the region",xDomain:n=[0,10],yDomain:r=[0,10],x1:o=3,x2:i=7,y1:s=3,y2:a=7,onChange:l,width:u=400,height:c=320,stage:d,theme:f}=e,p=mn(f);return{width:u,height:c,theme:f,margins:{top:40,right:24,bottom:36,left:40},schema:{x1:{type:"quantitative",domain:n},x2:{type:"quantitative",domain:n},y1:{type:"quantitative",domain:r},y2:{type:"quantitative",domain:r}},data:[{x1:o,x2:i,y1:s,y2:a}],constraints:[Qt({min:n[0],max:n[1],field:"x1"}),Qt({min:n[0],max:n[1],field:"x2"}),Qt({min:r[0],max:r[1],field:"y1"}),Qt({min:r[0],max:r[1],field:"y2"})],onChange:l,guides:[nn(t)],marks:[Is({id:"region",fill:p.widget.accent,fillOpacity:.35,stroke:p.widget.accent,channels:{x1:{field:"x1"},x2:{field:"x2"},y1:{field:"y1"},y2:{field:"y2"}},edits:[q0({edgeInset:12,stage:d})]})]}}function Q8(e={}){const{question:t="Set the value",domain:n=[0,100],step:r,value:o,onChange:i,width:s=200,height:a=320,stage:l,theme:u}=e,c=mn(u),d=[Qt({min:n[0],max:n[1],field:"value"})];return r&&d.push(Ed({field:"value",step:r,origin:n[0]})),{width:s,height:a,theme:u,margins:{top:40,right:40,bottom:36,left:48},schema:{cat:{type:"categorical",domain:["v"]},value:{type:"quantitative",domain:n}},data:[{cat:"v",value:o??n[0]}],constraints:d,onChange:i,guides:[nn(t)],marks:[nc({id:"thermo",fill:c.widget.accent,fillOpacity:.8,channels:{x:{field:"cat"},y:{field:"value"}},edits:[Xn({pick:"probe",channels:["y"],advance:!1,guide:!0,stage:l})]})]}}function e3(e={}){const{question:t="Set the value",input:n="number",value:r,domain:o=[0,100],label:i="value",onChange:s,width:a=360,height:l=200,stage:u,theme:c}=e,d=mn(c);return n==="text"?{width:a,height:l,theme:c,margins:{top:40,right:24,bottom:24,left:24},schema:{label:{type:"categorical"},x:{type:"quantitative",domain:[0,10]},y:{type:"quantitative",domain:[0,10]}},data:[{x:5,y:5,label:r!=null?String(r):i}],onChange:s,axes:!1,guides:[nn(t)],marks:[Or({id:"label",fontSize:18,fill:d.widget.accent,channels:{x:{field:"x"},y:{field:"y"},text:{field:"label",edit:K0()}},edits:[Xn({channels:["x","y"],stage:u})]})]}:{width:a,height:l,theme:c,margins:{top:40,right:40,bottom:36,left:48},schema:{cat:{type:"categorical",domain:["v"]},n:{type:"quantitative",domain:o}},data:[{cat:"v",n:r??o[0]}],constraints:[Qt({min:o[0],max:o[1],field:"n"})],onChange:s,guides:[nn(t)],marks:[Or({id:"readout",fontSize:22,fill:d.widget.accent,channels:{x:{field:"cat"},y:{field:"n",edit:Xn({guide:!0,stage:u})},text:{field:"n"}}})]}}const t3=Object.freeze(Object.defineProperty({__proto__:null,allocation:K8,histogram:J8,interval:X8,labeledValue:e3,likert:z8,lineCone:H8,matrix:W8,multipleChoice:D8,probabilityTokens:Y8,ranking:U8,region:Z8,slider:j8,thermometer:Q8},Symbol.toStringTag,{value:"Module"})),n3=Object.freeze(Object.defineProperty({__proto__:null,AXIS_CHROME:I5,AXIS_OPTIONS:Q0,AXIS_RADIAL_OPTIONS:Ib,CONSTRAINT_OPTIONS:_0,DEFAULT_PICK_THRESHOLD:Jl,EDIT_OPTIONS:$0,EDIT_UNIVERSAL_OPTIONS:S0,ELEMENT_OPTIONS:As,ELEMENT_UNIVERSAL_OPTIONS:v0,GRID_OPTIONS:od,GUIDE_OPTIONS:Ts,GUIDE_UNIVERSAL_OPTIONS:k0,HANDLE_DEFAULTS:Jf,LEGEND_OPTIONS:ob,LINK_SHAPES:yl,MARK_OPTIONS:st,MARK_SHORTHANDS:x0,MARK_UNIVERSAL_OPTIONS:w0,ORIENT_SPAN:$a,STANDARD_STYLE_CHANNELS:I0,THEME:Ub,anchorsOf:ic,andWhen:Vr,angularBand:mb,arcPath:ps,arcSpan:yd,arcSpine:hl,bandSpan:i0,bandStartOf:Yr,bandwidthOf:yn,baselineOf:yr,categoryOf:Nn,channelDomain:A0,claimEdge:cl,claimPick:Kl,createProjection:m0,defineConstraint:Vt,degToRad:yb,discreteDomain:T0,distanceToMark:us,edgeInsetOf:Zl,encodeAngle:zr,encodeChannel:se,encodeValue:Lt,envelopePolygon:xd,groupByPosition:ad,hitTest:Sa,invertChannel:ho,invertPoint:Fr,isBand:Vn,isDiscrete:fo,isWebMercator:Ob,lineSegment:pl,linearInvert:E0,makeEdit:je,markCenter:Rn,markCommon:lt,markDefaults:Nt,measureText:qi,mintDatum:Fn,nearestMark:In,nearestMarkOnAxis:td,nearestSeries:Ar,needleTriangle:bb,nestedEnvelopes:kb,nextCategory:Yf,nextSeriesKey:Yl,normalizeMarkOptions:at,noteBox:$n,nudgeTarget:Hu,orientationOf:Zf,paramChannels:md,pickThreshold:Zn,polarToXY:cn,positionalKeys:Xt,projectBounds:b0,projectPoint:ur,rangeExtent:oo,readParams:bd,recenterSpan:Gl,registerDriver:AE,resolveHandles:fn,resolveMarkNode:Pr,resolveStyle:yt,resolveSymbol:cs,resolveValueAxis:kr,sampleCubic:dl,sampleLines:Sb,sampleQuadratic:rc,schemaDefaults:Es,seriesFieldOf:Os,stackDescriptor:ds,stackLayout:tc,symbolNode:Xl,themeOf:it,tileCover:Cb,tileUrl:Nb,valueAt:Cr,warn:ge,warnUnknownElementOptions:Cs,widgetTheme:mn,wrapText:xb},Symbol.toStringTag,{value:"Module"}));let Ii=null;const r3={start:"start",middle:"center",end:"end",left:"left",right:"right",center:"center"},o3={middle:"middle",central:"middle",hanging:"hanging","text-before-edge":"top","text-after-edge":"bottom",alphabetic:"alphabetic",ideographic:"ideographic"};function li(e,t){const n={},r=e.effectStyle;for(const{field:o,base:i}of X0){const s=o in t?t[o]:i;n[o]=r&&r[o]!=null?r[o]:e[o]!=null?e[o]:s}return n}function i3(e,t){if(t==null||t==="none"){e.setLineDash([]);return}if(Array.isArray(t)){e.setLineDash(t);return}e.setLineDash(String(t).split(/[\s,]+/).map(Number).filter(n=>!Number.isNaN(n)))}function Rs(e,t,n){const r=t.opacity!=null?t.opacity:1;t.fill&&t.fill!=="none"&&(e.globalAlpha=r*(t.fillOpacity!=null?t.fillOpacity:1),e.fillStyle=t.fill,n?e.fill(n):e.fill()),t.stroke&&t.stroke!=="none"&&(e.globalAlpha=r*(t.strokeOpacity!=null?t.strokeOpacity:1),e.strokeStyle=t.stroke,e.lineWidth=t.strokeWidth!=null?t.strokeWidth:1,e.lineCap=t.strokeLinecap||"butt",i3(e,t.strokeDasharray),n?e.stroke(n):e.stroke()),e.globalAlpha=1,e.lineCap="butt",e.setLineDash([])}function ci(e,t,n){if(t.angle!=null&&t.angle!==0){const r=Rn(t);if(r){e.save(),e.translate(r.cx,r.cy),e.rotate(-t.angle*Math.PI/180),e.translate(-r.cx,-r.cy),n(),e.restore();return}}n()}function cc(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.r!=null?t.r:5);e.beginPath(),e.arc(t.cx,t.cy,r,0,2*Math.PI),Rs(e,li(t,n))})}function Vb(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.rx!=null?t.rx:5),o=Math.max(0,t.ry!=null?t.ry:5);e.beginPath(),e.ellipse(t.cx,t.cy,r,o,0,0,2*Math.PI),Rs(e,li(t,n))})}function bl(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.height);if(e.beginPath(),t.rx!=null&&typeof e.roundRect=="function"){const o=Math.max(0,t.rx),i=t.ry!=null?Math.max(0,t.ry):o;e.roundRect(t.x,t.y,t.width,r,[o,i])}else e.rect(t.x,t.y,t.width,r);Rs(e,li(t,n))})}function uc(e,t,n){ci(e,t,()=>{e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),Rs(e,li(t,n))})}function fc(e,t,n){let r;t.d?r=new Path2D(t.d):(r=new Path2D,_i().curve(Ni(t.curve)).context(r)(t.points||[])),Rs(e,li(t,n),r)}function Od(e,t,n,r){t.text!=null&&ci(e,t,()=>{const o=li(t,n),i=Ii&&Ii.family||"sans-serif",s=t.fontSize!=null?t.fontSize:Ii&&Ii.size||10;e.font=`${s}px ${i}`,e.textAlign=r3[t.textAnchor||r]||"start",e.textBaseline=o3[t.dominantBaseline]||"alphabetic";const a=Array.isArray(t.lines)?t.lines:[String(t.text)],l=t.lineHeight!=null?t.lineHeight:Math.round(s*1.35),u=t.y-(a.length-1)*l/2,c=o.opacity!=null?o.opacity:1;o.fill&&o.fill!=="none"&&(e.globalAlpha=c*(o.fillOpacity!=null?o.fillOpacity:1),e.fillStyle=o.fill,a.forEach((d,f)=>e.fillText(String(d),t.x,u+f*l))),o.stroke&&o.stroke!=="none"&&(e.globalAlpha=c*(o.strokeOpacity!=null?o.strokeOpacity:1),e.strokeStyle=o.stroke,e.lineWidth=o.strokeWidth!=null?o.strokeWidth:1,a.forEach((d,f)=>e.strokeText(String(d),t.x,u+f*l))),e.globalAlpha=1})}function s3(e,t,n,r){if(!t.href)return;let o=n.get(t.href);if(!o){const i=new Image;o={img:i,ready:!1},i.onload=()=>{o.ready=!0,r()},i.src=t.href,n.set(t.href,o)}o.ready&&ci(e,t,()=>{const i=e.globalAlpha;t.opacity!=null&&(e.globalAlpha=t.opacity),e.drawImage(o.img,t.x,t.y,t.width,t.height),e.globalAlpha=i})}function a3(e,t){switch(t.type){case"path":fc(e,t,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});break;case"rect":bl(e,t,{fill:"black"});break;case"circle":cc(e,t,{fill:"black"});break;case"ellipse":Vb(e,t,{fill:"black"});break;case"line":uc(e,t,{stroke:"black",strokeWidth:1,opacity:1});break;case"text":Od(e,t,{fill:"black",opacity:1},t.editable?"middle":"start");break}}function l3(e,t){switch(t.type){case"line":uc(e,t,{stroke:"black",strokeWidth:1,opacity:1});break;case"circle":cc(e,t,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});break;case"path":fc(e,t,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});break;case"text":Od(e,t,{fill:"black",opacity:1},"start");break}}function c3(e,t){const n={fill:"none",stroke:"none",strokeWidth:1,opacity:1};switch(t.type){case"circle":cc(e,t,n);break;case"rect":bl(e,t,n);break;case"ellipse":Vb(e,t,n);break;case"line":uc(e,t,n);break;case"path":fc(e,t,n);break}}function gy(e,t,n){Ii=n&&n.theme&&n.theme.font||null;const{background:r,guideRegions:o,marks:i,guideFront:s,effects:a}=J0(t);r.filter(l=>l.type==="image").forEach(l=>s3(e,l,n.images,n.requestRepaint));for(const l of r)l.type==="image"||l.type==="path"||(l.type==="rect"?bl(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1}):l.type==="circle"?cc(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1}):l.type==="line"?uc(e,l,{stroke:"#6b7280",strokeWidth:1,opacity:1}):l.type==="text"&&Od(e,l,{fill:"#374151",opacity:1},"middle"));r.filter(l=>l.type==="path").forEach(l=>fc(e,l,{fill:"none",stroke:"black",strokeWidth:1,opacity:1})),o.forEach(l=>bl(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1})),i.forEach(l=>a3(e,l)),s.forEach(l=>l3(e,l)),a.forEach(l=>c3(e,l))}const u3=4,f3=3;function d3(e,t){let n=null,r=null,o=!1;e.style.touchAction="none",e.style.userSelect="none";const i=a=>{const l=t(),u=e.getBoundingClientRect(),c=u.width?l.width/u.width:1,d=u.height?l.height/u.height:1;return[(a.clientX-u.left)*c-l.margins.left,(a.clientY-u.top)*d-l.margins.top]},s=(a,l,u,c=!0)=>{const d=t();n&&(n.mode==="direct"?(d.onEvent({type:"dragend",x:l,y:u,node:n.node,rawEvent:a}),c&&!n.moved&&d.onEvent({type:"click",x:l,y:u,node:n.node,rawEvent:a}),c&&(o=!0)):n.dragging&&(d.onEvent({type:"dragend",x:l,y:u,rawEvent:a}),c&&(o=!0))),n=null;const f=e.getBoundingClientRect();(a.clientX<f.left||a.clientX>f.right||a.clientY<f.top||a.clientY>f.bottom)&&(d.planeOnTop?d.onEvent({type:"hoverout",rawEvent:a}):r!==null&&(r=null,d.onEvent({type:"pointerout",rawEvent:a})))};e.addEventListener("pointerdown",a=>{const l=t(),[u,c]=i(a);if(l.planeOnTop)n={mode:"plane",sx:u,sy:c,dragging:!1};else{const d=Sa(l.scene.children,u,c);if(d)n={mode:"direct",node:d,sx:u,sy:c,moved:!1},l.onEvent({type:"dragstart",x:u,y:c,node:d,rawEvent:a});else{n=null;return}}a.preventDefault();try{e.setPointerCapture(a.pointerId)}catch{}}),e.addEventListener("pointermove",a=>{const l=t(),[u,c]=i(a);if(n&&a.pointerType==="mouse"&&a.buttons===0){s(a,u,c);return}if(!n){if(l.planeOnTop)l.onEvent({type:"hover",x:u,y:c,rawEvent:a}),e.style.cursor=l.planeCursor||"pointer";else{const d=Sa(l.scene.children,u,c),f=d?`${d.featureId}:${d.index}`:null;f!==r&&(r=f,l.onEvent(d?{type:"pointerover",node:d,rawEvent:a}:{type:"pointerout",rawEvent:a})),e.style.cursor=d?d.cursor||"move":"default"}return}n.mode==="direct"?(Math.hypot(u-n.sx,c-n.sy)>u3&&(n.moved=!0),l.onEvent({type:"drag",x:u,y:c,node:n.node,rawEvent:a})):(!n.dragging&&Math.hypot(u-n.sx,c-n.sy)>f3&&(n.dragging=!0,l.onEvent({type:"dragstart",x:n.sx,y:n.sy,rawEvent:a})),n.dragging&&l.onEvent({type:"drag",x:u,y:c,rawEvent:a}))}),e.addEventListener("pointerup",a=>{const[l,u]=i(a);s(a,l,u)}),e.addEventListener("pointercancel",a=>{const[l,u]=i(a);s(a,l,u,!1)}),e.addEventListener("pointerleave",a=>{if(!n){const l=t();l.planeOnTop?l.onEvent({type:"hoverout",rawEvent:a}):r!==null&&(r=null,l.onEvent({type:"pointerout",rawEvent:a}))}}),e.addEventListener("click",a=>{if(o){o=!1;return}const l=t(),[u,c]=i(a);l.onEvent({type:"click",x:u,y:c,rawEvent:a})}),e.addEventListener("dblclick",a=>{const l=t(),[u,c]=i(a),d=l.planeOnTop?null:Sa(l.scene.children,u,c);l.onEvent({type:"dblclick",x:u,y:c,...d?{node:d}:{},rawEvent:a})})}class h3{constructor(){this._canvas=null,this._2d=null,this._ctx=null,this._images=new Map}render(t){const{container:n,scene:r,width:o,height:i,margins:s}=t,a=t.responsive||"fixed";this._ensure(n),this._ctx=t;const l=this._canvas;l.style.background=t.theme&&t.theme.background||"";const u=this._canvas,c=this._2d,d=typeof window<"u"&&window.devicePixelRatio||1,f=Math.round(o*d),p=Math.round(i*d);(u.width!==f||u.height!==p)&&(u.width=f,u.height=p),a==="scale"?(u.style.width="100%",u.style.height="auto"):(u.style.width=`${o}px`,u.style.height=`${i}px`),c.setTransform(d,0,0,d,0,0),c.clearRect(0,0,o,i),c.translate(s.left,s.top),gy(c,r.children,{images:this._images,theme:t.theme,requestRepaint:()=>this._repaint()})}_ensure(t){if(this._canvas&&this._canvas.parentNode===t)return;const n=document.createElement("canvas");n.style.display="block",t.appendChild(n),this._canvas=n,this._2d=n.getContext("2d"),d3(n,()=>this._ctx)}_repaint(){const t=this._ctx,n=this._2d;if(!t||!n)return;const{scene:r,width:o,height:i,margins:s}=t,a=typeof window<"u"&&window.devicePixelRatio||1;n.setTransform(a,0,0,a,0,0),n.clearRect(0,0,o,i),n.translate(s.left,s.top),gy(n,r.children,{images:this._images,theme:t.theme,requestRepaint:()=>this._repaint()})}}const p3={default:{},survey:{ink:"#4f46e5",accent:"#4f46e5",muted:"#94a3b8",font:{family:'"Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif',size:11,labelSize:13,titleSize:15},axis:{stroke:"#cbd5e1",labelFill:"#475569",fontSize:11,handle:"#4f46e5"},grid:{stroke:"#f1f5f9",strokeWidth:1},constraint:{color:"#e11d48"},widget:{accent:"#4f46e5",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#475569",question:"#1e293b",labelSize:13,questionSize:15,radius:12}},dark:{background:"#0f172a",ink:"#38bdf8",accent:"#38bdf8",muted:"#64748b",axis:{stroke:"#475569",labelFill:"#cbd5e1",fontSize:10,handle:"#38bdf8"},grid:{stroke:"#1e293b"},guide:{rule:{stroke:"#94a3b8",strokeDasharray:"5 4"},region:{fill:"#94a3b8",opacity:.14},legend:{stroke:"#cbd5e1",labelFill:"#cbd5e1",fontSize:11}},constraint:{color:"#fb7185"},widget:{accent:"#38bdf8",ring:"#334155",track:"#1e293b",cellFill:"#1e293b",cellStroke:"#334155",label:"#cbd5e1",question:"#f1f5f9",labelSize:12,questionSize:13,radius:11}}},y3=Object.freeze(Object.defineProperty({__proto__:null,CanvasRenderer:h3,D3Renderer:Z0,DEFAULT_THEME:Vf,Elicit:ab,authoring:n3,constraints:Hb,edit:_d,elements:_4,format:gA,guides:P8,plot:vd,resolveTheme:Xf,setTheme:T5,setWarnings:YM,themes:p3,widgets:t3},Symbol.toStringTag,{value:"Module"})),Dt=e=>e?.__data__,Je={connect:"connect-step",removeStep:"delete-step",removeArrow:"delete-arrow",flip:"flip-arrow",kind:"set-kind",group:"set-group",boxKind:"set-box-kind",external:"set-external"},g3=[["Move a step","drag its box","move({ channels: [x, y] })","writes steps.x and steps.y"],["Draw a dependency","drag from a dot on a box’s edge to another box","network.connect()","appends a row to depends"],["Add a step after one","press the + beside a box","create() + connect()","adds a step and the arrow into it, together"],["Add a step","double-click empty canvas","create()","mints a row with a fresh steps.id"],["Rename a step","double-click a box","editText()","writes steps.label — and the box resizes to fit"],["Label an arrow","double-click an arrow","editText()","writes depends.label"],["Re-point an arrow","drag either arrow end","network.rewire()","rewrites depends.source or .target"],["Flip a dependency","right-click an arrow, then Flip direction","network.reverse()","swaps depends.source and .target"],["Set what an arrow means","right-click an arrow, then pick its kind","commit({ kind })","writes depends.kind"],["Move to a group","right-click a box, then a group; or drag it into the group’s frame","commit({ group })","writes steps.group"],["Delete","select a box or an arrow, then press Delete; or right-click it","remove()","deletes the row — and, via type: ref, every arrow into it"]],m3=[["Move a box","drag it; a folded frame takes what is in it along","move({ channels: [x, y] })","writes boxes.x and boxes.y"],["Draw an arrow","drag from a dot on a box’s edge to another box: the first uses the second","network.connect()","appends a row to arrows"],["Add a box after one","press the + beside a box","create() + connect()","adds a box and the arrow to it, together"],["Add a box","double-click empty canvas","create()","mints a row with a fresh boxes.id"],["Rename a box","double-click it","editText()","writes boxes.label"],["Say what an arrow is for","double-click an arrow","editText()","writes arrows.label"],["Re-point an arrow","drag either end","network.rewire()","rewrites arrows.source or .target"],["Change what a box is","right-click it, then Change kind: a person, service, component, store or queue","commit({ kind })","writes boxes.kind"],["Make an arrow async","right-click it: it does not wait for the answer","commit({ kind })","writes arrows.kind"],["Put a box in a frame","right-click it, then Move into; or drag it into the frame","commit({ group })","writes boxes.group"],["Fold a frame","press the chevron on its name, or right-click the frame","layout.fold","hides what is inside it; its arrows are drawn to it"],["Delete","select a box or an arrow, then press Delete; or right-click it","remove()","deletes the row, and every arrow into it"]],{sticker:b3,link:w3,text:x3}=vd,{move:v3,editText:my,remove:by,network:sa}=_d,{unique:k3}=Hb,Cd=90,wl=60,ln=(e,t)=>typeof document>"u"?t:getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t,Xc=26,Xb=e=>{const t=e==null?"":String(e);if(t.length<=Xc)return t;const n=t.slice(0,Xc-1),r=n.lastIndexOf(" ");return`${(r>Xc/2?n.slice(0,r):n).trimEnd()}…`},Jb=({defaults:e,over:t})=>je({type:"create",gesture:"dblclick",channels:["x","y"],pick:"plane",cardinality:"append",when:n=>!n.data.some(r=>t(r,n.pointer)),apply:n=>{const r=Fn(n,{defaults:e});if(!r)return;const o=new Set(n.data.map(s=>s.id));let i=n.data.length+1;for(;o.has(`step-${i}`);)i++;return[...n.data,{...r,id:`step-${i}`}]}}),Dn=(e,t)=>Object.defineProperty(t,"name",{value:e}),dr=e=>Dn(`byName(${e})`,t=>t.event?.by===e),No=(e,t)=>je({type:e,name:e,gesture:"commit",pick:"direct",when:dr(e),apply:n=>n.datum&&n.value!==void 0&&n.datum[t]!==n.value?{...n.datum,[t]:n.value}:void 0}),Zb=Object.assign(k3({field:["source","target"],strategy:"reject"}),{table:"links"});function S3(e){const t=Gy(e);return t.length||t.push(jt),t}const $3=new Set(["approve","ask","input"]);function _3(e,t){return t?.arrow(e)==="yours"?{stroke:Ta.waiting}:{}}function M3(e,{onChange:t,decor:n}){const r=S3(e),o=ln("--ember","#EA5202"),i=ln("--surface","#FFFFFF"),s=ln("--wire","#8F8881"),a=ln("--wire-soft","#C9C3BD"),l=ln("--slate","#69625B"),u=ln("--ink","#19120F"),c=ln("--sans","sans-serif"),d={...Xr,fontFamily:c},{fontSize:f,...p}=d;return{...wr(e),responsive:"scale",focusOutline:!0,axes:!1,margins:{top:xt.y,right:xt.x,bottom:xt.y,left:xt.x},theme:{handle:o,handleStroke:i,background:"transparent",font:{family:c},marks:{text:{fill:u}}},schema:{structure:"network",tables:{steps:{role:"nodes",fields:{id:{type:"categorical",key:!0,open:!0},label:{type:"categorical",open:!0,default:"new step"},group:{type:"categorical",domain:r,open:!0,default:jt},x:{type:"quantitative",domain:[0,e.canvas.width]},y:{type:"quantitative",domain:[0,e.canvas.height]}}},depends:{role:"links",directed:!0,fields:{source:{type:"ref"},target:{type:"ref"},label:{type:"categorical",open:!0,default:""},kind:{type:"categorical",open:!0,default:"needs"}}}}},data:{steps:e.steps,depends:e.depends},onChange:t,...n?{lock:Dn("frozen",(h,y,g)=>n.frozen(h,g))}:{},constraints:[Zb],marks:[w3({curve:"orthogonal",arrowSize:8,inset:3,stroke:h=>_3(h,n).stroke??(h.kind==="after"?a:s),strokeWidth:h=>$3.has(h.kind)?2.6:h.kind==="after"?1.1:1.4,handleSize:4.5,handleColor:a,fill:l,fontSize:11,labelBackground:i,labelPadding:3,format:Xb,channels:{nodeWidth:{fn:Dn("boxWidth",h=>$n(h.label,d).width)},nodeHeight:{fn:Dn("boxHeight",h=>$n(h.label,d).height)},source:{field:"source",edit:sa.rewire({channel:"source",threshold:wl,when:h=>h.node?.channel==="source"})},target:{field:"target",edit:sa.rewire({channel:"target",threshold:wl,when:h=>h.node?.channel==="target"})},text:{field:"label"}},edits:[sa.reverse({name:Je.flip,when:dr(Je.flip)}),by({name:Je.removeArrow,when:dr(Je.removeArrow)}),No(Je.kind,"kind"),my()]}),b3({...p,radius:7,stroke:n?Dn("statusEdge",h=>n.stroke(h)??s):s,strokeWidth:n?Dn("statusEdgeWidth",h=>n.strokeWidth(h)??1.5):1.5,...n?{opacity:h=>n.opacity(h)}:{},channels:{x:{field:"x",edit:v3({channels:["x","y"],mode:"relative"})},y:{field:"y",scale:{reverse:!0}},text:{field:"label"},fill:{value:i},fontSize:{value:f}},edits:[sa.connect({name:Je.connect,when:dr(Je.connect),threshold:Cd}),No(Je.group,"group"),Jb({defaults:{label:"new step",group:jt},over:(h,y)=>{const{width:g,height:m}=$n(h.label,d);return Math.abs(y.x-h.x)<=g/2&&Math.abs(y.y-h.y)<=m/2}}),by({name:Je.removeStep,when:dr(Je.removeStep)}),my()]}),...n?[x3({fill:l,fontSize:12,dy:h=>$n(h.label,d).height/2+13,channels:{x:{field:"x"},y:{field:"y",scale:{reverse:!0}},text:{fn:Dn("owner",h=>n.owner(h))}}})]:[]]}}const wy={fine:8,coarse:40},E3={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},On=e=>e?.tagName==="rect"&&!!Dt(e)?.data&&"group"in Dt(e).data;function A3({frame:e,chart:t,onSelect:n}){e.addEventListener("keydown",i=>{const s=i.target instanceof Element&&On(i.target)?Dt(i.target):null;if(!s)return;const a=E3[i.key];if(a){i.preventDefault(),i.stopPropagation();const l=i.shiftKey?wy.coarse:wy.fine,u=s.x+s.width/2,c=s.y+s.height/2,d=t();d.emit({type:"dragstart",node:s,x:u,y:c}),d.emit({type:"drag",node:s,x:u+a[0]*l,y:c+a[1]*l}),d.emit({type:"dragend",node:s,x:u+a[0]*l,y:c+a[1]*l}),T3(e,s.data.id)}else i.key===" "&&n?(i.preventDefault(),i.stopPropagation(),n(s.data.id)):(i.key==="Enter"||i.key==="F2")&&(i.preventDefault(),i.stopPropagation(),i.target.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0})))},!0),e.addEventListener("focusin",i=>{if(!(i.target instanceof Element)||!On(i.target))return;const s=Dt(i.target).data;i.target.setAttribute("aria-label",`${s.label}. A step: the arrow keys move it, Enter renames it, Delete removes it, the menu key opens its menu.`)});let r=!1;const o=()=>{r=!1;for(const i of e.querySelectorAll('svg [tabindex="0"]'))On(i)||i.setAttribute("tabindex","-1")};new MutationObserver(()=>{r||(r=!0,requestAnimationFrame(o))}).observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex"]})}function T3(e,t){requestAnimationFrame(()=>{if(e.contains(document.activeElement)&&On(document.activeElement))return;[...e.querySelectorAll("svg rect.mark")].find(r=>Dt(r)?.data?.id===t)?.focus()})}const xy={x:90,y:50};function Qb(e,t,n=[]){const r=new Set(n.filter(f=>e.nodes[f]&&Er(e,f))),o=f=>I1(e,f,r),i=new Set;for(const f of Object.keys(e.nodes))Ky(e,f).some(p=>r.has(p))&&i.add(f);const s=[],a=[],l=new Map;for(const[f,p]of Object.entries(e.nodes)){if(i.has(f))continue;const h={id:f,label:p.label,kind:p.kind,external:!!p.external,...p.tech?{tech:p.tech}:{},...p.in?{parent:p.in}:{}},y=p.in??jt;if(!Er(e,f)){s.push(vy(f,p,y,t.nodes[f]??xy));continue}if(!r.has(f)){a.push(h);continue}const g=Oa(e,f).filter(b=>t.nodes[b]),m=g.length?{x:Math.round(g.reduce((b,w)=>b+t.nodes[w].x,0)/g.length),y:Math.round(g.reduce((b,w)=>b+t.nodes[w].y,0)/g.length)}:xy;l.set(f,{count:Oa(e,f).filter(b=>!Er(e,b)).length}),s.push(vy(f,p,y,m))}const u=new Map,c=new Set;for(const f of e.edges){const p=o(f.from),h=o(f.to);if(p===h)continue;const y=`${p}\0${h}`,g=u.get(y);if((p!==f.from||h!==f.to)&&c.add(y),g){g.n++,g.async+=f.async?1:0,g.label=`${g.n} arrows`,g.tech="";continue}u.set(y,{source:p,target:h,label:f.label??"",kind:"needs",tech:f.tech??"",n:1,async:f.async?1:0})}const d=[...u.values()].map(({n:f,async:p,...h})=>({...h,kind:p===f?"async":"needs"}));return{steps:s,depends:d,lifted:c,folded:l,frames:a,hidden:i,stand:o}}const vy=(e,t,n,r)=>({id:e,label:t.label,group:n,kind:t.kind,external:t.external?"yes":"",x:r.x,y:r.y});function ky(e,t,n){const r=typeof n=="function"?n:a=>n.get(a),o=new Map,i=(a,l)=>{const u=o.get(a.id);if(u)return u;if(l.has(a.id))return null;l.add(a.id);const c=t.filter(m=>m.group===a.id).map(m=>m.id),d=[];for(const m of c){const b=r(m);b&&d.push({x:b.x-b.w/2,y:b.y-b.h/2,w:b.w,h:b.h})}for(const m of e.filter(b=>b.parent===a.id)){const b=i(m,l);b&&(d.push({x:b.x,y:b.y,w:b.w,h:b.h}),c.push(...b.members))}if(l.delete(a.id),!d.length)return null;const f=Math.min(...d.map(m=>m.x))-Eo.left,p=Math.max(...d.map(m=>m.x+m.w))+Eo.right,h=Math.min(...d.map(m=>m.y))-Eo.top,y=Math.max(...d.map(m=>m.y+m.h))+Eo.bottom,g={x:f,y:h,w:p-f,h:y-h,members:c};return o.set(a.id,g),g};for(const a of e)i(a,new Set);const s=a=>{let l=0;for(let u=a.parent;u;u=e.find(c=>c.id===u)?.parent)l++;return l};return e.filter(a=>o.has(a.id)).map(a=>({...a,group:a.id,depth:s(a),...o.get(a.id)})).sort((a,l)=>a.depth-l.depth)}class Hi extends Error{}const _a={label:"new box",kind:"service",external:"",group:jt},Sy={width:300,height:180};function Mo({arch:e,layout:t},{headroom:n=!0}={}){const r=Qb(e,t,t.collapsed??[]),o=t.canvas??{width:640,height:240};return{id:"architecture",title:e.title,plan:e.title,repo:"",source:e.source?.url??"",direction:t.direction,note:e.goal??"",canvas:n?{width:o.width+Sy.width,height:o.height+Sy.height}:o,steps:r.steps,depends:r.depends,proj:r}}function e1(e,t,n){const r=Qb(e,t,t.collapsed??[]),o=structuredClone(e),i=[],s=new Set(n.steps.map(h=>h.id)),a=new Map(r.steps.map(h=>[h.id,h]));for(const h of a.keys())if(!s.has(h)){if(r.folded.has(h))throw new Hi(`${e.nodes[h].label} is a folded frame: it stands for everything in it. Unfold it, and take away what you mean to.`);delete o.nodes[h];for(const y of o.flows)y.steps=y.steps.filter(g=>g.from!==h&&g.to!==h)}for(const h of n.steps){const y=a.get(h.id),g=o.nodes[h.id];if(!y||!g){const x={label:h.label,kind:h.kind||_a.kind};h.external&&(x.external=!0),h.group&&h.group!==jt&&(x.in=h.group),o.nodes[h.id]=x,i.push({id:h.id,x:Math.round(h.x),y:Math.round(h.y)});continue}h.label!==g.label&&(g.label=h.label),h.kind&&h.kind!==g.kind&&(g.kind=h.kind),!!h.external!=!!g.external&&(h.external?g.external=!0:delete g.external);const m=h.group===jt||!h.group?void 0:h.group;m!==g.in&&(m?g.in=m:delete g.in);const b=Math.round(h.x)-Math.round(y.x),w=Math.round(h.y)-Math.round(y.y);if(!(!b&&!w))if(r.folded.has(h.id))for(const x of Oa(e,h.id))t.nodes[x]&&i.push({id:x,x:Math.round(t.nodes[x].x)+b,y:Math.round(t.nodes[x].y)+w});else i.push({id:h.id,x:Math.round(h.x),y:Math.round(h.y)})}const l=h=>`${h.from}\0${h.to}`,u=h=>r.stand(h.from)===h.from&&r.stand(h.to)===h.to,c=e.edges.filter(h=>!u(h));new Set(n.depends.map(h=>`${h.source}\0${h.target}`));for(const h of r.lifted){const[y,g]=h.split("\0"),m=n.depends.find(w=>w.source===y&&w.target===g),b=r.depends.find(w=>w.source===y&&w.target===g);if(!m||m.label!==b?.label||m.kind==="async"!=(b?.kind==="async"))throw new Hi(`That arrow stands for the arrows inside a folded frame, and cannot be changed from here. Unfold ${e.nodes[y]?.label??y} or ${e.nodes[g]?.label??g} to change them.`)}const d=[];for(const h of n.depends){if(r.lifted.has(`${h.source}\0${h.target}`))continue;const y=e.edges.find(m=>m.from===h.source&&m.to===h.target)??e.edges.find(m=>m.from===h.target&&m.to===h.source),g={from:h.source,to:h.target};h.label&&(g.label=h.label),h.tech&&(g.tech=h.tech),h.kind==="async"&&(g.async=!0),y?.via&&(g.via=y.via),y?.planned&&(g.planned=y.planned),y?.retiring&&(g.retiring=y.retiring),d.push(g)}o.edges=[...c,...d].filter(h=>h.from in o.nodes&&h.to in o.nodes);const f=new Map(e.edges.map((h,y)=>[l(h),y]));o.edges.sort((h,y)=>(f.get(l(h))??1e9)-(f.get(l(y))??1e9));for(const h of o.edges)h.via&&!(h.via in o.nodes)&&delete h.via;const p=Vy(o);if(p.length)throw new Hi(p[0]);return{after:o,placements:i}}function O3(e,t){const{after:n,placements:r}=e1(e.arch,e.layout,t),{ops:o}=pg(e.arch,n);for(const i of r){const s=e.layout.nodes[i.id];n.nodes[i.id]&&(!s||Math.round(s.x)!==i.x||Math.round(s.y)!==i.y)&&o.push({op:"layout.place",id:i.id,x:i.x,y:i.y})}return o}function C3(e){const t=Mo(e,{headroom:!1});return{...t,steps:t.steps.map(n=>({...n,group:n.group===jt?n.group:e.arch.nodes[n.group]?.label??n.group}))}}const Jc={untouched:.4,offFlow:.22};function N3(e){const t=i=>e()?.arch.nodes[i],n=i=>{const s=e();return s?.footprint&&t(i)?L1(s.arch,s.footprint,i):null},r=()=>{const i=e();if(!i?.flow)return null;const s=new Set;for(const a of i.flow)s.add(i.stand(a.from)),s.add(i.stand(a.to));return s},o=i=>{const s=t(i);return s?.planned?"planned":s?.retiring?"retiring":null};return{edge(i){const s=n(i);return s==="new"||s==="changed"||s==="removed"?{colour:Br[s].colour,width:2.6,dashed:s==="new"||s==="removed"}:o(i)?{width:1.6,dashed:!0}:{width:1.5,dashed:!1}},opacity(i){const s=r();return s?s.has(i)?1:Jc.offFlow:n(i)==="untouched"?Jc.untouched:1},look(i){const s=n(i);if(s==="new"||s==="changed"||s==="removed")return{...Br[s],strike:s==="removed"};const a=o(i);return a==="planned"?{...Br.new,word:t(i)?.planned==="next"?"planned":`planned by ${t(i)?.planned}`,strike:!1}:a==="retiring"?{...Br.removed,word:`retiring: ${t(i)?.retiring} removes it`,strike:!1}:null},caption(i,s){const a=e(),l=[],u=a?.folded.get(i);u&&l.push(`${u.count} inside`);const c=a?.footprint?.changed.get(i);return c?.length&&l.push(c.length===1?`changed by ${s?.[c[0]]??c[0]}`:`changed by ${c.length} steps`),l.join(" · ")},arrow(i){const s=e();if(!s)return{opacity:1};const a=`${i.source}\0${i.target}`,l=s.flow,c=(l?l.some(f=>s.stand(f.from)===i.source&&s.stand(f.to)===i.target||s.stand(f.from)===i.target&&s.stand(f.to)===i.source):!0)?1:Jc.offFlow;if(s.footprint?.addedArrows.has(a))return{stroke:Ta.done,opacity:c,dashed:!0};if(s.footprint?.removedArrows.has(a))return{stroke:Ta.failed,opacity:c,dashed:!0};const d=s.arch.edges.find(f=>`${f.from}\0${f.to}`===a);return{opacity:c,...d?.planned||d?.retiring?{dashed:!0}:{}}}}}const{sticker:I3,link:L3,text:F3}=vd,{move:R3,editText:$y,remove:_y,network:aa}=_d;function P3(e,{onChange:t,decor:n,stepLabel:r}){const o=[jt,...e.proj.frames.map(g=>g.id)],i=ln("--ember","#EA5202"),s=ln("--surface","#FFFFFF"),a=ln("--wire","#8F8881"),l=ln("--wire-soft","#C9C3BD"),u=ln("--slate","#69625B"),c=ln("--ink","#19120F"),d=ln("--sans","sans-serif"),f={...Xr,fontFamily:d},{fontSize:p,...h}=f,y=g=>r?.(g);return{...wr(e),responsive:"scale",focusOutline:!0,axes:!1,margins:{top:xt.y,right:xt.x,bottom:xt.y,left:xt.x},theme:{handle:i,handleStroke:s,background:"transparent",font:{family:d},marks:{text:{fill:c}}},schema:{structure:"network",tables:{steps:{role:"nodes",fields:{id:{type:"categorical",key:!0,open:!0},label:{type:"categorical",open:!0,default:_a.label},group:{type:"categorical",domain:o,open:!0,default:jt},kind:{type:"categorical",open:!0,default:_a.kind},external:{type:"categorical",open:!0,default:""},x:{type:"quantitative",domain:[0,e.canvas.width]},y:{type:"quantitative",domain:[0,e.canvas.height]}}},depends:{role:"links",directed:!0,fields:{source:{type:"ref"},target:{type:"ref"},label:{type:"categorical",open:!0,default:""},kind:{type:"categorical",open:!0,default:"needs"},tech:{type:"categorical",open:!0,default:""}}}}},data:{steps:e.steps,depends:e.depends},onChange:t,constraints:[Zb],marks:[L3({curve:"orthogonal",arrowSize:8,inset:3,stroke:g=>n?.arrow({source:g.source,target:g.target}).stroke??(g.kind==="async"?l:a),strokeWidth:g=>n?.arrow({source:g.source,target:g.target}).stroke?2.2:g.kind==="async"?1.2:1.4,...n?{opacity:g=>n.arrow({source:g.source,target:g.target}).opacity}:{},handleSize:4.5,handleColor:l,fill:u,fontSize:11,labelBackground:s,labelPadding:3,format:Xb,channels:{nodeWidth:{fn:Dn("boxWidth",g=>$n(g.label,f).width)},nodeHeight:{fn:Dn("boxHeight",g=>$n(g.label,f).height)},source:{field:"source",edit:aa.rewire({channel:"source",threshold:wl,when:g=>g.node?.channel==="source"})},target:{field:"target",edit:aa.rewire({channel:"target",threshold:wl,when:g=>g.node?.channel==="target"})},text:{field:"label"}},edits:[aa.reverse({name:Je.flip,when:dr(Je.flip)}),_y({name:Je.removeArrow,when:dr(Je.removeArrow)}),No(Je.kind,"kind"),$y()]}),I3({...h,radius:7,stroke:"transparent",fill:"transparent",strokeWidth:0,...n?{opacity:g=>n.opacity(g.id)}:{},channels:{x:{field:"x",edit:R3({channels:["x","y"],mode:"relative"})},y:{field:"y",scale:{reverse:!0}},text:{field:"label"},fill:{value:"transparent"},fontSize:{value:p}},edits:[aa.connect({name:Je.connect,when:dr(Je.connect),threshold:Cd}),No(Je.group,"group"),No(Je.boxKind,"kind"),No(Je.external,"external"),Jb({defaults:{..._a},over:(g,m)=>{const{width:b,height:w}=$n(g.label,f);return Math.abs(m.x-g.x)<=b/2&&Math.abs(m.y-g.y)<=w/2}}),_y({name:Je.removeStep,when:dr(Je.removeStep)}),$y()]}),...n?[F3({fill:u,fontSize:12,dy:g=>$n(g.label,f).height/2+13,...n?{opacity:g=>n.opacity(g.id)}:{},channels:{x:{field:"x"},y:{field:"y",scale:{reverse:!0}},text:{fn:Dn("caption",g=>n.caption(g.id,new Proxy({},{get:(m,b)=>y(String(b))})))}}})]:[]]}}const z3="http://www.w3.org/2000/svg";function ht(e,t={},n){const r=document.createElementNS(z3,e);for(const[o,i]of Object.entries(t))r.setAttribute(o,String(i));return n!==void 0&&(r.innerHTML=n),r}const Ui=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]??t),_n=(e,t)=>getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t;function jn(e){const t=_n("--sans","sans-serif");return e.map(n=>{const{width:r,height:o}=$n(n.label,{...Xr,fontFamily:t});return{id:n.id,group:n.group,x:n.x+xt.x,y:n.y+xt.y,w:r,h:o}})}function dc(e,t,n){e.querySelector(`:scope > .${t}`)?.remove();const{width:r,height:o}=wr({canvas:n});return ht("svg",{class:t,viewBox:`0 0 ${r} ${o}`,"aria-hidden":"true"})}function D3(e,t,n,r=null){if(!e)return;const o=dc(e,"frames",n),i=_n("--ember","#EA5202");for(const s of Xy(t)){const a=s.group===r,l=ht("g",{"data-group":s.group}),u=s.members.length===1&&!a;u||l.appendChild(ht("rect",{x:s.x,y:s.y,width:s.w,height:s.h,rx:10,fill:"var(--frame)",stroke:a?i:"var(--frame-edge)","stroke-width":a?2.2:1.2,...a?{"stroke-dasharray":"6 4"}:{}})),l.appendChild(ht("text",u?{x:s.x+Eo.left+16,y:s.y+Eo.top-5,class:"frame-name","font-size":10.5,"font-weight":600,fill:"var(--slate)",opacity:.85}:{x:s.x+12,y:s.y+19,class:"frame-name","font-size":11.5,"font-weight":600,fill:"var(--slate)"},Ui(Jy(s.group,u?s.w+60:s.w)))),o.appendChild(l)}e.prepend(o)}const j3=e=>22+e.length*5.7;function ef(e,t){const n=e instanceof SVGSVGElement?e:e.querySelector("svg"),r=new Map;for(const s of e.querySelectorAll("path")){const a=Dt(s)?.data;if(!a||a.source===void 0||a.target===void 0)continue;const l=s.getAttribute("fill");if(l&&l!=="none")continue;const u=s.getTotalLength?.()??0,c=`${a.source}\0${a.target}`;u>(r.get(c)?.len??0)&&r.set(c,{path:s,len:u})}const o=new Map,i=n?.getScreenCTM()?.inverse();if(!i)return o;for(const s of t){const a=`${s.source}\0${s.target}`,l=r.get(a);if(!l||l.len<18)continue;const u=l.path.getPointAtLength(s.label?Math.min(16,l.len*.2):l.len*.5),c=l.path.getScreenCTM();if(!c)continue;const d=new DOMPoint(u.x,u.y).matrixTransform(i.multiply(c));o.set(a,{x:d.x,y:d.y})}return o}function t1(e,{items:t,look:n,arrows:r,size:o}){if(!e)return;const i=dc(e,"marks",o),s=_n("--ink","#19120F"),a=_n("--surface","#FFFFFF"),l=_n("--slate","#69625B");for(const c of t){const d=n(c.id);if(!d)continue;const f=c.x-c.w/2,p=c.x+c.w/2,h=c.y-c.h/2;if(d.strike&&i.appendChild(ht("path",{d:`M${f+7} ${c.y} H${p-7}`,stroke:s,"stroke-width":1.6,"stroke-linecap":"round",opacity:.8})),d.icon){const g=ht("g",{transform:`translate(${f+1} ${h-1})`,class:"chip","data-status":d.word??""});g.appendChild(ht("title",{},Ui(d.word??""))),g.appendChild(ht("circle",{r:9,fill:d.colour??l,stroke:a,"stroke-width":2})),g.appendChild(ht("g",{transform:"translate(-6 -6)",color:"#FFFFFF"},fa(d.icon))),i.appendChild(g)}[d.review?["question","review"]:null,d.atRisk?["exclaim","at risk"]:null].filter(Boolean).forEach((g,m)=>{const[b,w]=g,x=j3(w),S=ht("g",{transform:`translate(${p-x+10} ${h-9-m*19})`,class:"pill","data-badge":w});S.appendChild(ht("rect",{width:x,height:16,rx:8,fill:a,stroke:s,"stroke-width":1})),S.appendChild(ht("g",{transform:"translate(3 2)",color:s},fa(b))),S.appendChild(ht("text",{x:18,y:11.5,"font-size":10.5,"font-weight":600,fill:s},Ui(w))),i.appendChild(S)})}const u=Ta.waiting;for(const c of r){const d=c.icon??ff[c.kind];if(d){const f=ht("g",{transform:`translate(${c.x} ${c.y})`,class:"gate","data-kind":c.kind,...c.yours?{"data-yours":""}:{}});f.appendChild(ht("circle",{r:9,fill:a,stroke:c.yours?u:"var(--wire)","stroke-width":c.yours?2.4:1.5})),f.appendChild(ht("g",{transform:"translate(-6 -6)",color:c.yours?u:s},fa(d))),i.appendChild(f)}c.tech&&i.appendChild(ht("text",{class:"arrow-tech",x:c.x,y:c.y+(d?21:15),"text-anchor":"middle","font-size":10,fill:l,stroke:a,"stroke-width":3,"paint-order":"stroke"},Ui(c.tech)))}e.insertBefore(i,e.querySelector(":scope > .ghost"))}function W3(e,{frames:t,boxes:n,decor:r,size:o,dropping:i=null}){if(!e)return;const s=dc(e,"frames",o),a=_n("--ember","#EA5202"),l=_n("--surface","#FFFFFF"),u=_n("--wire","#8F8881"),c=_n("--ext-fill","#ECE9E5"),d="6 4";for(const f of t){const p=f.id===i,h=r.edge(f.id),y=ht("g",{"data-group":f.id,class:"frame",opacity:r.opacity(f.id)}),g=p?a:h.colour??"var(--frame-edge)",m=p||h.dashed||f.kind==="group";y.appendChild(ht("rect",{x:f.x,y:f.y,width:f.w,height:f.h,rx:12,fill:f.external?c:"var(--frame)",stroke:g,"stroke-width":p?2.2:h.colour?h.width:1.2,...m?{"stroke-dasharray":d}:{}})),y.appendChild(ht("text",{x:f.x+12,y:f.y+19,class:"frame-name","font-size":11.5,"font-weight":600,fill:"var(--slate)"},Ui(Jy(f.label,f.w-40)))),s.appendChild(y)}for(const f of n){const p=r.edge(f.id),h=ht("g",{class:"shape","data-id":f.id,"data-kind":f.kind,opacity:r.opacity(f.id)});for(const y of F1(f.kind,f,{folded:f.folded})){const{dashed:g,...m}=y.attrs,b=y.role==="line";h.appendChild(ht(y.tag,{...m,class:`part ${y.role}`,fill:b?"none":f.external?c:l,stroke:p.colour??u,"stroke-width":p.width,"stroke-linejoin":"round",...g||p.dashed?{"stroke-dasharray":d}:{}}))}s.appendChild(h)}e.prepend(s)}function n1(e,t){for(const n of e.querySelectorAll("path")){const r=Dt(n)?.data;if(!r||r.source===void 0||r.target===void 0)continue;const o=n.getAttribute("stroke");if(!o||o==="transparent"||o==="none")continue;const i=n.getAttribute("fill");i&&i!=="none"||(t(r)?n.setAttribute("stroke-dasharray","6 4"):n.removeAttribute("stroke-dasharray"))}}function q3(e,{steps:t,size:n}){if(!e)return;const r=dc(e,"flow",n),o=_n("--ember","#EA5202"),i=_n("--surface","#FFFFFF"),s=_n("--slate","#69625B");for(const a of t){a.gap&&r.appendChild(ht("path",{d:`M${a.gap.from.x} ${a.gap.from.y} L${a.gap.to.x} ${a.gap.to.y}`,stroke:a.current?o:s,"stroke-width":a.current?2.4:1.4,"stroke-dasharray":"5 4",fill:"none",opacity:a.current?1:.7}));const l=ht("g",{transform:`translate(${a.x} ${a.y})`,class:`flow-chip${a.current?" current":""}`,"data-step":a.n});l.appendChild(ht("circle",{r:a.current?11:9,fill:a.current?o:i,stroke:a.current?i:s,"stroke-width":a.current?2:1.4})),l.appendChild(ht("text",{x:0,y:4,"text-anchor":"middle","font-size":a.current?11.5:10.5,"font-weight":700,fill:a.current?"#FFFFFF":s},`${a.n}${a.gap?"?":a.reply?"↩":""}`)),r.appendChild(l)}e.insertBefore(r,e.querySelector(":scope > .ghost"))}const B3=[{kind:"needs",label:"Needs",hint:"it uses what comes before"},{kind:"after",label:"After",hint:"order only"},{kind:"approve",label:"Approve first",hint:"you approve the step before"},{kind:"ask",label:"Ask first",hint:"the agent asks you"},{kind:"input",label:"Needs your input",hint:"it waits for something from you"}],H3="finished work is history: reopen the step first";function U3(e,{groups:t=[],group:n,kind:r="needs",frozen:o=!1}={}){const i=o?H3:void 0;if(e.type==="canvas")return[{id:"add",label:"Add a step here"}];if(e.type==="step"){const s=n&&n!==jt?n:void 0,a=t.filter(l=>l!==jt);return[{id:"rename",label:"Rename",key:"Enter",disabled:i},...a.map((l,u)=>({id:`group:${l}`,label:l,checked:l===s,disabled:i,...u===0?{section:"Move to group"}:{}})),{id:"group:top",label:"No group",checked:!s,disabled:i,...a.length?{}:{section:"Move to group"}},{id:"group:new",label:"New group…",disabled:i,ask:"Name the group"},{id:"delete",label:"Delete",key:"Delete",danger:!0,disabled:i,section:" "}]}return[{id:"label",label:"Label…",disabled:i},{id:"flip",label:"Flip direction",disabled:i},...B3.map((s,a)=>({id:`kind:${s.kind}`,label:s.label,hint:s.hint,checked:s.kind===r,disabled:i,...a===0?{section:"This arrow means"}:{}})),{id:"delete",label:"Delete",key:"Delete",danger:!0,disabled:i,section:" "}]}const K3=[{kind:"needs",label:"Waits for the answer",hint:"a call"},{kind:"async",label:"Does not wait",hint:"an event or a message"}];function la(e,{kind:t,external:n=!1,group:r,frames:o=[],folded:i=!1,container:s=!1,plan:a=null}={}){if(e.type==="canvas")return[{id:"add",label:"Add a box here"}];const l=(d,f)=>[...o.filter(p=>p.id!==d).map((p,h)=>({id:`${f}${p.id}`,label:p.label,checked:p.id===r,...h===0?{section:"Move into"}:{}})),{id:`${f}top`,label:"Nothing: top level",checked:!r||r===jt,...o.filter(p=>p.id!==d).length?{}:{section:"Move into"}},{id:`${f}new`,label:"A new frame…",ask:"Name the frame"}],u=a?[{id:"plan:planned",label:`Planned by ${a.id}`,hint:"it does not exist yet",checked:a.planned,section:`For the plan ${a.id}`},{id:"plan:retiring",label:`Removed by ${a.id}`,hint:"it goes when the plan is done",checked:a.retiring}]:[];if(e.type==="arrow")return[{id:"label",label:"Label…"},{id:"flip",label:"Flip direction",hint:"who uses whom"},...K3.map((d,f)=>({id:`kind:${d.kind}`,label:d.label,hint:d.hint,checked:d.kind===(t??"needs"),...f===0?{section:"This arrow"}:{}})),{id:"delete",label:"Delete",key:"Delete",danger:!0,section:" "}];const c=d=>Object.keys(da).map((f,p)=>({id:`${d}${f}`,label:da[f],checked:f===t,...s&&f!=="service"&&f!=="group"?{disabled:"it holds boxes: take them out first"}:{},...p===0?{section:"Change kind"}:{}}));return e.type==="frame"?[{id:"fold",label:i?"Unfold":"Fold",hint:i?"show what is inside":"hide what is inside"},{id:"rename",label:"Rename…",ask:"Rename the frame"},...["service","group"].map((d,f)=>({id:`frame-kind:${d}`,label:da[d],checked:d===t,...f===0?{section:"It is a"}:{}})),{id:n?"external:off":"external:on",label:"Someone else runs it",checked:n},...l(e.id??"","into:"),{id:"delete",label:"Remove the frame",hint:"what is inside stays",danger:!0,section:" "}]:[...i?[{id:"fold",label:"Unfold",hint:"show what is inside"}]:[],{id:"rename",label:"Rename",key:"Enter"},...c("boxkind:"),{id:n?"external:off":"external:on",label:"Someone else runs it",checked:n,section:" "},...l(e.id??"","into:"),...u,{id:"delete",label:"Delete",key:"Delete",danger:!0,section:" "}]}const Y3="http://www.w3.org/2000/svg";function bn(e,t={},n){const r=document.createElementNS(Y3,e);for(const[o,i]of Object.entries(t))r.setAttribute(o,String(i));return n!==void 0&&(r.textContent=n),r}const Zc=(e,t)=>getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t;function My(e,t){if(Math.abs(t.x-e.x)*.6>=Math.abs(t.y-e.y)){const a=t.x>=e.x?1:-1,l=e.x+a*e.w/2,u=t.x-a*t.w/2,c=(l+u)/2;return`M${l} ${e.y} H${c} V${t.y} H${u}`}const r=t.y>=e.y?1:-1,o=e.y+r*e.h/2,i=t.y-r*t.h/2,s=(o+i)/2;return`M${e.x} ${o} V${s} H${t.x} V${i}`}const Ey=(e,t,n=10)=>Math.abs(e.x-t.x)<(e.w+t.w)/2+n&&Math.abs(e.y-t.y)<(e.h+t.h)/2+n;function r1(e,t){if(!t.some(n=>Ey(e,n)))return e;for(let n=1;n<=8;n++)for(const r of[1,-1]){const o={...e,y:e.y+r*n*(e.h+14)};if(o.y-o.h/2>=0&&!t.some(i=>Ey(o,i)))return o}return e}function xl(e,t,n,r,o,i=null){e?.querySelector(":scope > .ghost")?.remove();const s=t&&t.applies?t:null;if(!e||!s&&!i)return null;t=s??{applies:!0,addedNodes:[],addedEdges:[],removedNodes:[],removedEdges:[],changedNodes:[]};const l=Zc("--ember","#EA5202"),u=Zc("--ember-deep","#B53D00"),c=Zc("--sans","sans-serif"),d=v=>$n(v,{...Xr,fontFamily:c}),f=new Map;for(const[v,k]of Object.entries(n.nodes)){const _=r.nodes[v];if(!_)continue;const{width:T,height:L}=d(k.label);f.set(v,{x:_.x+xt.x,y:_.y+xt.y,w:T,h:L})}const p=[...f.values()];for(const v of t.addedNodes){const{width:k,height:_}=d(v.label),T=r1({x:v.x+xt.x,y:v.y+xt.y,w:k,h:_},p);p.push(T),f.set(v.id,T)}const h=bn("svg",{class:"ghost",viewBox:`0 0 ${wr({canvas:o}).width} ${wr({canvas:o}).height}`,"aria-hidden":"true"});h.appendChild(bn("defs")).innerHTML=[l,u].map((v,k)=>`<marker id="ghost-head-${k}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="${v}"/></marker>`).join("");const y=[],g=(v,k,_=4)=>bn("rect",{x:v.x-v.w/2-_,y:v.y-v.h/2-_,width:v.w+_*2,height:v.h+_*2,rx:9,fill:"none",stroke:k,"stroke-width":1.6,"stroke-dasharray":"5 3"});for(const v of t.removedEdges){const k=f.get(v.from),_=f.get(v.to);k&&_&&y.push(k,_),k&&_&&h.appendChild(bn("path",{d:My(k,_),fill:"none",stroke:u,"stroke-width":3,"stroke-dasharray":"2 5",opacity:.85}))}for(const v of t.removedNodes){const k=f.get(v);k&&(y.push(k),h.appendChild(g(k,u)),h.appendChild(bn("path",{d:`M${k.x-k.w/2} ${k.y-k.h/2} L${k.x+k.w/2} ${k.y+k.h/2} M${k.x+k.w/2} ${k.y-k.h/2} L${k.x-k.w/2} ${k.y+k.h/2}`,stroke:u,"stroke-width":1.6,opacity:.7})))}for(const v of t.changedNodes){const k=f.get(v.id);if(k&&(y.push(k),h.appendChild(g(k,l)),v.label!==void 0)){const _=d(v.label),T=bn("g",{transform:`translate(${k.x} ${k.y+k.h/2+15})`});T.appendChild(bn("rect",{x:-_.width/2,y:-10,width:_.width,height:20,rx:6,fill:l})),T.appendChild(bn("text",{x:0,y:4,"text-anchor":"middle","font-size":11,"font-family":c,"font-style":"italic",fill:"#FFFFFF"},v.label)),h.appendChild(T)}}for(const v of t.addedEdges){const k=f.get(v.from),_=f.get(v.to);k&&_&&y.push(k,_),k&&_&&h.appendChild(bn("path",{d:My(k,_),fill:"none",stroke:l,"stroke-width":1.8,"stroke-dasharray":"6 4","marker-end":"url(#ghost-head-0)"}))}for(const v of t.addedNodes){const k=f.get(v.id);k&&(y.push(k),h.appendChild(bn("rect",{x:k.x-k.w/2,y:k.y-k.h/2,width:k.w,height:k.h,rx:7,fill:l,"fill-opacity":.12,stroke:l,"stroke-width":1.6,"stroke-dasharray":"5 3"})),h.appendChild(bn("text",{x:k.x,y:k.y+4,"text-anchor":"middle","font-size":Xr.fontSize,"font-family":c,fill:u},v.label.length>26?`${v.label.slice(0,25)}…`:v.label)))}const m=i?f.get(i):void 0;if(m&&h.appendChild(bn("rect",{x:m.x-m.w/2-5,y:m.y-m.h/2-5,width:m.w+10,height:m.h+10,rx:10,fill:"none",stroke:l,"stroke-width":2.4})),e.appendChild(h),!s||!y.length)return null;const b=Math.min(...y.map(v=>v.x-v.w/2)),w=Math.max(...y.map(v=>v.x+v.w/2)),x=Math.min(...y.map(v=>v.y-v.h/2)),S=Math.max(...y.map(v=>v.y+v.h/2));return{x:b,y:x,w:w-b,h:S-x}}const G3=["label","group","x","y","kind","external"],Ay=e=>typeof e=="number"?Math.round(e):e;function tf(e,t){const n=new Map(e.steps.map(y=>[y.id,y])),r=new Map(t.steps.map(y=>[y.id,y])),o=[],i=[];for(const[y,g]of r){const m=n.get(y);if(!m){o.push(g);continue}const b={};for(const w of G3)Ay(m[w])!==Ay(g[w])&&(b[w]=g[w]);Object.keys(b).length&&i.push({id:y,...b})}const s=[...n.keys()].filter(y=>!r.has(y)),a=y=>`${y.source}\0${y.target}`,l=new Map(e.depends.map(y=>[a(y),y])),u=new Map(t.depends.map(y=>[a(y),y])),c=new Set(s),d=[],f=[];for(const[y,g]of u){const m=l.get(y);m?((m.label??"")!==(g.label??"")||(m.kind??"needs")!==(g.kind??"needs")||(m.tech??"")!==(g.tech??""))&&f.push({source:g.source,target:g.target,label:g.label,kind:g.kind??"needs",...g.tech!==void 0?{tech:g.tech}:{}}):d.push(g)}const p=[...l].filter(([y,g])=>!u.has(y)&&!c.has(g.source)&&!c.has(g.target)).map(([,y])=>({source:y.source,target:y.target})),h={};return(o.length||i.length||s.length)&&(h.steps={...o.length?{insert:o}:{},...i.length?{update:i}:{},...s.length?{remove:s}:{}}),(d.length||f.length||p.length)&&(h.depends={...d.length?{insert:d}:{},...f.length?{update:f}:{},...p.length?{remove:p}:{}}),Object.keys(h).length?h:null}const V3=new Set(["apply","type","inverts","cardinality","scope","into","constrain","guide","stage","advance","target","targets","table"]),X3=new Set(["build","glyph","xKey","yKey","discreteScale","rawChannels","table"]),ca=e=>" ".repeat(e),Ty=e=>`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`,J3=e=>e&&typeof e=="object"&&typeof e.apply=="function"&&typeof e.type=="string",Oy=["name","channels","field","gesture","mode","strategy","threshold","when"],Z3=([e],[t])=>(Oy.indexOf(e)+1||99)-(Oy.indexOf(t)+1||99)||(e<t?-1:1),Q3=(e,t)=>t==null||t===!1||Array.isArray(t)&&!t.length||e==="pick"&&t==="direct"||e==="gesture"&&t==="drag"||e==="threshold"&&t===0;function Ma(e,t,n={}){if(typeof e=="function")return`ƒ ${e.name||"anonymous"}`;if(typeof e=="string")return Ty(e);if(e===null||typeof e!="object")return String(e);if(e instanceof Date)return e.toISOString();if(J3(e)){const s=e,a=Object.entries(s).filter(([l,u])=>!V3.has(l)&&!Q3(l,u)).sort(Z3);return`${s.type}(${a.length?`{ ${a.map(([l,u])=>`${l}: ${Ma(u,t,{one:!0})}`).join(", ")} }`:""})`}if(Array.isArray(e)){if(!e.length)return"[]";const s=e.map(l=>Ma(l,t+1,{one:!0})),a=`[${s.join(", ")}]`;return n.one&&a.length<=76&&!s.some(l=>l.includes(`
12
+ ${t5(e5(t))}`);return}for(const i of g0(t))r[i]||ge(`schema:extra:${i}`,`${n} has a column "${i}" that the schema does not declare. The schema is the contract of the elicited dataset, so every column belongs in it — an undeclared one gets no domain, no type and no creation default, so a row made by an edit will be missing it. Declare it: schema: { ${JSON.stringify(i)}: { type: ${JSON.stringify(qf(al(t,i)))} } }.`);for(const[i,s]of Object.entries(r)){if(!s)continue;const a=al(t,i);if(!s.type){s.domain&&ge(`schema:notype:${i}`,`schema.${i} declares a domain but no \`type\`. A field's measurement type is required — without it the type is inferred from the data and can disagree with the domain you declared. Add type: ${JSON.stringify(y0(s.domain))}.`);continue}const l=a.find(d=>n5(d,s.type));if(l!==void 0){ge(`schema:type:${i}`,`${n} has a value in "${i}" (${JSON.stringify(l)}) that contradicts its declared type "${s.type}". The schema owns the data type; either fix the value or declare the type the data actually has.`);continue}const u=s.domain;if(!u||s.open)continue;const c=a.find(d=>r5(d,s.type,u));c!==void 0&&ge(`schema:domain:${i}`,`${n} has a value in "${i}" (${JSON.stringify(c)}) outside its declared domain ${JSON.stringify(s.domain)}. The domain is what the axis spans, so that row draws clipped or off-plot. Widen the domain or fix the data.`)}}function jc(e,t,n="data"){const r=Object.keys(e.tables);for(const o of r){const i=r.length>1?`${n}.${o}`:n;o5(e.tables[o].fields,t[o]||[],i),s5(e,t,o,i),e.tables[o].role==="links"&&i5(e,t,o,i)}}function i5(e,t,n,r){const o=e.tables[n];if(o.multi!==!1&&o.selfLoops!==!1)return;const i=Object.keys(o.fields).filter(u=>o.fields[u]&&o.fields[u].type==="ref");if(i.length<2)return;const[s,a]=i,l=new Set;for(const u of t[n]||[]){if(!u)continue;const c=u[s],d=u[a];if(o.selfLoops===!1&&c!=null&&c===d&&ge(`schema:selfLoops:${n}`,`${r} has a link from ${JSON.stringify(c)} to itself, but the "${n}" table declares selfLoops: false. Remove the row, or declare selfLoops: true.`),o.multi===!1){const f=o.directed===!1&&String(d)<String(c)?[d,c]:[c,d],p=JSON.stringify(f);l.has(p)&&ge(`schema:multi:${n}`,`${r} links ${JSON.stringify(c)} and ${JSON.stringify(d)} more than once, but the "${n}" table declares multi: false. Remove the duplicate, or declare multi: true.`),l.add(p)}}}function s5(e,t,n,r){const o=e.tables[n].fields,i=t[n]||[];if(i.length)for(const[s,a]of Object.entries(o)){if(!a||a.type!=="ref")continue;const l=Kf(e,a);if(!l){ge(`schema:ref:${n}:${s}`,`schema.${n}.${s} is a \`ref\` but its target cannot be resolved${a.to?` (to: ${JSON.stringify(a.to)})`:""}. A ref points at a table's \`key: true\` column — declare one, or name the column with \`to\`. Nothing references anything until then.`);continue}const u=new Set(p0(e,a,t)),c=al(i,s).find(d=>!u.has(d));c!==void 0&&ge(`schema:dangling:${n}:${s}`,`${r} has a value in "${s}" (${JSON.stringify(c)}) that names no row of "${l.table}" (its ${JSON.stringify(l.field)}). A \`ref\` must name an existing identity — a link to a node that isn't there connects nothing, and draws nothing.`)}}function Mp(e){return e==null?{}:typeof e=="function"?{instance:e}:typeof e=="string"?{type:e}:e}function Wc(e,t,n,r){const o=n.schema||{},i=n.schemaSpec||null,s=n.scales||{},a=m=>t&&(t[m.table]||t[n.schemaSpec?n.schemaSpec.primary:""])||[],l=m=>{const b=i&&i.tables[m.table];return b&&b.fields||o},u={},c=m=>u[m]||(u[m]={fields:[],fieldRefs:[],schemas:[],undeclared:[],values:[]}),d={},f={},p=(m,b)=>{const w=_t(m),x=w||uo(m,b&&b.field!=null?b.field:void 0);return(d[x]||(d[x]=new Set)).add(m),f[x]=w||m,x};for(const m of e){const b=WM(m),w=m.discreteScale||"band",x=new Set(m.rawChannels||[]);for(const[S,v]of Object.entries(b)){if(!v||v.scale===null||Gr(v)||x.has(S))continue;if(typeof v.fn=="function"&&v.field==null){(v.scale!==void 0||v.type!==void 0)&&ge(`fnopt:${S}`,`channel "${S}" is derived ({ fn }) — its result is used as-is in visual space, so its "${v.scale!==void 0?"scale":"type"}" is ignored. Drop it, or use a field channel if you want a scale.`);continue}for(const[_,T]of[["domain","the spec's schema"],["range","this channel's `scale`"]])v[_]!==void 0&&ge(`stray:${_}:${S}`,`channel "${S}" declares "${_}", which is ignored. Move it to ${T}: ${_==="range"?"scale: { range: [...] }":"schema: { <field>: { domain: [...] } }"}.`);const k=c(p(S,v));if(k.measure==null&&v.type!=null&&(k.measure=v.type),k.scaleOpt==null&&v.scale!=null&&(k.scaleOpt=v.scale),k.discretePref!=="band"&&(k.discretePref=w),k.countAxis==null&&m.countAxis&&(k.countAxis=m.countAxis),v.field!=null){k.fields.includes(v.field)||k.fields.push(v.field);const _=m.table;_!=null&&!k.fieldRefs.some(L=>L.table===_&&L.field===v.field)&&k.fieldRefs.push({table:_,field:v.field});const T=l(m)[v.field];T&&T.type==="ref"&&i?k.schemas.push({type:"categorical",domain:p0(i,T,t),open:!0}):T?k.schemas.push(T):k.undeclared.includes(v.field)||k.undeclared.push(v.field);for(const L of a(m))k.values.push(L[v.field])}else v.datum!==void 0&&k.values.push(v.datum)}}const h={},y={},g={};for(const m of Object.keys(u)){const b=f[m]||m;y[m]=g[b]||0,g[b]=y[m]+1}for(const[m,b]of Object.entries(u)){const w=f[m]||m,x=b.values.some($=>$!=null);if(!b.fields.length&&!x)continue;const S=b.schemas;for(const $ of b.undeclared)ge(`schema:${$}:${w}`,`field "${$}" is encoded on channel "${w}" but not declared in schema; inferring its type and domain from data. Declare it in the Elicit spec's schema — the schema is the contract of the elicited dataset.`);if(!S.length&&!x)throw new Error(`[elicit] cannot resolve a scale for channel "${w}": field(s) ${b.fields.map($=>`"${$}"`).join(", ")} have no schema entry and there is no data to infer from. Declare them in the Elicit spec's schema.`);const v={...Mp(b.scaleOpt),...Mp(s[w])},k=S.map($=>$.type).filter(Boolean);new Set(k).size>1&&ge(`measure:${w}`,`fields ${b.fields.map($=>`"${$}"`).join(", ")} share channel "${w}" but declare different schema types (${[...new Set(k)].join(", ")}). Using "${k[0]}".`);const _=b.measure||k[0]||qf(b.values),T=v.type||PM(w,_,b.discretePref||"band"),L=[];for(const $ of S)$.domain&&L.push($.domain);const N=zM(_,L)||c0(T,b.values),I=!!_t(w);let O=v.range||Ai(v.scheme,T,N.length)||u0(w,T,r,n.theme,{measure:_,index:y[m]||0,count:N.length,countAxis:b.countAxis});v.reverse&&Array.isArray(O)&&(O=[...O].reverse());const M=v.instance?EM(v.instance,{range:v.range?void 0:O,positional:I,domain:N}):ju({...v,type:T,domain:N},O);if(M){M.fields=b.fields,M.fieldRefs=b.fieldRefs,h[m]=M;for(const $ of d[m]||[])h[$]===void 0&&(h[$]=M)}}if(h.count===void 0){const m=e.find(b=>b&&b.countAxis&&b.countPitch>0);if(m){const b=m.countAxis==="x"?r.width:r.height,w=Math.max(1,Math.floor(b/m.countPitch)),x=w*m.countPitch,S=ju({type:"linear",domain:[0,w]},m.countAxis==="x"?[0,x]:[r.height,r.height-x]);S&&(h.count=S)}}return h}const a5={"albers-usa":()=>PS(),albers:()=>mm(),"azimuthal-equal-area":()=>zS(),"azimuthal-equidistant":()=>DS(),"conic-conformal":()=>qS(),"conic-equal-area":()=>Qa(),"conic-equidistant":()=>US(),"equal-earth":()=>YS(),equirectangular:()=>BS(),gnomonic:()=>GS(),mercator:()=>jS(),orthographic:()=>XS(),stereographic:()=>JS(),"transverse-mercator":()=>ZS(),identity:()=>VS()};function l5(e){if(typeof e=="function"&&typeof e.stream!="function")return e();if(typeof e=="string"){const t=e.toLowerCase(),n=a5[t];if(!n)throw new Error(`[elicit] unknown projection type: ${e}`);return n()}return e}const Ep=new WeakSet;function c5(e){if(!oi()||!e||typeof e!="object"||Ep.has(e))return;Ep.add(e);const n=(e.type==="FeatureCollection"&&Array.isArray(e.features)?e.features:[e]).filter(o=>{const i=o&&o.type==="Feature"?o.geometry:o;return!i||i.type!=="Polygon"&&i.type!=="MultiPolygon"?!1:iS(i)>Math.PI});if(!n.length)return;const r=n.map((o,i)=>o.properties&&(o.properties.name||o.properties.NAME)||`feature ${i}`).slice(0,3);ge(`rings:${r.join(",")}`,`projection domain has ${n.length} polygon(s) with reversed ring winding (${r.join(", ")}${n.length>3?", …":""}). d3 reads these as covering the whole globe, so the map fits the world and your features shrink to a dot. Rewind the exterior rings counterclockwise (RFC 7946).`)}function na(e){const t=ES(e),n=typeof e.invert=="function";return{apply(r){if(!r||r[0]==null||r[1]==null)return null;const o=e(r);return!o||o[0]==null||o[1]==null||!Number.isFinite(o[0])||!Number.isFinite(o[1])?null:o},invert(r){if(!n||!r||r[0]==null||r[1]==null)return null;const o=e.invert(r);return!o||o[0]==null||o[1]==null||!Number.isFinite(o[0])||!Number.isFinite(o[1])?null:o},path(r){return r==null?null:t(r)},invertible:n,raw:e}}function m0(e,t){if(e==null)return null;if(typeof e=="object"&&typeof e.apply=="function"&&typeof e.invert=="function"&&e.raw)return e;if(typeof e=="function"&&typeof e.stream=="function"||typeof e=="object"&&typeof e.stream=="function")return na(e);let n={},r=e,o,i=0,s,a,l,u;if(typeof e=="object"&&e!==null){if({type:r,domain:o,inset:i=0,insetTop:s=i,insetRight:a=i,insetBottom:l=i,insetLeft:u=i,...n}={type:void 0,domain:void 0,...e},r==null&&typeof e.stream=="function")return na(e);if(r==null)return null}else s=a=l=u=0;const c=l5(r),{rotate:d,parallels:f,precision:p=.15,clipAngle:h}=n;p!=null&&typeof c.precision=="function"&&c.precision(p),d!=null&&typeof c.rotate=="function"&&c.rotate(d),f!=null&&typeof c.parallels=="function"&&c.parallels(f),h!=null&&typeof c.clipAngle=="function"&&c.clipAngle(h);const y=Math.max(0,t.width-(u||0)-(a||0)),g=Math.max(0,t.height-(s||0)-(l||0));if(o!=null&&typeof c.fitExtent=="function")c5(o),c.fitExtent([[u||0,s||0],[(u||0)+y,(s||0)+g]],o);else if(typeof c.fitSize=="function"){try{c.fitSize([y,g],{type:"Sphere"})}catch{}if(u||s){const m=c.translate();c.translate([m[0]+(u||0),m[1]+(s||0)])}}return na(c)}function ur(e,t,n){if(!e||t==null||n==null)return null;const r=e.apply([+t,+n]);return r?{x:r[0],y:r[1]}:null}function Fr(e,t){if(!e||!t)return null;const n=e.invert([t.x,t.y]);return n?{lon:n[0],lat:n[1]}:null}function b0(e,t,n,r,o){if(!e)return null;const i=[ur(e,t,n),ur(e,t,o),ur(e,r,n),ur(e,r,o)];if(i.some(f=>!f))return null;const s=i.map(f=>f.x),a=i.map(f=>f.y),l=Math.min(...s),u=Math.max(...s),c=Math.min(...a),d=Math.max(...a);return{x:l,y:c,width:u-l,height:d-c}}const w0=["channels","id","edits","table"],x0=["fill","stroke","strokeWidth","opacity","fillOpacity","strokeOpacity","size","symbol","text","fontSize","textAnchor","lineAnchor","dx","dy","angle"],v0=["id","edit","edits","field","table"],k0=["id"],st={arc:["outerRadius","innerRadius","padAngle","arc","start","end","handles","handleSize","handleColor"],area:["orientation","curve","handles","handleSize","handleColor","connect"],bar:["orientation","stack","handles","handleSize","handleColor"],composite:["parts","discreteScale"],curve:["orientation","length"],dotStack:["orientation","gap","ghost","label"],ellipse:[],face:["ink"],geoBasemap:["geojson","stroke","strokeWidth","fill"],geoTile:["url","subdomains","tileSize","minZoom","maxZoom","zoomOffset","attribution","attributionSize","opacity"],geoPoint:[],geoPolygon:[],geoLine:["curve","handles","handleSize","handleColor","connect","showVertices"],geoText:["format"],geoRect:[],line:["orientation","curve","handles","handleSize","handleColor","connect"],link:["curve","curvature","spread","arrow","arrowSize","inset","sourceInset","targetInset","loopRadius","format","labelBackground","labelPadding","labelRadius","labelOpacity","cornerRadius","sourceSide","targetSide","sourceOffset","targetOffset","handles","handleSize","handleColor"],needle:["length","handles","handleSize","handleColor","baseWidth"],node:["dy","shape","format"],point:["shape"],rect:["orientation","width","height","rx"],rule:["orientation","strokeDasharray","discreteScale"],sticker:["padding","radius","maxWidth","minWidth","minHeight","lineHeight","fontFamily","format"],text:["orientation","format","wrap","lineHeight"],tick:["orientation","inset","length"],trend:["anchor","probe","grip","handles","handleSize","handleColor"],trendBand:["render","levels","samples","seed","sigma","distribution","anchor","probe","grip","handles","handleSize","handleColor"],waffle:["orientation","unit","multiple","gap","shape","showEmpty","emptyFill"]},As={axis:["channel","anchor","transform","ticks","tickValues","tickFormat","tickSize","title","stroke","fill","fontSize","grid","handleColor","handleSize"],grid:["channel","ticks","tickValues","stroke","strokeWidth"],legend:["channel","anchor","orient","swatchSize","gap","labelWidth","rampLength","rampThickness","ticks","tickFormat","title","row","stroke","fill","fontSize","handleColor","handleSize"],axisRadial:["channel","channels","radius","innerRadius","bandWidth","ticks","tickValues","tickFormat","tickSize","labelOffset","bands","title","arc","orient","start","end","labelFill","stroke","strokeWidth","fontSize"]},Ts={rule:["x","y","stroke","strokeDasharray","strokeWidth","opacity","label"],region:["x","y","fill","opacity","stroke","label"],remaining:["field","total","unit","format","anchor","label","fill","fontSize"],proximity:["target","stroke","strokeDasharray","strokeWidth","opacity"],prompt:["y"],optionRings:["labelOffset","radius"],cellGrid:["pad"],sliderTrack:["format"],crosshair:["x","y"],custom:[]},S0=["type","name","gesture","channel","channels","when","pick","threshold","scope","into","constrain","guide","stage","advance","target","cardinality","inverts","table","inline","multiline","defaults","apply","targets"],$0={move:["mode"],moveSpan:[],brushSpan:["edgeInset"],brushRect:["edgeInset","resize","move"],slide:["axis","increase","extent","mode"],resize:[],rotate:["relativeTo","pivot","fold"],cycle:[],create:[],toggle:[],remove:[],set:[],editText:[],rank:[],select:["exclusive","toggle","multi"],custom:[],"line.anchor":["series"],"line.newSeries":["along","value","samples","series"],"line.draw":["along","value","samples","minDist","series"],"line.sweep":["mode"],"line.removeSeries":["series"],"axis.scale":["field","mode"],"scale.addCategory":["field","mode"],"scale.renameCategory":["field","mode"],"scale.removeCategory":["field","mode"],"legend.category":[],"legend.value":[],"stack.cut":["label","categoryField"],"stack.edge":[],"stack.merge":[],"trend.intercept":["anchor","probe"],"trend.slope":["anchor","probe"],"trend.interceptSpread":["anchor","probe"],"trend.slopeSpread":["anchor","probe"],"waffle.fill":[],"network.connect":[],"network.rewire":[],"network.reverse":[],"geo.move":[],"geo.create":[],"geo.dragVertex":[],"geo.removeVertex":["min"],"geo.draw":["minDist"],"geo.brush":["move","edgeInset"],"geo.createRect":["width","height","edgeInset"]},_0={clamp:["min","max","field"],snap:["step","origin","field"],count:["max","strategy"],unique:["field","max","strategy"],maintainSum:["total","field","strategy"],ordering:["field","strategy"],monotonic:["field","along","dir","series"],spacing:["field","min","series"],custom:[]};function u5(e,t,n){if(!(!e||!t||!n))for(const r of Object.keys(n)){const o=n[r];if(!o||o.field!==e)continue;const i=t[uo(r,e)]||t[r];if(i){if(i.domainConfig)return i.domainConfig;if(typeof i.domain=="function")return i.domain()}}}const f5={targetSum:"the total is `total` — maintainSum({ total: 100 }) — the same word guides.remaining uses.",fields:'the columns a rule is about are `field`, singular, which takes one name or an ordered list: ordering({ field: ["lo", "mean", "hi"] }).',lower:'ordering takes its columns as one ordered list: ordering({ field: ["lo", "hi"] }).',upper:'ordering takes its columns as one ordered list: ordering({ field: ["lo", "hi"] }).',mode:"what a constraint does when its rule is broken is `strategy` (cap | normalize | redistribute | push | block | reject | replace)."};function Rr(e,t){if(!t||!oi())return t;const n=_0[e]||[];for(const r of Object.keys(t)){if(n.includes(r))continue;const o=f5[r];ge(`constraintopt:${e}:${r}`,o?`${e}({ ${r}: … }): ${o}`:`${e}({ ${r}: … }) is not an option this constraint reads, so it is ignored. ${e} options are: ${n.slice().sort().join(", ")}.`)}return t}function d5(e){return{type:e.type,field:e.field,options:e.options||{},...e.table!=null?{table:e.table}:{},...typeof e.guide=="function"?{guide:e.guide}:{},apply:e.apply}}function Vt(e,t={}){return d5({...t,type:t.type||"custom",apply:e})}function h5(e,t,n,r){if(typeof e=="function")return e(t,n,r||{});const o=e;r=r||{};const i=Array.isArray(o.field)?o.field[0]:o.field,s=i??r.field,a=r.activeIndex!=null?r.activeIndex:null,l=a!=null&&a>=0&&a<t.length,u=l?t[a]:void 0,c={data:t,oldData:n,activeIndex:a,active:u,field:s,fields:Array.isArray(o.field)?o.field:s!=null?[s]:[],value:u&&s!=null?u[s]:void 0,domain:u5(s,r.scales,r.markChannels),table:r.table,tables:r.tables},d=o.apply(c);return d===!1||d===!0||d===void 0||Array.isArray(d)?d:typeof d=="number"?!l||s==null?t:t.map((f,p)=>p===a?{...f,[s]:d}:f):d&&typeof d=="object"&&l?t.map((f,p)=>p===a?{...f,...d}:f):t}function ll(e){return e==null||typeof e!="object"?JSON.stringify(e)||"null":JSON.stringify(Object.keys(e).sort().map(t=>[t,e[t]]))}const p5=(e,t)=>e===t||e!=null&&t!=null&&ll(e)===ll(t);function y5(e,t,n){return e==null||e===!1?null:typeof e=="function"?(r,o)=>!!e(r,o,n):e===!0||e==="seed"?(r,o)=>o<t():(console.warn(`[elicit] spec.lock: expected "seed", true, or a (datum, index) => boolean predicate; got ${JSON.stringify(e)}. Nothing is locked.`),null)}function g5(e){return Vt(({data:t,oldData:n})=>{if(!n||!n.length)return;if(t.length<n.length){const o=new Map;if(n.forEach((i,s)=>{if(!e(i,s))return;const a=ll(i);o.set(a,(o.get(a)||0)+1)}),!o.size)return;for(const i of t){const s=ll(i),a=o.get(s);a&&(a===1?o.delete(s):o.set(s,a-1))}return o.size===0?void 0:!1}let r=null;for(let o=0;o<n.length;o++){const i=n[o];e(i,o)&&(p5(t[o],i)||(r=r||t.slice(),r[o]=i))}return r||void 0},{type:"lock"})}function m5(e,t,n,r){if(e.index!=null){const s=n[e.index];return s!=null&&r(s,e.index)}if(e.series===void 0)return!1;const o=t.seriesKey||null;let i=!1;for(let s=0;s<n.length;s++){const a=n[s];if(!(o&&a[o]!==e.series)&&(i=!0,!r(a,s)))return!1}return i}function b5(e){return!!(e&&typeof e=="object"&&typeof e.apply=="function"&&e.gesture)}function va(e){const t=[],n=e.channels||{};for(const[r,o]of Object.entries(n))if(o&&o.edit){if(typeof o.fn=="function"&&o.field==null)continue;const i=o.edit;t.push(i.channels?i:{...i,channels:[r]})}for(const r of e.edits||[])t.push(r);return t}function w5(e,t){const n=e.channels||{},r=t?t(e):`"${e.id||"?"}"`,o=e.id||e.type||"?";for(const[i,s]of Object.entries(n)){const a=`${o}:${i}`;i==="edit"||b5(s)?ge(a,`mark ${r} has a misplaced edit under channels.${i}. Attach edits on a channel (y: { field, edit: move() }) or at mark level (edits: [move({ channels: ['x','y'] })]). A bare channels.edit key is ignored.`):s&&s.edit&&typeof s.fn=="function"&&s.field==null?ge(a,`mark ${r} puts an edit on the derived channel "${i}" ({ fn }). A derived channel is read-only — it recomputes from the committed rows on every render, so the edit is ignored. Attach the edit to the source field's channel (e.g. x: { field: "x", edit: move() }); the fn re-derives automatically after each commit.`):s&&s.edit&&s.field==null&&typeof s.fn!="function"&&ge(`${a}:nofield`,`mark ${r} puts an edit on channel "${i}", which has no field (it is a constant: ${s.value!==void 0?"{ value }":"{ datum }"}). An edit writes back to a COLUMN, so give the channel a field (${i}: { field: "…", edit: … }) — otherwise there is nothing to elicit.`)}}function Ti(e,t,n,r=void 0){const o=!!(r&&r.views==="scale"),i=r&&r.field!=null?r.field:void 0,s=o||!t||Object.keys(t).length===0,a=[];for(const l of e||[]){const u=t&&t[l];let c=u&&u.field;if(c==null&&s)if(i!=null)c=i;else{const f=n[l],p=f&&f.fields;c=p&&p[0]}if(c==null)continue;const d=n[uo(l,c)]||n[l]||void 0;a.push({name:l,field:c,scale:d})}return a}const M0=Symbol("elicit.unverifiedOptions"),x5=e=>e==null?[]:Array.isArray(e)?e:[e],Vr=(e,t)=>n=>e(n)&&(typeof t=="function"?!!t(n):!0);function Kl(e,t,n){const{pick:r,...o}=e||{};return r!=null&&r!==n&&ge(`fixedpick:${t}`,`${t} is bound to the "${n}" driver — it reads a zone lock only that driver writes — so { pick: "${r}" } is ignored. Drop it, or use an edit that supports the strategy you want (move/moveSpan take any pick).`),o}function je(e){const{channel:t,channels:n,...r}=e,o=$0[e.type],i=o?Object.keys(r).filter(s=>!S0.includes(s)&&!o.includes(s)):[];return{...r,...i.length?{[M0]:i}:{},type:e.type,name:e.name||null,gesture:e.gesture||"drag",channels:t?[t]:n||null,when:e.when||null,pick:e.pick||"direct",threshold:e.threshold!=null?e.threshold:0,scope:e.scope||null,into:e.into||null,constrain:x5(e.constrain),guide:e.guide||null,stage:e.stage!=null?e.stage:null,advance:e.advance!==!1,target:e.target||void 0,cardinality:e.cardinality||null,inverts:!!e.inverts,apply:e.apply}}function cl(e,t){const n=e.when;return{...e,when:r=>{const o=r.node&&r.node.channel;return o!=null&&o!==t?!1:n?n(r):!0}}}function Yl(e,t){if(!t)return 0;const n=new Set((e||[]).map(o=>o[t]));let r=0;for(;n.has(r);)r++;return r}function Yf(e,t,n,{open:r=!1,label:o="Category"}={}){if(!t)return;const i=new Set((e||[]).map(a=>a[t]));for(const a of n||[])if(!i.has(a))return a;if(!r)return;let s=(n||[]).length+1;for(;i.has(`${o} ${s}`)||(n||[]).includes(`${o} ${s}`);)s++;return`${o} ${s}`}function Fn(e,{defaults:t={},seed:n={},label:r}={}){const o={...Es(e.schema),...t,...n};let i=Object.keys(n).length>0;for(const a of e.channels){const l=ho(a,e.pointer);l!==void 0&&(o[a.field]=l,i=!0)}if(!i)return;const s=v5(e.schema);if(s&&o[s]==null){const a=e.schema&&e.schema[s]||{},l=Yf(e.data,s,a.domain||[],{open:a.open!==!1,label:r||"Item"});if(l===void 0)return;o[s]=l}return o}function v5(e){if(!e)return null;for(const[t,n]of Object.entries(e))if(n&&n.key===!0)return t;return null}function Pr(e){return e.node?e.node:e.index==null||!e.marks?null:e.marks.find(t=>t&&t.index===e.index)||null}function Rn(e){return e?e.cx!=null&&e.cy!=null?{cx:e.cx,cy:e.cy}:e.x!=null&&e.width!=null?{cx:e.x+e.width/2,cy:e.y+(e.height||0)/2}:e.x1!=null&&e.y1!=null&&e.x2!=null&&e.y2!=null?{cx:(e.x1+e.x2)/2,cy:(e.y1+e.y2)/2}:e.x!=null&&e.y!=null?{cx:e.x,cy:e.y}:null:null}const k5=.01,S5=.1;function Hu(e,t,n,r=!1){if(!e||!n||!e.invertible)return t;if(e.kind==="band"||e.kind==="point"){const a=e.domain();if(a.length<2)return t;const l=e.invertValue(t),u=a.indexOf(l);if(u<0)return t;const c=e.encode(a[a.length-1])>e.encode(a[0]),d=u+(c?n:-n);return d<0||d>=a.length?t:e.encode(a[d])}const[o,i]=oo(e),s=(i-o)*(r?S5:k5);return Math.max(o,Math.min(i,t+n*s))}const xn=e=>e instanceof Date?e.getTime():e;function E0(e,t,n,r,o){if(n===t)return;let i=(e-t)/(n-t);return i=i<0?0:i>1?1:i,r+i*(o-r)}function A0(e){const t=e&&e.scale&&e.scale.domainConfig;return Array.isArray(t)&&t.length?[t[0],t[t.length-1]]:[0,1]}function T0(e,t){const n=e&&e.scale&&typeof e.scale.domain=="function"?e.scale.domain():null;if(Array.isArray(n)&&n.length)return n;const r=e&&e.field!=null&&t?t[e.field]:null,o=r&&r.domain;return Array.isArray(o)&&o.length?o:null}function ho(e,t,n=null){if(!e||!e.scale||!e.scale.invertible)return;const r=BM(e.name,t,n);if(r!==void 0)return e.scale.invertValue(r)}function Gl(e,t,n,r){if(!e||!t||!n||!t.scale||!n.scale||!t.scale.invertible||!n.scale.invertible)return;const o=_t(t.name);if(!o||o!==_t(n.name))return;const i=o==="x"?r.x:r.y,s=o==="x"?e.width:e.height;if(i===void 0||s==null)return;let a=i-s/2,l=i+s/2;const[u,c]=oo(t.scale),d=Math.min(u,c),f=Math.max(u,c),p=f-d;return s>=p?(a=d,l=f):(a<d&&(l+=d-a,a=d),l>f&&(a-=l-f,l=f)),{a:t.scale.invertValue(a),b:n.scale.invertValue(l)}}const O0=["filter","opacity","fill","stroke","strokeWidth","cursor"],$5=["hovered","selected","grabbed"],ul={hovered:{outline:{color:"#ff9800",width:2,pad:5,dash:null,opacity:.65}},selected:{outline:{color:"#ff9800",width:2.5,pad:5,dash:null,opacity:.95}},grabbed:{filter:"brightness(0.82)"}},_5={color:"#ff9800",dash:"2 4",width:1,opacity:.45};function M5(e,t){const n=t||{};if(e===!1)return{enabled:!1};if(typeof e=="string")return{...n,enabled:!0,filter:e};const r=e||{},o=r.outline===!1?null:n.outline||r.outline?{...n.outline,...r.outline||{}}:null;return{...n,...r,outline:o,enabled:!0}}function E5(e={},t=ul){const n=e||{},r=t||ul,o={};for(const i of $5)o[i]=M5(n[i],r[i]);return o}function Uu(e){if(!e||e.enabled===!1)return null;const t={};let n=!1;for(const r of O0)e[r]!=null&&(t[r]=e[r],n=!0);return n?t:null}function A5(e){const t={};let n=!1;for(const r of e||[]){const o=Uu(r);o&&(Object.assign(t,o),n=!0)}return n?t:null}function Gf(e,t){if(!e||!t||t.enabled===!1||!t.outline)return[];if(e.effectShape)return Gf({...e.effectShape,...e.angle?{angle:e.angle}:{}},t);const{color:n,width:r,pad:o,dash:i,opacity:s}=t.outline,a={fill:"none",stroke:n,strokeWidth:r,opacity:s,...i?{strokeDasharray:i}:{},...e.angle?{angle:e.angle}:{},guide:!0,effect:!0,pointerEvents:"none"};if(e.type==="circle")return[{type:"circle",cx:e.cx,cy:e.cy,r:(e.r||5)+o,...a}];if(e.type==="ellipse")return[{type:"ellipse",cx:e.cx,cy:e.cy,rx:(e.rx!=null?e.rx:5)+o,ry:(e.ry!=null?e.ry:5)+o,...a}];if(e.type==="rect")return[{type:"rect",x:e.x-o,y:e.y-o,width:e.width+o*2,height:e.height+o*2,...a}];if(e.type==="line"){const l=Math.min(e.x1,e.x2),u=Math.min(e.y1,e.y2);return[{type:"rect",x:l-o,y:u-o,width:Math.abs(e.x2-e.x1)+o*2,height:Math.abs(e.y2-e.y1)+o*2,...a}]}if(e.type==="path")return e.d?[{type:"path",d:e.d,...a}]:[];if(e.type==="text"){const l=(e.fontSize||12)*.9+o;return[{type:"circle",cx:e.x,cy:e.y,r:l,...a}]}return[]}function Ap(e,t,n){if(!n||n.enabled===!1||!n.outline)return[];const r=[];for(const o of t){if(o==null)continue;const i=(e||[]).find(s=>s&&s.index===o)||(e||[])[o];!i||i.ghost||r.push(...Gf(i,n))}return r}const Vf={ink:"steelblue",accent:"#2563eb",muted:"#9ca3af",handle:"#2563eb",handleStroke:"#fff",background:null,palette:ls,ramp:Ei,diverging:Wu,font:{family:null,size:10,labelSize:12,titleSize:13},axis:{stroke:"#6b7280",labelFill:"#374151",fontSize:10,handle:"#2563eb"},grid:{stroke:"#e5e7eb",strokeWidth:1},guide:{rule:{stroke:"#64748b",strokeDasharray:"5 4",strokeWidth:1,opacity:.9},region:{fill:"#64748b",opacity:.1},legend:{stroke:"#374151",labelFill:"#374151",fontSize:11,currentStroke:"#111827",currentWidth:2},bounds:{dash:"4 4",width:1,opacity:.9},catchment:{dash:"2 4",width:1,opacity:.45},track:{dash:"3 3",width:2,opacity:.35}},constraint:{color:"#e4572e"},effects:ul,ghost:{opacity:.45,fill:null,stroke:null,strokeDasharray:null},widget:{accent:"#2563eb",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#334155",question:"#0f172a",labelSize:12,questionSize:13,radius:11},marks:{}};function qc(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof Date)}function Ku(e,t){if(!qc(t))return t===void 0?e:t;const n={...e};for(const r of Object.keys(t)){const o=e?e[r]:void 0,i=t[r];n[r]=qc(o)&&qc(i)?Ku(o,i):i===void 0?o:i}return n}let C0={};function T5(e){C0=e||{}}function Xf(e){const t=Ku(Vf,C0);return e==null||typeof e=="string"?t:Ku(t,e)}function it(e){return e&&e.theme||Vf}function It(e,t,n){const r=it(e),o=r.marks&&r.marks[t]||{};return{...n,...o}}const N0={fill:void 0,stroke:void 0,strokeWidth:void 0,opacity:void 0,fillOpacity:void 0,strokeOpacity:void 0},I0=Object.keys(N0),L0=x0;function Vl(e,t,n,r,o,i){if(n==null)return i;try{const s=e.fn(n,r,o);return s??i}catch(s){return ge(`fn:${t}`,`fn on channel "${t}" threw: ${s instanceof Error?s.message:s}; using the fallback.`),i}}function se(e,t,n,r,o,i,s){const a=t[n];if(!a)return o;if(a.expr!==void 0&&ge(`expr:${n}`,`channel "${n}" uses { expr: … }, which is RESERVED for the planned JSON spec layer and is not implemented in 0.1. In JavaScript, write the derived form instead: { fn: (d, i, data) => … }.`),a.field===void 0){if(typeof a.fn=="function")return Vl(a,n,r,i,s,o);if(a.value!==void 0)return a.value;if(a.datum!==void 0){if(a.scale===null)return a.datum;const c=e[n];return c?c.encode(a.datum,o):o}return o}const l=r?r[a.field]:void 0;if(l==null)return o;if(a.scale===null)return l;const u=e[uo(n,a.field)]||e[n];return u?u.encode(l,o):o}const Jf={size:5};function fn(e,t,n={}){const{handles:r=!0,handleSize:o,handleColor:i}=t||{},s=it(e),a=r!==!1&&r!=="hit",l=r!==!1;return{visible:a,grabbable:l,size:o??Jf.size,fill:a?i||n.fill||s.handle||s.accent:l?"transparent":i||n.fill||s.handle||s.accent,stroke:a?n.stroke||s.handleStroke:"none",strokeWidth:a?1.25:0}}function Xt(e){const t=e||{};return{xKey:t.x&&t.x.field||"x",yKey:t.y&&t.y.field||"y"}}function kr(e,t,{orientation:n,extent:r="value",single:o="value"}={}){if(n==="horizontal")return"x";if(n==="vertical")return"y";const i=e||{},s=d=>d==="x"?"y":"x",a=!!(i.x1||i.x2),l=!!(i.y1||i.y2);if(a!==l){const d=a?"x":"y";return r==="span"?s(d):d}if(t){const d=Tp(t.x),f=Tp(t.y);if(d&&!f)return"y";if(f&&!d)return"x"}const u=!!i.x,c=!!i.y;if(u!==c){const d=u?"x":"y";return o==="value"?d:s(d)}return"y"}const Tp=e=>!!(e&&e.kind==="band"),Zf=e=>e==="x"?"horizontal":"vertical";function Nn(e,t,n,r,o,i){const s=e?e[t]:void 0,a=r??t;r==null&&n&&n[t]!==void 0&&ge(`implicitcol:${t}`,`a mark places rows on the "${t}" category axis but declares no "${t}" channel, so it is reading the column named "${t}" implicitly. Declare it — channels: { ${t}: { field: "${t}" } } — so the spec says which column the mark draws (and which one an edit would write).`);const l=n?n[a]:void 0;if(!s)return l;if(s.field===void 0)return typeof s.fn=="function"?Vl(s,t,n,o,i,l):s.datum!==void 0?s.datum:(s.value!==void 0&&ge(`catvalue:${t}`,`channel "${t}" is a CATEGORY axis on this mark, and { value: … } is a visual-space constant — there is no visual constant for "which band". Use { datum: … } to pin every row to one category, or { field: "…" } to read it from the data.`),l);const u=n?n[s.field]:void 0;return u??l}function Ft(e,t,n,r,o){if(r==null)return o;const i=t[n];if(i&&i.scale===null)return r;const s=e[n];return s?s.encode(r,o):o}function zr(e,t,n,r,o=0,i,s){if(!t||!t[n])return o;if(e[n])return se(e,t,n,r,o,i,s);const l=t[n];if(typeof l.fn=="function")return+Vl(l,n,r,i,s,o);if(l.field!=null){const u=r?r[l.field]:void 0;return u==null?o:+u}return l.value!==void 0?+l.value:o}function cs(e,t,n,r,o){if(!t||!t.symbol)return;const i=se(e,t,"symbol",n,void 0,r,o);return i==null||i===""?void 0:String(i)}function Xl(e,t,n,r,o={}){return{type:"text",x:t,y:n,text:e,fontSize:Math.max(1,r*2),textAnchor:"middle",dominantBaseline:"central",...o}}function yt(e,t,n,r={},o,i){const s={};for(const a of I0){const l=a in r?r[a]:N0[a],u=se(e,t,a,n,l,o,i);u!==void 0&&(s[a]=u)}return s}function Os(e={}){return e.series&&e.series.field||e.fill&&e.fill.field||e.stroke&&e.stroke.field||null}function pt(e,t,n,r,o,i){const s=e[t];if(!s)return r;if(s.field!=null){const a=n[s.field];return a??r}return typeof s.fn=="function"?Vl(s,t,n,o,i,r):s.value!==void 0?s.value:(s.datum!==void 0&&ge(`rawdatum:${t}`,`channel "${t}" on a text mark has no scale — its value IS the output — so { datum: … } has nothing to go through. Use { value: … } for a constant.`),r)}function Qf(e={}){return e.order&&e.order.field||null}const O5=w0;function lt(e){return{id:e.id,edits:e.edits,table:e.table}}const F0={color:"there is no `color` channel — use `fill` (or `stroke` for a line).",data:"a mark never owns data. Put `data` on the Elicit spec; the engine hands the rows to every mark.",onChange:"put `onChange` on the Elicit spec, not on a mark.",domain:"a domain describes the DATA, so it lives on the spec's schema: schema: { field: { domain: [...] } }.",range:"a range belongs to the scale: channels.<name>.scale = { range: [...] }.",scale:"a scale is per channel: channels.<name>.scale, or spec.scales for the whole chart.",channel:"did you mean `channels`? (Axis/grid/legend marks take a singular `channel`; data marks take a `channels` map.)",edit:'attach an edit to a channel — y: { field: "…", edit: move() } — or pass several with `edits: [...]`.',r:"the radius channel is `size` (px), on every mark.",handleRadius:"a sub-element's radius is `handleSize`.",order:'order is a CHANNEL — it names the column to sort by: channels: { order: { field: "…" } }. The MODE (sort by the domain axis, or connect in array order) is the `connect` option: connect: "domain" | "sequence".',series:'series is a CHANNEL — it names a column, and `channels` is the only place a mark names one: channels: { series: { field: "…" } }.',z:'the grouping channel is `series`: channels: { series: { field: "…" } }.',constraints:"a constraint is a DATASET invariant — it gates every edit from every mark, whichever one declared it — so writing it inside a mark says something the engine does not mean. Put it on the Elicit spec: constraints: [...].",value:"a constant belongs on a channel: channels.<name> = { value: … } for visual space, { datum: … } for data space.",field:'a field belongs on a channel: channels.<name> = { field: "…" }.',...C5()};function C5(){const e={};for(const t of["x","y","x1","x2","y1","y2","lon","lat"])e[t]=`positional channels are not top-level shorthands (only style names like fill/stroke/size are). For a constant in the field's own units, write channels: { ${t}: { datum: … } } — it goes THROUGH the scale, so it lands where that value is. For a column, channels: { ${t}: { field: "…" } }. And for a plain reference line, a guide is the mark-free way to say it: guides.rule({ ${t}: … }).`;return e}function N5(e,t,n){if(!t||!oi())return;const r=e||"this mark";e&&!n&&ge(`noallow:${e}`,`${r}() calls normalizeMarkOptions without an \`allow\` list, which turns off its unknown-option diagnostics. Declare the mark's own option vocabulary — see the "Adding a new mark" contract in CLAUDE.md.`);const o=n?new Set([...O5,...L0,...n]):null;for(const i of Object.keys(t)){const s=F0[i];if(s){if(o&&o.has(i))continue;ge(`opt:${r}:${i}`,`${r}({ ${i}: … }): ${s}`);continue}!o||o.has(i)||ge(`opt:${r}:${i}`,`${r}({ ${i}: … }) is not an option this mark reads, so it is ignored. Mark options are: ${[...o].sort().join(", ")}.`)}}function at(e={},{except:t=[],mark:n,allow:r}={}){N5(n,e,r);const{channels:o={},...i}=e,s={...o};for(const a of L0)i[a]===void 0||t.includes(a)||(s[a]===void 0&&(s[a]=typeof i[a]=="function"?{fn:i[a]}:{value:i[a]}),delete i[a]);return{...i,channels:s}}const I5=["stroke","strokeWidth","fill","fontSize"],L5=v0;function Cs(e,t,n){if(!t||!oi())return;const r=new Set([...L5,...n]);for(const o of Object.keys(t)){if(r.has(o))continue;const i=F0[o];if(i){ge(`opt:${e}:${o}`,`${e}({ ${o}: … }): ${i}`);continue}ge(`opt:${e}:${o}`,`${e}({ ${o}: … }) is not an option this chart element reads, so it is ignored. ${e} options are: ${[...r].sort().join(", ")}.`)}}function Wi(e,t){return[e&&e.edit,e&&e.edits].flat(1/0).filter(r=>r&&typeof r.apply=="function").map(r=>r.channels?r:{...r,channels:[t]})}const Yu=16,Oi=.4,R0=8,F5=30,R5=.25,P5=25e4,At=["top","right","bottom","left"];function Op(e,t,n){let r=t[0],o=1/0;for(const i of t){const s=tn[i],a=Math.hypot(e.cx+s.x*e.hw-n.x,e.cy+s.y*e.hh-n.y);a<o&&(o=a,r=i)}return r}function z5(e,t,n,r,o){const i=e||At,s=t||At,a=(c,d)=>{if(d.includes(c))return c;const f=At.indexOf(c),p=h=>{const y=Math.abs(At.indexOf(h)-f);return Math.min(y,4-y)};return d.slice().sort((h,y)=>p(h)-p(y))[0]};if(n||r){const c=n||a(r,i);return{out:c,in:r||a(c,s),nest:o}}const l=At.filter(c=>i.includes(c)&&s.includes(c));if(l.length){const c=l[o%l.length];return{out:c,in:c,nest:Math.floor(o/l.length)}}const u=i[0];return{out:u,in:a(u,s),nest:o}}const tn={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}},D5={top:"bottom",bottom:"top",left:"right",right:"left"};function j5(e,t,n){return Math.max(t,Math.min(n,e))}function P0(e){const t=[];for(const n of e){const r=t[t.length-1];r&&Math.abs(r[0]-n[0])<.01&&Math.abs(r[1]-n[1])<.01||t.push(n)}for(let n=t.length-2;n>=1;n--){const r=t[n-1],o=t[n],i=t[n+1],s=(o[0]-r[0])*(i[1]-r[1])-(o[1]-r[1])*(i[0]-r[0]),a=(o[0]-r[0])*(i[0]-o[0])+(o[1]-r[1])*(i[1]-o[1]);Math.abs(s)<.01&&a>0&&t.splice(n,1)}return t}function Go(e,t,n,r,o=Oi){const i=tn[t],s=i.x?e.hh:e.hw,a=j5(r,-o,o),l=a*s*2;return{side:t,offset:a,x:e.cx+i.x*(e.hw+n)+-i.y*l,y:e.cy+i.y*(e.hh+n)+i.x*l}}function Cp(e,t,n,r=0){const o=t.x-e.cx,i=t.y-e.cy,s=e.hw||1e-6,a=e.hh||1e-6;let l,u;if(Math.abs(o)*a>=Math.abs(i)*s){l=o>=0?"right":"left";const f=o===0?0:i*(s/Math.abs(o));u=l==="right"?f:-f}else{l=i>=0?"bottom":"top";const f=i===0?0:o*(a/Math.abs(i));u=l==="top"?f:-f}const d=(tn[l].x?a:s)*2;return Go(e,l,n,u/d+r,.5)}function W5(e,t,n,r,o,i){const s=tn[e.side],a=tn[t.side];if(s.x!==-a.x||s.y!==-a.y)return{a:e,b:t};if(!ka(e,t,s))return{a:e,b:t};const l=!!s.x,u=l?t.y-e.y:t.x-e.x;if(Math.abs(u)<.01)return{a:e,b:t};const c=Math.sign(u),d=(m,b,w)=>{const x=l?b.hh:b.hw,S=l?m.y-b.cy:m.x-b.cx;return Math.max(0,x-w*S)},f=o?Math.min(Yu,d(e,n,c)):0,p=i?Math.min(Yu,d(t,r,-c)):0,h=Math.min(Math.abs(u),f+p);if(!h)return{a:e,b:t};const y=h*f/(f+p)*c,g=h*c-y;return{a:l?{...e,y:e.y+y}:{...e,x:e.x+y},b:l?{...t,y:t.y-g}:{...t,x:t.x-g}}}function q5(e,t,n,r){const o=n.cx-n.hw-r,i=n.cx+n.hw+r,s=n.cy-n.hh-r,a=n.cy+n.hh+r,l=Math.min(e[0],t[0]),u=Math.max(e[0],t[0]),c=Math.min(e[1],t[1]),d=Math.max(e[1],t[1]);return l<i&&u>o&&c<a&&d>s}function Gu(e,t){return e===t||e.cx===t.cx&&e.cy===t.cy&&e.hw===t.hw&&e.hh===t.hh}function B5(e,t,n,r){let o=0;const i=e.length-2;for(let s=0;s<=i;s++)for(const a of r)s===0&&Gu(a,t)||s===i&&Gu(a,n)||q5(e[s],e[s+1],a,R0)&&o++;return o}function ka(e,t,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y>=0}function H5(e,t,n,r,o,i,s,a,l){const u=[e.x,e.y],c=[t.x,t.y],d=[n.x,n.y],f=[r.x,r.y];if(o.x===-i.x&&o.y===-i.y){if(ka(e,r,o)){if(o.x){const S=(e.x+r.x)/2;return[u,[S,e.y],[S,r.y],f]}const x=(e.y+r.y)/2;return[u,[e.x,x],[r.x,x],f]}if(o.x){const x=Math.min(s.cy-s.hh,a.cy-a.hh)-l,S=Math.max(s.cy+s.hh,a.cy+a.hh)+l,v=_=>Math.abs(_-t.y)+Math.abs(_-n.y),k=v(x)<=v(S)?x:S;return[u,c,[t.x,k],[n.x,k],d,f]}const g=Math.min(s.cx-s.hw,a.cx-a.hw)-l,m=Math.max(s.cx+s.hw,a.cx+a.hw)+l,b=x=>Math.abs(x-t.x)+Math.abs(x-n.x),w=b(g)<=b(m)?g:m;return[u,c,[w,t.y],[w,n.y],d,f]}if(o.x===i.x&&o.y===i.y){if(o.x){const m=o.x>0?Math.max(t.x,n.x):Math.min(t.x,n.x);return[u,c,[m,t.y],[m,n.y],d,f]}const g=o.y>0?Math.max(t.y,n.y):Math.min(t.y,n.y);return[u,c,[t.x,g],[n.x,g],d,f]}const p=o.x?{x:n.x,y:t.y}:{x:t.x,y:n.y},h={x:-i.x,y:-i.y};if(ka(t,p,o)&&ka(p,n,h))return[u,c,[p.x,p.y],d,f];const y=o.x?{x:t.x,y:n.y}:{x:n.x,y:t.y};return[u,c,[y.x,y.y],d,f]}function z0(e,t,n,r,o,i){const s=+t.offset||0,a=+o.offset||0,l=t.side?Go(e,t.side,n,s):null,u=o.side?Go(r,o.side,i,a):null,c=l||Cp(e,u||{x:r.cx,y:r.cy},n,s),d=u||Cp(r,l||{x:e.cx,y:e.cy},i,a);return{a:c,b:d}}function U5(e){const t=e.source.box,n=e.target.box;if(t.cx===n.cx&&t.cy===n.cy)return null;const r=e.sourceGap||0,o=e.targetGap||0,i=Math.max(Yu,r,o),s=e.obstacles||[],a=z0(t,e.source.port,r,n,e.target.port,o),{a:l,b:u}=W5(a.a,a.b,t,n,!e.source.port.side,!e.target.port.side),c=tn[l.side],d=tn[u.side],f={x:l.x+c.x*i,y:l.y+c.y*i},p={x:u.x+d.x*i,y:u.y+d.y*i},h=P0(H5(l,f,p,u,c,d,t,n,i)),y=B5(h,t,n,s),g={points:h,sourceSide:l.side,targetSide:u.side,crossings:y};if(y&&e.grid){const m=G5(e.grid,t,n,l,u,i);if(m)return m}return g}function Np(e){const t=[...e].sort((o,i)=>o-i),n=[];for(const o of t)(!n.length||o-n[n.length-1]>.5)&&n.push(o);const r=[];for(let o=0;o<n.length;o++)o&&r.push((n[o-1]+n[o])/2),r.push(n[o]);return r}function K5(e,t=R0){const n=[],r=[];for(const o of e)n.push(o.cx-o.hw-t,o.cx+o.hw+t),r.push(o.cy-o.hh-t,o.cy+o.hh+t);return{xs:Np(n),ys:Np(r),boxes:e,margin:t}}function Ip(e,t){const n=[...e];for(const r of t){let o=0,i=n.length;for(;o<i;){const s=o+i>>1;n[s]<r?o=s+1:i=s}Math.abs((n[o]??1/0)-r)<.01||o>0&&Math.abs(n[o-1]-r)<.01||n.splice(o,0,r)}return n}function ra(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=n+r>>1,i=e[o]-t;if(Math.abs(i)<.01)return o;i<0?n=o+1:r=o-1}return-1}class Y5{constructor(){this.a=[]}get size(){return this.a.length}push(t,n){const r=this.a;r.push([t,n]);let o=r.length-1;for(;o>0;){const i=o-1>>1;if(r[i][0]<=r[o][0])break;[r[o],r[i]]=[r[i],r[o]],o=i}}pop(){const t=this.a,n=t[0],r=t.pop();if(t.length){t[0]=r;let o=0;for(;;){const i=2*o+1,s=i+1;let a=o;if(i<t.length&&t[i][0]<t[a][0]&&(a=i),s<t.length&&t[s][0]<t[a][0]&&(a=s),a===o)break;[t[o],t[a]]=[t[a],t[o]],o=a}}return n}}const Lp=[[0,-1],[1,0],[0,1],[-1,0]];function G5(e,t,n,r,o,i){const s=tn[r.side],a=tn[o.side],l={x:r.x,y:r.y},u={x:o.x,y:o.y},c=Ip(e.xs,[l.x,u.x,r.x+s.x*i,o.x+a.x*i]),d=Ip(e.ys,[l.y,u.y,r.y+s.y*i,o.y+a.y*i]),f=c.length,p=d.length;if(f*p>P5)return null;const h=e.margin-.5,y=e.boxes,g=new Int8Array(f*p).fill(-1),m=(z,j)=>{const G=j*f+z;if(g[G]>=0)return g[G];const J=c[z],re=d[j];let Q=0;for(const ve of y){const Ce=Math.abs(J-ve.cx)-ve.hw,le=Math.abs(re-ve.cy)-ve.hh;if(Ce<h&&le<h){Q=1;break}Ce<=e.margin+.5&&le<=e.margin+.5&&(Q=2)}return g[G]=Q,Q},b=ra(c,l.x),w=ra(d,l.y),x=ra(c,u.x),S=ra(d,u.y);if(b<0||w<0||x<0||S<0)return null;const v=(z,j)=>y.some(G=>!Gu(G,j)&&Math.abs(z.x-G.cx)-G.hw<h&&Math.abs(z.y-G.cy)-G.hh<h);if(v(l,t)||v(u,n))return null;const k=At.indexOf(D5[o.side]),_=f*p*4,T=new Float64Array(_).fill(1/0),L=new Int32Array(_).fill(-1),N=new Y5,I=(z,j)=>Math.abs(c[z]-c[x])+Math.abs(d[j]-d[S]),O=(w*f+b)*4+At.indexOf(r.side);T[O]=0,N.push(I(b,w),O);let M=1/0,$=-1;for(;N.size;){const[z,j]=N.pop();if(z>=M)break;const G=j&3,J=j>>2,re=J%f,Q=(J-re)/f,ve=T[j];if(!(z>ve+I(re,Q)+1e-9)){re===x&&Q===S&&G===k&&ve<M&&(M=ve,$=j);for(let Ce=0;Ce<4;Ce++){if(j===O&&Ce!==G)continue;const le=re+Lp[Ce][0],me=Q+Lp[Ce][1];if(le<0||me<0||le>=f||me>=p)continue;const ce=le===x&&me===S?0:m(le,me);if(ce===1)continue;const Y=Math.abs(c[le]-c[re])+Math.abs(d[me]-d[Q]),fe=ve+Y*(ce===2?1+R5:1)+(Ce===G?0:F5),ie=(me*f+le)*4+Ce;fe<T[ie]&&(T[ie]=fe,L[ie]=j,N.push(fe+I(le,me),ie))}}}if($<0)return null;const F=[];for(let z=$;z>=0;z=L[z]){const j=z>>2,G=j%f;F.push([c[G],d[(j-G)/f]])}return F.reverse(),{points:P0(F),sourceSide:r.side,targetSide:o.side,crossings:0}}function D0(e,t){if(e==null||e===!1)return null;const n={},r=(o,i)=>(o===!0?At:Array.isArray(o)?o:o==null?[]:[o]).filter(a=>At.includes(a)?!0:(ge(`ports:side:${a}`,`ports got ${JSON.stringify(a)}${i}, which is not an edge. Use any of ${At.map(l=>`"${l}"`).join(", ")}. Skipping it.`),!1));if(e===!0||typeof e=="string"||Array.isArray(e))for(const o of r(e,""))n[o]="both";else if(typeof e=="object"){const o=r(e.out," in `out`"),i=r(e.in," in `in`");if(t===!1&&(e.out||e.in)){ge("ports:undirected","ports splits its sides into `out` and `in`, but the links table is declared directed: false, so a link has no direction to leave or enter by. Using every side listed, both ways. List them as one array instead.");for(const s of[...o,...i])n[s]="both"}else{for(const s of o)n[s]="out";for(const s of i)n[s]=n[s]==="out"?"both":"in"}}else return ge("ports:value",`ports got ${JSON.stringify(e)}. Use true, a side, a list of sides, or { out: [...], in: [...] }.`),null;return Object.keys(n).length?n:null}function ed(e,t,n){return`${e}\0${t}\0${n}`}function j0(e,t){return e?e==="both"||e===(t==="source"?"out":"in"):!1}function V5(e,t){const{edit:n,...r}=t||{},o={ports:r};return{id:`${e.id}/ports`,type:"port",table:e.table,...e.glyph?{glyph:e.glyph}:{},channels:o,edits:n?[n]:[],rawChannels:["ports"],discreteScale:"point",portHost:e,build:(i,s,a,l,u)=>{if(typeof e.nodeBox!="function")return[];const c=fn(s,{}),d=u&&u.schema?Ms(u.schema):void 0,f=[];return i.forEach((p,h)=>{if(!p)return;const y=D0(pt(o,"ports",p,!1,h,i),d);if(!y)return;const g=e.nodeBox(p,h,i,s,a,l);if(g)for(const m of At){const b=y[m];if(!b)continue;const w=Go(g,m,0,0);f.push({type:"circle",cx:w.x,cy:w.y,r:c.size,fill:c.fill,stroke:c.stroke,strokeWidth:c.strokeWidth,channel:"port",side:m,portRole:b,onHover:!0,data:p,index:h})}}),f}}}const X5={name:"plane",sessionKeys:[],onEvent({event:e,edits:t,runEdit:n}){let r=!1;return t.filter(o=>o.gesture===e.type).forEach(o=>{n(o,null)&&(r=!0)}),r}};function us(e,t,n){const r=Vu(e,t,n);if(e.type==="circle"||e.type==="ellipse")return Math.hypot(r.x-e.cx,r.y-e.cy);if(e.type==="rect"){if(e.bandAxis==="y"){const s=e.y,a=e.y+e.height;return r.y<s?s-r.y:r.y>a?r.y-a:0}const o=e.x,i=e.x+e.width;return r.x<o?o-r.x:r.x>i?r.x-i:0}if(e.type==="line")return Fp(r.x,r.y,e.x1,e.y1,e.x2,e.y2);if(e.type==="path"){const o=e.points||[];let i=1/0;for(let s=1;s<o.length;s++){const a=Fp(r.x,r.y,o[s-1][0],o[s-1][1],o[s][0],o[s][1]);a<i&&(i=a)}return i}return 1/0}function Vu(e,t,n){if(!e.angle)return{x:t,y:n};const r=Rn(e);if(!r)return{x:t,y:n};const o=-e.angle*Math.PI/180,i=t-r.cx,s=n-r.cy,a=Math.cos(o),l=Math.sin(o);return{x:r.cx+i*a+s*l,y:r.cy-i*l+s*a}}function Fp(e,t,n,r,o,i){const s=o-n,a=i-r,l=s*s+a*a,u=l?Math.max(0,Math.min(1,((e-n)*s+(t-r)*a)/l)):0;return Math.hypot(e-(n+u*s),t-(r+u*a))}function In(e,t,n,r,o){let i=null,s=1/0;return(e||[]).forEach(a=>{if(a.index==null||a.locked||o!==void 0&&a.series!==o)return;const l=us(a,t,n);l<s&&(s=l,i=a.index)}),i!=null&&s<=r?i:null}function Ar(e,t,n,r){let o=null,i=1/0;return(e||[]).forEach(s=>{if(s.series===void 0||s.locked)return;let a;if(s.type==="path")a=us(s,t,n);else if(s.cx!=null)a=Math.hypot(t-s.cx,n-s.cy);else return;a<i&&(i=a,o=s.series)}),o!=null&&i<=r?o:null}function td(e,t,n,r,o,i){let s=null,a=1/0;return(e||[]).forEach((l,u)=>{if(l.locked||i!==void 0&&l.series!==i)return;const c=o==="x"?l.cx:l.cy;if(c==null)return;const d=Math.abs((o==="x"?t:n)-c);d<a&&(a=d,s=l.index!=null?l.index:u)}),s!=null&&a<=r?s:null}const wn=4,fl=12;function Ci(e){const t=e.width||0,n=e.height||0,r=Math.max(t,fl),o=Math.max(n,fl);return{x:e.x-(r-t)/2,y:e.y-(o-n)/2,w:r,h:o}}function Sa(e,t,n){const r=e||[];for(let o=r.length-1;o>=0;o--){const i=r[o];if(!(!i||!i.editable)&&!(i.locked||i.guide||i.background)&&i.pointerEvents!=="none"&&J5(i,t,n))return i}return null}function J5(e,t,n){if(e.type==="circle"){const r=e.r!=null?e.r:5;return us(e,t,n)<=r+wn}if(e.type==="ellipse"){const r=Vu(e,t,n),o=Math.max(1e-6,(e.rx!=null?e.rx:5)+wn),i=Math.max(1e-6,(e.ry!=null?e.ry:5)+wn);return Math.hypot((r.x-e.cx)/o,(r.y-e.cy)/i)<=1}if(e.type==="rect"){const r=Ci(e),o=Vu(e,t,n);return o.x>=r.x-wn&&o.x<=r.x+r.w+wn&&o.y>=r.y-wn&&o.y<=r.y+r.h+wn}if(e.sector){const{cx:r,cy:o,r0:i,r1:s,a0:a,a1:l}=e.sector,u=Math.hypot(t-r,n-o);if(u<Math.max(0,i)-wn||u>s+wn)return!1;const c=l-a,d=Math.sign(c)||1;return((Math.atan2(-(n-o),t-r)*180/Math.PI-a)*d%360+360)%360<=Math.abs(c)}if(e.type==="line"||e.type==="path"){const r=(e.strokeWidth||1)/2;return us(e,t,n)<=r+wn}return e.type==="text"?Math.hypot(t-e.x,n-e.y)<=(e.fontSize||10)+wn:!1}const Jl=40;function W0(e,t=Jl){return e&&e>0?e:t}function Zn(e,t=Jl){return W0(e?e.threshold:void 0,t)}const Z5=8;function Zl(e){const t=e.edgeInset;return t&&t>0?t:Z5}const Q5={name:"nearest",sessionKeys:["px","py","threshold","hoverIndex","activeIndex"],selects:!0,onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=Zn(t[0]);let s=!1;if(e.type==="hover"){const a=In(n,e.x,e.y,i);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:a}),s=!0}else if(e.type==="hoverout")r.clear(),s=!0;else if(e.type==="dragstart"){const a=In(n,e.x,e.y,i);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:a,activeIndex:a}),s=!0}else if(e.type==="dragend"){const a=r.get();a&&(a.activeIndex=null),s=!0}else{const a=r.get();a&&(a.px=e.x,a.py=e.y);const l=t.filter(u=>u.gesture===e.type);if(l.length>0){let u=a?a.activeIndex:null;u==null&&(u=In(n,e.x,e.y,i)),u!=null&&l.forEach(c=>{o(c,u)&&(s=!0)})}else a&&(s=!0)}return s}},eE={name:"sweep",sessionKeys:["px","py","threshold","hoverIndex","activeIndex","series"],selects:!0,onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=Zn(t[0]),s=t[0].channels||["y"],a=s.includes("x")&&s.includes("y"),u=(s[0]||"y")==="x"?"y":"x",c=f=>a?In(n,e.x,e.y,i,f):td(n,e.x,e.y,i,u,f);let d=!1;if(e.type==="hover"){const f=Ar(n,e.x,e.y,i),p=c(f??void 0);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:p,series:f}),d=!0}else if(e.type==="hoverout")r.clear(),d=!0;else if(e.type==="dragstart"){const f=Ar(n,e.x,e.y,i),p=c(f??void 0);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:p,activeIndex:p,series:f}),p!=null&&t.forEach(h=>{o(h,p)&&(d=!0)}),d=!0}else if(e.type==="dragend"){const f=r.get();f&&(f.activeIndex=null,f.series=null),d=!0}else if(e.type==="drag"){const f=r.get(),p=f&&f.series!=null?f.series:void 0,h=c(p);r.set({px:e.x,py:e.y,threshold:i,hoverIndex:h,activeIndex:h}),h!=null&&t.forEach(y=>{o(y,h)&&(d=!0)}),d=!0}return d}},tE={name:"draw",sessionKeys:["mode","drawSeries","lastDomain","lastX","lastY","px","py"],onEvent({feature:e,event:t,edits:n,marks:r,data:o,session:i,runEdit:s}){const a=Zn(n[0]);let l=!1;if(t.type==="dragstart"){const u=n[0].into==="new"?null:Ar(r,t.x,t.y,a);if(u!=null)i.set({mode:"edit",drawSeries:u,px:t.x,py:t.y});else{const c=e.seriesKey||null,f=e.connect==="sequence"&&o.length>0&&n[0].into!=="new"?c?o[o.length-1][c]:0:Yl(o,c);i.set({mode:"draw",drawSeries:f,lastDomain:null,lastX:null,lastY:null,px:t.x,py:t.y})}n.forEach(c=>{s(c,null)&&(l=!0)}),l=!0}else if(t.type==="drag"){const u=i.get();u&&(u.px=t.x,u.py=t.y),n.forEach(c=>{s(c,null)&&(l=!0)}),l=!0}else t.type==="dragend"&&(i.clear(),l=!0);return l}};function nE(e,t,n,r,o,i,s){const a=e.channels||{},[l,u]=r,c=a[l],d=a[u];if(!c||!d||!n)return null;const f=_t(l);if(!f)return null;const p=se(t,a,l,n),h=se(t,a,u,n);if(p==null||h==null)return null;const y=Math.min(p,h),g=Math.max(p,h),m=p<=h?c.field:d.field,b=p<=h?d.field:c.field,w=f==="x"?o:i,x=Math.abs(w-y),S=Math.abs(w-g);return Math.min(x,S)<=s?x<=S?{zone:"edgeA",field:m}:{zone:"edgeB",field:b}:{zone:"body"}}const rE={name:"brush",options:["edgeInset"],sessionKeys:["px","py","threshold","hoverIndex","activeIndex","zone","field"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zn(l),c=Zl(l),d=l.channels||[];let f=!1;if(t.type==="hover"){const p=In(r,t.x,t.y,u);s.set({px:t.x,py:t.y,threshold:u,hoverIndex:p}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const p=In(r,t.x,t.y,u),h=p!=null?nE(e,i,o[p],d,t.x,t.y,c):null;s.set({px:t.x,py:t.y,threshold:u,hoverIndex:p,activeIndex:p,zone:h?h.zone:null,field:h?h.field:null}),f=!0}else if(t.type==="drag"){const p=s.get();p&&(p.px=t.x,p.py=t.y);const h=p?p.activeIndex:null;h!=null&&p&&p.zone&&a(l,h)&&(f=!0),f=!0}else if(t.type==="dragend"){const p=s.get(),h=p?p.activeIndex:null;h!=null&&p&&p.zone&&(p.zone="canonicalize",a(l,h)),p&&(p.activeIndex=null),f=!0}return f}};function Rp(e,t,n,r){const o=e.channels||{},i=o[r+"1"],s=o[r+"2"];if(!i||!s||!i.field||!s.field||!n)return null;const a=se(t,o,r+"1",n),l=se(t,o,r+"2",n);if(a==null||l==null)return null;const u=a<=l?i.field:s.field,c=a<=l?s.field:i.field;return{loField:u,hiField:c}}function Pp(e,t,n,r,o,i,s,a,l){const u=r.x,c=r.x+r.width,d=r.y,f=r.y+r.height,p=a==="both"||a==="x",h=a==="both"||a==="y",y=p?Rp(e,t,n,"x"):null,g=h?Rp(e,t,n,"y"):null;let m=null;if(y){const w=Math.abs(o-u),x=Math.abs(o-c);Math.min(w,x)<=s&&(m=w<=x?y.loField:y.hiField)}let b=null;if(g){const w=Math.abs(i-d),x=Math.abs(i-f);Math.min(w,x)<=s&&(b=w<=x?g.loField:g.hiField)}return m&&b?{zone:"corner",fields:[m,b]}:m?{zone:"edgeX",fields:[m]}:b?{zone:"edgeY",fields:[b]}:l?{zone:"body",fields:[]}:null}function zp(e,t,n,r){let o=null;return(e||[]).forEach(i=>{i.type!=="rect"||i.index==null||i.width==null||t>=i.x-r&&t<=i.x+i.width+r&&n>=i.y-r&&n<=i.y+i.height+r&&(o=i.index)}),o}function Dp(e){return e==="corner"?"nwse-resize":e==="edgeX"?"ew-resize":e==="edgeY"?"ns-resize":e==="body"?"move":"default"}const oE={name:"brushRect",options:["edgeInset","resize","move"],sessionKeys:["px","py","hoverIndex","activeIndex","zone","fields","cursor"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zl(l),c=l.resize||"both",d=l.move!==!1;let f=!1;if(t.type==="hover"){const p=zp(r,t.x,t.y,u),h=p!=null?r.find(g=>g.index===p):null,y=p!=null&&h?Pp(e,i,o[p],h,t.x,t.y,u,c,d):null;s.set({px:t.x,py:t.y,hoverIndex:p,cursor:Dp(y?y.zone:null)}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const p=zp(r,t.x,t.y,u),h=p!=null?r.find(g=>g.index===p):null,y=p!=null&&h?Pp(e,i,o[p],h,t.x,t.y,u,c,d):null;s.set({px:t.x,py:t.y,hoverIndex:p,activeIndex:p,zone:y?y.zone:null,fields:y?y.fields:null,cursor:Dp(y?y.zone:null)}),f=!0}else if(t.type==="drag"){const p=s.get();p&&(p.px=t.x,p.py=t.y);const h=p?p.activeIndex:null;h!=null&&p&&p.zone&&a(l,h)&&(f=!0),f=!0}else if(t.type==="dragend"){const p=s.get(),h=p?p.activeIndex:null;h!=null&&p&&p.zone&&(p.zone="canonicalize",a(l,h)),p&&(p.activeIndex=null,p.cursor="default"),f=!0}return f}};function iE(e,t,n,r){let o=null;return(e||[]).forEach(i=>{i.type!=="rect"||i.index==null||i.width==null||t>=i.x-r&&t<=i.x+i.width+r&&n>=i.y-r&&n<=i.y+i.height+r&&(o=i.index)}),o}function sE(e,t,n,r,o){const i=e.x,s=e.x+e.width,a=e.y,l=e.y+e.height,u=[],c=Math.abs(t-i),d=Math.abs(t-s);Math.min(c,d)<=r&&u.push(c<=d?"west":"east");const f=Math.abs(n-a),p=Math.abs(n-l);return Math.min(f,p)<=r&&u.push(f<=p?"north":"south"),u.length===2?{zone:"corner",edges:u}:u.length===1?{zone:"edge",edges:u}:o?{zone:"body",edges:[]}:null}function jp(e,t){return e==="corner"?t.includes("west")&&t.includes("north")||t.includes("east")&&t.includes("south")?"nwse-resize":"nesw-resize":e==="edge"?t[0]==="west"||t[0]==="east"?"ew-resize":"ns-resize":e==="body"?"move":"default"}function aE(e){const t=e&&e.channels||{};return{west:t.west&&t.west.field||"west",south:t.south&&t.south.field||"south",east:t.east&&t.east.field||"east",north:t.north&&t.north.field||"north"}}const lE={name:"geoBrush",options:["edgeInset","move"],sessionKeys:["px","py","hoverIndex","activeIndex","zone","edges","grab","box0","cursor"],selects:!0,onEvent({feature:e,event:t,edits:n,marks:r,data:o,scales:i,session:s,runEdit:a}){const l=n[0],u=Zl(l),c=l.move!==!1,d=i.projection||null;let f=!1;const p=(h,y)=>{const g=iE(r,h,y,u);if(g==null)return{hit:null,zone:null};const m=r.find(b=>b.index===g&&b.type==="rect");return m?{hit:g,zone:sE(m,h,y,u,c)}:{hit:null,zone:null}};if(t.type==="hover"){const{hit:h,zone:y}=p(t.x,t.y);s.set({px:t.x,py:t.y,hoverIndex:h,cursor:jp(y?y.zone:null,y?y.edges:[])}),f=!0}else if(t.type==="hoverout")s.clear(),f=!0;else if(t.type==="dragstart"){const{hit:h,zone:y}=p(t.x,t.y),g=h!=null?o[h]:null,m=Fr(d,{x:t.x,y:t.y}),b=aE(e);s.set({px:t.x,py:t.y,hoverIndex:h,activeIndex:y?h:null,zone:y?y.zone:null,edges:y?y.edges:null,grab:m,box0:g?{west:g[b.west],south:g[b.south],east:g[b.east],north:g[b.north]}:null,cursor:jp(y?y.zone:null,y?y.edges:[])}),f=!0}else if(t.type==="drag"){const h=s.get();h&&(h.px=t.x,h.py=t.y);const y=h?h.activeIndex:null;y!=null&&h&&h.zone&&a(l,y)&&(f=!0),f=!0}else if(t.type==="dragend"){const h=s.get(),y=h?h.activeIndex:null;y!=null&&h&&h.zone&&(h.zone="canonicalize",a(l,y)),h&&(h.activeIndex=null,h.zone=null,h.edges=null,h.grab=null,h.box0=null,h.cursor="default"),f=!0}return f}};function Wp(e,t){const{marks:n,data:r,event:o}=e;if(o.x!=null&&o.y!=null){const i=In(n,o.x,o.y,Zn(t));if(i!=null)return i}return r.length===1?0:null}const cE={name:"probe",sessionKeys:[],onEvent:e=>{const{event:t,edits:n,preview:r,stage:o,runEdit:i,previewEdit:s}=e;if(!n.length)return!1;const a=t.type;if(a==="hover"||a==="dragstart"||a==="drag"){let l=!1;for(const u of n)s(u,Wp(e,u))&&(l=!0);return l||r.clear()}if(a==="hoverout")return r.clear();if(a==="click"||a==="dragend"){let l=!1,u=!1;for(const c of n)i(c,Wp(e,c))&&(l=!0,c.stage!=null&&c.advance!==!1&&(u=!0));return u&&o.next(),l}return!1}},uE=14;function qp(e,t,n,r){let o=null,i=r;for(const s of e||[]){if(!s||!s.axisHandle)continue;const a=s.cx!=null?s.cx:s.x,l=s.cy!=null?s.cy:s.y,u=Math.hypot(t-a,n-l);u<=i&&(i=u,o=s)}return o}function fE(e){return{axis:e.axis,grabEnd:e.handle,anchorPixel:e.anchorPixel,anchorValue:e.anchorValue,grabPixel:e.grabPixel,grabValue:e.grabValue,pxPerUnit:e.pxPerUnit,cursor:e.axis==="x"?"ew-resize":"ns-resize"}}const dE={name:"axisDrag",sessionKeys:["axis","grabEnd","anchorPixel","anchorValue","grabPixel","grabValue","pxPerUnit","cursor"],onEvent({event:e,edits:t,marks:n,session:r,runEdit:o}){const i=t[0],s=Zn(i,uE);let a=!1;if(e.type==="hover"){const l=qp(n,e.x,e.y,s),u=l?l.axis==="x"?"ew-resize":"ns-resize":null,c=r.get();(c&&c.cursor)!==u&&(r.set({cursor:u}),a=!0)}else if(e.type==="hoverout")r.clear(),a=!0;else if(e.type==="dragstart"){const l=qp(n,e.x,e.y,s);l&&(r.set(fE(l)),a=!0)}else if(e.type==="drag"){const l=r.get();l&&l.grabEnd&&o(i,null)&&(a=!0)}else e.type==="dragend"&&(r.clear(),a=!0);return a}};function Xn(e={}){const{mode:t="absolute",...n}=e,r=t==="relative";return r&&n.pick!=null&&n.pick!=="direct"&&ge("move:relative:pick",`move({ mode: "relative" }) is direct-pick: it measures from where you GRABBED the mark, so there has to be a mark under the press. { pick: "${n.pick}" } is ignored. Use the default mode: "absolute" with that pick.`),je({type:"move",inverts:!0,gesture:"drag",mode:t,...n,...r?{pick:"direct"}:{},apply:o=>{const i={...o.datum},s=Rn(Pr(o)),a=r?(o.session||{}).move:null,l=a&&a.anchors;for(const u of o.channels){if(r){const d=l&&l[u.field],f=_t(u.name);if(!d||!f||!u.scale||!u.scale.invertible)continue;const p=u.scale.encode(d.startValue);if(typeof p!="number"||Number.isNaN(p))continue;const h=(f==="x"?o.pointer.x:o.pointer.y)-d.startPx;i[u.field]=u.scale.invertValue(p+h);continue}const c=ho(u,o.pointer,s);c!==void 0&&(i[u.field]=c)}return i}})}function hE(e={}){return je({type:"moveSpan",inverts:!0,gesture:"drag",...e,apply:t=>{const[n,r]=t.channels,o=Pr(t),i=Gl(o,n,r,t.pointer);if(i)return{...t.datum,[n.field]:i.a,[r.field]:i.b}}})}function pE(e={}){const t=Kl(e,"brushSpan","brush");return je({type:"brushSpan",inverts:!0,gesture:"drag",...t,pick:"brush",apply:n=>{const[r,o]=n.channels,i=n.datum;if(!r||!o||!i)return;const s=n.session&&n.session.zone;if(!s)return;if(s==="canonicalize"){const c=i[r.field],d=i[o.field];return c==null||d==null||c<=d?void 0:{...i,[r.field]:d,[o.field]:c}}if(s==="body"){const c=Pr(n),d=Gl(c,r,o,n.pointer);return d?{...i,[r.field]:d.a,[o.field]:d.b}:void 0}const a=n.session&&n.session.field,l=a===r.field?r:a===o.field?o:null;if(!l)return;const u=ho(l,n.pointer);if(u!==void 0)return{...i,[l.field]:u}}})}function q0(e={}){const{resize:t="both",move:n=!0,...r}=Kl(e,"brushRect","brushRect");return je({type:"brushRect",inverts:!0,gesture:"drag",channels:["x1","x2","y1","y2"],...r,resize:t,move:n,pick:"brushRect",apply:o=>{const i=o.session&&o.session.zone,s=o.datum;if(!i||!s)return;const a=o.channels.filter(p=>_t(p.name)==="x"),l=o.channels.filter(p=>_t(p.name)==="y"),u=Pr(o);if(i==="canonicalize"){const p={...s};let h=!1;for(const[y,g]of[a,l]){if(!y||!g)continue;const m=s[y.field],b=s[g.field];m==null||b==null||m<=b||(p[y.field]=b,p[g.field]=m,h=!0)}return h?p:void 0}if(i==="body"){const p={...s};let h=!1;for(const[y,g]of[a,l]){if(!y||!g)continue;const m=Gl(u,y,g,o.pointer);m&&(p[y.field]=m.a,p[g.field]=m.b,h=!0)}return h?p:void 0}const c=o.session&&o.session.fields||[],d={...s};let f=!1;for(const p of o.channels){if(!p.field||!c.includes(p.field))continue;const h=ho(p,o.pointer);h!==void 0&&(d[p.field]=h,f=!0)}return f?d:void 0}})}function yE(e,t){const n=t||(e==="x"?"left":"up");return{axis:e,towardSmaller:n==="left"||n==="up"}}function gE(e,t){if(typeof e=="number"&&e>0)return e;const n=t&&t.scale&&t.scale.frameExtent;return typeof n=="number"&&n>0?n:120}const B0=(e,t)=>`${e}:${t}`;function mE(e={}){const{axis:t="x",increase:n,extent:r,mode:o="relative",...i}=e,{towardSmaller:s}=yE(t,n);return o==="relative"&&i.pick!=null&&i.pick!=="direct"&&i.pick!=="slide"&&(ge("slide:relative:pick",`slide({ mode: "relative" }) needs the slide driver's dragstart anchor, so it is served by that driver alone. { pick: "${i.pick}" } is ignored (direct pick); use mode: "absolute" with that pick, or pick: "slide" for the plane form.`),delete i.pick),je({type:"slide",inverts:!0,gesture:"drag",pick:"direct",axis:t,increase:n,extent:r,mode:o,...i,apply:a=>{const l=a.channels[0];if(!l||!l.field)return;const[u,c]=A0(l),d=t==="x"?a.pointer.x:a.pointer.y,f=gE(r,l);if(o==="relative"){const b=(a.session||{}).slide,w=b&&b[B0(t,l.field)];if(!w||typeof w.startValue!="number")return;const x=(d-w.startPx)*(s?-1:1),S=c-u,v=Math.min(u,c),k=Math.max(u,c),_=Math.max(v,Math.min(k,w.startValue+x/f*S));return{...a.datum,[l.field]:_}}const p=Rn(Pr(a));if(!p)return;const h=t==="x"?p.cx:p.cy,y=s?h+f:h-f,g=s?h-f:h+f,m=E0(d,y,g,u,c);if(m!==void 0)return{...a.datum,[l.field]:m}}})}function bE(e={}){return je({type:"resize",inverts:!0,gesture:"drag",...e,apply:t=>{const n=t.channels[0],r=Rn(Pr(t));if(!n||!n.scale||!n.scale.invertible||!r)return;const o=Math.hypot(t.pointer.x-r.cx,t.pointer.y-r.cy);return{...t.datum,[n.field]:n.scale.invertValue(o)}}})}function wE(e={}){const{relativeTo:t,pivot:n="plot",fold:r=!0,...o}=e,i=o.pick||"plane",s=a=>{let l=(a.width||0)/2,u=(a.height||0)/2;if(n==="mark"){const d=Rn(Pr(a));d&&(l=d.cx,u=d.cy)}let c=Bf(a.pointer,{cx:l,cy:u});if(r)c>90?c-=180:c<=-90&&(c+=180);else{const d=a.channels[0]&&a.channels[0].scale,f=d&&typeof d.range=="function"?d.range():null;f&&f.length>=2&&typeof f[0]=="number"&&typeof f[f.length-1]=="number"&&(c=qM(c,f[0],f[f.length-1]))}return c};return je({type:"rotate",inverts:!0,gesture:"drag",pick:"plane",...o,apply:a=>{const l=a.channels[0],u=l&&l.scale;if(!u||!u.invertible)return;const c=s(a),d=f=>{if(!t)return{...f,[l.field]:u.invertValue(c)};const p=a.markChannels[t],h=p?p.field:null,y=a.scales[t],g=h!=null&&y?.encode?y.encode(f[h]):0,m=Math.abs(c-g);return{...f,[l.field]:u.invertValue(m)}};if(i==="direct")return a.datum?d(a.datum):void 0;if(a.data.length)return a.data.map(d)}})}function xE(e={}){return je({type:"cycle",gesture:"click",...e,apply:t=>{const n=t.channels[0];if(!n||!t.datum)return;const r=T0(n,t.schema);if(!r||!r.length)return;const o=r.indexOf(t.datum[n.field]);return{...t.datum,[n.field]:r[(o+1)%r.length]}}})}function nd(e={}){const{defaults:t={},...n}=e;return je({type:"create",gesture:"click",channels:["x","y"],pick:"plane",cardinality:"append",defaults:t,...n,apply:r=>{const o=Fn(r,{defaults:t});return o?[...r.data,o]:void 0}})}function rd(e={}){const{defaults:t={},...n}=e;return je({type:"toggle",gesture:"click",channels:["x"],pick:"plane",cardinality:"toggle",defaults:t,...n,apply:r=>{const o=Fn(r,{defaults:t});if(!o)return;const i=r.channels.map(a=>a.field),s=r.data.findIndex(a=>i.every(l=>a[l]===o[l]));return s>=0?r.data.filter((a,l)=>l!==s):[...r.data,o]}})}function H0(e={}){return je({type:"remove",gesture:"click",cardinality:"delete",...e,apply:t=>{if(t.index!=null)return t.data.filter((n,r)=>r!==t.index)}})}function U0(e){const t=e.channels[0];if(!(!t||!t.field||e.value===void 0||!e.datum))return{...e.datum,[t.field]:e.value}}function vE(e={}){return je({type:"set",gesture:"commit",pick:"direct",...e,apply:U0})}function K0(e={}){return je({type:"editText",gesture:"commit",pick:"direct",channels:["text"],inline:!0,...e,apply:U0})}function Y0(e={}){return je({type:"rank",inverts:!0,gesture:"drag",...e,apply:t=>{const n=t.channels[0];if(!n||!t.datum||t.index==null)return;const r=n.field;if(!r)return;const o=ho(n,t.pointer);if(o===void 0)return;const i=t.datum[r];if(i!==o)return t.data.map((s,a)=>a===t.index?{...s,[r]:o}:s[r]===o?{...s,[r]:i}:s)}})}function kE(e={}){const{exclusive:t=!0,toggle:n=!0,multi:r=!1,...o}=e;return je({type:"select",gesture:"click",pick:"direct",target:"selection",...o,apply:i=>{if(i.index==null)return;const s=i.event||{},a=r&&!!(s.shiftKey||s.metaKey);return{index:i.index,exclusive:a?!1:t,toggle:n}}})}function G0(e,t={}){return je({type:"custom",gesture:"drag",...t,apply:e})}const SE=40,$E={name:"slide",sessionKeys:["index","slide"],wants:e=>e.type==="slide"&&e.mode==="relative",onEvent({feature:e,event:t,edits:n,marks:r,data:o,index:i,session:s,runEdit:a}){if(!n.length)return!1;let l=!1;if(t.type==="dragstart"){const u=i??In(r,t.x,t.y,Zn(n[0],SE));if(u==null)return!1;const c=o[u],d={};for(const f of n){const p=f.axis==="y"?"y":"x",h=f.channels&&f.channels[0]||null,y=h&&e.channels&&e.channels[h],g=y&&y.field;if(!g)continue;const m=c&&c[g];typeof m=="number"&&(d[B0(p,g)]={startPx:p==="x"?t.x:t.y,startValue:m})}if(!Object.keys(d).length)return!1;s.set({index:u,slide:d}),l=!0}else if(t.type==="drag"){const u=s.get();if(!u||u.index==null||!u.slide)return!1;for(const c of n)a(c,u.index)&&(l=!0)}else if(t.type==="dragend"||t.type==="hoverout"){if(!s.get())return!1;s.set({index:null,slide:null}),l=!0}return l}},_E=40,ME={name:"move",sessionKeys:["move"],wants:e=>e.type==="move"&&e.mode==="relative",onEvent({feature:e,event:t,edits:n,marks:r,data:o,index:i,session:s,runEdit:a}){if(!n.length)return!1;let l=!1;if(t.type==="dragstart"){const u=i??In(r,t.x,t.y,Zn(n[0],_E));if(u==null)return!1;const c=o[u],d={};for(const f of n)for(const p of f.channels||[]){const h=e.channels&&e.channels[p],y=h&&h.field;!y||!c||c[y]===void 0||(d[y]={startPx:_t(p)==="y"?t.y:t.x,startValue:c[y]})}if(!Object.keys(d).length)return!1;s.set({move:{index:u,anchors:d}}),l=!0}else if(t.type==="drag"){const u=(s.get()||{}).move;if(!u||u.index==null)return!1;for(const c of n)a(c,u.index)&&(l=!0)}else if(t.type==="dragend"||t.type==="hoverout"){if(!(s.get()||{}).move)return!1;s.set({move:null}),l=!0}return l}},EE={name:"connect",sessionKeys:["fromIndex","fromSide","fromPoint","targets"],wants:e=>e.type==="network.connect"||e.type==="network.rewire",onEvent({event:e,edits:t,index:n,session:r,runEdit:o,previewEdit:i,preview:s,reachable:a}){if(!t.length)return!1;let l=!1;if(e.type==="dragstart"){if(n==null)return!1;const c=e.node;r.set({fromIndex:n,fromSide:c&&c.side?c.side:null,fromPoint:{x:e.x,y:e.y}});let d=null;for(const p of t){const h=a?a(p,n):null;h&&(d=[...d||[],...h])}const f=t.some(p=>p.cardinality==="append");if(d&&!d.length&&f)return r.clear(),!0;d&&r.set({targets:d});for(const p of t)i(p,n)&&(l=!0);return!0}const u=r.get();if(!u||u.fromIndex==null)return!1;if(e.type==="drag"){let c=!1;for(const d of t)i(d,u.fromIndex)&&(c=!0);(!c&&s.clear()||c)&&(l=!0)}else if(e.type==="dragend"){for(const c of t)o(c,u.fromIndex)&&(l=!0);s.clear()&&(l=!0),r.clear(),l=!0}return l}},zo=[X5,Q5,eE,tE,rE,oE,lE,cE,dE,$E,ME,EE];function AE(e){if(!e||!e.name||typeof e.onEvent!="function"||e.wants!=null&&typeof e.wants!="function")throw new Error("[elicit] registerDriver expects { name, onEvent(ctx), wants?(edit), sessionKeys? }");const t=zo.findIndex(n=>n.name===e.name);t>=0?zo[t]=e:zo.push(e)}function gr(e){return zo.find(t=>t.name===e.pick)||zo.find(t=>t.wants?t.wants(e):!1)}function TE(e){return e.some(t=>t.pick==="direct"||t.pick==="plane"?!1:!!gr(t))}const OE="#e4572e",CE={bounds:{dash:"4 4",width:1,opacity:.9,bandOpacity:.07,fontSize:10,labelOpacity:.95,tickLength:6,tickOpacity:.5},catchment:{dash:"2 4",width:1,opacity:.45},track:{dash:"3 3",width:2,opacity:.35}},NE=["bounds","catchment"];function V0(e,t){let n=e&&e.guide;if(n==null){const a=gr(e);n=a&&a.selects?{catchment:!0}:!1}if(n===!1)return{bounds:null,catchment:null,track:null};const r=t&&t.theme&&t.theme.guide,o=t&&t.theme&&t.theme.constraint&&t.theme.constraint.color,i=n&&typeof n=="object"&&n.color||o||OE,s=a=>{const l=n===!0?NE.includes(a):n&&typeof n=="object"?n[a]:!1;if(!l)return null;const u=r&&r[a];return{color:i,...CE[a],...u&&typeof u=="object"?u:{},...typeof l=="object"?l:{}}};return{bounds:s("bounds"),catchment:s("catchment"),track:s("track")}}function IE(e){const t=[],n=new Set;for(const r of e)va(r).forEach((o,i)=>{if(o.guide===!1)return;if(!o.guide){const l=gr(o);if(!(l&&l.selects))return}const s=`${r.id}:edit-${o.type}-${i}`;if(n.has(s))return;n.add(s);const a={views:"state",build:(l,u,c,d,f)=>LE(r,o,f)};t.push(a)});return t}function LE(e,t,n){const{scales:r,width:o,height:i}=n,s=n.tableOf?n.tableOf(e):n.data,a=n.constraintsIn?n.constraintsIn(e.table):n.constraints,l=e.channels||{},u=Ti(t.channels,l,r,e),c=u[0],d=V0(t,n),f=[];if(d.bounds&&c&&c.scale){const h=d.bounds,y=[...a||[],...t.constrain].filter(g=>typeof g!="function");for(const g of y){const m=g.field==null?null:[].concat(g.field);m&&c.field&&!m.includes(c.field)||f.push(...RE(g,{feature:e,data:s,scales:r,width:o,height:i,primary:c,color:h.color,style:h}))}u.length>=2&&f.push(...jE(y,u,{color:h.color,style:h}))}const p=gr(t);return p&&p.selects&&f.push(...qE(e,t,n)),d.track&&f.push(...FE(e,t,n,d.track)),f}function FE(e,t,n,r){const o=n.featureNodes&&n.featureNodes[e.id]||[],i=t.channels&&t.channels.length?t.channels:null,s=[],a={stroke:r.color,strokeWidth:r.width,strokeDasharray:r.dash,opacity:r.opacity,fill:"none",guide:!0,pointerEvents:"none"};for(const l of o){const u=l&&l.dm;if(!u)continue;const c=Rn(l);if(c)for(const d of["x","y"]){const f=u[d];!f||f.pxAt0==null||f.pxAt1==null||i&&!i.includes(f.channel)||s.push(d==="x"?{type:"line",x1:f.pxAt0,x2:f.pxAt1,y1:c.cy,y2:c.cy,...a}:{type:"line",x1:c.cx,x2:c.cx,y1:f.pxAt0,y2:f.pxAt1,...a})}}return s}function RE(e,t){if(typeof e.guide=="function")return e.guide(t)||[];switch(e.type){case"clamp":return DE(e.options||{},t);case"maintainSum":return WE(e.options||{},t);case"snap":return zE(e.options||{},t);default:return[]}}const PE=200;function zE({step:e=1,origin:t=0},n){const{primary:r,width:o,height:i,color:s,style:a}=n,l=r.scale;if(!l||!(e>0)||fo(l))return[];const u=l.domain().map(Number),c=Math.min(...u),d=Math.max(...u);if(!Number.isFinite(c)||!Number.isFinite(d))return[];if((d-c)/e>PE)return[];const f=_t(r.name)==="x",[p,h]=oo(l),y=a&&a.tickLength||6,g=(a&&a.tickOpacity)!=null?a.tickOpacity:.5,m=[],b=Math.ceil((c-t)/e),w=Math.floor((d-t)/e);for(let x=b;x<=w;x++){const S=l(t+x*e);!Number.isFinite(S)||S<p-.5||S>h+.5||m.push(f?{type:"line",x1:S,x2:S,y1:i,y2:i-y,stroke:s,strokeWidth:1,opacity:g,pointerEvents:"none",guide:!0}:{type:"line",x1:0,x2:y,y1:S,y2:S,stroke:s,strokeWidth:1,opacity:g,pointerEvents:"none",guide:!0})}return m}function Bp(e,t,n){const{primary:r,width:o,height:i,color:s,style:a}=n;if(e===void 0)return[];const l=r.scale(e),u=a||{},c={stroke:s,strokeDasharray:u.dash,strokeWidth:u.width,opacity:u.opacity,pointerEvents:"none",guide:!0},d={fill:s,fontSize:u.fontSize,opacity:u.labelOpacity,pointerEvents:"none",guide:!0},f=[];return _t(r.name)==="x"?(f.push({type:"line",x1:l,x2:l,y1:0,y2:i,...c}),f.push({type:"text",x:l+4,y:12,text:t,textAnchor:"start",...d})):(f.push({type:"line",x1:0,x2:o,y1:l,y2:l,...c}),f.push({type:"text",x:o-4,y:l-4,text:t,textAnchor:"end",...d})),f}function DE({min:e,max:t},n){const{primary:r,width:o,height:i,color:s}=n,a=[],l=_t(r.name)==="x";if(e!==void 0&&t!==void 0){const u=r.scale(e),c=r.scale(t),d=Math.min(u,c),f=Math.max(u,c),p=(n.style&&n.style.bandOpacity)!=null?n.style.bandOpacity:.07;a.push(l?{type:"rect",x:d,y:0,width:f-d,height:i,fill:s,opacity:p,pointerEvents:"none",guide:!0}:{type:"rect",x:0,y:d,width:o,height:f-d,fill:s,opacity:p,pointerEvents:"none",guide:!0})}return a.push(...Bp(e,`min ${e}`,n)),a.push(...Bp(t,`max ${t}`,n)),a}function jE(e,t,n){const r=t.find(y=>_t(y.name)==="x"),o=t.find(y=>_t(y.name)==="y");if(!r||!o||!r.scale||!o.scale)return[];const i=e.filter(y=>typeof y!="function"),s=i.find(y=>y.type==="clamp"&&y.field===r.field),a=i.find(y=>y.type==="clamp"&&y.field===o.field);if(!s||!a)return[];const l=s.options||{},u=a.options||{};if(l.min==null||l.max==null||u.min==null||u.max==null)return[];const c=r.scale(l.min),d=r.scale(l.max),f=o.scale(u.min),p=o.scale(u.max),{color:h}=n;return[{type:"rect",x:Math.min(c,d),y:Math.min(f,p),width:Math.abs(d-c),height:Math.abs(p-f),fill:h,opacity:(n.style&&n.style.bandOpacity)!=null?n.style.bandOpacity:.08,stroke:h,strokeWidth:n.style&&n.style.width||1,strokeDasharray:n.style&&n.style.dash||"4 4",pointerEvents:"none",guide:!0}]}function WE({total:e},t){if(typeof e!="number")return[];const{feature:n,data:r,scales:o,primary:i,color:s}=t,a=i.name,l=_t(a)||(a==="x"?"x":"y"),u=l==="y"?"x":"y",c=l==="y"?n.yKey||"y":n.xKey||"x",d=u==="y"?n.yKey||"y":n.xKey||"x",f=i.scale,p=o[u];if(!p||!Vn(p))return[];const[h,y]=[Math.min(...f.domain()),Math.max(...f.domain())],g=p.bandwidth(),m=[];return r.forEach(b=>{const w=r.reduce((_,T)=>T[d]===b[d]?_:_+T[c],0),x=e-w;if(x<h||x>y)return;const S=p(b[d]),v=f(x),k={stroke:s,strokeDasharray:t.style&&t.style.dash||"3 3",strokeWidth:(t.style&&t.style.width||1)*1.5,opacity:(t.style&&t.style.opacity)!=null?t.style.opacity:.9,pointerEvents:"none",guide:!0};m.push(l==="y"?{type:"line",x1:S-2,x2:S+g+2,y1:v,y2:v,...k}:{type:"line",x1:v,x2:v,y1:S-2,y2:S+g+2,...k})}),m}function qE(e,t,n){const r=n.ui&&n.ui.session&&n.ui.session[e.id];if(!r||r.px==null||r.py==null||r.threshold==null)return[];const o=V0(t,n).catchment;return o?[{type:"circle",cx:r.px,cy:r.py,r:r.threshold,fill:"none",stroke:o.color,strokeDasharray:o.dash,strokeWidth:o.width,opacity:o.opacity,guide:!0,effect:!0,pointerEvents:"none"}]:[]}const BE={linear:Df,catmullRom:wM,natural:kM,step:SM,stepAfter:_M,stepBefore:$M,basis:gM,cardinal:mM,monotoneX:xM,monotoneY:vM};function Ni(e){return e&&BE[e]||Df}const X0=[{field:"fill",svgAttr:"fill",base:null},{field:"stroke",svgAttr:"stroke",base:null},{field:"strokeWidth",svgAttr:"stroke-width",base:null},{field:"strokeDasharray",svgAttr:"stroke-dasharray",base:null},{field:"strokeLinecap",svgAttr:"stroke-linecap",base:null},{field:"opacity",svgAttr:"opacity",base:null},{field:"fillOpacity",svgAttr:"fill-opacity",base:null},{field:"strokeOpacity",svgAttr:"stroke-opacity",base:null}];function J0(e){const t=[],n=[],r=[],o=[],i=[];for(const s of e||[])if(s){if(s.effect){i.push(s);continue}if(s.background){t.push(s);continue}if(s.guide){s.type==="rect"?n.push(s):o.push(s);continue}r.push(s)}return{background:t,guideRegions:n,marks:r,guideFront:o,effects:i}}const HE=e=>e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase());class Z0{constructor(){this.STYLE_ATTRS=X0.map(({field:t,svgAttr:n,base:r})=>[t,n,r]),this._planeGesture=null,this._planeTracking=null,this._planePointer=null,this._planeNode=null,this._markDragLive=!1}_themeFontSize(){return this._theme&&this._theme.font&&this._theme.font.size||10}render(t){const{container:n,scene:r,width:o,height:i,margins:s,onEvent:a,planeOnTop:l=!1,planeCursor:u="pointer",responsive:c="fixed",overflow:d="hidden",focusOutline:f=!1}=t,p=t.effects||ul,h=o-s.left-s.right,y=i-s.top-s.bottom,{g,plane:m}=this._ensureScene(n,{width:o,height:i,margins:s,innerWidth:h,innerHeight:y,responsive:c,overflow:d});this._sceneG=g,this._onEvent=a,this._theme=t.theme||null;const b=this._theme&&this._theme.font;sr(n).select("svg").style("font-family",b&&b.family||null).style("background",this._theme&&this._theme.background||null);const w=F=>du(F,g.node());this._bindPlaneGestures(m,w,a,l);const x=this._makeDrag(a),S=this._makeHover(a,p.hovered),v=this._makeKeyboard(a,f),k=(F,D)=>{const[z,j]=w(F);a({type:"click",x:z,y:j,node:D,rawEvent:F})},_=(F,D)=>{F.preventDefault(),F.stopPropagation();const[z,j]=w(F);a({type:"dblclick",x:z,y:j,node:D,rawEvent:F})},{background:T,guideRegions:L,marks:N,guideFront:I,effects:O}=J0(r.children),M=(F,D)=>F.filter(z=>z.type===D),$=this._sceneLayers(g);if(this._drawBackground($.bg,M(T,"image"),M(T,"path"),M(T,"line"),M(T,"text"),M(T,"rect"),M(T,"circle")),this._drawGuideRegions($.guideBack,L),this._drawPaths($.marks,M(N,"path"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawMarks($.marks,M(N,"rect"),M(N,"circle"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawEllipses($.marks,M(N,"ellipse"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawLines($.marks,M(N,"line"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._drawTextMarks($.marks,M(N,"text"),{drag:x,markClick:k,markDblClick:_,keys:v,hover:S}),this._orderMarkLayer($.marks,N),this._drawGuideFront($.guideFront,I),this._drawEffects($.effects,O),l){g.selectAll(".mark, .mark-hit").style("pointer-events","none");const F=m.node(),D=$.effects.node(),z=F&&F.parentNode;z&&z.lastElementChild===D&&D.previousElementSibling===F||(m.raise(),$.effects.raise()),m.style("cursor",u||"pointer")}}_ensureScene(t,{width:n,height:r,margins:o,innerWidth:i,innerHeight:s,responsive:a="fixed",overflow:l="hidden"}){let u=sr(t).select("svg");if(u.empty()){u=sr(t).append("svg").style("user-select","none").style("display","block");const d=u.append("g").attr("class","scene-container");d.append("rect").attr("class","plane").attr("x",0).attr("y",0).style("fill","transparent").style("pointer-events","all"),d.append("g").attr("class","bg-layer"),d.append("g").attr("class","guide-back-layer"),d.append("g").attr("class","mark-layer"),d.append("g").attr("class","guide-front-layer"),d.append("g").attr("class","effects-layer")}a==="scale"?u.attr("viewBox",`0 0 ${n} ${r}`).attr("preserveAspectRatio","xMidYMid meet").attr("width",null).attr("height",null).style("width","100%").style("height","auto"):u.attr("viewBox",null).attr("width",n).attr("height",r).style("width",null).style("height",null),u.style("overflow",l==="visible"?"visible":null);const c=u.select(".scene-container").attr("transform",`translate(${o.left},${o.top})`);return c.select("rect.plane").attr("width",i).attr("height",s),this._sceneLayers(c),{svg:u,g:c,plane:c.select("rect.plane")}}_sceneLayers(t){const n=!t.select("g.mark-layer").empty(),r=[],o=c=>{let d=t.select(`g.${c}`);return d.empty()&&(d=t.append("g").attr("class",c),r.push(c)),d},i=o("bg-layer"),s=o("guide-back-layer"),a=o("mark-layer"),l=o("guide-front-layer"),u=o("effects-layer");if(n||t.selectAll(":scope > .mark, :scope > path.mark-line, :scope > .guide-region, :scope > .guide-circle, :scope > .guide-label").remove(),r.length){const c=t.node(),d=t.select("rect.plane").node();for(const f of[d,i.node(),s.node(),a.node(),l.node(),u.node()])f&&c.appendChild(f)}return{bg:i,guideBack:s,marks:a,guideFront:l,effects:u}}_orderMarkLayer(t,n){const r=new Map(n.map((c,d)=>[c,d])),o=t.selectAll(".mark, path.mark-line").filter(c=>r.has(c)),i=o.nodes();let s=-1,a=!1;for(const c of i){const d=r.get(sr(c).datum());if(d<s){a=!0;break}s=d}if(!a)return;const l=typeof document<"u"?document.activeElement:null,u=t.node();o.sort((c,d)=>r.get(c)-r.get(d)),l&&u&&u.contains(l)&&typeof l.focus=="function"&&l.focus()}_bindPlaneGestures(t,n,r,o){if(t.on("click",i=>{if(this._suppressClick){this._suppressClick=!1;return}const[s,a]=n(i);r({type:"click",x:s,y:a,rawEvent:i})}).on("dblclick",i=>{const[s,a]=n(i);r({type:"dblclick",x:s,y:a,rawEvent:i})}),!o){this._abortPlaneGesture(),t.on("pointerdown",null).on("pointermove",null).on("pointerleave",null);return}this._planePointer=n,this._planeNode=t.node(),t.on("pointerdown",i=>{const[s,a]=n(i);this._planeGesture={startX:s,startY:a,down:!0,dragging:!1,pointerId:i.pointerId},this._trackPlaneGesture()}).on("pointermove",i=>{if(this._planeGesture)return;const[s,a]=n(i);r({type:"hover",x:s,y:a,rawEvent:i})}).on("pointerleave",i=>{this._planeGesture||r({type:"hoverout",rawEvent:i})})}_trackPlaneGesture(){if(this._planeTracking||typeof window>"u")return;const t=r=>this._planeMoved(r),n=r=>this._planeReleased(r);this._planeTracking={move:t,end:n},window.addEventListener("pointermove",t,!0),window.addEventListener("pointerup",n,!0),window.addEventListener("pointercancel",n,!0)}_releasePlaneTracking(){const t=this._planeTracking;!t||typeof window>"u"||(window.removeEventListener("pointermove",t.move,!0),window.removeEventListener("pointerup",t.end,!0),window.removeEventListener("pointercancel",t.end,!0),this._planeTracking=null)}_abortPlaneGesture(){this._releasePlaneTracking(),this._planeGesture=null}_planeMoved(t){const n=this._planeGesture;if(!n||!this._planePointer||!this._onEvent||n.pointerId!=null&&t.pointerId!==n.pointerId)return;if(t.pointerType==="mouse"&&t.buttons===0)return this._planeReleased(t);const[r,o]=this._planePointer(t);!n.dragging&&Math.hypot(r-n.startX,o-n.startY)>3&&(n.dragging=!0,this._onEvent({type:"dragstart",x:n.startX,y:n.startY,rawEvent:t})),n.dragging&&this._onEvent({type:"drag",x:r,y:o,rawEvent:t})}_planeReleased(t){const n=this._planeGesture;if(!n)return this._releasePlaneTracking();if(n.pointerId!=null&&t.pointerId!==n.pointerId||(this._releasePlaneTracking(),this._planeGesture=null,!this._planePointer||!this._onEvent))return;const[r,o]=this._planePointer(t);n.dragging&&(this._onEvent({type:"dragend",x:r,y:o,rawEvent:t}),this._suppressClick=!0),this._pointerOverPlane(t)||this._onEvent({type:"hoverout",rawEvent:t})}_pointerOverPlane(t){const n=this._planeNode;if(!n||typeof n.getBoundingClientRect!="function")return!1;const r=n.getBoundingClientRect();return t.clientX>=r.left&&t.clientX<=r.right&&t.clientY>=r.top&&t.clientY<=r.bottom}_makeKeyboard(t,n=!1){const r={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};return o=>{o.attr("tabindex",i=>i.editable?0:null).attr("role",i=>i.editable?"button":null).style("outline",n?null:"none").on("keydown",(i,s)=>{if(!s||!s.editable)return;const a=r[i.key];if(!a)return;i.preventDefault();const[l,u]=a;t({type:"nudge",node:s,dx:l,dy:u,coarse:!!i.shiftKey,rawEvent:i})})}}_makeHover(t,n){const r=!n||n.enabled!==!1;return o=>{o.on("pointerenter",(i,s)=>{!r||!s||!s.editable||t({type:"pointerover",node:s})}).on("pointerleave",(i,s)=>{!r||!s||!s.editable||t({type:"pointerout",node:s})})}}_makeDrag(t){return Xv().clickDistance(4).subject(n=>({x:n.x,y:n.y})).on("start",(n,r)=>{this._markDragLive=!0,t({type:"dragstart",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent})}).on("drag",(n,r)=>{const o=n.sourceEvent;if(o&&o.type==="mousemove"&&o.buttons===0){this._endMarkDrag(t,n,r);return}this._markDragLive&&t({type:"drag",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent})}).on("end",(n,r)=>{this._endMarkDrag(t,n,r)})}_endMarkDrag(t,n,r){this._markDragLive&&(this._markDragLive=!1,t({type:"dragend",x:n.x,y:n.y,node:r,rawEvent:n.sourceEvent}))}_applyStyle(t,n={}){for(const[r,o,i]of this.STYLE_ATTRS){const s=r in n?n[r]:i;t.attr(o,a=>a[r]!=null?a[r]:s)}return t.attr("data-ghost",r=>r.ghost?"":null),t.attr("data-hit",r=>r.hit?"":null),t.attr("data-channel",r=>r.channel!=null?r.channel:null),t}_applyEffectStyle(t,n="move"){for(const r of O0)r!=="cursor"&&t.style(HE(r),o=>o.effectStyle&&o.effectStyle[r]!=null?o.effectStyle[r]:null);return t.style("cursor",r=>r.effectStyle&&r.effectStyle.cursor!=null?r.effectStyle.cursor:r.editable?r.cursor||n:"default"),t}_angleTransform(t){if(t==null||t.angle==null||t.angle===0)return null;const n=Rn(t);return n?`rotate(${-t.angle} ${n.cx} ${n.cy})`:null}_geomRect(t){t.attr("x",n=>n.x).attr("y",n=>n.y).attr("width",n=>n.width).attr("height",n=>Math.max(0,n.height)).attr("rx",n=>n.rx!=null?n.rx:null).attr("ry",n=>n.ry!=null?n.ry:n.rx!=null?n.rx:null).attr("transform",n=>this._angleTransform(n))}_geomCircle(t){t.attr("cx",n=>n.cx).attr("cy",n=>n.cy).attr("r",n=>Math.max(0,n.r!=null?n.r:5)).attr("transform",n=>this._angleTransform(n))}_geomEllipse(t){t.attr("cx",n=>n.cx).attr("cy",n=>n.cy).attr("rx",n=>Math.max(0,n.rx!=null?n.rx:5)).attr("ry",n=>Math.max(0,n.ry!=null?n.ry:5)).attr("transform",n=>this._angleTransform(n))}_geomLine(t){t.attr("x1",n=>n.x1).attr("x2",n=>n.x2).attr("y1",n=>n.y1).attr("y2",n=>n.y2).attr("transform",n=>this._angleTransform(n))}_geomText(t,n="start"){t.attr("x",r=>r.x).attr("y",r=>r.y).attr("text-anchor",r=>r.textAnchor||n).attr("dominant-baseline",r=>r.dominantBaseline||null).attr("font-size",r=>r.fontSize!=null?r.fontSize:this._themeFontSize()).attr("transform",r=>this._angleTransform(r)),t.each(function(r){const o=sr(this),i=Array.isArray(r.lines)?r.lines:null;if(!i||i.length<=1){o.selectAll("tspan").remove(),o.text(i?i[0]||"":r.text);return}const s=r.fontSize!=null?r.fontSize:12,a=r.lineHeight!=null?r.lineHeight:Math.round(s*1.35),l=-(i.length-1)*a/2;o.text(null),o.selectAll("tspan").data(i).join("tspan").attr("x",r.x).attr("dy",(u,c)=>c===0?l:a).text(u=>u)})}_drawBackground(t,n,r,o,i,s=[],a=[]){t.selectAll("image").data(n,h=>h.key).join("image").style("pointer-events","none").attr("x",h=>h.x).attr("y",h=>h.y).attr("width",h=>h.width).attr("height",h=>h.height).attr("transform",h=>this._angleTransform(h)).attr("preserveAspectRatio","none").attr("href",h=>h.href).attr("opacity",h=>h.opacity!=null?h.opacity:null).lower();const u=t.selectAll("rect.bg-rect").data(s).join("rect").attr("class","bg-rect").style("pointer-events","none");this._geomRect(u),this._applyStyle(u,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const c=t.selectAll("circle.bg-circle").data(a).join("circle").attr("class","bg-circle").style("pointer-events","none");this._geomCircle(c),this._applyStyle(c,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const d=t.selectAll("line").data(o).join("line").style("pointer-events","none");this._geomLine(d),this._applyStyle(d,{stroke:"#6b7280",strokeWidth:1,opacity:1});const f=t.selectAll("text").data(i).join("text").style("pointer-events","none");this._geomText(f,"middle"),this._applyStyle(f,{fill:"#374151",opacity:1});const p=t.selectAll("path.bg-path").data(r).join("path").attr("class","bg-path").style("pointer-events","none").attr("d",h=>h.d?h.d:_i().curve(Ni(h.curve))(h.points||[]));this._applyStyle(p,{fill:"none",stroke:"black",strokeWidth:1,opacity:1})}_drawGuideRegions(t,n){const r=t.selectAll("rect.guide-region").data(n).join("rect").attr("class","guide-region").style("pointer-events","none");this._geomRect(r),this._applyStyle(r,{fill:"none",stroke:"none",strokeWidth:1,opacity:1})}_drawGuideFront(t,n){const r=u=>n.filter(c=>c.type===u),o=t.selectAll("line.guide-line").data(r("line")).join("line").attr("class","guide-line").style("pointer-events","none");this._geomLine(o),this._applyStyle(o,{stroke:"black",strokeWidth:1,opacity:1});const i=t.selectAll("circle.guide-circle").data(r("circle")).join("circle").attr("class","guide-circle").style("pointer-events","none");this._geomCircle(i),this._applyStyle(i,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});const s=t.selectAll("path.guide-path").data(r("path")).join("path").attr("class","guide-path").style("pointer-events","none").attr("d",u=>u.d?u.d:_i().curve(Ni(u.curve))(u.points||[]));this._applyStyle(s,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});const a=t.selectAll("text.guide-label").data(r("text")).join("text").attr("class","guide-label").style("pointer-events","none");this._geomText(a,"start"),this._applyStyle(a,{fill:"black",opacity:1});const l=new Map(n.map((u,c)=>[u,c]));t.selectAll("line.guide-line, circle.guide-circle, path.guide-path, text.guide-label").filter(u=>l.has(u)).sort((u,c)=>l.get(u)-l.get(c))}_drawEffects(t,n){const r=d=>n.filter(f=>f.type===d),o={fill:"none",stroke:"none",strokeWidth:1,opacity:1},i=t.selectAll("circle.effect").data(r("circle")).join("circle").attr("class","effect").style("pointer-events","none");this._geomCircle(i),this._applyStyle(i,o);const s=t.selectAll("rect.effect").data(r("rect")).join("rect").attr("class","effect").style("pointer-events","none");this._geomRect(s),this._applyStyle(s,o);const a=t.selectAll("ellipse.effect").data(r("ellipse")).join("ellipse").attr("class","effect").style("pointer-events","none");this._geomEllipse(a),this._applyStyle(a,o);const l=t.selectAll("line.effect").data(r("line")).join("line").attr("class","effect").style("pointer-events","none");this._geomLine(l),this._applyStyle(l,o);const u=t.selectAll("path.effect").data(r("path")).join("path").attr("class","effect").style("pointer-events","none").attr("d",d=>d.d?d.d:_i().curve(Ni(d.curve))(d.points||[]));this._applyStyle(u,o);const c=new Map(n.map((d,f)=>[d,f]));t.selectAll("circle.effect, rect.effect, ellipse.effect, line.effect, path.effect").filter(d=>c.has(d)).sort((d,f)=>c.get(d)-c.get(f))}_dblClick(t){return(n,r)=>{if(r&&r.editText){n.preventDefault(),n.stopPropagation(),this._editText(n,r);return}t&&t(n,r)}}_drawMarks(t,n,r,{drag:o,markClick:i,markDblClick:s,keys:a,hover:l}){const u=t.selectAll("rect.mark").data(n).join("rect").attr("class","mark").style("pointer-events",p=>p.pointerEvents||"auto").style("cursor",p=>p.editable?p.cursor||"ns-resize":"default").on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).call(a);this._geomRect(u),this._applyStyle(u,{fill:"black"}),this._applyEffectStyle(u,"ns-resize");const c=n.filter(p=>p.editable&&p.pointerEvents!=="none"&&((p.width||0)<fl||(p.height||0)<fl));t.selectAll("rect.mark-hit").data(c).join("rect").attr("class","mark-hit").style("pointer-events","all").style("fill","transparent").style("cursor",p=>p.cursor||"ns-resize").attr("x",p=>Ci(p).x).attr("y",p=>Ci(p).y).attr("width",p=>Ci(p).w).attr("height",p=>Ci(p).h).attr("transform",p=>this._angleTransform(p)).on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).lower();const f=t.selectAll("circle.mark").data(r).join("circle").attr("class","mark").style("pointer-events",p=>p.pointerEvents||"auto").style("cursor",p=>p.editable?p.cursor||"move":"default").on("click",i).on("dblclick",this._dblClick(s)).call(o).call(l).call(a);this._geomCircle(f),this._applyStyle(f,{fill:"black"}),this._applyEffectStyle(f,"move")}_drawEllipses(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("ellipse.mark").data(n).join("ellipse").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomEllipse(l),this._applyStyle(l,{fill:"black"}),this._applyEffectStyle(l,"move")}_drawLines(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("line.mark").data(n).join("line").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomLine(l),this._applyStyle(l,{stroke:"black",strokeWidth:1,opacity:1}),this._applyEffectStyle(l,"move")}_drawPaths(t,n,r){const o=t.selectAll("path.mark-line").data(n).join("path").attr("class","mark-line").style("pointer-events",i=>i.pointerEvents||(i.editable?"auto":"none")).style("cursor",i=>i.editable?i.cursor||"pointer":"default").attr("d",i=>i.d?i.d:_i().curve(Ni(i.curve))(i.points||[]));this._applyStyle(o,{fill:"none",stroke:"black",strokeWidth:1,opacity:1}),this._applyEffectStyle(o,"pointer"),r&&o.on("click",r.markClick).on("dblclick",this._dblClick(r.markDblClick)).call(r.drag).call(r.hover).call(r.keys)}_drawTextMarks(t,n,{drag:r,markClick:o,markDblClick:i,keys:s,hover:a}){const l=t.selectAll("text.mark").data(n).join("text").attr("class","mark").style("pointer-events",u=>u.pointerEvents||"auto").style("cursor",u=>u.editable?u.cursor||"move":"default").on("click",o).on("dblclick",this._dblClick(i)).call(r).call(a).call(s);this._geomText(l,"middle"),this._applyStyle(l,{fill:"black",opacity:1}),this._applyEffectStyle(l,"move")}_editText(t,n){if(!n||!n.editText)return;const r=this._sceneG,o=this._onEvent;if(!r||!o)return;r.selectAll("foreignObject.text-editor").remove();const i=n.fontSize!=null?n.fontSize:12,s=n.editBox||(n.type==="rect"&&n.width!=null?{x:n.x,y:n.y,width:n.width,height:Math.max(0,n.height)}:null),a=s?s.width:140,l=s?s.height:i+10,u=s?s.x:n.x-a/2,c=s?s.y:n.y-l+4,d=r.append("foreignObject").attr("class","text-editor").attr("x",u).attr("y",c).attr("width",a).attr("height",l),f=!!n.multiline,p=d.append(f?"xhtml:textarea":"xhtml:input").attr("type",f?null:"text").style("width","100%").style("height",f?"100%":null).style("box-sizing","border-box").style("font-size",i+"px").style("font-family","inherit").style("text-align","center").style("resize",f?"none":null).node();p.value=n.text!=null?String(n.text):n.editValue!=null?String(n.editValue):"",p.focus(),f?p.setSelectionRange(p.value.length,p.value.length):p.select();let h=!1;const y=()=>{if(h)return;h=!0;const m=p.value;d.remove(),o({type:"commit",node:n,value:m,x:n.x,y:n.y,rawEvent:t})},g=()=>{h||(h=!0,d.remove())};p.addEventListener("keydown",m=>{m.key==="Enter"?(!f||m.metaKey||m.ctrlKey)&&(m.preventDefault(),y()):m.key==="Escape"&&(m.preventDefault(),g()),m.stopPropagation()}),p.addEventListener("blur",y)}}const Q0=As.axis,od=As.grid,Hp=e=>e instanceof Date?e.getTime():e;function Up({x:e,y:t,textAnchor:n,v:r,format:o,fill:i,fontSize:s}){return{type:"text",x:e,y:t,text:o(r),textAnchor:n,fill:i,fontSize:s,category:r,editText:!0,index:0,cursor:"text"}}function Kp({x:e,y:t,v:n,fontSize:r}){return{type:"text",x:e,y:t,text:"×",textAnchor:"middle",fill:"#dc2626",fontSize:r+1,cursor:"pointer",removeCategory:n,index:0}}function UE(e,t,n){switch(e){case"top":return{x:0,y:0};case"bottom":return{x:0,y:n};case"left":return{x:0,y:0};case"right":return{x:t,y:0};default:return{x:0,y:0}}}function Ql(e,t={}){const{ticks:n=5,tickValues:r,tickFormat:o}=t,i=e.kind!=="continuous";let s;r?s=r:i?s=e.domain():typeof e.ticks=="function"?s=e.ticks(n):s=e.domain();let a;return typeof o=="function"?a=o:typeof o=="string"?a=ti(o):!i&&typeof e.tickFormat=="function"?a=e.tickFormat(n):a=l=>`${l}`,{values:s,format:a}}function ec(e={}){Cs("axis",e,Q0);const{channel:t="x",anchor:n=t==="x"?"bottom":"left",transform:r,ticks:o=5,tickValues:i,tickFormat:s,tickSize:a=6,title:l,stroke:u,fill:c,fontSize:d,grid:f=!1,field:p,table:h,handleColor:y,handleSize:g,id:m}=e,b=t==="x"||t!=="y"&&(n==="bottom"||n==="top"),w=Wi(e,t),x=w.length>0;return{id:m,type:"axis",isAxis:!0,views:"scale",channel:t,layer:"background",edits:w,field:p,table:h,grid:f,build:(S,v,k,_)=>{const T=v[t];if(!T)return[];const L=it(v),N=u??L.axis.stroke,I=c??L.axis.labelFill,O=d??L.axis.fontSize,M=fn(v,{handles:!0,handleSize:g,handleColor:y??L.axis.handle}),$=M.fill,F=M.size,D=M.stroke,z=UE(n,k,_),j=r?{...z,...r({width:k,height:_,scales:v,anchor:n,base:z})||{}}:z,{values:G,format:J}=Ql(T,{ticks:o,tickValues:i,tickFormat:s}),re=n==="bottom"||n==="right"?1:-1,Q=[],ve=x&&fo(T),Ce=x&&T.kind==="continuous";b?Q.push({type:"line",x1:j.x,x2:j.x+k,y1:j.y,y2:j.y,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"}):Q.push({type:"line",x1:j.x,x2:j.x,y1:j.y,y2:j.y+_,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});for(const le of G){const me=Mr(T,le);if(!(me==null||Number.isNaN(me)))if(b){const ce=j.x+me;Q.push({type:"line",x1:ce,x2:ce,y1:j.y,y2:j.y+re*a,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});const Y=j.y+re*(a+O);Q.push(ve?Up({x:ce,y:Y,textAnchor:"middle",v:le,format:J,fill:I,fontSize:O}):{type:"text",x:ce,y:Y,text:J(le),textAnchor:"middle",fill:I,fontSize:O,background:!0,pointerEvents:"none"}),ve&&Q.push(Kp({x:ce,y:Y+O,v:le,fontSize:O}))}else{const ce=j.y+me;Q.push({type:"line",x1:j.x,x2:j.x+re*a,y1:ce,y2:ce,stroke:N,strokeWidth:1,background:!0,pointerEvents:"none"});const Y=j.x+re*(a+3);Q.push(ve?Up({x:Y,y:ce+O/3,textAnchor:re<0?"end":"start",v:le,format:J,fill:I,fontSize:O}):{type:"text",x:Y,y:ce+O/3,text:J(le),textAnchor:re<0?"end":"start",fill:I,fontSize:O,background:!0,pointerEvents:"none"}),ve&&Q.push(Kp({x:Y+re*(O+4),y:ce+O/3,v:le,fontSize:O}))}}if(ve){const le=b?j.x+k+O:j.x,me=b?j.y+re*(a+O):j.y+_+re*(a+O);Q.push({type:"text",x:le,y:me,text:"+",textAnchor:"middle",fill:$,fontSize:O+4,cursor:"pointer",addCategory:!0,editText:!0,index:0})}else if(Ce){const le=typeof T.domain=="function"?T.domain():[],me=le[0],ce=le[le.length-1],Y=fe=>(b?j.x:j.y)+Mr(T,fe);for(const fe of["min","max"]){const ie=fe==="max"?ce:me,U=fe==="max"?me:ce,we=Y(ie),xe=Y(U),P=Hp(ie)-Hp(U)||1;Q.push({type:"circle",cx:b?j.x+Mr(T,ie):j.x,cy:b?j.y:j.y+Mr(T,ie),r:F,fill:$,stroke:D,strokeWidth:M.strokeWidth,axisHandle:!0,handle:fe,axis:t,anchorPixel:xe,anchorValue:U,grabPixel:we,grabValue:ie,pxPerUnit:(we-xe)/P,cursor:b?"ew-resize":"ns-resize"})}}return l&&(b?Q.push({type:"text",x:j.x+k/2,y:j.y+re*(a+O*2.4),text:l,textAnchor:"middle",fill:I,fontSize:O+1,background:!0,pointerEvents:"none"}):Q.push({type:"text",x:j.x+re*(a+O*2.4),y:j.y+_/2,text:l,textAnchor:"middle",fill:I,fontSize:O+1,background:!0,pointerEvents:"none"})),Q}}}function id(e={}){Cs("grid",e,od);const{channel:t="x",ticks:n=5,tickValues:r,stroke:o,strokeWidth:i,id:s}=e,a=t==="x";return{id:s,type:"grid",isGrid:!0,views:"scale",channel:t,layer:"background",build:(l,u,c,d)=>{const f=u[t];if(!f)return[];const p=it(u),h=o??p.grid.stroke,y=i??p.grid.strokeWidth,{values:g}=Ql(f,{ticks:n,tickValues:r}),m=[];for(const b of g){const w=Mr(f,b);w==null||Number.isNaN(w)||(a?m.push({type:"line",x1:w,x2:w,y1:0,y2:d,stroke:h,strokeWidth:y,background:!0,pointerEvents:"none"}):m.push({type:"line",x1:0,x2:c,y1:w,y2:w,stroke:h,strokeWidth:y,background:!0,pointerEvents:"none"}))}return m}}}const eb=(e={})=>ec({...e,channel:"x"}),tb=(e={})=>ec({...e,channel:"y"}),nb=(e={})=>id({...e,channel:"x"}),rb=(e={})=>id({...e,channel:"y"});function KE(e){const t={};for(const n of od)e[n]!==void 0&&(t[n]=e[n]);return t}function YE(e){return(e||[]).flat(1/0).filter(t=>t&&typeof t=="object")}function GE(e){return({scales:t})=>{if(e==="x"){const o=t.y;if(!o)return{};const i=typeof o.encode=="function"?o.encode(0):o(0);return i!=null&&!Number.isNaN(Number(i))?{y:Number(i)}:{}}const n=t.x;if(!n)return{};const r=typeof n.encode=="function"?n.encode(0):n(0);return r!=null&&!Number.isNaN(Number(r))?{x:Number(r)}:{}}}function VE(e,t){if(t===!1)return[];const n=YE(e),r=t&&typeof t=="object"?t.origin:void 0,o=r===!0||r===void 0&&t==null&&n.some(l=>l.isTrend),i=[],s=l=>n.some(u=>(u.isAxis||u.isGrid)&&u.channel===l),a={x:{axis:eb,grid:nb},y:{axis:tb,grid:rb}};if(t&&t.count&&!s("count")){const l=n.find(u=>u.countAxis);if(l){const u=t.count===!0?{}:{...t.count};i.push(ec({anchor:l.countAxis==="x"?"bottom":"left",...u,channel:"count"}))}}for(const l of["x","y"]){const u=t?t[l]:void 0;if(u===!1||s(l))continue;const c=u?{...u}:{};o&&c.transform==null&&(c.transform=GE(l)),i.push(a[l].axis(c)),c.grid&&i.push(a[l].grid(KE(c)))}return i}const ob=As.legend,Co=e=>e instanceof Date?e.getTime():e,XE=e=>e==="fill"||e==="stroke";function JE(e){return e.kind==="continuous"||!!e.ramp}function ZE(e,t){return JE(t)?e==="size"?"graduated":e==="theta"?"fan":e==="strokeWidth"?"weights":"ramp":"swatches"}function Yp(e,t,n,r){if(e!=="size")return r;let o=0;for(const i of n){const s=Number(typeof t.encode=="function"?t.encode(i):t(i));Number.isFinite(s)&&(o=Math.max(o,s))}return Math.max(r,2*o)}function Gp(e,t,n){if(e===!1||e===null)return null;if(e!=null)return String(e);const r=t??(n&&n.fields&&n.fields[0]||null);return r==null?null:String(r)}function QE(e,t,n){let r=0;for(const o of e)r=Math.max(r,String(t(o)).length);return Math.ceil(r*n*.6)}function Ns(e={}){Cs("legend",e,ob);const{channel:t="fill",anchor:n="right",orient:r,swatchSize:o=14,gap:i=6,labelWidth:s,rampLength:a=140,rampThickness:l=12,ticks:u=4,tickFormat:c,title:d,row:f,stroke:p,fill:h,fontSize:y,handleColor:g,handleSize:m,field:b,table:w,id:x}=e,S=r||(n==="left"||n==="right"?"vertical":"horizontal"),v=S==="vertical",k=Wi(e,t),_=k.length>0,T=k.some(O=>O.target==="domain"),L=O=>O[uo(t,b)]||O[t],N={offset:0,size:0},I=(O,M)=>{const $=y??(M.guide.legend.fontSize||11),F=ZE(t,O),D=F!=="swatches";let z,j;if(D){const J=O.domain(),re=ji().domain([Math.min(...J.map(Co)),Math.max(...J.map(Co))]);z=re.ticks(u),j=typeof c=="string"?ti(c):typeof c=="function"?c:re.tickFormat(u)}else z=O.domain(),j=c?Ql(O,{tickFormat:c}).format:J=>`${J}`;const G=s??QE(z,j,$);return{ramp:D,form:F,values:z,format:j,labelW:G,fontSize:$}};return{id:x,type:"legend",isLegend:!0,views:"scale",channel:t,anchor:n,orient:S,layer:"background",edits:k,field:b,table:w,_place:N,measure(O){const M=L(O);if(!M||typeof M.domain!="function")return null;const $=it(O),{form:F,values:D,labelW:z,fontSize:j}=I(M,$),J=Gp(d,b,M)?j+4:0;if(F==="graduated"){const le=ib(M,D);if(!le.length)return{width:z,height:j+J};const me=le[le.length-1].r,ce=le.reduce((Y,fe)=>Y+2*fe.r+i,0);return v?{width:2*me+6+z,height:ce+J}:{width:le.reduce((Y,fe)=>Y+2*fe.r+6+z+i,0),height:2*me+j+J}}if(F==="fan"){const le=sb(M,D,z,j);return{width:le.width,height:le.height+J}}if(F==="weights"){const le=D.reduce((me,ce)=>{const Y=Number(typeof M.encode=="function"?M.encode(ce):M(ce));return me+Math.max(Number.isFinite(Y)?Y:0,j)+i},0);return{width:2*fs+6+z,height:le+J}}if(F==="ramp")return v?{width:l+6+z,height:a+J}:{width:a,height:l+6+j+J};const re=(D.length||1)+(T?1:0),Q=T?j+6:0,ve=Yp(t,M,D,o);if(v)return{width:ve+4+z+Q,height:re*(ve+i)+J};const Ce=ve+4+z+Q+i;return{width:re*Ce,height:ve+i+J}},build(O,M,$,F){const D=L(M);if(!D||typeof D.domain!="function")return[];const z=D.domain();if(!z.length)return[];_&&b==null&&!(D.fields||[]).length&&ge(`legend:field:${t}`,`legend({ channel: "${t}", edit: … }) can't tell which column to write: no mark binds a field to "${t}", so the scale carries none and the edit is a no-op. Pin it with legend({ field: "…" }), or bind the channel on a mark.`);const j=it(M),G=p??(j.guide.legend.stroke||"#374151"),J=h??(j.guide.legend.labelFill||"#374151"),re=fn(M,{handles:!0,handleSize:m,handleColor:g??j.axis.handle}),Q=re.fill,ve=re.size,Ce=re.stroke,{form:le,values:me,format:ce,labelW:Y,fontSize:fe}=I(D,j),ie=N.size||(this.measure(M)||{width:0,height:0})[v?"width":"height"];let U=0,we=0;n==="right"?U=$+N.offset:n==="left"?U=-(N.offset+ie):n==="bottom"?we=F+N.offset:n==="top"&&(we=-(N.offset+ie));const xe=[];let P=we;const H=Gp(d,b,D);H&&(xe.push({type:"text",x:U,y:we+fe,text:H,textAnchor:"start",fill:J,fontSize:fe+1,background:!0,pointerEvents:"none"}),P=we+fe+4);const oe=M.selection,he=M.selectionAll,ke=typeof he=="function"?he(this.table):oe!=null?[oe]:[];let pe;if(f!=null&&f!=="selection"){const ae=typeof f=="function"?f(O,{selection:oe}):f;pe=ae==null?[]:Array.isArray(ae)?ae:[ae]}else ke.length?pe=ke:pe=O.length===1?[0]:[];const _e=pe.filter(ae=>Number.isInteger(ae)&&ae>=0&&ae<O.length),Te=_e.length?_e[0]:null,Se={scale:D,values:me,format:ce,cx0:U,cy0:P,vertical:v,anchor:n,fontSize:fe,swatchStroke:G,labelFill:J,editable:_,domainEditable:T,handleColor:Q,data:O,channel:t,field:b,targetRow:Te,targetRows:_e,currentStroke:j.guide.legend.currentStroke||"#111827",currentWidth:j.guide.legend.currentWidth??2};return le==="graduated"?e6(xe,{...Se,gap:i}):le==="fan"?t6(xe,{...Se,labelW:Y}):le==="weights"?n6(xe,{...Se,gap:i}):le==="ramp"?i6(xe,{...Se,rampLength:a,rampThickness:l,handleColor:Q,handleSize:ve,handleStroke:Ce}):o6(xe,{...Se,domain:z,swatchSize:Yp(t,D,z,o),gap:i,labelW:Y}),xe}}}function ib(e,t){const n=[];for(const r of t){const o=Number(typeof e.encode=="function"?e.encode(r):e(r));!Number.isFinite(o)||o<1||n.push({v:r,r:o})}return n.sort((r,o)=>r.r-o.r),n}function e6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,vertical:a,gap:l,labelFill:u,fontSize:c,swatchStroke:d}=t,f=ib(n,r);if(!f.length)return;const p=f[f.length-1].r;let h=0;for(const{v:y,r:g}of f){const m=a?i+p:i+h+g,b=a?s+h+g:s+p;e.push({type:"circle",cx:m,cy:b,r:g,fill:"none",stroke:d,strokeWidth:1,background:!0,pointerEvents:"none"}),e.push({type:"text",x:a?i+2*p+6:m,y:a?b+c*.35:s+2*p+c,text:String(o(y)),fill:u,fontSize:c,textAnchor:a?"start":"middle",background:!0,pointerEvents:"none"}),h+=2*g+l}}const fs=22;function sb(e,t,n,r){const o=[];let i=0,s=0,a=0,l=0;for(const u of t){const c=Number(typeof e.encode=="function"?e.encode(u):e(u));if(!Number.isFinite(c))continue;const d=c*Math.PI/180,f=Math.cos(d)*fs,p=-Math.sin(d)*fs,h=f+Math.cos(d)*6,y=p-Math.sin(d)*6,g=Math.cos(d)<-.1?"end":Math.cos(d)>.1?"start":"middle";o.push({v:u,tx:f,ty:p,lx:h,ly:y,anchor:g});const m=g==="end"?h-n:g==="middle"?h-n/2:h,b=g==="end"?h:g==="middle"?h+n/2:h+n;i=Math.min(i,f,m),s=Math.max(s,f,b),a=Math.min(a,p,y-r),l=Math.max(l,p,y+r*.5)}return{spokes:o,width:s-i,height:l-a,ox:-i,oy:-a}}function t6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,labelFill:a,fontSize:l,swatchStroke:u,labelW:c}=t,{spokes:d,ox:f,oy:p}=sb(n,r,c,l),h=i+f,y=s+p;for(const g of d)e.push({type:"line",x1:h,y1:y,x2:h+g.tx,y2:y+g.ty,stroke:u,strokeWidth:1.5,background:!0,pointerEvents:"none"}),e.push({type:"text",x:h+g.lx,y:y+g.ly+l*.35,text:String(o(g.v)),fill:a,fontSize:l,textAnchor:g.anchor,background:!0,pointerEvents:"none"})}function n6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,gap:a,labelFill:l,fontSize:u,swatchStroke:c}=t,d=[];for(const p of r){const h=Number(typeof n.encode=="function"?n.encode(p):n(p));Number.isFinite(h)&&h>0&&d.push({v:p,w:h})}d.sort((p,h)=>p.w-h.w);let f=0;for(const{v:p,w:h}of d){const y=s+f+h/2;e.push({type:"line",x1:i,y1:y,x2:i+fs*2,y2:y,stroke:c,strokeWidth:h,background:!0,pointerEvents:"none"}),e.push({type:"text",x:i+fs*2+6,y:y+u*.35,text:String(o(p)),fill:l,fontSize:u,textAnchor:"start",background:!0,pointerEvents:"none"}),f+=Math.max(h,u)+a}}function r6({channel:e,x:t,y:n,size:r,encoded:o,stroke:i,ink:s,interactive:a}){const l=a?{}:{background:!0,pointerEvents:"none"};if(e==="symbol")return{type:"text",x:t+r/2,y:n+r/2,text:String(o),fontSize:r,textAnchor:"middle",dominantBaseline:"central",...l};if(e==="size"){const u=Math.max(1,Number(o)||r/2);return{type:"circle",cx:t+r/2,cy:n+r/2,r:u,fill:s,stroke:i,strokeWidth:1,...l}}return e==="opacity"?{type:"rect",x:t,y:n,width:r,height:r,fill:s,fillOpacity:Number(o),stroke:i,strokeWidth:1,...l}:{type:"rect",x:t,y:n,width:r,height:r,fill:o,stroke:i,strokeWidth:1,...l}}function o6(e,t){const{domain:n,cx0:r,cy0:o,vertical:i,swatchSize:s,gap:a,fontSize:l,swatchStroke:u,labelFill:c,editable:d,domainEditable:f,handleColor:p,targetRow:h,targetRows:y,scale:g,channel:m,data:b,field:w,currentStroke:x,currentWidth:S}=t,v=d&&h!=null,k=v||f,_=h??0,T=w??(g.fields&&g.fields[0]||null),L=new Set;if(v&&T!=null)for(const $ of y){const F=b&&b[$];F&&F[T]!==void 0&&L.add(F[T])}const N=f?l+6:0,I=s+4+t.labelW+N+a,O=s+a,M=$=>({sx:i?r:r+$*I,sy:i?o+$*O:o});if(n.forEach(($,F)=>{const D=typeof g.encode=="function"?g.encode($):typeof g=="function"?g($):$,{sx:z,sy:j}=M(F),G=r6({channel:m,x:z,y:j,size:s,encoded:D,stroke:u,ink:c,interactive:k});k&&(G.category=$,G.index=_,G.indices=y,G.cursor=f&&!v?"text":"pointer",f&&(G.editText=!0,G.editValue=String($))),e.push(G),L.has($)&&e.push({type:"rect",x:z-2.5,y:j-2.5,width:s+5,height:s+5,fill:"none",stroke:x,strokeWidth:S,rx:2,effect:!0,background:!0,pointerEvents:"none"}),e.push({type:"text",x:z+s+4,y:j+s*.75,text:String(t.format($)),fill:c,fontSize:l,textAnchor:"start",background:!0,pointerEvents:"none"}),f&&e.push({type:"text",x:z+s+4+t.labelW+l*.5,y:j+s*.75,text:"×",textAnchor:"middle",fill:"#dc2626",fontSize:l+1,cursor:"pointer",removeCategory:$,index:0})}),f){const{sx:$,sy:F}=M(n.length);e.push({type:"text",x:$+s/2,y:F+s*.75,text:"+",textAnchor:"middle",fill:p,fontSize:l+4,cursor:"pointer",addCategory:!0,editText:!0,index:0})}}function i6(e,t){const{scale:n,values:r,format:o,cx0:i,cy0:s,vertical:a,rampLength:l,rampThickness:u,fontSize:c,swatchStroke:d,labelFill:f,handleColor:p,handleSize:h,handleStroke:y,editable:g,data:m,targetRow:b,targetRows:w,channel:x,field:S}=t,v=n.domain(),k=Math.min(...v.map(Co)),_=Math.max(...v.map(Co)),T=_-k||1,L=40,N=a?"y":"x",I=a?s+l:i,O=a?s:i+l,M=XE(x),$=x==="opacity"||x==="fillOpacity"||x==="strokeOpacity",F=D=>M?{fill:D}:$?{fill:f,fillOpacity:Number(D)}:{fill:"#94a3b8"};for(let D=0;D<L;D++){const z=D/L,j=(D+1)/L,G=k+(z+j)/2*T,J=typeof n.encode=="function"?n.encode(G):n(G);if(a){const re=s+(1-j)*l;e.push({type:"rect",x:i,y:re,width:u,height:l/L+.5,...F(J),stroke:"none",background:!0,pointerEvents:"none"})}else{const re=i+z*l;e.push({type:"rect",x:re,y:s,width:l/L+.5,height:u,...F(J),stroke:"none",background:!0,pointerEvents:"none"})}}e.push({type:"rect",x:i,y:s,width:a?u:l,height:a?l:u,fill:"none",stroke:d,strokeWidth:1,background:!0,pointerEvents:"none"});for(const D of r){const z=(Co(D)-k)/T;if(!(z<-.001||z>1.001))if(a){const j=s+(1-z)*l;e.push({type:"text",x:i+u+4,y:j+c*.35,text:String(o(D)),fill:f,fontSize:c,textAnchor:"start",background:!0,pointerEvents:"none"})}else{const j=i+z*l;e.push({type:"text",x:j,y:s+u+c+2,text:String(o(D)),fill:f,fontSize:c,textAnchor:"middle",background:!0,pointerEvents:"none"})}}if(g&&b!=null){const D=S??(n.fields&&n.fields[0]||null),z=D!=null?m[b]&&m[b][D]:null,j=z==null?.5:Math.max(0,Math.min(1,(Co(z)-k)/T)),G=a?i+u/2:i+j*l,J=a?s+(1-j)*l:s+u/2;e.push({type:"circle",cx:G,cy:J,r:h,fill:p,stroke:y,strokeWidth:1.5,index:b,indices:w,along:N,rampStart:I,rampEnd:O,loValue:k,hiValue:_,cursor:a?"ns-resize":"ew-resize"})}}const s6=(e={})=>Ns({...e,channel:e.channel||"fill"}),a6=(e={})=>Ns({...e,channel:"size"}),l6=(e={})=>Ns({...e,channel:"symbol"}),Bc=["fill","stroke","size","symbol","opacity","theta","strokeWidth"];function c6(e){const t=(e||[]).flat(1/0).filter(r=>r&&typeof r=="object"),n=[];for(const r of t){if(r.views==="scale"||!r.channels)continue;const o=new Set(r.rawChannels||[]);for(const[i,s]of Object.entries(r.channels)){const a=s;!a||a.field==null||a.scale===null||o.has(i)||Gr(a)||n.some(l=>l.channel===i&&l.field===a.field)||n.push({channel:i,field:a.field,table:r.table,tableRole:r.tableRole,spec:a,feature:r})}}return n}function u6(e,t){const n=(e||[]).flat(1/0).filter(l=>l&&typeof l=="object"),r=c6(e),o=l=>r.filter(u=>u.channel===l),i=n.filter(l=>l.isLegend);for(const l of i){if(l.field!=null)continue;const u=o(l.channel);u.length&&(u.length>1&&ge(`legend:ambiguous:${l.channel}`,`legend({ channel: "${l.channel}" }) — "${l.channel}" carries ${u.length} encodings (${u.map(c=>`"${c.field}"`).join(", ")}), and a legend is a key for one. Name which: legend({ channel: "${l.channel}", field: "${u[0].field}" }). Using "${u[0].field}".`),l.field=u[0].field,l.table==null&&(l.table=u[0].table),l.tableRole==null&&(l.tableRole=u[0].tableRole))}const s=(l,u)=>i.find(c=>c.channel===l&&c.field===u),a=[];for(const l of r){const{channel:u,field:c,spec:d}=l,f=d.legend;if(f===!1||f===null)continue;const p=[d.edit].flat(1/0).filter(S=>S&&typeof S.apply=="function"),h=p.filter(S=>S.scope==="legend");let y;if(f!==void 0)y=f===!0?{}:f;else if(h.length)y={};else{if(!t)continue;const S=t===!0?void 0:t[u];if(S===!1||t!==!0&&S===void 0||!Bc.includes(u))continue;y=S||{}}if(!Bc.includes(u)){ge(`legend:channel:${u}`,`a legend was asked for on channel "${u}", which has no legend form. Legendable channels are ${Bc.join(", ")}.`+(u==="x"||u==="y"?" An axis is the key for x/y.":""));continue}if(h.length){const S=p.filter(k=>k.scope!=="legend"),v={...d};S.length?v.edit=S.length===1?S[0]:S:delete v.edit,l.feature.channels[u]=v}const g=s(u,c);if(g){const S=[...h,...Wi(y,u)];S.length&&(g.edits=[...g.edits||[],...Wi({edits:S},u)]);for(const[v,k]of Object.entries(y))v==="edit"||v==="edits"||g[v]===void 0&&(g[v]=k);continue}const{edit:m,edits:b,...w}=y,x=Ns({...w,channel:u,field:c,table:l.table,edits:[...Wi(y,u),...h]});x.tableRole=l.tableRole,a.push(x)}return a}function f6(e,t,n,r=8){const o={top:0,right:0,bottom:0,left:0},i=(e||[]).filter(a=>a&&a.isLegend&&typeof a.measure=="function");if(!i.length)return o;const s={top:n.top+r,right:n.right+r,bottom:n.bottom+r,left:n.left+r};for(const a of i){const l=a.anchor||"right",c=t[uo(a.channel,a.field)]||t[a.channel]?a.measure(t):null;if(!c){a._place.offset=0,a._place.size=0;continue}const d=a.orient==="vertical"?c.width:c.height;a._place.offset=s[l],a._place.size=d,s[l]+=d+r,o[l]+=d+r}return o}function nt(e){return e?e.id&&!e.autoId?`"${e.id}"`:e.type?`${e.type}()`:e.id?`"${e.id}"`:"(an unnamed mark)":"(unknown mark)"}const d6={line:{flag:"supportsSeries",expects:"a line mark (line/area)"},geo:{flag:"supportsGeo",expects:"a geo* mark (geoPoint, geoLine, …)"},stack:{flag:"supportsStack",expects:"a stacked mark (bar with `stack`, or arc/donut)"},waffle:{flag:"supportsWaffle",expects:"a waffle mark"},axis:{flag:"isAxis",expects:"an axis element (axisX/axisY/axisRadial)"},trend:{flag:"supportsTrend",expects:"a trend mark (trend/trendBand)"},network:{flag:"supportsNetwork",expects:"a link mark"},legend:{flag:"isLegend",expects:"a legend element"},scale:{test:e=>e.views==="scale",expects:"an axis or legend element"}},h6={discrete:e=>e==="band"||e==="point",band:e=>e==="band",point:e=>e==="point",continuous:e=>e==="continuous"};function p6(e,t){const n=e&&e.requires;if(Array.isArray(n))for(const r of n){const o=h6[r.kind];if(!o)continue;const i=r.channels||[],s=c=>{const d=t[c];return!!(d&&o(d.kind))};if(r.match==="any"?i.some(s):i.every(s))continue;const l=r.match==="any"?`one of ${i.map(c=>`"${c}"`).join(" / ")}`:i.map(c=>`"${c}"`).join(" and "),u=i.map(c=>{const d=t[c];return`${c}: ${d?d.kind:"no scale"}`}).join(", ");ge(`requires:${nt(e)}:${r.kind}:${i.join(",")}`,`mark ${nt(e)} needs a ${r.kind} scale on ${l}, but got ${u}. ${r.why||""} It will still draw, using fallback geometry that is not meaningful — declare the field's type on the spec's schema so the right scale resolves.`)}}function y6(e,t){for(const n of t){if(!n.scope)continue;const r=d6[n.scope];r&&((r.test?r.test(e):e[r.flag])||ge(`${nt(e)}:${n.type}`,`edit.${n.type}() is attached to a mark without ${n.scope} support (mark ${nt(e)}). ${n.scope}-scoped edits expect ${r.expects}; it may not behave.`))}}function g6(e,t){if(!t.projection)return;const n=e.filter(r=>{if(r.supportsGeo||r.views==="scale")return!1;const o=r.channels||{};return Object.keys(o).some(i=>_t(i)&&o[i]&&o[i].scale!==null)});n.length&&ge(`projcartesian:${n.map(nt).join(",")}`,`spec.projection is set together with cartesian x/y channels on ${n.map(nt).join(", ")}. Projection charts use geo* marks (geoPoint, geoLine, …); mixing ordinary positional marks is unsupported.`)}function m6(e,t,n){const r={};for(const o of e)for(const i of t(o)){if(i.pick==="direct")continue;const s=n(o,i),a=r[s]||(r[s]=[]);a.includes(o)||a.push(o)}for(const[o,i]of Object.entries(r))i.length<2||ge(`planedup:${o}:${i.map(nt).join(",")}`,`${i.length} marks carry a plane-pick edit over the same rows (marks ${i.map(nt).join(", ")}). A plane gesture fans to all of them, so a whole-dataset edit (create/remove/rotate/toggle) will apply once per mark. Declare it on exactly one.`)}function b6(e,t,n){const r=s=>t(s).filter(a=>!a.target),o=e.filter(s=>s&&s.isLegend&&r(s).length&&s.row==null);if(!o.length)return;const i=new Set(e.filter(s=>s&&s.views!=="scale"&&t(s).some(a=>a.target==="selection")).map(s=>s.table));for(const s of o)i.has(s.table)||n(s).length<=1||ge(`legend:norow:${s.channel}:${s.id}`,`${nt(s)} is a picker with no way to choose a row. Its target row defaults to the chart's SELECTION, "${s.table}" has more than one row, and no mark over that table carries edit.select(). Add one, pin a row (legend({ row: 0 })), or drive el.select(i) — otherwise clicking a swatch writes nothing.`)}function w6(e,t){if(!t.filter(o=>o.type==="network.connect"&&!o.when).length)return;const r=t.filter(o=>o.type!=="network.connect"&&o.pick==="direct"&&o.gesture==="drag"&&!o.when);r.length&&ge(`connectconflict:${nt(e)}`,`mark ${nt(e)} carries edit.network.connect() beside ${r.map(o=>`${o.type}()`).join(", ")}, and neither arbitrates with \`when\`. A plain drag fans to both: the other edit moves the source node along under the pointer, so connect finds that same node at release and creates nothing. Split them — connect({ when: when.shift }) and ${r[0].type}({ when: when.noShift }).`)}const x6=new Set(["append","appendMany","toggle"]);function sd(e){return e.target!=="domain"&&x6.has(e.cardinality)}function v6(e,t,n){for(const r of t){if(!sd(r)||e.supportsGeo)continue;const o=`${nt(e)}:nomark:${r.type}`;if(e.views==="scale"){ge(o,`a create/${r.type} edit is on ${nt(e)}, which is a chart element (axis/grid/legend), not a data mark. Creation mints dataset rows; a guide edits the DOMAIN instead (edit.axis.*). Move the create to a data mark.`);continue}const i=r.channels&&r.channels.length?r.channels:["x","y"];i.some(a=>{const l=n[a];return l&&l.invertible})||ge(o,`a create/${r.type} edit is on ${nt(e)}, but none of its positional channels (${i.join(", ")}) has an invertible scale — the pointer can't be inverted to a datum, so the create is a no-op. Creation needs a data mark on an axis.`)}}function k6(e,t,n){const r=e.channels||{},o=[];r.x1&&r.x2&&o.push(r.x1.field,r.x2.field),r.y1&&r.y2&&o.push(r.y1.field,r.y2.field);const i=o.filter(Boolean);if(i.length)for(const s of t){if(!sd(s))continue;const a=new Set(Object.keys(s.defaults||{})),l=i.filter(u=>!a.has(u)&&!(n&&n[u]&&n[u].default!==void 0));l.length&&ge(`${nt(e)}:extent:${s.type}`,`create/${s.type} on the extent mark ${nt(e)} doesn't seed ${l.join(", ")}, so a new row is minted with no extent (zero-size, invisible). Seed it via create({ defaults: { … } }) or a field default in the schema.`)}}function S6(e,t){for(const n of t)!n.pick||n.pick==="direct"||gr(n)||ge(`${nt(e)}:nopick:${n.pick}`,`${n.type}() on ${nt(e)} has pick: "${n.pick}", which names no registered driver, so no gesture will ever reach it. Built-in picks are direct, plane, nearest, probe, sweep, draw, brush, brushRect, geoBrush, axisDrag, slide; a custom one needs registerDriver().`)}function $6(e,t){for(const n of t){const r=n[M0];if(!r||!r.length)continue;const o=gr(n),i=new Set(o&&o.options?o.options:[]),s=r.filter(a=>!i.has(a));s.length&&ge(`${nt(e)}:editopt:${n.type}:${s.join(",")}`,`${n.type}() on ${nt(e)} was given ${s.map(a=>`\`${a}\``).join(", ")}, which ${s.length>1?"are":"is"} not ${s.length>1?"options":"an option"} this edit${o?` or its "${o.name}" driver`:""} reads, so ${s.length>1?"they are":"it is"} ignored.`)}}function Vp(e){return e?typeof e!="function"&&e.type?`${e.type}()`:e.name?`${e.name}()`:"(an anonymous constraint)":"(unknown)"}function _6(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const t=typeof e;return t==="object"?"an object":t==="string"?`the string ${JSON.stringify(e.slice(0,20))}`:`the ${t} ${String(e)}`}function M6(e,t,n){const r=e.channels||{};for(const o of t){if(!o.inverts||sd(o)||e.supportsGeo)continue;const i=o.channels||[];if(!i.length)continue;const s=i.filter(a=>{const l=r[a];if(!l||l.field==null)return!1;const u=n[a];return u&&!u.invertible});s.length&&ge(`${nt(e)}:dead:${o.type}:${s.join(",")}`,`${o.type}() on ${nt(e)} edits channel${s.length>1?"s":""} ${s.map(a=>`"${a}"`).join(", ")}, whose scale cannot be inverted (${s.map(a=>n[a].type||"ordinal").join(", ")}). An edit runs a gesture BACKWARD through the scale, so a non-invertible channel silently does nothing. Edit a positional channel (x/y), or give the channel a continuous, band or point scale.`)}}const Xp=["width","height","margins","responsive","overflow","focusOutline","marks","elements","guides","axes","legends","schema","data","constraints","lock","scales","projection","theme","effects","stage","stageLabels","onChange","renderer"],E6={mark:"did you mean `marks`? (an array of marks — plot.*)",element:"did you mean `elements`? (an array of chart elements — elements.*)",guide:"did you mean `guides`? (an array of guides — guides.*)",constraint:"did you mean `constraints`? (an array of dataset invariants)",scale:"did you mean `scales`? (per-channel scale config, keyed by channel name)",edit:"an edit goes on a mark — either on a channel (`y: { field, edit: move() }`) or in the mark's `edits: [...]`. There is no chart-level `edit`.",edits:"edits go on a MARK, not on the spec: `barY({ edits: [move()] })`.",onchange:"did you mean `onChange`? (capital C)",domain:"a domain describes the DATA, so it lives on the schema: schema: { field: { domain: [...] } }.",x:"there is no chart-level `x`. Scale config is `scales: { x: {...} }`; a field's domain is the schema's.",y:"there is no chart-level `y`. Scale config is `scales: { y: {...} }`; a field's domain is the schema's.",type:"a chart has no `type` — what it draws is its `marks`. A FIELD's type belongs on the schema; the DATASET's shape is the schema's `structure`.",title:"there is no chart-level `title`. Draw one with a `text` mark, or a widget's `question`.",container:"Elicit returns the chart element — append it yourself: `container.appendChild(Elicit(spec))`.",el:"Elicit returns the chart element; it does not take one."};function A6(e){if(!e||!oi())return;const t=new Set(Xp);for(const n of Object.keys(e)){if(t.has(n))continue;const r=E6[n];ge(`spec:${n}`,r?`Elicit({ ${n}: … }): ${r}`:`Elicit({ ${n}: … }) is not a key the chart reads, so it is ignored. Spec keys are: ${Xp.slice().sort().join(", ")}.`)}}function T6(e,t){const n=t||{},r=e.opacity!=null?e.opacity:1;e.opacity=r*(n.opacity!=null?n.opacity:.45),n.fill!=null&&(e.fill=n.fill),n.stroke!=null&&(e.stroke=n.stroke),n.strokeDasharray!=null&&(e.strokeDasharray=n.strokeDasharray)}function ab(e){A6(e);const{width:t=600,height:n=400,margins:r={top:20,right:20,bottom:30,left:40},marks:o=[],elements:i=[],axes:s,legends:a,guides:l=[],effects:u,responsive:c,overflow:d="hidden",focusOutline:f=!1,renderer:p=new Z0}=e,h=c===!0?"reflow":c==="scale"||c==="reflow"?c:"fixed",y=Xf(e.theme),g=E5(u,y.effects),m=[...i,...o],b=e.projection!=null&&s===void 0?!1:s,w=[...VE(m,b),...m,...u6(m,a)].flat(1/0),x=w.some(E=>E&&E.isLegend),S=typeof t=="number"?t:600,v=typeof n=="number"?n:400;let k=S,_=v;const T=r;let L={...T},N=k-L.left-L.right,I=_-L.top-L.bottom;w.forEach((E,R)=>{E.id||(E.id=`feature-${R}`,E.autoId=!0)});const O=ZM(structuredClone(e.schema||{})),M=O.tables[O.primary].fields;let $=_p(structuredClone(e.data??null),O);const F=E=>$[E.table]||[],D=(E,R)=>R&&R.table&&O.byRole[R.table]||E.table,z=()=>$[O.primary],j=()=>xa(O)?z():$;w.forEach(E=>{const R=E.table;R!=null&&!O.tables[R]&&ge(`${nt(E)}:table:${R}`,`mark ${nt(E)} draws table "${R}", which the schema does not declare. Declared tables: ${Object.keys(O.tables).map(K=>`"${K}"`).join(", ")}. Falling back to "${O.primary}".`),E.table=R!=null&&O.tables[R]?R:O.byRole[E.tableRole]||O.primary});const G=O.byRole.nodes||null;for(let E=0;E<w.length;E++){const R=w[E],K=R&&!R.portHost&&R.views!=="scale"&&R.channels&&R.channels.ports;if(!K)continue;if(delete R.channels.ports,typeof R.nodeBox!="function"){ge(`${nt(R)}:ports:box`,`mark ${nt(R)} has a \`ports\` channel, but it does not declare the box it draws, so there is no edge to put a port on. Put \`ports\` on a mark that draws a node shape: point, rect, ellipse, text, sticker, node, face, or a composite.`);continue}if(!G||R.table!==G){ge(`${nt(R)}:ports:table`,`mark ${nt(R)} has a \`ports\` channel, but it draws table "${R.table}", which is not a network's nodes table. Ports are where links meet NODES: declare schema: { structure: "network", … } and put \`ports\` on the mark drawing the nodes.`);continue}let X=E+1;for(;R.glyph&&X<w.length&&w[X]&&w[X].glyph===R.glyph;)X++;w.splice(X,0,V5(R,K))}const J=w.filter(E=>E&&E.portHost&&E.table===G);J.length>1&&ge("ports:hosts",`${J.length} marks draw ports over the "${G}" table; only the first (${nt(J[0].portHost)}) decides where links may meet a node. Put \`ports\` on one mark.`);const re=J[0]||null,Q=G?w.filter(E=>E&&E.views!=="scale"&&E.table===G&&typeof E.nodeBox=="function"):[],ve=re?re.portHost:Q.find(E=>!E.labelBox)||Q[0]||null;let Ce=null,le=[];const me=()=>{if(!ve)return null;const E=[tt,N,I];if(!Ce||E.some((R,K)=>R!==le[K])){const R=tt,K=N,X=I;Ce=(ne,de,ye)=>ve.nodeBox(ne,de,ye,R,K,X),le=E}return Ce},ce=re?(E,R,K)=>D0(pt(re.channels,"ports",E,!1,R,K),Ms(O)):null,Y={},fe=E=>{if(E in Y)return Y[E];const R=w.filter(X=>X&&X.views!=="scale"&&!X.portHost&&X.table===E&&X.channels),K=(X,ne)=>X.channels[ne]&&X.channels[ne].field||null;for(const X of["source","target","sourceSide","targetSide"]){const ne=new Set(R.map(de=>K(de,X)).filter(Boolean));ne.size>1&&ge(`viewers:${E}:${X}`,`marks drawing table "${E}" name different columns for \`${X}\` (${[...ne].map(de=>`"${de}"`).join(", ")}). An edit writing that table uses the first. Name the column on one mark, or the same column on each.`)}return Y[E]=R.length?R[0].channels:null,Y[E]};let ie={};for(const E of Object.keys($))ie[E]=$[E].length;const U={},we={},xe=E=>(E in U||(U[E]=y5(e.lock,()=>ie[E]||0,E)),U[E]),P=E=>{if(!(E in we)){const R=xe(E);we[E]=R?g5(R):null}return we[E]};jc(O,$);const H={...e,schema:M,schemaSpec:O,theme:y},oe={},he=(E,R)=>{const K=oe[R]||(oe[R]=[]);K.includes(E)||K.push(E)};for(const E of e.constraints||[]){const R=E.table;he(E,R&&(O.byRole[R]||O.tables[R]&&R)||O.primary)}const ke=E=>oe[E]||[],pe=ke(O.primary),_e=[...IE(w),...l];let Te=e.stage!=null?e.stage:0;const Se=Array.isArray(e.stageLabels)?e.stageLabels:[],ae=E=>Se[E]!=null?Se[E]:null,$e=E=>va(E).filter(R=>R.stage==null||R.stage===Te),Le=E=>{Te=E,Z.session={},Z.preview=null,Z.hover=null,Z.grab=null,Z.selection.clear();for(const R of qt.stage)R(Te,ae(Te))},Z={session:{},preview:null,selection:new Set,hover:null,grab:null};let St=!1;const rt=E=>E?`${E.index}\0${E.channel??""}\0${E.side??""}\0${E.vertexIndex??""}`:"",ct=(E,R)=>`${E}\0${R}`,$t=E=>{const R=E.indexOf("\0");return{table:E.slice(0,R),index:Number(E.slice(R+1))}},xt=E=>{const R=new Set;for(const K of Z.selection){const X=$t(K);X.table===E&&R.add(X.index)}return R},Tt=()=>{for(const E of xt(O.primary))if(E>=0&&E<z().length)return E;return null},Jt=(E=O.primary)=>{const R=($[E]||[]).length;return[...xt(E)].filter(K=>K>=0&&K<R).sort((K,X)=>K-X)},qt={change:new Set,stage:new Set,select:new Set,gesture:new Set},Qn=100;let C=[],W=[],q=null,V=[];const ee=()=>({tables:structuredClone($),schema:structuredClone(M),width:k,height:_}),ue=E=>{$=structuredClone(E.tables);for(const R of Object.keys(M))delete M[R];Object.assign(M,structuredClone(E.schema)),(E.width!==k||E.height!==_)&&Pt({width:E.width,height:E.height}),Z.preview=null},be=()=>{q||(q={recorded:!1,before:null,edits:[]})},Oe=(E=!1)=>{const R=q;q=null,E&&R&&R.recorded&&rn(R),V.length&&$1()},Ze=()=>{if(q||be(),!q||q.recorded)return;const E=ee();C.push(E),C.length>Qn&&C.shift(),W=[],q.before=E.tables,q.recorded=!0},rn=E=>{if(!qt.gesture.size)return;const R=new Set,K=E.edits.filter(de=>{const ye=`${de.type}\0${de.name??""}\0${de.table}`;return R.has(ye)?!1:(R.add(ye),!0)}),X=de=>xa(O)?de[O.primary]:de,ne={edits:K,before:structuredClone(X(E.before)),after:structuredClone(j())};for(const de of qt.gesture)de(ne)},bt=()=>{e.onChange&&e.onChange(j());for(const E of qt.change)E(structuredClone(j()))},ut=()=>{const E=Tt(),R=xa(O)?[...xt(O.primary)]:[...Z.selection].map($t);for(const K of qt.select)K(E,R)},zn=(E,R=O.primary)=>{const K=[...Z.selection].join(",");An(E,R);const X=[...Z.selection].join(",");return K===X?!1:(ut(),!0)},An=(E,R=O.primary)=>{if(E.clear||E.index==null){Z.selection.clear();return}const K=ct(R,E.index),X=Z.selection.has(K);if(E.exclusive!==!1){const ne=X&&Z.selection.size===1;if(Z.selection.clear(),E.toggle&&ne)return}else if(E.toggle&&X){Z.selection.delete(K);return}Z.selection.add(K)},Bt={},Ht=(E,R,K)=>{let X=R&&R.frame?R:null;return!X&&K!=null&&E&&(X=(Bt[E.id]||[]).find(ne=>ne&&ne.index===K&&ne.frame)||null),X?{...tt,...X.frame}:null},Lt={width:N,height:I};let tt=Wc(w,$,H,Lt);const Xe=document.createElement("div");Xe.style.position="relative",h==="scale"?(Xe.style.width="100%",Xe.style.height="auto"):h==="reflow"?(Xe.style.width="100%",Xe.style.height=`${_}px`):(Xe.style.width=`${k}px`,Xe.style.height=`${_}px`);const Dr=()=>{N=k-L.left-L.right,I=_-L.top-L.bottom,Lt.width=N,Lt.height=I},jr=()=>{if(h!=="reflow")return!1;const E=Xe.clientWidth||S;return E>0&&E!==k?(k=E,Dr(),!0):!1},er=new Yw,on=()=>{if(jr(),er.clear(),x){L={...T},Dr();const te=Wc(w,$,H,Lt);te.theme=y;const Ae=f6(w,te,T);L={top:T.top+Ae.top,right:T.right+Ae.right,bottom:T.bottom+Ae.bottom,left:T.left+Ae.left},Dr()}tt=Wc(w,$,H,Lt);const E=m0(H.projection,Lt);E&&(tt.projection=E),tt.theme=y,tt.selection=Tt(),tt.selectionAll=Jt,tt.schema=M,g6(w,tt);const R=w.some(te=>TE($e(te)));let K="pointer";if(R&&Z.session)for(const te of Object.keys(Z.session)){const Ae=Z.session[te]&&Z.session[te].cursor;if(Ae){K=Ae;break}}m6(w,$e,D),b6(w,$e,F);const X=[];if(w.forEach(te=>{const Ae=F(te),Fe=xe(te.table),Re=te.build(Ae,tt,N,I,{tables:$,schema:O,table:te.table,nodeBox:me(),nodePorts:ce});Bt[te.id]=Re;const Ie=va(te);p6(te,tt),y6(te,Ie),w5(te,nt),v6(te,Ie,tt),k6(te,Ie,H.schema),M6(te,Ie,tt),w6(te,Ie),S6(te,Ie),$6(te,Ie);const Mt=$e(te).some(We=>We.pick==="direct"),Et=$e(te).find(We=>We.inline),Ct=Et?(Ti(Et.channels,te.channels||{},tt,te)[0]||{}).field:null;Re.forEach(We=>{We.featureId=te.id;const gt=Fe&&m5(We,te,Ae,Fe);if(gt&&(We.locked=!0),Mt&&!gt?We.editable=!0:We.pointerEvents==null&&(We.pointerEvents="none"),Et&&!gt&&(We.editText=!0,Et.multiline&&(We.multiline=!0),Ct!=null&&We.data)){const mt=We.data[Ct];mt!=null&&(We.editValue=String(mt))}}),X.push({glyph:te.glyph,nodes:Re})}),oh(X).forEach(te=>er.add(te)),Z.preview){const te=Object.values(Z.preview),Ae=te.length===1?te[0]:null,Fe=[];for(const Re of w){if(Re.views==="scale")continue;const Ie=Z.preview[Re.id]||Ae;if(!Ie||Ie.table!==Re.table)continue;const Mt=Ie.rows,Et=F(Re),Ct=new Set;let We=Mt.length!==Et.length;const gt=Math.max(Mt.length,Et.length);for(let Ke=0;Ke<gt;Ke++)Mt[Ke]!==Et[Ke]&&(Ct.add(Ke),We=!0);if(!We)continue;const ze=Re.build(Mt,tt,N,I,{tables:{...$,[Ie.table]:Mt},schema:O,table:Re.table,ghost:{pointer:Ie.pointer},nodeBox:me(),nodePorts:ce}).filter(Ke=>(Ke.index!=null?Ct.has(Ke.index):We)?(Ke.ghost=!0,Ke.featureId=Re.id,Ke.editable=!1,Ke.pointerEvents="none",T6(Ke,y.ghost),!0):!1);Fe.push({glyph:Re.glyph,nodes:ze})}oh(Fe).forEach(Re=>er.add(Re))}const ne={scales:tt,data:z(),tableOf:F,constraintsIn:ke,constraints:pe,features:w,featureNodes:Bt,ui:Z,effects:g,theme:y,width:N,height:I,stage:Te};_e.forEach(te=>{(te.build(ne.data,tt,N,I,ne)||[]).forEach(Fe=>{Fe.guide=!0,er.add(Fe)})});const de={},ye={},Me=te=>{if(!te||te.index==null)return;const Ae=w.find(Fe=>Fe.id===te.featureId);!Ae||Ae.table==null||(ye[Ae.table]||(ye[Ae.table]=new Set)).add(te.index)};Me(Z.hover),Me(Z.grab),St=!1;let Ee=null;for(const te of Object.values(Z.session||{}))if(te&&Array.isArray(te.targets)){Ee=Ee||new Set;for(const Ae of te.targets)Ee.add(Ae)}for(const te of w){if(te.views==="scale")continue;const Ae=de[te.table]||(de[te.table]=xt(te.table)),Fe=Bt[te.id]||[],Re=new Set,Ie=Z.session&&Z.session[te.id],Mt=Ie?Ie.activeIndex!=null?Ie.activeIndex:Ie.hoverIndex:null;Mt!=null&&Re.add(Mt),Z.hover&&Z.hover.featureId===te.id&&Z.hover.index!=null&&Re.add(Z.hover.index);for(const ze of Ae)Re.delete(ze);const Et=new Set;Z.grab&&Z.grab.featureId===te.id&&Z.grab.index!=null&&Et.add(Z.grab.index);const Ct=[[Re,g.hovered],[Ae,g.selected],[Et,g.grabbed]],We=new Map;for(const[ze,Ke]of Ct)for(const zt of ze){const Dt=We.get(zt)||[];Dt.push(Ke),We.set(zt,Dt)}for(const ze of Fe){if(!ze||ze.ghost||ze.index==null)continue;const Ke=A5(We.get(ze.index)||[]);Ke&&(ze.effectStyle=Ke)}const gt=ye[te.table];for(const ze of Fe){if(!ze||ze.ghost||!ze.onHover||ze.index==null)continue;St=!0;const Ke=ze.index,zt=gt&&gt.has(Ke)||Re.has(Ke)||Ae.has(Ke)||Et.has(Ke)||Mt===Ke;let Dt=zt;ze.portRole&&(Ee?Dt=!!Ie&&Ie.fromIndex===Ke&&Ie.fromSide===ze.side||Ee.has(ed(te.table,Ke,ze.side)):Dt=zt&&ze.portRole!=="in"&&zs(te,ze)),Dt||(ze.effectStyle={...ze.effectStyle||{},opacity:0},ze.pointerEvents="none")}const mt=Z.hover&&Z.hover.featureId===te.id&&Z.hover.node&&Z.hover.node.channel!=null?Fe.find(ze=>ze&&rt(ze)===rt(Z.hover&&Z.hover.node)):null;for(const[ze,Ke]of Ct){if(!ze.size)continue;let zt;if(Ke===g.hovered&&mt&&ze.has(mt.index)){const Dt=new Set(ze);Dt.delete(mt.index),zt=[...Gf(mt,Ke),...Ap(Fe,Dt,Ke)]}else zt=Ap(Fe,ze,Ke);zt.forEach(Dt=>{Dt.guide=!0,er.add(Dt)})}}p.render({container:Xe,scene:er,width:k,height:_,margins:L,scales:tt,spec:e,planeOnTop:R,planeCursor:K,responsive:h,overflow:d,focusOutline:f,effects:g,theme:y,onEvent:Dd})},Ue=(E,R,K,X,ne=!1,de=void 0)=>{const ye=F(E),Me=D(E,R),Ee=$[Me]||[],te=E.channels||{},Ae=Ht(E,K.node,X)||tt,Fe=Ti(R.channels,te,Ae,E),Re={data:Ee,datum:X!=null?ye[X]:void 0,index:X,tables:$,table:Me,pointer:{x:K.x,y:K.y},node:K.node||null,event:K.rawEvent,value:K.value,channels:Fe,scales:Ae,markChannels:te,projection:tt.projection||null,width:N,height:I,margins:L,schema:(O.tables[Me]||O.tables[O.primary]).fields,schemaSpec:O,xKey:E.xKey||"x",yKey:E.yKey||"y",seriesKey:E.seriesKey||null,marks:Bt[E.id]||[],connect:E.connect||null,session:de!==void 0?de:Z.session&&Z.session[E.id]||null,nodeBox:me(),nodePorts:ce,targetChannels:Me!==E.table?fe(Me):null,selection:Tt(),edit:R,preview:ne};if(R.when&&!R.when(Re))return null;const Ie=R.apply(Re);if(Ie===void 0)return null;const Mt=gt=>R.cardinality==="append"?gt.length-1:R.cardinality==="delete"?null:X,Et=(gt,mt=Me)=>{const ze=mt===Me,Ke=P(mt),zt=[...ke(mt),...ze?R.constrain:[],...Ke?[Ke]:[]],Dt={activeIndex:ze?Mt(gt):null,scales:tt,markChannels:te,field:ze&&Fe[0]?Fe[0].field:void 0,tables:$,table:mt};let qs=gt;const _1=ze?Ee:$[mt]||[];for(const gc of zt){const wo=h5(gc,qs,_1,Dt);if(wo===!1)return null;if(!(wo===!0||wo===void 0)){if(!Array.isArray(wo)){ge(`constraint:return:${Vp(gc)}`,`constraint ${Vp(gc)} returned ${_6(wo)}; a constraint must return the repaired rows (an array), false to reject the edit, or true/undefined to accept it unchanged. Ignoring the return value.`);continue}qs=wo}}return qs};if(R.target==="domain"){if(!(Ie&&typeof Ie=="object"&&Ie.domains))return null;const gt={...Ie};if(Array.isArray(Ie.data)){const mt=Et(Ie.data);if(!mt)return null;gt.data=mt}if(Ie.tables){const mt={};for(const[ze,Ke]of Object.entries(Ie.tables)){const zt=Ke;if(!Array.isArray(zt.data)){mt[ze]=zt;continue}const Dt=Et(zt.data,ze);if(!Dt)return null;mt[ze]={...zt,data:Dt}}gt.tables=mt}return{kind:"domain",result:gt}}if(R.target==="selection")return Ie&&typeof Ie=="object"&&"index"in Ie?{kind:"selection",selection:Ie}:null;const Ct=Array.isArray(Ie)?Ie:Ee.map((gt,mt)=>mt===X?Ie:gt),We=Et(Ct);return We?{kind:"rows",rows:We}:null},Ot=(E,R,K,X)=>{const ne=Ue(E,R,K,X);return ne?(q&&ne.kind!=="selection"&&q.edits.push({type:R.type,name:R.name,table:D(E,R)}),ne.kind==="domain"?Zt(ne.result,D(E,R)):ne.kind==="selection"?zn(ne.selection,D(E,R)):(Ze(),$[D(E,R)]=ne.rows,Dc(O,$),Z.preview=null,bt(),!0)):!1},Zt=(E,R=O.primary)=>{Ze();const K={[R]:{domains:E.domains,data:E.data}};for(const[ne,de]of Object.entries(E.tables||{})){if(!O.tables[ne]){ge(`domain:table:${ne}`,`a domain edit names table "${ne}", which the schema does not declare. Declared tables: ${Object.keys(O.tables).map(Me=>`"${Me}"`).join(", ")}.`);continue}const ye=K[ne];K[ne]=ye?{domains:{...ye.domains,...de.domains},data:de.data??ye.data}:de}let X=!1;for(const[ne,de]of Object.entries(K)){const ye=(O.tables[ne]||O.tables[O.primary]).fields;for(const[Me,Ee]of Object.entries(de.domains||{})){const te=ye[Me];ye[Me]={...te||{type:y0(Ee)},domain:Ee}}Array.isArray(de.data)&&($[ne]=de.data,X=!0)}return X&&Dc(O,$),E.resize&&Pt(E.resize),Z.preview=null,bt(),!0},Pt=E=>{typeof E.width=="number"&&E.width>0&&(k=E.width),typeof E.height=="number"&&E.height>0&&(_=E.height),h==="fixed"?(Xe.style.width=`${k}px`,Xe.style.height=`${_}px`):h==="reflow"&&(Xe.style.height=`${_}px`),Dr()},sn=(E,R,K,X)=>{const ne=Ue(E,R,K,X,!0);if(!ne||ne.kind!=="rows")return!1;const de=ne.rows;return Z.preview||(Z.preview={}),Z.preview[E.id]={table:D(E,R),rows:de,pointer:typeof K.x=="number"&&typeof K.y=="number"?{x:K.x,y:K.y}:void 0},!0},tr=(E,R,K,X,ne)=>{if(typeof R.targets!="function")return null;const de=D(E,R),ye={scales:tt,schemaSpec:O,tables:$,table:de,data:$[de]||[],nodeBox:me(),nodePorts:ce,width:N,height:I,node:X||null,edit:R,pointer:{x:0,y:0},index:K,datum:K!=null?F(E)[K]:void 0,markChannels:E.channels||{}},Me=[],Ee=R.targets(ye);if(!Ee)return null;for(const te of Ee)Ue(E,R,{x:te.x,y:te.y,node:X},K,!1,ne)!==null&&Me.push(te.key);return Me},yo=new Map;let go=[];const zs=(E,R)=>{const K=Object.keys($).map(Me=>$[Me]);(K.length!==go.length||K.some((Me,Ee)=>Me!==go[Ee]))&&(yo.clear(),go=K);const X=`${E.id}\0${R.index}\0${R.side}`,ne=yo.get(X);if(ne!==void 0)return ne;let de=!1;const ye={...Z.session&&Z.session[E.id]||{},fromIndex:R.index,fromSide:R.side,fromPoint:null};for(const Me of $e(E)){const Ee=tr(E,Me,R.index,R,ye);if(Ee&&Ee.length){de=!0;break}}return yo.set(X,de),de},yc=(E,R)=>{const K=R.node?R.node.index:void 0;if(K==null)return!1;let X=!1;const ne=$e(E).filter(ye=>ye.pick==="direct"&&(!R.editName||ye.name===R.editName)),de=ne.filter(ye=>gr(ye));return de.length&&Ds(E,R,de,K)&&(X=!0),ne.filter(ye=>ye.gesture===R.type&&!gr(ye)).forEach(ye=>{Ot(E,ye,R,K)&&(X=!0)}),X},Ds=(E,R,K,X)=>{if(K.length===0)return!1;const ne=E.id,de=(Fe,Re)=>Ot(E,Fe,R,Re),ye=(Fe,Re)=>sn(E,Fe,R,Re),Me={get:()=>Z.preview&&Z.preview[ne]||null,clear:()=>!Z.preview||!Z.preview[ne]?!1:(delete Z.preview[ne],Object.keys(Z.preview).length===0&&(Z.preview=null),!0)},Ee={get:()=>Te,set:Fe=>Le(Fe),next:()=>Le(Te+1)},te=new Map;for(const Fe of K){const Re=gr(Fe);if(!Re)continue;const Ie=te.get(Re)||[];Ie.push(Fe),te.set(Re,Ie)}let Ae=!1;for(const Fe of zo){const Re=te.get(Fe);if(!Re)continue;const Ie=Fe.sessionKeys||[],Mt={get:()=>Z.session&&Z.session[ne]||null,set:Ct=>{Z.session=Z.session||{},Z.session[ne]={...Z.session[ne]||{},...Ct}},clear:()=>{if(!Z.session||!Z.session[ne])return;const Ct={};for(const We of Ie)Ct[We]=null;Z.session[ne]={...Z.session[ne],...Ct}}},Et={feature:E,event:R,edits:Re,marks:Bt[ne]||[],data:F(E),scales:tt,index:X??null,session:Mt,preview:Me,stage:Ee,runEdit:de,previewEdit:ye,reachable:(Ct,We,gt)=>tr(E,Ct,We,gt!==void 0?gt:R.node)};Fe.onEvent(Et)&&(Ae=!0)}return Ae},js=(E,R)=>Ds(E,R,$e(E).filter(K=>K.pick!=="direct"),null),Dd=E=>{let R=!1;if(E.type==="pointerover"||E.type==="pointerout"){const K=E.node,X=E.type==="pointerover"&&K&&K.index!=null?{featureId:K.featureId,index:K.index,node:K}:null,ne=(ye,Me)=>!ye&&!Me||!!(ye&&Me&&ye.featureId===Me.featureId&&ye.index===Me.index&&rt(ye.node)===rt(Me.node));if(!(E.type==="pointerout"&&Z.hover&&K&&!ne(Z.hover,{featureId:K.featureId,index:K.index,node:K}))&&!ne(Z.hover,X)){Z.hover=X;const ye=g.hovered;ye&&ye.enabled!==!1&&(ye.outline||Uu(ye))&&(R=!0),St&&(R=!0)}R&&on();return}if(E.type==="nudge"){const K=E.node,X=Rn(K);if(!X)return;const ne=w.find(Ae=>Ae.id===K.featureId),de=ne&&ne.channels||{},ye=K.index!=null?(ne?F(ne):[])[K.index]:K.data,Me=Ht(ne,K,K.index)||tt,Ee=ye?se(Me,de,"x",ye,X.cx):X.cx,te=ye?se(Me,de,"y",ye,X.cy):X.cy;E={type:"drag",node:K,x:Hu(Me.x,Ee,E.dx,E.coarse),y:Hu(Me.y,te,E.dy,E.coarse),nudge:!0,rawEvent:E.rawEvent}}if(E.type==="dragstart"?(Oe(!0),be()):q||be(),E.type==="dragstart"||E.type==="dragend"){const K=E.type==="dragstart"&&E.node&&E.node.index!=null?{featureId:E.node.featureId,index:E.node.index}:null,X=!!Z.grab!=!!K||!!(Z.grab&&K&&(Z.grab.featureId!==K.featureId||Z.grab.index!==K.index));Z.grab=K;const ne=g.grabbed;X&&ne&&ne.enabled!==!1&&(ne.outline||Uu(ne))&&(R=!0)}if(E.node){const K=w.find(X=>X.id===E.node.featureId);K&&yc(K,E)&&(R=!0)}else w.forEach(K=>{js(K,E)&&(R=!0)});(E.type==="dragend"||E.nudge||E.type!=="dragstart"&&E.type!=="drag")&&Oe(!0),R&&on()},Qe=Xe;Qe.getData=()=>structuredClone(j()),Qe.getSchema=()=>structuredClone(QM(O)),Qe.setData=E=>{$=_p(structuredClone(E??null),O),jc(O,$,"setData()"),ie={};for(const R of Object.keys($))ie[R]=$[R].length;Z.preview=null,Z.hover=null,Z.grab=null,Z.selection.clear(),C=[],W=[],V=[],Oe(),on()};const jd=E=>{const R=O.tables[E];if(!R)throw new Error(`patch(): there is no table named "${E}".`);const K=Object.entries(R.fields),X=K.filter(([,de])=>de&&de.key).map(([de])=>de);if(X.length)return X;const ne=K.filter(([,de])=>de&&de.type==="ref").map(([de])=>de);if(ne.length)return ne;throw new Error(`patch(): table "${E}" has no key field (\`key: true\`) and no \`ref\` fields, so its rows cannot be addressed.`)},nr=(E,R)=>JSON.stringify(E.map(K=>R?R[K]:void 0)),v1=(E,R)=>Array.isArray(R)?JSON.stringify(R):R!=null&&typeof R=="object"?nr(E,R):JSON.stringify([R]),k1=E=>Object.entries(E||{}).map(([R,K])=>{const X=jd(R);return{name:R,fields:X,insert:K.insert||[],update:K.update||[],remove:new Set((K.remove||[]).map(ne=>v1(X,ne)))}}),Wd=(E,R,K)=>{for(const X of R){let ne=E[X.name]||[];X.remove.size&&(ne=ne.filter(ye=>!X.remove.has(nr(X.fields,ye))));const de=new Map(ne.map((ye,Me)=>[nr(X.fields,ye),Me]));for(const ye of X.update){const Me=nr(X.fields,ye),Ee=de.get(Me);if(Ee===void 0){K&&K.missing.push({table:X.name,key:JSON.parse(Me)});continue}ne[Ee]={...ne[Ee],...structuredClone(ye)},K&&K.updated++}for(const ye of X.insert){const Me=nr(X.fields,ye);if(de.has(Me)){K&&K.conflicts.push({table:X.name,key:JSON.parse(Me)});continue}de.set(Me,ne.length),ne.push(structuredClone(ye)),K&&K.inserted++}E[X.name]=ne}Dc(O,E)},qd=(E,R)=>{const K=[...Z.selection].map($t).map(({table:Ee,index:te})=>{const Ae=O.tables[Ee]?S1(Ee):null;return{table:Ee,key:Ae?nr(Ae,($[Ee]||[])[te]):null,fields:Ae}}),X={};for(const Ee of E)X[Ee.name]=new Set(($[Ee.name]||[]).slice(0,ie[Ee.name]||0).map(te=>nr(Ee.fields,te)));const ne=Object.fromEntries(Object.entries($).map(([Ee,te])=>[Ee,te.length]));R==="record"&&(C.push(ee()),C.length>Qn&&C.shift(),W=[]);const de={inserted:0,updated:0,removed:0,missing:[],conflicts:[]};if(Wd($,E,de),jc(O,$,"patch()"),R==="keep")for(const Ee of[...C,...W])Wd(Ee.tables,E);let ye=0;for(const Ee of new Set([...Object.keys(ne),...Object.keys($)]))ye+=(ne[Ee]||0)-($[Ee]||[]).length;de.removed=ye+de.inserted;for(const Ee of E)ie[Ee.name]&&(ie[Ee.name]=($[Ee.name]||[]).filter(te=>X[Ee.name].has(nr(Ee.fields,te))).length);const Me=[...Z.selection].join("|");Z.selection.clear();for(const{table:Ee,key:te,fields:Ae}of K){if(te==null||!Ae)continue;const Fe=($[Ee]||[]).findIndex(Re=>nr(Ae,Re)===te);Fe>=0&&Z.selection.add(ct(Ee,Fe))}return Z.preview=null,Z.hover=null,bt(),[...Z.selection].join("|")!==Me&&ut(),on(),de},S1=E=>{try{return jd(E)}catch{return null}},$1=()=>{const E=V;V=[];for(const R of E)qd(R.plan,R.history)};Qe.patch=(E,R={})=>{const K=R.history??"keep";if(K!=="keep"&&K!=="record")throw new Error(`patch(): history is "keep" or "record", not "${K}".`);const X=k1(E);return q&&(V.length||X.some(ne=>ne.remove.size))?(V.push({plan:X,history:K}),{deferred:!0}):qd(X,K)},Qe.getSelection=()=>Tt(),Qe.getSelectionAll=()=>Jt();const Ws=E=>{const R=zn(E);return R&&on(),R};Qe.select=E=>{const R=z(),K=ne=>typeof ne=="number"&&ne>=0&&ne<R.length;if(Array.isArray(E)){const ne=E.filter(K);if(!ne.length)return Ws({index:null,clear:!0});const de=[...Z.selection].join(",");An({index:ne[0],exclusive:!0,toggle:!1});for(const ye of ne.slice(1))An({index:ye,exclusive:!1,toggle:!1});return[...Z.selection].join(",")===de?!1:(ut(),on(),!0)}const X=K(E)?E:null;return Ws({index:X,exclusive:!0,toggle:!1,clear:X==null})},Qe.toggleSelection=E=>Ws({index:E,exclusive:!1,toggle:!0}),Qe.selectAll=()=>Qe.select(z().map((E,R)=>R)),Qe.selectWhere=(E,R,K)=>{const X=typeof E=="function"?E:ye=>ye&&ye[E]===R,ne=z();if(K&&K.all){const ye=ne.map((Me,Ee)=>X(Me,Ee)?Ee:-1).filter(Me=>Me>=0);return Qe.select(ye.length?ye:null)}const de=ne.findIndex(X);return Qe.select(de<0?null:de)},Qe.clearSelection=()=>Ws({index:null,clear:!0}),Qe.emit=E=>Dd(E);const mo=E=>{let R=null;const K=new Set;for(const X of w)for(const ne of va(X))ne.name===E&&(K.add(ne.apply),R||(R={feature:X,edit:ne}));return K.size===0&&ge(`control:none:${E}`,`el.control("${E}"): no edit is named "${E}".`),K.size>1&&ge(`control:many:${E}`,`el.control("${E}"): ${K.size} different edits share the name "${E}"; driving the first.`),R},bo=(E,R)=>(Bt[E.id]||[]).find(K=>K&&K.index===R)||null;Qe.control=(E,R=0)=>{const K=(de,ye,Me)=>{const Ee=bo(de,R),te=Rn(Ee),Ae=z()[R],Fe=de.channels||{},Re=Ht(de,Ee,R)||tt;let Ie=Ae?se(Re,Fe,"x",Ae,te?te.cx:0):te?te.cx:0,Mt=Ae?se(Re,Fe,"y",Ae,te?te.cy:0):te?te.cy:0;const Et=Ti(ye.channels,Fe,Re,de),Ct=We=>Me!=null&&typeof Me=="object"&&!(Me instanceof Date)?We.name in Me?Me[We.name]:We.field!=null&&We.field in Me?Me[We.field]:void 0:Me;for(const We of Et){if(!We.scale||!We.scale.invertible)continue;const gt=Ct(We);if(gt===void 0)continue;const mt=We.scale.encode(gt),ze=HM(We.name,mt,te);if(!ze)continue;const Ke=_t(We.name);Ke!=="y"&&(Ie=ze.x),Ke!=="x"&&(Mt=ze.y)}return{node:Ee,x:Ie,y:Mt}};let X=!1;return{set(de){const ye=mo(E);if(!ye)return;const{feature:Me,edit:Ee}=ye,te=bo(Me,R);if(Ee.gesture==="commit"){Qe.emit({type:"commit",node:te,value:de,editName:E,x:te?te.cx:0,y:te?te.cy:0});return}const{node:Ae,x:Fe,y:Re}=K(Me,Ee,de);Qe.emit(X?{type:"drag",node:Ae,x:Fe,y:Re,editName:E}:{type:"drag",node:Ae,x:Fe,y:Re,nudge:!0,editName:E})},begin(){const de=mo(E);de&&(X=!0,Qe.emit({type:"dragstart",node:bo(de.feature,R),editName:E}))},end(){const de=mo(E);X=!1,de&&Qe.emit({type:"dragend",node:bo(de.feature,R),editName:E})},fire(de){const ye=mo(E);if(!ye)return;const Me=de||ye.edit.gesture||"click";Qe.emit({type:Me,node:bo(ye.feature,R),editName:E})},emit(de){const ye=mo(E);Qe.emit({node:ye?bo(ye.feature,R):void 0,...de})},accepts(){const de=mo(E);if(!de)return null;const{feature:ye,edit:Me}=de,Ee=Ht(ye,null,R)||tt,te=Ti(Me.channels,ye.channels||{},Ee,ye)[0],Ae=te&&te.scale,Fe=M&&te&&te.field&&M[te.field]||null,Re=Fe&&Fe.type||null,Ie=(Ae&&typeof Ae.domain=="function"?Ae.domain():null)||Fe&&Fe.domain||null,Mt=Ae&&typeof Ae.range=="function"?Ae.range():null;return{field:te?te.field:null,type:Re,kind:Ae?Ae.kind:null,temporal:!!(Ae&&Ae.temporal),invertible:!!(Ae&&Ae.invertible),domain:Ie,values:Ae&&(Ae.kind==="band"||Ae.kind==="discrete"||Ae.kind==="point")||Re==="categorical"||Re==="ordinal"?Ie:null,range:Mt}}}},Qe.canUndo=()=>C.length>0,Qe.canRedo=()=>W.length>0,Qe.undo=()=>C.length?(W.push(ee()),ue(C.pop()),Oe(),bt(),on(),!0):!1,Qe.redo=()=>W.length?(C.push(ee()),ue(W.pop()),Oe(),bt(),on(),!0):!1,Qe.on=(E,R)=>(qt[E].add(R),()=>qt[E].delete(R)),Qe.getStage=()=>Te,Qe.getStageLabel=()=>ae(Te),Qe.setStage=E=>{Le(E),on()},Qe.nextStage=()=>Qe.setStage(Te+1);let ui=null;if(h==="reflow"&&typeof ResizeObserver<"u"){let E=!1;ui=new ResizeObserver(()=>{E||(E=!0,requestAnimationFrame(()=>{E=!1,jr()&&on()}))}),ui.observe(Xe)}return Qe.destroy=()=>{ui&&(ui.disconnect(),ui=null)},setTimeout(on,0),Qe}function ad(e,t,n,r={}){const o=n.filter(s=>t&&t[s]&&t[s].field!=null),i=new Map;return e.forEach((s,a)=>{const l=o.length?o.map(c=>String(Nn(t,c,s,r[c],a,e))).join("\0"):"__all__";let u=i.get(l);u||(u={key:l,rep:s,members:[]},i.set(l,u)),u.members.push(a)}),[...i.values()]}function tc(e,t,n){const r=e.map(s=>{const a=t[s],l=n!=null&&a?Number(a[n]):NaN;return Number.isFinite(l)&&l>0?l:0}),o=[];let i=0;for(const s of r)o.push([i,i+s]),i+=s;return{mags:r,total:i,bounds:o}}function ds({members:e,local:t,field:n,geometry:r}){return{members:e,local:t,field:n,geometry:r}}function O6(e,t,n){if(!n)return e;const r=[];for(const i of t){const s=i[n];r.includes(s)||r.push(s)}const o=i=>{const s=r.indexOf(t[i][n]);return s<0?r.length:s};return[...e].sort((i,s)=>o(i)-o(s))}function C6(e,t,n,r,o,i){const s=new Map;for(const a of ad(e,t,[n],{[n]:r})){const l=O6(a.members,e,i),{bounds:u}=tc(l,e,o);l.forEach((c,d)=>{s.set(c,{y0:u[d][0],y1:u[d][1],members:l,local:d})})}return s}function N6(e){const t=at(e,{mark:"bar",allow:st.bar}),{channels:n={},id:r,edits:o,orientation:i,stack:s,handles:a=!0,handleSize:l,handleColor:u}=t,{xKey:c,yKey:d}=Xt(n),f=!!(n.x1&&n.x2),p=!!(n.y1&&n.y2),h=s?Os(n):null,y=!!s&&!f&&!p,g=o||[],m=g.some(b=>b&&b.scope==="stack");return{...lt(t),type:"bar",channels:n,rawChannels:["series"],edits:g,supportsStack:y,discreteScale:"band",xKey:c,yKey:d,build:(b,w)=>{const{x,y:S}=w,v=Zf(kr(n,w,{orientation:i})),k=v==="horizontal"?"y":"x",_=v==="horizontal"?"x":"y",T=v==="horizontal"?d:c,L=v==="horizontal"?c:d,N=y?C6(b,n,k,T,L,h):null,I=It(w,"bar",y?{fill:it(w).ink,stroke:it(w).handleStroke,strokeWidth:1}:{fill:it(w).ink}),O=fn(w,{handles:a,handleSize:l,handleColor:u}),M={kind:"linear",axis:_},$=D=>{const z=N&&N.get(D);return z?ds({members:z.members,local:z.local,field:L,geometry:M}):void 0},F=b.map((D,z)=>{const j=yt(w,n,D,I,z,b),G=$(z);if(v==="horizontal"){const le=Yr(S,Nn(n,"y",D,d,z,b),0),me=yn(S,20),ce=yr(x);let Y,fe;if(f){const ie=se(w,n,"x1",D,ce,z,b),U=se(w,n,"x2",D,ce,z,b);Y=Math.min(ie,U),fe=Math.max(ie,U)}else if(N){const{y0:ie,y1:U}=N.get(z)||{y0:0,y1:D[c]},we=Ft(w,n,"x",ie,ce),xe=Ft(w,n,"x",U,ce);Y=Math.min(we,xe),fe=Math.max(we,xe)}else{const ie=se(w,n,"x",D,ce,z,b);Y=Math.min(ie,ce),fe=Math.max(ie,ce)}return{type:"rect",x:Y,y:le,width:fe-Y,height:me,...j,data:D,index:z,orientation:v,bandAxis:"y",...G?{stack:G}:{}}}const J=Yr(x,Nn(n,"x",D,c,z,b),0),re=yn(x,20),Q=yr(S);let ve,Ce;if(p){const le=se(w,n,"y1",D,Q,z,b),me=se(w,n,"y2",D,Q,z,b);ve=Math.min(le,me),Ce=Math.max(le,me)}else if(N){const{y0:le,y1:me}=N.get(z)||{y0:0,y1:D[d]},ce=Ft(w,n,"y",le,Q),Y=Ft(w,n,"y",me,Q);ve=Math.min(ce,Y),Ce=Math.max(ce,Y)}else{const le=se(w,n,"y",D,Q,z,b);ve=Math.min(le,Q),Ce=Math.max(le,Q)}return{type:"rect",x:J,y:ve,width:re,height:Ce-ve,...j,data:D,index:z,orientation:v,bandAxis:"x",...G?{stack:G}:{}}});if(N&&m&&O.grabbable){const D=k==="x"?x:S,j=yr(_==="x"?x:S),G=yn(D,20),J=new Set;for(const re of N.values()){const Q=re.members;if(J.has(Q))continue;J.add(Q);const ve=b[Q[0]],le=Yr(D,Nn(n,k,ve,T,Q[0],b),0)+G/2;for(let me=0;me<Q.length-1;me++){const ce=Q[me],Y=N.get(ce);if(!Y)continue;const fe=Ft(w,n,_,Y.y1,j);F.push({type:"circle",cx:_==="x"?fe:le,cy:_==="x"?le:fe,r:O.size,fill:O.visible?O.fill:"transparent",stroke:O.visible?O.stroke:"none",strokeWidth:O.visible?O.strokeWidth:0,cursor:"grab",data:b[ce],index:ce,edge:!0,loIndex:ce,hiIndex:Q[me+1],stack:ds({members:Q,local:me,field:L,geometry:M})})}}}return F}}}function ld(e={}){return N6(e)}function nc(e={}){return ld({...e,orientation:"vertical"})}function I6(e={}){return ld({...e,orientation:"horizontal"})}function oa(e,t,n,r,o,i,s,a,l,u){const c=e+"1",d=e+"2";if(t[c]&&t[d]){const y=se(n,t,c,o,0,l,u),g=se(n,t,d,o,0,l,u);return{lo:Math.min(y,g),hi:Math.max(y,g),band:!1}}const f=e==="x"?"width":"height";if(t[f]){const y=se(n,t,f,o,0,l,u),[g,m]=r?oo(r):[0,a],b=se(n,t,e,o,(g+m)/2,l,u);return{lo:b-y/2,hi:b+y/2,band:!1}}if(!s&&Vn(r)){const y=Yr(r,Nn(t,e,o,i,l,u),0),g=yn(r,20);return{lo:y,hi:y+g,band:!0}}if(t[e]){const y=yr(r),g=se(n,t,e,o,y,l,u);return{lo:Math.min(g,y),hi:Math.max(g,y),band:!1}}const[p,h]=r?oo(r):[0,a];return{lo:Math.min(p,h),hi:Math.max(p,h),band:!1}}function L6(e){const t=at(e,{mark:"rect",allow:st.rect}),n=t.orientation==="vertical"?"y":t.orientation==="horizontal"?"x":null,{channels:r={},id:o,edits:i,width:s,height:a,rx:l}=t;s!==void 0&&!r.width&&(r.width={value:s}),a!==void 0&&!r.height&&(r.height={value:a}),l!==void 0&&!r.rx&&(r.rx={value:l});const{xKey:u,yKey:c}=Xt(r);return{...lt(t),type:"rect",channels:r,discreteScale:"band",xKey:u,yKey:c,nodeBox:(d,f,p,h,y,g)=>{const m=oa("x",r,h,h.x,d,u,n==="x",y,f,p),b=oa("y",r,h,h.y,d,c,n==="y",g,f,p);return{cx:(m.lo+m.hi)/2,cy:(b.lo+b.hi)/2,hw:(m.hi-m.lo)/2,hh:(b.hi-b.lo)/2}},build:(d,f,p,h)=>{const{x:y,y:g}=f,m=It(f,"rect",{fill:it(f).ink});return d.map((b,w)=>{const x=yt(f,r,b,m,w,d),S=oa("x",r,f,y,b,u,n==="x",p,w,d),v=oa("y",r,f,g,b,c,n==="y",h,w,d);let k;S.band&&!v.band?k="x":v.band&&!S.band&&(k="y");const _=zr(f,r,"angle",b,0,w,d),T=r.rx?se(f,r,"rx",b,0,w,d):void 0;return{type:"rect",x:S.lo,y:v.lo,width:S.hi-S.lo,height:v.hi-v.lo,...x,data:b,index:w,..._?{angle:_}:{},...T?{rx:T}:{},...k?{bandAxis:k}:{}}})}}}function Is(e={}){return L6(e)}function F6(e={}){return Is({...e,orientation:"horizontal"})}function R6(e={}){return Is({...e,orientation:"vertical"})}function Jp(e,t,n,r,o,i,s,a,l,u,c){const d=n[`${e}1`],f=n[`${e}2`];if(d&&f)return[se(r,n,`${e}1`,o,0,u,c),se(r,n,`${e}2`,o,s,u,c)];if(l!=null&&n[e]){const p=se(r,n,e,o,s/2,u,c);return[p-l/2,p+l/2]}return i0(t,Nn(n,e,o,i,u,c),s,{inset:a,length:l})}function P6(e){const t=at(e,{mark:"tick",allow:st.tick}),{channels:n={},id:r,edits:o,inset:i=0,length:s}=t,{xKey:a,yKey:l}=Xt(n);return{...lt(t),type:"tick",channels:n,discreteScale:"band",xKey:a,yKey:l,build:(u,c,d,f)=>{const{x:p,y:h}=c,y=kr(n,c,{orientation:t.orientation,extent:"span"}),g=It(c,"tick",{stroke:it(c).ink,strokeWidth:2});return u.map((m,b)=>{const w=yt(c,n,m,g,b,u),x=zr(c,n,"angle",m,0,b,u);if(y==="x"){const _=se(c,n,"x",m,d/2,b,u),[T,L]=Jp("y",h,n,c,m,l,f,i,s,b,u);return{type:"line",x1:_,x2:_,y1:T,y2:L,...w,data:m,index:b,bandAxis:"y",cursor:"ew-resize",...x?{angle:x}:{}}}const S=se(c,n,"y",m,f/2,b,u),[v,k]=Jp("x",p,n,c,m,a,d,i,s,b,u);return{type:"line",x1:v,x2:k,y1:S,y2:S,...w,data:m,index:b,bandAxis:"x",cursor:"ns-resize",...x?{angle:x}:{}}})}}}function hs(e={}){return P6(e)}function lb(e={}){return hs({...e,orientation:"vertical"})}function z6(e={}){return hs({...e,orientation:"horizontal"})}function D6(e){const t=at(e,{mark:"rule",allow:st.rule}),{channels:n={},id:r,edits:o,strokeDasharray:i,discreteScale:s}=t,a=!!(n.y1||n.y2),l=!!(n.x1||n.x2),u=a?"y":l?"x":null,c=kr(n,null,{orientation:t.orientation,extent:"span",single:"value"}),d=!Object.values(n).some(h=>h&&h.field!=null),{xKey:f,yKey:p}=Xt(n);return{...lt(t),type:"rule",channels:n,discreteScale:s,xKey:f,yKey:p,build:(h,y,g,m)=>{const b=[],w=(x,S)=>{const v=yt(y,n,x||{},It(y,"rule",{stroke:it(y).ink,strokeWidth:1}),S,h);if(u){const T=u==="y"?"x":"y",L=T==="x"?g:m,N=yr(y[u]),[I,O]=u==="y"?["y1","y2"]:["x1","x2"],M=n[I]?se(y,n,I,x,N,S,h):N,$=n[O]?se(y,n,O,x,N,S,h):N;if(M===void 0||$===void 0)return;const F=y[T];let D=L/2;if(n[T])if(Vn(F)){const G=Nn(n,T,x,T==="x"?f:p,S,h);D=Yr(F,G,0)+yn(F,0)/2}else D=se(y,n,T,x,L/2,S,h);const z={type:"line",...u==="y"?{x1:D,x2:D,y1:M,y2:$}:{x1:M,x2:$,y1:D,y2:D},...v,data:x,index:S};i!=null&&(z.strokeDasharray=i),b.push(z);return}const k=se(y,n,c,x,void 0,S,h);if(k===void 0)return;const _={type:"line",...c==="y"?{x1:0,x2:g,y1:k,y2:k}:{x1:k,x2:k,y1:0,y2:m},...v,data:x,index:S};i!=null&&(_.strokeDasharray=i),b.push(_)};return d?w(null,-1):h.forEach(w),b}}}function cd(e={}){return D6(e)}function cb(e={}){return cd({...e,orientation:"vertical"})}function j6(e={}){return cd({...e,orientation:"horizontal"})}function W6(e){const t=e&&e.domainConfig;if(Array.isArray(t)&&t.length>=2){const n=Math.min(t[0],t[t.length-1]),r=Math.max(t[0],t[t.length-1]);return[n,r]}return ge("waffle:domain",'a waffle needs a declared DOMAIN on its value axis — one cell is a fixed quantity, so the number of cells is (domain span / unit). Without it the domain falls back to [0, 1] and the grid stops being countable. Declare it: schema: { <field>: { type: "quantitative", domain: [0, max] } }, and bind it to the `count` channel.'),[0,1]}function q6(e){const t=at(e,{mark:"waffle",allow:st.waffle}),{channels:n={},id:r,edits:o,orientation:i,unit:s=1,multiple:a,gap:l=1,shape:u="rect",showEmpty:c=!0,emptyFill:d="#eee"}=t,{xKey:f,yKey:p}=Xt(n),y=Zf(kr(n,null,{orientation:i,single:"other"}))!=="horizontal";return{...lt(t),type:"waffle",channels:n,countAxis:y?"y":"x",discreteScale:"band",xKey:f,yKey:p,requires:[{channels:["x","y"],kind:"discrete",match:"any",why:"a waffle tiles ONE category's block into countable cells, so its category axis has to be a band (an interval to tile)."}],supportsWaffle:!0,build:(g,m)=>{const{x:b,y:w}=m,x=[],S=It(m,"waffle",{fill:it(m).ink});return g.forEach((v,k)=>{const _=yt(m,n,v,S,k,g),T=u==="symbol"?cs(m,n,v,k,g)||"·":cs(m,n,v,k,g),L=y?b:w,N="count",I=m.count,M=Yr(L,Nn(n,y?"x":"y",v,y?f:p,k,g),0),$=yn(L,20),F=yr(I),[D,z]=W6(I),j=Math.abs(z-D)||1,G=I?I.encode(z,F):F,J=Math.abs(F-G)||1,re=j/s;Math.abs(re-Math.round(re))>1e-9&&ge("waffle:unit",`a waffle's domain span (${j}) is not a whole number of \`unit\`s (${s}) — it needs ${re.toFixed(2)} cells, so the grid is rounded to ${Math.round(re)} and one cell no longer means exactly ${s}. Pick a unit that divides the domain.`);const Q=Math.max(1,Math.round(re));let ve=a;if(!(ve>=1)){const ke=Math.sqrt(Q*$/J);ve=Number.isFinite(ke)&&ke>=1?Math.floor(ke):1}ve=Math.max(1,Math.min(Q,Math.round(ve)));const Ce=Math.ceil(Q/ve),le=Math.min($/ve,J/Ce),me=($-ve*le)/2,ce=Math.max(.5,le-l),Y={axis:y?"y":"x",sign:y?-1:1,baseline:F,cellSize:le,rows:Ce,multiple:ve,bandStart:M,bandInset:me,unit:s,dlo:D,dhi:z,totalCells:Q},fe=y?-1:1,ie=M+me+l/2,U=Math.min(F,F+fe*Ce*le)+l/2,we=Math.max(0,ve*le-l),xe=Math.max(0,Ce*le-l),P={type:"rect",x:y?ie:U,y:y?U:ie,width:y?we:xe,height:y?xe:we},H=se(m,n,N,v,F,k,g),oe=Math.abs(F-H)/J,he=Math.max(0,Math.min(Q,Math.round(oe*Q)));for(let ke=0;ke<Q;ke++){const pe=Math.floor(ke/ve),_e=ke%ve,Te=ke<he,Se=Te?_:{..._,fill:c?d:"transparent"},ae=M+me+_e*le,$e=F+fe*pe*le,Le=F+fe*(pe+1)*le,Z=Math.min($e,Le);if(T!==void 0){const St=ae+le/2,rt=($e+Le)/2,ct={..._,data:v,index:k,grid:Y,effectShape:P};Te||(ct.opacity=c?.2:0),x.push(Xl(T,y?St:rt,y?rt:St,ce/2,ct));continue}if(u==="circle"){const St=ce/2,rt=ae+le/2,ct=($e+Le)/2;x.push({type:"circle",cx:y?rt:ct,cy:y?ct:rt,r:St,...Se,data:v,index:k,grid:Y,effectShape:P});continue}x.push({type:"rect",x:(y?ae:Z)+l/2,y:(y?Z:ae)+l/2,width:ce,height:ce,...Se,data:v,index:k,grid:Y,effectShape:P})}}),x}}}function ud(e={}){return q6(e)}function B6(e={}){return ud({...e,orientation:"vertical"})}function H6(e={}){return ud({...e,orientation:"horizontal"})}function Sr(e={}){const t=at(e,{mark:"point",allow:st.point}),{channels:n={},id:r,edits:o,shape:i="circle"}=t;return{...lt(t),type:"point",channels:n,discreteScale:"point",...Xt(n),nodeBox:(s,a,l,u,c,d)=>{const f=Math.max(0,+se(u,n,"size",s,5,a,l)||0);return{cx:se(u,n,"x",s,c/2,a,l),cy:se(u,n,"y",s,d/2,a,l),hw:f,hh:f,round:i!=="square"}},build:(s,a,l,u)=>{const c=It(a,"point",{fill:it(a).ink});return s.map((d,f)=>{const p=yt(a,n,d,c,f,s),h=se(a,n,"x",d,l/2,f,s),y=se(a,n,"y",d,u/2,f,s),g=se(a,n,"size",d,5,f,s),m=zr(a,n,"angle",d,0,f,s),b=cs(a,n,d,f,s);if(b!==void 0)return Xl(b,h,y,g,{...p,data:d,index:f,...m?{angle:m}:{}});if(i==="square"){const w=Math.max(0,g*2);return{type:"rect",x:h-w/2,y:y-w/2,width:w,height:w,...p,data:d,index:f,...m?{angle:m}:{}}}return{type:"circle",cx:h,cy:y,r:g,...p,data:d,index:f,...m?{angle:m}:{}}})}}}function ub(e={}){const t=at(e,{mark:"ellipse",allow:st.ellipse}),{channels:n={},id:r,edits:o}=t;return{...lt(t),type:"ellipse",channels:n,discreteScale:"point",...Xt(n),nodeBox:(i,s,a,l,u,c)=>{const d=se(l,n,"size",i,5,s,a);return{cx:se(l,n,"x",i,u/2,s,a),cy:se(l,n,"y",i,c/2,s,a),hw:Math.max(0,+se(l,n,"rx",i,d,s,a)||0),hh:Math.max(0,+se(l,n,"ry",i,d,s,a)||0),round:!0}},build:(i,s,a,l)=>{const u=It(s,"ellipse",{fill:it(s).ink});return i.map((c,d)=>{const f=yt(s,n,c,u,d,i),p=se(s,n,"x",c,a/2,d,i),h=se(s,n,"y",c,l/2,d,i),y=se(s,n,"size",c,5,d,i),g=se(s,n,"rx",c,y,d,i),m=se(s,n,"ry",c,y,d,i),b=zr(s,n,"angle",c,0,d,i);return{type:"ellipse",cx:p,cy:h,rx:g,ry:m,...f,data:c,index:d,...b?{angle:b}:{}}})}}}function Zp(e,t,n){if(e&&Array.isArray(e.domainConfig))return e.domainConfig;const r=[];for(const o of n)r.includes(o[t])||r.push(o[t]);return r}function U6(e){const t=at(e,{mark:"dotStack",allow:st.dotStack}),{channels:n={},id:r,edits:o,orientation:i,gap:s=2,ghost:a=!0,label:l=!1}=t,{xKey:u,yKey:c}=Xt(n),d=kr(n,null,{orientation:i,single:"other"}),f=n.size&&n.size.value!=null?+n.size.value:7;return{...lt(t),type:"dotStack",channels:n,countAxis:d,countPitch:2*f+s,discreteScale:"point",xKey:u,yKey:c,build:(p,h,y,g)=>{const m=se(h,n,"size",null,7),b=2*m+s,w=d==="y"?u:c,x=d==="y"?"x":"y",S=d==="y"?g:0,v=new Map;p.forEach((L,N)=>{const I=Nn(n,x,L,w,N,p);v.set(I,(v.get(I)||0)+1)});const k=(L,N)=>{const I=se(h,n,x,L,(d==="y"?y:g)/2),O=(N+.5)*b;return{cx:d==="y"?I:S+O,cy:d==="y"?S-O:I}},_=[];if(a)for(const L of Zp(h[x],w,p))_.push({type:"circle",...k({[w]:L},v.get(L)||0),r:m,fill:"none",stroke:"#bbb",strokeWidth:1,pointerEvents:"none"});const T=new Map;if(p.forEach((L,N)=>{const I=Nn(n,x,L,w,N,p),O=T.get(I)||0;T.set(I,O+1);const M=yt(h,n,L,It(h,"dotStack",{fill:it(h).ink}),N,p),$=k(L,O),F=cs(h,n,L,N,p);F!==void 0?_.push(Xl(F,$.cx,$.cy,m,{...M,data:L,index:N})):_.push({type:"circle",...$,r:m,...M,data:L,index:N})}),l)for(const L of Zp(h[x],w,p)){const N=v.get(L)||0;if(N===0)continue;const I={[w]:L},O=se(h,n,x,I,(d==="y"?y:g)/2),M=(N+1)*b;_.push({type:"text",text:String(N),x:d==="y"?O:S+M,y:d==="y"?S-M:O,textAnchor:"middle",fontSize:11,fill:"#555",pointerEvents:"none"})}return _}}}function fd(e={}){return U6(e)}function fb(e={}){return fd({...e,orientation:"vertical"})}function K6(e={}){return fd({...e,orientation:"horizontal"})}const Y6="__single__";function db(e,t="domain"){const n=at(e,{mark:"line",allow:st.line}),{channels:r={},id:o,edits:i,curve:s="linear",handles:a=!0,handleSize:l,handleColor:u,connect:c=t}=n,{xKey:d,yKey:f}=Xt(r),p=Os(r);return{...lt(n),type:"line",channels:r,rawChannels:["curve","series","order"],discreteScale:"point",xKey:d,yKey:f,seriesKey:p,connect:c,supportsSeries:!0,build:(h,y,g,m)=>{const{x:b,y:w}=y,S=kr(r,y,{orientation:n.orientation})==="y"?"x":"y",v=[],k=h.map((N,I)=>({d:N,i:I,cx:se(y,r,"x",N,g/2,I,h),cy:se(y,r,"y",N,m/2,I,h),series:p?N[p]:Y6})),_=new Map;for(const N of k){const I=_.get(N.series);I?I.push(N):_.set(N.series,[N])}const T=It(y,"line",{stroke:it(y).ink,strokeWidth:2});for(const N of _.values()){if(N.length<2)continue;const I=G6(N,c,S,r),O=yt(y,r,N[0].d,T,N[0].i,h),M=String(pt(r,"curve",N[0].d,s,N[0].i,h));v.push({type:"path",points:I.map($=>[$.cx,$.cy]),curve:M,...O,fill:"none",pointerEvents:"none",series:N[0].series})}const L=fn(y,{handles:a,handleSize:l,handleColor:u},{fill:T.stroke});return k.forEach(({d:N,i:I,cx:O,cy:M,series:$})=>{if(!L.grabbable)return;const F=yt(y,r,N,{fill:L.fill,stroke:L.stroke,strokeWidth:L.strokeWidth},I,h);v.push({type:"circle",cx:O,cy:M,r:L.size,...F,...L.visible?{}:{fill:"transparent",stroke:"none",strokeWidth:0},data:N,index:I,series:$,sweepAxis:S})}),v}}}function G6(e,t,n,r){const o=Qf(r);if(o)return[...e].sort((i,s)=>{const a=i.d[o],l=s.d[o];return a<l?-1:a>l?1:0});if(t==="domain"){const i=n==="x"?"cx":"cy";return[...e].sort((s,a)=>s[i]-a[i])}return e}function dd(e={}){return db(e)}function V6(e={}){return dd({...e,orientation:"vertical"})}function X6(e={}){return dd({...e,orientation:"horizontal"})}function J6(e={}){return db(e,"sequence")}const Hc="__single__";function Z6(e,t,n){if(!e)return{channels:t,edits:n};const r={...t};for(const i of e){const s=r[i];s&&s.edit&&(r[i]={...s,edit:cl(s.edit,i)})}const o=n&&n.map(i=>{const s=(i.channels||[]).filter(a=>e.includes(a));return s.length===1?cl(i,s[0]):i});return{channels:r,edits:o}}function Q6(e){const t=at(e,{mark:"area",allow:st.area}),{channels:n={},id:r,edits:o,curve:i="linear",handles:s=!0,handleSize:a,handleColor:l,connect:u="domain"}=t,{xKey:c,yKey:d}=Xt(n),f=Os(n),p=!!(n.x1&&n.x2),h=!!(n.y1&&n.y2),y=h?["y1","y2"]:p?["x1","x2"]:null,{channels:g,edits:m}=Z6(y,n,o);return{...lt(t),type:"area",channels:g,rawChannels:["curve","series","order"],discreteScale:"point",xKey:c,yKey:d,seriesKey:f,connect:u,supportsSeries:!0,build:(b,w,x,S)=>{const{x:v,y:k}=w,_=kr(g,w,{orientation:t.orientation,extent:"value"}),T=_==="y"?h:p,L=new Map;b.forEach(($,F)=>{const D=f!=null?$[f]:Hc;let z=L.get(D);z||(z=[],L.set(D,z)),z.push({d:$,i:F})});const N=[],I=fn(w,{handles:s,handleSize:a,handleColor:l}),O=yr(k),M=yr(v);for(const[$,F]of L){const z=[...F||[]],j=Qf(g);if(j)z.sort((me,ce)=>me.d[j]<ce.d[j]?-1:me.d[j]>ce.d[j]?1:0);else if(u==="domain"){const me=_==="y"?c:d;z.sort((ce,Y)=>{const fe=ce.d[me],ie=Y.d[me];return fe instanceof Date&&ie instanceof Date?fe-ie:fe<ie?-1:fe>ie?1:0})}const G=it(w).ink,J=yt(w,g,z[0]?z[0].d:{},It(w,"area",{fill:G,stroke:G,fillOpacity:.35}),z[0]?z[0].i:void 0,b),re=String(pt(g,"curve",z[0]?z[0].d:{},i,z[0]?z[0].i:void 0,b));let Q,ve;if(_==="y"){const me=(ce,Y)=>se(w,g,"x",ce,x/2,Y,b);Q=z.map(({d:ce,i:Y})=>[me(ce,Y),T?se(w,g,"y2",ce,O,Y,b):se(w,g,"y",ce,S/2,Y,b)]),ve=[...z].reverse().map(({d:ce,i:Y})=>[me(ce,Y),T?se(w,g,"y1",ce,O,Y,b):O])}else{const me=(ce,Y)=>se(w,g,"y",ce,S/2,Y,b);Q=z.map(({d:ce,i:Y})=>[T?se(w,g,"x2",ce,M,Y,b):se(w,g,"x",ce,x/2,Y,b),me(ce,Y)]),ve=[...z].reverse().map(({d:ce,i:Y})=>[T?se(w,g,"x1",ce,M,Y,b):M,me(ce,Y)])}const Ce=[...Q,...ve];Ce.length>=2&&N.push({type:"path",points:Ce,curve:re,...J,strokeWidth:J.strokeWidth!=null?J.strokeWidth:1,series:$===Hc?void 0:$,pointerEvents:"none"});const le=T?_==="y"?["y1","y2"]:["x1","x2"]:[_];I.grabbable&&z.forEach(({d:me,i:ce})=>{const Y=yt(w,g,me,{fill:I.fill,stroke:I.stroke,strokeWidth:I.strokeWidth},ce,b);for(const fe of le){const ie=fe[0]==="y",U=ie?se(w,g,"x",me,x/2,ce,b):se(w,g,"y",me,S/2,ce,b),we=se(w,g,fe,me,ie?S/2:x/2,ce,b);N.push({type:"circle",cx:ie?U:we,cy:ie?we:U,r:I.size,...Y,...I.visible?{}:{fill:"transparent",stroke:"none",strokeWidth:0},data:me,index:ce,channel:fe,series:$===Hc?void 0:$})}})}return N}}}function hd(e={}){return Q6(e)}function eA(e={}){return hd({...e,orientation:"vertical"})}function tA(e={}){return hd({...e,orientation:"horizontal"})}const Xu=16,hb=16;function rc(e,t,n,r=Xu){const o=[];for(let i=0;i<=r;i++){const s=i/r,a=1-s;o.push([a*a*e[0]+2*a*s*t[0]+s*s*n[0],a*a*e[1]+2*a*s*t[1]+s*s*n[1]])}return o}function dl(e,t,n,r){const o=[];for(let i=0;i<=Xu;i++){const s=i/Xu,a=1-s,l=a*a*a,u=3*a*a*s,c=3*a*s*s,d=s*s*s;o.push([l*e[0]+u*t[0]+c*n[0]+d*r[0],l*e[1]+u*t[1]+c*n[1]+d*r[1]])}return o}function Uc(e,t,n){if(!n)return e;const r=-n*Math.PI/180,o=Math.cos(r),i=Math.sin(r),s=e[0]-t.cx,a=e[1]-t.cy;return[t.cx+s*o-a*i,t.cy+s*i+a*o]}function nA(e){const t=at(e,{mark:"curve",allow:st.curve}),{channels:n={},id:r,edits:o,length:i}=t,{xKey:s,yKey:a}=Xt(n);return{...lt(t),type:"curve",channels:n,discreteScale:"point",xKey:s,yKey:a,build:(l,u,c,d)=>{const f=kr(n,u,{orientation:t.orientation,extent:"span",single:"other"}),p=f==="x"?"y":"x",h=p==="x"?c:d,y=f==="x"?c:d,g=It(u,"curve",{fill:"none",stroke:it(u).ink,strokeWidth:2}),m=[];return l.forEach((b,w)=>{const x=yt(u,n,b,g,w,l),S=se(u,n,f,b,y/2,w,l);let v,k;if(n[`${p}1`]&&n[`${p}2`])v=se(u,n,`${p}1`,b,h*.25,w,l),k=se(u,n,`${p}2`,b,h*.75,w,l);else{const re=se(u,n,p,b,h/2,w,l),Q=(i??Math.min(c,d)*.25)/2;v=re-Q,k=re+Q}let _=p==="x"?[v,S]:[S,v],T=p==="x"?[k,S]:[S,k];const L={cx:(_[0]+T[0])/2,cy:(_[1]+T[1])/2},N=T[0]-_[0],I=T[1]-_[1],O=Math.hypot(N,I)||1,M=I/O,$=-N/O,D=(se(u,n,"curvature",b,0,w,l)||0)*(O/2);let z=[L.cx+M*D*2,L.cy+$*D*2];const j=zr(u,n,"angle",b,0,w,l);j&&(_=Uc(_,L,j),T=Uc(T,L,j),z=Uc(z,L,j));const G=`M ${_[0]} ${_[1]} Q ${z[0]} ${z[1]} ${T[0]} ${T[1]}`,J=rc(_,z,T);m.push({type:"path",d:G,cx:L.cx,cy:L.cy,...x,data:b,index:w,pointerEvents:"none"}),m.push({type:"path",d:G,points:J,cx:L.cx,cy:L.cy,fill:"none",stroke:"transparent",strokeWidth:Math.max(hb,(x.strokeWidth||2)*6),data:b,index:w,cursor:"grab"})}),m}}}function pd(e={}){return nA(e)}function pb(e={}){return pd({...e,orientation:"vertical"})}function rA(e={}){return pd({...e,orientation:"horizontal"})}function yb(e){return e*Math.PI/180}function cn(e,t,n,r){const o=yb(r);return{x:e+n*Math.cos(o),y:t-n*Math.sin(o)}}const $a={top:[180,0],right:[-90,90],bottom:[0,-180],left:[90,270]};function yd(e={}){return e.start!=null&&e.end!=null?[e.start,e.end]:e.arc==="full"?[-180,180]:e.orient&&$a[e.orient]?$a[e.orient]:$a.top}function gb(e,t){let n=t-e;for(;n>360;)n-=360;for(;n<-360;)n+=360;return n}function ps(e,t,n,r,o,i={}){const s=i.innerRadius||0,a=gb(r,o);if(Math.abs(a)<1e-6||n<=0)return"";if(Math.abs(Math.abs(a)-360)<1e-6){const y=r+a/2,g=ps(e,t,n,r,y,i),m=ps(e,t,n,y,o,i);return`${g} ${m}`.trim()}const l=a>=0?0:1,u=Math.abs(a)>180?1:0,c=cn(e,t,n,r),d=cn(e,t,n,o);if(s<=0)return[`M ${e} ${t}`,`L ${c.x} ${c.y}`,`A ${n} ${n} 0 ${u} ${l} ${d.x} ${d.y}`,"Z"].join(" ");const f=cn(e,t,s,r),p=cn(e,t,s,o),h=l===0?1:0;return[`M ${c.x} ${c.y}`,`A ${n} ${n} 0 ${u} ${l} ${d.x} ${d.y}`,`L ${p.x} ${p.y}`,`A ${s} ${s} 0 ${u} ${h} ${f.x} ${f.y}`,"Z"].join(" ")}function hl(e,t,n,r,o){const i=gb(r,o);if(Math.abs(i)<1e-6||n<=0)return"";if(Math.abs(Math.abs(i)-360)<1e-6){const c=r+i/2;return`${hl(e,t,n,r,c)} ${hl(e,t,n,c,o)}`.trim()}const s=cn(e,t,n,r),a=cn(e,t,n,o),l=Math.abs(i)>180?1:0,u=i>=0?0:1;return`M ${s.x} ${s.y} A ${n} ${n} 0 ${l} ${u} ${a.x} ${a.y}`}function mb(e,t){if(!e||!fo(e))return null;const n=e.domain();if(!n.length)return null;if(Vn(e)){const c=e(t);return c==null?null:[c,c+e.bandwidth()]}const r=e.range(),o=r[0],i=r[r.length-1],s=n.indexOf(t);if(s<0)return null;const a=n.map(c=>e(c)),l=s===0?o:(a[s-1]+a[s])/2,u=s===n.length-1?i:(a[s]+a[s+1])/2;return[l,u]}function bb(e,t,n,r,o=10){const i=cn(e,t,n,r),s=o/2,a=cn(e,t,s,r+90),l=cn(e,t,s,r-90);return[[i.x,i.y],[a.x,a.y],[l.x,l.y]]}function wb(e={}){const t=at(e,{mark:"arc",allow:st.arc}),{channels:n={},id:r,edits:o,outerRadius:i,innerRadius:s=0,padAngle:a=0,arc:l,start:u,end:c,handles:d=!0,handleSize:f,handleColor:p}=t,h=o||[],y=h.some(w=>w&&w.scope==="stack"),[g,m]=yd({arc:l||"full",start:u??(l?void 0:-180),end:c??(l?void 0:180)}),b=n.theta&&n.theta.field;return{...lt(t),type:"arc",channels:n,rawChannels:["theta"],edits:h,discreteScale:"band",yKey:b,supportsStack:!0,build:(w,x,S,v)=>{const k=ad(w,n,["x","y"]),_=Vn(x.x),T=Vn(x.y),L=_?yn(x.x,S):S,N=T?yn(x.y,v):v,I=_||T?.42*Math.min(L,N):(k.length>1?.14:.4)*Math.min(S,v),O=m-g,M=a,$=[],F=fn(x,{handles:d,handleSize:f,handleColor:p});return k.forEach(D=>{const z=D.rep,j=D.members,G=j[0],J=se(x,n,"x",z,S/2,G,w),re=se(x,n,"y",z,v/2,G,w),Q=i??(n.size?se(x,n,"size",z,I,G,w):I),ve=s>0&&s<=1?s*Q:Math.min(s,Q*.95),Ce=b!=null?tc(j,w,b).mags:j.map(U=>{const we=se(x,n,"theta",w[U],0,U,w);return Number.isFinite(we)&&we>0?Number(we):0}),le=Ce.reduce((U,we)=>U+we,0),me=j.length,ce=le>0?O-M*me:0,Y={kind:"angular",cx:J,cy:re,spanStart:g,spanEnd:m,pad:M},fe={};let ie=g+M/2;if(j.forEach((U,we)=>{const xe=w[U],P=le>0?Ce[we]/le:0,H=ce*P,oe=ie,he=ie+H;if(ie=he+M,fe[we]=he,H<=0)return;const ke=yt(x,n,xe,It(x,"arc",{fill:"#4f46e5",stroke:"#fff",strokeWidth:1}),U,w),pe=ps(J,re,Q,oe,he,{innerRadius:ve});pe&&$.push({type:"path",d:pe,...ke,cx:J,cy:re,index:U,midAngle:(oe+he)/2,a0:oe,a1:he,stack:ds({members:j,local:we,field:b,geometry:Y}),sector:{cx:J,cy:re,r0:ve,r1:Q,a0:oe,a1:he}})}),y&&F.grabbable&&le>0&&me>1)for(let U=0;U<me-1;U++){const we=fe[U]+M/2,xe=cn(J,re,Q,we);$.push({type:"circle",cx:xe.x,cy:xe.y,r:F.size,fill:F.visible?F.fill:"transparent",stroke:F.visible?F.stroke:"none",strokeWidth:F.visible?F.strokeWidth:0,cursor:"grab",index:j[U],edge:!0,loIndex:j[U],hiIndex:j[U+1],stack:ds({members:j,local:U,field:b,geometry:Y})})}}),$}}}function oA(e={}){const t=e.innerRadius!=null?e.innerRadius:e.outerRadius!=null?e.outerRadius*.55:.55;return wb({...e,arc:e.arc||"full",innerRadius:t})}function iA(e={}){const t=at(e,{mark:"needle",allow:st.needle});for(const p of["arc","orient","start","end"])e&&e[p]!==void 0&&ge(`needle:span:${p}`,`needle({ ${p}: … }) does nothing: a needle's sweep is the theta scale's range. Set it on the channel — channels: { theta: { field, scale: { range: [180, 0] } } } — or chart-wide with scales: { theta: { range } }; axisRadial takes arc/orient/start/end for the chrome.`);t.channels&&t.channels.angle&&!t.channels.theta&&ge("needle:angle","needle({ channels: { angle: … } }) — a needle's direction is `theta`, the polar angular POSITION (what axisRadial draws). `angle` is a mark's rotation in place and this mark does not read it, so the needle would point at 0°. Rename the channel to `theta`.");const{channels:n={},id:r,edits:o,length:i,handles:s=!0,handleSize:a,handleColor:l,baseWidth:u=10}=t,c=n.theta&&n.theta.field,d=n.x&&n.x.field,f=n.y&&n.y.field;return{...lt(t),type:"needle",channels:n,discreteScale:"point",xKey:d||c,yKey:f||c,build:(p,h,y,g)=>{const m=[],b=fn(h,{handles:s,handleSize:a,handleColor:l});return p.forEach((w,x)=>{const S=se(h,n,"x",w,y/2,x,p),v=se(h,n,"y",w,g/2,x,p),k=zr(h,n,"theta",w,0,x,p),_=i??se(h,n,"size",w,Math.min(y,g)*.4,x,p),T=yt(h,n,w,It(h,"needle",{fill:"#1e293b",stroke:"#1e293b",strokeWidth:1}),x,p),L=bb(S,v,_,k,u),N=`M ${L[0][0]} ${L[0][1]} L ${L[1][0]} ${L[1][1]} L ${L[2][0]} ${L[2][1]} Z`;m.push({type:"path",d:N,...T,cx:S,cy:v,data:w,index:x,cursor:b.grabbable?"grab":void 0}),b.grabbable&&m.push({type:"circle",cx:S,cy:v,r:b.size,fill:b.fill,stroke:b.stroke,strokeWidth:b.strokeWidth,data:w,index:x,cursor:"grab"})}),m}}}const sA=.52,aA=4096,yi=new Map;let _o;function lA(){if(_o!==void 0)return _o;if(_o=null,typeof document<"u")try{_o=document.createElement("canvas").getContext("2d")}catch{_o=null}return _o}function cA({fontSize:e=12,fontFamily:t="sans-serif",fontWeight:n="normal"}){return`${n} ${e}px ${t}`}function qi(e,t={}){const n=e==null?"":String(e);if(!n)return 0;const r=cA(t),o=`${r}\0${n}`,i=yi.get(o);if(i!==void 0)return i;const s=lA();let a;if(s?(s.font=r,a=s.measureText(n).width):a=n.length*(t.fontSize||12)*sA,yi.size>=aA){const l=yi.keys().next().value;l!==void 0&&yi.delete(l)}return yi.set(o,a),a}function xb(e,t={}){const{maxWidth:n,...r}=t,i=(e==null?"":String(e)).split(`
13
+ `);if(!n||n<=0)return i;const s=[];for(const a of i){const l=a.split(/\s+/).filter(c=>c.length);if(!l.length){s.push("");continue}let u="";for(const c of l){const d=u?`${u} ${c}`:c;if(qi(d,r)<=n){u=d;continue}if(u&&s.push(u),qi(c,r)>n){let f="";for(const p of c)f&&qi(f+p,r)>n?(s.push(f),f=p):f+=p;u=f}else u=c}s.push(u)}return s}function oc(e,t={}){const{lineHeight:n,...r}=t,o=r.fontSize||12,i=n||Math.round(o*1.35),s=xb(e,r);let a=0;for(const l of s)a=Math.max(a,qi(l,r));return{lines:s,width:a,height:s.length*i,lineHeight:i}}function $n(e,t={}){const{padding:n=10,maxWidth:r=160,minWidth:o=60,minHeight:i=0,fontSize:s=13,fontFamily:a,lineHeight:l}=t,u=oc(e==null?"":String(e),{maxWidth:r-n*2,fontSize:+s||13,fontFamily:a,lineHeight:l});return{block:u,width:Math.max(o,Math.min(r,u.width+n*2)),height:Math.max(i,u.height+n*2)}}function $r(e){if(typeof e=="function")return e;if(typeof e=="string"){const t=ti(e);return n=>n==null||n===""?"":t(n)}return t=>t==null?"":String(t)}function uA(e=""){return $r(e)}function fA(e=".0%"){return $r(e)}function dA(e=".2s"){return $r(e)}function hA(e="%Y-%m-%d"){const t=zf(e);return n=>{if(n==null||n==="")return"";const r=n instanceof Date?n:new Date(n);return Number.isNaN(+r)?String(n):t(r)}}function pA(e,t=""){const n=$r(t);return r=>r==null||r===""?"":`${e}${n(r)}`}function yA(e,t=""){const n=$r(t);return r=>r==null||r===""?"":`${n(r)}${e}`}const gA=Object.freeze(Object.defineProperty({__proto__:null,number:uA,percent:fA,prefix:pA,resolveFormat:$r,si:dA,suffix:yA,time:hA},Symbol.toStringTag,{value:"Module"}));function mA(e){switch(e){case"top":return"text-before-edge";case"bottom":return"text-after-edge";default:return"central"}}function gd(e,t,n,r,o,i,s={}){const{format:a=x=>x,data:l,wrap:u,lineHeight:c}=s,d=typeof u=="function"?u(n,r,l||[n]):u,f=yt(e,t,n,It(e,"text",{fill:"#111"}),r,l),p=+pt(t,"dx",n,0,r,l)||0,h=+pt(t,"dy",n,0,r,l)||0,y=zr(e,t,"angle",n,0,r,l),g=pt(t,"lineAnchor",n,"middle",r,l),m=pt(t,"fontSize",n,12,r,l),b=a(pt(t,"text",n,"",r,l)),w=d||c?oc(b,{maxWidth:d,fontSize:+m||12,fontFamily:it(e).font&&it(e).font.family||void 0,lineHeight:c}):null;return{type:"text",x:o+p,y:i+h,text:b,fontSize:m,textAnchor:pt(t,"textAnchor",n,"middle",r,l),lineAnchor:g,dominantBaseline:mA(g),...y?{angle:y}:{},...w&&w.lines.length>1?{lines:w.lines,lineHeight:w.lineHeight}:{},...f,data:n,index:r}}function bA(e){const t=at(e,{mark:"text",allow:st.text}),{channels:n={},id:r,edits:o,format:i,wrap:s,lineHeight:a}=t,l=$r(i);return{...lt(t),type:"text",channels:n,rawChannels:["text","fontSize","textAnchor","lineAnchor","dx","dy"],discreteScale:"point",...Xt(n),build:(c,d,f,p)=>c.map((h,y)=>{const{x:g,y:m}=u(h,y,c,d,f,p);return gd(d,n,h,y,g,m,{format:l,data:c,wrap:s,lineHeight:a})}),labelBox:!0,nodeBox:(c,d,f,p,h,y)=>{const g=u(c,d,f,p,h,y),m=+pt(n,"dx",c,0,d,f)||0,b=+pt(n,"dy",c,0,d,f)||0,w=+pt(n,"fontSize",c,12,d,f)||12,x=oc(l(pt(n,"text",c,"",d,f)),{maxWidth:typeof s=="function"?s(c,d,f):s,fontSize:w,fontFamily:it(p).font&&it(p).font.family||void 0,lineHeight:a}),S=x.width/2,v=x.height/2,k=pt(n,"textAnchor",c,"middle",d,f),_=pt(n,"lineAnchor",c,"middle",d,f),T=g.x+m,L=g.y+b;return{cx:k==="start"?T+S:k==="end"?T-S:T,cy:_==="top"?L+v:_==="bottom"?L-v:L,hw:S,hh:v}}};function u(c,d,f,p,h,y){const g=t.orientation==="vertical"?"y":t.orientation==="horizontal"?"x":null;return{x:g==="y"?h/2:se(p,n,"x",c,h/2,d,f),y:g==="x"?y/2:se(p,n,"y",c,y/2,d,f)}}}function Or(e={}){return bA(e)}function wA(e={}){return Or({...e,orientation:"horizontal"})}function xA(e={}){return Or({...e,orientation:"vertical"})}const vA=["intercept","slope","interceptSpread","slopeSpread","intercept1","intercept2","slope1","slope2"];function md(e,t={}){const n={x:{field:"x"},y:{field:"y"},...t,...e};for(const r of vA){const o=n[r];o&&(n[r]={...o,scale:null})}return n}function bd(e,t,n,r,o){const i=(p,h)=>{const y=se(n,t,p,e,h,r,o),g=Number(y);return Number.isFinite(g)?g:h},s=i("intercept",0),a=i("slope",0),l=(p,h)=>{if(t[`${p}1`]||t[`${p}2`]){const g=i(`${p}1`,h),m=i(`${p}2`,h);return g<=m?[g,m]:[m,g]}const y=Math.abs(i(`${p}Spread`,0));return[h-y,h+y]},[u,c]=l("intercept",s),[d,f]=l("slope",a);return{a:s,b:a,aLo:u,aHi:c,bLo:d,bHi:f}}function wd(e){const t=e.x&&e.x.domainConfig;return{x0:Array.isArray(t)?Number(t[0]):0,x1:Array.isArray(t)?Number(t[t.length-1]):1}}function ic(e,t={}){const{x0:n,x1:r}=wd(e),o=Math.min(n,r),i=Math.max(n,r),s=o<=0&&0<=i?0:n;return{anchor:t.anchor!=null?Number(t.anchor):s,probe:t.probe!=null?Number(t.probe):r}}const Cr=(e,t)=>e.a+e.b*t;function kA(e,t,n,r,o,i){const s=n-e,a=r-t;if(s===0&&a===0)return e<0||e>o||t<0||t>i?null:{x1:e,y1:t,x2:n,y2:r};let l=-1/0,u=1/0;const c=(d,f)=>{if(d===0)return f>=0;const p=f/d;if(d<0){if(p>u)return!1;p>l&&(l=p)}else{if(p<l)return!1;p<u&&(u=p)}return!0};return!c(-s,e-0)||!c(s,o-e)||!c(-a,t-0)||!c(a,i-t)||l>u?null:{x1:e+l*s,y1:t+l*a,x2:e+u*s,y2:t+u*a}}function SA(e,t,n){const r=[{inside:s=>s[0]>=0,at:(s,a)=>o(s,a,0,0)},{inside:s=>s[0]<=t,at:(s,a)=>o(s,a,0,t)},{inside:s=>s[1]>=0,at:(s,a)=>o(s,a,1,0)},{inside:s=>s[1]<=n,at:(s,a)=>o(s,a,1,n)}];function o(s,a,l,u){const c=a[l]-s[l],d=c===0?0:(u-s[l])/c;return[s[0]+d*(a[0]-s[0]),s[1]+d*(a[1]-s[1])]}let i=e;for(const s of r){const a=[];for(let l=0;l<i.length;l++){const u=i[l],c=i[(l+i.length-1)%i.length],d=s.inside(u),f=s.inside(c);d?(f||a.push(s.at(c,u)),a.push(u)):f&&a.push(s.at(c,u))}if(i=a,!i.length)return[]}return i}function pl(e,t,n,r,o){const{x0:i,x1:s}=wd(t),a=u=>Ft(t,n,"x",u,0),l=u=>Ft(t,n,"y",u,0);return kA(a(i),l(Cr(e,i)),a(s),l(Cr(e,s)),r,o)}function vb(e,t=0){if(!e)return null;const n=e.x2-e.x1,r=e.y2-e.y1,o=Math.hypot(n,r);if(!Number.isFinite(o))return null;const i=t>0&&o>4*t?t/o:0;return[{x:e.x1+i*n,y:e.y1+i*r},{x:e.x2-i*n,y:e.y2-i*r}]}function xd(e,t,n,r,o){const{aLo:i,aHi:s,bLo:a,bHi:l}=e,{x0:u,x1:c}=wd(t),d=Math.min(u,c),f=Math.max(u,c),p=[d];d<0&&0<f&&p.push(0),p.push(f);const h=w=>Ft(t,n,"x",w,0),y=w=>Ft(t,n,"y",w,0),g=w=>s+Math.max(a*w,l*w),m=w=>i+Math.min(a*w,l*w),b=[];for(const w of p)b.push([h(w),y(g(w))]);for(let w=p.length-1;w>=0;w--)b.push([h(p[w]),y(m(p[w]))]);return SA(b,r,o)}function kb(e,t,n,r,o,i){const{a:s,b:a,aLo:l,aHi:u,bLo:c,bHi:d}=e,f=[];for(let p=1;p<=t;p++){const h=p/t,y={aLo:s-(s-l)*h,aHi:s+(u-s)*h,bLo:a-(a-c)*h,bHi:a+(d-a)*h},g=xd(y,n,r,o,i);g.length>=3&&f.push(g)}return f}function $A(e){let t=e>>>0;return function(){t|=0,t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function _A(e){let t=0,n=0;for(;t===0;)t=e();for(;n===0;)n=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*n)}function Sb(e,t={}){const{samples:n=60,seed:r=7,distribution:o="normal",sigma:i=1.96}=t,{a:s,b:a,aLo:l,aHi:u,bLo:c,bHi:d}=e,f=$A(r),p=i>0?i:1.96,h=(g,m,b)=>{if(o==="uniform")return m+f()*(b-m);const w=_A(f)/p;return w>=0?g+w*(b-g):g+w*(g-m)},y=[];for(let g=0;g<n;g++)y.push({a:h(s,l,u),b:h(a,c,d)});return y}function $b(e={}){const t=at(e,{mark:"trend",allow:st.trend}),{edits:n,anchor:r,probe:o,grip:i="end",handles:s=!0,handleSize:a,handleColor:l}=t;o!=null&&i!=="probe"&&ge("trend:probe-ignored","trend(): `probe` places the slope handle only under `grip: 'probe'`. The default grip mounts the handles on the line's own ends; add `grip: 'probe'` to pin one at that column instead.");const u=md(t.channels||{},{intercept:{field:"intercept"},slope:{field:"slope"}}),c={anchor:r,probe:o};return{...lt(t),type:"trend",channels:u,isTrend:!0,supportsTrend:!0,...Xt(u),requires:[{channels:["x","y"],kind:"continuous",match:"all",why:"an intercept and a slope are only defined over two continuous axes."}],build:(d,f,p,h)=>{if(!f.x||!f.y)return[];const{anchor:y,probe:g}=ic(f,c),m=[],b=It(f,"trend",{stroke:"#333",fill:"#333"}),w=fn(f,{handles:s,handleSize:a,handleColor:l},{fill:b.fill});return d.forEach((x,S)=>{const v=bd(x,u,f,S,d),k=yt(f,u,x,b,S,d),_=pl(v,f,u,p,h);if(_&&m.push({type:"line",..._,stroke:k.stroke||b.stroke,strokeWidth:k.strokeWidth||2,pointerEvents:"none"}),!w.grabbable)return;const T=(L,N,I)=>{m.push({type:"circle",cx:N,cy:I,r:w.size,fill:w.visible?k.fill||w.fill:"transparent",data:x,index:S,channel:L,anchor:y,probe:g,grip:i})};if(T("intercept",Ft(f,u,"x",y,0),Ft(f,u,"y",Cr(v,y),0)),i==="probe"){T("slope",Ft(f,u,"x",g,0),Ft(f,u,"y",Cr(v,g),0));return}for(const L of vb(_,w.size+1)||[])T("slope",L.x,L.y)}),m}}}function _b(e={}){const t=at(e,{mark:"trendBand",allow:st.trendBand}),{edits:n,render:r="region",levels:o=5,samples:i=60,seed:s=7,sigma:a=1.96,distribution:l="normal",anchor:u,probe:c,grip:d="end",handles:f=!1,handleSize:p,handleColor:h}=t;c!=null&&d!=="probe"&&ge("trendBand:probe-ignored","trendBand(): `probe` places the slopeSpread handle only under `grip: 'probe'`. The default grip mounts the handles on the band's own edge ends; add `grip: 'probe'` to pin one at that column instead.");const y=md(t.channels||{},{intercept:{field:"intercept"},slope:{field:"slope"}}),g={anchor:u,probe:c};return{...lt(t),type:"trendBand",channels:y,supportsTrend:!0,isTrend:!0,...Xt(y),requires:[{channels:["x","y"],kind:"continuous",match:"all",why:"an intercept and a slope are only defined over two continuous axes."}],build:(m,b,w,x)=>{if(!b.x||!b.y)return[];const{anchor:S,probe:v}=ic(b,g),k=[],_=fn(b,{handles:f,handleSize:p,handleColor:h}),T=it(b).ink,L=It(b,"trendBand",{fill:T,stroke:T,fillOpacity:.18,strokeOpacity:.15}),N=(I,O)=>{const M=vb(pl(I,b,y,w,x),_.size+1);if(!M)return null;const $=b.x,F=$&&$.invertible?j=>Number($.invertValue(j.x)):j=>j.x,[D,z]=M;return O>0==F(D)>=F(z)?D:z};return m.forEach((I,O)=>{const M=bd(I,y,b,O,m),$=yt(b,y,I,L,O,m),F=$.fill||L.fill,D=$.fillOpacity,z=M.aLo===M.aHi&&M.bLo===M.bHi;if(!z&&r==="samples")for(const J of Sb(M,{samples:i,seed:s,distribution:l,sigma:a})){const re=pl(J,b,y,w,x);re&&k.push({type:"line",...re,stroke:$.stroke||L.stroke,strokeWidth:$.strokeWidth!=null?$.strokeWidth:1,strokeOpacity:$.strokeOpacity,pointerEvents:"none",background:!0})}else if(!z&&r==="gradient"){const J=Math.max(1,Math.round(o)),re=1-Math.pow(1-Math.min(.99,D),1/J);for(const Q of kb(M,J,b,y,w,x))k.push({type:"path",points:Q,curve:"linear",fill:F,fillOpacity:re,stroke:"none",pointerEvents:"none",background:!0})}else if(!z){const J=xd(M,b,y,w,x);J.length>=3&&k.push({type:"path",points:J,curve:"linear",fill:F,fillOpacity:D,stroke:"none",pointerEvents:"none",background:!0})}if(!_.grabbable)return;const j=J=>M.aHi+Math.max(M.bLo*J,M.bHi*J),G=(J,re,Q)=>{k.push({type:"circle",cx:re,cy:Q,r:_.size,fill:_.visible?h||F:"transparent",data:I,index:O,channel:J,anchor:S,probe:v,grip:d})};if(y.interceptSpread&&G("interceptSpread",Ft(b,y,"x",S,0),Ft(b,y,"y",z?Cr(M,S):j(S),0)),!!y.slopeSpread){if(d==="probe"){G("slopeSpread",Ft(b,y,"x",v,0),Ft(b,y,"y",z?Cr(M,v):j(v),0));return}for(const[J,re]of[[1,M.bHi],[-1,M.bLo]]){const Q=N({a:M.aHi,b:re},J);Q&&G("slopeSpread",Q.x,Q.y)}}}),k}}}const ia=["x","y","size"],MA=["ports"];let EA=0;function AA(e,t,n){const r={};for(const[o,i]of Object.entries(e||{}))if(i)if(!n&&i.edit){const{edit:s,...a}=i;r[o]=a}else r[o]=i;for(const[o,i]of Object.entries(t||{}))i!==void 0&&(r[o]=i);return r}function Qp(e){for(const[t,n]of Object.entries(e||{})){const r=LM(n);r!==n&&(e[t]=r)}return e}function TA(e){return Object.values(e||{}).some(t=>!!Gr(t))}function OA(e,t,n){const r=[];Vn(e.x)&&r.push(yn(e.x,0)),Vn(e.y)&&r.push(yn(e.y,0));const o=r.filter(i=>i>0);return o.length?Math.min(...o)/2:Math.min(t,n)*.35}function Kc(e,t,n,r,o,i,s){const a=OA(e,i,s);return{cx:se(e,t,"x",n,i/2,r,o),cy:se(e,t,"y",n,s/2,r,o),r:se(e,t,"size",n,a,r,o)}}function CA(e,t,n){if(e.field==null)return t;const r=n&&n[e.field],o=r&&r.domain;return Array.isArray(o)&&o.length?[o[0],o[o.length-1]]:(ge(`frame:domain:${e.field}`,`field "${e.field}" is encoded in a composite's local frame, but the schema declares no domain for it — a frame maps the field's DOMAIN onto the glyph's local box, so without one it falls back to [0, 1]. Declare it: schema: { ${e.field}: { type: "quantitative", domain: [lo, hi] } }.`),[0,1])}function NA(e,t,n,r,o,i){const s={};for(const a of t){const l=e[a],u=Gr(l)||{},c=Wf(a),d=u.range||RM(a)||u0(a,"linear",o,i),f=AM({domain:CA(l,d,r),localRange:d,origin:c==="x"?n.cx:c==="y"?n.cy:0,halfSize:n.r,family:c});f&&(s[a]=f,l&&l.field!=null&&(s[uo(a,l.field)]=f))}return s}function IA(e,t,n){const r={};for(const o of t){const i=e[o],s=n[o];if(!i||!i.edit||i.field==null||!s)continue;const a=Wf(o);if(a!=="x"&&a!=="y")continue;const l=s.domainConfig||[];if(l.length<2||r[a])continue;const u=l[0],c=l[l.length-1];r[a]={channel:o,field:i.field,pxAt0:s.encode(u),pxAt1:s.encode(c),loVal:u,hiVal:c}}return Object.keys(r).length?r:null}function ii(e={}){const t=`glyph#${++EA}`,n=at(e,{mark:"composite",allow:st.composite}),{id:r,parts:o=[],edits:i,table:s,channels:a={},discreteScale:l="band"}=n,u=r||"composite",c=o.length-1;Qp(a);for(const m of o)Qp(m.channels||(m.channels={}));const d=o.some(m=>TA(m.channels))||Object.entries(a).some(([m,b])=>!ia.includes(m)&&Gr(b)),f={};for(const[m,b]of Object.entries(a))d&&ia.includes(m)||MA.includes(m)||(f[m]=b);if(!d&&a.ports){const m=o.filter(w=>typeof w.nodeBox=="function"),b=m.find(w=>!w.labelBox)||m[0]||o[0];b&&((b.channels||(b.channels={})).ports=a.ports)}const p=o.map((m,b)=>{const w=m.channels,x=AA(f,{...w},b===c);for(const _ of Object.keys(w))delete w[_];Object.assign(w,x);let S=Object.keys(w).filter(_=>Gr(w[_]));if(S.length)for(const _ of["x","y"])w[_]===void 0&&(w[_]={datum:0,scale:"frame"},S.push(_));S.length&&m.supportsSeries&&ge(`composite:series:${u}:${b}`,`composite "${u}" contains a series mark (${m.type||"a line-family mark"}) with local (frame) channels. A frame is per ROW, so the mark is built one row at a time and cannot group rows into a series. Position it on the global scales, or move it out of the composite.`);const v=m.build,k=S.length?((_,T,L,N)=>{const I=T.schema||{},O=it(T),M={width:L,height:N},$=[];for(let F=0;F<_.length;F++){const D=_[F],z=Kc(T,a,D,F,_,L,N),j=NA(w,S,z,I,M,O),G=IA(w,S,j),J=v([D],{...T,...j},L,N)||[];for(const re of J)re.index=F,re.data=D,re.frame=j,G&&re.dm==null&&(re.dm=G),$.push(re)}return $}):v;return{...m,channels:w,build:k,nodeBox:S.length?void 0:m.nodeBox,labelBox:m.labelBox,glyph:t,xKey:w.x&&w.x.field||m.xKey,yKey:w.y&&w.y.field||m.yKey,id:m.id||`${u}/${b}`,table:m.table||s,discreteScale:m.discreteScale||l,edits:!d&&b===c&&i?[...i,...m.edits||[]]:m.edits}});if(!d)return p;const h={};for(const m of ia){const b=a[m];!b||Gr(b)||(h[m]=b)}a.ports&&(h.ports=a.ports);const y=!!(i&&i.length)||ia.some(m=>h[m]&&h[m].edit);return[{id:`${u}/frame`,type:"composite",glyph:t,channels:h,edits:i,table:s,discreteScale:l,...Xt(h),nodeBox:(m,b,w,x,S,v)=>{const k=Kc(x,a,m,b,w,S,v);return{cx:k.cx,cy:k.cy,hw:k.r,hh:k.r,round:!0}},build:(m,b,w,x)=>m.map((S,v)=>{const k=Kc(b,a,S,v,m,w,x);return{type:"circle",cx:k.cx,cy:k.cy,r:k.r,fill:"none",stroke:"none",hit:!0,...y?{pointerEvents:"all"}:{},data:S,index:v}})},...p]}const LA=e=>e<0?0:e>1?1:e,FA=["mouthCurve","mouthAsym","eyeScale","eyeSquint","browHeight","browTilt"],vt={ink:"#1f2937",headFill:"#FFD666",headStroke:"#B7791F",headStrokeWidth:.03,lineWidth:.055,eyeX:.4,eyeY:.16,eyeRx:[.055,.185],eyeRy:[.12,.03],eyeNeutral:.12,browInner:.14,browOuter:.5,browY:[.23,.57],browTiltRight:[-45,45],browTiltLeft:[45,-45],mouthY:-.34,mouthX:.36,mouthCurve:[.67,-.67],mouthAsym:[-20,20]};function RA(e={}){const t=at(e,{mark:"face",allow:st.face}),{id:n,edits:r,table:o,ink:i=vt.ink}=t,s={...t.channels};FA.some(x=>s[x])||(s.mouthCurve={field:"valence"},s.eyeScale={field:"arousal"});const a=(x,S,v=.5)=>{const k=s[x];if(k&&k.field!=null)return k.scale!==void 0||k.frame!==void 0?k:{...k,frame:S};const _=k&&k.value!==void 0?LA(+k.value):v;return{frame:S[0]+_*(S[1]-S[0])}},l=x=>({frame:x}),u=x=>({frame:x}),c=a("eyeScale",vt.eyeRx,(vt.eyeNeutral-vt.eyeRx[0])/(vt.eyeRx[1]-vt.eyeRx[0])),d=x=>{if(!x)return x;const{edit:S,...v}=x;return v},f=s.eyeSquint?a("eyeSquint",vt.eyeRy):d(c),p=a("browHeight",vt.browY),h=u(vt.lineWidth),y=n||"face",g=x=>`${y}/${x}`,m=x=>x<0?"left":"right",b=(x,S)=>lb({id:g(`brow-${m(x)}`),channels:{x1:l(x*vt.browInner),x2:l(x*vt.browOuter),y:p,angle:a("browTilt",S),stroke:{value:i},strokeWidth:h}}),w=x=>ub({id:g(`eye-${m(x)}`),channels:{x:l(x*vt.eyeX),y:l(vt.eyeY),rx:c,ry:f,fill:{value:i},stroke:{value:"none"}}});return ii({id:y,edits:r,table:o,channels:{x:s.x,y:s.y,size:s.size,...s.ports?{ports:s.ports}:{}},parts:[Sr({id:g("head"),channels:{size:u(1),fill:s.fill||{value:vt.headFill},stroke:s.stroke||{value:vt.headStroke},strokeWidth:s.strokeWidth||u(vt.headStrokeWidth)}}),w(-1),w(1),b(-1,vt.browTiltLeft),b(1,vt.browTiltRight),pb({id:g("mouth"),channels:{x1:l(-.36),x2:l(vt.mouthX),y:l(vt.mouthY),curvature:a("mouthCurve",vt.mouthCurve),angle:a("mouthAsym",vt.mouthAsym),stroke:{value:i},strokeWidth:h}})]})}const PA=["text","fontSize","textAnchor","lineAnchor","dx"],zA=["x","y"];function DA(e={}){const t=at(e,{mark:"node",except:["dy"],allow:st.node}),{channels:n={},dy:r=-16,shape:o,format:i}=t,s=lt(t),a=s.id||"node",l={},u={},c={};for(const[f,p]of Object.entries(n))zA.includes(f)?l[f]=p:PA.includes(f)?c[f]=p:u[f]=p;const d=[];return n.text&&d.push(Or({id:`${a}/label`,dy:r,...i!==void 0?{format:i}:{},channels:{textAnchor:{value:"middle"},...c}})),d.push(Sr({id:`${a}/dot`,...o!==void 0?{shape:o}:{},channels:u})),ii({...s,channels:l,parts:d})}const jA=["text","fontSize","textAnchor","lineAnchor","dx","dy"],WA=["x","y"],qA=["width","height"],Yc=e=>{if(!e)return e;const{edit:t,...n}=e;return n};function BA(e={}){const t=at(e,{mark:"sticker",except:["padding","radius","maxWidth","minWidth","lineHeight"],allow:st.sticker}),{channels:n={},padding:r=10,radius:o=6,maxWidth:i=160,minWidth:s=60,minHeight:a=0,lineHeight:l,fontFamily:u,format:c}=t,d=lt(t),f=d.id||"sticker",p={},h={},y={};for(const[_,T]of Object.entries(n))WA.includes(_)?p[_]=T:jA.includes(_)?y[_]=T:h[_]=T;const g=y.fontSize&&(y.fontSize.value??y.fontSize)||13,m=n.text&&n.text.field,b=n.text&&n.text.fn,w=n.text&&n.text.value,x=(_,T,L)=>{const N=n.width?+pt(n,"width",_,NaN,T,L):NaN;return Number.isFinite(N)?N:i},S=(_,T,L)=>{const N=m!=null?_[m]:typeof b=="function"?b(_,T,L):w;return $n(N,{padding:r,maxWidth:x(_,T,L),minWidth:s,minHeight:a,fontSize:+g||13,fontFamily:u,lineHeight:l})},v={...h,...p,rx:{value:o}};n.text&&(v.text=Yc(n.text));for(const _ of qA){if(v[_])continue;const T=_==="width"?L=>L.width:L=>L.height;v[_]={fn:(L,N,I)=>T(S(L,N,I))}}const k=[Is({id:`${f}/body`,...d.edits?{edits:d.edits}:{},...d.table?{table:d.table}:{},channels:v}),Or({id:`${f}/label`,wrap:(_,T,L)=>x(_,T,L)-r*2,...l!==void 0?{lineHeight:l}:{},...c!==void 0?{format:c}:{},channels:{textAnchor:{value:"middle"},lineAnchor:{value:"middle"},fontSize:{value:g},...y,...p.x?{x:Yc(p.x)}:{},...p.y?{y:Yc(p.y)}:{}}})];return ii({id:d.id,table:d.table,channels:{},parts:k})}const HA=6;function fr(e,t){const n=Math.hypot(e,t)||1;return{x:e/n,y:t/n}}function UA(e){return fr(e.x2-e.x1,e.y2-e.y1)}function KA(e){const t=UA(e);return{points:[[e.x1,e.y1],[e.x2,e.y2]],curve:"linear",start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2},tangentIn:t,tangentOut:t}}function Gc(e){return(t,n)=>{const r=t.x2-t.x1,o=t.y2-t.y1,i=Math.sign(r)||1,s=Math.sign(o)||1,a={x:i,y:0},l={x:0,y:s};let u,c,d;if(e==="stepAfter")u=[[t.x1,t.y1],[t.x2,t.y1],[t.x2,t.y2]],c=a,d=l;else if(e==="stepBefore")u=[[t.x1,t.y1],[t.x1,t.y2],[t.x2,t.y2]],c=l,d=a;else{const f=Math.min(.85,Math.max(.15,.5+n)),p=t.x1+r*f;u=[[t.x1,t.y1],[p,t.y1],[p,t.y2],[t.x2,t.y2]],c=a,d=a}return{points:u,curve:"linear",start:{x:t.x1,y:t.y1},end:{x:t.x2,y:t.y2},mid:{x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2},tangentIn:c,tangentOut:d}}}function YA(e,t){const n=(e.x1+e.x2)/2,r=(e.y1+e.y2)/2,o=e.x2-e.x1,i=e.y2-e.y1,s=n-i*t,a=r+o*t;return{d:`M${e.x1},${e.y1}Q${s},${a} ${e.x2},${e.y2}`,hit:rc([e.x1,e.y1],[s,a],[e.x2,e.y2]),start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:.25*e.x1+.5*s+.25*e.x2,y:.25*e.y1+.5*a+.25*e.y2},tangentIn:fr(s-e.x1,a-e.y1),tangentOut:fr(e.x2-s,e.y2-a)}}function ey(e,t,n={}){const r=e.x2-e.x1,o=e.y2-e.y1,i=Math.abs(r)>=Math.abs(o),s=Math.abs(i?r:o)*(.5+Math.abs(t)),a=n.sourceNormal,l=n.targetNormal,u=Math.hypot(r,o),c=(w,x)=>x<0?Math.min(s,Math.max(20,u*.2)):s,d=a?c(a,a.x*r+a.y*o):s,f=l?c(l,-(l.x*r+l.y*o)):s,p=a?[e.x1+a.x*d,e.y1+a.y*d]:i?[e.x1+Math.sign(r||1)*s,e.y1]:[e.x1,e.y1+Math.sign(o||1)*s],h=l?[e.x2+l.x*f,e.y2+l.y*f]:i?[e.x2-Math.sign(r||1)*s,e.y2]:[e.x2,e.y2-Math.sign(o||1)*s],y=[e.x1,e.y1],g=[e.x2,e.y2],m=p,b=h;return{d:`M${e.x1},${e.y1}C${p[0]},${p[1]} ${h[0]},${h[1]} ${e.x2},${e.y2}`,hit:dl(y,m,b,g),start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},mid:{x:.125*e.x1+.375*p[0]+.375*h[0]+.125*e.x2,y:.125*e.y1+.375*p[1]+.375*h[1]+.125*e.y2},tangentIn:fr(p[0]-e.x1,p[1]-e.y1),tangentOut:fr(e.x2-h[0],e.y2-h[1])}}const ty=12;function GA(e,t,n,r={}){const o=r.source,i=n*(1+.6*(r.nest||0));if(!o||!r.loopOut){const M=e.x1,$=e.y1,F=t<0?-1:1,D=i*.9,z=i*1.8*F,j=[M-D,$-z],G=[M+D,$-z],J=[M,$];return{d:`M${M},${$}C${j[0]},${j[1]} ${G[0]},${G[1]} ${M},${$}`,hit:dl(J,j,G,J),start:{x:M,y:$},end:{x:M,y:$},mid:{x:M,y:$-z*.75},tangentIn:fr(j[0]-M,j[1]-$),tangentOut:fr(M-G[0],$-G[1])}}const s=r.loopOut,a=r.loopIn||s,l=r.sourceGap||0,u=r.targetGap||0,c=tn[s],d=tn[a];if(s===a){const M=c,$={x:-M.y,y:M.x},F=M.x?o.hh:o.hw,D=Math.min(i*.35,F*.8),z=o.cx+M.x*o.hw,j=o.cy+M.y*o.hh,G=[z-$.x*D+M.x*l,j-$.y*D+M.y*l],J=[z+$.x*D+M.x*u,j+$.y*D+M.y*u],re=[z+M.x*i*1.8-$.x*i*.9,j+M.y*i*1.8-$.y*i*.9],Q=[z+M.x*i*1.8+$.x*i*.9,j+M.y*i*1.8+$.y*i*.9];return{d:`M${G[0]},${G[1]}C${re[0]},${re[1]} ${Q[0]},${Q[1]} ${J[0]},${J[1]}`,hit:dl(G,re,Q,J),start:{x:G[0],y:G[1]},end:{x:J[0],y:J[1]},mid:{x:z+M.x*(i*1.35+ty),y:j+M.y*(i*1.35+ty)},tangentIn:fr(re[0]-G[0],re[1]-G[1]),tangentOut:fr(J[0]-Q[0],J[1]-Q[1])}}const f=At.indexOf(s),p=At.indexOf(a),h=(p-f+4)%4,y=M=>{const $=[];for(let F=f;F!==p;F=(F+M+4)%4)$.push(At[(F+M+4)%4]);return $};let g=h<2?1:h>2?-1:0;if(!g){const M=y(1);g=M.includes("top")||!y(-1).includes("top")&&M.includes("right")?1:-1}const m=o.cx-o.hw-i,b=o.cx+o.hw+i,w=o.cy-o.hh-i,x=o.cy+o.hh+i,S={top:[b,w],right:[b,x],bottom:[m,x],left:[m,w]},v=o.cx+c.x*o.hw,k=o.cy+c.y*o.hh,_=o.cx+d.x*o.hw,T=o.cy+d.y*o.hh,L=[[v+c.x*l,k+c.y*l],[v+c.x*i,k+c.y*i]];for(let M=f;M!==p;M=(M+g+4)%4){const $=g>0?At[M]:At[(M+3)%4];L.push(S[$])}L.push([_+d.x*i,T+d.y*i],[_+d.x*u,T+d.y*u]);const N=Mb(L,Number(r.cornerRadius)||i*.4),I=L[0],O=L[L.length-1];return{points:N,curve:"linear",start:{x:I[0],y:I[1]},end:{x:O[0],y:O[1]},mid:Eb(N),tangentIn:c,tangentOut:{x:-d.x||0,y:-d.y||0}}}function Mb(e,t){if(!(t>0)||e.length<3)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const o=e[r-1],i=e[r],s=e[r+1],a=Math.hypot(i[0]-o[0],i[1]-o[1]),l=Math.hypot(s[0]-i[0],s[1]-i[1]),u=Math.min(t,a/2),c=Math.min(t,l/2);if(!a||!l){n.push(i);continue}const d=[i[0]+(o[0]-i[0])/a*u,i[1]+(o[1]-i[1])/a*u],f=[i[0]+(s[0]-i[0])/l*c,i[1]+(s[1]-i[1])/l*c];for(const p of rc(d,i,f,HA))n.push(p)}return n.push(e[e.length-1]),n}function Eb(e){const t=[];let n=0;for(let o=1;o<e.length;o++){const i=Math.hypot(e[o][0]-e[o-1][0],e[o][1]-e[o-1][1]);t.push(i),n+=i}let r=n/2;for(let o=0;o<t.length;o++){if(r<=t[o]||o===t.length-1){const i=t[o]?r/t[o]:0;return{x:e[o][0]+(e[o+1][0]-e[o][0])*i,y:e[o][1]+(e[o+1][1]-e[o][1])*i}}r-=t[o]}return{x:e[0][0],y:e[0][1]}}function ny(e,t){const n=r=>r&&r!=="auto"?String(r):null;return e?{side:n(e.side),offset:+e.offset||0}:{side:n(t),offset:0}}function VA(e,t,n){const r=n.source||{cx:e.x1,cy:e.y1,hw:0,hh:0},o=n.target||{cx:e.x2,cy:e.y2,hw:0,hh:0},i=ny(n.sourcePort,n.sourceSide),s=ny(n.targetPort,n.targetSide),a=U5({source:{box:r,port:{side:i.side,offset:i.offset+t}},target:{box:o,port:{side:s.side,offset:s.offset-t}},sourceGap:n.sourceGap||0,targetGap:n.targetGap||0,obstacles:n.obstacles,grid:n.grid});if(!a)return null;const l=Mb(a.points,Number(n.cornerRadius)||0),u=a.points[0],c=a.points[a.points.length-1],d=tn[a.sourceSide],f=tn[a.targetSide];return{points:l,curve:"linear",start:{x:u[0],y:u[1]},end:{x:c[0],y:c[1]},mid:Eb(l),tangentIn:d,tangentOut:{x:-f.x||0,y:-f.y||0}}}const yl={line:{anchors:"chord",build:e=>KA(e)},step:{anchors:"chord",build:Gc("step")},stepBefore:{anchors:"chord",build:Gc("stepBefore")},stepAfter:{anchors:"chord",build:Gc("stepAfter")},orthogonal:{anchors:"box",build:VA},arc:{anchors:"chord",build:(e,t)=>YA(e,t)},bezier:{anchors:"chord",build:(e,t,n)=>ey(e,t,n)},smooth:{anchors:"chord",build:(e,t,n)=>ey(e,t,n)},loop:{anchors:"chord",build:(e,t,n)=>GA(e,t,n.loopRadius||0,n)}},XA=Object.keys(yl).filter(e=>e!=="loop");function Ab(e,t){const n=r=>!!(t&&t.fields[r]);return{x:e.x||(n("x")?{field:"x"}:void 0),y:e.y||(n("y")?{field:"y"}:void 0)}}function Tb(e,t,n,r,o,i,s,a,l){const u=Ab(t,n);return r.map((c,d)=>{if(!c)return null;if(o){const f=o(c,d,r);if(f&&[f.cx,f.cy,f.hw,f.hh].every(Number.isFinite))return f}return{cx:se(e,u,"x",c,a/2,d,r),cy:se(e,u,"y",c,l/2,d,r),hw:i/2,hh:s/2}})}const JA=.16,ZA=.9,QA=22,ry=12,e4=8,oy=140,iy=10,t4=["stroke","strokeWidth","strokeOpacity"],n4="#ffffff",r4=3,o4=3,i4=.9;function s4(e){return e?Object.keys(e.fields).filter(t=>e.fields[t]&&e.fields[t].type==="ref"):[]}function a4(e,t,n,r){if(!n||!n.schema)return null;const o=n.schema,i=o.tables[r],s=o.byRole.nodes||o.primary,a=o.tables[s];if(!i||!a)return null;const l=s4(i),u=e.source&&e.source.field||l[0],c=e.target&&e.target.field||l[1],d=a.key;return{rows:n.tables&&n.tables[s]||[],nodesName:s,sourceField:u,targetField:c,keyField:d}}function l4(e,t,n,r,o,i){const s=n-e,a=r-t,l=Math.hypot(s,a);if(!l||o+i>=l)return null;const u=s/l,c=a/l;return{x1:e+u*o,y1:t+c*o,x2:n-u*i,y2:r-c*i}}function sy(e,t){if(e==null||e==="auto")return null;const n=String(e);return At.includes(n)?n:(ge(`link:side:${n}`,`link() got ${t}: ${JSON.stringify(e)}, which is not an edge. Use ${At.map(r=>`"${r}"`).join(", ")}, or null to let the end slide along the box toward the other node. Sliding.`),null)}function ay(e,t){if(e==null)return 0;const n=+e;return Number.isFinite(n)?Math.max(-Oi,Math.min(Oi,n)):(ge(`link:offset:${t}`,`link() got ${t}: ${JSON.stringify(e)}, which is not a number. It is a fraction of the edge from its midpoint, between ${-Oi} and ${Oi}. Using the midpoint.`),0)}function c4(e,t){let n=e;switch(n==null||n==="auto"?n=t===!0?"target":"none":n===!0?n="target":n===!1&&(n="none"),n){case"none":return{source:!1,target:!1};case"target":return{source:!1,target:!0};case"source":return{source:!0,target:!1};case"both":return{source:!0,target:!0};default:return ge(`link:arrow:${n}`,`link() got arrow: ${JSON.stringify(n)}, which it doesn't know. Use "none", "target", "source", "both", or "auto" (the target end when the links table declares directed: true). Drawing no arrowhead.`),{source:!1,target:!1}}}function ly(e,t,n,r){const o=r*.5;return`M${e+n.x*r},${t+n.y*r}L${e-n.y*o},${t+n.x*o}L${e+n.y*o},${t-n.x*o}Z`}function u4(e,t,n,r,o){const i=new Map,s=new Map,a=u=>{const c=String(u[t]),d=String(u[n]);return c<d?`${c}\0${d}`:`${d}\0${c}`};e.forEach((u,c)=>{if(!u)return;const d=a(u),f=i.get(d);f?f.push(c):i.set(d,[c])});const l=new Array(e.length).fill(0);for(const u of i.values())u.length<2||u.forEach((c,d)=>{const f=e[c];if(r){const p=`${f[t]}\0${f[n]}`,h=s.get(p)||0;s.set(p,h+1),l[c]=o*(h+1)}else l[c]=o*((2*d-(u.length-1))/2)});return l}function f4(e,t,n){const r=new Map;return e.map(o=>{if(!o||o[t]==null||o[t]!==o[n])return-1;const i=String(o[t]),s=r.get(i)||0;return r.set(i,s+1),s})}function d4(e={}){const t=at(e,{mark:"link",allow:st.link}),{channels:n={},id:r,edits:o,table:i,curve:s="line",curvature:a="auto",spread:l=JA,arrow:u="auto",arrowSize:c=6,loopRadius:d=QA,inset:f=0,sourceInset:p,targetInset:h,format:y,cornerRadius:g=e4,sourceSide:m="auto",targetSide:b="auto",sourceOffset:w=0,targetOffset:x=0,labelBackground:S,labelPadding:v=r4,labelRadius:k=o4,labelOpacity:_=i4}=t,T=$r(y),L=I=>!!(n[I]&&n[I].edit)||Array.isArray(o)&&o.some(O=>O&&Array.isArray(O.channels)&&O.channels.includes(I)),N={source:L("source"),target:L("target")};return{...lt(t),type:"link",channels:n,table:i,tableRole:"links",supportsNetwork:!0,rawChannels:["sourceSide","targetSide","sourceOffset","targetOffset","curve","arrow","fontSize"],discreteScale:void 0,build:(I,O,M,$,F)=>{const D=a4(n,t,F,F?F.table:"");if(!D)return ge("link:structure",'link() needs a network dataset: declare schema: { structure: "network", tables: { nodes: {…}, links: {…} } }. Without a links table there is nothing for it to draw.'),[];if(!D.keyField)return ge("link:key",'link() cannot find the column that identifies a node. Mark one in the node table with `key: true` (e.g. id: { type: "categorical", key: true }), or pass link({ key: "id" }). No links are drawn until it can.'),[];if(!D.sourceField||!D.targetField)return ge("link:refs",`link() cannot find the link table's endpoint columns. Declare them as references — source: { type: "ref" }, target: { type: "ref" } — or name them with channels: { source: { field: … }, target: { field: … } }.`),[];const z=F.schema,j=z.tables[D.nodesName],G=Ab(n,j),J=it(O),re=It(O,"link",{stroke:J.ink,fill:"none"}),Q=fn(O,t),ve=p??f,Ce=h??f,le=F&&F.nodeBox||null,me=F&&F.nodePorts||null,ce=(f||ry)*2,Y=(f||ry)*2,fe=!!le,ie=Ms(z),U=a==="auto"?u4(I,D.sourceField,D.targetField,ie,l):null,we=f4(I,D.sourceField,D.targetField),xe=n.text?{...n}:null;if(xe)for(const Se of t4)delete xe[Se];const P=xe&&S?S===!0?J.background||n4:String(S):null,H=J.font&&J.font.family||void 0,oe=new Map;D.rows.forEach((Se,ae)=>{const $e=Se?Se[D.keyField]:void 0;$e!=null&&!oe.has($e)&&oe.set($e,{row:Se,index:ae})});let he=null,ke=[],pe;const _e=()=>{if(he)return he;const Se=Tb(O,n,j,D.rows,le,ce,Y,M,$);return ke=Se.filter(Boolean),pe=K5(ke),he=Se,Se},Te=[];return I.forEach((Se,ae)=>{const $e=oe.get(Se?Se[D.sourceField]:void 0),Le=oe.get(Se?Se[D.targetField]:void 0),Z=F&&F.ghost&&F.ghost.pointer?F.ghost.pointer:null,St=!$e&&Le&&Z?Z:null,rt=!Le&&$e&&Z?Z:null,ct=St||rt;if(!$e&&!St||!Le&&!rt)return;const $t=le&&$e?_e()[$e.index]:null,xt=le&&Le?_e()[Le.index]:null,Tt=$t?$t.cx:$e?se(O,G,"x",$e.row,M/2,$e.index,D.rows):St.x,Jt=$t?$t.cy:$e?se(O,G,"y",$e.row,$/2,$e.index,D.rows):St.y,qt=xt?xt.cx:Le?se(O,G,"x",Le.row,M/2,Le.index,D.rows):rt.x,Qn=xt?xt.cy:Le?se(O,G,"y",Le.row,$/2,Le.index,D.rows):rt.y,C=!!Le&&!!$e&&$e.index===Le.index,W=c4(pt(n,"arrow",Se,u,ae,I),ie);let q=U?U[ae]:+a||0,V=C?"loop":String(pt(n,"curve",Se,s,ae,I));yl[V]||(ge(`link:curve:${V}`,`link() got curve: "${V}", which it doesn't know. Use one of ${XA.map(Ue=>`"${Ue}"`).join(", ")}. Drawing a straight line.`),V="line"),V==="line"&&q&&(V="arc");const ee=yl[V];let ue;const be={loopRadius:d,cornerRadius:+g||0},Oe={side:sy(pt(n,"sourceSide",Se,m,ae,I),"sourceSide"),offset:ay(pt(n,"sourceOffset",Se,w,ae,I),"sourceOffset")},Ze={side:sy(pt(n,"targetSide",Se,b,ae,I),"targetSide"),offset:ay(pt(n,"targetOffset",Se,x,ae,I),"targetOffset")},rn=(Ue,Ot,Zt)=>_e()[Ue]||{cx:Ot,cy:Zt,hw:ce/2,hh:Y/2},bt=$e?rn($e.index,Tt,Jt):{cx:Tt,cy:Jt,hw:0,hh:0},ut=Le?rn(Le.index,qt,Qn):{cx:qt,cy:Qn,hw:0,hh:0},zn=(Ue,Ot)=>{if(!me||!Ue)return null;const Zt=me(Ue.row,Ue.index,D.rows)||{},Pt=At.filter(sn=>j0(Zt[sn],Ot));return Pt.length?Pt:null},An=zn($e,"source"),Bt=zn(Le,"target");if(C){const Ue=z5(An,Bt,Oe.side,Ze.side,Math.max(0,we[ae]));be.loopOut=Ue.out,be.loopIn=Ue.in,be.nest=Ue.nest}else An&&!Oe.side&&(Oe.side=Op(bt,An,{x:ut.cx,y:ut.cy}));!C&&Bt&&!Ze.side&&(Ze.side=Op(ut,Bt,{x:bt.cx,y:bt.cy}));const Ht=(An?0:ve)+(W.source?c:0),Lt=(Bt?0:Ce)+(W.target?c:0);if(ee.anchors==="box")ue={x1:Tt,y1:Jt,x2:qt,y2:Qn},be.source=bt,be.target=ut,be.sourceGap=Ht,be.targetGap=Lt,be.obstacles=ke,be.grid=pe,be.sourcePort=Oe,be.targetPort=Ze;else if(C)ue={x1:Tt,y1:Jt,x2:Tt,y2:Jt},fe?(be.source=bt,be.sourceGap=Ht,be.targetGap=Lt):(delete be.loopOut,be.nest=Math.floor(Math.max(0,we[ae])/2));else if(fe||Oe.side||Ze.side){const Ue=z0(bt,Oe,Ht,ut,Ze,Lt),Ot=(sn,tr,yo)=>{const go=yo.x-sn.cx,zs=yo.y-sn.cy,yc=sn.hw+tr,Ds=sn.hh+tr,js=1/(Math.hypot(go/(yc||1e-6),zs/(Ds||1e-6))||1);return{x:sn.cx+go*js,y:sn.cy+zs*js}},Zt=!Oe.side&&bt.round?Ot(bt,Ht,Ze.side?Ue.b:{x:ut.cx,y:ut.cy}):Ue.a,Pt=!Ze.side&&ut.round?Ot(ut,Lt,Oe.side?Ue.a:{x:bt.cx,y:bt.cy}):Ue.b;ue=Math.hypot(Pt.x-Zt.x,Pt.y-Zt.y)<1?null:{x1:Zt.x,y1:Zt.y,x2:Pt.x,y2:Pt.y},Oe.side&&(be.sourceNormal=tn[Oe.side]),Ze.side&&(be.targetNormal=tn[Ze.side])}else ue=l4(Tt,Jt,qt,Qn,Ht,Lt);if(!ue)return;if(U&&q&&xe&&ee.anchors==="chord"&&!C){const Ue=Math.hypot(ue.x2-ue.x1,ue.y2-ue.y1),Ot=l*Ue/2,Pt=(+pt(n,"fontSize",Se,12,ae,I)||12)+v*2+2;Ot>0&&Ot<Pt&&(q=Math.sign(q)*Math.min(Math.abs(q)*(Pt/Ot),ZA))}const tt=yt(O,n,Se,re,ae,I),Xe=ee.build(ue,q,be);if(!Xe)return;const Dr=+pt(n,"fontSize",Se,12,ae,I)||12,jr={x:Xe.mid.x-oy/2,y:Xe.mid.y-(Dr+iy)/2,width:oy,height:Dr+iy},er=Xe.hit||Xe.points;er&&Te.push({type:"path",points:er,curve:Xe.hit?"linear":Xe.curve,stroke:"transparent",strokeWidth:Math.max(hb,+tt.strokeWidth||0),strokeLinecap:"round",fill:"none",hit:!0,editBox:jr,data:Se,index:ae}),Te.push({type:"path",...Xe.d?{d:Xe.d}:{points:Xe.points,curve:Xe.curve},...tt,fill:"none",...ct?{strokeDasharray:"4 3"}:{},editBox:jr,data:Se,index:ae});const on=tt.stroke||re.stroke;if(W.target&&Te.push({type:"path",d:ly(Xe.end.x,Xe.end.y,Xe.tangentOut,c),fill:on,stroke:"none",data:Se,index:ae}),W.source&&Te.push({type:"path",d:ly(Xe.start.x,Xe.start.y,{x:-Xe.tangentIn.x,y:-Xe.tangentIn.y},c),fill:on,stroke:"none",data:Se,index:ae}),xe){const Ue=Object.assign(gd(O,xe,Se,ae,Xe.mid.x,Xe.mid.y,{format:T,data:I}),{editBox:jr});if(P&&Ue.text!==""&&Ue.text!=null){const Ot=oc(String(Ue.text),{fontSize:+(Ue.fontSize||0)||12,fontFamily:H}),Zt=Ot.width+v*2,Pt=Ot.height+v*2,sn=Ue.x||0,tr=Ue.y||0;Te.push({type:"rect",x:Ue.textAnchor==="start"?sn:Ue.textAnchor==="end"?sn-Zt:sn-Zt/2,y:Ue.lineAnchor==="top"?tr:Ue.lineAnchor==="bottom"?tr-Pt:tr-Pt/2,width:Zt,height:Pt,rx:k,fill:P,fillOpacity:_,stroke:"none",...Ue.angle?{angle:Ue.angle}:{},editBox:jr,data:Se,index:ae})}Te.push(Ue)}for(const[Ue,Ot]of[["source",Xe.start],["target",Xe.end]])!N[Ue]||!Q.grabbable||Te.push({type:"circle",cx:Ot.x,cy:Ot.y,r:Q.size,fill:Q.fill,stroke:Q.stroke,strokeWidth:Q.strokeWidth,channel:Ue,onHover:!0,raise:!0,data:Se,index:ae})}),Te}}}function Ob(e){if(!e||!e.raw||typeof e.raw.scale!="function")return!1;const t=2*Math.PI*e.raw.scale();if(!Number.isFinite(t)||t<=0)return!1;const n=e.apply([0,0]);if(!n)return!1;const r=n[0]-t/2,o=n[1]-t/2,i=l=>{const u=l*Math.PI/180;return o+t*(.5-Math.log(Math.tan(Math.PI/4+u/2))/(2*Math.PI))},s=l=>r+t*(l+180)/360,a=Math.max(.5,t*1e-6);for(const[l,u]of[[90,0],[-60,45],[30,-30],[0,60]]){const c=e.apply([l,u]);if(!c||Math.abs(c[0]-s(l))>a||Math.abs(c[1]-i(u))>a)return!1}return!0}function Cb(e,t,n,r={}){const{tileSize:o=256,minZoom:i=0,maxZoom:s=19,zoomOffset:a=0}=r;if(!Ob(e)||!(t>0)||!(n>0))return null;const l=e,u=2*Math.PI*l.raw.scale();if(!Number.isFinite(u)||u<=0)return null;const c=Math.round(Math.log2(u/o))+a,d=Math.max(i,Math.min(s,c)),f=2**d,p=u/f,h=l.apply([0,0]);if(!h)return null;const y=h[0]-u/2,g=h[1]-u/2,m=Math.floor((0-y)/p),b=Math.ceil((t-y)/p),w=Math.floor((0-g)/p),x=Math.ceil((n-g)/p),S=[];for(let v=Math.max(0,w);v<Math.min(f,x);v++)for(let k=m;k<b;k++){const _=(k%f+f)%f;S.push({z:d,x:_,y:v,px:y+k*p,py:g+v*p,size:p,key:`${d}/${_}/${v}`})}return{z:d,size:p,tiles:S}}function Nb(e,t,n=["a","b","c"]){if(typeof e=="function")return e(t);const r=n.length?n[Math.abs(t.x+t.y)%n.length]:"";return e.replace("{s}",r).replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y))}const h4=Symbol("single");function p4(){ge("geoTile:mercator",'geoTile needs projection: "mercator" (unrotated). Tiles are images baked in Web Mercator — under another projection they cannot align with the data, so none are drawn. Use geoBasemap({ geojson }) for vector chrome under other projections.')}function Nr(e){return e&&e.projection||null}function pn(e,t){const n=e[t];return n&&n.field!=null?n.field:null}function y4(e={}){const t=at(e,{mark:"geoBasemap",allow:st.geoBasemap,except:["stroke","strokeWidth","fill"]}),{channels:n={},id:r,edits:o,geojson:i,stroke:s="#94a3b8",strokeWidth:a=.75,fill:l="#e2e8f0"}=t,u=i||null;return{...lt(t),type:"geoBasemap",channels:n,supportsGeo:!0,build:(c,d,f,p)=>{const h=Nr(d);if(!h||!u)return[];const y=yt(d,n,{},{fill:l,stroke:s,strokeWidth:a}),g=y.fill!=null?y.fill:l,m=y.stroke!=null?y.stroke:s,b=y.strokeWidth!=null?y.strokeWidth:a,w=u.type==="FeatureCollection"&&Array.isArray(u.features)?u.features:[u],x=[];return w.forEach((S,v)=>{const k=S&&S.type==="Feature"?S.geometry:S;if(!k)return;const _=h.path(k);_&&x.push({type:"path",d:_,fill:g,stroke:m,strokeWidth:b,opacity:y.opacity,fillOpacity:y.fillOpacity,strokeOpacity:y.strokeOpacity,background:!0,pointerEvents:"none",index:v})}),x}}}function g4(e={}){const t=at(e,{mark:"geoTile",allow:st.geoTile,except:["opacity"]}),{channels:n={},id:r,edits:o,url:i="https://tile.openstreetmap.org/{z}/{x}/{y}.png",subdomains:s=[],tileSize:a=256,minZoom:l=0,maxZoom:u=19,zoomOffset:c=0,opacity:d,attribution:f="© OpenStreetMap contributors",attributionSize:p=9}=t;return{...lt(t),type:"geoTile",channels:n,supportsGeo:!0,build:(h,y,g,m)=>{const b=Nr(y);if(!b)return[];const w=Cb(b,g,m,{tileSize:a,minZoom:l,maxZoom:u,zoomOffset:c});if(!w)return p4(),[];const x=w.tiles.map(S=>({type:"image",x:S.px,y:S.py,width:S.size+.5,height:S.size+.5,href:Nb(i,S,s),opacity:d,background:!0,pointerEvents:"none",key:S.key}));return f&&x.push({type:"text",x:g-4,y:m-4,text:f,fontSize:p,textAnchor:"end",lineAnchor:"bottom",dominantBaseline:"text-after-edge",fill:"#334155",pointerEvents:"none"}),x}}}function m4(e={}){const t=at(e,{mark:"geoPoint",allow:st.geoPoint}),{channels:n={},id:r,edits:o}=t,i=pn(n,"lon")||"lon",s=pn(n,"lat")||"lat";return{...lt(t),type:"geoPoint",channels:n,supportsGeo:!0,lonKey:i,latKey:s,xKey:i,yKey:s,build:(a,l,u,c)=>{const d=Nr(l),f=[],p=It(l,"geoPoint",{fill:it(l).ink});return a.forEach((h,y)=>{const g=n.lon?h[i]:h.lon,m=n.lat?h[s]:h.lat,b=ur(d,g,m);if(!b)return;const w=yt(l,n,h,p,y,a);f.push({type:"circle",cx:b.x,cy:b.y,r:se(l,n,"size",h,5,y,a),...w,data:h,index:y})}),f}}}function b4(e={}){const t=at(e,{mark:"geoPolygon",allow:st.geoPolygon}),{channels:n={},id:r,edits:o}=t,i=pn(n,"geometry")||"geometry";return{...lt(t),type:"geoPolygon",channels:n,supportsGeo:!0,geometryKey:i,build:(s,a)=>{const l=Nr(a);if(!l)return[];const u=[];return s.forEach((c,d)=>{const f=c[i];if(!f)return;const p=l.path(f);if(!p)return;const h=yt(a,n,c,{fill:"#93c5fd",stroke:"#1e3a8a",strokeWidth:.75});u.push({type:"path",d:p,...h,data:c,index:d})}),u}}}function w4(e,t){const n=Qf(t);return n?e.slice().sort((r,o)=>{const i=r.d[n],s=o.d[n];return i==null||s==null?0:i<s?-1:i>s?1:0}):e}function x4(e={}){const t=at(e,{mark:"geoLine",allow:st.geoLine}),{channels:n={},id:r,edits:o,curve:i="linear",handles:s=!0,handleSize:a,handleColor:l}=t,u=pn(n,"coordinates")||"coordinates",c=pn(n,"geometry")||null,d=!!(n.lon&&n.lat),f=pn(n,"lon")||"lon",p=pn(n,"lat")||"lat",h=Os(n),y=t.connect||"sequence",g=t.showVertices!=null?t.showVertices:!d;return d?{...lt(t),type:"geoLine",channels:n,rawChannels:["curve","series","order"],supportsGeo:!0,lonKey:f,latKey:p,xKey:f,yKey:p,seriesKey:h,connect:y,supportsSeries:!0,build:(m,b)=>{const w=Nr(b);if(!w)return[];const x=[];m.forEach((_,T)=>{const L=ur(w,_[f],_[p]);L&&x.push({d:_,i:T,x:L.x,y:L.y,series:h?_[h]:h4})});const S=new Map;for(const _ of x){const T=S.get(_.series);T?T.push(_):S.set(_.series,[_])}const v=[],k=fn(b,{handles:s,handleSize:a,handleColor:l});for(const _ of S.values()){if(_.length<2)continue;const T=w4(_,n),L=yt(b,n,_[0].d,{stroke:"#1d4ed8",strokeWidth:2}),N=String(pt(n,"curve",_[0].d,i,_[0].i,m));v.push({type:"path",points:T.map(I=>[I.x,I.y]),curve:N,...L,fill:"none"})}return g&&x.forEach(_=>{v.push({type:"circle",cx:_.x,cy:_.y,r:k.size,fill:k.visible?k.fill:"transparent",stroke:"#fff",strokeWidth:1,data:_.d,index:_.i})}),v}}:{...lt(t),type:"geoLine",channels:n,supportsGeo:!0,coordinatesKey:u,geometryKey:c,supportsSeries:!1,build:(m,b)=>{const w=Nr(b);if(!w)return[];const x=[],S=fn(b,{handles:s,handleSize:a,handleColor:l});return m.forEach((v,k)=>{let _=null;if(c&&v[c]&&v[c].coordinates){const I=v[c];_=I.type==="LineString"?I.coordinates:I.type==="MultiLineString"?I.coordinates.flat():null}if(!_&&Array.isArray(v[u])&&(_=v[u]),!_||!_.length)return;const T={type:"LineString",coordinates:_},L=w.path(T),N=yt(b,n,v,{fill:"none",stroke:"#1d4ed8",strokeWidth:2});L&&x.push({type:"path",d:L,...N,fill:"none",data:v,index:k,pointerEvents:"stroke"}),g&&_.forEach((I,O)=>{const M=ur(w,I[0],I[1]);M&&x.push({type:"circle",cx:M.x,cy:M.y,r:S.size,fill:S.visible?l||N.stroke||S.fill:"transparent",stroke:"#fff",strokeWidth:1,data:v,index:k,channel:"vertex",vertexIndex:O})})}),x}}}function v4(e={}){const t=at(e,{mark:"geoText",allow:st.geoText}),{channels:n={},id:r,edits:o,format:i}=t,s=pn(n,"lon")||"lon",a=pn(n,"lat")||"lat",l=$r(i);return{...lt(t),type:"geoText",channels:n,supportsGeo:!0,lonKey:s,latKey:a,xKey:s,yKey:a,build:(u,c)=>{const d=Nr(c),f=[];return u.forEach((p,h)=>{const y=ur(d,p[s],p[a]);y&&f.push(gd(c,n,p,h,y.x,y.y,{format:l,data:u}))}),f}}}function k4(e={}){const t=at(e,{mark:"geoRect",allow:st.geoRect}),{channels:n={},id:r,edits:o}=t,i=pn(n,"west")||"west",s=pn(n,"south")||"south",a=pn(n,"east")||"east",l=pn(n,"north")||"north";return{...lt(t),type:"geoRect",channels:n,supportsGeo:!0,westKey:i,southKey:s,eastKey:a,northKey:l,xKey:i,yKey:s,build:(u,c)=>{const d=Nr(c),f=[];return u.forEach((p,h)=>{const y=p[i],g=p[s],m=p[a],b=p[l];if(y==null||g==null||m==null||b==null)return;const w=Math.min(y,m),x=Math.max(y,m),S=Math.min(g,b),v=Math.max(g,b),k=b0(d,w,S,x,v);if(!k||k.width<=0||k.height<=0)return;const _=yt(c,n,p,{fill:"rgba(37, 99, 235, 0.2)",stroke:"#1d4ed8",strokeWidth:1.5}),T={type:"Polygon",coordinates:[[[w,S],[w,v],[x,v],[x,S],[w,S]]]},L=d&&d.path(T);L&&f.push({type:"path",d:L,..._,data:p,index:h,pointerEvents:"none"}),f.push({type:"rect",x:k.x,y:k.y,width:k.width,height:k.height,fill:"transparent",stroke:"transparent",data:p,index:h})}),f}}}const vd=Object.freeze(Object.defineProperty({__proto__:null,arc:wb,area:hd,areaX:tA,areaY:eA,bar:ld,barX:I6,barY:nc,composite:ii,curve:pd,curveX:rA,curveY:pb,donut:oA,dotStack:fd,dotStackX:K6,dotStackY:fb,ellipse:ub,face:RA,geoBasemap:y4,geoLine:x4,geoPoint:m4,geoPolygon:b4,geoRect:k4,geoText:v4,geoTile:g4,line:dd,lineX:X6,lineY:V6,link:d4,needle:iA,node:DA,path:J6,point:Sr,rect:Is,rectX:F6,rectY:R6,rule:cd,ruleX:j6,ruleY:cb,sticker:BA,text:Or,textX:wA,textY:xA,tick:hs,tickX:z6,tickY:lb,trend:$b,trendBand:_b,waffle:ud,waffleX:H6,waffleY:B6},Symbol.toStringTag,{value:"Module"}));function S4(e,t,n=1){return e>t+n?"start":e<t-n?"end":"middle"}const Ib=As.axisRadial;function $4(e={}){Cs("axisRadial",e,Ib);const{channels:t={},id:n,edits:r,channel:o="theta",radius:i,innerRadius:s=0,bandWidth:a=18,ticks:l=5,tickValues:u,tickFormat:c,tickSize:d=6,labelOffset:f=14,bands:p=!1,title:h,arc:y,orient:g,start:m,end:b,labelFill:w,stroke:x,strokeWidth:S=1.25,fontSize:v}=e,[k,_]=yd({arc:y,orient:g,start:m,end:b}),T=t.x&&t.x.field,L=t.y&&t.y.field;return{id:n,type:"axisRadial",channel:o,channels:t,edits:r,isAxis:!0,views:"scale",layer:"background",build:(N,I,O,M)=>{const $=I[o];if(!$)return[];const F=it(I),D=w??F.axis.labelFill,z=x??F.axis.stroke,j=v??F.axis.fontSize,G=typeof $.range=="function"?$.range():null;let J=k,re=_;G&&G.length>=2&&typeof G[0]=="number"&&(J=G[0],re=G[G.length-1]);const Q={background:!0,pointerEvents:"none"},{values:ve,format:Ce}=Ql($,{ticks:l,tickValues:u,tickFormat:c}),le=t.fill&&t.fill.field,me=(ie,U,we)=>{const xe=[];p&&fo($)&&$.domain().forEach((oe,he)=>{const ke=mb($,oe);if(!ke)return;const[pe,_e]=ke,Te=le?{[le]:oe}:{};let Se=se(I,t,"fill",Te,null);Se==null&&(Se=ls[he%ls.length]);const ae=s>0?s:Math.max(0,we-a),$e=ps(ie,U,we,pe,_e,{innerRadius:ae});$e&&xe.push({type:"path",d:$e,fill:Se,stroke:"none",fillOpacity:.9,...Q})});const P=hl(ie,U,we,J,re);return P&&xe.push({type:"path",d:P,fill:"none",stroke:z,strokeWidth:S,...Q}),ve.forEach(H=>{const oe=Mr($,H);if(oe==null||Number.isNaN(oe))return;const he=cn(ie,U,we,oe),ke=cn(ie,U,we-d,oe);d>0&&xe.push({type:"line",x1:he.x,y1:he.y,x2:ke.x,y2:ke.y,stroke:z,strokeWidth:1,...Q});const pe=cn(ie,U,we+f,oe);xe.push({type:"text",x:pe.x,y:pe.y,text:Ce(H),textAnchor:S4(pe.x,ie),dominantBaseline:"middle",fontSize:j,fill:D,...Q})}),h&&xe.push({type:"text",x:ie,y:U+we+f+j+8,text:h,textAnchor:"middle",fontSize:j+1,fill:"#0f172a",...Q}),xe};if(T||L){const ie=[],U=i??Math.min(O,M)*.42;return N.forEach((we,xe)=>{const P=se(I,t,"x",we,O/2,xe,N),H=se(I,t,"y",we,M/2,xe,N);ie.push(...me(P,H,U))}),ie}const ce=se(I,t,"x",N[0],O/2,0,N),Y=se(I,t,"y",N[0],M/2,0,N),fe=i??Math.min(O,M)*.42;return me(ce,Y,fe)}}}const _4=Object.freeze(Object.defineProperty({__proto__:null,axis:ec,axisRadial:$4,axisX:eb,axisY:tb,grid:id,gridX:nb,gridY:rb,legend:Ns,legendColor:s6,legendSize:a6,legendSymbol:l6},Symbol.toStringTag,{value:"Module"})),cy=e=>e.edit&&e.edit.threshold>0?e.edit.threshold:Jl,M4={shift:e=>!!(e.event&&e.event.shiftKey),noShift:e=>!(e.event&&e.event.shiftKey),alt:e=>!!(e.event&&e.event.altKey),noAlt:e=>!(e.event&&e.event.altKey),modifier:e=>t=>!!(t.event&&t.event[e]),noModifier:e=>t=>!(t.event&&t.event[e]),near:e=>Ar(e.marks||[],e.pointer.x,e.pointer.y,cy(e))!=null,far:e=>Ar(e.marks||[],e.pointer.x,e.pointer.y,cy(e))==null,nearWithin:e=>t=>Ar(t.marks||[],t.pointer.x,t.pointer.y,e)!=null},uy={year:Gn,month:Bl,week:_s,day:ri,hour:ql,minute:Wl};function Lb(e,t){if(!e)return[];if(fo(e)||e.kind==="discrete")return[...e.domain()];if(Array.isArray(t))return t;if(typeof t=="number")return fy(e,t);if(t&&typeof t=="object"){if(typeof t.count=="number")return fy(e,t.count);if(t.every&&e.temporal&&uy[t.every]&&typeof e.ticks=="function")return e.ticks(uy[t.every])}if(typeof e.ticks=="function"){const n=e.ticks();if(n&&n.length)return n}return[...e.domain()]}function fy(e,t){const n=e.domain(),r=Number(n[0]),o=Number(n[n.length-1]),i=!!e.temporal;if(t<=1)return[n[0]];const s=[];for(let a=0;a<t;a++){const l=r+(o-r)*a/(t-1);s.push(i?new Date(l):l)}return s}function E4(e={}){const{into:t="nearest",series:n,...r}=e,o=W0(e.threshold);return je({type:"line.anchor",gesture:"click",channels:["x","y"],pick:"plane",scope:"line",into:t,cardinality:"append",...r,apply:i=>{const s=n||i.seriesKey||null;let a=null;t==="nearest"&&(a=Ar(i.marks||[],i.pointer.x,i.pointer.y,o),a==null&&i.connect==="sequence"&&s&&(i.data||[]).length&&(a=i.data[i.data.length-1][s])),a==null&&(a=Yl(i.data,s));const l=Fn(i,{defaults:s?{[s]:a}:{}});if(l)return[...i.data,l]}})}function A4(e={}){const{along:t="x",value:n="y",samples:r,series:o,...i}=e;return je({type:"line.newSeries",gesture:"dblclick",cardinality:"appendMany",channels:[t,n],pick:"plane",scope:"line",...i,apply:s=>{const a=o||s.seriesKey||null,l=s.markChannels[t]&&s.markChannels[t].field||(t==="x"?s.xKey:s.yKey),u=s.markChannels[n]&&s.markChannels[n].field||(n==="x"?s.xKey:s.yKey),c=s.scales[t],d=s.scales[n];if(!c||!l)return;const f=Lb(c,r);if(!f.length)return;const p=n==="x"?s.pointer.x:s.pointer.y,h=d&&d.invertible?d.invertValue(p):d&&d.domain?d.domain()[0]:null,y=Yl(s.data,a),g=f.map(m=>{const b={...Es(s.schema)};return a&&(b[a]=y),b[l]=m,u&&(b[u]=h),b});return[...s.data,...g]}})}function T4(e={}){const{along:t="x",value:n="y",samples:r,minDist:o=8,into:i="nearest",series:s,...a}=e;return je({type:"line.draw",gesture:"drag",cardinality:"appendMany",inverts:!0,channels:[t,n],pick:"draw",scope:"line",into:i,...a,apply:l=>{const u=l.session;if(!u)return;const c=s||l.seriesKey||null,d=u.drawSeries,f=l.connect==="sequence",p={};for(const v of l.channels)p[v.name]=v;if(u.mode==="edit"){const v=f?In(l.marks||[],l.pointer.x,l.pointer.y,1/0,d):td(l.marks||[],l.pointer.x,l.pointer.y,1/0,t,d);if(v==null||l.data[v]==null)return;const k={...l.data[v]};for(const _ of l.channels){if(!f&&_.name!==n)continue;const T=ho(_,l.pointer);T!==void 0&&(k[_.field]=T)}return l.data.map((_,T)=>T===v?k:_)}if(f){const v=l.pointer.x,k=l.pointer.y;if(u.lastX!=null&&u.lastY!=null&&Math.hypot(v-u.lastX,k-u.lastY)<o)return;const _=Fn(l,{defaults:c?{[c]:d}:{}});return _?(u.lastX=v,u.lastY=k,[...l.data,_]):void 0}const h=p[t],y=p[n];if(!h||!y||!h.scale||!y.scale||!h.scale.invertible||!y.scale.invertible)return;const g=Lb(l.scales[t],r);if(!g.length)return;const m=h.scale.invertValue(t==="x"?l.pointer.x:l.pointer.y),b=y.scale.invertValue(n==="x"?l.pointer.x:l.pointer.y),w=()=>{let v=null,k=1/0;for(const _ of g){const T=Math.abs(xn(_)-xn(m));T<k&&(k=T,v=_)}return v==null?[]:[v]};let x;if(u.lastDomain==null)x=w();else{const v=Math.min(xn(u.lastDomain),xn(m)),k=Math.max(xn(u.lastDomain),xn(m));x=g.filter(_=>xn(_)>=v&&xn(_)<=k),x.length||(x=w())}u.lastDomain=m;const S=l.data.slice();for(const v of x){const k=S.findIndex(T=>(!c||T[c]===d)&&xn(T[h.field])===xn(v)),_={...Es(l.schema),...k>=0?S[k]:{}};c&&(_[c]=d),_[h.field]=v,_[y.field]=b,k>=0?S[k]=_:S.push(_)}return S}})}function O4(e={}){return e.mode==="relative"&&(ge("sweep:relative",`edit.line.sweep({ mode: "relative" }) is not a mode a sweep has — the pointer's POSITION is the value it paints. Ignoring mode.`),e={...e,mode:"absolute"}),Xn({pick:"sweep",guide:!0,scope:"line",...e,type:"line.sweep"})}function C4(e={}){const{series:t,...n}=e;return je({type:"line.removeSeries",gesture:"click",scope:"line",cardinality:"delete",...n,apply:r=>{if(r.datum==null)return;const o=t||r.seriesKey||null;if(!o)return r.data.filter((s,a)=>a!==r.index);const i=r.datum[o];return r.data.filter(s=>s[o]!==i)}})}function N4(e,t){return t?[t]:e&&e.fields||[]}function I4(e,t){const n={};for(const r of e)n[r]=t;return n}function L4(e={}){const{field:t,mode:n="rescale",...r}=e,o=6;return je({type:"axis.scale",gesture:"drag",pick:"axisDrag",scope:"axis",target:"domain",...r,apply:i=>{const s=i.session,a=i.channels[0];if(!s||!s.grabEnd||!a||!a.scale)return;const l=N4(a.scale,t);if(!l.length)return;const u=s.anchorPixel,c=xn(s.anchorValue),d=xn(s.grabValue),f=s.anchorValue instanceof Date||s.grabValue instanceof Date;let h=(s.axis==="x"?i.pointer.x:i.pointer.y)-u;const y=s.grabPixel-u;Math.abs(h)<o&&(h=h<0?-o:o);let g;if(n==="grow"){const S=s.pxPerUnit||y/(d-c||1);g=c+h/(S||1)}else g=c+(d-c)*(y/h);const m=Math.min(c,g),b=Math.max(c,g);if(!Number.isFinite(m)||!Number.isFinite(b)||b<=m)return;const w=f?[new Date(m),new Date(b)]:[m,b],x={domains:I4(l,w)};if(n==="grow"){const S=Math.abs(s.pxPerUnit||1),v=(b-m)*S,k=i.margins||{top:20,right:20,bottom:30,left:40};x.resize=s.axis==="x"?{width:v+k.left+k.right}:{height:v+k.top+k.bottom}}return x}})}function F4(e,t,n){const r=e&&e.fieldRefs||[];if(t){const o=r.filter(i=>i.field===t);return o.length?o:[{table:n,field:t}]}return r.length?r:(e&&e.fields||[]).map(o=>({table:n,field:o}))}function Vc(e,t,n,r,o){const i={domains:{}},s={},a={};for(const l of e)(a[l.table]||(a[l.table]=[])).push(l.field);for(const[l,u]of Object.entries(a)){const c={};let d=o[l]||[],f=!1;for(const p of u){c[p]=t({table:l,field:p});const h=n({table:l,field:p},d);h&&(d=h,f=!0)}l===r?(i.domains=c,f&&(i.data=d)):s[l]=f?{domains:c,data:d}:{domains:c}}return Object.keys(s).length&&(i.tables=s),i}function dy(e,t){const n=e.channels[0],r=n&&_t(n.name);if(!r)return;const o=n&&n.scale,i=o&&typeof o.step=="function"?o.step():null;if(!i)return;const s=e.margins||{top:20,right:20,bottom:30,left:40};if(r==="y"){const l=(e.height||0)+t*i;return l>i?{height:l+s.top+s.bottom}:void 0}const a=(e.width||0)+t*i;return a>i?{width:a+s.left+s.right}:void 0}function R4(e={}){const{field:t,mode:n="rescale",when:r,...o}=e,i=n==="grow",s=f=>F4(f.channels[0]&&f.channels[0].scale,t,f.table||"data"),a=f=>{const p=f.channels[0];return p&&p.scale&&typeof p.scale.domain=="function"?[...p.scale.domain()]:[]},l=f=>f.tables||{[f.table]:f.data},u=je({type:"scale.addCategory",gesture:"commit",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.addCategory),r),apply:f=>{const p=f.value!=null?String(f.value).trim():"";if(!p)return;const h=a(f);if(h.includes(p))return;const y=s(f);if(!y.length)return;const g=Vc(y,()=>[...h,p],()=>null,f.table,l(f));if(i){const m=dy(f,1);m&&(g.resize=m)}return g}}),c=je({type:"scale.renameCategory",gesture:"commit",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.category!=null),r),apply:f=>{const p=f.node&&f.node.category,h=f.value!=null?String(f.value).trim():"";if(p==null||!h||h===p)return;const y=a(f);if(y.includes(h))return;const g=s(f);if(!g.length)return;const m=y.map(b=>b===p?h:b);return Vc(g,()=>m,({field:b},w)=>w.map(x=>x[b]===p?{...x,[b]:h}:x),f.table,l(f))}}),d=je({type:"scale.removeCategory",gesture:"click",pick:"direct",scope:"scale",target:"domain",...o,when:Vr(f=>!!(f.node&&f.node.removeCategory!=null),r),apply:f=>{const p=f.node&&f.node.removeCategory;if(p==null)return;const h=a(f);if(!h.includes(p))return;const y=s(f);if(!y.length)return;const g=h.filter(b=>b!==p),m=Vc(y,()=>g,({field:b},w)=>w.filter(x=>x[b]!==p),f.table,l(f));if(i){const b=dy(f,-1);b&&(m.resize=b)}return m}});return[u,c,d]}function Fb(e){return e?e.field:void 0}function Rb(e,t,n){const r=e.node&&e.node.indices||[];if(r.length>1){const o=new Set(r);return e.data.map((i,s)=>o.has(s)?{...i,[t]:n}:i)}return{...e.datum,[t]:n}}function P4(e={}){return je({type:"legend.category",gesture:"click",pick:"direct",scope:"legend",...e,apply:t=>{const n=Fb(t.channels[0]);if(!n||!t.node||t.datum==null)return;const r=t.node.category;if(r!==void 0)return Rb(t,n,r)}})}function z4(e={}){return je({type:"legend.value",gesture:"drag",pick:"direct",scope:"legend",...e,apply:t=>{const n=t.node;if(!n||n.rampStart==null||n.rampEnd==null)return;const r=Fb(t.channels[0]);if(!r||t.datum==null)return;const o=n.rampEnd-n.rampStart;if(!o)return;const i=n.along==="y"?t.pointer.y:t.pointer.x,s=Math.max(0,Math.min(1,(i-n.rampStart)/o)),a=n.loValue+s*(n.hiValue-n.loValue);return Rb(t,r,a)}})}const D4={linear:(e,t,n)=>{const r=t.scales&&t.scales[e.axis];if(!r||!r.invertible)return;const o=e.axis==="x"?t.pointer.x:t.pointer.y,i=Number(r.invertValue(o));if(Number.isFinite(i))return Math.max(n.lo,Math.min(n.hi,i))},angular:(e,t,n)=>{const{cx:r,cy:o,spanStart:i,spanEnd:s,pad:a}=e,l=s-i-a*n.n;if(!Number.isFinite(l)||l===0||!(n.total>0))return;const u=Math.sign(l)||1,c=i+a/2+n.local*a+l*(n.lo/n.total),f=((Bf(t.pointer,{cx:r,cy:o})-c)*u%360+360)%360,p=Math.abs(l)*((n.hi-n.lo)/n.total);return p<1e-9?n.lo:f<=p?n.lo+f/Math.abs(l)*n.total:f-p<360-f?n.hi:n.lo}};function Pb(e,t,n){const r=e&&D4[e.kind];return r?r(e,t,n):void 0}function kd(e,t){const n=e&&e.stack;if(!n||!Array.isArray(n.members)||n.local==null||!n.field||!Array.isArray(t.data)||!t.data.length)return null;const{mags:r,total:o,bounds:i}=tc(n.members,t.data,n.field);return{st:n,members:n.members,local:n.local,field:n.field,mags:r,total:o,bounds:i}}function j4(e,t){const n=e.markChannels||{},r=t||n.fill&&n.fill.field||n.stroke&&n.stroke.field||null;if(!r)return{field:null,domain:[],open:!0};const o=e.schema&&e.schema[r],i=o&&Array.isArray(o.domain)?o.domain:null;if(i)return{field:r,domain:i,open:!!o.open};for(const s of["fill","stroke"]){const a=n[s];if(!a||a.field!==r)continue;const l=e.scales[s],u=l&&Array.isArray(l.domainConfig)?l.domainConfig:null;if(u)return{field:r,domain:u,open:!0}}return{field:r,domain:[],open:!0}}function W4(e={}){const{defaults:t={},label:n,categoryField:r,when:o,...i}=e;return je({type:"stack.cut",gesture:"click",pick:"direct",scope:"stack",target:"domain",...i,when:Vr(s=>!!(s.node&&s.node.stack&&!s.node.edge),o),apply:s=>{const a=s.node,l=kd(a,s);if(!l)return;const{members:u,local:c,field:d,mags:f,total:p,bounds:h}=l,[y,g]=h[c];if(!(g>y))return;const m=Pb(l.st.geometry,s,{lo:y,hi:g,local:c,n:u.length,total:p});if(m===void 0)return;const b=u[c],w=s.data[b],x=j4(s,r),S=u.map(N=>s.data[N]),v=Yf(S,x.field,x.domain,{open:x.open,label:n});if(x.field&&v===void 0){ge(`stack:domainfull:${x.field}`,`edit.stack.cut() has no category left to give a new segment: this stack already uses every value in schema.${x.field}'s domain (${JSON.stringify(x.domain)}). A declared domain is the whole vocabulary, so the cut is refused. Declare more categories, or set schema.${x.field}.open = true to let a cut add one.`);return}const k={};for(const N of["x","y"]){const I=s.markChannels[N]&&s.markChannels[N].field;I&&(k[I]=w[I])}const _={...Es(s.schema),...k,...x.field?{[x.field]:v}:{},[d]:g-m,...t},T=s.data.slice();T[b]={...w,[d]:m-y},T.splice(b+1,0,_);const L={};return x.field&&x.open&&!x.domain.includes(v)&&(L[x.field]=[...x.domain,v]),{domains:L,data:T}}})}function q4(e={}){const{when:t,...n}=e;return je({type:"stack.edge",inverts:!0,gesture:"drag",pick:"direct",scope:"stack",...n,when:Vr(r=>!!(r.node&&r.node.edge&&r.node.stack),t),apply:r=>{const o=kd(r.node,r);if(!o)return;const{members:i,local:s,field:a,mags:l,total:u,bounds:c}=o,d=s+1;if(d>=i.length)return;const f=l[s]+l[d];if(!(f>0))return;const p=c[s][0],h=c[d][1],y=Pb(o.st.geometry,r,{lo:p,hi:h,local:s,n:i.length,total:u});if(y===void 0)return;const g=y-p,m=f-g,b=i[s],w=i[d];return r.data.map((x,S)=>S===b?{...x,[a]:g}:S===w?{...x,[a]:m}:x)}})}function B4(e={}){const{when:t,...n}=e;return je({type:"stack.merge",gesture:"dblclick",pick:"direct",scope:"stack",cardinality:"delete",...n,when:Vr(r=>!!(r.node&&r.node.edge&&r.node.stack),t),apply:r=>{const o=kd(r.node,r);if(!o)return;const{members:i,local:s,field:a,mags:l}=o,u=s+1;if(u>=i.length)return;const c=i[s],d=i[u],f=l[s]+l[u];return r.data.map((p,h)=>h===c?{...p,[a]:f}:p).filter((p,h)=>h!==d)}})}const H4=1;function U4(e,t){const n=e.markChannels&&e.markChannels[t];return n&&n.field!=null?n.field:null}function hy(e,t,n){const r=e.markChannels&&e.markChannels[t];if(!r)return n;if(r.field!=null){const i=e.datum?Number(e.datum[r.field]):NaN;return Number.isFinite(i)?i:n}const o=Number(r.datum!==void 0?r.datum:r.value);return Number.isFinite(o)?o:n}function K4(e,t){const n=e.scales.x,r=e.scales.y;if(!r||!r.invertible)return null;const o=e.node?{anchor:e.node.anchor,probe:e.node.probe}:{},{anchor:i,probe:s}=ic(e.scales,{anchor:t.anchor!=null?t.anchor:o.anchor,probe:t.probe!=null?t.probe:o.probe}),a=hy(e,"intercept",0),l=hy(e,"slope",0),u=e.node&&e.node.grip==="probe";let c=s;return u||(c=n&&n.invertible?Number(n.invertValue(e.pointer.x)):null),c!=null&&!Number.isFinite(c)&&(c=null),c!=null&&((n&&n.encode?Math.abs(Number(n.encode(c))-Number(n.encode(i))):c===i?0:1/0)>=H4||(c=null)),{a,b:l,anchor:i,probeX:c,yv:Number(r.invertValue(e.pointer.y)),yAnchor:Cr({a,b:l},i)}}function Y4(e,t){const n={};let r=!1;for(const[o,i]of Object.entries(t)){const s=U4(e,o);s==null||!Number.isFinite(i)||(n[s]=i,r=!0)}if(r){if(e.datum)return{...e.datum,...n};if(e.data.length)return e.data.map(o=>({...o,...n}))}}function sc(e,t,n,r){const{anchor:o,probe:i,...s}=r||{};return cl(je({type:e,gesture:"drag",pick:"direct",scope:"trend",channels:[t],...s,apply:a=>{const l=K4(a,{anchor:o,probe:i});if(!l)return;const u=n(l,a);return u?Y4(a,u):void 0}}),t)}function G4(e={}){return sc("trend.intercept","intercept",t=>({intercept:t.yv-t.b*t.anchor}),e)}function V4(e={}){return sc("trend.slope","slope",t=>{if(t.probeX==null)return;const n=(t.yv-t.yAnchor)/(t.probeX-t.anchor);return{slope:n,intercept:t.yAnchor-n*t.anchor}},e)}function X4(e={}){return sc("trend.interceptSpread","interceptSpread",t=>({interceptSpread:Math.abs(t.yv-t.yAnchor)}),e)}function J4(e={}){return sc("trend.slopeSpread","slopeSpread",t=>{if(t.probeX==null)return;const n=(t.yv-t.yAnchor)/(t.probeX-t.anchor);return{slopeSpread:Math.abs(n-t.b)}},e)}function Z4(e,t){const n=t.axis==="y"?e.y:e.x,r=t.axis==="y"?e.x:e.y,o=t.sign*(n-t.baseline);if(o<=0)return 0;const i=Math.floor(o/t.cellSize);if(i>=t.rows)return t.totalCells;let s=Math.floor((r-(t.bandStart+t.bandInset))/t.cellSize);s=Math.max(0,Math.min(t.multiple-1,s));const a=i*t.multiple+s+1;return Math.max(0,Math.min(t.totalCells,a))}function Q4(e={}){return je({type:"waffle.fill",gesture:"drag",scope:"waffle",...e,apply:t=>{const n=t.node&&t.node.grid,r=t.channels&&t.channels[0];if(!n||!r||!r.field)return;const o=Z4(t.pointer,n),i=Math.max(n.dlo,Math.min(n.dhi,n.dlo+o*n.unit));return{...t.datum,[r.field]:i}}})}const Sd=28,py=12,e8=8;function gl(e){const t=e.schemaSpec;if(!t)return null;const n=t.byRole.nodes||t.primary,r=t.tables[n];return!r||!r.key?null:{name:n,table:r,rows:(e.tables||{})[n]||[],key:r.key}}function ml(e,t){const n=e.schemaSpec,r=n&&(n.byRole.links||e.table),o=n&&n.tables[r];if(!o)return null;const i=Object.keys(o.fields).filter(u=>o.fields[u]&&o.fields[u].type==="ref"),s=u=>t[u]&&t[u].field!=null?t[u].field:null,a=s("source")||i[0],l=s("target")||i[1];return!a||!l?null:{source:a,target:l,sourceSide:s("sourceSide"),targetSide:s("targetSide")}}function $d(e){ge(`${e}:refs`,`edit.network.${e}() cannot find the link table's endpoint columns. Declare them as references (source: { type: "ref" }, target: { type: "ref" }), or name them on the link mark: channels: { source: { field: … }, target: { field: … } }.`)}function zb(e,t){const n=e.nodeBox||null,r=e.nodePorts||null,o=Tb(e.scales,{},t.table,t.rows,n,py*2,py*2,e.width||0,e.height||0),i=t.rows.map((s,a)=>!r||!s?null:r(s,a,t.rows)||{});return{boxed:!!n,ported:!!r,boxes:o,roles:i}}function Bi(e,t){return e?At.filter(n=>j0(e[n],t)):null}function Ju(e,t,n,r,o=null){const i=zb(e,t),s=e.pointer,a=d=>d===r||!!o&&d===o.index&&!o.body;let l=null,u=1/0;if(i.ported){const d=Jf.size+wn;if(i.boxes.forEach((f,p)=>{if(!(!f||p===r))for(const h of Bi(i.roles[p],n)||[]){if(o&&p===o.index&&h===o.side)continue;const y=Go(f,h,0,0),g=Math.hypot(y.x-s.x,y.y-s.y);g<=d&&g<u&&(u=g,l={row:t.rows[p],index:p,side:h})}}),l)return l}if(i.boxed&&(i.boxes.forEach((d,f)=>{if(!d||a(f))return;const p=Bi(i.roles[f],n);if(p&&!p.length||Math.abs(s.x-d.cx)>d.hw||Math.abs(s.y-d.cy)>d.hh)return;const h=Math.hypot(d.cx-s.x,d.cy-s.y);h<u&&(u=h,l={row:t.rows[f],index:f,side:null})}),l))return l;const c=Zn(e.edit,Sd);return i.boxes.forEach((d,f)=>{if(!d||a(f))return;const p=Bi(i.roles[f],n);if(p&&!p.length)return;const h=Math.hypot(d.cx-s.x,d.cy-s.y);h<=c&&h<u&&(u=h,l={row:t.rows[f],index:f,side:null})}),l}function Db(e,t){const n=gl(e);if(!n)return null;const r=zb(e,n);if(!r.ported)return null;const o=[];return r.boxes.forEach((i,s)=>{if(i)for(const a of Bi(r.roles[s],t)||[]){const l=Go(i,a,0,0);o.push({x:l.x,y:l.y,key:ed(n.name,s,a)})}}),o}function jb(e,t,n,r,o){const i=e.schemaSpec;if(sl(i).multi)return!1;const s=Ms(i)===!1;return e.data.some((a,l)=>!a||l===o?!1:a[t.source]===n&&a[t.target]===r?!0:s&&a[t.source]===r&&a[t.target]===n)}function t8(e={}){const{defaults:t={},threshold:n,...r}=e;return je({type:"network.connect",gesture:"drag",pick:"direct",table:"links",cardinality:"append",threshold:n??Sd,...r,targets:o=>Db(o,"target"),apply:o=>{const i=gl(o),s=o.session;if(!i||!s||s.fromIndex==null)return;const a=ml(o,o.targetChannels||{});if(!a){$d("connect");return}const l=i.rows[s.fromIndex];if(!l)return;const u=l[i.key];if(u==null)return;const c=o.nodePorts;if(c){const w=c(l,s.fromIndex,i.rows)||{},x=Bi(w,"source")||[];if(s.fromSide!=null?!x.includes(s.fromSide):!x.length)return}const d=w=>({...a.sourceSide?{[a.sourceSide]:s.fromSide!=null?s.fromSide:null}:{},...a.targetSide?{[a.targetSide]:w}:{}}),f=()=>{if(!o.preview)return;const w=Fn(o,{defaults:t,seed:{[a.source]:u,[a.target]:null,...d(null)}});return w?[...o.data,w]:void 0},p=sl(o.schemaSpec).selfLoops,h=s.fromPoint,y=!h||Math.hypot(o.pointer.x-h.x,o.pointer.y-h.y)>=e8,g=p?Ju(o,i,"target",null,{index:s.fromIndex,side:s.fromSide,body:y}):Ju(o,i,"target",s.fromIndex);if(!g)return f();const m=g.row[i.key];if(m==null||jb(o,a,u,m,null))return f();const b=Fn(o,{defaults:t,seed:{[a.source]:u,[a.target]:m,...d(g.side)}});return b?[...o.data,b]:void 0}})}function n8(e={}){const{threshold:t,when:n,channel:r,channels:o,...i}=e,s=r?[r]:Array.isArray(o)?o:["source","target"],a=l=>{const u=l.node&&l.node.channel;return u==="source"||u==="target"?u:null};return je({type:"network.rewire",gesture:"drag",pick:"direct",scope:"network",threshold:t??Sd,...i,channels:s,when:l=>{const u=a(l);return!u||!s.includes(u)?!1:n?!!n(l):!0},targets:l=>{const u=a(l),c=gl(l),d=u?Db(l,u):null;if(!d||!c||!l.datum||sl(l.schemaSpec).selfLoops)return d;const f=ml(l,l.markChannels||{}),p=f&&l.datum[u==="source"?f.target:f.source],h=c.rows.findIndex(y=>y&&y[c.key]===p);return d.filter(y=>!y.key.startsWith(ed(c.name,h,"")))},apply:l=>{const u=gl(l),c=a(l);if(!u||!c||l.index==null||!l.datum)return;const d=ml(l,l.markChannels||{});if(!d){$d("rewire");return}const f=c==="source"?d.source:d.target,p=c==="source"?d.sourceSide:d.targetSide,h=l.datum[c==="source"?d.target:d.source],y=u.rows.findIndex(S=>S&&S[u.key]===h),g=sl(l.schemaSpec).selfLoops,m=Ju(l,u,c,!g&&y>=0?y:null);if(!m||m.row[u.key]==null)return l.preview?{...l.datum,[f]:null}:l.data.filter((S,v)=>v!==l.index);const b=m.row[u.key],w=!p||l.datum[p]===m.side;if(l.datum[f]===b&&w)return;const x=c==="source"?[b,h]:[h,b];if(!(l.datum[f]!==b&&jb(l,d,x[0],x[1],l.index)))return{...l.datum,[f]:b,...p?{[p]:m.side}:{}}}})}function r8(e={}){return je({type:"network.reverse",gesture:"click",pick:"direct",scope:"network",...e,apply:t=>{if(!t.datum)return;const n=ml(t,t.markChannels||{});if(!n){$d("reverse");return}if(Ms(t.schemaSpec)===!1){ge("reverse:undirected","edit.network.reverse() is on a links table declared directed: false, where source and target name the same relationship either way round — so swapping them has no visible effect. Declare directed: true, or drop the edit.");return}return{...t.datum,[n.source]:t.datum[n.target],[n.target]:t.datum[n.source]}}})}function si(e){return e.projection||e.scales&&e.scales.projection||null}function Wb(e){const t=e.lon&&e.lon.field||"lon",n=e.lat&&e.lat.field||"lat";return{lon:t,lat:n}}function o8(e={}){const{...t}=e;return je({type:"geo.move",gesture:"drag",channels:null,pick:"direct",scope:"geo",...t,apply:n=>{if(!n.datum)return;const r=Fr(si(n),n.pointer);if(!r)return;const o=Wb(n.markChannels||{});return{...n.datum,[o.lon]:r.lon,[o.lat]:r.lat}}})}function i8(e={}){const{defaults:t={},...n}=e;return je({type:"geo.create",gesture:"click",channels:null,pick:"plane",scope:"geo",cardinality:"append",...n,apply:r=>{const o=Fr(si(r),r.pointer);if(!o)return;const i=Wb(r.markChannels||{}),s=Fn(r,{defaults:t,seed:{[i.lon]:o.lon,[i.lat]:o.lat}});return s?[...r.data,s]:void 0}})}function s8(e={}){const{...t}=e;return je({type:"geo.dragVertex",gesture:"drag",channels:null,pick:"direct",scope:"geo",when:n=>!!(n.node&&n.node.channel==="vertex"),...t,apply:n=>{if(!n.datum||!n.node)return;const r=n.node.vertexIndex;if(r==null)return;const o=Fr(si(n),n.pointer);if(!o)return;const i=n.markChannels.coordinates&&n.markChannels.coordinates.field||"coordinates",s=n.datum[i];if(!Array.isArray(s)||!s[r])return;const a=s.map((l,u)=>u===r?[o.lon,o.lat]:l.slice());return{...n.datum,[i]:a}}})}function a8(e={}){const{min:t=2,...n}=e;return je({type:"geo.removeVertex",gesture:"click",channels:null,pick:"direct",scope:"geo",when:r=>!!(r.node&&r.node.channel==="vertex"),...n,apply:r=>{if(!r.datum||!r.node)return;const o=r.node.vertexIndex;if(o==null)return;const i=r.markChannels.coordinates&&r.markChannels.coordinates.field||"coordinates",s=r.datum[i];if(!Array.isArray(s)||!s[o]||s.length<=t)return;const a=s.filter((l,u)=>u!==o).map(l=>l.slice());return{...r.datum,[i]:a}}})}function l8(e={}){const{threshold:t=24,minDist:n=8,defaults:r={},into:o="new",...i}=e;return je({type:"geo.draw",gesture:"drag",cardinality:"appendMany",channels:null,pick:"draw",scope:"geo",threshold:t,into:o,...i,apply:s=>{const a=s.session;if(!a)return;const l=Fr(si(s),s.pointer);if(!l)return;const u=s.markChannels.coordinates&&s.markChannels.coordinates.field||"coordinates",c=s.pointer.x,d=s.pointer.y;if(a.lastX!=null&&a.lastY!=null&&Math.hypot(c-a.lastX,d-a.lastY)<n)return;if(a.drawIndex!=null&&s.data[a.drawIndex]){const h=a.drawIndex,y=s.data[h],g=Array.isArray(y[u])?y[u].slice():[];return g.push([l.lon,l.lat]),a.lastX=c,a.lastY=d,s.data.map((m,b)=>b===h?{...m,[u]:g}:m)}const f=Fn(s,{defaults:r,seed:{[u]:[[l.lon,l.lat]]}});if(!f)return;const p=[...s.data,f];return a.drawIndex=p.length-1,a.lastX=c,a.lastY=d,p}})}function qb(e){return{west:e.west&&e.west.field||"west",south:e.south&&e.south.field||"south",east:e.east&&e.east.field||"east",north:e.north&&e.north.field||"north"}}function c8(e={}){const{move:t=!0,...n}=Kl(e,"geo.brush","geoBrush");return je({type:"geo.brush",gesture:"drag",channels:null,scope:"geo",...n,move:t,pick:"geoBrush",apply:r=>{const o=r.session,i=o&&o.zone,s=r.datum;if(!i||!s)return;const a=qb(r.markChannels||{});if(i==="canonicalize"){const p={...s};let h=!1;for(const[y,g]of[[a.west,a.east],[a.south,a.north]])s[y]==null||s[g]==null||s[y]<=s[g]||(p[y]=s[g],p[g]=s[y],h=!0);return h?p:void 0}const l=Fr(si(r),r.pointer);if(!l)return;let u=s[a.west],c=s[a.south],d=s[a.east],f=s[a.north];if(i==="body"){if(!t||!o.grab||!o.box0)return;const p=l.lon-o.grab.lon,h=l.lat-o.grab.lat;u=o.box0.west+p,d=o.box0.east+p,c=o.box0.south+h,f=o.box0.north+h}else for(const p of o.edges||[])p==="west"?u=l.lon:p==="east"?d=l.lon:p==="south"?c=l.lat:p==="north"&&(f=l.lat);return{...s,[a.west]:u,[a.south]:c,[a.east]:d,[a.north]:f}}})}function u8(e,t){const{x:n,y:r}=e.pointer;return(e.marks||[]).some(o=>o.type!=="rect"||o.index==null||o.x==null||o.y==null||o.width==null||o.height==null?!1:n>=o.x-t&&n<=o.x+o.width+t&&r>=o.y-t&&r<=o.y+o.height+t)}function f8(e={}){const{defaults:t={},width:n=10,height:r=6,edgeInset:o=8,...i}=e;return je({type:"geo.createRect",gesture:"click",channels:null,pick:"plane",scope:"geo",cardinality:"append",when:s=>!u8(s,o),...i,apply:s=>{const a=Fr(si(s),s.pointer);if(!a)return;const l=qb(s.markChannels||{}),u=n/2,c=r/2,d=Fn(s,{defaults:t,seed:{[l.west]:a.lon-u,[l.east]:a.lon+u,[l.south]:a.lat-c,[l.north]:a.lat+c}});return d?[...s.data,d]:void 0}})}const d8={anchor:E4,newSeries:A4,draw:T4,sweep:O4,removeSeries:C4},h8={categories:R4},p8={scale:L4},y8={category:P4,value:z4},g8={cut:W4,edge:q4,merge:B4},Zu={intercept:G4,slope:V4,interceptSpread:X4,slopeSpread:J4},m8={fill:Q4},b8={connect:t8,rewire:n8,reverse:r8},w8={move:o8,create:i8,draw:l8,dragVertex:s8,removeVertex:a8,brush:c8,createRect:f8},_d=Object.freeze(Object.defineProperty({__proto__:null,axis:p8,brushRect:q0,brushSpan:pE,create:nd,custom:G0,cycle:xE,editText:K0,geo:w8,legend:y8,line:d8,move:Xn,moveSpan:hE,network:b8,rank:Y0,remove:H0,resize:bE,rotate:wE,scale:h8,select:kE,set:vE,slide:mE,stack:g8,toggle:rd,trend:Zu,waffle:m8,when:M4},Symbol.toStringTag,{value:"Module"}));function Qt(e={}){const{min:t,max:n,field:r}=Rr("clamp",e);return Vt(({value:o,domain:i})=>{let s=t,a=n;s===void 0&&i&&(s=Math.min(...i)),a===void 0&&i&&(a=Math.max(...i));let l=o;return s!==void 0&&l!==void 0&&(l=Math.max(s,l)),a!==void 0&&l!==void 0&&(l=Math.min(a,l)),l},{type:"clamp",options:{min:t,max:n},field:r})}function Bb(e={}){const{total:t,field:n,strategy:r="cap"}=Rr("maintainSum",e);return typeof t!="number"?(ge("maintainSum:target","maintainSum() needs the total the rows must sum to — maintainSum({ total: 100 }). Without one the constraint accepts every edit unchanged."),Vt(()=>{},{type:"maintainSum",options:{total:t,strategy:r},field:n})):r==="normalize"?Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;const l=o.map((d,f)=>f===i&&s!==void 0?{...d,[a]:s}:{...d}),u=l.reduce((d,f)=>d+(Number(f[a])||0),0);if(u===0)return l;const c=t/u;return l.map(d=>({...d,[a]:(Number(d[a])||0)*c}))},{type:"maintainSum",options:{total:t,strategy:r},field:n}):r==="redistribute"?Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;if(i==null||s===void 0)return s;const l=Math.max(0,Math.min(t,Number(s)||0)),u=o.map((f,p)=>p===i?0:Number(f[a])||0).reduce((f,p)=>f+p,0),c=Math.max(0,t-l),d=u>0?c/u:0;return o.map((f,p)=>{if(p===i)return{...f,[a]:l};const h=Number(f[a])||0;return{...f,[a]:u>0?h*d:o.length>1?c/(o.length-1):0}})},{type:"maintainSum",options:{total:t,strategy:r},field:n}):Vt(({data:o,activeIndex:i,value:s,field:a})=>{if(a==null)return;if(i==null||s===void 0)return s;const l=o.reduce((c,d,f)=>f===i?c:c+(d[a]||0),0),u=Math.max(0,t-l);return Math.min(s,u)},{type:"maintainSum",options:{total:t,strategy:"cap"},field:n})}function ac(e={}){const{max:t=1/0,strategy:n="replace"}=Rr("count",e);return Vt(({data:r})=>{if(!(r.length<=t))return n==="reject"?!1:r.slice(r.length-t)},{type:"count",options:{max:t,strategy:n}})}function Md(e={}){const{field:t,max:n=1,strategy:r="reject"}=Rr("unique",e);return Vt(({data:o,activeIndex:i,fields:s})=>{const a=d=>s.map(f=>d[f]).join(""),l=new Map;o.forEach((d,f)=>{const p=a(d);let h=l.get(p);h||(h=[],l.set(p,h)),h.push(f)});let u=!1;for(const d of l.values())if(d.length>n){u=!0;break}if(!u)return;if(r==="reject")return!1;const c=new Set;for(const d of l.values()){if(d.length<=n)continue;let f;if(i!=null&&d.includes(i)){const p=d.filter(h=>h!==i);f=new Set([i,...p.slice(p.length-(n-1))])}else f=new Set(d.slice(d.length-n));d.forEach(p=>{f.has(p)||c.add(p)})}return o.filter((d,f)=>!c.has(f))},{type:"unique",options:{field:t,max:n,strategy:r},field:t})}function Ed(e={}){const{step:t=1,origin:n=0,field:r}=Rr("snap",e);return Vt(({value:o})=>o===void 0||t<=0?o:n+Math.round((o-n)/t)*t,{type:"snap",options:{step:t,origin:n},field:r})}function x8(e){for(let t=1;t<e.length;t++)if(e[t]<e[t-1])return!1;return!0}function v8(e,t,n){if(!n)return-1;let r=-1;for(let o=0;o<e.length;o++)if(Number(n[e[o]])!==Number(t[e[o]])){if(r>=0)return-1;r=o}return r}function k8(e={}){const{field:t,strategy:n="push"}=Rr("ordering",e),r=Array.isArray(t)?t:t!=null?[t]:[];return r.length<2?(ge("ordering:fields","ordering() needs at least two columns, in order — ordering({ field: ['lo', 'mean', 'hi'] }). Without them the constraint accepts every edit unchanged."),Vt(()=>{},{type:"ordering",options:{strategy:n},field:r})):Vt(({active:o,oldData:i,activeIndex:s})=>{if(!o)return;const a=r.map(f=>Number(o[f]));if(a.some(f=>!Number.isFinite(f))||x8(a))return;if(n==="block")return!1;const l=i&&s!=null?i[s]:null,u=v8(r,o,l),c=a.slice();if(u>=0){for(let f=u-1;f>=0;f--)c[f]=Math.min(c[f],c[f+1]);for(let f=u+1;f<c.length;f++)c[f]=Math.max(c[f],c[f-1])}else for(let f=1;f<c.length;f++)c[f]=Math.max(c[f],c[f-1]);const d={...o};return r.forEach((f,p)=>{d[f]=c[p]}),d},{type:"ordering",options:{strategy:n},field:r})}function S8(e={}){const{field:t,along:n="x",dir:r="up",series:o=null}=Rr("monotonic",e),i=r!=="down";return Vt(({data:s,activeIndex:a,field:l})=>{if(!s||s.length<2||l==null)return;const u=new Map;s.forEach((f,p)=>{const h=o?f[o]:null;u.has(h)||u.set(h,[]),u.get(h).push(p)});const c=s.map(f=>({...f}));let d=!1;for(const f of u.values()){const p=f.filter(g=>Number.isFinite(Number(c[g][l]))).sort((g,m)=>yy(c[g][n])-yy(c[m][n]));if(p.length<2)continue;const h=p.indexOf(a),y=h>=0?h:0;for(let g=y+1;g<p.length;g++){const m=Number(c[p[g-1]][l]),b=Number(c[p[g]][l]),w=i?Math.max(b,m):Math.min(b,m);w!==b&&(c[p[g]][l]=w,d=!0)}for(let g=y-1;g>=0;g--){const m=Number(c[p[g+1]][l]),b=Number(c[p[g]][l]),w=i?Math.min(b,m):Math.max(b,m);w!==b&&(c[p[g]][l]=w,d=!0)}}return d?c:void 0},{type:"monotonic",options:{dir:r,along:n,series:o},field:t})}function yy(e){return e instanceof Date?e.getTime():Number(e)}function $8(e={}){const{field:t,min:n=1,series:r=null}=Rr("spacing",e);return Vt(({data:o,activeIndex:i,field:s})=>{if(!o||o.length<2||!(n>0)||s==null)return;const a=new Map;o.forEach((c,d)=>{const f=r?c[r]:null;a.has(f)||a.set(f,[]),a.get(f).push(d)});const l=o.map(c=>({...c}));let u=!1;for(const c of a.values()){const d=c.filter(h=>Number.isFinite(Number(l[h][s]))).sort((h,y)=>Number(l[h][s])-Number(l[y][s]));if(d.length<2)continue;const f=d.indexOf(i),p=f>=0?f:0;for(let h=p+1;h<d.length;h++){const y=Number(l[d[h-1]][s])+n;Number(l[d[h]][s])<y&&(l[d[h]][s]=y,u=!0)}for(let h=p-1;h>=0;h--){const y=Number(l[d[h+1]][s])-n;Number(l[d[h]][s])>y&&(l[d[h]][s]=y,u=!0)}}return u?l:void 0},{type:"spacing",options:{min:n,series:r},field:t})}const Hb=Object.freeze(Object.defineProperty({__proto__:null,clamp:Qt,count:ac,custom:Vt,maintainSum:Bb,monotonic:S8,ordering:k8,snap:Ed,spacing:$8,unique:Md},Symbol.toStringTag,{value:"Module"}));function _8(e,t){return typeof e=="function"?e(t):e}function Ad(e,t){const n={};for(const[r,o]of Object.entries(e))n[r]=_8(o,t);return n}const M8=k0,E8={channels:"a guide has no channel map — it views STATE, not columns. Its options take a literal or a function of the chart context: guides.rule({ y: ({ data }) => … }).",field:"a guide names no field: it draws a statement about the chart, not a column. Read the rows in a function option instead: ({ data }) => …",edit:"a guide is read-only by construction — it can never carry an edit. Put the edit on the MARK whose data the gesture should change.",edits:"a guide is read-only by construction. Put edits on a mark.",table:"a guide views chart STATE, so it has no table. It is handed the primary table's rows and may read any of them through the context.",data:"a guide never owns data. It is handed the rows: guides.rule({ y: ({ data }) => … }).",constraints:"invariants belong to the DATASET (spec.constraints), not to a guide. A guide can READ them: ({ constraints }) => …"};function lc(e,t,n){if(!t||!oi())return;const r=new Set([...M8,...n]);for(const o of Object.keys(t)){if(r.has(o))continue;const i=E8[o];if(i){ge(`guideopt:${e}:${o}`,`guides.${e}({ ${o}: … }): ${i}`);continue}ge(`guideopt:${e}:${o}`,`guides.${e}({ ${o}: … }) is not an option this guide reads, so it is ignored. ${e} options are: ${[...r].sort().join(", ")}.`)}}const A8=Ts.rule;function T8(e={}){return lc("rule",e,A8),{views:"state",type:"rule",build:(t,n,r,o,i)=>{const{scales:s,width:a,height:l}=i,u=i.theme&&i.theme.guide&&i.theme.guide.rule||{},{x:c,y:d,label:f,stroke:p=u.stroke,strokeDasharray:h=u.strokeDasharray,strokeWidth:y=u.strokeWidth,opacity:g=u.opacity}=Ad(e,i),m=i.theme&&i.theme.font&&i.theme.font.labelSize||10,b=[];if(d!==void 0&&s.y){const w=s.y.encode(d);b.push({type:"line",x1:0,x2:a,y1:w,y2:w,stroke:p,strokeDasharray:h,strokeWidth:y,opacity:g,pointerEvents:"none",guide:!0}),f&&b.push({type:"text",x:a-4,y:w-4,text:f,fill:p,fontSize:m,textAnchor:"end",pointerEvents:"none",guide:!0})}if(c!==void 0&&s.x){const w=s.x.encode(c);b.push({type:"line",x1:w,x2:w,y1:0,y2:l,stroke:p,strokeDasharray:h,strokeWidth:y,opacity:g,pointerEvents:"none",guide:!0}),f&&b.push({type:"text",x:w+4,y:10,text:f,fill:p,fontSize:m,textAnchor:"start",pointerEvents:"none",guide:!0})}return b}}}const O8=Ts.region;function C8(e={}){return lc("region",e,O8),{views:"state",type:"region",build:(t,n,r,o,i)=>{const{scales:s,width:a,height:l}=i,u=i.theme&&i.theme.guide&&i.theme.guide.region||{},{x:c,y:d,fill:f=u.fill||"#64748b",opacity:p=u.opacity!=null?u.opacity:.1}=Ad(e,i),h=[];if(Array.isArray(d)&&s.y){const y=s.y.encode(d[0]),g=s.y.encode(d[1]);h.push({type:"rect",x:0,y:Math.min(y,g),width:a,height:Math.abs(g-y),fill:f,opacity:p,pointerEvents:"none",guide:!0})}if(Array.isArray(c)&&s.x){const y=s.x.encode(c[0]),g=s.x.encode(c[1]);h.push({type:"rect",x:Math.min(y,g),y:0,width:Math.abs(g-y),height:l,fill:f,opacity:p,pointerEvents:"none",guide:!0})}return h}}}const N8=Ts.remaining;function I8(e,t){for(const n of e||[]){const r=n;if(!r||r.type!=="maintainSum"||r.field!=null&&t!=null&&r.field!==t)continue;const o=r.options&&r.options.total;if(typeof o=="number")return o}return null}function L8(e={}){return lc("remaining",e,N8),{views:"state",type:"remaining",build:(t,n,r,o,i)=>{const s=i&&i.theme&&i.theme.guide&&i.theme.guide.rule||{},{field:a="y",total:l,unit:u,format:c,anchor:d="top-right",label:f,fill:p=s.stroke||"#64748b",fontSize:h=11}=Ad(e,i),y=t||[],g=typeof l=="number"?l:I8(i&&i.constraints||[],a);if(g==null)return[];const m=y.reduce((k,_)=>{const T=_&&_[a];return k+(typeof T=="number"&&Number.isFinite(T)?T:0)},0),b=g-m,w=typeof c=="function"?c:k=>{const _=Math.round(k*100)/100;return String(_)};let x;if(typeof f=="function")x=String(f(b,m,g));else if(u){const k=Math.round(b);x=`${w(b)} ${u}${k===1?"":"s"} left`}else x=`${w(b)} of ${w(g)} left`;const S=d.endsWith("right"),v=d.startsWith("top");return[{type:"text",x:S?r-4:4,y:v?12:o-6,text:x,fill:p,fontSize:h,textAnchor:S?"end":"start",pointerEvents:"none",guide:!0}]}}}const F8=Ts.proximity;function R8(e){lc("proximity",e,F8);const{target:t,stroke:n,strokeDasharray:r,strokeWidth:o,opacity:i}=e;return{views:"state",type:"proximity",build:(s,a,l,u,c)=>{const d=c.ui&&c.ui.session&&c.ui.session[t];if(!d||d.px==null||d.py==null||d.threshold==null)return[];const f={..._5,...n!==void 0?{color:n}:{},...r!==void 0?{dash:r}:{},...o!==void 0?{width:o}:{},...i!==void 0?{opacity:i}:{}};return[{type:"circle",cx:d.px,cy:d.py,r:d.threshold,fill:"none",stroke:f.color,strokeDasharray:f.dash,strokeWidth:f.width,opacity:f.opacity,guide:!0,effect:!0,pointerEvents:"none"}]}}}function ai(e){return{views:"state",type:"custom",build:(t,n,r,o,i)=>(e(i)||[]).map(s=>({pointerEvents:"none",...s,guide:!0}))}}const Ls=(e,t)=>Object.assign(t,{type:e}),Ub={accent:"#2563eb",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#334155",question:"#0f172a",labelSize:12,questionSize:13,radius:11},Fs=e=>e&&e.theme&&e.theme.widget||Ub,Qu=e=>e&&Array.isArray(e.domainConfig)?e.domainConfig:[];function Td(e={}){const{labelOffset:t=30,radius:n}=e;return Ls("optionRings",ai(r=>{const{scales:o,height:i}=r,s=Fs(r),a=n??s.radius,l=Qu(o.x);if(!l.length)return[];const u=i/2,c=f=>o.x.encode(f),d=[];for(let f=0;f<l.length-1;f++)d.push({type:"line",x1:c(l[f])+a,y1:u,x2:c(l[f+1])-a,y2:u,stroke:s.track,strokeWidth:3,background:!0});for(const f of l)d.push({type:"circle",cx:c(f),cy:u,r:a,fill:"none",stroke:s.ring,strokeWidth:1.5}),d.push({type:"text",x:c(f),y:u+t,text:String(f),textAnchor:"middle",fontSize:s.labelSize,fill:s.label});return d}))}function Kb(e={}){const{pad:t=3}=e;return Ls("cellGrid",ai(n=>{const{scales:r}=n,o=Fs(n),i=Qu(r.x),s=Qu(r.y);if(!i.length||!s.length)return[];const a=yn(r.x,40),l=yn(r.y,30),u=[];for(const c of s)for(const d of i)u.push({type:"rect",x:r.x.encode(d)-a/2+t,y:r.y.encode(c)-l/2+t,width:a-2*t,height:l-2*t,fill:o.cellFill,stroke:o.cellStroke,strokeWidth:1});for(const c of i)u.push({type:"text",x:r.x.encode(c),y:-14,text:String(c),textAnchor:"middle",fontSize:o.labelSize,fill:o.label});for(const c of s)u.push({type:"text",x:-10,y:r.y.encode(c)+4,text:String(c),textAnchor:"end",fontSize:o.labelSize,fill:o.label});return u}))}function Yb(e={}){const{format:t=n=>String(n)}=e;return Ls("sliderTrack",ai(n=>{const{scales:r,width:o,height:i}=n,s=Fs(n);if(!r.x)return[];const a=i/2,l=r.x.domainConfig||[0,1],u=l[0],c=l[l.length-1];return[{type:"line",x1:0,y1:a,x2:o,y2:a,stroke:s.track,strokeWidth:4,background:!0},{type:"line",x1:0,y1:a-7,x2:0,y2:a+7,stroke:s.ring,strokeWidth:2},{type:"line",x1:o,y1:a-7,x2:o,y2:a+7,stroke:s.ring,strokeWidth:2},{type:"text",x:0,y:a+26,text:t(u),textAnchor:"start",fontSize:s.labelSize,fill:s.label},{type:"text",x:o,y:a+26,text:t(c),textAnchor:"end",fontSize:s.labelSize,fill:s.label}]}))}function nn(e,t={}){const{y:n=-18}=t;return Ls("prompt",ai(r=>{const o=Fs(r);return e?[{type:"text",x:0,y:n,text:e,textAnchor:"start",fontSize:o.questionSize,fill:o.question}]:[]}))}function Gb(e={}){const{x:t="x",y:n="y"}=e;return Ls("crosshair",ai(r=>{const{width:o,height:i}=r,s=Fs(r),a=o/2,l=i/2,u=(f,p,h,y)=>({type:"text",x:f,y:p,text:h,textAnchor:y,fontSize:s.labelSize,fill:s.label}),c=14,d=(f,p,h)=>{const y=[...String(t).split(/\s+/),`(${p})`],g=l-(y.length-1)*c/2;return y.map((m,b)=>u(f,g+b*c+4,m,h))};return[{type:"line",x1:0,y1:l,x2:o,y2:l,stroke:s.ring,strokeWidth:1,background:!0},{type:"line",x1:a,y1:0,x2:a,y2:i,stroke:s.ring,strokeWidth:1,background:!0},...d(o+10,"high","start"),...d(-10,"low","end"),u(a,-8,`${n} (high)`,"middle"),u(a,i+20,`${n} (low)`,"middle")]}))}const P8=Object.freeze(Object.defineProperty({__proto__:null,cellGrid:Kb,crosshair:Gb,custom:ai,optionRings:Td,prompt:nn,proximity:R8,region:C8,remaining:L8,rule:T8,sliderTrack:Yb},Symbol.toStringTag,{value:"Module"}));function mn(e){return Xf(e)}function z8(e={}){const{question:t,options:n=[],value:r,onChange:o,width:i=560,height:s=130,stage:a,theme:l}=e,u=mn(l);return{width:i,height:s,theme:l,margins:{top:34,right:60,bottom:44,left:60},schema:{choice:{type:"ordinal",domain:n}},scales:{x:{type:"band"}},data:r!=null?[{choice:r}]:[],constraints:[ac({max:1,strategy:"replace"})],onChange:o,axes:!1,guides:[nn(t||""),Td()],marks:[Sr({id:"likert",size:u.widget.radius-3,fill:u.widget.accent,channels:{x:{field:"choice"}},edits:[nd({pick:"probe",channels:["x"],advance:!1,stage:a})]})]}}function D8(e={}){const{question:t,options:n=[],max:r=1/0,value:o=[],onChange:i,width:s=560,height:a=130,stage:l,theme:u}=e,c=mn(u),d=[Md({field:"choice",strategy:"reject"})];return r!==1/0&&d.push(ac({max:r,strategy:"reject"})),{width:s,height:a,theme:u,margins:{top:34,right:60,bottom:44,left:60},schema:{choice:{type:"categorical",domain:n}},scales:{x:{type:"band"}},data:o.map(f=>({choice:f})),constraints:d,onChange:i,axes:!1,guides:[nn(t||""),Td()],marks:[Sr({id:"choice",size:c.widget.radius-3,fill:c.widget.accent,channels:{x:{field:"choice"}},edits:[rd({pick:"probe",channels:["x"],advance:!1,stage:l})]})]}}function j8(e={}){const{question:t,domain:n=[0,1],step:r,value:o,format:i,onChange:s,width:a=560,height:l=120,stage:u,theme:c}=e,d=mn(c),f=[Qt({min:n[0],max:n[1],field:"value"})];return r&&f.push(Ed({field:"value",step:r,origin:n[0]})),{width:a,height:l,theme:c,margins:{top:34,right:40,bottom:40,left:40},schema:{value:{type:"quantitative",domain:n}},data:[{value:o??n[0]}],constraints:f,onChange:s,axes:!1,guides:[nn(t||""),Yb(i?{format:i}:{})],marks:[Sr({id:"slider",size:d.widget.radius-2,fill:d.widget.accent,channels:{x:{field:"value"}},edits:[Xn({pick:"probe",channels:["x"],advance:!1,stage:u})]})]}}function W8(e={}){const{question:t,questions:n=[],options:r=[],value:o=[],onChange:i,width:s=620,height:a=100+n.length*46,stage:l,theme:u}=e,c=mn(u),d={top:62,right:30,bottom:20,left:130},f=a-d.top-d.bottom;return{width:s,height:a,theme:u,margins:d,schema:{option:{type:"ordinal",domain:r},question:{type:"categorical",domain:n}},scales:{x:{type:"band"},y:{type:"band",range:[0,f]}},data:o,constraints:[Md({field:"question",strategy:"replace"})],onChange:i,axes:!1,guides:[nn(t||"",{y:-38}),Kb()],marks:[Sr({id:"matrix",size:c.widget.radius-3,fill:c.widget.accent,channels:{x:{field:"option"},y:{field:"question"}},edits:[rd({pick:"probe",channels:["x","y"],advance:!1,stage:l})]})]}}const q8={top:56,right:92,bottom:52,left:92};function B8(e,t){const n={...q8},r=e-n.left-n.right,o=t-n.top-n.bottom;if(r>o){const i=(r-o)/2;n.left+=i,n.right+=i}else if(o>r){const i=(o-r)/2;n.top+=i,n.bottom+=i}return n}function H8(e={}){const{question:t,x:n="x",y:r="y",r:o=0,spread:i=0,samples:s=60,seed:a=7,render:l="samples",onChange:u,width:c=460,height:d=400,theme:f}=e;return{width:c,height:d,theme:f,margins:B8(c,d),schema:{x:{type:"quantitative",domain:[-1,1]},y:{type:"quantitative",domain:[-1,1]},r:{type:"quantitative",domain:[-1,1],default:0},spread:{type:"quantitative",domain:[0,1],default:0}},data:[{r:o,spread:i}],constraints:[Qt({field:"r",min:-1,max:1}),Qt({field:"spread",min:0,max:1})],onChange:u,axes:!1,guides:[nn(t||"",{y:-32}),Gb({x:n,y:r})],marks:[ii({id:"lineCone",parts:[_b({render:l,samples:s,seed:a,channels:{intercept:{datum:0},slope:{field:"r"},slopeSpread:{field:"spread"}}}),$b({handles:!1,channels:{intercept:{datum:0},slope:{field:"r",edit:Zu.slope({pick:"probe",stage:0})},slopeSpread:{field:"spread",edit:Zu.slopeSpread({pick:"probe",stage:1})}}})]})]}}function U8(e={}){const{question:t="Rank these items",items:n=["A","B","C","D"],onChange:r,width:o=420,height:i=280,stage:s,theme:a}=e,l=mn(a),u=n.map((d,f)=>f+1),c=n.map((d,f)=>({item:d,rank:f+1}));return{width:o,height:i,theme:a,margins:{top:40,right:24,bottom:24,left:100},schema:{item:{type:"categorical",domain:n},rank:{type:"ordinal",domain:u}},data:c,onChange:r,axes:!1,guides:[nn(t)],marks:[Sr({id:"rank-dots",size:l.widget.radius-2,fill:l.widget.accent,channels:{x:{value:40},y:{field:"rank",edit:Y0({stage:s})}}}),Or({id:"rank-labels",fontSize:13,fill:l.widget.label,channels:{x:{value:56},y:{field:"rank"},text:{field:"item"},textAnchor:{value:"start"}}})]}}function K8(e={}){const{question:t="Allocate the budget",categories:n=["A","B","C","D"],total:r=100,values:o,onChange:i,width:s=480,height:a=280,stage:l,theme:u}=e,c=mn(u),d=r/n.length,f=n.map((p,h)=>({cat:p,share:o&&o[h]!=null?o[h]:d}));return{width:s,height:a,theme:u,margins:{top:40,right:24,bottom:36,left:48},schema:{cat:{type:"categorical",domain:n},share:{type:"quantitative",domain:[0,r]}},data:f,constraints:[Qt({min:0,max:r,field:"share"}),Bb({total:r,field:"share",strategy:"redistribute"})],onChange:i,guides:[nn(t)],marks:[nc({id:"alloc",fill:c.widget.accent,fillOpacity:.75,channels:{x:{field:"cat"},y:{field:"share",edit:Xn({guide:!0,stage:l})}}})]}}function Y8(e={}){const{question:t="Place tokens to express probability",bins:n=["Low","Med","High"],maxTokens:r=20,onChange:o,width:i=420,height:s=300,stage:a,theme:l}=e,u=mn(l);return{width:i,height:s,theme:l,margins:{top:40,right:24,bottom:36,left:40},schema:{bin:{type:"categorical",domain:n}},data:[],constraints:[ac({max:r,strategy:"reject"})],onChange:o,guides:[nn(t)],marks:[fb({id:"tokens",fill:u.widget.accent,channels:{x:{field:"bin"}},edits:[nd({pick:"probe",channels:["x"],defaults:{},advance:!1,stage:a}),H0({pick:"direct",stage:a})]})]}}function G8(){return Vt(({active:e})=>{if(e)return{lo:Math.min(e.lo,e.mean),hi:Math.max(e.hi,e.mean)}},{type:"orderInterval"})}function V8(e){return G0(t=>{const n=t.datum,r=t.channels[0];if(!r||!r.scale||!n)return;const o=r.scale.invertValue(t.pointer.y);if(o==null||Number.isNaN(Number(o)))return;const i=r.scale.domainConfig||(typeof r.scale.domain=="function"?r.scale.domain():null);if(!i||i.length<2){const p=o-n.mean;return{...n,mean:o,lo:n.lo+p,hi:n.hi+p}}const s=Math.min(...i.map(Number)),a=Math.max(...i.map(Number)),l=Number(n.hi)-Number(n.lo);let u=Number(o)-Number(n.mean),c=Number(n.lo)+u,d=Number(n.hi)+u;l>=a-s?(c=s,d=a):(c<s&&(d+=s-c,c=s),d>a&&(c-=d-a,d=a));const f=Number(n.mean)+(c-Number(n.lo));return{...n,mean:f,lo:c,hi:d}},{guide:!0,stage:e})}function X8(e={}){const{question:t="Set your interval",category:n="estimate",mean:r=50,lo:o=30,hi:i=70,domain:s=[0,100],onChange:a,width:l=360,height:u=280,stage:c,theme:d}=e,f=mn(d);return{width:l,height:u,theme:d,margins:{top:40,right:24,bottom:36,left:48},schema:{cat:{type:"categorical",domain:[n]},mean:{type:"quantitative",domain:s},lo:{type:"quantitative",domain:s},hi:{type:"quantitative",domain:s}},data:[{cat:n,mean:r,lo:o,hi:i}],constraints:[Qt({min:s[0],max:s[1],field:"mean"}),Qt({min:s[0],max:s[1],field:"lo"}),Qt({min:s[0],max:s[1],field:"hi"}),G8()],onChange:a,guides:[nn(t)],marks:[ii({id:"ci",parts:[cb({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y1:{field:"lo"},y2:{field:"hi"}}}),Sr({size:f.widget.radius-2,fill:f.widget.accent,channels:{x:{field:"cat"},y:{field:"mean",edit:V8(c)}}}),hs({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y:{field:"lo",edit:Xn({stage:c})}}}),hs({stroke:f.widget.accent,strokeWidth:2,channels:{x:{field:"cat"},y:{field:"hi",edit:Xn({stage:c})}}})]})]}}function J8(e={}){const{question:t="How often?",bins:n=["0-1","1-2","2-3","3-4","4+"],max:r=40,values:o,onChange:i,width:s=480,height:a=280,stage:l,theme:u}=e,c=mn(u),d=n.map((f,p)=>({bin:f,n:o&&o[p]!=null?o[p]:0}));return{width:s,height:a,theme:u,margins:{top:40,right:24,bottom:40,left:40},schema:{bin:{type:"categorical",domain:n},n:{type:"quantitative",domain:[0,r]}},data:d,constraints:[Qt({min:0,max:r,field:"n"})],onChange:i,guides:[nn(t)],marks:[nc({id:"hist",fill:c.widget.accent,fillOpacity:.7,channels:{x:{field:"bin"},y:{field:"n",edit:Xn({guide:!0,stage:l})}}})]}}function Z8(e={}){const{question:t="Drag the region",xDomain:n=[0,10],yDomain:r=[0,10],x1:o=3,x2:i=7,y1:s=3,y2:a=7,onChange:l,width:u=400,height:c=320,stage:d,theme:f}=e,p=mn(f);return{width:u,height:c,theme:f,margins:{top:40,right:24,bottom:36,left:40},schema:{x1:{type:"quantitative",domain:n},x2:{type:"quantitative",domain:n},y1:{type:"quantitative",domain:r},y2:{type:"quantitative",domain:r}},data:[{x1:o,x2:i,y1:s,y2:a}],constraints:[Qt({min:n[0],max:n[1],field:"x1"}),Qt({min:n[0],max:n[1],field:"x2"}),Qt({min:r[0],max:r[1],field:"y1"}),Qt({min:r[0],max:r[1],field:"y2"})],onChange:l,guides:[nn(t)],marks:[Is({id:"region",fill:p.widget.accent,fillOpacity:.35,stroke:p.widget.accent,channels:{x1:{field:"x1"},x2:{field:"x2"},y1:{field:"y1"},y2:{field:"y2"}},edits:[q0({edgeInset:12,stage:d})]})]}}function Q8(e={}){const{question:t="Set the value",domain:n=[0,100],step:r,value:o,onChange:i,width:s=200,height:a=320,stage:l,theme:u}=e,c=mn(u),d=[Qt({min:n[0],max:n[1],field:"value"})];return r&&d.push(Ed({field:"value",step:r,origin:n[0]})),{width:s,height:a,theme:u,margins:{top:40,right:40,bottom:36,left:48},schema:{cat:{type:"categorical",domain:["v"]},value:{type:"quantitative",domain:n}},data:[{cat:"v",value:o??n[0]}],constraints:d,onChange:i,guides:[nn(t)],marks:[nc({id:"thermo",fill:c.widget.accent,fillOpacity:.8,channels:{x:{field:"cat"},y:{field:"value"}},edits:[Xn({pick:"probe",channels:["y"],advance:!1,guide:!0,stage:l})]})]}}function e3(e={}){const{question:t="Set the value",input:n="number",value:r,domain:o=[0,100],label:i="value",onChange:s,width:a=360,height:l=200,stage:u,theme:c}=e,d=mn(c);return n==="text"?{width:a,height:l,theme:c,margins:{top:40,right:24,bottom:24,left:24},schema:{label:{type:"categorical"},x:{type:"quantitative",domain:[0,10]},y:{type:"quantitative",domain:[0,10]}},data:[{x:5,y:5,label:r!=null?String(r):i}],onChange:s,axes:!1,guides:[nn(t)],marks:[Or({id:"label",fontSize:18,fill:d.widget.accent,channels:{x:{field:"x"},y:{field:"y"},text:{field:"label",edit:K0()}},edits:[Xn({channels:["x","y"],stage:u})]})]}:{width:a,height:l,theme:c,margins:{top:40,right:40,bottom:36,left:48},schema:{cat:{type:"categorical",domain:["v"]},n:{type:"quantitative",domain:o}},data:[{cat:"v",n:r??o[0]}],constraints:[Qt({min:o[0],max:o[1],field:"n"})],onChange:s,guides:[nn(t)],marks:[Or({id:"readout",fontSize:22,fill:d.widget.accent,channels:{x:{field:"cat"},y:{field:"n",edit:Xn({guide:!0,stage:u})},text:{field:"n"}}})]}}const t3=Object.freeze(Object.defineProperty({__proto__:null,allocation:K8,histogram:J8,interval:X8,labeledValue:e3,likert:z8,lineCone:H8,matrix:W8,multipleChoice:D8,probabilityTokens:Y8,ranking:U8,region:Z8,slider:j8,thermometer:Q8},Symbol.toStringTag,{value:"Module"})),n3=Object.freeze(Object.defineProperty({__proto__:null,AXIS_CHROME:I5,AXIS_OPTIONS:Q0,AXIS_RADIAL_OPTIONS:Ib,CONSTRAINT_OPTIONS:_0,DEFAULT_PICK_THRESHOLD:Jl,EDIT_OPTIONS:$0,EDIT_UNIVERSAL_OPTIONS:S0,ELEMENT_OPTIONS:As,ELEMENT_UNIVERSAL_OPTIONS:v0,GRID_OPTIONS:od,GUIDE_OPTIONS:Ts,GUIDE_UNIVERSAL_OPTIONS:k0,HANDLE_DEFAULTS:Jf,LEGEND_OPTIONS:ob,LINK_SHAPES:yl,MARK_OPTIONS:st,MARK_SHORTHANDS:x0,MARK_UNIVERSAL_OPTIONS:w0,ORIENT_SPAN:$a,STANDARD_STYLE_CHANNELS:I0,THEME:Ub,anchorsOf:ic,andWhen:Vr,angularBand:mb,arcPath:ps,arcSpan:yd,arcSpine:hl,bandSpan:i0,bandStartOf:Yr,bandwidthOf:yn,baselineOf:yr,categoryOf:Nn,channelDomain:A0,claimEdge:cl,claimPick:Kl,createProjection:m0,defineConstraint:Vt,degToRad:yb,discreteDomain:T0,distanceToMark:us,edgeInsetOf:Zl,encodeAngle:zr,encodeChannel:se,encodeValue:Ft,envelopePolygon:xd,groupByPosition:ad,hitTest:Sa,invertChannel:ho,invertPoint:Fr,isBand:Vn,isDiscrete:fo,isWebMercator:Ob,lineSegment:pl,linearInvert:E0,makeEdit:je,markCenter:Rn,markCommon:lt,markDefaults:It,measureText:qi,mintDatum:Fn,nearestMark:In,nearestMarkOnAxis:td,nearestSeries:Ar,needleTriangle:bb,nestedEnvelopes:kb,nextCategory:Yf,nextSeriesKey:Yl,normalizeMarkOptions:at,noteBox:$n,nudgeTarget:Hu,orientationOf:Zf,paramChannels:md,pickThreshold:Zn,polarToXY:cn,positionalKeys:Xt,projectBounds:b0,projectPoint:ur,rangeExtent:oo,readParams:bd,recenterSpan:Gl,registerDriver:AE,resolveHandles:fn,resolveMarkNode:Pr,resolveStyle:yt,resolveSymbol:cs,resolveValueAxis:kr,sampleCubic:dl,sampleLines:Sb,sampleQuadratic:rc,schemaDefaults:Es,seriesFieldOf:Os,stackDescriptor:ds,stackLayout:tc,symbolNode:Xl,themeOf:it,tileCover:Cb,tileUrl:Nb,valueAt:Cr,warn:ge,warnUnknownElementOptions:Cs,widgetTheme:mn,wrapText:xb},Symbol.toStringTag,{value:"Module"}));let Ii=null;const r3={start:"start",middle:"center",end:"end",left:"left",right:"right",center:"center"},o3={middle:"middle",central:"middle",hanging:"hanging","text-before-edge":"top","text-after-edge":"bottom",alphabetic:"alphabetic",ideographic:"ideographic"};function li(e,t){const n={},r=e.effectStyle;for(const{field:o,base:i}of X0){const s=o in t?t[o]:i;n[o]=r&&r[o]!=null?r[o]:e[o]!=null?e[o]:s}return n}function i3(e,t){if(t==null||t==="none"){e.setLineDash([]);return}if(Array.isArray(t)){e.setLineDash(t);return}e.setLineDash(String(t).split(/[\s,]+/).map(Number).filter(n=>!Number.isNaN(n)))}function Rs(e,t,n){const r=t.opacity!=null?t.opacity:1;t.fill&&t.fill!=="none"&&(e.globalAlpha=r*(t.fillOpacity!=null?t.fillOpacity:1),e.fillStyle=t.fill,n?e.fill(n):e.fill()),t.stroke&&t.stroke!=="none"&&(e.globalAlpha=r*(t.strokeOpacity!=null?t.strokeOpacity:1),e.strokeStyle=t.stroke,e.lineWidth=t.strokeWidth!=null?t.strokeWidth:1,e.lineCap=t.strokeLinecap||"butt",i3(e,t.strokeDasharray),n?e.stroke(n):e.stroke()),e.globalAlpha=1,e.lineCap="butt",e.setLineDash([])}function ci(e,t,n){if(t.angle!=null&&t.angle!==0){const r=Rn(t);if(r){e.save(),e.translate(r.cx,r.cy),e.rotate(-t.angle*Math.PI/180),e.translate(-r.cx,-r.cy),n(),e.restore();return}}n()}function cc(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.r!=null?t.r:5);e.beginPath(),e.arc(t.cx,t.cy,r,0,2*Math.PI),Rs(e,li(t,n))})}function Vb(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.rx!=null?t.rx:5),o=Math.max(0,t.ry!=null?t.ry:5);e.beginPath(),e.ellipse(t.cx,t.cy,r,o,0,0,2*Math.PI),Rs(e,li(t,n))})}function bl(e,t,n){ci(e,t,()=>{const r=Math.max(0,t.height);if(e.beginPath(),t.rx!=null&&typeof e.roundRect=="function"){const o=Math.max(0,t.rx),i=t.ry!=null?Math.max(0,t.ry):o;e.roundRect(t.x,t.y,t.width,r,[o,i])}else e.rect(t.x,t.y,t.width,r);Rs(e,li(t,n))})}function uc(e,t,n){ci(e,t,()=>{e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),Rs(e,li(t,n))})}function fc(e,t,n){let r;t.d?r=new Path2D(t.d):(r=new Path2D,_i().curve(Ni(t.curve)).context(r)(t.points||[])),Rs(e,li(t,n),r)}function Od(e,t,n,r){t.text!=null&&ci(e,t,()=>{const o=li(t,n),i=Ii&&Ii.family||"sans-serif",s=t.fontSize!=null?t.fontSize:Ii&&Ii.size||10;e.font=`${s}px ${i}`,e.textAlign=r3[t.textAnchor||r]||"start",e.textBaseline=o3[t.dominantBaseline]||"alphabetic";const a=Array.isArray(t.lines)?t.lines:[String(t.text)],l=t.lineHeight!=null?t.lineHeight:Math.round(s*1.35),u=t.y-(a.length-1)*l/2,c=o.opacity!=null?o.opacity:1;o.fill&&o.fill!=="none"&&(e.globalAlpha=c*(o.fillOpacity!=null?o.fillOpacity:1),e.fillStyle=o.fill,a.forEach((d,f)=>e.fillText(String(d),t.x,u+f*l))),o.stroke&&o.stroke!=="none"&&(e.globalAlpha=c*(o.strokeOpacity!=null?o.strokeOpacity:1),e.strokeStyle=o.stroke,e.lineWidth=o.strokeWidth!=null?o.strokeWidth:1,a.forEach((d,f)=>e.strokeText(String(d),t.x,u+f*l))),e.globalAlpha=1})}function s3(e,t,n,r){if(!t.href)return;let o=n.get(t.href);if(!o){const i=new Image;o={img:i,ready:!1},i.onload=()=>{o.ready=!0,r()},i.src=t.href,n.set(t.href,o)}o.ready&&ci(e,t,()=>{const i=e.globalAlpha;t.opacity!=null&&(e.globalAlpha=t.opacity),e.drawImage(o.img,t.x,t.y,t.width,t.height),e.globalAlpha=i})}function a3(e,t){switch(t.type){case"path":fc(e,t,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});break;case"rect":bl(e,t,{fill:"black"});break;case"circle":cc(e,t,{fill:"black"});break;case"ellipse":Vb(e,t,{fill:"black"});break;case"line":uc(e,t,{stroke:"black",strokeWidth:1,opacity:1});break;case"text":Od(e,t,{fill:"black",opacity:1},t.editable?"middle":"start");break}}function l3(e,t){switch(t.type){case"line":uc(e,t,{stroke:"black",strokeWidth:1,opacity:1});break;case"circle":cc(e,t,{fill:"none",stroke:"none",strokeWidth:1,opacity:1});break;case"path":fc(e,t,{fill:"none",stroke:"black",strokeWidth:1,opacity:1});break;case"text":Od(e,t,{fill:"black",opacity:1},"start");break}}function c3(e,t){const n={fill:"none",stroke:"none",strokeWidth:1,opacity:1};switch(t.type){case"circle":cc(e,t,n);break;case"rect":bl(e,t,n);break;case"ellipse":Vb(e,t,n);break;case"line":uc(e,t,n);break;case"path":fc(e,t,n);break}}function gy(e,t,n){Ii=n&&n.theme&&n.theme.font||null;const{background:r,guideRegions:o,marks:i,guideFront:s,effects:a}=J0(t);r.filter(l=>l.type==="image").forEach(l=>s3(e,l,n.images,n.requestRepaint));for(const l of r)l.type==="image"||l.type==="path"||(l.type==="rect"?bl(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1}):l.type==="circle"?cc(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1}):l.type==="line"?uc(e,l,{stroke:"#6b7280",strokeWidth:1,opacity:1}):l.type==="text"&&Od(e,l,{fill:"#374151",opacity:1},"middle"));r.filter(l=>l.type==="path").forEach(l=>fc(e,l,{fill:"none",stroke:"black",strokeWidth:1,opacity:1})),o.forEach(l=>bl(e,l,{fill:"none",stroke:"none",strokeWidth:1,opacity:1})),i.forEach(l=>a3(e,l)),s.forEach(l=>l3(e,l)),a.forEach(l=>c3(e,l))}const u3=4,f3=3;function d3(e,t){let n=null,r=null,o=!1;e.style.touchAction="none",e.style.userSelect="none";const i=a=>{const l=t(),u=e.getBoundingClientRect(),c=u.width?l.width/u.width:1,d=u.height?l.height/u.height:1;return[(a.clientX-u.left)*c-l.margins.left,(a.clientY-u.top)*d-l.margins.top]},s=(a,l,u,c=!0)=>{const d=t();n&&(n.mode==="direct"?(d.onEvent({type:"dragend",x:l,y:u,node:n.node,rawEvent:a}),c&&!n.moved&&d.onEvent({type:"click",x:l,y:u,node:n.node,rawEvent:a}),c&&(o=!0)):n.dragging&&(d.onEvent({type:"dragend",x:l,y:u,rawEvent:a}),c&&(o=!0))),n=null;const f=e.getBoundingClientRect();(a.clientX<f.left||a.clientX>f.right||a.clientY<f.top||a.clientY>f.bottom)&&(d.planeOnTop?d.onEvent({type:"hoverout",rawEvent:a}):r!==null&&(r=null,d.onEvent({type:"pointerout",rawEvent:a})))};e.addEventListener("pointerdown",a=>{const l=t(),[u,c]=i(a);if(l.planeOnTop)n={mode:"plane",sx:u,sy:c,dragging:!1};else{const d=Sa(l.scene.children,u,c);if(d)n={mode:"direct",node:d,sx:u,sy:c,moved:!1},l.onEvent({type:"dragstart",x:u,y:c,node:d,rawEvent:a});else{n=null;return}}a.preventDefault();try{e.setPointerCapture(a.pointerId)}catch{}}),e.addEventListener("pointermove",a=>{const l=t(),[u,c]=i(a);if(n&&a.pointerType==="mouse"&&a.buttons===0){s(a,u,c);return}if(!n){if(l.planeOnTop)l.onEvent({type:"hover",x:u,y:c,rawEvent:a}),e.style.cursor=l.planeCursor||"pointer";else{const d=Sa(l.scene.children,u,c),f=d?`${d.featureId}:${d.index}`:null;f!==r&&(r=f,l.onEvent(d?{type:"pointerover",node:d,rawEvent:a}:{type:"pointerout",rawEvent:a})),e.style.cursor=d?d.cursor||"move":"default"}return}n.mode==="direct"?(Math.hypot(u-n.sx,c-n.sy)>u3&&(n.moved=!0),l.onEvent({type:"drag",x:u,y:c,node:n.node,rawEvent:a})):(!n.dragging&&Math.hypot(u-n.sx,c-n.sy)>f3&&(n.dragging=!0,l.onEvent({type:"dragstart",x:n.sx,y:n.sy,rawEvent:a})),n.dragging&&l.onEvent({type:"drag",x:u,y:c,rawEvent:a}))}),e.addEventListener("pointerup",a=>{const[l,u]=i(a);s(a,l,u)}),e.addEventListener("pointercancel",a=>{const[l,u]=i(a);s(a,l,u,!1)}),e.addEventListener("pointerleave",a=>{if(!n){const l=t();l.planeOnTop?l.onEvent({type:"hoverout",rawEvent:a}):r!==null&&(r=null,l.onEvent({type:"pointerout",rawEvent:a}))}}),e.addEventListener("click",a=>{if(o){o=!1;return}const l=t(),[u,c]=i(a);l.onEvent({type:"click",x:u,y:c,rawEvent:a})}),e.addEventListener("dblclick",a=>{const l=t(),[u,c]=i(a),d=l.planeOnTop?null:Sa(l.scene.children,u,c);l.onEvent({type:"dblclick",x:u,y:c,...d?{node:d}:{},rawEvent:a})})}class h3{constructor(){this._canvas=null,this._2d=null,this._ctx=null,this._images=new Map}render(t){const{container:n,scene:r,width:o,height:i,margins:s}=t,a=t.responsive||"fixed";this._ensure(n),this._ctx=t;const l=this._canvas;l.style.background=t.theme&&t.theme.background||"";const u=this._canvas,c=this._2d,d=typeof window<"u"&&window.devicePixelRatio||1,f=Math.round(o*d),p=Math.round(i*d);(u.width!==f||u.height!==p)&&(u.width=f,u.height=p),a==="scale"?(u.style.width="100%",u.style.height="auto"):(u.style.width=`${o}px`,u.style.height=`${i}px`),c.setTransform(d,0,0,d,0,0),c.clearRect(0,0,o,i),c.translate(s.left,s.top),gy(c,r.children,{images:this._images,theme:t.theme,requestRepaint:()=>this._repaint()})}_ensure(t){if(this._canvas&&this._canvas.parentNode===t)return;const n=document.createElement("canvas");n.style.display="block",t.appendChild(n),this._canvas=n,this._2d=n.getContext("2d"),d3(n,()=>this._ctx)}_repaint(){const t=this._ctx,n=this._2d;if(!t||!n)return;const{scene:r,width:o,height:i,margins:s}=t,a=typeof window<"u"&&window.devicePixelRatio||1;n.setTransform(a,0,0,a,0,0),n.clearRect(0,0,o,i),n.translate(s.left,s.top),gy(n,r.children,{images:this._images,theme:t.theme,requestRepaint:()=>this._repaint()})}}const p3={default:{},survey:{ink:"#4f46e5",accent:"#4f46e5",muted:"#94a3b8",font:{family:'"Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif',size:11,labelSize:13,titleSize:15},axis:{stroke:"#cbd5e1",labelFill:"#475569",fontSize:11,handle:"#4f46e5"},grid:{stroke:"#f1f5f9",strokeWidth:1},constraint:{color:"#e11d48"},widget:{accent:"#4f46e5",ring:"#cbd5e1",track:"#e2e8f0",cellFill:"#f8fafc",cellStroke:"#e2e8f0",label:"#475569",question:"#1e293b",labelSize:13,questionSize:15,radius:12}},dark:{background:"#0f172a",ink:"#38bdf8",accent:"#38bdf8",muted:"#64748b",axis:{stroke:"#475569",labelFill:"#cbd5e1",fontSize:10,handle:"#38bdf8"},grid:{stroke:"#1e293b"},guide:{rule:{stroke:"#94a3b8",strokeDasharray:"5 4"},region:{fill:"#94a3b8",opacity:.14},legend:{stroke:"#cbd5e1",labelFill:"#cbd5e1",fontSize:11}},constraint:{color:"#fb7185"},widget:{accent:"#38bdf8",ring:"#334155",track:"#1e293b",cellFill:"#1e293b",cellStroke:"#334155",label:"#cbd5e1",question:"#f1f5f9",labelSize:12,questionSize:13,radius:11}}},y3=Object.freeze(Object.defineProperty({__proto__:null,CanvasRenderer:h3,D3Renderer:Z0,DEFAULT_THEME:Vf,Elicit:ab,authoring:n3,constraints:Hb,edit:_d,elements:_4,format:gA,guides:P8,plot:vd,resolveTheme:Xf,setTheme:T5,setWarnings:YM,themes:p3,widgets:t3},Symbol.toStringTag,{value:"Module"})),jt=e=>e?.__data__,Je={connect:"connect-step",removeStep:"delete-step",removeArrow:"delete-arrow",flip:"flip-arrow",kind:"set-kind",group:"set-group",boxKind:"set-box-kind",external:"set-external"},g3=[["Move a step","drag its box","move({ channels: [x, y] })","writes steps.x and steps.y"],["Draw a dependency","drag from a dot on a box’s edge to another box","network.connect()","appends a row to depends"],["Add a step after one","press the + beside a box","create() + connect()","adds a step and the arrow into it, together"],["Add a step","double-click empty canvas","create()","mints a row with a fresh steps.id"],["Rename a step","double-click a box","editText()","writes steps.label — and the box resizes to fit"],["Label an arrow","double-click an arrow","editText()","writes depends.label"],["Re-point an arrow","drag either arrow end","network.rewire()","rewrites depends.source or .target"],["Flip a dependency","right-click an arrow, then Flip direction","network.reverse()","swaps depends.source and .target"],["Set what an arrow means","right-click an arrow, then pick its kind","commit({ kind })","writes depends.kind"],["Move to a group","right-click a box, then a group; or drag it into the group’s frame","commit({ group })","writes steps.group"],["Delete","select a box or an arrow, then press Delete; or right-click it","remove()","deletes the row — and, via type: ref, every arrow into it"]],m3=[["Move a box","drag it; a folded frame takes what is in it along","move({ channels: [x, y] })","writes boxes.x and boxes.y"],["Draw an arrow","drag from a dot on a box’s edge to another box: the first uses the second","network.connect()","appends a row to arrows"],["Add a box after one","press the + beside a box","create() + connect()","adds a box and the arrow to it, together"],["Add a box","double-click empty canvas","create()","mints a row with a fresh boxes.id"],["Rename a box","double-click it","editText()","writes boxes.label"],["Say what an arrow is for","double-click an arrow","editText()","writes arrows.label"],["Re-point an arrow","drag either end","network.rewire()","rewrites arrows.source or .target"],["Change what a box is","right-click it, then Change kind: a person, service, component, store or queue","commit({ kind })","writes boxes.kind"],["Make an arrow async","right-click it: it does not wait for the answer","commit({ kind })","writes arrows.kind"],["Put a box in a frame","right-click it, then Move into; or drag it into the frame","commit({ group })","writes boxes.group"],["Fold a frame","press the chevron on its name, or right-click the frame","layout.fold","hides what is inside it; its arrows are drawn to it"],["Delete","select a box or an arrow, then press Delete; or right-click it","remove()","deletes the row, and every arrow into it"]],{sticker:b3,link:w3,text:x3}=vd,{move:v3,editText:my,remove:by,network:sa}=_d,{unique:k3}=Hb,Cd=90,wl=60,ln=(e,t)=>typeof document>"u"?t:getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t,Xc=26,Xb=e=>{const t=e==null?"":String(e);if(t.length<=Xc)return t;const n=t.slice(0,Xc-1),r=n.lastIndexOf(" ");return`${(r>Xc/2?n.slice(0,r):n).trimEnd()}…`},Jb=({defaults:e,over:t,prefix:n="step"})=>je({type:"create",gesture:"dblclick",channels:["x","y"],pick:"plane",cardinality:"append",when:r=>!r.data.some(o=>t(o,r.pointer)),apply:r=>{const o=Fn(r,{defaults:e});if(!o)return;const i=new Set(r.data.map(a=>a.id));let s=r.data.length+1;for(;i.has(`${n}-${s}`);)s++;return[...r.data,{...o,id:`${n}-${s}`}]}}),Dn=(e,t)=>Object.defineProperty(t,"name",{value:e}),dr=e=>Dn(`byName(${e})`,t=>t.event?.by===e),No=(e,t)=>je({type:e,name:e,gesture:"commit",pick:"direct",when:dr(e),apply:n=>n.datum&&n.value!==void 0&&n.datum[t]!==n.value?{...n.datum,[t]:n.value}:void 0}),Zb=Object.assign(k3({field:["source","target"],strategy:"reject"}),{table:"links"});function S3(e){const t=Gy(e);return t.length||t.push(Wt),t}const $3=new Set(["approve","ask","input"]);function _3(e,t){return t?.arrow(e)==="yours"?{stroke:Ta.waiting}:{}}function M3(e,{onChange:t,decor:n}){const r=S3(e),o=ln("--ember","#EA5202"),i=ln("--surface","#FFFFFF"),s=ln("--wire","#8F8881"),a=ln("--wire-soft","#C9C3BD"),l=ln("--slate","#69625B"),u=ln("--ink","#19120F"),c=ln("--sans","sans-serif"),d={...Xr,fontFamily:c},{fontSize:f,...p}=d;return{...wr(e),responsive:"scale",focusOutline:!0,axes:!1,margins:{top:wt.y,right:wt.x,bottom:wt.y,left:wt.x},theme:{handle:o,handleStroke:i,background:"transparent",font:{family:c},marks:{text:{fill:u}}},schema:{structure:"network",tables:{steps:{role:"nodes",fields:{id:{type:"categorical",key:!0,open:!0},label:{type:"categorical",open:!0,default:"new step"},group:{type:"categorical",domain:r,open:!0,default:Wt},x:{type:"quantitative",domain:[0,e.canvas.width]},y:{type:"quantitative",domain:[0,e.canvas.height]}}},depends:{role:"links",directed:!0,fields:{source:{type:"ref"},target:{type:"ref"},label:{type:"categorical",open:!0,default:""},kind:{type:"categorical",open:!0,default:"needs"}}}}},data:{steps:e.steps,depends:e.depends},onChange:t,...n?{lock:Dn("frozen",(h,y,g)=>n.frozen(h,g))}:{},constraints:[Zb],marks:[w3({curve:"orthogonal",arrowSize:8,inset:3,stroke:h=>_3(h,n).stroke??(h.kind==="after"?a:s),strokeWidth:h=>$3.has(h.kind)?2.6:h.kind==="after"?1.1:1.4,handleSize:4.5,handleColor:a,fill:l,fontSize:11,labelBackground:i,labelPadding:3,format:Xb,channels:{nodeWidth:{fn:Dn("boxWidth",h=>$n(h.label,d).width)},nodeHeight:{fn:Dn("boxHeight",h=>$n(h.label,d).height)},source:{field:"source",edit:sa.rewire({channel:"source",threshold:wl,when:h=>h.node?.channel==="source"})},target:{field:"target",edit:sa.rewire({channel:"target",threshold:wl,when:h=>h.node?.channel==="target"})},text:{field:"label"}},edits:[sa.reverse({name:Je.flip,when:dr(Je.flip)}),by({name:Je.removeArrow,when:dr(Je.removeArrow)}),No(Je.kind,"kind"),my()]}),b3({...p,radius:7,stroke:n?Dn("statusEdge",h=>n.stroke(h)??s):s,strokeWidth:n?Dn("statusEdgeWidth",h=>n.strokeWidth(h)??1.5):1.5,...n?{opacity:h=>n.opacity(h)}:{},channels:{x:{field:"x",edit:v3({channels:["x","y"],mode:"relative"})},y:{field:"y",scale:{reverse:!0}},text:{field:"label"},fill:{value:i},fontSize:{value:f}},edits:[sa.connect({name:Je.connect,when:dr(Je.connect),threshold:Cd}),No(Je.group,"group"),Jb({defaults:{label:"new step",group:Wt},over:(h,y)=>{const{width:g,height:m}=$n(h.label,d);return Math.abs(y.x-h.x)<=g/2&&Math.abs(y.y-h.y)<=m/2}}),by({name:Je.removeStep,when:dr(Je.removeStep)}),my()]}),...n?[x3({fill:l,fontSize:12,dy:h=>$n(h.label,d).height/2+13,channels:{x:{field:"x"},y:{field:"y",scale:{reverse:!0}},text:{fn:Dn("owner",h=>n.owner(h))}}})]:[]]}}const wy={fine:8,coarse:40},E3={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},On=e=>e?.tagName==="rect"&&!!jt(e)?.data&&"group"in jt(e).data;function A3({frame:e,chart:t,onSelect:n}){e.addEventListener("keydown",i=>{const s=i.target instanceof Element&&On(i.target)?jt(i.target):null;if(!s)return;const a=E3[i.key];if(a){i.preventDefault(),i.stopPropagation();const l=i.shiftKey?wy.coarse:wy.fine,u=s.x+s.width/2,c=s.y+s.height/2,d=t();d.emit({type:"dragstart",node:s,x:u,y:c}),d.emit({type:"drag",node:s,x:u+a[0]*l,y:c+a[1]*l}),d.emit({type:"dragend",node:s,x:u+a[0]*l,y:c+a[1]*l}),T3(e,s.data.id)}else i.key===" "&&n?(i.preventDefault(),i.stopPropagation(),n(s.data.id)):(i.key==="Enter"||i.key==="F2")&&(i.preventDefault(),i.stopPropagation(),i.target.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0})))},!0),e.addEventListener("focusin",i=>{if(!(i.target instanceof Element)||!On(i.target))return;const s=jt(i.target).data;i.target.setAttribute("aria-label",`${s.label}. A step: the arrow keys move it, Enter renames it, Delete removes it, the menu key opens its menu.`)});let r=!1;const o=()=>{r=!1;for(const i of e.querySelectorAll('svg [tabindex="0"]'))On(i)||i.setAttribute("tabindex","-1")};new MutationObserver(()=>{r||(r=!0,requestAnimationFrame(o))}).observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex"]})}function T3(e,t){requestAnimationFrame(()=>{if(e.contains(document.activeElement)&&On(document.activeElement))return;[...e.querySelectorAll("svg rect.mark")].find(r=>jt(r)?.data?.id===t)?.focus()})}const xy={x:90,y:50};function Qb(e,t,n=[]){const r=new Set(n.filter(f=>e.nodes[f]&&Er(e,f))),o=f=>I1(e,f,r),i=new Set;for(const f of Object.keys(e.nodes))Ky(e,f).some(p=>r.has(p))&&i.add(f);const s=[],a=[],l=new Map;for(const[f,p]of Object.entries(e.nodes)){if(i.has(f))continue;const h={id:f,label:p.label,kind:p.kind,external:!!p.external,...p.tech?{tech:p.tech}:{},...p.in?{parent:p.in}:{}},y=p.in??Wt;if(!Er(e,f)){s.push(vy(f,p,y,t.nodes[f]??xy));continue}if(!r.has(f)){a.push(h);continue}const g=Oa(e,f).filter(b=>t.nodes[b]),m=g.length?{x:Math.round(g.reduce((b,w)=>b+t.nodes[w].x,0)/g.length),y:Math.round(g.reduce((b,w)=>b+t.nodes[w].y,0)/g.length)}:xy;l.set(f,{count:Oa(e,f).filter(b=>!Er(e,b)).length}),s.push(vy(f,p,y,m))}const u=new Map,c=new Set;for(const f of e.edges){const p=o(f.from),h=o(f.to);if(p===h)continue;const y=`${p}\0${h}`,g=u.get(y);if((p!==f.from||h!==f.to)&&c.add(y),g){g.n++,g.async+=f.async?1:0,g.label=`${g.n} arrows`,g.tech="";continue}u.set(y,{source:p,target:h,label:f.label??"",kind:"needs",tech:f.tech??"",n:1,async:f.async?1:0})}const d=[...u.values()].map(({n:f,async:p,...h})=>({...h,kind:p===f?"async":"needs"}));return{steps:s,depends:d,lifted:c,folded:l,frames:a,hidden:i,stand:o}}const vy=(e,t,n,r)=>({id:e,label:t.label,group:n,kind:t.kind,external:t.external?"yes":"",x:r.x,y:r.y});function ky(e,t,n){const r=typeof n=="function"?n:a=>n.get(a),o=new Map,i=(a,l)=>{const u=o.get(a.id);if(u)return u;if(l.has(a.id))return null;l.add(a.id);const c=t.filter(m=>m.group===a.id).map(m=>m.id),d=[];for(const m of c){const b=r(m);b&&d.push({x:b.x-b.w/2,y:b.y-b.h/2,w:b.w,h:b.h})}for(const m of e.filter(b=>b.parent===a.id)){const b=i(m,l);b&&(d.push({x:b.x,y:b.y,w:b.w,h:b.h}),c.push(...b.members))}if(l.delete(a.id),!d.length)return null;const f=Math.min(...d.map(m=>m.x))-Eo.left,p=Math.max(...d.map(m=>m.x+m.w))+Eo.right,h=Math.min(...d.map(m=>m.y))-Eo.top,y=Math.max(...d.map(m=>m.y+m.h))+Eo.bottom,g={x:f,y:h,w:p-f,h:y-h,members:c};return o.set(a.id,g),g};for(const a of e)i(a,new Set);const s=a=>{let l=0;for(let u=a.parent;u;u=e.find(c=>c.id===u)?.parent)l++;return l};return e.filter(a=>o.has(a.id)).map(a=>({...a,group:a.id,depth:s(a),...o.get(a.id)})).sort((a,l)=>a.depth-l.depth)}class Hi extends Error{}const _a={label:"new box",kind:"service",external:"",group:Wt},Sy={width:300,height:180};function Mo({arch:e,layout:t},{headroom:n=!0}={}){const r=Qb(e,t,t.collapsed??[]),o=t.canvas??{width:640,height:240};return{id:"architecture",title:e.title,plan:e.title,repo:"",source:e.source?.url??"",direction:t.direction,note:e.goal??"",canvas:n?{width:o.width+Sy.width,height:o.height+Sy.height}:o,steps:r.steps,depends:r.depends,proj:r}}function e1(e,t,n){const r=Qb(e,t,t.collapsed??[]),o=structuredClone(e),i=[],s=new Set(n.steps.map(h=>h.id)),a=new Map(r.steps.map(h=>[h.id,h]));for(const h of a.keys())if(!s.has(h)){if(r.folded.has(h))throw new Hi(`${e.nodes[h].label} is a folded frame: it stands for everything in it. Unfold it, and take away what you mean to.`);delete o.nodes[h];for(const y of o.flows)y.steps=y.steps.filter(g=>g.from!==h&&g.to!==h)}for(const h of n.steps){const y=a.get(h.id),g=o.nodes[h.id];if(!y||!g){const x={label:h.label,kind:h.kind||_a.kind};h.external&&(x.external=!0),h.group&&h.group!==Wt&&(x.in=h.group),o.nodes[h.id]=x,i.push({id:h.id,x:Math.round(h.x),y:Math.round(h.y)});continue}h.label!==g.label&&(g.label=h.label),h.kind&&h.kind!==g.kind&&(g.kind=h.kind),!!h.external!=!!g.external&&(h.external?g.external=!0:delete g.external);const m=h.group===Wt||!h.group?void 0:h.group;m!==g.in&&(m?g.in=m:delete g.in);const b=Math.round(h.x)-Math.round(y.x),w=Math.round(h.y)-Math.round(y.y);if(!(!b&&!w))if(r.folded.has(h.id))for(const x of Oa(e,h.id))t.nodes[x]&&i.push({id:x,x:Math.round(t.nodes[x].x)+b,y:Math.round(t.nodes[x].y)+w});else i.push({id:h.id,x:Math.round(h.x),y:Math.round(h.y)})}const l=h=>`${h.from}\0${h.to}`,u=h=>r.stand(h.from)===h.from&&r.stand(h.to)===h.to,c=e.edges.filter(h=>!u(h));new Set(n.depends.map(h=>`${h.source}\0${h.target}`));for(const h of r.lifted){const[y,g]=h.split("\0"),m=n.depends.find(w=>w.source===y&&w.target===g),b=r.depends.find(w=>w.source===y&&w.target===g);if(!m||m.label!==b?.label||m.kind==="async"!=(b?.kind==="async"))throw new Hi(`That arrow stands for the arrows inside a folded frame, and cannot be changed from here. Unfold ${e.nodes[y]?.label??y} or ${e.nodes[g]?.label??g} to change them.`)}const d=[];for(const h of n.depends){if(r.lifted.has(`${h.source}\0${h.target}`))continue;const y=e.edges.find(m=>m.from===h.source&&m.to===h.target)??e.edges.find(m=>m.from===h.target&&m.to===h.source),g={from:h.source,to:h.target};h.label&&(g.label=h.label),h.tech&&(g.tech=h.tech),h.kind==="async"&&(g.async=!0),y?.via&&(g.via=y.via),y?.planned&&(g.planned=y.planned),y?.retiring&&(g.retiring=y.retiring),d.push(g)}o.edges=[...c,...d].filter(h=>h.from in o.nodes&&h.to in o.nodes);const f=new Map(e.edges.map((h,y)=>[l(h),y]));o.edges.sort((h,y)=>(f.get(l(h))??1e9)-(f.get(l(y))??1e9));for(const h of o.edges)h.via&&!(h.via in o.nodes)&&delete h.via;const p=Vy(o);if(p.length)throw new Hi(p[0]);return{after:o,placements:i}}function O3(e,t){const{after:n,placements:r}=e1(e.arch,e.layout,t),{ops:o}=pg(e.arch,n);for(const i of r){const s=e.layout.nodes[i.id];n.nodes[i.id]&&(!s||Math.round(s.x)!==i.x||Math.round(s.y)!==i.y)&&o.push({op:"layout.place",id:i.id,x:i.x,y:i.y})}return o}function C3(e){const t=Mo(e,{headroom:!1});return{...t,steps:t.steps.map(n=>({...n,group:n.group===Wt?n.group:e.arch.nodes[n.group]?.label??n.group}))}}const Jc={untouched:.4,offFlow:.22};function N3(e){const t=i=>e()?.arch.nodes[i],n=i=>{const s=e();return s?.footprint&&t(i)?L1(s.arch,s.footprint,i):null},r=()=>{const i=e();if(!i?.flow)return null;const s=new Set;for(const a of i.flow)s.add(i.stand(a.from)),s.add(i.stand(a.to));return s},o=i=>{const s=t(i);return s?.planned?"planned":s?.retiring?"retiring":null};return{edge(i){const s=n(i);return s==="new"||s==="changed"||s==="removed"?{colour:Br[s].colour,width:2.6,dashed:s==="new"||s==="removed"}:o(i)?{width:1.6,dashed:!0}:{width:1.5,dashed:!1}},opacity(i){const s=r();return s?s.has(i)?1:Jc.offFlow:n(i)==="untouched"?Jc.untouched:1},look(i){const s=n(i);if(s==="new"||s==="changed"||s==="removed")return{...Br[s],strike:s==="removed"};const a=o(i);return a==="planned"?{...Br.new,word:t(i)?.planned==="next"?"planned":`planned by ${t(i)?.planned}`,strike:!1}:a==="retiring"?{...Br.removed,word:`retiring: ${t(i)?.retiring} removes it`,strike:!1}:null},caption(i,s){const a=e(),l=[],u=a?.folded.get(i);u&&l.push(`${u.count} inside`);const c=a?.footprint?.changed.get(i);return c?.length&&l.push(c.length===1?`changed by ${s?.[c[0]]??c[0]}`:`changed by ${c.length} steps`),l.join(" · ")},arrow(i){const s=e();if(!s)return{opacity:1};const a=`${i.source}\0${i.target}`,l=s.flow,c=(l?l.some(f=>s.stand(f.from)===i.source&&s.stand(f.to)===i.target||s.stand(f.from)===i.target&&s.stand(f.to)===i.source):!0)?1:Jc.offFlow;if(s.footprint?.addedArrows.has(a))return{stroke:Ta.done,opacity:c,dashed:!0};if(s.footprint?.removedArrows.has(a))return{stroke:Ta.failed,opacity:c,dashed:!0};const d=s.arch.edges.find(f=>`${f.from}\0${f.to}`===a);return{opacity:c,...d?.planned||d?.retiring?{dashed:!0}:{}}}}}const{sticker:I3,link:L3,text:F3}=vd,{move:R3,editText:$y,remove:_y,network:aa}=_d;function P3(e,{onChange:t,decor:n,stepLabel:r}){const o=[Wt,...e.proj.frames.map(g=>g.id)],i=ln("--ember","#EA5202"),s=ln("--surface","#FFFFFF"),a=ln("--wire","#8F8881"),l=ln("--wire-soft","#C9C3BD"),u=ln("--slate","#69625B"),c=ln("--ink","#19120F"),d=ln("--sans","sans-serif"),f={...Xr,fontFamily:d},{fontSize:p,...h}=f,y=g=>r?.(g);return{...wr(e),responsive:"scale",focusOutline:!0,axes:!1,margins:{top:wt.y,right:wt.x,bottom:wt.y,left:wt.x},theme:{handle:i,handleStroke:s,background:"transparent",font:{family:d},marks:{text:{fill:c}}},schema:{structure:"network",tables:{steps:{role:"nodes",fields:{id:{type:"categorical",key:!0,open:!0},label:{type:"categorical",open:!0,default:_a.label},group:{type:"categorical",domain:o,open:!0,default:Wt},kind:{type:"categorical",open:!0,default:_a.kind},external:{type:"categorical",open:!0,default:""},x:{type:"quantitative",domain:[0,e.canvas.width]},y:{type:"quantitative",domain:[0,e.canvas.height]}}},depends:{role:"links",directed:!0,fields:{source:{type:"ref"},target:{type:"ref"},label:{type:"categorical",open:!0,default:""},kind:{type:"categorical",open:!0,default:"needs"},tech:{type:"categorical",open:!0,default:""}}}}},data:{steps:e.steps,depends:e.depends},onChange:t,constraints:[Zb],marks:[L3({curve:"orthogonal",arrowSize:8,inset:3,stroke:g=>n?.arrow({source:g.source,target:g.target}).stroke??(g.kind==="async"?l:a),strokeWidth:g=>n?.arrow({source:g.source,target:g.target}).stroke?2.2:g.kind==="async"?1.2:1.4,...n?{opacity:g=>n.arrow({source:g.source,target:g.target}).opacity}:{},handleSize:4.5,handleColor:l,fill:u,fontSize:11,labelBackground:s,labelPadding:3,format:Xb,channels:{nodeWidth:{fn:Dn("boxWidth",g=>$n(g.label,f).width)},nodeHeight:{fn:Dn("boxHeight",g=>$n(g.label,f).height)},source:{field:"source",edit:aa.rewire({channel:"source",threshold:wl,when:g=>g.node?.channel==="source"})},target:{field:"target",edit:aa.rewire({channel:"target",threshold:wl,when:g=>g.node?.channel==="target"})},text:{field:"label"}},edits:[aa.reverse({name:Je.flip,when:dr(Je.flip)}),_y({name:Je.removeArrow,when:dr(Je.removeArrow)}),No(Je.kind,"kind"),$y()]}),I3({...h,radius:7,stroke:"transparent",fill:"transparent",strokeWidth:0,...n?{opacity:g=>n.opacity(g.id)}:{},channels:{x:{field:"x",edit:R3({channels:["x","y"],mode:"relative"})},y:{field:"y",scale:{reverse:!0}},text:{field:"label"},fill:{value:"transparent"},fontSize:{value:p}},edits:[aa.connect({name:Je.connect,when:dr(Je.connect),threshold:Cd}),No(Je.group,"group"),No(Je.boxKind,"kind"),No(Je.external,"external"),Jb({prefix:"box",defaults:{..._a},over:(g,m)=>{const{width:b,height:w}=$n(g.label,f);return Math.abs(m.x-g.x)<=b/2&&Math.abs(m.y-g.y)<=w/2}}),_y({name:Je.removeStep,when:dr(Je.removeStep)}),$y()]}),...n?[F3({fill:u,fontSize:12,dy:g=>$n(g.label,f).height/2+13,...n?{opacity:g=>n.opacity(g.id)}:{},channels:{x:{field:"x"},y:{field:"y",scale:{reverse:!0}},text:{fn:Dn("caption",g=>n.caption(g.id,new Proxy({},{get:(m,b)=>y(String(b))})))}}})]:[]]}}const z3="http://www.w3.org/2000/svg";function ht(e,t={},n){const r=document.createElementNS(z3,e);for(const[o,i]of Object.entries(t))r.setAttribute(o,String(i));return n!==void 0&&(r.innerHTML=n),r}const Ui=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]??t),_n=(e,t)=>getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t;function jn(e){const t=_n("--sans","sans-serif");return e.map(n=>{const{width:r,height:o}=$n(n.label,{...Xr,fontFamily:t});return{id:n.id,group:n.group,x:n.x+wt.x,y:n.y+wt.y,w:r,h:o}})}function dc(e,t,n){e.querySelector(`:scope > .${t}`)?.remove();const{width:r,height:o}=wr({canvas:n});return ht("svg",{class:t,viewBox:`0 0 ${r} ${o}`,"aria-hidden":"true"})}function D3(e,t,n,r=null){if(!e)return;const o=dc(e,"frames",n),i=_n("--ember","#EA5202");for(const s of Xy(t)){const a=s.group===r,l=ht("g",{"data-group":s.group}),u=s.members.length===1&&!a;u||l.appendChild(ht("rect",{x:s.x,y:s.y,width:s.w,height:s.h,rx:10,fill:"var(--frame)",stroke:a?i:"var(--frame-edge)","stroke-width":a?2.2:1.2,...a?{"stroke-dasharray":"6 4"}:{}})),l.appendChild(ht("text",u?{x:s.x+Eo.left+16,y:s.y+Eo.top-5,class:"frame-name","font-size":10.5,"font-weight":600,fill:"var(--slate)",opacity:.85}:{x:s.x+12,y:s.y+19,class:"frame-name","font-size":11.5,"font-weight":600,fill:"var(--slate)"},Ui(Jy(s.group,u?s.w+60:s.w)))),o.appendChild(l)}e.prepend(o)}const j3=e=>22+e.length*5.7;function ef(e,t){const n=e instanceof SVGSVGElement?e:e.querySelector("svg"),r=new Map;for(const s of e.querySelectorAll("path")){const a=jt(s)?.data;if(!a||a.source===void 0||a.target===void 0)continue;const l=s.getAttribute("fill");if(l&&l!=="none")continue;const u=s.getTotalLength?.()??0,c=`${a.source}\0${a.target}`;u>(r.get(c)?.len??0)&&r.set(c,{path:s,len:u})}const o=new Map,i=n?.getScreenCTM()?.inverse();if(!i)return o;for(const s of t){const a=`${s.source}\0${s.target}`,l=r.get(a);if(!l||l.len<18)continue;const u=l.path.getPointAtLength(s.label?Math.min(16,l.len*.2):l.len*.5),c=l.path.getScreenCTM();if(!c)continue;const d=new DOMPoint(u.x,u.y).matrixTransform(i.multiply(c));o.set(a,{x:d.x,y:d.y})}return o}function t1(e,{items:t,look:n,arrows:r,size:o}){if(!e)return;const i=dc(e,"marks",o),s=_n("--ink","#19120F"),a=_n("--surface","#FFFFFF"),l=_n("--slate","#69625B");for(const c of t){const d=n(c.id);if(!d)continue;const f=c.x-c.w/2,p=c.x+c.w/2,h=c.y-c.h/2;if(d.strike&&i.appendChild(ht("path",{d:`M${f+7} ${c.y} H${p-7}`,stroke:s,"stroke-width":1.6,"stroke-linecap":"round",opacity:.8})),d.icon){const g=ht("g",{transform:`translate(${f+1} ${h-1})`,class:"chip","data-status":d.word??""});g.appendChild(ht("title",{},Ui(d.word??""))),g.appendChild(ht("circle",{r:9,fill:d.colour??l,stroke:a,"stroke-width":2})),g.appendChild(ht("g",{transform:"translate(-6 -6)",color:"#FFFFFF"},fa(d.icon))),i.appendChild(g)}[d.review?["question","review"]:null,d.atRisk?["exclaim","at risk"]:null].filter(Boolean).forEach((g,m)=>{const[b,w]=g,x=j3(w),S=ht("g",{transform:`translate(${p-x+10} ${h-9-m*19})`,class:"pill","data-badge":w});S.appendChild(ht("rect",{width:x,height:16,rx:8,fill:a,stroke:s,"stroke-width":1})),S.appendChild(ht("g",{transform:"translate(3 2)",color:s},fa(b))),S.appendChild(ht("text",{x:18,y:11.5,"font-size":10.5,"font-weight":600,fill:s},Ui(w))),i.appendChild(S)})}const u=Ta.waiting;for(const c of r){const d=c.icon??ff[c.kind];if(d){const f=ht("g",{transform:`translate(${c.x} ${c.y})`,class:"gate","data-kind":c.kind,...c.yours?{"data-yours":""}:{}});f.appendChild(ht("circle",{r:9,fill:a,stroke:c.yours?u:"var(--wire)","stroke-width":c.yours?2.4:1.5})),f.appendChild(ht("g",{transform:"translate(-6 -6)",color:c.yours?u:s},fa(d))),i.appendChild(f)}c.tech&&i.appendChild(ht("text",{class:"arrow-tech",x:c.x,y:c.y+(d?21:15),"text-anchor":"middle","font-size":10,fill:l,stroke:a,"stroke-width":3,"paint-order":"stroke"},Ui(c.tech)))}e.insertBefore(i,e.querySelector(":scope > .ghost"))}function W3(e,{frames:t,boxes:n,decor:r,size:o,dropping:i=null}){if(!e)return;const s=dc(e,"frames",o),a=_n("--ember","#EA5202"),l=_n("--surface","#FFFFFF"),u=_n("--wire","#8F8881"),c=_n("--ext-fill","#ECE9E5"),d="6 4";for(const f of t){const p=f.id===i,h=r.edge(f.id),y=ht("g",{"data-group":f.id,class:"frame",opacity:r.opacity(f.id)}),g=p?a:h.colour??"var(--frame-edge)",m=p||h.dashed||f.kind==="group";y.appendChild(ht("rect",{x:f.x,y:f.y,width:f.w,height:f.h,rx:12,fill:f.external?c:"var(--frame)",stroke:g,"stroke-width":p?2.2:h.colour?h.width:1.2,...m?{"stroke-dasharray":d}:{}})),y.appendChild(ht("text",{x:f.x+12,y:f.y+19,class:"frame-name","font-size":11.5,"font-weight":600,fill:"var(--slate)"},Ui(Jy(f.label,f.w-40)))),s.appendChild(y)}for(const f of n){const p=r.edge(f.id),h=ht("g",{class:"shape","data-id":f.id,"data-kind":f.kind,opacity:r.opacity(f.id)});for(const y of F1(f.kind,f,{folded:f.folded})){const{dashed:g,...m}=y.attrs,b=y.role==="line";h.appendChild(ht(y.tag,{...m,class:`part ${y.role}`,fill:b?"none":f.external?c:l,stroke:p.colour??u,"stroke-width":p.width,"stroke-linejoin":"round",...g||p.dashed?{"stroke-dasharray":d}:{}}))}s.appendChild(h)}e.prepend(s)}function n1(e,t){for(const n of e.querySelectorAll("path")){const r=jt(n)?.data;if(!r||r.source===void 0||r.target===void 0)continue;const o=n.getAttribute("stroke");if(!o||o==="transparent"||o==="none")continue;const i=n.getAttribute("fill");i&&i!=="none"||(t(r)?n.setAttribute("stroke-dasharray","6 4"):n.removeAttribute("stroke-dasharray"))}}function q3(e,{steps:t,size:n}){if(!e)return;const r=dc(e,"flow",n),o=_n("--ember","#EA5202"),i=_n("--surface","#FFFFFF"),s=_n("--slate","#69625B");for(const a of t){a.gap&&r.appendChild(ht("path",{d:`M${a.gap.from.x} ${a.gap.from.y} L${a.gap.to.x} ${a.gap.to.y}`,stroke:a.current?o:s,"stroke-width":a.current?2.4:1.4,"stroke-dasharray":"5 4",fill:"none",opacity:a.current?1:.7}));const l=ht("g",{transform:`translate(${a.x} ${a.y})`,class:`flow-chip${a.current?" current":""}`,"data-step":a.n});l.appendChild(ht("circle",{r:a.current?11:9,fill:a.current?o:i,stroke:a.current?i:s,"stroke-width":a.current?2:1.4})),l.appendChild(ht("text",{x:0,y:4,"text-anchor":"middle","font-size":a.current?11.5:10.5,"font-weight":700,fill:a.current?"#FFFFFF":s},`${a.n}${a.gap?"?":a.reply?"↩":""}`)),r.appendChild(l)}e.insertBefore(r,e.querySelector(":scope > .ghost"))}const B3=[{kind:"needs",label:"Needs",hint:"it uses what comes before"},{kind:"after",label:"After",hint:"order only"},{kind:"approve",label:"Approve first",hint:"you approve the step before"},{kind:"ask",label:"Ask first",hint:"the agent asks you"},{kind:"input",label:"Needs your input",hint:"it waits for something from you"}],H3="finished work is history: reopen the step first";function U3(e,{groups:t=[],group:n,kind:r="needs",frozen:o=!1}={}){const i=o?H3:void 0;if(e.type==="canvas")return[{id:"add",label:"Add a step here"}];if(e.type==="step"){const s=n&&n!==Wt?n:void 0,a=t.filter(l=>l!==Wt);return[{id:"rename",label:"Rename",key:"Enter",disabled:i},...a.map((l,u)=>({id:`group:${l}`,label:l,checked:l===s,disabled:i,...u===0?{section:"Move to group"}:{}})),{id:"group:top",label:"No group",checked:!s,disabled:i,...a.length?{}:{section:"Move to group"}},{id:"group:new",label:"New group…",disabled:i,ask:"Name the group"},{id:"delete",label:"Delete",key:"Delete",danger:!0,disabled:i,section:" "}]}return[{id:"label",label:"Label…",disabled:i},{id:"flip",label:"Flip direction",disabled:i},...B3.map((s,a)=>({id:`kind:${s.kind}`,label:s.label,hint:s.hint,checked:s.kind===r,disabled:i,...a===0?{section:"This arrow means"}:{}})),{id:"delete",label:"Delete",key:"Delete",danger:!0,disabled:i,section:" "}]}const K3=[{kind:"needs",label:"Waits for the answer",hint:"a call"},{kind:"async",label:"Does not wait",hint:"an event or a message"}];function la(e,{kind:t,external:n=!1,group:r,frames:o=[],folded:i=!1,container:s=!1,plan:a=null}={}){if(e.type==="canvas")return[{id:"add",label:"Add a box here"}];const l=(d,f)=>[...o.filter(p=>p.id!==d).map((p,h)=>({id:`${f}${p.id}`,label:p.label,checked:p.id===r,...h===0?{section:"Move into"}:{}})),{id:`${f}top`,label:"Nothing: top level",checked:!r||r===Wt,...o.filter(p=>p.id!==d).length?{}:{section:"Move into"}},{id:`${f}new`,label:"A new frame…",ask:"Name the frame"}],u=a?[{id:"plan:planned",label:`Planned by ${a.id}`,hint:"it does not exist yet",checked:a.planned,section:`For the plan ${a.id}`},{id:"plan:retiring",label:`Removed by ${a.id}`,hint:"it goes when the plan is done",checked:a.retiring}]:[];if(e.type==="arrow")return[{id:"label",label:"Label…"},{id:"flip",label:"Flip direction",hint:"who uses whom"},...K3.map((d,f)=>({id:`kind:${d.kind}`,label:d.label,hint:d.hint,checked:d.kind===(t??"needs"),...f===0?{section:"This arrow"}:{}})),{id:"delete",label:"Delete",key:"Delete",danger:!0,section:" "}];const c=d=>Object.keys(da).map((f,p)=>({id:`${d}${f}`,label:da[f],checked:f===t,...s&&f!=="service"&&f!=="group"?{disabled:"it holds boxes: take them out first"}:{},...p===0?{section:"Change kind"}:{}}));return e.type==="frame"?[{id:"fold",label:i?"Unfold":"Fold",hint:i?"show what is inside":"hide what is inside"},{id:"rename",label:"Rename…",ask:"Rename the frame"},...["service","group"].map((d,f)=>({id:`frame-kind:${d}`,label:da[d],checked:d===t,...f===0?{section:"It is a"}:{}})),{id:n?"external:off":"external:on",label:"Someone else runs it",checked:n},...l(e.id??"","into:"),{id:"delete",label:"Remove the frame",hint:"what is inside stays",danger:!0,section:" "}]:[...i?[{id:"fold",label:"Unfold",hint:"show what is inside"}]:[],{id:"rename",label:"Rename",key:"Enter"},...c("boxkind:"),{id:n?"external:off":"external:on",label:"Someone else runs it",checked:n,section:" "},...l(e.id??"","into:"),...u,{id:"delete",label:"Delete",key:"Delete",danger:!0,section:" "}]}const Y3="http://www.w3.org/2000/svg";function bn(e,t={},n){const r=document.createElementNS(Y3,e);for(const[o,i]of Object.entries(t))r.setAttribute(o,String(i));return n!==void 0&&(r.textContent=n),r}const Zc=(e,t)=>getComputedStyle(document.documentElement).getPropertyValue(e).trim()||t;function My(e,t){if(Math.abs(t.x-e.x)*.6>=Math.abs(t.y-e.y)){const a=t.x>=e.x?1:-1,l=e.x+a*e.w/2,u=t.x-a*t.w/2,c=(l+u)/2;return`M${l} ${e.y} H${c} V${t.y} H${u}`}const r=t.y>=e.y?1:-1,o=e.y+r*e.h/2,i=t.y-r*t.h/2,s=(o+i)/2;return`M${e.x} ${o} V${s} H${t.x} V${i}`}const Ey=(e,t,n=10)=>Math.abs(e.x-t.x)<(e.w+t.w)/2+n&&Math.abs(e.y-t.y)<(e.h+t.h)/2+n;function r1(e,t){if(!t.some(n=>Ey(e,n)))return e;for(let n=1;n<=8;n++)for(const r of[1,-1]){const o={...e,y:e.y+r*n*(e.h+14)};if(o.y-o.h/2>=0&&!t.some(i=>Ey(o,i)))return o}return e}function xl(e,t,n,r,o,i=null){e?.querySelector(":scope > .ghost")?.remove();const s=t&&t.applies?t:null;if(!e||!s&&!i)return null;t=s??{applies:!0,addedNodes:[],addedEdges:[],removedNodes:[],removedEdges:[],changedNodes:[]};const l=Zc("--ember","#EA5202"),u=Zc("--ember-deep","#B53D00"),c=Zc("--sans","sans-serif"),d=v=>$n(v,{...Xr,fontFamily:c}),f=new Map;for(const[v,k]of Object.entries(n.nodes)){const _=r.nodes[v];if(!_)continue;const{width:T,height:L}=d(k.label);f.set(v,{x:_.x+wt.x,y:_.y+wt.y,w:T,h:L})}const p=[...f.values()];for(const v of t.addedNodes){const{width:k,height:_}=d(v.label),T=r1({x:v.x+wt.x,y:v.y+wt.y,w:k,h:_},p);p.push(T),f.set(v.id,T)}const h=bn("svg",{class:"ghost",viewBox:`0 0 ${wr({canvas:o}).width} ${wr({canvas:o}).height}`,"aria-hidden":"true"});h.appendChild(bn("defs")).innerHTML=[l,u].map((v,k)=>`<marker id="ghost-head-${k}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="${v}"/></marker>`).join("");const y=[],g=(v,k,_=4)=>bn("rect",{x:v.x-v.w/2-_,y:v.y-v.h/2-_,width:v.w+_*2,height:v.h+_*2,rx:9,fill:"none",stroke:k,"stroke-width":1.6,"stroke-dasharray":"5 3"});for(const v of t.removedEdges){const k=f.get(v.from),_=f.get(v.to);k&&_&&y.push(k,_),k&&_&&h.appendChild(bn("path",{d:My(k,_),fill:"none",stroke:u,"stroke-width":3,"stroke-dasharray":"2 5",opacity:.85}))}for(const v of t.removedNodes){const k=f.get(v);k&&(y.push(k),h.appendChild(g(k,u)),h.appendChild(bn("path",{d:`M${k.x-k.w/2} ${k.y-k.h/2} L${k.x+k.w/2} ${k.y+k.h/2} M${k.x+k.w/2} ${k.y-k.h/2} L${k.x-k.w/2} ${k.y+k.h/2}`,stroke:u,"stroke-width":1.6,opacity:.7})))}for(const v of t.changedNodes){const k=f.get(v.id);if(k&&(y.push(k),h.appendChild(g(k,l)),v.label!==void 0)){const _=d(v.label),T=bn("g",{transform:`translate(${k.x} ${k.y+k.h/2+15})`});T.appendChild(bn("rect",{x:-_.width/2,y:-10,width:_.width,height:20,rx:6,fill:l})),T.appendChild(bn("text",{x:0,y:4,"text-anchor":"middle","font-size":11,"font-family":c,"font-style":"italic",fill:"#FFFFFF"},v.label)),h.appendChild(T)}}for(const v of t.addedEdges){const k=f.get(v.from),_=f.get(v.to);k&&_&&y.push(k,_),k&&_&&h.appendChild(bn("path",{d:My(k,_),fill:"none",stroke:l,"stroke-width":1.8,"stroke-dasharray":"6 4","marker-end":"url(#ghost-head-0)"}))}for(const v of t.addedNodes){const k=f.get(v.id);k&&(y.push(k),h.appendChild(bn("rect",{x:k.x-k.w/2,y:k.y-k.h/2,width:k.w,height:k.h,rx:7,fill:l,"fill-opacity":.12,stroke:l,"stroke-width":1.6,"stroke-dasharray":"5 3"})),h.appendChild(bn("text",{x:k.x,y:k.y+4,"text-anchor":"middle","font-size":Xr.fontSize,"font-family":c,fill:u},v.label.length>26?`${v.label.slice(0,25)}…`:v.label)))}const m=i?f.get(i):void 0;if(m&&h.appendChild(bn("rect",{x:m.x-m.w/2-5,y:m.y-m.h/2-5,width:m.w+10,height:m.h+10,rx:10,fill:"none",stroke:l,"stroke-width":2.4})),e.appendChild(h),!s||!y.length)return null;const b=Math.min(...y.map(v=>v.x-v.w/2)),w=Math.max(...y.map(v=>v.x+v.w/2)),x=Math.min(...y.map(v=>v.y-v.h/2)),S=Math.max(...y.map(v=>v.y+v.h/2));return{x:b,y:x,w:w-b,h:S-x}}const G3=["label","group","x","y","kind","external"],Ay=e=>typeof e=="number"?Math.round(e):e;function tf(e,t){const n=new Map(e.steps.map(y=>[y.id,y])),r=new Map(t.steps.map(y=>[y.id,y])),o=[],i=[];for(const[y,g]of r){const m=n.get(y);if(!m){o.push(g);continue}const b={};for(const w of G3)Ay(m[w])!==Ay(g[w])&&(b[w]=g[w]);Object.keys(b).length&&i.push({id:y,...b})}const s=[...n.keys()].filter(y=>!r.has(y)),a=y=>`${y.source}\0${y.target}`,l=new Map(e.depends.map(y=>[a(y),y])),u=new Map(t.depends.map(y=>[a(y),y])),c=new Set(s),d=[],f=[];for(const[y,g]of u){const m=l.get(y);m?((m.label??"")!==(g.label??"")||(m.kind??"needs")!==(g.kind??"needs")||(m.tech??"")!==(g.tech??""))&&f.push({source:g.source,target:g.target,label:g.label,kind:g.kind??"needs",...g.tech!==void 0?{tech:g.tech}:{}}):d.push(g)}const p=[...l].filter(([y,g])=>!u.has(y)&&!c.has(g.source)&&!c.has(g.target)).map(([,y])=>({source:y.source,target:y.target})),h={};return(o.length||i.length||s.length)&&(h.steps={...o.length?{insert:o}:{},...i.length?{update:i}:{},...s.length?{remove:s}:{}}),(d.length||f.length||p.length)&&(h.depends={...d.length?{insert:d}:{},...f.length?{update:f}:{},...p.length?{remove:p}:{}}),Object.keys(h).length?h:null}const V3=new Set(["apply","type","inverts","cardinality","scope","into","constrain","guide","stage","advance","target","targets","table"]),X3=new Set(["build","glyph","xKey","yKey","discreteScale","rawChannels","table"]),ca=e=>" ".repeat(e),Ty=e=>`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`,J3=e=>e&&typeof e=="object"&&typeof e.apply=="function"&&typeof e.type=="string",Oy=["name","channels","field","gesture","mode","strategy","threshold","when"],Z3=([e],[t])=>(Oy.indexOf(e)+1||99)-(Oy.indexOf(t)+1||99)||(e<t?-1:1),Q3=(e,t)=>t==null||t===!1||Array.isArray(t)&&!t.length||e==="pick"&&t==="direct"||e==="gesture"&&t==="drag"||e==="threshold"&&t===0;function Ma(e,t,n={}){if(typeof e=="function")return`ƒ ${e.name||"anonymous"}`;if(typeof e=="string")return Ty(e);if(e===null||typeof e!="object")return String(e);if(e instanceof Date)return e.toISOString();if(J3(e)){const s=e,a=Object.entries(s).filter(([l,u])=>!V3.has(l)&&!Q3(l,u)).sort(Z3);return`${s.type}(${a.length?`{ ${a.map(([l,u])=>`${l}: ${Ma(u,t,{one:!0})}`).join(", ")} }`:""})`}if(Array.isArray(e)){if(!e.length)return"[]";const s=e.map(l=>Ma(l,t+1,{one:!0})),a=`[${s.join(", ")}]`;return n.one&&a.length<=76&&!s.some(l=>l.includes(`
14
14
  `))?a:`[
15
15
  ${s.map(l=>`${ca(t+1)}${l}`).join(`,
16
16
  `)}
@@ -22,24 +22,24 @@ ${ca(t)}}`}const e7=e=>e&&typeof e=="object"&&typeof e.id=="string"&&e.id.includ
22
22
  `)}const i1=(e,t)=>JSON.stringify({canvas:e.canvas,steps:t.steps.map(n=>({id:n.id,label:n.label,group:n.group,x:Math.round(n.x),y:Math.round(n.y)})),depends:t.depends.map(n=>({source:n.source,target:n.target,label:n.label??"",...n.kind&&n.kind!=="needs"?{kind:n.kind}:{}}))},null,2),t7={actor:"you",via:"editor"},n7=1500;function r7(e){const{state:t,el:n,esc:r,notice:o,sync:i}=e,s={server:null,local:null,view:null,footprintId:"",planState:null,fp:null,flowId:null,flowAt:null,flowTimer:void 0,proposalId:null,drafts:{},own:new Set,unfollow:null,unfollowPlan:null,exists:null,fileInfo:new Map,calls:new Map},a=()=>t.mode==="architecture",l=()=>t.source==="server",u=()=>l()?s.server?{arch:s.server.arch,layout:s.server.layout}:null:s.local?{arch:s.local.arch,layout:s.local.layout}:null,c=()=>u()?.arch??null,d=()=>Object.fromEntries(Object.entries(s.planState?.plan?.nodes??{}).map(([C,W])=>[C,W.label])),f=()=>c()?.flows.find(C=>C.id===s.flowId)??null,p=()=>{const C=f();return C?s.flowAt===null?C.steps:[C.steps[s.flowAt]??C.steps[0]]:null},h=N3(()=>{const C=u();return!C||!s.view?null:{arch:C.arch,footprint:s.fp,flow:p(),folded:s.view.proj.folded,stand:s.view.proj.stand}}),y=(C,W)=>P3(C,{onChange:W,decor:h,stepLabel:q=>d()[q]});function g(){const C=u(),W=Mo(C,{headroom:l()});s.view=W;const q=s.local?.sample;return l()?W:{...W,id:q.id,title:q.title,plan:q.plan,repo:q.repo,source:q.source,note:q.note}}function m(){e.mount(g())}const b=()=>c()?.title??"Architecture";async function w(){s.unfollow?.(),s.own.clear(),s.exists=null,t.selected=null,s.proposalId=null;let C;try{C=await Ji()}catch(W){o(`Could not open the architecture: ${W.message}.`,"error");return}if(!C.exists){s.server=null,s.exists=!1,s.view=null,x(C.error),T(),e.render();return}o(""),s.exists=!0,s.server=C,await F(s.footprintId,{quiet:!0}),m(),ie(),T()}function x(C){e.state.chart?.destroy?.(),e.state.chart=null,e.el("chart").replaceChildren(),e.el("empty").hidden=!1,e.el("board").toggleAttribute("data-empty",!0),e.el("planbar").hidden=!0,e.el("needs").hidden=!0,e.el("planTitle").textContent="No architecture yet",e.el("planMeta").textContent="draw one, import one, or ask";const W=t.root.split(/[\\/]/).filter(Boolean).pop()??t.root;e.el("empty").innerHTML=`
23
23
  <div class="card">
24
24
  <h2>${C?"The architecture file needs fixing":`No architecture in ${r(W)} yet`}</h2>
25
- ${C?`<p class="err">${r(C)}</p>`:"<p>The architecture is the system as it is: its services, components and stores, and what uses what. Every plan is a change to it. It is one file, <code>.dcursed/architecture.json</code>.</p>"}
25
+ ${C?`<p class="err">${r(C)}</p>`:"<p>The architecture is the system as it is: its services, components and stores, and what uses what. Every plan is a change to it. It is one file, <code>.diacode/architecture.json</code>.</p>"}
26
26
  ${C?"":`<ul>
27
27
  <li><button class="primary" data-arch-start="new">Draw it</button><span>Name it, then double-click the board to add boxes, and drag from the dots on a box to draw arrows: the first uses the second.</span></li>
28
28
  <li><button data-arch-start="import">Import…</button><span>A Mermaid flowchart or C4 diagram, <code>.mmd</code> or markdown with a Mermaid block.</span></li>
29
29
  <li><b>Tell your agent the task</b><span>It draws the architecture here first, as the system will be. You change what is wrong and approve it; then it draws the plan.</span></li>
30
30
  </ul>`}
31
- </div>`;for(const q of e.el("empty").querySelectorAll("[data-arch-start]"))q.onclick=()=>q.dataset.archStart==="new"?S():v()}function S(){const C=e.el("empty").querySelector(".card");if(!C)return;C.innerHTML='<h2>What is the system called?</h2><form class="new-plan"><input name="title" placeholder="The shop" aria-label="What the system is called" autocomplete="off" required><button type="submit">Create</button></form>';const W=C.querySelector("form"),q=W.elements.namedItem("title");q.focus(),W.onsubmit=async V=>{V.preventDefault();const ee=q.value.trim();if(ee)try{await B1({title:ee}),e.el("empty").hidden=!0,await w()}catch(ue){o(`Not created: ${ue.message}`,"error")}}}function v(){const C=document.createElement("input");C.type="file",C.accept=".md,.markdown,.mmd,.mermaid,.txt",C.onchange=async()=>{const W=C.files?.[0];if(W)try{const{warnings:q}=await H1(W);e.el("empty").hidden=!0,await w(),o(`Imported ${W.name}.${q.length?` ${q.join("; ")}.`:""}`)}catch(q){o(`Not imported: ${q.message}`,"error")}},C.click()}function k(C){D(),s.flowId=null,s.flowAt=null,s.fp=null,s.footprintId="",t.selected=null,s.local={sample:C,arch:structuredClone(C.arch),layout:structuredClone(C.layout)},m()}function _(){s.unfollow?.(),s.unfollow=null,s.unfollowPlan?.(),s.unfollowPlan=null,D()}function T(){s.unfollow?.(),s.unfollow=tg({change:C=>{if(C.recovered){o(""),N({quiet:!0});return}if(!C.loaded&&!(C.rev!=null&&s.own.has(C.rev))){if(C.created||C.removed){w();return}N({line:C.line})}},problem:C=>o(`The architecture file has a problem: ${C.error}`,"error"),call:C=>{s.calls.set(C.id,C),e.shownCall()===C.id&&e.showCall(C)},open:C=>{e.el("conn").className="conn live",e.el("conn").textContent="saved live",C&&N()},down:()=>{e.el("conn").className="conn down",e.el("conn").textContent="server unreachable"}})}const L=(C,W)=>C?`${C.actor==="you"?C.via==="file"?"An edit to the file":"Another window":`${C.actor}`} changed the architecture (rev ${C.rev}${W?`, was ${W.rev}`:""}).`:"The architecture changed elsewhere.";async function N({quiet:C=!1,reseed:W=!1,line:q}={}){if(!l())return;if(i.pointerDown||i.inFlight){i.stale=!0,q&&(i.staleLine=q);return}const V=i.staleLine;V&&!s.own.has(V.rev)&&(q=V,C=!1),q&&s.own.has(q.rev)&&(q=void 0,C=!0),i.stale=!1,i.staleLine=null;let ee;try{ee=await Ji()}catch(ct){o(`Could not refresh: ${ct.message}.`,"error");return}if(!ee.exists){s.exists&&(s.server=null,s.exists=!1,x(ee.error));return}const ue=s.server;if(s.server=ee,s.exists=!0,i.pending&&!W&&s.own.has(ee.rev)){ie(),e.render();return}if(!t.chart){m(),ie();return}const be=Mo(ee);s.view=be;const Oe=ee.layout.canvas??{width:640,height:240},Ze=t.domain&&(Oe.width+40>t.domain.width||Oe.height+30>t.domain.height),rn=JSON.stringify(ue?.layout.collapsed??[])!==JSON.stringify(ee.layout.collapsed??[]),wt=JSON.stringify(ue?Mo(ue).proj.frames.map(ct=>ct.id):[])!==JSON.stringify(be.proj.frames.map(ct=>ct.id));if(Ze||rn||wt)m();else if(W)t.chart.setData({steps:be.steps,depends:be.depends}),C||o(`${L(q,ue)} Undo starts again from here.`);else{const ct=tf(t.chart.getData(),be);ct?("deferred"in t.chart.patch(ct,{history:"keep"})&&(i.stale=!0),C||o(`${L(q,ue)} Your undo history is kept.`)):(e.redraw(),!C&&q&&o(L(q,ue)))}await F(s.footprintId,{quiet:!0,keep:!0}),ie(),e.render()}async function I(){if(!l())return O();const C=s.server;if(!C||i.inFlight||i.refreshing||!i.pending||i.pointerDown)return;i.pending=!1;let W;try{W=O3(C,t.chart.getData())}catch(V){if(!(V instanceof Hi))throw V;o(`Not saved: ${V.message}`,"error"),await N({quiet:!0,reseed:!0});return}if(!W.length)return;i.inFlight=!0;let q=null;try{q=await ou(C.rev,W)}catch{o("Lost the plan server. Your last change is not saved.","error")}finally{i.inFlight=!1}if(q?.status===200){s.own.add(q.body.rev),q.body.kind==="proposed"&&o(`Saved as proposal ${q.body.proposal.id}: the architecture is accepted.`),i.refreshing=!0;try{await N({quiet:!0})}finally{i.refreshing=!1}}else q&&(o(`Not saved: ${q.body.why??q.body.error}. The chart is back to the architecture as it is.`,"error"),await N({quiet:!0,reseed:!0}));i.pending&&e.scheduleSave(60)}function O(){const C=s.local;if(!(!C||!t.chart)){i.pending=!1;try{const{after:W,placements:q}=e1(C.arch,C.layout,t.chart.getData());C.arch=W;const V={...C.layout.nodes};for(const ee of q)V[ee.id]={x:ee.x,y:ee.y};C.layout=au(W,{...C.layout,nodes:V}).layout,s.view=Mo({arch:C.arch,layout:C.layout},{headroom:!1}),e.render()}catch(W){if(!(W instanceof Hi))throw W;o(`Not done: ${W.message}`,"error"),s.view=Mo({arch:C.arch,layout:C.layout},{headroom:!1}),m()}}}async function M(C,W,q){if(!l())return $(C,W);for(let ee=0;i.inFlight&&ee<5e3;ee+=40)await new Promise(ue=>setTimeout(ue,40));if(!s.server||i.inFlight)return!1;let V=!1;i.inFlight=!0;try{const{status:ee,body:ue}=await ou(s.server.rev,C,q);if(ee===200){s.own.add(ue.rev),o(W),V=!0;const be=ue.calls?.[0];be&&e.showCall(s.calls.get(be.id)??be)}else o(`Not done: ${ue.why??ue.error}`,"error")}finally{i.inFlight=!1}return await N({quiet:!0}),V}function $(C,W){const q=s.local;if(!q)return!1;O();const V=Yy(q.arch,C,t7);if(V.kind!=="applied")return o(`Not done: ${V.kind==="rejected"?V.why:"it is not a change you can make"}`,"error"),Promise.resolve(!1);q.arch=V.arch;const ee={...q.layout.nodes};for(const be of V.placements)ee[be.id]={x:be.x,y:be.y};let ue=q.layout.collapsed??[];for(const be of V.folds)ue=be.folded?[...ue.filter(Oe=>Oe!==be.id),be.id]:ue.filter(Oe=>Oe!==be.id);return q.layout=au(V.arch,{...q.layout,nodes:ee,...ue.length?{collapsed:ue}:{collapsed:void 0}}).layout,ue.length||delete q.layout.collapsed,W&&o(W),m(),Promise.resolve(!0)}async function F(C,{quiet:W=!1,keep:q=!1}={}){if(l()){if(!C){s.unfollowPlan?.(),s.unfollowPlan=null,s.footprintId="",s.planState=null,s.fp=null,W||(e.redraw(),e.render());return}try{const V=await Al(C);if(!V.plan)throw new Error(V.error??"not a plan");s.footprintId=C,s.planState=V,s.fp=s.server?R1(s.server.arch,V.plan):null,q||(s.unfollowPlan?.(),s.unfollowPlan=Zy(C,{change:()=>{F(C,{quiet:!1,keep:!0})},problem:()=>{},open:()=>{},down:()=>{}}))}catch(V){s.footprintId="",s.planState=null,s.fp=null,W||o(`Could not look at that plan: ${V.message}.`,"error")}(!W||q)&&(e.redraw(),e.render())}}function D(){clearInterval(s.flowTimer),s.flowTimer=void 0}function z(C){D(),s.flowId=C===s.flowId?null:C,s.flowAt=null,e.redraw(),e.render()}function j(C){const W=f();W&&(s.flowAt=C===null?null:Math.max(0,Math.min(W.steps.length-1,C)),e.redraw(),e.render())}function G(){const C=f();if(C){if(s.flowTimer){D(),e.render();return}s.flowAt===null||s.flowAt>=C.steps.length-1?s.flowAt=0:s.flowAt+=1,e.redraw(),s.flowTimer=setInterval(()=>{const W=f();if(!W||s.flowAt===null||s.flowAt>=W.steps.length-1){D(),e.render();return}s.flowAt+=1,e.redraw(),e.render()},n7),e.render()}}function J(C,W){const q=f();if(!q||!s.view||!t.domain){C.querySelector(":scope > .flow")?.remove();return}const V=new Map(jn(W.steps).map(Ze=>[Ze.id,Ze])),{stand:ee}=s.view.proj,ue=W.depends,be=ef(t.chart,ue),Oe=[];q.steps.forEach((Ze,rn)=>{const wt=ee(Ze.from),ct=ee(Ze.to);if(wt===ct)return;const zn=s.flowAt===rn,An=be.get(`${wt}\0${ct}`),Bt=be.get(`${ct}\0${wt}`);if(An)Oe.push({n:rn+1,current:zn,...An});else if(Bt)Oe.push({n:rn+1,current:zn,x:Bt.x+14,y:Bt.y+14,reply:!0});else{const Ht=V.get(wt),It=V.get(ct);Ht&&It&&Oe.push({n:rn+1,current:zn,x:(Ht.x+It.x)/2,y:(Ht.y+It.y)/2,gap:{from:{x:Ht.x,y:Ht.y},to:{x:It.x,y:It.y}}})}}),q3(C,{steps:Oe,size:t.domain})}function re(C){if(!s.view||!t.chart)return[];const W=t.chart.getData(),q=C?W.steps.filter(V=>V.id!==C):W.steps;return ky(s.view.proj.frames,q,new Map(jn(q).map(V=>[V.id,V])))}function Q(C){if(!t.chart||!t.domain||!s.view)return;const W=t.chart.getData(),q=jn(W.steps),V=new Map(q.map(Oe=>[Oe.id,Oe])),ee=ky(s.view.proj.frames,W.steps,V);W3(C,{frames:ee,boxes:W.steps.flatMap(Oe=>{const Ze=V.get(Oe.id);return Ze?[{id:Oe.id,kind:Oe.kind,external:!!Oe.external,x:Ze.x,y:Ze.y,w:Ze.w,h:Ze.h,folded:s.view?.proj.folded.has(Oe.id)??!1}]:[]}),decor:h,size:t.domain,dropping:e.interactions().dropping()});const ue=W.depends.filter(Oe=>Oe.kind==="async"),be=ue.length?ef(t.chart,ue):new Map;t1(C,{items:[...q,...ee.map(Oe=>({id:Oe.id,group:void 0,x:Oe.x+Oe.w/2,y:Oe.y+Oe.h/2,w:Oe.w,h:Oe.h}))],look:Oe=>h.look(Oe)??void 0,arrows:ue.flatMap(Oe=>{const Ze=be.get(`${Oe.source}\0${Oe.target}`);return Ze?[{...Ze,kind:Oe.kind,icon:"async"}]:[]}),size:t.domain}),n1(t.chart,Oe=>Oe.kind==="async"||h.arrow(Oe).dashed===!0),J(C,W),me(),e.interactions().paint()}const ve=()=>c()?.proposals??[],Ce=()=>ve().find(C=>C.id===s.proposalId)??ve()[0]??null;let le="";function me(){const C=u(),W=n("chart").querySelector(".canvas");if(!C||!l()){xl(W,null,{},{},t.domain??{width:0,height:0}),e.ghost(null),ce();return}const q=Ce(),V=q?th(C.arch,C.layout,q.ops):null;e.ghost(xl(W,V,{nodes:C.arch.nodes},C.layout,t.domain??C.layout.canvas)),ce()}function ce(){const C=n("proposalCard"),W=ve(),q=u();if(!q||!l()||!W.length){C.hidden=!0,le="";return}const V=Ce();if(!V)return;const ee=th(q.arch,q.layout,V.ops),ue=U1(V,{at:W.indexOf(V)+1,of:W.length,applies:ee.applies,why:ee.why,arch:c()});ue!==le&&(le=ue,C.innerHTML=ue,C.setAttribute("aria-label",`Proposal ${V.id} from ${V.by}`),fe(C)),C.hidden=!1,e.placeCard()}function Y(C){s.proposalId=C,le="",e.render()}function fe(C){for(const W of C.querySelectorAll("[data-arch-accept-draft]"))W.onclick=()=>M([{op:"arch.set",phase:"accepted"}],"Architecture approved. Your agent draws the plan on it.","you approved the architecture");for(const W of C.querySelectorAll("[data-arch-accept]"))W.onclick=()=>M([{op:"proposal.accept",id:W.dataset.archAccept??""}],`Accepted ${W.dataset.archAccept}.`);for(const W of C.querySelectorAll("[data-arch-reject]"))W.onclick=()=>{const q=W.dataset.archReject??"",V=C.querySelector(`[data-arch-why="${CSS.escape(q)}"]`)?.value.trim();M([{op:"proposal.reject",id:q}],`Rejected ${q}.`,V||void 0)};for(const W of C.querySelectorAll("[data-arch-show]"))W.onclick=()=>Y(W.dataset.archShow??"");for(const W of C.querySelectorAll("[data-arch-next]"))W.onclick=()=>{const q=ve(),V=q.findIndex(ee=>ee.id===Ce()?.id);Y(q[(V+1)%q.length].id)}}function ie(){const C=u(),W=n("phase");if(n("phase2").hidden=!0,!C){W.hidden=!0,n("planbar").hidden=!0;return}const q=C.arch;n("planbar").hidden=!l(),n("planNote").hidden=l();const V=q.goal??"";if(n("goal").hidden=!V,n("goal").innerHTML=V?`<b>Goal</b> ${r(V)}`:"",n("rev").textContent=`rev ${s.server?.rev??0} · ${q.phase==="draft"?"draft":"approved"}`,l())e.bar();else{const Ze=q.phase==="draft";n("phases").innerHTML=["Draft","Approved"].map(rn=>`<li${rn==="Draft"===Ze?' class="on" aria-current="step"':""}>${rn}</li>`).join(""),W.hidden=!0,n("phaseLine").textContent="A demo: nothing here is kept."}const ee=[...s.server?.recent??[]].reverse().find(Ze=>Ze.actor!=="you")?.actor,ue=Qy(q,{by:ee});e.needs(ue.length,ue.length?`${ue.length} thing${ue.length===1?"":"s"} wait${ue.length===1?"s":""} on you in the architecture`:"");const be=n("needsBody");n("needs").hidden=!ue.length,ue.length||n("needs").removeAttribute("open");const Oe=z1(ue);Oe!==U&&!(be.contains(document.activeElement)&&document.activeElement instanceof HTMLInputElement)&&(U=Oe,be.innerHTML=Oe,fe(be)),n("planTitle").textContent=q.title,n("planMeta").textContent=`${Object.keys(q.nodes).length} boxes · ${q.edges.length} arrows`}let U="";const we=(C,W,q)=>M(C,W,q);function xe(C){const W=c();if(!W)return[];const q=new Set([C,...Oa(W,C)]);return Object.entries(W.nodes).filter(([V,ee])=>!q.has(V)&&(ee.kind==="service"||ee.kind==="group")).map(([V,ee])=>({id:V,label:ee.label}))}function P(C,W){const q=c();if(!q||!s.view)return la({type:"canvas"});if(C.type==="canvas")return la({type:"canvas"});if(C.type==="arrow")return la({type:"arrow"},{kind:W?.kind});const V=C.id,ee=q.nodes[V];if(!ee)return[];const ue=s.footprintId?{id:s.footprintId,planned:ee.planned===s.footprintId,retiring:ee.retiring===s.footprintId}:null;return la({type:C.type,id:V},{kind:ee.kind,external:!!ee.external,group:ee.in,frames:xe(V),folded:s.view.proj.folded.has(V),container:Er(q,V),plan:ue})}function H(C,W,q){const V=c(),ee=W.id;if(!V||!ee)return;const ue=V.nodes[ee]?.label??ee;if(C==="fold"){he(ee);return}if(C==="delete"){M([{op:"box.remove",id:ee}],`Removed ${ue}${Er(V,ee)?"; what was in it stays":""}.`);return}if(C==="rename"&&q){M([{op:"box.set",id:ee,label:q}],`Renamed ${ue}.`);return}if(C.startsWith("frame-kind:")){M([{op:"box.set",id:ee,kind:C.slice(11)}],`${ue} is a ${C.slice(11)}.`);return}if(C==="external:on"||C==="external:off"){M([{op:"box.set",id:ee,external:C==="external:on"}],C==="external:on"?`${ue} is run by someone else.`:`${ue} is yours.`);return}if(C==="plan:planned"){const be=V.nodes[ee]?.planned!==s.footprintId;M([{op:"box.set",id:ee,planned:be?s.footprintId:null}],be?`${ue} is planned by ${s.footprintId}.`:`${ue} is no longer planned.`);return}if(C==="plan:retiring"){const be=V.nodes[ee]?.retiring!==s.footprintId;M([{op:"box.set",id:ee,retiring:be?s.footprintId:null}],be?`${s.footprintId} removes ${ue}.`:`${ue} is no longer retiring.`);return}if(C==="into:new"&&q){const be=oe(V,q);M([{op:"box.add",id:be,label:q,kind:"group"},{op:"box.set",id:ee,in:be}],`${ue} is in a new frame, ${q}.`);return}if(C.startsWith("into:")){const be=C.slice(5);M([{op:"box.set",id:ee,in:be==="top"?null:be}],be==="top"?`${ue} is out of its frame.`:`${ue} is in ${V.nodes[be]?.label??be}.`)}}const oe=(C,W)=>{const q=W.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)||"frame";let V=q;for(let ee=2;V in C.nodes;ee++)V=`${q}-${ee}`;return V};function he(C){const W=c(),q=u();if(!W||!q||!Er(W,C))return;const V=(q.layout.collapsed??[]).includes(C);M([{op:"layout.fold",id:C,folded:!V}],"")}function ke(C){const W=C.dataset.box,q=C.dataset.boxField,V=c();if(!W||!q||!V?.nodes[W])return;const ee=V.nodes[W];if(q==="detail"){const ue=C.value.replace(/\s+$/,"");if(ue===(ee.detail??"")){W===t.selected&&delete s.drafts.detail;return}M([{op:"box.set",id:W,detail:ue}],`Saved what ${ee.label} is for.`,`you edited the detail of ${W}`).then(be=>{be&&(delete s.drafts.detail,e.render())})}else if(q==="tech"){const ue=C.value.trim();if(ue===(ee.tech??"")){delete s.drafts.tech;return}M([{op:"box.set",id:W,tech:ue}],`Saved what ${ee.label} runs on.`,`you edited the tech of ${W}`).then(be=>{be&&(delete s.drafts.tech,e.render())})}else if(q==="kind"){const ue=C.value;ue!==ee.kind&&M([{op:"box.set",id:W,kind:ue}],`${ee.label} is a ${ue}.`)}else if(q==="external"){const ue=C.checked;M([{op:"box.set",id:W,external:ue}],ue?`${ee.label} is run by someone else.`:`${ee.label} is yours.`)}}const pe={samples:["Flows","Changes"],server:["Boxes","Flows","Changes"]},$e=()=>l()?pe.server:pe.samples;function Te(){return l()?`<div class="footprint-pick"><label for="footprintPick">Look at a plan on it</label>
31
+ </div>`;for(const q of e.el("empty").querySelectorAll("[data-arch-start]"))q.onclick=()=>q.dataset.archStart==="new"?S():v()}function S(){const C=e.el("empty").querySelector(".card");if(!C)return;C.innerHTML='<h2>What is the system called?</h2><form class="new-plan"><input name="title" placeholder="The shop" aria-label="What the system is called" autocomplete="off" required><button type="submit">Create</button></form>';const W=C.querySelector("form"),q=W.elements.namedItem("title");q.focus(),W.onsubmit=async V=>{V.preventDefault();const ee=q.value.trim();if(ee)try{await B1({title:ee}),e.el("empty").hidden=!0,await w()}catch(ue){o(`Not created: ${ue.message}`,"error")}}}function v(){const C=document.createElement("input");C.type="file",C.accept=".md,.markdown,.mmd,.mermaid,.txt",C.onchange=async()=>{const W=C.files?.[0];if(W)try{const{warnings:q}=await H1(W);e.el("empty").hidden=!0,await w(),o(`Imported ${W.name}.${q.length?` ${q.join("; ")}.`:""}`)}catch(q){o(`Not imported: ${q.message}`,"error")}},C.click()}function k(C){D(),s.flowId=null,s.flowAt=null,s.fp=null,s.footprintId="",t.selected=null,s.local={sample:C,arch:structuredClone(C.arch),layout:structuredClone(C.layout)},m()}function _(){s.unfollow?.(),s.unfollow=null,s.unfollowPlan?.(),s.unfollowPlan=null,D()}function T(){s.unfollow?.(),s.unfollow=tg({change:C=>{if(C.recovered){o(""),N({quiet:!0});return}if(!C.loaded&&!(C.rev!=null&&s.own.has(C.rev))){if(C.created||C.removed){w();return}N({line:C.line})}},problem:C=>o(`The architecture file has a problem: ${C.error}`,"error"),call:C=>{s.calls.set(C.id,C),e.shownCall()===C.id&&e.showCall(C)},open:C=>{e.el("conn").className="conn live",e.el("conn").textContent="saved live",C&&N()},down:()=>{e.el("conn").className="conn down",e.el("conn").textContent="server unreachable"}})}const L=(C,W)=>C?`${C.actor==="you"?C.via==="file"?"An edit to the file":"Another window":`${C.actor}`} changed the architecture (rev ${C.rev}${W?`, was ${W.rev}`:""}).`:"The architecture changed elsewhere.";async function N({quiet:C=!1,reseed:W=!1,line:q}={}){if(!l())return;if(i.pointerDown||i.inFlight){i.stale=!0,q&&(i.staleLine=q);return}const V=i.staleLine;V&&!s.own.has(V.rev)&&(q=V,C=!1),q&&s.own.has(q.rev)&&(q=void 0,C=!0),i.stale=!1,i.staleLine=null;let ee;try{ee=await Ji()}catch(ut){o(`Could not refresh: ${ut.message}.`,"error");return}if(!ee.exists){s.exists&&(s.server=null,s.exists=!1,x(ee.error));return}const ue=s.server;if(s.server=ee,s.exists=!0,i.pending&&!W&&s.own.has(ee.rev)){ie(),e.render();return}if(!t.chart){m(),ie();return}const be=Mo(ee);s.view=be;const Oe=ee.layout.canvas??{width:640,height:240},Ze=t.domain&&(Oe.width+40>t.domain.width||Oe.height+30>t.domain.height),rn=JSON.stringify(ue?.layout.collapsed??[])!==JSON.stringify(ee.layout.collapsed??[]),bt=JSON.stringify(ue?Mo(ue).proj.frames.map(ut=>ut.id):[])!==JSON.stringify(be.proj.frames.map(ut=>ut.id));if(Ze||rn||bt)m();else if(W)t.chart.setData({steps:be.steps,depends:be.depends}),C||o(`${L(q,ue)} Undo starts again from here.`);else{const ut=tf(t.chart.getData(),be);ut?("deferred"in t.chart.patch(ut,{history:"keep"})&&(i.stale=!0),C||o(`${L(q,ue)} Your undo history is kept.`)):(e.redraw(),!C&&q&&o(L(q,ue)))}await F(s.footprintId,{quiet:!0,keep:!0}),ie(),e.render()}async function I(){if(!l())return O();const C=s.server;if(!C||i.inFlight||i.refreshing||!i.pending||i.pointerDown)return;i.pending=!1;let W;try{W=O3(C,t.chart.getData())}catch(V){if(!(V instanceof Hi))throw V;o(`Not saved: ${V.message}`,"error"),await N({quiet:!0,reseed:!0});return}if(!W.length)return;i.inFlight=!0;let q=null;try{q=await ou(C.rev,W)}catch{o("Lost the plan server. Your last change is not saved.","error")}finally{i.inFlight=!1}if(q?.status===200){s.own.add(q.body.rev),q.body.kind==="proposed"&&o(`Saved as proposal ${q.body.proposal.id}: the architecture is accepted.`),i.refreshing=!0;try{await N({quiet:!0})}finally{i.refreshing=!1}}else q&&(o(`Not saved: ${q.body.why??q.body.error}. The chart is back to the architecture as it is.`,"error"),await N({quiet:!0,reseed:!0}));i.pending&&e.scheduleSave(60)}function O(){const C=s.local;if(!(!C||!t.chart)){i.pending=!1;try{const{after:W,placements:q}=e1(C.arch,C.layout,t.chart.getData());C.arch=W;const V={...C.layout.nodes};for(const ee of q)V[ee.id]={x:ee.x,y:ee.y};C.layout=au(W,{...C.layout,nodes:V}).layout,s.view=Mo({arch:C.arch,layout:C.layout},{headroom:!1}),e.render()}catch(W){if(!(W instanceof Hi))throw W;o(`Not done: ${W.message}`,"error"),s.view=Mo({arch:C.arch,layout:C.layout},{headroom:!1}),m()}}}async function M(C,W,q){if(!l())return $(C,W);for(let ee=0;i.inFlight&&ee<5e3;ee+=40)await new Promise(ue=>setTimeout(ue,40));if(!s.server||i.inFlight)return!1;let V=!1;i.inFlight=!0;try{const{status:ee,body:ue}=await ou(s.server.rev,C,q);if(ee===200){s.own.add(ue.rev),o(W),V=!0;const be=ue.calls?.[0];be&&e.showCall(s.calls.get(be.id)??be)}else o(`Not done: ${ue.why??ue.error}`,"error")}finally{i.inFlight=!1}return await N({quiet:!0}),V}function $(C,W){const q=s.local;if(!q)return!1;O();const V=Yy(q.arch,C,t7);if(V.kind!=="applied")return o(`Not done: ${V.kind==="rejected"?V.why:"it is not a change you can make"}`,"error"),Promise.resolve(!1);q.arch=V.arch;const ee={...q.layout.nodes};for(const be of V.placements)ee[be.id]={x:be.x,y:be.y};let ue=q.layout.collapsed??[];for(const be of V.folds)ue=be.folded?[...ue.filter(Oe=>Oe!==be.id),be.id]:ue.filter(Oe=>Oe!==be.id);return q.layout=au(V.arch,{...q.layout,nodes:ee,...ue.length?{collapsed:ue}:{collapsed:void 0}}).layout,ue.length||delete q.layout.collapsed,W&&o(W),m(),Promise.resolve(!0)}async function F(C,{quiet:W=!1,keep:q=!1}={}){if(l()){if(!C){s.unfollowPlan?.(),s.unfollowPlan=null,s.footprintId="",s.planState=null,s.fp=null,W||(e.redraw(),e.render());return}try{const V=await Al(C);if(!V.plan)throw new Error(V.error??"not a plan");s.footprintId=C,s.planState=V,s.fp=s.server?R1(s.server.arch,V.plan):null,q||(s.unfollowPlan?.(),s.unfollowPlan=Zy(C,{change:()=>{F(C,{quiet:!1,keep:!0})},problem:()=>{},open:()=>{},down:()=>{}}))}catch(V){s.footprintId="",s.planState=null,s.fp=null,W||o(`Could not look at that plan: ${V.message}.`,"error")}(!W||q)&&(e.redraw(),e.render())}}function D(){clearInterval(s.flowTimer),s.flowTimer=void 0}function z(C){D(),s.flowId=C===s.flowId?null:C,s.flowAt=null,e.redraw(),e.render()}function j(C){const W=f();W&&(s.flowAt=C===null?null:Math.max(0,Math.min(W.steps.length-1,C)),e.redraw(),e.render())}function G(){const C=f();if(C){if(s.flowTimer){D(),e.render();return}s.flowAt===null||s.flowAt>=C.steps.length-1?s.flowAt=0:s.flowAt+=1,e.redraw(),s.flowTimer=setInterval(()=>{const W=f();if(!W||s.flowAt===null||s.flowAt>=W.steps.length-1){D(),e.render();return}s.flowAt+=1,e.redraw(),e.render()},n7),e.render()}}function J(C,W){const q=f();if(!q||!s.view||!t.domain){C.querySelector(":scope > .flow")?.remove();return}const V=new Map(jn(W.steps).map(Ze=>[Ze.id,Ze])),{stand:ee}=s.view.proj,ue=W.depends,be=ef(t.chart,ue),Oe=[];q.steps.forEach((Ze,rn)=>{const bt=ee(Ze.from),ut=ee(Ze.to);if(bt===ut)return;const zn=s.flowAt===rn,An=be.get(`${bt}\0${ut}`),Bt=be.get(`${ut}\0${bt}`);if(An)Oe.push({n:rn+1,current:zn,...An});else if(Bt)Oe.push({n:rn+1,current:zn,x:Bt.x+14,y:Bt.y+14,reply:!0});else{const Ht=V.get(bt),Lt=V.get(ut);Ht&&Lt&&Oe.push({n:rn+1,current:zn,x:(Ht.x+Lt.x)/2,y:(Ht.y+Lt.y)/2,gap:{from:{x:Ht.x,y:Ht.y},to:{x:Lt.x,y:Lt.y}}})}}),q3(C,{steps:Oe,size:t.domain})}function re(C){if(!s.view||!t.chart)return[];const W=t.chart.getData(),q=C?W.steps.filter(V=>V.id!==C):W.steps;return ky(s.view.proj.frames,q,new Map(jn(q).map(V=>[V.id,V])))}function Q(C){if(!t.chart||!t.domain||!s.view)return;const W=t.chart.getData(),q=jn(W.steps),V=new Map(q.map(Oe=>[Oe.id,Oe])),ee=ky(s.view.proj.frames,W.steps,V);W3(C,{frames:ee,boxes:W.steps.flatMap(Oe=>{const Ze=V.get(Oe.id);return Ze?[{id:Oe.id,kind:Oe.kind,external:!!Oe.external,x:Ze.x,y:Ze.y,w:Ze.w,h:Ze.h,folded:s.view?.proj.folded.has(Oe.id)??!1}]:[]}),decor:h,size:t.domain,dropping:e.interactions().dropping()});const ue=W.depends.filter(Oe=>Oe.kind==="async"),be=ue.length?ef(t.chart,ue):new Map;t1(C,{items:[...q,...ee.map(Oe=>({id:Oe.id,group:void 0,x:Oe.x+Oe.w/2,y:Oe.y+Oe.h/2,w:Oe.w,h:Oe.h}))],look:Oe=>h.look(Oe)??void 0,arrows:ue.flatMap(Oe=>{const Ze=be.get(`${Oe.source}\0${Oe.target}`);return Ze?[{...Ze,kind:Oe.kind,icon:"async"}]:[]}),size:t.domain}),n1(t.chart,Oe=>Oe.kind==="async"||h.arrow(Oe).dashed===!0),J(C,W),me(),e.interactions().paint()}const ve=()=>c()?.proposals??[],Ce=()=>ve().find(C=>C.id===s.proposalId)??ve()[0]??null;let le="";function me(){const C=u(),W=n("chart").querySelector(".canvas");if(!C||!l()){xl(W,null,{},{},t.domain??{width:0,height:0}),e.ghost(null),ce();return}const q=Ce(),V=q?th(C.arch,C.layout,q.ops):null;e.ghost(xl(W,V,{nodes:C.arch.nodes},C.layout,t.domain??C.layout.canvas)),ce()}function ce(){const C=n("proposalCard"),W=ve(),q=u();if(!q||!l()||!W.length){C.hidden=!0,le="";return}const V=Ce();if(!V)return;const ee=th(q.arch,q.layout,V.ops),ue=U1(V,{at:W.indexOf(V)+1,of:W.length,applies:ee.applies,why:ee.why,arch:c()});ue!==le&&(le=ue,C.innerHTML=ue,C.setAttribute("aria-label",`Proposal ${V.id} from ${V.by}`),fe(C)),C.hidden=!1,e.placeCard()}function Y(C){s.proposalId=C,le="",e.render()}function fe(C){for(const W of C.querySelectorAll("[data-arch-accept-draft]"))W.onclick=()=>M([{op:"arch.set",phase:"accepted"}],"Architecture approved. Your agent draws the plan on it.","you approved the architecture");for(const W of C.querySelectorAll("[data-arch-accept]"))W.onclick=()=>M([{op:"proposal.accept",id:W.dataset.archAccept??""}],`Accepted ${W.dataset.archAccept}.`);for(const W of C.querySelectorAll("[data-arch-reject]"))W.onclick=()=>{const q=W.dataset.archReject??"",V=C.querySelector(`[data-arch-why="${CSS.escape(q)}"]`)?.value.trim();M([{op:"proposal.reject",id:q}],`Rejected ${q}.`,V||void 0)};for(const W of C.querySelectorAll("[data-arch-show]"))W.onclick=()=>Y(W.dataset.archShow??"");for(const W of C.querySelectorAll("[data-arch-next]"))W.onclick=()=>{const q=ve(),V=q.findIndex(ee=>ee.id===Ce()?.id);Y(q[(V+1)%q.length].id)}}function ie(){const C=u(),W=n("phase");if(n("phase2").hidden=!0,!C){W.hidden=!0,n("planbar").hidden=!0;return}const q=C.arch;n("planbar").hidden=!l(),n("planNote").hidden=l();const V=q.goal??"";if(n("goal").hidden=!V,n("goal").innerHTML=V?`<b>Goal</b> ${r(V)}`:"",n("rev").textContent=`rev ${s.server?.rev??0} · ${q.phase==="draft"?"draft":"approved"}`,l())e.bar();else{const Ze=q.phase==="draft";n("phases").innerHTML=["Draft","Approved"].map(rn=>`<li${rn==="Draft"===Ze?' class="on" aria-current="step"':""}>${rn}</li>`).join(""),W.hidden=!0,n("phaseLine").textContent="A demo: nothing here is kept."}const ee=[...s.server?.recent??[]].reverse().find(Ze=>Ze.actor!=="you")?.actor,ue=Qy(q,{by:ee});e.needs(ue.length,ue.length?`${ue.length} thing${ue.length===1?"":"s"} wait${ue.length===1?"s":""} on you in the architecture`:"");const be=n("needsBody");n("needs").hidden=!ue.length,ue.length||n("needs").removeAttribute("open");const Oe=z1(ue);Oe!==U&&!(be.contains(document.activeElement)&&document.activeElement instanceof HTMLInputElement)&&(U=Oe,be.innerHTML=Oe,fe(be)),n("planTitle").textContent=q.title,n("planMeta").textContent=`${Object.keys(q.nodes).length} boxes · ${q.edges.length} arrows`}let U="";const we=(C,W,q)=>M(C,W,q);function xe(C){const W=c();if(!W)return[];const q=new Set([C,...Oa(W,C)]);return Object.entries(W.nodes).filter(([V,ee])=>!q.has(V)&&(ee.kind==="service"||ee.kind==="group")).map(([V,ee])=>({id:V,label:ee.label}))}function P(C,W){const q=c();if(!q||!s.view)return la({type:"canvas"});if(C.type==="canvas")return la({type:"canvas"});if(C.type==="arrow")return la({type:"arrow"},{kind:W?.kind});const V=C.id,ee=q.nodes[V];if(!ee)return[];const ue=s.footprintId?{id:s.footprintId,planned:ee.planned===s.footprintId,retiring:ee.retiring===s.footprintId}:null;return la({type:C.type,id:V},{kind:ee.kind,external:!!ee.external,group:ee.in,frames:xe(V),folded:s.view.proj.folded.has(V),container:Er(q,V),plan:ue})}function H(C,W,q){const V=c(),ee=W.id;if(!V||!ee)return;const ue=V.nodes[ee]?.label??ee;if(C==="fold"){he(ee);return}if(C==="delete"){M([{op:"box.remove",id:ee}],`Removed ${ue}${Er(V,ee)?"; what was in it stays":""}.`);return}if(C==="rename"&&q){M([{op:"box.set",id:ee,label:q}],`Renamed ${ue}.`);return}if(C.startsWith("frame-kind:")){M([{op:"box.set",id:ee,kind:C.slice(11)}],`${ue} is a ${C.slice(11)}.`);return}if(C==="external:on"||C==="external:off"){M([{op:"box.set",id:ee,external:C==="external:on"}],C==="external:on"?`${ue} is run by someone else.`:`${ue} is yours.`);return}if(C==="plan:planned"){const be=V.nodes[ee]?.planned!==s.footprintId;M([{op:"box.set",id:ee,planned:be?s.footprintId:null}],be?`${ue} is planned by ${s.footprintId}.`:`${ue} is no longer planned.`);return}if(C==="plan:retiring"){const be=V.nodes[ee]?.retiring!==s.footprintId;M([{op:"box.set",id:ee,retiring:be?s.footprintId:null}],be?`${s.footprintId} removes ${ue}.`:`${ue} is no longer retiring.`);return}if(C==="into:new"&&q){const be=oe(V,q);M([{op:"box.add",id:be,label:q,kind:"group"},{op:"box.set",id:ee,in:be}],`${ue} is in a new frame, ${q}.`);return}if(C.startsWith("into:")){const be=C.slice(5);M([{op:"box.set",id:ee,in:be==="top"?null:be}],be==="top"?`${ue} is out of its frame.`:`${ue} is in ${V.nodes[be]?.label??be}.`)}}const oe=(C,W)=>{const q=W.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)||"frame";let V=q;for(let ee=2;V in C.nodes;ee++)V=`${q}-${ee}`;return V};function he(C){const W=c(),q=u();if(!W||!q||!Er(W,C))return;const V=(q.layout.collapsed??[]).includes(C);M([{op:"layout.fold",id:C,folded:!V}],"")}function ke(C){const W=C.dataset.box,q=C.dataset.boxField,V=c();if(!W||!q||!V?.nodes[W])return;const ee=V.nodes[W];if(q==="detail"){const ue=C.value.replace(/\s+$/,"");if(ue===(ee.detail??"")){W===t.selected&&delete s.drafts.detail;return}M([{op:"box.set",id:W,detail:ue}],`Saved what ${ee.label} is for.`,`you edited the detail of ${W}`).then(be=>{be&&(delete s.drafts.detail,e.render())})}else if(q==="tech"){const ue=C.value.trim();if(ue===(ee.tech??"")){delete s.drafts.tech;return}M([{op:"box.set",id:W,tech:ue}],`Saved what ${ee.label} runs on.`,`you edited the tech of ${W}`).then(be=>{be&&(delete s.drafts.tech,e.render())})}else if(q==="kind"){const ue=C.value;ue!==ee.kind&&M([{op:"box.set",id:W,kind:ue}],`${ee.label} is a ${ue}.`)}else if(q==="external"){const ue=C.checked;M([{op:"box.set",id:W,external:ue}],ue?`${ee.label} is run by someone else.`:`${ee.label} is yours.`)}}const pe={samples:["Flows","Changes"],server:["Boxes","Flows","Changes"]},_e=()=>l()?pe.server:pe.samples;function Te(){return l()?`<div class="footprint-pick"><label for="footprintPick">Look at a plan on it</label>
32
32
  <select id="footprintPick"><option value="">No plan</option>${e.plans().filter(W=>!W.error).map(W=>`<option value="${r(W.id)}"${W.id===s.footprintId?" selected":""}>${r(W.title??W.id)}</option>`).join("")}</select>
33
- <p class="help">${s.fp?"New is green, changed amber, removed red, and what the plan leaves alone fades.":"Pick a plan to see what it adds, changes and removes."}</p></div>`:""}function Se(C){const W=u();if(!W)return'<p class="lede">No architecture open.</p>';if(C==="Boxes"){const q=t.selected?D1({arch:W.arch,id:t.selected,footprint:s.fp,steps:s.planState?.plan?.nodes??{},drafts:s.drafts,fileInfo:Pe(),recent:s.server?.recent??[],editable:l(),suggesting:eg({id:t.selected,calls:s.server?.calls,noun:"box",bare:!W.arch.nodes[t.selected]?.detail&&!W.arch.nodes[t.selected]?.tech&&!W.arch.nodes[t.selected]?.files?.length,proposed:(W.arch.proposals??[]).some(V=>(V.ops??[]).some(ee=>ee.id===t.selected))})}):"";return t.selected&&!q&&(t.selected=null),`${q}${Te()}${j1({arch:W.arch,selected:t.selected,folded:W.layout.collapsed??[],footprint:s.fp})}`}return C==="Flows"?`${W1({arch:W.arch,flowId:s.flowId,at:s.flowAt,playing:!!s.flowTimer})}`:l()?q1(s.server?.recent??[]):e.changesPanel(t.chart?.getData())}function ae(){const C=n("panel");for(const q of C.querySelectorAll("[data-fold]"))q.onclick=()=>he(q.dataset.fold??"");for(const q of C.querySelectorAll("[data-flow]"))q.onclick=()=>z(q.dataset.flow??null);for(const q of C.querySelectorAll("[data-flow-at]"))q.onclick=()=>{D(),j(Number(q.dataset.flowAt))};f(),C.querySelector("[data-flow-play]")?.addEventListener("click",G),C.querySelector("[data-flow-next]")?.addEventListener("click",()=>{D(),j((s.flowAt??-1)+1)}),C.querySelector("[data-flow-prev]")?.addEventListener("click",()=>{D(),j((s.flowAt??1)-1)}),C.querySelector("[data-flow-clear]")?.addEventListener("click",()=>{D(),s.flowAt=null,e.redraw(),e.render()});const W=C.querySelector("#footprintPick");W&&(W.onchange=()=>F(W.value));for(const q of C.querySelectorAll("[data-box-field]")){const V=q,ee=V.dataset.boxField;ee==="detail"||ee==="tech"?(V.addEventListener("input",()=>{s.drafts[ee]=V.value}),V.addEventListener("blur",()=>ke(V)),V.addEventListener("keydown",ue=>{const be=ue;be.key==="Enter"&&(ee==="tech"||be.metaKey||be.ctrlKey)&&(be.preventDefault(),ke(V))})):V.addEventListener("change",()=>ke(V))}fe(C)}const _e=5e3,Pe=()=>Object.fromEntries([...s.fileInfo].map(([C,W])=>[C,W.info])),Z=()=>{const C=t.selected,W=C?c()?.nodes[C]:void 0;return C&&W?{id:C,files:W.files??[]}:null};function vt(C,W){const q=c()?.nodes[C];return q?M([{op:"box.set",id:C,files:W}],`Saved the files for ${q.label}.`,`you edited the files of ${C}`):Promise.resolve(!1)}function rt(C){const W=Z();if(!W||!l())return;const q=Date.now(),V=W.files.filter(ee=>!((s.fileInfo.get(ee)?.at??0)>q-_e)&&!dt.has(ee));if(V.length){for(const ee of V)dt.add(ee);df(V).then(ee=>{for(const ue of ee)s.fileInfo.set(ue.path,{at:Date.now(),info:{kind:ue.kind,matches:ue.matches}})}).catch(()=>{}).finally(()=>{for(const ee of V)dt.delete(ee);C()})}}const dt=new Set;function gt(){const C=m3.map(([W,q,V,ee])=>`<div><dt>${r(W)}</dt><dd>${r(q)}</dd>${l()?"":`<dd><code>${r(V)}</code></dd>`}<dd>${r(ee)}</dd></div>`).join("");return`
33
+ <p class="help">${s.fp?"New is green, changed amber, removed red, and what the plan leaves alone fades.":"Pick a plan to see what it adds, changes and removes."}</p></div>`:""}function Se(C){const W=u();if(!W)return'<p class="lede">No architecture open.</p>';if(C==="Boxes"){const q=t.selected?D1({arch:W.arch,id:t.selected,footprint:s.fp,steps:s.planState?.plan?.nodes??{},drafts:s.drafts,fileInfo:Le(),recent:s.server?.recent??[],editable:l(),suggesting:eg({id:t.selected,calls:s.server?.calls,noun:"box",bare:!W.arch.nodes[t.selected]?.detail&&!W.arch.nodes[t.selected]?.tech&&!W.arch.nodes[t.selected]?.files?.length,proposed:(W.arch.proposals??[]).some(V=>(V.ops??[]).some(ee=>ee.id===t.selected))})}):"";return t.selected&&!q&&(t.selected=null),`${q}${Te()}${j1({arch:W.arch,selected:t.selected,folded:W.layout.collapsed??[],footprint:s.fp})}`}return C==="Flows"?`${W1({arch:W.arch,flowId:s.flowId,at:s.flowAt,playing:!!s.flowTimer})}`:l()?q1(s.server?.recent??[]):e.changesPanel(t.chart?.getData())}function ae(){const C=n("panel");for(const q of C.querySelectorAll("[data-fold]"))q.onclick=()=>he(q.dataset.fold??"");for(const q of C.querySelectorAll("[data-flow]"))q.onclick=()=>z(q.dataset.flow??null);for(const q of C.querySelectorAll("[data-flow-at]"))q.onclick=()=>{D(),j(Number(q.dataset.flowAt))};f(),C.querySelector("[data-flow-play]")?.addEventListener("click",G),C.querySelector("[data-flow-next]")?.addEventListener("click",()=>{D(),j((s.flowAt??-1)+1)}),C.querySelector("[data-flow-prev]")?.addEventListener("click",()=>{D(),j((s.flowAt??1)-1)}),C.querySelector("[data-flow-clear]")?.addEventListener("click",()=>{D(),s.flowAt=null,e.redraw(),e.render()});const W=C.querySelector("#footprintPick");W&&(W.onchange=()=>F(W.value));for(const q of C.querySelectorAll("[data-box-field]")){const V=q,ee=V.dataset.boxField;ee==="detail"||ee==="tech"?(V.addEventListener("input",()=>{s.drafts[ee]=V.value}),V.addEventListener("blur",()=>ke(V)),V.addEventListener("keydown",ue=>{const be=ue;be.key==="Enter"&&(ee==="tech"||be.metaKey||be.ctrlKey)&&(be.preventDefault(),ke(V))})):V.addEventListener("change",()=>ke(V))}fe(C)}const $e=5e3,Le=()=>Object.fromEntries([...s.fileInfo].map(([C,W])=>[C,W.info])),Z=()=>{const C=t.selected,W=C?c()?.nodes[C]:void 0;return C&&W?{id:C,files:W.files??[]}:null};function St(C,W){const q=c()?.nodes[C];return q?M([{op:"box.set",id:C,files:W}],`Saved the files for ${q.label}.`,`you edited the files of ${C}`):Promise.resolve(!1)}function rt(C){const W=Z();if(!W||!l())return;const q=Date.now(),V=W.files.filter(ee=>!((s.fileInfo.get(ee)?.at??0)>q-$e)&&!ct.has(ee));if(V.length){for(const ee of V)ct.add(ee);df(V).then(ee=>{for(const ue of ee)s.fileInfo.set(ue.path,{at:Date.now(),info:{kind:ue.kind,matches:ue.matches}})}).catch(()=>{}).finally(()=>{for(const ee of V)ct.delete(ee);C()})}}const ct=new Set;function $t(){const C=m3.map(([W,q,V,ee])=>`<div><dt>${r(W)}</dt><dd>${r(q)}</dd>${l()?"":`<dd><code>${r(V)}</code></dd>`}<dd>${r(ee)}</dd></div>`).join("");return`
34
34
  <h4>Edit the architecture</h4>
35
35
  <p>An arrow from A to B means <b>A uses B</b>: a call, not an order. ${l()?"Each gesture is saved as a change to the architecture, which is how your agents hear about it.":"Every gesture below is one line of <code>archspec.js</code>: nothing in this app implements dragging or hit-testing. Nothing is kept: it is a demo."}</p>
36
36
  <dl class="gestures">${C}</dl>
37
37
  <h4>Look around</h4>
38
- <p>Scroll, or hold Space and drag. + and − zoom; 0 shows the whole architecture.</p>`}function Wt(){const C=q=>`<li><span class="kind-key kind-${q}" aria-hidden="true"></span><b>${r(da[q])}</b> ${r({person:"a user or a role",service:"something that runs",component:"a part inside a service",store:"where data lives",queue:"a message channel",group:"a frame round other boxes"}[q])}</li>`,W=q=>`<span class="chip" style="background:${Br[q].colour}">${Ao(Br[q].icon,{size:12})}</span>`;return`
38
+ <p>Scroll, or hold Space and drag. + and − zoom; 0 shows the whole architecture.</p>`}function xt(){const C=q=>`<li><span class="kind-key kind-${q}" aria-hidden="true"></span><b>${r(da[q])}</b> ${r({person:"a user or a role",service:"something that runs",component:"a part inside a service",store:"where data lives",queue:"a message channel",group:"a frame round other boxes"}[q])}</li>`,W=q=>`<span class="chip" style="background:${Br[q].colour}">${Ao(Br[q].icon,{size:12})}</span>`;return`
39
39
  <h4>Boxes</h4><ul>${["person","service","component","store","queue","group"].map(C).join("")}<li><span class="kind-key external" aria-hidden="true"></span><b>Grey</b> someone else runs it</li></ul>
40
40
  <h4>Arrows</h4><ul><li><span class="wire"></span>A uses B: a call, and A waits for the answer</li><li><span class="gate">${Ao("async",{size:12})}</span>A does not wait for the answer <i>(lighter, with this mark)</i></li></ul>
41
41
  <h4>A plan on it</h4><ul>${["new","changed","removed"].map(q=>`<li>${W(q)}${r(Br[q].word)}${q==="removed"?" <i>(struck through)</i>":""}</li>`).join("")}<li><span class="frame-key"></span>faded: the plan leaves it alone</li></ul>
42
- <h4>Marks</h4><ul><li><span class="frame-key"></span>a frame holds boxes; the chevron folds it</li><li><span class="ember-key"></span>ember: what you hold or just changed</li></ul>`}function At(C,W){const q=u();if(!q)return"";if(C==="Data"){const V=l()?`${Hw(q.arch)}`:i1({...t.plan,canvas:t.domain??t.plan.canvas},W);return`
42
+ <h4>Marks</h4><ul><li><span class="frame-key"></span>a frame holds boxes; the chevron folds it</li><li><span class="ember-key"></span>ember: what you hold or just changed</li></ul>`}function Tt(C,W){const q=u();if(!q)return"";if(C==="Data"){const V=l()?`${Hw(q.arch)}`:i1({...t.plan,canvas:t.domain??t.plan.canvas},W);return`
43
43
  <p class="lede">${l()?"The architecture as the file holds it. Edit it and press Apply: the difference is sent as operations, under the same rules as a gesture.":"The diagram as data: its boxes and its arrows. Edit it and press Apply to load it back in; that starts Undo over from here."}</p>
44
44
  <textarea id="json" spellcheck="false" aria-label="The architecture as JSON">${r(V)}</textarea>
45
45
  <p class="err" id="jsonErr" hidden></p>
@@ -49,17 +49,17 @@ ${ca(t)}}`}const e7=e=>e&&typeof e=="object"&&typeof e.id=="string"&&e.id.includ
49
49
  <div class="row"><button data-copy="mermaid" class="primary">Copy</button></div>`:`
50
50
  <p class="lede">The ElicitJS chart spec this diagram is built from: what a box and an arrow are, how each is drawn, and each edit as the call that made it. Functions show by name. It is made from the architecture, so there is nothing here to edit.</p>
51
51
  <pre class="spec" id="spec" tabindex="0" aria-label="The chart spec">${r(o1({...t.spec,data:W}))}</pre>
52
- <div class="row"><button data-copy="spec" class="primary">Copy</button></div>`}function Jt(C){const W=JSON.parse(C);if(l()){const ee=Vy(W);if(ee.length)throw new Error(ee[0]);const ue=s.server;if(!ue)throw new Error("there is no architecture to change");const{ops:be}=pg(ue.arch,{...W,rev:ue.arch.rev});be.length&&M(be,`Applied ${be.length} operation${be.length===1?"":"s"}.`);return}if(!Array.isArray(W.steps)||!Array.isArray(W.depends))throw new Error("needs a `steps` array and a `depends` array");const q=new Set(W.steps.map(ee=>ee.id)),V=W.depends.filter(ee=>!q.has(ee.source)||!q.has(ee.target));if(V.length)throw new Error(V.length===1?`an arrow names a box that is not in steps (${V[0].source} → ${V[0].target})`:`${V.length} arrows name boxes that are not in steps`);t.chart.setData({steps:W.steps,depends:W.depends}),e.render()}function qt(){if(l())return N({reseed:!0,quiet:!0});s.local&&(s.local.arch=structuredClone(s.local.sample.arch),s.local.layout=structuredClone(s.local.sample.layout),m())}function Qn(C){s.drafts={}}return{active:a,current:u,openServer:w,openSample:k,leave:_,specFor:y,mount:m,paint:Q,panel:Se,panels:$e,wirePanel:ae,save:I,catchUp:N,send:M,saveFiles:vt,pickedBox:Z,askFileInfo:rt,knownFileInfo:Pe,renderStatus:ie,sendFromBar:we,help:gt,legend:Wt,drawerBody:At,applyJSON:Jt,reset:qt,title:b,onSelect:Qn,showProposal:Y,fold:he,choosePlan:F,fp:()=>s.fp,footprintId:()=>s.footprintId,proposals:ve,refreshPlans:()=>{a()&&e.render()},host:{frames:C=>a()?re(C):void 0,newRow:C=>a()?{kind:["person","queue","store"].includes(C.kind)||C.kind==="group"?"service":C.kind,external:""}:void 0,newArrow:()=>a()?{tech:""}:void 0,menu:(C,W)=>a()?P(C,W):void 0,act:(C,W,q)=>{a()&&H(C,W,q)},fold:C=>{a()&&he(C)},folded:()=>a()&&s.view?[...s.view.proj.folded.keys()]:void 0,frozen:()=>!1,groups:()=>[]},_state:s}}function o7(e,t={}){const n={};for(const o of e.steps||[])n[o.id]={label:String(o.label??""),...o.group&&o.group!==jt?{group:o.group}:{}};const r=(e.depends||[]).map(o=>({from:o.source,to:o.target,...o.label?{label:o.label}:{},...o.kind&&o.kind!=="needs"?{kind:o.kind}:{}}));return K1({nodes:n,edges:r},t.direction==="TD"?"TD":"LR")}function s1(e,t){const n=[],r=new Map(e.steps.map(f=>[f.id,f])),o=new Map(t.steps.map(f=>[f.id,f]));for(const[f,p]of o){const h=r.get(f);if(!h){n.push(["add",`step ${f} — “${p.label}”`]);continue}h.label!==p.label&&n.push(["edit",`${f}: “${h.label}” → “${p.label}”`]),h.group!==p.group&&n.push(["edit",`${f}: group ${h.group} → ${p.group}`]),h.kind!==p.kind&&p.kind&&n.push(["edit",`${f}: ${h.kind} → ${p.kind}`]),(h.external??"")!==(p.external??"")&&p.external!==void 0&&n.push(["edit",`${f}: ${p.external?"run by someone else":"run by you"}`]),(Math.round(h.x)!==Math.round(p.x)||Math.round(h.y)!==Math.round(p.y))&&n.push(["move",`${f}: ${Math.round(h.x)},${Math.round(h.y)} → ${Math.round(p.x)},${Math.round(p.y)}`])}const i=new Set([...r.keys()].filter(f=>!o.has(f))),s=f=>i.has(f.source)||i.has(f.target);for(const f of i){const p=e.depends.filter(h=>h.source===f||h.target===f).length;n.push(["drop",p?`step ${f}, and ${p} arrow${p===1?"":"s"} with it`:`step ${f}`])}const a=f=>f.map(p=>`${p.source} → ${p.target}`),l=f=>f.split(" → ").reverse().join(" → "),u=a(e.depends.filter(f=>!s(f))),c=[];for(const f of a(t.depends)){const p=u.indexOf(f);p>=0?u.splice(p,1):c.push(f)}for(let f=u.length-1;f>=0;f--){const p=c.indexOf(l(u[f]));p<0||(n.push(["edit",`${u[f]} flipped`]),c.splice(p,1),u.splice(f,1))}for(let f=u.length-1;f>=0;f--){const[p,h]=u[f].split(" → "),y=c.findIndex(g=>{const[m,b]=g.split(" → ");return m===p||b===h});y<0||(n.push(["edit",`${u[f]} becomes ${c[y]}`]),c.splice(y,1),u.splice(f,1))}for(const f of u)n.push(["drop",f]);for(const f of c)n.push(["add",f]);const d=new Map(e.depends.map(f=>[`${f.source}>${f.target}`,f.label||""]));for(const f of t.depends){const p=d.get(`${f.source}>${f.target}`);p!==void 0&&p!==(f.label||"")&&n.push(["edit",`${f.source} → ${f.target}: label “${p}” → “${f.label||""}”`])}return n}const i7={label:"Approve architecture",primary:!0,ops:[{op:"arch.set",phase:"accepted"}],reason:"you approved the architecture",message:"Architecture approved. Your agent draws the plan on it.",tell:Y1,line:"",hint:"Approve the architecture as it is now, with your changes. Your agent draws the plan on it; from then on its changes to the architecture arrive as proposals for you to accept."},s7=e=>qw.map((t,n)=>`<li${n===e?' class="on" aria-current="step"':n<e?' class="past"':""}>${t}</li>`).join("");function a7(e,t,n=null){const r=e.listening??[];if(e.next==="approveArchitecture")return{first:{...i7,target:"architecture",line:e.line},second:null,line:e.line};const o=e.planInfo??t.find(i=>i.id===e.plan);if(o){const i=Ca(o.phase,{total:o.steps,done:o.done},r),s={...i,target:"plan",plan:o.id,...e.next==="start"&&e.why?{disabled:!0,why:e.why}:{}},a=i.second?{...i.second,target:"plan",plan:o.id}:null;return i.label==="Mark plan done"?{first:s,second:a,line:"Every step is finished: mark the plan done to close it. What it planned in the architecture is then put to you to make real."}:e.stage==="running"?{first:s,second:a,line:`${e.line} ${o.phase==="paused"?"Stop halts them now.":"Pause lets them finish the step they are on; Stop halts them now."}`}:{first:s,second:a,line:e.line}}if(n&&(n.phase==="done"||n.phase==="abandoned")){const i=Ca(n.phase,void 0),s=e.stage==="plan-wait"?" For the next task, give your agent the task: it draws the plan on the architecture you approved.":"";return{first:{...i,target:"plan",plan:n.id},second:null,line:`This plan is finished (Reopen changes it).${s||` ${e.line}`}`}}return{first:null,second:null,line:e.line}}const l7=e=>e?.waiting?.plan?String(e.waiting.plan):"";function c7(e,t){const n=e.split(`
52
+ <div class="row"><button data-copy="spec" class="primary">Copy</button></div>`}function Jt(C){const W=JSON.parse(C);if(l()){const ee=Vy(W);if(ee.length)throw new Error(ee[0]);const ue=s.server;if(!ue)throw new Error("there is no architecture to change");const{ops:be}=pg(ue.arch,{...W,rev:ue.arch.rev});be.length&&M(be,`Applied ${be.length} operation${be.length===1?"":"s"}.`);return}if(!Array.isArray(W.steps)||!Array.isArray(W.depends))throw new Error("needs a `steps` array and a `depends` array");const q=new Set(W.steps.map(ee=>ee.id)),V=W.depends.filter(ee=>!q.has(ee.source)||!q.has(ee.target));if(V.length)throw new Error(V.length===1?`an arrow names a box that is not in steps (${V[0].source} → ${V[0].target})`:`${V.length} arrows name boxes that are not in steps`);t.chart.setData({steps:W.steps,depends:W.depends}),e.render()}function qt(){if(l())return N({reseed:!0,quiet:!0});s.local&&(s.local.arch=structuredClone(s.local.sample.arch),s.local.layout=structuredClone(s.local.sample.layout),m())}function Qn(C){s.drafts={}}return{active:a,current:u,openServer:w,openSample:k,leave:_,specFor:y,mount:m,paint:Q,panel:Se,panels:_e,wirePanel:ae,save:I,catchUp:N,send:M,saveFiles:St,pickedBox:Z,askFileInfo:rt,knownFileInfo:Le,renderStatus:ie,sendFromBar:we,help:$t,legend:xt,drawerBody:Tt,applyJSON:Jt,reset:qt,title:b,onSelect:Qn,showProposal:Y,fold:he,choosePlan:F,fp:()=>s.fp,footprintId:()=>s.footprintId,proposals:ve,refreshPlans:()=>{a()&&e.render()},host:{frames:C=>a()?re(C):void 0,newRow:C=>a()?{kind:["person","queue","store"].includes(C.kind)||C.kind==="group"?"service":C.kind,external:""}:void 0,newArrow:()=>a()?{tech:""}:void 0,menu:(C,W)=>a()?P(C,W):void 0,act:(C,W,q)=>{a()&&H(C,W,q)},fold:C=>{a()&&he(C)},folded:()=>a()&&s.view?[...s.view.proj.folded.keys()]:void 0,frozen:()=>!1,groups:()=>[]},_state:s}}function o7(e,t={}){const n={};for(const o of e.steps||[])n[o.id]={label:String(o.label??""),...o.group&&o.group!==Wt?{group:o.group}:{}};const r=(e.depends||[]).map(o=>({from:o.source,to:o.target,...o.label?{label:o.label}:{},...o.kind&&o.kind!=="needs"?{kind:o.kind}:{}}));return K1({nodes:n,edges:r},t.direction==="TD"?"TD":"LR")}function s1(e,t){const n=[],r=new Map(e.steps.map(f=>[f.id,f])),o=new Map(t.steps.map(f=>[f.id,f]));for(const[f,p]of o){const h=r.get(f);if(!h){n.push(["add",`step ${f} — “${p.label}”`]);continue}h.label!==p.label&&n.push(["edit",`${f}: “${h.label}” → “${p.label}”`]),h.group!==p.group&&n.push(["edit",`${f}: group ${h.group} → ${p.group}`]),h.kind!==p.kind&&p.kind&&n.push(["edit",`${f}: ${h.kind} → ${p.kind}`]),(h.external??"")!==(p.external??"")&&p.external!==void 0&&n.push(["edit",`${f}: ${p.external?"run by someone else":"run by you"}`]),(Math.round(h.x)!==Math.round(p.x)||Math.round(h.y)!==Math.round(p.y))&&n.push(["move",`${f}: ${Math.round(h.x)},${Math.round(h.y)} → ${Math.round(p.x)},${Math.round(p.y)}`])}const i=new Set([...r.keys()].filter(f=>!o.has(f))),s=f=>i.has(f.source)||i.has(f.target);for(const f of i){const p=e.depends.filter(h=>h.source===f||h.target===f).length;n.push(["drop",p?`step ${f}, and ${p} arrow${p===1?"":"s"} with it`:`step ${f}`])}const a=f=>f.map(p=>`${p.source} → ${p.target}`),l=f=>f.split(" → ").reverse().join(" → "),u=a(e.depends.filter(f=>!s(f))),c=[];for(const f of a(t.depends)){const p=u.indexOf(f);p>=0?u.splice(p,1):c.push(f)}for(let f=u.length-1;f>=0;f--){const p=c.indexOf(l(u[f]));p<0||(n.push(["edit",`${u[f]} flipped`]),c.splice(p,1),u.splice(f,1))}for(let f=u.length-1;f>=0;f--){const[p,h]=u[f].split(" → "),y=c.findIndex(g=>{const[m,b]=g.split(" → ");return m===p||b===h});y<0||(n.push(["edit",`${u[f]} becomes ${c[y]}`]),c.splice(y,1),u.splice(f,1))}for(const f of u)n.push(["drop",f]);for(const f of c)n.push(["add",f]);const d=new Map(e.depends.map(f=>[`${f.source}>${f.target}`,f.label||""]));for(const f of t.depends){const p=d.get(`${f.source}>${f.target}`);p!==void 0&&p!==(f.label||"")&&n.push(["edit",`${f.source} → ${f.target}: label “${p}” → “${f.label||""}”`])}return n}const i7={label:"Approve architecture",primary:!0,ops:[{op:"arch.set",phase:"accepted"}],reason:"you approved the architecture",message:"Architecture approved. Your agent draws the plan on it.",tell:Y1,line:"",hint:"Approve the architecture as it is now, with your changes. Your agent draws the plan on it; from then on its changes to the architecture arrive as proposals for you to accept."},s7=e=>qw.map((t,n)=>`<li${n===e?' class="on" aria-current="step"':n<e?' class="past"':""}>${t}</li>`).join("");function a7(e,t,n=null){const r=e.listening??[];if(e.next==="approveArchitecture")return{first:{...i7,target:"architecture",line:e.line},second:null,line:e.line};const o=e.planInfo??t.find(i=>i.id===e.plan);if(o){const i=Ca(o.phase,{total:o.steps,done:o.done},r),s={...i,target:"plan",plan:o.id,...e.next==="start"&&e.why?{disabled:!0,why:e.why}:{}},a=i.second?{...i.second,target:"plan",plan:o.id}:null;return i.label==="Mark plan done"?{first:s,second:a,line:"Every step is finished: mark the plan done to close it. What it planned in the architecture is then put to you to make real."}:e.stage==="running"?{first:s,second:a,line:`${e.line} ${o.phase==="paused"?"Stop halts them now.":"Pause lets them finish the step they are on; Stop halts them now."}`}:{first:s,second:a,line:e.line}}if(n&&(n.phase==="done"||n.phase==="abandoned")){const i=Ca(n.phase,void 0),s=e.stage==="plan-wait"?" For the next task, give your agent the task: it draws the plan on the architecture you approved.":"";return{first:{...i,target:"plan",plan:n.id},second:null,line:`This plan is finished (Reopen changes it).${s||` ${e.line}`}`}}return{first:null,second:null,line:e.line}}const l7=e=>e?.waiting?.plan?String(e.waiting.plan):"";function c7(e,t){const n=e.split(`
53
53
  `),r=t.split(`
54
54
  `),o=Array.from({length:n.length+1},()=>new Array(r.length+1).fill(0));for(let l=n.length-1;l>=0;l--)for(let u=r.length-1;u>=0;u--)o[l][u]=n[l]===r[u]?o[l+1][u+1]+1:Math.max(o[l+1][u],o[l][u+1]);const i=[];let s=0,a=0;for(;s<n.length&&a<r.length;)n[s]===r[a]?(i.push([" ",n[s]]),s++,a++):o[s+1][a]>=o[s][a+1]?(i.push(["-",n[s]]),s++):(i.push(["+",r[a]]),a++);for(;s<n.length;)i.push(["-",n[s++]]);for(;a<r.length;)i.push(["+",r[a++]]);return i}const u7=(e,t)=>e?t?c7(e,t):e.split(`
55
55
  `).map(n=>["-",n]):t?t.split(`
56
- `).map(n=>["+",n]):[];function f7(e,t){const n=new Map,r=new Map,o=(i,s,a,l)=>{const u=n.get(i)??a;n.set(i,l);const c=r.get(i);if(u===l&&!c)return;const d=c?c.before:u;r.set(i,{where:s,before:d,after:l,diff:u7(d,l)})};for(const i of t)(i.op==="node.set"||i.op==="node.add")&&i.id&&typeof i.detail=="string"&&o(`${i.id}\0detail`,`${i.id}: detail`,e.nodes[i.id]?.detail??"",i.detail),i.op==="plan.set"&&typeof i.goal=="string"&&o("goal","the goal",e.goal??"",i.goal);return[...r.values()].filter(i=>i.before!==i.after)}const an={min:.25,max:2.5,step:1.2,autoMin:.85,autoMax:1.6},ir=(e,t,n)=>Math.max(t,Math.min(n,e));function d7(e,t,n){if(e.mode==="manual")return ir(e.scale,an.min,an.max);const r=Math.min(n.width/t.width,n.height/t.height);return e.mode==="fit"?ir(r,an.min,an.autoMax):ir(r,an.autoMin,an.autoMax)}const Cy=22,Ny=12,Iy={width:176,height:150};function h7(e){const{frame:t,zoomOut:n,zoomIn:r,zoomFit:o,zoomLevel:i,minimap:s}=e,a={mode:"auto",scale:1};let l=null,u={width:1,height:1},c=[];t.style.setProperty("--mx",String(xt.x)),t.style.setProperty("--my",String(xt.y));const d=document.createElement("div");d.className="mm-art";const f=document.createElement("div");f.className="mm-here",s.replaceChildren(d,f);const p=()=>({width:Math.max(1,t.offsetWidth-t.clientLeft*2-Cy*2-Ny),height:Math.max(1,t.offsetHeight-t.clientTop*2-Cy*2-Ny)});function h(M=null){if(!l)return;const $=l.getBoundingClientRect(),F=Number(t.style.getPropertyValue("--scale"))||1,D=d7(a,u,p()),z=M??(()=>{const re=t.getBoundingClientRect();return{x:re.left+re.width/2,y:re.top+re.height/2}})(),j=(z.x-$.left)/F,G=(z.y-$.top)/F;l.style.width=`${Math.round(u.width*D)}px`,t.style.setProperty("--scale",String(D));const J=l.getBoundingClientRect();t.scrollLeft+=J.left+j*D-z.x,t.scrollTop+=J.top+G*D-z.y,i.textContent=`${Math.round(D*100)}%`,n.disabled=D<=an.min+1e-6,r.disabled=D>=an.max-1e-6,o.setAttribute("aria-pressed",String(a.mode==="fit")),w(),b()}function y(M,$=null){a.mode="manual",a.scale=ir(M,an.min,an.max),h($)}const g=()=>Number(t.style.getPropertyValue("--scale"))||1,m=M=>y(g()*M);function b(){if(!l)return;const M=t.getBoundingClientRect(),$=l.getBoundingClientRect(),F=ir((M.left-$.left)/$.width,0,1),D=ir((M.right-$.left)/$.width,0,1),z=ir((M.top-$.top)/$.height,0,1),j=ir((M.bottom-$.top)/$.height,0,1),[G,J,re,Q]=[F*u.width,D*u.width,z*u.height,j*u.height];s.hidden=c.every(ve=>ve.x>=G&&ve.x<=J&&ve.y>=re&&ve.y<=Q),Object.assign(f.style,{left:`${F*100}%`,top:`${z*100}%`,width:`${(D-F)*100}%`,height:`${(j-z)*100}%`})}function w(){const M=Math.min(Iy.width,t.clientWidth*.28)/u.width,$=Math.min(Iy.height,t.clientHeight*.38)/u.height,F=Math.min(M,$);s.style.width=`${Math.round(u.width*F)}px`,s.style.height=`${Math.round(u.height*F)}px`}function x(){if(!l)return;w();const M=e.view();c=M.steps.map($=>({x:$.x+xt.x,y:$.y+xt.y})),d.innerHTML=ng(M,{title:"The whole plan, small",margin:xt}),b()}function S(M){if(!l)return;const $=s.getBoundingClientRect(),F=l.getBoundingClientRect(),D=t.getBoundingClientRect();t.scrollLeft+=F.left+(M.clientX-$.left)/$.width*F.width-(D.left+D.width/2),t.scrollTop+=F.top+(M.clientY-$.top)/$.height*F.height-(D.top+D.height/2)}let v=!1;s.addEventListener("pointerdown",M=>{v=!0,s.setPointerCapture(M.pointerId),S(M),M.preventDefault()}),s.addEventListener("pointermove",M=>{v&&S(M)});const k=()=>{v=!1};s.addEventListener("pointerup",k),s.addEventListener("pointercancel",k),t.addEventListener("scroll",b,{passive:!0}),t.addEventListener("wheel",M=>{if(!(M.ctrlKey||M.metaKey))return;M.preventDefault();const $=M.deltaMode===1?16:1;y(g()*Math.exp(-ir(M.deltaY*$,-30,30)*.01),{x:M.clientX,y:M.clientY})},{passive:!1});let _=!1,T=null;const L=M=>M instanceof HTMLElement&&!!M.closest("input, textarea, select, button, [contenteditable]");document.addEventListener("keydown",M=>{M.code!=="Space"||L(M.target)||_||(_=!0,t.classList.add("can-pan"),M.preventDefault())});const N=()=>{_=!1,t.classList.remove("can-pan")};document.addEventListener("keyup",M=>{M.code==="Space"&&N()}),addEventListener("blur",N),t.addEventListener("pointerdown",M=>{(M.button===1||M.button===0&&_)&&(M.preventDefault(),M.stopPropagation(),T={x:M.clientX,y:M.clientY,left:t.scrollLeft,top:t.scrollTop},t.setPointerCapture(M.pointerId),t.classList.add("panning"))},!0),t.addEventListener("pointermove",M=>{T&&(t.scrollLeft=T.left-(M.clientX-T.x),t.scrollTop=T.top-(M.clientY-T.y))});const I=()=>{T=null,t.classList.remove("panning")};t.addEventListener("pointerup",I),t.addEventListener("pointercancel",I),n.addEventListener("click",()=>m(1/an.step)),r.addEventListener("click",()=>m(an.step)),i.addEventListener("click",()=>y(1)),o.addEventListener("click",()=>{a.mode="fit",h(),t.scrollTo(0,0)});const O=typeof ResizeObserver>"u"?null:new ResizeObserver(M=>{M.some($=>$.target===t)?h():b()});return O?.observe(t),{attach(M,$,{keep:F=!1}={}){l=M,O?.disconnect(),O?.observe(t),O?.observe(M),u=wr($),F||(a.mode="auto"),h(),F||t.scrollTo(0,0),x()},refresh:(()=>{let M=!1;return()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,x()}))}})(),layout:h,zoomIn:()=>m(an.step),zoomOut:()=>m(1/an.step),fit(){a.mode="fit",h(),t.scrollTo(0,0)},actual:()=>y(1)}}const p7="http://www.w3.org/2000/svg";function y7({frame:e,canvas:t,chart:n,size:r,direction:o=()=>"LR",host:i}){let s=null,a=null,l,u=null,c=null,d=null,f=null,p=null;const h=()=>getComputedStyle(document.documentElement).getPropertyValue("--ember").trim()||"#EA5202",y=()=>getComputedStyle(document.documentElement).getPropertyValue("--surface").trim()||"#FFFFFF",g=()=>n()?.querySelector("svg")??null,m=()=>n()?.getData()??{steps:[],depends:[]};function b(P,H){const oe=g()?.getScreenCTM()?.inverse();if(!oe)return null;const he=new DOMPoint(P,H).matrixTransform(oe);return{x:he.x,y:he.y}}const w=P=>({x:P.x-xt.x,y:P.y-xt.y}),x=P=>{for(const H of n()?.querySelectorAll("rect")??[])if(On(H)&&Dt(H).data.id===P)return Dt(H);return null},S=P=>[...n()?.querySelectorAll("rect")??[]].find(H=>On(H)&&Dt(H).data.id===P)??null;function v(P,H){let oe=null,he=0;for(const ke of n()?.querySelectorAll("path")??[]){const pe=Dt(ke)?.data;if(pe?.source!==P||pe?.target!==H)continue;const $e=ke.getAttribute("fill");if($e&&$e!=="none")continue;const Te=ke.getTotalLength?.()??0;Te>he&&(oe=ke,he=Te)}return{el:oe,node:oe?Dt(oe):null}}const k=(P,H)=>{const oe=H.node;n().emit({editName:P,rawEvent:{by:P},...oe?{x:oe.cx??0,y:oe.cy??0}:{},...H})},_=(P,H)=>!P||!H?P===H:P.type===H.type&&(P.type==="step"?P.id===H.id:P.from===H.from&&P.to===H.to);function T(P,{silent:H=!1}={}){_(s,P)||(s=P,H||i.select?.(P),xe())}function L(P,H){const oe=b(P,H);if(!oe)return null;const he=jn(m().steps).filter(ke=>Math.abs(oe.x-ke.x)<=ke.w/2&&Math.abs(oe.y-ke.y)<=ke.h/2);return he.length?he[he.length-1].id:null}function N(P){if(!(P instanceof Element))return null;if(On(P))return{type:"step",id:Dt(P).data.id};const H=Dt(P)?.data;return H&&H.source!==void 0&&H.target!==void 0?{type:"arrow",from:H.source,to:H.target}:null}function I(P){const H=N(P.target);if(H)return H;const oe=L(P.clientX,P.clientY);return oe?{type:"step",id:oe}:null}e.addEventListener("pointerdown",P=>{p={x:P.clientX,y:P.clientY}},!0),e.addEventListener("click",P=>{!(P.target instanceof Element)||P.target.closest(".handles")||p&&Math.hypot(P.clientX-p.x,P.clientY-p.y)>4||T(I(P))});function O(){if(!s)return!1;if(i.frozen?.(s))return i.say?.("Finished work is history: reopen the step to change it.","error"),!1;const P=s.type==="step"?x(s.id):v(s.from,s.to).node;return P?(k(s.type==="step"?Je.removeStep:Je.removeArrow,{type:"click",node:P}),T(null),!0):!1}const M=P=>{const H=P.target;return H instanceof HTMLElement&&(H.tagName==="INPUT"||H.tagName==="TEXTAREA"||H.isContentEditable)?!1:H===document.body||H instanceof Node&&e.contains(H)};function $(P){if(P.key==="Escape"){if(f){P.preventDefault(),F(!0);return}if(u){P.preventDefault(),le();return}M(P)&&s&&T(null);return}if(!(!M(P)||P.metaKey||P.ctrlKey||P.altKey)){if((P.key==="Delete"||P.key==="Backspace")&&s){P.preventDefault(),O();return}if(P.key==="ContextMenu"||P.key==="F10"&&P.shiftKey){const H=document.activeElement&&On(document.activeElement)?N(document.activeElement):null;if(H&&T(H),!s)return;P.preventDefault();const oe=s.type==="step"?S(s.id)?.getBoundingClientRect():v(s.from,s.to).el?.getBoundingClientRect();oe&&j(s,{x:oe.left+oe.width/2,y:oe.top+oe.height/2})}}}document.addEventListener("keydown",$);function F(P=!1){if(!f)return;const H=f._from;f.remove(),f=null,P&&H instanceof HTMLElement&&H.isConnected&&H.focus()}document.addEventListener("pointerdown",P=>{f&&!(P.target instanceof Node&&f.contains(P.target))&&F()},!0);function D(P,H,oe){F();const he=document.createElement("div");he.className="ctxmenu",he.setAttribute("role","menu"),he._from=document.activeElement;for(const pe of P){if(pe.section&&pe.section.trim()){const Se=document.createElement("div");Se.className="ctx-sec",Se.setAttribute("role","presentation"),Se.textContent=pe.section,he.append(Se)}else if(pe.section){const Se=document.createElement("div");Se.className="ctx-sep",Se.setAttribute("role","separator"),he.append(Se)}const $e=document.createElement("button");$e.type="button",$e.tabIndex=-1,$e.className=`ctx-item${pe.danger?" danger":""}`,$e.setAttribute("role",pe.checked!==void 0?"menuitemradio":"menuitem"),pe.checked!==void 0&&$e.setAttribute("aria-checked",String(pe.checked)),pe.disabled&&($e.setAttribute("aria-disabled","true"),$e.title=pe.disabled),$e.dataset.item=pe.id;const Te=document.createElement("span");if(Te.textContent=pe.label,$e.append(Te),pe.hint){const Se=document.createElement("i");Se.textContent=pe.hint,$e.append(Se)}if(pe.key){const Se=document.createElement("kbd");Se.textContent=pe.key,$e.append(Se)}$e.addEventListener("click",()=>{if(!pe.disabled){if(pe.ask){z(he,$e,oe,pe.id,pe.ask);return}F(!1),oe(pe.id)}}),he.append($e)}he.addEventListener("keydown",pe=>{const $e=[...he.querySelectorAll('.ctx-item:not([aria-disabled="true"])')],Te=$e.indexOf(document.activeElement);pe.key==="ArrowDown"?(pe.preventDefault(),$e[(Te+1)%$e.length]?.focus()):pe.key==="ArrowUp"?(pe.preventDefault(),$e[(Te-1+$e.length)%$e.length]?.focus()):pe.key==="Home"?(pe.preventDefault(),$e[0]?.focus()):pe.key==="End"?(pe.preventDefault(),$e[$e.length-1]?.focus()):pe.key==="Tab"&&F(!0)}),document.body.append(he),f=he;const ke=he.getBoundingClientRect();he.style.left=`${Math.max(6,Math.min(H.x,innerWidth-ke.width-6))}px`,he.style.top=`${Math.max(6,Math.min(H.y,innerHeight-ke.height-6))}px`,he.querySelector('.ctx-item:not([aria-disabled="true"])')?.focus()}function z(P,H,oe,he,ke){const pe=document.createElement("input");pe.className="ctx-input",pe.placeholder=ke,pe.setAttribute("aria-label",ke),H.replaceWith(pe),pe.focus(),pe.addEventListener("keydown",$e=>{if($e.stopPropagation(),$e.key==="Escape")$e.preventDefault(),F(!0);else if($e.key==="Enter"){$e.preventDefault();const Te=pe.value.trim();if(!Te)return;F(!1),oe(he,Te)}})}function j(P,H){const oe=m(),he=P.type==="step"?oe.steps.find(Te=>Te.id===P.id):P.type==="arrow"?oe.depends.find(Te=>Te.source===P.from&&Te.target===P.to):null;if(P.type!=="canvas"&&P.type!=="frame"&&!he)return;const ke=i.groups?.()??[],pe=i.menu?.(P,he)??U3(P,{groups:ke,group:he?.group,kind:he?.kind,frozen:P.type!=="canvas"&&P.type!=="frame"&&!!i.frozen?.(P)}),$e=P.type==="canvas"?b(H.x,H.y):null;D(pe,H,(Te,Se)=>G(P,Te,Se,$e))}function G(P,H,oe,he){if(P.type==="frame"){i.act?.(H,P,oe);return}if(P.type==="canvas"){if(H==="add"&&he){const $e=w(he);n().emit({type:"dblclick",x:$e.x,y:$e.y,rawEvent:{}})}return}if(H==="delete"){O();return}if(P.type==="step"){const $e=x(P.id);if(H==="rename"){S(P.id)?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0}));return}if(!$e)return;if(H.startsWith("boxkind:")){k(Je.boxKind,{type:"commit",node:$e,value:H.slice(8)});return}if(H==="external:on"||H==="external:off"){k(Je.external,{type:"commit",node:$e,value:H==="external:on"?"yes":""});return}if(H.startsWith("into:")&&H!=="into:new"){k(Je.group,{type:"commit",node:$e,value:H==="into:top"?jt:H.slice(5)});return}if(!H.startsWith("group:")&&H!=="into:new"){i.act?.(H,P,oe);return}if(H==="into:new"){i.act?.(H,P,oe);return}const Te=H==="group:top"?jt:H==="group:new"?oe:H.slice(6);Te&&k(Je.group,{type:"commit",node:$e,value:Te});return}const{el:ke,node:pe}=v(P.from,P.to);pe&&(H==="flip"?k(Je.flip,{type:"click",node:pe}):H==="label"?ke?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0})):H.startsWith("kind:")&&k(Je.kind,{type:"commit",node:pe,value:H.slice(5)}),T({type:"arrow",from:P.from,to:P.to},{silent:!0}))}e.addEventListener("contextmenu",P=>{if(!(P.target instanceof Element)||P.target.closest(".handles"))return;P.preventDefault();const H={x:P.clientX,y:P.clientY},oe=I(P);if(oe){T(oe),j(oe,H);return}const he=b(H.x,H.y),ke=i.frames?.(),pe=ke&&he?Hd(ke,he.x,he.y):void 0;T(null),j(pe?{type:"frame",id:pe.group}:{type:"canvas"},H)});function J(P){if(clearTimeout(l),P!==a){if(P===null){l=setTimeout(()=>{a=null,xe()},160);return}a=P,xe()}}e.addEventListener("pointermove",P=>{if(P.buttons||u||f)return;const H=P.target;if(H instanceof Element){if(H.closest(".handles")){clearTimeout(l);return}J(On(H)?Dt(H).data.id:L(P.clientX,P.clientY))}}),e.addEventListener("pointerleave",()=>{u||J(null)});function re(P,H){let oe=null,he=Cd;for(const ke of jn(m().steps)){if(ke.id===H)continue;const pe=Math.hypot(ke.x-P.x,ke.y-P.y);pe<=he&&(oe=ke.id,he=pe)}return oe}function Q(P,H){const oe=x(H),he=b(P.clientX,P.clientY);!oe||!he||(P.preventDefault(),P.stopPropagation(),u={id:H,node:oe,p:he,to:null},k(Je.connect,{type:"dragstart",node:oe,x:w(he).x,y:w(he).y}),window.addEventListener("pointermove",ve),window.addEventListener("pointerup",Ce),window.addEventListener("pointercancel",le),xe())}function ve(P){if(!u)return;const H=b(P.clientX,P.clientY);H&&(u.p=H,u.to=re(H,u.id),k(Je.connect,{type:"drag",node:u.node,x:w(H).x,y:w(H).y}),xe())}function Ce(P){if(!u)return;const H=b(P.clientX,P.clientY)??u.p,{node:oe}=u;me(),k(Je.connect,{type:"dragend",node:oe,x:w(H).x,y:w(H).y}),xe()}function le(){if(!u)return;const{node:P}=u;me(),k(Je.connect,{type:"dragend",node:P,x:-1e6,y:-1e6}),xe()}function me(){u=null,window.removeEventListener("pointermove",ve),window.removeEventListener("pointerup",Ce),window.removeEventListener("pointercancel",le)}function ce(P){const H=m(),oe=H.steps.find(gt=>gt.id===P);if(!oe)return;const he=jn(H.steps),ke=he.find(gt=>gt.id===P);if(!ke)return;const pe=new Set(H.steps.map(gt=>gt.id));let $e=H.steps.length+1;for(;pe.has(`step-${$e}`);)$e++;const Te=`step-${$e}`,Se=Math.max(Xr.minWidth,78),ae=Xr.minHeight,_e=70,Z=o()==="LR"?{x:ke.x+ke.w/2+_e+Se/2,y:ke.y,w:Se,h:ae}:{x:ke.x,y:ke.y+ke.h/2+_e/1.4+ae/2,w:Se,h:ae},vt=r1(Z,he),rt=r(),dt={id:Te,label:`new ${i.noun??"step"}`,group:oe.group??jt,x:Math.round(Math.min(Math.max(vt.x-xt.x,0),rt.width)),y:Math.round(Math.min(Math.max(vt.y-xt.y,0),rt.height)),...i.newRow?.(oe)??{}};n().patch({steps:{insert:[dt]},depends:{insert:[{source:P,target:Te,label:"",kind:"needs",...i.newArrow?.()??{}}]}},{history:"record"}),i.changed(),T({type:"step",id:Te}),requestAnimationFrame(()=>requestAnimationFrame(()=>S(Te)?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0}))))}const Y=P=>i.frames?.(P)??Xy(jn(m().steps).filter(H=>H.id!==P));function fe(P){P.button!==0||!(P.target instanceof Element)||!On(P.target)||(c={id:Dt(P.target).data.id,x:P.clientX,y:P.clientY,active:!1},window.addEventListener("pointermove",ie),window.addEventListener("pointerup",U))}function ie(P){if(!c||(!c.active&&Math.hypot(P.clientX-c.x,P.clientY-c.y)>5&&(c.active=!0,J(null),a=null),!c.active))return;const H=jn(m().steps).find(he=>he.id===c?.id),oe=H?Hd(Y(H.id),H.x,H.y)?.group??null:null;oe!==d&&(d=oe,i.repaint())}function U(){window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",U);const P=c,H=d;c=null,d&&(d=null,i.repaint()),!(!P?.active||!H)&&requestAnimationFrame(()=>{const oe=m().steps.find(ke=>ke.id===P.id),he=x(P.id);oe&&he&&oe.group!==H&&!i.frozen?.({type:"step",id:P.id})&&k(Je.group,{type:"commit",node:he,value:H})})}e.addEventListener("pointerdown",fe,!0);function we(P,H={}){const oe=document.createElementNS(p7,P);for(const[he,ke]of Object.entries(H))oe.setAttribute(he,String(ke));return oe}function xe(){const P=t();if(!P||!n())return;P.querySelector(":scope > .handles")?.remove();const H=m(),oe=s?.type==="step"&&!H.steps.some(ae=>ae.id===s.id)||s?.type==="arrow"&&!H.depends.some(ae=>ae.source===s.from&&ae.target===s.to);oe&&(s=null),a&&!H.steps.some(ae=>ae.id===a)&&(a=null);const{width:he,height:ke}=wr({canvas:r()}),pe=we("svg",{class:"handles",viewBox:`0 0 ${he} ${ke}`,"aria-hidden":"true"}),$e=jn(H.steps),Te=h(),Se=y();if(s?.type==="step"){const ae=$e.find(_e=>_e.id===s.id);ae&&pe.append(we("rect",{class:"halo",x:ae.x-ae.w/2-5,y:ae.y-ae.h/2-5,width:ae.w+10,height:ae.h+10,rx:10,fill:"none",stroke:Te,"stroke-width":2.4}))}else if(s?.type==="arrow"){const{el:ae}=v(s.from,s.to),_e=g()?.getScreenCTM()?.inverse(),Pe=ae?.getScreenCTM();if(ae&&_e&&Pe){const Z=_e.multiply(Pe);pe.append(we("path",{class:"halo",d:ae.getAttribute("d")??"",transform:`matrix(${Z.a} ${Z.b} ${Z.c} ${Z.d} ${Z.e} ${Z.f})`,fill:"none",stroke:Te,"stroke-width":5,"stroke-linecap":"round",opacity:.45}))}}if(u){const ae=$e.find(Pe=>Pe.id===u?.id);ae&&pe.append(we("path",{class:"band",d:`M${ae.x} ${ae.y} L${u.p.x} ${u.p.y}`,stroke:Te,"stroke-width":2,"stroke-dasharray":"6 4",fill:"none","stroke-linecap":"round"}));const _e=$e.find(Pe=>Pe.id===u?.to);_e&&pe.append(we("rect",{class:"landing",x:_e.x-_e.w/2-5,y:_e.y-_e.h/2-5,width:_e.w+10,height:_e.h+10,rx:10,fill:Te,"fill-opacity":.12,stroke:Te,"stroke-width":2.4}))}else if(a&&!c?.active&&!f){const ae=$e.find(_e=>_e.id===a);if(ae){const _e=[["right",ae.x+ae.w/2,ae.y],["left",ae.x-ae.w/2,ae.y],["top",ae.x,ae.y-ae.h/2],["bottom",ae.x,ae.y+ae.h/2]];for(const[gt,Wt,At]of _e){const Jt=we("circle",{class:"dot",cx:Wt,cy:At,r:6,fill:Se,stroke:Te,"stroke-width":2,"data-side":gt,"data-id":ae.id});Jt.setAttribute("pointer-events","all"),Jt.addEventListener("pointerdown",qt=>Q(qt,ae.id)),pe.append(Jt)}const Pe=o()==="LR",Z=Pe?ae.x+ae.w/2+24:ae.x,vt=Pe?ae.y:ae.y+ae.h/2+24,rt=we("g",{class:"plus",transform:`translate(${Z} ${vt})`,role:"presentation"});rt.append(we("circle",{r:10,fill:Se,stroke:Te,"stroke-width":1.8}),we("path",{d:"M-4.2 0H4.2M0 -4.2V4.2",stroke:Te,"stroke-width":1.9,"stroke-linecap":"round",fill:"none"}));const dt=we("title");dt.textContent=`Add a ${i.noun??"step"} after this one`,rt.append(dt),rt.setAttribute("pointer-events","all"),rt.addEventListener("pointerdown",gt=>gt.stopPropagation()),rt.addEventListener("click",gt=>{gt.stopPropagation(),ce(ae.id)}),pe.append(rt)}}if(i.fold){const ae=(_e,Pe,Z,vt,rt)=>{const dt=we("g",{class:"fold-chip",transform:`translate(${Pe} ${Z})`,"data-id":_e,role:"presentation"});dt.append(we("circle",{r:9,fill:Se,stroke:"var(--wire)","stroke-width":1.4}));const gt=we("g",{transform:"translate(-6 -6)",color:"var(--ink)"});gt.innerHTML=fa(vt?"unfold":"fold");const Wt=we("title");Wt.textContent=rt,dt.append(gt,Wt),dt.setAttribute("pointer-events","all"),dt.addEventListener("pointerdown",At=>At.stopPropagation()),dt.addEventListener("click",At=>{At.stopPropagation(),i.fold?.(_e)}),pe.append(dt)};for(const _e of i.frames?.()??[])ae(_e.group,_e.x+_e.w-16,_e.y+15,!1,"Fold: hide what is inside, and draw its arrows to the frame");for(const _e of i.folded?.()??[]){const Pe=$e.find(Z=>Z.id===_e);Pe&&ae(_e,Pe.x+Pe.w/2-2,Pe.y-Pe.h/2+2,!0,"Unfold: show what is inside")}}P.append(pe),oe&&queueMicrotask(()=>i.select?.(null))}return{select:T,paint:xe,selection:()=>s,dropping:()=>d,deleteSelection:O,openMenuFor:j,destroy(){document.removeEventListener("keydown",$),me(),F()}}}const B=e=>document.getElementById(e),Be=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]),vl=/Mac|iPhone|iPad/i.test(navigator.userAgentData?.platform??navigator.platform??"")?"⌘":"Ctrl+",g7={samples:["Changes"],server:["Steps","Changes"]},A={mode:"plan",source:"samples",root:"",plans:[],plan:Jr[0]??nh,chart:null,spec:null,drawer:{open:!1,tab:"Data"},start:Fi(Jr[0]??nh),panel:"Changes",selected:null,server:null,domain:null};document.body.dataset.mode=A.mode;let hr=null;const Ps=()=>A.chart?A.chart.getData():Fi(A.plan),Ki=h7({frame:B("chart"),zoomOut:B("zoomOut"),zoomIn:B("zoomIn"),zoomFit:B("zoomFit"),zoomLevel:B("zoomLevel"),minimap:B("minimap"),view:()=>({...A.plan,...Ps()})});let io={};const Qc=new Set;async function Ea(e){const{field:t,step:n}=e.dataset,r=n?A.server?.plan.nodes[n]:void 0;if(!n||!r||t!=="detail")return;const o=J1(n,t,e.value);if((o.detail??"")===(r.detail??"")){n===A.selected&&delete io[t];return}const s=`${n}\0${t}`;if(!Qc.has(s)){Qc.add(s);try{await Kt([o],`Saved what done means for ${r.label}.`,`you edited the ${t} of ${n}`)&&n===A.selected&&(delete io[t],dn())}finally{Qc.delete(s)}}}window.addEventListener("blur",()=>{const e=document.activeElement;e instanceof HTMLTextAreaElement&&e.dataset.field&&B("panel").contains(e)&&Ea(e)});function Vo(e){e!==A.selected&&(io={},B("panel").contains(document.activeElement)&&document.activeElement.blur()),A.selected=e,Ye.onSelect(e),e&&A.mode==="plan"&&E7(),Xo.select(e?{type:"step",id:e}:null,{silent:!0});const t=A.mode==="architecture"?"Boxes":"Steps";e&&A.panel!==t&&(A.mode!=="architecture"||A.source==="server")?pr(t):dn(),e&&B("panel").querySelector(".inspector")?.scrollIntoView({block:"nearest"})}const Xo=y7({frame:B("chart"),canvas:()=>B("chart").querySelector(".canvas"),chart:()=>A.chart,size:()=>A.domain??{width:0,height:0},direction:()=>A.plan?.direction==="TD"?"TD":"LR",host:{select:e=>{if(A.source==="server"){if(e?.type==="step"){e.id!==A.selected&&Vo(e.id);return}A.selected&&(io={},A.selected=null,dn())}},frozen:e=>!!hr&&(e.type==="step"?hr.frozen({id:e.id},"steps"):hr.frozen({target:e.to},"depends")),groups:()=>Gy({steps:Ps().steps}),frames:e=>Ye.host.frames(e),newRow:e=>Ye.host.newRow(e),newArrow:()=>Ye.host.newArrow(),menu:(e,t)=>Ye.host.menu(e,t),act:(e,t,n)=>Ye.host.act(e,t,n),fold:e=>Ye.host.fold(e),folded:()=>Ye.host.folded(),get noun(){return A.mode==="architecture"?"box":"step"},changed:()=>Jo(),repaint:()=>Rd(),say:(e,t)=>Ge(e,t)}});A3({frame:B("chart"),chart:()=>A.chart,onSelect:e=>{A.source==="server"?Vo(e):Xo.select({type:"step",id:e})}});function po(e){const t=!!A.chart&&A.plan?.id===e.id;ws(null),A.plan=e,A.start=Fi(e),A.domain=e.canvas,A.chart&&A.chart.destroy?.();const n=document.createElement("div");n.className="canvas",B("chart").replaceChildren(n),hr=A.source==="server"&&A.mode==="plan"?Kw(()=>A.server):null,A.spec=A.mode==="architecture"?Ye.specFor({...e,...Fi(e)},Jo):M3({...e,...Fi(e)},{onChange:Jo,decor:hr??void 0}),A.chart=ab(A.spec),n.appendChild(A.chart),Ki.attach(n,e,{keep:t}),M7(),b7(),m7(),B("source").hidden=!e.source,B("source").href=e.source||"#",B("planNote").textContent=e.note,f1(e),dn()}function m7(){if(A.mode==="architecture"){B("helpBody").innerHTML=Ye.help();return}const e=A.source==="server",t=g3.map(([n,r,o,i])=>`
56
+ `).map(n=>["+",n]):[];function f7(e,t){const n=new Map,r=new Map,o=(i,s,a,l)=>{const u=n.get(i)??a;n.set(i,l);const c=r.get(i);if(u===l&&!c)return;const d=c?c.before:u;r.set(i,{where:s,before:d,after:l,diff:u7(d,l)})};for(const i of t)(i.op==="node.set"||i.op==="node.add")&&i.id&&typeof i.detail=="string"&&o(`${i.id}\0detail`,`${i.id}: detail`,e.nodes[i.id]?.detail??"",i.detail),i.op==="plan.set"&&typeof i.goal=="string"&&o("goal","the goal",e.goal??"",i.goal);return[...r.values()].filter(i=>i.before!==i.after)}const an={min:.25,max:2.5,step:1.2,autoMin:.85,autoMax:1.6},ir=(e,t,n)=>Math.max(t,Math.min(n,e));function d7(e,t,n){if(e.mode==="manual")return ir(e.scale,an.min,an.max);const r=Math.min(n.width/t.width,n.height/t.height);return e.mode==="fit"?ir(r,an.min,an.autoMax):ir(r,an.autoMin,an.autoMax)}const Cy=22,Ny=12,Iy={width:176,height:150};function h7(e){const{frame:t,zoomOut:n,zoomIn:r,zoomFit:o,zoomLevel:i,minimap:s}=e,a={mode:"auto",scale:1};let l=null,u={width:1,height:1},c=[];t.style.setProperty("--mx",String(wt.x)),t.style.setProperty("--my",String(wt.y));const d=document.createElement("div");d.className="mm-art";const f=document.createElement("div");f.className="mm-here",s.replaceChildren(d,f);const p=()=>({width:Math.max(1,t.offsetWidth-t.clientLeft*2-Cy*2-Ny),height:Math.max(1,t.offsetHeight-t.clientTop*2-Cy*2-Ny)});function h(M=null){if(!l)return;const $=l.getBoundingClientRect(),F=Number(t.style.getPropertyValue("--scale"))||1,D=d7(a,u,p()),z=M??(()=>{const re=t.getBoundingClientRect();return{x:re.left+re.width/2,y:re.top+re.height/2}})(),j=(z.x-$.left)/F,G=(z.y-$.top)/F;l.style.width=`${Math.round(u.width*D)}px`,t.style.setProperty("--scale",String(D));const J=l.getBoundingClientRect();t.scrollLeft+=J.left+j*D-z.x,t.scrollTop+=J.top+G*D-z.y,i.textContent=`${Math.round(D*100)}%`,n.disabled=D<=an.min+1e-6,r.disabled=D>=an.max-1e-6,o.setAttribute("aria-pressed",String(a.mode==="fit")),w(),b()}function y(M,$=null){a.mode="manual",a.scale=ir(M,an.min,an.max),h($)}const g=()=>Number(t.style.getPropertyValue("--scale"))||1,m=M=>y(g()*M);function b(){if(!l)return;const M=t.getBoundingClientRect(),$=l.getBoundingClientRect(),F=ir((M.left-$.left)/$.width,0,1),D=ir((M.right-$.left)/$.width,0,1),z=ir((M.top-$.top)/$.height,0,1),j=ir((M.bottom-$.top)/$.height,0,1),[G,J,re,Q]=[F*u.width,D*u.width,z*u.height,j*u.height];s.hidden=c.every(ve=>ve.x>=G&&ve.x<=J&&ve.y>=re&&ve.y<=Q),Object.assign(f.style,{left:`${F*100}%`,top:`${z*100}%`,width:`${(D-F)*100}%`,height:`${(j-z)*100}%`})}function w(){const M=Math.min(Iy.width,t.clientWidth*.28)/u.width,$=Math.min(Iy.height,t.clientHeight*.38)/u.height,F=Math.min(M,$);s.style.width=`${Math.round(u.width*F)}px`,s.style.height=`${Math.round(u.height*F)}px`}function x(){if(!l)return;w();const M=e.view();c=M.steps.map($=>({x:$.x+wt.x,y:$.y+wt.y})),d.innerHTML=ng(M,{title:"The whole plan, small",margin:wt}),b()}function S(M){if(!l)return;const $=s.getBoundingClientRect(),F=l.getBoundingClientRect(),D=t.getBoundingClientRect();t.scrollLeft+=F.left+(M.clientX-$.left)/$.width*F.width-(D.left+D.width/2),t.scrollTop+=F.top+(M.clientY-$.top)/$.height*F.height-(D.top+D.height/2)}let v=!1;s.addEventListener("pointerdown",M=>{v=!0,s.setPointerCapture(M.pointerId),S(M),M.preventDefault()}),s.addEventListener("pointermove",M=>{v&&S(M)});const k=()=>{v=!1};s.addEventListener("pointerup",k),s.addEventListener("pointercancel",k),t.addEventListener("scroll",b,{passive:!0}),t.addEventListener("wheel",M=>{if(!(M.ctrlKey||M.metaKey))return;M.preventDefault();const $=M.deltaMode===1?16:1;y(g()*Math.exp(-ir(M.deltaY*$,-30,30)*.01),{x:M.clientX,y:M.clientY})},{passive:!1});let _=!1,T=null;const L=M=>M instanceof HTMLElement&&!!M.closest("input, textarea, select, button, [contenteditable]");document.addEventListener("keydown",M=>{M.code!=="Space"||L(M.target)||_||(_=!0,t.classList.add("can-pan"),M.preventDefault())});const N=()=>{_=!1,t.classList.remove("can-pan")};document.addEventListener("keyup",M=>{M.code==="Space"&&N()}),addEventListener("blur",N),t.addEventListener("pointerdown",M=>{(M.button===1||M.button===0&&_)&&(M.preventDefault(),M.stopPropagation(),T={x:M.clientX,y:M.clientY,left:t.scrollLeft,top:t.scrollTop},t.setPointerCapture(M.pointerId),t.classList.add("panning"))},!0),t.addEventListener("pointermove",M=>{T&&(t.scrollLeft=T.left-(M.clientX-T.x),t.scrollTop=T.top-(M.clientY-T.y))});const I=()=>{T=null,t.classList.remove("panning")};t.addEventListener("pointerup",I),t.addEventListener("pointercancel",I),n.addEventListener("click",()=>m(1/an.step)),r.addEventListener("click",()=>m(an.step)),i.addEventListener("click",()=>y(1)),o.addEventListener("click",()=>{a.mode="fit",h(),t.scrollTo(0,0)});const O=typeof ResizeObserver>"u"?null:new ResizeObserver(M=>{M.some($=>$.target===t)?h():b()});return O?.observe(t),{attach(M,$,{keep:F=!1}={}){l=M,O?.disconnect(),O?.observe(t),O?.observe(M),u=wr($),F||(a.mode="auto"),h(),F||t.scrollTo(0,0),x()},refresh:(()=>{let M=!1;return()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,x()}))}})(),layout:h,zoomIn:()=>m(an.step),zoomOut:()=>m(1/an.step),fit(){a.mode="fit",h(),t.scrollTo(0,0)},actual:()=>y(1)}}const p7="http://www.w3.org/2000/svg";function y7({frame:e,canvas:t,chart:n,size:r,direction:o=()=>"LR",host:i}){let s=null,a=null,l,u=null,c=null,d=null,f=null,p=null;const h=()=>getComputedStyle(document.documentElement).getPropertyValue("--ember").trim()||"#EA5202",y=()=>getComputedStyle(document.documentElement).getPropertyValue("--surface").trim()||"#FFFFFF",g=()=>n()?.querySelector("svg")??null,m=()=>n()?.getData()??{steps:[],depends:[]};function b(P,H){const oe=g()?.getScreenCTM()?.inverse();if(!oe)return null;const he=new DOMPoint(P,H).matrixTransform(oe);return{x:he.x,y:he.y}}const w=P=>({x:P.x-wt.x,y:P.y-wt.y}),x=P=>{for(const H of n()?.querySelectorAll("rect")??[])if(On(H)&&jt(H).data.id===P)return jt(H);return null},S=P=>[...n()?.querySelectorAll("rect")??[]].find(H=>On(H)&&jt(H).data.id===P)??null;function v(P,H){let oe=null,he=0;for(const ke of n()?.querySelectorAll("path")??[]){const pe=jt(ke)?.data;if(pe?.source!==P||pe?.target!==H)continue;const _e=ke.getAttribute("fill");if(_e&&_e!=="none")continue;const Te=ke.getTotalLength?.()??0;Te>he&&(oe=ke,he=Te)}return{el:oe,node:oe?jt(oe):null}}const k=(P,H)=>{const oe=H.node;n().emit({editName:P,rawEvent:{by:P},...oe?{x:oe.cx??0,y:oe.cy??0}:{},...H})},_=(P,H)=>!P||!H?P===H:P.type===H.type&&(P.type==="step"?P.id===H.id:P.from===H.from&&P.to===H.to);function T(P,{silent:H=!1}={}){_(s,P)||(s=P,H||i.select?.(P),xe())}function L(P,H){const oe=b(P,H);if(!oe)return null;const he=jn(m().steps).filter(ke=>Math.abs(oe.x-ke.x)<=ke.w/2&&Math.abs(oe.y-ke.y)<=ke.h/2);return he.length?he[he.length-1].id:null}function N(P){if(!(P instanceof Element))return null;if(On(P))return{type:"step",id:jt(P).data.id};const H=jt(P)?.data;return H&&H.source!==void 0&&H.target!==void 0?{type:"arrow",from:H.source,to:H.target}:null}function I(P){const H=N(P.target);if(H)return H;const oe=L(P.clientX,P.clientY);return oe?{type:"step",id:oe}:null}e.addEventListener("pointerdown",P=>{p={x:P.clientX,y:P.clientY}},!0),e.addEventListener("click",P=>{!(P.target instanceof Element)||P.target.closest(".handles")||p&&Math.hypot(P.clientX-p.x,P.clientY-p.y)>4||T(I(P))});function O(){if(!s)return!1;if(i.frozen?.(s))return i.say?.("Finished work is history: reopen the step to change it.","error"),!1;const P=s.type==="step"?x(s.id):v(s.from,s.to).node;return P?(k(s.type==="step"?Je.removeStep:Je.removeArrow,{type:"click",node:P}),T(null),!0):!1}const M=P=>{const H=P.target;return H instanceof HTMLElement&&(H.tagName==="INPUT"||H.tagName==="TEXTAREA"||H.isContentEditable)?!1:H===document.body||H instanceof Node&&e.contains(H)};function $(P){if(P.key==="Escape"){if(f){P.preventDefault(),F(!0);return}if(u){P.preventDefault(),le();return}M(P)&&s&&T(null);return}if(!(!M(P)||P.metaKey||P.ctrlKey||P.altKey)){if((P.key==="Delete"||P.key==="Backspace")&&s){P.preventDefault(),O();return}if(P.key==="ContextMenu"||P.key==="F10"&&P.shiftKey){const H=document.activeElement&&On(document.activeElement)?N(document.activeElement):null;if(H&&T(H),!s)return;P.preventDefault();const oe=s.type==="step"?S(s.id)?.getBoundingClientRect():v(s.from,s.to).el?.getBoundingClientRect();oe&&j(s,{x:oe.left+oe.width/2,y:oe.top+oe.height/2})}}}document.addEventListener("keydown",$);function F(P=!1){if(!f)return;const H=f._from;f.remove(),f=null,P&&H instanceof HTMLElement&&H.isConnected&&H.focus()}document.addEventListener("pointerdown",P=>{f&&!(P.target instanceof Node&&f.contains(P.target))&&F()},!0);function D(P,H,oe){F();const he=document.createElement("div");he.className="ctxmenu",he.setAttribute("role","menu"),he._from=document.activeElement;for(const pe of P){if(pe.section&&pe.section.trim()){const Se=document.createElement("div");Se.className="ctx-sec",Se.setAttribute("role","presentation"),Se.textContent=pe.section,he.append(Se)}else if(pe.section){const Se=document.createElement("div");Se.className="ctx-sep",Se.setAttribute("role","separator"),he.append(Se)}const _e=document.createElement("button");_e.type="button",_e.tabIndex=-1,_e.className=`ctx-item${pe.danger?" danger":""}`,_e.setAttribute("role",pe.checked!==void 0?"menuitemradio":"menuitem"),pe.checked!==void 0&&_e.setAttribute("aria-checked",String(pe.checked)),pe.disabled&&(_e.setAttribute("aria-disabled","true"),_e.title=pe.disabled),_e.dataset.item=pe.id;const Te=document.createElement("span");if(Te.textContent=pe.label,_e.append(Te),pe.hint){const Se=document.createElement("i");Se.textContent=pe.hint,_e.append(Se)}if(pe.key){const Se=document.createElement("kbd");Se.textContent=pe.key,_e.append(Se)}_e.addEventListener("click",()=>{if(!pe.disabled){if(pe.ask){z(he,_e,oe,pe.id,pe.ask);return}F(!1),oe(pe.id)}}),he.append(_e)}he.addEventListener("keydown",pe=>{const _e=[...he.querySelectorAll('.ctx-item:not([aria-disabled="true"])')],Te=_e.indexOf(document.activeElement);pe.key==="ArrowDown"?(pe.preventDefault(),_e[(Te+1)%_e.length]?.focus()):pe.key==="ArrowUp"?(pe.preventDefault(),_e[(Te-1+_e.length)%_e.length]?.focus()):pe.key==="Home"?(pe.preventDefault(),_e[0]?.focus()):pe.key==="End"?(pe.preventDefault(),_e[_e.length-1]?.focus()):pe.key==="Tab"&&F(!0)}),document.body.append(he),f=he;const ke=he.getBoundingClientRect();he.style.left=`${Math.max(6,Math.min(H.x,innerWidth-ke.width-6))}px`,he.style.top=`${Math.max(6,Math.min(H.y,innerHeight-ke.height-6))}px`,he.querySelector('.ctx-item:not([aria-disabled="true"])')?.focus()}function z(P,H,oe,he,ke){const pe=document.createElement("input");pe.className="ctx-input",pe.placeholder=ke,pe.setAttribute("aria-label",ke),H.replaceWith(pe),pe.focus(),pe.addEventListener("keydown",_e=>{if(_e.stopPropagation(),_e.key==="Escape")_e.preventDefault(),F(!0);else if(_e.key==="Enter"){_e.preventDefault();const Te=pe.value.trim();if(!Te)return;F(!1),oe(he,Te)}})}function j(P,H){const oe=m(),he=P.type==="step"?oe.steps.find(Te=>Te.id===P.id):P.type==="arrow"?oe.depends.find(Te=>Te.source===P.from&&Te.target===P.to):null;if(P.type!=="canvas"&&P.type!=="frame"&&!he)return;const ke=i.groups?.()??[],pe=i.menu?.(P,he)??U3(P,{groups:ke,group:he?.group,kind:he?.kind,frozen:P.type!=="canvas"&&P.type!=="frame"&&!!i.frozen?.(P)}),_e=P.type==="canvas"?b(H.x,H.y):null;D(pe,H,(Te,Se)=>G(P,Te,Se,_e))}function G(P,H,oe,he){if(P.type==="frame"){i.act?.(H,P,oe);return}if(P.type==="canvas"){if(H==="add"&&he){const _e=w(he);n().emit({type:"dblclick",x:_e.x,y:_e.y,rawEvent:{}})}return}if(H==="delete"){O();return}if(P.type==="step"){const _e=x(P.id);if(H==="rename"){S(P.id)?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0}));return}if(!_e)return;if(H.startsWith("boxkind:")){k(Je.boxKind,{type:"commit",node:_e,value:H.slice(8)});return}if(H==="external:on"||H==="external:off"){k(Je.external,{type:"commit",node:_e,value:H==="external:on"?"yes":""});return}if(H.startsWith("into:")&&H!=="into:new"){k(Je.group,{type:"commit",node:_e,value:H==="into:top"?Wt:H.slice(5)});return}if(!H.startsWith("group:")&&H!=="into:new"){i.act?.(H,P,oe);return}if(H==="into:new"){i.act?.(H,P,oe);return}const Te=H==="group:top"?Wt:H==="group:new"?oe:H.slice(6);Te&&k(Je.group,{type:"commit",node:_e,value:Te});return}const{el:ke,node:pe}=v(P.from,P.to);pe&&(H==="flip"?k(Je.flip,{type:"click",node:pe}):H==="label"?ke?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0})):H.startsWith("kind:")&&k(Je.kind,{type:"commit",node:pe,value:H.slice(5)}),T({type:"arrow",from:P.from,to:P.to},{silent:!0}))}e.addEventListener("contextmenu",P=>{if(!(P.target instanceof Element)||P.target.closest(".handles"))return;P.preventDefault();const H={x:P.clientX,y:P.clientY},oe=I(P);if(oe){T(oe),j(oe,H);return}const he=b(H.x,H.y),ke=i.frames?.(),pe=ke&&he?Hd(ke,he.x,he.y):void 0;T(null),j(pe?{type:"frame",id:pe.group}:{type:"canvas"},H)});function J(P){if(clearTimeout(l),P!==a){if(P===null){l=setTimeout(()=>{a=null,xe()},160);return}a=P,xe()}}e.addEventListener("pointermove",P=>{if(P.buttons||u||f)return;const H=P.target;if(H instanceof Element){if(H.closest(".handles")){clearTimeout(l);return}J(On(H)?jt(H).data.id:L(P.clientX,P.clientY))}}),e.addEventListener("pointerleave",()=>{u||J(null)});function re(P,H){let oe=null,he=Cd;for(const ke of jn(m().steps)){if(ke.id===H)continue;const pe=Math.hypot(ke.x-P.x,ke.y-P.y);pe<=he&&(oe=ke.id,he=pe)}return oe}function Q(P,H){const oe=x(H),he=b(P.clientX,P.clientY);!oe||!he||(P.preventDefault(),P.stopPropagation(),u={id:H,node:oe,p:he,to:null},k(Je.connect,{type:"dragstart",node:oe,x:w(he).x,y:w(he).y}),window.addEventListener("pointermove",ve),window.addEventListener("pointerup",Ce),window.addEventListener("pointercancel",le),xe())}function ve(P){if(!u)return;const H=b(P.clientX,P.clientY);H&&(u.p=H,u.to=re(H,u.id),k(Je.connect,{type:"drag",node:u.node,x:w(H).x,y:w(H).y}),xe())}function Ce(P){if(!u)return;const H=b(P.clientX,P.clientY)??u.p,{node:oe}=u;me(),k(Je.connect,{type:"dragend",node:oe,x:w(H).x,y:w(H).y}),xe()}function le(){if(!u)return;const{node:P}=u;me(),k(Je.connect,{type:"dragend",node:P,x:-1e6,y:-1e6}),xe()}function me(){u=null,window.removeEventListener("pointermove",ve),window.removeEventListener("pointerup",Ce),window.removeEventListener("pointercancel",le)}function ce(P){const H=m(),oe=H.steps.find(xt=>xt.id===P);if(!oe)return;const he=jn(H.steps),ke=he.find(xt=>xt.id===P);if(!ke)return;const pe=new Set(H.steps.map(xt=>xt.id));let _e=H.steps.length+1;const Te=i.noun??"step";for(;pe.has(`${Te}-${_e}`);)_e++;const Se=`${Te}-${_e}`,ae=Math.max(Xr.minWidth,78),$e=Xr.minHeight,Le=70,St=o()==="LR"?{x:ke.x+ke.w/2+Le+ae/2,y:ke.y,w:ae,h:$e}:{x:ke.x,y:ke.y+ke.h/2+Le/1.4+$e/2,w:ae,h:$e},rt=r1(St,he),ct=r(),$t={id:Se,label:`new ${i.noun??"step"}`,group:oe.group??Wt,x:Math.round(Math.min(Math.max(rt.x-wt.x,0),ct.width)),y:Math.round(Math.min(Math.max(rt.y-wt.y,0),ct.height)),...i.newRow?.(oe)??{}};n().patch({steps:{insert:[$t]},depends:{insert:[{source:P,target:Se,label:"",kind:"needs",...i.newArrow?.()??{}}]}},{history:"record"}),i.changed(),T({type:"step",id:Se}),requestAnimationFrame(()=>requestAnimationFrame(()=>S(Se)?.dispatchEvent(new MouseEvent("dblclick",{bubbles:!0,cancelable:!0}))))}const Y=P=>i.frames?.(P)??Xy(jn(m().steps).filter(H=>H.id!==P));function fe(P){P.button!==0||!(P.target instanceof Element)||!On(P.target)||(c={id:jt(P.target).data.id,x:P.clientX,y:P.clientY,active:!1},window.addEventListener("pointermove",ie),window.addEventListener("pointerup",U))}function ie(P){if(!c||(!c.active&&Math.hypot(P.clientX-c.x,P.clientY-c.y)>5&&(c.active=!0,J(null),a=null),!c.active))return;const H=jn(m().steps).find(he=>he.id===c?.id),oe=H?Hd(Y(H.id),H.x,H.y)?.group??null:null;oe!==d&&(d=oe,i.repaint())}function U(){window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",U);const P=c,H=d;c=null,d&&(d=null,i.repaint()),!(!P?.active||!H)&&requestAnimationFrame(()=>{const oe=m().steps.find(ke=>ke.id===P.id),he=x(P.id);oe&&he&&oe.group!==H&&!i.frozen?.({type:"step",id:P.id})&&k(Je.group,{type:"commit",node:he,value:H})})}e.addEventListener("pointerdown",fe,!0);function we(P,H={}){const oe=document.createElementNS(p7,P);for(const[he,ke]of Object.entries(H))oe.setAttribute(he,String(ke));return oe}function xe(){const P=t();if(!P||!n())return;P.querySelector(":scope > .handles")?.remove();const H=m(),oe=s?.type==="step"&&!H.steps.some(ae=>ae.id===s.id)||s?.type==="arrow"&&!H.depends.some(ae=>ae.source===s.from&&ae.target===s.to);oe&&(s=null),a&&!H.steps.some(ae=>ae.id===a)&&(a=null);const{width:he,height:ke}=wr({canvas:r()}),pe=we("svg",{class:"handles",viewBox:`0 0 ${he} ${ke}`,"aria-hidden":"true"}),_e=jn(H.steps),Te=h(),Se=y();if(s?.type==="step"){const ae=_e.find($e=>$e.id===s.id);ae&&pe.append(we("rect",{class:"halo",x:ae.x-ae.w/2-5,y:ae.y-ae.h/2-5,width:ae.w+10,height:ae.h+10,rx:10,fill:"none",stroke:Te,"stroke-width":2.4}))}else if(s?.type==="arrow"){const{el:ae}=v(s.from,s.to),$e=g()?.getScreenCTM()?.inverse(),Le=ae?.getScreenCTM();if(ae&&$e&&Le){const Z=$e.multiply(Le);pe.append(we("path",{class:"halo",d:ae.getAttribute("d")??"",transform:`matrix(${Z.a} ${Z.b} ${Z.c} ${Z.d} ${Z.e} ${Z.f})`,fill:"none",stroke:Te,"stroke-width":5,"stroke-linecap":"round",opacity:.45}))}}if(u){const ae=_e.find(Le=>Le.id===u?.id);ae&&pe.append(we("path",{class:"band",d:`M${ae.x} ${ae.y} L${u.p.x} ${u.p.y}`,stroke:Te,"stroke-width":2,"stroke-dasharray":"6 4",fill:"none","stroke-linecap":"round"}));const $e=_e.find(Le=>Le.id===u?.to);$e&&pe.append(we("rect",{class:"landing",x:$e.x-$e.w/2-5,y:$e.y-$e.h/2-5,width:$e.w+10,height:$e.h+10,rx:10,fill:Te,"fill-opacity":.12,stroke:Te,"stroke-width":2.4}))}else if(a&&!c?.active&&!f){const ae=_e.find($e=>$e.id===a);if(ae){const $e=[["right",ae.x+ae.w/2,ae.y],["left",ae.x-ae.w/2,ae.y],["top",ae.x,ae.y-ae.h/2],["bottom",ae.x,ae.y+ae.h/2]];for(const[$t,xt,Tt]of $e){const Jt=we("circle",{class:"dot",cx:xt,cy:Tt,r:6,fill:Se,stroke:Te,"stroke-width":2,"data-side":$t,"data-id":ae.id});Jt.setAttribute("pointer-events","all"),Jt.addEventListener("pointerdown",qt=>Q(qt,ae.id)),pe.append(Jt)}const Le=o()==="LR",Z=Le?ae.x+ae.w/2+24:ae.x,St=Le?ae.y:ae.y+ae.h/2+24,rt=we("g",{class:"plus",transform:`translate(${Z} ${St})`,role:"presentation"});rt.append(we("circle",{r:10,fill:Se,stroke:Te,"stroke-width":1.8}),we("path",{d:"M-4.2 0H4.2M0 -4.2V4.2",stroke:Te,"stroke-width":1.9,"stroke-linecap":"round",fill:"none"}));const ct=we("title");ct.textContent=`Add a ${i.noun??"step"} after this one`,rt.append(ct),rt.setAttribute("pointer-events","all"),rt.addEventListener("pointerdown",$t=>$t.stopPropagation()),rt.addEventListener("click",$t=>{$t.stopPropagation(),ce(ae.id)}),pe.append(rt)}}if(i.fold){const ae=($e,Le,Z,St,rt)=>{const ct=we("g",{class:"fold-chip",transform:`translate(${Le} ${Z})`,"data-id":$e,role:"presentation"});ct.append(we("circle",{r:9,fill:Se,stroke:"var(--wire)","stroke-width":1.4}));const $t=we("g",{transform:"translate(-6 -6)",color:"var(--ink)"});$t.innerHTML=fa(St?"unfold":"fold");const xt=we("title");xt.textContent=rt,ct.append($t,xt),ct.setAttribute("pointer-events","all"),ct.addEventListener("pointerdown",Tt=>Tt.stopPropagation()),ct.addEventListener("click",Tt=>{Tt.stopPropagation(),i.fold?.($e)}),pe.append(ct)};for(const $e of i.frames?.()??[])ae($e.group,$e.x+$e.w-16,$e.y+15,!1,"Fold: hide what is inside, and draw its arrows to the frame");for(const $e of i.folded?.()??[]){const Le=_e.find(Z=>Z.id===$e);Le&&ae($e,Le.x+Le.w/2-2,Le.y-Le.h/2+2,!0,"Unfold: show what is inside")}}P.append(pe),oe&&queueMicrotask(()=>i.select?.(null))}return{select:T,paint:xe,selection:()=>s,dropping:()=>d,deleteSelection:O,openMenuFor:j,destroy(){document.removeEventListener("keydown",$),me(),F()}}}const B=e=>document.getElementById(e),Be=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]),vl=/Mac|iPhone|iPad/i.test(navigator.userAgentData?.platform??navigator.platform??"")?"⌘":"Ctrl+",g7={samples:["Changes"],server:["Steps","Changes"]},A={mode:"plan",source:"samples",root:"",plans:[],plan:Jr[0]??nh,chart:null,spec:null,drawer:{open:!1,tab:"Data"},start:Fi(Jr[0]??nh),panel:"Changes",selected:null,server:null,domain:null};document.body.dataset.mode=A.mode;let hr=null;const Ps=()=>A.chart?A.chart.getData():Fi(A.plan),Ki=h7({frame:B("chart"),zoomOut:B("zoomOut"),zoomIn:B("zoomIn"),zoomFit:B("zoomFit"),zoomLevel:B("zoomLevel"),minimap:B("minimap"),view:()=>({...A.plan,...Ps()})});let io={};const Qc=new Set;async function Ea(e){const{field:t,step:n}=e.dataset,r=n?A.server?.plan.nodes[n]:void 0;if(!n||!r||t!=="detail")return;const o=J1(n,t,e.value);if((o.detail??"")===(r.detail??"")){n===A.selected&&delete io[t];return}const s=`${n}\0${t}`;if(!Qc.has(s)){Qc.add(s);try{await Kt([o],`Saved what done means for ${r.label}.`,`you edited the ${t} of ${n}`)&&n===A.selected&&(delete io[t],dn())}finally{Qc.delete(s)}}}window.addEventListener("blur",()=>{const e=document.activeElement;e instanceof HTMLTextAreaElement&&e.dataset.field&&B("panel").contains(e)&&Ea(e)});function Vo(e){e!==A.selected&&(io={},B("panel").contains(document.activeElement)&&document.activeElement.blur()),A.selected=e,Ye.onSelect(e),e&&A.mode==="plan"&&E7(),Xo.select(e?{type:"step",id:e}:null,{silent:!0});const t=A.mode==="architecture"?"Boxes":"Steps";e&&A.panel!==t&&(A.mode!=="architecture"||A.source==="server")?pr(t):dn(),e&&B("panel").querySelector(".inspector")?.scrollIntoView({block:"nearest"})}const Xo=y7({frame:B("chart"),canvas:()=>B("chart").querySelector(".canvas"),chart:()=>A.chart,size:()=>A.domain??{width:0,height:0},direction:()=>A.plan?.direction==="TD"?"TD":"LR",host:{select:e=>{if(A.source==="server"){if(e?.type==="step"){e.id!==A.selected&&Vo(e.id);return}A.selected&&(io={},A.selected=null,dn())}},frozen:e=>!!hr&&(e.type==="step"?hr.frozen({id:e.id},"steps"):hr.frozen({target:e.to},"depends")),groups:()=>Gy({steps:Ps().steps}),frames:e=>Ye.host.frames(e),newRow:e=>Ye.host.newRow(e),newArrow:()=>Ye.host.newArrow(),menu:(e,t)=>Ye.host.menu(e,t),act:(e,t,n)=>Ye.host.act(e,t,n),fold:e=>Ye.host.fold(e),folded:()=>Ye.host.folded(),get noun(){return A.mode==="architecture"?"box":"step"},changed:()=>Jo(),repaint:()=>Rd(),say:(e,t)=>Ge(e,t)}});A3({frame:B("chart"),chart:()=>A.chart,onSelect:e=>{A.source==="server"?Vo(e):Xo.select({type:"step",id:e})}});function po(e){const t=!!A.chart&&A.plan?.id===e.id;ws(null),A.plan=e,A.start=Fi(e),A.domain=e.canvas,A.chart&&A.chart.destroy?.();const n=document.createElement("div");n.className="canvas",B("chart").replaceChildren(n),hr=A.source==="server"&&A.mode==="plan"?Kw(()=>A.server):null,A.spec=A.mode==="architecture"?Ye.specFor({...e,...Fi(e)},Jo):M3({...e,...Fi(e)},{onChange:Jo,decor:hr??void 0}),A.chart=ab(A.spec),n.appendChild(A.chart),Ki.attach(n,e,{keep:t}),M7(),b7(),m7(),B("source").hidden=!e.source,B("source").href=e.source||"#",B("planNote").textContent=e.note,f1(e),dn()}function m7(){if(A.mode==="architecture"){B("helpBody").innerHTML=Ye.help();return}const e=A.source==="server",t=g3.map(([n,r,o,i])=>`
57
57
  <div><dt>${Be(n)}</dt><dd>${Be(r)}</dd>${e?"":`<dd><code>${Be(o)}</code></dd>`}<dd>${Be(i)}</dd></div>`).join("");B("helpBody").innerHTML=`
58
58
  <h4>Edit the diagram</h4>
59
59
  <p>${e?"Each one is saved as a change to the plan, which is how your agents hear about it.":"Every gesture below is one line of <code>spec.js</code>: nothing in this app implements dragging, hit-testing or snapping."}</p>
60
60
  <dl class="gestures">${t}</dl>
61
61
  <h4>Look around</h4>
62
- <p>Scroll, or hold Space and drag. ${Be(vl)}scroll or + and − zoom; 0 shows the whole plan. ${Be(vl)}Z undoes.</p>`}function b7(){if(A.mode==="architecture"){B("legendBody").innerHTML=Ye.legend();return}const e=A.source==="server",t=(o,i)=>`<span class="chip" style="background:${o}">${Ao(i,{size:12})}</span>`,n=(o,i)=>`<h4>${o}</h4><ul>${i.map(s=>`<li>${s}</li>`).join("")}</ul>`,r=[e?n("Status",cw.map(o=>`${t(mi[o].colour,mi[o].icon)}${Be(mi[o].word)}${mi[o].strike?" <i>(struck through)</i>":""}`)):"",e?n("Arrows",['<span class="wire"></span>needs: it uses what comes before','<span class="wire soft"></span>after: order only',...Object.entries(ff).map(([o,i])=>`<span class="gate">${Ao(i,{size:12})}</span>${Be(bw[o])}: you come in <i>(amber while it waits for you)</i>`)]):"",e?n("Badges",[`<span class="pill">${Ao("question",{size:11})}review</span>a change upstream may affect it`,`<span class="pill">${Ao("exclaim",{size:11})}at risk</span>a step before it failed`]):"",n("Marks",['<span class="frame-key"></span>a frame is a group','<span class="ember-key"></span>ember: what you hold or just changed'])];B("legendBody").innerHTML=r.join("")}const Re={pending:!1,inFlight:!1,pointerDown:!1,refreshing:!1,stale:!1,staleLine:null,own:new Set,timer:void 0,unfollow:null};addEventListener("pointerdown",()=>{Re.pointerDown=!0},!0);addEventListener("pointerup",()=>{Re.pointerDown=!1,Re.pending?ys(60):Re.stale&&Un()},!0);const Ye=r7({state:A,el:B,esc:Be,sync:Re,notice:(e,t,n)=>Ge(e,t,n),interactions:()=>Xo,mount:e=>po(e),render:()=>dn(),redraw:()=>Nd(),renderTabs:()=>Xi(),setPanel:e=>pr(e),select:e=>Vo(e),changesPanel:e=>g1(e),ghost:e=>{hn=e},placeCard:()=>hc(),plans:()=>A.plans,scheduleSave:e=>ys(e),needs:(e,t)=>{Sl=e,$l(),of(e>0),B("needsText").textContent=t},showCall:e=>Zo(e),shownCall:()=>ms,bar:()=>nf(),refreshFlow:()=>gs()});function Jo(){if(Ki.refresh(),dn(),A.mode==="architecture"){(A.source!=="server"||Ye.current())&&(Re.pending=!0,Re.pointerDown||ys(A.source==="server"?180:60));return}A.source!=="server"||!A.server||(Re.pending=!0,Re.pointerDown||ys(180))}const ys=e=>{clearTimeout(Re.timer),Re.timer=setTimeout(w7,e)};async function w7(){if(A.mode==="architecture")return Ye.save();if(!A.server||Re.inFlight||Re.refreshing||!Re.pending||Re.pointerDown)return;Re.pending=!1;const e=ig(A.server,A.chart.getData());if(!e.length)return;Re.inFlight=!0;let t=null;try{t=await hf(A.server.id,A.server.rev,e)}catch{Ge("Lost the plan server. Your last change is not saved.","error")}finally{Re.inFlight=!1}if(t?.status===200){Re.own.add(t.body.rev),t.body.kind==="proposed"&&Ge(`Saved as proposal ${t.body.proposal.id}: the plan is executing.`),Re.refreshing=!0;try{await Un({quiet:!0})}finally{Re.refreshing=!1}}else t&&(Ge(`Not saved: ${t.body.why??t.body.error}. The chart is back to the plan as it is.`,"error"),await Un({quiet:!0,reseed:!0}));Re.pending&&ys(60)}async function Un({quiet:e=!1,reseed:t=!1,line:n}={}){if(A.mode==="architecture")return Ye.catchUp({quiet:e,reseed:t,line:n});if(!A.server)return;if(Re.pointerDown||Re.inFlight){Re.stale=!0,n&&(Re.staleLine=n);return}const r=Re.staleLine;r&&!Re.own.has(r.rev)&&(n=r,e=!1),n&&Re.own.has(n.rev)&&(n=void 0,e=!0),Re.stale=!1,Re.staleLine=null;let o;try{o=await Al(A.server.id)}catch(l){Ge(`Could not refresh: ${l.message}.`,"error");return}if(!o.plan){Ge(o.error??"The plan file is not a plan.","error");return}const i=A.server;if(A.server=o,Re.pending&&!t&&Re.own.has(o.rev)){mr(),dn();return}const s=o.layout.canvas;A.domain&&(s.width+40>A.domain.width||s.height+30>A.domain.height)?po(rg(o)):t?(A.chart.setData(bc(o)),e||Ge(`${eu(n,i)} Undo starts again from here.`)):tf(A.chart.getData(),bc(o))?("deferred"in A.chart.patch(tf(A.chart.getData(),bc(o)),{history:"keep"})&&(Re.stale=!0),e||Ge(`${eu(n,i)} Your undo history is kept.`)):(Nd(),!e&&n&&Ge(eu(n,i))),mr(),dn()}const Nd=()=>A.chart?.setStage(A.chart.getStage());function eu(e,t){return e?`${e.actor==="you"?e.via==="file"?"An edit to the file":"Another window":`${e.actor}`} changed the plan (rev ${e.rev}${t?`, was ${t.rev}`:""}).`:"The plan changed elsewhere."}async function Ir(e){A.mode==="architecture"&&Bn("plan",{open:!1}),Re.unfollow?.(),Re.pending=!1,Re.own.clear(),A.selected=null,Pd=null,Vi="",kl="";let t;try{t=await Al(e)}catch(n){Ge(`Could not open ${e}: ${n.message}.`,"error");return}if(A.server=t,!t.plan){Ge(t.error??"Not a plan.","error");return}Ge(""),po(rg(t)),mr(),Re.unfollow=Zy(e,{change:n=>{if(n.id===e){if(n.recovered){Ge(""),Un({quiet:!0});return}n.loaded||n.rev!=null&&Re.own.has(n.rev)||Un({line:n.line})}},problem:n=>{n.id===e&&Ge(`The plan file has a problem: ${n.error}`,"error")},reconcile:n=>{n.plan!==e||!A.server||(A.server={...A.server,reconcile:n},dn(),mr(),n.state!=="running"&&Un({quiet:!0}))},presence:n=>{A.server?.plan&&(A.server={...A.server,presence:n.presence,reads:n.reads??[],drift:n.drift??[],listening:n.listening??A.server.listening??[],stopping:n.stopping??[],derived:{...A.server.derived,stalled:n.stalled}},Nd(),dn(),mr())},call:n=>{n.plan!==e||!A.server||(A.server={...A.server,calls:[n,...(A.server.calls??[]).filter(r=>r.id!==n.id)]},(ms===n.id||n.kind==="changed"&&(n.state==="delivered"||n.state==="failed"))&&Zo(n))},open:n=>{Ly("live"),n&&Un()},down:()=>Ly("down")})}let Aa=!1;function Ly(e){B("conn").className=`conn ${e}`,B("conn").textContent=e==="live"?"saved live":"server unreachable",e==="down"&&!Aa?(Ge("The plan server is not answering. What you change is not saved until it is back.","error"),Aa=!0):e==="live"&&Aa&&Ge("")}function mr(){if(A.mode==="architecture"){Ye.renderStatus();return}const e=A.server,t=B("phase");if(!e?.plan){t.hidden=!0,B("phase2").hidden=!0,B("planNote").hidden=!1,B("needs").hidden=!0,kl="",Sl=0,$l(),of(!1),B("planbar").hidden=!br,br&&(B("goal").hidden=!0,B("rev").textContent="",nf());return}const n=e.derived?.progress;B("planbar").hidden=!1,B("planNote").hidden=!0;const r=e.plan.goal??"";if(B("goal").hidden=!r,B("goal").innerHTML=r?`<b>Goal</b> ${Be(r)}`:"",B("goal").title=r,B("rev").textContent=`rev ${e.rev} · ${e.plan.phase}${n?.total?` · ${n.done}/${n.total} done`:""}`,n){const s=`${e.id} · ${n.done}/${n.total} done`,a=B("plans").querySelector(`[data-id="${CSS.escape(e.id)}"] .meta`);a&&(a.textContent=s),B("planMeta").textContent=s}nf();const o=uw(e);Sl=o.total,$l(),of(o.total>0);const i=og(e);B("needs").hidden=!i.length,i.length||B("needs").removeAttribute("open"),B("needsText").textContent=fw(o),x7(i,e);for(const s of i){const a=s.permission?.id;!a||Fy.has(a)||(Fy.add(a),B("needs").setAttribute("open",""))}}const Fy=new Set;let kl="";function x7(e,t){const n=B("needsBody"),r=n.contains(document.activeElement)&&document.activeElement instanceof HTMLInputElement,o=xw(e,t);r||o===kl||(kl=o,n.innerHTML=o,pc(n))}let br=null,Ry=0;async function gs(){if(A.source==="server")try{const e=await aw();JSON.stringify(e)!==JSON.stringify(br)&&(br=e,a1())}catch{}}function v7(){clearInterval(Ry),Ry=window.setInterval(()=>{document.hidden||gs()},2e3),gs()}function a1(){A.mode==="architecture"?Ye.renderStatus():mr()}function l1(){if(!br)return null;const e=A.mode==="plan"&&A.server?.plan?{id:A.server.id,phase:A.server.plan.phase}:null;return a7(br,A.plans??[],e)}function nf(){const e=B("phase"),t=B("phase2"),n=l1();if(!n||!br){const o=A.server;if(!o?.plan){e.hidden=!0,t.hidden=!0;return}const i=o.plan.phase==="paused"?Ud.map(l=>l==="executing"?"paused":l):[...Ud],s=i.includes(o.plan.phase)?i:[...i,o.plan.phase];B("phases").innerHTML=s.map(l=>`<li${l===o.plan.phase?' class="on" aria-current="step"':""}>${Be(l[0].toUpperCase()+l.slice(1))}</li>`).join("");const a=Ca(o.plan.phase,o.derived?.progress,o.listening??[]);Io(e,a),t.hidden=!a.second,a.second&&Io(t,a.second),B("phaseLine").textContent=a.line;return}B("phases").innerHTML=s7(br.at),B("phaseLine").textContent=n.line,n.first?Io(e,n.first):(e.hidden=!0,delete e.dataset.armed),e.disabled=!!n.first?.disabled,n.first?.disabled&&n.first.why&&(e.title=`Not yet: ${n.first.why}`),t.hidden=!n.second,n.second&&Io(t,n.second);const r=l7(br);B("modePlan").dataset.count=r,B("modePlan").title=r?`${r==="1"?"One thing waits":`${r} things wait`} on you in the plan`:""}function Io(e,t){e.hidden=!1;const n=e.dataset.armed===t.label;e.textContent=n&&t.confirm?t.confirm:t.label,e.title=t.hint,e.classList.toggle("primary",t.primary),e.classList.toggle("danger",n)}function Ge(e,t="info",n){Aa=!1,ms=void 0;const r=B("notice");if(r.hidden=!e,r.className=`notice ${t}`,r.setAttribute("role",t==="error"?"alert":"status"),r.textContent=e,e&&n){const o=document.createElement("button");o.textContent=n.label,o.onclick=n.run,r.append(" ",o)}}let ms;function Zo(e){const t=lw(e);if(!t){ms===e.id&&Ge("");return}const n=t.copy;Ge(t.text,t.kind,n?{label:"Copy a prompt for it",run:async()=>{try{await navigator.clipboard.writeText(n),Ge("Copied. Paste it to your agent.")}catch{Ge(`Say to your agent: ${n}`)}}}:void 0),ms=e.id}function k7(e){const t=A.server?.plan?.nodes?.[e];return t?eg({id:e,calls:A.server.calls,working:gw(A.server),bare:!t.detail&&!t.files?.length&&!t.touches?.length,proposed:(A.server.plan.proposals??[]).some(n=>(n.ops??[]).some(r=>r.id===e))}):""}async function Py(e){try{const{job:t,call:n}=await vw(A.server.id,e);t&&(A.server={...A.server,reconcile:t},dn(),mr()),n&&(A.server={...A.server,calls:[n,...(A.server.calls??[]).filter(r=>r.id!==n.id)]},Zo(El(n)))}catch(t){Ge(`Not asked: ${t.message}.`,"error")}}let bs=[];function Kt(e,t,n){return tu=tu.catch(()=>!1).then(()=>S7(e,t,n)),tu}let tu=Promise.resolve(!1);async function S7(e,t,n){for(let o=0;Re.inFlight&&o<5e3;o+=40)await new Promise(i=>setTimeout(i,40));if(!A.server||Re.inFlight)return!1;let r=!1;Re.inFlight=!0,bs=[];try{const{status:o,body:i}=await hf(A.server.id,A.server.rev,e,n);o===200?(Re.own.add(i.rev),Ge(t),r=!0,bs=i.calls??[]):Ge(`Not done: ${i.why??i.error}`,"error")}finally{Re.inFlight=!1}return await Un({quiet:!0}),gs(),r}function Id(e){return A.mode==="architecture"?A.source==="server"?(Bn("plan",{open:!1}),Ir(e)):(history.replaceState(null,"",`#architecture/${e}`),Ye.openSample(yf(e))):(history.replaceState(null,"",`#${e}`),A.source==="server"?Ir(e):po(Tl(e)))}const c1=()=>A.mode==="architecture"?A.source==="server"?[]:Zi.map(e=>e.id):A.source==="server"?A.plans.filter(e=>!e.error).map(e=>e.id):Jr.map(e=>e.id),$7=()=>A.mode==="architecture"?A.source==="server"?void 0:A.plan?.id:A.source==="server"?A.server?.id:A.plan?.id,rf=document.title;let u1=rf,Sl=0;const $l=()=>{document.title=ww(u1,Sl)},of=e=>{const t=document.querySelector('link[rel="icon"]');t&&t.setAttribute("href",e?"/favicon-needs.svg":"/favicon.svg")};function f1(e){B("planTitle").textContent=e.title||e.id||"Plans",u1=e.title?`${e.title} · ${rf}`:rf,$l(),B("planMeta").textContent=e.repo||e.id||"";for(const n of B("plans").querySelectorAll("[data-id]"))n.dataset.id===e.id?n.setAttribute("aria-current","true"):n.removeAttribute("aria-current");const t=c1();B("prevPlan").disabled=B("nextPlan").disabled=t.length<2}function d1(e){const t=c1();if(t.length<2)return;const n=t.indexOf($7()??"");Id(t[(n+e+t.length)%t.length])}const _l=()=>!B("plans").hidden;function Ld(){B("plans").hidden=!1,B("planBtn").setAttribute("aria-expanded","true");const e=[...B("plans").querySelectorAll(".plan")];(e.find(t=>t.hasAttribute("aria-current"))??e[0])?.focus()}function so(e=!1){B("plans").hidden=!0,B("planBtn").setAttribute("aria-expanded","false"),e&&B("planBtn").focus(),af&&Fd()}B("planBtn").onclick=()=>_l()?so():Ld();B("prevPlan").onclick=()=>d1(-1);B("nextPlan").onclick=()=>d1(1);document.addEventListener("pointerdown",e=>{_l()&&!B("switcher").contains(e.target)&&so()});B("switcher").addEventListener("keydown",e=>{if(e.key==="Escape"&&_l()){so(!0),e.stopPropagation();return}if(e.target===B("planBtn")&&e.key==="ArrowDown"){e.preventDefault(),_l()||Ld();return}const t=e.target;if(!t.classList.contains("plan"))return;const n=[...B("plans").querySelectorAll(".plan")],r=n.indexOf(t),o={ArrowDown:r+1,ArrowRight:r+1,ArrowUp:r-1,ArrowLeft:r-1,Home:0,End:n.length-1}[e.key];o!==void 0&&(e.preventDefault(),n[(o+n.length)%n.length].focus())});function zy(){B("plans").classList.remove("plain");const e=A.mode==="architecture";B("plans").innerHTML=(e?Zi:Jr).map(t=>{const n=e?C3(t):t,r=e?`${Object.keys(t.arch.nodes).length} boxes, ${t.arch.edges.length} arrows`:`${t.steps.length} steps, ${t.depends.length} arrows`;return`
62
+ <p>Scroll, or hold Space and drag. ${Be(vl)}scroll or + and − zoom; 0 shows the whole plan. ${Be(vl)}Z undoes.</p>`}function b7(){if(A.mode==="architecture"){B("legendBody").innerHTML=Ye.legend();return}const e=A.source==="server",t=(o,i)=>`<span class="chip" style="background:${o}">${Ao(i,{size:12})}</span>`,n=(o,i)=>`<h4>${o}</h4><ul>${i.map(s=>`<li>${s}</li>`).join("")}</ul>`,r=[e?n("Status",cw.map(o=>`${t(mi[o].colour,mi[o].icon)}${Be(mi[o].word)}${mi[o].strike?" <i>(struck through)</i>":""}`)):"",e?n("Arrows",['<span class="wire"></span>needs: it uses what comes before','<span class="wire soft"></span>after: order only',...Object.entries(ff).map(([o,i])=>`<span class="gate">${Ao(i,{size:12})}</span>${Be(bw[o])}: you come in <i>(amber while it waits for you)</i>`)]):"",e?n("Badges",[`<span class="pill">${Ao("question",{size:11})}review</span>a change upstream may affect it`,`<span class="pill">${Ao("exclaim",{size:11})}at risk</span>a step before it failed`]):"",n("Marks",['<span class="frame-key"></span>a frame is a group','<span class="ember-key"></span>ember: what you hold or just changed'])];B("legendBody").innerHTML=r.join("")}const Pe={pending:!1,inFlight:!1,pointerDown:!1,refreshing:!1,stale:!1,staleLine:null,own:new Set,timer:void 0,unfollow:null};addEventListener("pointerdown",()=>{Pe.pointerDown=!0},!0);addEventListener("pointerup",()=>{Pe.pointerDown=!1,Pe.pending?ys(60):Pe.stale&&Un()},!0);const Ye=r7({state:A,el:B,esc:Be,sync:Pe,notice:(e,t,n)=>Ge(e,t,n),interactions:()=>Xo,mount:e=>po(e),render:()=>dn(),redraw:()=>Nd(),renderTabs:()=>Xi(),setPanel:e=>pr(e),select:e=>Vo(e),changesPanel:e=>g1(e),ghost:e=>{hn=e},placeCard:()=>hc(),plans:()=>A.plans,scheduleSave:e=>ys(e),needs:(e,t)=>{Sl=e,$l(),of(e>0),B("needsText").textContent=t},showCall:e=>Zo(e),shownCall:()=>ms,bar:()=>nf(),refreshFlow:()=>gs()});function Jo(){if(Ki.refresh(),dn(),A.mode==="architecture"){(A.source!=="server"||Ye.current())&&(Pe.pending=!0,Pe.pointerDown||ys(A.source==="server"?180:60));return}A.source!=="server"||!A.server||(Pe.pending=!0,Pe.pointerDown||ys(180))}const ys=e=>{clearTimeout(Pe.timer),Pe.timer=setTimeout(w7,e)};async function w7(){if(A.mode==="architecture")return Ye.save();if(!A.server||Pe.inFlight||Pe.refreshing||!Pe.pending||Pe.pointerDown)return;Pe.pending=!1;const e=ig(A.server,A.chart.getData());if(!e.length)return;Pe.inFlight=!0;let t=null;try{t=await hf(A.server.id,A.server.rev,e)}catch{Ge("Lost the plan server. Your last change is not saved.","error")}finally{Pe.inFlight=!1}if(t?.status===200){Pe.own.add(t.body.rev),t.body.kind==="proposed"&&Ge(`Saved as proposal ${t.body.proposal.id}: the plan is executing.`),Pe.refreshing=!0;try{await Un({quiet:!0})}finally{Pe.refreshing=!1}}else t&&(Ge(`Not saved: ${t.body.why??t.body.error}. The chart is back to the plan as it is.`,"error"),await Un({quiet:!0,reseed:!0}));Pe.pending&&ys(60)}async function Un({quiet:e=!1,reseed:t=!1,line:n}={}){if(A.mode==="architecture")return Ye.catchUp({quiet:e,reseed:t,line:n});if(!A.server)return;if(Pe.pointerDown||Pe.inFlight){Pe.stale=!0,n&&(Pe.staleLine=n);return}const r=Pe.staleLine;r&&!Pe.own.has(r.rev)&&(n=r,e=!1),n&&Pe.own.has(n.rev)&&(n=void 0,e=!0),Pe.stale=!1,Pe.staleLine=null;let o;try{o=await Al(A.server.id)}catch(l){Ge(`Could not refresh: ${l.message}.`,"error");return}if(!o.plan){Ge(o.error??"The plan file is not a plan.","error");return}const i=A.server;if(A.server=o,Pe.pending&&!t&&Pe.own.has(o.rev)){mr(),dn();return}const s=o.layout.canvas;A.domain&&(s.width+40>A.domain.width||s.height+30>A.domain.height)?po(rg(o)):t?(A.chart.setData(bc(o)),e||Ge(`${eu(n,i)} Undo starts again from here.`)):tf(A.chart.getData(),bc(o))?("deferred"in A.chart.patch(tf(A.chart.getData(),bc(o)),{history:"keep"})&&(Pe.stale=!0),e||Ge(`${eu(n,i)} Your undo history is kept.`)):(Nd(),!e&&n&&Ge(eu(n,i))),mr(),dn()}const Nd=()=>A.chart?.setStage(A.chart.getStage());function eu(e,t){return e?`${e.actor==="you"?e.via==="file"?"An edit to the file":"Another window":`${e.actor}`} changed the plan (rev ${e.rev}${t?`, was ${t.rev}`:""}).`:"The plan changed elsewhere."}async function Ir(e){A.mode==="architecture"&&Bn("plan",{open:!1}),Pe.unfollow?.(),Pe.pending=!1,Pe.own.clear(),A.selected=null,Pd=null,Vi="",kl="";let t;try{t=await Al(e)}catch(n){Ge(`Could not open ${e}: ${n.message}.`,"error");return}if(A.server=t,!t.plan){Ge(t.error??"Not a plan.","error");return}Ge(""),po(rg(t)),mr(),Pe.unfollow=Zy(e,{change:n=>{if(n.id===e){if(n.recovered){Ge(""),Un({quiet:!0});return}n.loaded||n.rev!=null&&Pe.own.has(n.rev)||Un({line:n.line})}},problem:n=>{n.id===e&&Ge(`The plan file has a problem: ${n.error}`,"error")},reconcile:n=>{n.plan!==e||!A.server||(A.server={...A.server,reconcile:n},dn(),mr(),n.state!=="running"&&Un({quiet:!0}))},presence:n=>{A.server?.plan&&(A.server={...A.server,presence:n.presence,reads:n.reads??[],drift:n.drift??[],listening:n.listening??A.server.listening??[],stopping:n.stopping??[],derived:{...A.server.derived,stalled:n.stalled}},Nd(),dn(),mr())},call:n=>{n.plan!==e||!A.server||(A.server={...A.server,calls:[n,...(A.server.calls??[]).filter(r=>r.id!==n.id)]},(ms===n.id||n.kind==="changed"&&(n.state==="delivered"||n.state==="failed"))&&Zo(n))},open:n=>{Ly("live"),n&&Un()},down:()=>Ly("down")})}let Aa=!1;function Ly(e){B("conn").className=`conn ${e}`,B("conn").textContent=e==="live"?"saved live":"server unreachable",e==="down"&&!Aa?(Ge("The plan server is not answering. What you change is not saved until it is back.","error"),Aa=!0):e==="live"&&Aa&&Ge("")}function mr(){if(A.mode==="architecture"){Ye.renderStatus();return}const e=A.server,t=B("phase");if(!e?.plan){t.hidden=!0,B("phase2").hidden=!0,B("planNote").hidden=!1,B("needs").hidden=!0,kl="",Sl=0,$l(),of(!1),B("planbar").hidden=!br,br&&(B("goal").hidden=!0,B("rev").textContent="",nf());return}const n=e.derived?.progress;B("planbar").hidden=!1,B("planNote").hidden=!0;const r=e.plan.goal??"";if(B("goal").hidden=!r,B("goal").innerHTML=r?`<b>Goal</b> ${Be(r)}`:"",B("goal").title=r,B("rev").textContent=`rev ${e.rev} · ${e.plan.phase}${n?.total?` · ${n.done}/${n.total} done`:""}`,n){const s=`${e.id} · ${n.done}/${n.total} done`,a=B("plans").querySelector(`[data-id="${CSS.escape(e.id)}"] .meta`);a&&(a.textContent=s),B("planMeta").textContent=s}nf();const o=uw(e);Sl=o.total,$l(),of(o.total>0);const i=og(e);B("needs").hidden=!i.length,i.length||B("needs").removeAttribute("open"),B("needsText").textContent=fw(o),x7(i,e);for(const s of i){const a=s.permission?.id;!a||Fy.has(a)||(Fy.add(a),B("needs").setAttribute("open",""))}}const Fy=new Set;let kl="";function x7(e,t){const n=B("needsBody"),r=n.contains(document.activeElement)&&document.activeElement instanceof HTMLInputElement,o=xw(e,t);r||o===kl||(kl=o,n.innerHTML=o,pc(n))}let br=null,Ry=0;async function gs(){if(A.source==="server")try{const e=await aw();JSON.stringify(e)!==JSON.stringify(br)&&(br=e,a1())}catch{}}function v7(){clearInterval(Ry),Ry=window.setInterval(()=>{document.hidden||gs()},2e3),gs()}function a1(){A.mode==="architecture"?Ye.renderStatus():mr()}function l1(){if(!br)return null;const e=A.mode==="plan"&&A.server?.plan?{id:A.server.id,phase:A.server.plan.phase}:null;return a7(br,A.plans??[],e)}function nf(){const e=B("phase"),t=B("phase2"),n=l1();if(!n||!br){const o=A.server;if(!o?.plan){e.hidden=!0,t.hidden=!0;return}const i=o.plan.phase==="paused"?Ud.map(l=>l==="executing"?"paused":l):[...Ud],s=i.includes(o.plan.phase)?i:[...i,o.plan.phase];B("phases").innerHTML=s.map(l=>`<li${l===o.plan.phase?' class="on" aria-current="step"':""}>${Be(l[0].toUpperCase()+l.slice(1))}</li>`).join("");const a=Ca(o.plan.phase,o.derived?.progress,o.listening??[]);Io(e,a),t.hidden=!a.second,a.second&&Io(t,a.second),B("phaseLine").textContent=a.line;return}B("phases").innerHTML=s7(br.at),B("phaseLine").textContent=n.line,n.first?Io(e,n.first):(e.hidden=!0,delete e.dataset.armed),e.disabled=!!n.first?.disabled,n.first?.disabled&&n.first.why&&(e.title=`Not yet: ${n.first.why}`),t.hidden=!n.second,n.second&&Io(t,n.second);const r=l7(br);B("modePlan").dataset.count=r,B("modePlan").title=r?`${r==="1"?"One thing waits":`${r} things wait`} on you in the plan`:""}function Io(e,t){e.hidden=!1;const n=e.dataset.armed===t.label;e.textContent=n&&t.confirm?t.confirm:t.label,e.title=t.hint,e.classList.toggle("primary",t.primary),e.classList.toggle("danger",n)}function Ge(e,t="info",n){Aa=!1,ms=void 0;const r=B("notice");if(r.hidden=!e,r.className=`notice ${t}`,r.setAttribute("role",t==="error"?"alert":"status"),r.textContent=e,e&&n){const o=document.createElement("button");o.textContent=n.label,o.onclick=n.run,r.append(" ",o)}}let ms;function Zo(e){const t=lw(e);if(!t){ms===e.id&&Ge("");return}const n=t.copy;Ge(t.text,t.kind,n?{label:"Copy a prompt for it",run:async()=>{try{await navigator.clipboard.writeText(n),Ge("Copied. Paste it to your agent.")}catch{Ge(`Say to your agent: ${n}`)}}}:void 0),ms=e.id}function k7(e){const t=A.server?.plan?.nodes?.[e];return t?eg({id:e,calls:A.server.calls,working:gw(A.server),bare:!t.detail&&!t.files?.length&&!t.touches?.length,proposed:(A.server.plan.proposals??[]).some(n=>(n.ops??[]).some(r=>r.id===e))}):""}async function Py(e){try{const{job:t,call:n}=await vw(A.server.id,e);t&&(A.server={...A.server,reconcile:t},dn(),mr()),n&&(A.server={...A.server,calls:[n,...(A.server.calls??[]).filter(r=>r.id!==n.id)]},Zo(El(n)))}catch(t){Ge(`Not asked: ${t.message}.`,"error")}}let bs=[];function Kt(e,t,n){return tu=tu.catch(()=>!1).then(()=>S7(e,t,n)),tu}let tu=Promise.resolve(!1);async function S7(e,t,n){for(let o=0;Pe.inFlight&&o<5e3;o+=40)await new Promise(i=>setTimeout(i,40));if(!A.server||Pe.inFlight)return!1;let r=!1;Pe.inFlight=!0,bs=[];try{const{status:o,body:i}=await hf(A.server.id,A.server.rev,e,n);o===200?(Pe.own.add(i.rev),Ge(t),r=!0,bs=i.calls??[]):Ge(`Not done: ${i.why??i.error}`,"error")}finally{Pe.inFlight=!1}return await Un({quiet:!0}),gs(),r}function Id(e){return A.mode==="architecture"?A.source==="server"?(Bn("plan",{open:!1}),Ir(e)):(history.replaceState(null,"",`#architecture/${e}`),Ye.openSample(yf(e))):(history.replaceState(null,"",`#${e}`),A.source==="server"?Ir(e):po(Tl(e)))}const c1=()=>A.mode==="architecture"?A.source==="server"?[]:Zi.map(e=>e.id):A.source==="server"?A.plans.filter(e=>!e.error).map(e=>e.id):Jr.map(e=>e.id),$7=()=>A.mode==="architecture"?A.source==="server"?void 0:A.plan?.id:A.source==="server"?A.server?.id:A.plan?.id,rf=document.title;let u1=rf,Sl=0;const $l=()=>{document.title=ww(u1,Sl)},of=e=>{const t=document.querySelector('link[rel="icon"]');t&&t.setAttribute("href",e?"/favicon-needs.svg":"/favicon.svg")};function f1(e){B("planTitle").textContent=e.title||e.id||"Plans",u1=e.title?`${e.title} · ${rf}`:rf,$l(),B("planMeta").textContent=e.repo||e.id||"";for(const n of B("plans").querySelectorAll("[data-id]"))n.dataset.id===e.id?n.setAttribute("aria-current","true"):n.removeAttribute("aria-current");const t=c1();B("prevPlan").disabled=B("nextPlan").disabled=t.length<2}function d1(e){const t=c1();if(t.length<2)return;const n=t.indexOf($7()??"");Id(t[(n+e+t.length)%t.length])}const _l=()=>!B("plans").hidden;function Ld(){B("plans").hidden=!1,B("planBtn").setAttribute("aria-expanded","true");const e=[...B("plans").querySelectorAll(".plan")];(e.find(t=>t.hasAttribute("aria-current"))??e[0])?.focus()}function so(e=!1){B("plans").hidden=!0,B("planBtn").setAttribute("aria-expanded","false"),e&&B("planBtn").focus(),af&&Fd()}B("planBtn").onclick=()=>_l()?so():Ld();B("prevPlan").onclick=()=>d1(-1);B("nextPlan").onclick=()=>d1(1);document.addEventListener("pointerdown",e=>{_l()&&!B("switcher").contains(e.target)&&so()});B("switcher").addEventListener("keydown",e=>{if(e.key==="Escape"&&_l()){so(!0),e.stopPropagation();return}if(e.target===B("planBtn")&&e.key==="ArrowDown"){e.preventDefault(),_l()||Ld();return}const t=e.target;if(!t.classList.contains("plan"))return;const n=[...B("plans").querySelectorAll(".plan")],r=n.indexOf(t),o={ArrowDown:r+1,ArrowRight:r+1,ArrowUp:r-1,ArrowLeft:r-1,Home:0,End:n.length-1}[e.key];o!==void 0&&(e.preventDefault(),n[(o+n.length)%n.length].focus())});function zy(){B("plans").classList.remove("plain");const e=A.mode==="architecture";B("plans").innerHTML=(e?Zi:Jr).map(t=>{const n=e?C3(t):t,r=e?`${Object.keys(t.arch.nodes).length} boxes, ${t.arch.edges.length} arrows`:`${t.steps.length} steps, ${t.depends.length} arrows`;return`
63
63
  <button class="plan" data-id="${Be(t.id)}">
64
64
  <span class="thumb" aria-hidden="true">${ng(n,{title:""})}</span>
65
65
  <span class="txt"><b>${Be(t.title)}</b><span class="meta">${Be(t.repo)}</span><span class="shape">${r}</span></span>
@@ -86,7 +86,7 @@ ${ca(t)}}`}const e7=e=>e&&typeof e=="object"&&typeof e.id=="string"&&e.id.includ
86
86
  <li><button data-start="new">+ New plan</button><span>Or draw a plan yourself: name it, double-click the board to add steps, and drag from the dots on a box to draw arrows between them.</span></li>
87
87
  <li><button data-start="import">Import…</button><span>A Cursor <code>.plan.md</code>, markdown with a Mermaid block, or a <code>.mmd</code> file.</span></li>
88
88
  </ul>
89
- </div>`,pc(t);for(const r of t.querySelectorAll("[data-start]"))r.onclick=()=>{if(r.dataset.start==="arch"){Bn("architecture");return}Ld(),B(r.dataset.start==="new"?"newPlan":"importPlan").click()};A.mode==="plan"&&mr()}let Yi=[],Lo=[];async function ua(){if(A.source!=="server")return;const[e,t]=await Promise.all([Ji().catch(()=>null),nw().catch(()=>[])]),n=e?.exists?[...e.recent??[]].reverse().find(a=>a.actor!=="you")?.actor:void 0,r=e?.exists?Qy(e.arch,{by:n}):[],o=t.filter(a=>a.state!=="gone"),i=JSON.stringify([r,o.map(a=>[a.actor,a.state,a.detail,a.permission?.id])])!==JSON.stringify([Yi,Lo.map(a=>[a.actor,a.state,a.detail,a.permission?.id])]);Yi=r,Lo=o;const s=B("modeArch");s.dataset.count=r.length?String(r.length):"",s.title=r.length?`${r.length===1?"One thing waits":`${r.length} things wait`} on you in the architecture`:"",i&&!B("empty").hidden&&!A.server?.plan&&A.mode==="plan"&&B("empty").querySelector('[data-start="new"]')&&ws("none")}function Rd(){const e=B("chart").querySelector(".canvas");if(!e||!A.chart||!A.domain)return;if(A.mode==="architecture"){Ye.paint(e);return}const t=A.chart.getData(),n=jn(t.steps);D3(e,n,A.domain,Xo.dropping()),n1(A.chart,s=>s.kind==="after");const r=A.server,o=t.depends.filter(s=>ff[s.kind]),i=hr&&o.length?ef(A.chart,o):new Map;t1(e,{items:n,look:s=>hr&&r?.plan?.nodes[s]?hr.look({id:s}):void 0,arrows:o.flatMap(s=>{const a=i.get(`${s.source}\0${s.target}`);return a?[{...a,kind:s.kind,yours:hr?.arrow(s)==="yours"}]:[]}),size:A.domain}),Xo.paint()}let nu=null;function M7(){nu?.disconnect();let e=!1;nu=new MutationObserver(()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1,Rd()}))}),nu.observe(A.chart,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["d","x","y","transform"]})}function dn(){const e=Ps();if(z7(),Rd(),B("panel").contains(document.activeElement)&&(document.activeElement instanceof HTMLTextAreaElement||document.activeElement instanceof HTMLInputElement)){qy(),lf(),vs();return}B("panel").innerHTML={Boxes:()=>Ye.panel("Boxes"),Flows:()=>Ye.panel("Flows"),Steps:()=>{if(!A.server?.plan)return'<p class="lede">No plan open.</p>';const n=A.selected?iw({plan:A.server.plan,id:A.selected,derived:A.server.derived,review:A.server.review,recent:A.server.recent,drafts:io,fileInfo:m1(),arch:xs,suggesting:k7(A.selected)}):"";return A.selected&&!n&&(A.selected=null),n+sw(A.server)},Changes:()=>A.mode==="architecture"?Ye.panel("Changes"):A.source==="server"?I7():g1(e)}[A.panel](),R7(),A.mode==="architecture"&&Ye.wirePanel(),F7(),uf(),qy(),A.mode!=="architecture"&&Ml(),lf()}let xs=null;function E7(){A.source==="server"&&Ji().then(e=>{const t=e.exists?e.arch:null;JSON.stringify(t)!==JSON.stringify(xs)&&(xs=t,A.mode==="plan"&&A.selected&&dn())}).catch(()=>{})}let Gi=null,Pd=null,hn=null,Vi="";const p1=()=>{const e=A.server?.plan?.proposals??[];return e.find(t=>t.id===Pd)??e[0]??null};function Ml(){const e=A.server,t=B("chart").querySelector(".canvas");if(!e?.plan){xl(t,null,{},{},A.domain??{width:0,height:0}),hn=null,Wy();return}const n=p1(),r=n?hg(e.plan,e.layout,n.ops):null,o=A.panel==="Steps"&&Gi&&Gi in e.plan.nodes?Gi:null;hn=xl(t,r,e.plan,e.layout,A.domain??e.layout.canvas,o),Wy()}function zd(e){Pd=e,Vi="",Ml(),A7()}async function jy(e){if(A.source==="server"){if(e.architecture){e.proposal&&A.mode==="architecture"&&Ye.showProposal(e.proposal);return}e.step?y1(e.step):e.proposal&&zd(e.proposal)}}function y1(e){if(!(e in(A.server?.plan?.nodes??{})))return;Vo(e),[...B("chart").querySelectorAll("rect")].find(n=>On(n)&&Dt(n).data.id===e)?.scrollIntoView({block:"center",inline:"center",behavior:"smooth"})}function A7(){const e=B("chart").querySelector(".canvas");if(!hn||!e||!A.domain)return;const t=e.getBoundingClientRect().width/wr({canvas:A.domain}).width,n=B("chart");n.scrollTo({left:e.offsetLeft+(hn.x+hn.w/2)*t-n.clientWidth/2,top:e.offsetTop+(hn.y+hn.h/2)*t-n.clientHeight/2,behavior:"smooth"})}function T7(e){const t=e.diff.map(([n,r])=>`<span class="${n==="+"?"add":n==="-"?"del":"same"}"><i aria-hidden="true">${n==="-"?"−":n==="+"?"+":" "}</i><span class="sr">${n==="+"?"added: ":n==="-"?"removed: ":""}</span>${Be(r)||"&nbsp;"}</span>`).join("");return`<div class="words"><div class="where">${Be(e.where)}, now and as proposed</div><div class="diff" tabindex="0" role="group" aria-label="${Be(e.where)}: what it says now and what it would say">${t}</div></div>`}function O7(e,t,n,r){const o=hg(e.plan,e.layout,t.ops),i=s=>/remove$/.test(s)?"−":/\.add$/.test(s)?"+":"~";return`
89
+ </div>`,pc(t);for(const r of t.querySelectorAll("[data-start]"))r.onclick=()=>{if(r.dataset.start==="arch"){Bn("architecture");return}Ld(),B(r.dataset.start==="new"?"newPlan":"importPlan").click()};A.mode==="plan"&&mr()}let Yi=[],Lo=[];async function ua(){if(A.source!=="server")return;const[e,t]=await Promise.all([Ji().catch(()=>null),nw().catch(()=>[])]),n=e?.exists?[...e.recent??[]].reverse().find(a=>a.actor!=="you")?.actor:void 0,r=e?.exists?Qy(e.arch,{by:n}):[],o=t.filter(a=>a.state!=="gone"),i=JSON.stringify([r,o.map(a=>[a.actor,a.state,a.detail,a.permission?.id])])!==JSON.stringify([Yi,Lo.map(a=>[a.actor,a.state,a.detail,a.permission?.id])]);Yi=r,Lo=o;const s=B("modeArch");s.dataset.count=r.length?String(r.length):"",s.title=r.length?`${r.length===1?"One thing waits":`${r.length} things wait`} on you in the architecture`:"",i&&!B("empty").hidden&&!A.server?.plan&&A.mode==="plan"&&B("empty").querySelector('[data-start="new"]')&&ws("none")}function Rd(){const e=B("chart").querySelector(".canvas");if(!e||!A.chart||!A.domain)return;if(A.mode==="architecture"){Ye.paint(e);return}const t=A.chart.getData(),n=jn(t.steps);D3(e,n,A.domain,Xo.dropping()),n1(A.chart,s=>s.kind==="after");const r=A.server,o=t.depends.filter(s=>ff[s.kind]),i=hr&&o.length?ef(A.chart,o):new Map;t1(e,{items:n,look:s=>hr&&r?.plan?.nodes[s]?hr.look({id:s}):void 0,arrows:o.flatMap(s=>{const a=i.get(`${s.source}\0${s.target}`);return a?[{...a,kind:s.kind,yours:hr?.arrow(s)==="yours"}]:[]}),size:A.domain}),Xo.paint()}let nu=null;function M7(){nu?.disconnect();let e=!1;nu=new MutationObserver(()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1,Rd()}))}),nu.observe(A.chart,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["d","x","y","transform"]})}function dn(){const e=Ps();if(z7(),Rd(),B("panel").contains(document.activeElement)&&(document.activeElement instanceof HTMLTextAreaElement||document.activeElement instanceof HTMLInputElement)){qy(),lf(),vs();return}B("panel").innerHTML={Boxes:()=>Ye.panel("Boxes"),Flows:()=>Ye.panel("Flows"),Steps:()=>{if(!A.server?.plan)return'<p class="lede">No plan open.</p>';const n=A.selected?iw({plan:A.server.plan,id:A.selected,derived:A.server.derived,review:A.server.review,recent:A.server.recent,drafts:io,fileInfo:m1(),arch:xs,suggesting:k7(A.selected)}):"";return A.selected&&!n&&(A.selected=null),n+sw(A.server)},Changes:()=>A.mode==="architecture"?Ye.panel("Changes"):A.source==="server"?I7():g1(e)}[A.panel](),R7(),A.mode==="architecture"&&Ye.wirePanel(),F7(),uf(),qy(),A.mode!=="architecture"&&Ml(),lf()}let xs=null;function E7(){A.source==="server"&&Ji().then(e=>{const t=e.exists?e.arch:null;JSON.stringify(t)!==JSON.stringify(xs)&&(xs=t,A.mode==="plan"&&A.selected&&dn())}).catch(()=>{})}let Gi=null,Pd=null,hn=null,Vi="";const p1=()=>{const e=A.server?.plan?.proposals??[];return e.find(t=>t.id===Pd)??e[0]??null};function Ml(){const e=A.server,t=B("chart").querySelector(".canvas");if(!e?.plan){xl(t,null,{},{},A.domain??{width:0,height:0}),hn=null,Wy();return}const n=p1(),r=n?hg(e.plan,e.layout,n.ops):null,o=A.panel==="Steps"&&Gi&&Gi in e.plan.nodes?Gi:null;hn=xl(t,r,e.plan,e.layout,A.domain??e.layout.canvas,o),Wy()}function zd(e){Pd=e,Vi="",Ml(),A7()}async function jy(e){if(A.source==="server"){if(e.architecture){e.proposal&&A.mode==="architecture"&&Ye.showProposal(e.proposal);return}e.step?y1(e.step):e.proposal&&zd(e.proposal)}}function y1(e){if(!(e in(A.server?.plan?.nodes??{})))return;Vo(e),[...B("chart").querySelectorAll("rect")].find(n=>On(n)&&jt(n).data.id===e)?.scrollIntoView({block:"center",inline:"center",behavior:"smooth"})}function A7(){const e=B("chart").querySelector(".canvas");if(!hn||!e||!A.domain)return;const t=e.getBoundingClientRect().width/wr({canvas:A.domain}).width,n=B("chart");n.scrollTo({left:e.offsetLeft+(hn.x+hn.w/2)*t-n.clientWidth/2,top:e.offsetTop+(hn.y+hn.h/2)*t-n.clientHeight/2,behavior:"smooth"})}function T7(e){const t=e.diff.map(([n,r])=>`<span class="${n==="+"?"add":n==="-"?"del":"same"}"><i aria-hidden="true">${n==="-"?"−":n==="+"?"+":" "}</i><span class="sr">${n==="+"?"added: ":n==="-"?"removed: ":""}</span>${Be(r)||"&nbsp;"}</span>`).join("");return`<div class="words"><div class="where">${Be(e.where)}, now and as proposed</div><div class="diff" tabindex="0" role="group" aria-label="${Be(e.where)}: what it says now and what it would say">${t}</div></div>`}function O7(e,t,n,r){const o=hg(e.plan,e.layout,t.ops),i=s=>/remove$/.test(s)?"−":/\.add$/.test(s)?"+":"~";return`
90
90
  <div class="pc-head">
91
91
  <span><b>Proposal ${Be(t.id)}</b> from <code>${Be(t.by)}</code></span>
92
92
  ${r>1?`<span class="pc-step"><button class="plain small" data-prev aria-label="The proposal before this one">◀</button><span>${n+1} of ${r}</span><button class="plain small" data-next aria-label="The proposal after this one">▶</button></span>`:""}
@@ -119,4 +119,4 @@ ${ca(t)}}`}const e7=e=>e&&typeof e=="object"&&typeof e.id=="string"&&e.id.includ
119
119
  <ul class="log">${e.map(n=>`
120
120
  <li><span class="rev">rev ${n.rev}</span> <code>${Be(n.actor)}</code> <span class="via">via ${Be(n.via)}</span>
121
121
  ${n.proposed?`<span class="via">→ proposal ${Be(n.proposed)}</span>`:""}
122
- <div>${n.ops.map(r=>Be(t(r))).join(" · ")}</div></li>`).join("")}</ul>`}const cf=new Map,ru=new Set,L7=5e3,m1=()=>A.mode==="architecture"?Ye.knownFileInfo():Object.fromEntries([...cf].map(([e,t])=>[e,t.info]));function b1(){if(A.mode==="architecture")return Ye.pickedBox();const e=A.selected,t=e?A.server?.plan?.nodes[e]:void 0;return e&&t?{id:e,files:t.files??[]}:null}function uf(){if(A.mode==="architecture"){Ye.askFileInfo(vs);return}const e=b1();if(!e||A.source!=="server")return;const t=Date.now(),n=e.files.filter(r=>!ru.has(r)&&!((cf.get(r)?.at??0)>t-L7));if(n.length){for(const r of n)ru.add(r);df(n).then(r=>{for(const o of r)cf.set(o.path,{at:Date.now(),info:{kind:o.kind,matches:o.matches}})}).catch(()=>{}).finally(()=>{for(const r of n)ru.delete(r);vs()})}}function vs(){const e=b1(),t=B("panel").querySelector(".files .chips");if(!e||!t)return;const n=yw(e.id,e.files,m1());t.innerHTML!==n&&(t.innerHTML=n)}async function Hy(e,t){if(A.mode==="architecture"){const o=await Ye.saveFiles(e,t);return vs(),uf(),o}const n=A.server?.plan.nodes[e];if(!n)return!1;const r=await Kt([{op:"node.set",id:e,files:t}],`Saved the files for ${n.label}.`,`you edited the files of ${e}`);return vs(),uf(),r}function F7(){const e=B("panel").querySelector("[data-files-input]"),t=B("panel").querySelector(".files-menu"),n=B("panel").querySelector(".files .chips");if(!e||!t||!n)return;const r=e.dataset.filesInput;let o=[],i=-1,s=0,a=!1,l;const u=()=>(A.mode==="architecture"?Ye.current()?.arch.nodes[r]?.files:A.server?.plan.nodes[r]?.files)??[];n.addEventListener("click",h=>{const y=h.target instanceof Element?h.target.closest("[data-remove-file]"):null;y&&Hy(r,mw(u(),y.dataset.removeFile??""))});const c=()=>{t.hidden=!0,e.setAttribute("aria-expanded","false"),e.removeAttribute("aria-activedescendant"),i=-1},d=()=>{const h=e.value.trim();t.innerHTML=o.length?o.map((y,g)=>`<li role="option" id="insp-files-opt-${g}" data-row="${g}" aria-selected="${g===i}" class="${y.kind}"><code>${Be(y.path)}</code>${y.note?`<span>${Be(y.note)}</span>`:""}</li>`).join(""):`<li class="none" role="presentation">${h?"Nothing in the repository has that in its path. Enter adds it as you typed it.":"No files to offer."}</li>`,t.hidden=!1,e.setAttribute("aria-expanded","true"),i>=0?e.setAttribute("aria-activedescendant",`insp-files-opt-${i}`):e.removeAttribute("aria-activedescendant")};async function f(){const h=++s,y=e.value;try{const[g,m]=await Promise.all([Sw(y),y.trim()?df([$w(y)]):Promise.resolve([])]);if(h!==s)return;o=_w(y,g.files,m[0],u()),i=o.length&&y.trim()?0:-1,a=!1,d()}catch{h===s&&(o=[],a=!1,d())}}async function p(h){const y=Mw(u(),h);e.value="",y!==u()&&await Hy(r,y),f()}e.addEventListener("input",()=>{a=!0,clearTimeout(l),l=setTimeout(f,120)}),e.addEventListener("focus",()=>f()),e.addEventListener("blur",()=>{clearTimeout(l),setTimeout(()=>{document.activeElement!==e&&c()},120)}),e.addEventListener("keydown",h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){if(t.hidden){f();return}h.preventDefault(),o.length&&(i=(i+(h.key==="ArrowDown"?1:-1)+o.length)%o.length),d()}else h.key==="Enter"?(h.preventDefault(),(async()=>{a&&(clearTimeout(l),await f());const y=e.value.trim();i>=0&&o[i]?p(o[i].path):y&&p(y)})()):h.key==="Escape"&&!t.hidden&&(h.preventDefault(),h.stopPropagation(),c())}),t.addEventListener("mousedown",h=>h.preventDefault()),t.addEventListener("click",h=>{const y=h.target instanceof Element?h.target.closest("[data-row]"):null,g=y?o[Number(y.dataset.row)]:void 0;g&&p(g.path)})}function R7(){for(const e of B("panel").querySelectorAll("[data-inspect]"))e.onclick=()=>Vo(e.dataset.inspect??null);for(const e of B("panel").querySelectorAll("[data-close-inspector]"))e.onclick=()=>Vo(null);for(const e of B("panel").querySelectorAll("textarea[data-field]"))e.addEventListener("input",()=>{io[e.dataset.field]=e.value}),e.addEventListener("blur",()=>Ea(e)),e.addEventListener("keydown",t=>{const n=t;n.key==="Enter"&&(n.metaKey||n.ctrlKey)&&(n.preventDefault(),Ea(e))});for(const e of B("panel").querySelectorAll("[data-remove-touch]"))e.onclick=()=>{const t=e.dataset.step??"",n=e.dataset.removeTouch??"",r=A.server?.plan.nodes[t]?.touches??[];Kt([{op:"node.set",id:t,touches:r.filter(o=>o!==n)}],`${A.server?.plan.nodes[t]?.label??t} no longer changes ${xs?.nodes[n]?.label??n}.`,`you edited the boxes ${t} changes`)};for(const e of B("panel").querySelectorAll("select[data-touch-add]"))e.onchange=()=>{const t=e.dataset.touchAdd??"",n=e.value;if(!n)return;const r=A.server?.plan.nodes[t]?.touches??[];Kt([{op:"node.set",id:t,touches:[...r,n]}],`${A.server?.plan.nodes[t]?.label??t} changes ${xs?.nodes[n]?.label??n}.`,`you edited the boxes ${t} changes`)};for(const e of B("panel").querySelectorAll("[data-save-field]"))e.onclick=()=>{const t=B("panel").querySelector(`#insp-${e.dataset.saveField}`);t&&Ea(t)};for(const e of B("panel").querySelectorAll("li.step[data-step]")){const t=e.dataset.step;e.addEventListener("mouseenter",()=>{Gi=t,Ml()}),e.addEventListener("mouseleave",()=>{Gi=null,Ml()})}pc(B("panel"))}function pc(e){for(const i of e.querySelectorAll("[data-act]"))i.onclick=async()=>{if(i.dataset.act==="replan"||i.dataset.act==="drift"){Py(i.dataset.act==="replan"?{kind:"failure",step:i.dataset.step}:{kind:"drift"});return}const s=e.querySelector(`[data-answer="${CSS.escape(i.dataset.step??"")}"]`),a=dw(i.dataset.act,i.dataset.step,s?.value??"");a?Kt(a.ops,a.message,a.reason).then(l=>{const u=l&&bs.find(c=>c.kind==="answered");u&&Zo(El(u))}):i.dataset.act==="answer"&&s?.focus()};for(const i of e.querySelectorAll("[data-gate]"))i.onclick=()=>{const{gate:s,from:a,to:l,option:u}=i.dataset,c=e.querySelector(`[data-gate-text][data-from="${CSS.escape(a??"")}"][data-to="${CSS.escape(l??"")}"]`),d=hw(s??"",a??"",l??"",u??c?.value??"");if(!d){c?.focus();return}Kt(d.ops,d.message,d.reason).then(f=>{const p=f&&bs.find(h=>h.kind==="passed"||h.kind==="sentBack");p&&Zo(El(p))})};for(const i of e.querySelectorAll("[data-gate-text]"))i.addEventListener("keydown",s=>{if(s.key!=="Enter")return;const{from:a,to:l}=i.dataset,u=`[data-from="${CSS.escape(a??"")}"][data-to="${CSS.escape(l??"")}"]`;(e.querySelector(`[data-gate="give"]:not([data-option])${u}`)??e.querySelector(`[data-gate="pass"]${u}`))?.click()});for(const i of e.querySelectorAll("[data-answer]"))i.addEventListener("keydown",s=>{s.key==="Enter"&&e.querySelector(`[data-act="answer"][data-step="${CSS.escape(i.dataset.answer??"")}"]`)?.click()});for(const i of e.querySelectorAll("[data-reconcile]"))i.onclick=()=>Py({});for(const i of e.querySelectorAll("[data-ignore-drift]"))i.onclick=async()=>{try{await pw(A.server.id,i.dataset.ignoreDrift??""),Ge(`Ignoring ${i.dataset.ignoreDrift}: it is not offered again.`)}catch(s){Ge(`Not ignored: ${s.message}.`,"error")}};for(const i of e.querySelectorAll("select[data-drift-add]"))i.onchange=()=>{const s=i.dataset.driftAdd??"",a=i.value;if(!a||!s)return;const l=A.server?.plan?.nodes?.[a]?.files??[];Kt([{op:"node.set",id:a,files:[...l,s]}],`Added ${s} to ${A.server?.plan?.nodes?.[a]?.label??a}.`,`you added ${s} to ${a}`)};for(const i of e.querySelectorAll("[data-review]"))i.onclick=()=>Kt([{op:"review",ids:[i.dataset.review]}],`Marked ${i.dataset.review} as reviewed.`);for(const i of e.querySelectorAll("[data-accept]"))i.onclick=()=>Kt([{op:"proposal.accept",id:i.dataset.accept}],`Accepted ${i.dataset.accept}.`);for(const i of e.querySelectorAll("[data-finish]"))i.onclick=()=>Kt([{op:"plan.set",phase:"done"}],"Plan marked done.","you marked the plan done");const t=async(i,s,a=!1)=>{const l=e.querySelector(`[data-permit-why="${CSS.escape(i)}"]`)?.value.trim(),{status:u}=await kw(i,s,s==="deny"?l:void 0,a);Ge(u===200?s==="deny"?"Denied: the agent is told why.":a?"Allowed, and it will not ask again for this kind until its session ends.":"Allowed: the agent carries on.":u===409?"That one cannot be allowed for good: allow it once, or deny it.":"That prompt was already answered in the agent's window.",u===200?"info":"error"),A.server&&Un({quiet:!0})};for(const i of e.querySelectorAll("[data-permit]"))i.onclick=()=>t(i.dataset.permit??"","allow");for(const i of e.querySelectorAll("[data-permit-always]"))i.onclick=()=>t(i.dataset.permitAlways??"","allow",!0);for(const i of e.querySelectorAll("[data-deny]"))i.onclick=()=>t(i.dataset.deny??"","deny");for(const i of e.querySelectorAll("[data-reject]"))i.onclick=()=>{const s=e.querySelector(`[data-why="${CSS.escape(i.dataset.reject??"")}"]`)?.value.trim();Kt([{op:"proposal.reject",id:i.dataset.reject,...s?{reason:s}:{}}],`Rejected ${i.dataset.reject}.`)};const n=(A.server?.plan?.proposals??[]).map(i=>i.id),r=e.querySelector("[data-accept-all]");r&&(r.onclick=()=>Kt(n.map(i=>({op:"proposal.accept",id:i})),`Accepted ${n.length} proposals.`));const o=e.querySelector("[data-reject-all]");o&&(o.onclick=()=>Kt(n.map(i=>({op:"proposal.reject",id:i})),`Rejected ${n.length} proposals.`));for(const i of e.querySelectorAll("[data-show-step]"))i.onclick=()=>y1(i.dataset.showStep??"");for(const i of e.querySelectorAll("[data-show-proposal]"))i.onclick=()=>zd(i.dataset.showProposal??"")}function P7(){const e=B("jsonErr");try{if(A.mode==="architecture"){Ye.applyJSON(B("json").value),e.hidden=!0;return}const t=JSON.parse(B("json").value);if(!Array.isArray(t.steps)||!Array.isArray(t.depends))throw new Error("needs a `steps` array and a `depends` array");const n=new Set(t.steps.map(o=>o.id)),r=t.depends.filter(o=>!n.has(o.source)||!n.has(o.target));if(r.length)throw new Error(r.length===1?`a dependency names a step that is not in steps (${r[0].source} → ${r[0].target})`:`${r.length} dependencies name steps that are not in steps`);if(e.hidden=!0,A.source==="server"){const o=ig(A.server,{steps:t.steps,depends:t.depends});o.length&&Kt(o,`Applied ${o.length} operation${o.length===1?"":"s"}.`);return}A.chart.setData({steps:t.steps,depends:t.depends}),dn()}catch(t){e.hidden=!1,e.textContent=`Not applied — ${t.message}`}}function pr(e){A.panel=e;for(const t of B("tabs").children)t.setAttribute("aria-selected",String(t.dataset.panel===e));dn()}function Xi(){B("tabs").innerHTML=(A.mode==="architecture"?Ye.panels():g7[A.source]).map(e=>`<button role="tab" aria-selected="false" data-panel="${e}">${e}${e==="Changes"&&A.source==="samples"?'<span class="count" hidden></span>':""}</button>`).join("");for(const e of B("tabs").children)e.onclick=()=>pr(e.dataset.panel??"")}function z7(){const e=B("tabs").querySelector(".count");if(!e||!A.start)return;const t=s1(A.start,Ps()).length;e.hidden=!t,e.textContent=String(t)}function w1(e,t){const n=l1();if(!n){j7(e,t);return}const r=t?n.second:n.first;if(!(!r||r.disabled)){if(r.confirm&&e.dataset.armed!==r.label){e.dataset.armed=r.label,Io(e,r),setTimeout(()=>{e.dataset.armed===r.label&&(delete e.dataset.armed,a1())},4e3);return}delete e.dataset.armed,D7(r).then(o=>{if(gs(),!o)return;const i=o.find(s=>["planApproved","started","resumed","stopped","archAccepted"].includes(s.kind));i?Zo(i.kind==="archAccepted"?i:El(i)):r.ops[0]?.op==="plan.stop"&&A.server?.stopping?.length&&Ge(`Stopped. ${Z1(A.server.stopping)} ${A.server.stopping.length===1?"stops":"stop"} at the next tool call; press Start to carry on.`)})}}async function D7(e){if(e.target==="plan"&&A.mode==="plan"&&A.server?.id===e.plan)return await Kt(e.ops,e.message,e.reason)?bs:null;try{if(e.target==="architecture"){if(A.mode==="architecture"&&A.source==="server"&&Ye.current())return await Ye.sendFromBar(e.ops,e.message,e.reason)?[]:null;const o=await Ji(),{status:i,body:s}=await ou(o.rev??0,e.ops,e.reason);return i!==200?(Ge(`Not done: ${s.why??s.error}`,"error"),null):(Ge(e.message),s.calls??[])}const t=await Al(e.plan),{status:n,body:r}=await hf(e.plan,t.rev,e.ops,e.reason);return n!==200?(Ge(`Not done: ${r.why??r.error}`,"error"),null):(Ge(e.message),r.calls??[])}catch(t){return Ge(`Not done: ${t.message}`,"error"),null}}function j7(e,t){const n=A.server;if(!n?.plan)return;const r=Ca(n.plan.phase,n.derived?.progress,n.listening??[]),o=t?r.second:r;if(o){if(o.confirm&&e.dataset.armed!==o.label){e.dataset.armed=o.label,Io(e,o),setTimeout(()=>{e.dataset.armed===o.label&&(delete e.dataset.armed,mr())},4e3);return}delete e.dataset.armed,Kt(o.ops,o.message,o.reason)}}B("phase").onclick=()=>w1(B("phase"),!1);B("phase2").onclick=()=>w1(B("phase2"),!0);const El=e=>A.server?.calls?.find(t=>t.id===e.id)??e,x1=()=>Li(location.hash).sample??null;async function Bn(e,{open:t=!0,id:n}={}){if(e===A.mode&&t&&A.chart||(A.mode==="architecture"&&e!=="architecture"&&Ye.leave(),e==="architecture"&&(Re.unfollow?.(),Re.unfollow=null,Re.pending=!1),A.mode=e,A.selected=null,io={},document.body.dataset.mode=e,B("modePlan").setAttribute("aria-pressed",String(e==="plan")),B("modeArch").setAttribute("aria-pressed",String(e==="architecture")),B("modeBadge").innerHTML=e==="plan"?"<b>Plan</b> an arrow A → B means B comes after A":"<b>Architecture</b> an arrow A → B means A uses B",B("chart").setAttribute("aria-label",e==="plan"?"Plan board. Tab to a step: the arrow keys move it, Enter renames it, Delete removes it. Scroll to look around.":"Architecture board. Tab to a box: the arrow keys move it, Enter renames it, Delete removes it. Scroll to look around."),B("planbar").hidden=!0,B("needs").hidden=!0,Ge(""),so(),!t))return;if(Xi(),e==="architecture"){if(A.source==="server")history.replaceState(null,"","#architecture"),pr("Boxes"),await Ye.openServer();else{const o=yf(n??x1()??Zi[0]?.id);history.replaceState(null,"",`#architecture/${o.id}`),zy(),pr("Flows"),Ye.openSample(o)}return}const r=n??Li(location.hash).plan??"";if(A.source==="server"){pr("Steps"),await Do();const o=A.plans.find(i=>i.id===r)??A.plans[0];o?(history.replaceState(null,"",`#${o.id}`),Ir(o.id)):ws("none")}else{pr("Changes"),zy();const o=Tl(r);history.replaceState(null,"",`#${o.id}`),po(o)}}B("modePlan").onclick=()=>Bn("plan");B("modeArch").onclick=()=>Bn("architecture");B("undo").title=`Undo (${vl}Z)`;B("redo").title=`Redo (${vl==="⌘"?"⇧⌘Z":"Ctrl+Shift+Z"})`;B("undo").onclick=()=>{A.chart&&(A.chart.undo(),Jo())};B("redo").onclick=()=>{A.chart&&(A.chart.redo(),Jo())};B("reset").onclick=()=>A.mode==="architecture"?Ye.reset():A.source==="server"?Un({reseed:!0,quiet:!0}):po(Tl(A.plan.id));document.addEventListener("keydown",e=>{const t=e.target;if(!(t instanceof HTMLElement&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable))){if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="z"){if(e.preventDefault(),!A.chart)return;e.shiftKey?A.chart.redo():A.chart.undo(),Jo();return}if(!(e.metaKey||e.ctrlKey||e.altKey)){if(e.key==="Escape"&&A.drawer.open&&!e.defaultPrevented&&(document.activeElement===document.body||B("drawer").contains(document.activeElement))){Qo(!1);return}if(e.key==="s"||e.key==="S"){Qo(!A.drawer.open);return}if(e.key==="?"){const n=B("help");n.open=!n.open;return}if(e.key==="+"||e.key==="="){Ki.zoomIn();return}if(e.key==="-"||e.key==="_"){Ki.zoomOut();return}if(e.key==="0"){Ki.fit();return}}}});await G1();const gi=await V1();if(gi){A.source="server",A.root=gi.root,document.body.dataset.source="server";const e=gi.root.split(/[\\/]/).filter(Boolean).pop()??gi.root;B("descr").textContent=`Plans in ${e}/.dcursed/plans. Every gesture is saved as you make it, and changes made elsewhere show up here.`,B("descr").title=`${gi.root}/.dcursed/plans`,B("reset").textContent="Reload",B("reset").title="Reload the plan as the server holds it",Xi(),pr("Steps"),await Do(),X1({plans:r=>_7(r),open:r=>{r&&Fd()}}),await ua(),tg({change:()=>ua(),problem:()=>{},call:()=>{},open:()=>ua(),down:()=>{}}),setInterval(()=>{document.hidden||ua()},5e3),v7();const t=Li(location.hash),n=A.plans.find(r=>r.id===t.plan)??A.plans[0];t.architecture?await Bn("architecture"):n?await Ir(n.id):ws("none"),await jy(t),addEventListener("hashchange",async()=>{const r=Li(location.hash);!r.architecture&&r.plan&&(r.plan!==A.server?.id||A.mode==="architecture")?(A.mode==="architecture"&&await Bn("plan",{open:!1}),await Ir(r.plan)):r.architecture&&await Bn("architecture"),await jy(r)})}else if(!Jr.length)B("descr").textContent="",B("switcher").hidden=!0,Xi(),pr("Steps"),ws("server");else{const e=()=>{const t=x1(),n=!!t||location.hash==="#architecture",r=Li(location.hash).plan??"";return n&&A.mode==="architecture"?Ye.openSample(yf(t??"")):!n&&A.mode==="plan"&&A.chart?po(Tl(r)):n?Bn("architecture",{id:t??void 0}):Bn("plan",{id:r})};Xi(),await e(),addEventListener("hashchange",e)}Object.assign(window,{elicit:y3,app:A,interactions:Xo});
122
+ <div>${n.ops.map(r=>Be(t(r))).join(" · ")}</div></li>`).join("")}</ul>`}const cf=new Map,ru=new Set,L7=5e3,m1=()=>A.mode==="architecture"?Ye.knownFileInfo():Object.fromEntries([...cf].map(([e,t])=>[e,t.info]));function b1(){if(A.mode==="architecture")return Ye.pickedBox();const e=A.selected,t=e?A.server?.plan?.nodes[e]:void 0;return e&&t?{id:e,files:t.files??[]}:null}function uf(){if(A.mode==="architecture"){Ye.askFileInfo(vs);return}const e=b1();if(!e||A.source!=="server")return;const t=Date.now(),n=e.files.filter(r=>!ru.has(r)&&!((cf.get(r)?.at??0)>t-L7));if(n.length){for(const r of n)ru.add(r);df(n).then(r=>{for(const o of r)cf.set(o.path,{at:Date.now(),info:{kind:o.kind,matches:o.matches}})}).catch(()=>{}).finally(()=>{for(const r of n)ru.delete(r);vs()})}}function vs(){const e=b1(),t=B("panel").querySelector(".files .chips");if(!e||!t)return;const n=yw(e.id,e.files,m1());t.innerHTML!==n&&(t.innerHTML=n)}async function Hy(e,t){if(A.mode==="architecture"){const o=await Ye.saveFiles(e,t);return vs(),uf(),o}const n=A.server?.plan.nodes[e];if(!n)return!1;const r=await Kt([{op:"node.set",id:e,files:t}],`Saved the files for ${n.label}.`,`you edited the files of ${e}`);return vs(),uf(),r}function F7(){const e=B("panel").querySelector("[data-files-input]"),t=B("panel").querySelector(".files-menu"),n=B("panel").querySelector(".files .chips");if(!e||!t||!n)return;const r=e.dataset.filesInput;let o=[],i=-1,s=0,a=!1,l;const u=()=>(A.mode==="architecture"?Ye.current()?.arch.nodes[r]?.files:A.server?.plan.nodes[r]?.files)??[];n.addEventListener("click",h=>{const y=h.target instanceof Element?h.target.closest("[data-remove-file]"):null;y&&Hy(r,mw(u(),y.dataset.removeFile??""))});const c=()=>{t.hidden=!0,e.setAttribute("aria-expanded","false"),e.removeAttribute("aria-activedescendant"),i=-1},d=()=>{const h=e.value.trim();t.innerHTML=o.length?o.map((y,g)=>`<li role="option" id="insp-files-opt-${g}" data-row="${g}" aria-selected="${g===i}" class="${y.kind}"><code>${Be(y.path)}</code>${y.note?`<span>${Be(y.note)}</span>`:""}</li>`).join(""):`<li class="none" role="presentation">${h?"Nothing in the repository has that in its path. Enter adds it as you typed it.":"No files to offer."}</li>`,t.hidden=!1,e.setAttribute("aria-expanded","true"),i>=0?e.setAttribute("aria-activedescendant",`insp-files-opt-${i}`):e.removeAttribute("aria-activedescendant")};async function f(){const h=++s,y=e.value;try{const[g,m]=await Promise.all([Sw(y),y.trim()?df([$w(y)]):Promise.resolve([])]);if(h!==s)return;o=_w(y,g.files,m[0],u()),i=o.length&&y.trim()?0:-1,a=!1,d()}catch{h===s&&(o=[],a=!1,d())}}async function p(h){const y=Mw(u(),h);e.value="",y!==u()&&await Hy(r,y),f()}e.addEventListener("input",()=>{a=!0,clearTimeout(l),l=setTimeout(f,120)}),e.addEventListener("focus",()=>f()),e.addEventListener("blur",()=>{clearTimeout(l),setTimeout(()=>{document.activeElement!==e&&c()},120)}),e.addEventListener("keydown",h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){if(t.hidden){f();return}h.preventDefault(),o.length&&(i=(i+(h.key==="ArrowDown"?1:-1)+o.length)%o.length),d()}else h.key==="Enter"?(h.preventDefault(),(async()=>{a&&(clearTimeout(l),await f());const y=e.value.trim();i>=0&&o[i]?p(o[i].path):y&&p(y)})()):h.key==="Escape"&&!t.hidden&&(h.preventDefault(),h.stopPropagation(),c())}),t.addEventListener("mousedown",h=>h.preventDefault()),t.addEventListener("click",h=>{const y=h.target instanceof Element?h.target.closest("[data-row]"):null,g=y?o[Number(y.dataset.row)]:void 0;g&&p(g.path)})}function R7(){for(const e of B("panel").querySelectorAll("[data-inspect]"))e.onclick=()=>Vo(e.dataset.inspect??null);for(const e of B("panel").querySelectorAll("[data-close-inspector]"))e.onclick=()=>Vo(null);for(const e of B("panel").querySelectorAll("textarea[data-field]"))e.addEventListener("input",()=>{io[e.dataset.field]=e.value}),e.addEventListener("blur",()=>Ea(e)),e.addEventListener("keydown",t=>{const n=t;n.key==="Enter"&&(n.metaKey||n.ctrlKey)&&(n.preventDefault(),Ea(e))});for(const e of B("panel").querySelectorAll("[data-remove-touch]"))e.onclick=()=>{const t=e.dataset.step??"",n=e.dataset.removeTouch??"",r=A.server?.plan.nodes[t]?.touches??[];Kt([{op:"node.set",id:t,touches:r.filter(o=>o!==n)}],`${A.server?.plan.nodes[t]?.label??t} no longer changes ${xs?.nodes[n]?.label??n}.`,`you edited the boxes ${t} changes`)};for(const e of B("panel").querySelectorAll("select[data-touch-add]"))e.onchange=()=>{const t=e.dataset.touchAdd??"",n=e.value;if(!n)return;const r=A.server?.plan.nodes[t]?.touches??[];Kt([{op:"node.set",id:t,touches:[...r,n]}],`${A.server?.plan.nodes[t]?.label??t} changes ${xs?.nodes[n]?.label??n}.`,`you edited the boxes ${t} changes`)};for(const e of B("panel").querySelectorAll("[data-save-field]"))e.onclick=()=>{const t=B("panel").querySelector(`#insp-${e.dataset.saveField}`);t&&Ea(t)};for(const e of B("panel").querySelectorAll("li.step[data-step]")){const t=e.dataset.step;e.addEventListener("mouseenter",()=>{Gi=t,Ml()}),e.addEventListener("mouseleave",()=>{Gi=null,Ml()})}pc(B("panel"))}function pc(e){for(const i of e.querySelectorAll("[data-act]"))i.onclick=async()=>{if(i.dataset.act==="replan"||i.dataset.act==="drift"){Py(i.dataset.act==="replan"?{kind:"failure",step:i.dataset.step}:{kind:"drift"});return}const s=e.querySelector(`[data-answer="${CSS.escape(i.dataset.step??"")}"]`),a=dw(i.dataset.act,i.dataset.step,s?.value??"");a?Kt(a.ops,a.message,a.reason).then(l=>{const u=l&&bs.find(c=>c.kind==="answered");u&&Zo(El(u))}):i.dataset.act==="answer"&&s?.focus()};for(const i of e.querySelectorAll("[data-gate]"))i.onclick=()=>{const{gate:s,from:a,to:l,option:u}=i.dataset,c=e.querySelector(`[data-gate-text][data-from="${CSS.escape(a??"")}"][data-to="${CSS.escape(l??"")}"]`),d=hw(s??"",a??"",l??"",u??c?.value??"");if(!d){c?.focus();return}Kt(d.ops,d.message,d.reason).then(f=>{const p=f&&bs.find(h=>h.kind==="passed"||h.kind==="sentBack");p&&Zo(El(p))})};for(const i of e.querySelectorAll("[data-gate-text]"))i.addEventListener("keydown",s=>{if(s.key!=="Enter")return;const{from:a,to:l}=i.dataset,u=`[data-from="${CSS.escape(a??"")}"][data-to="${CSS.escape(l??"")}"]`;(e.querySelector(`[data-gate="give"]:not([data-option])${u}`)??e.querySelector(`[data-gate="pass"]${u}`))?.click()});for(const i of e.querySelectorAll("[data-answer]"))i.addEventListener("keydown",s=>{s.key==="Enter"&&e.querySelector(`[data-act="answer"][data-step="${CSS.escape(i.dataset.answer??"")}"]`)?.click()});for(const i of e.querySelectorAll("[data-reconcile]"))i.onclick=()=>Py({});for(const i of e.querySelectorAll("[data-ignore-drift]"))i.onclick=async()=>{try{await pw(A.server.id,i.dataset.ignoreDrift??""),Ge(`Ignoring ${i.dataset.ignoreDrift}: it is not offered again.`)}catch(s){Ge(`Not ignored: ${s.message}.`,"error")}};for(const i of e.querySelectorAll("select[data-drift-add]"))i.onchange=()=>{const s=i.dataset.driftAdd??"",a=i.value;if(!a||!s)return;const l=A.server?.plan?.nodes?.[a]?.files??[];Kt([{op:"node.set",id:a,files:[...l,s]}],`Added ${s} to ${A.server?.plan?.nodes?.[a]?.label??a}.`,`you added ${s} to ${a}`)};for(const i of e.querySelectorAll("[data-review]"))i.onclick=()=>Kt([{op:"review",ids:[i.dataset.review]}],`Marked ${i.dataset.review} as reviewed.`);for(const i of e.querySelectorAll("[data-accept]"))i.onclick=()=>Kt([{op:"proposal.accept",id:i.dataset.accept}],`Accepted ${i.dataset.accept}.`);for(const i of e.querySelectorAll("[data-finish]"))i.onclick=()=>Kt([{op:"plan.set",phase:"done"}],"Plan marked done.","you marked the plan done");const t=async(i,s,a=!1)=>{const l=e.querySelector(`[data-permit-why="${CSS.escape(i)}"]`)?.value.trim(),{status:u}=await kw(i,s,s==="deny"?l:void 0,a);Ge(u===200?s==="deny"?"Denied: the agent is told why.":a?"Allowed, and it will not ask again for this kind until its session ends.":"Allowed: the agent carries on.":u===409?"That one cannot be allowed for good: allow it once, or deny it.":"That prompt was already answered in the agent's window.",u===200?"info":"error"),A.server&&Un({quiet:!0})};for(const i of e.querySelectorAll("[data-permit]"))i.onclick=()=>t(i.dataset.permit??"","allow");for(const i of e.querySelectorAll("[data-permit-always]"))i.onclick=()=>t(i.dataset.permitAlways??"","allow",!0);for(const i of e.querySelectorAll("[data-deny]"))i.onclick=()=>t(i.dataset.deny??"","deny");for(const i of e.querySelectorAll("[data-reject]"))i.onclick=()=>{const s=e.querySelector(`[data-why="${CSS.escape(i.dataset.reject??"")}"]`)?.value.trim();Kt([{op:"proposal.reject",id:i.dataset.reject,...s?{reason:s}:{}}],`Rejected ${i.dataset.reject}.`)};const n=(A.server?.plan?.proposals??[]).map(i=>i.id),r=e.querySelector("[data-accept-all]");r&&(r.onclick=()=>Kt(n.map(i=>({op:"proposal.accept",id:i})),`Accepted ${n.length} proposals.`));const o=e.querySelector("[data-reject-all]");o&&(o.onclick=()=>Kt(n.map(i=>({op:"proposal.reject",id:i})),`Rejected ${n.length} proposals.`));for(const i of e.querySelectorAll("[data-show-step]"))i.onclick=()=>y1(i.dataset.showStep??"");for(const i of e.querySelectorAll("[data-show-proposal]"))i.onclick=()=>zd(i.dataset.showProposal??"")}function P7(){const e=B("jsonErr");try{if(A.mode==="architecture"){Ye.applyJSON(B("json").value),e.hidden=!0;return}const t=JSON.parse(B("json").value);if(!Array.isArray(t.steps)||!Array.isArray(t.depends))throw new Error("needs a `steps` array and a `depends` array");const n=new Set(t.steps.map(o=>o.id)),r=t.depends.filter(o=>!n.has(o.source)||!n.has(o.target));if(r.length)throw new Error(r.length===1?`a dependency names a step that is not in steps (${r[0].source} → ${r[0].target})`:`${r.length} dependencies name steps that are not in steps`);if(e.hidden=!0,A.source==="server"){const o=ig(A.server,{steps:t.steps,depends:t.depends});o.length&&Kt(o,`Applied ${o.length} operation${o.length===1?"":"s"}.`);return}A.chart.setData({steps:t.steps,depends:t.depends}),dn()}catch(t){e.hidden=!1,e.textContent=`Not applied — ${t.message}`}}function pr(e){A.panel=e;for(const t of B("tabs").children)t.setAttribute("aria-selected",String(t.dataset.panel===e));dn()}function Xi(){B("tabs").innerHTML=(A.mode==="architecture"?Ye.panels():g7[A.source]).map(e=>`<button role="tab" aria-selected="false" data-panel="${e}">${e}${e==="Changes"&&A.source==="samples"?'<span class="count" hidden></span>':""}</button>`).join("");for(const e of B("tabs").children)e.onclick=()=>pr(e.dataset.panel??"")}function z7(){const e=B("tabs").querySelector(".count");if(!e||!A.start)return;const t=s1(A.start,Ps()).length;e.hidden=!t,e.textContent=String(t)}function w1(e,t){const n=l1();if(!n){j7(e,t);return}const r=t?n.second:n.first;if(!(!r||r.disabled)){if(r.confirm&&e.dataset.armed!==r.label){e.dataset.armed=r.label,Io(e,r),setTimeout(()=>{e.dataset.armed===r.label&&(delete e.dataset.armed,a1())},4e3);return}delete e.dataset.armed,D7(r).then(o=>{if(gs(),!o)return;const i=o.find(s=>["planApproved","started","resumed","stopped","archAccepted"].includes(s.kind));i?Zo(i.kind==="archAccepted"?i:El(i)):r.ops[0]?.op==="plan.stop"&&A.server?.stopping?.length&&Ge(`Stopped. ${Z1(A.server.stopping)} ${A.server.stopping.length===1?"stops":"stop"} at the next tool call; press Start to carry on.`)})}}async function D7(e){if(e.target==="plan"&&A.mode==="plan"&&A.server?.id===e.plan)return await Kt(e.ops,e.message,e.reason)?bs:null;try{if(e.target==="architecture"){if(A.mode==="architecture"&&A.source==="server"&&Ye.current())return await Ye.sendFromBar(e.ops,e.message,e.reason)?[]:null;const o=await Ji(),{status:i,body:s}=await ou(o.rev??0,e.ops,e.reason);return i!==200?(Ge(`Not done: ${s.why??s.error}`,"error"),null):(Ge(e.message),s.calls??[])}const t=await Al(e.plan),{status:n,body:r}=await hf(e.plan,t.rev,e.ops,e.reason);return n!==200?(Ge(`Not done: ${r.why??r.error}`,"error"),null):(Ge(e.message),r.calls??[])}catch(t){return Ge(`Not done: ${t.message}`,"error"),null}}function j7(e,t){const n=A.server;if(!n?.plan)return;const r=Ca(n.plan.phase,n.derived?.progress,n.listening??[]),o=t?r.second:r;if(o){if(o.confirm&&e.dataset.armed!==o.label){e.dataset.armed=o.label,Io(e,o),setTimeout(()=>{e.dataset.armed===o.label&&(delete e.dataset.armed,mr())},4e3);return}delete e.dataset.armed,Kt(o.ops,o.message,o.reason)}}B("phase").onclick=()=>w1(B("phase"),!1);B("phase2").onclick=()=>w1(B("phase2"),!0);const El=e=>A.server?.calls?.find(t=>t.id===e.id)??e,x1=()=>Li(location.hash).sample??null;async function Bn(e,{open:t=!0,id:n}={}){if(e===A.mode&&t&&A.chart||(A.mode==="architecture"&&e!=="architecture"&&Ye.leave(),e==="architecture"&&(Pe.unfollow?.(),Pe.unfollow=null,Pe.pending=!1),A.mode=e,A.selected=null,io={},document.body.dataset.mode=e,B("modePlan").setAttribute("aria-pressed",String(e==="plan")),B("modeArch").setAttribute("aria-pressed",String(e==="architecture")),B("modeBadge").innerHTML=e==="plan"?"<b>Plan</b> an arrow A → B means B comes after A":"<b>Architecture</b> an arrow A → B means A uses B",B("chart").setAttribute("aria-label",e==="plan"?"Plan board. Tab to a step: the arrow keys move it, Enter renames it, Delete removes it. Scroll to look around.":"Architecture board. Tab to a box: the arrow keys move it, Enter renames it, Delete removes it. Scroll to look around."),B("planbar").hidden=!0,B("needs").hidden=!0,Ge(""),so(),!t))return;if(Xi(),e==="architecture"){if(A.source==="server")history.replaceState(null,"","#architecture"),pr("Boxes"),await Ye.openServer();else{const o=yf(n??x1()??Zi[0]?.id);history.replaceState(null,"",`#architecture/${o.id}`),zy(),pr("Flows"),Ye.openSample(o)}return}const r=n??Li(location.hash).plan??"";if(A.source==="server"){pr("Steps"),await Do();const o=A.plans.find(i=>i.id===r)??A.plans[0];o?(history.replaceState(null,"",`#${o.id}`),Ir(o.id)):ws("none")}else{pr("Changes"),zy();const o=Tl(r);history.replaceState(null,"",`#${o.id}`),po(o)}}B("modePlan").onclick=()=>Bn("plan");B("modeArch").onclick=()=>Bn("architecture");B("undo").title=`Undo (${vl}Z)`;B("redo").title=`Redo (${vl==="⌘"?"⇧⌘Z":"Ctrl+Shift+Z"})`;B("undo").onclick=()=>{A.chart&&(A.chart.undo(),Jo())};B("redo").onclick=()=>{A.chart&&(A.chart.redo(),Jo())};B("reset").onclick=()=>A.mode==="architecture"?Ye.reset():A.source==="server"?Un({reseed:!0,quiet:!0}):po(Tl(A.plan.id));document.addEventListener("keydown",e=>{const t=e.target;if(!(t instanceof HTMLElement&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable))){if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="z"){if(e.preventDefault(),!A.chart)return;e.shiftKey?A.chart.redo():A.chart.undo(),Jo();return}if(!(e.metaKey||e.ctrlKey||e.altKey)){if(e.key==="Escape"&&A.drawer.open&&!e.defaultPrevented&&(document.activeElement===document.body||B("drawer").contains(document.activeElement))){Qo(!1);return}if(e.key==="s"||e.key==="S"){Qo(!A.drawer.open);return}if(e.key==="?"){const n=B("help");n.open=!n.open;return}if(e.key==="+"||e.key==="="){Ki.zoomIn();return}if(e.key==="-"||e.key==="_"){Ki.zoomOut();return}if(e.key==="0"){Ki.fit();return}}}});await G1();const gi=await V1();if(gi){A.source="server",A.root=gi.root,document.body.dataset.source="server";const e=gi.root.split(/[\\/]/).filter(Boolean).pop()??gi.root;B("descr").textContent=`Plans in ${e}/.diacode/plans. Every gesture is saved as you make it, and changes made elsewhere show up here.`,B("descr").title=`${gi.root}/.diacode/plans`,B("reset").textContent="Reload",B("reset").title="Reload the plan as the server holds it",Xi(),pr("Steps"),await Do(),X1({plans:r=>_7(r),open:r=>{r&&Fd()}}),await ua(),tg({change:()=>ua(),problem:()=>{},call:()=>{},open:()=>ua(),down:()=>{}}),setInterval(()=>{document.hidden||ua()},5e3),v7();const t=Li(location.hash),n=A.plans.find(r=>r.id===t.plan)??A.plans[0];t.architecture?await Bn("architecture"):n?await Ir(n.id):ws("none"),await jy(t),addEventListener("hashchange",async()=>{const r=Li(location.hash);!r.architecture&&r.plan&&(r.plan!==A.server?.id||A.mode==="architecture")?(A.mode==="architecture"&&await Bn("plan",{open:!1}),await Ir(r.plan)):r.architecture&&await Bn("architecture"),await jy(r)})}else if(!Jr.length)B("descr").textContent="",B("switcher").hidden=!0,Xi(),pr("Steps"),ws("server");else{const e=()=>{const t=x1(),n=!!t||location.hash==="#architecture",r=Li(location.hash).plan??"";return n&&A.mode==="architecture"?Ye.openSample(yf(t??"")):!n&&A.mode==="plan"&&A.chart?po(Tl(r)):n?Bn("architecture",{id:t??void 0}):Bn("plan",{id:r})};Xi(),await e(),addEventListener("hashchange",e)}Object.assign(window,{elicit:y3,app:A,interactions:Xo});