aggregate_api 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. aggregate_api/__init__.py +41 -0
  2. aggregate_api/__main__.py +154 -0
  3. aggregate_api/app.py +206 -0
  4. aggregate_api/audit.py +395 -0
  5. aggregate_api/bounds.py +331 -0
  6. aggregate_api/cache.py +319 -0
  7. aggregate_api/capability.py +823 -0
  8. aggregate_api/completion.py +219 -0
  9. aggregate_api/config.py +363 -0
  10. aggregate_api/cors.py +61 -0
  11. aggregate_api/examples.py +620 -0
  12. aggregate_api/layer_pricing.py +840 -0
  13. aggregate_api/library.py +94 -0
  14. aggregate_api/library_notes.py +96 -0
  15. aggregate_api/models.py +1407 -0
  16. aggregate_api/net.py +281 -0
  17. aggregate_api/pnl.py +101 -0
  18. aggregate_api/pricing.py +778 -0
  19. aggregate_api/resources.py +257 -0
  20. aggregate_api/routes/__init__.py +8 -0
  21. aggregate_api/routes/decl.py +327 -0
  22. aggregate_api/routes/examples.py +82 -0
  23. aggregate_api/routes/meta.py +282 -0
  24. aggregate_api/routes/objects.py +4119 -0
  25. aggregate_api/routes/status.py +466 -0
  26. aggregate_api/serializers.py +565 -0
  27. aggregate_api/sessions.py +353 -0
  28. aggregate_api/static/aggregate-api-logo-512.png +0 -0
  29. aggregate_api/static/aggregate-api-logo.png +0 -0
  30. aggregate_api/static/aggregate-api-trim.png +0 -0
  31. aggregate_api/static/android-chrome-192x192.png +0 -0
  32. aggregate_api/static/android-chrome-512x512.png +0 -0
  33. aggregate_api/static/apple-touch-icon.png +0 -0
  34. aggregate_api/static/assets/bootstrap-icons-BeopsB42.woff +0 -0
  35. aggregate_api/static/assets/bootstrap-icons-mSm7cUeB.woff2 +0 -0
  36. aggregate_api/static/assets/bootstrap-ohb1VZ53.js +5 -0
  37. aggregate_api/static/assets/codemirror-h62DHGGa.js +14 -0
  38. aggregate_api/static/assets/csv-grid.worker-DKzHGXac.js +4 -0
  39. aggregate_api/static/assets/echarts-B7o9sc00.js +40 -0
  40. aggregate_api/static/assets/echarts-gl-DG1Uf6wE.js +4282 -0
  41. aggregate_api/static/assets/lite-CUlcD8p4.css +1 -0
  42. aggregate_api/static/assets/lite-Dd2TnT4M.js +1 -0
  43. aggregate_api/static/assets/main-Bxhxa55v.css +9 -0
  44. aggregate_api/static/assets/main-CmoEiPit.js +9 -0
  45. aggregate_api/static/assets/tables-BHCF7qIF.js +8 -0
  46. aggregate_api/static/assets/tables-CxvajLr7.css +1 -0
  47. aggregate_api/static/favicon-16x16.png +0 -0
  48. aggregate_api/static/favicon-32x32.png +0 -0
  49. aggregate_api/static/favicon.ico +0 -0
  50. aggregate_api/static/index.html +912 -0
  51. aggregate_api/static/lite.html +83 -0
  52. aggregate_api/static/logo.png +0 -0
  53. aggregate_api/static/site.webmanifest +14 -0
  54. aggregate_api/static/sw.js +78 -0
  55. aggregate_api/status.py +536 -0
  56. aggregate_api/status_page.html +546 -0
  57. aggregate_api/tables.py +316 -0
  58. aggregate_api-1.0.0.dist-info/METADATA +187 -0
  59. aggregate_api-1.0.0.dist-info/RECORD +63 -0
  60. aggregate_api-1.0.0.dist-info/WHEEL +5 -0
  61. aggregate_api-1.0.0.dist-info/entry_points.txt +2 -0
  62. aggregate_api-1.0.0.dist-info/licenses/LICENSE +28 -0
  63. aggregate_api-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./echarts-gl-DG1Uf6wE.js","./echarts-B7o9sc00.js"])))=>i.map(i=>d[i]);
