@malloy-publisher/server 0.9.1 → 0.9.2

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 (31) hide show
  1. package/dist/app/api-doc.yaml +127 -53
  2. package/dist/app/assets/EnvironmentPage-B-t_QP32.js +1 -0
  3. package/dist/app/assets/{HomePage-D3MvQaZn.js → HomePage-Cpu2zMy-.js} +1 -1
  4. package/dist/app/assets/{LightMode-e1lNBfpL.js → LightMode-DOBl6awB.js} +1 -1
  5. package/dist/app/assets/MainPage-C7ySrclP.js +1 -0
  6. package/dist/app/assets/ModelPage-D8r_J-N9.js +2 -0
  7. package/dist/app/assets/PackagePage-CcVFBhnT.js +1 -0
  8. package/dist/app/assets/RenderedResult-CBLHr32C.es-DRr9Gmsz.js +141 -0
  9. package/dist/app/assets/{RouteError-BQnzPJvb.js → RouteError-mgOkv7XK.js} +1 -1
  10. package/dist/app/assets/ThemeEditorPage-CIPDs2w9.js +1 -0
  11. package/dist/app/assets/ToggleButtonGroup-CEZThrzh.js +1 -0
  12. package/dist/app/assets/{index-CCNqF0-G.js → index-Bg-M8sZz.js} +1 -1
  13. package/dist/app/assets/index-CGdwupPP.js +457 -0
  14. package/dist/app/assets/{index-CKmZ4HG7.js → index-CeLTZAFW.js} +116 -116
  15. package/dist/app/assets/{index-CdExa3Pk.js → index-DoF8ihra.js} +1 -1
  16. package/dist/app/assets/{index-ufFZR_K-.js → index-IC0jPCkR.js} +1 -1
  17. package/dist/app/assets/index.es-6eARPKZf.js +198 -0
  18. package/dist/app/index.html +1 -1
  19. package/dist/package_load_worker.mjs +436 -56
  20. package/dist/server.mjs +9537 -9076
  21. package/package.json +1 -1
  22. package/dist/app/assets/EnvironmentPage-UMS7Py4Q.js +0 -1
  23. package/dist/app/assets/MainPage-B0ozqtQO.js +0 -2
  24. package/dist/app/assets/ModelPage-lQj4Axqu.js +0 -2
  25. package/dist/app/assets/PackagePage-BT0YKNKU.js +0 -1
  26. package/dist/app/assets/RenderedResult-BRgIgxWh.es-DiE7kPNX.js +0 -136
  27. package/dist/app/assets/ThemeEditorPage-D6t7w9Js.js +0 -1
  28. package/dist/app/assets/ToggleButtonGroup-CJT2JKTC.js +0 -1
  29. package/dist/app/assets/index-TiWjmdoW.js +0 -450
  30. package/dist/app/assets/index.es-iUV0gCYk.js +0 -111
  31. package/dist/cpufeatures-1yrn0vtw.node +0 -0
