@vuu-ui/vuu-datatable 0.6.13 → 0.8.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/cjs/index.js +1 -16
  2. package/cjs/index.js.map +7 -0
  3. package/esm/index.js +2 -0
  4. package/esm/index.js.map +7 -0
  5. package/index.css +1 -1
  6. package/index.css.map +3 -3
  7. package/package.json +14 -8
  8. package/types/filter-table/FilterTable.d.ts +10 -0
  9. package/types/filter-table/index.d.ts +1 -0
  10. package/types/index.d.ts +2 -3
  11. package/types/json-table/JsonTable.d.ts +9 -0
  12. package/types/json-table/index.d.ts +1 -0
  13. package/types/ColumnBasedTable.d.ts +0 -3
  14. package/types/ColumnResizer.d.ts +0 -8
  15. package/types/DataTable.d.ts +0 -4
  16. package/types/DragVisualizer.d.ts +0 -8
  17. package/types/KeySet.d.ts +0 -12
  18. package/types/RowBasedTable.d.ts +0 -3
  19. package/types/SortIndicator.d.ts +0 -7
  20. package/types/TableCell.d.ts +0 -9
  21. package/types/TableGroupCell.d.ts +0 -7
  22. package/types/TableGroupHeaderCell.d.ts +0 -13
  23. package/types/TableHeaderCell.d.ts +0 -11
  24. package/types/TableRow.d.ts +0 -14
  25. package/types/context-menu/buildContextMenuDescriptors.d.ts +0 -4
  26. package/types/context-menu/index.d.ts +0 -2
  27. package/types/context-menu/useContextMenu.d.ts +0 -16
  28. package/types/dataTableTypes.d.ts +0 -67
  29. package/types/filter-indicator.d.ts +0 -13
  30. package/types/keyUtils.d.ts +0 -19
  31. package/types/useDataSource.d.ts +0 -40
  32. package/types/useDataTable.d.ts +0 -63
  33. package/types/useDraggableColumn.d.ts +0 -12
  34. package/types/useKeyboardNavigation.d.ts +0 -22
  35. package/types/useMeasuredContainer.d.ts +0 -25
  36. package/types/useMeasuredSize.d.ts +0 -26
  37. package/types/useResizeObserver.d.ts +0 -15
  38. package/types/useSelection.d.ts +0 -7
  39. package/types/useTableColumnResize.d.ts +0 -17
  40. package/types/useTableModel.d.ts +0 -66
  41. package/types/useTableScroll.d.ts +0 -31
  42. package/types/useTableViewport.d.ts +0 -39