2
+ import{aW as Lr,ab as Ni,ac as Ii,ad as Oi,ae as Fi,af as zi,ag as Pi,ah as ji,ai as Di,aj as Wi,ak as Bi,al as Hi,a9 as Ui,a7 as zn}from"./echarts-B7o9sc00.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const l of s.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();const Gi={},$r=Gi?.VITE_API_BASE_URL||"",Pn="aggregate-session-id",Yi="X-Aggregate-Session";function jn(){const t=new Date().toISOString(),e=globalThis.crypto&&globalThis.crypto.randomUUID?globalThis.crypto.randomUUID():`${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`;return`${t}-${e}`}let Nt=null;function Tr(){if(Nt)return Nt;try{const t=sessionStorage.getItem(Pn);if(t)return Nt=t,Nt;Nt=jn(),sessionStorage.setItem(Pn,Nt)}catch{Nt=Nt||jn()}return Nt}function Xi(){return`&session=${encodeURIComponent(Tr())}`}class Rr extends Error{constructor(e,n,r){super(n&&n.message||`HTTP ${e}`),this.status=e,this.body=n,this.retryAfter=r}}function xc(t){if(!(t instanceof Rr))return t.message;const e=t.body&&(t.body.detail||t.body);return Array.isArray(e)?e.map(n=>{const r=Array.isArray(n.loc)?n.loc[n.loc.length-1]:null;return r?`${r}: ${n.msg}`:n.msg}).join("; "):e&&e.message||(typeof e=="string"?e:t.message)}function oe(t){const e=[];for(const[n,r]of Object.entries(t))r==null||r===""||e.push(`${encodeURIComponent(n)}=${encodeURIComponent(r)}`);return e.join("&")}async function J(t,e,n){const r={[Yi]:Tr()};n&&(r["Content-Type"]="application/json");const i=await fetch($r+e,{method:t,headers:r,body:n?JSON.stringify(n):void 0});let s=null;const l=await i.text();if(l)try{s=JSON.parse(l)}catch{s={message:l}}if(!i.ok)throw new Rr(i.status,s,i.headers.get("Retry-After"));return s}const De=new Map,he={build:(t,e={})=>J("POST","/v1/objects",{decl:t,...e}),list:()=>J("GET","/v1/objects"),manifest:t=>J("GET",`/v1/objects/${t}`),drop:t=>J("DELETE",`/v1/objects/${t}`),info:t=>J("GET",`/v1/objects/${t}/info`),meta_of:t=>J("GET",`/v1/objects/${t}/meta`),tail_df:t=>J("GET",`/v1/objects/${t}/tail_df`),stats_df:t=>J("GET",`/v1/objects/${t}/stats_df`),density_df:(t,e={})=>J("GET",`/v1/objects/${t}/density_df?${oe(e)}`),frameIr:(t,e)=>J("GET",`/v1/objects/${t}/frame/${e}?format=ir`),exhibit:(t,e,n="insurer")=>J("GET",`/v1/objects/${t}/exhibit/${e}?perspective=${n}`),chartDoc:(t,e,n={})=>J("GET",`/v1/objects/${t}/chart/${e}${Object.keys(n).length?`?${oe(n)}`:""}`),kappa:(t,e={})=>J("GET",`/v1/objects/${t}/kappa?${oe(e)}`),reinsDescription:t=>J("GET",`/v1/objects/${t}/reins_description`),quantiles:(t,e,n="aggregate")=>J("GET",`/v1/objects/${t}/quantiles?p=${e.join(",")}&basis=${n}`),layerIndication:(t,e,n=0)=>J("POST",`/v1/objects/${t}/layers/indication`,{layers:e,cede:n}),frameOf:(t,e,n={})=>J("GET",`/v1/objects/${t}/${e}?${oe(n)}`),pnlPentagon:(t,e={})=>J("POST",`/v1/objects/${t}/pnl/pentagon`,e),pricingPreview:(t,e)=>{const n=`${t} ${JSON.stringify(e)}`;let r=De.get(n);return r||(r=J("POST",`/v1/objects/${t}/pricing/preview`,e).finally(()=>{De.delete(n)}),De.set(n,r)),r},pricingCalibrate:(t,e)=>J("POST",`/v1/objects/${t}/pricing/calibrate`,e),pricingAllocate:(t,e)=>J("POST",`/v1/objects/${t}/pricing/allocate`,e),pricingEvaluate:(t,e)=>J("POST",`/v1/objects/${t}/pricing/evaluate`,e),ruin:(t,e)=>J("POST",`/v1/objects/${t}/ruin`,e),sharpen:t=>J("POST",`/v1/objects/${t}/sharpen`,{}),hints:t=>J("POST",`/v1/objects/${t}/hints`,{}),pnl:(t,e={})=>J("POST",`/v1/objects/${t}/pnl`,e),explode:t=>J("POST",`/v1/objects/${t}/explode`,{}),reins:(t,e,{price:n=!1,cede:r=0}={})=>J("POST",`/v1/objects/${t}/reins`,{cession:e,price:n,cede:r}),complete:(t,e)=>J("POST","/v1/decl/complete",{decl:t,cursor:e}),lex:t=>J("POST","/v1/decl/lex",{decl:t}),formatDecl:t=>J("POST","/v1/decl/format",{decl:t}),examples:()=>J("GET","/v1/examples"),heroes:()=>J("GET","/v1/examples/heroes"),meta:()=>J("GET","/v1/meta"),style:()=>J("GET","/v1/meta/style"),health:()=>J("GET","/v1/health"),narrative:t=>J("GET",`/v1/objects/${t}/narrative`),boundsEnvelope:(t,e={})=>J("GET",`/v1/objects/${t}/bounds/envelope?${oe(e)}`),allocationBounds:(t,e)=>J("POST",`/v1/objects/${t}/bounds/allocation?ir=true`,e),pricingBounds:(t,e)=>J("POST",`/v1/objects/${t}/bounds/pricing?ir=true`,e),sessionModelsUrl:(t="raw")=>`${$r}/v1/session/models.agg?form=${t}${Xi()}`},wc=t=>document.getElementById(t);function T(t,e={},...n){const r=document.createElement(t);for(const[i,s]of Object.entries(e||{}))s!=null&&(i==="className"?r.className=s:i==="dataset"?Object.assign(r.dataset,s):i.startsWith("on")&&typeof s=="function"?r.addEventListener(i.slice(2).toLowerCase(),s):r.setAttribute(i,s));return Nr(r,n),r}function Nr(t,e){for(const n of e)if(!(n==null||n===!1)){if(Array.isArray(n)){Nr(t,n);continue}if(n instanceof Node){t.appendChild(n);continue}t.appendChild(document.createTextNode(String(n)))}}function bc(t,...e){t.replaceChildren(...e.flat().filter(Boolean))}function Mt(t){for(;t.firstChild;)t.removeChild(t.firstChild)}const Ir=(t,e)=>t>e?1:t<e?-1:0,rn=1/0,We=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Dn="eexxaacctt",qi=/\p{P}/gu,Vi="A-Z",Ki="a-z",Zi=["en",{numeric:!0,sensitivity:"base"}],Jt=(t,e,n)=>t.replace(Vi,e).replace(Ki,n),Wn={unicode:!1,alpha:null,interSplit:"[^A-Za-z\\d']+",intraSplit:"[a-z][A-Z]",interBound:"[^A-Za-z\\d]",intraBound:"[A-Za-z]\\d|\\d[A-Za-z]|[a-z][A-Z]",interLft:0,interRgt:0,interChars:".",interIns:rn,intraChars:"[a-z\\d']",intraIns:null,intraContr:"'[a-z]{1,2}\\b",intraMode:0,intraSlice:[1,rn],intraSub:null,intraTrn:null,intraDel:null,intraFilt:(t,e,n)=>!0,toUpper:t=>t.toLocaleUpperCase(),toLower:t=>t.toLocaleLowerCase(),compare:null,sort:(t,e,n,r=Ir)=>{let{idx:i,chars:s,terms:l,interLft2:o,interLft1:a,start:c,intraIns:u,interIns:f,cases:h}=t;return i.map((d,w)=>w).sort((d,w)=>s[w]-s[d]||u[d]-u[w]||l[w]+o[w]+.5*a[w]-(l[d]+o[d]+.5*a[d])||f[d]-f[w]||c[d]-c[w]||h[w]-h[d]||r(e[i[d]],e[i[w]]))}},Be=(t,e)=>e==0?"":e==1?t+"??":e==rn?t+"*?":t+`{0,${e}}?`,Bn="(?:\\b|_)";function Fe(t){t=Object.assign({},Wn,t);let{unicode:e,interLft:n,interRgt:r,intraMode:i,intraSlice:s,intraIns:l,intraSub:o,intraTrn:a,intraDel:c,intraContr:u,intraSplit:f,interSplit:h,intraBound:d,interBound:w,intraChars:S,toUpper:N,toLower:W,compare:z}=t;l??(l=i),o??(o=i),a??(a=i),c??(c=i),z??(z=typeof Intl>"u"?Ir:new Intl.Collator(...Zi).compare);let F=t.letters??t.alpha;if(F!=null){let R=N(F),U=W(F);h=Jt(h,R,U),f=Jt(f,R,U),w=Jt(w,R,U),d=Jt(d,R,U),S=Jt(S,R,U),u=Jt(u,R,U)}let L=e?"u":"";const B='".+?"',p=new RegExp(B,"gi"+L),g=new RegExp(`(?:\\s+|^)-(?:${S}+|${B})`,"gi"+L);let{intraRules:y}=t;y==null&&(y=R=>{let U=Wn.intraSlice,m=0,E=0,_=0,v=0;if(/[^\d]/.test(R)){let $=R.length;$<=4?$>=3&&(_=Math.min(a,1),$==4&&(m=Math.min(l,1))):(U=s,m=l,E=o,_=a,v=c)}return{intraSlice:U,intraIns:m,intraSub:E,intraTrn:_,intraDel:v}});let M=!!f,G=new RegExp(f,"g"+L),P=new RegExp(h,"g"+L),H=new RegExp("^"+h+"|"+h+"$","g"+L),X=new RegExp(u,"gi"+L);const I=(R,U=!1)=>{let m=[];R=R.replace(p,_=>(m.push(_),Dn)),R=R.replace(H,""),U||(R=W(R)),M&&(R=R.replace(G,_=>_[0]+" "+_[1]));let E=0;return R.split(P).filter(_=>_!="").map(_=>_===Dn?m[E++]:_)},A=/[^\d]+|\d+/g,b=(R,U=0,m=!1)=>{let E=I(R);if(E.length==0)return[];let _=Array(E.length).fill("");E=E.map((Y,O)=>Y.replace(X,D=>(_[O]=D,"")));let v;if(i==1)v=E.map((Y,O)=>{if(Y[0]==='"')return We(Y.slice(1,-1));let D="";for(let tt of Y.matchAll(A)){let k=tt[0],{intraSlice:Q,intraIns:V,intraSub:q,intraTrn:et,intraDel:rt}=y(k);if(V+q+et+rt==0)D+=k+_[O];else{let[ct,lt]=Q,at=k.slice(0,ct),Ct=k.slice(lt),mt=k.slice(ct,lt);V==1&&at.length==1&&at!=mt[0]&&(at+="(?!"+at+")");let $t=mt.length,bt=[k];if(q)for(let st=0;st<$t;st++)bt.push(at+mt.slice(0,st)+S+mt.slice(st+1)+Ct);if(et)for(let st=0;st<$t-1;st++)mt[st]!=mt[st+1]&&bt.push(at+mt.slice(0,st)+mt[st+1]+mt[st]+mt.slice(st+2)+Ct);if(rt)for(let st=0;st<$t;st++)bt.push(at+mt.slice(0,st+1)+"?"+mt.slice(st+1)+Ct);if(V){let st=Be(S,1);for(let Tt=0;Tt<$t;Tt++)bt.push(at+mt.slice(0,Tt)+st+mt.slice(Tt)+Ct)}D+="(?:"+bt.join("|")+")"+_[O]}}return D});else{let Y=Be(S,l);U==2&&l>0&&(Y=")("+Y+")("),v=E.map((O,D)=>O[0]==='"'?We(O.slice(1,-1)):O.split("").map((tt,k,Q)=>(l==1&&k==0&&Q.length>1&&tt!=Q[k+1]&&(tt+="(?!"+tt+")"),tt)).join(Y)+_[D])}let $=n==2?Bn:"",Z=r==2?Bn:"",x=Z+Be(t.interChars,t.interIns)+$;return U>0?m?v=$+"("+v.join(")"+Z+"|"+$+"(")+")"+Z:(v="("+v.join(")("+x+")(")+")",v="(.??"+$+")"+v+"("+Z+".*)"):(v=v.join(x),v=$+v+Z),[new RegExp(v,"i"+L),E,_]},C=(R,U,m)=>{let[E]=b(U);if(E==null)return null;let _=[];if(m!=null)for(let v=0;v<m.length;v++){let $=m[v];E.test(R[$])&&_.push($)}else for(let v=0;v<R.length;v++)E.test(R[v])&&_.push(v);return _};let j=!!d,K=new RegExp(w,L),it=new RegExp(d,L);const nt=(R,U,m)=>{let[E,_,v]=b(m,1),$=I(m,!0),[Z]=b(m,2),x=_.length,Y=Array(x),O=Array(x);for(let q=0;q<x;q++){let et=_[q],rt=$[q],ct=et[0]=='"'?et.slice(1,-1):et+v[q],lt=rt[0]=='"'?rt.slice(1,-1):rt+v[q];Y[q]=ct,O[q]=lt}let D=R.length,tt=Array(D).fill(0),k={idx:Array(D),start:tt.slice(),chars:tt.slice(),cases:tt.slice(),terms:tt.slice(),interIns:tt.slice(),intraIns:tt.slice(),interLft2:tt.slice(),interRgt2:tt.slice(),interLft1:tt.slice(),interRgt1:tt.slice(),ranges:Array(D)},Q=n==1||r==1,V=0;for(let q=0;q<R.length;q++){let et=U[R[q]],rt=et.match(E),ct=rt.index+rt[1].length,lt=ct,at=!1,Ct=0,mt=0,$t=0,bt=0,st=0,Tt=0,ye=0,Nn=0,In=0,Pt=[];for(let gt=0,wt=2;gt<x;gt++,wt+=2){let It=W(rt[wt]),_t=Y[gt],Pe=O[gt],St=_t.length,At=It.length,vt=It==_t;if(rt[wt]==Pe&&ye++,!vt&&rt[wt+1].length>=St){let yt=W(rt[wt+1]).indexOf(_t);yt>-1&&(Pt.push(lt,At,yt,St),lt+=ot(rt,wt,yt,St),It=_t,At=St,vt=!0,gt==0&&(ct=lt))}if(Q||vt){let yt=lt-1,Rt=lt+At,jt=!1,se=!1;if(yt==-1||K.test(et[yt]))vt&&Ct++,jt=!0;else{if(n==2){at=!0;break}if(j&&it.test(et[yt]+et[yt+1]))vt&&mt++,jt=!0;else if(n==1){let xe=rt[wt+1],Kt=lt+At;if(xe.length>=St){let Dt=0,Zt=!1,Ri=new RegExp(_t,"ig"+L),On;for(;On=Ri.exec(xe);){Dt=On.index;let Fn=Kt+Dt,je=Fn-1;if(je==-1||K.test(et[je])){Ct++,Zt=!0;break}else if(it.test(et[je]+et[Fn])){mt++,Zt=!0;break}}Zt&&(jt=!0,Pt.push(lt,At,Dt,St),lt+=ot(rt,wt,Dt,St),It=_t,At=St,vt=!0,gt==0&&(ct=lt))}if(!jt){at=!0;break}}}if(Rt==et.length||K.test(et[Rt]))vt&&$t++,se=!0;else{if(r==2){at=!0;break}if(j&&it.test(et[Rt-1]+et[Rt]))vt&&bt++,se=!0;else if(r==1){at=!0;break}}vt&&(st+=St,jt&&se&&Tt++)}if(At>St&&(In+=At-St),gt>0&&(Nn+=rt[wt-1].length),!t.intraFilt(_t,It,lt)){at=!0;break}gt<x-1&&(lt+=At+rt[wt+1].length)}if(!at){k.idx[V]=R[q],k.interLft2[V]=Ct,k.interLft1[V]=mt,k.interRgt2[V]=$t,k.interRgt1[V]=bt,k.chars[V]=st,k.terms[V]=Tt,k.cases[V]=ye,k.interIns[V]=Nn,k.intraIns[V]=In,k.start[V]=ct;let gt=et.match(Z),wt=gt.index+gt[1].length,It=Pt.length,_t=It>0?0:1/0,Pe=It-4;for(let yt=2;yt<gt.length;){let Rt=gt[yt].length;if(_t<=Pe&&Pt[_t]==wt){let jt=Pt[_t+1],se=Pt[_t+2],xe=Pt[_t+3],Kt=yt,Dt="";for(let Zt=0;Zt<jt;Kt++)Dt+=gt[Kt],Zt+=gt[Kt].length;gt.splice(yt,Kt-yt,Dt),wt+=ot(gt,yt,se,xe),_t+=4}else wt+=Rt,yt++}wt=gt.index+gt[1].length;let St=k.ranges[V]=[],At=wt,vt=wt;for(let yt=2;yt<gt.length;yt++){let Rt=gt[yt].length;wt+=Rt,yt%2==0?vt=wt:Rt>0&&(St.push(At,vt),At=vt=wt)}vt>At&&St.push(At,vt),V++}}if(V<R.length)for(let q in k)k[q]=k[q].slice(0,V);return k},ot=(R,U,m,E)=>{let _=R[U]+R[U+1].slice(0,m);return R[U-1]+=_,R[U]=R[U+1].slice(m,m+E),R[U+1]=R[U+1].slice(m+E),_.length},ft=5,pt=(R,U,m,E=1e3,_)=>{m=m?m===!0?ft:m:0;let v=null,$=null,Z=[];U=U.replace(g,k=>{let Q=k.trim().slice(1);return Q=Q[0]==='"'?We(Q.slice(1,-1)):Q.replace(qi,""),Q!=""&&Z.push(Q),""});let x=I(U),Y;if(Z.length>0){if(Y=new RegExp(Z.join("|"),"i"+L),x.length==0){let k=[];for(let Q=0;Q<R.length;Q++)Y.test(R[Q])||k.push(Q);return[k,null,null]}}else if(x.length==0)return[null,null,null];if(m>0){let k=I(U);if(k.length>1){let Q=k.slice().sort((q,et)=>et.length-q.length);for(let q=0;q<Q.length;q++){if(_?.length==0)return[[],null,null];_=C(R,Q[q],_)}if(k.length>m)return[_,null,null];v=Or(k).map(q=>q.join(" ")),$=[];let V=new Set;for(let q=0;q<v.length;q++)if(V.size<_.length){let et=_.filter(ct=>!V.has(ct)),rt=C(R,v[q],et);for(let ct=0;ct<rt.length;ct++)V.add(rt[ct]);$.push(rt)}else $.push([])}}v==null&&(v=[U],$=[_?.length>0?_:C(R,U)]);let O=null,D=null;if(Z.length>0&&($=$.map(k=>k.filter(Q=>!Y.test(R[Q])))),$.reduce((k,Q)=>k+Q.length,0)<=E){O={},D=[];for(let k=0;k<$.length;k++){let Q=$[k];if(Q==null||Q.length==0)continue;let V=v[k],q=nt(Q,R,V),et=t.sort(q,R,V,z);if(k>0)for(let rt=0;rt<et.length;rt++)et[rt]+=D.length;for(let rt in q)O[rt]=(O[rt]??[]).concat(q[rt]);D=D.concat(et)}}return[[].concat(...$),O,D]};return{search:(...R)=>pt(...R),split:I,filter:C,info:nt,sort:t.sort}}const Ji=(()=>{let t={A:"ÁÀÃÂÄĄĂÅ",a:"áàãâäąăå",E:"ÉÈÊËĖĚ",e:"éèêëęě",I:"ÍÌÎÏĮİ",i:"íìîïįı",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲŮŰ",u:"úùûüūųůű",C:"ÇČĆ",c:"çčć",D:"Ď",d:"ď",G:"Ğ",g:"ğ",L:"Ł",l:"ł",N:"ÑŃŇ",n:"ñńň",S:"ŠŚȘŞ",s:"šśșş",T:"ŢȚŤ",t:"ţțť",Y:"Ý",y:"ý",Z:"ŻŹŽ",z:"żźž"},e={},n="";for(let s in t)t[s].split("").forEach(l=>{n+=l,e[l]=s});let r=new RegExp(`[${n}]`,"g"),i=s=>e[s];return s=>{if(typeof s=="string")return s.replace(r,i);let l=Array(s.length);for(let o=0;o<s.length;o++)l[o]=s[o].replace(r,i);return l}})();function Or(t){t=t.slice();let e=t.length,n=[t.slice()],r=new Array(e).fill(0),i=1,s,l;for(;i<e;)r[i]<i?(s=i%2&&r[i],l=t[i],t[i]=t[s],t[s]=l,++r[i],i=1,n.push(t.slice())):(r[i]=0,++i);return n}const Qi=(t,e)=>e?`<mark>${t}</mark>`:t,ts=(t,e)=>t+e;function es(t,e,n=Qi,r="",i=ts){r=i(r,n(t.substring(0,e[0]),!1))??r;for(let s=0;s<e.length;s+=2){let l=e[s],o=e[s+1];r=i(r,n(t.substring(l,o),!0))??r,s<e.length-3&&(r=i(r,n(t.substring(e[s+1],e[s+2]),!1))??r)}return r=i(r,n(t.substring(e[e.length-1]),!1))??r,r}Fe.latinize=Ji;Fe.permute=t=>Or([...Array(t.length).keys()]).sort((n,r)=>{for(let i=0;i<n.length;i++)if(n[i]!=r[i])return n[i]-r[i];return 0}).map(n=>n.map(r=>t[r]));Fe.highlight=es;let Qt=null,we=null,ne=null,Fr=null;function ns(t){const{idx:e,chars:n,terms:r,interLft2:i,interLft1:s,start:l,intraIns:o,interIns:a,cases:c}=t;return e.map((u,f)=>f).sort((u,f)=>n[f]-n[u]||o[u]-o[f]||r[f]+i[f]+.5*s[f]-(r[u]+i[u]+.5*s[u])||a[u]-a[f]||l[u]-l[f]||c[f]-c[u]||e[u]-e[f])}const rs=new Fe({intraMode:1,interLft:0,interRgt:0,sort:ns}),is=4,zr="aggapi.examples.filters",Et=new Set(ss()),sn=new Set;let $e="";function ss(){try{const t=JSON.parse(window.localStorage.getItem(zr)||"null");return Array.isArray(t)?t.filter(e=>typeof e=="string"):[]}catch{return[]}}function Pr(){try{window.localStorage.setItem(zr,JSON.stringify([...Et]))}catch{}}let He=!1;function Sn(){if(!He){He=!0;try{for(const t of sn)t()}finally{He=!1}}}function jr(t){return sn.add(t),()=>sn.delete(t)}function os(t,e){const n=`${t}:${e}`;Et.has(n)?Et.delete(n):Et.add(n),Pr(),Sn()}function Dr(){Et.size&&(Et.clear(),Pr(),Sn())}function on(t){const e=t.trim();e!==$e&&($e=e,Sn())}async function Wr(){if(Qt)return Qt;we||(we=he.examples().finally(()=>{we=null}));const t=await we;return Qt||(Qt=t,ls(Qt)),Qt}function ls(t){ne=t.items||[],Fr=ne.map(e=>`${e.name} ${e.kind} ${(e.tags||[]).join(" ")} ${e.note||""}`)}function as(t,e){const n=new Map;for(const r of e){const i=r.indexOf(":");if(i<1)continue;const s=r.slice(0,i);n.has(s)||n.set(s,new Set),n.get(s).add(r.slice(i+1))}return n.size?t.filter(r=>{for(const[i,s]of n)if(!(r.pills||[]).some(o=>o.ns===i&&s.has(o.value)))return!1;return!0}):t}function An(){return ne?Et.size?as(ne,Et):ne:[]}function vc(){return $e.trim()?Br($e):An()}function Br(t){const e=An(),n=t.trim();if(!n)return e;const r=new Set(e);return cs(Fr,n).map(i=>ne[i]).filter(i=>r.has(i))}function cs(t,e){const[n,r,i]=rs.search(t,e,is);return n?i&&r?i.map(s=>r.idx[s]):n:[]}function Hr(t,e,{count:n=null,on:r=!1}={}){return T("button",{type:"button",className:`pill pill-${t}${r?" is-on":""}`,title:r?`stop filtering on ${t} ${e}`:`filter on ${t} ${e}`,onClick:i=>{i.preventDefault(),i.stopPropagation(),os(t,e)}},n==null?e:`${e} ${n}`,r?T("span",{className:"pill-x"},"×"):null)}function us(t,e){const n=T("li",{className:"example-item"},T("a",{className:"dropdown-item example-row",href:"#",title:t.note||t.kind||"",onClick:i=>{i.preventDefault(),e?.(t)}},T("span",{className:"example-name"},t.name),t.note?T("span",{className:"example-note"},t.note):null)),r=t.pills||[];return r.length&&n.appendChild(T("div",{className:"example-pills"},r.map(i=>Hr(i.ns,i.value,{on:Et.has(`${i.ns}:${i.value}`)})))),n}function fs(t){if(!Et.size)return null;const e=new Map;for(const[r,i]of Object.entries(t.facets||{}))for(const s of i)e.set(`${r}:${s.value}`,s.count);const n=T("div",{className:"example-filters"});for(const r of Et){const i=r.indexOf(":");n.appendChild(Hr(r.slice(0,i),r.slice(i+1),{count:e.get(r),on:!0}))}return n.appendChild(T("span",{className:"example-shown"},`${An().length} of ${(t.items||[]).length}`)),n.appendChild(T("button",{type:"button",className:"example-clear",onClick:r=>{r.preventDefault(),Dr()}},"clear")),n}function Ur(t,e,n,r){Mt(t);const i=n.trim(),s=fs(e);s&&t.appendChild(T("li",{},s));const l=Br(i);if(!l.length){const o=i?`no example matches “${i}”`:"no example carries every filter";t.appendChild(T("li",{},T("span",{className:"dropdown-item-text text-muted small"},Et.size?`${o} with these filters. `:o,Et.size?T("a",{href:"#",onClick:a=>{a.preventDefault(),Dr()}},"Clear them"):null)));return}i&&t.appendChild(T("li",{},T("h6",{className:"dropdown-header"},`${l.length} match${l.length===1?"":"es"}`)));for(const o of l)t.appendChild(us(o,r))}async function _c(t,e){let n;try{n=await Wr()}catch(o){Mt(t),t.appendChild(T("li",{},T("span",{className:"dropdown-item-text text-danger small"},`failed to load examples: ${o.message}`)));return}Mt(t);const r=T("div",{className:"example-list"}),i=T("input",{type:"search",className:"form-control form-control-sm example-search",placeholder:`search ${(n.items||[]).length} examples…`,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:!1}),s=()=>Ur(r,n,i.value,e);i.addEventListener("input",()=>on(i.value)),i.addEventListener("keydown",o=>o.stopPropagation()),jr(s),t.appendChild(T("li",{className:"example-search-wrap"},i)),t.appendChild(T("li",{},r)),s();const l=t.previousElementSibling;l&&l.addEventListener("shown.bs.dropdown",()=>i.focus())}function Sc(t){let e=null,n=null,r=null,i=null;async function s(){if(e)return!0;let a;try{a=await Wr()}catch{return!1}r=T("div",{className:"example-list palette-list"}),n=T("input",{type:"search",className:"form-control example-search",placeholder:"search the library…",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:!1});const c=u=>{l(),t?.(u)};return i=()=>Ur(r,a,n.value,c),n.addEventListener("input",()=>on(n.value)),jr(i),e=T("div",{className:"palette-backdrop",role:"dialog","aria-modal":"true"},T("div",{className:"palette"},n,r)),e.addEventListener("mousedown",u=>{u.target===e&&l()}),document.body.appendChild(e),i(),!0}function l(){e&&e.classList.remove("open")}async function o(){await s()&&(e.classList.add("open"),n.value="",on(""),i(),n.focus())}return document.addEventListener("keydown",a=>{(a.ctrlKey||a.metaKey)&&a.key.toLowerCase()==="k"?(a.preventDefault(),o()):a.key==="Escape"&&e&&e.classList.contains("open")&&l()}),{open:o,close:l}}const Mn=[9583,1133],Hn={usagePage:1,usage:8},ln={scale:350,deadzone:.05},hs=["tx","ty","tz","rx","ry","rz"],ge=()=>({tx:0,ty:0,tz:0,rx:0,ry:0,rz:0});let Lt=null,re=ge(),Ft=0,ds={...ln},Un=!1;const an=new Set,cn=new Set;function ps(t){const e=[];for(let n=0;n+1<t.byteLength;n+=2)e.push(t.getInt16(n,!0));return e}function ms(t,e){if(!e||!e.byteLength)return null;const n=ps(e);if((t===1||t===0)&&n.length>=6)return{axes:{tx:n[0],ty:n[1],tz:n[2],rx:n[3],ry:n[4],rz:n[5]}};if(t===1&&n.length>=3)return{axes:{tx:n[0],ty:n[1],tz:n[2]}};if(t===2&&n.length>=3)return{axes:{rx:n[0],ry:n[1],rz:n[2]}};if(t===3){let r=0;const i=Math.min(4,e.byteLength);for(let s=0;s<i;s+=1)r|=e.getUint8(s)<<8*s;return{buttons:r>>>0}}return null}function gs(t,e=ds){const n=e.scale||ln.scale,r=Math.min(.9,Math.max(0,e.deadzone??ln.deadzone)),i=ge();for(const s of hs){const l=Math.max(-1,Math.min(1,(t[s]||0)/n)),o=Math.abs(l);i[s]=o<=r?0:Math.sign(l)*((o-r)/(1-r))}return i}function ze(){return typeof navigator<"u"&&!!navigator.hid}function de(){return!!(Lt&&Lt.opened)}function Gr(){return Lt?Lt.productName||"SpaceMouse":""}function ys(t){return an.add(t),()=>an.delete(t)}function xs(t){return cn.add(t),()=>cn.delete(t)}function En(){for(const t of cn)try{t({connected:de(),name:Gr()})}catch{}}function Yr(t){const e=ms(t.reportId,t.data);if(!e)return;const n=Ft;e.axes&&(re={...re,...e.axes}),e.buttons!==void 0&&(Ft=e.buttons);const r={axes:gs(re),buttons:Ft,pressed:Ft&~n,released:n&~Ft};for(const i of an)try{i(r)}catch{}}function Xr(t){const e=t.filter(r=>Mn.includes(r.vendorId));return e.filter(r=>(r.collections||[]).some(i=>i.usagePage===Hn.usagePage&&i.usage===Hn.usage))[0]||e[0]||null}function ws(){Un||!ze()||(Un=!0,navigator.hid.addEventListener("disconnect",t=>{t.device===Lt&&(Lt=null,re=ge(),Ft=0,En())}),navigator.hid.addEventListener("connect",async t=>{Lt||!Mn.includes(t.device.vendorId)||await Cn(t.device)}))}async function Cn(t){if(!t)return!1;try{t.opened||await t.open()}catch{return!1}return Lt=t,re=ge(),Ft=0,Lt.addEventListener("inputreport",Yr),ws(),En(),!0}async function qr(){if(!ze()||de())return de();try{return await Cn(Xr(await navigator.hid.getDevices()))}catch{return!1}}async function bs(){if(!ze())return!1;if(await qr())return!0;try{const t=await navigator.hid.requestDevice({filters:Mn.map(e=>({vendorId:e}))});return await Cn(Xr(t))}catch{return!1}}async function vs(){const t=Lt;if(Lt=null,re=ge(),Ft=0,En(),!!t){t.removeEventListener("inputreport",Yr);try{await t.close()}catch{}}}const _s=/^-?\d+$/;function kt(t){if(t==null)return"";if(typeof t=="string")return _s.test(t),t;if(typeof t!="number")return String(t);if(!Number.isFinite(t))return"";if(t===0)return"0";const e=Math.abs(t);return Number.isInteger(t)&&e<1e9?t.toLocaleString("en-US"):e>=.001&&e<1e6?t.toPrecision(6).replace(/\.?0+$/,""):t.toExponential(4)}const Ss={f32b64:7,f64b64:15,u16log12b64:4,json:6},As=new Uint8Array(new Uint16Array([1]).buffer)[0]===1;function Ms(t){const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r+=1)n[r]=e.charCodeAt(r);return n}function Gn(t,e){const n=Math.floor(t.byteLength/e),r=new Float64Array(n);if(As){const s=e===4?new Float32Array(t.buffer,t.byteOffset,n):new Float64Array(t.buffer,t.byteOffset,n);return r.set(s),r}const i=new DataView(t.buffer,t.byteOffset,n*e);for(let s=0;s<n;s+=1)r[s]=e===4?i.getFloat32(s*e,!0):i.getFloat64(s*e,!0);return r}function Es(t,e,n){const r=t.byteLength>>1,i=new Float64Array(r),s=new DataView(t.buffer,t.byteOffset,r*2);for(let l=0;l<r;l+=1){const o=s.getUint16(l*2,!0);i[l]=o===0?0:e*10**((o-1)/65534*n-n)}return i}function Vr(t){if(!Array.isArray(t))throw new Error("surface z is not an array");if(!Array.isArray(t[0]))return Float64Array.from(t);const e=t.length,n=t[0].length,r=new Float64Array(n*e);for(let i=0;i<e;i+=1){const s=t[i];for(let l=0;l<n;l+=1)r[i*n+l]=s[l]}return r}function Cs(t){const e=t.z_block;if(e&&typeof e=="object"&&!Array.isArray(e))return e;const n=t.z;return n&&typeof n=="object"&&!Array.isArray(n)&&n.dtype?n:null}function ks(t){const e=t.dtype||"f32b64";if(e==="json")return Vr(t.data);if(typeof t.data!="string")throw new Error(`surface dtype ${e} wants base64 data`);const n=Ms(t.data);if(e==="f32b64")return Gn(n,4);if(e==="f64b64")return Gn(n,8);if(e==="u16log12b64"){const{peak:r,decades:i}=t;if(!(r>0)||!(i>0))throw new Error("u16log12b64 needs peak and decades");return Es(n,r,i)}throw new Error(`unknown surface dtype ${e}`)}function Yn(t,e){const n=t[`${e}0`],r=t[`d${e}`],i=t[`n${e}`];if(Number.isFinite(n)&&Number.isFinite(r)&&i>0)return{origin:n,step:r,count:Math.round(i)};const s=t[e];if(!Array.isArray(s)||!s.length)throw new Error(`surface has no ${e} lattice and no ${e} array`);return{origin:Number(s[0]),step:s.length>1?Number(s[1])-Number(s[0]):1,count:s.length}}function Kr(t){if(!t||typeof t!="object")throw new Error("surface block missing");const e=Yn(t,"x"),n=Yn(t,"y"),r=e.count,i=n.count,s=Cs(t),l=s?s.dtype||"f32b64":"json";let o=s?ks(s):Vr(t.z);if(o.length!==r*i)throw new Error(`surface z has ${o.length} values for a ${r} by ${i} grid`);if(s&&s.order==="xy"){const f=new Float64Array(r*i);for(let h=0;h<r;h+=1)for(let d=0;d<i;d+=1)f[d*r+h]=o[h*i+d];o=f}const a=e.step*n.step;if(!(a>0))throw new Error(`surface cell area ${a} is not positive`);let c=0;const u=new Float64Array(r*i);for(let f=0;f<o.length;f+=1)c+=o[f],u[f]=o[f]/a;return{x0:e.origin,dx:e.step,nx:r,y0:n.origin,dy:n.step,ny:i,edge:t.edge==="left"?"left":"mid",z:u,cellArea:a,totalMass:c,dtype:l,digits:Ss[l]||6,quantized:l==="u16log12b64",bs:t.bs||null,k:t.k||null,quantileWindow:t.window||null,marginals:t.marginals||null,moments:t.moments||null,deficit:Number.isFinite(t.deficit)?t.deficit:null}}function Zr(t,e){return(t&&t.series||[]).find(r=>r&&r.surface&&(e===void 0||r.panel_id===e))||null}function ht(t,e){return t.x0+e*t.dx}function dt(t,e){return t.y0+e*t.dy}function Jr(t){return Array.from({length:t.nx},(e,n)=>ht(t,n))}function Qr(t){return Array.from({length:t.ny},(e,n)=>dt(t,n))}function Bt(t,e,n){return t.z[n*t.nx+e]}function Ls(t,e=0){let n=0,r=1/0;for(let i=0;i<t.z.length;i+=1){const s=t.z[i];s>n&&(n=s),s>e&&s<r&&(r=s)}return{max:n,min:Number.isFinite(r)?r:e}}function $s(t){return(e,n)=>{const r=(e-t.x0)/t.dx,i=(n-t.y0)/t.dy,s=Math.max(0,Math.min(t.nx-2,Math.floor(r))),l=Math.max(0,Math.min(t.ny-2,Math.floor(i))),o=Math.min(1,Math.max(0,r-s)),a=Math.min(1,Math.max(0,i-l));return Bt(t,s,l)*(1-o)*(1-a)+Bt(t,s+1,l)*o*(1-a)+Bt(t,s,l+1)*(1-o)*a+Bt(t,s+1,l+1)*o*a}}function Ts(t,e,{anti:n=!0,count:r=64}={}){const i=ht(t,0),s=ht(t,t.nx-1),l=dt(t,0),o=dt(t,t.ny-1),a=S=>n?e-S:S-e,c=n?e-o:l+e,u=n?e-l:o+e,f=Math.max(i,Math.min(c,u)),h=Math.min(s,Math.max(c,u));if(!(h>f)||r<2)return[];const d=$s(t),w=[];for(let S=0;S<r;S+=1){const N=f+(h-f)*S/(r-1),W=a(N);w.push([N,W,d(N,W)])}return w}function Rs(t,e){const n=Math.max(0,Math.min(t.ny-1,Math.round((e-t.y0)/t.dy))),r=new Float64Array(t.nx);for(let i=0;i<t.nx;i+=1)r[i]=Bt(t,i,n);return{index:n,at:dt(t,n),values:r}}function Ns(t,e){const n=Math.max(0,Math.min(t.nx-1,Math.round((e-t.x0)/t.dx))),r=new Float64Array(t.ny);for(let i=0;i<t.ny;i+=1)r[i]=Bt(t,n,i);return{index:n,at:ht(t,n),values:r}}function Is(t,e,n=8){const r=Math.max(t,e),i=Math.min(t,e);return r>0?!(i>0)||r/i<=n?{scale:1/r,clipped:!1}:{scale:1/(n*i),clipped:!0}:{scale:1,clipped:!1}}function ti(t,e,n){const r=[],i=(s,l,o,a)=>{const c=(e-s)/(l-s);return[o[0]+c*(a[0]-o[0]),o[1]+c*(a[1]-o[1])]};for(let s=0;s<t.ny-1;s+=1)for(let l=0;l<t.nx-1;l+=1){const o=[n(l,s),n(l+1,s),n(l+1,s+1),n(l,s+1)],a=[[ht(t,l),dt(t,s)],[ht(t,l+1),dt(t,s)],[ht(t,l+1),dt(t,s+1)],[ht(t,l),dt(t,s+1)]];let c=0;for(let h=0;h<4;h+=1)o[h]>e&&(c|=1<<h);if(c===0||c===15)continue;const u=[];for(let h=0;h<4;h+=1){const d=h,w=(h+1)%4;u[h]=o[d]>e!=o[w]>e?i(o[d],o[w],a[d],a[w]):null}const f=(h,d)=>{u[h]&&u[d]&&r.push([u[h],u[d]])};switch(c){case 1:case 14:f(3,0);break;case 2:case 13:f(0,1);break;case 4:case 11:f(1,2);break;case 8:case 7:f(2,3);break;case 3:case 12:f(3,1);break;case 6:case 9:f(0,2);break;case 5:case 10:{const h=(o[0]+o[1]+o[2]+o[3])/4>e;(c&1)!==0===h?(f(0,1),f(2,3)):(f(3,0),f(1,2));break}}}return Os(r,Math.min(Math.abs(t.dx),Math.abs(t.dy))*1e-4||1e-9)}function Os(t,e){const n=o=>`${Math.round(o[0]/e)}:${Math.round(o[1]/e)}`,r=new Map;t.forEach((o,a)=>{for(const c of o){const u=n(c);r.has(u)||r.set(u,[]),r.get(u).push(a)}});const i=new Array(t.length).fill(!1),s=[],l=(o,a)=>{for(let c=0;c<t.length;c+=1){const u=a?o[o.length-1]:o[0],f=n(u),h=(r.get(f)||[]).find(w=>!i[w]);if(h==null)return;i[h]=!0;const d=n(t[h][0])===f?t[h][1]:t[h][0];a?o.push(d):o.unshift(d)}};for(let o=0;o<t.length;o+=1){if(i[o])continue;i[o]=!0;const a=[t[o][0],t[o][1]];l(a,!0),l(a,!1),a.length>=3&&s.push(a)}return s}function Ue(t,e,n){const r=t.length;if(!r)return NaN;const i=t[r-1]>=t[0],s=i?t[0]:t[r-1],l=i?t[r-1]:t[0];if(!(n>=s&&n<=l))return NaN;for(let o=0;o<r-1;o+=1){const a=t[o],c=t[o+1];if(n>=a&&n<=c||n<=a&&n>=c){const u=c===a?0:(n-a)/(c-a);return e[o]+u*(e[o+1]-e[o])}}return e[r-1]}function Ge(t,e){let n=0,r=0;for(let i=0;i<e.length;i+=1)n+=t[i]*e[i],r+=e[i];return r>0?n/r:NaN}function Fs(t,e){return t.map(n=>{if(n==null)return null;const r=e==="complement"?1/(1-n):1/n;return Number.isFinite(r)&&r>0?r:null})}function Xn(t,e){return!t&&e==null?null:n=>{const r=t?n.map(i=>i==null?null:1-i):n;return e==null?r:Fs(r,e)}}const un=["#440154","#414487","#2a788e","#22a884","#7ad151","#fde725"],ei=.35,ni=6,zs=33;function Ps(t,e){const n=Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*(t.length-1),r=Math.min(t.length-2,Math.floor(n)),i=n-r,s=c=>{const u=parseInt(String(c).replace("#",""),16);return[u>>16&255,u>>8&255,u&255]},l=s(t[r]),o=s(t[r+1]),a=c=>Math.round(c).toString(16).padStart(2,"0");return`#${[0,1,2].map(c=>a(l[c]+(o[c]-l[c])*i)).join("")}`}function js(t,e,n){return e==="log"?t<=0?0:Math.max(0,1+Math.log10(t)/n):typeof e=="number"?t**e:t}function Ds(t,e,n){return e==="log"?10**(n*(t-1)):typeof e=="number"?t**(1/e):t}function Te(t,{stops:e=zs,decades:n=ni}={}){if(t==null||t===1)return un.slice();const r=new Array(e);for(let i=0;i<e;i++)r[i]=Ps(un,js(i/(e-1),t,n));return r}function ri(t,e,n,r=null,{decades:i=ni}={}){const s=e-t;if(!(s>0))return[];const l=new Array(n);for(let o=1;o<=n;o++)l[o-1]=t+s*Ds(o/(n+1),r,i);return l}function qn(t){if(t==="linear")return null;if(t==="gamma")return ei;if(t==="log")return"log";if(typeof t=="number"&&t>0&&t<1)return t;if(t===1)return null}function Ws({held:t=null,hint:e=null,relief:n=!1,logZ:r=!1}={}){const i=qn(t);if(i!==void 0&&t!==null&&t!==void 0)return i;if(r)return null;const s=qn(e);return s!==void 0&&e!==null&&e!==void 0?s:n?ei:null}function Bs(t){return t==="log"?"log":typeof t=="number"&&t>0&&t<1?"gamma":"linear"}Lr([Ni,Ii,Oi,Fi,zi,Pi,ji,Di,Wi,Bi,Hi,Ui]);const fn={colors:["#0d6efd","#dc3545","#198754","#eaab00","#6f42c1","#0aa2c0","#d63384","#6c757d"],grid_color:"#dee2e6",text_color:"#212529",line_width:1.4,font_size:8.5,fig_w:3.5,fig_h:2.45},Gt=1e-15;let Yt=fn,Ye=null;function Hs(){return Ye||(Ye=he.style().then(t=>(Yt={...fn,...t},Yt)).catch(()=>fn)),Ye}function pe(){return Yt}function kn(t){const e=Yt.colors;return e[(t%e.length+e.length)%e.length]}function ii(t,e){const n=String(t).replace("#","");if(n.length!==6)return t;const r=parseInt(n,16);return`rgba(${r>>16&255},${r>>8&255},${r&255},${e})`}function Vn(){const t=Yt;return{color:t.colors,textStyle:{fontSize:Math.max(10,t.font_size+2),color:t.text_color},animation:!1,tooltip:{trigger:"axis",confine:!0,axisPointer:{type:"line",lineStyle:{color:t.grid_color,width:1}},backgroundColor:"rgba(255,255,255,.96)",borderColor:t.grid_color,textStyle:{fontSize:11,color:t.text_color}},legend:{type:"scroll",bottom:0,itemWidth:18,itemHeight:2,textStyle:{fontSize:11,color:t.text_color}}}}function Xt(t={}){const e=Yt;return{nameLocation:"middle",nameGap:26,nameTextStyle:{fontSize:11,color:"#6c757d"},axisLine:{lineStyle:{color:e.grid_color}},axisTick:{show:!1},axisLabel:{fontSize:10,color:"#6c757d",hideOverlap:!0},splitLine:{lineStyle:{color:e.grid_color,type:"dashed"}},...t}}function Us(){return Yt.line_width}const Gs=4,Ys=40,Xs="minmax",qs=1e9,Kn=.3,Ht=64,be=46,si=18,ve=26,Zn=96,Vs=30,Ks=130,Zs=380,Jn=4/3.25,ae=720,oi={logX:!1,logY:!1,fullRange:!1,reflect:!1,returnPeriod:!1,invert:!1,refLines:!0,stretch:null},Js=240,Qs=336,to=78,eo=1,no=2,ro=110,io=360,so=.62,oo=180,lo=620,Ce=86,ao=260,co=420,uo=1.75/4.41,Re=10,fo=.55,li=1.3,ho={layer:{color:0,alpha:[.8,.55]},co_participation:{color:7,alpha:[.16],dashed:!0},retention:{color:7,alpha:[.3]},gap:{color:null,alpha:[0],dashed:!0},gross:{color:1,alpha:[.4]}};function hn(t,e){const n={...t};for(const[r,i]of Object.entries(e||{})){const s=n[r];if(Array.isArray(s)&&Array.isArray(i)){const l=s.map((o,a)=>o&&i[a]&&typeof o=="object"&&typeof i[a]=="object"?{...o,...i[a]}:i[a]===void 0?o:i[a]);for(let o=s.length;o<i.length;o++)l.push(i[o]);n[r]=l}else s&&i&&typeof s=="object"&&typeof i=="object"&&!Array.isArray(s)&&!Array.isArray(i)?n[r]={...s,...i}:n[r]=i}return n}function Qn(t,e){const n=t[e];if(Array.isArray(n))return n;const r=t[`${e}_lattice`];if(!r)return null;const[i,s,l]=r,o=new Array(l);for(let a=0;a<l;a++)o[a]=i+a*s;return o}function me(t){let e=1/0;for(const n of t)for(const r of n)r!=null&&Number.isFinite(r)&&r>Gt&&r<e&&(e=r);return Number.isFinite(e)?10**(Math.ceil(Math.log10(e))-1):null}function po(t,e){const n=t&&t.panels||[],r=new Set(n.filter((l,o)=>e[o]==="tower").map(l=>l.y_axis).filter(Boolean));if(!r.size)return{};const i=Object.fromEntries(n.map(l=>[l.id,l])),s={};for(const l of t&&t.blocks||[]){const o=i[l.panel_id];!o||!r.has(o.y_axis)||(s[o.y_axis]||(s[o.y_axis]=[])).push(l.y0,l.y1)}return Object.fromEntries(Object.entries(s).map(([l,o])=>[l,me([o])]))}function Ne(t){let e=1/0,n=-1/0;for(const r of t)for(const i of r)i==null||!Number.isFinite(i)||(i<e&&(e=i),i>n&&(n=i));return Number.isFinite(e)&&Number.isFinite(n)?[e,n]:null}function qt(t,e){const n=t.scales||[t.scale||"linear"];return e?n.includes("log")?"log":t.scale||"linear":n.includes("linear")?"linear":t.scale||"linear"}function dn(t,e){const n=Object.fromEntries((t&&t.axes||[]).map(i=>[i.id,i])),r=i=>!!i&&(n[i]||{}).scale==="log";return e&&e.z_axis?{logX:!1,logY:r(e.z_axis)}:{logX:r(e&&e.x_axis),logY:r(e&&e.y_axis)}}function pn(t,{full:e,uncapped:n},r=null){if(e&&Array.isArray(t.full_range))return t.full_range;if(n&&t.unit==="density"){if(Array.isArray(t.full_range))return t.full_range;const i=r?Ne(r):null;if(i)return i}return Array.isArray(t.suggested_range)?t.suggested_range:null}function _e(t,e,n="reciprocal_of"){return(t.axes||[]).find(r=>r[n]===e)||null}function mo(t,e,n,r){const i=[t,e].filter(Boolean);if(!i.length)return null;const s=Ne([...n,...r]);let l=Math.min(...i.map(a=>a[0]));s&&(l=Math.max(l,s[0]));const o=Math.max(...i.map(a=>a[1]));return o>l?[l,o]:i[0]}const tr=t=>!!t&&(t.scales||[]).length>1,go=t=>!!t&&Array.isArray(t.full_range)&&(!Array.isArray(t.suggested_range)||t.full_range[0]<t.suggested_range[0]||t.full_range[1]>t.suggested_range[1]);function er(t,e,n){const r=t&&t.axes||[],i=Object.fromEntries(r.map(c=>[c.id,c])),s=n==="x"?e.x_axis:e.y_axis,l=n==="x"?e.y_axis:e.x_axis,o=e.invertible?[s,l]:[s],a=[];for(const c of o)if(c){a.push(i[c]);for(const u of r)(u.complement_of===c||u.reciprocal_of===c)&&a.push(u)}return a.filter(Boolean)}function Ln(t){const e=t&&t.axes||[],n=t&&t.panels||[],r=new Set((t&&t.marks||[]).map(o=>o.panel_id)),i=new Set;for(const o of n){const a=o.kinds||[o.kind];if(a.length>1)for(const c of a)i.add(c);o.kind==="surface"&&(i.add("surface"),i.add("heatmap"))}const s=ai(n),l=Object.fromEntries(e.map(o=>[o.id,o]));return{panels:n.map(o=>{if(!s.has(o.y_axis))return nr(t,e,r,o);if(s.get(o.y_axis)!==o.id)return vo(o);const a=l[o.y_axis];return{...nr(t,e,r,o),title:a&&a.label||o.title||""}}),kinds:i.size>1?[...i]:[]}}function yo(t,e,n={}){const r=Object.fromEntries((t&&t.axes||[]).map(o=>[o.id,o])),i=o=>!!o&&qt(o,!0)==="log";if(e&&e.z_axis){const o=r[e.z_axis];return{logX:!1,logY:i(o),xLabel:"",yLabel:o&&o.label||""}}const{xAxis:s,yAxis:l}=di(t,e,r,n);return{logX:i(s),logY:i(l),xLabel:s&&s.label||"",yLabel:l&&l.label||""}}function ai(t){const e=new Map;for(const n of t)n.kind==="tower"&&n.y_axis&&e.set(n.y_axis,n.id);return e}const xo=9,wo=4;function bo(t,e,n){const r=Math.max(1,Math.round(n/xo)),i=[];for(let s=r-1;s>=0;s--)i.push([t+n*(s+.5)/r,e+wo],[t+n*s/r,e]);return i}function vo(t){return{id:t.id,title:t.title||"",logX:!1,logY:!1,fullRange:!1,reflect:!1,returnPeriod:!1,invert:!1,marks:!1}}function nr(t,e,n,r){const i=er(t,r,"x"),s=er(t,r,"y"),l=r.z_axis?[e.find(a=>a.id===r.z_axis)]:[],o=a=>[r.x_axis,r.y_axis].some(c=>c&&e.some(u=>u[a]===c));return{id:r.id,title:r.title||"",logX:i.some(tr),logY:[...s,...l].some(tr),fullRange:[...i,...s].some(go),reflect:o("complement_of"),returnPeriod:o("reciprocal_of"),invert:!!r.invertible,marks:n.has(r.id)}}function _o(t,e){const n=t.kinds||[t.kind];return e&&n.includes(e)?e:e==="heatmap"&&t.kind==="surface"?"heatmap":t.kind}function ci(t,e,n,r=0,i=null){const s=Math.max(1,t||1),l=n||900,o=l>=ae,a=o&&i&&i.ratios&&i.ratios.length===s?i:null,c=a?s:o?Math.min(2,s):1,u=si+r,f=p=>l-Ht-(p-1)*Zn-u,h=ve+be,d=Math.max(o?160:200,f(c)/c);if(i&&i.matrix&&i.matrix.columns>0){const p=(f(c)/c+Ce-Ht)/i.matrix.columns,g=i.matrix.rows*p*so,y=Math.max(oo,Math.min(lo,g)),M=[{left:Ce,top:ve,width:Math.max(160,l-Ce-u),height:y}];return{grids:M,wide:o,panelW:M[0].width,panelH:y,footprint:h+y,hostHeight:Math.round(ve+y+be)}}const w=a&&a.tall?Math.max(ao,Math.min(co,l/Jn-h)):e?Math.max(Js,Math.min(Qs,d)):Math.max(Ks,Math.min(Zs,d/Jn-h));let S=e&&!a?w:d;i&&i.maxWidth&&(S=Math.min(S,i.maxWidth));const N=a?a.ratios.reduce((p,g)=>p+g,0):0,W=a?Math.min(w*uo,f(s)/N):0,z=p=>a?W*a.ratios[p]:S,F=[];let L=Ht;for(let p=0;p<s;p++){const g=Math.floor(p/c);p%c===0&&(L=Ht);const y=z(p);F.push({left:L,top:ve+g*(w+be+Vs),width:y,height:w}),L+=y+Zn}const B=Math.max(...F.map(p=>p.top+p.height));return{grids:F,wide:o,panelW:S,panelH:w,footprint:h+w,hostHeight:Math.round(B+be)}}function So(t){const e=t&&t.grids||[];if(!e.length)return{left:Ht,width:0};const n=e[0].left,r=Math.max(...e.map(i=>i.left+i.width));return{left:n,width:Math.max(0,r-n)}}function Ao(t){return{left:Ht,width:Math.max(0,(t||900)-Ht-si)}}function ui(t,e){const n=t&&t.panels||[],r=n.length>0&&n.every(a=>a.aspect==="equal"),i=n.some(a=>a.kind==="heatmap"||a.kind==="surface");let s=n.some(a=>a.kind==="tower")?{ratios:n.map(a=>a.kind==="tower"?eo:no),tall:!0}:null;const l=n.length===1&&n[0].kind==="xy"&&(t&&t.axes||[]).find(a=>a.id===n[0].x_axis&&a.kind==="category"&&a.categories&&a.categories.length);l&&!s&&(s={maxWidth:Math.max(io,l.categories.length*ro)});const o=n.find(a=>a.kind==="matrix");if(o&&!s){const a=(t&&t.series||[]).find(c=>c.panel_id===o.id&&c.matrix);a&&a.matrix.rows&&a.matrix.columns&&(s={matrix:{rows:a.matrix.rows.length,columns:a.matrix.columns.length}})}return ci(n.length,r,e,i?to:0,s)}function fi(t,e){if(!e)return t.length;let n=0;for(const r of t)r!=null&&r>=e[0]&&r<=e[1]&&n++;return n}function mn(t,e,n,r){return e&&e.kind==="category"||t==="continuous"?"line":n.unit==="probability"?"step-post":e.unit==="probability"||e.unit==="return_period"?"step-pre":n.unit==="density"&&r<=Ys?"stem":"step-mid"}const rr={"step-pre":"start","step-mid":"middle","step-post":"end"};function Mo(t){for(const e of t)if(e==null)return!1;return!0}const Eo=.06,Co="#e34948",ko="#008300",ir=["circle","rect","triangle","diamond","pin","arrow"],Lo=.45;function $o(t,e){const n=String(t).replace("#","");if(n.length!==6||!e)return t;const r=parseInt(n,16),i=e>0?255:0,s=l=>Math.round(l+(i-l)*Math.abs(e));return`rgb(${s(r>>16&255)},${s(r>>8&255)},${s(r&255)})`}function To(t){const e=[];for(const r of t)r.group&&!e.includes(r.group)&&e.push(r.group);const n={};if(!e.length)return n;for(const r of t){if(!r.group)continue;const i=t.filter(a=>a.group===r.group),s=i.indexOf(r),l=kn(e.indexOf(r.group)),o=i.length>1?(s/(i.length-1)-.5)*2*Lo:0;n[r.name]={color:$o(l,o),symbol:ir[s%ir.length]}}return n}function Ro(t){const e=String(pe().colors[0]).replace("#","");if(e.length!==6)return pe().colors[0];const n=parseInt(e,16),r=i=>Math.round(255+(i-255)*Math.max(0,Math.min(1,t)));return`rgb(${r(n>>16&255)},${r(n>>8&255)},${r(n&255)})`}function sr(t,e=7){const n=t.length;if(n<=e)return{};const r=Number(t[0]),i=Number(t[n-1]),s=$n((i-r)/e);if(!s||!Number.isFinite(r)||!Number.isFinite(i))return{};const l=new Map;for(let o=Math.ceil(r/s)*s;o<=i+s/2;o+=s){const a=Math.round((o-r)/(i-r)*(n-1));a>=0&&a<n&&l.set(a,o)}return{interval:o=>l.has(o),formatter:(o,a)=>kt(l.get(a))}}function $n(t){if(!(t>0)||!Number.isFinite(t))return null;const e=10**Math.floor(Math.log10(t)),n=t/e;return n<=1?e:n<=2?2*e:n<=5?5*e:10*e}function No(t,e,n=5){if(!Number.isFinite(t)||!Number.isFinite(e)||!(e>t))return null;const r=$n((e-t)/n);return r?{min:Math.floor(t/r)*r,max:Math.ceil(e/r)*r,interval:r}:null}function gn(t,e,{scale:n,window:r,floor:i,formatter:s,nameGap:l}){if(t.kind==="category"&&t.categories&&t.categories.length)return Xt({type:"category",gridIndex:e,data:[...t.categories],name:t.label||"",boundaryGap:!0,...l==null?{}:{nameGap:l}});const o=n==="log";let[a,c]=r||[];o&&a!=null&&a<=0&&(a=i??void 0);const u=Array.isArray(t.full_range)?t.full_range:null;u&&a!=null&&c!=null&&(o||(a=Math.max(a,u[0])),c=Math.min(c,u[1]));let f=null;return a!=null&&c!=null&&(o?a>0&&c>a&&(a=10**Math.floor(Math.log10(a)),c=10**Math.ceil(Math.log10(c))):(f=No(a,c),f&&({min:a,max:c}=f))),Xt({type:o?"log":"value",...o?{logBase:10}:{},name:t.label||"",gridIndex:e,...l==null?{}:{nameGap:l},...a==null?{}:{min:a},...c==null?{}:{max:c},...f?{interval:f.interval}:{},axisLabel:{fontSize:10,color:"#6c757d",hideOverlap:!0,formatter:s}})}function Ie(t){return Number(t).toExponential(1)}function yn(t,e){return t.unit==="probability"?n=>n>=.01||n===0?String(n):Ie(n):t.unit==="return_period"?n=>hi(n):t.unit==="density"||e==="log"?n=>n?Ie(n):"0":n=>kt(n)}const Io=[[1e9,"B"],[1e6,"M"],[1e3,"k"]];function hi(t){if(!Number.isFinite(t))return"";for(const[e,n]of Io)if(t>=e){const r=t/e;return`${r>=10?Math.round(r):Number(r.toFixed(1))}${n}`}return t>=10?String(Math.round(t)):Number(t).toFixed(1)}function di(t,e,n,r){let i=n[e.x_axis],s=n[e.y_axis],l=!1,o=!1,a=null,c=null;if(r.reflect){const d=_e(t,e.x_axis,"complement_of");d&&(i=d,l=!0);const w=_e(t,e.y_axis,"complement_of");w&&(s=w,o=!0)}if(r.returnPeriod){const d=(t.meta||{}).return_period_map||"reciprocal",w=_e(t,e.x_axis);w&&(i=w,a=d);const S=_e(t,e.y_axis);S&&(s=S,c=d)}let u=Xn(l,a),f=Xn(o,c);const h=!!r.invert&&!!e.invertible;return h&&([i,s]=[s,i],[u,f]=[f,u],[a,c]=[c,a]),{xAxis:i,yAxis:s,xMap:u,yMap:f,xPeriod:a,yPeriod:c,inverted:h}}function Oo(t,e,n,r,i,s,l){const{xAxis:o,yAxis:a,xMap:c,yMap:u,xPeriod:f,yPeriod:h,inverted:d}=di(t,e,r,i),w=(t.series||[]).filter(x=>x.panel_id===e.id),S=(x,Y)=>Y?Y(x):x,N=[];for(const x of w){const Y=Qn(x,"x"),O=Qn(x,"y");if(!Y||!O)continue;const D=S(Y,d?u:c),tt=S(O,d?c:u),k=x.y2?S(x.y2,d?c:u):null;N.push(d?{s:x,x:tt,y:D,y2:k}:{s:x,x:D,y:tt,y2:k})}const W=N.map(x=>x.x),z=N.map(x=>x.y),F=qt(o,i.logX),L=qt(a,i.logY),B=(x,Y)=>!!Y&&(x.scales||[]).length>1,p={full:i.fullRange,uncapped:B(o,i.logX)},g={full:i.fullRange,uncapped:B(a,i.logY)},y=(x,Y)=>Y&&x?[x[0],Math.min(x[1],qs)]:x,M=pn(o,p,W),G=pn(a,g,z);let P=y(M||Ne(W)||[0,1],f),H=f?null:y(G||(h?Ne(z):null),h),X=h?null:P;e.aspect==="equal"&&F===L&&(X=mo(X,H,W,z),H=X);const I=(N.find(({s:x})=>x.support!=="continuous")||N[0]||{}).x||[],A=fi(I,P),b=w.filter(x=>x.value!=null).map(x=>x.value),C=b.length?Math.min(...b):0,j=b.length?Math.max(...b):1,K=x=>j>C?(x-C)/(j-C):.5,it=l&&l.floors||{},nt=it[o.id]??me(W),ot=it[a.id]??me(z),ft=[],pt=[],R=To(N.map(x=>x.s)),U=Object.keys(R).length>0&&o.kind==="category";for(const{s:x,x:Y,y:O,y2:D}of N){const tt=R[x.name],k=tt?tt.color:x.value!=null?Ro(Kn+(1-Kn)*K(x.value)):x.role==="sample"?"#6c757d":kn(l.colorOf(x.name)),Q=(ct,lt)=>lt==="log"?ct.map(at=>at!=null&&at>Gt?at:null):ct,V=Q(Y,F),q=Q(O,L),et=V.map((ct,lt)=>ct==null||q[lt]==null?null:[ct,q[lt]]);if(x.role==="identity"){ft.push({type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,data:et,showSymbol:!1,silent:!0,z:1,lineStyle:{width:1,type:"dashed",color:"#6c757d"},itemStyle:{color:"#6c757d"},tooltip:{show:!1}});continue}if(x.role==="marker"){ft.push({type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,data:et,showSymbol:!0,symbolSize:9,lineStyle:{width:0},itemStyle:{color:k},z:4}),pt.push(x.name);continue}if(x.role==="rug"){ft.push({type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,data:et,showSymbol:!0,symbol:"rect",symbolSize:[1.5,9],lineStyle:{width:0},itemStyle:{color:k,opacity:.7},z:3,silent:!0,tooltip:{show:!1}});continue}if(D){const ct=Q(D,L),lt=[];let at=[],Ct=[];const mt=()=>{at.length>1&&lt.push(at.concat(Ct.reverse())),at=[],Ct=[]};V.forEach((bt,st)=>{if(bt==null||q[st]==null||ct[st]==null){mt();return}at.push([bt,q[st]]),Ct.push([bt,ct[st]])}),mt();const $t={type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,symbol:"none",lineStyle:{width:.8,color:k},itemStyle:{color:k},z:2};ft.push({...$t,data:et},{...$t,data:V.map((bt,st)=>bt==null||ct[st]==null?null:[bt,ct[st]]),tooltip:{show:!1},silent:!0}),lt.length&&ft.push({type:"custom",name:x.name,xAxisIndex:n,yAxisIndex:n,data:[lt[0][0]],silent:!0,clip:!0,z:1,tooltip:{show:!1},itemStyle:{color:k},renderItem:(bt,st)=>({type:"group",children:lt.map(Tt=>({type:"polygon",shape:{points:Tt.map(ye=>st.coord(ye))},style:{fill:ii(k,.18),stroke:null},silent:!0}))})}),pt.push(x.name);continue}const rt=mn(x.support,o,a,A);if(rt==="stem"){const ct=L==="log"?H&&H[0]>0?H[0]:ot??Gt:0,lt=[];for(const at of et)at&&lt.push([at[0],ct],[at[0],at[1]],null);ft.push({type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,data:lt,showSymbol:!1,connectNulls:!1,silent:!0,lineStyle:{width:1,color:k,opacity:.55},itemStyle:{color:k},z:2},{type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,data:et,showSymbol:!0,symbolSize:5,connectNulls:!1,lineStyle:{width:0},itemStyle:{color:k},emphasis:{focus:"series"},z:3}),pt.push(x.name);continue}ft.push({type:"line",name:x.name,xAxisIndex:n,yAxisIndex:n,...rr[rt]?{step:rr[rt]}:{},data:et,sampling:Mo(et)?Xs:void 0,...tt?{showSymbol:!0,symbol:tt.symbol,symbolSize:7}:{showSymbol:!1},connectNulls:!1,lineStyle:{width:x.value!=null||x.role==="sample"?.75:Us(),opacity:x.value!=null||x.role==="sample"?.55:1,color:k},itemStyle:{color:k},...U?{endLabel:{show:!0,color:k,fontSize:11,distance:6,formatter:x.name},labelLayout:{moveOverlap:"shiftY"},labelLine:{show:!0,lineStyle:{color:k}}}:{},emphasis:{focus:"series"}}),x.value==null&&x.role!=="sample"&&!U&&pt.push(x.name)}const m=[];for(const x of i.refLines===!1?[]:t.marks||[]){if(x.panel_id!==e.id)continue;const Y=d?x.orient==="v"?"h":"v":x.orient,O=Y==="v"?c:u;let D=x.at;O&&([D]=O([D]),D==null)||m.push({m:x,orient:Y,at:D})}const E=m.reduce((x,Y,O)=>Y.orient==="v"&&(x<0||Y.at>m[x].at)?O:x,-1),_=m.map((x,Y)=>jo(x.m,x.orient,x.at,Y===E));_.length&&ft.length&&(ft[0].markLine=Do(_));const v=m.find(x=>x.m.role==="base"&&x.orient==="h");v&&ft.length&&(ft[0].markArea={silent:!0,z:0,itemStyle:{opacity:Eo},data:[[{yAxis:v.at,itemStyle:{color:Co}},{yAxis:"max"}],[{yAxis:"min",itemStyle:{color:ko}},{yAxis:v.at}]]});const $=yn(o,F),Z=yn(a,L);return{series:ft,legend:pt,xAxis:gn(o,n,{scale:F,window:X,floor:nt,formatter:$}),yAxis:gn(a,n,{scale:L,window:H,floor:ot,formatter:Z,nameGap:46}),readAxis:d?e.read_axis==="y"?"x":"y":e.read_axis||"x",title:Tn(t,e,d),xWindow:X,atomGrid:I,rung:N.length?{support:N[0].s.support,xAxis:o,yAxis:a,drawnAs:mn(N[0].s.support,o,a,A)}:null,zoom:Wo(s,X),xUnit:o.unit,yUnit:a.unit,xName:o.label,yName:a.label}}function Tn(t,e,n){const r=e.title==="",i=e.title==null?t.title||"":e.title;return n?e.inverse_title?e.inverse_title:r?"":i?`${i}, inverted`:"Inverted":i}function Fo(t){return Math.floor(t/(li*Re))}function zo(t,e,n){const r=Fo(n);if(r<1)return[];const i=Math.floor(e/(fo*Re)),s=t.label||"";return s&&s.length>i?[]:(s?[s]:[]).concat((t.label_lines||[]).filter(o=>o.length<=i)).slice(0,r)}function Po(t,e,n,r,i,s){const l=(t.blocks||[]).filter(y=>y.panel_id===e.id);if(!l.length)return null;const o=r[e.x_axis]||{},a=r[e.y_axis]||{},c=qt(a,i.logY),u=c==="log",f=[Math.min(...l.map(y=>y.y0)),Math.max(...l.map(y=>y.y1))],h=pn(a,{full:i.fullRange,uncapped:!1})||f,d=Array.isArray(o.suggested_range)?o.suggested_range:[0,1],w=(s&&s.floors||{})[e.y_axis]??me([l.map(y=>y.y0),l.map(y=>y.y1)]),S=y=>u?Math.max(y,w??Gt):y,N={},W=l.map(y=>{const M=ho[y.role]||{color:7,alpha:[.3]},G=N[y.role]||0;return N[y.role]=G+1,{fill:M.color==null?"none":ii(kn(M.color),M.alpha[G%M.alpha.length]),dashed:!!M.dashed}}),z=pe().grid_color||"#dee2e6",F=[{type:"custom",name:e.title||e.id,xAxisIndex:n,yAxisIndex:n,data:l.map(y=>[y.x0,y.y0,y.x1,y.y1]),tooltip:{trigger:"item",formatter:y=>{const M=l[y.dataIndex]||{};return[M.label?`<b>${M.label}</b>`:M.role,...M.label_lines||[]].join("<br>")}},renderItem:(y,M)=>{const G=y.dataIndex||0,P=l[G];if(!P||u&&w!=null&&P.y1<=w)return null;const H=M.coord([P.x0,S(P.y0)]),X=M.coord([P.x1,S(P.y1)]),I=Math.min(H[0],X[0]),A=Math.min(H[1],X[1]),b=Math.abs(X[0]-H[0]),C=Math.abs(X[1]-H[1]),{fill:j,dashed:K}=W[G],it=[[I,A],[I,A+C],[I+b,A+C],[I+b,A]];P.open_top?it.push(...bo(I,A,b)):it.push([I,A]);const nt=[{type:"rect",shape:{x:I,y:A,width:b,height:C},style:{fill:j,lineWidth:0},silent:!0},{type:"polyline",shape:{points:it},style:{stroke:z,lineWidth:.8,lineDash:K?[4,3]:null,fill:null},silent:!0}],ot=zo(P,b,C);return ot.length&&nt.push({type:"text",style:{text:ot.join(`
3
+ `),x:I+b/2,y:A+C/2,textAlign:"center",textVerticalAlign:"middle",fontSize:Re,lineHeight:li*Re,fill:pe().text_color||"#212529"},silent:!0}),{type:"group",children:nt}}}],L=(i.refLines===!1?[]:t.marks||[]).filter(y=>y.panel_id===e.id).filter(y=>!u||y.at>0),B=[...new Set(L.map(y=>y.at))].sort((y,M)=>y-M),p=new Map(L.filter(y=>y.label).map(y=>[y.at,y.label])),g=gn(a,n,{scale:c,window:h,floor:w,formatter:yn(a,c),nameGap:46});return B.length&&(delete g.interval,g.axisLabel={...g.axisLabel,customValues:B,formatter:y=>p.get(y)??kt(y)}),{series:F,legend:[],xAxis:Xt({type:"value",gridIndex:n,name:"",min:d[0],max:d[1],axisLabel:{show:!1},splitLine:{show:!1}}),yAxis:g,readAxis:e.read_axis||"y",title:Tn(t,e,!1),xWindow:null,zoom:{},xUnit:o.unit,yUnit:a.unit,xName:o.label,yName:a.label}}function jo(t,e,n,r){const i={color:"#6c757d",type:"dashed",width:1,opacity:t.faint?.45:1};return e!=="v"?{yAxis:n,name:t.label||"",lineStyle:i,label:{position:"insideStartTop",align:"left",padding:[0,0,0,5]}}:{xAxis:n,name:t.label||"",lineStyle:i,label:{position:"insideEndTop",rotate:90,align:"right",verticalAlign:r?"top":"bottom",padding:[0,4,0,4]}}}function Do(t){return{symbol:"none",silent:!0,label:{show:!0,fontSize:10,color:"#6c757d",distance:0,formatter:e=>e.name},lineStyle:{color:"#6c757d",type:"dashed",width:1},data:t}}function Wo(t,e){if(!t||!e||!(e[1]>e[0]))return{};const n=e[1]-e[0];return{start:100*(t[0]-e[0])/n,end:100*(t[1]-e[0])/n}}function Rn(t,e,n,r){const i=(t&&t.axes||[]).find(l=>l.id===e.z_axis)||{},s=qt(i,n.logY)==="log";return Ws({held:n.stretch,hint:e.stretch,relief:r,logZ:s})}const Bo=[0,131,0],Ho=[143,202,143],or=[240,239,236],Uo=[240,160,159],Go=[227,73,72],Yo=.45;function Xo(t,e,n){return[0,1,2].map(r=>Math.round(t[r]+(e[r]-t[r])*n))}function qo(t,e,n){if(!Number.isFinite(t)||e<=0||Math.abs(t)<=n)return or;const r=Math.max(e-n,1e-12),i=Math.min((Math.abs(t)-n)/r,1),[s,l]=t<0?[Ho,Bo]:[Uo,Go];return Xo(s,l,i)}function Vo([t,e,n]){return(.2126*t+.7152*e+.0722*n)/255}const Se=3,lr=13,Ko=4;function ar(t,e){const n=new Set;if(!t||!t.length)return n;for(let r=1;r<e;r++)t[r]!==t[r-1]&&n.add(r);return n}function Zo(t,e,n,r){const i=(t.series||[]).find(p=>p.panel_id===e.id&&p.matrix);if(!i)return null;const s=i.matrix,l=s.rows||[],o=s.columns||[],a=s.values||[],c=s.annotations||[],u=s.row_polarity&&s.row_polarity.length?s.row_polarity:l.map(()=>1),f=s.center===void 0||s.center===null?null:s.center,h=s.neutral||0,d=p=>f!==0&&Math.sign(p)!==Math.sign(f),w=a.map((p,g)=>p.map(y=>f===null||y===null||y===void 0||!Number.isFinite(y)||d(y)?NaN:u[g]*(y-f)));let S=0;for(const p of w)for(const g of p)Number.isFinite(g)&&(S=Math.max(S,Math.abs(g)));const N=ar(s.column_groups,o.length),W=ar(s.row_groups,l.length),z=p=>String(p).replace(/-/g,"−"),F=[];a.forEach((p,g)=>{p.forEach((y,M)=>{if(y==null)return;const G=qo(w[g][M],S,h),P=Vo(G)<=Yo;F.push({value:[M,g,y],fill:`rgb(${G.join(",")})`,ink:P?"#ffffff":"#0b0b0b",faint:P?"rgba(255,255,255,0.78)":"#52514e",text:`${z(Number(y).toFixed(2))}×`,note:c[g]&&c[g][M]?`(${z(c[g][M])})`:"",padL:N.has(M)?lr:0,padT:W.has(g)?lr:0})})});const L=(p,g)=>{const[y,M]=g.coord([g.value(0),g.value(1)]),G=g.size([1,1]),P=F[p.dataIndex]||{},H=P.padL||0,X=P.padT||0,I=y-G[0]/2+Se/2+H,A=M-G[1]/2+Se/2+X,b=Math.max(G[0]-Se-H,1),C=Math.max(G[1]-Se-X,1),j=I+b/2,K=[{type:"rect",shape:{x:I,y:A,width:b,height:C,r:2},style:{fill:P.fill},silent:!0}],it=C-2*Ko,nt=Math.min(13,Math.max(9,it*.34));return P.note?K.push({type:"text",silent:!0,style:{text:P.text,x:j,y:A+C/2-nt*.18,textAlign:"center",textVerticalAlign:"bottom",fill:P.ink,fontSize:nt}},{type:"text",silent:!0,style:{text:P.note,x:j,y:A+C/2+nt*.22,textAlign:"center",textVerticalAlign:"top",fill:P.faint,fontSize:Math.max(8,nt*.72)}}):K.push({type:"text",silent:!0,style:{text:P.text,x:j,y:A+C/2,textAlign:"center",textVerticalAlign:"middle",fill:P.ink,fontSize:nt}}),{type:"group",children:K}},B={splitLine:{show:!1},axisTick:{show:!1},axisLine:{show:!1}};return{series:[{type:"custom",name:i.name,data:F,renderItem:L,xAxisIndex:n,yAxisIndex:n}],legend:[],xAxis:Xt({type:"category",gridIndex:n,name:(r[e.x_axis]||{}).label||"",data:o,...B,axisLabel:{fontSize:11,color:"#52514e"}}),yAxis:Xt({type:"category",gridIndex:n,name:(r[e.y_axis]||{}).label||"",inverse:!0,data:l,...B,nameGap:46,axisLabel:{fontSize:11,color:"#52514e",width:Ce,overflow:"break",lineHeight:13}}),tooltip:{trigger:"item",formatter:p=>{const g=(r[e.z_axis]||{}).label||"value",y=p.data.note?`<br>${p.data.note}`:"";return`${l[p.value[1]]}, ${o[p.value[0]]}<br>${g} <b>${z(Number(p.value[2]).toFixed(3))}</b>`+y}}}}function Jo(t,e,n,r,i,s){const l=Zr(t,e.id);if(!l)return null;const o=Kr(l.surface),a=Jr(o),c=Qr(o),u=r[e.z_axis]||{},f=qt(u,i.logY)==="log",h=Rn(t,e,i,!1),d=me([o.z])||Gt;let w=-1/0;const S=[];for(let p=0;p<o.ny;p++)for(let g=0;g<o.nx;g++){const y=o.z[p*o.nx+g],M=f?Math.log10(Math.max(y,d)):y;M>w&&(w=M),S.push([g,p,M])}const N=f?Math.log10(d):0,W={fontSize:10,color:"#6c757d",hideOverlap:!0,formatter:p=>kt(Number(p))},z=u.label||"z",F=sr(a),L=sr(c),B=[];if(i.contours!==!1){const p=(M,G)=>{const P=o.z[G*o.nx+M];return f?Math.log10(Math.max(P,d)):P},g=Number.isFinite(w)?w:N+1,y=[];for(const M of ri(N,g,wi,h))for(const G of ti(o,M,p)){if(y.length>=xn)break;y.push(G.map(P=>[(P[0]-o.x0)/o.dx,(P[1]-o.y0)/o.dy]))}y.length&&B.push({type:"custom",name:"contour",silent:!0,xAxisIndex:n,yAxisIndex:n,data:[0],tooltip:{show:!1},renderItem:(M,G)=>{const P=G.coord([0,0]),H=G.coord([o.nx-1,o.ny-1]),X=o.nx>1?(H[0]-P[0])/(o.nx-1):0,I=o.ny>1?(H[1]-P[1])/(o.ny-1):0;return{type:"group",children:y.map(A=>({type:"polyline",shape:{points:A.map(([b,C])=>[P[0]+b*X,P[1]+C*I]),smooth:.4},style:{stroke:gi,lineWidth:yi,opacity:xi,fill:null},silent:!0}))}}})}return{series:[{type:"heatmap",name:l.name,data:S,xAxisIndex:n,yAxisIndex:n,progressive:4e3,emphasis:{disabled:!0}},...B],legend:[],xAxis:Xt({type:"category",gridIndex:n,name:(r[e.x_axis]||{}).label||"",data:a,splitLine:{show:!1},axisLabel:{...W,...F}}),yAxis:Xt({type:"category",gridIndex:n,name:(r[e.y_axis]||{}).label||"",data:c,nameGap:46,splitLine:{show:!1},axisLabel:{...W,...L}}),visualMap:{min:N,max:Number.isFinite(w)?w:N+1,seriesIndex:null,calculable:!0,left:s.left+s.width+24,top:s.top+10,itemHeight:Math.max(90,s.height-60),textStyle:{fontSize:10,color:"#6c757d"},inRange:{color:Te(h)},formatter:p=>f?Ie(10**Number(p)):p?Ie(p):"0"},tooltip:{trigger:"item",formatter:p=>{const g=f?10**p.value[2]:p.value[2],y=f&&p.value[2]<=N?`&lt; ${d.toExponential(0)}`:Number(g).toExponential(3);return`${kt(Number(a[p.value[0]]))}, ${kt(Number(c[p.value[1]]))}<br>${z} <b>${y}</b>`}},readAxis:"x",title:Tn(t,e,!1),xWindow:null,zoom:{}}}function cr(t,e={}){const n=t&&t.panels||[];if(!n.length||t.ir_version>Gs)return null;const r={kind:null,...e.view||{}},i=ai(n),s=Object.fromEntries(n.map(c=>[c.id,c])),l=new Set,o=c=>({...dn(t,s[c]),...(r.panels||{})[c]||{}});for(const[c,u]of i)o(u).logY&&l.add(c);r.forPanel=c=>{const u=s[c],f=!!u&&i.has(u.y_axis),h=f&&i.get(u.y_axis)!==c,d={...r,...oi,...dn(t,u),...h?{}:(r.panels||{})[c]||{}};return f&&(d.logY=l.has(u.y_axis)),d};const a=n.map(c=>_o(c,r.kind));return a.some(c=>c==="surface")?wl(t,e,r):Qo(t,e,r,a)}function Qo(t,e,n,r){const i=t.panels||[],s=Object.fromEntries((t.axes||[]).map(p=>[p.id,p])),l=ui(t,e.width),o=[],c={colorOf:p=>{let g=o.indexOf(p);return g<0&&(g=o.length,o.push(p)),g},floors:po(t,r)},u=i.map((p,g)=>{const y=n.forPanel(p.id);return r[g]==="xy"?Oo(t,p,g,s,y,e.zoom,c):r[g]==="tower"?Po(t,p,g,s,y,c):r[g]==="matrix"?Zo(t,p,g,s):Jo(t,p,g,s,y,l.grids[g])}).filter(Boolean);if(!u.length)return null;const f=[],h=[];u.forEach((p,g)=>{p.firstSeries=f.length;for(const y of p.series)f.push(y),h.push(g)});const d=[...new Set(u.flatMap(p=>p.legend))],w=d.map(p=>{const g=f.find(y=>y.name===p);return{name:p,color:g&&g.itemStyle&&g.itemStyle.color||"#6c757d"}}),S=i.map((p,g)=>({p,i:g})).filter(({p,i:g})=>r[g]==="xy"&&p.aspect!=="equal"),N=new Map;for(const{p,i:g}of S)for(const[y,M]of[["x",p.x_axis],["y",p.y_axis]])N.has(M)||N.set(M,{x:[],y:[]}),N.get(M)[y].push(g);const W=[];for(const p of N.values()){if(!p.x.length)continue;const g=u[p.x[0]].zoom;W.push({type:"inside",filterMode:"filter",xAxisIndex:p.x,...p.y.length?{yAxisIndex:p.y}:{},...g})}const z=hn(Vn(),{grid:l.grids.map((p,g)=>({...p,containLabel:!1,tooltip:r[g]==="tower"?{trigger:"item"}:{axisPointer:{axis:(u[g]||{}).readAxis||"x"}}})),title:u.map((p,g)=>({text:p.title,left:l.grids[g].left,top:l.grids[g].top-24,textStyle:{fontSize:12,fontWeight:600}})).filter(p=>p.text),xAxis:u.map(p=>p.xAxis),yAxis:u.map(p=>p.yAxis),legend:{...Vn().legend,show:!1,data:d},series:f,...W.length?{dataZoom:W}:{}}),F=u.filter(p=>p.visualMap);F.length?(z.visualMap=F.map(p=>({...p.visualMap,seriesIndex:p.firstSeries})),z.tooltip={...z.tooltip,...F[0].tooltip}):(z.tooltip={...z.tooltip,axisPointer:{type:"line",lineStyle:{color:"#adb5bd",width:1,type:"dashed"},label:{show:!1}},formatter:p=>tl(p,h,u)},z.readout=p=>pi(p,h,u));const L=hn(z,mi(e.overrides,{doc:t,view:n,box:l}));L.legendItems=F.length?[]:w,L.hostHeight=l.hostHeight,L.panelFootprint=l.footprint,L.columns=l.grids.map(p=>({left:p.left,width:p.width})),L.extent=So(l),L.is3d=!1;const B=u.find(p=>p.xWindow&&p.rung)||{};return L.lossWindow=B.xWindow||null,L.lossGrid=B.atomGrid||null,L.rung=B.rung||null,L.readings=Ln(t),L}function Xe(t,e){return t==null?"":e==="probability"?Number(t).toExponential(3):e==="return_period"?`1-in-${hi(t)}`:e==="density"?Number(t).toExponential(3):kt(t)}function pi(t,e,n){const r=(Array.isArray(t)?t:[t]).filter(o=>Array.isArray(o.value)&&o.value[1]!=null);if(!r.length)return null;const i=n[e[r[0].seriesIndex]]||{},s=i.readAxis==="y";return{head:s?`${i.yName||""} ${Xe(r[0].value[1],i.yUnit)}`.trim():`${i.xName||""} ${Xe(r[0].value[0],i.xUnit)}`.trim(),rows:r.map(o=>({color:o.color&&String(o.color)||"#6c757d",name:o.seriesName,value:Xe(s?o.value[0]:o.value[1],s?i.xUnit:i.yUnit)}))}}function tl(t,e,n){const r=pi(t,e,n);if(!r)return"";const i=r.rows.map((s,l)=>`${(Array.isArray(t)?t:[t])[l].marker}${s.name} <b>${s.value}</b>`).join("<br>");return`${r.head}<br>${i}`}function el(t,e){if(!t||!t.lossGrid||!t.rung)return null;const{support:n,xAxis:r,yAxis:i}=t.rung;return mn(n,r,i,fi(t.lossGrid,e))}function mi(t,e){return typeof t=="function"?t(e):t}const nl=8,rl=.45,il=1.47,sl=760,ol=.5,ll=90,al=6,cl=.0018,qe=.004;function ul(t,e){const n=e-t;if(!(n>0)||!Number.isFinite(n))return{min:t,max:e};const r=$n(n/5)||n/5;return{min:Math.floor(t/r)*r,max:Math.ceil(e/r)*r}}const fl="#f8f9fa",hl=.9,dl=.5,pl="#e9ecef",ml="#6c757d",gi="#ffffff",yi=1.4,xi=.85,wi=8,xn=160,gl=.55;function yl(t,e,n){const r=l=>{const o=[];for(let a=0;a<l;a+=e)o.push(a);return o[o.length-1]!==l-1&&o.push(l-1),o},i=[];r(t.ny).forEach((l,o,a)=>{const c=o%2===0;for(let u=0;u<t.nx;u++)i.push(n(c?u:t.nx-1-u,l));if(o<a.length-1){const u=c?t.nx-1:0;for(let f=l+1;f<a[o+1];f++)i.push(n(u,f))}});const s=[];return r(t.nx).forEach((l,o,a)=>{const c=o%2===0;for(let u=0;u<t.ny;u++)s.push(n(l,c?u:t.ny-1-u));if(o<a.length-1){const u=c?t.ny-1:0;for(let f=l+1;f<a[o+1];f++)s.push(n(f,u))}}),[i,s]}const Ae={x:"#dc3545",y:"#0d6efd",s:"#198754"};function bi(t,e,n){const r=n.cut||"none";if(r==="none")return{series:[],readout:{where:[],leaves:[]}};const{height:i,zMax:s,floorH:l,hair:o,xWall:a,yWall:c,k:u,dataMax:f,xName:h,yName:d,digits:w}=e,S=[],N=[],W=[];let z=null,F=null;const L=A=>Number.isFinite(A)?kt(A):"",B=A=>Number.isFinite(A)?Number(A).toExponential(Math.max(1,w-3)):"",p=A=>Math.min(s,Math.max(l,i(A))),g=(A,b)=>Number.isFinite(A)?Math.min(1,Math.max(0,A)):b,y=(A,b,C)=>A+(b-A)*C,M=y(ht(t,0),ht(t,t.nx-1),g(n.cutX,.5)),G=y(dt(t,0),dt(t,t.ny-1),g(n.cutY,.5)),P=y(ht(t,0)+dt(t,0),ht(t,t.nx-1)+dt(t,t.ny-1),g(n.cutS,.5)),H=A=>{let b=0;for(const j of A)j>b&&(b=j);const C=f*.98;return b>C?C/b:1},X=A=>{const b=H(A);return b===1?A:A.map(C=>C*b)},I=(A,b,C,j,K,it)=>{const nt=Math.min(j[0],j[j.length-1]),ot=Math.max(j[0],j[j.length-1]),ft=Number.isFinite(it)&&it>=nt&&it<=ot,pt=ft?p(Ue(j,K,it)):0,R=U=>C==="x"?[it,c,U]:[a,it,U];S.push({id:`mean-${A}`,type:"line3D",name:`mean of ${A}`,data:ft?[R(l),R(pt)]:[],lineStyle:{color:b,width:1.2,opacity:.55},silent:!0},{id:`meandot-${A}`,type:"scatter3D",name:`mean of ${A}`,symbolSize:9,data:ft?[R(pt)]:[],itemStyle:{color:b,opacity:1,borderColor:"#ffffff",borderWidth:1},silent:!0})};if(r==="components"||r==="all"){const A=[{tag:"x",color:Ae.x,alongY:!0,curve:Ns(t,M),coords:Qr(t),step:t.dy},{tag:"y",color:Ae.y,alongY:!1,curve:Rs(t,G),coords:Jr(t),step:t.dx}];for(const b of A){const C=Array.from(b.curve.values),j=C.reduce((nt,ot)=>nt+ot,0)*b.step,K=X(C.map(nt=>nt/(j||1)*u)),it=Ge(b.coords,C);S.push({id:`cond-${b.tag}`,type:"line3D",name:`conditional given ${b.tag}`,data:b.alongY?b.coords.map((nt,ot)=>[a,nt,p(K[ot])]):b.coords.map((nt,ot)=>[nt,c,p(K[ot])]),lineStyle:{color:b.color,width:2.4,opacity:1},silent:!0},{id:`cut-${b.tag}`,type:"line3D",name:`cut at ${b.tag}`,data:b.alongY?b.coords.map((nt,ot)=>[b.curve.at,nt,Math.min(s,i(C[ot])+o)]):b.coords.map((nt,ot)=>[nt,b.curve.at,Math.min(s,i(C[ot])+o)]),lineStyle:{color:b.color,width:2.4,opacity:1},silent:!0},{id:`trace-${b.tag}`,type:"line3D",name:`trace at ${b.tag}`,data:b.alongY?[[b.curve.at,dt(t,0),l+o],[b.curve.at,dt(t,t.ny-1),l+o]]:[[ht(t,0),b.curve.at,l+o],[ht(t,t.nx-1),b.curve.at,l+o]],lineStyle:{color:b.color,width:1.6,opacity:.85},silent:!0}),I(b.tag,b.color,b.alongY?"y":"x",b.coords,K,it),N.push({name:b.alongY?h:d,color:b.color,value:L(b.curve.at)}),W.push({name:`mean ${b.alongY?d:h}`,color:b.color,value:L(it)})}F=Bt(t,Math.max(0,Math.min(t.nx-1,Math.round((M-t.x0)/t.dx))),Math.max(0,Math.min(t.ny-1,Math.round((G-t.y0)/t.dy)))),z=M+G}if(r==="total"||r==="all"){const A=Ae.s,b=Ts(t,P,{count:Math.max(t.nx,t.ny)});if(b.length>=2){const C=b.map(v=>v[0]),j=b.map(v=>v[1]),K=b.map(v=>v[2]),it=C.length>1?Math.abs(C[1]-C[0]):1,nt=K.reduce((v,$)=>v+$,0)*it,ot=()=>K.map(v=>v/(nt||1)*u),ft=X(ot()),pt=X(ot());S.push({id:"cond-s-x",type:"line3D",name:"x given the total",data:b.map((v,$)=>[v[0],c,p(ft[$])]),lineStyle:{color:A,width:2.4,opacity:1},silent:!0},{id:"cond-s-y",type:"line3D",name:"y given the total",data:b.map((v,$)=>[a,v[1],p(pt[$])]),lineStyle:{color:A,width:2.4,opacity:1},silent:!0},{id:"cut-s",type:"line3D",name:"cut at the total",data:b.map(v=>[v[0],v[1],Math.min(s,i(v[2])+o)]),lineStyle:{color:A,width:2.4,opacity:1},silent:!0},{id:"trace-s",type:"line3D",name:"trace at the total",data:[[C[0],j[0],l+o],[C[C.length-1],j[j.length-1],l+o]],lineStyle:{color:A,width:1.6,opacity:.85},silent:!0});const R=Ge(C,K),U=Ge(j,K);I("s-x",A,"x",C,ft,R),I("s-y",A,"y",j,pt,U);const m=(v,$)=>v>=ht(t,0)&&v<=ht(t,t.nx-1)&&$>=dt(t,0)&&$<=dt(t,t.ny-1),E=v=>Math.min(s,i(Ue(C,K,v))+o*2),_=(C[0]+j[0])/2;S.push({id:"kappa-point",type:"scatter3D",name:"kappa",symbolSize:11,data:m(R,U)?[[R,U,E(R)]]:[],itemStyle:{color:A,opacity:1,borderColor:"#ffffff",borderWidth:1.5},silent:!0},{id:"even-split",type:"scatter3D",name:"even split",symbolSize:9,data:m(_,_)?[[_,_,E(_)]]:[],itemStyle:{color:"rgba(0,0,0,0)",borderColor:A,borderWidth:1.6},silent:!0}),z=C[0]+j[0],F===null&&(F=Ue(C,K,R)),W.push({name:`kappa ${h}`,color:A,value:L(R),hint:`E[${h} | total = ${L(z)}]: how much of a total that size falls to this component, on average`},{name:`kappa ${d}`,color:A,value:L(U),hint:"The other half of the same split. The two sum to the total exactly, at every cut"},{name:"even split",color:A,value:L(_),hint:"Half the total to each, which is where the split would sit if the two components shared it equally. The hollow ring on the chart. The gap between it and the filled dot is how far from even this total actually splits"})}}return z!==null&&N.push({name:"total",color:Ae.s,value:L(z),hint:"The sum of the two components at the cut"}),F!==null&&N.push({name:"density",color:"#6c757d",value:B(F),hint:"The joint density where the cut sits"}),{series:S,readout:{where:N,leaves:W}}}function xl(t,e){const n=t&&t.cutContext;return n?bi(n.grid,n.ctx,e):null}function wl(t,e,n){const r=t&&t.panels&&t.panels[0]||null;if(!r)return null;const i=n.forPanel(r.id),s=Object.fromEntries((t.axes||[]).map(O=>[O.id,O])),l=Zr(t);if(!l)return null;const o=Kr(l.surface),a=qt(s[r.z_axis]||{},i.logY)==="log",c=Rn(t,r,i,!0),{max:u,min:f}=Ls(o,Gt),h=a?Math.ceil(Math.log10(u)):u,d=a?Math.max(Math.floor(Math.log10(f)),h-nl):0,w=h-d||1,S=w*qe,N=d-w*rl,W=N+S*.5,z=O=>a?O>Gt?Math.max(d,Math.log10(O)):d:O,F=new Float64Array(o.nx*o.ny);for(let O=0;O<F.length;O++)F[O]=z(o.z[O]);const L=[];for(let O=0;O<o.nx;O++)for(let D=0;D<o.ny;D++)L.push([ht(o,O),dt(o,D),F[D*o.nx+O]]);const B=w*cl,p=(O,D)=>[ht(o,O),dt(o,D),Math.min(h,z(o.z[D*o.nx+O])+B)],[g,y]=yl(o,al,p),M=Math.max(1,Math.round(Math.max(o.nx,o.ny)/ll)),G=[],P=[];for(let O=0;O<o.nx;O+=M)G.push(O);for(let O=0;O<o.ny;O+=M)P.push(O);const H=[];for(const O of G)for(const D of P)H.push([ht(o,O),dt(o,D),W,z(o.z[D*o.nx+O])]);const X=(s[r.x_axis]||{}).label||"x",I=(s[r.y_axis]||{}).label||"y",A=(s[r.z_axis]||{}).label||"z",b=a?`log ${A}`:A,C=ui(t,e.width),j=i.mesh!==!1,K=[{type:"surface",name:l.name,dataShape:[o.nx,o.ny],data:L}];if(j)for(const[O,D]of[["mesh along x",g],["mesh along y",y]])K.push({type:"line3D",name:O,data:D,lineStyle:{color:fl,width:hl,opacity:dl},silent:!0});const it=K.length;K.push({type:"surface",name:"floor",dimensions:["x","y","z","height"],dataShape:[G.length,P.length],data:H,shading:"color",itemStyle:{color:pl,opacity:ol},wireframe:{show:!1},silent:!0});const nt=(ht(o,o.nx-1)-ht(o,0))*qe,ot=(dt(o,o.ny-1)-dt(o,0))*qe,ft=ht(o,0)+nt,pt=dt(o,0)+ot;let R=1;if(o.marginals){const O=k=>Math.max(...Array.from(k,Math.abs))||1,D=O(Array.from(o.marginals.x||[1],k=>k/o.dx)),tt=O(Array.from(o.marginals.y||[1],k=>k/o.dy));R=u*gl*Is(D,tt).scale}if(i.marginals&&o.marginals){const O=Array.from(o.marginals.x||[],V=>V/o.dx),D=Array.from(o.marginals.y||[],V=>V/o.dy),tt=R,k=V=>Math.min(h,Math.max(W,z(V))),Q={color:ml,width:2,opacity:.95};K.push({type:"line3D",name:`marginal in ${X}`,data:O.map((V,q)=>[ht(o,q),pt,k(V*tt)]),lineStyle:Q,silent:!0},{type:"line3D",name:`marginal in ${I}`,data:D.map((V,q)=>[ft,dt(o,q),k(V*tt)]),lineStyle:Q,silent:!0})}if(i.contours){const O=(tt,k)=>z(o.z[k*o.nx+tt]);let D=0;for(const tt of ri(d,h,wi,c)){if(D>=xn)break;for(const k of ti(o,tt,O)){if(D>=xn)break;for(const Q of[tt,W])D+=1,K.push({type:"line3D",name:"contour",data:k.map(V=>[V[0],V[1],Q+S]),lineStyle:{color:gi,width:yi,opacity:xi},silent:!0})}}}const U={height:z,zMax:h,floorH:W,hair:S,xWall:ft,yWall:pt,k:R,dataMax:u,xName:X,yName:I,digits:o.digits},m=bi(o,U,i);K.push(...m.series);const E={splitLine:{show:i.wallGrid!==!1}},_=ul(N,h),v={xAxis3D:{type:"value",name:X,...E},yAxis3D:{type:"value",name:I,...E},zAxis3D:{type:"value",name:b,..._,...E},visualMap:[{min:d,max:h,dimension:2,seriesIndex:0},{min:d,max:h,dimension:3,seriesIndex:it,show:!1}],series:K},$=Math.min(sl,Math.round(C.hostHeight*il)),Z={doc:t,view:i,box:C,xName:X,yName:I,zName:b,logZ:a,zMin:d,zMax:h,grid:o,digits:o.digits,quantized:o.quantized,camera:e.camera||null,stretch:c,hostHeight:$,side:C.panelW},x=hn(v,mi(e.overrides,Z));x.hostHeight=$,x.extent=Ao(e.width),x.columns=[x.extent],x.is3d=!0,x.cutReadout=m.readout,x.cutContext={grid:o,ctx:U},x.surfaceBox={x:[ht(o,0),ht(o,o.nx-1)],y:[dt(o,0),dt(o,o.ny-1)]};const Y=x.grid3D||{};return x.meshSource={name:t.title||l.name||"surface",nx:o.nx,ny:o.ny,x0:ht(o,0),dx:o.dx,y0:dt(o,0),dy:o.dy,z:F,zRange:[_.min,_.max],colorRange:[d,h],ramp:Te(c),box:{width:Y.boxWidth||100,depth:Y.boxDepth||100,height:Y.boxHeight||62}},x.readings=Ln(t),x}function ur(t){return String(t||"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||"surface"}function bl(t,e={}){const{nx:n,ny:r,x0:i,dx:s,y0:l,dy:o,z:a}=t||{};if(!(n>1)||!(r>1))throw new Error("a surface mesh needs at least two points on each axis");if(!a||a.length!==n*r)throw new Error(`surface mesh got ${a?a.length:0} heights for a ${n} by ${r} grid`);const c={width:100,depth:100,height:62,...e.box||{}},u=e.zRange||vl(a),[f,h]=u,d=h-f||1,w=Math.min(i,i+(n-1)*s),S=Math.abs((n-1)*s)||1,N=Math.min(l,l+(r-1)*o),W=Math.abs((r-1)*o)||1,z=H=>((i+H*s-w)/S-.5)*c.width,F=H=>((l+H*o-N)/W-.5)*c.depth,L=H=>(H-f)/d*c.height,B=new Int32Array(n*r).fill(-1),p=[],g=[],y=[],M=(H,X)=>{const I=X*n+H;return B[I]<0&&(B[I]=p.length/3,p.push(z(H),F(X),L(a[I])),g.push(a[I])),B[I]},G=s*o<0;let P=0;for(let H=0;H<r-1;H+=1)for(let X=0;X<n-1;X+=1){const I=H*n+X;if(!Number.isFinite(a[I])||!Number.isFinite(a[I+1])||!Number.isFinite(a[I+n])||!Number.isFinite(a[I+n+1])){P+=1;continue}const A=M(X,H),b=M(X+1,H),C=M(X+1,H+1),j=M(X,H+1);G?y.push(A,C,b,A,j,C):y.push(A,b,C,A,C,j)}return{vertices:Float64Array.from(p),values:Float64Array.from(g),triangles:Uint32Array.from(y),counts:{vertices:p.length/3,triangles:y.length/3},box:c,zRange:[f,h],dropped:P}}function vl(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r+=1){const i=t[r];Number.isFinite(i)&&(i<e&&(e=i),i>n&&(n=i))}return Number.isFinite(e)?[e,n]:[0,1]}function _l(t,e,n,r){const i=t[n]-t[e],s=t[n+1]-t[e+1],l=t[n+2]-t[e+2],o=t[r]-t[e],a=t[r+1]-t[e+1],c=t[r+2]-t[e+2],u=s*c-l*a,f=l*o-i*c,h=i*a-s*o,d=Math.hypot(u,f,h);return d>0?[u/d,f/d,h/d]:[0,0,0]}function Sl(t,e="surface"){const n=t.counts.triangles,r=new ArrayBuffer(84+50*n),i=new Uint8Array(r),s=new DataView(r),l=`aggregate Loss Lab surface: ${e}`;for(let a=0;a<Math.min(80,l.length);a+=1){const c=l.charCodeAt(a);i[a]=c<128?c:63}s.setUint32(80,n,!0);const o=t.vertices;for(let a=0;a<n;a+=1){const c=t.triangles[a*3]*3,u=t.triangles[a*3+1]*3,f=t.triangles[a*3+2]*3,h=_l(o,c,u,f);let d=84+a*50;for(let w=0;w<3;w+=1)s.setFloat32(d,h[w],!0),d+=4;for(const w of[c,u,f])for(let S=0;S<3;S+=1)s.setFloat32(d,o[w+S],!0),d+=4;s.setUint16(d,0,!0)}return i}function te(t){return String(Math.round(t*1e4)/1e4)}function Al(t,e){const n=t&&t.length?t:["#000000","#ffffff"],r=Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*(n.length-1),i=Math.min(n.length-2,Math.floor(r)),s=n.length>1?r-i:0,l=u=>{const f=parseInt(String(u).replace("#",""),16);return[f>>16&255,f>>8&255,f&255]},o=l(n[i]),a=l(n[Math.min(n.length-1,i+1)]),c=u=>u<=.04045?u/12.92:((u+.055)/1.055)**2.4;return[0,1,2].map(u=>c((o[u]+(a[u]-o[u])*s)/255))}function Ml(t,e="surface",n={}){const r=n.ramp,[i,s]=n.colorRange||t.zRange,l=s-i||1,o=t.counts.vertices,a=Float32Array.from(t.vertices),c=new Float32Array(o*3);for(let y=0;y<o;y+=1){const[M,G,P]=Al(r,((t.values[y]||0)-i)/l);c[y*3]=M,c[y*3+1]=G,c[y*3+2]=P}const u=Uint32Array.from(t.triangles),f=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0];for(let y=0;y<o;y+=1)for(let M=0;M<3;M+=1){const G=a[y*3+M];G<f[M]&&(f[M]=G),G>h[M]&&(h[M]=G)}const d=a.byteLength,w=c.byteLength,S=u.byteLength,N={asset:{version:"2.0",generator:"aggregate Loss Lab"},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0,name:e}],meshes:[{name:e,primitives:[{attributes:{POSITION:0,COLOR_0:1},indices:2,material:0}]}],materials:[{name:"viridis",doubleSided:!0,pbrMetallicRoughness:{baseColorFactor:[1,1,1,1],metallicFactor:0,roughnessFactor:.85}}],buffers:[{byteLength:d+w+S}],bufferViews:[{buffer:0,byteOffset:0,byteLength:d,target:34962},{buffer:0,byteOffset:d,byteLength:w,target:34962},{buffer:0,byteOffset:d+w,byteLength:S,target:34963}],accessors:[{bufferView:0,componentType:5126,count:o,type:"VEC3",min:f,max:h},{bufferView:1,componentType:5126,count:o,type:"VEC3"},{bufferView:2,componentType:5125,count:u.length,type:"SCALAR"}]},W=fr(new TextEncoder().encode(JSON.stringify(N)),32),z=new Uint8Array(d+w+S);z.set(new Uint8Array(a.buffer),0),z.set(new Uint8Array(c.buffer),d),z.set(new Uint8Array(u.buffer),d+w);const F=fr(z,0),L=20+W.length+8+F.length,B=new Uint8Array(L),p=new DataView(B.buffer);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,L,!0),p.setUint32(12,W.length,!0),p.setUint32(16,1313821514,!0),B.set(W,20);let g=20+W.length;return p.setUint32(g,F.length,!0),p.setUint32(g+4,5130562,!0),B.set(F,g+8),B}function fr(t,e){const n=(4-t.length%4)%4;if(!n)return t;const r=new Uint8Array(t.length+n);return r.set(t,0),r.fill(e,t.length),r}function El(t,e="surface"){const n=t.vertices,r=["# aggregate Loss Lab, surface export. Z is up, as in the STL",`# display box ${te(t.box.width)} by ${te(t.box.depth)} by ${te(t.box.height)}, height axis ${t.zRange[0].toPrecision(6)} to ${t.zRange[1].toPrecision(6)}`,`o ${e}`];for(let s=0;s<n.length;s+=3)r.push(`v ${te(n[s])} ${te(n[s+1])} ${te(n[s+2])}`);const i=t.triangles;for(let s=0;s<i.length;s+=3)r.push(`f ${i[s]+1} ${i[s+1]+1} ${i[s+2]+1}`);return r.push(""),r.join(`
4
+ `)}function vi(t,e){const n=(t&&t.windows||{})[e],r=(t&&t.lee||{})[e];return{...Number.isFinite(n)?{window:n}:{},...r?{lee:!0}:{}}}function Cl(t,e,n){const r={...t||{}};return Number.isFinite(n)?r[e]=n:delete r[e],r}function kl(t,e,n){const r={...t||{}};return n?r[e]=!0:delete r[e],r}const Ll=new Set(["window","log","fullRange","reflect","returnPeriod","invert","refLines"]);function hr(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e={};for(const[n,r]of Object.entries(t))Ll.has(n)||(e[n]=r);return e}const $l=new Set(["logX","logY"]);function Tl(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e=t.panels;if(!e||typeof e!="object"||Array.isArray(e))return t;const n={};for(const[r,i]of Object.entries(e))!i||typeof i!="object"||Array.isArray(i)||(n[r]=Object.fromEntries(Object.entries(i).filter(([s])=>!$l.has(s))));return{...t,panels:n}}const ce={orbit:90,elevate:55,zoom:.9,pan:.7,dominant:!1,expo:.6,invert:{tx:!1,ty:!1,tz:!1,rx:!1,ry:!1,rz:!1}},dr=40,Rl=400,Nl=-90,Il=90,Ol=.05,Fl=300;function zl(t,e=ce.expo){const n=Math.min(1,Math.max(0,e));return(1-n)*t+n*t*t*t}function Pl(t){let e=null,n=0;for(const[i,s]of Object.entries(t))Math.abs(s)>n&&(n=Math.abs(s),e=i);const r={};for(const i of Object.keys(t))r[i]=i===e?t[i]:0;return r}function jl(t,e){const n=t*Math.PI/180,r=e*Math.PI/180;return{right:[Math.cos(r),0,-Math.sin(r)],up:[-Math.sin(n)*Math.sin(r),Math.cos(n),-Math.sin(n)*Math.cos(r)]}}function Dl(t,e,n=ce,r=1/60){const i={...ce,...n,invert:{...ce.invert,...n.invert||{}}};let s={};for(const[c,u]of Object.entries(e||{}))s[c]=zl(u,i.expo)*(i.invert[c]?-1:1);if(i.dominant&&(s=Pl(s)),!Object.values(s).some(c=>c!==0)||!t||!Number.isFinite(t.alpha))return null;const o=Number.isFinite(t.distance)?t.distance:dr,a={};if(s.rz&&(a.beta=t.beta+s.rz*i.orbit*r),s.rx&&(a.alpha=Math.min(Il,Math.max(Nl,t.alpha+s.rx*i.elevate*r))),s.ty&&(a.distance=Math.min(Rl,Math.max(dr,o*Math.exp(-s.ty*i.zoom*r)))),s.tx||s.tz){const{right:c,up:u}=jl(t.alpha,t.beta),f=Array.isArray(t.center)?t.center.slice(0,3):[0,0,0],h=o*i.pan*r;a.center=[0,1,2].map(d=>(f[d]||0)-c[d]*s.tx*h+u[d]*s.tz*h)}return Object.keys(a).length?a:null}function Wl(t,e={}){const n={settings:{...ce,...e},running:!1};let r=null,i=0,s=0,l=null;const o=()=>typeof performance<"u"?performance.now():Date.now(),a=h=>typeof requestAnimationFrame=="function"?requestAnimationFrame(h):setTimeout(()=>h(o()),16),c=h=>{typeof cancelAnimationFrame=="function"?cancelAnimationFrame(h):clearTimeout(h)},u=()=>!r||!Object.values(r).some(h=>h!==0);n.tick=h=>{const d=Number.isFinite(h)?h:o(),w=Math.min(Ol,Math.max(0,(d-s)/1e3))||1/60;if(s=d,d-i>Fl&&(r=null),u())return n.stop(),!1;const S=Dl(t.read(),r,n.settings,w);return S&&t.write(S),!0};function f(h){l=null,n.running&&n.tick(h)&&(l=a(f))}return n.input=h=>{if(h){if(r=h.axes,i=o(),h.pressed&&(h.pressed&1&&t.reset&&t.reset(),h.pressed&2&&t.setProjection)){const d=t.read(),w=d&&d.projection||"perspective";t.setProjection(w==="perspective"?"orthographic":"perspective")}u()||n.running||(n.running=!0,s=o(),l=a(f))}},n.stop=()=>{n.running=!1,l!==null&&c(l),l=null},n.dispose=()=>{n.stop(),r=null},n}const Bl="modulepreload",Hl=function(t,e){return new URL(t,e).href},pr={},wn=function(e,n,r){let i=Promise.resolve();if(n&&n.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),a=o?.nonce||o?.getAttribute("nonce");i=Promise.allSettled(n.map(c=>{if(c=Hl(c,r),c in pr)return;pr[c]=!0;const u=c.endsWith(".css"),f=u?'[rel="stylesheet"]':"";if(!!r)for(let w=l.length-1;w>=0;w--){const S=l[w];if(S.href===c&&(!u||S.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${c}"]${f}`))return;const d=document.createElement("link");if(d.rel=u?"stylesheet":Bl,u||(d.as="script"),d.crossOrigin="",d.href=c,a&&d.setAttribute("nonce",a),document.head.appendChild(d),u)return new Promise((w,S)=>{d.addEventListener("load",w),d.addEventListener("error",()=>S(new Error(`Unable to preload CSS for ${c}`)))})}))}function s(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&s(o.reason);return e().catch(s)})};function Ul({xName:t,yName:e,logZ:n,zMin:r,digits:i=7,quantized:s=!1}={}){const l=a=>Number(a).toExponential(Math.max(0,i-1)),o=()=>[{name:t,value:""},{name:e,value:""},{name:"density",value:""}];return a=>{if(!Array.isArray(a)||a.length<3)return o();const[c,u,f]=a;if(![c,u,f].every(Number.isFinite))return o();const h=n?10**f:f,d=n&&f<=r?`< ${(10**r).toExponential(0)}`:l(h);return[{name:t,value:kt(c)},{name:e,value:kt(u)},{name:"density",value:d,hint:s?"height is quantized":void 0}]}}let Ve=null;function Gl(){return Ve||(Ve=(async()=>{const[{Line3DChart:t,Scatter3DChart:e,SurfaceChart:n},{Grid3DComponent:r}]=await Promise.all([wn(()=>import("./echarts-gl-DG1Uf6wE.js").then(i=>i.c),__vite__mapDeps([0,1]),import.meta.url),wn(()=>import("./echarts-gl-DG1Uf6wE.js").then(i=>i.a),__vite__mapDeps([0,1]),import.meta.url)]);return Lr([t,e,n,r]),!0})().catch(()=>!1)),Ve}function mr(t){try{const e=t.getModel().getComponent("grid3D").option.viewControl;if(!e||!Number.isFinite(e.alpha))return null;const n={alpha:e.alpha,beta:e.beta};return Number.isFinite(e.distance)&&(n.distance=e.distance),Array.isArray(e.center)&&(n.center=e.center.slice(0,3)),e.projection&&(n.projection=e.projection),n}catch{return null}}function gr(t){if(t===0)return"0";const e=Math.abs(t);return e>=1e5||e<.001?t.toExponential(1):String(+t.toPrecision(4))}function Yl({xName:t,yName:e,logZ:n,zMin:r,digits:i=7,quantized:s=!1,side:l=420,hostHeight:o=480,camera:a=null,lights:c=!0,stretch:u=null}={}){const f=pe();return{color:f.colors,textStyle:{fontSize:Math.max(10,f.font_size+2),color:f.text_color},animation:!1,cellReader:Ul({xName:t,yName:e,logZ:n,zMin:r,digits:i,quantized:s}),tooltip:{show:!1},visualMap:[{calculable:!0,right:4,top:20,itemHeight:Math.max(80,Math.round(o*.5)),textStyle:{fontSize:10,color:"#6c757d"},inRange:{color:Te(u)},formatter:h=>n?`1e${Math.round(h)}`:gr(h)},{show:!1,inRange:{color:Te(u)}}],xAxis3D:{nameTextStyle:{fontSize:11,color:"#6c757d"},axisLabel:{fontSize:9,color:"#6c757d",formatter:h=>kt(h)}},yAxis3D:{nameTextStyle:{fontSize:11,color:"#6c757d"},axisLabel:{fontSize:9,color:"#6c757d",formatter:h=>kt(h)}},zAxis3D:{nameTextStyle:{fontSize:11,color:"#6c757d"},axisLabel:{fontSize:9,color:"#6c757d",formatter:h=>n?`1e${Math.round(h)}`:gr(h)}},grid3D:{boxWidth:100,boxDepth:100,boxHeight:62,axisPointer:{show:!1},light:{main:{intensity:c?.45:1.15,shadow:!1,alpha:40,beta:40},ambient:{intensity:c?.85:.35}},viewControl:{alpha:24,beta:40,distance:190,damping:.85,autoRotate:!1,zoomSensitivity:1,...a||{}},environment:"#ffffff"},series:[{wireframe:{show:!1},shading:"lambert"}]}}function Xl(t,e){return{x:e.clientX-t.left,y:e.clientY-t.top}}function ql(t){if(!t||!t.addEventListener)return()=>{};const e=["touchstart","touchmove","touchend"],n=r=>{const i=r.changedTouches&&r.changedTouches[0];if(!i)return;const s=i.target&&i.target.getBoundingClientRect?i.target:t,{x:l,y:o}=Xl(s.getBoundingClientRect(),i);try{Object.defineProperty(r,"offsetX",{value:l,configurable:!0}),Object.defineProperty(r,"offsetY",{value:o,configurable:!0})}catch{}};for(const r of e)t.addEventListener(r,n,!0);return()=>{for(const r of e)t.removeEventListener(r,n,!0)}}let Me=!1;const bn="aggapi.chartView.v5",yr="aggapi.chartView.v4",le={panels:{},kind:null,mesh:!0,wallGrid:!0,marginals:!1,contours:!0,lights:!0,cut:"none",cutX:.5,cutY:.5,cutS:.5,windows:{}},Vl=["mesh","wallGrid","marginals","contours","lights","cut","cutX","cutY","cutS"],Kl=["mesh","wallGrid","marginals","contours","cut","cutX","cutY","cutS"],Ke=["none","components","total","all"],xr={none:"off",components:"x,y",total:"x+y",all:"all"},wr={linear:"lin",gamma:"gam",log:"log"},Zl=13e3,br=50;let ut=(()=>{try{const t=localStorage.getItem(bn);if(t!==null)return{...le,...hr(JSON.parse(t))};const e=localStorage.getItem(yr);if(e===null)return{...le};const n={...le,...Tl(hr(JSON.parse(e)))};return localStorage.setItem(bn,JSON.stringify(n)),localStorage.removeItem(yr),n}catch{return{...le}}})();function Vt(t,e=!0){if(ut={...ut,...t},!!e)try{localStorage.setItem(bn,JSON.stringify(ut))}catch{}}function _i(t,e=null){return{...oi,...e||{},...(ut.panels||{})[t]||{}}}function Ut(t,e,n=!0){Vt({panels:{...ut.panels||{},[t]:{...(ut.panels||{})[t]||{},...e}}},n)}function Wt(t){return{...ut,..._i(t)}}function vr(t){const e=(t&&t.panels||[]).find(n=>n.kind==="surface"||n.kind==="heatmap");return e?e.id:null}function Si(t,e){const n=t[0].toUpperCase()+t.slice(1);if(t.includes(":"))return`${n}. ${e}`;const r=e[1]&&e[1]===e[1].toLowerCase()?e[0].toLowerCase()+e.slice(1):e;return`${n}: ${r}`}function Ze(t){return t.short?{text:t.short,title:Si(t.label,t.title)}:{text:t.label,title:t.title}}function Jl(t){return t.length<2?t.join(""):`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function Ql(t,e,n){const r=e?`${e}, on this panel's ${t} axis,`:`This panel's ${t} axis`,i=Jl([n.reflect&&"reflect",n.returnPeriod&&"the return period",n.invert&&"invert"].filter(Boolean)),s=i?` ${i[0].toUpperCase()}${i.slice(1)} put a different axis under this button.`:"";return`${r} declares a single reading, so there is no log to switch to.${s}`}const ta=[{key:"logX",label:"log x",title:"Read this panel's horizontal axis on log, where it offers a log reading. Which axes do is the document's statement, not a setting here, and it acts on this panel alone"},{key:"logY",label:"log y",title:"Read this panel's vertical axis on log, where it offers a log reading. A density ordinate is uncropped on the way there, because room for a spike is the whole point of asking"},{key:"fullRange",label:"full range",short:"range",title:"Draw this panel's axes over the whole extent they declare, instead of the window the library suggested. On a return period that opens the ladder past 1-in-10,000 to the deep tail"},{key:"reflect",label:"reflect",title:"Read this panel's probability axis as its complement, 1 - v. A distribution function reflected is the survival function; with the return period it opens out the other end of the curve"},{key:"returnPeriod",label:"return period",short:"ret prd",title:"Read this panel's probability axis as the return period it pairs with: the same curve, interrogated at 1-in-200 rather than at 0.995"},{key:"invert",label:"invert",title:"Exchange this panel's axes, where it says they exchange. A quantile plot inverted is the distribution function"},{key:"refLines",offer:"marks",label:"reference lines",short:"marks",title:"Show the marks this panel carries, the mean and break even, drawn where the document puts them"}],_r=[{key:"contours",panel:!0,label:"contours",title:"Contour lines at eight levels. In relief they run on the surface and on the floor image at the same levels, which is what makes the two read as one drawing; flat, they run over the image",flat:!0},{key:"marginals",panel:!0,label:"marginals",title:"Draw each component's own distribution on the wall behind it. These are the library's exact marginals, not an integral of what is on screen, so they do not move when the window does"},{key:"mesh",panel:!0,label:"mesh",title:"The grid over the skin, every sixth line. Off leaves a bare surface, which reads the shape more cleanly and the resolution not at all"},{key:"wallGrid",panel:!0,label:"wall grid",short:"walls",title:"Grid lines on the three walls of the box"},{key:"lights",label:"lights",title:"Light the surface from all around, so no face of it is dark. The color is the height here, so a key light strong enough to shade one side into darkness is a second encoding fighting the first. Off is one hard key light, which reads the relief more sculpturally and the color less well"}],Sr={xy:"curves",heatmap:"flat",surface:"3D"},ea={distortion:{panels:1,square:!0},joint_surface:{panels:1,square:!0,colorbar:!0},envelope:{panels:2,square:!0}},na={panels:2,square:!1};function ra(t,e,n){const r=ea[e]||na,i=ci(r.panels,r.square,n,r.colorbar?78:0);Mt(t),t.style.position="relative",t.style.height=`${i.hostHeight}px`;const s=T("div",{className:"exhibit-skeleton"});for(const l of i.grids)s.appendChild(T("div",{className:"exhibit-skeleton-panel",style:`left:${l.left}px; top:${l.top}px;width:${l.width}px; height:${l.height}px`},T("i",{className:"bi bi-graph-up","aria-hidden":"true"})));return t.appendChild(s),i}function ia(t){return T("div",{className:"text-muted small fst-italic"},t||"This chart is not published by the library yet.")}function Ac(){return ia("This chart could not be fetched. That is a request failure rather than a gap in what the library publishes, so it is worth trying again.")}function Ai(t,e,n){const r=(a,c,u)=>c>a?Math.min(1,Math.max(0,(u-a)/(c-a))):.5,[i,s]=t.x,[l,o]=t.y;return{cutX:r(i,s,e),cutY:r(l,o,n),cutS:r(i+l,s+o,e+n)}}function sa(t,e){const n=Math.max(t.x[0],t.y[0]),r=Math.min(t.x[1],t.y[1]);if(!(r>n))return{cutX:e,cutY:e,cutS:e};const i=n+(r-n)*e;return Ai(t,i,i)}function oa(t,e){const n=T("label",{className:"exhibit-window"},"window "),r=T("input",{type:"number",min:"0",max:"12",step:"0.5",className:"form-control form-control-sm exhibit-window-input",title:"How deep to cut the quantile window: keep q(10^-w) to q(1 - 10^-w) of each component. 0 keeps the whole grid. The library chooses the grid from this before it reduces, so a deeper window is finer, not cropped"}),i=(ut.windows||{})[t];r.value=Number.isFinite(i)?String(i):"",r.placeholder="auto";let s=null;return r.addEventListener("input",()=>{s&&clearTimeout(s),s=setTimeout(()=>{const l=r.value.trim(),o=l===""?null:Number(l);l!==""&&!(o>=0&&o<=12)||(Vt({windows:Cl(ut.windows,t,o)}),e())},90)}),n.appendChild(r),n}function la(t,e){const n=!!(ut.lee||{})[t],r=T("button",{type:"button",className:`exhibit-toggle${n?" active":""}`,title:"Draw the quantile curve each tower is read against beside it, on the same loss axis, so every attachment and exhaustion point reads off as a return period",onClick:()=>{Vt({lee:kl(ut.lee,t,!n)}),r.classList.toggle("active",!n),e()}},"quantiles");return r}function aa(t,e){const n=T("button",{type:"button",className:"exhibit-toggle"},"spacemouse"),r=()=>{const i=de();n.classList.toggle("active",i),n.disabled=!ze(),n.setAttribute("aria-disabled",n.disabled?"true":"false"),n.title=n.disabled?"This browser has no WebHID, so a 6DOF puck cannot be reached from a page. Chrome or Edge on the desktop can. The .obj download is the way in on every other browser: 3Dconnexion's own viewer navigates it natively":i?`Connected to ${Gr()}. Twist to orbit, tilt to raise the camera, push and pull to zoom, slide to pan. The left button puts the view back, the right one swaps perspective and orthographic. Click to let the device go`:"Drive the relief with a 3Dconnexion SpaceMouse. One grant per browser: after that it reattaches silently. Mouse dragging keeps working throughout"};return r(),e(xs(r)),n.addEventListener("click",()=>{t().then(r,r)}),n}function ca(t,e,n){const r=n(),i=T("div",{className:"dropdown"}),s=T("button",{type:"button",className:"exhibit-toggle dropdown-toggle","data-bs-toggle":"dropdown","aria-expanded":"false",title:r?"Save what is on screen. The file is the box you are looking at, so the log reading and the proportions come with it":"Nothing is drawn yet, so there is nothing to save","aria-disabled":r?"false":"true"},"Download");s.disabled=!r,i.appendChild(s);const l=T("ul",{className:"dropdown-menu"});for(const{ext:o,label:a,why:c}of t)l.appendChild(T("li",{},T("button",{type:"button",className:"dropdown-item",title:c,onClick:()=>e(o)},a)));return i.appendChild(l),i}function ua(t){const e=T("div",{className:"dropdown"});e.appendChild(T("button",{type:"button",className:"exhibit-toggle dropdown-toggle","data-bs-toggle":"dropdown","data-bs-auto-close":"outside","aria-expanded":"false",title:"The relief's occasional controls: the walk, and how deep a window the drawing is fetched over"},"relief"));const n=T("ul",{className:"dropdown-menu exhibit-menu"});for(const r of t)n.appendChild(T("li",{},r));return e.appendChild(n),e}const Ar={ext:"png",label:"PNG image",why:"The chart exactly as drawn, at twice the screen resolution, including every toggle and zoom since it was drawn"},fa=[{ext:"glb",label:"GLB mesh",why:"One file, colored by height in the chart's own viridis, which is what makes it read as the picture rather than as a gray sheet"},{ext:"obj",label:"OBJ mesh",why:"Geometry only, which every viewer and Blender read. This is the way in for a 6DOF puck on a browser with no WebHID: 3Dconnexion's own viewer navigates it natively"},{ext:"stl",label:"STL mesh",why:"Geometry only, and the format a slicer wants. Masked cells are holes rather than invented geometry, so it is a surface and not a solid"}];function ha(t,e){const{chart:n,onChange:r,onReset:i,onRefetch:s,walking:l,onWalk:o,onExport:a,canExport:c,onSpaceMouse:u,register:f,width:h}=e,d=Ln(t),w=T("div",{className:"exhibit-controls"}),S=(h?h():0)<ae;w.classList.add(S?"exhibit-controls-stacked":"exhibit-controls-aligned");const N=T("div",{className:"exhibit-footer"}),W=[],z=ut.kind||zt(t),F=(t.panels||[]).some(g=>g.kind==="surface"||g.kind==="heatmap"),L=(t&&t.panels||[]).some(g=>g.kind==="tower"),B=t&&t.panels||[];for(const g of d.panels){const y=T("div",{className:"exhibit-group exhibit-group-panel"});y.dataset.panel=String(B.findIndex(I=>I.id===g.id)),(S||L)&&d.panels.length>1&&g.title&&y.appendChild(T("span",{className:"exhibit-group-label"},g.title));const M=B.find(I=>I.id===g.id),G=dn(t,M),P=()=>_i(g.id,G),H=[];for(const I of ta){if(!g[I.offer||I.key])continue;const{text:A,title:b}=Ze(I),C=T("button",{type:"button",className:`exhibit-toggle${P()[I.key]?" active":""}`,title:b,onClick:()=>{Ut(g.id,{[I.key]:!P()[I.key]}),C.classList.toggle("active",!!P()[I.key]),X(),r()}},A);(I.key==="logX"||I.key==="logY")&&H.push({spec:I,btn:C,title:b}),y.appendChild(C)}const X=()=>{if(!M||!H.length)return;const I=yo(t,M,P());for(const{spec:A,btn:b,title:C}of H)b.disabled=!I[A.key],b.setAttribute("aria-disabled",b.disabled?"true":"false"),b.title=b.disabled?Ql(A.key==="logX"?"horizontal":"vertical",A.key==="logX"?I.xLabel:I.yLabel,g):C};if(X(),M&&(M.kind==="surface"||M.kind==="heatmap")){const I=()=>Bs(Rn(t,M,P(),(ut.kind||zt(t))==="surface")),A=T("button",{type:"button",className:`exhibit-toggle${I()!=="linear"?" active":""}`,title:Si(`color: ${I()}`,"How value maps to color on this panel. Gamma lifts the faint structure a linear ramp buries under the peak; log resolves the deep decades. The values, the tooltips and the colorbar's numbers never change, only where the colors sit along the bar"),onClick:()=>{const b=["linear","gamma","log"],C=b[(b.indexOf(I())+1)%b.length];Ut(g.id,{stretch:C}),A.textContent=`c: ${wr[C]}`,A.classList.toggle("active",C!=="linear"),r()}},`c: ${wr[I()]||I()}`);y.appendChild(A);for(const b of _r){if(!b.panel||z!=="surface"&&!b.flat)continue;const{text:C,title:j}=Ze(b),K=T("button",{type:"button",className:`exhibit-toggle${Wt(g.id)[b.key]?" active":""}`,title:j,onClick:()=>{Ut(g.id,{[b.key]:!Wt(g.id)[b.key]}),K.classList.toggle("active",!!Wt(g.id)[b.key]),r()}},C);y.appendChild(K)}if(z==="surface"){const b=Wt(g.id).cut,C=T("button",{type:"button",className:`exhibit-toggle${b!=="none"?" active":""}`,title:"Cut the joint and read the conditional it leaves, drawn on the wall beside the marginal it should be compared with. Cycles off, then x,y with each component held in turn, then x+y on the total, where the two means are kappa, then all three at once",onClick:()=>{const j=Wt(g.id).cut,K=Ke[(Ke.indexOf(j)+1)%Ke.length];Ut(g.id,{cut:K}),C.textContent=`cut: ${xr[K]}`,C.classList.toggle("active",K!=="none"),r()}},`cut: ${xr[b]||b}`);y.appendChild(C)}}y.querySelector("button")&&W.push(y)}for(const g of W)w.appendChild(g);if(F&&(z==="surface"||z==="heatmap"))for(const g of _r){if(g.panel||z!=="surface"&&!g.flat)continue;const{text:y,title:M}=Ze(g),G=T("button",{type:"button",className:`exhibit-toggle${ut[g.key]?" active":""}`,title:M,onClick:()=>{Vt({[g.key]:!ut[g.key]}),G.classList.toggle("active",!!ut[g.key]),r()}},y);N.appendChild(G)}if(F&&z==="surface"){const g=T("button",{type:"button",className:`exhibit-toggle${l()?" active":""}`,title:"Walk the cuts out along the diagonal, the total rising steadily, and watch where the split falls against an even one",onClick:()=>{o(),g.classList.toggle("active",l())}},"walk");N.appendChild(aa(u,f)),N.appendChild(ua([g,...s?[oa(n,s)]:[]]))}(t.panels||[]).some(g=>g.kind==="tower")&&s&&N.appendChild(la(n,s));for(const g of d.kinds){const M=T("button",{type:"button",className:`exhibit-toggle${(ut.kind||zt(t))===g?" active":""}`,title:`Draw the grid as ${Sr[g]||g}`,onClick:()=>{Vt({kind:g}),r()}},Sr[g]||g);N.appendChild(M)}const p=F&&z==="surface";return N.appendChild(ca(p?[Ar,...fa]:[Ar],a,p?c:()=>!0)),N.appendChild(T("button",{type:"button",className:"exhibit-toggle",title:"Back to the default view: the full range, and the camera with it on a surface",onClick:()=>i&&i()},"reset")),{row:w,figure:N,groups:W}}function zt(t){return(t&&t.panels||[]).some(n=>n.kind==="surface")?"surface":null}async function Mc(t,e){Mt(t);const n=T("div"),r=T("div",{className:"exhibit-canvas"});t.appendChild(r),t.appendChild(n),ra(r,e.chart,r.clientWidth||0);const i=vi(ut,e.chart);let s;try{const[l]=await Promise.all([he.chartDoc(e.id,e.chart,i),Hs().catch(()=>null)]);s=l}catch{if(s=Object.keys(i).length?await he.chartDoc(e.id,e.chart,{}).catch(()=>null):null,!s)throw Mt(t),new Error("chart document could not be fetched")}return Mi(t,n,r,s,e)}function Ec(t,e){Mt(t);const n=T("div"),r=T("div",{className:"exhibit-canvas"});return t.appendChild(r),t.appendChild(n),Mi(t,n,r,e)}function Mi(t,e,n,r,i=null){if(!r)return Mt(t),null;const s=T("div",{className:"chart-readout"});t.insertBefore(s,e);let l=null,o=null,a=null,c=!1,u=!1,f=null,h=null;const d=()=>({view:{...ut,kind:ut.kind||zt(r)},width:n.clientWidth||0,zoom:l,camera:h,overrides:da(r)});function w(){const m=cr(r,d());return m?m.is3d&&!Me?cr(r,{...d(),view:{...ut,kind:"heatmap"}}):m:null}const S=new Set;let N=null;function W(){const m=a&&a.cellReader;return m?m(N):[]}function z(m){Mt(s);const E=m&&m.where||[],_=m&&m.leaves||[],v=W();if(!v.length&&!E.length&&!_.length){s.appendChild(T("span",{className:"chart-readout-head is-idle"},"click the surface to cut it and read the cell"));return}for(const $ of[v,E,_]){if(!$.length)continue;const Z=T("div",{className:"chart-readout-line"});for(const x of $){const Y=T("span",{className:"chart-readout-item",title:x.hint||x.name});x.color&&Y.appendChild(T("i",{className:"chart-readout-swatch",style:`background:${x.color}`,"aria-hidden":"true"})),Y.appendChild(T("span",{className:"chart-readout-name"},x.name)),Y.appendChild(T("b",{},x.value)),Z.appendChild(Y)}s.appendChild(Z)}}function F(m){if(a&&a.is3d)return;Mt(s);const E=a&&a.legendItems||[];if(!E.length)return;const _=new Map((m?m.rows:[]).map(v=>[v.name,v.value]));s.appendChild(T("span",{className:`chart-readout-head${m?"":" is-idle"}`},m?m.head:"hover to read"));for(const v of E){const $=S.has(v.name),Z=T("button",{type:"button",className:`chart-readout-item${$?" is-off":""}`,title:`${$?"Show":"Hide"} ${v.name}`,onClick:()=>L(v.name)});Z.appendChild(T("i",{className:"chart-readout-swatch",style:`background:${v.color}`,"aria-hidden":"true"})),Z.appendChild(T("span",{className:"chart-readout-name"},v.name)),Z.appendChild(T("b",{},_.get(v.name)||"")),s.appendChild(Z)}}function L(m){const E=o&&o.chart;if(!E)return;const _=S.has(m);_?S.delete(m):S.add(m),E.dispatchAction({type:_?"legendSelect":"legendUnSelect",name:m}),F(null)}function B(m){return!m.readout||!m.tooltip||(m.tooltip={...m.tooltip,showContent:!0,extraCssText:"display:none!important",formatter:E=>(F(m.readout(E)),"")}),m}function p(m){const E=o&&o.chart;if(!E)return;const _=E.getDataURL({type:"png",pixelRatio:2,backgroundColor:"#fff"}),v=T("a",{href:_,download:`${m}.png`});document.body.appendChild(v),v.click(),v.remove()}function g(m){const E=a&&a.meshSource;if(!E)return;let _;try{_=bl(E,{box:E.box,zRange:E.zRange})}catch{return}const v=ur(E.name),$={glb:[()=>Ml(_,v,{ramp:E.ramp||un,colorRange:E.colorRange}),"model/gltf-binary"],obj:[()=>El(_,v),"text/plain"],stl:[()=>Sl(_,v),"model/stl"]},[Z,x]=$[m]||$.stl,Y=Z(),O=URL.createObjectURL(new Blob([Y],{type:x})),D=T("a",{href:O,download:`${v}-surface.${m}`});document.body.appendChild(D),D.click(),D.remove(),setTimeout(()=>URL.revokeObjectURL(O),0)}const M=Wl({read:()=>{const m=o&&o.chart;return c&&m&&a&&a.is3d?mr(m):null},write:m=>{const E=o&&o.chart;!c||!E||E.setOption({grid3D:{viewControl:{...m,animation:!1}}})},reset:()=>{c&&ot()},setProjection:m=>{const E=o&&o.chart;!c||!E||E.setOption({grid3D:{viewControl:{projection:m,animation:!1}}})}}),G=ys(m=>M.input(m));let P=!1,H=[],X=!1;function I(){const m=!!(a&&a.meshSource);m!==X&&(X=m,it())}function A(){o&&o.chart&&(h=mr(o.chart)||h);const m=w();if(!m)return!1;a=B(m),n.style.height=`${m.hostHeight}px`,o?o.update(m):(Mt(n),o=pa(n,m)),b(),m.is3d&&z(m.cutReadout),m.is3d&&!P&&(P=!0,qr().catch(()=>{}));for(const E of S)o.chart.dispatchAction({type:"legendUnSelect",name:E});return F(null),I(),K(),!0}function b(){const m=o&&o.chart;if(!m)return;m.off("globalout"),m.on("globalout",()=>F(null)),m.off("click"),m.on("click",_=>{const v=a&&a.surfaceBox,$=_&&_.value;if(!v||!Array.isArray($)||$.length<2||!Number.isFinite($[0])||!Number.isFinite($[1]))return;pt(!1),N=$;const Z=vr(r);if(!Z)return;const x=Ai(v,$[0],$[1]);Ut(Z,x),A()});const E=m.getZr();E.off("dblclick"),E.on("dblclick",()=>{c&&ot()}),!(!a||!a.lossWindow)&&(m.off("dataZoom"),m.on("dataZoom",()=>{const _=a&&a.lossWindow;if(!_||!(_[1]>_[0]))return;const v=(m.getOption().dataZoom||[])[0];if(!v||v.start==null)return;const $=_[1]-_[0],x=v.start<=0&&v.end>=100?null:[_[0]+$*v.start/100,_[0]+$*v.end/100];l=x,el(a,x)!==(a.rung||{}).drawnAs&&A()}))}let C=ut.kind||zt(r),j=null;function K(){if(!j)return;const m=a&&a.extent,E=a&&a.columns||[],_=(n.clientWidth||0)>=ae;if(m&&(s.style.paddingLeft=`${m.left}px`,j.figure.style.marginLeft=`${m.left}px`,j.figure.style.width=`${m.width}px`),!_){j.row.style.paddingLeft=m?`${m.left}px`:"";for(const $ of j.groups)$.style.left="",$.style.width="";j.row.style.minHeight="";return}j.row.style.paddingLeft="";let v=0;for(const $ of j.groups){const Z=E[Number($.dataset.panel)];Z&&($.style.left=`${Z.left}px`,$.style.width=`${Z.width}px`,v=Math.max(v,$.offsetHeight))}j.row.style.minHeight=v?`${v}px`:""}function it(){for(const m of H)m();H=[],Mt(e),j=ha(r,{chart:i?i.chart:null,onChange:()=>{c&&nt()},onReset:()=>{c&&ot()},onRefetch:i?()=>{c&&ft()}:null,walking:()=>u,onWalk:()=>pt(!u),onExport:m=>m==="png"?p(ur(r.title||i&&i.chart||"chart")):g(m),canExport:()=>!!(a&&a.meshSource),onSpaceMouse:()=>de()?vs():bs(),register:m=>H.push(m),width:()=>n.clientWidth||0}),e.appendChild(j.row),e.appendChild(j.figure),K()}if(it(),!A())return Mt(t),null;async function nt(){const m=ut.kind||zt(r);m==="surface"&&!Me&&await Gl()&&(Me=!0),m!==C&&(C=m,it()),A()}function ot(){if(pt(!1),l=null,(ut.kind||zt(r))==="surface"){const m={};for(const _ of Vl)m[_]=le[_];const E={};for(const[_,v]of Object.entries(ut.panels||{})){const $={...v};for(const Z of Kl)delete $[Z];E[_]=$}Vt({...m,panels:E}),o&&(o.dispose(),o=null)}it(),A()}async function ft(){if(!i)return;let m;try{m=await he.chartDoc(i.id,i.chart,vi(ut,i.chart))}catch{return}if(!c||!m)return;const E=(r&&r.panels||[]).length!==(m.panels||[]).length;r=m,o&&(o.dispose(),o=null),E&&it(),A()}function pt(m){if(u===m)return;const E=vr(r);if(m&&!E)return;if(u=m,!m){f&&clearInterval(f),f=null,Vt({});return}Wt(E).cut==="none"&&Ut(E,{cut:"all"});let _=0;f=setInterval(()=>{const v=a&&a.surfaceBox,$=o&&o.chart;if(!u||!c||!v||!$)return;_=(_+br/Zl)%1,Ut(E,sa(v,_),!1);const Z=xl(a,Wt(E));if(!Z){A();return}$.setOption({series:Z.series},!1),z(Z.readout)},br)}c=!0,!Me&&(ut.kind||zt(r))==="surface"&&nt();let R=n.clientWidth||0;const U=new ResizeObserver(()=>{const m=n.clientWidth||0;if(Math.abs(m-R)<=8)return;const E=m<ae!=R<ae;R=m,c&&(E&&it(),A())});return U.observe(n),{get option(){return a},dispose(){c=!1,pt(!1),G(),M.dispose();for(const m of H)m();H=[];try{U.disconnect()}catch{}o&&o.dispose()},get chart(){return o&&o.chart}}}function da(t){return(t.panels||[]).some(n=>n.kind!=="xy")?n=>n.logZ===void 0?null:Yl({...n,lights:ut.lights!==!1}):null}function pa(t,e){let n=!!e.is3d,r=zn(t,null,{renderer:"canvas"});const i=ql(t);return r.setOption(e),Mr(r,e),{engine:"echarts",get chart(){return r},update(s){const l=!!s.is3d;if(l!==n){n=l;try{r.dispose()}catch{}r=zn(t,null,{renderer:"canvas"})}r.setOption(s,!0),r.resize(),Mr(r,s)},dispose(){i();try{r.dispose()}catch{}}}}function Mr(t,e){const n=e.series||[];if(n.length<2)return;const r=new Map;n.forEach((s,l)=>{s.name&&(r.has(s.name)||r.set(s.name,[]),r.get(s.name).push(l))});let i=!1;t.off("highlight"),t.on("highlight",s=>{if(i)return;const{seriesIndex:l,dataIndex:o}=s;if(l==null||o==null)return;const a=(n[l]||{}).name,c=(r.get(a)||[]).filter(u=>u!==l);if(c.length){i=!0;try{for(const u of c)t.dispatchAction({type:"highlight",seriesIndex:u,dataIndex:o})}finally{i=!1}}})}function ma(t){return(t??"").replace(/^\uFEFF/,"").replace(/^(?:[ \t]*(?:\r\n|\n|\r))+/,"")}function ga(t){let e=[","," ",";","|"],n=t.split(/\r\n|\n|\r/,20).filter(s=>s.length),r=",",i=0;for(let s of e){let l=n.map(c=>ya(c,s).length),o=l[0];if(o<2)continue;let a=o*(l.every(c=>c===o)?10:1);a>i&&(i=a,r=s)}return r}function ya(t,e){let n=[],r="",i=!1;for(let s=0;s<t.length;s++){let l=t[s];i?l==='"'?i=!1:r+=l:l==='"'?i=!0:l===e?(n.push(r),r=""):r+=l}return n.push(r),n}function xa(t,e){let n=[],r=[],i="",s=!1,l=0,o=t.length;for(;l<o;){let a=t[l];if(s){if(a==='"'){if(t[l+1]==='"'){i+='"',l+=2;continue}s=!1,l++;continue}i+=a,l++;continue}if(a==='"'){s=!0,l++;continue}if(a===e){r.push(i),i="",l++;continue}if(a==="\r"||a===`
5
+ `){r.push(i),i="",n.push(r),r=[],a==="\r"&&t[l+1]===`
6
+ `&&l++,l++;continue}i+=a,l++}for((i.length||r.length)&&(r.push(i),n.push(r));n.length&&n[n.length-1].every(a=>a.trim()==="");)n.pop();return n}function ke(t){t=t.trim(),t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&!t.endsWith("\\|")&&(t=t.slice(0,-1));let e=[],n="";for(let r=0;r<t.length;r++){let i=t[r];i==="\\"&&t[r+1]==="|"?(n+="|",r++):i==="|"?(e.push(n),n=""):n+=i}return e.push(n),e.map(r=>r.trim())}var wa=/^:?-+:?$/;function ba(t){let e=t.split(/\r\n|\n|\r/).filter(r=>r.trim()!=="");if(e.length<2||!e[0].includes("|"))return!1;let n=ke(e[1]);return n.length>0&&n.every(r=>wa.test(r))}function va(t){let e=t.split(/\r\n|\n|\r/).filter(i=>i.trim()!==""),n=ke(e[0]).map((i,s)=>i||`col${s+1}`),r=ke(e[1]).map(i=>{let s=i.startsWith(":"),l=i.endsWith(":");return s&&l?"center":l?"right":s?"left":null});for(;r.length<n.length;)r.push(null);return{headers:n,rows:e.slice(2).filter(i=>i.includes("|")).map(i=>{let s=ke(i).slice(0,n.length);for(;s.length<n.length;)s.push("");return s}),aligns:r}}var vn=/[$£€¥¥]/,_a=/^\(?(?:[+-]?[$£€¥¥]?|[$£€¥¥][+-]?)(?:[0-9][0-9,]*(?:\.[0-9]+)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?%?\)?$/,Sa=/^\(?[+-]?(?:inf(?:inity)?|∞)\)?$/i,Aa=/^(\d{4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?Z?)?$/,Ei=/^(\d{1,4})([\/\-.])(\d{1,2})\2(\d{1,4})$/,Ma=/^(\d{1,2})[ \-]([A-Za-z]{3,9})\.?,?[ \-](\d{2,4})$/,Ea=/^([A-Za-z]{3,9})\.?,?[ \-](\d{1,2}),?[ \-](\d{2,4})$/,Ca=["january","february","march","april","may","june","july","august","september","october","november","december"],ka=new Set(["nan","na","n/a","#n/a","null","none","-","--","."]);function ee(t){return ka.has((t??"").trim().toLowerCase())}function Oe(t){if(t=t.trim(),Sa.test(t)){let f=t;return f.startsWith("(")&&f.endsWith(")")&&(f="-"+f.slice(1,-1)),{v:f.startsWith("-")?-1/0:1/0,dec:0}}if(!_a.test(t))return null;let e=!1;t.startsWith("(")&&t.endsWith(")")&&(e=!0,t=t.slice(1,-1));let n="",r=vn.exec(t);r&&(n=r[0],t=t.replace(vn,""));let i=!1;t.endsWith("%")&&(i=!0,t=t.slice(0,-1)),t=t.replace(/,/g,"");let s=parseFloat(t);if(!isFinite(s))return null;e&&(s=-s),i&&(s/=100);let l=/^([^eE]*)[eE]([+-]?\d+)$/.exec(t),o=l?l[1]:t,a=l?+l[2]:0,c=o.indexOf("."),u=Math.max(0,(c<0?0:o.length-c-1)-a);return i&&(u+=2),{v:s,dec:u,sym:n}}var La="9007199254740991";function $a(t){return t=t.trim(),t.endsWith("%")||(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t=t.replace(/[$£€¥¥,]/g,"").replace(/^[+-]/,""),!/^\d+$/.test(t))?!1:(t=t.replace(/^0+(?=\d)/,""),t.length>16||t.length===16&&t>La)}function Er(t){let e=t.toLowerCase(),n=Ca.findIndex(r=>r.startsWith(e)||e==="sept"&&r==="september");return n<0||e.length<3?null:n+1}function Je(t){return t=+t,t<100?t<50?2e3+t:1900+t:t}function Ot(t,e,n,r=0,i=0,s=0,l=0,o=!1){let a=new Date(t,e-1,n,r,i,s,l);return a.getFullYear()!==t||a.getMonth()!==e-1||a.getDate()!==+n?null:{t:a.getTime(),hasTime:o}}function ue(t,e=!1){t=t.trim();let n=Aa.exec(t);if(n){let[,r,i,s,l,o,a,c]=n,u=c?Math.round(("0."+c)*1e3):0;return Ot(+r,+i,+s,+(l||0),+(o||0),+(a||0),u,l!==void 0)}if(n=Ei.exec(t),n){let[,r,,i,s]=n;if(r.length===4&&s.length<=2)return Ot(+r,+i,+s);if(r.length<=2&&(s.length===4||s.length===2)){let l=Je(s);return+r>12&&+i<=12?Ot(l,+i,+r):+i>12&&+r<=12?Ot(l,+r,+i):e?Ot(l,+i,+r):Ot(l,+r,+i)}return null}if(n=Ma.exec(t),n){let r=Er(n[2]);return r?Ot(Je(n[3]),r,+n[1]):null}if(n=Ea.exec(t),n){let r=Er(n[1]);return r?Ot(Je(n[3]),r,+n[2]):null}return null}function Ta(t){let e=Ei.exec(t.trim());if(!e)return null;let n=e[1],r=e[3],i=e[4];return n.length===4||!(i.length===4||i.length===2)?null:+n>12&&+r<=12?"day":+r>12&&+n<=12?"month":+n<=12&&+r<=12?"ambiguous":null}function Ra(t){return t.some(e=>{let n=(e??"").trim();return n!==""&&(Oe(n)!==null||ue(n)!==null)})}function Na(t){let e=i=>i.type==="date"?"Date":i.type==="number"?i.format==="year"?"Year":"Amount":"Description",n={},r={};t.forEach(i=>{let s=e(i);n[s]=(n[s]||0)+1}),t.forEach(i=>{let s=e(i);r[s]=(r[s]||0)+1,i.name=n[s]>1?`${s} ${r[s]}`:s})}var Ia=/\b(year|yr|vintage|cohort)\b/i,Qe=/\b(amount|amt|balance|bal|price|cost|fee|fees|charge|paid|payment|debit|credit|total|premium|loss|salary|wage|income|expense|revenue|usd|gbp|eur|cad)\b|[$£€]/i,Oa=/\b(id|no|num|number|account|acct|code|zip|postal|phone|fax|ssn|ein|tin|invoice|inv|ref|reference|sku|upc|isbn|order|customer|cust|member|policy|claim|seq)\b/i,Fa=/(?<![a-z])(ratio|rate|roe|roa|coc|lr|elr|plr|margin|yield|return|growth|retention|cede|ceded|discount|apr|apy|coupon|util|utilization|share|pct|percent|frequency)(?![a-z])/i;function za(t,e,n,r=!1){if(r)return{format:"float",dec:2};let i=e.filter(u=>u!==null);if(i.every(u=>Number.isInteger(u))&&i.length)return Ia.test(t)||i.every(u=>u>=1800&&u<=2100)?{format:"year",dec:0}:Oa.test(t)&&!Qe.test(t)?{format:"plain",dec:0}:Qe.test(t)?{format:"float",dec:2}:{format:"int",dec:0};let s=0,l=0,o=1/0,a=0;for(let u of i){if(u===0||!Number.isFinite(u))continue;let f=Math.abs(u);s++,f>l&&(l=f),f<o&&(o=f),a+=f}if(!s)return{format:"float",dec:Math.min(n,6)};if(Fa.test(t)&&l<=2)return{format:"pct",dec:Math.max(1,Math.min(4,n-2))};if(Qe.test(t)||n<=2&&l<1e5)return{format:"float",dec:2};if(l/o>1e6)return{format:"eng",dec:0};let c=a/s;return{format:"float",dec:Math.max(0,Math.min(n,3-Math.floor(Math.log10(c)),6))}}var Pa={"-9":"n","-6":"µ","-3":"m",0:"",3:"k",6:"M",9:"G",12:"T"};function _n(t){if(!Number.isFinite(t))return t>0?"inf":"-inf";if(t===0)return"0";let e=Math.abs(t),n=Math.floor(Math.log10(e)/3)*3;n=Math.max(-9,Math.min(12,n));let r=e/10**n;return(t<0?"-":"")+Number(r.toPrecision(3))+Pa[n]}function Ci(t,e){if(t<=e)return Array.from({length:t},(i,s)=>s);let n=Array(e),r=t/e;for(let i=0;i<e;i++)n[i]=Math.floor(i*r);return n}var ja=2048,Da=/^-?0\d/;function ki(t,e){let n=Ci(e.length,ja);return t.map((r,i)=>{let s=!0,l=!0,o=!1,a=!1,c=0;for(let u of n){let f=(e[u][i]??"").trim();if(!(f===""||ee(f))&&(c++,s&&(Oe(f)===null?s=!1:(!o&&Da.test(f)&&(o=!0),!a&&$a(f)&&(a=!0))),l&&ue(f,!1)===null&&(l=!1),o||a||!s&&!l))break}if(c===0||o||a)return a?{name:r,type:"text",align:"right",values:null}:{name:r,type:"text",values:null};if(s){let u=Array(e.length).fill(null),f=0,h=!1;for(let w=0;w<e.length;w++){let S=(e[w][i]??"").trim();if(S===""||ee(S))continue;let N=Oe(S);N&&(u[w]=N.v,N.dec>f&&(f=N.dec),N.sym&&(h=!0))}let d=za(r,u,f,h);return{name:r,type:"number",format:d.format,dec:d.dec,hasCurrency:h,values:u}}if(l){let u=!1,f=!1,h=!1,d=!1,w=Array(e.length).fill(null);for(let F=0;F<e.length;F++){let L=(e[F][i]??"").trim();if(L===""||ee(L))continue;let B=ue(L,!1);B&&(w[F]=B.t,f||(f=B.hasTime));let p=Ta(L);p==="day"?(u=!0,d=!0):p==="month"?d=!0:p==="ambiguous"&&(h=!0)}if(u){w=Array(e.length).fill(null);for(let F=0;F<e.length;F++){let L=(e[F][i]??"").trim();if(L===""||ee(L))continue;let B=ue(L,!0);B&&(w[F]=B.t)}}let S=!1,N=!1,W=0;for(let F=0;F<w.length;F++){let L=w[F];if(L===null)continue;let B=new Date(L),p=B.getMilliseconds();if((B.getHours()||B.getMinutes()||B.getSeconds()||p)&&(S=!0),(B.getSeconds()||p)&&(N=!0),p){let g=p%100==0?1:p%10==0?2:3;g>W&&(W=g)}}let z=S?N?"second":"minute":"day";return{name:r,type:"date",hasTime:f,timePrec:{level:z,frac:z==="second"?W:0},ambiguousOrder:h&&!d,values:w}}return{name:r,type:"text",values:null}})}function Wa(t,e=null){let n,r,i=null,s;if(ba(t)){if({headers:n,rows:r,aligns:i}=va(t),s=e===!1,s&&(r=[n,...r],n=n.map((o,a)=>`col${a+1}`)),!r.length)throw Error("Markdown table has no data rows.")}else{let o=xa(t,ga(t));if(o.length<2)throw Error("Need a header row and at least one data row.");s=e===null?Ra(o[0]):!e,n=s?o[0].map((a,c)=>`col${c+1}`):o[0].map((a,c)=>a.trim()||`col${c+1}`),r=(s?o:o.slice(1)).map(a=>{if(a.length===n.length)return a;let c=a.slice(0,n.length);for(;c.length<n.length;)c.push("");return c})}let l=ki(n,r);return s&&Na(l),i&&l.forEach((o,a)=>{i[a]&&(o.align=i[a])}),{headers:l.map(o=>o.name),rows:r,cols:l,headerless:s}}var Cr=new Map;function fe(t){let e=Cr.get(t);return e||(e=new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t}),Cr.set(t,e)),e}function Ba(t,e){if(t==null||t==="")return null;if(/%[YymdHMSf%]/.test(t)){if(e==="number")throw Error(`CsvGrid: date format '${t}' on a number column`);return{kind:"datefmt",pattern:t}}if(t==="year"||t==="eng"){if(e==="date")throw Error(`CsvGrid: number format '${t}' on a date column`);return{kind:t}}let n=/^(,)?(?:\.(\d+))?([fd%esg])$/.exec(t);if(!n)throw Error(`CsvGrid: unrecognized format spec '${t}'`);if(e==="date")throw Error(`CsvGrid: number format '${t}' on a date column`);return{kind:n[3],comma:!!n[1],dec:n[2]===void 0?null:+n[2]}}function Ha(t,e){let n=r=>String(r).padStart(2,"0");return e.replace(/%([YymdHMSf%])/g,(r,i)=>{switch(i){case"Y":return String(t.getFullYear());case"y":return n(t.getFullYear()%100);case"m":return n(t.getMonth()+1);case"d":return n(t.getDate());case"H":return n(t.getHours());case"M":return n(t.getMinutes());case"S":return n(t.getSeconds());case"f":return String(t.getMilliseconds()).padStart(3,"0");case"%":return"%"}})}var Ua=[[1e12,"T"],[1e9,"G"],[1e6,"M"],[1e3,"k"],[1,""],[.001,"m"],[1e-6,"µ"],[1e-9,"n"]];function kr(t){return t.includes(".")?t.replace(/\.?0+$/,""):t}function Ga(t){let[e,n]=t.split("."),r=e.replace(/\B(?=(\d{3})+(?!\d))/g,",");return n===void 0?r:`${r}.${n}`}function Ya(t,e){switch(e.kind){case"year":return String(t);case"eng":return _n(t);case"d":{let n=Math.round(t);return e.comma?fe(0).format(n):String(n)}case"f":{let n=e.dec??2;return e.comma?fe(n).format(t):t.toFixed(n)}case"%":{let n=e.dec??0,r=t*100;return(e.comma?fe(n).format(r):r.toFixed(n))+"%"}case"e":return t.toExponential(e.dec??2);case"g":{let n=Math.max(1,e.dec??6);if(t===0)return"0";let r=t.toExponential(n-1),i=r.indexOf("e"),s=+r.slice(i+1);if(s<-4||s>=n){let o=s<0?"-":"+",a=String(Math.abs(s)).padStart(2,"0");return`${kr(r.slice(0,i))}e${o}${a}`}let l=kr(t.toFixed(Math.max(0,n-1-s)));return e.comma?Ga(l):l}case"s":{if(e.dec===null||e.dec===void 0)return _n(t);if(t===0)return 0 .toFixed(e.dec);let n=Math.abs(t);for(let[r,i]of Ua)if(n>=r)return(t/r).toFixed(e.dec)+i;return(t/1e-9).toFixed(e.dec)+"n"}}}function Xa(t){return[...t].map(e=>({l:"left",r:"right",c:"center"})[e]??null)}function qa(t,e,n,r="auto"){if(t=(t??"").trim(),t==="")return"";if(r==="raw")return t;if(e.type==="number"){let i=e.values[n];if(i===null)return ee(t)?"":t;if(!Number.isFinite(i))return i>0?"inf":"-inf";if(e.fmt)return Ya(i,e.fmt);if(e.format==="year"||e.format==="plain")return String(i);if(e.format==="eng")return _n(i);if(e.format==="pct")return fe(e.dec).format(i*100)+"%";let s=fe(e.dec).format(i);if(e.hasCurrency){let l=vn.exec(t);if(l)return s[0]==="-"?"-"+l[0]+s.slice(1):l[0]+s}return s}if(e.type==="date"){let i=e.values[n];if(i===null)return ee(t)?"":t;let s=new Date(i);if(e.fmt?.kind==="datefmt")return Ha(s,e.fmt.pattern);let l=c=>String(c).padStart(2,"0"),o=`${s.getFullYear()}-${l(s.getMonth()+1)}-${l(s.getDate())}`,a=e.timePrec??{level:e.hasTime?"minute":"day",frac:0};if(a.level!=="day"&&(o+=` ${l(s.getHours())}:${l(s.getMinutes())}`,a.level==="second"&&(o+=`:${l(s.getSeconds())}`,a.frac>0))){let c=String(s.getMilliseconds()).padStart(3,"0");o+="."+c.slice(0,a.frac)}return o}return t}function Va(t,e){let n=s=>(s=(s??"")+"",/[",\r\n]/.test(s)?'"'+s.replace(/"/g,'""')+'"':s),r=s=>s.map(n).join(","),i=[r(t)];for(let s of e)i.push(r(s));return i.join(`\r
7
+ `)}function Ka(t,e,n=[]){let r=a=>((a??"")+"").replace(/\|/g,"\\|").replace(/\s*\r?\n\s*/g," "),i=a=>a==="right"?"---:":a==="center"?":--:":a==="left"?":---":"---",s=a=>"| "+a.map(r).join(" | ")+" |",l="|"+t.map((a,c)=>i(n[c])).join("|")+"|",o=[s(t),l];for(let a of e)o.push(s(a));return o.join(`
8
+ `)}function Za(t,e="file"){return(t||"").replace(/\.[^.\\/]+$/,"").replace(/[<>:"/\\|?*\x00-\x1f]/g,"").replace(/[. ]+$/,"").trim()||e}function Ja(t,e){if(!Array.isArray(t))throw Error("CsvGrid: records must be an array.");let n=l=>l==null||typeof l=="number"&&Number.isNaN(l)?"":String(l),r,i;if(t.length&&Array.isArray(t[0])){if(!e)throw Error("CsvGrid: columns are required with array-of-arrays records.");r=e.map(String),i=t.map(l=>r.map((o,a)=>n(l[a])))}else r=(e??Object.keys(t[0]??{})).map(String),i=t.map(l=>r.map(o=>n(l[o])));let s=ki(r,i);return{headers:r,rows:i,cols:s,headerless:!1}}function Qa(t){let e=[];for(let n of t.trim().split(/\s+/)){if(!n)continue;let r={kind:"fuzzy",negate:!1};n.startsWith("!")&&(r.negate=!0,r.kind="exact",n=n.slice(1)),n.startsWith("'")&&(r.kind="exact",n=n.slice(1)),n.startsWith("^")&&(r.kind="prefix",n=n.slice(1)),n.endsWith("$")&&(r.kind=r.kind==="prefix"?"exact":"suffix",n=n.slice(0,-1)),n&&(r.cs=/[A-Z]/.test(n),r.str=r.cs?n:n.toLowerCase(),e.push(r))}return e}var tc=/[\s_\-\/\\.,:;()[\]{}"']/;function ec(t,e){let n=e.length,r=t.length;if(r===0)return 0;if(r>n)return-1;let i=0,s=-1;for(let c=0;c<n;c++)if(e[c]===t[i]&&(i++,i===r)){s=c;break}if(s<0)return-1;i=r-1;let l=s;for(let c=s;c>=0&&!(e[c]===t[i]&&(l=c,i--,i<0));c--);let o=100-3*(s-l+1-r)-Math.min(l,20);i=0;let a=!1;for(let c=l;c<=s&&i<r;c++)e[c]===t[i]?((c===0||tc.test(e[c-1]))&&(o+=8),a&&(o+=4),a=!0,i++):a=!1;return o}function nc(t,e,n){let r=t.cs?n:e,i,s=0;switch(t.kind){case"exact":i=r.includes(t.str);break;case"prefix":i=r.startsWith(t.str);break;case"suffix":i=r.endsWith(t.str);break;default:{let l=ec(t.str,r);i=l>=0,s=l}}return t.negate&&(i=!i),i?s:-1}function rc(t){return t=(t??"").trim(),t===""?"":(t=t.toLowerCase().normalize("NFKD").replace(/\p{Diacritic}/gu,""),t.replace(/\d+/g,e=>(e=e.replace(/^0+(?=\d)/,""),""+String.fromCharCode(e.length)+e)))}function ic(t,e,n,r="equal-risk"){return r==="coverage"?oc(t,e,n):sc(t,e,n)}function sc(t,e,n){let r=(c,u)=>c.length?c[Math.floor(u*(c.length-1))]:0,i=c=>t.map((u,f)=>Math.max(e[f],r(u,c))),s=c=>c.reduce((u,f)=>u+f,0),l=i(1);if(s(l)<=n)return l;if(s(i(0))>=n)return i(0);let o=0,a=1;for(let c=0;c<32;c++){let u=(o+a)/2;s(i(u))<=n?o=u:a=u}return i(o)}function oc(t,e,n){let r=t.map((a,c)=>Math.max(e[c],a.length?a[a.length-1]:0)),i=a=>a.reduce((c,u)=>c+u,0);if(i(r)<=n)return r;if(i(e)>=n)return e.slice();let s=e.slice(),l=n-i(e),o=[];for(let a=0;a<t.length;a++){let c=lc(t[a],e[a]);for(let u=1;u<c.length;u++){let f=c[u].w-c[u-1].w,h=c[u].cells-c[u-1].cells;f>0&&h>0&&o.push({j:a,dw:f,slope:h/f})}}o.sort((a,c)=>c.slope-a.slope);for(let a of o){if(l<=0)break;let c=Math.min(a.dw,l);s[a.j]+=c,l-=c}return s}function lc(t,e){let n=t.length,r=0;for(;r<n&&t[r]<=e;)r++;let i=[{w:e,cells:r}];for(;r<n;){let l=t[r];for(;r<n&&t[r]===l;)r++;i.push({w:l,cells:r})}let s=[];for(let l of i){for(;s.length>=2;){let o=s[s.length-2],a=s[s.length-1];if((a.w-o.w)*(l.cells-o.cells)-(a.cells-o.cells)*(l.w-o.w)>=0)s.pop();else break}s.push(l)}return s}function ac(t,e){let n=t.trim();if(!n)return null;if(e.type==="number"||e.type==="date"){let i=e.type==="number"?l=>{let o=Oe(l);return o?o.v:NaN}:l=>{let o=ue(l);return o?o.t:NaN},s=/^(>=|<=|>|<|=)\s*(.+)$/.exec(n);if(s){let l=i(s[2]);if(!isNaN(l)){let o=s[1];return(a,c)=>{let u=e.values[c];if(u===null)return!1;switch(o){case">":return u>l;case">=":return u>=l;case"<":return u<l;case"<=":return u<=l;default:return u===l}}}}if(s=/^(.+?)\.\.(.+)$/.exec(n),s){let l=i(s[1]),o=i(s[2]);if(!isNaN(l)&&!isNaN(o))return(a,c)=>{let u=e.values[c];return u!==null&&u>=l&&u<=o}}}let r=n.toLowerCase();return(i,s)=>i.toLowerCase().includes(r)}function tn(t){return t.align?`col-${t.type} align-${t.align}`:`col-${t.type}`}function en(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var cc=1e6,uc=2048,fc=1e4,nn=10;function xt(t,e){let n=document.createElement(t);return e&&(n.className=e),n}var hc=class Le{constructor(e,n,r={}){let i=typeof e=="string"?document.querySelector(e):e;if(!i)throw Error("CsvGrid: target element not found.");this.root=i,i.csvgrid=this,this.opts={globalSearch:!0,columnFilters:!0,sortable:!0,statusBar:!0,expandButtons:!0,exportButtons:!0,align:null,formats:null,renderCap:2048,eagerCells:262144,worker:!0,headerMode:"auto",widthMode:"equal-risk",maxRows:null,height:null,displayMode:"auto",selectable:!1,selectMode:"row",hiddenColumns:null,...r},this.displayMode=this.opts.displayMode==="raw"?"raw":"auto",this.fileName="",this.headers=[],this.rows=[],this.cols=[],this.formatted=[],this.searchRaw=null,this.searchLow=null,this.searchReady=!1,this.indexing=null,this.loadGen=0,this.scores=[],this.sortedOrder=null,this.layout=null,this.expandAll=!1,this.manualWidths=new Map,this.guessedHeaders=!1,this.ambiguousDateCols=[],this.view=[],this.sortCol=null,this.sortDir=1,this.globalFilter="",this.colFilters=[],this.showAll=!1,this.visibleCols=[],this.selected=null,this._rowH=0,this._winStart=0,this._winEnd=0,this._windowed=!1,this._scrollRaf=0,this._worker=void 0,this._pending=new Map,this._buildScaffold(),n&&this.setData(n)}_buildScaffold(){let e=this.opts,n=this.root;if(n.classList.add("csvgrid"),n.replaceChildren(),this.els={},e.globalSearch||e.expandButtons||e.exportButtons){let f=xt("div","csvgrid-toolbar");if(e.globalSearch){let h=xt("input","csvgrid-search");h.type="text",h.placeholder="fzf search: term 'exact !not ^pre fix$",h.title="Space-separated terms AND together. Fuzzy by default; 'exact, !exclude, ^prefix, suffix$. Uppercase = case-sensitive.",h.addEventListener("input",()=>this.setGlobalFilter(h.value)),h.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),h.value="",h.blur(),this.setGlobalFilter(""))}),f.appendChild(h),this.els.search=h}if(e.expandButtons){let h=xt("button","csvgrid-btn");h.type="button",h.textContent="Expand",h.title="Expand all columns to their full natural width (table scrolls horizontally)",h.addEventListener("click",()=>this.expand());let d=xt("button","csvgrid-btn");d.type="button",d.textContent="Contract",d.title="Back to fitted widths (equal-risk squeeze); also clears any dragged widths",d.addEventListener("click",()=>this.contract()),f.append(h,d)}e.exportButtons&&f.append(this._buildExportControl("copy"),this._buildExportControl("save")),n.appendChild(f)}let r=xt("div","csvgrid-scroll");r.addEventListener("scroll",()=>this._onScroll());let i=xt("table","csvgrid-table"),s=xt("thead"),l=xt("tbody");i.append(s,l),r.appendChild(i),n.appendChild(r);let o=xt("div","csvgrid-capnote csvgrid-hidden"),a=xt("button","csvgrid-btn");a.type="button",a.addEventListener("click",()=>{this.showAll=!0,this.renderBody(),this.renderStatus()}),o.appendChild(a),n.appendChild(o);let c=xt("div","csvgrid-error csvgrid-hidden");n.appendChild(c);let u=null;e.statusBar===!0?(u=xt("div","csvgrid-status"),n.appendChild(u)):e.statusBar&&(u=e.statusBar),Object.assign(this.els,{table:i,head:s,body:l,scroll:r,capNote:o,showAllBtn:a,error:c,status:u}),i.addEventListener("mouseover",f=>{let h=f.target.closest("td, th");h&&!h.title&&h.scrollWidth>h.clientWidth&&(h.title=h.textContent)}),this.opts.selectable&&(n.dataset.selectable="",l.addEventListener("click",f=>this._onBodyClick(f)))}_buildExportControl(e){let n=e==="copy"?"Copy":"Save",r=xt("span","csvgrid-export"),i=xt("button","csvgrid-btn");i.type="button",i.textContent=n,i.title=`${n} the current view as CSV`,i.addEventListener("click",()=>this._runExport(e,"view","csv",r,i));let s=xt("details","csvgrid-menu"),l=xt("summary","csvgrid-btn csvgrid-menu-toggle");l.textContent="▾",l.title=`More ${n.toLowerCase()} options`;let o=xt("div","csvgrid-menu-panel");for(let[u,f,h]of[["view","csv","Current view → CSV"],["view","md","Current view → Markdown"],["all","csv","Whole table → CSV"],["all","md","Whole table → Markdown"]]){let d=xt("button","csvgrid-menu-item");d.type="button",d.textContent=h,d.addEventListener("click",()=>{s.open=!1,this._runExport(e,u,f,r,i)}),o.appendChild(d)}o.appendChild(xt("div","csvgrid-menu-sep"));let a=xt("label","csvgrid-menu-check"),c=xt("input","csvgrid-export-formatted");return c.type="checkbox",c.checked=!0,a.append(c,document.createTextNode(" Formatted values")),o.appendChild(a),s.addEventListener("focusout",u=>{s.contains(u.relatedTarget)||(s.open=!1)}),s.addEventListener("keydown",u=>{u.key==="Escape"&&s.open&&(u.preventDefault(),s.open=!1,l.focus())}),s.append(l,o),r.append(i,s),r}_runExport(e,n,r,i,s){let l=i.querySelector(".csvgrid-export-formatted"),o=l&&l.checked?"formatted":"raw",a=this.export({scope:n,format:r,values:o,visibleOnly:!0});e==="copy"?this._copyText(a,s):this._saveText(a,r,s)}_copyText(e,n){let r=()=>this._flash(n,"Copied"),i=()=>this._flash(n,"Copy failed");if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(e).then(r,i);else{let s=document.createElement("textarea");s.value=e,s.style.cssText="position:fixed;opacity:0",document.body.appendChild(s),s.select();try{document.execCommand("copy"),r()}catch{i()}s.remove()}}_saveText(e,n,r){let i=n==="md",s=i?e:"\uFEFF"+e,l=(i?"text/markdown":"text/csv")+";charset=utf-8",o=URL.createObjectURL(new Blob([s],{type:l})),a=document.createElement("a");a.href=o,a.download=this._exportBaseName()+(i?".md":".csv"),document.body.appendChild(a),a.click(),a.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3),this._flash(r,"Saved")}_exportBaseName(){return Za(this.fileName,"grid")}_flash(e,n){clearTimeout(e._flashTimer),e._flashLabel===void 0&&(e._flashLabel=e.textContent),e.textContent=n,e.classList.add("csvgrid-flash"),e._flashTimer=setTimeout(()=>{e.textContent=e._flashLabel,e._flashLabel=void 0,e.classList.remove("csvgrid-flash")},1200)}setData(e){let n=++this.loadGen,r=new Promise((i,s)=>{this._resolveData(e,n).then(({d:l,name:o})=>{n===this.loadGen&&(this._install(l,o),i())}).catch(l=>{n===this.loadGen&&(this._showError(l.message||String(l)),s(l))})});return r.catch(()=>{}),r}async _resolveData(e,n){if(!e||typeof e!="object")throw Error("CsvGrid: data must be {csv}, {records[, columns]}, or {url}.");if(this._headerMode=e.headerMode??this.opts.headerMode,e.url!==void 0){let r=String(e.url),i=e.name??decodeURIComponent(r.split("/").pop()||r),s=await fetch(r);if(!s.ok)throw Error(`HTTP ${s.status}`);return{d:await this._parse(await s.text(),n,i),name:i}}if(e.csv!==void 0){let r=e.name??"";return{d:await this._parse(e.csv,n,r),name:r}}if(e.records!==void 0)return{d:Ja(e.records,e.columns),name:e.name??""};throw Error("CsvGrid: data must be {csv}, {records[, columns]}, or {url}.")}_parse(e,n,r){if(e=ma(e),!e.trim())throw Error("No data found.");let i=this._headerMode==="first-row"?!0:this._headerMode==="headerless"?!1:null,s=this.opts.worker!==!1&&e.length>=cc?this._getWorker():null;return s?(this._setStatus(`parsing ${r||"data"} (${(e.length/1e6).toFixed(1)} MB)…`),new Promise((l,o)=>{this._pending.set(n,{resolve:l,reject:o}),s.postMessage({gen:n,text:e,headerOverride:i})})):Wa(e,i)}_getWorker(){if(this._worker===void 0){this._worker=null;try{let e=typeof this.opts.worker=="string"?new Worker(this.opts.worker):new Worker(new URL(""+new URL(""+new URL("csv-grid.worker-DKzHGXac.js",import.meta.url).href,import.meta.url).href,""+import.meta.url),{type:"module"});e.onmessage=n=>{let{gen:r,result:i,error:s}=n.data,l=this._pending.get(r);l&&(this._pending.delete(r),s?l.reject(Error(s)):l.resolve(i))},e.onerror=()=>{let n=[...this._pending.values()];this._pending.clear();for(let r of n)r.reject(Error("Background parse failed."))},this._worker=e}catch{}}return this._worker}_install(e,n){let{rows:r,cols:i}=e;if(this.opts.align){let l=Xa(this.opts.align);i.forEach((o,a)=>{l[a]&&(o.align=l[a])})}this.opts.formats&&i.forEach((l,o)=>{l.fmt=Ba(this.opts.formats[o],l.type)}),this.fileName=n||"",this.guessedHeaders=e.headerless,this.ambiguousDateCols=i.filter(l=>l.ambiguousOrder).map(l=>l.name),this.headers=e.headers,this.rows=r,this.cols=i;let s=Array.isArray(this.opts.hiddenColumns)&&this.opts.hiddenColumns.length?new Set(this.opts.hiddenColumns):null;if(this.visibleCols=i.map((l,o)=>o).filter(l=>!s||!s.has(this.headers[l])),this.selected=null,this.formatted=Array(r.length),this.searchRaw=null,this.searchLow=null,this.searchReady=!1,this.indexing=null,r.length*i.length<=this.opts.eagerCells){for(let l=0;l<r.length;l++)this.getFormattedRow(l);this.searchRaw=this.formatted.map((l,o)=>l.join(" ")+" "+r[o].join(" ")),this.searchLow=this.searchRaw.map(l=>l.toLowerCase()),this.searchReady=!0}this.sortCol=null,this.sortDir=1,this.sortedOrder=null,this.globalFilter="",this.colFilters=Array(i.length).fill(""),this.manualWidths=new Map,this.showAll=!1,this._rowH=0,this._winStart=this._winEnd=0,this._windowed=!1,this.els.search&&(this.els.search.value=""),this.els.error.classList.add("csvgrid-hidden"),this.renderHead(),this.layout=this.measureLayout(),this.applyLayout(),this.refresh(),this._applyHeight()}_applyHeight(){let e=this.opts,n=!1;if(e.height)this.els.scroll.style.maxHeight=e.height,n=!0;else if(e.maxRows){let r=this.els.body.querySelector("tr:not(.csvgrid-spacer)"),i=this._rowH||(r?r.offsetHeight:0);if(i){let s=this.els.head.offsetHeight;this.els.scroll.style.maxHeight=Math.ceil(s+i*e.maxRows+2)+"px",n=!0}}n&&this.renderBody()}_showError(e){this.els.error.textContent=e,this.els.error.classList.remove("csvgrid-hidden")}_setStatus(e){this.els.status&&(this.els.status.textContent=e)}destroy(){this.loadGen++,this._pending.clear(),this._scrollRaf&&(this._scrollRaf=(cancelAnimationFrame(this._scrollRaf),0)),this._worker&&(this._worker=(this._worker.terminate(),null)),delete this.root.csvgrid,this.root.classList.remove("csvgrid"),delete this.root.dataset.selectable,this.root.replaceChildren()}setGlobalFilter(e){this.globalFilter=e,this.refresh()}clearFilters(){this.globalFilter="",this.colFilters=this.colFilters.map(()=>""),this.els.search&&(this.els.search.value=""),this.renderHead(),this.refresh()}expand(){this.expandAll=!0,this.applyLayout()}contract(){this.expandAll=!1,this.manualWidths.clear(),this.applyLayout()}export({scope:e="view",format:n="csv",values:r="raw",visibleOnly:i=!1}={}){let s=e==="all"?this.rows.map((u,f)=>f):this.view,l=i?this.visibleCols:this.cols.map((u,f)=>f),o=r==="formatted"&&s.length<=this.opts.renderCap,a=s.map(u=>{let f=o?this.getFormattedRow(u):this.rows[u];return l.map(h=>f[h]??"")}),c=l.map(u=>this.headers[u]);return n==="md"?Ka(c,a,l.map(u=>this.cols[u].align||(this.cols[u].type==="number"?"right":this.cols[u].type==="date"?"center":"left"))):Va(c,a)}setWidthMode(e){this.opts.widthMode=e==="coverage"?"coverage":"equal-risk",this.applyLayout()}setDisplayMode(e){if(e=e==="raw"?"raw":"auto",e===this.displayMode||!this.cols.length){this.displayMode=e;return}if(this.displayMode=e,this.formatted=Array(this.rows.length),this.searchRaw=null,this.searchLow=null,this.searchReady=!1,this.indexing=null,this.rows.length*this.cols.length<=this.opts.eagerCells){for(let n=0;n<this.rows.length;n++)this.getFormattedRow(n);this.searchRaw=this.formatted.map((n,r)=>n.join(" ")+" "+this.rows[r].join(" ")),this.searchLow=this.searchRaw.map(n=>n.toLowerCase()),this.searchReady=!0}this.layout=this.measureLayout(),this.applyLayout(),this.refresh()}measureLayout(){let e=(Le._canvas||(Le._canvas=document.createElement("canvas"))).getContext("2d"),n=getComputedStyle(this.els.table),r=`${n.fontSize} ${n.fontFamily}`,i=Ci(this.rows.length,uc),s=[],l=[];for(let o of this.visibleCols){e.font=`bold ${r}`,l.push(Math.max(50,Math.ceil(e.measureText(this.cols[o].name).width)+14+18)),e.font=r;let a=[];for(let c of i){let u=this.getFormattedRow(c)[o];u!==""&&a.push(Math.ceil(e.measureText(u).width)+18)}a.sort((c,u)=>c-u),s.push(a)}return{arrays:s,floors:l}}startColResize(e,n){e.preventDefault(),e.stopPropagation();let r=this.els.table,i=r.querySelectorAll("colgroup col")[n];if(!i)return;let s=e.clientX,l=parseFloat(i.style.width);document.body.classList.add("csvgrid-resizing");let o=()=>{let u=0;r.querySelectorAll("colgroup col").forEach(f=>{u+=parseFloat(f.style.width)}),r.style.width=u+"px"},a=u=>{let f=Math.max(24,Math.round(l+u.clientX-s));this.manualWidths.set(n,f),i.style.width=f+"px",o()},c=()=>{document.body.classList.remove("csvgrid-resizing"),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",c)};document.addEventListener("mousemove",a),document.addEventListener("mouseup",c)}fitColumn(e){let{arrays:n,floors:r}=this.layout,i=Math.max(r[e],n[e].length?n[e][n[e].length-1]:0);this.manualWidths.set(e,i),this.applyLayout()}applyLayout(){if(!this.layout)return;let e=this.els.table,n=this.expandAll?1/0:e.parentElement.clientWidth;if(!n)return;let r=ic(this.layout.arrays,this.layout.floors,n,this.opts.widthMode);for(let[s,l]of this.manualWidths)s<r.length&&(r[s]=l);let i=e.querySelector("colgroup");i&&i.remove(),i=document.createElement("colgroup");for(let s of r){let l=document.createElement("col");l.style.width=s+"px",i.appendChild(l)}e.prepend(i),e.style.tableLayout="fixed",e.style.width=r.reduce((s,l)=>s+l,0)+"px",this.view.length&&this.renderBody()}getFormattedRow(e){let n=this.formatted[e];return n||(n=this.cols.map((r,i)=>qa(this.rows[e][i],r,e,this.displayMode)),this.formatted[e]=n),n}buildSearchIndexChunked(){let e=this.loadGen,n=this.rows.length,r=Array(n),i=Array(n),s=0;this.indexing=0;let l=()=>{if(e!==this.loadGen)return;let o=Math.min(n,s+fc);for(;s<o;s++){let a=this.getFormattedRow(s).join(" ")+" "+this.rows[s].join(" ");r[s]=a,i[s]=a.toLowerCase()}s<n?(this.indexing=s/n,this.renderStatus(),setTimeout(l,0)):(this.searchRaw=r,this.searchLow=i,this.searchReady=!0,this.indexing=null,this.refresh())};l()}_buildSortOrder(){let e=this.rows.length,n=Array(e);for(let i=0;i<e;i++)n[i]=i;let r=this.sortCol;if(r!==null){let i=this.cols[r],s=this.sortDir;if(i.type==="text"){let l=Array(e);for(let o=0;o<e;o++)l[o]=rc(this.rows[o][r]);n.sort((o,a)=>{let c=l[o],u=l[a];return c===""||u===""?c===u?0:c===""?1:-1:c<u?-s:c>u?s:0})}else{let l=i.values;n.sort((o,a)=>{let c=l[o],u=l[a];return c===null||u===null?c===u?0:c===null?1:-1:s*(c-u)})}}this.sortedOrder=n}rebuildView(){let{rows:e,cols:n}=this,r=Qa(this.globalFilter);r.length&&!this.searchReady&&(this.indexing===null&&this.buildSearchIndexChunked(),r=[]);let i=r.some(u=>u.kind==="fuzzy"&&!u.negate),s=this.colFilters.map((u,f)=>ac(u||"",n[f])),l=s.some(u=>u)||r.length,o=i&&this.sortCol===null;(!this.sortedOrder||this.sortedOrder.length!==e.length)&&this._buildSortOrder();let a=this.sortedOrder;if(!l){this.view=a.slice();return}let c=[];o&&(this.scores=[]);for(let u=0;u<a.length;u++){let f=a[u],h=!0,d=0;for(let w of r){let S=nc(w,this.searchLow[f],this.searchRaw[f]);if(S<0){h=!1;break}d+=S}if(h){for(let w=0;w<s.length;w++)if(s[w]&&!s[w](e[f][w]??"",f)){h=!1;break}}h&&(o&&(this.scores[f]=d),c.push(f))}o&&c.sort((u,f)=>this.scores[f]-this.scores[u]||u-f),this.view=c}renderHead(){let{cols:e}=this,n=this.els.head;n.innerHTML="";let r=document.createElement("tr");if(this.visibleCols.forEach((s,l)=>{let o=e[s],a=document.createElement("th");a.className=tn(o),this.opts.sortable?(a.innerHTML=`<span class="sort-arrow">${this.sortCol===s?this.sortDir===1?"▲":"▼":""}</span>${en(o.name)}`,a.title=`${o.name} (${o.type}) — click to sort`,a.addEventListener("click",()=>this.onSort(s))):(a.innerHTML=`<span class="sort-arrow"></span>${en(o.name)}`,a.title=`${o.name} (${o.type})`,a.classList.add("csvgrid-nosort"));let c=document.createElement("span");c.className="col-resizer",c.title="Drag to resize — double-click to fit content",c.addEventListener("mousedown",u=>this.startColResize(u,l)),c.addEventListener("dblclick",u=>{u.stopPropagation(),this.fitColumn(l)}),c.addEventListener("click",u=>u.stopPropagation()),a.appendChild(c),r.appendChild(a)}),n.appendChild(r),!this.opts.columnFilters)return;let i=document.createElement("tr");i.className="filter-row",this.visibleCols.forEach(s=>{let l=e[s],o=document.createElement("th"),a=document.createElement("input");a.type="text",a.className="csvgrid-filter",a.placeholder=l.type==="text"?"filter":"filter, >, .. ",a.value=this.colFilters[s]||"",a.addEventListener("input",()=>{this.colFilters[s]=a.value,a.classList.toggle("active-filter",a.value.trim()!==""),this.refresh()}),a.addEventListener("keydown",c=>{c.key==="Escape"&&(c.preventDefault(),a.value="",this.colFilters[s]="",a.classList.remove("active-filter"),a.blur(),this.refresh())}),o.appendChild(a),i.appendChild(o)}),n.appendChild(i)}renderBody(){let{view:e}=this,n=this.els.body,r=this.els.scroll;if(!e.length){n.innerHTML="",this._winStart=this._winEnd=0,this._windowed=!1,this._updateCapNote();return}if(!this._rowH){this._renderSlice(0,Math.min(e.length,60),0,0);let l=n.querySelector("tr:not(.csvgrid-spacer)");if(this._rowH=l?l.offsetHeight:0,!this._rowH){let o=Math.min(e.length,this.opts.renderCap);this._renderSlice(0,o,0,0),this._winStart=0,this._winEnd=o,this._windowed=!1,this._updateCapNote();return}}let i=this._rowH,s=this._computeWindow();if(this._renderSlice(s.start,s.end,s.start*i,(e.length-s.end)*i),r.scrollHeight-r.clientHeight>1)this._windowed=!0,this._winStart=s.start,this._winEnd=s.end;else{this._windowed=!1;let l=this.showAll?e.length:Math.min(e.length,this.opts.renderCap);this._renderSlice(0,l,0,0),this._winStart=0,this._winEnd=l}this._updateCapNote()}_renderSlice(e,n,r,i){let{cols:s,view:l}=this,o=this.opts.selectable,a=this.visibleCols.length,c=[];r>0&&c.push(`<tr class="csvgrid-spacer"><td colspan="${a}" style="height:${r}px"></td></tr>`);for(let u=e;u<n;u++){let f=l[u],h=this.getFormattedRow(f),d=this.visibleCols.map(w=>{let S=s[w],N=h[w];return N===""?`<td class="${tn(S)} blank">·</td>`:`<td class="${tn(S)}">${en(N)}</td>`});c.push(`<tr${o?` data-r="${f}"`:""}>${d.join("")}</tr>`)}i>0&&c.push(`<tr class="csvgrid-spacer"><td colspan="${a}" style="height:${i}px"></td></tr>`),this.els.body.innerHTML=c.join(""),o&&this._paintSelection()}_computeWindow(){let{view:e,_rowH:n}=this,r=this.els.scroll,i=e.length,s=r.clientHeight||i*n,l=Math.max(1,Math.ceil(s/n)),o=Math.max(0,Math.floor(r.scrollTop/n)-nn);return{start:o,end:Math.min(i,o+l+2*nn)}}_onScroll(){!this._windowed||this._scrollRaf||(this._scrollRaf=requestAnimationFrame(()=>{if(this._scrollRaf=0,!this._windowed)return;let{start:e,end:n}=this._computeWindow();e===this._winStart&&n===this._winEnd||(this._winStart=e,this._winEnd=n,this._renderSlice(e,n,e*this._rowH,(this.view.length-n)*this._rowH))}))}_updateCapNote(){let e=this.els.capNote;if(!e)return;let n=this.view.length;!this._windowed&&this._winEnd<n?(e.classList.remove("csvgrid-hidden"),this.els.showAllBtn.textContent=`Showing first ${this._winEnd.toLocaleString()} of ${n.toLocaleString()} rows — show all`):e.classList.add("csvgrid-hidden")}renderStatus(){if(!this.els.status)return;let e=s=>s.toLocaleString(),n=this.rows.length,r=this.view.length,i=this.fileName?this.fileName+" — ":"";i+=r===n?`${e(n)} rows`:`${e(r)} of ${e(n)} rows`,i+=` × ${this.cols.length} cols`,!this._windowed&&this._winEnd<r&&(i+=` — showing rows 1–${e(this._winEnd)}`),this.guessedHeaders&&(i+=" (headers guessed)"),this.indexing!==null&&(i+=` — indexing search ${Math.round(this.indexing*100)}%`),this.els.status.textContent=i}refresh(){this.rebuildView(),this.renderBody(),this.renderStatus()}onSort(e){this.sortCol===e?this.sortDir===1?this.sortDir=-1:(this.sortCol=null,this.sortDir=1):(this.sortCol=e,this.sortDir=1),this._buildSortOrder(),this.renderHead(),this.refresh()}static forElement(e){let n=typeof e=="string"?document.querySelector(e):e;return n&&n.csvgrid||null}_rawValue(e,n){let r=this.cols[n];if(r&&r.type==="number"){let i=r.values[e];if(i!=null)return i}return this.rows[e][n]??null}_rowDetail(e,n,r){let i=this.getFormattedRow(e),s={},l={};return this.headers.forEach((o,a)=>{s[o]=this._rawValue(e,a),l[o]=i[a]??""}),{name:this.fileName,rowIndex:e,viewIndex:this.view.indexOf(e),column:this.headers[n],columnIndex:n,value:this._rawValue(e,n),valueText:i[n]??"",row:s,rowText:l,originalEvent:r}}_onBodyClick(e){let n=e.target.closest("td"),r=n&&n.parentElement;if(!n||!r||r.dataset.r===void 0)return;let i=+r.dataset.r,s=[...r.children].indexOf(n),l=this.visibleCols[s];if(l===void 0)return;let o=new CustomEvent("csvgrid:cellclick",{detail:this._rowDetail(i,l,e),bubbles:!0,composed:!0,cancelable:!0});this.root.dispatchEvent(o)&&this.opts.selectMode!=="none"&&(this.selected={rowIndex:i,columnIndex:l},this._paintSelection())}_paintSelection(){let e=this.els.body;if(e.querySelectorAll(".csvgrid-selected, .csvgrid-selected-row").forEach(r=>r.classList.remove("csvgrid-selected","csvgrid-selected-row")),!this.selected||this.opts.selectMode==="none")return;let n=e.querySelector(`tr[data-r="${this.selected.rowIndex}"]`);if(n)if(this.opts.selectMode==="cell"){n.classList.add("csvgrid-selected-row");let r=n.children[this.visibleCols.indexOf(this.selected.columnIndex)];r&&r.classList.add("csvgrid-selected")}else n.classList.add("csvgrid-selected")}getSelection(){return this.selected?this._rowDetail(this.selected.rowIndex,this.selected.columnIndex,null):null}clearSelection(){this.selected=null,this.opts.selectable&&this._paintSelection()}selectRow(e){if(!this.opts.selectable)return;this.selected={rowIndex:e,columnIndex:this.selected?this.selected.columnIndex:this.visibleCols[0]};let n=this.view.indexOf(e);if(n<0){this._paintSelection();return}if(this._windowed&&this._rowH){let i=this._rowH,s=this.els.scroll,l=n*i;(l<s.scrollTop||l+i>s.scrollTop+s.clientHeight)&&(s.scrollTop=Math.max(0,l-i*nn)),this.renderBody();return}this._paintSelection();let r=this.els.body.querySelector(`tr[data-r="${e}"]`);r&&r.scrollIntoView({block:"nearest"})}};const ie=new Map;function Li(t,e){ie.has(t)||ie.set(t,[]),ie.get(t).push(e)}function dc(t){const e=ie.get(t);if(e){for(const n of e)try{n.destroy()}catch{}ie.delete(t)}}function Cc(){for(const t of[...ie.keys()])dc(t)}function kc(t,e,n,r={}){const{columns:i=[],rows:s=[]}=n||{};e.setAttribute("data-theme","light");const l=new hc(e,{columns:i,records:s},{worker:!1,expandButtons:!1,...r});return pc(e),Li(t,l),l}function pc(t){for(const e of t.querySelectorAll(".csvgrid-export-formatted"))e.checked=!1}const $i="/v1/assets";function Lc(t){return!!(t&&(t.notes||[]).some(e=>/^Showing first /.test(e)))}function mc(t){if(!Number.isFinite(t))return String(t);if(t===0)return"0";let e=t.toPrecision(15);return e.includes("e")||(e=e.includes(".")?e.replace(/\.?0+$/,""):e),e}function $c(t){if(!t||!Array.isArray(t.body))return t;const e=n=>{if(!n||typeof n!="object"||!("raw"in n))return n;const{raw:r}=n;if(typeof r=="boolean"||r===null||r==="")return n;const i=Number(r);return Number.isFinite(i)?{...n,text:mc(i)}:n};return{...t,body:t.body.map(n=>({...n,cells:(n.cells||[]).map(e)})),...Array.isArray(t.foot)?{foot:t.foot.map(n=>({...n,cells:(n.cells||[]).map(e)}))}:{}}}let Ee=null;function gc(){const t=`${$i}/gt.css`;if(document.querySelector(`link[href="${t}"]`))return;const e=document.createElement("link");e.rel="stylesheet",e.href=t,document.head.appendChild(e)}function Ti(){return Ee||(gc(),Ee=wn(()=>import(`${$i}/gt-render.esm.js`),[],import.meta.url).catch(t=>{throw Ee=null,t})),Ee}async function Tc(t,e,n){let r;try{r=await Ti()}catch{return null}const i=r.renderTable(n,{mount:e,allowHtml:!0});return Li(t,i),i}async function Rc(t){try{const n=(await Ti()).irToGridInput(t);return{frame:{columns:n.columns,rows:n.records},formats:n.formats,align:n.align}}catch(e){return console.error("[tables] could not derive grid input from the document",e),null}}export{wc as $,Rr as A,he as a,$c as b,dc as c,Cc as d,Lc as e,T as f,Mt as g,xc as h,Ac as i,kt as j,Rc as k,Wr as l,Mc as m,Ec as n,_c as o,kc as p,Tc as q,Sc as r,ia as s,jr as t,cs as u,bc as v,vc as w};
@@ -0,0 +1 @@
1
+ .csvgrid{--csvgrid-fg: #212529;--csvgrid-bg: #fff;--csvgrid-muted: #6c757d;--csvgrid-border: #dee2e6;--csvgrid-input-border: #ced4da;--csvgrid-accent: #0d6efd;--csvgrid-focus-ring: rgba(13, 110, 253, .25);--csvgrid-row-hover: rgba(0, 0, 0, .075);--csvgrid-grip-hover: rgba(13, 110, 253, .3);--csvgrid-blank: #adb5bd;--csvgrid-filter-active-bg: #e7f1ff;--csvgrid-selected-bg: rgba(13, 110, 253, .12);--csvgrid-error-fg: #842029;--csvgrid-error-bg: #f8d7da;--csvgrid-error-border: #f5c2c7;font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;color:var(--csvgrid-fg)}.csvgrid-hidden{display:none!important}@media (prefers-color-scheme: dark){.csvgrid:not([data-theme=light]){--csvgrid-fg: #dee2e6;--csvgrid-bg: #1e1e1e;--csvgrid-muted: #adb5bd;--csvgrid-border: #495057;--csvgrid-input-border: #495057;--csvgrid-accent: #6ea8fe;--csvgrid-focus-ring: rgba(110, 168, 254, .25);--csvgrid-row-hover: rgba(255, 255, 255, .075);--csvgrid-grip-hover: rgba(110, 168, 254, .4);--csvgrid-blank: #6c757d;--csvgrid-filter-active-bg: #2b3a55;--csvgrid-selected-bg: rgba(110, 168, 254, .22);--csvgrid-error-fg: #ea868f;--csvgrid-error-bg: #2c0b0e;--csvgrid-error-border: #842029}}.csvgrid[data-theme=dark]{--csvgrid-fg: #dee2e6;--csvgrid-bg: #1e1e1e;--csvgrid-muted: #adb5bd;--csvgrid-border: #495057;--csvgrid-input-border: #495057;--csvgrid-accent: #6ea8fe;--csvgrid-focus-ring: rgba(110, 168, 254, .25);--csvgrid-row-hover: rgba(255, 255, 255, .075);--csvgrid-grip-hover: rgba(110, 168, 254, .4);--csvgrid-blank: #6c757d;--csvgrid-filter-active-bg: #2b3a55;--csvgrid-selected-bg: rgba(110, 168, 254, .22);--csvgrid-error-fg: #ea868f;--csvgrid-error-bg: #2c0b0e;--csvgrid-error-border: #842029}.csvgrid-toolbar{display:flex;align-items:center;gap:8px;margin-bottom:8px;flex-wrap:wrap}.csvgrid-search{flex:1;max-width:320px;min-width:8em;font-size:.875rem;padding:.25rem .5rem;border:1px solid var(--csvgrid-input-border);border-radius:.25rem;background:var(--csvgrid-bg);color:var(--csvgrid-fg)}.csvgrid-search:focus{outline:0;border-color:var(--csvgrid-accent);box-shadow:0 0 0 .25rem var(--csvgrid-focus-ring)}.csvgrid-btn{font-size:.875rem;padding:.25rem .5rem;border:1px solid var(--csvgrid-muted);border-radius:.25rem;background:var(--csvgrid-bg);color:var(--csvgrid-muted);cursor:pointer;white-space:nowrap}.csvgrid-btn:hover{background:var(--csvgrid-muted);color:var(--csvgrid-bg)}.csvgrid-btn.csvgrid-flash{background:var(--csvgrid-accent);border-color:var(--csvgrid-accent);color:var(--csvgrid-bg)}.csvgrid-export{display:inline-flex;position:relative}.csvgrid-export .csvgrid-btn{border-radius:0}.csvgrid-export>.csvgrid-btn:first-child{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.csvgrid-export .csvgrid-menu-toggle{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem;border-left:0;list-style:none}.csvgrid-menu-toggle::-webkit-details-marker{display:none}.csvgrid-menu-toggle::marker{content:""}.csvgrid-menu-panel{position:absolute;top:calc(100% + 2px);left:0;z-index:5;min-width:max-content;display:flex;flex-direction:column;padding:.25rem 0;border:1px solid var(--csvgrid-border);border-radius:.25rem;background:var(--csvgrid-bg);box-shadow:0 .25rem .75rem #00000026}.csvgrid-menu-item{text-align:left;white-space:nowrap;font-size:.875rem;padding:.25rem .75rem;border:0;background:transparent;color:var(--csvgrid-fg);cursor:pointer}.csvgrid-menu-item:hover{background:var(--csvgrid-row-hover)}.csvgrid-menu-sep{height:1px;margin:.25rem 0;background:var(--csvgrid-border)}.csvgrid-menu-check{display:flex;align-items:center;gap:.4rem;white-space:nowrap;font-size:.875rem;padding:.25rem .75rem;color:var(--csvgrid-fg);cursor:pointer}.csvgrid-scroll{overflow:auto}.csvgrid{container-type:inline-size}@container (max-width: 360px){.csvgrid-search{max-width:none;flex-basis:100%}}.csvgrid .csvgrid-table{border-collapse:collapse;width:auto;font-size:.8rem;line-height:1.5;font-variant-numeric:tabular-nums;background:var(--csvgrid-bg)}.csvgrid .csvgrid-table th,.csvgrid .csvgrid-table td{padding:.25rem;border-bottom:1px solid var(--csvgrid-border);text-align:left}.csvgrid .csvgrid-table tbody tr:hover td{background:var(--csvgrid-row-hover)}.csvgrid .csvgrid-table tbody tr.csvgrid-spacer td,.csvgrid .csvgrid-table tbody tr.csvgrid-spacer:hover td{padding:0;border:0;background:none}.csvgrid .csvgrid-table thead th{position:sticky;top:0;z-index:2;background:var(--csvgrid-bg);box-shadow:inset 0 -2px 0 var(--csvgrid-border);cursor:pointer;user-select:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.csvgrid .csvgrid-table thead th.csvgrid-nosort{cursor:default}.csvgrid .csvgrid-table thead th .col-resizer{position:absolute;top:0;right:0;width:7px;height:100%;cursor:col-resize;z-index:3}.csvgrid .csvgrid-table thead th .col-resizer:hover{background:var(--csvgrid-grip-hover)}body.csvgrid-resizing{cursor:col-resize;user-select:none}.csvgrid .csvgrid-table thead th .sort-arrow{display:inline-block;width:1em;color:var(--csvgrid-accent)}.csvgrid .csvgrid-table thead tr.filter-row th{cursor:default;box-shadow:inset 0 -2px 0 var(--csvgrid-border);top:28px;padding:2px 4px}.csvgrid-filter{width:100%;min-width:4em;font-size:.78rem;padding:1px 6px;border:1px solid var(--csvgrid-input-border);border-radius:.25rem;background:var(--csvgrid-bg);color:var(--csvgrid-fg)}.csvgrid-filter:focus{outline:0;border-color:var(--csvgrid-accent);box-shadow:0 0 0 .2rem var(--csvgrid-focus-ring)}.csvgrid-filter.active-filter{background-color:var(--csvgrid-filter-active-bg);border-color:var(--csvgrid-accent)}.csvgrid .csvgrid-table td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.csvgrid .csvgrid-table .col-number{text-align:right}.csvgrid .csvgrid-table .col-date{text-align:center}.csvgrid .csvgrid-table .col-text,.csvgrid .csvgrid-table .align-left{text-align:left}.csvgrid .csvgrid-table .align-center{text-align:center}.csvgrid .csvgrid-table .align-right{text-align:right}.csvgrid .csvgrid-table td.blank{color:var(--csvgrid-blank)}.csvgrid[data-selectable] .csvgrid-table tbody tr{cursor:pointer}.csvgrid .csvgrid-table tbody tr.csvgrid-selected td,.csvgrid .csvgrid-table tbody tr.csvgrid-selected-row td{background:var(--csvgrid-selected-bg)}.csvgrid .csvgrid-table tbody td.csvgrid-selected{outline:2px solid var(--csvgrid-accent);outline-offset:-2px}.csvgrid-capnote{text-align:center;margin:1rem 0}.csvgrid-status{font-size:.75rem;color:var(--csvgrid-muted);padding:3px 0}.csvgrid-error{margin:.5rem 0;padding:.5rem .75rem;font-size:.875rem;color:var(--csvgrid-error-fg);background:var(--csvgrid-error-bg);border:1px solid var(--csvgrid-error-border);border-radius:.25rem}
Binary file
Binary file
Binary file