@vuu-ui/vuu-datatable 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -1,2 +1,17 @@
1
- "use strict";var mo=Object.create;var Pe=Object.defineProperty;var po=Object.getOwnPropertyDescriptor;var fo=Object.getOwnPropertyNames;var go=Object.getPrototypeOf,bo=Object.prototype.hasOwnProperty;var ho=(e,t)=>{for(var n in t)Pe(e,n,{get:t[n],enumerable:!0})},Dt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fo(t))!bo.call(e,r)&&r!==n&&Pe(e,r,{get:()=>t[r],enumerable:!(o=po(t,r))||o.enumerable});return e};var N=(e,t,n)=>(n=e!=null?mo(go(e)):{},Dt(t||!e||!e.__esModule?Pe(n,"default",{value:e,enumerable:!0}):n,e)),Co=e=>Dt(Pe({},"__esModule",{value:!0}),e);var Vr={};ho(Vr,{DataTable:()=>Gr,useMeasuredContainer:()=>yt});module.exports=Co(Vr);var Xe=require("@heswell/salt-lab"),xo=require("@salt-ds/core"),wo=N(require("classnames")),Ye=require("react");var ye=require("react"),Ht=N(require("react-dom"));var Tt=N(require("react-dom")),Rt=require("@salt-ds/core"),Et=require("react/jsx-runtime"),yo=1,Mo=(e=0,t=0,n=window)=>{let o=n.document.createElement("div");return o.className="vuuPopup "+yo++,o.style.cssText=`left:${e}px; top:${t}px;`,n.document.body.appendChild(o),o},vo=(e,t)=>Mo(e,t),Ee=(e,t,n,o,r)=>{t.style.cssText=`left:${n}px; top:${o}px;position: absolute;`,Tt.render((0,Et.jsx)(Rt.SaltProvider,{applyClassesTo:"child",children:e}),t,r)},Pt=vo;var _e=function({children:t,x:n=0,y:o=0,onRender:r}){let i=(0,ye.useMemo)(()=>Pt(),[]);return(0,ye.useLayoutEffect)(()=>{Ee(t,i,n,o,r)},[t,r,i,n,o]),(0,ye.useLayoutEffect)(()=>()=>{var s;i&&(Ht.unmountComponentAtNode(i),i.classList.contains("vuuPopup")&&((s=i.parentElement)==null||s.removeChild(i)))},[i]),null};var St=require("react/jsx-runtime");var Yt=require("@salt-ds/core"),Z=require("react");var Y=N(require("react")),qe=N(require("classnames")),Bt=require("@salt-ds/core");var z=require("react");var Lt=e=>e.closest("[data-root='true']")!==null,It=(e,t)=>{var n;return e.ariaHasPopup==="true"&&((n=e.dataset)==null?void 0:n.idx)===`${t}`||e.querySelector(`:scope > [data-idx='${t}'][aria-haspopup='true']`)!==null};function Do(e,...t){let n=new Set(e);for(let o of t)for(let r of o)n.add(r);return n}var To="Enter";var Ro="Delete",Po=new Set([To,Ro]),Eo=new Set(["Tab"]),Ho=new Set(["ArrowRight","ArrowLeft"]),At=new Set(["Home","End","ArrowDown","ArrowUp"]),kt=new Set(["Home","End","ArrowRight","ArrowLeft"]),So=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),as=Do(Po,kt,At,Ho,So,Eo);var Kt=({key:e},t="vertical")=>(t==="vertical"?At:kt).has(e);var Nt=({autoHighlightFirstItem:e=!1,count:t,highlightedIndex:n,onActivate:o,onHighlight:r,onCloseMenu:i,onOpenMenu:s})=>{let l=(0,z.useRef)((n!=null?n:e)?0:-1),[,c]=(0,z.useState)(null),p=n!==void 0,m=(0,z.useCallback)(a=>{l.current=a,r==null||r(a),c({})},[r]),u=(0,z.useCallback)(a=>{a!==l.current&&(p||m(a))},[p,m]),d=(0,z.useRef)(!0),C=(0,z.useRef)(!1),v=a=>C.current=a,b=p?n:l.current,h=(0,z.useCallback)(a=>{let y=Lo(t,a.key,l.current);y!==l.current&&u(y)},[t,u]),x=(0,z.useCallback)(a=>{Kt(a)?(a.preventDefault(),a.stopPropagation(),d.current=!0,h(a)):(a.key==="ArrowRight"||a.key==="Enter")&&It(a.target,b)?s(b):a.key==="ArrowLeft"&&!Lt(a.target)?i(b):a.key==="Enter"&&o&&o(b)},[b,h,o,i,s]),D=(0,z.useMemo)(()=>({onFocus:()=>{b===-1&&m(0)},onKeyDown:x,onMouseDownCapture:()=>{d.current=!1,v(!0)},onMouseMove:()=>{d.current&&(d.current=!1)},onMouseLeave:()=>{d.current=!0,v(!1),u(-1)}}),[b,u,h,o,i,s,m]);return{focusVisible:d.current?b:-1,controlledHighlighting:p,highlightedIndex:b,setHighlightedIndex:u,listProps:D,setIgnoreFocus:v}};function Lo(e,t,n){return t==="ArrowUp"?n>0?n-1:n:n===null?0:n===e-1?n:n+1}var J=N(require("react"));var Qe=e=>e.type===He||!!e.props["data-group"],Ft=e=>{let t=(0,J.useCallback)(()=>{let r=(s,l="root",c={},p={})=>{let m=c[l]=[],u=0,d=!1;return J.default.Children.forEach(s,C=>{if(C.type===zt)d=!0;else{let v=Qe(C),b=l==="root"?`${u}`:`${l}.${u}`,{props:{action:h,options:x}}=C,{childWithId:D,grandChildren:a}=i(C,b,v,d);m.push(D),a?r(a,b,c,p):p[b]={action:h,options:x},u+=1,d=!1}}),[c,p]},i=(s,l,c,p=!1)=>{let{props:{children:m}}=s;return{childWithId:J.default.cloneElement(s,{hasSeparator:p,id:`${l}`,key:l,children:c?void 0:m}),grandChildren:c?m:void 0}};return r(e)},[e]),[n,o]=(0,J.useMemo)(()=>t(),[t]);return[n,o]};var ue=require("react/jsx-runtime"),$t="vuuMenuList",zt=()=>(0,ue.jsx)("li",{className:"vuuMenuItem-divider"}),He=()=>null,Je=({children:e,idx:t,...n})=>(0,ue.jsx)("div",{...n,children:e}),Io=e=>e.props["data-icon"],Ot=({activatedByKeyboard:e,childMenuShowing:t=-1,children:n,className:o,highlightedIdx:r,id:i,isRoot:s,listItemProps:l,menuId:c,onHighlightMenuItem:p,onActivate:m,onCloseMenu:u,onOpenMenu:d,...C})=>{let v=(0,Bt.useIdMemo)(i),b=(0,Y.useRef)(null),h=(0,Y.useMemo)(()=>new Map,[]),x=E=>{var M;let f=(M=b.current)==null?void 0:M.querySelector(`:scope > [data-idx='${E}']`);f!=null&&f.id&&(d==null||d(f.id))},D=E=>{var M;let f=(M=b.current)==null?void 0:M.querySelector(`:scope > [data-idx='${E}']`);f!=null&&f.id&&(m==null||m(f.id))},{focusVisible:a,highlightedIndex:y,listProps:g}=Nt({count:Y.default.Children.count(n),highlightedIndex:r,onActivate:D,onHighlight:p,onOpenMenu:x,onCloseMenu:u}),R=t==-1?a:-1;return(0,Y.useLayoutEffect)(()=>{var E;t===-1&&e&&((E=b.current)==null||E.focus())},[e,t]),(0,ue.jsx)("div",{...C,...g,"aria-activedescendant":(()=>y===void 0||y===-1?void 0:h.get(y))(),className:(0,qe.default)($t,o,{[`${$t}-childMenuShowing`]:t!==-1}),"data-root":s||void 0,id:`${v}-${c}`,ref:b,role:"menu",tabIndex:0,children:L()});function L(){let E={...l,role:"menuitem"},f=(T,w,S)=>w?[(0,ue.jsx)("span",{className:"vuuIconContainer","data-icon":S},"icon")].concat(T):T;function M(T,w,S,U){var wt;let{children:ie,className:he,"data-icon":Re,id:le,hasSeparator:Ce,label:We,...ao}=w.props,Ue=Qe(w),xt=Ue&&t===S,co=xt?`${v}-${le}`:void 0;T.push((0,ue.jsx)(Je,{...ao,...E,...Ao(`${v}-${c}`,le,S,(wt=w.key)!=null?wt:le,y,R,he,Ce),"aria-controls":co,"aria-haspopup":Ue||void 0,"aria-expanded":xt||void 0,children:f(Ue?We:ie,U,Re)}))}let P=[];if(n.length>0){let T=n.some(Io);n.forEach((w,S)=>{M(P,w,S,T)})}return P}},Ao=(e,t,n,o,r,i,s,l)=>({id:`${e}-${t}`,key:o!=null?o:n,"data-idx":n,"data-highlighted":n===r||void 0,className:(0,qe.default)("vuuMenuItem",s,{"vuuMenuItem-separator":l,focusVisible:i===n})});Ot.displayName="MenuList";var Gt=Ot;var k=require("react");function Vt(e){if(e){let t=e.dataset.idx;if(t)return parseInt(t,10);if(e.ariaPosInSet)return parseInt(e.ariaPosInSet,10)-1}}var Ze=e=>e==null?void 0:e.closest("[data-idx],[aria-posinset]");var Wt=(e,t,n)=>e.map((o,r)=>r===e.length-1?{...o,[n]:o[n]-t}:o),ko=(e,t)=>Wt(e,t,"left"),Ko=(e,t)=>Wt(e,t,"top"),No=(e,t)=>{let[n,o]=t.slice(-2),r=document.getElementById(`${e}-${o.id}`);if(r===null)throw Error(`useCascade.flipSides element with id ${o.id} not found`);let{width:i}=r.getBoundingClientRect();return t.map(s=>s===o?{...s,left:n.left-(i-2)}:s)},Fo=(e,t)=>{let[{left:n,top:o}]=t.slice(-1),{offsetWidth:r,offsetTop:i}=e;return{left:n+r,top:i+o}},Me=e=>{let t=e.lastIndexOf("-");return t===-1?e:e.slice(t+1)},Se=e=>{let t=Me(e),n=t.lastIndexOf(".");return n>-1?t.slice(0,n):"root"},zo=e=>{let t=0,n=e.indexOf(".",0);for(;n!==-1;)t+=1,n=e.indexOf(".",n+1);return t},$o=e=>({menuId:Se(e.id),itemId:Me(e.id),isGroup:e.ariaHasPopup==="true",isOpen:e.ariaExpanded==="true",level:zo(e.id)}),Ut=({id:e,onActivate:t,onMouseEnterItem:n,position:{x:o,y:r}})=>{let[,i]=(0,k.useState)({}),s=(0,k.useRef)([{id:"root",left:o,top:r}]),l=(0,k.useCallback)(a=>{s.current=a,i({})},[]),c=(0,k.useRef)(),p=(0,k.useRef)(),m=(0,k.useRef)({root:"no-popup"}),u=(0,k.useRef)(0),d=(0,k.useCallback)((a="root",y=null,g=null)=>{if(a==="root"&&y===null)l([{id:"root",left:o,top:r}]);else{m.current[a]="popup-open";let H=(g?g.ownerDocument:document).getElementById(`${e}-${a}-${y}`),{left:L,top:E}=Fo(H,s.current);l(s.current.concat({id:y,left:L,top:E}))}},[e,o,r,l]),C=(0,k.useCallback)(a=>{l(a==="root"?[]:s.current.slice(0,-1))},[l]),v=(0,k.useCallback)((a,y)=>{let g=s.current.slice(),{id:R}=g[g.length-1];for(;g.length>1&&!y.startsWith(R);){let H=Se(R);g.pop(),m.current[R]="no-popup",m.current[H]="no-popup",{id:R}=g[g.length-1]}g.length<s.current.length&&l(g)},[l]),b=(0,k.useCallback)((a,y,g)=>{c.current&&clearTimeout(c.current),c.current=window.setTimeout(()=>{console.log(`scheduleOpen timed out opening ${y}`),v(a,y),m.current[a]="popup-open",m.current[y]="no-popup",d(a,y,g)},400)},[v,d]),h=(0,k.useCallback)((a,y,g)=>{console.log(`scheduleClose openMenuId ${a} menuId ${y} itemId ${g}`),m.current[a]="pending-close",p.current=window.setTimeout(()=>{v(y,g)},400)},[v]),x=(0,k.useCallback)(()=>{let{current:a}=s,[y]=a.slice(-1),g=document.getElementById(`${e}-${y.id}`);if(g){let{right:R,bottom:H}=g.getBoundingClientRect(),{clientHeight:L,clientWidth:E}=document.body;if(R>E){let f=a.length>1?No(e,a):ko(a,R-E);l(f)}else if(H>L){let f=Ko(a,H-L);l(f)}}},[e,l]),D=(0,k.useMemo)(()=>({onMouseEnter:a=>{let y=Ze(a.target),{menuId:g,itemId:R,isGroup:H,isOpen:L,level:E}=$o(y),f=u.current===E,{current:{[g]:M}}=m;if(u.current=E,M==="no-popup"&&H)m.current[g]="popup-pending",b(g,R,y);else if(M==="popup-pending"&&!H)m.current[g]="no-popup",clearTimeout(c.current),c.current=void 0;else if(M==="popup-pending"&&H)clearTimeout(c.current),b(g,R,y);else if(M==="popup-open"){let[{id:P},{id:T}]=s.current.slice(-2);P===g&&m.current[T]!=="pending-close"&&f?(h(T,g,R),H&&!L&&b(g,R,y)):P===g&&H&&R!==T&&m.current[T]==="pending-close"?b(g,R,y):H?(v(g,R),b(g,R,y)):m.current[T]==="pending-close"&&f||v(g,R)}M==="pending-close"&&(c.current&&(clearTimeout(c.current),c.current=void 0),clearTimeout(p.current),p.current=void 0,m.current[g]="popup-open"),n(a,R)},onClick:a=>{let y=a.target,g=Ze(y),R=Vt(g);console.log(`list item click [${R}] hasPopup ${g.ariaHasPopup}`),g.ariaHasPopup==="true"?g.ariaExpanded!=="true"&&d(R):t(Me(g.id))}}),[v,t,n,d,h,b]);return{closeMenu:C,handleRender:x,listItemProps:D,openMenu:d,openMenus:s.current}};var _t=require("react"),Xt=({containerClassName:e,isOpen:t,onClose:n})=>{(0,_t.useEffect)(()=>{let o;return t&&(o=r=>{r.target.closest(`.${e}`)===null&&(n==null||n("root"))},document.body.addEventListener("click",o,!0)),()=>{o&&document.body.removeEventListener("click",o,!0)}},[e,t,n])};var ve=require("react/jsx-runtime"),Qt=require("react"),Bo=()=>{},je=({activatedByKeyboard:e,children:t,className:n,id:o,onClose:r=()=>{},position:i={x:0,y:0},style:s,...l})=>{let c=(0,Yt.useIdMemo)(o),p=(0,Z.useRef)(Bo),[m,u]=Ft(t),d=(0,Z.useRef)(e),C=(0,Z.useCallback)(()=>{d.current=!1},[]),v=(0,Z.useCallback)(f=>{let{action:M,options:P}=u[f];p.current("root"),r(M,P)},[u,r]),{closeMenu:b,listItemProps:h,openMenu:x,openMenus:D,handleRender:a}=Ut({id:c,onActivate:v,onMouseEnterItem:C,position:i});p.current=b,console.log({openMenus:D});let y=(0,Z.useCallback)(()=>{b(),r()},[b,r]);Xt({containerClassName:"vuuMenuList",onClose:y,isOpen:D.length>0});let g=f=>{let M=Me(f),P=Se(M);d.current=!0,x(P,M)},R=()=>{d.current=!0,b()},H=()=>{},L=D.length-1,E=f=>{if(f>=L)return-1;{let{id:M}=D[f+1],P=M.lastIndexOf(".");return parseInt(P===-1?M:M.slice(-P),10)}};return(0,ve.jsx)(ve.Fragment,{children:D.map(({id:f,left:M,top:P},T)=>{let w=E(T);return(0,ve.jsx)(_e,{x:M,y:P,onRender:a,children:(0,Qt.createElement)(Gt,{...l,activatedByKeyboard:d.current,childMenuShowing:w,className:n,id:c,menuId:f,isRoot:T===0,key:T,listItemProps:h,onActivate:v,onHighlightMenuItem:H,onCloseMenu:R,onOpenMenu:g,style:s},m[f])},T)})})};je.displayName="ContextMenu";var ae=require("react"),Le=require("react/jsx-runtime"),Ie=(0,ae.createContext)(null),qt=e=>"children"in e,Oo=({children:e,context:t,menuActionHandler:n,menuBuilder:o})=>{let r=(0,ae.useMemo)(()=>t!=null&&t.menuBuilders&&o?t.menuBuilders.concat(o):o?[o]:(t==null?void 0:t.menuBuilders)||[],[t,o]),i=(0,ae.useCallback)((s,l)=>{var c;if(n!=null&&n(s,l)||(c=t==null?void 0:t.menuActionHandler)!=null&&c.call(t,s,l))return!0},[t,n]);return(0,Le.jsx)(Ie.Provider,{value:{menuActionHandler:i,menuBuilders:r},children:e})},Jt=({children:e,label:t,menuActionHandler:n,menuBuilder:o})=>(0,Le.jsx)(Ie.Consumer,{children:r=>(0,Le.jsx)(Oo,{context:r,label:t,menuActionHandler:n,menuBuilder:o,children:e})});var xe=require("react");var Zt=N(require("classnames")),ce=N(require("react")),Ae=N(require("react-dom"));var et=!1,O=[];function jt(e){if(e.key==="Esc"){if(O.length)tn();else if(et){let t=document.body.querySelector(".vuuDialog");t&&Ae.default.unmountComponentAtNode(t)}}}function en(e){if(O.length){let t=document.body.querySelectorAll(".vuuPopup");for(let n=0;n<t.length;n++)if(t[n].contains(e.target))return;tn()}}function tn(){if(O.length){let e=document.body.querySelectorAll(".vuuPopup");for(let t=0;t<e.length;t++)Ae.default.unmountComponentAtNode(e[t]);nn("*")}}function Go(e){O.indexOf(e)===-1&&(O.push(e),et===!1&&(window.addEventListener("keydown",jt,!0),window.addEventListener("click",en,!0)))}function nn(e){if(O.length){if(e==="*")O.length=0;else{let t=O.indexOf(e);t!==-1&&O.splice(t,1)}O.length===0&&et===!1&&(window.removeEventListener("keydown",jt,!0),window.removeEventListener("click",en,!0))}}var Vo=({children:e,position:t,style:n})=>{let o=(0,Zt.default)("hwPopup","hwPopupContainer",t);return(0,ce.createElement)("div",{className:o,style:n},e)},Wo=1,j=class{static showPopup({name:t="anon",group:n="all",position:o="",left:r=0,right:i="auto",top:s=0,width:l="auto",component:c}){if(!c)throw Error("PopupService showPopup, no component supplied");Go(t);let p=document.body.querySelector(".vuuPopup."+n);p===null&&(p=document.createElement("div"),p.className="vuuPopup "+n,document.body.appendChild(p));let m={width:l};Ee((0,ce.createElement)(Vo,{key:Wo++,position:o,style:m},c),p,r,s,()=>{j.keepWithinThePage(p,i)})}static hidePopup(t="anon",n="all"){if(O.indexOf(t)!==-1){nn(t);let o=document.body.querySelector(`.vuuPopup.${n}`);o&&Ae.default.unmountComponentAtNode(o)}}static keepWithinThePage(t,n="auto"){let o=t.querySelector(".vuuPopupContainer > *");if(o){let{top:r,left:i,width:s,height:l,right:c}=o.getBoundingClientRect(),p=window.innerWidth,u=window.innerHeight-(r+l);u<0&&(o.style.top=Math.round(r)+u+"px");let d=p-(i+s);if(d<0&&(o.style.left=Math.round(i)+d+"px"),typeof n=="number"&&n!==c){let C=n-c;o.style.left=i+C+"px"}}}};var ke=require("react/jsx-runtime"),Ke=()=>{let e=(0,xe.useContext)(Ie),t=(0,xe.useCallback)((o,r,i)=>{let s=[];for(let l of o)s=s.concat(l(r,i));return s},[]);return(0,xe.useCallback)((o,r,i)=>{var c;o.stopPropagation(),o.preventDefault();let s=(c=e==null?void 0:e.menuBuilders)!=null?c:[],l=t(s,r,i);console.log({menuItemDescriptors:l}),l.length&&(e!=null&&e.menuActionHandler)&&(console.log(`showContextMenu ${r}`,{options:i}),Uo(o,l,e.menuActionHandler))},[t,e])},Uo=(e,t,n)=>{let{clientX:o,clientY:r}=e,l=(0,ke.jsx)(je,{onClose:(c,p)=>{c&&(n(c,p),j.hidePopup())},position:{x:o,y:r},children:(c=>{let p=(m,u)=>qt(m)?(0,ke.jsx)(He,{label:m.label,children:m.children.map(p)},u):(0,ke.jsx)(Je,{action:m.action,"data-icon":m.icon,options:m.options,children:m.label},u);return c.map(p)})(t)});j.showPopup({left:0,top:0,component:l})};var Ve=require("@salt-ds/core"),uo=require("react");var xn=require("@vuu-ui/vuu-utils"),wn=require("react"),Dn=N(require("classnames"));var Fe=require("@vuu-ui/vuu-utils"),mn=N(require("classnames")),ze=require("react");var on=require("@vuu-ui/vuu-utils"),rn=require("@heswell/salt-lab"),sn=N(require("classnames")),we=require("react");var Ne=require("react/jsx-runtime"),_o=e=>e==null?"":typeof e=="string"?e:e.toString(),ln=({className:e,column:t,row:n,valueFormatter:o=_o})=>{let r=(0,we.useRef)(null),{align:i,key:s,pin:l,editable:c,resizing:p}=t,[m,u]=(0,we.useState)(!1),d=o(n[s]),[C,v]=(0,we.useState)(d),b=()=>{var g;(g=r.current)==null||g.focus()},h=g=>{g.key==="Enter"&&u(!0)},x=()=>{u(!0)},D=(g="",R="",H=!0,L=!1)=>{var E;u(!1),L?v(g):R!==g&&v(R),H===!1&&((E=r.current)==null||E.focus())},a=(0,sn.default)(e,{vuuAlignRight:i==="right",vuuPinFloating:l==="floating",vuuPinLeft:l==="left",vuuPinRight:l==="right","vuuTableCell-resizing":p})||void 0,y=(0,on.getColumnPinStyle)(t);return c?(0,Ne.jsx)("td",{className:a,"data-editable":!0,style:y,onKeyDown:h,children:(0,Ne.jsx)(rn.EditableLabel,{editing:m,value:C,onChange:v,onMouseDownCapture:b,onEnterEditMode:x,onExitEditMode:D,onKeyDown:h,ref:r,tabIndex:0},"title")}):(0,Ne.jsx)("td",{className:a,style:y,children:d})};var un=require("@vuu-ui/vuu-utils");var me=require("react/jsx-runtime"),{DEPTH:Xo,IS_LEAF:an}=un.metadataKeys,Yo=(e,t)=>{let{[Xo]:n,[an]:o}=t;if(o||n>e.length)return[null,n===null?0:n-1];if(n===0)return["$root",0];{let r=e[n-1];return[t[r.key],n-1]}},cn=({column:e,onClick:t,row:n})=>{let{columns:o}=e,[r,i]=Yo(o,n),s={left:e.pin=="left"?e.pinnedOffset:void 0},l=n[an],c=Array(i).fill(0).map((p,m)=>(0,me.jsx)("span",{className:"vuuTableGroupCell-spacer"},m));return(0,me.jsxs)("td",{className:"vuuTableGroupCell vuuPinLeft",onClick:l?void 0:t,style:s,children:[c,l?null:(0,me.jsx)("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),(0,me.jsx)("span",{children:r})]})};var nt=require("react/jsx-runtime"),{IDX:Qo,IS_EXPANDED:qo}=Fe.metadataKeys,tt="vuuDataTableRow",$e=(0,ze.memo)(function({columns:t,height:n,index:o,onToggleGroup:r,row:i,valueFormatters:s}){let{[Qo]:l,[qo]:c}=i,p=(0,mn.default)(tt,{[`${tt}-even`]:l%2===0,[`${tt}-expanded`]:c}),m=l-o,u=(0,ze.useCallback)(()=>r==null?void 0:r(i),[r,i]);return(0,nt.jsx)("tr",{"data-idx":l,className:p,style:{transform:`translate3d(0px, ${m*n}px, 0px)`},children:t.map(d=>{let C=(0,Fe.isGroupColumn)(d);return(0,nt.jsx)(C?cn:ln,{column:d,onClick:C?u:void 0,row:i,valueFormatter:s==null?void 0:s[d.name]},d.name)})})});var Mn=N(require("classnames")),ne=require("react");var pe=require("react");var dn=require("react/jsx-runtime"),pn=()=>{},Jo="vuuColumnResizer",Be=({onDrag:e,onDragEnd:t=pn,onDragStart:n=pn})=>{let o=(0,pe.useRef)(0),r=(0,pe.useCallback)(l=>{l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault();let c=Math.round(l.clientX),p=c-o.current;o.current=c,p!==0&&e(l,p)},[e]),i=(0,pe.useCallback)(l=>{window.removeEventListener("mouseup",i),window.removeEventListener("mousemove",r),t(l)},[t,r]),s=(0,pe.useCallback)(l=>{n(l),o.current=Math.round(l.clientX),window.addEventListener("mouseup",i),window.addEventListener("mousemove",r),l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault()},[n,r,i]);return(0,dn.jsx)("div",{className:Jo,onMouseDown:s})};var ot=N(require("classnames"));var ee=require("react/jsx-runtime"),fn="vuuSortIndicator",gn=({sorted:e})=>{if(!e)return null;let t=typeof e=="number"?e<0?"dsc":"asc":e==="A"?"asc":"dsc";return typeof e=="number"?(0,ee.jsxs)("div",{className:(0,ot.default)(fn,"multi-col",t),children:[(0,ee.jsx)("span",{"data-icon":`sorted-${t}`}),(0,ee.jsx)("span",{className:"vuuSortPosition",children:Math.abs(e)})]}):(0,ee.jsx)("div",{className:(0,ot.default)(fn,"single-col"),children:(0,ee.jsx)("span",{"data-icon":`sorted-${t}`})})};var te=require("react"),Oe=({column:e,onResize:t,rootRef:n})=>{let o=(0,te.useRef)(0),r=(0,te.useRef)(!1),{name:i}=e,s=(0,te.useCallback)(()=>{if(t&&n.current){let{width:p}=n.current.getBoundingClientRect();o.current=Math.round(p),r.current=!0,t==null||t("begin",i)}},[i,t,n]),l=(0,te.useCallback)((p,m)=>{if(n.current&&t){let{width:u}=n.current.getBoundingClientRect(),d=Math.round(u)+m;d!==o.current&&d>0&&(t("resize",i,d),o.current=d)}},[i,t,n]),c=(0,te.useCallback)(()=>{t&&(t("end",i,o.current),r.current=!1)},[i,t]);return{isResizing:r.current,onDrag:l,onDragStart:s,onDragEnd:c}};var bn=N(require("classnames")),hn=require("react");var yn=require("react/jsx-runtime");var Cn=({column:e,filter:t})=>{let n=Ke(),o=(0,hn.useCallback)(r=>{r.stopPropagation(),n(r,"filter",{column:e,filter:t})},[e,t,n]);return e.filter?(0,yn.jsx)("div",{className:(0,bn.default)("vuuFilterIndicator"),"data-icon":"filter",onClick:o}):null};var Q=require("react/jsx-runtime"),De="vuuTable-headerCell",Ge=({column:e,className:t,onClick:n,onDragStart:o,onResize:r,...i})=>{let s=(0,ne.useRef)(null),{isResizing:l,...c}=Oe({column:e,onResize:r,rootRef:s}),p=Ke(),m=(0,ne.useRef)(null),u=h=>{p(h,"header",{column:e})},d=(0,ne.useCallback)(h=>!l&&(n==null?void 0:n(h)),[l,n]),C=(0,ne.useCallback)(h=>{m.current=window.setTimeout(()=>{o==null||o(h),m.current=null},250)},[o]),v=(0,ne.useCallback)(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),b=(0,Mn.default)(De,t,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:e.endPin,[`${De}-resizing`]:e.resizing,[`${De}-right`]:e.align==="right"});return(0,Q.jsx)("th",{className:b,...i,onClick:d,onContextMenu:u,onMouseDown:C,onMouseUp:v,ref:s,children:(0,Q.jsxs)("div",{className:`${De}-inner`,children:[(0,Q.jsx)(Cn,{column:e}),(0,Q.jsx)("div",{className:`${De}-label`,children:e.label}),(0,Q.jsx)(gn,{sorted:e.sorted}),e.resizeable!==!1?(0,Q.jsx)(Be,{...c}):null]})})};var G=require("react/jsx-runtime"),vn="vuuDataTable",{RENDER_IDX:Zo}=xn.metadataKeys,Tn=({columns:e,data:t,headerHeight:n,onHeaderCellDragEnd:o,rowHeight:r})=>{let i=(0,wn.useCallback)(()=>{o==null||o()},[o]);return console.log("ColumnBasedTable render"),(0,G.jsx)(G.Fragment,{children:e.map((s,l)=>(0,G.jsx)("table",{className:(0,Dn.default)(`${vn}-table`,`${vn}-columnBased`,{vuuPinLeft:s.pin==="left"}),"data-idx":l,id:`col-${l}`,style:{width:s.width,left:s.pinnedOffset,"--vuuTableHeaderHeight":`${n}px`,"--row-height":`${r}px`},children:(0,G.jsxs)("tbody",{children:[(0,G.jsx)("tr",{children:(0,G.jsx)(Ge,{column:s,"data-idx":l,onDragEnd:i},l)},"header"),t.map((c,p)=>(0,G.jsx)($e,{columns:[s],height:r,index:p,row:c},c[Zo])),(0,G.jsx)("tr",{className:"vuuTable-filler"})]})},s.name))})};var Rn=require("@vuu-ui/vuu-utils"),Pn=e=>(t,n)=>{let o=[];if(e===void 0)return o;if(t==="header")o.push(...jo(n,e)),o.push(...nr(n,e)),o.push(...er(n,e)),o.push(...tr(n,e));else if(t==="filter"){let{column:r,filter:i}=n,s=(i==null?void 0:i.column)===(r==null?void 0:r.name);o.push({label:"Edit filter",action:"filter-edit",options:n}),o.push({label:"Remove filter",action:"filter-remove-column",options:n}),r&&!s&&o.push({label:"Remove all filters",action:"remove-filters",options:n})}return o};function jo(e,{sort:{sortDefs:t}}){let{column:n}=e,o=[];if(n===void 0)return o;let r=t.length>0;return n.sorted==="A"?o.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):n.sorted==="D"?o.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof n.sorted=="number"?(n.sorted>0?o.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):o.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),r&&Math.abs(n.sorted)<t.length&&o.push({label:"Remove from sort",action:"sort-remove",options:e}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r?(o.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):o.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),o}function er(e,t){let{column:n}=e;if(n===void 0||t.groupBy.length===0)return[];let{name:o,label:r=o}=n;return[{label:`Aggregate ${r}`,children:[{label:"Count",action:"agg-count",options:e}].concat((0,Rn.isNumericColumn)(n)?[{label:"Sum",action:"agg-sum",options:e},{label:"Avg",action:"agg-avg",options:e},{label:"High",action:"agg-high",options:e},{label:"Low",action:"agg-low",options:e}]:[])}]}var lt=(e,t)=>({label:`Pin ${t}`,action:`column-pin-${t}`,options:e}),rt=e=>lt(e,"left"),st=e=>lt(e,"floating"),it=e=>lt(e,"right");function tr(e,t){let{column:n}=e;if(n===void 0)return[];let{name:o,label:r=o,pin:i}=n,s=[{label:"Hide column",action:"column-hide",options:e}];return i===void 0?s.push({label:"Pin column",children:[rt(e),st(e),it(e)]}):i==="left"?s.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[st(e),it(e)]}):i==="right"?s.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[rt(e),st(e)]}):i==="floating"&&s.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[rt(e),it(e)]}),s}function nr(e,{groupBy:t}){let{column:n}=e,o=[];if(n===void 0)return o;let{name:r,label:i=r}=n;return t.length===0?o.push({label:`Group by ${i}`,action:"group",options:e}):o.push({label:`Add ${i} to group by`,action:"group-add",options:e}),o}var En=require("@vuu-ui/vuu-filters"),K=require("@vuu-ui/vuu-utils"),or=(e,t)=>{if(e.filterStruct&&t){let[n,o]=(0,En.removeColumnFromFilter)(t,e.filterStruct);return{filter:o,filterStruct:n}}else return e},{Average:rr,Count:sr,High:ir,Low:lr,Sum:ur}=K.AggregationType,Hn=({dataSource:e,dispatchColumnAction:t})=>(o,r)=>{let i=r;if(i.column&&e){let{column:s}=i;switch(o){case"sort-asc":return e.sort=(0,K.setSortColumn)(e.sort,s,"A"),!0;case"sort-dsc":return e.sort=(0,K.setSortColumn)(e.sort,s,"D"),!0;case"sort-add-asc":return e.sort=(0,K.addSortColumn)(e.sort,s,"A"),!0;case"sort-add-dsc":return e.sort=(0,K.addSortColumn)(e.sort,s,"D"),!0;case"group":return e.groupBy=(0,K.addGroupColumn)(e.groupBy,s),!0;case"group-add":return e.groupBy=(0,K.addGroupColumn)(e.groupBy,s),!0;case"filter-remove-column":return e.filter=or(e.filter,s),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=(0,K.setAggregations)(e.aggregations,s,rr),!0;case"agg-high":return e.aggregations=(0,K.setAggregations)(e.aggregations,s,ir),!0;case"agg-low":return e.aggregations=(0,K.setAggregations)(e.aggregations,s,lr),!0;case"agg-count":return e.aggregations=(0,K.setAggregations)(e.aggregations,s,sr),!0;case"agg-sum":return e.aggregations=(0,K.setAggregations)(e.aggregations,s,ur),!0;case"column-pin-floating":return t({type:"updateColumnProp",column:s,pin:"floating"}),!0;case"column-pin-left":return t({type:"updateColumnProp",column:s,pin:"left"}),!0;case"column-pin-right":return t({type:"updateColumnProp",column:s,pin:"right"}),!0;case"column-unpin":return t({type:"updateColumnProp",column:s,pin:void 0}),!0;default:}}return!1};var fe=require("@vuu-ui/vuu-utils"),at=require("react");var ut=N(require("classnames")),Sn=require("react");var _=require("react/jsx-runtime"),de="vuuTable-groupHeaderCell",ar=e=>{let{column:t,className:n,onRemoveColumn:o}=e;return(0,_.jsxs)("div",{className:(0,ut.default)(`${de}-col`,n),role:"columnheader",children:[(0,_.jsx)("span",{className:`${de}-label`,children:t.name}),(0,_.jsx)("span",{className:`${de}-close`,"data-icon":"close-circle",onClick:()=>o==null?void 0:o(t)})]})},Ln=({column:e,className:t,onRemoveColumn:n,onResize:o,...r})=>{let i=(0,Sn.useRef)(null),{isResizing:s,...l}=Oe({column:e,onResize:o,rootRef:i}),c=(0,ut.default)(de,t,{vuuPinLeft:e.pin==="left",[`${de}-right`]:e.align==="right"}),{columns:p}=e;return(0,_.jsx)("th",{className:c,...r,children:(0,_.jsxs)("div",{className:`${de}-inner`,children:[p.map(m=>(0,_.jsx)(ar,{column:m,onRemoveColumn:n},m.key)),e.resizeable!==!1?(0,_.jsx)(Be,{...l}):null]})})};var $=require("react/jsx-runtime"),In="vuuDataTable",{RENDER_IDX:cr}=fe.metadataKeys,An=({columns:e,data:t,onColumnResize:n,onHeaderCellDragStart:o,onRemoveColumnFromGroupBy:r,onSort:i,onToggleGroup:s,rowHeight:l,valueFormatters:c})=>{let p=(0,at.useCallback)(u=>{console.log("RowBasedDataTable handleDragStart",{evt:u,onHeaderCellDragStart:o}),o==null||o(u)},[o]),m=(0,at.useCallback)(u=>{var x;let C=u.target.closest(".vuuTable-headerCell"),v=parseInt((x=C==null?void 0:C.dataset.idx)!=null?x:"-1"),b=e[v],h=u.shiftKey;b&&i(b,h)},[e,i]);return(0,$.jsxs)("table",{className:`${In}-table`,children:[(0,$.jsx)("colgroup",{children:e.map((u,d)=>(0,$.jsx)("col",{width:`${u.width}px`},d))}),(0,$.jsx)("thead",{children:(0,$.jsx)("tr",{children:e.map((u,d)=>{let C=(0,fe.getColumnPinStyle)(u);return(0,fe.isGroupColumn)(u)?(0,$.jsx)(Ln,{column:u,"data-idx":d,onRemoveColumn:r,onResize:n,style:C},d):(0,$.jsx)(Ge,{column:u,"data-idx":d,onClick:m,onDragStart:p,onResize:n,style:C},d)})})}),(0,$.jsxs)("tbody",{children:[t==null?void 0:t.map((u,d)=>(0,$.jsx)($e,{columns:e,height:l,index:d,onToggleGroup:s,row:u,valueFormatters:c},u[cr])),(0,$.jsx)("tr",{className:`${In}-filler`})]})]})};var be=require("@vuu-ui/vuu-utils"),F=require("react");var q=require("@vuu-ui/vuu-utils"),I=require("react"),{RENDER_IDX:kn}=q.metadataKeys,Kn=(e,t)=>e[kn]-t[kn],mr=e=>["aggregate","filter","groupBy","sort"].includes(e.type);function Nn({dataSource:e,onConfigChange:t,onSizeChange:n,onSubscribed:o,range:r={from:0,to:0},renderBufferSize:i=0,viewportRowCount:s}){let[,l]=(0,I.useState)(null),c=(0,I.useRef)(!0),p=(0,I.useRef)(!1),m=(0,I.useRef)({from:0,to:0}),u=(0,I.useRef)(null),d=(0,I.useRef)([]),C=(0,I.useMemo)(()=>new ct((0,q.getFullRange)(r)),[]),v=(0,I.useCallback)(a=>{for(let y of a)C.add(y);d.current=C.data.slice().sort(Kn),p.current=!0},[C]),b=(0,I.useCallback)(a=>{a.type==="subscribed"?o==null||o(a):a.type==="viewport-update"?(typeof a.size=="number"&&(n==null||n(a.size),C.setRowCount(a.size)),a.rows?v(a.rows):typeof a.size=="number"&&(d.current=C.data.slice().sort(Kn),p.current=!0)):mr(a)&&(t==null||t(a))},[C,t,n,o,v]);(0,I.useEffect)(()=>()=>{u.current&&(cancelAnimationFrame(u.current),u.current=null),c.current=!1},[]);let h=(0,I.useCallback)(()=>{c.current&&(p.current&&(l({}),p.current=!1),u.current=requestAnimationFrame(h))},[l]);(0,I.useEffect)(()=>{u.current=requestAnimationFrame(h)},[h]);let x=(0,I.useCallback)(a=>{let{from:y}=e.range,g=(0,q.getFullRange)({from:y,to:y+a},i);e.range=m.current=g,C.setRange(g)},[e,C,i]),D=(0,I.useCallback)(a=>{let y=(0,q.getFullRange)(a,i);e.range=m.current=y,C.setRange(y)},[e,C,i]);return(0,I.useEffect)(()=>(e==null||e.subscribe({range:m.current},b),()=>{e==null||e.unsubscribe()}),[e,b]),(0,I.useEffect)(()=>{x(s)},[x,s]),{data:d.current,range:m.current,setRange:D,dataSource:e}}var ct=class{constructor({from:t,to:n}){this.rowCount=0;this.setRowCount=t=>{t<this.data.length&&(this.data.length=t),this.rowCount=t};this.range=new q.WindowRange(t,n),this.data=new Array(n-t),this.rowCount=0}add(t){let[n]=t;if(this.isWithinRange(n)){let o=n-this.range.from;this.data[o]=t}}getAtIndex(t){return this.range.isWithin(t)&&this.data[t-this.range.from]!=null?this.data[t-this.range.from]:void 0}isWithinRange(t){return this.range.isWithin(t)}setRange({from:t,to:n}){if(t!==this.range.from||n!==this.range.to){let[o,r]=this.range.overlap(t,n),i=new Array(n-t);for(let s=o;s<r;s++){let l=this.getAtIndex(s);if(l){let c=s-t;i[c]=l}}this.data=i,this.range.from=t,this.range.to=n}}};var On=require("@vuu-ui/vuu-utils"),A=require("react");function pr(e,...t){let n=new Set(e);for(let o of t)for(let r of o)n.add(r);return n}var mt="ArrowUp",pt="ArrowDown",dt="ArrowLeft",ft="ArrowRight";var gt="Home",bt="End",ht="PageUp",Ct="PageDown";var dr=new Set(["Enter","Delete"," "]),fr=new Set(["Tab"]),gr=new Set(["ArrowRight","ArrowLeft"]),Fn=new Set([gt,bt,ht,Ct,pt,dt,ft,mt]),br=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),Hl=pr(dr,Fn,gr,br,fr);var hr=["Home","End","PageUp","PageDown"],zn=e=>hr.includes(e),$n=e=>Fn.has(e);var Bn=e=>`thead th:nth-child(${e+1})`,Cr=(e,t)=>`tbody > tr[data-idx='${e}'] > td:nth-child(${t+1})`;function yr(e,[t,n],o,r){return e===mt?t>-1?[t-1,n]:[t,n]:e===pt?t===-1?[0,n]:t===r-1?[t,n]:[t+1,n]:e===ft?n<o-1?[t,n+1]:[t,n]:e===dt?n>0?[t,n-1]:[t,n]:[t,n]}var Gn=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:n,data:o,requestScroll:r,rowCount:i=0,viewportRange:s})=>{var E;let{from:l,to:c}=s,p=(0,A.useRef)([-1,-1]),m=(0,A.useRef)(),u=(0,A.useRef)([-1,0]),d=(0,A.useCallback)(([f,M])=>{var T;let P=f===-1?Bn(M):Cr(f,M);return(T=t.current)==null?void 0:T.querySelector(P)},[t]),C=f=>f==null?void 0:f.closest("th,td"),v=f=>{var M,P;if(f.tagName==="TH")return[-1,parseInt((M=f.dataset.idx)!=null?M:"-1",10)];{let T=f.closest("tr");if(T){let w=parseInt((P=T.dataset.idx)!=null?P:"-1",10),S=Array.from(T.childNodes).indexOf(f);return[w,S]}}return[-1,-1]},b=(0,A.useCallback)(f=>{var M;if(t.current){let P=d(f);P?(P!==m.current&&((M=m.current)==null||M.setAttribute("tabindex",""),m.current=P,P.setAttribute("tabindex","0")),P.focus()):(0,On.withinRange)(f[0],s)||(m.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[t,d,r,s]),h=(0,A.useCallback)((f,M,P=!1)=>{let T=[f,M];u.current=T,b(T),P&&(p.current=T)},[b]),x=(0,A.useCallback)(()=>{var f;(f=m.current)==null||f.setAttribute("tabindex",""),m.current=void 0},[]),D=(0,A.useCallback)(async(f,M)=>{switch(f){case Ct:r==null||r({type:"scroll-page",direction:"down"});break;case ht:r==null||r({type:"scroll-page",direction:"up"});break;case gt:r==null||r({type:"scroll-end",direction:"home"});break;case bt:r==null||r({type:"scroll-end",direction:"end"});break}return M},[r]),a=(0,A.useCallback)(()=>{var f;if(n!==!0&&(f=t.current)!=null&&f.contains(document.activeElement)){let M=C(document.activeElement);M&&(p.current=v(M))}},[n,t]),y=(0,A.useCallback)(async f=>{let[M,P]=zn(f)?await D(f,u.current):yr(f,u.current,e,i),[T,w]=u.current;(M!==T||P!==w)&&h(M,P,!0)},[e,D,i,h]),g=(0,A.useCallback)(f=>{o.length>0&&$n(f.key)&&(f.preventDefault(),f.stopPropagation(),y(f.key))},[o,y]),R=(0,A.useCallback)(f=>{let M=f.target,P=C(M),[T,w]=v(P);h(T,w)},[h]),H=(0,A.useMemo)(()=>({onClick:R,onFocus:a,onKeyDown:g}),[R,a,g]);(0,A.useLayoutEffect)(()=>{let{current:f}=u,M=f[0]>=l&&f[0]<=c;m.current&&!M?x():!m.current&&M&&b(f)},[b,l,c,x]);let L=((E=t.current)==null?void 0:E.firstChild)!=null;return(0,A.useEffect)(()=>{var f;if(L&&m.current===void 0){let M=(f=t.current)==null?void 0:f.querySelector(Bn(0));M&&(M.setAttribute("tabindex","0"),m.current=M)}},[t,L]),H};var ge=require("react");var re=require("react");var oe=new Map,Wn=(e,t,n)=>{switch(n){case"height":return t.height;case"clientHeight":return e.clientHeight;case"clientWidth":return e.clientWidth;case"contentHeight":return t.contentHeight;case"contentWidth":return t.contentWidth;case"scrollHeight":return Math.ceil(e.scrollHeight);case"scrollWidth":return Math.ceil(e.scrollWidth);case"width":return t.width;default:return 0}},Vn=new ResizeObserver(e=>{for(let t of e){let{target:n,borderBoxSize:o,contentBoxSize:r}=t,i=oe.get(n);if(i){let[{blockSize:s,inlineSize:l}]=o,[{blockSize:c,inlineSize:p}]=r,{onResize:m,measurements:u}=i,d=!1;for(let[C,v]of Object.entries(u)){let b=Wn(n,{height:s,width:l,contentHeight:c,contentWidth:p},C);b!==v&&(d=!0,u[C]=b)}d&&m&&m(u)}}});function Un(e,t,n,o=!1){let r=(0,re.useRef)(t),i=(0,re.useCallback)(s=>{let{width:l,height:c}=s.getBoundingClientRect(),{clientWidth:p,clientHeight:m}=s;return r.current.reduce((u,d)=>(u[d]=Wn(s,{width:l,height:c,contentHeight:m,contentWidth:p},d),u),{})},[]);(0,re.useEffect)(()=>{let s=e.current;async function l(){oe.set(s,{measurements:{}}),await document.fonts.ready;let c=oe.get(s);if(c){let p=i(s);c.measurements=p,Vn.observe(s),o&&n(p)}else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation","font-weight:bold; color:red;")}if(s){if(oe.has(s))throw Error("useResizeObserver attemping to observe same element twice");l()}return()=>{s&&oe.has(s)&&(Vn.unobserve(s),oe.delete(s))}},[i,e]),(0,re.useEffect)(()=>{let s=e.current,l=oe.get(s);if(l){if(r.current!==t){r.current=t;let c=i(s);l.measurements=c}l.onResize=n}},[t,i,e,n])}var Mr=["clientHeight","clientWidth"],_n=e=>Number.isFinite(e),yt=({defaultHeight:e=0,defaultWidth:t=0,height:n,width:o})=>{let r=(0,ge.useRef)(null),[i,s]=(0,ge.useState)({outer:{height:n!=null?n:"100%",width:o!=null?o:"100%"}}),l=(0,ge.useCallback)(({clientWidth:c,clientHeight:p})=>{s(m=>{let{inner:u,outer:d}=m;return _n(p)&&_n(c)&&(c!==(u==null?void 0:u.width)||p!==(u==null?void 0:u.height))?{outer:d,inner:{width:Math.floor(c)||t,height:Math.floor(p)||e}}:m})},[e,t]);return Un(r,Mr,l,!0),{containerRef:r,outerSize:i.outer,innerSize:i.inner}};var Yn=require("@heswell/salt-lab"),V=require("@vuu-ui/vuu-utils"),Qn=require("@vuu-ui/vuu-filters"),qn=require("react"),vr=100,xr=V.metadataKeys.count,wr=({serverDataType:e})=>e===void 0,Dr=(e,t,n)=>{var r;let o=t.indexOf(e.name);return o!==-1&&n[o]?n[o]:(r=e.serverDataType)!=null?r:"string"},Tr=["int","long","double"],Jn=e=>e===void 0?void 0:Tr.includes(e)?"right":"left",Rr=(e,t)=>{switch(t.type){case"init":return jn(t.config);case"moveColumn":return Pr(e,t);case"resizeColumn":return Er(e,t);case"setTypes":return Hr(e,t);case"updateColumnProp":return Mt(e,t);case"tableConfig":return Sr(e,t);default:return console.log(`unhandled action ${t.type}`),e}},Zn=e=>{let[t,n]=(0,qn.useReducer)(Rr,e,jn);return{columns:t.columns,dispatchColumnAction:n}};function jn(e){let t=e.columns.map(Xn);return t.some(V.isPinned)?{columns:(0,V.sortPinnedColumns)(t)}:{columns:e.columns.map(Xn)}}var Xn=(e,t)=>{let{align:n=Jn(e.serverDataType),name:o,label:r=o,width:i=vr,...s}=e;return{...s,align:n,label:r,key:t+xr,name:o,originalIdx:t,width:i}};function Pr(e,{column:t,moveBy:n,moveTo:o}){let{columns:r}=e;if(typeof n=="number"){let i=r.indexOf(t),s=r.slice(),[l]=s.splice(i,1);return s.splice(i+n,0,l),{...e,columns:s}}else if(typeof o=="number"){let i=r.indexOf(t);return{...e,columns:(0,Yn.moveItem)(r,i,o)}}return e}function Er(e,{column:t,phase:n,width:o}){let r="updateColumnProp",i=n!=="end";switch(n){case"begin":case"end":return Mt(e,{type:r,column:t,resizing:i});case"resize":return Mt(e,{type:r,column:t,width:o});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${n}`)}}function Hr(e,{columnNames:t,serverDataTypes:n}){console.log("setTypes, existing columns",{state:e});let{columns:o}=e;if(o.some(wr)){let r=o.map(i=>{var l;let s=Dr(i,t,n);return{...i,align:(l=i.align)!=null?l:Jn(s),serverDataType:s}});return{...e,columns:r}}else return e}function Mt(e,t){let{columns:n}=e,{align:o,column:r,label:i,pin:s,resizing:l,width:c}=t,p=n.find(m=>m.name===r.name);return p&&((o==="left"||o==="right")&&(n=Te(n,{...p,align:o})),typeof i=="string"&&(n=Te(n,{...p,label:i})),typeof l=="boolean"&&(n=Te(n,{...p,resizing:l})),typeof c=="number"&&(n=Te(n,{...p,width:c})),"pin"in t&&(n=Te(n,{...p,pin:s}),n=(0,V.sortPinnedColumns)(n))),{...e,columns:n}}function Sr(e,{filter:t,groupBy:n,sort:o}){let r=n!==void 0,i=typeof(t==null?void 0:t.filter)=="string",s=o&&o.sortDefs.length>0,l=e;return r&&(l={...e,columns:Lr(e.columns,n)}),s&&(l={...e,columns:Ir(e.columns,o)}),i&&(l={...e,columns:Ar(e.columns,t)}),l}function Te(e,t){return e.map(n=>n.name===t.name?t:n)}var Lr=(e,t)=>{var n;if(t.length){let[o,r]=(0,V.extractGroupColumn)(e,t);if(o)return[o].concat(r)}else if((n=e[0])!=null&&n.isGroup)return(0,V.flattenColumnGroup)(e);return e},Ir=(e,t)=>e.map(n=>{let o=kr(n,t);return o!==void 0?{...n,sorted:o}:n.sorted?{...n,sorted:void 0}:n}),Ar=(e,{filterStruct:t})=>e.map(n=>{let o=(0,Qn.extractFilterForColumn)(t,n.name);return o!==void 0?{...n,filter:o}:n.filter?{...n,filter:void 0}:n}),kr=(e,{sortDefs:t})=>{let n=t.find(o=>o.column===e.name);if(n)return t.length>1?(t.indexOf(n)+1)*(n.sortType==="A"?1:-1):n.sortType};var B=require("react"),eo=e=>{let{scrollLeft:t,scrollTop:n}=e,{clientHeight:o,clientWidth:r,scrollHeight:i,scrollWidth:s}=e,l=t/(s-r),c=n/(i-o);return[l,c,t,n]},Kr=e=>{let{clientHeight:t,clientWidth:n,scrollHeight:o,scrollWidth:r}=e;return[r-n,o-t]},to=({onRangeChange:e,rowHeight:t,viewport:n})=>{let o=(0,B.useRef)(null),r=(0,B.useRef)(null),i=(0,B.useRef)(null),s=(0,B.useRef)(!1),l=(0,B.useRef)(-1),{rowCount:c,maxScrollContainerScrollHorizontal:p,maxScrollContainerScrollVertical:m}=n,u=(0,B.useCallback)((h,x)=>{let{current:D}=i;D&&(D.scrollLeft=h,D.scrollTop=x)},[i]),d=(0,B.useCallback)(()=>{let{current:h}=i;if(h){let{scrollTop:x}=h,D=Math.floor(x/t);D!==l.current&&(l.current=D,e(D,D+c))}},[e,t,c]),C=(0,B.useCallback)(()=>{let{current:h}=r,{current:x}=o;if(h&&x){let[D,a,y,g]=eo(h);s.current=!0,x.scrollLeft=Math.round(D*p),x.scrollTop=Math.round(a*m),u(y,g)}},[p,m,r,o,u]),v=(0,B.useCallback)(()=>{let{current:h}=r,{current:x}=o,{current:D}=s;if(D)s.current=!1;else if(h&&x){let[a,y]=eo(x),[g,R]=Kr(h),H=Math.round(a*g),L=Math.round(y*R);h.scrollLeft=H,h.scrollTop=L,u(H,L)}},[r,o,u]),b=(0,B.useCallback)(h=>{let{current:x}=o;if(x){if(s.current=!1,h.type==="scroll-page"){let{clientHeight:D,scrollTop:a}=x,{direction:y}=h,g=y==="down"?D:-D;x.scrollTop=Math.min(Math.max(0,a+g),n.maxScrollContainerScrollVertical)}else if(h.type==="scroll-end"){let{direction:D}=h,a=D==="end"?n.maxScrollContainerScrollVertical:0;x.scrollTop=a}}},[n.maxScrollContainerScrollVertical]);return{onScrollbarContainerScroll:v,onContentContainerScroll:C,onTableContainerScroll:d,requestScroll:b,contentContainerRef:r,scrollbarContainerRef:o,tableContainerRef:i}};var vt=require("react"),Nr={fillerHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,scrollContentHeight:0,scrollbarSize:0,scrollContentWidth:0},Fr=e=>{let t=0,n=0,o=0;for(let r of e){let{pin:i,width:s}=r;i==="left"?t+=s:i==="right"?n+=s:o+=s}return{pinnedWidthLeft:t,pinnedWidthRight:n,unpinnedWidth:o}},no=({columns:e,headerHeight:t,rowCount:n,rowHeight:o,size:r})=>{let{pinnedWidthLeft:i,pinnedWidthRight:s,unpinnedWidth:l}=(0,vt.useMemo)(()=>Fr(e),[e]);return(0,vt.useMemo)(()=>{var p;if(r){let u=n*o,d=i+l+s,C=u+t-(((p=r==null?void 0:r.height)!=null?p:0)-t-15),v=d-r.width+i,b=(r.height-t)/o,h=Number.isInteger(b)?b+1:Math.ceil(b);return{fillerHeight:(n-h)*o,maxScrollContainerScrollHorizontal:v,maxScrollContainerScrollVertical:C,pinnedWidthLeft:i,pinnedWidthRight:s,rowCount:h,scrollContentHeight:t+u+15,scrollbarSize:15,scrollContentWidth:d}}else return Nr},[t,i,s,n,o,r,l])};var{KEY:oo,IS_EXPANDED:zr}=be.metadataKeys,$r={},ro=e=>e==null?"":typeof e=="string"?e:e.toString(),Br=({align:e="right",type:t})=>{var n;if(t===void 0||typeof t=="string")return ro;{let{alignOnDecimals:o=!1,decimals:r,zeroPad:i=!1}=(n=t.formatting)!=null?n:$r;return s=>{if(typeof s=="string"&&(s.startsWith("\u03A3")||s.startsWith("[")))return s;let l=typeof s=="number"?s:typeof s=="string"?parseFloat(s):void 0;return(0,be.roundDecimal)(l,e,r,i,o)}}},Or=e=>{let{serverDataType:t}=e;return t==="string"||t==="char"?n=>n:t==="double"?Br(e):ro},so=({config:e,dataSource:t,headerHeight:n,onConfigChange:o,renderBufferSize:r=0,rowHeight:i,...s})=>{var P,T;let[l,c]=(0,F.useState)(0);if(t===void 0)throw Error("no data source provided to DataTable");let p=yt(s),m=(0,F.useCallback)(w=>{c(w)},[]),{columns:u,dispatchColumnAction:d}=Zn(e),C=no({columns:u,headerHeight:n,rowCount:l,rowHeight:i,size:p.innerSize}),v=(0,F.useCallback)(w=>{if(w.tableMeta){let{columns:S,dataTypes:U}=w.tableMeta;d({type:"setTypes",columnNames:S,serverDataTypes:U})}},[d]),b=(0,F.useMemo)(()=>u.reduce((w,S)=>(w[S.name]=Or(S),w),{}),[u]);(0,F.useMemo)(()=>{o==null||o({...e,columns:u})},[u,e,o]),(0,F.useMemo)(()=>{d({type:"init",config:e})},[e,d]);let h=(0,F.useCallback)(w=>{switch(w.type){case"groupBy":return d({type:"tableConfig",groupBy:w.groupBy});case"filter":return d({type:"tableConfig",filter:w.filter});case"sort":return d({type:"tableConfig",sort:w.sort})}},[d]),{data:x,range:D,setRange:a}=Nn({dataSource:t,onConfigChange:h,onSubscribed:v,onSizeChange:m,renderBufferSize:r,viewportRowCount:C.rowCount}),y=(0,F.useCallback)((w,S)=>{a({from:w,to:S})},[a]),g=(0,F.useCallback)((w,S=!1,U)=>{t&&(t.sort=(0,be.applySort)(t.sort,w,S,U))},[t]),R=(0,F.useCallback)((w,S,U)=>{let ie=u.find(he=>he.name===S);if(ie)d({type:"resizeColumn",phase:w,column:ie,width:U});else throw Error(`useDataTable.handleColumnResize, column ${S} not found`)},[u,d]),H=(0,F.useCallback)(w=>{t&&(w[zr]?t.closeTreeNode(w[oo]):t.openTreeNode(w[oo]))},[t]),L=(0,F.useCallback)(w=>{t&&t.groupBy.includes(w.name)&&(t.groupBy=t.groupBy.filter(S=>S!==w.name))},[t]),{requestScroll:E,...f}=to({onRangeChange:y,rowHeight:i,viewport:C,viewportHeight:((T=(P=p.innerSize)==null?void 0:P.height)!=null?T:0)-n}),M=Gn({columnCount:u.length,containerRef:p.containerRef,data:x,requestScroll:E,rowCount:t==null?void 0:t.size,viewportRange:D});return{containerMeasurements:p,containerProps:M,columns:u,data:x,dispatchColumnAction:d,onColumnResize:R,onRemoveColumnFromGroupBy:L,onSort:g,onToggleGroup:H,scrollProps:f,rowCount:l,valueFormatters:b,viewportMeasurements:C}};var io=require("@heswell/salt-lab"),X=require("react"),lo=({onDrop:e,tableContainerRef:t,tableLayout:n})=>{let[o,r]=(0,X.useState)(n),i=(0,X.useRef)(),s=(0,X.useCallback)(()=>{console.log("handleDropSettle"),i.current=void 0,r("row")},[]),{draggable:l,draggedItemIndex:c,onMouseDown:p}=(0,io.useDragDrop)({allowDragDrop:!0,draggableClassName:"table-column",orientation:"horizontal",containerRef:t,itemQuery:".vuuDataTable-table",onDrop:e,onDropSettle:s}),m=(0,X.useCallback)(u=>{let{clientX:d,clientY:C}=u;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let b=u.target.closest(".vuuTable-headerCell"),{dataset:{idx:h="-1"}}=b;i.current={clientX:d,clientY:C,idx:h},r("column")},[]);return(0,X.useLayoutEffect)(()=>{var u;if(o==="column"&&i.current&&!l){let{clientX:d,clientY:C,idx:v}=i.current,b=(u=t.current)==null?void 0:u.querySelector(`.vuuDataTable-table[data-idx="${v}"]`);if(b){let h={persist:()=>{},nativeEvent:{clientX:d,clientY:C,target:b}};p==null||p(h)}}},[l,p,t,o]),{draggable:l,draggedItemIndex:c,tableLayout:o,handleHeaderCellDragStart:m}};var W=require("react/jsx-runtime"),se="vuuDataTable",Gr=({allowConfigEditing:e=!1,className:t,config:n,dataSource:o,headerHeight:r=25,height:i,id:s,onConfigChange:l,onShowConfigEditor:c,renderBufferSize:p=0,rowHeight:m=20,style:u,tableLayout:d="row",width:C,...v})=>{let b=(0,Ve.useIdMemo)(s),{columns:h,dispatchColumnAction:x,containerMeasurements:{containerRef:D,innerSize:a,outerSize:y},containerProps:g,rowCount:R,scrollProps:H,valueFormatters:L,viewportMeasurements:E,...f}=so({config:n,dataSource:o,renderBufferSize:p,headerHeight:r,height:i,onConfigChange:l,rowHeight:m,width:C}),M=Hn({dataSource:o,dispatchColumnAction:x}),P=(0,uo.useCallback)((le,Ce)=>{let We=h[le];x({type:"moveColumn",column:We,moveTo:Ce})},[h,x]),{draggable:T,draggedItemIndex:w,tableLayout:S,handleHeaderCellDragStart:U}=lo({onDrop:P,tableContainerRef:H.tableContainerRef,tableLayout:d}),ie={...y,"--content-height":`${E.scrollContentHeight}px`,"--content-width":`${E.scrollContentWidth}px`,"--filler-height":`${E.fillerHeight}px`,"--pinned-width-left":`${E.pinnedWidthLeft}px`,"--pinned-width-right":`${E.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${m}px`,"--scrollbar-size":`${E.scrollbarSize}px`,"--table-height":`${a==null?void 0:a.height}px`,"--table-width":`${a==null?void 0:a.width}px`},he={left:E.pinnedWidthLeft-1,top:r-1},Re=S==="column"?Tn:An;return(0,W.jsx)(Jt,{menuActionHandler:M,menuBuilder:Pn(o),children:(0,W.jsxs)("div",{...g,className:se,id:b,ref:D,style:ie,tabIndex:-1,children:[a?(0,W.jsx)("div",{className:`${se}-scrollbarContainer`,onScroll:H.onScrollbarContainerScroll,ref:H.scrollbarContainerRef,style:he,children:(0,W.jsx)("div",{className:`${se}-scrollContent`})}):null,a?(0,W.jsxs)("div",{className:`${se}-contentContainer`,onScroll:H.onContentContainerScroll,ref:H.contentContainerRef,...v,children:[(0,W.jsx)("div",{className:`${se}-scrollContent`}),(0,W.jsx)("div",{className:`${se}-tableContainer`,onScroll:H.onTableContainerScroll,ref:H.tableContainerRef,children:(0,W.jsx)(Re,{...f,columns:h.filter((le,Ce)=>Ce!==w),headerHeight:r,onHeaderCellDragStart:S==="row"?U:void 0,rowHeight:m,valueFormatters:L})}),T]}):null,e&&a?(0,W.jsx)(Ve.Button,{className:`${se}-settings`,"data-icon":"settings",onClick:c,variant:"secondary"}):null]})})};
1
+ "use strict";var Cp=Object.create;var Ss=Object.defineProperty;var xp=Object.getOwnPropertyDescriptor;var Sp=Object.getOwnPropertyNames;var kp=Object.getPrototypeOf,Mp=Object.prototype.hasOwnProperty;var Tp=(i,e)=>{for(var t in e)Ss(i,t,{get:e[t],enumerable:!0})},Oa=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Sp(e))!Mp.call(i,s)&&s!==t&&Ss(i,s,{get:()=>e[s],enumerable:!(n=xp(e,s))||n.enumerable});return i};var Pe=(i,e,t)=>(t=i!=null?Cp(kp(i)):{},Oa(e||!i||!i.__esModule?Ss(t,"default",{value:i,enumerable:!0}):t,i)),Ap=i=>Oa(Ss({},"__esModule",{value:!0}),i);var Va=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var U=(i,e,t)=>(Va(i,e,"read from private field"),t?t.call(i):e.get(i)),ie=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)},_=(i,e,t,n)=>(Va(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);var nw={};Tp(nw,{DataTable:()=>tw,useMeasuredContainer:()=>Ta});module.exports=Ap(nw);var eo=require("@heswell/salt-lab"),Pp=require("@salt-ds/core"),Op=Pe(require("classnames")),to=require("react");var Wi=require("react"),Fa=Pe(require("react-dom"));var Ia=Pe(require("react-dom")),La=require("@salt-ds/core"),Ba=require("react/jsx-runtime"),Rp=1,Ep=(i=0,e=0,t=window)=>{let n=t.document.createElement("div");return n.className="vuuPopup "+Rp++,n.style.cssText=`left:${i}px; top:${e}px;`,t.document.body.appendChild(n),n},Dp=(i,e)=>Ep(i,e),ks=(i,e,t,n,s)=>{e.style.cssText=`left:${t}px; top:${n}px;position: absolute;`,Ia.render((0,Ba.jsx)(La.SaltProvider,{applyClassesTo:"child",children:i}),e,s)},Na=Dp;var Zr=function({children:e,x:t=0,y:n=0,onRender:s}){let r=(0,Wi.useMemo)(()=>Na(),[]);return(0,Wi.useLayoutEffect)(()=>{ks(e,r,t,n,s)},[e,s,r,t,n]),(0,Wi.useLayoutEffect)(()=>()=>{var o;r&&(Fa.unmountComponentAtNode(r),r.classList.contains("vuuPopup")&&((o=r.parentElement)==null||o.removeChild(r)))},[r]),null};var Ha=require("react/jsx-runtime");var iu=require("@salt-ds/core"),yn=require("react");var Ut=Pe(require("react")),io=Pe(require("classnames")),Qa=require("@salt-ds/core");var qe=require("react");var Wa=i=>i.closest("[data-root='true']")!==null,_a=(i,e)=>{var t;return i.ariaHasPopup==="true"&&((t=i.dataset)==null?void 0:t.idx)===`${e}`||i.querySelector(`:scope > [data-idx='${e}'][aria-haspopup='true']`)!==null};function Vp(i,...e){let t=new Set(i);for(let n of e)for(let s of n)t.add(s);return t}var Ip="Enter";var Lp="Delete",Np=new Set([Ip,Lp]),Bp=new Set(["Tab"]),Fp=new Set(["ArrowRight","ArrowLeft"]),$a=new Set(["Home","End","ArrowDown","ArrowUp"]),za=new Set(["Home","End","ArrowRight","ArrowLeft"]),Hp=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),Mw=Vp(Np,za,$a,Fp,Hp,Bp);var Ua=({key:i},e="vertical")=>(e==="vertical"?$a:za).has(i);var Ka=({autoHighlightFirstItem:i=!1,count:e,highlightedIndex:t,onActivate:n,onHighlight:s,onCloseMenu:r,onOpenMenu:o})=>{let l=(0,qe.useRef)((t!=null?t:i)?0:-1),[,a]=(0,qe.useState)(null),u=t!==void 0,h=(0,qe.useCallback)(C=>{l.current=C,s==null||s(C),a({})},[s]),c=(0,qe.useCallback)(C=>{C!==l.current&&(u||h(C))},[u,h]),f=(0,qe.useRef)(!0),d=(0,qe.useRef)(!1),m=C=>d.current=C,b=u?t:l.current,y=(0,qe.useCallback)(C=>{let T=Wp(e,C.key,l.current);T!==l.current&&c(T)},[e,c]),v=(0,qe.useCallback)(C=>{Ua(C)?(C.preventDefault(),C.stopPropagation(),f.current=!0,y(C)):(C.key==="ArrowRight"||C.key==="Enter")&&_a(C.target,b)?o(b):C.key==="ArrowLeft"&&!Wa(C.target)?r(b):C.key==="Enter"&&n&&n(b)},[b,y,n,r,o]),A=(0,qe.useMemo)(()=>({onFocus:()=>{b===-1&&h(0)},onKeyDown:v,onMouseDownCapture:()=>{f.current=!1,m(!0)},onMouseMove:()=>{f.current&&(f.current=!1)},onMouseLeave:()=>{f.current=!0,m(!1),c(-1)}}),[b,c,y,n,r,o,h]);return{focusVisible:f.current?b:-1,controlledHighlighting:u,highlightedIndex:b,setHighlightedIndex:c,listProps:A,setIgnoreFocus:m}};function Wp(i,e,t){return e==="ArrowUp"?t>0?t-1:t:t===null?0:t===i-1?t:t+1}var bn=Pe(require("react"));var no=i=>i.type===Ms||!!i.props["data-group"],Ga=i=>{let e=(0,bn.useCallback)(()=>{let s=(o,l="root",a={},u={})=>{let h=a[l]=[],c=0,f=!1;return bn.default.Children.forEach(o,d=>{if(d.type===qa)f=!0;else{let m=no(d),b=l==="root"?`${c}`:`${l}.${c}`,{props:{action:y,options:v}}=d,{childWithId:A,grandChildren:C}=r(d,b,m,f);h.push(A),C?s(C,b,a,u):u[b]={action:y,options:v},c+=1,f=!1}}),[a,u]},r=(o,l,a,u=!1)=>{let{props:{children:h}}=o;return{childWithId:bn.default.cloneElement(o,{hasSeparator:u,id:`${l}`,key:l,children:a?void 0:h}),grandChildren:a?h:void 0}};return s(i)},[i]),[t,n]=(0,bn.useMemo)(()=>e(),[e]);return[t,n]};var qn=require("react/jsx-runtime"),ja="vuuMenuList",qa=()=>(0,qn.jsx)("li",{className:"vuuMenuItem-divider"}),Ms=()=>null,so=({children:i,idx:e,...t})=>(0,qn.jsx)("div",{...t,children:i}),_p=i=>i.props["data-icon"],Ja=({activatedByKeyboard:i,childMenuShowing:e=-1,children:t,className:n,highlightedIdx:s,id:r,isRoot:o,listItemProps:l,menuId:a,onHighlightMenuItem:u,onActivate:h,onCloseMenu:c,onOpenMenu:f,...d})=>{let m=(0,Qa.useIdMemo)(r),b=(0,Ut.useRef)(null),y=(0,Ut.useMemo)(()=>new Map,[]),v=B=>{var D;let M=(D=b.current)==null?void 0:D.querySelector(`:scope > [data-idx='${B}']`);M!=null&&M.id&&(f==null||f(M.id))},A=B=>{var D;let M=(D=b.current)==null?void 0:D.querySelector(`:scope > [data-idx='${B}']`);M!=null&&M.id&&(h==null||h(M.id))},{focusVisible:C,highlightedIndex:T,listProps:x}=Ka({count:Ut.default.Children.count(t),highlightedIndex:s,onActivate:A,onHighlight:u,onOpenMenu:v,onCloseMenu:c}),R=e==-1?C:-1;return(0,Ut.useLayoutEffect)(()=>{var B;e===-1&&i&&((B=b.current)==null||B.focus())},[i,e]),(0,qn.jsx)("div",{...d,...x,"aria-activedescendant":(()=>T===void 0||T===-1?void 0:y.get(T))(),className:(0,io.default)(ja,n,{[`${ja}-childMenuShowing`]:e!==-1}),"data-root":o||void 0,id:`${m}-${a}`,ref:b,role:"menu",tabIndex:0,children:z()});function z(){let B={...l,role:"menuitem"},M=(N,Q,K)=>Q?[(0,qn.jsx)("span",{className:"vuuIconContainer","data-icon":K},"icon")].concat(N):N;function D(N,Q,K,oe){var be;let{children:ke,className:te,"data-icon":ve,id:ge,hasSeparator:Le,label:Ne,...Ye}=Q.props,at=no(Q),pn=at&&e===K,Y=pn?`${m}-${ge}`:void 0;N.push((0,qn.jsx)(so,{...Ye,...B,...$p(`${m}-${a}`,ge,K,(be=Q.key)!=null?be:ge,T,R,te,Le),"aria-controls":Y,"aria-haspopup":at||void 0,"aria-expanded":pn||void 0,children:M(at?Ne:ke,oe,ve)}))}let H=[];if(t.length>0){let N=t.some(_p);t.forEach((Q,K)=>{D(H,Q,K,N)})}return H}},$p=(i,e,t,n,s,r,o,l)=>({id:`${i}-${e}`,key:n!=null?n:t,"data-idx":t,"data-highlighted":t===s||void 0,className:(0,io.default)("vuuMenuItem",o,{"vuuMenuItem-separator":l,focusVisible:r===t})});Ja.displayName="MenuList";var Xa=Ja;var Ae=require("react");function Ya(i){if(i){let e=i.dataset.idx;if(e)return parseInt(e,10);if(i.ariaPosInSet)return parseInt(i.ariaPosInSet,10)-1}}var ro=i=>i==null?void 0:i.closest("[data-idx],[aria-posinset]");var Za=(i,e,t)=>i.map((n,s)=>s===i.length-1?{...n,[t]:n[t]-e}:n),zp=(i,e)=>Za(i,e,"left"),Up=(i,e)=>Za(i,e,"top"),Kp=(i,e)=>{let[t,n]=e.slice(-2),s=document.getElementById(`${i}-${n.id}`);if(s===null)throw Error(`useCascade.flipSides element with id ${n.id} not found`);let{width:r}=s.getBoundingClientRect();return e.map(o=>o===n?{...o,left:t.left-(r-2)}:o)},Gp=(i,e)=>{let[{left:t,top:n}]=e.slice(-1),{offsetWidth:s,offsetTop:r}=i;return{left:t+s,top:r+n}},_i=i=>{let e=i.lastIndexOf("-");return e===-1?i:i.slice(e+1)},Ts=i=>{let e=_i(i),t=e.lastIndexOf(".");return t>-1?e.slice(0,t):"root"},qp=i=>{let e=0,t=i.indexOf(".",0);for(;t!==-1;)e+=1,t=i.indexOf(".",t+1);return e},jp=i=>({menuId:Ts(i.id),itemId:_i(i.id),isGroup:i.ariaHasPopup==="true",isOpen:i.ariaExpanded==="true",level:qp(i.id)}),eu=({id:i,onActivate:e,onMouseEnterItem:t,position:{x:n,y:s}})=>{let[,r]=(0,Ae.useState)({}),o=(0,Ae.useRef)([{id:"root",left:n,top:s}]),l=(0,Ae.useCallback)(C=>{o.current=C,r({})},[]),a=(0,Ae.useRef)(),u=(0,Ae.useRef)(),h=(0,Ae.useRef)({root:"no-popup"}),c=(0,Ae.useRef)(0),f=(0,Ae.useCallback)((C="root",T=null,x=null)=>{if(C==="root"&&T===null)l([{id:"root",left:n,top:s}]);else{h.current[C]="popup-open";let L=(x?x.ownerDocument:document).getElementById(`${i}-${C}-${T}`),{left:z,top:B}=Gp(L,o.current);l(o.current.concat({id:T,left:z,top:B}))}},[i,n,s,l]),d=(0,Ae.useCallback)(C=>{l(C==="root"?[]:o.current.slice(0,-1))},[l]),m=(0,Ae.useCallback)((C,T)=>{let x=o.current.slice(),{id:R}=x[x.length-1];for(;x.length>1&&!T.startsWith(R);){let L=Ts(R);x.pop(),h.current[R]="no-popup",h.current[L]="no-popup",{id:R}=x[x.length-1]}x.length<o.current.length&&l(x)},[l]),b=(0,Ae.useCallback)((C,T,x)=>{a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{console.log(`scheduleOpen timed out opening ${T}`),m(C,T),h.current[C]="popup-open",h.current[T]="no-popup",f(C,T,x)},400)},[m,f]),y=(0,Ae.useCallback)((C,T,x)=>{console.log(`scheduleClose openMenuId ${C} menuId ${T} itemId ${x}`),h.current[C]="pending-close",u.current=window.setTimeout(()=>{m(T,x)},400)},[m]),v=(0,Ae.useCallback)(()=>{let{current:C}=o,[T]=C.slice(-1),x=document.getElementById(`${i}-${T.id}`);if(x){let{right:R,bottom:L}=x.getBoundingClientRect(),{clientHeight:z,clientWidth:B}=document.body;if(R>B){let M=C.length>1?Kp(i,C):zp(C,R-B);l(M)}else if(L>z){let M=Up(C,L-z);l(M)}}},[i,l]),A=(0,Ae.useMemo)(()=>({onMouseEnter:C=>{let T=ro(C.target),{menuId:x,itemId:R,isGroup:L,isOpen:z,level:B}=jp(T),M=c.current===B,{current:{[x]:D}}=h;if(c.current=B,D==="no-popup"&&L)h.current[x]="popup-pending",b(x,R,T);else if(D==="popup-pending"&&!L)h.current[x]="no-popup",clearTimeout(a.current),a.current=void 0;else if(D==="popup-pending"&&L)clearTimeout(a.current),b(x,R,T);else if(D==="popup-open"){let[{id:H},{id:N}]=o.current.slice(-2);H===x&&h.current[N]!=="pending-close"&&M?(y(N,x,R),L&&!z&&b(x,R,T)):H===x&&L&&R!==N&&h.current[N]==="pending-close"?b(x,R,T):L?(m(x,R),b(x,R,T)):h.current[N]==="pending-close"&&M||m(x,R)}D==="pending-close"&&(a.current&&(clearTimeout(a.current),a.current=void 0),clearTimeout(u.current),u.current=void 0,h.current[x]="popup-open"),t(C,R)},onClick:C=>{let T=C.target,x=ro(T),R=Ya(x);console.log(`list item click [${R}] hasPopup ${x.ariaHasPopup}`),x.ariaHasPopup==="true"?x.ariaExpanded!=="true"&&f(R):e(_i(x.id))}}),[m,e,t,f,y,b]);return{closeMenu:d,handleRender:v,listItemProps:A,openMenu:f,openMenus:o.current}};var tu=require("react"),nu=({containerClassName:i,isOpen:e,onClose:t})=>{(0,tu.useEffect)(()=>{let n;return e&&(n=s=>{s.target.closest(`.${i}`)===null&&(t==null||t("root"))},document.body.addEventListener("click",n,!0)),()=>{n&&document.body.removeEventListener("click",n,!0)}},[i,e,t])};var $i=require("react/jsx-runtime"),su=require("react"),Qp=()=>{},oo=({activatedByKeyboard:i,children:e,className:t,id:n,onClose:s=()=>{},position:r={x:0,y:0},style:o,...l})=>{let a=(0,iu.useIdMemo)(n),u=(0,yn.useRef)(Qp),[h,c]=Ga(e),f=(0,yn.useRef)(i),d=(0,yn.useCallback)(()=>{f.current=!1},[]),m=(0,yn.useCallback)(M=>{let{action:D,options:H}=c[M];u.current("root"),s(D,H)},[c,s]),{closeMenu:b,listItemProps:y,openMenu:v,openMenus:A,handleRender:C}=eu({id:a,onActivate:m,onMouseEnterItem:d,position:r});u.current=b,console.log({openMenus:A});let T=(0,yn.useCallback)(()=>{b(),s()},[b,s]);nu({containerClassName:"vuuMenuList",onClose:T,isOpen:A.length>0});let x=M=>{let D=_i(M),H=Ts(D);f.current=!0,v(H,D)},R=()=>{f.current=!0,b()},L=()=>{},z=A.length-1,B=M=>{if(M>=z)return-1;{let{id:D}=A[M+1],H=D.lastIndexOf(".");return parseInt(H===-1?D:D.slice(-H),10)}};return(0,$i.jsx)($i.Fragment,{children:A.map(({id:M,left:D,top:H},N)=>{let Q=B(N);return(0,$i.jsx)(Zr,{x:D,y:H,onRender:C,children:(0,su.createElement)(Xa,{...l,activatedByKeyboard:f.current,childMenuShowing:Q,className:t,id:a,menuId:M,isRoot:N===0,key:N,listItemProps:y,onActivate:m,onHighlightMenuItem:L,onCloseMenu:R,onOpenMenu:x,style:o},h[M])},N)})})};oo.displayName="ContextMenu";var jn=require("react"),As=require("react/jsx-runtime"),Rs=(0,jn.createContext)(null),ru=i=>"children"in i,Jp=({children:i,context:e,menuActionHandler:t,menuBuilder:n})=>{let s=(0,jn.useMemo)(()=>e!=null&&e.menuBuilders&&n?e.menuBuilders.concat(n):n?[n]:(e==null?void 0:e.menuBuilders)||[],[e,n]),r=(0,jn.useCallback)((o,l)=>{var a;if(t!=null&&t(o,l)||(a=e==null?void 0:e.menuActionHandler)!=null&&a.call(e,o,l))return!0},[e,t]);return(0,As.jsx)(Rs.Provider,{value:{menuActionHandler:r,menuBuilders:s},children:i})},ou=({children:i,label:e,menuActionHandler:t,menuBuilder:n})=>(0,As.jsx)(Rs.Consumer,{children:s=>(0,As.jsx)(Jp,{context:s,label:e,menuActionHandler:t,menuBuilder:n,children:i})});var zi=require("react");var lu=Pe(require("classnames")),Qn=Pe(require("react")),Es=Pe(require("react-dom"));var lo=!1,ut=[];function au(i){if(i.key==="Esc"){if(ut.length)hu();else if(lo){let e=document.body.querySelector(".vuuDialog");e&&Es.default.unmountComponentAtNode(e)}}}function uu(i){if(ut.length){let e=document.body.querySelectorAll(".vuuPopup");for(let t=0;t<e.length;t++)if(e[t].contains(i.target))return;hu()}}function hu(){if(ut.length){let i=document.body.querySelectorAll(".vuuPopup");for(let e=0;e<i.length;e++)Es.default.unmountComponentAtNode(i[e]);cu("*")}}function Xp(i){ut.indexOf(i)===-1&&(ut.push(i),lo===!1&&(window.addEventListener("keydown",au,!0),window.addEventListener("click",uu,!0)))}function cu(i){if(ut.length){if(i==="*")ut.length=0;else{let e=ut.indexOf(i);e!==-1&&ut.splice(e,1)}ut.length===0&&lo===!1&&(window.removeEventListener("keydown",au,!0),window.removeEventListener("click",uu,!0))}}var Yp=({children:i,position:e,style:t})=>{let n=(0,lu.default)("hwPopup","hwPopupContainer",e);return(0,Qn.createElement)("div",{className:n,style:t},i)},Zp=1,wn=class{static showPopup({name:e="anon",group:t="all",position:n="",left:s=0,right:r="auto",top:o=0,width:l="auto",component:a}){if(!a)throw Error("PopupService showPopup, no component supplied");Xp(e);let u=document.body.querySelector(".vuuPopup."+t);u===null&&(u=document.createElement("div"),u.className="vuuPopup "+t,document.body.appendChild(u));let h={width:l};ks((0,Qn.createElement)(Yp,{key:Zp++,position:n,style:h},a),u,s,o,()=>{wn.keepWithinThePage(u,r)})}static hidePopup(e="anon",t="all"){if(ut.indexOf(e)!==-1){cu(e);let n=document.body.querySelector(`.vuuPopup.${t}`);n&&Es.default.unmountComponentAtNode(n)}}static keepWithinThePage(e,t="auto"){let n=e.querySelector(".vuuPopupContainer > *");if(n){let{top:s,left:r,width:o,height:l,right:a}=n.getBoundingClientRect(),u=window.innerWidth,c=window.innerHeight-(s+l);c<0&&(n.style.top=Math.round(s)+c+"px");let f=u-(r+o);if(f<0&&(n.style.left=Math.round(r)+f+"px"),typeof t=="number"&&t!==a){let d=t-a;n.style.left=r+d+"px"}}}};var Ds=require("react/jsx-runtime"),Jn=()=>{let i=(0,zi.useContext)(Rs),e=(0,zi.useCallback)((n,s,r)=>{let o=[];for(let l of n)o=o.concat(l(s,r));return o},[]);return(0,zi.useCallback)((n,s,r)=>{var a;n.stopPropagation(),n.preventDefault();let o=(a=i==null?void 0:i.menuBuilders)!=null?a:[],l=e(o,s,r);console.log({menuItemDescriptors:l}),l.length&&(i!=null&&i.menuActionHandler)&&(console.log(`showContextMenu ${s}`,{options:r}),em(n,l,i.menuActionHandler))},[e,i])},em=(i,e,t)=>{let{clientX:n,clientY:s}=i,l=(0,Ds.jsx)(oo,{onClose:(a,u)=>{a&&(t(a,u),wn.hidePopup())},position:{x:n,y:s},children:(a=>{let u=(h,c)=>ru(h)?(0,Ds.jsx)(Ms,{label:h.label,children:h.children.map(u)},c):(0,Ds.jsx)(so,{action:h.action,"data-icon":h.icon,options:h.options,children:h.label},c);return a.map(u)})(e)});wn.showPopup({left:0,top:0,component:l})};var Jr=require("@salt-ds/core"),Xd=require("react");var Eu=require("@vuu-ui/vuu-utils"),Du=require("react"),Pu=Pe(require("classnames"));var Yn=require("@vuu-ui/vuu-utils"),yu=Pe(require("classnames")),Ki=require("react");var Ps=require("@vuu-ui/vuu-utils"),du=require("@heswell/salt-lab"),pu=Pe(require("classnames")),vn=require("react");var Ui=require("react/jsx-runtime"),{KEY:fu}=Ps.metadataKeys,ao=(0,vn.memo)(({className:i,column:e,row:t})=>{let n=(0,vn.useRef)(null),{align:s,CellRenderer:r,key:o,pin:l,editable:a,resizing:u,valueFormatter:h}=e,[c,f]=(0,vn.useState)(!1),d=h(t[o]),[m,b]=(0,vn.useState)(d),y=()=>{var R;(R=n.current)==null||R.focus()},v=R=>{R.key==="Enter"&&f(!0)},A=()=>{f(!0)},C=(R="",L="",z=!0,B=!1)=>{var M;f(!1),B?b(R):L!==R&&b(L),z===!1&&((M=n.current)==null||M.focus())},T=(0,pu.default)(i,{vuuAlignRight:s==="right",vuuPinFloating:l==="floating",vuuPinLeft:l==="left",vuuPinRight:l==="right","vuuTableCell-resizing":u})||void 0,x=(0,Ps.getColumnPinStyle)(e);return a?(0,Ui.jsx)("td",{className:T,"data-editable":!0,style:x,onKeyDown:v,children:(0,Ui.jsx)(du.EditableLabel,{editing:c,value:m,onChange:b,onMouseDownCapture:y,onEnterEditMode:A,onExitEditMode:C,onKeyDown:v,ref:n,tabIndex:0},"title")}):(0,Ui.jsx)("td",{className:T,style:x,children:r?(0,Ui.jsx)(r,{column:e,row:t}):d})},tm);ao.displayName="TableCell";function tm(i,e){return i.column===e.column&&i.row[fu]===e.row[fu]&&i.row[i.column.key]===e.row[e.column.key]}var mu=require("@vuu-ui/vuu-utils");var Xn=require("react/jsx-runtime"),{DEPTH:nm,IS_LEAF:gu}=mu.metadataKeys,im=(i,e)=>{let{[nm]:t,[gu]:n}=e;if(n||t>i.length)return[null,t===null?0:t-1];if(t===0)return["$root",0];{let s=i[t-1];return[e[s.key],t-1]}},bu=({column:i,onClick:e,row:t})=>{let{columns:n}=i,[s,r]=im(n,t),o={left:i.pin=="left"?i.pinnedOffset:void 0},l=t[gu],a=Array(r).fill(0).map((u,h)=>(0,Xn.jsx)("span",{className:"vuuTableGroupCell-spacer"},h));return(0,Xn.jsxs)("td",{className:"vuuTableGroupCell vuuPinLeft",onClick:l?void 0:e,style:o,children:[a,l?null:(0,Xn.jsx)("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),(0,Xn.jsx)("span",{children:s})]})};var uo=require("react/jsx-runtime"),{IDX:sm,IS_EXPANDED:rm,SELECTED:om}=Yn.metadataKeys,Os="vuuDataTableRow",Vs=(0,Ki.memo)(function({columns:e,height:t,index:n,onClick:s,onToggleGroup:r,row:o}){let{[sm]:l,[rm]:a,[om]:u}=o,h=(0,yu.default)(Os,{[`${Os}-even`]:l%2===0,[`${Os}-expanded`]:a,[`${Os}-preSelected`]:u===2}),c=l-n,f=(0,Ki.useCallback)(m=>{let b=m.shiftKey,y=m.ctrlKey||m.metaKey;s==null||s(n,o,b,y)},[n,s,o]),d=(0,Ki.useCallback)(()=>r==null?void 0:r(o),[r,o]);return(0,uo.jsx)("tr",{"aria-selected":u===1?!0:void 0,"data-idx":l,className:h,onClick:f,style:{transform:`translate3d(0px, ${c*t}px, 0px)`},children:e.filter(Yn.notHidden).map(m=>{let b=(0,Yn.isGroupColumn)(m);return(0,uo.jsx)(b?bu:ao,{column:m,onClick:b?d:void 0,row:o},m.name)})})});var Au=Pe(require("classnames")),Sn=require("react");var Zn=require("react");var vu=require("react/jsx-runtime"),wu=()=>{},lm="vuuColumnResizer",Is=({onDrag:i,onDragEnd:e=wu,onDragStart:t=wu})=>{let n=(0,Zn.useRef)(0),s=(0,Zn.useCallback)(l=>{l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault();let a=Math.round(l.clientX),u=a-n.current;n.current=a,u!==0&&i(l,u)},[i]),r=(0,Zn.useCallback)(l=>{window.removeEventListener("mouseup",r),window.removeEventListener("mousemove",s),e(l)},[e,s]),o=(0,Zn.useCallback)(l=>{t(l),n.current=Math.round(l.clientX),window.addEventListener("mouseup",r),window.addEventListener("mousemove",s),l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault()},[t,s,r]);return(0,vu.jsx)("div",{className:lm,onMouseDown:o})};var ho=Pe(require("classnames"));var Cn=require("react/jsx-runtime"),Cu="vuuSortIndicator",xu=({sorted:i})=>{if(!i)return null;let e=typeof i=="number"?i<0?"dsc":"asc":i==="A"?"asc":"dsc";return typeof i=="number"?(0,Cn.jsxs)("div",{className:(0,ho.default)(Cu,"multi-col",e),children:[(0,Cn.jsx)("span",{"data-icon":`sorted-${e}`}),(0,Cn.jsx)("span",{className:"vuuSortPosition",children:Math.abs(i)})]}):(0,Cn.jsx)("div",{className:(0,ho.default)(Cu,"single-col"),children:(0,Cn.jsx)("span",{"data-icon":`sorted-${e}`})})};var xn=require("react"),Ls=({column:i,onResize:e,rootRef:t})=>{let n=(0,xn.useRef)(0),s=(0,xn.useRef)(!1),{name:r}=i,o=(0,xn.useCallback)(()=>{if(e&&t.current){let{width:u}=t.current.getBoundingClientRect();n.current=Math.round(u),s.current=!0,e==null||e("begin",r)}},[r,e,t]),l=(0,xn.useCallback)((u,h)=>{if(t.current&&e){let{width:c}=t.current.getBoundingClientRect(),f=Math.round(c)+h;f!==n.current&&f>0&&(e("resize",r,f),n.current=f)}},[r,e,t]),a=(0,xn.useCallback)(()=>{e&&(e("end",r,n.current),s.current=!1)},[r,e]);return{isResizing:s.current,onDrag:l,onDragStart:o,onDragEnd:a}};var Su=Pe(require("classnames")),ku=require("react");var Tu=require("react/jsx-runtime");var Mu=({column:i,filter:e})=>{let t=Jn(),n=(0,ku.useCallback)(s=>{s.stopPropagation(),t(s,"filter",{column:i,filter:e})},[i,e,t]);return i.filter?(0,Tu.jsx)("div",{className:(0,Su.default)("vuuFilterIndicator"),"data-icon":"filter",onClick:n}):null};var Kt=require("react/jsx-runtime"),Gi="vuuTable-headerCell",Ns=({column:i,className:e,onClick:t,onDragStart:n,onResize:s,...r})=>{let o=(0,Sn.useRef)(null),{isResizing:l,...a}=Ls({column:i,onResize:s,rootRef:o}),u=Jn(),h=(0,Sn.useRef)(null),c=y=>{u(y,"header",{column:i})},f=(0,Sn.useCallback)(y=>!l&&(t==null?void 0:t(y)),[l,t]),d=(0,Sn.useCallback)(y=>{h.current=window.setTimeout(()=>{n==null||n(y),h.current=null},250)},[n]),m=(0,Sn.useCallback)(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),b=(0,Au.default)(Gi,e,{vuuPinFloating:i.pin==="floating",vuuPinLeft:i.pin==="left",vuuPinRight:i.pin==="right",vuuEndPin:i.endPin,[`${Gi}-resizing`]:i.resizing,[`${Gi}-right`]:i.align==="right"});return(0,Kt.jsx)("th",{className:b,...r,onClick:f,onContextMenu:c,onMouseDown:d,onMouseUp:m,ref:o,children:(0,Kt.jsxs)("div",{className:`${Gi}-inner`,children:[(0,Kt.jsx)(Mu,{column:i}),(0,Kt.jsx)("div",{className:`${Gi}-label`,children:i.label}),(0,Kt.jsx)(xu,{sorted:i.sorted}),i.resizeable!==!1?(0,Kt.jsx)(Is,{...a}):null]})})};var ht=require("react/jsx-runtime"),Ru="vuuDataTable",{RENDER_IDX:am}=Eu.metadataKeys,Ou=({columns:i,data:e,headerHeight:t,onHeaderCellDragEnd:n,rowHeight:s})=>{let r=(0,Du.useCallback)(()=>{n==null||n()},[n]);return console.log("ColumnBasedTable render"),(0,ht.jsx)(ht.Fragment,{children:i.map((o,l)=>(0,ht.jsx)("table",{className:(0,Pu.default)(`${Ru}-table`,`${Ru}-columnBased`,{vuuPinLeft:o.pin==="left"}),"data-idx":l,id:`col-${l}`,style:{width:o.width,left:o.pinnedOffset,"--vuuTableHeaderHeight":`${t}px`,"--row-height":`${s}px`},children:(0,ht.jsxs)("tbody",{children:[(0,ht.jsx)("tr",{children:(0,ht.jsx)(Ns,{column:o,"data-idx":l,onDragEnd:r},l)},"header"),e.map((a,u)=>(0,ht.jsx)(Vs,{columns:[o],height:s,index:u,row:a},a[am])),(0,ht.jsx)("tr",{className:"vuuTable-filler"})]})},o.name))})};var Vu=require("@vuu-ui/vuu-utils"),Iu=i=>(e,t)=>{let n=[];if(i===void 0)return n;if(e==="header")n.push(...um(t,i)),n.push(...fm(t,i)),n.push(...hm(t,i)),n.push(...cm(t));else if(e==="filter"){let{column:s,filter:r}=t,o=(r==null?void 0:r.column)===(s==null?void 0:s.name);n.push({label:"Edit filter",action:"filter-edit",options:t}),n.push({label:"Remove filter",action:"filter-remove-column",options:t}),s&&!o&&n.push({label:"Remove all filters",action:"remove-filters",options:t})}return n};function um(i,{sort:{sortDefs:e}}){let{column:t}=i,n=[];if(t===void 0)return n;let s=e.length>0;return t.sorted==="A"?n.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:i}):t.sorted==="D"?n.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:i}):typeof t.sorted=="number"?(t.sorted>0?n.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:i}):n.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:i}),s&&Math.abs(t.sorted)<e.length&&n.push({label:"Remove from sort",action:"sort-remove",options:i}),n.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:i},{label:"Descending",action:"sort-dsc",options:i}]})):s?(n.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:i},{label:"Descending",action:"sort-add-dsc",options:i}]}),n.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:i},{label:"Descending",action:"sort-dsc",options:i}]})):n.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:i},{label:"Descending",action:"sort-dsc",options:i}]}),n}function hm(i,e){let{column:t}=i;if(t===void 0||e.groupBy.length===0)return[];let{name:n,label:s=n}=t;return[{label:`Aggregate ${s}`,children:[{label:"Count",action:"agg-count",options:i}].concat((0,Vu.isNumericColumn)(t)?[{label:"Sum",action:"agg-sum",options:i},{label:"Avg",action:"agg-avg",options:i},{label:"High",action:"agg-high",options:i},{label:"Low",action:"agg-low",options:i}]:[])}]}var mo=(i,e)=>({label:`Pin ${e}`,action:`column-pin-${e}`,options:i}),co=i=>mo(i,"left"),fo=i=>mo(i,"floating"),po=i=>mo(i,"right");function cm(i){let{column:e}=i;if(e===void 0)return[];let{pin:t}=e,n=[{label:"Hide column",action:"column-hide",options:i},{label:"Remove column",action:"column-remove",options:i}];return t===void 0?n.push({label:"Pin column",children:[co(i),fo(i),po(i)]}):t==="left"?n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[fo(i),po(i)]}):t==="right"?n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[co(i),fo(i)]}):t==="floating"&&n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[co(i),po(i)]}),n}function fm(i,{groupBy:e}){let{column:t}=i,n=[];if(t===void 0)return n;let{name:s,label:r=s}=t;return e.length===0?n.push({label:`Group by ${r}`,action:"group",options:i}):n.push({label:`Add ${r} to group by`,action:"group-add",options:i}),n}var F0=require("@salt-ds/core");var J=class{constructor(){}lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){let s=[];return this.decompose(0,e,s,2),n.length&&n.decompose(0,n.length,s,3),this.decompose(t,this.length,s,1),Ze.from(s,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let n=[];return this.decompose(e,t,n,0),Ze.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),s=new Tn(this),r=new Tn(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=n)return!0}}iter(e=1){return new Tn(this,e)}iterRange(e,t=this.length){return new Ws(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;n=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new _s(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?J.empty:e.length<=32?new ce(e):Ze.from(ce.split(e,[]))}},ce=class extends J{constructor(e,t=dm(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?n:l)>=e)return new bo(s,l,n,o);s=l+1,n++}}decompose(e,t,n,s){let r=e<=0&&t>=this.length?this:new ce(Lu(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=n.pop(),l=Hs(r.text,o.text.slice(),0,r.length);if(l.length<=32)n.push(new ce(l,o.length+r.length));else{let a=l.length>>1;n.push(new ce(l.slice(0,a)),new ce(l.slice(a)))}}else n.push(r)}replace(e,t,n){if(!(n instanceof ce))return super.replace(e,t,n);let s=Hs(this.text,Hs(n.text,Lu(this.text,0,e)),t),r=this.length+n.length-(t-e);return s.length<=32?new ce(s,r):Ze.from(ce.split(s,[]),r)}sliceString(e,t=this.length,n=`
2
+ `){let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=n),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],s=-1;for(let r of e)n.push(r),s+=r.length+1,n.length==32&&(t.push(new ce(n,s)),n=[],s=-1);return s>-1&&t.push(new ce(n,s)),t}},Ze=class extends J{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let n of e)this.lines+=n.lines}lineInner(e,t,n,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=n+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,n,s);s=l+1,n=a+1}}decompose(e,t,n,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let u=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!u?n.push(l):l.decompose(e-o,t-o,n,u)}o=a+1}}replace(e,t,n){if(n.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,n),u=this.lines-o.lines+a.lines;if(a.lines<u>>5-1&&a.lines>u>>5+1){let h=this.children.slice();return h[s]=a,new Ze(h,this.length-(t-e)+n.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
3
+ `){let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=n),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,n)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Ze))return 0;let n=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return n;let a=this.children[s],u=e.children[r];if(a!=u)return n+a.scanIdentical(u,t);n+=a.length+1}}static from(e,t=e.reduce((n,s)=>n+s.length+1,-1)){let n=0;for(let d of e)n+=d.lines;if(n<32){let d=[];for(let m of e)m.flatten(d);return new ce(d,t)}let s=Math.max(32,n>>5),r=s<<1,o=s>>1,l=[],a=0,u=-1,h=[];function c(d){let m;if(d.lines>r&&d instanceof Ze)for(let b of d.children)c(b);else d.lines>o&&(a>o||!a)?(f(),l.push(d)):d instanceof ce&&a&&(m=h[h.length-1])instanceof ce&&d.lines+m.lines<=32?(a+=d.lines,u+=d.length+1,h[h.length-1]=new ce(m.text.concat(d.text),m.length+1+d.length)):(a+d.lines>s&&f(),a+=d.lines,u+=d.length+1,h.push(d))}function f(){a!=0&&(l.push(h.length==1?h[0]:Ze.from(h,u)),u=-1,a=h.length=0)}for(let d of e)c(d);return f(),l.length==1?l[0]:new Ze(l,t)}};J.empty=new ce([""],0);function dm(i){let e=-1;for(let t of i)e+=t.length+1;return e}function Hs(i,e,t=0,n=1e9){for(let s=0,r=0,o=!0;r<i.length&&s<=n;r++){let l=i[r],a=s+l.length;a>=t&&(a>n&&(l=l.slice(0,n-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function Lu(i,e,t){return Hs(i,[""],e,t)}var Tn=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ce?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,s=this.nodes[n],r=this.offsets[n],o=r>>1,l=s instanceof ce?s.text.length:s.children.length;if(o==(t>0?l:0)){if(n==0)return this.done=!0,this.value="",this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
4
+ `,this;e--}else if(s instanceof ce){let a=s.text[o+(t<0?-1:0)];if(this.offsets[n]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ce?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Ws=class{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new Tn(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=n?s:t<0?s.slice(s.length-n):s.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},_s=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:s}=this.inner.next(e);return t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(J.prototype[Symbol.iterator]=function(){return this.iter()},Tn.prototype[Symbol.iterator]=Ws.prototype[Symbol.iterator]=_s.prototype[Symbol.iterator]=function(){return this});var bo=class{constructor(e,t,n,s){this.from=e,this.to=t,this.number=n,this.text=s}get length(){return this.to-this.from}},ei="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(i=>i?parseInt(i,36):1);for(let i=1;i<ei.length;i++)ei[i]+=ei[i-1];function pm(i){for(let e=1;e<ei.length;e+=2)if(ei[e]>i)return ei[e-1]<=i;return!1}function Nu(i){return i>=127462&&i<=127487}var Bu=8205;function _e(i,e,t=!0,n=!0){return(t?zu:mm)(i,e,n)}function zu(i,e,t){if(e==i.length)return e;e&&Uu(i.charCodeAt(e))&&Ku(i.charCodeAt(e-1))&&e--;let n=ti(i,e);for(e+=$s(n);e<i.length;){let s=ti(i,e);if(n==Bu||s==Bu||t&&pm(s))e+=$s(s),n=s;else if(Nu(s)){let r=0,o=e-2;for(;o>=0&&Nu(ti(i,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function mm(i,e,t){for(;e>0;){let n=zu(i,e-2,t);if(n<e)return n;e--}return 0}function Uu(i){return i>=56320&&i<57344}function Ku(i){return i>=55296&&i<56320}function ti(i,e){let t=i.charCodeAt(e);if(!Ku(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return Uu(n)?(t-55296<<10)+(n-56320)+65536:t}function $s(i){return i<65536?1:2}var yo=/\r\n?|\n/,ze=function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i}(ze||(ze={})),je=class{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(n,s,r),s+=r):s+=o,n+=r}}iterChangedRanges(e,t=!1){wo(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],s=this.sections[t++];s<0?e.push(n,s):e.push(s,n)}return new je(e)}composeDesc(e){return this.empty?e:e.empty?this:Gu(this,e)}mapDesc(e,t=!1){return e.empty?this:vo(this,e,t)}mapPos(e,t=-1,n=ze.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],u=s+l;if(a<0){if(u>e)return r+(e-s);r+=l}else{if(n!=ze.Simple&&u>=e&&(n==ze.TrackDel&&s<e&&u>e||n==ze.TrackBefore&&s<e||n==ze.TrackAfter&&u>e))return null;if(u>e||u==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=u}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let n=0,s=0;n<this.sections.length&&s<=t;){let r=this.sections[n++],o=this.sections[n++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+n+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new je(e)}static create(e){return new je(e)}},fe=class extends je{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return wo(this,(t,n,s,r,o)=>e=e.replace(s,s+(n-t),o),!1),e}mapDesc(e,t=!1){return vo(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;n.length<a;)n.push(J.empty);n.push(o?e.slice(r,r+o):J.empty)}r+=o}return new fe(t,n)}compose(e){return this.empty?e:e.empty?this:Gu(this,e,!0)}map(e,t=!1){return e.empty?this:vo(this,e,t,!0)}iterChanges(e,t=!1){wo(this,e,t)}get desc(){return je.create(this.sections)}filter(e){let t=[],n=[],s=[],r=new An(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let h=Math.min(r.len,a-l);Be(s,h,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;Be(t,h,c),c>0&&Gt(n,t,r.text),r.forward(h),l+=h}let u=e[o++];for(;l<u;){if(r.done)break e;let h=Math.min(r.len,u-l);Be(t,h,-1),Be(s,h,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(h),l+=h}}return{changes:new fe(t,n),filtered:je.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],s=this.sections[t+1];s<0?e.push(n):s==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,n){let s=[],r=[],o=0,l=null;function a(h=!1){if(!h&&!s.length)return;o<t&&Be(s,t-o,-1);let c=new fe(s,r);l=l?l.compose(c.map(l)):c,s=[],r=[],o=0}function u(h){if(Array.isArray(h))for(let c of h)u(c);else if(h instanceof fe){if(h.length!=t)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:c,to:f=c,insert:d}=h;if(c>f||c<0||f>t)throw new RangeError(`Invalid change range ${c} to ${f} (in doc of length ${t})`);let m=d?typeof d=="string"?J.of(d.split(n||yo)):d:J.empty,b=m.length;if(c==f&&b==0)return;c<o&&a(),c>o&&Be(s,c-o,-1),Be(s,f-c,b),Gt(r,s,m),o=f}}return u(e),a(!l),l}static empty(e){return new fe(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;n.length<s;)n.push(J.empty);n[s]=J.of(r.slice(1)),t.push(r[0],n[s].length)}}}return new fe(t,n)}static createSet(e,t){return new fe(e,t)}};function Be(i,e,t,n=!1){if(e==0&&t<=0)return;let s=i.length-2;s>=0&&t<=0&&t==i[s+1]?i[s]+=e:e==0&&i[s]==0?i[s+1]+=t:n?(i[s]+=e,i[s+1]+=t):i.push(e,t)}function Gt(i,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n<i.length)i[i.length-1]=i[i.length-1].append(t);else{for(;i.length<n;)i.push(J.empty);i.push(t)}}function wo(i,e,t){let n=i.inserted;for(let s=0,r=0,o=0;o<i.sections.length;){let l=i.sections[o++],a=i.sections[o++];if(a<0)s+=l,r+=l;else{let u=s,h=r,c=J.empty;for(;u+=l,h+=a,a&&n&&(c=c.append(n[o-2>>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)l=i.sections[o++],a=i.sections[o++];e(s,u,r,h,c),s=u,r=h}}}function vo(i,e,t,n=!1){let s=[],r=n?[]:null,o=new An(i),l=new An(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let u=Math.min(o.len,l.len);Be(s,u,-1),o.forward(u),l.forward(u)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let u=l.len;for(Be(s,l.ins,-1);u;){let h=Math.min(o.len,u);o.ins>=0&&a<o.i&&o.len<=h&&(Be(s,0,o.ins),r&&Gt(r,s,o.text),a=o.i),o.forward(h),u-=h}l.next()}else if(o.ins>=0){let u=0,h=o.len;for(;h;)if(l.ins==-1){let c=Math.min(h,l.len);u+=c,h-=c,l.forward(c)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;Be(s,u,a<o.i?o.ins:0),r&&a<o.i&&Gt(r,s,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return r?fe.createSet(s,r):je.create(s);throw new Error("Mismatched change set lengths")}}function Gu(i,e,t=!1){let n=[],s=t?[]:null,r=new An(i),o=new An(e);for(let l=!1;;){if(r.done&&o.done)return s?fe.createSet(n,s):je.create(n);if(r.ins==0)Be(n,r.len,0,l),r.next();else if(o.len==0&&!o.done)Be(n,0,o.ins,l),s&&Gt(s,n,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),u=n.length;if(r.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;Be(n,a,h,l),s&&h&&Gt(s,n,o.text)}else o.ins==-1?(Be(n,r.off?0:r.len,a,l),s&&Gt(s,n,r.textBit(a))):(Be(n,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&Gt(s,n,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||n.length>u),r.forward2(a),o.forward(a)}}}}var An=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?J.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?J.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},Dt=class{constructor(e,t,n){this.from=e,this.to=t,this.flags=n}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let e=this.flags&3;return e==3?null:e}get goalColumn(){let e=this.flags>>5;return e==33554431?void 0:e}map(e,t=-1){let n,s;return this.empty?n=s=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),n==this.from&&s==this.to?this:new Dt(n,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return P.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return P.range(this.anchor,n)}eq(e){return this.anchor==e.anchor&&this.head==e.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return P.range(e.anchor,e.head)}static create(e,t,n){return new Dt(e,t,n)}},P=class{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:P.create(this.ranges.map(n=>n.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;t<this.ranges.length;t++)if(!this.ranges[t].eq(e.ranges[t]))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new P([this.main],0)}addRange(e,t=!0){return P.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();return n[t]=e,P.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new P(e.ranges.map(t=>Dt.fromJSON(t)),e.main)}static single(e,t=e){return new P([P.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=n:r.from<n)return P.normalized(e.slice(),t);n=r.to}return new P(e,t)}static cursor(e,t=0,n,s){return Dt.create(e,e,(t==0?0:t<0?4:8)|(n==null?3:Math.min(2,n))|(s!=null?s:33554431)<<5)}static range(e,t,n){let s=(n!=null?n:33554431)<<5;return t<e?Dt.create(t,e,16|s|8):Dt.create(e,t,s|(t>e?4:0))}static normalized(e,t=0){let n=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(n);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?P.range(a,l):P.range(l,a))}}return new P(e,t)}};function qu(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var Ro=0,$=class{constructor(e,t,n,s,r){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=s,this.id=Ro++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}static define(e={}){return new $(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:Eo),!!e.static,e.enables)}of(e){return new ni([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ni(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ni(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}};function Eo(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}var ni=class{constructor(e,t,n,s){this.dependencies=e,this.facet=t,this.type=n,this.value=s,this.id=Ro++}dynamicSlot(e){var t;let n=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,u=!1,h=[];for(let c of this.dependencies)c=="doc"?a=!0:c=="selection"?u=!0:((t=e[c.id])!==null&&t!==void 0?t:1)&1||h.push(e[c.id]);return{create(c){return c.values[o]=n(c),1},update(c,f){if(a&&f.docChanged||u&&(f.docChanged||f.selection)||Co(c,h)){let d=n(c);if(l?!Fu(d,c.values[o],s):!s(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,f)=>{let d,m=f.config.address[r];if(m!=null){let b=Us(f,m);if(this.dependencies.every(y=>y instanceof $?f.facet(y)===c.facet(y):y instanceof Qe?f.field(y,!1)==c.field(y,!1):!0)||(l?Fu(d=n(c),b,s):s(d=n(c),b)))return c.values[o]=b,0}else d=n(c);return c.values[o]=d,1}}}};function Fu(i,e,t){if(i.length!=e.length)return!1;for(let n=0;n<i.length;n++)if(!t(i[n],e[n]))return!1;return!0}function Co(i,e){let t=!1;for(let n of e)ji(i,n)&1&&(t=!0);return t}function gm(i,e,t){let n=t.map(a=>i[a.id]),s=t.map(a=>a.type),r=n.filter(a=>!(a&1)),o=i[e.id]>>1;function l(a){let u=[];for(let h=0;h<n.length;h++){let c=Us(a,n[h]);if(s[h]==2)for(let f of c)u.push(f);else u.push(c)}return e.combine(u)}return{create(a){for(let u of n)ji(a,u);return a.values[o]=l(a),1},update(a,u){if(!Co(a,r))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,u){let h=Co(a,n),c=u.config.facets[e.id],f=u.facet(e);if(c&&!h&&Eo(t,c))return a.values[o]=f,0;let d=l(a);return e.compare(d,f)?(a.values[o]=f,0):(a.values[o]=d,1)}}}var Hu=$.define({static:!0}),Qe=class{constructor(e,t,n,s,r){this.id=e,this.createF=t,this.updateF=n,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Qe(Ro++,e.create,e.update,e.compare||((n,s)=>n===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Hu).find(n=>n.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,s)=>{let r=n.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(n.values[t]=o,1)},reconfigure:(n,s)=>s.config.address[this.id]!=null?(n.values[t]=s.field(this),0):(n.values[t]=this.create(n),1)}}init(e){return[this,Hu.of({field:this,create:e})]}get extension(){return this}},kn={lowest:4,low:3,default:2,high:1,highest:0};function qi(i){return e=>new zs(e,i)}var oi={highest:qi(kn.highest),high:qi(kn.high),default:qi(kn.default),low:qi(kn.low),lowest:qi(kn.lowest)},zs=class{constructor(e,t){this.inner=e,this.prec=t}},si=class{of(e){return new Qi(this,e)}reconfigure(e){return si.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},Qi=class{constructor(e,t){this.compartment=e,this.inner=t}},ri=class{constructor(e,t,n,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,n){let s=[],r=Object.create(null),o=new Map;for(let f of bm(e,t,o))f instanceof Qe?s.push(f):(r[f.facet.id]||(r[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],u=[];for(let f of s)l[f.id]=u.length<<1,u.push(d=>f.slot(d));let h=n==null?void 0:n.config.facets;for(let f in r){let d=r[f],m=d[0].facet,b=h&&h[f]||[];if(d.every(y=>y.type==0))if(l[m.id]=a.length<<1|1,Eo(b,d))a.push(n.facet(m));else{let y=m.combine(d.map(v=>v.value));a.push(n&&m.compare(y,n.facet(m))?n.facet(m):y)}else{for(let y of d)y.type==0?(l[y.id]=a.length<<1|1,a.push(y.value)):(l[y.id]=u.length<<1,u.push(v=>y.dynamicSlot(v)));l[m.id]=u.length<<1,u.push(y=>gm(y,m,d))}}let c=u.map(f=>f(l));return new ri(e,o,c,l,a,r)}};function bm(i,e,t){let n=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let u=n[a].indexOf(o);u>-1&&n[a].splice(u,1),o instanceof Qi&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let u of o)r(u,l);else if(o instanceof Qi){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(o.compartment)||o.inner;t.set(o.compartment,u),r(u,l)}else if(o instanceof zs)r(o.inner,o.prec);else if(o instanceof Qe)n[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof ni)n[l].push(o),o.facet.extensions&&r(o.facet.extensions,kn.default);else{let u=o.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(u,l)}}return r(i,kn.default),n.reduce((o,l)=>o.concat(l))}function ji(i,e){if(e&1)return 2;let t=e>>1,n=i.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;i.status[t]=4;let s=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|s}function Us(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}var ju=$.define(),Qu=$.define({combine:i=>i.some(e=>e),static:!0}),Ju=$.define({combine:i=>i.length?i[0]:void 0,static:!0}),Xu=$.define(),Yu=$.define(),Zu=$.define(),eh=$.define({combine:i=>i.length?i[0]:!1}),yt=class{constructor(e,t){this.type=e,this.value=t}static define(){return new xo}},xo=class{of(e){return new yt(this,e)}},So=class{constructor(e){this.map=e}of(e){return new ae(this,e)}},ae=class{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new ae(this.type,t)}is(e){return this.type==e}static define(e={}){return new So(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let s of e){let r=s.map(t);r&&n.push(r)}return n}};ae.reconfigure=ae.define();ae.appendConfig=ae.define();var de=class{constructor(e,t,n,s,r,o){this.startState=e,this.changes=t,this.selection=n,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,n&&qu(n,t.newLength),r.some(l=>l.type==de.time)||(this.annotations=r.concat(de.time.of(Date.now())))}static create(e,t,n,s,r,o){return new de(e,t,n,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(de.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};de.time=yt.define();de.userEvent=yt.define();de.addToHistory=yt.define();de.remote=yt.define();function ym(i,e){let t=[];for(let n=0,s=0;;){let r,o;if(n<i.length&&(s==e.length||e[s]>=i[n]))r=i[n++],o=i[n++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function th(i,e,t){var n;let s,r,o;return t?(s=e.changes,r=fe.empty(e.changes.length),o=i.changes.compose(e.changes)):(s=e.changes.map(i.changes),r=i.changes.mapDesc(e.changes,!0),o=i.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(n=i.selection)===null||n===void 0?void 0:n.map(s),effects:ae.mapEffects(i.effects,s).concat(ae.mapEffects(e.effects,r)),annotations:i.annotations.length?i.annotations.concat(e.annotations):e.annotations,scrollIntoView:i.scrollIntoView||e.scrollIntoView}}function ko(i,e,t){let n=e.selection,s=ii(e.annotations);return e.userEvent&&(s=s.concat(de.userEvent.of(e.userEvent))),{changes:e.changes instanceof fe?e.changes:fe.of(e.changes||[],t,i.facet(Ju)),selection:n&&(n instanceof P?n:P.single(n.anchor,n.head)),effects:ii(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function nh(i,e,t){let n=ko(i,e.length?e[0]:{},i.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;n=th(n,ko(i,e[r],o?n.changes.newLength:i.doc.length),o)}let s=de.create(i,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return vm(t?wm(s):s)}function wm(i){let e=i.startState,t=!0;for(let s of e.facet(Xu)){let r=s(i);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:ym(t,r))}if(t!==!0){let s,r;if(t===!1)r=i.changes.invertedDesc,s=fe.empty(e.doc.length);else{let o=i.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}i=de.create(e,s,i.selection&&i.selection.map(r),ae.mapEffects(i.effects,r),i.annotations,i.scrollIntoView)}let n=e.facet(Yu);for(let s=n.length-1;s>=0;s--){let r=n[s](i);r instanceof de?i=r:Array.isArray(r)&&r.length==1&&r[0]instanceof de?i=r[0]:i=nh(e,ii(r),!1)}return i}function vm(i){let e=i.startState,t=e.facet(Zu),n=i;for(let s=t.length-1;s>=0;s--){let r=t[s](i);r&&Object.keys(r).length&&(n=th(n,ko(e,r,i.changes.newLength),!0))}return n==i?i:de.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}var Cm=[];function ii(i){return i==null?Cm:Array.isArray(i)?i:[i]}var ct=function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i}(ct||(ct={})),xm=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Mo;try{Mo=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Sm(i){if(Mo)return Mo.test(i);for(let e=0;e<i.length;e++){let t=i[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||xm.test(t)))return!0}return!1}function km(i){return e=>{if(!/\S/.test(e))return ct.Space;if(Sm(e))return ct.Word;for(let t=0;t<i.length;t++)if(e.indexOf(i[t])>-1)return ct.Word;return ct.Other}}var X=class{constructor(e,t,n,s,r,o){this.config=e,this.doc=t,this.selection=n,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)ji(this,l<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw new RangeError("Field is not present in this state");return}return ji(this,n),Us(this,n)}update(...e){return nh(this,e,!0)}applyTransaction(e){let t=this.config,{base:n,compartments:s}=t;for(let o of e.effects)o.is(si.reconfigure)?(t&&(s=new Map,t.compartments.forEach((l,a)=>s.set(a,l)),t=null),s.set(o.value.compartment,o.value.extension)):o.is(ae.reconfigure)?(t=null,n=o.value):o.is(ae.appendConfig)&&(t=null,n=ii(n).concat(o.value));let r;t?r=e.startState.values.slice():(t=ri.resolve(n,s,this),r=new X(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new X(t,e.newDoc,e.newSelection,r,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:P.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),s=this.changes(n.changes),r=[n.range],o=ii(n.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),u=this.changes(a.changes),h=u.map(s);for(let f=0;f<l;f++)r[f]=r[f].map(h);let c=s.mapDesc(u,!0);r.push(a.range.map(c)),s=s.compose(h),o=ae.mapEffects(o,h).concat(ae.mapEffects(ii(a.effects),c))}return{changes:s,selection:P.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof fe?e:fe.of(e,this.doc.length,this.facet(X.lineSeparator))}toText(e){return J.of(e.split(this.facet(X.lineSeparator)||yo))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(ji(this,t),Us(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let s=e[n];s instanceof Qe&&this.config.address[s.id]!=null&&(t[n]=s.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(e,t={},n){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(n){for(let r in n)if(Object.prototype.hasOwnProperty.call(e,r)){let o=n[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return X.create({doc:e.doc,selection:P.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=ri.resolve(e.extensions||[],new Map),n=e.doc instanceof J?e.doc:J.of((e.doc||"").split(t.staticFacet(X.lineSeparator)||yo)),s=e.selection?e.selection instanceof P?e.selection:P.single(e.selection.anchor,e.selection.head):P.single(0);return qu(s,n.length),t.staticFacet(Qu)||(s=s.asSingle()),new X(t,n,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(X.tabSize)}get lineBreak(){return this.facet(X.lineSeparator)||`
5
+ `}get readOnly(){return this.facet(eh)}phrase(e,...t){for(let n of this.facet(X.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?n:t[r-1]})),e}languageDataAt(e,t,n=-1){let s=[];for(let r of this.facet(ju))for(let o of r(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return km(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-n,l=e-n;for(;o>0;){let a=_e(t,o,!1);if(r(t.slice(a,o))!=ct.Word)break;o=a}for(;l<s;){let a=_e(t,l);if(r(t.slice(l,a))!=ct.Word)break;l=a}return o==l?null:P.range(o+n,l+n)}};X.allowMultipleSelections=Qu;X.tabSize=$.define({combine:i=>i.length?i[0]:4});X.lineSeparator=Ju;X.readOnly=eh;X.phrases=$.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(s=>i[s]==e[s])}});X.languageData=ju;X.changeFilter=Xu;X.transactionFilter=Yu;X.transactionExtender=Zu;si.reconfigure=ae.define();function li(i,e,t={}){let n={};for(let s of i)for(let r of Object.keys(s)){let o=s[r],l=n[r];if(l===void 0)n[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))n[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)n[s]===void 0&&(n[s]=e[s]);return n}var Pt=class{eq(e){return this==e}range(e,t=e){return Rn.create(e,t,this)}};Pt.prototype.startSide=Pt.prototype.endSide=0;Pt.prototype.point=!1;Pt.prototype.mapMode=ze.TrackDel;var Rn=class{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new Rn(e,t,n)}};function To(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}var Ji=class{constructor(e,t,n,s){this.from=e,this.to=t,this.value=n,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,s=0){let r=n?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,u=r[a]-e||(n?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return u>=0?o:l;u>=0?l=a:o=a+1}}between(e,t,n,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let n=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let u=this.value[a],h=this.from[a]+e,c=this.to[a]+e,f,d;if(h==c){let m=t.mapPos(h,u.startSide,u.mapMode);if(m==null||(f=d=m,u.startSide!=u.endSide&&(d=t.mapPos(h,u.endSide),d<f)))continue}else if(f=t.mapPos(h,u.startSide),d=t.mapPos(c,u.endSide),f>d||f==d&&u.startSide>0&&u.endSide<=0)continue;(d-f||u.endSide-u.startSide)<0||(o<0&&(o=f),u.point&&(l=Math.max(l,d-f)),n.push(u),s.push(f-o),r.push(d-o))}return{mapped:n.length?new Ji(s,r,n,l):null,pos:o}}},le=class{constructor(e,t,n,s){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=s}static create(e,t,n,s){return new le(e,t,n,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:n=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(To)),this.isEmpty)return t.length?le.of(t):this;let l=new Ks(this,null,-1).goto(0),a=0,u=[],h=new wt;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let c=t[a++];h.addInner(c.from,c.to,c.value)||u.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||u.push(Rn.create(l.from,l.to,l.value))),l.next());return h.finishInner(this.nextLayer.isEmpty&&!u.length?le.empty:this.nextLayer.update({add:u,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],u=e.touchesRange(l,l+a.length);if(u===!1)s=Math.max(s,a.maxPoint),t.push(a),n.push(e.mapPos(l));else if(u===!0){let{mapped:h,pos:c}=a.map(l,e);h&&(s=Math.max(s,h.maxPoint),t.push(h),n.push(c))}}let r=this.nextLayer.map(e);return t.length==0?r:new le(n,t,r||le.empty,s)}between(e,t,n){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return En.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return En.from(e).goto(t)}static compare(e,t,n,s,r=-1){let o=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),a=Wu(o,l,n),u=new Mn(o,a,r),h=new Mn(l,a,r);n.iterGaps((c,f,d)=>_u(u,c,h,f,d,s)),n.empty&&n.length==0&&_u(u,0,h,0,0,s)}static eq(e,t,n=0,s){s==null&&(s=1e9-1);let r=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Wu(r,o),a=new Mn(r,l,0).goto(n),u=new Mn(o,l,0).goto(n);for(;;){if(a.to!=u.to||!Ao(a.active,u.active)||a.point&&(!u.point||!a.point.eq(u.point)))return!1;if(a.to>s)return!0;a.next(),u.next()}}static spans(e,t,n,s,r=-1){let o=new Mn(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let u=Math.min(o.to,n);if(o.point){let h=o.activeForPoint(o.to),c=o.pointFrom<t?h.length+1:Math.min(h.length,a);s.point(l,u,o.point,h,c,o.pointRank),a=Math.min(o.openEnd(u),h.length)}else u>l&&(s.span(l,u,o.active,a),a=o.openEnd(u));if(o.to>n)return a+(o.point&&o.to>n?1:0);l=o.to,o.next()}}static of(e,t=!1){let n=new wt;for(let s of e instanceof Rn?[e]:t?Mm(e):e)n.add(s.from,s.to,s.value);return n.finish()}};le.empty=new le([],[],null,-1);function Mm(i){if(i.length>1)for(let e=i[0],t=1;t<i.length;t++){let n=i[t];if(To(e,n)>0)return i.slice().sort(To);e=n}return i}le.empty.nextLayer=le.empty;var wt=class{constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}finishChunk(e){this.chunks.push(new Ji(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}add(e,t,n){this.addInner(e,t,n)||(this.nextLayer||(this.nextLayer=new wt)).add(e,t,n)}addInner(e,t,n){let s=e-this.lastTo||n.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(le.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=le.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function Wu(i,e,t){let n=new Map;for(let r of i)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&n.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=n.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}var Ks=class{constructor(e,t,n,s=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},En=class{constructor(e){this.heap=e}static from(e,t=null,n=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=n&&s.push(new Ks(o,t,n,r));return s.length==1?s[0]:new En(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let n=this.heap.length>>1;n>=0;n--)go(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)go(this.heap,n);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),go(this.heap,0)}}};function go(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let s=i[n];if(n+1<i.length&&s.compare(i[n+1])>=0&&(s=i[n+1],n++),t.compare(s)<0)break;i[n]=t,i[e]=s,e=n}}var Mn=class{constructor(e,t,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=En.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Bs(this.active,e),Bs(this.activeTo,e),Bs(this.activeRank,e),this.minActive=$u(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&this.activeRank[t]<=r;)t++;Fs(this.active,t,n),Fs(this.activeTo,t,s),Fs(this.activeRank,t,r),e&&Fs(e,t,this.cursor.from),this.minActive=$u(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),n&&Bs(n,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(n){this.openStart=0;for(let s=n.length-1;s>=0&&n[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function _u(i,e,t,n,s,r){i.goto(e),t.goto(n);let o=n+s,l=n,a=n-e;for(;;){let u=i.to+a-t.to||i.endSide-t.endSide,h=u<0?i.to+a:t.to,c=Math.min(h,o);if(i.point||t.point?i.point&&t.point&&(i.point==t.point||i.point.eq(t.point))&&Ao(i.activeForPoint(i.to+a),t.activeForPoint(t.to))||r.comparePoint(l,c,i.point,t.point):c>l&&!Ao(i.active,t.active)&&r.compareRange(l,c,i.active,t.active),h>o)break;l=h,u<=0&&i.next(),u>=0&&t.next()}}function Ao(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(i[t]!=e[t]&&!i[t].eq(e[t]))return!1;return!0}function Bs(i,e){for(let t=e,n=i.length-1;t<n;t++)i[t]=i[t+1];i.pop()}function Fs(i,e,t){for(let n=i.length-1;n>=e;n--)i[n+1]=i[n];i[e]=t}function $u(i,e){let t=-1,n=1e9;for(let s=0;s<e.length;s++)(e[s]-n||i[s].endSide-i[t].endSide)<0&&(t=s,n=e[s]);return t}function Dn(i,e,t=i.length){let n=0;for(let s=0;s<t;)i.charCodeAt(s)==9?(n+=e-n%e,s++):(n++,s=_e(i,s));return n}function ih(i,e,t,n){for(let s=0,r=0;;){if(r>=e)return s;if(s==i.length)break;r+=i.charCodeAt(s)==9?t-r%t:1,s=_e(i,s)}return n===!0?-1:i.length}var Do="\u037C",sh=typeof Symbol>"u"?"__"+Do:Symbol.for(Do),Po=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),rh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},et=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,u){let h=[],c=/^@(\w+)\b/.exec(o[0]),f=c&&c[1]=="keyframes";if(c&&l==null)return a.push(o[0]+";");for(let d in l){let m=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(b=>o.map(y=>b.replace(/&/,y))).reduce((b,y)=>b.concat(y)),m,a);else if(m&&typeof m=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),m,h,f)}else m!=null&&h.push(d.replace(/_.*/,"").replace(/[A-Z]/g,b=>"-"+b.toLowerCase())+": "+m+";")}(h.length||f)&&a.push((n&&!c&&!u?o.map(n):o).join(", ")+" {"+h.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(`
6
+ `)}static newName(){let e=rh[sh]||1;return rh[sh]=e+1,Do+e.toString(36)}static mount(e,t){(e[Po]||new Oo(e)).mount(Array.isArray(t)?t:[t])}},Gs=null,Oo=class{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(Gs)return e.adoptedStyleSheets=[Gs.sheet].concat(e.adoptedStyleSheets),e[Po]=Gs;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),Gs=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[Po]=this}mount(e){let t=this.sheet,n=0,s=0;for(let r=0;r<e.length;r++){let o=e[r],l=this.modules.indexOf(o);if(l<s&&l>-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),t)for(let a=0;a<o.rules.length;a++)t.insertRule(o.rules[a],n++)}else{for(;s<l;)n+=this.modules[s++].rules.length;n+=o.rules.length,s++}}if(!t){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
7
+ `;this.styleTag.textContent=r}}};var Ot={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ai={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},oh=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),PC=typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent),Tm=typeof navigator<"u"&&/Mac/.test(navigator.platform),Am=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Rm=Tm||oh&&+oh[1]<57;for(Ce=0;Ce<10;Ce++)Ot[48+Ce]=Ot[96+Ce]=String(Ce);var Ce;for(Ce=1;Ce<=24;Ce++)Ot[Ce+111]="F"+Ce;var Ce;for(Ce=65;Ce<=90;Ce++)Ot[Ce]=String.fromCharCode(Ce+32),ai[Ce]=String.fromCharCode(Ce);var Ce;for(qs in Ot)ai.hasOwnProperty(qs)||(ai[qs]=Ot[qs]);var qs;function lh(i){var e=Rm&&(i.ctrlKey||i.altKey||i.metaKey)||Am&&i.shiftKey&&i.key&&i.key.length==1||i.key=="Unidentified",t=!e&&i.key||(i.shiftKey?ai:Ot)[i.keyCode]||i.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function ir(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function fi(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function Em(i){let e=i.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Zs(i,e){if(!e.anchorNode)return!1;try{return fi(i,e.anchorNode)}catch{return!1}}function ns(i){return i.nodeType==3?di(i,0,i.nodeValue.length).getClientRects():i.nodeType==1?i.getClientRects():[]}function sr(i,e,t,n){return t?ah(i,e,t,n,-1)||ah(i,e,t,n,1):!1}function rr(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function ah(i,e,t,n,s){for(;;){if(i==t&&e==n)return!0;if(e==(s<0?0:is(i))){if(i.nodeName=="DIV")return!1;let r=i.parentNode;if(!r||r.nodeType!=1)return!1;e=rr(i)+(s<0?0:1),i=r}else if(i.nodeType==1){if(i=i.childNodes[e+(s<0?-1:0)],i.nodeType==1&&i.contentEditable=="false")return!1;e=s<0?is(i):0}else return!1}}function is(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}var _h={left:0,right:0,top:0,bottom:0};function wl(i,e){let t=e?i.left:i.right;return{left:t,right:t,top:i.top,bottom:i.bottom}}function Dm(i){return{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function Pm(i,e,t,n,s,r,o,l){let a=i.ownerDocument,u=a.defaultView||window;for(let h=i;h;)if(h.nodeType==1){let c,f=h==a.body;if(f)c=Dm(u);else{if(h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let b=h.getBoundingClientRect();c={left:b.left,right:b.left+h.clientWidth,top:b.top,bottom:b.top+h.clientHeight}}let d=0,m=0;if(s=="nearest")e.top<c.top?(m=-(c.top-e.top+o),t>0&&e.bottom>c.bottom+m&&(m=e.bottom-c.bottom+m+o)):e.bottom>c.bottom&&(m=e.bottom-c.bottom+o,t<0&&e.top-m<c.top&&(m=-(c.top+m-e.top+o)));else{let b=e.bottom-e.top,y=c.bottom-c.top;m=(s=="center"&&b<=y?e.top+b/2-y/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-y+o)-c.top}if(n=="nearest"?e.left<c.left?(d=-(c.left-e.left+r),t>0&&e.right>c.right+d&&(d=e.right-c.right+d+r)):e.right>c.right&&(d=e.right-c.right+r,t<0&&e.left<c.left+d&&(d=-(c.left+d-e.left+r))):d=(n=="center"?e.left+(e.right-e.left)/2-(c.right-c.left)/2:n=="start"==l?e.left-r:e.right-(c.right-c.left)+r)-c.left,d||m)if(f)u.scrollBy(d,m);else{let b=0,y=0;if(m){let v=h.scrollTop;h.scrollTop+=m,y=h.scrollTop-v}if(d){let v=h.scrollLeft;h.scrollLeft+=d,b=h.scrollLeft-v}e={left:e.left-b,top:e.top-y,right:e.right-b,bottom:e.bottom-y},b&&Math.abs(b-d)<1&&(n="nearest"),y&&Math.abs(y-m)<1&&(s="nearest")}if(f)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}var Fo=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){this.set(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)}set(e,t,n,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=s}},ui=null;function $h(i){if(i.setActive)return i.setActive();if(ui)return i.focus(ui);let e=[];for(let t=i;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(i.focus(ui==null?{get preventScroll(){return ui={preventScroll:!0},!0}}:void 0),!ui){ui=!1;for(let t=0;t<e.length;){let n=e[t++],s=e[t++],r=e[t++];n.scrollTop!=s&&(n.scrollTop=s),n.scrollLeft!=r&&(n.scrollLeft=r)}}}var uh;function di(i,e,t=e){let n=uh||(uh=document.createRange());return n.setEnd(i,t),n.setStart(i,e),n}function ci(i,e,t){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0},s=new KeyboardEvent("keydown",n);s.synthetic=!0,i.dispatchEvent(s);let r=new KeyboardEvent("keyup",n);return r.synthetic=!0,i.dispatchEvent(r),s.defaultPrevented||r.defaultPrevented}function Om(i){for(;i;){if(i&&(i.nodeType==9||i.nodeType==11&&i.host))return i;i=i.assignedSlot||i.parentNode}return null}function zh(i){for(;i.attributes.length;)i.removeAttributeNode(i.attributes[0])}function Vm(i,e){let t=e.focusNode,n=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=n)return!1;for(;;)if(n){if(t.nodeType!=1)return!1;let s=t.childNodes[n-1];s.contentEditable=="false"?n--:(t=s,n=is(t))}else{if(t==i)return!0;n=rr(t),t=t.parentNode}}var Re=class{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(e,t){return new Re(e.parentNode,rr(e),t)}static after(e,t){return new Re(e.parentNode,rr(e)+1,t)}},vl=[],ee=class{constructor(){this.parent=null,this.dom=null,this.dirty=2}get editorView(){if(!this.parent)throw new Error("Accessing view in orphan content view");return this.parent.editorView}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let n of this.children){if(n==e)return t;t+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}coordsAt(e,t){return null}sync(e){if(this.dirty&2){let t=this.dom,n=null,s;for(let r of this.children){if(r.dirty){if(!r.dom&&(s=n?n.nextSibling:t.firstChild)){let o=ee.get(s);(!o||!o.parent&&o.canReuseDOM(r))&&r.reuseDOM(s)}r.sync(e),r.dirty=0}if(s=n?n.nextSibling:t.firstChild,e&&!e.written&&e.node==t&&s!=r.dom&&(e.written=!0),r.dom.parentNode==t)for(;s&&s!=r.dom;)s=hh(s);else t.insertBefore(r.dom,s);n=r.dom}for(s=n?n.nextSibling:t.firstChild,s&&e&&e.node==t&&(e.written=!0);s;)s=hh(s)}else if(this.dirty&1)for(let t of this.children)t.dirty&&(t.sync(e),t.dirty=0)}reuseDOM(e){}localPosFromDOM(e,t){let n;if(e==this.dom)n=this.dom.childNodes[t];else{let s=is(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?s=-1:s=1),e=r}s<0?n=e:n=e.nextSibling}if(n==this.dom.firstChild)return 0;for(;n&&!ee.get(n);)n=n.nextSibling;if(!n)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==n)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,n=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,u=n,h=n;a<this.children.length;a++){let c=this.children[a],f=u+c.length;if(u<e&&f>t)return c.domBoundsAround(e,t,u);if(f>=e&&s==-1&&(s=a,r=u),u>t&&c.dom.parentNode==this.dom){o=a,l=h;break}h=f,u=f+c.breakAfter}return{from:r,to:l<0?n+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.dirty|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.dirty|=2),t.dirty&1)return;t.dirty|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.dirty&&this.markParentsDirty(!0))}setDOM(e){this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,n=vl){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&r.destroy()}this.children.splice(e,t-e,...n);for(let s=0;s<n.length;s++)n[s].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new or(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}merge(e,t,n,s,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor}getSide(){return 0}destroy(){this.parent=null}};ee.prototype.breakAfter=0;function hh(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}var or=class{constructor(e,t,n){this.children=e,this.pos=t,this.i=n,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let n=this.children[--this.i];this.pos-=n.length+n.breakAfter}}};function Uh(i,e,t,n,s,r,o,l,a){let{children:u}=i,h=u.length?u[e]:null,c=r.length?r[r.length-1]:null,f=c?c.breakAfter:o;if(!(e==n&&h&&!o&&!f&&r.length<2&&h.merge(t,s,r.length?c:null,t==0,l,a))){if(n<u.length){let d=u[n];d&&s<d.length?(e==n&&(d=d.split(s),s=0),!f&&c&&d.merge(0,s,c,!0,0,a)?r[r.length-1]=d:(s&&d.merge(0,s,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(c?c.breakAfter=1:o=1),n++}for(h&&(h.breakAfter=o,t>0&&(!o&&r.length&&h.merge(t,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(t<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(t,h.length,null,!1,l,0),e++));e<n&&r.length;)if(u[n-1].become(r[r.length-1]))n--,r.pop(),a=r.length?0:l;else if(u[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&n<u.length&&!u[e-1].breakAfter&&u[n].merge(0,0,u[e-1],!1,l,a)&&e--,(e<n||r.length)&&i.replaceChildren(e,n,r)}}function Kh(i,e,t,n,s,r){let o=i.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:u,off:h}=o.findPos(e,-1),c=e-t;for(let f of n)c+=f.length;i.length+=c,Uh(i,u,h,l,a,n,0,s,r)}var Je=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ho=typeof document<"u"?document:{documentElement:{style:{}}},Wo=/Edge\/(\d+)/.exec(Je.userAgent),Gh=/MSIE \d/.test(Je.userAgent),_o=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Je.userAgent),gr=!!(Gh||_o||Wo),ch=!gr&&/gecko\/(\d+)/i.test(Je.userAgent),Vo=!gr&&/Chrome\/(\d+)/.exec(Je.userAgent),fh="webkitFontSmoothing"in Ho.documentElement.style,qh=!gr&&/Apple Computer/.test(Je.vendor),dh=qh&&(/Mobile\/\w+/.test(Je.userAgent)||Je.maxTouchPoints>2),W={mac:dh||/Mac/.test(Je.platform),windows:/Win/.test(Je.platform),linux:/Linux|X11/.test(Je.platform),ie:gr,ie_version:Gh?Ho.documentMode||6:_o?+_o[1]:Wo?+Wo[1]:0,gecko:ch,gecko_version:ch?+(/Firefox\/(\d+)/.exec(Je.userAgent)||[0,0])[1]:0,chrome:!!Vo,chrome_version:Vo?+Vo[1]:0,ios:dh,android:/Android\b/.test(Je.userAgent),webkit:fh,safari:qh,webkit_version:fh?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:Ho.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"},Im=256,St=class extends ee{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,n){return n&&(!(n instanceof St)||this.length-(t-e)+n.length>Im)?!1:(this.text=this.text.slice(0,e)+(n?n.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new St(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new Re(this.dom,e)}domBoundsAround(e,t,n){return{from:n,to:n+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return $o(this.dom,e,t)}},nt=class extends ee{constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let s of t)s.setParent(this)}setAttrs(e){if(zh(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.dirty|=6)}sync(e){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e)}merge(e,t,n,s,r,o){return n&&(!(n instanceof nt&&n.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(Kh(this,e,t,n?n.children:[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],n=0,s=-1,r=0;for(let l of this.children){let a=n+l.length;a>e&&t.push(n<e?l.split(e-n):l),s<0&&n>=e&&(s=r),n=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new nt(this.mark,t,o)}domAtPos(e){return Qh(this,e)}coordsAt(e,t){return Xh(this,e,t)}};function $o(i,e,t){let n=i.nodeValue.length;e>n&&(e=n);let s=e,r=e,o=0;e==0&&t<0||e==n&&t>=0?W.chrome||W.gecko||(e?(s--,o=1):r<n&&(r++,o=-1)):t<0?s--:r<n&&r++;let l=di(i,s,r).getClientRects();if(!l.length)return _h;let a=l[(o?o<0:t>=0)?0:l.length-1];return W.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,u=>u.width)||a),o?wl(a,o<0):a||null}var Ct=class extends ee{constructor(e,t,n){super(),this.widget=e,this.length=t,this.side=n,this.prevWidget=null}static create(e,t,n){return new(e.customView||Ct)(e,t,n)}split(e){let t=Ct.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,n,s,r,o){return n&&(!(n instanceof Ct)||!this.widget.compare(n.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(n?n.length:0)+(this.length-t),!0)}become(e){return e.length==this.length&&e instanceof Ct&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.eq(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return J.empty;let e=this;for(;e.parent;)e=e.parent;let t=e.editorView,n=t&&t.state.doc,s=this.posAtStart;return n?n.slice(s,s+this.length):J.empty}domAtPos(e){return e==0?Re.before(this.dom):Re.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let n=this.dom.getClientRects(),s=null;if(!n.length)return _h;for(let r=e>0?n.length-1:0;s=n[r],!(e>0?r==0:r==n.length-1||s.top<s.bottom);r+=e>0?-1:1);return this.length?s:wl(s,this.side>0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},lr=class extends Ct{domAtPos(e){let{topView:t,text:n}=this.widget;return t?zo(e,0,t,n,(s,r)=>s.domAtPos(r),s=>new Re(n,Math.min(s,n.nodeValue.length))):new Re(n,Math.min(e,n.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:n,text:s}=this.widget;return n?jh(e,t,n,s):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:n,text:s}=this.widget;return n?zo(e,t,n,s,(r,o,l)=>r.coordsAt(o,l),(r,o)=>$o(s,r,o)):$o(s,e,t)}destroy(){var e;super.destroy(),(e=this.widget.topView)===null||e===void 0||e.destroy()}get isEditable(){return!0}canReuseDOM(){return!0}};function zo(i,e,t,n,s,r){if(t instanceof nt){for(let o=t.dom.firstChild;o;o=o.nextSibling){let l=ee.get(o);if(!l)return r(i,e);let a=fi(o,n),u=l.length+(a?n.nodeValue.length:0);if(i<u||i==u&&l.getSide()<=0)return a?zo(i,e,l,n,s,r):s(l,i,e);i-=u}return s(t,t.length,-1)}else return t.dom==n?r(i,e):s(t,i,e)}function jh(i,e,t,n){if(t instanceof nt)for(let s of t.children){let r=0,o=fi(s.dom,n);if(fi(s.dom,i))return r+(o?jh(i,e,s,n):s.localPosFromDOM(i,e));r+=o?n.nodeValue.length:s.length}else if(t.dom==n)return Math.min(e,n.nodeValue.length);return t.localPosFromDOM(i,e)}var Jt=class extends ee{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof Jt&&e.side==this.side}split(){return new Jt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return Re.before(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){let t=this.dom.getBoundingClientRect(),n=Lm(this,this.side>0?-1:1);return n&&n.top<t.bottom&&n.bottom>t.top?{left:t.left,right:t.right,top:n.top,bottom:n.bottom}:t}get overrideDOMText(){return J.empty}};St.prototype.children=Ct.prototype.children=Jt.prototype.children=vl;function Lm(i,e){let t=i.parent,n=t?t.children.indexOf(i):-1;for(;t&&n>=0;)if(e<0?n>0:n<t.children.length){let s=t.children[n+e];if(s instanceof St){let r=s.coordsAt(e<0?s.length:0,e);if(r)return r}n+=e}else if(t instanceof nt&&t.parent)n=t.parent.children.indexOf(t)+(e<0?0:1),t=t.parent;else{let s=t.dom.lastChild;if(s&&s.nodeName=="BR")return s.getClientRects()[0];break}}function Qh(i,e){let t=i.dom,{children:n}=i,s=0;for(let r=0;s<n.length;s++){let o=n[s],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(e>r&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-r);if(e<=r)break;r=l}}for(let r=s;r>0;r--){let o=n[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=s;r<n.length;r++){let o=n[r];if(o.dom.parentNode==t)return o.domAtPos(0)}return new Re(t,0)}function Jh(i,e,t){let n,{children:s}=i;t>0&&e instanceof nt&&s.length&&(n=s[s.length-1])instanceof nt&&n.mark.eq(e.mark)?Jh(n,e.children[0],t-1):(s.push(e),e.setParent(i)),i.length+=e.length}function Xh(i,e,t){let n=null,s=-1,r=null,o=-1;function l(u,h){for(let c=0,f=0;c<u.children.length&&f<=h;c++){let d=u.children[c],m=f+d.length;m>=h&&(d.children.length?l(d,h-f):!r&&(m>h||f==m&&d.getSide()>0)?(r=d,o=h-f):(f<h||f==m&&d.getSide()<0)&&(n=d,s=h-f)),f=m}}l(i,e);let a=(t<0?n:r)||n||r;return a?a.coordsAt(Math.max(0,a==n?s:o),t):Nm(i)}function Nm(i){let e=i.dom.lastChild;if(!e)return i.dom.getBoundingClientRect();let t=ns(e);return t[t.length-1]||null}function Uo(i,e){for(let t in i)t=="class"&&e.class?e.class+=" "+i.class:t=="style"&&e.style?e.style+=";"+i.style:e[t]=i[t];return e}function Cl(i,e){if(i==e)return!0;if(!i||!e)return!1;let t=Object.keys(i),n=Object.keys(e);if(t.length!=n.length)return!1;for(let s of t)if(n.indexOf(s)==-1||i[s]!==e[s])return!1;return!0}function Ko(i,e,t){let n=null;if(e)for(let s in e)t&&s in t||i.removeAttribute(n=s);if(t)for(let s in t)e&&e[s]==t[s]||i.setAttribute(n=s,t[s]);return!!n}var Lt=class{eq(e){return!1}updateDOM(e){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}ignoreEvent(e){return!0}get customView(){return null}destroy(e){}},ue=function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i}(ue||(ue={})),re=class extends Pt{constructor(e,t,n,s){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=s}get heightRelevant(){return!1}static mark(e){return new pi(e)}static widget(e){let t=e.side||0,n=!!e.block;return t+=n?t>0?3e8:-4e8:t>0?1e8:-1e8,new Nt(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,s;if(e.isBlockGap)n=-5e8,s=4e8;else{let{start:r,end:o}=Yh(e,t);n=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new Nt(e,n,s,t,e.widget||null,!0)}static line(e){return new Pn(e)}static set(e,t=!1){return le.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};re.none=le.empty;var pi=class extends re{constructor(e){let{start:t,end:n}=Yh(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){return this==e||e instanceof pi&&this.tagName==e.tagName&&this.class==e.class&&Cl(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};pi.prototype.point=!1;var Pn=class extends re{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Pn&&Cl(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}};Pn.prototype.mapMode=ze.TrackBefore;Pn.prototype.point=!0;var Nt=class extends re{constructor(e,t,n,s,r,o){super(t,n,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?ze.TrackBefore:ze.TrackAfter:ze.TrackDel}get type(){return this.startSide<this.endSide?ue.WidgetRange:this.startSide<=0?ue.WidgetBefore:ue.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&this.widget.estimatedHeight>=5}eq(e){return e instanceof Nt&&Bm(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}};Nt.prototype.point=!0;function Yh(i,e=!1){let{inclusiveStart:t,inclusiveEnd:n}=i;return t==null&&(t=i.inclusive),n==null&&(n=i.inclusive),{start:t!=null?t:e,end:n!=null?n:e}}function Bm(i,e){return i==e||!!(i&&e&&i.compare(e))}function Go(i,e,t,n=0){let s=t.length-1;s>=0&&t[s]+n>=i?t[s]=Math.max(t[s],e):t.push(i,e)}var Oe=class extends ee{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,n,s,r,o){if(n){if(!(n instanceof Oe))return!1;this.dom||n.transferDOM(this)}return s&&this.setDeco(n?n.attrs:null),Kh(this,e,t,n?n.children:[],r,o),!0}split(e){let t=new Oe;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i:n,off:s}=this.childPos(e);s&&(t.append(this.children[n].split(s),0),this.children[n].merge(s,this.children[n].length,null,!1,0,0),n++);for(let r=n;r<this.children.length;r++)t.append(this.children[r],0);for(;n>0&&this.children[n-1].length==0;)this.children[--n].destroy();return this.children.length=n,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Cl(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Jh(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=Uo(t,this.attrs||{})),n&&(this.attrs=Uo({class:n},this.attrs||{}))}domAtPos(e){return Qh(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e){var t;this.dom?this.dirty&4&&(zh(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Ko(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e);let n=this.dom.lastChild;for(;n&&ee.get(n)instanceof nt;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((t=ee.get(n))===null||t===void 0?void 0:t.isEditable)==!1&&(!W.ios||!this.children.some(s=>s instanceof St))){let s=document.createElement("BR");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0;for(let t of this.children){if(!(t instanceof St)||/[^ -~]/.test(t.text))return null;let n=ns(t.dom);if(n.length!=1)return null;e+=n[0].width}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length}:null}coordsAt(e,t){return Xh(this,e,t)}become(e){return!1}get type(){return ue.Text}static find(e,t){for(let n=0,s=0;n<e.children.length;n++){let r=e.children[n],o=s+r.length;if(o>=t){if(r instanceof Oe)return r;if(o>t)break}s=o+r.breakAfter}return null}},Vt=class extends ee{constructor(e,t,n){super(),this.widget=e,this.length=t,this.type=n,this.breakAfter=0,this.prevWidget=null}merge(e,t,n,s,r,o){return n&&(!(n instanceof Vt)||!this.widget.compare(n.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(n?n.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?Re.before(this.dom):Re.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let n=new Vt(this.widget,t,this.type);return n.breakAfter=this.breakAfter,n}get children(){return vl}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):J.empty}domBoundsAround(){return null}become(e){return e instanceof Vt&&e.type==this.type&&e.widget.constructor==this.widget.constructor?(e.widget.eq(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},ss=class{constructor(e,t,n,s){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!e.breakAfter&&!(e instanceof Vt&&e.type==ue.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new Oe),this.atCursorPos=!0),this.curLine}flushBuffer(e){this.pendingBuffer&&(this.curLine.append(js(new Jt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer([]),this.curLine=null,this.content.push(e)}finish(e){e?this.pendingBuffer=0:this.flushBuffer([]),this.posCovered()||this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(js(new St(this.text.slice(this.textOff,this.textOff+s)),t),n),this.atCursorPos=!0,this.textOff+=s,e-=s,n=0}}span(e,t,n,s){this.buildText(t-e,n,s),this.pos=t,this.openStart<0&&(this.openStart=s)}point(e,t,n,s,r,o){if(this.disallowBlockEffectsFor[o]&&n instanceof Nt){if(n.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(n instanceof Nt)if(n.block){let{type:a}=n;a==ue.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Vt(n.widget||new ar("div"),l,a))}else{let a=Ct.create(n.widget||new ar("span"),l,l?0:n.startSide),u=this.atCursorPos&&!a.isEditable&&r<=s.length&&(e<t||n.startSide>0),h=!a.isEditable&&(e<t||n.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!u&&(this.pendingBuffer=0),this.flushBuffer(s),u&&(c.append(js(new Jt(1),s),r),r=s.length+Math.max(0,r-s.length)),c.append(js(a,s),r),this.atCursorPos=h,this.pendingBuffer=h?e<t?1:2:0}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(n);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,n,s,r){let o=new ss(e,t,n,r);return o.openEnd=le.spans(s,t,n,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function js(i,e){for(let t of e)i=new nt(t,[i],i.length);return i}var ar=class extends Lt{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}},Zh=$.define(),ec=$.define(),tc=$.define(),nc=$.define(),qo=$.define(),ic=$.define(),sc=$.define({combine:i=>i.some(e=>e)}),rc=$.define({combine:i=>i.some(e=>e)}),mi=class{constructor(e,t="nearest",n="nearest",s=5,r=5){this.range=e,this.y=t,this.x=n,this.yMargin=s,this.xMargin=r}map(e){return e.empty?this:new mi(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}},ph=ae.define({map:(i,e)=>i.map(e)});function It(i,e,t){let n=i.facet(nc);n.length?n[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}var br=$.define({combine:i=>i.length?i[0]:!0}),Fm=0,Xi=$.define(),ft=class{constructor(e,t,n,s){this.id=e,this.create=t,this.domEventHandlers=n,this.extension=s(this)}static define(e,t){let{eventHandlers:n,provide:s,decorations:r}=t||{};return new ft(Fm++,e,n,o=>{let l=[Xi.of(o)];return r&&l.push(rs.of(a=>{let u=a.plugin(o);return u?r(u):re.none})),s&&l.push(s(o)),l})}static fromClass(e,t){return ft.define(n=>new e(n),t)}},es=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(It(t.state,n,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){It(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){It(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},oc=$.define(),xl=$.define(),rs=$.define(),lc=$.define(),ac=$.define(),Yi=$.define(),tt=class{constructor(e,t,n,s){this.fromA=e,this.toA=t,this.fromB=n,this.toB=s}join(e){return new tt(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>n.toA)){if(s.toA<n.fromA)break;n=n.join(s),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(e,t){if(t.length==0)return e;let n=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],u=o-l,h=a?a.fromB:1e9;for(;r<t.length&&t[r]<h;){let c=t[r],f=t[r+1],d=Math.max(l,c),m=Math.min(h,f);if(d<=m&&new tt(d+u,m+u,d,m).addToSet(n),f>h)break;r+=2}if(!a)return n;new tt(a.fromA,a.toA,a.fromB,a.toB).addToSet(n),o=a.toA,l=a.toB}}},gi=class{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=fe.empty(this.startState.doc.length);for(let o of n)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,l,a,u)=>s.push(new tt(o,l,a,u))),this.changedRanges=s;let r=e.hasFocus;r!=e.inputState.notifiedFocused&&(e.inputState.notifiedFocused=r,this.flags|=1)}static create(e,t,n){return new gi(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},xe=function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i}(xe||(xe={})),jo=xe.LTR,Hm=xe.RTL;function uc(i){let e=[];for(let t=0;t<i.length;t++)e.push(1<<+i[t]);return e}var Wm=uc("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),_m=uc("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Qo=Object.create(null),vt=[];for(let i of["()","[]","{}"]){let e=i.charCodeAt(0),t=i.charCodeAt(1);Qo[e]=t,Qo[t]=-e}function $m(i){return i<=247?Wm[i]:1424<=i&&i<=1524?2:1536<=i&&i<=1785?_m[i-1536]:1774<=i&&i<=2220?4:8192<=i&&i<=8203?256:64336<=i&&i<=65023?4:i==8204?256:1}var zm=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Qt=class{constructor(e,t,n){this.from=e,this.to=t,this.level=n}get dir(){return this.level%2?Hm:jo}side(e,t){return this.dir==t==e?this.to:this.from}static find(e,t,n,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==n)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}},pe=[];function Um(i,e){let t=i.length,n=e==jo?1:2,s=e==jo?2:1;if(!i||n==1&&!zm.test(i))return hc(t);for(let o=0,l=n,a=n;o<t;o++){let u=$m(i.charCodeAt(o));u==512?u=l:u==8&&a==4&&(u=16),pe[o]=u==4?2:u,u&7&&(a=u),l=u}for(let o=0,l=n,a=n;o<t;o++){let u=pe[o];if(u==128)o<t-1&&l==pe[o+1]&&l&24?u=pe[o]=l:pe[o]=256;else if(u==64){let h=o+1;for(;h<t&&pe[h]==64;)h++;let c=o&&l==8||h<t&&pe[h]==8?a==1?1:8:256;for(let f=o;f<h;f++)pe[f]=c;o=h-1}else u==8&&a==1&&(pe[o]=1);l=u,u&7&&(a=u)}for(let o=0,l=0,a=0,u,h,c;o<t;o++)if(h=Qo[u=i.charCodeAt(o)])if(h<0){for(let f=l-3;f>=0;f-=3)if(vt[f+1]==-h){let d=vt[f+2],m=d&2?n:d&4?d&1?s:n:0;m&&(pe[o]=pe[vt[f]]=m),l=f;break}}else{if(vt.length==189)break;vt[l++]=o,vt[l++]=u,vt[l++]=a}else if((c=pe[o])==2||c==1){let f=c==n;a=f?0:1;for(let d=l-3;d>=0;d-=3){let m=vt[d+2];if(m&2)break;if(f)vt[d+2]|=2;else{if(m&4)break;vt[d+2]|=4}}}for(let o=0;o<t;o++)if(pe[o]==256){let l=o+1;for(;l<t&&pe[l]==256;)l++;let a=(o?pe[o-1]:n)==1,u=(l<t?pe[l]:n)==1,h=a==u?a?1:2:n;for(let c=o;c<l;c++)pe[c]=h;o=l-1}let r=[];if(n==1)for(let o=0;o<t;){let l=o,a=pe[o++]!=1;for(;o<t&&a==(pe[o]!=1);)o++;if(a)for(let u=o;u>l;){let h=u,c=pe[--u]!=2;for(;u>l&&c==(pe[u-1]!=2);)u--;r.push(new Qt(u,h,c?2:1))}else r.push(new Qt(l,o,0))}else for(let o=0;o<t;){let l=o,a=pe[o++]==2;for(;o<t&&a==(pe[o]==2);)o++;r.push(new Qt(l,o,a?1:2))}return r}function hc(i){return[new Qt(0,i,0)]}var cc="";function Km(i,e,t,n,s){var r;let o=n.head-i.from,l=-1;if(o==0){if(!s||!i.length)return null;e[0].level!=t&&(o=e[0].side(!1,t),l=0)}else if(o==i.length){if(s)return null;let f=e[e.length-1];f.level!=t&&(o=f.side(!0,t),l=e.length-1)}l<0&&(l=Qt.find(e,o,(r=n.bidiLevel)!==null&&r!==void 0?r:-1,n.assoc));let a=e[l];o==a.side(s,t)&&(a=e[l+=s?1:-1],o=a.side(!s,t));let u=s==(a.dir==t),h=_e(i.text,o,u);if(cc=i.text.slice(Math.min(o,h),Math.max(o,h)),h!=a.side(s,t))return P.cursor(h+i.from,u?-1:1,a.level);let c=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return!c&&a.level!=t?P.cursor(s?i.to:i.from,s?-1:1,t):c&&c.level<a.level?P.cursor(c.side(!s,t)+i.from,s?1:-1,c.level):P.cursor(h+i.from,s?-1:1,a.level)}var jt="\uFFFF",ur=class{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(X.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=jt}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let s=e;;){this.findPointBefore(n,s),this.readNode(s);let r=s.nextSibling;if(r==t)break;let o=ee.get(s),l=ee.get(r);(o&&l?o.breakAfter:(o?o.breakAfter:mh(s))||mh(r)&&(s.nodeName!="BR"||s.cmIgnore))&&this.lineBreak(),s=r}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(n,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);n=r+o}}readNode(e){if(e.cmIgnore)return;let t=ee.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let s=n.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+Math.min(t,n.offset))}};function mh(i){return i.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}var hr=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},cr=class extends ee{constructor(e){super(),this.view=e,this.compositionDeco=re.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new Oe],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new tt(0,0,0,e.state.doc.length)],0)}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:o,toA:l})=>l<this.minWidthFrom||o>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=re.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=qm(this.view,e.changes)),(W.ie||W.chrome)&&!this.compositionDeco.size&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let n=this.decorations,s=this.updateDeco(),r=Qm(n,s,e.changes);return t=tt.extendWithRanges(t,r),this.dirty==0&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=W.chrome||W.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(r),this.dirty=0,r&&(r.written||n.selectionRange.focusNode!=r.node)&&(this.forceSelection=!0),this.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.children)r instanceof Vt&&r.widget instanceof fr&&s.push(r.dom);n.updateGaps(s)}updateChildren(e,t){let n=this.childCursor(t);for(let s=e.length-1;;s--){let r=s>=0?e[s]:null;if(!r)break;let{fromA:o,toA:l,fromB:a,toB:u}=r,{content:h,breakAtStart:c,openStart:f,openEnd:d}=ss.build(this.view.state.doc,a,u,this.decorations,this.dynamicDecorationMap),{i:m,off:b}=n.findPos(l,1),{i:y,off:v}=n.findPos(o,-1);Uh(this,y,v,m,b,h,c,f,d)}}updateSelection(e=!1,t=!1){if((e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange(),!(t||this.mayControlSelection()))return;let n=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),o=s.empty?r:this.domAtPos(s.head);if(W.gecko&&s.empty&&Gm(r)){let a=document.createTextNode("");this.view.observer.ignore(()=>r.node.insertBefore(a,r.node.childNodes[r.offset]||null)),r=o=new Re(a,0),n=!0}let l=this.view.observer.selectionRange;(n||!l.focusNode||!sr(r.node,r.offset,l.anchorNode,l.anchorOffset)||!sr(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{W.android&&W.chrome&&this.dom.contains(l.focusNode)&&Jm(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let a=ir(this.view.root);if(a)if(s.empty){if(W.gecko){let u=jm(r.node,r.offset);if(u&&u!=3){let h=dc(r.node,r.offset,u==1?1:-1);h&&(r=new Re(h,u==1?0:h.nodeValue.length))}}a.collapse(r.node,r.offset),s.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=s.bidiLevel)}else if(a.extend){a.collapse(r.node,r.offset);try{a.extend(o.node,o.offset)}catch{}}else{let u=document.createRange();s.anchor>s.head&&([r,o]=[o,r]),u.setEnd(o.node,o.offset),u.setStart(r.node,r.offset),a.removeAllRanges(),a.addRange(u)}}),this.view.observer.setSelectionRange(r,o)),this.impreciseAnchor=r.precise?null:new Re(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new Re(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let{view:e}=this,t=e.state.selection.main,n=ir(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=Oe.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),u=this.coordsAt(t.head,1);if(!a||!u||a.bottom>u.top)return;let h=this.domAtPos(t.head+t.assoc);n.collapse(h.node,h.offset),n.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&n.collapse(s,r)}mayControlSelection(){let e=this.view.root.activeElement;return e==this.dom||Zs(this.dom,this.view.observer.selectionRange)&&!(e&&this.dom.contains(e))}nearest(e){for(let t=e;t;){let n=ee.get(t);if(n&&n.rootView==this)return n;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw new RangeError("Trying to find position for a DOM position outside of the document");return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let s=this.children[t];if(n<s.length||s instanceof Oe)break;t++,n=0}return this.children[t].domAtPos(n)}coordsAt(e,t){for(let n=this.length,s=this.children.length-1;;s--){let r=this.children[s],o=n-r.breakAfter-r.length;if(e>o||e==o&&r.type!=ue.WidgetBefore&&r.type!=ue.WidgetAfter&&(!s||t==2||this.children[s-1].breakAfter||this.children[s-1].type==ue.WidgetBefore&&t>-2))return r.coordsAt(e-o,t);n=o}}measureVisibleLineHeights(e){let t=[],{from:n,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==xe.LTR;for(let u=0,h=0;h<this.children.length;h++){let c=this.children[h],f=u+c.length;if(f>s)break;if(u>=n){let d=c.dom.getBoundingClientRect();if(t.push(d.height),o){let m=c.dom.lastChild,b=m?ns(m):[];if(b.length){let y=b[b.length-1],v=a?y.right-d.left:d.right-y.left;v>l&&(l=v,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=f)}}}u=f+c.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?xe.RTL:xe.LTR}measureTextSize(){for(let s of this.children)if(s instanceof Oe){let r=s.measureTextSize();if(r)return r}let e=document.createElement("div"),t,n;return e.className="cm-line",e.style.width="99999px",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let s=ns(e.firstChild)[0];t=e.getBoundingClientRect().height,n=s?s.width/27:7,e.remove()}),{lineHeight:t,charWidth:n}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new or(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>n){let l=t.lineBlockAt(o).bottom-t.lineBlockAt(n).top;e.push(re.replace({widget:new fr(l),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!r)break;n=r.to+1}return re.set(e)}updateDeco(){let e=this.view.state.facet(rs).map((t,n)=>(this.dynamicDecorationMap[n]=typeof t=="function")?t(this.view):t);for(let t=e.length;t<e.length+3;t++)this.dynamicDecorationMap[t]=!1;return this.decorations=[...e,this.compositionDeco,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(e){let{range:t}=e,n=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!n)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,s.left),top:Math.min(n.top,s.top),right:Math.max(n.right,s.right),bottom:Math.max(n.bottom,s.bottom)});let r=0,o=0,l=0,a=0;for(let h of this.view.state.facet(ac).map(c=>c(this.view)))if(h){let{left:c,right:f,top:d,bottom:m}=h;c!=null&&(r=Math.max(r,c)),f!=null&&(o=Math.max(o,f)),d!=null&&(l=Math.max(l,d)),m!=null&&(a=Math.max(a,m))}let u={left:n.left-r,top:n.top-l,right:n.right+o,bottom:n.bottom+a};Pm(this.view.scrollDOM,u,t.head<t.anchor?-1:1,e.x,e.y,e.xMargin,e.yMargin,this.view.textDirection==xe.LTR)}};function Gm(i){return i.node.nodeType==1&&i.node.firstChild&&(i.offset==0||i.node.childNodes[i.offset-1].contentEditable=="false")&&(i.offset==i.node.childNodes.length||i.node.childNodes[i.offset].contentEditable=="false")}var fr=class extends Lt{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}};function fc(i){let e=i.observer.selectionRange,t=e.focusNode&&dc(e.focusNode,e.focusOffset,0);if(!t)return null;let n=i.docView.nearest(t);if(!n)return null;if(n instanceof Oe){let s=t;for(;s.parentNode!=n.dom;)s=s.parentNode;let r=s.previousSibling;for(;r&&!ee.get(r);)r=r.previousSibling;let o=r?ee.get(r).posAtEnd:n.posAtStart;return{from:o,to:o,node:s,text:t}}else{for(;;){let{parent:r}=n;if(!r)return null;if(r instanceof Oe)break;n=r}let s=n.posAtStart;return{from:s,to:s+n.length,node:n.dom,text:t}}}function qm(i,e){let t=fc(i);if(!t)return re.none;let{from:n,to:s,node:r,text:o}=t,l=e.mapPos(n,1),a=Math.max(l,e.mapPos(s,-1)),{state:u}=i,h=r.nodeType==3?r.nodeValue:new ur([],u).readRange(r.firstChild,null).text;if(a-l<h.length)if(u.doc.sliceString(l,Math.min(u.doc.length,l+h.length),jt)==h)a=l+h.length;else if(u.doc.sliceString(Math.max(0,a-h.length),a,jt)==h)l=a-h.length;else return re.none;else if(u.doc.sliceString(l,a,jt)!=h)return re.none;let c=ee.get(r);return c instanceof lr?c=c.widget.topView:c&&(c.parent=null),re.set(re.replace({widget:new Jo(r,o,c),inclusive:!0}).range(l,a))}var Jo=class extends Lt{constructor(e,t,n){super(),this.top=e,this.text=t,this.topView=n}eq(e){return this.top==e.top&&this.text==e.text}toDOM(){return this.top}ignoreEvent(){return!1}get customView(){return lr}};function dc(i,e,t){for(;;){if(i.nodeType==3)return i;if(i.nodeType==1&&e>0&&t<=0)i=i.childNodes[e-1],e=is(i);else if(i.nodeType==1&&e<i.childNodes.length&&t>=0)i=i.childNodes[e],e=0;else return null}}function jm(i,e){return i.nodeType!=1?0:(e&&i.childNodes[e-1].contentEditable=="false"?1:0)|(e<i.childNodes.length&&i.childNodes[e].contentEditable=="false"?2:0)}var Xo=class{constructor(){this.changes=[]}compareRange(e,t){Go(e,t,this.changes)}comparePoint(e,t){Go(e,t,this.changes)}};function Qm(i,e,t){let n=new Xo;return le.compare(i,e,t,n),n.changes}function Jm(i,e){for(let t=i;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function Xm(i,e,t=1){let n=i.charCategorizer(e),s=i.doc.lineAt(e),r=e-s.from;if(s.length==0)return P.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=_e(s.text,r,!1):l=_e(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let u=_e(s.text,o,!1);if(n(s.text.slice(u,o))!=a)break;o=u}for(;l<s.length;){let u=_e(s.text,l);if(n(s.text.slice(l,u))!=a)break;l=u}return P.range(o+s.from,l+s.from)}function Ym(i,e){return e.left>i?e.left-i:Math.max(0,i-e.right)}function Zm(i,e){return e.top>i?e.top-i:Math.max(0,i-e.bottom)}function Io(i,e){return i.top<e.bottom-1&&i.bottom>e.top+1}function gh(i,e){return e<i.top?{top:e,left:i.left,right:i.right,bottom:i.bottom}:i}function bh(i,e){return e>i.bottom?{top:i.top,left:i.left,right:i.right,bottom:e}:i}function Yo(i,e,t){let n,s,r,o,l=!1,a,u,h,c;for(let m=i.firstChild;m;m=m.nextSibling){let b=ns(m);for(let y=0;y<b.length;y++){let v=b[y];s&&Io(s,v)&&(v=gh(bh(v,s.bottom),s.top));let A=Ym(e,v),C=Zm(t,v);if(A==0&&C==0)return m.nodeType==3?yh(m,e,t):Yo(m,e,t);(!n||o>C||o==C&&r>A)&&(n=m,s=v,r=A,o=C,l=!A||(A>0?y<b.length-1:y>0)),A==0?t>v.bottom&&(!h||h.bottom<v.bottom)?(a=m,h=v):t<v.top&&(!c||c.top>v.top)&&(u=m,c=v):h&&Io(h,v)?h=bh(h,v.bottom):c&&Io(c,v)&&(c=gh(c,v.top))}}if(h&&h.bottom>=t?(n=a,s=h):c&&c.top<=t&&(n=u,s=c),!n)return{node:i,offset:0};let f=Math.max(s.left,Math.min(s.right,e));if(n.nodeType==3)return yh(n,f,t);if(l&&n.contentEditable!="false")return Yo(n,f,t);let d=Array.prototype.indexOf.call(i.childNodes,n)+(e>=(s.left+s.right)/2?1:0);return{node:i,offset:d}}function yh(i,e,t){let n=i.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<n;l++){let a=di(i,l,l+1).getClientRects();for(let u=0;u<a.length;u++){let h=a[u];if(h.top==h.bottom)continue;o||(o=e-h.left);let c=(h.top>t?h.top-t:t-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&c<r){let f=e>=(h.left+h.right)/2,d=f;if((W.chrome||W.gecko)&&di(i,l).getBoundingClientRect().left==h.right&&(d=!f),c<=0)return{node:i,offset:l+(d?1:0)};s=l+(d?1:0),r=c}}}return{node:i,offset:s>-1?s:o>0?i.nodeValue.length:0}}function pc(i,{x:e,y:t},n,s=-1){var r;let o=i.contentDOM.getBoundingClientRect(),l=o.top+i.viewState.paddingTop,a,{docHeight:u}=i.viewState,h=t-l;if(h<0)return 0;if(h>u)return i.state.doc.length;for(let v=i.defaultLineHeight/2,A=!1;a=i.elementAtHeight(h),a.type!=ue.Text;)for(;h=s>0?a.bottom+v:a.top-v,!(h>=0&&h<=u);){if(A)return n?null:0;A=!0,s=-s}t=l+h;let c=a.from;if(c<i.viewport.from)return i.viewport.from==0?0:n?null:wh(i,o,a,e,t);if(c>i.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:n?null:wh(i,o,a,e,t);let f=i.dom.ownerDocument,d=i.root.elementFromPoint?i.root:f,m=d.elementFromPoint(e,t);m&&!i.contentDOM.contains(m)&&(m=null),m||(e=Math.max(o.left+1,Math.min(o.right-1,e)),m=d.elementFromPoint(e,t),m&&!i.contentDOM.contains(m)&&(m=null));let b,y=-1;if(m&&((r=i.docView.nearest(m))===null||r===void 0?void 0:r.isEditable)!=!1){if(f.caretPositionFromPoint){let v=f.caretPositionFromPoint(e,t);v&&({offsetNode:b,offset:y}=v)}else if(f.caretRangeFromPoint){let v=f.caretRangeFromPoint(e,t);v&&({startContainer:b,startOffset:y}=v,(!i.contentDOM.contains(b)||W.safari&&eg(b,y,e)||W.chrome&&tg(b,y,e))&&(b=void 0))}}if(!b||!i.docView.dom.contains(b)){let v=Oe.find(i.docView,c);if(!v)return h>a.top+a.height/2?a.to:a.from;({node:b,offset:y}=Yo(v.dom,e,t))}return i.docView.posFromDOM(b,y)}function wh(i,e,t,n,s){let r=Math.round((n-e.left)*i.defaultCharacterWidth);if(i.lineWrapping&&t.height>i.defaultLineHeight*1.5){let l=Math.floor((s-t.top)/i.defaultLineHeight);r+=l*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+ih(o,r,i.state.tabSize)}function eg(i,e,t){let n;if(i.nodeType!=3||e!=(n=i.nodeValue.length))return!1;for(let s=i.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return di(i,n-1,n).getBoundingClientRect().left>t}function tg(i,e,t){if(e!=0)return!1;for(let s=i;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let n=i.nodeType==1?i.getBoundingClientRect():di(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return t-n.left>5}function ng(i,e,t,n){let s=i.state.doc.lineAt(e.head),r=!n||!i.lineWrapping?null:i.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let a=i.dom.getBoundingClientRect(),u=i.textDirectionAt(s.from),h=i.posAtCoords({x:t==(u==xe.LTR)?a.right-1:a.left+1,y:(r.top+r.bottom)/2});if(h!=null)return P.cursor(h,t?-1:1)}let o=Oe.find(i.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?s.to:s.from;return P.cursor(l,t?-1:1)}function vh(i,e,t,n){let s=i.state.doc.lineAt(e.head),r=i.bidiSpans(s),o=i.textDirectionAt(s.from);for(let l=e,a=null;;){let u=Km(s,r,o,l,t),h=cc;if(!u){if(s.number==(t?i.state.doc.lines:1))return l;h=`
8
+ `,s=i.state.doc.line(s.number+(t?1:-1)),r=i.bidiSpans(s),u=P.cursor(t?s.from:s.to)}if(a){if(!a(h))return l}else{if(!n)return u;a=n(h)}l=u}}function ig(i,e,t){let n=i.state.charCategorizer(e),s=n(t);return r=>{let o=n(r);return s==ct.Space&&(s=o),s==o}}function sg(i,e,t,n){let s=e.head,r=t?1:-1;if(s==(t?i.state.doc.length:0))return P.cursor(s,e.assoc);let o=e.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),u=i.coordsAtPos(s),h=i.documentTop;if(u)o==null&&(o=u.left-a.left),l=r<0?u.top:u.bottom;else{let d=i.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+h}let c=a.left+o,f=n!=null?n:i.defaultLineHeight>>1;for(let d=0;;d+=10){let m=l+(f+d)*r,b=pc(i,{x:c,y:m},!1,r);if(m<a.top||m>a.bottom||(r<0?b<s:b>s))return P.cursor(b,e.assoc,void 0,o)}}function Lo(i,e,t){let n=i.state.facet(lc).map(s=>s(i));for(;;){let s=!1;for(let r of n)r.between(t.from-1,t.from+1,(o,l,a)=>{t.from>o&&t.from<l&&(t=e.head>t.from?P.cursor(o,1):P.cursor(l,-1),s=!0)});if(!s)return t}}var Zo=class{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.mouseSelection=null;for(let t in Ee){let n=Ee[t];e.contentDOM.addEventListener(t,s=>{!Ch(e,s)||this.ignoreDuringComposition(s)||t=="keydown"&&this.keydown(e,s)||(this.mustFlushObserver(s)&&e.observer.forceFlush(),this.runCustomHandlers(t,e,s)?s.preventDefault():n(e,s))},tl[t]),this.registeredEvents.push(t)}W.chrome&&W.chrome_version==102&&e.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?e.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,e.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=e.hasFocus,W.safari&&e.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e,t){var n;let s;this.customHandlers=[];for(let r of t)if(s=(n=r.update(e).spec)===null||n===void 0?void 0:n.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let o in s)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{Ch(e,l)&&this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,n){for(let s of this.customHandlers){let r=s.handlers[e];if(r)try{if(r.call(s.plugin,n,t)||n.defaultPrevented)return!0}catch(o){It(t.state,o)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let n of this.customHandlers){let s=n.handlers.scroll;if(s)try{s.call(n.plugin,t,e)}catch(r){It(e.state,r)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(W.android&&W.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return e.observer.delayAndroidKey(t.key,t.keyCode),!0;let n;return W.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((n=mc.find(s=>s.keyCode==t.keyCode))&&!t.ctrlKey||rg.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=n||t,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,ci(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:W.safari&&!W.ios&&Date.now()-this.compositionEndedAt<100?(this.compositionEndedAt=0,!0):!1:!1}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}},mc=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],rg="dthko",gc=[16,17,18,20,91,92,224,225],el=class{constructor(e,t,n,s){this.view=e,this.style=n,this.mustSelect=s,this.lastEvent=t;let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(X.allowMultipleSelections)&&og(e,t),this.dragMove=lg(e,t),this.dragging=ag(e,t)&&vc(t)==1?null:!1,this.dragging===!1&&(t.preventDefault(),this.select(t))}move(e){if(e.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=e)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(e){let t=this.style.get(e,this.extend,this.multiple);(this.mustSelect||!t.eq(this.view.state.selection)||t.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:t,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function og(i,e){let t=i.state.facet(Zh);return t.length?t[0](e):W.mac?e.metaKey:e.ctrlKey}function lg(i,e){let t=i.state.facet(ec);return t.length?t[0](e):W.mac?!e.altKey:!e.ctrlKey}function ag(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=ir(i.root);if(!n||n.rangeCount==0)return!0;let s=n.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Ch(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=ee.get(t))&&n.ignoreEvent(e))return!1;return!0}var Ee=Object.create(null),tl=Object.create(null),bc=W.ie&&W.ie_version<15||W.ios&&W.webkit_version<604;function ug(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),yc(i,t.value)},50)}function yc(i,e){let{state:t}=i,n,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(nl!=null&&t.selection.ranges.every(a=>a.empty)&&nl==r.toString()){let a=-1;n=t.changeByRange(u=>{let h=t.doc.lineAt(u.from);if(h.from==a)return{range:u};a=h.from;let c=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:c},range:P.cursor(u.from+c.length)}})}else o?n=t.changeByRange(a=>{let u=r.line(s++);return{changes:{from:a.from,to:a.to,insert:u.text},range:P.cursor(a.from+u.length)}}):n=t.replaceSelection(r);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}Ee.keydown=(i,e)=>{i.inputState.setSelectionOrigin("select"),e.keyCode==27?i.inputState.lastEscPress=Date.now():gc.indexOf(e.keyCode)<0&&(i.inputState.lastEscPress=0)};Ee.touchstart=(i,e)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin("select.pointer")};Ee.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};tl.touchstart=tl.touchmove={passive:!0};Ee.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let n of i.state.facet(tc))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=fg(i,e)),t){let n=i.root.activeElement!=i.contentDOM;n&&i.observer.ignore(()=>$h(i.contentDOM)),i.inputState.startMouseSelection(new el(i,e,t,n))}};function xh(i,e,t,n){if(n==1)return P.cursor(e,t);if(n==2)return Xm(i.state,e,t);{let s=Oe.find(i.docView,e),r=i.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<i.state.doc.length&&l==r.to&&l++,P.range(o,l)}}var wc=(i,e)=>i>=e.top&&i<=e.bottom,Sh=(i,e,t)=>wc(e,t)&&i>=t.left&&i<=t.right;function hg(i,e,t,n){let s=Oe.find(i.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Sh(t,n,o))return-1;let l=s.coordsAt(r,1);return l&&Sh(t,n,l)?1:o&&wc(n,o)?-1:1}function kh(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:hg(i,t,e.clientX,e.clientY)}}var cg=W.ie&&W.ie_version<=11,Mh=null,Th=0,Ah=0;function vc(i){if(!cg)return i.detail;let e=Mh,t=Ah;return Mh=i,Ah=Date.now(),Th=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(Th+1)%3:1}function fg(i,e){let t=kh(i,e),n=vc(e),s=i.state.selection,r=t,o=e;return{update(l){l.docChanged&&(t.pos=l.changes.mapPos(t.pos),s=s.map(l.changes),o=null)},get(l,a,u){let h;o&&l.clientX==o.clientX&&l.clientY==o.clientY?h=r:(h=r=kh(i,l),o=l);let c=xh(i,h.pos,h.bias,n);if(t.pos!=h.pos&&!a){let f=xh(i,t.pos,t.bias,n),d=Math.min(f.from,c.from),m=Math.max(f.to,c.to);c=d<c.from?P.range(d,m):P.range(m,d)}return a?s.replaceRange(s.main.extend(c.from,c.to)):u&&s.ranges.length>1&&s.ranges.some(f=>f.eq(c))?dg(s,c):u?s.addRange(c):P.create([c])}}}function dg(i,e){for(let t=0;;t++)if(i.ranges[t].eq(e))return P.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}Ee.dragstart=(i,e)=>{let{selection:{main:t}}=i.state,{mouseSelection:n}=i.inputState;n&&(n.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",i.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function Rh(i,e,t,n){if(!t)return;let s=i.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:r}=i.inputState,o=n&&r&&r.dragging&&r.dragMove?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:t},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}Ee.drop=(i,e)=>{if(!e.dataTransfer)return;if(i.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let n=Array(t.length),s=0,r=()=>{++s==t.length&&Rh(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(n[o]=l.result),r()},l.readAsText(t[o])}}else Rh(i,e,e.dataTransfer.getData("Text"),!0)};Ee.paste=(i,e)=>{if(i.state.readOnly)return e.preventDefault();i.observer.flush();let t=bc?null:e.clipboardData;t?(yc(i,t.getData("text/plain")),e.preventDefault()):ug(i)};function pg(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),i.focus()},50)}function mg(i){let e=[],t=[],n=!1;for(let s of i.selection.ranges)s.empty||(e.push(i.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of i.selection.ranges){let o=i.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),s=o.number}n=!0}return{text:e.join(i.lineBreak),ranges:t,linewise:n}}var nl=null;Ee.copy=Ee.cut=(i,e)=>{let{text:t,ranges:n,linewise:s}=mg(i.state);if(!t&&!s)return;nl=s?t:null;let r=bc?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",t)):pg(i,t),e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"})};function Cc(i){setTimeout(()=>{i.hasFocus!=i.inputState.notifiedFocused&&i.update([])},10)}Ee.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),Cc(i)};Ee.blur=i=>{i.observer.clearSelectionRange(),Cc(i)};Ee.compositionstart=Ee.compositionupdate=i=>{i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0)};Ee.compositionend=i=>{i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionFirstChange=null,W.chrome&&W.android&&i.observer.flushSoon(),setTimeout(()=>{i.inputState.composing<0&&i.docView.compositionDeco.size&&i.update([])},50)};Ee.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};Ee.beforeinput=(i,e)=>{var t;let n;if(W.chrome&&W.android&&(n=mc.find(s=>s.inputType==e.inputType))&&(i.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let s=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}};var Eh=["pre-wrap","normal","pre-line","break-spaces"],il=class{constructor(e){this.lineWrapping=e,this.doc=J.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength)),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Eh.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let s=e[n];s<0?n++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,n,s,r){let o=Eh.indexOf(e)>-1,l=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=n,this.lineLength=s,l){this.heightSamples={};for(let a=0;a<r.length;a++){let u=r[a];u<0?a++:this.heightSamples[Math.floor(u*10)]=!0}}return l}},sl=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},xt=class{constructor(e,t,n,s,r){this.from=e,this.length=t,this.top=n,this.height=s,this.type=r}get to(){return this.from+this.length}get bottom(){return this.top+this.height}join(e){let t=(Array.isArray(this.type)?this.type:[this]).concat(Array.isArray(e.type)?e.type:[e]);return new xt(this.from,this.length+e.length,this.top,this.height+e.height,t)}},se=function(i){return i[i.ByPos=0]="ByPos",i[i.ByHeight=1]="ByHeight",i[i.ByPosNoHeight=2]="ByPosNoHeight",i}(se||(se={})),er=.001,Ve=class{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>er&&(e.heightChanged=!0),this.height=t)}replace(e,t,n){return Ve.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,s){let r=this;for(let o=s.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:u,toB:h}=s[o],c=r.lineAt(l,se.ByPosNoHeight,t,0,0),f=c.to>=a?c:r.lineAt(a,se.ByPosNoHeight,t,0,0);for(h+=f.to-a,a=f.to;o>0&&c.from<=s[o-1].toA;)l=s[o-1].fromA,u=s[o-1].fromB,o--,l<c.from&&(c=r.lineAt(l,se.ByPosNoHeight,t,0,0));u+=c.from-l,l=c.from;let d=os.build(n,e,u,h);r=r.replace(l,a,d)}return r.updateHeight(n,0)}static empty(){return new $e(0,0)}static of(e){if(e.length==1)return e[0];let t=0,n=e.length,s=0,r=0;for(;;)if(t==n)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),n+=1+l.break,s-=l.size}else if(r>s*2){let l=e[n];l.break?e.splice(n,1,l.left,null,l.right):e.splice(n,1,l.left,l.right),n+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--n];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,n++),new rl(Ve.of(e.slice(0,t)),o,Ve.of(e.slice(n)))}};Ve.prototype.size=1;var dr=class extends Ve{constructor(e,t,n){super(e,t),this.type=n}blockAt(e,t,n,s){return new xt(s,this.length,n,this.height,this.type)}lineAt(e,t,n,s,r){return this.blockAt(0,n,s,r)}forEachLine(e,t,n,s,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,n,s,r))}updateHeight(e,t=0,n=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},$e=class extends dr{constructor(e,t){super(e,t,ue.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,n){let s=n[0];return n.length==1&&(s instanceof $e||s instanceof Me&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof Me?s=new $e(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):Ve.of(n)}updateHeight(e,t=0,n=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(n||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Me=class extends Ve{constructor(e){super(e,0)}lines(e,t){let n=e.lineAt(t).number,s=e.lineAt(t+this.length).number;return{firstLine:n,lastLine:s,lineHeight:this.height/(s-n+1)}}blockAt(e,t,n,s){let{firstLine:r,lastLine:o,lineHeight:l}=this.lines(t,s),a=Math.max(0,Math.min(o-r,Math.floor((e-n)/l))),{from:u,length:h}=t.line(r+a);return new xt(u,h,n+l*a,l,ue.Text)}lineAt(e,t,n,s,r){if(t==se.ByHeight)return this.blockAt(e,n,s,r);if(t==se.ByPosNoHeight){let{from:c,to:f}=n.lineAt(e);return new xt(c,f-c,0,0,ue.Text)}let{firstLine:o,lineHeight:l}=this.lines(n,r),{from:a,length:u,number:h}=n.lineAt(e);return new xt(a,u,s+l*(h-o),l,ue.Text)}forEachLine(e,t,n,s,r,o){let{firstLine:l,lineHeight:a}=this.lines(n,r);for(let u=Math.max(e,r),h=Math.min(r+this.length,t);u<=h;){let c=n.lineAt(u);u==e&&(s+=a*(c.number-l)),o(new xt(c.from,c.length,s,a,ue.Text)),s+=a,u=c.to+1}}replace(e,t,n){let s=this.length-t;if(s>0){let r=n[n.length-1];r instanceof Me?n[n.length-1]=new Me(r.length+s):n.push(null,new Me(s-1))}if(e>0){let r=n[0];r instanceof Me?n[0]=new Me(e+r.length):n.unshift(new Me(e-1),null)}return Ve.of(n)}decomposeLeft(e,t){t.push(new Me(e-1),null)}decomposeRight(e,t){t.push(null,new Me(this.length-e-1))}updateHeight(e,t=0,n=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1,u=e.heightChanged;for(s.from>t&&o.push(new Me(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=er&&(a=-2);let d=new $e(c,f);d.outdated=!1,o.push(d),l+=c+1}l<=r&&o.push(null,new Me(r-l).updateHeight(e,l));let h=Ve.of(o);return e.heightChanged=u||a<0||Math.abs(h.height-this.height)>=er||Math.abs(a-this.lines(e.doc,t).lineHeight)>=er,h}else(n||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},rl=class extends Ve{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,s){let r=n+this.left.height;return e<r?this.left.blockAt(e,t,n,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,n,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==se.ByHeight?e<o:e<l,u=a?this.left.lineAt(e,t,n,s,r):this.right.lineAt(e,t,n,o,l);if(this.break||(a?u.to<l:u.from>l))return u;let h=t==se.ByPosNoHeight?se.ByPosNoHeight:se.ByPos;return a?u.join(this.right.lineAt(l,h,n,o,l)):this.left.lineAt(l,h,n,s,r).join(u)}forEachLine(e,t,n,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,n,s,r,o),t>=a&&this.right.forEachLine(e,t,n,l,a,o);else{let u=this.lineAt(a,se.ByPos,n,s,r);e<u.from&&this.left.forEachLine(e,u.from-1,n,s,r,o),u.to>=e&&u.from<=t&&o(u),t>u.to&&this.right.forEachLine(u.to+1,t,n,l,a,o)}}replace(e,t,n){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,n));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of n)r.push(l);if(e>0&&Dh(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Dh(r,l)}return Ve.of(r)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,s=n+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Ve.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,n,s):r.updateHeight(e,t,n),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,n,s):o.updateHeight(e,l,n),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Dh(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof Me&&(n=i[e+1])instanceof Me&&i.splice(e-1,3,new Me(t.length+1+n.length))}var gg=5,os=class{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let n=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof $e?s.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new $e(n-this.pos,-1)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let s=n.widget?n.widget.estimatedHeight:0;s<0&&(s=this.oracle.lineHeight);let r=t-e;n.block?this.addBlock(new dr(r,s,n.type)):(r||s>=gg)&&this.addLineDeco(s,r)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new $e(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let n=new Me(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof $e)return e;let t=new $e(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type==ue.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=ue.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let n=this.ensureLine();n.length+=t,n.collapsed+=t,n.widgetHeight=Math.max(n.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof $e)&&!this.isCovered?this.nodes.push(new $e(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let s of this.nodes)s instanceof $e&&s.updateHeight(this.oracle,n),n+=s?s.length:1;return this.nodes}static build(e,t,n,s){let r=new os(n,e);return le.spans(t,n,s,r,0),r.finish(n)}};function bg(i,e,t){let n=new ol;return le.compare(i,e,t,n,0),n.changes}var ol=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,s){(e<t||n&&n.heightRelevant||s&&s.heightRelevant)&&Go(e,t,this.changes,5)}};function yg(i,e){let t=i.getBoundingClientRect(),n=i.ownerDocument,s=n.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let u=i.parentNode;u&&u!=n.body;)if(u.nodeType==1){let h=u,c=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let f=h.getBoundingClientRect();r=Math.max(r,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=u==i.parentNode?f.bottom:Math.min(a,f.bottom)}u=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function wg(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var ts=class{constructor(e,t,n){this.from=e,this.to=t,this.size=n}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let s=e[n],r=t[n];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e){return re.replace({widget:new ll(this.size,e)}).range(this.from,this.to)}},ll=class extends Lt{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},pr=class{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaler=Ph,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=xe.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(xl).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new il(t),this.stateDeco=e.facet(rs).filter(n=>typeof n!="function"),this.heightMap=Ve.empty().applyChanges(this.stateDeco,J.empty,this.heightOracle.setDoc(e.doc),[new tt(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=re.set(this.lineGaps.map(n=>n.draw(!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let s=n?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new hi(r,o))}}this.viewports=e.sort((n,s)=>n.from-s.from),this.scaler=this.heightMap.height<=7e6?Ph:new al(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:Zi(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(rs).filter(u=>typeof u!="function");let s=e.changedRanges,r=tt.extendWithRanges(s,bg(n,this.stateDeco,e?e.changes:fe.empty(this.state.doc.length))),o=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2);let l=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<l.from||t.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let a=!e.changes.empty||e.flags&2||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),a&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(rc)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,n=window.getComputedStyle(t),s=this.heightOracle,r=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?xe.RTL:xe.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=o||this.mustMeasureContent||this.contentDOMHeight!=t.clientHeight;this.contentDOMHeight=t.clientHeight,this.mustMeasureContent=!1;let a=0,u=0,h=parseInt(n.paddingTop)||0,c=parseInt(n.paddingBottom)||0;(this.paddingTop!=h||this.paddingBottom!=c)&&(this.paddingTop=h,this.paddingBottom=c,a|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,a|=8);let f=(this.printing?wg:yg)(t,this.paddingTop),d=f.top-this.pixelViewport.top,m=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let y=t.clientWidth;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=y,this.editorHeight=e.scrollDOM.clientHeight,a|=8),l){let A=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(A)&&(o=!0),o||s.lineWrapping&&Math.abs(y-this.contentDOMWidth)>s.charWidth){let{lineHeight:C,charWidth:T}=e.docView.measureTextSize();o=C>0&&s.refresh(r,C,T,y/T,A),o&&(e.docView.minWidth=0,a|=8)}d>0&&m>0?u=Math.max(d,m):d<0&&m<0&&(u=Math.min(d,m)),s.heightChanged=!1;for(let C of this.viewports){let T=C.from==this.viewport.from?A:e.docView.measureVisibleLineHeights(C);this.heightMap=(o?Ve.empty().applyChanges(this.stateDeco,J.empty,this.heightOracle,[new tt(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new sl(C.from,T))}s.heightChanged&&(a|=2)}let v=!this.viewportIsAppropriate(this.viewport,u)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return v&&(this.viewport=this.getViewport(u,this.scrollTarget)),this.updateForViewport(),(a&2||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.state.doc,{visibleTop:o,visibleBottom:l}=this,a=new hi(s.lineAt(o-n*1e3,se.ByHeight,r,0,0).from,s.lineAt(l+(1-n)*1e3,se.ByHeight,r,0,0).to);if(t){let{head:u}=t.range;if(u<a.from||u>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=s.lineAt(u,se.ByPos,r,0,0),f;t.y=="center"?f=(c.top+c.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&u<a.from?f=c.top:f=c.bottom-h,a=new hi(s.lineAt(f-1e3/2,se.ByHeight,r,0,0).from,s.lineAt(f+h+1e3/2,se.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let n=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new hi(this.heightMap.lineAt(n,se.ByPos,this.state.doc,0,0).from,this.heightMap.lineAt(s,se.ByPos,this.state.doc,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,se.ByPos,this.state.doc,0,0),{bottom:r}=this.heightMap.lineAt(t,se.ByPos,this.state.doc,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(n,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let s of e)t.touchesRange(s.from,s.to)||n.push(new ts(t.mapPos(s.from),t.mapPos(s.to),s.size));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,s=n?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=xe.LTR&&!n)return[];let l=[],a=(u,h,c,f)=>{if(h-u<r)return;let d=this.state.selection.main,m=[d.from];d.empty||m.push(d.to);for(let y of m)if(y>u&&y<h){a(u,y-10,c,f),a(y+10,h,c,f);return}let b=Cg(e,y=>y.from>=c.from&&y.to<=c.to&&Math.abs(y.from-u)<r&&Math.abs(y.to-h)<r&&!m.some(v=>y.from<v&&y.to>v));if(!b){if(h<c.to&&t&&n&&t.visibleRanges.some(y=>y.from<=h&&y.to>=h)){let y=t.moveToLineBoundary(P.cursor(h),!1,!0).head;y>u&&(h=y)}b=new ts(u,h,this.gapSize(c,u,h,f))}l.push(b)};for(let u of this.viewportLines){if(u.length<o)continue;let h=vg(u.from,u.to,this.stateDeco);if(h.total<o)continue;let c=this.scrollTarget?this.scrollTarget.range.head:null,f,d;if(n){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,y;if(c!=null){let v=Js(h,c),A=((this.visibleBottom-this.visibleTop)/2+m)/u.height;b=v-A,y=v+A}else b=(this.visibleTop-u.top-m)/u.height,y=(this.visibleBottom-u.top+m)/u.height;f=Qs(h,b),d=Qs(h,y)}else{let m=h.total*this.heightOracle.charWidth,b=s*this.heightOracle.charWidth,y,v;if(c!=null){let A=Js(h,c),C=((this.pixelViewport.right-this.pixelViewport.left)/2+b)/m;y=A-C,v=A+C}else y=(this.pixelViewport.left-b)/m,v=(this.pixelViewport.right+b)/m;f=Qs(h,y),d=Qs(h,v)}f>u.from&&a(u.from,f,u,h),d<u.to&&a(d,u.to,u,h)}return l}gapSize(e,t,n,s){let r=Js(s,n)-Js(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){ts.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=re.set(e.map(t=>t.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];le.spans(e,this.viewport.from,this.viewport.to,{span(s,r){t.push({from:s,to:r})},point(){}},20);let n=t.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=t[r].from||s.to!=t[r].to);return this.visibleRanges=t,n?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Zi(this.heightMap.lineAt(e,se.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(e){return Zi(this.heightMap.lineAt(this.scaler.fromDOM(e),se.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(e){return Zi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},hi=class{constructor(e,t){this.from=e,this.to=t}};function vg(i,e,t){let n=[],s=i,r=0;return le.spans(t,i,e,{span(){},point(o,l){o>s&&(n.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(n.push({from:s,to:e}),r+=e-s),{total:r,ranges:n}}function Qs({total:i,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(n<=l)return r+n;n-=l}}function Js(i,e){let t=0;for(let{from:n,to:s}of i.ranges){if(e<=s){t+=e-n;break}t+=s-n}return t/i.total}function Cg(i,e){for(let t of i)if(e(t))return t}var Ph={toDOM(i){return i},fromDOM(i){return i},scale:1},al=class{constructor(e,t,n){let s=0,r=0,o=0;this.viewports=n.map(({from:l,to:a})=>{let u=t.lineAt(l,se.ByPos,e,0,0).top,h=t.lineAt(a,se.ByPos,e,0,0).bottom;return s+=h-u,{from:l,to:a,top:u,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,n=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-n)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);n=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,n=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return n+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);n=r.bottom,s=r.domBottom}}};function Zi(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new xt(i.from,i.length,t,n-t,Array.isArray(i.type)?i.type.map(s=>Zi(s,e)):i.type)}var Xs=$.define({combine:i=>i.join(" ")}),ul=$.define({combine:i=>i.indexOf(!0)>-1}),hl=et.newName(),xc=et.newName(),Sc=et.newName(),kc={"&light":"."+xc,"&dark":"."+Sc};function cl(i,e,t){return new et(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,s=>{if(s=="&")return i;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):i+" "+n}})}var xg=cl("."+hl,{"&.cm-editor":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},kc),fl=class{constructor(e,t,n,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let l=r||o?[]:kg(e),a=new ur(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Mg(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!fi(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),u=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!fi(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=P.single(u,a)}}};function Mc(i,e){let t,{newSel:n}=e,s=i.state.selection.main;if(e.bounds){let{from:r,to:o}=e.bounds,l=s.from,a=null;(i.inputState.lastKeyCode===8&&i.inputState.lastKeyTime>Date.now()-100||W.android&&e.text.length<o-r)&&(l=s.to,a="end");let u=Sg(i.state.doc.sliceString(r,o,jt),e.text,l-r,a);u&&(W.chrome&&i.inputState.lastKeyCode==13&&u.toB==u.from+2&&e.text.slice(u.from,u.toB)==jt+jt&&u.toB--,t={from:r+u.from,to:r+u.toA,insert:J.of(e.text.slice(u.from,u.toB).split(jt))})}else n&&(!i.hasFocus||!i.state.facet(br)||n.main.eq(s))&&(n=null);if(!t&&!n)return!1;if(!t&&e.typeOver&&!s.empty&&n&&n.main.empty?t={from:s.from,to:s.to,insert:i.state.doc.slice(s.from,s.to)}:t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:i.state.doc.slice(s.from,t.from).append(t.insert).append(i.state.doc.slice(t.to,s.to))}:(W.mac||W.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())?(n&&t.insert.length==2&&(n=P.single(n.main.anchor-1,n.main.head-1)),t={from:s.from,to:s.to,insert:J.of([" "])}):W.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
9
+ `&&i.lineWrapping&&(n&&(n=P.single(n.main.anchor-1,n.main.head-1)),t={from:s.from,to:s.to,insert:J.of([" "])}),t){let r=i.state;if(W.ios&&i.inputState.flushIOSKey(i)||W.android&&(t.from==s.from&&t.to==s.to&&t.insert.length==1&&t.insert.lines==2&&ci(i.contentDOM,"Enter",13)||t.from==s.from-1&&t.to==s.to&&t.insert.length==0&&ci(i.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&ci(i.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();if(i.state.facet(ic).some(u=>u(i,t.from,t.to,o)))return!0;i.inputState.composing>=0&&i.inputState.composing++;let l;if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&i.inputState.composing<0){let u=s.from<t.from?r.sliceDoc(s.from,t.from):"",h=s.to>t.to?r.sliceDoc(t.to,s.to):"";l=r.replaceSelection(i.state.toText(u+t.insert.sliceString(0,void 0,i.state.lineBreak)+h))}else{let u=r.changes(t),h=n&&!r.selection.main.eq(n.main)&&n.main.to<=u.newLength?n.main:void 0;if(r.selection.ranges.length>1&&i.inputState.composing>=0&&t.to<=s.to&&t.to>=s.to-10){let c=i.state.sliceDoc(t.from,t.to),f=fc(i)||i.state.doc.lineAt(s.head),d=s.to-t.to,m=s.to-s.from;l=r.changeByRange(b=>{if(b.from==s.from&&b.to==s.to)return{changes:u,range:h||b.map(u)};let y=b.to-d,v=y-c.length;if(b.to-b.from!=m||i.state.sliceDoc(v,y)!=c||f&&b.to>=f.from&&b.from<=f.to)return{range:b};let A=r.changes({from:v,to:y,insert:t.insert}),C=b.to-s.to;return{changes:A,range:h?P.range(Math.max(0,h.anchor+C),Math.max(0,h.head+C)):b.map(A)}})}else l={changes:u,selection:h&&r.selection.replaceRange(h)}}let a="input.type";return i.composing&&(a+=".compose",i.inputState.compositionFirstChange&&(a+=".start",i.inputState.compositionFirstChange=!1)),i.dispatch(l,{scrollIntoView:!0,userEvent:a}),!0}else if(n&&!n.main.eq(s)){let r=!1,o="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(r=!0),o=i.inputState.lastSelectionOrigin),i.dispatch({selection:n,scrollIntoView:r,userEvent:o}),!0}else return!1}function Sg(i,e,t,n){let s=Math.min(i.length,e.length),r=0;for(;r<s&&i.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&i.length==e.length)return null;let o=i.length,l=e.length;for(;o>0&&l>0&&i.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(n=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&i.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function kg(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:s,focusOffset:r}=i.observer.selectionRange;return t&&(e.push(new hr(t,n)),(s!=t||r!=n)&&e.push(new hr(s,r))),e}function Mg(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t>-1&&n>-1?P.single(t+e,n+e):null}var Tg={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},No=W.ie&&W.ie_version<=11,dl=class{constructor(e){this.view=e,this.active=!1,this.selectionRange=new Fo,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let n of t)this.queue.push(n);(W.ie&&W.ie_version<=11||W.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),No&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resize.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runScrollHandlers(this.view,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,s=this.selectionRange;if(n.state.facet(br)?n.root.activeElement!=this.dom:!Zs(n.dom,s))return;let r=s.anchorNode&&n.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(W.ie&&W.ie_version<=11||W.android&&W.chrome)&&!n.state.selection.main.empty&&s.focusNode&&sr(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=W.safari&&e.root.nodeType==11&&Em(this.dom.ownerDocument)==this.dom&&Ag(this.view)||ir(e.root);if(!t||this.selectionRange.eq(t))return!1;let n=Zs(this.dom,t);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Vm(this.dom,t)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(t),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(n.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);for(let n of this.scrollTargets=t)n.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Tg),No&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),No&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var n;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),!this.flush()&&r.force&&ci(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((n=this.delayedAndroidKey)===null||n===void 0)&&n.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}processRecords(){let e=this.queue;for(let r of this.observer.takeRecords())e.push(r);e.length&&(this.queue=[]);let t=-1,n=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:s}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),s=this.selectionChanged&&Zs(this.dom,this.selectionRange);return e<0&&!s?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new fl(this.view,e,t,n))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let n=this.view.state,s=Mc(this.view,t);return this.view.state==n&&this.view.update([]),s}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.dirty|=4),e.type=="childList"){let n=Oh(t,e.previousSibling||e.target.previousSibling,-1),s=Oh(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resize)===null||n===void 0||n.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}};function Oh(i,e,t){for(;e;){let n=ee.get(e);if(n&&n.parent==i)return n;let s=e.parentNode;e=s!=i.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function Ag(i){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(i.contentDOM.addEventListener("beforeinput",t,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let n=e.startContainer,s=e.startOffset,r=e.endContainer,o=e.endOffset,l=i.docView.domAtPos(i.state.selection.main.anchor);return sr(l.node,l.offset,r,o)&&([n,s,r,o]=[r,o,n,s]),{anchorNode:n,anchorOffset:s,focusNode:r,focusOffset:o}}var j=class{constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this._root=e.root||Om(e.parent)||document,this.viewState=new pr(e.state||X.create(e)),this.plugins=this.state.facet(Xi).map(t=>new es(t));for(let t of this.plugins)t.update(this);this.observer=new dl(this),this.inputState=new Zo(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new cr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof de?e[0]:this.state.update(...e))}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.observer.delayedAndroidKey,l=null;if(o?(this.observer.clearDelayedAndroidKey(),l=this.observer.readChange(),(l&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(l=null)):this.observer.clear(),r.facet(X.phrases)!=this.state.facet(X.phrases))return this.setState(r);s=gi.create(this,r,e);let a=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(a&&(a=a.map(u.changes)),u.scrollIntoView){let{main:h}=u.state.selection;a=new mi(h.empty?h:P.cursor(h.head,h.head>h.anchor?-1:1))}for(let h of u.effects)h.is(ph)&&(a=h.value)}this.viewState.update(s,a),this.bidiCache=bi.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(Yi)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Xs)!=s.state.facet(Xs)&&(this.viewState.mustMeasureContent=!0),(t||n||a||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let u of this.state.facet(qo))u(s);l&&!Mc(this,l)&&o.force&&ci(this.contentDOM,o.key,o.keyCode)}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new pr(e),this.plugins=e.facet(Xi).map(n=>new es(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView=new cr(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Xi),n=e.state.facet(Xi);if(t!=n){let s=[];for(let r of n){let o=t.indexOf(r);if(o<0)s.push(new es(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this)}measure(e=!0){if(this.destroyed)return;this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:n,scrollTop:s,clientHeight:r}=this.scrollDOM,o=s>n-r-4?n:s;try{for(let l=0;;l++){this.updateState=1;let a=this.viewport,u=this.viewState.lineBlockAtHeight(o),h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];h&4||([this.measureRequests,c]=[c,this.measureRequests]);let f=c.map(y=>{try{return y.read(this)}catch(v){return It(this.state,v),Vh}}),d=gi.create(this,this.state,[]),m=!1,b=!1;d.flags|=h,t?t.flags|=h:t=d,this.updateState=2,d.empty||(this.updatePlugins(d),this.inputState.update(d),this.updateAttrs(),m=this.docView.update(d));for(let y=0;y<c.length;y++)if(f[y]!=Vh)try{let v=c[y];v.write&&v.write(f[y],this)}catch(v){It(this.state,v)}if(this.viewState.editorHeight)if(this.viewState.scrollTarget)this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,b=!0;else{let y=this.viewState.lineBlockAt(u.from).top-u.top;(y>1||y<-1)&&(this.scrollDOM.scrollTop+=y,b=!0)}if(m&&this.docView.updateSelection(!0),this.viewport.from==a.from&&this.viewport.to==a.to&&!b&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(qo))l(t)}get themeClasses(){return hl+" "+(this.state.facet(ul)?Sc:xc)+" "+this.state.facet(Xs)}updateAttrs(){let e=Ih(this,oc,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(br)?"true":"false",class:"cm-content",style:`${W.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Ih(this,xl,t);let n=this.observer.ignore(()=>{let s=Ko(this.contentDOM,this.contentAttrs,t),r=Ko(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let s of n.effects)if(s.is(j.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Yi),et.mount(this.root,this.styleModules.concat(xg).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(n=>n.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return Lo(this,e,vh(this,e,t,n))}moveByGroup(e,t){return Lo(this,e,vh(this,e,t,n=>ig(this,e.head,n)))}moveToLineBoundary(e,t,n=!0){return ng(this,e,t,n)}moveVertically(e,t,n){return Lo(this,e,sg(this,e,t,n))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),pc(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.docView.coordsAt(e,t);if(!n||n.left==n.right)return n;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[Qt.find(r,e-s.from,-1,t)];return wl(n,o.dir==xe.LTR==t>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(sc)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Rg)return hc(e.length);let t=this.textDirectionAt(e.from);for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t)return s.order;let n=Um(e.text,t);return this.bidiCache.push(new bi(e.from,e.to,t,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||W.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{$h(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return ph.of(new mi(typeof e=="number"?P.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return ft.define(()=>({}),{eventHandlers:e})}static theme(e,t){let n=et.newName(),s=[Xs.of(n),Yi.of(cl(`.${n}`,e))];return t&&t.dark&&s.push(ul.of(!0)),s}static baseTheme(e){return oi.lowest(Yi.of(cl("."+hl,e,kc)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),s=n&&ee.get(n)||ee.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}};j.styleModule=Yi;j.inputHandler=ic;j.perLineTextDirection=sc;j.exceptionSink=nc;j.updateListener=qo;j.editable=br;j.mouseSelectionStyle=tc;j.dragMovesSelection=ec;j.clickAddsSelectionRange=Zh;j.decorations=rs;j.atomicRanges=lc;j.scrollMargins=ac;j.darkTheme=ul;j.contentAttributes=xl;j.editorAttributes=oc;j.lineWrapping=j.contentAttributes.of({class:"cm-lineWrapping"});j.announce=ae.define();var Rg=4096,Vh={},bi=class{constructor(e,t,n,s){this.from=e,this.to=t,this.dir=n,this.order=s}static update(e,t){if(t.empty)return e;let n=[],s=e.length?e[e.length-1].dir:xe.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&n.push(new bi(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.order))}return n}};function Ih(i,e,t){for(let n=i.state.facet(e),s=n.length-1;s>=0;s--){let r=n[s],o=typeof r=="function"?r(i):r;o&&Uo(o,t)}return t}var Eg=W.mac?"mac":W.windows?"win":W.linux?"linux":"key";function Dg(i,e){let t=i.split(/-(?!$)/),n=t[t.length-1];n=="Space"&&(n=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){let u=t[a];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))s=!0;else if(/^(c|ctrl|control)$/i.test(u))r=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+u)}return s&&(n="Alt-"+n),r&&(n="Ctrl-"+n),l&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function Ys(i,e,t){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t!==!1&&e.shiftKey&&(i="Shift-"+i),i}var Pg=oi.default(j.domEventHandlers({keydown(i,e){return Lg(Og(e.state),i,e,"editor")}})),Sl=$.define({enables:Pg}),Lh=new WeakMap;function Og(i){let e=i.facet(Sl),t=Lh.get(e);return t||Lh.set(e,t=Ig(e.reduce((n,s)=>n.concat(s),[]))),t}var qt=null,Vg=4e3;function Ig(i,e=Eg){let t=Object.create(null),n=Object.create(null),s=(o,l)=>{let a=n[o];if(a==null)n[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,u)=>{var h,c;let f=t[o]||(t[o]=Object.create(null)),d=l.split(/ (?!$)/).map(y=>Dg(y,e));for(let y=1;y<d.length;y++){let v=d.slice(0,y).join(" ");s(v,!0),f[v]||(f[v]={preventDefault:!0,run:[A=>{let C=qt={view:A,prefix:v,scope:o};return setTimeout(()=>{qt==C&&(qt=null)},Vg),!0}]})}let m=d.join(" ");s(m,!1);let b=f[m]||(f[m]={preventDefault:!1,run:((c=(h=f._any)===null||h===void 0?void 0:h.run)===null||c===void 0?void 0:c.slice())||[]});a&&b.run.push(a),u&&(b.preventDefault=!0)};for(let o of i){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of l){let h=t[u]||(t[u]=Object.create(null));h._any||(h._any={preventDefault:!1,run:[]});for(let c in h)h[c].run.push(o.any)}let a=o[e]||o.key;if(a)for(let u of l)r(u,a,o.run,o.preventDefault),o.shift&&r(u,"Shift-"+a,o.shift,o.preventDefault)}return t}function Lg(i,e,t,n){let s=lh(e),r=ti(s,0),o=$s(r)==s.length&&s!=" ",l="",a=!1;qt&&qt.view==t&&qt.scope==n&&(l=qt.prefix+" ",(a=gc.indexOf(e.keyCode)<0)&&(qt=null));let u=new Set,h=m=>{if(m){for(let b of m.run)if(!u.has(b)&&(u.add(b),b(t,e)))return!0;m.preventDefault&&(a=!0)}return!1},c=i[n],f,d;if(c){if(h(c[l+Ys(s,e,!o)]))return!0;if(o&&(e.altKey||e.metaKey||e.ctrlKey)&&(f=Ot[e.keyCode])&&f!=s){if(h(c[l+Ys(f,e,!0)]))return!0;if(e.shiftKey&&(d=ai[e.keyCode])!=s&&d!=f&&h(c[l+Ys(d,e,!1)]))return!0}else if(o&&e.shiftKey&&h(c[l+Ys(s,e,!0)]))return!0;if(h(c._any))return!0}return a}var mr=class{constructor(e,t,n,s,r){this.className=e,this.left=t,this.top=n,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width>=0&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}};function Ng(i,e){return i.constructor==e.constructor&&i.eq(e)}var pl=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(tr)!=e.state.facet(tr)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&e.view.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(tr);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}draw(e){if(e.length!=this.drawn.length||e.some((t,n)=>!Ng(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[n].constructor&&s.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.dom.remove()}},tr=$.define();function Tc(i){return[ft.define(e=>new pl(e,i)),tr.of(i)]}var Ac=!W.ios,ls=$.define({combine(i){return li(i,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Rc(i={}){return[ls.of(i),Bg,Fg,Hg,rc.of(!0)]}function Ec(i){return i.startState.facet(ls)!=i.startState.facet(ls)}var Bg=Tc({above:!0,markers(i){let{state:e}=i,t=e.facet(ls),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty?!r||Ac:t.drawRangeCursor){let o=_g(i,s,r);o&&n.push(o)}}return n},update(i,e){i.transactions.some(n=>n.scrollIntoView)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Ec(i);return t&&Nh(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){Nh(e.state,i)},class:"cm-cursorLayer"});function Nh(i,e){e.style.animationDuration=i.facet(ls).cursorBlinkRate+"ms"}var Fg=Tc({above:!1,markers(i){return i.state.selection.ranges.map(e=>e.empty?[]:Wg(i,e)).reduce((e,t)=>e.concat(t))},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||Ec(i)},class:"cm-selectionLayer"}),Dc={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Ac&&(Dc[".cm-line"].caretColor="transparent !important");var Hg=oi.highest(j.theme(Dc));function Pc(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==xe.LTR?e.left:e.right-i.scrollDOM.clientWidth)-i.scrollDOM.scrollLeft,top:e.top-i.scrollDOM.scrollTop}}function Bh(i,e,t){let n=P.cursor(e);return{from:Math.max(t.from,i.moveToLineBoundary(n,!1,!0).from),to:Math.min(t.to,i.moveToLineBoundary(n,!0,!0).from),type:ue.Text}}function Fh(i,e){let t=i.lineBlockAt(e);if(Array.isArray(t.type)){for(let n of t.type)if(n.to>e||n.to==e&&(n.to==t.to||n.type==ue.Text))return n}return t}function Wg(i,e){if(e.to<=i.viewport.from||e.from>=i.viewport.to)return[];let t=Math.max(e.from,i.viewport.from),n=Math.min(e.to,i.viewport.to),s=i.textDirection==xe.LTR,r=i.contentDOM,o=r.getBoundingClientRect(),l=Pc(i),a=window.getComputedStyle(r.firstChild),u=o.left+parseInt(a.paddingLeft)+Math.min(0,parseInt(a.textIndent)),h=o.right-parseInt(a.paddingRight),c=Fh(i,t),f=Fh(i,n),d=c.type==ue.Text?c:null,m=f.type==ue.Text?f:null;if(i.lineWrapping&&(d&&(d=Bh(i,t,d)),m&&(m=Bh(i,n,m))),d&&m&&d.from==m.from)return y(v(e.from,e.to,d));{let C=d?v(e.from,null,d):A(c,!1),T=m?v(null,e.to,m):A(f,!0),x=[];return(d||c).to<(m||f).from-1?x.push(b(u,C.bottom,h,T.top)):C.bottom<T.top&&i.elementAtHeight((C.bottom+T.top)/2).type==ue.Text&&(C.bottom=T.top=(C.bottom+T.top)/2),y(C).concat(x).concat(y(T))}function b(C,T,x,R){return new mr("cm-selectionBackground",C-l.left,T-l.top-.01,x-C,R-T+.01)}function y({top:C,bottom:T,horizontal:x}){let R=[];for(let L=0;L<x.length;L+=2)R.push(b(x[L],C,x[L+1],T));return R}function v(C,T,x){let R=1e9,L=-1e9,z=[];function B(H,N,Q,K,oe){let ke=i.coordsAtPos(H,H==x.to?-2:2),te=i.coordsAtPos(Q,Q==x.from?2:-2);R=Math.min(ke.top,te.top,R),L=Math.max(ke.bottom,te.bottom,L),oe==xe.LTR?z.push(s&&N?u:ke.left,s&&K?h:te.right):z.push(!s&&K?u:te.left,!s&&N?h:ke.right)}let M=C!=null?C:x.from,D=T!=null?T:x.to;for(let H of i.visibleRanges)if(H.to>M&&H.from<D)for(let N=Math.max(H.from,M),Q=Math.min(H.to,D);;){let K=i.state.doc.lineAt(N);for(let oe of i.bidiSpans(K)){let ke=oe.from+K.from,te=oe.to+K.from;if(ke>=Q)break;te>N&&B(Math.max(ke,N),C==null&&ke<=M,Math.min(te,Q),T==null&&te>=D,oe.dir)}if(N=K.to+1,N>=Q)break}return z.length==0&&B(M,C==null,D,T==null,i.textDirection),{top:R,bottom:L,horizontal:z}}function A(C,T){let x=o.top+(T?C.top:C.bottom);return{top:x,bottom:x,horizontal:[]}}}function _g(i,e,t){let n=i.coordsAtPos(e.head,e.assoc||1);if(!n)return null;let s=Pc(i);return new mr(t?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",n.left-s.left,n.top-s.top,-1,n.bottom-n.top)}function Hh(i,e,t,n,s){e.lastIndex=0;for(let r=i.iterRange(t,n),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function $g(i,e){let t=i.visibleRanges;if(t.length==1&&t[0].from==i.viewport.from&&t[0].to==i.viewport.to)return t;let n=[];for(let{from:s,to:r}of t)s=Math.max(i.state.doc.lineAt(s).from,s-e),r=Math.min(i.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}var ml=class{constructor(e){let{regexp:t,decoration:n,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,u,h)=>s(h,u,u+l[0].length,l,a);else if(typeof n=="function")this.addMatch=(l,a,u,h)=>{let c=n(l,a,u);c&&h(u,u+l[0].length,c)};else if(n)this.addMatch=(l,a,u,h)=>h(u,u+l[0].length,n);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new wt,n=t.add.bind(t);for(let{from:s,to:r}of $g(e,this.maxLength))Hh(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,n));return t.finish()}updateDeco(e,t){let n=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(n=Math.min(l,n),s=Math.max(a,s))}),e.viewportChanged||s-n>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),n,s):t}updateRange(e,t,n,s){for(let r of e.visibleRanges){let o=Math.max(r.from,n),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),u=a.to<l?e.state.doc.lineAt(l):a,h=Math.max(r.from,a.from),c=Math.min(r.to,u.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){h=o;break}for(;l<u.to;l++)if(this.boundary.test(u.text[l-u.from])){c=l;break}}let f=[],d,m=(b,y,v)=>f.push(v.range(b,y));if(a==u)for(this.regexp.lastIndex=h-a.from;(d=this.regexp.exec(a.text))&&d.index<c-a.from;)this.addMatch(d,e,d.index+a.from,m);else Hh(e.state.doc,this.regexp,h,c,(b,y)=>this.addMatch(y,e,b,m));t=t.update({filterFrom:h,filterTo:c,filter:(b,y)=>b<h||y>c,add:f})}}return t}},gl=/x/.unicode!=null?"gu":"g",zg=new RegExp(`[\0-\b
10
+ -\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,gl),Ug={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"},Bo=null;function Kg(){var i;if(Bo==null&&typeof document<"u"&&document.body){let e=document.body.style;Bo=((i=e.tabSize)!==null&&i!==void 0?i:e.MozTabSize)!=null}return Bo||!1}var nr=$.define({combine(i){let e=li(i,{render:null,specialChars:zg,addSpecialChars:null});return(e.replaceTabs=!Kg())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,gl)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,gl)),e}});function Oc(i={}){return[nr.of(i),Gg()]}var Wh=null;function Gg(){return Wh||(Wh=ft.fromClass(class{constructor(i){this.view=i,this.decorations=re.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(i.state.facet(nr)),this.decorations=this.decorator.createDeco(i)}makeDecorator(i){return new ml({regexp:i.specialChars,decoration:(e,t,n)=>{let{doc:s}=t.state,r=ti(e[0],0);if(r==9){let o=s.lineAt(n),l=t.state.tabSize,a=Dn(o.text,l,n-o.from);return re.replace({widget:new yl((l-a%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[r]||(this.decorationCache[r]=re.replace({widget:new bl(i,r)}))},boundary:i.replaceTabs?void 0:/[^]/})}update(i){let e=i.state.facet(nr);i.startState.facet(nr)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(i.view)):this.decorations=this.decorator.updateDeco(i,this.decorations)}},{decorations:i=>i.decorations}))}var qg="\u2022";function jg(i){return i>=32?qg:i==10?"\u2424":String.fromCharCode(9216+i)}var bl=class extends Lt{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=jg(this.code),n=e.state.phrase("Control character")+" "+(Ug[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,n,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=n,r.setAttribute("aria-label",n),r.className="cm-specialChar",r}ignoreEvent(){return!1}},yl=class extends Lt{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}};var NC=j.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}});var Bt=class extends Pt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Bt.prototype.elementClass="";Bt.prototype.toDOM=void 0;Bt.prototype.mapMode=ze.TrackBefore;Bt.prototype.startSide=Bt.prototype.endSide=-1;Bt.prototype.point=!0;var Qg=0,as=class{constructor(e,t){this.from=e,this.to=t}},q=class{constructor(e={}){this.id=Qg++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=De.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};q.closedBy=new q({deserialize:i=>i.split(" ")});q.openedBy=new q({deserialize:i=>i.split(" ")});q.group=new q({deserialize:i=>i.split(" ")});q.contextHash=new q({perNode:!0});q.lookAhead=new q({perNode:!0});q.mounted=new q({perNode:!0});var Jg=Object.create(null),De=class{constructor(e,t,n,s=0){this.name=e,this.props=t,this.id=n,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Jg,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new De(e.name||"",t,e.id,n);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(q.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let s of n.split(" "))t[s]=e[n];return n=>{for(let s=n.prop(q.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?n.name:s[r]];if(o)return o}}}};De.none=new De("",Object.create(null),0,8);var On=class{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let n of this.types){let s=null;for(let r of e){let o=r(n);o&&(s||(s=Object.assign({},n.props)),s[o[0].id]=o[1])}t.push(s?new De(n.name,s,n.id,n.flags):n)}return new On(t)}},yr=new WeakMap,Vc=new WeakMap,Te;(function(i){i[i.ExcludeBuffers=1]="ExcludeBuffers",i[i.IncludeAnonymous=2]="IncludeAnonymous",i[i.IgnoreMounts=4]="IgnoreMounts",i[i.IgnoreOverlays=8]="IgnoreOverlays"})(Te||(Te={}));var he=class{constructor(e,t,n,s,r){if(this.type=e,this.children=t,this.positions=n,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(q.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let n of this.children){let s=n.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new wi(this.topNode,e)}cursorAt(e,t=0,n=0){let s=yr.get(this)||this.topNode,r=new wi(s);return r.moveTo(e,t),yr.set(this,r._tree),r}get topNode(){return new dt(this,0,0,null)}resolve(e,t=0){let n=yi(yr.get(this)||this.topNode,e,t,!1);return yr.set(this,n),n}resolveInner(e,t=0){let n=yi(Vc.get(this)||this.topNode,e,t,!0);return Vc.set(this,n),n}iterate(e){let{enter:t,leave:n,from:s=0,to:r=this.length}=e;for(let o=this.cursor((e.mode||0)|Te.IncludeAnonymous);;){let l=!1;if(o.from<=r&&o.to>=s&&(o.type.isAnonymous||t(o)!==!1)){if(o.firstChild())continue;l=!0}for(;l&&n&&!o.type.isAnonymous&&n(o),!o.nextSibling();){if(!o.parent())return;l=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Al(De.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,s)=>new he(this.type,t,n,s,this.propValues),e.makeTree||((t,n,s)=>new he(De.none,t,n,s)))}static build(e){return Xg(e)}};he.empty=new he(De.none,[],[],0);var us=class{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new us(this.buffer,this.index)}},Ft=class{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return De.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],n=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,n==e)return r;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,n,s,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Lc(r,s,o[a+1],o[a+2])&&(l=a,n>0));a=o[a+3]);return l}slice(e,t,n){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=s[l++],r[a++]=s[l++]-n;let u=r[a++]=s[l++]-n;r[a++]=s[l++]-e,o=Math.max(o,u)}return new Ft(r,o,this.set)}};function Lc(i,e,t,n){switch(i){case-2:return t<e;case-1:return n>=e&&t<e;case 0:return t<e&&n>e;case 1:return t<=e&&n>e;case 2:return n>e;case 4:return!0}}function Nc(i,e){let t=i.childBefore(e);for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}function yi(i,e,t,n){for(var s;i.from==i.to||(t<1?i.from>=e:i.from>e)||(t>-1?i.to<=e:i.to<e);){let o=!n&&i instanceof dt&&i.index<0?null:i.parent;if(!o)return i;i=o}let r=n?0:Te.IgnoreOverlays;if(n)for(let o=i,l=o.parent;l;o=l,l=o.parent)o instanceof dt&&o.index<0&&((s=l.enter(e,t,r))===null||s===void 0?void 0:s.from)!=o.from&&(i=l);for(;;){let o=i.enter(e,t,r);if(!o)return i;i=o}}var dt=class{constructor(e,t,n,s){this._tree=e,this.from=t,this.index=n,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,n,s,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,u=t>0?l.length:-1;e!=u;e+=t){let h=l[e],c=a[e]+o.from;if(Lc(s,n,c,c+h.length)){if(h instanceof Ft){if(r&Te.ExcludeBuffers)continue;let f=h.findChild(0,h.buffer.length,t,n-c,s);if(f>-1)return new kt(new kl(o,h,e,c),null,f)}else if(r&Te.IncludeAnonymous||!h.type.isAnonymous||Tl(h)){let f;if(!(r&Te.IgnoreMounts)&&h.props&&(f=h.prop(q.mounted))&&!f.overlay)return new dt(f.tree,c,e,o);let d=new dt(h,c,e,o);return r&Te.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?h.children.length-1:0,t,n,s)}}}if(r&Te.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,n=0){let s;if(!(n&Te.IgnoreOverlays)&&(s=this._tree.prop(q.mounted))&&s.overlay){let r=e-this.from;for(let{from:o,to:l}of s.overlay)if((t>0?o<=r:o<r)&&(t<0?l>=r:l>r))return new dt(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new wi(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return yi(this,e,t,!1)}resolveInner(e,t=0){return yi(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Nc(this,e)}getChild(e,t=null,n=null){let s=vr(this,e,t,n);return s.length?s[0]:null}getChildren(e,t=null,n=null){return vr(this,e,t,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return Cr(this,e)}};function vr(i,e,t,n){let s=i.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(;!s.type.is(t);)if(!s.nextSibling())return r}for(;;){if(n!=null&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return n==null?r:[]}}function Cr(i,e,t=e.length-1){for(let n=i.parent;t>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[t]&&e[t]!=n.name)return!1;t--}}return!0}var kl=class{constructor(e,t,n,s){this.parent=e,this.buffer=t,this.index=n,this.start=s}},kt=class{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,n);return r<0?null:new kt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,n=0){if(n&Te.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new kt(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new kt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new kt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new wi(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,s=this.index+4,r=n.buffer[this.index+3];if(r>s){let o=n.buffer[this.index+1];e.push(n.slice(s,r,o)),t.push(0)}return new he(this.type,e,t,this.to-this.from)}resolve(e,t=0){return yi(this,e,t,!1)}resolveInner(e,t=0){return yi(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Nc(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,n=null){let s=vr(this,e,t,n);return s.length?s[0]:null}getChildren(e,t=null,n=null){return vr(this,e,t,n)}get node(){return this}matchContext(e){return Cr(this,e)}},wi=class{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof dt)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let n=e._parent;n;n=n._parent)this.stack.unshift(n.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=n+s.buffer[e+1],this.to=n+s.buffer[e+2],!0}yield(e){return e?e instanceof dt?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,n);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&Te.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Te.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Te.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let s=n<0?0:this.stack[n]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(s)}return n<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:n}=s)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,o=e<0?-1:n._tree.children.length;r!=o;r+=e){let l=n._tree.children[r];if(this.mode&Te.IncludeAnonymous||l instanceof Ft||!l.type.isAnonymous||Tl(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer){e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,n=r+1;break e}s=this.stack[--r]}}for(let s=n;s<this.stack.length;s++)t=new kt(this.buffer,t,this.stack[s]);return this.bufferNode=new kt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(s=!0)}for(;s&&t&&t(this),s=this.type.isAnonymous,!this.nextSibling();){if(!n)return;this.parent(),n--,s=!0}}}matchContext(e){if(!this.buffer)return Cr(this.node,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Cr(this.node,e,s);let o=n[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}};function Tl(i){return i.children.some(e=>e instanceof Ft||!e.type.isAnonymous||Tl(e))}function Xg(i){var e;let{buffer:t,nodeSet:n,maxBufferLength:s=1024,reused:r=[],minRepeatType:o=n.types.length}=i,l=Array.isArray(t)?new us(t,t.length):t,a=n.types,u=0,h=0;function c(T,x,R,L,z){let{id:B,start:M,end:D,size:H}=l,N=h;for(;H<0;)if(l.next(),H==-1){let te=r[B];R.push(te),L.push(M-T);return}else if(H==-3){u=B;return}else if(H==-4){h=B;return}else throw new RangeError(`Unrecognized record size: ${H}`);let Q=a[B],K,oe,ke=M-T;if(D-M<=s&&(oe=b(l.pos-x,z))){let te=new Uint16Array(oe.size-oe.skip),ve=l.pos-oe.size,ge=te.length;for(;l.pos>ve;)ge=y(oe.start,te,ge);K=new Ft(te,D-oe.start,n),ke=oe.start-T}else{let te=l.pos-H;l.next();let ve=[],ge=[],Le=B>=o?B:-1,Ne=0,Ye=D;for(;l.pos>te;)Le>=0&&l.id==Le&&l.size>=0?(l.end<=Ye-s&&(d(ve,ge,M,Ne,l.end,Ye,Le,N),Ne=ve.length,Ye=l.end),l.next()):c(M,te,ve,ge,Le);if(Le>=0&&Ne>0&&Ne<ve.length&&d(ve,ge,M,Ne,M,Ye,Le,N),ve.reverse(),ge.reverse(),Le>-1&&Ne>0){let at=f(Q);K=Al(Q,ve,ge,0,ve.length,0,D-M,at,at)}else K=m(Q,ve,ge,D-M,N-D)}R.push(K),L.push(ke)}function f(T){return(x,R,L)=>{let z=0,B=x.length-1,M,D;if(B>=0&&(M=x[B])instanceof he){if(!B&&M.type==T&&M.length==L)return M;(D=M.prop(q.lookAhead))&&(z=R[B]+M.length+D)}return m(T,x,R,L,z)}}function d(T,x,R,L,z,B,M,D){let H=[],N=[];for(;T.length>L;)H.push(T.pop()),N.push(x.pop()+R-z);T.push(m(n.types[M],H,N,B-z,D-B)),x.push(z-R)}function m(T,x,R,L,z=0,B){if(u){let M=[q.contextHash,u];B=B?[M].concat(B):[M]}if(z>25){let M=[q.lookAhead,z];B=B?[M].concat(B):[M]}return new he(T,x,R,L,B)}function b(T,x){let R=l.fork(),L=0,z=0,B=0,M=R.end-s,D={size:0,start:0,skip:0};e:for(let H=R.pos-T;R.pos>H;){let N=R.size;if(R.id==x&&N>=0){D.size=L,D.start=z,D.skip=B,B+=4,L+=4,R.next();continue}let Q=R.pos-N;if(N<0||Q<H||R.start<M)break;let K=R.id>=o?4:0,oe=R.start;for(R.next();R.pos>Q;){if(R.size<0)if(R.size==-3)K+=4;else break e;else R.id>=o&&(K+=4);R.next()}z=oe,L+=N,B+=K}return(x<0||L==T)&&(D.size=L,D.start=z,D.skip=B),D.size>4?D:void 0}function y(T,x,R){let{id:L,start:z,end:B,size:M}=l;if(l.next(),M>=0&&L<o){let D=R;if(M>4){let H=l.pos-(M-4);for(;l.pos>H;)R=y(T,x,R)}x[--R]=D,x[--R]=B-T,x[--R]=z-T,x[--R]=L}else M==-3?u=L:M==-4&&(h=L);return R}let v=[],A=[];for(;l.pos>0;)c(i.start||0,i.bufferStart||0,v,A,-1);let C=(e=i.length)!==null&&e!==void 0?e:v.length?A[0]+v[0].length:0;return new he(a[i.topID],v.reverse(),A.reverse(),C)}var Ic=new WeakMap;function wr(i,e){if(!i.isAnonymous||e instanceof Ft||e.type!=i)return 1;let t=Ic.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof he)){t=1;break}t+=wr(i,n)}Ic.set(e,t)}return t}function Al(i,e,t,n,s,r,o,l,a){let u=0;for(let m=n;m<s;m++)u+=wr(i,e[m]);let h=Math.ceil(u*1.5/8),c=[],f=[];function d(m,b,y,v,A){for(let C=y;C<v;){let T=C,x=b[C],R=wr(i,m[C]);for(C++;C<v;C++){let L=wr(i,m[C]);if(R+L>=h)break;R+=L}if(C==T+1){if(R>h){let L=m[T];d(L.children,L.positions,0,L.children.length,b[T]+A);continue}c.push(m[T])}else{let L=b[C-1]+m[C-1].length-x;c.push(Al(i,m,b,T,C,x,L,null,a))}f.push(x+A-r)}}return d(e,t,n,s,0),(l||a)(c,f,o)}var Mt=class{constructor(e,t,n,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],n=!1){let s=[new Mt(0,e.length,e,0,!1,n)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,n=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,u=0;;l++){let h=l<t.length?t[l]:null,c=h?h.fromA:1e9;if(c-a>=n)for(;o&&o.from<c;){let f=o;if(a>=f.from||c<=f.to||u){let d=Math.max(f.from,a)-u,m=Math.min(f.to,c)-u;f=d>=m?null:new Mt(d,m,f.tree,f.offset+u,l>0,!!h)}if(f&&s.push(f),o.to>c)break;o=r<e.length?e[r++]:null}if(!h)break;a=h.toA,u=h.toA-h.toB}return s}},vi=class{startParse(e,t,n){return typeof e=="string"&&(e=new Ml(e)),n=n?n.length?n.map(s=>new as(s.from,s.to)):[new as(0,0)]:[new as(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let s=this.startParse(e,t,n);for(;;){let r=s.advance();if(r)return r}}},Ml=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var HC=new q({perNode:!0});var Yg=0,it=class{constructor(e,t,n){this.set=e,this.base=t,this.modified=n,this.id=Yg++}static define(e){if(e!=null&&e.base)throw new Error("Can not derive from a modified tag");let t=new it([],null,[]);if(t.set.push(t),e)for(let n of e.set)t.set.push(n);return t}static defineModifier(){let e=new Ci;return t=>t.modified.indexOf(e)>-1?t:Ci.get(t.base||t,t.modified.concat(e).sort((n,s)=>n.id-s.id))}},Zg=0,Ci=class{constructor(){this.instances=[],this.id=Zg++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(l=>l.base==e&&eb(t,l.modified));if(n)return n;let s=[],r=new it(s,e,t);for(let l of t)l.instances.push(r);let o=tb(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(Ci.get(l,a));return r}};function eb(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function tb(i){let e=[[]];for(let t=0;t<i.length;t++)for(let n=0,s=e.length;n<s;n++)e.push(e[n].concat(i[t]));return e.sort((t,n)=>n.length-t.length)}function Mr(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let c=0;;){if(l=="..."&&c>0&&c+3==s.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+s);if(r.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),c+=f[0].length,c==s.length)break;let d=s[c++];if(c==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(c)}let a=r.length-1,u=r[a];if(!u)throw new RangeError("Invalid path: "+s);let h=new xi(n,o,a>0?r.slice(0,a):null);e[u]=h.sort(e[u])}}return Hc.add(e)}var Hc=new q,xi=class{constructor(e,t,n,s){this.tags=e,this.mode=t,this.context=n,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};xi.empty=new xi([],2,null);function Pl(i,e){let t=Object.create(null);for(let r of i)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:n,all:s=null}=e||{};return{style:r=>{let o=s;for(let l of r)for(let a of l.set){let u=t[a.id];if(u){o=o?o+" "+u:u;break}}return o},scope:n}}function nb(i,e){let t=null;for(let n of i){let s=n.style(e);s&&(t=t?t+" "+s:s)}return t}function Wc(i,e,t,n=0,s=i.length){let r=new El(n,Array.isArray(e)?e:[e],t);r.highlightRange(i.cursor(),n,s,"",r.highlighters),r.flush(s)}var El=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,s,r){let{type:o,from:l,to:a}=e;if(l>=n||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let u=s,h=ib(e)||xi.empty,c=nb(r,h.tags);if(c&&(u&&(u+=" "),u+=c,h.mode==1&&(s+=(s?" ":"")+c)),this.startSpan(e.from,u),h.opaque)return;let f=e.tree&&e.tree.prop(q.mounted);if(f&&f.overlay){let d=e.node.enter(f.overlay[0].from+l,1),m=this.highlighters.filter(y=>!y.scope||y.scope(f.tree.type)),b=e.firstChild();for(let y=0,v=l;;y++){let A=y<f.overlay.length?f.overlay[y]:null,C=A?A.from+l:a,T=Math.max(t,v),x=Math.min(n,C);if(T<x&&b)for(;e.from<x&&(this.highlightRange(e,T,x,s,r),this.startSpan(Math.min(x,e.to),u),!(e.to>=C||!e.nextSibling())););if(!A||C>n)break;v=A.to+l,v>t&&(this.highlightRange(d.cursor(),Math.max(t,A.from+l),Math.min(n,v),s,m),this.startSpan(v,u))}b&&e.parent()}else if(e.firstChild()){do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,s,r),this.startSpan(Math.min(n,e.to),u)}while(e.nextSibling());e.parent()}}};function ib(i){let e=i.type.prop(Hc);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}var V=it.define,xr=V(),Xt=V(),Bc=V(Xt),Fc=V(Xt),Yt=V(),Sr=V(Yt),Rl=V(Yt),Rt=V(),Vn=V(Rt),Tt=V(),At=V(),Dl=V(),hs=V(Dl),kr=V(),O={comment:xr,lineComment:V(xr),blockComment:V(xr),docComment:V(xr),name:Xt,variableName:V(Xt),typeName:Bc,tagName:V(Bc),propertyName:Fc,attributeName:V(Fc),className:V(Xt),labelName:V(Xt),namespace:V(Xt),macroName:V(Xt),literal:Yt,string:Sr,docString:V(Sr),character:V(Sr),attributeValue:V(Sr),number:Rl,integer:V(Rl),float:V(Rl),bool:V(Yt),regexp:V(Yt),escape:V(Yt),color:V(Yt),url:V(Yt),keyword:Tt,self:V(Tt),null:V(Tt),atom:V(Tt),unit:V(Tt),modifier:V(Tt),operatorKeyword:V(Tt),controlKeyword:V(Tt),definitionKeyword:V(Tt),moduleKeyword:V(Tt),operator:At,derefOperator:V(At),arithmeticOperator:V(At),logicOperator:V(At),bitwiseOperator:V(At),compareOperator:V(At),updateOperator:V(At),definitionOperator:V(At),typeOperator:V(At),controlOperator:V(At),punctuation:Dl,separator:V(Dl),bracket:hs,angleBracket:V(hs),squareBracket:V(hs),paren:V(hs),brace:V(hs),content:Rt,heading:Vn,heading1:V(Vn),heading2:V(Vn),heading3:V(Vn),heading4:V(Vn),heading5:V(Vn),heading6:V(Vn),contentSeparator:V(Rt),list:V(Rt),quote:V(Rt),emphasis:V(Rt),strong:V(Rt),link:V(Rt),monospace:V(Rt),strikethrough:V(Rt),inserted:V(),deleted:V(),changed:V(),invalid:V(),meta:kr,documentMeta:V(kr),annotation:V(kr),processingInstruction:V(kr),definition:it.defineModifier(),constant:it.defineModifier(),function:it.defineModifier(),standard:it.defineModifier(),local:it.defineModifier(),special:it.defineModifier()},$C=Pl([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}]);var Ol,fs=new q;function sb(i){return $.define({combine:i?e=>e.concat(i):void 0})}var Xe=class{constructor(e,t,n=[],s=""){this.data=e,this.name=s,X.prototype.hasOwnProperty("tree")||Object.defineProperty(X.prototype,"tree",{get(){return pt(this)}}),this.parser=t,this.extension=[ki.of(this),X.languageData.of((r,o,l)=>r.facet(_c(r,o,l)))].concat(n)}isActiveAt(e,t,n=-1){return _c(e,t,n)==this.data}findRegions(e){let t=e.facet(ki);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],s=(r,o)=>{if(r.prop(fs)==this.data){n.push({from:o,to:o+r.length});return}let l=r.prop(q.mounted);if(l){if(l.tree.prop(fs)==this.data){if(l.overlay)for(let a of l.overlay)n.push({from:a.from+o,to:a.to+o});else n.push({from:o,to:o+r.length});return}else if(l.overlay){let a=n.length;if(s(l.tree,l.overlay[0].from+o),n.length>a)return}}for(let a=0;a<r.children.length;a++){let u=r.children[a];u instanceof he&&s(u,r.positions[a]+o)}};return s(pt(e),0),n}get allowsNesting(){return!0}};Xe.setState=ae.define();function _c(i,e,t){let n=i.facet(ki);if(!n)return null;let s=n.data;if(n.allowsNesting)for(let r=pt(i).topNode;r;r=r.enter(e,t,Te.ExcludeBuffers))s=r.type.prop(fs)||s;return s}var In=class extends Xe{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=sb(e.languageData);return new In(t,e.parser.configure({props:[fs.add(n=>n.isTop?t:void 0)]}),e.name)}configure(e,t){return new In(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function pt(i){let e=i.field(Xe.state,!1);return e?e.tree:he.empty}var Nl=class{constructor(e,t=e.length){this.doc=e,this.length=t,this.cursorPos=0,this.string="",this.cursor=e.iter()}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}},cs=null,Si=class{constructor(e,t,n=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=n,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Si(e,t,[],he.empty,0,n,[],null)}startParse(){return this.parser.startParse(new Nl(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=he.empty&&this.isDone(t!=null?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Mt.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(n=this.parse.stoppedAt)!==null&&n!==void 0?n:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t!=null?t:this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Mt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=cs;cs=this;try{return e()}finally{cs=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=$c(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((u,h,c,f)=>a.push({fromA:u,toA:h,fromB:c,toB:f})),n=Mt.applyChanges(n,a),s=he.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let u of this.skipped){let h=e.mapPos(u.from,1),c=e.mapPos(u.to,-1);h<c&&l.push({from:h,to:c})}}}return new Si(this.parser,t,n,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let n=0;n<this.skipped.length;n++){let{from:s,to:r}=this.skipped[n];s<e.to&&r>e.from&&(this.fragments=$c(this.fragments,s,r),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends vi{createParse(t,n,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=cs;if(a){for(let u of s)a.tempSkipped.push(u);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new he(De.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return cs}};function $c(i,e,t){return Mt.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}var Zt=class{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new Zt(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=Si.create(e.facet(ki).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new Zt(n)}};Xe.state=Qe.define({create:Zt.init,update(i,e){for(let t of e.effects)if(t.is(Xe.setState))return t.value;return e.startState.facet(ki)!=e.state.facet(ki)?Zt.init(e.state):i.apply(e)}});var Kc=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Kc=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var Vl=typeof navigator<"u"&&(!((Ol=navigator.scheduling)===null||Ol===void 0)&&Ol.isInputPending)?()=>navigator.scheduling.isInputPending():null,rb=ft.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Xe.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Xe.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Kc(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:s}}=this.view,r=n.field(Xe.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Vl?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&n.doc.length>s+1e3,a=r.context.work(()=>Vl&&Vl()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Xe.setState.of(new Zt(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>It(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),ki=$.define({combine(i){return i.length?i[0]:null},enables:i=>[Xe.state,rb,j.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});var ob=$.define(),Tr=$.define({combine:i=>{if(!i.length)return" ";if(!/^(?: +|\t+)$/.test(i[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return i[0]}});function ps(i){let e=i.facet(Tr);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function ms(i,e){let t="",n=i.tabSize;if(i.facet(Tr).charCodeAt(0)==9)for(;e>=n;)t+=" ",e-=n;for(let s=0;s<e;s++)t+=" ";return t}function Wl(i,e){i instanceof X&&(i=new Ln(i));for(let n of i.state.facet(ob)){let s=n(i,e);if(s!==void 0)return s}let t=pt(i.state);return t?ab(i,t,e):null}var Ln=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=ps(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=n.from&&s<=n.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:n.text.slice(s-n.from),from:s}:{text:n.text.slice(0,s-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:s}=this.lineAt(e,t);return n.slice(e-s,Math.min(n.length,e+100-s))}column(e,t=1){let{text:n,from:s}=this.lineAt(e,t),r=this.countColumn(n,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(n,n.search(/\S|$/))),r}countColumn(e,t=e.length){return Dn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},lb=new q;function ab(i,e,t){return Gc(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,i)}function ub(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function hb(i){let e=i.type.prop(lb);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(q.closedBy))){let s=i.lastChild,r=s&&n.indexOf(s.name)>-1;return o=>pb(o,!0,1,void 0,r&&!ub(o)?s.from:void 0)}return i.parent==null?cb:null}function Gc(i,e,t){for(;i;i=i.parent){let n=hb(i);if(n)return n(ds.create(t,e,i))}return null}function cb(){return 0}var ds=class extends Ln{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.node=n}static create(e,t,n){return new ds(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(fb(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?Gc(e,this.pos,this.base):0}};function fb(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function db(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let s=i.options.simulateBreak,r=i.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==n)return null;if(!a.type.isSkipped)return a.from<o?t:null;l=a.to}}function pb(i,e,t,n,s){let r=i.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==i.pos+o,a=e?db(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*t)}var en=class{constructor(e,t){this.specs=e;let n;function s(l){let a=et.newName();return(n||(n=Object.create(null)))["."+a]=l,a}let r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Xe?l=>l.prop(fs)==o.data:o?l=>l==o:void 0,this.style=Pl(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=n?new et(n):null,this.themeType=t.themeType}static define(e,t){return new en(e,t||{})}},Bl=$.define(),qc=$.define({combine(i){return i.length?[i[0]]:null}});function Il(i){let e=i.facet(Bl);return e.length?e:i.facet(qc)}function Ar(i,e){let t=[mb],n;return i instanceof en&&(i.module&&t.push(j.styleModule.of(i.module)),n=i.themeType),e!=null&&e.fallback?t.push(qc.of(i)):n?t.push(Bl.computeN([j.darkTheme],s=>s.facet(j.darkTheme)==(n=="dark")?[i]:[])):t.push(Bl.of(i)),t}var Fl=class{constructor(e){this.markCache=Object.create(null),this.tree=pt(e.state),this.decorations=this.buildDeco(e,Il(e.state))}update(e){let t=pt(e.state),n=Il(e.state),s=n!=Il(e.startState);t.length<e.view.viewport.to&&!s&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n))}buildDeco(e,t){if(!t||!this.tree.length)return re.none;let n=new wt;for(let{from:s,to:r}of e.visibleRanges)Wc(this.tree,t,(o,l,a)=>{n.add(o,l,this.markCache[a]||(this.markCache[a]=re.mark({class:a})))},s,r);return n.finish()}},mb=oi.high(ft.fromClass(Fl,{decorations:i=>i.decorations})),jc=en.define([{tag:O.meta,color:"#7a757a"},{tag:O.link,textDecoration:"underline"},{tag:O.heading,textDecoration:"underline",fontWeight:"bold"},{tag:O.emphasis,fontStyle:"italic"},{tag:O.strong,fontWeight:"bold"},{tag:O.strikethrough,textDecoration:"line-through"},{tag:O.keyword,color:"#708"},{tag:[O.atom,O.bool,O.url,O.contentSeparator,O.labelName],color:"#219"},{tag:[O.literal,O.inserted],color:"#164"},{tag:[O.string,O.deleted],color:"#a11"},{tag:[O.regexp,O.escape,O.special(O.string)],color:"#e40"},{tag:O.definition(O.variableName),color:"#00f"},{tag:O.local(O.variableName),color:"#30a"},{tag:[O.typeName,O.namespace],color:"#085"},{tag:O.className,color:"#167"},{tag:[O.special(O.variableName),O.macroName],color:"#256"},{tag:O.definition(O.propertyName),color:"#00c"},{tag:O.comment,color:"#940"},{tag:O.invalid,color:"#f00"}]);var gb=1e4,bb="()[]{}";function Hl(i,e,t){let n=i.prop(e<0?q.openedBy:q.closedBy);if(n)return n;if(i.name.length==1){let s=t.indexOf(i.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Nn(i,e,t,n={}){let s=n.maxScanDistance||gb,r=n.brackets||bb,o=pt(i),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let u=Hl(a.type,t,r);if(u&&a.from<a.to)return yb(i,e,t,a,u,r)}return wb(i,e,t,o,l.type,s,r)}function yb(i,e,t,n,s,r){let o=n.parent,l={from:n.from,to:n.to},a=0,u=o==null?void 0:o.cursor();if(u&&(t<0?u.childBefore(n.from):u.childAfter(n.to)))do if(t<0?u.to<=n.from:u.from>=n.to){if(a==0&&s.indexOf(u.type.name)>-1&&u.from<u.to)return{start:l,end:{from:u.from,to:u.to},matched:!0};if(Hl(u.type,t,r))a++;else if(Hl(u.type,-t,r)){if(a==0)return{start:l,end:u.from==u.to?void 0:{from:u.from,to:u.to},matched:!1};a--}}while(t<0?u.prevSibling():u.nextSibling());return{start:l,matched:!1}}function wb(i,e,t,n,s,r,o){let l=t<0?i.sliceDoc(e-1,e):i.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let u={from:t<0?e-1:e,to:t>0?e+1:e},h=i.doc.iterRange(e,t>0?i.doc.length:0),c=0;for(let f=0;!h.next().done&&f<=r;){let d=h.value;t<0&&(f+=d.length);let m=e+f*t;for(let b=t>0?0:d.length-1,y=t>0?d.length:-1;b!=y;b+=t){let v=o.indexOf(d[b]);if(!(v<0||n.resolveInner(m+b,1).type!=s))if(v%2==0==t>0)c++;else{if(c==1)return{start:u,end:{from:m+b,to:m+b+1},matched:v>>1==a>>1};c--}}t>0&&(f+=d.length)}return h.done?{start:u,matched:!1}:null}var vb=Object.create(null),zc=[De.none];var Uc=[],Cb=Object.create(null);for(let[i,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Cb[i]=xb(vb,e);function Ll(i,e){Uc.indexOf(i)>-1||(Uc.push(i),console.warn(e))}function xb(i,e){let t=null;for(let r of e.split(".")){let o=i[r]||O[r];o?typeof o=="function"?t?t=o(t):Ll(r,`Modifier ${r} used at start of tag`):t?Ll(r,`Tag ${r} used as modifier`):t=o:Ll(r,`Unknown highlighting tag ${r}`)}if(!t)return 0;let n=e.replace(/ /g,"_"),s=De.define({id:zc.length,name:n,props:[Mr({[n]:t})]});return zc.push(s),s.id}var Sb=i=>{let e=ql(i.state);return e.line?kb(i):e.block?Tb(i):!1};function Gl(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let s=i(e,t);return s?(n(t.update(s)),!0):!1}}var kb=Gl(Eb,0);var Mb=Gl(nf,0);var Tb=Gl((i,e)=>nf(i,e,Rb(e)),0);function ql(i,e=i.selection.main.head){let t=i.languageDataAt("commentTokens",e);return t.length?t[0]:{}}var gs=50;function Ab(i,{open:e,close:t},n,s){let r=i.sliceDoc(n-gs,n),o=i.sliceDoc(s,s+gs),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,u=r.length-l;if(r.slice(u-e.length,u)==e&&o.slice(a,a+t.length)==t)return{open:{pos:n-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let h,c;s-n<=2*gs?h=c=i.sliceDoc(n,s):(h=i.sliceDoc(n,n+gs),c=i.sliceDoc(s-gs,s));let f=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(c)[0].length,m=c.length-d-t.length;return h.slice(f,f+e.length)==e&&c.slice(m,m+t.length)==t?{open:{pos:n+f+e.length,margin:/\s/.test(h.charAt(f+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(c.charAt(m-1))?1:0}}:null}function Rb(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),s=t.to<=n.to?n:i.doc.lineAt(t.to),r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from,to:s.to})}return e}function nf(i,e,t=e.selection.ranges){let n=t.map(r=>ql(e,r.from).block);if(!n.every(r=>r))return null;let s=t.map((r,o)=>Ab(e,n[o],r.from,r.to));if(i!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:n[o].open+" "},{from:r.to,insert:" "+n[o].close}]))};if(i!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=n[o],{open:u,close:h}=l;r.push({from:u.pos-a.open.length,to:u.pos+u.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:r}}return null}function Eb(i,e,t=e.selection.ranges){let n=[],s=-1;for(let{from:r,to:o}of t){let l=n.length,a=1e9;for(let u=r;u<=o;){let h=e.doc.lineAt(u);if(h.from>s&&(r==o||o>h.from)){s=h.from;let c=ql(e,u).line;if(!c)continue;let f=/^\s*/.exec(h.text)[0].length,d=f==h.length,m=h.text.slice(f,f+c.length)==c?f:-1;f<h.text.length&&f<a&&(a=f),n.push({line:h,comment:m,token:c,indent:f,empty:d,single:!1})}u=h.to+1}if(a<1e9)for(let u=l;u<n.length;u++)n[u].indent<n[u].line.text.length&&(n[u].indent=a);n.length==l+1&&(n[l].single=!0)}if(i!=2&&n.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:u,empty:h,single:c}of n)(c||!h)&&r.push({from:l.from+u,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(i!=1&&n.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of n)if(l>=0){let u=o.from+l,h=u+a.length;o.text[h-o.from]==" "&&h++,r.push({from:u,to:h})}return{changes:r}}return null}var $l=yt.define(),Db=yt.define(),Pb=$.define(),sf=$.define({combine(i){return li(i,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}});function Ob(i){let e=0;return i.iterChangedRanges((t,n)=>e=n),e}var rf=Qe.define({create(){return rt.empty},update(i,e){let t=e.state.facet(sf),n=e.annotation($l);if(n){let a=e.docChanged?P.single(Ob(e.changes)):void 0,u=Fe.fromTransaction(e,a),h=n.side,c=h==0?i.undone:i.done;return u?c=Er(c,c.length,t.minDepth,u):c=uf(c,e.startState.selection),new rt(h==0?n.rest:c,h==0?c:n.rest)}let s=e.annotation(Db);if((s=="full"||s=="before")&&(i=i.isolate()),e.annotation(de.addToHistory)===!1)return e.changes.empty?i:i.addMapping(e.changes.desc);let r=Fe.fromTransaction(e),o=e.annotation(de.time),l=e.annotation(de.userEvent);return r?i=i.addChanges(r,o,l,t.newGroupDelay,t.minDepth):e.selection&&(i=i.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(i=i.isolate()),i},toJSON(i){return{done:i.done.map(e=>e.toJSON()),undone:i.undone.map(e=>e.toJSON())}},fromJSON(i){return new rt(i.done.map(Fe.fromJSON),i.undone.map(Fe.fromJSON))}});function of(i={}){return[rf,sf.of(i),j.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?lf:e.inputType=="historyRedo"?zl:null;return n?(e.preventDefault(),n(t)):!1}})]}function Dr(i,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let s=t.field(rf,!1);if(!s)return!1;let r=s.pop(i,t,e);return r?(n(r),!0):!1}}var lf=Dr(0,!1),zl=Dr(1,!1),Vb=Dr(0,!0),Ib=Dr(1,!0);var Fe=class{constructor(e,t,n,s,r){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new Fe(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new Fe(e.changes&&fe.fromJSON(e.changes),[],e.mapped&&je.fromJSON(e.mapped),e.startSelection&&P.fromJSON(e.startSelection),e.selectionsAfter.map(P.fromJSON))}static fromTransaction(e,t){let n=st;for(let s of e.startState.facet(Pb)){let r=s(e);r.length&&(n=n.concat(r))}return!n.length&&e.changes.empty?null:new Fe(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,st)}static selection(e){return new Fe(void 0,st,void 0,void 0,e)}};function Er(i,e,t,n){let s=e+1>t+20?e-t-1:0,r=i.slice(s,e);return r.push(n),r}function Lb(i,e){let t=[],n=!1;return i.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let u=t[a++],h=t[a++];l>=u&&o<=h&&(n=!0)}}),n}function Nb(i,e){return i.ranges.length==e.ranges.length&&i.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function af(i,e){return i.length?e.length?i.concat(e):i:e}var st=[],Bb=200;function uf(i,e){if(i.length){let t=i[i.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Bb));return n.length&&n[n.length-1].eq(e)?i:(n.push(e),Er(i,i.length-1,1e9,t.setSelAfter(n)))}else return[Fe.selection([e])]}function Fb(i){let e=i[i.length-1],t=i.slice();return t[i.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function _l(i,e){if(!i.length)return i;let t=i.length,n=st;for(;t;){let s=Hb(i[t-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let r=i.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,n=s.selectionsAfter}return n.length?[Fe.selection(n)]:st}function Hb(i,e,t){let n=af(i.selectionsAfter.length?i.selectionsAfter.map(l=>l.map(e)):st,t);if(!i.changes)return Fe.selection(n);let s=i.changes.map(e),r=e.mapDesc(i.changes,!0),o=i.mapped?i.mapped.composeDesc(r):r;return new Fe(s,ae.mapEffects(i.effects,e),o,i.startSelection.map(r),n)}var Wb=/^(input\.type|delete)($|\.)/,rt=class{constructor(e,t,n=0,s=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=s}isolate(){return this.prevTime?new rt(this.done,this.undone):this}addChanges(e,t,n,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!n||Wb.test(n))&&(!l.selectionsAfter.length&&t-this.prevTime<s&&Lb(l.changes,e.changes)||n=="input.type.compose")?o=Er(o,o.length-1,r,new Fe(e.changes.compose(l.changes),af(e.effects,l.effects),l.mapped,l.startSelection,st)):o=Er(o,o.length,r,e),new rt(o,st,t,n)}addSelection(e,t,n,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:st;return r.length>0&&t-this.prevTime<s&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&Nb(r[r.length-1],e)?this:new rt(uf(this.done,e),this.undone,t,n)}addMapping(e){return new rt(_l(this.done,e),_l(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1];if(n&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:$l.of({side:e,rest:Fb(s)}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let o=s.length==1?st:s.slice(0,s.length-1);return r.mapped&&(o=_l(o,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:$l.of({side:e,rest:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};rt.empty=new rt(st,st);var hf=[{key:"Mod-z",run:lf,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:zl,preventDefault:!0},{linux:"Ctrl-Shift-z",run:zl,preventDefault:!0},{key:"Mod-u",run:Vb,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ib,preventDefault:!0}];function Mi(i,e){return P.create(i.ranges.map(e),i.mainIndex)}function Et(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function mt({state:i,dispatch:e},t){let n=Mi(i.selection,t);return n.eq(i.selection)?!1:(e(Et(i,n)),!0)}function Pr(i,e){return P.cursor(e?i.to:i.from)}function cf(i,e){return mt(i,t=>t.empty?i.moveByChar(t,e):Pr(t,e))}function He(i){return i.textDirectionAt(i.state.selection.main.head)==xe.LTR}var ff=i=>cf(i,!He(i)),df=i=>cf(i,He(i));function pf(i,e){return mt(i,t=>t.empty?i.moveByGroup(t,e):Pr(t,e))}var _b=i=>pf(i,!He(i)),$b=i=>pf(i,He(i));function zb(i,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(i.sliceDoc(e.from,e.to)))||e.firstChild}function Or(i,e,t){let n=pt(i).resolveInner(e.head),s=t?q.closedBy:q.openedBy;for(let a=e.head;;){let u=t?n.childAfter(a):n.childBefore(a);if(!u)break;zb(i,u,s)?n=u:a=t?u.to:u.from}let r=n.type.prop(s),o,l;return r&&(o=t?Nn(i,n.from,1):Nn(i,n.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?n.to:n.from,P.cursor(l,t?-1:1)}var Ub=i=>mt(i,e=>Or(i.state,e,!He(i))),Kb=i=>mt(i,e=>Or(i.state,e,He(i)));function mf(i,e){return mt(i,t=>{if(!t.empty)return Pr(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}var gf=i=>mf(i,!1),bf=i=>mf(i,!0);function yf(i){return Math.max(i.defaultLineHeight,Math.min(i.dom.clientHeight,innerHeight)-5)}function wf(i,e){let{state:t}=i,n=Mi(t.selection,l=>l.empty?i.moveVertically(l,e,yf(i)):Pr(l,e));if(n.eq(t.selection))return!1;let s=i.coordsAtPos(t.selection.main.head),r=i.scrollDOM.getBoundingClientRect(),o;return s&&s.top>r.top&&s.bottom<r.bottom&&s.top-r.top<=i.scrollDOM.scrollHeight-i.scrollDOM.scrollTop-i.scrollDOM.clientHeight&&(o=j.scrollIntoView(n.main.head,{y:"start",yMargin:s.top-r.top})),i.dispatch(Et(t,n),{effects:o}),!0}var Qc=i=>wf(i,!1),Ul=i=>wf(i,!0);function tn(i,e,t){let n=i.lineBlockAt(e.head),s=i.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?n.to:n.from)&&(s=i.moveToLineBoundary(e,t,!1)),!t&&s.head==n.from&&n.length){let r=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;r&&e.head!=n.from+r&&(s=P.cursor(n.from+r))}return s}var Gb=i=>mt(i,e=>tn(i,e,!0)),qb=i=>mt(i,e=>tn(i,e,!1)),jb=i=>mt(i,e=>tn(i,e,!He(i))),Qb=i=>mt(i,e=>tn(i,e,He(i))),Jb=i=>mt(i,e=>P.cursor(i.lineBlockAt(e.head).from,1)),Xb=i=>mt(i,e=>P.cursor(i.lineBlockAt(e.head).to,-1));function Yb(i,e,t){let n=!1,s=Mi(i.selection,r=>{let o=Nn(i,r.head,-1)||Nn(i,r.head,1)||r.head>0&&Nn(i,r.head-1,1)||r.head<i.doc.length&&Nn(i,r.head+1,-1);if(!o||!o.end)return r;n=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return t?P.range(r.anchor,l):P.cursor(l)});return n?(e(Et(i,s)),!0):!1}var Zb=({state:i,dispatch:e})=>Yb(i,e,!1);function ot(i,e){let t=Mi(i.state.selection,n=>{let s=e(n);return P.range(n.anchor,s.head,s.goalColumn)});return t.eq(i.state.selection)?!1:(i.dispatch(Et(i.state,t)),!0)}function vf(i,e){return ot(i,t=>i.moveByChar(t,e))}var Cf=i=>vf(i,!He(i)),xf=i=>vf(i,He(i));function Sf(i,e){return ot(i,t=>i.moveByGroup(t,e))}var e0=i=>Sf(i,!He(i)),t0=i=>Sf(i,He(i));var n0=i=>ot(i,e=>Or(i.state,e,!He(i))),i0=i=>ot(i,e=>Or(i.state,e,He(i)));function kf(i,e){return ot(i,t=>i.moveVertically(t,e))}var Mf=i=>kf(i,!1),Tf=i=>kf(i,!0);function Af(i,e){return ot(i,t=>i.moveVertically(t,e,yf(i)))}var Jc=i=>Af(i,!1),Xc=i=>Af(i,!0),s0=i=>ot(i,e=>tn(i,e,!0)),r0=i=>ot(i,e=>tn(i,e,!1)),o0=i=>ot(i,e=>tn(i,e,!He(i))),l0=i=>ot(i,e=>tn(i,e,He(i))),a0=i=>ot(i,e=>P.cursor(i.lineBlockAt(e.head).from)),u0=i=>ot(i,e=>P.cursor(i.lineBlockAt(e.head).to)),Yc=({state:i,dispatch:e})=>(e(Et(i,{anchor:0})),!0),Zc=({state:i,dispatch:e})=>(e(Et(i,{anchor:i.doc.length})),!0),ef=({state:i,dispatch:e})=>(e(Et(i,{anchor:i.selection.main.anchor,head:0})),!0),tf=({state:i,dispatch:e})=>(e(Et(i,{anchor:i.selection.main.anchor,head:i.doc.length})),!0),h0=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),c0=({state:i,dispatch:e})=>{let t=Ir(i).map(({from:n,to:s})=>P.range(n,Math.min(s+1,i.doc.length)));return e(i.update({selection:P.create(t),userEvent:"select"})),!0},f0=({state:i,dispatch:e})=>{let t=Mi(i.selection,n=>{var s;let r=pt(i).resolveInner(n.head,1);for(;!(r.from<n.from&&r.to>=n.to||r.to>n.to&&r.from<=n.from||!(!((s=r.parent)===null||s===void 0)&&s.parent));)r=r.parent;return P.range(r.to,r.from)});return e(Et(i,t)),!0},d0=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=P.create([t.main]):t.main.empty||(n=P.create([P.cursor(t.main.head)])),n?(e(Et(i,n)),!0):!1};function Vr(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,s=n.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(o);a<o?(t="delete.backward",a=Rr(i,a,!1)):a>o&&(t="delete.forward",a=Rr(i,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Rr(i,o,!1),l=Rr(i,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:P.cursor(o)}});return s.changes.empty?!1:(i.dispatch(n.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?j.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Rr(i,e,t){if(i instanceof j)for(let n of i.state.facet(j.atomicRanges).map(s=>s(i)))n.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}var Rf=(i,e)=>Vr(i,t=>{let{state:n}=i,s=n.doc.lineAt(t),r,o;if(!e&&t>s.from&&t<s.from+200&&!/[^ \t]/.test(r=s.text.slice(0,t-s.from))){if(r[r.length-1]==" ")return t-1;let l=Dn(r,n.tabSize),a=l%ps(n)||ps(n);for(let u=0;u<a&&r[r.length-1-u]==" ";u++)t--;o=t}else o=_e(s.text,t-s.from,e,e)+s.from,o==t&&s.number!=(e?n.doc.lines:1)&&(o+=e?1:-1);return o}),Kl=i=>Rf(i,!1),Ef=i=>Rf(i,!0),Df=(i,e)=>Vr(i,t=>{let n=t,{state:s}=i,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let l=null;;){if(n==(e?r.to:r.from)){n==t&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let a=_e(r.text,n-r.from,e)+r.from,u=r.text.slice(Math.min(n,a)-r.from,Math.max(n,a)-r.from),h=o(u);if(l!=null&&h!=l)break;(u!=" "||n!=t)&&(l=h),n=a}return n}),Pf=i=>Df(i,!1),p0=i=>Df(i,!0),Of=i=>Vr(i,e=>{let t=i.lineBlockAt(e).to;return e<t?t:Math.min(i.state.doc.length,e+1)}),m0=i=>Vr(i,e=>{let t=i.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)});var g0=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:J.of(["",""])},range:P.cursor(n.from)}));return e(i.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},b0=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>{if(!n.empty||n.from==0||n.from==i.doc.length)return{range:n};let s=n.from,r=i.doc.lineAt(s),o=s==r.from?s-1:_e(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:_e(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:i.doc.slice(s,l).append(i.doc.slice(o,s))},range:P.cursor(l)}});return t.changes.empty?!1:(e(i.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Ir(i){let e=[],t=-1;for(let n of i.selection.ranges){let s=i.doc.lineAt(n.from),r=i.doc.lineAt(n.to);if(!n.empty&&n.to==r.from&&(r=i.doc.lineAt(n.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});t=r.number+1}return e}function Vf(i,e,t){if(i.readOnly)return!1;let n=[],s=[];for(let r of Ir(i)){if(t?r.to==i.doc.length:r.from==0)continue;let o=i.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){n.push({from:r.to,to:o.to},{from:r.from,insert:o.text+i.lineBreak});for(let a of r.ranges)s.push(P.range(Math.min(i.doc.length,a.anchor+l),Math.min(i.doc.length,a.head+l)))}else{n.push({from:o.from,to:r.from},{from:r.to,insert:i.lineBreak+o.text});for(let a of r.ranges)s.push(P.range(a.anchor-l,a.head-l))}}return n.length?(e(i.update({changes:n,scrollIntoView:!0,selection:P.create(s,i.selection.mainIndex),userEvent:"move.line"})),!0):!1}var y0=({state:i,dispatch:e})=>Vf(i,e,!1),w0=({state:i,dispatch:e})=>Vf(i,e,!0);function If(i,e,t){if(i.readOnly)return!1;let n=[];for(let s of Ir(i))t?n.push({from:s.from,insert:i.doc.slice(s.from,s.to)+i.lineBreak}):n.push({from:s.to,insert:i.lineBreak+i.doc.slice(s.from,s.to)});return e(i.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}var v0=({state:i,dispatch:e})=>If(i,e,!1),C0=({state:i,dispatch:e})=>If(i,e,!0),x0=i=>{if(i.state.readOnly)return!1;let{state:e}=i,t=e.changes(Ir(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),n=Mi(e.selection,s=>i.moveVertically(s,!0)).map(t);return i.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function S0(i,e){if(/\(\)|\[\]|\{\}/.test(i.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=pt(i).resolveInner(e),n=t.childBefore(e),s=t.childAfter(e),r;return n&&s&&n.to<=e&&s.from>=e&&(r=n.type.prop(q.closedBy))&&r.indexOf(s.name)>-1&&i.doc.lineAt(n.to).from==i.doc.lineAt(s.from).from?{from:n.to,to:s.from}:null}var k0=Lf(!1),M0=Lf(!0);function Lf(i){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!i&&r==o&&S0(e,r);i&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let u=new Ln(e,{simulateBreak:r,simulateDoubleBreak:!!a}),h=Wl(u,r);for(h==null&&(h=/^\s*/.exec(e.doc.lineAt(r).text)[0].length);o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",ms(e,h)];return a&&c.push(ms(e,u.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:J.of(c)},range:P.cursor(r+1+c[1].length)}});return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function jl(i,e){let t=-1;return i.changeByRange(n=>{let s=[];for(let o=n.from;o<=n.to;){let l=i.doc.lineAt(o);l.number>t&&(n.empty||n.to>l.from)&&(e(l,s,n),t=l.number),o=l.to+1}let r=i.changes(s);return{changes:s,range:P.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}var T0=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=Object.create(null),n=new Ln(i,{overrideIndentation:r=>{let o=t[r];return o==null?-1:o}}),s=jl(i,(r,o,l)=>{let a=Wl(n,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let u=/^\s*/.exec(r.text)[0],h=ms(i,a);(u!=h||l.from<r.from+u.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+u.length,insert:h}))});return s.changes.empty||e(i.update(s,{userEvent:"indent"})),!0},A0=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(jl(i,(t,n)=>{n.push({from:t.from,insert:i.facet(Tr)})}),{userEvent:"input.indent"})),!0),R0=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(jl(i,(t,n)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=Dn(s,i.tabSize),o=0,l=ms(i,Math.max(0,r-ps(i)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;n.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0);var E0=[{key:"Ctrl-b",run:ff,shift:Cf,preventDefault:!0},{key:"Ctrl-f",run:df,shift:xf},{key:"Ctrl-p",run:gf,shift:Mf},{key:"Ctrl-n",run:bf,shift:Tf},{key:"Ctrl-a",run:Jb,shift:a0},{key:"Ctrl-e",run:Xb,shift:u0},{key:"Ctrl-d",run:Ef},{key:"Ctrl-h",run:Kl},{key:"Ctrl-k",run:Of},{key:"Ctrl-Alt-h",run:Pf},{key:"Ctrl-o",run:g0},{key:"Ctrl-t",run:b0},{key:"Ctrl-v",run:Ul}],D0=[{key:"ArrowLeft",run:ff,shift:Cf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:_b,shift:e0,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:jb,shift:o0,preventDefault:!0},{key:"ArrowRight",run:df,shift:xf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:$b,shift:t0,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Qb,shift:l0,preventDefault:!0},{key:"ArrowUp",run:gf,shift:Mf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Yc,shift:ef},{mac:"Ctrl-ArrowUp",run:Qc,shift:Jc},{key:"ArrowDown",run:bf,shift:Tf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Zc,shift:tf},{mac:"Ctrl-ArrowDown",run:Ul,shift:Xc},{key:"PageUp",run:Qc,shift:Jc},{key:"PageDown",run:Ul,shift:Xc},{key:"Home",run:qb,shift:r0,preventDefault:!0},{key:"Mod-Home",run:Yc,shift:ef},{key:"End",run:Gb,shift:s0,preventDefault:!0},{key:"Mod-End",run:Zc,shift:tf},{key:"Enter",run:k0},{key:"Mod-a",run:h0},{key:"Backspace",run:Kl,shift:Kl},{key:"Delete",run:Ef},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Pf},{key:"Mod-Delete",mac:"Alt-Delete",run:p0},{mac:"Mod-Backspace",run:m0},{mac:"Mod-Delete",run:Of}].concat(E0.map(i=>({mac:i.key,run:i.run,shift:i.shift}))),Nf=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Ub,shift:n0},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Kb,shift:i0},{key:"Alt-ArrowUp",run:y0},{key:"Shift-Alt-ArrowUp",run:v0},{key:"Alt-ArrowDown",run:w0},{key:"Shift-Alt-ArrowDown",run:C0},{key:"Escape",run:d0},{key:"Mod-Enter",run:M0},{key:"Alt-l",mac:"Ctrl-l",run:c0},{key:"Mod-i",run:f0,preventDefault:!0},{key:"Mod-[",run:R0},{key:"Mod-]",run:A0},{key:"Mod-Alt-\\",run:T0},{key:"Shift-Mod-k",run:x0},{key:"Shift-Mod-\\",run:Zb},{key:"Mod-/",run:Sb},{key:"Alt-A",run:Mb}].concat(D0);var na=require("react");var P0=(()=>[Oc(),of(),Rc(),Ar(jc,{fallback:!0}),Sl.of([...Nf,...hf])])();var Ri=class{constructor(e,t,n,s,r,o,l,a,u,h=0,c){this.p=e,this.stack=t,this.state=n,this.reducePos=s,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=u,this.lookAhead=h,this.parent=c}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,n=0){let s=e.parser.context;return new Ri(e,[],t,n,n,0,[],0,s?new Nr(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){let t=e>>19,n=e&65535,{parser:s}=this.p,r=s.dynamicPrecedence(n);if(r&&(this.score+=r),t==0){this.pushState(s.getGoto(this.state,n,!0),this.reducePos),n<s.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,4,!0),this.reduceContext(n,this.reducePos);return}let o=this.stack.length-(t-1)*3-(e&262144?6:0),l=this.stack[o-2],a=this.stack[o-1],u=this.bufferBase+this.buffer.length-a;if(n<s.minRepeatTerm||e&131072){let h=s.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,l,h,u+4,!0)}if(e&262144)this.state=this.stack[o];else{let h=this.stack[o-3];this.state=s.getGoto(h,n,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(n,l)}storeNode(e,t,n,s=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(t==n)return;if(o.buffer[l-2]>=t){o.buffer[l-2]=n;return}}}if(!r||this.pos==n)this.buffer.push(e,t,n,s);else{let o=this.buffer.length;if(o>0&&this.buffer[o-4]!=0)for(;o>0&&this.buffer[o-2]>n;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4);this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=n,this.buffer[o+3]=s}}shift(e,t,n){let s=this.pos;if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=n,this.shiftContext(t,s),t<=this.p.parser.maxNode&&this.buffer.push(t,s,n,4);else{let r=e,{parser:o}=this.p;(n>this.pos||t<=o.maxNode)&&(this.pos=n,o.stateFlag(r,1)||(this.reducePos=n)),this.pushState(r,s),this.shiftContext(t,s),t<=o.maxNode&&this.buffer.push(t,s,n,4)}}apply(e,t,n){e&65536?this.reduce(e):this.shift(e,t,n)}useNode(e,t){let n=this.p.reused.length-1;(n<0||this.p.reused[n]!=e)&&(this.p.reused.push(e),n++);let s=this.pos;this.reducePos=this.pos=s+e.length,this.pushState(t,s),this.buffer.push(n,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let n=e.buffer.slice(t),s=e.bufferBase+t;for(;e&&s==e.bufferBase;)e=e.parent;return new Ri(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,n,s,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let n=e<=this.p.parser.maxNode;n&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,n?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Jl(this);;){let n=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(n==0)return!1;if(!(n&65536))return!0;t.reduce(n)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>4<<1||this.stack.length>=120){let s=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&s.push(t[r],o);if(this.stack.length<120)for(let r=0;s.length<4<<1&&r<t.length;r+=2){let o=t[r+1];s.some((l,a)=>a&1&&l==o)||s.push(t[r],o)}t=s}let n=[];for(let s=0;s<t.length&&n.length<4;s+=2){let r=t[s+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[s],this.pos),o.score-=200,n.push(o)}return n}forceReduce(){let e=this.p.parser.stateSlot(this.state,5);if(!(e&65536))return!1;let{parser:t}=this.p;if(!t.validAction(this.state,e)){let n=e>>19,s=e&65535,r=this.stack.length-n*3;if(r<0||t.getGoto(this.stack[r],s,!1)<0)return!1;this.storeNode(0,this.reducePos,this.reducePos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.reducePos,this.reducePos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.reducePos,this.reducePos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new Nr(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){e>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=e)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},Nr=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},Bf;(function(i){i[i.Insert=200]="Insert",i[i.Delete=190]="Delete",i[i.Reduce=100]="Reduce",i[i.MaxNext=4]="MaxNext",i[i.MaxInsertStackDepth=300]="MaxInsertStackDepth",i[i.DampenInsertStackDepth=120]="DampenInsertStackDepth"})(Bf||(Bf={}));var Jl=class{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,n=e>>19;n==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(n-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=s}},Ei=class{constructor(e,t,n){this.stack=e,this.pos=t,this.index=n,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new Ei(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new Ei(this.stack,this.pos,this.index)}},Ti=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},Ff=new Ti,Xl=class{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Ff,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let n=this.range,s=this.rangeIndex,r=this.pos+e;for(;r<n.from;){if(!s)return null;let o=this.ranges[--s];r-=n.from-o.to,n=o}for(;t<0?r>n.to:r>=n.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];r+=o.from-n.to,n=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,n,s;if(t>=0&&t<this.chunk.length)n=this.pos+e,s=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(n=r,n>=this.chunk2Pos&&n<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(n-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=n;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=n),n+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-n)),s=this.chunk2.charCodeAt(0)}}return n>=this.token.lookAhead&&(this.token.lookAhead=n+1),s}acceptToken(e,t=0){let n=t?this.resolveOffset(t,-1):this.pos;if(n==null||n<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=n}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=Ff,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let n="";for(let s of this.ranges){if(s.from>=t)break;s.to>e&&(n+=this.input.read(Math.max(s.from,e),Math.min(s.to,t)))}return n}},Ai=class{constructor(e,t){this.data=e,this.id=t}token(e,t){V0(this.data,e,t,this.id)}};Ai.prototype.contextual=Ai.prototype.fallback=Ai.prototype.extend=!1;function V0(i,e,t,n){let s=0,r=1<<n,{parser:o}=t.p,{dialect:l}=o;e:for(;r&i[s];){let a=i[s+1];for(let f=s+3;f<a;f+=2)if((i[f+1]&r)>0){let d=i[f];if(l.allows(d)&&(e.token.value==-1||e.token.value==d||o.overrides(d,e.token.value))){e.acceptToken(d);break}}let u=e.next,h=0,c=i[s+2];if(e.next<0&&c>h&&i[a+c*3-3]==65535&&i[a+c*3-3]==65535){s=i[a+c*3-1];continue e}for(;h<c;){let f=h+c>>1,d=a+f+(f<<1),m=i[d],b=i[d+1]||65536;if(u<m)c=f;else if(u>=b)h=f+1;else{s=i[d+2],e.advance();continue e}}break}}function Lr(i,e=Uint16Array){if(typeof i!="string")return i;let t=null;for(let n=0,s=0;n<i.length;){let r=0;for(;;){let o=i.charCodeAt(n++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[s++]=r:t=new e(r)}return t}var gt=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Ql=null,Hf;(function(i){i[i.Margin=25]="Margin"})(Hf||(Hf={}));function Wf(i,e,t){let n=i.cursor(Te.IncludeAnonymous);for(n.moveTo(e);;)if(!(t<0?n.childBefore(e):n.childAfter(e)))for(;;){if((t<0?n.to<e:n.from>e)&&!n.type.isError)return t<0?Math.max(0,Math.min(n.to-1,e-25)):Math.min(i.length,Math.max(n.from+1,e+25));if(t<0?n.prevSibling():n.nextSibling())break;if(!n.parent())return t<0?0:i.length}}var Yl=class{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Wf(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Wf(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let n=this.trees[t],s=this.index[t];if(s==n.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=n.children[s],o=this.start[t]+n.positions[s];if(o>e)return this.nextStart=o,null;if(r instanceof he){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let a=r.prop(q.lookAhead);if(!a||l+a<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}},Zl=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(n=>new Ti)}getActions(e){let t=0,n=null,{parser:s}=e.p,{tokenizers:r}=s,o=s.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let u=0;u<r.length;u++){if(!(1<<u&o))continue;let h=r[u],c=this.tokens[u];if(!(n&&!h.fallback)&&((h.contextual||c.start!=e.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,h,e),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(a=Math.max(c.lookAhead,a)),c.value!=0)){let f=t;if(c.extended>-1&&(t=this.addActions(e,c.extended,c.end,t)),t=this.addActions(e,c.value,c.end,t),!h.extend&&(n=c,t>f))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!n&&e.pos==this.stream.end&&(n=new Ti,n.value=e.p.parser.eofTerm,n.start=n.end=e.pos,t=this.addActions(e,n.value,n.end,t)),this.mainToken=n,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Ti,{pos:n,p:s}=e;return t.start=n,t.end=Math.min(n+1,s.stream.end),t.value=n==s.stream.end?s.parser.eofTerm:0,t}updateCachedToken(e,t,n){let s=this.stream.clipPos(n.pos);if(t.token(this.stream.reset(s,e),n),e.value>-1){let{parser:r}=n.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),n);if(l>=0&&n.p.parser.dialect.allows(l>>1)){l&1?e.extended=l>>1:e.value=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(s+1)}putAction(e,t,n,s){for(let r=0;r<s;r+=3)if(this.actions[r]==e)return s;return this.actions[s++]=e,this.actions[s++]=t,this.actions[s++]=n,s}addActions(e,t,n,s){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let u=o.stateSlot(r,a?2:1);;u+=3){if(l[u]==65535)if(l[u+1]==1)u=Ht(l,u+2);else{s==0&&l[u+1]==2&&(s=this.putAction(Ht(l,u+2),t,n,s));break}l[u]==t&&(s=this.putAction(Ht(l,u+1),t,n,s))}return s}},_f;(function(i){i[i.Distance=5]="Distance",i[i.MaxRemainingPerStep=3]="MaxRemainingPerStep",i[i.MinBufferLengthPrune=500]="MinBufferLengthPrune",i[i.ForceReduceLimit=10]="ForceReduceLimit",i[i.CutDepth=15e3]="CutDepth",i[i.CutTo=9e3]="CutTo"})(_f||(_f={}));var ea=class{constructor(e,t,n,s){this.parser=e,this.input=t,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.stream=new Xl(t,s),this.tokens=new Zl(e,this.stream),this.topTerm=e.top[1];let{from:r}=s[0];this.stacks=[Ri.start(this,e.top[0],r)],this.fragments=n.length&&this.stream.end-r>e.bufferLength*4?new Yl(n,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,n=this.stacks=[],s,r;for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)n.push(l);else{if(this.advanceStack(l,n,e))continue;{s||(s=[],r=[]),s.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!n.length){let o=s&&I0(s);if(o)return this.stackToTree(o);if(this.parser.strict)throw gt&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,r,n);if(o)return this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(n.length>o)for(n.sort((l,a)=>a.score-l.score);n.length>o;)n.pop();n.some(l=>l.reducePos>t)&&this.recovering--}else if(n.length>1){e:for(let o=0;o<n.length-1;o++){let l=n[o];for(let a=o+1;a<n.length;a++){let u=n[a];if(l.sameState(u)||l.buffer.length>500&&u.buffer.length>500)if((l.score-u.score||l.buffer.length-u.buffer.length)>0)n.splice(a--,1);else{n.splice(o--,1);continue e}}}}this.minStackPos=n[0].pos;for(let o=1;o<n.length;o++)n[o].pos<this.minStackPos&&(this.minStackPos=n[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,n){let s=e.pos,{parser:r}=this,o=gt?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let u=e.curContext&&e.curContext.tracker.strict,h=u?e.curContext.hash:0;for(let c=this.fragments.nodeAt(s);c;){let f=this.parser.nodeSet.types[c.type.id]==c.type?r.getGoto(e.state,c.type.id):-1;if(f>-1&&c.length&&(!u||(c.prop(q.contextHash)||0)==h))return e.useNode(c,f),gt&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof he)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof he&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),gt&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=15e3)for(;e.stack.length>9e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let u=0;u<a.length;){let h=a[u++],c=a[u++],f=a[u++],d=u==a.length||!n,m=d?e:e.split();if(m.apply(h,c,f),gt&&console.log(o+this.stackID(m)+` (via ${h&65536?`reduce of ${r.getName(h&65535)}`:"shift"} for ${r.getName(c)} @ ${s}${m==e?"":", split"})`),d)return!0;m.pos>s?t.push(m):n.push(m)}return!1}advanceFully(e,t){let n=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>n)return $f(e,t),!0}}runRecovery(e,t,n){let s=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],u=t[(o<<1)+1],h=gt?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),gt&&console.log(h+this.stackID(l)+" (restarted)"),this.advanceFully(l,n))))continue;let c=l.split(),f=h;for(let d=0;c.forceReduce()&&d<10&&(gt&&console.log(f+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,n));d++)gt&&(f=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(a))gt&&console.log(h+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,n);this.stream.end>l.pos?(u==l.pos&&(u++,a=0),l.recoverByDelete(a,u),gt&&console.log(h+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),$f(l,n)):(!s||s.score<l.score)&&(s=l)}return s}stackToTree(e){return e.close(),he.build({buffer:Ei.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Ql||(Ql=new WeakMap)).get(e);return t||Ql.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function $f(i,e){for(let t=0;t<e.length;t++){let n=e[t];if(n.pos==i.pos&&n.sameState(i)){e[t].score<i.score&&(e[t]=i);return}}e.push(i)}var ta=class{constructor(e,t,n){this.source=e,this.flags=t,this.disabled=n}allows(e){return!this.disabled||this.disabled[e]==0}};var Bn=class extends vi{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let n=Object.keys(e.topRules).map(l=>e.topRules[l][1]),s=[];for(let l=0;l<t.length;l++)s.push([]);function r(l,a,u){s[l].push([a,a.deserialize(String(u))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=q[a]);for(let u=1;u<l.length;){let h=l[u++];if(h>=0)r(h,a,l[u++]);else{let c=l[u+-h];for(let f=-h;f>0;f--)r(l[u++],a,c);u++}}}this.nodeSet=new On(t.map((l,a)=>De.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:s[a],top:n.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=1024;let o=Lr(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Uf),this.states=Lr(e.states,Uint32Array),this.data=Lr(e.stateData),this.goto=Lr(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new Ai(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,n){let s=new ea(this,e,t,n);for(let r of this.wrappers)s=r(s,e,t,n);return s}getGoto(e,t,n=!1){let s=this.goto;if(t>=s[0])return-1;for(let r=s[t+1];;){let o=s[r++],l=o&1,a=s[r++];if(l&&n)return a;for(let u=r+(o>>1);r<u;r++)if(s[r]==e)return a;if(l)return-1}}hasAction(e,t){let n=this.data;for(let s=0;s<2;s++)for(let r=this.stateSlot(e,s?2:1),o;;r+=3){if((o=n[r])==65535)if(n[r+1]==1)o=n[r=Ht(n,r+2)];else{if(n[r+1]==2)return Ht(n,r+2);break}if(o==t||o==0)return Ht(n,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){if(t==this.stateSlot(e,4))return!0;for(let n=this.stateSlot(e,1);;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Ht(this.data,n+2);else return!1;if(t==Ht(this.data,n+1))return!0}}nextStates(e){let t=[];for(let n=this.stateSlot(e,1);;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Ht(this.data,n+2);else break;if(!(this.data[n+2]&1)){let s=this.data[n+1];t.some((r,o)=>o&1&&r==s)||t.push(this.data[n],s)}}return t}overrides(e,t){let n=zf(this.data,this.tokenPrecTable,t);return n<0||zf(this.data,this.tokenPrecTable,e)<n}configure(e){let t=Object.assign(Object.create(Bn.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let n=this.topRules[e.top];if(!n)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=n}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(n=>{let s=e.tokenizers.find(r=>r.from==n);return s?s.to:n})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((n,s)=>{let r=e.specializers.find(l=>l.from==n.external);if(!r)return n;let o=Object.assign(Object.assign({},n),{external:r.to});return t.specializers[s]=Uf(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),n=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(n[o]=!0)}let s=null;for(let r=0;r<t.length;r++)if(!n[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new ta(e,n,s)}static deserialize(e){return new Bn(e)}};function Ht(i,e){return i[e]|i[e+1]<<16}function zf(i,e,t){for(let n=e,s;(s=i[n])!=65535;n++)if(s==t)return n-e;return-1}function I0(i){let e=null;for(let t of i){let n=t.p.stoppedAt;(t.pos==t.p.stream.end||n!=null&&t.pos>n)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Uf(i){if(i.external){let e=i.extend?1:0;return(t,n)=>i.external(t,n)<<1|e}return i.get}var Kf=Bn.deserialize({version:14,states:"%jOVQPOOOOQO'#Cc'#CcO[QQO'#CbOOQO'#Ca'#CaOvQQO'#C`O!UQQO'#C_O!aQQO'#C^QOQPOOOOQO'#Ce'#CeO!iQPO,58|O!tQPO,59]OVQPO'#C|O!yQQO,58zOVQPO'#C}O#XQQO,58yO#dQPO'#CyOOQO,58x,58xO#iQPO'#CoOOQO'#Cm'#CmOOQO1G.h1G.hO!iQPO1G.wOOQO,59h,59hOOQO-E6z-E6zOOQO,59i,59iOOQO-E6{-E6{OOQO,59e,59eO#nQPO,59ZO#sQPO'#CtO#{QPO7+$cOOQO1G.u1G.uO!iQPO'#C{O$QQPO,59`OOQO<<G}<<G}OOQO,59g,59gOOQO-E6y-E6y",stateData:"$Y~OtOS~OWPO~OYWOZWO[WO]WO^WO_WO`WOfYO~OkZOlSXnSXrSX~Ol]OnRXrRX~On_OrQX~OWbObbOdaO~OgdO~OkZOlSanSarSa~Ol]OnRarRa~OWiO~OWjO~OdmO~OinOjhX~OjpO~OinOjha~O",goto:"#]rPPsvy!P!W!]P!bPPPPPPP!eP!nP!WPP!sPPPP!vP!y#P#VRVORUOQTORg]SSO]ReZVROZ]VQOZ]RXQQcXQkdRqnVbXdnRldR`UQokRroQ[SRf[Q^TRh^",nodeNames:"\u26A0 Filter Expression OrExpression AndExpression FilterClause ColumnValueExpression Column Identifier Operator Eq NotEq Gt Lt Contains Starts Ends Value Int String Quote ColumnSetExpression In LBrack Values Comma RBrack And Or AsClause As",maxTerm:36,skippedNodes:[0],repeatNodeCount:3,tokenData:"1U~RkXY!vYZ!v]^!vpq!vqr#Xrs#d|}#i!Q![#n!^!_#v!_!`#{!`!a$Q!c!}$V!}#O$h#P#Q$m#R#S$V#T#U$r#U#V$V#V#W&p#W#X$V#X#Y*i#Y#]$V#]#^,e#^#c$V#c#d-a#d#g$V#g#h.]#h#o$V~!{St~XY!vYZ!v]^!vpq!v~#[P!_!`#_~#dOZ~~#iOd~~#nOi~~#sPb~!Q![#n~#{O]~~$QOY~~$VO[~P$[SWP!Q![$V!c!}$V#R#S$V#T#o$V~$mOg~~$rOj~R$wWWP!Q![$V!c!}$V#R#S$V#T#b$V#b#c%a#c#g$V#g#h&]#h#o$VR%fUWP!Q![$V!c!}$V#R#S$V#T#W$V#W#X%x#X#o$VR&PSkQWP!Q![$V!c!}$V#R#S$V#T#o$VR&dSnQWP!Q![$V!c!}$V#R#S$V#T#o$VR&uUWP!Q![$V!c!}$V#R#S$V#T#c$V#c#d'X#d#o$VR'^UWP!Q![$V!c!}$V#R#S$V#T#b$V#b#c'p#c#o$VR'uUWP!Q![$V!c!}$V#R#S$V#T#h$V#h#i(X#i#o$VR(^TWP!Q![$V!c!}$V#R#S$V#T#U(m#U#o$VR(rUWP!Q![$V!c!}$V#R#S$V#T#]$V#]#^)U#^#o$VR)ZUWP!Q![$V!c!}$V#R#S$V#T#b$V#b#c)m#c#o$VR)rUWP!Q![$V!c!}$V#R#S$V#T#g$V#g#h*U#h#o$VR*]S^QWP!Q![$V!c!}$V#R#S$V#T#o$VR*nUWP!Q![$V!c!}$V#R#S$V#T#b$V#b#c+Q#c#o$VR+VUWP!Q![$V!c!}$V#R#S$V#T#W$V#W#X+i#X#o$VR+nUWP!Q![$V!c!}$V#R#S$V#T#g$V#g#h,Q#h#o$VR,XS`QWP!Q![$V!c!}$V#R#S$V#T#o$VR,jUWP!Q![$V!c!}$V#R#S$V#T#b$V#b#c,|#c#o$VR-TSWPfQ!Q![$V!c!}$V#R#S$V#T#o$VR-fUWP!Q![$V!c!}$V#R#S$V#T#f$V#f#g-x#g#o$VR.PSWPlQ!Q![$V!c!}$V#R#S$V#T#o$VR.bUWP!Q![$V!c!}$V#R#S$V#T#h$V#h#i.t#i#o$VR.yTWP!Q![$V!c!}$V#R#S$V#T#U/Y#U#o$VR/_UWP!Q![$V!c!}$V#R#S$V#T#f$V#f#g/q#g#o$VR/vUWP!Q![$V!c!}$V#R#S$V#T#h$V#h#i0Y#i#o$VR0_UWP!Q![$V!c!}$V#R#S$V#T#g$V#g#h0q#h#o$VR0xSWP_Q!Q![$V!c!}$V#R#S$V#T#o$V",tokenizers:[0,1],topRules:{Filter:[0,1]},tokenPrec:0});var gx=In.define({name:"VuuFilterQuery",parser:Kf.configure({props:[Mr({Identifier:O.variableName,String:O.string,Or:O.emphasis,Operator:O.operator})]})});var Di,Gf=class{constructor(){ie(this,Di,void 0)}get lastExpression(){if(this.expression){let{filters:e}=this.expression;return e[e.length-1]}}get lastFilterClause(){let e=this.lastExpression;if(e){let{filters:t}=e;return t[t.length-1]}}get name(){return U(this,Di)}setName(e){_(this,Di,e)}toJson(){var e;return(e=this.expression)==null?void 0:e.toJson(U(this,Di))}};Di=new WeakMap;var L0=en.define([{tag:O.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:O.comment,color:"green",fontStyle:"italic"}]),N0=Ar(L0);var B0=j.theme({"&":{color:"var(--vuuFilterEditor-color)",backgroundColor:"var(--vuuFilterEditor-background)",fontSize:"var(--vuuFilterEditor-fontSize)"},".cm-content":{caretColor:"var(--vuuFilterEditor-cursorColor)",padding:0},".cm-line":{lineHeight:"var(--vuuFilterEditor-lineHeight)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-scroller":{fontFamily:"var(--vuuFilterEditor-fontFamily)"},".cm-tooltip":{background:"var(--vuuFilterEditor-tooltipBackground)",border:"var(--vuuFilterEditor-tooltipBorder)",boxShadow:"var(--vuuFilterEditor-tooltipElevation)","&.cm-tooltip-autocomplete > ul":{fontFamily:"var(--vuuFilterEditor-fontFamily)",fontSize:"var(--vuuFilterEditor-fontSize)",maxHeight:"240px"},"&.cm-tooltip-autocomplete > ul > li":{height:"var(--vuuFilterEditor-suggestion-height)",padding:"0 3px",lineHeight:"var(--vuuFilterEditor-suggestion-height)"},"&.cm-tooltip-autocomplete li[aria-selected]":{background:"var(--vuuFilterEditor-suggestion-selectedBackground)",color:"var(--vuuFilterEditor-suggestion-selectedColor)"}}},{dark:!1});var qf=require("react");var jf=require("react/jsx-runtime");var Hr=require("@vuu-ui/vuu-utils");var H0=["aggregate","viewport-update","columns","disabled","enabled","filter","groupBy","vuu-link-created","vuu-link-removed","vuu-links","vuu-menu","sort","subscribed"],Qf=i=>{let e=i.type;return H0.includes(e)};var Jf="GET_TABLE_LIST",Xf="GET_TABLE_META";var ia=i=>i.type==="connection-status",Yf=i=>typeof i.result<"u";function Zf(){var i=/^ws(s)?:\/\/.+/,e={},t=Symbol("setWebsocket"),n=Symbol("connectionCallback");async function s(p,g){return o(p,g)}async function r(p){o(p.url,p[n],p)}async function o(p,g,w){let S=e[p]||(e[p]={attemptsRemaining:5,status:"disconnected"});try{g({type:"connection-status",status:"connecting"});let k=typeof w<"u",I=await a(p);console.log("%c\u26A1 %cconnected","font-size: 24px;color: green;font-weight: bold;","color:green; font-size: 14px;"),w!==void 0&&w[t](I);let E=w!=null?w:new f(I,p,g),F=k?"reconnected":"connected";return g({type:"connection-status",status:F}),E.status=F,E}catch{let k=--S.attemptsRemaining>0;if(g({type:"connection-status",status:"disconnected",reason:"failed to connect",retry:k}),k)return l(p,g,w,1e4);throw Error("Failed to establish connection")}}var l=(p,g,w,S)=>new Promise(k=>{setTimeout(()=>{k(o(p,g,w))},S)}),a=p=>new Promise((g,w)=>{let S=i.test(p)?p:`wss://${p}`,k=new WebSocket(S);k.onopen=()=>g(k),k.onerror=I=>w(I)}),u=()=>{console.log("Connection cannot be closed, socket not yet opened")},h=p=>{console.log("Message cannot be sent, socket closed")},c=p=>{try{return JSON.parse(p)}catch{throw Error(`Error parsing JSON response from server ${p}`)}},f=class{constructor(p,g,w){this.close=u,this.requiresLogin=!0,this.send=h,this.status="ready",this.url=g,this[n]=w,this[t](p)}reconnect(){r(this)}[t](p){let g=this[n];p.onmessage=k=>{let I=c(k.data);g(I)},p.onerror=()=>{console.log("%c\u26A1 connection error","font-size: 24px;color: red;font-weight: bold;","color:red; font-size: 14px;"),g({type:"connection-status",status:"disconnected",reason:"error"}),this.status!=="closed"&&(r(this),this.send=S)},p.onclose=()=>{console.log("%c\u26A1 connection close","font-size: 24px;color: orange;font-weight: bold;","color:orange; font-size: 14px;"),g({type:"connection-status",status:"disconnected",reason:"close"}),this.status!=="closed"&&(r(this),this.send=S)};let w=k=>{p.send(JSON.stringify(k))},S=k=>{console.log("TODO queue message until websocket reconnected",{_msg:k})};this.send=w,this.close=()=>{console.log("[Connection] close websocket"),this.status="closed",p.close(),this.close=u,this.send=h}}},d="CHANGE_VP",m="CHANGE_VP_SUCCESS",b="CHANGE_VP_RANGE",y="CHANGE_VP_RANGE_SUCCESS",v="CLOSE_TREE_NODE",A="CLOSE_TREE_SUCCESS",C="CREATE_VP",T="CREATE_VP_SUCCESS",x="DISABLE_VP",R="DISABLE_VP_SUCCESS",L="ENABLE_VP",z="ENABLE_VP_SUCCESS",B="GET_VP_VISUAL_LINKS",M="GET_VIEW_PORT_MENUS",D="HB",H="HB_RESP",N="LOGIN",Q="LOGIN_SUCCESS",K="OPEN_TREE_NODE",oe="OPEN_TREE_SUCCESS",ke="REMOVE_VP",te="RPC_RESP",ve="SET_SELECTION",ge="SET_SELECTION_SUCCESS",Le="TABLE_META_RESP",Ne="TABLE_LIST_RESP",Ye="TABLE_ROW";function at(p,g,w=[],S=[]){for(let k=0,I=p.length;k<I;k++)(g(p[k],k)?w:S).push(p[k]);return[w,S]}var pn={IDX:0,RENDER_IDX:1,IS_LEAF:2,IS_EXPANDED:3,DEPTH:4,COUNT:5,KEY:6,SELECTED:7,count:8,PARENT_IDX:"parent_idx",IDX_POINTER:"idx_pointer",FILTER_COUNT:"filter_count",NEXT_FILTER_IDX:"next_filter_idx"};function Y({from:p,to:g},w=0,S=Number.MAX_SAFE_INTEGER){if(w===0)return{from:p,to:Math.min(g,S)};if(p===0)return{from:p,to:Math.min(g+w,S)};{let k=g-p,I=Math.round(w/2),E=p-I<0,F=S-(g+I)<0;return E&&F?{from:0,to:S}:E?{from:0,to:k+w}:F?{from:Math.max(0,S-(k+w)),to:S}:{from:p-I,to:g+I}}}var be=(p,{from:g,to:w})=>p>=g&&p<w,Ke=class{constructor(p,g){this.from=p,this.to=g}isWithin(p){return be(p,this)}overlap(p,g){return p>=this.to||g<this.from?[0,0]:[Math.max(p,this.from),Math.min(g,this.to)]}copy(){return new Ke(this.from,this.to)}},{KEY:mn}=pn,Un=String.fromCharCode(8200),ne=String.fromCharCode(8199),iw={DIGIT:ne,TWO_DIGITS:ne+ne,THREE_DIGITS:ne+ne+ne,FULL_PADDING:[null,Un+ne,Un+ne+ne,Un+ne+ne+ne,Un+ne+ne+ne+ne]},sw=ne+ne+ne+ne+ne+ne+ne+ne+ne,Yd={Enter:"Enter",Delete:"Delete"},Zd={Home:"Home",End:"End",ArrowRight:"ArrowRight",ArrowLeft:"ArrowLeft",ArrowDown:"ArrowDown",ArrowUp:"ArrowUp",Tab:"Tab"},ep={F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"},rw={...Yd,...Zd,...ep},Ra=(p,g,w,S)=>{let k=S*.25;return!p||!S||p.to-w<k?!0:p.from>0&&g-p.from<k},Cs=[],tp=class{constructor({from:p,to:g},{from:w,to:S},k){this.setRowCount=I=>{if(I<this.internalData.length&&(this.internalData.length=I),I<this.rowCount){this.rowsWithinRange=0;let E=Math.min(I,this.clientRange.to);for(let F=this.clientRange.from;F<E;F++){let G=F-this.range.from;this.internalData[G]!==void 0&&(this.rowsWithinRange+=1)}}this.rowCount=I},this.bufferSize=k,this.clientRange=new Ke(p,g),this.range=new Ke(w,S),this.internalData=new Array(k),this.rowsWithinRange=0,this.rowCount=0}get hasAllRowsWithinRange(){return this.rowsWithinRange===this.clientRange.to-this.clientRange.from||this.rowCount>0&&this.clientRange.from+this.rowsWithinRange===this.rowCount}setAtIndex(p,g){let w=this.isWithinClientRange(p);if(w||this.isWithinRange(p)){let S=p-this.range.from;!this.internalData[S]&&w&&(this.rowsWithinRange+=1),this.internalData[S]=g}return w}getAtIndex(p){return this.range.isWithin(p)&&this.internalData[p-this.range.from]!=null?this.internalData[p-this.range.from]:void 0}isWithinRange(p){return this.range.isWithin(p)}isWithinClientRange(p){return this.clientRange.isWithin(p)}setClientRange(p,g){let w=this.clientRange.from,S=Math.min(this.clientRange.to,this.rowCount);if(p===w&&g===S)return[!1,Cs,Cs];let k=this.clientRange.copy();this.clientRange.from=p,this.clientRange.to=g,this.rowsWithinRange=0;for(let G=p;G<g;G++){let Z=G-this.range.from;this.internalData[Z]&&(this.rowsWithinRange+=1)}let I=Cs,E=Cs,F=this.range.from;if(this.hasAllRowsWithinRange)if(g>k.to){let G=Math.max(p,k.to);I=this.internalData.slice(G-F,g-F)}else{let G=Math.min(k.from,g);I=this.internalData.slice(p-F,G-F)}else if(this.rowsWithinRange>0)if(g>k.to){let G=Math.max(p,k.to);E=this.internalData.slice(G-F,g-F).filter(Z=>!!Z)}else{let G=Math.max(k.from,g);E=this.internalData.slice(Math.max(0,p-F),G-F).filter(Z=>!!Z)}return[Ra(this.range,p,g,this.bufferSize),I,E]}setRange(p,g){let[w,S]=this.range.overlap(p,g),k=new Array(g-p+this.bufferSize);this.rowsWithinRange=0;for(let I=w;I<S;I++){let E=this.getAtIndex(I);if(E){let F=I-p;k[F]=E,this.isWithinClientRange(I)&&(this.rowsWithinRange+=1)}}this.internalData=k,this.range.from=p,this.range.to=g}getData(){var p;let{from:g,to:w}=this.range,{from:S,to:k}=this.clientRange,I=Math.max(0,S-g),E=Math.min(w-g,w,k-g,(p=this.rowCount)!=null?p:w);return this.internalData.slice(I,E)}getCurrentDataRange(){let p=this.internalData,g=p.length,[w]=this.internalData,S=this.internalData[g-1];if(w&&S)return[w.rowIndex,S.rowIndex];for(let k=0;k<g;k++)if(p[k]!==void 0){w=p[k];break}for(let k=g-1;k>=0;k--)if(p[k]!==void 0){S=p[k];break}return w&&S?[w.rowIndex,S.rowIndex]:[-1,-1]}},np=class{constructor(p){this.keys=new Map,this.free=[],this.nextKeyValue=0,this.reset(p)}next(){return this.free.length>0?this.free.pop():this.nextKeyValue++}reset({from:p,to:g}){this.keys.forEach((S,k)=>{(k<p||k>=g)&&(this.free.push(S),this.keys.delete(k))});let w=g-p;this.keys.size+this.free.length>w&&(this.free.length=w-this.keys.size);for(let S=p;S<g;S++)if(!this.keys.has(S)){let k=this.next();this.keys.set(S,k)}}keyFor(p){let g=this.keys.get(p);if(g===void 0)throw console.log(`key not found
11
+ keys: ${Object.entries(this.keys).map((w,S)=>`${w}=>${S}`).join(", ")}
12
+ free : ${this.free.join(",")}
13
+ `),Error(`KeySet, no key found for rowIndex ${p}`);return g}},ip=[],sp=([p],[g])=>p-g,rp=class{constructor({aggregations:p,bufferSize:g=50,columns:w,filter:S,groupBy:k=[],table:I,range:E,sort:F,title:G,viewport:Z,visualLink:Ge}){this.dataWindow=void 0,this.hasUpdates=!1,this.holdingPen=[],this.pendingOperations=new Map,this.pendingRangeRequest=null,this.rowCountChanged=!1,this.serverTableMeta=null,this.disabled=!1,this.isTree=!1,this.status="",this.suspended=!1,this.getNewRowCount=()=>{if(this.rowCountChanged&&this.dataWindow)return this.rowCountChanged=!1,this.dataWindow.rowCount},console.log(`Viewport::constructor bufferSize: ${g}`),this.aggregations=p,this.bufferSize=g,this.clientRange=E,this.clientViewportId=Z,this.columns=w,this.filter=S,this.groupBy=k,this.keys=new np(E),this.pendingLinkedParent=Ge,this.table=I,this.sort=F,this.title=G}get hasUpdatesToProcess(){return this.suspended?!1:this.rowCountChanged||this.hasUpdates}subscribe(){let{filter:p}=this.filter;return this.status=this.status==="subscribed"?"resubscribing":"subscribing",{type:C,table:this.table,range:Y(this.clientRange,this.bufferSize),aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:p}}}handleSubscribed({viewPortId:p,aggregations:g,columns:w,filterSpec:S,range:k,sort:I,groupBy:E}){return this.serverViewportId=p,this.status="subscribed",this.aggregations=g,this.columns=w,this.groupBy=E,this.isTree=E&&E.length>0,this.dataWindow=new tp(this.clientRange,k,this.bufferSize),{aggregations:g,type:"subscribed",clientViewportId:this.clientViewportId,columns:w,filter:S,groupBy:E,range:k,sort:I,tableMeta:this.serverTableMeta}}awaitOperation(p,g){this.pendingOperations.set(p,g)}completeOperation(p,...g){var w;let{clientViewportId:S,pendingOperations:k}=this,{type:I,data:E}=k.get(p);if(k.delete(p),I===b){let[F,G]=g;(w=this.dataWindow)==null||w.setRange(F,G),this.pendingRangeRequest=null}else{if(I==="groupBy")return this.isTree=E.length>0,this.groupBy=E,{clientViewportId:S,type:I,groupBy:E};if(I==="columns")return this.columns=E,{clientViewportId:S,type:I,columns:E};if(I==="filter")return this.filter=E,{clientViewportId:S,type:I,filter:E};if(I==="aggregate")return this.aggregations=E,{clientViewportId:S,type:"aggregate",aggregations:this.aggregations};if(I==="sort")return this.sort=E,{clientViewportId:S,type:I,sort:this.sort};if(I!=="selection"){if(I==="disable")return this.disabled=!0,{type:"disabled",clientViewportId:S};if(I==="enable")return this.disabled=!1,{type:"enabled",clientViewportId:S};if(I==="CREATE_VISUAL_LINK"){let[F,G,Z]=g;return this.linkedParent={colName:F,parentViewportId:G,parentColName:Z},this.pendingLinkedParent=void 0,{type:"vuu-link-created",clientViewportId:S,colName:F,parentViewportId:G,parentColName:Z}}else if(I==="REMOVE_VISUAL_LINK")return this.linkedParent=void 0,{type:"vuu-link-removed",clientViewportId:S}}}}rangeRequest(p,g){let w=b;if(this.dataWindow){let[S,k,I]=this.dataWindow.setClientRange(g.from,g.to);console.log(`Viewport [${g.from}]:[${g.to}] requested, dataWindow has ${this.dataWindow.getCurrentDataRange().join(":")}`);let E=S&&Ra(this.pendingRangeRequest,g.from,g.to,this.bufferSize)?{type:w,viewPortId:this.serverViewportId,...Y(g,this.bufferSize,this.dataWindow.rowCount)}:null;E&&(this.awaitOperation(p,{type:w}),this.pendingRangeRequest=E),this.keys.reset(this.dataWindow.clientRange);let F=([Z])=>Z<g.from||Z>=g.to;this.holdingPen.some(F)&&(this.holdingPen=this.holdingPen.filter(([Z])=>Z>=g.from&&Z<g.to));let G=this.isTree?Yr:Xr;return I.length&&I.forEach(Z=>{this.holdingPen.push(G(Z,this.keys))}),k.length?[E,k.map(Z=>G(Z,this.keys))]:[E]}else return[null]}setLinks(p){return this.links=p,[{type:"vuu-links",links:p,clientViewportId:this.clientViewportId},this.pendingLinkedParent]}setMenu(p){return{type:"vuu-menu",menu:p,clientViewportId:this.clientViewportId}}setTableMeta(p,g){this.serverTableMeta={columns:p,dataTypes:g}}createLink(p,g,w,S){let k={type:"CREATE_VISUAL_LINK",parentVpId:w,childVpId:this.serverViewportId,parentColumnName:S,childColumnName:g};return this.awaitOperation(p,k),k}removeLink(p){let g={type:"REMOVE_VISUAL_LINK",childVpId:this.serverViewportId};return this.awaitOperation(p,g),g}suspend(){this.suspended=!0}resume(){return this.suspended=!1,this.currentData()}currentData(){let p=[];if(this.dataWindow){let g=this.dataWindow.getData(),{keys:w}=this,S=this.isTree?Yr:Xr;for(let k of g)k&&p.push(S(k,w))}return p}enable(p){return this.awaitOperation(p,{type:"enable"}),{type:L,viewPortId:this.serverViewportId}}disable(p){return this.awaitOperation(p,{type:"disable"}),{type:x,viewPortId:this.serverViewportId}}columnRequest(p,g){return this.awaitOperation(p,{type:"columns",data:g}),this.createRequest({columns:g})}filterRequest(p,g){this.awaitOperation(p,{type:"filter",data:g});let{filter:w}=g;return this.createRequest({filterSpec:{filter:w}})}aggregateRequest(p,g){return this.awaitOperation(p,{type:"aggregate",data:g}),this.createRequest({aggregations:g})}sortRequest(p,g){return this.awaitOperation(p,{type:"sort",data:g}),this.createRequest({sort:g})}groupByRequest(p,g=ip){return this.awaitOperation(p,{type:"groupBy",data:g}),this.createRequest({groupBy:g})}selectRequest(p,g){return this.awaitOperation(p,{type:"selection",data:g}),{type:ve,vpId:this.serverViewportId,selection:g}}handleUpdate(p,g,w){this.dataWindow&&(this.dataWindow.rowCount!==w.vpSize&&(this.dataWindow.setRowCount(w.vpSize),this.rowCountChanged=!0),p==="U"&&this.dataWindow.setAtIndex(g,w)&&(this.hasUpdates=!0))}getClientRows(p){if(this.hasUpdates&&this.dataWindow){let g=this.dataWindow.getData(),{keys:w}=this,S=this.isTree?Yr:Xr,k=this.dataWindow.hasAllRowsWithinRange?this.holdingPen.splice(0):void 0,I=k||this.holdingPen;for(let E of g)E&&E.ts>=p&&I.push(S(E,w));return this.hasUpdates=!1,k&&k.sort(sp)}}createRequest(p){return{type:d,viewPortId:this.serverViewportId,aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:this.filter.filter},...p}}},Xr=({rowIndex:p,rowKey:g,sel:w,data:S},k)=>[p,k.keyFor(p),!0,null,null,1,g,w].concat(S),Yr=({rowIndex:p,rowKey:g,sel:w,data:S},k)=>{let[I,E,,F,,G,...Z]=S;return[p,k.keyFor(p),F,E,I,G,g,w].concat(Z)},op=p=>{switch(p){case"TypeAheadRpcHandler":return"TYPEAHEAD";default:return"SIMUL"}},lp=p=>p.type==="connection-status",ap=p=>"viewport"in p,up=["VIEW_PORT_MENUS_SELECT_RPC","VIEW_PORT_MENU_TABLE_RPC","VIEW_PORT_MENU_ROW_RPC","VIEW_PORT_MENU_CELL_RPC"],hp=p=>up.includes(p.type),Ea=({requestId:p,...g})=>[p,g],Da=1,We=()=>`${Da++}`,cp=[],fp={},dp=p=>p.disabled!==!0&&p.suspended!==!0,pp=(p,g,w)=>p.map(S=>S.parentVpId===g?{...S,label:w}:S);function mp(p,g){return p.map(w=>{let{parentVpId:S}=w,k=g.get(S);if(k)return{...w,parentClientVpId:k.clientViewportId,label:k.title};throw Error("addLabelsToLinks viewport not found")})}var gp=class{constructor(p,g){this.authToken="",this.pendingTableMetaRequests=new Map,this.queuedRequests=[],this.cachedTableMeta=new Map,this.connection=p,this.postMessageToClient=g,this.viewports=new Map,this.mapClientToServerViewport=new Map}async reconnect(){await this.login(this.authToken);let[p,g]=at(Array.from(this.viewports.values()),dp);this.viewports.clear(),this.mapClientToServerViewport.clear();let w=S=>{S.forEach(k=>{let{clientViewportId:I}=k;this.viewports.set(I,k),this.sendMessageToServer(k.subscribe(),I)})};w(p),setTimeout(()=>{w(g)},2e3)}async login(p){if(p)return this.authToken=p,new Promise((g,w)=>{this.sendMessageToServer({type:N,token:this.authToken,user:"user"},""),this.pendingLogin={resolve:g,reject:w}});this.authToken===""&&console.warn("ServerProxy login, cannot login until auth token has been obtained")}subscribe(p){if(this.mapClientToServerViewport.has(p.viewport))console.log(`ServerProxy spurious subscribe call ${p.viewport}`);else{if(!this.hasMetaDataFor(p.table)){let w=We();this.sendMessageToServer({type:"GET_TABLE_META",table:p.table},w),this.pendingTableMetaRequests.set(w,p.viewport)}let g=new rp(p);this.viewports.set(p.viewport,g),this.sendIfReady(g.subscribe(),p.viewport,this.sessionId!=="")}}unsubscribe(p){let g=this.mapClientToServerViewport.get(p);g?this.sendMessageToServer({type:ke,viewPortId:g}):console.error(`ServerProxy: failed to unsubscribe client viewport ${p}, viewport not found`)}getViewportForClient(p,g=!0){let w=this.mapClientToServerViewport.get(p);if(w){let S=this.viewports.get(w);if(S)return S;if(g)throw Error(`Viewport not found for client viewport ${p}`);return null}else{if(this.viewports.has(p))return this.viewports.get(p);if(g)throw Error(`Viewport server id not found for client viewport ${p}`);return null}}setViewRange(p,g){let w=We(),[S,k]=p.rangeRequest(w,g.range);S&&this.sendIfReady(S,w,p.status==="subscribed"),k&&this.postMessageToClient({type:"viewport-update",clientViewportId:p.clientViewportId,rows:k})}aggregate(p,g){let w=We(),S=p.aggregateRequest(w,g.aggregations);this.sendIfReady(S,w,p.status==="subscribed")}sort(p,g){let w=We(),S=p.sortRequest(w,g.sort);this.sendIfReady(S,w,p.status==="subscribed")}groupBy(p,g){let w=We(),S=p.groupByRequest(w,g.groupBy);this.sendIfReady(S,w,p.status==="subscribed")}filter(p,g){let w=We(),{filter:S}=g,k=p.filterRequest(w,S);this.sendIfReady(k,w,p.status==="subscribed")}setColumns(p,g){let w=We(),{columns:S}=g,k=p.columnRequest(w,S);this.sendIfReady(k,w,p.status==="subscribed")}setTitle(p,g){p&&(p.title=g.title,this.updateTitleOnVisualLinks(p))}select(p,g){let w=We(),{selected:S}=g,k=p.selectRequest(w,S);this.sendIfReady(k,w,p.status==="subscribed")}disableViewport(p){let g=We(),w=p.disable(g);this.sendIfReady(w,g,p.status==="subscribed")}enableViewport(p){let g=We(),w=p.enable(g);this.sendIfReady(w,g,p.status==="subscribed")}resumeViewport(p){let g=p.resume();this.postMessageToClient({clientViewportId:p.clientViewportId,rows:g,type:"viewport-update"})}openTreeNode(p,g){p.serverViewportId&&this.sendIfReady({type:K,vpId:p.serverViewportId,treeKey:g.key},We(),p.status==="subscribed")}closeTreeNode(p,g){p.serverViewportId&&this.sendIfReady({type:v,vpId:p.serverViewportId,treeKey:g.key},We(),p.status==="subscribed")}createLink(p,g){let{parentClientVpId:w,parentColumnName:S,childColumnName:k}=g,I=We(),E=this.mapClientToServerViewport.get(w);if(E){let F=p.createLink(I,k,E,S);this.sendMessageToServer(F,I)}else console.warn("ServerProxy unable to create link, viewport not found")}removeLink(p){let g=We(),w=p.removeLink(g);this.sendMessageToServer(w,g)}updateTitleOnVisualLinks(p){var g;let{serverViewportId:w,title:S}=p;for(let k of this.viewports.values())if(k!==p&&k.links&&w&&S&&(g=k.links)!=null&&g.some(I=>I.parentVpId===w)){let[I]=k.setLinks(pp(k.links,w,S));this.postMessageToClient(I)}}removeViewportFromVisualLinks(p){var g;for(let w of this.viewports.values())if((g=w.links)!=null&&g.some(({parentVpId:S})=>S===p)){let[S]=w.setLinks(w.links.filter(({parentVpId:k})=>k!==p));this.postMessageToClient(S)}}menuRpcCall(p){let g=this.getViewportForClient(p.vpId,!1);if(g!=null&&g.serverViewportId){let[w,S]=Ea(p);this.sendMessageToServer({...S,vpId:g.serverViewportId},w)}}rpcCall(p){let[g,w]=Ea(p),S=op(w.service);this.sendMessageToServer(w,g,{module:S})}handleMessageFromClient(p){if(ap(p))if(p.type==="disable"){let g=this.getViewportForClient(p.viewport,!1);return g!==null?this.disableViewport(g):void 0}else{let g=this.getViewportForClient(p.viewport);switch(p.type){case"setViewRange":return this.setViewRange(g,p);case"aggregate":return this.aggregate(g,p);case"sort":return this.sort(g,p);case"groupBy":return this.groupBy(g,p);case"filter":return this.filter(g,p);case"select":return this.select(g,p);case"suspend":return g.suspend();case"resume":return this.resumeViewport(g);case"enable":return this.enableViewport(g);case"openTreeNode":return this.openTreeNode(g,p);case"closeTreeNode":return this.closeTreeNode(g,p);case"createLink":return this.createLink(g,p);case"removeLink":return this.removeLink(g);case"setColumns":return this.setColumns(g,p);case"setTitle":return this.setTitle(g,p);default:}}else{if(hp(p))return this.menuRpcCall(p);{let{type:g,requestId:w}=p;switch(g){case"GET_TABLE_LIST":return this.sendMessageToServer({type:g},w);case"GET_TABLE_META":return this.sendMessageToServer({type:g,table:p.table},w);case"RPC_CALL":return this.rpcCall(p);default:}}}console.log(`Vuu ServerProxy Unexpected message from client ${JSON.stringify(p)}`)}sendIfReady(p,g,w=!0){return w?this.sendMessageToServer(p,g):this.queuedRequests.push(p),w}sendMessageToServer(p,g=`${Da++}`,w=fp){let{module:S="CORE"}=w;this.authToken&&this.connection.send({requestId:g,sessionId:this.sessionId,token:this.authToken,user:"user",module:S,body:p})}handleMessageFromServer(p){var g;let{body:w,requestId:S,sessionId:k}=p,{viewports:I}=this;switch(w.type){case D:this.sendMessageToServer({type:H,ts:+new Date},"NA");break;case Q:if(k)this.sessionId=k,(g=this.pendingLogin)==null||g.resolve(k),this.pendingLogin=void 0;else throw Error("LOGIN_SUCCESS did not provide sessionId ");break;case T:{let E=I.get(S);if(E){let{status:F}=E,{viewPortId:G}=w;S!==G&&(I.delete(S),I.set(G,E)),this.mapClientToServerViewport.set(S,G);let Z=E.handleSubscribed(w);Z&&this.postMessageToClient(Z),E.disabled&&this.disableViewport(E),F==="subscribing"&&(this.sendMessageToServer({type:B,vpId:G}),this.sendMessageToServer({type:M,vpId:G}),Array.from(I.entries()).filter(([Ge,{disabled:Kn}])=>Ge!==G&&!Kn).forEach(([Ge])=>{this.sendMessageToServer({type:B,vpId:Ge})}))}}break;case"REMOVE_VP_SUCCESS":{let E=this.viewports.get(w.viewPortId);E&&(this.mapClientToServerViewport.delete(E.clientViewportId),I.delete(w.viewPortId),this.removeViewportFromVisualLinks(w.viewPortId))}break;case ge:{let E=this.viewports.get(w.vpId);E&&E.completeOperation(S)}break;case m:case R:if(I.has(w.viewPortId)){let E=this.viewports.get(w.viewPortId);if(E){let F=E.completeOperation(S);F!==void 0&&this.postMessageToClient(F)}}break;case z:{let E=this.viewports.get(w.viewPortId);if(E){let F=E.completeOperation(S);if(F){this.postMessageToClient(F);let G=E.currentData();this.postMessageToClient({clientViewportId:E.clientViewportId,rows:G,type:"viewport-update"})}}}break;case Ye:{let{timeStamp:E}=w,[{ts:F}={ts:E}]=w.rows||cp;for(let G of w.rows){let{viewPortId:Z,rowIndex:Ge,rowKey:Kn,updateType:xs}=G,Gn=I.get(Z);Gn?Gn.isTree&&xs==="U"&&!Kn.startsWith("$root")||Gn.handleUpdate(xs,Ge,G):console.warn(`TABLE_ROW message received for non registered viewport ${Z}`)}this.processUpdates(F)}break;case y:{let E=this.viewports.get(w.viewPortId);if(E){let{from:F,to:G}=w;E.completeOperation(S,F,G)}}break;case oe:case A:break;case"CREATE_VISUAL_LINK_SUCCESS":{let E=this.viewports.get(w.childVpId),F=this.viewports.get(w.parentVpId);if(E&&F){let{childColumnName:G,parentColumnName:Z}=w,Ge=E.completeOperation(S,G,F.clientViewportId,Z);Ge&&this.postMessageToClient(Ge)}}break;case"REMOVE_VISUAL_LINK_SUCCESS":{let E=this.viewports.get(w.childVpId);if(E){let F=E.completeOperation(S);F&&this.postMessageToClient(F)}}break;case Ne:this.postMessageToClient({type:Ne,tables:w.tables,requestId:S});break;case Le:{this.cacheTableMeta(w.table,w.columns,w.dataTypes);let E=this.pendingTableMetaRequests.get(S);if(E){this.pendingTableMetaRequests.delete(S);let F=this.viewports.get(E);F?F.setTableMeta(w.columns,w.dataTypes):console.log("Message has come back AFTER CREATE_VP_SUCCESS, what do we do now")}else this.postMessageToClient({type:Le,table:w.table,columns:w.columns,dataTypes:w.dataTypes,requestId:S})}break;case"VP_VISUAL_LINKS_RESP":{let E=this.getActiveLinks(w.links),F=this.viewports.get(w.vpId);if(E.length&&F){let G=mp(E,this.viewports),[Z,Ge]=F.setLinks(G);if(this.postMessageToClient(Z),Ge){let{link:Kn,parentClientVpId:xs}=Ge,Gn=We(),Pa=this.mapClientToServerViewport.get(xs);if(Pa){let vp=F.createLink(Gn,Kn.fromColumn,Pa,Kn.toColumn);this.sendMessageToServer(vp,Gn)}}}}break;case"VIEW_PORT_MENUS_RESP":if(w.menu.name){let E=this.viewports.get(w.vpId);if(E){let F=E.setMenu(w.menu);this.postMessageToClient(F)}}break;case"VIEW_PORT_MENU_RESP":{let{action:E}=w;this.postMessageToClient({type:"VIEW_PORT_MENU_RESP",action:E,tableAlreadyOpen:this.isTableOpen(E.table),requestId:S})}break;case te:{let{method:E,result:F}=w;this.postMessageToClient({type:te,method:E,result:F,requestId:S})}break;case"ERROR":console.error(w.msg);break;default:console.log(`handleMessageFromServer ${w.type}.`)}}hasMetaDataFor(p){return this.cachedTableMeta.has(`${p.module}:${p.table}`)}cacheTableMeta(p,g,w){this.hasMetaDataFor(p)||this.cachedTableMeta.set(`${p.module}:${p.table}`,{columns:g,serverDataTypes:w})}isTableOpen(p){if(p){let g=p.table;for(let w of this.viewports.values())if(!w.suspended&&w.table.table===g)return!0}}getActiveLinks(p){return p.filter(g=>{let w=this.viewports.get(g.parentVpId);return w&&!w.suspended})}processUpdates(p){this.viewports.forEach(g=>{if(g.hasUpdatesToProcess){let w=g.getClientRows(p),S=g.getNewRowCount();(S!==void 0||w&&w.length>0)&&this.postMessageToClient({clientViewportId:g.clientViewportId,rows:w,size:S,type:"viewport-update"})}})}},gn;async function bp(p,g,w){let S=await s(p,k=>{lp(k)?(w(k),k.status==="reconnected"&&gn.reconnect()):gn.handleMessageFromServer(k)});gn=new gp(S,k=>yp(k)),S.requiresLogin&&await gn.login(g)}function yp(p){postMessage(p)}var wp=async({data:p})=>{switch(p.type){case"connect":await bp(p.url,p.token,postMessage),postMessage({type:"connected"});break;case"subscribe":gn.subscribe(p);break;case"unsubscribe":gn.unsubscribe(p.viewport);break;default:gn.handleMessageFromClient(p)}};self.addEventListener("message",wp),postMessage({type:"ready"})}var _0=Zf.toString().replace(/(?:^function(?:\s+[^(]*)?\(\)\s*\{)|(?:\}$)/g,""),$0=new Blob([_0],{type:"text/javascript"}),z0=URL.createObjectURL($0),Pi,sa,ra=[],U0,K0,G0=new Promise((i,e)=>{U0=i,K0=e}),Wr=()=>G0,Br=new Map,Fr=new Map,q0=async(i,e="",t)=>e===""&&sa===void 0?new Promise(n=>{ra.push({resolve:n})}):sa||(sa=new Promise(n=>{let s=new Worker(z0),r=window.setTimeout(()=>{console.error("timed out waiting for worker to load")},1e3);s.onmessage=o=>{let{data:l}=o;if(l.type==="ready")window.clearTimeout(r),s.postMessage({type:"connect",url:i,token:e});else if(l.type==="connected"){s.onmessage=ed,n(s);for(let a of ra)a.resolve(s);ra.length=0}else ia(l)?t(o):console.log("ConnectionManager: Unexpected message from the worker")}}));function ed({data:i}){if(ia(i))td.emit("connection-status",i);else if(Qf(i)){let e=Br.get(i.clientViewportId);e?e.postMessageToClientDataSource(i):console.error(`[ConnectionManager] ${i.type} message received, viewport not found`)}else{let e=i.requestId;if(Fr.has(e)){let{resolve:t}=Fr.get(e);Fr.delete(e);let{type:n,requestId:s,...r}=i;Yf(i)?t(i.result):t(r)}else console.log("%cConnectionManager Unexpected message from the worker","color:red;font-weight:bold;")}}var oa=i=>{let e=(0,Hr.uuid)();return Pi.postMessage({requestId:e,...i}),new Promise((t,n)=>{Fr.set(e,{resolve:t,reject:n})})},j0={subscribe:(i,e)=>{Br.set(i.viewport,{status:"subscribing",request:i,postMessageToClientDataSource:e}),Pi.postMessage({type:"subscribe",...i})},unsubscribe:i=>{Pi.postMessage({type:"unsubscribe",viewport:i})},send:i=>{Pi.postMessage(i)},destroy:i=>{i&&Br.has(i)&&Br.delete(i)},rpcCall:async i=>oa(i),getTableList:async()=>oa({type:Jf}),getTableMeta:async i=>oa({type:Xf,table:i})},la=class extends Hr.EventEmitter{async connect(e,t){return Pi=await q0(e,t,ed),j0}destroy(){console.log("MEGA DESTROY"),Pi.terminate()}},td=new la;var _r=require("@vuu-ui/vuu-utils"),bs=require("react"),{SELECTED:gS}=_r.metadataKeys;var aa=require("react");var J0=require("react");var X0=require("react");var Y0=i=>i.type==="vuu-links";var Z0=i=>i.type==="vuu-menu",nd=i=>Z0(i)||Y0(i),id=i=>i.type==="vuu-link-created"||i.type==="vuu-link-removed";var ua=require("react");var ey=([,i],[,e])=>i-e,$r=class{constructor(e){this.keys=new Map,this.free=[],this.nextKeyValue=0,this.reset(e)}next(){return this.free.length>0?this.free.pop():this.nextKeyValue++}reset({from:e,to:t}){this.keys.forEach((s,r)=>{(r<e||r>=t)&&(this.free.push(s),this.keys.delete(r))});let n=t-e;this.keys.size+this.free.length>n&&(this.free.length=n-this.keys.size);for(let s=e;s<t;s++)if(!this.keys.has(s)){let r=this.next();this.keys.set(s,r)}}keyFor(e){let t=this.keys.get(e);if(t===void 0)throw console.log(`key not found
14
+ keys: ${Object.entries(this.keys).map((n,s)=>`${n}=>${s}`).join(", ")}
15
+ free : ${this.free.join(",")}
16
+ `),Error(`KeySet, no key found for rowIndex ${e}`);return t}withKeys(e){for(let t of e)t[1]=this.keyFor(t[0]);return e.sort(ey)}};var ys=require("@vuu-ui/vuu-utils");var ty=(i,e)=>[e,e,!0,!1,1,0,i[0],0,...i],ny=i=>{let e={columns:[],dataTypes:[]};return i.forEach(t=>{var n;e.columns.push(t.name),e.dataTypes.push((n=t.serverDataType)!=null?n:"string")}),e},iy=(i,e)=>{let[t]=i,n=i.slice();return n[1]=e.keyFor(t),n},nn,sn,Fn,rn,on,ln,zr,Ur,an,Oi,sd=class extends ys.EventEmitter{constructor({aggregations:t,columnDescriptors:n,columns:s,data:r,filter:o,groupBy:l,sort:a,title:u,viewport:h}){super();this.status="initialising";this.disabled=!1;this.suspended=!1;ie(this,nn,[]);ie(this,sn,[]);ie(this,Fn,void 0);ie(this,rn,{filter:""});ie(this,on,[]);ie(this,ln,{from:0,to:0});ie(this,zr,0);ie(this,Ur,0);ie(this,an,{sortDefs:[]});ie(this,Oi,void 0);this.keys=new $r(U(this,ln));if(!r||!n)throw Error("ArrayDataSource constructor called without data");this.columnDescriptors=n,this.tableMeta=ny(n),_(this,Fn,r.map(ty)),this.viewport=h||(0,ys.uuid)(),t&&_(this,nn,t),s&&_(this,sn,s),o&&_(this,rn,o),l&&_(this,on,l),a&&_(this,an,a),_(this,Oi,u)}async subscribe({viewport:t=(h=>(h=this.viewport)!=null?h:(0,ys.uuid)())(),columns:n,aggregations:s,range:r,sort:o,groupBy:l,filter:a},u){var c;this.clientCallback=u,console.log(`subscribe range ${r==null?void 0:r.from} ${r==null?void 0:r.to}`),s&&_(this,nn,s),n&&_(this,sn,n),a&&_(this,rn,a),l&&_(this,on,l),r&&_(this,ln,r),o&&_(this,an,o),this.status==="initialising"&&(this.viewport=t,this.status="subscribed",(c=this.clientCallback)==null||c.call(this,{aggregations:U(this,nn),type:"subscribed",clientViewportId:this.viewport,columns:U(this,sn),filter:U(this,rn),groupBy:U(this,on),range:U(this,ln),sort:U(this,an),tableMeta:this.tableMeta}),this.clientCallback({clientViewportId:this.viewport,type:"viewport-update",size:U(this,Fn).length}))}unsubscribe(){console.log("noop")}suspend(){return console.log("noop"),this}resume(){return console.log("noop"),this}disable(){return console.log("noop"),this}enable(){return console.log("noop"),this}select(t){console.log("TODO: select",{selected:t})}openTreeNode(t){console.log("TODO: open tree node",{key:t})}closeTreeNode(t){console.log("TODO: close tree node",{key:t})}get config(){}get selectedRowsCount(){return U(this,zr)}get size(){return U(this,Ur)}get range(){return U(this,ln)}set range(t){_(this,ln,t),this.keys.reset(t),requestAnimationFrame(()=>{var n;(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,rows:U(this,Fn).slice(t.from,t.to).map(s=>iy(s,this.keys)),size:U(this,Fn).length,type:"viewport-update"})})}get columns(){return U(this,sn)}set columns(t){_(this,sn,t),console.log(`ArrayDataSource setColumns ${t.join(",")}`)}get aggregations(){return U(this,nn)}set aggregations(t){_(this,nn,t)}get sort(){return U(this,an)}set sort(t){_(this,an,t)}get filter(){return U(this,rn)}set filter(t){_(this,rn,t),console.log(`RemoteDataSource ${JSON.stringify(t)}`)}get groupBy(){return U(this,on)}set groupBy(t){_(this,on,t)}get title(){return U(this,Oi)}set title(t){_(this,Oi,t)}createLink({parentVpId:t,link:{fromColumn:n,toColumn:s}}){console.log("create link",{parentVpId:t,fromColumn:n,toColumn:s})}removeLink(){console.log("remove link")}async menuRpcCall(t){console.log("rmenuRpcCall",{rpcRequest:t})}};nn=new WeakMap,sn=new WeakMap,Fn=new WeakMap,rn=new WeakMap,on=new WeakMap,ln=new WeakMap,zr=new WeakMap,Ur=new WeakMap,an=new WeakMap,Oi=new WeakMap;var Kr=require("@vuu-ui/vuu-utils");var un,hn,Vi,cn,Wt,Hn,ws,Ii,fn,Wn,Li,rd=class extends Kr.EventEmitter{constructor({bufferSize:t=100,aggregations:n,columns:s,filter:r,groupBy:o,onConfigChange:l,sort:a,table:u,title:h,viewport:c,visualLink:f}){super();this.server=null;this.status="initialising";this.disabled=!1;this.suspended=!1;ie(this,un,[]);ie(this,hn,[]);ie(this,Vi,void 0);ie(this,cn,{filter:""});ie(this,Wt,[]);ie(this,Hn,{from:0,to:0});ie(this,ws,0);ie(this,Ii,0);ie(this,fn,{sortDefs:[]});ie(this,Wn,void 0);ie(this,Li,void 0);this.handleMessageFromServer=t=>{var n,s;t.type==="subscribed"?(this.status="subscribed",this.emit("subscribed",t),(n=this.clientCallback)==null||n.call(this,t)):t.type==="disabled"?this.status="disabled":t.type==="enabled"?this.status="enabled":(t.type==="viewport-update"&&t.size!==void 0&&t.size!==U(this,Ii)&&(this.rowCount=t.size,_(this,Ii,t.size)),(s=this.clientCallback)==null||s.call(this,t))};if(!u)throw Error("RemoteDataSource constructor called without table");this.bufferSize=t,this.onConfigChange=l,this.table=u,this.viewport=c,n&&_(this,un,n),s&&_(this,hn,s),r&&_(this,cn,r),o&&_(this,Wt,o),a&&_(this,fn,a),_(this,Wn,h),_(this,Li,f),this.refreshConfig()}async subscribe({viewport:t=(h=>(h=this.viewport)!=null?h:(0,Kr.uuid)())(),columns:n,aggregations:s,range:r,sort:o,groupBy:l,filter:a},u){var f;if(this.clientCallback=u,s&&_(this,un,s),n&&_(this,hn,n),a&&_(this,cn,a),l&&_(this,Wt,l),r&&_(this,Hn,r),o&&_(this,fn,o),this.status!=="initialising")return;this.status="subscribing",this.viewport=t,this.server=await Wr();let{bufferSize:c}=this;(f=this.server)==null||f.subscribe({aggregations:U(this,un),bufferSize:c,columns:U(this,hn),filter:U(this,cn),groupBy:U(this,Wt),viewport:t,table:this.table,range:U(this,Hn),sort:U(this,fn),title:U(this,Wn),visualLink:this.visualLink},this.handleMessageFromServer)}unsubscribe(){var t,n;this.viewport&&((t=this.server)==null||t.unsubscribe(this.viewport)),(n=this.server)==null||n.destroy(this.viewport)}suspend(){var t;return this.viewport&&(this.suspended=!0,(t=this.server)==null||t.send({type:"suspend",viewport:this.viewport})),this}resume(){var t;return this.viewport&&this.suspended&&((t=this.server)==null||t.send({type:"resume",viewport:this.viewport}),this.suspended=!1),this}disable(){var t;return this.viewport&&(this.status="disabling",this.disabled=!0,(t=this.server)==null||t.send({viewport:this.viewport,type:"disable"})),this}enable(){var t;return this.viewport&&this.disabled&&(this.status="enabling",(t=this.server)==null||t.send({viewport:this.viewport,type:"enable"}),this.disabled=!1),this}select(t){var n;_(this,ws,t.length),this.viewport&&((n=this.server)==null||n.send({viewport:this.viewport,type:"select",selected:t}))}openTreeNode(t){var n;this.viewport&&((n=this.server)==null||n.send({viewport:this.viewport,type:"openTreeNode",key:t}))}closeTreeNode(t){var n;this.viewport&&((n=this.server)==null||n.send({viewport:this.viewport,type:"closeTreeNode",key:t}))}refreshConfig(){let{aggregations:t,columns:n,filter:s,groupBy:r,sort:o,visualLink:l}=this,a=t.length>0,u=n.length>0,h=s.filter!=="",c=r.length>0,f=o.sortDefs.length>0,d=l!==void 0;if(a||u||h||c||f){let m={};return a&&(m.aggregations=t),u&&(m.columns=n),h&&(m.filter=s),c&&(m.groupBy=r),f&&(m.sort=o),d&&(m.visualLink=l),_(this,Vi,m)}else return _(this,Vi,void 0)}get config(){return U(this,Vi)}get selectedRowsCount(){return U(this,ws)}get size(){return U(this,Ii)}get range(){return U(this,Hn)}set range(t){_(this,Hn,t),this.viewport&&this.server&&this.server.send({viewport:this.viewport,type:"setViewRange",range:t})}get columns(){return U(this,hn)}set columns(t){var s;if(console.log(`RemoteDataSOurce ${t.join(",")}`),_(this,hn,t),this.viewport){let r={viewport:this.viewport,type:"setColumns",columns:t};this.server&&this.server.send(r)}let n=this.refreshConfig();(s=this.onConfigChange)==null||s.call(this,n)}get aggregations(){return U(this,un)}set aggregations(t){var s,r;_(this,un,t),this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"aggregate",aggregations:t}));let n=this.refreshConfig();(r=this.onConfigChange)==null||r.call(this,n)}get sort(){return U(this,fn)}set sort(t){var s;if(_(this,fn,t),this.viewport){let r={viewport:this.viewport,type:"sort",sort:t};this.server&&this.server.send(r)}let n=this.refreshConfig();(s=this.onConfigChange)==null||s.call(this,n)}get filter(){return U(this,cn)}set filter(t){var s;if(_(this,cn,t),this.viewport){let r={viewport:this.viewport,type:"filter",filter:t};this.server&&this.server.send(r)}let n=this.refreshConfig();(s=this.onConfigChange)==null||s.call(this,n)}get groupBy(){return U(this,Wt)}set groupBy(t){var s;if(_(this,Wt,t!=null?t:[]),this.viewport){let r={viewport:this.viewport,type:"groupBy",groupBy:U(this,Wt)};this.server&&this.server.send(r)}let n=this.refreshConfig();(s=this.onConfigChange)==null||s.call(this,n)}get title(){return U(this,Wn)}set title(t){var n;_(this,Wn,t),this.viewport&&t&&((n=this.server)==null||n.send({type:"setTitle",title:t,viewport:this.viewport}))}get visualLink(){return U(this,Li)}set visualLink(t){var s,r,o;if(_(this,Li,t),console.log("create visual link ",{visualLink:t}),t){let{parentClientVpId:l,link:{fromColumn:a,toColumn:u}}=t;this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"createLink",parentClientVpId:l,parentColumnName:u,childColumnName:a}))}else this.viewport&&((r=this.server)==null||r.send({type:"removeLink",viewport:this.viewport}));let n=this.refreshConfig();(o=this.onConfigChange)==null||o.call(this,n)}async menuRpcCall(t){var n;if(this.viewport)return(n=this.server)==null?void 0:n.rpcCall({vpId:this.viewport,...t})}};un=new WeakMap,hn=new WeakMap,Vi=new WeakMap,cn=new WeakMap,Wt=new WeakMap,Hn=new WeakMap,ws=new WeakMap,Ii=new WeakMap,fn=new WeakMap,Wn=new WeakMap,Li=new WeakMap;var sy=/^ws(s)?:\/\/.+/,od={},ca=Symbol("setWebsocket"),Gr=Symbol("connectionCallback");async function ha(i){ud(i.url,i[Gr],i)}async function ud(i,e,t){let n=od[i]||(od[i]={attemptsRemaining:5,status:"disconnected"});try{e({type:"connection-status",status:"connecting"});let s=typeof t<"u",r=await oy(i);console.log("%c\u26A1 %cconnected","font-size: 24px;color: green;font-weight: bold;","color:green; font-size: 14px;"),t!==void 0&&t[ca](r);let o=t!=null?t:new fa(r,i,e),l=s?"reconnected":"connected";return e({type:"connection-status",status:l}),o.status=l,o}catch{let r=--n.attemptsRemaining>0;if(e({type:"connection-status",status:"disconnected",reason:"failed to connect",retry:r}),r)return ry(i,e,t,1e4);throw Error("Failed to establish connection")}}var ry=(i,e,t,n)=>new Promise(s=>{setTimeout(()=>{s(ud(i,e,t))},n)}),oy=i=>new Promise((e,t)=>{let n=sy.test(i)?i:`wss://${i}`,s=new WebSocket(n);s.onopen=()=>e(s),s.onerror=r=>t(r)}),ld=()=>{console.log("Connection cannot be closed, socket not yet opened")},ad=i=>{console.log("Message cannot be sent, socket closed")},ly=i=>{try{return JSON.parse(i)}catch{throw Error(`Error parsing JSON response from server ${i}`)}},fa=class{constructor(e,t,n){this.close=ld;this.requiresLogin=!0;this.send=ad;this.status="ready";this.url=t,this[Gr]=n,this[ca](e)}reconnect(){ha(this)}[(Gr,ca)](e){let t=this[Gr];e.onmessage=r=>{let o=ly(r.data);t(o)},e.onerror=()=>{console.log("%c\u26A1 connection error","font-size: 24px;color: red;font-weight: bold;","color:red; font-size: 14px;"),t({type:"connection-status",status:"disconnected",reason:"error"}),this.status!=="closed"&&(ha(this),this.send=s)},e.onclose=()=>{console.log("%c\u26A1 connection close","font-size: 24px;color: orange;font-weight: bold;","color:orange; font-size: 14px;"),t({type:"connection-status",status:"disconnected",reason:"close"}),this.status!=="closed"&&(ha(this),this.send=s)};let n=r=>{e.send(JSON.stringify(r))},s=r=>{console.log("TODO queue message until websocket reconnected",{_msg:r})};this.send=n,this.close=()=>{console.log("[Connection] close websocket"),this.status="closed",e.close(),this.close=ld,this.send=ad}}};var hd=require("react");var cd=[{label:"=",boost:10},{label:"!=",boost:9}],ZS=[...cd,{label:"in",boost:6},{label:"starts",boost:5},{label:"ends",boost:4}],ek=[...cd,{label:">",boost:8},{label:"<",boost:7}];var py=require("@heswell/salt-lab"),my=Pe(require("classnames"),1);var pd=require("@heswell/salt-lab");var ay=require("@heswell/salt-lab"),fd=require("react"),uy=require("react/jsx-runtime");var hy=require("@heswell/salt-lab"),dd=require("react"),cy=require("react/jsx-runtime");var fy=require("react/jsx-runtime");var gy=require("react/jsx-runtime");var md=require("@vuu-ui/vuu-utils");var da=i=>i!==void 0&&i.op==="in";function pa(i){return i!==void 0&&(i.op==="and"||i.op==="or")}var qr=(i,e={})=>{if(pa(i)){let[t,n]=i.filters;return`${qr(t,e)} ${i.op} ${qr(n,e)}`}return da(i)?`${i.column} ${i.op} [${i.values.join(",")}]`:`${i.column} ${i.op} ${i.value}`};var gd=(i,e)=>{if(pa(e)){let[t,n]=e.filters;if(t.column===i.name)return[n,qr(n)];if(n.column===i.name)return[t,qr(t)]}return[void 0,""]};var Ie=require("@vuu-ui/vuu-utils"),by=(i,e)=>{if(i.filterStruct&&e){let[t,n]=gd(e,i.filterStruct);return{filter:n,filterStruct:t}}else return i},{Average:yy,Count:wy,High:vy,Low:Cy,Sum:xy}=Ie.AggregationType,bd=({dataSource:i,onPersistentColumnOperation:e})=>(n,s)=>{let r=s;if(r.column&&i){let{column:o}=r;switch(n){case"sort-asc":return i.sort=(0,Ie.setSortColumn)(i.sort,o,"A"),!0;case"sort-dsc":return i.sort=(0,Ie.setSortColumn)(i.sort,o,"D"),!0;case"sort-add-asc":return i.sort=(0,Ie.addSortColumn)(i.sort,o,"A"),!0;case"sort-add-dsc":return i.sort=(0,Ie.addSortColumn)(i.sort,o,"D"),!0;case"group":return i.groupBy=(0,Ie.addGroupColumn)(i.groupBy,o),!0;case"group-add":return i.groupBy=(0,Ie.addGroupColumn)(i.groupBy,o),!0;case"column-hide":return e({type:"hideColumn",column:o}),!0;case"column-remove":return i.columns=i.columns.filter(l=>l!==o.name),!0;case"filter-remove-column":return i.filter=by(i.filter,o),!0;case"remove-filters":return i.filter={filter:""},!0;case"agg-avg":return i.aggregations=(0,Ie.setAggregations)(i.aggregations,o,yy),!0;case"agg-high":return i.aggregations=(0,Ie.setAggregations)(i.aggregations,o,vy),!0;case"agg-low":return i.aggregations=(0,Ie.setAggregations)(i.aggregations,o,Cy),!0;case"agg-count":return i.aggregations=(0,Ie.setAggregations)(i.aggregations,o,wy),!0;case"agg-sum":return i.aggregations=(0,Ie.setAggregations)(i.aggregations,o,xy),!0;case"column-pin-floating":return e({type:"pinColumn",column:o,pin:"floating"}),!0;case"column-pin-left":return e({type:"pinColumn",column:o,pin:"left"}),!0;case"column-pin-right":return e({type:"pinColumn",column:o,pin:"right"}),!0;case"column-unpin":return e({type:"pinColumn",column:o,pin:void 0}),!0;default:}}return!1};var $t=require("@vuu-ui/vuu-utils"),ga=require("react");var ma=Pe(require("classnames")),yd=require("react");var _t=require("react/jsx-runtime"),Ni="vuuTable-groupHeaderCell",Sy=i=>{let{column:e,className:t,onRemoveColumn:n}=i;return(0,_t.jsxs)("div",{className:(0,ma.default)(`${Ni}-col`,t),role:"columnheader",children:[(0,_t.jsx)("span",{className:`${Ni}-label`,children:e.name}),(0,_t.jsx)("span",{className:`${Ni}-close`,"data-icon":"close-circle",onClick:()=>n==null?void 0:n(e)})]})},wd=({column:i,className:e,onRemoveColumn:t,onResize:n,...s})=>{let r=(0,yd.useRef)(null),{isResizing:o,...l}=Ls({column:i,onResize:n,rootRef:r}),a=(0,ma.default)(Ni,e,{vuuPinLeft:i.pin==="left",[`${Ni}-right`]:i.align==="right"}),{columns:u}=i;return(0,_t.jsx)("th",{className:a,...s,children:(0,_t.jsxs)("div",{className:`${Ni}-inner`,children:[u.map(h=>(0,_t.jsx)(Sy,{column:h,onRemoveColumn:t},h.key)),i.resizeable!==!1?(0,_t.jsx)(Is,{...l}):null]})})};var Ue=require("react/jsx-runtime"),vd="vuuDataTable",{RENDER_IDX:ky}=$t.metadataKeys,Cd=({columns:i,data:e,headings:t,onColumnResize:n,onHeaderCellDragStart:s,onContextMenu:r,onRemoveColumnFromGroupBy:o,onRowClick:l,onSort:a,onToggleGroup:u,rowHeight:h})=>{let c=(0,ga.useCallback)(d=>{console.log("RowBasedDataTable handleDragStart",{evt:d,onHeaderCellDragStart:s}),s==null||s(d)},[s]),f=(0,ga.useCallback)(d=>{var C;let b=d.target.closest(".vuuTable-headerCell"),y=parseInt((C=b==null?void 0:b.dataset.idx)!=null?C:"-1"),v=i[y],A=d.shiftKey;v&&a(v,A)},[i,a]);return(0,Ue.jsxs)("table",{className:`${vd}-table`,children:[(0,Ue.jsx)("colgroup",{children:i.filter($t.notHidden).map((d,m)=>(0,Ue.jsx)("col",{width:`${d.width}px`},m))}),(0,Ue.jsxs)("thead",{children:[t.map((d,m)=>(0,Ue.jsx)("tr",{className:"vuuTable-heading",children:d.map(({label:b,span:y},v)=>(0,Ue.jsx)("th",{colSpan:y,className:"vuuTable-headingCell",children:b},v))},m)),(0,Ue.jsx)("tr",{children:i.filter($t.notHidden).map((d,m)=>{let b=(0,$t.getColumnPinStyle)(d);return(0,$t.isGroupColumn)(d)?(0,Ue.jsx)(wd,{column:d,"data-idx":m,onRemoveColumn:o,onResize:n,style:b},m):(0,Ue.jsx)(Ns,{column:d,"data-idx":m,onClick:f,onDragStart:c,onResize:n,style:b},m)})})]}),(0,Ue.jsxs)("tbody",{onContextMenu:r,children:[e==null?void 0:e.map((d,m)=>(0,Ue.jsx)(Vs,{columns:i,height:h,index:m,onClick:l,onToggleGroup:u,row:d},d[ky])),(0,Ue.jsx)("tr",{className:`${vd}-filler`})]})]})};var Hi=require("@vuu-ui/vuu-utils"),we=require("react");var dn=require("@vuu-ui/vuu-utils"),ye=require("react"),{RENDER_IDX:xd,SELECTED:jr}=dn.metadataKeys,Sd=(i,e)=>i[xd]-e[xd],My=i=>["aggregate","columns","filter","groupBy","sort"].includes(i.type);function kd({dataSource:i,onConfigChange:e,onFeatureEnabled:t,onFeatureInvocation:n,onSizeChange:s,onSubscribed:r,range:o={from:0,to:0},renderBufferSize:l=0,viewportRowCount:a}){let[,u]=(0,ye.useState)(null),h=(0,ye.useRef)(!0),c=(0,ye.useRef)(!1),f=(0,ye.useRef)({from:0,to:0}),d=(0,ye.useRef)(null),m=(0,ye.useRef)([]),b=(0,ye.useMemo)(()=>new ba((0,dn.getFullRange)(o)),[]),y=(0,ye.useCallback)(x=>{for(let R of x)b.add(R);m.current=b.data.slice().sort(Sd),c.current=!0},[b]),v=(0,ye.useCallback)(x=>{x.type==="subscribed"?r==null||r(x):x.type==="viewport-update"?(typeof x.size=="number"&&(s==null||s(x.size),b.setRowCount(x.size)),x.rows?y(x.rows):typeof x.size=="number"&&(m.current=b.data.slice().sort(Sd),c.current=!0)):My(x)?e==null||e(x):nd(x)?t==null||t(x):id(x)?n==null||n(x):console.log(`useDataSource unexpected message ${x.type}`)},[b,e,t,n,s,r,y]);(0,ye.useEffect)(()=>()=>{d.current&&(cancelAnimationFrame(d.current),d.current=null),h.current=!1},[]);let A=(0,ye.useCallback)(()=>{h.current&&(c.current&&(u({}),c.current=!1),d.current=requestAnimationFrame(A))},[u]);(0,ye.useEffect)(()=>{d.current=requestAnimationFrame(A)},[A]);let C=(0,ye.useCallback)(x=>{let{from:R}=i.range,L=(0,dn.getFullRange)({from:R,to:R+x},l);i.range=f.current=L,b.setRange(L)},[i,b,l]),T=(0,ye.useCallback)(x=>{let R=(0,dn.getFullRange)(x,l);i.range=f.current=R,b.setRange(R)},[i,b,l]);return(0,ye.useEffect)(()=>{i==null||i.subscribe({range:f.current},v)},[i,v]),(0,ye.useEffect)(()=>{C(a)},[C,a]),{data:m.current,range:f.current,setRange:T,dataSource:i}}var ba=class{constructor({from:e,to:t}){this.rowCount=0;this.setRowCount=e=>{e<this.data.length&&(this.data.length=e),this.rowCount=e};this.range=new dn.WindowRange(e,t),this.data=new Array(t-e),this.rowCount=0}add(e){var n;let[t]=e;if(this.isWithinRange(t)){let s=t-this.range.from;this.data[s]=e;let r=e[jr],o=(n=this.data[s-1])==null?void 0:n[jr];o===0&&r?this.data[s-1][jr]=2:o===2&&!r&&(this.data[s-1][jr]=0)}}getAtIndex(e){return this.range.isWithin(e)&&this.data[e-this.range.from]!=null?this.data[e-this.range.from]:void 0}isWithinRange(e){return this.range.isWithin(e)}setRange({from:e,to:t}){if(e!==this.range.from||t!==this.range.to){let[n,s]=this.range.overlap(e,t),r=new Array(t-e);for(let o=n;o<s;o++){let l=this.getAtIndex(o);if(l){let a=o-e;r[a]=l}}this.data=r,this.range.from=e,this.range.to=t}}};var Ed=require("@vuu-ui/vuu-utils"),Se=require("react");function Ty(i,...e){let t=new Set(i);for(let n of e)for(let s of n)t.add(s);return t}var ya="ArrowUp",wa="ArrowDown",va="ArrowLeft",Ca="ArrowRight";var xa="Home",Sa="End",ka="PageUp",Ma="PageDown";var Ay=new Set(["Enter","Delete"," "]),Ry=new Set(["Tab"]),Ey=new Set(["ArrowRight","ArrowLeft"]),Md=new Set([xa,Sa,ka,Ma,wa,va,Ca,ya]),Dy=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),dM=Ty(Ay,Md,Ey,Dy,Ry);var Py=["Home","End","PageUp","PageDown"],Td=i=>Py.includes(i),Ad=i=>Md.has(i);var Rd=i=>`thead th:nth-child(${i+1})`,Oy=(i,e)=>`tbody > tr[data-idx='${i}'] > td:nth-child(${e+1})`,Vy=[-1,-1];function Iy(i,[e,t],n,s){return i===ya?e>-1?[e-1,t]:[e,t]:i===wa?e===-1?[0,t]:e===s-1?[e,t]:[e+1,t]:i===Ca?t<n-1?[e,t+1]:[e,t]:i===va?t>0?[e,t-1]:[e,t]:[e,t]}var Dd=({columnCount:i=0,containerRef:e,disableHighlightOnFocus:t,data:n,requestScroll:s,rowCount:r=0,viewportRange:o})=>{var B;let{from:l,to:a}=o,u=(0,Se.useRef)([-1,-1]),h=(0,Se.useRef)(),c=(0,Se.useRef)([-1,0]),f=(0,Se.useCallback)(([M,D])=>{var N;let H=M===-1?Rd(D):Oy(M,D);return(N=e.current)==null?void 0:N.querySelector(H)},[e]),d=M=>M==null?void 0:M.closest("th,td"),m=M=>{var D,H;if(M.tagName==="TH")return[-1,parseInt((D=M.dataset.idx)!=null?D:"-1",10)];{let N=M.closest("tr");if(N){let Q=parseInt((H=N.dataset.idx)!=null?H:"-1",10),K=Array.from(N.childNodes).indexOf(M);return[Q,K]}}return Vy},b=(0,Se.useCallback)(M=>{var D;if(e.current){let H=f(M);H?(H!==h.current&&((D=h.current)==null||D.setAttribute("tabindex",""),h.current=H,H.setAttribute("tabindex","0")),H.focus()):(0,Ed.withinRange)(M[0],o)||(h.current=void 0,s==null||s({type:"scroll-page",direction:"up"}))}},[e,f,s,o]),y=(0,Se.useCallback)((M,D,H=!1)=>{let N=[M,D];c.current=N,b(N),H&&(u.current=N)},[b]),v=(0,Se.useCallback)(()=>{var M;(M=h.current)==null||M.setAttribute("tabindex",""),h.current=void 0},[]),A=(0,Se.useCallback)(async(M,D)=>{switch(M){case Ma:s==null||s({type:"scroll-page",direction:"down"});break;case ka:s==null||s({type:"scroll-page",direction:"up"});break;case xa:s==null||s({type:"scroll-end",direction:"home"});break;case Sa:s==null||s({type:"scroll-end",direction:"end"});break}return D},[s]),C=(0,Se.useCallback)(()=>{var M;if(t!==!0&&(M=e.current)!=null&&M.contains(document.activeElement)){let D=d(document.activeElement);D&&(u.current=m(D))}},[t,e]),T=(0,Se.useCallback)(async M=>{let[D,H]=Td(M)?await A(M,c.current):Iy(M,c.current,i,r),[N,Q]=c.current;(D!==N||H!==Q)&&y(D,H,!0)},[i,A,r,y]),x=(0,Se.useCallback)(M=>{n.length>0&&Ad(M.key)&&(M.preventDefault(),M.stopPropagation(),T(M.key))},[n,T]),R=(0,Se.useCallback)(M=>{let D=M.target,H=d(D);if(H){let[N,Q]=m(H);y(N,Q)}},[y]),L=(0,Se.useMemo)(()=>({onClick:R,onFocus:C,onKeyDown:x}),[R,C,x]);(0,Se.useLayoutEffect)(()=>{let{current:M}=c,D=M[0]>=l&&M[0]<=a;h.current&&!D?v():!h.current&&D&&b(M)},[b,l,a,v]);let z=((B=e.current)==null?void 0:B.firstChild)!=null;return(0,Se.useEffect)(()=>{var M;if(z&&h.current===void 0){let D=(M=e.current)==null?void 0:M.querySelector(Rd(0));D&&(D.setAttribute("tabindex","0"),h.current=D)}},[e,z]),L};var Bi=require("react");var $n=require("react");var _n=new Map,Od=(i,e,t)=>{switch(t){case"height":return e.height;case"clientHeight":return i.clientHeight;case"clientWidth":return i.clientWidth;case"contentHeight":return e.contentHeight;case"contentWidth":return e.contentWidth;case"scrollHeight":return Math.ceil(i.scrollHeight);case"scrollWidth":return Math.ceil(i.scrollWidth);case"width":return e.width;default:return 0}},Pd=new ResizeObserver(i=>{for(let e of i){let{target:t,borderBoxSize:n,contentBoxSize:s}=e,r=_n.get(t);if(r){let[{blockSize:o,inlineSize:l}]=n,[{blockSize:a,inlineSize:u}]=s,{onResize:h,measurements:c}=r,f=!1;for(let[d,m]of Object.entries(c)){let b=Od(t,{height:o,width:l,contentHeight:a,contentWidth:u},d);b!==m&&(f=!0,c[d]=b)}f&&h&&h(c)}}});function Vd(i,e,t,n=!1){let s=(0,$n.useRef)(e),r=(0,$n.useCallback)(o=>{let{width:l,height:a}=o.getBoundingClientRect(),{clientWidth:u,clientHeight:h}=o;return s.current.reduce((c,f)=>(c[f]=Od(o,{width:l,height:a,contentHeight:h,contentWidth:u},f),c),{})},[]);(0,$n.useEffect)(()=>{let o=i.current;async function l(){_n.set(o,{measurements:{}}),await document.fonts.ready;let a=_n.get(o);if(a){let u=r(o);a.measurements=u,Pd.observe(o),n&&t(u)}else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation","font-weight:bold; color:red;")}if(o){if(_n.has(o))throw Error("useResizeObserver attemping to observe same element twice");l()}return()=>{o&&_n.has(o)&&(Pd.unobserve(o),_n.delete(o))}},[r,i]),(0,$n.useEffect)(()=>{let o=i.current,l=_n.get(o);if(l){if(s.current!==e){s.current=e;let a=r(o);l.measurements=a}l.onResize=t}},[e,r,i,t])}var Ly=["clientHeight","clientWidth"],Id=i=>Number.isFinite(i),Ta=({defaultHeight:i=0,defaultWidth:e=0,height:t,width:n})=>{let s=(0,Bi.useRef)(null),[r,o]=(0,Bi.useState)({outer:{height:t!=null?t:"100%",width:n!=null?n:"100%"}}),l=(0,Bi.useCallback)(({clientWidth:a,clientHeight:u})=>{o(h=>{let{inner:c,outer:f}=h;return Id(u)&&Id(a)&&(a!==(c==null?void 0:c.width)||u!==(c==null?void 0:c.height))?{outer:f,inner:{width:Math.floor(a)||e,height:Math.floor(u)||i}}:h})},[i,e]);return Vd(s,Ly,l,!0),{containerRef:s,outerSize:r.outer,innerSize:r.inner}};var Ld=require("@heswell/salt-lab"),me=require("@vuu-ui/vuu-utils"),Nd=require("react"),Ny=100,Bd=me.metadataKeys.count,By=({serverDataType:i})=>i===void 0,Fy=i=>{var e,t;if((0,me.isTypeDescriptor)(i.type))return(0,me.getCellRenderer)((t=(e=i.type)==null?void 0:e.renderer)==null?void 0:t.name)},Hy=(i,e,t)=>{var s;let n=e.indexOf(i.name);return n!==-1&&t[n]?t[n]:(s=i.serverDataType)!=null?s:"string"},Wy=["int","long","double"],Fd=i=>i===void 0?void 0:Wy.includes(i)?"right":"left",_y=(i,e)=>{switch(e.type){case"init":return console.log("modeel init"),Wd(e);case"moveColumn":return Uy(i,e);case"resizeColumn":return Gy(i,e);case"setTypes":return qy(i,e);case"hideColumn":return Ky(i,e);case"pinColumn":return jy(i,e);case"updateColumnProp":return Qr(i,e);case"tableConfig":return _d(i,e);default:return console.log(`unhandled action ${e.type}`),i}},Hd=(i,e)=>{let[t,n]=(0,Nd.useReducer)(_y,{tableConfig:i,dataSourceConfig:e},Wd);return{columns:t.columns,dispatchColumnAction:n,headings:t.headings}};function Wd({dataSourceConfig:i,tableConfig:e}){let t=e.columns.map(zy(e)),n=t.some(me.isPinned)?(0,me.sortPinnedColumns)(t):t,s={columns:n,headings:(0,me.getTableHeadings)(n)};return i?_d(s,i):s}var $y=(i,e)=>e==="uppercase"?i.toUpperCase():e==="capitalize"?i[0].toUpperCase()+i.slice(1).toLowerCase():i,zy=({columnDefaultWidth:i=Ny,columnFormatHeader:e})=>(t,n)=>{let{align:s=Fd(t.serverDataType),name:r,label:o=r,width:l=i,...a}=t;return{...a,align:s,CellRenderer:Fy(t),label:$y(o,e),key:n+Bd,name:r,originalIdx:n,valueFormatter:(0,me.getValueFormatter)(t),width:l}};function Uy(i,{column:e,moveBy:t,moveTo:n}){let{columns:s}=i;if(typeof t=="number"){let r=s.indexOf(e),o=s.slice(),[l]=o.splice(r,1);return o.splice(r+t,0,l),{...i,columns:o}}else if(typeof n=="number"){let r=s.indexOf(e);return{...i,columns:(0,Ld.moveItem)(s,r,n)}}return i}function Ky(i,{column:e}){return Qr(i,{type:"updateColumnProp",column:e,hidden:!0})}function Gy(i,{column:e,phase:t,width:n}){let s="updateColumnProp",r=t!=="end";switch(t){case"begin":case"end":return Qr(i,{type:s,column:e,resizing:r});case"resize":return Qr(i,{type:s,column:e,width:n});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${t}`)}}function qy(i,{columnNames:e,serverDataTypes:t}){let{columns:n}=i;if(n.some(By)){let s=n.map(r=>{var l;let o=Hy(r,e,t);return{...r,align:(l=r.align)!=null?l:Fd(o),serverDataType:o}});return console.log(`setTypes ${JSON.stringify(s,null,2)}`),{...i,columns:s}}else return i}function jy(i,e){let{columns:t}=i,{column:n,pin:s}=e,r=t.find(o=>o.name===n.name);return r?(t=Fi(t,{...r,pin:s}),t=(0,me.sortPinnedColumns)(t),{...i,columns:t}):i}function Qr(i,e){let{columns:t}=i,{align:n,column:s,hidden:r,label:o,resizing:l,width:a}=e,u=t.find(h=>h.name===s.name);return u&&((n==="left"||n==="right")&&(t=Fi(t,{...u,align:n})),typeof o=="string"&&(t=Fi(t,{...u,label:o})),typeof l=="boolean"&&(t=Fi(t,{...u,resizing:l})),typeof r=="boolean"&&(t=Fi(t,{...u,hidden:r})),typeof a=="number"&&(t=Fi(t,{...u,width:a}))),{...i,columns:t}}function _d(i,{columns:e,filter:t,groupBy:n,sort:s}){let r=e&&e.length>0,o=n!==void 0,l=typeof(t==null?void 0:t.filter)=="string",a=s&&s.sortDefs.length>0,u=i;return r&&(u={...i,columns:e.map((h,c)=>{let f=(0,me.getColumnName)(h),d=c+Bd,m=u.columns.find(b=>b.name===f);if(m)return m.key===d?m:{...m,key:d};throw Error(`useTableModel column ${h} not found`)})}),o&&(u={...i,columns:(0,me.applyGroupByToColumns)(u.columns,n)}),a&&(u={...i,columns:(0,me.applySortToColumns)(u.columns,s)}),l&&(u={...i,columns:(0,me.applyFilterToColumns)(u.columns,t)}),u}function Fi(i,e){return i.map(t=>t.name===e.name?e:t)}var lt=require("react"),$d=i=>{let{scrollLeft:e,scrollTop:t}=i,{clientHeight:n,clientWidth:s,scrollHeight:r,scrollWidth:o}=i,l=e/(o-s),a=t/(r-n);return[l,a,e,t]},Qy=i=>{let{clientHeight:e,clientWidth:t,scrollHeight:n,scrollWidth:s}=i;return[s-t,n-e]},zd=({onRangeChange:i,rowHeight:e,viewport:t})=>{let n=(0,lt.useRef)(null),s=(0,lt.useRef)(null),r=(0,lt.useRef)(null),o=(0,lt.useRef)(!1),l=(0,lt.useRef)(-1),{rowCount:a,maxScrollContainerScrollHorizontal:u,maxScrollContainerScrollVertical:h}=t,c=(0,lt.useCallback)((y,v)=>{let{current:A}=r;A&&(A.scrollLeft=y,A.scrollTop=v)},[r]),f=(0,lt.useCallback)(()=>{let{current:y}=r;if(y){let{scrollTop:v}=y,A=Math.floor(v/e);A!==l.current&&(l.current=A,i(A,A+a))}},[i,e,a]),d=(0,lt.useCallback)(()=>{let{current:y}=s,{current:v}=n;if(y&&v){let[A,C,T,x]=$d(y);o.current=!0,v.scrollLeft=Math.round(A*u),v.scrollTop=Math.round(C*h),c(T,x)}},[u,h,s,n,c]),m=(0,lt.useCallback)(()=>{let{current:y}=s,{current:v}=n,{current:A}=o;if(A)o.current=!1;else if(y&&v){let[C,T]=$d(v),[x,R]=Qy(y),L=Math.round(C*x),z=Math.round(T*R);y.scrollLeft=L,y.scrollTop=z,c(L,z)}},[s,n,c]),b=(0,lt.useCallback)(y=>{let{current:v}=n;if(v){if(o.current=!1,y.type==="scroll-page"){let{clientHeight:A,scrollTop:C}=v,{direction:T}=y,x=T==="down"?A:-A;v.scrollTop=Math.min(Math.max(0,C+x),t.maxScrollContainerScrollVertical)}else if(y.type==="scroll-end"){let{direction:A}=y,C=A==="end"?t.maxScrollContainerScrollVertical:0;v.scrollTop=C}}},[t.maxScrollContainerScrollVertical]);return{onScrollbarContainerScroll:m,onContentContainerScroll:d,onTableContainerScroll:f,requestScroll:b,contentContainerRef:s,scrollbarContainerRef:n,tableContainerRef:r}};var Aa=require("react"),Jy={fillerHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,scrollContentHeight:0,scrollbarSize:0,scrollContentWidth:0,totalHeaderHeight:0},Xy=i=>{let e=0,t=0,n=0;for(let s of i){let{hidden:r,pin:o,width:l}=s,a=r?0:l;o==="left"?e+=a:o==="right"?t+=a:n+=a}return{pinnedWidthLeft:e,pinnedWidthRight:t,unpinnedWidth:n}},Ud=({columns:i,headerHeight:e,headings:t,rowCount:n,rowHeight:s,size:r})=>{let{pinnedWidthLeft:o,pinnedWidthRight:l,unpinnedWidth:a}=(0,Aa.useMemo)(()=>Xy(i),[i]);return(0,Aa.useMemo)(()=>{var h;if(r){let c=t.length,f=15,d=n*s,m=o+a+l,b=d+e-(((h=r==null?void 0:r.height)!=null?h:0)-e-f),y=m-r.width+o,v=(r.height-e)/s,A=Number.isInteger(v)?v+1:Math.ceil(v);return{fillerHeight:(n-A)*s,maxScrollContainerScrollHorizontal:y,maxScrollContainerScrollVertical:b,pinnedWidthLeft:o,pinnedWidthRight:l,rowCount:A,scrollContentHeight:e+d+f,scrollbarSize:f,scrollContentWidth:m,totalHeaderHeight:e*(1+c)}}else return Jy},[e,t.length,o,l,n,s,r,a])};var Kd=require("@vuu-ui/vuu-utils"),vs=require("react"),{IDX:Yy,SELECTED:Zy}=Kd.metadataKeys,Gd=({selectionModel:i,setSelected:e})=>{let t=i==="single",n=i==="extended"||i==="checkbox",s=(0,vs.useRef)(-1),r=(0,vs.useRef)([]);return(0,vs.useCallback)((l,a,u,h)=>{let{[Yy]:c,[Zy]:f}=a,{current:d}=s,{current:m}=r,y=t||n&&!h&&(!u||d===-1),v;if(y&&f)v=[];else if(y)v=[c];else if(!u)f?v=m==null?void 0:m.filter(A=>A!==c):v=m==null?void 0:m.concat(c);else if(n){let[A,C]=c>d?[d,c]:[c,d];v=m==null?void 0:m.slice();for(let T=A;T<=C;T++)m!=null&&m.includes(T)||v.push(T)}r.current=v!=null?v:[],s.current=c,e&&e(v)},[n,e,t])};var qd=require("@heswell/salt-lab"),zt=require("react"),jd=({onDrop:i,tableContainerRef:e,tableLayout:t})=>{let[n,s]=(0,zt.useState)(t),r=(0,zt.useRef)(),o=(0,zt.useCallback)(()=>{console.log("handleDropSettle"),r.current=void 0,s("row")},[]),{draggable:l,draggedItemIndex:a,onMouseDown:u}=(0,qd.useDragDrop)({allowDragDrop:!0,draggableClassName:"table-column",orientation:"horizontal",containerRef:e,itemQuery:".vuuDataTable-table",onDrop:i,onDropSettle:o}),h=(0,zt.useCallback)(c=>{let{clientX:f,clientY:d}=c;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let b=c.target.closest(".vuuTable-headerCell"),{dataset:{idx:y="-1"}}=b;r.current={clientX:f,clientY:d,idx:y},s("column")},[]);return(0,zt.useLayoutEffect)(()=>{var c;if(n==="column"&&r.current&&!l){let{clientX:f,clientY:d,idx:m}=r.current,b=(c=e.current)==null?void 0:c.querySelector(`.vuuDataTable-table[data-idx="${m}"]`);if(b){let y={persist:()=>{},nativeEvent:{clientX:f,clientY:d,target:b}};u==null||u(y)}}},[l,u,e,n]),{draggable:l,draggedItemIndex:a,tableLayout:n,onHeaderCellDragStart:n==="row"?h:void 0}};var{KEY:Qd,IS_EXPANDED:ew}=Hi.metadataKeys,Jd=({config:i,dataSource:e,headerHeight:t,onConfigChange:n,onFeatureEnabled:s,onFeatureInvocation:r,renderBufferSize:o=0,rowHeight:l,selectionModel:a,tableLayout:u,...h})=>{var at,pn;let[c,f]=(0,we.useState)(0),d=(0,we.useRef)(!1),m=(0,we.useRef)();if(m.current=e,e===void 0)throw Error("no data source provided to DataTable");let b=Ta(h),y=(0,we.useCallback)(Y=>{f(Y)},[]),{columns:v,dispatchColumnAction:A,headings:C}=Hd(i,e.config),T=(0,we.useCallback)(Y=>{d.current=!0,A(Y)},[A]),x=bd({dataSource:e,onPersistentColumnOperation:T}),R=Ud({columns:v,headerHeight:t,headings:C,rowCount:c,rowHeight:l,size:b.innerSize}),L=(0,we.useCallback)(Y=>{if(Y.tableMeta){let{columns:be,dataTypes:Ke}=Y.tableMeta;d.current=!0,A({type:"setTypes",columnNames:be,serverDataTypes:Ke})}},[A]),z=(0,we.useCallback)(Y=>{let{type:be}=Y;switch(be){case"groupBy":case"filter":case"sort":case"columns":{let Ke=Y[be];return A({type:"tableConfig",[be]:Ke})}}},[A]),B=(0,we.useCallback)(Y=>{e.select(Y)},[e]),M=Gd({setSelected:B,selectionModel:a}),{data:D,range:H,setRange:N}=kd({dataSource:e,onConfigChange:z,onFeatureEnabled:s,onFeatureInvocation:r,onSubscribed:L,onSizeChange:y,renderBufferSize:o,viewportRowCount:R.rowCount}),Q=(0,we.useCallback)((Y,be)=>{N({from:Y,to:be})},[N]),K=(0,we.useCallback)((Y,be=!1,Ke)=>{e&&(e.sort=(0,Hi.applySort)(e.sort,Y,be,Ke))},[e]),oe=(0,we.useCallback)((Y,be,Ke)=>{let mn=v.find(Un=>Un.name===be);if(mn)Y==="end"&&(d.current=!0),A({type:"resizeColumn",phase:Y,column:mn,width:Ke});else throw Error(`useDataTable.handleColumnResize, column ${be} not found`)},[v,A]),ke=(0,we.useCallback)(Y=>{e&&(Y[ew]?e.closeTreeNode(Y[Qd]):e.openTreeNode(Y[Qd]))},[e]),te=(0,we.useCallback)(Y=>{e&&e.groupBy.includes(Y.name)&&(e.groupBy=e.groupBy.filter(be=>be!==Y.name))},[e]),{requestScroll:ve,...ge}=zd({onRangeChange:Q,rowHeight:l,viewport:R,viewportHeight:((pn=(at=b.innerSize)==null?void 0:at.height)!=null?pn:0)-t}),Le=Dd({columnCount:v.length,containerRef:b.containerRef,data:D,requestScroll:ve,rowCount:e==null?void 0:e.size,viewportRange:H}),Ne=(0,we.useCallback)((Y,be)=>{let Ke=e.columns[Y],mn=(0,Hi.moveItem)(e.columns,Ke,be);mn!==e.columns&&(e.columns=mn,A({type:"tableConfig",columns:mn}))},[e,A]),Ye=jd({onDrop:Ne,tableContainerRef:ge.tableContainerRef,tableLayout:u});return(0,we.useEffect)(()=>{m.current&&(d.current=!0,A({type:"init",tableConfig:i,dataSourceConfig:m.current.config}))},[i,A]),(0,we.useMemo)(()=>{console.log("4) useDataTable change detected to config ...",{config:i}),d.current?(console.log("%c expected so call onConfigChange","color: red; font-weight: bold;",{columns:v,config:i}),n==null||n({...i,columns:v}),d.current=!1):console.log(" ...columns changes but we were not expecting it so ignore")},[v,i,n]),{containerMeasurements:b,containerProps:Le,columns:v,data:D,dispatchColumnAction:A,handleContextMenuAction:x,headings:C,onColumnResize:oe,onRemoveColumnFromGroupBy:te,onRowClick:M,onSort:K,onToggleGroup:ke,scrollProps:ge,rowCount:c,viewportMeasurements:R,...Ye}};var bt=require("react/jsx-runtime"),zn="vuuDataTable",tw=({allowConfigEditing:i=!1,className:e,config:t,dataSource:n,headerHeight:s=25,height:r,id:o,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,onShowConfigEditor:h,renderBufferSize:c=0,rowHeight:f=20,selectionModel:d="extended",style:m,tableLayout:b="row",width:y,...v})=>{let A=(0,Jr.useIdMemo)(o),{columns:C,containerMeasurements:{containerRef:T,innerSize:x,outerSize:R},containerProps:L,dispatchColumnAction:z,draggable:B,draggedItemIndex:M,handleContextMenuAction:D,rowCount:H,scrollProps:N,tableLayout:Q,viewportMeasurements:K,...oe}=Jd({config:t,dataSource:n,renderBufferSize:c,headerHeight:s,height:r,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,rowHeight:f,selectionModel:d,tableLayout:b,width:y}),ke={...R,"--content-height":`${K.scrollContentHeight}px`,"--content-width":`${K.scrollContentWidth}px`,"--filler-height":`${K.fillerHeight}px`,"--pinned-width-left":`${K.pinnedWidthLeft}px`,"--pinned-width-right":`${K.pinnedWidthRight}px`,"--header-height":`${s}px`,"--row-height":`${f}px`,"--scrollbar-size":`${K.scrollbarSize}px`,"--table-height":`${x==null?void 0:x.height}px`,"--table-width":`${x==null?void 0:x.width}px`,"--total-header-height":`${K==null?void 0:K.totalHeaderHeight}px`},te={left:K.pinnedWidthLeft-1,top:(K==null?void 0:K.totalHeaderHeight)-1},ve=Q==="column"?Ou:Cd,ge=Jn(),Le=(0,Xd.useCallback)(Ne=>{ge(Ne,"grid",{selectedRowCount:n.selectedRowsCount,viewport:n==null?void 0:n.viewport})},[n.selectedRowsCount,n==null?void 0:n.viewport,ge]);return(0,bt.jsx)(ou,{menuActionHandler:D,menuBuilder:Iu(n),children:(0,bt.jsxs)("div",{...L,className:zn,id:A,ref:T,style:ke,tabIndex:-1,children:[x?(0,bt.jsx)("div",{className:`${zn}-scrollbarContainer`,onScroll:N.onScrollbarContainerScroll,ref:N.scrollbarContainerRef,style:te,children:(0,bt.jsx)("div",{className:`${zn}-scrollContent`})}):null,x?(0,bt.jsxs)("div",{className:`${zn}-contentContainer`,onScroll:N.onContentContainerScroll,ref:N.contentContainerRef,...v,children:[(0,bt.jsx)("div",{className:`${zn}-scrollContent`}),(0,bt.jsx)("div",{className:`${zn}-tableContainer`,onScroll:N.onTableContainerScroll,ref:N.tableContainerRef,children:(0,bt.jsx)(ve,{...oe,columns:C.filter((Ne,Ye)=>Ye!==M),headerHeight:s,onContextMenu:Le,rowHeight:f})}),B]}):null,i&&x?(0,bt.jsx)(Jr.Button,{className:`${zn}-settings`,"data-icon":"settings",onClick:h,variant:"secondary"}):null]})})};
2
17
  //# sourceMappingURL=index.js.map