@@ -0,0 +1,198 @@
1
+ import{r as k,aR as $c,aS as Ff,j as v,a9 as ye,av as xt,H as Oe,T as ie,aA as Ee,aT as qf,aU as Sc,aV as ms,a5 as Bf,aW as Uf,O as jc,at as Gf,aX as Nt,aY as Hf,aZ as Ti,a_ as Vf,a$ as ol,b0 as al,b1 as ll,b2 as Yf,b3 as Kf,b4 as Xf,a2 as Zf,b5 as Qf,b6 as Jf,b7 as eh,aa as Cc,Y as Oc,A as nt,b8 as ro,C as Un,I as Hi,a0 as Ec,b9 as th,J as Ur,ba as nh,bb as rh,ao as et,bc as ih,bd as Mc,be as sh,az as gs,as as Ct,bf as io,ap as Tc,U as Ko,bg as oh,bh as ah,bi as lh,bj as Xo,bk as ch,bl as dh,bm as uh,bn as fh,bo as hh,bp as ph,aL as Ac,bq as mh,br as Ic,bs as vs,bt as Dc,bu as Pc,bv as gh,bw as vh,bx as en,by as bh,L as xh,Q as yh,bz as Zo,bA as un,bB as Qo,bC as wh,bD as kh,bE as $h,bF as Sh,bG as cl,bH as Lc,bI as jh,bJ as Ch,bK as Oh,bL as Eh,aC as Mh}from"./index-CGdwupPP.js";import{bM as Xx,bN as Zx,bO as Qx,bP as Jx,bQ as ey,bR as ty,bS as ny,bT as ry,bU as iy,bV as sy,bW as oy}from"./index-CGdwupPP.js";import{d as Th}from"./index-DoF8ihra.js";import{T as Jo,a as Kn}from"./ToggleButtonGroup-CEZThrzh.js";import"./index-ByieDZlo.js";var dl={},Ah=Symbol.for("preact-signals");function bs(){if(zt>1)zt--;else{var e,t=!1;for((function(){var i=Yi;for(Yi=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();zr!==void 0;){var n=zr;for(zr=void 0,Vi++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Rc(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Vi=0,zt--,t)throw e}}function Ie(e){if(zt>0)return e();so=++Ih,zt++;try{return e()}finally{bs()}}var Rr,je=void 0;function de(e){var t=je,n=Rr;je=void 0,Rr=void 0;try{return e()}finally{je=t,Rr=n}}var zr=void 0,zt=0,Vi=0,Ih=0,so=0,Yi=void 0,Ki=0;function Nc(e){if(je!==void 0){var t=e.n;if(t===void 0||t.t!==je)return t={i:0,S:e,p:je.s,n:void 0,t:je,e:void 0,x:void 0,r:t},je.s!==void 0&&(je.s.n=t),je.s=t,e.n=t,32&je.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=je.s,t.n=void 0,je.s.n=t,je.s=t),t}}function rt(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}rt.prototype.brand=Ah;rt.prototype.h=function(){return!0};rt.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:de(function(){var r;(r=t.W)==null||r.call(t)}))};rt.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&de(function(){var i;(i=t.Z)==null||i.call(t)}))}};rt.prototype.subscribe=function(e){var t=this;return gt(function(){var n=t.value;de(function(){return e(n)})},{name:"sub"})};rt.prototype.valueOf=function(){return this.value};rt.prototype.toString=function(){return this.value+""};rt.prototype.toJSON=function(){return this.value};rt.prototype.peek=function(){var e=this;return de(function(){return e.value})};Object.defineProperty(rt.prototype,"value",{get:function(){var e=Nc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Vi>100)throw new Error("Cycle detected");(function(n){zt!==0&&Vi===0&&n.l!==so&&(n.l=so,Yi={S:n,v:n.v,i:n.i,o:Yi})})(this),this.v=e,this.i++,Ki++,zt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{bs()}}}});function nr(e,t){return new rt(e,t)}function Rc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function zc(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Wc(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function jn(e,t){rt.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ki-1,this.f=4}jn.prototype=new rt;jn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ki))return!0;if(this.g=Ki,this.f|=1,this.i>0&&!Rc(this))return this.f&=-2,!0;var e=je;try{zc(this),je=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return je=e,Wc(this),this.f&=-2,!0};jn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}rt.prototype.S.call(this,e)};jn.prototype.U=function(e){if(this.t!==void 0&&(rt.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};jn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(jn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Nc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ul(e,t){return new jn(e,t)}function _c(e){var t=e.m;if(e.m=void 0,typeof t=="function"){zt++;var n=je;je=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,ea(e),r}finally{je=n,bs()}}}function ea(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function Dh(e){if(je!==this)throw new Error("Out-of-order effect");Wc(this),je=e,this.f&=-2,8&this.f&&ea(this),bs()}function rr(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Rr&&Rr.push(this)}rr.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};rr.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,_c(this),zc(this),zt++;var e=je;return je=this,Dh.bind(this,e)};rr.prototype.N=function(){2&this.f||(this.f|=2,this.u=zr,zr=this)};rr.prototype.d=function(){this.f|=8,1&this.f||ea(this)};rr.prototype.dispose=function(){this.d()};function gt(e,t){var n=new rr(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Ph=Object.create,ta=Object.defineProperty,Lh=Object.defineProperties,Nh=Object.getOwnPropertyDescriptor,Rh=Object.getOwnPropertyDescriptors,fl=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Wh=Object.prototype.propertyIsEnumerable,_h=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ir=e=>{throw TypeError(e)},oo=(e,t,n)=>t in e?ta(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fh=(e,t)=>{for(var n in t||(t={}))zh.call(t,n)&&oo(e,n,t[n]);if(fl)for(var n of fl(t))Wh.call(t,n)&&oo(e,n,t[n]);return e},qh=(e,t)=>Lh(e,Rh(t)),hl=(e,t)=>ta(e,"name",{value:t,configurable:!0}),Bh=e=>{var t;return[,,,Ph((t=void 0)!=null?t:null)]},Fc=["class","method","getter","setter","accessor","field","value","get","set"],wr=e=>e!==void 0&&typeof e!="function"?ir("Function expected"):e,Uh=(e,t,n,r,i)=>({kind:Fc[e],name:t,metadata:r,addInitializer:s=>n._?ir("Already initialized"):i.push(wr(s||null))}),qc=(e,t)=>oo(t,_h("metadata"),e[3]),dn=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},sr=(e,t,n,r,i,s)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),x=c>3?e.length+1:c?f?1:2:0,g=Fc[c+5],y=c>3&&(e[x-1]=[]),w=e[x]||(e[x]=[]),h=c&&(!p&&!f&&(i=i.prototype),c<5&&(c>3||!p)&&Nh(c<4?i:{get[n](){return ut(this,s)},set[n](b){return Ht(this,s,b)}},n));c?p&&c<4&&hl(s,(c>2?"set ":c>1?"get ":"")+n):hl(i,n);for(var m=r.length-1;m>=0;m--)u=Uh(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>Gh(i,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?ut:Hh)(b,i,c^4?s:h.get):b=>b[n]),c>2&&(d.set=p?(b,$)=>Ht(b,i,$,c^4?s:h.set):(b,$)=>b[n]=$)),a=(0,r[m])(c?c<4?p?s:h[g]:c>4?void 0:{get:h.get,set:h.set}:i,u),l._=1,c^4||a===void 0?wr(a)&&(c>4?y.unshift(a):c?p?s=a:h[g]=a:i=a):typeof a!="object"||a===null?ir("Object expected"):(wr(o=a.get)&&(h.get=o),wr(o=a.set)&&(h.set=o),wr(o=a.init)&&y.unshift(o));return c||qc(e,i),h&&ta(i,n,h),p?c^4?s:h:i},na=(e,t,n)=>t.has(e)||ir("Cannot "+n),Gh=(e,t)=>Object(t)!==t?ir('Cannot use the "in" operator on this value'):e.has(t),ut=(e,t,n)=>(na(e,t,"read from private field"),n?n.call(e):t.get(e)),kr=(e,t,n)=>t.has(e)?ir("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ht=(e,t,n,r)=>(na(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Hh=(e,t,n)=>(na(e,t,"access private method"),n);function ao(e,t){if(t){let n;return ul(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return ul(e)}function yt(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((n,r)=>!yt(n,t[r]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!yt(e[i],t[i]))}return!1}function ue({get:e},t){return{init(n){return nr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Pe(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ao(e.bind(this)),n.set(this,r)),r.value}}function Is(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),i=Object.getOwnPropertyDescriptor(r,n.name);i&&Object.defineProperty(r,n.name,qh(Fh({},i),{enumerable:e}))})}}function ri(...e){const t=e.map(n=>gt(n));return()=>t.forEach(n=>n())}var Bc,Uc,Gc,Hc,Vc,Yc,Qe,ra,Ds,lo,co,Xe,ia,Ps,Kc,uo,sa,Ls,fo,ho;Yc=[ue],Vc=[ue],Hc=[ue],Gc=[Is()],Uc=[Is()],Bc=[Is()];var Cn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,dn(Qe,5,this),kr(this,Xe),kr(this,ra,dn(Qe,8,this)),dn(Qe,11,this),kr(this,ia,dn(Qe,12,this)),dn(Qe,15,this),kr(this,sa,dn(Qe,16,this)),dn(Qe,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return ut(this,Xe,fo)}get initial(){return ut(this,Xe,lo)}get previous(){return ut(this,Xe,Kc)}set current(e){const t=de(()=>ut(this,Xe,fo));e&&t&&this.equals(t,e)||Ie(()=>{ut(this,Xe,lo)||Ht(this,Xe,e,co),Ht(this,Xe,t,uo),Ht(this,Xe,e,ho)})}reset(e=this.defaultValue){Ie(()=>{Ht(this,Xe,void 0,uo),Ht(this,Xe,e,co),Ht(this,Xe,e,ho)})}};Qe=Bh();ra=new WeakMap;Xe=new WeakSet;ia=new WeakMap;sa=new WeakMap;Ds=sr(Qe,20,"#initial",Yc,Xe,ra),lo=Ds.get,co=Ds.set;Ps=sr(Qe,20,"#previous",Vc,Xe,ia),Kc=Ps.get,uo=Ps.set;Ls=sr(Qe,20,"#current",Hc,Xe,sa),fo=Ls.get,ho=Ls.set;sr(Qe,2,"current",Gc,Cn);sr(Qe,2,"initial",Uc,Cn);sr(Qe,2,"previous",Bc,Cn);qc(Qe,Cn);function Ns(e){return de(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var fn,Vh=class{constructor(){kr(this,fn,new WeakMap)}get(e,t){var n;return e?(n=ut(this,fn).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return ut(this,fn).has(e)||ut(this,fn).set(e,new Map),(r=ut(this,fn).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=ut(this,fn).get(e))==null?void 0:t.clear():void 0}};fn=new WeakMap;var Yh=Object.create,Xc=Object.defineProperty,Kh=Object.getOwnPropertyDescriptor,pl=Object.getOwnPropertySymbols,Xh=Object.prototype.hasOwnProperty,Zh=Object.prototype.propertyIsEnumerable,Zc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),xs=e=>{throw TypeError(e)},ml=Math.pow,po=(e,t,n)=>t in e?Xc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qh=(e,t)=>{for(var n in t||(t={}))Xh.call(t,n)&&po(e,n,t[n]);if(pl)for(var n of pl(t))Zh.call(t,n)&&po(e,n,t[n]);return e},Jh=e=>{var t;return[,,,Yh((t=e?.[Zc("metadata")])!=null?t:null)]},Qc=["class","method","getter","setter","accessor","field","value","get","set"],Jc=e=>e!==void 0&&typeof e!="function"?xs("Function expected"):e,ep=(e,t,n,r,i)=>({kind:Qc[e],name:t,metadata:r,addInitializer:s=>n._?xs("Already initialized"):i.push(Jc(s||null))}),tp=(e,t)=>po(t,Zc("metadata"),e[3]),np=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},ed=(e,t,n,r,i,s)=>{for(var o,a,l,u,d=t&7,c=!1,f=!1,p=2,x=Qc[d+5],g=e[p]||(e[p]=[]),y=(i=i.prototype,Kh(i,n)),w=r.length-1;w>=0;w--)l=ep(d,n,a={},e[3],g),l.static=c,l.private=f,u=l.access={has:h=>n in h},u.get=h=>h[n],o=(0,r[w])(y[x],l),a._=1,Jc(o)&&(y[x]=o);return y&&Xc(i,n,y),i},td=(e,t,n)=>t.has(e)||xs("Cannot "+n),rp=(e,t,n)=>(td(e,t,"read from private field"),t.get(e)),ip=(e,t,n)=>t.has(e)?xs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),sp=(e,t,n,r)=>(td(e,t,"write to private field"),t.set(e,n),n),ft=class mo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new mo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new mo(t,n)}},Et=class hn{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,l=new hn(i+t,r+n,s,o);return l.scale=Qh({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new ft((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof hn))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof hn?op(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:i}){return new hn(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],l=o==="x"?s.left:s.top,u=o==="x"?s.width:s.height;return a=="start"?l:a=="end"?l+u:l+u/2};return ft.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return hn.from(t).intersectionRatio(hn.from(n))}};function op(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var nd,rd,go,Ai,ii,ys=class extends(go=Cn,rd=[Pe],nd=[Pe],go){constructor(e){const t=ft.from(e);super(t,(n,r)=>ft.equals(n,r)),np(ii,5,this),ip(this,Ai,0),this.velocity={x:0,y:0}}get delta(){return ft.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=ft.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-rp(this,Ai),o=a=>Math.round(a/s*100);Ie(()=>{sp(this,Ai,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(ft.from(e)),this.velocity={x:0,y:0}}};ii=Jh(go);Ai=new WeakMap;ed(ii,2,"delta",rd,ys);ed(ii,2,"direction",nd,ys);tp(ii,ys);function vo({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(ml(r,2)+ml(i,2))>n:"x"in n&&"y"in n?r>n.x&&i>n.y:"x"in n?r>n.x:"y"in n?i>n.y:!1}var id=(e=>(e.Horizontal="x",e.Vertical="y",e))(id||{}),sd=Object.values(id),ap=Object.create,oa=Object.defineProperty,lp=Object.defineProperties,cp=Object.getOwnPropertyDescriptor,dp=Object.getOwnPropertyDescriptors,Xi=Object.getOwnPropertySymbols,od=Object.prototype.hasOwnProperty,ad=Object.prototype.propertyIsEnumerable,ld=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),or=e=>{throw TypeError(e)},bo=(e,t,n)=>t in e?oa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,aa=(e,t)=>{for(var n in t||(t={}))od.call(t,n)&&bo(e,n,t[n]);if(Xi)for(var n of Xi(t))ad.call(t,n)&&bo(e,n,t[n]);return e},la=(e,t)=>lp(e,dp(t)),gl=(e,t)=>oa(e,"name",{value:t,configurable:!0}),cd=(e,t)=>{var n={};for(var r in e)od.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Xi)for(var r of Xi(e))t.indexOf(r)<0&&ad.call(e,r)&&(n[r]=e[r]);return n},ar=e=>{var t;return[,,,ap((t=e?.[ld("metadata")])!=null?t:null)]},dd=["class","method","getter","setter","accessor","field","value","get","set"],$r=e=>e!==void 0&&typeof e!="function"?or("Function expected"):e,up=(e,t,n,r,i)=>({kind:dd[e],name:t,metadata:r,addInitializer:s=>n._?or("Already initialized"):i.push($r(s||null))}),On=(e,t)=>bo(t,ld("metadata"),e[3]),re=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},fe=(e,t,n,r,i,s)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),x=c>3?e.length+1:c?f?1:2:0,g=dd[c+5],y=c>3&&(e[x-1]=[]),w=e[x]||(e[x]=[]),h=c&&(!p&&!f&&(i=i.prototype),c<5&&(c>3||!p)&&cp(c<4?i:{get[n](){return De(this,s)},set[n](b){return at(this,s,b)}},n));c?p&&c<4&&gl(s,(c>2?"set ":c>1?"get ":"")+n):gl(i,n);for(var m=r.length-1;m>=0;m--)u=up(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>fp(i,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?De:ud)(b,i,c^4?s:h.get):b=>b[n]),c>2&&(d.set=p?(b,$)=>at(b,i,$,c^4?s:h.set):(b,$)=>b[n]=$)),a=(0,r[m])(c?c<4?p?s:h[g]:c>4?void 0:{get:h.get,set:h.set}:i,u),l._=1,c^4||a===void 0?$r(a)&&(c>4?y.unshift(a):c?p?s=a:h[g]=a:i=a):typeof a!="object"||a===null?or("Object expected"):($r(o=a.get)&&(h.get=o),$r(o=a.set)&&(h.set=o),$r(o=a.init)&&y.unshift(o));return c||On(e,i),h&&oa(i,n,h),p?c^4?s:h:i},ca=(e,t,n)=>t.has(e)||or("Cannot "+n),fp=(e,t)=>Object(t)!==t?or('Cannot use the "in" operator on this value'):e.has(t),De=(e,t,n)=>(ca(e,t,"read from private field"),n?n.call(e):t.get(e)),ge=(e,t,n)=>t.has(e)?or("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),at=(e,t,n,r)=>(ca(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),ud=(e,t,n)=>(ca(e,t,"access private method"),n);function fd(e,t){return{plugin:e,options:t}}function si(e){return t=>fd(e,t)}function Gr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var hd,Hr,da,Ii;hd=[ue];var Ze=class{constructor(e,t){this.manager=e,this.options=t,ge(this,da,re(Hr,8,this,!1)),re(Hr,11,this),ge(this,Ii,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return de(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=gt(e.bind(this));return De(this,Ii).add(t),t}destroy(){De(this,Ii).forEach(e=>e())}static configure(e){return fd(this,e)}};Hr=ar(null);da=new WeakMap;Ii=new WeakMap;fe(Hr,4,"disabled",hd,Ze,da);On(Hr,Ze);var oi=class extends Ze{},Di,Rs=class{constructor(e){this.manager=e,this.instances=new Map,ge(this,Di,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Gr).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of De(this,Di))if(!n.includes(r)){if(r.prototype instanceof oi)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);at(this,Di,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};Di=new WeakMap;function hp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var gi=[],Ln,Nn,pp=class extends Ze{constructor(e){super(e),ge(this,Ln),ge(this,Nn),this.computeCollisions=this.computeCollisions.bind(this),at(this,Nn,nr(gi)),this.destroy=ri(()=>{const t=this.computeCollisions(),n=de(()=>this.manager.dragOperation.position.current);if(t!==gi){const r=De(this,Ln);if(at(this,Ln,n),r&&n.x==r.x&&n.y==r.y)return}else at(this,Ln,void 0);De(this,Nn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){de(()=>{e?De(this,Nn).value=this.computeCollisions():at(this,Ln,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return gi;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||i&&!u.accepts(i))continue;const d=t??u.collisionDetector;if(!d)continue;l.push(u),u.shape;const c=de(()=>d({droppable:u,dragOperation:r}));c&&(u.collisionPriority!=null&&(c.priority=u.collisionPriority),a.push(c))}return l.length===0?gi:(a.sort(hp),a)}get collisions(){return De(this,Nn).value}};Ln=new WeakMap;Nn=new WeakMap;var pd,md,gd,ua,vd,wt,fa,qn,ha,pa;gd=[ue],md=[ue],pd=[ue];var _t=class pn{constructor(t,n){ge(this,fa,re(wt,8,this)),re(wt,11,this),ge(this,qn),ge(this,ha,re(wt,12,this)),re(wt,15,this),ge(this,pa,re(wt,16,this)),re(wt,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let l=i;at(this,qn,nr(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var u;return[()=>{const{id:d,manager:c}=this;if(d!==l)return l=d,c?.registry.register(this),()=>c?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=De(this,qn).value;return(n=(t=pn.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=pn.pendingIdChanges)==null?void 0:n.get(this))!=null?r:De(this,qn).peek();t!==i&&(pn.pendingIdChanges||(pn.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return ud(s=pn,ua,vd).call(s)})),pn.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};wt=ar(null);ua=new WeakSet;vd=function(){const e=_t.pendingIdChanges;_t.pendingIdChanges=null,e&&Ie(()=>{for(const[t,n]of e)De(t,qn).value=n})};fa=new WeakMap;qn=new WeakMap;ha=new WeakMap;pa=new WeakMap;fe(wt,4,"manager",gd,_t,fa);fe(wt,4,"data",md,_t,ha);fe(wt,4,"disabled",pd,_t,pa);ge(_t,ua);On(wt,_t);_t.pendingIdChanges=null;var ws=_t,vl=class{constructor(){this.map=nr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;r&&r.id===e&&(this.cleanupFunctions.get(r)?.(),this.cleanupFunctions.delete(r));const s=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=ri(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;this.cleanupFunctions.get(t)?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this)this.cleanupFunctions.get(e)?.(),e.destroy();this.map.value=new Map}},bd,xd,yd,wd,kd,$d,xo,Je,ma,ga,va,Mt=class extends(xo=ws,$d=[ue],kd=[ue],wd=[ue],yd=[Pe],xd=[Pe],bd=[Pe],xo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,l=cd(n,["modifiers","type","sensors","plugins","effects"]);super(la(aa({},l),{effects:()=>{var u;return[...(u=a?.())!=null?u:[],()=>{const{manager:d,plugins:c}=this;if(!(!d||!c))for(const f of c){const{plugin:p}=Gr(f);d.registry.plugins.register(p)}}]}}),t),re(Je,5,this),ge(this,ma,re(Je,8,this)),re(Je,11,this),ge(this,ga,re(Je,12,this)),re(Je,15,this),ge(this,va,re(Je,16,this,this.isDragSource?"dragging":"idle")),re(Je,19,this),this.type=i,this.sensors=s,this.modifiers=r,this.alignment=l.alignment,this.plugins=o}pluginConfig(e){if(this.plugins)for(const t of this.plugins){const n=Gr(t);if(n.plugin===e)return n.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.source)==null?void 0:t.id)===this.id}};Je=ar(xo);ma=new WeakMap;ga=new WeakMap;va=new WeakMap;fe(Je,4,"type",$d,Mt,ma);fe(Je,4,"modifiers",kd,Mt,ga);fe(Je,4,"status",wd,Mt,va);fe(Je,2,"isDropping",yd,Mt);fe(Je,2,"isDragging",xd,Mt);fe(Je,2,"isDragSource",bd,Mt);On(Je,Mt);var Sd,jd,Cd,Od,Ed,Md,yo,We,ba,xa,ya,wa,ka,Tt=class extends(yo=ws,Md=[ue],Ed=[ue],Od=[ue],Cd=[ue],jd=[ue],Sd=[Pe],yo){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=cd(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),re(We,5,this),ge(this,ba,re(We,8,this)),re(We,11,this),ge(this,xa,re(We,12,this)),re(We,15,this),ge(this,ya,re(We,16,this)),re(We,19,this),ge(this,wa,re(We,20,this)),re(We,23,this),ge(this,ka,re(We,24,this)),re(We,27,this),this.accept=r,this.collisionDetector=i,this.collisionPriority=s,this.type=o}accepts(e){const{accept:t}=this;return t?typeof t=="function"?t(e):e.type?Array.isArray(t)?t.includes(e.type):e.type===t:!1:!0}get isDropTarget(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.target)==null?void 0:t.id)===this.id}};We=ar(yo);ba=new WeakMap;xa=new WeakMap;ya=new WeakMap;wa=new WeakMap;ka=new WeakMap;fe(We,4,"accept",Md,Tt,ba);fe(We,4,"type",Ed,Tt,xa);fe(We,4,"collisionDetector",Od,Tt,ya);fe(We,4,"collisionPriority",Cd,Tt,wa);fe(We,4,"shape",jd,Tt,ka);fe(We,2,"isDropTarget",Sd,Tt);On(We,Tt);var mp=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const i of r)i(...t)}},gp=class extends mp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Pi(e,t=!0){let n=!1;return la(aa({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var vp=class extends oi{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=ri(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||ws.pendingIdChanges)return;const o=Pi({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;de(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},lr=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(lr||{}),cr=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(cr||{}),Td,Ad,Id,Dd,Pd,Ld,Nd,mt,$a;Nd=[ue],Ld=[Pe],Pd=[Pe],Dd=[Pe],Id=[Pe],Ad=[Pe],Td=[Pe];var qt=class{constructor(){re(mt,5,this),ge(this,$a,re(mt,8,this,"idle")),re(mt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};mt=ar(null);$a=new WeakMap;fe(mt,4,"value",Nd,qt,$a);fe(mt,2,"current",Ld,qt);fe(mt,2,"idle",Pd,qt);fe(mt,2,"initializing",Dd,qt);fe(mt,2,"initialized",Id,qt);fe(mt,2,"dragging",Ad,qt);fe(mt,2,"dropped",Td,qt);On(mt,qt);var bp=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return de(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Pi({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return de(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const n=new AbortController,{event:r,coordinates:i}=e;Ie(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=r??null,t.position.reset(i)});const s=Pi({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",s),s.defaultPrevented?(t.reset(),n.abort(),n):(t.status.set("initializing"),t.controller=n,this.manager.renderer.rendering.then(()=>{if(n.signal.aborted)return;const{status:o}=t;o.current==="initializing"&&Ie(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return de(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=Pi({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,l,u,d,c;if(o.defaultPrevented)return;const f=(c=e.to)!=null?c:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((d=(u=e.by)==null?void 0:u.y)!=null?d:0)};r.position.current=f})})}stop(e={}){return de(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const l={resume:()=>{},abort:()=>{}};return s=new Promise((u,d)=>{l.resume=u,l.abort=d}),l};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=de(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),u=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(l){const{source:d}=r,c=gt(()=>{d?.status==="idle"&&(c(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},Xn=class extends Ze{constructor(e,t){super(e,t),this.manager=e,this.options=t}},xp=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},Li,Rd=class{constructor(e){this.options=e,ge(this,Li)}set controller(e){at(this,Li,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=De(this,Li))==null||t.activate(e)}};Li=new WeakMap;var bl=class extends Ze{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},yp=class{constructor(e){this.draggables=new vl,this.droppables=new vl,this.plugins=new Rs(e),this.sensors=new Rs(e),this.modifiers=new Rs(e)}register(e,t){if(e instanceof Mt)return this.draggables.register(e.id,e);if(e instanceof Tt)return this.droppables.register(e.id,e);if(e.prototype instanceof bl)return this.modifiers.register(e,t);if(e.prototype instanceof Xn)return this.sensors.register(e,t);if(e.prototype instanceof Ze)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof ws)return e instanceof Mt?this.draggables.unregister(e.id,e):e instanceof Tt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof bl)return this.modifiers.unregister(e);if(e.prototype instanceof Xn)return this.sensors.unregister(e);if(e.prototype instanceof Ze)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},zd,Wd,_d,Fd,qd,Bd,Ud,Gd,Hd,Sr,Ni,Rn,Ae,Sa,ja,Ca,Oa,Ea,jr;Hd=[Pe],Gd=[ue],Ud=[ue],Bd=[ue],qd=[ue],Fd=[ue],_d=[Pe],Wd=[Pe],zd=[Pe];var $t=class{constructor(e){re(Ae,5,this),ge(this,Sr),ge(this,Ni),ge(this,Rn,new Cn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new qt,ge(this,Sa,re(Ae,8,this,!1)),re(Ae,11,this),ge(this,ja,re(Ae,12,this,null)),re(Ae,15,this),ge(this,Ca,re(Ae,16,this,null)),re(Ae,19,this),ge(this,Oa,re(Ae,20,this,null)),re(Ae,23,this),ge(this,Ea,re(Ae,24,this,[])),re(Ae,27,this),this.position=new ys({x:0,y:0}),ge(this,jr,{x:0,y:0}),at(this,Sr,e)}get shape(){const{current:e,initial:t,previous:n}=De(this,Rn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?De(this,Rn).current=e:De(this,Rn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=De(this,Sr).registry.draggables.get(t);return n&&at(this,Ni,n),(e=n??De(this,Ni))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=De(this,Sr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(la(aa({},this.snapshot()),{transform:n}));return at(this,jr,n),n}snapshot(){return de(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:De(this,jr),shape:this.shape?Ns(this.shape):null,position:Ns(this.position),status:Ns(this.status),canceled:this.canceled}))}reset(){Ie(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,De(this,Rn).reset(),this.position.reset({x:0,y:0}),at(this,jr,{x:0,y:0}),this.modifiers=[]})}};Ae=ar(null);Sr=new WeakMap;Ni=new WeakMap;Rn=new WeakMap;Sa=new WeakMap;ja=new WeakMap;Ca=new WeakMap;Oa=new WeakMap;Ea=new WeakMap;jr=new WeakMap;fe(Ae,2,"shape",Hd,$t);fe(Ae,4,"canceled",Gd,$t,Sa);fe(Ae,4,"activatorEvent",Ud,$t,ja);fe(Ae,4,"sourceIdentifier",Bd,$t,Ca);fe(Ae,4,"targetIdentifier",qd,$t,Oa);fe(Ae,4,"modifiers",Fd,$t,Ea);fe(Ae,2,"source",_d,$t);fe(Ae,2,"target",Wd,$t);fe(Ae,2,"transform",zd,$t);On(Ae,$t);var wp={get rendering(){return Promise.resolve()}};function kt(e,t){return typeof e=="function"?e(t):e??t}var kp=class{constructor(e){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(c=>c.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var t;const n=e??{},r=kt(n.plugins,[]),i=kt(n.sensors,[]),s=kt(n.modifiers,[]),o=(t=n.renderer)!=null?t:wp,a=new gp(this),l=new yp(this);this.registry=l,this.monitor=a,this.renderer=o,this.actions=new bp(this),this.dragOperation=new $t(this),this.collisionObserver=new pp(this),this.plugins=[vp,...r],this.modifiers=s,this.sensors=i;const{destroy:u}=this,d=ri(()=>{var c,f,p;const x=de(()=>this.dragOperation.modifiers),g=this.modifiers;for(const y of x)g.includes(y)||y.destroy();this.dragOperation.modifiers=(p=(f=(c=this.dragOperation.source)==null?void 0:c.modifiers)==null?void 0:f.map(y=>{const{plugin:w,options:h}=Gr(y);return new w(this,h)}))!=null?p:g});this.destroy=()=>{d(),u()}}get plugins(){return this.registry.plugins.values}set plugins(e){this.registry.plugins.values=e}get modifiers(){return this.registry.modifiers.values}set modifiers(e){this.registry.modifiers.values=e}get sensors(){return this.registry.sensors.values}set sensors(e){this.registry.sensors.values=e}},Vd=e=>{throw TypeError(e)},Ma=(e,t,n)=>t.has(e)||Vd("Cannot "+n),ne=(e,t,n)=>(Ma(e,t,"read from private field"),t.get(e)),it=(e,t,n)=>t.has(e)?Vd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ot=(e,t,n,r)=>(Ma(e,t,"write to private field"),t.set(e,n),n),Yd=(e,t,n)=>(Ma(e,t,"access private method"),n);function ks(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Kd(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(ks(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function $s(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function Ta(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ai(e){return"nodeType"in e}function lt(e){var t,n,r;return e?Ta(e)?e:ai(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function Aa(e){const{Document:t}=lt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Qt(e){return!e||Ta(e)?!1:e instanceof lt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Xd(e){return e instanceof lt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function dr(e){return e?Ta(e)?e.document:ai(e)?Aa(e)?e:Qt(e)||Xd(e)?e.ownerDocument:document:document:document}function $p(e){var t,n,r,i;const{documentElement:s}=dr(e),o=lt(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,l=(n=o?.height)!=null?n:s.clientHeight,u=(r=o?.offsetTop)!=null?r:0,d=(i=o?.offsetLeft)!=null?i:0;return{top:u,left:d,right:d+a,bottom:u+l,width:a,height:l}}function Sp(e,t){if(jp(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function jp(e){return e.tagName==="DETAILS"}function Vr(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let l=t;const{ownerDocument:u}=e,d=(r=u.defaultView)!=null?r:window;let c=e.parentElement;for(;c&&c!==u.documentElement;){if(!Sp(c)){const m=c.getBoundingClientRect(),b=n*(m.bottom-m.top),$=n*(m.right-m.left),D=n*(m.bottom-m.top),M=n*(m.right-m.left);l={top:Math.max(l.top,m.top-b),right:Math.min(l.right,m.right+$),bottom:Math.min(l.bottom,m.bottom+D),left:Math.max(l.left,m.left-M),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}c=c.parentElement}const f=d.visualViewport,p=(i=f?.offsetTop)!=null?i:0,x=(s=f?.offsetLeft)!=null?s:0,g=(o=f?.width)!=null?o:d.innerWidth,y=(a=f?.height)!=null?a:d.innerHeight,w=n*y,h=n*g;return l={top:Math.max(l.top,p-w),right:Math.min(l.right,x+g+h),bottom:Math.min(l.bottom,p+y+w),left:Math.max(l.left,x-h),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Zn(e){return{x:e.clientX,y:e.clientY}}var Zd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function wo(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const i=r.contentDocument;i&&!t.has(i)&&n.push(...wo(i,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const i=r.parent;i&&i.document&&i.document!==e&&n.push(...wo(i.document,t))}}catch{}return n}function Ia(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Qd(){var e,t;const n=Ia()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Da(e){return!e||!ai(e)?!1:e instanceof lt(e).ShadowRoot}function Zi(e){if(e&&ai(e)){let t=e.getRootNode();if(Da(t)||t instanceof Document)return t}return dr(e)}function Pa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Cp(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,s)=>{const o=r[s];xl(i)&&xl(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),yl(i)&&yl(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function xl(e){return"value"in e}function yl(e){return e.tagName==="CANVAS"}function Jd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Op(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return Jd(i,{x:t-s,y:n-o})}}return r}function Op(e){return e?.tagName==="IFRAME"}var ko=new WeakMap;function Ep(e){return e.closest(`
2
+ input:not([disabled]),
3
+ select:not([disabled]),
4
+ textarea:not([disabled]),
5
+ button:not([disabled]),
6
+ a[href],
7
+ [contenteditable]:not([contenteditable="false"])
8
+ `)}var eu=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:l,listener:u,options:d}=a,c=[o,a];o.addEventListener(l,u,d),this.entries.add(c),i.push(c)}const s=this.entries;return function(){for(const o of i){const[a,{type:l,listener:u,options:d}]=o;a.removeEventListener(l,u,d),s.delete(o)}}}};function Qn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Mp(e){const t=new Set;let n=Qn(e);for(;n;)t.add(n),n=Qn(n);return t}function Tp(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function tu(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Tp(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Ap(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function Ip(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Vr(e,t);return n>0&&r>0}var Dp=Zd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Ri,Pp=class extends Dp{constructor(e){super(t=>{if(!ne(this,Ri)){ot(this,Ri,!0);return}e(t,this)}),it(this,Ri,!1)}};Ri=new WeakMap;var wl=Array.from({length:100},(e,t)=>t/100),nu=75,mn,Qi,Ut,gn,Cr,Ve,Wr,Or,Ji,ru,iu,su=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,it(this,Ji),this.disconnect=()=>{var s,o,a;ot(this,Wr,!0),(s=ne(this,Ut))==null||s.disconnect(),(o=ne(this,gn))==null||o.disconnect(),ne(this,Cr).disconnect(),(a=ne(this,Ve))==null||a.remove()},it(this,mn,!0),it(this,Qi),it(this,Ut),it(this,gn),it(this,Cr),it(this,Ve),it(this,Wr,!1),it(this,Or,tu(()=>{var s,o,a;const{element:l}=this;if((s=ne(this,gn))==null||s.disconnect(),ne(this,Wr)||!ne(this,mn)||!l.isConnected)return;const u=(o=l.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:c}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),p=Vr(l,f),{top:x,left:g,bottom:y,right:w}=p,h=-Math.floor(x),m=-Math.floor(g),b=-Math.floor(c-w),$=-Math.floor(d-y),D=`${h}px ${b}px ${$}px ${m}px`;this.boundingClientRect=f,ot(this,gn,new IntersectionObserver(M=>{const[A]=M,{intersectionRect:E}=A;(A.intersectionRatio!==1?A.intersectionRatio:Et.intersectionRatio(E,Vr(l)))!==1&&ne(this,Or).call(this)},{threshold:wl,rootMargin:D,root:u})),ne(this,gn).observe(l),Yd(this,Ji,ru).call(this)},nu)),this.boundingClientRect=e.getBoundingClientRect(),ot(this,mn,Ip(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(ot(this,Ve,document.createElement("div")),ne(this,Ve).style.background="rgba(0,0,0,0.15)",ne(this,Ve).style.position="fixed",ne(this,Ve).style.pointerEvents="none",i.body.appendChild(ne(this,Ve))),ot(this,Cr,new IntersectionObserver(s=>{var o,a;const l=s[s.length-1],{boundingClientRect:u,isIntersecting:d}=l,{width:c,height:f}=u,p=ne(this,mn);ot(this,mn,d),!(!c&&!f)&&(p&&!d?((o=ne(this,gn))==null||o.disconnect(),this.callback(null),(a=ne(this,Ut))==null||a.disconnect(),ot(this,Ut,void 0),ne(this,Ve)&&(ne(this,Ve).style.visibility="hidden")):ne(this,Or).call(this),d&&!ne(this,Ut)&&(ot(this,Ut,new Pp(ne(this,Or))),ne(this,Ut).observe(e)))},{threshold:wl,root:i})),ne(this,mn)&&!n.skipInitial&&this.callback(this.boundingClientRect),ne(this,Cr).observe(e)}};mn=new WeakMap;Qi=new WeakMap;Ut=new WeakMap;gn=new WeakMap;Cr=new WeakMap;Ve=new WeakMap;Wr=new WeakMap;Or=new WeakMap;Ji=new WeakSet;ru=function(){ne(this,Wr)||(Yd(this,Ji,iu).call(this),!Ap(this.boundingClientRect,ne(this,Qi))&&(this.callback(this.boundingClientRect),ot(this,Qi,this.boundingClientRect)))};iu=function(){if(ne(this,Ve)){const{top:e,left:t,width:n,height:r}=Vr(this.element);ne(this,Ve).style.overflow="hidden",ne(this,Ve).style.visibility="visible",ne(this,Ve).style.top=`${Math.floor(e)}px`,ne(this,Ve).style.left=`${Math.floor(t)}px`,ne(this,Ve).style.width=`${Math.floor(n)}px`,ne(this,Ve).style.height=`${Math.floor(r)}px`}};var vi=new WeakMap,bi=new WeakMap;function Lp(e,t){let n=vi.get(e);return n||(n={disconnect:new su(e,r=>{const i=vi.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),vi.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(vi.delete(e),n.disconnect())}}function Np(e,t){const n=new Set;for(const r of e){const i=Lp(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Rp(e,t){var n;const r=e.ownerDocument;if(!bi.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(u=>u(l)),{capture:!0,passive:!0,signal:o.signal}),bi.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=bi.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),bi.delete(r))})}var Er,Mr,zi,$o,zp=class{constructor(e,t,n){this.callback=t,it(this,Er),it(this,Mr,!1),it(this,zi),it(this,$o,tu(o=>{if(!ne(this,Mr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of ne(this,zi))if(o.target.contains(a)){this.callback(ne(this,Er).boundingClientRect);break}}},nu));const r=Mp(e),i=Np(r,t),s=Rp(e,ne(this,$o));ot(this,zi,r),ot(this,Er,new su(e,t,n)),this.disconnect=()=>{ne(this,Mr)||(ot(this,Mr,!0),i(),s(),ne(this,Er).disconnect())}}};Er=new WeakMap;Mr=new WeakMap;zi=new WeakMap;$o=new WeakMap;function So(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Gn(e){try{So(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function kl(e){return!Zd||!e?!1:e===dr(e).scrollingElement}function ou(e){var t,n;const r=lt(e),i=kl(e)?$p(e):$s(e),s=r.visualViewport,o=kl(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},l=a.current.y<=0,u=a.current.x<=0,d=a.current.y>=a.max.y,c=a.current.x>=a.max.x;return{rect:i,position:a,isTop:l,isLeft:u,isBottom:d,isRight:c}}function Wp(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=ou(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&o.current.y+l>0,d=!r&&o.current.y+l<o.max.y,c=!i&&o.current.x+a>0,f=!s&&o.current.x+a<o.max.x;return{top:u,bottom:d,left:c,right:f,x:c||f,y:u||d}}var La=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},es=new La(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),_p=new La(e=>setTimeout(e,50)),ts=new Map,Fp=ts.clear.bind(ts);function At(e,t=!1){if(!t)return $l(e);let n=ts.get(e);return n||(n=$l(e),ts.set(e,n),_p.schedule(Fp),n)}function $l(e){return lt(e).getComputedStyle(e)}function qp(e,t=At(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Bp(e,t=At(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const i=t[r];return typeof i=="string"?n.test(i):!1})}var Up={excludeElement:!0,escapeShadowDOM:!0};function jo(e,t=Up){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(Aa(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&Da(a))return o(a.host);if(!Qt(a))return Xd(a)?o(a.parentElement):s;if(s.has(a))return s;const l=At(a,!0);if(r&&a===e||Bp(a,l)&&s.add(a),qp(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&s.add(u),s}return o(a.parentNode)}return e?o(e):s}function Jn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Qn(e);for(;r;){if(r===t)return n;const i=$s(r),{x:s,y:o}=Gp(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=Qn(r)}return n}function Gp(e,t=$s(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Qt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=At(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function Hp(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Yr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),i={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(i.x)&&isNaN(i.y)?null:{x:isNaN(i.x)?0:i.x,y:isNaN(i.y)?0:i.y,z:isNaN(i.z)?0:i.z}}function Ss(e){var t,n,r,i,s,o,a,l,u;const{scale:d,transform:c,translate:f}=e,p=Hp(d),x=Yr(f),g=Vp(c);if(!g&&!p&&!x)return null;const y={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},w={x:(r=x?.x)!=null?r:0,y:(i=x?.y)!=null?i:0},h={x:(s=g?.x)!=null?s:0,y:(o=g?.y)!=null?o:0,scaleX:(a=g?.scaleX)!=null?a:1,scaleY:(l=g?.scaleY)!=null?l:1};return{x:w.x+h.x,y:w.y+h.y,z:(u=x?.z)!=null?u:0,scaleX:y.x*h.scaleX,scaleY:y.y*h.scaleY}}function Vp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var ht=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(ht||{}),Yp={x:.2,y:.2},Kp={x:10,y:10};function Xp(e,t,n,r=25,i=Yp,s=Kp){const{x:o,y:a}=t,{rect:l,isTop:u,isBottom:d,isLeft:c,isRight:f}=ou(e),p=Jn(e),x=At(e,!0),g=Ss(x),y=g!==null?g?.scaleX<0:!1,w=g!==null?g?.scaleY<0:!1,h=new Et(l.left*p.scaleX+p.x,l.top*p.scaleY+p.y,l.width*p.scaleX,l.height*p.scaleY),m={x:0,y:0},b={x:0,y:0},$={height:h.height*i.y,width:h.width*i.x};return $.height>0&&(!u||w&&!d)&&a<=h.top+$.height&&n?.y!==1&&o>=h.left-s.x&&o<=h.right+s.x?(m.y=w?1:-1,b.y=r*Math.abs((h.top+$.height-a)/$.height)):$.height>0&&(!d||w&&!u)&&a>=h.bottom-$.height&&n?.y!==-1&&o>=h.left-s.x&&o<=h.right+s.x&&(m.y=w?-1:1,b.y=r*Math.abs((h.bottom-$.height-a)/$.height)),$.width>0&&(!f||y&&!c)&&o>=h.right-$.width&&n?.x!==-1&&a>=h.top-s.y&&a<=h.bottom+s.y?(m.x=y?-1:1,b.x=r*Math.abs((h.right-$.width-o)/$.width)):$.width>0&&(!c||y&&!f)&&o<=h.left+$.width&&n?.x!==1&&a>=h.top-s.y&&a<=h.bottom+s.y&&(m.x=y?1:-1,b.x=r*Math.abs((h.left+$.width-o)/$.width)),{direction:m,speed:b}}function au(e,{block:t="nearest",inline:n="nearest"}={}){if(!Qt(e))return;const r=jo(e),i=[];for(const s of r){if(!Qt(s))continue;const{top:o,left:a}=Zp(e,s);let l=o,u=a;for(const d of i)l-=d.scrollTop,u-=d.scrollLeft;if(t!=="none"){const d=l<s.scrollTop,c=l+e.offsetHeight>s.scrollTop+s.clientHeight;d!==c&&(t==="center"?s.scrollTop=l-s.clientHeight/2+e.offsetHeight/2:d?s.scrollTop=l:s.scrollTop=l+e.offsetHeight-s.clientHeight)}if(n!=="none"){const d=u<s.scrollLeft,c=u+e.offsetWidth>s.scrollLeft+s.clientWidth;d!==c&&(n==="center"?s.scrollLeft=u-s.clientWidth/2+e.offsetWidth/2:d?s.scrollLeft=u:s.scrollLeft=u+e.offsetWidth-s.clientWidth)}i.push(s)}}function Sl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!Qt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Zp(e,t){const n=Sl(e),r=Sl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Qp(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),l=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,d=i?e.height*i:e.height;return{width:u,height:d,top:l,right:a+u,bottom:l+d,left:a}}function Jp(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),l=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,d=i?e.height/i:e.height;return{width:u,height:d,top:l,right:a+u,bottom:l+d,left:a}}function lu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function jl(e,t=At(e).translate,n=!0){if(n){const r=Kd(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=Yr(i);if(s)return s}}}if(t){const r=Yr(t);if(r)return r}return{x:0,y:0,z:0}}var em=new La(e=>setTimeout(e,0)),_r=new Map,tm=_r.clear.bind(_r);function nm(e){const t=e.ownerDocument;let n=_r.get(t);if(n)return n;n=t.getAnimations(),_r.set(t,n),em.schedule(tm);const r=n.filter(i=>ks(i.effect)&&i.effect.target===e);return _r.set(e,r),n}function rm(e,t){const n=nm(e).filter(r=>{var i,s;if(ks(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))==null||s)return r.effect.getKeyframes().some(a=>{for(const l of t.properties)if(a[l])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Ot=class extends Et{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=Jn(e),ignoreTransforms:a,getBoundingClientRect:l=$s}=t,u=rm(e,{properties:["transform","translate","scale","width","height"],isValidTarget:$=>($!==e||Ia())&&$.contains(e)}),d=l(e);let{top:c,left:f,width:p,height:x}=d,g;const y=At(e),w=Ss(y),h={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},m=im(e,y);u?.(),w&&(g=Jp(d,w,y.transformOrigin),(a||m)&&(c=g.top,f=g.left,p=g.width,x=g.height));const b={width:(i=g?.width)!=null?i:p,height:(s=g?.height)!=null?s:x};if(m&&!a&&g){const $=Qp(g,m,y.transformOrigin);c=$.top,f=$.left,p=$.width,x=$.height,h.x=m.scaleX,h.y=m.scaleY}o&&(a||(f*=o.scaleX,p*=o.scaleX,c*=o.scaleY,x*=o.scaleY),f+=o.x,c+=o.y),super(f,c,p,x),this.scale=h,this.intrinsicWidth=b.width,this.intrinsicHeight=b.height}};function im(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=ks(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:d,translate:c,scale:f}=u;typeof d=="string"&&d&&(r=d,o=!0),typeof c=="string"&&c&&(i=c,o=!0),typeof f=="string"&&f&&(s=f,o=!0)}return o?Ss({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function Fr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var sm=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Fr(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(Fr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(Fr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function kn(e){return e?e instanceof lt(e).Element||ai(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Kr(e){if(!e)return!1;const{KeyboardEvent:t}=lt(e.target);return e instanceof t}function om(e){if(!e)return!1;const{PointerEvent:t}=lt(e.target);return e instanceof t}function am(e){if(!kn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||lm(e)}function lm(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var zs={};function Co(e){const t=zs[e]==null?0:zs[e]+1;return zs[e]=t,`${e}-${t}`}var Na=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=ft.distance(t.shape.center,n);return{id:r,value:1/i,type:cr.PointerIntersection,priority:lr.High}}return null},cm=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=ft.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:cr.ShapeIntersection,priority:lr.Normal}}return null},cu=e=>{var t;return(t=Na(e))!=null?t:cm(e)},dm=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?Et.from(r.current.boundingRectangle).corners:void 0,o=Et.from(n.shape.boundingRectangle).corners.reduce((a,l,u)=>{var d;return a+ft.distance(ft.from(l),(d=s?.[u])!=null?d:i.current)},0)/4;return{id:n.id,value:1/o,type:cr.Collision,priority:lr.Normal}},um=Object.create,Ra=Object.defineProperty,fm=Object.defineProperties,hm=Object.getOwnPropertyDescriptor,pm=Object.getOwnPropertyDescriptors,ns=Object.getOwnPropertySymbols,du=Object.prototype.hasOwnProperty,uu=Object.prototype.propertyIsEnumerable,fu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ur=e=>{throw TypeError(e)},Oo=(e,t,n)=>t in e?Ra(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xr=(e,t)=>{for(var n in t||(t={}))du.call(t,n)&&Oo(e,n,t[n]);if(ns)for(var n of ns(t))uu.call(t,n)&&Oo(e,n,t[n]);return e},za=(e,t)=>fm(e,pm(t)),Cl=(e,t)=>Ra(e,"name",{value:t,configurable:!0}),hu=(e,t)=>{var n={};for(var r in e)du.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ns)for(var r of ns(e))t.indexOf(r)<0&&uu.call(e,r)&&(n[r]=e[r]);return n},fr=e=>{var t;return[,,,um((t=e?.[fu("metadata")])!=null?t:null)]},pu=["class","method","getter","setter","accessor","field","value","get","set"],Tr=e=>e!==void 0&&typeof e!="function"?ur("Function expected"):e,mm=(e,t,n,r,i)=>({kind:pu[e],name:t,metadata:r,addInitializer:s=>n._?ur("Already initialized"):i.push(Tr(s||null))}),En=(e,t)=>Oo(t,fu("metadata"),e[3]),_e=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},vt=(e,t,n,r,i,s)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),x=c>3?e.length+1:c?f?1:2:0,g=pu[c+5],y=c>3&&(e[x-1]=[]),w=e[x]||(e[x]=[]),h=c&&(!p&&!f&&(i=i.prototype),c<5&&(c>3||!p)&&hm(c<4?i:{get[n](){return ke(this,s)},set[n](b){return tt(this,s,b)}},n));c?p&&c<4&&Cl(s,(c>2?"set ":c>1?"get ":"")+n):Cl(i,n);for(var m=r.length-1;m>=0;m--)u=mm(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>gm(i,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?ke:$n)(b,i,c^4?s:h.get):b=>b[n]),c>2&&(d.set=p?(b,$)=>tt(b,i,$,c^4?s:h.set):(b,$)=>b[n]=$)),a=(0,r[m])(c?c<4?p?s:h[g]:c>4?void 0:{get:h.get,set:h.set}:i,u),l._=1,c^4||a===void 0?Tr(a)&&(c>4?y.unshift(a):c?p?s=a:h[g]=a:i=a):typeof a!="object"||a===null?ur("Object expected"):(Tr(o=a.get)&&(h.get=o),Tr(o=a.set)&&(h.set=o),Tr(o=a.init)&&y.unshift(o));return c||En(e,i),h&&Ra(i,n,h),p?c^4?s:h:i},Wa=(e,t,n)=>t.has(e)||ur("Cannot "+n),gm=(e,t)=>Object(t)!==t?ur('Cannot use the "in" operator on this value'):e.has(t),ke=(e,t,n)=>(Wa(e,t,"read from private field"),n?n.call(e):t.get(e)),Le=(e,t,n)=>t.has(e)?ur("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),tt=(e,t,n,r)=>(Wa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),$n=(e,t,n)=>(Wa(e,t,"access private method"),n),Ol={role:"button",roleDescription:"draggable"},vm="dnd-kit-description",bm="dnd-kit-announcement",xm={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},ym={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function wm(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function km(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function $m(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Sm=["dragover","dragmove"],jm=class extends Ze{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=vm,announcement:i=bm}={},announcements:s=ym,screenReaderInstructions:o=xm,debounce:a=500}=t??{},l=n?`${r}-${n}`:Co(r),u=n?`${i}-${n}`:Co(i);let d,c,f,p;const x=($=p)=>{!f||!$||f?.nodeValue!==$&&(f.nodeValue=$)},g=()=>es.schedule(x),y=Cm(g,a),w=Object.entries(s).map(([$,D])=>this.manager.monitor.addEventListener($,(M,A)=>{const E=f;if(!E)return;const T=D?.(M,A);T&&E.nodeValue!==T&&(p=T,Sm.includes($)?y():(g(),y.cancel()))})),h=()=>{let $=[];d?.isConnected||(d=km(l,o.draggable),$.push(d)),c?.isConnected||(c=$m(u),f=document.createTextNode(""),c.appendChild(f),$.push(c)),$.length>0&&document.body.append(...$)},m=new Set;function b(){for(const $ of m)$()}this.registerEffect(()=>{var $;m.clear();for(const D of this.manager.registry.draggables.value){const M=($=D.handle)!=null?$:D.element;if(M){(!d||!c)&&m.add(h),(!wm(M)||Ia())&&!M.hasAttribute("tabindex")&&m.add(()=>M.setAttribute("tabindex","0")),!M.hasAttribute("role")&&M.tagName.toLowerCase()!=="button"&&m.add(()=>M.setAttribute("role",Ol.role)),M.hasAttribute("aria-roledescription")||m.add(()=>M.setAttribute("aria-roledescription",Ol.roleDescription)),M.hasAttribute("aria-describedby")||m.add(()=>M.setAttribute("aria-describedby",l));for(const E of["aria-pressed","aria-grabbed"]){const T=String(D.isDragging);M.getAttribute(E)!==T&&m.add(()=>M.setAttribute(E,T))}const A=String(D.disabled);M.getAttribute("aria-disabled")!==A&&m.add(()=>M.setAttribute("aria-disabled",A))}}m.size>0&&es.schedule(b)}),this.destroy=()=>{super.destroy(),d?.remove(),c?.remove(),w.forEach($=>$())}}};function Cm(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var rs=new Map,mu,gu,vu,bu,Eo,qr,Wt,_a,er,xu,yu,wu,ku,Jt=class extends(Eo=oi,bu=[ue],vu=[Pe],gu=[Pe],mu=[Pe],Eo){constructor(e,t){super(e,t),_e(Wt,5,this),Le(this,er),Le(this,qr,new Set),Le(this,_a,_e(Wt,8,this,new Set)),_e(Wt,11,this),this.registerEffect($n(this,er,xu))}register(e){return ke(this,qr).add(e),()=>{ke(this,qr).delete(e)}}addRoot(e){return de(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{de(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return Zi((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return Zi((e=t?.element)!=null?e:null)}get roots(){const{status:e}=this.manager.dragOperation;if(e.initializing||e.initialized){const t=[this.sourceRoot,this.targetRoot].filter(n=>n!=null);return new Set([...t,...this.additionalRoots])}return new Set}};Wt=fr(Eo);qr=new WeakMap;_a=new WeakMap;er=new WeakSet;xu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ke(this,qr))t.push($n(this,er,yu).call(this,n,r));return()=>{for(const n of t)n()}};yu=function(e,t){let n=rs.get(e);n||(n=new Map,rs.set(e,n));let r=n.get(t);if(!r){const s=Aa(e)?$n(this,er,wu).call(this,e,n,t):$n(this,er,ku).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};wu=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&rs.delete(e)}}};ku=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(Da(e)&&(o=e.host)!=null&&o.isConnected){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&rs.delete(e)}}};vt(Wt,4,"additionalRoots",bu,Jt,_a);vt(Wt,2,"sourceRoot",vu,Jt);vt(Wt,2,"targetRoot",gu,Jt);vt(Wt,2,"roots",mu,Jt);En(Wt,Jt);Jt.configure=si(Jt);var js=Jt,Om=class extends Ze{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(js),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},li="data-dnd-",Mo=`${li}dropping`,He="--dnd-",jt=`${li}dragging`,is=`${li}placeholder`,Em=[jt,is,"popover","aria-pressed","aria-grabbing"],Mm=["view-transition-name"],Tm=`
9
+ :is(:root,:host) [${jt}] {
10
+ position: fixed !important;
11
+ pointer-events: none !important;
12
+ touch-action: none;
13
+ z-index: calc(infinity);
14
+ will-change: translate;
15
+ top: var(${He}top, 0px) !important;
16
+ left: var(${He}left, 0px) !important;
17
+ right: unset !important;
18
+ bottom: unset !important;
19
+ width: var(${He}width, auto);
20
+ max-width: var(${He}width, auto);
21
+ height: var(${He}height, auto);
22
+ max-height: var(${He}height, auto);
23
+ transform: var(${He}transform, none) !important;
24
+ transition: var(${He}transition) !important;
25
+ }
26
+
27
+ :is(:root,:host) [${is}] {
28
+ transition: none;
29
+ }
30
+
31
+ :is(:root,:host) [${is}='hidden'] {
32
+ visibility: hidden;
33
+ }
34
+
35
+ [${jt}] * {
36
+ pointer-events: none !important;
37
+ }
38
+
39
+ [${jt}]:not([${Mo}]) {
40
+ translate: var(${He}translate) !important;
41
+ }
42
+
43
+ [${jt}][style*='${He}scale'] {
44
+ scale: var(${He}scale) !important;
45
+ transform-origin: var(${He}transform-origin) !important;
46
+ }
47
+
48
+ @layer dnd-kit {
49
+ :where([${jt}][popover]) {
50
+ overflow: visible;
51
+ background: unset;
52
+ border: unset;
53
+ margin: unset;
54
+ padding: unset;
55
+ color: inherit;
56
+
57
+ &:is(input, button) {
58
+ border: revert;
59
+ background: revert;
60
+ }
61
+ }
62
+ }
63
+ [${jt}]::backdrop, [${li}overlay]:not([${jt}]) {
64
+ display: none;
65
+ visibility: hidden;
66
+ }
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Am(e,t="hidden"){return de(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Im(n,r.registry.droppables),s=[],o=Cp(n),{remove:a}=o;return Dm(i,o,s),Pm(o,t),o.remove=()=>{s.forEach(l=>l()),a.call(o)},o})}function Im(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${li}${Co("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Dm(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),ko.set(a,o),n.push(()=>{ko.delete(a),r.proxy=void 0})}}function Pm(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(is,t)}function $u(e,t){return e===t?!0:Qn(e)===Qn(t)}function El(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&kn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Gn(t))}function To(e){return e.tagName==="TR"}function Lm(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Em.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(Fr(e)&&Fr(t)){const u=e.style;for(const d of Array.from(t.style))u.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(u)){if(Mm.includes(d)||d.startsWith(He))continue;const c=u.getPropertyValue(d);t.style.setProperty(d,c)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Nm(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Gn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Gn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Gn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Rm(e){return new ResizeObserver(()=>{var t,n,r;const i=new Ot(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,l=Qd();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},He),(n=e.getElementMutationObserver())==null||n.takeRecords(),To(e.element)&&To(e.placeholder)){const g=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(g.map(w=>w.style.width));for(const[w,h]of g.entries()){const m=y[w];h.style.width=`${m.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+l.x+u.x,c=e.top+a+l.y+u.y,f=i.width-e.widthOffset,p=i.height-e.heightOffset,x=e.frameTransform;e.dragOperation.shape=new Et(d*x.scaleX+x.x,c*x.scaleY+x.y,f*x.scaleX,p*x.scaleY)})}var zm=250,Wm="ease";function _m(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const h=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(h).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=zm,easing:a=Wm}=s??{};Gn(e.feedbackElement);const[,l]=(t=Kd(e.feedbackElement,h=>"translate"in h))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,d={frameTransform:$u(e.feedbackElement,u)?null:void 0},c=new Ot(e.feedbackElement,d),f=(r=Yr(At(e.feedbackElement).translate))!=null?r:e.translate,p=new Ot(u,d),x=Et.delta(c,p,e.alignment),g={x:f.x-x.x,y:f.y-x.y},y=Math.round(c.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},w=Math.round(c.intrinsicWidth)!==Math.round(p.intrinsicWidth)?{minWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`],maxWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},He),e.feedbackElement.setAttribute(Mo,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),lu({element:e.feedbackElement,keyframes:za(Xr(Xr({},y),w),{translate:[`${f.x}px ${f.y}px 0`,`${g.x}px ${g.y}px 0`]}),options:{duration:Pa(lt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Mo),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Su,Ao,Zr,Fa,Wi,ju,Cu,tr=class extends(Ao=Ze,Su=[ue],Ao){constructor(e,t){super(e,t),Le(this,Wi),Le(this,Fa,_e(Zr,8,this)),_e(Zr,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(js),r=n?.register(Tm);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect($n(this,Wi,ju).bind(this,n)),this.registerEffect($n(this,Wi,Cu))}};Zr=fr(Ao);Fa=new WeakMap;Wi=new WeakSet;ju=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Zi(t);if(n)return e.addRoot(n)};Cu=function(){var e,t,n,r,i,s,o;const{state:a,manager:l,options:u}=this,{dragOperation:d}=l,{position:c,source:f,status:p}=d;if(p.idle){a.current={},a.initial={};return}if(!f)return;const{element:x}=f,g=f.pluginConfig(tr),y=(t=(e=g?.feedback)!=null?e:u?.feedback)!=null?t:"default",w=typeof y=="function"?y(f,l):y;if(!x||w==="none"||!p.initialized||p.initializing)return;const{initial:h}=a,m=(n=this.overlay)!=null?n:x,b=Jn(m),$=Jn(x),D=!$u(x,m),M=new Ot(x,{frameTransform:D?$:null,ignoreTransforms:!D}),A={x:$.scaleX/b.scaleX,y:$.scaleY/b.scaleY};let{width:E,height:T,top:F,left:z}=M;D&&(E=E/A.x,T=T/A.y);const q=new sm(m),K=At(x),{transition:X,translate:oe,boxSizing:ae,paddingBlockStart:Q,paddingBlockEnd:he,paddingInlineStart:O,paddingInlineEnd:B,borderInlineStartWidth:W,borderInlineEndWidth:L,borderBlockStartWidth:_,borderBlockEndWidth:N}=K,H=X.split(",").filter(C=>!/^\s*(transform|translate|scale)\b/.test(C)).join(","),j=Ss(K),S=K.transform,I=w==="clone",Z=ae==="content-box",V=Z?parseInt(O)+parseInt(B)+parseInt(W)+parseInt(L):0,se=Z?parseInt(Q)+parseInt(he)+parseInt(_)+parseInt(N):0,Y=w!=="move"&&!this.overlay?Am(f,I?"clone":"hidden"):null,ve=de(()=>Kr(l.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&j)h.translate={x:j.x,y:j.y};else if(oe!=="none"){const C=Yr(oe);C&&(h.translate=C)}}if(!h.transformOrigin){const C=de(()=>c.current),P=z+((r=j?.x)!=null?r:0),U=F+((i=j?.y)!=null?i:0);h.transformOrigin={x:(C.x-P*b.scaleX-b.x)/(E*b.scaleX),y:(C.y-U*b.scaleY-b.y)/(T*b.scaleY)}}const{transformOrigin:J}=h,be=F*b.scaleY+b.y,le=z*b.scaleX+b.x;if(!h.coordinates&&(h.coordinates={x:le,y:be},A.x!==1||A.y!==1)){const{scaleX:C,scaleY:P}=$,{x:U,y:ee}=J;h.coordinates.x+=(E*C-E)*U,h.coordinates.y+=(T*P-T)*ee}h.dimensions||(h.dimensions={width:E,height:T}),h.frameTransform||(h.frameTransform=b);const me={x:h.coordinates.x-le,y:h.coordinates.y-be},Ge={width:(h.dimensions.width*h.frameTransform.scaleX-E*b.scaleX)*J.x,height:(h.dimensions.height*h.frameTransform.scaleY-T*b.scaleY)*J.y},te={x:me.x/b.scaleX+Ge.width,y:me.y/b.scaleY+Ge.height},R={left:z+te.x,top:F+te.y};m.setAttribute(jt,"true");const G=de(()=>d.transform),ce=(s=h.translate)!=null?s:{x:0,y:0},pe=G.x*b.scaleX+ce.x,Fe=G.y*b.scaleY+ce.y,It=Qd();q.set({width:E-V,height:T-se,top:R.top+It.y,left:R.left+It.x,translate:`${pe}px ${Fe}px 0`,transform:this.overlay?"none":S,transition:H?`${H}, translate 0ms linear`:"translate 0ms linear",scale:D?`${A.x} ${A.y}`:"","transform-origin":`${J.x*100}% ${J.y*100}%`},He),Y&&(x.insertAdjacentElement("afterend",Y),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(x)),So(m)&&(m.hasAttribute("popover")||m.setAttribute("popover","manual"),Gn(m),m.addEventListener("beforetoggle",El));let Ke,tn,ct;const Dt=Rm({placeholder:Y,element:x,feedbackElement:m,frameTransform:b,transformOrigin:J,width:E,height:T,top:F,left:z,widthOffset:V,heightOffset:se,delta:te,styles:q,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>Ke,getSavedCellWidths:()=>ct,setSavedCellWidths:C=>{ct=C}}),nn=new Ot(m);de(()=>d.shape=nn);const Bt=lt(m),Pt=C=>{this.manager.actions.stop({event:C})},rn=Pa(Bt);ve&&Bt.addEventListener("resize",Pt),de(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Y&&(Dt.observe(Y),Ke=Lm(x,Y,I),tn=Nm(x,Y,m));const dt=(o=l.dragOperation.source)==null?void 0:o.id,pr=()=>{var C;if(!ve||dt==null)return;const P=l.registry.draggables.get(dt),U=(C=P?.handle)!=null?C:P?.element;Qt(U)&&U.focus()},Lt=()=>{Ke?.disconnect(),tn?.disconnect(),Dt.disconnect(),Bt.removeEventListener("resize",Pt),So(m)&&(m.removeEventListener("beforetoggle",El),m.removeAttribute("popover")),m.removeAttribute(jt),q.reset();const C=()=>{var P;if(ct&&To(x)){const Ne=Array.from(x.cells);for(const[$e,Se]of Ne.entries())Se.style.width=(P=ct[$e])!=null?P:""}f.status="idle";const U=a.current.translate!=null,ee=d.status.dragging;Y&&(!ee&&U||Y.parentElement!==m.parentElement)&&m.isConnected&&Y.replaceWith(m),Y?.remove()};m===this.overlay?setTimeout(C,0):C()},sn=u?.dropAnimation,on=this,mr=ri(()=>{var C,P,U;const{transform:ee,status:Ne}=d;if(!(!ee.x&&!ee.y&&!a.current.translate)&&Ne.dragging){const $e=(C=h.translate)!=null?C:{x:0,y:0},Se={x:ee.x/b.scaleX+$e.x,y:ee.y/b.scaleY+$e.y},bt=a.current.translate,mi=de(()=>d.modifiers),gr=de(()=>{var ln;return(ln=d.shape)==null?void 0:ln.current}),an=u?.keyboardTransition,vr=ve&&!rn&&an!==null?`${(P=an?.duration)!=null?P:250}ms ${(U=an?.easing)!=null?U:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(q.set({transition:H?`${H}, translate ${vr}`:`translate ${vr}`,translate:`${Se.x}px ${Se.y}px 0`},He),Ke?.takeRecords(),gr&&gr!==nn&&bt&&!mi.length){const ln=ft.delta(Se,bt);d.shape=Et.from(gr.boundingRectangle).translate(ln.x*b.scaleX,ln.y*b.scaleY)}else d.shape=new Ot(m);a.current.translate=Se}},function(){if(d.status.dropped){this.dispose(),f.status="dropping";const C=g?.dropAnimation!==void 0?g.dropAnimation:on.dropAnimation!==void 0?on.dropAnimation:sn;let P=a.current.translate;const U=P!=null;if(!P&&x!==m&&(P={x:0,y:0}),!P||C===null){Lt();return}l.renderer.rendering.then(()=>{_m({source:f,element:x,feedbackElement:m,placeholder:Y,translate:P,moved:U,transition:X,alignment:f.alignment,styles:q,animation:C??void 0,getElementMutationObserver:()=>Ke,cleanup:Lt,restoreFocus:pr})})}});return()=>{Lt(),mr()}};vt(Zr,4,"overlay",Su,tr,Fa);En(Zr,tr);tr.configure=si(tr);var qa=tr,br=!0,Fm=!1,Ou,Eu,Mu,Tu,Vt,Ba,Ua;Tu=(Mu=[ue],ht.Forward),Eu=(Ou=[ue],ht.Reverse);var Qr=class{constructor(){Le(this,Ba,_e(Vt,8,this,br)),_e(Vt,11,this),Le(this,Ua,_e(Vt,12,this,br)),_e(Vt,15,this)}isLocked(e){return e===ht.Idle?!1:e==null?this[ht.Forward]===br&&this[ht.Reverse]===br:this[e]===br}unlock(e){e!==ht.Idle&&(this[e]=Fm)}};Vt=fr(null);Ba=new WeakMap;Ua=new WeakMap;vt(Vt,4,Tu,Mu,Qr,Ba);vt(Vt,4,Eu,Ou,Qr,Ua);En(Vt,Qr);var qm=[ht.Forward,ht.Reverse],Ml=class{constructor(){this.x=new Qr,this.y=new Qr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Bm=class extends Ze{constructor(e){super(e);const t=nr(new Ml);let n=null;this.signal=t,gt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Ml;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Tl(i.x,n.x),y:Tl(i.y,n.y)},o=t.peek();Ie(()=>{for(const a of sd)for(const l of qm)s[a]===l&&o[a].unlock(l);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Tl(e,t){return Math.sign(e-t)}var Au,Io,Jr,Ga,Gt,Do,ci=class extends(Io=oi,Au=[ue],Io){constructor(e){super(e),Le(this,Ga,_e(Jr,8,this,!1)),_e(Jr,11,this),Le(this,Gt),Le(this,Do,()=>{if(!ke(this,Gt))return;const{element:s,by:o}=ke(this,Gt);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return tt(this,Gt,void 0),!1;const{position:u}=this.manager.dragOperation,d=u?.current;if(d){const{by:c}=s??{},f=c?{x:Al(c.x),y:Al(c.y)}:void 0,p=f?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const x of l){const g=Wp(x,c);if(g.x||g.y){const{speed:y,direction:w}=Xp(x,d,f,o?.acceleration,o?.threshold);if(p)for(const h of sd)p[h].isLocked(w[h])&&(y[h]=0,w[h]=0);if(w.x||w.y){const{x:h,y:m}=c??w,b=h*y.x,$=m*y.y;if(b||$){const D=(a=ke(this,Gt))==null?void 0:a.by;if(this.autoScrolling&&D&&(D.x&&!b||D.y&&!$))continue;return tt(this,Gt,{element:x,by:{x:b,y:$}}),es.schedule(ke(this,Do)),!0}}}}}return tt(this,Gt,void 0),!1};let t=null,n=null;const r=ao(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=Jd(Zi(o?.element),s.current);return a&&(t=a),a??t}),i=ao(()=>{const s=r.value,{documentElement:o}=dr(s);if(!s||s===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=jo(l,{excludeElement:!1});return n=u,u}}if(s){const a=jo(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},yt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new Bm(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!Kr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};Jr=fr(Io);Ga=new WeakMap;Gt=new WeakMap;Do=new WeakMap;vt(Jr,4,"autoScrolling",Au,ci,Ga);En(Jr,ci);function Al(e){return e>0?ht.Forward:e<0?ht.Reverse:ht.Idle}var Um=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},Gm=new Um(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Hm=10,Po=class extends Ze{constructor(e,t){super(e,t);const n=e.registry.plugins.get(ci);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=gt(()=>{var r,i,s;if(this.disabled)return;const{position:o,status:a}=e.dragOperation;if(a.dragging){const l={acceleration:(r=this.options)==null?void 0:r.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(s=this.options)==null?void 0:s.threshold};if(n.scroll(void 0,l)){n.autoScrolling=!0;const u=setInterval(()=>Gm.schedule(()=>n.scroll(void 0,l)),Hm);return()=>{clearInterval(u)}}else n.autoScrolling=!1}})}};Po.configure=si(Po);var Iu=Po,Il={capture:!0,passive:!0},Ar,Vm=class extends oi{constructor(e){super(e),Le(this,Ar),this.handleScroll=()=>{ke(this,Ar)==null&&tt(this,Ar,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),tt(this,Ar,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=gt(()=>{var n,r,i;if(t.status.dragging){const s=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return s.addEventListener("scroll",this.handleScroll,Il),()=>{s.removeEventListener("scroll",this.handleScroll,Il)}}})}};Ar=new WeakMap;var Ym="* { user-select: none !important; -webkit-user-select: none !important; }",Km=class extends Ze{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(js),n=t?.register(Ym);if(this.destroy=gt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ws(),document.addEventListener("selectionchange",Ws,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ws,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ws(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Ir=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),zn,ss=class extends Xn{constructor(e,t){super(e),this.manager=e,this.options=t,Le(this,zn,[]),this.listeners=new eu,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!kn(n.target)||r.disabled)return;const{keyboardCodes:s=Ir.keyboardCodes,preventActivation:o=Ir.preventActivation}=i??{};s.start.includes(n.code)&&this.manager.dragOperation.status.idle&&(o?.(n,r)||this.handleStart(n,r,i))}}bind(e,t=this.options){return gt(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{Kr(s)&&this.handleSourceKeyDown(s,e,t)};if(r)return r.addEventListener("keydown",i),()=>{r.removeEventListener("keydown",i)}})}handleStart(e,t,n){const{element:r}=t;if(!r)throw new Error("Source draggable does not have an associated element");e.preventDefault(),e.stopImmediatePropagation(),au(r);const{center:i}=new Ot(r);if(this.manager.actions.start({event:e,coordinates:{x:i.x,y:i.y},source:t}).signal.aborted)return this.cleanup();this.sideEffects();const s=dr(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];ke(this,zn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=Ir.keyboardCodes}=n??{};if(Mn(e,[...r.end,...r.cancel])){e.preventDefault();const i=Mn(e,r.cancel);this.handleEnd(e,i);return}Mn(e,r.up)?this.handleMove("up",e):Mn(e,r.down)&&this.handleMove("down",e),Mn(e,r.left)?this.handleMove("left",e):Mn(e,r.right)&&this.handleMove("right",e)}handleEnd(e,t){this.manager.actions.stop({event:e,canceled:t}),this.cleanup()}handleMove(e,t){var n,r;const{shape:i}=this.manager.dragOperation,s=t.shiftKey?5:1;let o={x:0,y:0},a=(r=(n=this.options)==null?void 0:n.offset)!=null?r:Ir.offset;if(typeof a=="number"&&(a={x:a,y:a}),!!i){switch(e){case"up":o={x:0,y:-a.y*s};break;case"down":o={x:0,y:a.y*s};break;case"left":o={x:-a.x*s,y:0};break;case"right":o={x:a.x*s,y:0};break}(o.x||o.y)&&(t.preventDefault(),this.manager.actions.move({event:t,by:o}))}}sideEffects(){const e=this.manager.registry.plugins.get(Iu);e?.disabled===!1&&(e.disable(),ke(this,zn).push(()=>{e.enable()}))}cleanup(){ke(this,zn).forEach(e=>e()),tt(this,zn,[])}destroy(){this.cleanup(),this.listeners.clear()}};zn=new WeakMap;ss.configure=si(ss);ss.defaults=Ir;var Du=ss;function Mn(e,t){return t.includes(e.code)}var vn,Xm=class extends Rd{constructor(){super(...arguments),Le(this,vn)}onEvent(e){switch(e.type){case"pointerdown":tt(this,vn,Zn(e));break;case"pointermove":if(!ke(this,vn))return;const{x:t,y:n}=Zn(e),r={x:t-ke(this,vn).x,y:n-ke(this,vn).y},{tolerance:i}=this.options;if(i&&vo(r,i)){this.abort();return}vo(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){tt(this,vn,void 0)}};vn=new WeakMap;var Wn,bn,Zm=class extends Rd{constructor(){super(...arguments),Le(this,Wn),Le(this,bn)}onEvent(e){switch(e.type){case"pointerdown":tt(this,bn,Zn(e)),tt(this,Wn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ke(this,bn))return;const{x:t,y:n}=Zn(e),r={x:t-ke(this,bn).x,y:n-ke(this,bn).y};vo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ke(this,Wn)&&(clearTimeout(ke(this,Wn)),tt(this,bn,void 0),tt(this,Wn,void 0))}};Wn=new WeakMap;bn=new WeakMap;var Bn=class{};Bn.Delay=Zm;Bn.Distance=Xm;var Lo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&kn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new Bn.Delay({value:250,tolerance:5})]:am(i)&&!e.defaultPrevented?[new Bn.Delay({value:200,tolerance:0})]:[new Bn.Delay({value:200,tolerance:10}),new Bn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!kn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=Ep(r);return i===t.element?!1:!!i}}),_n,os=class extends Xn{constructor(e,t){super(e),this.manager=e,this.options=t,Le(this,_n,new Set),this.listeners=new eu,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:n,coordinates:r}=this.latest;!n||!r||this.manager.actions.move({event:n,to:r})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(e,t,n=this.options){const{activationConstraints:r=Lo.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return gt(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{om(a)&&this.handlePointerDown(a,e,t)};let o=[(n=e.handle)!=null?n:e.element];t?.activatorElements&&(Array.isArray(t.activatorElements)?o=t.activatorElements:o=t.activatorElements(e));for(const a of o)a&&(eg(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!kn(e.target)||t.disabled||Qm(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=Lo.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=Qt(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=Jn(t.element),{x:a,y:l}=Zn(e);this.initialCoordinates={x:a*o.scaleX+o.x,y:l*o.scaleY+o.y};const u=this.activationConstraints(e,t,n);e.sensor=this;const d=new xp(u,x=>this.handleStart(t,x));d.signal.onabort=()=>this.handleCancel(e),d.onEvent(e),this.controller=d;const c=wo(),f=this.listeners.bind(c,[{type:"pointermove",listener:x=>this.handlePointerMove(x,t)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:s?this.handleCancel:xi,options:{capture:!0}}]),p=()=>{f(),this.initialCoordinates=void 0};ke(this,_n).add(p)}handlePointerMove(e,t){var n,r;if(((n=this.controller)==null?void 0:n.activated)===!1){(r=this.controller)==null||r.onEvent(e);return}if(this.manager.dragOperation.status.dragging){const i=Zn(e),s=Jn(t.element);i.x=i.x*s.scaleX+s.x,i.y=i.y*s.scaleY+s.y,e.preventDefault(),e.stopPropagation(),this.latest.event=e,this.latest.coordinates=i,es.schedule(this.handleMove)}}handlePointerUp(e){const{status:t}=this.manager.dragOperation;if(!t.idle){e.preventDefault(),e.stopPropagation();const n=!t.initialized;this.manager.actions.stop({event:e,canceled:n})}this.cleanup()}handleKeyDown(e){e.key==="Escape"&&(e.preventDefault(),this.handleCancel(e))}handleStart(e,t){const{manager:n,initialCoordinates:r}=this;if(!r||!n.dragOperation.status.idle||t.defaultPrevented)return;if(n.actions.start({coordinates:r,event:t,source:e}).signal.aborted)return this.cleanup();t.preventDefault();const i=dr(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=kn(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:xi,options:{passive:!1}},{type:"click",listener:xi},{type:"contextmenu",listener:xi},{type:"keydown",listener:this.handleKeyDown}]);ke(this,_n).add(o)}handleCancel(e){const{dragOperation:t}=this.manager;t.status.initialized&&this.manager.actions.stop({event:e,canceled:!0}),this.cleanup()}cleanup(){const{controller:e}=this;this.controller=void 0,e&&!e.signal.aborted&&e.abort(),this.latest={event:void 0,coordinates:void 0},ke(this,_n).forEach(t=>t()),ke(this,_n).clear()}destroy(){this.cleanup(),this.listeners.clear()}};_n=new WeakMap;os.configure=si(os);os.defaults=Lo;var Pu=os;function Qm(e){return"sensor"in e}function xi(e){e.preventDefault()}function Jm(){}var Dl=new WeakSet;function eg(e){!e||Dl.has(e)||(e.addEventListener("touchmove",Jm,{capture:!1,passive:!1}),Dl.add(e))}var Hn={modifiers:[],plugins:[jm,Iu,Om,qa,Km],sensors:[Pu,Du]},Lu=class extends kp{constructor(e={}){const t=kt(e.plugins,Hn.plugins),n=kt(e.sensors,Hn.sensors),r=kt(e.modifiers,Hn.modifiers);super(za(Xr({},e),{plugins:[Vm,ci,js,...t],sensors:n,modifiers:r}))}},Nu,Ru,No,Yt,Ha,Va,Cs=class extends(No=Mt,Ru=[ue],Nu=[ue],No){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=hu(n,["element","effects","handle"]);super(Xr({effects:()=>[...i(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(Gr))!=null?l:[...u.sensors]).map(c=>{const f=c instanceof Xn?c:u.registry.register(c.plugin),p=c instanceof Xn?void 0:c.options;return f.bind(this,p)});return function(){d.forEach(c=>c())}}]},o),t),Le(this,Ha,_e(Yt,8,this)),_e(Yt,11,this),Le(this,Va,_e(Yt,12,this)),_e(Yt,15,this),this.element=r,this.handle=s}};Yt=fr(No);Ha=new WeakMap;Va=new WeakMap;vt(Yt,4,"handle",Ru,Cs,Ha);vt(Yt,4,"element",Nu,Cs,Va);En(Yt,Cs);var zu,Wu,Ro,Kt,Ya,_s,_u,Fu,Br,Ka,Os=class extends(Ro=Tt,Wu=[ue],zu=[ue],Ro){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=hu(n,["element","effects"]);const{collisionDetector:o=cu}=s,a=u=>{const{manager:d,element:c}=this;if(!c||u===null){this.shape=void 0;return}if(!d)return;const f=new Ot(c),p=de(()=>this.shape);return f&&p?.equals(f)?p:(this.shape=f,f)},l=nr(!1);super(za(Xr({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:u,manager:d}=this;if(!d)return;const{dragOperation:c}=d,{source:f}=c;l.value=!!(f&&c.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const d=new zp(u,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Le(this,Br),Le(this,Ya,_e(Kt,8,this)),_e(Kt,11,this),Le(this,Ka,_e(Kt,12,this)),_e(Kt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){tt(this,Br,e,Fu)}get element(){var e;return(e=this.proxy)!=null?e:ke(this,Br,_u)}};Kt=fr(Ro);Ya=new WeakMap;Br=new WeakSet;Ka=new WeakMap;_s=vt(Kt,20,"#element",Wu,Br,Ya),_u=_s.get,Fu=_s.set;vt(Kt,4,"proxy",zu,Os,Ka);En(Kt,Os);function tg(e){return e!=null&&typeof e=="object"&&"current"in e}function Vn(e){var t;if(e!=null)return tg(e)?(t=e.current)!=null?t:void 0:e}var ng=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",hr=ng?k.useLayoutEffect:k.useEffect;function rg(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function qu(e,t){const n=k.useRef(new Map),r=rg();return hr(()=>{if(!e){n.current.clear();return}return gt(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[l]=a,u=de(()=>a[1]),d=e[l];u!==d&&(s=!0,n.current.set(l,d),o=(i=t?.(l,u,d))!=null?i:!1)}s&&(o?queueMicrotask(()=>Mh.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function ig(e,t){e()}function Tn(e){const t=k.useRef(e);return hr(()=>{t.current=e},[e]),t}function Te(e,t,n=k.useEffect,r=Object.is){const i=k.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function _i(e,t){const n=k.useRef(Vn(e));hr(()=>{const r=Vn(e);r!==n.current&&(n.current=r,t(r))})}var sg=Object.defineProperty,og=Object.defineProperties,ag=Object.getOwnPropertyDescriptors,as=Object.getOwnPropertySymbols,Bu=Object.prototype.hasOwnProperty,Uu=Object.prototype.propertyIsEnumerable,Pl=(e,t,n)=>t in e?sg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lg=(e,t)=>{for(var n in t||(t={}))Bu.call(t,n)&&Pl(e,n,t[n]);if(as)for(var n of as(t))Uu.call(t,n)&&Pl(e,n,t[n]);return e},cg=(e,t)=>og(e,ag(t)),dg=(e,t)=>{var n={};for(var r in e)Bu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&as)for(var r of as(e))t.indexOf(r)<0&&Uu.call(e,r)&&(n[r]=e[r]);return n},ug=new Lu,Gu=k.createContext(ug),fg=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),i=k.useRef(null),s=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(l=>{s.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return hr(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),Fs=[void 0,yt];function hg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:l}=t,u=dg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:c,modifiers:f,sensors:p}=u,x=kt(c,Hn.plugins),g=kt(p,Hn.sensors),y=kt(f,Hn.modifiers),w=Tn(i),h=Tn(s),m=Tn(a),b=Tn(o),$=Tn(l),D=Tn(r),M=pg(()=>{var A;return(A=u.manager)!=null?A:new Lu(u)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:A,trackRendering:E}=d.current,{monitor:T}=M;M.renderer=A;const F=[T.addEventListener("beforedragstart",z=>{const q=w.current;q&&E(()=>q(z,M))}),T.addEventListener("dragstart",z=>{var q;return(q=h.current)==null?void 0:q.call(h,z,M)}),T.addEventListener("dragover",z=>{const q=m.current;q&&E(()=>q(z,M))}),T.addEventListener("dragmove",z=>{const q=b.current;q&&E(()=>q(z,M))}),T.addEventListener("dragend",z=>{const q=$.current;q&&E(()=>q(z,M))}),T.addEventListener("collision",z=>{var q;return(q=D.current)==null?void 0:q.call(D,z,M)})];return()=>F.forEach(z=>z())},[M]),Te(x,()=>M&&(M.plugins=x),...Fs),Te(g,()=>M&&(M.sensors=g),...Fs),Te(y,()=>M&&(M.modifiers=y),...Fs),v.jsxs(Gu.Provider,{value:M,children:[v.jsx(fg,{ref:d,children:n}),n]})}function pg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function mg(){return k.useContext(Gu)}function Hu(e){var t;const n=(t=mg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),hr(r.register,[n,r]),r}var gg=Object.create,Vu=Object.defineProperty,vg=Object.getOwnPropertyDescriptor,Yu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Es=e=>{throw TypeError(e)},bg=(e,t,n)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xg=e=>{var t;return[,,,gg((t=e?.[Yu("metadata")])!=null?t:null)]},Ku=["class","method","getter","setter","accessor","field","value","get","set"],Xu=e=>e!==void 0&&typeof e!="function"?Es("Function expected"):e,yg=(e,t,n,r,i)=>({kind:Ku[e],name:t,metadata:r,addInitializer:s=>n._?Es("Already initialized"):i.push(Xu(s||null))}),wg=(e,t)=>bg(t,Yu("metadata"),e[3]),kg=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},Zu=(e,t,n,r,i,s)=>{for(var o,a,l,u,d=t&7,c=!1,f=!1,p=2,x=Ku[d+5],g=e[p]||(e[p]=[]),y=(i=i.prototype,vg(i,n)),w=r.length-1;w>=0;w--)l=yg(d,n,a={},e[3],g),l.static=c,l.private=f,u=l.access={has:h=>n in h},u.get=h=>h[n],o=(0,r[w])(y[x],l),a._=1,Xu(o)&&(y[x]=o);return y&&Vu(i,n,y),i},Qu=(e,t,n)=>t.has(e)||Es("Cannot "+n),$g=(e,t,n)=>(Qu(e,t,"read from private field"),t.get(e)),Sg=(e,t,n)=>t.has(e)?Es("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jg=(e,t,n,r)=>(Qu(e,t,"write to private field"),t.set(e,n),n),yn=class zo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new zo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new zo(t,n)}},Ju,ef,Wo,Fi,di,Xa=class extends(Wo=Cn,ef=[Pe],Ju=[Pe],Wo){constructor(e){const t=yn.from(e);super(t,(n,r)=>yn.equals(n,r)),kg(di,5,this),Sg(this,Fi,0),this.velocity={x:0,y:0}}get delta(){return yn.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=yn.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-$g(this,Fi),o=a=>Math.round(a/s*100);Ie(()=>{jg(this,Fi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(yn.from(e)),this.velocity={x:0,y:0}}};di=xg(Wo);Fi=new WeakMap;Zu(di,2,"delta",ef,Xa);Zu(di,2,"direction",Ju,Xa);wg(di,Xa);var tf=(e=>(e.Horizontal="x",e.Vertical="y",e))(tf||{});Object.values(tf);var Cg=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=yn.distance(t.shape.center,n);return{id:r,value:1/i,type:cr.PointerIntersection,priority:lr.High}}return null},Og=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=yn.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:cr.ShapeIntersection,priority:lr.Normal}}return null},Eg=e=>{var t;return(t=Cg(e))!=null?t:Og(e)};function Mg(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,l=Hu(d=>new Os(cg(lg({},e),{register:!1,element:Vn(i)}),d)),u=qu(l);return Te(s,()=>l.id=s),_i(i,d=>l.element=d),Te(o,()=>l.accept=o,void 0,yt),Te(t,()=>l.collisionDetector=t??Eg),Te(n,()=>n&&(l.data=n)),Te(r,()=>l.disabled=r===!0),Te(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:k.useCallback(d=>{var c,f;!d&&(c=l.element)!=null&&c.isConnected&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=d??void 0)},[l])}}const Ue=e=>e.kind==="text",we=e=>e.kind!=="text",qs=e=>we(e)?e.label??e.name:e.name,Ye=e=>Ue(e)?`text.${e.name}`:`${e.source}.${e.name}`;function Tg(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of we(s)?s.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function ls(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Ag(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function qi(e,t){const n=Ag(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const i=new Set(["date","timestamp"]);return i.has(n)?i.has(r):n===r}function Ll(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function Ig(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const Dg=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function Pg(e,t){const n=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",r=/^[A-Z_]/.test(n)?n:`F_${n}`,i=Lc(r)?r:`${r}_FILTER`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const Nl=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function yi(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const _o=e=>we(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function Lg(e,t){return e.tiles.map(n=>{const r=(we(n)?n.filters??[]:[]).find(i=>i.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:ls(t.type)!==void 0?{op:ls(t.type)}:{}}})}function Ng(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!_o(s))return;const o=(s.filters??[]).filter(l=>l.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function Rg(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function zg(e,t){for(const r of e.tiles){if(!we(r))continue;const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Wg=en(v.jsx("path",{d:"M3 17v2h6v-2zM3 5v2h10V5zm10 16v-2h8v-2h-8v-2h-2v6zM7 9v2H3v2h4v2h2V9zm14 4v-2H11v2zm-6-4h2V7h4V5h-4V3h-2z"})),_g=en(v.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"})),Fg=en(v.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),qg=en(v.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),Fo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Bs=Fo?"⌘":"Ctrl+",Bg=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Rl=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Ug(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const i=s=>{const o=t.current;if(o.paused)return;const a=Fo?s.metaKey:s.ctrlKey,l=s.key.toLowerCase();if(s.key==="Escape"){o.escape();return}if(Bg(s.target)){if(a&&l==="s"){if(s.preventDefault(),!o.save||Rl(s.target))return;s.target.blur(),r(!0)}return}if(a&&l==="z"){s.preventDefault(),s.shiftKey?o.redo():o.undo();return}if(!Fo&&a&&l==="y"){s.preventDefault(),o.redo();return}if(a&&l==="s"){s.preventDefault(),Rl(s.target)||o.save?.();return}o.nudge&&!a&&!s.altKey&&!s.shiftKey&&(s.key==="ArrowLeft"||s.key==="ArrowRight")&&(s.preventDefault(),o.nudge(s.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[])}const Gg={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Hg({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,savesTo:a="package",saveLabel:l,saveButton:u,actions:d,onExit:c,onAddTile:f,onSettings:p}){const{theme:x}=nt();return v.jsxs(Cc,{left:v.jsx(Ur,{size:"medium",variant:"outlined",icon:v.jsx(_g,{sx:{fontSize:20}}),label:"Editing",sx:{height:37,fontSize:"0.875rem",fontWeight:500,border:x.border,color:x.tileTitle,"& .MuiChip-icon":{color:"inherit"},"& .MuiChip-label":{fontSize:"0.875rem"}}}),children:[f&&v.jsx(Ee,{startIcon:v.jsx(ms,{}),onClick:f,"aria-label":"Add tile",children:"Tile"}),p&&v.jsx(Ee,{startIcon:v.jsx(Wg,{}),onClick:g=>p(g.currentTarget),children:"Settings"}),v.jsx(ro,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),v.jsx(Un,{title:`Undo (${Bs}Z)`,children:v.jsx("span",{children:v.jsx(Hi,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:v.jsx(qg,{fontSize:"small"})})})}),v.jsx(Un,{title:`Redo (${Bs}⇧Z)`,children:v.jsx("span",{children:v.jsx(Hi,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:v.jsx(Fg,{fontSize:"small"})})})}),o&&v.jsx(v.Fragment,{children:v.jsxs(Oe,{sx:{display:"flex",flexDirection:"column",alignItems:"center"},children:[v.jsx(Un,{title:i?`Save (${Bs}S)`:"",children:v.jsx("span",{children:v.jsx(Ee,{ref:u,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{minWidth:124},children:s?"Saving…":i?"Save changes":"Saved"})})}),v.jsx(ie,{variant:"caption",sx:{fontSize:11,lineHeight:1.2,opacity:.7},children:l??Gg[a]})]})}),(d||c)&&v.jsxs(v.Fragment,{children:[v.jsx(ro,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),d,c&&v.jsx(Ec,{label:"Close",icon:v.jsx(th,{}),onClick:c})]})]})}function Vg(e,t){const n=new Map(e.tiles.map((r,i)=>[Ye(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(Ye(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return Ye(i)}}const nf=k.createContext(void 0);function rf(e,t){const n=k.useContext(nf),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const s=()=>r.current();return n.commitRef.current=s,()=>{n.commitRef.current===s&&(n.commitRef.current=void 0)}},[n,e]);const i=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!i.current||(i.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{i.current&&n?.setDirty(!1)},[n])}const sf=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],of=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],Ms=e=>of.includes(e),qo=new Set([...sf,"viz"]);function Zt(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let i;for(const s of n)if(s.startsWith("-")){if(i!==void 0)return;const o=s.slice(1);if(!qo.has(o))return;r.push(o)}else{if(i!==void 0||!qo.has(s))return;i=s}return{negated:r,...i!==void 0&&{pick:i}}}function ei(e){const t=e.trim();return!/^#[ \t]/.test(t)||Zt(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(n=>qo.has(n))}function Yn(e,t){return["#",...of.filter(n=>n!==e&&(t===void 0||t.includes(n))).map(n=>`-${n}`),"-viz",...e==="none"?[]:[e]].join(" ")}function Yg(e){return e.pick!==void 0?Ms(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function Kg(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=Zt(e[0]);return t?Yg(t):"custom"}function Xg(e){const t=e.filter(n=>Zt(n));return e.some(ei)?"custom":t.length===0?void 0:Kg(t)}const Zg=e=>e.filter(t=>Zt(t)||ei(t)),af=e=>e.ok===!1,Re=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),ui=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Me={sourceDefinition:e=>Re(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Re(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Re(e,"VIEW","subQueryDefList"),defDimension:e=>Re(e,"defList","DIMENSION"),exploreProperties:e=>Re(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Re(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Re(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Re(e,"WHERE","filterClauseList"),givenDef:e=>Re(e,"givenNameDef"),givenStatement:e=>Re(e,"GIVEN","givenDefList"),importStatement:e=>Re(e,"IMPORT","importURL"),vArrow:e=>Re(e,"ARROW","vExpr","segExpr"),segRefine:e=>Re(e,"PLUS","segExpr"),segOps:e=>Re(e,"queryProperties"),segField:e=>Re(e,"fieldPath")&&!Re(e,"segExpr"),segParen:e=>Re(e,"OPAREN","CPAREN","vExpr"),compare:e=>Re(e,"fieldExpr","compareOp"),givenRef:e=>Re(e,"GIVEN_REF")};function Qg(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function Jg(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}class Za{constructor(t){this.text=t,this.map=Qg(t),this.lineStarts=Jg(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!ui(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],s=this.map[r.stopIndex+1];if(!(i===void 0||s===void 0||s<i))return{start:i,end:s}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],i=this.map[n.stopIndex+1];if(!(r===void 0||i===void 0||i<r))return{start:r,end:i}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const i=n+r+1>>1;this.lineStarts[i]<=t?n=i:r=i-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function fi(e,t,n=[]){ui(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)fi(e.getChild(r),t,n);return n}const ev=e=>Re(e,"OCURLY","CCURLY");function ti(e,t){const n=[],r=i=>{if(ui(i)){if(t(i)){n.push(i);return}if(!ev(i))for(let s=0;s<(i.childCount??0);s++)r(i.getChild(s))}};for(let i=0;i<(e.childCount??0);i++)r(e.getChild(i));return n}const ze=(e,t)=>e[t]?.call(e),Sn=(e,t)=>e[t]?.call(e)??[];function tv(e,t){if(!Me.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Me.givenRef(n))return;const r=e.text_(t.getChild(0)),i=e.text_(t.getChild(1)),s=e.text_(n)??"";if(!(r===void 0||i===void 0))return{field:r,op:i.trim(),given:s.replace(/^\$/,"")}}function lf(e,t){const n=e.positioned(t);if(!n)return;const r=ze(t,"filterClauseList"),i=[];for(const s of r?Sn(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=fi(s,Me.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));i.push({...o,givens:a,binding:tv(e,s)})}return{...n,clauses:i}}function Bo(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const u of ti(t,Me.queryStatement)){const d=e.positioned(u);d&&r.push(d);const c=ze(u,"whereStatement");if(c&&Me.whereStatement(c)){const f=lf(e,c);f&&i.push(f)}}const s=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
+ `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:s,closeStart:o,statements:r,wheres:i,indent:l,oneLine:a}}function Qa(e,t,n){const r=[],i=e.line(t.start),s=e.line(n);for(let o=i;o<s;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function nv(e,t){const n=ze(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Me.vArrow(t);if(Me.segOps(n)){const i=ze(n,"queryProperties"),s=i&&Bo(e,i);return s?{kind:"inline",stage:s,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(Me.segField(n)){const i=e.span(n);return i?{kind:"reference",from:e.text.slice(i.start,i.end),fromSpan:i}:{kind:"unsupported",why:"an unreadable name"}}if(Me.segRefine(n)){const i=Sn(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;Me.segRefine(a);){const f=Sn(a,"segExpr");if(f.some(p=>Me.segOps(p)||Me.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&Me.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Me.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const l=e.span(s);if(!l||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!Me.segOps(o)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(l.start,l.end),d=ze(o,"queryProperties"),c=d&&Bo(e,d);return c?{kind:"reference",from:u,fromSpan:l,refinement:c}:{kind:"reference",from:u,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function rv(e,t){const n=[];for(const r of ti(t,Me.defExploreQuery)){const i=e.span(r),s=ze(r,"subQueryDefList");if(!i||!s)continue;const o=Sn(s,"exploreQueryDef").filter(Me.exploreQueryDef),a=e.terminal(ze(r,"VIEW"));for(const l of o){const u=e.span(l),d=ze(l,"exploreQueryNameDef"),c=e.text_(d),f=ze(l,"vExpr");!u||!c||!f||n.push({name:c,span:u,line:e.line(u.start),statement:i,tags:Qa(e,i,a?.start??u.start),siblings:o.length,body:nv(e,f)})}}return n}function iv(e,t){const n=[];for(const r of ti(t,Me.defDimension)){const i=e.span(r),s=ze(r,"defList");if(!i||!s)continue;const o=e.terminal(ze(r,"DIMENSION"));for(const a of Sn(s,"fieldDef")){const l=e.span(a),u=e.text_(ze(a,"fieldNameDef"))?.trim(),d=e.text_(ze(a,"fieldExpr"))?.trim();!l||!u||d===void 0||n.push({name:u,expression:d,span:l,line:e.line(l.start),statement:i,tags:Qa(e,i,o?.start??l.start)})}}return n}function sv(e,t){const n=[];for(const r of fi(t,Me.sourceDefinition)){const i=e.span(r),s=e.text_(ze(r,"sourceNameDef")),o=ze(r,"sqExplore");if(!i||!s||!o)continue;const a=e.span(o),l=a?e.text.slice(a.start,a.end):"",u=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),d=ti(o,Me.exploreProperties)[0],c=d&&Bo(e,d),f={start:e.lineStarts[e.line(i.start)],end:i.end},p=[];if(d)for(const x of ti(d,Me.whereStatement)){const g=lf(e,x);g&&p.push(g)}n.push({name:s,base:u,span:i,line:e.line(i.start),statement:f,...c?{properties:c}:{},views:d?rv(e,d):[],dimensions:d?iv(e,d):[],wheres:p})}return n}function ov(e,t){const n=[];for(const r of fi(t,Me.givenStatement)){const i=e.terminal(ze(r,"GIVEN")),s=ze(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?Sn(s,"givenDef"):[]){const l=e.span(a),u=e.span(ze(a,"givenNameDef")),d=u&&e.text.slice(u.start,u.end);if(!l||!u||!d)continue;const c={start:u.start,end:l.end},f=e.line(c.start);n.push({name:d,declaration:e.text.slice(c.start,c.end),span:c,line:f,statement:{start:e.lineStarts[f],end:c.end},tags:Qa(e,l,c.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function av(e,t){const n=[];for(const r of fi(t,Me.importStatement)){const i=e.span(r),s=e.text_(ze(r,"importURL"));if(!i||s===void 0)continue;const o=ze(r,"importSelect"),a=o?Sn(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:s.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:i,line:e.line(i.start),statement:i})}return n}async function cf(e){let t;try{t=await Ts(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,i=r?.root;if(!i||!ui(i)||typeof i.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const s=r?.tokenStream??{},o=typeof s.getTokens=="function"?s.getTokens():void 0;if(!o||typeof s.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new Za(e),l=Ja(a,s);a.commentLines=l.lines;const u=e.split(`
70
+ `),d=f=>l.lines.has(f);a.proseLines=kh(u,d),a.blocks=$h(u,d).filter(([f])=>!u[f].trimStart().startsWith("##"));const c=sv(a,i);return c.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:av(a,i),sources:c,givens:ov(a,i),textBlocks:cv(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(p=>p.start>=f.start&&p.start<f.end),blockStart:f=>lv(a,l.lines,f)}}}async function Ts(e,t){const{MalloyTranslator:n}=await Zo(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Ja(e,t){const n=new Map,r=new Set,i=[],s=t.tokenSource?.vocabulary;for(const d of t.getTokens?.()??[]){const c=s?.getSymbolicName(d.type);if(c!=="COMMENT_TO_EOL"&&c!=="BLOCK_COMMENT")continue;const f=e.utf16(d.startIndex);let p=e.utf16(d.stopIndex+1);if(!(f===void 0||p===void 0||p<f)){for(;p>f&&(e.text[p-1]===`
71
+ `||e.text[p-1]==="\r");)p--;i.push({start:f,end:p})}}const o=[...i].sort((d,c)=>d.start-c.start);let a="",l=0;for(const d of o)a+=e.text.slice(l,Math.max(l,d.start)),a+=e.text.slice(Math.max(l,d.start),Math.max(l,d.end)).replace(/[^\n\r]/g," "),l=Math.max(l,d.end);a+=e.text.slice(l);const u=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of i){const c=e.line(d.start),f=e.line(d.end-1);for(let g=c;g<=f;g++)u(g).trim()===""&&r.add(g);const p=a.slice(e.lineStarts[c],d.start).trim(),x=a.slice(d.end,e.lineStarts[f+1]??a.length).trim();p!==""&&x===""&&n.set(f,d)}return{trailing:n,lines:r,all:i}}function lv(e,t,n){const r=s=>e.text.slice(e.lineStarts[s],e.lineStarts[s+1]??e.text.length).trim();let i=n;for(let s=n-1;s>=0;s--){const o=r(s),a=e.blocks.find(([,l])=>l===s);if(a){i=s=a[0];continue}if(o===""&&!t.has(s))break;if(o.startsWith("#")||t.has(s))i=s;else break}return i}function cv(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,i=a=>r?.getSymbolicName(a.type),s=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(i(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=Oh(s(n[a]).replace(/\r?\n$/,""));if(!l)continue;const u=[];let d=a+1;for(;i(n[d]??n[a])==="BLOCK_ANNOTATION_TEXT";d++)u.push(s(n[d]));const c=n[d];if(!c||i(c)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),p=e.utf16(c.stopIndex+1)??e.text.length,x=l.name===void 0&&l.rest?[`${l.rest}
72
+ `]:[];o.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...x,...u].join("").replace(/\r\n?/g,`
73
+ `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:p},line:f}),a=d}return o}function df(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function el(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=df(e,r);else if(i==="{"||i==="[")t++===0&&n++;else if(i==="}"||i==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const s=/^tiles\s*=\s*\[/.exec(e.slice(r));if(s)return dv(e,r+s[0].length-1)}}}function dv(e,t){const n=[];let r=0,i=t+1;const s=o=>{const a=e.slice(i,o),l=a.length-a.trimStart().length,u=a.trim();u!==""&&n.push({text:u,span:{start:i+l,end:i+l+u.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=df(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return s(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(s(o),i=o+1)}}function uv(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
74
+ `)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const i=e.indexOf(`
75
+ `,r),s=i===-1?e.length:i;if(e.slice(r,s).trim()===">>>")return s;if(i===-1)return e.length;r=i+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let i=t+3;i<e.length;i++)if(e[i]==="\\")i++;else if(e.startsWith(r,i))return i+3;return e.length}for(let i=t+1;i<e.length;i++)if(e[i]==="\\")i++;else{if(e[i]===n)return i+1;if(e[i]===`
76
+ `)return i}return e.length}return t}function fv(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=uv(e,r);if(i>r){n+=e.slice(r,i),r=i;continue}const s=e[r];if(/[=[,]/.test(s)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${s}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=s,r+=1}return n}function uf(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(s=>{if(e([s]).log.length===0)return s;const o=fv(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const cs=e=>e.ok===!1;function hi(e,t,n){const r=e.blockStart(n),i=[],s=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){s.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&i.push({line:o,text:a})}return{start:r,tags:i,prose:s}}const ds=e=>e.map(t=>t.text);function zl(e){const t=ds(e),n=Xg(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:Zg(t)}:{chart:n}}function hv(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:i,op:s,given:o}=r.binding;t.push({field:Sh(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function pv(e,t,n){const r=[];for(const i of e.givens){const s=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(i.declaration);s&&r.push({name:s[1],type:s[2],default:s[3].trim(),...mv(n(ds(hi(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function mv(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),i=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...i===void 0?{}:{rangeMax:i}}}function Us(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const gv=/^"((?:[^"\\]|\\.)+)"$/,vv=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function us(e,t){try{return await bv(e,t)}catch(n){return{ok:!1,reason:`A value in this file's tags cannot be read (${n instanceof Error?n.message:String(n)}), so it cannot be opened in the builder.`}}}async function bv(e,t){const{parseAnnotation:n}=await Ac(),r=mh(e),i=await cf(e);if(af(i))return{ok:!1,reason:i.reason,...i.line?{line:i.line}:{}};const s=i.parsed,o=Ic(r).text,a=vs(r);if(a===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a composite dashboard."};if(!Dc(a.text))return{ok:!1,reason:Pc,line:a.from+1};const{tag:l,errors:u}=uf(n,[gh(a.text)]),d=l?.tag("artifact"),c=d?.text("kind"),f=c==="notebook"||c!=="dashboard"&&t?.startsWith("notebooks/")?"notebook":void 0,p=el(a.text);if(p===void 0)return u.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${u[0]}`}:f==="notebook"?{ok:!1,legacyNotebook:!0,reason:"This notebook is in the cell format, with no `tiles=[…]` list."}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const x=s.imports.map(M=>M.names?{kind:"names",names:M.names,from:M.from}:{kind:"all",from:M.from}),g=[],y=[],w=new Map;for(const M of s.sources){const A={name:M.name,base:M.base};M.dimensions.length>0&&(A.dimensions=M.dimensions.map(T=>({name:T.name,expression:T.expression})));const E=new Set(M.wheres.flatMap(T=>T.clauses.flatMap(F=>F.givens)));E.size>0&&(A.scopedBy=Array.from(E)),g.push(A);for(const T of M.dimensions){const F=n(ds(hi(s,r,T.line).tags)).tag?.tag("drill");if(!F)continue;const z=F.textArray("to")??[F.text("to")??""];y.push({source:M.name,name:T.name,expression:T.expression,to:z.filter(Boolean),...F.text("given")?{given:F.text("given")}:{}})}w.set(M.name,new Map(M.views.map(T=>[T.name,T])))}const h=[];for(const{text:M}of p.entries){const A=gv.exec(M),E=A?void 0:vv.exec(M)?.[1];if(E!==void 0){const Q=n([`# ${M}`]).tag?.tag(E);if(Q?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${M}\` is neither a quoted \`source -> view\` expression nor a \`${E} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(h.some(O=>Ue(O)&&O.name===E))return{ok:!1,reason:`Two text tiles are named \`${E}\`, so the builder cannot tell them apart.`};const he=Us(Q,"colspan");h.push({kind:"text",name:E,markdown:s.textBlocks.find(O=>O.name===E)?.body??"",...he===void 0?{}:{colspan:he},...Q.has("break")?{break:!0}:{}});continue}const T=A?.[1]??M,F=A?vh(T):void 0;if(!F)return{ok:!1,reason:`The tile \`${T}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:z,view:q}=F,K=w.get(z)?.get(q);if(K===void 0){h.push({name:q,source:z,declaration:{kind:"inherited"}});continue}const X=n(ds(K.tags)).tag,oe=K.body.kind==="reference"?{kind:"reference",from:K.body.from}:K.body.kind==="inline"?{kind:"inline"}:void 0;if(oe===void 0){h.push({name:q,source:z,declaration:{kind:"opaque",why:K.body.kind==="unsupported"?K.body.why:"unreadable"},...X?.text("label")?{label:X.text("label")}:{},...X?.text("subtitle")?{subtitle:X.text("subtitle")}:{},...X?.numeric("colspan")!==void 0?{colspan:X.numeric("colspan")}:{},...zl(K.tags),...X?.has("break")?{break:!0}:{},...X?.has("borderless")?{borderless:!0}:{}});continue}const ae=hv(K.body.kind==="reference"?K.body.refinement:K.body.kind==="inline"?K.body.stage:void 0);h.push({name:q,source:z,declaration:oe,...ae?{filters:ae}:{},...X?.text("label")?{label:X.text("label")}:{},...X?.text("subtitle")?{subtitle:X.text("subtitle")}:{},...X?.numeric("colspan")!==void 0?{colspan:X.numeric("colspan")}:{},...zl(K.tags),...X?.has("break")?{break:!0}:{},...X?.has("borderless")?{borderless:!0}:{}})}const m=pv(s,r,n),b={},$=d?.tag("givens");for(const M of Object.keys($?.dict??{})){const A=$?.text(M);A!==void 0&&(b[M]=A)}const D=l?.tag("dashboard")?.has("columns")?Us(l.tag("dashboard"),"columns"):d?.array("tiles")?Us(d,"dashboard_columns"):void 0;return{ok:!0,document:{...f?{kind:f}:{},title:d?.text("title")??"",...o?{description:o}:{},...D===void 0?{}:{columns:D},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:x,sources:g,...m?{localGivens:m}:{},...Object.keys(b).length>0?{startingGivens:b}:{},...y.length>0?{drills:y}:{},tiles:h}}}const Uo=e=>e.ok===!1;async function Wl(e){const{problems:t}=await Ts(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function Ce(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const i of Object.keys(n).sort())r[i]=t(n[i]);return r}return n};return JSON.stringify(t(e))}function ff(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function xv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function yv(e,t){let n=e;for(const r of[...t].sort((i,s)=>s.start-i.start||s.end-i.end))n=n.slice(0,r.start)+r.text+n.slice(r.end);return n}const hf=e=>e==="none"||Ms(e)?e:void 0;function pf(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${Rt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${Rt(e.subtitle)}`);const r=t?hf(e.chart):void 0;return r!==void 0&&n.push(Yn(r,e.chartCarried)),n}function Bi(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const wv=new Set(["colspan","break","borderless","label","subtitle"]),kv=new Set(["label","description","control","suggest","range_min","range_max"]),st=e=>e.kind??"dashboard";function _l(e){const t=[];if(e.label!==void 0&&t.push(`label=${Rt(e.label)}`),e.description!==void 0&&t.push(`description=${Rt(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${Rt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${Rt(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const Fl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function $v(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function ql(e){return`# drill { to=${e.to.length===1?e.to[0]:`[${e.to.map(t=>`"${t}"`).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const fs=e=>`${e.source}.${e.name}`,Rt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Go=e=>Ue(e)?Ce(["text",e.name]):Ce([e.name,e.source,e.declaration]),pt=Go,Bl=e=>Ce(e.tiles.map(pt));function Sv(e,t,n){if(st(e)!==st(t)&&!n)return{ok:!1,reason:"The document's kind is not changed by an ordinary edit; switch it with the explicit kind change."};const r=new Set(e.tiles.map(pt)),i=new Set(t.tiles.map(pt)),s=e.tiles.filter(c=>!i.has(pt(c))),o=t.tiles.filter(c=>!r.has(pt(c))),a=s.length>0||o.length>0||Bl(e)!==Bl(t);for(const c of o)if(we(c)&&c.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${c.name}\` is ${c.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const l=new Map(e.sources.map(c=>[c.name,c])),u=new Set(t.imports.flatMap(c=>c.kind==="names"?c.names:[]));for(const c of e.sources)u.add(c.base);const d=t.sources.filter(c=>!l.has(c.name));for(const c of e.sources){const f=t.sources.find(p=>p.name===c.name);if(!f||f.base!==c.base)return{ok:!1,reason:`The source \`${c.name}\` cannot be changed or removed here.`}}for(const c of d){if(!o.some(f=>we(f)&&f.source===c.name))return{ok:!1,reason:`A new source \`${c.name}\` needs a tile on it.`};if(!u.has(c.base))return{ok:!1,reason:`\`${c.base}\` is not imported by name in this file, so a tile cannot be put on it. Add it as a source first.`}}return{currentKeys:r,nextKeys:i,removedTiles:s,addedTiles:o,newSources:d,currentSources:l,reordered:a}}const Ul=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function jv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=ni(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Gl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=jv(t),r=n.indexOf("{"),i=n.lastIndexOf("}");let s=t.slice(r+1,i),o=n.slice(r+1,i);const a=u=>{const d=u.exec(o);d&&(s=s.slice(0,d.index)+s.slice(d.index+d[0].length),o=o.slice(0,d.index)+o.slice(d.index+d[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const l=[s.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${l.join(" ")} }${t.slice(i+1)}`}function Cv(e){const{lines:t,wholeLine:n,current:r,next:i,reordered:s,currentKeys:o,nextKeys:a,edits:l}=e,u=new Map(r.tiles.filter(Ue).map(h=>[h.name,h])),d=i.tiles.filter(Ue).some(h=>{const m=u.get(h.name);return m!==void 0&&Ul(m,h)});if(!s&&!d)return;const c=vs(t);if(!c)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=c.text,p=el(f);if(!p)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A dashboard with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const x=new Map;for(const{text:h}of p.entries){const m=/^"((?:[^"\\]|\\.)+)"$/.exec(h);if(m){const $=m[1].split("->").map(D=>D.trim());$.length===2&&x.set(`${$[0]}->${$[1]}`,h);continue}const b=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(h)?.[1];b!==void 0&&x.set(`text.${b}`,h)}const g=i.tiles.map(h=>{const m=!o.has(pt(h));if(Ue(h)){const b=x.get(`text.${h.name}`);return b!==void 0?u.has(h.name)&&!Ul(u.get(h.name),h)?b:Gl(h,b):m?Gl(h):void 0}return x.get(`${h.source}->${h.name}`)??(m?`"${h.source} -> ${h.name}"`:void 0)});if(g.some(h=>h===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const y=f.slice(0,p.open).search(/tiles\s*=\s*$/),w=`${f.slice(0,y)}tiles=[${Ov(f,p,g)}]${f.slice(p.close+1)}`;w!==f&&l.push({...mf(n,c),text:`${w}
78
+ `})}function mf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Ov(e,t,n){const r=t.entries[0],i=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const s=e.slice(t.open+1,r.span.start),o=e.slice(i.span.end,t.close),a=s.slice(s.lastIndexOf(`
79
+ `)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
+ `)?a:" "}`;return`${s}${n.join(l)}${o}`}function Hl(e,t){let n=0,r=0;for(let i=0;i<e.length;i++){const s=e[i];if(s==='"')i=ni(e,i);else if(s==="{"||s==="[")n++===0&&r++;else if(s==="}"||s==="]")n--;else if(r===1&&n===1&&e.startsWith(t,i)&&!/[A-Za-z0-9_]/.test(e[i-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(i+t.length));if(!o)continue;const a=i+t.length+o[0].length,l=e[a]==='"'?ni(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),u=i-(/\s*$/.exec(e.slice(0,i))?.[0].length??0);return e.slice(0,u)+e.slice(l)}}return e}function Ev(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=ni(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const i=/^dashboard\s*\{/.exec(e.slice(n));if(!i)continue;let s=1,o=n+i[0].length;for(;o<e.length&&s>0;o++)e[o]==='"'?o=ni(e,o):e[o]==="{"?s++:e[o]==="}"&&s--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function ni(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Mv(e){const{lines:t,wholeLine:n,current:r,next:i,edits:s}=e;if(st(r)!==st(i)||r.title!==i.title||r.autorun!==i.autorun||r.columns!==i.columns||Ce(r.startingGivens)!==Ce(i.startingGivens)){const o=vs(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=mf(n,o),l=s.find(h=>h.start===a.start&&h.end===a.end);let u=l?l.text.replace(/\n$/,""):o.text;st(r)!==st(i)&&(u=Hl(u,"kind"));const d=u.indexOf("artifact"),c=u.indexOf("{",d);let f=0,p=-1;for(let h=c;h<u.length;h++)if(u[h]==="{")f++;else if(u[h]==="}"&&--f===0){p=h;break}if(c<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let x=u.slice(c+1,p);const g=o.block?`
81
+ ${/\n([ \t]+)\S/.exec(x)?.[1]??" "}`:" ",y=h=>o.block?`${x.trimEnd()}${g}${h}
82
+ `:`${x.trimEnd()} ${h} `,w=(h,m)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${h}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(m===void 0){const $=new RegExp(`
83
+ ${b.source}[ \\t]*(?=
84
+ )`);x=x.replace(o.block&&$.test(x)?$:b,"")}else b.test(x)?x=x.replace(b,$=>`${o.block?$.slice(0,$.length-$.trimStart().length):" "}${h}=${m}`):x=y(`${h}=${m}`)};if(st(r)!==st(i)&&st(i)==="notebook"?x=y("kind=notebook"):st(r)!==st(i)&&e.modelPath?.startsWith("notebooks/")&&(x=y("kind=dashboard")),r.title!==i.title&&w("title",i.title?Rt(i.title):void 0),r.autorun!==i.autorun&&w("autorun",i.autorun===void 0?void 0:String(i.autorun)),Ce(r.startingGivens)!==Ce(i.startingGivens)){x=x.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const h=Object.entries(i.startingGivens??{});h.length>0&&(x=y(`givens { ${h.map(([m,b])=>`${m}=${Rt(b)}`).join(" ")} }`))}o.block?u=`${u.slice(0,c+1)}${x}${u.slice(p)}`:(x=x.replace(/\s{2,}/g," "),u=`${u.slice(0,c+1)}${x.startsWith(" ")?x:` ${x}`}${x.endsWith(" ")?"":" "}${u.slice(p)}`),r.columns!==i.columns&&(u=Hl(u,"dashboard_columns"),u=Ev(u),i.columns!==void 0&&(u=`${u.trimEnd()} dashboard { columns=${i.columns} }`)),l?l.text=`${u}
85
+ `:s.push({...a,text:`${u}
86
+ `})}if(r.description!==i.description){const{read:o,blankAbove:a,below:l,belowBlock:u,inBlock:d}=Ic(t);if(d||i.description===void 0&&u)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const c=ff(i.description??"").split(`
87
+ `).map(g=>g.trim()===""?'##"':`##" ${g.trim()}`).join(`
88
+ `),f=o.length>0&&o[0]<cl(t),p=i.description===void 0,x=f?[...o.slice(1),...p?l:[]]:[...o,...a];for(const g of x)s.push({...n(g),text:""});if(f)s.push({...n(o[0]),text:i.description===void 0?"":`${c}
89
+ `});else if(i.description!==void 0){const g=n(cl(t)).start;s.push({start:g,end:g,text:`${c}
90
+ `})}}}function Tv(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,l=new Map((i.localGivens??[]).map(p=>[p.name,p])),u=new Map((s.localGivens??[]).map(p=>[p.name,p])),d=new Map(a.givens.map(p=>[p.name,p])),c=new Set;for(const[p,x]of l){const g=u.get(p);if(g!==void 0&&Ce(g)===Ce(x))continue;const y=d.get(p);if(y===void 0)return{ok:!1,reason:`Could not find where the given \`${p}\` is declared.`};const{tags:w,prose:h}=hi(a,t,y.line),m=[...(g===void 0?w:w.filter(A=>{const E=Bi(A.text);return E!==void 0&&kv.has(E)})).map(A=>A.line),...g===void 0?h:[]];for(const A of m)o.push({...n(A),text:""}),c.add(A);const b=Ft(a,y.span.end-1);if(g===void 0){o.push({start:n(y.line).start,end:n(b).end,text:""});for(let q=y.line;q<=b;q++)c.add(q);const A=Math.min(y.line,...m),E=y.blockHeader??A,T=(t[b+1]??"x").trim()==="",F=E===0||t[E-1].trim()==="",z=y.blockHeader===void 0||![...d.values()].some(q=>q.blockHeader===y.blockHeader&&q.line>y.line&&u.has([...d.entries()].find(([,K])=>K===q)?.[0]??""));T&&F&&z&&!c.has(b+1)&&(o.push({...n(b+1),text:""}),c.add(b+1));continue}const $=r(y.line),D=_l(g),M=g.type!==x.type||g.default!==x.default?y.blockHeader===void 0?Fl(g):`${g.name} :: ${g.type} is ${g.default}`:t.slice(y.line,b+1).join(`
91
+ `).trim();o.push({start:n(y.line).start,end:n(b).end,text:(D?`${$}${D}
92
+ `:"")+`${$}${M}
93
+ `})}for(const[p,x]of d)x.blockHeader===void 0||u.has(p)||![...d.values()].some(g=>g.blockHeader===x.blockHeader&&!c.has(g.line))&&!c.has(x.blockHeader)&&(o.push({...n(x.blockHeader),text:""}),c.add(x.blockHeader));const f=[...u.values()].filter(p=>!l.has(p.name));if(f.length>0){const p=Math.max(-1,...[...d.values()].map(h=>h.line)),x=(()=>{let h=-1;for(let m=0;m<t.length;m++){const b=t[m].trim();(b.startsWith("import ")||h>=0&&/^}\s*from\s/.test(b))&&(h=m)}return h})(),g=p>=0?p:x,y=f.map(h=>{const m=_l(h);return(m?`${m}
94
+ `:"")+`${Fl(h)}
95
+ `}).join(`
96
+ `),w=g>=0?n(g).end:n(0).end;o.push({start:w,end:w,text:`
97
+ ${y}`}),t.some(h=>h.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
+ `})}}const Vl=(e,t)=>`import { ${e.join(", ")} } from ${Rt(t)}`;function Av(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:s}=e,o=c=>Ce(c.imports.flatMap(f=>f.kind==="all"?[f.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(Ce(n.imports)===Ce(r.imports))return;const a=r.imports.flatMap(c=>c.kind==="names"?[{...c,claimed:!1}]:[]),l=new Set([...r.sources.map(c=>c.base),...r.tiles.filter(we).map(c=>c.source)]),u=t.imports.map((c,f)=>({statement:c,entry:n.imports[f]}));for(const{statement:c,entry:f}of u){if(!f||f.kind!=="names")continue;const p=a.find(h=>!h.claimed&&h.from===f.from);p&&(p.claimed=!0);const x=p?.names??[],g=f.names.filter(h=>!x.includes(h)).find(h=>l.has(h));if(g!==void 0)return{ok:!1,reason:`\`${g}\` is still read by a tile, so its import cannot be removed.`};if(Ce(x)===Ce(f.names))continue;const y=x.length===0?tl(t,c.statement):c.statement,w=t.commentIn(y);if(w)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(w.start,w.end).trim()}\`), so nothing was written. Delete it in the file first.`};i.push({...y,text:x.length===0?"":Vl(x,f.from)})}const d=a.filter(c=>!c.claimed);if(d.length>0){const c=t.imports.at(-1);if(!c)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=s(Ft(t,c.statement.end-1)).end;i.push({start:f,end:f,text:d.map(p=>`${Vl(p.names,p.from)}
99
+ `).join("")})}}function Iv(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,l=new Map((i.drills??[]).map(d=>[fs(d),d])),u=new Map((s.drills??[]).map(d=>[fs(d),d]));for(const d of new Set([...l.keys(),...u.keys()])){const c=l.get(d),f=u.get(d);if(c&&f&&Ce(c)===Ce(f))continue;const p=f??c;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const x=a.sources.find(h=>h.name===p.source)?.dimensions.find(h=>h.name===p.name);if(x===void 0)return{ok:!1,reason:`\`${p.name}\` is not a dimension \`${p.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:g}=hi(a,t,x.line),y=g.find(h=>/^#\s*drill\b/.test(h.text)),w=r(x.line);if(f===void 0)y&&o.push({...n(y.line),text:""});else if(y)o.push({...n(y.line),text:`${w}${ql(f)}
100
+ `});else{const h=n(x.line).start;o.push({start:h,end:h,text:`${w}${ql(f)}
101
+ `})}}}function Dv(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(Ue(o)||o.declaration.kind==="inherited")continue;const a=gf(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const l=Ft(s,a.statement.start),u=Ft(s,a.statement.end-1),d=s.trailingComment(u),c=d&&d.start>=a.statement.end?d.end:a.statement.end;if(s.text.slice(s.lineStarts[l],a.statement.start).trim()!==""||s.text.slice(c,n(u).end).trim()!==""){i.push({...tl(s,a.statement),text:""});continue}i.push({start:s.lineStarts[l],end:n(u).end,text:""});const f=l===0?"":t[l-1].trim();(t[u+1]??"x").trim()===""&&(l===0||f===""||f.endsWith("{"))&&i.push({...n(u+1),text:""})}}function Pv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:s,currentSources:o,edits:a,parsed:l}=e,u=new Map;for(const f of i){if(Ue(f))continue;const p=u.get(f.source)??[];p.push(f),u.set(f.source,p)}const d=(f,p)=>{const x=f.declaration.kind==="reference"?f.declaration.from:f.name,g=(f.filters??[]).map(y=>`where: ${Qo(y.field)} ${y.op??"~"} $${y.given}`).join(", ");return[...pf(f).map(y=>`${p}${y}`),`${p}view: ${f.name} is ${x}${g?` + { ${g} }`:""}`].join(`
102
+ `)};let c=-1;for(const f of l.sources)c=Math.max(c,Ft(l,f.span.end-1));for(const[f,p]of u)if(o.has(f)){const x=l.sources.find(b=>b.name===f);if(!x)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!x.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const g=x.line,y=Ft(l,x.properties.closeStart);let w=" ";for(let b=g+1;b<y;b++){const $=/^(\s+)view:/.exec(n[b]);if($){w=$[1];break}}const h=r(y).start,m=(n[y-1]??"").trim()==="";a.push({start:h,end:h,text:(m?"":`
103
+ `)+p.map(b=>d(b,w)).join(`
104
+
105
+ `)+`
106
+ `})}else{const x=s.find(m=>m.name===f);if(!x)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const g=`
107
+ source: ${x.name} is ${x.base} extend {
108
+ `+p.map(m=>d(m," ")).join(`
109
+
110
+ `)+`
111
+ }
112
+ `;let y=c;if(y<0)for(let m=0;m<n.length;m++){const b=n[m].trim();(/^(import\s|given:|}\s*from\s)/.test(b)||/^[A-Z_]+\s*::/.test(b))&&(y=m)}const w=y>=0?r(y).end:t.length,h=w===t.length&&!t.endsWith(`
113
+ `)?`
114
+ `:"";a.push({start:w,end:w,text:h+g}),c=y}}function Lv(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:s,next:o,edits:a,parsed:l}=e,u=new Map(s.tiles.map(d=>[pt(d),d]));for(const d of o.tiles){const c=u.get(pt(d));if(c===void 0||Ue(d)||Ue(c)||Ce(hs(c))===Ce(hs(d)))continue;if(d.declaration.kind==="inherited")return{ok:!1,reason:`\`${d.source} -> ${d.name}\` is declared on its source, not in this dashboard, so its presentation cannot be changed here.`};const f=$v(l,d.source,d.name);if(f<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:p}=hi(l,t,f),x=i(f),g=pf(d,!1),y=new Map(g.map(E=>[Bi(E)??E,E])),w=new Set,h=hf(d.chart),m=Yl(c)!==Yl(d);if(m){const E=p.filter(z=>ei(z.text)),T=p.filter(z=>Zt(z.text)),F=c.chart==="custom"?p.filter(z=>Zt(z.text)||ei(z.text)):E.length>0?E:T.length>1?T:[];if(F.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${F.map(z=>z.text).join(" and ")}), so its chart cannot be changed here.`}}let b=!1;for(const E of p){if(m&&Zt(E.text)){h===void 0?a.push({...r(E.line),text:""}):E.text!==Yn(h,d.chartCarried)&&a.push({...r(E.line),text:`${x}${Yn(h,d.chartCarried)}
115
+ `}),b=!0;continue}const T=Bi(E.text);if(T===void 0||!wv.has(T))continue;const F=y.get(T);if(F===void 0){a.push({...r(E.line),text:""});continue}w.add(T),F!==E.text&&a.push({...r(E.line),text:`${x}${F}
116
+ `})}const $=g.filter(E=>!w.has(Bi(E)??E));if(m&&h!==void 0&&!b&&$.push(Yn(h,d.chartCarried)),$.length>0){const E=n[f];a.push({start:E,end:E,text:$.map(T=>`${x}${T}
117
+ `).join("")})}if(Ce(c.filters)===Ce(d.filters))continue;const D=gf(e,d);if(!D)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(D.body.kind==="reference"){const E=qv(e,d,D);if(E)return E;continue}if(D.body.kind!=="inline")return{ok:!1,reason:`\`${d.name}\`'s body is ${D.body.why}, so there is no single first stage to write its filter into.`};const M=vf(d.filters,D.body.stage);if(M)return bf(d.name,M.given);const A=xf(e,d,D.body.stage);if(A)return A}}const Yl=e=>e.chart==="default"?void 0:e.chart,hs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...s}=r;return s};function Nv(e,t){const n=new Map(e.tiles.map(r=>[pt(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(pt(r));return we(r)&&r.chart===void 0&&i&&we(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function Ui(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function Rv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!Eh(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=Ui(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const Gs=e=>`##|(markdown) ${e.name}
118
+ ${e.markdown===""?"":`${e.markdown}
119
+ `}|##
120
+ `;function zv(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:s,parsed:o,edits:a}=e,l=new Map(i.tiles.filter(Ue).map(p=>[p.name,p])),u=s.tiles.filter(Ue),d=p=>o.textBlocks.find(x=>x.name===p),c=new Set(u.map(p=>p.name));for(const p of l.keys()){const x=c.has(p)?void 0:d(p);if(!x)continue;const g=Ft(o,x.span.end-1);a.push({...x.span,text:""});const y=r(g+1),w=x.line===0||n[x.line-1].trim()==="";y.end>y.start&&n[g+1].trim()===""&&w?a.push({...y,text:""}):x.line>0&&w&&t.slice(x.span.end).trim()===""&&a.push({...r(x.line-1),text:""})}const f=[];for(const p of u){const x=l.get(p.name),g=d(p.name);if(x===void 0){if(g)return{ok:!1,reason:`A block named \`${p.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(Gs(p))}else x.markdown!==p.markdown&&(g?a.push({...g.span,text:Gs(p)}):f.push(Gs(p)))}if(f.length>0){const p=o.textBlocks.filter(h=>h.name===void 0||c.has(h.name)),x=p[p.length-1],g=o.sources.find(h=>h.name.endsWith("_tiles"));if(x){const h=x.span.end,m=t.slice(h);a.push({start:h,end:h,text:`
121
+ ${f.join(`
122
+ `)}${m===""||m.startsWith(`
123
+ `)?"":`
124
+ `}`});return}if(g){const h=e.starts[o.blockStart(g.line)],m=h===0||t.slice(0,h).endsWith(`
125
+
126
+ `);a.push({start:h,end:h,text:`${m?"":`
127
+ `}${f.join(`
128
+ `)}
129
+ `});return}const y=t.length,w=t===""||t.endsWith(`
130
+
131
+ `)?"":t.endsWith(`
132
+ `)?`
133
+ `:`
134
+
135
+ `;a.push({start:y,end:y,text:w+f.join(`
136
+ `)})}}const wi=(e,t=Xo)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function Wv(e,t){const n=new Map(e.tiles.map(o=>[pt(o),o]));if(st(t)==="notebook"&&t.columns!==void 0&&(st(e)!=="notebook"||t.columns!==e.columns))return"A notebook is one column, so its width is not written. Clear the width when switching a dashboard to a notebook.";const r=new Set;for(const o of t.tiles){const a=n.get(pt(o));if(Ue(o)){const c=Rv(o,a&&Ue(a)?a:void 0,r);if(c)return c;continue}const l=a&&we(a)?a:void 0;if(a&&!l)continue;const u=o.chart;if(u!==void 0&&u!=="default"&&u!=="none"&&!Ms(u)&&!(u==="custom"&&l?.chart==="custom"))return`"${String(u)}" is not a chart this editor writes.`;const d=new Set(l?.filters?.map(c=>c.field));for(const c of o.filters??[])if(!d.has(c.field)&&/[\r\n]/.test(c.field))return"A filter field is one line.";if(a===void 0){const c=[o.name,o.source];o.declaration.kind==="reference"&&c.push(o.declaration.from);for(const f of c){const p=wi(f);if(p)return p}}for(const c of["label","subtitle"]){const f=o[c];if(f===void 0||f===l?.[c])continue;const p=un(`tile ${c}`,f);if(p)return p}}const i=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!i.has(o.name))for(const a of[o.name,o.base]){const l=wi(a);if(l)return l}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=un("description line",o);if(a)return a}if(t.title!==e.title){const o=un("title",t.title);if(o)return o}const s=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=s.get(o.name);if(a===void 0){const u=wi(o.name,Lc);if(u)return u}const l=o.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const u=wi(l);if(u)return`The suggest source is not a name. ${u}`}for(const u of["query","dimension"]){const d=o.suggest?.[u];if(d===void 0||d===a?.suggest?.[u])continue;const c=un(`suggest ${u}`,d);if(c)return c}for(const u of["label","description"]){const d=o[u];if(d===void 0||d===s.get(o.name)?.[u])continue;const c=un(`given ${u}`,d);if(c)return c}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const l=un(`starting value for ${o}`,a);if(l)return l}}const Ft=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function gf(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function vf(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const i of r.clauses)if(!i.binding)for(const s of i.givens)n.add(s);return(e??[]).find(r=>n.has(r.given))}function bf(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const Gi=e=>`where: ${Qo(e.field)} ${e.op??"~"} $${e.given}`;function Kl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function _v(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(Ft(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function Fv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function tl(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),i=e.text.indexOf(`
137
+ `,t.end),s=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&s.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(s)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function xf(e,t,n){const{parsed:r,edits:i}=e,s=new Map((t.filters??[]).map(f=>[f.given,f])),o=new Set;let a;for(const f of n.wheres){const p=f.clauses.map((g,y)=>({clause:g,index:y})).filter(({clause:g})=>g.binding!==void 0);if(p.length===0)continue;const x=p.filter(({clause:g})=>s.has(g.binding.given));for(const{clause:g}of p)o.add(g.binding.given);if(x.length===0&&p.length===f.clauses.length){const g=tl(r,f.span),y=_v(r,f.span,g);if(y)return Kl(t.name,r,y);i.push({...g,text:""});continue}x.length>0&&(a=f.span);for(let g=p.length-1;g>=0;g--){const{clause:y,index:w}=p[g],h=s.get(y.binding.given);if(!h){const b=Fv(f.clauses,w),$=r.commentIn(b);if($)return Kl(t.name,r,$);i.push({...b,text:""});continue}const m=Gi(h).replace(/^where:\s*/,"");m!==r.text.slice(y.span.start,y.span.end)&&i.push({...y.span,text:m})}}const l=(t.filters??[]).filter(f=>!o.has(f.given));if(l.length===0)return;let u=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(Ft(r,u));f&&f.start>=u&&(u=f.end)}const d=a!==void 0&&!/,\s*$/.test(r.text.slice(0,u))?", ":" ",c=n.oneLine?`${d}${l.map(Gi).join(", ")}`:l.map(f=>`
138
+ ${n.indent}${Gi(f)}`).join("");i.push({start:u,end:u,text:c})}function qv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=vf(t.filters,s);if(o)return bf(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const d=` + { ${a.map(Gi).join(", ")} }`;r.push({start:i.end,end:i.end,text:d});return}const l=s.wheres.some(d=>d.clauses.some(c=>!c.binding)),u=s.statements.some(d=>!s.wheres.some(c=>c.span.start===d.span.start));if(a.length===0&&!l&&!u){const d={start:i.end,end:s.span.end},c=e.parsed.commentIn(d);if(c)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(c.start,c.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...d,text:""});return}return xf(e,t,s)}async function Bv(e,t,n={}){if(!(e.includes(`\r
139
+ `)&&!/(?<!\r)\n/.test(e)))return Xl(e,t,n);const r=await Xl(e.replace(/\r\n/g,`
140
+ `),t,n);return Uo(r)?r:{...r,source:r.source.replace(/\n/g,`\r
141
+ `)}}async function Xl(e,t,n){const r=await us(e,n.modelPath);if(cs(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=Nv(i,t),o=Sv(i,s,n.changeKind===!0);if("reason"in o)return o;const a=Wv(i,s);if(a)return{ok:!1,reason:a};const l=await cf(e);if(af(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const u=e.split(`
142
+ `),d=xv(e),c=h=>({start:d[h],end:h+1<d.length?d[h+1]:e.length}),f=h=>/^\s*/.exec(u[h])?.[0]??"",p=[],x={...o,sourceText:e,parsed:l.parsed,lines:u,starts:d,wholeLine:c,indentOf:f,current:i,next:s,edits:p,...n.modelPath!==void 0?{modelPath:n.modelPath}:{}};for(const h of[Cv,Mv,Av,Tv,Iv,Dv,Pv,Lv,zv]){const m=h(x);if(m)return m}const g=h=>{const{drills:m,localGivens:b,kind:$,description:D,...M}=h,A=h.tiles.map(E=>{if(Ue(E))return E;if(E.filters?.length)return hs(E);const{filters:T,...F}=E;return hs(F)});return{...M,...D===void 0?{}:{description:ff(D)},...$==="notebook"?{kind:$}:{},tiles:A,...m?.length?{drills:[...m].sort((E,T)=>fs(E).localeCompare(fs(T)))}:{},...b?.length?{localGivens:b}:{}}};if(p.length===0)return Ce(g(i))!==Ce(g(s))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const y=yv(e,p);if((await Wl(e)).length===0){const h=await Wl(y);if(h.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${h[0]}). Your changes are still here.`}}const w=await us(y,n.modelPath);return cs(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:Ce(g(w.document))!==Ce(g(s))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:y}}function nl(e,t,n,r){const[i,s]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:o=>s(a=>{if(a===void 0)return a;const l=structuredClone(a);return o(l),l}),close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}function yf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=nt(),[s,o]=k.useState(!1),a=k.useMemo(()=>s?{text:e}:void 0,[s,e]),{draft:l,patch:u,close:d,discard:c}=nl(a,s,m=>n(m.text),()=>o(!1)),f=s&&l!==void 0&&l.text!==e,p=l!==void 0&&l.text!==e?Ui(l.text):void 0;rf(f,()=>p!==void 0?!1:(d(),!0));const x=k.useRef(null),g=k.useRef(!1);k.useEffect(()=>{s||(g.current=!1)},[s]);const y=k.useCallback(m=>{!m||g.current||(g.current=!0,m.setSelectionRange(m.value.length,m.value.length))},[]);if(!s||l===void 0){const m=e.trim()?Ui(e):void 0;return v.jsxs(Oe,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():o(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),o(!0)))},sx:{cursor:"text",minHeight:24,borderRadius:"2px","&:hover, &:focus-visible":{outline:"1px dashed currentColor"}},children:[e.trim()?v.jsx(rh,{variant:r,children:e}):v.jsx(ie,{variant:"body2",sx:{color:i.tileTitle,opacity:.6},children:t}),m&&v.jsx(ie,{variant:"caption",color:"error",role:"alert",children:m})]})}const w=l.text!==e?Ui(l.text):void 0,h=()=>{w===void 0&&d()};return v.jsxs(ye,{spacing:1,children:[v.jsx(et,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:y,inputProps:{"aria-label":"Markdown"},onChange:m=>u(b=>{b.text=m.target.value}),onKeyDown:m=>{m.key==="Escape"?h():m.key==="Enter"&&(m.metaKey||m.ctrlKey)&&(m.preventDefault(),h())},onBlur:m=>{m.relatedTarget instanceof Node&&x.current?.contains(m.relatedTarget)||d()}}),v.jsxs(ye,{ref:x,direction:"row",spacing:1,children:[v.jsx(Ee,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:h,children:"Done"}),v.jsx(Ee,{size:"small",onMouseDown:m=>m.preventDefault(),onClick:()=>{c(),o(!1)},children:"Cancel"})]})]})}function Hs({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const[s,o]=k.useState(void 0),a=k.useRef(!1),l=()=>{a.current||s===void 0||(o(void 0),s!==e&&r(s))};rf(s!==void 0&&s!==e,()=>(l(),!0));const u=()=>{a.current=!1,o(e)};if(s===void 0){const d=e===""&&i;return v.jsx(Oe,{component:"button",type:"button",className:d?"builder-affordance":void 0,onClick:u,onKeyDown:c=>{c.key!=="Enter"&&c.key!==" "||(c.preventDefault(),u())},sx:{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",cursor:"text",display:"inline-block",maxWidth:"100%",borderRadius:"2px",opacity:d?0:1,fontStyle:d?"italic":void 0,"&:hover, &:focus-visible":{outline:"1px dashed currentColor"}},children:e===""?t:e})}return v.jsx(nh,{autoFocus:!0,fullWidth:!0,value:s,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>o(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?l():d.key==="Escape"&&(a.current=!0,o(void 0))},onBlur:l,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}function ki(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Zl(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&sf.includes(n))return n}}const Uv=1;function wf(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...wf(a,`${t}${s}.`,n-1))}}}return r}function Gv(e){const t=new Map;for(const n of kf(e))t.set(n.name,wf(n.schema?.fields,"",Uv));return t}function kf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Hv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Th.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Vv(e){const t=new Map;for(const n of kf(e)){const r=new Set;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const s=i.schema?.fields;s&&s.length>0&&s.every(Hv)&&r.add(i.name)}t.set(n.name,r)}return t}function Ql(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const $f=e=>(e??"").startsWith("dashboards/"),Sf=e=>e.modelPath??e.path??"";function Yv(e){const t=[],n=new Set;for(const r of e){const i=Sf(r);if($f(i))continue;const s=Gv(r),o=Vv(r);for(const a of r.sources??[]){const l=a.name;if(!l||n.has(l))continue;n.add(l);const u=(a.givens??[]).map(d=>d.name).filter(d=>typeof d=="string");t.push({name:l,modelPath:i,...ki(a.annotations)?{description:ki(a.annotations)}:{},views:(a.views??[]).filter(d=>typeof d.name=="string").map(d=>({name:d.name,...ki(d.annotations)?{description:ki(d.annotations)}:{},...Zl(d.annotations)?{chart:Zl(d.annotations)}:{},...o.get(l)?.has(d.name)?{aggregateOnly:!0}:{}})),givens:u,fields:s.get(l)??[]})}}return{sources:t}}function Kv(e,t,n){const r=new Set;for(const i of t){if(i.kind==="names"){for(const o of i.names)r.add(o);continue}const s=n.find(o=>Sf(o)===i.path);if(!s)return e;for(const o of s.sources??[])o.name&&r.add(o.name)}return{...e,sources:e.sources.filter(i=>r.has(i.name))}}const Xv={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Zv(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,i=s=>{if(t!==s){if(s==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(s==="shape_map"||s==="segment_map")return e?.chart===s?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(s=>{const o=i(s);return{value:s,label:Xv[s],...o?{disabled:!0,reason:o}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ho({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:i,onOpen:s,onChange:o}){const a=Zv(t,e,n),l=k.useId();return v.jsx(et,{select:!0,size:"small",variant:"standard",label:"Viz type",value:e,disabled:i!==void 0,onChange:u=>{const d=u.target.value;a.find(c=>c.value===d)?.disabled||o(d)},helperText:i,FormHelperTextProps:{id:l},SelectProps:{...s?{onOpen:s}:{},renderValue:u=>a.find(d=>d.value===u)?.label??String(u),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...i?{"aria-describedby":l}:{}}},sx:{minWidth:140},children:a.map(u=>v.jsx(Ct,{value:u.value,disabled:u.value==="custom"||u.disabled===!0,children:v.jsx(Ko,{primary:u.label,...u.reason?{secondary:u.reason}:{}})},u.value))})}function Qv({sources:e,source:t,view:n,onSource:r,onView:i}){const{theme:s}=nt(),o=e.find(a=>a.name===t);return v.jsxs(v.Fragment,{children:[v.jsx(et,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>v.jsxs(Ct,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&v.jsx(ie,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&v.jsx(ie,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),v.jsxs(Oe,{children:[v.jsx(ie,{variant:"subtitle2",sx:{mb:.5},children:"View"}),v.jsxs(xh,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:s.border,borderRadius:1},children:[(o?.views??[]).map(a=>v.jsxs(yh,{selected:n===a.name,onClick:()=>i(a.name),"aria-label":`View ${a.name}`,children:[v.jsx(Ko,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&v.jsx(Ur,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&v.jsx(ie,{variant:"body2",sx:{p:1.5,color:s.tileTitle},children:"This source declares no views."})]})]})]})}function Jv(e,t){if(!t)return[];const n=new Set;for(const r of e.sources)n.add(r.base);for(const r of e.imports)if(r.kind==="names")for(const i of r.names)n.add(i);return t.sources.filter(r=>n.has(r.name))}function eb({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o}){const{theme:a}=nt(),l=t.kind==="notebook"?"notebook":"dashboard",u=k.useMemo(()=>Jv(t,n),[t,n]),[d,c]=k.useState("query"),[f,p]=k.useState(""),[x,g]=k.useState(""),[y,w]=k.useState(""),[h,m]=k.useState("default"),[b,$]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;c("query");const E=T=>u.some(F=>F.name===T&&F.views.length>0);p(t.sources.map(T=>T.base).find(E)??u.find(T=>T.views.length>0)?.name??""),g(""),w(""),m("default"),$(Math.ceil(r/2))},[e,t,u,r]);const D=f!==""&&x!=="",M=[f,x].filter(E=>E!==""&&!Xo(E)).map(E=>`"${E}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],A=u.find(E=>E.name===f)?.views.find(E=>E.name===x);return v.jsx(gs,{open:e,onClose:i,title:"Add a tile",description:`A tile shows one view of one source this ${l} imports.`,actions:v.jsxs(v.Fragment,{children:[v.jsx(Ee,{onClick:i,children:"Cancel"}),v.jsx(Ee,{variant:"contained",disabled:d==="query"&&(!D||M!==void 0),onClick:()=>d==="text"?o():s({base:f,view:x,...y.trim()?{label:y.trim()}:{},...h!=="default"?{chart:h,...A?{chartCarried:A.chart?[A.chart]:[]}:{}}:{},colspan:b}),children:d==="text"?"Add text":"Add tile"})]}),children:v.jsxs(ye,{sx:{gap:2,pt:1},children:[v.jsxs(Jo,{size:"small",exclusive:!0,value:d,"aria-label":"Tile type",onChange:(E,T)=>{T!==null&&c(T)},children:[v.jsx(Kn,{value:"query",sx:{px:1.5},children:"Query"}),v.jsx(Kn,{value:"text",sx:{px:1.5},children:"Text"})]}),d==="text"?v.jsx(ie,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):u.length===0?v.jsx(ie,{variant:"body2",sx:{color:a.tileTitle},children:n?`This ${l} imports no source by name, so there is nothing to put a tile on. Import a source in the file first.`:"The package's sources are still loading."}):v.jsxs(v.Fragment,{children:[v.jsx(Qv,{sources:u,source:f,view:x,onSource:E=>{p(E),g("")},onView:E=>{g(E),m("default")}}),M&&v.jsx(ie,{variant:"body2",color:"error",children:M}),v.jsx(Ho,{state:h,view:A,cellLabel:"new tile",...A?{}:{disabledReason:"Pick a view to choose its chart."},onChange:E=>m(E)}),v.jsxs(ye,{direction:"row",sx:{gap:1.5},children:[v.jsx(et,{size:"small",label:"Title",placeholder:"Uses the view's name",value:y,onChange:E=>w(E.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}}),r>1&&v.jsx(et,{size:"small",type:"number",label:`Width (of ${r})`,value:b,onChange:E=>$(Math.min(Math.max(Number(E.target.value)||1,1),r)),inputProps:{min:1,max:r,"aria-label":"Tile width"},sx:{width:140}})]})]})]})})}const Jl=4e3;function tb(e,t){const n=e.split(`
143
+ `),r=t.split(`
144
+ `);if(n.length>Jl||r.length>Jl)return[...n.map(l=>({kind:"del",text:l})),...r.map(l=>({kind:"add",text:l}))];const i=Array.from({length:n.length+1},()=>new Uint32Array(r.length+1));for(let l=n.length-1;l>=0;l--)for(let u=r.length-1;u>=0;u--)i[l][u]=n[l]===r[u]?i[l+1][u+1]+1:Math.max(i[l+1][u],i[l][u+1]);const s=[];let o=0,a=0;for(;o<n.length&&a<r.length;)n[o]===r[a]?(s.push({kind:"same",text:n[o]}),o++,a++):i[o+1][a]>=i[o][a+1]?s.push({kind:"del",text:n[o++]}):s.push({kind:"add",text:r[a++]});for(;o<n.length;)s.push({kind:"del",text:n[o++]});for(;a<r.length;)s.push({kind:"add",text:r[a++]});return s}function nb(e,t=3){const n=new Array(e.length).fill(!1);e.forEach((s,o)=>{if(s.kind!=="same")for(let a=Math.max(0,o-t);a<=Math.min(e.length-1,o+t);a++)n[a]=!0});const r=[];let i=0;return e.forEach((s,o)=>{n[o]?(i>0&&r.push({kind:"fold",count:i}),i=0,r.push(s)):i++}),i>0&&r.push({kind:"fold",count:i}),r}function rb({open:e,before:t,after:n,onClose:r}){const{theme:i}=nt(),s=k.useMemo(()=>e?nb(tb(t,n)):[],[e,t,n]),o=s.filter(l=>l.kind==="add").length,a=s.filter(l=>l.kind==="del").length;return v.jsx(gs,{open:e,onClose:r,maxWidth:"md",title:"The change to the file",description:v.jsxs(v.Fragment,{children:["What the last save wrote. Lines the builder does not own, such as comments and other Malloy, are left where they were."," ",v.jsxs(Oe,{component:"span",sx:{fontVariantNumeric:"tabular-nums"},children:["+",o," −",a]})]}),actions:v.jsx(Ee,{onClick:r,children:"Close"}),children:v.jsx(Oe,{component:"pre","aria-label":"File changes",sx:{m:0,px:2,py:1,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,lineHeight:1.6,overflowX:"auto",bgcolor:i.background,color:i.foreground},children:s.map((l,u)=>l.kind==="fold"?v.jsx(Oe,{component:"span",sx:{display:"block",opacity:.55,py:.25},children:`⋯ ${l.count} unchanged line${l.count===1?"":"s"}`},u):v.jsxs(Oe,{component:"span",sx:{display:"block",mx:-2,px:2,whiteSpace:"pre",bgcolor:l.kind==="add"?"rgba(46, 125, 91, 0.16)":l.kind==="del"?"rgba(168, 41, 31, 0.14)":"transparent",opacity:l.kind==="del"?.8:1},children:[l.kind==="add"?"+ ":l.kind==="del"?"− ":" ",l.text]},u))})})}const Vs=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function ib({lastSave:e,unit:t,moved:n},r){if(!e)return[];const i=[],s=n?n.after-n.before:0;return s===1?i.push(`Added a ${t}`):s>1?i.push(`Added ${Vs(s,t)}`):s<0?i.push(`Removed ${Vs(-s,t)}`):e.structural?i.push(`Changed the ${t}s in the file`):i.push("Saved your edits"),r.length>0&&i.push(`Removed ${Vs(r.length,"comment")} with their ${t}s`),e.clearsHistory&&i.push("Undo history was cleared"),i}function sb(e){const{lastSave:t,canUndoSave:n,undone:r,viewing:i,onView:s,onUndoSave:o}=e;if(r)return v.jsx(xt,{severity:"info",role:"status",children:"Save undone. Your edits are back and unsaved."});if(!t)return null;const a=t.removedComments??[];return v.jsxs(v.Fragment,{children:[v.jsxs(xt,{severity:"success",role:"status",action:v.jsxs(v.Fragment,{children:[v.jsx(Ee,{color:"inherit",size:"small",onClick:()=>s(!0),children:"View change"}),v.jsx(Ee,{color:"inherit",size:"small",disabled:!n,onClick:()=>void o(),children:"Undo save"})]}),children:[ib(e,a).join(". "),".",a.length>0&&v.jsx(Oe,{component:"span","aria-label":"Comments removed with their cell",sx:{display:"block",whiteSpace:"pre",fontFamily:"monospace",fontSize:12,mt:.5},children:a.join(`
145
+ `)})]}),v.jsx(rb,{open:i,before:t.before,after:t.after,onClose:()=>s(!1)})]})}const Ys="self";function ob({open:e,document:t,source:n,givenNames:r,dashboards:i,onClose:s,onApply:o}){const{theme:a}=nt(),[l,u]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(x=>x.source===n.name);u((n.dimensions??[]).map(x=>{const g=p.find(y=>y.name===x.name);return{name:x.name,expression:x.expression,to:g?.to??[],given:g?.given??""}}))},[e,n,t]);const d=(p,x)=>u(g=>g.map((y,w)=>{if(w!==p)return y;const h={...y};return x(h),h})),c=[Ys,...i.filter(p=>p!==Ys)],f=p=>p===Ys?"This dashboard":p;return v.jsx(gs,{open:e,onClose:s,title:"Drill-through",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the dashboard it opens.",actions:v.jsxs(v.Fragment,{children:[v.jsx(Ee,{onClick:s,children:"Cancel"}),v.jsx(Ee,{variant:"contained",onClick:()=>{n&&(o(l.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),s())},disabled:l.length===0,children:"Apply"})]}),children:v.jsx(ye,{sx:{gap:2,pt:1},children:l.length===0?v.jsx(ie,{variant:"body2",sx:{color:a.tileTitle},children:n?v.jsxs(v.Fragment,{children:[v.jsx(Oe,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",v.jsx(Oe,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((p,x)=>v.jsxs(Oe,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[v.jsxs(Oe,{sx:{minWidth:0,pt:.75},children:[v.jsx(ie,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:p.name}),v.jsxs(ie,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.expression,children:["is ",p.expression]})]}),v.jsx(et,{select:!0,size:"small",label:"Clicks go to",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:g=>g.length===0?"Not clickable":g.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:g=>d(x,y=>{const w=g.target.value;y.to=Array.isArray(w)?w:String(w).split(",").filter(Boolean)}),children:c.map(g=>v.jsxs(Ct,{value:g,children:[v.jsx(io,{size:"small",checked:p.to.includes(g),sx:{p:0,mr:1}}),v.jsx(Ko,{primary:f(g)})]},g))}),v.jsxs(et,{select:!0,size:"small",label:"Sets the control",value:p.given,disabled:p.to.length===0,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:p.given===""?`Named ${p.name}, like the dimension`:void 0,onChange:g=>d(x,y=>{y.given=g.target.value}),children:[v.jsx(Ct,{value:"",children:v.jsx("em",{children:"Same name as the dimension"})}),r.map(g=>v.jsx(Ct,{value:g,children:g},g))]})]},p.name))})})}const jf=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function ab({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:s}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[u,d]=k.useState({kind:"new"}),[c,f]=k.useState(""),[p,x]=k.useState("select"),[g,y]=k.useState(""),[w,h]=k.useState(""),[m,b]=k.useState([]),[$,D]=k.useState(!1),[M,A]=k.useState(!1),E=R=>t.sources.find(G=>G.name===R.source)?.base??R.source;k.useEffect(()=>{if(e)if(A(n!==void 0),n){d({kind:"existing",name:n.name}),f(n.label??"");const R=Lg(t,n);b(R);const G=R.filter(pe=>pe.include),ce=new Set(G.map(pe=>pe.field));h(ce.size===1?G[0].field:n.field??""),D(ce.size>1)}else d({kind:"new"}),f(""),x("select"),h(""),y(new Date().toISOString().slice(0,10)),b(t.tiles.map(R=>({include:_o(R),field:""}))),D(!1)},[e,n,t]);const T=k.useMemo(()=>[...(t.localGivens??[]).map(R=>R.name),...r.map(R=>R.name)],[t,r]),F=k.useMemo(()=>w.trim()?Pg(w.trim(),T):"",[w,T]),z=u.kind==="existing"?n??r.find(R=>R.name===u.name):F?{name:F,type:yi({name:F,label:c,kind:p,field:w}).type}:void 0,q=z?.type!==void 0&&!z.type.startsWith("filter<"),K=m.find(R=>R.include)?.op??ls(z?.type),X=(R,G)=>{A(!0),b(ce=>ce.map((pe,Fe)=>Fe===R?{...pe,...G}:pe))},oe=R=>{A(!0),b(G=>G.map(ce=>({...ce,op:R})))},ae=R=>{const G=ls(R);b(ce=>ce.map(({op:pe,...Fe})=>G?{...Fe,op:G}:Fe))},Q=R=>{A(!0),d({kind:"existing",name:R.name}),h(R.field??""),ae(R.type)},he=R=>{A(!0),x(R),ae(yi({name:"X",label:c,kind:R,field:w}).type)},O=t.tiles.map(_o),B=O.filter(Boolean).length,W=m.filter((R,G)=>R.include&&O[G]).length,L=t.tiles.filter((R,G)=>(m[G]?.include??!1)&&O[G]&&we(R)),_=L.length>0?L:t.tiles.filter((R,G)=>O[G]&&we(R)),N=k.useMemo(()=>{const R=new Map;let G=!1;for(const ce of _){const pe=i?.(ce);if(pe){G=!0;for(const Fe of pe)R.has(Fe.name)||R.set(Fe.name,Fe)}}return G?[...R.values()]:void 0},[m,t.tiles,i]),H=(()=>{const R=w.trim();for(const G of L){const ce=i?.(G);if(!ce||ce.some(pe=>pe.name===R))return E(G)}return L[0]?E(L[0]):t.sources[0]?.base})(),j=R=>{A(!0),b(G=>G.map((ce,pe)=>({...ce,include:R&&O[pe]})))},S=k.useMemo(()=>$?m:m.map(R=>({...R,field:w})),[$,m,w]),I=R=>{for(const G of _){const ce=i?.(G)?.find(pe=>pe.name===R.trim());if(ce?.type)return ce.type}},Z=R=>qi(z?.type,R.type),V=(R,G)=>{if(R.trim()==="")return"Pick the field this filter compares.";const ce=G?i?.(G):void 0;if(!ce)return;const pe=ce.find(Fe=>Fe.name===R.trim());if(!pe)return`Not a field of ${G?E(G):"the tiles' source"}.`;if(pe.type&&!qi(z?.type,pe.type))return`${R.trim()} is ${Ll(pe.type)}; this filter compares ${Ll(z?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},se=R=>{if(A(!0),h(R),l||u.kind!=="new")return;const G=I(R),ce=yi({name:"X",label:c,kind:p,field:R}).type;G&&!qi(ce,G)&&he(Ig(G))},Y=R=>{const G=t.tiles[R];return G&&we(G)?G:void 0},ve=S.map((R,G)=>R.include&&O[G]?V(R.field,Y(G)):void 0),J=ve.every(R=>R===void 0),be=M?ve:ve.map(()=>{}),le=M&&!$&&W>0?L.map(R=>V(w,R)).find(Boolean):void 0,me=z!==void 0&&J&&(u.kind==="existing"||w.trim()!==""&&F!==""),Ge=()=>{if(!(!z||!me))if(u.kind==="new")s(z.name,S,yi({name:z.name,label:c.trim()||jf(z.name),kind:p,field:w.trim(),...H?{source:H}:{},...g?{dateDefault:g}:{}}));else if(n?.origin==="dashboard"&&n.local){const R=c.trim(),G=R!==(n.local.label??"");s(z.name,S,G?{...n.local,...R?{label:R}:{}}:void 0)}else s(z.name,S)},te=l&&a.origin==="model";return{editing:l,shown:a,fromModel:te,source:u,setSource:d,label:c,setLabel:f,kind:p,dateDefault:g,setDateDefault:y,field:w,rows:m,setRows:b,perTile:$,setPerTile:D,newName:F,target:z,valueTyped:q,commonOp:K,setRow:X,setCommonOp:oe,pickExisting:Q,pickKind:he,bindable:O,bindableCount:B,included:W,commonFields:N,setAll:j,accepts:Z,pickField:se,rowProblems:be,commonProblem:le,canApply:me,apply:Ge}}function ec({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:l,autoFocus:u,placeholder:d,sx:c}){const f=k.useMemo(()=>(n??[]).filter(x=>r?.(x)??!0).map(x=>x.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(x=>[x.name,x.type])),[n]);return v.jsx(bh,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(x,g)=>t(g),value:e,onChange:(x,g)=>t(typeof g=="string"?g:""),disabled:l,disableClearable:!0,renderOption:(x,g)=>k.createElement("li",{...x,key:g},v.jsx(ie,{variant:"body2",sx:{flex:1},children:g}),p.get(g)&&v.jsx(ie,{variant:"caption",sx:{opacity:.6},children:p.get(g)?.replace(/_type$/,"")})),renderInput:x=>v.jsx(et,{...x,label:i,placeholder:d,autoFocus:u,error:o,helperText:a,inputProps:{...x.inputProps,"aria-label":s}}),sx:c})}const tc=e=>e&&we(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this dashboard does not write."};function lb({open:e,document:t,control:n,available:r,fieldsFor:i,onClose:s,onApply:o,onRemove:a}){const{theme:l}=nt(),{editing:u,shown:d,fromModel:c,source:f,setSource:p,label:x,setLabel:g,kind:y,dateDefault:w,setDateDefault:h,field:m,rows:b,setRows:$,perTile:D,setPerTile:M,newName:A,target:E,valueTyped:T,commonOp:F,setRow:z,setCommonOp:q,pickExisting:K,pickKind:X,bindable:oe,bindableCount:ae,included:Q,commonFields:he,setAll:O,accepts:B,pickField:W,rowProblems:L,commonProblem:_,canApply:N,apply:H}=ab({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:o}),j=(S,I,Z)=>v.jsx(et,{select:!0,size:"small",label:"Compares",value:S??">=",onChange:V=>I(V.target.value),inputProps:{"aria-label":Z},sx:{width:130},children:Dg.filter(V=>V.op!=="~").map(V=>v.jsx(Ct,{value:V.op,children:V.label},V.op))});return v.jsx(gs,{open:e,onClose:s,title:u?d.label??d.name:"Add a filter",description:u?v.jsxs(v.Fragment,{children:[v.jsxs(Oe,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",d.name]}),c?" · declared in the model, so its label and options are set there":" · declared in this dashboard"]}):"A control on the page, and the tiles it filters.",actions:v.jsxs(v.Fragment,{children:[u&&v.jsx(Ee,{color:"error",onClick:()=>a(d.name),"aria-label":`Remove control ${d.name}`,sx:{mr:"auto"},children:"Remove from dashboard"}),v.jsx(Ee,{onClick:s,children:"Cancel"}),v.jsx(Un,{title:N||E===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:v.jsx("span",{children:v.jsx(Ee,{variant:"contained",onClick:H,disabled:!N,children:u?"Apply":"Add filter"})})})]}),children:v.jsxs(ye,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&v.jsxs(Jo,{exclusive:!0,size:"small",value:f.kind,onChange:(S,I)=>{I==="new"?p({kind:"new"}):I==="existing"&&r[0]&&K(r[0])},"aria-label":"Where the filter comes from",children:[v.jsx(Kn,{value:"new",children:"New in this dashboard"}),v.jsx(Kn,{value:"existing",children:"From the model"})]}),!u&&f.kind==="existing"?v.jsx(et,{select:!0,size:"small",label:"Control",value:f.name,onChange:S=>{const I=r.find(Z=>Z.name===S.target.value);I&&K(I)},children:r.map(S=>v.jsxs(Ct,{value:S.name,children:[S.label??S.name,v.jsxs(ie,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",S.name]})]},S.name))}):null,v.jsxs(ye,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!D&&v.jsx(ec,{value:m,onChange:W,fields:he,accepts:B,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:_!==void 0,helperText:_??(!u&&A?`Declared as $${A}`:void 0),sx:{flex:1,minWidth:200}}),!c&&v.jsx(et,{size:"small",label:"Label",placeholder:A?jf(A):"",value:x,onChange:S=>g(S.target.value),inputProps:{"aria-label":"Control label"},sx:{flex:1,minWidth:160}}),T&&!D&&j(F,q,"Comparison")]}),!u&&f.kind==="new"&&v.jsxs(ye,{direction:"row",sx:{gap:1.5},children:[v.jsx(et,{select:!0,size:"small",label:"Control",value:y,onChange:S=>X(S.target.value),inputProps:{"aria-label":"Kind of control"},slotProps:{select:{renderValue:S=>Nl.find(I=>I.kind===S)?.label??String(S)}},sx:{flex:1},children:Nl.map(S=>v.jsxs(Ct,{value:S.kind,children:[S.label,v.jsx(ie,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:S.hint})]},S.kind))}),y==="date"&&v.jsx(et,{size:"small",type:"date",label:"Starts at",value:w,onChange:S=>h(S.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),v.jsxs(Oe,{children:[v.jsxs(ye,{direction:"row",sx:{alignItems:"center",gap:.5},children:[v.jsx(io,{size:"small",checked:ae>0&&Q===ae,indeterminate:Q>0&&Q<ae,disabled:ae===0,onChange:S=>O(S.target.checked),inputProps:{"aria-label":"All tiles"}}),v.jsxs(ie,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",Q," of ",t.tiles.length," tiles"]}),v.jsx(Ee,{size:"small",onClick:()=>{D||$(S=>S.map(I=>({...I,field:m}))),M(S=>!S)},children:D?"Same field for all":"Adjust per tile"})]}),v.jsx(ye,{sx:{gap:D?1:0},children:t.tiles.map((S,I)=>{if(!we(S))return null;const Z=b[I],V=S.label??S.name,se=D?L[I]:void 0;return v.jsxs(ye,{direction:"row",sx:{gap:1,alignItems:D?"flex-start":"center",opacity:oe[I]?1:.6},children:[v.jsx(io,{size:"small",disabled:!oe[I],checked:(Z?.include??!1)&&oe[I],inputProps:{"aria-label":`Filter ${V}`},onChange:Y=>z(I,{include:Y.target.checked})}),v.jsx(ie,{variant:"body2",sx:{flex:1,minWidth:0,pt:D?1:0},noWrap:!0,children:V}),oe[I]?D&&v.jsxs(v.Fragment,{children:[T&&j(Z?.op,Y=>z(I,{op:Y}),`Comparison for ${V}`),v.jsx(ec,{value:Z?.field??"",onChange:Y=>z(I,{field:Y}),fields:i?.(S),accepts:B,label:"Field",ariaLabel:`Field for ${V}`,disabled:!Z?.include,error:se!==void 0,helperText:se,sx:{width:220}})]}):v.jsx(Un,{title:tc(t.tiles[I]).reason,children:v.jsx(ie,{variant:"caption",sx:{color:l.tileTitle},children:tc(t.tiles[I]).label})})]},`${S.source}.${S.name}`)})}),Q===0&&v.jsx(ie,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}const Cf=en(v.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),cb=e=>({imports:e.imports,...e.kind===void 0?{}:{kind:e.kind},...e.columns===void 0?{}:{columns:e.columns},...e.autorun===void 0?{}:{autorun:e.autorun}}),db=e=>`../${e}`;function ub(e,t,n){const r=db(n);if(e.some(s=>s.kind==="names"&&s.names.includes(t)))return e;const i=e.findIndex(s=>s.kind==="names"&&s.from===r);return i<0?[...e,{kind:"names",names:[t],from:r}]:e.map((s,o)=>o===i&&s.kind==="names"?{...s,names:[...s.names,t]}:s)}const fb=(e,t)=>e.flatMap(n=>{if(n.kind!=="names"||!n.names.includes(t))return[n];const r=n.names.filter(i=>i!==t);return r.length===0?[]:[{...n,names:r}]}),Ks=[2,3,4,6,12,oh];function hb({anchor:e,settings:t,catalog:n,inUse:r,onClose:i,onCommit:s}){const{theme:o}=nt(),{draft:a,patch:l,close:u}=nl(t,e!==null,s,i),d=a?.kind==="notebook",c=new Set((a?.imports??[]).flatMap(g=>g.kind==="names"?g.names:[])),f=(n?.sources??[]).filter(g=>!c.has(g.name)&&!g.modelPath.startsWith("dashboards/")&&!g.modelPath.startsWith("notebooks/")),p=a?.columns??$c,x=Ks.includes(p)?Ks:[...Ks,p].sort((g,y)=>g-y);return v.jsx(Tc,{open:e!==null&&a!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:380,p:2}}},children:a&&v.jsxs(ye,{sx:{gap:1.5},children:[v.jsx(ie,{variant:"overline",sx:{color:o.tileTitle,lineHeight:1.5},children:d?"Notebook":"Dashboard"}),v.jsxs(ye,{direction:"row",sx:{gap:1,alignItems:"center",flexWrap:"wrap"},children:[v.jsx(ie,{variant:"caption",sx:{color:o.tileTitle},children:"Show as"}),v.jsxs(Jo,{size:"small",exclusive:!0,value:d?"notebook":"dashboard","aria-label":"Show as",onChange:(g,y)=>{y!==null&&l(w=>{y==="notebook"?(w.kind="notebook",delete w.columns):delete w.kind})},children:[v.jsx(Kn,{value:"dashboard",sx:{px:1.5},children:"Dashboard"}),v.jsx(Kn,{value:"notebook",sx:{px:1.5},children:"Notebook"})]})]}),!d&&v.jsx(et,{select:!0,size:"small",label:"Grid width",value:p,helperText:"Columns across the page. Tiles are placed in these.",inputProps:{"aria-label":"Grid width"},onChange:g=>l(y=>{y.columns=Number(g.target.value)}),children:x.map(g=>v.jsx(Ct,{value:g,children:g},g))}),v.jsxs(ye,{sx:{gap:.75},children:[v.jsx(ie,{variant:"caption",sx:{color:o.tileTitle},children:"Sources"}),v.jsxs(ye,{direction:"row","aria-label":"Sources",sx:{gap:.75,flexWrap:"wrap"},children:[a.imports.length===0&&v.jsx(ie,{variant:"body2",sx:{opacity:.7},children:"None imported."}),a.imports.flatMap(g=>g.kind==="all"?[v.jsx(Ur,{size:"small",variant:"outlined",label:g.from,title:"Every declaration in this file; edit it in the file"},`all ${g.from}`)]:g.names.map(y=>v.jsx(Ur,{size:"small",label:y,title:r.has(y)?`${y} from ${g.from}; a tile reads it`:`${y} from ${g.from}`,...r.has(y)?{}:{onDelete:()=>l(w=>{w.imports=fb(w.imports,y)}),deleteIcon:v.jsx(Cf,{"aria-label":`Remove source ${y}`})}},`${g.from} ${y}`)))]}),n&&f.length>0&&v.jsx(et,{select:!0,size:"small",label:"Add a source",value:"",inputProps:{"aria-label":"Add a source"},onChange:g=>{const y=f.find(w=>`${w.modelPath} ${w.name}`===g.target.value);y&&l(w=>{w.imports=ub(w.imports,y.name,y.modelPath)})},children:f.map(g=>v.jsxs(Ct,{value:`${g.modelPath} ${g.name}`,children:[g.name,v.jsx(ie,{component:"span",variant:"caption",sx:{ml:1,opacity:.7},children:g.modelPath})]},`${g.modelPath} ${g.name}`))})]}),v.jsx(ah,{control:v.jsx(lh,{size:"small",checked:a.autorun!==!1,slotProps:{input:{"aria-label":"Run as controls change"}},onChange:g=>l(y=>{g.target.checked?delete y.autorun:y.autorun=!1})}),label:v.jsxs(ie,{variant:"body2",children:["Run as controls change",v.jsx(ie,{component:"span",variant:"caption",sx:{display:"block",opacity:.7},children:"Off, readers press Apply. For a page whose queries are slow."})]})})]})})}const pb=en(v.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),mb=49;function gb({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:i,onRemove:s,children:o}){const{theme:a}=nt();return v.jsx(v.Fragment,{children:v.jsxs(ye,{sx:{gap:1,position:"sticky",top:mb,zIndex:4,bgcolor:a.background,pb:1},children:[v.jsxs(ye,{direction:"row","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",minHeight:32},children:[v.jsx(pb,{sx:{fontSize:18,color:a.tileTitle,opacity:.7}}),v.jsx(ie,{variant:"subtitle2",sx:{color:a.tileTitle,mr:.5},children:"Filters"}),e.length===0&&v.jsx(ie,{variant:"body2",sx:{color:a.tileTitle,opacity:.8},children:"None yet."}),e.map(l=>{const u=n(l.name,l.type);return v.jsx(Un,{title:u.length>0?`$${l.name} · cannot filter on: ${u.join(", ")}`:`$${l.name} · ${l.origin==="dashboard"?"declared here":"from the model"} · ${l.boundTiles} of ${t} tiles`,children:v.jsx(Ur,{size:"small",label:l.label??l.name,"aria-label":`Edit filter ${l.name}`,color:u.length>0?"warning":"default",variant:l.origin==="dashboard"?"filled":"outlined",onClick:()=>r(l),onDelete:()=>s(l.name),deleteIcon:v.jsx(Cf,{"aria-label":`Remove filter ${l.name}`}),sx:{opacity:l.boundTiles===0?.6:1,cursor:"pointer",transition:"opacity 120ms"}})},l.name)}),v.jsx(Oe,{sx:{ml:"auto"},children:v.jsx(Ec,{label:"Filter",icon:v.jsx(ms,{}),onClick:()=>i(),ariaLabel:"Add filter",ariaHasPopup:"dialog"})})]}),o]})})}const vb=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),bb=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},Of=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),Ef=e=>`gap.${e}`,xb=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),l=o===0||s.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Ye(e[o-1]),colspan:t-r}),l&&(r=0),n.push(Of(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:Ye(i),colspan:t-r}),n};var yb=Object.create,Mf=Object.defineProperty,wb=Object.defineProperties,kb=Object.getOwnPropertyDescriptor,$b=Object.getOwnPropertyDescriptors,ps=Object.getOwnPropertySymbols,Tf=Object.prototype.hasOwnProperty,Af=Object.prototype.propertyIsEnumerable,Sb=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),pi=e=>{throw TypeError(e)},Vo=(e,t,n)=>t in e?Mf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xs=(e,t)=>{for(var n in t||(t={}))Tf.call(t,n)&&Vo(e,n,t[n]);if(ps)for(var n of ps(t))Af.call(t,n)&&Vo(e,n,t[n]);return e},Zs=(e,t)=>wb(e,$b(t)),jb=(e,t)=>{var n={};for(var r in e)Tf.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ps)for(var r of ps(e))t.indexOf(r)<0&&Af.call(e,r)&&(n[r]=e[r]);return n},Cb=e=>{var t;return[,,,yb((t=void 0)!=null?t:null)]},If=["class","method","getter","setter","accessor","field","value","get","set"],Dr=e=>e!==void 0&&typeof e!="function"?pi("Function expected"):e,Ob=(e,t,n,r,i)=>({kind:If[e],name:t,metadata:r,addInitializer:s=>n._?pi("Already initialized"):i.push(Dr(s||null))}),Eb=(e,t)=>Vo(t,Sb("metadata"),e[3]),$i=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},Df=(e,t,n,r,i,s)=>{for(var o,a,l,u,d,c=t&7,f=!1,p=!1,x=e.length+1,g=If[c+5],y=e[x-1]=[],w=e[x]||(e[x]=[]),h=(i=i.prototype,kb({get[n](){return Pr(this,s)},set[n](b){return xn(this,s,b)}},n)),m=r.length-1;m>=0;m--)u=Ob(c,n,l={},e[3],w),u.static=f,u.private=p,d=u.access={has:b=>n in b},d.get=b=>b[n],d.set=(b,$)=>b[n]=$,a=(0,r[m])({get:h.get,set:h.set},u),l._=1,a===void 0?Dr(a)&&(h[g]=a):typeof a!="object"||a===null?pi("Object expected"):(Dr(o=a.get)&&(h.get=o),Dr(o=a.set)&&(h.set=o),Dr(o=a.init)&&y.unshift(o));return h&&Mf(i,n,h),i},Pf=(e,t,n)=>t.has(e)||pi("Cannot "+n),Pr=(e,t,n)=>(Pf(e,t,"read from private field"),t.get(e)),xr=(e,t,n)=>t.has(e)?pi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),xn=(e,t,n,r)=>(Pf(e,t,"write to private field"),t.set(e,n),n);function wn(e){return e instanceof sl||e instanceof zf}var Si=10,Mb=class extends Ze{constructor(e){super(e);const t=gt(()=>{const{dragOperation:r}=e;if(Kr(r.activatorEvent)&&wn(r.source)&&r.status.initialized){const i=e.registry.plugins.get(ci);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!Kr(r.nativeEvent)||!wn(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:l}=i,{by:u}=r;if(!u)return;const d=Tb(u),{source:c,target:f}=s,{center:p}=s.shape.current,x=[],g=[];Ie(()=>{for(const $ of l.droppables){const{id:D}=$;if(!$.accepts(c)||D===f?.id&&wn($)||!$.element)continue;let M=$.shape;const A=new Ot($.element,{getBoundingClientRect:E=>Vr(E,void 0,.2)});!A.height||!A.width||(d=="down"&&p.y+Si<A.center.y||d=="up"&&p.y-Si>A.center.y||d=="left"&&p.x-Si>A.center.x||d=="right"&&p.x+Si<A.center.x)&&(x.push($),$.shape=A,g.push(()=>$.shape=M))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(x,dm);Ie(()=>g.forEach($=>$()));const[w]=y;if(!w)return;const{id:h}=w,{index:m,group:b}=c.sortable;o.setDropTarget(h).then(()=>{const{source:$,target:D,shape:M}=s;if(!$||!wn($)||!M)return;const{index:A,group:E,target:T}=$.sortable,F=m!==A||b!==E,z=F?T:D?.element;if(!z)return;au(z);const q=new Ot(z);if(!q)return;const K=Et.delta(q,Et.from(M.current.boundingRectangle),$.alignment);o.move({by:K}),F?o.setDropTarget($.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Tb(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var Ab=Object.defineProperty,Ib=Object.defineProperties,Db=Object.getOwnPropertyDescriptors,nc=Object.getOwnPropertySymbols,Pb=Object.prototype.hasOwnProperty,Lb=Object.prototype.propertyIsEnumerable,rc=(e,t,n)=>t in e?Ab(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,An=(e,t)=>{for(var n in t||(t={}))Pb.call(t,n)&&rc(e,n,t[n]);if(nc)for(var n of nc(t))Lb.call(t,n)&&rc(e,n,t[n]);return e},In=(e,t)=>Ib(e,Db(t));function Nb(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ji(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Qs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Rb(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(h,m)=>h===m||h!==null&&typeof h=="object"&&"id"in h&&h.id===m;if(Array.isArray(e)){const h=e.findIndex(b=>l(b,s.id)),m=e.findIndex(b=>l(b,o.id));if(h===-1||m===-1){if(Qs(s)){const b=s.initialIndex,$=s.index;return b===$||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,$)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const b=s.index;if(b!==h)return n(e,h,b)}return n(e,h,m)}const u=Object.entries(e);let d=-1,c,f=-1,p;for(const[h,m]of u)if(d===-1&&(d=m.findIndex(b=>l(b,s.id)),d!==-1&&(c=h)),f===-1&&(f=m.findIndex(b=>l(b,o.id)),f!==-1&&(p=h)),d!==-1&&f!==-1)break;if(d===-1&&Qs(s)){const h=s.initialGroup==null?void 0:ji(e,s.initialGroup),m=s.initialIndex,b=s.group==null?void 0:ji(e,s.group),$=s.index;if(h==null||b==null||h===b&&m===$)return"preventDefault"in t&&t.preventDefault(),e;if(h===b)return In(An({},e),{[h]:n(e[h],m,$)});const D=e[h][m];return In(An({},e),{[h]:[...e[h].slice(0,m),...e[h].slice(m+1)],[b]:[...e[b].slice(0,$),D,...e[b].slice($)]})}if(!s.manager)return e;const{dragOperation:x}=s.manager,g=(i=(r=x.shape)==null?void 0:r.current.center)!=null?i:x.position.current;if(p==null){const h=ji(e,o.id);if(h!=null){const m=o.shape&&g.y>o.shape.center.y?e[h].length:0;p=h,f=m}}if(c==null||p==null||c===p&&d===f){if(c!=null&&c===p&&d===f&&Qs(s)){const h=s.group==null?void 0:ji(e,s.group),m=s.group!=null&&h!==c,b=s.index!==d;if(m||b){const $=s.group==null?c:h;if($!=null){if(c===$)return In(An({},e),{[c]:n(e[c],d,s.index)});const D=e[c][d];return In(An({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[$]:[...e[$].slice(0,s.index),D,...e[$].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return In(An({},e),{[c]:n(e[c],d,f)});const y=o.shape&&Math.round(g.y)>Math.round(o.shape.center.y)?1:0,w=e[c][d];return In(An({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[p]:[...e[p].slice(0,f+y),w,...e[p].slice(f+y)]})}function zb(e,t){return Rb(e,t,Nb)}function ic(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function sc(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var oc="__default__",Wb=class extends Ze{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof sl){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!wn(o)||!wn(a)||o.sortable===a.sortable)return;const l=t(),u=ic(l),d=o.sortable.group===a.sortable.group,c=l.get(o.sortable.group),f=d?c:l.get(a.sortable.group);!c||!f||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var p,x;const g=t();if(sc(u,l,g))return;const y=o.sortable.element,w=a.sortable.element;if(!w||!y||!d&&a.id===o.sortable.group)return;const h=Ci(c),m=d?h:Ci(f),b=(p=o.sortable.group)!=null?p:oc,$=(x=a.sortable.group)!=null?x:oc,D={[b]:h,[$]:m},M=zb(D,r);if(D===M)return;const A=M[$].indexOf(o.sortable),E=M[$].indexOf(a.sortable);i.collisionObserver.disable(),ac(y,A,w,E),Ie(()=>{for(const[T,F]of M[b].entries())F.index=T;if(!d)for(const[T,F]of M[$].entries())F.group=a.sortable.group,F.index=T}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;wn(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=ic(a),u=a.get(o.sortable.initialGroup);u&&i.renderer.rendering.then(()=>{const d=t();if(sc(l,a,d))return;const c=Ci(u),f=Ci(u,Fb),p=o.sortable.element,x=f.indexOf(o.sortable),g=c[x],y=g?.element;!g||!y||!p||(ac(p,g.index,y,o.index),Ie(()=>{for(const w of a.values()){const h=Array.from(w).values();for(const m of h)m.index=m.initialIndex,m.group=m.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function ac(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function _b(e,t){return e.index-t.index}function Fb(e,t){return e.initialIndex-t.initialIndex}function Ci(e,t=_b){return Array.from(e).sort(t)}var lc=[Mb,Wb],Lf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function cc(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var Oi=new Vh,Nf,Rf,Xt,rl,Lr,Nr,il,Fn;Rf=[ue],Nf=[ue];var As=class{constructor(e,t){xr(this,rl,$i(Xt,8,this)),$i(Xt,11,this),xr(this,Lr),xr(this,Nr),xr(this,il,$i(Xt,12,this)),$i(Xt,15,this),xr(this,Fn),this.register=()=>(Ie(()=>{var x,g;(x=this.manager)==null||x.registry.register(this.droppable),(g=this.manager)==null||g.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ie(()=>{var x,g;(x=this.manager)==null||x.registry.unregister(this.droppable),(g=this.manager)==null||g.registry.unregister(this.draggable)})},this.destroy=()=>{Ie(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:l,transition:u=Lf,plugins:d}=n,c=jb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=kt(d,lc),p=cc(i);this.droppable=new sl(Zs(Xs({},c),{disabled:p.droppable}),t,this),this.draggable=new zf(Zs(Xs({},c),{disabled:p.draggable,plugins:f,effects:()=>[()=>{var x,g,y;const w=(x=this.manager)==null?void 0:x.dragOperation.status;w?.initializing&&this.id===((y=(g=this.manager)==null?void 0:g.dragOperation.source)==null?void 0:y.id)&&Oi.clear(this.manager),w?.dragging&&Oi.set(this.manager,this.id,de(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:x,group:g,manager:y}=this,w=Pr(this,Nr),h=Pr(this,Lr);(x!==w||g!==h)&&(xn(this,Nr,x),xn(this,Lr,g),this.animate())},()=>{var x,g;const{target:y}=this,{isDragSource:w}=this.draggable;((g=(x=this.draggable.pluginConfig(qa))==null?void 0:x.feedback)!=null?g:"default")==="move"&&w&&(this.droppable.disabled=!y)},...r()],type:l,sensors:a}),t,this),xn(this,Fn,c.element),this.manager=t,this.index=o,xn(this,Nr,o),this.group=s,xn(this,Lr,s),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=Oi.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Oi.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){de(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:i}=this;if(!i)return;for(const d of i.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.cancel();const s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=At(i),l=jl(i,a,!1),u=jl(i,a);if(o.x||o.y){const d=Pa(lt(i))?Zs(Xs({},t),{duration:0}):t;lu({element:i,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Ie(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ie(()=>{const t=Pr(this,Fn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),xn(this,Fn,e)})}get element(){var e,t;const n=Pr(this,Fn);if(n)return(t=(e=ko.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=kt(e,lc)}set disabled(e){const t=cc(e);Ie(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ie(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??cu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ie(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Xt=Cb();rl=new WeakMap;Lr=new WeakMap;Nr=new WeakMap;il=new WeakMap;Fn=new WeakMap;Df(Xt,4,"index",Rf,As,rl);Df(Xt,4,"group",Nf,As,il);Eb(Xt,As);var zf=class extends Cs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},sl=class extends Os{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},qb=Object.defineProperty,Bb=Object.defineProperties,Ub=Object.getOwnPropertyDescriptors,dc=Object.getOwnPropertySymbols,Gb=Object.prototype.hasOwnProperty,Hb=Object.prototype.propertyIsEnumerable,uc=(e,t,n)=>t in e?qb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Js=(e,t)=>{for(var n in t||(t={}))Gb.call(t,n)&&uc(e,n,t[n]);if(dc)for(var n of dc(t))Hb.call(t,n)&&uc(e,n,t[n]);return e},Vb=(e,t)=>Bb(e,Ub(t));function Yb(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:l,group:u,disabled:d,modifiers:c,sensors:f,target:p,type:x,plugins:g}=e,y=Js(Js({},Lf),e.transition),w=Hu(m=>new As(Vb(Js({},e),{transition:y,register:!1,handle:Vn(a),element:Vn(o),target:Vn(p)}),m)),h=qu(w,Kb);return Te(i,()=>w.id=i),hr(()=>{Ie(()=>{w.group=u,w.index=l})},[w,u,l]),Te(x,()=>w.type=x),Te(t,()=>w.accept=t,void 0,yt),Te(s,()=>s&&(w.data=s)),Te(l,()=>{var m;(m=w.manager)!=null&&m.dragOperation.status.idle&&y?.idle&&w.refreshShape()},ig),_i(a,m=>w.handle=m),_i(o,m=>w.element=m),_i(p,m=>w.target=m),Te(d,()=>w.disabled=d??!1,void 0,yt),Te(f,()=>w.sensors=f,void 0,yt),Te(n,()=>w.collisionDetector=n),Te(r,()=>w.collisionPriority=r),Te(g,()=>w.plugins=g,void 0,yt),Te(y,()=>w.transition=y,void 0,yt),Te(c,()=>w.modifiers=c,void 0,yt),Te(e.alignment,()=>w.alignment=e.alignment),{sortable:h,get isDragging(){return h.isDragging},get isDropping(){return h.isDropping},get isDragSource(){return h.isDragSource},get isDropTarget(){return h.isDropTarget},handleRef:k.useCallback(m=>{w.handle=m??void 0},[w]),ref:k.useCallback(m=>{var b,$;!m&&(b=w.element)!=null&&b.isConnected&&!(($=w.manager)!=null&&$.dragOperation.status.idle)||(w.element=m??void 0)},[w]),sourceRef:k.useCallback(m=>{var b,$;!m&&(b=w.source)!=null&&b.isConnected&&!(($=w.manager)!=null&&$.dragOperation.status.idle)||(w.source=m??void 0)},[w]),targetRef:k.useCallback(m=>{var b,$;!m&&(b=w.target)!=null&&b.isConnected&&!(($=w.manager)!=null&&$.dragOperation.status.idle)||(w.target=m??void 0)},[w])}}function Kb(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Yo="tile",Wf="gap",Xb=[Pu.configure({activatorElements:e=>[e.element]}),Du],Zb=e=>[...e,qa.configure({feedback:"clone"})];function Qb({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=Yb({id:e,index:t,type:Yo,accept:Yo,collisionDetector:Na,plugins:Zb});return v.jsx(v.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function Jb({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=Mg({id:e,type:Wf,accept:Yo,collisionDetector:Na,data:{after:t}});return v.jsx(v.Fragment,{children:n({ref:r,isDropTarget:i})})}const ex=en(v.jsx("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2m-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"})),tx=en(v.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"}));function nx({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,onInsertAfter:s,onSelect:o,onOpenMenu:a,children:l}){const{theme:u}=nt();return v.jsx(Qb,{id:Ye(e),index:t,children:({ref:d,handleRef:c,isDragSource:f})=>v.jsxs(Oe,{ref:d,onClick:o,onPointerDown:p=>{p.button===0&&o()},"aria-label":`Tile ${e.name}`,"aria-current":n,"data-tile-key":Ye(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",borderRadius:1,outline:n?`2px solid ${u.drillLink}`:"2px solid transparent",outlineOffset:2,...r&&{outlineColor:u.drillLink,boxShadow:`0 0 0 6px color-mix(in srgb, ${u.drillLink} 25%, transparent)`},transition:"outline-color 120ms, opacity 120ms, box-shadow 120ms","&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:"0 12px 32px rgba(0, 0, 0, 0.22)"},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${u.drillLink}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"&:hover":{outlineColor:n?u.drillLink:u.cardBorder,boxShadow:"0 2px 10px rgba(0, 0, 0, 0.10)"}},children:[l,v.jsx(Oe,{ref:c,className:"builder-affordance","aria-label":`Move ${qs(e)}`,sx:{position:"absolute",top:"2px",left:"2px",display:"grid",placeItems:"center",width:"22px",height:"22px",borderRadius:"4px",cursor:"grab",touchAction:"none",zIndex:2,color:u.tileTitle,bgcolor:u.tile,opacity:f||n?.9:0,transition:"opacity 120ms","&:hover":{opacity:1},"&:active":{cursor:"grabbing"},"&:focus-visible":{opacity:1,outline:`2px solid ${u.drillLink}`,outlineOffset:1}},children:v.jsx(ex,{sx:{fontSize:16}})}),v.jsx(Hi,{className:"builder-affordance",size:"small","aria-label":`Settings for ${qs(e)}`,onClick:p=>{p.stopPropagation(),a(p.currentTarget)},sx:{position:"absolute",top:"2px",right:"2px",width:22,height:22,zIndex:2,color:u.tileTitle,bgcolor:u.tile,opacity:n||i?.9:0,transition:"opacity 120ms","&:hover":{opacity:1,bgcolor:u.tile}},children:v.jsx(tx,{sx:{fontSize:16}})}),s&&v.jsx(Hi,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${qs(e)}`,onClick:p=>{p.stopPropagation(),s()},sx:{position:"absolute",bottom:"-18px",left:"50%",transform:"translateX(-50%)",width:20,height:20,zIndex:3,color:u.tileTitle,bgcolor:u.tile,border:u.cardBorder,opacity:0,transition:"opacity 120ms","&:hover, &:focus-visible":{opacity:1,bgcolor:u.tile}},children:v.jsx(ms,{sx:{fontSize:14}})})]})})}function rx({tile:e,heading:t,note:n}){const{theme:r}=nt();return v.jsxs(Mc,{sx:{minHeight:140},children:[v.jsx(sh,{title:t?.title??e.label??e.name,subtitle:t?t.subtitle:e.subtitle}),n&&v.jsx(ie,{variant:"body2",sx:{color:r.tileTitle,py:2},children:n}),v.jsxs(ie,{variant:"caption",sx:{display:"block",color:r.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function ix({after:e}){const{theme:t}=nt();return v.jsx(Jb,{id:Ef(e),after:e,children:({ref:n,isDropTarget:r})=>v.jsx(Oe,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.drillLink}`,bgcolor:r?`color-mix(in srgb, ${t.drillLink} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:"opacity 120ms, background-color 120ms"}})})}function sx({columns:e}){const{theme:t}=nt();return v.jsx(Oe,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${ih}px`},children:Array.from({length:e},(n,r)=>v.jsx(Oe,{sx:{borderLeft:`1px dashed ${t.drillLink}`,borderRight:r===e-1?`1px dashed ${t.drillLink}`:"none",opacity:.35}},r))})}const ox="Write markdown: # heading, **bold**, - list";function ax({tile:e,onChange:t}){return v.jsx(Mc,{sx:{minHeight:72},children:v.jsx(yf,{markdown:e.markdown,placeholder:ox,onCommit:t})})}var lx=Object.defineProperty,cx=Object.defineProperties,dx=Object.getOwnPropertyDescriptors,fc=Object.getOwnPropertySymbols,ux=Object.prototype.hasOwnProperty,fx=Object.prototype.propertyIsEnumerable,hc=(e,t,n)=>t in e?lx(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dn=(e,t)=>{for(var n in t||(t={}))ux.call(t,n)&&hc(e,n,t[n]);if(fc)for(var n of fc(t))fx.call(t,n)&&hc(e,n,t[n]);return e},Pn=(e,t)=>cx(e,dx(t));function hx(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Ei(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function eo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function px(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(h,m)=>h===m||h!==null&&typeof h=="object"&&"id"in h&&h.id===m;if(Array.isArray(e)){const h=e.findIndex(b=>l(b,s.id)),m=e.findIndex(b=>l(b,o.id));if(h===-1||m===-1){if(eo(s)){const b=s.initialIndex,$=s.index;return b===$||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,$)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const b=s.index;if(b!==h)return n(e,h,b)}return n(e,h,m)}const u=Object.entries(e);let d=-1,c,f=-1,p;for(const[h,m]of u)if(d===-1&&(d=m.findIndex(b=>l(b,s.id)),d!==-1&&(c=h)),f===-1&&(f=m.findIndex(b=>l(b,o.id)),f!==-1&&(p=h)),d!==-1&&f!==-1)break;if(d===-1&&eo(s)){const h=s.initialGroup==null?void 0:Ei(e,s.initialGroup),m=s.initialIndex,b=s.group==null?void 0:Ei(e,s.group),$=s.index;if(h==null||b==null||h===b&&m===$)return"preventDefault"in t&&t.preventDefault(),e;if(h===b)return Pn(Dn({},e),{[h]:n(e[h],m,$)});const D=e[h][m];return Pn(Dn({},e),{[h]:[...e[h].slice(0,m),...e[h].slice(m+1)],[b]:[...e[b].slice(0,$),D,...e[b].slice($)]})}if(!s.manager)return e;const{dragOperation:x}=s.manager,g=(i=(r=x.shape)==null?void 0:r.current.center)!=null?i:x.position.current;if(p==null){const h=Ei(e,o.id);if(h!=null){const m=o.shape&&g.y>o.shape.center.y?e[h].length:0;p=h,f=m}}if(c==null||p==null||c===p&&d===f){if(c!=null&&c===p&&d===f&&eo(s)){const h=s.group==null?void 0:Ei(e,s.group),m=s.group!=null&&h!==c,b=s.index!==d;if(m||b){const $=s.group==null?c:h;if($!=null){if(c===$)return Pn(Dn({},e),{[c]:n(e[c],d,s.index)});const D=e[c][d];return Pn(Dn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[$]:[...e[$].slice(0,s.index),D,...e[$].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return Pn(Dn({},e),{[c]:n(e[c],d,f)});const y=o.shape&&Math.round(g.y)>Math.round(o.shape.center.y)?1:0,w=e[c][d];return Pn(Dn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[p]:[...e[p].slice(0,f+y),w,...e[p].slice(f+y)]})}function mx(e,t){return px(e,t,hx)}function gx({tiles:e,commit:t,onLanded:n}){const[r,i]=k.useState(void 0),s=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:l=>{const{source:u,target:d}=l.operation;if(!u||!d)return;const c=s.current??e;let f;if(d.type===Wf){const{after:p}=d.data,x=c.findIndex(y=>Ye(y)===u.id);if(x<0||p===u.id)return;const g=c.filter((y,w)=>w!==x).findIndex(y=>Ye(y)===p)+1;f=bb(c,x,g)}else{const p=c.map(Ye),x=mx(p,l);if(x.every((y,w)=>y===p[w]))return;const g=new Map(c.map(y=>[Ye(y),y]));f=vb(x.map(y=>g.get(y)),e.map(y=>y.break??!1))}s.current=f,i(f)},onDragEnd:l=>{a(!1);const u=s.current;if(s.current=void 0,i(void 0),l.canceled||!u)return;t(u);const d=u.findIndex(c=>Ye(c)===l.operation.source?.id);d>=0&&n(d)}}}const vx=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,bx="This tile's view is declared on its source, so its chart is set in the model.";function pc({columns:e,colspan:t,onPick:n}){const{theme:r}=nt();return v.jsxs(ye,{direction:"row",sx:{gap:.5,alignItems:"center"},children:[v.jsx(ie,{variant:"caption",sx:{color:r.tileTitle,mr:.5},children:"Width"}),[["Full",1],["½",2],["⅓",3],["¼",4]].map(([i,s])=>{const o=jh(e,s),a=(t??1)===o;return v.jsx(Ee,{size:"small",variant:a?"contained":"outlined","aria-label":`Width ${i}`,"aria-pressed":a,onClick:()=>n(o),sx:{minWidth:40,px:1},children:i},i)})]})}function xx({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:i,removeBlocked:s,columns:o,onDrills:a,view:l}){const u=k.useId(),{theme:d}=nt(),{draft:c,patch:f,close:p,discard:x}=nl(t,e!==null,r,n),g=c!==void 0&&we(c)?c:void 0,y=g!==void 0&&g.declaration.kind!=="inherited",w=m=>f(b=>{we(b)&&m(b)}),h=t&&we(t)?t.chart:void 0;return v.jsx(Tc,{open:e!==null&&c!==void 0,anchorEl:e,onClose:p,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:c&&v.jsxs(ye,{sx:{gap:1.5},children:[v.jsx(ie,{variant:"overline",sx:{color:d.tileTitle,lineHeight:1.5},children:g?`${g.source} → ${g.name}`:`Text · ${c.name}`}),!g&&o>1&&v.jsx(pc,{columns:o,colspan:c.colspan,onPick:m=>f(b=>{b.colspan=m})}),g&&y&&v.jsxs(v.Fragment,{children:[v.jsx(Ho,{state:g.chart??"default",view:l,cellLabel:`${g.source} ${g.name}`,...g.chart==="custom"?{disabledReason:vx(g.chartLines)}:{},onChange:m=>w(b=>{const $=h;m===($??"default")?($===void 0?delete b.chart:b.chart=$,delete b.chartCarried):(b.chart=m,l?b.chartCarried=l.chart?[l.chart]:[]:delete b.chartCarried)})}),o>1&&v.jsx(pc,{columns:o,colspan:g.colspan,onPick:m=>w(b=>{b.colspan=m})})]}),g&&!y&&v.jsxs(v.Fragment,{children:[v.jsx(ie,{variant:"body2",sx:{color:d.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),v.jsx(Ho,{state:"default",view:l,cellLabel:`${g.source} ${g.name}`,disabledReason:bx,onChange:()=>{}})]}),g?.declaration.kind==="opaque"&&v.jsxs(ie,{variant:"body2",sx:{color:d.tileTitle},children:["Its body is ",g.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),v.jsx(ro,{}),v.jsxs(ye,{direction:"row",sx:{justifyContent:"space-between"},children:[y?v.jsx(Ee,{size:"small",onClick:()=>{p(),a()},children:"Drill-through…"}):v.jsx("span",{}),v.jsx(Ee,{color:"error",size:"small","aria-disabled":s!==void 0||void 0,"aria-describedby":s!==void 0?u:void 0,disableRipple:s!==void 0,sx:s!==void 0?{opacity:.5,cursor:"default"}:void 0,onClick:()=>{s===void 0&&(x(),i())},children:"Remove tile"})]}),s!==void 0&&v.jsx(ie,{id:u,variant:"caption",sx:{color:d.tileTitle},children:s})]})})}function yx({dirty:e,saving:t,canSave:n,save:r,onExit:i}){const[s,o]=k.useState("idle"),[a,l]=k.useState(!1),u=k.useRef(r);u.current=r;const d=k.useRef(i);d.current=i;const c=k.useRef(0),f=k.useCallback(async()=>{const p=++c.current;l(!1),o("saving");try{await u.current()}catch{c.current===p&&o("idle");return}c.current===p&&l(!0)},[]);return k.useEffect(()=>{if(s==="waiting"){if(t)return;e?f():(o("idle"),d.current())}else if(s==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[s,a,t,e,f]),{requestExit:k.useCallback(()=>{s==="idle"&&(e?o("asking"):d.current())},[s,e]),dialog:{open:s==="asking",canSave:n,onKeepEditing:()=>{s==="asking"&&o("idle")},onDiscard:()=>{s==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{s==="asking"&&(t?o("waiting"):f())}}}}function wx({editor:e,onSave:t,onExit:n,onDirtyChange:r,onSaveNoticeChange:i,onChange:s,extraDirty:o=!1,report:a,unit:l,prepare:u,shortcuts:d}){const[c,f]=k.useState(!1),[p,x]=k.useState(!1),[g,y]=k.useState(!1),[w,h]=k.useState(void 0),m=k.useRef(null),b=k.useRef(a);b.current=a;const $=e.dirty||o,D=(e.edited??e.dirty)||o;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{r?.(D)},[D,r]);const M=k.useRef(r);M.current=r,k.useEffect(()=>()=>M.current?.(!1),[]);const A=e.lastSave!==void 0&&!!t;k.useEffect(()=>{i?.(A)},[A,i]);const E=k.useRef(i);E.current=i,k.useEffect(()=>()=>E.current?.(!1),[]),k.useEffect(()=>{A||x(!1)},[A]);const T=k.useRef(l);T.current=l,k.useEffect(()=>{y(!1)},[e.document]);const F=k.useCallback(()=>{f(!0),y(!1);const L=Nt(),{structural:_}=e,N=e.pendingOpen??!1,H=b.current.size,j={before:T.current.count(e.saved),after:T.current.count(e.document)};return e.save().then(S=>{S.ok===!0?(h(j),b.current.saved({size:H,structural:_,fromOpen:N,durationMs:Nt()-L})):b.current.refused(S.reason)}).finally(()=>f(!1))},[e]),z=k.useRef(!1),q=k.useRef(!1);k.useEffect(()=>{!q.current||c||(q.current=!1,m.current?.focus())},[g,c]);const K=k.useCallback(()=>{if(!t||c||z.current||!e.canUndoSave)return;z.current=!0,f(!0);const L=Nt(),_=e.lastSave?.structural??!1,N=b.current.size;return e.undoSave().then(H=>{H.ok===!0?(q.current=!0,y(!0),b.current.undone({size:N,structural:_,fromOpen:!1,durationMs:Nt()-L})):b.current.undoRefused(H.reason)}).finally(()=>{z.current=!1,f(!1)})},[t,c,e]),X=k.useCallback(()=>{if(!(!t||!e.dirty||c))return F()},[t,e,c,F]),oe=k.useRef(X);oe.current=X;const ae=k.useCallback(()=>{const L=()=>oe.current();return u?u(L):L()},[u]),Q=yx({dirty:D,saving:c,canSave:!!t,save:ae,onExit:()=>n?.()});Ug(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:ae}:{},paused:Q.dialog.open||p}),[d,e,t,ae,Q.dialog.open,p]));const he=!!t&&!c&&e.canUndoSave,O=e.lastSave,B={...O?{lastSave:O}:{},unit:l.name,moved:w,canUndoSave:he,undone:g&&O===void 0,viewing:p,onView:x,onUndoSave:K},W={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:$,saving:c,saveButton:m,...t?{onSave:ae}:{},...n?{onExit:Q.requestExit}:{}};return{saving:c,save:ae,exitGuard:Q,undoSave:K,canUndoSave:he,lastSave:O,notice:B,toolbarProps:W}}function kx(e){const{splice:t,onSave:n,structural:r,clearsHistory:i,opensDirty:s=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,u]=k.useState(e.source),[d,c]=k.useState(void 0),[f,p]=k.useState(e.document),[x,g]=k.useState(s),[y,w]=k.useState(e.replaces),[h,m]=k.useState(!1),b=o.stack[o.index],$=k.useRef(o);$.current=o;const D=k.useRef(!1),[M,A]=k.useState(!1),E=L=>{D.current=L,A(L)},[T,F]=k.useState(void 0),z=k.useCallback(L=>{c(void 0),a(_=>{const N=structuredClone(_.stack[_.index]);if(L(N),JSON.stringify(N)===JSON.stringify(_.stack[_.index]))return _;const H=[..._.stack.slice(0,_.index+1),N].slice(-100);return{stack:H,index:H.length-1}})},[]),q=k.useCallback(()=>{c(void 0),a(L=>L.index>0?{...L,index:L.index-1}:L)},[]),K=k.useCallback(()=>{c(void 0),a(L=>L.index<L.stack.length-1?{...L,index:L.index+1}:L)},[]),X=k.useCallback(async(L,_)=>{try{return await t(L,_)}catch(N){return{ok:!1,reason:`Could not build the file: ${N instanceof Error?N.message:String(N)}`}}},[t]),oe=k.useCallback(async()=>{if(D.current)return{ok:!1,reason:"A save is still being written."};const L={source:l,saved:f,history:$.current,pendingOpen:x,replacing:y,unwritten:h},_=i?.(f,b)??!1,N=r?.(f,b)??!1;E(!0);try{const H=await X(l,b);if(Uo(H))return c(H.reason),{ok:!1,reason:H.reason};try{await n?.(H.source,{purpose:"save",document:b})}catch(S){const I=`Could not save: ${S instanceof Error?S.message:String(S)}`;return c(I),{ok:!1,reason:I}}u(H.source),p(b),g(!1),w(void 0),m(!1);const j=_?{stack:[b],index:0}:L.history;return a(S=>S===L.history?j:_?{stack:[S.stack[S.index]],index:0}:S),F(n?{before:L,after:j,lastSave:{before:y??l,after:H.source,structural:N,clearsHistory:_}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[b,X,n,l,f,x,y,h,i,r]),ae=k.useCallback(async()=>{if(D.current)return{ok:!1,reason:"A save is still being written."};if(!n||T===void 0||T.after!==$.current)return{ok:!1,reason:"There is no save to undo."};const{before:L}=T;E(!0);try{await n(L.replacing??L.source,{purpose:"undo",document:L.saved})}catch(_){const N=`Could not undo the save: ${_ instanceof Error?_.message:String(_)}`;return c(N),{ok:!1,reason:N}}finally{E(!1)}return u(L.source),p(L.saved),g(L.pendingOpen),w(L.replacing),m(L.unwritten||L.replacing!==void 0),a(_=>_===T.after?L.history:_),F(void 0),c(void 0),{ok:!0}},[n,T]),Q=k.useMemo(()=>h||JSON.stringify(b)!==JSON.stringify(f),[b,f,h]),he=k.useMemo(()=>r?.(f,b)??!1,[b,f,r]),O=k.useMemo(()=>i?.(f,b)??!1,[b,f,i]),B=T!==void 0&&T.after===o,W=k.useCallback(async()=>{const L=await X(l,b);return Uo(L)?{ok:!1,reason:L.reason}:{ok:!0,source:L.source}},[b,X,l]);return{document:b,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:Q||x,edited:Q,pendingOpen:x,...d===void 0?{}:{error:d},update:z,undo:q,redo:K,save:oe,preview:W,structural:he,clearsHistory:O,canUndoSave:B&&!M&&n!==void 0,...B?{lastSave:T.lastSave}:{},undoSave:ae}}const $x=(e,t)=>{const n=new Set(e.tiles.map(Go)),r=new Set(t.tiles.map(Go));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function Sx(e){const{conversion:t,modelPath:n,...r}=e,i=t?.from,s=t?.to,o=k.useCallback((a,l)=>Bv(i!==void 0&&a===i?s:a,l,{changeKind:!0,...n!==void 0?{modelPath:n}:{}}),[i,s,n]);return kx({...r,splice:o,structural:$x,opensDirty:t!==void 0})}function jx({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onSaveNoticeChange:s,renderTile:o,controls:a,givens:l,catalog:u,toolbar:d,onExit:c,dashboards:f,onEvent:p,conversion:x,savesTo:g="package",saveLabel:y,replaces:w,modelPath:h}){const m=Sx({source:e,document:t,...n?{onSave:n}:{},...x?{conversion:x}:{},...w!==void 0?{replaces:w}:{},...h!==void 0?{modelPath:h}:{}}),[b,$]=k.useState(void 0),[D,M]=k.useState(void 0),A=k.useRef(!1),E=k.useRef(m.document),T=m.document.kind==="notebook",F=T?1:m.document.columns??$c,z=k.useRef(null),{dragging:q,preview:K,onDragStart:X,onDragOver:oe,onDragEnd:ae}=gx({tiles:m.document.tiles,commit:C=>m.update(P=>{P.tiles=C}),onLanded:$}),[Q,he]=k.useState(void 0),[O,B]=k.useState(void 0),[W,L]=k.useState(!1),[_,N]=k.useState(void 0),H=C=>{N(C),L(!0)},[j,S]=k.useState(void 0),[I,Z]=k.useState(null),V=k.useMemo(()=>cb(m.document),[m.document]),se=k.useMemo(()=>new Set([...m.document.sources.map(C=>C.base),...m.document.tiles.filter(we).map(C=>C.source)]),[m.document]),Y=k.useMemo(()=>{const C=new Set((t.localGivens??[]).map(P=>P.name));return(l??[]).filter(P=>!C.has(P.name))},[t,l]),ve=k.useMemo(()=>Tg(m.document,Y),[m.document,Y]),J=k.useMemo(()=>new Map(m.document.sources.map(C=>[C.name,Ql(u,C.base)])),[u,m.document.sources]),be=k.useCallback(C=>J.get(C.source)??Ql(u,C.source),[J,u]),le=O===void 0?void 0:m.document.tiles[O.index],me=le&&we(le)?le:void 0,Ge=(()=>{if(!me||!u)return;const C=m.document.sources.find(U=>U.name===me.source)?.base??me.source,P=me.declaration.kind==="reference"?me.declaration.from:me.name;return u.sources.find(U=>U.name===C)?.views.find(U=>U.name===P)})(),te=(C,P)=>{const U=[];for(const ee of m.document.tiles){if(!we(ee))continue;const Ne=be(ee);if(!Ne)continue;const $e=new Map(Ne.map(Se=>[Se.name,Se.type]));for(const Se of ee.filters??[])Se.given===C&&(!$e.has(Se.field)||!qi(P,$e.get(Se.field)))&&U.push(`${Se.field} on ${ee.label??ee.name} (${m.document.sources.find(bt=>bt.name===ee.source)?.base??ee.source})`)}return U},R=k.useMemo(()=>ve.filter(C=>C.origin==="model"&&C.boundTiles===0),[ve]),G=k.useMemo(()=>({escape:()=>{!O&&!Q&&$(void 0)},nudge:C=>{if(q||b===void 0||T)return;const P=m.document.tiles[b];if(!P||we(P)&&P.declaration.kind==="inherited")return;const U=Ff(P.colspan??1,C,F);U!==(P.colspan??1)&&m.update(ee=>{ee.tiles[b].colspan=U})}}),[m,O,Q,b,F,T,q]);k.useEffect(()=>{const C=E.current;if(E.current=m.document,!A.current)return;A.current=!1;const P=Vg(C,m.document);P!==void 0&&(M(P),Array.from(z.current?.querySelectorAll("[data-tile-key]")??[]).find(U=>U.dataset.tileKey===P)?.scrollIntoView?.({block:"nearest",behavior:"smooth"}))},[m.document,z]),k.useEffect(()=>{if(D===void 0)return;const C=setTimeout(()=>M(void 0),1500);return()=>clearTimeout(C)},[D]);const ce=k.useMemo(()=>({...m,undo:()=>{A.current=!0,m.undo()},redo:()=>{A.current=!0,m.redo()}}),[m]),[pe,Fe]=k.useState(!1),It=k.useRef(void 0),Ke=k.useRef(void 0),tn=k.useMemo(()=>({setDirty:Fe,commitRef:It}),[]),ct=k.useCallback(C=>{if(!It.current)return C();if(It.current())return new Promise(P=>{Ke.current=()=>P(C())})},[]);k.useEffect(()=>{if(pe||!Ke.current)return;const C=Ke.current;Ke.current=void 0,C()},[pe,m.dirty]);const Dt=wx({editor:ce,extraDirty:pe,prepare:ct,unit:{name:"tile",count:C=>C.tiles.length},onSave:n,onExit:c,onDirtyChange:i,onSaveNoticeChange:s,onChange:r,shortcuts:G,report:{size:m.document.tiles.length,saved:({size:C,structural:P,durationMs:U,fromOpen:ee})=>p?.(T?{type:"notebook.saved",cells:C,structural:P,converted:ee,where:g,durationMs:U}:{type:"dashboard.saved",tiles:C,structural:P,where:g,durationMs:U}),refused:C=>p?.({type:T?"notebook.save_refused":"dashboard.save_refused",reason:C}),undone:({size:C,structural:P,durationMs:U})=>p?.(T?{type:"notebook.save_undone",cells:C,structural:P,where:g,durationMs:U}:{type:"dashboard.save_undone",tiles:C,structural:P,where:g,durationMs:U}),undoRefused:C=>p?.({type:T?"notebook.save_undo_refused":"dashboard.save_undo_refused",reason:C})}}),nn=C=>{L(!1),m.update(P=>{let U=P.sources.find($e=>$e.base===C.base);if(!U){const $e=new Set(P.sources.map(bt=>bt.name));let Se=`${C.base}_tiles`;for(let bt=2;$e.has(Se);bt++)Se=`${C.base}_tiles_${bt}`;U={name:Se,base:C.base},P.sources.push(U)}const ee=new Set(P.tiles.filter(we).filter($e=>$e.source===U.name).map($e=>$e.name));let Ne=`${C.view}_tile`;for(let $e=2;ee.has(Ne);$e++)Ne=`${C.view}_tile_${$e}`;P.tiles.splice(_??P.tiles.length,0,{name:Ne,source:U.name,declaration:{kind:"reference",from:C.view},...T?{}:{colspan:C.colspan},...C.label?{label:C.label}:{},...C.chart?{chart:C.chart}:{},...C.chartCarried?{chartCarried:C.chartCarried}:{}})}),$(_??m.document.tiles.length)},Bt=()=>{L(!1),m.update(C=>{const P=new Set(C.tiles.filter(Ue).map(ee=>ee.name));let U=1;for(;P.has(`text_${U}`);)U++;C.tiles.splice(_??C.tiles.length,0,{kind:"text",name:`text_${U}`,markdown:"",...T?{}:{colspan:F}})}),$(_??m.document.tiles.length)},Pt=(C,P)=>m.update(U=>{const ee=U.tiles.find(Ne=>Ye(Ne)===C);ee&&P(ee)}),rn=(C,P)=>{if(C.declaration.kind==="inherited")return;const U=Ye(C),ee=Ne=>$e=>Pt(U,Se=>{we(Se)&&($e===""?delete Se[Ne]:Se[Ne]=$e)});return{title:v.jsx(Hs,{value:C.label??"",placeholder:P,ariaLabel:"Tile title",onCommit:ee("label")}),subtitle:v.jsx(Hs,{value:C.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:ee("subtitle")})}},dt=C=>{B(void 0),$(void 0),m.update(P=>{P.tiles.splice(C,1)})},pr=(C,P,U)=>{he(void 0),m.update(ee=>{U&&Rg(ee,U),Ng(ee,C,P)})},Lt=C=>{he(void 0),m.update(P=>zg(P,C))},sn=K??m.document.tiles,on=m.document.tiles.length===0,mr=q?xb(sn,F):sn.map(Of);return v.jsx(nf.Provider,{value:tn,children:v.jsxs(ye,{sx:{gap:0},children:[v.jsx(Hg,{...Dt.toolbarProps,...d?{actions:d}:{},...u?{onAddTile:()=>H()}:{},onSettings:Z,savesTo:g,...y?{saveLabel:y}:{}}),v.jsxs(ye,{sx:{gap:2,px:"4px",pb:"4px"},children:[m.pendingOpen&&v.jsx(xt,{severity:"info",children:"This notebook is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view; Undo save puts it back."}),v.jsx(sb,{...Dt.notice}),v.jsxs(Oe,{children:[v.jsx(ie,{variant:"h5",sx:{fontWeight:600},children:v.jsx(Hs,{value:m.document.title,placeholder:T?"Untitled notebook":"Untitled dashboard",ariaLabel:T?"Notebook title":"Dashboard title",onCommit:C=>m.update(P=>{P.title=C})})}),v.jsx(yf,{variant:"caption",markdown:m.document.description??"",placeholder:"Add a description",onCommit:C=>m.update(P=>{C.trim()===""?delete P.description:P.description=C})})]}),on?v.jsxs(ye,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[v.jsxs(ie,{variant:"body2",children:["This ",T?"notebook":"dashboard"," is not served until it has a tile."]}),u&&v.jsx(Ee,{size:"small",variant:"contained",onClick:()=>H(),children:"Add tile"})]}):v.jsx(gb,{controls:ve,tileCount:m.document.tiles.length,unknownFieldsOf:te,onEdit:C=>he({control:C}),onAdd:()=>he({}),onRemove:Lt,children:a}),m.error&&v.jsx(xt,{severity:"warning",children:m.error}),v.jsx(hg,{sensors:Xb,onDragStart:X,onDragOver:oe,onDragEnd:ae,children:v.jsxs(Oe,{ref:z,sx:{position:"relative"},children:[!T&&q&&v.jsx(sx,{columns:F}),v.jsx(qf,{tiles:mr,columns:F,keyOf:C=>C.kind==="gap"?Ef(C.after):Ye(C.tile),renderTile:C=>{if(C.kind==="gap")return v.jsx(ix,{after:C.after});const{tile:P,index:U}=C;return v.jsx(nx,{tile:P,index:U,selected:U===b,flash:Ye(P)===D,menuOpen:O?.index===U,...T&&u?{onInsertAfter:()=>H(U+1)}:{},onSelect:()=>$(U),onOpenMenu:ee=>{$(U),B({anchor:ee,index:U})},children:Ue(P)?v.jsx(ax,{tile:P,onChange:ee=>Pt(Ye(P),Ne=>{Ue(Ne)&&(Ne.markdown=ee)})}):o&&!m.pendingOpen?o(P,rn(P,Sc(`${P.source} -> ${P.name}`))):v.jsx(rx,{tile:P,heading:rn(P,P.name),...m.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),T&&u&&!on&&v.jsx(Ee,{size:"small",startIcon:v.jsx(ms,{}),"aria-label":"Add tile at the end",onClick:()=>H(),sx:{alignSelf:"center"},children:"Add tile"}),v.jsx(lb,{open:Q!==void 0,document:m.document,...Q?.control?{control:Q.control}:{},available:R,...u?{fieldsFor:be}:{},onClose:()=>he(void 0),onApply:pr,onRemove:Lt}),v.jsx(xx,{anchor:O?.anchor??null,tile:O===void 0?void 0:m.document.tiles[O.index],onClose:()=>B(void 0),onCommit:C=>{const P=O?.index;P!==void 0&&m.update(U=>{U.tiles[P]=C})},onRemove:()=>{O!==void 0&&dt(O.index)},...m.document.tiles.length===1&&m.saved.tiles.length>0?{removeBlocked:"A saved dashboard needs at least one tile."}:{},columns:F,view:Ge,onDrills:()=>{S(me?.source)}}),v.jsx(ob,{open:j!==void 0,document:m.document,source:m.document.sources.find(C=>C.name===j),givenNames:ve.map(C=>C.name),dashboards:f??[],onClose:()=>S(void 0),onApply:C=>m.update(P=>{const U=[...(P.drills??[]).filter(ee=>ee.source!==j),...C];U.length===0?delete P.drills:P.drills=U})}),v.jsx(hb,{anchor:I,settings:V,catalog:u,inUse:se,onClose:()=>Z(null),onCommit:C=>m.update(P=>{C.kind===void 0?delete P.kind:P.kind=C.kind,C.columns===void 0?delete P.columns:P.columns=C.columns,C.autorun===void 0?delete P.autorun:P.autorun=C.autorun,P.imports=C.imports})}),v.jsx(eb,{open:W,document:m.document,catalog:u,columns:F,onClose:()=>L(!1),onAdd:nn,onAddText:Bt}),v.jsx(Bf,{...Dt.exitGuard.dialog})]})]})})}function Cx(e,t){const n=new Set;for(const s of e.tiles)for(const o of we(s)?s.filters??[]:[])n.add(o.given);const r=[],i=new Set;for(const s of e.localGivens??[])n.has(s.name)&&(i.add(s.name),r.push(Ox(s)));for(const s of t)s.name===void 0||i.has(s.name)||!n.has(s.name)||(i.add(s.name),r.push(s));return r}function Ox(e){return{name:e.name,type:e.type,default:e.default,...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function Ex(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function mc(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function Mx(e,t,n,r=new Map,i){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:i&&[...i]};const s=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(g=>[g.name,g.type])),l=e.sources.find(g=>g.name===s)?.scopedBy??[],u=new Set([...l,...i??[]].filter(g=>n.has(g))),d=new Set([...l,...i??[]]),c=[];for(const g of t.filters??[]){const y=`where: ${Qo(g.field)} ${g.op??"~"}`;if(n.has(g.given)){u.add(g.given),d.add(g.given),c.push(`${y} $${g.given}`);continue}if(!a.has(g.given))continue;d.add(g.given);const w=wh(r.get(g.given),a.get(g.given));w!==void 0&&c.push(`${y} ${w}`)}const f=c.join(", "),p=t.chart,x=p==="none"||Ms(p)?Yn(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
146
+ `):p==="default"&&Ex(t.declaration)?Yn("none"):void 0;return{...x?{annotation:x}:{},expression:`${s} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(u),reads:i||d.size>0?Array.from(d):void 0}}const Tx=e=>e.ok===!1,yr=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},Ax=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],Ix=/^[A-Za-z_][A-Za-z0-9_]*$/,Dx="file:///publisher-notebook-builder/notebook.malloy",Mi=e=>e.replace(/\r\n?/g,`
147
+ `);async function Px(e){const t=(O,B)=>({ok:!1,refused:`Line ${O+1}: ${B}`,line:O+1}),n=/\r(?!\n)/.exec(e);if(n)return t(e.slice(0,n.index).split(`
148
+ `).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,i;try{r=await Ts(e,Dx),i=await Zo()}catch(O){return t(0,`Malloy could not read this notebook: ${O}`)}const s=r.problems.find(O=>O.code==="syntax-error");if(s)return t(s.at?.range?.start?.line??0,`Malloy could not parse this notebook (${s.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,l=a?.tokenSource?.vocabulary,u=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!u||typeof l?.getSymbolicName!="function"||u.length===0&&e.trim()!=="")return{ok:!1,refused:"This build of Malloy does not expose a parse tree and token stream the notebook builder can read, so editing is off."};const d=O=>l.getSymbolicName(O.type),c=O=>i.routeOf({value:O.trimStart()}),f=O=>i.payloadOf({value:O}),p=O=>O==="markdown"||O==='"'||O==="text",x=O=>Mi(f(O)).replace(/\n$/,""),g=(O,B)=>{const W=f(O).trim(),L=c(O)!=='"'&&Ix.test(W)?"":W;return Mi([L&&`${L}
149
+ `,...B].join("")).replace(/\n$/,"")},y=new Za(e),w=Ja(y,a),h=O=>e.slice(y.utf16(O.startIndex),y.utf16(O.stopIndex+1)),m=O=>{const B=O.start?.startIndex,W=O.stop?.stopIndex,L=y.span(O);if(B===void 0||W===void 0||!L)return;let _=L.end;for(;_>L.start&&(e[_-1]===`
150
+ `||e[_-1]==="\r");)_--;return{startCp:B,stopCp:W,...L,startLine:y.line(L.start),endLine:y.line(Math.max(L.start,_-1))}},b=O=>{let B=0,W=u.length;for(;B<W;){const L=B+W>>1;u[L].startIndex<O?B=L+1:W=L}return B},$=(O,B)=>{const W=[],L=[],_={lines:[],insertAt:y.utf16(O)};let N=-2;for(let H=b(O);H<u.length;H++){const j=u[H];if(j.startIndex>B)break;if(j.channel!==0)continue;const S=d(j);if(S!=="ANNOTATION"&&S!=="BLOCK_ANNOTATION_BEGIN"){_.insertAt=y.lineStarts[y.line(y.utf16(j.startIndex))];break}const I=Mi(h(j)),Z=[];if(S==="BLOCK_ANNOTATION_BEGIN"){for(;d(u[H+1]??j)==="BLOCK_ANNOTATION_TEXT";)Z.push(h(u[++H]));d(u[H+1]??j)==="BLOCK_ANNOTATION_END"&&H++}if(p(c(I))){const V=y.utf16(j.startIndex),se=y.lineStarts[y.line(V)],Y=/^[ \t]*$/.test(e.slice(se,V));L.push({start:Y?se:V,end:y.utf16(u[H].stopIndex+1)})}if(S==="ANNOTATION"){const V=I.replace(/\n$/,"");if(Zt(V)){const se=y.utf16(j.startIndex),Y=y.lineStarts[y.line(se)];_.lines.push({span:{start:/^[ \t]*$/.test(e.slice(Y,se))?Y:se,end:y.utf16(j.stopIndex+1)},text:V})}else ei(V)&&_.unmodelled===void 0&&(_.unmodelled=V.trim())}if(c(I)!=="markdown")N=-2;else if(S==="BLOCK_ANNOTATION_BEGIN")W.push(g(I,Z)),N=-2;else{const V=x(I);j.line===N+1?W[W.length-1]+=`
151
+ ${V}`:W.push(V),N=j.line}}return{markdown:W.length>0?W.join(`
152
+
153
+ `):void 0,prose:L,chart:_}},D=[],M=[],A=(O,B,W="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(O,`${B}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${W}`);for(let O=0;O<(o.childCount??0);O++){const B=o.getChild(O);if(!ui(B)){const j=B?.symbol,S=j?d(j):void 0;if(j&&S==="EOF")continue;if(j&&S==="SEMI"){D.push([j.startIndex,j.stopIndex]);continue}return A((j?.line??1)-1,"a token outside any statement")}const W=m(B);if(!W)return A(0,"a statement with no readable range");const L=Ax.find(([j])=>yr(B,j)!==void 0);if(!L&&yr(B,"ignoredObjectAnnotations"))return A(W.startLine,"a # tag that annotates no statement","move the tag directly above its run:, or write trailing prose as a `##(markdown)` note.");if(!L){const j=e.slice(W.start,W.end).split(`
154
+ `)[0];return A(W.startLine,`\`${j.trim()}\` is a statement the notebook reader does not recognize`)}D.push([W.startCp,W.stopCp]);const[_,N]=L;if(N!=="notes"){const{markdown:j,prose:S,chart:I}=$(W.startCp,W.stopCp);M.push({kind:"statement",run:N==="run",...j!==void 0&&{markdown:j},prose:S,chart:I,startLine:W.startLine,endLine:W.endLine});continue}const H=yr(B,_);for(const j of yr(H,"docAnnotation")??[]){const S=m(j);if(!S)return A(W.startLine,"a note with no readable range");const I=yr(j,"docBlockAnnotation")!==void 0,Z=u.filter(be=>be.startIndex>=S.startCp&&be.stopIndex<=S.stopCp),V=Z.filter(be=>d(be)==="BLOCK_ANNOTATION_TEXT"),se=V[V.length-1]??Z[0],Y=Mi(I&&se?e.slice(S.start,y.utf16(se.stopIndex+1)).replace(/\r?\n$/,""):e.slice(S.start,S.end)),ve=c(Y),J=p(ve)?I?g(Y.split(`
155
+ `,1)[0],V.map(h)):x(Y):void 0;M.push({kind:"note",note:{text:Y,route:ve,...J!==void 0&&{body:J},block:I,startLine:S.startLine,endLine:S.endLine}})}}for(const O of u){if(d(O)!=="BLOCK_ANNOTATION_END")continue;const B=h(O).trimStart().replace(/^\|#{1,2}/,"").trim();if(B)return t(O.line-1,`the text after a block's closer (\`${B}\`) is not part of any cell, so the notebook cannot be edited here. Fix: put it on its own line, or inside the block.`)}let E=0;for(const O of u){if(O.channel!==0||d(O)==="EOF")continue;for(;E<D.length&&D[E][1]<O.startIndex;)E++;const[B,W]=D[E]??[1/0,-1/0];if(O.startIndex<B||O.stopIndex>W)return A(O.line-1,"a token outside any statement")}const T=M.findIndex(O=>O.kind==="note"&&Ch(O.note.text));if(T<0)return t(0,"this file has no ## artifact note, so it is not a notebook the builder can edit. Fix: add `## artifact { kind=notebook }` after the ##! line.");const F=M.findIndex((O,B)=>B<T&&O.kind==="statement");if(F>=0)return t(M[F].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let O=1;O<M.length;O++){const B=M[O-1],W=M[O],L=B.kind==="note"?B.note.endLine:B.endLine,_=W.kind==="note"?W.note.startLine:W.startLine;if(_<=L)return A(_,"a line holding two statements or notes","put each statement and note on its own line.")}const z=O=>y.lineStarts[O+1]??e.length,q=[];let K=-1,X=!0,oe;M.forEach((O,B)=>{if(O.kind==="statement"){X=!1,oe=void 0,q.push({cell:{kind:O.run?"query":"definition",...O.markdown!==void 0&&{markdown:O.markdown},...O.prose.length>0&&{prose:O.prose},...O.run&&{chart:O.chart},id:""},startLine:O.startLine,endLine:O.endLine});return}const{note:W}=O;if(!(B>T&&W.body!==void 0)){X&&(K=W.endLine),oe=void 0;return}if(X=!1,!W.block&&oe&&oe.endLine+1===W.startLine){oe.cell.markdown+=`
156
+ ${W.body}`,oe.endLine=W.endLine;return}const L={cell:{kind:"markdown",markdown:W.body,id:""},startLine:W.startLine,endLine:W.endLine};q.push(L),oe=W.block?void 0:L});const ae={start:0,end:z(K)};let Q=K;const he=q.map(({cell:O,startLine:B,endLine:W},L)=>{let _=B;for(;_-1>Q&&w.lines.has(_-1);)_--;return Q=W,{...O,span:{start:y.lineStarts[_],end:z(W)},id:String(L)}});for(const O of[ae,...he.map(B=>B.span)]){const B=w.all.find(W=>W.start<O.start&&W.end>O.start||W.start<O.end&&W.end>O.end);if(B)return A(y.line(B.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:ae,cells:he}}}const Lx=e=>e.ok===!1,Nx=/^[A-Za-z_][A-Za-z0-9_]*$/,gc=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,vc=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function to(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const i=e.indexOf(`
157
+ `,n),s=i<0?e.length:i;t+=" ".repeat(s-n),n=s}else if(r==="/*"){const i=e.indexOf("*/",n+2),s=i<0?e.length:i+2;t+=e.slice(n,s).replace(/[^\n]/g," "),n=s}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const i=e[n];let s=n+1;for(;s<e.length&&e[s]!==i;)s+=e[s]==="\\"?2:1;const o=Math.min(s,e.length);t+=i+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=i),n=o+1}else t+=e[n],n++}return t}function bc(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const i=e[r];i==="{"||i==="("||i==="["?n++:i==="}"||i===")"||i==="]"?n--:n===0&&i==="-"&&e[r+1]===">"&&t.push(r)}return t}function xc(e,t,n){let r=e;for(const i of[...n].sort((s,o)=>o.start-s.start))r=r.slice(0,i.start-t)+r.slice(i.end-t);return r}function yc(e,t){const n=t.split(`
158
+ `).map(r=>r.startsWith("|##")?` ${r}`:r).join(`
159
+ `);return`##|(markdown) ${e}
160
+ ${n===""?"":`${n}
161
+ `}|##
162
+ `}function Rx(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function zx(e){const t=(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),n=t.length>40?t.lastIndexOf("_",40):t.length,r=t.slice(0,n>0?n:40);return/^[a-z]/.test(r)&&Xo(r)?r:void 0}async function Wx(e){const t=await Px(e);if(Tx(t))return{ok:!1,refused:t.refused,line:t.line};const{header:n,cells:r}=t.source,i=(j,S)=>({ok:!1,refused:`Line ${j+1}: ${S}`,line:j+1}),s=e.slice(n.start,n.end).split(`
163
+ `),o=vs(s);if(o&&!Dc(o.text))return i(o.from,Pc);if(!o||el(o.text))return i(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const a=(await Ts(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,l=a?.tokenSource?.vocabulary,u=a?.getTokens?.()??[];if(typeof l?.getSymbolicName!="function")return i(0,"Malloy's token stream is not available.");const d=await Zo(),{parseAnnotation:c}=await Ac(),f=j=>l.getSymbolicName(j.type),p=new Za(e),x=Ja(p,a),g=j=>e.slice(p.utf16(j.startIndex),p.utf16(j.stopIndex+1)),y=j=>d.routeOf({value:j.trimStart()}),w=j=>d.payloadOf({value:j}),h=j=>j.replace(/\r\n?/g,`
164
+ `),m=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),b=j=>{let S=j;for(let I=2;m.has(S);I++)S=`${j}_${I}`;return m.add(S),S},$=j=>{const S=u.filter(J=>J.channel===0&&p.utf16(J.startIndex)>=j.span.start&&p.utf16(J.stopIndex+1)<=j.span.end),I=[],Z=[],V=[];let se;for(let J=0;J<S.length;J++){const be=f(S[J]);if(be!=="ANNOTATION"&&be!=="BLOCK_ANNOTATION_BEGIN"){se=S[J];break}let le=J;const me=[];if(be==="BLOCK_ANNOTATION_BEGIN"){for(;f(S[le+1]??S[J])==="BLOCK_ANNOTATION_TEXT";)me.push(g(S[++le]));f(S[le+1]??S[J])==="BLOCK_ANNOTATION_END"&&le++}const Ge=h(g(S[J])),te=y(Ge),R=p.utf16(S[J].startIndex),G=p.lineStarts[p.line(R)],ce={start:/^[ \t]*$/.test(e.slice(G,R))?G:R,end:p.utf16(S[le].stopIndex+1)};te==="markdown"?I.push(ce):te==='"'&&(Z.push(ce),V.push(be==="ANNOTATION"?h(w(Ge)).replace(/\n$/,"").trim():[h(w(Ge.split(`
165
+ `,1)[0])),...me.map(h)].map(pe=>pe.trim()).filter(Boolean).join(" "))),J=le}if(!se)return;const Y=p.utf16(se.startIndex),ve=e.slice(j.span.start,j.span.end);return{cell:j,above:xc(e.slice(j.span.start,Y),j.span.start,(j.kind==="query"?[...I,...Z]:I).filter(J=>J.end<=Y)),statement:e.slice(Y,j.span.end).trimEnd(),kept:xc(ve,j.span.start,I),...j.kind==="query"&&V.length>0&&{caption:V.join(" ")},line:p.line(Y)}},D=new Map,M=new Map;for(const[j,S]of r.entries()){if(S.kind==="markdown")continue;const I=$(S);if(!I)return i(p.line(S.span.start),"a cell with no statement the converter can place.");M.set(j,I);const Z=gc.exec(I.statement);S.kind==="definition"&&Z&&D.set(Z[1],{expression:I.statement.slice(Z[0].length).trim(),cell:j})}const A=j=>{const S=/^run\s*:\s*/.exec(j.statement);if(!S)return i(j.line,"a run that is not `run: <query>`.");let I=j.statement.slice(S[0].length).trim();const Z=[];for(let J=0;J<10;J++){const be=to(I),le=/^[A-Za-z_][A-Za-z0-9_]*/.exec(be)?.[0],me=le?D.get(le):void 0;if(!le||!me)break;const Ge=I.slice(le.length).trim(),te=be.slice(le.length).trim();if(te!==""&&!te.startsWith("->")&&!te.startsWith("+"))break;if(te.startsWith("+")&&bc(to(me.expression)).length!==1)return i(j.line,`\`${le} + { … }\` refines a query with more than one stage, which cannot become one view.`);Z.push(le);const R=/(\/\/|--)[^\n]*$/.test(me.expression)?`
166
+ `:" ";I=`${me.expression}${Ge===""?"":`${R}${Ge}`}`}const V=to(I);if(D.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(V)?.[0]??""))return i(j.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const se=bc(V);if(se.length===0)return i(j.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const Y=I.slice(0,se[0]).trim();if(/\bextend\b/.test(V.slice(0,se[0])))return i(j.line,"this run extends its source inline before `->`, so it cannot become a tile. Fix: declare the extension with a `source:` statement and run that.");if(!Nx.test(Y)&&!/^`[^`]+`$/.test(Y))return i(j.line,"the source of this run is not a name, so it cannot become a tile. Fix: name it with a `source:` statement and run that.");const ve=I.slice(se[0]+2).trim();return ve===""?i(j.line,"this run has nothing after `->`."):{source:Y,body:ve,used:Z}},E=new Map,T=[],F=new Set,z=new Map;let q=0,K=0;const X=new Map;for(const j of M.values()){if(j.cell.kind!=="query")continue;const S=A(j);if("ok"in S)return S;for(const I of S.used)X.set(I,(X.get(I)??0)+1)}const oe=j=>X.get(j)===1&&(e.match(new RegExp(`\\b${j}\\b`,"g"))??[]).length===2,ae=new Map;for(const[j,S]of r.entries()){if(S.kind==="markdown"){const te=b(`text_${++q}`);T.push(`${te} { kind=text }`);const R=x.all.filter(G=>G.start>=S.span.start&&G.end<=S.span.end).map(G=>`${e.slice(G.start,G.end)}
167
+ `).join("");z.set(j,R+yc(te,S.markdown??""));continue}const I=M.get(j);let Z="";if(S.markdown!==void 0){const te=b(`text_${++q}`);T.push(`${te} { kind=text }`),Z=`${yc(te,S.markdown)}
168
+ `}if(S.kind==="definition"){const te=gc.exec(I.statement)?.[1];if(te&&oe(te)){F.add(j),ae.set(te,I.above.split(`
169
+ `).filter(R=>R.trim()!=="")),Z&&z.set(j,Z.replace(/\n$/,""));continue}z.set(j,`${Z}${I.kept}`);continue}const V=A(I),se=V.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let Y=E.get(V.source);Y||(Y={name:b(`${se}_tiles`),base:V.source,views:[]},E.set(V.source,Y));const ve=[...V.used.flatMap(te=>ae.get(te)??[]),...I.above.split(`
170
+ `)].filter(te=>te.trim()!==""),J=ve.filter(te=>/^\s*#(?!["(|])/.test(te)),be=J.length>0?uf(c,J).tag:void 0,le=b(zx(be?.text("label")??I.caption)??`tile_${K+1}`);K++,T.push(`"${Y.name} -> ${le}"`);const me=ve.map(Rx);if(I.caption!==void 0){const te=un("caption",I.caption)===void 0;te&&!be?.has("label")?me.push(` # label=${vc(I.caption)}`):te&&!be?.has("subtitle")?me.push(` # subtitle=${vc(I.caption)}`):me.push(` #" ${I.caption}`)}const Ge=V.body.split(`
171
+ `).map((te,R)=>R===0||te.trim()===""?te:` ${te}`).join(`
172
+ `);Y.views.push([...me,` view: ${le} is ${Ge}`].join(`
173
+ `)),F.add(j),Z&&z.set(j,Z.replace(/\n$/,""))}const Q=(()=>{let j=0;const S=o.text;for(let I=S.indexOf("{");I<S.length;I++)if(S[I]==='"')for(I++;I<S.length&&S[I]!=='"';I++)S[I]==="\\"&&I++;else if(S[I]==="{")j++;else if(S[I]==="}"&&--j===0)return I;return-1})();if(Q<0)return i(o.from,"the `## artifact { … }` tag never closes.");const he=T.length===0?`
174
+ tiles=[]
175
+ `:`
176
+ tiles=[
177
+ ${T.map(j=>` ${j}`).join(`,
178
+ `)}
179
+ ]
180
+ `,O=`${o.text.slice(0,Q).trimEnd().replace(/^##(?!\|)/,"##|")}${he}${o.text.slice(Q)}`;s.splice(o.from,o.block?o.to-o.from:1,...(o.block?O:`${O}
181
+ |##`).split(`
182
+ `));const B=j=>{const S=j.text.split(`
183
+ `),I=S.pop(),Z=[];let V=0;for(const se of S){const Y=j.at[V]??-1,ve=x.all.some(J=>Y>=J.start&&Y<J.end);(se.trim()!==""||Z.at(-1)?.trim()!==""||ve)&&Z.push(se),V+=se.length+1}return Z.map(se=>`${se}
184
+ `).join("")+I},W={text:"",at:[]},L=(j,S)=>{W.text+=e.slice(j,S);for(let I=j;I<S;I++)W.at.push(I)};let _=s.join(`
185
+ `),N=n.end;for(const[j,S]of r.entries()){L(N,S.span.start),N=S.span.end;const I=z.get(j);I!==void 0&&(_+=B(W)+(I.endsWith(`
186
+ `)?I:`${I}
187
+ `),W.text="",W.at=[])}L(N,e.length),_=`${_.trimEnd()}
188
+ `+(W.text.trim()===""?"":B(W)),_=`${_.trimEnd()}
189
+ `;const H=[...E.values()].map(j=>`source: ${j.name} is ${j.base} extend {
190
+ ${j.views.join(`
191
+
192
+ `)}
193
+ }
194
+ `);return H.length>0&&(_+=`
195
+ ${H.join(`
196
+ `)}`),e.includes(`\r
197
+ `)&&(_=_.replace(/\r?\n/g,`\r
198
+ `)),{ok:!0,text:_,tiles:T.length}}const no=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function _x(e,t){const n=await us(e,t);if(!cs(n))return{ok:!0,document:n.document};if(!n.legacyNotebook)return{ok:!1,reason:no(n.reason,n.line)};const r=await Wx(e);if(Lx(r))return{ok:!1,reason:no(r.refused,r.line)};const i=await us(r.text,t);return cs(i)?{ok:!1,reason:`The converted notebook cannot be opened: ${no(i.reason,i.line)}`}:{ok:!0,document:i.document,conversion:{from:e,to:r.text}}}const wc="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` notebook under notebooks/ to edit it here.",kc="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Fx(e){const{onExit:t,onEvent:n,onDirtyChange:r,kind:i="dashboard",path:s}=e,o=i==="notebook",{environmentName:a,packageName:l,versionId:u,namesBoth:d}=Uf(e),c="resourceUri"in e?e.dashboard:e.dashboardName,f=o?"notebook":"dashboard",p=o?"notebook.open_refused":"dashboard.open_refused",{apiClients:x,mutable:g,isLoadingStatus:y}=jc(),w=Gf(),h=k.useRef(Nt()),m=k.useRef(n);m.current=n;const b=k.useRef(r);b.current=r;const $=Hf()?.documentStorage,D=o&&/\.malloynb$/i.test(c),M=s??`${i}s/${c}.malloy`,A=Ti({queryKey:["dashboard-editor-model",a,l,M,u,o],queryFn:()=>x.models.getModel(a,l,M,u,o?!0:void 0),enabled:d&&!D}),E=A.data?.data?.sourceText,[T,F]=k.useState(void 0),[z,q]=k.useState(void 0),[K,X]=k.useState($===void 0),[oe,ae]=k.useState(!1),[Q,he]=k.useState(void 0);k.useEffect(()=>{if(!$)return;let xe=!1;return he(void 0),(async()=>{try{const qe=Vf(await $.listWorkspaces(!1));if(xe)return;if(F(qe),qe!==void 0&&(!o||qe.authoritative)){const cn=await $.getDocument(ol(i,qe.name,a,l,M)).catch(Be=>{if(!al(Be))throw Be});if(xe)return;q(cn),ae(cn!==void 0)}}catch(qe){if(xe)return;he(ll(qe))}xe||X(!0)})(),()=>{xe=!0}},[$,i,o,a,l,M]);const O=T?.authoritative===!0,B=O&&Q!==void 0,[W,L]=k.useState(void 0),_=(O||W===!0)&&z!==void 0,[N,H]=k.useState(void 0),[j,S]=k.useState(D?wc:void 0),I=k.useRef(void 0),Z=k.useRef(void 0),[V,se]=k.useState(void 0),Y=A.dataUpdatedAt,ve=k.useRef(Y);ve.current=Y;const J=V!==void 0&&V.onFetch===Y?V.text:E,be=k.useRef(J);be.current=J;const le=_?z:J,[me,Ge]=k.useState(!1),[te,R]=k.useState(!1),[G,ce]=k.useState(void 0),[pe,Fe]=k.useState(void 0),It=le!==void 0&&le!==pe,Ke=N?.source,tn=It&&(me||te)&&Ke!==void 0&&le!==G,ct=tn?Ke:It?le:Ke??le,Dt=tn?le:void 0,nn=k.useRef(Ke);nn.current=Ke;const Bt=k.useRef(le);Bt.current=le;const Pt=k.useRef("package");Pt.current=_?O?"record":"draft":"package",k.useEffect(()=>{if(ct===void 0||!K||B||ct===nn.current)return;let xe=!1;const qe=be.current,cn=Bt.current;return _x(ct,M).then(Be=>{if(!xe){if(Be.ok===!1){S(Be.reason),m.current?.({type:p,reason:Be.reason});return}S(void 0),I.current=void 0,Z.current=qe,se(void 0),ce(void 0),Fe(cn),H(St=>({source:ct,document:Be.document,...Be.conversion?{conversion:Be.conversion}:{},...qe!==void 0?{packageText:qe}:{},generation:(St?.generation??0)+1})),m.current?.(o||Be.document.kind==="notebook"?{type:"notebook.opened",from:Pt.current==="package"?"package":"record",cells:Be.document.tiles.length,durationMs:Nt()-h.current}:{type:"dashboard.opened",from:Pt.current,tiles:Be.document.tiles.length,durationMs:Nt()-h.current})}}).catch(Be=>{if(xe)return;const St=`Could not read the ${f}: ${Be instanceof Error?Be.message:String(Be)}`;S(St),m.current?.({type:p,reason:St})}),()=>{xe=!0}},[ct,M,K,B,o,f,p]),k.useEffect(()=>{D&&m.current?.({type:"notebook.open_refused",reason:wc})},[D]);const rn=o&&!N&&K&&!_&&A.isSuccess&&!A.isFetching&&E===void 0;k.useEffect(()=>{rn&&(S(kc),m.current?.({type:"notebook.open_refused",reason:kc}))},[rn]);const dt=T===void 0?void 0:ol(i,T.name,a,l,M),pr=k.useCallback(async xe=>{if(!$||!dt)throw new Error("This host keeps no documents, so there is nowhere to save.");await $.saveDocument(dt,xe),H(qe=>qe&&{...qe,source:xe}),q(xe),(O||W===!0)&&Fe(xe),O||L(qe=>qe??!1)},[$,dt,O,W]),[Lt,sn]=k.useState(void 0),on=k.useCallback(async xe=>{const qe=await Yf(I.current,Z.current);if(qe===void 0)throw new Error("The package file is still loading; try again.");const cn=["dashboard-editor-model",a,l,M,u,o];await Kf({apiClients:x,queryClient:w,environmentName:a,packageName:l,modelPath:M,source:xe,expectedHash:qe,invalidateOnError:[cn],afterWrite:async Be=>{if(H(St=>St&&{...St,source:xe}),se({text:xe,onFetch:ve.current}),Fe(xe),I.current=Be,sn(void 0),$&&dt)try{await $.deleteDocument(dt),q(void 0),ae(!1)}catch(St){al(St)?(q(void 0),ae(!1)):sn(ll(St))}L(!1)},invalidate:[{queryKey:cn,wait:!0},{queryKey:Xf({environmentName:a,packageName:l,versionId:u,modelPath:M})},{queryKey:["dashboard-editor-manifest"]},{queryKey:["dashboards"]},{queryKey:["dashboard"]},...o?[{queryKey:[Zf({environmentName:a,packageName:l,modelPath:M})]}]:[]]})},[x,a,l,M,u,o,$,dt,w]),mr=T?.writeable===!0,C=g===!0,{savesTo:P,pinnedPackageSave:U,writer:ee}=ch({authoritative:O,mutable:C,...u!==void 0?{versionId:u}:{},canStore:!!$&&!!dt&&mr&&(!o||O),readFailed:Q!==void 0}),Ne=ee==="storage"?pr:ee==="package"?on:void 0,$e=T?.name,Se=k.useCallback(xe=>{m.current?.(Qf(xe,$e))},[$e]),bt=k.useCallback(xe=>{Ge(xe),b.current?.(xe)},[]),mi=xe=>{h.current=Nt(),ce(xe?z:J),L(xe)},gr=()=>{h.current=Nt(),ce(Dt)},an=P==="host"&&T?.description?T.description:void 0,vr=!O&&g===void 0?y?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":Jf({authoritative:O,mutable:C,pinnedPackageSave:U,...T?{workspace:T}:{},...Q!==void 0?{readFailure:Q}:{},...u!==void 0?{versionId:u}:{}}),ln=vr===an?"":vr;if(!d&&"resourceUri"in e)return v.jsxs(xt,{severity:"error",sx:{m:2},children:["A ",f," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(j)return v.jsxs(xt,{severity:"error",sx:{m:2},children:["This ",f," cannot be opened in the builder: ",j]});if(A.isError&&!N)return v.jsx(eh,{error:A.error,context:`Opening the ${f}`});if(!N&&(!E||!K))return v.jsxs(ye,{sx:{gap:2},children:[v.jsx(Cc,{}),v.jsx(Oc,{text:`Opening the ${f}…`})]});if(B)return v.jsxs(xt,{severity:"error",sx:{m:2},children:["This ",f," cannot be opened: ",Q]});const _f=z!==void 0&&z!==E;return v.jsxs(ye,{sx:{gap:2},children:[A.isError&&v.jsxs(xt,{severity:"warning",children:["The ",f," could not be re-read from the server:"," ",A.error?.message,". Your edits are still here."]}),!o&&!O&&oe&&_f&&W===void 0&&v.jsx(xt,{severity:"info",action:v.jsxs(ye,{direction:"row",sx:{gap:1},children:[v.jsx(Ee,{size:"small",onClick:()=>mi(!0),children:"Resume"}),v.jsx(Ee,{size:"small",onClick:()=>mi(!1),children:"Start from the package"})]}),children:"You have edits to this dashboard saved in this browser that the package does not have."}),Dt!==void 0&&v.jsx(xt,{severity:"warning",action:v.jsx(Ee,{size:"small",onClick:gr,children:"Load it"}),children:me?P==="package"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":P==="host"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them.":"This dashboard changed since you opened it. Loading the new version drops Undo save."}),Lt!==void 0&&v.jsxs(xt,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",Lt]}),N&&v.jsx(qx,{kind:i,environmentName:a,packageName:l,modelPath:M,slug:c,modelGivens:A.data?.data?.givens,...u!==void 0?{versionId:u}:{},opened:N,..._&&ee==="package"&&N.packageText!==void 0?{replaces:N.packageText}:{},onSave:Ne,onDirtyChange:bt,onSaveNoticeChange:R,savesTo:P,...an?{saveLabel:an}:{},...n?{onEvent:Se}:{},...t?{onExit:t}:{},note:ln},N.generation)]})}function qx({kind:e,modelGivens:t,environmentName:n,packageName:r,modelPath:i,slug:s,versionId:o,opened:a,replaces:l,onSave:u,onDirtyChange:d,onSaveNoticeChange:c,onEvent:f,savesTo:p,saveLabel:x,onExit:g,note:y}){const{apiClients:w}=jc(),h=e==="notebook",[m,b]=k.useState(a.document.tiles.length>0);k.useEffect(()=>b(a.document.tiles.length>0),[a.generation,a.document]);const{data:$,isSuccess:D,isError:M}=Ti({queryKey:["dashboard-editor-manifest",n,r,s,o,e],queryFn:async()=>{if(!h)return(await w.dashboards.getDashboard(n,r,s,o)).data;const N=(await w.notebooks.getNotebook(n,r,i,o)).data;return N.dashboard??{...N.startingGivens?{startingGivens:N.startingGivens}:{},...N.autorun===void 0?{}:{autorun:N.autorun}}},enabled:m}),A=$,{data:E}=Ti({queryKey:["dashboards",n,r,o],staleTime:6e4,queryFn:()=>w.dashboards.listDashboards(n,r,o),enabled:!h}),T=k.useMemo(()=>(E?.data??[]).map(N=>N.name).filter(N=>!!N&&N!==s),[E,s]),F=k.useMemo(()=>{const N=i.slice(0,i.lastIndexOf("/")+1);return a.document.imports.map(H=>({...H,path:new URL(H.from,`https://malloy.invalid/${N}`).pathname.slice(1)}))},[a.document.imports,i]),{data:z}=Ti({queryKey:["dashboard-editor-catalog",n,r,...F.map(N=>N.path),o],queryFn:async()=>{const N=(await w.models.listModels(n,r,o)).data.filter(j=>j.path&&!j.error&&!$f(j.path)&&!j.path.startsWith("notebooks/")),H=(await Promise.allSettled(N.map(j=>w.models.getModel(n,r,j.path,o).then(S=>S.data)))).flatMap(j=>j.status==="fulfilled"?[j.value]:[]);return Kv(Yv(H),F,H)},enabled:F.length>0}),[q,K]=k.useState(a.document);k.useEffect(()=>K(a.document),[a.document]);const X=k.useMemo(()=>u&&p==="package"?async(N,H)=>{await u(N),b(H.document.tiles.length>0)}:u,[u,p]),oe=k.useMemo(()=>A?.givens??(a.conversion?t??[]:[]),[A,a.conversion,t]),ae=k.useMemo(()=>new Set(oe.map(N=>N.name).filter(N=>N!==void 0)),[oe]),Q=k.useMemo(()=>Cx(q,oe),[q,oe]),{declaredTypes:he,applied:O,panel:B}=dh({specs:Q,loaded:D,startingValues:A?.startingGivens,documentKey:`${n}/${r}/${o??""}/${h?"notebook/":""}${s}/edit`,autorun:A?.autorun!==!1,environmentName:n,packageName:r,modelPath:A?.path,versionId:o,documentName:s}),W=!m||D||M,L=k.useMemo(()=>new Map((A?.tiles??[]).flatMap(N=>N.kind!=="text"&&N.query&&N.givenNames?[[mc(N.query),N.givenNames]]:[])),[A]),_=k.useMemo(()=>function(N,H){if(!W)return v.jsx(Oc,{text:"Running…"});const j=Mx(q,N,ae,O,L.get(mc(`${N.source} -> ${N.name}`)));return v.jsx(uh,{environmentName:n,packageName:r,versionId:o,modelPath:i,tile:j.expression,...j.annotation?{annotation:j.annotation}:{},label:N.label??Sc(`${N.source} -> ${N.name}`),subtitle:N.subtitle,...H?{heading:H}:{},borderless:N.borderless,givens:O,declaredTypes:he,givenNames:j.givenNames,ignoredFilters:hh(j.reads,Q),height:fh})},[q,W,ae,L,n,r,o,i,O,he,Q]);return v.jsxs(ye,{sx:{gap:1},children:[v.jsx(jx,{source:a.source,document:a.document,renderTile:_,givens:Q.filter(N=>N.name!==void 0).map(N=>({name:N.name,...N.label?{label:N.label}:{},...N.type?{type:N.type}:{},...N.suggest?.dimension?{field:N.suggest.dimension}:{}})),onChange:K,onDirtyChange:d,onSaveNoticeChange:c,...a.conversion?{conversion:a.conversion}:{},...z?{catalog:z}:{},dashboards:T,...f?{onEvent:f}:{},...g?{onExit:g}:{},controls:D?v.jsx(ph,{...B,layout:"bar"}):void 0,...X?{onSave:X}:{},savesTo:p,...x?{saveLabel:x}:{},...l!==void 0?{replaces:l}:{},modelPath:i}),v.jsx(Oe,{sx:{px:.5},children:v.jsx(ie,{variant:"caption",sx:{opacity:.7},children:y})})]})}function Vx(e){const{onExit:t,onEvent:n,onDirtyChange:r,path:i}=e,s="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return v.jsx(Fx,{...s,kind:"notebook",...t?{onExit:t}:{},...n?{onEvent:n}:{},...r?{onDirtyChange:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:dl===void 0&&(dl={});export{jx as DashboardBuilder,Fx as DashboardEditor,Xx as MAX_SLUG_ATTEMPTS,Vx as NotebookEditor,Yv as buildCatalog,Zx as createDocument,Qx as createRoute,Jx as documentPathFor,ey as documentPathForTitle,ol as locatorFor,ty as newDashboardSource,ny as newDocumentProblem,ry as newNotebookSource,us as readDashboardDocument,cs as readFailed,iy as slugFor,sy as slugOrFallback,Bv as spliceDashboardDocument,Uo as spliceFailed,oy as useDocumentChoices};