package/cjs/index.js CHANGED
@@ -1,17 +1,2 @@
1
- "use strict";var Op=Object.create;var Hr=Object.defineProperty;var Ip=Object.getOwnPropertyDescriptor;var Lp=Object.getOwnPropertyNames;var Vp=Object.getPrototypeOf,Np=Object.prototype.hasOwnProperty;var Bp=(i,e)=>{for(var t in e)Hr(i,t,{get:e[t],enumerable:!0})},iu=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Lp(e))!Np.call(i,r)&&r!==t&&Hr(i,r,{get:()=>e[r],enumerable:!(n=Ip(e,r))||n.enumerable});return i};var Me=(i,e,t)=>(t=i!=null?Op(Vp(i)):{},iu(e||!i||!i.__esModule?Hr(t,"default",{value:i,enumerable:!0}):t,i)),Fp=i=>iu(Hr({},"__esModule",{value:!0}),i);var ru=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var z=(i,e,t)=>(ru(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)},U=(i,e,t,n)=>(ru(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);var kw={};Bp(kw,{DataTable:()=>xw,useMeasuredContainer:()=>Xa});module.exports=Fp(kw);var bo=require("@heswell/salt-lab"),zp=require("@salt-ds/core"),Up=Me(require("classnames")),yo=require("react");var Ji=require("react"),uu=Me(require("react-dom"));var su=Me(require("react-dom")),ou=require("@salt-ds/core"),au=require("react/jsx-runtime"),Hp=1,Wp=(i=0,e=0,t=window)=>{let n=t.document.createElement("div");return n.className="vuuPopup "+Hp++,n.style.cssText=`left:${i}px; top:${e}px;`,t.document.body.appendChild(n),n},_p=(i,e)=>Wp(i,e),Wr=(i,e,t,n,r)=>{e.style.cssText=`left:${t}px; top:${n}px;position: absolute;`,su.render((0,au.jsx)(ou.SaltProvider,{applyClassesTo:"child",children:i}),e,r)},lu=_p;var go=function({children:e,x:t=0,y:n=0,onRender:r}){let s=(0,Ji.useMemo)(()=>lu(),[]);return(0,Ji.useLayoutEffect)(()=>{Wr(e,s,t,n,r)},[e,r,s,t,n]),(0,Ji.useLayoutEffect)(()=>()=>{var o;s&&(uu.unmountComponentAtNode(s),s.classList.contains("vuuPopup")&&((o=s.parentElement)==null||o.removeChild(s)))},[s]),null};var hu=require("react/jsx-runtime");var Au=require("@salt-ds/core"),An=require("react");var Xt=Me(require("react")),vo=Me(require("classnames")),vu=require("@salt-ds/core");var qe=require("react");var cu=i=>i.closest("[data-root='true']")!==null,fu=(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 Kp(i,...e){let t=new Set(i);for(let n of e)for(let r of n)t.add(r);return t}var $p="Enter";var Gp="Delete",qp=new Set([$p,Gp]),jp=new Set(["Tab"]),Qp=new Set(["ArrowRight","ArrowLeft"]),du=new Set(["Home","End","ArrowDown","ArrowUp"]),pu=new Set(["Home","End","ArrowRight","ArrowLeft"]),Jp=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),Kw=Kp(qp,pu,du,Qp,Jp,jp);var mu=({key:i},e="vertical")=>(e==="vertical"?du:pu).has(i);var gu=({autoHighlightFirstItem:i=!1,count:e,highlightedIndex:t,onActivate:n,onHighlight:r,onCloseMenu:s,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,r==null||r(C),a({})},[r]),c=(0,qe.useCallback)(C=>{C!==l.current&&(u||h(C))},[u,h]),f=(0,qe.useRef)(!0),p=(0,qe.useRef)(!1),m=C=>p.current=C,b=u?t:l.current,w=(0,qe.useCallback)(C=>{let k=Xp(e,C.key,l.current);k!==l.current&&c(k)},[e,c]),v=(0,qe.useCallback)(C=>{mu(C)?(C.preventDefault(),C.stopPropagation(),f.current=!0,w(C)):(C.key==="ArrowRight"||C.key==="Enter")&&fu(C.target,b)?o(b):C.key==="ArrowLeft"&&!cu(C.target)?s(b):C.key==="Enter"&&n&&n(b)},[b,w,n,s,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,w,n,s,o,h]);return{focusVisible:f.current?b:-1,controlledHighlighting:u,highlightedIndex:b,setHighlightedIndex:c,listProps:A,setIgnoreFocus:m}};function Xp(i,e,t){return e==="ArrowUp"?t>0?t-1:t:t===null?0:t===i-1?t:t+1}var Rn=Me(require("react"));var wo=i=>i.type===_r||!!i.props["data-group"],bu=i=>{let e=(0,Rn.useCallback)(()=>{let r=(o,l="root",a={},u={})=>{let h=a[l]=[],c=0,f=!1;return Rn.default.Children.forEach(o,p=>{if(p.type===yu)f=!0;else{let m=wo(p),b=l==="root"?`${c}`:`${l}.${c}`,{props:{action:w,options:v}}=p,{childWithId:A,grandChildren:C}=s(p,b,m,f);h.push(A),C?r(C,b,a,u):u[b]={action:w,options:v},c+=1,f=!1}}),[a,u]},s=(o,l,a,u=!1)=>{let{props:{children:h}}=o;return{childWithId:Rn.default.cloneElement(o,{hasSeparator:u,id:`${l}`,key:l,children:a?void 0:h}),grandChildren:a?h:void 0}};return r(i)},[i]),[t,n]=(0,Rn.useMemo)(()=>e(),[e]);return[t,n]};var ni=require("react/jsx-runtime"),wu="vuuMenuList",yu=()=>(0,ni.jsx)("li",{className:"vuuMenuItem-divider"}),_r=()=>null,Co=({children:i,idx:e,...t})=>(0,ni.jsx)("div",{...t,children:i}),Yp=i=>i.props["data-icon"],Cu=({activatedByKeyboard:i,childMenuShowing:e=-1,children:t,className:n,highlightedIdx:r,id:s,isRoot:o,listItemProps:l,menuId:a,onHighlightMenuItem:u,onActivate:h,onCloseMenu:c,onOpenMenu:f,...p})=>{let m=(0,vu.useIdMemo)(s),b=(0,Xt.useRef)(null),w=(0,Xt.useMemo)(()=>new Map,[]),v=F=>{var P;let R=(P=b.current)==null?void 0:P.querySelector(`:scope > [data-idx='${F}']`);R!=null&&R.id&&(f==null||f(R.id))},A=F=>{var P;let R=(P=b.current)==null?void 0:P.querySelector(`:scope > [data-idx='${F}']`);R!=null&&R.id&&(h==null||h(R.id))},{focusVisible:C,highlightedIndex:k,listProps:M}=gu({count:Xt.default.Children.count(t),highlightedIndex:r,onActivate:A,onHighlight:u,onOpenMenu:v,onCloseMenu:c}),x=e==-1?C:-1;return(0,Xt.useLayoutEffect)(()=>{var F;e===-1&&i&&((F=b.current)==null||F.focus())},[i,e]),(0,ni.jsx)("div",{...p,...M,"aria-activedescendant":(()=>k===void 0||k===-1?void 0:w.get(k))(),className:(0,vo.default)(wu,n,{[`${wu}-childMenuShowing`]:e!==-1}),"data-root":o||void 0,id:`${m}-${a}`,ref:b,role:"menu",tabIndex:0,children:_()});function _(){let F={...l,role:"menuitem"},R=(N,j,$)=>j?[(0,ni.jsx)("span",{className:"vuuIconContainer","data-icon":$},"icon")].concat(N):N;function P(N,j,$,ee){var Mn;let{children:Oe,className:ne,"data-icon":Y,id:ke,hasSeparator:Fe,label:Ze,...ht}=j.props,vt=wo(j),kn=vt&&e===$,qi=kn?`${m}-${ke}`:void 0;N.push((0,ni.jsx)(Co,{...ht,...F,...Zp(`${m}-${a}`,ke,$,(Mn=j.key)!=null?Mn:ke,k,x,ne,Fe),"aria-controls":qi,"aria-haspopup":vt||void 0,"aria-expanded":kn||void 0,children:R(vt?Ze:Oe,ee,Y)}))}let H=[];if(t.length>0){let N=t.some(Yp);t.forEach((j,$)=>{P(H,j,$,N)})}return H}},Zp=(i,e,t,n,r,s,o,l)=>({id:`${i}-${e}`,key:n!=null?n:t,"data-idx":t,"data-highlighted":t===r||void 0,className:(0,vo.default)("vuuMenuItem",o,{"vuuMenuItem-separator":l,focusVisible:s===t})});Cu.displayName="MenuList";var Su=Cu;var Te=require("react");function xu(i){if(i){let e=i.dataset.idx;if(e)return parseInt(e,10);if(i.ariaPosInSet)return parseInt(i.ariaPosInSet,10)-1}}var So=i=>i==null?void 0:i.closest("[data-idx],[aria-posinset]");var ku=(i,e,t)=>i.map((n,r)=>r===i.length-1?{...n,[t]:n[t]-e}:n),em=(i,e)=>ku(i,e,"left"),tm=(i,e)=>ku(i,e,"top"),nm=(i,e)=>{let[t,n]=e.slice(-2),r=document.getElementById(`${i}-${n.id}`);if(r===null)throw Error(`useCascade.flipSides element with id ${n.id} not found`);let{width:s}=r.getBoundingClientRect();return e.map(o=>o===n?{...o,left:t.left-(s-2)}:o)},im=(i,e)=>{let[{left:t,top:n}]=e.slice(-1),{offsetWidth:r,offsetTop:s}=i;return{left:t+r,top:s+n}},Xi=i=>{let e=i.lastIndexOf("-");return e===-1?i:i.slice(e+1)},zr=i=>{let e=Xi(i),t=e.lastIndexOf(".");return t>-1?e.slice(0,t):"root"},rm=i=>{let e=0,t=i.indexOf(".",0);for(;t!==-1;)e+=1,t=i.indexOf(".",t+1);return e},sm=i=>({menuId:zr(i.id),itemId:Xi(i.id),isGroup:i.ariaHasPopup==="true",isOpen:i.ariaExpanded==="true",level:rm(i.id)}),Mu=({id:i,onActivate:e,onMouseEnterItem:t,position:{x:n,y:r}})=>{let[,s]=(0,Te.useState)({}),o=(0,Te.useRef)([{id:"root",left:n,top:r}]),l=(0,Te.useCallback)(C=>{o.current=C,s({})},[]),a=(0,Te.useRef)(),u=(0,Te.useRef)(),h=(0,Te.useRef)({root:"no-popup"}),c=(0,Te.useRef)(0),f=(0,Te.useCallback)((C="root",k=null,M=null)=>{if(C==="root"&&k===null)l([{id:"root",left:n,top:r}]);else{h.current[C]="popup-open";let I=(M?M.ownerDocument:document).getElementById(`${i}-${C}-${k}`),{left:_,top:F}=im(I,o.current);l(o.current.concat({id:k,left:_,top:F}))}},[i,n,r,l]),p=(0,Te.useCallback)(C=>{l(C==="root"?[]:o.current.slice(0,-1))},[l]),m=(0,Te.useCallback)((C,k)=>{let M=o.current.slice(),{id:x}=M[M.length-1];for(;M.length>1&&!k.startsWith(x);){let I=zr(x);M.pop(),h.current[x]="no-popup",h.current[I]="no-popup",{id:x}=M[M.length-1]}M.length<o.current.length&&l(M)},[l]),b=(0,Te.useCallback)((C,k,M)=>{a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{console.log(`scheduleOpen timed out opening ${k}`),m(C,k),h.current[C]="popup-open",h.current[k]="no-popup",f(C,k,M)},400)},[m,f]),w=(0,Te.useCallback)((C,k,M)=>{console.log(`scheduleClose openMenuId ${C} menuId ${k} itemId ${M}`),h.current[C]="pending-close",u.current=window.setTimeout(()=>{m(k,M)},400)},[m]),v=(0,Te.useCallback)(()=>{let{current:C}=o,[k]=C.slice(-1),M=document.getElementById(`${i}-${k.id}`);if(M){let{right:x,bottom:I}=M.getBoundingClientRect(),{clientHeight:_,clientWidth:F}=document.body;if(x>F){let R=C.length>1?nm(i,C):em(C,x-F);l(R)}else if(I>_){let R=tm(C,I-_);l(R)}}},[i,l]),A=(0,Te.useMemo)(()=>({onMouseEnter:C=>{let k=So(C.target),{menuId:M,itemId:x,isGroup:I,isOpen:_,level:F}=sm(k),R=c.current===F,{current:{[M]:P}}=h;if(c.current=F,P==="no-popup"&&I)h.current[M]="popup-pending",b(M,x,k);else if(P==="popup-pending"&&!I)h.current[M]="no-popup",clearTimeout(a.current),a.current=void 0;else if(P==="popup-pending"&&I)clearTimeout(a.current),b(M,x,k);else if(P==="popup-open"){let[{id:H},{id:N}]=o.current.slice(-2);H===M&&h.current[N]!=="pending-close"&&R?(w(N,M,x),I&&!_&&b(M,x,k)):H===M&&I&&x!==N&&h.current[N]==="pending-close"?b(M,x,k):I?(m(M,x),b(M,x,k)):h.current[N]==="pending-close"&&R||m(M,x)}P==="pending-close"&&(a.current&&(clearTimeout(a.current),a.current=void 0),clearTimeout(u.current),u.current=void 0,h.current[M]="popup-open"),t(C,x)},onClick:C=>{let k=C.target,M=So(k),x=xu(M);console.log(`list item click [${x}] hasPopup ${M.ariaHasPopup}`),M.ariaHasPopup==="true"?M.ariaExpanded!=="true"&&f(x):e(Xi(M.id))}}),[m,e,t,f,w,b]);return{closeMenu:p,handleRender:v,listItemProps:A,openMenu:f,openMenus:o.current}};var Tu=require("react"),Ru=({containerClassName:i,isOpen:e,onClose:t})=>{(0,Tu.useEffect)(()=>{let n;return e&&(n=r=>{r.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 Yi=require("react/jsx-runtime"),Du=require("react"),om=()=>{},xo=({activatedByKeyboard:i,children:e,className:t,id:n,onClose:r=()=>{},position:s={x:0,y:0},style:o,...l})=>{let a=(0,Au.useIdMemo)(n),u=(0,An.useRef)(om),[h,c]=bu(e),f=(0,An.useRef)(i),p=(0,An.useCallback)(()=>{f.current=!1},[]),m=(0,An.useCallback)(R=>{let{action:P,options:H}=c[R];u.current("root"),r(P,H)},[c,r]),{closeMenu:b,listItemProps:w,openMenu:v,openMenus:A,handleRender:C}=Mu({id:a,onActivate:m,onMouseEnterItem:p,position:s});u.current=b,console.log({openMenus:A});let k=(0,An.useCallback)(()=>{b(),r()},[b,r]);Ru({containerClassName:"vuuMenuList",onClose:k,isOpen:A.length>0});let M=R=>{let P=Xi(R),H=zr(P);f.current=!0,v(H,P)},x=()=>{f.current=!0,b()},I=()=>{},_=A.length-1,F=R=>{if(R>=_)return-1;{let{id:P}=A[R+1],H=P.lastIndexOf(".");return parseInt(H===-1?P:P.slice(-H),10)}};return(0,Yi.jsx)(Yi.Fragment,{children:A.map(({id:R,left:P,top:H},N)=>{let j=F(N);return(0,Yi.jsx)(go,{x:P,y:H,onRender:C,children:(0,Du.createElement)(Su,{...l,activatedByKeyboard:f.current,childMenuShowing:j,className:t,id:a,menuId:R,isRoot:N===0,key:N,listItemProps:w,onActivate:m,onHighlightMenuItem:I,onCloseMenu:x,onOpenMenu:M,style:o},h[R])},N)})})};xo.displayName="ContextMenu";var ii=require("react"),Ur=require("react/jsx-runtime"),Kr=(0,ii.createContext)(null),ko=i=>i!==void 0&&"children"in i,lm=({children:i,context:e,menuActionHandler:t,menuBuilder:n})=>{let r=(0,ii.useMemo)(()=>e!=null&&e.menuBuilders&&n?e.menuBuilders.concat(n):n?[n]:(e==null?void 0:e.menuBuilders)||[],[e,n]),s=(0,ii.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,Ur.jsx)(Kr.Provider,{value:{menuActionHandler:s,menuBuilders:r},children:i})},Eu=({children:i,label:e,menuActionHandler:t,menuBuilder:n})=>(0,Ur.jsx)(Kr.Consumer,{children:r=>(0,Ur.jsx)(lm,{context:r,label:e,menuActionHandler:t,menuBuilder:n,children:i})});var Zi=require("react");var Pu=Me(require("classnames")),ri=Me(require("react")),$r=Me(require("react-dom"));var Mo=!1,ct=[];function Ou(i){if(i.key==="Esc"){if(ct.length)Lu();else if(Mo){let e=document.body.querySelector(".vuuDialog");e&&$r.default.unmountComponentAtNode(e)}}}function Iu(i){if(ct.length){let e=document.body.querySelectorAll(".vuuPopup");for(let t=0;t<e.length;t++)if(e[t].contains(i.target))return;Lu()}}function Lu(){if(ct.length){let i=document.body.querySelectorAll(".vuuPopup");for(let e=0;e<i.length;e++)$r.default.unmountComponentAtNode(i[e]);Vu("*")}}function am(i){ct.indexOf(i)===-1&&(ct.push(i),Mo===!1&&(window.addEventListener("keydown",Ou,!0),window.addEventListener("click",Iu,!0)))}function Vu(i){if(ct.length){if(i==="*")ct.length=0;else{let e=ct.indexOf(i);e!==-1&&ct.splice(e,1)}ct.length===0&&Mo===!1&&(window.removeEventListener("keydown",Ou,!0),window.removeEventListener("click",Iu,!0))}}var um=({children:i,position:e,style:t})=>{let n=(0,Pu.default)("hwPopup","hwPopupContainer",e);return(0,ri.createElement)("div",{className:n,style:t},i)},hm=1,Dn=class{static showPopup({name:e="anon",group:t="all",position:n="",left:r=0,right:s="auto",top:o=0,width:l="auto",component:a}){if(!a)throw Error("PopupService showPopup, no component supplied");am(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};Wr((0,ri.createElement)(um,{key:hm++,position:n,style:h},a),u,r,o,()=>{Dn.keepWithinThePage(u,s)})}static hidePopup(e="anon",t="all"){if(ct.indexOf(e)!==-1){Vu(e);let n=document.body.querySelector(`.vuuPopup.${t}`);n&&$r.default.unmountComponentAtNode(n)}}static keepWithinThePage(e,t="auto"){let n=e.querySelector(".vuuPopupContainer > *");if(n){let{top:r,left:s,width:o,height:l,right:a}=n.getBoundingClientRect(),u=window.innerWidth,c=window.innerHeight-(r+l);c<0&&(n.style.top=Math.round(r)+c+"px");let f=u-(s+o);if(f<0&&(n.style.left=Math.round(s)+f+"px"),typeof t=="number"&&t!==a){let p=t-a;n.style.left=s+p+"px"}}}};var Gr=require("react/jsx-runtime"),si=()=>{let i=(0,Zi.useContext)(Kr),e=(0,Zi.useCallback)((n,r,s)=>{let o=[];for(let l of n)o=o.concat(l(r,s));return o},[]);return(0,Zi.useCallback)((n,r,s)=>{var a;n.stopPropagation(),n.preventDefault();let o=(a=i==null?void 0:i.menuBuilders)!=null?a:[],l=e(o,r,s);console.log({menuItemDescriptors:l}),l.length&&(i!=null&&i.menuActionHandler)&&(console.log(`showContextMenu ${r}`,{options:s}),cm(n,l,i.menuActionHandler))},[e,i])},cm=(i,e,t)=>{let{clientX:n,clientY:r}=i,l=(0,Gr.jsx)(xo,{onClose:(a,u)=>{a&&(t(a,u),Dn.hidePopup())},position:{x:n,y:r},children:(a=>{let u=(h,c)=>ko(h)?(0,Gr.jsx)(_r,{label:h.label,children:h.children.map(u)},c):(0,Gr.jsx)(Co,{action:h.action,"data-icon":h.icon,options:h.options,children:h.label},c);return a.map(u)})(e)});Dn.showPopup({left:0,top:0,component:l})};var ao=require("@salt-ds/core");var Zu=require("@vuu-ui/vuu-utils"),eh=require("react"),th=Me(require("classnames"));var li=require("@vuu-ui/vuu-utils"),zu=Me(require("classnames")),tr=require("react");var qr=require("@vuu-ui/vuu-utils"),Bu=require("@heswell/salt-lab"),Fu=Me(require("classnames")),En=require("react");var er=require("react/jsx-runtime"),{KEY:Nu}=qr.metadataKeys,To=(0,En.memo)(({className:i,column:e,row:t})=>{let n=(0,En.useRef)(null),{align:r,CellRenderer:s,key:o,pin:l,editable:a,resizing:u,valueFormatter:h}=e,[c,f]=(0,En.useState)(!1),p=h(t[o]),[m,b]=(0,En.useState)(p),w=()=>{var x;(x=n.current)==null||x.focus()},v=x=>{x.key==="Enter"&&f(!0)},A=()=>{f(!0)},C=(x="",I="",_=!0,F=!1)=>{var R;f(!1),F?b(x):I!==x&&b(I),_===!1&&((R=n.current)==null||R.focus())},k=(0,Fu.default)(i,{vuuAlignRight:r==="right",vuuPinFloating:l==="floating",vuuPinLeft:l==="left",vuuPinRight:l==="right","vuuTableCell-resizing":u})||void 0,M=(0,qr.getColumnPinStyle)(e);return a?(0,er.jsx)("td",{className:k,"data-editable":!0,style:M,onKeyDown:v,children:(0,er.jsx)(Bu.EditableLabel,{editing:c,value:m,onChange:b,onMouseDownCapture:w,onEnterEditMode:A,onExitEditMode:C,onKeyDown:v,ref:n,tabIndex:0},"title")}):(0,er.jsx)("td",{className:k,style:M,children:s?(0,er.jsx)(s,{column:e,row:t}):p})},fm);To.displayName="TableCell";function fm(i,e){return i.column===e.column&&i.row[Nu]===e.row[Nu]&&i.row[i.column.key]===e.row[e.column.key]}var Hu=require("@vuu-ui/vuu-utils");var oi=require("react/jsx-runtime"),{DEPTH:dm,IS_LEAF:Wu}=Hu.metadataKeys,pm=(i,e)=>{let{[dm]:t,[Wu]:n}=e;if(n||t>i.length)return[null,t===null?0:t-1];if(t===0)return["$root",0];{let r=i[t-1];return[e[r.key],t-1]}},_u=({column:i,onClick:e,row:t})=>{let{columns:n}=i,[r,s]=pm(n,t),o={left:i.pin=="left"?i.pinnedOffset:void 0},l=t[Wu],a=Array(s).fill(0).map((u,h)=>(0,oi.jsx)("span",{className:"vuuTableGroupCell-spacer"},h));return(0,oi.jsxs)("td",{className:"vuuTableGroupCell vuuPinLeft",onClick:l?void 0:e,style:o,children:[a,l?null:(0,oi.jsx)("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),(0,oi.jsx)("span",{children:r})]})};var Ro=require("react/jsx-runtime"),{IDX:mm,IS_EXPANDED:gm,SELECTED:bm}=li.metadataKeys,jr="vuuDataTableRow",Qr=(0,tr.memo)(function({columns:e,height:t,index:n,onClick:r,onToggleGroup:s,row:o}){let{[mm]:l,[gm]:a,[bm]:u}=o,h=(0,zu.default)(jr,{[`${jr}-even`]:l%2===0,[`${jr}-expanded`]:a,[`${jr}-preSelected`]:u===2}),c=l-n,f=(0,tr.useCallback)(m=>{let b=m.shiftKey,w=m.ctrlKey||m.metaKey;r==null||r(o,b,w)},[r,o]),p=(0,tr.useCallback)(()=>s==null?void 0:s(o),[s,o]);return(0,Ro.jsx)("tr",{"aria-selected":u===1?!0:void 0,"aria-rowindex":l,className:h,onClick:f,style:{transform:`translate(0px, ${c*t}px)`},children:e.filter(li.notHidden).map(m=>{let b=(0,li.isGroupColumn)(m);return(0,Ro.jsx)(b?_u:To,{column:m,onClick:b?p:void 0,row:o},m.name)})})});var Xu=Me(require("classnames")),In=require("react");var ai=require("react");var Ku=require("react/jsx-runtime"),Uu=()=>{},ym="vuuColumnResizer",Jr=({onDrag:i,onDragEnd:e=Uu,onDragStart:t=Uu})=>{let n=(0,ai.useRef)(0),r=(0,ai.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]),s=(0,ai.useCallback)(l=>{window.removeEventListener("mouseup",s),window.removeEventListener("mousemove",r),e(l)},[e,r]),o=(0,ai.useCallback)(l=>{t(l),n.current=Math.round(l.clientX),window.addEventListener("mouseup",s),window.addEventListener("mousemove",r),l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault()},[t,r,s]);return(0,Ku.jsx)("div",{className:ym,onMouseDown:o})};var Ao=Me(require("classnames"));var Pn=require("react/jsx-runtime"),$u="vuuSortIndicator",Gu=({sorted:i})=>{if(!i)return null;let e=typeof i=="number"?i<0?"dsc":"asc":i==="A"?"asc":"dsc";return typeof i=="number"?(0,Pn.jsxs)("div",{className:(0,Ao.default)($u,"multi-col",e),children:[(0,Pn.jsx)("span",{"data-icon":`sorted-${e}`}),(0,Pn.jsx)("span",{className:"vuuSortPosition",children:Math.abs(i)})]}):(0,Pn.jsx)("div",{className:(0,Ao.default)($u,"single-col"),children:(0,Pn.jsx)("span",{"data-icon":`sorted-${e}`})})};var On=require("react"),Xr=({column:i,onResize:e,rootRef:t})=>{let n=(0,On.useRef)(0),r=(0,On.useRef)(!1),{name:s}=i,o=(0,On.useCallback)(()=>{if(e&&t.current){let{width:u}=t.current.getBoundingClientRect();n.current=Math.round(u),r.current=!0,e==null||e("begin",s)}},[s,e,t]),l=(0,On.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",s,f),n.current=f)}},[s,e,t]),a=(0,On.useCallback)(()=>{e&&(e("end",s,n.current),r.current=!1)},[s,e]);return{isResizing:r.current,onDrag:l,onDragStart:o,onDragEnd:a}};var qu=Me(require("classnames")),ju=require("react");var Ju=require("react/jsx-runtime");var Qu=({column:i,filter:e})=>{let t=si(),n=(0,ju.useCallback)(r=>{r.stopPropagation(),t(r,"filter",{column:i,filter:e})},[i,e,t]);return i.filter?(0,Ju.jsx)("div",{className:(0,qu.default)("vuuFilterIndicator"),"data-icon":"filter",onClick:n}):null};var Yt=require("react/jsx-runtime"),nr="vuuTable-headerCell",Yr=({column:i,className:e,onClick:t,onDragStart:n,onResize:r,...s})=>{let o=(0,In.useRef)(null),{isResizing:l,...a}=Xr({column:i,onResize:r,rootRef:o}),u=si(),h=(0,In.useRef)(null),c=w=>{u(w,"header",{column:i})},f=(0,In.useCallback)(w=>!l&&(t==null?void 0:t(w)),[l,t]),p=(0,In.useCallback)(w=>{h.current=window.setTimeout(()=>{n==null||n(w),h.current=null},250)},[n]),m=(0,In.useCallback)(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),b=(0,Xu.default)(nr,e,{vuuPinFloating:i.pin==="floating",vuuPinLeft:i.pin==="left",vuuPinRight:i.pin==="right",vuuEndPin:i.endPin,[`${nr}-resizing`]:i.resizing,[`${nr}-right`]:i.align==="right"});return(0,Yt.jsx)("th",{className:b,...s,onClick:f,onContextMenu:c,onMouseDown:p,onMouseUp:m,ref:o,children:(0,Yt.jsxs)("div",{className:`${nr}-inner`,children:[(0,Yt.jsx)(Qu,{column:i}),(0,Yt.jsx)("div",{className:`${nr}-label`,children:i.label}),(0,Yt.jsx)(Gu,{sorted:i.sorted}),i.resizeable!==!1?(0,Yt.jsx)(Jr,{...a}):null]})})};var ft=require("react/jsx-runtime"),Yu="vuuDataTable",{RENDER_IDX:wm}=Zu.metadataKeys,nh=({columns:i,data:e,headerHeight:t,onHeaderCellDragEnd:n,rowHeight:r})=>{let s=(0,eh.useCallback)(()=>{n==null||n()},[n]);return console.log("ColumnBasedTable render"),(0,ft.jsx)(ft.Fragment,{children:i.map((o,l)=>(0,ft.jsx)("table",{className:(0,th.default)(`${Yu}-table`,`${Yu}-columnBased`,{vuuPinLeft:o.pin==="left"}),"data-idx":l,id:`col-${l}`,style:{width:o.width,left:o.pinnedOffset,"--vuuTableHeaderHeight":`${t}px`,"--row-height":`${r}px`},children:(0,ft.jsxs)("tbody",{children:[(0,ft.jsx)("tr",{children:(0,ft.jsx)(Yr,{column:o,"data-idx":l,onDragEnd:s},l)},"header"),e.map((a,u)=>(0,ft.jsx)(Qr,{columns:[o],height:r,index:u,row:a},a[wm])),(0,ft.jsx)("tr",{className:"vuuTable-filler"})]})},o.name))})};var ih=require("@vuu-ui/vuu-utils"),rh=i=>(e,t)=>{let n=[];if(i===void 0)return n;if(e==="header")n.push(...vm(t,i)),n.push(...xm(t,i)),n.push(...Cm(t,i)),n.push(...Sm(t));else if(e==="filter"){let{column:r,filter:s}=t,o=(s==null?void 0:s.column)===(r==null?void 0:r.name);n.push({label:"Edit filter",action:"filter-edit",options:t}),n.push({label:"Remove filter",action:"filter-remove-column",options:t}),r&&!o&&n.push({label:"Remove all filters",action:"remove-filters",options:t})}return n};function vm(i,{sort:{sortDefs:e}}){let{column:t}=i,n=[];if(t===void 0)return n;let r=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}),r&&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}]})):r?(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 Cm(i,e){let{column:t}=i;if(t===void 0||e.groupBy.length===0)return[];let{name:n,label:r=n}=t;return[{label:`Aggregate ${r}`,children:[{label:"Count",action:"agg-count",options:i}].concat((0,ih.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 Oo=(i,e)=>({label:`Pin ${e}`,action:`column-pin-${e}`,options:i}),Do=i=>Oo(i,"left"),Eo=i=>Oo(i,"floating"),Po=i=>Oo(i,"right");function Sm(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:[Do(i),Eo(i),Po(i)]}):t==="left"?n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[Eo(i),Po(i)]}):t==="right"?n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[Do(i),Eo(i)]}):t==="floating"&&n.push({label:"Unpin column",action:"column-unpin",options:i},{label:"Pin column",children:[Do(i),Po(i)]}),n}function xm(i,{groupBy:e}){let{column:t}=i,n=[];if(t===void 0)return n;let{name:r,label:s=r}=t;return e.length===0?n.push({label:`Group by ${s}`,action:"group",options:i}):n.push({label:`Add ${s} to group by`,action:"group-add",options:i}),n}var ny=require("@salt-ds/core");var Q=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 r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),et.from(r,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),et.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),r=new Nn(this),s=new Nn(e);for(let o=t,l=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(l+=r.value.length,r.done||l>=n)return!0}}iter(e=1){return new Nn(this,e)}iterRange(e,t=this.length){return new ns(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new is(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]?Q.empty:e.length<=32?new he(e):et.from(he.split(e,[]))}},he=class extends Q{constructor(e,t=km(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.text[s],l=r+o.length;if((t?n:l)>=e)return new Lo(r,l,n,o);r=l+1,n++}}decompose(e,t,n,r){let s=e<=0&&t>=this.length?this:new he(sh(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=n.pop(),l=ts(s.text,o.text.slice(),0,s.length);if(l.length<=32)n.push(new he(l,o.length+s.length));else{let a=l.length>>1;n.push(new he(l.slice(0,a)),new he(l.slice(a)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof he))return super.replace(e,t,n);let r=ts(this.text,ts(n.text,sh(this.text,0,e)),t),s=this.length+n.length-(t-e);return r.length<=32?new he(r,s):et.from(he.split(r,[]),s)}sliceString(e,t=this.length,n=`
2
- `){let r="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let l=this.text[o],a=s+l.length;s>e&&o&&(r+=n),e<a&&t>s&&(r+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],r=-1;for(let s of e)n.push(s),r+=s.length+1,n.length==32&&(t.push(new he(n,r)),n=[],r=-1);return r>-1&&t.push(new he(n,r)),t}},et=class extends Q{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,r){for(let s=0;;s++){let o=this.children[s],l=r+o.length,a=n+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,n,r);r=l+1,n=a+1}}decompose(e,t,n,r){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let l=this.children[s],a=o+l.length;if(e<=a&&t>=o){let u=r&((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 r=0,s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.length;if(e>=s&&t<=l){let a=o.replace(e-s,t-s,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[r]=a,new et(h,this.length-(t-e)+n.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
3
- `){let r="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let l=this.children[s],a=o+l.length;o>e&&s&&(r+=n),e<a&&t>o&&(r+=l.sliceString(e-o,t-o,n)),o=a+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof et))return 0;let n=0,[r,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==l)return n;let a=this.children[r],u=e.children[s];if(a!=u)return n+a.scanIdentical(u,t);n+=a.length+1}}static from(e,t=e.reduce((n,r)=>n+r.length+1,-1)){let n=0;for(let p of e)n+=p.lines;if(n<32){let p=[];for(let m of e)m.flatten(p);return new he(p,t)}let r=Math.max(32,n>>5),s=r<<1,o=r>>1,l=[],a=0,u=-1,h=[];function c(p){let m;if(p.lines>s&&p instanceof et)for(let b of p.children)c(b);else p.lines>o&&(a>o||!a)?(f(),l.push(p)):p instanceof he&&a&&(m=h[h.length-1])instanceof he&&p.lines+m.lines<=32?(a+=p.lines,u+=p.length+1,h[h.length-1]=new he(m.text.concat(p.text),m.length+1+p.length)):(a+p.lines>r&&f(),a+=p.lines,u+=p.length+1,h.push(p))}function f(){a!=0&&(l.push(h.length==1?h[0]:et.from(h,u)),u=-1,a=h.length=0)}for(let p of e)c(p);return f(),l.length==1?l[0]:new et(l,t)}};Q.empty=new he([""],0);function km(i){let e=-1;for(let t of i)e+=t.length+1;return e}function ts(i,e,t=0,n=1e9){for(let r=0,s=0,o=!0;s<i.length&&r<=n;s++){let l=i[s],a=r+l.length;a>=t&&(a>n&&(l=l.slice(0,n-r)),r<t&&(l=l.slice(t-r)),o?(e[e.length-1]+=l,o=!1):e.push(l)),r=a+1}return e}function sh(i,e,t){return ts(i,[""],e,t)}var Nn=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 he?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],s=this.offsets[n],o=s>>1,l=r instanceof he?r.text.length:r.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((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
4
- `,this;e--}else if(r instanceof he){let a=r.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=r.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 he?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)}},ns=class{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new Nn(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:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.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!=""}},is=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(Q.prototype[Symbol.iterator]=function(){return this.iter()},Nn.prototype[Symbol.iterator]=ns.prototype[Symbol.iterator]=is.prototype[Symbol.iterator]=function(){return this});var Lo=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}},ui="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<ui.length;i++)ui[i]+=ui[i-1];function Mm(i){for(let e=1;e<ui.length;e+=2)if(ui[e]>i)return ui[e-1]<=i;return!1}function oh(i){return i>=127462&&i<=127487}var lh=8205;function We(i,e,t=!0,n=!0){return(t?dh:Tm)(i,e,n)}function dh(i,e,t){if(e==i.length)return e;e&&ph(i.charCodeAt(e))&&mh(i.charCodeAt(e-1))&&e--;let n=hi(i,e);for(e+=rs(n);e<i.length;){let r=hi(i,e);if(n==lh||r==lh||t&&Mm(r))e+=rs(r),n=r;else if(oh(r)){let s=0,o=e-2;for(;o>=0&&oh(hi(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function Tm(i,e,t){for(;e>0;){let n=dh(i,e-2,t);if(n<e)return n;e--}return 0}function ph(i){return i>=56320&&i<57344}function mh(i){return i>=55296&&i<56320}function hi(i,e){let t=i.charCodeAt(e);if(!mh(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return ph(n)?(t-55296<<10)+(n-56320)+65536:t}function rs(i){return i<65536?1:2}var Vo=/\r\n?|\n/,Ke=function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i}(Ke||(Ke={})),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,r=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(n,r,s),r+=s):r+=o,n+=s}}iterChangedRanges(e,t=!1){No(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];r<0?e.push(n,r):e.push(r,n)}return new je(e)}composeDesc(e){return this.empty?e:e.empty?this:gh(this,e)}mapDesc(e,t=!1){return e.empty?this:Bo(this,e,t)}mapPos(e,t=-1,n=Ke.Simple){let r=0,s=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],u=r+l;if(a<0){if(u>e)return s+(e-r);s+=l}else{if(n!=Ke.Simple&&u>=e&&(n==Ke.TrackDel&&r<e&&u>e||n==Ke.TrackBefore&&r<e||n==Ke.TrackAfter&&u>e))return null;if(u>e||u==e&&t<0&&!l)return e==r||t<0?s:s+a;s+=a}r=u}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let s=this.sections[n++],o=this.sections[n++],l=r+s;if(o>=0&&r<=t&&l>=e)return r<e&&l>t?"cover":!0;r=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?" ":"")+n+(r>=0?":"+r:"")}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)}},ce=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 No(this,(t,n,r,s,o)=>e=e.replace(r,r+(n-t),o),!1),e}mapDesc(e,t=!1){return Bo(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let r=0,s=0;r<t.length;r+=2){let o=t[r],l=t[r+1];if(l>=0){t[r]=l,t[r+1]=o;let a=r>>1;for(;n.length<a;)n.push(Q.empty);n.push(o?e.slice(s,s+o):Q.empty)}s+=o}return new ce(t,n)}compose(e){return this.empty?e:e.empty?this:gh(this,e,!0)}map(e,t=!1){return e.empty?this:Bo(this,e,t,!0)}iterChanges(e,t=!1){No(this,e,t)}get desc(){return je.create(this.sections)}filter(e){let t=[],n=[],r=[],s=new Bn(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&s.len==0;){if(s.done)break e;let h=Math.min(s.len,a-l);Ve(r,h,-1);let c=s.ins==-1?-1:s.off==0?s.ins:0;Ve(t,h,c),c>0&&Zt(n,t,s.text),s.forward(h),l+=h}let u=e[o++];for(;l<u;){if(s.done)break e;let h=Math.min(s.len,u-l);Ve(t,h,-1),Ve(r,h,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(h),l+=h}}return{changes:new ce(t,n),filtered:je.create(r)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,n){let r=[],s=[],o=0,l=null;function a(h=!1){if(!h&&!r.length)return;o<t&&Ve(r,t-o,-1);let c=new ce(r,s);l=l?l.compose(c.map(l)):c,r=[],s=[],o=0}function u(h){if(Array.isArray(h))for(let c of h)u(c);else if(h instanceof ce){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:p}=h;if(c>f||c<0||f>t)throw new RangeError(`Invalid change range ${c} to ${f} (in doc of length ${t})`);let m=p?typeof p=="string"?Q.of(p.split(n||Vo)):p:Q.empty,b=m.length;if(c==f&&b==0)return;c<o&&a(),c>o&&Ve(r,c-o,-1),Ve(r,f-c,b),Zt(s,r,m),o=f}}return u(e),a(!l),l}static empty(e){return new ce(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let r=0;r<e.length;r++){let s=e[r];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length<r;)n.push(Q.empty);n[r]=Q.of(s.slice(1)),t.push(s[0],n[r].length)}}}return new ce(t,n)}static createSet(e,t){return new ce(e,t)}};function Ve(i,e,t,n=!1){if(e==0&&t<=0)return;let r=i.length-2;r>=0&&t<=0&&t==i[r+1]?i[r]+=e:e==0&&i[r]==0?i[r+1]+=t:n?(i[r]+=e,i[r+1]+=t):i.push(e,t)}function Zt(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(Q.empty);i.push(t)}}function No(i,e,t){let n=i.inserted;for(let r=0,s=0,o=0;o<i.sections.length;){let l=i.sections[o++],a=i.sections[o++];if(a<0)r+=l,s+=l;else{let u=r,h=s,c=Q.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(r,u,s,h,c),r=u,s=h}}}function Bo(i,e,t,n=!1){let r=[],s=n?[]:null,o=new Bn(i),l=new Bn(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let u=Math.min(o.len,l.len);Ve(r,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(Ve(r,l.ins,-1);u;){let h=Math.min(o.len,u);o.ins>=0&&a<o.i&&o.len<=h&&(Ve(r,0,o.ins),s&&Zt(s,r,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;Ve(r,u,a<o.i?o.ins:0),s&&a<o.i&&Zt(s,r,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return s?ce.createSet(r,s):je.create(r);throw new Error("Mismatched change set lengths")}}function gh(i,e,t=!1){let n=[],r=t?[]:null,s=new Bn(i),o=new Bn(e);for(let l=!1;;){if(s.done&&o.done)return r?ce.createSet(n,r):je.create(n);if(s.ins==0)Ve(n,s.len,0,l),s.next();else if(o.len==0&&!o.done)Ve(n,0,o.ins,l),r&&Zt(r,n,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,o.len),u=n.length;if(s.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;Ve(n,a,h,l),r&&h&&Zt(r,n,o.text)}else o.ins==-1?(Ve(n,s.off?0:s.len,a,l),r&&Zt(r,n,s.textBit(a))):(Ve(n,s.off?0:s.len,o.off?0:o.ins,l),r&&!o.off&&Zt(r,n,o.text));l=(s.ins>a||o.ins>=0&&o.len>a)&&(l||n.length>u),s.forward2(a),o.forward(a)}}}}var Bn=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?Q.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?Q.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)}},It=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,r;return this.empty?n=r=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),n==this.from&&r==this.to?this:new It(n,r,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return E.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return E.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 E.range(e.anchor,e.head)}static create(e,t,n){return new It(e,t,n)}},E=class{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:E.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 E([this.main],0)}addRange(e,t=!0){return E.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();return n[t]=e,E.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 E(e.ranges.map(t=>It.fromJSON(t)),e.main)}static single(e,t=e){return new E([E.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,r=0;r<e.length;r++){let s=e[r];if(s.empty?s.from<=n:s.from<n)return E.normalized(e.slice(),t);n=s.to}return new E(e,t)}static cursor(e,t=0,n,r){return It.create(e,e,(t==0?0:t<0?4:8)|(n==null?3:Math.min(2,n))|(r!=null?r:33554431)<<5)}static range(e,t,n,r){let s=(n!=null?n:33554431)<<5|(r==null?3:Math.min(2,r));return t<e?It.create(t,e,24|s):It.create(e,t,(t>e?4:0)|s)}static normalized(e,t=0){let n=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(n);for(let r=1;r<e.length;r++){let s=e[r],o=e[r-1];if(s.empty?s.from<=o.to:s.from<o.to){let l=o.from,a=Math.max(s.to,o.to);r<=t&&t--,e.splice(--r,2,s.anchor>s.head?E.range(a,l):E.range(l,a))}}return new E(e,t)}};function bh(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var $o=0,K=class{constructor(e,t,n,r,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=$o++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}static define(e={}){return new K(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:Go),!!e.static,e.enables)}of(e){return new ci([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ci(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ci(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}};function Go(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}var ci=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=$o++}dynamicSlot(e){var t;let n=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>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)||Fo(c,h)){let p=n(c);if(l?!ah(p,c.values[o],r):!r(p,c.values[o]))return c.values[o]=p,1}return 0},reconfigure:(c,f)=>{let p,m=f.config.address[s];if(m!=null){let b=os(f,m);if(this.dependencies.every(w=>w instanceof K?f.facet(w)===c.facet(w):w instanceof Qe?f.field(w,!1)==c.field(w,!1):!0)||(l?ah(p=n(c),b,r):r(p=n(c),b)))return c.values[o]=b,0}else p=n(c);return c.values[o]=p,1}}}};function ah(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 Fo(i,e){let t=!1;for(let n of e)rr(i,n)&1&&(t=!0);return t}function Rm(i,e,t){let n=t.map(a=>i[a.id]),r=t.map(a=>a.type),s=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=os(a,n[h]);if(r[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)rr(a,u);return a.values[o]=l(a),1},update(a,u){if(!Fo(a,s))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,u){let h=Fo(a,n),c=u.config.facets[e.id],f=u.facet(e);if(c&&!h&&Go(t,c))return a.values[o]=f,0;let p=l(a);return e.compare(p,f)?(a.values[o]=f,0):(a.values[o]=p,1)}}}var uh=K.define({static:!0}),Qe=class{constructor(e,t,n,r,s){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=s,this.provides=void 0}static define(e){let t=new Qe($o++,e.create,e.update,e.compare||((n,r)=>n===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(uh).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,r)=>{let s=n.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(n.values[t]=o,1)},reconfigure:(n,r)=>r.config.address[this.id]!=null?(n.values[t]=r.field(this),0):(n.values[t]=this.create(n),1)}}init(e){return[this,uh.of({field:this,create:e})]}get extension(){return this}},Ln={lowest:4,low:3,default:2,high:1,highest:0};function ir(i){return e=>new ss(e,i)}var mi={highest:ir(Ln.highest),high:ir(Ln.high),default:ir(Ln.default),low:ir(Ln.low),lowest:ir(Ln.lowest)},ss=class{constructor(e,t){this.inner=e,this.prec=t}},di=class{of(e){return new sr(this,e)}reconfigure(e){return di.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},sr=class{constructor(e,t){this.compartment=e,this.inner=t}},pi=class{constructor(e,t,n,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=s,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 r=[],s=Object.create(null),o=new Map;for(let f of Am(e,t,o))f instanceof Qe?r.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],u=[];for(let f of r)l[f.id]=u.length<<1,u.push(p=>f.slot(p));let h=n==null?void 0:n.config.facets;for(let f in s){let p=s[f],m=p[0].facet,b=h&&h[f]||[];if(p.every(w=>w.type==0))if(l[m.id]=a.length<<1|1,Go(b,p))a.push(n.facet(m));else{let w=m.combine(p.map(v=>v.value));a.push(n&&m.compare(w,n.facet(m))?n.facet(m):w)}else{for(let w of p)w.type==0?(l[w.id]=a.length<<1|1,a.push(w.value)):(l[w.id]=u.length<<1,u.push(v=>w.dynamicSlot(v)));l[m.id]=u.length<<1,u.push(w=>Rm(w,m,p))}}let c=u.map(f=>f(l));return new pi(e,o,c,l,a,s)}};function Am(i,e,t){let n=[[],[],[],[],[]],r=new Map;function s(o,l){let a=r.get(o);if(a!=null){if(a<=l)return;let u=n[a].indexOf(o);u>-1&&n[a].splice(u,1),o instanceof sr&&t.delete(o.compartment)}if(r.set(o,l),Array.isArray(o))for(let u of o)s(u,l);else if(o instanceof sr){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),s(u,l)}else if(o instanceof ss)s(o.inner,o.prec);else if(o instanceof Qe)n[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof ci)n[l].push(o),o.facet.extensions&&s(o.facet.extensions,Ln.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.`);s(u,l)}}return s(i,Ln.default),n.reduce((o,l)=>o.concat(l))}function rr(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 r=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|r}function os(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}var yh=K.define(),wh=K.define({combine:i=>i.some(e=>e),static:!0}),vh=K.define({combine:i=>i.length?i[0]:void 0,static:!0}),Ch=K.define(),Sh=K.define(),xh=K.define(),kh=K.define({combine:i=>i.length?i[0]:!1}),tt=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Ho}},Ho=class{of(e){return new tt(this,e)}},Wo=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 Wo(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let s=r.map(t);s&&n.push(s)}return n}};ae.reconfigure=ae.define();ae.appendConfig=ae.define();var fe=class{constructor(e,t,n,r,s,o){this.startState=e,this.changes=t,this.selection=n,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,n&&bh(n,t.newLength),s.some(l=>l.type==fe.time)||(this.annotations=s.concat(fe.time.of(Date.now())))}static create(e,t,n,r,s,o){return new fe(e,t,n,r,s,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(fe.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};fe.time=tt.define();fe.userEvent=tt.define();fe.addToHistory=tt.define();fe.remote=tt.define();function Dm(i,e){let t=[];for(let n=0,r=0;;){let s,o;if(n<i.length&&(r==e.length||e[r]>=i[n]))s=i[n++],o=i[n++];else if(r<e.length)s=e[r++],o=e[r++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Mh(i,e,t){var n;let r,s,o;return t?(r=e.changes,s=ce.empty(e.changes.length),o=i.changes.compose(e.changes)):(r=e.changes.map(i.changes),s=i.changes.mapDesc(e.changes,!0),o=i.changes.compose(r)),{changes:o,selection:e.selection?e.selection.map(s):(n=i.selection)===null||n===void 0?void 0:n.map(r),effects:ae.mapEffects(i.effects,r).concat(ae.mapEffects(e.effects,s)),annotations:i.annotations.length?i.annotations.concat(e.annotations):e.annotations,scrollIntoView:i.scrollIntoView||e.scrollIntoView}}function _o(i,e,t){let n=e.selection,r=fi(e.annotations);return e.userEvent&&(r=r.concat(fe.userEvent.of(e.userEvent))),{changes:e.changes instanceof ce?e.changes:ce.of(e.changes||[],t,i.facet(vh)),selection:n&&(n instanceof E?n:E.single(n.anchor,n.head)),effects:fi(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function Th(i,e,t){let n=_o(i,e.length?e[0]:{},i.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;n=Mh(n,_o(i,e[s],o?n.changes.newLength:i.doc.length),o)}let r=fe.create(i,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return Pm(t?Em(r):r)}function Em(i){let e=i.startState,t=!0;for(let r of e.facet(Ch)){let s=r(i);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:Dm(t,s))}if(t!==!0){let r,s;if(t===!1)s=i.changes.invertedDesc,r=ce.empty(e.doc.length);else{let o=i.changes.filter(t);r=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}i=fe.create(e,r,i.selection&&i.selection.map(s),ae.mapEffects(i.effects,s),i.annotations,i.scrollIntoView)}let n=e.facet(Sh);for(let r=n.length-1;r>=0;r--){let s=n[r](i);s instanceof fe?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof fe?i=s[0]:i=Th(e,fi(s),!1)}return i}function Pm(i){let e=i.startState,t=e.facet(xh),n=i;for(let r=t.length-1;r>=0;r--){let s=t[r](i);s&&Object.keys(s).length&&(n=Mh(n,_o(e,s,i.changes.newLength),!0))}return n==i?i:fe.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}var Om=[];function fi(i){return i==null?Om:Array.isArray(i)?i:[i]}var dt=function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i}(dt||(dt={})),Im=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,zo;try{zo=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Lm(i){if(zo)return zo.test(i);for(let e=0;e<i.length;e++){let t=i[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||Im.test(t)))return!0}return!1}function Vm(i){return e=>{if(!/\S/.test(e))return dt.Space;if(Lm(e))return dt.Word;for(let t=0;t<i.length;t++)if(e.indexOf(i[t])>-1)return dt.Word;return dt.Other}}var J=class{constructor(e,t,n,r,s,o){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)rr(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 rr(this,n),os(this,n)}update(...e){return Th(this,e,!0)}applyTransaction(e){let t=this.config,{base:n,compartments:r}=t;for(let o of e.effects)o.is(di.reconfigure)?(t&&(r=new Map,t.compartments.forEach((l,a)=>r.set(a,l)),t=null),r.set(o.value.compartment,o.value.extension)):o.is(ae.reconfigure)?(t=null,n=o.value):o.is(ae.appendConfig)&&(t=null,n=fi(n).concat(o.value));let s;t?s=e.startState.values.slice():(t=pi.resolve(n,r,this),s=new J(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new J(t,e.newDoc,e.newSelection,s,(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:E.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),s=[n.range],o=fi(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(r);for(let f=0;f<l;f++)s[f]=s[f].map(h);let c=r.mapDesc(u,!0);s.push(a.range.map(c)),r=r.compose(h),o=ae.mapEffects(o,h).concat(ae.mapEffects(fi(a.effects),c))}return{changes:r,selection:E.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ce?e:ce.of(e,this.doc.length,this.facet(J.lineSeparator))}toText(e){return Q.of(e.split(this.facet(J.lineSeparator)||Vo))}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:(rr(this,t),os(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Qe&&this.config.address[r.id]!=null&&(t[n]=r.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 r=[];if(n){for(let s in n)if(Object.prototype.hasOwnProperty.call(e,s)){let o=n[s],l=e[s];r.push(o.init(a=>o.spec.fromJSON(l,a)))}}return J.create({doc:e.doc,selection:E.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=pi.resolve(e.extensions||[],new Map),n=e.doc instanceof Q?e.doc:Q.of((e.doc||"").split(t.staticFacet(J.lineSeparator)||Vo)),r=e.selection?e.selection instanceof E?e.selection:E.single(e.selection.anchor,e.selection.head):E.single(0);return bh(r,n.length),t.staticFacet(wh)||(r=r.asSingle()),new J(t,n,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(J.tabSize)}get lineBreak(){return this.facet(J.lineSeparator)||`
5
- `}get readOnly(){return this.facet(kh)}phrase(e,...t){for(let n of this.facet(J.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let r=[];for(let s of this.facet(yh))for(let o of s(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){return Vm(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-n,l=e-n;for(;o>0;){let a=We(t,o,!1);if(s(t.slice(a,o))!=dt.Word)break;o=a}for(;l<r;){let a=We(t,l);if(s(t.slice(l,a))!=dt.Word)break;l=a}return o==l?null:E.range(o+n,l+n)}};J.allowMultipleSelections=wh;J.tabSize=K.define({combine:i=>i.length?i[0]:4});J.lineSeparator=vh;J.readOnly=kh;J.phrases=K.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(r=>i[r]==e[r])}});J.languageData=yh;J.changeFilter=Ch;J.transactionFilter=Sh;J.transactionExtender=xh;di.reconfigure=ae.define();function gi(i,e,t={}){let n={};for(let r of i)for(let s of Object.keys(r)){let o=r[s],l=n[s];if(l===void 0)n[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](l,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)n[r]===void 0&&(n[r]=e[r]);return n}var Lt=class{eq(e){return this==e}range(e,t=e){return Fn.create(e,t,this)}};Lt.prototype.startSide=Lt.prototype.endSide=0;Lt.prototype.point=!1;Lt.prototype.mapMode=Ke.TrackDel;var Fn=class{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new Fn(e,t,n)}};function Uo(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}var or=class{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,r=0){let s=n?this.to:this.from;for(let o=r,l=s.length;;){if(o==l)return o;let a=o+l>>1,u=s[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,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,s);s<o;s++)if(r(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t){let n=[],r=[],s=[],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,p;if(h==c){let m=t.mapPos(h,u.startSide,u.mapMode);if(m==null||(f=p=m,u.startSide!=u.endSide&&(p=t.mapPos(h,u.endSide),p<f)))continue}else if(f=t.mapPos(h,u.startSide),p=t.mapPos(c,u.endSide),f>p||f==p&&u.startSide>0&&u.endSide<=0)continue;(p-f||u.endSide-u.startSide)<0||(o<0&&(o=f),u.point&&(l=Math.max(l,p-f)),n.push(u),r.push(f-o),s.push(p-o))}return{mapped:n.length?new or(r,s,n,l):null,pos:o}}},le=class{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(e,t,n,r){return new le(e,t,n,r)}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:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(Uo)),this.isEmpty)return t.length?le.of(t):this;let l=new ls(this,null,-1).goto(0),a=0,u=[],h=new Ct;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||r>this.chunkEnd(l.chunkIndex)||s<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||r>l.to||s<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||u.push(Fn.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:r,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],r=-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)r=Math.max(r,a.maxPoint),t.push(a),n.push(e.mapPos(l));else if(u===!0){let{mapped:h,pos:c}=a.map(l,e);h&&(r=Math.max(r,h.maxPoint),t.push(h),n.push(c))}}let s=this.nextLayer.map(e);return t.length==0?s:new le(n,t,s||le.empty,r)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let s=this.chunkPos[r],o=this.chunk[r];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Hn.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Hn.from(e).goto(t)}static compare(e,t,n,r,s=-1){let o=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=s),l=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=s),a=hh(o,l,n),u=new Vn(o,a,s),h=new Vn(l,a,s);n.iterGaps((c,f,p)=>ch(u,c,h,f,p,r)),n.empty&&n.length==0&&ch(u,0,h,0,0,r)}static eq(e,t,n=0,r){r==null&&(r=1e9-1);let s=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=hh(s,o),a=new Vn(s,l,0).goto(n),u=new Vn(o,l,0).goto(n);for(;;){if(a.to!=u.to||!Ko(a.active,u.active)||a.point&&(!u.point||!a.point.eq(u.point)))return!1;if(a.to>r)return!0;a.next(),u.next()}}static spans(e,t,n,r,s=-1){let o=new Vn(e,null,s).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);r.point(l,u,o.point,h,c,o.pointRank),a=Math.min(o.openEnd(u),h.length)}else u>l&&(r.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 Ct;for(let r of e instanceof Fn?[e]:t?Nm(e):e)n.add(r.from,r.to,r.value);return n.finish()}};le.empty=new le([],[],null,-1);function Nm(i){if(i.length>1)for(let e=i[0],t=1;t<i.length;t++){let n=i[t];if(Uo(e,n)>0)return i.slice().sort(Uo);e=n}return i}le.empty.nextLayer=le.empty;var Ct=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 or(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 Ct)).add(e,t,n)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<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 hh(i,e,t){let n=new Map;for(let s of i)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&n.set(s.chunk[o],s.chunkPos[o]);let r=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let l=n.get(s.chunk[o]);l!=null&&(t?t.mapPos(l):l)==s.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+s.chunk[o].length))&&r.add(s.chunk[o])}return r}var ls=class{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}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 r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<e||r.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}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}},Hn=class{constructor(e){this.heap=e}static from(e,t=null,n=-1){let r=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=n&&r.push(new ls(o,t,n,s));return r.length==1?r[0]:new Hn(r)}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--)Io(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--)Io(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(),Io(this.heap,0)}}};function Io(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let r=i[n];if(n+1<i.length&&r.compare(i[n+1])>=0&&(r=i[n+1],n++),t.compare(r)<0)break;i[n]=t,i[e]=r,e=n}}var Vn=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=Hn.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){Zr(this.active,e),Zr(this.activeTo,e),Zr(this.activeRank,e),this.minActive=fh(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:s}=this.cursor;for(;t<this.activeRank.length&&this.activeRank[t]<=s;)t++;es(this.active,t,n),es(this.activeTo,t,r),es(this.activeRank,t,s),e&&es(e,t,this.cursor.from),this.minActive=fh(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&Zr(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.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=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.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 r=n.length-1;r>=0&&n[r]<e;r--)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 ch(i,e,t,n,r,s){i.goto(e),t.goto(n);let o=n+r,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))&&Ko(i.activeForPoint(i.to+a),t.activeForPoint(t.to))||s.comparePoint(l,c,i.point,t.point):c>l&&!Ko(i.active,t.active)&&s.compareRange(l,c,i.active,t.active),h>o)break;l=h,u<=0&&i.next(),u>=0&&t.next()}}function Ko(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 Zr(i,e){for(let t=e,n=i.length-1;t<n;t++)i[t]=i[t+1];i.pop()}function es(i,e,t){for(let n=i.length-1;n>=e;n--)i[n+1]=i[n];i[e]=t}function fh(i,e){let t=-1,n=1e9;for(let r=0;r<e.length;r++)(e[r]-n||i[r].endSide-i[t].endSide)<0&&(t=r,n=e[r]);return t}function Wn(i,e,t=i.length){let n=0;for(let r=0;r<t;)i.charCodeAt(r)==9?(n+=e-n%e,r++):(n++,r=We(i,r));return n}function Rh(i,e,t,n){for(let r=0,s=0;;){if(s>=e)return r;if(r==i.length)break;s+=i.charCodeAt(r)==9?t-s%t:1,r=We(i,r)}return n===!0?-1:i.length}var qo="\u037C",Ah=typeof Symbol>"u"?"__"+qo:Symbol.for(qo),jo=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Dh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},nt=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(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 p in l){let m=l[p];if(/&/.test(p))s(p.split(/,\s*/).map(b=>o.map(w=>b.replace(/&/,w))).reduce((b,w)=>b.concat(w)),m,a);else if(m&&typeof m=="object"){if(!c)throw new RangeError("The value of a property ("+p+") should be a primitive value.");s(r(p),m,h,f)}else m!=null&&h.push(p.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)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
6
- `)}static newName(){let e=Dh[Ah]||1;return Dh[Ah]=e+1,qo+e.toString(36)}static mount(e,t){(e[jo]||new Qo(e)).mount(Array.isArray(t)?t:[t])}},as=null,Qo=class{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(as)return e.adoptedStyleSheets=[as.sheet].concat(e.adoptedStyleSheets),e[jo]=as;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),as=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[jo]=this}mount(e){let t=this.sheet,n=0,r=0;for(let s=0;s<e.length;s++){let o=e[s],l=this.modules.indexOf(o);if(l<r&&l>-1&&(this.modules.splice(l,1),r--,l=-1),l==-1){if(this.modules.splice(r++,0,o),t)for(let a=0;a<o.rules.length;a++)t.insertRule(o.rules[a],n++)}else{for(;r<l;)n+=this.modules[r++].rules.length;n+=o.rules.length,r++}}if(!t){let s="";for(let o=0;o<this.modules.length;o++)s+=this.modules[o].getRules()+`
7
- `;this.styleTag.textContent=s}}};var Vt={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:"'"},bi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Eh=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),XC=typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent),Bm=typeof navigator<"u"&&/Mac/.test(navigator.platform),Fm=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Hm=Bm||Eh&&+Eh[1]<57;for(ye=0;ye<10;ye++)Vt[48+ye]=Vt[96+ye]=String(ye);var ye;for(ye=1;ye<=24;ye++)Vt[ye+111]="F"+ye;var ye;for(ye=65;ye<=90;ye++)Vt[ye]=String.fromCharCode(ye+32),bi[ye]=String.fromCharCode(ye);var ye;for(us in Vt)bi.hasOwnProperty(us)||(bi[us]=Vt[us]);var us;function Ph(i){var e=Hm&&(i.ctrlKey||i.altKey||i.metaKey)||Fm&&i.shiftKey&&i.key&&i.key.length==1||i.key=="Unidentified",t=!e&&i.key||(i.shiftKey?bi:Vt)[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 vs(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function Ci(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function Wm(i){let e=i.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function gs(i,e){if(!e.anchorNode)return!1;try{return Ci(i,e.anchorNode)}catch{return!1}}function fr(i){return i.nodeType==3?Si(i,0,i.nodeValue.length).getClientRects():i.nodeType==1?i.getClientRects():[]}function Cs(i,e,t,n){return t?Oh(i,e,t,n,-1)||Oh(i,e,t,n,1):!1}function Ss(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function Oh(i,e,t,n,r){for(;;){if(i==t&&e==n)return!0;if(e==(r<0?0:dr(i))){if(i.nodeName=="DIV")return!1;let s=i.parentNode;if(!s||s.nodeType!=1)return!1;e=Ss(i)+(r<0?0:1),i=s}else if(i.nodeType==1){if(i=i.childNodes[e+(r<0?-1:0)],i.nodeType==1&&i.contentEditable=="false")return!1;e=r<0?dr(i):0}else return!1}}function dr(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}var cc={left:0,right:0,top:0,bottom:0};function Nl(i,e){let t=e?i.left:i.right;return{left:t,right:t,top:i.top,bottom:i.bottom}}function _m(i){return{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function zm(i,e,t,n,r,s,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=_m(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 p=0,m=0;if(r=="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,w=c.bottom-c.top;m=(r=="center"&&b<=w?e.top+b/2-w/2:r=="start"||r=="center"&&t<0?e.top-o:e.bottom-w+o)-c.top}if(n=="nearest"?e.left<c.left?(p=-(c.left-e.left+s),t>0&&e.right>c.right+p&&(p=e.right-c.right+p+s)):e.right>c.right&&(p=e.right-c.right+s,t<0&&e.left<c.left+p&&(p=-(c.left+p-e.left+s))):p=(n=="center"?e.left+(e.right-e.left)/2-(c.right-c.left)/2:n=="start"==l?e.left-s:e.right-(c.right-c.left)+s)-c.left,p||m)if(f)u.scrollBy(p,m);else{let b=0,w=0;if(m){let v=h.scrollTop;h.scrollTop+=m,w=h.scrollTop-v}if(p){let v=h.scrollLeft;h.scrollLeft+=p,b=h.scrollLeft-v}e={left:e.left-b,top:e.top-w,right:e.right-b,bottom:e.bottom-w},b&&Math.abs(b-p)<1&&(n="nearest"),w&&Math.abs(w-m)<1&&(r="nearest")}if(f)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function Um(i){let e=i.ownerDocument;for(let t=i.parentNode;t&&t!=e.body;)if(t.nodeType==1){if(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)return t;t=t.assignedSlot||t.parentNode}else if(t.nodeType==11)t=t.host;else break;return null}var tl=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,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}},yi=null;function fc(i){if(i.setActive)return i.setActive();if(yi)return i.focus(yi);let e=[];for(let t=i;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(i.focus(yi==null?{get preventScroll(){return yi={preventScroll:!0},!0}}:void 0),!yi){yi=!1;for(let t=0;t<e.length;){let n=e[t++],r=e[t++],s=e[t++];n.scrollTop!=r&&(n.scrollTop=r),n.scrollLeft!=s&&(n.scrollLeft=s)}}}var Ih;function Si(i,e,t=e){let n=Ih||(Ih=document.createRange());return n.setEnd(i,t),n.setStart(i,e),n}function vi(i,e,t){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0},r=new KeyboardEvent("keydown",n);r.synthetic=!0,i.dispatchEvent(r);let s=new KeyboardEvent("keyup",n);return s.synthetic=!0,i.dispatchEvent(s),r.defaultPrevented||s.defaultPrevented}function Km(i){for(;i;){if(i&&(i.nodeType==9||i.nodeType==11&&i.host))return i;i=i.assignedSlot||i.parentNode}return null}function dc(i){for(;i.attributes.length;)i.removeAttributeNode(i.attributes[0])}function $m(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 r=t.childNodes[n-1];r.contentEditable=="false"?n--:(t=r,n=dr(t))}else{if(t==i)return!0;n=Ss(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,Ss(e),t)}static after(e,t){return new Re(e.parentNode,Ss(e)+1,t)}},Bl=[],te=class{constructor(){this.parent=null,this.dom=null,this.dirty=2}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,t){if(this.dirty&2){let n=this.dom,r=null,s;for(let o of this.children){if(o.dirty){if(!o.dom&&(s=r?r.nextSibling:n.firstChild)){let l=te.get(s);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(s)}o.sync(e,t),o.dirty=0}if(s=r?r.nextSibling:n.firstChild,t&&!t.written&&t.node==n&&s!=o.dom&&(t.written=!0),o.dom.parentNode==n)for(;s&&s!=o.dom;)s=Lh(s);else n.insertBefore(o.dom,s);r=o.dom}for(s=r?r.nextSibling:n.firstChild,s&&t&&t.node==n&&(t.written=!0);s;)s=Lh(s)}else if(this.dirty&1)for(let n of this.children)n.dirty&&(n.sync(e,t),n.dirty=0)}reuseDOM(e){}localPosFromDOM(e,t){let n;if(e==this.dom)n=this.dom.childNodes[t];else{let r=dr(e)==0?0:t==0?-1:1;for(;;){let s=e.parentNode;if(s==this.dom)break;r==0&&s.firstChild!=s.lastChild&&(e==s.firstChild?r=-1:r=1),e=s}r<0?n=e:n=e.nextSibling}if(n==this.dom.firstChild)return 0;for(;n&&!te.get(n);)n=n.nextSibling;if(!n)return this.length;for(let r=0,s=0;;r++){let o=this.children[r];if(o.dom==n)return s;s+=o.length+o.breakAfter}}domBoundsAround(e,t,n=0){let r=-1,s=-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&&r==-1&&(r=a,s=u),u>t&&c.dom.parentNode==this.dom){o=a,l=h;break}h=f,u=f+c.breakAfter}return{from:s,to:l<0?n+this.length:l,startDOM:(r?this.children[r-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=Bl){this.markDirty();for(let r=e;r<t;r++){let s=this.children[r];s.parent==this&&s.destroy()}this.children.splice(e,t-e,...n);for(let r=0;r<n.length;r++)n[r].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new xs(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}get isWidget(){return!1}merge(e,t,n,r,s,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor}getSide(){return 0}destroy(){this.parent=null}};te.prototype.breakAfter=0;function Lh(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}var xs=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 pc(i,e,t,n,r,s,o,l,a){let{children:u}=i,h=u.length?u[e]:null,c=s.length?s[s.length-1]:null,f=c?c.breakAfter:o;if(!(e==n&&h&&!o&&!f&&s.length<2&&h.merge(t,r,s.length?c:null,t==0,l,a))){if(n<u.length){let p=u[n];p&&r<p.length?(e==n&&(p=p.split(r),r=0),!f&&c&&p.merge(0,r,c,!0,0,a)?s[s.length-1]=p:(r&&p.merge(0,r,null,!1,0,a),s.push(p))):p!=null&&p.breakAfter&&(c?c.breakAfter=1:o=1),n++}for(h&&(h.breakAfter=o,t>0&&(!o&&s.length&&h.merge(t,h.length,s[0],!1,l,0)?h.breakAfter=s.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&&s.length;)if(u[n-1].become(s[s.length-1]))n--,s.pop(),a=s.length?0:l;else if(u[e].become(s[0]))e++,s.shift(),l=s.length?0:a;else break;!s.length&&e&&n<u.length&&!u[e-1].breakAfter&&u[n].merge(0,0,u[e-1],!1,l,a)&&e--,(e<n||s.length)&&i.replaceChildren(e,n,s)}}function mc(i,e,t,n,r,s){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,pc(i,u,h,l,a,n,0,r,s)}var Je=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},nl=typeof document<"u"?document:{documentElement:{style:{}}},il=/Edge\/(\d+)/.exec(Je.userAgent),gc=/MSIE \d/.test(Je.userAgent),rl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Je.userAgent),Os=!!(gc||rl||il),Vh=!Os&&/gecko\/(\d+)/i.test(Je.userAgent),Jo=!Os&&/Chrome\/(\d+)/.exec(Je.userAgent),Nh="webkitFontSmoothing"in nl.documentElement.style,bc=!Os&&/Apple Computer/.test(Je.vendor),Bh=bc&&(/Mobile\/\w+/.test(Je.userAgent)||Je.maxTouchPoints>2),W={mac:Bh||/Mac/.test(Je.platform),windows:/Win/.test(Je.platform),linux:/Linux|X11/.test(Je.platform),ie:Os,ie_version:gc?nl.documentMode||6:rl?+rl[1]:il?+il[1]:0,gecko:Vh,gecko_version:Vh?+(/Firefox\/(\d+)/.exec(Je.userAgent)||[0,0])[1]:0,chrome:!!Jo,chrome_version:Jo?+Jo[1]:0,ios:Bh,android:/Android\b/.test(Je.userAgent),webkit:Nh,safari:bc,webkit_version:Nh?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:nl.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"},Gm=256,kt=class extends te{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,n){return n&&(!(n instanceof kt)||this.length-(t-e)+n.length>Gm)?!1:(this.text=this.text.slice(0,e)+(n?n.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new kt(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 sl(this.dom,e,t)}},rt=class extends te{constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let r of t)r.setParent(this)}setAttrs(e){if(dc(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,t){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,n,r,s,o){return n&&(!(n instanceof rt&&n.mark.eq(this.mark))||e&&s<=0||t<this.length&&o<=0)?!1:(mc(this,e,t,n?n.children:[],s-1,o-1),this.markDirty(),!0)}split(e){let t=[],n=0,r=-1,s=0;for(let l of this.children){let a=n+l.length;a>e&&t.push(n<e?l.split(e-n):l),r<0&&n>=e&&(r=s),n=a,s++}let o=this.length-e;return this.length=e,r>-1&&(this.children.length=r,this.markDirty()),new rt(this.mark,t,o)}domAtPos(e){return wc(this,e)}coordsAt(e,t){return Cc(this,e,t)}};function sl(i,e,t){let n=i.nodeValue.length;e>n&&(e=n);let r=e,s=e,o=0;e==0&&t<0||e==n&&t>=0?W.chrome||W.gecko||(e?(r--,o=1):s<n&&(s++,o=-1)):t<0?r--:s<n&&s++;let l=Si(i,r,s).getClientRects();if(!l.length)return cc;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?Nl(a,o<0):a||null}var xt=class extends te{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||xt)(e,t,n)}split(e){let t=xt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,n,r,s,o){return n&&(!(n instanceof xt)||!this.widget.compare(n.widget)||e>0&&s<=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 xt&&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 Q.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,n=t&&t.state.doc,r=this.posAtStart;return n?n.slice(r,r+this.length):Q.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(),r=null;if(!n.length)return cc;for(let s=e>0?n.length-1:0;r=n[s],!(e>0?s==0:s==n.length-1||r.top<r.bottom);s+=e>0?-1:1);return this.length?r:Nl(r,this.side>0)}get isEditable(){return!1}get isWidget(){return!0}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},ks=class extends xt{domAtPos(e){let{topView:t,text:n}=this.widget;return t?ol(e,0,t,n,(r,s)=>r.domAtPos(s),r=>new Re(n,Math.min(r,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:r}=this.widget;return n?yc(e,t,n,r):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:n,text:r}=this.widget;return n?ol(e,t,n,r,(s,o,l)=>s.coordsAt(o,l),(s,o)=>sl(r,s,o)):sl(r,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 ol(i,e,t,n,r,s){if(t instanceof rt){for(let o=t.dom.firstChild;o;o=o.nextSibling){let l=te.get(o);if(!l)return s(i,e);let a=Ci(o,n),u=l.length+(a?n.nodeValue.length:0);if(i<u||i==u&&l.getSide()<=0)return a?ol(i,e,l,n,r,s):r(l,i,e);i-=u}return r(t,t.length,-1)}else return t.dom==n?s(i,e):r(t,i,e)}function yc(i,e,t,n){if(t instanceof rt)for(let r of t.children){let s=0,o=Ci(r.dom,n);if(Ci(r.dom,i))return s+(o?yc(i,e,r,n):r.localPosFromDOM(i,e));s+=o?n.nodeValue.length:r.length}else if(t.dom==n)return Math.min(e,n.nodeValue.length);return t.localPosFromDOM(i,e)}var rn=class extends te{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof rn&&e.side==this.side}split(){return new rn(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=qm(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 Q.empty}};kt.prototype.children=xt.prototype.children=rn.prototype.children=Bl;function qm(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 r=t.children[n+e];if(r instanceof kt){let s=r.coordsAt(e<0?r.length:0,e);if(s)return s}n+=e}else if(t instanceof rt&&t.parent)n=t.parent.children.indexOf(t)+(e<0?0:1),t=t.parent;else{let r=t.dom.lastChild;if(r&&r.nodeName=="BR")return r.getClientRects()[0];break}}function wc(i,e){let t=i.dom,{children:n}=i,r=0;for(let s=0;r<n.length;r++){let o=n[r],l=s+o.length;if(!(l==s&&o.getSide()<=0)){if(e>s&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-s);if(e<=s)break;s=l}}for(let s=r;s>0;s--){let o=n[s-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let s=r;s<n.length;s++){let o=n[s];if(o.dom.parentNode==t)return o.domAtPos(0)}return new Re(t,0)}function vc(i,e,t){let n,{children:r}=i;t>0&&e instanceof rt&&r.length&&(n=r[r.length-1])instanceof rt&&n.mark.eq(e.mark)?vc(n,e.children[0],t-1):(r.push(e),e.setParent(i)),i.length+=e.length}function Cc(i,e,t){let n=null,r=-1,s=null,o=-1;function l(u,h){for(let c=0,f=0;c<u.children.length&&f<=h;c++){let p=u.children[c],m=f+p.length;m>=h&&(p.children.length?l(p,h-f):!s&&(m>h||f==m&&p.getSide()>0)?(s=p,o=h-f):(f<h||f==m&&p.getSide()<0)&&(n=p,r=h-f)),f=m}}l(i,e);let a=(t<0?n:s)||n||s;return a?a.coordsAt(Math.max(0,a==n?r:o),t):jm(i)}function jm(i){let e=i.dom.lastChild;if(!e)return i.dom.getBoundingClientRect();let t=fr(e);return t[t.length-1]||null}function ll(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 Fl(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 r of t)if(n.indexOf(r)==-1||i[r]!==e[r])return!1;return!0}function al(i,e,t){let n=null;if(e)for(let r in e)t&&r in t||i.removeAttribute(n=r);if(t)for(let r in t)e&&e[r]==t[r]||i.setAttribute(n=r,t[r]);return!!n}var Ft=class{eq(e){return!1}updateDOM(e,t){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){}},se=function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i}(se||(se={})),oe=class extends Lt{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new xi(e)}static widget(e){let t=e.side||0,n=!!e.block;return t+=n?t>0?3e8:-4e8:t>0?1e8:-1e8,new Ht(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:s,end:o}=Sc(e,t);n=(s?t?-3e8:-1:5e8)-1,r=(o?t?2e8:1:-6e8)+1}return new Ht(e,n,r,t,e.widget||null,!0)}static line(e){return new _n(e)}static set(e,t=!1){return le.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};oe.none=le.empty;var xi=class extends oe{constructor(e){let{start:t,end:n}=Sc(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 xi&&this.tagName==e.tagName&&this.class==e.class&&Fl(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)}};xi.prototype.point=!1;var _n=class extends oe{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof _n&&this.spec.class==e.spec.class&&Fl(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)}};_n.prototype.mapMode=Ke.TrackBefore;_n.prototype.point=!0;var Ht=class extends oe{constructor(e,t,n,r,s,o){super(t,n,s,e),this.block=r,this.isReplace=o,this.mapMode=r?t<=0?Ke.TrackBefore:Ke.TrackAfter:Ke.TrackDel}get type(){return this.startSide<this.endSide?se.WidgetRange:this.startSide<=0?se.WidgetBefore:se.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&this.widget.estimatedHeight>=5}eq(e){return e instanceof Ht&&Qm(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)}};Ht.prototype.point=!0;function Sc(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 Qm(i,e){return i==e||!!(i&&e&&i.compare(e))}function ul(i,e,t,n=0){let r=t.length-1;r>=0&&t[r]+n>=i?t[r]=Math.max(t[r],e):t.push(i,e)}var De=class extends te{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,n,r,s,o){if(n){if(!(n instanceof De))return!1;this.dom||n.transferDOM(this)}return r&&this.setDeco(n?n.attrs:null),mc(this,e,t,n?n.children:[],s,o),!0}split(e){let t=new De;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i:n,off:r}=this.childPos(e);r&&(t.append(this.children[n].split(r),0),this.children[n].merge(r,this.children[n].length,null,!1,0,0),n++);for(let s=n;s<this.children.length;s++)t.append(this.children[s],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){Fl(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){vc(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=ll(t,this.attrs||{})),n&&(this.attrs=ll({class:n},this.attrs||{}))}domAtPos(e){return wc(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e,t){var n;this.dom?this.dirty&4&&(dc(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&&(al(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let r=this.dom.lastChild;for(;r&&te.get(r)instanceof rt;)r=r.lastChild;if(!r||!this.length||r.nodeName!="BR"&&((n=te.get(r))===null||n===void 0?void 0:n.isEditable)==!1&&(!W.ios||!this.children.some(s=>s instanceof kt))){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 kt)||/[^ -~]/.test(t.text))return null;let n=fr(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 Cc(this,e,t)}become(e){return!1}get type(){return se.Text}static find(e,t){for(let n=0,r=0;n<e.children.length;n++){let s=e.children[n],o=r+s.length;if(o>=t){if(s instanceof De)return s;if(o>t)break}r=o+s.breakAfter}return null}},Nt=class extends te{constructor(e,t,n){super(),this.widget=e,this.length=t,this.type=n,this.breakAfter=0,this.prevWidget=null}merge(e,t,n,r,s,o){return n&&(!(n instanceof Nt)||!this.widget.compare(n.widget)||e>0&&s<=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 Nt(this.widget,t,this.type);return n.breakAfter=this.breakAfter,n}get children(){return Bl}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):Q.empty}domBoundsAround(){return null}become(e){return e instanceof Nt&&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)}get isEditable(){return!1}get isWidget(){return!0}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},pr=class{constructor(e,t,n,r){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=r,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],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 Nt&&e.type==se.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new De),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(hs(new rn(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:s,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,this.atCursorPos=!0,e--;continue}else this.text=s,this.textOff=0}let r=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(hs(new kt(this.text.slice(this.textOff,this.textOff+r)),t),n),this.atCursorPos=!0,this.textOff+=r,e-=r,n=0}}span(e,t,n,r){this.buildText(t-e,n,r),this.pos=t,this.openStart<0&&(this.openStart=r)}point(e,t,n,r,s,o){if(this.disallowBlockEffectsFor[o]&&n instanceof Ht){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 Ht)if(n.block){let{type:a}=n;a==se.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Nt(n.widget||new Ms("div"),l,a))}else{let a=xt.create(n.widget||new Ms("span"),l,l?0:n.startSide),u=this.atCursorPos&&!a.isEditable&&s<=r.length&&(e<t||n.startSide>0),h=!a.isEditable&&(e<t||s>r.length||n.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!u&&(this.pendingBuffer=0),this.flushBuffer(r),u&&(c.append(hs(new rn(1),r),s),s=r.length+Math.max(0,s-r.length)),c.append(hs(a,r),s),this.atCursorPos=h,this.pendingBuffer=h?e<t||s>r.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=r.slice())}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=s)}static build(e,t,n,r,s){let o=new pr(e,t,n,s);return o.openEnd=le.spans(r,t,n,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function hs(i,e){for(let t of e)i=new rt(t,[i],i.length);return i}var Ms=class extends Ft{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}},xc=K.define(),kc=K.define(),Mc=K.define(),Tc=K.define(),hl=K.define(),Rc=K.define(),Ac=K.define(),Dc=K.define({combine:i=>i.some(e=>e)}),Ec=K.define({combine:i=>i.some(e=>e)}),ki=class{constructor(e,t="nearest",n="nearest",r=5,s=5){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=s}map(e){return e.empty?this:new ki(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}},Fh=ae.define({map:(i,e)=>i.map(e)});function Bt(i,e,t){let n=i.facet(Tc);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 Is=K.define({combine:i=>i.length?i[0]:!0}),Jm=0,lr=K.define(),mt=class{constructor(e,t,n,r){this.id=e,this.create=t,this.domEventHandlers=n,this.extension=r(this)}static define(e,t){let{eventHandlers:n,provide:r,decorations:s}=t||{};return new mt(Jm++,e,n,o=>{let l=[lr.of(o)];return s&&l.push(mr.of(a=>{let u=a.plugin(o);return u?s(u):oe.none})),r&&l.push(r(o)),l})}static fromClass(e,t){return mt.define(n=>new e(n),t)}},hr=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(Bt(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){Bt(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){Bt(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},Pc=K.define(),Hl=K.define(),mr=K.define(),Oc=K.define(),Ic=K.define(),ar=K.define(),it=class{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new it(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 r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),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 r=0,s=0,o=0,l=0;;r++){let a=r==e.length?null:e[r],u=o-l,h=a?a.fromB:1e9;for(;s<t.length&&t[s]<h;){let c=t[s],f=t[s+1],p=Math.max(l,c),m=Math.min(h,f);if(p<=m&&new it(p+u,m+u,p,m).addToSet(n),f>h)break;s+=2}if(!a)return n;new it(a.fromA,a.toA,a.fromB,a.toB).addToSet(n),o=a.toA,l=a.toB}}},Mi=class{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=ce.empty(this.startState.doc.length);for(let s of n)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,l,a)=>r.push(new it(s,o,l,a))),this.changedRanges=r}static create(e,t,n){return new Mi(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}},we=function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i}(we||(we={})),cl=we.LTR,Xm=we.RTL;function Lc(i){let e=[];for(let t=0;t<i.length;t++)e.push(1<<+i[t]);return e}var Ym=Lc("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Zm=Lc("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),fl=Object.create(null),St=[];for(let i of["()","[]","{}"]){let e=i.charCodeAt(0),t=i.charCodeAt(1);fl[e]=t,fl[t]=-e}function eg(i){return i<=247?Ym[i]:1424<=i&&i<=1524?2:1536<=i&&i<=1785?Zm[i-1536]:1774<=i&&i<=2220?4:8192<=i&&i<=8203?256:64336<=i&&i<=65023?4:i==8204?256:1}var tg=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,nn=class{constructor(e,t,n){this.from=e,this.to=t,this.level=n}get dir(){return this.level%2?Xm:cl}side(e,t){return this.dir==t==e?this.to:this.from}static find(e,t,n,r){let s=-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;(s<0||(r!=0?r<0?l.from<t:l.to>t:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}},de=[];function ng(i,e){let t=i.length,n=e==cl?1:2,r=e==cl?2:1;if(!i||n==1&&!tg.test(i))return Vc(t);for(let o=0,l=n,a=n;o<t;o++){let u=eg(i.charCodeAt(o));u==512?u=l:u==8&&a==4&&(u=16),de[o]=u==4?2:u,u&7&&(a=u),l=u}for(let o=0,l=n,a=n;o<t;o++){let u=de[o];if(u==128)o<t-1&&l==de[o+1]&&l&24?u=de[o]=l:de[o]=256;else if(u==64){let h=o+1;for(;h<t&&de[h]==64;)h++;let c=o&&l==8||h<t&&de[h]==8?a==1?1:8:256;for(let f=o;f<h;f++)de[f]=c;o=h-1}else u==8&&a==1&&(de[o]=1);l=u,u&7&&(a=u)}for(let o=0,l=0,a=0,u,h,c;o<t;o++)if(h=fl[u=i.charCodeAt(o)])if(h<0){for(let f=l-3;f>=0;f-=3)if(St[f+1]==-h){let p=St[f+2],m=p&2?n:p&4?p&1?r:n:0;m&&(de[o]=de[St[f]]=m),l=f;break}}else{if(St.length==189)break;St[l++]=o,St[l++]=u,St[l++]=a}else if((c=de[o])==2||c==1){let f=c==n;a=f?0:1;for(let p=l-3;p>=0;p-=3){let m=St[p+2];if(m&2)break;if(f)St[p+2]|=2;else{if(m&4)break;St[p+2]|=4}}}for(let o=0;o<t;o++)if(de[o]==256){let l=o+1;for(;l<t&&de[l]==256;)l++;let a=(o?de[o-1]:n)==1,u=(l<t?de[l]:n)==1,h=a==u?a?1:2:n;for(let c=o;c<l;c++)de[c]=h;o=l-1}let s=[];if(n==1)for(let o=0;o<t;){let l=o,a=de[o++]!=1;for(;o<t&&a==(de[o]!=1);)o++;if(a)for(let u=o;u>l;){let h=u,c=de[--u]!=2;for(;u>l&&c==(de[u-1]!=2);)u--;s.push(new nn(u,h,c?2:1))}else s.push(new nn(l,o,0))}else for(let o=0;o<t;){let l=o,a=de[o++]==2;for(;o<t&&a==(de[o]==2);)o++;s.push(new nn(l,o,a?1:2))}return s}function Vc(i){return[new nn(0,i,0)]}var Nc="";function ig(i,e,t,n,r){var s;let o=n.head-i.from,l=-1;if(o==0){if(!r||!i.length)return null;e[0].level!=t&&(o=e[0].side(!1,t),l=0)}else if(o==i.length){if(r)return null;let f=e[e.length-1];f.level!=t&&(o=f.side(!0,t),l=e.length-1)}l<0&&(l=nn.find(e,o,(s=n.bidiLevel)!==null&&s!==void 0?s:-1,n.assoc));let a=e[l];o==a.side(r,t)&&(a=e[l+=r?1:-1],o=a.side(!r,t));let u=r==(a.dir==t),h=We(i.text,o,u);if(Nc=i.text.slice(Math.min(o,h),Math.max(o,h)),h!=a.side(r,t))return E.cursor(h+i.from,u?-1:1,a.level);let c=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];return!c&&a.level!=t?E.cursor(r?i.to:i.from,r?-1:1,t):c&&c.level<a.level?E.cursor(c.side(!r,t)+i.from,r?1:-1,c.level):E.cursor(h+i.from,r?-1:1,a.level)}var tn="\uFFFF",Ts=class{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(J.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=tn}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r),this.readNode(r);let s=r.nextSibling;if(s==t)break;let o=te.get(r),l=te.get(s);(o&&l?o.breakAfter:(o?o.breakAfter:Hh(r))||Hh(s)&&(r.nodeName!="BR"||r.cmIgnore))&&this.lineBreak(),r=s}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,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(l=r.exec(t))&&(s=l.index,o=l[0].length),this.append(t.slice(n,s<0?t.length:s)),s<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=s+o}}readNode(e){if(e.cmIgnore)return;let t=te.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let r=n.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.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 Hh(i){return i.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}var Rs=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},As=class extends te{constructor(e){super(),this.view=e,this.compositionDeco=oe.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 De],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new it(0,0,0,e.state.doc.length)],0)}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=oe.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=sg(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,r=this.updateDeco(),s=lg(n,r,e.changes);return t=it.extendWithRanges(t,s),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 s=W.chrome||W.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,s),this.dirty=0,s&&(s.written||n.selectionRange.focusNode!=s.node)&&(this.forceSelection=!0),this.dom.style.height=""});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.children)s instanceof Nt&&s.widget instanceof Ds&&r.push(s.dom);n.updateGaps(r)}updateChildren(e,t){let n=this.childCursor(t);for(let r=e.length-1;;r--){let s=r>=0?e[r]:null;if(!s)break;let{fromA:o,toA:l,fromB:a,toB:u}=s,{content:h,breakAtStart:c,openStart:f,openEnd:p}=pr.build(this.view.state.doc,a,u,this.decorations,this.dynamicDecorationMap),{i:m,off:b}=n.findPos(l,1),{i:w,off:v}=n.findPos(o,-1);pc(this,w,v,m,b,h,c,f,p)}}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 r=this.view.state.selection.main,s=this.domAtPos(r.anchor),o=r.empty?s:this.domAtPos(r.head);if(W.gecko&&r.empty&&rg(s)){let a=document.createTextNode("");this.view.observer.ignore(()=>s.node.insertBefore(a,s.node.childNodes[s.offset]||null)),s=o=new Re(a,0),n=!0}let l=this.view.observer.selectionRange;(n||!l.focusNode||!Cs(s.node,s.offset,l.anchorNode,l.anchorOffset)||!Cs(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{W.android&&W.chrome&&this.dom.contains(l.focusNode)&&ag(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let a=vs(this.view.root);if(a)if(r.empty){if(W.gecko){let u=og(s.node,s.offset);if(u&&u!=3){let h=Fc(s.node,s.offset,u==1?1:-1);h&&(s=new Re(h,u==1?0:h.nodeValue.length))}}a.collapse(s.node,s.offset),r.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=r.bidiLevel)}else if(a.extend){a.collapse(s.node,s.offset);try{a.extend(o.node,o.offset)}catch{}}else{let u=document.createRange();r.anchor>r.head&&([s,o]=[o,s]),u.setEnd(o.node,o.offset),u.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(u)}}),this.view.observer.setSelectionRange(s,o)),this.impreciseAnchor=s.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=vs(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=De.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(r,s)}mayControlSelection(){let e=this.view.root.activeElement;return e==this.dom||gs(this.dom,this.view.observer.selectionRange)&&!(e&&this.dom.contains(e))}nearest(e){for(let t=e;t;){let n=te.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 r=this.children[t];if(n<r.length||r instanceof De)break;t++,n=0}return this.children[t].domAtPos(n)}coordsAt(e,t){for(let n=this.length,r=this.children.length-1;;r--){let s=this.children[r],o=n-s.breakAfter-s.length;if(e>o||e==o&&s.type!=se.WidgetBefore&&s.type!=se.WidgetAfter&&(!r||t==2||this.children[r-1].breakAfter||this.children[r-1].type==se.WidgetBefore&&t>-2))return s.coordsAt(e-o,t);n=o}}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==we.LTR;for(let u=0,h=0;h<this.children.length;h++){let c=this.children[h],f=u+c.length;if(f>r)break;if(u>=n){let p=c.dom.getBoundingClientRect();if(t.push(p.height),o){let m=c.dom.lastChild,b=m?fr(m):[];if(b.length){let w=b[b.length-1],v=a?w.right-p.left:p.right-w.left;v>l&&(l=v,this.minWidth=s,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"?we.RTL:we.LTR}measureTextSize(){for(let r of this.children)if(r instanceof De){let s=r.measureTextSize();if(s)return s}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 r=fr(e.firstChild)[0];t=e.getBoundingClientRect().height,n=r?r.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 xs(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.length;if(o>n){let l=t.lineBlockAt(o).bottom-t.lineBlockAt(n).top;e.push(oe.replace({widget:new Ds(l),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!s)break;n=s.to+1}return oe.set(e)}updateDeco(){let e=this.view.state.facet(mr).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),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let s=0,o=0,l=0,a=0;for(let h of this.view.state.facet(Ic).map(c=>c(this.view)))if(h){let{left:c,right:f,top:p,bottom:m}=h;c!=null&&(s=Math.max(s,c)),f!=null&&(o=Math.max(o,f)),p!=null&&(l=Math.max(l,p)),m!=null&&(a=Math.max(a,m))}let u={left:n.left-s,top:n.top-l,right:n.right+o,bottom:n.bottom+a};zm(this.view.scrollDOM,u,t.head<t.anchor?-1:1,e.x,e.y,e.xMargin,e.yMargin,this.view.textDirection==we.LTR)}};function rg(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 Ds=class extends Ft{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 Bc(i){let e=i.observer.selectionRange,t=e.focusNode&&Fc(e.focusNode,e.focusOffset,0);if(!t)return null;let n=i.docView.nearest(t);if(!n)return null;if(n instanceof De){let r=t;for(;r.parentNode!=n.dom;)r=r.parentNode;let s=r.previousSibling;for(;s&&!te.get(s);)s=s.previousSibling;let o=s?te.get(s).posAtEnd:n.posAtStart;return{from:o,to:o,node:r,text:t}}else{for(;;){let{parent:s}=n;if(!s)return null;if(s instanceof De)break;n=s}let r=n.posAtStart;return{from:r,to:r+n.length,node:n.dom,text:t}}}function sg(i,e){let t=Bc(i);if(!t)return oe.none;let{from:n,to:r,node:s,text:o}=t,l=e.mapPos(n,1),a=Math.max(l,e.mapPos(r,-1)),{state:u}=i,h=s.nodeType==3?s.nodeValue:new Ts([],u).readRange(s.firstChild,null).text;if(a-l<h.length)if(u.doc.sliceString(l,Math.min(u.doc.length,l+h.length),tn)==h)a=l+h.length;else if(u.doc.sliceString(Math.max(0,a-h.length),a,tn)==h)l=a-h.length;else return oe.none;else if(u.doc.sliceString(l,a,tn)!=h)return oe.none;let c=te.get(s);return c instanceof ks?c=c.widget.topView:c&&(c.parent=null),oe.set(oe.replace({widget:new dl(s,o,c),inclusive:!0}).range(l,a))}var dl=class extends Ft{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 ks}};function Fc(i,e,t){for(;;){if(i.nodeType==3)return i;if(i.nodeType==1&&e>0&&t<=0)i=i.childNodes[e-1],e=dr(i);else if(i.nodeType==1&&e<i.childNodes.length&&t>=0)i=i.childNodes[e],e=0;else return null}}function og(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 pl=class{constructor(){this.changes=[]}compareRange(e,t){ul(e,t,this.changes)}comparePoint(e,t){ul(e,t,this.changes)}};function lg(i,e,t){let n=new pl;return le.compare(i,e,t,n),n.changes}function ag(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 ug(i,e,t=1){let n=i.charCategorizer(e),r=i.doc.lineAt(e),s=e-r.from;if(r.length==0)return E.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,l=s;t<0?o=We(r.text,s,!1):l=We(r.text,s);let a=n(r.text.slice(o,l));for(;o>0;){let u=We(r.text,o,!1);if(n(r.text.slice(u,o))!=a)break;o=u}for(;l<r.length;){let u=We(r.text,l);if(n(r.text.slice(l,u))!=a)break;l=u}return E.range(o+r.from,l+r.from)}function hg(i,e){return e.left>i?e.left-i:Math.max(0,i-e.right)}function cg(i,e){return e.top>i?e.top-i:Math.max(0,i-e.bottom)}function Xo(i,e){return i.top<e.bottom-1&&i.bottom>e.top+1}function Wh(i,e){return e<i.top?{top:e,left:i.left,right:i.right,bottom:i.bottom}:i}function _h(i,e){return e>i.bottom?{top:i.top,left:i.left,right:i.right,bottom:e}:i}function ml(i,e,t){let n,r,s,o,l=!1,a,u,h,c;for(let m=i.firstChild;m;m=m.nextSibling){let b=fr(m);for(let w=0;w<b.length;w++){let v=b[w];r&&Xo(r,v)&&(v=Wh(_h(v,r.bottom),r.top));let A=hg(e,v),C=cg(t,v);if(A==0&&C==0)return m.nodeType==3?zh(m,e,t):ml(m,e,t);if(!n||o>C||o==C&&s>A){n=m,r=v,s=A,o=C;let k=C?t<v.top?-1:1:A?e<v.left?-1:1:0;l=!k||(k>0?w<b.length-1:w>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&&Xo(h,v)?h=_h(h,v.bottom):c&&Xo(c,v)&&(c=Wh(c,v.top))}}if(h&&h.bottom>=t?(n=a,r=h):c&&c.top<=t&&(n=u,r=c),!n)return{node:i,offset:0};let f=Math.max(r.left,Math.min(r.right,e));if(n.nodeType==3)return zh(n,f,t);if(l&&n.contentEditable!="false")return ml(n,f,t);let p=Array.prototype.indexOf.call(i.childNodes,n)+(e>=(r.left+r.right)/2?1:0);return{node:i,offset:p}}function zh(i,e,t){let n=i.nodeValue.length,r=-1,s=1e9,o=0;for(let l=0;l<n;l++){let a=Si(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<s){let f=e>=(h.left+h.right)/2,p=f;if((W.chrome||W.gecko)&&Si(i,l).getBoundingClientRect().left==h.right&&(p=!f),c<=0)return{node:i,offset:l+(p?1:0)};r=l+(p?1:0),s=c}}}return{node:i,offset:r>-1?r:o>0?i.nodeValue.length:0}}function Hc(i,e,t,n=-1){var r;let s=i.contentDOM.getBoundingClientRect(),o=s.top+i.viewState.paddingTop,l,{docHeight:a}=i.viewState,{x:u,y:h}=e,c=h-o;if(c<0)return 0;if(c>a)return i.state.doc.length;for(let C=i.defaultLineHeight/2,k=!1;l=i.elementAtHeight(c),l.type!=se.Text;)for(;c=n>0?l.bottom+C:l.top-C,!(c>=0&&c<=a);){if(k)return t?null:0;k=!0,n=-n}h=o+c;let f=l.from;if(f<i.viewport.from)return i.viewport.from==0?0:t?null:Uh(i,s,l,u,h);if(f>i.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:t?null:Uh(i,s,l,u,h);let p=i.dom.ownerDocument,m=i.root.elementFromPoint?i.root:p,b=m.elementFromPoint(u,h);b&&!i.contentDOM.contains(b)&&(b=null),b||(u=Math.max(s.left+1,Math.min(s.right-1,u)),b=m.elementFromPoint(u,h),b&&!i.contentDOM.contains(b)&&(b=null));let w,v=-1;if(b&&((r=i.docView.nearest(b))===null||r===void 0?void 0:r.isEditable)!=!1){if(p.caretPositionFromPoint){let C=p.caretPositionFromPoint(u,h);C&&({offsetNode:w,offset:v}=C)}else if(p.caretRangeFromPoint){let C=p.caretRangeFromPoint(u,h);C&&({startContainer:w,startOffset:v}=C,(!i.contentDOM.contains(w)||W.safari&&fg(w,v,u)||W.chrome&&dg(w,v,u))&&(w=void 0))}}if(!w||!i.docView.dom.contains(w)){let C=De.find(i.docView,f);if(!C)return c>l.top+l.height/2?l.to:l.from;({node:w,offset:v}=ml(C.dom,u,h))}let A=i.docView.nearest(w);if(!A)return null;if(A.isWidget){let C=A.dom.getBoundingClientRect();return e.y<C.top||e.y<=C.bottom&&e.x<=(C.left+C.right)/2?A.posAtStart:A.posAtEnd}else return A.localPosFromDOM(w,v)+A.posAtStart}function Uh(i,e,t,n,r){let s=Math.round((n-e.left)*i.defaultCharacterWidth);if(i.lineWrapping&&t.height>i.defaultLineHeight*1.5){let l=Math.floor((r-t.top)/i.defaultLineHeight);s+=l*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+Rh(o,s,i.state.tabSize)}function fg(i,e,t){let n;if(i.nodeType!=3||e!=(n=i.nodeValue.length))return!1;for(let r=i.nextSibling;r;r=r.nextSibling)if(r.nodeType!=1||r.nodeName!="BR")return!1;return Si(i,n-1,n).getBoundingClientRect().left>t}function dg(i,e,t){if(e!=0)return!1;for(let r=i;;){let s=r.parentNode;if(!s||s.nodeType!=1||s.firstChild!=r)return!1;if(s.classList.contains("cm-line"))break;r=s}let n=i.nodeType==1?i.getBoundingClientRect():Si(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return t-n.left>5}function pg(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=!n||!i.lineWrapping?null:i.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let a=i.dom.getBoundingClientRect(),u=i.textDirectionAt(r.from),h=i.posAtCoords({x:t==(u==we.LTR)?a.right-1:a.left+1,y:(s.top+s.bottom)/2});if(h!=null)return E.cursor(h,t?-1:1)}let o=De.find(i.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?r.to:r.from;return E.cursor(l,t?-1:1)}function Kh(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=i.bidiSpans(r),o=i.textDirectionAt(r.from);for(let l=e,a=null;;){let u=ig(r,s,o,l,t),h=Nc;if(!u){if(r.number==(t?i.state.doc.lines:1))return l;h=`
8
- `,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),u=E.cursor(t?r.from:r.to)}if(a){if(!a(h))return l}else{if(!n)return u;a=n(h)}l=u}}function mg(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==dt.Space&&(r=o),r==o}}function gg(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return E.cursor(r,e.assoc);let o=e.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),u=i.coordsAtPos(r),h=i.documentTop;if(u)o==null&&(o=u.left-a.left),l=s<0?u.top:u.bottom;else{let p=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(r-p.from))),l=(s<0?p.top:p.bottom)+h}let c=a.left+o,f=n!=null?n:i.defaultLineHeight>>1;for(let p=0;;p+=10){let m=l+(f+p)*s,b=Hc(i,{x:c,y:m},!1,s);if(m<a.top||m>a.bottom||(s<0?b<r:b>r))return E.cursor(b,e.assoc,void 0,o)}}function Yo(i,e,t){let n=i.state.facet(Oc).map(r=>r(i));for(;;){let r=!1;for(let s of n)s.between(t.from-1,t.from+1,(o,l,a)=>{t.from>o&&t.from<l&&(t=e.head>t.from?E.cursor(o,1):E.cursor(l,-1),r=!0)});if(!r)return t}}var gl=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;let t=(n,r)=>{this.ignoreDuringComposition(r)||r.type=="keydown"&&this.keydown(e,r)||(this.mustFlushObserver(r)&&e.observer.forceFlush(),this.runCustomHandlers(r.type,e,r)?r.preventDefault():n(e,r))};for(let n in Se){let r=Se[n];e.contentDOM.addEventListener(n,s=>{$h(e,s)&&t(r,s)},yl[n]),this.registeredEvents.push(n)}e.scrollDOM.addEventListener("mousedown",n=>{n.target==e.scrollDOM&&n.clientY>e.contentDOM.getBoundingClientRect().bottom&&t(Se.mousedown,n)}),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 r;this.customHandlers=[];for(let s of t)if(r=(n=s.update(e).spec)===null||n===void 0?void 0:n.domEventHandlers){this.customHandlers.push({plugin:s.value,handlers:r});for(let o in r)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{$h(e,l)&&this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,n){for(let r of this.customHandlers){let s=r.handlers[e];if(s)try{if(s.call(r.plugin,n,t)||n.defaultPrevented)return!0}catch(o){Bt(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 r=n.handlers.scroll;if(r)try{r.call(n.plugin,t,e)}catch(s){Bt(e.state,s)}}}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=Wc.find(r=>r.keyCode==t.keyCode))&&!t.ctrlKey||bg.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,vi(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()}},Wc=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],bg="dthko",_c=[16,17,18,20,91,92,224,225];function cs(i){return i*.7+8}var bl=class{constructor(e,t,n,r){this.view=e,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=Um(e.contentDOM);let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(J.allowMultipleSelections)&&yg(e,t),this.dragMove=wg(e,t),this.dragging=vg(e,t)&&$c(t)==1?null:!1}start(e){this.dragging===!1&&(e.preventDefault(),this.select(e))}move(e){var t;if(e.buttons==0)return this.destroy();if(this.dragging!==!1)return;this.select(this.lastEvent=e);let n=0,r=0,s=((t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight};e.clientX<=s.left?n=-cs(s.left-e.clientX):e.clientX>=s.right&&(n=cs(e.clientX-s.right)),e.clientY<=s.top?r=-cs(s.top-e.clientY):e.clientY>=s.bottom&&(r=cs(e.clientY-s.bottom)),this.setScrollSpeed(n,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}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"}),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 yg(i,e){let t=i.state.facet(xc);return t.length?t[0](e):W.mac?e.metaKey:e.ctrlKey}function wg(i,e){let t=i.state.facet(kc);return t.length?t[0](e):W.mac?!e.altKey:!e.ctrlKey}function vg(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=vs(i.root);if(!n||n.rangeCount==0)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let o=r[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function $h(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=te.get(t))&&n.ignoreEvent(e))return!1;return!0}var Se=Object.create(null),yl=Object.create(null),zc=W.ie&&W.ie_version<15||W.ios&&W.webkit_version<604;function Cg(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(),Uc(i,t.value)},50)}function Uc(i,e){let{state:t}=i,n,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(wl!=null&&t.selection.ranges.every(a=>a.empty)&&wl==s.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?s.line(r++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:c},range:E.cursor(u.from+c.length)}})}else o?n=t.changeByRange(a=>{let u=s.line(r++);return{changes:{from:a.from,to:a.to,insert:u.text},range:E.cursor(a.from+u.length)}}):n=t.replaceSelection(s);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}Se.keydown=(i,e)=>{i.inputState.setSelectionOrigin("select"),e.keyCode==27?i.inputState.lastEscPress=Date.now():_c.indexOf(e.keyCode)<0&&(i.inputState.lastEscPress=0)};Se.touchstart=(i,e)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin("select.pointer")};Se.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};yl.touchstart=yl.touchmove={passive:!0};Se.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let n of i.state.facet(Mc))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=kg(i,e)),t){let n=i.root.activeElement!=i.contentDOM;i.inputState.startMouseSelection(new bl(i,e,t,n)),n&&i.observer.ignore(()=>fc(i.contentDOM)),i.inputState.mouseSelection&&i.inputState.mouseSelection.start(e)}};function Gh(i,e,t,n){if(n==1)return E.cursor(e,t);if(n==2)return ug(i.state,e,t);{let r=De.find(i.docView,e),s=i.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,l=r?r.posAtEnd:s.to;return l<i.state.doc.length&&l==s.to&&l++,E.range(o,l)}}var Kc=(i,e)=>i>=e.top&&i<=e.bottom,qh=(i,e,t)=>Kc(e,t)&&i>=t.left&&i<=t.right;function Sg(i,e,t,n){let r=De.find(i.docView,e);if(!r)return 1;let s=e-r.posAtStart;if(s==0)return 1;if(s==r.length)return-1;let o=r.coordsAt(s,-1);if(o&&qh(t,n,o))return-1;let l=r.coordsAt(s,1);return l&&qh(t,n,l)?1:o&&Kc(n,o)?-1:1}function jh(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Sg(i,t,e.clientX,e.clientY)}}var xg=W.ie&&W.ie_version<=11,Qh=null,Jh=0,Xh=0;function $c(i){if(!xg)return i.detail;let e=Qh,t=Xh;return Qh=i,Xh=Date.now(),Jh=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(Jh+1)%3:1}function kg(i,e){let t=jh(i,e),n=$c(e),r=i.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,l){let a=jh(i,s),u=Gh(i,a.pos,a.bias,n);if(t.pos!=a.pos&&!o){let h=Gh(i,t.pos,t.bias,n),c=Math.min(h.from,u.from),f=Math.max(h.to,u.to);u=c<u.from?E.range(c,f):E.range(f,c)}return o?r.replaceRange(r.main.extend(u.from,u.to)):l&&r.ranges.length>1&&r.ranges.some(h=>h.eq(u))?Mg(r,u):l?r.addRange(u):E.create([u])}}}function Mg(i,e){for(let t=0;;t++)if(i.ranges[t].eq(e))return E.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}Se.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 Yh(i,e,t,n){if(!t)return;let r=i.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:s}=i.inputState,o=n&&s&&s.dragging&&s.dragMove?{from:s.dragging.from,to:s.dragging.to}:null,l={from:r,insert:t},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"})}Se.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),r=0,s=()=>{++r==t.length&&Yh(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=s,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(n[o]=l.result),s()},l.readAsText(t[o])}}else Yh(i,e,e.dataTransfer.getData("Text"),!0)};Se.paste=(i,e)=>{if(i.state.readOnly)return e.preventDefault();i.observer.flush();let t=zc?null:e.clipboardData;t?(Uc(i,t.getData("text/plain")),e.preventDefault()):Cg(i)};function Tg(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 Rg(i){let e=[],t=[],n=!1;for(let r of i.selection.ranges)r.empty||(e.push(i.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),r=o.number}n=!0}return{text:e.join(i.lineBreak),ranges:t,linewise:n}}var wl=null;Se.copy=Se.cut=(i,e)=>{let{text:t,ranges:n,linewise:r}=Rg(i.state);if(!t&&!r)return;wl=r?t:null;let s=zc?null:e.clipboardData;s?(e.preventDefault(),s.clearData(),s.setData("text/plain",t)):Tg(i,t),e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"})};var Gc=tt.define();function qc(i,e){let t=[];for(let n of i.facet(Ac)){let r=n(i,e);r&&t.push(r)}return t?i.update({effects:t,annotations:Gc.of(!0)}):null}function jc(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=qc(i.state,e);t?i.dispatch(t):i.update([])}},10)}Se.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),jc(i)};Se.blur=i=>{i.observer.clearSelectionRange(),jc(i)};Se.compositionstart=Se.compositionupdate=i=>{i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0)};Se.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)};Se.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};Se.beforeinput=(i,e)=>{var t;let n;if(W.chrome&&W.android&&(n=Wc.find(r=>r.inputType==e.inputType))&&(i.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var s;(((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0)>r+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}};var Zh=["pre-wrap","normal","pre-line","break-spaces"],vl=class{constructor(e){this.lineWrapping=e,this.doc=Q.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.max(0,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 Zh.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,s){let o=Zh.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=r,l){this.heightSamples={};for(let a=0;a<s.length;a++){let u=s[a];u<0?a++:this.heightSamples[Math.floor(u*10)]=!0}}return l}},Cl=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},pt=class{constructor(e,t,n,r,s){this.from=e,this.length=t,this.top=n,this.height=r,this.type=s}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 pt(this.from,this.length+e.length,this.top,this.height+e.height,t)}},re=function(i){return i[i.ByPos=0]="ByPos",i[i.ByHeight=1]="ByHeight",i[i.ByPosNoHeight=2]="ByPosNoHeight",i}(re||(re={})),bs=.001,Ee=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)>bs&&(e.heightChanged=!0),this.height=t)}replace(e,t,n){return Ee.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let s=this,o=n.doc;for(let l=r.length-1;l>=0;l--){let{fromA:a,toA:u,fromB:h,toB:c}=r[l],f=s.lineAt(a,re.ByPosNoHeight,n.setDoc(t),0,0),p=f.to>=u?f:s.lineAt(u,re.ByPosNoHeight,n,0,0);for(c+=p.to-u,u=p.to;l>0&&f.from<=r[l-1].toA;)a=r[l-1].fromA,h=r[l-1].fromB,l--,a<f.from&&(f=s.lineAt(a,re.ByPosNoHeight,n,0,0));h+=f.from-a,a=f.from;let m=gr.build(n.setDoc(o),e,h,c);s=s.replace(a,u,m)}return s.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,r=0,s=0;for(;;)if(t==n)if(r>s*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,r-=l.size}else if(s>r*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,s-=l.size}else break;else if(r<s){let l=e[t++];l&&(r+=l.size)}else{let l=e[--n];l&&(s+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,n++),new Sl(Ee.of(e.slice(0,t)),o,Ee.of(e.slice(n)))}};Ee.prototype.size=1;var Es=class extends Ee{constructor(e,t,n){super(e,t),this.type=n}blockAt(e,t,n,r){return new pt(r,this.length,n,this.height,this.type)}lineAt(e,t,n,r,s){return this.blockAt(0,n,r,s)}forEachLine(e,t,n,r,s,o){e<=s+this.length&&t>=s&&o(this.blockAt(0,n,r,s))}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setHeight(e,r.heights[r.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},_e=class extends Es{constructor(e,t){super(e,t,se.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,n){let r=n[0];return n.length==1&&(r instanceof _e||r instanceof Ce&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof Ce?r=new _e(r.length,this.height):r.height=this.height,this.outdated||(r.outdated=!1),r):Ee.of(n)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setHeight(e,r.heights[r.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:""})`}},Ce=class extends Ee{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*s);o=a/s,l=(this.height-a)/(this.length-s-1)}else o=this.height/s;return{firstLine:n,lastLine:r,perLine:o,perChar:l}}blockAt(e,t,n,r){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let u=r+Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length),h=t.doc.lineAt(u),c=l+h.length*a,f=Math.max(n,e-c/2);return new pt(h.from,h.length,f,c,se.Text)}else{let u=Math.max(0,Math.min(o-s,Math.floor((e-n)/l))),{from:h,length:c}=t.doc.line(s+u);return new pt(h,c,n+l*u,l,se.Text)}}lineAt(e,t,n,r,s){if(t==re.ByHeight)return this.blockAt(e,n,r,s);if(t==re.ByPosNoHeight){let{from:p,to:m}=n.doc.lineAt(e);return new pt(p,m-p,0,0,se.Text)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(n,s),u=n.doc.lineAt(e),h=l+u.length*a,c=u.number-o,f=r+l*c+a*(u.from-s-c);return new pt(u.from,u.length,Math.max(r,Math.min(f,r+this.height-h)),h,se.Text)}forEachLine(e,t,n,r,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:l,perLine:a,perChar:u}=this.heightMetrics(n,s);for(let h=e,c=r;h<=t;){let f=n.doc.lineAt(h);if(h==e){let m=f.number-l;c+=a*m+u*(e-s-m)}let p=a+u*f.length;o(new pt(f.from,f.length,c,p,se.Text)),c+=p,h=f.to+1}}replace(e,t,n){let r=this.length-t;if(r>0){let s=n[n.length-1];s instanceof Ce?n[n.length-1]=new Ce(s.length+r):n.push(null,new Ce(r-1))}if(e>0){let s=n[0];s instanceof Ce?n[0]=new Ce(e+s.length):n.unshift(new Ce(e-1),null)}return Ee.of(n)}decomposeLeft(e,t){t.push(new Ce(e-1),null)}decomposeRight(e,t){t.push(null,new Ce(this.length-e-1))}updateHeight(e,t=0,n=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],l=Math.max(t,r.from),a=-1;for(r.from>t&&o.push(new Ce(r.from-t-1).updateHeight(e,t));l<=s&&r.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let c=r.heights[r.index++];a==-1?a=c:Math.abs(c-a)>=bs&&(a=-2);let f=new _e(h,c);f.outdated=!1,o.push(f),l+=h+1}l<=s&&o.push(null,new Ce(s-l).updateHeight(e,l));let u=Ee.of(o);return(a<0||Math.abs(u.height-this.height)>=bs||Math.abs(a-this.heightMetrics(e,t).perLine)>=bs)&&(e.heightChanged=!0),u}else(n||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Sl=class extends Ee{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,r){let s=n+this.left.height;return e<s?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,s,r+this.left.length+this.break)}lineAt(e,t,n,r,s){let o=r+this.left.height,l=s+this.left.length+this.break,a=t==re.ByHeight?e<o:e<l,u=a?this.left.lineAt(e,t,n,r,s):this.right.lineAt(e,t,n,o,l);if(this.break||(a?u.to<l:u.from>l))return u;let h=t==re.ByPosNoHeight?re.ByPosNoHeight:re.ByPos;return a?u.join(this.right.lineAt(l,h,n,o,l)):this.left.lineAt(l,h,n,r,s).join(u)}forEachLine(e,t,n,r,s,o){let l=r+this.left.height,a=s+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,n,r,s,o),t>=a&&this.right.forEachLine(e,t,n,l,a,o);else{let u=this.lineAt(a,re.ByPos,n,r,s);e<u.from&&this.left.forEachLine(e,u.from-1,n,r,s,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 r=this.left.length+this.break;if(t<r)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-r,t-r,n));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of n)s.push(l);if(e>0&&ec(s,o-1),t<this.length){let l=s.length;this.decomposeRight(t,s),ec(s,l)}return Ee.of(s)}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,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Ee.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,r){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return r&&r.from<=t+s.length&&r.more?a=s=s.updateHeight(e,t,n,r):s.updateHeight(e,t,n),r&&r.from<=l+o.length&&r.more?a=o=o.updateHeight(e,l,n,r):o.updateHeight(e,l,n),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function ec(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof Ce&&(n=i[e+1])instanceof Ce&&i.splice(e-1,3,new Ce(t.length+1+n.length))}var Ag=5,gr=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),r=this.nodes[this.nodes.length-1];r instanceof _e?r.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 r=n.widget?n.widget.estimatedHeight:0;r<0&&(r=this.oracle.lineHeight);let s=t-e;n.block?this.addBlock(new Es(s,r,n.type)):(s||r>=Ag)&&this.addLineDeco(r,s)}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 Ce(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==se.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=se.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 r of this.nodes)r instanceof _e&&r.updateHeight(this.oracle,n),n+=r?r.length:1;return this.nodes}static build(e,t,n,r){let s=new gr(n,e);return le.spans(t,n,r,s,0),s.finish(n)}};function Dg(i,e,t){let n=new xl;return le.compare(i,e,t,n,0),n.changes}var xl=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&ul(e,t,this.changes,5)}};function Eg(i,e){let t=i.getBoundingClientRect(),n=i.ownerDocument,r=n.defaultView||window,s=Math.max(0,t.left),o=Math.min(r.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(r.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();s=Math.max(s,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:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Pg(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var cr=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 r=e[n],s=t[n];if(r.from!=s.from||r.to!=s.to||r.size!=s.size)return!1}return!0}draw(e){return oe.replace({widget:new kl(this.size,e)}).range(this.from,this.to)}},kl=class extends Ft{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}},Ps=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=tc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=we.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(Hl).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new vl(t),this.stateDeco=e.facet(mr).filter(n=>typeof n!="function"),this.heightMap=Ee.empty().applyChanges(this.stateDeco,Q.empty,this.heightOracle.setDoc(e.doc),[new it(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=oe.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 r=n?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new wi(s,o))}}this.viewports=e.sort((n,r)=>n.from-r.from),this.scaler=this.heightMap.height<=7e6?tc:new Ml(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:ur(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(mr).filter(u=>typeof u!="function");let r=e.changedRanges,s=it.extendWithRanges(r,Dg(n,this.stateDeco,e?e.changes:ce.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),s),this.heightMap.height!=o&&(e.flags|=2);let l=s.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(Ec)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,s=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?we.RTL:we.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let u=0,h=0,c=parseInt(n.paddingTop)||0,f=parseInt(n.paddingBottom)||0;(this.paddingTop!=c||this.paddingBottom!=f)&&(this.paddingTop=c,this.paddingBottom=f,u|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=8);let p=(this.printing?Pg:Eg)(t,this.paddingTop),m=p.top-this.pixelViewport.top,b=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,u|=8),a){let C=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(C)&&(o=!0),o||r.lineWrapping&&Math.abs(v-this.contentDOMWidth)>r.charWidth){let{lineHeight:k,charWidth:M}=e.docView.measureTextSize();o=k>0&&r.refresh(s,k,M,v/M,C),o&&(e.docView.minWidth=0,u|=8)}m>0&&b>0?h=Math.max(m,b):m<0&&b<0&&(h=Math.min(m,b)),r.heightChanged=!1;for(let k of this.viewports){let M=k.from==this.viewport.from?C:e.docView.measureVisibleLineHeights(k);this.heightMap=(o?Ee.empty().applyChanges(this.stateDeco,Q.empty,this.heightOracle,[new it(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new Cl(k.from,M))}r.heightChanged&&(u|=2)}let A=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return A&&(this.viewport=this.getViewport(h,this.scrollTarget)),this.updateForViewport(),(u&2||A)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}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)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new wi(r.lineAt(o-n*1e3,re.ByHeight,s,0,0).from,r.lineAt(l+(1-n)*1e3,re.ByHeight,s,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=r.lineAt(u,re.ByPos,s,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 wi(r.lineAt(f-1e3/2,re.ByHeight,s,0,0).from,r.lineAt(f+h+1e3/2,re.ByHeight,s,0,0).to)}}return a}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new wi(this.heightMap.lineAt(n,re.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,re.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,re.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,re.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||r<=o-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||s>=l+Math.max(10,Math.min(n,250)))&&r>o-2*1e3&&s<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new cr(t.mapPos(r.from),t.mapPos(r.to),r.size));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,s=r>>1,o=r<<1;if(this.defaultTextDirection!=we.LTR&&!n)return[];let l=[],a=(u,h,c,f)=>{if(h-u<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let w of m)if(w>u&&w<h){a(u,w-10,c,f),a(w+10,h,c,f);return}let b=Ig(e,w=>w.from>=c.from&&w.to<=c.to&&Math.abs(w.from-u)<s&&Math.abs(w.to-h)<s&&!m.some(v=>w.from<v&&w.to>v));if(!b){if(h<c.to&&t&&n&&t.visibleRanges.some(w=>w.from<=h&&w.to>=h)){let w=t.moveToLineBoundary(E.cursor(h),!1,!0).head;w>u&&(h=w)}b=new cr(u,h,this.gapSize(c,u,h,f))}l.push(b)};for(let u of this.viewportLines){if(u.length<o)continue;let h=Og(u.from,u.to,this.stateDeco);if(h.total<o)continue;let c=this.scrollTarget?this.scrollTarget.range.head:null,f,p;if(n){let m=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,w;if(c!=null){let v=ds(h,c),A=((this.visibleBottom-this.visibleTop)/2+m)/u.height;b=v-A,w=v+A}else b=(this.visibleTop-u.top-m)/u.height,w=(this.visibleBottom-u.top+m)/u.height;f=fs(h,b),p=fs(h,w)}else{let m=h.total*this.heightOracle.charWidth,b=r*this.heightOracle.charWidth,w,v;if(c!=null){let A=ds(h,c),C=((this.pixelViewport.right-this.pixelViewport.left)/2+b)/m;w=A-C,v=A+C}else w=(this.pixelViewport.left-b)/m,v=(this.pixelViewport.right+b)/m;f=fs(h,w),p=fs(h,v)}f>u.from&&a(u.from,f,u,h),p<u.to&&a(p,u.to,u,h)}return l}gapSize(e,t,n,r){let s=ds(r,n)-ds(r,t);return this.heightOracle.lineWrapping?e.height*s:r.total*this.heightOracle.charWidth*s}updateLineGaps(e){cr.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=oe.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(r,s){t.push({from:r,to:s})},point(){}},20);let n=t.length!=this.visibleRanges.length||this.visibleRanges.some((r,s)=>r.from!=t[s].from||r.to!=t[s].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)||ur(this.heightMap.lineAt(e,re.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return ur(this.heightMap.lineAt(this.scaler.fromDOM(e),re.ByHeight,this.heightOracle,0,0),this.scaler)}elementAtHeight(e){return ur(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},wi=class{constructor(e,t){this.from=e,this.to=t}};function Og(i,e,t){let n=[],r=i,s=0;return le.spans(t,i,e,{span(){},point(o,l){o>r&&(n.push({from:r,to:o}),s+=o-r),r=l}},20),r<e&&(n.push({from:r,to:e}),s+=e-r),{total:s,ranges:n}}function fs({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 r=0;;r++){let{from:s,to:o}=e[r],l=o-s;if(n<=l)return s+n;n-=l}}function ds(i,e){let t=0;for(let{from:n,to:r}of i.ranges){if(e<=r){t+=e-n;break}t+=r-n}return t/i.total}function Ig(i,e){for(let t of i)if(e(t))return t}var tc={toDOM(i){return i},fromDOM(i){return i},scale:1},Ml=class{constructor(e,t,n){let r=0,s=0,o=0;this.viewports=n.map(({from:l,to:a})=>{let u=t.lineAt(l,re.ByPos,e,0,0).top,h=t.lineAt(a,re.ByPos,e,0,0).bottom;return r+=h-u,{from:l,to:a,top:u,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return r+(e-n)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);n=s.bottom,r=s.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return n+(e-r)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);n=s.bottom,r=s.domBottom}}};function ur(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new pt(i.from,i.length,t,n-t,Array.isArray(i.type)?i.type.map(r=>ur(r,e)):i.type)}var ps=K.define({combine:i=>i.join(" ")}),Tl=K.define({combine:i=>i.indexOf(!0)>-1}),Rl=nt.newName(),Qc=nt.newName(),Jc=nt.newName(),Xc={"&light":"."+Qc,"&dark":"."+Jc};function Al(i,e,t){return new nt(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,r=>{if(r=="&")return i;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):i+" "+n}})}var Lg=Al("."+Rl,{"&":{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,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-dropCursor":{position:"absolute"},"&.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-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".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"}},Xc),Dl=class{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text="";let{impreciseHead:s,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=s||o?[]:Ng(e),a=new Ts(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Bg(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Ci(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||!Ci(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=E.single(u,a)}}};function Yc(i,e){let t,{newSel:n}=e,r=i.state.selection.main;if(e.bounds){let{from:s,to:o}=e.bounds,l=r.from,a=null;(i.inputState.lastKeyCode===8&&i.inputState.lastKeyTime>Date.now()-100||W.android&&e.text.length<o-s)&&(l=r.to,a="end");let u=Vg(i.state.doc.sliceString(s,o,tn),e.text,l-s,a);u&&(W.chrome&&i.inputState.lastKeyCode==13&&u.toB==u.from+2&&e.text.slice(u.from,u.toB)==tn+tn&&u.toB--,t={from:s+u.from,to:s+u.toA,insert:Q.of(e.text.slice(u.from,u.toB).split(tn))})}else n&&(!i.hasFocus&&i.state.facet(Is)||n.main.eq(r))&&(n=null);if(!t&&!n)return!1;if(!t&&e.typeOver&&!r.empty&&n&&n.main.empty?t={from:r.from,to:r.to,insert:i.state.doc.slice(r.from,r.to)}:t&&t.from>=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:i.state.doc.slice(r.from,t.from).append(t.insert).append(i.state.doc.slice(t.to,r.to))}:(W.mac||W.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=E.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:Q.of([" "])}):W.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
9
- `&&i.lineWrapping&&(n&&(n=E.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:Q.of([" "])}),t){let s=i.state;if(W.ios&&i.inputState.flushIOSKey(i)||W.android&&(t.from==r.from&&t.to==r.to&&t.insert.length==1&&t.insert.lines==2&&vi(i.contentDOM,"Enter",13)||t.from==r.from-1&&t.to==r.to&&t.insert.length==0&&vi(i.contentDOM,"Backspace",8)||t.from==r.from&&t.to==r.to+1&&t.insert.length==0&&vi(i.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();if(i.state.facet(Rc).some(u=>u(i,t.from,t.to,o)))return!0;i.inputState.composing>=0&&i.inputState.composing++;let l;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&i.inputState.composing<0){let u=r.from<t.from?s.sliceDoc(r.from,t.from):"",h=r.to>t.to?s.sliceDoc(t.to,r.to):"";l=s.replaceSelection(i.state.toText(u+t.insert.sliceString(0,void 0,i.state.lineBreak)+h))}else{let u=s.changes(t),h=n&&!s.selection.main.eq(n.main)&&n.main.to<=u.newLength?n.main:void 0;if(s.selection.ranges.length>1&&i.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let c=i.state.sliceDoc(t.from,t.to),f=Bc(i)||i.state.doc.lineAt(r.head),p=r.to-t.to,m=r.to-r.from;l=s.changeByRange(b=>{if(b.from==r.from&&b.to==r.to)return{changes:u,range:h||b.map(u)};let w=b.to-p,v=w-c.length;if(b.to-b.from!=m||i.state.sliceDoc(v,w)!=c||f&&b.to>=f.from&&b.from<=f.to)return{range:b};let A=s.changes({from:v,to:w,insert:t.insert}),C=b.to-r.to;return{changes:A,range:h?E.range(Math.max(0,h.anchor+C),Math.max(0,h.head+C)):b.map(A)}})}else l={changes:u,selection:h&&s.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(r)){let s=!1,o="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(s=!0),o=i.inputState.lastSelectionOrigin),i.dispatch({selection:n,scrollIntoView:s,userEvent:o}),!0}else return!1}function Vg(i,e,t,n){let r=Math.min(i.length,e.length),s=0;for(;s<r&&i.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==r&&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,s-Math.min(o,l));t-=o+a-s}if(o<s&&i.length<e.length){let a=t<=s&&t>=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l<s){let a=t<=s&&t>=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function Ng(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}=i.observer.selectionRange;return t&&(e.push(new Rs(t,n)),(r!=t||s!=n)&&e.push(new Rs(r,s))),e}function Bg(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?E.single(t+e,n+e):null}var Fg={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Zo=W.ie&&W.ie_version<=11,El=class{constructor(e){this.view=e,this.active=!1,this.selectionRange=new tl,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.resizeScroll=null,this.resizeContent=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()}),Zo&&(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.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM),this.resizeContent=new ResizeObserver(()=>this.view.requestMeasure()),this.resizeContent.observe(e.contentDOM)),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,r=this.selectionRange;if(n.state.facet(Is)?n.root.activeElement!=this.dom:!gs(n.dom,r))return;let s=r.anchorNode&&n.docView.nearest(r.anchorNode);if(s&&s.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(W.ie&&W.ie_version<=11||W.android&&W.chrome)&&!n.state.selection.main.empty&&r.focusNode&&Cs(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=W.safari&&e.root.nodeType==11&&Wm(this.dom.ownerDocument)==this.dom&&Hg(this.view)||vs(e.root);if(!t||this.selectionRange.eq(t))return!1;let n=gs(this.dom,t);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&$m(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,Fg),Zo&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Zo&&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 r=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),!this.flush()&&s.force&&vi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!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 s of this.observer.takeRecords())e.push(s);e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!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:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&gs(this.dom,this.selectionRange);return e<0&&!r?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new Dl(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,r=Yc(this.view,t);return this.view.state==n&&this.view.update([]),r}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=nc(t,e.previousSibling||e.target.previousSibling,-1),r=nc(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):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,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect(),(r=this.resizeContent)===null||r===void 0||r.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 nc(i,e,t){for(;e;){let n=te.get(e);if(n&&n.parent==i)return n;let r=e.parentNode;e=r!=i.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function Hg(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,r=e.startOffset,s=e.endContainer,o=e.endOffset,l=i.docView.domAtPos(i.state.selection.main.anchor);return Cs(l.node,l.offset,s,o)&&([n,r,s,o]=[s,o,n,r]),{anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:o}}var q=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: fixed; 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||Km(e.parent)||document,this.viewState=new Ps(e.state||J.create(e)),this.plugins=this.state.facet(lr).map(t=>new hr(t));for(let t of this.plugins)t.update(this);this.observer=new El(this),this.inputState=new gl(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new As(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 fe?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,r,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;e.some(f=>f.annotation(Gc))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=qc(s,o),a||(l=1));let u=this.observer.delayedAndroidKey,h=null;if(u?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(J.phrases)!=this.state.facet(J.phrases))return this.setState(s);r=Mi.create(this,s,e),r.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(c&&(c=c.map(f.changes)),f.scrollIntoView){let{main:p}=f.state.selection;c=new ki(p.empty?p:E.cursor(p.head,p.head>p.anchor?-1:1))}for(let p of f.effects)p.is(Fh)&&(c=p.value)}this.viewState.update(r,c),this.bidiCache=Ti.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(ar)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(ps)!=r.state.facet(ps)&&(this.viewState.mustMeasureContent=!0),(t||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!r.empty)for(let f of this.state.facet(hl))f(r);(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!Yc(this,h)&&u.force&&vi(this.contentDOM,u.key,u.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 Ps(e),this.plugins=e.facet(lr).map(n=>new hr(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView=new As(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(lr),n=e.state.facet(lr);if(t!=n){let r=[];for(let s of n){let o=t.indexOf(s);if(o<0)r.push(new hr(s));else{let l=this.plugins[o];l.mustUpdate=e,r.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r<this.plugins.length;r++)this.plugins[r].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:r,clientHeight:s}=this.scrollDOM,o=r>n-s-4?n:r;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(w=>{try{return w.read(this)}catch(v){return Bt(this.state,v),ic}}),p=Mi.create(this,this.state,[]),m=!1,b=!1;p.flags|=h,t?t.flags|=h:t=p,this.updateState=2,p.empty||(this.updatePlugins(p),this.inputState.update(p),this.updateAttrs(),m=this.docView.update(p));for(let w=0;w<c.length;w++)if(f[w]!=ic)try{let v=c[w];v.write&&v.write(f[w],this)}catch(v){Bt(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 w=this.viewState.lineBlockAt(u.from).top-u.top;(w>1||w<-1)&&(this.scrollDOM.scrollTop+=w,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(hl))l(t)}get themeClasses(){return Rl+" "+(this.state.facet(Tl)?Jc:Qc)+" "+this.state.facet(ps)}updateAttrs(){let e=rc(this,Pc,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Is)?"true":"false",class:"cm-content",style:`${W.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),rc(this,Hl,t);let n=this.observer.ignore(()=>{let r=al(this.contentDOM,this.contentAttrs,t),s=al(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let r of n.effects)if(r.is(q.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(ar),nt.mount(this.root,this.styleModules.concat(Lg).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(this.measureRequests.indexOf(e)>-1)return;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 Yo(this,e,Kh(this,e,t,n))}moveByGroup(e,t){return Yo(this,e,Kh(this,e,t,n=>mg(this,e.head,n)))}moveToLineBoundary(e,t,n=!0){return pg(this,e,t,n)}moveVertically(e,t,n){return Yo(this,e,gg(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(),Hc(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 r=this.state.doc.lineAt(e),s=this.bidiSpans(r),o=s[nn.find(s,e-r.from,-1,t)];return Nl(n,o.dir==we.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(Dc)||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>Wg)return Vc(e.length);let t=this.textDirectionAt(e.from);for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t)return r.order;let n=ng(e.text,t);return this.bidiCache.push(new Ti(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(()=>{fc(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 Fh.of(new ki(typeof e=="number"?E.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return mt.define(()=>({}),{eventHandlers:e})}static theme(e,t){let n=nt.newName(),r=[ps.of(n),ar.of(Al(`.${n}`,e))];return t&&t.dark&&r.push(Tl.of(!0)),r}static baseTheme(e){return mi.lowest(ar.of(Al("."+Rl,e,Xc)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),r=n&&te.get(n)||te.get(e);return((t=r==null?void 0:r.rootView)===null||t===void 0?void 0:t.view)||null}};q.styleModule=ar;q.inputHandler=Rc;q.focusChangeEffect=Ac;q.perLineTextDirection=Dc;q.exceptionSink=Tc;q.updateListener=hl;q.editable=Is;q.mouseSelectionStyle=Mc;q.dragMovesSelection=kc;q.clickAddsSelectionRange=xc;q.decorations=mr;q.atomicRanges=Oc;q.scrollMargins=Ic;q.darkTheme=Tl;q.contentAttributes=Hl;q.editorAttributes=Pc;q.lineWrapping=q.contentAttributes.of({class:"cm-lineWrapping"});q.announce=ae.define();var Wg=4096,ic={},Ti=class{constructor(e,t,n,r){this.from=e,this.to=t,this.dir=n,this.order=r}static update(e,t){if(t.empty)return e;let n=[],r=e.length?e[e.length-1].dir:we.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==r&&!t.touchesRange(o.from,o.to)&&n.push(new Ti(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.order))}return n}};function rc(i,e,t){for(let n=i.state.facet(e),r=n.length-1;r>=0;r--){let s=n[r],o=typeof s=="function"?s(i):s;o&&ll(o,t)}return t}var _g=W.mac?"mac":W.windows?"win":W.linux?"linux":"key";function zg(i,e){let t=i.split(/-(?!$)/),n=t[t.length-1];n=="Space"&&(n=" ");let r,s,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))r=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?l=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return r&&(n="Alt-"+n),s&&(n="Ctrl-"+n),l&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function ms(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 Ug=mi.default(q.domEventHandlers({keydown(i,e){return qg(Kg(e.state),i,e,"editor")}})),yr=K.define({enables:Ug}),sc=new WeakMap;function Kg(i){let e=i.facet(yr),t=sc.get(e);return t||sc.set(e,t=Gg(e.reduce((n,r)=>n.concat(r),[]))),t}var en=null,$g=4e3;function Gg(i,e=_g){let t=Object.create(null),n=Object.create(null),r=(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")},s=(o,l,a,u)=>{var h,c;let f=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(w=>zg(w,e));for(let w=1;w<p.length;w++){let v=p.slice(0,w).join(" ");r(v,!0),f[v]||(f[v]={preventDefault:!0,run:[A=>{let C=en={view:A,prefix:v,scope:o};return setTimeout(()=>{en==C&&(en=null)},$g),!0}]})}let m=p.join(" ");r(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)s(u,a,o.run,o.preventDefault),o.shift&&s(u,"Shift-"+a,o.shift,o.preventDefault)}return t}function qg(i,e,t,n){let r=Ph(e),s=hi(r,0),o=rs(s)==r.length&&r!=" ",l="",a=!1;en&&en.view==t&&en.scope==n&&(l=en.prefix+" ",(a=_c.indexOf(e.keyCode)<0)&&(en=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,p;if(c){if(h(c[l+ms(r,e,!o)]))return!0;if(o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(W.windows&&e.ctrlKey&&e.altKey)&&(f=Vt[e.keyCode])&&f!=r){if(h(c[l+ms(f,e,!0)]))return!0;if(e.shiftKey&&(p=bi[e.keyCode])!=r&&p!=f&&h(c[l+ms(p,e,!1)]))return!0}else if(o&&e.shiftKey&&h(c[l+ms(r,e,!0)]))return!0;if(h(c._any))return!0}return a}var zn=class{constructor(e,t,n,r,s){this.className=e,this.left=t,this.top=n,this.width=r,this.height=s}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!=null&&(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}static forRange(e,t,n){if(n.empty){let r=e.coordsAtPos(n.head,n.assoc||1);if(!r)return[];let s=Zc(e);return[new zn(t,r.left-s.left,r.top-s.top,null,r.bottom-r.top)]}else return jg(e,t,n)}};function Zc(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==we.LTR?e.left:e.right-i.scrollDOM.clientWidth)-i.scrollDOM.scrollLeft,top:e.top-i.scrollDOM.scrollTop}}function oc(i,e,t){let n=E.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:se.Text}}function lc(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==se.Text))return n}return t}function jg(i,e,t){if(t.to<=i.viewport.from||t.from>=i.viewport.to)return[];let n=Math.max(t.from,i.viewport.from),r=Math.min(t.to,i.viewport.to),s=i.textDirection==we.LTR,o=i.contentDOM,l=o.getBoundingClientRect(),a=Zc(i),u=window.getComputedStyle(o.firstChild),h=l.left+parseInt(u.paddingLeft)+Math.min(0,parseInt(u.textIndent)),c=l.right-parseInt(u.paddingRight),f=lc(i,n),p=lc(i,r),m=f.type==se.Text?f:null,b=p.type==se.Text?p:null;if(i.lineWrapping&&(m&&(m=oc(i,n,m)),b&&(b=oc(i,r,b))),m&&b&&m.from==b.from)return v(A(t.from,t.to,m));{let k=m?A(t.from,null,m):C(f,!1),M=b?A(null,t.to,b):C(p,!0),x=[];return(m||f).to<(b||p).from-1?x.push(w(h,k.bottom,c,M.top)):k.bottom<M.top&&i.elementAtHeight((k.bottom+M.top)/2).type==se.Text&&(k.bottom=M.top=(k.bottom+M.top)/2),v(k).concat(x).concat(v(M))}function w(k,M,x,I){return new zn(e,k-a.left,M-a.top-.01,x-k,I-M+.01)}function v({top:k,bottom:M,horizontal:x}){let I=[];for(let _=0;_<x.length;_+=2)I.push(w(x[_],k,x[_+1],M));return I}function A(k,M,x){let I=1e9,_=-1e9,F=[];function R(N,j,$,ee,Oe){let ne=i.coordsAtPos(N,N==x.to?-2:2),Y=i.coordsAtPos($,$==x.from?2:-2);I=Math.min(ne.top,Y.top,I),_=Math.max(ne.bottom,Y.bottom,_),Oe==we.LTR?F.push(s&&j?h:ne.left,s&&ee?c:Y.right):F.push(!s&&ee?h:Y.left,!s&&j?c:ne.right)}let P=k!=null?k:x.from,H=M!=null?M:x.to;for(let N of i.visibleRanges)if(N.to>P&&N.from<H)for(let j=Math.max(N.from,P),$=Math.min(N.to,H);;){let ee=i.state.doc.lineAt(j);for(let Oe of i.bidiSpans(ee)){let ne=Oe.from+ee.from,Y=Oe.to+ee.from;if(ne>=$)break;Y>j&&R(Math.max(ne,j),k==null&&ne<=P,Math.min(Y,$),M==null&&Y>=H,Oe.dir)}if(j=ee.to+1,j>=$)break}return F.length==0&&R(P,k==null,H,M==null,i.textDirection),{top:I,bottom:_,horizontal:F}}function C(k,M){let x=l.top+(M?k.top:k.bottom);return{top:x,bottom:x,horizontal:[]}}}function Qg(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(ys)!=e.state.facet(ys)&&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(ys);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)=>!Qg(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let r=t.nextSibling;t.remove(),t=r}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},ys=K.define();function ef(i){return[mt.define(e=>new Pl(e,i)),ys.of(i)]}var tf=!W.ios,br=K.define({combine(i){return gi(i,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Wl(i={}){return[br.of(i),Jg,Xg,Yg,Ec.of(!0)]}function nf(i){return i.startState.facet(br)!=i.state.facet(br)}var Jg=ef({above:!0,markers(i){let{state:e}=i,t=e.facet(br),n=[];for(let r of e.selection.ranges){let s=r==e.selection.main;if(r.empty?!s||tf:t.drawRangeCursor){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=r.empty?r:E.cursor(r.head,r.head>r.anchor?-1:1);for(let a of zn.forRange(i,o,l))n.push(a)}}return n},update(i,e){i.transactions.some(n=>n.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=nf(i);return t&&ac(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){ac(e.state,i)},class:"cm-cursorLayer"});function ac(i,e){e.style.animationDuration=i.facet(br).cursorBlinkRate+"ms"}var Xg=ef({above:!1,markers(i){return i.state.selection.ranges.map(e=>e.empty?[]:zn.forRange(i,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||nf(i)},class:"cm-selectionLayer"}),rf={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};tf&&(rf[".cm-line"].caretColor="transparent !important");var Yg=mi.highest(q.theme(rf));function uc(i,e,t,n,r){e.lastIndex=0;for(let s=i.iterRange(t,n),o=t,l;!s.next().done;o+=s.value.length)if(!s.lineBreak)for(;l=e.exec(s.value);)r(o+l.index,l)}function Zg(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:r,to:s}of t)r=Math.max(i.state.doc.lineAt(r).from,r-e),s=Math.min(i.state.doc.lineAt(s).to,s+e),n.length&&n[n.length-1].to>=r?n[n.length-1].to=s:n.push({from:r,to:s});return n}var Ol=class{constructor(e){let{regexp:t,decoration:n,decorate:r,boundary:s,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,r)this.addMatch=(l,a,u,h)=>r(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=s,this.maxLength=o}createDeco(e){let t=new Ct,n=t.add.bind(t);for(let{from:r,to:s}of Zg(e,this.maxLength))uc(e.state.doc,this.regexp,r,s,(o,l)=>this.addMatch(l,e,o,n));return t.finish()}updateDeco(e,t){let n=1e9,r=-1;return e.docChanged&&e.changes.iterChanges((s,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(n=Math.min(l,n),r=Math.max(a,r))}),e.viewportChanged||r-n>1e3?this.createDeco(e.view):r>-1?this.updateRange(e.view,t.map(e.changes),n,r):t}updateRange(e,t,n,r){for(let s of e.visibleRanges){let o=Math.max(s.from,n),l=Math.min(s.to,r);if(l>o){let a=e.state.doc.lineAt(o),u=a.to<l?e.state.doc.lineAt(l):a,h=Math.max(s.from,a.from),c=Math.min(s.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=[],p,m=(b,w,v)=>f.push(v.range(b,w));if(a==u)for(this.regexp.lastIndex=h-a.from;(p=this.regexp.exec(a.text))&&p.index<c-a.from;)this.addMatch(p,e,p.index+a.from,m);else uc(e.state.doc,this.regexp,h,c,(b,w)=>this.addMatch(w,e,b,m));t=t.update({filterFrom:h,filterTo:c,filter:(b,w)=>b<h||w>c,add:f})}}return t}},Il=/x/.unicode!=null?"gu":"g",eb=new RegExp(`[\0-\b
10
- -\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,Il),tb={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"},el=null;function nb(){var i;if(el==null&&typeof document<"u"&&document.body){let e=document.body.style;el=((i=e.tabSize)!==null&&i!==void 0?i:e.MozTabSize)!=null}return el||!1}var ws=K.define({combine(i){let e=gi(i,{render:null,specialChars:eb,addSpecialChars:null});return(e.replaceTabs=!nb())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Il)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Il)),e}});function _l(i={}){return[ws.of(i),ib()]}var hc=null;function ib(){return hc||(hc=mt.fromClass(class{constructor(i){this.view=i,this.decorations=oe.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(i.state.facet(ws)),this.decorations=this.decorator.createDeco(i)}makeDecorator(i){return new Ol({regexp:i.specialChars,decoration:(e,t,n)=>{let{doc:r}=t.state,s=hi(e[0],0);if(s==9){let o=r.lineAt(n),l=t.state.tabSize,a=Wn(o.text,l,n-o.from);return oe.replace({widget:new Vl((l-a%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[s]||(this.decorationCache[s]=oe.replace({widget:new Ll(i,s)}))},boundary:i.replaceTabs?void 0:/[^]/})}update(i){let e=i.state.facet(ws);i.startState.facet(ws)!=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 rb="\u2022";function sb(i){return i>=32?rb:i==10?"\u2424":String.fromCharCode(9216+i)}var Ll=class extends Ft{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=sb(this.code),n=e.state.phrase("Control character")+" "+(tb[this.code]||"0x"+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let s=document.createElement("span");return s.textContent=t,s.title=n,s.setAttribute("aria-label",n),s.className="cm-specialChar",s}ignoreEvent(){return!1}},Vl=class extends Ft{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 nS=q.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 Wt=class extends Lt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Wt.prototype.elementClass="";Wt.prototype.toDOM=void 0;Wt.prototype.mapMode=Ke.TrackBefore;Wt.prototype.startSide=Wt.prototype.endSide=-1;Wt.prototype.point=!0;var ob=0,wr=class{constructor(e,t){this.from=e,this.to=t}},G=class{constructor(e={}){this.id=ob++,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=Ae.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};G.closedBy=new G({deserialize:i=>i.split(" ")});G.openedBy=new G({deserialize:i=>i.split(" ")});G.group=new G({deserialize:i=>i.split(" ")});G.contextHash=new G({perNode:!0});G.lookAhead=new G({perNode:!0});G.mounted=new G({perNode:!0});var lb=Object.create(null),Ae=class{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):lb,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new Ae(e.name||"",t,e.id,n);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(r)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return r}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(G.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 r of n.split(" "))t[r]=e[n];return n=>{for(let r=n.prop(G.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?n.name:r[s]];if(o)return o}}}};Ae.none=new Ae("",Object.create(null),0,8);var Un=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 r=null;for(let s of e){let o=s(n);o&&(r||(r=Object.assign({},n.props)),r[o[0].id]=o[1])}t.push(r?new Ae(n.name,r,n.id,n.flags):n)}return new Un(t)}},Ls=new WeakMap,sf=new WeakMap,xe;(function(i){i[i.ExcludeBuffers=1]="ExcludeBuffers",i[i.IncludeAnonymous=2]="IncludeAnonymous",i[i.IgnoreMounts=4]="IgnoreMounts",i[i.IgnoreOverlays=8]="IgnoreOverlays"})(xe||(xe={}));var ue=class{constructor(e,t,n,r,s){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,l]of s)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(G.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let n of this.children){let r=n.toString();r&&(t&&(t+=","),t+=r)}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 Ai(this.topNode,e)}cursorAt(e,t=0,n=0){let r=Ls.get(this)||this.topNode,s=new Ai(r);return s.moveTo(e,t),Ls.set(this,s._tree),s}get topNode(){return new gt(this,0,0,null)}resolve(e,t=0){let n=Ri(Ls.get(this)||this.topNode,e,t,!1);return Ls.set(this,n),n}resolveInner(e,t=0){let n=Ri(sf.get(this)||this.topNode,e,t,!0);return sf.set(this,n),n}iterate(e){let{enter:t,leave:n,from:r=0,to:s=this.length}=e;for(let o=this.cursor((e.mode||0)|xe.IncludeAnonymous);;){let l=!1;if(o.from<=s&&o.to>=r&&(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:$l(Ae.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new ue(this.type,t,n,r,this.propValues),e.makeTree||((t,n,r)=>new ue(Ae.none,t,n,r)))}static build(e){return ab(e)}};ue.empty=new ue(Ae.none,[],[],0);var vr=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 vr(this.buffer,this.index)}},_t=class{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return Ae.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],r=this.set.types[t],s=r.name;if(/\W/.test(s)&&!r.isError&&(s=JSON.stringify(s)),e+=4,n==e)return s;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,n,r,s){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(lf(s,r,o[a+1],o[a+2])&&(l=a,n>0));a=o[a+3]);return l}slice(e,t,n){let r=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){s[a++]=r[l++],s[a++]=r[l++]-n;let u=s[a++]=r[l++]-n;s[a++]=r[l++]-e,o=Math.max(o,u)}return new _t(s,o,this.set)}};function lf(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 af(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 Ri(i,e,t,n){for(var r;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 gt&&i.index<0?null:i.parent;if(!o)return i;i=o}let s=n?0:xe.IgnoreOverlays;if(n)for(let o=i,l=o.parent;l;o=l,l=o.parent)o instanceof gt&&o.index<0&&((r=l.enter(e,t,s))===null||r===void 0?void 0:r.from)!=o.from&&(i=l);for(;;){let o=i.enter(e,t,s);if(!o)return i;i=o}}var gt=class{constructor(e,t,n,r){this._tree=e,this.from=t,this.index=n,this._parent=r}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,r,s=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(lf(r,n,c,c+h.length)){if(h instanceof _t){if(s&xe.ExcludeBuffers)continue;let f=h.findChild(0,h.buffer.length,t,n-c,r);if(f>-1)return new Mt(new zl(o,h,e,c),null,f)}else if(s&xe.IncludeAnonymous||!h.type.isAnonymous||Kl(h)){let f;if(!(s&xe.IgnoreMounts)&&h.props&&(f=h.prop(G.mounted))&&!f.overlay)return new gt(f.tree,c,e,o);let p=new gt(h,c,e,o);return s&xe.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?h.children.length-1:0,t,n,r)}}}if(s&xe.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 r;if(!(n&xe.IgnoreOverlays)&&(r=this._tree.prop(G.mounted))&&r.overlay){let s=e-this.from;for(let{from:o,to:l}of r.overlay)if((t>0?o<=s:o<s)&&(t<0?l>=s:l>s))return new gt(r.tree,r.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 Ai(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return Ri(this,e,t,!1)}resolveInner(e,t=0){return Ri(this,e,t,!0)}enterUnfinishedNodesBefore(e){return af(this,e)}getChild(e,t=null,n=null){let r=Ns(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Ns(this,e,t,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return Bs(this,e)}};function Ns(i,e,t,n){let r=i.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(;!r.type.is(t);)if(!r.nextSibling())return s}for(;;){if(n!=null&&r.type.is(n))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return n==null?s:[]}}function Bs(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 zl=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},Mt=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:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return s<0?null:new Mt(this.context,this,s)}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&xe.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new Mt(this.context,this,s)}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 Mt(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 Mt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new Ai(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,s=n.buffer[this.index+3];if(s>r){let o=n.buffer[this.index+1];e.push(n.slice(r,s,o)),t.push(0)}return new ue(this.type,e,t,this.to-this.from)}resolve(e,t=0){return Ri(this,e,t,!1)}resolveInner(e,t=0){return Ri(this,e,t,!0)}enterUnfinishedNodesBefore(e){return af(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,n=null){let r=Ns(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Ns(this,e,t,n)}get node(){return this}matchContext(e){return Bs(this,e)}},Ai=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 gt)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:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof gt?(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:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}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&xe.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&xe.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&xe.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 r=n<0?0:this.stack[n]+4;if(this.index!=r)return this.yieldBuf(t.findChild(r,this.index,-1,0,4))}else{let r=t.buffer[this.index+3];if(r<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(r)}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:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(r.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let s=t+e,o=e<0?-1:n._tree.children.length;s!=o;s+=e){let l=n._tree.children[s];if(this.mode&xe.IncludeAnonymous||l instanceof _t||!l.type.isAnonymous||Kl(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 r=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,n=s+1;break e}r=this.stack[--s]}}for(let r=n;r<this.stack.length;r++)t=new Mt(this.buffer,t,this.stack[r]);return this.bufferNode=new Mt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;r&&t&&t(this),r=this.type.isAnonymous,!this.nextSibling();){if(!n)return;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return Bs(this.node,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,s=this.stack.length-1;r>=0;s--){if(s<0)return Bs(this.node,e,r);let o=n[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}};function Kl(i){return i.children.some(e=>e instanceof _t||!e.type.isAnonymous||Kl(e))}function ab(i){var e;let{buffer:t,nodeSet:n,maxBufferLength:r=1024,reused:s=[],minRepeatType:o=n.types.length}=i,l=Array.isArray(t)?new vr(t,t.length):t,a=n.types,u=0,h=0;function c(k,M,x,I,_){let{id:F,start:R,end:P,size:H}=l,N=h;for(;H<0;)if(l.next(),H==-1){let ne=s[F];x.push(ne),I.push(R-k);return}else if(H==-3){u=F;return}else if(H==-4){h=F;return}else throw new RangeError(`Unrecognized record size: ${H}`);let j=a[F],$,ee,Oe=R-k;if(P-R<=r&&(ee=b(l.pos-M,_))){let ne=new Uint16Array(ee.size-ee.skip),Y=l.pos-ee.size,ke=ne.length;for(;l.pos>Y;)ke=w(ee.start,ne,ke);$=new _t(ne,P-ee.start,n),Oe=ee.start-k}else{let ne=l.pos-H;l.next();let Y=[],ke=[],Fe=F>=o?F:-1,Ze=0,ht=P;for(;l.pos>ne;)Fe>=0&&l.id==Fe&&l.size>=0?(l.end<=ht-r&&(p(Y,ke,R,Ze,l.end,ht,Fe,N),Ze=Y.length,ht=l.end),l.next()):c(R,ne,Y,ke,Fe);if(Fe>=0&&Ze>0&&Ze<Y.length&&p(Y,ke,R,Ze,R,ht,Fe,N),Y.reverse(),ke.reverse(),Fe>-1&&Ze>0){let vt=f(j);$=$l(j,Y,ke,0,Y.length,0,P-R,vt,vt)}else $=m(j,Y,ke,P-R,N-P)}x.push($),I.push(Oe)}function f(k){return(M,x,I)=>{let _=0,F=M.length-1,R,P;if(F>=0&&(R=M[F])instanceof ue){if(!F&&R.type==k&&R.length==I)return R;(P=R.prop(G.lookAhead))&&(_=x[F]+R.length+P)}return m(k,M,x,I,_)}}function p(k,M,x,I,_,F,R,P){let H=[],N=[];for(;k.length>I;)H.push(k.pop()),N.push(M.pop()+x-_);k.push(m(n.types[R],H,N,F-_,P-F)),M.push(_-x)}function m(k,M,x,I,_=0,F){if(u){let R=[G.contextHash,u];F=F?[R].concat(F):[R]}if(_>25){let R=[G.lookAhead,_];F=F?[R].concat(F):[R]}return new ue(k,M,x,I,F)}function b(k,M){let x=l.fork(),I=0,_=0,F=0,R=x.end-r,P={size:0,start:0,skip:0};e:for(let H=x.pos-k;x.pos>H;){let N=x.size;if(x.id==M&&N>=0){P.size=I,P.start=_,P.skip=F,F+=4,I+=4,x.next();continue}let j=x.pos-N;if(N<0||j<H||x.start<R)break;let $=x.id>=o?4:0,ee=x.start;for(x.next();x.pos>j;){if(x.size<0)if(x.size==-3)$+=4;else break e;else x.id>=o&&($+=4);x.next()}_=ee,I+=N,F+=$}return(M<0||I==k)&&(P.size=I,P.start=_,P.skip=F),P.size>4?P:void 0}function w(k,M,x){let{id:I,start:_,end:F,size:R}=l;if(l.next(),R>=0&&I<o){let P=x;if(R>4){let H=l.pos-(R-4);for(;l.pos>H;)x=w(k,M,x)}M[--x]=P,M[--x]=F-k,M[--x]=_-k,M[--x]=I}else R==-3?u=I:R==-4&&(h=I);return x}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 ue(a[i.topID],v.reverse(),A.reverse(),C)}var of=new WeakMap;function Vs(i,e){if(!i.isAnonymous||e instanceof _t||e.type!=i)return 1;let t=of.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof ue)){t=1;break}t+=Vs(i,n)}of.set(e,t)}return t}function $l(i,e,t,n,r,s,o,l,a){let u=0;for(let m=n;m<r;m++)u+=Vs(i,e[m]);let h=Math.ceil(u*1.5/8),c=[],f=[];function p(m,b,w,v,A){for(let C=w;C<v;){let k=C,M=b[C],x=Vs(i,m[C]);for(C++;C<v;C++){let I=Vs(i,m[C]);if(x+I>=h)break;x+=I}if(C==k+1){if(x>h){let I=m[k];p(I.children,I.positions,0,I.children.length,b[k]+A);continue}c.push(m[k])}else{let I=b[C-1]+m[C-1].length-M;c.push($l(i,m,b,k,C,M,I,null,a))}f.push(M+A-s)}}return p(e,t,n,r,0),(l||a)(c,f,o)}var Tt=class{constructor(e,t,n,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=(s?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 r=[new Tt(0,e.length,e,0,!1,n)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,n=128){if(!t.length)return e;let r=[],s=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 p=Math.max(f.from,a)-u,m=Math.min(f.to,c)-u;f=p>=m?null:new Tt(p,m,f.tree,f.offset+u,l>0,!!h)}if(f&&r.push(f),o.to>c)break;o=s<e.length?e[s++]:null}if(!h)break;a=h.toA,u=h.toA-h.toB}return r}},Di=class{startParse(e,t,n){return typeof e=="string"&&(e=new Ul(e)),n=n?n.length?n.map(r=>new wr(r.from,r.to)):[new wr(0,0)]:[new wr(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let s=r.advance();if(s)return s}}},Ul=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 sS=new G({perNode:!0});var ub=0,st=class{constructor(e,t,n){this.set=e,this.base=t,this.modified=n,this.id=ub++}static define(e){if(e!=null&&e.base)throw new Error("Can not derive from a modified tag");let t=new st([],null,[]);if(t.set.push(t),e)for(let n of e.set)t.set.push(n);return t}static defineModifier(){let e=new Ei;return t=>t.modified.indexOf(e)>-1?t:Ei.get(t.base||t,t.modified.concat(e).sort((n,r)=>n.id-r.id))}},hb=0,Ei=class{constructor(){this.instances=[],this.id=hb++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(l=>l.base==e&&cb(t,l.modified));if(n)return n;let r=[],s=new st(r,e,t);for(let l of t)l.instances.push(s);let o=fb(t);for(let l of e.set)if(!l.modified.length)for(let a of o)r.push(Ei.get(l,a));return s}};function cb(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function fb(i){let e=[[]];for(let t=0;t<i.length;t++)for(let n=0,r=e.length;n<r;n++)e.push(e[n].concat(i[t]));return e.sort((t,n)=>n.length-t.length)}function Sr(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let r of t.split(" "))if(r){let s=[],o=2,l=r;for(let c=0;;){if(l=="..."&&c>0&&c+3==r.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+r);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),c+=f[0].length,c==r.length)break;let p=r[c++];if(c==r.length&&p=="!"){o=0;break}if(p!="/")throw new RangeError("Invalid path: "+r);l=r.slice(c)}let a=s.length-1,u=s[a];if(!u)throw new RangeError("Invalid path: "+r);let h=new Pi(n,o,a>0?s.slice(0,a):null);e[u]=h.sort(e[u])}}return cf.add(e)}var cf=new G,Pi=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}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}};Pi.empty=new Pi([],2,null);function Ql(i,e){let t=Object.create(null);for(let s of i)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:n,all:r=null}=e||{};return{style:s=>{let o=r;for(let l of s)for(let a of l.set){let u=t[a.id];if(u){o=o?o+" "+u:u;break}}return o},scope:n}}function db(i,e){let t=null;for(let n of i){let r=n.style(e);r&&(t=t?t+" "+r:r)}return t}function ff(i,e,t,n=0,r=i.length){let s=new ql(n,Array.isArray(e)?e:[e],t);s.highlightRange(i.cursor(),n,r,"",s.highlighters),s.flush(r)}var ql=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,r,s){let{type:o,from:l,to:a}=e;if(l>=n||a<=t)return;o.isTop&&(s=this.highlighters.filter(p=>!p.scope||p.scope(o)));let u=r,h=pb(e)||Pi.empty,c=db(s,h.tags);if(c&&(u&&(u+=" "),u+=c,h.mode==1&&(r+=(r?" ":"")+c)),this.startSpan(e.from,u),h.opaque)return;let f=e.tree&&e.tree.prop(G.mounted);if(f&&f.overlay){let p=e.node.enter(f.overlay[0].from+l,1),m=this.highlighters.filter(w=>!w.scope||w.scope(f.tree.type)),b=e.firstChild();for(let w=0,v=l;;w++){let A=w<f.overlay.length?f.overlay[w]:null,C=A?A.from+l:a,k=Math.max(t,v),M=Math.min(n,C);if(k<M&&b)for(;e.from<M&&(this.highlightRange(e,k,M,r,s),this.startSpan(Math.min(M,e.to),u),!(e.to>=C||!e.nextSibling())););if(!A||C>n)break;v=A.to+l,v>t&&(this.highlightRange(p.cursor(),Math.max(t,A.from+l),Math.min(n,v),r,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,r,s),this.startSpan(Math.min(n,e.to),u)}while(e.nextSibling());e.parent()}}};function pb(i){let e=i.type.prop(cf);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}var L=st.define,Fs=L(),sn=L(),uf=L(sn),hf=L(sn),on=L(),Hs=L(on),Gl=L(on),Dt=L(),Kn=L(Dt),Rt=L(),At=L(),jl=L(),Cr=L(jl),Ws=L(),O={comment:Fs,lineComment:L(Fs),blockComment:L(Fs),docComment:L(Fs),name:sn,variableName:L(sn),typeName:uf,tagName:L(uf),propertyName:hf,attributeName:L(hf),className:L(sn),labelName:L(sn),namespace:L(sn),macroName:L(sn),literal:on,string:Hs,docString:L(Hs),character:L(Hs),attributeValue:L(Hs),number:Gl,integer:L(Gl),float:L(Gl),bool:L(on),regexp:L(on),escape:L(on),color:L(on),url:L(on),keyword:Rt,self:L(Rt),null:L(Rt),atom:L(Rt),unit:L(Rt),modifier:L(Rt),operatorKeyword:L(Rt),controlKeyword:L(Rt),definitionKeyword:L(Rt),moduleKeyword:L(Rt),operator:At,derefOperator:L(At),arithmeticOperator:L(At),logicOperator:L(At),bitwiseOperator:L(At),compareOperator:L(At),updateOperator:L(At),definitionOperator:L(At),typeOperator:L(At),controlOperator:L(At),punctuation:jl,separator:L(jl),bracket:Cr,angleBracket:L(Cr),squareBracket:L(Cr),paren:L(Cr),brace:L(Cr),content:Dt,heading:Kn,heading1:L(Kn),heading2:L(Kn),heading3:L(Kn),heading4:L(Kn),heading5:L(Kn),heading6:L(Kn),contentSeparator:L(Dt),list:L(Dt),quote:L(Dt),emphasis:L(Dt),strong:L(Dt),link:L(Dt),monospace:L(Dt),strikethrough:L(Dt),inserted:L(),deleted:L(),changed:L(),invalid:L(),meta:Ws,documentMeta:L(Ws),annotation:L(Ws),processingInstruction:L(Ws),definition:st.defineModifier(),constant:st.defineModifier(),function:st.defineModifier(),standard:st.defineModifier(),local:st.defineModifier(),special:st.defineModifier()},aS=Ql([{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 Jl,Oi=new G;function mb(i){return K.define({combine:i?e=>e.concat(i):void 0})}var gb=new G,Xe=class{constructor(e,t,n=[],r=""){this.data=e,this.name=r,J.prototype.hasOwnProperty("tree")||Object.defineProperty(J.prototype,"tree",{get(){return Ye(this)}}),this.parser=t,this.extension=[Li.of(this),J.languageData.of((s,o,l)=>{let a=df(s,o,l),u=a.type.prop(Oi);if(!u)return[];let h=s.facet(u),c=a.type.prop(gb);if(c){let f=a.resolve(o-a.from,l);for(let p of c)if(p.test(f,s)){let m=s.facet(p.facet);return p.type=="replace"?m:m.concat(h)}}return h})].concat(n)}isActiveAt(e,t,n=-1){return df(e,t,n).type.prop(Oi)==this.data}findRegions(e){let t=e.facet(Li);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(s,o)=>{if(s.prop(Oi)==this.data){n.push({from:o,to:o+s.length});return}let l=s.prop(G.mounted);if(l){if(l.tree.prop(Oi)==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+s.length});return}else if(l.overlay){let a=n.length;if(r(l.tree,l.overlay[0].from+o),n.length>a)return}}for(let a=0;a<s.children.length;a++){let u=s.children[a];u instanceof ue&&r(u,s.positions[a]+o)}};return r(Ye(e),0),n}get allowsNesting(){return!0}};Xe.setState=ae.define();function df(i,e,t){let n=i.facet(Li),r=Ye(i).topNode;if(!n||n.allowsNesting)for(let s=r;s;s=s.enter(e,t,xe.ExcludeBuffers))s.type.isTop&&(r=s);return r}var ln=class extends Xe{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=mb(e.languageData);return new ln(t,e.parser.configure({props:[Oi.add(n=>n.isTop?t:void 0)]}),e.name)}configure(e,t){return new ln(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function Ye(i){let e=i.field(Xe.state,!1);return e?e.tree:ue.empty}var ea=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}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)}},xr=null,Ii=class{constructor(e,t,n=[],r,s,o,l,a){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Ii(e,t,[],ue.empty,0,n,[],null)}startParse(){return this.parser.startParse(new ea(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=ue.empty&&this.isDone(t!=null?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let r=Date.now()+e;e=()=>Date.now()>r}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 r=this.parse.advance();if(r)if(this.fragments=this.withoutTempSkipped(Tt.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(n=this.parse.stoppedAt)!==null&&n!==void 0?n:this.state.doc.length,this.tree=r,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(Tt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=xr;xr=this;try{return e()}finally{xr=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=pf(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:s,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=Tt.applyChanges(n,a),r=ue.empty,s=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 Ii(this.parser,t,n,r,s,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:r,to:s}=this.skipped[n];r<e.to&&s>e.from&&(this.fragments=pf(this.fragments,r,s),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 Di{createParse(t,n,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=xr;if(a){for(let u of r)a.tempSkipped.push(u);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new ue(Ae.none,[],[],o-s)},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 xr}};function pf(i,e,t){return Tt.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}var an=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 an(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=Ii.create(e.facet(Li).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new an(n)}};Xe.state=Qe.define({create:an.init,update(i,e){for(let t of e.effects)if(t.is(Xe.setState))return t.value;return e.startState.facet(Li)!=e.state.facet(Li)?an.init(e.state):i.apply(e)}});var bf=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(bf=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var Xl=typeof navigator<"u"&&(!((Jl=navigator.scheduling)===null||Jl===void 0)&&Jl.isInputPending)?()=>navigator.scheduling.isInputPending():null,bb=mt.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=bf(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:r}}=this.view,s=n.field(Xe.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Xl?Math.max(25,e.timeRemaining()-5):1e9),l=s.context.treeLen<r&&n.doc.length>r+1e3,a=s.context.work(()=>Xl&&Xl()||Date.now()>o,r+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Xe.setState.of(new an(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Bt(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()}}}),Li=K.define({combine(i){return i.length?i[0]:null},enables:i=>[Xe.state,bb,q.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});var yb=K.define(),_s=K.define({combine:i=>{if(!i.length)return" ";let e=i[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return e}});function Mr(i){let e=i.facet(_s);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function Tr(i,e){let t="",n=i.tabSize,r=i.facet(_s)[0];if(r==" "){for(;e>=n;)t+=" ",e-=n;r=" "}for(let s=0;s<e;s++)t+=r;return t}function sa(i,e){i instanceof J&&(i=new $n(i));for(let n of i.state.facet(yb)){let r=n(i,e);if(r!==void 0)return r}let t=Ye(i.state);return t?vb(i,t,e):null}var $n=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=Mr(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=n.from&&r<=n.to?s&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.countColumn(n,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(s+=o-this.countColumn(n,n.search(/\S|$/))),s}countColumn(e,t=e.length){return Wn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(r);if(o>-1)return o}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},wb=new G;function vb(i,e,t){return yf(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,i)}function Cb(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function Sb(i){let e=i.type.prop(wb);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(G.closedBy))){let r=i.lastChild,s=r&&n.indexOf(r.name)>-1;return o=>Tb(o,!0,1,void 0,s&&!Cb(o)?r.from:void 0)}return i.parent==null?xb:null}function yf(i,e,t){for(;i;i=i.parent){let n=Sb(i);if(n)return n(kr.create(t,e,i))}return null}function xb(){return 0}var kr=class extends $n{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 kr(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(kb(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?yf(e,this.pos,this.base):0}};function kb(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function Mb(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let r=i.options.simulateBreak,s=i.state.doc.lineAt(t.from),o=r==null||r<=s.from?s.to:Math.min(s.to,r);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 Tb(i,e,t,n,r){let s=i.textAfter,o=s.match(/^\s*/)[0].length,l=n&&s.slice(o,o+n.length)==n||r==i.pos+o,a=e?Mb(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*t)}var zt=class{constructor(e,t){this.specs=e;let n;function r(l){let a=nt.newName();return(n||(n=Object.create(null)))["."+a]=l,a}let s=typeof t.all=="string"?t.all:t.all?r(t.all):void 0,o=t.scope;this.scope=o instanceof Xe?l=>l.prop(Oi)==o.data:o?l=>l==o:void 0,this.style=Ql(e.map(l=>({tag:l.tag,class:l.class||r(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=n?new nt(n):null,this.themeType=t.themeType}static define(e,t){return new zt(e,t||{})}},ta=K.define(),wf=K.define({combine(i){return i.length?[i[0]]:null}});function Yl(i){let e=i.facet(ta);return e.length?e:i.facet(wf)}function Rr(i,e){let t=[Rb],n;return i instanceof zt&&(i.module&&t.push(q.styleModule.of(i.module)),n=i.themeType),e!=null&&e.fallback?t.push(wf.of(i)):n?t.push(ta.computeN([q.darkTheme],r=>r.facet(q.darkTheme)==(n=="dark")?[i]:[])):t.push(ta.of(i)),t}var na=class{constructor(e){this.markCache=Object.create(null),this.tree=Ye(e.state),this.decorations=this.buildDeco(e,Yl(e.state))}update(e){let t=Ye(e.state),n=Yl(e.state),r=n!=Yl(e.startState);t.length<e.view.viewport.to&&!r&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n))}buildDeco(e,t){if(!t||!this.tree.length)return oe.none;let n=new Ct;for(let{from:r,to:s}of e.visibleRanges)ff(this.tree,t,(o,l,a)=>{n.add(o,l,this.markCache[a]||(this.markCache[a]=oe.mark({class:a})))},r,s);return n.finish()}},Rb=mi.high(mt.fromClass(na,{decorations:i=>i.decorations})),oa=zt.define([{tag:O.meta,color:"#404740"},{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 Ab=1e4,Db="()[]{}";var Eb=new G;function ia(i,e,t){let n=i.prop(e<0?G.openedBy:G.closedBy);if(n)return n;if(i.name.length==1){let r=t.indexOf(i.name);if(r>-1&&r%2==(e<0?1:0))return[t[r+e]]}return null}function ra(i){let e=i.type.prop(Eb);return e?e(i.node):i}function Gn(i,e,t,n={}){let r=n.maxScanDistance||Ab,s=n.brackets||Db,o=Ye(i),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let u=ia(a.type,t,s);if(u&&a.from<a.to){let h=ra(a);if(h&&(t>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return Pb(i,e,t,a,h,u,s)}}return Ob(i,e,t,o,l.type,r,s)}function Pb(i,e,t,n,r,s,o){let l=n.parent,a={from:r.from,to:r.to},u=0,h=l==null?void 0:l.cursor();if(h&&(t<0?h.childBefore(n.from):h.childAfter(n.to)))do if(t<0?h.to<=n.from:h.from>=n.to){if(u==0&&s.indexOf(h.type.name)>-1&&h.from<h.to){let c=ra(h);return{start:a,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(ia(h.type,t,o))u++;else if(ia(h.type,-t,o)){if(u==0){let c=ra(h);return{start:a,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}u--}}while(t<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function Ob(i,e,t,n,r,s,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<=s;){let p=h.value;t<0&&(f+=p.length);let m=e+f*t;for(let b=t>0?0:p.length-1,w=t>0?p.length:-1;b!=w;b+=t){let v=o.indexOf(p[b]);if(!(v<0||n.resolveInner(m+b,1).type!=r))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+=p.length)}return h.done?{start:u,matched:!1}:null}var Ib=Object.create(null),mf=[Ae.none];var gf=[],Lb=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"]])Lb[i]=Vb(Ib,e);function Zl(i,e){gf.indexOf(i)>-1||(gf.push(i),console.warn(e))}function Vb(i,e){let t=null;for(let s of e.split(".")){let o=i[s]||O[s];o?typeof o=="function"?t?t=o(t):Zl(s,`Modifier ${s} used at start of tag`):t?Zl(s,`Tag ${s} used as modifier`):t=o:Zl(s,`Unknown highlighting tag ${s}`)}if(!t)return 0;let n=e.replace(/ /g,"_"),r=Ae.define({id:mf.length,name:n,props:[Sr({[n]:t})]});return mf.push(r),r.id}var Nb=i=>{let{state:e}=i,t=e.doc.lineAt(e.selection.main.head),n=da(i.state,t.from);return n.line?Bb(i):n.block?Hb(i):!1};function fa(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=i(e,t);return r?(n(t.update(r)),!0):!1}}var Bb=fa(zb,0);var Fb=fa(Rf,0);var Hb=fa((i,e)=>Rf(i,e,_b(e)),0);function da(i,e){let t=i.languageDataAt("commentTokens",e);return t.length?t[0]:{}}var Ar=50;function Wb(i,{open:e,close:t},n,r){let s=i.sliceDoc(n-Ar,n),o=i.sliceDoc(r,r+Ar),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,u=s.length-l;if(s.slice(u-e.length,u)==e&&o.slice(a,a+t.length)==t)return{open:{pos:n-l,margin:l&&1},close:{pos:r+a,margin:a&&1}};let h,c;r-n<=2*Ar?h=c=i.sliceDoc(n,r):(h=i.sliceDoc(n,n+Ar),c=i.sliceDoc(r-Ar,r));let f=/^\s*/.exec(h)[0].length,p=/\s*$/.exec(c)[0].length,m=c.length-p-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:r-p-t.length,margin:/\s/.test(c.charAt(m-1))?1:0}}:null}function _b(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),r=t.to<=n.to?n:i.doc.lineAt(t.to),s=e.length-1;s>=0&&e[s].to>n.from?e[s].to=r.to:e.push({from:n.from,to:r.to})}return e}function Rf(i,e,t=e.selection.ranges){let n=t.map(s=>da(e,s.from).block);if(!n.every(s=>s))return null;let r=t.map((s,o)=>Wb(e,n[o],s.from,s.to));if(i!=2&&!r.every(s=>s))return{changes:e.changes(t.map((s,o)=>r[o]?[]:[{from:s.from,insert:n[o].open+" "},{from:s.to,insert:" "+n[o].close}]))};if(i!=1&&r.some(s=>s)){let s=[];for(let o=0,l;o<r.length;o++)if(l=r[o]){let a=n[o],{open:u,close:h}=l;s.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:s}}return null}function zb(i,e,t=e.selection.ranges){let n=[],r=-1;for(let{from:s,to:o}of t){let l=n.length,a=1e9;for(let u=s;u<=o;){let h=e.doc.lineAt(u);if(h.from>r&&(s==o||o>h.from)){r=h.from;let c=da(e,h.from).line;if(!c)continue;let f=/^\s*/.exec(h.text)[0].length,p=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:p,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(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:u,empty:h,single:c}of n)(c||!h)&&s.push({from:l.from+u,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(i!=1&&n.some(s=>s.comment>=0)){let s=[];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++,s.push({from:u,to:h})}return{changes:s}}return null}var aa=tt.define(),Ub=tt.define(),Kb=K.define(),Af=K.define({combine(i){return gi(i,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}});function $b(i){let e=0;return i.iterChangedRanges((t,n)=>e=n),e}var Df=Qe.define({create(){return lt.empty},update(i,e){let t=e.state.facet(Af),n=e.annotation(aa);if(n){let a=e.docChanged?E.single($b(e.changes)):void 0,u=Ne.fromTransaction(e,a),h=n.side,c=h==0?i.undone:i.done;return u?c=Us(c,c.length,t.minDepth,u):c=Of(c,e.startState.selection),new lt(h==0?n.rest:c,h==0?c:n.rest)}let r=e.annotation(Ub);if((r=="full"||r=="before")&&(i=i.isolate()),e.annotation(fe.addToHistory)===!1)return e.changes.empty?i:i.addMapping(e.changes.desc);let s=Ne.fromTransaction(e),o=e.annotation(fe.time),l=e.annotation(fe.userEvent);return s?i=i.addChanges(s,o,l,t,e):e.selection&&(i=i.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(r=="full"||r=="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 lt(i.done.map(Ne.fromJSON),i.undone.map(Ne.fromJSON))}});function pa(i={}){return[Df,Af.of(i),q.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?Ef:e.inputType=="historyRedo"?ua:null;return n?(e.preventDefault(),n(t)):!1}})]}function Ks(i,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let r=t.field(Df,!1);if(!r)return!1;let s=r.pop(i,t,e);return s?(n(s),!0):!1}}var Ef=Ks(0,!1),ua=Ks(1,!1),Gb=Ks(0,!0),qb=Ks(1,!0);var Ne=class{constructor(e,t,n,r,s){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=s}setSelAfter(e){return new Ne(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(r=>r.toJSON())}}static fromJSON(e){return new Ne(e.changes&&ce.fromJSON(e.changes),[],e.mapped&&je.fromJSON(e.mapped),e.startSelection&&E.fromJSON(e.startSelection),e.selectionsAfter.map(E.fromJSON))}static fromTransaction(e,t){let n=ot;for(let r of e.startState.facet(Kb)){let s=r(e);s.length&&(n=n.concat(s))}return!n.length&&e.changes.empty?null:new Ne(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,ot)}static selection(e){return new Ne(void 0,ot,void 0,void 0,e)}};function Us(i,e,t,n){let r=e+1>t+20?e-t-1:0,s=i.slice(r,e);return s.push(n),s}function jb(i,e){let t=[],n=!1;return i.iterChangedRanges((r,s)=>t.push(r,s)),e.iterChangedRanges((r,s,o,l)=>{for(let a=0;a<t.length;){let u=t[a++],h=t[a++];l>=u&&o<=h&&(n=!0)}}),n}function Qb(i,e){return i.ranges.length==e.ranges.length&&i.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function Pf(i,e){return i.length?e.length?i.concat(e):i:e}var ot=[],Jb=200;function Of(i,e){if(i.length){let t=i[i.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Jb));return n.length&&n[n.length-1].eq(e)?i:(n.push(e),Us(i,i.length-1,1e9,t.setSelAfter(n)))}else return[Ne.selection([e])]}function Xb(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 la(i,e){if(!i.length)return i;let t=i.length,n=ot;for(;t;){let r=Yb(i[t-1],e,n);if(r.changes&&!r.changes.empty||r.effects.length){let s=i.slice(0,t);return s[t-1]=r,s}else e=r.mapped,t--,n=r.selectionsAfter}return n.length?[Ne.selection(n)]:ot}function Yb(i,e,t){let n=Pf(i.selectionsAfter.length?i.selectionsAfter.map(l=>l.map(e)):ot,t);if(!i.changes)return Ne.selection(n);let r=i.changes.map(e),s=e.mapDesc(i.changes,!0),o=i.mapped?i.mapped.composeDesc(s):s;return new Ne(r,ae.mapEffects(i.effects,e),o,i.startSelection.map(s),n)}var Zb=/^(input\.type|delete)($|\.)/,lt=class{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new lt(this.done,this.undone):this}addChanges(e,t,n,r,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!n||Zb.test(n))&&(!l.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(s,jb(l.changes,e.changes))||n=="input.type.compose")?o=Us(o,o.length-1,r.minDepth,new Ne(e.changes.compose(l.changes),Pf(e.effects,l.effects),l.mapped,l.startSelection,ot)):o=Us(o,o.length,r.minDepth,e),new lt(o,ot,t,n)}addSelection(e,t,n,r){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:ot;return s.length>0&&t-this.prevTime<r&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&Qb(s[s.length-1],e)?this:new lt(Of(this.done,e),this.undone,t,n)}addMapping(e){return new lt(la(this.done,e),la(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let s=r[r.length-1];if(n&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:aa.of({side:e,rest:Xb(r)}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let o=r.length==1?ot:r.slice(0,r.length-1);return s.mapped&&(o=la(o,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:aa.of({side:e,rest:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};lt.empty=new lt(ot,ot);var ma=[{key:"Mod-z",run:Ef,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:ua,preventDefault:!0},{linux:"Ctrl-Shift-z",run:ua,preventDefault:!0},{key:"Mod-u",run:Gb,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:qb,preventDefault:!0}];function Vi(i,e){return E.create(i.ranges.map(e),i.mainIndex)}function Et(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function bt({state:i,dispatch:e},t){let n=Vi(i.selection,t);return n.eq(i.selection)?!1:(e(Et(i,n)),!0)}function $s(i,e){return E.cursor(e?i.to:i.from)}function If(i,e){return bt(i,t=>t.empty?i.moveByChar(t,e):$s(t,e))}function Be(i){return i.textDirectionAt(i.state.selection.main.head)==we.LTR}var Lf=i=>If(i,!Be(i)),Vf=i=>If(i,Be(i));function Nf(i,e){return bt(i,t=>t.empty?i.moveByGroup(t,e):$s(t,e))}var e0=i=>Nf(i,!Be(i)),t0=i=>Nf(i,Be(i));function n0(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 Gs(i,e,t){let n=Ye(i).resolveInner(e.head),r=t?G.closedBy:G.openedBy;for(let a=e.head;;){let u=t?n.childAfter(a):n.childBefore(a);if(!u)break;n0(i,u,r)?n=u:a=t?u.to:u.from}let s=n.type.prop(r),o,l;return s&&(o=t?Gn(i,n.from,1):Gn(i,n.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?n.to:n.from,E.cursor(l,t?-1:1)}var i0=i=>bt(i,e=>Gs(i.state,e,!Be(i))),r0=i=>bt(i,e=>Gs(i.state,e,Be(i)));function Bf(i,e){return bt(i,t=>{if(!t.empty)return $s(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}var Ff=i=>Bf(i,!1),Hf=i=>Bf(i,!0);function Wf(i){let e=i.scrollDOM.clientHeight<i.scrollDOM.scrollHeight-2,t=0,n=0,r;if(e){for(let s of i.state.facet(q.scrollMargins)){let o=s(i);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(n=Math.max(o==null?void 0:o.bottom,n))}r=i.scrollDOM.clientHeight-t-n}else r=(i.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:n,selfScroll:e,height:Math.max(i.defaultLineHeight,r-5)}}function _f(i,e){let t=Wf(i),{state:n}=i,r=Vi(n.selection,o=>o.empty?i.moveVertically(o,e,t.height):$s(o,e));if(r.eq(n.selection))return!1;let s;if(t.selfScroll){let o=i.coordsAtPos(n.selection.main.head),l=i.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,u=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<u&&(s=q.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-a}))}return i.dispatch(Et(n,r),{effects:s}),!0}var vf=i=>_f(i,!1),ha=i=>_f(i,!0);function un(i,e,t){let n=i.lineBlockAt(e.head),r=i.moveToLineBoundary(e,t);if(r.head==e.head&&r.head!=(t?n.to:n.from)&&(r=i.moveToLineBoundary(e,t,!1)),!t&&r.head==n.from&&n.length){let s=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;s&&e.head!=n.from+s&&(r=E.cursor(n.from+s))}return r}var s0=i=>bt(i,e=>un(i,e,!0)),o0=i=>bt(i,e=>un(i,e,!1)),l0=i=>bt(i,e=>un(i,e,!Be(i))),a0=i=>bt(i,e=>un(i,e,Be(i))),u0=i=>bt(i,e=>E.cursor(i.lineBlockAt(e.head).from,1)),h0=i=>bt(i,e=>E.cursor(i.lineBlockAt(e.head).to,-1));function c0(i,e,t){let n=!1,r=Vi(i.selection,s=>{let o=Gn(i,s.head,-1)||Gn(i,s.head,1)||s.head>0&&Gn(i,s.head-1,1)||s.head<i.doc.length&&Gn(i,s.head+1,-1);if(!o||!o.end)return s;n=!0;let l=o.start.from==s.head?o.end.to:o.end.from;return t?E.range(s.anchor,l):E.cursor(l)});return n?(e(Et(i,r)),!0):!1}var f0=({state:i,dispatch:e})=>c0(i,e,!1);function at(i,e){let t=Vi(i.state.selection,n=>{let r=e(n);return E.range(n.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return t.eq(i.state.selection)?!1:(i.dispatch(Et(i.state,t)),!0)}function zf(i,e){return at(i,t=>i.moveByChar(t,e))}var Uf=i=>zf(i,!Be(i)),Kf=i=>zf(i,Be(i));function $f(i,e){return at(i,t=>i.moveByGroup(t,e))}var d0=i=>$f(i,!Be(i)),p0=i=>$f(i,Be(i));var m0=i=>at(i,e=>Gs(i.state,e,!Be(i))),g0=i=>at(i,e=>Gs(i.state,e,Be(i)));function Gf(i,e){return at(i,t=>i.moveVertically(t,e))}var qf=i=>Gf(i,!1),jf=i=>Gf(i,!0);function Qf(i,e){return at(i,t=>i.moveVertically(t,e,Wf(i).height))}var Cf=i=>Qf(i,!1),Sf=i=>Qf(i,!0),b0=i=>at(i,e=>un(i,e,!0)),y0=i=>at(i,e=>un(i,e,!1)),w0=i=>at(i,e=>un(i,e,!Be(i))),v0=i=>at(i,e=>un(i,e,Be(i))),C0=i=>at(i,e=>E.cursor(i.lineBlockAt(e.head).from)),S0=i=>at(i,e=>E.cursor(i.lineBlockAt(e.head).to)),xf=({state:i,dispatch:e})=>(e(Et(i,{anchor:0})),!0),kf=({state:i,dispatch:e})=>(e(Et(i,{anchor:i.doc.length})),!0),Mf=({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),x0=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),k0=({state:i,dispatch:e})=>{let t=js(i).map(({from:n,to:r})=>E.range(n,Math.min(r+1,i.doc.length)));return e(i.update({selection:E.create(t),userEvent:"select"})),!0},M0=({state:i,dispatch:e})=>{let t=Vi(i.selection,n=>{var r;let s=Ye(i).resolveInner(n.head,1);for(;!(s.from<n.from&&s.to>=n.to||s.to>n.to&&s.from<=n.from||!(!((r=s.parent)===null||r===void 0)&&r.parent));)s=s.parent;return E.range(s.to,s.from)});return e(Et(i,t)),!0},T0=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=E.create([t.main]):t.main.empty||(n=E.create([E.cursor(t.main.head)])),n?(e(Et(i,n)),!0):!1};function qs(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,r=n.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(o);a<o?(t="delete.backward",a=zs(i,a,!1)):a>o&&(t="delete.forward",a=zs(i,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=zs(i,o,!1),l=zs(i,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:E.cursor(o)}});return r.changes.empty?!1:(i.dispatch(n.update(r,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?q.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function zs(i,e,t){if(i instanceof q)for(let n of i.state.facet(q.atomicRanges).map(r=>r(i)))n.between(e,e,(r,s)=>{r<e&&s>e&&(e=t?s:r)});return e}var Jf=(i,e)=>qs(i,t=>{let{state:n}=i,r=n.doc.lineAt(t),s,o;if(!e&&t>r.from&&t<r.from+200&&!/[^ \t]/.test(s=r.text.slice(0,t-r.from))){if(s[s.length-1]==" ")return t-1;let l=Wn(s,n.tabSize),a=l%Mr(n)||Mr(n);for(let u=0;u<a&&s[s.length-1-u]==" ";u++)t--;o=t}else o=We(r.text,t-r.from,e,e)+r.from,o==t&&r.number!=(e?n.doc.lines:1)&&(o+=e?1:-1);return o}),ca=i=>Jf(i,!1),Xf=i=>Jf(i,!0),Yf=(i,e)=>qs(i,t=>{let n=t,{state:r}=i,s=r.doc.lineAt(n),o=r.charCategorizer(n);for(let l=null;;){if(n==(e?s.to:s.from)){n==t&&s.number!=(e?r.doc.lines:1)&&(n+=e?1:-1);break}let a=We(s.text,n-s.from,e)+s.from,u=s.text.slice(Math.min(n,a)-s.from,Math.max(n,a)-s.from),h=o(u);if(l!=null&&h!=l)break;(u!=" "||n!=t)&&(l=h),n=a}return n}),Zf=i=>Yf(i,!1),R0=i=>Yf(i,!0),ed=i=>qs(i,e=>{let t=i.lineBlockAt(e).to;return e<t?t:Math.min(i.state.doc.length,e+1)}),A0=i=>qs(i,e=>{let t=i.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)});var D0=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:Q.of(["",""])},range:E.cursor(n.from)}));return e(i.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},E0=({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 r=n.from,s=i.doc.lineAt(r),o=r==s.from?r-1:We(s.text,r-s.from,!1)+s.from,l=r==s.to?r+1:We(s.text,r-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:i.doc.slice(r,l).append(i.doc.slice(o,r))},range:E.cursor(l)}});return t.changes.empty?!1:(e(i.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function js(i){let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.from),s=i.doc.lineAt(n.to);if(!n.empty&&n.to==s.from&&(s=i.doc.lineAt(n.to-1)),t>=r.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(n)}else e.push({from:r.from,to:s.to,ranges:[n]});t=s.number+1}return e}function td(i,e,t){if(i.readOnly)return!1;let n=[],r=[];for(let s of js(i)){if(t?s.to==i.doc.length:s.from==0)continue;let o=i.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){n.push({from:s.to,to:o.to},{from:s.from,insert:o.text+i.lineBreak});for(let a of s.ranges)r.push(E.range(Math.min(i.doc.length,a.anchor+l),Math.min(i.doc.length,a.head+l)))}else{n.push({from:o.from,to:s.from},{from:s.to,insert:i.lineBreak+o.text});for(let a of s.ranges)r.push(E.range(a.anchor-l,a.head-l))}}return n.length?(e(i.update({changes:n,scrollIntoView:!0,selection:E.create(r,i.selection.mainIndex),userEvent:"move.line"})),!0):!1}var P0=({state:i,dispatch:e})=>td(i,e,!1),O0=({state:i,dispatch:e})=>td(i,e,!0);function nd(i,e,t){if(i.readOnly)return!1;let n=[];for(let r of js(i))t?n.push({from:r.from,insert:i.doc.slice(r.from,r.to)+i.lineBreak}):n.push({from:r.to,insert:i.lineBreak+i.doc.slice(r.from,r.to)});return e(i.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}var I0=({state:i,dispatch:e})=>nd(i,e,!1),L0=({state:i,dispatch:e})=>nd(i,e,!0),V0=i=>{if(i.state.readOnly)return!1;let{state:e}=i,t=e.changes(js(e).map(({from:r,to:s})=>(r>0?r--:s<e.doc.length&&s++,{from:r,to:s}))),n=Vi(e.selection,r=>i.moveVertically(r,!0)).map(t);return i.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function N0(i,e){if(/\(\)|\[\]|\{\}/.test(i.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Ye(i).resolveInner(e),n=t.childBefore(e),r=t.childAfter(e),s;return n&&r&&n.to<=e&&r.from>=e&&(s=n.type.prop(G.closedBy))&&s.indexOf(r.name)>-1&&i.doc.lineAt(n.to).from==i.doc.lineAt(r.from).from?{from:n.to,to:r.from}:null}var B0=id(!1),F0=id(!0);function id(i){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{let{from:s,to:o}=r,l=e.doc.lineAt(s),a=!i&&s==o&&N0(e,s);i&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let u=new $n(e,{simulateBreak:s,simulateDoubleBreak:!!a}),h=sa(u,s);for(h==null&&(h=/^\s*/.exec(e.doc.lineAt(s).text)[0].length);o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:s,to:o}=a:s>l.from&&s<l.from+100&&!/\S/.test(l.text.slice(0,s))&&(s=l.from);let c=["",Tr(e,h)];return a&&c.push(Tr(e,u.lineIndent(l.from,-1))),{changes:{from:s,to:o,insert:Q.of(c)},range:E.cursor(s+1+c[1].length)}});return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function ga(i,e){let t=-1;return i.changeByRange(n=>{let r=[];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,r,n),t=l.number),o=l.to+1}let s=i.changes(r);return{changes:r,range:E.range(s.mapPos(n.anchor,1),s.mapPos(n.head,1))}})}var H0=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=Object.create(null),n=new $n(i,{overrideIndentation:s=>{let o=t[s];return o==null?-1:o}}),r=ga(i,(s,o,l)=>{let a=sa(n,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let u=/^\s*/.exec(s.text)[0],h=Tr(i,a);(u!=h||l.from<s.from+u.length)&&(t[s.from]=a,o.push({from:s.from,to:s.from+u.length,insert:h}))});return r.changes.empty||e(i.update(r,{userEvent:"indent"})),!0},W0=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(ga(i,(t,n)=>{n.push({from:t.from,insert:i.facet(_s)})}),{userEvent:"input.indent"})),!0),_0=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(ga(i,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let s=Wn(r,i.tabSize),o=0,l=Tr(i,Math.max(0,s-Mr(i)));for(;o<r.length&&o<l.length&&r.charCodeAt(o)==l.charCodeAt(o);)o++;n.push({from:t.from+o,to:t.from+r.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0);var z0=[{key:"Ctrl-b",run:Lf,shift:Uf,preventDefault:!0},{key:"Ctrl-f",run:Vf,shift:Kf},{key:"Ctrl-p",run:Ff,shift:qf},{key:"Ctrl-n",run:Hf,shift:jf},{key:"Ctrl-a",run:u0,shift:C0},{key:"Ctrl-e",run:h0,shift:S0},{key:"Ctrl-d",run:Xf},{key:"Ctrl-h",run:ca},{key:"Ctrl-k",run:ed},{key:"Ctrl-Alt-h",run:Zf},{key:"Ctrl-o",run:D0},{key:"Ctrl-t",run:E0},{key:"Ctrl-v",run:ha}],U0=[{key:"ArrowLeft",run:Lf,shift:Uf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e0,shift:d0,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:l0,shift:w0,preventDefault:!0},{key:"ArrowRight",run:Vf,shift:Kf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t0,shift:p0,preventDefault:!0},{mac:"Cmd-ArrowRight",run:a0,shift:v0,preventDefault:!0},{key:"ArrowUp",run:Ff,shift:qf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xf,shift:Mf},{mac:"Ctrl-ArrowUp",run:vf,shift:Cf},{key:"ArrowDown",run:Hf,shift:jf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:kf,shift:Tf},{mac:"Ctrl-ArrowDown",run:ha,shift:Sf},{key:"PageUp",run:vf,shift:Cf},{key:"PageDown",run:ha,shift:Sf},{key:"Home",run:o0,shift:y0,preventDefault:!0},{key:"Mod-Home",run:xf,shift:Mf},{key:"End",run:s0,shift:b0,preventDefault:!0},{key:"Mod-End",run:kf,shift:Tf},{key:"Enter",run:B0},{key:"Mod-a",run:x0},{key:"Backspace",run:ca,shift:ca},{key:"Delete",run:Xf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Zf},{key:"Mod-Delete",mac:"Alt-Delete",run:R0},{mac:"Mod-Backspace",run:A0},{mac:"Mod-Delete",run:ed}].concat(z0.map(i=>({mac:i.key,run:i.run,shift:i.shift}))),Qs=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:i0,shift:m0},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:r0,shift:g0},{key:"Alt-ArrowUp",run:P0},{key:"Shift-Alt-ArrowUp",run:I0},{key:"Alt-ArrowDown",run:O0},{key:"Shift-Alt-ArrowDown",run:L0},{key:"Escape",run:T0},{key:"Mod-Enter",run:F0},{key:"Alt-l",mac:"Ctrl-l",run:k0},{key:"Mod-i",run:M0,preventDefault:!0},{key:"Mod-[",run:_0},{key:"Mod-]",run:W0},{key:"Mod-Alt-\\",run:H0},{key:"Shift-Mod-k",run:V0},{key:"Shift-Mod-\\",run:f0},{key:"Mod-/",run:Nb},{key:"Alt-A",run:Fb}].concat(U0);var Bi=class{constructor(e,t,n,r,s,o,l,a,u,h=0,c){this.p=e,this.stack=t,this.state=n,this.reducePos=r,this.pos=s,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 r=e.parser.context;return new Bi(e,[],t,n,n,0,[],0,r?new Js(r,r.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){var t;let n=e>>19,r=e&65535,{parser:s}=this.p,o=s.dynamicPrecedence(r);if(o&&(this.score+=o),n==0){this.pushState(s.getGoto(this.state,r,!0),this.reducePos),r<s.minRepeatTerm&&this.storeNode(r,this.reducePos,this.reducePos,4,!0),this.reduceContext(r,this.reducePos);return}let l=this.stack.length-(n-1)*3-(e&262144?6:0),a=l?this.stack[l-2]:this.p.ranges[0].from,u=this.reducePos-a;u>=2e3&&!(!((t=this.p.parser.nodeSet.types[r])===null||t===void 0)&&t.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let h=l?this.stack[l-1]:0,c=this.bufferBase+this.buffer.length-h;if(r<s.minRepeatTerm||e&131072){let f=s.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(r,a,f,c+4,!0)}if(e&262144)this.state=this.stack[l];else{let f=this.stack[l-3];this.state=s.getGoto(f,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,a)}storeNode(e,t,n,r=4,s=!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(!s||this.pos==n)this.buffer.push(e,t,n,r);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,r>4&&(r-=4);this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=n,this.buffer[o+3]=r}}shift(e,t,n){let r=this.pos;if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=n,this.shiftContext(t,r),t<=this.p.parser.maxNode&&this.buffer.push(t,r,n,4);else{let s=e,{parser:o}=this.p;(n>this.pos||t<=o.maxNode)&&(this.pos=n,o.stateFlag(s,1)||(this.reducePos=n)),this.pushState(s,r),this.shiftContext(t,r),t<=o.maxNode&&this.buffer.push(t,r,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 r=this.pos;this.reducePos=this.pos=r+e.length,this.pushState(t,r),this.buffer.push(n,r,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),r=e.bufferBase+t;for(;e&&r==e.bufferBase;)e=e.parent;return new Bi(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,n,r,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 ya(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 r=[];for(let s=0,o;s<t.length;s+=2)(o=t[s+1])!=this.state&&this.p.parser.hasAction(o,e)&&r.push(t[s],o);if(this.stack.length<120)for(let s=0;r.length<4<<1&&s<t.length;s+=2){let o=t[s+1];r.some((l,a)=>a&1&&l==o)||r.push(t[s],o)}t=r}let n=[];for(let r=0;r<t.length&&n.length<4;r+=2){let s=t[r+1];if(s==this.state)continue;let o=this.split();o.pushState(s,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[r],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,r=e&65535,s=this.stack.length-n*3;if(s<0||t.getGoto(this.stack[s],r,!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 Js(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()}},Js=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},rd;(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",i[i.MinBigReduction=2e3]="MinBigReduction"})(rd||(rd={}));var ya=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 r=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=r}},Fi=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 Fi(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 Fi(this.stack,this.pos,this.index)}};function Dr(i,e=Uint16Array){if(typeof i!="string")return i;let t=null;for(let n=0,r=0;n<i.length;){let s=0;for(;;){let o=i.charCodeAt(n++),l=!1;if(o==126){s=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),s+=a,l)break;s*=46}t?t[r++]=s:t=new e(s)}return t}var Ni=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},sd=new Ni,wa=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=sd,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,r=this.rangeIndex,s=this.pos+e;for(;s<n.from;){if(!r)return null;let o=this.ranges[--r];s-=n.from-o.to,n=o}for(;t<0?s>n.to:s>=n.to;){if(r==this.ranges.length-1)return null;let o=this.ranges[++r];s+=o.from-n.to,n=o}return s}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,r;if(t>=0&&t<this.chunk.length)n=this.pos+e,r=this.chunk.charCodeAt(t);else{let s=this.resolveOffset(e,1);if(s==null)return-1;if(n=s,n>=this.chunk2Pos&&n<this.chunk2Pos+this.chunk2.length)r=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)),r=this.chunk2.charCodeAt(0)}}return n>=this.token.lookAhead&&(this.token.lookAhead=n+1),r}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=sd,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 r of this.ranges){if(r.from>=t)break;r.to>e&&(n+=this.input.read(Math.max(r.from,e),Math.min(r.to,t)))}return n}},hn=class{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:n}=t.p;fd(this.data,e,t,this.id,n.data,n.tokenPrecTable)}};hn.prototype.contextual=hn.prototype.fallback=hn.prototype.extend=!1;var va=class{constructor(e,t,n){this.precTable=t,this.elseToken=n,this.data=typeof e=="string"?Dr(e):e}token(e,t){let n=e.pos,r;for(;r=e.pos,fd(this.data,e,t,0,this.data,this.precTable),!(e.token.value>-1);){if(this.elseToken==null)return;if(e.next<0)break;e.advance(),e.reset(r+1,e.token)}r>n&&(e.reset(n,e.token),e.acceptToken(this.elseToken,r-n))}};va.prototype.contextual=hn.prototype.fallback=hn.prototype.extend=!1;function fd(i,e,t,n,r,s){let o=0,l=1<<n,{dialect:a}=t.p.parser;e:for(;l&i[o];){let u=i[o+1];for(let p=o+3;p<u;p+=2)if((i[p+1]&l)>0){let m=i[p];if(a.allows(m)&&(e.token.value==-1||e.token.value==m||$0(m,e.token.value,r,s))){e.acceptToken(m);break}}let h=e.next,c=0,f=i[o+2];if(e.next<0&&f>c&&i[u+f*3-3]==65535&&i[u+f*3-3]==65535){o=i[u+f*3-1];continue e}for(;c<f;){let p=c+f>>1,m=u+p+(p<<1),b=i[m],w=i[m+1]||65536;if(h<b)f=p;else if(h>=w)c=p+1;else{o=i[m+2],e.advance();continue e}}break}}function od(i,e,t){for(let n=e,r;(r=i[n])!=65535;n++)if(r==t)return n-e;return-1}function $0(i,e,t,n){let r=od(t,n,e);return r<0||od(t,n,i)<r}var yt=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),ba=null,ld;(function(i){i[i.Margin=25]="Margin"})(ld||(ld={}));function ad(i,e,t){let n=i.cursor(xe.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 Ca=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?ad(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?ad(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],r=this.index[t];if(r==n.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let s=n.children[r],o=this.start[t]+n.positions[r];if(o>e)return this.nextStart=o,null;if(s instanceof ue){if(o==e){if(o<this.safeFrom)return null;let l=o+s.length;if(l<=this.safeTo){let a=s.prop(G.lookAhead);if(!a||l+a<this.fragment.to)return s}}this.index[t]++,o+s.length>=Math.max(this.safeFrom,e)&&(this.trees.push(s),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+s.length}}},Sa=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(n=>new Ni)}getActions(e){let t=0,n=null,{parser:r}=e.p,{tokenizers:s}=r,o=r.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let u=0;u<s.length;u++){if(!(1<<u&o))continue;let h=s[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 Ni,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 Ni,{pos:n,p:r}=e;return t.start=n,t.end=Math.min(n+1,r.stream.end),t.value=n==r.stream.end?r.parser.eofTerm:0,t}updateCachedToken(e,t,n){let r=this.stream.clipPos(n.pos);if(t.token(this.stream.reset(r,e),n),e.value>-1){let{parser:s}=n.p;for(let o=0;o<s.specialized.length;o++)if(s.specialized[o]==e.value){let l=s.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(r+1)}putAction(e,t,n,r){for(let s=0;s<r;s+=3)if(this.actions[s]==e)return r;return this.actions[r++]=e,this.actions[r++]=t,this.actions[r++]=n,r}addActions(e,t,n,r){let{state:s}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let u=o.stateSlot(s,a?2:1);;u+=3){if(l[u]==65535)if(l[u+1]==1)u=Ut(l,u+2);else{r==0&&l[u+1]==2&&(r=this.putAction(Ut(l,u+2),t,n,r));break}l[u]==t&&(r=this.putAction(Ut(l,u+1),t,n,r))}return r}},ud;(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",i[i.MaxLeftAssociativeReductionCount=300]="MaxLeftAssociativeReductionCount",i[i.MaxStackCount=12]="MaxStackCount"})(ud||(ud={}));var xa=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new wa(t,r),this.tokens=new Sa(e,this.stream),this.topTerm=e.top[1];let{from:s}=r[0];this.stacks=[Bi.start(this,e.top[0],s)],this.fragments=n.length&&this.stream.end-s>e.bufferLength*4?new Ca(n,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,n=this.stacks=[],r,s;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}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;{r||(r=[],s=[]),r.push(l);let a=this.tokens.getMainToken(l);s.push(a.value,a.end)}}break}}if(!n.length){let o=r&&G0(r);if(o)return this.stackToTree(o);if(this.parser.strict)throw yt&&r&&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&&r){let o=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,s,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}}}n.length>12&&n.splice(12,n.length-12)}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 r=e.pos,{parser:s}=this,o=yt?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&r>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(r);c;){let f=this.parser.nodeSet.types[c.type.id]==c.type?s.getGoto(e.state,c.type.id):-1;if(f>-1&&c.length&&(!u||(c.prop(G.contextHash)||0)==h))return e.useNode(c,f),yt&&console.log(o+this.stackID(e)+` (via reuse of ${s.getName(c.type.id)})`),!0;if(!(c instanceof ue)||c.children.length==0||c.positions[0]>0)break;let p=c.children[0];if(p instanceof ue&&c.positions[0]==0)c=p;else break}}let l=s.stateSlot(e.state,4);if(l>0)return e.reduce(l),yt&&console.log(o+this.stackID(e)+` (via always-reduce ${s.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++],p=u==a.length||!n,m=p?e:e.split();if(m.apply(h,c,f),yt&&console.log(o+this.stackID(m)+` (via ${h&65536?`reduce of ${s.getName(h&65535)}`:"shift"} for ${s.getName(c)} @ ${r}${m==e?"":", split"})`),p)return!0;m.pos>r?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 hd(e,t),!0}}runRecovery(e,t,n){let r=null,s=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],u=t[(o<<1)+1],h=yt?this.stackID(l)+" -> ":"";if(l.deadEnd&&(s||(s=!0,l.restart(),yt&&console.log(h+this.stackID(l)+" (restarted)"),this.advanceFully(l,n))))continue;let c=l.split(),f=h;for(let p=0;c.forceReduce()&&p<10&&(yt&&console.log(f+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,n));p++)yt&&(f=this.stackID(c)+" -> ");for(let p of l.recoverByInsert(a))yt&&console.log(h+this.stackID(p)+" (via recover-insert)"),this.advanceFully(p,n);this.stream.end>l.pos?(u==l.pos&&(u++,a=0),l.recoverByDelete(a,u),yt&&console.log(h+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),hd(l,n)):(!r||r.score<l.score)&&(r=l)}return r}stackToTree(e){return e.close(),ue.build({buffer:Fi.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=(ba||(ba=new WeakMap)).get(e);return t||ba.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function hd(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 ka=class{constructor(e,t,n){this.source=e,this.flags=t,this.disabled=n}allows(e){return!this.disabled||this.disabled[e]==0}};var cn=class extends Di{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]),r=[];for(let l=0;l<t.length;l++)r.push([]);function s(l,a,u){r[l].push([a,a.deserialize(String(u))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=G[a]);for(let u=1;u<l.length;){let h=l[u++];if(h>=0)s(h,a,l[u++]);else{let c=l[u+-h];for(let f=-h;f>0;f--)s(l[u++],a,c);u++}}}this.nodeSet=new Un(t.map((l,a)=>Ae.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:r[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=Dr(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(cd),this.states=Dr(e.states,Uint32Array),this.data=Dr(e.stateData),this.goto=Dr(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new hn(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 r=new xa(this,e,t,n);for(let s of this.wrappers)r=s(r,e,t,n);return r}getGoto(e,t,n=!1){let r=this.goto;if(t>=r[0])return-1;for(let s=r[t+1];;){let o=r[s++],l=o&1,a=r[s++];if(l&&n)return a;for(let u=s+(o>>1);s<u;s++)if(r[s]==e)return a;if(l)return-1}}hasAction(e,t){let n=this.data;for(let r=0;r<2;r++)for(let s=this.stateSlot(e,r?2:1),o;;s+=3){if((o=n[s])==65535)if(n[s+1]==1)o=n[s=Ut(n,s+2)];else{if(n[s+1]==2)return Ut(n,s+2);break}if(o==t||o==0)return Ut(n,s+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=Ut(this.data,n+2);else return!1;if(t==Ut(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=Ut(this.data,n+2);else break;if(!(this.data[n+2]&1)){let r=this.data[n+1];t.some((s,o)=>o&1&&s==r)||t.push(this.data[n],r)}}return t}configure(e){let t=Object.assign(Object.create(cn.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 r=e.tokenizers.find(s=>s.from==n);return r?r.to:n})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((n,r)=>{let s=e.specializers.find(l=>l.from==n.external);if(!s)return n;let o=Object.assign(Object.assign({},n),{external:s.to});return t.specializers[r]=cd(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 s of e.split(" ")){let o=t.indexOf(s);o>=0&&(n[o]=!0)}let r=null;for(let s=0;s<t.length;s++)if(!n[s])for(let o=this.dialects[t[s]],l;(l=this.data[o++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[l]=1;return new ka(e,n,r)}static deserialize(e){return new cn(e)}};function Ut(i,e){return i[e]|i[e+1]<<16}function G0(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 cd(i){if(i.external){let e=i.extend?1:0;return(t,n)=>i.external(t,n)<<1|e}return i.get}var ty=Me(require("classnames"),1),Ma=require("react");var Q0=(()=>[_l(),pa(),Wl(),Rr(oa,{fallback:!0}),yr.of([...Qs,...ma])])();var Xs=cn.deserialize({version:14,states:"%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",stateData:"#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",goto:"#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",nodeNames:"\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,tokenData:"6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",tokenizers:[0,1],topRules:{Filter:[0,1]},tokenPrec:0});var HS=ln.define({name:"VuuFilterQuery",parser:Xs.configure({props:[Sr({Identifier:O.variableName,String:O.string,Or:O.emphasis,Operator:O.operator})]})});var Pt=require("@vuu-ui/vuu-utils");var $e,dd=class{constructor(){ie(this,$e,void 0)}setFilterCombinatorOp(e,t=z(this,$e)){(0,Pt.isMultiClauseFilter)(t)&&t.op===e||U(this,$e,{op:e,filters:[z(this,$e)]})}add(e){if(z(this,$e)===void 0)U(this,$e,e);else if((0,Pt.isMultiClauseFilter)(z(this,$e)))z(this,$e).filters.push(e);else throw Error("Invalid filter passed to FilterExpression")}setColumn(e,t=z(this,$e)){if((0,Pt.isMultiClauseFilter)(t)){let n=t.filters.at(-1);n&&this.setColumn(e,n)}else t&&(t.column=e)}setOp(e,t=z(this,$e)){if((0,Pt.isMultiClauseFilter)(t)){let n=t.filters.at(-1);n&&this.setOp(e,n)}else t&&(t.op=e)}setValue(e,t=z(this,$e)){var n;if((0,Pt.isMultiClauseFilter)(t)){let r=t.filters.at(-1);r&&this.setValue(e,r)}else(0,Pt.isMultiValueFilter)(t)?((n=t.values)!=null||(t.values=[]),t.values.push(e)):(0,Pt.isSingleValueFilter)(t)&&(t.value=e)}toJSON(e=z(this,$e)){return this.name?{...e,name:this.name}:e}};$e=new WeakMap;var J0=zt.define([{tag:O.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:O.comment,color:"green",fontStyle:"italic"}]),X0=Rr(J0);var Y0=q.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":{alignItems:"center",display:"flex",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)"}},".cm-completionIcon":{height:"18px",flex:"0 0 16px"},".cm-completionLabel":{flex:"1 1 auto"},".cm-completionIcon-filter":{position:"relative","&:after":{background:"var(--salt-text-secondary-foreground)",content:"''","-webkit-mask":"var(--svg-filter) center center/13px 13px","-webkit-mask-repeat":"no-repeat",position:"absolute",height:"18px",left:"0px",top:"0px",width:"16px"}}},{dark:!1});var Z0=require("react");var pd=require("react/jsx-runtime");var Ot=require("@vuu-ui/vuu-utils");var iy=["aggregate","viewport-update","columns","disabled","enabled","filter","groupBy","vuu-link-created","vuu-link-removed","vuu-links","vuu-menu","sort","subscribed"],md=i=>{let e=i.type;return iy.includes(e)};var gd="GET_TABLE_LIST",bd="GET_TABLE_META";var Ta=i=>i.type==="connection-status",yd=i=>typeof i.result<"u";function wd(){function i(d,g,y=[],S=[]){for(let T=0,V=d.length;T<V;T++)(g(d[T],T)?y:S).push(d[T]);return[y,S]}var e={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 t({from:d,to:g},y=0,S=Number.MAX_SAFE_INTEGER){if(y===0)return{from:d,to:Math.min(g,S)};if(d===0)return{from:d,to:Math.min(g+y,S)};{let T=g-d,V=Math.round(y/2),D=d-V<0,B=S-(g+V)<0;return D&&B?{from:0,to:S}:D?{from:0,to:T+y}:B?{from:Math.max(0,S-(T+y)),to:S}:{from:d-V,to:g+V}}}var n=(d,{from:g,to:y})=>d>=g&&d<y,r=class{constructor(d,g){this.from=d,this.to=g}isWithin(d){return n(d,this)}overlap(d,g){return d>=this.to||g<this.from?[0,0]:[Math.max(d,this.from),Math.min(g,this.to)]}copy(){return new r(this.from,this.to)}},{KEY:s}=e,o=String.fromCharCode(8200),l=String.fromCharCode(8199),a={DIGIT:l,TWO_DIGITS:l+l,THREE_DIGITS:l+l+l,FULL_PADDING:[null,o+l,o+l+l,o+l+l+l,o+l+l+l+l]},u=l+l+l+l+l+l+l+l+l,h={Enter:"Enter",Delete:"Delete"},c={Home:"Home",End:"End",ArrowRight:"ArrowRight",ArrowLeft:"ArrowLeft",ArrowDown:"ArrowDown",ArrowUp:"ArrowUp",Tab:"Tab"},f={F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"},p={...h,...c,...f},m=d=>{if(d.every(y=>typeof y=="number"))return d;let g=[];for(let y of d)if(typeof y=="number")g.push(y);else for(let S=y[0];S<=y[1];S++)g.push(S);return g},b=()=>{},w=class{constructor(d,g){let{buildEnv:y}=d||{};if(y==="production"){this.log=b,this.warn=b,this.error=b,this.group=b,this.groupCollapsed=b,this.groupEnd=b,this.assert=b,this.trace=b,this.debug=b,this.info=b,this.table=b;return}this.log=console.log.bind(console),this.warn=console.warn.bind(console),this.error=console.error.bind(console),this.group=console.group.bind(console),this.groupEnd=console.groupEnd.bind(console),this.groupCollapsed=console.groupCollapsed.bind(console),this.assert=console.assert.bind(console),this.trace=console.trace.bind(console),this.debug=console.debug.bind(console),this.info=console.info.bind(console),this.table=console.table.bind(console)}},v=new w({buildEnv:"production"}),A=/^ws(s)?:\/\/.+/,C={},k=Symbol("setWebsocket"),M=Symbol("connectionCallback");async function x(d,g){return _(d,g)}async function I(d){_(d.url,d[M],d)}async function _(d,g,y){let S=C[d]||(C[d]={attemptsRemaining:5,status:"disconnected"});try{g({type:"connection-status",status:"connecting"});let T=typeof y<"u",V=await R(d);v.log("%c\u26A1 %cconnected","font-size: 24px;color: green;font-weight: bold;","color:green; font-size: 14px;"),y!==void 0&&y[k](V);let D=y!=null?y:new j(V,d,g),B=T?"reconnected":"connected";return g({type:"connection-status",status:B}),D.status=B,D}catch{let T=--S.attemptsRemaining>0;if(g({type:"connection-status",status:"disconnected",reason:"failed to connect",retry:T}),T)return F(d,g,y,1e4);throw Error("Failed to establish connection")}}var F=(d,g,y,S)=>new Promise(T=>{setTimeout(()=>{T(_(d,g,y))},S)}),R=d=>new Promise((g,y)=>{let S=A.test(d)?d:`wss://${d}`,T=new WebSocket(S);T.onopen=()=>g(T),T.onerror=V=>y(V)}),P=()=>{v.warn("Connection cannot be closed, socket not yet opened")},H=d=>{v.warn("Message cannot be sent, socket closed",d)},N=d=>{try{return JSON.parse(d)}catch{throw Error(`Error parsing JSON response from server ${d}`)}},j=class{constructor(d,g,y){this.close=P,this.requiresLogin=!0,this.send=H,this.status="ready",this.url=g,this[M]=y,this[k](d)}reconnect(){I(this)}[k](d){let g=this[M];d.onmessage=T=>{let V=N(T.data);g(V)},d.onerror=()=>{v.error("%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"&&(I(this),this.send=S)},d.onclose=()=>{v.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"&&(I(this),this.send=S)};let y=T=>{d.send(JSON.stringify(T))},S=T=>{console.log("TODO queue message until websocket reconnected",{_msg:T})};this.send=y,this.close=()=>{v.log("[Connection] close websocket"),this.status="closed",d.close(),this.close=P,this.send=H}}},$="CHANGE_VP_SUCCESS",ee="CHANGE_VP_RANGE_SUCCESS",Oe="CLOSE_TREE_NODE",ne="CLOSE_TREE_SUCCESS",Y="CREATE_VP",ke="CREATE_VP_SUCCESS",Fe="DISABLE_VP",Ze="DISABLE_VP_SUCCESS",ht="ENABLE_VP",vt="ENABLE_VP_SUCCESS",kn="GET_VP_VISUAL_LINKS",qi="GET_VIEW_PORT_MENUS",Mn="HB",uo="HB_RESP",Lr="LOGIN",Vr="LOGIN_SUCCESS",X="OPEN_TREE_NODE",be="OPEN_TREE_SUCCESS",ze="REMOVE_VP",Ie="RPC_RESP",ei="SET_SELECTION_SUCCESS",ti="TABLE_META_RESP",ji="TABLE_LIST_RESP",Nr="TABLE_ROW",Br=(d,g,y,S)=>{let T=S*.25;return!d||!S||d.to-y<T?!0:d.from>0&&g-d.from<T},Fr=[],ho=class{constructor({from:d,to:g},{from:y,to:S},T){this.setRowCount=V=>{if(V<this.internalData.length&&(this.internalData.length=V),V<this.rowCount){this.rowsWithinRange=0;let D=Math.min(V,this.clientRange.to);for(let B=this.clientRange.from;B<D;B++){let Z=B-this.range.from;this.internalData[Z]!==void 0&&(this.rowsWithinRange+=1)}}this.rowCount=V},this.bufferSize=T,this.clientRange=new r(d,g),this.range=new r(y,S),this.internalData=new Array(T),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(d,g){let y=this.isWithinClientRange(d);if(y||this.isWithinRange(d)){let S=d-this.range.from;!this.internalData[S]&&y&&(this.rowsWithinRange+=1),this.internalData[S]=g}return y}getAtIndex(d){return this.range.isWithin(d)&&this.internalData[d-this.range.from]!=null?this.internalData[d-this.range.from]:void 0}isWithinRange(d){return this.range.isWithin(d)}isWithinClientRange(d){return this.clientRange.isWithin(d)}setClientRange(d,g){let y=this.clientRange.from,S=Math.min(this.clientRange.to,this.rowCount);if(d===y&&g===S)return[!1,Fr];let T=this.clientRange.copy();this.clientRange.from=d,this.clientRange.to=g,this.rowsWithinRange=0;for(let B=d;B<g;B++){let Z=B-this.range.from;this.internalData[Z]&&(this.rowsWithinRange+=1)}let V=Fr,D=this.range.from;if(this.hasAllRowsWithinRange)if(g>T.to){let B=Math.max(d,T.to);V=this.internalData.slice(B-D,g-D)}else{let B=Math.min(T.from,g);V=this.internalData.slice(d-D,B-D)}return[Br(this.range,d,g,this.bufferSize),V]}setRange(d,g){let[y,S]=this.range.overlap(d,g),T=new Array(g-d+this.bufferSize);this.rowsWithinRange=0;for(let V=y;V<S;V++){let D=this.getAtIndex(V);if(D){let B=V-d;T[B]=D,this.isWithinClientRange(V)&&(this.rowsWithinRange+=1)}}this.internalData=T,this.range.from=d,this.range.to=g}getData(){var d;let{from:g,to:y}=this.range,{from:S,to:T}=this.clientRange,V=Math.max(0,S-g),D=Math.min(y-g,y,T-g,(d=this.rowCount)!=null?d:y);return this.internalData.slice(V,D)}getCurrentDataRange(){let d=this.internalData,g=d.length,[y]=this.internalData,S=this.internalData[g-1];if(y&&S)return[y.rowIndex,S.rowIndex];for(let T=0;T<g;T++)if(d[T]!==void 0){y=d[T];break}for(let T=g-1;T>=0;T--)if(d[T]!==void 0){S=d[T];break}return y&&S?[y.rowIndex,S.rowIndex]:[-1,-1]}},co=class{constructor(d){this.keys=new Map,this.free=[],this.nextKeyValue=0,this.reset(d)}next(){return this.free.length>0?this.free.pop():this.nextKeyValue++}reset({from:d,to:g}){this.keys.forEach((S,T)=>{(T<d||T>=g)&&(this.free.push(S),this.keys.delete(T))});let y=g-d;this.keys.size+this.free.length>y&&(this.free.length=y-this.keys.size);for(let S=d;S<g;S++)if(!this.keys.has(S)){let T=this.next();this.keys.set(S,T)}}keyFor(d){let g=this.keys.get(d);if(g===void 0)throw console.log(`key not found
11
- keys: ${Object.entries(this.keys).map((y,S)=>`${y}=>${S}`).join(", ")}
12
- free : ${this.free.join(",")}
13
- `),Error(`KeySet, no key found for rowIndex ${d}`);return g}},fo=[],po=class{constructor({aggregations:d,bufferSize:g=50,columns:y,filter:S,groupBy:T=[],table:V,range:D,sort:B,title:Z,viewport:Le,visualLink:Ue}){this.dataWindow=void 0,this.hasUpdates=!1,this.pendingUpdates=[],this.pendingOperations=new Map,this.pendingRangeRequest=null,this.rowCountChanged=!1,this.serverTableMeta=null,this.batchMode=!0,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},this.aggregations=d,this.bufferSize=g,this.clientRange=D,this.clientViewportId=Le,this.columns=y,this.filter=S,this.groupBy=T,this.keys=new co(D),this.pendingLinkedParent=Ue,this.table=V,this.sort=B,this.title=Z}get hasUpdatesToProcess(){return this.suspended?!1:this.rowCountChanged||this.hasUpdates}get size(){var d,g;return(g=(d=this.dataWindow)==null?void 0:d.rowCount)!=null?g:0}subscribe(){let{filter:d}=this.filter;return this.status=this.status==="subscribed"?"resubscribing":"subscribing",{type:Y,table:this.table,range:t(this.clientRange,this.bufferSize),aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:d}}}handleSubscribed({viewPortId:d,aggregations:g,columns:y,filterSpec:S,range:T,sort:V,groupBy:D}){return this.serverViewportId=d,this.status="subscribed",this.aggregations=g,this.columns=y,this.groupBy=D,this.isTree=D&&D.length>0,this.dataWindow=new ho(this.clientRange,T,this.bufferSize),{aggregations:g,type:"subscribed",clientViewportId:this.clientViewportId,columns:y,filter:S,groupBy:D,range:T,sort:V,tableMeta:this.serverTableMeta}}awaitOperation(d,g){this.pendingOperations.set(d,g)}completeOperation(d,...g){var y;let{clientViewportId:S,pendingOperations:T}=this,V=T.get(d);if(!V){v.warn("Viewport no matching operation found to complete");return}let{type:D}=V;if(T.delete(d),D==="CHANGE_VP_RANGE"){let[B,Z]=g;(y=this.dataWindow)==null||y.setRange(B,Z),this.pendingRangeRequest=null}else{if(D==="groupBy")return this.isTree=V.data.length>0,this.groupBy=V.data,{clientViewportId:S,type:D,groupBy:V.data};if(D==="columns")return this.columns=V.data,{clientViewportId:S,type:D,columns:V.data};if(D==="filter")return this.filter=V.data,{clientViewportId:S,type:D,filter:V.data};if(D==="aggregate")return this.aggregations=V.data,{clientViewportId:S,type:"aggregate",aggregations:this.aggregations};if(D==="sort")return this.sort=V.data,{clientViewportId:S,type:D,sort:this.sort};if(D!=="selection"){if(D==="disable")return this.disabled=!0,{type:"disabled",clientViewportId:S};if(D==="enable")return this.disabled=!1,{type:"enabled",clientViewportId:S};if(D==="CREATE_VISUAL_LINK"){let[B,Z,Le]=g;return this.linkedParent={colName:B,parentViewportId:Z,parentColName:Le},this.pendingLinkedParent=void 0,{type:"vuu-link-created",clientViewportId:S,colName:B,parentViewportId:Z,parentColName:Le}}else if(D==="REMOVE_VISUAL_LINK")return this.linkedParent=void 0,{type:"vuu-link-removed",clientViewportId:S}}}}rangeRequest(d,g){let y="CHANGE_VP_RANGE";if(this.dataWindow){let[S,T]=this.dataWindow.setClientRange(g.from,g.to),V=S&&Br(this.pendingRangeRequest,g.from,g.to,this.bufferSize)?{type:y,viewPortId:this.serverViewportId,...t(g,this.bufferSize,this.dataWindow.rowCount)}:null;V?(this.awaitOperation(d,{type:y}),this.pendingRangeRequest=V,this.batchMode=!0):T.length>0&&(this.batchMode=!1),this.keys.reset(this.dataWindow.clientRange);let D=this.isTree?mo:Qi;return T.length?[V,T.map(B=>D(B,this.keys))]:[V]}else return[null]}setLinks(d){return this.links=d,[{type:"vuu-links",links:d,clientViewportId:this.clientViewportId},this.pendingLinkedParent]}setMenu(d){return{type:"vuu-menu",menu:d,clientViewportId:this.clientViewportId}}setTableMeta(d,g){this.serverTableMeta={columns:d,dataTypes:g}}openTreeNode(d,g){return this.batchMode=!0,{type:X,vpId:this.serverViewportId,treeKey:g.key}}closeTreeNode(d,g){return this.batchMode=!0,{type:Oe,vpId:this.serverViewportId,treeKey:g.key}}createLink(d,g,y,S){let T={type:"CREATE_VISUAL_LINK",parentVpId:y,childVpId:this.serverViewportId,parentColumnName:S,childColumnName:g};return this.awaitOperation(d,T),T}removeLink(d){let g={type:"REMOVE_VISUAL_LINK",childVpId:this.serverViewportId};return this.awaitOperation(d,g),g}suspend(){this.suspended=!0}resume(){return this.suspended=!1,this.currentData()}currentData(){let d=[];if(this.dataWindow){let g=this.dataWindow.getData(),{keys:y}=this,S=this.isTree?mo:Qi;for(let T of g)T&&d.push(S(T,y))}return d}enable(d){return this.awaitOperation(d,{type:"enable"}),{type:ht,viewPortId:this.serverViewportId}}disable(d){return this.awaitOperation(d,{type:"disable"}),{type:Fe,viewPortId:this.serverViewportId}}columnRequest(d,g){return this.awaitOperation(d,{type:"columns",data:g}),this.createRequest({columns:g})}filterRequest(d,g){this.awaitOperation(d,{type:"filter",data:g});let{filter:y}=g;return this.createRequest({filterSpec:{filter:y}})}aggregateRequest(d,g){return this.awaitOperation(d,{type:"aggregate",data:g}),this.createRequest({aggregations:g})}sortRequest(d,g){return this.awaitOperation(d,{type:"sort",data:g}),this.createRequest({sort:g})}groupByRequest(d,g=fo){return this.awaitOperation(d,{type:"groupBy",data:g}),this.batchMode=!0,this.createRequest({groupBy:g})}selectRequest(d,g){return this.awaitOperation(d,{type:"selection",data:g}),{type:"SET_SELECTION",vpId:this.serverViewportId,selection:m(g)}}handleUpdate(d,g,y){this.dataWindow&&(this.dataWindow.rowCount!==y.vpSize&&(this.dataWindow.setRowCount(y.vpSize),this.rowCountChanged=!0),d==="U"&&this.dataWindow.setAtIndex(g,y)&&(this.hasUpdates=!0,this.batchMode||this.pendingUpdates.push(y)))}getClientRows(){let d,g="size-only";if(this.hasUpdates&&this.dataWindow){let{keys:y}=this,S=this.isTree?mo:Qi;if(this.pendingUpdates.length>0){d=[],g="update";for(let T of this.pendingUpdates)d.push(S(T,y));this.pendingUpdates.length=0}else{let T=this.dataWindow.getData();if(this.dataWindow.hasAllRowsWithinRange){d=[],g="batch";for(let V of T)d.push(S(V,y));this.batchMode=!1}}this.hasUpdates=!1}return[d,g]}createRequest(d){return{type:"CHANGE_VP",viewPortId:this.serverViewportId,aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:this.filter.filter},...d}}},Qi=({rowIndex:d,rowKey:g,sel:y,data:S},T)=>[d,T.keyFor(d),!0,null,null,1,g,y].concat(S),mo=({rowIndex:d,rowKey:g,sel:y,data:S},T)=>{let[V,D,,B,,Z,...Le]=S;return[d,T.keyFor(d),B,D,V,Z,g,y].concat(Le)},bp=d=>{switch(d){case"TypeAheadRpcHandler":return"TYPEAHEAD";default:return"SIMUL"}},yp=d=>d.type==="connection-status",wp=d=>"viewport"in d,vp=["VIEW_PORT_MENUS_SELECT_RPC","VIEW_PORT_MENU_TABLE_RPC","VIEW_PORT_MENU_ROW_RPC","VIEW_PORT_MENU_CELL_RPC"],Cp=d=>vp.includes(d.type),Za=({requestId:d,...g})=>[d,g],eu=1,He=()=>`${eu++}`,Sp={},xp=d=>d.disabled!==!0&&d.suspended!==!0,kp=(d,g,y)=>d.map(S=>S.parentVpId===g?{...S,label:y}:S);function Mp(d,g){return d.map(y=>{let{parentVpId:S}=y,T=g.get(S);if(T)return{...y,parentClientVpId:T.clientViewportId,label:T.title};throw Error("addLabelsToLinks viewport not found")})}var Tp=class{constructor(d,g){this.authToken="",this.pendingTableMetaRequests=new Map,this.queuedRequests=[],this.cachedTableMeta=new Map,this.connection=d,this.postMessageToClient=g,this.viewports=new Map,this.mapClientToServerViewport=new Map}async reconnect(){await this.login(this.authToken);let[d,g]=i(Array.from(this.viewports.values()),xp);this.viewports.clear(),this.mapClientToServerViewport.clear();let y=S=>{S.forEach(T=>{let{clientViewportId:V}=T;this.viewports.set(V,T),this.sendMessageToServer(T.subscribe(),V)})};y(d),setTimeout(()=>{y(g)},2e3)}async login(d){if(d)return this.authToken=d,new Promise((g,y)=>{this.sendMessageToServer({type:Lr,token:this.authToken,user:"user"},""),this.pendingLogin={resolve:g,reject:y}});this.authToken===""&&console.warn("ServerProxy login, cannot login until auth token has been obtained")}subscribe(d){if(this.mapClientToServerViewport.has(d.viewport))v.error(`ServerProxy spurious subscribe call ${d.viewport}`);else{if(!this.hasMetaDataFor(d.table)){v.info("Get Meta Data Message (Client to Server): ",d);let y=He();this.sendMessageToServer({type:"GET_TABLE_META",table:d.table},y),this.pendingTableMetaRequests.set(y,d.viewport)}let g=new po(d);this.viewports.set(d.viewport,g),this.sendIfReady(g.subscribe(),d.viewport,this.sessionId!=="")}}unsubscribe(d){let g=this.mapClientToServerViewport.get(d);g?(v.log("Viewport Unsubscribe Message (Client to Server): ",g),this.sendMessageToServer({type:ze,viewPortId:g})):console.error(`ServerProxy: failed to unsubscribe client viewport ${d}, viewport not found`)}getViewportForClient(d,g=!0){let y=this.mapClientToServerViewport.get(d);if(y){let S=this.viewports.get(y);if(S)return S;if(g)throw Error(`Viewport not found for client viewport ${d}`);return null}else{if(this.viewports.has(d))return this.viewports.get(d);if(g)throw Error(`Viewport server id not found for client viewport ${d}`);return null}}setViewRange(d,g){let y=He(),[S,T]=d.rangeRequest(y,g.range);S&&this.sendIfReady(S,y,d.status==="subscribed"),T&&this.postMessageToClient({mode:"batch",type:"viewport-update",clientViewportId:d.clientViewportId,rows:T})}aggregate(d,g){let y=He(),S=d.aggregateRequest(y,g.aggregations);this.sendIfReady(S,y,d.status==="subscribed")}sort(d,g){let y=He(),S=d.sortRequest(y,g.sort);this.sendIfReady(S,y,d.status==="subscribed")}groupBy(d,g){let y=He(),S=d.groupByRequest(y,g.groupBy);this.sendIfReady(S,y,d.status==="subscribed")}filter(d,g){let y=He(),{filter:S}=g,T=d.filterRequest(y,S);this.sendIfReady(T,y,d.status==="subscribed")}setColumns(d,g){let y=He(),{columns:S}=g,T=d.columnRequest(y,S);this.sendIfReady(T,y,d.status==="subscribed")}setTitle(d,g){d&&(d.title=g.title,this.updateTitleOnVisualLinks(d))}select(d,g){let y=He(),{selected:S}=g,T=d.selectRequest(y,S);this.sendIfReady(T,y,d.status==="subscribed")}disableViewport(d){let g=He(),y=d.disable(g);this.sendIfReady(y,g,d.status==="subscribed")}enableViewport(d){let g=He(),y=d.enable(g);this.sendIfReady(y,g,d.status==="subscribed")}resumeViewport(d){let g=d.resume();this.postMessageToClient({clientViewportId:d.clientViewportId,rows:g,type:"viewport-update"})}openTreeNode(d,g){if(d.serverViewportId){let y=He();this.sendIfReady(d.openTreeNode(y,g),y,d.status==="subscribed")}}closeTreeNode(d,g){if(d.serverViewportId){let y=He();this.sendIfReady(d.closeTreeNode(y,g),y,d.status==="subscribed")}}createLink(d,g){let{parentClientVpId:y,parentColumnName:S,childColumnName:T}=g,V=He(),D=this.mapClientToServerViewport.get(y);if(D){let B=d.createLink(V,T,D,S);this.sendMessageToServer(B,V)}else console.warn("ServerProxy unable to create link, viewport not found")}removeLink(d){let g=He(),y=d.removeLink(g);this.sendMessageToServer(y,g)}updateTitleOnVisualLinks(d){var g;let{serverViewportId:y,title:S}=d;for(let T of this.viewports.values())if(T!==d&&T.links&&y&&S&&(g=T.links)!=null&&g.some(V=>V.parentVpId===y)){let[V]=T.setLinks(kp(T.links,y,S));this.postMessageToClient(V)}}removeViewportFromVisualLinks(d){var g;for(let y of this.viewports.values())if((g=y.links)!=null&&g.some(({parentVpId:S})=>S===d)){let[S]=y.setLinks(y.links.filter(({parentVpId:T})=>T!==d));this.postMessageToClient(S)}}menuRpcCall(d){let g=this.getViewportForClient(d.vpId,!1);if(g!=null&&g.serverViewportId){let[y,S]=Za(d);this.sendMessageToServer({...S,vpId:g.serverViewportId},y)}}rpcCall(d){let[g,y]=Za(d),S=bp(y.service);this.sendMessageToServer(y,g,{module:S})}handleMessageFromClient(d){if(wp(d))if(d.type==="disable"){let g=this.getViewportForClient(d.viewport,!1);return g!==null?(v.log("Disable Message From Client: ",d),this.disableViewport(g)):void 0}else{let g=this.getViewportForClient(d.viewport);switch(v.log(`${d.type} Message From Client: `,d),d.type){case"setViewRange":return this.setViewRange(g,d);case"aggregate":return this.aggregate(g,d);case"sort":return this.sort(g,d);case"groupBy":return this.groupBy(g,d);case"filter":return this.filter(g,d);case"select":return this.select(g,d);case"suspend":return g.suspend();case"resume":return this.resumeViewport(g);case"enable":return this.enableViewport(g);case"openTreeNode":return this.openTreeNode(g,d);case"closeTreeNode":return this.closeTreeNode(g,d);case"createLink":return this.createLink(g,d);case"removeLink":return this.removeLink(g);case"setColumns":return this.setColumns(g,d);case"setTitle":return this.setTitle(g,d);default:}}else{if(Cp(d))return this.menuRpcCall(d);{let{type:g,requestId:y}=d;switch(g){case"GET_TABLE_LIST":return v.log("Get Table List Message (Client to Server)",d),this.sendMessageToServer({type:g},y);case"GET_TABLE_META":return this.sendMessageToServer({type:g,table:d.table},y);case"RPC_CALL":return this.rpcCall(d);default:}}}v.error(`Vuu ServerProxy Unexpected message from client ${JSON.stringify(d)}`)}sendIfReady(d,g,y=!0){return y?this.sendMessageToServer(d,g):this.queuedRequests.push(d),y}sendMessageToServer(d,g=`${eu++}`,y=Sp){let{module:S="CORE"}=y;this.authToken&&this.connection.send({requestId:g,sessionId:this.sessionId,token:this.authToken,user:"user",module:S,body:d})}handleMessageFromServer(d){var g;let{body:y,requestId:S,sessionId:T}=d,{viewports:V}=this;switch(y.type){case Mn:this.sendMessageToServer({type:uo,ts:+new Date},"NA");break;case Vr:if(T)this.sessionId=T,(g=this.pendingLogin)==null||g.resolve(T),this.pendingLogin=void 0;else throw Error("LOGIN_SUCCESS did not provide sessionId ");break;case ke:{let D=V.get(S);if(D){let{status:B}=D,{viewPortId:Z}=y;S!==Z&&(V.delete(S),V.set(Z,D)),this.mapClientToServerViewport.set(S,Z);let Le=D.handleSubscribed(y);Le&&(v.info("Subscribe Response (ServerProxy to Client): ",Le),this.postMessageToClient(Le)),D.disabled&&this.disableViewport(D),B==="subscribing"&&(this.sendMessageToServer({type:kn,vpId:Z}),this.sendMessageToServer({type:qi,vpId:Z}),Array.from(V.entries()).filter(([Ue,{disabled:Jt}])=>Ue!==Z&&!Jt).forEach(([Ue])=>{this.sendMessageToServer({type:kn,vpId:Ue})}))}}break;case"REMOVE_VP_SUCCESS":{let D=this.viewports.get(y.viewPortId);D&&(this.mapClientToServerViewport.delete(D.clientViewportId),V.delete(y.viewPortId),this.removeViewportFromVisualLinks(y.viewPortId))}break;case ei:{let D=this.viewports.get(y.vpId);D&&D.completeOperation(S)}break;case $:case Ze:if(V.has(y.viewPortId)){let D=this.viewports.get(y.viewPortId);if(D){let B=D.completeOperation(S);B!==void 0&&(v.info("Disable Response (ServerProxy to Client): ",B),this.postMessageToClient(B))}}break;case vt:{let D=this.viewports.get(y.viewPortId);if(D){let B=D.completeOperation(S);if(B){this.postMessageToClient(B);let Z=D.currentData();v.info("Enable Response (ServerProxy to Client): ",B),this.postMessageToClient({clientViewportId:D.clientViewportId,mode:"batch",rows:Z,size:D.size,type:"viewport-update"})}}}break;case Nr:{for(let D of y.rows){let{viewPortId:B,rowIndex:Z,rowKey:Le,updateType:Ue}=D,Jt=V.get(B);Jt?Jt.isTree&&Ue==="U"&&!Le.startsWith("$root")||Jt.handleUpdate(Ue,Z,D):console.warn(`TABLE_ROW message received for non registered viewport ${B}`)}this.processUpdates()}break;case ee:{let D=this.viewports.get(y.viewPortId);if(D){let{from:B,to:Z}=y;D.completeOperation(S,B,Z)}}break;case be:case ne:break;case"CREATE_VISUAL_LINK_SUCCESS":{let D=this.viewports.get(y.childVpId),B=this.viewports.get(y.parentVpId);if(D&&B){let{childColumnName:Z,parentColumnName:Le}=y,Ue=D.completeOperation(S,Z,B.clientViewportId,Le);Ue&&this.postMessageToClient(Ue)}}break;case"REMOVE_VISUAL_LINK_SUCCESS":{let D=this.viewports.get(y.childVpId);if(D){let B=D.completeOperation(S);B&&this.postMessageToClient(B)}}break;case ji:this.postMessageToClient({type:ji,tables:y.tables,requestId:S});break;case ti:{this.cacheTableMeta(y.table,y.columns,y.dataTypes);let D=this.pendingTableMetaRequests.get(S);if(D){this.pendingTableMetaRequests.delete(S);let B=this.viewports.get(D);B?B.setTableMeta(y.columns,y.dataTypes):v.warn("Message has come back AFTER CREATE_VP_SUCCESS, what do we do now")}else this.postMessageToClient({type:ti,table:y.table,columns:y.columns,dataTypes:y.dataTypes,requestId:S})}break;case"VP_VISUAL_LINKS_RESP":{let D=this.getActiveLinks(y.links),B=this.viewports.get(y.vpId);if(D.length&&B){let Z=Mp(D,this.viewports),[Le,Ue]=B.setLinks(Z);if(this.postMessageToClient(Le),Ue){let{link:Jt,parentClientVpId:Ep}=Ue,tu=He(),nu=this.mapClientToServerViewport.get(Ep);if(nu){let Pp=B.createLink(tu,Jt.fromColumn,nu,Jt.toColumn);this.sendMessageToServer(Pp,tu)}}}}break;case"VIEW_PORT_MENUS_RESP":if(y.menu.name){let D=this.viewports.get(y.vpId);if(D){let B=D.setMenu(y.menu);this.postMessageToClient(B)}}break;case"VIEW_PORT_MENU_RESP":{let{action:D}=y;this.postMessageToClient({type:"VIEW_PORT_MENU_RESP",action:D,tableAlreadyOpen:this.isTableOpen(D.table),requestId:S})}break;case Ie:{let{method:D,result:B}=y;this.postMessageToClient({type:Ie,method:D,result:B,requestId:S})}break;case"ERROR":v.error(y.msg);break;default:v.log(`handleMessageFromServer ${y.type}.`)}}hasMetaDataFor(d){return this.cachedTableMeta.has(`${d.module}:${d.table}`)}cacheTableMeta(d,g,y){this.hasMetaDataFor(d)||this.cachedTableMeta.set(`${d.module}:${d.table}`,{columns:g,serverDataTypes:y})}isTableOpen(d){if(d){let g=d.table;for(let y of this.viewports.values())if(!y.suspended&&y.table.table===g)return!0}}getActiveLinks(d){return d.filter(g=>{let y=this.viewports.get(g.parentVpId);return y&&!y.suspended})}processUpdates(){this.viewports.forEach(d=>{if(d.hasUpdatesToProcess){let[g,y]=d.getClientRows(),S=d.getNewRowCount();(S!==void 0||g&&g.length>0)&&this.postMessageToClient({clientViewportId:d.clientViewportId,mode:y,rows:g,size:S,type:"viewport-update"})}})}},Tn;async function Rp(d,g,y){let S=await x(d,T=>{yp(T)?(y(T),T.status==="reconnected"&&Tn.reconnect()):Tn.handleMessageFromServer(T)});Tn=new Tp(S,T=>Ap(T)),S.requiresLogin&&await Tn.login(g)}function Ap(d){postMessage(d)}var Dp=async({data:d})=>{switch(d.type){case"connect":await Rp(d.url,d.token,postMessage),postMessage({type:"connected"});break;case"subscribe":v.info("Subscribe Message From Client: ",d),Tn.subscribe(d);break;case"unsubscribe":v.info("Unsubscribe Message From Client: ",d),Tn.unsubscribe(d.viewport);break;default:v.info("Message From Client: ",d),Tn.handleMessageFromClient(d)}};self.addEventListener("message",Dp),postMessage({type:"ready"})}var sy=wd.toString().replace(/(?:^function(?:\s+[^(]*)?\(\)\s*\{)|(?:\}$)/g,""),oy=new Blob([sy],{type:"text/javascript"}),ly=URL.createObjectURL(oy),Hi,Ra,Aa=[],ay,uy,hy=new Promise((i,e)=>{ay=i,uy=e}),eo=()=>hy,Ys=new Map,Zs=new Map,cy=async(i,e="",t)=>e===""&&Ra===void 0?new Promise(n=>{Aa.push({resolve:n})}):Ra||(Ra=new Promise(n=>{let r=new Worker(ly),s=window.setTimeout(()=>{Ot.logger.error("timed out waiting for worker to load")},1e3);r.onmessage=o=>{let{data:l}=o;if(l.type==="ready")window.clearTimeout(s),r.postMessage({type:"connect",url:i,token:e});else if(l.type==="connected"){r.onmessage=vd,n(r);for(let a of Aa)a.resolve(r);Aa.length=0}else Ta(l)?t(o):Ot.logger.warn("ConnectionManager: Unexpected message from the worker")}}));function vd({data:i}){if(Ta(i))Cd.emit("connection-status",i);else if(md(i)){let e=Ys.get(i.clientViewportId);e?e.postMessageToClientDataSource(i):Ot.logger.error(`[ConnectionManager] ${i.type} message received, viewport not found`)}else{let e=i.requestId;if(Zs.has(e)){let{resolve:t}=Zs.get(e);Zs.delete(e);let{type:n,requestId:r,...s}=i;yd(i)?t(i.result):t(s)}else Ot.logger.warn("%cConnectionManager Unexpected message from the worker","color:red;font-weight:bold;")}}var Da=i=>{let e=(0,Ot.uuid)();return Hi.postMessage({requestId:e,...i}),new Promise((t,n)=>{Zs.set(e,{resolve:t,reject:n})})},fy={subscribe:(i,e)=>{Ys.set(i.viewport,{status:"subscribing",request:i,postMessageToClientDataSource:e}),Hi.postMessage({type:"subscribe",...i})},unsubscribe:i=>{Hi.postMessage({type:"unsubscribe",viewport:i})},send:i=>{Hi.postMessage(i)},destroy:i=>{i&&Ys.has(i)&&Ys.delete(i)},rpcCall:async i=>Da(i),getTableList:async()=>Da({type:gd}),getTableMeta:async i=>Da({type:bd,table:i})},Ea=class extends Ot.EventEmitter{async connect(e,t){return Hi=await cy(e,t,vd),fy}destroy(){Ot.logger.log("MEGA DESTROY"),Hi.terminate()}},Cd=new Ea;var to=require("@vuu-ui/vuu-utils"),Er=require("react"),{SELECTED:Qx}=to.metadataKeys;var Pa=require("react");var py=require("react");var Oa=require("@vuu-ui/vuu-utils");var my=require("react");var{KEY:ok}=Oa.metadataKeys;var gy=i=>i.type==="vuu-links";var by=i=>i.type==="vuu-menu",Sd=i=>by(i)||gy(i),xd=i=>i.type==="vuu-link-created"||i.type==="vuu-link-removed";var Ia=require("react");var no=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((r,s)=>{(s<e||s>=t)&&(this.free.push(r),this.keys.delete(s))});let n=t-e;this.keys.size+this.free.length>n&&(this.free.length=n-this.keys.size);for(let r=e;r<t;r++)if(!this.keys.has(r)){let s=this.next();this.keys.set(r,s)}}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,r)=>`${n}=>${r}`).join(", ")}
15
- free : ${this.free.join(",")}
16
- `),Error(`KeySet, no key found for rowIndex ${e}`);return t}};var $t=require("@vuu-ui/vuu-utils");var{IDX:yy,SELECTED:kd}=$t.metadataKeys,wy=(i,e)=>[e,e,!0,!1,1,0,i[0],0,...i],vy=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},Cy=(i,e)=>{let[t]=i,n=i.slice();return n[1]=e.keyFor(t),n},fn,dn,Kt,pn,mn,gn,io,ro,bn,Wi,Md=class extends $t.EventEmitter{constructor({aggregations:t,columnDescriptors:n,columns:r,data:s,filter:o,groupBy:l,sort:a,title:u,viewport:h}){super();this.status="initialising";this.disabled=!1;this.suspended=!1;ie(this,fn,[]);ie(this,dn,[]);ie(this,Kt,void 0);ie(this,pn,{filter:""});ie(this,mn,[]);ie(this,gn,{from:0,to:0});ie(this,io,0);ie(this,ro,0);ie(this,bn,{sortDefs:[]});ie(this,Wi,void 0);this.keys=new no(z(this,gn));if(!s||!n)throw Error("ArrayDataSource constructor called without data");this.columnDescriptors=n,this.tableMeta=vy(n),U(this,Kt,s.map(wy)),this.viewport=h||(0,$t.uuid)(),t&&U(this,fn,t),r&&U(this,dn,r),o&&U(this,pn,o),l&&U(this,mn,l),a&&U(this,bn,a),U(this,Wi,u)}async subscribe({viewport:t=(h=>(h=this.viewport)!=null?h:(0,$t.uuid)())(),columns:n,aggregations:r,range:s,sort:o,groupBy:l,filter:a},u){var c;this.clientCallback=u,console.log(`subscribe range ${s==null?void 0:s.from} ${s==null?void 0:s.to}`),r&&U(this,fn,r),n&&U(this,dn,n),a&&U(this,pn,a),l&&U(this,mn,l),s&&U(this,gn,s),o&&U(this,bn,o),this.status==="initialising"&&(this.viewport=t,this.status="subscribed",(c=this.clientCallback)==null||c.call(this,{aggregations:z(this,fn),type:"subscribed",clientViewportId:this.viewport,columns:z(this,dn),filter:z(this,pn),groupBy:z(this,mn),range:z(this,gn),sort:z(this,bn),tableMeta:this.tableMeta}),this.clientCallback({clientViewportId:this.viewport,type:"viewport-update",size:z(this,Kt).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){var r;let n=[];for(let s of z(this,Kt)){let{[yy]:o,[kd]:l}=s,a=l===1,u=(0,$t.isSelected)(t,o);if(u!==a){let h=s.slice();h[kd]=u?1:0,z(this,Kt)[o]=h,n.push(h)}}n.length>0&&((r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",type:"viewport-update",rows:n}))}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 z(this,io)}get size(){return z(this,ro)}get range(){return z(this,gn)}set range(t){U(this,gn,t),this.keys.reset(t),requestAnimationFrame(()=>{var n;(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,rows:z(this,Kt).slice(t.from,t.to).map(r=>Cy(r,this.keys)),size:z(this,Kt).length,type:"viewport-update"})})}get columns(){return z(this,dn)}set columns(t){U(this,dn,t),console.log(`ArrayDataSource setColumns ${t.join(",")}`)}get aggregations(){return z(this,fn)}set aggregations(t){U(this,fn,t)}get sort(){return z(this,bn)}set sort(t){U(this,bn,t)}get filter(){return z(this,pn)}set filter(t){U(this,pn,t),console.log(`RemoteDataSource ${JSON.stringify(t)}`)}get groupBy(){return z(this,mn)}set groupBy(t){U(this,mn,t)}get title(){return z(this,Wi)}set title(t){U(this,Wi,t)}createLink({parentVpId:t,link:{fromColumn:n,toColumn:r}}){console.log("create link",{parentVpId:t,fromColumn:n,toColumn:r})}removeLink(){console.log("remove link")}async menuRpcCall(t){console.log("rmenuRpcCall",{rpcRequest:t})}};fn=new WeakMap,dn=new WeakMap,Kt=new WeakMap,pn=new WeakMap,mn=new WeakMap,gn=new WeakMap,io=new WeakMap,ro=new WeakMap,bn=new WeakMap,Wi=new WeakMap;var so=require("@vuu-ui/vuu-utils");var yn,wn,_i,vn,Gt,qn,Pr,zi,Cn,jn,Ui,Td=class extends so.EventEmitter{constructor({bufferSize:t=100,aggregations:n,columns:r,filter:s,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,yn,[]);ie(this,wn,[]);ie(this,_i,void 0);ie(this,vn,{filter:""});ie(this,Gt,[]);ie(this,qn,{from:0,to:0});ie(this,Pr,0);ie(this,zi,0);ie(this,Cn,{sortDefs:[]});ie(this,jn,void 0);ie(this,Ui,void 0);this.handleMessageFromServer=t=>{var n,r;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!==z(this,zi)&&(this.rowCount=t.size,U(this,zi,t.size)),(r=this.clientCallback)==null||r.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&&U(this,yn,n),r&&U(this,wn,r),s&&U(this,vn,s),o&&U(this,Gt,o),a&&U(this,Cn,a),U(this,jn,h),U(this,Ui,f),this.refreshConfig()}async subscribe({viewport:t=(h=>(h=this.viewport)!=null?h:(0,so.uuid)())(),columns:n,aggregations:r,range:s,sort:o,groupBy:l,filter:a},u){var f;if(this.clientCallback=u,r&&U(this,yn,r),n&&U(this,wn,n),a&&U(this,vn,a),l&&U(this,Gt,l),s&&U(this,qn,s),o&&U(this,Cn,o),this.status!=="initialising")return;this.status="subscribing",this.viewport=t,this.server=await eo();let{bufferSize:c}=this;(f=this.server)==null||f.subscribe({aggregations:z(this,yn),bufferSize:c,columns:z(this,wn),filter:z(this,vn),groupBy:z(this,Gt),viewport:t,table:this.table,range:z(this,qn),sort:z(this,Cn),title:z(this,jn),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;U(this,Pr,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:r,groupBy:s,sort:o,visualLink:l}=this,a=t.length>0,u=n.length>0,h=r.filter!=="",c=s.length>0,f=o.sortDefs.length>0,p=l!==void 0;if(a||u||h||c||f){let m={};return a&&(m.aggregations=t),u&&(m.columns=n),h&&(m.filter=r),c&&(m.groupBy=s),f&&(m.sort=o),p&&(m.visualLink=l),U(this,_i,m)}else return U(this,_i,void 0)}get config(){return z(this,_i)}get selectedRowsCount(){return z(this,Pr)}get size(){return z(this,zi)}get range(){return z(this,qn)}set range(t){U(this,qn,t),this.viewport&&this.server&&this.server.send({viewport:this.viewport,type:"setViewRange",range:t})}get columns(){return z(this,wn)}set columns(t){var r;if(console.log(`RemoteDataSOurce ${t.join(",")}`),U(this,wn,t),this.viewport){let s={viewport:this.viewport,type:"setColumns",columns:t};this.server&&this.server.send(s)}let n=this.refreshConfig();n&&((r=this.onConfigChange)==null||r.call(this,n))}get aggregations(){return z(this,yn)}set aggregations(t){var r,s;U(this,yn,t),this.viewport&&((r=this.server)==null||r.send({viewport:this.viewport,type:"aggregate",aggregations:t}));let n=this.refreshConfig();n&&((s=this.onConfigChange)==null||s.call(this,n))}get sort(){return z(this,Cn)}set sort(t){var r;if(U(this,Cn,t),this.viewport){let s={viewport:this.viewport,type:"sort",sort:t};this.server&&this.server.send(s)}let n=this.refreshConfig();n&&((r=this.onConfigChange)==null||r.call(this,n))}get filter(){return z(this,vn)}set filter(t){var r;if(U(this,vn,t),this.viewport){let s={viewport:this.viewport,type:"filter",filter:t};this.server&&this.server.send(s)}let n=this.refreshConfig();n&&((r=this.onConfigChange)==null||r.call(this,n))}get groupBy(){return z(this,Gt)}set groupBy(t){var r;if(U(this,Gt,t!=null?t:[]),this.viewport){let s={viewport:this.viewport,type:"groupBy",groupBy:z(this,Gt)};this.server&&this.server.send(s)}let n=this.refreshConfig();n&&((r=this.onConfigChange)==null||r.call(this,n))}get title(){return z(this,jn)}set title(t){var n;U(this,jn,t),this.viewport&&t&&((n=this.server)==null||n.send({type:"setTitle",title:t,viewport:this.viewport}))}get visualLink(){return z(this,Ui)}set visualLink(t){var r,s,o;if(U(this,Ui,t),t){let{parentClientVpId:l,link:{fromColumn:a,toColumn:u}}=t;this.viewport&&((r=this.server)==null||r.send({viewport:this.viewport,type:"createLink",parentClientVpId:l,parentColumnName:u,childColumnName:a}))}else this.viewport&&((s=this.server)==null||s.send({type:"removeLink",viewport:this.viewport}));let n=this.refreshConfig();n&&((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})}};yn=new WeakMap,wn=new WeakMap,_i=new WeakMap,vn=new WeakMap,Gt=new WeakMap,qn=new WeakMap,Pr=new WeakMap,zi=new WeakMap,Cn=new WeakMap,jn=new WeakMap,Ui=new WeakMap;var Qn=require("@vuu-ui/vuu-utils"),Sy=/^ws(s)?:\/\/.+/,Rd={},Va=Symbol("setWebsocket"),oo=Symbol("connectionCallback");async function La(i){Ed(i.url,i[oo],i)}async function Ed(i,e,t){let n=Rd[i]||(Rd[i]={attemptsRemaining:5,status:"disconnected"});try{e({type:"connection-status",status:"connecting"});let r=typeof t<"u",s=await ky(i);Qn.logger.log("%c\u26A1 %cconnected","font-size: 24px;color: green;font-weight: bold;","color:green; font-size: 14px;"),t!==void 0&&t[Va](s);let o=t!=null?t:new Na(s,i,e),l=r?"reconnected":"connected";return e({type:"connection-status",status:l}),o.status=l,o}catch{let s=--n.attemptsRemaining>0;if(e({type:"connection-status",status:"disconnected",reason:"failed to connect",retry:s}),s)return xy(i,e,t,1e4);throw Error("Failed to establish connection")}}var xy=(i,e,t,n)=>new Promise(r=>{setTimeout(()=>{r(Ed(i,e,t))},n)}),ky=i=>new Promise((e,t)=>{let n=Sy.test(i)?i:`wss://${i}`,r=new WebSocket(n);r.onopen=()=>e(r),r.onerror=s=>t(s)}),Ad=()=>{Qn.logger.warn("Connection cannot be closed, socket not yet opened")},Dd=i=>{Qn.logger.warn("Message cannot be sent, socket closed",i)},My=i=>{try{return JSON.parse(i)}catch{throw Error(`Error parsing JSON response from server ${i}`)}},Na=class{constructor(e,t,n){this.close=Ad;this.requiresLogin=!0;this.send=Dd;this.status="ready";this.url=t,this[oo]=n,this[Va](e)}reconnect(){La(this)}[(oo,Va)](e){let t=this[oo];e.onmessage=s=>{let o=My(s.data);t(o)},e.onerror=()=>{Qn.logger.error("%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"&&(La(this),this.send=r)},e.onclose=()=>{Qn.logger.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"&&(La(this),this.send=r)};let n=s=>{e.send(JSON.stringify(s))},r=s=>{console.log("TODO queue message until websocket reconnected",{_msg:s})};this.send=n,this.close=()=>{Qn.logger.log("[Connection] close websocket"),this.status="closed",e.close(),this.close=Ad,this.send=Dd}}};var Pd=require("react");var Ty=require("@vuu-ui/vuu-utils");var Od=[{label:"=",boost:10},{label:"!=",boost:9}],zk=[...Od,{label:"in",boost:6},{label:"starts",boost:5},{label:"ends",boost:4}],Uk=[...Od,{label:">",boost:8},{label:"<",boost:7}];var Iy=require("@heswell/salt-lab"),Ly=Me(require("classnames"),1);var Vd=require("@heswell/salt-lab");var Ry=require("@heswell/salt-lab"),Id=require("react"),Ay=require("react/jsx-runtime");var Dy=require("@heswell/salt-lab"),Ld=require("react"),Ey=require("react/jsx-runtime");var Py=require("react/jsx-runtime");var Vy=require("react/jsx-runtime");var wM=Xs.configure({strict:!0});var Nd=require("@vuu-ui/vuu-utils");var Ba=i=>i!==void 0&&i.op==="in";function Fa(i){return i!==void 0&&(i.op==="and"||i.op==="or")}var Ny=i=>typeof i=="string"?`"${i}"`:i,Ha=(i,e={})=>Fa(i)?i.filters.map(t=>Ha(t)).join(` ${i.op} `):Ba(i)?`${i.column} ${i.op} [${i.values.join(",")}]`:`${i.column} ${i.op} ${Ny(i.value)}`;var Bd=(i,e)=>{if(Fa(e)){let[t,n]=e.filters;if(t.column===i.name)return[n,Ha(n)];if(n.column===i.name)return[t,Ha(t)]}return[void 0,""]};var Pe=require("@vuu-ui/vuu-utils"),By=(i,e)=>{if(i.filterStruct&&e){let[t,n]=Bd(e,i.filterStruct);return{filter:n,filterStruct:t}}else return i},{Average:Fy,Count:Hy,High:Wy,Low:_y,Sum:zy}=Pe.AggregationType,Fd=({dataSource:i,onPersistentColumnOperation:e})=>(n,r)=>{let s=r;if(s.column&&i){let{column:o}=s;switch(n){case"sort-asc":return i.sort=(0,Pe.setSortColumn)(i.sort,o,"A"),!0;case"sort-dsc":return i.sort=(0,Pe.setSortColumn)(i.sort,o,"D"),!0;case"sort-add-asc":return i.sort=(0,Pe.addSortColumn)(i.sort,o,"A"),!0;case"sort-add-dsc":return i.sort=(0,Pe.addSortColumn)(i.sort,o,"D"),!0;case"group":return i.groupBy=(0,Pe.addGroupColumn)(i.groupBy,o),!0;case"group-add":return i.groupBy=(0,Pe.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,Pe.setAggregations)(i.aggregations,o,Fy),!0;case"agg-high":return i.aggregations=(0,Pe.setAggregations)(i.aggregations,o,Wy),!0;case"agg-low":return i.aggregations=(0,Pe.setAggregations)(i.aggregations,o,_y),!0;case"agg-count":return i.aggregations=(0,Pe.setAggregations)(i.aggregations,o,Hy),!0;case"agg-sum":return i.aggregations=(0,Pe.setAggregations)(i.aggregations,o,zy),!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 jt=require("@vuu-ui/vuu-utils"),_a=require("react");var Wa=Me(require("classnames")),Hd=require("react");var qt=require("react/jsx-runtime"),Jn="vuuTable-groupHeaderCell",Uy=i=>{let{column:e,className:t,onRemoveColumn:n}=i;return(0,qt.jsxs)("div",{className:(0,Wa.default)(`${Jn}-col`,t),role:"columnheader",children:[(0,qt.jsx)("span",{className:`${Jn}-label`,children:e.name}),(0,qt.jsx)("span",{className:`${Jn}-close`,"data-icon":"close-circle",onClick:()=>n==null?void 0:n(e)})]})},Wd=({column:i,className:e,onRemoveColumn:t,onResize:n,...r})=>{let s=(0,Hd.useRef)(null),{isResizing:o,...l}=Xr({column:i,onResize:n,rootRef:s}),a=(0,Wa.default)(Jn,e,{vuuPinLeft:i.pin==="left",[`${Jn}-right`]:i.align==="right",[`${Jn}-resizing`]:i.resizing}),{columns:u}=i;return(0,qt.jsx)("th",{className:a,ref:s,...r,children:(0,qt.jsxs)("div",{className:`${Jn}-inner`,children:[u.map(h=>(0,qt.jsx)(Uy,{column:h,onRemoveColumn:t},h.key)),i.resizeable!==!1?(0,qt.jsx)(Jr,{...l}):null]})})};var Ge=require("react/jsx-runtime"),_d="vuuDataTable",{RENDER_IDX:Ky}=jt.metadataKeys,zd=({columns:i,data:e,headings:t,onColumnResize:n,onHeaderCellDragStart:r,onContextMenu:s,onRemoveColumnFromGroupBy:o,onRowClick:l,onSort:a,onToggleGroup:u,rowCount:h,rowHeight:c})=>{let f=(0,_a.useCallback)(m=>{r==null||r(m)},[r]),p=(0,_a.useCallback)(m=>{var k;let w=m.target.closest(".vuuTable-headerCell"),v=parseInt((k=w==null?void 0:w.dataset.idx)!=null?k:"-1"),A=i[v],C=m.shiftKey;A&&a(A,C)},[i,a]);return(0,Ge.jsxs)("table",{"aria-rowcount":h,className:`${_d}-table`,children:[(0,Ge.jsx)("colgroup",{children:i.filter(jt.notHidden).map((m,b)=>(0,Ge.jsx)("col",{width:`${m.width}px`},b))}),(0,Ge.jsxs)("thead",{children:[t.map((m,b)=>(0,Ge.jsx)("tr",{className:"vuuTable-heading",children:m.map(({label:w,span:v},A)=>(0,Ge.jsx)("th",{colSpan:v,className:"vuuTable-headingCell",children:w},A))},b)),(0,Ge.jsx)("tr",{children:i.filter(jt.notHidden).map((m,b)=>{let w=(0,jt.getColumnPinStyle)(m);return(0,jt.isGroupColumn)(m)?(0,Ge.jsx)(Wd,{column:m,"data-idx":b,onRemoveColumn:o,onResize:n,style:w},b):(0,Ge.jsx)(Yr,{column:m,"data-idx":b,onClick:p,onDragStart:f,onResize:n,style:w},b)})})]}),(0,Ge.jsxs)("tbody",{onContextMenu:s,children:[e==null?void 0:e.map((m,b)=>(0,Ge.jsx)(Qr,{columns:i,height:c,index:b,onClick:l,onToggleGroup:u,row:m},m[Ky])),(0,Ge.jsx)("tr",{className:`${_d}-filler`})]})]})};var xn=require("@vuu-ui/vuu-utils"),me=require("react");var Sn=require("@vuu-ui/vuu-utils"),ge=require("react"),{RENDER_IDX:Ud,SELECTED:Or}=Sn.metadataKeys,Kd=(i,e)=>i[Ud]-e[Ud],$y=i=>["aggregate","columns","filter","groupBy","sort"].includes(i.type);function $d({dataSource:i,onConfigChange:e,onFeatureEnabled:t,onFeatureInvocation:n,onSizeChange:r,onSubscribed:s,range:o={from:0,to:0},renderBufferSize:l=0,viewportRowCount:a}){let[,u]=(0,ge.useState)(null),h=(0,ge.useRef)(!0),c=(0,ge.useRef)(!1),f=(0,ge.useRef)({from:0,to:0}),p=(0,ge.useRef)(null),m=(0,ge.useRef)([]),b=(0,ge.useMemo)(()=>new za((0,Sn.getFullRange)(o)),[]),w=(0,ge.useCallback)(x=>{for(let I of x)b.add(I);m.current=b.data.slice().sort(Kd),c.current=!0},[b]),v=(0,ge.useCallback)(x=>{x.type==="subscribed"?s==null||s(x):x.type==="viewport-update"?(typeof x.size=="number"&&(r==null||r(x.size),b.setRowCount(x.size)),x.rows?w(x.rows):typeof x.size=="number"&&(m.current=b.data.slice().sort(Kd),c.current=!0)):$y(x)?e==null||e(x):Sd(x)?t==null||t(x):xd(x)?n==null||n(x):console.log(`useDataSource unexpected message ${x.type}`)},[b,e,t,n,r,s,w]);(0,ge.useEffect)(()=>()=>{p.current&&(cancelAnimationFrame(p.current),p.current=null),h.current=!1},[]);let A=(0,ge.useCallback)(()=>{h.current&&(c.current&&(u({}),c.current=!1),p.current=requestAnimationFrame(A))},[u]);(0,ge.useEffect)(()=>{p.current=requestAnimationFrame(A)},[A]);let C=(0,ge.useCallback)(x=>{let{from:I}=i.range,_=(0,Sn.getFullRange)({from:I,to:I+x},l);i.range=f.current=_,b.setRange(_)},[i,b,l]),k=(0,ge.useCallback)(x=>{let I=(0,Sn.getFullRange)(x,l);i.range=f.current=I,b.setRange(I)},[i,b,l]),M=(0,ge.useCallback)(()=>b.getSelectedRows(),[b]);return(0,ge.useEffect)(()=>{i==null||i.subscribe({range:f.current},v)},[i,v]),(0,ge.useEffect)(()=>{console.log(`adjust range with viewportRowCount ${a}`),C(a)},[C,a]),{data:m.current,getSelectedRows:M,range:f.current,setRange:k,dataSource:i}}var za=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 Sn.WindowRange(e,t),this.data=new Array(t-e),this.rowCount=0}add(e){var n;let[t]=e;if(this.isWithinRange(t)){let r=t-this.range.from;this.data[r]=e;let s=e[Or],o=(n=this.data[r-1])==null?void 0:n[Or];o===0&&s?this.data[r-1][Or]=2:o===2&&!s&&(this.data[r-1][Or]=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,r]=this.range.overlap(e,t),s=new Array(t-e);for(let o=n;o<r;o++){let l=this.getAtIndex(o);if(l){let a=o-e;s[a]=l}}this.data=s,this.range.from=e,this.range.to=t}}getSelectedRows(){return this.data.filter(e=>e[Or]===1)}};var Gd=require("@heswell/salt-lab"),Qt=require("react"),qd=({onDrop:i,tableContainerRef:e,tableLayout:t})=>{let[n,r]=(0,Qt.useState)(t),s=(0,Qt.useRef)(),o=(0,Qt.useCallback)(()=>{console.log("handleDropSettle"),s.current=void 0,r("row")},[]),{draggable:l,draggedItemIndex:a,onMouseDown:u}=(0,Gd.useDragDrop)({allowDragDrop:!0,draggableClassName:"table-column",orientation:"horizontal",containerRef:e,itemQuery:".vuuDataTable-table",onDrop:i,onDropSettle:o}),h=(0,Qt.useCallback)(c=>{let{clientX:f,clientY:p}=c;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let b=c.target.closest(".vuuTable-headerCell"),{dataset:{idx:w="-1"}}=b;s.current={clientX:f,clientY:p,idx:w},r("column")},[]);return(0,Qt.useLayoutEffect)(()=>{var c;if(n==="column"&&s.current&&!l){let{clientX:f,clientY:p,idx:m}=s.current,b=(c=e.current)==null?void 0:c.querySelector(`.vuuDataTable-table[data-idx="${m}"]`);if(b){let w={persist:()=>{},nativeEvent:{clientX:f,clientY:p,target:b}};u==null||u(w)}}},[l,u,e,n]),{draggable:l,draggedItemIndex:a,tableLayout:n,onHeaderCellDragStart:n==="row"?h:void 0}};var Yd=require("@vuu-ui/vuu-utils"),ve=require("react");function Gy(i,...e){let t=new Set(i);for(let n of e)for(let r of n)t.add(r);return t}var Ua="ArrowUp",Ka="ArrowDown",$a="ArrowLeft",Ga="ArrowRight";var qa="Home",ja="End",Qa="PageUp",Ja="PageDown";var qy=new Set(["Enter","Delete"," "]),jy=new Set(["Tab"]),Qy=new Set(["ArrowRight","ArrowLeft"]),jd=new Set([qa,ja,Qa,Ja,Ka,$a,Ga,Ua]),Jy=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),d1=Gy(qy,jd,Qy,Jy,jy);var Xy=["Home","End","PageUp","PageDown"],Qd=i=>Xy.includes(i),Jd=i=>jd.has(i);var Xd=i=>`thead th:nth-child(${i+1})`,Yy=(i,e)=>`tbody > tr[aria-rowindex='${i}'] > td:nth-child(${e+1})`,Zy=[-1,-1];function ew(i,[e,t],n,r){return i===Ua?e>-1?[e-1,t]:[e,t]:i===Ka?e===-1?[0,t]:e===r-1?[e,t]:[e+1,t]:i===Ga?t<n-1?[e,t+1]:[e,t]:i===$a?t>0?[e,t-1]:[e,t]:[e,t]}var Zd=({columnCount:i=0,containerRef:e,disableHighlightOnFocus:t,data:n,requestScroll:r,rowCount:s=0,viewportRange:o})=>{var F;let{from:l,to:a}=o,u=(0,ve.useRef)([-1,-1]),h=(0,ve.useRef)(),c=(0,ve.useRef)([-1,0]),f=(0,ve.useCallback)(([R,P])=>{var N;let H=R===-1?Xd(P):Yy(R,P);return(N=e.current)==null?void 0:N.querySelector(H)},[e]),p=R=>R==null?void 0:R.closest("th,td"),m=R=>{var P,H;if(R.tagName==="TH")return[-1,parseInt((P=R.dataset.idx)!=null?P:"-1",10)];{let N=R.closest("tr");if(N){let j=parseInt((H=N.ariaRowIndex)!=null?H:"-1",10),$=Array.from(N.childNodes).indexOf(R);return[j,$]}}return Zy},b=(0,ve.useCallback)(R=>{var P;if(e.current){let H=f(R);H?(H!==h.current&&((P=h.current)==null||P.setAttribute("tabindex",""),h.current=H,H.setAttribute("tabindex","0")),H.focus()):(0,Yd.withinRange)(R[0],o)||(h.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[e,f,r,o]),w=(0,ve.useCallback)((R,P,H=!1)=>{let N=[R,P];c.current=N,b(N),H&&(u.current=N)},[b]),v=(0,ve.useCallback)(()=>{var R;(R=h.current)==null||R.setAttribute("tabindex",""),h.current=void 0},[]),A=(0,ve.useCallback)(async(R,P)=>{switch(R){case Ja:r==null||r({type:"scroll-page",direction:"down"});break;case Qa:r==null||r({type:"scroll-page",direction:"up"});break;case qa:r==null||r({type:"scroll-end",direction:"home"});break;case ja:r==null||r({type:"scroll-end",direction:"end"});break}return P},[r]),C=(0,ve.useCallback)(()=>{var R;if(t!==!0&&(R=e.current)!=null&&R.contains(document.activeElement)){let P=p(document.activeElement);P&&(u.current=m(P))}},[t,e]),k=(0,ve.useCallback)(async R=>{let[P,H]=Qd(R)?await A(R,c.current):ew(R,c.current,i,s),[N,j]=c.current;(P!==N||H!==j)&&w(P,H,!0)},[i,A,s,w]),M=(0,ve.useCallback)(R=>{n.length>0&&Jd(R.key)&&(R.preventDefault(),R.stopPropagation(),k(R.key))},[n,k]),x=(0,ve.useCallback)(R=>{let P=R.target,H=p(P);if(H){let[N,j]=m(H);w(N,j)}},[w]),I=(0,ve.useMemo)(()=>({onClick:x,onFocus:C,onKeyDown:M}),[x,C,M]);(0,ve.useLayoutEffect)(()=>{let{current:R}=c,P=R[0]>=l&&R[0]<=a;h.current&&!P?v():!h.current&&P&&b(R)},[b,l,a,v]);let _=((F=e.current)==null?void 0:F.firstChild)!=null;return(0,ve.useEffect)(()=>{var R;if(_&&h.current===void 0){let P=(R=e.current)==null?void 0:R.querySelector(Xd(0));P&&(P.setAttribute("tabindex","0"),h.current=P)}},[e,_]),I};var Ki=require("react");var Yn=require("react");var Xn=new Map,tp=(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}},ep=new ResizeObserver(i=>{for(let e of i){let{target:t,borderBoxSize:n,contentBoxSize:r}=e,s=Xn.get(t);if(s){let[{blockSize:o,inlineSize:l}]=n,[{blockSize:a,inlineSize:u}]=r,{onResize:h,measurements:c}=s,f=!1;for(let[p,m]of Object.entries(c)){let b=tp(t,{height:o,width:l,contentHeight:a,contentWidth:u},p);b!==m&&(f=!0,c[p]=b)}f&&h&&h(c)}}});function np(i,e,t,n=!1){let r=(0,Yn.useRef)(e),s=(0,Yn.useCallback)(o=>{let{width:l,height:a}=o.getBoundingClientRect(),{clientWidth:u,clientHeight:h}=o;return r.current.reduce((c,f)=>(c[f]=tp(o,{width:l,height:a,contentHeight:h,contentWidth:u},f),c),{})},[]);(0,Yn.useEffect)(()=>{let o=i.current;async function l(){Xn.set(o,{measurements:{}}),await document.fonts.ready;let a=Xn.get(o);if(a){let u=s(o);a.measurements=u,ep.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(Xn.has(o))throw Error("useResizeObserver attemping to observe same element twice");l()}return()=>{o&&Xn.has(o)&&(ep.unobserve(o),Xn.delete(o))}},[s,i]),(0,Yn.useEffect)(()=>{let o=i.current,l=Xn.get(o);if(l){if(r.current!==e){r.current=e;let a=s(o);l.measurements=a}l.onResize=t}},[e,s,i,t])}var tw=["clientHeight","clientWidth"],ip=i=>Number.isFinite(i),Xa=({defaultHeight:i=0,defaultWidth:e=0,height:t,width:n})=>{let r=(0,Ki.useRef)(null),[s,o]=(0,Ki.useState)({outer:{height:t!=null?t:"100%",width:n!=null?n:"100%"}}),l=(0,Ki.useCallback)(({clientWidth:a,clientHeight:u})=>{o(h=>{let{inner:c,outer:f}=h;return ip(u)&&ip(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 np(r,tw,l,!0),{containerRef:r,outerSize:s.outer,innerSize:s.inner}};var $i=require("@vuu-ui/vuu-utils"),Ir=require("react"),{IDX:nw,SELECTED:iw}=$i.metadataKeys,rw=[],rp=({selectionModel:i,onSelectionChange:e})=>{let t=(0,Ir.useRef)(-1),n=(0,Ir.useRef)(rw);return(0,Ir.useCallback)((s,o,l)=>{let{[nw]:a,[iw]:u}=s,{current:h}=t,{current:c}=n,p=(u?$i.deselectItem:$i.selectItem)(i,c,a,o,l,h);n.current=p,t.current=a,e&&e(p)},[e,i])};var sp=require("@heswell/salt-lab"),pe=require("@vuu-ui/vuu-utils"),op=require("react"),sw=100,lp=pe.metadataKeys.count,ow=({serverDataType:i})=>i===void 0,lw=i=>{var e,t;if((0,pe.isTypeDescriptor)(i.type))return(0,pe.getCellRenderer)((t=(e=i.type)==null?void 0:e.renderer)==null?void 0:t.name)},aw=(i,e,t)=>{var r;let n=e.indexOf(i.name);return n!==-1&&t[n]?t[n]:(r=i.serverDataType)!=null?r:"string"},uw=["int","long","double"],ap=i=>i===void 0?void 0:uw.includes(i)?"right":"left",hw=(i,e)=>{switch(e.type){case"init":return hp(e);case"moveColumn":return dw(i,e);case"resizeColumn":return mw(i,e);case"setTypes":return gw(i,e);case"hideColumn":return pw(i,e);case"pinColumn":return bw(i,e);case"updateColumnProp":return lo(i,e);case"tableConfig":return cp(i,e);default:return console.log(`unhandled action ${e.type}`),i}},up=(i,e)=>{let[t,n]=(0,op.useReducer)(hw,{tableConfig:i,dataSourceConfig:e},hp);return{columns:t.columns,dispatchColumnAction:n,headings:t.headings}};function hp({dataSourceConfig:i,tableConfig:e}){let t=e.columns.map(fw(e)),n=t.some(pe.isPinned)?(0,pe.sortPinnedColumns)(t):t,r={columns:n,headings:(0,pe.getTableHeadings)(n)};return i?cp(r,i):r}var cw=(i,e)=>e==="uppercase"?i.toUpperCase():e==="capitalize"?i[0].toUpperCase()+i.slice(1).toLowerCase():i,fw=({columnDefaultWidth:i=sw,columnFormatHeader:e})=>(t,n)=>{let{align:r=ap(t.serverDataType),name:s,label:o=s,width:l=i,...a}=t;return{...a,align:r,CellRenderer:lw(t),label:cw(o,e),key:n+lp,name:s,originalIdx:n,valueFormatter:(0,pe.getValueFormatter)(t),width:l}};function dw(i,{column:e,moveBy:t,moveTo:n}){let{columns:r}=i;if(typeof t=="number"){let s=r.indexOf(e),o=r.slice(),[l]=o.splice(s,1);return o.splice(s+t,0,l),{...i,columns:o}}else if(typeof n=="number"){let s=r.indexOf(e);return{...i,columns:(0,sp.moveItem)(r,s,n)}}return i}function pw(i,{column:e}){return lo(i,{type:"updateColumnProp",column:e,hidden:!0})}function mw(i,{column:e,phase:t,width:n}){let r="updateColumnProp",s=t!=="end";switch(t){case"begin":case"end":return lo(i,{type:r,column:e,resizing:s});case"resize":return lo(i,{type:r,column:e,width:n});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${t}`)}}function gw(i,{columnNames:e,serverDataTypes:t}){let{columns:n}=i;if(n.some(ow)){let r=n.map(s=>{var l;let o=aw(s,e,t);return{...s,align:(l=s.align)!=null?l:ap(o),serverDataType:o}});return{...i,columns:r}}else return i}function bw(i,e){let{columns:t}=i,{column:n,pin:r}=e,s=t.find(o=>o.name===n.name);return s?(t=Gi(t,{...s,pin:r}),t=(0,pe.sortPinnedColumns)(t),{...i,columns:t}):i}function lo(i,e){let{columns:t}=i,{align:n,column:r,hidden:s,label:o,resizing:l,width:a}=e,u=t.find(h=>h.name===r.name);return u&&((n==="left"||n==="right")&&(t=Gi(t,{...u,align:n})),typeof o=="string"&&(t=Gi(t,{...u,label:o})),typeof l=="boolean"&&(t=Gi(t,{...u,resizing:l})),typeof s=="boolean"&&(t=Gi(t,{...u,hidden:s})),typeof a=="number"&&(t=Gi(t,{...u,width:a}))),{...i,columns:t}}function cp(i,{columns:e,filter:t,groupBy:n,sort:r}){let s=e&&e.length>0,o=n!==void 0,l=typeof(t==null?void 0:t.filter)=="string",a=r&&r.sortDefs.length>0,u=i;return s&&(u={...i,columns:e.map((h,c)=>{let f=(0,pe.getColumnName)(h),p=c+lp,m=u.columns.find(b=>b.name===f);if(m)return m.key===p?m:{...m,key:p};throw Error(`useTableModel column ${h} not found`)})}),o&&(u={...i,columns:(0,pe.applyGroupByToColumns)(u.columns,n)}),a&&(u={...i,columns:(0,pe.applySortToColumns)(u.columns,r)}),l&&(u={...i,columns:(0,pe.applyFilterToColumns)(u.columns,t)}),u}function Gi(i,e){return i.map(t=>t.name===e.name?e:t)}var ut=require("react"),fp=i=>{let{scrollLeft:e,scrollTop:t}=i,{clientHeight:n,clientWidth:r,scrollHeight:s,scrollWidth:o}=i,l=e/(o-r),a=t/(s-n);return[l,a,e,t]},yw=i=>{let{clientHeight:e,clientWidth:t,scrollHeight:n,scrollWidth:r}=i;return[r-t,n-e]},dp=({onRangeChange:i,rowHeight:e,viewport:t})=>{let n=(0,ut.useRef)(null),r=(0,ut.useRef)(null),s=(0,ut.useRef)(null),o=(0,ut.useRef)(!1),l=(0,ut.useRef)(-1),{rowCount:a,maxScrollContainerScrollHorizontal:u,maxScrollContainerScrollVertical:h}=t,c=(0,ut.useCallback)((w,v)=>{let{current:A}=s;A&&(A.scrollLeft=w,A.scrollTop=v)},[s]),f=(0,ut.useCallback)(()=>{let{current:w}=s;if(w){let{scrollTop:v}=w,A=Math.floor(v/e);A!==l.current&&(l.current=A,i(A,A+a))}},[i,e,a]),p=(0,ut.useCallback)(()=>{let{current:w}=r,{current:v}=n;if(w&&v){let[A,C,k,M]=fp(w);o.current=!0,v.scrollLeft=Math.round(A*u),v.scrollTop=Math.round(C*h),c(k,M)}},[u,h,r,n,c]),m=(0,ut.useCallback)(()=>{let{current:w}=r,{current:v}=n,{current:A}=o;if(A)o.current=!1;else if(w&&v){let[C,k]=fp(v),[M,x]=yw(w),I=Math.round(C*M),_=Math.round(k*x);w.scrollLeft=I,w.scrollTop=_,c(I,_)}},[r,n,c]),b=(0,ut.useCallback)(w=>{let{current:v}=n;if(v){if(o.current=!1,w.type==="scroll-page"){let{clientHeight:A,scrollTop:C}=v,{direction:k}=w,M=k==="down"?A:-A;v.scrollTop=Math.min(Math.max(0,C+M),t.maxScrollContainerScrollVertical)}else if(w.type==="scroll-end"){let{direction:A}=w,C=A==="end"?t.maxScrollContainerScrollVertical:0;v.scrollTop=C}}},[t.maxScrollContainerScrollVertical]);return{onScrollbarContainerScroll:m,onContentContainerScroll:p,onTableContainerScroll:f,requestScroll:b,contentContainerRef:r,scrollbarContainerRef:n,tableContainerRef:s}};var Ya=require("react"),ww={fillerHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,scrollContentHeight:0,scrollbarSize:0,scrollContentWidth:0,totalHeaderHeight:0},vw=i=>{let e=0,t=0,n=0;for(let r of i){let{hidden:s,pin:o,width:l}=r,a=s?0:l;o==="left"?e+=a:o==="right"?t+=a:n+=a}return{pinnedWidthLeft:e,pinnedWidthRight:t,unpinnedWidth:n}},pp=({columns:i,headerHeight:e,headings:t,rowCount:n,rowHeight:r,size:s})=>{let{pinnedWidthLeft:o,pinnedWidthRight:l,unpinnedWidth:a}=(0,Ya.useMemo)(()=>vw(i),[i]);return(0,Ya.useMemo)(()=>{var h;if(s){let c=t.length,f=15,p=n*r,m=o+a+l,b=p+e-(((h=s==null?void 0:s.height)!=null?h:0)-e-f),w=m-s.width+o,v=(s.height-e)/r,A=Number.isInteger(v)?v+1:Math.ceil(v);return{fillerHeight:(n-A)*r,maxScrollContainerScrollHorizontal:w,maxScrollContainerScrollVertical:b,pinnedWidthLeft:o,pinnedWidthRight:l,rowCount:A,scrollContentHeight:e+p+f,scrollbarSize:f,scrollContentWidth:m,totalHeaderHeight:e*(1+c)}}else return ww},[e,t.length,o,l,n,r,s,a])};var Cw=[],{KEY:mp,IS_EXPANDED:Sw}=xn.metadataKeys,gp=({config:i,dataSource:e,headerHeight:t,onConfigChange:n,onFeatureEnabled:r,onFeatureInvocation:s,onSelectionChange:o,renderBufferSize:l=0,rowHeight:a,selectionModel:u,tableLayout:h,...c})=>{var Lr,Vr;let[f,p]=(0,me.useState)(0),m=(0,me.useRef)(!1),b=(0,me.useRef)();if(b.current=e,e===void 0)throw Error("no data source provided to DataTable");let w=Xa(c),v=(0,me.useCallback)(X=>{p(X)},[]),{columns:A,dispatchColumnAction:C,headings:k}=up(i,e.config),M=(0,me.useCallback)(X=>{m.current=!0,C(X)},[C]),x=Fd({dataSource:e,onPersistentColumnOperation:M}),I=pp({columns:A,headerHeight:t,headings:k,rowCount:f,rowHeight:a,size:w.innerSize}),_=(0,me.useCallback)(X=>{if(X.tableMeta){let{columns:be,dataTypes:ze}=X.tableMeta;m.current=!0,C({type:"setTypes",columnNames:be,serverDataTypes:ze})}},[C]),F=(0,me.useCallback)(X=>{let{type:be}=X;switch(be){case"groupBy":case"filter":case"sort":case"columns":{let ze=X[be];return C({type:"tableConfig",[be]:ze})}}},[C]),R=(0,me.useCallback)(X=>{e.select(X),o==null||o(X)},[e,o]),P=rp({onSelectionChange:R,selectionModel:u}),{data:H,getSelectedRows:N,range:j,setRange:$}=$d({dataSource:e,onConfigChange:F,onFeatureEnabled:r,onFeatureInvocation:s,onSubscribed:_,onSizeChange:v,renderBufferSize:l,viewportRowCount:I.rowCount}),ee=(0,me.useRef)();ee.current=H;let Oe=(0,me.useCallback)((X,be)=>{$({from:X,to:be})},[$]),ne=(0,me.useCallback)((X,be=!1,ze)=>{e&&(e.sort=(0,xn.applySort)(e.sort,X,be,ze))},[e]),Y=(0,me.useCallback)((X,be,ze)=>{let Ie=A.find(ei=>ei.name===be);if(Ie)X==="end"&&(m.current=!0),C({type:"resizeColumn",phase:X,column:Ie,width:ze});else throw Error(`useDataTable.handleColumnResize, column ${be} not found`)},[A,C]),ke=(0,me.useCallback)(X=>{e&&(X[Sw]?e.closeTreeNode(X[mp]):e.openTreeNode(X[mp]))},[e]),Fe=(0,me.useCallback)(X=>{e&&e.groupBy.includes(X.name)&&(e.groupBy=e.groupBy.filter(be=>be!==X.name))},[e]),{requestScroll:Ze,...ht}=dp({onRangeChange:Oe,rowHeight:a,viewport:I,viewportHeight:((Vr=(Lr=w.innerSize)==null?void 0:Lr.height)!=null?Vr:0)-t}),vt=Zd({columnCount:A.length,containerRef:w.containerRef,data:H,requestScroll:Ze,rowCount:e==null?void 0:e.size,viewportRange:j}),kn=(0,me.useCallback)((X,be)=>{let ze=e.columns[X],Ie=(0,xn.moveItem)(e.columns,ze,be);Ie!==e.columns&&(e.columns=Ie,C({type:"tableConfig",columns:Ie}))},[e,C]),qi=qd({onDrop:kn,tableContainerRef:ht.tableContainerRef,tableLayout:h});(0,me.useEffect)(()=>{b.current&&(m.current=!0,C({type:"init",tableConfig:i,dataSourceConfig:b.current.config}))},[i,C]),(0,me.useMemo)(()=>{m.current&&(n==null||n({...i,columns:A}),m.current=!1)},[A,i,n]);let Mn=si(),uo=(0,me.useCallback)(X=>{var ji;let{current:be}=ee,{current:ze}=b,Ie=X.target,ei=Ie==null?void 0:Ie.closest("td"),ti=Ie==null?void 0:Ie.closest("tr");if(ei&&ti&&be&&ze){let{columns:Nr,selectedRowsCount:Br}=ze,Fr=(0,xn.buildColumnMap)(Nr),ho=parseInt((ji=ti.ariaRowIndex)!=null?ji:"-1"),co=Array.from(ti.childNodes).indexOf(ei),fo=be.find(([Qi])=>Qi===ho),po=Nr[co];Mn(X,"grid",{columnMap:Fr,columnName:po,row:fo,selectedRows:Br===0?Cw:N(),viewport:e==null?void 0:e.viewport})}},[e==null?void 0:e.viewport,N,Mn]);return{containerMeasurements:w,containerProps:vt,columns:A,data:H,dispatchColumnAction:C,handleContextMenuAction:x,headings:k,onColumnResize:Y,onContextMenu:uo,onRemoveColumnFromGroupBy:Fe,onRowClick:P,onSort:ne,onToggleGroup:ke,scrollProps:ht,rowCount:f,viewportMeasurements:I,...qi}};var wt=require("react/jsx-runtime"),Zn="vuuDataTable",xw=({allowConfigEditing:i=!1,className:e,config:t,dataSource:n,headerHeight:r=25,height:s,id:o,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,onSelectionChange:h,onShowConfigEditor:c,renderBufferSize:f=0,rowHeight:p=20,selectionModel:m="extended",style:b,tableLayout:w="row",width:v,...A})=>{let C=(0,ao.useIdMemo)(o),{columns:k,containerMeasurements:{containerRef:M,innerSize:x,outerSize:I},containerProps:_,dispatchColumnAction:F,draggable:R,draggedItemIndex:P,handleContextMenuAction:H,scrollProps:N,tableLayout:j,viewportMeasurements:$,...ee}=gp({config:t,dataSource:n,renderBufferSize:f,headerHeight:r,height:s,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,onSelectionChange:h,rowHeight:p,selectionModel:m,tableLayout:w,width:v}),Oe={...I,"--content-height":`${$.scrollContentHeight}px`,"--content-width":`${$.scrollContentWidth}px`,"--filler-height":`${$.fillerHeight}px`,"--pinned-width-left":`${$.pinnedWidthLeft}px`,"--pinned-width-right":`${$.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${p}px`,"--scrollbar-size":`${$.scrollbarSize}px`,"--table-height":`${x==null?void 0:x.height}px`,"--table-width":`${x==null?void 0:x.width}px`,"--total-header-height":`${$==null?void 0:$.totalHeaderHeight}px`},ne={left:$.pinnedWidthLeft-1,top:($==null?void 0:$.totalHeaderHeight)-1},Y=j==="column"?nh:zd;return(0,wt.jsx)(Eu,{menuActionHandler:H,menuBuilder:rh(n),children:(0,wt.jsxs)("div",{..._,className:Zn,id:C,ref:M,style:Oe,tabIndex:-1,children:[x?(0,wt.jsx)("div",{className:`${Zn}-scrollbarContainer`,onScroll:N.onScrollbarContainerScroll,ref:N.scrollbarContainerRef,style:ne,children:(0,wt.jsx)("div",{className:`${Zn}-scrollContent`})}):null,x?(0,wt.jsxs)("div",{className:`${Zn}-contentContainer`,onScroll:N.onContentContainerScroll,ref:N.contentContainerRef,...A,children:[(0,wt.jsx)("div",{className:`${Zn}-scrollContent`}),(0,wt.jsx)("div",{className:`${Zn}-tableContainer`,onScroll:N.onTableContainerScroll,ref:N.tableContainerRef,children:(0,wt.jsx)(Y,{...ee,columns:k.filter((ke,Fe)=>Fe!==P),headerHeight:r,rowHeight:p})}),R]}):null,i&&x?(0,wt.jsx)(ao.Button,{className:`${Zn}-settings`,"data-icon":"settings",onClick:c,variant:"secondary"}):null]})})};
1
+ "use strict";var x=Object.create;var i=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var D=(r,e)=>{for(var o in e)i(r,o,{get:e[o],enumerable:!0})},f=(r,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of S(e))!g.call(r,t)&&t!==o&&i(r,t,{get:()=>e[t],enumerable:!(s=F(e,t))||s.enumerable});return r};var B=(r,e,o)=>(o=r!=null?x(J(r)):{},f(e||!r||!r.__esModule?i(o,"default",{value:r,enumerable:!0}):o,r)),v=r=>f(i({},"__esModule",{value:!0}),r);var L={};D(L,{FilterTable:()=>M,JsonTable:()=>H});module.exports=v(L);var m=require("@vuu-ui/vuu-filters"),c=require("@vuu-ui/vuu-table"),u=B(require("classnames"));var n=require("react/jsx-runtime"),C="vuuFilterTable",M=({TableProps:r,FilterBarProps:e,...o})=>(0,n.jsxs)("div",{...o,className:(0,u.default)(C),children:[(0,n.jsx)(m.FilterBar,{...e}),(0,n.jsx)(c.Table,{...r})]});var b=require("@vuu-ui/vuu-table"),T=require("@vuu-ui/vuu-data"),a=require("react"),d=require("react/jsx-runtime"),H=({config:r,source:e={"":""},...o})=>{let s=(0,a.useRef)(e),t=(0,a.useRef)();(0,a.useMemo)(()=>{t.current=new T.JsonDataSource({data:s.current})},[]);let P=(0,a.useMemo)(()=>{var l,p;return{...r,columns:(p=(l=t.current)==null?void 0:l.columnDescriptors)!=null?p:[]}},[r]);return(0,a.useEffect)(()=>{t.current&&(t.current.data=e)},[e]),t.current===void 0?null:(0,d.jsx)(b.Table,{...o,config:P,dataSource:t.current})};
17
2
  //# sourceMappingURL=index.js.map